@osdk/maker 0.9.0-beta.8 → 0.9.0-rc.32

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 (109) hide show
  1. package/CHANGELOG.md +221 -0
  2. package/build/browser/api/defineImportSpt.js +24 -2
  3. package/build/browser/api/defineImportSpt.js.map +1 -1
  4. package/build/browser/api/defineInterface.js +34 -6
  5. package/build/browser/api/defineInterface.js.map +1 -1
  6. package/build/browser/api/defineInterfaceLinkConstraint.js +2 -1
  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 +130 -14
  11. package/build/browser/api/defineOntology.js.map +1 -1
  12. package/build/browser/api/defineSpt.js +2 -0
  13. package/build/browser/api/defineSpt.js.map +1 -1
  14. package/build/browser/api/defineValueType.js +57 -10
  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 +461 -68
  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 +3 -4
  23. package/build/browser/cli/main.js.map +1 -1
  24. package/build/browser/index.js +2 -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 +24 -2
  30. package/build/esm/api/defineImportSpt.js.map +1 -1
  31. package/build/esm/api/defineInterface.js +34 -6
  32. package/build/esm/api/defineInterface.js.map +1 -1
  33. package/build/esm/api/defineInterfaceLinkConstraint.js +2 -1
  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 +130 -14
  38. package/build/esm/api/defineOntology.js.map +1 -1
  39. package/build/esm/api/defineSpt.js +2 -0
  40. package/build/esm/api/defineSpt.js.map +1 -1
  41. package/build/esm/api/defineValueType.js +57 -10
  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 +461 -68
  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 +3 -4
  50. package/build/esm/cli/main.js.map +1 -1
  51. package/build/esm/index.js +2 -0
  52. package/build/esm/index.js.map +1 -1
  53. package/package.json +26 -13
  54. package/build/browser/api/defineImportSpt.d.ts +0 -10
  55. package/build/browser/api/defineImportSpt.d.ts.map +0 -1
  56. package/build/browser/api/defineInterface.d.ts +0 -14
  57. package/build/browser/api/defineInterface.d.ts.map +0 -1
  58. package/build/browser/api/defineInterfaceLinkConstraint.d.ts +0 -21
  59. package/build/browser/api/defineInterfaceLinkConstraint.d.ts.map +0 -1
  60. package/build/browser/api/defineLink.d.ts +0 -18
  61. package/build/browser/api/defineLink.d.ts.map +0 -1
  62. package/build/browser/api/defineLink.js +0 -37
  63. package/build/browser/api/defineLink.js.map +0 -1
  64. package/build/browser/api/defineObject.d.ts +0 -15
  65. package/build/browser/api/defineObject.d.ts.map +0 -1
  66. package/build/browser/api/defineOntology.d.ts +0 -10
  67. package/build/browser/api/defineOntology.d.ts.map +0 -1
  68. package/build/browser/api/defineSpt.d.ts +0 -13
  69. package/build/browser/api/defineSpt.d.ts.map +0 -1
  70. package/build/browser/api/defineValueType.d.ts +0 -26
  71. package/build/browser/api/defineValueType.d.ts.map +0 -1
  72. package/build/browser/api/iconNames.d.ts +0 -3
  73. package/build/browser/api/iconNames.d.ts.map +0 -1
  74. package/build/browser/api/overall.test.d.ts +0 -2
  75. package/build/browser/api/overall.test.d.ts.map +0 -1
  76. package/build/browser/api/types.d.ts +0 -52
  77. package/build/browser/api/types.d.ts.map +0 -1
  78. package/build/browser/cli/main.d.ts +0 -2
  79. package/build/browser/cli/main.d.ts.map +0 -1
  80. package/build/browser/index.d.ts +0 -7
  81. package/build/browser/index.d.ts.map +0 -1
  82. package/build/esm/api/defineImportSpt.d.ts +0 -10
  83. package/build/esm/api/defineImportSpt.d.ts.map +0 -1
  84. package/build/esm/api/defineInterface.d.ts +0 -14
  85. package/build/esm/api/defineInterface.d.ts.map +0 -1
  86. package/build/esm/api/defineInterfaceLinkConstraint.d.ts +0 -21
  87. package/build/esm/api/defineInterfaceLinkConstraint.d.ts.map +0 -1
  88. package/build/esm/api/defineLink.d.ts +0 -18
  89. package/build/esm/api/defineLink.d.ts.map +0 -1
  90. package/build/esm/api/defineLink.js +0 -37
  91. package/build/esm/api/defineLink.js.map +0 -1
  92. package/build/esm/api/defineObject.d.ts +0 -15
  93. package/build/esm/api/defineObject.d.ts.map +0 -1
  94. package/build/esm/api/defineOntology.d.ts +0 -10
  95. package/build/esm/api/defineOntology.d.ts.map +0 -1
  96. package/build/esm/api/defineSpt.d.ts +0 -13
  97. package/build/esm/api/defineSpt.d.ts.map +0 -1
  98. package/build/esm/api/defineValueType.d.ts +0 -26
  99. package/build/esm/api/defineValueType.d.ts.map +0 -1
  100. package/build/esm/api/iconNames.d.ts +0 -3
  101. package/build/esm/api/iconNames.d.ts.map +0 -1
  102. package/build/esm/api/overall.test.d.ts +0 -2
  103. package/build/esm/api/overall.test.d.ts.map +0 -1
  104. package/build/esm/api/types.d.ts +0 -52
  105. package/build/esm/api/types.d.ts.map +0 -1
  106. package/build/esm/cli/main.d.ts +0 -2
  107. package/build/esm/cli/main.d.ts.map +0 -1
  108. package/build/esm/index.d.ts +0 -7
  109. package/build/esm/index.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,226 @@
