@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
package/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2025 Palantir Technologies, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # @pack/document-schema-type-gen
2
+
3
+ TypeScript type generation from document schema definitions. This package provides CLI tools and programmatic APIs for generating TypeScript types and Zod schemas from document schema definitions in both IR (Intermediate Representation) and YAML migration steps formats.
4
+
5
+ ## CLI Usage
6
+
7
+ ### Available Commands
8
+
9
+ ```
10
+ Usage: document-schema-type-gen [options] [command]
11
+
12
+ Document schema type generation CLI
13
+
14
+ Options:
15
+ -V, --version output the version number
16
+ -h, --help display help for command
17
+
18
+ Commands:
19
+ ir IR (Intermediate Representation) based generation commands
20
+ schema Commands for working with TypeScript schema definitions
21
+ steps Commands dealing with migration steps and type generation
22
+ help [command] display help for command
23
+ ```
24
+
25
+ #### Steps Commands
26
+
27
+ Generate types and schemas from YAML migration steps:
28
+
29
+ ```bash
30
+ # Generate TypeScript types from YAML migration steps
31
+ type-gen steps types -i <yaml-folder> -o <output-file>
32
+
33
+ # Convert YAML migration steps to IR format
34
+ type-gen steps ir -i <input.yaml> -o <output.json> [options]
35
+ Options:
36
+ -n, --schema-name <name> Override schema name (default: "Generated Schema")
37
+ -d, --schema-description <desc> Override schema description (default: "Schema generated from migration steps")
38
+ -v, --version <version> Schema version (default: "1")
39
+
40
+ # Generate Zod schemas from YAML migration steps
41
+ type-gen steps zod -i <input.yaml> -o <output.ts>
42
+
43
+ # Generate Model constants from YAML migration steps
44
+ type-gen steps models -i <input.yaml> -o <output.ts>
45
+ ```
46
+
47
+ #### IR Commands
48
+
49
+ Generate schemas from Intermediate Representation format:
50
+
51
+ ```bash
52
+ # Generate Zod schemas from IR format
53
+ type-gen ir zod -s <schema.json> -r <records.json> -o <output.ts>
54
+ ```
55
+
56
+ ### Examples
57
+
58
+ #### Generating TypeScript Types from YAML
59
+
60
+ Given a directory with YAML migration step files:
61
+
62
+ ```yaml
63
+ # 001-initial.yaml
64
+ - local-fragment:
65
+ position:
66
+ x: double
67
+ y: double
68
+
69
+ - add-records:
70
+ Node:
71
+ docs: "A node in the graph"
72
+ extends: [position]
73
+ fields:
74
+ label: optional<string>
75
+ edges: list<Edge>
76
+
77
+ - add-union:
78
+ NodeType:
79
+ standard: Node
80
+ special: SpecialNode
81
+ ```
82
+
83
+ Run:
84
+
85
+ ```bash
86
+ type-gen steps types -i ./schemas -o ./generated/types.ts
87
+ ```
88
+
89
+ This generates TypeScript interfaces for all defined records and unions.
90
+
91
+ #### Converting YAML to IR Format
92
+
93
+ ```bash
94
+ type-gen steps ir \
95
+ -i ./schema.yaml \
96
+ -o ./schema-ir.json \
97
+ -n "MySchema" \
98
+ -d "Application document schema" \
99
+ -v "2.0"
100
+ ```
101
+
102
+ #### Generating Zod Schemas
103
+
104
+ From YAML:
105
+
106
+ ```bash
107
+ type-gen steps zod -i ./schema.yaml -o ./generated/zod-schemas.ts
108
+ ```
109
+
110
+ From IR:
111
+
112
+ ```bash
113
+ type-gen ir zod -s ./schema.json -r ./records.json -o ./generated/zod-schemas.ts
114
+ ```
115
+
116
+ ## Programmatic API
117
+
118
+ All CLI commands and their handlers are exported for composition in other tools and libraries.
119
+
120
+ ### Command Registration
121
+
122
+ Register commands in your own CLI:
123
+
124
+ ```typescript
125
+ import {
126
+ registerIrCommands,
127
+ registerStepsCommands,
128
+ } from "@pack/document-schema-type-gen";
129
+ import { Command } from "commander";
130
+
131
+ const program = new Command();
132
+
133
+ // Register IR-based commands
134
+ registerIrCommands(program);
135
+
136
+ // Register steps-based commands
137
+ registerStepsCommands(program);
138
+
139
+ program.parse();
140
+ ```
141
+
142
+ ### Direct Handler Usage
143
+
144
+ Use command handlers directly in your code:
145
+
146
+ ```typescript
147
+ import {
148
+ convertSchemaToIr,
149
+ convertStepsToIr,
150
+ generateTypesFromSchema,
151
+ generateZodFromSchema,
152
+ generateZodSchemasFromIr,
153
+ } from "@pack/document-schema-type-gen";
154
+
155
+ // Generate TypeScript types from a schema object
156
+ const schema = {/* your schema definition */};
157
+ const typesCode = generateTypesFromSchema(schema);
158
+
159
+ // Generate Zod schemas from migration steps
160
+ const zodCode = generateZodFromSchema(schema);
161
+
162
+ // Convert migration steps to IR format
163
+ const irSchema = convertStepsToIr(steps, metadata);
164
+
165
+ // Generate Zod from IR
166
+ const zodFromIr = await generateZodSchemasFromIr(irSchema);
167
+ ```
168
+
169
+ ### Utility Functions
170
+
171
+ The package exports several utility functions for schema processing:
172
+
173
+ ```typescript
174
+ import {
175
+ convertRecordDefToIr,
176
+ convertSchemaToIr,
177
+ convertTypeToFieldTypeUnion,
178
+ generateZodFromStepsSchema,
179
+ type SchemaMetadata,
180
+ } from "@pack/document-schema-type-gen";
181
+
182
+ // Convert PACK types to field type unions
183
+ const fieldType = convertTypeToFieldTypeUnion(type);
184
+
185
+ // Convert record definitions to IR format
186
+ const irRecord = convertRecordDefToIr(recordDef);
187
+
188
+ // Generate Zod schemas from steps with custom metadata
189
+ const metadata: SchemaMetadata = {
190
+ name: "MySchema",
191
+ description: "Custom schema",
192
+ version: "1.0.0",
193
+ };
194
+ const zodSchemas = generateZodFromStepsSchema(steps, metadata);
195
+ ```
196
+
197
+ ### Building a Custom CLI
198
+
199
+ ```typescript
200
+ import { cli } from "@pack/document-schema-type-gen";
201
+
202
+ // Use the built-in CLI with custom arguments
203
+ cli(process.argv);
204
+
205
+ // Or build your own CLI using the exported handlers
206
+ import { stepsGenTypesHandler } from "@pack/document-schema-type-gen";
207
+ import { Command } from "commander";
208
+
209
+ const program = new Command();
210
+
211
+ program
212
+ .command("generate-types")
213
+ .requiredOption("-i, --input <folder>", "Input folder")
214
+ .requiredOption("-o, --output <file>", "Output file")
215
+ .action(stepsGenTypesHandler);
216
+
217
+ program.parse();
218
+ ```
219
+
220
+ ## Supported Field Types
221
+
222
+ The type generator supports the following field types in YAML:
223
+
224
+ - Basic types: `string`, `double`, `boolean`
225
+ - Collections: `array<T>`, `list<T>`, `set<T>`
226
+ - Optional types: `optional<T>`
227
+ - References to other defined records
228
+ - Nested structures via record extension
229
+
230
+ ## Migration Steps Format
231
+
232
+ The YAML migration steps support these operations:
233
+
234
+ - `local-fragment`: Define reusable field groups
235
+ - `add-records`: Add new record types with fields
236
+ - `add-union`: Define discriminated unions
237
+ - `modify-records`: Modify existing record definitions
package/bin/cli.ts ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env -S npx bun@1.3.0
2
+
3
+ // We run the CLI using tsx so certain commands can import ts files and take
4
+ // advantage of the ts loader. We use the built version for packaging reasons.
5
+ import { cli } from "../build/esm/index.js";
6
+ cli(process.argv);
@@ -0,0 +1,29 @@
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 { Command } from "commander";
18
+ import { registerIrCommands } from "./commands/ir/registerIrCommands.js";
19
+ import { registerSchemaCommands } from "./commands/schema/registerSchemaCommands.js";
20
+ import { registerStepsCommands } from "./commands/steps/registerStepsCommands.js";
21
+ export function cli(args) {
22
+ const program = new Command();
23
+ program.name("document-schema-type-gen").description("Document schema type generation CLI").version("0.0.1");
24
+ registerIrCommands(program);
25
+ registerSchemaCommands(program);
26
+ registerStepsCommands(program);
27
+ program.parse(args);
28
+ }
29
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","names":["Command","registerIrCommands","registerSchemaCommands","registerStepsCommands","cli","args","program","name","description","version","parse"],"sources":["cli.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 { Command } from \"commander\";\nimport { registerIrCommands } from \"./commands/ir/registerIrCommands.js\";\nimport { registerSchemaCommands } from \"./commands/schema/registerSchemaCommands.js\";\nimport { registerStepsCommands } from \"./commands/steps/registerStepsCommands.js\";\n\nexport function cli(args: string[]): void {\n const program = new Command();\n\n program\n .name(\"document-schema-type-gen\")\n .description(\"Document schema type generation CLI\")\n .version(\"0.0.1\");\n\n registerIrCommands(program);\n registerSchemaCommands(program);\n registerStepsCommands(program);\n\n program.parse(args);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,QAAQ,WAAW;AACnC,SAASC,kBAAkB,QAAQ,qCAAqC;AACxE,SAASC,sBAAsB,QAAQ,6CAA6C;AACpF,SAASC,qBAAqB,QAAQ,2CAA2C;AAEjF,OAAO,SAASC,GAAGA,CAACC,IAAc,EAAQ;EACxC,MAAMC,OAAO,GAAG,IAAIN,OAAO,CAAC,CAAC;EAE7BM,OAAO,CACJC,IAAI,CAAC,0BAA0B,CAAC,CAChCC,WAAW,CAAC,qCAAqC,CAAC,CAClDC,OAAO,CAAC,OAAO,CAAC;EAEnBR,kBAAkB,CAACK,OAAO,CAAC;EAC3BJ,sBAAsB,CAACI,OAAO,CAAC;EAC/BH,qBAAqB,CAACG,OAAO,CAAC;EAE9BA,OAAO,CAACI,KAAK,CAACL,IAAI,CAAC;AACrB","ignoreList":[]}
@@ -0,0 +1,45 @@
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 { createPlatformClient } from "@osdk/client";
18
+ import { DocumentTypes } from "@osdk/foundry.pack";
19
+ import { CommanderError } from "commander";
20
+ import { consola } from "consola";
21
+ import { readFileSync } from "fs";
22
+ import { resolve } from "path";
23
+ export async function irDeployHandler(options) {
24
+ try {
25
+ const irPath = resolve(options.ir);
26
+ consola.info(`Reading schema from: ${irPath}`);
27
+ const irContent = readFileSync(irPath, "utf8");
28
+
29
+ // TODO: conjureToZod based validation that IR content matches the conjure IR shape
30
+ const ir = JSON.parse(irContent);
31
+ const osdkClient = createPlatformClient(options.baseUrl, () => Promise.resolve(options.auth));
32
+ const request = {
33
+ name: ir.name,
34
+ parentFolderRid: options.parentFolder
35
+ };
36
+
37
+ // PACK BE does not yet support storing schemas...
38
+ consola.warn("Creating document type without schema information", request);
39
+ await DocumentTypes.create(osdkClient, request);
40
+ } catch (error) {
41
+ consola.error("❌ Error during Deploy:", error);
42
+ throw new CommanderError(1, "ERRIRMDEPLOY", "Error deploying IR document schema");
43
+ }
44
+ }
45
+ //# sourceMappingURL=irDeployHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"irDeployHandler.js","names":["createPlatformClient","DocumentTypes","CommanderError","consola","readFileSync","resolve","irDeployHandler","options","irPath","ir","info","irContent","JSON","parse","osdkClient","baseUrl","Promise","auth","request","name","parentFolderRid","parentFolder","warn","create","error"],"sources":["irDeployHandler.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 { createPlatformClient } from \"@osdk/client\";\nimport type { CreateDocumentTypeRequest } from \"@osdk/foundry.pack\";\nimport { DocumentTypes } from \"@osdk/foundry.pack\";\nimport type { IRealTimeDocumentSchema } from \"@palantir/pack-docschema-api/pack-docschema-ir\";\nimport { CommanderError } from \"commander\";\nimport { consola } from \"consola\";\nimport { readFileSync } from \"fs\";\nimport { resolve } from \"path\";\n\ninterface DeployOptions {\n readonly ir: string;\n readonly baseUrl: string;\n readonly auth: string;\n readonly parentFolder: string;\n}\n\nexport async function irDeployHandler(options: DeployOptions): Promise<void> {\n try {\n const irPath = resolve(options.ir);\n\n consola.info(`Reading schema from: ${irPath}`);\n\n const irContent = readFileSync(irPath, \"utf8\");\n\n // TODO: conjureToZod based validation that IR content matches the conjure IR shape\n const ir = JSON.parse(irContent) as IRealTimeDocumentSchema;\n\n const osdkClient = createPlatformClient(\n options.baseUrl,\n () => Promise.resolve(options.auth),\n );\n\n const request: CreateDocumentTypeRequest = {\n name: ir.name,\n parentFolderRid: options.parentFolder,\n };\n\n // PACK BE does not yet support storing schemas...\n consola.warn(\"Creating document type without schema information\", request);\n\n await DocumentTypes.create(osdkClient, request);\n } catch (error) {\n consola.error(\"❌ Error during Deploy:\", error);\n throw new CommanderError(1, \"ERRIRMDEPLOY\", \"Error deploying IR document schema\");\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,oBAAoB,QAAQ,cAAc;AAEnD,SAASC,aAAa,QAAQ,oBAAoB;AAElD,SAASC,cAAc,QAAQ,WAAW;AAC1C,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,YAAY,QAAQ,IAAI;AACjC,SAASC,OAAO,QAAQ,MAAM;AAS9B,OAAO,eAAeC,eAAeA,CAACC,OAAsB,EAAiB;EAC3E,IAAI;IACF,MAAMC,MAAM,GAAGH,OAAO,CAACE,OAAO,CAACE,EAAE,CAAC;IAElCN,OAAO,CAACO,IAAI,CAAC,wBAAwBF,MAAM,EAAE,CAAC;IAE9C,MAAMG,SAAS,GAAGP,YAAY,CAACI,MAAM,EAAE,MAAM,CAAC;;IAE9C;IACA,MAAMC,EAAE,GAAGG,IAAI,CAACC,KAAK,CAACF,SAAS,CAA4B;IAE3D,MAAMG,UAAU,GAAGd,oBAAoB,CACrCO,OAAO,CAACQ,OAAO,EACf,MAAMC,OAAO,CAACX,OAAO,CAACE,OAAO,CAACU,IAAI,CACpC,CAAC;IAED,MAAMC,OAAkC,GAAG;MACzCC,IAAI,EAAEV,EAAE,CAACU,IAAI;MACbC,eAAe,EAAEb,OAAO,CAACc;IAC3B,CAAC;;IAED;IACAlB,OAAO,CAACmB,IAAI,CAAC,mDAAmD,EAAEJ,OAAO,CAAC;IAE1E,MAAMjB,aAAa,CAACsB,MAAM,CAACT,UAAU,EAAEI,OAAO,CAAC;EACjD,CAAC,CAAC,OAAOM,KAAK,EAAE;IACdrB,OAAO,CAACqB,KAAK,CAAC,wBAAwB,EAAEA,KAAK,CAAC;IAC9C,MAAM,IAAItB,cAAc,CAAC,CAAC,EAAE,cAAc,EAAE,oCAAoC,CAAC;EACnF;AACF","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 { CommanderError } from "commander";
18
+ import { consola } from "consola";
19
+ import { readFileSync, writeFileSync } from "fs";
20
+ import { resolve } from "path";
21
+ import { generateModelsFromIr } from "../../utils/ir/generateModelsFromIr.js";
22
+ export async function irGenModelsHandler(options) {
23
+ try {
24
+ const schemaPath = resolve(options.schema);
25
+ const outputPath = resolve(options.output);
26
+ consola.info(`Reading schema from: ${schemaPath}`);
27
+ const schemaContent = readFileSync(schemaPath, "utf8");
28
+
29
+ // TODO: conjureToZod based validation matches conjure ir
30
+ const schema = JSON.parse(schemaContent);
31
+ consola.info(`Generating Model constants for ${schema.primaryModelKeys.length} model(s)...`);
32
+ const generatedCode = await generateModelsFromIr(schema, {
33
+ typeImportPath: options.typeImportPath,
34
+ schemaImportPath: options.schemaImportPath
35
+ });
36
+ consola.info(`Writing generated Model constants to: ${outputPath}`);
37
+ writeFileSync(outputPath, generatedCode, "utf8");
38
+ consola.success("✅ Model constants generation completed successfully");
39
+ } catch (error) {
40
+ consola.error("❌ Error during Model constants generation:", error);
41
+ throw new CommanderError(1, "ERRIRMODELS", "Error generating Model constants");
42
+ }
43
+ }
44
+ //# sourceMappingURL=irGenModelsHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"irGenModelsHandler.js","names":["CommanderError","consola","readFileSync","writeFileSync","resolve","generateModelsFromIr","irGenModelsHandler","options","schemaPath","schema","outputPath","output","info","schemaContent","JSON","parse","primaryModelKeys","length","generatedCode","typeImportPath","schemaImportPath","success","error"],"sources":["irGenModelsHandler.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 { IRealTimeDocumentSchema } from \"@palantir/pack-docschema-api/pack-docschema-ir\";\nimport { CommanderError } from \"commander\";\nimport { consola } from \"consola\";\nimport { readFileSync, writeFileSync } from \"fs\";\nimport { resolve } from \"path\";\nimport { generateModelsFromIr } from \"../../utils/ir/generateModelsFromIr.js\";\n\ninterface ModelsGenOptions {\n readonly schema: string;\n readonly output: string;\n readonly typeImportPath?: string;\n readonly schemaImportPath?: string;\n}\n\nexport async function irGenModelsHandler(options: ModelsGenOptions): Promise<void> {\n try {\n const schemaPath = resolve(options.schema);\n const outputPath = resolve(options.output);\n\n consola.info(`Reading schema from: ${schemaPath}`);\n\n const schemaContent = readFileSync(schemaPath, \"utf8\");\n\n // TODO: conjureToZod based validation matches conjure ir\n const schema = JSON.parse(schemaContent) as IRealTimeDocumentSchema;\n\n consola.info(`Generating Model constants for ${schema.primaryModelKeys.length} model(s)...`);\n\n const generatedCode = await generateModelsFromIr(schema, {\n typeImportPath: options.typeImportPath,\n schemaImportPath: options.schemaImportPath,\n });\n\n consola.info(`Writing generated Model constants to: ${outputPath}`);\n writeFileSync(outputPath, generatedCode, \"utf8\");\n\n consola.success(\"✅ Model constants generation completed successfully\");\n } catch (error) {\n consola.error(\"❌ Error during Model constants generation:\", error);\n throw new CommanderError(1, \"ERRIRMODELS\", \"Error generating Model constants\");\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,cAAc,QAAQ,WAAW;AAC1C,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,YAAY,EAAEC,aAAa,QAAQ,IAAI;AAChD,SAASC,OAAO,QAAQ,MAAM;AAC9B,SAASC,oBAAoB,QAAQ,wCAAwC;AAS7E,OAAO,eAAeC,kBAAkBA,CAACC,OAAyB,EAAiB;EACjF,IAAI;IACF,MAAMC,UAAU,GAAGJ,OAAO,CAACG,OAAO,CAACE,MAAM,CAAC;IAC1C,MAAMC,UAAU,GAAGN,OAAO,CAACG,OAAO,CAACI,MAAM,CAAC;IAE1CV,OAAO,CAACW,IAAI,CAAC,wBAAwBJ,UAAU,EAAE,CAAC;IAElD,MAAMK,aAAa,GAAGX,YAAY,CAACM,UAAU,EAAE,MAAM,CAAC;;IAEtD;IACA,MAAMC,MAAM,GAAGK,IAAI,CAACC,KAAK,CAACF,aAAa,CAA4B;IAEnEZ,OAAO,CAACW,IAAI,CAAC,kCAAkCH,MAAM,CAACO,gBAAgB,CAACC,MAAM,cAAc,CAAC;IAE5F,MAAMC,aAAa,GAAG,MAAMb,oBAAoB,CAACI,MAAM,EAAE;MACvDU,cAAc,EAAEZ,OAAO,CAACY,cAAc;MACtCC,gBAAgB,EAAEb,OAAO,CAACa;IAC5B,CAAC,CAAC;IAEFnB,OAAO,CAACW,IAAI,CAAC,yCAAyCF,UAAU,EAAE,CAAC;IACnEP,aAAa,CAACO,UAAU,EAAEQ,aAAa,EAAE,MAAM,CAAC;IAEhDjB,OAAO,CAACoB,OAAO,CAAC,qDAAqD,CAAC;EACxE,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdrB,OAAO,CAACqB,KAAK,CAAC,4CAA4C,EAAEA,KAAK,CAAC;IAClE,MAAM,IAAItB,cAAc,CAAC,CAAC,EAAE,aAAa,EAAE,kCAAkC,CAAC;EAChF;AACF","ignoreList":[]}
@@ -0,0 +1,43 @@
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 { CommanderError } from "commander";
18
+ import { consola } from "consola";
19
+ import { readFileSync, writeFileSync } from "fs";
20
+ import { resolve } from "path";
21
+ import { generateZodSchemasFromIr } from "../../utils/ir/generateZodSchemasFromIr.js";
22
+ export async function irGenZodHandler(options) {
23
+ try {
24
+ const schemaPath = resolve(options.schema);
25
+ const outputPath = resolve(options.output);
26
+ consola.info(`Reading schema from: ${schemaPath}`);
27
+ const schemaContent = readFileSync(schemaPath, "utf8");
28
+
29
+ // TODO: conjureToZod based validation matches conjure ir
30
+ const schema = JSON.parse(schemaContent);
31
+ consola.info(`Generating Zod schemas for ${schema.primaryModelKeys.length} model(s)...`);
32
+ const generatedCode = await generateZodSchemasFromIr(schema, {
33
+ typeImportPath: options.typeImportPath
34
+ });
35
+ consola.info(`Writing generated Zod schemas to: ${outputPath}`);
36
+ writeFileSync(outputPath, generatedCode, "utf8");
37
+ consola.success("✅ Zod schema generation completed successfully");
38
+ } catch (error) {
39
+ consola.error("❌ Error during Zod schema generation:", error);
40
+ throw new CommanderError(1, "ERRIRZOD", "Error generating Zod schemas");
41
+ }
42
+ }
43
+ //# sourceMappingURL=irGenZodHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"irGenZodHandler.js","names":["CommanderError","consola","readFileSync","writeFileSync","resolve","generateZodSchemasFromIr","irGenZodHandler","options","schemaPath","schema","outputPath","output","info","schemaContent","JSON","parse","primaryModelKeys","length","generatedCode","typeImportPath","success","error"],"sources":["irGenZodHandler.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 { IRealTimeDocumentSchema } from \"@palantir/pack-docschema-api/pack-docschema-ir\";\nimport { CommanderError } from \"commander\";\nimport { consola } from \"consola\";\nimport { readFileSync, writeFileSync } from \"fs\";\nimport { resolve } from \"path\";\nimport { generateZodSchemasFromIr } from \"../../utils/ir/generateZodSchemasFromIr.js\";\n\ninterface ZodGenOptions {\n readonly schema: string;\n readonly output: string;\n readonly typeImportPath?: string;\n}\n\nexport async function irGenZodHandler(options: ZodGenOptions): Promise<void> {\n try {\n const schemaPath = resolve(options.schema);\n const outputPath = resolve(options.output);\n\n consola.info(`Reading schema from: ${schemaPath}`);\n\n const schemaContent = readFileSync(schemaPath, \"utf8\");\n\n // TODO: conjureToZod based validation matches conjure ir\n const schema = JSON.parse(schemaContent) as IRealTimeDocumentSchema;\n\n consola.info(`Generating Zod schemas for ${schema.primaryModelKeys.length} model(s)...`);\n\n const generatedCode = await generateZodSchemasFromIr(schema, {\n typeImportPath: options.typeImportPath,\n });\n\n consola.info(`Writing generated Zod schemas to: ${outputPath}`);\n writeFileSync(outputPath, generatedCode, \"utf8\");\n\n consola.success(\"✅ Zod schema generation completed successfully\");\n } catch (error) {\n consola.error(\"❌ Error during Zod schema generation:\", error);\n throw new CommanderError(1, \"ERRIRZOD\", \"Error generating Zod schemas\");\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,cAAc,QAAQ,WAAW;AAC1C,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,YAAY,EAAEC,aAAa,QAAQ,IAAI;AAChD,SAASC,OAAO,QAAQ,MAAM;AAC9B,SAASC,wBAAwB,QAAQ,4CAA4C;AAQrF,OAAO,eAAeC,eAAeA,CAACC,OAAsB,EAAiB;EAC3E,IAAI;IACF,MAAMC,UAAU,GAAGJ,OAAO,CAACG,OAAO,CAACE,MAAM,CAAC;IAC1C,MAAMC,UAAU,GAAGN,OAAO,CAACG,OAAO,CAACI,MAAM,CAAC;IAE1CV,OAAO,CAACW,IAAI,CAAC,wBAAwBJ,UAAU,EAAE,CAAC;IAElD,MAAMK,aAAa,GAAGX,YAAY,CAACM,UAAU,EAAE,MAAM,CAAC;;IAEtD;IACA,MAAMC,MAAM,GAAGK,IAAI,CAACC,KAAK,CAACF,aAAa,CAA4B;IAEnEZ,OAAO,CAACW,IAAI,CAAC,8BAA8BH,MAAM,CAACO,gBAAgB,CAACC,MAAM,cAAc,CAAC;IAExF,MAAMC,aAAa,GAAG,MAAMb,wBAAwB,CAACI,MAAM,EAAE;MAC3DU,cAAc,EAAEZ,OAAO,CAACY;IAC1B,CAAC,CAAC;IAEFlB,OAAO,CAACW,IAAI,CAAC,qCAAqCF,UAAU,EAAE,CAAC;IAC/DP,aAAa,CAACO,UAAU,EAAEQ,aAAa,EAAE,MAAM,CAAC;IAEhDjB,OAAO,CAACmB,OAAO,CAAC,gDAAgD,CAAC;EACnE,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdpB,OAAO,CAACoB,KAAK,CAAC,uCAAuC,EAAEA,KAAK,CAAC;IAC7D,MAAM,IAAIrB,cAAc,CAAC,CAAC,EAAE,UAAU,EAAE,8BAA8B,CAAC;EACzE;AACF","ignoreList":[]}
@@ -0,0 +1,26 @@
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 { irDeployHandler } from "./irDeployHandler.js";
18
+ import { irGenModelsHandler } from "./irGenModelsHandler.js";
19
+ import { irGenZodHandler } from "./irGenZodHandler.js";
20
+ export function registerIrCommands(program) {
21
+ const irCmd = program.command("ir").description("IR (Intermediate Representation) based generation commands");
22
+ irCmd.command("zod").description("Generate Zod schemas from IR document schema definitions").requiredOption("-s, --schema <file>", "Path to schema JSON file").requiredOption("-o, --output <file>", "Output file path for generated Zod schemas").option("-t, --type-import-path <path>", "Path to import types from (enables satisfies operators)").action(irGenZodHandler);
23
+ irCmd.command("models").description("Generate Model constants from IR document schema definitions").requiredOption("-s, --schema <file>", "Path to schema JSON file").requiredOption("-o, --output <file>", "Output file path for generated Model constants").option("-t, --type-import-path <path>", "Path to import types from", "./types.js").option("--schema-import-path <path>", "Path to import schemas from", "./schema.js").action(irGenModelsHandler);
24
+ irCmd.command("deploy").description("Create a document type on a Foundry stack using an IR document schema").requiredOption("-i, --ir <file>", "Path to IR JSON file").requiredOption("-b, --base-url <url>", "Base URL for Foundry API").requiredOption("-a, --auth <token>", "Authentication token for Foundry API").requiredOption("-p, --parent-folder <rid>", "Parent folder RID for the document type").action(irDeployHandler);
25
+ }
26
+ //# sourceMappingURL=registerIrCommands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerIrCommands.js","names":["irDeployHandler","irGenModelsHandler","irGenZodHandler","registerIrCommands","program","irCmd","command","description","requiredOption","option","action"],"sources":["registerIrCommands.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 { Command } from \"commander\";\nimport { irDeployHandler } from \"./irDeployHandler.js\";\nimport { irGenModelsHandler } from \"./irGenModelsHandler.js\";\nimport { irGenZodHandler } from \"./irGenZodHandler.js\";\n\nexport function registerIrCommands(program: Command): void {\n const irCmd = program\n .command(\"ir\")\n .description(\"IR (Intermediate Representation) based generation commands\");\n\n irCmd\n .command(\"zod\")\n .description(\"Generate Zod schemas from IR document schema definitions\")\n .requiredOption(\"-s, --schema <file>\", \"Path to schema JSON file\")\n .requiredOption(\"-o, --output <file>\", \"Output file path for generated Zod schemas\")\n .option(\n \"-t, --type-import-path <path>\",\n \"Path to import types from (enables satisfies operators)\",\n )\n .action(irGenZodHandler);\n\n irCmd\n .command(\"models\")\n .description(\"Generate Model constants from IR document schema definitions\")\n .requiredOption(\"-s, --schema <file>\", \"Path to schema JSON file\")\n .requiredOption(\"-o, --output <file>\", \"Output file path for generated Model constants\")\n .option(\n \"-t, --type-import-path <path>\",\n \"Path to import types from\",\n \"./types.js\",\n )\n .option(\n \"--schema-import-path <path>\",\n \"Path to import schemas from\",\n \"./schema.js\",\n )\n .action(irGenModelsHandler);\n\n irCmd\n .command(\"deploy\")\n .description(\"Create a document type on a Foundry stack using an IR document schema\")\n .requiredOption(\"-i, --ir <file>\", \"Path to IR JSON file\")\n .requiredOption(\"-b, --base-url <url>\", \"Base URL for Foundry API\")\n .requiredOption(\"-a, --auth <token>\", \"Authentication token for Foundry API\")\n .requiredOption(\"-p, --parent-folder <rid>\", \"Parent folder RID for the document type\")\n .action(irDeployHandler);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,eAAe,QAAQ,sBAAsB;AACtD,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,eAAe,QAAQ,sBAAsB;AAEtD,OAAO,SAASC,kBAAkBA,CAACC,OAAgB,EAAQ;EACzD,MAAMC,KAAK,GAAGD,OAAO,CAClBE,OAAO,CAAC,IAAI,CAAC,CACbC,WAAW,CAAC,4DAA4D,CAAC;EAE5EF,KAAK,CACFC,OAAO,CAAC,KAAK,CAAC,CACdC,WAAW,CAAC,0DAA0D,CAAC,CACvEC,cAAc,CAAC,qBAAqB,EAAE,0BAA0B,CAAC,CACjEA,cAAc,CAAC,qBAAqB,EAAE,4CAA4C,CAAC,CACnFC,MAAM,CACL,+BAA+B,EAC/B,yDACF,CAAC,CACAC,MAAM,CAACR,eAAe,CAAC;EAE1BG,KAAK,CACFC,OAAO,CAAC,QAAQ,CAAC,CACjBC,WAAW,CAAC,8DAA8D,CAAC,CAC3EC,cAAc,CAAC,qBAAqB,EAAE,0BAA0B,CAAC,CACjEA,cAAc,CAAC,qBAAqB,EAAE,gDAAgD,CAAC,CACvFC,MAAM,CACL,+BAA+B,EAC/B,2BAA2B,EAC3B,YACF,CAAC,CACAA,MAAM,CACL,6BAA6B,EAC7B,6BAA6B,EAC7B,aACF,CAAC,CACAC,MAAM,CAACT,kBAAkB,CAAC;EAE7BI,KAAK,CACFC,OAAO,CAAC,QAAQ,CAAC,CACjBC,WAAW,CAAC,uEAAuE,CAAC,CACpFC,cAAc,CAAC,iBAAiB,EAAE,sBAAsB,CAAC,CACzDA,cAAc,CAAC,sBAAsB,EAAE,0BAA0B,CAAC,CAClEA,cAAc,CAAC,oBAAoB,EAAE,sCAAsC,CAAC,CAC5EA,cAAc,CAAC,2BAA2B,EAAE,yCAAyC,CAAC,CACtFE,MAAM,CAACV,eAAe,CAAC;AAC5B","ignoreList":[]}
@@ -0,0 +1,102 @@
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 * as P from "@palantir/pack.schema";
18
+ import { describe, expect, it } from "vitest";
19
+ import yaml from "yaml";
20
+ import { convertSchemaToSteps, convertStepsToYamlString } from "../../../utils/schema/convertSchemaToSteps.js";
21
+ describe("Schema to YAML Integration", () => {
22
+ it("should convert schema to valid YAML format", () => {
23
+ const schema = P.defineMigration({}, () => {
24
+ const position = {
25
+ x: P.Double,
26
+ y: P.Double
27
+ };
28
+ const ObjectNode = P.defineRecord("ObjectNode", {
29
+ docs: "A node in the graph",
30
+ fields: {
31
+ ...position,
32
+ label: P.Optional(P.String)
33
+ }
34
+ });
35
+ const TextBox = P.defineRecord("TextBox", {
36
+ docs: "A text box",
37
+ fields: {
38
+ ...position,
39
+ text: P.String
40
+ }
41
+ });
42
+ const Edge = P.defineRecord("Edge", {
43
+ docs: "An edge between nodes",
44
+ fields: {
45
+ source: () => ObjectNode,
46
+ target: () => ObjectNode
47
+ }
48
+ });
49
+ const Node = P.defineUnion("Node", {
50
+ docs: "Any node type",
51
+ variants: {
52
+ object: ObjectNode,
53
+ textBox: TextBox
54
+ }
55
+ });
56
+ return {
57
+ ObjectNode,
58
+ TextBox,
59
+ Edge,
60
+ Node
61
+ };
62
+ });
63
+ const steps = convertSchemaToSteps(schema);
64
+ const yamlString = convertStepsToYamlString(steps);
65
+ const parsedSteps = yaml.parse(yamlString);
66
+ expect(parsedSteps).toBeInstanceOf(Array);
67
+ expect(parsedSteps.length).toBeGreaterThan(0);
68
+ const recordsStep = parsedSteps.find(step => "add-records" in step);
69
+ expect(recordsStep).toBeDefined();
70
+ expect(recordsStep?.["add-records"]).toMatchObject({
71
+ ObjectNode: {
72
+ fields: {
73
+ x: "double",
74
+ y: "double",
75
+ label: "optional<string>"
76
+ }
77
+ },
78
+ TextBox: {
79
+ fields: {
80
+ x: "double",
81
+ y: "double",
82
+ text: "string"
83
+ }
84
+ },
85
+ Edge: {
86
+ fields: {
87
+ source: "ObjectNode",
88
+ target: "ObjectNode"
89
+ }
90
+ }
91
+ });
92
+ const unionStep = parsedSteps.find(step => "add-union" in step);
93
+ expect(unionStep).toBeDefined();
94
+ expect(unionStep?.["add-union"]).toMatchObject({
95
+ Node: {
96
+ object: "ObjectNode",
97
+ textBox: "TextBox"
98
+ }
99
+ });
100
+ });
101
+ });
102
+ //# sourceMappingURL=schemaToYaml.integration.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaToYaml.integration.test.js","names":["P","describe","expect","it","yaml","convertSchemaToSteps","convertStepsToYamlString","schema","defineMigration","position","x","Double","y","ObjectNode","defineRecord","docs","fields","label","Optional","String","TextBox","text","Edge","source","target","Node","defineUnion","variants","object","textBox","steps","yamlString","parsedSteps","parse","toBeInstanceOf","Array","length","toBeGreaterThan","recordsStep","find","step","toBeDefined","toMatchObject","unionStep"],"sources":["schemaToYaml.integration.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 * as P from \"@palantir/pack.schema\";\nimport { describe, expect, it } from \"vitest\";\nimport yaml from \"yaml\";\nimport {\n convertSchemaToSteps,\n convertStepsToYamlString,\n} from \"../../../utils/schema/convertSchemaToSteps.js\";\n\ndescribe(\"Schema to YAML Integration\", () => {\n it(\"should convert schema to valid YAML format\", () => {\n const schema = P.defineMigration({}, () => {\n const position = {\n x: P.Double,\n y: P.Double,\n };\n\n const ObjectNode = P.defineRecord(\"ObjectNode\", {\n docs: \"A node in the graph\",\n fields: {\n ...position,\n label: P.Optional(P.String),\n },\n });\n\n const TextBox = P.defineRecord(\"TextBox\", {\n docs: \"A text box\",\n fields: {\n ...position,\n text: P.String,\n },\n });\n\n const Edge = P.defineRecord(\"Edge\", {\n docs: \"An edge between nodes\",\n fields: {\n source: () => ObjectNode,\n target: () => ObjectNode,\n },\n });\n\n const Node = P.defineUnion(\"Node\", {\n docs: \"Any node type\",\n variants: {\n object: ObjectNode,\n textBox: TextBox,\n },\n });\n\n return { ObjectNode, TextBox, Edge, Node };\n });\n\n const steps = convertSchemaToSteps(schema);\n const yamlString = convertStepsToYamlString(steps);\n const parsedSteps = yaml.parse(yamlString) as Array<Record<string, unknown>>;\n\n expect(parsedSteps).toBeInstanceOf(Array);\n expect(parsedSteps.length).toBeGreaterThan(0);\n\n const recordsStep = parsedSteps.find(step => \"add-records\" in step);\n expect(recordsStep).toBeDefined();\n expect(recordsStep?.[\"add-records\"]).toMatchObject({\n ObjectNode: {\n fields: {\n x: \"double\",\n y: \"double\",\n label: \"optional<string>\",\n },\n },\n TextBox: {\n fields: {\n x: \"double\",\n y: \"double\",\n text: \"string\",\n },\n },\n Edge: {\n fields: {\n source: \"ObjectNode\",\n target: \"ObjectNode\",\n },\n },\n });\n\n const unionStep = parsedSteps.find(step => \"add-union\" in step);\n expect(unionStep).toBeDefined();\n expect(unionStep?.[\"add-union\"]).toMatchObject({\n Node: {\n object: \"ObjectNode\",\n textBox: \"TextBox\",\n },\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,CAAC,MAAM,uBAAuB;AAC1C,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,OAAOC,IAAI,MAAM,MAAM;AACvB,SACEC,oBAAoB,EACpBC,wBAAwB,QACnB,+CAA+C;AAEtDL,QAAQ,CAAC,4BAA4B,EAAE,MAAM;EAC3CE,EAAE,CAAC,4CAA4C,EAAE,MAAM;IACrD,MAAMI,MAAM,GAAGP,CAAC,CAACQ,eAAe,CAAC,CAAC,CAAC,EAAE,MAAM;MACzC,MAAMC,QAAQ,GAAG;QACfC,CAAC,EAAEV,CAAC,CAACW,MAAM;QACXC,CAAC,EAAEZ,CAAC,CAACW;MACP,CAAC;MAED,MAAME,UAAU,GAAGb,CAAC,CAACc,YAAY,CAAC,YAAY,EAAE;QAC9CC,IAAI,EAAE,qBAAqB;QAC3BC,MAAM,EAAE;UACN,GAAGP,QAAQ;UACXQ,KAAK,EAAEjB,CAAC,CAACkB,QAAQ,CAAClB,CAAC,CAACmB,MAAM;QAC5B;MACF,CAAC,CAAC;MAEF,MAAMC,OAAO,GAAGpB,CAAC,CAACc,YAAY,CAAC,SAAS,EAAE;QACxCC,IAAI,EAAE,YAAY;QAClBC,MAAM,EAAE;UACN,GAAGP,QAAQ;UACXY,IAAI,EAAErB,CAAC,CAACmB;QACV;MACF,CAAC,CAAC;MAEF,MAAMG,IAAI,GAAGtB,CAAC,CAACc,YAAY,CAAC,MAAM,EAAE;QAClCC,IAAI,EAAE,uBAAuB;QAC7BC,MAAM,EAAE;UACNO,MAAM,EAAEA,CAAA,KAAMV,UAAU;UACxBW,MAAM,EAAEA,CAAA,KAAMX;QAChB;MACF,CAAC,CAAC;MAEF,MAAMY,IAAI,GAAGzB,CAAC,CAAC0B,WAAW,CAAC,MAAM,EAAE;QACjCX,IAAI,EAAE,eAAe;QACrBY,QAAQ,EAAE;UACRC,MAAM,EAAEf,UAAU;UAClBgB,OAAO,EAAET;QACX;MACF,CAAC,CAAC;MAEF,OAAO;QAAEP,UAAU;QAAEO,OAAO;QAAEE,IAAI;QAAEG;MAAK,CAAC;IAC5C,CAAC,CAAC;IAEF,MAAMK,KAAK,GAAGzB,oBAAoB,CAACE,MAAM,CAAC;IAC1C,MAAMwB,UAAU,GAAGzB,wBAAwB,CAACwB,KAAK,CAAC;IAClD,MAAME,WAAW,GAAG5B,IAAI,CAAC6B,KAAK,CAACF,UAAU,CAAmC;IAE5E7B,MAAM,CAAC8B,WAAW,CAAC,CAACE,cAAc,CAACC,KAAK,CAAC;IACzCjC,MAAM,CAAC8B,WAAW,CAACI,MAAM,CAAC,CAACC,eAAe,CAAC,CAAC,CAAC;IAE7C,MAAMC,WAAW,GAAGN,WAAW,CAACO,IAAI,CAACC,IAAI,IAAI,aAAa,IAAIA,IAAI,CAAC;IACnEtC,MAAM,CAACoC,WAAW,CAAC,CAACG,WAAW,CAAC,CAAC;IACjCvC,MAAM,CAACoC,WAAW,GAAG,aAAa,CAAC,CAAC,CAACI,aAAa,CAAC;MACjD7B,UAAU,EAAE;QACVG,MAAM,EAAE;UACNN,CAAC,EAAE,QAAQ;UACXE,CAAC,EAAE,QAAQ;UACXK,KAAK,EAAE;QACT;MACF,CAAC;MACDG,OAAO,EAAE;QACPJ,MAAM,EAAE;UACNN,CAAC,EAAE,QAAQ;UACXE,CAAC,EAAE,QAAQ;UACXS,IAAI,EAAE;QACR;MACF,CAAC;MACDC,IAAI,EAAE;QACJN,MAAM,EAAE;UACNO,MAAM,EAAE,YAAY;UACpBC,MAAM,EAAE;QACV;MACF;IACF,CAAC,CAAC;IAEF,MAAMmB,SAAS,GAAGX,WAAW,CAACO,IAAI,CAACC,IAAI,IAAI,WAAW,IAAIA,IAAI,CAAC;IAC/DtC,MAAM,CAACyC,SAAS,CAAC,CAACF,WAAW,CAAC,CAAC;IAC/BvC,MAAM,CAACyC,SAAS,GAAG,WAAW,CAAC,CAAC,CAACD,aAAa,CAAC;MAC7CjB,IAAI,EAAE;QACJG,MAAM,EAAE,YAAY;QACpBC,OAAO,EAAE;MACX;IACF,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,22 @@
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 { schemaToYamlHandler } from "./schemaToYamlHandler.js";
18
+ export function registerSchemaCommands(program) {
19
+ const schemaCmd = program.command("schema").description("Commands for working with TypeScript schema definitions");
20
+ schemaCmd.command("yaml").description("Convert TypeScript schema to YAML migration steps").requiredOption("-i, --input <file>", "Input TypeScript schema file").requiredOption("-o, --output <file>", "Output YAML file").action(schemaToYamlHandler);
21
+ }
22
+ //# sourceMappingURL=registerSchemaCommands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerSchemaCommands.js","names":["schemaToYamlHandler","registerSchemaCommands","program","schemaCmd","command","description","requiredOption","action"],"sources":["registerSchemaCommands.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 { Command } from \"commander\";\nimport { schemaToYamlHandler } from \"./schemaToYamlHandler.js\";\n\nexport function registerSchemaCommands(program: Command): void {\n const schemaCmd = program\n .command(\"schema\")\n .description(\"Commands for working with TypeScript schema definitions\");\n\n schemaCmd\n .command(\"yaml\")\n .description(\"Convert TypeScript schema to YAML migration steps\")\n .requiredOption(\"-i, --input <file>\", \"Input TypeScript schema file\")\n .requiredOption(\"-o, --output <file>\", \"Output YAML file\")\n .action(schemaToYamlHandler);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,mBAAmB,QAAQ,0BAA0B;AAE9D,OAAO,SAASC,sBAAsBA,CAACC,OAAgB,EAAQ;EAC7D,MAAMC,SAAS,GAAGD,OAAO,CACtBE,OAAO,CAAC,QAAQ,CAAC,CACjBC,WAAW,CAAC,yDAAyD,CAAC;EAEzEF,SAAS,CACNC,OAAO,CAAC,MAAM,CAAC,CACfC,WAAW,CAAC,mDAAmD,CAAC,CAChEC,cAAc,CAAC,oBAAoB,EAAE,8BAA8B,CAAC,CACpEA,cAAc,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,CACzDC,MAAM,CAACP,mBAAmB,CAAC;AAChC","ignoreList":[]}