@fluidframework/tree-agent 2.80.0 → 2.81.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/api-report/tree-agent.alpha.api.md +195 -20
  3. package/dist/alpha.d.ts +31 -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 +23 -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 +290 -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 +430 -0
  26. package/dist/treeAgentTypes.d.ts.map +1 -0
  27. package/dist/treeAgentTypes.js +227 -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 +31 -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 +23 -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 +285 -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 +430 -0
  57. package/lib/treeAgentTypes.d.ts.map +1 -0
  58. package/lib/treeAgentTypes.js +223 -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 +12 -12
  65. package/src/index.ts +36 -0
  66. package/src/methodBinding.ts +93 -15
  67. package/src/propertyBinding.ts +66 -9
  68. package/src/renderSchemaTypeScript.ts +31 -9
  69. package/src/renderTypeFactoryTypeScript.ts +339 -0
  70. package/src/subtree.ts +5 -4
  71. package/src/treeAgentTypes.ts +611 -0
  72. package/src/utils.ts +2 -9
  73. package/.eslintrc.cjs +0 -48
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderTypeFactoryTypeScript.js","sourceRoot":"","sources":["../src/renderTypeFactoryTypeScript.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAmBtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,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C;QACf,CAAC;QACD,IAAI,YAAY,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;YAC9C,IAAI,CAAC,KAAK,EAAE,CAAC;gBACZ,MAAM,CAAC,IAAI,CAAC,CAAC;YACd,CAAC;YACD,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,YAAY,CAAC,aAAa,CAAC;YAChD,MAAM,CAAC,KAAK,CAAC,CAAC;YACd,MAAM,CAAC,IAAI,CAAC,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,CAAC;YACb,UAAU,CAAC,IAAI,gCAAwB,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,CAAC;QACd,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAChB,UAAU,CAAC,YAAY,CAAC,UAAU,+BAAuB,CAAC;IAC3D,CAAC;AACF,CAAC;AAED,IAAW,cAIV;AAJD,WAAW,cAAc;IACxB,qDAAS,CAAA;IACT,mEAAgB,CAAA;IAChB,uDAAU,CAAA;AACX,CAAC,EAJU,cAAc,KAAd,cAAc,QAIxB;AAED,SAAS,iBAAiB,CAAC,IAAqB;IAC/C,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,OAAO,CAAC,CAAC,CAAC;YACd,oCAA4B;QAC7B,CAAC;QACD,KAAK,cAAc,CAAC,CAAC,CAAC;YACrB,2CAAmC;QACpC,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,qCAA6B;QAC9B,CAAC;IACF,CAAC;AACF,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 { ObjectNodeSchema, TreeNodeSchema } from \"@fluidframework/tree/alpha\";\n\nimport type {\n\tTypeFactoryType,\n\tTypeFactoryArray,\n\tTypeFactoryPromise,\n\tTypeFactoryObject,\n\tTypeFactoryTuple,\n\tTypeFactoryRecord,\n\tTypeFactoryMap,\n\tTypeFactoryLiteral,\n\tTypeFactoryOptional,\n\tTypeFactoryReadonly,\n\tTypeFactoryUnion,\n\tTypeFactoryIntersection,\n\tTypeFactoryFunction,\n} from \"./treeAgentTypes.js\";\n\nexport { instanceOfsTypeFactory } from \"./treeAgentTypes.js\";\n\n/**\n * Converts type factory type definitions into TypeScript declaration text.\n * @alpha\n */\nexport function renderTypeFactoryTypeScript(\n\ttypeFactoryType: TypeFactoryType,\n\tgetFriendlyName: (schema: TreeNodeSchema) => string,\n\tinstanceOfLookup: WeakMap<TypeFactoryType, ObjectNodeSchema>,\n\tinitialIndent: number = 0,\n): string {\n\tlet result = \"\";\n\tlet startOfLine = false;\n\tlet indent = initialIndent;\n\n\tappendType(typeFactoryType, TypePrecedence.Union);\n\treturn result;\n\n\tfunction appendType(type: TypeFactoryType, minPrecedence = TypePrecedence.Object): void {\n\t\tconst shouldParenthesize = getTypePrecedence(type) < minPrecedence;\n\t\tif (shouldParenthesize) {\n\t\t\tappend(\"(\");\n\t\t}\n\t\tappendTypeDefinition(type);\n\t\tif (shouldParenthesize) {\n\t\t\tappend(\")\");\n\t\t}\n\t}\n\n\tfunction append(s: string): void {\n\t\tif (startOfLine) {\n\t\t\tresult += \" \".repeat(indent);\n\t\t\tstartOfLine = false;\n\t\t}\n\t\tresult += s;\n\t}\n\n\tfunction appendNewLine(): void {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendTypeDefinition(type: TypeFactoryType): void {\n\t\tswitch (type._kind) {\n\t\t\tcase \"string\": {\n\t\t\t\tappend(\"string\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"number\": {\n\t\t\t\tappend(\"number\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"boolean\": {\n\t\t\t\tappend(\"boolean\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"date\": {\n\t\t\t\tappend(\"Date\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"void\": {\n\t\t\t\tappend(\"void\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"undefined\": {\n\t\t\t\tappend(\"undefined\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"null\": {\n\t\t\t\tappend(\"null\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"unknown\": {\n\t\t\t\tappend(\"unknown\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"array\": {\n\t\t\t\tappendArrayType(type as TypeFactoryArray);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"promise\": {\n\t\t\t\tappendPromiseType(type as TypeFactoryPromise);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"object\": {\n\t\t\t\tappendObjectType(type as TypeFactoryObject);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"union\": {\n\t\t\t\tappendUnionTypes((type as TypeFactoryUnion).options, TypePrecedence.Union);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"intersection\": {\n\t\t\t\tappendIntersectionTypes(\n\t\t\t\t\t(type as TypeFactoryIntersection).types,\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"tuple\": {\n\t\t\t\tappendTupleType(type as TypeFactoryTuple);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"record\": {\n\t\t\t\tappendRecordType(type as TypeFactoryRecord);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"map\": {\n\t\t\t\tappendMapType(type as TypeFactoryMap);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"literal\": {\n\t\t\t\tappendLiteral((type as TypeFactoryLiteral).value);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"optional\": {\n\t\t\t\tappendUnionTypes(\n\t\t\t\t\t[(type as TypeFactoryOptional).innerType, { _kind: \"undefined\" }],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"readonly\": {\n\t\t\t\tappendReadonlyType(type as TypeFactoryReadonly);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"function\": {\n\t\t\t\tappendFunctionType(type as TypeFactoryFunction);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"instanceof\": {\n\t\t\t\tconst schema = instanceOfLookup.get(type);\n\t\t\t\tif (schema === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"instanceof type not found in lookup - this typically indicates the type was not created via typeFactory.instanceOf\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tappend(getFriendlyName(schema));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when formatting helper types: ${String(type._kind ?? \"unknown\")}. Expected one of: string, number, boolean, void, undefined, null, unknown, array, object, union, tuple, record, map, literal, optional, readonly, instanceof.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: TypeFactoryArray): void {\n\t\tappendType(arrayType.element, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendPromiseType(promiseType: TypeFactoryPromise): void {\n\t\tappend(\"Promise<\");\n\t\tappendType(promiseType.innerType, TypePrecedence.Union);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendObjectType(objectType: TypeFactoryObject): void {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\tfor (const [name, propertyType] of Object.entries(objectType.shape)) {\n\t\t\tappend(name);\n\t\t\tif (propertyType._kind === \"optional\") {\n\t\t\t\tappend(\"?\");\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType((propertyType as TypeFactoryOptional).innerType);\n\t\t\t} else {\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(propertyType);\n\t\t\t}\n\t\t\tappend(\";\");\n\t\t\tappendNewLine();\n\t\t}\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionTypes(\n\t\ttypes: readonly TypeFactoryType[],\n\t\tminPrecedence: TypePrecedence,\n\t): void {\n\t\tlet first = true;\n\t\tfor (const innerType of types) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\" | \");\n\t\t\t}\n\t\t\tappendType(innerType, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendIntersectionTypes(\n\t\ttypes: readonly TypeFactoryType[],\n\t\tminPrecedence: TypePrecedence,\n\t): void {\n\t\tlet first = true;\n\t\tfor (const innerType of types) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\" & \");\n\t\t\t}\n\t\t\tappendType(innerType, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: TypeFactoryTuple): void {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const innerType of tupleType.items) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tif (innerType._kind === \"optional\") {\n\t\t\t\tappendType((innerType as TypeFactoryOptional).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(innerType);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tif (tupleType.rest !== undefined) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tappend(\"...\");\n\t\t\tappendType(tupleType.rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: TypeFactoryRecord): void {\n\t\tappend(\"Record<\");\n\t\tappendType(recordType.keyType, TypePrecedence.Union);\n\t\tappend(\", \");\n\t\tappendType(recordType.valueType, TypePrecedence.Union);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: TypeFactoryMap): void {\n\t\tappend(\"Map<\");\n\t\tappendType(mapType.keyType, TypePrecedence.Union);\n\t\tappend(\", \");\n\t\tappendType(mapType.valueType, TypePrecedence.Union);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: string | number | boolean): void {\n\t\tappend(JSON.stringify(value));\n\t}\n\n\tfunction appendReadonlyType(readonlyType: TypeFactoryReadonly): void {\n\t\tappend(\"Readonly<\");\n\t\tappendType(readonlyType.innerType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendFunctionType(functionType: TypeFactoryFunction): void {\n\t\tappend(\"(\");\n\t\tlet first = true;\n\t\tfor (const param of functionType.parameters) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tconst [name, type] = param;\n\t\t\tappend(name);\n\t\t\tif (type._kind === \"optional\") {\n\t\t\t\tappend(\"?\");\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType((type as TypeFactoryOptional).innerType, TypePrecedence.Union);\n\t\t\t} else {\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type, TypePrecedence.Union);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tif (functionType.restParameter !== undefined) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tconst [name, type] = functionType.restParameter;\n\t\t\tappend(\"...\");\n\t\t\tappend(name);\n\t\t\tappend(\": \");\n\t\t\tappendType(type, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\") => \");\n\t\tappendType(functionType.returnType, TypePrecedence.Union);\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecedence(type: TypeFactoryType): TypePrecedence {\n\tswitch (type._kind) {\n\t\tcase \"union\": {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tcase \"intersection\": {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"subtree.d.ts","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACX,mBAAmB,EACnB,0BAA0B,EAG1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EACX,aAAa,EAEb,eAAe,EACf,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAY,UAAU,EAAE,MAAM,UAAU,CAAC;AAGrD;;GAEG;AACH,qBAAa,OAAO,CAAC,KAAK,SAAS,mBAAmB;aAClB,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;gBAA7B,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;IAMhE,IAAW,MAAM,IAAI,eAAe,CAInC;IAED,IAAW,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAEvC;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,0BAA0B,CAAC,KAAK,CAAC,EAsDxD;IAED,IAAW,MAAM,IAAI,KAAK,CAMzB;IAEM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC;CAY7B"}
1
+ {"version":3,"file":"subtree.d.ts","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACX,mBAAmB,EACnB,0BAA0B,EAG1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EACX,aAAa,EAEb,eAAe,EACf,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAY,UAAU,EAAE,MAAM,UAAU,CAAC;AAGrD;;GAEG;AACH,qBAAa,OAAO,CAAC,KAAK,SAAS,mBAAmB;aAClB,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;gBAA7B,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;IAMhE,IAAW,MAAM,IAAI,eAAe,CAInC;IAED,IAAW,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAEvC;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,0BAA0B,CAAC,KAAK,CAAC,EAsDxD;IAED,IAAW,MAAM,IAAI,KAAK,CAMzB;IAEM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC;CAa7B"}
package/lib/subtree.js CHANGED
@@ -19,7 +19,7 @@ export class Subtree {
19
19
  }
20
20
  get branch() {
21
21
  return this.viewOrTree instanceof TreeNode
22
- ? (TreeAlpha.branch(this.viewOrTree) ?? fail("Node cannot be raw."))
22
+ ? (TreeAlpha.branch(this.viewOrTree) ?? fail(0xcb3 /* Node cannot be raw. */))
23
23
  : this.viewOrTree;
24
24
  }
25
25
  get field() {
@@ -76,7 +76,7 @@ export class Subtree {
76
76
  }
77
77
  }
78
78
  default: {
79
- fail("Unexpected node kind");
79
+ fail(0xcb4 /* Unexpected node kind */);
80
80
  }
81
81
  }
82
82
  }
