@osdk/maker 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -147,7 +147,7 @@ function isSimpleType(v) {
147
147
 
148
148
  // src/cli/main.ts
149
149
  async function main(args = process.argv) {
150
- const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.2.0").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
150
+ const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.3.0").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
151
151
  input: {
152
152
  alias: "i",
153
153
  describe: "Input file",
@@ -173,7 +173,7 @@ async function main(args = process.argv) {
173
173
  consola.consola.info(`Loading ontology from ${commandLineOpts.input}`);
174
174
  const ontology = await loadOntology(commandLineOpts.input);
175
175
  consola.consola.info(`Saving ontology to ${commandLineOpts.output}`);
176
- fs__namespace.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));
176
+ await fs__namespace.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));
177
177
  }
178
178
  async function loadOntology(input) {
179
179
  const q = await defineOntology("", async () => await import(input));
@@ -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"],"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,gBAAgB,CAAC;AAAA,IACjB,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,qBAAqB,CAAC;AAAA,EACxB;A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*\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 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(apiName, 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 // switch (v) {\n // case \"boolean\":\n // case \"byte\":\n // case \"date\":\n // case \"float\":\n // case \"geopoint\":\n // case \"geoshape\":\n // case \"integer\":\n // case \"decimal\":\n // case \"double\":\n // case \"long\":\n // case \"short\":\n // case \"string\":\n // case \"timestamp\":\n // return [\n // k,\n // {\n // rid: \"idk\",\n // apiName: k,\n // displayName: k,\n // dataType: {\n // type: v,\n // },\n // } satisfies SharedPropertyType,\n // ];\n // }\n\n const spt = defineSharedPropertyType(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 return ontologyDefinition.interfaceTypes[apiName] = {\n apiName,\n displayName: opts.displayName ?? apiName,\n extendsInterfaces: [],\n links: {},\n properties,\n rid: \"\",\n description: opts.description ?? opts.displayName ?? apiName\n };\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 interfaceTypes: {},\n objectTypes: {},\n queryTypes: {},\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 ontology: {\n apiName: \"IDK\",\n description: \"IDK\",\n displayName: \"IDK\",\n rid: \"ri.ontology.main.generated-object.foo\"\n },\n ...ontology,\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, convertSpt(spt)])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, {\n displayName,\n description,\n properties\n }]) => {\n return [apiName, {\n rid: \"ri.ontology.main.generated-object.foo\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n extendsInterfaces: [],\n links: {},\n properties: Object.fromEntries(Object.entries(properties).map(([apiName, spt]) => [apiName, convertSpt(spt)]))\n }];\n }))\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 rid: \"ri.ontology.main.generated-object.foo\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n dataType: array ? {\n type: \"array\",\n subType: {\n type\n }\n } : {\n type\n }\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 defineSharedPropertyType(apiName, 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 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 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}"]}
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"],"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,gBAAgB,CAAC;AAAA,IACjB,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,qBAAqB,CAAC;AAAA,EACxB;AACA,MAAI;AACF,UAAM,KAAK;AAAA,EACb,SAAS,GAAG;AAEV,YAAQ,MAA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ACF;AACA,SAAS,aAAa,GAAG;AACvB,SAAO,MAAM,aAAa,MAAM,UAAU,MAAM,UAAU,MAAM,aAAa,MAAM,YAAY,MAAM,WAAW,MAAM,cAAc,MAAM,cAAc,MAAM,aAAa,MAAM,UAAU,MAAM,aAAa,MAAM,WAAW,MAAM,YAAY,MAAM;AACzP;;;AG7DA,OAAOD,gBAAe;;;ACAtB,OAAOA,gBAAe;;;ALUtB,eAAO,KAA4B,OAAO,QAAQ,MAAM;AACtD,QAAM,kBAAkB,MAAM,MAAM,QAAQ,IAAI,CAAC,EAAE,QAAQ,OAAiC,EAAE,KAAK,KAAK,IAAI,KAAK,MAAM,EAAE,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ;AAAA,IACjK,OAAO;AAAA,MACL,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,MACT,QAAa;AAAA,IACf;AAAA,IACA,QAAQ;AAAA,MACN,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,MACT,QAAa;AAAA,IACf;AAAA,IACA,aAAa;AAAA,MACX,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,MACT,QAAa;AAAA,IACf;AAAA,EACF,CAAC,EAAE,WAAW;AACd,UAAQ,KAAK,yBAAyB,gBAAgB,KAAK,EAAE;AAC7D,QAAM,WAAW,MAAM,aAAa,gBAAgB,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","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(apiName, 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 // switch (v) {\n // case \"boolean\":\n // case \"byte\":\n // case \"date\":\n // case \"float\":\n // case \"geopoint\":\n // case \"geoshape\":\n // case \"integer\":\n // case \"decimal\":\n // case \"double\":\n // case \"long\":\n // case \"short\":\n // case \"string\":\n // case \"timestamp\":\n // return [\n // k,\n // {\n // rid: \"idk\",\n // apiName: k,\n // displayName: k,\n // dataType: {\n // type: v,\n // },\n // } satisfies SharedPropertyType,\n // ];\n // }\n\n const spt = defineSharedPropertyType(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 return ontologyDefinition.interfaceTypes[apiName] = {\n apiName,\n displayName: opts.displayName ?? apiName,\n extendsInterfaces: [],\n links: {},\n properties,\n rid: \"\",\n description: opts.description ?? opts.displayName ?? apiName\n };\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 interfaceTypes: {},\n objectTypes: {},\n queryTypes: {},\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 ontology: {\n apiName: \"IDK\",\n description: \"IDK\",\n displayName: \"IDK\",\n rid: \"ri.ontology.main.generated-object.foo\"\n },\n ...ontology,\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, convertSpt(spt)])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, {\n displayName,\n description,\n properties\n }]) => {\n return [apiName, {\n rid: \"ri.ontology.main.generated-object.foo\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n extendsInterfaces: [],\n links: {},\n properties: Object.fromEntries(Object.entries(properties).map(([apiName, spt]) => [apiName, convertSpt(spt)]))\n }];\n }))\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 rid: \"ri.ontology.main.generated-object.foo\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n dataType: array ? {\n type: \"array\",\n subType: {\n type\n }\n } : {\n type\n }\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 defineSharedPropertyType(apiName, 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 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 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}"]}
@@ -118,7 +118,7 @@ function isSimpleType(v) {
118
118
 
119
119
  // src/cli/main.ts
120
120
  async function main(args = process.argv) {
121
- const commandLineOpts = await yargs(hideBin(args)).version("0.2.0").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
121
+ const commandLineOpts = await yargs(hideBin(args)).version("0.3.0").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
122
122
  input: {
123
123
  alias: "i",
124
124
  describe: "Input file",
@@ -144,7 +144,7 @@ async function main(args = process.argv) {
144
144
  consola.info(`Loading ontology from ${commandLineOpts.input}`);
145
145
  const ontology = await loadOntology(commandLineOpts.input);
146
146
  consola.info(`Saving ontology to ${commandLineOpts.output}`);
147
- fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));
147
+ await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));
148
148
  }
149
149
  async function loadOntology(input) {
150
150
  const q = await defineOntology("", async () => await import(input));
@@ -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"],"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,gBAAgB,CAAC;AAAA,IACjB,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,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,UAAU;AAAA,MACR,SAAS;AAAA,MACT,aAAa;AAAA,MACb,aAAa;AAAA,MACb,KAAK;AAAA,IACP;AAAA,IACA,GAAG;AAAA,IACH,qBAAqB,OAAO,YAAY,OAAO,QAAQ,SAAS,mBAAmB,EAAE,IAAI,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,WAAW,GAAG,CAAC,CAAC,CAAC;AAAA,IACxI,gBAAgB,OAAO,YAAY,OAAO,QAAQ,SAAS,cAAc,EAAE,IAAI,CAAC,CAAC,SAAS;AAAA,MACxF;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC,MAAM;AACL,aAAO,CAAC,SAAS;AAAA,QACf,KAAK;AAAA,QACL;AAAA,QACA,aAAa,eAAe;AAAA,QAC5B;AAAA,QACA,mBAAmB,CAAC;AAAA,QACpB,OAAO,CAAC;AAAA,QACR,YAAY,OAAO,YAAY,OAAO,QAAQ,UAAU,EAAE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ACA,aAAa;AAAA,MACX,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,MACT,QAAa;AAAA,IACf;AAAA,EACF,CAAC,EAAE,WAAW;AACd,UAAQ,KAAK,yBAAyB,gBAAgB,KAAK,EAAE;AAC7D,QAAM,WAAW,MAAM,aAAa,gBAAgB,KAAK;AACzD,UAAQ,KAAK,sBAAsB,gBAAgB,MAAM,EAAE;AAC3D,EAAG,aAAU,gBAAgB,QAAQ,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AACxE;AAkCA,eAAe,aAAa,OAAO;AAQjC,QAAM,IAAI,MAAM,eAAe,IAAI,YAAY,MAAM,OAAO,MAAM;AAClE,SAAO;AACT","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 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(apiName, 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 // switch (v) {\n // case \"boolean\":\n // case \"byte\":\n // case \"date\":\n // case \"float\":\n // case \"geopoint\":\n // case \"geoshape\":\n // case \"integer\":\n // case \"decimal\":\n // case \"double\":\n // case \"long\":\n // case \"short\":\n // case \"string\":\n // case \"timestamp\":\n // return [\n // k,\n // {\n // rid: \"idk\",\n // apiName: k,\n // displayName: k,\n // dataType: {\n // type: v,\n // },\n // } satisfies SharedPropertyType,\n // ];\n // }\n\n const spt = defineSharedPropertyType(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 return ontologyDefinition.interfaceTypes[apiName] = {\n apiName,\n displayName: opts.displayName ?? apiName,\n extendsInterfaces: [],\n links: {},\n properties,\n rid: \"\",\n description: opts.description ?? opts.displayName ?? apiName\n };\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 interfaceTypes: {},\n objectTypes: {},\n queryTypes: {},\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 ontology: {\n apiName: \"IDK\",\n description: \"IDK\",\n displayName: \"IDK\",\n rid: \"ri.ontology.main.generated-object.foo\"\n },\n ...ontology,\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, convertSpt(spt)])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, {\n displayName,\n description,\n properties\n }]) => {\n return [apiName, {\n rid: \"ri.ontology.main.generated-object.foo\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n extendsInterfaces: [],\n links: {},\n properties: Object.fromEntries(Object.entries(properties).map(([apiName, spt]) => [apiName, convertSpt(spt)]))\n }];\n }))\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 rid: \"ri.ontology.main.generated-object.foo\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n dataType: array ? {\n type: \"array\",\n subType: {\n type\n }\n } : {\n type\n }\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 defineSharedPropertyType(apiName, 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 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 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}"]}
1
+ {"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt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MACN,SAAS;AAAA,MACT,QAAa;AAAA,IACf;AAAA,EACF,CAAC,EAAE,WAAW;AACd,UAAQ,KAAK,yBAAyB,gBAAgB,KAAK,EAAE;AAC7D,QAAM,WAAW,MAAM,aAAa,gBAAgB,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","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(apiName, 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 // switch (v) {\n // case \"boolean\":\n // case \"byte\":\n // case \"date\":\n // case \"float\":\n // case \"geopoint\":\n // case \"geoshape\":\n // case \"integer\":\n // case \"decimal\":\n // case \"double\":\n // case \"long\":\n // case \"short\":\n // case \"string\":\n // case \"timestamp\":\n // return [\n // k,\n // {\n // rid: \"idk\",\n // apiName: k,\n // displayName: k,\n // dataType: {\n // type: v,\n // },\n // } satisfies SharedPropertyType,\n // ];\n // }\n\n const spt = defineSharedPropertyType(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 return ontologyDefinition.interfaceTypes[apiName] = {\n apiName,\n displayName: opts.displayName ?? apiName,\n extendsInterfaces: [],\n links: {},\n properties,\n rid: \"\",\n description: opts.description ?? opts.displayName ?? apiName\n };\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 interfaceTypes: {},\n objectTypes: {},\n queryTypes: {},\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 ontology: {\n apiName: \"IDK\",\n description: \"IDK\",\n displayName: \"IDK\",\n rid: \"ri.ontology.main.generated-object.foo\"\n },\n ...ontology,\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, convertSpt(spt)])),\n interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, {\n displayName,\n description,\n properties\n }]) => {\n return [apiName, {\n rid: \"ri.ontology.main.generated-object.foo\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n extendsInterfaces: [],\n links: {},\n properties: Object.fromEntries(Object.entries(properties).map(([apiName, spt]) => [apiName, convertSpt(spt)]))\n }];\n }))\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 rid: \"ri.ontology.main.generated-object.foo\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n dataType: array ? {\n type: \"array\",\n subType: {\n type\n }\n } : {\n type\n }\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 defineSharedPropertyType(apiName, 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 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 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}"]}
@@ -0,0 +1,5 @@
1
+ type: improvement
2
+ improvement:
3
+ description: generator can make packagejson
4
+ links:
5
+ - https://github.com/palantir/osdk-ts/pull/140
@@ -0,0 +1,5 @@
1
+ type: improvement
2
+ improvement:
3
+ description: Improves tsconfig
4
+ links:
5
+ - https://github.com/palantir/osdk-ts/pull/141
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osdk/maker",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,8 +24,8 @@
24
24
  "tiny-invariant": "^1.3.3",
25
25
  "ts-node": "^10.9.2",
26
26
  "yargs": "^17.7.2",
27
- "@osdk/api": "1.4.0",
28
- "@osdk/gateway": "2.0.0"
27
+ "@osdk/api": "1.5.0",
28
+ "@osdk/gateway": "2.1.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/yargs": "^17.0.32",