@palantir/pack.schema 0.2.0 → 0.3.1

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.
@@ -1,4 +1,11 @@
1
1
 
2
- > @palantir/pack.schema@0.2.0 lint /home/runner/work/pack/pack/packages/schema
2
+ > @palantir/pack.schema@0.3.1 lint /home/runner/work/pack/pack/packages/schema
3
3
  > eslint ./src && dprint check --config $(find-up dprint.json) --allow-no-files
4
4
 
5
+
6
+ /home/runner/work/pack/pack/packages/schema/src/defineMigration.ts
7
+ 48:23 warning { [k in K]: Ref; } is overridden by S in this intersection type @typescript-eslint/no-redundant-type-constituents
8
+ 64:23 warning Record<K, Ref> is overridden by S in this intersection type @typescript-eslint/no-redundant-type-constituents
9
+
10
+ ✖ 2 problems (0 errors, 2 warnings)
11
+
@@ -1,5 +1,6 @@
1
1
 
2
- > @palantir/pack.schema@0.2.0 transpileBrowser /home/runner/work/pack/pack/packages/schema
2
+ > @palantir/pack.schema@0.3.1 transpileBrowser /home/runner/work/pack/pack/packages/schema
3
3
  > monorepo-transpile -f esm -m bundle -t browser
4
4
 