@@ -92,9 +92,9 @@ export class Subtree {
92
92
  }
93
93
  fork() {
94
94
  if (this.viewOrTree instanceof TreeNode) {
95
- const branch = TreeAlpha.branch(this.viewOrTree) ?? fail("Node cannot be raw.");
95
+ const branch = TreeAlpha.branch(this.viewOrTree) ?? fail(0xcb5 /* Node cannot be raw. */);
96
96
  const node = getNodeOnBranch(this.viewOrTree, branch.fork()) ??
97
- fail("Expected node to be on new fork.");
97
+ fail(0xcb6 /* Expected node to be on new fork. */);
98
98
  return new Subtree(node);
99
99
  }
100
100
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAOhE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAQvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAA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AAC,CAAC;4BAC3C,CAAC,CAAC,CAAC;wBACJ,CAAC;oBACF,CAAC;oBACD,OAAO,CAAC,CAAC,CAAC;wBACT,IAAI,CAAC,sBAAsB,CAAC,CAAC;oBAC9B,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,QAAQ;YAClC,CAAC,CAAC,IAAI,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,QAAQ,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,qBAAqB,CAAC,CAAC;YAChF,MAAM,IAAI,GACT,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC/C,IAAI,CAAC,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","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(\"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,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAOhE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAQvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB,YAAmC,UAA6B;QAA7B,eAAU,GAAV,UAAU,CAAmB;QAC/D,IAAI,UAAU,YAAY,QAAQ,IAAI,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;YAClF,MAAM,IAAI,UAAU,CAAC,4CAA4C,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,UAAU,YAAY,QAAQ;YACzC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC9E,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IACpB,CAAC;IAED,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,UAAU,YAAY,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CA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C,IAAI,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;YAC5E,MAAM,IAAI,GACT,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC/C,IAAI,CAAC,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","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,430 @@
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" | "date" | "promise" | "array" | "object" | "record" | "map" | "tuple" | "union" | "intersection" | "literal" | "optional" | "readonly" | "function" | "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 Date type in the type factory system.
59
+ * @alpha
60
+ */
61
+ export interface TypeFactoryDate extends TypeFactoryType {
62
+ /**
63
+ * {@inheritDoc TypeFactoryType._kind}
64
+ */
65
+ readonly _kind: "date";
66
+ }
67
+ /**
68
+ * Represents a void type in the type factory system.
69
+ * @alpha
70
+ */
71
+ export interface TypeFactoryVoid extends TypeFactoryType {
72
+ /**
73
+ * {@inheritDoc TypeFactoryType._kind}
74
+ */
75
+ readonly _kind: "void";
76
+ }
77
+ /**
78
+ * Represents an undefined type in the type factory system.
79
+ * @alpha
80
+ */
81
+ export interface TypeFactoryUndefined extends TypeFactoryType {
82
+ /**
83
+ * {@inheritDoc TypeFactoryType._kind}
84
+ */
85
+ readonly _kind: "undefined";
86
+ }
87
+ /**
88
+ * Represents a null type in the type factory system.
89
+ * @alpha
90
+ */
91
+ export interface TypeFactoryNull extends TypeFactoryType {
92
+ /**
93
+ * {@inheritDoc TypeFactoryType._kind}
94
+ */
95
+ readonly _kind: "null";
96
+ }
97
+ /**
98
+ * Represents an unknown type in the type factory system.
99
+ * @alpha
100
+ */
101
+ export interface TypeFactoryUnknown extends TypeFactoryType {
102
+ /**
103
+ * {@inheritDoc TypeFactoryType._kind}
104
+ */
105
+ readonly _kind: "unknown";
106
+ }
107
+ /**
108
+ * Represents an array type in the type factory system.
109
+ * @alpha
110
+ */
111
+ export interface TypeFactoryArray extends TypeFactoryType {
112
+ /**
113
+ * {@inheritDoc TypeFactoryType._kind}
114
+ */
115
+ readonly _kind: "array";
116
+ /**
117
+ * The type of elements in the array.
118
+ */
119
+ readonly element: TypeFactoryType;
120
+ }
121
+ /**
122
+ * Represents a Promise type in the type factory system.
123
+ * @alpha
124
+ */
125
+ export interface TypeFactoryPromise extends TypeFactoryType {
126
+ /**
127
+ * {@inheritDoc TypeFactoryType._kind}
128
+ */
129
+ readonly _kind: "promise";
130
+ /**
131
+ * The type that the Promise resolves to.
132
+ */
133
+ readonly innerType: TypeFactoryType;
134
+ }
135
+ /**
136
+ * Represents an object type with a fixed shape in the type factory system.
137
+ * @alpha
138
+ */
139
+ export interface TypeFactoryObject extends TypeFactoryType {
140
+ /**
141
+ * {@inheritDoc TypeFactoryType._kind}
142
+ */
143
+ readonly _kind: "object";
144
+ /**
145
+ * The shape of the object, mapping property names to their types.
146
+ */
147
+ readonly shape: Record<string, TypeFactoryType>;
148
+ }
149
+ /**
150
+ * Represents a record type (index signature) in the type factory system.
151
+ * @alpha
152
+ */
153
+ export interface TypeFactoryRecord extends TypeFactoryType {
154
+ /**
155
+ * {@inheritDoc TypeFactoryType._kind}
156
+ */
157
+ readonly _kind: "record";
158
+ /**
159
+ * The type of the record's keys.
160
+ */
161
+ readonly keyType: TypeFactoryType;
162
+ /**
163
+ * The type of the record's values.
164
+ */
165
+ readonly valueType: TypeFactoryType;
166
+ }
167
+ /**
168
+ * Represents a Map type in the type factory system.
169
+ * @alpha
170
+ */
171
+ export interface TypeFactoryMap extends TypeFactoryType {
172
+ /**
173
+ * {@inheritDoc TypeFactoryType._kind}
174
+ */
175
+ readonly _kind: "map";
176
+ /**
177
+ * The type of the map's keys.
178
+ */
179
+ readonly keyType: TypeFactoryType;
180
+ /**
181
+ * The type of the map's values.
182
+ */
183
+ readonly valueType: TypeFactoryType;
184
+ }
185
+ /**
186
+ * Represents a tuple type with fixed-length items and optional rest elements in the type factory system.
187
+ * @alpha
188
+ */
189
+ export interface TypeFactoryTuple extends TypeFactoryType {
190
+ /**
191
+ * {@inheritDoc TypeFactoryType._kind}
192
+ */
193
+ readonly _kind: "tuple";
194
+ /**
195
+ * The fixed-length items in the tuple.
196
+ */
197
+ readonly items: readonly TypeFactoryType[];
198
+ /**
199
+ * Optional rest element type for variable-length tuples.
200
+ */
201
+ readonly rest?: TypeFactoryType;
202
+ }
203
+ /**
204
+ * Represents a union type in the type factory system.
205
+ * @alpha
206
+ */
207
+ export interface TypeFactoryUnion extends TypeFactoryType {
208
+ /**
209
+ * {@inheritDoc TypeFactoryType._kind}
210
+ */
211
+ readonly _kind: "union";
212
+ /**
213
+ * The possible types in the union.
214
+ */
215
+ readonly options: readonly TypeFactoryType[];
216
+ }
217
+ /**
218
+ * Represents an intersection type in the type factory system.
219
+ * @alpha
220
+ */
221
+ export interface TypeFactoryIntersection extends TypeFactoryType {
222
+ /**
223
+ * {@inheritDoc TypeFactoryType._kind}
224
+ */
225
+ readonly _kind: "intersection";
226
+ /**
227
+ * The types to intersect.
228
+ */
229
+ readonly types: readonly TypeFactoryType[];
230
+ }
231
+ /**
232
+ * Represents a literal type (specific string, number, or boolean value) in the type factory system.
233
+ * @alpha
234
+ */
235
+ export interface TypeFactoryLiteral extends TypeFactoryType {
236
+ /**
237
+ * {@inheritDoc TypeFactoryType._kind}
238
+ */
239
+ readonly _kind: "literal";
240
+ /**
241
+ * The specific literal value.
242
+ */
243
+ readonly value: string | number | boolean;
244
+ }
245
+ /**
246
+ * Represents an optional type modifier in the type factory system.
247
+ * @alpha
248
+ */
249
+ export interface TypeFactoryOptional extends TypeFactoryType {
250
+ /**
251
+ * {@inheritDoc TypeFactoryType._kind}
252
+ */
253
+ readonly _kind: "optional";
254
+ /**
255
+ * The inner type that is optional.
256
+ */
257
+ readonly innerType: TypeFactoryType;
258
+ }
259
+ /**
260
+ * Represents a readonly type modifier in the type factory system.
261
+ * @alpha
262
+ */
263
+ export interface TypeFactoryReadonly extends TypeFactoryType {
264
+ /**
265
+ * {@inheritDoc TypeFactoryType._kind}
266
+ */
267
+ readonly _kind: "readonly";
268
+ /**
269
+ * The inner type that is readonly.
270
+ */
271
+ readonly innerType: TypeFactoryType;
272
+ }
273
+ /**
274
+ * Represents a function parameter as a tuple of [name, type].
275
+ * @alpha
276
+ */
277
+ export type TypeFactoryFunctionParameter = readonly [name: string, type: TypeFactoryType];
278
+ /**
279
+ * Represents a function type in the type factory system.
280
+ * @alpha
281
+ */
282
+ export interface TypeFactoryFunction extends TypeFactoryType {
283
+ /**
284
+ * {@inheritDoc TypeFactoryType._kind}
285
+ */
286
+ readonly _kind: "function";
287
+ /**
288
+ * The function parameters.
289
+ */
290
+ readonly parameters: readonly TypeFactoryFunctionParameter[];
291
+ /**
292
+ * The function return type.
293
+ */
294
+ readonly returnType: TypeFactoryType;
295
+ /**
296
+ * Optional rest parameter for variable-length argument lists.
297
+ */
298
+ readonly restParameter?: TypeFactoryFunctionParameter;
299
+ }
300
+ /**
301
+ * Represents an instanceof type that references a SharedTree schema class in the type factory system.
302
+ * @alpha
303
+ */
304
+ export interface TypeFactoryInstanceOf extends TypeFactoryType {
305
+ /**
306
+ * {@inheritDoc TypeFactoryType._kind}
307
+ */
308
+ readonly _kind: "instanceof";
309
+ /**
310
+ * The SharedTree schema class to reference.
311
+ */
312
+ readonly schema: ObjectNodeSchema;
313
+ }
314
+ /**
315
+ * Namespace containing type factory functions.
316
+ * @alpha
317
+ */
318
+ export declare const typeFactory: {
319
+ /**
320
+ * Create a string type.
321
+ * @alpha
322
+ */
323
+ string(): TypeFactoryString;
324
+ /**
325
+ * Create a number type.
326
+ * @alpha
327
+ */
328
+ number(): TypeFactoryNumber;
329
+ /**
330
+ * Create a boolean type.
331
+ * @alpha
332
+ */
333
+ boolean(): TypeFactoryBoolean;
334
+ /**
335
+ * Create a Date type.
336
+ * @alpha
337
+ */
338
+ date(): TypeFactoryDate;
339
+ /**
340
+ * Create a void type.
341
+ * @alpha
342
+ */
343
+ void(): TypeFactoryVoid;
344
+ /**
345
+ * Create an undefined type.
346
+ * @alpha
347
+ */
348
+ undefined(): TypeFactoryUndefined;
349
+ /**
350
+ * Create a null type.
351
+ * @alpha
352
+ */
353
+ null(): TypeFactoryNull;
354
+ /**
355
+ * Create an unknown type.
356
+ * @alpha
357
+ */
358
+ unknown(): TypeFactoryUnknown;
359
+ /**
360
+ * Create an array type.
361
+ * @alpha
362
+ */
363
+ array(element: TypeFactoryType): TypeFactoryArray;
364
+ /**
365
+ * Create a Promise type.
366
+ * @alpha
367
+ */
368
+ promise(innerType: TypeFactoryType): TypeFactoryPromise;
369
+ /**
370
+ * Create an object type.
371
+ * @alpha
372
+ */
373
+ object(shape: Record<string, TypeFactoryType>): TypeFactoryObject;
374
+ /**
375
+ * Create a record type.
376
+ * @alpha
377
+ */
378
+ record(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord;
379
+ /**
380
+ * Create a map type.
381
+ * @alpha
382
+ */
383
+ map(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap;
384
+ /**
385
+ * Create a tuple type.
386
+ * @alpha
387
+ */
388
+ tuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple;
389
+ /**
390
+ * Create a union type.
391
+ * @alpha
392
+ */
393
+ union(options: readonly TypeFactoryType[]): TypeFactoryUnion;
394
+ /**
395
+ * Create an intersection type.
396
+ * @alpha
397
+ */
398
+ intersection(types: readonly TypeFactoryType[]): TypeFactoryIntersection;
399
+ /**
400
+ * Create a literal type.
401
+ * @alpha
402
+ */
403
+ literal(value: string | number | boolean): TypeFactoryLiteral;
404
+ /**
405
+ * Create an optional type.
406
+ * @alpha
407
+ */
408
+ optional(innerType: TypeFactoryType): TypeFactoryOptional;
409
+ /**
410
+ * Create a readonly type.
411
+ * @alpha
412
+ */
413
+ readonly(innerType: TypeFactoryType): TypeFactoryReadonly;
414
+ /**
415
+ * Create a function type.
416
+ * @alpha
417
+ */
418
+ function(parameters: readonly TypeFactoryFunctionParameter[], returnType: TypeFactoryType, restParameter?: TypeFactoryFunctionParameter): TypeFactoryFunction;
419
+ /**
420
+ * Create an instanceOf type for a SharedTree schema class.
421
+ * @alpha
422
+ */
423
+ instanceOf<T extends TreeNodeSchemaClass>(schema: T): TypeFactoryInstanceOf;
424
+ };
425
+ /**
426
+ * A lookup from type factory instanceOf types to their corresponding ObjectNodeSchema.
427
+ * @alpha
428
+ */
429
+ export declare const instanceOfsTypeFactory: WeakMap<TypeFactoryInstanceOf, ObjectNodeSchema<string, import("@fluidframework/tree/alpha").RestrictiveStringRecord<import("@fluidframework/tree/alpha").ImplicitFieldSchema>, boolean, unknown>>;
430
+ //# 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,MAAM,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