1
1
  # @osdk/maker
2
2
 
3
+ ## 0.9.0-rc.32
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [55c05f2]
8
+ - @osdk/api@2.1.0-rc.32
9
+
10
+ ## 0.9.0-beta.31
11
+
12
+ ### Minor Changes
13
+
14
+ - bb8b219: Use new external packages instead of the internal ones.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [bb8b219]
19
+ - Updated dependencies [ee6224b]
20
+ - Updated dependencies [5fe2c8d]
21
+ - @osdk/api@2.1.0-beta.31
22
+
23
+ ## 0.9.0-beta.30
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [966d408]
28
+ - Updated dependencies [f03e39f]
29
+ - Updated dependencies [1591f04]
30
+ - Updated dependencies [785f663]
31
+ - Updated dependencies [2d5e648]
32
+ - @osdk/api@2.1.0-beta.30
33
+
34
+ ## 0.9.0-beta.29
35
+
36
+ ### Patch Changes
37
+
38
+ - Updated dependencies [f1145ff]
39
+ - @osdk/api@2.1.0-beta.29
40
+
41
+ ## 0.9.0-beta.28
42
+
43
+ ### Patch Changes
44
+
45
+ - Updated dependencies [f446d0c]
46
+ - @osdk/api@2.1.0-beta.28
47
+
48
+ ## 0.9.0-beta.27
49
+
50
+ ### Patch Changes
51
+
52
+ - @osdk/api@2.1.0-beta.27
53
+
54
+ ## 0.9.0-beta.26
55
+
56
+ ### Minor Changes
57
+
58
+ - 44e62f6: Updating fetch for auth and other packages.
59
+ - 94463b6: Support objects as code
60
+
61
+ ### Patch Changes
62
+
63
+ - Updated dependencies [7865cb6]
64
+ - Updated dependencies [9c4efe6]
65
+ - Updated dependencies [f19da8e]
66
+ - @osdk/api@2.1.0-beta.26
67
+
68
+ ## 0.9.0-beta.25
69
+
70
+ ### Patch Changes
71
+
72
+ - Updated dependencies [c80ca45]
73
+ - @osdk/api@2.1.0-beta.25
74
+
75
+ ## 0.9.0-beta.24
76
+
77
+ ### Patch Changes
78
+
79
+ - Updated dependencies [03f95eb]
80
+ - Updated dependencies [c691c8b]
81
+ - Updated dependencies [3c9ac22]
82
+ - @osdk/api@2.1.0-beta.24
83
+
84
+ ## 0.9.0-beta.23
85
+
86
+ ### Minor Changes
87
+
88
+ - f0b519d: Upgrade to vitest 3 and vite 6
89
+ - 7a95618: Generate new OMS APIs
90
+ - d665147: Update platform sdk deps
91
+
92
+ ### Patch Changes
93
+
94
+ - Updated dependencies [d794c19]
95
+ - Updated dependencies [62c1d63]
96
+ - @osdk/api@2.1.0-beta.23
97
+
98
+ ## 0.9.0-beta.22
99
+
100
+ ### Minor Changes
101
+
102
+ - 8d8bebb: Fix nullability
103
+ - c9da74c: Improves code quality by fixing linting errors
104
+
105
+ ### Patch Changes
106
+
107
+ - Updated dependencies [73fa373]
108
+ - @osdk/api@2.1.0-beta.22
109
+
110
+ ## 0.9.0-beta.21
111
+
112
+ ### Patch Changes
113
+
114
+ - Updated dependencies [3ea2e79]
115
+ - Updated dependencies [656f975]
116
+ - Updated dependencies [f34b3d4]
117
+ - @osdk/api@2.1.0-beta.21
118
+
119
+ ## 0.9.0-beta.20
120
+
121
+ ### Minor Changes
122
+
123
+ - 9d35a1f: Remove unused imports
124
+ - abfe4b3: Add support for reading struct properties.
125
+ - 06e66dc: Making interface type status configurable
126
+
127
+ ### Patch Changes
128
+
129
+ - Updated dependencies [9d35a1f]
130
+ - Updated dependencies [abfe4b3]
131
+ - Updated dependencies [c537e2d]
132
+ - @osdk/api@2.1.0-beta.20
133
+
134
+ ## 0.9.0-beta.19
135
+
136
+ ### Patch Changes
137
+
138
+ - Updated dependencies [cddc196]
139
+ - @osdk/api@2.1.0-beta.19
140
+
141
+ ## 0.9.0-beta.18
142
+
143
+ ### Patch Changes
144
+
145
+ - @osdk/api@2.1.0-beta.18
146
+
147
+ ## 0.9.0-beta.17
148
+
149
+ ### Patch Changes
150
+
151
+ - @osdk/api@2.1.0-beta.17
152
+
153
+ ## 0.9.0-beta.16
154
+
155
+ ### Minor Changes
156
+
157
+ - 0a4f131: Fix value types so they actually serialize correctly.
158
+ - 8e5e49a: Add optional link constraints
159
+
160
+ ### Patch Changes
161
+
162
+ - Updated dependencies [e5fe7c0]
163
+ - @osdk/api@2.1.0-beta.16
164
+
165
+ ## 0.9.0-beta.15
166
+
167
+ ### Patch Changes
168
+
169
+ - @osdk/api@2.1.0-beta.15
170
+
171
+ ## 0.9.0-beta.14
172
+
173
+ ### Minor Changes
174
+
175
+ - 91cfa3a: Fixing url parsing for client.
176
+ - 6b6c8a1: Updates gateway endpoints and changes fetchContents for attachments to return a response
177
+
178
+ ### Patch Changes
179
+
180
+ - Updated dependencies [0c56d21]
181
+ - Updated dependencies [6b6c8a1]
182
+ - @osdk/api@2.1.0-beta.14
183
+
184
+ ## 0.9.0-beta.13
185
+
186
+ ### Patch Changes
187
+
188
+ - @osdk/api@2.1.0-beta.13
189
+
190
+ ## 0.9.0-beta.12
191
+
192
+ ### Patch Changes
193
+
194
+ - @osdk/api@2.1.0-beta.12
195
+
196
+ ## 0.9.0-beta.11
197
+
198
+ ### Minor Changes
199
+
200
+ - bc1761c: Update platform API dependencies.
201
+ - caf1abc: Support generating linked products for marketplace
202
+
203
+ ### Patch Changes
204
+
205
+ - Updated dependencies [bc1761c]
206
+ - Updated dependencies [9298f75]
207
+ - @osdk/api@2.1.0-beta.11
208
+
209
+ ## 0.9.0-beta.10
210
+
211
+ ### Patch Changes
212
+
213
+ - Updated dependencies [11a05cc]
214
+ - Updated dependencies [11088aa]
215
+ - @osdk/api@2.1.0-beta.10
216
+
217
+ ## 0.9.0-beta.9
218
+
219
+ ### Patch Changes
220
+
221
+ - Updated dependencies [acbfab9]
222
+ - @osdk/api@2.1.0-beta.9
223
+
3
224
  ## 0.9.0-beta.8
