@palantir/pack.document-schema.type-gen 0.9.0 → 0.11.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 (156) 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/assetUpdateSchemaHandler.js +84 -0
  6. package/build/esm/commands/asset/assetUpdateSchemaHandler.js.map +1 -0
  7. package/build/esm/commands/asset/registerAssetCommands.js +3 -1
  8. package/build/esm/commands/asset/registerAssetCommands.js.map +1 -1
  9. package/build/esm/commands/ir/irGenTypesHandler.js +49 -0
  10. package/build/esm/commands/ir/irGenTypesHandler.js.map +1 -0
  11. package/build/esm/commands/ir/registerIrCommands.js +2 -0
  12. package/build/esm/commands/ir/registerIrCommands.js.map +1 -1
  13. package/build/esm/commands/schema/registerSchemaCommands.js +2 -2
  14. package/build/esm/commands/schema/registerSchemaCommands.js.map +1 -1
  15. package/build/esm/commands/schema/schemaIrHandler.js +56 -0
  16. package/build/esm/commands/schema/schemaIrHandler.js.map +1 -0
  17. package/build/esm/index.js +0 -6
  18. package/build/esm/index.js.map +1 -1
  19. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js +1 -1
  20. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js.map +1 -1
  21. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js +1 -1
  22. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js.map +1 -1
  23. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js +1 -1
  24. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js.map +1 -1
  25. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js +1 -1
  26. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js.map +1 -1
  27. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js +1 -1
  28. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js.map +1 -1
  29. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js +1 -1
  30. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js.map +1 -1
  31. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js +1 -1
  32. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js.map +1 -1
  33. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js +1 -1
  34. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js.map +1 -1
  35. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js +1 -1
  36. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js.map +1 -1
  37. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js +1 -1
  38. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js.map +1 -1
  39. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js +1 -1
  40. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js.map +1 -1
  41. package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js +23 -0
  42. package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js.map +1 -1
  43. package/build/esm/utils/ir/irFieldHelpers.js +383 -0
  44. package/build/esm/utils/ir/irFieldHelpers.js.map +1 -0
  45. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/single-version.js.map +1 -1
  46. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/three-version-chain.js.map +1 -1
  47. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js.map +1 -1
  48. package/build/esm/utils/schema/__tests__/convertSchemaToSteps.test.js +13 -0
  49. package/build/esm/utils/schema/__tests__/convertSchemaToSteps.test.js.map +1 -1
  50. package/build/esm/utils/schema/__tests__/fixtures.js +78 -13
  51. package/build/esm/utils/schema/__tests__/fixtures.js.map +1 -1
  52. package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js +19 -7
  53. package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js.map +1 -1
  54. package/build/esm/utils/schema/__tests__/generateModelMetadataFromSchema.test.js +12 -7
  55. package/build/esm/utils/schema/__tests__/generateModelMetadataFromSchema.test.js.map +1 -1
  56. package/build/esm/utils/schema/__tests__/generateScopeFromSchema.test.js +6 -5
  57. package/build/esm/utils/schema/__tests__/generateScopeFromSchema.test.js.map +1 -1
  58. package/build/esm/utils/schema/__tests__/generateVersionedTypesFromSchema.test.js +19 -10
  59. package/build/esm/utils/schema/__tests__/generateVersionedTypesFromSchema.test.js.map +1 -1
  60. package/build/esm/utils/schema/__tests__/generateVersionedZodFromSchema.test.js +15 -10
  61. package/build/esm/utils/schema/__tests__/generateVersionedZodFromSchema.test.js.map +1 -1
  62. package/build/esm/utils/schema/__tests__/generateVersionsFromSchema.test.js +6 -5
  63. package/build/esm/utils/schema/__tests__/generateVersionsFromSchema.test.js.map +1 -1
  64. package/build/esm/utils/schema/__tests__/snapshotUtils.js +3 -0
  65. package/build/esm/utils/schema/__tests__/snapshotUtils.js.map +1 -1
  66. package/build/esm/utils/schema/convertSchemaToSteps.js +6 -0
  67. package/build/esm/utils/schema/convertSchemaToSteps.js.map +1 -1
  68. package/build/esm/utils/schema/generateIndexFromSchema.js +21 -14
  69. package/build/esm/utils/schema/generateIndexFromSchema.js.map +1 -1
  70. package/build/esm/utils/schema/generateInternalFromSchema.js +202 -191
  71. package/build/esm/utils/schema/generateInternalFromSchema.js.map +1 -1
  72. package/build/esm/utils/schema/generateModelMetadataFromSchema.js +89 -80
  73. package/build/esm/utils/schema/generateModelMetadataFromSchema.js.map +1 -1
  74. package/build/esm/utils/schema/generateScopeFromSchema.js +29 -33
  75. package/build/esm/utils/schema/generateScopeFromSchema.js.map +1 -1
  76. package/build/esm/utils/schema/generateTypesFromSchema.js +9 -1
  77. package/build/esm/utils/schema/generateTypesFromSchema.js.map +1 -1
  78. package/build/esm/utils/schema/generateVersionedTypesFromSchema.js +61 -155
  79. package/build/esm/utils/schema/generateVersionedTypesFromSchema.js.map +1 -1
  80. package/build/esm/utils/schema/generateVersionedZodFromSchema.js +58 -94
  81. package/build/esm/utils/schema/generateVersionedZodFromSchema.js.map +1 -1
  82. package/build/esm/utils/schema/generateVersionsFromSchema.js +7 -5
  83. package/build/esm/utils/schema/generateVersionsFromSchema.js.map +1 -1
  84. package/build/esm/utils/schema/loadSchemaModule.js +53 -0
  85. package/build/esm/utils/schema/loadSchemaModule.js.map +1 -0
  86. package/build/esm/utils/schema/resolveSchemaChain.js +68 -9
  87. package/build/esm/utils/schema/resolveSchemaChain.js.map +1 -1
  88. package/build/esm/utils/schema/runtimeSchema.js +3 -27
  89. package/build/esm/utils/schema/runtimeSchema.js.map +1 -1
  90. package/build/esm/utils/schema/writeAllSdkFiles.js +113 -0
  91. package/build/esm/utils/schema/writeAllSdkFiles.js.map +1 -0
  92. package/build/esm/utils/steps/__tests__/__snapshots__/types/arrayFields.js.map +1 -1
  93. package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js +1 -1
  94. package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js.map +1 -1
  95. package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js +1 -1
  96. package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map +1 -1
  97. package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js.map +1 -1
  98. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleRecord.js.map +1 -1
  99. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js +1 -1
  100. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js.map +1 -1
  101. package/build/esm/utils/steps/__tests__/convertStepsToIr.test.js +93 -1
  102. package/build/esm/utils/steps/__tests__/convertStepsToIr.test.js.map +1 -1
  103. package/build/esm/utils/steps/convertStepsToIr.js +43 -35
  104. package/build/esm/utils/steps/convertStepsToIr.js.map +1 -1
  105. package/build/types/commands/asset/__tests__/buildPrefixRewriteFetch.test.d.ts +2 -0
  106. package/build/types/commands/asset/__tests__/buildPrefixRewriteFetch.test.d.ts.map +1 -0
  107. package/build/types/commands/asset/assetDeployHandler.d.ts +15 -0
  108. package/build/types/commands/asset/assetDeployHandler.d.ts.map +1 -1
  109. package/build/types/commands/asset/assetUpdateSchemaHandler.d.ts +12 -0
  110. package/build/types/commands/asset/assetUpdateSchemaHandler.d.ts.map +1 -0
  111. package/build/types/commands/asset/registerAssetCommands.d.ts.map +1 -1
  112. package/build/types/commands/ir/irGenTypesHandler.d.ts +8 -0
  113. package/build/types/commands/ir/irGenTypesHandler.d.ts.map +1 -0
  114. package/build/types/commands/ir/registerIrCommands.d.ts.map +1 -1
  115. package/build/types/commands/schema/registerSchemaCommands.d.ts.map +1 -1
  116. package/build/types/commands/schema/schemaIrHandler.d.ts +19 -0
  117. package/build/types/commands/schema/schemaIrHandler.d.ts.map +1 -0
  118. package/build/types/index.d.ts +1 -6
  119. package/build/types/index.d.ts.map +1 -1
  120. package/build/types/utils/ir/irFieldHelpers.d.ts +36 -0
  121. package/build/types/utils/ir/irFieldHelpers.d.ts.map +1 -0
  122. package/build/types/utils/schema/__tests__/fixtures.d.ts +10 -1
  123. package/build/types/utils/schema/__tests__/fixtures.d.ts.map +1 -1
  124. package/build/types/utils/schema/__tests__/snapshotUtils.d.ts +2 -0
  125. package/build/types/utils/schema/__tests__/snapshotUtils.d.ts.map +1 -1
  126. package/build/types/utils/schema/convertSchemaToSteps.d.ts.map +1 -1
  127. package/build/types/utils/schema/generateIndexFromSchema.d.ts +5 -3
  128. package/build/types/utils/schema/generateIndexFromSchema.d.ts.map +1 -1
  129. package/build/types/utils/schema/generateInternalFromSchema.d.ts +6 -7
  130. package/build/types/utils/schema/generateInternalFromSchema.d.ts.map +1 -1
  131. package/build/types/utils/schema/generateModelMetadataFromSchema.d.ts +3 -8
  132. package/build/types/utils/schema/generateModelMetadataFromSchema.d.ts.map +1 -1
  133. package/build/types/utils/schema/generateScopeFromSchema.d.ts +2 -2
  134. package/build/types/utils/schema/generateScopeFromSchema.d.ts.map +1 -1
  135. package/build/types/utils/schema/generateTypesFromSchema.d.ts.map +1 -1
  136. package/build/types/utils/schema/generateVersionedTypesFromSchema.d.ts +4 -7
  137. package/build/types/utils/schema/generateVersionedTypesFromSchema.d.ts.map +1 -1
  138. package/build/types/utils/schema/generateVersionedZodFromSchema.d.ts +3 -7
  139. package/build/types/utils/schema/generateVersionedZodFromSchema.d.ts.map +1 -1
  140. package/build/types/utils/schema/generateVersionsFromSchema.d.ts +3 -3
  141. package/build/types/utils/schema/generateVersionsFromSchema.d.ts.map +1 -1
  142. package/build/types/utils/schema/loadSchemaModule.d.ts +14 -0
  143. package/build/types/utils/schema/loadSchemaModule.d.ts.map +1 -0
  144. package/build/types/utils/schema/resolveSchemaChain.d.ts +29 -8
  145. package/build/types/utils/schema/resolveSchemaChain.d.ts.map +1 -1
  146. package/build/types/utils/schema/runtimeSchema.d.ts +2 -32
  147. package/build/types/utils/schema/runtimeSchema.d.ts.map +1 -1
  148. package/build/types/utils/schema/writeAllSdkFiles.d.ts +8 -0
  149. package/build/types/utils/schema/writeAllSdkFiles.d.ts.map +1 -0
  150. package/build/types/utils/steps/convertStepsToIr.d.ts +3 -3
  151. package/build/types/utils/steps/convertStepsToIr.d.ts.map +1 -1
  152. package/package.json +4 -4
  153. package/build/esm/commands/schema/schemaGenTypesHandler.js +0 -147
  154. package/build/esm/commands/schema/schemaGenTypesHandler.js.map +0 -1
  155. package/build/types/commands/schema/schemaGenTypesHandler.d.ts +0 -8
  156. package/build/types/commands/schema/schemaGenTypesHandler.d.ts.map +0 -1
