@palantir/pack.schema 0.5.0 → 0.6.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/.turbo/turbo-lint.log +7 -4
- package/.turbo/turbo-transpileBrowser.log +1 -1
- package/.turbo/turbo-transpileCjs.log +1 -1
- package/.turbo/turbo-transpileEsm.log +1 -1
- package/.turbo/turbo-transpileTypes.log +1 -1
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +6 -0
- package/build/browser/index.js +142 -15
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +143 -15
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +52 -3
- package/build/esm/index.js +142 -15
- package/build/esm/index.js.map +1 -1
- package/build/types/__tests__/addFieldOptions.test.d.ts +1 -0
- package/build/types/__tests__/addFieldOptions.test.d.ts.map +1 -0
- package/build/types/defineMigration.d.ts +55 -1
- package/build/types/defineMigration.d.ts.map +1 -1
- package/build/types/defineSchemaUpdate.d.ts +0 -1
- package/build/types/defineSchemaUpdate.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/addFieldOptions.test.ts +577 -0
- package/src/defineMigration.ts +220 -22
- package/src/defineSchemaUpdate.ts +66 -5
package/build/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.ts","../../src/defineSchemaUpdate.ts"],"names":[],"mappings":";;;AAgBO,IAAM,YAAA,GAAe;AAAA,EAC1B,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO;AACT;;;ACHO,IAAM,QAAA,GAAW;AAAA,EACtB,KAAA,EAAO,OAAA;AAAA,EACP,OAAA,EAAS,SAAA;AAAA,EACT,OAAA,EAAS,QAAA;AAAA,EACT,MAAA,EAAQ,QAAA;AAAA,EACR,SAAA,EAAW,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AO,IAAI,0BAAyB,MAAA,EAAQ,IAAA,CAAK,SAAS,IAAA,CAAK,QAAA,EAAU,KAAK,WAAW,CAAA;AAAA,EAC3F;AAAA,EACA,eAAe,UAAA,EAAY;AACzB,IAAA,OAAO,IAAI,0BAAyB,IAAA,CAAK,MAAA,EAAQ,KAAK,OAAA,EAAS,IAAA,CAAK,UAAU,UAAU,CAAA;AAAA,EAC1F;AAAA,EACA,KAAA,GAAQ;AACN,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,WAAA;AAAA,MACN,MAAA,EAAQ;AAAA,QACN,GAAG,IAAA,CAAK;AAAA,OACV;AAAA,MACA,SAAS,IAAA,CAAK,OAAA;AAAA,MACd,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,GAAI,IAAA,CAAK,WAAA,IAAe,IAAA,GAAO;AAAA,QAC7B,YAAY,IAAA,CAAK;AAAA,UACf;AAAC,KACP;AAAA,EACF;AACF,CAAA;AACO,SAAS,WAAW,QAAA,EAAU;AACnC,EAAA,OAAO,IAAI,wBAAA,CAAyB,QAAA,CAAS,QAAQ,QAAA,CAAS,OAAA,GAAU,GAAG,QAAQ,CAAA;AACrF","file":"index.cjs","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\nexport const ModelDefType = {\n RECORD: \"record\",\n UNION: \"union\"\n};","/*\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\nexport const TypeKind = {\n ARRAY: \"array\",\n BOOLEAN: \"boolean\",\n DOC_REF: \"docRef\",\n DOUBLE: \"double\",\n MEDIA_REF: \"mediaRef\",\n OBJECT_REF: \"objectRef\",\n OPTIONAL: \"optional\",\n REF: \"ref\",\n STRING: \"string\",\n UNKNOWN: \"unknown\",\n USER_REF: \"userRef\"\n};\n\n// Forward declaration to avoid circular reference\n\n// A reference to a record or a union type\n\nexport const String = {\n type: TypeKind.STRING\n};\nexport const Double = {\n type: TypeKind.DOUBLE\n};\nexport const Boolean = {\n type: TypeKind.BOOLEAN\n};\nexport const Unknown = {\n type: TypeKind.UNKNOWN\n};\nfunction unwrapOneOptional(t) {\n return t.type === TypeKind.OPTIONAL && \"item\" in t ? t.item : t;\n}\nexport const Array = item => {\n if (unwrapOneOptional(item).type === TypeKind.ARRAY) {\n throw new Error(\"Nested arrays (Array(Array(...)) or Array(Optional(Array(...)))) are not supported. \" + \"Wrap the inner array in a record instead.\");\n }\n return {\n type: TypeKind.ARRAY,\n items: item\n };\n};\nexport const Optional = item => {\n if (item.type === TypeKind.OPTIONAL) {\n throw new Error(\"Nested optionals (Optional(Optional(...))) are not supported.\");\n }\n return {\n type: TypeKind.OPTIONAL,\n item\n };\n};","/*\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 { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\n\n/**\n * Helper function to safely transform a record definition to a reference.\n * This function helps TypeScript track type transformations better.\n */\nexport function modelToRef(model) {\n return createRef(model.name, model.type);\n}\n\n/**\n * Helper function to create a reference with proper typing.\n * This avoids type assertions in multiple places.\n */\nexport function createRef(name, refType) {\n return {\n type: TypeKind.REF,\n name,\n refType\n };\n}\n\n/**\n * Type guard to check if a value is a RecordDef\n */\nexport function isRecordDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.RECORD && \"fields\" in value;\n}\n\n/**\n * Type guard to check if a value is a UnionDef\n */\nexport function isUnionDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.UNION && \"variants\" in value;\n}","/*\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 { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\nimport { modelToRef } from \"./utils.js\";\nexport function defineUnion(name, {\n discriminant = \"type\",\n docs,\n variants\n}) {\n const entries = Object.entries(variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);\n const resolvedVariants = Object.fromEntries(entries);\n return {\n type: ModelDefType.UNION,\n discriminant,\n name,\n docs,\n variants: resolvedVariants\n };\n}\nexport function resolveUnionVariantArg(arg) {\n const resolved = typeof arg === \"function\" ? arg() : arg;\n return resolved.type === TypeKind.REF ? resolved : modelToRef(resolved);\n}","/*\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 { resolveUnionVariantArg } from \"./defineUnion.js\";\nimport { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef } from \"./utils.js\";\n\n/** Soon to be deprecated - Use `ModelDefs` instead. */\n\n/** Soon to be deprecated - use `ModelDefs` instead. */\n\nclass UnionBuilderImpl {\n name;\n docs;\n variants;\n constructor({\n name,\n docs,\n variants\n }) {\n this.name = name;\n this.docs = docs;\n this.variants = {\n ...variants\n };\n }\n addVariant(variantName, modelDefOrRef) {\n const ref = resolveUnionVariantArg(modelDefOrRef);\n const newVariants = {\n ...this.variants,\n [variantName]: ref\n };\n return new UnionBuilderImpl({\n type: ModelDefType.UNION,\n name: this.name,\n variants: newVariants,\n discriminant: \"type\"\n });\n }\n build() {\n return {\n type: ModelDefType.UNION,\n variants: this.variants,\n discriminant: \"type\",\n name: this.name\n };\n }\n}\nclass RecordBuilderImpl {\n name;\n fields;\n constructor(initialRecordDef) {\n this.name = initialRecordDef.name;\n this.fields = {\n ...initialRecordDef.fields\n };\n }\n\n // TODO: resolve field value from arg instead\n addField(name, value) {\n return new RecordBuilderImpl({\n type: ModelDefType.RECORD,\n name: this.name,\n fields: {\n ...this.fields,\n [name]: value\n },\n docs: \"\"\n });\n }\n build() {\n return {\n type: ModelDefType.RECORD,\n name: this.name,\n fields: this.fields,\n docs: \"\"\n };\n }\n}\nexport function defineMigration(models, migration) {\n const builders = {};\n for (const key in models) {\n const v = models[key];\n if (isRecordDef(v)) {\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...models,\n ...migration(builders)\n };\n}","/*\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 { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef, modelToRef } from \"./utils.js\";\n/**\n * Helper function to resolve a field value, handling functions and transforming\n * types as needed.\n */\nfunction resolveFieldArg(value) {\n // Handle function values\n const resolved = typeof value === \"function\" ? value() : value;\n if (isRecordDef(resolved) || isUnionDef(resolved)) {\n return modelToRef(resolved);\n }\n\n // For primitive types and other Types\n return resolved;\n}\nexport function defineRecord(name, record) {\n const entries = Object.entries(record.fields).map(([key, value]) => [key, resolveFieldArg(value)]);\n const fields = Object.fromEntries(entries);\n return {\n type: ModelDefType.RECORD,\n name: name,\n docs: record.docs,\n fields\n };\n}","/*\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 { defineMigration } from \"./defineMigration.js\";\nexport function defineSchema(models) {\n return {\n type: \"initial\",\n version: 1,\n models\n };\n}\nexport function defineSchemaUpdate(name, migration) {\n return {\n name,\n migration\n };\n}\nclass SchemaVersionBuilderImpl {\n models;\n version;\n previous;\n _migrations;\n constructor(models, version, previous, migrations) {\n this.models = models;\n this.version = version;\n this.previous = previous;\n this._migrations = migrations;\n }\n addSchemaUpdate(update) {\n const merged = defineMigration(this.models, update.migration);\n return new SchemaVersionBuilderImpl(merged, this.version, this.previous, this._migrations);\n }\n withMigrations(migrations) {\n return new SchemaVersionBuilderImpl(this.models, this.version, this.previous, migrations);\n }\n build() {\n return {\n type: \"versioned\",\n models: {\n ...this.models\n },\n version: this.version,\n previous: this.previous,\n ...(this._migrations != null ? {\n migrations: this._migrations\n } : {})\n };\n }\n}\nexport function nextSchema(previous) {\n return new SchemaVersionBuilderImpl(previous.models, previous.version + 1, previous);\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.ts","../../src/defineSchemaUpdate.ts"],"names":["Array"],"mappings":";;;AAgBO,IAAM,YAAA,GAAe;AAAA,EAC1B,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO;AACT;;;ACHO,IAAM,QAAA,GAAW;AAAA,EACtB,KAAA,EAAO,OAAA;AAAA,EACP,OAAA,EAAS,SAAA;AAAA,EACT,OAAA,EAAS,QAAA;AAAA,EACT,MAAA,EAAQ,QAAA;AAAA,EACR,SAAA,EAAW,UAAA;AAAA,EACX,UAAA,EAAY,WAAA;AAAA,EACZ,QAAA,EAAU,UAAA;AAAA,EACV,GAAA,EAAK,KAAA;AAAA,EACL,MAAA,EAAQ,QAAA;AAAA,EACR,OAAA,EAAS,SAAA;AAAA,EACT,QAAA,EAAU;AACZ;AAMO,IAAM,MAAA,GAAS;AAAA,EACpB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,MAAA,GAAS;AAAA,EACpB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,OAAA,GAAU;AAAA,EACrB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,OAAA,GAAU;AAAA,EACrB,MAAM,QAAA,CAAS;AACj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A,MAAM,MAAA,GAAS,eAAA,CAAgB,MAAA,EAAQ,MAAM,CAAA;AAC7C,IAAA,OAAO,IAAI,yBAAA,CAAyB,MAAA,EAAQ,KAAK,OAAA,EAAS,IAAA,CAAK,UAAU,MAAM,CAAA;AAAA,EACjF;AAAA,EACA,eAAe,UAAA,EAAY;AACzB,IAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,IAAA,CAAK,WAAA,EAAa,UAAU,CAAA;AAC3D,IAAA,MAAM,MAAA,GAAS,eAAA,CAAgB,MAAA,EAAQ,IAAA,CAAK,MAAM,CAAA;AAClD,IAAA,OAAO,IAAI,0BAAyB,IAAA,CAAK,MAAA,EAAQ,KAAK,OAAA,EAAS,IAAA,CAAK,UAAU,MAAM,CAAA;AAAA,EACtF;AAAA,EACA,KAAA,GAAQ;AACN,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,WAAA;AAAA,MACN,MAAA,EAAQ;AAAA,QACN,GAAG,IAAA,CAAK;AAAA,OACV;AAAA,MACA,SAAS,IAAA,CAAK,OAAA;AAAA,MACd,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,GAAI,IAAA,CAAK,WAAA,IAAe,IAAA,GAAO;AAAA,QAC7B,YAAY,IAAA,CAAK;AAAA,UACf;AAAC,KACP;AAAA,EACF;AACF,CAAA;AACO,SAAS,WAAW,QAAA,EAAU;AACnC,EAAA,OAAO,IAAI,wBAAA,CAAyB,QAAA,CAAS,QAAQ,QAAA,CAAS,OAAA,GAAU,GAAG,QAAQ,CAAA;AACrF","file":"index.cjs","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\nexport const ModelDefType = {\n RECORD: \"record\",\n UNION: \"union\"\n};","/*\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\nexport const TypeKind = {\n ARRAY: \"array\",\n BOOLEAN: \"boolean\",\n DOC_REF: \"docRef\",\n DOUBLE: \"double\",\n MEDIA_REF: \"mediaRef\",\n OBJECT_REF: \"objectRef\",\n OPTIONAL: \"optional\",\n REF: \"ref\",\n STRING: \"string\",\n UNKNOWN: \"unknown\",\n USER_REF: \"userRef\"\n};\n\n// Forward declaration to avoid circular reference\n\n// A reference to a record or a union type\n\nexport const String = {\n type: TypeKind.STRING\n};\nexport const Double = {\n type: TypeKind.DOUBLE\n};\nexport const Boolean = {\n type: TypeKind.BOOLEAN\n};\nexport const Unknown = {\n type: TypeKind.UNKNOWN\n};\nfunction unwrapOneOptional(t) {\n return t.type === TypeKind.OPTIONAL && \"item\" in t ? t.item : t;\n}\nexport const Array = item => {\n if (unwrapOneOptional(item).type === TypeKind.ARRAY) {\n throw new Error(\"Nested arrays (Array(Array(...)) or Array(Optional(Array(...)))) are not supported. \" + \"Wrap the inner array in a record instead.\");\n }\n return {\n type: TypeKind.ARRAY,\n items: item\n };\n};\nexport const Optional = item => {\n if (item.type === TypeKind.OPTIONAL) {\n throw new Error(\"Nested optionals (Optional(Optional(...))) are not supported.\");\n }\n return {\n type: TypeKind.OPTIONAL,\n item\n };\n};","/*\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 { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\n\n/**\n * Helper function to safely transform a record definition to a reference.\n * This function helps TypeScript track type transformations better.\n */\nexport function modelToRef(model) {\n return createRef(model.name, model.type);\n}\n\n/**\n * Helper function to create a reference with proper typing.\n * This avoids type assertions in multiple places.\n */\nexport function createRef(name, refType) {\n return {\n type: TypeKind.REF,\n name,\n refType\n };\n}\n\n/**\n * Type guard to check if a value is a RecordDef\n */\nexport function isRecordDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.RECORD && \"fields\" in value;\n}\n\n/**\n * Type guard to check if a value is a UnionDef\n */\nexport function isUnionDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.UNION && \"variants\" in value;\n}","/*\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 { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\nimport { modelToRef } from \"./utils.js\";\nexport function defineUnion(name, {\n discriminant = \"type\",\n docs,\n variants\n}) {\n const entries = Object.entries(variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);\n const resolvedVariants = Object.fromEntries(entries);\n return {\n type: ModelDefType.UNION,\n discriminant,\n name,\n docs,\n variants: resolvedVariants\n };\n}\nexport function resolveUnionVariantArg(arg) {\n const resolved = typeof arg === \"function\" ? arg() : arg;\n return resolved.type === TypeKind.REF ? resolved : modelToRef(resolved);\n}","/*\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 { resolveUnionVariantArg } from \"./defineUnion.js\";\nimport { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef } from \"./utils.js\";\n\n/** Soon to be deprecated - Use `ModelDefs` instead. */\n\n/** Soon to be deprecated - use `ModelDefs` instead. */\n\n/**\n * Recursive literal-JSON type. Constrains schema-time `default` values to\n * data that JSON-serializes losslessly — no `Date`, `RegExp`, functions, class\n * instances, or `undefined`. Mirrors the `JsonValue` exported by\n * `@palantir/pack.document-schema.model-types`; kept local here to avoid a\n * package dependency from `pack.schema`.\n */\n\n/**\n * Upgrade options for a field whose value is derived from prior-version fields.\n * Supplied as the third argument to `addField`; surfaced by `applyMigration`\n * as part of `MigrationResult.upgrades`. Declares the structural dependency\n * (`derivedFrom`) and an optional literal JSON `default` used when no source\n * data exists. The runtime forward function is supplied separately via the\n * generated `DocumentModel(...)` factory's `UpgradeFns` parameter.\n */\n\n/**\n * Options for a purely additive field. `default` is literal JSON only;\n * validated at `addField()` call time.\n */\n\n/**\n * Recursively assert `value` is representable as literal JSON. Rejects `Date`,\n * `RegExp`, functions, class instances, symbol-keyed properties, `undefined`\n * (anywhere — top-level or nested), `symbol`, and `bigint`. Throws on the\n * first offending value, naming the path for debuggability.\n */\nfunction assertJsonDefault(value, path) {\n // eslint-disable-next-line eqeqeq -- need to distinguish null (valid JSON) from undefined (not).\n if (value === null) return;\n const t = typeof value;\n if (t === \"undefined\") {\n throw new Error(`Invalid JSON default at ${path}: undefined is not valid JSON`);\n }\n if (t === \"string\" || t === \"number\" || t === \"boolean\") return;\n if (t === \"function\" || t === \"symbol\" || t === \"bigint\") {\n throw new Error(`Invalid JSON default at ${path}: ${t} is not valid JSON`);\n }\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n assertJsonDefault(value[i], `${path}[${i}]`);\n }\n return;\n }\n const proto = Object.getPrototypeOf(value);\n if (proto !== Object.prototype && proto != null) {\n const ctorName = value.constructor?.name ?? \"non-plain object\";\n throw new Error(`Invalid JSON default at ${path}: ${ctorName} is not valid JSON`);\n }\n if (Object.getOwnPropertySymbols(value).length > 0) {\n throw new Error(`Invalid JSON default at ${path}: symbol-keyed properties are not valid JSON`);\n }\n for (const [k, v] of Object.entries(value)) {\n assertJsonDefault(v, `${path}.${k}`);\n }\n}\nclass UnionBuilderImpl {\n name;\n docs;\n variants;\n constructor({\n name,\n docs,\n variants\n }) {\n this.name = name;\n this.docs = docs;\n this.variants = {\n ...variants\n };\n }\n addVariant(variantName, modelDefOrRef) {\n const ref = resolveUnionVariantArg(modelDefOrRef);\n const newVariants = {\n ...this.variants,\n [variantName]: ref\n };\n return new UnionBuilderImpl({\n type: ModelDefType.UNION,\n name: this.name,\n variants: newVariants,\n discriminant: \"type\"\n });\n }\n build() {\n return {\n type: ModelDefType.UNION,\n variants: this.variants,\n discriminant: \"type\",\n name: this.name\n };\n }\n}\n\n/**\n * Non-enumerable carrier property attached to a `RecordDef` by\n * `RecordBuilderImpl.build()` when the builder has collected one or more\n * `FieldOptions`. `applyMigration` reads this and then deletes the property,\n * so the `RecordDef` it returns is structurally clean (no extra keys, no\n * symbol-keyed metadata).\n */\nconst UPGRADE_OPTIONS_CARRIER = \"__pack_upgrade_options__\";\nclass RecordBuilderImpl {\n name;\n fields;\n upgradeOptions;\n constructor(initialRecordDef, upgradeOptions) {\n this.name = initialRecordDef.name;\n this.fields = {\n ...initialRecordDef.fields\n };\n // Upgrade options only flow forward within a single migration callback —\n // they are NOT inherited from the prior version's RecordDef, because each\n // version's upgrades describe a specific version transition.\n this.upgradeOptions = new Map(upgradeOptions ?? []);\n }\n\n // TODO: resolve field value from arg instead\n addField(name, value, options) {\n if (options != null && \"default\" in options && options.default !== undefined) {\n assertJsonDefault(options.default, `addField(\"${name}\").default`);\n }\n const next = new Map(this.upgradeOptions);\n if (options != null) {\n next.set(name, options);\n }\n return new RecordBuilderImpl({\n type: ModelDefType.RECORD,\n name: this.name,\n fields: {\n ...this.fields,\n [name]: value\n },\n docs: \"\"\n }, next);\n }\n removeField(name) {\n const {\n [name]: _removed,\n ...rest\n } = this.fields;\n const next = new Map(this.upgradeOptions);\n next.delete(name);\n return new RecordBuilderImpl({\n type: ModelDefType.RECORD,\n name: this.name,\n fields: rest,\n docs: \"\"\n }, next);\n }\n build() {\n const result = {\n type: ModelDefType.RECORD,\n name: this.name,\n fields: this.fields,\n docs: \"\"\n };\n if (this.upgradeOptions.size > 0) {\n Object.defineProperty(result, UPGRADE_OPTIONS_CARRIER, {\n value: this.upgradeOptions,\n enumerable: false,\n configurable: true,\n writable: false\n });\n }\n return result;\n }\n}\nfunction makeBuilders(models) {\n const builders = {};\n for (const key in models) {\n const v = models[key];\n if (isRecordDef(v)) {\n builders[key] = new RecordBuilderImpl(v);\n } else if (isUnionDef(v)) {\n builders[key] = new UnionBuilderImpl(v);\n }\n }\n return builders;\n}\n\n/** Per-model field migrations: `[modelKey][fieldName]` → upgrade options. */\n\n/**\n * Lower-level entry point that returns both the merged models AND any\n * `UpgradeFieldOptions` collected via `addField(name, type, options)` during\n * the migration callback. Used by `addSchemaUpdate` to fold sugar-form\n * upgrades into a `VersionedSchema`'s migrations map.\n *\n * Each `RecordBuilderImpl.build()` attaches its collected options to the\n * produced `RecordDef` via a non-enumerable carrier property; this function\n * walks the merged result, extracts the options keyed by the user's chosen\n * output key (so renames are handled), and strips the carrier so the returned\n * `RecordDef`s are structurally clean.\n */\nexport function applyMigration(models, migration) {\n const builders = makeBuilders(models);\n const merged = {\n ...models,\n ...migration(builders)\n };\n const upgrades = {};\n for (const [modelKey, def] of Object.entries(merged)) {\n if (!isRecordDef(def)) continue;\n const carrier = def;\n const opts = carrier[UPGRADE_OPTIONS_CARRIER];\n if (opts == null) continue;\n // Strip the carrier so the returned RecordDef is structurally clean.\n delete carrier[UPGRADE_OPTIONS_CARRIER];\n const fieldEntries = {};\n for (const [fieldName, options] of opts) {\n // Only `UpgradeFieldOptions` (which declare `derivedFrom`) flow into the\n // upgrades map; `AdditiveFieldOptions` carry only a literal `default`\n // and have no read-time lens effect.\n if (\"derivedFrom\" in options) {\n fieldEntries[fieldName] = options;\n }\n }\n if (Object.keys(fieldEntries).length > 0) {\n upgrades[modelKey] = fieldEntries;\n }\n }\n return {\n models: merged,\n upgrades: Object.keys(upgrades).length > 0 ? upgrades : undefined\n };\n}\nexport function defineMigration(models, migration) {\n return applyMigration(models, migration).models;\n}","/*\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 { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef, modelToRef } from \"./utils.js\";\n/**\n * Helper function to resolve a field value, handling functions and transforming\n * types as needed.\n */\nfunction resolveFieldArg(value) {\n // Handle function values\n const resolved = typeof value === \"function\" ? value() : value;\n if (isRecordDef(resolved) || isUnionDef(resolved)) {\n return modelToRef(resolved);\n }\n\n // For primitive types and other Types\n return resolved;\n}\nexport function defineRecord(name, record) {\n const entries = Object.entries(record.fields).map(([key, value]) => [key, resolveFieldArg(value)]);\n const fields = Object.fromEntries(entries);\n return {\n type: ModelDefType.RECORD,\n name: name,\n docs: record.docs,\n fields\n };\n}","/*\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 { applyMigration } from \"./defineMigration.js\";\nexport function defineSchema(models) {\n return {\n type: \"initial\",\n version: 1,\n models\n };\n}\nexport function defineSchemaUpdate(name, migration) {\n return {\n name,\n migration\n };\n}\n/**\n * Merge two `VersionMigrations` records. Per-model field migrations from\n * `override` take precedence over `base` for the same field, but the maps are\n * combined at both the model and field level so explicit `withMigrations`\n * calls can supplement (not just replace) the sugar from `addField` options.\n */\nfunction mergeMigrations(base, override) {\n if (base == null) return override;\n if (override == null) return base;\n const result = {\n ...base\n };\n for (const [modelKey, fields] of Object.entries(override)) {\n result[modelKey] = {\n ...result[modelKey],\n ...fields\n };\n }\n return result;\n}\n\n/**\n * Drop migration entries that no longer correspond to a field on a record in\n * `models`. Required because `mergeMigrations` is monotonic — a later\n * `addSchemaUpdate` that removes or retypes a field would otherwise leave a\n * stale entry in the accumulator. Entries are dropped when:\n * - the model key is no longer present,\n * - the model is no longer a record (e.g. replaced by a union), or\n * - the field name is no longer one of the record's fields.\n */\nfunction pruneMigrations(migrations, models) {\n if (migrations == null) return undefined;\n const result = {};\n for (const [modelKey, fields] of Object.entries(migrations)) {\n const def = models[modelKey];\n if (def == null || def.type !== \"record\") continue;\n const recordFields = def.fields;\n const kept = {};\n for (const [fieldName, migration] of Object.entries(fields)) {\n if (fieldName in recordFields) {\n kept[fieldName] = migration;\n }\n }\n if (Object.keys(kept).length > 0) {\n result[modelKey] = kept;\n }\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\nclass SchemaVersionBuilderImpl {\n models;\n version;\n previous;\n _migrations;\n constructor(models, version, previous, migrations) {\n this.models = models;\n this.version = version;\n this.previous = previous;\n this._migrations = migrations;\n }\n addSchemaUpdate(update) {\n // applyMigration returns both the merged models and any sugar-form\n // upgrades collected via `addField(name, type, { derivedFrom, forward })`.\n const {\n models,\n upgrades\n } = applyMigration(this.models, update.migration);\n const merged = mergeMigrations(this._migrations, upgrades);\n // Reconcile against the new models: a later update that removes or\n // retypes a field must drop the prior step's stale migration entry.\n const pruned = pruneMigrations(merged, models);\n return new SchemaVersionBuilderImpl(models, this.version, this.previous, pruned);\n }\n withMigrations(migrations) {\n const merged = mergeMigrations(this._migrations, migrations);\n const pruned = pruneMigrations(merged, this.models);\n return new SchemaVersionBuilderImpl(this.models, this.version, this.previous, pruned);\n }\n build() {\n return {\n type: \"versioned\",\n models: {\n ...this.models\n },\n version: this.version,\n previous: this.previous,\n ...(this._migrations != null ? {\n migrations: this._migrations\n } : {})\n };\n }\n}\nexport function nextSchema(previous) {\n return new SchemaVersionBuilderImpl(previous.models, previous.version + 1, previous);\n}"]}
|
package/build/cjs/index.d.cts
CHANGED
|
@@ -110,10 +110,41 @@ type Schema<T extends ModelDefs> = T;
|
|
|
110
110
|
type SchemaBuilder<T extends ModelDefs> = {
|
|
111
111
|
[k in keyof T]: T[k] extends UnionDef<infer R> ? UnionBuilder<R> : T[k] extends RecordDef<infer R> ? RecordBuilder<R> : never;
|
|
112
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* Recursive literal-JSON type. Constrains schema-time `default` values to
|
|
115
|
+
* data that JSON-serializes losslessly — no `Date`, `RegExp`, functions, class
|
|
116
|
+
* instances, or `undefined`. Mirrors the `JsonValue` exported by
|
|
117
|
+
* `@palantir/pack.document-schema.model-types`; kept local here to avoid a
|
|
118
|
+
* package dependency from `pack.schema`.
|
|
119
|
+
*/
|
|
120
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
121
|
+
[key: string]: JsonValue;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Upgrade options for a field whose value is derived from prior-version fields.
|
|
125
|
+
* Supplied as the third argument to `addField`; surfaced by `applyMigration`
|
|
126
|
+
* as part of `MigrationResult.upgrades`. Declares the structural dependency
|
|
127
|
+
* (`derivedFrom`) and an optional literal JSON `default` used when no source
|
|
128
|
+
* data exists. The runtime forward function is supplied separately via the
|
|
129
|
+
* generated `DocumentModel(...)` factory's `UpgradeFns` parameter.
|
|
130
|
+
*/
|
|
131
|
+
interface UpgradeFieldOptions<TOld extends Record<string, unknown>> {
|
|
132
|
+
readonly derivedFrom: ReadonlyArray<keyof TOld & string>;
|
|
133
|
+
readonly default?: JsonValue;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Options for a purely additive field. `default` is literal JSON only;
|
|
137
|
+
* validated at `addField()` call time.
|
|
138
|
+
*/
|
|
139
|
+
interface AdditiveFieldOptions {
|
|
140
|
+
readonly default?: JsonValue;
|
|
141
|
+
}
|
|
142
|
+
type FieldOptions = UpgradeFieldOptions<Record<string, unknown>> | AdditiveFieldOptions;
|
|
113
143
|
interface RecordBuilder<T extends Record<string, Type>> {
|
|
114
|
-
addField<const K extends string, V extends Type>(name: K, type: V): RecordBuilder<T & {
|
|
144
|
+
addField<const K extends string, V extends Type>(name: K, type: V, options?: FieldOptions): RecordBuilder<T & {
|
|
115
145
|
[k in K]: V;
|
|
116
146
|
}>;
|
|
147
|
+
removeField<K extends keyof T & string>(name: K): RecordBuilder<Omit<T, K>>;
|
|
117
148
|
build(): RecordDef<T>;
|
|
118
149
|
}
|
|
119
150
|
interface UnionBuilder<S extends UnionVariants> {
|
|
@@ -122,6 +153,25 @@ interface UnionBuilder<S extends UnionVariants> {
|
|
|
122
153
|
}>;
|
|
123
154
|
build(): UnionDef<S>;
|
|
124
155
|
}
|
|
156
|
+
/** Per-model field migrations: `[modelKey][fieldName]` → upgrade options. */
|
|
157
|
+
type FieldUpgrades = Record<string, Record<string, UpgradeFieldOptions<Record<string, unknown>>>>;
|
|
158
|
+
interface MigrationResult<M extends ModelDefs> {
|
|
159
|
+
readonly models: M;
|
|
160
|
+
readonly upgrades?: FieldUpgrades;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Lower-level entry point that returns both the merged models AND any
|
|
164
|
+
* `UpgradeFieldOptions` collected via `addField(name, type, options)` during
|
|
165
|
+
* the migration callback. Used by `addSchemaUpdate` to fold sugar-form
|
|
166
|
+
* upgrades into a `VersionedSchema`'s migrations map.
|
|
167
|
+
*
|
|
168
|
+
* Each `RecordBuilderImpl.build()` attaches its collected options to the
|
|
169
|
+
* produced `RecordDef` via a non-enumerable carrier property; this function
|
|
170
|
+
* walks the merged result, extracts the options keyed by the user's chosen
|
|
171
|
+
* output key (so renames are handled), and strips the carrier so the returned
|
|
172
|
+
* `RecordDef`s are structurally clean.
|
|
173
|
+
*/
|
|
174
|
+
declare function applyMigration<const T extends ModelDefs, const S extends ModelDefs>(models: T, migration: (schema: SchemaBuilder<T>) => S): MigrationResult<T & S>;
|
|
125
175
|
declare function defineMigration<const T extends ModelDefs, const S extends ModelDefs>(models: T, migration: (schema: SchemaBuilder<T>) => S): T & S;
|
|
126
176
|
|
|
127
177
|
type FieldArgExplicit = Type | RecordDef | UnionDef;
|
|
@@ -146,7 +196,6 @@ interface InitialSchema<T extends ModelDefs = ModelDefs> {
|
|
|
146
196
|
}
|
|
147
197
|
interface FieldMigration {
|
|
148
198
|
readonly derivedFrom: readonly string[];
|
|
149
|
-
readonly forward: (oldFields: Record<string, unknown>) => unknown;
|
|
150
199
|
}
|
|
151
200
|
type VersionMigrations = Record<string, Record<string, FieldMigration>>;
|
|
152
201
|
interface VersionedSchema<T extends ModelDefs = ModelDefs> {
|
|
@@ -189,4 +238,4 @@ declare function isRecordDef(value: unknown): value is RecordDef;
|
|
|
189
238
|
*/
|
|
190
239
|
declare function isUnionDef(value: unknown): value is UnionDef;
|
|
191
240
|
|
|
192
|
-
export { Array, Boolean, type DocRef, Double, type FieldArg, type FieldArgExplicit, type FieldArgExplicitOf, type FieldArgs, type FieldMigration, type InitialSchema, type MediaRef, type ModelDef, ModelDefType, type ModelDefs, type ObjectRef, Optional, type RecordArgs, type RecordBuilder, type RecordDef, type RecordFields, type Ref, type ResolvedFieldArg, type ResolvedFieldArgExplicit, type ResolvedFields, type ResolvedUnionVariants, type ReturnedSchema, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaUpdate, type SchemaVersionBuilder, String, type Type, TypeKind, type UnionArgs, type UnionBuilder, type UnionDef, type UnionVariantArg, type UnionVariantArgExplicit, type UnionVariantArgs, type UnionVariants, Unknown, type UserRef, type VersionMigrations, type VersionedSchema, createRef, defineMigration, defineRecord, defineSchema, defineSchemaUpdate, defineUnion, isRecordDef, isUnionDef, modelToRef, nextSchema, resolveUnionVariantArg };
|
|
241
|
+
export { type AdditiveFieldOptions, Array, Boolean, type DocRef, Double, type FieldArg, type FieldArgExplicit, type FieldArgExplicitOf, type FieldArgs, type FieldMigration, type FieldOptions, type FieldUpgrades, type InitialSchema, type MediaRef, type MigrationResult, type ModelDef, ModelDefType, type ModelDefs, type ObjectRef, Optional, type RecordArgs, type RecordBuilder, type RecordDef, type RecordFields, type Ref, type ResolvedFieldArg, type ResolvedFieldArgExplicit, type ResolvedFields, type ResolvedUnionVariants, type ReturnedSchema, type Schema, type SchemaBuilder, type SchemaDefinition, type SchemaUpdate, type SchemaVersionBuilder, String, type Type, TypeKind, type UnionArgs, type UnionBuilder, type UnionDef, type UnionVariantArg, type UnionVariantArgExplicit, type UnionVariantArgs, type UnionVariants, Unknown, type UpgradeFieldOptions, type UserRef, type VersionMigrations, type VersionedSchema, applyMigration, createRef, defineMigration, defineRecord, defineSchema, defineSchemaUpdate, defineUnion, isRecordDef, isUnionDef, modelToRef, nextSchema, resolveUnionVariantArg };
|
package/build/esm/index.js
CHANGED
|
@@ -33,7 +33,7 @@ var Unknown = {
|
|
|
33
33
|
function unwrapOneOptional(t) {
|
|
34
34
|
return t.type === TypeKind.OPTIONAL && "item" in t ? t.item : t;
|
|
35
35
|
}
|
|
36
|
-
var
|
|
36
|
+
var Array2 = (item) => {
|
|
37
37
|
if (unwrapOneOptional(item).type === TypeKind.ARRAY) {
|
|
38
38
|
throw new Error("Nested arrays (Array(Array(...)) or Array(Optional(Array(...)))) are not supported. Wrap the inner array in a record instead.");
|
|
39
39
|
}
|
|
@@ -92,6 +92,34 @@ function resolveUnionVariantArg(arg) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// src/defineMigration.ts
|
|
95
|
+
function assertJsonDefault(value, path) {
|
|
96
|
+
if (value === null) return;
|
|
97
|
+
const t = typeof value;
|
|
98
|
+
if (t === "undefined") {
|
|
99
|
+
throw new Error(`Invalid JSON default at ${path}: undefined is not valid JSON`);
|
|
100
|
+
}
|
|
101
|
+
if (t === "string" || t === "number" || t === "boolean") return;
|
|
102
|
+
if (t === "function" || t === "symbol" || t === "bigint") {
|
|
103
|
+
throw new Error(`Invalid JSON default at ${path}: ${t} is not valid JSON`);
|
|
104
|
+
}
|
|
105
|
+
if (Array.isArray(value)) {
|
|
106
|
+
for (let i = 0; i < value.length; i++) {
|
|
107
|
+
assertJsonDefault(value[i], `${path}[${i}]`);
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const proto = Object.getPrototypeOf(value);
|
|
112
|
+
if (proto !== Object.prototype && proto != null) {
|
|
113
|
+
const ctorName = value.constructor?.name ?? "non-plain object";
|
|
114
|
+
throw new Error(`Invalid JSON default at ${path}: ${ctorName} is not valid JSON`);
|
|
115
|
+
}
|
|
116
|
+
if (Object.getOwnPropertySymbols(value).length > 0) {
|
|
117
|
+
throw new Error(`Invalid JSON default at ${path}: symbol-keyed properties are not valid JSON`);
|
|
118
|
+
}
|
|
119
|
+
for (const [k, v] of Object.entries(value)) {
|
|
120
|
+
assertJsonDefault(v, `${path}.${k}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
95
123
|
var UnionBuilderImpl = class _UnionBuilderImpl {
|
|
96
124
|
name;
|
|
97
125
|
docs;
|
|
@@ -129,17 +157,27 @@ var UnionBuilderImpl = class _UnionBuilderImpl {
|
|
|
129
157
|
};
|
|
130
158
|
}
|
|
131
159
|
};
|
|
160
|
+
var UPGRADE_OPTIONS_CARRIER = "__pack_upgrade_options__";
|
|
132
161
|
var RecordBuilderImpl = class _RecordBuilderImpl {
|
|
133
162
|
name;
|
|
134
163
|
fields;
|
|
135
|
-
|
|
164
|
+
upgradeOptions;
|
|
165
|
+
constructor(initialRecordDef, upgradeOptions) {
|
|
136
166
|
this.name = initialRecordDef.name;
|
|
137
167
|
this.fields = {
|
|
138
168
|
...initialRecordDef.fields
|
|
139
169
|
};
|
|
170
|
+
this.upgradeOptions = new Map(upgradeOptions ?? []);
|
|
140
171
|
}
|
|
141
172
|
// TODO: resolve field value from arg instead
|
|
142
|
-
addField(name, value) {
|
|
173
|
+
addField(name, value, options) {
|
|
174
|
+
if (options != null && "default" in options && options.default !== void 0) {
|
|
175
|
+
assertJsonDefault(options.default, `addField("${name}").default`);
|
|
176
|
+
}
|
|
177
|
+
const next = new Map(this.upgradeOptions);
|
|
178
|
+
if (options != null) {
|
|
179
|
+
next.set(name, options);
|
|
180
|
+
}
|
|
143
181
|
return new _RecordBuilderImpl({
|
|
144
182
|
type: ModelDefType.RECORD,
|
|
145
183
|
name: this.name,
|
|
@@ -148,33 +186,82 @@ var RecordBuilderImpl = class _RecordBuilderImpl {
|
|
|
148
186
|
[name]: value
|
|
149
187
|
},
|
|
150
188
|
docs: ""
|
|
151
|
-
});
|
|
189
|
+
}, next);
|
|
190
|
+
}
|
|
191
|
+
removeField(name) {
|
|
192
|
+
const {
|
|
193
|
+
[name]: _removed,
|
|
194
|
+
...rest
|
|
195
|
+
} = this.fields;
|
|
196
|
+
const next = new Map(this.upgradeOptions);
|
|
197
|
+
next.delete(name);
|
|
198
|
+
return new _RecordBuilderImpl({
|
|
199
|
+
type: ModelDefType.RECORD,
|
|
200
|
+
name: this.name,
|
|
201
|
+
fields: rest,
|
|
202
|
+
docs: ""
|
|
203
|
+
}, next);
|
|
152
204
|
}
|
|
153
205
|
build() {
|
|
154
|
-
|
|
206
|
+
const result = {
|
|
155
207
|
type: ModelDefType.RECORD,
|
|
156
208
|
name: this.name,
|
|
157
209
|
fields: this.fields,
|
|
158
210
|
docs: ""
|
|
159
211
|
};
|
|
212
|
+
if (this.upgradeOptions.size > 0) {
|
|
213
|
+
Object.defineProperty(result, UPGRADE_OPTIONS_CARRIER, {
|
|
214
|
+
value: this.upgradeOptions,
|
|
215
|
+
enumerable: false,
|
|
216
|
+
configurable: true,
|
|
217
|
+
writable: false
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return result;
|
|
160
221
|
}
|
|
161
222
|
};
|
|
162
|
-
function
|
|
223
|
+
function makeBuilders(models) {
|
|
163
224
|
const builders = {};
|
|
164
225
|
for (const key in models) {
|
|
165
226
|
const v = models[key];
|
|
166
227
|
if (isRecordDef(v)) {
|
|
167
|
-
|
|
168
|
-
builders[key] = recordBuilder;
|
|
228
|
+
builders[key] = new RecordBuilderImpl(v);
|
|
169
229
|
} else if (isUnionDef(v)) {
|
|
170
|
-
|
|
171
|
-
builders[key] = unionBuilder;
|
|
230
|
+
builders[key] = new UnionBuilderImpl(v);
|
|
172
231
|
}
|
|
173
232
|
}
|
|
174
|
-
return
|
|
233
|
+
return builders;
|
|
234
|
+
}
|
|
235
|
+
function applyMigration(models, migration) {
|
|
236
|
+
const builders = makeBuilders(models);
|
|
237
|
+
const merged = {
|
|
175
238
|
...models,
|
|
176
239
|
...migration(builders)
|
|
177
240
|
};
|
|
241
|
+
const upgrades = {};
|
|
242
|
+
for (const [modelKey, def] of Object.entries(merged)) {
|
|
243
|
+
if (!isRecordDef(def)) continue;
|
|
244
|
+
const carrier = def;
|
|
245
|
+
const opts = carrier[UPGRADE_OPTIONS_CARRIER];
|
|
246
|
+
if (opts == null) continue;
|
|
247
|
+
delete carrier[UPGRADE_OPTIONS_CARRIER];
|
|
248
|
+
const fieldEntries = {};
|
|
249
|
+
for (const [fieldName, options] of opts) {
|
|
250
|
+
if ("derivedFrom" in options) {
|
|
251
|
+
fieldEntries[fieldName] = options;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (Object.keys(fieldEntries).length > 0) {
|
|
255
|
+
upgrades[modelKey] = fieldEntries;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
models: merged,
|
|
260
|
+
upgrades: Object.keys(upgrades).length > 0 ? upgrades : void 0
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function defineMigration(models, migration) {
|
|
264
|
+
return applyMigration(models, migration).models;
|
|
178
265
|
}
|
|
179
266
|
|
|
180
267
|
// src/defineRecord.ts
|
|
@@ -210,6 +297,39 @@ function defineSchemaUpdate(name, migration) {
|
|
|
210
297
|
migration
|
|
211
298
|
};
|
|
212
299
|
}
|
|
300
|
+
function mergeMigrations(base, override) {
|
|
301
|
+
if (base == null) return override;
|
|
302
|
+
if (override == null) return base;
|
|
303
|
+
const result = {
|
|
304
|
+
...base
|
|
305
|
+
};
|
|
306
|
+
for (const [modelKey, fields] of Object.entries(override)) {
|
|
307
|
+
result[modelKey] = {
|
|
308
|
+
...result[modelKey],
|
|
309
|
+
...fields
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
return result;
|
|
313
|
+
}
|
|
314
|
+
function pruneMigrations(migrations, models) {
|
|
315
|
+
if (migrations == null) return void 0;
|
|
316
|
+
const result = {};
|
|
317
|
+
for (const [modelKey, fields] of Object.entries(migrations)) {
|
|
318
|
+
const def = models[modelKey];
|
|
319
|
+
if (def == null || def.type !== "record") continue;
|
|
320
|
+
const recordFields = def.fields;
|
|
321
|
+
const kept = {};
|
|
322
|
+
for (const [fieldName, migration] of Object.entries(fields)) {
|
|
323
|
+
if (fieldName in recordFields) {
|
|
324
|
+
kept[fieldName] = migration;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (Object.keys(kept).length > 0) {
|
|
328
|
+
result[modelKey] = kept;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
332
|
+
}
|
|
213
333
|
var SchemaVersionBuilderImpl = class _SchemaVersionBuilderImpl {
|
|
214
334
|
models;
|
|
215
335
|
version;
|
|
@@ -222,11 +342,18 @@ var SchemaVersionBuilderImpl = class _SchemaVersionBuilderImpl {
|
|
|
222
342
|
this._migrations = migrations;
|
|
223
343
|
}
|
|
224
344
|
addSchemaUpdate(update) {
|
|
225
|
-
const
|
|
226
|
-
|
|
345
|
+
const {
|
|
346
|
+
models,
|
|
347
|
+
upgrades
|
|
348
|
+
} = applyMigration(this.models, update.migration);
|
|
349
|
+
const merged = mergeMigrations(this._migrations, upgrades);
|
|
350
|
+
const pruned = pruneMigrations(merged, models);
|
|
351
|
+
return new _SchemaVersionBuilderImpl(models, this.version, this.previous, pruned);
|
|
227
352
|
}
|
|
228
353
|
withMigrations(migrations) {
|
|
229
|
-
|
|
354
|
+
const merged = mergeMigrations(this._migrations, migrations);
|
|
355
|
+
const pruned = pruneMigrations(merged, this.models);
|
|
356
|
+
return new _SchemaVersionBuilderImpl(this.models, this.version, this.previous, pruned);
|
|
230
357
|
}
|
|
231
358
|
build() {
|
|
232
359
|
return {
|
|
@@ -246,6 +373,6 @@ function nextSchema(previous) {
|
|
|
246
373
|
return new SchemaVersionBuilderImpl(previous.models, previous.version + 1, previous);
|
|
247
374
|
}
|
|
248
375
|
|
|
249
|
-
export { Array, Boolean, Double, ModelDefType, Optional, String, TypeKind, Unknown, createRef, defineMigration, defineRecord, defineSchema, defineSchemaUpdate, defineUnion, isRecordDef, isUnionDef, modelToRef, nextSchema, resolveUnionVariantArg };
|
|
376
|
+
export { Array2 as Array, Boolean, Double, ModelDefType, Optional, String, TypeKind, Unknown, applyMigration, createRef, defineMigration, defineRecord, defineSchema, defineSchemaUpdate, defineUnion, isRecordDef, isUnionDef, modelToRef, nextSchema, resolveUnionVariantArg };
|
|
250
377
|
//# sourceMappingURL=index.js.map
|
|
251
378
|
//# sourceMappingURL=index.js.map
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.ts","../../src/defineSchemaUpdate.ts"],"names":[],"mappings":";AAgBO,IAAM,YAAA,GAAe;AAAA,EAC1B,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO;AACT;;;ACHO,IAAM,QAAA,GAAW;AAAA,EACtB,KAAA,EAAO,OAAA;AAAA,EACP,OAAA,EAAS,SAAA;AAAA,EACT,OAAA,EAAS,QAAA;AAAA,EACT,MAAA,EAAQ,QAAA;AAAA,EACR,SAAA,EAAW,UAAA;AAAA,EACX,UAAA,EAAY,WAAA;AAAA,EACZ,QAAA,EAAU,UAAA;AAAA,EACV,GAAA,EAAK,KAAA;AAAA,EACL,MAAA,EAAQ,QAAA;AAAA,EACR,OAAA,EAAS,SAAA;AAAA,EACT,QAAA,EAAU;AACZ;AAMO,IAAM,MAAA,GAAS;AAAA,EACpB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,MAAA,GAAS;AAAA,EACpB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,OAAA,GAAU;AAAA,EACrB,MAAM,QAAA,CAAS;AACjB;AACO,IAAM,OAAA,GAAU;AAAA,EACrB,MAAM,QAAA,CAAS;AACjB;AACA,SAAS,kBAAkB,CAAA,EAAG;AAC5B,EAAA,OAAO,EAAE,IAAA,KAAS,QAAA,CAAS,YAAY,MAAA,I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A,QAC7B,YAAY,IAAA,CAAK;AAAA,UACf;AAAC,KACP;AAAA,EACF;AACF,CAAA;AACO,SAAS,WAAW,QAAA,EAAU;AACnC,EAAA,OAAO,IAAI,wBAAA,CAAyB,QAAA,CAAS,QAAQ,QAAA,CAAS,OAAA,GAAU,GAAG,QAAQ,CAAA;AACrF","file":"index.js","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\nexport const ModelDefType = {\n RECORD: \"record\",\n UNION: \"union\"\n};","/*\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\nexport const TypeKind = {\n ARRAY: \"array\",\n BOOLEAN: \"boolean\",\n DOC_REF: \"docRef\",\n DOUBLE: \"double\",\n MEDIA_REF: \"mediaRef\",\n OBJECT_REF: \"objectRef\",\n OPTIONAL: \"optional\",\n REF: \"ref\",\n STRING: \"string\",\n UNKNOWN: \"unknown\",\n USER_REF: \"userRef\"\n};\n\n// Forward declaration to avoid circular reference\n\n// A reference to a record or a union type\n\nexport const String = {\n type: TypeKind.STRING\n};\nexport const Double = {\n type: TypeKind.DOUBLE\n};\nexport const Boolean = {\n type: TypeKind.BOOLEAN\n};\nexport const Unknown = {\n type: TypeKind.UNKNOWN\n};\nfunction unwrapOneOptional(t) {\n return t.type === TypeKind.OPTIONAL && \"item\" in t ? t.item : t;\n}\nexport const Array = item => {\n if (unwrapOneOptional(item).type === TypeKind.ARRAY) {\n throw new Error(\"Nested arrays (Array(Array(...)) or Array(Optional(Array(...)))) are not supported. \" + \"Wrap the inner array in a record instead.\");\n }\n return {\n type: TypeKind.ARRAY,\n items: item\n };\n};\nexport const Optional = item => {\n if (item.type === TypeKind.OPTIONAL) {\n throw new Error(\"Nested optionals (Optional(Optional(...))) are not supported.\");\n }\n return {\n type: TypeKind.OPTIONAL,\n item\n };\n};","/*\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 { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\n\n/**\n * Helper function to safely transform a record definition to a reference.\n * This function helps TypeScript track type transformations better.\n */\nexport function modelToRef(model) {\n return createRef(model.name, model.type);\n}\n\n/**\n * Helper function to create a reference with proper typing.\n * This avoids type assertions in multiple places.\n */\nexport function createRef(name, refType) {\n return {\n type: TypeKind.REF,\n name,\n refType\n };\n}\n\n/**\n * Type guard to check if a value is a RecordDef\n */\nexport function isRecordDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.RECORD && \"fields\" in value;\n}\n\n/**\n * Type guard to check if a value is a UnionDef\n */\nexport function isUnionDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.UNION && \"variants\" in value;\n}","/*\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 { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\nimport { modelToRef } from \"./utils.js\";\nexport function defineUnion(name, {\n discriminant = \"type\",\n docs,\n variants\n}) {\n const entries = Object.entries(variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);\n const resolvedVariants = Object.fromEntries(entries);\n return {\n type: ModelDefType.UNION,\n discriminant,\n name,\n docs,\n variants: resolvedVariants\n };\n}\nexport function resolveUnionVariantArg(arg) {\n const resolved = typeof arg === \"function\" ? arg() : arg;\n return resolved.type === TypeKind.REF ? resolved : modelToRef(resolved);\n}","/*\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 { resolveUnionVariantArg } from \"./defineUnion.js\";\nimport { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef } from \"./utils.js\";\n\n/** Soon to be deprecated - Use `ModelDefs` instead. */\n\n/** Soon to be deprecated - use `ModelDefs` instead. */\n\nclass UnionBuilderImpl {\n name;\n docs;\n variants;\n constructor({\n name,\n docs,\n variants\n }) {\n this.name = name;\n this.docs = docs;\n this.variants = {\n ...variants\n };\n }\n addVariant(variantName, modelDefOrRef) {\n const ref = resolveUnionVariantArg(modelDefOrRef);\n const newVariants = {\n ...this.variants,\n [variantName]: ref\n };\n return new UnionBuilderImpl({\n type: ModelDefType.UNION,\n name: this.name,\n variants: newVariants,\n discriminant: \"type\"\n });\n }\n build() {\n return {\n type: ModelDefType.UNION,\n variants: this.variants,\n discriminant: \"type\",\n name: this.name\n };\n }\n}\nclass RecordBuilderImpl {\n name;\n fields;\n constructor(initialRecordDef) {\n this.name = initialRecordDef.name;\n this.fields = {\n ...initialRecordDef.fields\n };\n }\n\n // TODO: resolve field value from arg instead\n addField(name, value) {\n return new RecordBuilderImpl({\n type: ModelDefType.RECORD,\n name: this.name,\n fields: {\n ...this.fields,\n [name]: value\n },\n docs: \"\"\n });\n }\n build() {\n return {\n type: ModelDefType.RECORD,\n name: this.name,\n fields: this.fields,\n docs: \"\"\n };\n }\n}\nexport function defineMigration(models, migration) {\n const builders = {};\n for (const key in models) {\n const v = models[key];\n if (isRecordDef(v)) {\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...models,\n ...migration(builders)\n };\n}","/*\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 { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef, modelToRef } from \"./utils.js\";\n/**\n * Helper function to resolve a field value, handling functions and transforming\n * types as needed.\n */\nfunction resolveFieldArg(value) {\n // Handle function values\n const resolved = typeof value === \"function\" ? value() : value;\n if (isRecordDef(resolved) || isUnionDef(resolved)) {\n return modelToRef(resolved);\n }\n\n // For primitive types and other Types\n return resolved;\n}\nexport function defineRecord(name, record) {\n const entries = Object.entries(record.fields).map(([key, value]) => [key, resolveFieldArg(value)]);\n const fields = Object.fromEntries(entries);\n return {\n type: ModelDefType.RECORD,\n name: name,\n docs: record.docs,\n fields\n };\n}","/*\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 { defineMigration } from \"./defineMigration.js\";\nexport function defineSchema(models) {\n return {\n type: \"initial\",\n version: 1,\n models\n };\n}\nexport function defineSchemaUpdate(name, migration) {\n return {\n name,\n migration\n };\n}\nclass SchemaVersionBuilderImpl {\n models;\n version;\n previous;\n _migrations;\n constructor(models, version, previous, migrations) {\n this.models = models;\n this.version = version;\n this.previous = previous;\n this._migrations = migrations;\n }\n addSchemaUpdate(update) {\n const merged = defineMigration(this.models, update.migration);\n return new SchemaVersionBuilderImpl(merged, this.version, this.previous, this._migrations);\n }\n withMigrations(migrations) {\n return new SchemaVersionBuilderImpl(this.models, this.version, this.previous, migrations);\n }\n build() {\n return {\n type: \"versioned\",\n models: {\n ...this.models\n },\n version: this.version,\n previous: this.previous,\n ...(this._migrations != null ? {\n migrations: this._migrations\n } : {})\n };\n }\n}\nexport function nextSchema(previous) {\n return new SchemaVersionBuilderImpl(previous.models, previous.version + 1, previous);\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRec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AO;AAAA,MACL,IAAA,EAAM,WAAA;AAAA,MACN,MAAA,EAAQ;AAAA,QACN,GAAG,IAAA,CAAK;AAAA,OACV;AAAA,MACA,SAAS,IAAA,CAAK,OAAA;AAAA,MACd,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,GAAI,IAAA,CAAK,WAAA,IAAe,IAAA,GAAO;AAAA,QAC7B,YAAY,IAAA,CAAK;AAAA,UACf;AAAC,KACP;AAAA,EACF;AACF,CAAA;AACO,SAAS,WAAW,QAAA,EAAU;AACnC,EAAA,OAAO,IAAI,wBAAA,CAAyB,QAAA,CAAS,QAAQ,QAAA,CAAS,OAAA,GAAU,GAAG,QAAQ,CAAA;AACrF","file":"index.js","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\nexport const ModelDefType = {\n RECORD: \"record\",\n UNION: \"union\"\n};","/*\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\nexport const TypeKind = {\n ARRAY: \"array\",\n BOOLEAN: \"boolean\",\n DOC_REF: \"docRef\",\n DOUBLE: \"double\",\n MEDIA_REF: \"mediaRef\",\n OBJECT_REF: \"objectRef\",\n OPTIONAL: \"optional\",\n REF: \"ref\",\n STRING: \"string\",\n UNKNOWN: \"unknown\",\n USER_REF: \"userRef\"\n};\n\n// Forward declaration to avoid circular reference\n\n// A reference to a record or a union type\n\nexport const String = {\n type: TypeKind.STRING\n};\nexport const Double = {\n type: TypeKind.DOUBLE\n};\nexport const Boolean = {\n type: TypeKind.BOOLEAN\n};\nexport const Unknown = {\n type: TypeKind.UNKNOWN\n};\nfunction unwrapOneOptional(t) {\n return t.type === TypeKind.OPTIONAL && \"item\" in t ? t.item : t;\n}\nexport const Array = item => {\n if (unwrapOneOptional(item).type === TypeKind.ARRAY) {\n throw new Error(\"Nested arrays (Array(Array(...)) or Array(Optional(Array(...)))) are not supported. \" + \"Wrap the inner array in a record instead.\");\n }\n return {\n type: TypeKind.ARRAY,\n items: item\n };\n};\nexport const Optional = item => {\n if (item.type === TypeKind.OPTIONAL) {\n throw new Error(\"Nested optionals (Optional(Optional(...))) are not supported.\");\n }\n return {\n type: TypeKind.OPTIONAL,\n item\n };\n};","/*\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 { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\n\n/**\n * Helper function to safely transform a record definition to a reference.\n * This function helps TypeScript track type transformations better.\n */\nexport function modelToRef(model) {\n return createRef(model.name, model.type);\n}\n\n/**\n * Helper function to create a reference with proper typing.\n * This avoids type assertions in multiple places.\n */\nexport function createRef(name, refType) {\n return {\n type: TypeKind.REF,\n name,\n refType\n };\n}\n\n/**\n * Type guard to check if a value is a RecordDef\n */\nexport function isRecordDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.RECORD && \"fields\" in value;\n}\n\n/**\n * Type guard to check if a value is a UnionDef\n */\nexport function isUnionDef(value) {\n return value != null && typeof value === \"object\" && \"type\" in value && value.type === ModelDefType.UNION && \"variants\" in value;\n}","/*\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 { ModelDefType } from \"./defs.js\";\nimport { TypeKind } from \"./primitives.js\";\nimport { modelToRef } from \"./utils.js\";\nexport function defineUnion(name, {\n discriminant = \"type\",\n docs,\n variants\n}) {\n const entries = Object.entries(variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);\n const resolvedVariants = Object.fromEntries(entries);\n return {\n type: ModelDefType.UNION,\n discriminant,\n name,\n docs,\n variants: resolvedVariants\n };\n}\nexport function resolveUnionVariantArg(arg) {\n const resolved = typeof arg === \"function\" ? arg() : arg;\n return resolved.type === TypeKind.REF ? resolved : modelToRef(resolved);\n}","/*\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 { resolveUnionVariantArg } from \"./defineUnion.js\";\nimport { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef } from \"./utils.js\";\n\n/** Soon to be deprecated - Use `ModelDefs` instead. */\n\n/** Soon to be deprecated - use `ModelDefs` instead. */\n\n/**\n * Recursive literal-JSON type. Constrains schema-time `default` values to\n * data that JSON-serializes losslessly — no `Date`, `RegExp`, functions, class\n * instances, or `undefined`. Mirrors the `JsonValue` exported by\n * `@palantir/pack.document-schema.model-types`; kept local here to avoid a\n * package dependency from `pack.schema`.\n */\n\n/**\n * Upgrade options for a field whose value is derived from prior-version fields.\n * Supplied as the third argument to `addField`; surfaced by `applyMigration`\n * as part of `MigrationResult.upgrades`. Declares the structural dependency\n * (`derivedFrom`) and an optional literal JSON `default` used when no source\n * data exists. The runtime forward function is supplied separately via the\n * generated `DocumentModel(...)` factory's `UpgradeFns` parameter.\n */\n\n/**\n * Options for a purely additive field. `default` is literal JSON only;\n * validated at `addField()` call time.\n */\n\n/**\n * Recursively assert `value` is representable as literal JSON. Rejects `Date`,\n * `RegExp`, functions, class instances, symbol-keyed properties, `undefined`\n * (anywhere — top-level or nested), `symbol`, and `bigint`. Throws on the\n * first offending value, naming the path for debuggability.\n */\nfunction assertJsonDefault(value, path) {\n // eslint-disable-next-line eqeqeq -- need to distinguish null (valid JSON) from undefined (not).\n if (value === null) return;\n const t = typeof value;\n if (t === \"undefined\") {\n throw new Error(`Invalid JSON default at ${path}: undefined is not valid JSON`);\n }\n if (t === \"string\" || t === \"number\" || t === \"boolean\") return;\n if (t === \"function\" || t === \"symbol\" || t === \"bigint\") {\n throw new Error(`Invalid JSON default at ${path}: ${t} is not valid JSON`);\n }\n if (Array.isArray(value)) {\n for (let i = 0; i < value.length; i++) {\n assertJsonDefault(value[i], `${path}[${i}]`);\n }\n return;\n }\n const proto = Object.getPrototypeOf(value);\n if (proto !== Object.prototype && proto != null) {\n const ctorName = value.constructor?.name ?? \"non-plain object\";\n throw new Error(`Invalid JSON default at ${path}: ${ctorName} is not valid JSON`);\n }\n if (Object.getOwnPropertySymbols(value).length > 0) {\n throw new Error(`Invalid JSON default at ${path}: symbol-keyed properties are not valid JSON`);\n }\n for (const [k, v] of Object.entries(value)) {\n assertJsonDefault(v, `${path}.${k}`);\n }\n}\nclass UnionBuilderImpl {\n name;\n docs;\n variants;\n constructor({\n name,\n docs,\n variants\n }) {\n this.name = name;\n this.docs = docs;\n this.variants = {\n ...variants\n };\n }\n addVariant(variantName, modelDefOrRef) {\n const ref = resolveUnionVariantArg(modelDefOrRef);\n const newVariants = {\n ...this.variants,\n [variantName]: ref\n };\n return new UnionBuilderImpl({\n type: ModelDefType.UNION,\n name: this.name,\n variants: newVariants,\n discriminant: \"type\"\n });\n }\n build() {\n return {\n type: ModelDefType.UNION,\n variants: this.variants,\n discriminant: \"type\",\n name: this.name\n };\n }\n}\n\n/**\n * Non-enumerable carrier property attached to a `RecordDef` by\n * `RecordBuilderImpl.build()` when the builder has collected one or more\n * `FieldOptions`. `applyMigration` reads this and then deletes the property,\n * so the `RecordDef` it returns is structurally clean (no extra keys, no\n * symbol-keyed metadata).\n */\nconst UPGRADE_OPTIONS_CARRIER = \"__pack_upgrade_options__\";\nclass RecordBuilderImpl {\n name;\n fields;\n upgradeOptions;\n constructor(initialRecordDef, upgradeOptions) {\n this.name = initialRecordDef.name;\n this.fields = {\n ...initialRecordDef.fields\n };\n // Upgrade options only flow forward within a single migration callback —\n // they are NOT inherited from the prior version's RecordDef, because each\n // version's upgrades describe a specific version transition.\n this.upgradeOptions = new Map(upgradeOptions ?? []);\n }\n\n // TODO: resolve field value from arg instead\n addField(name, value, options) {\n if (options != null && \"default\" in options && options.default !== undefined) {\n assertJsonDefault(options.default, `addField(\"${name}\").default`);\n }\n const next = new Map(this.upgradeOptions);\n if (options != null) {\n next.set(name, options);\n }\n return new RecordBuilderImpl({\n type: ModelDefType.RECORD,\n name: this.name,\n fields: {\n ...this.fields,\n [name]: value\n },\n docs: \"\"\n }, next);\n }\n removeField(name) {\n const {\n [name]: _removed,\n ...rest\n } = this.fields;\n const next = new Map(this.upgradeOptions);\n next.delete(name);\n return new RecordBuilderImpl({\n type: ModelDefType.RECORD,\n name: this.name,\n fields: rest,\n docs: \"\"\n }, next);\n }\n build() {\n const result = {\n type: ModelDefType.RECORD,\n name: this.name,\n fields: this.fields,\n docs: \"\"\n };\n if (this.upgradeOptions.size > 0) {\n Object.defineProperty(result, UPGRADE_OPTIONS_CARRIER, {\n value: this.upgradeOptions,\n enumerable: false,\n configurable: true,\n writable: false\n });\n }\n return result;\n }\n}\nfunction makeBuilders(models) {\n const builders = {};\n for (const key in models) {\n const v = models[key];\n if (isRecordDef(v)) {\n builders[key] = new RecordBuilderImpl(v);\n } else if (isUnionDef(v)) {\n builders[key] = new UnionBuilderImpl(v);\n }\n }\n return builders;\n}\n\n/** Per-model field migrations: `[modelKey][fieldName]` → upgrade options. */\n\n/**\n * Lower-level entry point that returns both the merged models AND any\n * `UpgradeFieldOptions` collected via `addField(name, type, options)` during\n * the migration callback. Used by `addSchemaUpdate` to fold sugar-form\n * upgrades into a `VersionedSchema`'s migrations map.\n *\n * Each `RecordBuilderImpl.build()` attaches its collected options to the\n * produced `RecordDef` via a non-enumerable carrier property; this function\n * walks the merged result, extracts the options keyed by the user's chosen\n * output key (so renames are handled), and strips the carrier so the returned\n * `RecordDef`s are structurally clean.\n */\nexport function applyMigration(models, migration) {\n const builders = makeBuilders(models);\n const merged = {\n ...models,\n ...migration(builders)\n };\n const upgrades = {};\n for (const [modelKey, def] of Object.entries(merged)) {\n if (!isRecordDef(def)) continue;\n const carrier = def;\n const opts = carrier[UPGRADE_OPTIONS_CARRIER];\n if (opts == null) continue;\n // Strip the carrier so the returned RecordDef is structurally clean.\n delete carrier[UPGRADE_OPTIONS_CARRIER];\n const fieldEntries = {};\n for (const [fieldName, options] of opts) {\n // Only `UpgradeFieldOptions` (which declare `derivedFrom`) flow into the\n // upgrades map; `AdditiveFieldOptions` carry only a literal `default`\n // and have no read-time lens effect.\n if (\"derivedFrom\" in options) {\n fieldEntries[fieldName] = options;\n }\n }\n if (Object.keys(fieldEntries).length > 0) {\n upgrades[modelKey] = fieldEntries;\n }\n }\n return {\n models: merged,\n upgrades: Object.keys(upgrades).length > 0 ? upgrades : undefined\n };\n}\nexport function defineMigration(models, migration) {\n return applyMigration(models, migration).models;\n}","/*\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 { ModelDefType } from \"./defs.js\";\nimport { isRecordDef, isUnionDef, modelToRef } from \"./utils.js\";\n/**\n * Helper function to resolve a field value, handling functions and transforming\n * types as needed.\n */\nfunction resolveFieldArg(value) {\n // Handle function values\n const resolved = typeof value === \"function\" ? value() : value;\n if (isRecordDef(resolved) || isUnionDef(resolved)) {\n return modelToRef(resolved);\n }\n\n // For primitive types and other Types\n return resolved;\n}\nexport function defineRecord(name, record) {\n const entries = Object.entries(record.fields).map(([key, value]) => [key, resolveFieldArg(value)]);\n const fields = Object.fromEntries(entries);\n return {\n type: ModelDefType.RECORD,\n name: name,\n docs: record.docs,\n fields\n };\n}","/*\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 { applyMigration } from \"./defineMigration.js\";\nexport function defineSchema(models) {\n return {\n type: \"initial\",\n version: 1,\n models\n };\n}\nexport function defineSchemaUpdate(name, migration) {\n return {\n name,\n migration\n };\n}\n/**\n * Merge two `VersionMigrations` records. Per-model field migrations from\n * `override` take precedence over `base` for the same field, but the maps are\n * combined at both the model and field level so explicit `withMigrations`\n * calls can supplement (not just replace) the sugar from `addField` options.\n */\nfunction mergeMigrations(base, override) {\n if (base == null) return override;\n if (override == null) return base;\n const result = {\n ...base\n };\n for (const [modelKey, fields] of Object.entries(override)) {\n result[modelKey] = {\n ...result[modelKey],\n ...fields\n };\n }\n return result;\n}\n\n/**\n * Drop migration entries that no longer correspond to a field on a record in\n * `models`. Required because `mergeMigrations` is monotonic — a later\n * `addSchemaUpdate` that removes or retypes a field would otherwise leave a\n * stale entry in the accumulator. Entries are dropped when:\n * - the model key is no longer present,\n * - the model is no longer a record (e.g. replaced by a union), or\n * - the field name is no longer one of the record's fields.\n */\nfunction pruneMigrations(migrations, models) {\n if (migrations == null) return undefined;\n const result = {};\n for (const [modelKey, fields] of Object.entries(migrations)) {\n const def = models[modelKey];\n if (def == null || def.type !== \"record\") continue;\n const recordFields = def.fields;\n const kept = {};\n for (const [fieldName, migration] of Object.entries(fields)) {\n if (fieldName in recordFields) {\n kept[fieldName] = migration;\n }\n }\n if (Object.keys(kept).length > 0) {\n result[modelKey] = kept;\n }\n }\n return Object.keys(result).length > 0 ? result : undefined;\n}\nclass SchemaVersionBuilderImpl {\n models;\n version;\n previous;\n _migrations;\n constructor(models, version, previous, migrations) {\n this.models = models;\n this.version = version;\n this.previous = previous;\n this._migrations = migrations;\n }\n addSchemaUpdate(update) {\n // applyMigration returns both the merged models and any sugar-form\n // upgrades collected via `addField(name, type, { derivedFrom, forward })`.\n const {\n models,\n upgrades\n } = applyMigration(this.models, update.migration);\n const merged = mergeMigrations(this._migrations, upgrades);\n // Reconcile against the new models: a later update that removes or\n // retypes a field must drop the prior step's stale migration entry.\n const pruned = pruneMigrations(merged, models);\n return new SchemaVersionBuilderImpl(models, this.version, this.previous, pruned);\n }\n withMigrations(migrations) {\n const merged = mergeMigrations(this._migrations, migrations);\n const pruned = pruneMigrations(merged, this.models);\n return new SchemaVersionBuilderImpl(this.models, this.version, this.previous, pruned);\n }\n build() {\n return {\n type: \"versioned\",\n models: {\n ...this.models\n },\n version: this.version,\n previous: this.previous,\n ...(this._migrations != null ? {\n migrations: this._migrations\n } : {})\n };\n }\n}\nexport function nextSchema(previous) {\n return new SchemaVersionBuilderImpl(previous.models, previous.version + 1, previous);\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"","names":[],"sources":["../../../src/__tests__/addFieldOptions.test.ts"],"version":3,"file":"addFieldOptions.test.d.ts"}
|
|
@@ -6,18 +6,72 @@ export type ReturnedSchema = ModelDefs;
|
|
|
6
6
|
/** Soon to be deprecated - use `ModelDefs` instead. */
|
|
7
7
|
export type Schema<T extends ModelDefs> = T;
|
|
8
8
|
export type SchemaBuilder<T extends ModelDefs> = { [k in keyof T] : T[k] extends UnionDef<infer R> ? UnionBuilder<R> : T[k] extends RecordDef<infer R> ? RecordBuilder<R> : never };
|
|
9
|
+
/**
|
|
10
|
+
* Recursive literal-JSON type. Constrains schema-time `default` values to
|
|
11
|
+
* data that JSON-serializes losslessly — no `Date`, `RegExp`, functions, class
|
|
12
|
+
* instances, or `undefined`. Mirrors the `JsonValue` exported by
|
|
13
|
+
* `@palantir/pack.document-schema.model-types`; kept local here to avoid a
|
|
14
|
+
* package dependency from `pack.schema`.
|
|
15
|
+
*/
|
|
16
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
17
|
+
[key: string]: JsonValue;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Upgrade options for a field whose value is derived from prior-version fields.
|
|
21
|
+
* Supplied as the third argument to `addField`; surfaced by `applyMigration`
|
|
22
|
+
* as part of `MigrationResult.upgrades`. Declares the structural dependency
|
|
23
|
+
* (`derivedFrom`) and an optional literal JSON `default` used when no source
|
|
24
|
+
* data exists. The runtime forward function is supplied separately via the
|
|
25
|
+
* generated `DocumentModel(...)` factory's `UpgradeFns` parameter.
|
|
26
|
+
*/
|
|
27
|
+
export interface UpgradeFieldOptions<TOld extends Record<string, unknown>> {
|
|
28
|
+
readonly derivedFrom: ReadonlyArray<keyof TOld & string>;
|
|
29
|
+
readonly default?: JsonValue;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for a purely additive field. `default` is literal JSON only;
|
|
33
|
+
* validated at `addField()` call time.
|
|
34
|
+
*/
|
|
35
|
+
export interface AdditiveFieldOptions {
|
|
36
|
+
readonly default?: JsonValue;
|
|
37
|
+
}
|
|
38
|
+
export type FieldOptions = UpgradeFieldOptions<Record<string, unknown>> | AdditiveFieldOptions;
|
|
9
39
|
export interface RecordBuilder<T extends Record<string, Type>> {
|
|
10
40
|
addField<
|
|
11
41
|
const K extends string,
|
|
12
42
|
V extends Type
|
|
13
|
-
>(name: K, type: V): RecordBuilder<T & { [k in K] : V }>;
|
|
43
|
+
>(name: K, type: V, options?: FieldOptions): RecordBuilder<T & { [k in K] : V }>;
|
|
44
|
+
removeField<K extends keyof T & string>(name: K): RecordBuilder<Omit<T, K>>;
|
|
14
45
|
build(): RecordDef<T>;
|
|
15
46
|
}
|
|
16
47
|
export interface UnionBuilder<S extends UnionVariants> {
|
|
17
48
|
addVariant<const K extends string>(name: K, modelDefOrRef: UnionVariantArg): UnionBuilder<S & { [k in K] : Ref }>;
|
|
18
49
|
build(): UnionDef<S>;
|
|
19
50
|
}
|
|
51
|
+
/** Per-model field migrations: `[modelKey][fieldName]` → upgrade options. */
|
|
52
|
+
export type FieldUpgrades = Record<string, Record<string, UpgradeFieldOptions<Record<string, unknown>>>>;
|
|
53
|
+
export interface MigrationResult<M extends ModelDefs> {
|
|
54
|
+
readonly models: M;
|
|
55
|
+
readonly upgrades?: FieldUpgrades;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Lower-level entry point that returns both the merged models AND any
|
|
59
|
+
* `UpgradeFieldOptions` collected via `addField(name, type, options)` during
|
|
60
|
+
* the migration callback. Used by `addSchemaUpdate` to fold sugar-form
|
|
61
|
+
* upgrades into a `VersionedSchema`'s migrations map.
|
|
62
|
+
*
|
|
63
|
+
* Each `RecordBuilderImpl.build()` attaches its collected options to the
|
|
64
|
+
* produced `RecordDef` via a non-enumerable carrier property; this function
|
|
65
|
+
* walks the merged result, extracts the options keyed by the user's chosen
|
|
66
|
+
* output key (so renames are handled), and strips the carrier so the returned
|
|
67
|
+
* `RecordDef`s are structurally clean.
|
|
68
|
+
*/
|
|
69
|
+
export declare function applyMigration<
|
|
70
|
+
const T extends ModelDefs,
|
|
71
|
+
const S extends ModelDefs
|
|
72
|
+
>(models: T, migration: (schema: SchemaBuilder<T>) => S): MigrationResult<T & S>;
|
|
20
73
|
export declare function defineMigration<
|
|
21
74
|
const T extends ModelDefs,
|
|
22
75
|
const S extends ModelDefs
|
|
23
76
|
>(models: T, migration: (schema: SchemaBuilder<T>) => S): T & S;
|
|
77
|
+
export {};
|