@fluidframework/tree-agent 2.74.0 → 2.81.0-374083

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.
Files changed (73) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/tree-agent.alpha.api.md +163 -20
  3. package/dist/alpha.d.ts +26 -1
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +5 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/methodBinding.d.ts +54 -10
  9. package/dist/methodBinding.d.ts.map +1 -1
  10. package/dist/methodBinding.js.map +1 -1
  11. package/dist/propertyBinding.d.ts +52 -2
  12. package/dist/propertyBinding.d.ts.map +1 -1
  13. package/dist/propertyBinding.js +28 -3
  14. package/dist/propertyBinding.js.map +1 -1
  15. package/dist/renderSchemaTypeScript.d.ts.map +1 -1
  16. package/dist/renderSchemaTypeScript.js +17 -8
  17. package/dist/renderSchemaTypeScript.js.map +1 -1
  18. package/dist/renderTypeFactoryTypeScript.d.ts +13 -0
  19. package/dist/renderTypeFactoryTypeScript.d.ts.map +1 -0
  20. package/dist/renderTypeFactoryTypeScript.js +222 -0
  21. package/dist/renderTypeFactoryTypeScript.js.map +1 -0
  22. package/dist/subtree.d.ts.map +1 -1
  23. package/dist/subtree.js +4 -4
  24. package/dist/subtree.js.map +1 -1
  25. package/dist/treeAgentTypes.d.ts +345 -0
  26. package/dist/treeAgentTypes.d.ts.map +1 -0
  27. package/dist/treeAgentTypes.js +190 -0
  28. package/dist/treeAgentTypes.js.map +1 -0
  29. package/dist/utils.d.ts +0 -4
  30. package/dist/utils.d.ts.map +1 -1
  31. package/dist/utils.js +2 -9
  32. package/dist/utils.js.map +1 -1
  33. package/eslint.config.mts +4 -4
  34. package/lib/alpha.d.ts +26 -1
  35. package/lib/index.d.ts +3 -1
  36. package/lib/index.d.ts.map +1 -1
  37. package/lib/index.js +1 -0
  38. package/lib/index.js.map +1 -1
  39. package/lib/methodBinding.d.ts +54 -10
  40. package/lib/methodBinding.d.ts.map +1 -1
  41. package/lib/methodBinding.js.map +1 -1
  42. package/lib/propertyBinding.d.ts +52 -2
  43. package/lib/propertyBinding.d.ts.map +1 -1
  44. package/lib/propertyBinding.js +28 -3
  45. package/lib/propertyBinding.js.map +1 -1
  46. package/lib/renderSchemaTypeScript.d.ts.map +1 -1
  47. package/lib/renderSchemaTypeScript.js +17 -8
  48. package/lib/renderSchemaTypeScript.js.map +1 -1
  49. package/lib/renderTypeFactoryTypeScript.d.ts +13 -0
  50. package/lib/renderTypeFactoryTypeScript.d.ts.map +1 -0
  51. package/lib/renderTypeFactoryTypeScript.js +217 -0
  52. package/lib/renderTypeFactoryTypeScript.js.map +1 -0
  53. package/lib/subtree.d.ts.map +1 -1
  54. package/lib/subtree.js +4 -4
  55. package/lib/subtree.js.map +1 -1
  56. package/lib/treeAgentTypes.d.ts +345 -0
  57. package/lib/treeAgentTypes.d.ts.map +1 -0
  58. package/lib/treeAgentTypes.js +186 -0
  59. package/lib/treeAgentTypes.js.map +1 -0
  60. package/lib/utils.d.ts +0 -4
  61. package/lib/utils.d.ts.map +1 -1
  62. package/lib/utils.js +2 -8
  63. package/lib/utils.js.map +1 -1
  64. package/package.json +17 -17
  65. package/src/index.ts +31 -0
  66. package/src/methodBinding.ts +94 -15
  67. package/src/propertyBinding.ts +66 -9
  68. package/src/renderSchemaTypeScript.ts +25 -9
  69. package/src/renderTypeFactoryTypeScript.ts +259 -0
  70. package/src/subtree.ts +6 -5
  71. package/src/treeAgentTypes.ts +490 -0
  72. package/src/utils.ts +2 -9
  73. package/.eslintrc.cjs +0 -48
package/dist/subtree.js CHANGED
@@ -22,7 +22,7 @@ class Subtree {
22
22
  }
23
23
  get branch() {
24
24
  return this.viewOrTree instanceof tree_1.TreeNode
25
- ? (alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)("Node cannot be raw."))
25
+ ? (alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)(0xcb3 /* Node cannot be raw. */))
26
26
  : this.viewOrTree;
27
27
  }
28
28
  get field() {
@@ -79,7 +79,7 @@ class Subtree {
79
79
  }
80
80
  }
81
81
  default: {
82
- (0, internal_1.fail)("Unexpected node kind");
82
+ (0, internal_1.fail)(0xcb4 /* Unexpected node kind */);
83
83
  }
84
84
  }
85
85
  }
@@ -95,9 +95,9 @@ class Subtree {
95
95
  }
96
96
  fork() {
97
97
  if (this.viewOrTree instanceof tree_1.TreeNode) {
98
- const branch = alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)("Node cannot be raw.");
98
+ const branch = alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)(0xcb5 /* Node cannot be raw. */);
99
99
  const node = (0, getNodeOnBranch_js_1.getNodeOnBranch)(this.viewOrTree, branch.fork()) ??
100
- (0, internal_1.fail)("Expected node to be on new fork.");
100
+ (0, internal_1.fail)(0xcb6 /* Expected node to be on new fork. */);
101
101
  return new Subtree(node);
102
102
  }
