@osdk/maker 0.7.0-beta.0 → 0.7.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @osdk/maker
2
2
 
3
+ ## 0.7.0-beta.2
4
+
5
+ ### Minor Changes
6
+
7
+ - bc89b62: Spelling fixes and spell check in CI
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [3ec7c38]
12
+ - Updated dependencies [bc89b62]
13
+ - @osdk/api@1.9.0-beta.1
14
+ - @osdk/gateway@2.4.0-beta.0
15
+
16
+ ## 0.7.0-beta.1
17
+
18
+ ### Minor Changes
19
+
20
+ - 388dba9: Change all internal dependencies to be tilde not caret
21
+ - dc93aa6: Update ontology as code interface link types to reflect internal expectations of ontology integration
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [388dba9]
26
+ - @osdk/api@1.9.0-beta.0
27
+
3
28
  ## 0.7.0-beta.0
4
29
 
5
30
  ### Minor Changes
@@ -3,7 +3,7 @@ import * as fs from 'fs/promises';
3
3
  import * as path from 'path';
4
4
  import yargs from 'yargs';
5
5
  import { hideBin } from 'yargs/helpers';
6
- import invariant5 from 'tiny-invariant';
6
+ import invariant2 from 'tiny-invariant';
7
7
 
8
8
  // src/cli/main.ts
9
9
 
@@ -128,7 +128,7 @@ function defineSharedPropertyType(opts) {
128
128
  const {
129
129
  apiName
130
130
  } = opts;
131
- !(ontologyDefinition.sharedPropertyTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Shared property type ${apiName} already exists`) : invariant5(false) : void 0;
131
+ !(ontologyDefinition.sharedPropertyTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Shared property type ${apiName} already exists`) : invariant2(false) : void 0;
132
132
  return ontologyDefinition.sharedPropertyTypes[apiName] = {
133
133
  ...opts
134
134
  };
@@ -139,10 +139,10 @@ function defineInterface(opts) {
139
139
  const {
140
140
  apiName
141
141
  } = opts;
142
- !(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Interface ${apiName} already exists`) : invariant5(false) : void 0;
142
+ !(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Interface ${apiName} already exists`) : invariant2(false) : void 0;
143
143
  const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
144
144
  if (typeof type === "string") {
145
- !isSimpleType(type) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Invalid data type ${type} for property ${apiName2} on InterfaceType ${apiName2}`) : invariant5(false) : void 0;
145
+ !isSimpleType(type) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Invalid data type ${type} for property ${apiName2} on InterfaceType ${apiName2}`) : invariant2(false) : void 0;
146
146
  const spt = defineSharedPropertyType({
147
147
  apiName: apiName2,
148
148
  displayName: apiName2,
@@ -151,10 +151,10 @@ function defineInterface(opts) {
151
151
  });
152
152
  return [apiName2, spt];
153
153
  } else {
154
- !(apiName2 === type.apiName) ? process.env.NODE_ENV !== "production" ? invariant5(false, `property key and it's apiName must be identical. ${JSON.stringify({
154
+ !(apiName2 === type.apiName) ? process.env.NODE_ENV !== "production" ? invariant2(false, `property key and it's apiName must be identical. ${JSON.stringify({
155
155
  key: apiName2,
156
156
  apiName: type.apiName
157
- })}`) : invariant5(false) : void 0;
157
+ })}`) : invariant2(false) : void 0;
158
158
  return [apiName2, type];
159
159
  }
160
160
  }));
