@osdk/maker 0.9.0-beta.3 → 0.9.0-beta.30

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 (105) hide show
  1. package/CHANGELOG.md +258 -0
  2. package/build/browser/api/defineImportSpt.js +47 -0
  3. package/build/browser/api/defineImportSpt.js.map +1 -0
  4. package/build/browser/api/defineInterface.js +39 -11
  5. package/build/browser/api/defineInterface.js.map +1 -1
  6. package/build/browser/api/defineInterfaceLinkConstraint.js +3 -2
  7. package/build/browser/api/defineInterfaceLinkConstraint.js.map +1 -1
  8. package/build/browser/api/defineObject.js +57 -62
  9. package/build/browser/api/defineObject.js.map +1 -1
  10. package/build/browser/api/defineOntology.js +194 -23
  11. package/build/browser/api/defineOntology.js.map +1 -1
  12. package/build/browser/api/defineSpt.js +3 -1
  13. package/build/browser/api/defineSpt.js.map +1 -1
  14. package/build/browser/api/defineValueType.js +58 -11
  15. package/build/browser/api/defineValueType.js.map +1 -1
  16. package/build/browser/api/iconNames.js +0 -15
  17. package/build/browser/api/iconNames.js.map +1 -1
  18. package/build/browser/api/overall.test.js +704 -63
  19. package/build/browser/api/overall.test.js.map +1 -1
  20. package/build/browser/api/types.js +0 -15
  21. package/build/browser/api/types.js.map +1 -1
  22. package/build/browser/cli/main.js +5 -6
  23. package/build/browser/cli/main.js.map +1 -1
  24. package/build/browser/index.js +3 -0
  25. package/build/browser/index.js.map +1 -1
  26. package/build/cjs/index.cjs +716 -0
  27. package/build/cjs/index.cjs.map +1 -0
  28. package/build/cjs/index.d.cts +343 -0
  29. package/build/esm/api/defineImportSpt.js +47 -0
  30. package/build/esm/api/defineImportSpt.js.map +1 -0
  31. package/build/esm/api/defineInterface.js +39 -11
  32. package/build/esm/api/defineInterface.js.map +1 -1
  33. package/build/esm/api/defineInterfaceLinkConstraint.js +3 -2
  34. package/build/esm/api/defineInterfaceLinkConstraint.js.map +1 -1
  35. package/build/esm/api/defineObject.js +57 -62
  36. package/build/esm/api/defineObject.js.map +1 -1
  37. package/build/esm/api/defineOntology.js +194 -23
  38. package/build/esm/api/defineOntology.js.map +1 -1
  39. package/build/esm/api/defineSpt.js +3 -1
  40. package/build/esm/api/defineSpt.js.map +1 -1
  41. package/build/esm/api/defineValueType.js +58 -11
  42. package/build/esm/api/defineValueType.js.map +1 -1
  43. package/build/esm/api/iconNames.js +0 -15
  44. package/build/esm/api/iconNames.js.map +1 -1
  45. package/build/esm/api/overall.test.js +704 -63
  46. package/build/esm/api/overall.test.js.map +1 -1
  47. package/build/esm/api/types.js +0 -15
  48. package/build/esm/api/types.js.map +1 -1
  49. package/build/esm/cli/main.js +5 -6
  50. package/build/esm/cli/main.js.map +1 -1
  51. package/build/esm/index.js +3 -0
  52. package/build/esm/index.js.map +1 -1
  53. package/package.json +28 -13
  54. package/build/browser/api/defineInterface.d.ts +0 -14
  55. package/build/browser/api/defineInterface.d.ts.map +0 -1
  56. package/build/browser/api/defineInterfaceLinkConstraint.d.ts +0 -21
  57. package/build/browser/api/defineInterfaceLinkConstraint.d.ts.map +0 -1
  58. package/build/browser/api/defineLink.d.ts +0 -18
  59. package/build/browser/api/defineLink.d.ts.map +0 -1
  60. package/build/browser/api/defineLink.js +0 -37
  61. package/build/browser/api/defineLink.js.map +0 -1
  62. package/build/browser/api/defineObject.d.ts +0 -15
  63. package/build/browser/api/defineObject.d.ts.map +0 -1
  64. package/build/browser/api/defineOntology.d.ts +0 -10
  65. package/build/browser/api/defineOntology.d.ts.map +0 -1
  66. package/build/browser/api/defineSpt.d.ts +0 -13
  67. package/build/browser/api/defineSpt.d.ts.map +0 -1
  68. package/build/browser/api/defineValueType.d.ts +0 -26
  69. package/build/browser/api/defineValueType.d.ts.map +0 -1
  70. package/build/browser/api/iconNames.d.ts +0 -3
  71. package/build/browser/api/iconNames.d.ts.map +0 -1
  72. package/build/browser/api/overall.test.d.ts +0 -2
  73. package/build/browser/api/overall.test.d.ts.map +0 -1
  74. package/build/browser/api/types.d.ts +0 -38
  75. package/build/browser/api/types.d.ts.map +0 -1
  76. package/build/browser/cli/main.d.ts +0 -2
  77. package/build/browser/cli/main.d.ts.map +0 -1
  78. package/build/browser/index.d.ts +0 -6
  79. package/build/browser/index.d.ts.map +0 -1
  80. package/build/esm/api/defineInterface.d.ts +0 -14
  81. package/build/esm/api/defineInterface.d.ts.map +0 -1
  82. package/build/esm/api/defineInterfaceLinkConstraint.d.ts +0 -21
  83. package/build/esm/api/defineInterfaceLinkConstraint.d.ts.map +0 -1
  84. package/build/esm/api/defineLink.d.ts +0 -18
  85. package/build/esm/api/defineLink.d.ts.map +0 -1
  86. package/build/esm/api/defineLink.js +0 -37
  87. package/build/esm/api/defineLink.js.map +0 -1
  88. package/build/esm/api/defineObject.d.ts +0 -15
  89. package/build/esm/api/defineObject.d.ts.map +0 -1
  90. package/build/esm/api/defineOntology.d.ts +0 -10
  91. package/build/esm/api/defineOntology.d.ts.map +0 -1
  92. package/build/esm/api/defineSpt.d.ts +0 -13
  93. package/build/esm/api/defineSpt.d.ts.map +0 -1
  94. package/build/esm/api/defineValueType.d.ts +0 -26
  95. package/build/esm/api/defineValueType.d.ts.map +0 -1
  96. package/build/esm/api/iconNames.d.ts +0 -3
  97. package/build/esm/api/iconNames.d.ts.map +0 -1
  98. package/build/esm/api/overall.test.d.ts +0 -2
  99. package/build/esm/api/overall.test.d.ts.map +0 -1
  100. package/build/esm/api/types.d.ts +0 -38
  101. package/build/esm/api/types.d.ts.map +0 -1
  102. package/build/esm/cli/main.d.ts +0 -2
  103. package/build/esm/cli/main.d.ts.map +0 -1
  104. package/build/esm/index.d.ts +0 -6
  105. package/build/esm/index.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,263 @@
