@osdk/maker 0.7.1 → 0.8.0-beta.1
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 +14 -4
- package/build/browser/index.js +26 -16
- package/build/browser/index.js.map +1 -1
- package/build/esm/api/defineInterfaceLinkConstraint.d.ts.map +1 -1
- package/build/esm/cli/main.d.ts.map +1 -1
- package/build/esm/index.js +26 -16
- package/build/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/build/cjs/index.cjs +0 -284
- package/build/cjs/index.cjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
# @osdk/maker
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.8.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6e3726b: Support namespacing maker generate ontologies
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [dc25fb4]
|
|
12
|
+
- @osdk/api@1.10.0-beta.1
|
|
13
|
+
|
|
14
|
+
## 0.8.0-beta.0
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
6
17
|
|
|
7
|
-
- Updated dependencies [
|
|
8
|
-
- @osdk/
|
|
9
|
-
- @osdk/api@1.9.1
|
|
18
|
+
- Updated dependencies [7c2db00]
|
|
19
|
+
- @osdk/api@1.10.0-beta.0
|
|
10
20
|
|
|
11
21
|
## 0.7.0
|
|
12
22
|
|
package/build/browser/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { consola } from 'consola';
|
|
2
2
|
import * as fs from 'fs/promises';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
+
import invariant2 from 'tiny-invariant';
|
|
4
5
|
import yargs from 'yargs';
|
|
5
6
|
import { hideBin } from 'yargs/helpers';
|
|
6
|
-
import invariant2 from 'tiny-invariant';
|
|
7
7
|
|
|
8
8
|
// src/cli/main.ts
|
|
9
9
|
|
|
10
10
|
// src/api/defineOntology.ts
|
|
11
11
|
var ontologyDefinition;
|
|
12
|
+
var namespace;
|
|
12
13
|
async function defineOntology(ns, body) {
|
|
14
|
+
namespace = ns;
|
|
13
15
|
ontologyDefinition = {
|
|
14
16
|
actionTypes: {},
|
|
15
17
|
objectTypes: {},
|
|
@@ -125,9 +127,7 @@ function distributeTypeHelper(type) {
|
|
|
125
127
|
};
|
|
126
128
|
}
|
|
127
129
|
function defineSharedPropertyType(opts) {
|
|
128
|
-
const
|
|
129
|
-
apiName
|
|
130
|
-
} = opts;
|
|
130
|
+
const apiName = namespace + opts.apiName;
|
|
131
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
|
|
@@ -136,9 +136,7 @@ function defineSharedPropertyType(opts) {
|
|
|
136
136
|
|
|
137
137
|
// src/api/defineInterface.ts
|
|
138
138
|
function defineInterface(opts) {
|
|
139
|
-
const
|
|
140
|
-
apiName
|
|
141
|
-
} = opts;
|
|
139
|
+
const apiName = namespace + opts.apiName;
|
|
142
140
|
!(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Interface ${apiName} already exists`) : invariant2(false) : void 0;
|
|
143
141
|
const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
|
|
144
142
|
if (typeof type === "string") {
|
|
@@ -161,8 +159,8 @@ function defineInterface(opts) {
|
|
|
161
159
|
const a = {
|
|
162
160
|
apiName,
|
|
163
161
|
displayMetadata: {
|
|
164
|
-
displayName: opts.displayName ?? apiName,
|
|
165
|
-
description: opts.description ?? opts.displayName ?? apiName,
|
|
162
|
+
displayName: opts.displayName ?? opts.apiName,
|
|
163
|
+
description: opts.description ?? opts.displayName ?? opts.apiName,
|
|
166
164
|
icon: void 0
|
|
167
165
|
},
|
|
168
166
|
extendsInterfaces: [],
|
|
@@ -173,15 +171,16 @@ function defineInterface(opts) {
|
|
|
173
171
|
active: {}
|
|
174
172
|
}
|
|
175
173
|
};
|
|
176
|
-
return ontologyDefinition.interfaceTypes[apiName] = a;
|
|
174
|
+
return ontologyDefinition.interfaceTypes[namespace + apiName] = a;
|
|
177
175
|
}
|
|
178
176
|
function isSimpleType(v) {
|
|
179
177
|
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";
|
|
180
178
|
}
|
|
181
179
|
|
|
182
180
|
// src/cli/main.ts
|
|
181
|
+
var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
|
|
183
182
|
async function main(args = process.argv) {
|
|
184
|
-
const commandLineOpts = await yargs(hideBin(args)).version("0.
|
|
183
|
+
const commandLineOpts = await yargs(hideBin(args)).version("0.8.0-beta.1").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
|
|
185
184
|
input: {
|
|
186
185
|
alias: "i",
|
|
187
186
|
describe: "Input file",
|
|
@@ -196,6 +195,11 @@ async function main(args = process.argv) {
|
|
|
196
195
|
default: "ontology.json",
|
|
197
196
|
coerce: path.resolve
|
|
198
197
|
},
|
|
198
|
+
apiNamespace: {
|
|
199
|
+
describe: "Api name prefix for namespaced ontology types",
|
|
200
|
+
type: "string",
|
|
201
|
+
default: ""
|
|
202
|
+
},
|
|
199
203
|
snapshotDir: {
|
|
200
204
|
alias: "s",
|
|
201
205
|
describe: "Snapshot directory",
|
|
@@ -204,13 +208,19 @@ async function main(args = process.argv) {
|
|
|
204
208
|
coerce: path.resolve
|
|
205
209
|
}
|
|
206
210
|
}).parseAsync();
|
|
211
|
+
let apiNamespace = "";
|
|
212
|
+
if (commandLineOpts.apiNamespace.length !== 0) {
|
|
213
|
+
apiNamespace = commandLineOpts.apiNamespace.slice(-1) !== "." ? commandLineOpts.apiNamespace + "." : commandLineOpts.apiNamespace;
|
|
214
|
+
!(apiNamespace.length < 1024) ? process.env.NODE_ENV !== "production" ? invariant2(false, "API namespace is too long.") : invariant2(false) : void 0;
|
|
215
|
+
!apiNamespaceRegex.test(apiNamespace) ? process.env.NODE_ENV !== "production" ? invariant2(false, "API namespace is invalid! It is expected to conform to ^[a-z0-9-]+(.[a-z0-9-]+)*.$") : invariant2(false) : void 0;
|
|
216
|
+
}
|
|
207
217
|
consola.info(`Loading ontology from ${commandLineOpts.input}`);
|
|
208
|
-
const ontology = await loadOntology(commandLineOpts.input);
|
|
218
|
+
const ontology = await loadOntology(commandLineOpts.input, apiNamespace);
|
|
209
219
|
consola.info(`Saving ontology to ${commandLineOpts.output}`);
|
|
210
220
|
await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));
|
|
211
221
|
}
|
|
212
|
-
async function loadOntology(input) {
|
|
213
|
-
const q = await defineOntology(
|
|
222
|
+
async function loadOntology(input, apiNamespace) {
|
|
223
|
+
const q = await defineOntology(apiNamespace, async () => await import(input));
|
|
214
224
|
return q;
|
|
215
225
|
}
|
|
216
226
|
function defineInterfaceLinkConstraint(linkDef) {
|
|
@@ -232,7 +242,7 @@ function getLinkedType(t) {
|
|
|
232
242
|
}
|
|
233
243
|
function getLinkMeta(meta) {
|
|
234
244
|
return typeof meta === "string" ? withDefaults({
|
|
235
|
-
apiName: meta
|
|
245
|
+
apiName: namespace + meta
|
|
236
246
|
}) : withDefaults(meta);
|
|
237
247
|
}
|
|
238
248
|
function withDefaults({
|
|
@@ -241,7 +251,7 @@ function withDefaults({
|
|
|
241
251
|
displayName
|
|
242
252
|
}) {
|
|
243
253
|
return {
|
|
244
|
-
apiName,
|
|
254
|
+
apiName: namespace + apiName,
|
|
245
255
|
displayName: displayName ?? apiName,
|
|
246
256
|
description: description ?? displayName ?? apiName
|
|
247
257
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineInterface.ts","../../src/cli/main.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";;;;;;;;;;AAiBO,IAAI,kBAAA,CAAA;AAIX,eAAsB,cAAA,CAAe,IAAI,IAAM,EAAA;AAE7C,EAAqB,kBAAA,GAAA;AAAA,IACnB,aAAa,EAAC;AAAA,IACd,aAAa,EAAC;AAAA,IACd,YAAY,EAAC;AAAA,IACb,gBAAgB,EAAC;AAAA,IACjB,qBAAqB,EAAC;AAAA,GACxB,CAAA;AACA,EAAI,IAAA;AACF,IAAA,MAAM,IAAK,EAAA,CAAA;AAAA,WACJ,CAAG,EAAA;AAEV,IAAQ,OAAA,CAAA,KAAA,CAAM,8DAA8D,CAAC,CAAA,CAAA;AAC7E,IAAM,MAAA,CAAA,CAAA;AAAA,GACR;AACA,EAAA,OAAO,sBAAsB,kBAAkB,CAAA,CAAA;AACjD,CAAA;AACA,SAAS,sBAAsB,QAAU,EAAA;AACvC,EAAO,OAAA;AAAA,IACL,mBAAqB,EAAA,MAAA,CAAO,WAAY,CAAA,MAAA,CAAO,QAAQ,QAAS,CAAA,mBAAmB,CAAE,CAAA,GAAA,CAAI,CAAC,CAAC,OAAA,EAAS,GAAG,CAAA,KAAM,CAAC,OAAS,EAAA;AAAA,MACrH,kBAAA,EAAoB,WAAW,GAAG,CAAA;AAAA,KACnC,CAAC,CAAC,CAAA;AAAA,IACH,cAAgB,EAAA,MAAA,CAAO,WAAY,CAAA,MAAA,CAAO,OAAQ,CAAA,QAAA,CAAS,cAAc,CAAA,CAAE,GAAI,CAAA,CAAC,CAAC,OAAA,EAAS,aAAa,CAAM,KAAA;AAC3G,MAAA,OAAO,CAAC,OAAS,EAAA;AAAA,QACf,aAAA,EAAe,iBAAiB,aAAa,CAAA;AAAA,OAC9C,CAAA,CAAA;AAAA,KACF,C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W,IAAI,CAAE,CAAA,OAAA;AAAA,GAC/C,CAAA;AACF,CAAA;AACA,SAAS,YAAY,IAAM,EAAA;AACzB,EAAO,OAAA,OAAO,IAAS,KAAA,QAAA,GAAW,YAAa,CAAA;AAAA,IAC7C,OAAS,EAAA,IAAA;AAAA,GACV,CAAI,GAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AACxB,CAAA;AACA,SAAS,YAAa,CAAA;AAAA,EACpB,OAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AACF,CAAG,EAAA;AACD,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,aAAa,WAAe,IAAA,OAAA;AAAA,IAC5B,WAAA,EAAa,eAAe,WAAe,IAAA,OAAA;AAAA,GAC7C,CAAA;AACF","file":"index.js","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** @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\";\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\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\";\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
|
+
{"version":3,"sources":["../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineInterface.ts","../../src/cli/main.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";;;;;;;;;;AAiBO,IAAI,kBAAA,CAAA;AAGJ,IAAI,SAAA,CAAA;AACX,eAAsB,cAAA,CAAe,IAAI,IAAM,EAAA;AAC7C,EAAY,SAAA,GAAA,EAAA,CAAA;AACZ,EAAqB,kBAAA,GAAA;AAAA,IACnB,aAAa,EAAC;AAAA,IACd,aAAa,EAAC;AAAA,IACd,YAAY,EAAC;AAAA,IACb,gBAAgB,EAAC;AAAA,IACjB,qBAAqB,EAAC;AAAA,GACxB,CAAA;AACA,EAAI,IAAA;AACF,IAAA,MAAM,IAAK,EAAA,CAAA;AAAA,WACJ,CAAG,EAAA;AAEV,IAAQ,OAAA,CAAA,KAAA,CAAM,8DAA8D,CAAC,CAAA,CAAA;AAC7E,IAAM,MAAA,CAAA,CAAA;AAAA,GACR;AACA,EAAA,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AA,aAAA,CAAc,OAAQ,CAAA,MAAA,IAAU,QAAQ,KAAK,CAAA;AAAA,IACjE,QAAU,EAAA,YAAA;AAAA,IACV,QAAU,EAAA,IAAA;AAAA;AAAA,GACX,CAAA,CAAA;AACH,CAAA;AACA,SAAS,cAAc,CAAG,EAAA;AACxB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,eAAA;AAAA,IACN,aAAe,EAAA,OAAO,CAAM,KAAA,QAAA,GAAW,IAAI,CAAE,CAAA,OAAA;AAAA,GAC/C,CAAA;AACF,CAAA;AACA,SAAS,YAAY,IAAM,EAAA;AACzB,EAAO,OAAA,OAAO,IAAS,KAAA,QAAA,GAAW,YAAa,CAAA;AAAA,IAC7C,SAAS,SAAY,GAAA,IAAA;AAAA,GACtB,CAAI,GAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AACxB,CAAA;AACA,SAAS,YAAa,CAAA;AAAA,EACpB,OAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AACF,CAAG,EAAA;AACD,EAAO,OAAA;AAAA,IACL,SAAS,SAAY,GAAA,OAAA;AAAA,IACrB,aAAa,WAAe,IAAA,OAAA;AAAA,IAC5B,WAAA,EAAa,eAAe,WAAe,IAAA,OAAA;AAAA,GAC7C,CAAA;AACF","file":"index.js","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** @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 { namespace, ontologyDefinition } from \"./defineOntology.js\";\nexport function defineSharedPropertyType(opts) {\n const apiName = namespace + opts.apiName;\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\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nimport { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const apiName = namespace + opts.apiName;\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 ?? opts.apiName,\n description: opts.description ?? opts.displayName ?? opts.apiName,\n icon: undefined\n },\n extendsInterfaces: [],\n links: [],\n properties,\n status: {\n type: \"active\",\n active: {}\n }\n };\n return ontologyDefinition.interfaceTypes[namespace + 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\nimport { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport invariant from \"tiny-invariant\";\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\";\nconst apiNamespaceRegex = /^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.$/;\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 apiNamespace: {\n describe: \"Api name prefix for namespaced ontology types\",\n type: \"string\",\n default: \"\"\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve\n }\n }).parseAsync();\n let apiNamespace = \"\";\n if (commandLineOpts.apiNamespace.length !== 0) {\n apiNamespace = commandLineOpts.apiNamespace.slice(-1) !== \".\" ? commandLineOpts.apiNamespace + \".\" : commandLineOpts.apiNamespace;\n !(apiNamespace.length < 1024) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"API namespace is too long.\") : invariant(false) : void 0;\n !apiNamespaceRegex.test(apiNamespace) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"API namespace is invalid! It is expected to conform to ^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.$\") : invariant(false) : void 0;\n }\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n const ontology = await loadOntology(commandLineOpts.input, apiNamespace);\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, apiNamespace) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(apiNamespace, 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 { namespace } from \"./defineOntology.js\";\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: namespace + meta\n }) : withDefaults(meta);\n}\nfunction withDefaults({\n apiName,\n description,\n displayName\n}) {\n return {\n apiName: namespace + apiName,\n displayName: displayName ?? apiName,\n description: description ?? displayName ?? apiName\n };\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineInterfaceLinkConstraint.d.ts","sourceRoot":"","sources":["../../../src/api/defineInterfaceLinkConstraint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"defineInterfaceLinkConstraint.d.ts","sourceRoot":"","sources":["../../../src/api/defineInterfaceLinkConstraint.ts"],"names":[],"mappings":"AAkBA,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/cli/main.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/cli/main.ts"],"names":[],"mappings":"AA8BA,wBAA8B,IAAI,CAChC,IAAI,GAAE,MAAM,EAAiB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA2Df"}
|
package/build/esm/index.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { consola } from 'consola';
|
|
2
2
|
import * as fs from 'fs/promises';
|
|
3
3
|
import * as path from 'path';
|
|
4
|
+
import invariant2 from 'tiny-invariant';
|
|
4
5
|
import yargs from 'yargs';
|
|
5
6
|
import { hideBin } from 'yargs/helpers';
|
|
6
|
-
import invariant2 from 'tiny-invariant';
|
|
7
7
|
|
|
8
8
|
// src/cli/main.ts
|
|
9
9
|
|
|
10
10
|
// src/api/defineOntology.ts
|
|
11
11
|
var ontologyDefinition;
|
|
12
|
+
var namespace;
|
|
12
13
|
async function defineOntology(ns, body) {
|
|
14
|
+
namespace = ns;
|
|
13
15
|
ontologyDefinition = {
|
|
14
16
|
actionTypes: {},
|
|
15
17
|
objectTypes: {},
|
|
@@ -125,9 +127,7 @@ function distributeTypeHelper(type) {
|
|
|
125
127
|
};
|
|
126
128
|
}
|
|
127
129
|
function defineSharedPropertyType(opts) {
|
|
128
|
-
const
|
|
129
|
-
apiName
|
|
130
|
-
} = opts;
|
|
130
|
+
const apiName = namespace + opts.apiName;
|
|
131
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
|
|
@@ -136,9 +136,7 @@ function defineSharedPropertyType(opts) {
|
|
|
136
136
|
|
|
137
137
|
// src/api/defineInterface.ts
|
|
138
138
|
function defineInterface(opts) {
|
|
139
|
-
const
|
|
140
|
-
apiName
|
|
141
|
-
} = opts;
|
|
139
|
+
const apiName = namespace + opts.apiName;
|
|
142
140
|
!(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Interface ${apiName} already exists`) : invariant2(false) : void 0;
|
|
143
141
|
const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
|
|
144
142
|
if (typeof type === "string") {
|
|
@@ -161,8 +159,8 @@ function defineInterface(opts) {
|
|
|
161
159
|
const a = {
|
|
162
160
|
apiName,
|
|
163
161
|
displayMetadata: {
|
|
164
|
-
displayName: opts.displayName ?? apiName,
|
|
165
|
-
description: opts.description ?? opts.displayName ?? apiName,
|
|
162
|
+
displayName: opts.displayName ?? opts.apiName,
|
|
163
|
+
description: opts.description ?? opts.displayName ?? opts.apiName,
|
|
166
164
|
icon: void 0
|
|
167
165
|
},
|
|
168
166
|
extendsInterfaces: [],
|
|
@@ -173,15 +171,16 @@ function defineInterface(opts) {
|
|
|
173
171
|
active: {}
|
|
174
172
|
}
|
|
175
173
|
};
|
|
176
|
-
return ontologyDefinition.interfaceTypes[apiName] = a;
|
|
174
|
+
return ontologyDefinition.interfaceTypes[namespace + apiName] = a;
|
|
177
175
|
}
|
|
178
176
|
function isSimpleType(v) {
|
|
179
177
|
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";
|
|
180
178
|
}
|
|
181
179
|
|
|
182
180
|
// src/cli/main.ts
|
|
181
|
+
var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
|
|
183
182
|
async function main(args = process.argv) {
|
|
184
|
-
const commandLineOpts = await yargs(hideBin(args)).version("0.
|
|
183
|
+
const commandLineOpts = await yargs(hideBin(args)).version("0.8.0-beta.1").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
|
|
185
184
|
input: {
|
|
186
185
|
alias: "i",
|
|
187
186
|
describe: "Input file",
|
|
@@ -196,6 +195,11 @@ async function main(args = process.argv) {
|
|
|
196
195
|
default: "ontology.json",
|
|
197
196
|
coerce: path.resolve
|
|
198
197
|
},
|
|
198
|
+
apiNamespace: {
|
|
199
|
+
describe: "Api name prefix for namespaced ontology types",
|
|
200
|
+
type: "string",
|
|
201
|
+
default: ""
|
|
202
|
+
},
|
|
199
203
|
snapshotDir: {
|
|
200
204
|
alias: "s",
|
|
201
205
|
describe: "Snapshot directory",
|
|
@@ -204,13 +208,19 @@ async function main(args = process.argv) {
|
|
|
204
208
|
coerce: path.resolve
|
|
205
209
|
}
|
|
206
210
|
}).parseAsync();
|
|
211
|
+
let apiNamespace = "";
|
|
212
|
+
if (commandLineOpts.apiNamespace.length !== 0) {
|
|
213
|
+
apiNamespace = commandLineOpts.apiNamespace.slice(-1) !== "." ? commandLineOpts.apiNamespace + "." : commandLineOpts.apiNamespace;
|
|
214
|
+
!(apiNamespace.length < 1024) ? process.env.NODE_ENV !== "production" ? invariant2(false, "API namespace is too long.") : invariant2(false) : void 0;
|
|
215
|
+
!apiNamespaceRegex.test(apiNamespace) ? process.env.NODE_ENV !== "production" ? invariant2(false, "API namespace is invalid! It is expected to conform to ^[a-z0-9-]+(.[a-z0-9-]+)*.$") : invariant2(false) : void 0;
|
|
216
|
+
}
|
|
207
217
|
consola.info(`Loading ontology from ${commandLineOpts.input}`);
|
|
208
|
-
const ontology = await loadOntology(commandLineOpts.input);
|
|
218
|
+
const ontology = await loadOntology(commandLineOpts.input, apiNamespace);
|
|
209
219
|
consola.info(`Saving ontology to ${commandLineOpts.output}`);
|
|
210
220
|
await fs.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));
|
|
211
221
|
}
|
|
212
|
-
async function loadOntology(input) {
|
|
213
|
-
const q = await defineOntology(
|
|
222
|
+
async function loadOntology(input, apiNamespace) {
|
|
223
|
+
const q = await defineOntology(apiNamespace, async () => await import(input));
|
|
214
224
|
return q;
|
|
215
225
|
}
|
|
216
226
|
function defineInterfaceLinkConstraint(linkDef) {
|
|
@@ -232,7 +242,7 @@ function getLinkedType(t) {
|
|
|
232
242
|
}
|
|
233
243
|
function getLinkMeta(meta) {
|
|
234
244
|
return typeof meta === "string" ? withDefaults({
|
|
235
|
-
apiName: meta
|
|
245
|
+
apiName: namespace + meta
|
|
236
246
|
}) : withDefaults(meta);
|
|
237
247
|
}
|
|
238
248
|
function withDefaults({
|
|
@@ -241,7 +251,7 @@ function withDefaults({
|
|
|
241
251
|
displayName
|
|
242
252
|
}) {
|
|
243
253
|
return {
|
|
244
|
-
apiName,
|
|
254
|
+
apiName: namespace + apiName,
|
|
245
255
|
displayName: displayName ?? apiName,
|
|
246
256
|
description: description ?? displayName ?? apiName
|
|
247
257
|
};
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineInterface.ts","../../src/cli/main.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";;;;;;;;;;AAiBO,IAAI,kBAAA,CAAA;AAIX,eAAsB,cAAA,CAAe,IAAI,IAAM,EAAA;AAE7C,EAAqB,kBAAA,GAAA;AAAA,IACnB,aAAa,EAAC;AAAA,IACd,aAAa,EAAC;AAAA,IACd,YAAY,EAAC;AAAA,IACb,gBAAgB,EAAC;AAAA,IACjB,qBAAqB,EAAC;AAAA,GACxB,CAAA;AACA,EAAI,IAAA;AACF,IAAA,MAAM,IAAK,EAAA,CAAA;AAAA,WACJ,CAAG,EAAA;AAEV,IAAQ,OAAA,CAAA,KAAA,CAAM,8DAA8D,CAAC,CAAA,CAAA;AAC7E,IAAM,MAAA,CAAA,CAAA;AAAA,GACR;AACA,EAAA,OAAO,sBAAsB,kBAAkB,CAAA,CAAA;AACjD,CAAA;AACA,SAAS,sBAAsB,QAAU,EAAA;AACvC,EAAO,OAAA;AAAA,IACL,mBAAqB,EAAA,MAAA,CAAO,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GAAIA,UAAU,CAAA,KAAK,CAAI,GAAA,KAAA,CAAA,CAAA;AACvP,EAAQ,OAAA,CAAA,IAAA,CAAK,MAAM,IAAK,CAAA;AAAA,IACtB,WAAA,EAAa,OAAQ,CAAA,MAAA,GAAS,MAAS,GAAA,QAAA;AAAA,IACvC,kBAAoB,EAAA,aAAA,CAAc,OAAQ,CAAA,MAAA,IAAU,QAAQ,KAAK,CAAA;AAAA,IACjE,QAAU,EAAA,YAAA;AAAA,IACV,QAAU,EAAA,IAAA;AAAA;AAAA,GACX,CAAA,CAAA;AACH,CAAA;AACA,SAAS,cAAc,CAAG,EAAA;AACxB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,eAAA;AAAA,IACN,aAAe,EAAA,OAAO,CAAM,KAAA,QAAA,GAAW,IAAI,CAAE,CAAA,OAAA;AAAA,GAC/C,CAAA;AACF,CAAA;AACA,SAAS,YAAY,IAAM,EAAA;AACzB,EAAO,OAAA,OAAO,IAAS,KAAA,QAAA,GAAW,YAAa,CAAA;AAAA,IAC7C,OAAS,EAAA,IAAA;AAAA,GACV,CAAI,GAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AACxB,CAAA;AACA,SAAS,YAAa,CAAA;AAAA,EACpB,OAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AACF,CAAG,EAAA;AACD,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,aAAa,WAAe,IAAA,OAAA;AAAA,IAC5B,WAAA,EAAa,eAAe,WAAe,IAAA,OAAA;AAAA,GAC7C,CAAA;AACF","file":"index.js","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** @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\";\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\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\";\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
|
+
{"version":3,"sources":["../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineInterface.ts","../../src/cli/main.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName"],"mappings":";;;;;;;;;;AAi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AAe,IAAA,OAAA;AAAA,GAC7C,CAAA;AACF","file":"index.js","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** @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 { namespace, ontologyDefinition } from \"./defineOntology.js\";\nexport function defineSharedPropertyType(opts) {\n const apiName = namespace + opts.apiName;\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\";\nimport { namespace, ontologyDefinition } from \"./defineOntology.js\";\nimport { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(opts) {\n const apiName = namespace + opts.apiName;\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 ?? opts.apiName,\n description: opts.description ?? opts.displayName ?? opts.apiName,\n icon: undefined\n },\n extendsInterfaces: [],\n links: [],\n properties,\n status: {\n type: \"active\",\n active: {}\n }\n };\n return ontologyDefinition.interfaceTypes[namespace + 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\nimport { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport invariant from \"tiny-invariant\";\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\";\nconst apiNamespaceRegex = /^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.$/;\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 apiNamespace: {\n describe: \"Api name prefix for namespaced ontology types\",\n type: \"string\",\n default: \"\"\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\",\n coerce: path.resolve\n }\n }).parseAsync();\n let apiNamespace = \"\";\n if (commandLineOpts.apiNamespace.length !== 0) {\n apiNamespace = commandLineOpts.apiNamespace.slice(-1) !== \".\" ? commandLineOpts.apiNamespace + \".\" : commandLineOpts.apiNamespace;\n !(apiNamespace.length < 1024) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"API namespace is too long.\") : invariant(false) : void 0;\n !apiNamespaceRegex.test(apiNamespace) ? process.env.NODE_ENV !== \"production\" ? invariant(false, \"API namespace is invalid! It is expected to conform to ^[a-z0-9-]+(\\.[a-z0-9-]+)*\\.$\") : invariant(false) : void 0;\n }\n consola.info(`Loading ontology from ${commandLineOpts.input}`);\n const ontology = await loadOntology(commandLineOpts.input, apiNamespace);\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, apiNamespace) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(apiNamespace, 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 { namespace } from \"./defineOntology.js\";\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: namespace + meta\n }) : withDefaults(meta);\n}\nfunction withDefaults({\n apiName,\n description,\n displayName\n}) {\n return {\n apiName: namespace + 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.
|
|
3
|
+
"version": "0.8.0-beta.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"tiny-invariant": "^1.3.3",
|
|
23
23
|
"ts-node": "^10.9.2",
|
|
24
24
|
"yargs": "^17.7.2",
|
|
25
|
-
"@osdk/api": "~1.
|
|
26
|
-
"@osdk/gateway": "~2.4.
|
|
25
|
+
"@osdk/api": "~1.10.0-beta.1",
|
|
26
|
+
"@osdk/gateway": "~2.4.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/yargs": "^17.0.32",
|
|
30
30
|
"typescript": "^5.5.4",
|
|
31
|
-
"vitest": "^
|
|
31
|
+
"vitest": "^2.0.4",
|
|
32
32
|
"@osdk/client.unstable": "~0.1.0",
|
|
33
33
|
"@osdk/monorepo.api-extractor": "~0.0.0",
|
|
34
34
|
"@osdk/monorepo.tsconfig": "~0.0.0",
|
package/build/cjs/index.cjs
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var consola = require('consola');
|
|
6
|
-
var fs = require('fs/promises');
|
|
7
|
-
var path = require('path');
|
|
8
|
-
var yargs = require('yargs');
|
|
9
|
-
var helpers = require('yargs/helpers');
|
|
10
|
-
var invariant2 = require('tiny-invariant');
|
|
11
|
-
|
|
12
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
|
|
14
|
-
function _interopNamespace(e) {
|
|
15
|
-
if (e && e.__esModule) return e;
|
|
16
|
-
var n = Object.create(null);
|
|
17
|
-
if (e) {
|
|
18
|
-
Object.keys(e).forEach(function (k) {
|
|
19
|
-
if (k !== 'default') {
|
|
20
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () { return e[k]; }
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
n.default = e;
|
|
29
|
-
return Object.freeze(n);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
33
|
-
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
34
|
-
var yargs__default = /*#__PURE__*/_interopDefault(yargs);
|
|
35
|
-
var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
|
|
36
|
-
|
|
37
|
-
// src/cli/main.ts
|
|
38
|
-
|
|
39
|
-
// src/api/defineOntology.ts
|
|
40
|
-
var ontologyDefinition;
|
|
41
|
-
async function defineOntology(ns, body) {
|
|
42
|
-
ontologyDefinition = {
|
|
43
|
-
actionTypes: {},
|
|
44
|
-
objectTypes: {},
|
|
45
|
-
queryTypes: {},
|
|
46
|
-
interfaceTypes: {},
|
|
47
|
-
sharedPropertyTypes: {}
|
|
48
|
-
};
|
|
49
|
-
try {
|
|
50
|
-
await body();
|
|
51
|
-
} catch (e) {
|
|
52
|
-
console.error("Unexpected error while processing the body of the ontology", e);
|
|
53
|
-
throw e;
|
|
54
|
-
}
|
|
55
|
-
return convertToWireOntology(ontologyDefinition);
|
|
56
|
-
}
|
|
57
|
-
function convertToWireOntology(ontology) {
|
|
58
|
-
return {
|
|
59
|
-
sharedPropertyTypes: Object.fromEntries(Object.entries(ontology.sharedPropertyTypes).map(([apiName, spt]) => [apiName, {
|
|
60
|
-
sharedPropertyType: convertSpt(spt)
|
|
61
|
-
}])),
|
|
62
|
-
interfaceTypes: Object.fromEntries(Object.entries(ontology.interfaceTypes).map(([apiName, interfaceType]) => {
|
|
63
|
-
return [apiName, {
|
|
64
|
-
interfaceType: convertInterface(interfaceType)
|
|
65
|
-
}];
|
|
66
|
-
})),
|
|
67
|
-
blockPermissionInformation: {
|
|
68
|
-
actionTypes: {},
|
|
69
|
-
linkTypes: {},
|
|
70
|
-
objectTypes: {}
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
function convertInterface(interfaceType) {
|
|
75
|
-
return {
|
|
76
|
-
...interfaceType,
|
|
77
|
-
properties: Object.values(interfaceType.properties).map((spt) => convertSpt(spt)),
|
|
78
|
-
// these are omitted from our internal types but we need to re-add them for the final json
|
|
79
|
-
allExtendsInterfaces: [],
|
|
80
|
-
allLinks: [],
|
|
81
|
-
allProperties: []
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function convertSpt({
|
|
85
|
-
type,
|
|
86
|
-
array,
|
|
87
|
-
description,
|
|
88
|
-
apiName,
|
|
89
|
-
displayName
|
|
90
|
-
}) {
|
|
91
|
-
return {
|
|
92
|
-
apiName,
|
|
93
|
-
displayMetadata: {
|
|
94
|
-
displayName: displayName ?? apiName,
|
|
95
|
-
visibility: "NORMAL",
|
|
96
|
-
description
|
|
97
|
-
},
|
|
98
|
-
type: array ? {
|
|
99
|
-
type: "array",
|
|
100
|
-
array: {
|
|
101
|
-
subtype: convertType(type)
|
|
102
|
-
}
|
|
103
|
-
} : convertType(type),
|
|
104
|
-
aliases: [],
|
|
105
|
-
baseFormatter: void 0,
|
|
106
|
-
dataConstraints: void 0,
|
|
107
|
-
gothamMapping: void 0,
|
|
108
|
-
indexedForSearch: true,
|
|
109
|
-
provenance: void 0,
|
|
110
|
-
typeClasses: [],
|
|
111
|
-
valueType: void 0
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
function convertType(type) {
|
|
115
|
-
switch (type) {
|
|
116
|
-
case "marking":
|
|
117
|
-
return {
|
|
118
|
-
type,
|
|
119
|
-
[type]: {
|
|
120
|
-
markingType: "MANDATORY"
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
case "geopoint":
|
|
124
|
-
return {
|
|
125
|
-
type: "geohash",
|
|
126
|
-
geohash: {}
|
|
127
|
-
};
|
|
128
|
-
case "decimal":
|
|
129
|
-
return {
|
|
130
|
-
type,
|
|
131
|
-
[type]: {
|
|
132
|
-
precision: void 0,
|
|
133
|
-
scale: void 0
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
case "string":
|
|
137
|
-
return {
|
|
138
|
-
type,
|
|
139
|
-
[type]: {
|
|
140
|
-
analyzerOverride: void 0,
|
|
141
|
-
enableAsciiFolding: void 0,
|
|
142
|
-
isLongText: false,
|
|
143
|
-
supportsExactMatching: true
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
default:
|
|
147
|
-
return distributeTypeHelper(type);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
function distributeTypeHelper(type) {
|
|
151
|
-
return {
|
|
152
|
-
type,
|
|
153
|
-
[type]: {}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
function defineSharedPropertyType(opts) {
|
|
157
|
-
const {
|
|
158
|
-
apiName
|
|
159
|
-
} = opts;
|
|
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
|
-
return ontologyDefinition.sharedPropertyTypes[apiName] = {
|
|
162
|
-
...opts
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// src/api/defineInterface.ts
|
|
167
|
-
function defineInterface(opts) {
|
|
168
|
-
const {
|
|
169
|
-
apiName
|
|
170
|
-
} = opts;
|
|
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
|
-
const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
|
|
173
|
-
if (typeof type === "string") {
|
|
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
|
-
const spt = defineSharedPropertyType({
|
|
176
|
-
apiName: apiName2,
|
|
177
|
-
displayName: apiName2,
|
|
178
|
-
type,
|
|
179
|
-
array: false
|
|
180
|
-
});
|
|
181
|
-
return [apiName2, spt];
|
|
182
|
-
} else {
|
|
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
|
-
key: apiName2,
|
|
185
|
-
apiName: type.apiName
|
|
186
|
-
})}`) : invariant2__default.default(false) : void 0;
|
|
187
|
-
return [apiName2, type];
|
|
188
|
-
}
|
|
189
|
-
}));
|
|
190
|
-
const a = {
|
|
191
|
-
apiName,
|
|
192
|
-
displayMetadata: {
|
|
193
|
-
displayName: opts.displayName ?? apiName,
|
|
194
|
-
description: opts.description ?? opts.displayName ?? apiName,
|
|
195
|
-
icon: void 0
|
|
196
|
-
},
|
|
197
|
-
extendsInterfaces: [],
|
|
198
|
-
links: [],
|
|
199
|
-
properties,
|
|
200
|
-
status: {
|
|
201
|
-
type: "active",
|
|
202
|
-
active: {}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
return ontologyDefinition.interfaceTypes[apiName] = a;
|
|
206
|
-
}
|
|
207
|
-
function isSimpleType(v) {
|
|
208
|
-
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";
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// src/cli/main.ts
|
|
212
|
-
async function main(args = process.argv) {
|
|
213
|
-
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.7.1").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
|
|
214
|
-
input: {
|
|
215
|
-
alias: "i",
|
|
216
|
-
describe: "Input file",
|
|
217
|
-
type: "string",
|
|
218
|
-
default: ".ontology/ontology.ts",
|
|
219
|
-
coerce: path__namespace.resolve
|
|
220
|
-
},
|
|
221
|
-
output: {
|
|
222
|
-
alias: "o",
|
|
223
|
-
describe: "Output file",
|
|
224
|
-
type: "string",
|
|
225
|
-
default: "ontology.json",
|
|
226
|
-
coerce: path__namespace.resolve
|
|
227
|
-
},
|
|
228
|
-
snapshotDir: {
|
|
229
|
-
alias: "s",
|
|
230
|
-
describe: "Snapshot directory",
|
|
231
|
-
type: "string",
|
|
232
|
-
default: "snapshots",
|
|
233
|
-
coerce: path__namespace.resolve
|
|
234
|
-
}
|
|
235
|
-
}).parseAsync();
|
|
236
|
-
consola.consola.info(`Loading ontology from ${commandLineOpts.input}`);
|
|
237
|
-
const ontology = await loadOntology(commandLineOpts.input);
|
|
238
|
-
consola.consola.info(`Saving ontology to ${commandLineOpts.output}`);
|
|
239
|
-
await fs__namespace.writeFile(commandLineOpts.output, JSON.stringify(ontology, null, 2));
|
|
240
|
-
}
|
|
241
|
-
async function loadOntology(input) {
|
|
242
|
-
const q = await defineOntology("", async () => await import(input));
|
|
243
|
-
return q;
|
|
244
|
-
}
|
|
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),
|
|
251
|
-
metadata: fromLinkMeta,
|
|
252
|
-
required: true
|
|
253
|
-
// TODO: expose this?
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
function getLinkedType(t) {
|
|
257
|
-
return {
|
|
258
|
-
type: "interfaceType",
|
|
259
|
-
interfaceType: typeof t === "string" ? t : t.apiName
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
function getLinkMeta(meta) {
|
|
263
|
-
return typeof meta === "string" ? withDefaults({
|
|
264
|
-
apiName: meta
|
|
265
|
-
}) : withDefaults(meta);
|
|
266
|
-
}
|
|
267
|
-
function withDefaults({
|
|
268
|
-
apiName,
|
|
269
|
-
description,
|
|
270
|
-
displayName
|
|
271
|
-
}) {
|
|
272
|
-
return {
|
|
273
|
-
apiName,
|
|
274
|
-
displayName: displayName ?? apiName,
|
|
275
|
-
description: description ?? displayName ?? apiName
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
exports.default = main;
|
|
280
|
-
exports.defineInterface = defineInterface;
|
|
281
|
-
exports.defineInterfaceLinkConstraint = defineInterfaceLinkConstraint;
|
|
282
|
-
exports.defineSharedPropertyType = defineSharedPropertyType;
|
|
283
|
-
//# sourceMappingURL=index.cjs.map
|
|
284
|
-
//# sourceMappingURL=index.cjs.map
|
package/build/cjs/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineInterface.ts","../../src/cli/main.ts","../../src/api/defineInterfaceLinkConstraint.ts"],"names":["invariant","apiName","yargs","hideBin","path","consola","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBO,IAAI,kBAAA,CAAA;AAIX,eAAsB,cAAA,CAAe,IAAI,IAAM,EAAA;AAE7C,EAAqB,kBAAA,GAAA;AAAA,IACnB,aAAa,EAAC;AAAA,IACd,aAAa,EAAC;AAAA,IACd,YAAY,EAAC;AAAA,IACb,gBAAgB,EAAC;AAAA,IACjB,qBAAqB,EAAC;AAAA,GACxB,CAAA;AACA,EAAI,IAAA;AACF,IAAA,MAAM,IAAK,EAAA,CAAA;AAAA,WACJ,CAAG,EAAA;AAEV,IAAQ,OAAA,CAAA,KAAA,CAAM,8DAA8D,CAAC,CAAA,CAAA;AAC7E,IAAM,MAAA,CAAA,CAAA;AAAA,GACR;AACA,EAAA,OAAO,sBAAsB,kBAAkB,CAAA,CAAA;AACjD,CAAA;AACA,SAAS,sBAAsB,QAAU,EAAA;AACvC,EAAO,OAAA;AAAA,IACL,mBAAqB,EAAA,MAAA,CAAO,WAAY,CAAA,MAAA,CAAO,QAAQ,QAAS,CAAA,mBAAmB,CAAE,CAAA,GAAA,CAAI,CAAC,CAAC,OAAA,EAAS,GAAG,CA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AA,CAAK,MAAM,IAAK,CAAA;AAAA,IACtB,WAAA,EAAa,OAAQ,CAAA,MAAA,GAAS,MAAS,GAAA,QAAA;AAAA,IACvC,kBAAoB,EAAA,aAAA,CAAc,OAAQ,CAAA,MAAA,IAAU,QAAQ,KAAK,CAAA;AAAA,IACjE,QAAU,EAAA,YAAA;AAAA,IACV,QAAU,EAAA,IAAA;AAAA;AAAA,GACX,CAAA,CAAA;AACH,CAAA;AACA,SAAS,cAAc,CAAG,EAAA;AACxB,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,eAAA;AAAA,IACN,aAAe,EAAA,OAAO,CAAM,KAAA,QAAA,GAAW,IAAI,CAAE,CAAA,OAAA;AAAA,GAC/C,CAAA;AACF,CAAA;AACA,SAAS,YAAY,IAAM,EAAA;AACzB,EAAO,OAAA,OAAO,IAAS,KAAA,QAAA,GAAW,YAAa,CAAA;AAAA,IAC7C,OAAS,EAAA,IAAA;AAAA,GACV,CAAI,GAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AACxB,CAAA;AACA,SAAS,YAAa,CAAA;AAAA,EACpB,OAAA;AAAA,EACA,WAAA;AAAA,EACA,WAAA;AACF,CAAG,EAAA;AACD,EAAO,OAAA;AAAA,IACL,OAAA;AAAA,IACA,aAAa,WAAe,IAAA,OAAA;AAAA,IAC5B,WAAA,EAAa,eAAe,WAAe,IAAA,OAAA;AAAA,GAC7C,CAAA;AACF","file":"index.cjs","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** @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\";\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\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\";\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}"]}
|