@palantir/pack.document-schema.type-gen 0.0.1-beta.1

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 (166) hide show
  1. package/LICENSE.txt +13 -0
  2. package/README.md +237 -0
  3. package/bin/cli.ts +6 -0
  4. package/build/esm/cli.js +29 -0
  5. package/build/esm/cli.js.map +1 -0
  6. package/build/esm/commands/ir/irDeployHandler.js +45 -0
  7. package/build/esm/commands/ir/irDeployHandler.js.map +1 -0
  8. package/build/esm/commands/ir/irGenModelsHandler.js +44 -0
  9. package/build/esm/commands/ir/irGenModelsHandler.js.map +1 -0
  10. package/build/esm/commands/ir/irGenZodHandler.js +43 -0
  11. package/build/esm/commands/ir/irGenZodHandler.js.map +1 -0
  12. package/build/esm/commands/ir/registerIrCommands.js +26 -0
  13. package/build/esm/commands/ir/registerIrCommands.js.map +1 -0
  14. package/build/esm/commands/schema/__tests__/schemaToYaml.integration.test.js +102 -0
  15. package/build/esm/commands/schema/__tests__/schemaToYaml.integration.test.js.map +1 -0
  16. package/build/esm/commands/schema/registerSchemaCommands.js +22 -0
  17. package/build/esm/commands/schema/registerSchemaCommands.js.map +1 -0
  18. package/build/esm/commands/schema/schemaToYamlHandler.js +55 -0
  19. package/build/esm/commands/schema/schemaToYamlHandler.js.map +1 -0
  20. package/build/esm/commands/steps/registerStepsCommands.js +28 -0
  21. package/build/esm/commands/steps/registerStepsCommands.js.map +1 -0
  22. package/build/esm/commands/steps/stepsGenIrHandler.js +75 -0
  23. package/build/esm/commands/steps/stepsGenIrHandler.js.map +1 -0
  24. package/build/esm/commands/steps/stepsGenModelsHandler.js +45 -0
  25. package/build/esm/commands/steps/stepsGenModelsHandler.js.map +1 -0
  26. package/build/esm/commands/steps/stepsGenTypesHandler.js +67 -0
  27. package/build/esm/commands/steps/stepsGenTypesHandler.js.map +1 -0
  28. package/build/esm/commands/steps/stepsGenZodHandler.js +44 -0
  29. package/build/esm/commands/steps/stepsGenZodHandler.js.map +1 -0
  30. package/build/esm/index.js +27 -0
  31. package/build/esm/index.js.map +1 -0
  32. package/build/esm/utils/assertNever.js +20 -0
  33. package/build/esm/utils/assertNever.js.map +1 -0
  34. package/build/esm/utils/formatVariantName.js +21 -0
  35. package/build/esm/utils/formatVariantName.js.map +1 -0
  36. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js +6 -0
  37. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js.map +1 -0
  38. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js +5 -0
  39. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js.map +1 -0
  40. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js +7 -0
  41. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js.map +1 -0
  42. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js +15 -0
  43. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js.map +1 -0
  44. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js +19 -0
  45. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js.map +1 -0
  46. package/build/esm/utils/ir/__tests__/formatWithPrettier.js +29 -0
  47. package/build/esm/utils/ir/__tests__/formatWithPrettier.js.map +1 -0
  48. package/build/esm/utils/ir/__tests__/generateZodSchemasFromIr.test.js +440 -0
  49. package/build/esm/utils/ir/__tests__/generateZodSchemasFromIr.test.js.map +1 -0
  50. package/build/esm/utils/ir/generateModelsFromIr.js +183 -0
  51. package/build/esm/utils/ir/generateModelsFromIr.js.map +1 -0
  52. package/build/esm/utils/ir/generateZodSchemasFromIr.js +315 -0
  53. package/build/esm/utils/ir/generateZodSchemasFromIr.js.map +1 -0
  54. package/build/esm/utils/schema/__tests__/convertSchemaToSteps.test.js +218 -0
  55. package/build/esm/utils/schema/__tests__/convertSchemaToSteps.test.js.map +1 -0
  56. package/build/esm/utils/schema/convertSchemaToSteps.js +104 -0
  57. package/build/esm/utils/schema/convertSchemaToSteps.js.map +1 -0
  58. package/build/esm/utils/schema/generateTypesFromSchema.js +235 -0
  59. package/build/esm/utils/schema/generateTypesFromSchema.js.map +1 -0
  60. package/build/esm/utils/schema/generateZodFromSchema.js +31 -0
  61. package/build/esm/utils/schema/generateZodFromSchema.js.map +1 -0
  62. package/build/esm/utils/schema/validateSchemaModule.js +107 -0
  63. package/build/esm/utils/schema/validateSchemaModule.js.map +1 -0
  64. package/build/esm/utils/steps/__tests__/__snapshots__/stepSchemas/simpleSteps.js +84 -0
  65. package/build/esm/utils/steps/__tests__/__snapshots__/stepSchemas/simpleSteps.js.map +1 -0
  66. package/build/esm/utils/steps/__tests__/__snapshots__/types/arrayFields.js +2 -0
  67. package/build/esm/utils/steps/__tests__/__snapshots__/types/arrayFields.js.map +1 -0
  68. package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js +17 -0
  69. package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map +1 -0
  70. package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js +2 -0
  71. package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js.map +1 -0
  72. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleRecord.js +2 -0
  73. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleRecord.js.map +1 -0
  74. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js +21 -0
  75. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js.map +1 -0
  76. package/build/esm/utils/steps/__tests__/convertStepsToIr.test.js +286 -0
  77. package/build/esm/utils/steps/__tests__/convertStepsToIr.test.js.map +1 -0
  78. package/build/esm/utils/steps/__tests__/convertStepsToSchema.test.js +69 -0
  79. package/build/esm/utils/steps/__tests__/convertStepsToSchema.test.js.map +1 -0
  80. package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/arrayFields.js +22 -0
  81. package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/arrayFields.js.map +1 -0
  82. package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/generateTypeScriptInterfaces.js +78 -0
  83. package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/generateTypeScriptInterfaces.js.map +1 -0
  84. package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/refTypes.js +44 -0
  85. package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/refTypes.js.map +1 -0
  86. package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/simpleRecord.js +23 -0
  87. package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/simpleRecord.js.map +1 -0
  88. package/build/esm/utils/steps/__tests__/generateTypes.test.js +44 -0
  89. package/build/esm/utils/steps/__tests__/generateTypes.test.js.map +1 -0
  90. package/build/esm/utils/steps/convertStepsToIr.js +181 -0
  91. package/build/esm/utils/steps/convertStepsToIr.js.map +1 -0
  92. package/build/esm/utils/steps/convertStepsToSchema.js +156 -0
  93. package/build/esm/utils/steps/convertStepsToSchema.js.map +1 -0
  94. package/build/esm/utils/steps/generateModelsFromStepsSchema.js +31 -0
  95. package/build/esm/utils/steps/generateModelsFromStepsSchema.js.map +1 -0
  96. package/build/esm/utils/steps/generateZodFromStepsSchema.js +31 -0
  97. package/build/esm/utils/steps/generateZodFromStepsSchema.js.map +1 -0
  98. package/build/esm/utils/steps/parseMigrationSteps.js +84 -0
  99. package/build/esm/utils/steps/parseMigrationSteps.js.map +1 -0
  100. package/build/types/cli.d.ts +2 -0
  101. package/build/types/cli.d.ts.map +1 -0
  102. package/build/types/commands/ir/irDeployHandler.d.ts +9 -0
  103. package/build/types/commands/ir/irDeployHandler.d.ts.map +1 -0
  104. package/build/types/commands/ir/irGenModelsHandler.d.ts +9 -0
  105. package/build/types/commands/ir/irGenModelsHandler.d.ts.map +1 -0
  106. package/build/types/commands/ir/irGenZodHandler.d.ts +8 -0
  107. package/build/types/commands/ir/irGenZodHandler.d.ts.map +1 -0
  108. package/build/types/commands/ir/registerIrCommands.d.ts +3 -0
  109. package/build/types/commands/ir/registerIrCommands.d.ts.map +1 -0
  110. package/build/types/commands/schema/__tests__/schemaToYaml.integration.test.d.ts +2 -0
  111. package/build/types/commands/schema/__tests__/schemaToYaml.integration.test.d.ts.map +1 -0
  112. package/build/types/commands/schema/registerSchemaCommands.d.ts +3 -0
  113. package/build/types/commands/schema/registerSchemaCommands.d.ts.map +1 -0
  114. package/build/types/commands/schema/schemaToYamlHandler.d.ts +7 -0
  115. package/build/types/commands/schema/schemaToYamlHandler.d.ts.map +1 -0
  116. package/build/types/commands/steps/registerStepsCommands.d.ts +3 -0
  117. package/build/types/commands/steps/registerStepsCommands.d.ts.map +1 -0
  118. package/build/types/commands/steps/stepsGenIrHandler.d.ts +10 -0
  119. package/build/types/commands/steps/stepsGenIrHandler.d.ts.map +1 -0
  120. package/build/types/commands/steps/stepsGenModelsHandler.d.ts +9 -0
  121. package/build/types/commands/steps/stepsGenModelsHandler.d.ts.map +1 -0
  122. package/build/types/commands/steps/stepsGenTypesHandler.d.ts +6 -0
  123. package/build/types/commands/steps/stepsGenTypesHandler.d.ts.map +1 -0
  124. package/build/types/commands/steps/stepsGenZodHandler.d.ts +8 -0
  125. package/build/types/commands/steps/stepsGenZodHandler.d.ts.map +1 -0
  126. package/build/types/index.d.ts +11 -0
  127. package/build/types/index.d.ts.map +1 -0
  128. package/build/types/utils/assertNever.d.ts +2 -0
  129. package/build/types/utils/assertNever.d.ts.map +1 -0
  130. package/build/types/utils/formatVariantName.d.ts +2 -0
  131. package/build/types/utils/formatVariantName.d.ts.map +1 -0
  132. package/build/types/utils/ir/__tests__/formatWithPrettier.d.ts +5 -0
  133. package/build/types/utils/ir/__tests__/formatWithPrettier.d.ts.map +1 -0
  134. package/build/types/utils/ir/__tests__/generateZodSchemasFromIr.test.d.ts +2 -0
  135. package/build/types/utils/ir/__tests__/generateZodSchemasFromIr.test.d.ts.map +1 -0
  136. package/build/types/utils/ir/generateModelsFromIr.d.ts +17 -0
  137. package/build/types/utils/ir/generateModelsFromIr.d.ts.map +1 -0
  138. package/build/types/utils/ir/generateZodSchemasFromIr.d.ts +9 -0
  139. package/build/types/utils/ir/generateZodSchemasFromIr.d.ts.map +1 -0
  140. package/build/types/utils/schema/__tests__/convertSchemaToSteps.test.d.ts +2 -0
  141. package/build/types/utils/schema/__tests__/convertSchemaToSteps.test.d.ts.map +1 -0
  142. package/build/types/utils/schema/convertSchemaToSteps.d.ts +5 -0
  143. package/build/types/utils/schema/convertSchemaToSteps.d.ts.map +1 -0
  144. package/build/types/utils/schema/generateTypesFromSchema.d.ts +3 -0
  145. package/build/types/utils/schema/generateTypesFromSchema.d.ts.map +1 -0
  146. package/build/types/utils/schema/generateZodFromSchema.d.ts +10 -0
  147. package/build/types/utils/schema/generateZodFromSchema.d.ts.map +1 -0
  148. package/build/types/utils/schema/validateSchemaModule.d.ts +25 -0
  149. package/build/types/utils/schema/validateSchemaModule.d.ts.map +1 -0
  150. package/build/types/utils/steps/__tests__/convertStepsToIr.test.d.ts +2 -0
  151. package/build/types/utils/steps/__tests__/convertStepsToIr.test.d.ts.map +1 -0
  152. package/build/types/utils/steps/__tests__/convertStepsToSchema.test.d.ts +2 -0
  153. package/build/types/utils/steps/__tests__/convertStepsToSchema.test.d.ts.map +1 -0
  154. package/build/types/utils/steps/__tests__/generateTypes.test.d.ts +2 -0
  155. package/build/types/utils/steps/__tests__/generateTypes.test.d.ts.map +1 -0
  156. package/build/types/utils/steps/convertStepsToIr.d.ts +21 -0
  157. package/build/types/utils/steps/convertStepsToIr.d.ts.map +1 -0
  158. package/build/types/utils/steps/convertStepsToSchema.d.ts +7 -0
  159. package/build/types/utils/steps/convertStepsToSchema.d.ts.map +1 -0
  160. package/build/types/utils/steps/generateModelsFromStepsSchema.d.ts +12 -0
  161. package/build/types/utils/steps/generateModelsFromStepsSchema.d.ts.map +1 -0
  162. package/build/types/utils/steps/generateZodFromStepsSchema.d.ts +12 -0
  163. package/build/types/utils/steps/generateZodFromStepsSchema.d.ts.map +1 -0
  164. package/build/types/utils/steps/parseMigrationSteps.d.ts +21 -0
  165. package/build/types/utils/steps/parseMigrationSteps.d.ts.map +1 -0
  166. package/package.json +65 -0