1
1
  # @osdk/maker
2
2
 
3
+ ## 0.9.0-beta.30
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [966d408]
8
+ - Updated dependencies [f03e39f]
9
+ - Updated dependencies [1591f04]
10
+ - Updated dependencies [785f663]
11
+ - Updated dependencies [2d5e648]
12
+ - @osdk/api@2.1.0-beta.30
13
+
14
+ ## 0.9.0-beta.29
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [f1145ff]
19
+ - @osdk/api@2.1.0-beta.29
20
+
21
+ ## 0.9.0-beta.28
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [f446d0c]
26
+ - @osdk/api@2.1.0-beta.28
27
+
28
+ ## 0.9.0-beta.27
29
+
30
+ ### Patch Changes
31
+
32
+ - @osdk/api@2.1.0-beta.27
33
+
34
+ ## 0.9.0-beta.26
35
+
36
+ ### Minor Changes
37
+
38
+ - 44e62f6: Updating fetch for auth and other packages.
39
+ - 94463b6: Support objects as code
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [7865cb6]
44
+ - Updated dependencies [9c4efe6]
45
+ - Updated dependencies [f19da8e]
46
+ - @osdk/api@2.1.0-beta.26
47
+
48
+ ## 0.9.0-beta.25
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [c80ca45]
53
+ - @osdk/api@2.1.0-beta.25
54
+
55
+ ## 0.9.0-beta.24
56
+
57
+ ### Patch Changes
58
+
59
+ - Updated dependencies [03f95eb]
60
+ - Updated dependencies [c691c8b]
61
+ - Updated dependencies [3c9ac22]
62
+ - @osdk/api@2.1.0-beta.24
63
+
64
+ ## 0.9.0-beta.23
65
+
66
+ ### Minor Changes
67
+
68
+ - f0b519d: Upgrade to vitest 3 and vite 6
69
+ - 7a95618: Generate new OMS APIs
70
+ - d665147: Update platform sdk deps
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies [d794c19]
75
+ - Updated dependencies [62c1d63]
76
+ - @osdk/api@2.1.0-beta.23
77
+
78
+ ## 0.9.0-beta.22
79
+
80
+ ### Minor Changes
81
+
82
+ - 8d8bebb: Fix nullability
83
+ - c9da74c: Improves code quality by fixing linting errors
84
+
85
+ ### Patch Changes
86
+
87
+ - Updated dependencies [73fa373]
88
+ - @osdk/api@2.1.0-beta.22
89
+
90
+ ## 0.9.0-beta.21
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [3ea2e79]
95
+ - Updated dependencies [656f975]
96
+ - Updated dependencies [f34b3d4]
97
+ - @osdk/api@2.1.0-beta.21
98
+
99
+ ## 0.9.0-beta.20
100
+
101
+ ### Minor Changes
102
+
103
+ - 9d35a1f: Remove unused imports
104
+ - abfe4b3: Add support for reading struct properties.
105
+ - 06e66dc: Making interface type status configurable
106
+
107
+ ### Patch Changes
108
+
109
+ - Updated dependencies [9d35a1f]
110
+ - Updated dependencies [abfe4b3]
111
+ - Updated dependencies [c537e2d]
112
+ - @osdk/api@2.1.0-beta.20
113
+
114
+ ## 0.9.0-beta.19
115
+
116
+ ### Patch Changes
117
+
118
+ - Updated dependencies [cddc196]
119
+ - @osdk/api@2.1.0-beta.19
120
+
121
+ ## 0.9.0-beta.18
122
+
123
+ ### Patch Changes
124
+
125
+ - @osdk/api@2.1.0-beta.18
126
+
127
+ ## 0.9.0-beta.17
128
+
129
+ ### Patch Changes
130
+
131
+ - @osdk/api@2.1.0-beta.17
132
+
133
+ ## 0.9.0-beta.16
134
+
135
+ ### Minor Changes
136
+
137
+ - 0a4f131: Fix value types so they actually serialize correctly.
138
+ - 8e5e49a: Add optional link constraints
139
+
140
+ ### Patch Changes
141
+
142
+ - Updated dependencies [e5fe7c0]
143
+ - @osdk/api@2.1.0-beta.16
144
+
145
+ ## 0.9.0-beta.15
146
+
147
+ ### Patch Changes
148
+
149
+ - @osdk/api@2.1.0-beta.15
150
+
151
+ ## 0.9.0-beta.14
152
+
153
+ ### Minor Changes
154
+
155
+ - 91cfa3a: Fixing url parsing for client.
156
+ - 6b6c8a1: Updates gateway endpoints and changes fetchContents for attachments to return a response
157
+
158
+ ### Patch Changes
159
+
160
+ - Updated dependencies [0c56d21]
161
+ - Updated dependencies [6b6c8a1]
162
+ - @osdk/api@2.1.0-beta.14
163
+
164
+ ## 0.9.0-beta.13
165
+
166
+ ### Patch Changes
167
+
168
+ - @osdk/api@2.1.0-beta.13
169
+
170
+ ## 0.9.0-beta.12
171
+
172
+ ### Patch Changes
173
+
174
+ - @osdk/api@2.1.0-beta.12
175
+
176
+ ## 0.9.0-beta.11
177
+
178
+ ### Minor Changes
179
+
180
+ - bc1761c: Update platform API dependencies.
181
+ - caf1abc: Support generating linked products for marketplace
182
+
183
+ ### Patch Changes
184
+
185
+ - Updated dependencies [bc1761c]
186
+ - Updated dependencies [9298f75]
187
+ - @osdk/api@2.1.0-beta.11
188
+
189
+ ## 0.9.0-beta.10
190
+
191
+ ### Patch Changes
192
+
193
+ - Updated dependencies [11a05cc]
194
+ - Updated dependencies [11088aa]
195
+ - @osdk/api@2.1.0-beta.10
196
+
197
+ ## 0.9.0-beta.9
198
+
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies [acbfab9]
202
+ - @osdk/api@2.1.0-beta.9
203
+
204
+ ## 0.9.0-beta.8
205
+
206
+ ### Minor Changes
207
+
208
+ - b8a1a58: Add nullability to markings because of course they need to be nullable. This sucks in the data model, I should talk to the ontology team about this.
209
+
210
+ ### Patch Changes
211
+
212
+ - Updated dependencies [9f3807c]
213
+ - @osdk/api@2.1.0-beta.8
214
+
215
+ ## 0.9.0-beta.7
216
+
217
+ ### Minor Changes
218
+
219
+ - cd8d657: Support importing foreign SPTs
220
+ - 9018dc2: Updating platform api dependencies.
221
+
222
+ ### Patch Changes
223
+
224
+ - Updated dependencies [27866a8]
225
+ - Updated dependencies [31e7d70]
226
+ - @osdk/api@2.1.0-beta.7
227
+
228
+ ## 0.9.0-beta.6
229
+
230
+ ### Minor Changes
231
+
232
+ - 25fd9f0: Updating package.json to have better entry points to support react native bundlers.
233
+
234
+ ### Patch Changes
235
+
236
+ - Updated dependencies [25fd9f0]
237
+ - Updated dependencies [1a89f23]
238
+ - Updated dependencies [1b2e8c9]
239
+ - @osdk/api@2.1.0-beta.6
240
+
241
+ ## 0.9.0-beta.5
242
+
243
+ ### Minor Changes
244
+
245
+ - b0544d4: Add additional marking configuration
246
+ - 2b35ed4: Structs in maker package
247
+
248
+ ### Patch Changes
249
+
250
+ - @osdk/api@2.1.0-beta.5
251
+
252
+ ## 0.9.0-beta.4
253
+
254
+ ### Patch Changes
255
+
256
+ - Updated dependencies [0dc40b0]
257
+ - Updated dependencies [1dc0228]
258
+ - Updated dependencies [d3b3f35]
259
+ - @osdk/api@2.1.0-beta.4
260
+
3
261
  ## 0.9.0-beta.3