@@ -0,0 +1,113 @@
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 { consola } from "consola";
18
+ import fs from "fs-extra";
19
+ import path from "path";
20
+ import { generateIndexFromChain } from "./generateIndexFromSchema.js";
21
+ import { generateInternalFromChain } from "./generateInternalFromSchema.js";
22
+ import { generateModelMetadataFromChain } from "./generateModelMetadataFromSchema.js";
23
+ import { generateScopeFromChain } from "./generateScopeFromSchema.js";
24
+ import { generateVersionedTypesFromChain } from "./generateVersionedTypesFromSchema.js";
25
+ import { generateVersionedZodFromChain } from "./generateVersionedZodFromSchema.js";
26
+ import { generateVersionsFromChain } from "./generateVersionsFromSchema.js";
27
+ /**
28
+ * Generate every versioned SDK output file from a resolved IR chain and write
29
+ * them to `outputDir`.
30
+ */
31
+ export async function writeAllSdkFiles(resolved, outputDir, minSupportedVersion) {
32
+ await fs.ensureDir(outputDir);
33
+
34
+ // Versioned types
35
+ consola.info("Generating versioned types...");
36
+ const types = generateVersionedTypesFromChain(resolved, minSupportedVersion);
37
+ for (const [version, content] of types.readTypes) {
38
+ const filePath = path.join(outputDir, `types_v${version}.ts`);
39
+ await fs.writeFile(filePath, content, "utf8");
40
+ consola.success(`Generated read types: ${filePath}`);
41
+ }
42
+ for (const [version, content] of types.writeTypes) {
43
+ const filePath = path.join(outputDir, `writeTypes_v${version}.ts`);
44
+ await fs.writeFile(filePath, content, "utf8");
45
+ consola.success(`Generated write types: ${filePath}`);
46
+ }
47
+ const typesPath = path.join(outputDir, "types.ts");
48
+ await fs.writeFile(typesPath, types.typesReExport, "utf8");
49
+ consola.success(`Generated types re-export: ${typesPath}`);
50
+
51
+ // Versioned Zod
52
+ consola.info("Generating versioned Zod schemas...");
53
+ const zod = generateVersionedZodFromChain(resolved, minSupportedVersion);
54
+ for (const [version, content] of zod.zodSchemas) {
55
+ const filePath = path.join(outputDir, `schema_v${version}.ts`);
56
+ await fs.writeFile(filePath, content, "utf8");
57
+ consola.success(`Generated Zod schema: ${filePath}`);
58
+ }
59
+ const schemaPath = path.join(outputDir, "schema.ts");
60
+ await fs.writeFile(schemaPath, zod.schemaReExport, "utf8");
61
+ consola.success(`Generated schema re-export: ${schemaPath}`);
62
+
63
+ // Internal
64
+ consola.info("Generating internal types and upgrades...");
65
+ const internal = generateInternalFromChain(resolved);
66
+ const internalDir = path.join(outputDir, "_internal");
67
+ await fs.ensureDir(internalDir);
68
+ await fs.writeFile(path.join(internalDir, "types.ts"), internal.internalTypes, "utf8");
69
+ consola.success(`Generated internal types: ${path.join(internalDir, "types.ts")}`);
70
+ await fs.writeFile(path.join(internalDir, "upgrades.ts"), internal.upgrades, "utf8");
71
+ consola.success(`Generated upgrades: ${path.join(internalDir, "upgrades.ts")}`);
72
+ await fs.writeFile(path.join(internalDir, "schema.ts"), internal.internalSchema, "utf8");
73
+ consola.success(`Generated internal schema: ${path.join(internalDir, "schema.ts")}`);
74
+ await fs.writeFile(path.join(internalDir, "upgradeFns.ts"), internal.internalUpgradeFns, "utf8");
75
+ consola.success(`Generated upgrade functions: ${path.join(internalDir, "upgradeFns.ts")}`);
76
+
77
+ // versions.ts
78
+ consola.info("Generating version types...");
79
+ const versionsContent = generateVersionsFromChain(resolved, minSupportedVersion);
80
+ const versionsPath = path.join(outputDir, "versions.ts");
81
+ await fs.writeFile(versionsPath, versionsContent, "utf8");
82
+ consola.success(`Generated versions: ${versionsPath}`);
83
+
84
+ // index.ts
85
+ consola.info("Generating index barrel export...");
86
+ const indexContent = generateIndexFromChain(resolved, minSupportedVersion);
87
+ const indexPath = path.join(outputDir, "index.ts");
88
+ await fs.writeFile(indexPath, indexContent, "utf8");
89
+ consola.success(`Generated index: ${indexPath}`);
90
+
91
+ // models.ts
92
+ consola.info("Generating model metadata...");
93
+ const modelMetadata = generateModelMetadataFromChain(resolved, minSupportedVersion);
94
+ const modelsPath = path.join(outputDir, "models.ts");
95
+ await fs.writeFile(modelsPath, modelMetadata.modelsFile, "utf8");
96
+ consola.success(`Generated models: ${modelsPath}`);
97
+
98
+ // versionedDocRef.ts
99
+ consola.info("Generating versioned document ref types...");
100
+ const versionedDocRefContent = generateScopeFromChain(resolved, minSupportedVersion);
101
+ const versionedDocRefPath = path.join(outputDir, "versionedDocRef.ts");
102
+ await fs.writeFile(versionedDocRefPath, versionedDocRefContent, "utf8");
103
+ consola.success(`Generated versioned doc ref: ${versionedDocRefPath}`);
104
+ }
105
+ export function parseMinVersion(minVersion) {
106
+ if (minVersion == null) return undefined;
107
+ const parsed = parseInt(minVersion, 10);
108
+ if (isNaN(parsed)) {
109
+ throw new Error(`--min-version must be a valid integer, got: "${minVersion}"`);
110
+ }
111
+ return parsed;
112
+ }
113
+ //# sourceMappingURL=writeAllSdkFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeAllSdkFiles.js","names":["consola","fs","path","generateIndexFromChain","generateInternalFromChain","generateModelMetadataFromChain","generateScopeFromChain","generateVersionedTypesFromChain","generateVersionedZodFromChain","generateVersionsFromChain","writeAllSdkFiles","resolved","outputDir","minSupportedVersion","ensureDir","info","types","version","content","readTypes","filePath","join","writeFile","success","writeTypes","typesPath","typesReExport","zod","zodSchemas","schemaPath","schemaReExport","internal","internalDir","internalTypes","upgrades","internalSchema","internalUpgradeFns","versionsContent","versionsPath","indexContent","indexPath","modelMetadata","modelsPath","modelsFile","versionedDocRefContent","versionedDocRefPath","parseMinVersion","minVersion","undefined","parsed","parseInt","isNaN","Error"],"sources":["writeAllSdkFiles.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 { consola } from \"consola\";\nimport fs from \"fs-extra\";\nimport path from \"path\";\nimport { generateIndexFromChain } from \"./generateIndexFromSchema.js\";\nimport { generateInternalFromChain } from \"./generateInternalFromSchema.js\";\nimport { generateModelMetadataFromChain } from \"./generateModelMetadataFromSchema.js\";\nimport { generateScopeFromChain } from \"./generateScopeFromSchema.js\";\nimport { generateVersionedTypesFromChain } from \"./generateVersionedTypesFromSchema.js\";\nimport { generateVersionedZodFromChain } from \"./generateVersionedZodFromSchema.js\";\nimport { generateVersionsFromChain } from \"./generateVersionsFromSchema.js\";\nimport type { ResolvedIrChain } from \"./resolveSchemaChain.js\";\n\n/**\n * Generate every versioned SDK output file from a resolved IR chain and write\n * them to `outputDir`.\n */\nexport async function writeAllSdkFiles(\n resolved: ResolvedIrChain,\n outputDir: string,\n minSupportedVersion: number | undefined,\n): Promise<void> {\n await fs.ensureDir(outputDir);\n\n // Versioned types\n consola.info(\"Generating versioned types...\");\n const types = generateVersionedTypesFromChain(resolved, minSupportedVersion);\n for (const [version, content] of types.readTypes) {\n const filePath = path.join(outputDir, `types_v${version}.ts`);\n await fs.writeFile(filePath, content, \"utf8\");\n consola.success(`Generated read types: ${filePath}`);\n }\n for (const [version, content] of types.writeTypes) {\n const filePath = path.join(outputDir, `writeTypes_v${version}.ts`);\n await fs.writeFile(filePath, content, \"utf8\");\n consola.success(`Generated write types: ${filePath}`);\n }\n const typesPath = path.join(outputDir, \"types.ts\");\n await fs.writeFile(typesPath, types.typesReExport, \"utf8\");\n consola.success(`Generated types re-export: ${typesPath}`);\n\n // Versioned Zod\n consola.info(\"Generating versioned Zod schemas...\");\n const zod = generateVersionedZodFromChain(resolved, minSupportedVersion);\n for (const [version, content] of zod.zodSchemas) {\n const filePath = path.join(outputDir, `schema_v${version}.ts`);\n await fs.writeFile(filePath, content, \"utf8\");\n consola.success(`Generated Zod schema: ${filePath}`);\n }\n const schemaPath = path.join(outputDir, \"schema.ts\");\n await fs.writeFile(schemaPath, zod.schemaReExport, \"utf8\");\n consola.success(`Generated schema re-export: ${schemaPath}`);\n\n // Internal\n consola.info(\"Generating internal types and upgrades...\");\n const internal = generateInternalFromChain(resolved);\n const internalDir = path.join(outputDir, \"_internal\");\n await fs.ensureDir(internalDir);\n await fs.writeFile(path.join(internalDir, \"types.ts\"), internal.internalTypes, \"utf8\");\n consola.success(`Generated internal types: ${path.join(internalDir, \"types.ts\")}`);\n await fs.writeFile(path.join(internalDir, \"upgrades.ts\"), internal.upgrades, \"utf8\");\n consola.success(`Generated upgrades: ${path.join(internalDir, \"upgrades.ts\")}`);\n await fs.writeFile(path.join(internalDir, \"schema.ts\"), internal.internalSchema, \"utf8\");\n consola.success(`Generated internal schema: ${path.join(internalDir, \"schema.ts\")}`);\n await fs.writeFile(path.join(internalDir, \"upgradeFns.ts\"), internal.internalUpgradeFns, \"utf8\");\n consola.success(`Generated upgrade functions: ${path.join(internalDir, \"upgradeFns.ts\")}`);\n\n // versions.ts\n consola.info(\"Generating version types...\");\n const versionsContent = generateVersionsFromChain(resolved, minSupportedVersion);\n const versionsPath = path.join(outputDir, \"versions.ts\");\n await fs.writeFile(versionsPath, versionsContent, \"utf8\");\n consola.success(`Generated versions: ${versionsPath}`);\n\n // index.ts\n consola.info(\"Generating index barrel export...\");\n const indexContent = generateIndexFromChain(resolved, minSupportedVersion);\n const indexPath = path.join(outputDir, \"index.ts\");\n await fs.writeFile(indexPath, indexContent, \"utf8\");\n consola.success(`Generated index: ${indexPath}`);\n\n // models.ts\n consola.info(\"Generating model metadata...\");\n const modelMetadata = generateModelMetadataFromChain(resolved, minSupportedVersion);\n const modelsPath = path.join(outputDir, \"models.ts\");\n await fs.writeFile(modelsPath, modelMetadata.modelsFile, \"utf8\");\n consola.success(`Generated models: ${modelsPath}`);\n\n // versionedDocRef.ts\n consola.info(\"Generating versioned document ref types...\");\n const versionedDocRefContent = generateScopeFromChain(resolved, minSupportedVersion);\n const versionedDocRefPath = path.join(outputDir, \"versionedDocRef.ts\");\n await fs.writeFile(versionedDocRefPath, versionedDocRefContent, \"utf8\");\n consola.success(`Generated versioned doc ref: ${versionedDocRefPath}`);\n}\n\nexport function parseMinVersion(minVersion: string | undefined): number | undefined {\n if (minVersion == null) return undefined;\n const parsed = parseInt(minVersion, 10);\n if (isNaN(parsed)) {\n throw new Error(`--min-version must be a valid integer, got: \"${minVersion}\"`);\n }\n return parsed;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,QAAQ,SAAS;AACjC,OAAOC,EAAE,MAAM,UAAU;AACzB,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,sBAAsB,QAAQ,8BAA8B;AACrE,SAASC,yBAAyB,QAAQ,iCAAiC;AAC3E,SAASC,8BAA8B,QAAQ,sCAAsC;AACrF,SAASC,sBAAsB,QAAQ,8BAA8B;AACrE,SAASC,+BAA+B,QAAQ,uCAAuC;AACvF,SAASC,6BAA6B,QAAQ,qCAAqC;AACnF,SAASC,yBAAyB,QAAQ,iCAAiC;AAG3E;AACA;AACA;AACA;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EACAxC,OAAO,CAACe,IAAI,CAAC,8BAA8B,CAAC;EAC5C,MAAM0B,aAAa,GAAGpC,8BAA8B,CAACM,QAAQ,EAAEE,mBAAmB,CAAC;EACnF,MAAM6B,UAAU,GAAGxC,IAAI,CAACmB,IAAI,CAACT,SAAS,EAAE,WAAW,CAAC;EACpD,MAAMX,EAAE,CAACqB,SAAS,CAACoB,UAAU,EAAED,aAAa,CAACE,UAAU,EAAE,MAAM,CAAC;EAChE3C,OAAO,CAACuB,OAAO,CAAC,qBAAqBmB,UAAU,EAAE,CAAC;;EAElD;EACA1C,OAAO,CAACe,IAAI,CAAC,4CAA4C,CAAC;EAC1D,MAAM6B,sBAAsB,GAAGtC,sBAAsB,CAACK,QAAQ,EAAEE,mBAAmB,CAAC;EACpF,MAAMgC,mBAAmB,GAAG3C,IAAI,CAACmB,IAAI,CAACT,SAAS,EAAE,oBAAoB,CAAC;EACtE,MAAMX,EAAE,CAACqB,SAAS,CAACuB,mBAAmB,EAAED,sBAAsB,EAAE,MAAM,CAAC;EACvE5C,OAAO,CAACuB,OAAO,CAAC,gCAAgCsB,mBAAmB,EAAE,CAAC;AACxE;AAEA,OAAO,SAASC,eAAeA,CAACC,UAA8B,EAAsB;EAClF,IAAIA,UAAU,IAAI,IAAI,EAAE,OAAOC,SAAS;EACxC,MAAMC,MAAM,GAAGC,QAAQ,CAACH,UAAU,EAAE,EAAE,CAAC;EACvC,IAAII,KAAK,CAACF,MAAM,CAAC,EAAE;IACjB,MAAM,IAAIG,KAAK,CAAC,gDAAgDL,UAAU,GAAG,CAAC;EAChF;EACA,OAAOE,MAAM;AACf","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"arrayFields.js","names":[],"sources":["arrayFields.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\n\nexport interface Container {\n readonly items: readonly string[];\n readonly numbers: readonly number[];\n}\n\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"arrayFields.js","names":[],"sources":["arrayFields.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */\n\n\nexport interface Container {\n readonly items: readonly string[];\n readonly numbers: readonly number[];\n}\n\n"],"mappings":"","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */
1
+ /* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */
2
2
 
