@fluidframework/tree 2.31.0 → 2.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +44 -0
- package/api-extractor/api-extractor.current.json +5 -1
- package/api-report/tree.alpha.api.md +44 -20
- package/dist/alpha.d.ts +6 -2
- package/dist/feature-libraries/flex-tree/context.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/context.js +1 -2
- package/dist/feature-libraries/flex-tree/context.js.map +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts +1 -1
- package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/index.js +1 -2
- package/dist/feature-libraries/flex-tree/index.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyEntity.d.ts +6 -15
- package/dist/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyEntity.js +9 -18
- package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.d.ts +3 -3
- package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyField.js +14 -14
- package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts +4 -4
- package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/dist/feature-libraries/flex-tree/lazyNode.js +12 -12
- package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/dist/feature-libraries/index.d.ts +1 -1
- package/dist/feature-libraries/index.d.ts.map +1 -1
- package/dist/feature-libraries/index.js +1 -2
- package/dist/feature-libraries/index.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/sharedTree.js +2 -2
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeApiAlpha.d.ts +6 -6
- package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -1
- package/dist/shared-tree/treeApiAlpha.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +0 -6
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +0 -17
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/conciseTree.d.ts +2 -2
- package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/conciseTree.js.map +1 -1
- package/dist/simple-tree/api/customTree.d.ts +14 -12
- package/dist/simple-tree/api/customTree.d.ts.map +1 -1
- package/dist/simple-tree/api/customTree.js.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.d.ts +21 -7
- package/dist/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/getJsonSchema.js +8 -16
- package/dist/simple-tree/api/getJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/getSimpleSchema.d.ts +3 -10
- package/dist/simple-tree/api/getSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/getSimpleSchema.js +4 -16
- package/dist/simple-tree/api/getSimpleSchema.js.map +1 -1
- package/dist/simple-tree/api/index.d.ts +4 -3
- package/dist/simple-tree/api/index.d.ts.map +1 -1
- package/dist/simple-tree/api/index.js +2 -1
- package/dist/simple-tree/api/index.js.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +17 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFactoryAlpha.js +4 -0
- package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.d.ts +5 -2
- package/dist/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/dist/simple-tree/api/schemaFromSimple.js +24 -8
- package/dist/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts +11 -3
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +40 -28
- package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/dist/simple-tree/api/tree.d.ts +32 -5
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js +17 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/dist/simple-tree/api/verboseTree.d.ts +4 -28
- package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/dist/simple-tree/api/verboseTree.js.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +7 -3
- package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/dist/simple-tree/core/treeNodeKernel.js +7 -6
- package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js +12 -1
- package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/dist/simple-tree/index.d.ts +1 -1
- package/dist/simple-tree/index.d.ts.map +1 -1
- package/dist/simple-tree/index.js +3 -2
- package/dist/simple-tree/index.js.map +1 -1
- package/dist/simple-tree/simpleSchema.d.ts +4 -11
- package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
- package/dist/simple-tree/simpleSchema.js.map +1 -1
- package/dist/tableSchema.d.ts +227 -0
- package/dist/tableSchema.d.ts.map +1 -0
- package/dist/tableSchema.js +234 -0
- package/dist/tableSchema.js.map +1 -0
- package/dist/treeFactory.d.ts +4 -4
- package/dist/treeFactory.d.ts.map +1 -1
- package/dist/treeFactory.js.map +1 -1
- package/dist/util/breakable.d.ts.map +1 -1
- package/dist/util/breakable.js +9 -7
- package/dist/util/breakable.js.map +1 -1
- package/lib/alpha.d.ts +6 -2
- package/lib/feature-libraries/flex-tree/context.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/context.js +1 -2
- package/lib/feature-libraries/flex-tree/context.js.map +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts +1 -1
- package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/index.js +1 -1
- package/lib/feature-libraries/flex-tree/index.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyEntity.d.ts +6 -15
- package/lib/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyEntity.js +8 -17
- package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.d.ts +3 -3
- package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyField.js +15 -15
- package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts +4 -4
- package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
- package/lib/feature-libraries/flex-tree/lazyNode.js +13 -13
- package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
- package/lib/feature-libraries/index.d.ts +1 -1
- package/lib/feature-libraries/index.d.ts.map +1 -1
- package/lib/feature-libraries/index.js +1 -1
- package/lib/feature-libraries/index.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/sharedTree.js +2 -2
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeApiAlpha.d.ts +6 -6
- package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -1
- package/lib/shared-tree/treeApiAlpha.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +0 -6
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +0 -17
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/conciseTree.d.ts +2 -2
- package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/conciseTree.js.map +1 -1
- package/lib/simple-tree/api/customTree.d.ts +14 -12
- package/lib/simple-tree/api/customTree.d.ts.map +1 -1
- package/lib/simple-tree/api/customTree.js.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.d.ts +21 -7
- package/lib/simple-tree/api/getJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/getJsonSchema.js +8 -16
- package/lib/simple-tree/api/getJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/getSimpleSchema.d.ts +3 -10
- package/lib/simple-tree/api/getSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/getSimpleSchema.js +4 -16
- package/lib/simple-tree/api/getSimpleSchema.js.map +1 -1
- package/lib/simple-tree/api/index.d.ts +4 -3
- package/lib/simple-tree/api/index.d.ts.map +1 -1
- package/lib/simple-tree/api/index.js +1 -1
- package/lib/simple-tree/api/index.js.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +17 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFactoryAlpha.js +4 -0
- package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.d.ts +5 -2
- package/lib/simple-tree/api/schemaFromSimple.d.ts.map +1 -1
- package/lib/simple-tree/api/schemaFromSimple.js +24 -8
- package/lib/simple-tree/api/schemaFromSimple.js.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts +11 -3
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +41 -29
- package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
- package/lib/simple-tree/api/tree.d.ts +32 -5
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js +16 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/lib/simple-tree/api/verboseTree.d.ts +4 -28
- package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
- package/lib/simple-tree/api/verboseTree.js.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +7 -3
- package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
- package/lib/simple-tree/core/treeNodeKernel.js +8 -7
- package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js +12 -1
- package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
- package/lib/simple-tree/index.d.ts +1 -1
- package/lib/simple-tree/index.d.ts.map +1 -1
- package/lib/simple-tree/index.js +1 -1
- package/lib/simple-tree/index.js.map +1 -1
- package/lib/simple-tree/simpleSchema.d.ts +4 -11
- package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
- package/lib/simple-tree/simpleSchema.js.map +1 -1
- package/lib/tableSchema.d.ts +227 -0
- package/lib/tableSchema.d.ts.map +1 -0
- package/lib/tableSchema.js +231 -0
- package/lib/tableSchema.js.map +1 -0
- package/lib/treeFactory.d.ts +4 -4
- package/lib/treeFactory.d.ts.map +1 -1
- package/lib/treeFactory.js.map +1 -1
- package/lib/util/breakable.d.ts.map +1 -1
- package/lib/util/breakable.js +9 -7
- package/lib/util/breakable.js.map +1 -1
- package/package.json +25 -37
- package/src/feature-libraries/flex-tree/context.ts +2 -2
- package/src/feature-libraries/flex-tree/index.ts +0 -1
- package/src/feature-libraries/flex-tree/lazyEntity.ts +11 -21
- package/src/feature-libraries/flex-tree/lazyField.ts +17 -26
- package/src/feature-libraries/flex-tree/lazyNode.ts +13 -19
- package/src/feature-libraries/index.ts +0 -1
- package/src/index.ts +6 -2
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/sharedTree.ts +2 -2
- package/src/shared-tree/treeApiAlpha.ts +17 -15
- package/src/shared-tree-core/sharedTreeCore.ts +0 -23
- package/src/simple-tree/api/conciseTree.ts +4 -4
- package/src/simple-tree/api/customTree.ts +16 -14
- package/src/simple-tree/api/getJsonSchema.ts +25 -16
- package/src/simple-tree/api/getSimpleSchema.ts +4 -18
- package/src/simple-tree/api/index.ts +4 -2
- package/src/simple-tree/api/schemaFactoryAlpha.ts +18 -1
- package/src/simple-tree/api/schemaFromSimple.ts +45 -16
- package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +53 -34
- package/src/simple-tree/api/tree.ts +51 -4
- package/src/simple-tree/api/verboseTree.ts +7 -32
- package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +8 -3
- package/src/simple-tree/core/treeNodeKernel.ts +11 -7
- package/src/simple-tree/core/unhydratedFlexTree.ts +17 -4
- package/src/simple-tree/index.ts +4 -2
- package/src/simple-tree/simpleSchema.ts +4 -12
- package/src/tableSchema.ts +609 -0
- package/src/treeFactory.ts +4 -3
- package/src/util/breakable.ts +9 -6
|
@@ -30,10 +30,9 @@ import {
|
|
|
30
30
|
applySchemaToParserOptions,
|
|
31
31
|
cursorFromVerbose,
|
|
32
32
|
verboseFromCursor,
|
|
33
|
-
type
|
|
33
|
+
type TreeEncodingOptions,
|
|
34
34
|
type VerboseTree,
|
|
35
35
|
toStoredSchema,
|
|
36
|
-
type EncodeOptions,
|
|
37
36
|
extractPersistedSchema,
|
|
38
37
|
TreeViewConfiguration,
|
|
39
38
|
type TreeBranch,
|
|
@@ -129,20 +128,20 @@ export const TreeAlpha: {
|
|
|
129
128
|
importVerbose<const TSchema extends ImplicitFieldSchema>(
|
|
130
129
|
schema: TSchema,
|
|
131
130
|
data: VerboseTree | undefined,
|
|
132
|
-
options?: Partial<
|
|
131
|
+
options?: Partial<TreeEncodingOptions>,
|
|
133
132
|
): Unhydrated<TreeFieldFromImplicitField<TSchema>>;
|
|
134
133
|
|
|
135
134
|
/**
|
|
136
135
|
* Copy a snapshot of the current version of a TreeNode into a {@link ConciseTree}.
|
|
137
136
|
*/
|
|
138
|
-
exportConcise(node: TreeNode | TreeLeafValue, options?:
|
|
137
|
+
exportConcise(node: TreeNode | TreeLeafValue, options?: TreeEncodingOptions): ConciseTree;
|
|
139
138
|
|
|
140
139
|
/**
|
|
141
140
|
* Copy a snapshot of the current version of a TreeNode into a {@link ConciseTree}, allowing undefined.
|
|
142
141
|
*/
|
|
143
142
|
exportConcise(
|
|
144
143
|
node: TreeNode | TreeLeafValue | undefined,
|
|
145
|
-
options?:
|
|
144
|
+
options?: TreeEncodingOptions,
|
|
146
145
|
): ConciseTree | undefined;
|
|
147
146
|
|
|
148
147
|
/**
|
|
@@ -159,7 +158,7 @@ export const TreeAlpha: {
|
|
|
159
158
|
*
|
|
160
159
|
* 3. When easy access to the type is desired.
|
|
161
160
|
*/
|
|
162
|
-
exportVerbose(node: TreeNode | TreeLeafValue, options?:
|
|
161
|
+
exportVerbose(node: TreeNode | TreeLeafValue, options?: TreeEncodingOptions): VerboseTree;
|
|
163
162
|
|
|
164
163
|
/**
|
|
165
164
|
* Export the content of the provided `tree` in a compressed JSON compatible format.
|
|
@@ -167,7 +166,7 @@ export const TreeAlpha: {
|
|
|
167
166
|
* If an `idCompressor` is provided, it will be used to compress identifiers and thus will be needed to decompress the data.
|
|
168
167
|
*
|
|
169
168
|
* Always uses "stored" keys.
|
|
170
|
-
* See {@link
|
|
169
|
+
* See {@link TreeEncodingOptions.useStoredKeys} for details.
|
|
171
170
|
* @privateRemarks
|
|
172
171
|
* TODO: It is currently not clear how to work with the idCompressors correctly in the package API.
|
|
173
172
|
* Better APIs should probably be provided as there is currently no way to associate an un-hydrated tree with an idCompressor,
|
|
@@ -243,9 +242,9 @@ export const TreeAlpha: {
|
|
|
243
242
|
importVerbose<const TSchema extends ImplicitFieldSchema>(
|
|
244
243
|
schema: TSchema,
|
|
245
244
|
data: VerboseTree | undefined,
|
|
246
|
-
options?:
|
|
245
|
+
options?: TreeEncodingOptions,
|
|
247
246
|
): Unhydrated<TreeFieldFromImplicitField<TSchema>> {
|
|
248
|
-
const config:
|
|
247
|
+
const config: TreeEncodingOptions = { ...options };
|
|
249
248
|
// Create a config which is standalone, and thus can be used without having to refer back to the schema.
|
|
250
249
|
const schemalessConfig = applySchemaToParserOptions(schema, config);
|
|
251
250
|
if (data === undefined) {
|
|
@@ -261,8 +260,8 @@ export const TreeAlpha: {
|
|
|
261
260
|
|
|
262
261
|
exportConcise,
|
|
263
262
|
|
|
264
|
-
exportVerbose(node: TreeNode | TreeLeafValue, options?:
|
|
265
|
-
const config:
|
|
263
|
+
exportVerbose(node: TreeNode | TreeLeafValue, options?: TreeEncodingOptions): VerboseTree {
|
|
264
|
+
const config: TreeEncodingOptions = { ...options };
|
|
266
265
|
|
|
267
266
|
const cursor = borrowCursorFromTreeNodeOrValue(node);
|
|
268
267
|
return verboseFromCursor(
|
|
@@ -314,21 +313,24 @@ export const TreeAlpha: {
|
|
|
314
313
|
},
|
|
315
314
|
};
|
|
316
315
|
|
|
317
|
-
function exportConcise(
|
|
316
|
+
function exportConcise(
|
|
317
|
+
node: TreeNode | TreeLeafValue,
|
|
318
|
+
options?: TreeEncodingOptions,
|
|
319
|
+
): ConciseTree;
|
|
318
320
|
|
|
319
321
|
function exportConcise(
|
|
320
322
|
node: TreeNode | TreeLeafValue | undefined,
|
|
321
|
-
options?:
|
|
323
|
+
options?: TreeEncodingOptions,
|
|
322
324
|
): ConciseTree | undefined;
|
|
323
325
|
|
|
324
326
|
function exportConcise(
|
|
325
327
|
node: TreeNode | TreeLeafValue | undefined,
|
|
326
|
-
options?:
|
|
328
|
+
options?: TreeEncodingOptions,
|
|
327
329
|
): ConciseTree | undefined {
|
|
328
330
|
if (node === undefined) {
|
|
329
331
|
return undefined;
|
|
330
332
|
}
|
|
331
|
-
const config:
|
|
333
|
+
const config: TreeEncodingOptions = { ...options };
|
|
332
334
|
|
|
333
335
|
const cursor = borrowCursorFromTreeNodeOrValue(node);
|
|
334
336
|
return conciseFromCursor(
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
7
7
|
import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
|
|
8
8
|
import type { IIdCompressor, SessionId } from "@fluidframework/id-compressor";
|
|
9
|
-
import type { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
|
|
10
9
|
import type {
|
|
11
10
|
IExperimentalIncrementalSummaryContext,
|
|
12
11
|
IRuntimeMessageCollection,
|
|
@@ -331,28 +330,6 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
|
|
|
331
330
|
this.resubmitMachine.onCommitSubmitted(enrichedCommit);
|
|
332
331
|
}
|
|
333
332
|
|
|
334
|
-
/**
|
|
335
|
-
* Process a message from the runtime.
|
|
336
|
-
* @deprecated - Use processMessagesCore to process a bunch of messages together.
|
|
337
|
-
*/
|
|
338
|
-
public processCore(
|
|
339
|
-
message: ISequencedDocumentMessage,
|
|
340
|
-
local: boolean,
|
|
341
|
-
localOpMetadata: unknown,
|
|
342
|
-
): void {
|
|
343
|
-
this.processMessagesCore({
|
|
344
|
-
envelope: message,
|
|
345
|
-
local,
|
|
346
|
-
messagesContent: [
|
|
347
|
-
{
|
|
348
|
-
clientSequenceNumber: message.clientSequenceNumber,
|
|
349
|
-
contents: message.contents,
|
|
350
|
-
localOpMetadata,
|
|
351
|
-
},
|
|
352
|
-
],
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
|
|
356
333
|
/**
|
|
357
334
|
* Process a bunch of messages from the runtime. SharedObject will call this method with a bunch of messages.
|
|
358
335
|
*/
|
|
@@ -11,7 +11,7 @@ import type { TreeNodeSchema } from "../core/index.js";
|
|
|
11
11
|
import {
|
|
12
12
|
customFromCursor,
|
|
13
13
|
replaceHandles,
|
|
14
|
-
type
|
|
14
|
+
type TreeEncodingOptions,
|
|
15
15
|
type HandleConverter,
|
|
16
16
|
} from "./customTree.js";
|
|
17
17
|
import { getUnhydratedContext } from "../createContext.js";
|
|
@@ -44,9 +44,9 @@ export type ConciseTree<THandle = IFluidHandle> =
|
|
|
44
44
|
export function conciseFromCursor(
|
|
45
45
|
reader: ITreeCursor,
|
|
46
46
|
rootSchema: ImplicitAllowedTypes,
|
|
47
|
-
options:
|
|
47
|
+
options: TreeEncodingOptions,
|
|
48
48
|
): ConciseTree {
|
|
49
|
-
const config: Required<
|
|
49
|
+
const config: Required<TreeEncodingOptions> = {
|
|
50
50
|
useStoredKeys: false,
|
|
51
51
|
...options,
|
|
52
52
|
};
|
|
@@ -57,7 +57,7 @@ export function conciseFromCursor(
|
|
|
57
57
|
|
|
58
58
|
function conciseFromCursorInner(
|
|
59
59
|
reader: ITreeCursor,
|
|
60
|
-
options: Required<
|
|
60
|
+
options: Required<TreeEncodingOptions>,
|
|
61
61
|
schema: ReadonlyMap<string, TreeNodeSchema>,
|
|
62
62
|
): ConciseTree {
|
|
63
63
|
return customFromCursor(reader, options, schema, conciseFromCursorInner);
|
|
@@ -33,26 +33,20 @@ import { isObjectNodeSchema } from "../objectNodeTypes.js";
|
|
|
33
33
|
import { FieldKinds, valueSchemaAllows } from "../../feature-libraries/index.js";
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Options for how to encode a tree.
|
|
36
|
+
* Options for how to interpret or encode a tree when schema information is available.
|
|
37
37
|
* @alpha
|
|
38
38
|
*/
|
|
39
|
-
export interface
|
|
39
|
+
export interface TreeEncodingOptions {
|
|
40
40
|
/**
|
|
41
|
-
* If true,
|
|
42
|
-
* If false,
|
|
41
|
+
* If true, use the stored keys of object nodes.
|
|
42
|
+
* If false, use the property keys.
|
|
43
|
+
* @remarks
|
|
44
|
+
* Has no effect on {@link NodeKind}s other than {@link NodeKind.Object}.
|
|
43
45
|
* @defaultValue false.
|
|
44
46
|
*/
|
|
45
47
|
readonly useStoredKeys?: boolean;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
/**
|
|
49
|
-
* Options for how to transcode handles.
|
|
50
|
-
* @remarks
|
|
51
|
-
* Can be applied using {@link replaceHandles}.
|
|
52
|
-
* @alpha
|
|
53
|
-
*/
|
|
54
|
-
export type HandleConverter<TCustom> = (data: IFluidHandle) => TCustom;
|
|
55
|
-
|
|
56
50
|
/**
|
|
57
51
|
* Options for how to interpret a `ConciseTree<TCustom>` without relying on schema.
|
|
58
52
|
*/
|
|
@@ -86,11 +80,11 @@ export type CustomTreeNode<TChild> = TChild[] | { [key: string]: TChild };
|
|
|
86
80
|
*/
|
|
87
81
|
export function customFromCursor<TChild>(
|
|
88
82
|
reader: ITreeCursor,
|
|
89
|
-
options: Required<
|
|
83
|
+
options: Required<TreeEncodingOptions>,
|
|
90
84
|
schema: ReadonlyMap<string, TreeNodeSchema>,
|
|
91
85
|
childHandler: (
|
|
92
86
|
reader: ITreeCursor,
|
|
93
|
-
options: Required<
|
|
87
|
+
options: Required<TreeEncodingOptions>,
|
|
94
88
|
schema: ReadonlyMap<string, TreeNodeSchema>,
|
|
95
89
|
) => TChild,
|
|
96
90
|
): CustomTree<TChild> {
|
|
@@ -203,6 +197,14 @@ export function tryStoredSchemaAsArray(
|
|
|
203
197
|
}
|
|
204
198
|
}
|
|
205
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Options for how to transcode handles.
|
|
202
|
+
* @remarks
|
|
203
|
+
* Can be applied using {@link replaceHandles}.
|
|
204
|
+
* @alpha
|
|
205
|
+
*/
|
|
206
|
+
export type HandleConverter<TCustom> = (data: IFluidHandle) => TCustom;
|
|
207
|
+
|
|
206
208
|
/**
|
|
207
209
|
* Clones tree, replacing any handles.
|
|
208
210
|
* @remarks
|
|
@@ -4,16 +4,25 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { JsonTreeSchema } from "./jsonSchema.js";
|
|
7
|
-
import type {
|
|
7
|
+
import type { ImplicitAllowedTypes } from "../schemaTypes.js";
|
|
8
8
|
import { toJsonSchema } from "./simpleSchemaToJsonSchema.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import type { TreeNodeSchema } from "../core/index.js";
|
|
9
|
+
import type { TreeEncodingOptions } from "./customTree.js";
|
|
10
|
+
import { TreeViewConfigurationAlpha } from "./tree.js";
|
|
12
11
|
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
13
|
+
* Options for how to interpret or encode a tree when schema information is available.
|
|
14
|
+
* @alpha
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
export interface TreeSchemaEncodingOptions extends TreeEncodingOptions {
|
|
17
|
+
/**
|
|
18
|
+
* If true, fields with default providers (like {@link SchemaFactory.identifier}) will be required.
|
|
19
|
+
* If false, they will be optional.
|
|
20
|
+
* @remarks
|
|
21
|
+
* Has no effect on {@link NodeKind}s other than {@link NodeKind.Object}.
|
|
22
|
+
* @defaultValue false.
|
|
23
|
+
*/
|
|
24
|
+
readonly requireFieldsWithDefaults?: boolean;
|
|
25
|
+
}
|
|
17
26
|
|
|
18
27
|
/**
|
|
19
28
|
* Creates a {@link https://json-schema.org/ | JSON Schema} representation of the provided {@link TreeNodeSchema}.
|
|
@@ -63,18 +72,18 @@ const jsonSchemaCache = new WeakMap<TreeNodeSchema, JsonTreeSchema>();
|
|
|
63
72
|
* TODO:
|
|
64
73
|
* This API should allow generating JSON schema for the whole matrix of combinations:
|
|
65
74
|
*
|
|
66
|
-
* 1. VerboseTree and ConciseTree
|
|
67
|
-
* 2. With and without requiring values with defaults (for insertion vs reading)
|
|
68
|
-
* 3. Using stored keys and property keys
|
|
69
|
-
*
|
|
70
|
-
* This current API seems to give ConciseTree with property keys and ignoring default values.
|
|
75
|
+
* 1. VerboseTree and (Done) ConciseTree
|
|
76
|
+
* 2. (Done) With and without requiring values with defaults (for insertion vs reading)
|
|
77
|
+
* 3. (Done) Using stored keys and property keys.
|
|
71
78
|
*
|
|
79
|
+
* This takes in `ImplicitAllowedTypes` since underlying `toJsonSchema` can't handle optional roots.
|
|
72
80
|
*
|
|
73
81
|
* @alpha
|
|
74
82
|
*/
|
|
75
|
-
export function getJsonSchema(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
83
|
+
export function getJsonSchema(
|
|
84
|
+
schema: ImplicitAllowedTypes,
|
|
85
|
+
options: Required<TreeSchemaEncodingOptions>,
|
|
86
|
+
): JsonTreeSchema {
|
|
87
|
+
const treeSchema = new TreeViewConfigurationAlpha({ schema });
|
|
88
|
+
return toJsonSchema(treeSchema, options);
|
|
80
89
|
}
|
|
@@ -3,39 +3,25 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { getOrCreate } from "../../util/index.js";
|
|
7
|
-
import type { TreeNodeSchema } from "../core/index.js";
|
|
8
6
|
import type { ImplicitFieldSchema } from "../schemaTypes.js";
|
|
9
7
|
import type { SimpleTreeSchema } from "../simpleSchema.js";
|
|
10
8
|
import { toSimpleTreeSchema } from "./viewSchemaToSimpleSchema.js";
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
const simpleSchemaCache = new WeakMap<TreeNodeSchema, SimpleTreeSchema>();
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a {@link SimpleTreeSchema} from the provided {@link ImplicitFieldSchema}.
|
|
11
|
+
* Copies data from {@link ImplicitFieldSchema} to create a {@link SimpleTreeSchema} out of new plain JavaScript objects, Sets and Maps.
|
|
19
12
|
*
|
|
20
13
|
* @remarks
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* Caches the result on the input schema for future calls.
|
|
14
|
+
* See also {@link TreeViewConfigurationAlpha} which implements {@link SimpleTreeSchema} as a way to get a `SimpleTreeSchema` without copying the node and field schema and without losing as much type information.
|
|
24
15
|
*
|
|
25
16
|
* @privateRemarks
|
|
26
17
|
* In the future, we may wish to move this to a more discoverable API location.
|
|
27
18
|
* For now, while still an experimental API, it is surfaced as a free function.
|
|
28
19
|
*
|
|
29
|
-
* If the main use for this is the "definitions" map, we should provide a better way to access it (that doesn't type erase the TreeNodeSchema down to SimpleNodeSchema).
|
|
30
|
-
* TODO: Having TreeViewConfiguration implement SimpleTreeSchema directly but with more specific types would be a good way to do this.
|
|
31
|
-
*
|
|
32
20
|
* Note that all TreeNodeSchema get a {@link Context} cached on them as part of one time initialization which contains a map from identifier to all transitively referenced schema.
|
|
33
21
|
* Perhaps exposing access to that would cover this use-case as well.
|
|
34
22
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* @internal
|
|
23
|
+
* @alpha
|
|
38
24
|
*/
|
|
39
25
|
export function getSimpleSchema(schema: ImplicitFieldSchema): SimpleTreeSchema {
|
|
40
|
-
return
|
|
26
|
+
return toSimpleTreeSchema(schema, true);
|
|
41
27
|
}
|
|
@@ -9,6 +9,8 @@ export {
|
|
|
9
9
|
type ViewableTree,
|
|
10
10
|
type TreeViewEvents,
|
|
11
11
|
TreeViewConfiguration,
|
|
12
|
+
TreeViewConfigurationAlpha,
|
|
13
|
+
type TreeSchema,
|
|
12
14
|
type ITreeViewConfiguration,
|
|
13
15
|
type SchemaCompatibilityStatus,
|
|
14
16
|
type ITreeConfigurationOptions,
|
|
@@ -51,6 +53,7 @@ export {
|
|
|
51
53
|
type JsonFieldSchema,
|
|
52
54
|
type JsonLeafSchemaType,
|
|
53
55
|
} from "./jsonSchema.js";
|
|
56
|
+
export type { TreeSchemaEncodingOptions } from "./getJsonSchema.js";
|
|
54
57
|
export { getJsonSchema } from "./getJsonSchema.js";
|
|
55
58
|
export { getSimpleSchema } from "./getSimpleSchema.js";
|
|
56
59
|
export { ViewSchema } from "./view.js";
|
|
@@ -85,7 +88,6 @@ export type {
|
|
|
85
88
|
|
|
86
89
|
export {
|
|
87
90
|
type VerboseTreeNode,
|
|
88
|
-
type ParseOptions,
|
|
89
91
|
type VerboseTree,
|
|
90
92
|
applySchemaToParserOptions,
|
|
91
93
|
cursorFromVerbose,
|
|
@@ -94,7 +96,7 @@ export {
|
|
|
94
96
|
} from "./verboseTree.js";
|
|
95
97
|
|
|
96
98
|
export {
|
|
97
|
-
type
|
|
99
|
+
type TreeEncodingOptions,
|
|
98
100
|
customFromCursorStored,
|
|
99
101
|
type CustomTreeNode,
|
|
100
102
|
type CustomTreeValue,
|
|
@@ -69,7 +69,19 @@ export class SchemaFactoryAlpha<
|
|
|
69
69
|
name: Name,
|
|
70
70
|
fields: T,
|
|
71
71
|
options?: SchemaFactoryObjectOptions<TCustomMetadata>,
|
|
72
|
-
): ObjectNodeSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> {
|
|
72
|
+
): ObjectNodeSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> & {
|
|
73
|
+
/**
|
|
74
|
+
* Typing checking workaround: not for for actual use.
|
|
75
|
+
* @remarks
|
|
76
|
+
* This API collides with {@link TreeNodeSchemaCore.createFromInsertable} to disable a type checking optimization which produces different and undesired results.
|
|
77
|
+
* See {@link https://github.com/microsoft/TypeScript/issues/59049#issuecomment-2773459693} for more details.
|
|
78
|
+
* @privateRemarks
|
|
79
|
+
* The specific issue here is non-empty POJO mode object schema not being assignable to `ObjectNodeSchema`,
|
|
80
|
+
* See the above link and the tests in objectNode.spec.ts which reference it.
|
|
81
|
+
* @system
|
|
82
|
+
*/
|
|
83
|
+
readonly createFromInsertable: unknown;
|
|
84
|
+
} {
|
|
73
85
|
return objectSchema(
|
|
74
86
|
this.scoped2(name),
|
|
75
87
|
fields,
|
|
@@ -136,6 +148,11 @@ export class SchemaFactoryAlpha<
|
|
|
136
148
|
>;
|
|
137
149
|
}
|
|
138
150
|
|
|
151
|
+
/**
|
|
152
|
+
* {@inheritDoc SchemaStatics.optional}
|
|
153
|
+
*/
|
|
154
|
+
public static override readonly leaves = schemaStatics.leaves;
|
|
155
|
+
|
|
139
156
|
/**
|
|
140
157
|
* {@inheritDoc SchemaStatics.optional}
|
|
141
158
|
*/
|
|
@@ -10,14 +10,15 @@ import {
|
|
|
10
10
|
type AllowedTypes,
|
|
11
11
|
type FieldSchemaAlpha,
|
|
12
12
|
FieldKind,
|
|
13
|
+
type FieldProps,
|
|
13
14
|
} from "../schemaTypes.js";
|
|
14
|
-
import { SchemaFactory } from "./schemaFactory.js";
|
|
15
15
|
import type {
|
|
16
16
|
SimpleFieldSchema,
|
|
17
17
|
SimpleNodeSchema,
|
|
18
18
|
SimpleTreeSchema,
|
|
19
19
|
} from "../simpleSchema.js";
|
|
20
20
|
import { SchemaFactoryAlpha } from "./schemaFactoryAlpha.js";
|
|
21
|
+
import type { TreeSchema } from "./tree.js";
|
|
21
22
|
|
|
22
23
|
const factory = new SchemaFactoryAlpha(undefined);
|
|
23
24
|
|
|
@@ -30,31 +31,53 @@ const factory = new SchemaFactoryAlpha(undefined);
|
|
|
30
31
|
* will produce a poor TypeScript typing experience which is subject to change.
|
|
31
32
|
*
|
|
32
33
|
* Editing through a view produced using this schema can easily violate invariants other users of the document might expect and must be done with great care.
|
|
34
|
+
*
|
|
35
|
+
* This API bakes in some arbitrary policy choices for how to handle data that is not included in the SimpleTreeSchema API, for example the value of `allowUnknownOptionalFields`.
|
|
36
|
+
* If any particular choice is required for such cases, this API should not be used.
|
|
33
37
|
* @alpha
|
|
34
38
|
*/
|
|
35
|
-
export function generateSchemaFromSimpleSchema(simple: SimpleTreeSchema):
|
|
39
|
+
export function generateSchemaFromSimpleSchema(simple: SimpleTreeSchema): TreeSchema {
|
|
36
40
|
const context: Context = new Map(
|
|
37
|
-
[...simple.definitions].map(
|
|
38
|
-
id,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
[...simple.definitions].map(
|
|
42
|
+
([id, schema]): [string, () => TreeNodeSchema & SimpleNodeSchema] => [
|
|
43
|
+
id,
|
|
44
|
+
// This relies on the caching in evaluateLazySchema so that it only runs once.
|
|
45
|
+
() => generateNode(id, schema, context),
|
|
46
|
+
],
|
|
47
|
+
),
|
|
42
48
|
);
|
|
43
|
-
|
|
49
|
+
const root = generateFieldSchema(simple.root, context, undefined);
|
|
50
|
+
const definitions = new Map<string, TreeNodeSchema & SimpleNodeSchema>();
|
|
51
|
+
for (const [id, lazy] of context) {
|
|
52
|
+
definitions.set(id, lazy());
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
root,
|
|
56
|
+
definitions,
|
|
57
|
+
};
|
|
44
58
|
}
|
|
45
59
|
|
|
46
|
-
type Context = ReadonlyMap<string, () => TreeNodeSchema>;
|
|
60
|
+
type Context = ReadonlyMap<string, () => TreeNodeSchema & SimpleNodeSchema>;
|
|
47
61
|
|
|
48
|
-
function generateFieldSchema(
|
|
62
|
+
function generateFieldSchema(
|
|
63
|
+
simple: SimpleFieldSchema,
|
|
64
|
+
context: Context,
|
|
65
|
+
storedKey: string | undefined,
|
|
66
|
+
): FieldSchemaAlpha {
|
|
49
67
|
const allowed = generateAllowedTypes(simple.allowedTypesIdentifiers, context);
|
|
68
|
+
const props: Omit<FieldProps, "defaultProvider"> = {
|
|
69
|
+
metadata: simple.metadata,
|
|
70
|
+
key: storedKey,
|
|
71
|
+
};
|
|
72
|
+
|
|
50
73
|
// Using createFieldSchema could work, but would require setting up the default providers.
|
|
51
74
|
switch (simple.kind) {
|
|
52
75
|
case FieldKind.Identifier:
|
|
53
|
-
return SchemaFactoryAlpha.identifier(
|
|
76
|
+
return SchemaFactoryAlpha.identifier(props);
|
|
54
77
|
case FieldKind.Optional:
|
|
55
|
-
return SchemaFactoryAlpha.optional(allowed,
|
|
78
|
+
return SchemaFactoryAlpha.optional(allowed, props);
|
|
56
79
|
case FieldKind.Required:
|
|
57
|
-
return SchemaFactoryAlpha.required(allowed,
|
|
80
|
+
return SchemaFactoryAlpha.required(allowed, props);
|
|
58
81
|
default:
|
|
59
82
|
return unreachableCase(simple.kind);
|
|
60
83
|
}
|
|
@@ -64,13 +87,19 @@ function generateAllowedTypes(allowed: ReadonlySet<string>, context: Context): A
|
|
|
64
87
|
return [...allowed].map((id) => context.get(id) ?? fail(0xb5a /* Missing schema */));
|
|
65
88
|
}
|
|
66
89
|
|
|
67
|
-
function generateNode(
|
|
90
|
+
function generateNode(
|
|
91
|
+
id: string,
|
|
92
|
+
schema: SimpleNodeSchema,
|
|
93
|
+
context: Context,
|
|
94
|
+
): TreeNodeSchema & SimpleNodeSchema {
|
|
68
95
|
switch (schema.kind) {
|
|
69
96
|
case NodeKind.Object: {
|
|
70
97
|
const fields: Record<string, FieldSchema> = {};
|
|
71
98
|
for (const [key, field] of schema.fields) {
|
|
72
|
-
fields[key] = generateFieldSchema(field, context);
|
|
99
|
+
fields[key] = generateFieldSchema(field, context, field.storedKey);
|
|
73
100
|
}
|
|
101
|
+
// Here allowUnknownOptionalFields is implicitly defaulting. This is a subjective policy choice:
|
|
102
|
+
// users of this code are expected to handle what ever choice this code makes for cases like this.
|
|
74
103
|
return factory.object(id, fields, { metadata: schema.metadata });
|
|
75
104
|
}
|
|
76
105
|
case NodeKind.Array:
|
|
@@ -87,7 +116,7 @@ function generateNode(id: string, schema: SimpleNodeSchema, context: Context): T
|
|
|
87
116
|
);
|
|
88
117
|
case NodeKind.Leaf:
|
|
89
118
|
return (
|
|
90
|
-
|
|
119
|
+
SchemaFactoryAlpha.leaves.find((leaf) => leaf.identifier === id) ??
|
|
91
120
|
fail(0xb5b /* Missing schema */)
|
|
92
121
|
);
|
|
93
122
|
default:
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { unreachableCase } from "@fluidframework/core-utils/internal";
|
|
7
7
|
import { UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
8
8
|
import { ValueSchema } from "../../core/index.js";
|
|
9
|
-
import { copyProperty,
|
|
9
|
+
import { copyProperty, hasSingle, type Mutable } from "../../util/index.js";
|
|
10
10
|
import type {
|
|
11
11
|
JsonArrayNodeSchema,
|
|
12
12
|
JsonFieldSchema,
|
|
@@ -24,24 +24,39 @@ import type {
|
|
|
24
24
|
SimpleArrayNodeSchema,
|
|
25
25
|
SimpleLeafNodeSchema,
|
|
26
26
|
SimpleMapNodeSchema,
|
|
27
|
-
SimpleNodeSchema,
|
|
28
|
-
SimpleObjectNodeSchema,
|
|
29
|
-
SimpleTreeSchema,
|
|
30
27
|
} from "../simpleSchema.js";
|
|
31
|
-
import { NodeKind } from "../core/index.js";
|
|
28
|
+
import { NodeKind, type TreeNodeSchema } from "../core/index.js";
|
|
29
|
+
import type { TreeSchema } from "./tree.js";
|
|
30
|
+
import type { TreeSchemaEncodingOptions } from "./getJsonSchema.js";
|
|
31
|
+
import { ObjectNodeSchema } from "../objectNodeTypes.js";
|
|
32
|
+
import { ArrayNodeSchema } from "../arrayNodeTypes.js";
|
|
33
|
+
import { MapNodeSchema } from "../mapNodeTypes.js";
|
|
34
|
+
import { LeafNodeSchema } from "../leafNodeSchema.js";
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* Generates a JSON Schema representation from a simple tree schema.
|
|
38
|
+
* @remarks
|
|
39
|
+
* This expects the data to be in the {@link ConciseTree} format.
|
|
40
|
+
*
|
|
41
|
+
* This cannot handle the case where the root is undefined since undefined is not a concept in JSON.
|
|
42
|
+
* This also cannot handle {@link SchemaStatics.handle} since they also are not supported in JSON.
|
|
43
|
+
*
|
|
35
44
|
* @internal
|
|
36
45
|
*/
|
|
37
|
-
export function toJsonSchema(
|
|
38
|
-
|
|
46
|
+
export function toJsonSchema(
|
|
47
|
+
schema: TreeSchema,
|
|
48
|
+
options: Required<TreeSchemaEncodingOptions>,
|
|
49
|
+
): JsonTreeSchema {
|
|
50
|
+
const definitions = convertDefinitions(schema.definitions, options);
|
|
39
51
|
|
|
40
52
|
const allowedTypes: JsonSchemaRef[] = [];
|
|
41
|
-
for (const allowedType of schema.allowedTypesIdentifiers) {
|
|
53
|
+
for (const allowedType of schema.root.allowedTypesIdentifiers) {
|
|
42
54
|
allowedTypes.push(createSchemaRef(allowedType));
|
|
43
55
|
}
|
|
44
56
|
|
|
57
|
+
// TODO: deduplicate field handling logic from convertObjectNodeSchema: at least include metadata's description.
|
|
58
|
+
// TODO: maybe account for consider schema.kind, or just take in ImplicitAllowedTypes
|
|
59
|
+
// TODO: handle case where allowedTypes is empty.
|
|
45
60
|
return hasSingle(allowedTypes)
|
|
46
61
|
? {
|
|
47
62
|
...allowedTypes[0],
|
|
@@ -54,40 +69,35 @@ export function toJsonSchema(schema: SimpleTreeSchema): JsonTreeSchema {
|
|
|
54
69
|
}
|
|
55
70
|
|
|
56
71
|
function convertDefinitions(
|
|
57
|
-
definitions: ReadonlyMap<string,
|
|
72
|
+
definitions: ReadonlyMap<string, TreeNodeSchema>,
|
|
73
|
+
options: Required<TreeSchemaEncodingOptions>,
|
|
58
74
|
): Record<string, JsonNodeSchema> {
|
|
59
75
|
const result: Record<string, JsonNodeSchema> = {};
|
|
60
76
|
for (const [key, value] of definitions) {
|
|
61
|
-
result[key] = convertNodeSchema(value);
|
|
77
|
+
result[key] = convertNodeSchema(value, options);
|
|
62
78
|
}
|
|
63
79
|
return result;
|
|
64
80
|
}
|
|
65
81
|
|
|
66
|
-
/**
|
|
67
|
-
* Private symbol under which the results of {@link convertNodeSchema} are cached on an input {@link SimpleNodeSchema}.
|
|
68
|
-
*/
|
|
69
|
-
const nodeJsonSchemaCache = new WeakMap<SimpleNodeSchema, JsonNodeSchema>();
|
|
70
|
-
|
|
71
82
|
/**
|
|
72
83
|
* Converts an input {@link SimpleNodeSchema} to a {@link JsonNodeSchema}.
|
|
73
84
|
*
|
|
74
85
|
* @remarks Caches the result on the input schema for future calls.
|
|
75
86
|
*/
|
|
76
|
-
function convertNodeSchema(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
87
|
+
function convertNodeSchema(
|
|
88
|
+
schema: TreeNodeSchema,
|
|
89
|
+
options: Required<TreeSchemaEncodingOptions>,
|
|
90
|
+
): JsonNodeSchema {
|
|
91
|
+
if (schema instanceof ArrayNodeSchema) {
|
|
92
|
+
return convertArrayNodeSchema(schema);
|
|
93
|
+
} else if (schema instanceof MapNodeSchema) {
|
|
94
|
+
return convertMapNodeSchema(schema);
|
|
95
|
+
} else if (schema instanceof ObjectNodeSchema) {
|
|
96
|
+
return convertObjectNodeSchema(schema, options);
|
|
97
|
+
} else if (schema instanceof LeafNodeSchema) {
|
|
98
|
+
return convertLeafNodeSchema(schema);
|
|
99
|
+
}
|
|
100
|
+
throw new TypeError(`Unknown node schema kind: ${schema.kind}`);
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
function convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSchema {
|
|
@@ -138,10 +148,14 @@ function convertLeafNodeSchema(schema: SimpleLeafNodeSchema): JsonLeafNodeSchema
|
|
|
138
148
|
};
|
|
139
149
|
}
|
|
140
150
|
|
|
141
|
-
export function convertObjectNodeSchema(
|
|
151
|
+
export function convertObjectNodeSchema(
|
|
152
|
+
schema: ObjectNodeSchema,
|
|
153
|
+
options: Required<TreeSchemaEncodingOptions>,
|
|
154
|
+
): JsonObjectNodeSchema {
|
|
142
155
|
const properties: Record<string, JsonFieldSchema> = {};
|
|
143
156
|
const required: string[] = [];
|
|
144
|
-
for (const [
|
|
157
|
+
for (const [propertyKey, fieldSchema] of schema.fields) {
|
|
158
|
+
const key = options.useStoredKeys ? fieldSchema.storedKey : propertyKey;
|
|
145
159
|
const allowedTypes: JsonSchemaRef[] = [];
|
|
146
160
|
for (const allowedType of fieldSchema.allowedTypesIdentifiers) {
|
|
147
161
|
allowedTypes.push(createSchemaRef(allowedType));
|
|
@@ -156,8 +170,13 @@ export function convertObjectNodeSchema(schema: SimpleObjectNodeSchema): JsonObj
|
|
|
156
170
|
copyProperty(fieldSchema.metadata, "description", output);
|
|
157
171
|
properties[key] = output;
|
|
158
172
|
|
|
159
|
-
if (fieldSchema.kind
|
|
160
|
-
|
|
173
|
+
if (fieldSchema.kind !== FieldKind.Optional) {
|
|
174
|
+
if (
|
|
175
|
+
options.requireFieldsWithDefaults ||
|
|
176
|
+
fieldSchema.props?.defaultProvider === undefined
|
|
177
|
+
) {
|
|
178
|
+
required.push(key);
|
|
179
|
+
}
|
|
161
180
|
}
|
|
162
181
|
}
|
|
163
182
|
|