4
262
 
5
263
  ### Minor Changes
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright 2024 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 invariant from "tiny-invariant";
18
+ import { ontologyDefinition } from "./defineOntology.js";
19
+ /**
20
+ * Defines a foreign shared property type you want to take as an input to your product. The typeHint field is used for OSDK generation
21
+ */
22
+ export function importSharedPropertyType(opts) {
23
+ const {
24
+ apiName,
25
+ packageName,
26
+ typeHint
27
+ } = opts;
28
+ if (packageName !== undefined) {
29
+ ontologyDefinition.importedTypes.sharedPropertyTypes.push({
30
+ apiName,
31
+ packageName
32
+ });
33
+ !!packageName.endsWith(".") ? process.env.NODE_ENV !== "production" ? invariant(false, "Package name format invalid ends with period") : invariant(false) : void 0;
34
+ !(packageName.match("[A-Z]") == null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Package name includes upper case characters") : invariant(false) : void 0;
35
+ return {
36
+ apiName: packageName + "." + apiName,
37
+ type: typeHint,
38
+ nonNameSpacedApiName: apiName
39
+ };
40
+ }
41
+ return {
42
+ apiName: apiName,
43
+ type: typeHint,
44
+ nonNameSpacedApiName: apiName
45
+ };
46
+ }
47
+ //# sourceMappingURL=defineImportSpt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineImportSpt.js","names":["invariant","ontologyDefinition","importSharedPropertyType","opts","apiName","packageName","typeHint","undefined","importedTypes","sharedPropertyTypes","push","endsWith","process","env","NODE_ENV","match","type","nonNameSpacedApiName"],"sources":["defineImportSpt.ts"],"sourcesContent":["/*\n * Copyright 2024 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 invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nimport type { PropertyTypeType, SharedPropertyType } from \"./types.js\";\n\n/**\n * Defines a foreign shared property type you want to take as an input to your product. The typeHint field is used for OSDK generation\n */\nexport function importSharedPropertyType(\n opts: {\n apiName: string;\n packageName?: string;\n typeHint: PropertyTypeType;\n },\n): SharedPropertyType {\n const { apiName, packageName, typeHint } = opts;\n if (packageName !== undefined) {\n ontologyDefinition.importedTypes.sharedPropertyTypes.push({\n apiName,\n packageName,\n });\n invariant(\n !packageName.endsWith(\".\"),\n \"Package name format invalid ends with period\",\n );\n\n invariant(\n packageName.match(\"[A-Z]\") == null,\n \"Package name includes upper case characters\",\n );\n\n return {\n apiName: packageName + \".\" + apiName,\n type: typeHint,\n nonNameSpacedApiName: apiName,\n };\n }\n return { apiName: apiName, type: typeHint, nonNameSpacedApiName: apiName };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,kBAAkB,QAAQ,qBAAqB;AAGxD;AACA;AACA;AACA,OAAO,SAASC,wBAAwBA,CACtCC,IAIC,EACmB;EACpB,MAAM;IAAEC,OAAO;IAAEC,WAAW;IAAEC;EAAS,CAAC,GAAGH,IAAI;EAC/C,IAAIE,WAAW,KAAKE,SAAS,EAAE;IAC7BN,kBAAkB,CAACO,aAAa,CAACC,mBAAmB,CAACC,IAAI,CAAC;MACxDN,OAAO;MACPC;IACF,CAAC,CAAC;IACF,CACE,CAACA,WAAW,CAACM,QAAQ,CAAC,GAAG,CAAC,GAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD5Bd,SAAS,QAEP,8CAA8C,IAFhDA,SAAS;IAKT,EACEK,WAAW,CAACU,KAAK,CAAC,OAAO,CAAC,IAAI,IAAI,IAAAH,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADpCd,SAAS,QAEP,6CAA6C,IAF/CA,SAAS;IAKT,OAAO;MACLI,OAAO,EAAEC,WAAW,GAAG,GAAG,GAAGD,OAAO;MACpCY,IAAI,EAAEV,QAAQ;MACdW,oBAAoB,EAAEb;IACxB,CAAC;EACH;EACA,OAAO;IAAEA,OAAO,EAAEA,OAAO;IAAEY,IAAI,EAAEV,QAAQ;IAAEW,oBAAoB,EAAEb;EAAQ,CAAC;AAC5E","ignoreList":[]}
@@ -13,15 +13,16 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
16
17
  import invariant from "tiny-invariant";
17
18
  import { namespace, ontologyDefinition } from "./defineOntology.js";
18
19
  import { defineSharedPropertyType } from "./defineSpt.js";
19
20
  export function defineInterface(opts) {
20
21
  const apiName = namespace + opts.apiName;
21
- !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? invariant(false, `Interface ${apiName} already exists`) : void 0;
22
+ !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;
22
23
  const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {
23
- if (typeof type === "string") {
24
- !isSimpleType(type) ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : void 0;
24
+ if (typeof type === "string" || typeof type === "object" && !("apiName" in type)) {
25
+ !isPropertyTypeType(type) ? process.env.NODE_ENV !== "production" ? invariant(false, `Invalid data type ${JSON.stringify(type)} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;
25
26
  const spt = defineSharedPropertyType({
26
27
  apiName,
27
28
  displayName: apiName,
@@ -30,10 +31,11 @@ export function defineInterface(opts) {
30
31
  });
31
32
  return [apiName, spt];
32
33
  } else {
33
- !(namespace + apiName === type.apiName) ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({
34
+ const unNamespacedTypeApiName = type.apiName.slice(type.apiName.lastIndexOf(".") + 1);
35
+ !(namespace + apiName === type.apiName || apiName === unNamespacedTypeApiName) ? process.env.NODE_ENV !== "production" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({
34
36
  key: apiName,
35
37
  apiName: type.apiName
36
- })}`) : void 0;
38
+ })}`) : invariant(false) : void 0;
37
39
  return [apiName, type];
38
40
  }
39
41
  }));
@@ -49,6 +51,10 @@ export function defineInterface(opts) {
49
51
  extendsInterfaces = opts.extends.map(item => item.apiName);
50
52
  }
51
53
  }
54
+ const status = mapSimplifiedStatusToInterfaceTypeStatus(opts.status ?? {
55
+ type: "active"
56
+ });
57
+ !(status.type !== "deprecated" || status.deprecated.message && status.deprecated.deadline) ? process.env.NODE_ENV !== "production" ? invariant(false, `Deprecated status must include message and deadline properties.`) : invariant(false) : void 0;
52
58
  const a = {
53
59
  apiName,
54
60
  displayMetadata: {
@@ -65,14 +71,36 @@ export function defineInterface(opts) {
65
71
  extendsInterfaces: extendsInterfaces,
66
72
  links: [],
67
73
  properties,
68
- status: {
69
- type: "active",
70
- active: {}
71
- }
74
+ status
72
75
  };
73
76
  return ontologyDefinition.interfaceTypes[apiName] = a;
74
77
  }
75
- function isSimpleType(v) {
76
- return v === "boolean" || v === "byte" || v === "date" || v === "decimal" || v === "double" || v === "float" || v === "geopoint" || v === "geoshape" || v === "integer" || v === "long" || v === "marking" || v === "short" || v === "string" || v === "timestamp";
78
+ function isPropertyTypeType(v) {
79
+ return v === "boolean" || v === "byte" || v === "date" || v === "decimal" || v === "double" || v === "float" || v === "geopoint" || v === "geoshape" || v === "integer" || v === "long" || typeof v === "object" && v.type === "marking" || v === "short" || v === "string" || v === "timestamp";
80
+ }
81
+ function mapSimplifiedStatusToInterfaceTypeStatus(status) {
82
+ switch (status.type) {
83
+ case "deprecated":
84
+ return {
85
+ type: "deprecated",
86
+ deprecated: {
87
+ message: status.message,
88
+ deadline: status.deadline,
89
+ replacedBy: undefined
90
+ }
91
+ };
92
+ case "active":
93
+ return {
94
+ type: "active",
95
+ active: {}
96
+ };
97
+ case "experimental":
98
+ return {
99
+ type: "experimental",
100
+ experimental: {}
101
+ };
102
+ default:
103
+ throw new Error(`Invalid status type: ${status.type}`);
104
+ }
77
105
  }
78
106
  //# sourceMappingURL=defineInterface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineInterface.js","names":["invariant","namespace","ontologyDefinition","defineSharedPropertyType","defineInterface","opts","apiName","interfaceTypes","undefined","properties","Object","fromEntries","entries","map","type","isSimpleType","spt","displayName","array","JSON","stringify","key","extendsInterfaces","extends","Array","isArray","every","item","a","displayMetadata","description","icon","blueprint","color","locator","links","status","active","v"],"sources":["defineInterface.js"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport invariant from \"tiny-invariant\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nimport { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const apiName = namespace + opts.apiName;\n invariant(ontologyDefinition.interfaceTypes[apiName] === undefined, `Interface ${apiName} already exists`);\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n invariant(isSimpleType(type), `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`);\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false,\n });\n return [apiName, spt];\n }\n else {\n invariant(namespace + apiName === type.apiName, `property key and it's apiName must be identical. ${JSON.stringify({ key: apiName, apiName: type.apiName })}`);\n return [apiName, type];\n }\n }));\n let extendsInterfaces = [];\n if (opts.extends) {\n if (typeof opts.extends === \"string\") {\n extendsInterfaces = [opts.extends];\n }\n else if (Array.isArray(opts.extends)\n && opts.extends.every(item => typeof item === \"string\")) {\n extendsInterfaces = opts.extends;\n }\n else if (opts.extends.apiName !== undefined) {\n extendsInterfaces = [opts.extends.apiName];\n }\n else {\n extendsInterfaces = opts.extends.map(item => item.apiName);\n }\n }\n const a = {\n apiName,\n displayMetadata: {\n displayName: opts.displayName ?? opts.apiName,\n description: opts.description ?? opts.displayName ?? opts.apiName,\n icon: opts.icon !== undefined\n ? {\n type: \"blueprint\",\n blueprint: { color: opts.icon.color, locator: opts.icon.locator },\n }\n : undefined,\n },\n extendsInterfaces: extendsInterfaces,\n links: [],\n properties,\n status: { type: \"active\", active: {} },\n };\n return ontologyDefinition.interfaceTypes[apiName] = a;\n}\nfunction isSimpleType(v) {\n return v === \"boolean\" || v === \"byte\"\n || v === \"date\" || v === \"decimal\" || v === \"double\"\n || v === \"float\" || v === \"geopoint\" || v === \"geoshape\"\n || v === \"integer\" || v === \"long\" || v === \"marking\"\n || v === \"short\" || v === \"string\"\n || v === \"timestamp\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,EAAEC,kBAAkB,QAAQ,qBAAqB;AACnE,SAASC,wBAAwB,QAAQ,gBAAgB;AACzD,OAAO,SAASC,eAAeA,CAACC,IAAI,EAAE;EAClC,MAAMC,OAAO,GAAGL,SAAS,GAAGI,IAAI,CAACC,OAAO;EACxC,EAAUJ,kBAAkB,CAACK,cAAc,CAACD,OAAO,CAAC,KAAKE,SAAS,IAAlER,SAAS,QAA2D,aAAaM,OAAO,iBAAiB;EACzG,MAAMG,UAAU,GAAGC,MAAM,CAACC,WAAW,CAACD,MAAM,CAACE,OAAO,CAACP,IAAI,CAACI,UAAU,IAAI,CAAC,CAAC,CAAC,CAACI,GAAG,CAAC,CAAC,CAACP,OAAO,EAAEQ,IAAI,CAAC,KAAK;IACjG,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC1B,CAAUC,YAAY,CAACD,IAAI,CAAC,GAA5Bd,SAAS,QAAqB,qBAAqBc,IAAI,iBAAiBR,OAAO,qBAAqBA,OAAO,EAAE;MAC7G,MAAMU,GAAG,GAAGb,wBAAwB,CAAC;QACjCG,OAAO;QACPW,WAAW,EAAEX,OAAO;QACpBQ,IAAI;QACJI,KAAK,EAAE;MACX,CAAC,CAAC;MACF,OAAO,CAACZ,OAAO,EAAEU,GAAG,CAAC;IACzB,CAAC,MACI;MACD,EAAUf,SAAS,GAAGK,OAAO,KAAKQ,IAAI,CAACR,OAAO,IAA9CN,SAAS,QAAuC,oDAAoDmB,IAAI,CAACC,SAAS,CAAC;QAAEC,GAAG,EAAEf,OAAO;QAAEA,OAAO,EAAEQ,IAAI,CAACR;MAAQ,CAAC,CAAC,EAAE;MAC7J,OAAO,CAACA,OAAO,E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,KAAK,EAAE,EAAE;IACT1B,UAAU;IACV2B,MAAM,EAAE;MAAEtB,IAAI,EAAE,QAAQ;MAAEuB,MAAM,EAAE,CAAC;IAAE;EACzC,CAAC;EACD,OAAOnC,kBAAkB,CAACK,cAAc,CAACD,OAAO,CAAC,GAAGsB,CAAC;AACzD;AACA,SAASb,YAAYA,CAACuB,CAAC,EAAE;EACrB,OAAOA,CAAC,KAAK,SAAS,IAAIA,CAAC,KAAK,MAAM,IAC/BA,CAAC,KAAK,MAAM,IAAIA,CAAC,KAAK,SAAS,IAAIA,CAAC,KAAK,QAAQ,IACjDA,CAAC,KAAK,OAAO,IAAIA,CAAC,KAAK,UAAU,IAAIA,CAAC,KAAK,UAAU,IACrDA,CAAC,KAAK,SAAS,IAAIA,CAAC,KAAK,MAAM,IAAIA,CAAC,KAAK,SAAS,IAClDA,CAAC,KAAK,OAAO,IAAIA,CAAC,KAAK,QAAQ,IAC/BA,CAAC,KAAK,WAAW;AAC5B","ignoreList":[]}
1
+ {"version":3,"file":"defineInterface.js","names":["invariant","namespace","ontologyDefinition","defineSharedPropertyType","defineInterface","opts","apiName","interfaceTypes","undefined","process","env","NODE_ENV","properties","Object","fromEntries","entries","map","type","isPropertyTypeType","JSON","stringify","spt","displayName","array","unNamespacedTypeApiName","slice","lastIndexOf","key","extendsInterfaces","extends","Array","isArray","every","item","status","mapSimplifiedStatusToInterfaceTypeStatus","deprecated","message","deadline","a","displayMetadata","description","icon","blueprint","color","locator","links","v","replacedBy","active","experimental","Error"],"sources":["defineInterface.ts"],"sourcesContent":["/*\n * Copyright 2024 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 invariant from \"tiny-invariant\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nimport { defineSharedPropertyType } from \"./defineSpt.js\";\nimport type { BlueprintIcon } from \"./iconNames.js\";\nimport type {\n InterfaceType,\n InterfaceTypeStatus,\n PropertyTypeType,\n SharedPropertyType,\n} from \"./types.js\";\n\ntype SimplifiedInterfaceTypeStatus =\n | { type: \"deprecated\"; message: string; deadline: string }\n | { type: \"active\" }\n | { type: \"experimental\" };\n\nexport function defineInterface(\n opts: {\n apiName: string;\n displayName?: string;\n description?: string;\n icon?: { locator: BlueprintIcon; color: string };\n status?: SimplifiedInterfaceTypeStatus;\n properties?: Record<\n string,\n SharedPropertyType | PropertyTypeType\n >;\n\n extends?: InterfaceType | InterfaceType[] | string | string[];\n },\n): InterfaceType {\n const apiName = namespace + opts.apiName;\n invariant(\n ontologyDefinition.interfaceTypes[apiName] === undefined,\n `Interface ${apiName} already exists`,\n );\n\n const properties = Object.fromEntries(\n Object.entries(opts.properties ?? {}).map<\n [string, SharedPropertyType]\n >(\n ([apiName, type]) => {\n if (\n typeof type === \"string\"\n || (typeof type === \"object\" && !(\"apiName\" in type))\n ) {\n invariant(\n isPropertyTypeType(type),\n `Invalid data type ${\n JSON.stringify(type)\n } for property ${apiName} on InterfaceType ${apiName}`,\n );\n\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false,\n });\n return [apiName, spt];\n } else {\n const unNamespacedTypeApiName = type.apiName.slice(\n type.apiName.lastIndexOf(\".\") + 1,\n );\n invariant(\n namespace + apiName === type.apiName\n || apiName === unNamespacedTypeApiName,\n `property key and it's apiName must be identical. ${\n JSON.stringify({ key: apiName, apiName: type.apiName })\n }`,\n );\n return [apiName, type];\n }\n },\n ),\n );\n\n let extendsInterfaces: string[] = [];\n if (opts.extends) {\n if (typeof opts.extends === \"string\") {\n extendsInterfaces = [opts.extends];\n } else if (\n Array.isArray(opts.extends)\n && opts.extends.every(item => typeof item === \"string\")\n ) {\n extendsInterfaces = opts.extends;\n } else if ((opts.extends as InterfaceType).apiName !== undefined) {\n extendsInterfaces = [(opts.extends as InterfaceType).apiName];\n } else {\n extendsInterfaces = (opts.extends as InterfaceType[]).map(item =>\n item.apiName\n );\n }\n }\n\n const status: InterfaceTypeStatus = mapSimplifiedStatusToInterfaceTypeStatus(\n opts.status ?? { type: \"active\" },\n );\n\n invariant(\n status.type !== \"deprecated\"\n || (status.deprecated.message && status.deprecated.deadline),\n `Deprecated status must include message and deadline properties.`,\n );\n\n const a: InterfaceType = {\n apiName,\n displayMetadata: {\n displayName: opts.displayName ?? opts.apiName,\n description: opts.description ?? opts.displayName ?? opts.apiName,\n icon: opts.icon !== undefined\n ? {\n type: \"blueprint\",\n blueprint: { color: opts.icon.color, locator: opts.icon.locator },\n }\n : undefined,\n },\n extendsInterfaces: extendsInterfaces,\n links: [],\n properties,\n status,\n };\n\n return ontologyDefinition.interfaceTypes[apiName] = a;\n}\n\nfunction isPropertyTypeType(\n v: PropertyTypeType,\n): v is PropertyTypeType {\n return v === \"boolean\" || v === \"byte\"\n || v === \"date\" || v === \"decimal\" || v === \"double\"\n || v === \"float\" || v === \"geopoint\" || v === \"geoshape\"\n || v === \"integer\" || v === \"long\"\n || (typeof v === \"object\" && v.type === \"marking\")\n || v === \"short\" || v === \"string\"\n || v === \"timestamp\";\n}\n\nfunction mapSimplifiedStatusToInterfaceTypeStatus(\n status: SimplifiedInterfaceTypeStatus,\n): InterfaceTypeStatus {\n switch (status.type) {\n case \"deprecated\":\n return {\n type: \"deprecated\",\n deprecated: {\n message: status.message,\n deadline: status.deadline,\n replacedBy: undefined,\n },\n };\n case \"active\":\n return {\n type: \"active\",\n active: {},\n };\n case \"experimental\":\n return {\n type: \"experimental\",\n experimental: {},\n };\n default:\n throw new Error(`Invalid status type: ${(status as any).type}`);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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AAqC,EAChB;EACrB,QAAQA,MAAM,CAACjB,IAAI;IACjB,KAAK,YAAY;MACf,OAAO;QACLA,IAAI,EAAE,YAAY;QAClBmB,UAAU,EAAE;UACVC,OAAO,EAAEH,MAAM,CAACG,OAAO;UACvBC,QAAQ,EAAEJ,MAAM,CAACI,QAAQ;UACzBU,UAAU,EAAExC;QACd;MACF,CAAC;IACH,KAAK,QAAQ;MACX,OAAO;QACLS,IAAI,EAAE,QAAQ;QACdgC,MAAM,EAAE,CAAC;MACX,CAAC;IACH,KAAK,cAAc;MACjB,OAAO;QACLhC,IAAI,EAAE,cAAc;QACpBiC,YAAY,EAAE,CAAC;MACjB,CAAC;IACH;MACE,MAAM,IAAIC,KAAK,CAAC,wBAAyBjB,MAAM,CAASjB,IAAI,EAAE,CAAC;EACnE;AACF","ignoreList":[]}
@@ -13,16 +13,17 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
16
17
  import invariant from "tiny-invariant";
17
18
  import { namespace } from "./defineOntology.js";
18
19
  export function defineInterfaceLinkConstraint(linkDef) {
19
20
  const fromLinkMeta = getLinkMeta(linkDef);
20
- !(linkDef.from.links.find(a => a.metadata.apiName === fromLinkMeta.apiName) == null) ? invariant(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`) : void 0;
21
+ !(linkDef.from.links.find(a => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`) : invariant(false) : void 0;
21
22
  linkDef.from.links.push({
22
23
  cardinality: linkDef.toMany ? "MANY" : "SINGLE",
23
24
  linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),
24
25
  metadata: fromLinkMeta,
25
- required: true // TODO: expose this?
26
+ required: linkDef.required ?? true
26
27
  });
27
28
  }
28
29
  function getLinkedType(t) {
@@ -1 +1 @@
1
- {"version":3,"file":"defineInterfaceLinkConstraint.js","names":["invariant","namespace","defineInterfaceLinkConstraint","linkDef","fromLinkMeta","getLinkMeta","from","links","find","a","metadata","apiName","push","cardinality","toMany","linkedEntityTypeId","getLinkedType","toOne","required","t","type","interfaceType","meta","withDefaults","description","displayName"],"sources":["defineInterfaceLinkConstraint.js"],"sourcesContent":["/*\n * Copyright 2024 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 */\nimport invariant from \"tiny-invariant\";\nimport { namespace } from \"./defineOntology.js\";\nexport function defineInterfaceLinkConstraint(linkDef) {\n const fromLinkMeta = getLinkMeta(linkDef);\n invariant(linkDef.from.links.find(a => a.metadata.apiName === fromLinkMeta.apiName)\n == null, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`);\n linkDef.from.links.push({\n cardinality: linkDef.toMany ? \"MANY\" : \"SINGLE\",\n linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),\n metadata: fromLinkMeta,\n required: true, // TODO: expose this?\n });\n}\nfunction getLinkedType(t) {\n return {\n type: \"interfaceType\",\n interfaceType: typeof t === \"string\" ? t : t.apiName,\n };\n}\nfunction getLinkMeta(meta) {\n return typeof meta === \"string\"\n ? withDefaults({ apiName: namespace + meta })\n : withDefaults(meta);\n}\nfunction withDefaults({ apiName, description, displayName }) {\n return {\n apiName: namespace + apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,gBA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CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"defineInterfaceLinkConstraint.js","names":["invariant","namespace","defineInterfaceLinkConstraint","linkDef","fromLinkMeta","getLinkMeta","from","links","find","a","metadata","apiName","process","env","NODE_ENV","push","cardinality","toMany","linkedEntityTypeId","getLinkedType","toOne","required","t","type","interfaceType","meta","withDefaults","description","displayName"],"sources":["defineInterfaceLinkConstraint.ts"],"sourcesContent":["/*\n * Copyright 2024 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 invariant from \"tiny-invariant\";\nimport { namespace } from \"./defineOntology.js\";\nimport type { InterfaceType } from \"./types.js\";\n\ntype Meta = { apiName: string; displayName?: string; description?: string };\ntype ApiNameOrInterfaceType = string | InterfaceType;\n\ntype Many = {\n apiName: string;\n from: InterfaceType;\n toMany: ApiNameOrInterfaceType;\n toOne?: never;\n displayName?: string;\n description?: string;\n required?: boolean;\n};\ntype One = {\n apiName: string;\n from: InterfaceType;\n toOne: ApiNameOrInterfaceType;\n toMany?: never;\n displayName?: string;\n description?: string;\n required?: boolean;\n};\n\nexport function defineInterfaceLinkConstraint(\n linkDef: One | Many,\n): void {\n const fromLinkMeta = getLinkMeta(linkDef);\n\n invariant(\n linkDef.from.links.find(a => a.metadata.apiName === fromLinkMeta.apiName)\n == null,\n `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`,\n );\n\n linkDef.from.links.push({\n cardinality: linkDef.toMany ? \"MANY\" : \"SINGLE\",\n linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),\n metadata: fromLinkMeta,\n required: linkDef.required ?? true,\n });\n}\n\nfunction getLinkedType(t: string | InterfaceType) {\n return {\n type: \"interfaceType\" as const,\n interfaceType: typeof t === \"string\" ? t : t.apiName,\n };\n}\n\nfunction getLinkMeta(meta: One | Many) {\n return typeof meta === \"string\"\n ? withDefaults({ apiName: namespace + meta })\n : withDefaults(meta);\n}\n\nfunction withDefaults(\n { apiName, description, displayName }: Meta,\n): Required<Meta> {\n return {\n apiName: namespace + apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,QAAQ,qBAAqB;AAyB/C,OAAO,SAASC,6BAA6BA,CAC3CC,OAAmB,EACb;EACN,MAAMC,YAAY,GAAGC,WAAW,CAACF,OAAO,CAAC;EAEzC,EACEA,OAAO,CAACG,IAAI,CAACC,KAAK,CAACC,IAAI,CAACC,CAAC,IAAIA,CAAC,CAACC,QAAQ,CAACC,OAAO,KAAKP,YAAY,CAACO,OAAO,CAAC,IACpE,IAAI,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAFXd,SAAS,QAGP,qBAAqBI,YAAY,CAACO,OAAO,sBAAsBR,OAAO,CAACQ,OAAO,EAAE,IAHlFX,SAAS;EAMTG,OAAO,CAACG,IAAI,CAACC,KAAK,CAACQ,IAAI,CAAC;IACtBC,WAAW,EAAEb,OAAO,CAACc,MAAM,GAAG,MAAM,GAAG,QAAQ;IAC/CC,kBAAkB,EAAEC,aAAa,CAAChB,OAAO,CAACc,MAAM,IAAId,OAAO,CAACiB,KAAK,CAAC;IAClEV,QAAQ,EAAEN,YAAY;IACtBiB,QAAQ,EAAElB,OAAO,CAACkB,QAAQ,IAAI;EAChC,CAAC,CAAC;AACJ;AAEA,SAASF,aAAaA,CAACG,CAAyB,EAAE;EAChD,OAAO;IACLC,IAAI,EAAE,eAAwB;IAC9BC,aAAa,EAAE,OAAOF,CAAC,KAAK,QAAQ,GAAGA,CAAC,GAAGA,CAAC,CAACX;EAC/C,CAAC;AACH;AAEA,SAASN,WAAWA,CAACoB,IAAgB,EAAE;EACrC,OAAO,OAAOA,IAAI,KAAK,QAAQ,GAC3BC,YAAY,CAAC;IAAEf,OAAO,EAAEV,SAAS,GAAGwB;EAAK,CAAC,CAAC,GAC3CC,YAAY,CAACD,IAAI,CAAC;AACxB;AAEA,SAASC,YAAYA,CACnB;EAAEf,OAAO;EAAEgB,WAAW;EAAEC;AAAkB,CAAC,EAC3B;EAChB,OAAO;IACLjB,OAAO,EAAEV,SAAS,GAAGU,OAAO;IAC5BiB,WAAW,EAAEA,WAAW,IAAIjB,OAAO;IACnCgB,WAAW,EAAEA,WAAW,IAAIC,WAAW,IAAIjB;EAC7C,CAAC;AACH","ignoreList":[]}
@@ -13,74 +13,69 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
16
17
  import invariant from "tiny-invariant";
17
- import { ontologyDefinition } from "./defineOntology.js";
18
- export function defineObject(apiName, opts) {
18
+ import { namespace, ontologyDefinition } from "./defineOntology.js";
19
+ export function defineObject(objectDef) {
20
+ const apiName = namespace + objectDef.apiName;
21
+ const propertyApiNames = (objectDef.properties ?? []).map(val => val.apiName);
22
+ if (ontologyDefinition.objectTypes[apiName] !== undefined) {
23
+ throw new Error(`Object type with apiName ${objectDef.apiName} is already defined`);
24
+ }
25
+ !propertyApiNames.includes(objectDef.titlePropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant(false, `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`) : invariant(false) : void 0;
26
+ !(objectDef.primaryKeys.length !== 0) ? process.env.NODE_ENV !== "production" ? invariant(false, `${objectDef.apiName} does not have any primary keys, objects must have at least one primary key`) : invariant(false) : void 0;
27
+ const nonExistentPrimaryKeys = objectDef.primaryKeys.filter(primaryKey => !objectDef.properties?.map(val => val.apiName).includes(primaryKey));
28
+ !(nonExistentPrimaryKeys.length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, `Primary key properties ${nonExistentPrimaryKeys} do not exist on object ${objectDef.apiName}`) : invariant(false) : void 0;
29
+ objectDef.implementsInterfaces?.forEach(interfaceImpl => {
30
+ const nonExistentInterfaceProperties = interfaceImpl.propertyMapping.map(val => val.interfaceProperty).filter(interfaceProperty => interfaceImpl.implements.properties[interfaceProperty] === undefined).map(interfaceProp => ({
31
+ type: "invalid",
32
+ reason: `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`
33
+ }));
34
+ const interfaceToObjectProperties = Object.fromEntries(interfaceImpl.propertyMapping.map(mapping => [mapping.interfaceProperty, mapping.mapsTo]));
35
+ const validateProperty = interfaceProp => {
36
+ if (interfaceProp[1].nonNameSpacedApiName in interfaceToObjectProperties) {
37
+ return validateInterfaceImplProperty(interfaceProp[1], interfaceToObjectProperties[interfaceProp[0]], objectDef);
38
+ }
39
+ return {
40
+ type: "invalid",
41
+ reason: `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp[1].nonNameSpacedApiName} not implemented by ${objectDef.apiName} object definition`
42
+ };
43
+ };
44
+ const baseValidations = Object.entries(interfaceImpl.implements.properties).map(validateProperty);
45
+ const extendsValidations = interfaceImpl.implements.extendsInterfaces.flatMap(interfaceApiName => Object.entries(ontologyDefinition.interfaceTypes[interfaceApiName].properties).map(validateProperty));
46
+ const allFailedValidations = baseValidations.concat(extendsValidations, nonExistentInterfaceProperties).filter(val => val.type === "invalid");
47
+ !(allFailedValidations.length === 0) ? process.env.NODE_ENV !== "production" ? invariant(false, "\n" + allFailedValidations.map(formatValidationErrors).join("\n")) : invariant(false) : void 0;
48
+ });
19
49
  ontologyDefinition.objectTypes[apiName] = {
20
- implementsInterfaces: [],
21
- implementsInterfaces2: {},
22
- linkTypes: [],
23
- objectType: {
24
- apiName,
25
- primaryKey: opts.primaryKey.apiName,
26
- displayName: opts.displayName ?? apiName,
27
- pluralDisplayName: opts.pluralDisplayName ?? apiName,
28
- icon: {
29
- color: "blue",
30
- name: "cube",
31
- type: "blueprint"
32
- },
33
- properties: {
34
- [opts.primaryKey.apiName]: {
35
- dataType: convertType(opts.primaryKey)
36
- }
37
- },
38
- rid: "PLACEHOLDER",
39
- status: "ACTIVE",
40
- titleProperty: opts.primaryKey.apiName
41
- },
42
- sharedPropertyTypeMapping: {}
50
+ ...objectDef,
51
+ apiName: apiName
43
52
  };
44
- // FIXME: don't return the raw value
45
53
  return {
46
- data: ontologyDefinition.objectTypes[apiName],
47
- linkTypes: {}
54
+ ...objectDef,
55
+ apiName: apiName
48
56
  };
49
57
  }
50
- function convertType(t) {
51
- switch (true) {
52
- case t.multiplicity === true:
53
- return {
54
- type: "array",
55
- subType: convertType({
56
- ...t,
57
- multiplicity: false
58
- })
59
- };
60
- case t.type === "stringTimeseries":
61
- return {
62
- itemType: {
63
- type: "string"
64
- },
65
- type: "timeseries"
66
- };
67
- break;
68
- case t.type === "numericTimeseries":
69
- return {
70
- itemType: {
71
- type: "double"
72
- },
73
- type: "timeseries"
74
- };
75
- case t.type === "datetime":
76
- return {
77
- type: "timestamp"
78
- };
79
- default:
80
- return {
81
- type: t.type
82
- };
58
+ function formatValidationErrors(error) {
59
+ return `Ontology Definition Error: ${error.reason}\n`;
60
+ }
61
+
62
+ // Validate that the object and the interface property match up
63
+ function validateInterfaceImplProperty(spt, mappedObjectProp, object) {
64
+ const objProp = object.properties?.find(prop => prop.apiName === mappedObjectProp);
65
+ if (objProp === undefined) {
66
+ return {
67
+ type: "invalid",
68
+ reason: `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`
69
+ };
70
+ }
71
+ if (spt.type !== objProp?.type) {
72
+ return {
73
+ type: "invalid",
74
+ reason: `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`
75
+ };
83
76
  }
84
- invariant(false);
77
+ return {
78
+ type: "valid"
79
+ };
85
80
  }
86
81
  //# sourceMappingURL=defineObject.js.map