4
225
 
5
226
  ### Minor Changes
@@ -13,13 +13,35 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+
17
+ import invariant from "tiny-invariant";
18
+ import { ontologyDefinition } from "./defineOntology.js";
16
19
  /**
17
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
18
21
  */
19
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
+ }
20
41
  return {
21
- apiName: opts.apiName,
22
- type: opts.typeHint
42
+ apiName: apiName,
43
+ type: typeHint,
44
+ nonNameSpacedApiName: apiName
23
45
  };
24
46
  }
25
47
  //# sourceMappingURL=defineImportSpt.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineImportSpt.js","names":["importSharedPropertyType","opts","apiName","type","typeHint"],"sources":["defineImportSpt.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 */\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(opts) {\n return { apiName: opts.apiName, type: opts.typeHint };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,wBAAwBA,CAACC,IAAI,EAAE;EAC3C,OAAO;IAAEC,OAAO,EAAED,IAAI,CAACC,OAAO;IAAEC,IAAI,EAAEF,IAAI,CAACG;EAAS,CAAC;AACzD","ignoreList":[]}
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,6 +13,7 @@
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";
@@ -21,7 +22,7 @@ export function defineInterface(opts) {
21
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
24
  if (typeof type === "string" || typeof type === "object" && !("apiName" in type)) {
24
- !isPropertyTypeType(type) ? process.env.NODE_ENV !== "production" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;
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,7 +31,8 @@ export function defineInterface(opts) {
30
31
  });
31
32
  return [apiName, spt];
32
33
  } else {
33
- !(namespace + apiName === type.apiName || apiName === type.apiName) ? process.env.NODE_ENV !== "production" ? 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
38
  })}`) : invariant(false) : void 0;
@@ -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
78
  function isPropertyTypeType(v) {
76
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";
77
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
+ }
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","process","env","NODE_ENV","properties","Object","fromEntries","entries","map","type","isPropertyTypeType","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 || (typeof type === \"object\" && !(\"apiName\" in type))) {\n invariant(isPropertyTypeType(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 || 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 isPropertyTypeType(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\"\n || (typeof v === \"object\" && v.type === \"marking\")\n || v === \"short\" || v === \"string\"\n || v === \"timestamp\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA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,EAAE/B,IAAI,CAAC6B,IAAI,CAACE,KAAK;UAAEC,OAAO,EAAEhC,IAAI,CAAC6B,IAAI,CAACG;QAAQ;MACpE,CAAC,GACC7B;IACV,CAAC;IACDiB,iBAAiB,EAAEA,iBAAiB;IACpCa,KAAK,EAAE,EAAE;IACT1B,UAAU;IACV2B,MAAM,EAAE;MAAEtB,IAAI,EAAE,QAAQ;MAAEuB,MAAM,EAAE,CAAC;IAAE;EACzC,CAAC;EACD,OAAOtC,kBAAkB,CAACK,cAAc,CAACD,OAAO,CAAC,GAAGyB,CAAC;AACzD;AACA,SAASb,kBAAkBA,CAACuB,CAAC,EAAE;EAC3B,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,IAC9B,OAAOA,CAAC,KAAK,QAAQ,IAAIA,CAAC,CAACxB,IAAI,KAAK,SAAU,IAC/CwB,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;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,SAASC,SAAS,EAAEC,kBAAkB,QAAQ,qBAAqB;AACnE,SAASC,wBAAwB,QAAQ,gBAAgB;AAczD,OAAO,SAASC,eAAeA,CAC7BC,IAYC,EACc;EACf,MAAMC,OAAO,GAAGL,SAAS,GAAGI,IAAI,CAACC,OAAO;EACxC,EACEJ,kBAAkB,CAACK,cAAc,CAACD,OAAO,CAAC,KAAKE,SAAS,IAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD1DX,SAAS,QAEP,aAAaM,OAAO,iBAAiB,IAFvCN,SAAS;EAKT,MAAMY,UAAU,GAAGC,MAAM,CAACC,WAAW,CACnCD,MAAM,CAACE,OAAO,CAACV,IAAI,CAACO,UAAU,IAAI,CAAC,CAAC,CAAC,CAACI,GAAG,CAGvC,CAAC,CAACV,OAAO,EAAEW,IAAI,CAAC,KAAK;IACnB,IACE,OAAOA,IAAI,KAAK,QAAQ,IACpB,OAAOA,IAAI,KAAK,QAAQ,IAAI,EAAE,SAAS,IAAIA,IAAI,CAAE,EACrD;MACA,CACEC,kBAAkB,CAACD,IAAI,CAAC,GAAAR,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD1BX,SAAS,QAEP,qBACEmB,IAAI,CAACC,SAAS,CAACH,IAAI,CAAC,iBACLX,OAAO,qBAAqBA,OAAO,EAAE,IAJxDN,SAAS;MAOT,MAAMqB,GAAG,GAAGlB,wBAAwB,CAAC;QACnCG,OAAO;QACPgB,WAAW,EAAEhB,OAAO;QACpBW,IAAI;QACJM,KAAK,EAAE;MACT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IAAIA,CAAC,KAAK,MAAM,IAC9B,OAAOA,CAAC,KAAK,QAAQ,IAAIA,CAAC,CAAC9B,IAAI,KAAK,SAAU,IAC/C8B,CAAC,KAAK,OAAO,IAAIA,CAAC,KAAK,QAAQ,IAC/BA,CAAC,KAAK,WAAW;AACxB;AAEA,SAASZ,wCAAwCA,CAC/CD,MAAqC,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,6 +13,7 @@
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) {
@@ -22,7 +23,7 @@ export function defineInterfaceLinkConstraint(linkDef) {
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","process","env","NODE_ENV","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,gBAAgB;AACtC,SAASC,SAAS,QAAQ,qBAAqB;A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,WAAW,IAAIjB;EAC/C,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
- process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false);
77
+ return {
78
+ type: "valid"
79
+ };
85
80
  }
86
81
  //# sourceMappingURL=defineObject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineObject.js","names":["invariant","ontologyDefinition","defineObject","apiName","opts","objectTypes","implementsInterfaces","implementsInterfaces2","linkTypes","objectType","primaryKey","displayName","pluralDisplayName","icon","color","name","type","properties","dataType","convertType","rid","status","titleProperty","sharedPropertyTypeMapping","data","t","multiplicity","subType","itemType","process","env","NODE_ENV"],"sources":["defineObject.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 { ontologyDefinition } from \"./defineOntology.js\";\nexport function defineObject(apiName, opts) {\n ontologyDefinition.objectTypes[apiName] = {\n implementsInterfaces: [],\n implementsInterfaces2: {},\n linkTypes: [],\n objectType: {\n apiName,\n primaryKey: opts.primaryKey.apiName,\n displayName: opts.displayName ?? apiName,\n pluralDisplayName: opts.pluralDisplayName ?? apiName,\n icon: {\n color: \"blue\",\n name: \"cube\",\n type: \"blueprint\",\n },\n properties: {\n [opts.primaryKey.apiName]: {\n dataType: convertType(opts.primaryKey),\n },\n },\n rid: \"PLACEHOLDER\",\n status: \"ACTIVE\",\n titleProperty: opts.primaryKey.apiName,\n },\n sharedPropertyTypeMapping: {},\n };\n // FIXME: don't return the raw value\n return {\n data: ontologyDefinition.objectTypes[apiName],\n linkTypes: {},\n };\n}\nfunction convertType(t) {\n switch (true) {\n case t.multiplicity === true:\n return {\n type: \"array\",\n subType: convertType({ ...t, multiplicity: false }),\n };\n case t.type === \"stringTimeseries\":\n return {\n itemType: {\n type: \"string\",\n },\n type: \"timeseries\",\n };\n break;\n case t.type === \"numericTimeseries\":\n return {\n itemType: {\n type: \"double\",\n },\n type: \"timeseries\",\n };\n case t.type === \"datetime\":\n return {\n type: \"timestamp\",\n };\n default:\n return {\n type: t.type,\n };\n }\n invariant(false);\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,kBAAkB,QAAQ,qBAAqB;AACxD,OAAO,SAASC,YAAYA,CAACC,OAAO,EAAEC,IAAI,EAAE;EACxCH,kBAAkB,CAACI,WAAW,CAACF,OAAO,CAAC,GAAG;IACtCG,oBAAoB,EAAE,EAAE;IACxBC,qBAAqB,EAAE,CAAC,CAAC;IACzBC,SAAS,EAAE,EAAE;IACbC,UAAU,EAAE;MACRN,OAAO;MACPO,UAAU,EAAEN,IAAI,CAACM,UAAU,CAACP,OAAO;MACnCQ,WAAW,EAAEP,IAAI,CAACO,WAAW,IAAIR,OAAO;MACxCS,iBAAiB,EAAER,IAAI,CAACQ,iBAAiB,IAAIT,OAAO;MACpDU,IAAI,EAAE;QACFC,KAAK,EAAE,MAAM;QACbC,IAAI,EAAE,MAAM;QACZC,IAAI,EAAE;MACV,CAAC;MACDC,UAAU,EAAE;QACR,CAACb,IAAI,CAACM,UAAU,CAACP,OAAO,GAAG;UACvBe,QAAQ,EAAEC,WAAW,CAACf,IAAI,CAACM,UAAU;QACzC;MACJ,CAAC;MACDU,GAAG,EAAE,aAAa;MAClBC,MAAM,EAAE,QAAQ;MAChBC,aAAa,EAAElB,IAAI,CAACM,UAAU,CAACP;IACnC,CAAC;IACDoB,yBAAyB,EAAE,CAAC;EAChC,CAAC;EACD;EACA,OAAO;IACHC,IAAI,EAAEvB,kBAAkB,CAACI,WAAW,CAACF,OAAO,CAAC;IAC7CK,SAAS,EAAE,CAAC;EAChB,CAAC;AACL;AACA,SAASW,WAAWA,CAACM,CAAC,EAAE;EACpB,QAAQ,IAAI;IACR,KAAKA,CAAC,CAACC,YAAY,KAAK,IAAI;MACxB,OAAO;QACHV,IAAI,EAAE,OAAO;QACbW,OAAO,EAAER,WAAW,CAAC;UAAE,GAAGM,CAAC;UAAEC,YAAY,EAAE;QAAM,CAAC;MACtD,CAAC;IACL,KAAKD,CAAC,CAACT,IAAI,KAAK,kBAAkB;MAC9B,OAAO;QACHY,QAAQ,EAAE;UACNZ,IAAI,EAAE;QACV,CAAC;QACDA,IAAI,EAAE;MACV,CAAC;MACD;IACJ,KAAKS,CAAC,CAACT,IAAI,KAAK,mBAAmB;MAC/B,OAAO;QACHY,QAAQ,EAAE;UACNZ,IAAI,EAAE;QACV,CAAC;QACDA,IAAI,EAAE;MACV,CAAC;IACL,KAAKS,CAAC,CAACT,IAAI,KAAK,UAAU;MACtB,OAAO;QACHA,IAAI,EAAE;MACV,CAAC;IACL;MACI,OAAO;QACHA,IAAI,EAAES,CAAC,CAACT;MACZ,CAAC;EACT;EACAa,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAAA/B,SAAS,UAATA,SAAS;AACb","ignoreList":[]}
1
+ {"version":3,"file":"defineObject.js","names":["invariant","namespace","ontologyDefinition","defineObject","objectDef","apiName","propertyApiNames","properties","map","val","objectTypes","undefined","Error","includes","titlePropertyApiName","process","env","NODE_ENV","primaryKeys","length","nonExistentPrimaryKeys","filter","primaryKey","implementsInterfaces","forEach","interfaceImpl","nonExistentInterfaceProperties","propertyMapping","interfaceProperty","implements","interfaceProp","type","reason","interfaceToObjectProperties","Object","fromEntries","mapping","mapsTo","validateProperty","nonNameSpacedApiName","validateInterfaceImplProperty","baseValidations","entries","extendsValidations","extendsInterfaces","flatMap","interfaceApiName","interfaceTypes","allFailedValidations","concat","formatValidationErrors","join","error","spt","mappedObjectProp","object","objProp","find","prop"],"sources":["defineObject.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 type { ObjectType, SharedPropertyType } from \"./types.js\";\n\nexport function defineObject(objectDef: ObjectType): ObjectType {\n const apiName = namespace + objectDef.apiName;\n const propertyApiNames = (objectDef.properties ?? []).map(val => val.apiName);\n if (ontologyDefinition.objectTypes[apiName] !== undefined) {\n throw new Error(\n `Object type with apiName ${objectDef.apiName} is already defined`,\n );\n }\n invariant(\n propertyApiNames.includes(objectDef.titlePropertyApiName),\n `Title property ${objectDef.titlePropertyApiName} is not defined on object ${objectDef.apiName}`,\n );\n invariant(\n objectDef.primaryKeys.length !== 0,\n `${objectDef.apiName} does not have any primary keys, objects must have at least one primary key`,\n );\n const nonExistentPrimaryKeys = objectDef.primaryKeys.filter(primaryKey =>\n !objectDef.properties?.map(val => val.apiName).includes(primaryKey)\n );\n invariant(\n nonExistentPrimaryKeys.length === 0,\n `Primary key properties ${nonExistentPrimaryKeys} do not exist on object ${objectDef.apiName}`,\n );\n\n objectDef.implementsInterfaces?.forEach(interfaceImpl => {\n const nonExistentInterfaceProperties: ValidationResult[] = interfaceImpl\n .propertyMapping.map(val => val.interfaceProperty).filter(\n interfaceProperty =>\n interfaceImpl.implements.properties[interfaceProperty] === undefined,\n ).map(interfaceProp => ({\n type: \"invalid\",\n reason:\n `Interface property ${interfaceImpl.implements.apiName}.${interfaceProp} referenced in ${objectDef.apiName} object does not exist`,\n }));\n\n const interfaceToObjectProperties = Object.fromEntries(\n interfaceImpl.propertyMapping.map(\n mapping => [mapping.interfaceProperty, mapping.mapsTo],\n ),\n );\n const validateProperty = (\n interfaceProp: [string, SharedPropertyType],\n ): ValidationResult => {\n if (\n interfaceProp[1].nonNameSpacedApiName in interfaceToObjectProperties\n ) {\n return validateInterfaceImplProperty(\n interfaceProp[1],\n interfaceToObjectProperties[interfaceProp[0]],\n objectDef,\n );\n }\n return {\n type: \"invalid\",\n reason: `Interface property ${interfaceImpl.implements.apiName}.${\n interfaceProp[1].nonNameSpacedApiName\n } not implemented by ${objectDef.apiName} object definition`,\n };\n };\n const baseValidations = Object.entries(interfaceImpl.implements.properties)\n .map<ValidationResult>(validateProperty);\n const extendsValidations = interfaceImpl.implements.extendsInterfaces\n .flatMap(interfaceApiName =>\n Object.entries(\n ontologyDefinition.interfaceTypes[interfaceApiName].properties,\n ).map(validateProperty)\n );\n\n const allFailedValidations = baseValidations.concat(\n extendsValidations,\n nonExistentInterfaceProperties,\n ).filter(val => val.type === \"invalid\");\n invariant(\n allFailedValidations.length === 0,\n \"\\n\" + allFailedValidations.map(formatValidationErrors).join(\"\\n\"),\n );\n });\n\n ontologyDefinition.objectTypes[apiName] = { ...objectDef, apiName: apiName };\n return { ...objectDef, apiName: apiName };\n}\n\ntype ValidationResult = { type: \"valid\" } | { type: \"invalid\"; reason: string };\n\nfunction formatValidationErrors(\n error: { type: \"invalid\"; reason: string },\n): string {\n return `Ontology Definition Error: ${error.reason}\\n`;\n}\n\n// Validate that the object and the interface property match up\nfunction validateInterfaceImplProperty(\n spt: SharedPropertyType,\n mappedObjectProp: string,\n object: ObjectType,\n): ValidationResult {\n const objProp = object.properties?.find(prop =>\n prop.apiName === mappedObjectProp\n );\n if (objProp === undefined) {\n return {\n type: \"invalid\",\n reason:\n `Object property mapped to interface does not exist. Object Property Mapped: ${mappedObjectProp}`,\n };\n }\n if (spt.type !== objProp?.type) {\n return {\n type: \"invalid\",\n reason:\n `Object property type does not match the interface property it is mapped to. Interface Property: ${spt.apiName}, objectProperty: ${mappedObjectProp}`,\n };\n }\n\n return { type: \"valid\" };\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,EAAEC,kBAAkB,QAAQ,qBAAqB;AAGnE,OAAO,SAASC,YAAYA,CAACC,SAAqB,EAAc;EAC9D,MAAMC,OAAO,GAAGJ,SAAS,GAAGG,SAAS,CAACC,OAAO;EAC7C,MAAMC,gBAAgB,GAAG,CAACF,SAAS,CAACG,UAAU,IAAI,EAAE,EAAEC,GAAG,CAACC,GAAG,IAAIA,GAAG,CAACJ,OAAO,CAAC;EAC7E,IAAIH,kBAAkB,CAACQ,WAAW,CAACL,OAAO,CAAC,KAAKM,SAAS,EAAE;IACzD,MAAM,IAAIC,KAAK,CACb,4BAA4BR,SAAS,CAACC,OAAO,qBAC/C,CAAC;EACH;EACA,CACEC,gBAAgB,CAACO,QAAQ,CAACT,SAAS,CAACU,oBAAoB,CAAC,GAAAC,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBAD3DjB,SAAS,QAEP,kBAAkBI,SAAS,CAACU,oBAAoB,6BAA6BV,SAAS,CAACC,OAAO,EAAE,IAFlGL,SAAS;EAIT,EACEI,SAAS,CAACc,WAAW,CAACC,MAAM,KAAK,CAAC,IAAAJ,OAAA,CAAAC,GAAA,CAAAC,QAAA,oBADpCjB,SAAS,QAEP,GAAGI,SAAS,CAACC,OAAO,6EAA6E,IAFnGL,SAAS;EAIT,MAAMoB,sBAAsB,GAAGhB,SAAS,CAACc,WAAW,CAACG,MAAM,CAACC,UAAU,IACpE,CAAClB,SAAS,CAACG,UAAU,EAAEC,GAAG,CAACC,GAAG,IAAIA,GAAG,CAACJ,OAAO,CAAC,CAACQ,QAAQ,CAACS,UAAU,CACpE,CAAC;EACD,EACEF,sBAAsB,CAACD,MA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