@palantir/pack.document-schema.type-gen 0.8.0 → 0.10.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 (173) hide show
  1. package/build/esm/commands/asset/__tests__/buildPrefixRewriteFetch.test.js +85 -0
  2. package/build/esm/commands/asset/__tests__/buildPrefixRewriteFetch.test.js.map +1 -0
  3. package/build/esm/commands/asset/assetDeployHandler.js +36 -1
  4. package/build/esm/commands/asset/assetDeployHandler.js.map +1 -1
  5. package/build/esm/commands/asset/registerAssetCommands.js +1 -1
  6. package/build/esm/commands/asset/registerAssetCommands.js.map +1 -1
  7. package/build/esm/commands/ir/irGenTypesHandler.js +49 -0
  8. package/build/esm/commands/ir/irGenTypesHandler.js.map +1 -0
  9. package/build/esm/commands/ir/registerIrCommands.js +2 -0
  10. package/build/esm/commands/ir/registerIrCommands.js.map +1 -1
  11. package/build/esm/commands/schema/registerSchemaCommands.js +2 -0
  12. package/build/esm/commands/schema/registerSchemaCommands.js.map +1 -1
  13. package/build/esm/commands/schema/schemaIrHandler.js +56 -0
  14. package/build/esm/commands/schema/schemaIrHandler.js.map +1 -0
  15. package/build/esm/index.js.map +1 -1
  16. package/build/esm/lib/pack-docschema-api/pack-docschema-ir/recordDef.js.map +1 -1
  17. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js +1 -1
  18. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js.map +1 -1
  19. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js +1 -1
  20. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js.map +1 -1
  21. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js +1 -1
  22. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js.map +1 -1
  23. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js +1 -1
  24. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js.map +1 -1
  25. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js +1 -1
  26. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js.map +1 -1
  27. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js +1 -1
  28. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js.map +1 -1
  29. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js +1 -1
  30. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js.map +1 -1
  31. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js +1 -1
  32. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js.map +1 -1
  33. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js +1 -1
  34. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js.map +1 -1
  35. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js +1 -1
  36. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js.map +1 -1
  37. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js +1 -1
  38. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js.map +1 -1
  39. package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js +27 -16
  40. package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js.map +1 -1
  41. package/build/esm/utils/ir/__tests__/generateModelsFromIr.test.js +6 -24
  42. package/build/esm/utils/ir/__tests__/generateModelsFromIr.test.js.map +1 -1
  43. package/build/esm/utils/ir/__tests__/generateZodSchemasFromIr.test.js +10 -40
  44. package/build/esm/utils/ir/__tests__/generateZodSchemasFromIr.test.js.map +1 -1
  45. package/build/esm/utils/ir/convertIrToWireSchema.js +4 -2
  46. package/build/esm/utils/ir/convertIrToWireSchema.js.map +1 -1
  47. package/build/esm/utils/ir/generateZodSchemasFromIr.js +1 -1
  48. package/build/esm/utils/ir/generateZodSchemasFromIr.js.map +1 -1
  49. package/build/esm/utils/ir/irFieldHelpers.js +383 -0
  50. package/build/esm/utils/ir/irFieldHelpers.js.map +1 -0
  51. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/single-version.js +2 -0
  52. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/single-version.js.map +1 -0
  53. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/three-version-chain.js +2 -0
  54. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/three-version-chain.js.map +1 -0
  55. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js +2 -0
  56. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js.map +1 -0
  57. package/build/esm/utils/schema/__tests__/convertSchemaToSteps.test.js +13 -0
  58. package/build/esm/utils/schema/__tests__/convertSchemaToSteps.test.js.map +1 -1
  59. package/build/esm/utils/schema/__tests__/fixtures.js +278 -0
  60. package/build/esm/utils/schema/__tests__/fixtures.js.map +1 -0
  61. package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js +53 -0
  62. package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js.map +1 -0
  63. package/build/esm/utils/schema/__tests__/generateModelMetadataFromSchema.test.js +42 -0
  64. package/build/esm/utils/schema/__tests__/generateModelMetadataFromSchema.test.js.map +1 -0
  65. package/build/esm/utils/schema/__tests__/generateScopeFromSchema.test.js +38 -0
  66. package/build/esm/utils/schema/__tests__/generateScopeFromSchema.test.js.map +1 -0
  67. package/build/esm/utils/schema/__tests__/generateVersionedTypesFromSchema.test.js +64 -0
  68. package/build/esm/utils/schema/__tests__/generateVersionedTypesFromSchema.test.js.map +1 -0
  69. package/build/esm/utils/schema/__tests__/generateVersionedZodFromSchema.test.js +60 -0
  70. package/build/esm/utils/schema/__tests__/generateVersionedZodFromSchema.test.js.map +1 -0
  71. package/build/esm/utils/schema/__tests__/generateVersionsFromSchema.test.js +38 -0
  72. package/build/esm/utils/schema/__tests__/generateVersionsFromSchema.test.js.map +1 -0
  73. package/build/esm/utils/schema/__tests__/snapshotUtils.js +106 -0
  74. package/build/esm/utils/schema/__tests__/snapshotUtils.js.map +1 -0
  75. package/build/esm/utils/schema/convertSchemaToSteps.js +6 -0
  76. package/build/esm/utils/schema/convertSchemaToSteps.js.map +1 -1
  77. package/build/esm/utils/schema/generateIndexFromSchema.js +74 -0
  78. package/build/esm/utils/schema/generateIndexFromSchema.js.map +1 -0
  79. package/build/esm/utils/schema/generateInternalFromSchema.js +264 -0
  80. package/build/esm/utils/schema/generateInternalFromSchema.js.map +1 -0
  81. package/build/esm/utils/schema/generateModelMetadataFromSchema.js +172 -0
  82. package/build/esm/utils/schema/generateModelMetadataFromSchema.js.map +1 -0
  83. package/build/esm/utils/schema/generateScopeFromSchema.js +151 -0
  84. package/build/esm/utils/schema/generateScopeFromSchema.js.map +1 -0
  85. package/build/esm/utils/schema/generateTypesFromSchema.js +20 -26
  86. package/build/esm/utils/schema/generateTypesFromSchema.js.map +1 -1
  87. package/build/esm/utils/schema/generateVersionedTypesFromSchema.js +187 -0
  88. package/build/esm/utils/schema/generateVersionedTypesFromSchema.js.map +1 -0
  89. package/build/esm/utils/schema/generateVersionedZodFromSchema.js +153 -0
  90. package/build/esm/utils/schema/generateVersionedZodFromSchema.js.map +1 -0
  91. package/build/esm/utils/schema/generateVersionsFromSchema.js +52 -0
  92. package/build/esm/utils/schema/generateVersionsFromSchema.js.map +1 -0
  93. package/build/esm/utils/schema/loadSchemaModule.js +53 -0
  94. package/build/esm/utils/schema/loadSchemaModule.js.map +1 -0
  95. package/build/esm/utils/schema/resolveSchemaChain.js +104 -0
  96. package/build/esm/utils/schema/resolveSchemaChain.js.map +1 -0
  97. package/build/esm/utils/schema/runtimeSchema.js +69 -0
  98. package/build/esm/utils/schema/runtimeSchema.js.map +1 -0
  99. package/build/esm/utils/schema/writeAllSdkFiles.js +111 -0
  100. package/build/esm/utils/schema/writeAllSdkFiles.js.map +1 -0
  101. package/build/esm/utils/steps/__tests__/__snapshots__/types/arrayFields.js.map +1 -1
  102. package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js +1 -1
  103. package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js.map +1 -1
  104. package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js +1 -1
  105. package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map +1 -1
  106. package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js.map +1 -1
  107. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleRecord.js.map +1 -1
  108. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js +1 -1
  109. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js.map +1 -1
  110. package/build/esm/utils/steps/__tests__/convertStepsToIr.test.js +93 -1
  111. package/build/esm/utils/steps/__tests__/convertStepsToIr.test.js.map +1 -1
  112. package/build/esm/utils/steps/convertStepsToIr.js +45 -40
  113. package/build/esm/utils/steps/convertStepsToIr.js.map +1 -1
  114. package/build/types/commands/asset/__tests__/buildPrefixRewriteFetch.test.d.ts +2 -0
  115. package/build/types/commands/asset/__tests__/buildPrefixRewriteFetch.test.d.ts.map +1 -0
  116. package/build/types/commands/asset/assetDeployHandler.d.ts +15 -0
  117. package/build/types/commands/asset/assetDeployHandler.d.ts.map +1 -1
  118. package/build/types/commands/asset/registerAssetCommands.d.ts.map +1 -1
  119. package/build/types/commands/ir/irGenTypesHandler.d.ts +8 -0
  120. package/build/types/commands/ir/irGenTypesHandler.d.ts.map +1 -0
  121. package/build/types/commands/ir/registerIrCommands.d.ts.map +1 -1
  122. package/build/types/commands/schema/registerSchemaCommands.d.ts.map +1 -1
  123. package/build/types/commands/schema/schemaIrHandler.d.ts +19 -0
  124. package/build/types/commands/schema/schemaIrHandler.d.ts.map +1 -0
  125. package/build/types/index.d.ts +1 -0
  126. package/build/types/index.d.ts.map +1 -1
  127. package/build/types/lib/pack-docschema-api/pack-docschema-ir/recordDef.d.ts +0 -2
  128. package/build/types/lib/pack-docschema-api/pack-docschema-ir/recordDef.d.ts.map +1 -1
  129. package/build/types/utils/ir/irFieldHelpers.d.ts +36 -0
  130. package/build/types/utils/ir/irFieldHelpers.d.ts.map +1 -0
  131. package/build/types/utils/schema/__tests__/fixtures.d.ts +23 -0
  132. package/build/types/utils/schema/__tests__/fixtures.d.ts.map +1 -0
  133. package/build/types/utils/schema/__tests__/generateInternalFromSchema.test.d.ts +2 -0
  134. package/build/types/utils/schema/__tests__/generateInternalFromSchema.test.d.ts.map +1 -0
  135. package/build/types/utils/schema/__tests__/generateModelMetadataFromSchema.test.d.ts +2 -0
  136. package/build/types/utils/schema/__tests__/generateModelMetadataFromSchema.test.d.ts.map +1 -0
  137. package/build/types/utils/schema/__tests__/generateScopeFromSchema.test.d.ts +2 -0
  138. package/build/types/utils/schema/__tests__/generateScopeFromSchema.test.d.ts.map +1 -0
  139. package/build/types/utils/schema/__tests__/generateVersionedTypesFromSchema.test.d.ts +2 -0
  140. package/build/types/utils/schema/__tests__/generateVersionedTypesFromSchema.test.d.ts.map +1 -0
  141. package/build/types/utils/schema/__tests__/generateVersionedZodFromSchema.test.d.ts +2 -0
  142. package/build/types/utils/schema/__tests__/generateVersionedZodFromSchema.test.d.ts.map +1 -0
  143. package/build/types/utils/schema/__tests__/generateVersionsFromSchema.test.d.ts +2 -0
  144. package/build/types/utils/schema/__tests__/generateVersionsFromSchema.test.d.ts.map +1 -0
  145. package/build/types/utils/schema/__tests__/snapshotUtils.d.ts +47 -0
  146. package/build/types/utils/schema/__tests__/snapshotUtils.d.ts.map +1 -0
  147. package/build/types/utils/schema/convertSchemaToSteps.d.ts.map +1 -1
  148. package/build/types/utils/schema/generateIndexFromSchema.d.ts +14 -0
  149. package/build/types/utils/schema/generateIndexFromSchema.d.ts.map +1 -0
  150. package/build/types/utils/schema/generateInternalFromSchema.d.ts +15 -0
  151. package/build/types/utils/schema/generateInternalFromSchema.d.ts.map +1 -0
  152. package/build/types/utils/schema/generateModelMetadataFromSchema.d.ts +10 -0
  153. package/build/types/utils/schema/generateModelMetadataFromSchema.d.ts.map +1 -0
  154. package/build/types/utils/schema/generateScopeFromSchema.d.ts +13 -0
  155. package/build/types/utils/schema/generateScopeFromSchema.d.ts.map +1 -0
  156. package/build/types/utils/schema/generateTypesFromSchema.d.ts.map +1 -1
  157. package/build/types/utils/schema/generateVersionedTypesFromSchema.d.ts +15 -0
  158. package/build/types/utils/schema/generateVersionedTypesFromSchema.d.ts.map +1 -0
  159. package/build/types/utils/schema/generateVersionedZodFromSchema.d.ts +12 -0
  160. package/build/types/utils/schema/generateVersionedZodFromSchema.d.ts.map +1 -0
  161. package/build/types/utils/schema/generateVersionsFromSchema.d.ts +13 -0
  162. package/build/types/utils/schema/generateVersionsFromSchema.d.ts.map +1 -0
  163. package/build/types/utils/schema/loadSchemaModule.d.ts +14 -0
  164. package/build/types/utils/schema/loadSchemaModule.d.ts.map +1 -0
  165. package/build/types/utils/schema/resolveSchemaChain.d.ts +39 -0
  166. package/build/types/utils/schema/resolveSchemaChain.d.ts.map +1 -0
  167. package/build/types/utils/schema/runtimeSchema.d.ts +27 -0
  168. package/build/types/utils/schema/runtimeSchema.d.ts.map +1 -0
  169. package/build/types/utils/schema/writeAllSdkFiles.d.ts +8 -0
  170. package/build/types/utils/schema/writeAllSdkFiles.d.ts.map +1 -0
  171. package/build/types/utils/steps/convertStepsToIr.d.ts +3 -3
  172. package/build/types/utils/steps/convertStepsToIr.d.ts.map +1 -1
  173. package/package.json +3 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateVersionedZodFromSchema.test.js","names":["path","describe","expect","it","generateVersionedZodFromChain","resolveSchemaChain","nestedOptionalsSchema","nestedUnionSchema","refFieldsSchema","singleVersionSchema","twoVersionAdditiveSchema","twoVersionFieldRemovalSchema","unionTypesSchema","formatVersionedZodSnapshot","snapshotDir","join","__dirname","result","toMatchFileSnapshot","zodSchemas","size","toBe","has"],"sources":["generateVersionedZodFromSchema.test.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"path\";\nimport { describe, expect, it } from \"vitest\";\nimport { generateVersionedZodFromChain } from \"../generateVersionedZodFromSchema.js\";\nimport { resolveSchemaChain } from \"../resolveSchemaChain.js\";\nimport {\n nestedOptionalsSchema,\n nestedUnionSchema,\n refFieldsSchema,\n singleVersionSchema,\n twoVersionAdditiveSchema,\n twoVersionFieldRemovalSchema,\n unionTypesSchema,\n} from \"./fixtures.js\";\nimport { formatVersionedZodSnapshot } from \"./snapshotUtils.js\";\n\ndescribe(\"generateVersionedZodFromChain\", () => {\n const snapshotDir = path.join(__dirname, \"__snapshots__\", \"generateVersionedZodFromSchema\");\n\n it(\"single-version schema\", async () => {\n const result = generateVersionedZodFromChain(resolveSchemaChain(singleVersionSchema));\n await expect(await formatVersionedZodSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"single-version.snap\"),\n );\n });\n\n it(\"two-version additive change\", async () => {\n const result = generateVersionedZodFromChain(\n resolveSchemaChain(twoVersionAdditiveSchema, 1),\n 1,\n );\n await expect(await formatVersionedZodSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"two-version-additive.snap\"),\n );\n });\n\n it(\"two-version field removal\", async () => {\n const result = generateVersionedZodFromChain(\n resolveSchemaChain(twoVersionFieldRemovalSchema, 1),\n 1,\n );\n await expect(await formatVersionedZodSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"two-version-field-removal.snap\"),\n );\n });\n\n it(\"schema with union types\", async () => {\n const result = generateVersionedZodFromChain(resolveSchemaChain(unionTypesSchema));\n await expect(await formatVersionedZodSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"union-types.snap\"),\n );\n });\n\n it(\"schema with ref fields\", async () => {\n const result = generateVersionedZodFromChain(resolveSchemaChain(refFieldsSchema));\n await expect(await formatVersionedZodSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"ref-fields.snap\"),\n );\n });\n\n it(\"nested optionals inside arrays\", async () => {\n const result = generateVersionedZodFromChain(resolveSchemaChain(nestedOptionalsSchema));\n await expect(await formatVersionedZodSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"nested-optionals.snap\"),\n );\n });\n\n it(\"includes value field in Zod schema for union variants that reference another union\", async () => {\n const result = generateVersionedZodFromChain(resolveSchemaChain(nestedUnionSchema));\n await expect(await formatVersionedZodSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"union-reference-union.snap\"),\n );\n });\n\n it(\"respects minSupportedVersion default (latest only)\", () => {\n const result = generateVersionedZodFromChain(resolveSchemaChain(twoVersionAdditiveSchema));\n expect(result.zodSchemas.size).toBe(1);\n expect(result.zodSchemas.has(2)).toBe(true);\n expect(result.zodSchemas.has(1)).toBe(false);\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,QAAQ,EAAEC,MAA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kBAAkB,CAACK,wBAAwB,CAAC,CAAC;IAC1FR,MAAM,CAACe,MAAM,CAACE,UAAU,CAACC,IAAI,CAAC,CAACC,IAAI,CAAC,CAAC,CAAC;IACtCnB,MAAM,CAACe,MAAM,CAACE,UAAU,CAACG,GAAG,CAAC,CAAC,CAAC,CAAC,CAACD,IAAI,CAAC,IAAI,CAAC;IAC3CnB,MAAM,CAACe,MAAM,CAACE,UAAU,CAACG,GAAG,CAAC,CAAC,CAAC,CAAC,CAACD,IAAI,CAAC,KAAK,CAAC;EAC9C,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import path from "path";
