@palantir/pack.document-schema.type-gen 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/esm/commands/asset/assetUpdateSchemaHandler.js +3 -2
- package/build/esm/commands/asset/assetUpdateSchemaHandler.js.map +1 -1
- package/build/esm/commands/ir/__tests__/resolveIrInput.test.js +88 -0
- package/build/esm/commands/ir/__tests__/resolveIrInput.test.js.map +1 -0
- package/build/esm/commands/ir/irDeployHandler.js +4 -3
- package/build/esm/commands/ir/irDeployHandler.js.map +1 -1
- package/build/esm/commands/ir/irGenAssetHandler.js +2 -31
- package/build/esm/commands/ir/irGenAssetHandler.js.map +1 -1
- package/build/esm/commands/ir/registerIrCommands.js +1 -1
- package/build/esm/commands/ir/registerIrCommands.js.map +1 -1
- package/build/esm/commands/ir/resolveIrInput.js +50 -0
- package/build/esm/commands/ir/resolveIrInput.js.map +1 -0
- package/build/esm/commands/schema/registerSchemaCommands.js +1 -1
- package/build/esm/commands/schema/registerSchemaCommands.js.map +1 -1
- package/build/esm/commands/schema/schemaIrHandler.js +14 -4
- package/build/esm/commands/schema/schemaIrHandler.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateDocumentTypeFromSchema/with-name-and-description.js +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateDocumentTypeFromSchema/with-name-and-description.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/single-version.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/three-version-chain.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js.map +1 -1
- package/build/esm/utils/schema/__tests__/fixtures.js +11 -0
- package/build/esm/utils/schema/__tests__/fixtures.js.map +1 -1
- package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js +6 -1
- package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js.map +1 -1
- package/build/esm/utils/schema/__tests__/resolveSchemaChain.test.js +13 -0
- package/build/esm/utils/schema/__tests__/resolveSchemaChain.test.js.map +1 -1
- package/build/esm/utils/schema/generateInternalFromSchema.js +54 -33
- package/build/esm/utils/schema/generateInternalFromSchema.js.map +1 -1
- package/build/esm/utils/schema/generateModelMetadataFromSchema.js +12 -10
- package/build/esm/utils/schema/generateModelMetadataFromSchema.js.map +1 -1
- package/build/esm/utils/schema/generateScopeFromSchema.js +13 -1
- package/build/esm/utils/schema/generateScopeFromSchema.js.map +1 -1
- package/build/esm/utils/schema/resolveSchemaChain.js +37 -11
- package/build/esm/utils/schema/resolveSchemaChain.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/arrayFields.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleRecord.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js.map +1 -1
- package/build/types/commands/asset/assetUpdateSchemaHandler.d.ts.map +1 -1
- package/build/types/commands/ir/__tests__/resolveIrInput.test.d.ts +2 -0
- package/build/types/commands/ir/__tests__/resolveIrInput.test.d.ts.map +1 -0
- package/build/types/commands/ir/irDeployHandler.d.ts.map +1 -1
- package/build/types/commands/ir/irGenAssetHandler.d.ts.map +1 -1
- package/build/types/commands/ir/registerIrCommands.d.ts.map +1 -1
- package/build/types/commands/ir/resolveIrInput.d.ts +8 -0
- package/build/types/commands/ir/resolveIrInput.d.ts.map +1 -0
- package/build/types/commands/schema/registerSchemaCommands.d.ts.map +1 -1
- package/build/types/commands/schema/schemaIrHandler.d.ts +4 -3
- package/build/types/commands/schema/schemaIrHandler.d.ts.map +1 -1
- package/build/types/utils/schema/__tests__/fixtures.d.ts +1 -0
- package/build/types/utils/schema/__tests__/fixtures.d.ts.map +1 -1
- package/build/types/utils/schema/generateInternalFromSchema.d.ts.map +1 -1
- package/build/types/utils/schema/generateModelMetadataFromSchema.d.ts.map +1 -1
- package/build/types/utils/schema/generateScopeFromSchema.d.ts.map +1 -1
- package/build/types/utils/schema/resolveSchemaChain.d.ts +13 -5
- package/build/types/utils/schema/resolveSchemaChain.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -30,6 +30,7 @@ export async function assetUpdateSchemaHandler(options) {
|
|
|
30
30
|
consola.info(`Reading asset file from: ${assetPath}`);
|
|
31
31
|
const assetContent = readFileSync(assetPath, "utf8");
|
|
32
32
|
const asset = JSON.parse(assetContent);
|
|
33
|
+
const schemaVersion = asset.schemaVersion;
|
|
33
34
|
const fetchFn = options.firstPartyPrefix != null ? buildPrefixRewriteFetch(options.firstPartyPrefix) : undefined;
|
|
34
35
|
if (fetchFn != null) {
|
|
35
36
|
consola.info(`Rewriting OSDK '${DEFAULT_API_PREFIX}' -> '${options.firstPartyPrefix}'`);
|
|
@@ -40,7 +41,7 @@ export async function assetUpdateSchemaHandler(options) {
|
|
|
40
41
|
requestBody: {
|
|
41
42
|
ontologyRid: options.ontologyRid,
|
|
42
43
|
schema: asset.documentStorageType.yjs.schema,
|
|
43
|
-
version:
|
|
44
|
+
version: schemaVersion,
|
|
44
45
|
...(options.forceOverwrite ? {
|
|
45
46
|
forceOverwrite: true
|
|
46
47
|
} : {})
|
|
@@ -49,7 +50,7 @@ export async function assetUpdateSchemaHandler(options) {
|
|
|
49
50
|
if (options.forceOverwrite) {
|
|
50
51
|
consola.warn("--force-overwrite is set: backwards-compatibility validation will be skipped.");
|
|
51
52
|
}
|
|
52
|
-
consola.info(`Updating schema for document type "${asset.documentTypeName}" -> version ${
|
|
53
|
+
consola.info(`Updating schema for document type "${asset.documentTypeName}" -> version ${schemaVersion}`);
|
|
53
54
|
const result = await DocumentTypes.updateSchema(osdkClient, request, {
|
|
54
55
|
preview: true
|
|
55
56
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assetUpdateSchemaHandler.js","names":["createPlatformClient","PalantirApiError","DocumentTypes","CommanderError","consola","readFileSync","resolve","buildPrefixRewriteFetch","DEFAULT_API_PREFIX","assetUpdateSchemaHandler","options","assetPath","input","info","assetContent","asset","JSON","parse","fetchFn","firstPartyPrefix","undefined","osdkClient","baseUrl","Promise","auth","request","documentTypeName","requestBody","ontologyRid","schema","documentStorageType","yjs","version","
|
|
1
|
+
{"version":3,"file":"assetUpdateSchemaHandler.js","names":["createPlatformClient","PalantirApiError","DocumentTypes","CommanderError","consola","readFileSync","resolve","buildPrefixRewriteFetch","DEFAULT_API_PREFIX","assetUpdateSchemaHandler","options","assetPath","input","info","assetContent","asset","JSON","parse","schemaVersion","fetchFn","firstPartyPrefix","undefined","osdkClient","baseUrl","Promise","auth","request","documentTypeName","requestBody","ontologyRid","schema","documentStorageType","yjs","version","forceOverwrite","warn","result","updateSchema","preview","type","success","error","violations","length","violation","fieldPath","violationType","message","errorName","errorCode","details","filter","Boolean","join"],"sources":["assetUpdateSchemaHandler.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, PalantirApiError } from \"@osdk/client\";\nimport type { UpdateSchemaDocumentTypeRequest } from \"@osdk/foundry.pack\";\nimport { DocumentTypes } from \"@osdk/foundry.pack\";\nimport { CommanderError } from \"commander\";\nimport { consola } from \"consola\";\nimport { readFileSync } from \"fs\";\nimport { resolve } from \"path\";\nimport type { DocumentTypeAsset } from \"../types.js\";\nimport { buildPrefixRewriteFetch } from \"./assetDeployHandler.js\";\n\ninterface AssetUpdateSchemaOptions {\n readonly input: string;\n readonly baseUrl: string;\n readonly auth: string;\n readonly ontologyRid: string;\n readonly forceOverwrite?: boolean;\n readonly firstPartyPrefix?: string;\n}\n\nconst DEFAULT_API_PREFIX = \"/api\";\n\n/** Updates the schema of an existing document type using a generated asset JSON file. */\nexport async function assetUpdateSchemaHandler(\n options: AssetUpdateSchemaOptions,\n): Promise<void> {\n try {\n const assetPath = resolve(options.input);\n\n consola.info(`Reading asset file from: ${assetPath}`);\n\n const assetContent = readFileSync(assetPath, \"utf8\");\n const asset = JSON.parse(assetContent) as DocumentTypeAsset;\n const schemaVersion = asset.schemaVersion;\n\n const fetchFn = options.firstPartyPrefix != null\n ? buildPrefixRewriteFetch(options.firstPartyPrefix)\n : undefined;\n if (fetchFn != null) {\n consola.info(`Rewriting OSDK '${DEFAULT_API_PREFIX}' -> '${options.firstPartyPrefix}'`);\n }\n\n const osdkClient = createPlatformClient(\n options.baseUrl,\n () => Promise.resolve(options.auth),\n undefined,\n fetchFn,\n );\n\n const request: UpdateSchemaDocumentTypeRequest = {\n documentTypeName: asset.documentTypeName,\n requestBody: {\n ontologyRid: options.ontologyRid,\n schema: asset.documentStorageType.yjs.schema,\n version: schemaVersion,\n ...(options.forceOverwrite ? { forceOverwrite: true } : {}),\n },\n };\n\n if (options.forceOverwrite) {\n consola.warn(\"--force-overwrite is set: backwards-compatibility validation will be skipped.\");\n }\n\n consola.info(\n `Updating schema for document type \"${asset.documentTypeName}\" -> version ${schemaVersion}`,\n );\n\n const result = await DocumentTypes.updateSchema(osdkClient, request, { preview: true });\n\n if (result.type === \"success\") {\n consola.success(`Schema updated successfully (version ${result.version})`);\n return;\n }\n\n consola.error(`Schema validation failed with ${result.violations.length} violation(s):`);\n for (const violation of result.violations) {\n consola.error(` - ${violation.fieldPath}\\t${violation.violationType}\\t${violation.message}`);\n }\n consola.info(\"Hint: re-run with --force-overwrite to skip validation.\");\n throw new CommanderError(\n 1,\n \"ERRSCHEMAVALIDATION\",\n \"Schema validation failed during update\",\n );\n } catch (error) {\n if (error instanceof CommanderError) {\n throw error;\n }\n if (error instanceof PalantirApiError) {\n const { message, errorName, errorCode } = error;\n const details = [errorName, errorCode].filter(Boolean).join(\" \");\n consola.error(\n `❌ Error during schema update: ${message}${details ? ` [${details}]` : \"\"}`,\n );\n } else {\n consola.error(\"❌ Error during schema update:\", error);\n }\n throw new CommanderError(1, \"ERRASSETUPDATESCHEMA\", \"Error updating document type schema\");\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,oBAAoB,EAAEC,gBAAgB,QAAQ,cAAc;AAErE,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,cAAc,QAAQ,WAAW;AAC1C,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,YAAY,QAAQ,IAAI;AACjC,SAASC,OAAO,QAAQ,MAAM;AAE9B,SAASC,uBAAuB,QAAQ,yBAAyB;AAWjE,MAAMC,kBAAkB,GAAG,MAAM;;AAEjC;AACA,OAAO,eAAeC,wBAAwBA,CAC5CC,OAAiC,EAClB;EACf,IAAI;IACF,MAAMC,SAAS,GAAGL,OAAO,CAACI,OAAO,CAACE,KAAK,CAAC;IAExCR,OAAO,CAACS,IAAI,CAAC,4BAA4BF,SAAS,EAAE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|
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 { describe, expect, it } from "vitest";
|
|
18
|
+
import { resolveIrInput } from "../resolveIrInput.js";
|
|
19
|
+
function ir(version) {
|
|
20
|
+
return {
|
|
21
|
+
name: `Test v${version}`,
|
|
22
|
+
description: "Test schema",
|
|
23
|
+
version,
|
|
24
|
+
primaryModelKeys: [],
|
|
25
|
+
models: {}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
describe("resolveIrInput", () => {
|
|
29
|
+
it("passes through legacy single-version IR", () => {
|
|
30
|
+
const resolved = resolveIrInput(ir(2), "legacy.json");
|
|
31
|
+
expect(resolved).toEqual({
|
|
32
|
+
ir: ir(2),
|
|
33
|
+
latestVersion: 2,
|
|
34
|
+
minSupportedVersion: 2
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it("selects the latest entry from a versioned IR chain", () => {
|
|
38
|
+
const resolved = resolveIrInput({
|
|
39
|
+
latestVersion: 3,
|
|
40
|
+
minSupportedVersion: 1,
|
|
41
|
+
chain: [{
|
|
42
|
+
version: 1,
|
|
43
|
+
ir: ir(1)
|
|
44
|
+
}, {
|
|
45
|
+
version: 3,
|
|
46
|
+
ir: ir(3)
|
|
47
|
+
}]
|
|
48
|
+
}, "chain.json");
|
|
49
|
+
expect(resolved).toEqual({
|
|
50
|
+
ir: ir(3),
|
|
51
|
+
latestVersion: 3,
|
|
52
|
+
minSupportedVersion: 1
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
it("defaults chain minSupportedVersion to latestVersion", () => {
|
|
56
|
+
const resolved = resolveIrInput({
|
|
57
|
+
latestVersion: 3,
|
|
58
|
+
chain: [{
|
|
59
|
+
version: 1,
|
|
60
|
+
ir: ir(1)
|
|
61
|
+
}, {
|
|
62
|
+
version: 3,
|
|
63
|
+
ir: ir(3)
|
|
64
|
+
}]
|
|
65
|
+
}, "chain.json");
|
|
66
|
+
expect(resolved.minSupportedVersion).toBe(3);
|
|
67
|
+
});
|
|
68
|
+
it("rejects an empty chain", () => {
|
|
69
|
+
expect(() => resolveIrInput({
|
|
70
|
+
latestVersion: 1,
|
|
71
|
+
chain: []
|
|
72
|
+
}, "empty.json")).toThrow("chain");
|
|
73
|
+
});
|
|
74
|
+
it("rejects a chain with an invalid minSupportedVersion", () => {
|
|
75
|
+
expect(() => resolveIrInput({
|
|
76
|
+
latestVersion: 3,
|
|
77
|
+
minSupportedVersion: 2,
|
|
78
|
+
chain: [{
|
|
79
|
+
version: 1,
|
|
80
|
+
ir: ir(1)
|
|
81
|
+
}, {
|
|
82
|
+
version: 3,
|
|
83
|
+
ir: ir(3)
|
|
84
|
+
}]
|
|
85
|
+
}, "missing.json")).toThrow("minSupportedVersion 2");
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=resolveIrInput.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveIrInput.test.js","names":["describe","expect","it","resolveIrInput","ir","version","name","description","primaryModelKeys","models","resolved","toEqual","latestVersion","minSupportedVersion","chain","toBe","toThrow"],"sources":["resolveIrInput.test.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { describe, expect, it } from \"vitest\";\nimport type { IRealTimeDocumentSchema } from \"../../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { resolveIrInput } from \"../resolveIrInput.js\";\n\nfunction ir(version: number): IRealTimeDocumentSchema {\n return {\n name: `Test v${version}`,\n description: \"Test schema\",\n version,\n primaryModelKeys: [],\n models: {},\n };\n}\n\ndescribe(\"resolveIrInput\", () => {\n it(\"passes through legacy single-version IR\", () => {\n const resolved = resolveIrInput(ir(2), \"legacy.json\");\n\n expect(resolved).toEqual({\n ir: ir(2),\n latestVersion: 2,\n minSupportedVersion: 2,\n });\n });\n\n it(\"selects the latest entry from a versioned IR chain\", () => {\n const resolved = resolveIrInput({\n latestVersion: 3,\n minSupportedVersion: 1,\n chain: [\n { version: 1, ir: ir(1) },\n { version: 3, ir: ir(3) },\n ],\n }, \"chain.json\");\n\n expect(resolved).toEqual({\n ir: ir(3),\n latestVersion: 3,\n minSupportedVersion: 1,\n });\n });\n\n it(\"defaults chain minSupportedVersion to latestVersion\", () => {\n const resolved = resolveIrInput({\n latestVersion: 3,\n chain: [\n { version: 1, ir: ir(1) },\n { version: 3, ir: ir(3) },\n ],\n }, \"chain.json\");\n\n expect(resolved.minSupportedVersion).toBe(3);\n });\n\n it(\"rejects an empty chain\", () => {\n expect(() =>\n resolveIrInput({\n latestVersion: 1,\n chain: [],\n }, \"empty.json\")\n ).toThrow(\"chain\");\n });\n\n it(\"rejects a chain with an invalid minSupportedVersion\", () => {\n expect(() =>\n resolveIrInput({\n latestVersion: 3,\n minSupportedVersion: 2,\n chain: [\n { version: 1, ir: ir(1) },\n { version: 3, ir: ir(3) },\n ],\n }, \"missing.json\")\n ).toThrow(\"minSupportedVersion 2\");\n });\n});\n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C,CAAC;EAEFX,EAAE,CAAC,qDAAqD,EAAE,MAAM;IAC9D,MAAMQ,QAAQ,GAAGP,cAAc,CAAC;MAC9BS,aAAa,EAAE,CAAC;MAChBE,KAAK,EAAE,CACL;QAAET,OAAO,EAAE,CAAC;QAAED,EAAE,EAAEA,EAAE,CAAC,CAAC;MAAE,CAAC,EACzB;QAAEC,OAAO,EAAE,CAAC;QAAED,EAAE,EAAEA,EAAE,CAAC,CAAC;MAAE,CAAC;IAE7B,CAAC,EAAE,YAAY,CAAC;IAEhBH,MAAM,CAACS,QAAQ,CAACG,mBAAmB,CAAC,CAACE,IAAI,CAAC,CAAC,CAAC;EAC9C,CAAC,CAAC;EAEFb,EAAE,CAAC,wBAAwB,EAAE,MAAM;IACjCD,MAAM,CAAC,MACLE,cAAc,CAAC;MACbS,aAAa,EAAE,CAAC;MAChBE,KAAK,EAAE;IACT,CAAC,EAAE,YAAY,CACjB,CAAC,CAACE,OAAO,CAAC,OAAO,CAAC;EACpB,CAAC,CAAC;EAEFd,EAAE,CAAC,qDAAqD,EAAE,MAAM;IAC9DD,MAAM,CAAC,MACLE,cAAc,CAAC;MACbS,aAAa,EAAE,CAAC;MAChBC,mBAAmB,EAAE,CAAC;MACtBC,KAAK,EAAE,CACL;QAAET,OAAO,EAAE,CAAC;QAAED,EAAE,EAAEA,EAAE,CAAC,CAAC;MAAE,CAAC,EACzB;QAAEC,OAAO,EAAE,CAAC;QAAED,EAAE,EAAEA,EAAE,CAAC,CAAC;MAAE,CAAC;IAE7B,CAAC,EAAE,cAAc,CACnB,CAAC,CAACY,OAAO,CAAC,uBAAuB,CAAC;EACpC,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -21,14 +21,15 @@ import { consola } from "consola";
|
|
|
21
21
|
import { readFileSync } from "fs";
|
|
22
22
|
import { resolve } from "path";
|
|
23
23
|
import { convertIrToWireSchema } from "../../utils/ir/convertIrToWireSchema.js";
|
|
24
|
+
import { resolveIrInput } from "./resolveIrInput.js";
|
|
24
25
|
export async function irDeployHandler(options) {
|
|
25
26
|
try {
|
|
26
27
|
const irPath = resolve(options.ir);
|
|
27
28
|
consola.info(`Reading schema from: ${irPath}`);
|
|
28
29
|
const irContent = readFileSync(irPath, "utf8");
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const {
|
|
31
|
+
ir
|
|
32
|
+
} = resolveIrInput(JSON.parse(irContent), irPath);
|
|
32
33
|
const osdkClient = createPlatformClient(options.baseUrl, () => Promise.resolve(options.auth));
|
|
33
34
|
const schema = convertIrToWireSchema(ir);
|
|
34
35
|
const request = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"irDeployHandler.js","names":["createPlatformClient","DocumentTypes","CommanderError","consola","readFileSync","resolve","convertIrToWireSchema","irDeployHandler","options","irPath","ir","info","irContent","JSON","parse","osdkClient","baseUrl","Promise","auth","schema","request","name","parentFolderRid","parentFolder","fileSystemType","create","preview","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 { CommanderError } from \"commander\";\nimport { consola } from \"consola\";\nimport { readFileSync } from \"fs\";\nimport { resolve } from \"path\";\nimport
|
|
1
|
+
{"version":3,"file":"irDeployHandler.js","names":["createPlatformClient","DocumentTypes","CommanderError","consola","readFileSync","resolve","convertIrToWireSchema","resolveIrInput","irDeployHandler","options","irPath","ir","info","irContent","JSON","parse","osdkClient","baseUrl","Promise","auth","schema","request","name","parentFolderRid","parentFolder","fileSystemType","create","preview","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 { CommanderError } from \"commander\";\nimport { consola } from \"consola\";\nimport { readFileSync } from \"fs\";\nimport { resolve } from \"path\";\nimport { convertIrToWireSchema } from \"../../utils/ir/convertIrToWireSchema.js\";\nimport type { FileSystemType } from \"../types.js\";\nimport { resolveIrInput } from \"./resolveIrInput.js\";\n\ninterface DeployOptions {\n readonly ir: string;\n readonly baseUrl: string;\n readonly auth: string;\n readonly parentFolder: string;\n readonly fileSystemType: FileSystemType;\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 const { ir } = resolveIrInput(JSON.parse(irContent) as unknown, irPath);\n\n const osdkClient = createPlatformClient(\n options.baseUrl,\n () => Promise.resolve(options.auth),\n );\n\n const schema = convertIrToWireSchema(ir);\n\n const request: CreateDocumentTypeRequest = {\n name: ir.name,\n parentFolderRid: options.parentFolder,\n schema,\n };\n\n if (options.fileSystemType != null) {\n request.fileSystemType = options.fileSystemType;\n }\n\n consola.info(\"Creating document type with schema\", request);\n\n await DocumentTypes.create(osdkClient, request, { preview: true });\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;AAClD,SAASC,cAAc,QAAQ,WAAW;AAC1C,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,YAAY,QAAQ,IAAI;AACjC,SAASC,OAAO,QAAQ,MAAM;AAC9B,SAASC,qBAAqB,QAAQ,yCAAyC;AAE/E,SAASC,cAAc,QAAQ,qBAAqB;AAUpD,OAAO,eAAeC,eAAeA,CAACC,OAAsB,EAAiB;EAC3E,IAAI;IACF,MAAMC,MAAM,GAAGL,OAAO,CAACI,OAAO,CAACE,EAAE,CAAC;IAElCR,OAAO,CAACS,IAAI,CAAC,wBAAwBF,MAAM,EAAE,CAAC;IAE9C,MAAMG,SAAS,GAAGT,YAAY,CAACM,MAAM,EAAE,MAAM,CAAC;IAE9C,MAAM;MAAEC;IAAG,CAAC,GAAGJ,cAAc,CAACO,IAAI,CAACC,KAAK,CAACF,SAAS,CAAC,EAAaH,MAAM,CAAC;IAEvE,MAAMM,UAAU,GAAGhB,oBAAoB,CACrCS,OAAO,CAACQ,OAAO,EACf,MAAMC,OAAO,CAACb,OAAO,CAACI,OAAO,CAACU,IAAI,CACpC,CAAC;IAED,MAAMC,MAAM,GAAGd,qBAAqB,CAACK,EAAE,CAAC;IAExC,MAAMU,OAAkC,GAAG;MACzCC,IAAI,EAAEX,EAAE,CAACW,IAAI;MACbC,eAAe,EAAEd,OAAO,CAACe,YAAY;MACrCJ;IACF,CAAC;IAED,IAAIX,OAAO,CAACgB,cAAc,IAAI,IAAI,EAAE;MAClCJ,OAAO,CAACI,cAAc,GAAGhB,OAAO,CAACgB,cAAc;IACjD;IAEAtB,OAAO,CAACS,IAAI,CAAC,oCAAoC,EAAES,OAAO,CAAC;IAE3D,MAAMpB,aAAa,CAACyB,MAAM,CAACV,UAAU,EAAEK,OAAO,EAAE;MAAEM,OAAO,EAAE;IAAK,CAAC,CAAC;EACpE,CAAC,CAAC,OAAOC,KAAK,EAAE;IACdzB,OAAO,CAACyB,KAAK,CAAC,wBAAwB,EAAEA,KAAK,CAAC;IAC9C,MAAM,IAAI1B,cAAc,CAAC,CAAC,EAAE,cAAc,EAAE,oCAAoC,CAAC;EACnF;AACF","ignoreList":[]}
|
|
@@ -20,36 +20,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
|
20
20
|
import { basename, dirname, extname, join, resolve } from "path";
|
|
21
21
|
import { GENERATED_JSON_COMMENT } from "../../utils/generatedFileHeader.js";
|
|
22
22
|
import { convertIrToWireSchema } from "../../utils/ir/convertIrToWireSchema.js";
|
|
23
|
-
import {
|
|
24
|
-
function isChainPayload(parsed) {
|
|
25
|
-
return typeof parsed === "object" && parsed != null && "chain" in parsed && Array.isArray(parsed.chain) && typeof parsed.latestVersion === "number";
|
|
26
|
-
}
|
|
27
|
-
function resolveFromChain(payload, irPath) {
|
|
28
|
-
if (payload.chain.length === 0) {
|
|
29
|
-
throw new CommanderError(1, "EINVAL", `Invalid IR chain payload at ${irPath}: 'chain' is empty`);
|
|
30
|
-
}
|
|
31
|
-
const {
|
|
32
|
-
latestVersion,
|
|
33
|
-
minVersion
|
|
34
|
-
} = resolveMinVersion(payload.chain, payload.minSupportedVersion);
|
|
35
|
-
const latestEntry = payload.chain.find(c => c.version === latestVersion);
|
|
36
|
-
if (latestEntry == null) {
|
|
37
|
-
throw new CommanderError(1, "EINVAL", `IR chain payload at ${irPath} has no entry matching latestVersion ${latestVersion}`);
|
|
38
|
-
}
|
|
39
|
-
return {
|
|
40
|
-
ir: latestEntry.ir,
|
|
41
|
-
latestVersion,
|
|
42
|
-
minSupportedVersion: minVersion
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function resolveFromSingleIr(ir) {
|
|
46
|
-
// Legacy single-IR input has no chain, so min defaults to max (no back-compat claim).
|
|
47
|
-
return {
|
|
48
|
-
ir,
|
|
49
|
-
latestVersion: ir.version,
|
|
50
|
-
minSupportedVersion: ir.version
|
|
51
|
-
};
|
|
52
|
-
}
|
|
23
|
+
import { resolveIrInput } from "./resolveIrInput.js";
|
|
53
24
|
function deriveCompatibilityRangePath(assetOutputPath) {
|
|
54
25
|
const stem = basename(assetOutputPath, extname(assetOutputPath));
|
|
55
26
|
return join(dirname(assetOutputPath), `${stem}-schema-compatibility-range.json`);
|
|
@@ -84,7 +55,7 @@ export function irGenAssetHandler(options) {
|
|
|
84
55
|
}
|
|
85
56
|
consola.info(`Reading IR schema from: ${irPath}`);
|
|
86
57
|
const parsed = JSON.parse(readFileSync(irPath, "utf8"));
|
|
87
|
-
const resolved =
|
|
58
|
+
const resolved = resolveIrInput(parsed, irPath);
|
|
88
59
|
const {
|
|
89
60
|
ir: irSchema,
|
|
90
61
|
latestVersion,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"irGenAssetHandler.js","names":["CommanderError","consola","existsSync","mkdirSync","readFileSync","writeFileSync","basename","dirname","extname","join","resolve","GENERATED_JSON_COMMENT","convertIrToWireSchema","resolveMinVersion","isChainPayload","parsed","Array","isArray","chain","latestVersion","resolveFromChain","payload","irPath","length","minVersion","minSupportedVersion","latestEntry","find","c","version","ir","resolveFromSingleIr","deriveCompatibilityRangePath","assetOutputPath","stem","irGenAssetHandler","options","outputPath","output","info","JSON","parse","resolved","irSchema","name","documentTypeName","wireSchema","fileSystemType","outputDir","recursive","__comment","documentStorageType","type","yjs","schema","schemaVersion","stringify","compatibilityRangePath","compatibilityRangeOutput","compatibilityRangeDir","min","max","success","error"],"sources":["irGenAssetHandler.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 { CommanderError } from \"commander\";\nimport { consola } from \"consola\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { basename, dirname, extname, join, resolve } from \"path\";\nimport type { IRealTimeDocumentSchema } from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { GENERATED_JSON_COMMENT } from \"../../utils/generatedFileHeader.js\";\nimport { convertIrToWireSchema } from \"../../utils/ir/convertIrToWireSchema.js\";\nimport { type IrChainPayload, resolveMinVersion } from \"../../utils/schema/resolveSchemaChain.js\";\nimport type { DocumentTypeAsset, FileSystemType } from \"../types.js\";\n\ninterface IrGenAssetOptions {\n readonly ir: string;\n readonly output: string;\n readonly fileSystemType?: FileSystemType;\n readonly compatibilityRangeOutput?: string;\n}\n\ninterface SchemaCompatibilityRangeFile {\n readonly min: number;\n readonly max: number;\n}\n\ninterface ResolvedIrInput {\n readonly ir: IRealTimeDocumentSchema;\n readonly latestVersion: number;\n readonly minSupportedVersion: number;\n}\n\nfunction isChainPayload(parsed: unknown): parsed is IrChainPayload {\n return (\n typeof parsed === \"object\"\n && parsed != null\n && \"chain\" in parsed\n && Array.isArray((parsed as IrChainPayload).chain)\n && typeof (parsed as IrChainPayload).latestVersion === \"number\"\n );\n}\n\nfunction resolveFromChain(payload: IrChainPayload, irPath: string): ResolvedIrInput {\n if (payload.chain.length === 0) {\n throw new CommanderError(\n 1,\n \"EINVAL\",\n `Invalid IR chain payload at ${irPath}: 'chain' is empty`,\n );\n }\n const { latestVersion, minVersion } = resolveMinVersion(\n payload.chain,\n payload.minSupportedVersion,\n );\n const latestEntry = payload.chain.find(c => c.version === latestVersion);\n if (latestEntry == null) {\n throw new CommanderError(\n 1,\n \"EINVAL\",\n `IR chain payload at ${irPath} has no entry matching latestVersion ${latestVersion}`,\n );\n }\n return { ir: latestEntry.ir, latestVersion, minSupportedVersion: minVersion };\n}\n\nfunction resolveFromSingleIr(ir: IRealTimeDocumentSchema): ResolvedIrInput {\n // Legacy single-IR input has no chain, so min defaults to max (no back-compat claim).\n return { ir, latestVersion: ir.version, minSupportedVersion: ir.version };\n}\n\nfunction deriveCompatibilityRangePath(assetOutputPath: string): string {\n const stem = basename(assetOutputPath, extname(assetOutputPath));\n return join(dirname(assetOutputPath), `${stem}-schema-compatibility-range.json`);\n}\n\n/**\n * Generates a document type asset JSON file (and a sibling schema\n * compatibility range JSON file) from an IR schema.\n *\n * The input IR may be either:\n * - a chain payload `{ latestVersion, minSupportedVersion?, chain }` produced\n * by `schema ir`. The latest entry's `ir` is used as the wire schema; the\n * asset's `schemaVersion` is `latestVersion`; the compatibility range is\n * `{ min: minSupportedVersion ?? latestVersion, max: latestVersion }`.\n * - a bare single-version `IRealTimeDocumentSchema` (legacy). The compat\n * range defaults to `{ min: version, max: version }` since no chain\n * information is available.\n *\n * This command is intended for internal platform applications where the\n * document type asset must exist on disk so the platform can discover it and\n * register the document type automatically at deploy time. Most users should\n * use `ir deploy` to register document types via the Foundry API instead.\n *\n * If you are unsure whether you need this command, you almost certainly do not.\n */\nexport function irGenAssetHandler(options: IrGenAssetOptions): void {\n try {\n const irPath = resolve(options.ir);\n const outputPath = resolve(options.output);\n\n if (!existsSync(irPath)) {\n throw new CommanderError(1, \"ENOENT\", `IR file does not exist: ${irPath}`);\n }\n\n consola.info(`Reading IR schema from: ${irPath}`);\n const parsed = JSON.parse(readFileSync(irPath, \"utf8\")) as unknown;\n\n const resolved = isChainPayload(parsed)\n ? resolveFromChain(parsed, irPath)\n : resolveFromSingleIr(parsed as IRealTimeDocumentSchema);\n\n const { ir: irSchema, latestVersion, minSupportedVersion } = resolved;\n const { name: documentTypeName } = irSchema;\n const wireSchema = convertIrToWireSchema(irSchema);\n\n const fileSystemType = options.fileSystemType ?? \"ARTIFACTS\";\n if (fileSystemType !== \"ARTIFACTS\" && fileSystemType !== \"COMPASS\") {\n throw new CommanderError(\n 1,\n \"EINVAL\",\n `Invalid fileSystemType \"${fileSystemType}\". Must be \"ARTIFACTS\" or \"COMPASS\".`,\n );\n }\n\n const asset: DocumentTypeAsset = {\n documentTypeName,\n documentStorageType: {\n type: \"yjs\",\n yjs: {\n schema: wireSchema,\n },\n },\n fileSystemType,\n schemaVersion: latestVersion,\n };\n\n const outputDir = dirname(outputPath);\n if (!existsSync(outputDir)) {\n mkdirSync(outputDir, { recursive: true });\n }\n const output = { __comment: GENERATED_JSON_COMMENT, ...asset };\n writeFileSync(outputPath, JSON.stringify(output, null, 2), \"utf8\");\n\n const compatibilityRange: SchemaCompatibilityRangeFile = {\n min: minSupportedVersion,\n max: latestVersion,\n };\n const compatibilityRangePath = resolve(\n options.compatibilityRangeOutput ?? deriveCompatibilityRangePath(outputPath),\n );\n const compatibilityRangeDir = dirname(compatibilityRangePath);\n if (!existsSync(compatibilityRangeDir)) {\n mkdirSync(compatibilityRangeDir, { recursive: true });\n }\n const compatibilityRangeOutput = {\n __comment: GENERATED_JSON_COMMENT,\n ...compatibilityRange,\n };\n writeFileSync(\n compatibilityRangePath,\n JSON.stringify(compatibilityRangeOutput, null, 2),\n \"utf8\",\n );\n\n consola.success(\"Successfully generated document type asset\");\n consola.info(` Output: ${outputPath}`);\n consola.info(` Compatibility range output: ${compatibilityRangePath}`);\n consola.info(` Document type: ${documentTypeName}`);\n consola.info(` Schema version: ${latestVersion}`);\n consola.info(` Compatibility range: [${minSupportedVersion}, ${latestVersion}]`);\n consola.info(` File system type: ${fileSystemType}`);\n } catch (error) {\n if (error instanceof CommanderError) {\n throw error;\n }\n consola.error(\"Error generating document type asset:\", error);\n throw new CommanderError(1, \"IR_ASSET_ERROR\", \"Fail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EAAE;QAAEV,SAAS,EAAE;MAAK,CAAC,CAAC;IACvD;IACA,MAAMS,wBAAwB,GAAG;MAC/BR,SAAS,EAAEvC,sBAAsB;MACjC,GAbuD;QACvDiD,GAAG,EAAEnC,mBAAmB;QACxBoC,GAAG,EAAE1C;MACP;IAWA,CAAC;IACDd,aAAa,CACXoD,sBAAsB,EACtBjB,IAAI,CAACgB,SAAS,CAACE,wBAAwB,EAAE,IAAI,EAAE,CAAC,CAAC,EACjD,MACF,CAAC;IAEDzD,OAAO,CAAC6D,OAAO,CAAC,4CAA4C,CAAC;IAC7D7D,OAAO,CAACsC,IAAI,CAAC,cAAcF,UAAU,EAAE,CAAC;IACxCpC,OAAO,CAACsC,IAAI,CAAC,kCAAkCkB,sBAAsB,EAAE,CAAC;IACxExD,OAAO,CAACsC,IAAI,CAAC,qBAAqBM,gBAAgB,EAAE,CAAC;IACrD5C,OAAO,CAACsC,IAAI,CAAC,sBAAsBpB,aAAa,EAAE,CAAC;IACnDlB,OAAO,CAACsC,IAAI,CAAC,4BAA4Bd,mBAAmB,KAAKN,aAAa,GAAG,CAAC;IAClFlB,OAAO,CAACsC,IAAI,CAAC,wBAAwBQ,cAAc,EAAE,CAAC;EACxD,CAAC,CAAC,OAAOgB,KAAK,EAAE;IACd,IAAIA,KAAK,YAAY/D,cAAc,EAAE;MACnC,MAAM+D,KAAK;IACb;IACA9D,OAAO,CAAC8D,KAAK,CAAC,uCAAuC,EAAEA,KAAK,CAAC;IAC7D,MAAM,IAAI/D,cAAc,CAAC,CAAC,EAAE,gBAAgB,EAAE,wCAAwC,CAAC;EACzF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"irGenAssetHandler.js","names":["CommanderError","consola","existsSync","mkdirSync","readFileSync","writeFileSync","basename","dirname","extname","join","resolve","GENERATED_JSON_COMMENT","convertIrToWireSchema","resolveIrInput","deriveCompatibilityRangePath","assetOutputPath","stem","irGenAssetHandler","options","irPath","ir","outputPath","output","info","parsed","JSON","parse","resolved","irSchema","latestVersion","minSupportedVersion","name","documentTypeName","wireSchema","fileSystemType","outputDir","recursive","__comment","documentStorageType","type","yjs","schema","schemaVersion","stringify","compatibilityRangePath","compatibilityRangeOutput","compatibilityRangeDir","min","max","success","error"],"sources":["irGenAssetHandler.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 { CommanderError } from \"commander\";\nimport { consola } from \"consola\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"fs\";\nimport { basename, dirname, extname, join, resolve } from \"path\";\nimport { GENERATED_JSON_COMMENT } from \"../../utils/generatedFileHeader.js\";\nimport { convertIrToWireSchema } from \"../../utils/ir/convertIrToWireSchema.js\";\nimport type { DocumentTypeAsset, FileSystemType } from \"../types.js\";\nimport { resolveIrInput } from \"./resolveIrInput.js\";\n\ninterface IrGenAssetOptions {\n readonly ir: string;\n readonly output: string;\n readonly fileSystemType?: FileSystemType;\n readonly compatibilityRangeOutput?: string;\n}\n\ninterface SchemaCompatibilityRangeFile {\n readonly min: number;\n readonly max: number;\n}\n\nfunction deriveCompatibilityRangePath(assetOutputPath: string): string {\n const stem = basename(assetOutputPath, extname(assetOutputPath));\n return join(dirname(assetOutputPath), `${stem}-schema-compatibility-range.json`);\n}\n\n/**\n * Generates a document type asset JSON file (and a sibling schema\n * compatibility range JSON file) from an IR schema.\n *\n * The input IR may be either:\n * - a chain payload `{ latestVersion, minSupportedVersion?, chain }` produced\n * by `schema ir`. The latest entry's `ir` is used as the wire schema; the\n * asset's `schemaVersion` is `latestVersion`; the compatibility range is\n * `{ min: minSupportedVersion ?? latestVersion, max: latestVersion }`.\n * - a bare single-version `IRealTimeDocumentSchema` (legacy). The compat\n * range defaults to `{ min: version, max: version }` since no chain\n * information is available.\n *\n * This command is intended for internal platform applications where the\n * document type asset must exist on disk so the platform can discover it and\n * register the document type automatically at deploy time. Most users should\n * use `ir deploy` to register document types via the Foundry API instead.\n *\n * If you are unsure whether you need this command, you almost certainly do not.\n */\nexport function irGenAssetHandler(options: IrGenAssetOptions): void {\n try {\n const irPath = resolve(options.ir);\n const outputPath = resolve(options.output);\n\n if (!existsSync(irPath)) {\n throw new CommanderError(1, \"ENOENT\", `IR file does not exist: ${irPath}`);\n }\n\n consola.info(`Reading IR schema from: ${irPath}`);\n const parsed = JSON.parse(readFileSync(irPath, \"utf8\")) as unknown;\n\n const resolved = resolveIrInput(parsed, irPath);\n\n const { ir: irSchema, latestVersion, minSupportedVersion } = resolved;\n const { name: documentTypeName } = irSchema;\n const wireSchema = convertIrToWireSchema(irSchema);\n\n const fileSystemType = options.fileSystemType ?? \"ARTIFACTS\";\n if (fileSystemType !== \"ARTIFACTS\" && fileSystemType !== \"COMPASS\") {\n throw new CommanderError(\n 1,\n \"EINVAL\",\n `Invalid fileSystemType \"${fileSystemType}\". Must be \"ARTIFACTS\" or \"COMPASS\".`,\n );\n }\n\n const asset: DocumentTypeAsset = {\n documentTypeName,\n documentStorageType: {\n type: \"yjs\",\n yjs: {\n schema: wireSchema,\n },\n },\n fileSystemType,\n schemaVersion: latestVersion,\n };\n\n const outputDir = dirname(outputPath);\n if (!existsSync(outputDir)) {\n mkdirSync(outputDir, { recursive: true });\n }\n const output = { __comment: GENERATED_JSON_COMMENT, ...asset };\n writeFileSync(outputPath, JSON.stringify(output, null, 2), \"utf8\");\n\n const compatibilityRange: SchemaCompatibilityRangeFile = {\n min: minSupportedVersion,\n max: latestVersion,\n };\n const compatibilityRangePath = resolve(\n options.compatibilityRangeOutput ?? deriveCompatibilityRangePath(outputPath),\n );\n const compatibilityRangeDir = dirname(compatibilityRangePath);\n if (!existsSync(compatibilityRangeDir)) {\n mkdirSync(compatibilityRangeDir, { recursive: true });\n }\n const compatibilityRangeOutput = {\n __comment: GENERATED_JSON_COMMENT,\n ...compatibilityRange,\n };\n writeFileSync(\n compatibilityRangePath,\n JSON.stringify(compatibilityRangeOutput, null, 2),\n \"utf8\",\n );\n\n consola.success(\"Successfully generated document type asset\");\n consola.info(` Output: ${outputPath}`);\n consola.info(` Compatibility range output: ${compatibilityRangePath}`);\n consola.info(` Document type: ${documentTypeName}`);\n consola.info(` Schema version: ${latestVersion}`);\n consola.info(` Compatibility range: [${minSupportedVersion}, ${latestVersion}]`);\n consola.info(` File system type: ${fileSystemType}`);\n } catch (error) {\n if (error instanceof CommanderError) {\n throw error;\n }\n consola.error(\"Error generating document type asset:\", error);\n throw new CommanderError(1, \"IR_ASSET_ERROR\", \"Failed to generate document type asset\");\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,WAAW;AAC1C,SAASC,OAAO,QAAQ,SAAS;AACjC,SAASC,UAAU,EAAEC,SAAS,EAAEC,YAAY,EAAEC,aAAa,QAAQ,IAAI;AACvE,SAASC,QAAQ,EAAEC,OAAO,EAAEC,OAAO,EAAEC,IAAI,EAAEC,OAAO,QAAQ,MAAM;AAChE,SAASC,sBAAsB,QAAQ,oCAAoC;AAC3E,SAASC,qBAAqB,QAAQ,yCAAyC;AAE/E,SAASC,cAAc,QAAQ,qBAAqB;AAcpD,SAASC,4BAA4BA,CAACC,eAAuB,EAAU;EACrE,MAAMC,IAAI,GAAGV,QAAQ,CAACS,eAAe,EAAEP,OAAO,CAACO,eAAe,CAAC,CAAC;EAChE,OAAON,IAAI,CAACF,OAAO,CAACQ,eAAe,CAAC,EAAE,GAAGC,IAAI,kCAAkC,CAAC;AAClF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA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I,CAAC,4BAA4BO,mBAAmB,KAAKD,aAAa,GAAG,CAAC;IAClF5B,OAAO,CAACsB,IAAI,CAAC,wBAAwBW,cAAc,EAAE,CAAC;EACxD,CAAC,CAAC,OAAOgB,KAAK,EAAE;IACd,IAAIA,KAAK,YAAYlD,cAAc,EAAE;MACnC,MAAMkD,KAAK;IACb;IACAjD,OAAO,CAACiD,KAAK,CAAC,uCAAuC,EAAEA,KAAK,CAAC;IAC7D,MAAM,IAAIlD,cAAc,CAAC,CAAC,EAAE,gBAAgB,EAAE,wCAAwC,CAAC;EACzF;AACF","ignoreList":[]}
|
|
@@ -24,7 +24,7 @@ export function registerIrCommands(program) {
|
|
|
24
24
|
irCmd.command("gen-types").description("Generate versioned SDK files (types, schemas, internal/, models.ts, versions.ts, versionedDocRef.ts, index.ts) from a versioned IR chain JSON.").requiredOption("-s, --schema <file>", "Path to versioned IR chain JSON file").requiredOption("-o, --output <dir>", "Output directory for generated SDK files").action(irGenTypesHandler);
|
|
25
25
|
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);
|
|
26
26
|
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);
|
|
27
|
-
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").requiredOption("-f, --file-system-type <type>", "File system type for the document type (ARTIFACTS or COMPASS)").action(irDeployHandler);
|
|
27
|
+
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 (chain payload from 'schema ir', or legacy single-version IR)").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").requiredOption("-f, --file-system-type <type>", "File system type for the document type (ARTIFACTS or COMPASS)").action(irDeployHandler);
|
|
28
28
|
irCmd.command("asset").description("Generate document type asset JSON and a sibling schema compatibility range JSON from an IR file (advanced — most users should use 'ir deploy' instead). The minimum supported schema version is sourced from the IR payload's 'minSupportedVersion' field (set by 'schema ir --config <pack-config.json>'); legacy single-IR inputs default to min == max.").requiredOption("-i, --ir <file>", "Path to IR JSON file (chain payload from 'schema ir', or legacy single-version IR)").requiredOption("-o, --output <file>", "Output file path for asset JSON").option("-f, --file-system-type <type>", "File system type (ARTIFACTS or COMPASS)", "ARTIFACTS").option("--compatibility-range-output <file>", "Output path for the schema compatibility range JSON (defaults to a sibling of --output with '-schema-compatibility-range' suffix)").action(irGenAssetHandler);
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=registerIrCommands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerIrCommands.js","names":["irDeployHandler","irGenAssetHandler","irGenModelsHandler","irGenTypesHandler","irGenZodHandler","registerIrCommands","program","irCmd","command","description","requiredOption","action","option"],"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 { irGenAssetHandler } from \"./irGenAssetHandler.js\";\nimport { irGenModelsHandler } from \"./irGenModelsHandler.js\";\nimport { irGenTypesHandler } from \"./irGenTypesHandler.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(\"gen-types\")\n .description(\n \"Generate versioned SDK files (types, schemas, internal/, models.ts, versions.ts, versionedDocRef.ts, index.ts) from a versioned IR chain JSON.\",\n )\n .requiredOption(\"-s, --schema <file>\", \"Path to versioned IR chain JSON file\")\n .requiredOption(\"-o, --output <dir>\", \"Output directory for generated SDK files\")\n .action(irGenTypesHandler);\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>\"
|
|
1
|
+
{"version":3,"file":"registerIrCommands.js","names":["irDeployHandler","irGenAssetHandler","irGenModelsHandler","irGenTypesHandler","irGenZodHandler","registerIrCommands","program","irCmd","command","description","requiredOption","action","option"],"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 { irGenAssetHandler } from \"./irGenAssetHandler.js\";\nimport { irGenModelsHandler } from \"./irGenModelsHandler.js\";\nimport { irGenTypesHandler } from \"./irGenTypesHandler.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(\"gen-types\")\n .description(\n \"Generate versioned SDK files (types, schemas, internal/, models.ts, versions.ts, versionedDocRef.ts, index.ts) from a versioned IR chain JSON.\",\n )\n .requiredOption(\"-s, --schema <file>\", \"Path to versioned IR chain JSON file\")\n .requiredOption(\"-o, --output <dir>\", \"Output directory for generated SDK files\")\n .action(irGenTypesHandler);\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(\n \"-i, --ir <file>\",\n \"Path to IR JSON file (chain payload from 'schema ir', or legacy single-version IR)\",\n )\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 .requiredOption(\n \"-f, --file-system-type <type>\",\n \"File system type for the document type (ARTIFACTS or COMPASS)\",\n )\n .action(irDeployHandler);\n\n irCmd\n .command(\"asset\")\n .description(\n \"Generate document type asset JSON and a sibling schema compatibility range JSON from an IR file (advanced — most users should use 'ir deploy' instead). The minimum supported schema version is sourced from the IR payload's 'minSupportedVersion' field (set by 'schema ir --config <pack-config.json>'); legacy single-IR inputs default to min == max.\",\n )\n .requiredOption(\n \"-i, --ir <file>\",\n \"Path to IR JSON file (chain payload from 'schema ir', or legacy single-version IR)\",\n )\n .requiredOption(\"-o, --output <file>\", \"Output file path for asset JSON\")\n .option(\n \"-f, --file-system-type <type>\",\n \"File system type (ARTIFACTS or COMPASS)\",\n \"ARTIFACTS\",\n )\n .option(\n \"--compatibility-range-output <file>\",\n \"Output path for the schema compatibility range JSON (defaults to a sibling of --output with '-schema-compatibility-range' suffix)\",\n )\n .action(irGenAssetHandler);\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,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,iBAAiB,QAAQ,wBAAwB;AAC1D,SAASC,eAAe,QAAQ,sBAAsB;AAEt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AAC,CACAC,MAAM,CAACX,eAAe,CAAC;EAE1BO,KAAK,CACFC,OAAO,CAAC,OAAO,CAAC,CAChBC,WAAW,CACV,4VACF,CAAC,CACAC,cAAc,CACb,iBAAiB,EACjB,oFACF,CAAC,CACAA,cAAc,CAAC,qBAAqB,EAAE,iCAAiC,CAAC,CACxEE,MAAM,CACL,+BAA+B,EAC/B,yCAAyC,EACzC,WACF,CAAC,CACAA,MAAM,CACL,qCAAqC,EACrC,mIACF,CAAC,CACAD,MAAM,CAACV,iBAAiB,CAAC;AAC9B","ignoreList":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { CommanderError } from "commander";
|
|
18
|
+
import { resolveMinVersion } from "../../utils/schema/resolveSchemaChain.js";
|
|
19
|
+
function isChainPayload(parsed) {
|
|
20
|
+
return typeof parsed === "object" && parsed != null && "chain" in parsed && Array.isArray(parsed.chain) && typeof parsed.latestVersion === "number";
|
|
21
|
+
}
|
|
22
|
+
function resolveFromChain(payload, irPath) {
|
|
23
|
+
if (payload.chain.length === 0) {
|
|
24
|
+
throw new CommanderError(1, "EINVAL", `Invalid IR chain payload at ${irPath}: 'chain' is empty`);
|
|
25
|
+
}
|
|
26
|
+
const {
|
|
27
|
+
latestVersion,
|
|
28
|
+
minVersion
|
|
29
|
+
} = resolveMinVersion(payload.chain, payload.minSupportedVersion);
|
|
30
|
+
const latestEntry = payload.chain.find(c => c.version === latestVersion);
|
|
31
|
+
if (latestEntry == null) {
|
|
32
|
+
throw new CommanderError(1, "EINVAL", `IR chain payload at ${irPath} has no entry matching latestVersion ${latestVersion}`);
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
ir: latestEntry.ir,
|
|
36
|
+
latestVersion,
|
|
37
|
+
minSupportedVersion: minVersion
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function resolveFromSingleIr(ir) {
|
|
41
|
+
return {
|
|
42
|
+
ir,
|
|
43
|
+
latestVersion: ir.version,
|
|
44
|
+
minSupportedVersion: ir.version
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function resolveIrInput(parsed, irPath) {
|
|
48
|
+
return isChainPayload(parsed) ? resolveFromChain(parsed, irPath) : resolveFromSingleIr(parsed);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=resolveIrInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveIrInput.js","names":["CommanderError","resolveMinVersion","isChainPayload","parsed","Array","isArray","chain","latestVersion","resolveFromChain","payload","irPath","length","minVersion","minSupportedVersion","latestEntry","find","c","version","ir","resolveFromSingleIr","resolveIrInput"],"sources":["resolveIrInput.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { CommanderError } from \"commander\";\nimport type { IRealTimeDocumentSchema } from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { type IrChainPayload, resolveMinVersion } from \"../../utils/schema/resolveSchemaChain.js\";\n\nexport interface ResolvedIrInput {\n readonly ir: IRealTimeDocumentSchema;\n readonly latestVersion: number;\n readonly minSupportedVersion: number;\n}\n\nfunction isChainPayload(parsed: unknown): parsed is IrChainPayload {\n return (\n typeof parsed === \"object\"\n && parsed != null\n && \"chain\" in parsed\n && Array.isArray((parsed as IrChainPayload).chain)\n && typeof (parsed as IrChainPayload).latestVersion === \"number\"\n );\n}\n\nfunction resolveFromChain(payload: IrChainPayload, irPath: string): ResolvedIrInput {\n if (payload.chain.length === 0) {\n throw new CommanderError(\n 1,\n \"EINVAL\",\n `Invalid IR chain payload at ${irPath}: 'chain' is empty`,\n );\n }\n const { latestVersion, minVersion } = resolveMinVersion(\n payload.chain,\n payload.minSupportedVersion,\n );\n const latestEntry = payload.chain.find(c => c.version === latestVersion);\n if (latestEntry == null) {\n throw new CommanderError(\n 1,\n \"EINVAL\",\n `IR chain payload at ${irPath} has no entry matching latestVersion ${latestVersion}`,\n );\n }\n return { ir: latestEntry.ir, latestVersion, minSupportedVersion: minVersion };\n}\n\nfunction resolveFromSingleIr(ir: IRealTimeDocumentSchema): ResolvedIrInput {\n return { ir, latestVersion: ir.version, minSupportedVersion: ir.version };\n}\n\nexport function resolveIrInput(parsed: unknown, irPath: string): ResolvedIrInput {\n return isChainPayload(parsed)\n ? resolveFromChain(parsed, irPath)\n : resolveFromSingleIr(parsed as IRealTimeDocumentSchema);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,cAAc,QAAQ,WAAW;AAE1C,SAA8BC,iBAAiB,QAAQ,0CAA0C;AAQjG,SAASC,cAAcA,CAACC,MAAe,EAA4B;EACjE,OACE,OAAOA,MAAM,KAAK,QAAQ,IACvBA,MAAM,IAAI,IAAI,IACd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|
|
|
19
19
|
export function registerSchemaCommands(program) {
|
|
20
20
|
const schemaCmd = program.command("schema").description("Commands for working with TypeScript schema definitions");
|
|
21
21
|
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);
|
|
22
|
-
schemaCmd.command("ir").description("Resolve a TypeScript schema module to a versioned IR chain JSON file").requiredOption("-i, --input <file>", "Input TypeScript/JavaScript schema module").requiredOption("-o, --output <file>", "Output IR chain JSON file").requiredOption("--config <file>", "Path to the SDK's pack-config JSON file. Its optional 'minSupportedVersion' field declares the oldest schema version this SDK supports; omit the field to track latest only.").action(schemaIrHandler);
|
|
22
|
+
schemaCmd.command("ir").description("Resolve a TypeScript schema module to a versioned IR chain JSON file").requiredOption("-i, --input <file>", "Input TypeScript/JavaScript schema module").requiredOption("-o, --output <file>", "Output IR chain JSON file").requiredOption("--config <file>", "Path to the SDK's pack-config JSON file. Its optional 'minSupportedVersion' field declares the oldest schema version this SDK supports; omit the field to track latest only.").option("--max-version <version>", "Generate an IR chain capped at this schema version").action(schemaIrHandler);
|
|
23
23
|
}
|
|
24
24
|
//# sourceMappingURL=registerSchemaCommands.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerSchemaCommands.js","names":["schemaIrHandler","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 { schemaIrHandler } from \"./schemaIrHandler.js\";\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 schemaCmd\n .command(\"ir\")\n .description(\"Resolve a TypeScript schema module to a versioned IR chain JSON file\")\n .requiredOption(\"-i, --input <file>\", \"Input TypeScript/JavaScript schema module\")\n .requiredOption(\"-o, --output <file>\", \"Output IR chain JSON file\")\n .requiredOption(\n \"--config <file>\",\n \"Path to the SDK's pack-config JSON file. Its optional 'minSupportedVersion' field declares the oldest schema version this SDK supports; omit the field to track latest only.\",\n )\n .action(schemaIrHandler);\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,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;EAE9BG,SAAS,CACNC,OAAO,CAAC,IAAI,CAAC,CACbC,WAAW,CAAC,sEAAsE,CAAC,CACnFC,cAAc,CAAC,oBAAoB,EAAE,2CAA2C,CAAC,CACjFA,cAAc,CAAC,qBAAqB,EAAE,2BAA2B,CAAC,CAClEA,cAAc,CACb,iBAAiB,EACjB,8KACF,CAAC,
|
|
1
|
+
{"version":3,"file":"registerSchemaCommands.js","names":["schemaIrHandler","schemaToYamlHandler","registerSchemaCommands","program","schemaCmd","command","description","requiredOption","action","option"],"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 { schemaIrHandler } from \"./schemaIrHandler.js\";\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 schemaCmd\n .command(\"ir\")\n .description(\"Resolve a TypeScript schema module to a versioned IR chain JSON file\")\n .requiredOption(\"-i, --input <file>\", \"Input TypeScript/JavaScript schema module\")\n .requiredOption(\"-o, --output <file>\", \"Output IR chain JSON file\")\n .requiredOption(\n \"--config <file>\",\n \"Path to the SDK's pack-config JSON file. Its optional 'minSupportedVersion' field declares the oldest schema version this SDK supports; omit the field to track latest only.\",\n )\n .option(\n \"--max-version <version>\",\n \"Generate an IR chain capped at this schema version\",\n )\n .action(schemaIrHandler);\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,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;EAE9BG,SAAS,CACNC,OAAO,CAAC,IAAI,CAAC,CACbC,WAAW,CAAC,sEAAsE,CAAC,CACnFC,cAAc,CAAC,oBAAoB,EAAE,2CAA2C,CAAC,CACjFA,cAAc,CAAC,qBAAqB,EAAE,2BAA2B,CAAC,CAClEA,cAAc,CACb,iBAAiB,EACjB,8KACF,CAAC,CACAE,MAAM,CACL,yBAAyB,EACzB,oDACF,CAAC,CACAD,MAAM,CAACR,eAAe,CAAC;AAC5B","ignoreList":[]}
|
|
@@ -54,6 +54,15 @@ export async function readPackConfig(configPath) {
|
|
|
54
54
|
minSupportedVersion
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
+
function parseMaxVersion(maxVersion) {
|
|
58
|
+
if (maxVersion == null) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (!/^[1-9]\d*$/.test(maxVersion)) {
|
|
62
|
+
throw new Error(`--max-version must be a positive integer, got: ${JSON.stringify(maxVersion)}`);
|
|
63
|
+
}
|
|
64
|
+
return Number(maxVersion);
|
|
65
|
+
}
|
|
57
66
|
|
|
58
67
|
/**
|
|
59
68
|
* Resolve a TypeScript schema module to a versioned IR chain JSON file.
|
|
@@ -78,9 +87,9 @@ export async function readPackConfig(configPath) {
|
|
|
78
87
|
* downstream tools default to supporting only the latest schema version.
|
|
79
88
|
*
|
|
80
89
|
* Note: this is distinct from the legacy single-version IR JSON consumed by
|
|
81
|
-
* `ir
|
|
82
|
-
*
|
|
83
|
-
*
|
|
90
|
+
* `ir zod`, which is a bare `IRealTimeDocumentSchema` (no chain, no migrations).
|
|
91
|
+
* Tools that previously read that format should pick the entry matching
|
|
92
|
+
* `latestVersion` from `chain` and use its `ir` field.
|
|
84
93
|
*/
|
|
85
94
|
export async function schemaIrHandler(options) {
|
|
86
95
|
const {
|
|
@@ -88,6 +97,7 @@ export async function schemaIrHandler(options) {
|
|
|
88
97
|
output,
|
|
89
98
|
config
|
|
90
99
|
} = options;
|
|
100
|
+
const maxVersion = parseMaxVersion(options.maxVersion);
|
|
91
101
|
const {
|
|
92
102
|
documentTypeName,
|
|
93
103
|
documentTypeDescription,
|
|
@@ -105,7 +115,7 @@ export async function schemaIrHandler(options) {
|
|
|
105
115
|
} = resolveSchemaChain(schema, minSupportedVersion, {
|
|
106
116
|
name: documentTypeName,
|
|
107
117
|
description: documentTypeDescription
|
|
108
|
-
});
|
|
118
|
+
}, maxVersion);
|
|
109
119
|
const outputPath = path.resolve(output);
|
|
110
120
|
await fs.ensureDir(path.dirname(outputPath));
|
|
111
121
|
const payload = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaIrHandler.js","names":["consola","fs","path","GENERATED_JSON_COMMENT","loadSchemaModule","resolveSchemaChain","assertNonEmptyString","value","field","configPath","trim","Error","JSON","stringify","readRequiredNonEmptyString","readPackConfig","resolvedConfigPath","resolve","pathExists","config","readJson","documentTypeName","documentTypeDescription","minSupportedVersion","rawMin","Number","isInteger","schemaIrHandler","options","input","output","warn","info","schema","chain","latestVersion","name","description","outputPath","ensureDir","dirname","payload","__comment","writeFile","success","length"],"sources":["schemaIrHandler.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { consola } from \"consola\";\nimport fs from \"fs-extra\";\nimport path from \"path\";\nimport { GENERATED_JSON_COMMENT } from \"../../utils/generatedFileHeader.js\";\nimport { loadSchemaModule } from \"../../utils/schema/loadSchemaModule.js\";\nimport { resolveSchemaChain } from \"../../utils/schema/resolveSchemaChain.js\";\n\ninterface SchemaIrOptions {\n input: string;\n output: string;\n config: string;\n}\n\ninterface PackConfigLike {\n documentTypeName?: unknown;\n documentTypeDescription?: unknown;\n minSupportedVersion?: unknown;\n}\n\ninterface PackConfigValues {\n readonly documentTypeName: string;\n readonly documentTypeDescription: string;\n readonly minSupportedVersion?: number;\n}\n\nfunction assertNonEmptyString(value: unknown, field: string, configPath: string): string {\n if (typeof value !== \"string\" || value.trim() === \"\") {\n throw new Error(\n `'${field}' in ${configPath} must be a non-empty string, got: ${JSON.stringify(value)}`,\n );\n }\n return value;\n}\n\nfunction readRequiredNonEmptyString(\n value: unknown,\n field: string,\n configPath: string,\n): string {\n if (value == null) {\n throw new Error(\n `'${field}' is required in ${configPath} and must be a non-empty string`,\n );\n }\n return assertNonEmptyString(value, field, configPath);\n}\n\nexport async function readPackConfig(configPath: string): Promise<PackConfigValues> {\n const resolvedConfigPath = path.resolve(configPath);\n if (!(await fs.pathExists(resolvedConfigPath))) {\n throw new Error(`--config file not found: ${resolvedConfigPath}`);\n }\n const config = (await fs.readJson(resolvedConfigPath)) as PackConfigLike;\n\n const documentTypeName = readRequiredNonEmptyString(\n config.documentTypeName,\n \"documentTypeName\",\n resolvedConfigPath,\n );\n\n const documentTypeDescription = readRequiredNonEmptyString(\n config.documentTypeDescription,\n \"documentTypeDescription\",\n resolvedConfigPath,\n );\n\n let minSupportedVersion: number | undefined;\n const rawMin = config.minSupportedVersion;\n if (rawMin != null) {\n if (typeof rawMin !== \"number\" || !Number.isInteger(rawMin) || rawMin <= 0) {\n throw new Error(\n `'minSupportedVersion' in ${resolvedConfigPath} must be a positive integer, got: ${\n JSON.stringify(rawMin)\n }`,\n );\n }\n minSupportedVersion = rawMin;\n }\n\n return { documentTypeName, documentTypeDescription, minSupportedVersion };\n}\n\n/**\n * Resolve a TypeScript schema module to a versioned IR chain JSON file.\n *\n * The output is a `{ latestVersion, minSupportedVersion?, chain }` payload\n * where each entry is `{ version, ir, migrations? }` and `ir` is a\n * single-version `IRealTimeDocumentSchema`. This is the input format for\n * `ir gen-types` and `ir asset`.\n *\n * `--config <pack-config.json>` is required: the pack-config is the single\n * source of truth for document-type identity. Required fields:\n * - `documentTypeName`: the document type name embedded into each chain\n * entry's IR (and surfaced as `documentTypeName` by `ir asset`).\n * - `documentTypeDescription`: document type description embedded into each\n * chain entry's IR.\n * Optional fields:\n * - `minSupportedVersion`: declares the oldest version this SDK supports;\n * when set, it must match one of the chain entries' `version` values and is\n * embedded as `minSupportedVersion` in the payload so downstream consumers\n * (`ir gen-types`, `ir asset`) read the same value. Omitting the field is\n * an explicit opt-out: the IR will not include `minSupportedVersion` and\n * downstream tools default to supporting only the latest schema version.\n *\n * Note: this is distinct from the legacy single-version IR JSON consumed by\n * `ir deploy` / `ir zod`, which is a bare `IRealTimeDocumentSchema` (no chain,\n * no migrations). Tools that previously read that format should pick the\n * entry matching `latestVersion` from `chain` and use its `ir` field.\n */\nexport async function schemaIrHandler(options: SchemaIrOptions): Promise<void> {\n const { input, output, config } = options;\n const { documentTypeName, documentTypeDescription, minSupportedVersion } = await readPackConfig(\n config,\n );\n\n if (minSupportedVersion == null) {\n consola.warn(\n `--config ${\n path.resolve(config)\n } does not set 'minSupportedVersion'. The generated IR will not include it, so downstream tools (ir gen-types, ir asset) will default to supporting only the latest schema version. Add 'minSupportedVersion' to your pack-config to enable back-compat.`,\n );\n }\n\n consola.info(`Loading schema from: ${input}`);\n const schema = await loadSchemaModule(input);\n\n consola.info(\"Resolving versioned IR chain...\");\n const { chain, latestVersion } = resolveSchemaChain(schema, minSupportedVersion, {\n name: documentTypeName,\n description: documentTypeDescription,\n });\n\n const outputPath = path.resolve(output);\n await fs.ensureDir(path.dirname(outputPath));\n\n const payload = {\n __comment: GENERATED_JSON_COMMENT,\n latestVersion,\n ...(minSupportedVersion != null ? { minSupportedVersion } : {}),\n chain,\n };\n await fs.writeFile(outputPath, JSON.stringify(payload, null, 2) + \"\\n\", \"utf8\");\n\n consola.success(\n `Wrote IR chain (${chain.length} version(s), min=${\n minSupportedVersion ?? latestVersion\n }, max=${latestVersion}) to: ${outputPath}`,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,QAAQ,SAAS;AACjC,OAAOC,EAAE,MAAM,UAAU;AACzB,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,sBAAsB,QAAQ,oCAAoC;AAC3E,SAASC,gBAAgB,QAAQ,wCAAwC;AACzE,SAASC,kBAAkB,QAAQ,0CAA0C;AAoB7E,SAASC,oBAAoBA,CAACC,KAAc,EAAEC,KAAa,EAAEC,UAAkB,EAAU;EACvF,IAAI,OAAOF,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACG,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;IACpD,MAAM,IAAIC,KAAK,CACb,IAAIH,KAAK,QAAQC,UAAU,qCAAqCG,IAAI,CAACC,SAAS,CAACN,KAAK,CAAC,EACvF,CAAC;EACH;EACA,OAAOA,KAAK;AACd;AAEA,SAASO,0BAA0BA,CACjCP,KAAc,EACdC,KAAa,EACbC,UAAkB,E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zC,OAAO,CAAC4C,OAAO,CACb,mBAAmBV,KAAK,CAACW,MAAM,oBAC7BtB,mBAAmB,IAAIY,aAAa,SAC7BA,aAAa,SAASG,UAAU,EAC3C,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"schemaIrHandler.js","names":["consola","fs","path","GENERATED_JSON_COMMENT","loadSchemaModule","resolveSchemaChain","assertNonEmptyString","value","field","configPath","trim","Error","JSON","stringify","readRequiredNonEmptyString","readPackConfig","resolvedConfigPath","resolve","pathExists","config","readJson","documentTypeName","documentTypeDescription","minSupportedVersion","rawMin","Number","isInteger","parseMaxVersion","maxVersion","undefined","test","schemaIrHandler","options","input","output","warn","info","schema","chain","latestVersion","name","description","outputPath","ensureDir","dirname","payload","__comment","writeFile","success","length"],"sources":["schemaIrHandler.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { consola } from \"consola\";\nimport fs from \"fs-extra\";\nimport path from \"path\";\nimport { GENERATED_JSON_COMMENT } from \"../../utils/generatedFileHeader.js\";\nimport { loadSchemaModule } from \"../../utils/schema/loadSchemaModule.js\";\nimport { resolveSchemaChain } from \"../../utils/schema/resolveSchemaChain.js\";\n\ninterface SchemaIrOptions {\n input: string;\n output: string;\n config: string;\n maxVersion?: string;\n}\n\ninterface PackConfigLike {\n documentTypeName?: unknown;\n documentTypeDescription?: unknown;\n minSupportedVersion?: unknown;\n}\n\ninterface PackConfigValues {\n readonly documentTypeName: string;\n readonly documentTypeDescription: string;\n readonly minSupportedVersion?: number;\n}\n\nfunction assertNonEmptyString(value: unknown, field: string, configPath: string): string {\n if (typeof value !== \"string\" || value.trim() === \"\") {\n throw new Error(\n `'${field}' in ${configPath} must be a non-empty string, got: ${JSON.stringify(value)}`,\n );\n }\n return value;\n}\n\nfunction readRequiredNonEmptyString(\n value: unknown,\n field: string,\n configPath: string,\n): string {\n if (value == null) {\n throw new Error(\n `'${field}' is required in ${configPath} and must be a non-empty string`,\n );\n }\n return assertNonEmptyString(value, field, configPath);\n}\n\nexport async function readPackConfig(configPath: string): Promise<PackConfigValues> {\n const resolvedConfigPath = path.resolve(configPath);\n if (!(await fs.pathExists(resolvedConfigPath))) {\n throw new Error(`--config file not found: ${resolvedConfigPath}`);\n }\n const config = (await fs.readJson(resolvedConfigPath)) as PackConfigLike;\n\n const documentTypeName = readRequiredNonEmptyString(\n config.documentTypeName,\n \"documentTypeName\",\n resolvedConfigPath,\n );\n\n const documentTypeDescription = readRequiredNonEmptyString(\n config.documentTypeDescription,\n \"documentTypeDescription\",\n resolvedConfigPath,\n );\n\n let minSupportedVersion: number | undefined;\n const rawMin = config.minSupportedVersion;\n if (rawMin != null) {\n if (typeof rawMin !== \"number\" || !Number.isInteger(rawMin) || rawMin <= 0) {\n throw new Error(\n `'minSupportedVersion' in ${resolvedConfigPath} must be a positive integer, got: ${\n JSON.stringify(rawMin)\n }`,\n );\n }\n minSupportedVersion = rawMin;\n }\n\n return { documentTypeName, documentTypeDescription, minSupportedVersion };\n}\n\nfunction parseMaxVersion(maxVersion: string | undefined): number | undefined {\n if (maxVersion == null) {\n return undefined;\n }\n\n if (!/^[1-9]\\d*$/.test(maxVersion)) {\n throw new Error(\n `--max-version must be a positive integer, got: ${JSON.stringify(maxVersion)}`,\n );\n }\n\n return Number(maxVersion);\n}\n\n/**\n * Resolve a TypeScript schema module to a versioned IR chain JSON file.\n *\n * The output is a `{ latestVersion, minSupportedVersion?, chain }` payload\n * where each entry is `{ version, ir, migrations? }` and `ir` is a\n * single-version `IRealTimeDocumentSchema`. This is the input format for\n * `ir gen-types` and `ir asset`.\n *\n * `--config <pack-config.json>` is required: the pack-config is the single\n * source of truth for document-type identity. Required fields:\n * - `documentTypeName`: the document type name embedded into each chain\n * entry's IR (and surfaced as `documentTypeName` by `ir asset`).\n * - `documentTypeDescription`: document type description embedded into each\n * chain entry's IR.\n * Optional fields:\n * - `minSupportedVersion`: declares the oldest version this SDK supports;\n * when set, it must match one of the chain entries' `version` values and is\n * embedded as `minSupportedVersion` in the payload so downstream consumers\n * (`ir gen-types`, `ir asset`) read the same value. Omitting the field is\n * an explicit opt-out: the IR will not include `minSupportedVersion` and\n * downstream tools default to supporting only the latest schema version.\n *\n * Note: this is distinct from the legacy single-version IR JSON consumed by\n * `ir zod`, which is a bare `IRealTimeDocumentSchema` (no chain, no migrations).\n * Tools that previously read that format should pick the entry matching\n * `latestVersion` from `chain` and use its `ir` field.\n */\nexport async function schemaIrHandler(options: SchemaIrOptions): Promise<void> {\n const { input, output, config } = options;\n const maxVersion = parseMaxVersion(options.maxVersion);\n const { documentTypeName, documentTypeDescription, minSupportedVersion } = await readPackConfig(\n config,\n );\n\n if (minSupportedVersion == null) {\n consola.warn(\n `--config ${\n path.resolve(config)\n } does not set 'minSupportedVersion'. The generated IR will not include it, so downstream tools (ir gen-types, ir asset) will default to supporting only the latest schema version. Add 'minSupportedVersion' to your pack-config to enable back-compat.`,\n );\n }\n\n consola.info(`Loading schema from: ${input}`);\n const schema = await loadSchemaModule(input);\n\n consola.info(\"Resolving versioned IR chain...\");\n const { chain, latestVersion } = resolveSchemaChain(\n schema,\n minSupportedVersion,\n {\n name: documentTypeName,\n description: documentTypeDescription,\n },\n maxVersion,\n );\n\n const outputPath = path.resolve(output);\n await fs.ensureDir(path.dirname(outputPath));\n\n const payload = {\n __comment: GENERATED_JSON_COMMENT,\n latestVersion,\n ...(minSupportedVersion != null ? { minSupportedVersion } : {}),\n chain,\n };\n await fs.writeFile(outputPath, JSON.stringify(payload, null, 2) + \"\\n\", \"utf8\");\n\n consola.success(\n `Wrote IR chain (${chain.length} version(s), min=${\n minSupportedVersion ?? latestVersion\n }, max=${latestVersion}) to: ${outputPath}`,\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,OAAO,QAAQ,SAAS;AACjC,OAAOC,EAAE,MAAM,UAAU;AACzB,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,sBAAsB,QAAQ,oCAAoC;AAC3E,SAASC,gBAAgB,QAAQ,wCAAwC;AACzE,SAASC,kBAAkB,QAAQ,0CAA0C;AAqB7E,SAASC,oBAAoBA,CAACC,KAAc,EAAEC,KAAa,EAAEC,UAAkB,EAAU;EACvF,IAAI,OAAOF,KAAK,KAAK,QAAQ,IAAIA,KAAK,CAACG,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;IACpD,MAAM,IAAIC,KAAK,CACb,IAAIH,KAAK,QAAQC,UAAU,qCAAqCG,IAAI,CAACC,SAAS,CAACN,KAAK,CAAC,EACvF,CAAC;EACH;EACA,OAAOA,KAAK;AACd;AAEA,SAASO,0BAA0BA,CACjCP,KAAc,EACdC,KAAa,EACbC,UAAkB,EACV;EACR,IAAIF,KAAK,IAAI,IAAI,EAAE;IACjB,MAAM,IAAII,KAAK,CACb,IAAIH,KAAK,oBAAoBC,UAAU,iCACzC,CAAC;EACH;EACA,OAAOH,oBAAoB,CAACC,KAAK,EAAEC,KAAK,EAAEC,UAAU,CAAC;AACvD;AAEA,OAAO,eAAeM,cAAcA,CAACN,UAAkB,EAA6B;EAClF,MAAMO,kBAAkB,GAAGd,IAAI,CAACe,OAAO,CAACR,UAAU,CAAC;EACnD,IAAI,EAAE,MAAMR,EAAE,CAACiB,UAAU,CAACF,kBAAkB,CAAC,CAAC,EAAE;IAC9C,MAAM,IAAIL,KAAK,CAAC,4BAA4BK,kBAAkB,EAAE,CAAC;EACnE;EACA,MAAMG,MAAM,GAAI,MAAMlB,EAAE,CAAC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UAAU,EAC3C,CAAC;AACH","ignoreList":[]}
|
package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
/* Generated by @palantir/pack.document-schema.type-gen@0.14.0 */
|
|
2
2
|
|
|
3
3
|
import { Metadata } from '@palantir/pack.document-schema.model-types';
|
|
4
4
|
import { AnimalCatSchema, AnimalDogSchema, AnimalSchema, CatSchema, DogSchema } from './schema.js';
|
package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-discriminant.js","names":["Metadata","AnimalCatSchema","AnimalDogSchema","AnimalSchema","CatSchema","DogSchema","CatModel","__type","zodSchema","name","DogModel","AnimalModel","discriminant","AnimalCatModel","AnimalDogModel","DocumentModel","Cat","Dog","Animal","AnimalCat","AnimalDog","version"],"sources":["custom-discriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"custom-discriminant.js","names":["Metadata","AnimalCatSchema","AnimalDogSchema","AnimalSchema","CatSchema","DogSchema","CatModel","__type","zodSchema","name","DogModel","AnimalModel","discriminant","AnimalCatModel","AnimalDogModel","DocumentModel","Cat","Dog","Animal","AnimalCat","AnimalDog","version"],"sources":["custom-discriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.14.0 */\n\nimport type {\n DocumentSchema,\n RecordModel,\n UnionModel,\n} from '@palantir/pack.document-schema.model-types';\nimport { Metadata } from '@palantir/pack.document-schema.model-types';\nimport type { Animal, AnimalCat, AnimalDog, Cat, Dog } from './types.js';\nimport {\n AnimalCatSchema,\n AnimalDogSchema,\n AnimalSchema,\n CatSchema,\n DogSchema,\n} from './schema.js';\n\nexport interface CatModel extends RecordModel<Cat, typeof CatSchema> {}\nexport const CatModel: CatModel = {\n __type: {} as Cat,\n zodSchema: CatSchema,\n [Metadata]: {\n name: 'Cat',\n },\n};\n\nexport interface DogModel extends RecordModel<Dog, typeof DogSchema> {}\nexport const DogModel: DogModel = {\n __type: {} as Dog,\n zodSchema: DogSchema,\n [Metadata]: {\n name: 'Dog',\n },\n};\n\nexport interface AnimalModel extends UnionModel<Animal, typeof AnimalSchema> {}\nexport const AnimalModel: AnimalModel = {\n __type: {} as Animal,\n zodSchema: AnimalSchema,\n [Metadata]: {\n discriminant: 'kind',\n name: 'Animal',\n },\n};\n\nexport interface AnimalCatModel extends UnionModel<\n AnimalCat,\n typeof AnimalCatSchema\n> {}\nexport const AnimalCatModel: AnimalCatModel = {\n __type: {} as AnimalCat,\n zodSchema: AnimalCatSchema,\n [Metadata]: {\n discriminant: 'kind',\n name: 'AnimalCat',\n },\n};\n\nexport interface AnimalDogModel extends UnionModel<\n AnimalDog,\n typeof AnimalDogSchema\n> {}\nexport const AnimalDogModel: AnimalDogModel = {\n __type: {} as AnimalDog,\n zodSchema: AnimalDogSchema,\n [Metadata]: {\n discriminant: 'kind',\n name: 'AnimalDog',\n },\n};\n\nexport const DocumentModel = {\n Cat: CatModel,\n Dog: DogModel,\n Animal: AnimalModel,\n AnimalCat: AnimalCatModel,\n AnimalDog: AnimalDogModel,\n [Metadata]: {\n version: 1,\n },\n} as const satisfies DocumentSchema;\n\nexport type DocumentModel = typeof DocumentModel;\n"],"mappings":"AAAA;;AAOA,SAASA,QAAQ,QAAQ,4CAA4C;AAErE,SACEC,eAAe,EACfC,eAAe,EACfC,YAAY,EACZC,SAAS,EACTC,SAAS,QACJ,aAAa;AAGpB,OAAO,MAAMC,QAAkB,GAAG;EAChCC,MAAM,EAAE,CAAC,CAAQ;EACjBC,SAAS,EAAEJ,SAAS;EACpB,CAACJ,QAAQ,GAAG;IACVS,IAAI,EAAE;EACR;AACF,CAAC;AAGD,OAAO,MAAMC,QAAkB,GAAG;EAChCH,MAAM,EAAE,C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