@palantir/pack.document-schema.type-gen 0.12.0 → 0.13.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/ir/irGenTypesHandler.js +6 -6
- package/build/esm/commands/ir/irGenTypesHandler.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__/provenanceScenarios.test.js +184 -0
- package/build/esm/utils/schema/__tests__/provenanceScenarios.test.js.map +1 -0
- package/build/esm/utils/schema/__tests__/resolveSchemaChain.test.js +122 -0
- package/build/esm/utils/schema/__tests__/resolveSchemaChain.test.js.map +1 -0
- package/build/esm/utils/schema/generateInternalFromSchema.js +1 -1
- package/build/esm/utils/schema/generateInternalFromSchema.js.map +1 -1
- package/build/esm/utils/schema/generateScopeFromSchema.js +2 -2
- package/build/esm/utils/schema/generateScopeFromSchema.js.map +1 -1
- package/build/esm/utils/schema/loadSchemaModule.js +2 -5
- package/build/esm/utils/schema/loadSchemaModule.js.map +1 -1
- package/build/esm/utils/schema/resolveSchemaChain.js +98 -18
- 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/esm/utils/steps/convertStepsToIr.js +49 -24
- package/build/esm/utils/steps/convertStepsToIr.js.map +1 -1
- package/build/types/commands/ir/irGenTypesHandler.d.ts.map +1 -1
- package/build/types/utils/schema/__tests__/provenanceScenarios.test.d.ts +2 -0
- package/build/types/utils/schema/__tests__/provenanceScenarios.test.d.ts.map +1 -0
- package/build/types/utils/schema/__tests__/resolveSchemaChain.test.d.ts +2 -0
- package/build/types/utils/schema/__tests__/resolveSchemaChain.test.d.ts.map +1 -0
- package/build/types/utils/schema/loadSchemaModule.d.ts.map +1 -1
- package/build/types/utils/schema/resolveSchemaChain.d.ts +12 -0
- package/build/types/utils/schema/resolveSchemaChain.d.ts.map +1 -1
- package/build/types/utils/steps/convertStepsToIr.d.ts +19 -4
- package/build/types/utils/steps/convertStepsToIr.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveSchemaChain.js","names":["convertSchemaToIr","collectVersionedIrChain","input","identity","chain","current","type","unshift","version","ir","models","name","description","migrations","serializeMigrations","previous","undefined","result","modelKey","fields","Object","entries","fieldEntries","fieldName","migration","derivedFrom","resolveMinVersion","minSupportedVersion","length","Error","latestVersion","some","c","map","join","minVersion","resolveSchemaChain","schema","chainHasDerivedFields","entry","recordMigrations","values","fieldMigration"],"sources":["resolveSchemaChain.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 type { SchemaDefinition, VersionMigrations } from \"@palantir/pack.schema\";\nimport type { IRealTimeDocumentSchema } from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { convertSchemaToIr } from \"../steps/convertStepsToIr.js\";\n\n/** JSON-serializable form of a single field migration. */\nexport interface SerializedFieldMigration {\n readonly derivedFrom: readonly string[];\n}\n\n/** Serialized migrations keyed by `[recordModelName][fieldName]`. */\nexport type SerializedVersionMigrations = Record<\n string,\n Record<string, SerializedFieldMigration>\n>;\n\nexport interface VersionedIrEntry {\n version: number;\n ir: IRealTimeDocumentSchema;\n migrations?: SerializedVersionMigrations;\n}\n\nexport interface ResolvedIrChain {\n chain: VersionedIrEntry[];\n latestVersion: number;\n minVersion: number;\n}\n\nexport interface IrChainPayload {\n __comment?: string;\n latestVersion: number;\n minSupportedVersion?: number;\n chain: VersionedIrEntry[];\n}\n\nexport interface SchemaIdentity {\n readonly name?: string;\n readonly description?: string;\n}\n\nfunction collectVersionedIrChain(\n input: SchemaDefinition,\n identity: SchemaIdentity,\n): VersionedIrEntry[] {\n const chain: VersionedIrEntry[] = [];\n let current: SchemaDefinition = input;\n\n while (current.type === \"versioned\") {\n chain.unshift({\n version: current.version,\n ir: convertSchemaToIr(current.models, {\n version: current.version,\n name: identity.name,\n description: identity.description,\n }),\n migrations: serializeMigrations(current.migrations),\n });\n current = current.previous;\n }\n chain.unshift({\n version: current.version,\n ir: convertSchemaToIr(current.models, {\n version: current.version,\n name: identity.name,\n description: identity.description,\n }),\n });\n\n return chain;\n}\n\n/** Convert schema-builder migrations to their JSON-serializable form. */\nfunction serializeMigrations(\n migrations: VersionMigrations | undefined,\n): SerializedVersionMigrations | undefined {\n if (migrations == null) return undefined;\n const result: SerializedVersionMigrations = {};\n for (const [modelKey, fields] of Object.entries(migrations)) {\n const fieldEntries: Record<string, SerializedFieldMigration> = {};\n for (const [fieldName, migration] of Object.entries(fields)) {\n fieldEntries[fieldName] = {\n derivedFrom: [...migration.derivedFrom],\n };\n }\n result[modelKey] = fieldEntries;\n }\n return result;\n}\n\n/**\n * Validate `minSupportedVersion` against an already-resolved chain and return\n * the effective `minVersion`. Throws on invalid input.\n */\nexport function resolveMinVersion(\n chain: VersionedIrEntry[],\n minSupportedVersion: number | undefined,\n): { latestVersion: number; minVersion: number } {\n if (chain.length === 0) {\n throw new Error(\"Schema version chain is empty\");\n }\n\n const latestVersion = chain[chain.length - 1]!.version;\n\n if (minSupportedVersion != null && !chain.some(c => c.version === minSupportedVersion)) {\n throw new Error(\n `minSupportedVersion ${minSupportedVersion} is not in the schema chain `\n + `(available versions: ${chain.map(c => c.version).join(\", \")})`,\n );\n }\n\n return {\n latestVersion,\n minVersion: minSupportedVersion ?? latestVersion,\n };\n}\n\n/**\n * Collect the version chain and resolve min/latest versions.\n * Each version's models are converted to IR (IRealTimeDocumentSchema).\n * `identity.name` / `identity.description` are embedded into each chain entry's\n * IR; when omitted (e.g. test callers), `convertSchemaToIr` falls back to its\n * defaults.\n * Throws on empty chain or invalid minSupportedVersion.\n */\nexport function resolveSchemaChain(\n schema: SchemaDefinition,\n minSupportedVersion?: number,\n identity: SchemaIdentity = {},\n): ResolvedIrChain {\n const chain = collectVersionedIrChain(schema, identity);\n const { latestVersion, minVersion } = resolveMinVersion(chain, minSupportedVersion);\n return { chain, latestVersion, minVersion };\n}\n\n/**\n * True if any migration in the chain declares a non-empty `derivedFrom`. Drives\n * whether the generated SDK emits `DocumentModel` as a factory (requires the\n * app to supply typed upgrade functions) or as a const (no upgrade functions needed).\n */\nexport function chainHasDerivedFields(chain: VersionedIrEntry[]): boolean {\n for (const entry of chain) {\n if (entry.migrations == null) continue;\n for (const recordMigrations of Object.values(entry.migrations)) {\n for (const fieldMigration of Object.values(recordMigrations)) {\n if (fieldMigration.derivedFrom.length > 0) return true;\n }\n }\n }\n return false;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,SAASA,iBAAiB,QAAQ,8BAA8B;;AAEhE;;AAKA;;AA8BA,SAASC,uBAAuBA,CAC9BC,KAAuB,EACvBC,QAAwB,EACJ;EACpB,MAAMC,KAAyB,GAAG,EAAE;EACpC,IAAIC,OAAyB,GAAGH,KAAK;EAErC,OAAOG,OAAO,CAACC,IAAI,KAAK,WAAW,EAAE;IACnCF,KAAK,CAACG,OAAO,CAAC;MACZC,OAAO,EAAEH,OAAO,CAACG,OAAO;MACxBC,EAAE,EAAET,iBAAiB,CAACK,OAAO,CAACK,MAAM,EAAE;QACpCF,OAAO,EAAEH,OAAO,CAACG,OAAO;QACxBG,IAAI,EAAER,QAAQ,CAACQ,IAAI;QACnBC,WAAW,EAAET,QAAQ,CAACS;MACxB,CAAC,CAAC;MACFC,UAAU,EAAEC,mBAAmB,CAACT,OAAO,CAACQ,UAAU;IACpD,CAAC,CAAC;IACFR,OAAO,GAAGA,OAAO,CAACU,QAAQ;EAC5B;EACAX,KAAK,CAACG,OAAO,CAAC;IACZC,OAAO,EAAEH,OAAO,CAACG,OAAO;IACxBC,EAAE,EAAET,iBAAiB,CAACK,OAAO,CAACK,MAAM,EAAE;MACpCF,OAAO,EAAEH,OAAO,CAACG,OAAO;MACxBG,IAAI,EAAER,QAAQ,CAACQ,IAAI;MACnBC,WAAW,EAAET,QAAQ,CAACS;IACxB,CAAC;EACH,CAAC,CAAC;EAEF,OAAOR,KAAK;AACd;;AAEA;AACA,SAASU,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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASM,kBAAkBA,CAChCC,MAAwB,EACxBV,mBAA4B,EAC5BxB,QAAwB,GAAG,CAAC,CAAC,EACZ;EACjB,MAAMC,KAAK,GAAGH,uBAAuB,CAACoC,MAAM,EAAElC,QAAQ,CAAC;EACvD,MAAM;IAAE2B,aAAa;IAAEK;EAAW,CAAC,GAAGT,iBAAiB,CAACtB,KAAK,EAAEuB,mBAAmB,CAAC;EACnF,OAAO;IAAEvB,KAAK;IAAE0B,aAAa;IAAEK;EAAW,CAAC;AAC7C;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,qBAAqBA,CAAClC,KAAyB,EAAW;EACxE,KAAK,MAAMmC,KAAK,IAAInC,KAAK,EAAE;IACzB,IAAImC,KAAK,CAAC1B,UAAU,IAAI,IAAI,EAAE;IAC9B,KAAK,MAAM2B,gBAAgB,IAAIpB,MAAM,CAACqB,MAAM,CAACF,KAAK,CAAC1B,UAAU,CAAC,EAAE;MAC9D,KAAK,MAAM6B,cAAc,IAAItB,MAAM,CAACqB,MAAM,CAACD,gBAAgB,CAAC,EAAE;QAC5D,IAAIE,cAAc,CAACjB,WAAW,CAACG,MAAM,GAAG,CAAC,EAAE,OAAO,IAAI;MACxD;IACF;EACF;EACA,OAAO,KAAK;AACd","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"resolveSchemaChain.js","names":["IModelDef","IModelDefCtor","convertSchemaToIr","collectVersionedIrChain","input","identity","schemas","collectSchemaDefinitions","provenances","deriveProvenance","map","schema","index","version","ir","models","name","description","type","migrations","serializeMigrations","current","unshift","previous","firstModelVersions","Map","firstFieldVersions","modelVersions","fieldVersions","modelKey","modelDef","Object","entries","has","set","get","fieldVersionsForModel","fields","fieldKey","keys","length","deprecations","undefined","result","fieldEntries","fieldName","migration","derivedFrom","resolveMinVersion","chain","minSupportedVersion","Error","latestVersion","some","c","join","minVersion","resolveSchemaChain","stripDeprecatedFieldsForSdk","entry","record","filter","field","dep","metadata","deprecatedFromVersion","chainHasDerivedFields","recordMigrations","values","fieldMigration"],"sources":["resolveSchemaChain.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 type { SchemaDefinition, VersionMigrations } from \"@palantir/pack.schema\";\nimport type {\n IModelDef,\n IRealTimeDocumentSchema,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { IModelDef as IModelDefCtor } from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport type { SchemaProvenance } from \"../steps/convertStepsToIr.js\";\nimport { convertSchemaToIr } from \"../steps/convertStepsToIr.js\";\n\n/** JSON-serializable form of a single field migration. */\nexport interface SerializedFieldMigration {\n readonly derivedFrom: readonly string[];\n}\n\n/** Serialized migrations keyed by `[recordModelName][fieldName]`. */\nexport type SerializedVersionMigrations = Record<\n string,\n Record<string, SerializedFieldMigration>\n>;\n\nexport interface VersionedIrEntry {\n version: number;\n ir: IRealTimeDocumentSchema;\n migrations?: SerializedVersionMigrations;\n}\n\nexport interface ResolvedIrChain {\n chain: VersionedIrEntry[];\n latestVersion: number;\n minVersion: number;\n}\n\nexport interface IrChainPayload {\n __comment?: string;\n latestVersion: number;\n minSupportedVersion?: number;\n chain: VersionedIrEntry[];\n}\n\nexport interface SchemaIdentity {\n readonly name?: string;\n readonly description?: string;\n}\n\nfunction collectVersionedIrChain(\n input: SchemaDefinition,\n identity: SchemaIdentity,\n): VersionedIrEntry[] {\n const schemas = collectSchemaDefinitions(input);\n const provenances = deriveProvenance(schemas);\n\n return schemas.map((schema, index): VersionedIrEntry => ({\n version: schema.version,\n ir: convertSchemaToIr(\n schema.models,\n { version: schema.version, name: identity.name, description: identity.description },\n provenances[index]!,\n ),\n ...(schema.type === \"versioned\" ? { migrations: serializeMigrations(schema.migrations) } : {}),\n }));\n}\n\nfunction collectSchemaDefinitions(input: SchemaDefinition): SchemaDefinition[] {\n const schemas: SchemaDefinition[] = [];\n let current: SchemaDefinition = input;\n\n while (current.type === \"versioned\") {\n schemas.unshift(current);\n current = current.previous;\n }\n schemas.unshift(current);\n\n return schemas;\n}\n\n/**\n * Build field/model provenance by walking the version chain from oldest to\n * newest. The first version where a model key or record field appears is the\n * version stamped into IR metadata.\n */\nfunction deriveProvenance(schemas: readonly SchemaDefinition[]): SchemaProvenance[] {\n const firstModelVersions = new Map<string, number>();\n const firstFieldVersions = new Map<string, Map<string, number>>();\n\n return schemas.map(schema => {\n const modelVersions: Record<string, number> = {};\n const fieldVersions: Record<string, Record<string, number>> = {};\n\n for (const [modelKey, modelDef] of Object.entries(schema.models)) {\n if (!firstModelVersions.has(modelKey)) {\n firstModelVersions.set(modelKey, schema.version);\n }\n modelVersions[modelKey] = firstModelVersions.get(modelKey)!;\n\n if (modelDef.type !== \"record\") continue;\n\n let fieldVersionsForModel = firstFieldVersions.get(modelKey);\n if (fieldVersionsForModel == null) {\n fieldVersionsForModel = new Map<string, number>();\n firstFieldVersions.set(modelKey, fieldVersionsForModel);\n }\n\n const fields: Record<string, number> = {};\n for (const fieldKey of Object.keys(modelDef.fields)) {\n if (!fieldVersionsForModel.has(fieldKey)) {\n fieldVersionsForModel.set(fieldKey, schema.version);\n }\n fields[fieldKey] = fieldVersionsForModel.get(fieldKey)!;\n }\n\n if (Object.keys(fields).length > 0) {\n fieldVersions[modelKey] = fields;\n }\n }\n\n return {\n fieldVersions,\n modelVersions,\n deprecations: \"deprecations\" in schema ? schema.deprecations : undefined,\n };\n });\n}\n\n/** Convert schema-builder migrations to their JSON-serializable form. */\nfunction serializeMigrations(\n migrations: VersionMigrations | undefined,\n): SerializedVersionMigrations | undefined {\n if (migrations == null) return undefined;\n const result: SerializedVersionMigrations = {};\n for (const [modelKey, fields] of Object.entries(migrations)) {\n const fieldEntries: Record<string, SerializedFieldMigration> = {};\n for (const [fieldName, migration] of Object.entries(fields)) {\n fieldEntries[fieldName] = {\n derivedFrom: [...migration.derivedFrom],\n };\n }\n result[modelKey] = fieldEntries;\n }\n return result;\n}\n\n/**\n * Validate `minSupportedVersion` against an already-resolved chain and return\n * the effective `minVersion`. Throws on invalid input.\n */\nexport function resolveMinVersion(\n chain: VersionedIrEntry[],\n minSupportedVersion: number | undefined,\n): { latestVersion: number; minVersion: number } {\n if (chain.length === 0) {\n throw new Error(\"Schema version chain is empty\");\n }\n\n const latestVersion = chain[chain.length - 1]!.version;\n\n if (minSupportedVersion != null && !chain.some(c => c.version === minSupportedVersion)) {\n throw new Error(\n `minSupportedVersion ${minSupportedVersion} is not in the schema chain `\n + `(available versions: ${chain.map(c => c.version).join(\", \")})`,\n );\n }\n\n return {\n latestVersion,\n minVersion: minSupportedVersion ?? latestVersion,\n };\n}\n\n/**\n * Collect the version chain and resolve min/latest versions.\n * Each version's models are converted to IR (IRealTimeDocumentSchema).\n * `identity.name` / `identity.description` are embedded into each chain entry's\n * IR; when omitted (e.g. test callers), `convertSchemaToIr` falls back to its\n * defaults.\n * Throws on empty chain or invalid minSupportedVersion.\n */\nexport function resolveSchemaChain(\n schema: SchemaDefinition,\n minSupportedVersion?: number,\n identity: SchemaIdentity = {},\n): ResolvedIrChain {\n const chain = collectVersionedIrChain(schema, identity);\n const { latestVersion, minVersion } = resolveMinVersion(chain, minSupportedVersion);\n return { chain, latestVersion, minVersion };\n}\n\n/**\n * Return a copy of the chain with deprecated fields removed from every version\n * at or after the version in which they were deprecated.\n *\n * The SDK type generators (`writeAllSdkFiles` and friends) must treat a\n * deprecated field exactly as a removed field: it disappears from that version's\n * public read/write types and per-version internal types, and the prev/curr diff\n * records it as a `removedField` (driving the upgrade lens). The field is still\n * collected into the all-versions `__Internal` type from earlier versions, which\n * are left untouched.\n */\nexport function stripDeprecatedFieldsForSdk(chain: VersionedIrEntry[]): VersionedIrEntry[] {\n return chain.map((entry): VersionedIrEntry => {\n const models: Record<string, IModelDef> = {};\n for (const [modelKey, modelDef] of Object.entries(entry.ir.models)) {\n if (modelDef.type === \"record\") {\n const fields = modelDef.record.fields.filter(field => {\n const dep = field.metadata.deprecatedFromVersion;\n return dep == null || entry.version < dep;\n });\n models[modelKey] = IModelDefCtor.record({ ...modelDef.record, fields });\n } else {\n models[modelKey] = modelDef;\n }\n }\n return { ...entry, ir: { ...entry.ir, models } };\n });\n}\n\n/**\n * True if any migration in the chain declares a non-empty `derivedFrom`. Drives\n * whether the generated SDK emits `DocumentModel` as a factory (requires the\n * app to supply typed upgrade functions) or as a const (no upgrade functions needed).\n */\nexport function chainHasDerivedFields(chain: VersionedIrEntry[]): boolean {\n for (const entry of chain) {\n if (entry.migrations == null) continue;\n for (const recordMigrations of Object.values(entry.migrations)) {\n for (const fieldMigration of Object.values(recordMigrations)) {\n if (fieldMigration.derivedFrom.length > 0) return true;\n }\n }\n }\n return false;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,SAAS,IAAIC,aAAa,QAAQ,yDAAyD;AAEpG,SAASC,iBAAiB,QAAQ,8BAA8B;;AAEhE;;AAKA;;AA8BA,SAASC,uBAAuBA,CAC9BC,KAAuB,EACvBC,QAAwB,EACJ;EACpB,MAAMC,OAAO,GAAGC,wBAAwB,CAACH,KAAK,CAAC;EAC/C,MAAMI,WAAW,GAAGC,gBAAgB,CAACH,OAAO,CAAC;EAE7C,OAAOA,OAAO,CAACI,GAAG,CAAC,CAACC,MAAM,EAAEC,KAAK,MAAwB;IACvDC,OAAO,EAAEF,MAAM,CAACE,OAAO;IACvBC,EAAE,EAAEZ,iBAAiB,CACnBS,MAAM,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E;IACzB,IAAIU,KAAK,CAACxC,UAAU,IAAI,IAAI,EAAE;IAC9B,KAAK,MAAMgD,gBAAgB,IAAIpC,MAAM,CAACqC,MAAM,CAACT,KAAK,CAACxC,UAAU,CAAC,EAAE;MAC9D,KAAK,MAAMkD,cAAc,IAAItC,MAAM,CAACqC,MAAM,CAACD,gBAAgB,CAAC,EAAE;QAC5D,IAAIE,cAAc,CAACtB,WAAW,CAACP,MAAM,GAAG,CAAC,EAAE,OAAO,IAAI;MACxD;IACF;EACF;EACA,OAAO,KAAK;AACd","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrayFields.js","names":[],"sources":["arrayFields.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"arrayFields.js","names":[],"sources":["arrayFields.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.13.0 */\n\n\nexport interface Container {\n readonly items: readonly string[];\n readonly numbers: readonly number[];\n}\n\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customDiscriminant.js","names":["isAnimalCat","value","kind","isAnimalDog"],"sources":["customDiscriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"customDiscriminant.js","names":["isAnimalCat","value","kind","isAnimalDog"],"sources":["customDiscriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.13.0 */\n\n\n/**\n * A cat\n */\nexport interface Cat {\n readonly meow: string;\n readonly whiskers: number;\n}\n\n/**\n * A dog\n */\nexport interface Dog {\n readonly bark: string;\n readonly tailWags: number;\n}\n\nexport interface AnimalCat extends Cat {\n readonly kind: \"cat\";\n}\n\nexport interface AnimalDog extends Dog {\n readonly kind: \"dog\";\n}\n\nexport type Animal = AnimalCat | AnimalDog;\n\nexport function isAnimalCat(value: Animal): value is AnimalCat {\n return value.kind === \"cat\";\n}\n\nexport function isAnimalDog(value: Animal): value is AnimalDog {\n return value.kind === \"dog\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;AAgBA,OAAO,SAASA,WAAWA,CAACC,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B;AAEA,OAAO,SAASC,WAAWA,CAACF,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B","ignoreList":[]}
|
package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypeScriptInterfaces.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["generateTypeScriptInterfaces.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"generateTypeScriptInterfaces.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["generateTypeScriptInterfaces.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.13.0 */\n\n\n/**\n * Represents an edge in a graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly label?: string;\n readonly color?: string;\n}\n\n/**\n * Represents a text box in a graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"text-box\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"text-box\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;;AAiBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,UAAU;AAClC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.13.0 */\n\nimport type { DocumentRef, MediaRef, ObjectRef, UserRef } from \"@palantir/pack.document-schema.model-types\";\n\n/**\n * A record containing all reference types\n */\nexport interface Document {\n readonly id: string;\n readonly docRef: DocumentRef;\n readonly userRef: UserRef;\n readonly objectRef: ObjectRef;\n readonly mediaRef: MediaRef;\n readonly optionalDocRef?: DocumentRef;\n readonly docRefArray: readonly DocumentRef[];\n readonly userRefArray: readonly UserRef[];\n}\n\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleRecord.js","names":[],"sources":["simpleRecord.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"simpleRecord.js","names":[],"sources":["simpleRecord.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.13.0 */\n\n\n/**\n * A person record\n */\nexport interface Person {\n readonly name: string;\n readonly age: number;\n readonly email?: string;\n}\n\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleSteps.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["simpleSteps.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"simpleSteps.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["simpleSteps.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.13.0 */\n\n\n/**\n * A node in the graph\n */\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly object: string;\n readonly label?: string;\n readonly edges: readonly Edge[];\n}\n\n/**\n * A text box in the graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\n/**\n * An edge in the graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"textBox\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"textBox\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AASA;AACA;AACA;;AAOA;AACA;AACA;;AAgBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,SAAS;AACjC","ignoreList":[]}
|
|
@@ -18,6 +18,15 @@ import invariant from "tiny-invariant";
|
|
|
18
18
|
import { IFieldTypeUnion, IFieldValueUnion, IModelDef } from "../../lib/pack-docschema-api/pack-docschema-ir/index.js";
|
|
19
19
|
import { assertNever } from "../assertNever.js";
|
|
20
20
|
import { convertStepsToSchema } from "./convertStepsToSchema.js";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Per-field version provenance for a schema, keyed by model export key then
|
|
24
|
+
* field name. Supplied by the version-aware caller (`resolveSchemaChain`) so the
|
|
25
|
+
* IR records the version each field first appeared in (and any deprecation)
|
|
26
|
+
* instead of a placeholder. When omitted, fields fall back to the schema's
|
|
27
|
+
* top-level version (correct for single-version / steps-based callers).
|
|
28
|
+
*/
|
|
29
|
+
|
|
21
30
|
/**
|
|
22
31
|
* Converts migration steps to Palantir IR format
|
|
23
32
|
*/
|
|
@@ -35,9 +44,12 @@ export function convertStepsToIr(steps, metadata) {
|
|
|
35
44
|
}
|
|
36
45
|
|
|
37
46
|
/**
|
|
38
|
-
* Converts record and union definitions to Palantir IR format
|
|
47
|
+
* Converts record and union definitions to Palantir IR format. When
|
|
48
|
+
* `provenance` is supplied (by the version-aware caller), each field/model is
|
|
49
|
+
* stamped with the version it first appeared in and any deprecation; otherwise
|
|
50
|
+
* everything falls back to `metadata.version` (default 1).
|
|
39
51
|
*/
|
|
40
|
-
export function convertSchemaToIr(inputSchema, metadata) {
|
|
52
|
+
export function convertSchemaToIr(inputSchema, metadata, provenance) {
|
|
41
53
|
// Build a mapping from declared model name → export key so that union variant
|
|
42
54
|
// refs (which use declared model names) can be remapped to export keys.
|
|
43
55
|
const nameToExportKey = new Map();
|
|
@@ -46,68 +58,81 @@ export function convertSchemaToIr(inputSchema, metadata) {
|
|
|
46
58
|
!(existing == null) ? process.env.NODE_ENV !== "production" ? invariant(false, `Duplicate declared model name "${modelDef.name}": exported as both "${existing}" and "${exportKey}"`) : invariant(false) : void 0;
|
|
47
59
|
nameToExportKey.set(modelDef.name, exportKey);
|
|
48
60
|
}
|
|
61
|
+
const fallbackVersion = metadata?.version ?? 1;
|
|
49
62
|
const primaryModelKeys = [];
|
|
50
63
|
const models = new Map();
|
|
51
64
|
for (const [exportKey, modelDef] of Object.entries(inputSchema)) {
|
|
52
|
-
if (collectModels(exportKey, modelDef, nameToExportKey, models)) {
|
|
65
|
+
if (collectModels(exportKey, modelDef, nameToExportKey, models, fallbackVersion, provenance)) {
|
|
53
66
|
primaryModelKeys.push(exportKey);
|
|
54
67
|
}
|
|
55
68
|
}
|
|
56
69
|
return {
|
|
57
70
|
name: metadata?.name ?? "Generated Schema",
|
|
58
71
|
description: metadata?.description ?? "Schema generated from migration steps",
|
|
59
|
-
version:
|
|
72
|
+
version: fallbackVersion,
|
|
60
73
|
primaryModelKeys,
|
|
61
74
|
models: Object.fromEntries(models)
|
|
62
75
|
};
|
|
63
76
|
}
|
|
64
|
-
function collectModels(exportKey, modelDef, nameToExportKey, outModels) {
|
|
77
|
+
function collectModels(exportKey, modelDef, nameToExportKey, outModels, fallbackVersion, provenance) {
|
|
65
78
|
!!outModels.has(exportKey) ? process.env.NODE_ENV !== "production" ? invariant(false, `Duplicate model definition: ${exportKey}`) : invariant(false) : void 0;
|
|
66
79
|
switch (modelDef.type) {
|
|
67
80
|
case "record":
|
|
68
81
|
{
|
|
69
|
-
outModels.set(exportKey, IModelDef.record(convertRecordDefToIr(modelDef, exportKey, nameToExportKey)));
|
|
82
|
+
outModels.set(exportKey, IModelDef.record(convertRecordDefToIr(modelDef, exportKey, nameToExportKey, fallbackVersion, provenance)));
|
|
70
83
|
return true;
|
|
71
84
|
}
|
|
72
85
|
case "union":
|
|
73
86
|
{
|
|
74
|
-
outModels.set(exportKey, IModelDef.union(convertUnionDefToIr(modelDef, exportKey, nameToExportKey)));
|
|
87
|
+
outModels.set(exportKey, IModelDef.union(convertUnionDefToIr(modelDef, exportKey, nameToExportKey, fallbackVersion, provenance)));
|
|
75
88
|
return true;
|
|
76
89
|
}
|
|
77
90
|
default:
|
|
78
91
|
assertNever(modelDef);
|
|
79
92
|
}
|
|
80
93
|
}
|
|
81
|
-
export function convertRecordDefToIr(recordDef, exportKey, nameToExportKey) {
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
export function convertRecordDefToIr(recordDef, exportKey, nameToExportKey, fallbackVersion = 1, provenance) {
|
|
95
|
+
const modelKey = exportKey ?? recordDef.name;
|
|
96
|
+
const fieldVersions = provenance?.fieldVersions?.[modelKey];
|
|
97
|
+
const deprecations = provenance?.deprecations?.[modelKey];
|
|
98
|
+
const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]) => {
|
|
99
|
+
const dep = deprecations?.[fieldKey];
|
|
100
|
+
return {
|
|
101
|
+
key: fieldKey,
|
|
102
|
+
name: fieldKey,
|
|
103
|
+
description: undefined,
|
|
104
|
+
fieldType: convertTypeToFieldTypeUnion(fieldType, nameToExportKey),
|
|
105
|
+
metadata: {
|
|
106
|
+
addedInVersion: fieldVersions?.[fieldKey] ?? fallbackVersion,
|
|
107
|
+
...(dep != null ? {
|
|
108
|
+
deprecatedFromVersion: dep.fromVersion,
|
|
109
|
+
...(dep.message != null ? {
|
|
110
|
+
deprecatedMessage: dep.message
|
|
111
|
+
} : {})
|
|
112
|
+
} : {})
|
|
113
|
+
},
|
|
114
|
+
isOptional: fieldType.type === "optional" ? true : undefined
|
|
115
|
+
};
|
|
116
|
+
});
|
|
93
117
|
return {
|
|
94
|
-
key,
|
|
118
|
+
key: modelKey,
|
|
95
119
|
name: recordDef.name,
|
|
96
120
|
description: recordDef.docs ?? undefined,
|
|
97
121
|
fields
|
|
98
122
|
};
|
|
99
123
|
}
|
|
100
|
-
export function convertUnionDefToIr(unionDef, exportKey, nameToExportKey) {
|
|
101
|
-
const
|
|
124
|
+
export function convertUnionDefToIr(unionDef, exportKey, nameToExportKey, fallbackVersion = 1, provenance) {
|
|
125
|
+
const modelKey = exportKey ?? unionDef.name;
|
|
102
126
|
const variantEntries = Object.entries(unionDef.variants).map(([variantName, modelRef]) => [variantName, nameToExportKey?.get(modelRef.name) ?? modelRef.name]);
|
|
127
|
+
const unionAddedIn = provenance?.modelVersions?.[modelKey] ?? fallbackVersion;
|
|
103
128
|
return {
|
|
104
|
-
key,
|
|
129
|
+
key: modelKey,
|
|
105
130
|
name: unionDef.name,
|
|
106
131
|
description: unionDef.docs,
|
|
107
132
|
discriminant: unionDef.discriminant,
|
|
108
133
|
variants: Object.fromEntries(variantEntries),
|
|
109
134
|
metadata: {
|
|
110
|
-
addedInVersion:
|
|
135
|
+
addedInVersion: unionAddedIn
|
|
111
136
|
}
|
|
112
137
|
};
|
|
113
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertStepsToIr.js","names":["invariant","IFieldTypeUnion","IFieldValueUnion","IModelDef","assertNever","convertStepsToSchema","convertStepsToIr","steps","metadata","recordDefinitions","unionDefinitions","schema","Object","fromEntries","map","def","name","convertSchemaToIr","inputSchema","nameToExportKey","Map","exportKey","modelDef","entries","existing","get","process","env","NODE_ENV","set","primaryModelKeys","models","collectModels","push","description","version","outModels","has","type","record","convertRecordDefToIr","union","convertUnionDefToIr","recordDef","key","fields","fieldKey","fieldType","undefined","convertTypeToFieldTypeUnion","addedInVersion","isOptional","docs","unionDef","variantEntries","variants","variantName","modelRef","discriminant","schemaType","items","allowNullValue","elementType","item","array","value","convertTypeToFieldValueUnion","Error","boolean","docRef","documentTypeRids","double","mediaRef","object","interfaceTypeRids","objectTypeRids","modelKey","modelTypes","string","unmanagedJson","userRef"],"sources":["convertStepsToIr.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as P from \"@palantir/pack.schema\";\nimport invariant from \"tiny-invariant\";\nimport type {\n IModelTypeKey,\n IUnionVariantKey,\n} from \"../../lib/pack-docschema-api/pack-docschema-api\";\nimport type {\n IFieldDef,\n IRealTimeDocumentSchema,\n IRecordDef,\n IUnionDef,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport {\n IFieldTypeUnion,\n IFieldValueUnion,\n IModelDef,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { assertNever } from \"../assertNever.js\";\nimport { convertStepsToSchema } from \"./convertStepsToSchema.js\";\nimport type { MigrationStep } from \"./parseMigrationSteps.js\";\n\nexport interface SchemaMetadata {\n readonly name?: string;\n readonly description?: string;\n readonly version?: number;\n}\n\n/**\n * Converts migration steps to Palantir IR format\n */\nexport function convertStepsToIr(\n steps: readonly MigrationStep[],\n metadata?: SchemaMetadata,\n): IRealTimeDocumentSchema {\n // First convert steps to document-schema-api format\n const { recordDefinitions, unionDefinitions } = convertStepsToSchema(steps as MigrationStep[]);\n\n const schema = {\n ...Object.fromEntries(recordDefinitions.map(def => [def.name, def])),\n ...Object.fromEntries(unionDefinitions.map(def => [def.name, def])),\n };\n\n return convertSchemaToIr(schema, metadata);\n}\n\n/**\n * Converts record and union definitions to Palantir IR format\n */\nexport function convertSchemaToIr(\n inputSchema: P.Schema<P.ReturnedSchema>,\n metadata?: SchemaMetadata,\n): IRealTimeDocumentSchema {\n // Build a mapping from declared model name → export key so that union variant\n // refs (which use declared model names) can be remapped to export keys.\n const nameToExportKey = new Map<string, string>();\n for (const [exportKey, modelDef] of Object.entries(inputSchema)) {\n const existing = nameToExportKey.get(modelDef.name);\n invariant(\n existing == null,\n `Duplicate declared model name \"${modelDef.name}\": exported as both \"${existing}\" and \"${exportKey}\"`,\n );\n nameToExportKey.set(modelDef.name, exportKey);\n }\n\n const primaryModelKeys: IModelTypeKey[] = [];\n const models = new Map<IModelTypeKey, IModelDef>();\n\n for (const [exportKey, modelDef] of Object.entries(inputSchema)) {\n if (collectModels(exportKey, modelDef, nameToExportKey, models)) {\n primaryModelKeys.push(exportKey);\n }\n }\n\n return {\n name: metadata?.name ?? \"Generated Schema\",\n description: metadata?.description ?? \"Schema generated from migration steps\",\n version: metadata?.version ?? 1,\n primaryModelKeys,\n models: Object.fromEntries(models),\n };\n}\n\nfunction collectModels(\n exportKey: string,\n modelDef: P.ModelDef,\n nameToExportKey: Map<string, string>,\n outModels: Map<IModelTypeKey, IModelDef>,\n): boolean {\n invariant(\n !outModels.has(exportKey),\n `Duplicate model definition: ${exportKey}`,\n );\n\n switch (modelDef.type) {\n case \"record\": {\n outModels.set(\n exportKey,\n IModelDef.record(convertRecordDefToIr(modelDef, exportKey, nameToExportKey)),\n );\n return true;\n }\n case \"union\": {\n outModels.set(\n exportKey,\n IModelDef.union(convertUnionDefToIr(modelDef, exportKey, nameToExportKey)),\n );\n return true;\n }\n default:\n assertNever(modelDef);\n }\n}\n\nexport function convertRecordDefToIr(\n recordDef: P.RecordDef,\n exportKey?: string,\n nameToExportKey?: Map<string, string>,\n): IRecordDef {\n const key = exportKey ?? recordDef.name;\n const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]): IFieldDef => ({\n key: fieldKey,\n name: fieldKey,\n description: undefined,\n fieldType: convertTypeToFieldTypeUnion(fieldType, nameToExportKey),\n metadata: { addedInVersion: 1 },\n isOptional: fieldType.type === \"optional\" ? true : undefined,\n }));\n\n return {\n key,\n name: recordDef.name,\n description: recordDef.docs ?? undefined,\n fields,\n };\n}\n\nexport function convertUnionDefToIr(\n unionDef: P.UnionDef,\n exportKey?: string,\n nameToExportKey?: Map<string, string>,\n): IUnionDef {\n const key = exportKey ?? unionDef.name;\n const variantEntries = Object.entries(unionDef.variants).map((\n [variantName, modelRef],\n ) =>\n [\n variantName as IUnionVariantKey,\n (nameToExportKey?.get(modelRef.name) ?? modelRef.name) as IModelTypeKey,\n ] as const\n );\n\n return {\n key,\n name: unionDef.name,\n description: unionDef.docs,\n discriminant: unionDef.discriminant,\n variants: Object.fromEntries(variantEntries),\n metadata: { addedInVersion: 1 },\n };\n}\n\n// TODO: rename to convertSchemaTypeToFieldTypeUnion\nexport function convertTypeToFieldTypeUnion(\n schemaType: P.Type,\n nameToExportKey?: Map<string, string>,\n): IFieldTypeUnion {\n switch (schemaType.type) {\n case \"array\": {\n // P.Array.items is typed as TypeBase due to the generic; narrow via type field\n const items = schemaType.items as P.Type;\n const allowNullValue = items.type === \"optional\";\n const elementType: P.Type = allowNullValue ? (items as P.Optional).item as P.Type : items;\n return IFieldTypeUnion.array({\n allowNullValue,\n value: convertTypeToFieldValueUnion(elementType, nameToExportKey),\n });\n }\n\n case \"optional\":\n // Optional flag is handled at field level; unwrap and recurse on inner type\n return convertTypeToFieldTypeUnion(schemaType.item as P.Type, nameToExportKey);\n\n case \"boolean\":\n case \"docRef\":\n case \"double\":\n case \"mediaRef\":\n case \"objectRef\":\n case \"ref\":\n case \"string\":\n case \"unknown\":\n case \"userRef\":\n return IFieldTypeUnion.value(convertTypeToFieldValueUnion(schemaType, nameToExportKey));\n\n default:\n assertNever(schemaType);\n }\n}\n\nfunction convertTypeToFieldValueUnion(\n schemaType: P.Type,\n nameToExportKey?: Map<string, string>,\n): IFieldValueUnion {\n switch (schemaType.type) {\n case \"array\":\n throw new Error(\n \"Nested arrays are not supported in the IR. \"\n + \"Wrap the inner array in a record instead.\",\n );\n\n case \"boolean\":\n return IFieldValueUnion.boolean({});\n\n case \"docRef\":\n return IFieldValueUnion.docRef({\n documentTypeRids: [], // FIXME: confirm whether we will use rids in the deployed schema.\n });\n\n case \"double\":\n return IFieldValueUnion.double({});\n\n case \"mediaRef\":\n return IFieldValueUnion.mediaRef({});\n\n case \"objectRef\":\n return IFieldValueUnion.object({\n // FIXME: confirm whether we will use rids in the deployed schema.\n interfaceTypeRids: [],\n objectTypeRids: [],\n });\n\n case \"optional\":\n // Nested optional — unwrap and continue\n // TODO: probably warn? maybe throw\n return convertTypeToFieldValueUnion(schemaType.item as P.Type, nameToExportKey);\n\n case \"ref\": {\n const modelKey = nameToExportKey?.get(schemaType.name) ?? schemaType.name;\n return IFieldValueUnion.modelRef({ modelTypes: [modelKey as IModelTypeKey] });\n }\n\n case \"string\":\n return IFieldValueUnion.string({});\n\n case \"unknown\":\n return IFieldValueUnion.unmanagedJson({});\n\n case \"userRef\":\n return I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AU,CAAC;EAC3B;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"convertStepsToIr.js","names":["invariant","IFieldTypeUnion","IFieldValueUnion","IModelDef","assertNever","convertStepsToSchema","convertStepsToIr","steps","metadata","recordDefinitions","unionDefinitions","schema","Object","fromEntries","map","def","name","convertSchemaToIr","inputSchema","provenance","nameToExportKey","Map","exportKey","modelDef","entries","existing","get","process","env","NODE_ENV","set","fallbackVersion","version","primaryModelKeys","models","collectModels","push","description","outModels","has","type","record","convertRecordDefToIr","union","convertUnionDefToIr","recordDef","modelKey","fieldVersions","deprecations","fields","fieldKey","fieldType","dep","key","undefined","convertTypeToFieldTypeUnion","addedInVersion","deprecatedFromVersion","fromVersion","message","deprecatedMessage","isOptional","docs","unionDef","variantEntries","variants","variantName","modelRef","unionAddedIn","modelVersions","discriminant","schemaType","items","allowNullValue","elementType","item","array","value","convertTypeToFieldValueUnion","Error","boolean","docRef","documentTypeRids","double","mediaRef","object","interfaceTypeRids","objectTypeRids","modelTypes","string","unmanagedJson","userRef"],"sources":["convertStepsToIr.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as P from \"@palantir/pack.schema\";\nimport invariant from \"tiny-invariant\";\nimport type {\n IModelTypeKey,\n IUnionVariantKey,\n} from \"../../lib/pack-docschema-api/pack-docschema-api\";\nimport type {\n IFieldDef,\n IRealTimeDocumentSchema,\n IRecordDef,\n IUnionDef,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport {\n IFieldTypeUnion,\n IFieldValueUnion,\n IModelDef,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { assertNever } from \"../assertNever.js\";\nimport { convertStepsToSchema } from \"./convertStepsToSchema.js\";\nimport type { MigrationStep } from \"./parseMigrationSteps.js\";\n\nexport interface SchemaMetadata {\n readonly name?: string;\n readonly description?: string;\n readonly version?: number;\n}\n\n/**\n * Per-field version provenance for a schema, keyed by model export key then\n * field name. Supplied by the version-aware caller (`resolveSchemaChain`) so the\n * IR records the version each field first appeared in (and any deprecation)\n * instead of a placeholder. When omitted, fields fall back to the schema's\n * top-level version (correct for single-version / steps-based callers).\n */\nexport interface SchemaProvenance {\n readonly fieldVersions?: Record<string, Record<string, number>>;\n readonly modelVersions?: Record<string, number>;\n readonly deprecations?: P.VersionDeprecations;\n}\n\n/**\n * Converts migration steps to Palantir IR format\n */\nexport function convertStepsToIr(\n steps: readonly MigrationStep[],\n metadata?: SchemaMetadata,\n): IRealTimeDocumentSchema {\n // First convert steps to document-schema-api format\n const { recordDefinitions, unionDefinitions } = convertStepsToSchema(steps as MigrationStep[]);\n\n const schema = {\n ...Object.fromEntries(recordDefinitions.map(def => [def.name, def])),\n ...Object.fromEntries(unionDefinitions.map(def => [def.name, def])),\n };\n\n return convertSchemaToIr(schema, metadata);\n}\n\n/**\n * Converts record and union definitions to Palantir IR format. When\n * `provenance` is supplied (by the version-aware caller), each field/model is\n * stamped with the version it first appeared in and any deprecation; otherwise\n * everything falls back to `metadata.version` (default 1).\n */\nexport function convertSchemaToIr(\n inputSchema: P.Schema<P.ReturnedSchema>,\n metadata?: SchemaMetadata,\n provenance?: SchemaProvenance,\n): IRealTimeDocumentSchema {\n // Build a mapping from declared model name → export key so that union variant\n // refs (which use declared model names) can be remapped to export keys.\n const nameToExportKey = new Map<string, string>();\n for (const [exportKey, modelDef] of Object.entries(inputSchema)) {\n const existing = nameToExportKey.get(modelDef.name);\n invariant(\n existing == null,\n `Duplicate declared model name \"${modelDef.name}\": exported as both \"${existing}\" and \"${exportKey}\"`,\n );\n nameToExportKey.set(modelDef.name, exportKey);\n }\n const fallbackVersion = metadata?.version ?? 1;\n\n const primaryModelKeys: IModelTypeKey[] = [];\n const models = new Map<IModelTypeKey, IModelDef>();\n\n for (const [exportKey, modelDef] of Object.entries(inputSchema)) {\n if (collectModels(exportKey, modelDef, nameToExportKey, models, fallbackVersion, provenance)) {\n primaryModelKeys.push(exportKey);\n }\n }\n\n return {\n name: metadata?.name ?? \"Generated Schema\",\n description: metadata?.description ?? \"Schema generated from migration steps\",\n version: fallbackVersion,\n primaryModelKeys,\n models: Object.fromEntries(models),\n };\n}\n\nfunction collectModels(\n exportKey: string,\n modelDef: P.ModelDef,\n nameToExportKey: Map<string, string>,\n outModels: Map<IModelTypeKey, IModelDef>,\n fallbackVersion: number,\n provenance?: SchemaProvenance,\n): boolean {\n invariant(\n !outModels.has(exportKey),\n `Duplicate model definition: ${exportKey}`,\n );\n\n switch (modelDef.type) {\n case \"record\": {\n outModels.set(\n exportKey,\n IModelDef.record(\n convertRecordDefToIr(modelDef, exportKey, nameToExportKey, fallbackVersion, provenance),\n ),\n );\n return true;\n }\n case \"union\": {\n outModels.set(\n exportKey,\n IModelDef.union(\n convertUnionDefToIr(modelDef, exportKey, nameToExportKey, fallbackVersion, provenance),\n ),\n );\n return true;\n }\n default:\n assertNever(modelDef);\n }\n}\n\nexport function convertRecordDefToIr(\n recordDef: P.RecordDef,\n exportKey?: string,\n nameToExportKey?: Map<string, string>,\n fallbackVersion: number = 1,\n provenance?: SchemaProvenance,\n): IRecordDef {\n const modelKey = exportKey ?? recordDef.name;\n const fieldVersions = provenance?.fieldVersions?.[modelKey];\n const deprecations = provenance?.deprecations?.[modelKey];\n const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]): IFieldDef => {\n const dep = deprecations?.[fieldKey];\n return {\n key: fieldKey,\n name: fieldKey,\n description: undefined,\n fieldType: convertTypeToFieldTypeUnion(fieldType, nameToExportKey),\n metadata: {\n addedInVersion: fieldVersions?.[fieldKey] ?? fallbackVersion,\n ...(dep != null\n ? {\n deprecatedFromVersion: dep.fromVersion,\n ...(dep.message != null ? { deprecatedMessage: dep.message } : {}),\n }\n : {}),\n },\n isOptional: fieldType.type === \"optional\" ? true : undefined,\n };\n });\n\n return {\n key: modelKey,\n name: recordDef.name,\n description: recordDef.docs ?? undefined,\n fields,\n };\n}\n\nexport function convertUnionDefToIr(\n unionDef: P.UnionDef,\n exportKey?: string,\n nameToExportKey?: Map<string, string>,\n fallbackVersion: number = 1,\n provenance?: SchemaProvenance,\n): IUnionDef {\n const modelKey = exportKey ?? unionDef.name;\n const variantEntries = Object.entries(unionDef.variants).map((\n [variantName, modelRef],\n ) =>\n [\n variantName as IUnionVariantKey,\n (nameToExportKey?.get(modelRef.name) ?? modelRef.name) as IModelTypeKey,\n ] as const\n );\n\n const unionAddedIn = provenance?.modelVersions?.[modelKey] ?? fallbackVersion;\n\n return {\n key: modelKey,\n name: unionDef.name,\n description: unionDef.docs,\n discriminant: unionDef.discriminant,\n variants: Object.fromEntries(variantEntries),\n metadata: { addedInVersion: unionAddedIn },\n };\n}\n\n// TODO: rename to convertSchemaTypeToFieldTypeUnion\nexport function convertTypeToFieldTypeUnion(\n schemaType: P.Type,\n nameToExportKey?: Map<string, string>,\n): IFieldTypeUnion {\n switch (schemaType.type) {\n case \"array\": {\n // P.Array.items is typed as TypeBase due to the generic; narrow via type field\n const items = schemaType.items as P.Type;\n const allowNullValue = items.type === \"optional\";\n const elementType: P.Type = allowNullValue ? (items as P.Optional).item as P.Type : items;\n return IFieldTypeUnion.array({\n allowNullValue,\n value: convertTypeToFieldValueUnion(elementType, nameToExportKey),\n });\n }\n\n case \"optional\":\n // Optional flag is handled at field level; unwrap and recurse on inner type\n return convertTypeToFieldTypeUnion(schemaType.item as P.Type, nameToExportKey);\n\n case \"boolean\":\n case \"docRef\":\n case \"double\":\n case \"mediaRef\":\n case \"objectRef\":\n case \"ref\":\n case \"string\":\n case \"unknown\":\n case \"userRef\":\n return IFieldTypeUnion.value(convertTypeToFieldValueUnion(schemaType, nameToExportKey));\n\n default:\n assertNever(schemaType);\n }\n}\n\nfunction convertTypeToFieldValueUnion(\n schemaType: P.Type,\n nameToExportKey?: Map<string, string>,\n): IFieldValueUnion {\n switch (schemaType.type) {\n case \"array\":\n throw new Error(\n \"Nested arrays are not supported in the IR. \"\n + \"Wrap the inner array in a record instead.\",\n );\n\n case \"boolean\":\n return IFieldValueUnion.boolean({});\n\n case \"docRef\":\n return IFieldValueUnion.docRef({\n documentTypeRids: [], // FIXME: confirm whether we will use rids in the deployed schema.\n });\n\n case \"double\":\n return IFieldValueUnion.double({});\n\n case \"mediaRef\":\n return IFieldValueUnion.mediaRef({});\n\n case \"objectRef\":\n return IFieldValueUnion.object({\n // FIXME: confirm whether we will use rids in the deployed schema.\n interfaceTypeRids: [],\n objectTypeRids: [],\n });\n\n case \"optional\":\n // Nested optional — unwrap and continue\n // TODO: probably warn? maybe throw\n return convertTypeToFieldValueUnion(schemaType.item as P.Type, nameToExportKey);\n\n case \"ref\": {\n const modelKey = nameToExportKey?.get(schemaType.name) ?? schemaType.name;\n return IFieldValueUnion.modelRef({ modelTypes: [modelKey as IModelTypeKey] });\n }\n\n case \"string\":\n return IFieldValueUnion.string({});\n\n case \"unknown\":\n return IFieldValueUnion.unmanagedJson({});\n\n case \"userRef\":\n return IFieldValueUnion.userRef({});\n\n default:\n assertNever(schemaType);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,SAAS,MAAM,gBAAgB;AAWtC,SACEC,eAAe,EACfC,gBAAgB,EAChBC,SAAS,QACJ,yDAAyD;AAChE,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,oBAAoB,QAAQ,2BAA2B;;AAShE;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,K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K,KAAK;MAAE;QACV,MAAM0B,QAAQ,GAAG1B,eAAe,EAAEM,GAAG,CAAC6C,UAAU,CAACvD,IAAI,CAAC,IAAIuD,UAAU,CAACvD,IAAI;QACzE,OAAOd,gBAAgB,CAACiE,QAAQ,CAAC;UAAEqB,UAAU,EAAE,CAAC1C,QAAQ;QAAmB,CAAC,CAAC;MAC/E;IAEA,KAAK,QAAQ;MACX,OAAO5C,gBAAgB,CAACuF,MAAM,CAAC,CAAC,CAAC,CAAC;IAEpC,KAAK,SAAS;MACZ,OAAOvF,gBAAgB,CAACwF,aAAa,CAAC,CAAC,CAAC,CAAC;IAE3C,KAAK,SAAS;MACZ,OAAOxF,gBAAgB,CAACyF,OAAO,CAAC,CAAC,CAAC,CAAC;IAErC;MACEvF,WAAW,CAACmE,UAAU,CAAC;EAC3B;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"irGenTypesHandler.d.ts","sourceRoot":"","sources":["../../../../src/commands/ir/irGenTypesHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"irGenTypesHandler.d.ts","sourceRoot":"","sources":["../../../../src/commands/ir/irGenTypesHandler.ts"],"names":[],"mappings":"AA0BA,UAAU,iBAAiB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAsBjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provenanceScenarios.test.d.ts","sourceRoot":"","sources":["../../../../../src/utils/schema/__tests__/provenanceScenarios.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveSchemaChain.test.d.ts","sourceRoot":"","sources":["../../../../../src/utils/schema/__tests__/resolveSchemaChain.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadSchemaModule.d.ts","sourceRoot":"","sources":["../../../../src/utils/schema/loadSchemaModule.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"loadSchemaModule.d.ts","sourceRoot":"","sources":["../../../../src/utils/schema/loadSchemaModule.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAO9D;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,OAAO,GAAG,gBAAgB,CAc/E;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAOlF"}
|
|
@@ -43,6 +43,18 @@ export declare function resolveMinVersion(chain: VersionedIrEntry[], minSupporte
|
|
|
43
43
|
* Throws on empty chain or invalid minSupportedVersion.
|
|
44
44
|
*/
|
|
45
45
|
export declare function resolveSchemaChain(schema: SchemaDefinition, minSupportedVersion?: number, identity?: SchemaIdentity): ResolvedIrChain;
|
|
46
|
+
/**
|
|
47
|
+
* Return a copy of the chain with deprecated fields removed from every version
|
|
48
|
+
* at or after the version in which they were deprecated.
|
|
49
|
+
*
|
|
50
|
+
* The SDK type generators (`writeAllSdkFiles` and friends) must treat a
|
|
51
|
+
* deprecated field exactly as a removed field: it disappears from that version's
|
|
52
|
+
* public read/write types and per-version internal types, and the prev/curr diff
|
|
53
|
+
* records it as a `removedField` (driving the upgrade lens). The field is still
|
|
54
|
+
* collected into the all-versions `__Internal` type from earlier versions, which
|
|
55
|
+
* are left untouched.
|
|
56
|
+
*/
|
|
57
|
+
export declare function stripDeprecatedFieldsForSdk(chain: VersionedIrEntry[]): VersionedIrEntry[];
|
|
46
58
|
/**
|
|
47
59
|
* True if any migration in the chain declares a non-empty `derivedFrom`. Drives
|
|
48
60
|
* whether the generated SDK emits `DocumentModel` as a factory (requires the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveSchemaChain.d.ts","sourceRoot":"","sources":["../../../../src/utils/schema/resolveSchemaChain.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,uBAAuB,CAAC;AACjF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"resolveSchemaChain.d.ts","sourceRoot":"","sources":["../../../../src/utils/schema/resolveSchemaChain.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,uBAAuB,CAAC;AACjF,OAAO,KAAK,EAEV,uBAAuB,EACxB,MAAM,yDAAyD,CAAC;AAKjE,0DAA0D;AAC1D,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAED,qEAAqE;AACrE,MAAM,MAAM,2BAA2B,GAAG,MAAM,CAC9C,MAAM,EACN,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CACzC,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,uBAAuB,CAAC;IAC5B,UAAU,CAAC,EAAE,2BAA2B,CAAC;CAC1C;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,KAAK,EAAE,gBAAgB,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAmGD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,gBAAgB,EAAE,EACzB,mBAAmB,EAAE,MAAM,GAAG,SAAS,GACtC;IAAE,aAAa,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAkB/C;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,gBAAgB,EACxB,mBAAmB,CAAC,EAAE,MAAM,EAC5B,QAAQ,GAAE,cAAmB,GAC5B,eAAe,CAIjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CAgBzF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAUxE"}
|
|
@@ -7,15 +7,30 @@ export interface SchemaMetadata {
|
|
|
7
7
|
readonly description?: string;
|
|
8
8
|
readonly version?: number;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Per-field version provenance for a schema, keyed by model export key then
|
|
12
|
+
* field name. Supplied by the version-aware caller (`resolveSchemaChain`) so the
|
|
13
|
+
* IR records the version each field first appeared in (and any deprecation)
|
|
14
|
+
* instead of a placeholder. When omitted, fields fall back to the schema's
|
|
15
|
+
* top-level version (correct for single-version / steps-based callers).
|
|
16
|
+
*/
|
|
17
|
+
export interface SchemaProvenance {
|
|
18
|
+
readonly fieldVersions?: Record<string, Record<string, number>>;
|
|
19
|
+
readonly modelVersions?: Record<string, number>;
|
|
20
|
+
readonly deprecations?: P.VersionDeprecations;
|
|
21
|
+
}
|
|
10
22
|
/**
|
|
11
23
|
* Converts migration steps to Palantir IR format
|
|
12
24
|
*/
|
|
13
25
|
export declare function convertStepsToIr(steps: readonly MigrationStep[], metadata?: SchemaMetadata): IRealTimeDocumentSchema;
|
|
14
26
|
/**
|
|
15
|
-
* Converts record and union definitions to Palantir IR format
|
|
27
|
+
* Converts record and union definitions to Palantir IR format. When
|
|
28
|
+
* `provenance` is supplied (by the version-aware caller), each field/model is
|
|
29
|
+
* stamped with the version it first appeared in and any deprecation; otherwise
|
|
30
|
+
* everything falls back to `metadata.version` (default 1).
|
|
16
31
|
*/
|
|
17
|
-
export declare function convertSchemaToIr(inputSchema: P.Schema<P.ReturnedSchema>, metadata?: SchemaMetadata): IRealTimeDocumentSchema;
|
|
18
|
-
export declare function convertRecordDefToIr(recordDef: P.RecordDef, exportKey?: string, nameToExportKey?: Map<string, string
|
|
19
|
-
export declare function convertUnionDefToIr(unionDef: P.UnionDef, exportKey?: string, nameToExportKey?: Map<string, string
|
|
32
|
+
export declare function convertSchemaToIr(inputSchema: P.Schema<P.ReturnedSchema>, metadata?: SchemaMetadata, provenance?: SchemaProvenance): IRealTimeDocumentSchema;
|
|
33
|
+
export declare function convertRecordDefToIr(recordDef: P.RecordDef, exportKey?: string, nameToExportKey?: Map<string, string>, fallbackVersion?: number, provenance?: SchemaProvenance): IRecordDef;
|
|
34
|
+
export declare function convertUnionDefToIr(unionDef: P.UnionDef, exportKey?: string, nameToExportKey?: Map<string, string>, fallbackVersion?: number, provenance?: SchemaProvenance): IUnionDef;
|
|
20
35
|
export declare function convertTypeToFieldTypeUnion(schemaType: P.Type, nameToExportKey?: Map<string, string>): IFieldTypeUnion;
|
|
21
36
|
//# sourceMappingURL=convertStepsToIr.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertStepsToIr.d.ts","sourceRoot":"","sources":["../../../../src/utils/steps/convertStepsToIr.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,KAAK,CAAC,MAAM,uBAAuB,CAAC;AAMhD,OAAO,KAAK,EAEV,uBAAuB,EACvB,UAAU,EACV,SAAS,EACV,MAAM,yDAAyD,CAAC;AACjE,OAAO,EACL,eAAe,EAGhB,MAAM,yDAAyD,CAAC;AAGjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,WAAW,c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AAuB,CAUzB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,EACvC,QAAQ,CAAC,EAAE,cAAc,EACzB,UAAU,CAAC,EAAE,gBAAgB,GAC5B,uBAAuB,CA8BzB;AAuCD,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,CAAC,CAAC,SAAS,EACtB,SAAS,CAAC,EAAE,MAAM,EAClB,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,eAAe,GAAE,MAAU,EAC3B,UAAU,CAAC,EAAE,gBAAgB,GAC5B,UAAU,CA8BZ;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,CAAC,CAAC,QAAQ,EACpB,SAAS,CAAC,EAAE,MAAM,EAClB,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,eAAe,GAAE,MAAU,EAC3B,UAAU,CAAC,EAAE,gBAAgB,GAC5B,SAAS,CAqBX;AAGD,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,CAAC,CAAC,IAAI,EAClB,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,eAAe,CA+BjB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@palantir/pack.document-schema.type-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "TypeScript type generation from document schema",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@osdk/client": "^2.5.2",
|
|
21
|
-
"@osdk/foundry.pack": "^2.
|
|
21
|
+
"@osdk/foundry.pack": "^2.63.0",
|
|
22
22
|
"commander": "^14.0.0",
|
|
23
23
|
"conjure-client": "^2.15.0",
|
|
24
24
|
"consola": "^3.4.2",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"tiny-invariant": "^1.3.3",
|
|
28
28
|
"yaml": "^2.8.2",
|
|
29
29
|
"zod": "^4.1.13",
|
|
30
|
-
"@palantir/pack.schema": "0.
|
|
31
|
-
"@palantir/pack.
|
|
30
|
+
"@palantir/pack.document-schema.model-types": "~0.12.0",
|
|
31
|
+
"@palantir/pack.schema": "0.8.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/fs-extra": "^11.0.4",
|