18
+ import { describe, expect, it } from "vitest";
19
+ import { generateVersionsFromChain } from "../generateVersionsFromSchema.js";
20
+ import { resolveSchemaChain } from "../resolveSchemaChain.js";
21
+ import { singleVersionSchema, threeVersionChainSchema, twoVersionAdditiveSchema } from "./fixtures.js";
22
+ import { formatSingleSnapshot } from "./snapshotUtils.js";
23
+ describe("generateVersionsFromChain", () => {
24
+ const snapshotDir = path.join(__dirname, "__snapshots__", "generateVersionsFromSchema");
25
+ it("single-version schema", async () => {
26
+ const result = generateVersionsFromChain(resolveSchemaChain(singleVersionSchema));
27
+ await expect(await formatSingleSnapshot("versions.ts", result)).toMatchFileSnapshot(path.join(snapshotDir, "single-version.ts"));
28
+ });
29
+ it("two-version with minSupportedVersion", async () => {
30
+ const result = generateVersionsFromChain(resolveSchemaChain(twoVersionAdditiveSchema, 1), 1);
31
+ await expect(await formatSingleSnapshot("versions.ts", result)).toMatchFileSnapshot(path.join(snapshotDir, "two-version.ts"));
32
+ });
33
+ it("three-version chain", async () => {
34
+ const result = generateVersionsFromChain(resolveSchemaChain(threeVersionChainSchema, 1), 1);
35
+ await expect(await formatSingleSnapshot("versions.ts", result)).toMatchFileSnapshot(path.join(snapshotDir, "three-version-chain.ts"));
36
+ });
37
+ });
38
+ //# sourceMappingURL=generateVersionsFromSchema.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateVersionsFromSchema.test.js","names":["path","describe","expect","it","generateVersionsFromChain","resolveSchemaChain","singleVersionSchema","threeVersionChainSchema","twoVersionAdditiveSchema","formatSingleSnapshot","snapshotDir","join","__dirname","result","toMatchFileSnapshot"],"sources":["generateVersionsFromSchema.test.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"path\";\nimport { describe, expect, it } from \"vitest\";\nimport { generateVersionsFromChain } from \"../generateVersionsFromSchema.js\";\nimport { resolveSchemaChain } from \"../resolveSchemaChain.js\";\nimport {\n singleVersionSchema,\n threeVersionChainSchema,\n twoVersionAdditiveSchema,\n} from \"./fixtures.js\";\nimport { formatSingleSnapshot } from \"./snapshotUtils.js\";\n\ndescribe(\"generateVersionsFromChain\", () => {\n const snapshotDir = path.join(__dirname, \"__snapshots__\", \"generateVersionsFromSchema\");\n\n it(\"single-version schema\", async () => {\n const result = generateVersionsFromChain(resolveSchemaChain(singleVersionSchema));\n await expect(await formatSingleSnapshot(\"versions.ts\", result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"single-version.ts\"),\n );\n });\n\n it(\"two-version with minSupportedVersion\", async () => {\n const result = generateVersionsFromChain(resolveSchemaChain(twoVersionAdditiveSchema, 1), 1);\n await expect(await formatSingleSnapshot(\"versions.ts\", result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"two-version.ts\"),\n );\n });\n\n it(\"three-version chain\", async () => {\n const result = generateVersionsFromChain(resolveSchemaChain(threeVersionChainSchema, 1), 1);\n await expect(await formatSingleSnapshot(\"versions.ts\", result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"three-version-chain.ts\"),\n );\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,yBAAyB,QAAQ,kCAAkC;AAC5E,SAASC,kBAAkB,QAAQ,0BAA0B;AAC7D,SACEC,mBAAmB,EACnBC,uBAAuB,EACvBC,wBAAwB,QACnB,eAAe;AACtB,SAASC,oBAAoB,QAAQ,oBAAoB;AAEzDR,QAAQ,CAAC,2BAA2B,EAAE,MAAM;EAC1C,MAAMS,WAAW,GAAGV,IAAI,CAACW,IAAI,CAACC,SAAS,EAAE,eAAe,EAAE,4BAA4B,CAAC;EAEvFT,EAAE,CAAC,uBAAuB,EAAE,YAAY;IACtC,MAAMU,MAAM,GAAGT,yBAAyB,CAACC,kBAAkB,CAACC,mBAAmB,CAAC,CAAC;IACjF,MAAMJ,MAAM,CAAC,MAAMO,oBAAoB,CAAC,aAAa,EAAEI,MAAM,CAAC,CAAC,CAACC,mBAAmB,CACjFd,IAAI,CAACW,IAAI,CAACD,WAAW,EAAE,mBAAmB,CAC5C,CAAC;EACH,CAAC,CAAC;EAEFP,EAAE,CAAC,sCAAsC,EAAE,YAAY;IACrD,MAAMU,MAAM,GAAGT,yBAAyB,CAACC,kBAAkB,CAACG,wBAAwB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC5F,MAAMN,MAAM,CAAC,MAAMO,oBAAoB,CAAC,aAAa,EAAEI,MAAM,CAAC,CAAC,CAACC,mBAAmB,CACjFd,IAAI,CAACW,IAAI,CAACD,WAAW,EAAE,gBAAgB,CACzC,CAAC;EACH,CAAC,CAAC;EAEFP,EAAE,CAAC,qBAAqB,EAAE,YAAY;IACpC,MAAMU,MAAM,GAAGT,yBAAyB,CAACC,kBAAkB,CAACE,uBAAuB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC3F,MAAML,MAAM,CAAC,MAAMO,oBAAoB,CAAC,aAAa,EAAEI,MAAM,CAAC,CAAC,CAACC,mBAAmB,CACjFd,IAAI,CAACW,IAAI,CAACD,WAAW,EAAE,wBAAwB,CACjD,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,106 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { format } from "prettier";
18
+ const prettierOpts = {
19
+ parser: "typescript",
20
+ singleQuote: true,
21
+ trailingComma: "es5"
22
+ };
23
+ async function fmt(code) {
24
+ return format(code, prettierOpts);
25
+ }
26
+ function section(filename, content) {
27
+ const bar = "=".repeat(60);
28
+ return `// ${bar}\n// ${filename}\n// ${bar}\n\n${content}`;
29
+ }
30
+
31
+ /**
32
+ * Combine a VersionedTypesOutput into a single snapshot string.
33
+ *
34
+ * Layout:
35
+ * // === types_v1.ts ===
36
+ * ...formatted code...
37
+ * // === writeTypes_v1.ts ===
38
+ * ...
39
+ * // === types.ts ===
40
+ * ...
41
+ */
42
+ export async function formatVersionedTypesSnapshot(result) {
43
+ const sections = [];
44
+ const sortedVersions = [...result.readTypes.keys()].sort((a, b) => a - b);
45
+ for (const version of sortedVersions) {
46
+ sections.push(section(`types_v${version}.ts`, await fmt(result.readTypes.get(version))));
47
+ }
48
+ for (const version of sortedVersions) {
49
+ sections.push(section(`writeTypes_v${version}.ts`, await fmt(result.writeTypes.get(version))));
50
+ }
51
+ sections.push(section("types.ts", await fmt(result.typesReExport)));
52
+ return sections.join("\n");
53
+ }
54
+
55
+ /**
56
+ * Format a ModelMetadataOutput into a snapshot string.
57
+ */
58
+ export async function formatModelMetadataSnapshot(result) {
59
+ return section("models.ts", await fmt(result.modelsFile));
60
+ }
61
+
62
+ /**
63
+ * Format a single generated string into a snapshot.
64
+ */
65
+ export async function formatSingleSnapshot(filename, code) {
66
+ return section(filename, await fmt(code));
67
+ }
68
+
69
+ /**
70
+ * Combine a VersionedZodOutput into a single snapshot string.
71
+ *
72
+ * Layout:
73
+ * // === schema_v1.ts ===
74
+ * ...formatted code...
75
+ * // === schema.ts ===
76
+ * ...
77
+ */
78
+ export async function formatVersionedZodSnapshot(result) {
79
+ const sections = [];
80
+ const sortedVersions = [...result.zodSchemas.keys()].sort((a, b) => a - b);
81
+ for (const version of sortedVersions) {
82
+ sections.push(section(`schema_v${version}.ts`, await fmt(result.zodSchemas.get(version))));
83
+ }
84
+ sections.push(section("schema.ts", await fmt(result.schemaReExport)));
85
+ return sections.join("\n");
86
+ }
87
+
88
+ /**
89
+ * Combine an InternalTypesOutput into a single snapshot string.
90
+ *
91
+ * Layout:
92
+ * // === _internal/types.ts ===
93
+ * ...formatted code...
94
+ * // === _internal/upgrades.ts ===
95
+ * ...
96
+ * // === _internal/schema.ts ===
97
+ * ...
98
+ */
99
+ export async function formatInternalTypesSnapshot(result) {
100
+ const sections = [];
101
+ sections.push(section("_internal/types.ts", await fmt(result.internalTypes)));
102
+ sections.push(section("_internal/upgrades.ts", await fmt(result.upgrades)));
103
+ sections.push(section("_internal/schema.ts", await fmt(result.internalSchema)));
104
+ return sections.join("\n");
105
+ }
106
+ //# sourceMappingURL=snapshotUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snapshotUtils.js","names":["format","prettierOpts","parser","singleQuote","trailingComma","fmt","code","section","filename","content","bar","repeat","formatVersionedTypesSnapshot","result","sections","sortedVersions","readTypes","keys","sort","a","b","version","push","get","writeTypes","typesReExport","join","formatModelMetadataSnapshot","modelsFile","formatSingleSnapshot","formatVersionedZodSnapshot","zodSchemas","schemaReExport","formatInternalTypesSnapshot","internalTypes","upgrades","internalSchema"],"sources":["snapshotUtils.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { format } from \"prettier\";\nimport type { InternalTypesOutput } from \"../generateInternalFromSchema.js\";\nimport type { ModelMetadataOutput } from \"../generateModelMetadataFromSchema.js\";\nimport type { VersionedTypesOutput } from \"../generateVersionedTypesFromSchema.js\";\nimport type { VersionedZodOutput } from \"../generateVersionedZodFromSchema.js\";\n\nconst prettierOpts = {\n parser: \"typescript\" as const,\n singleQuote: true,\n trailingComma: \"es5\" as const,\n};\n\nasync function fmt(code: string): Promise<string> {\n return format(code, prettierOpts);\n}\n\nfunction section(filename: string, content: string): string {\n const bar = \"=\".repeat(60);\n return `// ${bar}\\n// ${filename}\\n// ${bar}\\n\\n${content}`;\n}\n\n/**\n * Combine a VersionedTypesOutput into a single snapshot string.\n *\n * Layout:\n * // === types_v1.ts ===\n * ...formatted code...\n * // === writeTypes_v1.ts ===\n * ...\n * // === types.ts ===\n * ...\n */\nexport async function formatVersionedTypesSnapshot(\n result: VersionedTypesOutput,\n): Promise<string> {\n const sections: string[] = [];\n\n const sortedVersions = [...result.readTypes.keys()].sort((a, b) => a - b);\n\n for (const version of sortedVersions) {\n sections.push(section(`types_v${version}.ts`, await fmt(result.readTypes.get(version)!)));\n }\n for (const version of sortedVersions) {\n sections.push(section(`writeTypes_v${version}.ts`, await fmt(result.writeTypes.get(version)!)));\n }\n sections.push(section(\"types.ts\", await fmt(result.typesReExport)));\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Format a ModelMetadataOutput into a snapshot string.\n */\nexport async function formatModelMetadataSnapshot(\n result: ModelMetadataOutput,\n): Promise<string> {\n return section(\"models.ts\", await fmt(result.modelsFile));\n}\n\n/**\n * Format a single generated string into a snapshot.\n */\nexport async function formatSingleSnapshot(\n filename: string,\n code: string,\n): Promise<string> {\n return section(filename, await fmt(code));\n}\n\n/**\n * Combine a VersionedZodOutput into a single snapshot string.\n *\n * Layout:\n * // === schema_v1.ts ===\n * ...formatted code...\n * // === schema.ts ===\n * ...\n */\nexport async function formatVersionedZodSnapshot(\n result: VersionedZodOutput,\n): Promise<string> {\n const sections: string[] = [];\n\n const sortedVersions = [...result.zodSchemas.keys()].sort((a, b) => a - b);\n\n for (const version of sortedVersions) {\n sections.push(section(`schema_v${version}.ts`, await fmt(result.zodSchemas.get(version)!)));\n }\n sections.push(section(\"schema.ts\", await fmt(result.schemaReExport)));\n\n return sections.join(\"\\n\");\n}\n\n/**\n * Combine an InternalTypesOutput into a single snapshot string.\n *\n * Layout:\n * // === _internal/types.ts ===\n * ...formatted code...\n * // === _internal/upgrades.ts ===\n * ...\n * // === _internal/schema.ts ===\n * ...\n */\nexport async function formatInternalTypesSnapshot(\n result: InternalTypesOutput,\n): Promise<string> {\n const sections: string[] = [];\n\n sections.push(section(\"_internal/types.ts\", await fmt(result.internalTypes)));\n sections.push(section(\"_internal/upgrades.ts\", await fmt(result.upgrades)));\n sections.push(section(\"_internal/schema.ts\", await fmt(result.internalSchema)));\n\n return sections.join(\"\\n\");\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,MAAM,QAAQ,UAAU;AAMjC,MAAMC,YAAY,GAAG;EACnBC,MAAM,EAAE,YAAqB;EAC7BC,WAAW,EAAE,IAAI;EACjBC,aAAa,EAAE;AACjB,CAAC;AAED,eAAeC,GAAGA,CAACC,IAAY,EAAmB;EAChD,OAAON,MAAM,CAACM,IAAI,EAAEL,YAAY,CAAC;AACnC;AAEA,SAASM,OAAOA,CAACC,QAAgB,EAAEC,OAAe,EAAU;EAC1D,MAAMC,GAAG,GAAG,GAAG,CAACC,MAAM,CAAC,EAAE,CAAC;EAC1B,OAAO,MAAMD,GAAG,QAAQF,QAAQ,QAAQE,GAAG,OAAOD,OAAO,EAAE;AAC7D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeG,4BAA4BA,CAChDC,MAA4B,EACX;EACjB,MAAMC,QAAkB,GAAG,EAAE;EAE7B,MAAMC,cAAc,GAAG,CAAC,GAAGF,MAAM,CAACG,SAAS,CAACC,IAAI,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,GAAGC,CAAC,CAAC;EAEzE,KAAK,MAAMC,OAAO,IAAIN,cAAc,EAAE;IACpCD,QAAQ,CAACQ,IAAI,CAACf,OAAO,CAAC,UAAUc,OAAO,KAAK,EAAE,MAAMhB,GAAG,CAACQ,MAAM,CAACG,SAAS,CAACO,GAAG,CAACF,O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C;EAC7F;EACAP,QAAQ,CAACQ,IAAI,CAACf,OAAO,CAAC,WAAW,EAAE,MAAMF,GAAG,CAACQ,MAAM,CAACmB,cAAc,CAAC,CAAC,CAAC;EAErE,OAAOlB,QAAQ,CAACY,IAAI,CAAC,IAAI,CAAC;AAC5B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeO,2BAA2BA,CAC/CpB,MAA2B,EACV;EACjB,MAAMC,QAAkB,GAAG,EAAE;EAE7BA,QAAQ,CAACQ,IAAI,CAACf,OAAO,CAAC,oBAAoB,EAAE,MAAMF,GAAG,CAACQ,MAAM,CAACqB,aAAa,CAAC,CAAC,CAAC;EAC7EpB,QAAQ,CAACQ,IAAI,CAACf,OAAO,CAAC,uBAAuB,EAAE,MAAMF,GAAG,CAACQ,MAAM,CAACsB,QAAQ,CAAC,CAAC,CAAC;EAC3ErB,QAAQ,CAACQ,IAAI,CAACf,OAAO,CAAC,qBAAqB,EAAE,MAAMF,GAAG,CAACQ,MAAM,CAACuB,cAAc,CAAC,CAAC,CAAC;EAE/E,OAAOtB,QAAQ,CAACY,IAAI,CAAC,IAAI,CAAC;AAC5B","ignoreList":[]}
@@ -70,6 +70,12 @@ function convertUnionToYaml(unionDef) {
70
70
  return result;
71
71
  }
