@palantir/pack.document-schema.type-gen 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/esm/commands/schema/registerSchemaCommands.js +2 -0
- package/build/esm/commands/schema/registerSchemaCommands.js.map +1 -1
- package/build/esm/commands/schema/schemaGenTypesHandler.js +147 -0
- package/build/esm/commands/schema/schemaGenTypesHandler.js.map +1 -0
- package/build/esm/index.js +6 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/lib/pack-docschema-api/pack-docschema-ir/recordDef.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/custom-discriminant.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/external-refs.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/simple-record.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateModelsFromIr/union-types.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/array-and-map-types.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/boolean-fields.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/custom-discriminant.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/datetime-fields.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/simple-records.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-before-records.js.map +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js +1 -1
- package/build/esm/utils/ir/__tests__/__snapshots__/generateZodSchemasFromIr/union-types.js.map +1 -1
- package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js +4 -16
- package/build/esm/utils/ir/__tests__/convertIrToWireSchema.test.js.map +1 -1
- package/build/esm/utils/ir/__tests__/generateModelsFromIr.test.js +6 -24
- package/build/esm/utils/ir/__tests__/generateModelsFromIr.test.js.map +1 -1
- package/build/esm/utils/ir/__tests__/generateZodSchemasFromIr.test.js +10 -40
- package/build/esm/utils/ir/__tests__/generateZodSchemasFromIr.test.js.map +1 -1
- package/build/esm/utils/ir/convertIrToWireSchema.js +4 -2
- package/build/esm/utils/ir/convertIrToWireSchema.js.map +1 -1
- package/build/esm/utils/ir/generateZodSchemasFromIr.js +1 -1
- package/build/esm/utils/ir/generateZodSchemasFromIr.js.map +1 -1
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/single-version.js +2 -0
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/single-version.js.map +1 -0
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/three-version-chain.js +2 -0
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/three-version-chain.js.map +1 -0
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js +2 -0
- package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js.map +1 -0
- package/build/esm/utils/schema/__tests__/fixtures.js +207 -0
- package/build/esm/utils/schema/__tests__/fixtures.js.map +1 -0
- package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js +41 -0
- package/build/esm/utils/schema/__tests__/generateInternalFromSchema.test.js.map +1 -0
- package/build/esm/utils/schema/__tests__/generateModelMetadataFromSchema.test.js +41 -0
- package/build/esm/utils/schema/__tests__/generateModelMetadataFromSchema.test.js.map +1 -0
- package/build/esm/utils/schema/__tests__/generateScopeFromSchema.test.js +37 -0
- package/build/esm/utils/schema/__tests__/generateScopeFromSchema.test.js.map +1 -0
- package/build/esm/utils/schema/__tests__/generateVersionedTypesFromSchema.test.js +55 -0
- package/build/esm/utils/schema/__tests__/generateVersionedTypesFromSchema.test.js.map +1 -0
- package/build/esm/utils/schema/__tests__/generateVersionedZodFromSchema.test.js +55 -0
- package/build/esm/utils/schema/__tests__/generateVersionedZodFromSchema.test.js.map +1 -0
- package/build/esm/utils/schema/__tests__/generateVersionsFromSchema.test.js +37 -0
- package/build/esm/utils/schema/__tests__/generateVersionsFromSchema.test.js.map +1 -0
- package/build/esm/utils/schema/__tests__/snapshotUtils.js +106 -0
- package/build/esm/utils/schema/__tests__/snapshotUtils.js.map +1 -0
- package/build/esm/utils/schema/generateIndexFromSchema.js +72 -0
- package/build/esm/utils/schema/generateIndexFromSchema.js.map +1 -0
- package/build/esm/utils/schema/generateInternalFromSchema.js +380 -0
- package/build/esm/utils/schema/generateInternalFromSchema.js.map +1 -0
- package/build/esm/utils/schema/generateModelMetadataFromSchema.js +195 -0
- package/build/esm/utils/schema/generateModelMetadataFromSchema.js.map +1 -0
- package/build/esm/utils/schema/generateScopeFromSchema.js +155 -0
- package/build/esm/utils/schema/generateScopeFromSchema.js.map +1 -0
- package/build/esm/utils/schema/generateTypesFromSchema.js +16 -30
- package/build/esm/utils/schema/generateTypesFromSchema.js.map +1 -1
- package/build/esm/utils/schema/generateVersionedTypesFromSchema.js +281 -0
- package/build/esm/utils/schema/generateVersionedTypesFromSchema.js.map +1 -0
- package/build/esm/utils/schema/generateVersionedZodFromSchema.js +189 -0
- package/build/esm/utils/schema/generateVersionedZodFromSchema.js.map +1 -0
- package/build/esm/utils/schema/generateVersionsFromSchema.js +50 -0
- package/build/esm/utils/schema/generateVersionsFromSchema.js.map +1 -0
- package/build/esm/utils/schema/resolveSchemaChain.js +54 -0
- package/build/esm/utils/schema/resolveSchemaChain.js.map +1 -0
- package/build/esm/utils/schema/runtimeSchema.js +96 -0
- package/build/esm/utils/schema/runtimeSchema.js.map +1 -0
- package/build/esm/utils/steps/__tests__/__snapshots__/types/arrayFields.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/customDiscriminant.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/generateTypeScriptInterfaces.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/refTypes.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleRecord.js.map +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js +1 -1
- package/build/esm/utils/steps/__tests__/__snapshots__/types/simpleSteps.js.map +1 -1
- package/build/esm/utils/steps/convertStepsToIr.js +2 -5
- package/build/esm/utils/steps/convertStepsToIr.js.map +1 -1
- package/build/types/commands/schema/registerSchemaCommands.d.ts.map +1 -1
- package/build/types/commands/schema/schemaGenTypesHandler.d.ts +8 -0
- package/build/types/commands/schema/schemaGenTypesHandler.d.ts.map +1 -0
- package/build/types/index.d.ts +6 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/lib/pack-docschema-api/pack-docschema-ir/recordDef.d.ts +0 -2
- package/build/types/lib/pack-docschema-api/pack-docschema-ir/recordDef.d.ts.map +1 -1
- package/build/types/utils/schema/__tests__/fixtures.d.ts +14 -0
- package/build/types/utils/schema/__tests__/fixtures.d.ts.map +1 -0
- package/build/types/utils/schema/__tests__/generateInternalFromSchema.test.d.ts +2 -0
- package/build/types/utils/schema/__tests__/generateInternalFromSchema.test.d.ts.map +1 -0
- package/build/types/utils/schema/__tests__/generateModelMetadataFromSchema.test.d.ts +2 -0
- package/build/types/utils/schema/__tests__/generateModelMetadataFromSchema.test.d.ts.map +1 -0
- package/build/types/utils/schema/__tests__/generateScopeFromSchema.test.d.ts +2 -0
- package/build/types/utils/schema/__tests__/generateScopeFromSchema.test.d.ts.map +1 -0
- package/build/types/utils/schema/__tests__/generateVersionedTypesFromSchema.test.d.ts +2 -0
- package/build/types/utils/schema/__tests__/generateVersionedTypesFromSchema.test.d.ts.map +1 -0
- package/build/types/utils/schema/__tests__/generateVersionedZodFromSchema.test.d.ts +2 -0
- package/build/types/utils/schema/__tests__/generateVersionedZodFromSchema.test.d.ts.map +1 -0
- package/build/types/utils/schema/__tests__/generateVersionsFromSchema.test.d.ts +2 -0
- package/build/types/utils/schema/__tests__/generateVersionsFromSchema.test.d.ts.map +1 -0
- package/build/types/utils/schema/__tests__/snapshotUtils.d.ts +47 -0
- package/build/types/utils/schema/__tests__/snapshotUtils.d.ts.map +1 -0
- package/build/types/utils/schema/generateIndexFromSchema.d.ts +14 -0
- package/build/types/utils/schema/generateIndexFromSchema.d.ts.map +1 -0
- package/build/types/utils/schema/generateInternalFromSchema.d.ts +18 -0
- package/build/types/utils/schema/generateInternalFromSchema.d.ts.map +1 -0
- package/build/types/utils/schema/generateModelMetadataFromSchema.d.ts +15 -0
- package/build/types/utils/schema/generateModelMetadataFromSchema.d.ts.map +1 -0
- package/build/types/utils/schema/generateScopeFromSchema.d.ts +13 -0
- package/build/types/utils/schema/generateScopeFromSchema.d.ts.map +1 -0
- package/build/types/utils/schema/generateTypesFromSchema.d.ts.map +1 -1
- package/build/types/utils/schema/generateVersionedTypesFromSchema.d.ts +18 -0
- package/build/types/utils/schema/generateVersionedTypesFromSchema.d.ts.map +1 -0
- package/build/types/utils/schema/generateVersionedZodFromSchema.d.ts +16 -0
- package/build/types/utils/schema/generateVersionedZodFromSchema.d.ts.map +1 -0
- package/build/types/utils/schema/generateVersionsFromSchema.d.ts +13 -0
- package/build/types/utils/schema/generateVersionsFromSchema.d.ts.map +1 -0
- package/build/types/utils/schema/resolveSchemaChain.d.ts +18 -0
- package/build/types/utils/schema/resolveSchemaChain.d.ts.map +1 -0
- package/build/types/utils/schema/runtimeSchema.d.ts +59 -0
- package/build/types/utils/schema/runtimeSchema.d.ts.map +1 -0
- package/build/types/utils/steps/convertStepsToIr.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertIrToWireSchema.js","names":["convertIrToWireSchema","ir","wireModels","key","model","Object","entries","models","convertModelDef","primaryModelKeys","type","record","name","description","orUndefined","fields","map","convertFieldDef","metadata","convertSchemaMeta","union","discriminant","variants","Error","field","isOptional","fieldType","convertFieldTypeUnion","allowNullValue","array","value","convertFieldValueType","set","valueType","convertFieldValueUnion","defaultValue","boolean","datetime","documentTypeRids","docRef","rejectNaN","double","minValue","maxValue","integer","mediaRef","modelTypes","modelRef","interfaceTypeRids","object","objectTypeRids","string","minLength","maxLength","text","meta","addedInVersion","deprecatedFromVersion","deprecatedMessage","undefined"],"sources":["convertIrToWireSchema.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 {\n DocumentTypeSchema,\n FieldDef,\n FieldTypeUnion,\n FieldValueType,\n FieldValueUnion,\n ModelDef,\n SchemaMetadata,\n} from \"@osdk/foundry.pack\";\nimport type {\n IFieldDef,\n IFieldTypeUnion,\n IFieldValueUnion,\n IModelDef,\n IRealTimeDocumentSchema,\n ISchemaMeta,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\n\n/**\n * Converts the internal IR schema to the wire format expected by the Foundry API.\n *\n * The IR uses conjure-style tagged unions where the payload is nested under a key\n * matching the discriminant (e.g. `{ type: \"record\", record: { ... } }`).\n *\n * The Foundry API (DocumentTypeSchema from @osdk/foundry.pack) uses flat discriminated\n * unions where payload fields are spread alongside the type discriminant\n * (e.g. `{ type: \"record\", key: \"...\", name: \"...\", ... }`).\n *\n * This function performs that structural conversion. Field names already match between\n * the IR and wire format.\n */\nexport function convertIrToWireSchema(ir: IRealTimeDocumentSchema): DocumentTypeSchema {\n const wireModels: DocumentTypeSchema[\"models\"] = {};\n\n for (const [key, model] of Object.entries(ir.models)) {\n wireModels[key] = convertModelDef(model);\n }\n\n return {\n primaryModelKeys: [...ir.primaryModelKeys],\n models: wireModels,\n };\n}\n\nfunction convertModelDef(model: IModelDef): ModelDef {\n switch (model.type) {\n case \"record\":\n return {\n type: \"record\",\n key: model.record.key,\n name: model.record.name,\n description: orUndefined(model.record.description),\n fields: [...model.record.fields.map(convertFieldDef)],\n metadata: convertSchemaMeta(model.record.metadata),\n };\n case \"union\":\n return {\n type: \"union\",\n key: model.union.key,\n discriminant: model.union.discriminant,\n name: model.union.name,\n description: orUndefined(model.union.description),\n variants: { ...model.union.variants },\n metadata: convertSchemaMeta(model.union.metadata),\n };\n default: {\n const _exhaustive: never = model;\n throw new Error(`Unknown model type: ${(_exhaustive as IModelDef).type}`);\n }\n }\n}\n\nfunction convertFieldDef(field: IFieldDef): FieldDef {\n return {\n key: field.key,\n name: field.name,\n description: orUndefined(field.description),\n isOptional: orUndefined(field.isOptional),\n fieldType: convertFieldTypeUnion(field.fieldType),\n metadata: convertSchemaMeta(field.metadata),\n };\n}\n\nfunction convertFieldTypeUnion(fieldType: IFieldTypeUnion): FieldTypeUnion {\n switch (fieldType.type) {\n case \"array\":\n return {\n type: \"array\",\n allowNullValue: fieldType.array.allowNullValue,\n value: convertFieldValueType(fieldType.array.value),\n };\n case \"map\":\n return {\n type: \"map\",\n allowNullValue: fieldType.map.allowNullValue,\n key: convertFieldValueType(fieldType.map.key),\n value: convertFieldValueType(fieldType.map.value),\n };\n case \"set\":\n return {\n type: \"set\",\n allowNullValue: fieldType.set.allowNullValue,\n value: convertFieldValueType(fieldType.set.value),\n };\n case \"value\":\n return {\n type: \"value\",\n valueType: convertFieldValueUnion(fieldType.value),\n };\n }\n}\n\nfunction convertFieldValueType(value: IFieldValueUnion): FieldValueType {\n return {\n valueType: convertFieldValueUnion(value),\n };\n}\n\nfunction convertFieldValueUnion(value: IFieldValueUnion): FieldValueUnion {\n switch (value.type) {\n case \"boolean\":\n return { type: \"boolean\", defaultValue: orUndefined(value.boolean.defaultValue) };\n case \"datetime\":\n return { type: \"datetime\", value: value.datetime.value };\n case \"docRef\":\n return { type: \"docRef\", documentTypeRids: [...value.docRef.documentTypeRids] };\n case \"double\":\n return {\n type: \"double\",\n defaultValue: rejectNaN(orUndefined(value.double.defaultValue)),\n minValue: rejectNaN(orUndefined(value.double.minValue)),\n maxValue: rejectNaN(orUndefined(value.double.maxValue)),\n };\n case \"integer\":\n return {\n type: \"integer\",\n defaultValue: orUndefined(value.integer.defaultValue),\n minValue: orUndefined(value.integer.minValue),\n maxValue: orUndefined(value.integer.maxValue),\n };\n case \"mediaRef\":\n return { type: \"mediaRef\", value: value.mediaRef.value };\n case \"modelRef\":\n return { type: \"modelRef\", modelTypes: [...value.modelRef.modelTypes] };\n case \"object\":\n return {\n type: \"object\",\n interfaceTypeRids: [...value.object.interfaceTypeRids],\n objectTypeRids: [...value.object.objectTypeRids],\n };\n case \"string\":\n return {\n type: \"string\",\n defaultValue: orUndefined(value.string.defaultValue),\n minLength: orUndefined(value.string.minLength),\n maxLength: orUndefined(value.string.maxLength),\n };\n case \"text\":\n return {\n type: \"text\",\n defaultValue: orUndefined(value.text.defaultValue),\n minLength: orUndefined(value.text.minLength),\n maxLength: orUndefined(value.text.maxLength),\n };\n case \"unmanagedJson\":\n return { type: \"unmanagedJson\" };\n case \"userRef\":\n return { type: \"userRef\" };\n }\n}\n\nfunction convertSchemaMeta(meta: ISchemaMeta): SchemaMetadata {\n return {\n addedInVersion: meta.addedInVersion,\n deprecatedFromVersion: orUndefined(meta.deprecatedFromVersion),\n deprecatedMessage: orUndefined(meta.deprecatedMessage),\n };\n}\n\nfunction orUndefined<T>(value: T | null | undefined): T | undefined {\n return value ?? undefined;\n}\n\nfunction rejectNaN(value: number | \"NaN\" | undefined): number | undefined {\n if (value === \"NaN\") {\n throw new Error(\"NaN is not a valid double value for wire serialization\");\n }\n return value;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,qBAAqBA,CAACC,EAA2B,EAAsB;EACrF,MAAMC,UAAwC,GAAG,CAAC,CAAC;EAEnD,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,EAAE,CAACM,MAAM,CAAC,EAAE;IACpDL,UAAU,CAACC,GAAG,CAAC,GAAGK,eAAe,CAACJ,KAAK,CAAC;EAC1C;EAEA,OAAO;IACLK,gBAAgB,EAAE,CAAC,GAAGR,EAAE,CAACQ,gBAAgB,CAAC;IAC1CF,MAAM,EAAEL;EACV,CAAC;AACH;AAEA,SAASM,eAAeA,CAACJ,KAAgB,EAAY;EACnD,QAAQA,KAAK,CAACM,IAAI;IAChB,KAA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,KAAK;AACd","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"convertIrToWireSchema.js","names":["convertIrToWireSchema","ir","wireModels","key","model","Object","entries","models","convertModelDef","primaryModelKeys","type","record","name","description","orUndefined","fields","map","convertFieldDef","union","discriminant","variants","metadata","convertSchemaMeta","Error","field","isOptional","fieldType","convertFieldTypeUnion","allowNullValue","array","value","convertFieldValueType","set","valueType","convertFieldValueUnion","defaultValue","boolean","datetime","documentTypeRids","docRef","rejectNaN","double","minValue","maxValue","integer","mediaRef","modelTypes","modelRef","interfaceTypeRids","object","objectTypeRids","string","minLength","maxLength","text","meta","addedInVersion","deprecatedFromVersion","deprecatedMessage","undefined"],"sources":["convertIrToWireSchema.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 {\n DocumentTypeSchema,\n FieldDef,\n FieldTypeUnion,\n FieldValueType,\n FieldValueUnion,\n ModelDef,\n SchemaMetadata,\n} from \"@osdk/foundry.pack\";\nimport type {\n IFieldDef,\n IFieldTypeUnion,\n IFieldValueUnion,\n IModelDef,\n IRealTimeDocumentSchema,\n ISchemaMeta,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\n\n/**\n * Converts the internal IR schema to the wire format expected by the Foundry API.\n *\n * The IR uses conjure-style tagged unions where the payload is nested under a key\n * matching the discriminant (e.g. `{ type: \"record\", record: { ... } }`).\n *\n * The Foundry API (DocumentTypeSchema from @osdk/foundry.pack) uses flat discriminated\n * unions where payload fields are spread alongside the type discriminant\n * (e.g. `{ type: \"record\", key: \"...\", name: \"...\", ... }`).\n *\n * This function performs that structural conversion. Field names already match between\n * the IR and wire format.\n */\nexport function convertIrToWireSchema(ir: IRealTimeDocumentSchema): DocumentTypeSchema {\n const wireModels: DocumentTypeSchema[\"models\"] = {};\n\n for (const [key, model] of Object.entries(ir.models)) {\n wireModels[key] = convertModelDef(model);\n }\n\n return {\n primaryModelKeys: [...ir.primaryModelKeys],\n models: wireModels,\n };\n}\n\nfunction convertModelDef(model: IModelDef): ModelDef {\n switch (model.type) {\n case \"record\":\n // TODO: The @osdk/foundry.pack wire types still declare `metadata` as required on\n // RecordDef, but the Pack API schema (api-gateway / backpack) has removed it.\n // Cast through unknown until the published types catch up.\n return {\n type: \"record\",\n key: model.record.key,\n name: model.record.name,\n description: orUndefined(model.record.description),\n fields: [...model.record.fields.map(convertFieldDef)],\n } as unknown as ModelDef;\n case \"union\":\n return {\n type: \"union\",\n key: model.union.key,\n discriminant: model.union.discriminant,\n name: model.union.name,\n description: orUndefined(model.union.description),\n variants: { ...model.union.variants },\n metadata: convertSchemaMeta(model.union.metadata),\n };\n default: {\n const _exhaustive: never = model;\n throw new Error(`Unknown model type: ${(_exhaustive as IModelDef).type}`);\n }\n }\n}\n\nfunction convertFieldDef(field: IFieldDef): FieldDef {\n return {\n key: field.key,\n name: field.name,\n description: orUndefined(field.description),\n isOptional: orUndefined(field.isOptional),\n fieldType: convertFieldTypeUnion(field.fieldType),\n metadata: convertSchemaMeta(field.metadata),\n };\n}\n\nfunction convertFieldTypeUnion(fieldType: IFieldTypeUnion): FieldTypeUnion {\n switch (fieldType.type) {\n case \"array\":\n return {\n type: \"array\",\n allowNullValue: fieldType.array.allowNullValue,\n value: convertFieldValueType(fieldType.array.value),\n };\n case \"map\":\n return {\n type: \"map\",\n allowNullValue: fieldType.map.allowNullValue,\n key: convertFieldValueType(fieldType.map.key),\n value: convertFieldValueType(fieldType.map.value),\n };\n case \"set\":\n return {\n type: \"set\",\n allowNullValue: fieldType.set.allowNullValue,\n value: convertFieldValueType(fieldType.set.value),\n };\n case \"value\":\n return {\n type: \"value\",\n valueType: convertFieldValueUnion(fieldType.value),\n };\n }\n}\n\nfunction convertFieldValueType(value: IFieldValueUnion): FieldValueType {\n return {\n valueType: convertFieldValueUnion(value),\n };\n}\n\nfunction convertFieldValueUnion(value: IFieldValueUnion): FieldValueUnion {\n switch (value.type) {\n case \"boolean\":\n return { type: \"boolean\", defaultValue: orUndefined(value.boolean.defaultValue) };\n case \"datetime\":\n return { type: \"datetime\", value: value.datetime.value };\n case \"docRef\":\n return { type: \"docRef\", documentTypeRids: [...value.docRef.documentTypeRids] };\n case \"double\":\n return {\n type: \"double\",\n defaultValue: rejectNaN(orUndefined(value.double.defaultValue)),\n minValue: rejectNaN(orUndefined(value.double.minValue)),\n maxValue: rejectNaN(orUndefined(value.double.maxValue)),\n };\n case \"integer\":\n return {\n type: \"integer\",\n defaultValue: orUndefined(value.integer.defaultValue),\n minValue: orUndefined(value.integer.minValue),\n maxValue: orUndefined(value.integer.maxValue),\n };\n case \"mediaRef\":\n return { type: \"mediaRef\", value: value.mediaRef.value };\n case \"modelRef\":\n return { type: \"modelRef\", modelTypes: [...value.modelRef.modelTypes] };\n case \"object\":\n return {\n type: \"object\",\n interfaceTypeRids: [...value.object.interfaceTypeRids],\n objectTypeRids: [...value.object.objectTypeRids],\n };\n case \"string\":\n return {\n type: \"string\",\n defaultValue: orUndefined(value.string.defaultValue),\n minLength: orUndefined(value.string.minLength),\n maxLength: orUndefined(value.string.maxLength),\n };\n case \"text\":\n return {\n type: \"text\",\n defaultValue: orUndefined(value.text.defaultValue),\n minLength: orUndefined(value.text.minLength),\n maxLength: orUndefined(value.text.maxLength),\n };\n case \"unmanagedJson\":\n return { type: \"unmanagedJson\" };\n case \"userRef\":\n return { type: \"userRef\" };\n }\n}\n\nfunction convertSchemaMeta(meta: ISchemaMeta): SchemaMetadata {\n return {\n addedInVersion: meta.addedInVersion,\n deprecatedFromVersion: orUndefined(meta.deprecatedFromVersion),\n deprecatedMessage: orUndefined(meta.deprecatedMessage),\n };\n}\n\nfunction orUndefined<T>(value: T | null | undefined): T | undefined {\n return value ?? undefined;\n}\n\nfunction rejectNaN(value: number | \"NaN\" | undefined): number | undefined {\n if (value === \"NaN\") {\n throw new Error(\"NaN is not a valid double value for wire serialization\");\n }\n return value;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAoBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,qBAAqBA,CAACC,EAA2B,EAAsB;EACrF,MAAMC,UAAwC,GAAG,CAAC,CAAC;EAEnD,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,EAAE,CAACM,MAAM,CAAC,EAAE;IACpDL,UAAU,CAACC,GAAG,CAAC,GAAGK,eAAe,CAACJ,KAAK,CAAC;EAC1C;EAEA,OAAO;IACLK,gBAAgB,EAAE,CAAC,GAAGR,EAAE,CAACQ,gBAAgB,CAAC;IAC1CF,MAAM,EAAEL;EACV,CAAC;AACH;AAEA,SAASM,eAAeA,CAACJ,KAAgB,EAAY;EACnD,QAAQA,KAAK,CAACM,IAAI;IAChB,KAAK,QAAQ;MACX;MACA;MACA;MACA,OAAO;QACLA,IAAI,EAAE,QAAQ;QACdP,GAAG,EAAEC,KAAK,CAACO,MAAM,CAACR,GAAG;QACrBS,IAAI,EAAER,KAAK,CAACO,MAAM,CAACC,IAAI;QACvBC,WAAW,EAAEC,WAAW,CAACV,KAAK,CAACO,MAAM,CAACE,WAAW,CAAC;QAClDE,MAAM,EAAE,CAAC,GAAGX,KAAK,CAACO,MAAM,CAACI,MAAM,CAACC,GAAG,CAACC,eAAe,CAAC;MACtD,CAAC;IACH,KAAK,OAAO;MACV,OAAO;QACLP,IAAI,EAAE,OAAO;QACbP,GAAG,EAAEC,KAAK,CAACc,KAAK,CA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SAAS,EAAEtC,WAAW,CAACgB,KAAK,CAACwB,IAAI,CAACF,SAAS,CAAC;QAC5CC,SAAS,EAAEvC,WAAW,CAACgB,KAAK,CAACwB,IAAI,CAACD,SAAS;MAC7C,CAAC;IACH,KAAK,eAAe;MAClB,OAAO;QAAE3C,IAAI,EAAE;MAAgB,CAAC;IAClC,KAAK,SAAS;MACZ,OAAO;QAAEA,IAAI,EAAE;MAAU,CAAC;EAC9B;AACF;AAEA,SAASY,iBAAiBA,CAACiC,IAAiB,EAAkB;EAC5D,OAAO;IACLC,cAAc,EAAED,IAAI,CAACC,cAAc;IACnCC,qBAAqB,EAAE3C,WAAW,CAACyC,IAAI,CAACE,qBAAqB,CAAC;IAC9DC,iBAAiB,EAAE5C,WAAW,CAACyC,IAAI,CAACG,iBAAiB;EACvD,CAAC;AACH;AAEA,SAAS5C,WAAWA,CAAIgB,KAA2B,EAAiB;EAClE,OAAOA,KAAK,IAAI6B,SAAS;AAC3B;AAEA,SAASnB,SAASA,CAACV,KAAiC,EAAsB;EACxE,IAAIA,KAAK,KAAK,KAAK,EAAE;IACnB,MAAM,IAAIP,KAAK,CAAC,wDAAwD,CAAC;EAC3E;EACA,OAAOO,KAAK;AACd","ignoreList":[]}
|
|
@@ -143,7 +143,7 @@ class ZodSchemaGenerator {
|
|
|
143
143
|
const formattedVariantName = formatVariantName(variantName);
|
|
144
144
|
variantSchemaNames.push(`${union.key}${formattedVariantName}Schema`);
|
|
145
145
|
}
|
|
146
|
-
const discriminatorField = union.discriminant
|
|
146
|
+
const discriminatorField = union.discriminant ?? "type";
|
|
147
147
|
return `z.discriminatedUnion("${discriminatorField}", [\n ${variantSchemaNames.join(",\n ")}\n])`;
|
|
148
148
|
}
|
|
149
149
|
generateUnionWithVariants(union) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateZodSchemasFromIr.js","names":["consola","invariant","assertNever","formatVariantName","GENERATED_FILE_HEADER","ZodSchemaGenerator","constructor","schema","options","generateSDK","Error","generateTypes","imports","typeImportPath","typeNames","Set","primaryModelKeys","modelKey","model","models","type","variantName","Object","keys","union","variants","formattedVariantName","variantTypeName","key","add","typeImports","Array","from","sort","join","schemasCode","generateZodSchemas","schemaLines","emittedModels","recordSchemas","Map","unionDefinitions","modelTypeKey","process","env","NODE_ENV","schemaCode","generateRecordSchema","record","satisfiesClause","set","push","remainingUnions","madeProgress","size","allDependenciesEmitted","values","every","variantModelKey","has","unionSchemas","generateUnionWithVariants","delete","warn","generateModel","generateUnionSchema","fieldEntryLines","field","fields","fieldSchema","generateFieldSchema","variantSchemaNames","entries","discriminatorField","discriminant","variantSchemas","variantSchemaName","variantModel","variantSchemaCode","recordKey","unionKey","unionSchema","unionSatisfiesClause","fieldValueSchemaStr","generateFieldTypeSchema","fieldType","isOptional","arrayElementSchema","generateFieldValueSchema","array","value","keySchema","map","valueSchema","setElementSchema","fieldValue","doubleSchema","double","minValue","maxValue","intSchema","integer","refVariantsLines","modelType","modelRef","modelTypes","includes","length","stringSchema","string","minLength","maxLength","generateZodSchemasFromIr","generator"],"sources":["generateZodSchemasFromIr.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 consola from \"consola\";\nimport invariant from \"tiny-invariant\";\nimport type {\n IFieldDef,\n IFieldTypeUnion,\n IFieldValueUnion,\n IModelDef,\n IRealTimeDocumentSchema,\n IRecordDef,\n IUnionDef,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { assertNever } from \"../assertNever.js\";\nimport { formatVariantName } from \"../formatVariantName.js\";\nimport { GENERATED_FILE_HEADER } from \"../generatedFileHeader.js\";\n\nexport interface ZodGeneratorOptions {\n namespace?: string;\n includeTypes?: boolean;\n includeCRDT?: boolean;\n typeImportPath?: string;\n}\n\nclass ZodSchemaGenerator {\n constructor(\n private readonly schema: IRealTimeDocumentSchema,\n private readonly options?: ZodGeneratorOptions,\n ) {}\n\n public generateSDK(_options: ZodGeneratorOptions): string {\n throw new Error(\n \"SDK generation not yet implemented - placeholder for future development\",\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n public async generateTypes(): Promise<string> {\n let imports = \"import { z } from 'zod';\\n\";\n\n if (this.options?.typeImportPath) {\n imports = \"import type { ZodType } from \\\"zod\\\";\\n\" + imports;\n\n // Collect all type names from the schema (primary models + union variants)\n const typeNames = new Set(this.schema.primaryModelKeys);\n\n // Add union variant type names\n for (const modelKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelKey];\n if (model?.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantTypeName = `${model.union.key}${formattedVariantName}`;\n typeNames.add(variantTypeName);\n }\n }\n }\n\n const typeImports = Array.from(typeNames).sort().join(\", \");\n imports += `import type { ${typeImports} } from \"${this.options.typeImportPath}\";\\n`;\n }\n\n imports += \"\\n\";\n const schemasCode = this.generateZodSchemas();\n return GENERATED_FILE_HEADER + imports + schemasCode + \"\\n\";\n }\n\n private generateZodSchemas(): string {\n const schemaLines: string[] = [];\n const emittedModels = new Set<string>();\n const recordSchemas = new Map<string, string>();\n const unionDefinitions = new Map<string, IUnionDef>();\n\n // First, categorize all models and generate record schemas\n for (const modelTypeKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelTypeKey];\n invariant(model != null, `Model not found: ${modelTypeKey}`);\n\n switch (model.type) {\n case \"record\": {\n const schemaCode = this.generateRecordSchema(model.record);\n const satisfiesClause = this.options?.typeImportPath\n ? ` satisfies ZodType<${modelTypeKey}>`\n : \"\";\n recordSchemas.set(\n modelTypeKey,\n `export const ${modelTypeKey}Schema = ${schemaCode}${satisfiesClause};`,\n );\n break;\n }\n case \"union\": {\n unionDefinitions.set(modelTypeKey, model.union);\n break;\n }\n }\n }\n\n // Emit all record schemas first\n for (const [modelTypeKey, schemaCode] of recordSchemas) {\n schemaLines.push(schemaCode);\n emittedModels.add(modelTypeKey);\n }\n\n // Now handle unions with proper dependency ordering\n const remainingUnions = new Map(unionDefinitions);\n let madeProgress = true;\n\n while (remainingUnions.size > 0 && madeProgress) {\n madeProgress = false;\n\n for (const [modelTypeKey, union] of remainingUnions) {\n // Check if all dependencies are already emitted\n const allDependenciesEmitted = Object.values(union.variants).every(\n variantModelKey => emittedModels.has(variantModelKey),\n );\n\n if (allDependenciesEmitted) {\n // Generate the union with its variant schemas\n const unionSchemas = this.generateUnionWithVariants(union);\n schemaLines.push(unionSchemas);\n emittedModels.add(modelTypeKey);\n remainingUnions.delete(modelTypeKey);\n madeProgress = true;\n }\n }\n }\n\n // If there are still remaining unions, we have circular dependencies or missing models\n if (remainingUnions.size > 0) {\n consola.warn(\n `Warning: Could not generate schemas for unions due to circular or missing dependencies: ${\n Array.from(remainingUnions.keys()).join(\", \")\n }`,\n );\n // Emit them anyway with a comment\n for (const [modelTypeKey, union] of remainingUnions) {\n schemaLines.push(`// Warning: Union ${modelTypeKey} may have unresolved dependencies`);\n const unionSchemas = this.generateUnionWithVariants(union);\n schemaLines.push(unionSchemas);\n }\n }\n\n return schemaLines.join(\"\\n\\n\");\n }\n\n private generateModel(\n model: IModelDef,\n ): string {\n switch (model.type) {\n case \"record\":\n return this.generateRecordSchema(model.record);\n case \"union\":\n return this.generateUnionSchema(model.union);\n default:\n assertNever(model);\n }\n }\n\n private generateRecordSchema(\n record: IRecordDef,\n ): string {\n const fieldEntryLines: string[] = [];\n for (const field of record.fields) {\n const fieldSchema = this.generateFieldSchema(field);\n fieldEntryLines.push(` ${field.key}: ${fieldSchema}`);\n }\n return `z.object({\\n${fieldEntryLines.join(\",\\n\")}\\n})`;\n }\n\n private generateUnionSchema(\n union: IUnionDef,\n ): string {\n // Just return the discriminated union without variant schemas\n const variantSchemaNames: string[] = [];\n\n for (const [variantName] of Object.entries(union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n variantSchemaNames.push(`${union.key}${formattedVariantName}Schema`);\n }\n\n const discriminatorField = union.discriminant || \"type\";\n return `z.discriminatedUnion(\"${discriminatorField}\", [\\n ${\n variantSchemaNames.join(\",\\n \")\n }\\n])`;\n }\n\n private generateUnionWithVariants(\n union: IUnionDef,\n ): string {\n const variantSchemas: string[] = [];\n const variantSchemaNames: string[] = [];\n\n // Generate variant schemas\n for (const [variantName, variantModelKey] of Object.entries(union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantSchemaName = `${union.key}${formattedVariantName}Schema`;\n variantSchemaNames.push(variantSchemaName);\n\n // Look up the model from the schema\n const variantModel = this.schema.models[variantModelKey];\n invariant(variantModel != null, `Model not found: ${variantModelKey}`);\n\n let variantSchemaCode: string;\n switch (variantModel.type) {\n case \"record\": {\n // For record variants, reference the existing record schema and extend with discriminator\n const recordKey = variantModel.record.key;\n const discriminatorField = ` ${union.discriminant}: z.literal(\"${variantName}\")`;\n\n // Extend the existing record schema with the discriminator field\n // Note: We assume records are defined before unions, so we can directly reference them\n variantSchemaCode = `${recordKey}Schema.extend({\\n${discriminatorField}\\n})`;\n break;\n }\n case \"union\": {\n // For union variants (nested unions), wrap with discriminator and value\n const unionKey = variantModel.union.key;\n variantSchemaCode =\n `z.object({\\n ${union.discriminant}: z.literal(\"${variantName}\"),\\n value: z.lazy(() => ${unionKey}Schema)\\n})`;\n break;\n }\n default:\n assertNever(variantModel);\n }\n\n // Generate satisfies clause for variant schemas if typeImportPath is provided\n const variantTypeName = `${union.key}${formattedVariantName}`;\n const satisfiesClause = this.options?.typeImportPath\n ? ` satisfies ZodType<${variantTypeName}>`\n : \"\";\n variantSchemas.push(\n `export const ${variantSchemaName} = ${variantSchemaCode}${satisfiesClause};`,\n );\n }\n\n // Generate the discriminated union\n const discriminatorField = union.discriminant || \"type\";\n const unionSchema = `z.discriminatedUnion(\"${discriminatorField}\", [\\n ${\n variantSchemaNames.join(\",\\n \")\n }\\n])`;\n\n // Generate satisfies clause for the main union schema if typeImportPath is provided\n const unionSatisfiesClause = this.options?.typeImportPath\n ? ` satisfies ZodType<${union.key}>`\n : \"\";\n\n // Return the variant schemas and the union schema\n return variantSchemas.join(\"\\n\\n\")\n + `\\n\\nexport const ${union.key}Schema = ${unionSchema}${unionSatisfiesClause};`;\n }\n\n private generateFieldSchema(\n field: IFieldDef,\n ): string {\n const fieldValueSchemaStr = this.generateFieldTypeSchema(field.fieldType);\n\n if (field.isOptional) {\n return `${fieldValueSchemaStr}.optional()`;\n }\n\n return fieldValueSchemaStr;\n }\n\n private generateFieldTypeSchema(\n fieldType: IFieldTypeUnion,\n ): string {\n switch (fieldType.type) {\n case \"array\": {\n const arrayElementSchema = this.generateFieldValueSchema(\n fieldType.array.value,\n );\n return `z.array(${arrayElementSchema})`;\n }\n\n case \"map\": {\n const keySchema = this.generateFieldValueSchema(\n fieldType.map.key,\n );\n const valueSchema = this.generateFieldValueSchema(\n fieldType.map.value,\n );\n return `z.record(${keySchema}, ${valueSchema})`;\n }\n case \"set\": {\n const setElementSchema = this.generateFieldValueSchema(\n fieldType.set.value,\n );\n return `z.array(${setElementSchema})`;\n } // Zod doesn't have Set, use array\n\n case \"value\":\n return this.generateFieldValueSchema(fieldType.value);\n\n default:\n assertNever(fieldType);\n }\n }\n\n private generateFieldValueSchema(\n fieldValue: IFieldValueUnion,\n ): string {\n switch (fieldValue.type) {\n case \"boolean\":\n return \"z.boolean()\";\n\n case \"datetime\":\n return \"z.string().datetime()\";\n\n case \"double\": {\n let doubleSchema = \"z.number()\";\n if (fieldValue.double.minValue != null) {\n doubleSchema += `.min(${fieldValue.double.minValue})`;\n }\n if (fieldValue.double.maxValue != null) {\n doubleSchema += `.max(${fieldValue.double.maxValue})`;\n }\n return doubleSchema;\n }\n\n case \"integer\": {\n let intSchema = \"z.number().int()\";\n if (fieldValue.integer.minValue != null) {\n intSchema += `.min(${fieldValue.integer.minValue})`;\n }\n if (fieldValue.integer.maxValue != null) {\n intSchema += `.max(${fieldValue.integer.maxValue})`;\n }\n return intSchema;\n }\n\n case \"modelRef\": {\n const refVariantsLines: string[] = [];\n\n for (const modelType of fieldValue.modelRef.modelTypes) {\n const model = this.schema.models[modelType];\n invariant(model != null, `Model not found: ${modelType}`);\n\n // Referent the model directly\n if (this.schema.primaryModelKeys.includes(modelType)) {\n return `z.lazy(() => ${modelType}Schema)`;\n }\n\n // Generate inline model\n // TODO: should not be possible to have recursive nested models but we should guard against it\n return this.generateModel(model);\n }\n\n if (refVariantsLines.length === 0) {\n return \"z.unknown()\";\n }\n\n if (refVariantsLines.length === 1) {\n return refVariantsLines[0]!;\n }\n\n return `z.union([${refVariantsLines.join(\", \")}])`;\n }\n\n case \"string\": {\n let stringSchema = \"z.string()\";\n if (fieldValue.string.minLength != null) {\n stringSchema += `.min(${fieldValue.string.minLength})`;\n }\n if (fieldValue.string.maxLength != null) {\n stringSchema += `.max(${fieldValue.string.maxLength})`;\n }\n return stringSchema;\n }\n\n case \"text\":\n return \"z.unknown()\";\n\n case \"unmanagedJson\":\n return \"z.unknown()\";\n\n case \"docRef\":\n case \"mediaRef\":\n case \"object\":\n case \"userRef\":\n return \"z.string()\"; // Assume these are string IDs\n\n default:\n assertNever(fieldValue);\n }\n }\n}\n\nexport async function generateZodSchemasFromIr(\n schema: IRealTimeDocumentSchema,\n options?: ZodGeneratorOptions,\n): Promise<string> {\n const generator = new ZodSchemaGenerator(schema, options);\n return generator.generateTypes();\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,OAAO,MAAM,SAAS;AAC7B,OAAOC,SAAS,MAAM,gBAAgB;AAUtC,SAASC,WAAW,QAAQ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Q;MACb,KAAK,UAAU;MACf,KAAK,QAAQ;MACb,KAAK,SAAS;QACZ,OAAO,YAAY;MAAE;;MAEvB;QACE1G,WAAW,CAAC6F,UAAU,CAAC;IAC3B;EACF;AACF;AAEA,OAAO,eAAeiB,wBAAwBA,CAC5CzG,MAA+B,EAC/BC,OAA6B,EACZ;EACjB,MAAMyG,SAAS,GAAG,IAAI5G,kBAAkB,CAACE,MAAM,EAAEC,OAAO,CAAC;EACzD,OAAOyG,SAAS,CAACtG,aAAa,CAAC,CAAC;AAClC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"generateZodSchemasFromIr.js","names":["consola","invariant","assertNever","formatVariantName","GENERATED_FILE_HEADER","ZodSchemaGenerator","constructor","schema","options","generateSDK","Error","generateTypes","imports","typeImportPath","typeNames","Set","primaryModelKeys","modelKey","model","models","type","variantName","Object","keys","union","variants","formattedVariantName","variantTypeName","key","add","typeImports","Array","from","sort","join","schemasCode","generateZodSchemas","schemaLines","emittedModels","recordSchemas","Map","unionDefinitions","modelTypeKey","process","env","NODE_ENV","schemaCode","generateRecordSchema","record","satisfiesClause","set","push","remainingUnions","madeProgress","size","allDependenciesEmitted","values","every","variantModelKey","has","unionSchemas","generateUnionWithVariants","delete","warn","generateModel","generateUnionSchema","fieldEntryLines","field","fields","fieldSchema","generateFieldSchema","variantSchemaNames","entries","discriminatorField","discriminant","variantSchemas","variantSchemaName","variantModel","variantSchemaCode","recordKey","unionKey","unionSchema","unionSatisfiesClause","fieldValueSchemaStr","generateFieldTypeSchema","fieldType","isOptional","arrayElementSchema","generateFieldValueSchema","array","value","keySchema","map","valueSchema","setElementSchema","fieldValue","doubleSchema","double","minValue","maxValue","intSchema","integer","refVariantsLines","modelType","modelRef","modelTypes","includes","length","stringSchema","string","minLength","maxLength","generateZodSchemasFromIr","generator"],"sources":["generateZodSchemasFromIr.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 consola from \"consola\";\nimport invariant from \"tiny-invariant\";\nimport type {\n IFieldDef,\n IFieldTypeUnion,\n IFieldValueUnion,\n IModelDef,\n IRealTimeDocumentSchema,\n IRecordDef,\n IUnionDef,\n} from \"../../lib/pack-docschema-api/pack-docschema-ir/index.js\";\nimport { assertNever } from \"../assertNever.js\";\nimport { formatVariantName } from \"../formatVariantName.js\";\nimport { GENERATED_FILE_HEADER } from \"../generatedFileHeader.js\";\n\nexport interface ZodGeneratorOptions {\n namespace?: string;\n includeTypes?: boolean;\n includeCRDT?: boolean;\n typeImportPath?: string;\n}\n\nclass ZodSchemaGenerator {\n constructor(\n private readonly schema: IRealTimeDocumentSchema,\n private readonly options?: ZodGeneratorOptions,\n ) {}\n\n public generateSDK(_options: ZodGeneratorOptions): string {\n throw new Error(\n \"SDK generation not yet implemented - placeholder for future development\",\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/require-await\n public async generateTypes(): Promise<string> {\n let imports = \"import { z } from 'zod';\\n\";\n\n if (this.options?.typeImportPath) {\n imports = \"import type { ZodType } from \\\"zod\\\";\\n\" + imports;\n\n // Collect all type names from the schema (primary models + union variants)\n const typeNames = new Set(this.schema.primaryModelKeys);\n\n // Add union variant type names\n for (const modelKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelKey];\n if (model?.type === \"union\") {\n for (const variantName of Object.keys(model.union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantTypeName = `${model.union.key}${formattedVariantName}`;\n typeNames.add(variantTypeName);\n }\n }\n }\n\n const typeImports = Array.from(typeNames).sort().join(\", \");\n imports += `import type { ${typeImports} } from \"${this.options.typeImportPath}\";\\n`;\n }\n\n imports += \"\\n\";\n const schemasCode = this.generateZodSchemas();\n return GENERATED_FILE_HEADER + imports + schemasCode + \"\\n\";\n }\n\n private generateZodSchemas(): string {\n const schemaLines: string[] = [];\n const emittedModels = new Set<string>();\n const recordSchemas = new Map<string, string>();\n const unionDefinitions = new Map<string, IUnionDef>();\n\n // First, categorize all models and generate record schemas\n for (const modelTypeKey of this.schema.primaryModelKeys) {\n const model = this.schema.models[modelTypeKey];\n invariant(model != null, `Model not found: ${modelTypeKey}`);\n\n switch (model.type) {\n case \"record\": {\n const schemaCode = this.generateRecordSchema(model.record);\n const satisfiesClause = this.options?.typeImportPath\n ? ` satisfies ZodType<${modelTypeKey}>`\n : \"\";\n recordSchemas.set(\n modelTypeKey,\n `export const ${modelTypeKey}Schema = ${schemaCode}${satisfiesClause};`,\n );\n break;\n }\n case \"union\": {\n unionDefinitions.set(modelTypeKey, model.union);\n break;\n }\n }\n }\n\n // Emit all record schemas first\n for (const [modelTypeKey, schemaCode] of recordSchemas) {\n schemaLines.push(schemaCode);\n emittedModels.add(modelTypeKey);\n }\n\n // Now handle unions with proper dependency ordering\n const remainingUnions = new Map(unionDefinitions);\n let madeProgress = true;\n\n while (remainingUnions.size > 0 && madeProgress) {\n madeProgress = false;\n\n for (const [modelTypeKey, union] of remainingUnions) {\n // Check if all dependencies are already emitted\n const allDependenciesEmitted = Object.values(union.variants).every(\n variantModelKey => emittedModels.has(variantModelKey),\n );\n\n if (allDependenciesEmitted) {\n // Generate the union with its variant schemas\n const unionSchemas = this.generateUnionWithVariants(union);\n schemaLines.push(unionSchemas);\n emittedModels.add(modelTypeKey);\n remainingUnions.delete(modelTypeKey);\n madeProgress = true;\n }\n }\n }\n\n // If there are still remaining unions, we have circular dependencies or missing models\n if (remainingUnions.size > 0) {\n consola.warn(\n `Warning: Could not generate schemas for unions due to circular or missing dependencies: ${\n Array.from(remainingUnions.keys()).join(\", \")\n }`,\n );\n // Emit them anyway with a comment\n for (const [modelTypeKey, union] of remainingUnions) {\n schemaLines.push(`// Warning: Union ${modelTypeKey} may have unresolved dependencies`);\n const unionSchemas = this.generateUnionWithVariants(union);\n schemaLines.push(unionSchemas);\n }\n }\n\n return schemaLines.join(\"\\n\\n\");\n }\n\n private generateModel(\n model: IModelDef,\n ): string {\n switch (model.type) {\n case \"record\":\n return this.generateRecordSchema(model.record);\n case \"union\":\n return this.generateUnionSchema(model.union);\n default:\n assertNever(model);\n }\n }\n\n private generateRecordSchema(\n record: IRecordDef,\n ): string {\n const fieldEntryLines: string[] = [];\n for (const field of record.fields) {\n const fieldSchema = this.generateFieldSchema(field);\n fieldEntryLines.push(` ${field.key}: ${fieldSchema}`);\n }\n return `z.object({\\n${fieldEntryLines.join(\",\\n\")}\\n})`;\n }\n\n private generateUnionSchema(\n union: IUnionDef,\n ): string {\n // Just return the discriminated union without variant schemas\n const variantSchemaNames: string[] = [];\n\n for (const [variantName] of Object.entries(union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n variantSchemaNames.push(`${union.key}${formattedVariantName}Schema`);\n }\n\n const discriminatorField = union.discriminant ?? \"type\";\n return `z.discriminatedUnion(\"${discriminatorField}\", [\\n ${\n variantSchemaNames.join(\",\\n \")\n }\\n])`;\n }\n\n private generateUnionWithVariants(\n union: IUnionDef,\n ): string {\n const variantSchemas: string[] = [];\n const variantSchemaNames: string[] = [];\n\n // Generate variant schemas\n for (const [variantName, variantModelKey] of Object.entries(union.variants)) {\n const formattedVariantName = formatVariantName(variantName);\n const variantSchemaName = `${union.key}${formattedVariantName}Schema`;\n variantSchemaNames.push(variantSchemaName);\n\n // Look up the model from the schema\n const variantModel = this.schema.models[variantModelKey];\n invariant(variantModel != null, `Model not found: ${variantModelKey}`);\n\n let variantSchemaCode: string;\n switch (variantModel.type) {\n case \"record\": {\n // For record variants, reference the existing record schema and extend with discriminator\n const recordKey = variantModel.record.key;\n const discriminatorField = ` ${union.discriminant}: z.literal(\"${variantName}\")`;\n\n // Extend the existing record schema with the discriminator field\n // Note: We assume records are defined before unions, so we can directly reference them\n variantSchemaCode = `${recordKey}Schema.extend({\\n${discriminatorField}\\n})`;\n break;\n }\n case \"union\": {\n // For union variants (nested unions), wrap with discriminator and value\n const unionKey = variantModel.union.key;\n variantSchemaCode =\n `z.object({\\n ${union.discriminant}: z.literal(\"${variantName}\"),\\n value: z.lazy(() => ${unionKey}Schema)\\n})`;\n break;\n }\n default:\n assertNever(variantModel);\n }\n\n // Generate satisfies clause for variant schemas if typeImportPath is provided\n const variantTypeName = `${union.key}${formattedVariantName}`;\n const satisfiesClause = this.options?.typeImportPath\n ? ` satisfies ZodType<${variantTypeName}>`\n : \"\";\n variantSchemas.push(\n `export const ${variantSchemaName} = ${variantSchemaCode}${satisfiesClause};`,\n );\n }\n\n // Generate the discriminated union\n const discriminatorField = union.discriminant || \"type\";\n const unionSchema = `z.discriminatedUnion(\"${discriminatorField}\", [\\n ${\n variantSchemaNames.join(\",\\n \")\n }\\n])`;\n\n // Generate satisfies clause for the main union schema if typeImportPath is provided\n const unionSatisfiesClause = this.options?.typeImportPath\n ? ` satisfies ZodType<${union.key}>`\n : \"\";\n\n // Return the variant schemas and the union schema\n return variantSchemas.join(\"\\n\\n\")\n + `\\n\\nexport const ${union.key}Schema = ${unionSchema}${unionSatisfiesClause};`;\n }\n\n private generateFieldSchema(\n field: IFieldDef,\n ): string {\n const fieldValueSchemaStr = this.generateFieldTypeSchema(field.fieldType);\n\n if (field.isOptional) {\n return `${fieldValueSchemaStr}.optional()`;\n }\n\n return fieldValueSchemaStr;\n }\n\n private generateFieldTypeSchema(\n fieldType: IFieldTypeUnion,\n ): string {\n switch (fieldType.type) {\n case \"array\": {\n const arrayElementSchema = this.generateFieldValueSchema(\n fieldType.array.value,\n );\n return `z.array(${arrayElementSchema})`;\n }\n\n case \"map\": {\n const keySchema = this.generateFieldValueSchema(\n fieldType.map.key,\n );\n const valueSchema = this.generateFieldValueSchema(\n fieldType.map.value,\n );\n return `z.record(${keySchema}, ${valueSchema})`;\n }\n case \"set\": {\n const setElementSchema = this.generateFieldValueSchema(\n fieldType.set.value,\n );\n return `z.array(${setElementSchema})`;\n } // Zod doesn't have Set, use array\n\n case \"value\":\n return this.generateFieldValueSchema(fieldType.value);\n\n default:\n assertNever(fieldType);\n }\n }\n\n private generateFieldValueSchema(\n fieldValue: IFieldValueUnion,\n ): string {\n switch (fieldValue.type) {\n case \"boolean\":\n return \"z.boolean()\";\n\n case \"datetime\":\n return \"z.string().datetime()\";\n\n case \"double\": {\n let doubleSchema = \"z.number()\";\n if (fieldValue.double.minValue != null) {\n doubleSchema += `.min(${fieldValue.double.minValue})`;\n }\n if (fieldValue.double.maxValue != null) {\n doubleSchema += `.max(${fieldValue.double.maxValue})`;\n }\n return doubleSchema;\n }\n\n case \"integer\": {\n let intSchema = \"z.number().int()\";\n if (fieldValue.integer.minValue != null) {\n intSchema += `.min(${fieldValue.integer.minValue})`;\n }\n if (fieldValue.integer.maxValue != null) {\n intSchema += `.max(${fieldValue.integer.maxValue})`;\n }\n return intSchema;\n }\n\n case \"modelRef\": {\n const refVariantsLines: string[] = [];\n\n for (const modelType of fieldValue.modelRef.modelTypes) {\n const model = this.schema.models[modelType];\n invariant(model != null, `Model not found: ${modelType}`);\n\n // Referent the model directly\n if (this.schema.primaryModelKeys.includes(modelType)) {\n return `z.lazy(() => ${modelType}Schema)`;\n }\n\n // Generate inline model\n // TODO: should not be possible to have recursive nested models but we should guard against it\n return this.generateModel(model);\n }\n\n if (refVariantsLines.length === 0) {\n return \"z.unknown()\";\n }\n\n if (refVariantsLines.length === 1) {\n return refVariantsLines[0]!;\n }\n\n return `z.union([${refVariantsLines.join(\", \")}])`;\n }\n\n case \"string\": {\n let stringSchema = \"z.string()\";\n if (fieldValue.string.minLength != null) {\n stringSchema += `.min(${fieldValue.string.minLength})`;\n }\n if (fieldValue.string.maxLength != null) {\n stringSchema += `.max(${fieldValue.string.maxLength})`;\n }\n return stringSchema;\n }\n\n case \"text\":\n return \"z.unknown()\";\n\n case \"unmanagedJson\":\n return \"z.unknown()\";\n\n case \"docRef\":\n case \"mediaRef\":\n case \"object\":\n case \"userRef\":\n return \"z.string()\"; // Assume these are string IDs\n\n default:\n assertNever(fieldValue);\n }\n }\n}\n\nexport async function generateZodSchemasFromIr(\n schema: IRealTimeDocumentSchema,\n options?: ZodGeneratorOptions,\n): Promise<string> {\n const generator = new ZodSchemaGenerator(schema, options);\n return generator.generateTypes();\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,OAAO,MAAM,SAAS;AAC7B,OAAOC,SAAS,MAAM,gBAAgB;AAUtC,SAASC,WAAW,QAAQ,mBAAmB;AAC/C,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,qBAAqB,QAAQ,2BAA2B;AASjE,MAAMC,kBAAkB,CAAC;EACvBC,WAAWA,CACQC,MAA+B,EAC/BC,OAA6B,EAC9C;IAAA,KAFiBD,MAA+B,GAA/BA,MAA+B;IAAA,KAC/BC,OAA6B,GAA7BA,OAA6B;EAC7C;EAEIC,WAAWA,CAAA,EAAwC;IACxD,MAAM,IAAIC,KAAK,CACb,yEACF,CAAC;EACH;;EAEA;EACA,MAAaC,aAAaA,CAAA,EAAoB;IAC5C,IAAIC,OAAO,GAAG,4BAA4B;IAE1C,IAAI,IAAI,CAACJ,OAAO,EAAEK,cAAc,EAAE;MAChCD,OAAO,GAAG,yCAAyC,GAAGA,OAAO;;MAE7D;MACA,MAAME,SAAS,GAAG,IAAIC,GAAG,CAAC,IAAI,CAACR,MAAM,CAACS,gBAAgB,CAAC;;MAEvD;MACA,KAAK,MAAMC,QAAQ,IAAI,IAAI,CAACV,MAAM,CAACS,gBAAgB,EAAE;QACnD,MAAME,KAAK,GAAG,IAAI,CAACX,MAAM,CAACY,MAAM,CAACF,QAAQ,CAAC;QAC1C,IAAIC,KAAK,EAAEE,IAAI,KAAK,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AAI,CAAC,IAAI,CAAC,IAAI;QACpD;MAEA,KAAK,QAAQ;QAAE;UACb,IAAI0E,YAAY,GAAG,YAAY;UAC/B,IAAIb,UAAU,CAACc,MAAM,CAACC,SAAS,IAAI,IAAI,EAAE;YACvCF,YAAY,IAAI,QAAQb,UAAU,CAACc,MAAM,CAACC,SAAS,GAAG;UACxD;UACA,IAAIf,UAAU,CAACc,MAAM,CAACE,SAAS,IAAI,IAAI,EAAE;YACvCH,YAAY,IAAI,QAAQb,UAAU,CAACc,MAAM,CAACE,SAAS,GAAG;UACxD;UACA,OAAOH,YAAY;QACrB;MAEA,KAAK,MAAM;QACT,OAAO,aAAa;MAEtB,KAAK,eAAe;QAClB,OAAO,aAAa;MAEtB,KAAK,QAAQ;MACb,KAAK,UAAU;MACf,KAAK,QAAQ;MACb,KAAK,SAAS;QACZ,OAAO,YAAY;MAAE;;MAEvB;QACE1G,WAAW,CAAC6F,UAAU,CAAC;IAC3B;EACF;AACF;AAEA,OAAO,eAAeiB,wBAAwBA,CAC5CzG,MAA+B,EAC/BC,OAA6B,EACZ;EACjB,MAAMyG,SAAS,GAAG,IAAI5G,kBAAkB,CAACE,MAAM,EAAEC,OAAO,CAAC;EACzD,OAAOyG,SAAS,CAACtG,aAAa,CAAC,CAAC;AAClC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"single-version.js","names":[],"sources":["single-version.ts"],"sourcesContent":["// ============================================================\n// versions.ts\n// ============================================================\n\n/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\nexport type SupportedVersions = 1;\nexport type LatestVersion = 1;\nexport type MinSupportedVersion = 1;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"three-version-chain.js","names":[],"sources":["three-version-chain.ts"],"sourcesContent":["// ============================================================\n// versions.ts\n// ============================================================\n\n/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\nexport type SupportedVersions = 1 | 2 | 3;\nexport type LatestVersion = 3;\nexport type MinSupportedVersion = 1;\n"],"mappings":"","ignoreList":[]}
|
package/build/esm/utils/schema/__tests__/__snapshots__/generateVersionsFromSchema/two-version.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"two-version.js","names":[],"sources":["two-version.ts"],"sourcesContent":["// ============================================================\n// versions.ts\n// ============================================================\n\n/* Generated by @palantir/pack.document-schema.type-gen@0.9.0 */\n\nexport type SupportedVersions = 1 | 2;\nexport type LatestVersion = 2;\nexport type MinSupportedVersion = 1;\n"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { defineRecord, defineSchema, defineSchemaUpdate, defineUnion, modelToRef, nextSchema } from "@palantir/pack.schema";
|
|
18
|
+
import * as P from "@palantir/pack.schema";
|
|
19
|
+
|
|
20
|
+
/** Single-version schema: ShapeBox with 5 fields */
|
|
21
|
+
const singleVersionModels = {
|
|
22
|
+
ShapeBox: defineRecord("ShapeBox", {
|
|
23
|
+
docs: "A box shape",
|
|
24
|
+
fields: {
|
|
25
|
+
left: P.Double,
|
|
26
|
+
right: P.Double,
|
|
27
|
+
top: P.Double,
|
|
28
|
+
bottom: P.Double,
|
|
29
|
+
color: P.Optional(P.String)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
};
|
|
33
|
+
const singleVersionSchemaNarrow = defineSchema(singleVersionModels);
|
|
34
|
+
export const singleVersionSchema = singleVersionSchemaNarrow;
|
|
35
|
+
|
|
36
|
+
/** Two-version schema with field removal (color removed, fillColor + strokeColor + opacity added) */
|
|
37
|
+
export const twoVersionFieldRemovalSchema = {
|
|
38
|
+
type: "versioned",
|
|
39
|
+
models: {
|
|
40
|
+
ShapeBox: defineRecord("ShapeBox", {
|
|
41
|
+
docs: "A box shape",
|
|
42
|
+
fields: {
|
|
43
|
+
left: P.Double,
|
|
44
|
+
right: P.Double,
|
|
45
|
+
top: P.Double,
|
|
46
|
+
bottom: P.Double,
|
|
47
|
+
fillColor: P.Optional(P.String),
|
|
48
|
+
strokeColor: P.Optional(P.String),
|
|
49
|
+
opacity: P.Optional(P.Double)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
version: 2,
|
|
54
|
+
previous: singleVersionSchema
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Two-version schema with additive change only (adds fillColor) */
|
|
58
|
+
const addFillColorUpdate = defineSchemaUpdate("addFillColor", schema => ({
|
|
59
|
+
ShapeBox: schema.ShapeBox.addField("fillColor", P.Optional(P.String)).build()
|
|
60
|
+
}));
|
|
61
|
+
export const twoVersionAdditiveSchema = nextSchema(singleVersionSchemaNarrow).addSchemaUpdate(addFillColorUpdate).build();
|
|
62
|
+
|
|
63
|
+
/** Schema with ref fields: tests import paths for record refs, DocumentRef, UserRef */
|
|
64
|
+
const CircleRecord = defineRecord("Circle", {
|
|
65
|
+
docs: "A circle",
|
|
66
|
+
fields: {
|
|
67
|
+
radius: P.Double
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
const DocRef = {
|
|
71
|
+
type: "docRef"
|
|
72
|
+
};
|
|
73
|
+
const UserRefField = {
|
|
74
|
+
type: "userRef"
|
|
75
|
+
};
|
|
76
|
+
export const refFieldsSchema = defineSchema({
|
|
77
|
+
Circle: CircleRecord,
|
|
78
|
+
Drawing: defineRecord("Drawing", {
|
|
79
|
+
docs: "A drawing with references",
|
|
80
|
+
fields: {
|
|
81
|
+
mainShape: CircleRecord,
|
|
82
|
+
extraShapes: P.Array(modelToRef(CircleRecord)),
|
|
83
|
+
background: P.Optional(modelToRef(CircleRecord)),
|
|
84
|
+
attachment: DocRef,
|
|
85
|
+
owner: P.Optional(UserRefField)
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/** Schema with union types: tests union variant interfaces, discriminated union, and type guards */
|
|
91
|
+
const RectangleRecord = defineRecord("Rectangle", {
|
|
92
|
+
docs: "A rectangle",
|
|
93
|
+
fields: {
|
|
94
|
+
width: P.Double,
|
|
95
|
+
height: P.Double
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
export const unionTypesSchema = defineSchema({
|
|
99
|
+
Circle: CircleRecord,
|
|
100
|
+
Rectangle: RectangleRecord,
|
|
101
|
+
Shape: defineUnion("Shape", {
|
|
102
|
+
docs: "A shape",
|
|
103
|
+
variants: {
|
|
104
|
+
circle: CircleRecord,
|
|
105
|
+
rectangle: RectangleRecord
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
/** Schema with nested optionals: tests that optional inside array/nested structures is preserved */
|
|
111
|
+
export const nestedOptionalsSchema = defineSchema({
|
|
112
|
+
Config: defineRecord("Config", {
|
|
113
|
+
docs: "A config with nested optional fields",
|
|
114
|
+
fields: {
|
|
115
|
+
tags: P.Array(P.Optional(P.String)),
|
|
116
|
+
matrix: P.Array(P.Array(P.Optional(P.Double))),
|
|
117
|
+
label: P.Optional(P.String),
|
|
118
|
+
// Sparse 3D point cloud: pages of rows where each row may omit coordinate triples
|
|
119
|
+
pointCloud: P.Array(P.Array(P.Optional(P.Array(P.Double))))
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/** Two-version schema with derived fields (color split into fillColor + strokeColor) */
|
|
125
|
+
export const twoVersionDerivedFieldsSchema = {
|
|
126
|
+
type: "versioned",
|
|
127
|
+
models: {
|
|
128
|
+
ShapeBox: defineRecord("ShapeBox", {
|
|
129
|
+
docs: "A box shape",
|
|
130
|
+
fields: {
|
|
131
|
+
left: P.Double,
|
|
132
|
+
right: P.Double,
|
|
133
|
+
top: P.Double,
|
|
134
|
+
bottom: P.Double,
|
|
135
|
+
fillColor: P.Optional(P.String),
|
|
136
|
+
strokeColor: P.Optional(P.String),
|
|
137
|
+
opacity: P.Optional(P.Double)
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
},
|
|
141
|
+
version: 2,
|
|
142
|
+
previous: singleVersionSchema,
|
|
143
|
+
migrations: {
|
|
144
|
+
ShapeBox: {
|
|
145
|
+
fillColor: {
|
|
146
|
+
derivedFrom: ["color"],
|
|
147
|
+
forward: ({
|
|
148
|
+
color
|
|
149
|
+
}) => color
|
|
150
|
+
},
|
|
151
|
+
strokeColor: {
|
|
152
|
+
derivedFrom: ["color"],
|
|
153
|
+
forward: ({
|
|
154
|
+
color
|
|
155
|
+
}) => color
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/** Three-version chain: Item (name, color -> name, hexColor -> name, hexColor, tags) */
|
|
162
|
+
export const threeVersionChainSchema = (() => {
|
|
163
|
+
const v1Models = {
|
|
164
|
+
Item: defineRecord("Item", {
|
|
165
|
+
docs: "",
|
|
166
|
+
fields: {
|
|
167
|
+
name: P.String,
|
|
168
|
+
color: P.Optional(P.String)
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
};
|
|
172
|
+
const v2Models = {
|
|
173
|
+
Item: defineRecord("Item", {
|
|
174
|
+
docs: "",
|
|
175
|
+
fields: {
|
|
176
|
+
name: P.String,
|
|
177
|
+
hexColor: P.Optional(P.String)
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
};
|
|
181
|
+
const v3Models = {
|
|
182
|
+
Item: defineRecord("Item", {
|
|
183
|
+
docs: "",
|
|
184
|
+
fields: {
|
|
185
|
+
name: P.String,
|
|
186
|
+
hexColor: P.Optional(P.String),
|
|
187
|
+
tags: P.Optional(P.String)
|
|
188
|
+
}
|
|
189
|
+
})
|
|
190
|
+
};
|
|
191
|
+
return {
|
|
192
|
+
type: "versioned",
|
|
193
|
+
models: v3Models,
|
|
194
|
+
version: 3,
|
|
195
|
+
previous: {
|
|
196
|
+
type: "versioned",
|
|
197
|
+
models: v2Models,
|
|
198
|
+
version: 2,
|
|
199
|
+
previous: {
|
|
200
|
+
type: "initial",
|
|
201
|
+
version: 1,
|
|
202
|
+
models: v1Models
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
})();
|
|
207
|
+
//# sourceMappingURL=fixtures.js.map
|
|
@@ -0,0 +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","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","matrix","label","pointCloud","twoVersionDerivedFieldsSchema","migrations","derivedFrom","forward","threeVersionChainSchema","v1Models","Item","name","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/** 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/nested 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 matrix: P.Array(P.Array(P.Optional(P.Double))),\n label: P.Optional(P.String),\n // Sparse 3D point cloud: pages of rows where each row may omit coordinate triples\n pointCloud: P.Array(P.Array(P.Optional(P.Array(P.Double)))),\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 forward: ({ color }: Record<string, unknown>) => color,\n },\n strokeColor: {\n derivedFrom: [\"color\"],\n forward: ({ color }: Record<string, unknown>) => color,\n },\n },\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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9C,OAAO,EAAE,CAAC;IACVC,QAAQ,EAAE;MACRN,IAAI,EAAE,WAAW;MACjBC,MAAM,EAAEgD,QAAQ;MAChB5C,OAAO,EAAE,CAAC;MACVC,QAAQ,EAAE;QAAEN,IAAI,EAAE,SAAS;QAAEK,OAAO,EAAE,CAAC;QAAEJ,MAAM,EAAE6C;MAAS;IAC5D;EACF,CAAC;AACH,CAAC,EAAE,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { describe, expect, it } from "vitest";
|
|
19
|
+
import { generateInternalFromSchema } from "../generateInternalFromSchema.js";
|
|
20
|
+
import { nestedOptionalsSchema, singleVersionSchema, twoVersionDerivedFieldsSchema, twoVersionFieldRemovalSchema } from "./fixtures.js";
|
|
21
|
+
import { formatInternalTypesSnapshot } from "./snapshotUtils.js";
|
|
22
|
+
describe("generateInternalFromSchema", () => {
|
|
23
|
+
const snapshotDir = path.join(__dirname, "__snapshots__", "generateInternalFromSchema");
|
|
24
|
+
it("single-version schema", async () => {
|
|
25
|
+
const result = generateInternalFromSchema(singleVersionSchema);
|
|
26
|
+
await expect(await formatInternalTypesSnapshot(result)).toMatchFileSnapshot(path.join(snapshotDir, "single-version.snap"));
|
|
27
|
+
});
|
|
28
|
+
it("nested optionals inside arrays", async () => {
|
|
29
|
+
const result = generateInternalFromSchema(nestedOptionalsSchema);
|
|
30
|
+
await expect(await formatInternalTypesSnapshot(result)).toMatchFileSnapshot(path.join(snapshotDir, "nested-optionals.snap"));
|
|
31
|
+
});
|
|
32
|
+
it("two-version field removal", async () => {
|
|
33
|
+
const result = generateInternalFromSchema(twoVersionFieldRemovalSchema);
|
|
34
|
+
await expect(await formatInternalTypesSnapshot(result)).toMatchFileSnapshot(path.join(snapshotDir, "two-version-field-removal.snap"));
|
|
35
|
+
});
|
|
36
|
+
it("two-version derived fields", async () => {
|
|
37
|
+
const result = generateInternalFromSchema(twoVersionDerivedFieldsSchema);
|
|
38
|
+
await expect(await formatInternalTypesSnapshot(result)).toMatchFileSnapshot(path.join(snapshotDir, "two-version-derived-fields.snap"));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=generateInternalFromSchema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateInternalFromSchema.test.js","names":["path","describe","expect","it","generateInternalFromSchema","nestedOptionalsSchema","singleVersionSchema","twoVersionDerivedFieldsSchema","twoVersionFieldRemovalSchema","formatInternalTypesSnapshot","snapshotDir","join","__dirname","result","toMatchFileSnapshot"],"sources":["generateInternalFromSchema.test.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"path\";\nimport { describe, expect, it } from \"vitest\";\nimport { generateInternalFromSchema } from \"../generateInternalFromSchema.js\";\nimport {\n nestedOptionalsSchema,\n singleVersionSchema,\n twoVersionDerivedFieldsSchema,\n twoVersionFieldRemovalSchema,\n} from \"./fixtures.js\";\nimport { formatInternalTypesSnapshot } from \"./snapshotUtils.js\";\n\ndescribe(\"generateInternalFromSchema\", () => {\n const snapshotDir = path.join(__dirname, \"__snapshots__\", \"generateInternalFromSchema\");\n\n it(\"single-version schema\", async () => {\n const result = generateInternalFromSchema(singleVersionSchema);\n await expect(await formatInternalTypesSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"single-version.snap\"),\n );\n });\n\n it(\"nested optionals inside arrays\", async () => {\n const result = generateInternalFromSchema(nestedOptionalsSchema);\n await expect(await formatInternalTypesSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"nested-optionals.snap\"),\n );\n });\n\n it(\"two-version field removal\", async () => {\n const result = generateInternalFromSchema(twoVersionFieldRemovalSchema);\n await expect(await formatInternalTypesSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"two-version-field-removal.snap\"),\n );\n });\n\n it(\"two-version derived fields\", async () => {\n const result = generateInternalFromSchema(twoVersionDerivedFieldsSchema);\n await expect(await formatInternalTypesSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"two-version-derived-fields.snap\"),\n );\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,0BAA0B,QAAQ,kCAAkC;AAC7E,SACEC,qBAAqB,EACrBC,mBAAmB,EACnBC,6BAA6B,EAC7BC,4BAA4B,QACvB,eAAe;AACtB,SAASC,2BAA2B,QAAQ,oBAAoB;AAEhER,QAAQ,CAAC,4BAA4B,EAAE,MAAM;EAC3C,MAAMS,WAAW,GAAGV,IAAI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
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { describe, expect, it } from "vitest";
|
|
19
|
+
import { generateModelMetadataFromSchema } from "../generateModelMetadataFromSchema.js";
|
|
20
|
+
import { singleVersionSchema, threeVersionChainSchema, twoVersionFieldRemovalSchema, unionTypesSchema } from "./fixtures.js";
|
|
21
|
+
import { formatModelMetadataSnapshot } from "./snapshotUtils.js";
|
|
22
|
+
describe("generateModelMetadataFromSchema", () => {
|
|
23
|
+
const snapshotDir = path.join(__dirname, "__snapshots__", "generateModelMetadataFromSchema");
|
|
24
|
+
it("single-version schema", async () => {
|
|
25
|
+
const result = generateModelMetadataFromSchema(singleVersionSchema);
|
|
26
|
+
await expect(await formatModelMetadataSnapshot(result)).toMatchFileSnapshot(path.join(snapshotDir, "single-version.snap"));
|
|
27
|
+
});
|
|
28
|
+
it("two-version field removal", async () => {
|
|
29
|
+
const result = generateModelMetadataFromSchema(twoVersionFieldRemovalSchema, 1);
|
|
30
|
+
await expect(await formatModelMetadataSnapshot(result)).toMatchFileSnapshot(path.join(snapshotDir, "two-version-field-removal.snap"));
|
|
31
|
+
});
|
|
32
|
+
it("three-version chain", async () => {
|
|
33
|
+
const result = generateModelMetadataFromSchema(threeVersionChainSchema, 1);
|
|
34
|
+
await expect(await formatModelMetadataSnapshot(result)).toMatchFileSnapshot(path.join(snapshotDir, "three-version-chain.snap"));
|
|
35
|
+
});
|
|
36
|
+
it("union types schema", async () => {
|
|
37
|
+
const result = generateModelMetadataFromSchema(unionTypesSchema);
|
|
38
|
+
await expect(await formatModelMetadataSnapshot(result)).toMatchFileSnapshot(path.join(snapshotDir, "union-types.snap"));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=generateModelMetadataFromSchema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateModelMetadataFromSchema.test.js","names":["path","describe","expect","it","generateModelMetadataFromSchema","singleVersionSchema","threeVersionChainSchema","twoVersionFieldRemovalSchema","unionTypesSchema","formatModelMetadataSnapshot","snapshotDir","join","__dirname","result","toMatchFileSnapshot"],"sources":["generateModelMetadataFromSchema.test.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"path\";\nimport { describe, expect, it } from \"vitest\";\nimport { generateModelMetadataFromSchema } from \"../generateModelMetadataFromSchema.js\";\nimport {\n singleVersionSchema,\n threeVersionChainSchema,\n twoVersionFieldRemovalSchema,\n unionTypesSchema,\n} from \"./fixtures.js\";\nimport { formatModelMetadataSnapshot } from \"./snapshotUtils.js\";\n\ndescribe(\"generateModelMetadataFromSchema\", () => {\n const snapshotDir = path.join(__dirname, \"__snapshots__\", \"generateModelMetadataFromSchema\");\n\n it(\"single-version schema\", async () => {\n const result = generateModelMetadataFromSchema(singleVersionSchema);\n await expect(await formatModelMetadataSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"single-version.snap\"),\n );\n });\n\n it(\"two-version field removal\", async () => {\n const result = generateModelMetadataFromSchema(twoVersionFieldRemovalSchema, 1);\n await expect(await formatModelMetadataSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"two-version-field-removal.snap\"),\n );\n });\n\n it(\"three-version chain\", async () => {\n const result = generateModelMetadataFromSchema(threeVersionChainSchema, 1);\n await expect(await formatModelMetadataSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"three-version-chain.snap\"),\n );\n });\n\n it(\"union types schema\", async () => {\n const result = generateModelMetadataFromSchema(unionTypesSchema);\n await expect(await formatModelMetadataSnapshot(result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"union-types.snap\"),\n );\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,+BAA+B,QAAQ,uCAAuC;AACvF,SACEC,mBAAmB,EACnBC,uBAAuB,EACvBC,4BAA4B,EAC5BC,gBAAgB,QACX,eAAe;AACtB,SAASC,2BAA2B,QAAQ,oBAAoB;AAEhER,QAAQ,CAAC,iCAAiC,EAAE,MAAM;EAChD,MAAMS,WAAW,GAAGV,IAAI,CAACW,IAAI,CAACC,SAAS,EAAE,eAAe,EAAE,iCAAiC,CAAC;EAE5FT,EAAE,CAAC,uBAAuB,EAAE,YAAY;IACtC,MAAMU,MAAM,GAAGT,+BAA+B,CAACC,mBAAmB,CAAC;IACnE,MAAMH,MAAM,CAAC,MAAMO,2BAA2B,CAACI,MAAM,CAAC,CAAC,CAACC,mBAAmB,CACzEd,IAAI,CAACW,IAAI,CAACD,WAAW,EAAE,qBAAqB,CAC9C,CAAC;EACH,CAAC,CAAC;EAEFP,EAAE,CAAC,2BAA2B,EAAE,YAAY;IAC1C,MAAMU,MAAM,GAAGT,+BAA+B,CAACG,4BAA4B,EAAE,CAAC,CAAC;IAC/E,MAAML,MAAM,CAAC,MAAMO,2BAA2B,CAACI,MAAM,CAAC,CAAC,CAACC,mBAAmB,CACzEd,IAAI,CAACW,IAAI,CAACD,WAAW,EAAE,gCAAgC,CACzD,CAAC;EACH,CAAC,CAAC;EAEFP,EAAE,CAAC,qBAAqB,EAAE,YAAY;IACpC,MAAMU,MAAM,GAAGT,+BAA+B,CAACE,uBAAuB,EAAE,CAAC,CAAC;IAC1E,MAAMJ,MAAM,CAAC,MAAMO,2BAA2B,CAACI,MAAM,CAAC,CAAC,CAACC,mBAAmB,CACzEd,IAAI,CAACW,IAAI,CAACD,WAAW,EAAE,0BAA0B,CACnD,CAAC;EACH,CAAC,CAAC;EAEFP,EAAE,CAAC,oBAAoB,EAAE,YAAY;IACnC,MAAMU,MAAM,GAAGT,+BAA+B,CAACI,gBAAgB,CAAC;IAChE,MAAMN,MAAM,CAAC,MAAMO,2BAA2B,CAACI,MAAM,CAAC,CAAC,CAACC,mBAAmB,CACzEd,IAAI,CAACW,IAAI,CAACD,WAAW,EAAE,kBAAkB,CAC3C,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { describe, expect, it } from "vitest";
|
|
19
|
+
import { generateScopeFromSchema } from "../generateScopeFromSchema.js";
|
|
20
|
+
import { singleVersionSchema, twoVersionFieldRemovalSchema, unionTypesSchema } from "./fixtures.js";
|
|
21
|
+
import { formatSingleSnapshot } from "./snapshotUtils.js";
|
|
22
|
+
describe("generateScopeFromSchema", () => {
|
|
23
|
+
const snapshotDir = path.join(__dirname, "__snapshots__", "generateScopeFromSchema");
|
|
24
|
+
it("single-version schema", async () => {
|
|
25
|
+
const result = generateScopeFromSchema(singleVersionSchema);
|
|
26
|
+
await expect(await formatSingleSnapshot("versionedDocRef.ts", result)).toMatchFileSnapshot(path.join(snapshotDir, "single-version.snap"));
|
|
27
|
+
});
|
|
28
|
+
it("two-version field removal", async () => {
|
|
29
|
+
const result = generateScopeFromSchema(twoVersionFieldRemovalSchema, 1);
|
|
30
|
+
await expect(await formatSingleSnapshot("versionedDocRef.ts", result)).toMatchFileSnapshot(path.join(snapshotDir, "two-version-field-removal.snap"));
|
|
31
|
+
});
|
|
32
|
+
it("union types schema", async () => {
|
|
33
|
+
const result = generateScopeFromSchema(unionTypesSchema);
|
|
34
|
+
await expect(await formatSingleSnapshot("versionedDocRef.ts", result)).toMatchFileSnapshot(path.join(snapshotDir, "union-types.snap"));
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=generateScopeFromSchema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateScopeFromSchema.test.js","names":["path","describe","expect","it","generateScopeFromSchema","singleVersionSchema","twoVersionFieldRemovalSchema","unionTypesSchema","formatSingleSnapshot","snapshotDir","join","__dirname","result","toMatchFileSnapshot"],"sources":["generateScopeFromSchema.test.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"path\";\nimport { describe, expect, it } from \"vitest\";\nimport { generateScopeFromSchema } from \"../generateScopeFromSchema.js\";\nimport { singleVersionSchema, twoVersionFieldRemovalSchema, unionTypesSchema } from \"./fixtures.js\";\nimport { formatSingleSnapshot } from \"./snapshotUtils.js\";\n\ndescribe(\"generateScopeFromSchema\", () => {\n const snapshotDir = path.join(__dirname, \"__snapshots__\", \"generateScopeFromSchema\");\n\n it(\"single-version schema\", async () => {\n const result = generateScopeFromSchema(singleVersionSchema);\n await expect(await formatSingleSnapshot(\"versionedDocRef.ts\", result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"single-version.snap\"),\n );\n });\n\n it(\"two-version field removal\", async () => {\n const result = generateScopeFromSchema(twoVersionFieldRemovalSchema, 1);\n await expect(await formatSingleSnapshot(\"versionedDocRef.ts\", result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"two-version-field-removal.snap\"),\n );\n });\n\n it(\"union types schema\", async () => {\n const result = generateScopeFromSchema(unionTypesSchema);\n await expect(await formatSingleSnapshot(\"versionedDocRef.ts\", result)).toMatchFileSnapshot(\n path.join(snapshotDir, \"union-types.snap\"),\n );\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAASC,mBAAmB,EAAEC,4BAA4B,EAAEC,gBAAgB,QAAQ,eAAe;AACnG,SAASC,oBAAoB,QAAQ,oBAA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