@palantir/pack.document-schema.type-gen 0.20.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/build/esm/commands/ir/__tests__/irDeployFirstParty.test.js +237 -0
- package/build/esm/commands/ir/__tests__/irDeployFirstParty.test.js.map +1 -0
- package/build/esm/commands/ir/irDeployHandler.js +81 -41
- package/build/esm/commands/ir/irDeployHandler.js.map +1 -1
- package/build/esm/commands/ir/irGenAssetHandler.js +13 -0
- package/build/esm/commands/ir/irGenAssetHandler.js.map +1 -1
- package/build/esm/commands/ir/registerIrCommands.js +2 -2
- package/build/esm/commands/ir/registerIrCommands.js.map +1 -1
- package/build/esm/lib/pack-docschema-api/pack-docschema-api/index.js +1 -0
- package/build/esm/lib/pack-docschema-api/pack-docschema-api/index.js.map +1 -1
- package/build/esm/lib/pack-docschema-api/pack-docschema-api/resourceRid.js +2 -0
- package/build/esm/lib/pack-docschema-api/pack-docschema-api/resourceRid.js.map +1 -0
- package/build/esm/lib/pack-docschema-api/pack-docschema-ir/fieldValueResourceRef.js +2 -0
- package/build/esm/lib/pack-docschema-api/pack-docschema-ir/fieldValueResourceRef.js.map +1 -0
- package/build/esm/lib/pack-docschema-api/pack-docschema-ir/fieldValueUnion.js +14 -0
- package/build/esm/lib/pack-docschema-api/pack-docschema-ir/fieldValueUnion.js.map +1 -1
- package/build/esm/lib/pack-docschema-api/pack-docschema-ir/index.js +1 -0
- package/build/esm/lib/pack-docschema-api/pack-docschema-ir/index.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js +3 -2
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js.map +1 -1
- package/build/esm/utils/ir/__tests__/convertIrToConjureSchema.test.js +185 -0
- package/build/esm/utils/ir/__tests__/convertIrToConjureSchema.test.js.map +1 -0
- package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js +6 -0
- package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js.map +1 -1
- package/build/esm/utils/ir/__tests__/generateModelsFromIr.test.js +17 -0
- package/build/esm/utils/ir/__tests__/generateModelsFromIr.test.js.map +1 -1
- package/build/esm/utils/ir/convertIrToConjureSchema.js +148 -0
- package/build/esm/utils/ir/convertIrToConjureSchema.js.map +1 -0
- package/build/esm/utils/ir/convertIrToWireSchema.js +7 -0
- package/build/esm/utils/ir/convertIrToWireSchema.js.map +1 -1
- package/build/esm/utils/ir/generateModelsFromIr.js +3 -1
- package/build/esm/utils/ir/generateModelsFromIr.js.map +1 -1
- package/build/esm/utils/ir/generateZodSchemasFromIr.js +1 -0
- package/build/esm/utils/ir/generateZodSchemasFromIr.js.map +1 -1
- package/build/esm/utils/ir/irFieldHelpers.js +24 -11
- package/build/esm/utils/ir/irFieldHelpers.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateDocumentTypeFromSchema/with-name-and-description.js +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateDocumentTypeFromSchema/with-name-and-description.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/single-version.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/three-version-chain.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js.map +1 -1
- package/build/esm/utils/schema/__tests__/fixtures.js +6 -2
- package/build/esm/utils/schema/__tests__/fixtures.js.map +1 -1
- package/build/esm/utils/schema/convertSchemaToSteps.js +2 -0
- package/build/esm/utils/schema/convertSchemaToSteps.js.map +1 -1
- package/build/esm/utils/schema/generateTypesFromSchema.js +13 -8
- package/build/esm/utils/schema/generateTypesFromSchema.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/arrayFields.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleRecord.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js.map +1 -1
- package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/refTypes.js +15 -0
- package/build/esm/utils/steps/__tests__/fixtures/stepSchemas/refTypes.js.map +1 -1
- package/build/esm/utils/steps/convertStepsToIr.js +5 -0
- package/build/esm/utils/steps/convertStepsToIr.js.map +1 -1
- package/build/esm/utils/steps/convertStepsToSchema.js +5 -0
- package/build/esm/utils/steps/convertStepsToSchema.js.map +1 -1
- package/build/types/commands/ir/__tests__/irDeployFirstParty.test.d.ts +2 -0
- package/build/types/commands/ir/__tests__/irDeployFirstParty.test.d.ts.map +1 -0
- package/build/types/commands/ir/irDeployHandler.d.ts +20 -2
- package/build/types/commands/ir/irDeployHandler.d.ts.map +1 -1
- package/build/types/commands/ir/irGenAssetHandler.d.ts +5 -0
- package/build/types/commands/ir/irGenAssetHandler.d.ts.map +1 -1
- package/build/types/commands/ir/registerIrCommands.d.ts.map +1 -1
- package/build/types/lib/pack-docschema-api/pack-docschema-api/index.d.ts +1 -0
- package/build/types/lib/pack-docschema-api/pack-docschema-api/index.d.ts.map +1 -1
- package/build/types/lib/pack-docschema-api/pack-docschema-api/resourceRid.d.ts +5 -0
- package/build/types/lib/pack-docschema-api/pack-docschema-api/resourceRid.d.ts.map +1 -0
- package/build/types/lib/pack-docschema-api/pack-docschema-ir/fieldValueResourceRef.d.ts +5 -0
- package/build/types/lib/pack-docschema-api/pack-docschema-ir/fieldValueResourceRef.d.ts.map +1 -0
- package/build/types/lib/pack-docschema-api/pack-docschema-ir/fieldValueUnion.d.ts +11 -1
- package/build/types/lib/pack-docschema-api/pack-docschema-ir/fieldValueUnion.d.ts.map +1 -1
- package/build/types/lib/pack-docschema-api/pack-docschema-ir/index.d.ts +1 -0
- package/build/types/lib/pack-docschema-api/pack-docschema-ir/index.d.ts.map +1 -1
- package/build/types/utils/ir/__tests__/convertIrToConjureSchema.test.d.ts +2 -0
- package/build/types/utils/ir/__tests__/convertIrToConjureSchema.test.d.ts.map +1 -0
- package/build/types/utils/ir/convertIrToConjureSchema.d.ts +26 -0
- package/build/types/utils/ir/convertIrToConjureSchema.d.ts.map +1 -0
- package/build/types/utils/ir/generateModelsFromIr.d.ts.map +1 -1
- package/build/types/utils/ir/generateZodSchemasFromIr.d.ts.map +1 -1
- package/build/types/utils/ir/irFieldHelpers.d.ts +4 -3
- package/build/types/utils/ir/irFieldHelpers.d.ts.map +1 -1
- package/build/types/utils/schema/__tests__/fixtures.d.ts.map +1 -1
- package/build/types/utils/schema/convertSchemaToSteps.d.ts.map +1 -1
- package/build/types/utils/schema/generateTypesFromSchema.d.ts.map +1 -1
- package/build/types/utils/steps/convertStepsToIr.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -71,13 +71,16 @@ const addOpacityRequiredUpdate = defineSchemaUpdate("addOpacityRequired", schema
|
|
|
71
71
|
}));
|
|
72
72
|
export const twoVersionRequiredAdditiveSchema = nextSchema(singleVersionSchemaNarrow).addSchemaUpdate(addOpacityRequiredUpdate).build();
|
|
73
73
|
|
|
74
|
-
/** Schema with ref fields: tests import paths for record refs, DocumentRef, UserRef */
|
|
74
|
+
/** Schema with ref fields: tests import paths for record refs, ResourceRef, DocumentRef, UserRef */
|
|
75
75
|
const CircleRecord = defineRecord("Circle", {
|
|
76
76
|
docs: "A circle",
|
|
77
77
|
fields: {
|
|
78
78
|
radius: P.Double
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
|
+
const ResourceRefField = {
|
|
82
|
+
type: "resourceRef"
|
|
83
|
+
};
|
|
81
84
|
const DocRef = {
|
|
82
85
|
type: "docRef"
|
|
83
86
|
};
|
|
@@ -93,7 +96,8 @@ export const refFieldsSchema = defineSchema({
|
|
|
93
96
|
extraShapes: P.Array(modelToRef(CircleRecord)),
|
|
94
97
|
background: P.Optional(modelToRef(CircleRecord)),
|
|
95
98
|
attachment: DocRef,
|
|
96
|
-
owner: P.Optional(UserRefField)
|
|
99
|
+
owner: P.Optional(UserRefField),
|
|
100
|
+
resource: ResourceRefField
|
|
97
101
|
}
|
|
98
102
|
})
|
|
99
103
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.js","names":["defineRecord","defineSchema","defineSchemaUpdate","defineUnion","modelToRef","nextSchema","P","singleVersionModels","ShapeBox","docs","fields","left","Double","right","top","bottom","color","Optional","String","singleVersionSchemaNarrow","singleVersionSchema","twoVersionFieldRemovalSchema","type","models","fillColor","strokeColor","opacity","version","previous","addFillColorUpdate","schema","addField","build","twoVersionAdditiveSchema","addSchemaUpdate","addOpacityRequiredUpdate","twoVersionRequiredAdditiveSchema","CircleRecord","radius","DocRef","UserRefField","refFieldsSchema","Circle","Drawing","mainShape","extraShapes","Array","background","attachment","owner","RectangleRecord","width","height","unionTypesSchema","Rectangle","Shape","variants","circle","rectangle","nestedOptionalsSchema","Config","tags","scores","label","twoVersionDerivedFieldsSchema","migrations","derivedFrom","aliasedEntryNameSchema","FooAlias","name","AnimalRecord","species","PlantRecord","genus","LivingBeingUnion","animal","plant","nestedUnionSchema","Animal","Plant","LivingBeing","Entity","livingBeing","optionalToRequiredFieldSchema","v1","Item","threeVersionChainSchema","v1Models","v2Models","hexColor","v3Models"],"sources":["fixtures.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 { SchemaBuilder, SchemaDefinition } from \"@palantir/pack.schema\";\nimport {\n defineRecord,\n defineSchema,\n defineSchemaUpdate,\n defineUnion,\n modelToRef,\n nextSchema,\n} from \"@palantir/pack.schema\";\nimport * as P from \"@palantir/pack.schema\";\n\n/** Single-version schema: ShapeBox with 5 fields */\nconst singleVersionModels = {\n ShapeBox: defineRecord(\"ShapeBox\", {\n docs: \"A box shape\",\n fields: {\n left: P.Double,\n right: P.Double,\n top: P.Double,\n bottom: P.Double,\n color: P.Optional(P.String),\n },\n }),\n};\nconst singleVersionSchemaNarrow = defineSchema(singleVersionModels);\nexport const singleVersionSchema: SchemaDefinition = singleVersionSchemaNarrow;\n\n/** Two-version schema with field removal (color removed, fillColor + strokeColor + opacity added) */\nexport const twoVersionFieldRemovalSchema: SchemaDefinition = {\n type: \"versioned\",\n models: {\n ShapeBox: defineRecord(\"ShapeBox\", {\n docs: \"A box shape\",\n fields: {\n left: P.Double,\n right: P.Double,\n top: P.Double,\n bottom: P.Double,\n fillColor: P.Optional(P.String),\n strokeColor: P.Optional(P.String),\n opacity: P.Optional(P.Double),\n },\n }),\n },\n version: 2,\n previous: singleVersionSchema,\n};\n\n/** Two-version schema with additive change only (adds fillColor) */\nconst addFillColorUpdate = defineSchemaUpdate(\n \"addFillColor\",\n (schema: SchemaBuilder<typeof singleVersionModels>) => ({\n ShapeBox: schema.ShapeBox\n .addField(\"fillColor\", P.Optional(P.String))\n .build(),\n }),\n);\n\nexport const twoVersionAdditiveSchema: SchemaDefinition = nextSchema(singleVersionSchemaNarrow)\n .addSchemaUpdate(addFillColorUpdate)\n .build();\n\n/**\n * Two-version schema adding a *required* additive field. Drives the type\n * generator down the path where `DocumentUpgradeFns` must include a zero-arg\n * thunk for the new field — `() => Model__v<current>[field]`. Optional\n * additive fields (above) are deliberately absent from `DocumentUpgradeFns`.\n */\nconst addOpacityRequiredUpdate = defineSchemaUpdate(\n \"addOpacityRequired\",\n (schema: SchemaBuilder<typeof singleVersionModels>) => ({\n ShapeBox: schema.ShapeBox\n .addField(\"opacity\", P.Double)\n .build(),\n }),\n);\n\nexport const twoVersionRequiredAdditiveSchema: SchemaDefinition = nextSchema(\n singleVersionSchemaNarrow,\n).addSchemaUpdate(addOpacityRequiredUpdate).build();\n\n/** Schema with ref fields: tests import paths for record refs, DocumentRef, UserRef */\nconst CircleRecord = defineRecord(\"Circle\", {\n docs: \"A circle\",\n fields: {\n radius: P.Double,\n },\n});\n\nconst DocRef: P.DocRef = { type: \"docRef\" };\nconst UserRefField: P.UserRef = { type: \"userRef\" };\n\nexport const refFieldsSchema: SchemaDefinition = defineSchema({\n Circle: CircleRecord,\n Drawing: defineRecord(\"Drawing\", {\n docs: \"A drawing with references\",\n fields: {\n mainShape: CircleRecord,\n extraShapes: P.Array(modelToRef(CircleRecord)),\n background: P.Optional(modelToRef(CircleRecord)),\n attachment: DocRef,\n owner: P.Optional(UserRefField),\n },\n }),\n});\n\n/** Schema with union types: tests union variant interfaces, discriminated union, and type guards */\nconst RectangleRecord = defineRecord(\"Rectangle\", {\n docs: \"A rectangle\",\n fields: {\n width: P.Double,\n height: P.Double,\n },\n});\n\nexport const unionTypesSchema: SchemaDefinition = defineSchema({\n Circle: CircleRecord,\n Rectangle: RectangleRecord,\n Shape: defineUnion(\"Shape\", {\n docs: \"A shape\",\n variants: {\n circle: CircleRecord,\n rectangle: RectangleRecord,\n },\n }),\n});\n\n/** Schema with nested optionals: tests that optional inside array structures is preserved */\nexport const nestedOptionalsSchema: SchemaDefinition = defineSchema({\n Config: defineRecord(\"Config\", {\n docs: \"A config with nested optional fields\",\n fields: {\n tags: P.Array(P.Optional(P.String)),\n scores: P.Array(P.Optional(P.Double)),\n label: P.Optional(P.String),\n },\n }),\n});\n\n/** Two-version schema with derived fields (color split into fillColor + strokeColor) */\nexport const twoVersionDerivedFieldsSchema: SchemaDefinition = {\n type: \"versioned\",\n models: {\n ShapeBox: defineRecord(\"ShapeBox\", {\n docs: \"A box shape\",\n fields: {\n left: P.Double,\n right: P.Double,\n top: P.Double,\n bottom: P.Double,\n fillColor: P.Optional(P.String),\n strokeColor: P.Optional(P.String),\n opacity: P.Optional(P.Double),\n },\n }),\n },\n version: 2,\n previous: singleVersionSchema,\n migrations: {\n ShapeBox: {\n fillColor: {\n derivedFrom: [\"color\"],\n },\n strokeColor: {\n derivedFrom: [\"color\"],\n },\n },\n },\n};\n\n/** Schema with aliased export key: export key \"FooAlias\" differs from model name \"Foo\" */\nexport const aliasedEntryNameSchema: SchemaDefinition = defineSchema({\n FooAlias: defineRecord(\"Foo\", {\n docs: \"A record exported under an alias\",\n fields: {\n name: P.String,\n },\n }),\n});\n\n/** Schema with nested union: Entity union has a variant that points to another union (LivingBeing) */\nconst AnimalRecord = defineRecord(\"Animal\", {\n docs: \"An animal\",\n fields: { species: P.String },\n});\n\nconst PlantRecord = defineRecord(\"Plant\", {\n docs: \"A plant\",\n fields: { genus: P.String },\n});\n\nconst LivingBeingUnion = defineUnion(\"LivingBeing\", {\n docs: \"A living being\",\n variants: {\n animal: AnimalRecord,\n plant: PlantRecord,\n },\n});\n\nexport const nestedUnionSchema: SchemaDefinition = defineSchema({\n Animal: AnimalRecord,\n Plant: PlantRecord,\n LivingBeing: LivingBeingUnion,\n Entity: defineUnion(\"Entity\", {\n docs: \"An entity\",\n variants: {\n livingBeing: LivingBeingUnion,\n },\n }),\n});\n\n/**\n * Two-version schema where a field starts as Optional(String) in v1 and becomes\n * required (String) in v2. The internal schema must remain optional because\n * documents written under v1 may legitimately omit the field.\n */\nexport const optionalToRequiredFieldSchema: SchemaDefinition = (() => {\n const v1 = defineSchema({\n Item: defineRecord(\"Item\", {\n docs: \"An item\",\n fields: {\n name: P.String,\n label: P.Optional(P.String),\n },\n }),\n });\n return {\n type: \"versioned\" as const,\n models: {\n Item: defineRecord(\"Item\", {\n docs: \"An item\",\n fields: {\n name: P.String,\n label: P.String,\n },\n }),\n },\n version: 2,\n previous: v1,\n };\n})();\n\n/** Three-version chain: Item (name, color -> name, hexColor -> name, hexColor, tags) */\nexport const threeVersionChainSchema: SchemaDefinition = (() => {\n const v1Models = {\n Item: defineRecord(\"Item\", {\n docs: \"\",\n fields: {\n name: P.String,\n color: P.Optional(P.String),\n },\n }),\n };\n const v2Models = {\n Item: defineRecord(\"Item\", {\n docs: \"\",\n fields: {\n name: P.String,\n hexColor: P.Optional(P.String),\n },\n }),\n };\n const v3Models = {\n Item: defineRecord(\"Item\", {\n docs: \"\",\n fields: {\n name: P.String,\n hexColor: P.Optional(P.String),\n tags: P.Optional(P.String),\n },\n }),\n };\n return {\n type: \"versioned\",\n models: v3Models,\n version: 3,\n previous: {\n type: \"versioned\",\n models: v2Models,\n version: 2,\n previous: { type: \"initial\", version: 1, models: v1Models },\n },\n };\n})();\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SACEA,YAAY,EACZC,YAAY,EACZC,kBAAkB,EAClBC,WAAW,EACXC,UAAU,EACVC,UAAU,QACL,uBAAuB;AAC9B,OAAO,KAAKC,CAAC,MAAM,uBAAuB;;AAE1C;AACA,MAAMC,mBAAmB,GAAG;EAC1BC,QAAQ,EAAER,YAAY,CAAC,UAAU,EAAE;IACjCS,IAAI,EAAE,aAAa;IACnBC,MAAM,EAAE;MACNC,IAAI,EAAEL,CAAC,CAACM,MAAM;MACdC,KAAK,EAAEP,CAAC,CAACM,MAAM;MACfE,GAAG,EAAER,CAAC,CAACM,MAAM;MACbG,MAAM,EAAET,CAAC,CAACM,MAAM;MAChBI,KAAK,EAAEV,CAAC,CAACW,QAAQ,CAACX,CAAC,CAACY,MAAM;IAC5B;EACF,C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AAC;EACD,MAAMwE,QAAQ,GAAG;IACfL,IAAI,EAAErF,YAAY,CAAC,MAAM,EAAE;MACzBS,IAAI,EAAE,EAAE;MACRC,MAAM,EAAE;QACN2D,IAAI,EAAE/D,CAAC,CAACY,MAAM;QACduE,QAAQ,EAAEnF,CAAC,CAACW,QAAQ,CAACX,CAAC,CAACY,MAAM,CAAC;QAC9B2C,IAAI,EAAEvD,CAAC,CAACW,QAAQ,CAACX,CAAC,CAACY,MAAM;MAC3B;IACF,CAAC;EACH,CAAC;EACD,OAAO;IACLI,IAAI,EAAE,WAAW;IACjBC,MAAM,EAAEmE,QAAQ;IAChB/D,OAAO,EAAE,CAAC;IACVC,QAAQ,EAAE;MACRN,IAAI,EAAE,WAAW;MACjBC,MAAM,EAAEiE,QAAQ;MAChB7D,OAAO,EAAE,CAAC;MACVC,QAAQ,EAAE;QAAEN,IAAI,EAAE,SAAS;QAAEK,OAAO,EAAE,CAAC;QAAEJ,MAAM,EAAEgE;MAAS;IAC5D;EACF,CAAC;AACH,CAAC,EAAE,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fixtures.js","names":["defineRecord","defineSchema","defineSchemaUpdate","defineUnion","modelToRef","nextSchema","P","singleVersionModels","ShapeBox","docs","fields","left","Double","right","top","bottom","color","Optional","String","singleVersionSchemaNarrow","singleVersionSchema","twoVersionFieldRemovalSchema","type","models","fillColor","strokeColor","opacity","version","previous","addFillColorUpdate","schema","addField","build","twoVersionAdditiveSchema","addSchemaUpdate","addOpacityRequiredUpdate","twoVersionRequiredAdditiveSchema","CircleRecord","radius","ResourceRefField","DocRef","UserRefField","refFieldsSchema","Circle","Drawing","mainShape","extraShapes","Array","background","attachment","owner","resource","RectangleRecord","width","height","unionTypesSchema","Rectangle","Shape","variants","circle","rectangle","nestedOptionalsSchema","Config","tags","scores","label","twoVersionDerivedFieldsSchema","migrations","derivedFrom","aliasedEntryNameSchema","FooAlias","name","AnimalRecord","species","PlantRecord","genus","LivingBeingUnion","animal","plant","nestedUnionSchema","Animal","Plant","LivingBeing","Entity","livingBeing","optionalToRequiredFieldSchema","v1","Item","threeVersionChainSchema","v1Models","v2Models","hexColor","v3Models"],"sources":["fixtures.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 { SchemaBuilder, SchemaDefinition } from \"@palantir/pack.schema\";\nimport {\n defineRecord,\n defineSchema,\n defineSchemaUpdate,\n defineUnion,\n modelToRef,\n nextSchema,\n} from \"@palantir/pack.schema\";\nimport * as P from \"@palantir/pack.schema\";\n\n/** Single-version schema: ShapeBox with 5 fields */\nconst singleVersionModels = {\n ShapeBox: defineRecord(\"ShapeBox\", {\n docs: \"A box shape\",\n fields: {\n left: P.Double,\n right: P.Double,\n top: P.Double,\n bottom: P.Double,\n color: P.Optional(P.String),\n },\n }),\n};\nconst singleVersionSchemaNarrow = defineSchema(singleVersionModels);\nexport const singleVersionSchema: SchemaDefinition = singleVersionSchemaNarrow;\n\n/** Two-version schema with field removal (color removed, fillColor + strokeColor + opacity added) */\nexport const twoVersionFieldRemovalSchema: SchemaDefinition = {\n type: \"versioned\",\n models: {\n ShapeBox: defineRecord(\"ShapeBox\", {\n docs: \"A box shape\",\n fields: {\n left: P.Double,\n right: P.Double,\n top: P.Double,\n bottom: P.Double,\n fillColor: P.Optional(P.String),\n strokeColor: P.Optional(P.String),\n opacity: P.Optional(P.Double),\n },\n }),\n },\n version: 2,\n previous: singleVersionSchema,\n};\n\n/** Two-version schema with additive change only (adds fillColor) */\nconst addFillColorUpdate = defineSchemaUpdate(\n \"addFillColor\",\n (schema: SchemaBuilder<typeof singleVersionModels>) => ({\n ShapeBox: schema.ShapeBox\n .addField(\"fillColor\", P.Optional(P.String))\n .build(),\n }),\n);\n\nexport const twoVersionAdditiveSchema: SchemaDefinition = nextSchema(singleVersionSchemaNarrow)\n .addSchemaUpdate(addFillColorUpdate)\n .build();\n\n/**\n * Two-version schema adding a *required* additive field. Drives the type\n * generator down the path where `DocumentUpgradeFns` must include a zero-arg\n * thunk for the new field — `() => Model__v<current>[field]`. Optional\n * additive fields (above) are deliberately absent from `DocumentUpgradeFns`.\n */\nconst addOpacityRequiredUpdate = defineSchemaUpdate(\n \"addOpacityRequired\",\n (schema: SchemaBuilder<typeof singleVersionModels>) => ({\n ShapeBox: schema.ShapeBox\n .addField(\"opacity\", P.Double)\n .build(),\n }),\n);\n\nexport const twoVersionRequiredAdditiveSchema: SchemaDefinition = nextSchema(\n singleVersionSchemaNarrow,\n).addSchemaUpdate(addOpacityRequiredUpdate).build();\n\n/** Schema with ref fields: tests import paths for record refs, ResourceRef, DocumentRef, UserRef */\nconst CircleRecord = defineRecord(\"Circle\", {\n docs: \"A circle\",\n fields: {\n radius: P.Double,\n },\n});\n\nconst ResourceRefField: P.ResourceRef = { type: \"resourceRef\" };\nconst DocRef: P.DocRef = { type: \"docRef\" };\nconst UserRefField: P.UserRef = { type: \"userRef\" };\n\nexport const refFieldsSchema: SchemaDefinition = defineSchema({\n Circle: CircleRecord,\n Drawing: defineRecord(\"Drawing\", {\n docs: \"A drawing with references\",\n fields: {\n mainShape: CircleRecord,\n extraShapes: P.Array(modelToRef(CircleRecord)),\n background: P.Optional(modelToRef(CircleRecord)),\n attachment: DocRef,\n owner: P.Optional(UserRefField),\n resource: ResourceRefField,\n },\n }),\n});\n\n/** Schema with union types: tests union variant interfaces, discriminated union, and type guards */\nconst RectangleRecord = defineRecord(\"Rectangle\", {\n docs: \"A rectangle\",\n fields: {\n width: P.Double,\n height: P.Double,\n },\n});\n\nexport const unionTypesSchema: SchemaDefinition = defineSchema({\n Circle: CircleRecord,\n Rectangle: RectangleRecord,\n Shape: defineUnion(\"Shape\", {\n docs: \"A shape\",\n variants: {\n circle: CircleRecord,\n rectangle: RectangleRecord,\n },\n }),\n});\n\n/** Schema with nested optionals: tests that optional inside array structures is preserved */\nexport const nestedOptionalsSchema: SchemaDefinition = defineSchema({\n Config: defineRecord(\"Config\", {\n docs: \"A config with nested optional fields\",\n fields: {\n tags: P.Array(P.Optional(P.String)),\n scores: P.Array(P.Optional(P.Double)),\n label: P.Optional(P.String),\n },\n }),\n});\n\n/** Two-version schema with derived fields (color split into fillColor + strokeColor) */\nexport const twoVersionDerivedFieldsSchema: SchemaDefinition = {\n type: \"versioned\",\n models: {\n ShapeBox: defineRecord(\"ShapeBox\", {\n docs: \"A box shape\",\n fields: {\n left: P.Double,\n right: P.Double,\n top: P.Double,\n bottom: P.Double,\n fillColor: P.Optional(P.String),\n strokeColor: P.Optional(P.String),\n opacity: P.Optional(P.Double),\n },\n }),\n },\n version: 2,\n previous: singleVersionSchema,\n migrations: {\n ShapeBox: {\n fillColor: {\n derivedFrom: [\"color\"],\n },\n strokeColor: {\n derivedFrom: [\"color\"],\n },\n },\n },\n};\n\n/** Schema with aliased export key: export key \"FooAlias\" differs from model name \"Foo\" */\nexport const aliasedEntryNameSchema: SchemaDefinition = defineSchema({\n FooAlias: defineRecord(\"Foo\", {\n docs: \"A record exported under an alias\",\n fields: {\n name: P.String,\n },\n }),\n});\n\n/** Schema with nested union: Entity union has a variant that points to another union (LivingBeing) */\nconst AnimalRecord = defineRecord(\"Animal\", {\n docs: \"An animal\",\n fields: { species: P.String },\n});\n\nconst PlantRecord = defineRecord(\"Plant\", {\n docs: \"A plant\",\n fields: { genus: P.String },\n});\n\nconst LivingBeingUnion = defineUnion(\"LivingBeing\", {\n docs: \"A living being\",\n variants: {\n animal: AnimalRecord,\n plant: PlantRecord,\n },\n});\n\nexport const nestedUnionSchema: SchemaDefinition = defineSchema({\n Animal: AnimalRecord,\n Plant: PlantRecord,\n LivingBeing: LivingBeingUnion,\n Entity: defineUnion(\"Entity\", {\n docs: \"An entity\",\n variants: {\n livingBeing: LivingBeingUnion,\n },\n }),\n});\n\n/**\n * Two-version schema where a field starts as Optional(String) in v1 and becomes\n * required (String) in v2. The internal schema must remain optional because\n * documents written under v1 may legitimately omit the field.\n */\nexport const optionalToRequiredFieldSchema: SchemaDefinition = (() => {\n const v1 = defineSchema({\n Item: defineRecord(\"Item\", {\n docs: \"An item\",\n fields: {\n name: P.String,\n label: P.Optional(P.String),\n },\n }),\n });\n return {\n type: \"versioned\" as const,\n models: {\n Item: defineRecord(\"Item\", {\n docs: \"An item\",\n fields: {\n name: P.String,\n label: P.String,\n },\n }),\n },\n version: 2,\n previous: v1,\n };\n})();\n\n/** Three-version chain: Item (name, color -> name, hexColor -> name, hexColor, tags) */\nexport const threeVersionChainSchema: SchemaDefinition = (() => {\n const v1Models = {\n Item: defineRecord(\"Item\", {\n docs: \"\",\n fields: {\n name: P.String,\n color: P.Optional(P.String),\n },\n }),\n };\n const v2Models = {\n Item: defineRecord(\"Item\", {\n docs: \"\",\n fields: {\n name: P.String,\n hexColor: P.Optional(P.String),\n },\n }),\n };\n const v3Models = {\n Item: defineRecord(\"Item\", {\n docs: \"\",\n fields: {\n name: P.String,\n hexColor: P.Optional(P.String),\n tags: P.Optional(P.String),\n },\n }),\n };\n return {\n type: \"versioned\",\n models: v3Models,\n version: 3,\n previous: {\n type: \"versioned\",\n models: v2Models,\n version: 2,\n previous: { type: \"initial\", version: 1, models: v1Models },\n },\n };\n})();\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SACEA,YAAY,EACZC,YAAY,EACZC,kBAAkB,EAClBC,WAAW,EACXC,UAAU,EACVC,UAAU,QACL,uBAAuB;AAC9B,OAAO,KAAKC,CAAC,MAAM,uBAAuB;;AAE1C;AACA,MAAMC,mBAAmB,GAAG;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AI,EAAE,EAAE;MACRC,MAAM,EAAE;QACN6D,IAAI,EAAEjE,CAAC,CAACY,MAAM;QACdF,KAAK,EAAEV,CAAC,CAACW,QAAQ,CAACX,CAAC,CAACY,MAAM;MAC5B;IACF,CAAC;EACH,CAAC;EACD,MAAMwE,QAAQ,GAAG;IACfH,IAAI,EAAEvF,YAAY,CAAC,MAAM,EAAE;MACzBS,IAAI,EAAE,EAAE;MACRC,MAAM,EAAE;QACN6D,IAAI,EAAEjE,CAAC,CAACY,MAAM;QACdyE,QAAQ,EAAErF,CAAC,CAACW,QAAQ,CAACX,CAAC,CAACY,MAAM;MAC/B;IACF,CAAC;EACH,CAAC;EACD,MAAM0E,QAAQ,GAAG;IACfL,IAAI,EAAEvF,YAAY,CAAC,MAAM,EAAE;MACzBS,IAAI,EAAE,EAAE;MACRC,MAAM,EAAE;QACN6D,IAAI,EAAEjE,CAAC,CAACY,MAAM;QACdyE,QAAQ,EAAErF,CAAC,CAACW,QAAQ,CAACX,CAAC,CAACY,MAAM,CAAC;QAC9B6C,IAAI,EAAEzD,CAAC,CAACW,QAAQ,CAACX,CAAC,CAACY,MAAM;MAC3B;IACF,CAAC;EACH,CAAC;EACD,OAAO;IACLI,IAAI,EAAE,WAAW;IACjBC,MAAM,EAAEqE,QAAQ;IAChBjE,OAAO,EAAE,CAAC;IACVC,QAAQ,EAAE;MACRN,IAAI,EAAE,WAAW;MACjBC,MAAM,EAAEmE,QAAQ;MAChB/D,OAAO,EAAE,CAAC;MACVC,QAAQ,EAAE;QAAEN,IAAI,EAAE,SAAS;QAAEK,OAAO,EAAE,CAAC;QAAEJ,MAAM,EAAEkE;MAAS;IAC5D;EACF,CAAC;AACH,CAAC,EAAE,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertSchemaToSteps.js","names":["yaml","convertFieldType","field","type","items","item","name","Error","convertRecordToYaml","recordDef","result","fields","docs","fieldName","fieldDef","Object","entries","fieldType","convertUnionToYaml","unionDef","variants","variantName","variantRef","discriminant","convertSchemaToSteps","schema","exportKey","def","steps","records","unions","values","keys","length","push","convertStepsToYamlString","dump","flowLevel","lineWidth","noRefs","quotingType","forceQuotes","skipInvalid"],"sources":["convertSchemaToSteps.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 yaml from \"js-yaml\";\nimport type { MigrationStep, UnionDefinition } from \"../steps/parseMigrationSteps.js\";\nimport type { P } from \"./validateSchemaModule.js\";\n\nfunction convertFieldType(field: P.Type): string {\n switch (field.type) {\n case \"array\":\n return `array<${convertFieldType(field.items as P.Type)}>`;\n case \"boolean\":\n return \"boolean\";\n case \"docRef\":\n return \"docRef\";\n case \"double\":\n return \"double\";\n case \"mediaRef\":\n return \"mediaRef\";\n case \"objectRef\":\n return \"objectRef\";\n case \"optional\":\n return `optional<${convertFieldType(field.item as P.Type)}>`;\n case \"ref\":\n return field.name;\n case \"string\":\n return \"string\";\n case \"unknown\":\n return \"unknown\";\n case \"userRef\":\n return \"userRef\";\n default:\n field satisfies never;\n throw new Error(`Unsupported field type: ${(field as P.Type).type}`);\n }\n}\n\nfunction convertRecordToYaml(\n recordDef: P.RecordDef,\n): { docs?: string; fields: Record<string, string> } {\n const result: { docs?: string; fields: Record<string, string> } = {\n fields: {},\n };\n\n if (recordDef.docs) {\n result.docs = recordDef.docs;\n }\n\n for (const [fieldName, fieldDef] of Object.entries(recordDef.fields)) {\n const fieldType = convertFieldType(fieldDef);\n result.fields[fieldName] = fieldType;\n }\n\n return result;\n}\n\nfunction convertUnionToYaml(unionDef: P.UnionDef): UnionDefinition {\n const variants: Record<string, string> = {};\n\n for (const [variantName, variantRef] of Object.entries(unionDef.variants)) {\n variants[variantName] = variantRef.name;\n }\n\n const result: UnionDefinition = {\n variants,\n };\n\n if (unionDef.discriminant !== \"type\") {\n result.discriminant = unionDef.discriminant;\n }\n\n return result;\n}\n\nexport function convertSchemaToSteps(schema: P.ReturnedSchema): MigrationStep[] {\n // Reject aliased schemas: the YAML step format cannot represent exportKey !== declaredName\n for (const [exportKey, def] of Object.entries(schema)) {\n if (exportKey !== def.name) {\n throw new Error(\n `Schema entry \"${exportKey}\" has declared model name \"${def.name}\". `\n + `The migration-step YAML format cannot represent aliases (exportKey !== declaredName). `\n + `Use the same name for both, or use the IR pipeline instead.`,\n );\n }\n }\n\n const steps: MigrationStep[] = [];\n const records: Record<string, { docs?: string; fields: Record<string, string> }> = {};\n const unions: Record<string, UnionDefinition> = {};\n\n for (const def of Object.values(schema)) {\n switch (def.type) {\n case \"record\": {\n records[def.name] = convertRecordToYaml(def);\n break;\n }\n case \"union\": {\n unions[def.name] = convertUnionToYaml(def);\n break;\n }\n }\n }\n\n if (Object.keys(records).length > 0) {\n steps.push({ \"add-records\": records });\n }\n\n if (Object.keys(unions).length > 0) {\n steps.push({ \"add-union\": unions });\n }\n\n return steps;\n}\n\nexport function convertStepsToYamlString(steps: MigrationStep[]): string {\n return yaml.dump(steps, {\n flowLevel: -1,\n lineWidth: -1,\n noRefs: true,\n quotingType: \"'\",\n forceQuotes: false,\n skipInvalid: false,\n });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,SAAS;AAI1B,SAASC,gBAAgBA,CAACC,KAAa,EAAU;EAC/C,QAAQA,KAAK,CAACC,IAAI;IAChB,KAAK,OAAO;MACV,OAAO,SAASF,gBAAgB,CAACC,KAAK,CAACE,KAAe,CAAC,GAAG;IAC5D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AAW,EAAEJ;IAAO,CAAC,CAAC;EACrC;EAEA,OAAOF,KAAK;AACd;AAEA,OAAO,SAASO,wBAAwBA,CAACP,KAAsB,EAAU;EACvE,OAAO5B,IAAI,CAACoC,IAAI,CAACR,KAAK,EAAE;IACtBS,SAAS,EAAE,CAAC,CAAC;IACbC,SAAS,EAAE,CAAC,CAAC;IACbC,MAAM,EAAE,IAAI;IACZC,WAAW,EAAE,GAAG;IAChBC,WAAW,EAAE,KAAK;IAClBC,WAAW,EAAE;EACf,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"convertSchemaToSteps.js","names":["yaml","convertFieldType","field","type","items","item","name","Error","convertRecordToYaml","recordDef","result","fields","docs","fieldName","fieldDef","Object","entries","fieldType","convertUnionToYaml","unionDef","variants","variantName","variantRef","discriminant","convertSchemaToSteps","schema","exportKey","def","steps","records","unions","values","keys","length","push","convertStepsToYamlString","dump","flowLevel","lineWidth","noRefs","quotingType","forceQuotes","skipInvalid"],"sources":["convertSchemaToSteps.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 yaml from \"js-yaml\";\nimport type { MigrationStep, UnionDefinition } from \"../steps/parseMigrationSteps.js\";\nimport type { P } from \"./validateSchemaModule.js\";\n\nfunction convertFieldType(field: P.Type): string {\n switch (field.type) {\n case \"array\":\n return `array<${convertFieldType(field.items as P.Type)}>`;\n case \"resourceRef\":\n return \"resourceRef\";\n case \"boolean\":\n return \"boolean\";\n case \"docRef\":\n return \"docRef\";\n case \"double\":\n return \"double\";\n case \"mediaRef\":\n return \"mediaRef\";\n case \"objectRef\":\n return \"objectRef\";\n case \"optional\":\n return `optional<${convertFieldType(field.item as P.Type)}>`;\n case \"ref\":\n return field.name;\n case \"string\":\n return \"string\";\n case \"unknown\":\n return \"unknown\";\n case \"userRef\":\n return \"userRef\";\n default:\n field satisfies never;\n throw new Error(`Unsupported field type: ${(field as P.Type).type}`);\n }\n}\n\nfunction convertRecordToYaml(\n recordDef: P.RecordDef,\n): { docs?: string; fields: Record<string, string> } {\n const result: { docs?: string; fields: Record<string, string> } = {\n fields: {},\n };\n\n if (recordDef.docs) {\n result.docs = recordDef.docs;\n }\n\n for (const [fieldName, fieldDef] of Object.entries(recordDef.fields)) {\n const fieldType = convertFieldType(fieldDef);\n result.fields[fieldName] = fieldType;\n }\n\n return result;\n}\n\nfunction convertUnionToYaml(unionDef: P.UnionDef): UnionDefinition {\n const variants: Record<string, string> = {};\n\n for (const [variantName, variantRef] of Object.entries(unionDef.variants)) {\n variants[variantName] = variantRef.name;\n }\n\n const result: UnionDefinition = {\n variants,\n };\n\n if (unionDef.discriminant !== \"type\") {\n result.discriminant = unionDef.discriminant;\n }\n\n return result;\n}\n\nexport function convertSchemaToSteps(schema: P.ReturnedSchema): MigrationStep[] {\n // Reject aliased schemas: the YAML step format cannot represent exportKey !== declaredName\n for (const [exportKey, def] of Object.entries(schema)) {\n if (exportKey !== def.name) {\n throw new Error(\n `Schema entry \"${exportKey}\" has declared model name \"${def.name}\". `\n + `The migration-step YAML format cannot represent aliases (exportKey !== declaredName). `\n + `Use the same name for both, or use the IR pipeline instead.`,\n );\n }\n }\n\n const steps: MigrationStep[] = [];\n const records: Record<string, { docs?: string; fields: Record<string, string> }> = {};\n const unions: Record<string, UnionDefinition> = {};\n\n for (const def of Object.values(schema)) {\n switch (def.type) {\n case \"record\": {\n records[def.name] = convertRecordToYaml(def);\n break;\n }\n case \"union\": {\n unions[def.name] = convertUnionToYaml(def);\n break;\n }\n }\n }\n\n if (Object.keys(records).length > 0) {\n steps.push({ \"add-records\": records });\n }\n\n if (Object.keys(unions).length > 0) {\n steps.push({ \"add-union\": unions });\n }\n\n return steps;\n}\n\nexport function convertStepsToYamlString(steps: MigrationStep[]): string {\n return yaml.dump(steps, {\n flowLevel: -1,\n lineWidth: -1,\n noRefs: true,\n quotingType: \"'\",\n forceQuotes: false,\n skipInvalid: false,\n });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,SAAS;AAI1B,SAASC,gBAAgBA,CAACC,KAAa,EAAU;EAC/C,QAAQA,KAAK,CAACC,IAAI;IAChB,KAAK,OAAO;MACV,OAAO,SAASF,gBAAgB,CAACC,KAAK,CAACE,KAAe,CAAC,GAAG;IAC5D,KAAK,aAAa;MAChB,OAAO,aAAa;IACtB,KAAK,SAAS;MACZ,OAAO,SAAS;IAClB,KAAK,QAAQ;MACX,OAAO,QAAQ;IACjB,KAAK,QAAQ;MACX,OAAO,QAAQ;IACjB,KAAK,UAAU;MACb,OAAO,UAAU;IACnB,KAAK,WAAW;MACd,OAAO,WAAW;IACpB,KAAK,UAAU;MACb,OAAO,YAAYH,gBAAgB,CAACC,KAAK,CAACG,IAAc,CAAC,GAAG;IAC9D,KAAK,KAAK;MACR,OAAOH,KAAK,CAACI,IAAI;IACnB,KAAK,QAAQ;MACX,OAAO,QAAQ;IACjB,KAAK,SAAS;MACZ,OAAO,SAAS;IAClB,KAAK,SAAS;MACZ,OAAO,SAAS;IAClB;MAEE,MAAM,IAAIC,KAAK,CAAC,2BAA4BL,KAAK,CAAYC,IAAI,EAAE,CAAC;EACxE;AACF;AAEA,SAASK,mBAAmBA,CAC1BC,SAAsB,EAC6B;EACnD,MAAMC,MAAyD,GAAG;IAChEC,MAAM,EAAE,CAAC;EACX,CAAC;EAED,IAAIF,SAAS,CAACG,IAAI,EAAE;IAClBF,MAAM,CAACE,IAAI,GAAGH,SA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AAE;IACvC,QAAQE,GAAG,CAACxB,IAAI;MACd,KAAK,QAAQ;QAAE;UACb0B,OAAO,CAACF,GAAG,CAACrB,IAAI,CAAC,GAAGE,mBAAmB,CAACmB,GAAG,CAAC;UAC5C;QACF;MACA,KAAK,OAAO;QAAE;UACZG,MAAM,CAACH,GAAG,CAACrB,IAAI,CAAC,GAAGY,kBAAkB,CAACS,GAAG,CAAC;UAC1C;QACF;IACF;EACF;EAEA,IAAIZ,MAAM,CAACiB,IAAI,CAACH,OAAO,CAAC,CAACI,MAAM,GAAG,CAAC,EAAE;IACnCL,KAAK,CAACM,IAAI,CAAC;MAAE,aAAa,EAAEL;IAAQ,CAAC,CAAC;EACxC;EAEA,IAAId,MAAM,CAACiB,IAAI,CAACF,MAAM,CAAC,CAACG,MAAM,GAAG,CAAC,EAAE;IAClCL,KAAK,CAACM,IAAI,CAAC;MAAE,WAAW,EAAEJ;IAAO,CAAC,CAAC;EACrC;EAEA,OAAOF,KAAK;AACd;AAEA,OAAO,SAASO,wBAAwBA,CAACP,KAAsB,EAAU;EACvE,OAAO5B,IAAI,CAACoC,IAAI,CAACR,KAAK,EAAE;IACtBS,SAAS,EAAE,CAAC,CAAC;IACbC,SAAS,EAAE,CAAC,CAAC;IACbC,MAAM,EAAE,IAAI;IACZC,WAAW,EAAE,GAAG;IAChBC,WAAW,EAAE,KAAK;IAClBC,WAAW,EAAE;EACf,CAAC,CAAC;AACJ","ignoreList":[]}
|
|
@@ -53,14 +53,17 @@ function detectUsedRefTypes(schema) {
|
|
|
53
53
|
scanField(field.items);
|
|
54
54
|
}
|
|
55
55
|
break;
|
|
56
|
+
case TypeKind.RESOURCE_REF:
|
|
57
|
+
refTypes.add("ResourceRid");
|
|
58
|
+
break;
|
|
56
59
|
case TypeKind.DOC_REF:
|
|
57
|
-
refTypes.add("
|
|
60
|
+
refTypes.add("DocumentId");
|
|
58
61
|
break;
|
|
59
62
|
case TypeKind.MEDIA_REF:
|
|
60
|
-
refTypes.add("
|
|
63
|
+
refTypes.add("MediaId");
|
|
61
64
|
break;
|
|
62
65
|
case TypeKind.OBJECT_REF:
|
|
63
|
-
refTypes.add("
|
|
66
|
+
refTypes.add("ObjectId");
|
|
64
67
|
break;
|
|
65
68
|
case TypeKind.OPTIONAL:
|
|
66
69
|
if (isOptionalField(field)) {
|
|
@@ -68,7 +71,7 @@ function detectUsedRefTypes(schema) {
|
|
|
68
71
|
}
|
|
69
72
|
break;
|
|
70
73
|
case TypeKind.USER_REF:
|
|
71
|
-
refTypes.add("
|
|
74
|
+
refTypes.add("UserId");
|
|
72
75
|
break;
|
|
73
76
|
}
|
|
74
77
|
}
|
|
@@ -196,14 +199,16 @@ function convertTypeToTypeScript(fieldType, schema) {
|
|
|
196
199
|
throw new Error("Array field is missing items type");
|
|
197
200
|
}
|
|
198
201
|
return `readonly ${convertTypeToTypeScript(fieldType.items, schema)}[]`;
|
|
202
|
+
case TypeKind.RESOURCE_REF:
|
|
203
|
+
return "ResourceRid";
|
|
199
204
|
case TypeKind.DOC_REF:
|
|
200
|
-
return "
|
|
205
|
+
return "DocumentId";
|
|
201
206
|
case TypeKind.DOUBLE:
|
|
202
207
|
return "number";
|
|
203
208
|
case TypeKind.MEDIA_REF:
|
|
204
|
-
return "
|
|
209
|
+
return "MediaId";
|
|
205
210
|
case TypeKind.OBJECT_REF:
|
|
206
|
-
return "
|
|
211
|
+
return "ObjectId";
|
|
207
212
|
case TypeKind.OPTIONAL:
|
|
208
213
|
if (!isOptionalField(fieldType)) {
|
|
209
214
|
throw new Error("Optional field is missing inner type");
|
|
@@ -221,7 +226,7 @@ function convertTypeToTypeScript(fieldType, schema) {
|
|
|
221
226
|
case TypeKind.STRING:
|
|
222
227
|
return "string";
|
|
223
228
|
case TypeKind.USER_REF:
|
|
224
|
-
return "
|
|
229
|
+
return "UserId";
|
|
225
230
|
default:
|
|
226
231
|
{
|
|
227
232
|
throw new Error(`Unknown schema field type: ${fieldType.type}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypesFromSchema.js","names":["TypeKind","SchemaTypeKind","formatVariantName","GENERATED_FILE_HEADER","ANY","SchemaDefKind","RECORD","UNION","isRecordSchema","item","type","isUnionSchema","isRefField","field","REF","isArrayField","ARRAY","isOptionalField","OPTIONAL","detectUsedRefTypes","schema","refTypes","Set","scanField","items","DOC_REF","add","MEDIA_REF","OBJECT_REF","USER_REF","Object","values","fields","variant","variants","generateTypesFromSchema","runtimeSchema","usedRefTypes","output","size","refTypesList","Array","from","sort","join","exportName","entries","generateRecordInterface","unionEntries","filter","_","forEach","i","unionOutput","generateUnionType","length","record","docs","fieldName","fieldType","tsType","convertTypeToTypeScript","optional","union","variantInterfaces","discriminantField","discriminant","variantName","variantType","interfaceName","push","name","discriminatorValue","refType","recordName","findRecordExportName","map","v","Error","DOUBLE","STRING"],"sources":["generateTypesFromSchema.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ReturnedSchema, Schema } from \"@palantir/pack.schema\";\nimport { TypeKind as SchemaTypeKind } from \"@palantir/pack.schema\";\nimport { formatVariantName } from \"../formatVariantName.js\";\nimport { GENERATED_FILE_HEADER } from \"../generatedFileHeader.js\";\n\nconst TypeKind: typeof SchemaTypeKind & { readonly ANY: \"any\" } = {\n ...SchemaTypeKind,\n ANY: \"any\",\n};\n\nconst SchemaDefKind = {\n RECORD: \"record\",\n UNION: \"union\",\n} as const;\n\n// Base type definition for schema fields\ninterface BaseSchemaField {\n readonly type: string;\n}\n\ninterface AnyField extends BaseSchemaField {\n readonly type: typeof TypeKind.ANY;\n}\n\ninterface ArrayField extends BaseSchemaField {\n readonly type: typeof TypeKind.ARRAY;\n readonly items: SchemaField;\n}\n\ninterface DocRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.DOC_REF;\n}\n\ninterface DoubleField extends BaseSchemaField {\n readonly type: typeof TypeKind.DOUBLE;\n}\n\ninterface MediaRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.MEDIA_REF;\n}\n\ninterface ObjectRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.OBJECT_REF;\n}\n\ninterface OptionalField extends BaseSchemaField {\n readonly type: typeof TypeKind.OPTIONAL;\n readonly item: SchemaField;\n}\n\ninterface RefField extends BaseSchemaField {\n readonly type: typeof TypeKind.REF;\n readonly refType: \"record\" | \"union\";\n readonly name: string;\n}\n\ninterface StringField extends BaseSchemaField {\n readonly type: typeof TypeKind.STRING;\n}\n\ninterface UserRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.USER_REF;\n}\n\ntype SchemaField =\n | AnyField\n | ArrayField\n | DocRefField\n | DoubleField\n | MediaRefField\n | ObjectRefField\n | OptionalField\n | RefField\n | StringField\n | UserRefField;\n\ninterface RuntimeSchemaRecord {\n readonly type: typeof SchemaDefKind.RECORD;\n readonly name: string;\n readonly docs?: string;\n readonly fields: Readonly<Record<string, SchemaField>>;\n readonly ref?: RefField & {\n readonly refType: \"record\";\n };\n}\n\ninterface RuntimeSchemaUnion {\n readonly type: typeof SchemaDefKind.UNION;\n readonly name?: string;\n readonly variants: Readonly<Record<string, SchemaField>>;\n readonly discriminant: string;\n readonly ref?: RefField & {\n readonly refType: \"union\";\n };\n}\n\ntype RuntimeSchemaItem = RuntimeSchemaRecord | RuntimeSchemaUnion;\ntype RuntimeSchema = Record<string, RuntimeSchemaItem>;\n\n// Type guards\nfunction isRecordSchema(item: RuntimeSchemaItem): item is RuntimeSchemaRecord {\n return item.type === SchemaDefKind.RECORD && \"name\" in item && \"fields\" in item;\n}\n\nfunction isUnionSchema(item: RuntimeSchemaItem): item is RuntimeSchemaUnion {\n return item.type === SchemaDefKind.UNION && \"variants\" in item && \"discriminant\" in item;\n}\n\nfunction isRefField(field: SchemaField): field is RefField {\n return field.type === TypeKind.REF && \"refType\" in field && \"name\" in field;\n}\n\nfunction isArrayField(field: SchemaField): field is ArrayField {\n return field.type === TypeKind.ARRAY && \"items\" in field;\n}\n\nfunction isOptionalField(field: SchemaField): field is OptionalField {\n return field.type === TypeKind.OPTIONAL && \"item\" in field;\n}\n\nfunction detectUsedRefTypes(schema: RuntimeSchema): Set<string> {\n const refTypes = new Set<string>();\n\n function scanField(field: SchemaField): void {\n switch (field.type) {\n case TypeKind.ARRAY:\n if (isArrayField(field)) {\n scanField(field.items);\n }\n break;\n case TypeKind.DOC_REF:\n refTypes.add(\"DocumentRef\");\n break;\n case TypeKind.MEDIA_REF:\n refTypes.add(\"MediaRef\");\n break;\n case TypeKind.OBJECT_REF:\n refTypes.add(\"ObjectRef\");\n break;\n case TypeKind.OPTIONAL:\n if (isOptionalField(field)) {\n scanField(field.item);\n }\n break;\n case TypeKind.USER_REF:\n refTypes.add(\"UserRef\");\n break;\n }\n }\n\n for (const item of Object.values(schema)) {\n if (isRecordSchema(item)) {\n for (const field of Object.values(item.fields)) {\n scanField(field);\n }\n } else if (isUnionSchema(item)) {\n for (const variant of Object.values(item.variants)) {\n scanField(variant);\n }\n }\n }\n\n return refTypes;\n}\n\nexport function generateTypesFromSchema<T extends ReturnedSchema>(\n schema: Schema<T>,\n): string {\n const runtimeSchema = schema as unknown as RuntimeSchema;\n\n // Detect which ref types are used in the schema\n const usedRefTypes = detectUsedRefTypes(runtimeSchema);\n\n let output = GENERATED_FILE_HEADER;\n\n // Add conditional imports based on which ref types are used\n if (usedRefTypes.size > 0) {\n const refTypesList = Array.from(usedRefTypes).sort().join(\", \");\n output +=\n `import type { ${refTypesList} } from \"@palantir/pack.document-schema.model-types\";\\n`;\n }\n\n output += \"\\n\";\n\n // First pass: generate record interfaces\n for (const [exportName, item] of Object.entries(runtimeSchema)) {\n if (item.type === SchemaDefKind.RECORD && isRecordSchema(item)) {\n output += generateRecordInterface(item, exportName, runtimeSchema);\n output += \"\\n\";\n }\n }\n\n // Second pass: generate union types\n const unionEntries = Object.entries(runtimeSchema).filter(\n ([_, item]) => item.type === SchemaDefKind.UNION && isUnionSchema(item),\n );\n\n unionEntries.forEach(([exportName, item], i) => {\n if (isUnionSchema(item)) {\n const unionOutput = generateUnionType(item, exportName, runtimeSchema);\n if (unionOutput) {\n output += unionOutput;\n // Only add newline if not the last union\n if (i < unionEntries.length - 1) {\n output += \"\\n\";\n }\n }\n }\n });\n\n return output;\n}\n\nfunction generateRecordInterface(\n record: RuntimeSchemaRecord,\n exportName: string,\n schema: RuntimeSchema,\n): string {\n let output = \"\";\n\n if (record.docs) {\n output += `/**\\n * ${record.docs}\\n */\\n`;\n }\n\n output += `export interface ${exportName} {\\n`;\n\n for (const [fieldName, fieldType] of Object.entries(record.fields)) {\n const tsType = convertTypeToTypeScript(fieldType, schema);\n const optional = fieldType.type === TypeKind.OPTIONAL ? \"?\" : \"\";\n output += ` readonly ${fieldName}${optional}: ${tsType};\\n`;\n }\n\n output += \"}\\n\";\n\n return output;\n}\n\nfunction generateUnionType(\n union: RuntimeSchemaUnion,\n exportName: string,\n schema: RuntimeSchema,\n): string {\n let output = \"\";\n const variantInterfaces: Array<{ name: string; discriminatorValue: string }> = [];\n const discriminantField = union.discriminant;\n\n // First pass: generate variant interfaces\n for (const [variantName, variantType] of Object.entries(union.variants)) {\n const interfaceName = `${exportName}${formatVariantName(variantName)}`;\n variantInterfaces.push({ name: interfaceName, discriminatorValue: variantName });\n\n if (variantType.type === TypeKind.REF && variantType.refType === \"record\") {\n // Find the corresponding record name in the schema\n const recordName = findRecordExportName(variantType.name, schema);\n if (recordName) {\n output += `export interface ${interfaceName} extends ${recordName} {\\n`;\n output += ` readonly ${discriminantField}: \"${variantName}\";\\n`;\n output += \"}\\n\\n\";\n }\n } else {\n // Handle value types\n const tsType = convertTypeToTypeScript(variantType, schema);\n output += `export interface ${interfaceName} {\\n`;\n output += ` readonly ${discriminantField}: \"${variantName}\";\\n`;\n output += ` readonly value: ${tsType};\\n`;\n output += \"}\\n\\n\";\n }\n }\n\n // Second pass: generate the union type\n output += `export type ${exportName} = ${variantInterfaces.map(v => v.name).join(\" | \")};\\n\\n`;\n\n // Third pass: generate type guards\n for (let i = 0; i < variantInterfaces.length; i++) {\n const variant = variantInterfaces[i]!;\n output +=\n `export function is${variant.name}(value: ${exportName}): value is ${variant.name} {\\n`;\n output += ` return value.${discriminantField} === \"${variant.discriminatorValue}\";\\n`;\n output += \"}\\n\\n\";\n }\n\n return output;\n}\n\nfunction findRecordExportName(\n recordName: string,\n schema: RuntimeSchema,\n): string | null {\n for (const [exportName, item] of Object.entries(schema)) {\n if (isRecordSchema(item) && item.name === recordName) {\n return exportName;\n }\n }\n return null;\n}\n\nfunction convertTypeToTypeScript(\n fieldType: SchemaField,\n schema?: RuntimeSchema,\n): string {\n switch (fieldType.type) {\n case TypeKind.ANY:\n return \"any\";\n case TypeKind.ARRAY:\n if (!isArrayField(fieldType)) {\n throw new Error(\"Array field is missing items type\");\n }\n return `readonly ${convertTypeToTypeScript(fieldType.items, schema)}[]`;\n case TypeKind.DOC_REF:\n return \"DocumentRef\";\n case TypeKind.DOUBLE:\n return \"number\";\n case TypeKind.MEDIA_REF:\n return \"MediaRef\";\n case TypeKind.OBJECT_REF:\n return \"ObjectRef\";\n case TypeKind.OPTIONAL:\n if (!isOptionalField(fieldType)) {\n throw new Error(\"Optional field is missing inner type\");\n }\n return convertTypeToTypeScript(fieldType.item, schema);\n case TypeKind.REF:\n if (!isRefField(fieldType)) {\n throw new Error(\"Ref field is missing name or refType\");\n }\n if (fieldType.refType === \"record\") {\n const exportName = schema ? findRecordExportName(fieldType.name, schema) : null;\n return exportName ?? fieldType.name;\n }\n return fieldType.name;\n case TypeKind.STRING:\n return \"string\";\n case TypeKind.USER_REF:\n return \"UserRef\";\n default: {\n const _exhaustive: never = fieldType;\n throw new Error(`Unknown schema field type: ${(_exhaustive as SchemaField).type}`);\n }\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,QAAQ,IAAIC,cAAc,QAAQ,uBAAuB;AAClE,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,qBAAqB,QAAQ,2BAA2B;AAEjE,MAAMH,QAAyD,GAAG;EAChE,GAAGC,cAAc;EACjBG,GAAG,EAAE;AACP,CAAC;AAED,MAAMC,aAAa,GAAG;EACpBC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE;AACT,CAAU;;AAEV;;AAoFA;AACA,SAASC,cAAcA,CAACC,IAAuB,EAA+B;EAC5E,OAAOA,IAAI,CAACC,IAAI,KAAKL,aAAa,CAACC,MAAM,IAAI,MAAM,IAAIG,IAAI,IAAI,QAAQ,IAAIA,IAAI;AACjF;AAEA,SAASE,aAAaA,CAACF,IAAuB,EAA8B;EAC1E,OAAOA,IAAI,CAACC,IAAI,KAAKL,aAAa,CAACE,KAAK,IAAI,UAAU,IAAIE,IAAI,IAAI,cAAc,IAAIA,IAAI;AAC1F;AAEA,SAASG,UAAUA,CAACC,KAAkB,EAAqB;EACzD,OAAOA,KAAK,CAACH,IAAI,KAAKV,QAAQ,CAACc,GAAG,IAAI,SAAS,IAAID,KAAK,IAAI,MAAM,IAAIA,KAAK;AAC7E;AAEA,SAASE,YAAYA,CAACF,KAAkB,EAAuB;EAC7D,OAAOA,KAAK,CAACH,IAAI,KAAKV,QAAQ,CAACgB,KAAK,IAAI,OAAO,IAAIH,KAAK;AAC1D;AAEA,SAASI,eAAeA,CAACJ,KAAkB,EAA0B;EACnE,OAAOA,KAAK,CAACH,IAAI,KAAKV,QAAQ,CAACkB,QAAQ,IAAI,MAAM,IAAIL,KAAK;AAC5D;AAEA,SAASM,kBAAkBA,CAACC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A,IAAInB,SAAS,CAACc,OAAO,KAAK,QAAQ,EAAE;QAClC,MAAM5B,UAAU,GAAGzB,MAAM,GAAGuD,oBAAoB,CAAChB,SAAS,CAACY,IAAI,EAAEnD,MAAM,CAAC,GAAG,IAAI;QAC/E,OAAOyB,UAAU,IAAIc,SAAS,CAACY,IAAI;MACrC;MACA,OAAOZ,SAAS,CAACY,IAAI;IACvB,KAAKvE,QAAQ,CAACgF,MAAM;MAClB,OAAO,QAAQ;IACjB,KAAKhF,QAAQ,CAAC6B,QAAQ;MACpB,OAAO,SAAS;IAClB;MAAS;QAEP,MAAM,IAAIiD,KAAK,CAAC,8BADWnB,SAAS,CACuCjD,IAAI,EAAE,CAAC;MACpF;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"generateTypesFromSchema.js","names":["TypeKind","SchemaTypeKind","formatVariantName","GENERATED_FILE_HEADER","ANY","SchemaDefKind","RECORD","UNION","isRecordSchema","item","type","isUnionSchema","isRefField","field","REF","isArrayField","ARRAY","isOptionalField","OPTIONAL","detectUsedRefTypes","schema","refTypes","Set","scanField","items","RESOURCE_REF","add","DOC_REF","MEDIA_REF","OBJECT_REF","USER_REF","Object","values","fields","variant","variants","generateTypesFromSchema","runtimeSchema","usedRefTypes","output","size","refTypesList","Array","from","sort","join","exportName","entries","generateRecordInterface","unionEntries","filter","_","forEach","i","unionOutput","generateUnionType","length","record","docs","fieldName","fieldType","tsType","convertTypeToTypeScript","optional","union","variantInterfaces","discriminantField","discriminant","variantName","variantType","interfaceName","push","name","discriminatorValue","refType","recordName","findRecordExportName","map","v","Error","DOUBLE","STRING"],"sources":["generateTypesFromSchema.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ReturnedSchema, Schema } from \"@palantir/pack.schema\";\nimport { TypeKind as SchemaTypeKind } from \"@palantir/pack.schema\";\nimport { formatVariantName } from \"../formatVariantName.js\";\nimport { GENERATED_FILE_HEADER } from \"../generatedFileHeader.js\";\n\nconst TypeKind: typeof SchemaTypeKind & { readonly ANY: \"any\" } = {\n ...SchemaTypeKind,\n ANY: \"any\",\n};\n\nconst SchemaDefKind = {\n RECORD: \"record\",\n UNION: \"union\",\n} as const;\n\n// Base type definition for schema fields\ninterface BaseSchemaField {\n readonly type: string;\n}\n\ninterface AnyField extends BaseSchemaField {\n readonly type: typeof TypeKind.ANY;\n}\n\ninterface ArrayField extends BaseSchemaField {\n readonly type: typeof TypeKind.ARRAY;\n readonly items: SchemaField;\n}\n\ninterface ResourceRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.RESOURCE_REF;\n}\n\ninterface DocRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.DOC_REF;\n}\n\ninterface DoubleField extends BaseSchemaField {\n readonly type: typeof TypeKind.DOUBLE;\n}\n\ninterface MediaRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.MEDIA_REF;\n}\n\ninterface ObjectRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.OBJECT_REF;\n}\n\ninterface OptionalField extends BaseSchemaField {\n readonly type: typeof TypeKind.OPTIONAL;\n readonly item: SchemaField;\n}\n\ninterface RefField extends BaseSchemaField {\n readonly type: typeof TypeKind.REF;\n readonly refType: \"record\" | \"union\";\n readonly name: string;\n}\n\ninterface StringField extends BaseSchemaField {\n readonly type: typeof TypeKind.STRING;\n}\n\ninterface UserRefField extends BaseSchemaField {\n readonly type: typeof TypeKind.USER_REF;\n}\n\ntype SchemaField =\n | AnyField\n | ArrayField\n | ResourceRefField\n | DocRefField\n | DoubleField\n | MediaRefField\n | ObjectRefField\n | OptionalField\n | RefField\n | StringField\n | UserRefField;\n\ninterface RuntimeSchemaRecord {\n readonly type: typeof SchemaDefKind.RECORD;\n readonly name: string;\n readonly docs?: string;\n readonly fields: Readonly<Record<string, SchemaField>>;\n readonly ref?: RefField & {\n readonly refType: \"record\";\n };\n}\n\ninterface RuntimeSchemaUnion {\n readonly type: typeof SchemaDefKind.UNION;\n readonly name?: string;\n readonly variants: Readonly<Record<string, SchemaField>>;\n readonly discriminant: string;\n readonly ref?: RefField & {\n readonly refType: \"union\";\n };\n}\n\ntype RuntimeSchemaItem = RuntimeSchemaRecord | RuntimeSchemaUnion;\ntype RuntimeSchema = Record<string, RuntimeSchemaItem>;\n\n// Type guards\nfunction isRecordSchema(item: RuntimeSchemaItem): item is RuntimeSchemaRecord {\n return item.type === SchemaDefKind.RECORD && \"name\" in item && \"fields\" in item;\n}\n\nfunction isUnionSchema(item: RuntimeSchemaItem): item is RuntimeSchemaUnion {\n return item.type === SchemaDefKind.UNION && \"variants\" in item && \"discriminant\" in item;\n}\n\nfunction isRefField(field: SchemaField): field is RefField {\n return field.type === TypeKind.REF && \"refType\" in field && \"name\" in field;\n}\n\nfunction isArrayField(field: SchemaField): field is ArrayField {\n return field.type === TypeKind.ARRAY && \"items\" in field;\n}\n\nfunction isOptionalField(field: SchemaField): field is OptionalField {\n return field.type === TypeKind.OPTIONAL && \"item\" in field;\n}\n\nfunction detectUsedRefTypes(schema: RuntimeSchema): Set<string> {\n const refTypes = new Set<string>();\n\n function scanField(field: SchemaField): void {\n switch (field.type) {\n case TypeKind.ARRAY:\n if (isArrayField(field)) {\n scanField(field.items);\n }\n break;\n case TypeKind.RESOURCE_REF:\n refTypes.add(\"ResourceRid\");\n break;\n case TypeKind.DOC_REF:\n refTypes.add(\"DocumentId\");\n break;\n case TypeKind.MEDIA_REF:\n refTypes.add(\"MediaId\");\n break;\n case TypeKind.OBJECT_REF:\n refTypes.add(\"ObjectId\");\n break;\n case TypeKind.OPTIONAL:\n if (isOptionalField(field)) {\n scanField(field.item);\n }\n break;\n case TypeKind.USER_REF:\n refTypes.add(\"UserId\");\n break;\n }\n }\n\n for (const item of Object.values(schema)) {\n if (isRecordSchema(item)) {\n for (const field of Object.values(item.fields)) {\n scanField(field);\n }\n } else if (isUnionSchema(item)) {\n for (const variant of Object.values(item.variants)) {\n scanField(variant);\n }\n }\n }\n\n return refTypes;\n}\n\nexport function generateTypesFromSchema<T extends ReturnedSchema>(\n schema: Schema<T>,\n): string {\n const runtimeSchema = schema as unknown as RuntimeSchema;\n\n // Detect which ref types are used in the schema\n const usedRefTypes = detectUsedRefTypes(runtimeSchema);\n\n let output = GENERATED_FILE_HEADER;\n\n // Add conditional imports based on which ref types are used\n if (usedRefTypes.size > 0) {\n const refTypesList = Array.from(usedRefTypes).sort().join(\", \");\n output +=\n `import type { ${refTypesList} } from \"@palantir/pack.document-schema.model-types\";\\n`;\n }\n\n output += \"\\n\";\n\n // First pass: generate record interfaces\n for (const [exportName, item] of Object.entries(runtimeSchema)) {\n if (item.type === SchemaDefKind.RECORD && isRecordSchema(item)) {\n output += generateRecordInterface(item, exportName, runtimeSchema);\n output += \"\\n\";\n }\n }\n\n // Second pass: generate union types\n const unionEntries = Object.entries(runtimeSchema).filter(\n ([_, item]) => item.type === SchemaDefKind.UNION && isUnionSchema(item),\n );\n\n unionEntries.forEach(([exportName, item], i) => {\n if (isUnionSchema(item)) {\n const unionOutput = generateUnionType(item, exportName, runtimeSchema);\n if (unionOutput) {\n output += unionOutput;\n // Only add newline if not the last union\n if (i < unionEntries.length - 1) {\n output += \"\\n\";\n }\n }\n }\n });\n\n return output;\n}\n\nfunction generateRecordInterface(\n record: RuntimeSchemaRecord,\n exportName: string,\n schema: RuntimeSchema,\n): string {\n let output = \"\";\n\n if (record.docs) {\n output += `/**\\n * ${record.docs}\\n */\\n`;\n }\n\n output += `export interface ${exportName} {\\n`;\n\n for (const [fieldName, fieldType] of Object.entries(record.fields)) {\n const tsType = convertTypeToTypeScript(fieldType, schema);\n const optional = fieldType.type === TypeKind.OPTIONAL ? \"?\" : \"\";\n output += ` readonly ${fieldName}${optional}: ${tsType};\\n`;\n }\n\n output += \"}\\n\";\n\n return output;\n}\n\nfunction generateUnionType(\n union: RuntimeSchemaUnion,\n exportName: string,\n schema: RuntimeSchema,\n): string {\n let output = \"\";\n const variantInterfaces: Array<{ name: string; discriminatorValue: string }> = [];\n const discriminantField = union.discriminant;\n\n // First pass: generate variant interfaces\n for (const [variantName, variantType] of Object.entries(union.variants)) {\n const interfaceName = `${exportName}${formatVariantName(variantName)}`;\n variantInterfaces.push({ name: interfaceName, discriminatorValue: variantName });\n\n if (variantType.type === TypeKind.REF && variantType.refType === \"record\") {\n // Find the corresponding record name in the schema\n const recordName = findRecordExportName(variantType.name, schema);\n if (recordName) {\n output += `export interface ${interfaceName} extends ${recordName} {\\n`;\n output += ` readonly ${discriminantField}: \"${variantName}\";\\n`;\n output += \"}\\n\\n\";\n }\n } else {\n // Handle value types\n const tsType = convertTypeToTypeScript(variantType, schema);\n output += `export interface ${interfaceName} {\\n`;\n output += ` readonly ${discriminantField}: \"${variantName}\";\\n`;\n output += ` readonly value: ${tsType};\\n`;\n output += \"}\\n\\n\";\n }\n }\n\n // Second pass: generate the union type\n output += `export type ${exportName} = ${variantInterfaces.map(v => v.name).join(\" | \")};\\n\\n`;\n\n // Third pass: generate type guards\n for (let i = 0; i < variantInterfaces.length; i++) {\n const variant = variantInterfaces[i]!;\n output +=\n `export function is${variant.name}(value: ${exportName}): value is ${variant.name} {\\n`;\n output += ` return value.${discriminantField} === \"${variant.discriminatorValue}\";\\n`;\n output += \"}\\n\\n\";\n }\n\n return output;\n}\n\nfunction findRecordExportName(\n recordName: string,\n schema: RuntimeSchema,\n): string | null {\n for (const [exportName, item] of Object.entries(schema)) {\n if (isRecordSchema(item) && item.name === recordName) {\n return exportName;\n }\n }\n return null;\n}\n\nfunction convertTypeToTypeScript(\n fieldType: SchemaField,\n schema?: RuntimeSchema,\n): string {\n switch (fieldType.type) {\n case TypeKind.ANY:\n return \"any\";\n case TypeKind.ARRAY:\n if (!isArrayField(fieldType)) {\n throw new Error(\"Array field is missing items type\");\n }\n return `readonly ${convertTypeToTypeScript(fieldType.items, schema)}[]`;\n case TypeKind.RESOURCE_REF:\n return \"ResourceRid\";\n case TypeKind.DOC_REF:\n return \"DocumentId\";\n case TypeKind.DOUBLE:\n return \"number\";\n case TypeKind.MEDIA_REF:\n return \"MediaId\";\n case TypeKind.OBJECT_REF:\n return \"ObjectId\";\n case TypeKind.OPTIONAL:\n if (!isOptionalField(fieldType)) {\n throw new Error(\"Optional field is missing inner type\");\n }\n return convertTypeToTypeScript(fieldType.item, schema);\n case TypeKind.REF:\n if (!isRefField(fieldType)) {\n throw new Error(\"Ref field is missing name or refType\");\n }\n if (fieldType.refType === \"record\") {\n const exportName = schema ? findRecordExportName(fieldType.name, schema) : null;\n return exportName ?? fieldType.name;\n }\n return fieldType.name;\n case TypeKind.STRING:\n return \"string\";\n case TypeKind.USER_REF:\n return \"UserId\";\n default: {\n const _exhaustive: never = fieldType;\n throw new Error(`Unknown schema field type: ${(_exhaustive as SchemaField).type}`);\n }\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,QAAQ,IAAIC,cAAc,QAAQ,uBAAuB;AAClE,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,qBAAqB,QAAQ,2BAA2B;AAEjE,MAAMH,QAAyD,GAAG;EAChE,GAAGC,cAAc;EACjBG,GAAG,EAAE;AACP,CAAC;AAED,MAAMC,aAAa,GAAG;EACpBC,MAAM,EAAE,QAAQ;EAChBC,KAAK,EAAE;AACT,CAAU;;AAEV;;AAyFA;AACA,SAASC,cAAcA,CAACC,IAAuB,EAA+B;EAC5E,OAAOA,IAAI,CAACC,IAAI,KAAKL,aAAa,CAACC,MAAM,IAAI,MAAM,IAAIG,IA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]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrayFields.js","names":[],"sources":["arrayFields.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"arrayFields.js","names":[],"sources":["arrayFields.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.25.0 */\n\n\nexport interface Container {\n readonly items: readonly string[];\n readonly numbers: readonly number[];\n}\n\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customDiscriminant.js","names":["isAnimalCat","value","kind","isAnimalDog"],"sources":["customDiscriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"customDiscriminant.js","names":["isAnimalCat","value","kind","isAnimalDog"],"sources":["customDiscriminant.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.25.0 */\n\n\n/**\n * A cat\n */\nexport interface Cat {\n readonly meow: string;\n readonly whiskers: number;\n}\n\n/**\n * A dog\n */\nexport interface Dog {\n readonly bark: string;\n readonly tailWags: number;\n}\n\nexport interface AnimalCat extends Cat {\n readonly kind: \"cat\";\n}\n\nexport interface AnimalDog extends Dog {\n readonly kind: \"dog\";\n}\n\nexport type Animal = AnimalCat | AnimalDog;\n\nexport function isAnimalCat(value: Animal): value is AnimalCat {\n return value.kind === \"cat\";\n}\n\nexport function isAnimalDog(value: Animal): value is AnimalDog {\n return value.kind === \"dog\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;;AAgBA,OAAO,SAASA,WAAWA,CAACC,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B;AAEA,OAAO,SAASC,WAAWA,CAACF,KAAa,EAAsB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,KAAK;AAC7B","ignoreList":[]}
|
package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypeScriptInterfaces.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["generateTypeScriptInterfaces.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"generateTypeScriptInterfaces.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["generateTypeScriptInterfaces.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.25.0 */\n\n\n/**\n * Represents an edge in a graph\n */\nexport interface Edge {\n readonly source: ObjectNode;\n readonly target: ObjectNode;\n}\n\nexport interface ObjectNode {\n readonly x: number;\n readonly y: number;\n readonly label?: string;\n readonly color?: string;\n}\n\n/**\n * Represents a text box in a graph\n */\nexport interface TextBox {\n readonly x: number;\n readonly y: number;\n readonly text: string;\n}\n\nexport interface NodeObject extends ObjectNode {\n readonly type: \"object\";\n}\n\nexport interface NodeTextBox extends TextBox {\n readonly type: \"text-box\";\n}\n\nexport type Node = NodeObject | NodeTextBox;\n\nexport function isNodeObject(value: Node): value is NodeObject {\n return value.type === \"object\";\n}\n\nexport function isNodeTextBox(value: Node): value is NodeTextBox {\n return value.type === \"text-box\";\n}\n\n"],"mappings":"AAAA;;AAGA;AACA;AACA;;AAaA;AACA;AACA;;AAiBA,OAAO,SAASA,YAAYA,CAACC,KAAW,EAAuB;EAC7D,OAAOA,KAAK,CAACC,IAAI,KAAK,QAAQ;AAChC;AAEA,OAAO,SAASC,aAAaA,CAACF,KAAW,EAAwB;EAC/D,OAAOA,KAAK,CAACC,IAAI,KAAK,UAAU;AAClC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"refTypes.js","names":[],"sources":["refTypes.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.25.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.
|
|
1
|
+
{"version":3,"file":"simpleRecord.js","names":[],"sources":["simpleRecord.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.25.0 */\n\n\n/**\n * A person record\n */\nexport interface Person {\n readonly name: string;\n readonly age: number;\n readonly email?: string;\n}\n\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simpleSteps.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["simpleSteps.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.
|
|
1
|
+
{"version":3,"file":"simpleSteps.js","names":["isNodeObject","value","type","isNodeTextBox"],"sources":["simpleSteps.ts"],"sourcesContent":["/* Generated by @palantir/pack.document-schema.type-gen@0.25.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":[]}
|
|
@@ -19,6 +19,9 @@ const refTypes = {
|
|
|
19
19
|
"mediaRef": {
|
|
20
20
|
"type": "mediaRef"
|
|
21
21
|
},
|
|
22
|
+
"resourceRef": {
|
|
23
|
+
"type": "resourceRef"
|
|
24
|
+
},
|
|
22
25
|
"optionalDocRef": {
|
|
23
26
|
"type": "optional",
|
|
24
27
|
"item": {
|
|
@@ -36,6 +39,18 @@ const refTypes = {
|
|
|
36
39
|
"items": {
|
|
37
40
|
"type": "userRef"
|
|
38
41
|
}
|
|
42
|
+
},
|
|
43
|
+
"optionalResourceRef": {
|
|
44
|
+
"type": "optional",
|
|
45
|
+
"item": {
|
|
46
|
+
"type": "resourceRef"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"resourceRefArray": {
|
|
50
|
+
"type": "array",
|
|
51
|
+
"items": {
|
|
52
|
+
"type": "resourceRef"
|
|
53
|
+
}
|
|
39
54
|
}
|
|
40
55
|
}
|
|
41
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refTypes.js","names":["refTypes"],"sources":["refTypes.ts"],"sourcesContent":["import { Schema } from \"@palantir/pack.schema\";\n\nconst refTypes = {\n \"Document\": {\n \"type\": \"record\",\n \"name\": \"Document\",\n \"docs\": \"A record containing all reference types\",\n \"fields\": {\n \"id\": {\n \"type\": \"string\",\n },\n \"docRef\": {\n \"type\": \"docRef\",\n },\n \"userRef\": {\n \"type\": \"userRef\",\n },\n \"objectRef\": {\n \"type\": \"objectRef\",\n },\n \"mediaRef\": {\n \"type\": \"mediaRef\",\n },\n \"optionalDocRef\": {\n \"type\": \"optional\",\n \"item\": {\n \"type\": \"docRef\",\n },\n },\n \"docRefArray\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"docRef\",\n },\n },\n \"userRefArray\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"userRef\",\n },\n },\n },\n },\n} satisfies Schema<any>;\n\nexport default refTypes;\n"],"mappings":"AAEA,MAAMA,QAAQ,GAAG;EACf,UAAU,EAAE;IACV,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,yCAAyC;IACjD,QAAQ,EAAE;MACR,IAAI,EAAE;QACJ,MAAM,EAAE;MACV,CAAC;MACD,QAAQ,EAAE;QACR,MAAM,EAAE;MACV,CAAC;MACD,SAAS,EAAE;QACT,MAAM,EAAE;MACV,CAAC;MACD,WAAW,EAAE;QACX,MAAM,EAAE;MACV,CAAC;MACD,UAAU,EAAE;QACV,MAAM,EAAE;MACV,CAAC;MACD,gBAAgB,EAAE;QAChB,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE;UACN,MAAM,EAAE;QACV;MACF,CAAC;MACD,aAAa,EAAE;QACb,MAAM,EAAE,OAAO;QACf,OAAO,EAAE;UACP,MAAM,EAAE;QACV;MACF,CAAC;MACD,cAAc,EAAE;QACd,MAAM,EAAE,OAAO;QACf,OAAO,EAAE;UACP,MAAM,EAAE;QACV;MACF;IACF;EACF;AACF,CAAuB;AAEvB,eAAeA,QAAQ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"refTypes.js","names":["refTypes"],"sources":["refTypes.ts"],"sourcesContent":["import { Schema } from \"@palantir/pack.schema\";\n\nconst refTypes = {\n \"Document\": {\n \"type\": \"record\",\n \"name\": \"Document\",\n \"docs\": \"A record containing all reference types\",\n \"fields\": {\n \"id\": {\n \"type\": \"string\",\n },\n \"docRef\": {\n \"type\": \"docRef\",\n },\n \"userRef\": {\n \"type\": \"userRef\",\n },\n \"objectRef\": {\n \"type\": \"objectRef\",\n },\n \"mediaRef\": {\n \"type\": \"mediaRef\",\n },\n \"resourceRef\": {\n \"type\": \"resourceRef\",\n },\n \"optionalDocRef\": {\n \"type\": \"optional\",\n \"item\": {\n \"type\": \"docRef\",\n },\n },\n \"docRefArray\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"docRef\",\n },\n },\n \"userRefArray\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"userRef\",\n },\n },\n \"optionalResourceRef\": {\n \"type\": \"optional\",\n \"item\": {\n \"type\": \"resourceRef\",\n },\n },\n \"resourceRefArray\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"resourceRef\",\n },\n },\n },\n },\n} satisfies Schema<any>;\n\nexport default refTypes;\n"],"mappings":"AAEA,MAAMA,QAAQ,GAAG;EACf,UAAU,EAAE;IACV,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,UAAU;IAClB,MAAM,EAAE,yCAAyC;IACjD,QAAQ,EAAE;MACR,IAAI,EAAE;QACJ,MAAM,EAAE;MACV,CAAC;MACD,QAAQ,EAAE;QACR,MAAM,EAAE;MACV,CAAC;MACD,SAAS,EAAE;QACT,MAAM,EAAE;MACV,CAAC;MACD,WAAW,EAAE;QACX,MAAM,EAAE;MACV,CAAC;MACD,UAAU,EAAE;QACV,MAAM,EAAE;MACV,CAAC;MACD,aAAa,EAAE;QACb,MAAM,EAAE;MACV,CAAC;MACD,gBAAgB,EAAE;QAChB,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE;UACN,MAAM,EAAE;QACV;MACF,CAAC;MACD,aAAa,EAAE;QACb,MAAM,EAAE,OAAO;QACf,OAAO,EAAE;UACP,MAAM,EAAE;QACV;MACF,CAAC;MACD,cAAc,EAAE;QACd,MAAM,EAAE,OAAO;QACf,OAAO,EAAE;UACP,MAAM,EAAE;QACV;MACF,CAAC;MACD,qBAAqB,EAAE;QACrB,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE;UACN,MAAM,EAAE;QACV;MACF,CAAC;MACD,kBAAkB,EAAE;QAClB,MAAM,EAAE,OAAO;QACf,OAAO,EAAE;UACP,MAAM,EAAE;QACV;MACF;IACF;EACF;AACF,CAAuB;AAEvB,eAAeA,QAAQ","ignoreList":[]}
|
|
@@ -154,6 +154,7 @@ export function convertTypeToFieldTypeUnion(schemaType, nameToExportKey) {
|
|
|
154
154
|
case "optional":
|
|
155
155
|
// Optional flag is handled at field level; unwrap and recurse on inner type
|
|
156
156
|
return convertTypeToFieldTypeUnion(schemaType.item, nameToExportKey);
|
|
157
|
+
case "resourceRef":
|
|
157
158
|
case "boolean":
|
|
158
159
|
case "docRef":
|
|
159
160
|
case "double":
|
|
@@ -172,6 +173,10 @@ function convertTypeToFieldValueUnion(schemaType, nameToExportKey) {
|
|
|
172
173
|
switch (schemaType.type) {
|
|
173
174
|
case "array":
|
|
174
175
|
throw new Error("Nested arrays are not supported in the IR. " + "Wrap the inner array in a record instead.");
|
|
176
|
+
case "resourceRef":
|
|
177
|
+
return IFieldValueUnion.resourceRef({
|
|
178
|
+
resourceRids: []
|
|
179
|
+
});
|
|
175
180
|
case "boolean":
|
|
176
181
|
return IFieldValueUnion.boolean({});
|
|
177
182
|
case "docRef":
|
|
@@ -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","deprecations","fields","fieldKey","fieldType","dep","key","undefined","convertTypeToFieldTypeUnion","addedInVersion","deprecatedFromVersion","fromVersion","message","deprecatedMessage","isOptional","docs","unionDef","variantEntries","variants","variantName","modelRef","unionAddedIn","modelVersions","discriminant","schemaType","items","allowNullValue","elementType","item","array","value","convertTypeToFieldValueUnion","Error","boolean","docRef","documentTypeRids","double","mediaRef","object","interfaceTypeRids","objectTypeRids","modelTypes","string","unmanagedJson","userRef"],"sources":["convertStepsToIr.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type * as P from \"@palantir/pack.schema\";\nimport invariant from \"tiny-invariant\";\nimport type {\n IModelTypeKey,\n IUnionVariantKey,\n} from \"../../lib/pack-docschema-api/pack-docschema-api\";\nimport type {\n IFieldDef,\n IRealTimeDocumentSchema,\n IRecordDef,\n IUnionDef,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport {\n IFieldTypeUnion,\n IFieldValueUnion,\n IModelDef,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { assertNever } from \"../assertNever.js\";\nimport { convertStepsToSchema } from \"./convertStepsToSchema.js\";\nimport type { MigrationStep } from \"./parseMigrationSteps.js\";\n\nexport interface SchemaMetadata {\n readonly name?: string;\n readonly description?: string;\n readonly version?: number;\n}\n\n/**\n * Per-field version provenance for a schema, keyed by model export key then\n * field name. Supplied by the version-aware caller (`resolveSchemaChain`) so the\n * IR records the version each field first appeared in (and any deprecation)\n * instead of a placeholder. When omitted, fields fall back to the schema's\n * top-level version (correct for single-version / steps-based callers).\n */\nexport interface SchemaProvenance {\n readonly fieldVersions?: Record<string, Record<string, number>>;\n readonly modelVersions?: Record<string, number>;\n readonly deprecations?: P.VersionDeprecations;\n}\n\n/**\n * Converts migration steps to Palantir IR format\n */\nexport function convertStepsToIr(\n steps: readonly MigrationStep[],\n metadata?: SchemaMetadata,\n): IRealTimeDocumentSchema {\n // First convert steps to document-schema-api format\n const { recordDefinitions, unionDefinitions } = convertStepsToSchema(steps as MigrationStep[]);\n\n const schema = {\n ...Object.fromEntries(recordDefinitions.map(def => [def.name, def])),\n ...Object.fromEntries(unionDefinitions.map(def => [def.name, def])),\n };\n\n return convertSchemaToIr(schema, metadata);\n}\n\n/**\n * Converts record and union definitions to Palantir IR format. When\n * `provenance` is supplied (by the version-aware caller), each field/model is\n * stamped with the version it first appeared in and any deprecation; otherwise\n * everything falls back to `metadata.version` (default 1).\n */\nexport function convertSchemaToIr(\n inputSchema: P.Schema<P.ReturnedSchema>,\n metadata?: SchemaMetadata,\n provenance?: SchemaProvenance,\n): IRealTimeDocumentSchema {\n // Build a mapping from declared model name → export key so that union variant\n // refs (which use declared model names) can be remapped to export keys.\n const nameToExportKey = new Map<string, string>();\n for (const [exportKey, modelDef] of Object.entries(inputSchema)) {\n const existing = nameToExportKey.get(modelDef.name);\n invariant(\n existing == null,\n `Duplicate declared model name \"${modelDef.name}\": exported as both \"${existing}\" and \"${exportKey}\"`,\n );\n nameToExportKey.set(modelDef.name, exportKey);\n }\n const fallbackVersion = metadata?.version ?? 1;\n\n const primaryModelKeys: IModelTypeKey[] = [];\n const models = new Map<IModelTypeKey, IModelDef>();\n\n for (const [exportKey, modelDef] of Object.entries(inputSchema)) {\n if (collectModels(exportKey, modelDef, nameToExportKey, models, fallbackVersion, provenance)) {\n primaryModelKeys.push(exportKey);\n }\n }\n\n return {\n name: metadata?.name ?? \"Generated Schema\",\n description: metadata?.description ?? \"Schema generated from migration steps\",\n version: fallbackVersion,\n primaryModelKeys,\n models: Object.fromEntries(models),\n };\n}\n\nfunction collectModels(\n exportKey: string,\n modelDef: P.ModelDef,\n nameToExportKey: Map<string, string>,\n outModels: Map<IModelTypeKey, IModelDef>,\n fallbackVersion: number,\n provenance?: SchemaProvenance,\n): boolean {\n invariant(\n !outModels.has(exportKey),\n `Duplicate model definition: ${exportKey}`,\n );\n\n switch (modelDef.type) {\n case \"record\": {\n outModels.set(\n exportKey,\n IModelDef.record(\n convertRecordDefToIr(modelDef, exportKey, nameToExportKey, fallbackVersion, provenance),\n ),\n );\n return true;\n }\n case \"union\": {\n outModels.set(\n exportKey,\n IModelDef.union(\n convertUnionDefToIr(modelDef, exportKey, nameToExportKey, fallbackVersion, provenance),\n ),\n );\n return true;\n }\n default:\n assertNever(modelDef);\n }\n}\n\nexport function convertRecordDefToIr(\n recordDef: P.RecordDef,\n exportKey?: string,\n nameToExportKey?: Map<string, string>,\n fallbackVersion: number = 1,\n provenance?: SchemaProvenance,\n): IRecordDef {\n const modelKey = exportKey ?? recordDef.name;\n const fieldVersions = provenance?.fieldVersions?.[modelKey];\n const deprecations = provenance?.deprecations?.[modelKey];\n const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]): IFieldDef => {\n const dep = deprecations?.[fieldKey];\n return {\n key: fieldKey,\n name: fieldKey,\n description: undefined,\n fieldType: convertTypeToFieldTypeUnion(fieldType, nameToExportKey),\n metadata: {\n addedInVersion: fieldVersions?.[fieldKey] ?? fallbackVersion,\n ...(dep != null\n ? {\n deprecatedFromVersion: dep.fromVersion,\n ...(dep.message != null ? { deprecatedMessage: dep.message } : {}),\n }\n : {}),\n },\n isOptional: fieldType.type === \"optional\" ? true : undefined,\n };\n });\n\n return {\n key: modelKey,\n name: recordDef.name,\n description: recordDef.docs ?? undefined,\n fields,\n };\n}\n\nexport function convertUnionDefToIr(\n unionDef: P.UnionDef,\n exportKey?: string,\n nameToExportKey?: Map<string, string>,\n fallbackVersion: number = 1,\n provenance?: SchemaProvenance,\n): IUnionDef {\n const modelKey = exportKey ?? unionDef.name;\n const variantEntries = Object.entries(unionDef.variants).map((\n [variantName, modelRef],\n ) =>\n [\n variantName as IUnionVariantKey,\n (nameToExportKey?.get(modelRef.name) ?? modelRef.name) as IModelTypeKey,\n ] as const\n );\n\n const unionAddedIn = provenance?.modelVersions?.[modelKey] ?? fallbackVersion;\n\n return {\n key: modelKey,\n name: unionDef.name,\n description: unionDef.docs,\n discriminant: unionDef.discriminant,\n variants: Object.fromEntries(variantEntries),\n metadata: { addedInVersion: unionAddedIn },\n };\n}\n\n// TODO: rename to convertSchemaTypeToFieldTypeUnion\nexport function convertTypeToFieldTypeUnion(\n schemaType: P.Type,\n nameToExportKey?: Map<string, string>,\n): IFieldTypeUnion {\n switch (schemaType.type) {\n case \"array\": {\n // P.Array.items is typed as TypeBase due to the generic; narrow via type field\n const items = schemaType.items as P.Type;\n const allowNullValue = items.type === \"optional\";\n const elementType: P.Type = allowNullValue ? (items as P.Optional).item as P.Type : items;\n return IFieldTypeUnion.array({\n allowNullValue,\n value: convertTypeToFieldValueUnion(elementType, nameToExportKey),\n });\n }\n\n case \"optional\":\n // Optional flag is handled at field level; unwrap and recurse on inner type\n return convertTypeToFieldTypeUnion(schemaType.item as P.Type, nameToExportKey);\n\n case \"boolean\":\n case \"docRef\":\n case \"double\":\n case \"mediaRef\":\n case \"objectRef\":\n case \"ref\":\n case \"string\":\n case \"unknown\":\n case \"userRef\":\n return IFieldTypeUnion.value(convertTypeToFieldValueUnion(schemaType, nameToExportKey));\n\n default:\n assertNever(schemaType);\n }\n}\n\nfunction convertTypeToFieldValueUnion(\n schemaType: P.Type,\n nameToExportKey?: Map<string, string>,\n): IFieldValueUnion {\n switch (schemaType.type) {\n case \"array\":\n throw new Error(\n \"Nested arrays are not supported in the IR. \"\n + \"Wrap the inner array in a record instead.\",\n );\n\n case \"boolean\":\n return IFieldValueUnion.boolean({});\n\n case \"docRef\":\n return IFieldValueUnion.docRef({\n documentTypeRids: [], // FIXME: confirm whether we will use rids in the deployed schema.\n });\n\n case \"double\":\n return IFieldValueUnion.double({});\n\n case \"mediaRef\":\n return IFieldValueUnion.mediaRef({});\n\n case \"objectRef\":\n return IFieldValueUnion.object({\n // FIXME: confirm whether we will use rids in the deployed schema.\n interfaceTypeRids: [],\n objectTypeRids: [],\n });\n\n case \"optional\":\n // Nested optional — unwrap and continue\n // TODO: probably warn? maybe throw\n return convertTypeToFieldValueUnion(schemaType.item as P.Type, nameToExportKey);\n\n case \"ref\": {\n const modelKey = nameToExportKey?.get(schemaType.name) ?? schemaType.name;\n return IFieldValueUnion.modelRef({ modelTypes: [modelKey as IModelTypeKey] });\n }\n\n case \"string\":\n return IFieldValueUnion.string({});\n\n case \"unknown\":\n return IFieldValueUnion.unmanagedJson({});\n\n case \"userRef\":\n return IFieldValueUnion.userRef({});\n\n default:\n assertNever(schemaType);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,SAAS,MAAM,gBAAgB;AAWtC,SACEC,eAAe,EACfC,gBAAgB,EAChBC,SAAS,QACJ,yDAAyD;AAChE,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,oBAAoB,QAAQ,2BAA2B;;AAShE;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA;AACA;AACA;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,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,IA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C,CAAC;MAC/E;IAEA,KAAK,QAAQ;MACX,OAAO5C,gBAAgB,CAACuF,MAAM,CAAC,CAAC,CAAC,CAAC;IAEpC,KAAK,SAAS;MACZ,OAAOvF,gBAAgB,CAACwF,aAAa,CAAC,CAAC,CAAC,CAAC;IAE3C,KAAK,SAAS;MACZ,OAAOxF,gBAAgB,CAACyF,OAAO,CAAC,CAAC,CAAC,CAAC;IAErC;MACEvF,WAAW,CAACmE,UAAU,CAAC;EAC3B;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"convertStepsToIr.js","names":["invariant","IFieldTypeUnion","IFieldValueUnion","IModelDef","assertNever","convertStepsToSchema","convertStepsToIr","steps","metadata","recordDefinitions","unionDefinitions","schema","Object","fromEntries","map","def","name","convertSchemaToIr","inputSchema","provenance","nameToExportKey","Map","exportKey","modelDef","entries","existing","get","process","env","NODE_ENV","set","fallbackVersion","version","primaryModelKeys","models","collectModels","push","description","outModels","has","type","record","convertRecordDefToIr","union","convertUnionDefToIr","recordDef","modelKey","fieldVersions","deprecations","fields","fieldKey","fieldType","dep","key","undefined","convertTypeToFieldTypeUnion","addedInVersion","deprecatedFromVersion","fromVersion","message","deprecatedMessage","isOptional","docs","unionDef","variantEntries","variants","variantName","modelRef","unionAddedIn","modelVersions","discriminant","schemaType","items","allowNullValue","elementType","item","array","value","convertTypeToFieldValueUnion","Error","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 deprecations?: P.VersionDeprecations;\n}\n\n/**\n * Converts migration steps to Palantir IR format\n */\nexport function convertStepsToIr(\n steps: readonly MigrationStep[],\n metadata?: SchemaMetadata,\n): IRealTimeDocumentSchema {\n // First convert steps to document-schema-api format\n const { recordDefinitions, unionDefinitions } = convertStepsToSchema(steps as MigrationStep[]);\n\n const schema = {\n ...Object.fromEntries(recordDefinitions.map(def => [def.name, def])),\n ...Object.fromEntries(unionDefinitions.map(def => [def.name, def])),\n };\n\n return convertSchemaToIr(schema, metadata);\n}\n\n/**\n * Converts record and union definitions to Palantir IR format. When\n * `provenance` is supplied (by the version-aware caller), each field/model is\n * stamped with the version it first appeared in and any deprecation; otherwise\n * everything falls back to `metadata.version` (default 1).\n */\nexport function convertSchemaToIr(\n inputSchema: P.Schema<P.ReturnedSchema>,\n metadata?: SchemaMetadata,\n provenance?: SchemaProvenance,\n): IRealTimeDocumentSchema {\n // Build a mapping from declared model name → export key so that union variant\n // refs (which use declared model names) can be remapped to export keys.\n const nameToExportKey = new Map<string, string>();\n for (const [exportKey, modelDef] of Object.entries(inputSchema)) {\n const existing = nameToExportKey.get(modelDef.name);\n invariant(\n existing == null,\n `Duplicate declared model name \"${modelDef.name}\": exported as both \"${existing}\" and \"${exportKey}\"`,\n );\n nameToExportKey.set(modelDef.name, exportKey);\n }\n const fallbackVersion = metadata?.version ?? 1;\n\n const primaryModelKeys: IModelTypeKey[] = [];\n const models = new Map<IModelTypeKey, IModelDef>();\n\n for (const [exportKey, modelDef] of Object.entries(inputSchema)) {\n if (collectModels(exportKey, modelDef, nameToExportKey, models, fallbackVersion, provenance)) {\n primaryModelKeys.push(exportKey);\n }\n }\n\n return {\n name: metadata?.name ?? \"Generated Schema\",\n description: metadata?.description ?? \"Schema generated from migration steps\",\n version: fallbackVersion,\n primaryModelKeys,\n models: Object.fromEntries(models),\n };\n}\n\nfunction collectModels(\n exportKey: string,\n modelDef: P.ModelDef,\n nameToExportKey: Map<string, string>,\n outModels: Map<IModelTypeKey, IModelDef>,\n fallbackVersion: number,\n provenance?: SchemaProvenance,\n): boolean {\n invariant(\n !outModels.has(exportKey),\n `Duplicate model definition: ${exportKey}`,\n );\n\n switch (modelDef.type) {\n case \"record\": {\n outModels.set(\n exportKey,\n IModelDef.record(\n convertRecordDefToIr(modelDef, exportKey, nameToExportKey, fallbackVersion, provenance),\n ),\n );\n return true;\n }\n case \"union\": {\n outModels.set(\n exportKey,\n IModelDef.union(\n convertUnionDefToIr(modelDef, exportKey, nameToExportKey, fallbackVersion, provenance),\n ),\n );\n return true;\n }\n default:\n assertNever(modelDef);\n }\n}\n\nexport function convertRecordDefToIr(\n recordDef: P.RecordDef,\n exportKey?: string,\n nameToExportKey?: Map<string, string>,\n fallbackVersion: number = 1,\n provenance?: SchemaProvenance,\n): IRecordDef {\n const modelKey = exportKey ?? recordDef.name;\n const fieldVersions = provenance?.fieldVersions?.[modelKey];\n const deprecations = provenance?.deprecations?.[modelKey];\n const fields = Object.entries(recordDef.fields).map(([fieldKey, fieldType]): IFieldDef => {\n const dep = deprecations?.[fieldKey];\n return {\n key: fieldKey,\n name: fieldKey,\n description: undefined,\n fieldType: convertTypeToFieldTypeUnion(fieldType, nameToExportKey),\n metadata: {\n addedInVersion: fieldVersions?.[fieldKey] ?? fallbackVersion,\n ...(dep != null\n ? {\n deprecatedFromVersion: dep.fromVersion,\n ...(dep.message != null ? { deprecatedMessage: dep.message } : {}),\n }\n : {}),\n },\n isOptional: fieldType.type === \"optional\" ? true : undefined,\n };\n });\n\n return {\n key: modelKey,\n name: recordDef.name,\n description: recordDef.docs ?? undefined,\n fields,\n };\n}\n\nexport function convertUnionDefToIr(\n unionDef: P.UnionDef,\n exportKey?: string,\n nameToExportKey?: Map<string, string>,\n fallbackVersion: number = 1,\n provenance?: SchemaProvenance,\n): IUnionDef {\n const modelKey = exportKey ?? unionDef.name;\n const variantEntries = Object.entries(unionDef.variants).map((\n [variantName, modelRef],\n ) =>\n [\n variantName as IUnionVariantKey,\n (nameToExportKey?.get(modelRef.name) ?? modelRef.name) as IModelTypeKey,\n ] as const\n );\n\n const unionAddedIn = provenance?.modelVersions?.[modelKey] ?? fallbackVersion;\n\n return {\n key: modelKey,\n name: unionDef.name,\n description: unionDef.docs,\n discriminant: unionDef.discriminant,\n variants: Object.fromEntries(variantEntries),\n metadata: { addedInVersion: unionAddedIn },\n };\n}\n\n// TODO: rename to convertSchemaTypeToFieldTypeUnion\nexport function convertTypeToFieldTypeUnion(\n schemaType: P.Type,\n nameToExportKey?: Map<string, string>,\n): IFieldTypeUnion {\n switch (schemaType.type) {\n case \"array\": {\n // P.Array.items is typed as TypeBase due to the generic; narrow via type field\n const items = schemaType.items as P.Type;\n const allowNullValue = items.type === \"optional\";\n const elementType: P.Type = allowNullValue ? (items as P.Optional).item as P.Type : items;\n return IFieldTypeUnion.array({\n allowNullValue,\n value: convertTypeToFieldValueUnion(elementType, nameToExportKey),\n });\n }\n\n case \"optional\":\n // Optional flag is handled at field level; unwrap and recurse on inner type\n return convertTypeToFieldTypeUnion(schemaType.item as P.Type, nameToExportKey);\n\n case \"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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AOhF,gBAAgB,CAACiF,MAAM,CAAC;QAC7BC,gBAAgB,EAAE,EAAE,CAAE;MACxB,CAAC,CAAC;IAEJ,KAAK,QAAQ;MACX,OAAOlF,gBAAgB,CAACmF,MAAM,CAAC,CAAC,CAAC,CAAC;IAEpC,KAAK,UAAU;MACb,OAAOnF,gBAAgB,CAACoF,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEtC,KAAK,WAAW;MACd,OAAOpF,gBAAgB,CAACqF,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,EAAYvD,eAAe,CAAC;IAEjF,KAAK,KAAK;MAAE;QACV,MAAM0B,QAAQ,GAAG1B,eAAe,EAAEM,GAAG,CAAC6C,UAAU,CAACvD,IAAI,CAAC,IAAIuD,UAAU,CAACvD,IAAI;QACzE,OAAOd,gBAAgB,CAACiE,QAAQ,CAAC;UAAEuB,UAAU,EAAE,CAAC5C,QAAQ;QAAmB,CAAC,CAAC;MAC/E;IAEA,KAAK,QAAQ;MACX,OAAO5C,gBAAgB,CAACyF,MAAM,CAAC,CAAC,CAAC,CAAC;IAEpC,KAAK,SAAS;MACZ,OAAOzF,gBAAgB,CAAC0F,aAAa,CAAC,CAAC,CAAC,CAAC;IAE3C,KAAK,SAAS;MACZ,OAAO1F,gBAAgB,CAAC2F,OAAO,CAAC,CAAC,CAAC,CAAC;IAErC;MACEzF,WAAW,CAACmE,UAAU,CAAC;EAC3B;AACF","ignoreList":[]}
|
|
@@ -89,6 +89,11 @@ export function convertStepsToSchema(steps) {
|
|
|
89
89
|
function recordFieldDefinitionToSchemaType(recordFieldDefinition) {
|
|
90
90
|
if (typeof recordFieldDefinition === "string") {
|
|
91
91
|
// Basic types
|
|
92
|
+
if (recordFieldDefinition === "resourceRef") {
|
|
93
|
+
return {
|
|
94
|
+
type: "resourceRef"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
92
97
|
if (recordFieldDefinition === "docRef") {
|
|
93
98
|
return {
|
|
94
99
|
type: "docRef"
|