-
Notifications
You must be signed in to change notification settings - Fork 517
/
nodeKeySchema.ts
46 lines (41 loc) · 1.37 KB
/
nodeKeySchema.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import { assert } from "@fluidframework/core-utils";
import { ValueSchema } from "../../core";
import {
nodeKeyFieldKey,
FieldKinds,
nodeKeyTreeIdentifier,
SchemaBuilderInternal,
FieldSchema,
} from "../../feature-libraries";
const builder = new SchemaBuilderInternal({ scope: "com.fluidframework.nodeKey" });
/**
* Schema for a node which holds a {@link StableNodeKey}.
* @alpha
*
* @privateRemarks
* This being a leaf may cause issues with leaf unboxing plans.
* This might need to be changed to be a node holding a string node instead.
*/
export const nodeKeyTreeSchema = builder.leaf("NodeKey", ValueSchema.String);
assert(nodeKeyTreeSchema.name === nodeKeyTreeIdentifier, "mismatched identifiers");
/**
* Key and Field schema for working with {@link LocalNodeKey}s in a shared tree.
* Node keys are added to struct nodes via a field.
* This object can be expanded into a schema to add the field.
*
* Requires including {@link nodeKeySchema}.
* @alpha
*/
export const nodeKeyField = {
[nodeKeyFieldKey]: FieldSchema.create(FieldKinds.nodeKey, [nodeKeyTreeSchema]),
};
/**
* The schema library for working with {@link StableNodeKey}s in a tree.
* Required to use {@link nodeKeyField}.
* @alpha
*/
export const nodeKeySchema = builder.finalize();