3
3
  /**
4
4
  * A cat
@@ -1 +1 @@
1
- {"version":3,"file":"customDiscriminant.js","names":["isAnimalCat","value","kind","isAnimalDog"],"sources":["customDiscriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\n\n/**\n * A cat\n */\nexport interface Cat {\n readonly meow: string;\n readonly whiskers: number;\n}\n\n/**\n * A dog\n */\nexport interface Dog {\n readonly bark: string;\n readonly tailWags: number;\n}\n\nexport interface AnimalCat extends Cat {\n readonly kind: \"cat\";\n}\n\nexport interface AnimalDog extends Dog {\n readonly kind: \"dog\";\n}\n\nexport type Animal = AnimalCat | AnimalDog;\n\nexport function isAnimalCat(value: Animal): value is AnimalCat {\n return value.kind === \"cat\";\n}\n\nexport function isAnimalDog(value: Animal): value is AnimalDog {\n return value.kind === \"dog\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;AAgBA,OAAO,SAASA,WAAWA,CAACC,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B;AAEA,OAAO,SAASC,WAAWA,CAACF,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B","ignoreList":[]}
1
+ {"version":3,"file":"customDiscriminant.js","names":["isAnimalCat","value","kind","isAnimalDog"],"sources":["customDiscriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */\n\n\n/**\n * A cat\n */\nexport interface Cat {\n readonly meow: string;\n readonly whiskers: number;\n}\n\n/**\n * A dog\n */\nexport interface Dog {\n readonly bark: string;\n readonly tailWags: number;\n}\n\nexport interface AnimalCat extends Cat {\n readonly kind: \"cat\";\n}\n\nexport interface AnimalDog extends Dog {\n readonly kind: \"dog\";\n}\n\nexport type Animal = AnimalCat | AnimalDog;\n\nexport function isAnimalCat(value: Animal): value is AnimalCat {\n return value.kind === \"cat\";\n}\n\nexport function isAnimalDog(value: Animal): value is AnimalDog {\n return value.kind === \"dog\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;AAgBA,OAAO,SAASA,WAAWA,CAACC,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B;AAEA,OAAO,SAASC,WAAWA,CAACF,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */
1
+ /* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */
2
2
 
3
3
  /**
4
4
  * Represents an edge in a graph
@@ -1 +1 @@
1
- {"version":3,"file":"generateTypeScriptInterfaces.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["generateTypeScriptInterfaces.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\n\n/**\n * Represents an edge in a graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly label?: string;\n readonly color?: string;\n}\n\n/**\n * Represents a text box in a graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"text-box\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"text-box\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;;AAiBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,UAAU;AAClC","ignoreList":[]}
1
+ {"version":3,"file":"generateTypeScriptInterfaces.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["generateTypeScriptInterfaces.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */\n\n\n/**\n * Represents an edge in a graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly label?: string;\n readonly color?: string;\n}\n\n/**\n * Represents a text box in a graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"text-box\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"text-box\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;;AAiBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,UAAU;AAClC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\nimport type { DocumentRef, MediaRef, ObjectRef, UserRef } from \"@palantir/pack.document-schema.model-types\";\n\n/**\n * A record containing all reference types\n */\nexport interface Document {\n readonly id: string;\n readonly docRef: DocumentRef;\n readonly userRef: UserRef;\n readonly objectRef: ObjectRef;\n readonly mediaRef: MediaRef;\n readonly optionalDocRef?: DocumentRef;\n readonly docRefArray: readonly DocumentRef[];\n readonly userRefArray: readonly UserRef[];\n}\n\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */\n\nimport type { DocumentRef, MediaRef, ObjectRef, UserRef } from \"@palantir/pack.document-schema.model-types\";\n\n/**\n * A record containing all reference types\n */\nexport interface Document {\n readonly id: string;\n readonly docRef: DocumentRef;\n readonly userRef: UserRef;\n readonly objectRef: ObjectRef;\n readonly mediaRef: MediaRef;\n readonly optionalDocRef?: DocumentRef;\n readonly docRefArray: readonly DocumentRef[];\n readonly userRefArray: readonly UserRef[];\n}\n\n"],"mappings":"","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"simpleRecord.js","names":[],"sources":["simpleRecord.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\n\n/**\n * A person record\n */\nexport interface Person {\n readonly name: string;\n readonly age: number;\n readonly email?: string;\n}\n\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"simpleRecord.js","names":[],"sources":["simpleRecord.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */\n\n\n/**\n * A person record\n */\nexport interface Person {\n readonly name: string;\n readonly age: number;\n readonly email?: string;\n}\n\n"],"mappings":"","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */
1
+ /* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */
2
2
 
3
3
  /**
4
4
  * A node in the graph
@@ -1 +1 @@
1
- {"version":3,"file":"simpleSteps.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["simpleSteps.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\n\n/**\n * A node in the graph\n */\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly object: string;\n readonly label?: string;\n readonly edges: readonly Edge[];\n}\n\n/**\n * A text box in the graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\n/**\n * An edge in the graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"textBox\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"textBox\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AASA;AACA;AACA;;AAOA;AACA;AACA;;AAgBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,SAAS;AACjC","ignoreList":[]}
1
+ {"version":3,"file":"simpleSteps.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["simpleSteps.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.11.0 */\n\n\n/**\n * A node in the graph\n */\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly object: string;\n readonly label?: string;\n readonly edges: readonly Edge[];\n}\n\n/**\n * A text box in the graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\n/**\n * An edge in the graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"textBox\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"textBox\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AASA;AACA;AACA;;AAOA;AACA;AACA;;AAgBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,SAAS;AACjC","ignoreList":[]}
@@ -14,8 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import { defineRecord, defineUnion } from "@palantir/pack.schema";
18
+ import * as P from "@palantir/pack.schema";
17
19
  import { describe, expect, it } from "vitest";
18
- import { convertStepsToIr } from "../convertStepsToIr.js";
20
+ import { convertSchemaToIr, convertStepsToIr } from "../convertStepsToIr.js";
19
21
  import { parseMigrationSteps } from "../parseMigrationSteps.js";
20
22
  describe("convertStepsToIr", () => {
21
23
  it("should convert simple record types to IR format", () => {
@@ -358,4 +360,94 @@ describe("parseMigrationSteps generic type validation", () => {
358
360
  expect(() => parseMigrationSteps(stepsWithField(fieldType))).not.toThrow();
359
361
  });
360
362
  });
363
+ describe("convertSchemaToIr alias handling", () => {
364
+ it("preserves key = exportKey and name = declaredName for aliased records", () => {
365
+ const ir = convertSchemaToIr({
366
+ FooAlias: defineRecord("Foo", {
367
+ docs: "A foo",
368
+ fields: {
369
+ x: P.String
370
+ }
371
+ })
372
+ });
373
+ const model = ir.models["FooAlias"];
374
+ expect(model).toBeDefined();
375
+ expect(model.type).toBe("record");
376
+ if (model.type === "record") {
377
+ expect(model.record.key).toBe("FooAlias");
378
+ expect(model.record.name).toBe("Foo");
379
+ }
380
+ });
381
+ it("preserves key = exportKey and name = declaredName for aliased unions", () => {
382
+ const Circle = defineRecord("Circle", {
383
+ docs: "c",
384
+ fields: {
385
+ r: P.Double
386
+ }
387
+ });
388
+ const ir = convertSchemaToIr({
389
+ Circle,
390
+ ShapeAlias: defineUnion("Shape", {
391
+ docs: "A shape",
392
+ variants: {
393
+ circle: Circle
394
+ }
395
+ })
396
+ });
397
+ const model = ir.models["ShapeAlias"];
398
+ expect(model).toBeDefined();
399
+ expect(model.type).toBe("union");
400
+ if (model.type === "union") {
401
+ expect(model.union.key).toBe("ShapeAlias");
402
+ expect(model.union.name).toBe("Shape");
403
+ }
404
+ });
405
+ it("resolves field refs and union variants to export keys", () => {
406
+ const Inner = defineRecord("InnerModel", {
407
+ docs: "i",
408
+ fields: {
409
+ v: P.String
410
+ }
411
+ });
412
+ const ir = convertSchemaToIr({
413
+ InnerAlias: Inner,
414
+ Outer: defineRecord("Outer", {
415
+ docs: "o",
416
+ fields: {
417
+ nested: Inner
418
+ }
419
+ })
420
+ });
421
+
422
+ // The field ref should resolve to the export key "InnerAlias"
423
+ const outerModel = ir.models["Outer"];
424
+ expect(outerModel.type).toBe("record");
425
+ if (outerModel.type === "record") {
426
+ const nestedField = outerModel.record.fields.find(f => f.key === "nested");
427
+ expect(nestedField.fieldType.type).toBe("value");
428
+ if (nestedField.fieldType.type === "value") {
429
+ expect(nestedField.fieldType.value.type).toBe("modelRef");
430
+ if (nestedField.fieldType.value.type === "modelRef") {
431
+ expect(nestedField.fieldType.value.modelRef.modelTypes).toEqual(["InnerAlias"]);
432
+ }
433
+ }
434
+ }
435
+ });
436
+ it("throws on duplicate declared model names", () => {
437
+ expect(() => convertSchemaToIr({
438
+ AliasA: defineRecord("Foo", {
439
+ docs: "a",
440
+ fields: {
441
+ x: P.String
442
+ }
443
+ }),
444
+ AliasB: defineRecord("Foo", {
445
+ docs: "b",
446
+ fields: {
447
+ y: P.String
448
+ }
449
+ })
450
+ })).toThrow(/Duplicate declared model name "Foo"/);
451
+ });
452
+ });
361
453
  //# sourceMappingURL=convertStepsToIr.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"convertStepsToIr.test.js","names":["describe","expect","it","convertStepsToIr","parseMigrationSteps","schema","Person","docs","fields","name","age","email","toBe","description","version","primaryModelKeys","toEqual","Object","keys","models","toHaveLength","personModel","toBeDefined","type","Error","personRecord","record","key","nameField","find","f","isOptional","toBeUndefined","fieldType","value","string","ageField","double","emailField","Container","tags","numbers","containerModel","containerRecord","tagsField","array","allowNullValue","numbersField","Address","street","city","address","addressField","modelRef","modelTypes","position","x","y","ObjectNode","extends","label","objectNodeModel","objectNode","xField","yField","labelField","TextBox","text","Node","variants","object","textBox","Graph","nodes","graphModel","graphRecord","nodesField","Tag","labels","labelsField","stepsWithField","Foo","bar","each","toThrow","not"],"sources":["convertStepsToIr.test.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 { describe, expect, it } from \"vitest\";\nimport type { IFieldTypeUnion } from \"../../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { convertStepsToIr } from \"../convertStepsToIr.js\";\nimport type { MigrationStep } from \"../parseMigrationSteps.js\";\nimport { parseMigrationSteps } from \"../parseMigrationSteps.js\";\n\ndescribe(\"convertStepsToIr\", () => {\n it(\"should convert simple record types to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Person: {\n docs: \"A person record\",\n fields: {\n name: \"string\",\n age: \"double\",\n email: \"optional<string>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n\n expect(schema.name).toBe(\"Generated Schema\");\n expect(schema.description).toBe(\"Schema generated from migration steps\");\n expect(schema.version).toBe(1);\n expect(schema.primaryModelKeys).toEqual([\"Person\"]);\n expect(Object.keys(schema.models)).toHaveLength(1);\n\n const personModel = schema.models[\"Person\"];\n expect(personModel).toBeDefined();\n expect(personModel?.type).toBe(\"record\");\n if (personModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const personRecord = personModel.record;\n\n expect(personRecord.key).toBe(\"Person\");\n expect(personRecord.name).toBe(\"Person\");\n expect(personRecord.description).toBe(\"A person record\");\n expect(personRecord.fields).toHaveLength(3);\n\n // Check name field\n const nameField = personRecord.fields.find(f => f.key === \"name\");\n expect(nameField).toBeDefined();\n expect(nameField?.isOptional).toBeUndefined();\n expect(nameField?.fieldType).toEqual({\n type: \"value\",\n value: {\n type: \"string\",\n string: {},\n },\n });\n\n // Check age field\n const ageField = personRecord.fields.find(f => f.key === \"age\");\n expect(ageField).toBeDefined();\n expect(ageField?.fieldType).toEqual({\n type: \"value\",\n value: {\n type: \"double\",\n double: {},\n },\n });\n\n // Check optional email field\n const emailField = personRecord.fields.find(f => f.key === \"email\");\n expect(emailField).toBeDefined();\n expect(emailField?.isOptional).toBe(true);\n expect(emailField?.fieldType).toEqual({\n type: \"value\",\n value: {\n type: \"string\",\n string: {},\n },\n });\n });\n\n it(\"should convert array and list types to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Container: {\n docs: \"A container with collections\",\n fields: {\n tags: \"array<string>\",\n numbers: \"list<double>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const containerModel = schema.models[\"Container\"];\n expect(containerModel).toBeDefined();\n expect(containerModel?.type).toBe(\"record\");\n if (containerModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const containerRecord = containerModel.record;\n\n // Check tags array field\n const tagsField = containerRecord.fields.find(f => f.key === \"tags\");\n expect(tagsField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"string\",\n string: {},\n },\n },\n });\n\n // Check numbers list field (treated as array)\n const numbersField = containerRecord.fields.find(f => f.key === \"numbers\");\n expect(numbersField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"double\",\n double: {},\n },\n },\n });\n });\n\n it(\"should convert record references to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Address: {\n fields: {\n street: \"string\",\n city: \"string\",\n },\n },\n Person: {\n fields: {\n name: \"string\",\n address: \"Address\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const personModel = schema.models[\"Person\"];\n expect(personModel).toBeDefined();\n expect(personModel?.type).toBe(\"record\");\n if (personModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const personRecord = personModel.record;\n\n const addressField = personRecord.fields.find(f => f.key === \"address\");\n expect(addressField?.fieldType).toEqual(\n {\n type: \"value\",\n value: {\n type: \"modelRef\",\n modelRef: {\n modelTypes: [\"Address\"],\n },\n },\n } satisfies IFieldTypeUnion,\n );\n });\n\n it(\"should handle local fragments and extends\", () => {\n const steps: MigrationStep[] = [\n {\n \"local-fragment\": {\n position: {\n x: \"double\",\n y: \"double\",\n },\n },\n },\n {\n \"add-records\": {\n ObjectNode: {\n docs: \"A node with position\",\n extends: [\"position\"],\n fields: {\n label: \"string\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const objectNodeModel = schema.models[\"ObjectNode\"];\n expect(objectNodeModel).toBeDefined();\n expect(objectNodeModel?.type).toBe(\"record\");\n if (objectNodeModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const objectNode = objectNodeModel.record;\n\n expect(objectNode.fields).toHaveLength(3);\n\n // Check inherited fields from fragment\n const xField = objectNode.fields.find(f => f.key === \"x\");\n expect(xField).toBeDefined();\n expect(xField?.fieldType).toEqual({\n type: \"value\",\n value: {\n type: \"double\",\n double: {},\n },\n });\n\n const yField = objectNode.fields.find(f => f.key === \"y\");\n expect(yField).toBeDefined();\n\n // Check own field\n const labelField = objectNode.fields.find(f => f.key === \"label\");\n expect(labelField).toBeDefined();\n });\n\n it(\"should convert unions to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n ObjectNode: {\n fields: {\n label: \"string\",\n },\n },\n TextBox: {\n fields: {\n text: \"string\",\n },\n },\n },\n },\n {\n \"add-union\": {\n Node: {\n variants: {\n object: \"ObjectNode\",\n textBox: \"TextBox\",\n },\n },\n },\n },\n {\n \"add-records\": {\n Graph: {\n fields: {\n nodes: \"array<Node>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const graphModel = schema.models[\"Graph\"];\n if (graphModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const graphRecord = graphModel.record;\n\n const nodesField = graphRecord.fields.find(f => f.key === \"nodes\");\n expect(nodesField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"modelRef\",\n modelRef: {\n modelTypes: [\"Node\"],\n },\n },\n },\n });\n });\n\n it(\"should convert optional array types to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Tag: {\n fields: {\n name: \"string\",\n },\n },\n Container: {\n docs: \"A container with optional collections\",\n fields: {\n tags: \"optional<array<Tag>>\",\n labels: \"optional<array<string>>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const containerModel = schema.models[\"Container\"];\n expect(containerModel).toBeDefined();\n expect(containerModel?.type).toBe(\"record\");\n if (containerModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const containerRecord = containerModel.record;\n\n // Check optional array of references\n const tagsField = containerRecord.fields.find(f => f.key === \"tags\");\n expect(tagsField?.isOptional).toBe(true);\n expect(tagsField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"modelRef\",\n modelRef: {\n modelTypes: [\"Tag\"],\n },\n },\n },\n });\n\n // Check optional array of primitives\n const labelsField = containerRecord.fields.find(f => f.key === \"labels\");\n expect(labelsField?.isOptional).toBe(true);\n expect(labelsField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"string\",\n string: {},\n },\n },\n });\n });\n\n it(\"should handle modify-records step\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Person: {\n fields: {\n name: \"string\",\n },\n },\n },\n },\n {\n \"modify-records\": {\n Person: {\n \"add-fields\": {\n age: \"double\",\n email: \"optional<string>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const personModel = schema.models[\"Person\"];\n expect(personModel).toBeDefined();\n expect(personModel?.type).toBe(\"record\");\n if (personModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const personRecord = personModel.record;\n\n expect(personRecord.fields).toHaveLength(3);\n\n // Original field\n expect(personRecord.fields.find(f => f.key === \"name\")).toBeDefined();\n\n // Added fields\n expect(personRecord.fields.find(f => f.key === \"age\")).toBeDefined();\n\n const emailField = personRecord.fields.find(f => f.key === \"email\");\n expect(emailField).toBeDefined();\n expect(emailField?.isOptional).toBe(true);\n });\n});\n\ndescribe(\"parseMigrationSteps generic type validation\", () => {\n function stepsWithField(fieldType: string): unknown {\n return [{ \"add-records\": { Foo: { fields: { bar: fieldType } } } }];\n }\n\n it.each([\n \"optional<optional<string>>\",\n \"array<array<string>>\",\n \"list<list<double>>\",\n \"array<optional<string>>\",\n \"optional<array<array<string>>>\",\n \"optional<foo<string>>\",\n \"foo<string>\",\n ])(\"should reject invalid nested generic type: %s\", fieldType => {\n expect(() => parseMigrationSteps(stepsWithField(fieldType))).toThrow();\n });\n\n it.each([\n \"optional<string>\",\n \"optional<double>\",\n \"optional<MyType>\",\n \"array<string>\",\n \"list<double>\",\n \"set<MyType>\",\n \"map<string>\",\n \"optional<array<string>>\",\n \"optional<list<Tag>>\",\n \"optional<set<double>>\",\n \"optional<map<string>>\",\n ])(\"should accept valid generic type: %s\", fieldType => {\n expect(() => parseMigrationSteps(stepsWithField(fieldType))).not.toThrow();\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAE7C,SAASC,gBAAgB,QAAQ,wBAAwB;AAEzD,SAASC,mBAAmB,QAAQ,2BAA2B;AAE/DJ,QAAQ,CAAC,kBAAkB,EAAE,MAAM;EACjCE,EAAE,CAAC,iDAAiD,EAAE,MAAM;IAgB1D,MAAMG,MAAM,GAAGF,gBAAgB,CAfA,CAC7B;MACE,aAAa,EAAE;QACbG,MAAM,EAAE;UACNC,IAAI,EAAE,iBAAiB;UACvBC,MAAM,EAAE;YACNC,IAAI,EAAE,QAAQ;YACdC,GAAG,EAAE,QAAQ;YACbC,KAAK,EAAE;UACT;QACF;MACF;IACF,CAAC,CAGkC,CAAC;IAEtCV,MAAM,CAACI,MAAM,CAACI,IAAI,CAAC,CAACG,IAAI,CAAC,kBAAkB,CAAC;IAC5CX,MAAM,CAACI,MAAM,CAACQ,WAAW,CAAC,CAACD,IAAI,CAAC,uCAAuC,CAAC;IACxEX,MAAM,CAACI,MAAM,CAACS,OAAO,CAAC,CAACF,IAAI,CAAC,CAAC,CAAC;IAC9BX,MAAM,CAACI,MAAM,CAACU,gBAAgB,CAAC,CAACC,OAAO,CAAC,CAAC,QAAQ,CAAC,CAAC;IACnDf,MAAM,CAACgB,MAAM,CAACC,IAAI,CAACb,MAAM,CAACc,MAAM,CAAC,CAAC,CAACC,YAAY,CAAC,CAAC,CAAC;IAElD,MAAMC,WAAW,GAAGhB,MAAM,CAACc,MAAM,CAAC,QAAQ,CAAC;IAC3ClB,MAAM,CAACoB,WAAW,CAAC,CAACC,WAAW,CAAC,C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;QAAEgD,GAAG,EAAE;UAAEzE,MAAM,EAAE;YAAE0E,GAAG,EAAEjD;UAAU;QAAE;MAAE;IAAE,CAAC,CAAC;EACrE;EAEA/B,EAAE,CAACiF,IAAI,CAAC,CACN,4BAA4B,EAC5B,sBAAsB,EACtB,oBAAoB,EACpB,yBAAyB,EACzB,gCAAgC,EAChC,uBAAuB,EACvB,aAAa,CACd,CAAC,CAAC,+CAA+C,EAAElD,SAAS,IAAI;IAC/DhC,MAAM,CAAC,MAAMG,mBAAmB,CAAC4E,cAAc,CAAC/C,SAAS,CAAC,CAAC,CAAC,CAACmD,OAAO,CAAC,CAAC;EACxE,CAAC,CAAC;EAEFlF,EAAE,CAACiF,IAAI,CAAC,CACN,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,aAAa,EACb,aAAa,EACb,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,CACxB,CAAC,CAAC,sCAAsC,EAAElD,SAAS,IAAI;IACtDhC,MAAM,CAAC,MAAMG,mBAAmB,CAAC4E,cAAc,CAAC/C,SAAS,CAAC,CAAC,CAAC,CAACoD,GAAG,CAACD,OAAO,CAAC,CAAC;EAC5E,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"convertStepsToIr.test.js","names":["defineRecord","defineUnion","P","describe","expect","it","convertSchemaToIr","convertStepsToIr","parseMigrationSteps","schema","Person","docs","fields","name","age","email","toBe","description","version","primaryModelKeys","toEqual","Object","keys","models","toHaveLength","personModel","toBeDefined","type","Error","personRecord","record","key","nameField","find","f","isOptional","toBeUndefined","fieldType","value","string","ageField","double","emailField","Container","tags","numbers","containerModel","containerRecord","tagsField","array","allowNullValue","numbersField","Address","street","city","address","addressField","modelRef","modelTypes","position","x","y","ObjectNode","extends","label","objectNodeModel","objectNode","xField","yField","labelField","TextBox","text","Node","variants","object","textBox","Graph","nodes","graphModel","graphRecord","nodesField","Tag","labels","labelsField","stepsWithField","Foo","bar","each","toThrow","not","ir","FooAlias","String","model","Circle","r","Double","ShapeAlias","circle","union","Inner","v","InnerAlias","Outer","nested","outerModel","nestedField","AliasA","AliasB"],"sources":["convertStepsToIr.test.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 { defineRecord, defineUnion } from \"@palantir/pack.schema\";\nimport * as P from \"@palantir/pack.schema\";\nimport { describe, expect, it } from \"vitest\";\nimport type { IFieldTypeUnion } from \"../../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { convertSchemaToIr, convertStepsToIr } from \"../convertStepsToIr.js\";\nimport type { MigrationStep } from \"../parseMigrationSteps.js\";\nimport { parseMigrationSteps } from \"../parseMigrationSteps.js\";\n\ndescribe(\"convertStepsToIr\", () => {\n it(\"should convert simple record types to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Person: {\n docs: \"A person record\",\n fields: {\n name: \"string\",\n age: \"double\",\n email: \"optional<string>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n\n expect(schema.name).toBe(\"Generated Schema\");\n expect(schema.description).toBe(\"Schema generated from migration steps\");\n expect(schema.version).toBe(1);\n expect(schema.primaryModelKeys).toEqual([\"Person\"]);\n expect(Object.keys(schema.models)).toHaveLength(1);\n\n const personModel = schema.models[\"Person\"];\n expect(personModel).toBeDefined();\n expect(personModel?.type).toBe(\"record\");\n if (personModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const personRecord = personModel.record;\n\n expect(personRecord.key).toBe(\"Person\");\n expect(personRecord.name).toBe(\"Person\");\n expect(personRecord.description).toBe(\"A person record\");\n expect(personRecord.fields).toHaveLength(3);\n\n // Check name field\n const nameField = personRecord.fields.find(f => f.key === \"name\");\n expect(nameField).toBeDefined();\n expect(nameField?.isOptional).toBeUndefined();\n expect(nameField?.fieldType).toEqual({\n type: \"value\",\n value: {\n type: \"string\",\n string: {},\n },\n });\n\n // Check age field\n const ageField = personRecord.fields.find(f => f.key === \"age\");\n expect(ageField).toBeDefined();\n expect(ageField?.fieldType).toEqual({\n type: \"value\",\n value: {\n type: \"double\",\n double: {},\n },\n });\n\n // Check optional email field\n const emailField = personRecord.fields.find(f => f.key === \"email\");\n expect(emailField).toBeDefined();\n expect(emailField?.isOptional).toBe(true);\n expect(emailField?.fieldType).toEqual({\n type: \"value\",\n value: {\n type: \"string\",\n string: {},\n },\n });\n });\n\n it(\"should convert array and list types to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Container: {\n docs: \"A container with collections\",\n fields: {\n tags: \"array<string>\",\n numbers: \"list<double>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const containerModel = schema.models[\"Container\"];\n expect(containerModel).toBeDefined();\n expect(containerModel?.type).toBe(\"record\");\n if (containerModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const containerRecord = containerModel.record;\n\n // Check tags array field\n const tagsField = containerRecord.fields.find(f => f.key === \"tags\");\n expect(tagsField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"string\",\n string: {},\n },\n },\n });\n\n // Check numbers list field (treated as array)\n const numbersField = containerRecord.fields.find(f => f.key === \"numbers\");\n expect(numbersField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"double\",\n double: {},\n },\n },\n });\n });\n\n it(\"should convert record references to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Address: {\n fields: {\n street: \"string\",\n city: \"string\",\n },\n },\n Person: {\n fields: {\n name: \"string\",\n address: \"Address\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const personModel = schema.models[\"Person\"];\n expect(personModel).toBeDefined();\n expect(personModel?.type).toBe(\"record\");\n if (personModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const personRecord = personModel.record;\n\n const addressField = personRecord.fields.find(f => f.key === \"address\");\n expect(addressField?.fieldType).toEqual(\n {\n type: \"value\",\n value: {\n type: \"modelRef\",\n modelRef: {\n modelTypes: [\"Address\"],\n },\n },\n } satisfies IFieldTypeUnion,\n );\n });\n\n it(\"should handle local fragments and extends\", () => {\n const steps: MigrationStep[] = [\n {\n \"local-fragment\": {\n position: {\n x: \"double\",\n y: \"double\",\n },\n },\n },\n {\n \"add-records\": {\n ObjectNode: {\n docs: \"A node with position\",\n extends: [\"position\"],\n fields: {\n label: \"string\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const objectNodeModel = schema.models[\"ObjectNode\"];\n expect(objectNodeModel).toBeDefined();\n expect(objectNodeModel?.type).toBe(\"record\");\n if (objectNodeModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const objectNode = objectNodeModel.record;\n\n expect(objectNode.fields).toHaveLength(3);\n\n // Check inherited fields from fragment\n const xField = objectNode.fields.find(f => f.key === \"x\");\n expect(xField).toBeDefined();\n expect(xField?.fieldType).toEqual({\n type: \"value\",\n value: {\n type: \"double\",\n double: {},\n },\n });\n\n const yField = objectNode.fields.find(f => f.key === \"y\");\n expect(yField).toBeDefined();\n\n // Check own field\n const labelField = objectNode.fields.find(f => f.key === \"label\");\n expect(labelField).toBeDefined();\n });\n\n it(\"should convert unions to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n ObjectNode: {\n fields: {\n label: \"string\",\n },\n },\n TextBox: {\n fields: {\n text: \"string\",\n },\n },\n },\n },\n {\n \"add-union\": {\n Node: {\n variants: {\n object: \"ObjectNode\",\n textBox: \"TextBox\",\n },\n },\n },\n },\n {\n \"add-records\": {\n Graph: {\n fields: {\n nodes: \"array<Node>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const graphModel = schema.models[\"Graph\"];\n if (graphModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const graphRecord = graphModel.record;\n\n const nodesField = graphRecord.fields.find(f => f.key === \"nodes\");\n expect(nodesField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"modelRef\",\n modelRef: {\n modelTypes: [\"Node\"],\n },\n },\n },\n });\n });\n\n it(\"should convert optional array types to IR format\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Tag: {\n fields: {\n name: \"string\",\n },\n },\n Container: {\n docs: \"A container with optional collections\",\n fields: {\n tags: \"optional<array<Tag>>\",\n labels: \"optional<array<string>>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const containerModel = schema.models[\"Container\"];\n expect(containerModel).toBeDefined();\n expect(containerModel?.type).toBe(\"record\");\n if (containerModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const containerRecord = containerModel.record;\n\n // Check optional array of references\n const tagsField = containerRecord.fields.find(f => f.key === \"tags\");\n expect(tagsField?.isOptional).toBe(true);\n expect(tagsField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"modelRef\",\n modelRef: {\n modelTypes: [\"Tag\"],\n },\n },\n },\n });\n\n // Check optional array of primitives\n const labelsField = containerRecord.fields.find(f => f.key === \"labels\");\n expect(labelsField?.isOptional).toBe(true);\n expect(labelsField?.fieldType).toEqual({\n type: \"array\",\n array: {\n allowNullValue: false,\n value: {\n type: \"string\",\n string: {},\n },\n },\n });\n });\n\n it(\"should handle modify-records step\", () => {\n const steps: MigrationStep[] = [\n {\n \"add-records\": {\n Person: {\n fields: {\n name: \"string\",\n },\n },\n },\n },\n {\n \"modify-records\": {\n Person: {\n \"add-fields\": {\n age: \"double\",\n email: \"optional<string>\",\n },\n },\n },\n },\n ];\n\n const schema = convertStepsToIr(steps);\n const personModel = schema.models[\"Person\"];\n expect(personModel).toBeDefined();\n expect(personModel?.type).toBe(\"record\");\n if (personModel?.type !== \"record\") throw new Error(\"Expected record type\");\n const personRecord = personModel.record;\n\n expect(personRecord.fields).toHaveLength(3);\n\n // Original field\n expect(personRecord.fields.find(f => f.key === \"name\")).toBeDefined();\n\n // Added fields\n expect(personRecord.fields.find(f => f.key === \"age\")).toBeDefined();\n\n const emailField = personRecord.fields.find(f => f.key === \"email\");\n expect(emailField).toBeDefined();\n expect(emailField?.isOptional).toBe(true);\n });\n});\n\ndescribe(\"parseMigrationSteps generic type validation\", () => {\n function stepsWithField(fieldType: string): unknown {\n return [{ \"add-records\": { Foo: { fields: { bar: fieldType } } } }];\n }\n\n it.each([\n \"optional<optional<string>>\",\n \"array<array<string>>\",\n \"list<list<double>>\",\n \"array<optional<string>>\",\n \"optional<array<array<string>>>\",\n \"optional<foo<string>>\",\n \"foo<string>\",\n ])(\"should reject invalid nested generic type: %s\", fieldType => {\n expect(() => parseMigrationSteps(stepsWithField(fieldType))).toThrow();\n });\n\n it.each([\n \"optional<string>\",\n \"optional<double>\",\n \"optional<MyType>\",\n \"array<string>\",\n \"list<double>\",\n \"set<MyType>\",\n \"map<string>\",\n \"optional<array<string>>\",\n \"optional<list<Tag>>\",\n \"optional<set<double>>\",\n \"optional<map<string>>\",\n ])(\"should accept valid generic type: %s\", fieldType => {\n expect(() => parseMigrationSteps(stepsWithField(fieldType))).not.toThrow();\n });\n});\n\ndescribe(\"convertSchemaToIr alias handling\", () => {\n it(\"preserves key = exportKey and name = declaredName for aliased records\", () => {\n const ir = convertSchemaToIr({\n FooAlias: defineRecord(\"Foo\", { docs: \"A foo\", fields: { x: P.String } }),\n });\n\n const model = ir.models[\"FooAlias\"];\n expect(model).toBeDefined();\n expect(model!.type).toBe(\"record\");\n if (model!.type === \"record\") {\n expect(model!.record.key).toBe(\"FooAlias\");\n expect(model!.record.name).toBe(\"Foo\");\n }\n });\n\n it(\"preserves key = exportKey and name = declaredName for aliased unions\", () => {\n const Circle = defineRecord(\"Circle\", { docs: \"c\", fields: { r: P.Double } });\n const ir = convertSchemaToIr({\n Circle,\n ShapeAlias: defineUnion(\"Shape\", {\n docs: \"A shape\",\n variants: { circle: Circle },\n }),\n });\n\n const model = ir.models[\"ShapeAlias\"];\n expect(model).toBeDefined();\n expect(model!.type).toBe(\"union\");\n if (model!.type === \"union\") {\n expect(model!.union.key).toBe(\"ShapeAlias\");\n expect(model!.union.name).toBe(\"Shape\");\n }\n });\n\n it(\"resolves field refs and union variants to export keys\", () => {\n const Inner = defineRecord(\"InnerModel\", { docs: \"i\", fields: { v: P.String } });\n const ir = convertSchemaToIr({\n InnerAlias: Inner,\n Outer: defineRecord(\"Outer\", {\n docs: \"o\",\n fields: { nested: Inner },\n }),\n });\n\n // The field ref should resolve to the export key \"InnerAlias\"\n const outerModel = ir.models[\"Outer\"]!;\n expect(outerModel.type).toBe(\"record\");\n if (outerModel.type === \"record\") {\n const nestedField = outerModel.record.fields.find((f: { key: string }) =>\n f.key === \"nested\"\n )!;\n expect(nestedField.fieldType.type).toBe(\"value\");\n if (nestedField.fieldType.type === \"value\") {\n expect(nestedField.fieldType.value.type).toBe(\"modelRef\");\n if (nestedField.fieldType.value.type === \"modelRef\") {\n expect(nestedField.fieldType.value.modelRef.modelTypes).toEqual([\"InnerAlias\"]);\n }\n }\n }\n });\n\n it(\"throws on duplicate declared model names\", () => {\n expect(() =>\n convertSchemaToIr({\n AliasA: defineRecord(\"Foo\", { docs: \"a\", fields: { x: P.String } }),\n AliasB: defineRecord(\"Foo\", { docs: \"b\", fields: { y: P.String } }),\n })\n ).toThrow(/Duplicate declared model name \"Foo\"/);\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,EAAEC,WAAW,QAAQ,uBAAuB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C,CAAC0F;QAAO;MAAE,CAAC,CAAC;MACnEgB,MAAM,EAAE5G,YAAY,CAAC,KAAK,EAAE;QAAEW,IAAI,EAAE,GAAG;QAAEC,MAAM,EAAE;UAAEiD,CAAC,EAAE3D,CAAC,CAAC0F;QAAO;MAAE,CAAC;IACpE,CAAC,CACH,CAAC,CAACJ,OAAO,CAAC,qCAAqC,CAAC;EAClD,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -38,11 +38,19 @@ export function convertStepsToIr(steps, metadata) {
38
38
  * Converts record and union definitions to Palantir IR format
39
39
  */