72
72
  export function convertSchemaToSteps(schema) {
73
+ // Reject aliased schemas: the YAML step format cannot represent exportKey !== declaredName
74
+ for (const [exportKey, def] of Object.entries(schema)) {
75
+ if (exportKey !== def.name) {
76
+ throw new Error(`Schema entry "${exportKey}" has declared model name "${def.name}". ` + `The migration-step YAML format cannot represent aliases (exportKey !== declaredName). ` + `Use the same name for both, or use the IR pipeline instead.`);
77
+ }
78
+ }
73
79
  const steps = [];
74
80
  const records = {};
75
81
  const unions = {};
@@ -1 +1 @@
1
- {"version":3,"file":"convertSchemaToSteps.js","names":["yaml","convertFieldType","field","type","items","item","name","Error","convertRecordToYaml","recordDef","result","fields","docs","fieldName","fieldDef","Object","entries","fieldType","convertUnionToYaml","unionDef","variants","variantName","variantRef","discriminant","convertSchemaToSteps","schema","steps","records","unions","def","values","keys","length","push","convertStepsToYamlString","dump","flowLevel","lineWidth","noRefs","quotingType","forceQuotes","skipInvalid"],"sources":["convertSchemaToSteps.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport yaml from \"js-yaml\";\nimport type { MigrationStep, UnionDefinition } from \"../steps/parseMigrationSteps.js\";\nimport type { P } from \"./validateSchemaModule.js\";\n\nfunction convertFieldType(field: P.Type): string {\n switch (field.type) {\n case \"array\":\n return `array<${convertFieldType(field.items as P.Type)}>`;\n case \"boolean\":\n return \"boolean\";\n case \"docRef\":\n return \"docRef\";\n case \"double\":\n return \"double\";\n case \"mediaRef\":\n return \"mediaRef\";\n case \"objectRef\":\n return \"objectRef\";\n case \"optional\":\n return `optional<${convertFieldType(field.item as P.Type)}>`;\n case \"ref\":\n return field.name;\n case \"string\":\n return \"string\";\n case \"unknown\":\n return \"unknown\";\n case \"userRef\":\n return \"userRef\";\n default:\n field satisfies never;\n throw new Error(`Unsupported field type: ${(field as P.Type).type}`);\n }\n}\n\nfunction convertRecordToYaml(\n recordDef: P.RecordDef,\n): { docs?: string; fields: Record<string, string> } {\n const result: { docs?: string; fields: Record<string, string> } = {\n fields: {},\n };\n\n if (recordDef.docs) {\n result.docs = recordDef.docs;\n }\n\n for (const [fieldName, fieldDef] of Object.entries(recordDef.fields)) {\n const fieldType = convertFieldType(fieldDef);\n result.fields[fieldName] = fieldType;\n }\n\n return result;\n}\n\nfunction convertUnionToYaml(unionDef: P.UnionDef): UnionDefinition {\n const variants: Record<string, string> = {};\n\n for (const [variantName, variantRef] of Object.entries(unionDef.variants)) {\n variants[variantName] = variantRef.name;\n }\n\n const result: UnionDefinition = {\n variants,\n };\n\n if (unionDef.discriminant !== \"type\") {\n result.discriminant = unionDef.discriminant;\n }\n\n return result;\n}\n\nexport function convertSchemaToSteps(schema: P.ReturnedSchema): MigrationStep[] {\n const steps: MigrationStep[] = [];\n const records: Record<string, { docs?: string; fields: Record<string, string> }> = {};\n const unions: Record<string, UnionDefinition> = {};\n\n for (const def of Object.values(schema)) {\n switch (def.type) {\n case \"record\": {\n records[def.name] = convertRecordToYaml(def);\n break;\n }\n case \"union\": {\n unions[def.name] = convertUnionToYaml(def);\n break;\n }\n }\n }\n\n if (Object.keys(records).length > 0) {\n steps.push({ \"add-records\": records });\n }\n\n if (Object.keys(unions).length > 0) {\n steps.push({ \"add-union\": unions });\n }\n\n return steps;\n}\n\nexport function convertStepsToYamlString(steps: MigrationStep[]): string {\n return yaml.dump(steps, {\n flowLevel: -1,\n lineWidth: -1,\n noRefs: true,\n quotingType: \"'\",\n forceQuotes: false,\n skipInvalid: false,\n });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,SAAS;AAI1B,SAASC,gBAAgBA,CAACC,KAAa,EAAU;EAC/C,QAAQA,KAAK,CAACC,IAAI;IAChB,KAAK,OAAO;MACV,OAAO,SAASF,gBAAgB,CAACC,KAAK,CAACE,KAAe,CAAC,GAAG;IAC5D,KAAK,SAAS;MACZ,OAAO,SAAS;IAClB,KAAK,QAAQ;MACX,OAAO,QAAQ;IACjB,KAAK,QAAQ;MACX,OAAO,QAAQ;IACjB,KAAK,UAAU;MACb,OAAO,UAAU;IACnB,KAAK,WAAW;MACd,OAAO,WAAW;IACpB,KAAK,UAAU;MACb,OAAO,YA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B,EAAmB;EAC9E,MAAMC,KAAsB,GAAG,EAAE;EACjC,MAAMC,OAA0E,GAAG,CAAC,CAAC;EACrF,MAAMC,MAAuC,GAAG,CAAC,CAAC;EAElD,KAAK,MAAMC,GAAG,IAAId,MAAM,CAACe,MAAM,CAACL,MAAM,CAAC,EAAE;IACvC,QAAQI,GAAG,CAAC1B,IAAI;MACd,KAAK,QAAQ;QAAE;UACbwB,OAAO,CAACE,GAAG,CAACvB,IAAI,CAAC,GAAGE,mBAAmB,CAACqB,GAAG,CAAC;UAC5C;QACF;MACA,KAAK,OAAO;QAAE;UACZD,MAAM,CAACC,GAAG,CAACvB,IAAI,CAAC,GAAGY,kBAAkB,CAACW,GAAG,CAAC;UAC1C;QACF;IACF;EACF;EAEA,IAAId,MAAM,CAACgB,IAAI,CAACJ,OAAO,CAAC,CAACK,MAAM,GAAG,CAAC,EAAE;IACnCN,KAAK,CAACO,IAAI,CAAC;MAAE,aAAa,EAAEN;IAAQ,CAAC,CAAC;EACxC;EAEA,IAAIZ,MAAM,CAACgB,IAAI,CAACH,MAAM,CAAC,CAACI,MAAM,GAAG,CAAC,EAAE;IAClCN,KAAK,CAACO,IAAI,CAAC;MAAE,WAAW,EAAEL;IAAO,CAAC,CAAC;EACrC;EAEA,OAAOF,KAAK;AACd;AAEA,OAAO,SAASQ,wBAAwBA,CAACR,KAAsB,EAAU;EACvE,OAAO1B,IAAI,CAACmC,IAAI,CAACT,KAAK,EAAE;IACtBU,SAAS,EAAE,CAAC,CAAC;IACbC,SAAS,EAAE,CAAC,CAAC;IACbC,MAAM,EAAE,IAAI;IACZC,WAAW,EAAE,GAAG;IAChBC,WAAW,EAAE,KAAK;IAClBC,WAAW,EAAE;EACf,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"convertSchemaToSteps.js","names":["yaml","convertFieldType","field","type","items","item","name","Error","convertRecordToYaml","recordDef","result","fields","docs","fieldName","fieldDef","Object","entries","fieldType","convertUnionToYaml","unionDef","variants","variantName","variantRef","discriminant","convertSchemaToSteps","schema","exportKey","def","steps","records","unions","values","keys","length","push","convertStepsToYamlString","dump","flowLevel","lineWidth","noRefs","quotingType","forceQuotes","skipInvalid"],"sources":["convertSchemaToSteps.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport yaml from \"js-yaml\";\nimport type { MigrationStep, UnionDefinition } from \"../steps/parseMigrationSteps.js\";\nimport type { P } from \"./validateSchemaModule.js\";\n\nfunction convertFieldType(field: P.Type): string {\n switch (field.type) {\n case \"array\":\n return `array<${convertFieldType(field.items as P.Type)}>`;\n case \"boolean\":\n return \"boolean\";\n case \"docRef\":\n return \"docRef\";\n case \"double\":\n return \"double\";\n case \"mediaRef\":\n return \"mediaRef\";\n case \"objectRef\":\n return \"objectRef\";\n case \"optional\":\n return `optional<${convertFieldType(field.item as P.Type)}>`;\n case \"ref\":\n return field.name;\n case \"string\":\n return \"string\";\n case \"unknown\":\n return \"unknown\";\n case \"userRef\":\n return \"userRef\";\n default:\n field satisfies never;\n throw new Error(`Unsupported field type: ${(field as P.Type).type}`);\n }\n}\n\nfunction convertRecordToYaml(\n recordDef: P.RecordDef,\n): { docs?: string; fields: Record<string, string> } {\n const result: { docs?: string; fields: Record<string, string> } = {\n fields: {},\n };\n\n if (recordDef.docs) {\n result.docs = recordDef.docs;\n }\n\n for (const [fieldName, fieldDef] of Object.entries(recordDef.fields)) {\n const fieldType = convertFieldType(fieldDef);\n result.fields[fieldName] = fieldType;\n }\n\n return result;\n}\n\nfunction convertUnionToYaml(unionDef: P.UnionDef): UnionDefinition {\n const variants: Record<string, string> = {};\n\n for (const [variantName, variantRef] of Object.entries(unionDef.variants)) {\n variants[variantName] = variantRef.name;\n }\n\n const result: UnionDefinition = {\n variants,\n };\n\n if (unionDef.discriminant !== \"type\") {\n result.discriminant = unionDef.discriminant;\n }\n\n return result;\n}\n\nexport function convertSchemaToSteps(schema: P.ReturnedSchema): MigrationStep[] {\n // Reject aliased schemas: the YAML step format cannot represent exportKey !== declaredName\n for (const [exportKey, def] of Object.entries(schema)) {\n if (exportKey !== def.name) {\n throw new Error(\n `Schema entry \"${exportKey}\" has declared model name \"${def.name}\". `\n + `The migration-step YAML format cannot represent aliases (exportKey !== declaredName). `\n + `Use the same name for both, or use the IR pipeline instead.`,\n );\n }\n }\n\n const steps: MigrationStep[] = [];\n const records: Record<string, { docs?: string; fields: Record<string, string> }> = {};\n const unions: Record<string, UnionDefinition> = {};\n\n for (const def of Object.values(schema)) {\n switch (def.type) {\n case \"record\": {\n records[def.name] = convertRecordToYaml(def);\n break;\n }\n case \"union\": {\n unions[def.name] = convertUnionToYaml(def);\n break;\n }\n }\n }\n\n if (Object.keys(records).length > 0) {\n steps.push({ \"add-records\": records });\n }\n\n if (Object.keys(unions).length > 0) {\n steps.push({ \"add-union\": unions });\n }\n\n return steps;\n}\n\nexport function convertStepsToYamlString(steps: MigrationStep[]): string {\n return yaml.dump(steps, {\n flowLevel: -1,\n lineWidth: -1,\n noRefs: true,\n quotingType: \"'\",\n forceQuotes: false,\n skipInvalid: false,\n });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,SAAS;AAI1B,SAASC,gBAAgBA,CAACC,KAAa,EAAU;EAC/C,QAAQA,KAAK,CAACC,IAAI;IAChB,KAAK,OAAO;MACV,OAAO,SAASF,gBAAgB,CAACC,KAAK,CAACE,KAAe,CAAC,GAAG;IAC5D,KAAK,SAAS;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IAAO,CAAC,CAAC;EACrC;EAEA,OAAOF,KAAK;AACd;AAEA,OAAO,SAASO,wBAAwBA,CAACP,KAAsB,EAAU;EACvE,OAAO5B,IAAI,CAACoC,IAAI,CAACR,KAAK,EAAE;IACtBS,SAAS,EAAE,CAAC,CAAC;IACbC,SAAS,EAAE,CAAC,CAAC;IACbC,MAAM,EAAE,IAAI;IACZC,WAAW,EAAE,GAAG;IAChBC,WAAW,EAAE,KAAK;IAClBC,WAAW,EAAE;EACf,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { formatVariantName } from "../formatVariantName.js";
18
+ import { GENERATED_FILE_HEADER } from "../generatedFileHeader.js";
19
+ import { resolveMinVersion } from "./resolveSchemaChain.js";
20
+ import { MODELS_PATH, TYPES_REEXPORT_PATH, typesFilePath, VERSIONED_DOC_REF_PATH, versionedTypeName, VERSIONS_PATH } from "./runtimeSchema.js";
21
+
22
+ /**
23
+ * Generate the index.ts barrel export from a versioned schema.
24
+ *
25
+ * Exports:
26
+ * - `models.js` (star export — model constants and DocumentModel)
27
+ * - `types.js` (star export — latest-version type aliases)
28
+ * - `versions.js` (star export — SupportedVersions, LatestVersion, MinSupportedVersion)
29
+ * - `versionedDocRef.js` (star export — VersionedDocRef types and factory)
30
+ * - Per supported version: explicit named type exports from `types_vN.js`
31
+ * (not star exports, to avoid polluting autocomplete for read-only consumers)
32
+ */
33
+ export function generateIndexFromChain(resolved, minSupportedVersion) {
34
+ const {
35
+ chain
36
+ } = resolved;
37
+ const {
38
+ minVersion
39
+ } = resolveMinVersion(chain, minSupportedVersion);
40
+ let output = GENERATED_FILE_HEADER;
41
+
42
+ // Star exports for core modules
43
+ output += `export * from "${MODELS_PATH}";\n`;
44
+ output += `export * from "${TYPES_REEXPORT_PATH}";\n`;
45
+ output += `export * from "${VERSIONS_PATH}";\n`;
46
+ output += `export * from "${VERSIONED_DOC_REF_PATH}";\n`;
47
+
48
+ // Per-version explicit named type exports
49
+ for (const {
50
+ version,
51
+ ir
52
+ } of chain) {
53
+ if (version < minVersion) continue;
54
+ const typeNames = [];
55
+ for (const [modelKey, modelDef] of Object.entries(ir.models)) {
56
+ if (modelDef.type === "record") {
57
+ typeNames.push(versionedTypeName(modelKey, version));
58
+ } else if (modelDef.type === "union") {
59
+ typeNames.push(versionedTypeName(modelKey, version));
60
+
61
+ // Union variant types
62
+ for (const variantName of Object.keys(modelDef.union.variants)) {
63
+ const formattedVariant = formatVariantName(variantName);
64
+ typeNames.push(`${versionedTypeName(modelKey, version)}${formattedVariant}`);
65
+ }
66
+ }
67
+ }
68
+ if (typeNames.length > 0) {
69
+ output += `export type { ${typeNames.sort().join(", ")} } from "${typesFilePath(version)}";\n`;
70
+ }
71
+ }
72
+ return output;
73
+ }
74
+ //# sourceMappingURL=generateIndexFromSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateIndexFromSchema.js","names":["formatVariantName","GENERATED_FILE_HEADER","resolveMinVersion","MODELS_PATH","TYPES_REEXPORT_PATH","typesFilePath","VERSIONED_DOC_REF_PATH","versionedTypeName","VERSIONS_PATH","generateIndexFromChain","resolved","minSupportedVersion","chain","minVersion","output","version","ir","typeNames","modelKey","modelDef","Object","entries","models","type","push","variantName","keys","union","variants","formattedVariant","length","sort","join"],"sources":["generateIndexFromSchema.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { formatVariantName } from \"../formatVariantName.js\";\nimport { GENERATED_FILE_HEADER } from \"../generatedFileHeader.js\";\nimport type { ResolvedIrChain } from \"./resolveSchemaChain.js\";\nimport { resolveMinVersion } from \"./resolveSchemaChain.js\";\nimport {\n MODELS_PATH,\n TYPES_REEXPORT_PATH,\n typesFilePath,\n VERSIONED_DOC_REF_PATH,\n versionedTypeName,\n VERSIONS_PATH,\n} from \"./runtimeSchema.js\";\n\n/**\n * Generate the index.ts barrel export from a versioned schema.\n *\n * Exports:\n * - `models.js` (star export — model constants and DocumentModel)\n * - `types.js` (star export — latest-version type aliases)\n * - `versions.js` (star export — SupportedVersions, LatestVersion, MinSupportedVersion)\n * - `versionedDocRef.js` (star export — VersionedDocRef types and factory)\n * - Per supported version: explicit named type exports from `types_vN.js`\n * (not star exports, to avoid polluting autocomplete for read-only consumers)\n */\nexport function generateIndexFromChain(\n resolved: ResolvedIrChain,\n minSupportedVersion?: number,\n): string {\n const { chain } = resolved;\n const { minVersion } = resolveMinVersion(chain, minSupportedVersion);\n\n let output = GENERATED_FILE_HEADER;\n\n // Star exports for core modules\n output += `export * from \"${MODELS_PATH}\";\\n`;\n output += `export * from \"${TYPES_REEXPORT_PATH}\";\\n`;\n output += `export * from \"${VERSIONS_PATH}\";\\n`;\n output += `export * from \"${VERSIONED_DOC_REF_PATH}\";\\n`;\n\n // Per-version explicit named type exports\n for (const { version, ir } of chain) {\n if (version < minVersion) continue;\n\n const typeNames: string[] = [];\n\n for (const [modelKey, modelDef] of Object.entries(ir.models)) {\n if (modelDef.type === \"record\") {\n typeNames.push(versionedTypeName(modelKey, version));\n } else if (modelDef.type === \"union\") {\n typeNames.push(versionedTypeName(modelKey, version));\n\n // Union variant types\n for (const variantName of Object.keys(modelDef.union.variants)) {\n const formattedVariant = formatVariantName(variantName);\n typeNames.push(`${versionedTypeName(modelKey, version)}${formattedVariant}`);\n }\n }\n }\n\n if (typeNames.length > 0) {\n output += `export type { ${typeNames.sort().join(\", \")} } from \"${\n typesFilePath(version)\n }\";\\n`;\n }\n }\n\n return output;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,qBAAqB,QAAQ,2BAA2B;AAEjE,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SACEC,WAAW,EACXC,mBAAmB,EACnBC,aAAa,EACbC,sBAAsB,EACtBC,iBAAiB,EACjBC,aAAa,QACR,oBAAoB;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CACpCC,QAAyB,EACzBC,mBAA4B,EACpB;EACR,MAAM;IAAEC;EAAM,CAAC,GAAGF,QAAQ;EAC1B,MAAM;IAAEG;EAAW,CAAC,GAAGX,iBAAiB,CAACU,KAAK,EAAED,mBAAmB,CAAC;EAEpE,IAAIG,MAAM,GAAGb,qBAAqB;;EAElC;EACAa,MAAM,IAAI,kBAAkBX,WAAW,MAAM;EAC7CW,MAAM,IAAI,kBAAkBV,mBAAmB,MAAM;EACrDU,MAAM,IAAI,kBAAkBN,aAAa,MAAM;EAC/CM,MAAM,IAAI,kBAAkBR,sBAAsB,MAAM;;EAExD;EACA,KAAK,MAAM;IAAES,OAAO;IAAEC;EAAG,CAAC,IAAIJ,KAAK,EAAE;IACnC,IAAIG,OAAO,GAAGF,UAAU,EAAE;IAE1B,MAAMI,SAAmB,GAAG,EAAE;IAE9B,KAAK,MAAM,CAACC,QAAQ,EAAEC,QAAQ,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,EAAE,CAACM,MAAM,CAAC,EAAE;MAC5D,IAAIH,QAAQ,CAACI,IAAI,KAAK,QAAQ,EAAE;QAC9BN,SAAS,CAACO,IAAI,CAACjB,iBAAiB,CAACW,QAAQ,EAAEH,OAAO,CAAC,CAAC;MACtD,CAAC,MAAM,IAAII,QAAQ,CAACI,IAAI,KAAK,OAAO,EAAE;QACpCN,SAAS,CAACO,IAAI,CAACjB,iBAAiB,CAACW,QAAQ,EAAEH,OAAO,CAAC,CAAC;;QAEpD;QACA,KAAK,MAAMU,WAAW,IAAIL,MAAM,CAACM,IAAI,CAACP,QAAQ,CAACQ,KAAK,CAACC,QAAQ,CAAC,EAAE;UAC9D,MAAMC,gBAAgB,GAAG7B,iBAAiB,CAACyB,WAAW,CAAC;UACvDR,SAAS,CAACO,IAAI,CAAC,GAAGjB,iBAAiB,CAACW,QAAQ,EAAEH,OAAO,CAAC,GAAGc,gBAAgB,EAAE,CAAC;QAC9E;MACF;IACF;IAEA,IAAIZ,SAAS,CAACa,MAAM,GAAG,CAAC,EAAE;MACxBhB,MAAM,IAAI,iBAAiBG,SAAS,CAACc,IAAI,CAAC,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC,YACpD3B,aAAa,CAACU,OAAO,CAAC,MAClB;IACR;EACF;EAEA,OAAOD,MAAM;AACf","ignoreList":[]}
@@ -0,0 +1,264 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { GENERATED_FILE_HEADER } from "../generatedFileHeader.js";
18
+ import { convertFieldTypeToDescriptor, convertFieldTypeToInternalTypeScript, convertFieldTypeToInternalZod } from "../ir/irFieldHelpers.js";
19
+
20
+ /** Collected info about all fields for a model across all versions. */
21
+
22
+ /**
23
+ * Represents an upgrade step for a model between version transitions.
24
+ */
25
+
26
+ /**
27
+ * Helper to iterate sorted entries of a Map.
28
+ */
29
+ function sortedEntries(map) {
30
+ return Array.from(map.entries()).sort(([a], [b]) => a.localeCompare(b));
31
+ }
32
+
33
+ /**
34
+ * Collect all record model info across all versions and compute upgrade steps.
35
+ */
36
+ function collectRecordModels(chain) {
37
+ const allRecordModels = new Map();
38
+
39
+ // Initialize models from all versions
40
+ for (const {
41
+ version,
42
+ ir
43
+ } of chain) {
44
+ for (const [modelKey, modelDef] of Object.entries(ir.models)) {
45
+ if (modelDef.type !== "record") continue;
46
+ if (!allRecordModels.has(modelKey)) {
47
+ allRecordModels.set(modelKey, {
48
+ allFields: new Map(),
49
+ steps: []
50
+ });
51
+ }
52
+ const model = allRecordModels.get(modelKey);
53
+ for (const field of modelDef.record.fields) {
54
+ const existing = model.allFields.get(field.key);
55
+ if (existing == null) {
56
+ model.allFields.set(field.key, {
57
+ fieldType: field.fieldType,
58
+ isOptional: field.isOptional === true,
59
+ presentInVersions: new Set([version]),
60
+ alwaysOptional: field.isOptional === true,
61
+ everOptional: field.isOptional === true
62
+ });
63
+ } else {
64
+ existing.presentInVersions.add(version);
65
+ if (field.isOptional !== true) {
66
+ existing.alwaysOptional = false;
67
+ }
68
+ if (field.isOptional === true) {
69
+ existing.everOptional = true;
70
+ }
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ // Compute upgrade steps from version diffs
77
+ for (let i = 1; i < chain.length; i++) {
78
+ const prevEntry = chain[i - 1];
79
+ const currEntry = chain[i];
80
+ for (const [modelKey, currModelDef] of Object.entries(currEntry.ir.models)) {
81
+ if (currModelDef.type !== "record") continue;
82
+ const prevModelDef = prevEntry.ir.models[modelKey];
83
+ if (prevModelDef == null || prevModelDef.type !== "record") continue;
84
+ const model = allRecordModels.get(modelKey);
85
+ if (model == null) continue;
86
+ const prevFields = new Set(prevModelDef.record.fields.map(f => f.key));
87
+ const currFields = new Set(currModelDef.record.fields.map(f => f.key));
88
+
89
+ // Fields added in this version
90
+ const addedFields = new Map();
91
+ const recordUpgrades = currEntry.migrations?.[modelKey];
92
+ for (const fieldKey of currFields) {
93
+ if (!prevFields.has(fieldKey)) {
94
+ const annotation = recordUpgrades?.[fieldKey];
95
+ if (annotation != null) {
96
+ addedFields.set(fieldKey, {
97
+ derivedFrom: [...annotation.derivedFrom],
98
+ forwardSource: annotation.forwardSource
99
+ });
100
+ } else {
101
+ addedFields.set(fieldKey, {
102
+ derivedFrom: [],
103
+ forwardSource: "() => undefined"
104
+ });
105
+ }
106
+ }
107
+ }
108
+
109
+ // Fields removed in this version
110
+ const removedFields = [];
111
+ for (const fieldKey of prevFields) {
112
+ if (!currFields.has(fieldKey)) {
113
+ removedFields.push(fieldKey);
114
+ }
115
+ }
116
+ if (addedFields.size > 0 || removedFields.length > 0) {
117
+ model.steps.push({
118
+ name: `v${currEntry.version}`,
119
+ addedInVersion: currEntry.version,
120
+ fields: addedFields,
121
+ removedFields
122
+ });
123
+ }
124
+ }
125
+ }
126
+
127
+ // Mark fields that are not present in ALL versions as optional in internal type
128
+ const totalVersions = chain.length;
129
+ for (const model of allRecordModels.values()) {
130
+ for (const [, fieldInfo] of model.allFields) {
131
+ if (fieldInfo.presentInVersions.size < totalVersions) {
132
+ fieldInfo.alwaysOptional = true;
133
+ }
134
+ }
135
+ }
136
+ return allRecordModels;
137
+ }
138
+
139
+ /**
140
+ * Generate _internal/types.ts content.
141
+ */
142
+ function generateInternalTypes(allRecordModels) {
143
+ let output = GENERATED_FILE_HEADER;
144
+ output += "\n";
145
+ for (const [modelKey, model] of sortedEntries(allRecordModels)) {
146
+ output += `/** Internal representation containing all fields across all schema versions. */\n`;
147
+ output += `export interface ${modelKey}__Internal {\n`;
148
+ for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {
149
+ const tsType = convertFieldTypeToInternalTypeScript(fieldInfo.fieldType, fieldInfo.isOptional);
150
+ const optional = fieldInfo.alwaysOptional ? "?" : "";
151
+ output += ` readonly ${fieldName}${optional}: ${tsType};\n`;
152
+ }
153
+ output += "}\n\n";
154
+ }
155
+ return output;
156
+ }
157
+
158
+ /**
159
+ * Generate _internal/upgrades.ts content.
160
+ */
161
+ function generateUpgrades(allRecordModels, latestIr) {
162
+ let output = GENERATED_FILE_HEADER;
163
+ const hasRecords = allRecordModels.size > 0;
164
+ const hasUnions = Object.values(latestIr.models).some(m => m.type === "union");
165
+ const imports = [];
166
+ if (hasRecords) imports.push("UpgradeRegistry");
167
+ if (hasUnions) imports.push("UnionUpgradeRegistry");
168
+ if (imports.length > 0) {
169
+ output += `import type { ${imports.join(", ")} } from "@palantir/pack.document-schema.model-types";\n\n`;
170
+ }
171
+ for (const [modelKey, model] of sortedEntries(allRecordModels)) {
172
+ output += `export const ${modelKey}Upgrades: UpgradeRegistry<"${modelKey}"> = {\n`;
173
+ output += ` modelName: "${modelKey}",\n`;
174
+
175
+ // allFields
176
+ output += ` allFields: {\n`;
177
+ for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {
178
+ const typeDescriptor = convertFieldTypeToDescriptor(fieldInfo.fieldType, fieldInfo.isOptional);
179
+ output += ` ${fieldName}: { type: ${typeDescriptor} },\n`;
180
+ }
181
+ output += ` },\n`;
182
+
183
+ // steps
184
+ output += ` steps: [\n`;
185
+ for (const step of model.steps) {
186
+ output += ` {\n`;
187
+ output += ` name: "${step.name}",\n`;
188
+ output += ` addedInVersion: ${step.addedInVersion},\n`;
189
+ output += ` fields: {\n`;
190
+ for (const [fieldName, fieldMeta] of step.fields) {
191
+ output += ` ${fieldName}: {\n`;
192
+ output += ` derivedFrom: [${fieldMeta.derivedFrom.map(d => `"${d}"`).join(", ")}],\n`;
193
+ output += ` forward: ${fieldMeta.forwardSource},\n`;
194
+ if (fieldMeta.default !== undefined) {
195
+ output += ` default: ${JSON.stringify(fieldMeta.default)},\n`;
196
+ }
197
+ output += ` },\n`;
198
+ }
199
+ output += ` },\n`;
200
+ if (step.removedFields.length > 0) {
201
+ output += ` removedFields: [${step.removedFields.map(f => `"${f}"`).join(", ")}],\n`;
202
+ }
203
+ output += ` },\n`;
204
+ }
205
+ output += ` ],\n`;
206
+ output += `};\n\n`;
207
+ }
208
+
209
+ // Generate UnionUpgradeRegistry entries for union models
210
+ for (const [modelKey, modelDef] of Object.entries(latestIr.models)) {
211
+ if (modelDef.type !== "union") continue;
212
+ const union = modelDef.union;
213
+ output += `export const ${modelKey}Upgrades: UnionUpgradeRegistry<"${modelKey}"> = {\n`;
214
+ output += ` modelName: "${modelKey}",\n`;
215
+ output += ` discriminant: "${union.discriminant}",\n`;
216
+ output += ` variants: {\n`;
217
+ for (const [variantKey, variantModelKey] of Object.entries(union.variants)) {
218
+ output += ` "${variantKey}": "${variantModelKey}",\n`;
219
+ }
220
+ output += ` },\n`;
221
+ output += `};\n\n`;
222
+ }
223
+ return output;
224
+ }
225
+
226
+ /**
227
+ * Generate _internal/schema.ts content.
228
+ */
229
+ function generateInternalSchemaContent(allRecordModels) {
230
+ let output = GENERATED_FILE_HEADER;
231
+ output += `import { z } from "zod";\n\n`;
232
+ for (const [modelKey, model] of sortedEntries(allRecordModels)) {
233
+ output += `export const ${modelKey}InternalSchema = z.object({\n`;
234
+ for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {
235
+ // Use everOptional: a field optional in ANY version must stay optional
236
+ // in the internal schema because older documents may legitimately omit it.
237
+ const zodType = convertFieldTypeToInternalZod(fieldInfo.fieldType, fieldInfo.alwaysOptional || fieldInfo.everOptional);
238
+ output += ` ${fieldName}: ${zodType},\n`;
239
+ }
240
+ output += `}).passthrough();\n\n`;
241
+ }
242
+ return output;
243
+ }
244
+
245
+ /**
246
+ * Generate _internal/types.ts, _internal/upgrades.ts, and _internal/schema.ts
247
+ * from an already-resolved versioned IR chain.
248
+ */
249
+ export function generateInternalFromChain(resolved) {
250
+ const {
251
+ chain
252
+ } = resolved;
253
+ const latestIr = chain[chain.length - 1].ir;
254
+ const allRecordModels = collectRecordModels(chain);
255
+ const internalTypes = generateInternalTypes(allRecordModels);
256
+ const upgrades = generateUpgrades(allRecordModels, latestIr);
257
+ const internalSchema = generateInternalSchemaContent(allRecordModels);
258
+ return {
259
+ internalTypes,
260
+ upgrades,
261
+ internalSchema
262
+ };
263
+ }
264
+ //# sourceMappingURL=generateInternalFromSchema.js.map