@@ -0,0 +1,23 @@
1
+ const simpleRecord = {
2
+ "Person": {
3
+ "type": "record",
4
+ "name": "Person",
5
+ "docs": "A person record",
6
+ "fields": {
7
+ "name": {
8
+ "type": "string"
9
+ },
10
+ "age": {
11
+ "type": "double"
12
+ },
13
+ "email": {
14
+ "type": "optional",
15
+ "item": {
16
+ "type": "string"
17
+ }
18
+ }
19
+ }
20
+ }
21
+ };
22
+ export default simpleRecord;
23
+ //# sourceMappingURL=simpleRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simpleRecord.js","names":["simpleRecord"],"sources":["simpleRecord.ts"],"sourcesContent":["import { Schema } from \"@palantir/pack.schema\";\n\nconst simpleRecord = {\n \"Person\": {\n \"type\": \"record\",\n \"name\": \"Person\",\n \"docs\": \"A person record\",\n \"fields\": {\n \"name\": {\n \"type\": \"string\",\n },\n \"age\": {\n \"type\": \"double\",\n },\n \"email\": {\n \"type\": \"optional\",\n \"item\": {\n \"type\": \"string\",\n },\n },\n },\n },\n} satisfies Schema<any>;\n\nexport default simpleRecord;\n"],"mappings":"AAEA,MAAMA,YAAY,GAAG;EACnB,QAAQ,EAAE;IACR,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,iBAAiB;IACzB,QAAQ,EAAE;MACR,MAAM,EAAE;QACN,MAAM,EAAE;MACV,CAAC;MACD,KAAK,EAAE;QACL,MAAM,EAAE;MACV,CAAC;MACD,OAAO,EAAE;QACP,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE;UACN,MAAM,EAAE;QACV;MACF;IACF;EACF;AACF,CAAuB;AAEvB,eAAeA,YAAY","ignoreList":[]}
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright 2025 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 fs from "fs";
18
+ import path from "path";
19
+ import { describe, expect, it } from "vitest";
20
+ import { generateTypesFromSchema } from "../../schema/generateTypesFromSchema.js";
21
+ describe("generateTypes", () => {
22
+ // TODO: Add runtime validation of schema types instead of just using type assertions
23
+ // The fixtures currently use the old format with 'recordName' instead of 'name'
24
+ // and the tests pass because of type assertions that don't validate the actual runtime types
25
+
26
+ // Use __dirname which is available in both CJS and when vitest transforms the code
27
+ const fixturesInputDir = path.join(__dirname, "fixtures", "stepSchemas");
28
+ const snapshotTypesDir = path.join(__dirname, "__snapshots__", "types");
29
+
30
+ // Check if directory exists before reading
31
+ if (!fs.existsSync(fixturesInputDir)) {
32
+ throw new Error(`Fixtures directory not found: ${fixturesInputDir}`);
33
+ }
34
+ const testFiles = fs.readdirSync(fixturesInputDir).filter(file => file.endsWith(".ts"));
35
+ testFiles.forEach(testFile => {
36
+ const testName = path.basename(testFile, ".ts");
37
+ it(`should handle ${testName}`, async () => {
38
+ const inputSchema = await import(path.join(fixturesInputDir, testFile));
39
+ const result = generateTypesFromSchema(inputSchema.default);
40
+ await expect(result).toMatchFileSnapshot(path.join(snapshotTypesDir, `${testName}.ts`));
41
+ });
42
+ });
43
+ });
44
+ //# sourceMappingURL=generateTypes.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateTypes.test.js","names":["fs","path","describe","expect","it","generateTypesFromSchema","fixturesInputDir","join","__dirname","snapshotTypesDir","existsSync","Error","testFiles","readdirSync","filter","file","endsWith","forEach","testFile","testName","basename","inputSchema","result","default","toMatchFileSnapshot"],"sources":["generateTypes.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 type { ReturnedSchema, Schema } from \"@palantir/pack.schema\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { describe, expect, it } from \"vitest\";\nimport { generateTypesFromSchema } from \"../../schema/generateTypesFromSchema.js\";\n\ndescribe(\"generateTypes\", () => {\n // TODO: Add runtime validation of schema types instead of just using type assertions\n // The fixtures currently use the old format with 'recordName' instead of 'name'\n // and the tests pass because of type assertions that don't validate the actual runtime types\n\n // Use __dirname which is available in both CJS and when vitest transforms the code\n const fixturesInputDir = path.join(__dirname, \"fixtures\", \"stepSchemas\");\n const snapshotTypesDir = path.join(__dirname, \"__snapshots__\", \"types\");\n\n // Check if directory exists before reading\n if (!fs.existsSync(fixturesInputDir)) {\n throw new Error(`Fixtures directory not found: ${fixturesInputDir}`);\n }\n\n const testFiles = fs\n .readdirSync(fixturesInputDir)\n .filter(file => file.endsWith(\".ts\"));\n\n testFiles.forEach(testFile => {\n const testName = path.basename(testFile, \".ts\");\n\n it(`should handle ${testName}`, async () => {\n const inputSchema = await import(path.join(fixturesInputDir, testFile)) as {\n default: Schema<ReturnedSchema>;\n };\n const result = generateTypesFromSchema(inputSchema.default);\n\n await expect(result).toMatchFileSnap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IAAI,CAACM,IAAI,CAACE,gBAAgB,EAAE,GAAGU,QAAQ,KAAK,CAAC,CAAC;IACzF,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,181 @@
1
+ /*
2
+ * Copyright 2025 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 { IFieldTypeUnion, IFieldValueUnion, IModelDef } from "@palantir/pack-docschema-api/pack-docschema-ir";
18
+ import invariant from "tiny-invariant";
19
+ import { assertNever } from "../assertNever.js";
20
+ import { convertStepsToSchema } from "./convertStepsToSchema.js";
21
+ /**
22
+ * Converts migration steps to Palantir IR format
23
+ */
24
+ export function convertStepsToIr(steps, metadata) {
25
+ // First convert steps to document-schema-api format
26
+ const {
27
+ recordDefinitions,
28
+ unionDefinitions
29
+ } = convertStepsToSchema(steps);
30
+ const schema = {
31
+ ...Object.fromEntries(recordDefinitions.map(def => [def.name, def])),
32
+ ...Object.fromEntries(unionDefinitions.map(def => [def.name, def]))
33
+ };
34
+ return convertSchemaToIr(schema, metadata);
35
+ }
36
+
37
+ /**
38
+ * Converts record and union definitions to Palantir IR format
39
+ */
40
+ export function convertSchemaToIr(inputSchema, metadata) {
41
+ const primaryModelKeys = [];
42
+ const models = new Map();
43
+ for (const modelDef of Object.values(inputSchema)) {
44
+ if (collectModels(modelDef, models)) {
45
+ primaryModelKeys.push(modelDef.name);
46
+ }
47
+ }
48
+ return {
49
+ name: metadata?.name ?? "Generated Schema",
50
+ description: metadata?.description ?? "Schema generated from migration steps",
51
+ version: metadata?.version ?? 1,
52
+ primaryModelKeys,
53
+ models: Object.fromEntries(models)
54
+ };
55
+ }
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;
58
+ switch (modelDef.type) {
59
+ case "record":
60
+ {
61
+ outModels.set(modelDef.name, IModelDef.record(convertRecordDefToIr(modelDef)));
62
+ return true;
63
+ }
64
+ case "union":
65
+ {
66
+ outModels.set(modelDef.name, IModelDef.union(convertUnionDefToIr(modelDef)));
67
+ return true;
68
+ }
69
+ default:
70
+ assertNever(modelDef);
71
+ }
72
+ }
73
+ export function convertRecordDefToIr(recordDef) {
74
+ const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]) => ({
75
+ key: fieldKey,
76
+ name: fieldKey,
77
+ description: undefined,
78
+ value: convertTypeToFieldTypeUnion(fieldType),
79
+ meta: {
80
+ addedIn: 1
81
+ },
82
+ isOptional: fieldType.type === "optional" ? true : undefined
83
+ }));
84
+ return {
85
+ key: recordDef.name,
86
+ name: recordDef.name,
87
+ description: recordDef.docs || undefined,
88
+ fields,
89
+ meta: {
90
+ addedIn: 1
91
+ }
92
+ };
93
+ }
94
+ export function convertUnionDefToIr(unionDef) {
95
+ const variantEntries = Object.entries(unionDef.variants).map(([variantName, modelRef]) => [variantName, modelRef.name]);
96
+ return {
97
+ key: unionDef.name,
98
+ name: unionDef.name,
99
+ description: unionDef.docs,
100
+ discriminant: unionDef.discriminant,
101
+ variants: Object.fromEntries(variantEntries),
102
+ meta: {
103
+ addedIn: 1
104
+ }
105
+ };
106
+ }
107
+
108
+ // TODO: rename to convertSchemaTypeToFieldTypeUnion
109
+ export function convertTypeToFieldTypeUnion(schemaType) {
110
+ switch (schemaType.type) {
111
+ case "array":
112
+ {
113
+ return IFieldTypeUnion.array({
114
+ allowNullValue: false,
115
+ value: convertTypeToFieldValueUnion(schemaType.items)
116
+ });
117
+ }
118
+ // TODO: have map/set types in document-schema-api
119
+
120
+ case "optional":
121
+ {
122
+ // Optional flag is handled at field level, but we need to unwrap the inner type
123
+
124
+ return convertTypeToFieldTypeUnion(schemaType.item);
125
+ }
126
+ case "docRef":
127
+ case "double":
128
+ case "mediaRef":
129
+ case "objectRef":
130
+ case "ref":
131
+ case "string":
132
+ case "unknown":
133
+ case "userRef":
134
+ return IFieldTypeUnion.value(convertTypeToFieldValueUnion(schemaType));
135
+ default:
136
+ assertNever(schemaType);
137
+ }
138
+ }
139
+ function convertTypeToFieldValueUnion(schemaType) {
140
+ switch (schemaType.type) {
141
+ case "array":
142
+ // TODO: fix the argument types so these aren't possible
143
+ process.env.NODE_ENV !== "production" ? invariant(false, `Collection type passed to convertTypeToFieldValueUnion: ${schemaType.type}`) : invariant(false);
144
+ case "docRef":
145
+ return IFieldValueUnion.docRef({
146
+ documentTypeRids: [] // FIXME: confirm whether we will use rids in the deployed schema.
147
+ });
148
+ case "double":
149
+ return IFieldValueUnion.double({});
150
+ case "mediaRef":
151
+ return IFieldValueUnion.mediaRef({
152
+ mediaTypeRids: [] // FIXME: confirm whether we will use rids in the deployed schema.
153
+ });
154
+ case "objectRef":
155
+ return IFieldValueUnion.object({
156
+ // FIXME: confirm whether we will use rids in the deployed schema.
157
+ interfaceTypeRids: [],
158
+ objectTypeRids: []
159
+ });
160
+ case "optional":
161
+ {
162
+ // If we get here, it means we have nested optionals - unwrap and continue
163
+ // TODO: probably warn? maybe throw
164
+
165
+ return convertTypeToFieldValueUnion(schemaType.item);
166
+ }
167
+ case "ref":
168
+ return IFieldValueUnion.modelRef({
169
+ modelTypes: [schemaType.name]
170
+ });
171
+ case "string":
172
+ return IFieldValueUnion.string({});
173
+ case "unknown":
174
+ return IFieldValueUnion.unmanagedJson({});
175
+ case "userRef":
176
+ return IFieldValueUnion.userRef({});
177
+ default:
178
+ assertNever(schemaType);
179
+ }
180
+ }
181
+ //# sourceMappingURL=convertStepsToIr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertStepsToIr.js","names":["IFieldTypeUnion","IFieldValueUnion","IModelDef","invariant","assertNever","convertStepsToSchema","convertStepsToIr","steps","metadata","recordDefinitions","unionDefinitions","schema","Object","fromEntries","map","def","name","convertSchemaToIr","inputSchema","primaryModelKeys","models","Map","modelDef","values","collectModels","push","description","version","outModels","has","process","env","NODE_ENV","type","set","record","convertRecordDefToIr","union","convertUnionDefToIr","recordDef","fields","entries","fieldKey","fieldType","key","undefined","value","convertTypeToFieldTypeUnion","meta","addedIn","isOptional","docs","unionDef","variantEntries","variants","variantName","modelRef","discriminant","schemaType","array","allowNullValue","convertTypeToFieldValueUnion","items","item","docRef","documentTypeRids","double","mediaRef","mediaTypeRids","object","interfaceTypeRids","objectTypeRids","modelTypes","string","unmanagedJson","userRef"],"sources":["convertStepsToIr.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 type {\n IModelTypeKey,\n IUnionVariantKey,\n} from \"@palantir/pack-docschema-api/pack-docschema-api\";\nimport type {\n IFieldDef,\n IRealTimeDocumentSchema,\n IRecordDef,\n IUnionDef,\n} from \"@palantir/pack-docschema-api/pack-docschema-ir\";\nimport {\n IFieldTypeUnion,\n IFieldValueUnion,\n IModelDef,\n} from \"@palantir/pack-docschema-api/pack-docschema-ir\";\nimport type * as P from \"@palantir/pack.schema\";\nimport invariant from \"tiny-invariant\";\nimport { assertNever } from \"../assertNever.js\";\nimport { convertStepsToSchema } from \"./convertStepsToSchema.js\";\nimport type { MigrationStep } from \"./parseMigrationSteps.js\";\n\nexport interface SchemaMetadata {\n readonly name?: string;\n readonly description?: string;\n readonly version?: number;\n}\n\n/**\n * Converts migration steps to Palantir IR format\n */\nexport function convertStepsToIr(\n steps: readonly MigrationStep[],\n metadata?: SchemaMetadata,\n): IRealTimeDocumentSchema {\n // First convert steps to document-schema-api format\n const { recordDefinitions, unionDefinitions } = convertStepsToSchema(steps as MigrationStep[]);\n\n const schema = {\n ...Object.fromEntries(recordDefinitions.map(def => [def.name, def])),\n ...Object.fromEntries(unionDefinitions.map(def => [def.name, def])),\n };\n\n return convertSchemaToIr(schema, metadata);\n}\n\n/**\n * Converts record and union definitions to Palantir IR format\n */\nexport function convertSchemaToIr(\n inputSchema: P.Schema<P.ReturnedSchema>,\n metadata?: SchemaMetadata,\n): IRealTimeDocumentSchema {\n const primaryModelKeys: IModelTypeKey[] = [];\n const models = new Map<IModelTypeKey, IModelDef>();\n\n for (const modelDef of Object.values(inputSchema)) {\n if (collectModels(modelDef, models)) {\n primaryModelKeys.push(modelDef.name);\n }\n }\n\n return {\n name: metadata?.name ?? \"Generated Schema\",\n description: metadata?.description ?? \"Schema generated from migration steps\",\n version: metadata?.version ?? 1,\n primaryModelKeys,\n models: Object.fromEntries(models),\n };\n}\n\nfunction collectModels(\n modelDef: P.ModelDef,\n outModels: Map<IModelTypeKey, IModelDef>,\n): boolean {\n invariant(\n !outModels.has(modelDef.name),\n `Duplicate model definition: ${modelDef.name}`,\n );\n\n switch (modelDef.type) {\n case \"record\": {\n outModels.set(modelDef.name, IModelDef.record(convertRecordDefToIr(modelDef)));\n return true;\n }\n case \"union\": {\n outModels.set(modelDef.name, IModelDef.union(convertUnionDefToIr(modelDef)));\n return true;\n }\n default:\n assertNever(modelDef);\n }\n}\n\nexport function convertRecordDefToIr(recordDef: P.RecordDef): IRecordDef {\n const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]): IFieldDef => ({\n key: fieldKey,\n name: fieldKey,\n description: undefined,\n value: convertTypeToFieldTypeUnion(fieldType),\n meta: { addedIn: 1 },\n isOptional: fieldType.type === \"optional\" ? true : undefined,\n }));\n\n return {\n key: recordDef.name,\n name: recordDef.name,\n description: recordDef.docs || undefined,\n fields,\n meta: { addedIn: 1 },\n };\n}\n\nexport function convertUnionDefToIr(unionDef: P.UnionDef): IUnionDef {\n const variantEntries = Object.entries(unionDef.variants).map((\n [variantName, modelRef],\n ) =>\n [\n variantName as IUnionVariantKey,\n modelRef.name as IModelTypeKey,\n ] as const\n );\n\n return {\n key: unionDef.name,\n name: unionDef.name,\n description: unionDef.docs,\n discriminant: unionDef.discriminant,\n variants: Object.fromEntries(variantEntries),\n meta: { addedIn: 1 },\n };\n}\n\n// TODO: rename to convertSchemaTypeToFieldTypeUnion\nexport function convertTypeToFieldTypeUnion(schemaType: P.Type): IFieldTypeUnion {\n switch (schemaType.type) {\n case \"array\": {\n const arrayType = schemaType as P.Array;\n return IFieldTypeUnion.array({\n allowNullValue: false,\n value: convertTypeToFieldValueUnion(arrayType.items as P.Type),\n });\n }\n // TODO: have map/set types in document-schema-api\n\n case \"optional\": {\n // Optional flag is handled at field level, but we need to unwrap the inner type\n const optionalType = schemaType as P.Optional;\n return convertTypeToFieldTypeUnion(optionalType.item as P.Type);\n }\n\n case \"docRef\":\n case \"double\":\n case \"mediaRef\":\n case \"objectRef\":\n case \"ref\":\n case \"string\":\n case \"unknown\":\n case \"userRef\":\n return IFieldTypeUnion.value(convertTypeToFieldValueUnion(schemaType));\n\n default:\n assertNever(schemaType);\n }\n}\n\nfunction convertTypeToFieldValueUnion(schemaType: P.Type): IFieldValueUnion {\n switch (schemaType.type) {\n case \"array\":\n // TODO: fix the argument types so these aren't possible\n invariant(\n false,\n `Collection type passed to convertTypeToFieldValueUnion: ${schemaType.type}`,\n );\n\n case \"docRef\":\n return IFieldValueUnion.docRef({\n documentTypeRids: [], // FIXME: confirm whether we will use rids in the deployed schema.\n });\n\n case \"double\":\n return IFieldValueUnion.double({});\n\n case \"mediaRef\":\n return IFieldValueUnion.mediaRef({\n mediaTypeRids: [], // FIXME: confirm whether we will use rids in the deployed schema.\n });\n\n case \"objectRef\":\n return IFieldValueUnion.object({\n // FIXME: confirm whether we will use rids in the deployed schema.\n interfaceTypeRids: [],\n objectTypeRids: [],\n });\n\n case \"optional\": {\n // If we get here, it means we have nested optionals - unwrap and continue\n // TODO: probably warn? maybe throw\n const optionalType = schemaType as P.Optional;\n return convertTypeToFieldValueUnion(optionalType.item as P.Type);\n }\n\n case \"ref\":\n return IFieldValueUnion.modelRef({\n modelTypes: [schemaType.name as IModelTypeKey],\n });\n\n case \"string\":\n return IFieldValueUnion.string({});\n\n case \"unknown\":\n return IFieldValueUnion.unmanagedJson({});\n\n case \"userRef\":\n return IFieldValueUnion.userRef({});\n\n default:\n assertNever(schemaType);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,SACEA,eAAe,EACfC,gBAAgB,EAChBC,SAAS,QACJ,gDAAgD;AAEvD,OAAOC,SAAS,MAAM,gBAAgB;AACtC,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,oBAAoB,QAAQ,2BAA2B;AAShE;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,KAA+B,EAC/BC,QAAyB,EACA;EACzB;EACA,MAAM;IAAEC,iBAAiB;IAAEC;EAAiB,CAAC,GAAGL,oBAAoB,CAACE,KAAwB,CAAC;EAE9F,MAAMI,MAAM,GAAG;IACb,GAAGC,MAAM,CAACC,WAAW,CAACJ,iBAAiB,CAACK,GAAG,CAACC,GAAG,IAAI,CAACA,GAAG,CAACC,IAAI,EAAED,GAAG,CAAC,CAAC,CAAC;IACpE,GAAGH,MAAM,CAACC,WAAW,CAACH,gBAAgB,CAACI,GAAG,CAACC,GAAG,IAAI,CAACA,GAAG,CAACC,IAAI,EAAED,GAAG,CAAC,CAAC;EACpE,CAAC;EAED,OA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;MACrB,CAAC,CAAC;IAEJ,KAAK,WAAW;MACd,OAAOnE,gBAAgB,CAACoE,MAAM,CAAC;QAC7B;QACAC,iBAAiB,EAAE,EAAE;QACrBC,cAAc,EAAE;MAClB,CAAC,CAAC;IAEJ,KAAK,UAAU;MAAE;QACf;QACA;;QAEA,OAAOV,4BAA4B,CADdH,UAAU,CACkBK,IAAc,CAAC;MAClE;IAEA,KAAK,KAAK;MACR,OAAO9D,gBAAgB,CAACuD,QAAQ,CAAC;QAC/BgB,UAAU,EAAE,CAACd,UAAU,CAAC1C,IAAI;MAC9B,CAAC,CAAC;IAEJ,KAAK,QAAQ;MACX,OAAOf,gBAAgB,CAACwE,MAAM,CAAC,CAAC,CAAC,CAAC;IAEpC,KAAK,SAAS;MACZ,OAAOxE,gBAAgB,CAACyE,aAAa,CAAC,CAAC,CAAC,CAAC;IAE3C,KAAK,SAAS;MACZ,OAAOzE,gBAAgB,CAAC0E,OAAO,CAAC,CAAC,CAAC,CAAC;IAErC;MACEvE,WAAW,CAACsD,UAAU,CAAC;EAC3B;AACF","ignoreList":[]}
@@ -0,0 +1,156 @@
1
+ /*
2
+ * Copyright 2025 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 { modelToRef } from "@palantir/pack.schema";
18
+ export function convertStepsToSchema(steps) {
19
+ const localFragmentsByName = {};
20
+ const recordDefinitionsByName = {};
21
+ const unionDefinitionsByName = {};
22
+ for (const step of steps) {
23
+ if ("local-fragment" in step) {
24
+ const localFragment = step["local-fragment"];
25
+ Object.assign(localFragmentsByName, localFragment);
26
+ }
27
+ const addRecords = step["add-records"];
28
+ if (addRecords) {
29
+ for (const [recordKey, recordDef] of Object.entries(addRecords)) {
30
+ const recordFields = {};
31
+ for (const localFragmentName of recordDef.extends ?? []) {
32
+ const localFragment = localFragmentsByName[localFragmentName];
33
+ Object.assign(recordFields, localFragment);
34
+ }
35
+ for (const [fieldKey, fieldDefinition] of Object.entries(recordDef.fields)) {
36
+ recordFields[fieldKey] = fieldDefinition;
37
+ }
38
+ const recordFieldsAsSchemaType = {};
39
+ for (const [fieldKey, fieldDefinition] of Object.entries(recordFields)) {
40
+ recordFieldsAsSchemaType[fieldKey] = recordFieldDefinitionToSchemaType(fieldDefinition);
41
+ }
42
+ recordDefinitionsByName[recordKey] = {
43
+ type: "record",
44
+ name: recordKey,
45
+ fields: recordFieldsAsSchemaType,
46
+ docs: recordDef.docs
47
+ };
48
+ }
49
+ }
50
+ if ("add-union" in step) {
51
+ const addUnion = step["add-union"];
52
+ for (const [unionKey, unionDef] of Object.entries(addUnion)) {
53
+ // unionDef is a map from typeKey to recordKey (i.e. {"object" -> "ObjectNode"} implies { type: "object", ...ObjectNode })
54
+
55
+ const variants = {};
56
+ for (const [typeKey, recordKey] of Object.entries(unionDef)) {
57
+ const recordDef = recordDefinitionsByName[recordKey];
58
+ if (!recordDef) {
59
+ throw new Error(`Record ${recordKey} not found`);
60
+ }
61
+ variants[typeKey] = modelToRef(recordDef);
62
+ }
63
+ unionDefinitionsByName[unionKey] = {
64
+ type: "union",
65
+ name: unionKey,
66
+ docs: unionDef.docs,
67
+ variants,
68
+ discriminant: "type"
69
+ };
70
+ }
71
+ }
72
+ if ("modify-records" in step) {
73
+ const modifyRecords = step["modify-records"];
74
+ for (const [recordKey, modifyRecord] of Object.entries(modifyRecords)) {
75
+ const recordDef = recordDefinitionsByName[recordKey];
76
+ if (!recordDef) {
77
+ throw new Error(`Record ${recordKey} not found`);
78
+ }
79
+ for (const [fieldKey, fieldDefinition] of Object.entries(modifyRecord["add-fields"])) {
80
+ recordDef.fields[fieldKey] = recordFieldDefinitionToSchemaType(fieldDefinition);
81
+ }
82
+ }
83
+ }
84
+ }
85
+ return {
86
+ recordDefinitions: Object.values(recordDefinitionsByName),
87
+ unionDefinitions: Object.values(unionDefinitionsByName)
88
+ };
89
+ }
90
+ function recordFieldDefinitionToSchemaType(recordFieldDefinition) {
91
+ if (typeof recordFieldDefinition === "string") {
92
+ // Basic types
93
+ if (recordFieldDefinition === "docRef") {
94
+ return {
95
+ type: "docRef"
96
+ };
97
+ }
98
+ if (recordFieldDefinition === "double") {
99
+ return {
100
+ type: "double"
101
+ };
102
+ }
103
+ if (recordFieldDefinition === "mediaRef") {
104
+ return {
105
+ type: "mediaRef"
106
+ };
107
+ }
108
+ if (recordFieldDefinition === "objectRef") {
109
+ return {
110
+ type: "objectRef"
111
+ };
112
+ }
113
+ if (recordFieldDefinition === "string") {
114
+ return {
115
+ type: "string"
116
+ };
117
+ }
118
+ if (recordFieldDefinition === "userRef") {
119
+ return {
120
+ type: "userRef"
121
+ };
122
+ }
123
+
124
+ // Array types - e.g., "array<string>", "list<double>"
125
+ const arrayMatch = recordFieldDefinition.match(/^(?:array|list)<(.+)>$/);
126
+ if (arrayMatch?.[1]) {
127
+ const innerType = recordFieldDefinitionToSchemaType(arrayMatch[1]);
128
+ return {
129
+ type: "array",
130
+ items: innerType
131
+ };
132
+ }
133
+
134
+ // Optional types - e.g., "optional<string>"
135
+ const optionalMatch = recordFieldDefinition.match(/^optional<(.+)>$/);
136
+ if (optionalMatch?.[1]) {
137
+ const innerType = recordFieldDefinitionToSchemaType(optionalMatch[1]);
138
+ return {
139
+ type: "optional",
140
+ item: innerType
141
+ };
142
+ }
143
+
144
+ // Capitalized names are assumed to be references to other records or unions
145
+ if (recordFieldDefinition.charAt(0) === recordFieldDefinition.charAt(0).toUpperCase()) {
146
+ return {
147
+ type: "ref",
148
+ refType: "record",
149
+ // Could be union, but we assume record for now
150
+ name: recordFieldDefinition
151
+ };
152
+ }
153
+ }
154
+ throw new Error("Invalid record field definition " + JSON.stringify(recordFieldDefinition));
155
+ }
156
+ //# sourceMappingURL=convertStepsToSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertStepsToSchema.js","names":["modelToRef","convertStepsToSchema","steps","localFragmentsByName","recordDefinitionsByName","unionDefinitionsByName","step","localFragment","Object","assign","addRecords","recordKey","recordDef","entries","recordFields","localFragmentName","extends","fieldKey","fieldDefinition","fields","recordFieldsAsSchemaType","recordFieldDefinitionToSchemaType","type","name","docs","addUnion","unionKey","unionDef","variants","typeKey","Error","discriminant","modifyRecords","modifyRecord","recordDefinitions","values","unionDefinitions","recordFieldDefinition","arrayMatch","match","innerType","items","optionalMatch","item","charAt","toUpperCase","refType","JSON","stringify"],"sources":["convertStepsToSchema.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 {\n modelToRef,\n type RecordDef,\n type Ref,\n type Type,\n type UnionDef,\n} from \"@palantir/pack.schema\";\nimport type { MigrationStep, RecordFieldDefinition } from \"./parseMigrationSteps.js\";\n\nexport function convertStepsToSchema(steps: MigrationStep[]): {\n recordDefinitions: RecordDef[];\n unionDefinitions: UnionDef[];\n} {\n const localFragmentsByName: Record<string, Record<string, string>> = {};\n const recordDefinitionsByName: Record<string, RecordDef> = {};\n const unionDefinitionsByName: Record<string, UnionDef> = {};\n\n for (const step of steps) {\n if (\"local-fragment\" in step) {\n const localFragment = step[\"local-fragment\"]!;\n Object.assign(localFragmentsByName, localFragment);\n }\n\n const addRecords = step[\"add-records\"];\n if (addRecords) {\n for (const [recordKey, recordDef] of Object.entries(addRecords)) {\n const recordFields: Record<string, RecordFieldDefinition> = {};\n for (const localFragmentName of recordDef.extends ?? []) {\n const localFragment = localFragmentsByName[localFragmentName];\n Object.assign(recordFields, localFragment);\n }\n for (const [fieldKey, fieldDefinition] of Object.entries(recordDef.fields)) {\n recordFields[fieldKey] = fieldDefinition;\n }\n\n const recordFieldsAsSchemaType: Record<string, Type> = {};\n for (const [fieldKey, fieldDefinition] of Object.entries(recordFields)) {\n recordFieldsAsSchemaType[fieldKey] = recordFieldDefinitionToSchemaType(fieldDefinition);\n }\n\n recordDefinitionsByName[recordKey] = {\n type: \"record\",\n name: recordKey,\n fields: recordFieldsAsSchemaType,\n docs: recordDef.docs,\n };\n }\n }\n\n if (\"add-union\" in step) {\n const addUnion = step[\"add-union\"]!;\n for (const [unionKey, unionDef] of Object.entries(addUnion)) {\n // unionDef is a map from typeKey to recordKey (i.e. {\"object\" -> \"ObjectNode\"} implies { type: \"object\", ...ObjectNode })\n\n const variants: Record<string, Ref> = {};\n for (const [typeKey, recordKey] of Object.entries(unionDef)) {\n const recordDef = recordDefinitionsByName[recordKey];\n if (!recordDef) {\n throw new Error(`Record ${recordKey} not found`);\n }\n variants[typeKey] = modelToRef(recordDef);\n }\n\n unionDefinitionsByName[unionKey] = {\n type: \"union\",\n name: unionKey,\n docs: unionDef.docs,\n variants,\n discriminant: \"type\",\n };\n }\n }\n\n if (\"modify-records\" in step) {\n const modifyRecords = step[\"modify-records\"]!;\n for (const [recordKey, modifyRecord] of Object.entries(modifyRecords)) {\n const recordDef = recordDefinitionsByName[recordKey];\n if (!recordDef) {\n throw new Error(`Record ${recordKey} not found`);\n }\n for (const [fieldKey, fieldDefinition] of Object.entries(modifyRecord[\"add-fields\"])) {\n recordDef.fields[fieldKey] = recordFieldDefinitionToSchemaType(fieldDefinition);\n }\n }\n }\n }\n\n return {\n recordDefinitions: Object.values(recordDefinitionsByName),\n unionDefinitions: Object.values(unionDefinitionsByName),\n };\n}\n\nfunction recordFieldDefinitionToSchemaType(\n recordFieldDefinition: RecordFieldDefinition,\n): Type {\n if (typeof recordFieldDefinition === \"string\") {\n // Basic types\n if (recordFieldDefinition === \"docRef\") {\n return { type: \"docRef\" };\n }\n if (recordFieldDefinition === \"double\") {\n return { type: \"double\" };\n }\n if (recordFieldDefinition === \"mediaRef\") {\n return { type: \"mediaRef\" };\n }\n if (recordFieldDefinition === \"objectRef\") {\n return { type: \"objectRef\" };\n }\n if (recordFieldDefinition === \"string\") {\n return { type: \"string\" };\n }\n if (recordFieldDefinition === \"userRef\") {\n return { type: \"userRef\" };\n }\n\n // Array types - e.g., \"array<string>\", \"list<double>\"\n const arrayMatch = recordFieldDefinition.match(/^(?:array|list)<(.+)>$/);\n if (arrayMatch?.[1]) {\n const innerType = recordFieldDefinitionToSchemaType(arrayMatch[1]);\n return { type: \"array\", items: innerType };\n }\n\n // Optional types - e.g., \"optional<string>\"\n const optionalMatch = recordFieldDefinition.match(/^optional<(.+)>$/);\n if (optionalMatch?.[1]) {\n const innerType = recordFieldDefinitionToSchemaType(optionalMatch[1]);\n return { type: \"optional\", item: innerType };\n }\n\n // Capitalized names are assumed to be references to other records or unions\n if (\n recordFieldDefinition.charAt(0)\n === recordFieldDefinition.charAt(0).toUpperCase()\n ) {\n return {\n type: \"ref\",\n refType: \"record\", // Could be union, but we assume record for now\n name: recordFieldDefinition,\n };\n }\n }\n throw new Error(\n \"Invalid record field definition \" + JSON.stringify(recordFieldDefinition),\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,UAAU,QAKL,uBAAuB;AAG9B,OAAO,SAASC,oBAAoBA,CAACC,KAAsB,EAGzD;EACA,MAAMC,oBAA4D,GAAG,CAAC,CAAC;EACvE,MAAMC,uBAAkD,GAAG,CAAC,CAAC;EAC7D,MAAMC,sBAAgD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SAAS,GAAGnB,iCAAiC,CAACqB,aAAa,CAAC,CAAC,CAAC,CAAC;MACrE,OAAO;QAAEpB,IAAI,EAAE,UAAU;QAAEqB,IAAI,EAAEH;MAAU,CAAC;IAC9C;;IAEA;IACA,IACEH,qBAAqB,CAACO,MAAM,CAAC,CAAC,CAAC,KACzBP,qBAAqB,CAACO,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,CAAC,CAAC,EACnD;MACA,OAAO;QACLvB,IAAI,EAAE,KAAK;QACXwB,OAAO,EAAE,QAAQ;QAAE;QACnBvB,IAAI,EAAEc;MACR,CAAC;IACH;EACF;EACA,MAAM,IAAIP,KAAK,CACb,kCAAkC,GAAGiB,IAAI,CAACC,SAAS,CAACX,qBAAqB,CAC3E,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright 2025 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 { generateModelsFromIr } from "../ir/generateModelsFromIr.js";
18
+ import { convertStepsToIr } from "./convertStepsToIr.js";
19
+ /**
20
+ * Generates Model constants from migration steps
21
+ * @param steps - Array of migration steps
22
+ * @param metadata - Optional schema metadata overrides
23
+ * @param options - Optional generator options (e.g., typeImportPath, schemaImportPath)
24
+ * @returns Generated TypeScript code with Model constants
25
+ */
26
+ export async function generateModelsFromStepsSchema(steps, metadata, options) {
27
+ const irSchema = convertStepsToIr(steps, metadata);
28
+ const generatedModelsSource = await generateModelsFromIr(irSchema, options);
29
+ return generatedModelsSource;
30
+ }
31
+ //# sourceMappingURL=generateModelsFromStepsSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateModelsFromStepsSchema.js","names":["generateModelsFromIr","convertStepsToIr","generateModelsFromStepsSchema","steps","metadata","options","irSchema","generatedModelsSource"],"sources":["generateModelsFromStepsSchema.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 { generateModelsFromIr, type ModelGeneratorOptions } from \"../ir/generateModelsFromIr.js\";\nimport { convertStepsToIr, type SchemaMetadata } from \"./convertStepsToIr.js\";\nimport type { MigrationStep } from \"./parseMigrationSteps.js\";\n\n/**\n * Generates Model constants from migration steps\n * @param steps - Array of migration steps\n * @param metadata - Optional schema metadata overrides\n * @param options - Optional generator options (e.g., typeImportPath, schemaImportPath)\n * @returns Generated TypeScript code with Model constants\n */\nexport async function generateModelsFromStepsSchema(\n steps: readonly MigrationStep[],\n metadata?: SchemaMetadata,\n options?: Pick<ModelGeneratorOptions, \"typeImportPath\" | \"schemaImportPath\">,\n): Promise<string> {\n const irSchema = convertStepsToIr(steps, metadata);\n const generatedModelsSource = await generateModelsFromIr(irSchema, options);\n return generatedModelsSource;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,oBAAoB,QAAoC,+BAA+B;AAChG,SAASC,gBAAgB,QAA6B,uBAAuB;AAG7E;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,6BAA6BA,CACjDC,KAA+B,EAC/BC,QAAyB,EACzBC,OAA4E,EAC3D;EACjB,MAAMC,QAAQ,GAAGL,gBAAgB,CAACE,KAAK,EAAEC,QAAQ,CAAC;EAClD,MAAMG,qBAAqB,GAAG,MAAMP,oBAAoB,CAACM,QAAQ,EAAED,OAAO,CAAC;EAC3E,OAAOE,qBAAqB;AAC9B","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright 2025 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 { generateZodSchemasFromIr } from "../ir/generateZodSchemasFromIr.js";
18
+ import { convertStepsToIr } from "./convertStepsToIr.js";
19
+ /**
20
+ * Generates Zod schemas from migration steps
21
+ * @param steps - Array of migration steps
22
+ * @param metadata - Optional schema metadata overrides
23
+ * @param options - Optional generator options (e.g., typeImportPath for satisfies operators)
24
+ * @returns Generated TypeScript code with Zod schemas
25
+ */
26
+ export async function generateZodFromStepsSchema(steps, metadata, options) {
27
+ const irSchema = convertStepsToIr(steps, metadata);
28
+ const generatedZodSource = await generateZodSchemasFromIr(irSchema, options);
29
+ return generatedZodSource;
30
+ }
31
+ //# sourceMappingURL=generateZodFromStepsSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateZodFromStepsSchema.js","names":["generateZodSchemasFromIr","convertStepsToIr","generateZodFromStepsSchema","steps","metadata","options","irSchema","generatedZodSource"],"sources":["generateZodFromStepsSchema.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 {\n generateZodSchemasFromIr,\n type ZodGeneratorOptions,\n} from \"../ir/generateZodSchemasFromIr.js\";\nimport { convertStepsToIr, type SchemaMetadata } from \"./convertStepsToIr.js\";\nimport type { MigrationStep } from \"./parseMigrationSteps.js\";\n\n/**\n * Generates Zod schemas from migration steps\n * @param steps - Array of migration steps\n * @param metadata - Optional schema metadata overrides\n * @param options - Optional generator options (e.g., typeImportPath for satisfies operators)\n * @returns Generated TypeScript code with Zod schemas\n */\nexport async function generateZodFromStepsSchema(\n steps: readonly MigrationStep[],\n metadata?: SchemaMetadata,\n options?: Pick<ZodGeneratorOptions, \"typeImportPath\">,\n): Promise<string> {\n const irSchema = convertStepsToIr(steps, metadata);\n const generatedZodSource = await generateZodSchemasFromIr(irSchema, options);\n return generatedZodSource;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,wBAAwB,QAEnB,mCAAmC;AAC1C,SAASC,gBAAgB,QAA6B,uBAAuB;AAG7E;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,0BAA0BA,CAC9CC,KAA+B,EAC/BC,QAAyB,EACzBC,OAAqD,EACpC;EACjB,MAAMC,QAAQ,GAAGL,gBAAgB,CAACE,KAAK,EAAEC,QAAQ,CAAC;EAClD,MAAMG,kBAAkB,GAAG,MAAMP,wBAAwB,CAACM,QAAQ,EAAED,OAAO,CAAC;EAC5E,OAAOE,kBAAkB;AAC3B","ignoreList":[]}
@@ -0,0 +1,84 @@
1
+ /*
2
+ * Copyright 2025 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 z from "zod";
18
+
19
+ // Type definitions for the migration steps
20
+ // Note: These match the YAML syntax, not the P.Type objects
21
+ // Only "string" and "double" are valid primitives in P.TypeKind
22
+
23
+ // RecordFieldDefinition represents the YAML field values
24
+ // Can be: "string", "double", "optional<T>", "list<T>", "ObjectNode", or a complex definition
25
+
26
+ // Define allowed primitive types (matching TypeKind from document-schema-api)
27
+ const primitiveType = z.enum(["string", "double"]);
28
+
29
+ // Define generic type patterns like "optional<T>", "list<T>", "array<T>"
30
+ const genericTypePattern = z.string().regex(/^(optional|list|array|set|map)<[^<>]+>$/, {
31
+ message: "Invalid generic type pattern"
32
+ });
33
+
34
+ // Reference to other record/union types (capitalized names)
35
+ const typeReference = z.string().regex(/^[A-Z][a-zA-Z0-9]*$/, {
36
+ message: "Type references must be capitalized"
37
+ });
38
+ const basicType = z.union([primitiveType, genericTypePattern]);
39
+
40
+ // Complex field definition object (for future extensibility)
41
+ const complexFieldDefinition = z.object({
42
+ type: basicType,
43
+ docs: z.string().optional()
44
+ // This can be extended with e.g. constraints like min/max value or length, in the future
45
+ });
46
+
47
+ // Union of all allowed field definition types - more specific than just z.string()
48
+ const recordFieldDefinition = z.union([primitiveType, genericTypePattern, typeReference, complexFieldDefinition]);
49
+
50
+ // Keep as simple strings for now to maintain compatibility with existing code
51
+ const recordFieldKey = z.string(); // TODO: could be improved w/ regex if we want to control format
52
+ const fragmentKey = z.string();
53
+ const localFragment = z.record(fragmentKey, z.record(recordFieldKey, recordFieldDefinition));
54
+ const addRecords = z.record(z.string().regex(/^[A-Z][a-zA-Z0-9]*$/),
55
+ // Keys must be capitalized type names
56
+ z.object({
57
+ docs: z.optional(z.string()),
58
+ extends: z.array(z.string()).optional(),
59
+ fields: z.record(recordFieldKey, recordFieldDefinition)
60
+ }));
61
+
62
+ // e.g. { "Optional": { "of": "Something", "empty": "Nothing" } }
63
+ // TODO: could have a stronger type for key here.
64
+ const addUnion = z.record(z.string().regex(/^[A-Z][a-zA-Z0-9]*$/),
65
+ // Union names must be capitalized
66
+ z.record(z.string(), z.string().regex(/^[A-Z][a-zA-Z0-9]*$/)) // Values are type references
67
+ );
68
+ const modifyRecords = z.record(z.string().regex(/^[A-Z][a-zA-Z0-9]*$/),
69
+ // Record names must be capitalized
70
+ z.object({
71
+ "add-fields": z.record(recordFieldKey, recordFieldDefinition)
72
+ }));
73
+ const migrationStep = z.object({
74
+ "local-fragment": z.optional(localFragment),
75
+ "add-records": z.optional(addRecords),
76
+ "add-union": z.optional(addUnion),
77
+ "modify-records": z.optional(modifyRecords)
78
+ });
79
+ const migrationStepsSchema = z.array(migrationStep);
80
+ export function parseMigrationSteps(unparsed) {
81
+ const parsed = migrationStepsSchema.parse(unparsed);
82
+ return parsed;
83
+ }
84
+ //# sourceMappingURL=parseMigrationSteps.js.map