@@ -181,7 +181,7 @@ function isSimpleType(v) {
181
181
 
182
182
  // src/cli/main.ts
183
183
  async function main(args = process.argv) {
184
- const commandLineOpts = await yargs(hideBin(args)).version("0.7.0-beta.0").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
184
+ const commandLineOpts = await yargs(hideBin(args)).version("0.7.0-beta.2").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
185
185
  input: {
186
186
  alias: "i",
187
187
  describe: "Input file",
@@ -213,36 +213,21 @@ async function loadOntology(input) {
213
213
  const q = await defineOntology("", async () => await import(input));
214
214
  return q;
215
215
  }
216
- function defineInterfaceLinkConstraint({
217
- from,
218
- to
219
- }) {
220
- !(from.one == null && from.many || from.one && from.many == null) ? process.env.NODE_ENV !== "production" ? invariant5(false, "from should have either one or many, not both") : invariant5(false) : void 0;
221
- !(to.one == null && to.many || to.one && to.many == null) ? process.env.NODE_ENV !== "production" ? invariant5(false, "to should have either one or many, not both") : invariant5(false) : void 0;
222
- !!(from.many && to.many) ? process.env.NODE_ENV !== "production" ? invariant5(false, "many to many is not supported") : invariant5(false) : void 0;
223
- const fromLinkMeta = getLinkMeta(from.one ?? from.many);
224
- const toLinkMeta = getLinkMeta(to.one ?? to.many);
225
- !(from.type.links.find((a) => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${from.type.apiName}`) : invariant5(false) : void 0;
226
- !(to.type.links.find((a) => a.metadata.apiName === toLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Link with apiName ${toLinkMeta.apiName} already exists on ${to.type.apiName}`) : invariant5(false) : void 0;
227
- from.type.links.push({
228
- cardinality: from.many ? "MANY" : "SINGLE",
229
- linkedEntityTypeId: getLinkedType(to.type),
216
+ function defineInterfaceLinkConstraint(linkDef) {
217
+ const fromLinkMeta = getLinkMeta(linkDef);
218
+ !(linkDef.from.links.find((a) => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`) : invariant2(false) : void 0;
219
+ linkDef.from.links.push({
220
+ cardinality: linkDef.toMany ? "MANY" : "SINGLE",
221
+ linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),
230
222
  metadata: fromLinkMeta,
231
223
  required: true
232
224
  // TODO: expose this?
233
225
  });
234
- to.type.links.push({
235
- cardinality: to.one ? "SINGLE" : "MANY",
236
- linkedEntityTypeId: getLinkedType(from.type),
237
- metadata: toLinkMeta,
238
- required: true
239
- // TODO: expose this?
240
- });
241
226
  }
242
227
  function getLinkedType(t) {
243
228
  return {
244
229
  type: "interfaceType",
245
- interfaceType: t.apiName
230
+ interfaceType: typeof t === "string" ? t : t.apiName
246
231
  };
247
232
  }
248
233
  function getLinkMeta(meta) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineLink.ts","../../src/api/defineObject.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";AAgBA,SAAS,eAAe;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACJxB,OAAOA,gBAAe;;;ACCf,IAAI;AAGJ,IAAI;AACX,eAAsB,eAAe,IAAI,MAAM;AAC7C,cAAY;AACZ,uBAAqB;AAAA,IACnB,aAAa,CAAC;AAAA,IACd,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,qBAAqB,CAAC;AAAA,EACxB;AACA,MAAI;AACF,UAAM,KAAK;AAAA,EACb,SAAS,GAAG;AAEV,YAAQ,MAAM,8DAA8D,CAAC;AAC7E,UAAM;AAAA,EACR;AACA,SAAO,sBAAsB,kBAAkB;AACjD;AACA,SAAS,sBAAsB,UAAU;AACvC,SAAO;AAAA,IACL,qBAAqB,OAAO,YAAY,OAAO,QAAQ,SAAS,mBAAmB,EAAE,IAAI,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;AAAA,MACrH,oBAAoB,WAAW,GAAG;AAAA,IACpC,CAAC,CAAC,CAAC;AAAA,IACH,gBAAgB,OAAO,YAAY,OAAO,QAAQ,SAAS,cAAc,EA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K,KAAK,MAAM,KAAK,OAAK,EAAE,SAAS,YAAY,aAAa,OAAO,KAAK,QAAQ,QAAQ,IAAI,aAAa,eAAeA,WAAU,OAAO,qBAAqB,aAAa,OAAO,sBAAsB,KAAK,KAAK,OAAO,EAAE,IAAIA,WAAU,KAAK,IAAI;AACtP,IAAE,GAAG,KAAK,MAAM,KAAK,OAAK,EAAE,SAAS,YAAY,WAAW,OAAO,KAAK,QAAQ,QAAQ,IAAI,aAAa,eAAeA,WAAU,OAAO,qBAAqB,WAAW,OAAO,sBAAsB,GAAG,KAAK,OAAO,EAAE,IAAIA,WAAU,KAAK,IAAI;AAC9O,OAAK,KAAK,MAAM,KAAK;AAAA,IACnB,aAAa,KAAK,OAAO,SAAS;AAAA,IAClC,oBAAoB,cAAc,GAAG,IAAI;AAAA,IACzC,UAAU;AAAA,IACV,UAAU;AAAA;AAAA,EACZ,CAAC;AACD,KAAG,KAAK,MAAM,KAAK;AAAA,IACjB,aAAa,GAAG,MAAM,WAAW;AAAA,IACjC,oBAAoB,cAAc,KAAK,IAAI;AAAA,IAC3C,UAAU;AAAA,IACV,UAAU;AAAA;AAAA,EACZ,CAAC;AACH;AACA,SAAS,cAAc,GAAG;AACxB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,eAAe,EAAE;AAAA,EACnB;AACF;AACA,SAAS,YAAY,MAAM;AACzB,SAAO,OAAO,SAAS,WAAW,aAAa;AAAA,IAC7C,SAAS;AAAA,EACX,CAAC,IAAI,aAAa,IAAI;AACxB;AACA,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACF,GAAG;AACD,SAAO;AAAA,IACL;AAAA,IACA,aAAa,eAAe;AAAA,IAC5B,aAAa,eAAe,eAAe;AAAA,EAC7C;AACF","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 { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { defineInterface } from \"../api/defineInterface.js\";\nimport { defineLink } from \"../api/defineLink.js\";\nimport { defineObject } from \"../api/defineObject.js\";\nimport { defineOntology } from \"../api/defineOntology.js\";\nimport { defineSharedPropertyType } from \"../api/defineSpt.js\";\nexport default async function main(args = process.argv) {\n const commandLineOpts = await yargs(hideBin(args)).version(process.env.PACKAGE_VERSION ?? \"\").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({\n input: {\n alias: \"i\",\n describe: \"Input file\",\n type: \"string\",\n default: \".ontology/ontology.ts\",\n coerce: path.resolve\n },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\",\n coerce: path.resolve\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve\n }\n }).parseAsync();\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n const ontology = await loadOntology(commandLineOpts.input);\n consola.info(`Saving ontology to ${commandLineOpts.output}`);\n await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));\n}\nasync function loadOntologyViaJiti(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const jiti_ = await import(\"jiti\");\n const jiti = jiti_.default(process.cwd(), {\n debug: true\n });\n return defineOntology(\"\", async () => await jiti(input));\n}\nasync function loadOntologyViaTsNode(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const tsNode = await import(\"ts-node\");\n const tsNodeService = tsNode.register({\n transpileOnly: true,\n compilerOptions: {\n module: \"commonjs\",\n target: \"esnext\"\n },\n esm: true\n });\n tsNodeService.enabled(true);\n const q = await import(input);\n return q;\n}\nasync function loadOntology(input) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(\"\", async () => await import(input));\n return q;\n}","/*\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 { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n !isSimpleType(type) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false\n });\n return [apiName, spt];\n } else {\n !(apiName === type.apiName) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({\n key: apiName,\n apiName: type.apiName\n })}`) : invariant(false) : void 0;\n return [apiName, type];\n }\n }));\n const a = {\n apiName,\n displayMetadata: {\n displayName: opts.displayName ?? apiName,\n description: opts.description ?? opts.displayName ?? apiName,\n icon: undefined\n },\n extendsInterfaces: [],\n links: [],\n properties,\n status: {\n type: \"active\",\n active: {}\n }\n };\n return ontologyDefinition.interfaceTypes[apiName] = a;\n}\nfunction isSimpleType(v) {\n 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\";\n}","/*\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/** @internal */\nexport let ontologyDefinition;\n\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n objectTypes: {},\n queryTypes: {},\n interfaceTypes: {},\n sharedPropertyTypes: {}\n };\n try {\n await body();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertToWireOntology(ontology) {\n return {\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {\n sharedPropertyType: convertSpt(spt)\n }])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {\n return [apiName, {\n interfaceType: convertInterface(interfaceType)\n }];\n })),\n blockPermissionInformation: {\n actionTypes: {},\n linkTypes: {},\n objectTypes: {}\n }\n };\n}\nfunction convertInterface(interfaceType) {\n return {\n ...interfaceType,\n properties: Object.values(interfaceType.properties).map(spt => convertSpt(spt)),\n // these are omitted from our internal types but we need to re-add them for the final json\n allExtendsInterfaces: [],\n allLinks: [],\n allProperties: []\n };\n}\nexport function dumpOntologyFullMetadata() {\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertSpt({\n type,\n array,\n description,\n apiName,\n displayName\n}) {\n return {\n apiName,\n displayMetadata: {\n displayName: displayName ?? apiName,\n visibility: \"NORMAL\",\n description\n },\n type: array ? {\n type: \"array\",\n array: {\n subtype: convertType(type)\n }\n } : convertType(type),\n aliases: [],\n baseFormatter: undefined,\n dataConstraints: undefined,\n gothamMapping: undefined,\n indexedForSearch: true,\n provenance: undefined,\n typeClasses: [],\n valueType: undefined\n };\n}\nfunction convertType(type) {\n switch (type) {\n case \"marking\":\n return {\n type,\n [type]: {\n markingType: \"MANDATORY\"\n }\n };\n case \"geopoint\":\n return {\n type: \"geohash\",\n geohash: {}\n };\n case \"decimal\":\n return {\n type,\n [type]: {\n precision: undefined,\n scale: undefined\n }\n };\n case \"string\":\n return {\n type,\n [type]: {\n analyzerOverride: undefined,\n enableAsciiFolding: undefined,\n isLongText: false,\n supportsExactMatching: true\n }\n };\n default:\n // use helper function to distribute `type` properly\n return distributeTypeHelper(type);\n }\n}\n\n/**\n * Helper function to avoid duplication. Makes the types match properly with the correct\n * behavior without needing to switch on type.\n * @param type\n * @returns\n */\nfunction distributeTypeHelper(type) {\n return {\n type,\n [type]: {}\n }; // any cast to match conditional return type\n}","/*\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\";\nexport function defineSharedPropertyType(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n ...opts\n };\n}","/*\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\";\nexport function defineLink(from, opts) {\n const apiName = opts.one ?? opts.many;\n const toApiName = opts.reverse.one ?? opts.reverse.many;\n const to = opts.to;\n !(from.linkTypes[apiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${apiName} already exists on ${from.data.objectType.apiName}`) : invariant(false) : void 0;\n !(from.linkTypes[toApiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toApiName} already exists on ${to.data.objectType.apiName}`) : invariant(false) : void 0;\n from.linkTypes[apiName] = {\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: to.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n to.linkTypes[toApiName] = {\n apiName: toApiName,\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: from.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n}","/*\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\";\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 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\n // FIXME: dont 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({\n ...t,\n multiplicity: false\n })\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 !false ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n}","/*\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\";\nexport function defineInterfaceLinkConstraint({\n from,\n to\n}) {\n !(from.one == null && from.many || from.one && from.many == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"from should have either one or many, not both\") : invariant(false) : void 0;\n !(to.one == null && to.many || to.one && to.many == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"to should have either one or many, not both\") : invariant(false) : void 0;\n !!(from.many && to.many) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"many to many is not supported\") : invariant(false) : void 0;\n const fromLinkMeta = getLinkMeta(from.one ?? from.many);\n const toLinkMeta = getLinkMeta(to.one ?? to.many);\n !(from.type.links.find(a => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${from.type.apiName}`) : invariant(false) : void 0;\n !(to.type.links.find(a => a.metadata.apiName === toLinkMeta.apiName) == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toLinkMeta.apiName} already exists on ${to.type.apiName}`) : invariant(false) : void 0;\n from.type.links.push({\n cardinality: from.many ? \"MANY\" : \"SINGLE\",\n linkedEntityTypeId: getLinkedType(to.type),\n metadata: fromLinkMeta,\n required: true // TODO: expose this?\n });\n to.type.links.push({\n cardinality: to.one ? \"SINGLE\" : \"MANY\",\n linkedEntityTypeId: getLinkedType(from.type),\n metadata: toLinkMeta,\n required: true // TODO: expose this?\n });\n}\nfunction getLinkedType(t) {\n return {\n type: \"interfaceType\",\n interfaceType: t.apiName\n };\n}\nfunction getLinkMeta(meta) {\n return typeof meta === \"string\" ? withDefaults({\n apiName: meta\n }) : withDefaults(meta);\n}\nfunction withDefaults({\n apiName,\n description,\n displayName\n}) {\n return {\n apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName\n };\n}"]}
1
+ {"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineLink.ts","../../src/api/defineObject.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";AAgBA,SAAS,eAAe;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACJxB,OAAOA,gBAAe;;;ACCf,IAAI;AAGJ,IAAI;AACX,eAAsB,eAAe,IAAI,MAAM;AAC7C,cAAY;AACZ,uBAAqB;AAAA,IACnB,aAAa,CAAC;AAAA,IACd,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,qBAAqB,CAAC;AAAA,EACxB;AACA,MAAI;AACF,UAAM,KAAK;AAAA,EACb,SAAS,GAAG;AAEV,YAAQ,MAAM,8DAA8D,CAAC;AAC7E,UAAM;AAAA,EACR;AACA,SAAO,sBAAsB,kBAAkB;AACjD;AACA,SAAS,sBAAsB,UAAU;AACvC,SAAO;AAAA,IACL,qBAAqB,OAAO,YAAY,OAAO,QAAQ,SAAS,mBAAmB,EAAE,IAAI,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;AAAA,MACrH,oBAAoB,WAAW,GAAG;AAAA,IACpC,CAAC,CAAC,CAAC;AAAA,IACH,gBAAgB,OAAO,YAAY,OAAO,QAAQ,SAAS,cAAc,EAAE,IAAI,CAAC,CAAC,SAAS,aAAa,MAAM;AAC3G,aAAO,CAAC,SAAS;AAAA,QACf,eAAe,iBAAiB,aAAa;AAAA,MAC/C,CAAC;AAAA,IACH,CAAC,CAAC;AAAA,IACF,4BAA4B;AAAA,MAC1B,aAAa,CAAC;AAAA,MACd,WAAW,CAAC;AAAA,MACZ,aAAa,CAAC;AAAA,IAChB;AAAA,EACF;AACF;AACA,SAAS,iBAAiB,eAAe;AACvC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY,OAAO,OAAO,cAAc,UAAU,EAAE,IAAI,SAAO,WAAW,GAAG,CAAC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gB,KAAK;AACzD,UAAQ,KAAK,sBAAsB,gBAAgB,MAAM,EAAE;AAC3D,QAAS,aAAU,gBAAgB,QAAQ,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAC9E;AAkCA,eAAe,aAAa,OAAO;AAQjC,QAAM,IAAI,MAAM,eAAe,IAAI,YAAY,MAAM,OAAO,MAAM;AAClE,SAAO;AACT;;;AMlFA,OAAOA,gBAAe;AACf,SAAS,8BAA8B,SAAS;AACrD,QAAM,eAAe,YAAY,OAAO;AACxC,IAAE,QAAQ,KAAK,MAAM,KAAK,OAAK,EAAE,SAAS,YAAY,aAAa,OAAO,KAAK,QAAQ,QAAQ,IAAI,aAAa,eAAeA,WAAU,OAAO,qBAAqB,aAAa,OAAO,sBAAsB,QAAQ,OAAO,EAAE,IAAIA,WAAU,KAAK,IAAI;AACvP,UAAQ,KAAK,MAAM,KAAK;AAAA,IACtB,aAAa,QAAQ,SAAS,SAAS;AAAA,IACvC,oBAAoB,cAAc,QAAQ,UAAU,QAAQ,KAAK;AAAA,IACjE,UAAU;AAAA,IACV,UAAU;AAAA;AAAA,EACZ,CAAC;AACH;AACA,SAAS,cAAc,GAAG;AACxB,SAAO;AAAA,IACL,MAAM;AAAA,IACN,eAAe,OAAO,MAAM,WAAW,IAAI,EAAE;AAAA,EAC/C;AACF;AACA,SAAS,YAAY,MAAM;AACzB,SAAO,OAAO,SAAS,WAAW,aAAa;AAAA,IAC7C,SAAS;AAAA,EACX,CAAC,IAAI,aAAa,IAAI;AACxB;AACA,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACF,GAAG;AACD,SAAO;AAAA,IACL;AAAA,IACA,aAAa,eAAe;AAAA,IAC5B,aAAa,eAAe,eAAe;AAAA,EAC7C;AACF","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 { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { defineInterface } from \"../api/defineInterface.js\";\nimport { defineLink } from \"../api/defineLink.js\";\nimport { defineObject } from \"../api/defineObject.js\";\nimport { defineOntology } from \"../api/defineOntology.js\";\nimport { defineSharedPropertyType } from \"../api/defineSpt.js\";\nexport default async function main(args = process.argv) {\n const commandLineOpts = await yargs(hideBin(args)).version(process.env.PACKAGE_VERSION ?? \"\").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({\n input: {\n alias: \"i\",\n describe: \"Input file\",\n type: \"string\",\n default: \".ontology/ontology.ts\",\n coerce: path.resolve\n },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\",\n coerce: path.resolve\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve\n }\n }).parseAsync();\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n const ontology = await loadOntology(commandLineOpts.input);\n consola.info(`Saving ontology to ${commandLineOpts.output}`);\n await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));\n}\nasync function loadOntologyViaJiti(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const jiti_ = await import(\"jiti\");\n const jiti = jiti_.default(process.cwd(), {\n debug: true\n });\n return defineOntology(\"\", async () => await jiti(input));\n}\nasync function loadOntologyViaTsNode(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const tsNode = await import(\"ts-node\");\n const tsNodeService = tsNode.register({\n transpileOnly: true,\n compilerOptions: {\n module: \"commonjs\",\n target: \"esnext\"\n },\n esm: true\n });\n tsNodeService.enabled(true);\n const q = await import(input);\n return q;\n}\nasync function loadOntology(input) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(\"\", async () => await import(input));\n return q;\n}","/*\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 { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n !isSimpleType(type) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false\n });\n return [apiName, spt];\n } else {\n !(apiName === type.apiName) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({\n key: apiName,\n apiName: type.apiName\n })}`) : invariant(false) : void 0;\n return [apiName, type];\n }\n }));\n const a = {\n apiName,\n displayMetadata: {\n displayName: opts.displayName ?? apiName,\n description: opts.description ?? opts.displayName ?? apiName,\n icon: undefined\n },\n extendsInterfaces: [],\n links: [],\n properties,\n status: {\n type: \"active\",\n active: {}\n }\n };\n return ontologyDefinition.interfaceTypes[apiName] = a;\n}\nfunction isSimpleType(v) {\n 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\";\n}","/*\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/** @internal */\nexport let ontologyDefinition;\n\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n objectTypes: {},\n queryTypes: {},\n interfaceTypes: {},\n sharedPropertyTypes: {}\n };\n try {\n await body();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertToWireOntology(ontology) {\n return {\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {\n sharedPropertyType: convertSpt(spt)\n }])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {\n return [apiName, {\n interfaceType: convertInterface(interfaceType)\n }];\n })),\n blockPermissionInformation: {\n actionTypes: {},\n linkTypes: {},\n objectTypes: {}\n }\n };\n}\nfunction convertInterface(interfaceType) {\n return {\n ...interfaceType,\n properties: Object.values(interfaceType.properties).map(spt => convertSpt(spt)),\n // these are omitted from our internal types but we need to re-add them for the final json\n allExtendsInterfaces: [],\n allLinks: [],\n allProperties: []\n };\n}\nexport function dumpOntologyFullMetadata() {\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertSpt({\n type,\n array,\n description,\n apiName,\n displayName\n}) {\n return {\n apiName,\n displayMetadata: {\n displayName: displayName ?? apiName,\n visibility: \"NORMAL\",\n description\n },\n type: array ? {\n type: \"array\",\n array: {\n subtype: convertType(type)\n }\n } : convertType(type),\n aliases: [],\n baseFormatter: undefined,\n dataConstraints: undefined,\n gothamMapping: undefined,\n indexedForSearch: true,\n provenance: undefined,\n typeClasses: [],\n valueType: undefined\n };\n}\nfunction convertType(type) {\n switch (type) {\n case \"marking\":\n return {\n type,\n [type]: {\n markingType: \"MANDATORY\"\n }\n };\n case \"geopoint\":\n return {\n type: \"geohash\",\n geohash: {}\n };\n case \"decimal\":\n return {\n type,\n [type]: {\n precision: undefined,\n scale: undefined\n }\n };\n case \"string\":\n return {\n type,\n [type]: {\n analyzerOverride: undefined,\n enableAsciiFolding: undefined,\n isLongText: false,\n supportsExactMatching: true\n }\n };\n default:\n // use helper function to distribute `type` properly\n return distributeTypeHelper(type);\n }\n}\n\n/**\n * Helper function to avoid duplication. Makes the types match properly with the correct\n * behavior without needing to switch on type.\n * @param type\n * @returns\n */\nfunction distributeTypeHelper(type) {\n return {\n type,\n [type]: {}\n }; // any cast to match conditional return type\n}","/*\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\";\nexport function defineSharedPropertyType(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n ...opts\n };\n}","/*\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\";\nexport function defineLink(from, opts) {\n const apiName = opts.one ?? opts.many;\n const toApiName = opts.reverse.one ?? opts.reverse.many;\n const to = opts.to;\n !(from.linkTypes[apiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${apiName} already exists on ${from.data.objectType.apiName}`) : invariant(false) : void 0;\n !(from.linkTypes[toApiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toApiName} already exists on ${to.data.objectType.apiName}`) : invariant(false) : void 0;\n from.linkTypes[apiName] = {\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: to.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n to.linkTypes[toApiName] = {\n apiName: toApiName,\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: from.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n}","/*\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\";\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 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\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({\n ...t,\n multiplicity: false\n })\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 !false ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n}","/*\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\";\nexport function defineInterfaceLinkConstraint(linkDef) {\n const fromLinkMeta = getLinkMeta(linkDef);\n !(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;\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\" ? withDefaults({\n apiName: meta\n }) : withDefaults(meta);\n}\nfunction withDefaults({\n apiName,\n description,\n displayName\n}) {\n return {\n apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName\n };\n}"]}
@@ -7,7 +7,7 @@ var fs = require('fs/promises');
7
7
  var path = require('path');
8
8
  var yargs = require('yargs');
9
9
  var helpers = require('yargs/helpers');
10
- var invariant5 = require('tiny-invariant');
10
+ var invariant2 = require('tiny-invariant');
11
11
 
12
12
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
13
 
@@ -32,7 +32,7 @@ function _interopNamespace(e) {
32
32
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
33
33
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
34
34
  var yargs__default = /*#__PURE__*/_interopDefault(yargs);
35
- var invariant5__default = /*#__PURE__*/_interopDefault(invariant5);
35
+ var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
36
36
 
37
37
  // src/cli/main.ts
38
38
 
@@ -157,7 +157,7 @@ function defineSharedPropertyType(opts) {
157
157
  const {
158
158
  apiName
159
159
  } = opts;
160
- !(ontologyDefinition.sharedPropertyTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, `Shared property type ${apiName} already exists`) : invariant5__default.default(false) : void 0;
160
+ !(ontologyDefinition.sharedPropertyTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Shared property type ${apiName} already exists`) : invariant2__default.default(false) : void 0;
161
161
  return ontologyDefinition.sharedPropertyTypes[apiName] = {
162
162
  ...opts
163
163
  };
@@ -168,10 +168,10 @@ function defineInterface(opts) {
168
168
  const {
169
169
  apiName
170
170
  } = opts;
171
- !(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, `Interface ${apiName} already exists`) : invariant5__default.default(false) : void 0;
171
+ !(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Interface ${apiName} already exists`) : invariant2__default.default(false) : void 0;
172
172
  const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
173
173
  if (typeof type === "string") {
174
- !isSimpleType(type) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, `Invalid data type ${type} for property ${apiName2} on InterfaceType ${apiName2}`) : invariant5__default.default(false) : void 0;
174
+ !isSimpleType(type) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Invalid data type ${type} for property ${apiName2} on InterfaceType ${apiName2}`) : invariant2__default.default(false) : void 0;
175
175
  const spt = defineSharedPropertyType({
176
176
  apiName: apiName2,
177
177
  displayName: apiName2,
@@ -180,10 +180,10 @@ function defineInterface(opts) {
180
180
  });
181
181
  return [apiName2, spt];
182
182
  } else {
183
- !(apiName2 === type.apiName) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, `property key and it's apiName must be identical. ${JSON.stringify({
183
+ !(apiName2 === type.apiName) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `property key and it's apiName must be identical. ${JSON.stringify({
184
184
  key: apiName2,
185
185
  apiName: type.apiName
186
- })}`) : invariant5__default.default(false) : void 0;
186
+ })}`) : invariant2__default.default(false) : void 0;
187
187
  return [apiName2, type];
188
188
  }
189
189
  }));
@@ -210,7 +210,7 @@ function isSimpleType(v) {
210
210
 
211
211
  // src/cli/main.ts
212
212
  async function main(args = process.argv) {
213
- const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.7.0-beta.0").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
213
+ const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.7.0-beta.2").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
214
214
  input: {
215
215
  alias: "i",
216
216
  describe: "Input file",
@@ -242,36 +242,21 @@ async function loadOntology(input) {
242
242
  const q = await defineOntology("", async () => await import(input));
243
243
  return q;
244
244
  }
245
- function defineInterfaceLinkConstraint({
246
- from,
247
- to
248
- }) {
249
- !(from.one == null && from.many || from.one && from.many == null) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, "from should have either one or many, not both") : invariant5__default.default(false) : void 0;
250
- !(to.one == null && to.many || to.one && to.many == null) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, "to should have either one or many, not both") : invariant5__default.default(false) : void 0;
251
- !!(from.many && to.many) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, "many to many is not supported") : invariant5__default.default(false) : void 0;
252
- const fromLinkMeta = getLinkMeta(from.one ?? from.many);
253
- const toLinkMeta = getLinkMeta(to.one ?? to.many);
254
- !(from.type.links.find((a) => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${from.type.apiName}`) : invariant5__default.default(false) : void 0;
255
- !(to.type.links.find((a) => a.metadata.apiName === toLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant5__default.default(false, `Link with apiName ${toLinkMeta.apiName} already exists on ${to.type.apiName}`) : invariant5__default.default(false) : void 0;
256
- from.type.links.push({
257
- cardinality: from.many ? "MANY" : "SINGLE",
258
- linkedEntityTypeId: getLinkedType(to.type),
245
+ function defineInterfaceLinkConstraint(linkDef) {
246
+ const fromLinkMeta = getLinkMeta(linkDef);
247
+ !(linkDef.from.links.find((a) => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`) : invariant2__default.default(false) : void 0;
248
+ linkDef.from.links.push({
249
+ cardinality: linkDef.toMany ? "MANY" : "SINGLE",
250
+ linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),
259
251
  metadata: fromLinkMeta,
260
252
  required: true
261
253
  // TODO: expose this?
262
254
  });
263
- to.type.links.push({
264
- cardinality: to.one ? "SINGLE" : "MANY",
265
- linkedEntityTypeId: getLinkedType(from.type),
266
- metadata: toLinkMeta,
267
- required: true
268
- // TODO: expose this?
269
- });
270
255
  }
271
256
  function getLinkedType(t) {
272
257
  return {
273
258
  type: "interfaceType",
274
- interfaceType: t.apiName
259
+ interfaceType: typeof t === "string" ? t : t.apiName
275
260
  };
276
261
  }
277
262
  function getLinkMeta(meta) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineLink.ts","../../src/api/defineObject.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";AAgBA,SAAS,eAAe;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACJxB,OAAOA,gBAAe;;;ACCf,IAAI;AAGJ,IAAI;AACX,eAAsB,eAAe,IAAI,MAAM;AAC7C,cAAY;AACZ,uBAAqB;AAAA,IACnB,aAAa,CAAC;AAAA,IACd,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACj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,EAAE;AAAA,EACnB;AACF;AACA,SAAS,YAAY,MAAM;AACzB,SAAO,OAAO,SAAS,WAAW,aAAa;AAAA,IAC7C,SAAS;AAAA,EACX,CAAC,IAAI,aAAa,IAAI;AACxB;AACA,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACF,GAAG;AACD,SAAO;AAAA,IACL;AAAA,IACA,aAAa,eAAe;AAAA,IAC5B,aAAa,eAAe,eAAe;AAAA,EAC7C;AACF","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 { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { defineInterface } from \"../api/defineInterface.js\";\nimport { defineLink } from \"../api/defineLink.js\";\nimport { defineObject } from \"../api/defineObject.js\";\nimport { defineOntology } from \"../api/defineOntology.js\";\nimport { defineSharedPropertyType } from \"../api/defineSpt.js\";\nexport default async function main(args = process.argv) {\n const commandLineOpts = await yargs(hideBin(args)).version(process.env.PACKAGE_VERSION ?? \"\").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({\n input: {\n alias: \"i\",\n describe: \"Input file\",\n type: \"string\",\n default: \".ontology/ontology.ts\",\n coerce: path.resolve\n },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\",\n coerce: path.resolve\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve\n }\n }).parseAsync();\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n const ontology = await loadOntology(commandLineOpts.input);\n consola.info(`Saving ontology to ${commandLineOpts.output}`);\n await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));\n}\nasync function loadOntologyViaJiti(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const jiti_ = await import(\"jiti\");\n const jiti = jiti_.default(process.cwd(), {\n debug: true\n });\n return defineOntology(\"\", async () => await jiti(input));\n}\nasync function loadOntologyViaTsNode(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const tsNode = await import(\"ts-node\");\n const tsNodeService = tsNode.register({\n transpileOnly: true,\n compilerOptions: {\n module: \"commonjs\",\n target: \"esnext\"\n },\n esm: true\n });\n tsNodeService.enabled(true);\n const q = await import(input);\n return q;\n}\nasync function loadOntology(input) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(\"\", async () => await import(input));\n return q;\n}","/*\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 { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n !isSimpleType(type) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false\n });\n return [apiName, spt];\n } else {\n !(apiName === type.apiName) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({\n key: apiName,\n apiName: type.apiName\n })}`) : invariant(false) : void 0;\n return [apiName, type];\n }\n }));\n const a = {\n apiName,\n displayMetadata: {\n displayName: opts.displayName ?? apiName,\n description: opts.description ?? opts.displayName ?? apiName,\n icon: undefined\n },\n extendsInterfaces: [],\n links: [],\n properties,\n status: {\n type: \"active\",\n active: {}\n }\n };\n return ontologyDefinition.interfaceTypes[apiName] = a;\n}\nfunction isSimpleType(v) {\n 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\";\n}","/*\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/** @internal */\nexport let ontologyDefinition;\n\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n objectTypes: {},\n queryTypes: {},\n interfaceTypes: {},\n sharedPropertyTypes: {}\n };\n try {\n await body();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertToWireOntology(ontology) {\n return {\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {\n sharedPropertyType: convertSpt(spt)\n }])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {\n return [apiName, {\n interfaceType: convertInterface(interfaceType)\n }];\n })),\n blockPermissionInformation: {\n actionTypes: {},\n linkTypes: {},\n objectTypes: {}\n }\n };\n}\nfunction convertInterface(interfaceType) {\n return {\n ...interfaceType,\n properties: Object.values(interfaceType.properties).map(spt => convertSpt(spt)),\n // these are omitted from our internal types but we need to re-add them for the final json\n allExtendsInterfaces: [],\n allLinks: [],\n allProperties: []\n };\n}\nexport function dumpOntologyFullMetadata() {\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertSpt({\n type,\n array,\n description,\n apiName,\n displayName\n}) {\n return {\n apiName,\n displayMetadata: {\n displayName: displayName ?? apiName,\n visibility: \"NORMAL\",\n description\n },\n type: array ? {\n type: \"array\",\n array: {\n subtype: convertType(type)\n }\n } : convertType(type),\n aliases: [],\n baseFormatter: undefined,\n dataConstraints: undefined,\n gothamMapping: undefined,\n indexedForSearch: true,\n provenance: undefined,\n typeClasses: [],\n valueType: undefined\n };\n}\nfunction convertType(type) {\n switch (type) {\n case \"marking\":\n return {\n type,\n [type]: {\n markingType: \"MANDATORY\"\n }\n };\n case \"geopoint\":\n return {\n type: \"geohash\",\n geohash: {}\n };\n case \"decimal\":\n return {\n type,\n [type]: {\n precision: undefined,\n scale: undefined\n }\n };\n case \"string\":\n return {\n type,\n [type]: {\n analyzerOverride: undefined,\n enableAsciiFolding: undefined,\n isLongText: false,\n supportsExactMatching: true\n }\n };\n default:\n // use helper function to distribute `type` properly\n return distributeTypeHelper(type);\n }\n}\n\n/**\n * Helper function to avoid duplication. Makes the types match properly with the correct\n * behavior without needing to switch on type.\n * @param type\n * @returns\n */\nfunction distributeTypeHelper(type) {\n return {\n type,\n [type]: {}\n }; // any cast to match conditional return type\n}","/*\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\";\nexport function defineSharedPropertyType(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n ...opts\n };\n}","/*\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\";\nexport function defineLink(from, opts) {\n const apiName = opts.one ?? opts.many;\n const toApiName = opts.reverse.one ?? opts.reverse.many;\n const to = opts.to;\n !(from.linkTypes[apiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${apiName} already exists on ${from.data.objectType.apiName}`) : invariant(false) : void 0;\n !(from.linkTypes[toApiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toApiName} already exists on ${to.data.objectType.apiName}`) : invariant(false) : void 0;\n from.linkTypes[apiName] = {\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: to.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n to.linkTypes[toApiName] = {\n apiName: toApiName,\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: from.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n}","/*\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\";\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 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\n // FIXME: dont 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({\n ...t,\n multiplicity: false\n })\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 !false ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n}","/*\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\";\nexport function defineInterfaceLinkConstraint({\n from,\n to\n}) {\n !(from.one == null && from.many || from.one && from.many == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"from should have either one or many, not both\") : invariant(false) : void 0;\n !(to.one == null && to.many || to.one && to.many == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"to should have either one or many, not both\") : invariant(false) : void 0;\n !!(from.many && to.many) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"many to many is not supported\") : invariant(false) : void 0;\n const fromLinkMeta = getLinkMeta(from.one ?? from.many);\n const toLinkMeta = getLinkMeta(to.one ?? to.many);\n !(from.type.links.find(a => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${from.type.apiName}`) : invariant(false) : void 0;\n !(to.type.links.find(a => a.metadata.apiName === toLinkMeta.apiName) == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toLinkMeta.apiName} already exists on ${to.type.apiName}`) : invariant(false) : void 0;\n from.type.links.push({\n cardinality: from.many ? \"MANY\" : \"SINGLE\",\n linkedEntityTypeId: getLinkedType(to.type),\n metadata: fromLinkMeta,\n required: true // TODO: expose this?\n });\n to.type.links.push({\n cardinality: to.one ? \"SINGLE\" : \"MANY\",\n linkedEntityTypeId: getLinkedType(from.type),\n metadata: toLinkMeta,\n required: true // TODO: expose this?\n });\n}\nfunction getLinkedType(t) {\n return {\n type: \"interfaceType\",\n interfaceType: t.apiName\n };\n}\nfunction getLinkMeta(meta) {\n return typeof meta === \"string\" ? withDefaults({\n apiName: meta\n }) : withDefaults(meta);\n}\nfunction withDefaults({\n apiName,\n description,\n displayName\n}) {\n return {\n apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName\n };\n}"]}
1
+ {"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineLink.ts","../../src/api/defineObject.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";AAgBA,SAAS,eAAe;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACJxB,OAAOA,gBAAe;;;ACCf,IAAI;AAGJ,IAAI;AACX,eAAsB,eAAe,IAAI,MAAM;AAC7C,cAAY;AACZ,uBAAqB;AAAA,IACnB,aAAa,CAAC;AAAA,IACd,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,qBAAqB,CAAC;AAAA,EACxB;AACA,MAAI;AACF,UAAM,KAAK;AAAA,EACb,SAAS,GAAG;AAEV,YAAQ,MAAM,8DAA8D,CAAC;AAC7E,UAAM;AAAA,EACR;AACA,SAAO,sBAAsB,kBAAkB;AACjD;AACA,SAAS,sBAAsB,UAAU;AACvC,SAAO;AAAA,IACL,qBAAqB,OAAO,YAAY,OAAO,QAAQ,SAAS,mBAAmB,EAAE,IAAI,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;AAAA,MACrH,oBAAoB,WAAW,GAAG;AAAA,IACpC,CAAC,CAAC,CAAC;AAA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IAAI,EAAE;AAAA,EAC/C;AACF;AACA,SAAS,YAAY,MAAM;AACzB,SAAO,OAAO,SAAS,WAAW,aAAa;AAAA,IAC7C,SAAS;AAAA,EACX,CAAC,IAAI,aAAa,IAAI;AACxB;AACA,SAAS,aAAa;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACF,GAAG;AACD,SAAO;AAAA,IACL;AAAA,IACA,aAAa,eAAe;AAAA,IAC5B,aAAa,eAAe,eAAe;AAAA,EAC7C;AACF","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 { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { defineInterface } from \"../api/defineInterface.js\";\nimport { defineLink } from \"../api/defineLink.js\";\nimport { defineObject } from \"../api/defineObject.js\";\nimport { defineOntology } from \"../api/defineOntology.js\";\nimport { defineSharedPropertyType } from \"../api/defineSpt.js\";\nexport default async function main(args = process.argv) {\n const commandLineOpts = await yargs(hideBin(args)).version(process.env.PACKAGE_VERSION ?? \"\").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({\n input: {\n alias: \"i\",\n describe: \"Input file\",\n type: \"string\",\n default: \".ontology/ontology.ts\",\n coerce: path.resolve\n },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\",\n coerce: path.resolve\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve\n }\n }).parseAsync();\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n const ontology = await loadOntology(commandLineOpts.input);\n consola.info(`Saving ontology to ${commandLineOpts.output}`);\n await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));\n}\nasync function loadOntologyViaJiti(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const jiti_ = await import(\"jiti\");\n const jiti = jiti_.default(process.cwd(), {\n debug: true\n });\n return defineOntology(\"\", async () => await jiti(input));\n}\nasync function loadOntologyViaTsNode(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const tsNode = await import(\"ts-node\");\n const tsNodeService = tsNode.register({\n transpileOnly: true,\n compilerOptions: {\n module: \"commonjs\",\n target: \"esnext\"\n },\n esm: true\n });\n tsNodeService.enabled(true);\n const q = await import(input);\n return q;\n}\nasync function loadOntology(input) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(\"\", async () => await import(input));\n return q;\n}","/*\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 { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n !isSimpleType(type) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false\n });\n return [apiName, spt];\n } else {\n !(apiName === type.apiName) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({\n key: apiName,\n apiName: type.apiName\n })}`) : invariant(false) : void 0;\n return [apiName, type];\n }\n }));\n const a = {\n apiName,\n displayMetadata: {\n displayName: opts.displayName ?? apiName,\n description: opts.description ?? opts.displayName ?? apiName,\n icon: undefined\n },\n extendsInterfaces: [],\n links: [],\n properties,\n status: {\n type: \"active\",\n active: {}\n }\n };\n return ontologyDefinition.interfaceTypes[apiName] = a;\n}\nfunction isSimpleType(v) {\n 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\";\n}","/*\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/** @internal */\nexport let ontologyDefinition;\n\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n objectTypes: {},\n queryTypes: {},\n interfaceTypes: {},\n sharedPropertyTypes: {}\n };\n try {\n await body();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertToWireOntology(ontology) {\n return {\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {\n sharedPropertyType: convertSpt(spt)\n }])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {\n return [apiName, {\n interfaceType: convertInterface(interfaceType)\n }];\n })),\n blockPermissionInformation: {\n actionTypes: {},\n linkTypes: {},\n objectTypes: {}\n }\n };\n}\nfunction convertInterface(interfaceType) {\n return {\n ...interfaceType,\n properties: Object.values(interfaceType.properties).map(spt => convertSpt(spt)),\n // these are omitted from our internal types but we need to re-add them for the final json\n allExtendsInterfaces: [],\n allLinks: [],\n allProperties: []\n };\n}\nexport function dumpOntologyFullMetadata() {\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertSpt({\n type,\n array,\n description,\n apiName,\n displayName\n}) {\n return {\n apiName,\n displayMetadata: {\n displayName: displayName ?? apiName,\n visibility: \"NORMAL\",\n description\n },\n type: array ? {\n type: \"array\",\n array: {\n subtype: convertType(type)\n }\n } : convertType(type),\n aliases: [],\n baseFormatter: undefined,\n dataConstraints: undefined,\n gothamMapping: undefined,\n indexedForSearch: true,\n provenance: undefined,\n typeClasses: [],\n valueType: undefined\n };\n}\nfunction convertType(type) {\n switch (type) {\n case \"marking\":\n return {\n type,\n [type]: {\n markingType: \"MANDATORY\"\n }\n };\n case \"geopoint\":\n return {\n type: \"geohash\",\n geohash: {}\n };\n case \"decimal\":\n return {\n type,\n [type]: {\n precision: undefined,\n scale: undefined\n }\n };\n case \"string\":\n return {\n type,\n [type]: {\n analyzerOverride: undefined,\n enableAsciiFolding: undefined,\n isLongText: false,\n supportsExactMatching: true\n }\n };\n default:\n // use helper function to distribute `type` properly\n return distributeTypeHelper(type);\n }\n}\n\n/**\n * Helper function to avoid duplication. Makes the types match properly with the correct\n * behavior without needing to switch on type.\n * @param type\n * @returns\n */\nfunction distributeTypeHelper(type) {\n return {\n type,\n [type]: {}\n }; // any cast to match conditional return type\n}","/*\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\";\nexport function defineSharedPropertyType(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n ...opts\n };\n}","/*\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\";\nexport function defineLink(from, opts) {\n const apiName = opts.one ?? opts.many;\n const toApiName = opts.reverse.one ?? opts.reverse.many;\n const to = opts.to;\n !(from.linkTypes[apiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${apiName} already exists on ${from.data.objectType.apiName}`) : invariant(false) : void 0;\n !(from.linkTypes[toApiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toApiName} already exists on ${to.data.objectType.apiName}`) : invariant(false) : void 0;\n from.linkTypes[apiName] = {\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: to.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n to.linkTypes[toApiName] = {\n apiName: toApiName,\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: from.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n}","/*\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\";\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 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\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({\n ...t,\n multiplicity: false\n })\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 !false ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n}","/*\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\";\nexport function defineInterfaceLinkConstraint(linkDef) {\n const fromLinkMeta = getLinkMeta(linkDef);\n !(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;\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\" ? withDefaults({\n apiName: meta\n }) : withDefaults(meta);\n}\nfunction withDefaults({\n apiName,\n description,\n displayName\n}) {\n return {\n apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName\n };\n}"]}
@@ -1,26 +1,21 @@
1
1
  import type { InterfaceType } from "./types.js";
2
- type Meta = {
2
+ type ApiNameOrInterfaceType = string | InterfaceType;
3
+ type Many = {
3
4
  apiName: string;
5
+ from: InterfaceType;
6
+ toMany: ApiNameOrInterfaceType;
7
+ toOne?: never;
4
8
  displayName?: string;
5
9
  description?: string;
6
10
  };
7
- type ApiNameOrMeta = string | Meta;
8
- type Many = {
9
- type: InterfaceType;
10
- many: ApiNameOrMeta;
11
- one?: never;
12
- };
13
11
  type One = {
14
- type: InterfaceType;
15
- one: ApiNameOrMeta;
16
- many?: never;
12
+ apiName: string;
13
+ from: InterfaceType;
14
+ toOne: ApiNameOrInterfaceType;
15
+ toMany?: never;
16
+ displayName?: string;
17
+ description?: string;
17
18
  };
18
- export declare function defineInterfaceLinkConstraint({ from, to }: {
19
- from: Many;
20
- to: One;
21
- } | {
22
- from: One;
23
- to: One | Many;
24
- }): void;
19
+ export declare function defineInterfaceLinkConstraint(linkDef: One | Many): void;
25
20
  export {};
26
21
  //# sourceMappingURL=defineInterfaceLinkConstraint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defineInterfaceLinkConstraint.d.ts","sourceRoot":"","sources":["../../../src/api/defineInterfaceLinkConstraint.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,KAAK,IAAI,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAC5E,KAAK,aAAa,GAAG,MAAM,GAAG,IAAI,CAAC;AAEnC,KAAK,IAAI,GAAG;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,aAAa,CAAC;IAAC,GAAG,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AACtE,KAAK,GAAG,GAAG;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,GAAG,EAAE,aAAa,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAErE,wBAAgB,6BAA6B,CAC3C,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE;IACZ,IAAI,EAAE,IAAI,CAAC;IACX,EAAE,EAAE,GAAG,CAAC;CACT,GAAG;IACF,IAAI,EAAE,GAAG,CAAC;IACV,EAAE,EAAE,GAAG,GAAG,IAAI,CAAC;CAChB,QAwCF"}
1
+ {"version":3,"file":"defineInterfaceLinkConstraint.d.ts","sourceRoot":"","sources":["../../../src/api/defineInterfaceLinkConstraint.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGhD,KAAK,sBAAsB,GAAG,MAAM,GAAG,aAAa,CAAC;AAErD,KAAK,IAAI,GAAG;IACV,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,sBAAsB,CAAC;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AACF,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,sBAAsB,CAAC;IAC9B,MAAM,CAAC,EAAE,KAAK,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,GAAG,GAAG,IAAI,QAgBpB"}
@@ -3,7 +3,7 @@ import * as fs from 'fs/promises';
3
3
  import * as path from 'path';
4
4
  import yargs from 'yargs';
5
5
  import { hideBin } from 'yargs/helpers';
6
- import invariant5 from 'tiny-invariant';
6
+ import invariant2 from 'tiny-invariant';
7
7
 
8
8
  // src/cli/main.ts
9
9
 
@@ -128,7 +128,7 @@ function defineSharedPropertyType(opts) {
128
128
  const {
129
129
  apiName
130
130
  } = opts;
131
- !(ontologyDefinition.sharedPropertyTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Shared property type ${apiName} already exists`) : invariant5(false) : void 0;
131
+ !(ontologyDefinition.sharedPropertyTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Shared property type ${apiName} already exists`) : invariant2(false) : void 0;
132
132
  return ontologyDefinition.sharedPropertyTypes[apiName] = {
133
133
  ...opts
134
134
  };
@@ -139,10 +139,10 @@ function defineInterface(opts) {
139
139
  const {
140
140
  apiName
141
141
  } = opts;
142
- !(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Interface ${apiName} already exists`) : invariant5(false) : void 0;
142
+ !(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Interface ${apiName} already exists`) : invariant2(false) : void 0;
143
143
  const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
144
144
  if (typeof type === "string") {
145
- !isSimpleType(type) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Invalid data type ${type} for property ${apiName2} on InterfaceType ${apiName2}`) : invariant5(false) : void 0;
145
+ !isSimpleType(type) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Invalid data type ${type} for property ${apiName2} on InterfaceType ${apiName2}`) : invariant2(false) : void 0;
146
146
  const spt = defineSharedPropertyType({
147
147
  apiName: apiName2,
148
148
  displayName: apiName2,
@@ -151,10 +151,10 @@ function defineInterface(opts) {
151
151
  });
152
152
  return [apiName2, spt];
153
153
  } else {
154
- !(apiName2 === type.apiName) ? process.env.NODE_ENV !== "production" ? invariant5(false, `property key and it's apiName must be identical. ${JSON.stringify({
154
+ !(apiName2 === type.apiName) ? process.env.NODE_ENV !== "production" ? invariant2(false, `property key and it's apiName must be identical. ${JSON.stringify({
155
155
  key: apiName2,
156
156
  apiName: type.apiName
157
- })}`) : invariant5(false) : void 0;
157
+ })}`) : invariant2(false) : void 0;
158
158
  return [apiName2, type];
159
159
  }
160
160
  }));
@@ -181,7 +181,7 @@ function isSimpleType(v) {
181
181
 
182
182
  // src/cli/main.ts
183
183
  async function main(args = process.argv) {
184
- const commandLineOpts = await yargs(hideBin(args)).version("0.7.0-beta.0").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
184
+ const commandLineOpts = await yargs(hideBin(args)).version("0.7.0-beta.2").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
185
185
  input: {
186
186
  alias: "i",
187
187
  describe: "Input file",
@@ -213,36 +213,21 @@ async function loadOntology(input) {
213
213
  const q = await defineOntology("", async () => await import(input));
214
214
  return q;
215
215
  }
216
- function defineInterfaceLinkConstraint({
217
- from,
218
- to
219
- }) {
220
- !(from.one == null && from.many || from.one && from.many == null) ? process.env.NODE_ENV !== "production" ? invariant5(false, "from should have either one or many, not both") : invariant5(false) : void 0;
221
- !(to.one == null && to.many || to.one && to.many == null) ? process.env.NODE_ENV !== "production" ? invariant5(false, "to should have either one or many, not both") : invariant5(false) : void 0;
222
- !!(from.many && to.many) ? process.env.NODE_ENV !== "production" ? invariant5(false, "many to many is not supported") : invariant5(false) : void 0;
223
- const fromLinkMeta = getLinkMeta(from.one ?? from.many);
224
- const toLinkMeta = getLinkMeta(to.one ?? to.many);
225
- !(from.type.links.find((a) => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${from.type.apiName}`) : invariant5(false) : void 0;
226
- !(to.type.links.find((a) => a.metadata.apiName === toLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant5(false, `Link with apiName ${toLinkMeta.apiName} already exists on ${to.type.apiName}`) : invariant5(false) : void 0;
227
- from.type.links.push({
228
- cardinality: from.many ? "MANY" : "SINGLE",
229
- linkedEntityTypeId: getLinkedType(to.type),
216
+ function defineInterfaceLinkConstraint(linkDef) {
217
+ const fromLinkMeta = getLinkMeta(linkDef);
218
+ !(linkDef.from.links.find((a) => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${linkDef.apiName}`) : invariant2(false) : void 0;
219
+ linkDef.from.links.push({
220
+ cardinality: linkDef.toMany ? "MANY" : "SINGLE",
221
+ linkedEntityTypeId: getLinkedType(linkDef.toMany ?? linkDef.toOne),
230
222
  metadata: fromLinkMeta,
231
223
  required: true
232
224
  // TODO: expose this?
233
225
  });
234
- to.type.links.push({
235
- cardinality: to.one ? "SINGLE" : "MANY",
236
- linkedEntityTypeId: getLinkedType(from.type),
237
- metadata: toLinkMeta,
238
- required: true
239
- // TODO: expose this?
240
- });
241
226
  }
242
227
  function getLinkedType(t) {
243
228
  return {
244
229
  type: "interfaceType",
245
- interfaceType: t.apiName
230
+ interfaceType: typeof t === "string" ? t : t.apiName
246
231
  };
247
232
  }
248
233
  function getLinkMeta(meta) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineLink.ts","../../src/api/defineObject.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";AAgBA,SAAS,eAAe;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACJxB,OAAOA,gBAAe;;;ACCf,IAAI;AAGJ,IAAI;AACX,eAAsB,eAAe,IAAI,MAAM;AAC7C,cAAY;AACZ,uBAAqB;AAAA,IACnB,aAAa,CAAC;AAAA,IACd,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,qBAAqB,CAAC;AAAA,EACxB;AACA,MAAI;AACF,UAAM,KAAK;AAAA,EACb,SAAS,GAAG;AAEV,YAAQ,MAAM,8DAA8D,CAAC;AAC7E,UAAM;AAAA,EACR;AACA,SAAO,sBAAsB,kBAAkB;AACjD;AACA,SAAS,sBAAsB,UAAU;AACvC,SAAO;AA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AAO;AAAA,IACL;AAAA,IACA,aAAa,eAAe;AAAA,IAC5B,aAAa,eAAe,eAAe;AAAA,EAC7C;AACF","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 { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { defineInterface } from \"../api/defineInterface.js\";\nimport { defineLink } from \"../api/defineLink.js\";\nimport { defineObject } from \"../api/defineObject.js\";\nimport { defineOntology } from \"../api/defineOntology.js\";\nimport { defineSharedPropertyType } from \"../api/defineSpt.js\";\nexport default async function main(args = process.argv) {\n const commandLineOpts = await yargs(hideBin(args)).version(process.env.PACKAGE_VERSION ?? \"\").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({\n input: {\n alias: \"i\",\n describe: \"Input file\",\n type: \"string\",\n default: \".ontology/ontology.ts\",\n coerce: path.resolve\n },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\",\n coerce: path.resolve\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve\n }\n }).parseAsync();\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n const ontology = await loadOntology(commandLineOpts.input);\n consola.info(`Saving ontology to ${commandLineOpts.output}`);\n await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));\n}\nasync function loadOntologyViaJiti(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const jiti_ = await import(\"jiti\");\n const jiti = jiti_.default(process.cwd(), {\n debug: true\n });\n return defineOntology(\"\", async () => await jiti(input));\n}\nasync function loadOntologyViaTsNode(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const tsNode = await import(\"ts-node\");\n const tsNodeService = tsNode.register({\n transpileOnly: true,\n compilerOptions: {\n module: \"commonjs\",\n target: \"esnext\"\n },\n esm: true\n });\n tsNodeService.enabled(true);\n const q = await import(input);\n return q;\n}\nasync function loadOntology(input) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(\"\", async () => await import(input));\n return q;\n}","/*\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 { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n !isSimpleType(type) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false\n });\n return [apiName, spt];\n } else {\n !(apiName === type.apiName) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({\n key: apiName,\n apiName: type.apiName\n })}`) : invariant(false) : void 0;\n return [apiName, type];\n }\n }));\n const a = {\n apiName,\n displayMetadata: {\n displayName: opts.displayName ?? apiName,\n description: opts.description ?? opts.displayName ?? apiName,\n icon: undefined\n },\n extendsInterfaces: [],\n links: [],\n properties,\n status: {\n type: \"active\",\n active: {}\n }\n };\n return ontologyDefinition.interfaceTypes[apiName] = a;\n}\nfunction isSimpleType(v) {\n 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\";\n}","/*\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/** @internal */\nexport let ontologyDefinition;\n\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n objectTypes: {},\n queryTypes: {},\n interfaceTypes: {},\n sharedPropertyTypes: {}\n };\n try {\n await body();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertToWireOntology(ontology) {\n return {\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {\n sharedPropertyType: convertSpt(spt)\n }])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {\n return [apiName, {\n interfaceType: convertInterface(interfaceType)\n }];\n })),\n blockPermissionInformation: {\n actionTypes: {},\n linkTypes: {},\n objectTypes: {}\n }\n };\n}\nfunction convertInterface(interfaceType) {\n return {\n ...interfaceType,\n properties: Object.values(interfaceType.properties).map(spt => convertSpt(spt)),\n // these are omitted from our internal types but we need to re-add them for the final json\n allExtendsInterfaces: [],\n allLinks: [],\n allProperties: []\n };\n}\nexport function dumpOntologyFullMetadata() {\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertSpt({\n type,\n array,\n description,\n apiName,\n displayName\n}) {\n return {\n apiName,\n displayMetadata: {\n displayName: displayName ?? apiName,\n visibility: \"NORMAL\",\n description\n },\n type: array ? {\n type: \"array\",\n array: {\n subtype: convertType(type)\n }\n } : convertType(type),\n aliases: [],\n baseFormatter: undefined,\n dataConstraints: undefined,\n gothamMapping: undefined,\n indexedForSearch: true,\n provenance: undefined,\n typeClasses: [],\n valueType: undefined\n };\n}\nfunction convertType(type) {\n switch (type) {\n case \"marking\":\n return {\n type,\n [type]: {\n markingType: \"MANDATORY\"\n }\n };\n case \"geopoint\":\n return {\n type: \"geohash\",\n geohash: {}\n };\n case \"decimal\":\n return {\n type,\n [type]: {\n precision: undefined,\n scale: undefined\n }\n };\n case \"string\":\n return {\n type,\n [type]: {\n analyzerOverride: undefined,\n enableAsciiFolding: undefined,\n isLongText: false,\n supportsExactMatching: true\n }\n };\n default:\n // use helper function to distribute `type` properly\n return distributeTypeHelper(type);\n }\n}\n\n/**\n * Helper function to avoid duplication. Makes the types match properly with the correct\n * behavior without needing to switch on type.\n * @param type\n * @returns\n */\nfunction distributeTypeHelper(type) {\n return {\n type,\n [type]: {}\n }; // any cast to match conditional return type\n}","/*\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\";\nexport function defineSharedPropertyType(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n ...opts\n };\n}","/*\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\";\nexport function defineLink(from, opts) {\n const apiName = opts.one ?? opts.many;\n const toApiName = opts.reverse.one ?? opts.reverse.many;\n const to = opts.to;\n !(from.linkTypes[apiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${apiName} already exists on ${from.data.objectType.apiName}`) : invariant(false) : void 0;\n !(from.linkTypes[toApiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toApiName} already exists on ${to.data.objectType.apiName}`) : invariant(false) : void 0;\n from.linkTypes[apiName] = {\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: to.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n to.linkTypes[toApiName] = {\n apiName: toApiName,\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: from.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n}","/*\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\";\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 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\n // FIXME: dont 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({\n ...t,\n multiplicity: false\n })\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 !false ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n}","/*\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\";\nexport function defineInterfaceLinkConstraint({\n from,\n to\n}) {\n !(from.one == null && from.many || from.one && from.many == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"from should have either one or many, not both\") : invariant(false) : void 0;\n !(to.one == null && to.many || to.one && to.many == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"to should have either one or many, not both\") : invariant(false) : void 0;\n !!(from.many && to.many) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"many to many is not supported\") : invariant(false) : void 0;\n const fromLinkMeta = getLinkMeta(from.one ?? from.many);\n const toLinkMeta = getLinkMeta(to.one ?? to.many);\n !(from.type.links.find(a => a.metadata.apiName === fromLinkMeta.apiName) == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${fromLinkMeta.apiName} already exists on ${from.type.apiName}`) : invariant(false) : void 0;\n !(to.type.links.find(a => a.metadata.apiName === toLinkMeta.apiName) == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toLinkMeta.apiName} already exists on ${to.type.apiName}`) : invariant(false) : void 0;\n from.type.links.push({\n cardinality: from.many ? \"MANY\" : \"SINGLE\",\n linkedEntityTypeId: getLinkedType(to.type),\n metadata: fromLinkMeta,\n required: true // TODO: expose this?\n });\n to.type.links.push({\n cardinality: to.one ? \"SINGLE\" : \"MANY\",\n linkedEntityTypeId: getLinkedType(from.type),\n metadata: toLinkMeta,\n required: true // TODO: expose this?\n });\n}\nfunction getLinkedType(t) {\n return {\n type: \"interfaceType\",\n interfaceType: t.apiName\n };\n}\nfunction getLinkMeta(meta) {\n return typeof meta === \"string\" ? withDefaults({\n apiName: meta\n }) : withDefaults(meta);\n}\nfunction withDefaults({\n apiName,\n description,\n displayName\n}) {\n return {\n apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName\n };\n}"]}
1
+ {"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineLink.ts","../../src/api/defineObject.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";AAgBA,SAAS,eAAe;AACxB,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACJxB,OAAOA,gBAAe;;;ACCf,IAAI;AAGJ,IAAI;AACX,eAAsB,eAAe,IAAI,MAAM;AAC7C,cAAY;AACZ,uBAAqB;AAAA,IACnB,aAAa,CAAC;AAAA,IACd,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,gBAAgB,CAAC;AAAA,IACjB,qBAAqB,CAAC;AAAA,EACxB;AACA,MAAI;AACF,UAAM,KAAK;AAAA,EACb,SAAS,GAAG;AAEV,YAAQ,MAAM,8DAA8D,CAAC;AAC7E,UAAM;AAAA,EACR;AACA,SAAO,sBAAsB,kBAAkB;AACjD;AACA,SAAS,sBAAsB,UAAU;AACvC,SAAO;AAAA,IACL,qBAAqB,OAAO,YAAY,OAAO,QAAQ,SAAS,mBAAmB,EAAE,IAAI,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;AAAA,MACrH,oBAAoB,WAAW,GAAG;AAAA,IACpC,CAAC,CAAC,CAAC;AAAA,IACH,gBAAgB,OAAO,YAAY,OAAO,QAAQ,SAAS,cAAc,EAAE,IAAI,CAAC,CAAC,SAAS,aAAa,MAAM;AAC3G,aAAO,CAAC,SAAS;AAAA,QACf,eAAe,iBAAiB,aAAa;AAAA,MAC/C,CAAC;AAAA,IACH,CAAC,CAAC;AAAA,IACF,4BAA4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AACD,SAAO;AAAA,IACL;AAAA,IACA,aAAa,eAAe;AAAA,IAC5B,aAAa,eAAe,eAAe;AAAA,EAC7C;AACF","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 { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { defineInterface } from \"../api/defineInterface.js\";\nimport { defineLink } from \"../api/defineLink.js\";\nimport { defineObject } from \"../api/defineObject.js\";\nimport { defineOntology } from \"../api/defineOntology.js\";\nimport { defineSharedPropertyType } from \"../api/defineSpt.js\";\nexport default async function main(args = process.argv) {\n const commandLineOpts = await yargs(hideBin(args)).version(process.env.PACKAGE_VERSION ?? \"\").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({\n input: {\n alias: \"i\",\n describe: \"Input file\",\n type: \"string\",\n default: \".ontology/ontology.ts\",\n coerce: path.resolve\n },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\",\n coerce: path.resolve\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve\n }\n }).parseAsync();\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n const ontology = await loadOntology(commandLineOpts.input);\n consola.info(`Saving ontology to ${commandLineOpts.output}`);\n await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));\n}\nasync function loadOntologyViaJiti(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const jiti_ = await import(\"jiti\");\n const jiti = jiti_.default(process.cwd(), {\n debug: true\n });\n return defineOntology(\"\", async () => await jiti(input));\n}\nasync function loadOntologyViaTsNode(input) {\n Object.assign(globalThis, {\n defineInterface,\n defineLink,\n defineObject,\n defineSharedPropertyType\n });\n const tsNode = await import(\"ts-node\");\n const tsNodeService = tsNode.register({\n transpileOnly: true,\n compilerOptions: {\n module: \"commonjs\",\n target: \"esnext\"\n },\n esm: true\n });\n tsNodeService.enabled(true);\n const q = await import(input);\n return q;\n}\nasync function loadOntology(input) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(\"\", async () => await import(input));\n return q;\n}","/*\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 { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n !isSimpleType(type) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;\n const spt = defineSharedPropertyType({\n apiName,\n displayName: apiName,\n type,\n array: false\n });\n return [apiName, spt];\n } else {\n !(apiName === type.apiName) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({\n key: apiName,\n apiName: type.apiName\n })}`) : invariant(false) : void 0;\n return [apiName, type];\n }\n }));\n const a = {\n apiName,\n displayMetadata: {\n displayName: opts.displayName ?? apiName,\n description: opts.description ?? opts.displayName ?? apiName,\n icon: undefined\n },\n extendsInterfaces: [],\n links: [],\n properties,\n status: {\n type: \"active\",\n active: {}\n }\n };\n return ontologyDefinition.interfaceTypes[apiName] = a;\n}\nfunction isSimpleType(v) {\n 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\";\n}","/*\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/** @internal */\nexport let ontologyDefinition;\n\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n objectTypes: {},\n queryTypes: {},\n interfaceTypes: {},\n sharedPropertyTypes: {}\n };\n try {\n await body();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertToWireOntology(ontology) {\n return {\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {\n sharedPropertyType: convertSpt(spt)\n }])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {\n return [apiName, {\n interfaceType: convertInterface(interfaceType)\n }];\n })),\n blockPermissionInformation: {\n actionTypes: {},\n linkTypes: {},\n objectTypes: {}\n }\n };\n}\nfunction convertInterface(interfaceType) {\n return {\n ...interfaceType,\n properties: Object.values(interfaceType.properties).map(spt => convertSpt(spt)),\n // these are omitted from our internal types but we need to re-add them for the final json\n allExtendsInterfaces: [],\n allLinks: [],\n allProperties: []\n };\n}\nexport function dumpOntologyFullMetadata() {\n return convertToWireOntology(ontologyDefinition);\n}\nfunction convertSpt({\n type,\n array,\n description,\n apiName,\n displayName\n}) {\n return {\n apiName,\n displayMetadata: {\n displayName: displayName ?? apiName,\n visibility: \"NORMAL\",\n description\n },\n type: array ? {\n type: \"array\",\n array: {\n subtype: convertType(type)\n }\n } : convertType(type),\n aliases: [],\n baseFormatter: undefined,\n dataConstraints: undefined,\n gothamMapping: undefined,\n indexedForSearch: true,\n provenance: undefined,\n typeClasses: [],\n valueType: undefined\n };\n}\nfunction convertType(type) {\n switch (type) {\n case \"marking\":\n return {\n type,\n [type]: {\n markingType: \"MANDATORY\"\n }\n };\n case \"geopoint\":\n return {\n type: \"geohash\",\n geohash: {}\n };\n case \"decimal\":\n return {\n type,\n [type]: {\n precision: undefined,\n scale: undefined\n }\n };\n case \"string\":\n return {\n type,\n [type]: {\n analyzerOverride: undefined,\n enableAsciiFolding: undefined,\n isLongText: false,\n supportsExactMatching: true\n }\n };\n default:\n // use helper function to distribute `type` properly\n return distributeTypeHelper(type);\n }\n}\n\n/**\n * Helper function to avoid duplication. Makes the types match properly with the correct\n * behavior without needing to switch on type.\n * @param type\n * @returns\n */\nfunction distributeTypeHelper(type) {\n return {\n type,\n [type]: {}\n }; // any cast to match conditional return type\n}","/*\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\";\nexport function defineSharedPropertyType(opts) {\n const {\n apiName\n } = opts;\n !(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n ...opts\n };\n}","/*\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\";\nexport function defineLink(from, opts) {\n const apiName = opts.one ?? opts.many;\n const toApiName = opts.reverse.one ?? opts.reverse.many;\n const to = opts.to;\n !(from.linkTypes[apiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${apiName} already exists on ${from.data.objectType.apiName}`) : invariant(false) : void 0;\n !(from.linkTypes[toApiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toApiName} already exists on ${to.data.objectType.apiName}`) : invariant(false) : void 0;\n from.linkTypes[apiName] = {\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: to.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n to.linkTypes[toApiName] = {\n apiName: toApiName,\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: from.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n}","/*\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\";\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 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\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({\n ...t,\n multiplicity: false\n })\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 !false ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n}","/*\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\";\nexport function defineInterfaceLinkConstraint(linkDef) {\n const fromLinkMeta = getLinkMeta(linkDef);\n !(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;\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\" ? withDefaults({\n apiName: meta\n }) : withDefaults(meta);\n}\nfunction withDefaults({\n apiName,\n description,\n displayName\n}) {\n return {\n apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName\n };\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdk/maker",
3
- "version": "0.7.0-beta.0",
3
+ "version": "0.7.0-beta.2",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,14 +22,17 @@
22
22
  "tiny-invariant": "^1.3.3",
23
23
  "ts-node": "^10.9.2",
24
24
  "yargs": "^17.7.2",
25
- "@osdk/gateway": "^2.3.0",
26
- "@osdk/api": "^1.8.0"
25
+ "@osdk/api": "~1.9.0-beta.1",
26
+ "@osdk/gateway": "~2.4.0-beta.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/yargs": "^17.0.32",
30
30
  "typescript": "^5.5.2",
31
31
  "vitest": "^1.6.0",
32
- "@osdk/client.unstable": "^0.0.0"
32
+ "@osdk/client.unstable": "~0.1.0-beta.0",
33
+ "@osdk/monorepo.api-extractor": "~0.0.0",
34
+ "@osdk/monorepo.tsconfig": "~0.0.0",
35
+ "@osdk/monorepo.tsup": "~0.0.0"
33
36
  },
34
37
  "publishConfig": {
35
38
  "access": "public"
@@ -49,11 +52,12 @@
49
52
  "types": "./build/esm/index.d.ts",
50
53
  "type": "module",
51
54
  "scripts": {
52
- "check-attw": "../../scripts/build_common/check-attw.sh esm",
55
+ "check-attw": "monorepo.tool.attw esm",
56
+ "check-spelling": "cspell --quiet .",
53
57
  "clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
54
58
  "fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
55
59
  "lint": "eslint . && dprint check --config $(find-up dprint.json)",
56
- "transpile": "tsup",
57
- "typecheck": "../../scripts/build_common/typecheck.sh esm"
60
+ "transpile": "monorepo.tool.transpile",
61
+ "typecheck": "monorepo.tool.typecheck esm"
58
62
  }
59
63
  }