@palantir/pack.document-schema.type-gen 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/build/esm/commands/ir/__tests__/irDeployFirstParty.test.js +1 -1
  2. package/build/esm/commands/ir/__tests__/irDeployFirstParty.test.js.map +1 -1
  3. package/build/esm/commands/ir/__tests__/irUpdateSchemaHandler.test.js +1 -1
  4. package/build/esm/commands/ir/__tests__/irUpdateSchemaHandler.test.js.map +1 -1
  5. package/build/esm/commands/ir/irDeployHandler.js +1 -1
  6. package/build/esm/commands/ir/irDeployHandler.js.map +1 -1
  7. package/build/esm/commands/ir/irGenAssetHandler.js.map +1 -1
  8. package/build/esm/commands/ir/irUpdateSchemaHandler.js +1 -1
  9. package/build/esm/commands/ir/irUpdateSchemaHandler.js.map +1 -1
  10. package/build/esm/lib/pack-docschema-api/pack-docschema-ir/unionDef.js.map +1 -1
  11. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js +1 -1
  12. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js.map +1 -1
  13. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js +1 -1
  14. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js.map +1 -1
  15. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js +1 -1
  16. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js.map +1 -1
  17. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js +1 -1
  18. package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js.map +1 -1
  19. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js +1 -1
  20. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js.map +1 -1
  21. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js +1 -1
  22. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js.map +1 -1
  23. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js +1 -1
  24. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js.map +1 -1
  25. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js +1 -1
  26. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js.map +1 -1
  27. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js +1 -1
  28. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js.map +1 -1
  29. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js +1 -1
  30. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js.map +1 -1
  31. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js +1 -1
  32. package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js.map +1 -1
  33. package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js +36 -0
  34. package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js.map +1 -1
  35. package/build/esm/utils/ir/convertIrToWireSchema.js +9 -7
  36. package/build/esm/utils/ir/convertIrToWireSchema.js.map +1 -1
  37. package/build/esm/utils/schema/__tests__/__snapshots__/generateDocumentTypeFromSchema/with-name-and-description.js +1 -1
  38. package/build/esm/utils/schema/__tests__/__snapshots__/generateDocumentTypeFromSchema/with-name-and-description.js.map +1 -1
  39. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/single-version.js.map +1 -1
  40. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/three-version-chain.js.map +1 -1
  41. package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js.map +1 -1
  42. package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js +31 -0
  43. package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js.map +1 -1
  44. package/build/esm/utils/schema/__tests__/resolveSchemaChain.test.js +47 -0
  45. package/build/esm/utils/schema/__tests__/resolveSchemaChain.test.js.map +1 -1
  46. package/build/esm/utils/schema/generateInternalFromSchema.js +7 -0
  47. package/build/esm/utils/schema/generateInternalFromSchema.js.map +1 -1
  48. package/build/esm/utils/schema/resolveSchemaChain.js +29 -1
  49. package/build/esm/utils/schema/resolveSchemaChain.js.map +1 -1
  50. package/build/esm/utils/steps/__tests__/__snapshots__/types/arrayFields.js.map +1 -1
  51. package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js +1 -1
  52. package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js.map +1 -1
  53. package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js +1 -1
  54. package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map +1 -1
  55. package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js.map +1 -1
  56. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleRecord.js.map +1 -1
  57. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js +1 -1
  58. package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js.map +1 -1
  59. package/build/esm/utils/steps/convertStepsToIr.js +20 -1
  60. package/build/esm/utils/steps/convertStepsToIr.js.map +1 -1
  61. package/build/types/commands/ir/irDeployHandler.d.ts +1 -1
  62. package/build/types/commands/ir/irDeployHandler.d.ts.map +1 -1
  63. package/build/types/commands/ir/irGenAssetHandler.d.ts +1 -1
  64. package/build/types/commands/ir/irGenAssetHandler.d.ts.map +1 -1
  65. package/build/types/commands/ir/irUpdateSchemaHandler.d.ts.map +1 -1
  66. package/build/types/lib/pack-docschema-api/pack-docschema-ir/unionDef.d.ts +3 -0
  67. package/build/types/lib/pack-docschema-api/pack-docschema-ir/unionDef.d.ts.map +1 -1
  68. package/build/types/utils/ir/convertIrToWireSchema.d.ts +2 -2
  69. package/build/types/utils/ir/convertIrToWireSchema.d.ts.map +1 -1
  70. package/build/types/utils/schema/generateInternalFromSchema.d.ts.map +1 -1
  71. package/build/types/utils/schema/resolveSchemaChain.d.ts.map +1 -1
  72. package/build/types/utils/steps/convertStepsToIr.d.ts +2 -0
  73. package/build/types/utils/steps/convertStepsToIr.d.ts.map +1 -1
  74. package/package.json +18 -4
