@osdk/api 2.8.0-beta.8 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/build/browser/aggregate/IntervalRule.js +2 -0
  3. package/build/browser/aggregate/IntervalRule.js.map +1 -0
  4. package/build/browser/aggregate/StringFilter.js.map +1 -1
  5. package/build/browser/aggregate/WhereClause.js.map +1 -1
  6. package/build/browser/definitions/LinkDefinitions.js.map +1 -1
  7. package/build/browser/derivedProperties/DerivedProperty.js.map +1 -1
  8. package/build/browser/index.js.map +1 -1
  9. package/build/browser/mapping/DataValueMapping.js.map +1 -1
  10. package/build/browser/object/Media.js.map +1 -1
  11. package/build/browser/ontology/ActionDefinition.js.map +1 -1
  12. package/build/browser/ontology/ObjectTypeDefinition.js.map +1 -1
  13. package/build/browser/ontology/QueryDefinition.js.map +1 -1
  14. package/build/browser/public/shapes-internal.js +2 -0
  15. package/build/browser/public/shapes-internal.js.map +1 -0
  16. package/build/browser/public/unstable.js +2 -0
  17. package/build/browser/public/unstable.js.map +1 -1
  18. package/build/browser/queries/Queries.js.map +1 -1
  19. package/build/browser/shapes/InlineShapeConfig.js +2 -0
  20. package/build/browser/shapes/InlineShapeConfig.js.map +1 -0
  21. package/build/browser/shapes/ShapeBuilder.js +243 -0
  22. package/build/browser/shapes/ShapeBuilder.js.map +1 -0
  23. package/build/browser/shapes/ShapeDefinition.js +59 -0
  24. package/build/browser/shapes/ShapeDefinition.js.map +1 -0
  25. package/build/browser/shapes/computeShapeId.js +97 -0
  26. package/build/browser/shapes/computeShapeId.js.map +1 -0
  27. package/build/browser/shapes/configToShapeDefinition.js +115 -0
  28. package/build/browser/shapes/configToShapeDefinition.js.map +1 -0
  29. package/build/browser/{definitions/LinkDefinitions.test.js → shapes/index.js} +16 -11
  30. package/build/browser/shapes/index.js.map +1 -0
  31. package/build/browser/shapes/internal.js +2 -0
  32. package/build/browser/shapes/internal.js.map +1 -0
  33. package/build/browser/test/EmployeeApiTest.js +3 -1
  34. package/build/browser/test/EmployeeApiTest.js.map +1 -1
  35. package/build/cjs/{ObjectSet-CqVqDXKn.d.cts → ObjectSet-DxD7I6OR.d.cts} +107 -15
  36. package/build/cjs/index.d.cts +11 -5
  37. package/build/cjs/public/shapes-internal.cjs +4 -0
  38. package/build/cjs/public/shapes-internal.cjs.map +1 -0
  39. package/build/cjs/public/shapes-internal.d.cts +4 -0
  40. package/build/cjs/public/unstable.cjs +401 -0
  41. package/build/cjs/public/unstable.cjs.map +1 -1
  42. package/build/cjs/public/unstable.d.cts +57 -3
  43. package/build/cjs/shapes-internal-C7-hN21K.d.cts +152 -0
  44. package/build/esm/aggregate/IntervalRule.js +2 -0
  45. package/build/esm/aggregate/IntervalRule.js.map +1 -0
  46. package/build/esm/aggregate/StringFilter.js.map +1 -1
  47. package/build/esm/aggregate/WhereClause.js.map +1 -1
  48. package/build/esm/definitions/LinkDefinitions.js.map +1 -1
  49. package/build/esm/derivedProperties/DerivedProperty.js.map +1 -1
  50. package/build/esm/index.js.map +1 -1
  51. package/build/esm/mapping/DataValueMapping.js.map +1 -1
  52. package/build/esm/object/Media.js.map +1 -1
  53. package/build/esm/ontology/ActionDefinition.js.map +1 -1
  54. package/build/esm/ontology/ObjectTypeDefinition.js.map +1 -1
  55. package/build/esm/ontology/QueryDefinition.js.map +1 -1
  56. package/build/esm/public/shapes-internal.js +2 -0
  57. package/build/esm/public/shapes-internal.js.map +1 -0
  58. package/build/esm/public/unstable.js +2 -0
  59. package/build/esm/public/unstable.js.map +1 -1
  60. package/build/esm/queries/Queries.js.map +1 -1
  61. package/build/esm/shapes/InlineShapeConfig.js +2 -0
  62. package/build/esm/shapes/InlineShapeConfig.js.map +1 -0
  63. package/build/esm/shapes/ShapeBuilder.js +243 -0
  64. package/build/esm/shapes/ShapeBuilder.js.map +1 -0
  65. package/build/esm/shapes/ShapeDefinition.js +59 -0
  66. package/build/esm/shapes/ShapeDefinition.js.map +1 -0
  67. package/build/esm/shapes/computeShapeId.js +97 -0
  68. package/build/esm/shapes/computeShapeId.js.map +1 -0
  69. package/build/esm/shapes/configToShapeDefinition.js +115 -0
  70. package/build/esm/shapes/configToShapeDefinition.js.map +1 -0
  71. package/build/{browser/aggregate/AggregationsClause.test.js → esm/shapes/index.js} +16 -6
  72. package/build/esm/shapes/index.js.map +1 -0
  73. package/build/esm/shapes/internal.js +2 -0
  74. package/build/esm/shapes/internal.js.map +1 -0
  75. package/build/esm/test/EmployeeApiTest.js +3 -1
  76. package/build/esm/test/EmployeeApiTest.js.map +1 -1
  77. package/build/types/aggregate/IntervalRule.d.ts +69 -0
  78. package/build/types/aggregate/IntervalRule.d.ts.map +1 -0
  79. package/build/types/aggregate/StringFilter.d.ts +12 -1
  80. package/build/types/aggregate/StringFilter.d.ts.map +1 -1
  81. package/build/types/aggregate/WhereClause.d.ts +1 -1
  82. package/build/types/aggregate/WhereClause.d.ts.map +1 -1
  83. package/build/types/definitions/LinkDefinitions.d.ts +3 -3
  84. package/build/types/definitions/LinkDefinitions.d.ts.map +1 -1
  85. package/build/types/derivedProperties/DerivedProperty.d.ts +1 -10
  86. package/build/types/derivedProperties/DerivedProperty.d.ts.map +1 -1
  87. package/build/types/index.d.ts +3 -2
  88. package/build/types/index.d.ts.map +1 -1
  89. package/build/types/mapping/DataValueMapping.d.ts +2 -2
  90. package/build/types/mapping/DataValueMapping.d.ts.map +1 -1
  91. package/build/types/object/Media.d.ts +14 -0
  92. package/build/types/object/Media.d.ts.map +1 -1
  93. package/build/types/ontology/ActionDefinition.d.ts +2 -0
  94. package/build/types/ontology/ActionDefinition.d.ts.map +1 -1
  95. package/build/types/ontology/ObjectTypeDefinition.d.ts +2 -0
  96. package/build/types/ontology/ObjectTypeDefinition.d.ts.map +1 -1
  97. package/build/types/ontology/QueryDefinition.d.ts +1 -1
  98. package/build/types/ontology/QueryDefinition.d.ts.map +1 -1
  99. package/build/types/public/shapes-internal.d.ts +1 -0
  100. package/build/types/public/shapes-internal.d.ts.map +1 -0
  101. package/build/types/public/unstable.d.ts +2 -0
  102. package/build/types/public/unstable.d.ts.map +1 -1
  103. package/build/types/queries/Queries.d.ts +2 -0
  104. package/build/types/queries/Queries.d.ts.map +1 -1
  105. package/build/types/shapes/InlineShapeConfig.d.ts +29 -0
  106. package/build/types/shapes/InlineShapeConfig.d.ts.map +1 -0
  107. package/build/types/shapes/ShapeBuilder.d.ts +21 -0
  108. package/build/types/shapes/ShapeBuilder.d.ts.map +1 -0
  109. package/build/types/shapes/ShapeDefinition.d.ts +167 -0
  110. package/build/types/shapes/ShapeDefinition.d.ts.map +1 -0
  111. package/build/types/shapes/computeShapeId.d.ts +14 -0
  112. package/build/types/shapes/computeShapeId.d.ts.map +1 -0
  113. package/build/types/shapes/configToShapeDefinition.d.ts +6 -0
  114. package/build/types/shapes/configToShapeDefinition.d.ts.map +1 -0
  115. package/build/types/shapes/index.d.ts +5 -0
  116. package/build/types/shapes/index.d.ts.map +1 -0
  117. package/build/types/shapes/internal.d.ts +1 -0
  118. package/build/types/shapes/internal.d.ts.map +1 -0
  119. package/build/types/test/EmployeeApiTest.d.ts +2 -0
  120. package/build/types/test/EmployeeApiTest.d.ts.map +1 -1
  121. package/package.json +12 -3
  122. package/{build/browser/groupby/GroupByClause.test.js → shapes-internal.d.ts} +2 -6
  123. package/build/browser/OsdkObjectFrom.test.js +0 -204
  124. package/build/browser/OsdkObjectFrom.test.js.map +0 -1
  125. package/build/browser/aggregate/AggregationsClause.test.js.map +0 -1
  126. package/build/browser/definitions/LinkDefinitions.test.js.map +0 -1
  127. package/build/browser/groupby/GroupByClause.test.js.map +0 -1
  128. package/build/browser/junk.test.js +0 -23
  129. package/build/browser/junk.test.js.map +0 -1
  130. package/build/browser/object/ObjectDefinitions.test.js +0 -28
  131. package/build/browser/object/ObjectDefinitions.test.js.map +0 -1
  132. package/build/browser/objectSet/ObjectSet.test.js +0 -736
  133. package/build/browser/objectSet/ObjectSet.test.js.map +0 -1
  134. package/build/browser/ontology/ObjectSpecifier.test.js +0 -53
  135. package/build/browser/ontology/ObjectSpecifier.test.js.map +0 -1
  136. package/build/browser/ontology/SimplePropertyDef.test.js +0 -48
  137. package/build/browser/ontology/SimplePropertyDef.test.js.map +0 -1
  138. package/build/esm/OsdkObjectFrom.test.js +0 -204
  139. package/build/esm/OsdkObjectFrom.test.js.map +0 -1
  140. package/build/esm/aggregate/AggregationsClause.test.js +0 -21
  141. package/build/esm/aggregate/AggregationsClause.test.js.map +0 -1
  142. package/build/esm/definitions/LinkDefinitions.test.js +0 -26
  143. package/build/esm/definitions/LinkDefinitions.test.js.map +0 -1
  144. package/build/esm/groupby/GroupByClause.test.js +0 -21
  145. package/build/esm/groupby/GroupByClause.test.js.map +0 -1
  146. package/build/esm/junk.test.js +0 -23
  147. package/build/esm/junk.test.js.map +0 -1
  148. package/build/esm/object/ObjectDefinitions.test.js +0 -28
  149. package/build/esm/object/ObjectDefinitions.test.js.map +0 -1
  150. package/build/esm/objectSet/ObjectSet.test.js +0 -736
  151. package/build/esm/objectSet/ObjectSet.test.js.map +0 -1
  152. package/build/esm/ontology/ObjectSpecifier.test.js +0 -53
  153. package/build/esm/ontology/ObjectSpecifier.test.js.map +0 -1
  154. package/build/esm/ontology/SimplePropertyDef.test.js +0 -48
  155. package/build/esm/ontology/SimplePropertyDef.test.js.map +0 -1
  156. package/build/types/OsdkObjectFrom.test.d.ts +0 -1
  157. package/build/types/OsdkObjectFrom.test.d.ts.map +0 -1
  158. package/build/types/aggregate/AggregationsClause.test.d.ts +0 -46
  159. package/build/types/aggregate/AggregationsClause.test.d.ts.map +0 -1
  160. package/build/types/definitions/LinkDefinitions.test.d.ts +0 -1
  161. package/build/types/definitions/LinkDefinitions.test.d.ts.map +0 -1
  162. package/build/types/groupby/GroupByClause.test.d.ts +0 -23
  163. package/build/types/groupby/GroupByClause.test.d.ts.map +0 -1
  164. package/build/types/junk.test.d.ts +0 -1
  165. package/build/types/junk.test.d.ts.map +0 -1
  166. package/build/types/object/ObjectDefinitions.test.d.ts +0 -1
  167. package/build/types/object/ObjectDefinitions.test.d.ts.map +0 -1
  168. package/build/types/objectSet/ObjectSet.test.d.ts +0 -2
  169. package/build/types/objectSet/ObjectSet.test.d.ts.map +0 -1
  170. package/build/types/ontology/ObjectSpecifier.test.d.ts +0 -1
  171. package/build/types/ontology/ObjectSpecifier.test.d.ts.map +0 -1
  172. package/build/types/ontology/SimplePropertyDef.test.d.ts +0 -1
  173. package/build/types/ontology/SimplePropertyDef.test.d.ts.map +0 -1