40
40
  export function convertSchemaToIr(inputSchema, metadata) {
41
+ // Build a mapping from declared model name → export key so that union variant
42
+ // refs (which use declared model names) can be remapped to export keys.
43
+ const nameToExportKey = new Map();
44
+ for (const [exportKey, modelDef] of Object.entries(inputSchema)) {
45
+ const existing = nameToExportKey.get(modelDef.name);
46
+ !(existing == null) ? process.env.NODE_ENV !== "production" ? invariant(false, `Duplicate declared model name "${modelDef.name}": exported as both "${existing}" and "${exportKey}"`) : invariant(false) : void 0;
47
+ nameToExportKey.set(modelDef.name, exportKey);
48
+ }
41
49
  const primaryModelKeys = [];
42
50
  const models = new Map();
43
- for (const modelDef of Object.values(inputSchema)) {
44
- if (collectModels(modelDef, models)) {
45
- primaryModelKeys.push(modelDef.name);
51
+ for (const [exportKey, modelDef] of Object.entries(inputSchema)) {
52
+ if (collectModels(exportKey, modelDef, nameToExportKey, models)) {
53
+ primaryModelKeys.push(exportKey);
46
54
  }
47
55
  }
48
56
  return {
@@ -53,45 +61,47 @@ export function convertSchemaToIr(inputSchema, metadata) {
53
61
  models: Object.fromEntries(models)
54
62
  };
55
63
  }
56
- function collectModels(modelDef, outModels) {
57
- !!outModels.has(modelDef.name) ? process.env.NODE_ENV !== "production" ? invariant(false, `Duplicate model definition: ${modelDef.name}`) : invariant(false) : void 0;
64
+ function collectModels(exportKey, modelDef, nameToExportKey, outModels) {
65
+ !!outModels.has(exportKey) ? process.env.NODE_ENV !== "production" ? invariant(false, `Duplicate model definition: ${exportKey}`) : invariant(false) : void 0;
58
66
  switch (modelDef.type) {
59
67
  case "record":
60
68
  {
61
- outModels.set(modelDef.name, IModelDef.record(convertRecordDefToIr(modelDef)));
69
+ outModels.set(exportKey, IModelDef.record(convertRecordDefToIr(modelDef, exportKey, nameToExportKey)));
62
70
  return true;
63
71
  }
64
72
  case "union":
65
73
  {
66
- outModels.set(modelDef.name, IModelDef.union(convertUnionDefToIr(modelDef)));
74
+ outModels.set(exportKey, IModelDef.union(convertUnionDefToIr(modelDef, exportKey, nameToExportKey)));
67
75
  return true;
68
76
  }
69
77
  default:
70
78
  assertNever(modelDef);
71
79
  }
72
80
  }
73
- export function convertRecordDefToIr(recordDef) {
81
+ export function convertRecordDefToIr(recordDef, exportKey, nameToExportKey) {
82
+ const key = exportKey ?? recordDef.name;
74
83
  const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]) => ({
75
84
  key: fieldKey,
76
85
  name: fieldKey,
77
86
  description: undefined,
78
- fieldType: convertTypeToFieldTypeUnion(fieldType),
87
+ fieldType: convertTypeToFieldTypeUnion(fieldType, nameToExportKey),
79
88
  metadata: {
80
89
  addedInVersion: 1
81
90
  },
82
91
  isOptional: fieldType.type === "optional" ? true : undefined
83
92
  }));
84
93
  return {
85
- key: recordDef.name,
94
+ key,
86
95
  name: recordDef.name,
87
96
  description: recordDef.docs ?? undefined,
88
97
  fields
89
98
  };
90
99
  }
91
- export function convertUnionDefToIr(unionDef) {
92
- const variantEntries = Object.entries(unionDef.variants).map(([variantName, modelRef]) => [variantName, modelRef.name]);
100
+ export function convertUnionDefToIr(unionDef, exportKey, nameToExportKey) {
101
+ const key = exportKey ?? unionDef.name;
102
+ const variantEntries = Object.entries(unionDef.variants).map(([variantName, modelRef]) => [variantName, nameToExportKey?.get(modelRef.name) ?? modelRef.name]);
93
103
  return {
94
- key: unionDef.name,
104
+ key,
95
105
  name: unionDef.name,
96
106
  description: unionDef.docs,
97
107
  discriminant: unionDef.discriminant,
@@ -103,23 +113,22 @@ export function convertUnionDefToIr(unionDef) {
103
113
  }
104
114
 
105
115
  // TODO: rename to convertSchemaTypeToFieldTypeUnion
106
- export function convertTypeToFieldTypeUnion(schemaType) {
116
+ export function convertTypeToFieldTypeUnion(schemaType, nameToExportKey) {
107
117
  switch (schemaType.type) {
108
118
  case "array":
109
119
  {
120
+ // P.Array.items is typed as TypeBase due to the generic; narrow via type field
121
+ const items = schemaType.items;
122
+ const allowNullValue = items.type === "optional";
123
+ const elementType = allowNullValue ? items.item : items;
110
124
  return IFieldTypeUnion.array({
111
- allowNullValue: false,
112
- value: convertTypeToFieldValueUnion(schemaType.items)
125
+ allowNullValue,
126
+ value: convertTypeToFieldValueUnion(elementType, nameToExportKey)
113
127
  });
114
128
  }
115
- // TODO: have map/set types in document-schema-api
116
-
117
129
  case "optional":
118
- {
119
- // Optional flag is handled at field level, but we need to unwrap the inner type
120
-
121
- return convertTypeToFieldTypeUnion(schemaType.item);
122
- }
130
+ // Optional flag is handled at field level; unwrap and recurse on inner type
131
+ return convertTypeToFieldTypeUnion(schemaType.item, nameToExportKey);
123
132
  case "boolean":
124
133
  case "docRef":
125
134
  case "double":
@@ -129,16 +138,15 @@ export function convertTypeToFieldTypeUnion(schemaType) {
129
138
  case "string":
130
139
  case "unknown":
131
140
  case "userRef":
132
- return IFieldTypeUnion.value(convertTypeToFieldValueUnion(schemaType));
141
+ return IFieldTypeUnion.value(convertTypeToFieldValueUnion(schemaType, nameToExportKey));
133
142
  default:
134
143
  assertNever(schemaType);
135
144
  }
136
145
  }
137
- function convertTypeToFieldValueUnion(schemaType) {
146
+ function convertTypeToFieldValueUnion(schemaType, nameToExportKey) {
138
147
  switch (schemaType.type) {
139
148
  case "array":
140
- // TODO: fix the argument types so these aren't possible
141
- process.env.NODE_ENV !== "production" ? invariant(false, `Collection type passed to convertTypeToFieldValueUnion: ${schemaType.type}`) : invariant(false);
149
+ throw new Error("Nested arrays are not supported in the IR. " + "Wrap the inner array in a record instead.");
142
150
  case "boolean":
143
151
  return IFieldValueUnion.boolean({});
144
152
  case "docRef":
@@ -156,16 +164,16 @@ function convertTypeToFieldValueUnion(schemaType) {
156
164
  objectTypeRids: []
157
165
  });
158
166
  case "optional":
167
+ // Nested optional — unwrap and continue
168
+ // TODO: probably warn? maybe throw
169
+ return convertTypeToFieldValueUnion(schemaType.item, nameToExportKey);
170
+ case "ref":
159
171
  {
160
- // If we get here, it means we have nested optionals - unwrap and continue
161
- // TODO: probably warn? maybe throw
162
-
163
- return convertTypeToFieldValueUnion(schemaType.item);
172
+ const modelKey = nameToExportKey?.get(schemaType.name) ?? schemaType.name;
173
+ return IFieldValueUnion.modelRef({
174
+ modelTypes: [modelKey]
175
+ });
164
176
  }
165
- case "ref":
166
- return IFieldValueUnion.modelRef({
167
- modelTypes: [schemaType.name]
168
- });
169
177
  case "string":
170
178
  return IFieldValueUnion.string({});
171
179
  case "unknown":