@@ -1 +1 @@
1
- {"version":3,"file":"generateInternalFromSchema.js","names":["GENERATED_FILE_HEADER","convertFieldTypeToDescriptor","convertFieldTypeToInternalTypeScript","convertFieldTypeToInternalZod","chainNeedsUpgradeFns","getEntryMinorVersion","upgradeStepKey","internalSchemaName","internalTypeName","upgradesName","versionedInternalTypeName","sortedEntries","map","Array","from","entries","sort","a","b","localeCompare","getAddedInVersion","fieldInfo","Math","min","presentInVersions","collectRecordModels","chain","allRecordModels","Map","version","ir","modelKey","modelDef","Object","models","type","has","set","allFields","steps","model","get","field","record","fields","existing","key","fieldType","isOptional","Set","presentInEntries","alwaysOptional","everOptional","add","i","length","prevEntry","currEntry","currModelDef","prevModelDef","prevFields","f","currFields","addedFields","recordUpgrades","migrations","fieldKey","annotation","derivedFrom","removedFields","push","size","addedInVersion","addedInMinorVersion","totalEntries","values","generateInternalTypes","output","fieldName","tsType","optional","generatePerVersionInternalTypes","perModelVersions","list","sortedModels","versions","sortedFields","generateUpgrades","latestIr","hasRecords","hasUnions","some","m","imports","join","typeDescriptor","step","fieldMeta","d","union","discriminant","variantKey","variantModelKey","variants","generateInternalSchemaContent","zodType","generateUpgradeFns","perModel","neededTypes","currentIdx","findIndex","c","priorVersion","undefined","stepKey","currentVersion","sorted","currentType","returnType","priorType","pickKeys","generateInternalFromChain","resolved","stepChain","internalTypes","upgrades","internalSchema","internalUpgradeFns"],"sources":["generateInternalFromSchema.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 {\n IFieldDef,\n IFieldTypeUnion,\n IRealTimeDocumentSchema,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { GENERATED_FILE_HEADER } from \"../generatedFileHeader.js\";\nimport {\n convertFieldTypeToDescriptor,\n convertFieldTypeToInternalTypeScript,\n convertFieldTypeToInternalZod,\n} from \"../ir/irFieldHelpers.js\";\nimport {\n chainNeedsUpgradeFns,\n getEntryMinorVersion,\n type ResolvedIrChain,\n upgradeStepKey,\n type VersionedIrEntry,\n} from \"./resolveSchemaChain.js\";\nimport {\n internalSchemaName,\n internalTypeName,\n upgradesName,\n versionedInternalTypeName,\n} from \"./runtimeSchema.js\";\n\nexport interface InternalTypesOutput {\n /** _internal/types.ts content */\n internalTypes: string;\n /** _internal/upgrades.ts content */\n upgrades: string;\n /** _internal/schema.ts content */\n internalSchema: string;\n /** _internal/upgradeFns.ts content */\n internalUpgradeFns: string;\n}\n\n/** Collected info about all fields for a model across all versions. */\ninterface AllFieldInfo {\n fieldType: IFieldTypeUnion;\n isOptional: boolean;\n /** Major versions where this field exists. */\n presentInVersions: Set<number>;\n /** How many versions have this field, counting 3.0, 3.1 and 3.2 separately. Fewer than all → optional. */\n presentInEntries: number;\n /** Whether field is always optional. */\n alwaysOptional: boolean;\n /** Whether field is optional in at least one version. */\n everOptional: boolean;\n}\n\n/**\n * Represents an upgrade step for a model between version transitions.\n *\n * `fields` only contains entries that require lens treatment — derived fields\n * (`derivedFrom.length > 0`) and required additive fields (`derivedFrom.length\n * === 0 && !isOptional`). Optional additive fields are absent because\n * `undefined` is a legal value at the current version and the lens has no\n * work to do.\n */\ninterface UpgradeStep {\n addedInVersion: number;\n addedInMinorVersion: number;\n fields: Map<string, UpgradeStepField>;\n removedFields: string[];\n}\n\ninterface UpgradeStepField {\n derivedFrom: string[];\n isOptional: boolean;\n}\n\ninterface RecordModelInfo {\n allFields: Map<string, AllFieldInfo>;\n steps: UpgradeStep[];\n}\n\n/**\n * Helper to iterate sorted entries of a Map.\n */\nfunction sortedEntries<V>(map: Map<string, V>): [string, V][] {\n return Array.from(map.entries()).sort(([a], [b]) => a.localeCompare(b));\n}\n\nfunction getAddedInVersion(fieldInfo: AllFieldInfo): number {\n return Math.min(...fieldInfo.presentInVersions);\n}\n\n/**\n * Collect all record model info across all versions and compute upgrade steps.\n * Takes the full chain (with minor versions), so a field added in 1.1 gets its\n * own step and counts as missing from 1.0 records.\n */\nfunction collectRecordModels(\n chain: VersionedIrEntry[],\n): Map<string, RecordModelInfo> {\n const allRecordModels = new Map<string, RecordModelInfo>();\n\n // Initialize models from all versions\n for (const { version, ir } of chain) {\n for (const [modelKey, modelDef] of Object.entries(ir.models)) {\n if (modelDef.type !== \"record\") continue;\n\n if (!allRecordModels.has(modelKey)) {\n allRecordModels.set(modelKey, {\n allFields: new Map(),\n steps: [],\n });\n }\n\n const model = allRecordModels.get(modelKey)!;\n\n for (const field of modelDef.record.fields) {\n const existing = model.allFields.get(field.key);\n if (existing == null) {\n model.allFields.set(field.key, {\n fieldType: field.fieldType,\n isOptional: field.isOptional === true,\n presentInVersions: new Set([version]),\n presentInEntries: 1,\n alwaysOptional: field.isOptional === true,\n everOptional: field.isOptional === true,\n });\n } else {\n existing.presentInVersions.add(version);\n existing.presentInEntries += 1;\n if (field.isOptional !== true) {\n existing.alwaysOptional = false;\n }\n if (field.isOptional === true) {\n existing.everOptional = true;\n }\n }\n }\n }\n }\n\n // Compute upgrade steps from version diffs\n for (let i = 1; i < chain.length; i++) {\n const prevEntry = chain[i - 1]!;\n const currEntry = chain[i]!;\n\n for (const [modelKey, currModelDef] of Object.entries(currEntry.ir.models)) {\n if (currModelDef.type !== \"record\") continue;\n\n const prevModelDef = prevEntry.ir.models[modelKey];\n if (prevModelDef == null || prevModelDef.type !== \"record\") continue;\n\n const model = allRecordModels.get(modelKey);\n if (model == null) continue;\n\n const prevFields = new Set(prevModelDef.record.fields.map(f => f.key));\n const currFields = new Set(currModelDef.record.fields.map(f => f.key));\n\n // Fields added in this version that require lens treatment. Optional\n // additive fields are skipped — `undefined` is a legal v_current value\n // for them, so the lens has nothing to invent.\n const addedFields = new Map<string, UpgradeStepField>();\n const recordUpgrades = currEntry.migrations?.[modelKey];\n for (const field of currModelDef.record.fields) {\n const fieldKey = field.key;\n if (prevFields.has(fieldKey)) continue;\n const isOptional = field.isOptional === true;\n const annotation = recordUpgrades?.[fieldKey];\n const derivedFrom = annotation != null ? [...annotation.derivedFrom] : [];\n if (derivedFrom.length === 0 && isOptional) continue;\n addedFields.set(fieldKey, { derivedFrom, isOptional });\n }\n\n // Fields absent from this version relative to the previous one (i.e. deprecated fields).\n const removedFields: string[] = [];\n for (const fieldKey of prevFields) {\n if (!currFields.has(fieldKey)) {\n removedFields.push(fieldKey);\n }\n }\n\n if (addedFields.size > 0 || removedFields.length > 0) {\n model.steps.push({\n addedInVersion: currEntry.version,\n addedInMinorVersion: getEntryMinorVersion(currEntry),\n fields: addedFields,\n removedFields,\n });\n }\n }\n }\n\n // Mark fields that are not present in ALL versions as optional in internal type\n const totalEntries = chain.length;\n for (const model of allRecordModels.values()) {\n for (const [, fieldInfo] of model.allFields) {\n if (fieldInfo.presentInEntries < totalEntries) {\n fieldInfo.alwaysOptional = true;\n }\n }\n }\n\n return allRecordModels;\n}\n\n/**\n * Generate _internal/types.ts content.\n */\nfunction generateInternalTypes(\n allRecordModels: Map<string, RecordModelInfo>,\n): string {\n let output = GENERATED_FILE_HEADER;\n output += \"\\n\";\n\n for (const [modelKey, model] of sortedEntries(allRecordModels)) {\n output += `/** Internal representation containing all fields across all schema versions. */\\n`;\n output += `export interface ${internalTypeName(modelKey)} {\\n`;\n\n for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {\n const tsType = convertFieldTypeToInternalTypeScript(\n fieldInfo.fieldType,\n fieldInfo.isOptional,\n );\n const optional = fieldInfo.alwaysOptional ? \"?\" : \"\";\n output += ` readonly ${fieldName}${optional}: ${tsType};\\n`;\n }\n\n output += \"}\\n\\n\";\n }\n\n return output;\n}\n\n/**\n * Generate per-version internal interfaces (e.g. `ShapeBox__v1`, `ShapeBox__v2`).\n *\n * Each interface contains only the fields present in that version, with their\n * actual optionality taken straight from that version's IR. The downstream\n * `DocumentUpgradeFns` generator uses these so each upgrade function's\n * parameter can `Pick` the prior version's fields and its return type can\n * index the current version's field type precisely.\n */\nfunction generatePerVersionInternalTypes(\n chain: VersionedIrEntry[],\n): string {\n // Group by model so each model's versions appear together in ascending order.\n const perModelVersions = new Map<\n string,\n { version: number; fields: readonly IFieldDef[] }[]\n >();\n\n for (const { version, ir } of chain) {\n for (const [modelKey, modelDef] of Object.entries(ir.models)) {\n if (modelDef.type !== \"record\") continue;\n let list = perModelVersions.get(modelKey);\n if (list == null) {\n list = [];\n perModelVersions.set(modelKey, list);\n }\n list.push({ version, fields: modelDef.record.fields });\n }\n }\n\n let output = \"\";\n const sortedModels = Array.from(perModelVersions.entries()).sort(([a], [b]) =>\n a.localeCompare(b)\n );\n for (const [modelKey, versions] of sortedModels) {\n for (const { version, fields } of versions) {\n output += `/** Internal representation of ${modelKey} at schema version ${version}. */\\n`;\n output += `export interface ${versionedInternalTypeName(modelKey, version)} {\\n`;\n const sortedFields = [...fields].sort((a, b) => a.key.localeCompare(b.key));\n for (const field of sortedFields) {\n const tsType = convertFieldTypeToInternalTypeScript(\n field.fieldType,\n field.isOptional === true,\n );\n const optional = field.isOptional === true ? \"?\" : \"\";\n output += ` readonly ${field.key}${optional}: ${tsType};\\n`;\n }\n output += \"}\\n\\n\";\n }\n }\n return output;\n}\n\n/**\n * Generate _internal/upgrades.ts content.\n */\nfunction generateUpgrades(\n allRecordModels: Map<string, RecordModelInfo>,\n latestIr: IRealTimeDocumentSchema,\n): string {\n let output = GENERATED_FILE_HEADER;\n\n const hasRecords = allRecordModels.size > 0;\n const hasUnions = Object.values(latestIr.models).some(m => m.type === \"union\");\n\n const imports: string[] = [];\n if (hasRecords) imports.push(\"UpgradeRegistry\");\n if (hasUnions) imports.push(\"UnionUpgradeRegistry\");\n\n if (imports.length > 0) {\n output += `import type { ${\n imports.join(\", \")\n } } from \"@palantir/pack.document-schema.model-types\";\\n\\n`;\n }\n\n for (const [modelKey, model] of sortedEntries(allRecordModels)) {\n output += `export const ${upgradesName(modelKey)}: UpgradeRegistry<\"${modelKey}\"> = {\\n`;\n output += ` modelName: \"${modelKey}\",\\n`;\n\n // allFields\n output += ` allFields: {\\n`;\n for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {\n const typeDescriptor = convertFieldTypeToDescriptor(\n fieldInfo.fieldType,\n fieldInfo.isOptional,\n );\n output += ` ${fieldName}: { type: ${typeDescriptor}, addedInVersion: ${\n getAddedInVersion(fieldInfo)\n } },\\n`;\n }\n output += ` },\\n`;\n\n // steps\n output += ` steps: [\\n`;\n for (const step of model.steps) {\n output += ` {\\n`;\n output += ` addedInVersion: ${step.addedInVersion},\\n`;\n if (step.addedInMinorVersion > 0) {\n output += ` addedInMinorVersion: ${step.addedInMinorVersion},\\n`;\n }\n output += ` fields: {\\n`;\n for (const [fieldName, fieldMeta] of step.fields) {\n output += ` ${fieldName}: {\\n`;\n output += ` derivedFrom: [${\n fieldMeta.derivedFrom.map(d => `\"${d}\"`).join(\", \")\n }],\\n`;\n output += ` },\\n`;\n }\n output += ` },\\n`;\n if (step.removedFields.length > 0) {\n output += ` removedFields: [${step.removedFields.map(f => `\"${f}\"`).join(\", \")}],\\n`;\n }\n output += ` },\\n`;\n }\n output += ` ],\\n`;\n\n output += `};\\n\\n`;\n }\n\n // Generate UnionUpgradeRegistry entries for union models\n for (const [modelKey, modelDef] of Object.entries(latestIr.models)) {\n if (modelDef.type !== \"union\") continue;\n\n const union = modelDef.union;\n output += `export const ${upgradesName(modelKey)}: UnionUpgradeRegistry<\"${modelKey}\"> = {\\n`;\n output += ` modelName: \"${modelKey}\",\\n`;\n output += ` discriminant: \"${union.discriminant}\",\\n`;\n output += ` variants: {\\n`;\n for (const [variantKey, variantModelKey] of Object.entries(union.variants)) {\n output += ` \"${variantKey}\": \"${variantModelKey}\",\\n`;\n }\n output += ` },\\n`;\n output += `};\\n\\n`;\n }\n\n return output;\n}\n\n/**\n * Generate _internal/schema.ts content.\n */\nfunction generateInternalSchemaContent(\n allRecordModels: Map<string, RecordModelInfo>,\n): string {\n let output = GENERATED_FILE_HEADER;\n output += `import { z } from \"zod\";\\n\\n`;\n\n for (const [modelKey, model] of sortedEntries(allRecordModels)) {\n output += `export const ${internalSchemaName(modelKey)} = z.object({\\n`;\n\n for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {\n // Use everOptional: a field optional in ANY version must stay optional\n // in the internal schema because older documents may legitimately omit it.\n const zodType = convertFieldTypeToInternalZod(\n fieldInfo.fieldType,\n fieldInfo.alwaysOptional || fieldInfo.everOptional,\n );\n output += ` ${fieldName}: ${zodType},\\n`;\n }\n\n output += `}).passthrough();\\n\\n`;\n }\n\n return output;\n}\n\n/**\n * Generate _internal/upgradeFns.ts content: a typed `DocumentUpgradeFns`\n * interface enumerating every upgrade function the app must supply at boot.\n *\n * For each `(modelName, v${version}, fieldName)` triple in a step's `fields`,\n * emit one property:\n * - Derived (`derivedFrom.length > 0`):\n * `(oldFields: Pick<<Model>__v<prior>, derivedFrom[number]>) => <Model>__v<current>[fieldName]`.\n * - Required additive (`derivedFrom.length === 0`):\n * `() => <Model>__v<current>[fieldName]`.\n *\n * Optional additive fields are filtered out at step-collection time and don't\n * appear here — `undefined` is a legal v<current> value for them, so the app\n * has no obligation to invent one.\n *\n * The interface is consumed by the generated `DocumentModel` factory in\n * `models.ts`, which requires it as a parameter when the schema needs any\n * upgrade functions. Schemas with no required fields added past v1 emit an\n * empty interface (still exported for type-uniformity in downstream code).\n */\nfunction generateUpgradeFns(\n chain: VersionedIrEntry[],\n allRecordModels: Map<string, RecordModelInfo>,\n): string {\n interface UpgradeFnEntry {\n fieldName: string;\n derivedFrom: readonly string[];\n }\n interface StepEntry {\n stepKey: string;\n currentVersion: number;\n priorVersion: number | undefined;\n fields: UpgradeFnEntry[];\n }\n\n const perModel = new Map<string, StepEntry[]>();\n const neededTypes = new Set<string>();\n\n for (const [modelKey, model] of sortedEntries(allRecordModels)) {\n for (const step of model.steps) {\n // A derived field's function takes the previous major's type, e.g. `Pick<ShapeBox__v1, \"color\">`\n // for a 2.0 step. Minor versions can't use `derivedFrom`, so minor steps never need it.\n const currentIdx = chain.findIndex(c => c.version === step.addedInVersion);\n const priorVersion = currentIdx > 0 ? chain[currentIdx - 1]!.version : undefined;\n\n const fields: UpgradeFnEntry[] = [];\n for (const [fieldName, fieldMeta] of step.fields) {\n fields.push({ fieldName, derivedFrom: [...fieldMeta.derivedFrom] });\n }\n if (fields.length === 0) continue;\n if (priorVersion == null && fields.some(f => f.derivedFrom.length > 0)) continue;\n\n let list = perModel.get(modelKey);\n if (list == null) {\n list = [];\n perModel.set(modelKey, list);\n }\n list.push({\n stepKey: upgradeStepKey(step.addedInVersion, step.addedInMinorVersion),\n currentVersion: step.addedInVersion,\n priorVersion,\n fields,\n });\n // Prior-version type only needed when at least one field derives from it.\n if (priorVersion != null && fields.some(f => f.derivedFrom.length > 0)) {\n neededTypes.add(versionedInternalTypeName(modelKey, priorVersion));\n }\n neededTypes.add(versionedInternalTypeName(modelKey, step.addedInVersion));\n }\n }\n\n let output = GENERATED_FILE_HEADER;\n output += `\\n`;\n\n if (neededTypes.size > 0) {\n const sorted = Array.from(neededTypes).sort();\n output += `import type { ${sorted.join(\", \")} } from \"./types.js\";\\n\\n`;\n }\n\n output += `/**\\n`;\n output += ` * Typed upgrade functions the application must supply at boot. Coverage is\\n`;\n output +=\n ` * exhaustive: missing or extra entries fail type-check at the \\`DocumentModel(...)\\`\\n`;\n output += ` * call site. Derived fields receive their declared source fields; required\\n`;\n output += ` * additive fields receive no arguments. Optional additive fields are absent\\n`;\n output += ` * — \\`undefined\\` is a legal value at the new version, so the runtime lens\\n`;\n output += ` * leaves them alone. Keys are \\`v2\\` for version 2.0 and \\`v2_1\\` for 2.1.\\n`;\n output += ` */\\n`;\n if (perModel.size === 0) {\n output += `// eslint-disable-next-line @typescript-eslint/no-empty-object-type\\n`;\n output += `export interface DocumentUpgradeFns {}\\n`;\n } else {\n output += `export interface DocumentUpgradeFns {\\n`;\n for (\n const [modelKey, steps] of Array.from(perModel.entries()).sort(([a], [b]) =>\n a.localeCompare(b)\n )\n ) {\n output += ` ${modelKey}: {\\n`;\n for (const step of steps) {\n output += ` ${step.stepKey}: {\\n`;\n const currentType = versionedInternalTypeName(modelKey, step.currentVersion);\n for (const f of step.fields) {\n const returnType = `${currentType}[\"${f.fieldName}\"]`;\n if (f.derivedFrom.length === 0) {\n output += ` ${f.fieldName}: () => ${returnType};\\n`;\n } else {\n // Steps with derived fields always have a prior version (others are skipped above).\n const priorType = versionedInternalTypeName(modelKey, step.priorVersion!);\n const pickKeys = f.derivedFrom.map(d => `\"${d}\"`).join(\" | \");\n output +=\n ` ${f.fieldName}: (oldFields: Pick<${priorType}, ${pickKeys}>) => ${returnType};\\n`;\n }\n }\n output += ` };\\n`;\n }\n output += ` };\\n`;\n }\n output += `}\\n`;\n }\n\n return output;\n}\n\n/**\n * Generate _internal/types.ts, _internal/upgrades.ts, _internal/schema.ts and\n * _internal/upgradeFns.ts from an already-resolved versioned IR chain.\n */\nexport function generateInternalFromChain(\n resolved: ResolvedIrChain,\n): InternalTypesOutput {\n const { chain } = resolved;\n const stepChain = resolved.stepChain ?? chain;\n const latestIr = chain[chain.length - 1]!.ir;\n\n const allRecordModels = collectRecordModels(stepChain);\n\n const internalTypes = generateInternalTypes(allRecordModels)\n + (chainNeedsUpgradeFns(stepChain) ? generatePerVersionInternalTypes(chain) : \"\");\n const upgrades = generateUpgrades(allRecordModels, latestIr);\n const internalSchema = generateInternalSchemaContent(allRecordModels);\n const internalUpgradeFns = generateUpgradeFns(chain, allRecordModels);\n\n return { internalTypes, upgrades, internalSchema, internalUpgradeFns };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,qBAAqB,QAAQ,2BAA2B;AACjE,SACEC,4BAA4B,EAC5BC,oCAAoC,EACpCC,6BAA6B,QACxB,yBAAyB;AAChC,SACEC,oBAAoB,EACpBC,oBAAoB,EAEpBC,cAAc,QAET,yBAAyB;AAChC,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,YAAY,EACZC,yBAAyB,QACpB,oBAAoB;;AAa3B;;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA;AACA;AACA;AACA,SAASC,aAAaA,CAAIC,GAAmB,EAAiB;EAC5D,OAAOC,KAAK,CAACC,IAAI,CAACF,GAAG,CAACG,OAAO,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,CAACC,CAAC,CAAC,EAAE,CAACC,CAAC,CAAC,KAAKD,CAAC,CAACE,aAAa,CAACD,CAAC,CAAC,CAAC;AACzE;AAEA,SAASE,iBAAiBA,CAACC,SAAuB,EAAU;EAC1D,OAAOC,IAAI,CAACC,GAAG,CAAC,GAAGF,SAAS,CAACG,iBAAiB,CAAC;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASC,mBAAmBA,CAC1BC,KAAyB,EACK;EAC9B,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAA0B,CAAC;;EAE1D;EACA,KAAK,MAAM;I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AI,QAAQ;IACpB;IACAA,MAAM,IAAI,KAAK;EACjB;EAEA,OAAOA,MAAM;AACf;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAAS4C,yBAAyBA,CACvCC,QAAyB,EACJ;EACrB,MAAM;IAAEhG;EAAM,CAAC,GAAGgG,QAAQ;EAC1B,MAAMC,SAAS,GAAGD,QAAQ,CAACC,SAAS,IAAIjG,KAAK;EAC7C,MAAM8D,QAAQ,GAAG9D,KAAK,CAACA,KAAK,CAAC6B,MAAM,GAAG,CAAC,CAAC,CAAEzB,EAAE;EAE5C,MAAMH,eAAe,GAAGF,mBAAmB,CAACkG,SAAS,CAAC;EAEtD,MAAMC,aAAa,GAAGhD,qBAAqB,CAACjD,eAAe,CAAC,IACvDvB,oBAAoB,CAACuH,SAAS,CAAC,GAAG1C,+BAA+B,CAACvD,KAAK,CAAC,GAAG,EAAE,CAAC;EACnF,MAAMmG,QAAQ,GAAGtC,gBAAgB,CAAC5D,eAAe,EAAE6D,QAAQ,CAAC;EAC5D,MAAMsC,cAAc,GAAGtB,6BAA6B,CAAC7E,eAAe,CAAC;EACrE,MAAMoG,kBAAkB,GAAGrB,kBAAkB,CAAChF,KAAK,EAAEC,eAAe,CAAC;EAErE,OAAO;IAAEiG,aAAa;IAAEC,QAAQ;IAAEC,cAAc;IAAEC;EAAmB,CAAC;AACxE","ignoreList":[]}
1
+ {"version":3,"file":"generateInternalFromSchema.js","names":["GENERATED_FILE_HEADER","convertFieldTypeToDescriptor","convertFieldTypeToInternalTypeScript","convertFieldTypeToInternalZod","chainNeedsUpgradeFns","getEntryMinorVersion","upgradeStepKey","internalSchemaName","internalTypeName","upgradesName","versionedInternalTypeName","sortedEntries","map","Array","from","entries","sort","a","b","localeCompare","getAddedInVersion","fieldInfo","Math","min","presentInVersions","collectRecordModels","chain","allRecordModels","Map","version","ir","modelKey","modelDef","Object","models","type","has","set","allFields","steps","model","get","field","record","fields","existing","key","fieldType","isOptional","Set","presentInEntries","alwaysOptional","everOptional","add","i","length","prevEntry","currEntry","currModelDef","prevModelDef","prevFields","f","currFields","addedFields","recordUpgrades","migrations","fieldKey","annotation","derivedFrom","removedFields","push","size","addedInVersion","addedInMinorVersion","totalEntries","values","generateInternalTypes","output","fieldName","tsType","optional","generatePerVersionInternalTypes","perModelVersions","list","sortedModels","versions","sortedFields","generateUpgrades","latestIr","hasRecords","hasUnions","some","m","imports","join","typeDescriptor","step","fieldMeta","d","union","discriminant","variantKey","variantModelKey","variants","variantMetadata","meta","generateInternalSchemaContent","zodType","generateUpgradeFns","perModel","neededTypes","currentIdx","findIndex","c","priorVersion","undefined","stepKey","currentVersion","sorted","currentType","returnType","priorType","pickKeys","generateInternalFromChain","resolved","stepChain","internalTypes","upgrades","internalSchema","internalUpgradeFns"],"sources":["generateInternalFromSchema.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 {\n IFieldDef,\n IFieldTypeUnion,\n IRealTimeDocumentSchema,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { GENERATED_FILE_HEADER } from \"../generatedFileHeader.js\";\nimport {\n convertFieldTypeToDescriptor,\n convertFieldTypeToInternalTypeScript,\n convertFieldTypeToInternalZod,\n} from \"../ir/irFieldHelpers.js\";\nimport {\n chainNeedsUpgradeFns,\n getEntryMinorVersion,\n type ResolvedIrChain,\n upgradeStepKey,\n type VersionedIrEntry,\n} from \"./resolveSchemaChain.js\";\nimport {\n internalSchemaName,\n internalTypeName,\n upgradesName,\n versionedInternalTypeName,\n} from \"./runtimeSchema.js\";\n\nexport interface InternalTypesOutput {\n /** _internal/types.ts content */\n internalTypes: string;\n /** _internal/upgrades.ts content */\n upgrades: string;\n /** _internal/schema.ts content */\n internalSchema: string;\n /** _internal/upgradeFns.ts content */\n internalUpgradeFns: string;\n}\n\n/** Collected info about all fields for a model across all versions. */\ninterface AllFieldInfo {\n fieldType: IFieldTypeUnion;\n isOptional: boolean;\n /** Major versions where this field exists. */\n presentInVersions: Set<number>;\n /** How many versions have this field, counting 3.0, 3.1 and 3.2 separately. Fewer than all → optional. */\n presentInEntries: number;\n /** Whether field is always optional. */\n alwaysOptional: boolean;\n /** Whether field is optional in at least one version. */\n everOptional: boolean;\n}\n\n/**\n * Represents an upgrade step for a model between version transitions.\n *\n * `fields` only contains entries that require lens treatment — derived fields\n * (`derivedFrom.length > 0`) and required additive fields (`derivedFrom.length\n * === 0 && !isOptional`). Optional additive fields are absent because\n * `undefined` is a legal value at the current version and the lens has no\n * work to do.\n */\ninterface UpgradeStep {\n addedInVersion: number;\n addedInMinorVersion: number;\n fields: Map<string, UpgradeStepField>;\n removedFields: string[];\n}\n\ninterface UpgradeStepField {\n derivedFrom: string[];\n isOptional: boolean;\n}\n\ninterface RecordModelInfo {\n allFields: Map<string, AllFieldInfo>;\n steps: UpgradeStep[];\n}\n\n/**\n * Helper to iterate sorted entries of a Map.\n */\nfunction sortedEntries<V>(map: Map<string, V>): [string, V][] {\n return Array.from(map.entries()).sort(([a], [b]) => a.localeCompare(b));\n}\n\nfunction getAddedInVersion(fieldInfo: AllFieldInfo): number {\n return Math.min(...fieldInfo.presentInVersions);\n}\n\n/**\n * Collect all record model info across all versions and compute upgrade steps.\n * Takes the full chain (with minor versions), so a field added in 1.1 gets its\n * own step and counts as missing from 1.0 records.\n */\nfunction collectRecordModels(\n chain: VersionedIrEntry[],\n): Map<string, RecordModelInfo> {\n const allRecordModels = new Map<string, RecordModelInfo>();\n\n // Initialize models from all versions\n for (const { version, ir } of chain) {\n for (const [modelKey, modelDef] of Object.entries(ir.models)) {\n if (modelDef.type !== \"record\") continue;\n\n if (!allRecordModels.has(modelKey)) {\n allRecordModels.set(modelKey, {\n allFields: new Map(),\n steps: [],\n });\n }\n\n const model = allRecordModels.get(modelKey)!;\n\n for (const field of modelDef.record.fields) {\n const existing = model.allFields.get(field.key);\n if (existing == null) {\n model.allFields.set(field.key, {\n fieldType: field.fieldType,\n isOptional: field.isOptional === true,\n presentInVersions: new Set([version]),\n presentInEntries: 1,\n alwaysOptional: field.isOptional === true,\n everOptional: field.isOptional === true,\n });\n } else {\n existing.presentInVersions.add(version);\n existing.presentInEntries += 1;\n if (field.isOptional !== true) {\n existing.alwaysOptional = false;\n }\n if (field.isOptional === true) {\n existing.everOptional = true;\n }\n }\n }\n }\n }\n\n // Compute upgrade steps from version diffs\n for (let i = 1; i < chain.length; i++) {\n const prevEntry = chain[i - 1]!;\n const currEntry = chain[i]!;\n\n for (const [modelKey, currModelDef] of Object.entries(currEntry.ir.models)) {\n if (currModelDef.type !== \"record\") continue;\n\n const prevModelDef = prevEntry.ir.models[modelKey];\n if (prevModelDef == null || prevModelDef.type !== \"record\") continue;\n\n const model = allRecordModels.get(modelKey);\n if (model == null) continue;\n\n const prevFields = new Set(prevModelDef.record.fields.map(f => f.key));\n const currFields = new Set(currModelDef.record.fields.map(f => f.key));\n\n // Fields added in this version that require lens treatment. Optional\n // additive fields are skipped — `undefined` is a legal v_current value\n // for them, so the lens has nothing to invent.\n const addedFields = new Map<string, UpgradeStepField>();\n const recordUpgrades = currEntry.migrations?.[modelKey];\n for (const field of currModelDef.record.fields) {\n const fieldKey = field.key;\n if (prevFields.has(fieldKey)) continue;\n const isOptional = field.isOptional === true;\n const annotation = recordUpgrades?.[fieldKey];\n const derivedFrom = annotation != null ? [...annotation.derivedFrom] : [];\n if (derivedFrom.length === 0 && isOptional) continue;\n addedFields.set(fieldKey, { derivedFrom, isOptional });\n }\n\n // Fields absent from this version relative to the previous one (i.e. deprecated fields).\n const removedFields: string[] = [];\n for (const fieldKey of prevFields) {\n if (!currFields.has(fieldKey)) {\n removedFields.push(fieldKey);\n }\n }\n\n if (addedFields.size > 0 || removedFields.length > 0) {\n model.steps.push({\n addedInVersion: currEntry.version,\n addedInMinorVersion: getEntryMinorVersion(currEntry),\n fields: addedFields,\n removedFields,\n });\n }\n }\n }\n\n // Mark fields that are not present in ALL versions as optional in internal type\n const totalEntries = chain.length;\n for (const model of allRecordModels.values()) {\n for (const [, fieldInfo] of model.allFields) {\n if (fieldInfo.presentInEntries < totalEntries) {\n fieldInfo.alwaysOptional = true;\n }\n }\n }\n\n return allRecordModels;\n}\n\n/**\n * Generate _internal/types.ts content.\n */\nfunction generateInternalTypes(\n allRecordModels: Map<string, RecordModelInfo>,\n): string {\n let output = GENERATED_FILE_HEADER;\n output += \"\\n\";\n\n for (const [modelKey, model] of sortedEntries(allRecordModels)) {\n output += `/** Internal representation containing all fields across all schema versions. */\\n`;\n output += `export interface ${internalTypeName(modelKey)} {\\n`;\n\n for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {\n const tsType = convertFieldTypeToInternalTypeScript(\n fieldInfo.fieldType,\n fieldInfo.isOptional,\n );\n const optional = fieldInfo.alwaysOptional ? \"?\" : \"\";\n output += ` readonly ${fieldName}${optional}: ${tsType};\\n`;\n }\n\n output += \"}\\n\\n\";\n }\n\n return output;\n}\n\n/**\n * Generate per-version internal interfaces (e.g. `ShapeBox__v1`, `ShapeBox__v2`).\n *\n * Each interface contains only the fields present in that version, with their\n * actual optionality taken straight from that version's IR. The downstream\n * `DocumentUpgradeFns` generator uses these so each upgrade function's\n * parameter can `Pick` the prior version's fields and its return type can\n * index the current version's field type precisely.\n */\nfunction generatePerVersionInternalTypes(\n chain: VersionedIrEntry[],\n): string {\n // Group by model so each model's versions appear together in ascending order.\n const perModelVersions = new Map<\n string,\n { version: number; fields: readonly IFieldDef[] }[]\n >();\n\n for (const { version, ir } of chain) {\n for (const [modelKey, modelDef] of Object.entries(ir.models)) {\n if (modelDef.type !== \"record\") continue;\n let list = perModelVersions.get(modelKey);\n if (list == null) {\n list = [];\n perModelVersions.set(modelKey, list);\n }\n list.push({ version, fields: modelDef.record.fields });\n }\n }\n\n let output = \"\";\n const sortedModels = Array.from(perModelVersions.entries()).sort(([a], [b]) =>\n a.localeCompare(b)\n );\n for (const [modelKey, versions] of sortedModels) {\n for (const { version, fields } of versions) {\n output += `/** Internal representation of ${modelKey} at schema version ${version}. */\\n`;\n output += `export interface ${versionedInternalTypeName(modelKey, version)} {\\n`;\n const sortedFields = [...fields].sort((a, b) => a.key.localeCompare(b.key));\n for (const field of sortedFields) {\n const tsType = convertFieldTypeToInternalTypeScript(\n field.fieldType,\n field.isOptional === true,\n );\n const optional = field.isOptional === true ? \"?\" : \"\";\n output += ` readonly ${field.key}${optional}: ${tsType};\\n`;\n }\n output += \"}\\n\\n\";\n }\n }\n return output;\n}\n\n/**\n * Generate _internal/upgrades.ts content.\n */\nfunction generateUpgrades(\n allRecordModels: Map<string, RecordModelInfo>,\n latestIr: IRealTimeDocumentSchema,\n): string {\n let output = GENERATED_FILE_HEADER;\n\n const hasRecords = allRecordModels.size > 0;\n const hasUnions = Object.values(latestIr.models).some(m => m.type === \"union\");\n\n const imports: string[] = [];\n if (hasRecords) imports.push(\"UpgradeRegistry\");\n if (hasUnions) imports.push(\"UnionUpgradeRegistry\");\n\n if (imports.length > 0) {\n output += `import type { ${\n imports.join(\", \")\n } } from \"@palantir/pack.document-schema.model-types\";\\n\\n`;\n }\n\n for (const [modelKey, model] of sortedEntries(allRecordModels)) {\n output += `export const ${upgradesName(modelKey)}: UpgradeRegistry<\"${modelKey}\"> = {\\n`;\n output += ` modelName: \"${modelKey}\",\\n`;\n\n // allFields\n output += ` allFields: {\\n`;\n for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {\n const typeDescriptor = convertFieldTypeToDescriptor(\n fieldInfo.fieldType,\n fieldInfo.isOptional,\n );\n output += ` ${fieldName}: { type: ${typeDescriptor}, addedInVersion: ${\n getAddedInVersion(fieldInfo)\n } },\\n`;\n }\n output += ` },\\n`;\n\n // steps\n output += ` steps: [\\n`;\n for (const step of model.steps) {\n output += ` {\\n`;\n output += ` addedInVersion: ${step.addedInVersion},\\n`;\n if (step.addedInMinorVersion > 0) {\n output += ` addedInMinorVersion: ${step.addedInMinorVersion},\\n`;\n }\n output += ` fields: {\\n`;\n for (const [fieldName, fieldMeta] of step.fields) {\n output += ` ${fieldName}: {\\n`;\n output += ` derivedFrom: [${\n fieldMeta.derivedFrom.map(d => `\"${d}\"`).join(\", \")\n }],\\n`;\n output += ` },\\n`;\n }\n output += ` },\\n`;\n if (step.removedFields.length > 0) {\n output += ` removedFields: [${step.removedFields.map(f => `\"${f}\"`).join(\", \")}],\\n`;\n }\n output += ` },\\n`;\n }\n output += ` ],\\n`;\n\n output += `};\\n\\n`;\n }\n\n // Generate UnionUpgradeRegistry entries for union models\n for (const [modelKey, modelDef] of Object.entries(latestIr.models)) {\n if (modelDef.type !== \"union\") continue;\n\n const union = modelDef.union;\n output += `export const ${upgradesName(modelKey)}: UnionUpgradeRegistry<\"${modelKey}\"> = {\\n`;\n output += ` modelName: \"${modelKey}\",\\n`;\n output += ` discriminant: \"${union.discriminant}\",\\n`;\n output += ` variants: {\\n`;\n for (const [variantKey, variantModelKey] of Object.entries(union.variants)) {\n output += ` \"${variantKey}\": \"${variantModelKey}\",\\n`;\n }\n output += ` },\\n`;\n if (union.variantMetadata != null) {\n output += ` variantAddedInVersions: {\\n`;\n for (const [variantKey, meta] of Object.entries(union.variantMetadata)) {\n output += ` \"${variantKey}\": ${meta.addedInVersion},\\n`;\n }\n output += ` },\\n`;\n }\n output += `};\\n\\n`;\n }\n\n return output;\n}\n\n/**\n * Generate _internal/schema.ts content.\n */\nfunction generateInternalSchemaContent(\n allRecordModels: Map<string, RecordModelInfo>,\n): string {\n let output = GENERATED_FILE_HEADER;\n output += `import { z } from \"zod\";\\n\\n`;\n\n for (const [modelKey, model] of sortedEntries(allRecordModels)) {\n output += `export const ${internalSchemaName(modelKey)} = z.object({\\n`;\n\n for (const [fieldName, fieldInfo] of sortedEntries(model.allFields)) {\n // Use everOptional: a field optional in ANY version must stay optional\n // in the internal schema because older documents may legitimately omit it.\n const zodType = convertFieldTypeToInternalZod(\n fieldInfo.fieldType,\n fieldInfo.alwaysOptional || fieldInfo.everOptional,\n );\n output += ` ${fieldName}: ${zodType},\\n`;\n }\n\n output += `}).passthrough();\\n\\n`;\n }\n\n return output;\n}\n\n/**\n * Generate _internal/upgradeFns.ts content: a typed `DocumentUpgradeFns`\n * interface enumerating every upgrade function the app must supply at boot.\n *\n * For each `(modelName, v${version}, fieldName)` triple in a step's `fields`,\n * emit one property:\n * - Derived (`derivedFrom.length > 0`):\n * `(oldFields: Pick<<Model>__v<prior>, derivedFrom[number]>) => <Model>__v<current>[fieldName]`.\n * - Required additive (`derivedFrom.length === 0`):\n * `() => <Model>__v<current>[fieldName]`.\n *\n * Optional additive fields are filtered out at step-collection time and don't\n * appear here — `undefined` is a legal v<current> value for them, so the app\n * has no obligation to invent one.\n *\n * The interface is consumed by the generated `DocumentModel` factory in\n * `models.ts`, which requires it as a parameter when the schema needs any\n * upgrade functions. Schemas with no required fields added past v1 emit an\n * empty interface (still exported for type-uniformity in downstream code).\n */\nfunction generateUpgradeFns(\n chain: VersionedIrEntry[],\n allRecordModels: Map<string, RecordModelInfo>,\n): string {\n interface UpgradeFnEntry {\n fieldName: string;\n derivedFrom: readonly string[];\n }\n interface StepEntry {\n stepKey: string;\n currentVersion: number;\n priorVersion: number | undefined;\n fields: UpgradeFnEntry[];\n }\n\n const perModel = new Map<string, StepEntry[]>();\n const neededTypes = new Set<string>();\n\n for (const [modelKey, model] of sortedEntries(allRecordModels)) {\n for (const step of model.steps) {\n // A derived field's function takes the previous major's type, e.g. `Pick<ShapeBox__v1, \"color\">`\n // for a 2.0 step. Minor versions can't use `derivedFrom`, so minor steps never need it.\n const currentIdx = chain.findIndex(c => c.version === step.addedInVersion);\n const priorVersion = currentIdx > 0 ? chain[currentIdx - 1]!.version : undefined;\n\n const fields: UpgradeFnEntry[] = [];\n for (const [fieldName, fieldMeta] of step.fields) {\n fields.push({ fieldName, derivedFrom: [...fieldMeta.derivedFrom] });\n }\n if (fields.length === 0) continue;\n if (priorVersion == null && fields.some(f => f.derivedFrom.length > 0)) continue;\n\n let list = perModel.get(modelKey);\n if (list == null) {\n list = [];\n perModel.set(modelKey, list);\n }\n list.push({\n stepKey: upgradeStepKey(step.addedInVersion, step.addedInMinorVersion),\n currentVersion: step.addedInVersion,\n priorVersion,\n fields,\n });\n // Prior-version type only needed when at least one field derives from it.\n if (priorVersion != null && fields.some(f => f.derivedFrom.length > 0)) {\n neededTypes.add(versionedInternalTypeName(modelKey, priorVersion));\n }\n neededTypes.add(versionedInternalTypeName(modelKey, step.addedInVersion));\n }\n }\n\n let output = GENERATED_FILE_HEADER;\n output += `\\n`;\n\n if (neededTypes.size > 0) {\n const sorted = Array.from(neededTypes).sort();\n output += `import type { ${sorted.join(\", \")} } from \"./types.js\";\\n\\n`;\n }\n\n output += `/**\\n`;\n output += ` * Typed upgrade functions the application must supply at boot. Coverage is\\n`;\n output +=\n ` * exhaustive: missing or extra entries fail type-check at the \\`DocumentModel(...)\\`\\n`;\n output += ` * call site. Derived fields receive their declared source fields; required\\n`;\n output += ` * additive fields receive no arguments. Optional additive fields are absent\\n`;\n output += ` * — \\`undefined\\` is a legal value at the new version, so the runtime lens\\n`;\n output += ` * leaves them alone. Keys are \\`v2\\` for version 2.0 and \\`v2_1\\` for 2.1.\\n`;\n output += ` */\\n`;\n if (perModel.size === 0) {\n output += `// eslint-disable-next-line @typescript-eslint/no-empty-object-type\\n`;\n output += `export interface DocumentUpgradeFns {}\\n`;\n } else {\n output += `export interface DocumentUpgradeFns {\\n`;\n for (\n const [modelKey, steps] of Array.from(perModel.entries()).sort(([a], [b]) =>\n a.localeCompare(b)\n )\n ) {\n output += ` ${modelKey}: {\\n`;\n for (const step of steps) {\n output += ` ${step.stepKey}: {\\n`;\n const currentType = versionedInternalTypeName(modelKey, step.currentVersion);\n for (const f of step.fields) {\n const returnType = `${currentType}[\"${f.fieldName}\"]`;\n if (f.derivedFrom.length === 0) {\n output += ` ${f.fieldName}: () => ${returnType};\\n`;\n } else {\n // Steps with derived fields always have a prior version (others are skipped above).\n const priorType = versionedInternalTypeName(modelKey, step.priorVersion!);\n const pickKeys = f.derivedFrom.map(d => `\"${d}\"`).join(\" | \");\n output +=\n ` ${f.fieldName}: (oldFields: Pick<${priorType}, ${pickKeys}>) => ${returnType};\\n`;\n }\n }\n output += ` };\\n`;\n }\n output += ` };\\n`;\n }\n output += `}\\n`;\n }\n\n return output;\n}\n\n/**\n * Generate _internal/types.ts, _internal/upgrades.ts, _internal/schema.ts and\n * _internal/upgradeFns.ts from an already-resolved versioned IR chain.\n */\nexport function generateInternalFromChain(\n resolved: ResolvedIrChain,\n): InternalTypesOutput {\n const { chain } = resolved;\n const stepChain = resolved.stepChain ?? chain;\n const latestIr = chain[chain.length - 1]!.ir;\n\n const allRecordModels = collectRecordModels(stepChain);\n\n const internalTypes = generateInternalTypes(allRecordModels)\n + (chainNeedsUpgradeFns(stepChain) ? generatePerVersionInternalTypes(chain) : \"\");\n const upgrades = generateUpgrades(allRecordModels, latestIr);\n const internalSchema = generateInternalSchemaContent(allRecordModels);\n const internalUpgradeFns = generateUpgradeFns(chain, allRecordModels);\n\n return { internalTypes, upgrades, internalSchema, internalUpgradeFns };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,qBAAqB,QAAQ,2BAA2B;AACjE,SACEC,4BAA4B,EAC5BC,oCAAoC,EACpCC,6BAA6B,QACxB,yBAAyB;AAChC,SACEC,oBAAoB,EACpBC,oBAAoB,EAEpBC,cAAc,QAET,yBAAyB;AAChC,SACEC,kBAAkB,EAClBC,gBAAgB,EAChBC,YAAY,EACZC,yBAAyB,QACpB,oBAAoB;;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GAAGF,mBAAmB,CAACoG,SAAS,CAAC;EAEtD,MAAMC,aAAa,GAAGlD,qBAAqB,CAACjD,eAAe,CAAC,IACvDvB,oBAAoB,CAACyH,SAAS,CAAC,GAAG5C,+BAA+B,CAACvD,KAAK,CAAC,GAAG,EAAE,CAAC;EACnF,MAAMqG,QAAQ,GAAGxC,gBAAgB,CAAC5D,eAAe,EAAE6D,QAAQ,CAAC;EAC5D,MAAMwC,cAAc,GAAGtB,6BAA6B,CAAC/E,eAAe,CAAC;EACrE,MAAMsG,kBAAkB,GAAGrB,kBAAkB,CAAClF,KAAK,EAAEC,eAAe,CAAC;EAErE,OAAO;IAAEmG,aAAa;IAAEC,QAAQ;IAAEC,cAAc;IAAEC;EAAmB,CAAC;AACxE","ignoreList":[]}
@@ -73,6 +73,7 @@ function collectSchemaDefinitions(input) {
73
73
  function deriveProvenance(schemas) {
74
74
  const firstModelVersions = new Map();
75
75
  const firstFieldVersions = new Map();
76
+ const firstVariantVersions = new Map();
76
77
  return schemas.map(schema => {
77
78
  const currentVersion = {
78
79
  major: schema.version,
@@ -82,6 +83,8 @@ function deriveProvenance(schemas) {
82
83
  const modelMinorVersions = {};
83
84
  const fieldVersions = {};
84
85
  const fieldMinorVersions = {};
86
+ const variantVersions = {};
87
+ const variantMinorVersions = {};
85
88
  for (const [modelKey, modelDef] of Object.entries(schema.models)) {
86
89
  if (!firstModelVersions.has(modelKey)) {
87
90
  firstModelVersions.set(modelKey, currentVersion);
@@ -91,7 +94,30 @@ function deriveProvenance(schemas) {
91
94
  if (modelVersion.minor > 0) {
92
95
  modelMinorVersions[modelKey] = modelVersion.minor;
93
96
  }
94
- if (modelDef.type !== "record") continue;
97
+ if (modelDef.type === "union") {
98
+ let variantVersionsForModel = firstVariantVersions.get(modelKey);
99
+ if (variantVersionsForModel == null) {
100
+ variantVersionsForModel = new Map();
101
+ firstVariantVersions.set(modelKey, variantVersionsForModel);
102
+ }
103
+ const variants = {};
104
+ const minorVariants = {};
105
+ for (const variantName of Object.keys(modelDef.variants)) {
106
+ if (!variantVersionsForModel.has(variantName)) {
107
+ variantVersionsForModel.set(variantName, currentVersion);
108
+ }
109
+ const variantVersion = variantVersionsForModel.get(variantName);
110
+ variants[variantName] = variantVersion.major;
111
+ if (variantVersion.minor > 0) {
112
+ minorVariants[variantName] = variantVersion.minor;
113
+ }
114
+ }
115
+ variantVersions[modelKey] = variants;
116
+ if (Object.keys(minorVariants).length > 0) {
117
+ variantMinorVersions[modelKey] = minorVariants;
118
+ }
119
+ continue;
120
+ }
95
121
  let fieldVersionsForModel = firstFieldVersions.get(modelKey);
96
122
  if (fieldVersionsForModel == null) {
97
123
  fieldVersionsForModel = new Map();
@@ -121,6 +147,8 @@ function deriveProvenance(schemas) {
121
147
  modelVersions,
122
148
  fieldMinorVersions,
123
149
  modelMinorVersions,
150
+ variantVersions,
151
+ variantMinorVersions,
124
152
  deprecations: "deprecations" in schema ? schema.deprecations : undefined
125
153
  };
126
154
  });
@@ -1 +1 @@
1
- {"version":3,"file":"resolveSchemaChain.js","names":["IModelDef","IModelDefCtor","convertSchemaToIr","getEntryMinorVersion","entry","minorVersion","formatSchemaVersion","major","minor","formatEntryVersion","version","getSchemaMinorVersion","schema","type","collectVersionedIrChain","input","identity","schemas","collectSchemaDefinitions","provenances","deriveProvenance","map","index","ir","models","name","description","migrations","serializeMigrations","current","unshift","previous","firstModelVersions","Map","firstFieldVersions","currentVersion","modelVersions","modelMinorVersions","fieldVersions","fieldMinorVersions","modelKey","modelDef","Object","entries","has","set","modelVersion","get","fieldVersionsForModel","fields","minorFields","fieldKey","keys","fieldVersion","length","deprecations","undefined","result","fieldEntries","fieldName","migration","derivedFrom","resolveMinVersion","chain","minSupportedVersion","Error","latestVersion","some","c","join","minVersion","capVersionedIrChain","maxVersion","maxIndex","findIndex","slice","resolveSchemaChain","stripDeprecatedFieldsForSdk","record","filter","field","dep","metadata","deprecatedFromVersion","collapseChainToMajors","collapsed","mergeMigrations","collapsedEntry","push","base","override","chainNeedsUpgradeFns","i","prevEntry","currEntry","currModelDef","prevModelDef","prevFields","Set","f","key","recordMigrations","isOptional","upgradeStepKey"],"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 minorVersion?: number;\n ir: IRealTimeDocumentSchema;\n migrations?: SerializedVersionMigrations;\n}\n\nexport interface ResolvedIrChain {\n chain: VersionedIrEntry[];\n latestVersion: number;\n minVersion: number;\n /**\n * Every version, including minors (e.g. 3.0, 3.1, 3.2). `chain` merges these into one entry per\n * major. Upgrade steps compare neighbors here, so `title` added in 3.2 gets a `v3_2` step.\n * If absent, `chain` is used.\n */\n stepChain?: VersionedIrEntry[];\n}\n\nexport interface IrChainPayload {\n comment?: string;\n latestVersion: number;\n minSupportedVersion?: number;\n owningApplicationId?: string;\n chain: VersionedIrEntry[];\n}\n\nexport interface FullSchemaVersion {\n readonly major: number;\n readonly minor: number;\n}\n\nexport function getEntryMinorVersion(entry: VersionedIrEntry): number {\n return entry.minorVersion ?? 0;\n}\n\nexport function formatSchemaVersion(major: number, minor: number): string {\n return minor > 0 ? `${major}.${minor}` : `${major}`;\n}\n\nfunction formatEntryVersion(entry: VersionedIrEntry): string {\n return formatSchemaVersion(entry.version, getEntryMinorVersion(entry));\n}\n\nfunction getSchemaMinorVersion(schema: SchemaDefinition): number {\n return schema.type === \"versioned\" ? schema.minorVersion ?? 0 : 0;\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 const minorVersion = getSchemaMinorVersion(schema);\n return {\n version: schema.version,\n ...(minorVersion > 0 ? { minorVersion } : {}),\n ir: convertSchemaToIr(\n schema.models,\n { version: schema.version, name: identity.name, description: identity.description },\n provenances[index]!,\n ),\n ...(schema.type === \"versioned\"\n ? { migrations: serializeMigrations(schema.migrations) }\n : {}),\n };\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 (major and minor) where a model key or record field\n * appears is the version stamped into IR metadata.\n */\nfunction deriveProvenance(schemas: readonly SchemaDefinition[]): SchemaProvenance[] {\n const firstModelVersions = new Map<string, FullSchemaVersion>();\n const firstFieldVersions = new Map<string, Map<string, FullSchemaVersion>>();\n\n return schemas.map(schema => {\n const currentVersion = { major: schema.version, minor: getSchemaMinorVersion(schema) };\n const modelVersions: Record<string, number> = {};\n const modelMinorVersions: Record<string, number> = {};\n const fieldVersions: Record<string, Record<string, number>> = {};\n const fieldMinorVersions: 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, currentVersion);\n }\n const modelVersion = firstModelVersions.get(modelKey)!;\n modelVersions[modelKey] = modelVersion.major;\n if (modelVersion.minor > 0) {\n modelMinorVersions[modelKey] = modelVersion.minor;\n }\n\n if (modelDef.type !== \"record\") continue;\n\n let fieldVersionsForModel = firstFieldVersions.get(modelKey);\n if (fieldVersionsForModel == null) {\n fieldVersionsForModel = new Map<string, FullSchemaVersion>();\n firstFieldVersions.set(modelKey, fieldVersionsForModel);\n }\n\n const fields: Record<string, number> = {};\n const minorFields: Record<string, number> = {};\n for (const fieldKey of Object.keys(modelDef.fields)) {\n if (!fieldVersionsForModel.has(fieldKey)) {\n fieldVersionsForModel.set(fieldKey, currentVersion);\n }\n const fieldVersion = fieldVersionsForModel.get(fieldKey)!;\n fields[fieldKey] = fieldVersion.major;\n if (fieldVersion.minor > 0) {\n minorFields[fieldKey] = fieldVersion.minor;\n }\n }\n\n if (Object.keys(fields).length > 0) {\n fieldVersions[modelKey] = fields;\n }\n if (Object.keys(minorFields).length > 0) {\n fieldMinorVersions[modelKey] = minorFields;\n }\n }\n\n return {\n fieldVersions,\n modelVersions,\n fieldMinorVersions,\n modelMinorVersions,\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(formatEntryVersion).join(\", \")})`,\n );\n }\n\n return {\n latestVersion,\n minVersion: minSupportedVersion ?? latestVersion,\n };\n}\n\nfunction capVersionedIrChain(\n chain: VersionedIrEntry[],\n maxVersion: FullSchemaVersion | undefined,\n): VersionedIrEntry[] {\n if (maxVersion == null) {\n return chain;\n }\n\n const maxIndex = chain.findIndex(c =>\n c.version === maxVersion.major && getEntryMinorVersion(c) === maxVersion.minor\n );\n if (maxIndex === -1) {\n throw new Error(\n `maxVersion ${\n formatSchemaVersion(maxVersion.major, maxVersion.minor)\n } is not in the schema chain `\n + `(available versions: ${chain.map(formatEntryVersion).join(\", \")})`,\n );\n }\n\n // The chain is in version order, so everything up to the match is at or below it.\n return chain.slice(0, maxIndex + 1);\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 maxVersion?: FullSchemaVersion,\n): ResolvedIrChain {\n const chain = capVersionedIrChain(collectVersionedIrChain(schema, identity), maxVersion);\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 * Merge each major's minor versions into one entry, for generating SDK types.\n *\n * E.g. 3.0, 3.1 and 3.2 become one `3` entry that uses 3.2's IR, so `ShapeBox_v3` has every 3.x\n * field. Migrations from all three are kept, because each lives only on the version that added it.\n */\nexport function collapseChainToMajors(chain: VersionedIrEntry[]): VersionedIrEntry[] {\n const collapsed: VersionedIrEntry[] = [];\n for (const entry of chain) {\n const previous = collapsed[collapsed.length - 1];\n const migrations = previous?.version === entry.version\n ? mergeMigrations(previous.migrations, entry.migrations)\n : entry.migrations;\n const collapsedEntry: VersionedIrEntry = {\n version: entry.version,\n ir: entry.ir,\n ...(migrations != null ? { migrations } : {}),\n };\n if (previous?.version === entry.version) {\n collapsed[collapsed.length - 1] = collapsedEntry;\n } else {\n collapsed.push(collapsedEntry);\n }\n }\n return collapsed;\n}\n\nfunction mergeMigrations(\n base: SerializedVersionMigrations | undefined,\n override: SerializedVersionMigrations | undefined,\n): SerializedVersionMigrations | undefined {\n if (base == null) return override;\n if (override == null) return base;\n const result: SerializedVersionMigrations = { ...base };\n for (const [modelKey, fields] of Object.entries(override)) {\n result[modelKey] = { ...result[modelKey], ...fields };\n }\n return result;\n}\n\n/**\n * True if the chain has any field that requires a runtime upgrade function.\n * Drives whether the generated SDK emits `DocumentModel` as a factory\n * (requires the app to supply typed upgrade functions) or as a const.\n *\n * Two cases trigger this:\n * - A field declares `derivedFrom` with one or more source fields — the app\n * must supply a forward function.\n * - A required field is added in a version past v1 (no `derivedFrom`) — the\n * app must supply a zero-arg thunk; `undefined` is not a legal value.\n *\n * Optional additive fields don't trigger it; the lens leaves them alone.\n * Pass every version (`stepChain`), so a required field added in a minor, like `title` in 3.2, counts.\n */\nexport function chainNeedsUpgradeFns(chain: VersionedIrEntry[]): boolean {\n for (let i = 1; i < chain.length; i++) {\n const prevEntry = chain[i - 1]!;\n const currEntry = chain[i]!;\n for (const [modelKey, currModelDef] of Object.entries(currEntry.ir.models)) {\n if (currModelDef.type !== \"record\") continue;\n const prevModelDef = prevEntry.ir.models[modelKey];\n if (prevModelDef == null || prevModelDef.type !== \"record\") continue;\n const prevFields = new Set(prevModelDef.record.fields.map(f => f.key));\n const recordMigrations = currEntry.migrations?.[modelKey];\n for (const field of currModelDef.record.fields) {\n if (prevFields.has(field.key)) continue;\n const derivedFrom = recordMigrations?.[field.key]?.derivedFrom ?? [];\n if (derivedFrom.length > 0) return true;\n if (field.isOptional !== true) return true;\n }\n }\n }\n return false;\n}\n\n/** Upgrade function key for a step: `v2` for 2.0, `v2_1` for 2.1. Must match the key `applyReadLens` builds. */\nexport function upgradeStepKey(major: number, minor: number): string {\n return minor > 0 ? `v${major}_${minor}` : `v${major}`;\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;;AAK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,CAAChG,KAAa,EAAEC,KAAa,EAAU;EACnE,OAAOA,KAAK,GAAG,CAAC,GAAG,IAAID,KAAK,IAAIC,KAAK,EAAE,GAAG,IAAID,KAAK,EAAE;AACvD","ignoreList":[]}
1
+ {"version":3,"file":"resolveSchemaChain.js","names":["IModelDef","IModelDefCtor","convertSchemaToIr","getEntryMinorVersion","entry","minorVersion","formatSchemaVersion","major","minor","formatEntryVersion","version","getSchemaMinorVersion","schema","type","collectVersionedIrChain","input","identity","schemas","collectSchemaDefinitions","provenances","deriveProvenance","map","index","ir","models","name","description","migrations","serializeMigrations","current","unshift","previous","firstModelVersions","Map","firstFieldVersions","firstVariantVersions","currentVersion","modelVersions","modelMinorVersions","fieldVersions","fieldMinorVersions","variantVersions","variantMinorVersions","modelKey","modelDef","Object","entries","has","set","modelVersion","get","variantVersionsForModel","variants","minorVariants","variantName","keys","variantVersion","length","fieldVersionsForModel","fields","minorFields","fieldKey","fieldVersion","deprecations","undefined","result","fieldEntries","fieldName","migration","derivedFrom","resolveMinVersion","chain","minSupportedVersion","Error","latestVersion","some","c","join","minVersion","capVersionedIrChain","maxVersion","maxIndex","findIndex","slice","resolveSchemaChain","stripDeprecatedFieldsForSdk","record","filter","field","dep","metadata","deprecatedFromVersion","collapseChainToMajors","collapsed","mergeMigrations","collapsedEntry","push","base","override","chainNeedsUpgradeFns","i","prevEntry","currEntry","currModelDef","prevModelDef","prevFields","Set","f","key","recordMigrations","isOptional","upgradeStepKey"],"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 minorVersion?: number;\n ir: IRealTimeDocumentSchema;\n migrations?: SerializedVersionMigrations;\n}\n\nexport interface ResolvedIrChain {\n chain: VersionedIrEntry[];\n latestVersion: number;\n minVersion: number;\n /**\n * Every version, including minors (e.g. 3.0, 3.1, 3.2). `chain` merges these into one entry per\n * major. Upgrade steps compare neighbors here, so `title` added in 3.2 gets a `v3_2` step.\n * If absent, `chain` is used.\n */\n stepChain?: VersionedIrEntry[];\n}\n\nexport interface IrChainPayload {\n comment?: string;\n latestVersion: number;\n minSupportedVersion?: number;\n owningApplicationId?: string;\n chain: VersionedIrEntry[];\n}\n\nexport interface FullSchemaVersion {\n readonly major: number;\n readonly minor: number;\n}\n\nexport function getEntryMinorVersion(entry: VersionedIrEntry): number {\n return entry.minorVersion ?? 0;\n}\n\nexport function formatSchemaVersion(major: number, minor: number): string {\n return minor > 0 ? `${major}.${minor}` : `${major}`;\n}\n\nfunction formatEntryVersion(entry: VersionedIrEntry): string {\n return formatSchemaVersion(entry.version, getEntryMinorVersion(entry));\n}\n\nfunction getSchemaMinorVersion(schema: SchemaDefinition): number {\n return schema.type === \"versioned\" ? schema.minorVersion ?? 0 : 0;\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 const minorVersion = getSchemaMinorVersion(schema);\n return {\n version: schema.version,\n ...(minorVersion > 0 ? { minorVersion } : {}),\n ir: convertSchemaToIr(\n schema.models,\n { version: schema.version, name: identity.name, description: identity.description },\n provenances[index]!,\n ),\n ...(schema.type === \"versioned\"\n ? { migrations: serializeMigrations(schema.migrations) }\n : {}),\n };\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 (major and minor) where a model key or record field\n * appears is the version stamped into IR metadata.\n */\nfunction deriveProvenance(schemas: readonly SchemaDefinition[]): SchemaProvenance[] {\n const firstModelVersions = new Map<string, FullSchemaVersion>();\n const firstFieldVersions = new Map<string, Map<string, FullSchemaVersion>>();\n const firstVariantVersions = new Map<string, Map<string, FullSchemaVersion>>();\n\n return schemas.map(schema => {\n const currentVersion = { major: schema.version, minor: getSchemaMinorVersion(schema) };\n const modelVersions: Record<string, number> = {};\n const modelMinorVersions: Record<string, number> = {};\n const fieldVersions: Record<string, Record<string, number>> = {};\n const fieldMinorVersions: Record<string, Record<string, number>> = {};\n const variantVersions: Record<string, Record<string, number>> = {};\n const variantMinorVersions: 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, currentVersion);\n }\n const modelVersion = firstModelVersions.get(modelKey)!;\n modelVersions[modelKey] = modelVersion.major;\n if (modelVersion.minor > 0) {\n modelMinorVersions[modelKey] = modelVersion.minor;\n }\n\n if (modelDef.type === \"union\") {\n let variantVersionsForModel = firstVariantVersions.get(modelKey);\n if (variantVersionsForModel == null) {\n variantVersionsForModel = new Map<string, FullSchemaVersion>();\n firstVariantVersions.set(modelKey, variantVersionsForModel);\n }\n\n const variants: Record<string, number> = {};\n const minorVariants: Record<string, number> = {};\n for (const variantName of Object.keys(modelDef.variants)) {\n if (!variantVersionsForModel.has(variantName)) {\n variantVersionsForModel.set(variantName, currentVersion);\n }\n const variantVersion = variantVersionsForModel.get(variantName)!;\n variants[variantName] = variantVersion.major;\n if (variantVersion.minor > 0) {\n minorVariants[variantName] = variantVersion.minor;\n }\n }\n\n variantVersions[modelKey] = variants;\n if (Object.keys(minorVariants).length > 0) {\n variantMinorVersions[modelKey] = minorVariants;\n }\n continue;\n }\n\n let fieldVersionsForModel = firstFieldVersions.get(modelKey);\n if (fieldVersionsForModel == null) {\n fieldVersionsForModel = new Map<string, FullSchemaVersion>();\n firstFieldVersions.set(modelKey, fieldVersionsForModel);\n }\n\n const fields: Record<string, number> = {};\n const minorFields: Record<string, number> = {};\n for (const fieldKey of Object.keys(modelDef.fields)) {\n if (!fieldVersionsForModel.has(fieldKey)) {\n fieldVersionsForModel.set(fieldKey, currentVersion);\n }\n const fieldVersion = fieldVersionsForModel.get(fieldKey)!;\n fields[fieldKey] = fieldVersion.major;\n if (fieldVersion.minor > 0) {\n minorFields[fieldKey] = fieldVersion.minor;\n }\n }\n\n if (Object.keys(fields).length > 0) {\n fieldVersions[modelKey] = fields;\n }\n if (Object.keys(minorFields).length > 0) {\n fieldMinorVersions[modelKey] = minorFields;\n }\n }\n\n return {\n fieldVersions,\n modelVersions,\n fieldMinorVersions,\n modelMinorVersions,\n variantVersions,\n variantMinorVersions,\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(formatEntryVersion).join(\", \")})`,\n );\n }\n\n return {\n latestVersion,\n minVersion: minSupportedVersion ?? latestVersion,\n };\n}\n\nfunction capVersionedIrChain(\n chain: VersionedIrEntry[],\n maxVersion: FullSchemaVersion | undefined,\n): VersionedIrEntry[] {\n if (maxVersion == null) {\n return chain;\n }\n\n const maxIndex = chain.findIndex(c =>\n c.version === maxVersion.major && getEntryMinorVersion(c) === maxVersion.minor\n );\n if (maxIndex === -1) {\n throw new Error(\n `maxVersion ${\n formatSchemaVersion(maxVersion.major, maxVersion.minor)\n } is not in the schema chain `\n + `(available versions: ${chain.map(formatEntryVersion).join(\", \")})`,\n );\n }\n\n // The chain is in version order, so everything up to the match is at or below it.\n return chain.slice(0, maxIndex + 1);\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 maxVersion?: FullSchemaVersion,\n): ResolvedIrChain {\n const chain = capVersionedIrChain(collectVersionedIrChain(schema, identity), maxVersion);\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 * Merge each major's minor versions into one entry, for generating SDK types.\n *\n * E.g. 3.0, 3.1 and 3.2 become one `3` entry that uses 3.2's IR, so `ShapeBox_v3` has every 3.x\n * field. Migrations from all three are kept, because each lives only on the version that added it.\n */\nexport function collapseChainToMajors(chain: VersionedIrEntry[]): VersionedIrEntry[] {\n const collapsed: VersionedIrEntry[] = [];\n for (const entry of chain) {\n const previous = collapsed[collapsed.length - 1];\n const migrations = previous?.version === entry.version\n ? mergeMigrations(previous.migrations, entry.migrations)\n : entry.migrations;\n const collapsedEntry: VersionedIrEntry = {\n version: entry.version,\n ir: entry.ir,\n ...(migrations != null ? { migrations } : {}),\n };\n if (previous?.version === entry.version) {\n collapsed[collapsed.length - 1] = collapsedEntry;\n } else {\n collapsed.push(collapsedEntry);\n }\n }\n return collapsed;\n}\n\nfunction mergeMigrations(\n base: SerializedVersionMigrations | undefined,\n override: SerializedVersionMigrations | undefined,\n): SerializedVersionMigrations | undefined {\n if (base == null) return override;\n if (override == null) return base;\n const result: SerializedVersionMigrations = { ...base };\n for (const [modelKey, fields] of Object.entries(override)) {\n result[modelKey] = { ...result[modelKey], ...fields };\n }\n return result;\n}\n\n/**\n * True if the chain has any field that requires a runtime upgrade function.\n * Drives whether the generated SDK emits `DocumentModel` as a factory\n * (requires the app to supply typed upgrade functions) or as a const.\n *\n * Two cases trigger this:\n * - A field declares `derivedFrom` with one or more source fields — the app\n * must supply a forward function.\n * - A required field is added in a version past v1 (no `derivedFrom`) — the\n * app must supply a zero-arg thunk; `undefined` is not a legal value.\n *\n * Optional additive fields don't trigger it; the lens leaves them alone.\n * Pass every version (`stepChain`), so a required field added in a minor, like `title` in 3.2, counts.\n */\nexport function chainNeedsUpgradeFns(chain: VersionedIrEntry[]): boolean {\n for (let i = 1; i < chain.length; i++) {\n const prevEntry = chain[i - 1]!;\n const currEntry = chain[i]!;\n for (const [modelKey, currModelDef] of Object.entries(currEntry.ir.models)) {\n if (currModelDef.type !== \"record\") continue;\n const prevModelDef = prevEntry.ir.models[modelKey];\n if (prevModelDef == null || prevModelDef.type !== \"record\") continue;\n const prevFields = new Set(prevModelDef.record.fields.map(f => f.key));\n const recordMigrations = currEntry.migrations?.[modelKey];\n for (const field of currModelDef.record.fields) {\n if (prevFields.has(field.key)) continue;\n const derivedFrom = recordMigrations?.[field.key]?.derivedFrom ?? [];\n if (derivedFrom.length > 0) return true;\n if (field.isOptional !== true) return true;\n }\n }\n }\n return false;\n}\n\n/** Upgrade function key for a step: `v2` for 2.0, `v2_1` for 2.1. Must match the key `applyReadLens` builds. */\nexport function upgradeStepKey(major: number, minor: number): string {\n return minor > 0 ? `v${major}_${minor}` : `v${major}`;\n}\n"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,OAAO,IAAI;MAC5C;IACF;EACF;EACA,OAAO,KAAK;AACd;;AAEA;AACA,OAAO,SAASC,cAAcA,CAACxG,KAAa,EAAEC,KAAa,EAAU;EACnE,OAAOA,KAAK,GAAG,CAAC,GAAG,IAAID,KAAK,IAAIC,KAAK,EAAE,GAAG,IAAID,KAAK,EAAE;AACvD","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"arrayFields.js","names":[],"sources":["arrayFields.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.33.0 */\n\n\nexport interface Container {\n readonly items: readonly string[];\n readonly numbers: readonly number[];\n}\n\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"arrayFields.js","names":[],"sources":["arrayFields.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.34.0 */\n\n\nexport interface Container {\n readonly items: readonly string[];\n readonly numbers: readonly number[];\n}\n\n"],"mappings":"","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* Generated by @palantir/pack.document-schema.type-gen@0.33.0 */
1
+ /* Generated by @palantir/pack.document-schema.type-gen@0.34.0 */
2
2
 
3
3
  /**
4
4
  * A cat
@@ -1 +1 @@
1
- {"version":3,"file":"customDiscriminant.js","names":["isAnimalCat","value","kind","isAnimalDog"],"sources":["customDiscriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.33.0 */\n\n\n/**\n * A cat\n */\nexport interface Cat {\n readonly meow: string;\n readonly whiskers: number;\n}\n\n/**\n * A dog\n */\nexport interface Dog {\n readonly bark: string;\n readonly tailWags: number;\n}\n\nexport interface AnimalCat extends Cat {\n readonly kind: \"cat\";\n}\n\nexport interface AnimalDog extends Dog {\n readonly kind: \"dog\";\n}\n\nexport type Animal = AnimalCat | AnimalDog;\n\nexport function isAnimalCat(value: Animal): value is AnimalCat {\n return value.kind === \"cat\";\n}\n\nexport function isAnimalDog(value: Animal): value is AnimalDog {\n return value.kind === \"dog\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;AAgBA,OAAO,SAASA,WAAWA,CAACC,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B;AAEA,OAAO,SAASC,WAAWA,CAACF,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B","ignoreList":[]}
1
+ {"version":3,"file":"customDiscriminant.js","names":["isAnimalCat","value","kind","isAnimalDog"],"sources":["customDiscriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.34.0 */\n\n\n/**\n * A cat\n */\nexport interface Cat {\n readonly meow: string;\n readonly whiskers: number;\n}\n\n/**\n * A dog\n */\nexport interface Dog {\n readonly bark: string;\n readonly tailWags: number;\n}\n\nexport interface AnimalCat extends Cat {\n readonly kind: \"cat\";\n}\n\nexport interface AnimalDog extends Dog {\n readonly kind: \"dog\";\n}\n\nexport type Animal = AnimalCat | AnimalDog;\n\nexport function isAnimalCat(value: Animal): value is AnimalCat {\n return value.kind === \"cat\";\n}\n\nexport function isAnimalDog(value: Animal): value is AnimalDog {\n return value.kind === \"dog\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;AAgBA,OAAO,SAASA,WAAWA,CAACC,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B;AAEA,OAAO,SAASC,WAAWA,CAACF,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* Generated by @palantir/pack.document-schema.type-gen@0.33.0 */
1
+ /* Generated by @palantir/pack.document-schema.type-gen@0.34.0 */
2
2
 
3
3
  /**
4
4
  * Represents an edge in a graph
@@ -1 +1 @@
1
- {"version":3,"file":"generateTypeScriptInterfaces.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["generateTypeScriptInterfaces.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.33.0 */\n\n\n/**\n * Represents an edge in a graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly label?: string;\n readonly color?: string;\n}\n\n/**\n * Represents a text box in a graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"text-box\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"text-box\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;;AAiBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,UAAU;AAClC","ignoreList":[]}
1
+ {"version":3,"file":"generateTypeScriptInterfaces.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["generateTypeScriptInterfaces.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.34.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.33.0 */\n\nimport type { DocumentId, MediaId, ObjectId, ResourceRid, UserId } 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: DocumentId;\n readonly userRef: UserId;\n readonly objectRef: ObjectId;\n readonly mediaRef: MediaId;\n readonly resourceRef: ResourceRid;\n readonly optionalDocRef?: DocumentId;\n readonly docRefArray: readonly DocumentId[];\n readonly userRefArray: readonly UserId[];\n readonly optionalResourceRef?: ResourceRid;\n readonly resourceRefArray: readonly ResourceRid[];\n}\n\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.34.0 */\n\nimport type { DocumentId, MediaId, ObjectId, ResourceRid, UserId } 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: DocumentId;\n readonly userRef: UserId;\n readonly objectRef: ObjectId;\n readonly mediaRef: MediaId;\n readonly resourceRef: ResourceRid;\n readonly optionalDocRef?: DocumentId;\n readonly docRefArray: readonly DocumentId[];\n readonly userRefArray: readonly UserId[];\n readonly optionalResourceRef?: ResourceRid;\n readonly resourceRefArray: readonly ResourceRid[];\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.33.0 */\n\n\n/**\n * A person record\n */\nexport interface Person {\n readonly name: string;\n readonly age: number;\n readonly email?: string;\n}\n\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"simpleRecord.js","names":[],"sources":["simpleRecord.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.34.0 */\n\n\n/**\n * A person record\n */\nexport interface Person {\n readonly name: string;\n readonly age: number;\n readonly email?: string;\n}\n\n"],"mappings":"","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- /* Generated by @palantir/pack.document-schema.type-gen@0.33.0 */
1
+ /* Generated by @palantir/pack.document-schema.type-gen@0.34.0 */
2
2
 
3
3
  /**
4
4
  * A node in the graph
@@ -1 +1 @@
1
- {"version":3,"file":"simpleSteps.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["simpleSteps.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.33.0 */\n\n\n/**\n * A node in the graph\n */\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly object: string;\n readonly label?: string;\n readonly edges: readonly Edge[];\n}\n\n/**\n * A text box in the graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\n/**\n * An edge in the graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"textBox\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"textBox\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AASA;AACA;AACA;;AAOA;AACA;AACA;;AAgBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,SAAS;AACjC","ignoreList":[]}
1
+ {"version":3,"file":"simpleSteps.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["simpleSteps.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.34.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":[]}
@@ -131,6 +131,22 @@ export function convertUnionDefToIr(unionDef, exportKey, nameToExportKey, fallba
131
131
  const variantEntries = Object.entries(unionDef.variants).map(([variantName, modelRef]) => [variantName, nameToExportKey?.get(modelRef.name) ?? modelRef.name]);
132
132
  const unionAddedIn = provenance?.modelVersions?.[modelKey] ?? fallbackVersion;
133
133
  const unionAddedInMinor = provenance?.modelMinorVersions?.[modelKey] ?? 0;
134
+
135
+ // Only variants added after the union get an entry; the rest inherit the union's version. A union
136
+ // that never gained a variant has no variantMetadata, so its output stays the same.
137
+ const variantMetadata = {};
138
+ for (const variantName of Object.keys(unionDef.variants)) {
139
+ const addedIn = provenance?.variantVersions?.[modelKey]?.[variantName] ?? unionAddedIn;
140
+ const addedInMinor = provenance?.variantMinorVersions?.[modelKey]?.[variantName] ?? 0;
141
+ if (addedIn !== unionAddedIn || addedInMinor !== unionAddedInMinor) {
142
+ variantMetadata[variantName] = {
143
+ addedInVersion: addedIn,
144
+ ...(addedInMinor > 0 ? {
145
+ addedInMinorVersion: addedInMinor
146
+ } : {})
147
+ };
148
+ }
149
+ }
134
150
  return {
135
151
  key: modelKey,
136
152
  name: unionDef.name,
@@ -142,7 +158,10 @@ export function convertUnionDefToIr(unionDef, exportKey, nameToExportKey, fallba
142
158
  ...(unionAddedInMinor > 0 ? {
143
159
  addedInMinorVersion: unionAddedInMinor
144
160
  } : {})
145
- }
161
+ },
162
+ ...(Object.keys(variantMetadata).length > 0 ? {
163
+ variantMetadata
164
+ } : {})
146
165
  };
147
166
  }
148
167
 
@@ -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","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","fieldMinorVersions","deprecations","fields","fieldKey","fieldType","dep","addedInMinorVersion","key","undefined","convertTypeToFieldTypeUnion","addedInVersion","deprecatedFromVersion","fromVersion","message","deprecatedMessage","isOptional","docs","unionDef","variantEntries","variants","variantName","modelRef","unionAddedIn","modelVersions","unionAddedInMinor","modelMinorVersions","discriminant","schemaType","items","allowNullValue","elementType","item","array","value","convertTypeToFieldValueUnion","Error","resourceRef","resourceRids","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 fieldMinorVersions?: Record<string, Record<string, number>>;\n readonly modelMinorVersions?: 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 fieldMinorVersions = provenance?.fieldMinorVersions?.[modelKey];\n const deprecations = provenance?.deprecations?.[modelKey];\n const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]): IFieldDef => {\n const dep = deprecations?.[fieldKey];\n const addedInMinorVersion = fieldMinorVersions?.[fieldKey] ?? 0;\n return {\n key: fieldKey,\n name: fieldKey,\n description: undefined,\n fieldType: convertTypeToFieldTypeUnion(fieldType, nameToExportKey),\n metadata: {\n addedInVersion: fieldVersions?.[fieldKey] ?? fallbackVersion,\n ...(addedInMinorVersion > 0 ? { addedInMinorVersion } : {}),\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 const unionAddedInMinor = provenance?.modelMinorVersions?.[modelKey] ?? 0;\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: {\n addedInVersion: unionAddedIn,\n ...(unionAddedInMinor > 0 ? { addedInMinorVersion: unionAddedInMinor } : {}),\n },\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 \"resourceRef\":\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 \"resourceRef\":\n return IFieldValueUnion.resourceRef({\n resourceRids: [],\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;A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AAC,CAAC;IAEJ,KAAK,SAAS;MACZ,OAAOnF,gBAAgB,CAACoF,OAAO,CAAC,CAAC,CAAC,CAAC;IAErC,KAAK,QAAQ;MACX,OAAOpF,gBAAgB,CAACqF,MAAM,CAAC;QAC7BC,gBAAgB,EAAE,EAAE,CAAE;MACxB,CAAC,CAAC;IAEJ,KAAK,QAAQ;MACX,OAAOtF,gBAAgB,CAACuF,MAAM,CAAC,CAAC,CAAC,CAAC;IAEpC,KAAK,UAAU;MACb,OAAOvF,gBAAgB,CAACwF,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEtC,KAAK,WAAW;MACd,OAAOxF,gBAAgB,CAACyF,MAAM,CAAC;QAC7B;QACAC,iBAAiB,EAAE,EAAE;QACrBC,cAAc,EAAE;MAClB,CAAC,CAAC;IAEJ,KAAK,UAAU;MACb;MACA;MACA,OAAOX,4BAA4B,CAACP,UAAU,CAACI,IAAI,EAAY3D,eAAe,CAAC;IAEjF,KAAK,KAAK;MAAE;QACV,MAAM0B,QAAQ,GAAG1B,eAAe,EAAEM,GAAG,CAACiD,UAAU,CAAC3D,IAAI,CAAC,IAAI2D,UAAU,CAAC3D,IAAI;QACzE,OAAOd,gBAAgB,CAACmE,QAAQ,CAAC;UAAEyB,UAAU,EAAE,CAAChD,QAAQ;QAAmB,CAAC,CAAC;MAC/E;IAEA,KAAK,QAAQ;MACX,OAAO5C,gBAAgB,CAAC6F,MAAM,CAAC,CAAC,CAAC,CAAC;IAEpC,KAAK,SAAS;MACZ,OAAO7F,gBAAgB,CAAC8F,aAAa,CAAC,CAAC,CAAC,CAAC;IAE3C,KAAK,SAAS;MACZ,OAAO9F,gBAAgB,CAAC+F,OAAO,CAAC,CAAC,CAAC,CAAC;IAErC;MACE7F,WAAW,CAACuE,UAAU,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","fieldMinorVersions","deprecations","fields","fieldKey","fieldType","dep","addedInMinorVersion","key","undefined","convertTypeToFieldTypeUnion","addedInVersion","deprecatedFromVersion","fromVersion","message","deprecatedMessage","isOptional","docs","unionDef","variantEntries","variants","variantName","modelRef","unionAddedIn","modelVersions","unionAddedInMinor","modelMinorVersions","variantMetadata","keys","addedIn","variantVersions","addedInMinor","variantMinorVersions","discriminant","length","schemaType","items","allowNullValue","elementType","item","array","value","convertTypeToFieldValueUnion","Error","resourceRef","resourceRids","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 ISchemaMeta,\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 fieldMinorVersions?: Record<string, Record<string, number>>;\n readonly modelMinorVersions?: Record<string, number>;\n readonly variantVersions?: Record<string, Record<string, number>>;\n readonly variantMinorVersions?: Record<string, 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 fieldMinorVersions = provenance?.fieldMinorVersions?.[modelKey];\n const deprecations = provenance?.deprecations?.[modelKey];\n const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]): IFieldDef => {\n const dep = deprecations?.[fieldKey];\n const addedInMinorVersion = fieldMinorVersions?.[fieldKey] ?? 0;\n return {\n key: fieldKey,\n name: fieldKey,\n description: undefined,\n fieldType: convertTypeToFieldTypeUnion(fieldType, nameToExportKey),\n metadata: {\n addedInVersion: fieldVersions?.[fieldKey] ?? fallbackVersion,\n ...(addedInMinorVersion > 0 ? { addedInMinorVersion } : {}),\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 const unionAddedInMinor = provenance?.modelMinorVersions?.[modelKey] ?? 0;\n\n // Only variants added after the union get an entry; the rest inherit the union's version. A union\n // that never gained a variant has no variantMetadata, so its output stays the same.\n const variantMetadata: Record<string, ISchemaMeta> = {};\n for (const variantName of Object.keys(unionDef.variants)) {\n const addedIn = provenance?.variantVersions?.[modelKey]?.[variantName] ?? unionAddedIn;\n const addedInMinor = provenance?.variantMinorVersions?.[modelKey]?.[variantName] ?? 0;\n if (addedIn !== unionAddedIn || addedInMinor !== unionAddedInMinor) {\n variantMetadata[variantName] = {\n addedInVersion: addedIn,\n ...(addedInMinor > 0 ? { addedInMinorVersion: addedInMinor } : {}),\n };\n }\n }\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: {\n addedInVersion: unionAddedIn,\n ...(unionAddedInMinor > 0 ? { addedInMinorVersion: unionAddedInMinor } : {}),\n },\n ...(Object.keys(variantMetadata).length > 0 ? { variantMetadata } : {}),\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 \"resourceRef\":\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 \"resourceRef\":\n return IFieldValueUnion.resourceRef({\n resourceRids: [],\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;AAYtC,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;;AAWA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,KAA+B,EAC/BC,QAAyB,EACA;EACzB;EACA,MAAM;IAAEC,iBAAiB;IAAEC;EAAiB,CAAC,GAAGL,oBAAoB,CAACE,KAAwB,CAAC;EAE9F,MAAMI,MAAM,GAAG;IACb,GAAGC,MAAM,CAACC,WAAW,CAACJ,iBAAiB,CAACK,GAAG,CAACC,GAAG,IAAI,CAACA,GAAG,CAACC,IAAI,EAAED,GAAG,CAAC,CAAC,CAAC;IACpE,GAAGH,MAAM,CAACC,WAAW,CAACH,gBAAgB,CAACI,GAAG,CAACC,GAAG,IAAI,CAACA,GAAG,CAACC,IAAI,EAAED,GAAG,CAAC,CAAC;EAC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G,aAAa,CAAC,CAAC,CAAC,CAAC;IAE3C,KAAK,SAAS;MACZ,OAAOrG,gBAAgB,CAACsG,OAAO,CAAC,CAAC,CAAC,CAAC;IAErC;MACEpG,WAAW,CAAC8E,UAAU,CAAC;EAC3B;AACF","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import type { FileSystemType } from "@osdk/foundry.pack";
1
+ import type { FileSystemType } from "@palantir/pack.core/generatedPlatformSdk";
2
2
  interface DeployOptions {
3
3
  readonly ir: string;
4
4
  readonly baseUrl: string;
@@ -1 +1 @@
1
- {"version":3,"file":"irDeployHandler.d.ts","sourceRoot":"","sources":["../../../../src/commands/ir/irDeployHandler.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAA6B,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAWpF,UAAU,aAAa;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,wCAAwC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,6HAA6H;IAC7H,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,iJAAiJ;IACjJ,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAuC3E"}
1
+ {"version":3,"file":"irDeployHandler.d.ts","sourceRoot":"","sources":["../../../../src/commands/ir/irDeployHandler.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAEV,cAAc,EACf,MAAM,0CAA0C,CAAC;AAWlD,UAAU,aAAa;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;IACzC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,wCAAwC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,6HAA6H;IAC7H,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,iJAAiJ;IACjJ,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAuC3E"}
@@ -1,4 +1,4 @@
1
- import type { FileSystemType } from "@osdk/foundry.pack";
1
+ import type { FileSystemType } from "@palantir/pack.core/generatedPlatformSdk";
2
2
  interface IrGenAssetOptions {
3
3
  readonly ir: string;
4
4
  readonly output: string;