@@ -0,0 +1,243 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { computeShapeId } from "./computeShapeId.js";
18
+ import { SourcePrimaryKeySymbol } from "./ShapeDefinition.js";
19
+ class ShapeBuilderImpl {
20
+ #state;
21
+ constructor(state) {
22
+ this.#state = state;
23
+ }
24
+ #addProps(props, type) {
25
+ const newProps = {
26
+ ...this.#state.props
27
+ };
28
+ for (const prop of props) {
29
+ newProps[prop] = {
30
+ nullabilityOp: {
31
+ type
32
+ }
33
+ };
34
+ }
35
+ return newProps;
36
+ }
37
+ select(...props) {
38
+ return new ShapeBuilderImpl({
39
+ ...this.#state,
40
+ props: this.#addProps(props, "select")
41
+ });
42
+ }
43
+ require(...props) {
44
+ return new ShapeBuilderImpl({
45
+ ...this.#state,
46
+ props: this.#addProps(props, "require")
47
+ });
48
+ }
49
+ dropIfNull(...props) {
50
+ return new ShapeBuilderImpl({
51
+ ...this.#state,
52
+ props: this.#addProps(props, "dropIfNull")
53
+ });
54
+ }
55
+ withDefault(prop, defaultValue) {
56
+ return new ShapeBuilderImpl({
57
+ ...this.#state,
58
+ props: {
59
+ ...this.#state.props,
60
+ [prop]: {
61
+ nullabilityOp: {
62
+ type: "withDefault",
63
+ defaultValue
64
+ }
65
+ }
66
+ }
67
+ });
68
+ }
69
+ withTransform(prop, transform) {
70
+ return new ShapeBuilderImpl({
71
+ ...this.#state,
72
+ props: {
73
+ ...this.#state.props,
74
+ [prop]: {
75
+ nullabilityOp: {
76
+ type: "withTransform",
77
+ transform
78
+ }
79
+ }
80
+ }
81
+ });
82
+ }
83
+ deriveLink(name, builder) {
84
+ const linkBuilder = createShapeLinkBuilder(this.#state.baseTypeApiName);
85
+ const linkResult = builder(linkBuilder);
86
+ return new ShapeBuilderImpl({
87
+ ...this.#state,
88
+ props: {
89
+ ...this.#state.props
90
+ },
91
+ derivedLinks: [...this.#state.derivedLinks, {
92
+ name,
93
+ objectSetDef: linkResult.objectSetDef,
94
+ targetShape: linkResult.targetShape,
95
+ config: linkResult.config
96
+ }]
97
+ });
98
+ }
99
+ build() {
100
+ const shapeId = computeShapeId({
101
+ baseTypeApiName: this.#state.baseTypeApiName,
102
+ props: this.#state.props,
103
+ derivedLinks: this.#state.derivedLinks
104
+ });
105
+ return {
106
+ __shapeId: shapeId,
107
+ __debugName: this.#state.debugName,
108
+ __baseType: this.#state.baseType,
109
+ __baseTypeApiName: this.#state.baseTypeApiName,
110
+ __props: Object.freeze({
111
+ ...this.#state.props
112
+ }),
113
+ __derivedLinks: Object.freeze([...this.#state.derivedLinks]),
114
+ __selectedPropsType: {},
115
+ __derivedLinksType: {}
116
+ };
117
+ }
118
+ }
119
+ class ShapeLinkBuilderImpl {
120
+ #state;
121
+ $primaryKey = SourcePrimaryKeySymbol;
122
+ constructor(state) {
123
+ this.#state = state;
124
+ }
125
+ pivotTo(link) {
126
+ const newSegments = [...this.#state.segments, {
127
+ type: "pivotTo",
128
+ linkName: link,
129
+ sourceType: this.#state.currentTypeApiName
130
+ // targetType is resolved at link execution time when link metadata is available
131
+ }];
132
+ return new ShapeLinkBuilderImpl({
133
+ ...this.#state,
134
+ segments: newSegments,
135
+ // currentTypeApiName is a hint for debugging; actual type resolution happens at execution
136
+ currentTypeApiName: `${this.#state.currentTypeApiName}.${link}`
137
+ });
138
+ }
139
+
140
+ /** Sets the where filter for this link. Calling multiple times replaces the previous clause (last-write-wins). */
141
+ where(clause) {
142
+ return new ShapeLinkBuilderImpl({
143
+ ...this.#state,
144
+ where: clause
145
+ });
146
+ }
147
+ #setOp(type, others) {
148
+ return new ShapeLinkBuilderImpl({
149
+ ...this.#state,
150
+ setOperations: [...this.#state.setOperations, ...others.map(other => ({
151
+ type,
152
+ other: other.toObjectSetDef()
153
+ }))]
154
+ });
155
+ }
156
+ union(...others) {
157
+ return this.#setOp("union", others);
158
+ }
159
+ intersect(...others) {
160
+ return this.#setOp("intersect", others);
161
+ }
162
+ subtract(...others) {
163
+ return this.#setOp("subtract", others);
164
+ }
165
+ orderBy(property, direction = "asc") {
166
+ return new ShapeLinkBuilderImpl({
167
+ ...this.#state,
168
+ orderBy: [...this.#state.orderBy, {
169
+ property: property,
170
+ direction
171
+ }]
172
+ });
173
+ }
174
+ limit(n) {
175
+ if (!Number.isInteger(n) || n <= 0) {
176
+ throw new Error(`ShapeLinkBuilder.limit() requires a positive integer, got: ${n}`);
177
+ }
178
+ return new ShapeLinkBuilderImpl({
179
+ ...this.#state,
180
+ limit: n
181
+ });
182
+ }
183
+ distinct() {
184
+ return new ShapeLinkBuilderImpl({
185
+ ...this.#state,
186
+ distinct: true
187
+ });
188
+ }
189
+ as(shape, config = {}) {
190
+ // The brand is a compile-time only marker, at runtime it's just undefined
191
+ return {
192
+ targetShape: shape,
193
+ objectSetDef: this.toObjectSetDef(),
194
+ config
195
+ };
196
+ }
197
+ toObjectSetDef() {
198
+ return {
199
+ segments: Object.freeze([...this.#state.segments]),
200
+ where: this.#state.where,
201
+ orderBy: this.#state.orderBy.length > 0 ? Object.freeze([...this.#state.orderBy]) : undefined,
202
+ limit: this.#state.limit,
203
+ distinct: this.#state.distinct || undefined,
204
+ setOperations: this.#state.setOperations.length > 0 ? Object.freeze([...this.#state.setOperations]) : undefined
205
+ };
206
+ }
207
+ }
208
+ export function createShapeLinkBuilder(sourceTypeApiName) {
209
+ return new ShapeLinkBuilderImpl({
210
+ sourceTypeApiName,
211
+ currentTypeApiName: sourceTypeApiName,
212
+ segments: [],
213
+ orderBy: [],
214
+ distinct: false,
215
+ setOperations: []
216
+ });
217
+ }
218
+
219
+ /**
220
+ * Creates a new ShapeBuilder for the given base type.
221
+ *
222
+ * @param baseType - The base ObjectTypeDefinition or InterfaceDefinition
223
+ * @param debugName - Optional name for debugging in DevTools
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * const SlimPlayer = createShapeBuilder(Player, "SlimPlayer")
228
+ * .require("name", "age")
229
+ * .withDefault("position", "Unknown")
230
+ * .build();
231
+ * ```
232
+ */
233
+ export function createShapeBuilder(baseType, debugName) {
234
+ const state = {
235
+ baseType,
236
+ baseTypeApiName: baseType.apiName,
237
+ debugName,
238
+ props: {},
239
+ derivedLinks: []
240
+ };
241
+ return new ShapeBuilderImpl(state);
242
+ }
243
+ //# sourceMappingURL=ShapeBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShapeBuilder.js","names":["computeShapeId","SourcePrimaryKeySymbol","ShapeBuilderImpl","state","constructor","addProps","#addProps","props","type","newProps","prop","nullabilityOp","select","require","dropIfNull","withDefault","defaultValue","withTransform","transform","deriveLink","name","builder","linkBuilder","createShapeLinkBuilder","baseTypeApiName","linkResult","derivedLinks","objectSetDef","targetShape","config","build","shapeId","__shapeId","__debugName","debugName","__baseType","baseType","__baseTypeApiName","__props","Object","freeze","__derivedLinks","__selectedPropsType","__derivedLinksType","ShapeLinkBuilderImpl","$primaryKey","pivotTo","link","newSegments","segments","linkName","sourceType","currentTypeApiName","where","clause","setOp","#setOp","others","setOperations","map","other","toObjectSetDef","union","intersect","subtract","orderBy","property","direction","limit","n","Number","isInteger","Error","distinct","as","shape","length","undefined","sourceTypeApiName","createShapeBuilder","apiName"],"sources":["ShapeBuilder.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { WhereClause } from \"../aggregate/WhereClause.js\";\nimport type {\n ObjectOrInterfaceDefinition,\n PropertyKeys,\n} from \"../ontology/ObjectOrInterface.js\";\nimport type { LinkedType, LinkNames } from \"../util/LinkUtils.js\";\nimport { computeShapeId } from \"./computeShapeId.js\";\nimport { SourcePrimaryKeySymbol } from \"./ShapeDefinition.js\";\nimport type {\n DerivedLinkConfig,\n NullabilityOp,\n PropertyType,\n RequiredProperty,\n ShapeBuilder,\n ShapeDefinition,\n ShapeDerivedLinkDef,\n ShapeLinkBuilder,\n ShapeLinkObjectSetDef,\n ShapeLinkOrderBy,\n ShapeLinkResult,\n ShapeLinkSegment,\n ShapeLinkSetOperation,\n ShapePropertyConfig,\n} from \"./ShapeDefinition.js\";\n\ninterface ShapeBuilderState {\n readonly baseType: ObjectOrInterfaceDefinition;\n readonly baseTypeApiName: string;\n readonly debugName: string | undefined;\n readonly props: Record<string, ShapePropertyConfig>;\n readonly derivedLinks: ShapeDerivedLinkDef[];\n}\n\nclass ShapeBuilderImpl<\n BASE extends ObjectOrInterfaceDefinition,\n PROPS extends Record<string, unknown>,\n LINKS extends Record<string, ShapeDefinition<ObjectOrInterfaceDefinition>>,\n> implements ShapeBuilder<BASE, PROPS, LINKS> {\n readonly #state: ShapeBuilderState;\n\n constructor(state: ShapeBuilderState) {\n this.#state = state;\n }\n\n #addProps(\n props: string[],\n type: \"select\" | \"require\" | \"dropIfNull\",\n ): Record<string, ShapePropertyConfig> {\n const newProps = { ...this.#state.props };\n for (const prop of props) {\n newProps[prop] = { nullabilityOp: { type } };\n }\n return newProps;\n }\n\n select<K extends Exclude<PropertyKeys<BASE>, keyof PROPS>>(\n ...props: K[]\n ): ShapeBuilder<BASE, PROPS & { [P in K]: PropertyType<BASE, P> }, LINKS> {\n return new ShapeBuilderImpl({\n ...this.#state,\n props: this.#addProps(props as string[], \"select\"),\n });\n }\n\n require<K extends Exclude<PropertyKeys<BASE>, keyof PROPS>>(\n ...props: K[]\n ): ShapeBuilder<\n BASE,\n PROPS & { [P in K]: RequiredProperty<PropertyType<BASE, P>> },\n LINKS\n > {\n return new ShapeBuilderImpl({\n ...this.#state,\n props: this.#addProps(props as string[], \"require\"),\n });\n }\n\n dropIfNull<K extends Exclude<PropertyKeys<BASE>, keyof PROPS>>(\n ...props: K[]\n ): ShapeBuilder<\n BASE,\n PROPS & { [P in K]: RequiredProperty<PropertyType<BASE, P>> },\n LINKS\n > {\n return new ShapeBuilderImpl({\n ...this.#state,\n props: this.#addProps(props as string[], \"dropIfNull\"),\n });\n }\n\n withDefault<\n K extends Exclude<PropertyKeys<BASE>, keyof PROPS>,\n V extends NonNullable<PropertyType<BASE, K>>,\n >(\n prop: K,\n defaultValue: V,\n ): ShapeBuilder<\n BASE,\n PROPS & { [P in K]: NonNullable<PropertyType<BASE, P>> },\n LINKS\n > {\n return new ShapeBuilderImpl({\n ...this.#state,\n props: {\n ...this.#state.props,\n [prop as string]: {\n nullabilityOp: { type: \"withDefault\", defaultValue } as NullabilityOp,\n },\n },\n });\n }\n\n withTransform<K extends Exclude<PropertyKeys<BASE>, keyof PROPS>, R>(\n prop: K,\n transform: (value: PropertyType<BASE, K>) => R,\n ): ShapeBuilder<BASE, PROPS & { [P in K]: R }, LINKS> {\n return new ShapeBuilderImpl({\n ...this.#state,\n props: {\n ...this.#state.props,\n [prop as string]: {\n nullabilityOp: { type: \"withTransform\", transform } as NullabilityOp,\n },\n },\n });\n }\n\n deriveLink<\n NAME extends string,\n TARGET_SHAPE extends ShapeDefinition<ObjectOrInterfaceDefinition>,\n >(\n name: NAME,\n builder: (\n linkBuilder: ShapeLinkBuilder<BASE, BASE>,\n ) => ShapeLinkResult<TARGET_SHAPE>,\n ): ShapeBuilder<BASE, PROPS, LINKS & { [K in NAME]: TARGET_SHAPE }> {\n const linkBuilder = createShapeLinkBuilder<BASE, BASE>(\n this.#state.baseTypeApiName,\n );\n const linkResult = builder(linkBuilder);\n return new ShapeBuilderImpl({\n ...this.#state,\n props: { ...this.#state.props },\n derivedLinks: [\n ...this.#state.derivedLinks,\n {\n name,\n objectSetDef: linkResult.objectSetDef,\n targetShape: linkResult.targetShape,\n config: linkResult.config,\n },\n ],\n });\n }\n\n build(): ShapeDefinition<BASE, PROPS, LINKS> {\n const shapeId = computeShapeId({\n baseTypeApiName: this.#state.baseTypeApiName,\n props: this.#state.props,\n derivedLinks: this.#state.derivedLinks,\n });\n\n return {\n __shapeId: shapeId,\n __debugName: this.#state.debugName,\n __baseType: this.#state.baseType as BASE,\n __baseTypeApiName: this.#state.baseTypeApiName,\n __props: Object.freeze({ ...this.#state.props }),\n __derivedLinks: Object.freeze([...this.#state.derivedLinks]),\n __selectedPropsType: {} as PROPS,\n __derivedLinksType: {} as LINKS,\n } as ShapeDefinition<BASE, PROPS, LINKS>;\n }\n}\n\ninterface ShapeLinkBuilderState {\n readonly sourceTypeApiName: string;\n readonly currentTypeApiName: string;\n readonly segments: ShapeLinkSegment[];\n readonly where?: WhereClause<ObjectOrInterfaceDefinition>;\n readonly orderBy: ShapeLinkOrderBy[];\n readonly limit?: number;\n readonly distinct: boolean;\n readonly setOperations: ShapeLinkSetOperation[];\n}\n\nclass ShapeLinkBuilderImpl<\n SOURCE extends ObjectOrInterfaceDefinition,\n CURRENT extends ObjectOrInterfaceDefinition,\n> implements ShapeLinkBuilder<SOURCE, CURRENT> {\n readonly #state: ShapeLinkBuilderState;\n readonly $primaryKey: symbol = SourcePrimaryKeySymbol;\n\n constructor(state: ShapeLinkBuilderState) {\n this.#state = state;\n }\n\n pivotTo<L extends LinkNames<CURRENT>>(\n link: L,\n ): ShapeLinkBuilder<SOURCE, LinkedType<CURRENT, L>> {\n const newSegments: ShapeLinkSegment[] = [\n ...this.#state.segments,\n {\n type: \"pivotTo\",\n linkName: link as string,\n sourceType: this.#state.currentTypeApiName,\n // targetType is resolved at link execution time when link metadata is available\n },\n ];\n\n return new ShapeLinkBuilderImpl({\n ...this.#state,\n segments: newSegments,\n // currentTypeApiName is a hint for debugging; actual type resolution happens at execution\n currentTypeApiName: `${this.#state.currentTypeApiName}.${link as string}`,\n });\n }\n\n /** Sets the where filter for this link. Calling multiple times replaces the previous clause (last-write-wins). */\n where(clause: WhereClause<CURRENT>): ShapeLinkBuilder<SOURCE, CURRENT> {\n return new ShapeLinkBuilderImpl({\n ...this.#state,\n where: clause as WhereClause<ObjectOrInterfaceDefinition>,\n });\n }\n\n #setOp(\n type: \"union\" | \"intersect\" | \"subtract\",\n others: ShapeLinkBuilder<SOURCE, CURRENT>[],\n ): ShapeLinkBuilder<SOURCE, CURRENT> {\n return new ShapeLinkBuilderImpl({\n ...this.#state,\n setOperations: [\n ...this.#state.setOperations,\n ...others.map((other) => ({\n type,\n other: (other as ShapeLinkBuilderImpl<SOURCE, CURRENT>)\n .toObjectSetDef(),\n })),\n ],\n });\n }\n\n union(\n ...others: ShapeLinkBuilder<SOURCE, CURRENT>[]\n ): ShapeLinkBuilder<SOURCE, CURRENT> {\n return this.#setOp(\"union\", others);\n }\n\n intersect(\n ...others: ShapeLinkBuilder<SOURCE, CURRENT>[]\n ): ShapeLinkBuilder<SOURCE, CURRENT> {\n return this.#setOp(\"intersect\", others);\n }\n\n subtract(\n ...others: ShapeLinkBuilder<SOURCE, CURRENT>[]\n ): ShapeLinkBuilder<SOURCE, CURRENT> {\n return this.#setOp(\"subtract\", others);\n }\n\n orderBy<K extends PropertyKeys<CURRENT>>(\n property: K,\n direction: \"asc\" | \"desc\" = \"asc\",\n ): ShapeLinkBuilder<SOURCE, CURRENT> {\n return new ShapeLinkBuilderImpl({\n ...this.#state,\n orderBy: [\n ...this.#state.orderBy,\n { property: property as string, direction },\n ],\n });\n }\n\n limit(n: number): ShapeLinkBuilder<SOURCE, CURRENT> {\n if (!Number.isInteger(n) || n <= 0) {\n throw new Error(\n `ShapeLinkBuilder.limit() requires a positive integer, got: ${n}`,\n );\n }\n return new ShapeLinkBuilderImpl({\n ...this.#state,\n limit: n,\n });\n }\n\n distinct(): ShapeLinkBuilder<SOURCE, CURRENT> {\n return new ShapeLinkBuilderImpl({\n ...this.#state,\n distinct: true,\n });\n }\n\n as<TARGET_SHAPE extends ShapeDefinition<CURRENT>>(\n shape: TARGET_SHAPE,\n config: DerivedLinkConfig = {},\n ): ShapeLinkResult<TARGET_SHAPE> {\n // The brand is a compile-time only marker, at runtime it's just undefined\n return {\n targetShape: shape,\n objectSetDef: this.toObjectSetDef(),\n config,\n } as ShapeLinkResult<TARGET_SHAPE>;\n }\n\n toObjectSetDef(): ShapeLinkObjectSetDef {\n return {\n segments: Object.freeze([...this.#state.segments]),\n where: this.#state.where,\n orderBy: this.#state.orderBy.length > 0\n ? Object.freeze([...this.#state.orderBy])\n : undefined,\n limit: this.#state.limit,\n distinct: this.#state.distinct || undefined,\n setOperations: this.#state.setOperations.length > 0\n ? Object.freeze([...this.#state.setOperations])\n : undefined,\n };\n }\n}\n\nexport function createShapeLinkBuilder<\n SOURCE extends ObjectOrInterfaceDefinition,\n CURRENT extends ObjectOrInterfaceDefinition,\n>(sourceTypeApiName: string): ShapeLinkBuilder<SOURCE, CURRENT> {\n return new ShapeLinkBuilderImpl({\n sourceTypeApiName,\n currentTypeApiName: sourceTypeApiName,\n segments: [],\n orderBy: [],\n distinct: false,\n setOperations: [],\n });\n}\n\n/**\n * Creates a new ShapeBuilder for the given base type.\n *\n * @param baseType - The base ObjectTypeDefinition or InterfaceDefinition\n * @param debugName - Optional name for debugging in DevTools\n *\n * @example\n * ```typescript\n * const SlimPlayer = createShapeBuilder(Player, \"SlimPlayer\")\n * .require(\"name\", \"age\")\n * .withDefault(\"position\", \"Unknown\")\n * .build();\n * ```\n */\nexport function createShapeBuilder<BASE extends ObjectOrInterfaceDefinition>(\n baseType: BASE,\n debugName?: string,\n): ShapeBuilder<BASE, {}, {}> {\n const state: ShapeBuilderState = {\n baseType,\n baseTypeApiName: baseType.apiName,\n debugName,\n props: {},\n derivedLinks: [],\n };\n\n return new ShapeBuilderImpl(state);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,SAASA,cAAc,QAAQ,qBAAqB;AACpD,SAASC,sBAAsB,QAAQ,sBAAsB;AA0B7D,MAAMC,gBAAgB,CAIwB;EACnC,CAACC,KAAK;EAEfC,WAAWA,CAACD,KAAwB,EAAE;IACpC,IAAI,CAAC,CAACA,KAAK,GAAGA,KAAK;EACrB;EAEA,CAACE,QAAQC,CACPC,KAAe,EACfC,IAAyC,EACJ;IACrC,MAAMC,QAAQ,GAAG;MAAE,GAAG,IAAI,CAAC,CAACN,KAAK,CAACI;IAAM,CAAC;IACzC,KAAK,MAAMG,IAAI,IAAIH,KAAK,EAAE;MACxBE,QAAQ,CAACC,IAAI,CAAC,GAAG;QAAEC,aAAa,EAAE;UAAEH;QAAK;MAAE,CAAC;IAC9C;IACA,OAAOC,QAAQ;EACjB;EAEAG,MAAMA,CACJ,GAAGL,KAAU,EAC2D;IACxE,OAAO,IAAIL,gBAAgB,CAAC;MAC1B,GAAG,IAAI,CAAC,CAACC,KAAK;MACdI,KAAK,EAAE,IAAI,CAAC,CAACF,QAAQ,CAACE,KAAK,EAAc,QAAQ;IACnD,CAAC,CAAC;EAC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Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export const SourcePrimaryKeySymbol = Symbol.for("osdk.query.$sourcePk");
18
+ const LegacyShapesSymbol = Symbol.for("osdk.shapes.$primaryKey");
19
+ export function isSourcePkSymbol(value) {
20
+ return typeof value === "symbol" && (value === SourcePrimaryKeySymbol || value === LegacyShapesSymbol);
21
+ }
22
+
23
+ /** Configuration for how a derived link is loaded at runtime. */
24
+
25
+ /** The result of calling `ShapeLinkBuilder.as()`, binding a link traversal to a target shape. */
26
+
27
+ /** A single link traversal step in a derived link's object set definition. */
28
+
29
+ /** Sort clause for a derived link's result set. */
30
+
31
+ /** A set operation (union/intersect/subtract) applied to a derived link's object set. */
32
+
33
+ /** Serializable definition of a derived link's object set: link traversals, filters, ordering, and set operations. */
34
+
35
+ /** How a shape handles null values for a selected property. */
36
+
37
+ /** Per-property configuration stored in a shape's `__props` map. */
38
+
39
+ /** A derived link definition stored in a shape's `__derivedLinks` array. */
40
+
41
+ /**
42
+ * Type projection from an OSDK type. `__props` is the single source of truth for property config.
43
+ *
44
+ * @typeParam BASE - The base ObjectTypeDefinition or InterfaceDefinition
45
+ * @typeParam SELECTED_PROPS - Record of selected properties and their transformed types
46
+ * @typeParam DERIVED_LINKS - Record of derived link names to their result types
47
+ */
48
+
49
+ export class ShapeNullabilityError extends Error {
50
+ constructor(shape, violations) {
51
+ const props = violations.map(v => v.property).join(", ");
52
+ const shapeName = shape.__debugName ?? shape.__shapeId;
53
+ super(`Shape "${shapeName}" requires these properties to be non-null: ${props}`);
54
+ this.shape = shape;
55
+ this.violations = violations;
56
+ this.name = "ShapeNullabilityError";
57
+ }
58
+ }
59
+ //# sourceMappingURL=ShapeDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShapeDefinition.js","names":["SourcePrimaryKeySymbol","Symbol","for","LegacyShapesSymbol","isSourcePkSymbol","value","ShapeNullabilityError","Error","constructor","shape","violations","props","map","v","property","join","shapeName","__debugName","__shapeId","name"],"sources":["ShapeDefinition.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { WhereClause } from \"../aggregate/WhereClause.js\";\nimport type {\n ObjectOrInterfaceDefinition,\n PropertyKeys,\n} from \"../ontology/ObjectOrInterface.js\";\nimport type { CompileTimeMetadata } from \"../ontology/ObjectTypeDefinition.js\";\nimport type { OsdkBase } from \"../OsdkBase.js\";\nimport type { LinkedType, LinkNames } from \"../util/LinkUtils.js\";\n\nexport const SourcePrimaryKeySymbol: unique symbol = Symbol.for(\n \"osdk.query.$sourcePk\",\n);\n\nconst LegacyShapesSymbol = Symbol.for(\"osdk.shapes.$primaryKey\");\n\nexport function isSourcePkSymbol(value: unknown): value is symbol {\n return (\n typeof value === \"symbol\"\n && (value === SourcePrimaryKeySymbol || value === LegacyShapesSymbol)\n );\n}\n\ndeclare const ShapeDefinitionBrand: unique symbol;\n\ndeclare const ShapeLinkResultBrand: unique symbol;\n\n/** Configuration for how a derived link is loaded at runtime. */\nexport interface DerivedLinkConfig {\n defer?: boolean;\n}\n\n/** The result of calling `ShapeLinkBuilder.as()`, binding a link traversal to a target shape. */\nexport interface ShapeLinkResult<\n TARGET_SHAPE extends ShapeDefinition<ObjectOrInterfaceDefinition>,\n> {\n readonly __linkResultBrand: typeof ShapeLinkResultBrand;\n readonly targetShape: TARGET_SHAPE;\n readonly objectSetDef: ShapeLinkObjectSetDef;\n readonly config: DerivedLinkConfig;\n}\n\n/** A single link traversal step in a derived link's object set definition. */\nexport interface ShapeLinkSegment {\n readonly type: \"pivotTo\";\n readonly linkName: string;\n readonly sourceType?: string;\n readonly targetType?: string;\n}\n\n/** Sort clause for a derived link's result set. */\nexport interface ShapeLinkOrderBy {\n readonly property: string;\n readonly direction: \"asc\" | \"desc\";\n}\n\n/** A set operation (union/intersect/subtract) applied to a derived link's object set. */\nexport interface ShapeLinkSetOperation {\n readonly type: \"union\" | \"intersect\" | \"subtract\";\n readonly other: ShapeLinkObjectSetDef;\n}\n\n/** Serializable definition of a derived link's object set: link traversals, filters, ordering, and set operations. */\nexport interface ShapeLinkObjectSetDef {\n readonly segments: readonly ShapeLinkSegment[];\n readonly where?: WhereClause<ObjectOrInterfaceDefinition>;\n readonly orderBy?: readonly ShapeLinkOrderBy[];\n readonly limit?: number;\n readonly distinct?: boolean;\n readonly setOperations?: readonly ShapeLinkSetOperation[];\n}\n\n/** How a shape handles null values for a selected property. */\nexport type NullabilityOp =\n | { type: \"require\" }\n | { type: \"dropIfNull\" }\n | { type: \"withDefault\"; defaultValue: unknown }\n | { type: \"withTransform\"; transform: (value: unknown) => unknown }\n | { type: \"select\" };\n\n/** Per-property configuration stored in a shape's `__props` map. */\nexport interface ShapePropertyConfig {\n readonly nullabilityOp: NullabilityOp;\n}\n\n/** A derived link definition stored in a shape's `__derivedLinks` array. */\nexport interface ShapeDerivedLinkDef<\n TARGET_SHAPE extends ShapeDefinition<ObjectOrInterfaceDefinition> =\n ShapeDefinition<ObjectOrInterfaceDefinition>,\n> {\n readonly name: string;\n readonly objectSetDef: ShapeLinkObjectSetDef;\n readonly targetShape: TARGET_SHAPE;\n readonly config: DerivedLinkConfig;\n}\n\n/**\n * Type projection from an OSDK type. `__props` is the single source of truth for property config.\n *\n * @typeParam BASE - The base ObjectTypeDefinition or InterfaceDefinition\n * @typeParam SELECTED_PROPS - Record of selected properties and their transformed types\n * @typeParam DERIVED_LINKS - Record of derived link names to their result types\n */\nexport interface ShapeDefinition<\n BASE extends ObjectOrInterfaceDefinition,\n SELECTED_PROPS extends Record<string, unknown> = {},\n DERIVED_LINKS extends Record<\n string,\n ShapeDefinition<ObjectOrInterfaceDefinition>\n > = {},\n> {\n readonly [ShapeDefinitionBrand]: true;\n readonly __shapeId: string;\n readonly __debugName: string | undefined;\n readonly __baseType: BASE;\n readonly __baseTypeApiName: string;\n readonly __props: Readonly<Record<string, unknown>>;\n readonly __derivedLinks: readonly unknown[];\n readonly __selectedPropsType: SELECTED_PROPS;\n readonly __derivedLinksType: DERIVED_LINKS;\n}\n\nexport type ShapeBaseType<\n S extends ShapeDefinition<ObjectOrInterfaceDefinition>,\n> = S extends ShapeDefinition<infer BASE, infer _P, infer _L> ? BASE : never;\n\nexport type ShapeSelectedProps<\n S extends ShapeDefinition<ObjectOrInterfaceDefinition>,\n> = S extends ShapeDefinition<infer _B, infer PROPS, infer _L> ? PROPS : never;\n\nexport type ShapeDerivedLinks<\n S extends ShapeDefinition<ObjectOrInterfaceDefinition>,\n> = S extends ShapeDefinition<infer _B, infer _P, infer LINKS> ? LINKS : never;\n\nexport type ShapeInstance<\n S extends ShapeDefinition<ObjectOrInterfaceDefinition>,\n> = S extends ShapeDefinition<infer BASE, infer PROPS, infer LINKS> ?\n & OsdkBase<BASE>\n & { readonly $rid: string }\n & PROPS\n & {\n [K in keyof LINKS]: LINKS[K] extends\n ShapeDefinition<ObjectOrInterfaceDefinition> ? ShapeInstance<LINKS[K]>[]\n : never;\n }\n : never;\n\nexport type PropertyType<\n BASE extends ObjectOrInterfaceDefinition,\n K extends PropertyKeys<BASE>,\n> = CompileTimeMetadata<BASE>[\"props\"][K];\n\nexport type RequiredProperty<T> = NonNullable<T>;\n\nexport interface ShapeLinkBuilder<\n SOURCE extends ObjectOrInterfaceDefinition,\n CURRENT extends ObjectOrInterfaceDefinition,\n> {\n pivotTo<L extends LinkNames<CURRENT>>(\n link: L,\n ): ShapeLinkBuilder<SOURCE, LinkedType<CURRENT, L>>;\n\n where(clause: WhereClause<CURRENT>): ShapeLinkBuilder<SOURCE, CURRENT>;\n\n union(\n ...others: ShapeLinkBuilder<SOURCE, CURRENT>[]\n ): ShapeLinkBuilder<SOURCE, CURRENT>;\n\n intersect(\n ...others: ShapeLinkBuilder<SOURCE, CURRENT>[]\n ): ShapeLinkBuilder<SOURCE, CURRENT>;\n\n subtract(\n ...others: ShapeLinkBuilder<SOURCE, CURRENT>[]\n ): ShapeLinkBuilder<SOURCE, CURRENT>;\n\n orderBy<K extends PropertyKeys<CURRENT>>(\n property: K,\n direction?: \"asc\" | \"desc\",\n ): ShapeLinkBuilder<SOURCE, CURRENT>;\n\n limit(n: number): ShapeLinkBuilder<SOURCE, CURRENT>;\n\n distinct(): ShapeLinkBuilder<SOURCE, CURRENT>;\n\n as<TARGET_SHAPE extends ShapeDefinition<CURRENT>>(\n shape: TARGET_SHAPE,\n config?: DerivedLinkConfig,\n ): ShapeLinkResult<TARGET_SHAPE>;\n\n readonly $primaryKey: symbol;\n}\n\nexport interface ShapeLinkBuilderInternal\n extends\n ShapeLinkBuilder<ObjectOrInterfaceDefinition, ObjectOrInterfaceDefinition>\n{\n toObjectSetDef(): ShapeLinkObjectSetDef;\n}\n\nexport interface ShapeBuilder<\n BASE extends ObjectOrInterfaceDefinition,\n PROPS extends Record<string, unknown> = {},\n LINKS extends Record<\n string,\n ShapeDefinition<ObjectOrInterfaceDefinition>\n > = {},\n> {\n select<K extends Exclude<PropertyKeys<BASE>, keyof PROPS>>(\n ...props: K[]\n ): ShapeBuilder<\n BASE,\n PROPS & { [P in K]: PropertyType<BASE, P> },\n LINKS\n >;\n\n require<K extends Exclude<PropertyKeys<BASE>, keyof PROPS>>(\n ...props: K[]\n ): ShapeBuilder<\n BASE,\n PROPS & { [P in K]: RequiredProperty<PropertyType<BASE, P>> },\n LINKS\n >;\n\n dropIfNull<K extends Exclude<PropertyKeys<BASE>, keyof PROPS>>(\n ...props: K[]\n ): ShapeBuilder<\n BASE,\n PROPS & { [P in K]: RequiredProperty<PropertyType<BASE, P>> },\n LINKS\n >;\n\n withDefault<\n K extends Exclude<PropertyKeys<BASE>, keyof PROPS>,\n V extends NonNullable<PropertyType<BASE, K>>,\n >(\n prop: K,\n defaultValue: V,\n ): ShapeBuilder<\n BASE,\n PROPS & { [P in K]: NonNullable<PropertyType<BASE, P>> },\n LINKS\n >;\n\n withTransform<\n K extends Exclude<PropertyKeys<BASE>, keyof PROPS>,\n R,\n >(\n prop: K,\n transform: (value: PropertyType<BASE, K>) => R,\n ): ShapeBuilder<BASE, PROPS & { [P in K]: R }, LINKS>;\n\n deriveLink<\n NAME extends string,\n TARGET_SHAPE extends ShapeDefinition<ObjectOrInterfaceDefinition>,\n >(\n name: NAME,\n builder: (\n linkBuilder: ShapeLinkBuilder<BASE, BASE>,\n ) => ShapeLinkResult<TARGET_SHAPE>,\n ): ShapeBuilder<BASE, PROPS, LINKS & { [K in NAME]: TARGET_SHAPE }>;\n\n build(): ShapeDefinition<BASE, PROPS, LINKS>;\n}\n\nexport interface LinkLoadConfig {\n pageSize?: number;\n autoFetchMore?: boolean | number;\n streamUpdates?: boolean;\n defer?: boolean;\n}\n\nexport interface LinkStatus {\n isLoading: boolean;\n error: Error | undefined;\n hasMore: boolean;\n fetchMore: () => Promise<void>;\n}\n\nexport interface NullabilityViolation {\n property: string;\n primaryKey: unknown;\n constraint: \"require\" | \"dropIfNull\" | \"transformError\";\n}\n\nexport class ShapeNullabilityError extends Error {\n constructor(\n public readonly shape: ShapeDefinition<ObjectOrInterfaceDefinition>,\n public readonly violations: readonly NullabilityViolation[],\n ) {\n const props = violations.map((v) => v.property).join(\", \");\n const shapeName = shape.__debugName ?? shape.__shapeId;\n super(\n `Shape \"${shapeName}\" requires these properties to be non-null: ${props}`,\n );\n this.name = \"ShapeNullabilityError\";\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,OAAO,MAAMA,sBAAqC,GAAGC,MAAM,CAACC,GAAG,CAC7D,sBACF,CAAC;AAED,MAAMC,kBAAkB,GAAGF,MAAM,CAACC,GAAG,CAAC,yBAAyB,CAAC;AAEhE,OAAO,SAASE,gBAAgBA,CAACC,KAAc,EAAmB;EAChE,OACE,OAAOA,KAAK,KAAK,QAAQ,KACrBA,KAAK,KAAKL,sBAAsB,IAAIK,KAAK,KAAKF,kBAAkB,CAAC;AAEzE;;AAMA;;AAKA;;AAUA;;AAQA;;AAMA;;AAMA;;AAUA;;AAQA;;AAKA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;;AAuLA,OAAO,MAAMG,qBAAqB,SAASC,KAAK,CAAC;EAC/CC,WAAWA,CACOC,KAAmD,EACnDC,UAA2C,EAC3D;IACA,MAAMC,KAAK,GAAGD,UAAU,CAACE,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACC,QAAQ,CAAC,CAACC,IAAI,CAAC,IAAI,CAAC;IAC1D,MAAMC,SAAS,GAAGP,KAAK,CAACQ,WAAW,IAAIR,KAAK,CAACS,SAAS;IACtD,KAAK,CACH,UAAUF,SAAS,+CAA+CL,KAAK,EACzE,CAAC;IAAC,KAPcF,KAAmD,GAAnDA,KAAmD;IAAA,KACnDC,UAA2C,GAA3CA,UAA2C;IAO3D,IAAI,CAACS,IAAI,GAAG,uBAAuB;EACrC;AACF","ignoreList":[]}
@@ -0,0 +1,97 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ function sortedStringify(obj) {
18
+ return JSON.stringify(obj, (_, v) => v && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a.localeCompare(b))) : v);
19
+ }
20
+
21
+ /**
22
+ * Computes a stable, deterministic identifier for a shape definition.
23
+ * The ID uniquely represents the combination of base type, property
24
+ * selections/nullability configs, and derived link definitions so
25
+ * that identical shapes produce the same ID across calls.
26
+ */
27
+ export function computeShapeId(input) {
28
+ const canonical = canonicalizeShapeInput(input);
29
+ return simpleHash(sortedStringify(canonical));
30
+ }
31
+ function canonicalizeShapeInput(input) {
32
+ const sortedPropKeys = [...Object.keys(input.props)].sort();
33
+ const canonicalProps = {};
34
+ for (const key of sortedPropKeys) {
35
+ const config = input.props[key];
36
+ const op = config.nullabilityOp;
37
+ canonicalProps[key] = op.type === "withDefault" ? {
38
+ type: op.type,
39
+ defaultValue: op.defaultValue
40
+ } : op.type;
41
+ }
42
+ const canonicalLinks = input.derivedLinks.map(link => ({
43
+ name: link.name,
44
+ objectSetDef: canonicalizeObjectSetDef(link.objectSetDef),
45
+ targetShapeId: link.targetShape.__shapeId
46
+ }));
47
+ canonicalLinks.sort((a, b) => a.name.localeCompare(b.name));
48
+ return {
49
+ baseType: input.baseTypeApiName,
50
+ props: canonicalProps,
51
+ links: canonicalLinks
52
+ };
53
+ }
54
+ function canonicalizeObjectSetDef(def) {
55
+ const result = {
56
+ segments: def.segments.map(seg => ({
57
+ type: seg.type,
58
+ linkName: seg.linkName,
59
+ sourceType: seg.sourceType
60
+ }))
61
+ };
62
+ if (def.where) {
63
+ result.where = JSON.parse(sortedStringify(def.where));
64
+ }
65
+ if (def.orderBy && def.orderBy.length > 0) {
66
+ result.orderBy = def.orderBy.map(o => ({
67
+ property: o.property,
68
+ direction: o.direction
69
+ }));
70
+ }
71
+ if (def.limit !== undefined) {
72
+ result.limit = def.limit;
73
+ }
74
+ if (def.distinct) {
75
+ result.distinct = true;
76
+ }
77
+ if (def.setOperations && def.setOperations.length > 0) {
78
+ result.setOperations = def.setOperations.map(op => ({
79
+ type: op.type,
80
+ other: canonicalizeObjectSetDef(op.other)
81
+ }));
82
+ }
83
+ return result;
84
+ }
85
+
86
+ // Shape IDs are used for cache keying and equality, not security,
87
+ // so 32-bit is sufficient.
88
+ function simpleHash(str) {
89
+ let hash = 5381;
90
+ for (let i = 0; i < str.length; i++) {
91
+ const char = str.charCodeAt(i);
92
+ hash = (hash << 5) + hash ^ char;
93
+ }
94
+ const positiveHash = hash >>> 0;
95
+ return positiveHash.toString(16).padStart(8, "0");
96
+ }
97
+ //# sourceMappingURL=computeShapeId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computeShapeId.js","names":["sortedStringify","obj","JSON","stringify","_","v","Array","isArray","Object","fromEntries","entries","sort","a","b","localeCompare","computeShapeId","input","canonical","canonicalizeShapeInput","simpleHash","sortedPropKeys","keys","props","canonicalProps","key","config","op","nullabilityOp","type","defaultValue","canonicalLinks","derivedLinks","map","link","name","objectSetDef","canonicalizeObjectSetDef","targetShapeId","targetShape","__shapeId","baseType","baseTypeApiName","links","def","result","segments","seg","linkName","sourceType","where","parse","orderBy","length","o","property","direction","limit","undefined","distinct","setOperations","other","str","hash","i","char","charCodeAt","positiveHash","toString","padStart"],"sources":["computeShapeId.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ShapeDerivedLinkDef,\n ShapeLinkObjectSetDef,\n ShapePropertyConfig,\n} from \"./ShapeDefinition.js\";\n\ninterface ShapeIdInput {\n baseTypeApiName: string;\n props: Record<string, ShapePropertyConfig>;\n derivedLinks: readonly ShapeDerivedLinkDef[];\n}\n\nfunction sortedStringify(obj: unknown): string {\n return JSON.stringify(\n obj,\n (_, v) =>\n v && typeof v === \"object\" && !Array.isArray(v)\n ? Object.fromEntries(\n Object.entries(v).sort(([a], [b]) => a.localeCompare(b)),\n )\n : v,\n );\n}\n\n/**\n * Computes a stable, deterministic identifier for a shape definition.\n * The ID uniquely represents the combination of base type, property\n * selections/nullability configs, and derived link definitions so\n * that identical shapes produce the same ID across calls.\n */\nexport function computeShapeId(input: ShapeIdInput): string {\n const canonical = canonicalizeShapeInput(input);\n return simpleHash(sortedStringify(canonical));\n}\n\nfunction canonicalizeShapeInput(\n input: ShapeIdInput,\n): Record<string, unknown> {\n const sortedPropKeys = [...Object.keys(input.props)].sort();\n const canonicalProps: Record<string, unknown> = {};\n\n for (const key of sortedPropKeys) {\n const config = input.props[key];\n const op = config.nullabilityOp;\n canonicalProps[key] = op.type === \"withDefault\"\n ? { type: op.type, defaultValue: op.defaultValue }\n : op.type;\n }\n\n const canonicalLinks = input.derivedLinks.map((link) => ({\n name: link.name,\n objectSetDef: canonicalizeObjectSetDef(link.objectSetDef),\n targetShapeId: link.targetShape.__shapeId,\n }));\n canonicalLinks.sort((a, b) => a.name.localeCompare(b.name));\n\n return {\n baseType: input.baseTypeApiName,\n props: canonicalProps,\n links: canonicalLinks,\n };\n}\n\nfunction canonicalizeObjectSetDef(\n def: ShapeLinkObjectSetDef,\n): Record<string, unknown> {\n const result: Record<string, unknown> = {\n segments: def.segments.map((seg) => ({\n type: seg.type,\n linkName: seg.linkName,\n sourceType: seg.sourceType,\n })),\n };\n\n if (def.where) {\n result.where = JSON.parse(sortedStringify(def.where));\n }\n\n if (def.orderBy && def.orderBy.length > 0) {\n result.orderBy = def.orderBy.map((o) => ({\n property: o.property,\n direction: o.direction,\n }));\n }\n\n if (def.limit !== undefined) {\n result.limit = def.limit;\n }\n\n if (def.distinct) {\n result.distinct = true;\n }\n\n if (def.setOperations && def.setOperations.length > 0) {\n result.setOperations = def.setOperations.map((op) => ({\n type: op.type,\n other: canonicalizeObjectSetDef(op.other),\n }));\n }\n\n return result;\n}\n\n// Shape IDs are used for cache keying and equality, not security,\n// so 32-bit is sufficient.\nfunction simpleHash(str: string): string {\n let hash = 5381;\n for (let i = 0; i < str.length; i++) {\n const char = str.charCodeAt(i);\n hash = ((hash << 5) + hash) ^ char;\n }\n\n const positiveHash = hash >>> 0;\n return positiveHash.toString(16).padStart(8, \"0\");\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,SAASA,eAAeA,CAACC,GAAY,EAAU;EAC7C,OAAOC,IAAI,CAACC,SAAS,CACnBF,GAAG,EACH,CAACG,CAAC,EAAEC,CAAC,KACHA,CAAC,IAAI,OAAOA,CAAC,KAAK,QAAQ,IAAI,CAACC,KAAK,CAACC,OAAO,CAACF,CAAC,CAAC,GAC3CG,MAAM,CAACC,WAAW,CAClBD,MAAM,CAACE,OAAO,CAACL,CAAC,CAAC,CAACM,IAAI,CAAC,CAAC,CAACC,CAAC,CAAC,EAAE,CAACC,CAAC,CAAC,KAAKD,CAAC,CAACE,aAAa,CAACD,CAAC,CAAC,CACzD,CAAC,GACCR,CACR,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASU,cAAcA,CAACC,KAAmB,EAAU;EAC1D,MAAMC,SAAS,GAAGC,sBAAsB,CAACF,KAAK,CAAC;EAC/C,OAAOG,UAAU,CAACnB,eAAe,CAACiB,SAAS,CAAC,CAAC;AAC/C;AAEA,SAASC,sBAAsBA,CA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CAACF,CAAC,CAAC;IAC9BD,IAAI,GAAI,CAACA,IAAI,IAAI,CAAC,IAAIA,IAAI,GAAIE,IAAI;EACpC;EAEA,MAAME,YAAY,GAAGJ,IAAI,KAAK,CAAC;EAC/B,OAAOI,YAAY,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;AACnD","ignoreList":[]}
@@ -0,0 +1,115 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import { computeShapeId } from "./computeShapeId.js";
18
+ import { createShapeLinkBuilder } from "./ShapeBuilder.js";
19
+ export function configToShapeDefinition(baseType, config) {
20
+ const baseTypeApiName = baseType.apiName;
21
+ const props = {};
22
+ const seen = new Set();
23
+ function addProp(prop, config2) {
24
+ if (seen.has(prop)) {
25
+ throw new Error(`Property "${prop}" appears in multiple config arrays`);
26
+ }
27
+ seen.add(prop);
28
+ props[prop] = config2;
29
+ }
30
+ if (config.require) {
31
+ for (const prop of config.require) {
32
+ addProp(prop, {
33
+ nullabilityOp: {
34
+ type: "require"
35
+ }
36
+ });
37
+ }
38
+ }
39
+ if (config.select) {
40
+ for (const prop of config.select) {
41
+ addProp(prop, {
42
+ nullabilityOp: {
43
+ type: "select"
44
+ }
45
+ });
46
+ }
47
+ }
48
+ if (config.dropIfNull) {
49
+ for (const prop of config.dropIfNull) {
50
+ addProp(prop, {
51
+ nullabilityOp: {
52
+ type: "dropIfNull"
53
+ }
54
+ });
55
+ }
56
+ }
57
+ if (config.defaults) {
58
+ for (const [prop, defaultValue] of Object.entries(config.defaults)) {
59
+ addProp(prop, {
60
+ nullabilityOp: {
61
+ type: "withDefault",
62
+ defaultValue
63
+ }
64
+ });
65
+ }
66
+ }
67
+ if (config.transforms) {
68
+ for (const [prop, transform] of Object.entries(config.transforms)) {
69
+ if (typeof transform !== "function") {
70
+ throw new Error(`transforms["${prop}"] must be a function, got: ${typeof transform}`);
71
+ }
72
+ addProp(prop, {
73
+ nullabilityOp: {
74
+ type: "withTransform",
75
+ transform
76
+ }
77
+ });
78
+ }
79
+ }
80
+ const derivedLinks = [];
81
+ if (config.links) {
82
+ for (const [name, linkConfig] of Object.entries(config.links)) {
83
+ const linkBuilder = createShapeLinkBuilder(baseTypeApiName);
84
+ const traversed = linkConfig.via(linkBuilder);
85
+ const objectSetDef = traversed.toObjectSetDef();
86
+ const targetShape = linkConfig.target;
87
+ derivedLinks.push({
88
+ name,
89
+ objectSetDef,
90
+ targetShape,
91
+ config: {
92
+ defer: linkConfig.defer
93
+ }
94
+ });
95
+ }
96
+ }
97
+ const shapeId = computeShapeId({
98
+ baseTypeApiName,
99
+ props,
100
+ derivedLinks
101
+ });
102
+ return {
103
+ __shapeId: shapeId,
104
+ __debugName: undefined,
105
+ __baseType: baseType,
106
+ __baseTypeApiName: baseTypeApiName,
107
+ __props: Object.freeze({
108
+ ...props
109
+ }),
110
+ __derivedLinks: Object.freeze([...derivedLinks]),
111
+ __selectedPropsType: {},
112
+ __derivedLinksType: {}
113
+ };
114
+ }
115
+ //# sourceMappingURL=configToShapeDefinition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configToShapeDefinition.js","names":["computeShapeId","createShapeLinkBuilder","configToShapeDefinition","baseType","config","baseTypeApiName","apiName","props","seen","Set","addProp","prop","config2","has","Error","add","require","nullabilityOp","type","select","dropIfNull","defaults","defaultValue","Object","entries","transforms","transform","derivedLinks","links","name","linkConfig","linkBuilder","traversed","via","objectSetDef","toObjectSetDef","targetShape","target","push","defer","shapeId","__shapeId","__debugName","undefined","__baseType","__baseTypeApiName","__props","freeze","__derivedLinks","__selectedPropsType","__derivedLinksType"],"sources":["configToShapeDefinition.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ObjectOrInterfaceDefinition } from \"../ontology/ObjectOrInterface.js\";\nimport { computeShapeId } from \"./computeShapeId.js\";\nimport type {\n InferShapeDefinition,\n InlineShapeConfig,\n} from \"./InlineShapeConfig.js\";\nimport { createShapeLinkBuilder } from \"./ShapeBuilder.js\";\nimport type {\n NullabilityOp,\n ShapeDefinition,\n ShapeDerivedLinkDef,\n ShapeLinkBuilderInternal,\n ShapeLinkObjectSetDef,\n ShapePropertyConfig,\n} from \"./ShapeDefinition.js\";\n\nexport function configToShapeDefinition<\n BASE extends ObjectOrInterfaceDefinition,\n const C extends InlineShapeConfig<BASE>,\n>(\n baseType: BASE,\n config: C,\n): InferShapeDefinition<BASE, C> {\n const baseTypeApiName = baseType.apiName;\n const props: Record<string, ShapePropertyConfig> = {};\n\n const seen = new Set<string>();\n function addProp(prop: string, config2: ShapePropertyConfig) {\n if (seen.has(prop)) {\n throw new Error(`Property \"${prop}\" appears in multiple config arrays`);\n }\n seen.add(prop);\n props[prop] = config2;\n }\n\n if (config.require) {\n for (const prop of config.require) {\n addProp(prop as string, { nullabilityOp: { type: \"require\" } });\n }\n }\n\n if (config.select) {\n for (const prop of config.select) {\n addProp(prop as string, { nullabilityOp: { type: \"select\" } });\n }\n }\n\n if (config.dropIfNull) {\n for (const prop of config.dropIfNull) {\n addProp(prop as string, { nullabilityOp: { type: \"dropIfNull\" } });\n }\n }\n\n if (config.defaults) {\n for (const [prop, defaultValue] of Object.entries(config.defaults)) {\n addProp(prop, {\n nullabilityOp: {\n type: \"withDefault\",\n defaultValue,\n } as NullabilityOp,\n });\n }\n }\n\n if (config.transforms) {\n for (const [prop, transform] of Object.entries(config.transforms)) {\n if (typeof transform !== \"function\") {\n throw new Error(\n `transforms[\"${prop}\"] must be a function, got: ${typeof transform}`,\n );\n }\n addProp(prop, {\n nullabilityOp: {\n type: \"withTransform\",\n transform,\n } as NullabilityOp,\n });\n }\n }\n\n const derivedLinks: ShapeDerivedLinkDef[] = [];\n\n if (config.links) {\n for (const [name, linkConfig] of Object.entries(config.links)) {\n const linkBuilder = createShapeLinkBuilder(baseTypeApiName);\n const traversed = linkConfig.via(linkBuilder as ShapeLinkBuilderInternal);\n const objectSetDef: ShapeLinkObjectSetDef =\n (traversed as ShapeLinkBuilderInternal).toObjectSetDef();\n\n const targetShape: ShapeDefinition<ObjectOrInterfaceDefinition> =\n linkConfig.target;\n\n derivedLinks.push({\n name,\n objectSetDef,\n targetShape,\n config: { defer: linkConfig.defer },\n });\n }\n }\n\n const shapeId = computeShapeId({\n baseTypeApiName,\n props,\n derivedLinks,\n });\n\n return {\n __shapeId: shapeId,\n __debugName: undefined,\n __baseType: baseType,\n __baseTypeApiName: baseTypeApiName,\n __props: Object.freeze({ ...props }),\n __derivedLinks: Object.freeze([...derivedLinks]),\n __selectedPropsType: {} as InferShapeDefinition<\n BASE,\n C\n >[\"__selectedPropsType\"],\n __derivedLinksType: {} as InferShapeDefinition<\n BASE,\n C\n >[\"__derivedLinksType\"],\n } as InferShapeDefinition<BASE, C>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,cAAc,QAAQ,qBAAqB;AAKpD,SAASC,sBAAsB,QAAQ,mB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,EAAEzC,QAAQ;IACpB0C,iBAAiB,EAAExC,eAAe;IAClCyC,OAAO,EAAEvB,MAAM,CAACwB,MAAM,CAAC;MAAE,GAAGxC;IAAM,CAAC,CAAC;IACpCyC,cAAc,EAAEzB,MAAM,CAACwB,MAAM,CAAC,CAAC,GAAGpB,YAAY,CAAC,CAAC;IAChDsB,mBAAmB,EAAE,CAAC,CAGE;IACxBC,kBAAkB,EAAE,CAAC;EAIvB,CAAC;AACH","ignoreList":[]}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2023 Palantir Technologies, Inc. All rights reserved.
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -14,13 +14,18 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import { describe, expectTypeOf, it } from "vitest";
18
- describe("DefaultToFalse", () => {
19
- it("infers properly", () => {
20
- expectTypeOf().toEqualTypeOf();
21
- expectTypeOf().toEqualTypeOf();
22
- expectTypeOf().toEqualTypeOf();
23
- expectTypeOf().toEqualTypeOf();
24
- });
25
- });
26
- //# sourceMappingURL=LinkDefinitions.test.js.map
17
+ // Core types
18
+
19
+ // Inline shape config types
20
+
21
+ // Error types and runtime values
22
+ export { isSourcePkSymbol, ShapeNullabilityError, SourcePrimaryKeySymbol } from "./ShapeDefinition.js";
23
+
24
+ // Builder functions
25
+ export { createShapeBuilder } from "./ShapeBuilder.js";
26
+
27
+ // Inline config converter
28
+ export { configToShapeDefinition } from "./configToShapeDefinition.js";
29
+
30
+ // Inline config converter uses computeShapeId internally but it is not part of the public API.
31
+ //# sourceMappingURL=index.js.map