103
103
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAC3D,uEAAsE;AACtE,+CAAgE;AAOhE,sDAAuD;AAOvD,6DAAuD;AAGvD;;GAEG;AACH,MAAa,OAAO;IACnB,YAAmC,UAA6B;QAA7B,eAAU,GAAV,UAAU,CAAmB;QAC/D,IAAI,UAAU,YAAY,eAAQ,IAAI,iBAAS,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;YAClF,MAAM,IAAI,qBAAU,CAAC,4CAA4C,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,UAAU,YAAY,eAAQ;YACzC,CAAC,CAAC,CAAC,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAA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C9B,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAChB,CAAC;IACZ,CAAC;IAEM,IAAI;QACV,IAAI,IAAI,CAAC,UAAU,YAAY,eAAQ,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAA,eAAI,EAAC,qBAAqB,CAAC,CAAC;YAChF,MAAM,IAAI,GACT,IAAA,oCAAe,EAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC/C,IAAA,eAAI,EAAC,kCAAkC,CAAC,CAAC;YAE1C,OAAO,IAAI,OAAO,CAAQ,IAAI,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,OAAO,CAAQ,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;CACD;AA7FD,0BA6FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { TreeNode, Tree, NodeKind } from \"@fluidframework/tree\";\nimport type {\n\tImplicitFieldSchema,\n\tTreeFieldFromImplicitField,\n\tTreeMapNode,\n\tTreeArrayNode,\n} from \"@fluidframework/tree\";\nimport { TreeAlpha } from \"@fluidframework/tree/alpha\";\nimport type {\n\tReadableField,\n\tTreeRecordNode,\n\tTreeBranchAlpha,\n} from \"@fluidframework/tree/alpha\";\n\nimport { getNodeOnBranch } from \"./getNodeOnBranch.js\";\nimport type { TreeView, ViewOrTree } from \"./api.js\";\n\n/**\n * Wraps either a {@link TreeView} or a {@link TreeNode} and provides a common interface over them.\n */\nexport class Subtree<TRoot extends ImplicitFieldSchema> {\n\tpublic constructor(public readonly viewOrTree: ViewOrTree<TRoot>) {\n\t\tif (viewOrTree instanceof TreeNode && TreeAlpha.branch(viewOrTree) === undefined) {\n\t\t\tthrow new UsageError(\"The provided node must belong to a branch.\");\n\t\t}\n\t}\n\n\tpublic get branch(): TreeBranchAlpha {\n\t\treturn this.viewOrTree instanceof TreeNode\n\t\t\t? (TreeAlpha.branch(this.viewOrTree) ?? fail(\"Node cannot be raw.\"))\n\t\t\t: this.viewOrTree;\n\t}\n\n\tpublic get field(): ReadableField<TRoot> {\n\t\treturn this.viewOrTree instanceof TreeNode ? this.viewOrTree : this.viewOrTree.root;\n\t}\n\n\tpublic set field(value: TreeFieldFromImplicitField<TRoot>) {\n\t\tif (this.viewOrTree instanceof TreeNode) {\n\t\t\tconst parent = Tree.parent(this.viewOrTree);\n\t\t\tif (parent === undefined) {\n\t\t\t\t// In general, this is not a correct cast, but we know that the root of the branch at least allows the type of `value`\n\t\t\t\tconst view = this.branch as TreeView<TRoot>;\n\t\t\t\tview.root = value;\n\t\t\t} else {\n\t\t\t\tconst schema = Tree.schema(parent);\n\t\t\t\tswitch (schema.kind) {\n\t\t\t\t\tcase NodeKind.Object: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\t(parent as unknown as Record<string, unknown>)[key] = value;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Record: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\t\t\tdelete (parent as TreeRecordNode)[key];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t(parent as TreeRecordNode)[key] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Map: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\t(parent as TreeMapNode).delete(key);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t(parent as TreeMapNode).set(key, value as never);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Array: {\n\t\t\t\t\t\tconst index = Tree.key(this.viewOrTree) as number;\n\t\t\t\t\t\tconst arrayNode = parent as TreeArrayNode;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\tarrayNode.removeAt(index);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.branch.runTransaction(() => {\n\t\t\t\t\t\t\t\tarrayNode.removeAt(index);\n\t\t\t\t\t\t\t\tarrayNode.insertAt(index, value as never);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tfail(\"Unexpected node kind\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.viewOrTree.root = value;\n\t\t}\n\t}\n\n\tpublic get schema(): TRoot {\n\t\treturn (\n\t\t\tthis.viewOrTree instanceof TreeNode\n\t\t\t\t? Tree.schema(this.viewOrTree)\n\t\t\t\t: this.viewOrTree.schema\n\t\t) as TRoot;\n\t}\n\n\tpublic fork(): Subtree<TRoot> {\n\t\tif (this.viewOrTree instanceof TreeNode) {\n\t\t\tconst branch = TreeAlpha.branch(this.viewOrTree) ?? fail(\"Node cannot be raw.\");\n\t\t\tconst node =\n\t\t\t\tgetNodeOnBranch(this.viewOrTree, branch.fork()) ??\n\t\t\t\tfail(\"Expected node to be on new fork.\");\n\n\t\t\treturn new Subtree<TRoot>(node);\n\t\t} else {\n\t\t\treturn new Subtree<TRoot>(this.viewOrTree.fork());\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAC3D,uEAAsE;AACtE,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B,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAc,CAAC,CAAC;4BAC3C,CAAC,CAAC,CAAC;wBACJ,CAAC;oBACF,CAAC;oBACD,OAAO,CAAC,CAAC,CAAC;wBACT,IAAA,eAAI,EAAC,KAAK,CAAC,0BAA0B,CAAC,CAAC;oBACxC,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,KAAK,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,CACN,IAAI,CAAC,UAAU,YAAY,eAAQ;YAClC,CAAC,CAAC,WAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;YAC9B,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAChB,CAAC;IACZ,CAAC;IAEM,IAAI;QACV,IAAI,IAAI,CAAC,UAAU,YAAY,eAAQ,EAAE,CAAC;YACzC,MAAM,MAAM,GACX,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAA,eAAI,EAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC5E,MAAM,IAAI,GACT,IAAA,oCAAe,EAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC/C,IAAA,eAAI,EAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAEpD,OAAO,IAAI,OAAO,CAAQ,IAAI,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,OAAO,CAAQ,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;CACD;AA9FD,0BA8FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { TreeNode, Tree, NodeKind } from \"@fluidframework/tree\";\nimport type {\n\tImplicitFieldSchema,\n\tTreeFieldFromImplicitField,\n\tTreeMapNode,\n\tTreeArrayNode,\n} from \"@fluidframework/tree\";\nimport { TreeAlpha } from \"@fluidframework/tree/alpha\";\nimport type {\n\tReadableField,\n\tTreeRecordNode,\n\tTreeBranchAlpha,\n} from \"@fluidframework/tree/alpha\";\n\nimport type { TreeView, ViewOrTree } from \"./api.js\";\nimport { getNodeOnBranch } from \"./getNodeOnBranch.js\";\n\n/**\n * Wraps either a {@link TreeView} or a {@link TreeNode} and provides a common interface over them.\n */\nexport class Subtree<TRoot extends ImplicitFieldSchema> {\n\tpublic constructor(public readonly viewOrTree: ViewOrTree<TRoot>) {\n\t\tif (viewOrTree instanceof TreeNode && TreeAlpha.branch(viewOrTree) === undefined) {\n\t\t\tthrow new UsageError(\"The provided node must belong to a branch.\");\n\t\t}\n\t}\n\n\tpublic get branch(): TreeBranchAlpha {\n\t\treturn this.viewOrTree instanceof TreeNode\n\t\t\t? (TreeAlpha.branch(this.viewOrTree) ?? fail(0xcb3 /* Node cannot be raw. */))\n\t\t\t: this.viewOrTree;\n\t}\n\n\tpublic get field(): ReadableField<TRoot> {\n\t\treturn this.viewOrTree instanceof TreeNode ? this.viewOrTree : this.viewOrTree.root;\n\t}\n\n\tpublic set field(value: TreeFieldFromImplicitField<TRoot>) {\n\t\tif (this.viewOrTree instanceof TreeNode) {\n\t\t\tconst parent = Tree.parent(this.viewOrTree);\n\t\t\tif (parent === undefined) {\n\t\t\t\t// In general, this is not a correct cast, but we know that the root of the branch at least allows the type of `value`\n\t\t\t\tconst view = this.branch as TreeView<TRoot>;\n\t\t\t\tview.root = value;\n\t\t\t} else {\n\t\t\t\tconst schema = Tree.schema(parent);\n\t\t\t\tswitch (schema.kind) {\n\t\t\t\t\tcase NodeKind.Object: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\t(parent as unknown as Record<string, unknown>)[key] = value;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Record: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\t\t\tdelete (parent as TreeRecordNode)[key];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t(parent as TreeRecordNode)[key] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Map: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\t(parent as TreeMapNode).delete(key);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t(parent as TreeMapNode).set(key, value as never);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Array: {\n\t\t\t\t\t\tconst index = Tree.key(this.viewOrTree) as number;\n\t\t\t\t\t\tconst arrayNode = parent as TreeArrayNode;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\tarrayNode.removeAt(index);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.branch.runTransaction(() => {\n\t\t\t\t\t\t\t\tarrayNode.removeAt(index);\n\t\t\t\t\t\t\t\tarrayNode.insertAt(index, value as never);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tfail(0xcb4 /* Unexpected node kind */);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.viewOrTree.root = value;\n\t\t}\n\t}\n\n\tpublic get schema(): TRoot {\n\t\treturn (\n\t\t\tthis.viewOrTree instanceof TreeNode\n\t\t\t\t? Tree.schema(this.viewOrTree)\n\t\t\t\t: this.viewOrTree.schema\n\t\t) as TRoot;\n\t}\n\n\tpublic fork(): Subtree<TRoot> {\n\t\tif (this.viewOrTree instanceof TreeNode) {\n\t\t\tconst branch =\n\t\t\t\tTreeAlpha.branch(this.viewOrTree) ?? fail(0xcb5 /* Node cannot be raw. */);\n\t\t\tconst node =\n\t\t\t\tgetNodeOnBranch(this.viewOrTree, branch.fork()) ??\n\t\t\t\tfail(0xcb6 /* Expected node to be on new fork. */);\n\n\t\t\treturn new Subtree<TRoot>(node);\n\t\t} else {\n\t\t\treturn new Subtree<TRoot>(this.viewOrTree.fork());\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,345 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { TreeNodeSchemaClass } from "@fluidframework/tree/alpha";
6
+ import { ObjectNodeSchema } from "@fluidframework/tree/alpha";
7
+ /**
8
+ * Type kinds for the type factory type system.
9
+ * @alpha
10
+ */
11
+ export type TypeFactoryTypeKind = "string" | "number" | "boolean" | "void" | "undefined" | "null" | "unknown" | "array" | "object" | "record" | "map" | "tuple" | "union" | "literal" | "optional" | "readonly" | "instanceof";
12
+ /**
13
+ * Base interface for type factory types.
14
+ * @alpha
15
+ */
16
+ export interface TypeFactoryType {
17
+ /**
18
+ * The kind of type this represents.
19
+ */
20
+ readonly _kind: TypeFactoryTypeKind;
21
+ }
22
+ /**
23
+ * Type guard to check if a value is a type factory type.
24
+ * @alpha
25
+ */
26
+ export declare function isTypeFactoryType(value: unknown): value is TypeFactoryType;
27
+ /**
28
+ * Represents a string type in the type factory system.
29
+ * @alpha
30
+ */
31
+ export interface TypeFactoryString extends TypeFactoryType {
32
+ /**
33
+ * {@inheritDoc TypeFactoryType._kind}
34
+ */
35
+ readonly _kind: "string";
36
+ }
37
+ /**
38
+ * Represents a number type in the type factory system.
39
+ * @alpha
40
+ */
41
+ export interface TypeFactoryNumber extends TypeFactoryType {
42
+ /**
43
+ * {@inheritDoc TypeFactoryType._kind}
44
+ */
45
+ readonly _kind: "number";
46
+ }
47
+ /**
48
+ * Represents a boolean type in the type factory system.
49
+ * @alpha
50
+ */
51
+ export interface TypeFactoryBoolean extends TypeFactoryType {
52
+ /**
53
+ * {@inheritDoc TypeFactoryType._kind}
54
+ */
55
+ readonly _kind: "boolean";
56
+ }
57
+ /**
58
+ * Represents a void type in the type factory system.
59
+ * @alpha
60
+ */
61
+ export interface TypeFactoryVoid extends TypeFactoryType {
62
+ /**
63
+ * {@inheritDoc TypeFactoryType._kind}
64
+ */
65
+ readonly _kind: "void";
66
+ }
67
+ /**
68
+ * Represents an undefined type in the type factory system.
69
+ * @alpha
70
+ */
71
+ export interface TypeFactoryUndefined extends TypeFactoryType {
72
+ /**
73
+ * {@inheritDoc TypeFactoryType._kind}
74
+ */
75
+ readonly _kind: "undefined";
76
+ }
77
+ /**
78
+ * Represents a null type in the type factory system.
79
+ * @alpha
80
+ */
81
+ export interface TypeFactoryNull extends TypeFactoryType {
82
+ /**
83
+ * {@inheritDoc TypeFactoryType._kind}
84
+ */
85
+ readonly _kind: "null";
86
+ }
87
+ /**
88
+ * Represents an unknown type in the type factory system.
89
+ * @alpha
90
+ */
91
+ export interface TypeFactoryUnknown extends TypeFactoryType {
92
+ /**
93
+ * {@inheritDoc TypeFactoryType._kind}
94
+ */
95
+ readonly _kind: "unknown";
96
+ }
97
+ /**
98
+ * Represents an array type in the type factory system.
99
+ * @alpha
100
+ */
101
+ export interface TypeFactoryArray extends TypeFactoryType {
102
+ /**
103
+ * {@inheritDoc TypeFactoryType._kind}
104
+ */
105
+ readonly _kind: "array";
106
+ /**
107
+ * The type of elements in the array.
108
+ */
109
+ readonly element: TypeFactoryType;
110
+ }
111
+ /**
112
+ * Represents an object type with a fixed shape in the type factory system.
113
+ * @alpha
114
+ */
115
+ export interface TypeFactoryObject extends TypeFactoryType {
116
+ /**
117
+ * {@inheritDoc TypeFactoryType._kind}
118
+ */
119
+ readonly _kind: "object";
120
+ /**
121
+ * The shape of the object, mapping property names to their types.
122
+ */
123
+ readonly shape: Record<string, TypeFactoryType>;
124
+ }
125
+ /**
126
+ * Represents a record type (index signature) in the type factory system.
127
+ * @alpha
128
+ */
129
+ export interface TypeFactoryRecord extends TypeFactoryType {
130
+ /**
131
+ * {@inheritDoc TypeFactoryType._kind}
132
+ */
133
+ readonly _kind: "record";
134
+ /**
135
+ * The type of the record's keys.
136
+ */
137
+ readonly keyType: TypeFactoryType;
138
+ /**
139
+ * The type of the record's values.
140
+ */
141
+ readonly valueType: TypeFactoryType;
142
+ }
143
+ /**
144
+ * Represents a Map type in the type factory system.
145
+ * @alpha
146
+ */
147
+ export interface TypeFactoryMap extends TypeFactoryType {
148
+ /**
149
+ * {@inheritDoc TypeFactoryType._kind}
150
+ */
151
+ readonly _kind: "map";
152
+ /**
153
+ * The type of the map's keys.
154
+ */
155
+ readonly keyType: TypeFactoryType;
156
+ /**
157
+ * The type of the map's values.
158
+ */
159
+ readonly valueType: TypeFactoryType;
160
+ }
161
+ /**
162
+ * Represents a tuple type with fixed-length items and optional rest elements in the type factory system.
163
+ * @alpha
164
+ */
165
+ export interface TypeFactoryTuple extends TypeFactoryType {
166
+ /**
167
+ * {@inheritDoc TypeFactoryType._kind}
168
+ */
169
+ readonly _kind: "tuple";
170
+ /**
171
+ * The fixed-length items in the tuple.
172
+ */
173
+ readonly items: readonly TypeFactoryType[];
174
+ /**
175
+ * Optional rest element type for variable-length tuples.
176
+ */
177
+ readonly rest?: TypeFactoryType;
178
+ }
179
+ /**
180
+ * Represents a union type in the type factory system.
181
+ * @alpha
182
+ */
183
+ export interface TypeFactoryUnion extends TypeFactoryType {
184
+ /**
185
+ * {@inheritDoc TypeFactoryType._kind}
186
+ */
187
+ readonly _kind: "union";
188
+ /**
189
+ * The possible types in the union.
190
+ */
191
+ readonly options: readonly TypeFactoryType[];
192
+ }
193
+ /**
194
+ * Represents a literal type (specific string, number, or boolean value) in the type factory system.
195
+ * @alpha
196
+ */
197
+ export interface TypeFactoryLiteral extends TypeFactoryType {
198
+ /**
199
+ * {@inheritDoc TypeFactoryType._kind}
200
+ */
201
+ readonly _kind: "literal";
202
+ /**
203
+ * The specific literal value.
204
+ */
205
+ readonly value: string | number | boolean;
206
+ }
207
+ /**
208
+ * Represents an optional type modifier in the type factory system.
209
+ * @alpha
210
+ */
211
+ export interface TypeFactoryOptional extends TypeFactoryType {
212
+ /**
213
+ * {@inheritDoc TypeFactoryType._kind}
214
+ */
215
+ readonly _kind: "optional";
216
+ /**
217
+ * The inner type that is optional.
218
+ */
219
+ readonly innerType: TypeFactoryType;
220
+ }
221
+ /**
222
+ * Represents a readonly type modifier in the type factory system.
223
+ * @alpha
224
+ */
225
+ export interface TypeFactoryReadonly extends TypeFactoryType {
226
+ /**
227
+ * {@inheritDoc TypeFactoryType._kind}
228
+ */
229
+ readonly _kind: "readonly";
230
+ /**
231
+ * The inner type that is readonly.
232
+ */
233
+ readonly innerType: TypeFactoryType;
234
+ }
235
+ /**
236
+ * Represents an instanceof type that references a SharedTree schema class in the type factory system.
237
+ * @alpha
238
+ */
239
+ export interface TypeFactoryInstanceOf extends TypeFactoryType {
240
+ /**
241
+ * {@inheritDoc TypeFactoryType._kind}
242
+ */
243
+ readonly _kind: "instanceof";
244
+ /**
245
+ * The SharedTree schema class to reference.
246
+ */
247
+ readonly schema: ObjectNodeSchema;
248
+ }
249
+ /**
250
+ * Namespace containing type factory functions.
251
+ * @alpha
252
+ */
253
+ export declare const typeFactory: {
254
+ /**
255
+ * Create a string type.
256
+ * @alpha
257
+ */
258
+ string(): TypeFactoryString;
259
+ /**
260
+ * Create a number type.
261
+ * @alpha
262
+ */
263
+ number(): TypeFactoryNumber;
264
+ /**
265
+ * Create a boolean type.
266
+ * @alpha
267
+ */
268
+ boolean(): TypeFactoryBoolean;
269
+ /**
270
+ * Create a void type.
271
+ * @alpha
272
+ */
273
+ void(): TypeFactoryVoid;
274
+ /**
275
+ * Create an undefined type.
276
+ * @alpha
277
+ */
278
+ undefined(): TypeFactoryUndefined;
279
+ /**
280
+ * Create a null type.
281
+ * @alpha
282
+ */
283
+ null(): TypeFactoryNull;
284
+ /**
285
+ * Create an unknown type.
286
+ * @alpha
287
+ */
288
+ unknown(): TypeFactoryUnknown;
289
+ /**
290
+ * Create an array type.
291
+ * @alpha
292
+ */
293
+ array(element: TypeFactoryType): TypeFactoryArray;
294
+ /**
295
+ * Create an object type.
296
+ * @alpha
297
+ */
298
+ object(shape: Record<string, TypeFactoryType>): TypeFactoryObject;
299
+ /**
300
+ * Create a record type.
301
+ * @alpha
302
+ */
303
+ record(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord;
304
+ /**
305
+ * Create a map type.
306
+ * @alpha
307
+ */
308
+ map(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap;
309
+ /**
310
+ * Create a tuple type.
311
+ * @alpha
312
+ */
313
+ tuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple;
314
+ /**
315
+ * Create a union type.
316
+ * @alpha
317
+ */
318
+ union(options: readonly TypeFactoryType[]): TypeFactoryUnion;
319
+ /**
320
+ * Create a literal type.
321
+ * @alpha
322
+ */
323
+ literal(value: string | number | boolean): TypeFactoryLiteral;
324
+ /**
325
+ * Create an optional type.
326
+ * @alpha
327
+ */
328
+ optional(innerType: TypeFactoryType): TypeFactoryOptional;
329
+ /**
330
+ * Create a readonly type.
331
+ * @alpha
332
+ */
333
+ readonly(innerType: TypeFactoryType): TypeFactoryReadonly;
334
+ /**
335
+ * Create an instanceOf type for a SharedTree schema class.
336
+ * @alpha
337
+ */
338
+ instanceOf<T extends TreeNodeSchemaClass>(schema: T): TypeFactoryInstanceOf;
339
+ };
340
+ /**
341
+ * A lookup from type factory instanceOf types to their corresponding ObjectNodeSchema.
342
+ * @alpha
343
+ */
344
+ export declare const instanceOfsTypeFactory: WeakMap<TypeFactoryInstanceOf, ObjectNodeSchema<string, import("@fluidframework/tree/alpha").RestrictiveStringRecord<import("@fluidframework/tree/alpha").ImplicitFieldSchema>, boolean, unknown>>;
345
+ //# sourceMappingURL=treeAgentTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeAgentTypes.d.ts","sourceRoot":"","sources":["../src/treeAgentTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC5B,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,MAAM,GACN,WAAW,GACX,MAAM,GACN,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,KAAK,GACL,OAAO,GACP,OAAO,GACP,SAAS,GACT,UAAU,GACV,UAAU,GACV,YAAY,CAAC;AAEhB;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;CACpC;AA0BD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAM1E;AAID;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACzD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,eAAe;IACzD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IAC1D;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACvD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CAC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ACU,oBAAoB;IAIjC;;;OAGG;YACK,eAAe;IAIvB;;;OAGG;eACQ,kBAAkB;IAI7B;;;OAGG;mBACY,eAAe,GAAG,gBAAgB;IAIjD;;;OAGG;kBACW,OAAO,MAAM,EAAE,eAAe,CAAC,GAAG,iBAAiB;IAIjE;;;OAGG;oBACa,eAAe,aAAa,eAAe,GAAG,iBAAiB;IAI/E;;;OAGG;iBACU,eAAe,aAAa,eAAe,GAAG,cAAc;IAIzE;;;OAGG;iBACU,SAAS,eAAe,EAAE,SAAS,eAAe,GAAG,gBAAgB;IASlF;;;OAGG;mBACY,SAAS,eAAe,EAAE,GAAG,gBAAgB;IAS5D;;;OAGG;mBACY,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,kBAAkB;IAI7D;;;OAGG;wBACiB,eAAe,GAAG,mBAAmB;IAIzD;;;OAGG;wBACiB,eAAe,GAAG,mBAAmB;IAIzD;;;OAGG;sDAC+C,CAAC,GAAG,qBAAqB;CAc3E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sBAAsB,oMAAyD,CAAC"}
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.instanceOfsTypeFactory = exports.typeFactory = exports.isTypeFactoryType = void 0;
8
+ const internal_1 = require("@fluidframework/telemetry-utils/internal");
9
+ const alpha_1 = require("@fluidframework/tree/alpha");
10
+ /**
11
+ * Set of valid type factory type kinds for efficient validation.
12
+ * @internal
13
+ */
14
+ const validTypeKinds = new Set([
15
+ "string",
16
+ "number",
17
+ "boolean",
18
+ "void",
19
+ "undefined",
20
+ "null",
21
+ "unknown",
22
+ "array",
23
+ "object",
24
+ "record",
25
+ "map",
26
+ "tuple",
27
+ "union",
28
+ "literal",
29
+ "optional",
30
+ "readonly",
31
+ "instanceof",
32
+ ]);
33
+ /**
34
+ * Type guard to check if a value is a type factory type.
35
+ * @alpha
36
+ */
37
+ function isTypeFactoryType(value) {
38
+ if (typeof value !== "object" || value === null || !("_kind" in value)) {
39
+ return false;
40
+ }
41
+ const kind = value._kind;
42
+ return typeof kind === "string" && validTypeKinds.has(kind);
43
+ }
44
+ exports.isTypeFactoryType = isTypeFactoryType;
45
+ /**
46
+ * Namespace containing type factory functions.
47
+ * @alpha
48
+ */
49
+ exports.typeFactory = {
50
+ /**
51
+ * Create a string type.
52
+ * @alpha
53
+ */
54
+ string() {
55
+ return { _kind: "string" };
56
+ },
57
+ /**
58
+ * Create a number type.
59
+ * @alpha
60
+ */
61
+ number() {
62
+ return { _kind: "number" };
63
+ },
64
+ /**
65
+ * Create a boolean type.
66
+ * @alpha
67
+ */
68
+ boolean() {
69
+ return { _kind: "boolean" };
70
+ },
71
+ /**
72
+ * Create a void type.
73
+ * @alpha
74
+ */
75
+ void() {
76
+ return { _kind: "void" };
77
+ },
78
+ /**
79
+ * Create an undefined type.
80
+ * @alpha
81
+ */
82
+ undefined() {
83
+ return { _kind: "undefined" };
84
+ },
85
+ /**
86
+ * Create a null type.
87
+ * @alpha
88
+ */
89
+ null() {
90
+ return { _kind: "null" };
91
+ },
92
+ /**
93
+ * Create an unknown type.
94
+ * @alpha
95
+ */
96
+ unknown() {
97
+ return { _kind: "unknown" };
98
+ },
99
+ /**
100
+ * Create an array type.
101
+ * @alpha
102
+ */
103
+ array(element) {
104
+ return { _kind: "array", element };
105
+ },
106
+ /**
107
+ * Create an object type.
108
+ * @alpha
109
+ */
110
+ object(shape) {
111
+ return { _kind: "object", shape };
112
+ },
113
+ /**
114
+ * Create a record type.
115
+ * @alpha
116
+ */
117
+ record(keyType, valueType) {
118
+ return { _kind: "record", keyType, valueType };
119
+ },
120
+ /**
121
+ * Create a map type.
122
+ * @alpha
123
+ */
124
+ map(keyType, valueType) {
125
+ return { _kind: "map", keyType, valueType };
126
+ },
127
+ /**
128
+ * Create a tuple type.
129
+ * @alpha
130
+ */
131
+ tuple(items, rest) {
132
+ if (items.length === 0 && rest === undefined) {
133
+ throw new internal_1.UsageError("typeFactory.tuple requires at least one item or a rest type. Empty tuples are not supported.");
134
+ }
135
+ return rest === undefined ? { _kind: "tuple", items } : { _kind: "tuple", items, rest };
136
+ },
137
+ /**
138
+ * Create a union type.
139
+ * @alpha
140
+ */
141
+ union(options) {
142
+ if (options.length === 0) {
143
+ throw new internal_1.UsageError("typeFactory.union requires at least one option. Empty unions are not valid TypeScript types.");
144
+ }
145
+ return { _kind: "union", options };
146
+ },
147
+ /**
148
+ * Create a literal type.
149
+ * @alpha
150
+ */
151
+ literal(value) {
152
+ return { _kind: "literal", value };
153
+ },
154
+ /**
155
+ * Create an optional type.
156
+ * @alpha
157
+ */
158
+ optional(innerType) {
159
+ return { _kind: "optional", innerType };
160
+ },
161
+ /**
162
+ * Create a readonly type.
163
+ * @alpha
164
+ */
165
+ readonly(innerType) {
166
+ return { _kind: "readonly", innerType };
167
+ },
168
+ /**
169
+ * Create an instanceOf type for a SharedTree schema class.
170
+ * @alpha
171
+ */
172
+ instanceOf(schema) {
173
+ if (!(schema instanceof alpha_1.ObjectNodeSchema)) {
174
+ throw new internal_1.UsageError(`typeFactory.instanceOf only supports ObjectNodeSchema-based schema classes (created via SchemaFactory.object). ` +
175
+ `Pass a schema class that extends from an object schema (e.g., sf.object(...)), not primitive, array, or map schemas.`);
176
+ }
177
+ const instanceOfType = {
178
+ _kind: "instanceof",
179
+ schema,
180
+ };
181
+ exports.instanceOfsTypeFactory.set(instanceOfType, schema);
182
+ return instanceOfType;
183
+ },
184
+ };
185
+ /**
186
+ * A lookup from type factory instanceOf types to their corresponding ObjectNodeSchema.
187
+ * @alpha
188
+ */
189
+ exports.instanceOfsTypeFactory = new WeakMap();
190
+ //# sourceMappingURL=treeAgentTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeAgentTypes.js","sourceRoot":"","sources":["../src/treeAgentTypes.ts"],"names":[],"mappings":";AAAA;;;GAG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EAAE,KAAK,EAAE,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,SAA0B;QAClC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,SAA0B;QAClC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,UAAU,CAAgC,MAAS;QAClD,IAAI,CAAC,CAAC,MAAM,YAAY,wBAAgB,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,qBAAU,CACnB,iHAAiH;gBAChH,sHAAsH,CACvH,CAAC;QACH,CAAC;QACD,MAAM,cAAc,GAA0B;YAC7C,KAAK,EAAE,YAAY;YACnB,MAAM;SACN,CAAC;QACF,8BAAsB,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACnD,OAAO,cAAc,CAAC;IACvB,CAAC;CACD,CAAC;AAEF;;;GAGG;AACU,QAAA,sBAAsB,GAAG,IAAI,OAAO,EAA2C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { TreeNodeSchemaClass } from \"@fluidframework/tree/alpha\";\nimport { ObjectNodeSchema } from \"@fluidframework/tree/alpha\";\n\n/**\n * Type kinds for the type factory type system.\n * @alpha\n */\nexport type TypeFactoryTypeKind =\n\t| \"string\"\n\t| \"number\"\n\t| \"boolean\"\n\t| \"void\"\n\t| \"undefined\"\n\t| \"null\"\n\t| \"unknown\"\n\t| \"array\"\n\t| \"object\"\n\t| \"record\"\n\t| \"map\"\n\t| \"tuple\"\n\t| \"union\"\n\t| \"literal\"\n\t| \"optional\"\n\t| \"readonly\"\n\t| \"instanceof\";\n\n/**\n * Base interface for type factory types.\n * @alpha\n */\nexport interface TypeFactoryType {\n\t/**\n\t * The kind of type this represents.\n\t */\n\treadonly _kind: TypeFactoryTypeKind;\n}\n\n/**\n * Set of valid type factory type kinds for efficient validation.\n * @internal\n */\nconst validTypeKinds: ReadonlySet<TypeFactoryTypeKind> = new Set<TypeFactoryTypeKind>([\n\t\"string\",\n\t\"number\",\n\t\"boolean\",\n\t\"void\",\n\t\"undefined\",\n\t\"null\",\n\t\"unknown\",\n\t\"array\",\n\t\"object\",\n\t\"record\",\n\t\"map\",\n\t\"tuple\",\n\t\"union\",\n\t\"literal\",\n\t\"optional\",\n\t\"readonly\",\n\t\"instanceof\",\n]);\n\n/**\n * Type guard to check if a value is a type factory type.\n * @alpha\n */\nexport function isTypeFactoryType(value: unknown): value is TypeFactoryType {\n\tif (typeof value !== \"object\" || value === null || !(\"_kind\" in value)) {\n\t\treturn false;\n\t}\n\tconst kind = (value as { _kind: unknown })._kind;\n\treturn typeof kind === \"string\" && validTypeKinds.has(kind as TypeFactoryTypeKind);\n}\n\n// Primitive type factories\n\n/**\n * Represents a string type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryString extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"string\";\n}\n\n/**\n * Represents a number type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryNumber extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"number\";\n}\n\n/**\n * Represents a boolean type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryBoolean extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"boolean\";\n}\n\n/**\n * Represents a void type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryVoid extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"void\";\n}\n\n/**\n * Represents an undefined type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryUndefined extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"undefined\";\n}\n\n/**\n * Represents a null type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryNull extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"null\";\n}\n\n/**\n * Represents an unknown type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryUnknown extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"unknown\";\n}\n\n// Complex type interfaces\n\n/**\n * Represents an array type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryArray extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"array\";\n\t/**\n\t * The type of elements in the array.\n\t */\n\treadonly element: TypeFactoryType;\n}\n\n/**\n * Represents an object type with a fixed shape in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryObject extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"object\";\n\t/**\n\t * The shape of the object, mapping property names to their types.\n\t */\n\treadonly shape: Record<string, TypeFactoryType>;\n}\n\n/**\n * Represents a record type (index signature) in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryRecord extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"record\";\n\t/**\n\t * The type of the record's keys.\n\t */\n\treadonly keyType: TypeFactoryType;\n\t/**\n\t * The type of the record's values.\n\t */\n\treadonly valueType: TypeFactoryType;\n}\n\n/**\n * Represents a Map type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryMap extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"map\";\n\t/**\n\t * The type of the map's keys.\n\t */\n\treadonly keyType: TypeFactoryType;\n\t/**\n\t * The type of the map's values.\n\t */\n\treadonly valueType: TypeFactoryType;\n}\n\n/**\n * Represents a tuple type with fixed-length items and optional rest elements in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryTuple extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"tuple\";\n\t/**\n\t * The fixed-length items in the tuple.\n\t */\n\treadonly items: readonly TypeFactoryType[];\n\t/**\n\t * Optional rest element type for variable-length tuples.\n\t */\n\treadonly rest?: TypeFactoryType;\n}\n\n/**\n * Represents a union type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryUnion extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"union\";\n\t/**\n\t * The possible types in the union.\n\t */\n\treadonly options: readonly TypeFactoryType[];\n}\n\n/**\n * Represents a literal type (specific string, number, or boolean value) in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryLiteral extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"literal\";\n\t/**\n\t * The specific literal value.\n\t */\n\treadonly value: string | number | boolean;\n}\n\n/**\n * Represents an optional type modifier in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryOptional extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"optional\";\n\t/**\n\t * The inner type that is optional.\n\t */\n\treadonly innerType: TypeFactoryType;\n}\n\n/**\n * Represents a readonly type modifier in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryReadonly extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"readonly\";\n\t/**\n\t * The inner type that is readonly.\n\t */\n\treadonly innerType: TypeFactoryType;\n}\n\n/**\n * Represents an instanceof type that references a SharedTree schema class in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryInstanceOf extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"instanceof\";\n\t/**\n\t * The SharedTree schema class to reference.\n\t */\n\treadonly schema: ObjectNodeSchema;\n}\n\n/**\n * Namespace containing type factory functions.\n * @alpha\n */\nexport const typeFactory = {\n\t/**\n\t * Create a string type.\n\t * @alpha\n\t */\n\tstring(): TypeFactoryString {\n\t\treturn { _kind: \"string\" };\n\t},\n\n\t/**\n\t * Create a number type.\n\t * @alpha\n\t */\n\tnumber(): TypeFactoryNumber {\n\t\treturn { _kind: \"number\" };\n\t},\n\n\t/**\n\t * Create a boolean type.\n\t * @alpha\n\t */\n\tboolean(): TypeFactoryBoolean {\n\t\treturn { _kind: \"boolean\" };\n\t},\n\n\t/**\n\t * Create a void type.\n\t * @alpha\n\t */\n\tvoid(): TypeFactoryVoid {\n\t\treturn { _kind: \"void\" };\n\t},\n\n\t/**\n\t * Create an undefined type.\n\t * @alpha\n\t */\n\tundefined(): TypeFactoryUndefined {\n\t\treturn { _kind: \"undefined\" };\n\t},\n\n\t/**\n\t * Create a null type.\n\t * @alpha\n\t */\n\tnull(): TypeFactoryNull {\n\t\treturn { _kind: \"null\" };\n\t},\n\n\t/**\n\t * Create an unknown type.\n\t * @alpha\n\t */\n\tunknown(): TypeFactoryUnknown {\n\t\treturn { _kind: \"unknown\" };\n\t},\n\n\t/**\n\t * Create an array type.\n\t * @alpha\n\t */\n\tarray(element: TypeFactoryType): TypeFactoryArray {\n\t\treturn { _kind: \"array\", element };\n\t},\n\n\t/**\n\t * Create an object type.\n\t * @alpha\n\t */\n\tobject(shape: Record<string, TypeFactoryType>): TypeFactoryObject {\n\t\treturn { _kind: \"object\", shape };\n\t},\n\n\t/**\n\t * Create a record type.\n\t * @alpha\n\t */\n\trecord(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord {\n\t\treturn { _kind: \"record\", keyType, valueType };\n\t},\n\n\t/**\n\t * Create a map type.\n\t * @alpha\n\t */\n\tmap(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap {\n\t\treturn { _kind: \"map\", keyType, valueType };\n\t},\n\n\t/**\n\t * Create a tuple type.\n\t * @alpha\n\t */\n\ttuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple {\n\t\tif (items.length === 0 && rest === undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"typeFactory.tuple requires at least one item or a rest type. Empty tuples are not supported.\",\n\t\t\t);\n\t\t}\n\t\treturn rest === undefined ? { _kind: \"tuple\", items } : { _kind: \"tuple\", items, rest };\n\t},\n\n\t/**\n\t * Create a union type.\n\t * @alpha\n\t */\n\tunion(options: readonly TypeFactoryType[]): TypeFactoryUnion {\n\t\tif (options.length === 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"typeFactory.union requires at least one option. Empty unions are not valid TypeScript types.\",\n\t\t\t);\n\t\t}\n\t\treturn { _kind: \"union\", options };\n\t},\n\n\t/**\n\t * Create a literal type.\n\t * @alpha\n\t */\n\tliteral(value: string | number | boolean): TypeFactoryLiteral {\n\t\treturn { _kind: \"literal\", value };\n\t},\n\n\t/**\n\t * Create an optional type.\n\t * @alpha\n\t */\n\toptional(innerType: TypeFactoryType): TypeFactoryOptional {\n\t\treturn { _kind: \"optional\", innerType };\n\t},\n\n\t/**\n\t * Create a readonly type.\n\t * @alpha\n\t */\n\treadonly(innerType: TypeFactoryType): TypeFactoryReadonly {\n\t\treturn { _kind: \"readonly\", innerType };\n\t},\n\n\t/**\n\t * Create an instanceOf type for a SharedTree schema class.\n\t * @alpha\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(schema: T): TypeFactoryInstanceOf {\n\t\tif (!(schema instanceof ObjectNodeSchema)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`typeFactory.instanceOf only supports ObjectNodeSchema-based schema classes (created via SchemaFactory.object). ` +\n\t\t\t\t\t`Pass a schema class that extends from an object schema (e.g., sf.object(...)), not primitive, array, or map schemas.`,\n\t\t\t);\n\t\t}\n\t\tconst instanceOfType: TypeFactoryInstanceOf = {\n\t\t\t_kind: \"instanceof\",\n\t\t\tschema,\n\t\t};\n\t\tinstanceOfsTypeFactory.set(instanceOfType, schema);\n\t\treturn instanceOfType;\n\t},\n};\n\n/**\n * A lookup from type factory instanceOf types to their corresponding ObjectNodeSchema.\n * @alpha\n */\nexport const instanceOfsTypeFactory = new WeakMap<TypeFactoryInstanceOf, ObjectNodeSchema>();\n"]}
package/dist/utils.d.ts CHANGED
@@ -13,10 +13,6 @@ export interface MapGetSet<K, V> {
13
13
  get(key: K): V | undefined;
14
14
  set(key: K, value: V): void;
15
15
  }
16
- /**
17
- * TBD
18
- */
19
- export declare function fail(message: string): never;
20
16
  /**
21
17
  * Map one iterable to another by transforming each element one at a time
22
18
  * @param iterable - the iterable to transform
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EACX,iBAAiB,EACjB,QAAQ,EACR,cAAc,EAEd,MAAM,4BAA4B,CAAC;AASpC;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC;IAC9B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAE3C;AAED;;;;;;;GAOG;AACH,wBAAiB,WAAW,CAAC,CAAC,EAAE,CAAC,EAChC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACd,gBAAgB,CAAC,CAAC,CAAC,CAIrB;AAED;;;;;;;;GAQG;AACH,wBA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