5
+ [baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
5
6
  👍
@@ -1,5 +1,6 @@
1
1
 
2
- > @palantir/pack.schema@0.2.0 transpileCjs /home/runner/work/pack/pack/packages/schema
2
+ > @palantir/pack.schema@0.3.1 transpileCjs /home/runner/work/pack/pack/packages/schema
3
3
  > monorepo-transpile -f cjs -m bundle -t node
4
4
 
5
+ [baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
5
6
  👍
@@ -1,5 +1,6 @@
1
1
 
2
- > @palantir/pack.schema@0.2.0 transpileEsm /home/runner/work/pack/pack/packages/schema
2
+ > @palantir/pack.schema@0.3.1 transpileEsm /home/runner/work/pack/pack/packages/schema
3
3
  > monorepo-transpile -f esm -m bundle -t node
4
4
 
5
+ [baseline-browser-mapping] The data in this module is over two months old. To ensure accurate Baseline data, please update: `npm i baseline-browser-mapping@latest -D`
5
6
  👍
@@ -1,5 +1,5 @@
1
1
 
2
- > @palantir/pack.schema@0.2.0 transpileTypes /home/runner/work/pack/pack/packages/schema
2
+ > @palantir/pack.schema@0.3.1 transpileTypes /home/runner/work/pack/pack/packages/schema
3
3
  > monorepo-transpile -f esm -m types -t node
4
4
 
5
5
  👍
@@ -1,4 +1,4 @@
1
1
 
2
- > @palantir/pack.schema@0.2.0 typecheck /home/runner/work/pack/pack/packages/schema
2
+ > @palantir/pack.schema@0.3.1 typecheck /home/runner/work/pack/pack/packages/schema
3
3
  > tsc --noEmit --emitDeclarationOnly false
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @palantir/pack.schema
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 5120719: Update dependency ranges
8
+
9
+ ## 0.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 862daf6: Schema union types can define custom discriminant
14
+
15
+ ### Patch Changes
16
+
17
+ - 571578c: Add Booleans to pack.schema
18
+ - 7ee55de: Bump dependencies
19
+ - 4a44875: Remove bun-specific scripts and dependency
20
+
3
21
  ## 0.2.0
4
22
 
5
23
  ### Minor Changes
@@ -7,6 +7,7 @@ var ModelDefType = {
7
7
  // src/primitives.ts
8
8
  var TypeKind = {
9
9
  ARRAY: "array",
10
+ BOOLEAN: "boolean",
10
11
  DOC_REF: "docRef",
11
12
  DOUBLE: "double",
12
13
  MEDIA_REF: "mediaRef",
@@ -23,6 +24,9 @@ var String = {
23
24
  var Double = {
24
25
  type: TypeKind.DOUBLE
25
26
  };
27
+ var Boolean = {
28
+ type: TypeKind.BOOLEAN
29
+ };
26
30
  var Unknown = {
27
31
  type: TypeKind.UNKNOWN
28
32
  };
@@ -54,15 +58,19 @@ function isUnionDef(value) {
54
58
  }
55
59
 
56
60
  // src/defineUnion.ts
57
- function defineUnion(name, union) {
58
- const entries = Object.entries(union.variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);
59
- const variants = Object.fromEntries(entries);
61
+ function defineUnion(name, {
62
+ discriminant = "type",
63
+ docs,
64
+ variants
65
+ }) {
66
+ const entries = Object.entries(variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);
67
+ const resolvedVariants = Object.fromEntries(entries);
60
68
  return {
61
69
  type: ModelDefType.UNION,
62
- discriminant: "type",
70
+ discriminant,
63
71
  name,
64
- docs: union.docs,
65
- variants
72
+ docs,
73
+ variants: resolvedVariants
66
74
  };
67
75
  }
68
76
  function resolveUnionVariantArg(arg) {
@@ -175,6 +183,6 @@ function defineRecord(name, record) {
175
183
  };
176
184
  }
177
185
 
178
- export { Array, Double, ModelDefType, Optional, String, TypeKind, Unknown, createRef, defineMigration, defineRecord, defineUnion, isRecordDef, isUnionDef, modelToRef, resolveUnionVariantArg };
186
+ export { Array, Boolean, Double, ModelDefType, Optional, String, TypeKind, Unknown, createRef, defineMigration, defineRecord, defineUnion, isRecordDef, isUnionDef, modelToRef, resolveUnionVariantArg };
179
187
  //# sourceMappingURL=index.js.map
180
188
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.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,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,OAA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BAAA,CAAkB,CAAC,CAAA;AAC7C,MAAA,QAAA,CAAS,GAAG,CAAA,GAAI,aAAA;AAAA,IAClB,CAAA,MAAA,IAAW,UAAA,CAAW,CAAC,CAAA,EAAG;AAExB,MAAA,MAAM,YAAA,GAAe,IAAI,gBAAA,CAAiB,CAAC,CAAA;AAC3C,MAAA,QAAA,CAAS,GAAG,CAAA,GAAI,YAAA;AAAA,IAClB;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,GAAG,QAAA;AAAA,IACH,GAAG,UAAU,QAAQ;AAAA,GACvB;AACF;;;ACpGA,SAAS,gBAAgB,KAAA,EAAO;AAE9B,EAAA,MAAM,QAAA,GAAW,OAAO,KAAA,KAAU,UAAA,GAAa,OAAM,GAAI,KAAA;AACzD,EAAA,IAAI,WAAA,CAAY,QAAQ,CAAA,IAAK,UAAA,CAAW,QAAQ,CAAA,EAAG;AACjD,IAAA,OAAO,WAAW,QAAQ,CAAA;AAAA,EAC5B;AAGA,EAAA,OAAO,QAAA;AACT;AACO,SAAS,YAAA,CAAa,MAAM,MAAA,EAAQ;AACzC,EAAA,MAAM,UAAU,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,MAAM,EAAE,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,KAAK,eAAA,CAAgB,KAAK,CAAC,CAAC,CAAA;AACjG,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA;AACzC,EAAA,OAAO;AAAA,IACL,MAAM,YAAA,CAAa,MAAA;AAAA,IACnB,IAAA;AAAA,IACA,MAAM,MAAA,CAAO,IAAA;AAAA,IACb;AAAA,GACF;AACF","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 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 Unknown = {\n type: TypeKind.UNKNOWN\n};\nexport const Array = item => ({\n type: TypeKind.ARRAY,\n items: item\n});\nexport const Optional = item => ({\n type: TypeKind.OPTIONAL,\n item\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, union) {\n const entries = Object.entries(union.variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);\n const variants = Object.fromEntries(entries);\n return {\n type: ModelDefType.UNION,\n discriminant: \"type\",\n name: name,\n docs: union.docs,\n variants\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\";\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(previous, migration) {\n /**\n * Create a map of builders for the schema.\n *\n * Note about type assertions:\n * We use a type assertion here (SchemaBuilder<T>) because TypeScript cannot\n * track the relationship between the keys in the original schema and the\n * corresponding builder types. This is a fundamental limitation of TypeScript's\n * type system when dealing with dynamically constructed objects.\n *\n * The assertion is safe because:\n * 1. We're only adding keys that exist in the original schema\n * 2. For each key, we're creating a builder of the correct type\n * 3. The resulting object exactly matches the SchemaBuilder<T> type\n */\n const builders = {};\n for (const key in previous) {\n const v = previous[key];\n\n // Use our type guards for safer type narrowing\n if (isRecordDef(v)) {\n // This assertion is necessary because TypeScript can't track the field types\n // through the dynamic property access and object construction\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n // Similar assertion needed for union builders\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...previous,\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}"]}
1
+ {"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.ts"],"names":[],"mappings":";AAgBO,IAAM,YAAA,GAAe;AAAA,EAC1B,MAAA,EAAQ,QAAA;AAAA,EACR,KAAA,EAAO;AACT;;;ACHO,IAAM,QA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ACjG,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA;AACzC,EAAA,OAAO;AAAA,IACL,MAAM,YAAA,CAAa,MAAA;AAAA,IACnB,IAAA;AAAA,IACA,MAAM,MAAA,CAAO,IAAA;AAAA,IACb;AAAA,GACF;AACF","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};\nexport const Array = item => ({\n type: TypeKind.ARRAY,\n items: item\n});\nexport const Optional = item => ({\n type: TypeKind.OPTIONAL,\n item\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\";\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(previous, migration) {\n /**\n * Create a map of builders for the schema.\n *\n * Note about type assertions:\n * We use a type assertion here (SchemaBuilder<T>) because TypeScript cannot\n * track the relationship between the keys in the original schema and the\n * corresponding builder types. This is a fundamental limitation of TypeScript's\n * type system when dealing with dynamically constructed objects.\n *\n * The assertion is safe because:\n * 1. We're only adding keys that exist in the original schema\n * 2. For each key, we're creating a builder of the correct type\n * 3. The resulting object exactly matches the SchemaBuilder<T> type\n */\n const builders = {};\n for (const key in previous) {\n const v = previous[key];\n\n // Use our type guards for safer type narrowing\n if (isRecordDef(v)) {\n // This assertion is necessary because TypeScript can't track the field types\n // through the dynamic property access and object construction\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n // Similar assertion needed for union builders\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...previous,\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}"]}
@@ -9,6 +9,7 @@ var ModelDefType = {
9
9
  // src/primitives.ts
10
10
  var TypeKind = {
11
11
  ARRAY: "array",
12
+ BOOLEAN: "boolean",
12
13
  DOC_REF: "docRef",
13
14
  DOUBLE: "double",
14
15
  MEDIA_REF: "mediaRef",
@@ -25,6 +26,9 @@ var String = {
25
26
  var Double = {
26
27
  type: TypeKind.DOUBLE
27
28
  };
29
+ var Boolean = {
30
+ type: TypeKind.BOOLEAN
31
+ };
28
32
  var Unknown = {
29
33
  type: TypeKind.UNKNOWN
30
34
  };
@@ -56,15 +60,19 @@ function isUnionDef(value) {
56
60
  }
57
61
 
58
62
  // src/defineUnion.ts
59
- function defineUnion(name, union) {
60
- const entries = Object.entries(union.variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);
61
- const variants = Object.fromEntries(entries);
63
+ function defineUnion(name, {
64
+ discriminant = "type",
65
+ docs,
66
+ variants
67
+ }) {
68
+ const entries = Object.entries(variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);
69
+ const resolvedVariants = Object.fromEntries(entries);
62
70
  return {
63
71
  type: ModelDefType.UNION,
64
- discriminant: "type",
72
+ discriminant,
65
73
  name,
66
- docs: union.docs,
67
- variants
74
+ docs,
75
+ variants: resolvedVariants
68
76
  };
69
77
  }
70
78
  function resolveUnionVariantArg(arg) {
@@ -178,6 +186,7 @@ function defineRecord(name, record) {
178
186
  }
179
187
 
180
188
  exports.Array = Array;
189
+ exports.Boolean = Boolean;
181
190
  exports.Double = Double;
182
191
  exports.ModelDefType = ModelDefType;
183
192
  exports.Optional = Optional;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.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,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,QAAQ,CAAA,IAAA,MAAS;AAAA,EAC5B,MAAM,QAAA,CAAS,KAAA;AAAA,EACf,KAAA,EAAO;AACT,CAAA;AACO,IAAM,WAAW,CAAA,IAAA,MAAS;AAAA,EAC/B,MAAM,QAAA,CAAS,QAAA;AAAA,EACf;AACF,CAAA;;;AC1BO,SAAS,WAAW,KAAA,EAAO;AAChC,EAAA,OAAO,SAAA,CAAU,KAAA,CAAM,IAAA,EAAM,KAAA,CAAM,IAAI,CAAA;AACzC;AAMO,SAAS,SAAA,CAAU,MAAM,OAAA,EAAS;AACvC,EAAA,OAAO;AAAA,IACL,MAAM,QAAA,CAAS,GAAA;AAAA,IACf,IAAA;AAAA,IACA;AAAA,GACF;AACF;AAKO,SAAS,YAAY,KAAA,EAAO;AACjC,EAAA,OAAO,KAAA,IAAS,IAAA,IA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GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,KAAK,eAAA,CAAgB,KAAK,CAAC,CAAC,CAAA;AACjG,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA;AACzC,EAAA,OAAO;AAAA,IACL,MAAM,YAAA,CAAa,MAAA;AAAA,IACnB,IAAA;AAAA,IACA,MAAM,MAAA,CAAO,IAAA;AAAA,IACb;AAAA,GACF;AACF","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 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 Unknown = {\n type: TypeKind.UNKNOWN\n};\nexport const Array = item => ({\n type: TypeKind.ARRAY,\n items: item\n});\nexport const Optional = item => ({\n type: TypeKind.OPTIONAL,\n item\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, union) {\n const entries = Object.entries(union.variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);\n const variants = Object.fromEntries(entries);\n return {\n type: ModelDefType.UNION,\n discriminant: \"type\",\n name: name,\n docs: union.docs,\n variants\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\";\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(previous, migration) {\n /**\n * Create a map of builders for the schema.\n *\n * Note about type assertions:\n * We use a type assertion here (SchemaBuilder<T>) because TypeScript cannot\n * track the relationship between the keys in the original schema and the\n * corresponding builder types. This is a fundamental limitation of TypeScript's\n * type system when dealing with dynamically constructed objects.\n *\n * The assertion is safe because:\n * 1. We're only adding keys that exist in the original schema\n * 2. For each key, we're creating a builder of the correct type\n * 3. The resulting object exactly matches the SchemaBuilder<T> type\n */\n const builders = {};\n for (const key in previous) {\n const v = previous[key];\n\n // Use our type guards for safer type narrowing\n if (isRecordDef(v)) {\n // This assertion is necessary because TypeScript can't track the field types\n // through the dynamic property access and object construction\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n // Similar assertion needed for union builders\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...previous,\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}"]}
1
+ {"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.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;AACO,IAAM,QAAQ,CAAA,IAAA,MAAS;AAAA,EAC5B,MAAM,QAAA,CAAS,KAAA;AAAA,EACf,KAAA,EAAO;AACT,CAAA;AACO,IAAM,WAAW,CAAA,IAAA,MAAS;AAAA,EAC/B,MAAM,QAAA,CAAS,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GA,SAAS,gBAAgB,KAAA,EAAO;AAE9B,EAAA,MAAM,QAAA,GAAW,OAAO,KAAA,KAAU,UAAA,GAAa,OAAM,GAAI,KAAA;AACzD,EAAA,IAAI,WAAA,CAAY,QAAQ,CAAA,IAAK,UAAA,CAAW,QAAQ,CAAA,EAAG;AACjD,IAAA,OAAO,WAAW,QAAQ,CAAA;AAAA,EAC5B;AAGA,EAAA,OAAO,QAAA;AACT;AACO,SAAS,YAAA,CAAa,MAAM,MAAA,EAAQ;AACzC,EAAA,MAAM,UAAU,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,MAAM,EAAE,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,KAAK,eAAA,CAAgB,KAAK,CAAC,CAAC,CAAA;AACjG,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA;AACzC,EAAA,OAAO;AAAA,IACL,MAAM,YAAA,CAAa,MAAA;AAAA,IACnB,IAAA;AAAA,IACA,MAAM,MAAA,CAAO,IAAA;AAAA,IACb;AAAA,GACF;AACF","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};\nexport const Array = item => ({\n type: TypeKind.ARRAY,\n items: item\n});\nexport const Optional = item => ({\n type: TypeKind.OPTIONAL,\n item\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\";\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(previous, migration) {\n /**\n * Create a map of builders for the schema.\n *\n * Note about type assertions:\n * We use a type assertion here (SchemaBuilder<T>) because TypeScript cannot\n * track the relationship between the keys in the original schema and the\n * corresponding builder types. This is a fundamental limitation of TypeScript's\n * type system when dealing with dynamically constructed objects.\n *\n * The assertion is safe because:\n * 1. We're only adding keys that exist in the original schema\n * 2. For each key, we're creating a builder of the correct type\n * 3. The resulting object exactly matches the SchemaBuilder<T> type\n */\n const builders = {};\n for (const key in previous) {\n const v = previous[key];\n\n // Use our type guards for safer type narrowing\n if (isRecordDef(v)) {\n // This assertion is necessary because TypeScript can't track the field types\n // through the dynamic property access and object construction\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n // Similar assertion needed for union builders\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...previous,\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}"]}
@@ -1,5 +1,6 @@
1
1
  declare const TypeKind: {
2
2
  readonly ARRAY: "array";
3
+ readonly BOOLEAN: "boolean";
3
4
  readonly DOC_REF: "docRef";
4
5
  readonly DOUBLE: "double";
5
6
  readonly MEDIA_REF: "mediaRef";
@@ -31,7 +32,7 @@ type ObjectRef = {
31
32
  type UserRef = {
32
33
  readonly type: typeof TypeKind.USER_REF;
33
34
  };
34
- type Type = Array | DocRef | Double | MediaRef | ObjectRef | Optional | Ref | String | Unknown | UserRef;
35
+ type Type = Array | Boolean | DocRef | Double | MediaRef | ObjectRef | Optional | Ref | String | Unknown | UserRef;
35
36
  type String = {
36
37
  readonly type: typeof TypeKind.STRING;
37
38
  };
@@ -40,6 +41,10 @@ type Double = {
40
41
  readonly type: typeof TypeKind.DOUBLE;
41
42
  };
42
43
  declare const Double: Double;
44
+ type Boolean = {
45
+ readonly type: typeof TypeKind.BOOLEAN;
46
+ };
47
+ declare const Boolean: Boolean;
43
48
  type Unknown = {
44
49
  readonly type: typeof TypeKind.UNKNOWN;
45
50
  };
@@ -85,10 +90,16 @@ type ResolvedUnionVariants<T extends UnionVariantArgs> = {
85
90
  readonly [K in keyof T]: Ref;
86
91
  };
87
92
  type UnionArgs<T extends UnionVariantArgs> = {
93
+ /**
94
+ * The field name used to discriminate between union variants.
95
+ *
96
+ * @default "type"
97
+ */
98
+ readonly discriminant?: string;
88
99
  readonly docs: string;
89
100
  readonly variants: T;
90
101
  };
91
- declare function defineUnion<const TVariants extends UnionVariantArgs>(name: string, union: UnionArgs<TVariants>): UnionDef<ResolvedUnionVariants<TVariants>>;
102
+ declare function defineUnion<const TVariants extends UnionVariantArgs>(name: string, { discriminant, docs, variants, }: UnionArgs<TVariants>): UnionDef<ResolvedUnionVariants<TVariants>>;
92
103
  declare function resolveUnionVariantArg(arg: UnionVariantArg): Ref;
93
104
 
94
105
  type ReturnedSchema = Record<string, RecordDef | UnionDef>;
@@ -144,4 +155,4 @@ declare function isRecordDef(value: unknown): value is RecordDef;
144
155
  */
145
156
  declare function isUnionDef(value: unknown): value is UnionDef;
146
157
 
147
- export { Array, type DocRef, Double, type FieldArg, type FieldArgExplicit, type FieldArgExplicitOf, type FieldArgs, type MediaRef, type ModelDef, ModelDefType, 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, String, type Type, TypeKind, type UnionArgs, type UnionBuilder, type UnionDef, type UnionVariantArg, type UnionVariantArgExplicit, type UnionVariantArgs, type UnionVariants, Unknown, type UserRef, createRef, defineMigration, defineRecord, defineUnion, isRecordDef, isUnionDef, modelToRef, resolveUnionVariantArg };
158
+ export { Array, Boolean, type DocRef, Double, type FieldArg, type FieldArgExplicit, type FieldArgExplicitOf, type FieldArgs, type MediaRef, type ModelDef, ModelDefType, 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, String, type Type, TypeKind, type UnionArgs, type UnionBuilder, type UnionDef, type UnionVariantArg, type UnionVariantArgExplicit, type UnionVariantArgs, type UnionVariants, Unknown, type UserRef, createRef, defineMigration, defineRecord, defineUnion, isRecordDef, isUnionDef, modelToRef, resolveUnionVariantArg };
@@ -7,6 +7,7 @@ var ModelDefType = {
7
7
  // src/primitives.ts
8
8
  var TypeKind = {
9
9
  ARRAY: "array",
10
+ BOOLEAN: "boolean",
10
11
  DOC_REF: "docRef",
11
12
  DOUBLE: "double",
12
13
  MEDIA_REF: "mediaRef",
@@ -23,6 +24,9 @@ var String = {
23
24
  var Double = {
24
25
  type: TypeKind.DOUBLE
25
26
  };
27
+ var Boolean = {
28
+ type: TypeKind.BOOLEAN
29
+ };
26
30
  var Unknown = {
27
31
  type: TypeKind.UNKNOWN
28
32
  };
@@ -54,15 +58,19 @@ function isUnionDef(value) {
54
58
  }
55
59
 
56
60
  // src/defineUnion.ts
57
- function defineUnion(name, union) {
58
- const entries = Object.entries(union.variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);
59
- const variants = Object.fromEntries(entries);
61
+ function defineUnion(name, {
62
+ discriminant = "type",
63
+ docs,
64
+ variants
65
+ }) {
66
+ const entries = Object.entries(variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);
67
+ const resolvedVariants = Object.fromEntries(entries);
60
68
  return {
61
69
  type: ModelDefType.UNION,
62
- discriminant: "type",
70
+ discriminant,
63
71
  name,
64
- docs: union.docs,
65
- variants
72
+ docs,
73
+ variants: resolvedVariants
66
74
  };
67
75
  }
68
76
  function resolveUnionVariantArg(arg) {
@@ -175,6 +183,6 @@ function defineRecord(name, record) {
175
183
  };
176
184
  }
177
185
 
178
- export { Array, Double, ModelDefType, Optional, String, TypeKind, Unknown, createRef, defineMigration, defineRecord, defineUnion, isRecordDef, isUnionDef, modelToRef, resolveUnionVariantArg };
186
+ export { Array, Boolean, Double, ModelDefType, Optional, String, TypeKind, Unknown, createRef, defineMigration, defineRecord, defineUnion, isRecordDef, isUnionDef, modelToRef, resolveUnionVariantArg };
179
187
  //# sourceMappingURL=index.js.map
180
188
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.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,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,QAAQ,CAAA,IAAA,MAAS;AAAA,EAC5B,MAAM,QAAA,CAAS,KAAA;AAAA,EACf,KAAA,EAAO;AACT,CAAA;AACO,IAAM,WAAW,CAAA,IAAA,MAAS;AAAA,EAC/B,MAAM,QAAA,CAAS,QAAA;AAAA,EACf;AACF,CA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AAW,OAAO,KAAA,KAAU,UAAA,GAAa,OAAM,GAAI,KAAA;AACzD,EAAA,IAAI,WAAA,CAAY,QAAQ,CAAA,IAAK,UAAA,CAAW,QAAQ,CAAA,EAAG;AACjD,IAAA,OAAO,WAAW,QAAQ,CAAA;AAAA,EAC5B;AAGA,EAAA,OAAO,QAAA;AACT;AACO,SAAS,YAAA,CAAa,MAAM,MAAA,EAAQ;AACzC,EAAA,MAAM,UAAU,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,MAAM,EAAE,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,KAAK,eAAA,CAAgB,KAAK,CAAC,CAAC,CAAA;AACjG,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA;AACzC,EAAA,OAAO;AAAA,IACL,MAAM,YAAA,CAAa,MAAA;AAAA,IACnB,IAAA;AAAA,IACA,MAAM,MAAA,CAAO,IAAA;AAAA,IACb;AAAA,GACF;AACF","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 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 Unknown = {\n type: TypeKind.UNKNOWN\n};\nexport const Array = item => ({\n type: TypeKind.ARRAY,\n items: item\n});\nexport const Optional = item => ({\n type: TypeKind.OPTIONAL,\n item\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, union) {\n const entries = Object.entries(union.variants).map(([key, value]) => [key, resolveUnionVariantArg(value)]);\n const variants = Object.fromEntries(entries);\n return {\n type: ModelDefType.UNION,\n discriminant: \"type\",\n name: name,\n docs: union.docs,\n variants\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\";\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(previous, migration) {\n /**\n * Create a map of builders for the schema.\n *\n * Note about type assertions:\n * We use a type assertion here (SchemaBuilder<T>) because TypeScript cannot\n * track the relationship between the keys in the original schema and the\n * corresponding builder types. This is a fundamental limitation of TypeScript's\n * type system when dealing with dynamically constructed objects.\n *\n * The assertion is safe because:\n * 1. We're only adding keys that exist in the original schema\n * 2. For each key, we're creating a builder of the correct type\n * 3. The resulting object exactly matches the SchemaBuilder<T> type\n */\n const builders = {};\n for (const key in previous) {\n const v = previous[key];\n\n // Use our type guards for safer type narrowing\n if (isRecordDef(v)) {\n // This assertion is necessary because TypeScript can't track the field types\n // through the dynamic property access and object construction\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n // Similar assertion needed for union builders\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...previous,\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}"]}
1
+ {"version":3,"sources":["../../src/defs.ts","../../src/primitives.ts","../../src/utils.ts","../../src/defineUnion.ts","../../src/defineMigration.ts","../../src/defineRecord.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;AAA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QAAA,CAAS,GAAG,CAAA,GAAI,aAAA;AAAA,IAClB,CAAA,MAAA,IAAW,UAAA,CAAW,CAAC,CAAA,EAAG;AAExB,MAAA,MAAM,YAAA,GAAe,IAAI,gBAAA,CAAiB,CAAC,CAAA;AAC3C,MAAA,QAAA,CAAS,GAAG,CAAA,GAAI,YAAA;AAAA,IAClB;AAAA,EACF;AACA,EAAA,OAAO;AAAA,IACL,GAAG,QAAA;AAAA,IACH,GAAG,UAAU,QAAQ;AAAA,GACvB;AACF;;;ACpGA,SAAS,gBAAgB,KAAA,EAAO;AAE9B,EAAA,MAAM,QAAA,GAAW,OAAO,KAAA,KAAU,UAAA,GAAa,OAAM,GAAI,KAAA;AACzD,EAAA,IAAI,WAAA,CAAY,QAAQ,CAAA,IAAK,UAAA,CAAW,QAAQ,CAAA,EAAG;AACjD,IAAA,OAAO,WAAW,QAAQ,CAAA;AAAA,EAC5B;AAGA,EAAA,OAAO,QAAA;AACT;AACO,SAAS,YAAA,CAAa,MAAM,MAAA,EAAQ;AACzC,EAAA,MAAM,UAAU,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,MAAM,EAAE,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,KAAK,CAAA,KAAM,CAAC,KAAK,eAAA,CAAgB,KAAK,CAAC,CAAC,CAAA;AACjG,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,OAAO,CAAA;AACzC,EAAA,OAAO;AAAA,IACL,MAAM,YAAA,CAAa,MAAA;AAAA,IACnB,IAAA;AAAA,IACA,MAAM,MAAA,CAAO,IAAA;AAAA,IACb;AAAA,GACF;AACF","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};\nexport const Array = item => ({\n type: TypeKind.ARRAY,\n items: item\n});\nexport const Optional = item => ({\n type: TypeKind.OPTIONAL,\n item\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\";\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(previous, migration) {\n /**\n * Create a map of builders for the schema.\n *\n * Note about type assertions:\n * We use a type assertion here (SchemaBuilder<T>) because TypeScript cannot\n * track the relationship between the keys in the original schema and the\n * corresponding builder types. This is a fundamental limitation of TypeScript's\n * type system when dealing with dynamically constructed objects.\n *\n * The assertion is safe because:\n * 1. We're only adding keys that exist in the original schema\n * 2. For each key, we're creating a builder of the correct type\n * 3. The resulting object exactly matches the SchemaBuilder<T> type\n */\n const builders = {};\n for (const key in previous) {\n const v = previous[key];\n\n // Use our type guards for safer type narrowing\n if (isRecordDef(v)) {\n // This assertion is necessary because TypeScript can't track the field types\n // through the dynamic property access and object construction\n const recordBuilder = new RecordBuilderImpl(v);\n builders[key] = recordBuilder;\n } else if (isUnionDef(v)) {\n // Similar assertion needed for union builders\n const unionBuilder = new UnionBuilderImpl(v);\n builders[key] = unionBuilder;\n }\n }\n return {\n ...previous,\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}"]}
@@ -5,8 +5,14 @@ export type UnionVariantArg = UnionVariantArgExplicit | (() => UnionVariantArgEx
5
5
  export type UnionVariantArgs = Record<string, UnionVariantArg>;
6
6
  export type ResolvedUnionVariants<T extends UnionVariantArgs> = { readonly [K in keyof T] : Ref };
7
7
  export type UnionArgs<T extends UnionVariantArgs> = {
8
+ /**
9
+ * The field name used to discriminate between union variants.
10
+ *
11
+ * @default "type"
12
+ */
13
+ readonly discriminant?: string;
8
14
  readonly docs: string;
9
15
  readonly variants: T;
10
16
  };
11
- export declare function defineUnion<const TVariants extends UnionVariantArgs>(name: string, union: UnionArgs<TVariants>): UnionDef<ResolvedUnionVariants<TVariants>>;
17
+ export declare function defineUnion<const TVariants extends UnionVariantArgs>(name: string, { discriminant, docs, variants }: UnionArgs<TVariants>): UnionDef<ResolvedUnionVariants<TVariants>>;
12
18
  export declare function resolveUnionVariantArg(arg: UnionVariantArg): Ref;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,cAAc,UAAU,gBAAgB;AAExC,cAAc,WAAW;AAIzB,YAAY,0BAA0B,MAAM;AAC5C,YAAY,kBAAkB,iCAAiC;AAC/D,YAAY,mBAAmB,eAAe;AAE9C,YAAY,sBAAsB,UAAU,gCAChC,WAAW,KAAI;AAG3B,YAAY,UAAU,UAAU,oBAAoB;UACzC;UACA,UAAU;;AAGrB,OAAO,iBAAS,kBAAkB,kBAAkB,kBAClD,cACA,OAAO,UAAU,aAChB,SAAS,sBAAsB;AAgBlC,OAAO,iBAAS,uBAAuB,KAAK,kBAAkB","names":[],"sources":["../../src/defineUnion.ts"],"version":3,"file":"defineUnion.d.ts"}
1
+ {"mappings":"AAgBA,cAAc,UAAU,gBAAgB;AAExC,cAAc,WAAW;AAIzB,YAAY,0BAA0B,MAAM;AAC5C,YAAY,kBAAkB,iCAAiC;AAC/D,YAAY,mBAAmB,eAAe;AAE9C,YAAY,sBAAsB,UAAU,gCAChC,WAAW,KAAI;AAG3B,YAAY,UAAU,UAAU,oBAAoB;;;;;;UAMzC;UACA;UACA,UAAU;;AAGrB,OAAO,iBAAS,kBAAkB,kBAAkB,kBAClD,cACA,EACE,cACA,MACA,YACC,UAAU,aACZ,SAAS,sBAAsB;AAgBlC,OAAO,iBAAS,uBAAuB,KAAK,kBAAkB","names":[],"sources":["../../src/defineUnion.ts"],"version":3,"file":"defineUnion.d.ts"}
@@ -1,5 +1,6 @@
1
1
  export declare const TypeKind: {
2
2
  readonly ARRAY: "array";
3
+ readonly BOOLEAN: "boolean";
3
4
  readonly DOC_REF: "docRef";
4
5
  readonly DOUBLE: "double";
5
6
  readonly MEDIA_REF: "mediaRef";
@@ -17,6 +18,9 @@ export type String = {
17
18
  export type Double = {
18
19
  readonly type: typeof TypeKind.DOUBLE;
19
20
  };
21
+ export type Boolean = {
22
+ readonly type: typeof TypeKind.BOOLEAN;
23
+ };
20
24
  interface TypeBase {
21
25
  readonly type: TypeKind;
22
26
  }
@@ -48,9 +52,10 @@ export type ObjectRef = {
48
52
  export type UserRef = {
49
53
  readonly type: typeof TypeKind.USER_REF;
50
54
  };
51
- export type Type = Array | DocRef | Double | MediaRef | ObjectRef | Optional | Ref | String | Unknown | UserRef;
55
+ export type Type = Array | Boolean | DocRef | Double | MediaRef | ObjectRef | Optional | Ref | String | Unknown | UserRef;
52
56
  export declare const String: String;
53
57
  export declare const Double: Double;
58
+ export declare const Boolean: Boolean;
54
59
  export declare const Unknown: Unknown;
55
60
  export declare const Array: <T extends TypeBase>(item: T) => Array<T>;
56
61
  export declare const Optional: <T extends TypeBase>(item: T) => Optional<T>;
@@ -1 +1 @@
1
- {"mappings":"AAgBA,OAAO,cAAM;UACX,OAAO;UACP,SAAS;UACT,QAAQ;UACR,WAAW;UACX,YAAY;UACZ,UAAU;UACV,KAAK;UACL,QAAQ;UACR,SAAS;UACT,UAAU;;AAGZ,YAAY,kBAAkB,sBAAsB;AAEpD,YAAY,SAAS;UACV,aAAa,SAAS;;AAGjC,YAAY,SAAS;UACV,aAAa,SAAS;;UAIvB,SAAS;UACR,MAAM;;AAGjB,YAAY,MAAM,UAAU,WAAW,YAAY;UACxC,aAAa,SAAS;UACtB,OAAO;;AAIlB,YAAY,MAAM;UACP,aAAa,SAAS;UACtB,SAAS,WAAW;UACpB;;AAGX,YAAY,SAAS,UAAU,WAAW,YAAY;UAC3C,aAAa,SAAS;UACtB,MAAM;;AAGjB,YAAY,UAAU;UACX,aAAa,SAAS;;AAGjC,YAAY,SAAS;UACV,aAAa,SAAS;;AAGjC,YAAY,WAAW;UACZ,aAAa,SAAS;;AAGjC,YAAY,YAAY;UACb,aAAa,SAAS;;AAGjC,YAAY,UAAU;UACX,aAAa,SAAS;;AAGjC,YAAY,OACR,QACA,SACA,SACA,WACA,YACA,WACA,MACA,SACA,UACA;AAEJ,OAAO,cAAMA,QAAQ;AACrB,OAAO,cAAMC,QAAQ;AACrB,OAAO,cAAMC,SAAS;AACtB,OAAO,cAAM,QAAS,UAAU,UAAU,MAAM,MAAI,MAAM;AAI1D,OAAO,cAAM,WAAY,UAAU,UAAU,MAAM,MAAI,SAAS","names":["String: String","Double: Double","Unknown: Unknown"],"sources":["../../src/primitives.ts"],"version":3,"file":"primitives.d.ts"}
1
+ {"mappings":"AAgBA,OAAO,cAAM;UACX,OAAO;UACP,SAAS;UACT,SAAS;UACT,QAAQ;UACR,WAAW;UACX,YAAY;UACZ,UAAU;UACV,KAAK;UACL,QAAQ;UACR,SAAS;UACT,UAAU;;AAGZ,YAAY,kBAAkB,sBAAsB;AAEpD,YAAY,SAAS;UACV,aAAa,SAAS;;AAGjC,YAAY,SAAS;UACV,aAAa,SAAS;;AAGjC,YAAY,UAAU;UACX,aAAa,SAAS;;UAIvB,SAAS;UACR,MAAM;;AAGjB,YAAY,MAAM,UAAU,WAAW,YAAY;UACxC,aAAa,SAAS;UACtB,OAAO;;AAIlB,YAAY,MAAM;UACP,aAAa,SAAS;UACtB,SAAS,WAAW;UACpB;;AAGX,YAAY,SAAS,UAAU,WAAW,YAAY;UAC3C,aAAa,SAAS;UACtB,MAAM;;AAGjB,YAAY,UAAU;UACX,aAAa,SAAS;;AAGjC,YAAY,SAAS;UACV,aAAa,SAAS;;AAGjC,YAAY,WAAW;UACZ,aAAa,SAAS;;AAGjC,YAAY,YAAY;UACb,aAAa,SAAS;;AAGjC,YAAY,UAAU;UACX,aAAa,SAAS;;AAGjC,YAAY,OACR,QACA,UACA,SACA,SACA,WACA,YACA,WACA,MACA,SACA,UACA;AAEJ,OAAO,cAAMA,QAAQ;AACrB,OAAO,cAAMC,QAAQ;AACrB,OAAO,cAAMC,SAAS;AACtB,OAAO,cAAMC,SAAS;AACtB,OAAO,cAAM,QAAS,UAAU,UAAU,MAAM,MAAI,MAAM;AAI1D,OAAO,cAAM,WAAY,UAAU,UAAU,MAAM,MAAI,SAAS","names":["String: String","Double: Double","Boolean: Boolean","Unknown: Unknown"],"sources":["../../src/primitives.ts"],"version":3,"file":"primitives.d.ts"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palantir/pack.schema",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "API package for PACK schema functionality",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -28,9 +28,9 @@
28
28
  }
29
29
  },
30
30
  "devDependencies": {
31
- "rimraf": "^6.0.1",
31
+ "rimraf": "^6.1.2",
32
32
  "tslib": "^2.8.1",
33
- "typescript": "^5.9.2",
33
+ "typescript": "^5.9.3",
34
34
  "@palantir/pack.monorepo.tsconfig": "~0.4.3"
35
35
  },
36
36
  "publishConfig": {
@@ -48,6 +48,7 @@ describe("defineRecord", () => {
48
48
  username: P.String,
49
49
  email: P.Optional(P.String),
50
50
  age: P.Optional(P.Double),
51
+ active: P.Optional(P.Boolean),
51
52
  },
52
53
  });
53
54
 
@@ -60,8 +61,12 @@ describe("defineRecord", () => {
60
61
  type: "optional",
61
62
  item: { type: "double" },
62
63
  });
64
+ expect(UserRecord.fields.active).toEqual({
65
+ type: "optional",
66
+ item: { type: "boolean" },
67
+ });
63
68
 
64
- assertExactKeys<typeof UserRecord.fields, "username" | "email" | "age">();
69
+ assertExactKeys<typeof UserRecord.fields, "username" | "email" | "age" | "active">();
65
70
  assertTypeEquals<typeof UserRecord.fields.username, String>();
66
71
  assertTypeEquals<typeof UserRecord.fields.email, Optional<String>>();
67
72
  assertTypeEquals<typeof UserRecord.fields.age, Optional<Double>>();
@@ -228,4 +228,43 @@ describe("defineUnion", () => {
228
228
  "first" | "second" | "third" | "fourth"
229
229
  >();
230
230
  });
231
+
232
+ it("should support custom discriminant field", () => {
233
+ const CatRecord = defineRecord("Cat", {
234
+ docs: "A cat",
235
+ fields: {
236
+ meow: P.String,
237
+ },
238
+ });
239
+
240
+ const DogRecord = defineRecord("Dog", {
241
+ docs: "A dog",
242
+ fields: {
243
+ bark: P.String,
244
+ },
245
+ });
246
+
247
+ const AnimalUnion = defineUnion("Animal", {
248
+ discriminant: "kind",
249
+ docs: "An animal union with custom discriminant",
250
+ variants: {
251
+ cat: CatRecord,
252
+ dog: DogRecord,
253
+ },
254
+ });
255
+
256
+ expect(AnimalUnion.discriminant).toBe("kind");
257
+ expect(AnimalUnion.type).toBe("union");
258
+ expect(AnimalUnion.name).toBe("Animal");
259
+ expect(AnimalUnion.variants.cat).toEqual({
260
+ type: "ref",
261
+ name: "Cat",
262
+ refType: "record",
263
+ });
264
+ expect(AnimalUnion.variants.dog).toEqual({
265
+ type: "ref",
266
+ name: "Dog",
267
+ refType: "record",
268
+ });
269
+ });
231
270
  });
@@ -38,6 +38,16 @@ describe("primitives", () => {
38
38
  });
39
39
  });
40
40
 
41
+ describe("Boolean", () => {
42
+ it("should create a boolean type", () => {
43
+ expect(P.Boolean).toEqual({ type: "boolean" });
44
+ });
45
+
46
+ it("should have correct type property", () => {
47
+ expect(P.Boolean.type).toBe("boolean");
48
+ });
49
+ });
50
+
41
51
  describe("Array", () => {
42
52
  it("should create an array of strings", () => {
43
53
  const stringArray = P.Array(P.String);
@@ -76,6 +86,14 @@ describe("primitives", () => {
76
86
  },
77
87
  });
78
88
  });
89
+
90
+ it("should create an array of booleans", () => {
91
+ const booleanArray = P.Array(P.Boolean);
92
+ expect(booleanArray).toEqual({
93
+ type: "array",
94
+ items: { type: "boolean" },
95
+ });
96
+ });
79
97
  });
80
98
 
81
99
  describe("Optional", () => {
@@ -116,6 +134,36 @@ describe("primitives", () => {
116
134
  },
117
135
  });
118
136
  });
137
+
138
+ it("should create an optional boolean", () => {
139
+ const optionalBoolean = P.Optional(P.Boolean);
140
+ expect(optionalBoolean).toEqual({
141
+ type: "optional",
142
+ item: { type: "boolean" },
143
+ });
144
+ });
145
+
146
+ it("should create optional array of booleans", () => {
147
+ const optionalBooleanArray = P.Optional(P.Array(P.Boolean));
148
+ expect(optionalBooleanArray).toEqual({
149
+ type: "optional",
150
+ item: {
151
+ type: "array",
152
+ items: { type: "boolean" },
153
+ },
154
+ });
155
+ });
156
+
157
+ it("should create array of optional booleans", () => {
158
+ const arrayOfOptionalBooleans = P.Array(P.Optional(P.Boolean));
159
+ expect(arrayOfOptionalBooleans).toEqual({
160
+ type: "array",
161
+ items: {
162
+ type: "optional",
163
+ item: { type: "boolean" },
164
+ },
165
+ });
166
+ });
119
167
  });
120
168
 
121
169
  describe("Type combinations", () => {
@@ -149,5 +197,26 @@ describe("primitives", () => {
149
197
  expect(array1).toEqual(array2);
150
198
  expect(array1 === array2).toBe(false);
151
199
  });
200
+
201
+ it("should create complex nested structures with booleans", () => {
202
+ const complexBooleanType = P.Optional(P.Array(P.Optional(P.Boolean)));
203
+ expect(complexBooleanType).toEqual({
204
+ type: "optional",
205
+ item: {
206
+ type: "array",
207
+ items: {
208
+ type: "optional",
209
+ item: { type: "boolean" },
210
+ },
211
+ },
212
+ });
213
+ });
214
+
215
+ it("should maintain immutability of boolean primitive", () => {
216
+ const boolean1 = P.Boolean;
217
+ const boolean2 = P.Boolean;
218
+ expect(boolean1).toBe(boolean2);
219
+ expect(boolean1 === boolean2).toBe(true);
220
+ });
152
221
  });
153
222
  });
@@ -29,26 +29,36 @@ export type ResolvedUnionVariants<T extends UnionVariantArgs> = {
29
29
  };
30
30
 
31
31
  export type UnionArgs<T extends UnionVariantArgs> = {
32
+ /**
33
+ * The field name used to discriminate between union variants.
34
+ *
35
+ * @default "type"
36
+ */
37
+ readonly discriminant?: string;
32
38
  readonly docs: string;
33
39
  readonly variants: T;
34
40
  };
35
41
 
36
42
  export function defineUnion<const TVariants extends UnionVariantArgs>(
37
43
  name: string,
38
- union: UnionArgs<TVariants>,
44
+ {
45
+ discriminant = "type",
46
+ docs,
47
+ variants,
48
+ }: UnionArgs<TVariants>,
39
49
  ): UnionDef<ResolvedUnionVariants<TVariants>> {
40
- const entries = Object.entries(union.variants).map(
50
+ const entries = Object.entries(variants).map(
41
51
  ([key, value]) => [key, resolveUnionVariantArg(value)] as const,
42
52
  );
43
53
 
44
- const variants = Object.fromEntries(entries) as ResolvedUnionVariants<TVariants>;
54
+ const resolvedVariants = Object.fromEntries(entries) as ResolvedUnionVariants<TVariants>;
45
55
 
46
56
  return {
47
57
  type: ModelDefType.UNION,
48
- discriminant: "type",
49
- name: name,
50
- docs: union.docs,
51
- variants,
58
+ discriminant,
59
+ name,
60
+ docs,
61
+ variants: resolvedVariants,
52
62
  };
53
63
  }
54
64
 
package/src/primitives.ts CHANGED
@@ -16,6 +16,7 @@
16
16
 
17
17
  export const TypeKind = {
18
18
  ARRAY: "array",
19
+ BOOLEAN: "boolean",
19
20
  DOC_REF: "docRef",
20
21
  DOUBLE: "double",
21
22
  MEDIA_REF: "mediaRef",
@@ -37,6 +38,10 @@ export type Double = {
37
38
  readonly type: typeof TypeKind.DOUBLE;
38
39
  };
39
40
 
41
+ export type Boolean = {
42
+ readonly type: typeof TypeKind.BOOLEAN;
43
+ };
44
+
40
45
  // Forward declaration to avoid circular reference
41
46
  interface TypeBase {
42
47
  readonly type: TypeKind;
@@ -81,6 +86,7 @@ export type UserRef = {
81
86
 
82
87
  export type Type =
83
88
  | Array
89
+ | Boolean
84
90
  | DocRef
85
91
  | Double
86
92
  | MediaRef
@@ -93,6 +99,7 @@ export type Type =
93
99
 
94
100
  export const String: String = { type: TypeKind.STRING };
95
101
  export const Double: Double = { type: TypeKind.DOUBLE };
102
+ export const Boolean: Boolean = { type: TypeKind.BOOLEAN };
96
103
  export const Unknown: Unknown = { type: TypeKind.UNKNOWN };
97
104
  export const Array = <T extends TypeBase>(item: T): Array<T> => ({
98
105
  type: TypeKind.ARRAY,