@osdk/maker 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/maker.mjs +6 -0
- package/build/js/index.cjs +136 -0
- package/build/js/index.cjs.map +1 -0
- package/build/js/index.mjs +106 -0
- package/build/js/index.mjs.map +1 -0
- package/build/types/api/defineInterface.d.ts +17 -0
- package/build/types/api/defineInterface.d.ts.map +1 -0
- package/build/types/api/defineLink.d.ts +18 -0
- package/build/types/api/defineLink.d.ts.map +1 -0
- package/build/types/api/defineObject.d.ts +15 -0
- package/build/types/api/defineObject.d.ts.map +1 -0
- package/build/types/api/defineOntology.d.ts +9 -0
- package/build/types/api/defineOntology.d.ts.map +1 -0
- package/build/types/api/defineSpt.d.ts +8 -0
- package/build/types/api/defineSpt.d.ts.map +1 -0
- package/build/types/api/overall.test.d.ts +2 -0
- package/build/types/api/overall.test.d.ts.map +1 -0
- package/build/types/api/types.d.ts +19 -0
- package/build/types/api/types.d.ts.map +1 -0
- package/build/types/cli/main.d.ts +2 -0
- package/build/types/cli/main.d.ts.map +1 -0
- package/build/types/index.d.ts +4 -0
- package/build/types/index.d.ts.map +1 -0
- package/changelog/@unreleased/pr-136.v2.yml +5 -0
- package/package.json +60 -0
package/bin/maker.mjs
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
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 yargs__default = /*#__PURE__*/_interopDefault(yargs);
|
|
34
|
+
var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
|
|
35
|
+
|
|
36
|
+
// src/cli/main.ts
|
|
37
|
+
|
|
38
|
+
// src/api/defineOntology.ts
|
|
39
|
+
var ontologyDefinition;
|
|
40
|
+
async function defineOntology(ns, body) {
|
|
41
|
+
ontologyDefinition = {
|
|
42
|
+
actionTypes: {},
|
|
43
|
+
interfaceTypes: {},
|
|
44
|
+
objectTypes: {},
|
|
45
|
+
queryTypes: {},
|
|
46
|
+
sharedPropertyTypes: {}
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
await body();
|
|
50
|
+
} catch (e) {
|
|
51
|
+
console.error("Unexpected error while processing the body of the ontology", e);
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
return ontologyDefinition;
|
|
55
|
+
}
|
|
56
|
+
function defineSharedPropertyType(apiName, opts) {
|
|
57
|
+
!(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;
|
|
58
|
+
return ontologyDefinition.sharedPropertyTypes[apiName] = {
|
|
59
|
+
apiName,
|
|
60
|
+
...opts
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/api/defineInterface.ts
|
|
65
|
+
function defineInterface(apiName, opts) {
|
|
66
|
+
!(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `Interface ${apiName} already exists`) : invariant2__default.default(false) : void 0;
|
|
67
|
+
const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
|
|
68
|
+
if (typeof type === "string") {
|
|
69
|
+
!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;
|
|
70
|
+
const spt = defineSharedPropertyType(apiName2, {
|
|
71
|
+
displayName: apiName2,
|
|
72
|
+
type,
|
|
73
|
+
array: false
|
|
74
|
+
});
|
|
75
|
+
return [apiName2, spt];
|
|
76
|
+
} else {
|
|
77
|
+
!(apiName2 === type.apiName) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, `property key and it's apiName must be identical. ${JSON.stringify({
|
|
78
|
+
key: apiName2,
|
|
79
|
+
apiName: type.apiName
|
|
80
|
+
})}`) : invariant2__default.default(false) : void 0;
|
|
81
|
+
return [apiName2, type];
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
return ontologyDefinition.interfaceTypes[apiName] = {
|
|
85
|
+
apiName,
|
|
86
|
+
displayName: opts.displayName ?? apiName,
|
|
87
|
+
extendsInterfaces: [],
|
|
88
|
+
links: {},
|
|
89
|
+
properties,
|
|
90
|
+
rid: "",
|
|
91
|
+
description: opts.description ?? opts.displayName ?? apiName
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function isSimpleType(v) {
|
|
95
|
+
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";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/cli/main.ts
|
|
99
|
+
async function main(args = process.argv) {
|
|
100
|
+
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.0.0").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
|
|
101
|
+
input: {
|
|
102
|
+
alias: "i",
|
|
103
|
+
describe: "Input file",
|
|
104
|
+
type: "string",
|
|
105
|
+
default: ".ontology/ontology.ts"
|
|
106
|
+
},
|
|
107
|
+
output: {
|
|
108
|
+
alias: "o",
|
|
109
|
+
describe: "Output file",
|
|
110
|
+
type: "string",
|
|
111
|
+
default: "ontology.json"
|
|
112
|
+
},
|
|
113
|
+
snapshotDir: {
|
|
114
|
+
alias: "s",
|
|
115
|
+
describe: "Snapshot directory",
|
|
116
|
+
type: "string",
|
|
117
|
+
default: "snapshots"
|
|
118
|
+
}
|
|
119
|
+
}).parseAsync();
|
|
120
|
+
const fullInputPath = path.join(process.cwd(), commandLineOpts.input);
|
|
121
|
+
const fullOutputPath = path.join(process.cwd(), commandLineOpts.output);
|
|
122
|
+
consola.consola.info(`Loading ontology from ${fullInputPath}`);
|
|
123
|
+
const ontology = await loadOntology(fullInputPath);
|
|
124
|
+
consola.consola.info(`Saving ontology to ${fullOutputPath}`);
|
|
125
|
+
fs__namespace.writeFile(fullOutputPath, JSON.stringify(ontology, null, 2));
|
|
126
|
+
}
|
|
127
|
+
async function loadOntology(input) {
|
|
128
|
+
const q = await defineOntology("", async () => await import(input));
|
|
129
|
+
return q;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
exports.default = main;
|
|
133
|
+
exports.defineInterface = defineInterface;
|
|
134
|
+
exports.defineSharedPropertyType = defineSharedPropertyType;
|
|
135
|
+
//# sourceMappingURL=out.js.map
|
|
136
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/define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,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,IACA,aAAa;AAAA,MACX,OAAO;AAAA,MACP,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA,EACF,CAAC,EAAE,WAAW;AACd,QAAM,gBAAgB,KAAK,QAAQ,IAAI,GAAG,gBAAgB,KAAK;AAC/D,QAAM,iBAAiB,KAAK,QAAQ,IAAI,GAAG,gBAAgB,MAAM;AACjE,UAAQ,KAAK,yBAAyB,aAAa,EAAE;AACrD,QAAM,WAAW,MAAM,aAAa,aAAa;AACjD,UAAQ,KAAK,sBAAsB,cAAc,EAAE;AACnD,EAAG,aAAU,gBAAgB,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAChE;AAmCA,eAAe,aAAa,OAAO;AAQjC,QAAM,IAAI,MAAM,eAAe,IAAI,YAAY,MAAM,OAAO,MAAM;AAClE,SAAO;AACT","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport { join } 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 },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\"\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\"\n }\n }).parseAsync();\n const fullInputPath = join(process.cwd(), commandLineOpts.input);\n const fullOutputPath = join(process.cwd(), commandLineOpts.output);\n consola.info(`Loading ontology from ${fullInputPath}`);\n const ontology = await loadOntology(fullInputPath);\n consola.info(`Saving ontology to ${fullOutputPath}`);\n fs.writeFile(fullOutputPath, 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 fullPath = join(process.cwd(), input);\n const q = await import(fullPath);\n return q;\n}\nasync function loadOntology(input) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(\"\", async () => await import(input));\n return q;\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nimport { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(apiName, opts) {\n !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n !isSimpleType(type) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;\n // switch (v) {\n // case \"boolean\":\n // case \"byte\":\n // case \"date\":\n // case \"float\":\n // case \"geopoint\":\n // case \"geoshape\":\n // case \"integer\":\n // case \"decimal\":\n // case \"double\":\n // case \"long\":\n // case \"short\":\n // case \"string\":\n // case \"timestamp\":\n // return [\n // k,\n // {\n // rid: \"idk\",\n // apiName: k,\n // displayName: k,\n // dataType: {\n // type: v,\n // },\n // } satisfies SharedPropertyType,\n // ];\n // }\n\n const spt = defineSharedPropertyType(apiName, {\n displayName: apiName,\n type,\n array: false\n });\n return [apiName, spt];\n } else {\n !(apiName === type.apiName) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({\n key: apiName,\n apiName: type.apiName\n })}`) : invariant(false) : void 0;\n return [apiName, type];\n }\n }));\n return ontologyDefinition.interfaceTypes[apiName] = {\n apiName,\n displayName: opts.displayName ?? apiName,\n extendsInterfaces: [],\n links: {},\n properties,\n rid: \"\",\n description: opts.description ?? opts.displayName ?? apiName\n };\n}\nfunction isSimpleType(v) {\n return v === \"boolean\" || v === \"byte\" || v === \"date\" || v === \"decimal\" || v === \"double\" || v === \"float\" || v === \"geopoint\" || v === \"geoshape\" || v === \"integer\" || v === \"long\" || v === \"marking\" || v === \"short\" || v === \"string\" || v === \"timestamp\";\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** @internal */\nexport let ontologyDefinition;\n\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n interfaceTypes: {},\n objectTypes: {},\n queryTypes: {},\n sharedPropertyTypes: {}\n };\n try {\n await body();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return ontologyDefinition;\n}\nexport function dumpOntologyFullMetadata() {\n return {\n ontology: {\n apiName: \"IDK\",\n description: \"IDK\",\n displayName: \"IDK\",\n rid: \"IDK\"\n },\n ...ontologyDefinition,\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontologyDefinition.sharedPropertyTypes).map(([apiName, spt]) => [apiName, convertSpt(spt)])),\n interfaceTypes: Object.fromEntries(Object.entries(ontologyDefinition.interfaceTypes).map(([apiName, {\n displayName,\n description,\n properties\n }]) => {\n return [apiName, {\n rid: \"IDK\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n extendsInterfaces: [],\n links: {},\n properties: Object.fromEntries(Object.entries(properties).map(([apiName, spt]) => [apiName, convertSpt(spt)]))\n }];\n }))\n };\n}\nfunction convertSpt({\n type,\n array,\n description,\n apiName,\n displayName\n}) {\n return {\n rid: \"IDK\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n dataType: array ? {\n type: \"array\",\n subType: {\n type\n }\n } : {\n type\n }\n };\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nexport function defineSharedPropertyType(apiName, opts) {\n !(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n apiName,\n ...opts\n };\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nexport function defineLink(from, opts) {\n const apiName = opts.one ?? opts.many;\n const toApiName = opts.reverse.one ?? opts.reverse.many;\n const to = opts.to;\n !(from.linkTypes[apiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${apiName} already exists on ${from.data.objectType.apiName}`) : invariant(false) : void 0;\n !(from.linkTypes[toApiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toApiName} already exists on ${to.data.objectType.apiName}`) : invariant(false) : void 0;\n from.linkTypes[apiName] = {\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: to.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n to.linkTypes[toApiName] = {\n apiName: toApiName,\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: from.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nexport function defineObject(apiName, opts) {\n ontologyDefinition.objectTypes[apiName] = {\n implementsInterfaces: [],\n linkTypes: [],\n objectType: {\n apiName,\n primaryKey: opts.primaryKey.apiName,\n properties: {\n [opts.primaryKey.apiName]: {\n dataType: convertType(opts.primaryKey)\n }\n },\n rid: \"PLACEHOLDER\",\n status: \"ACTIVE\",\n titleProperty: opts.primaryKey.apiName\n },\n sharedPropertyTypeMapping: {}\n };\n\n // FIXME: dont return the raw value\n return {\n data: ontologyDefinition.objectTypes[apiName],\n linkTypes: {}\n };\n}\nfunction convertType(t) {\n switch (true) {\n case t.multiplicity === true:\n return {\n type: \"array\",\n subType: convertType({\n ...t,\n multiplicity: false\n })\n };\n case t.type === \"stringTimeseries\":\n return {\n itemType: {\n type: \"string\"\n },\n type: \"timeseries\"\n };\n break;\n case t.type === \"numericTimeseries\":\n return {\n itemType: {\n type: \"double\"\n },\n type: \"timeseries\"\n };\n case t.type === \"datetime\":\n return {\n type: \"timestamp\"\n };\n default:\n return {\n type: t.type\n };\n }\n !false ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n}"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { consola } from 'consola';
|
|
2
|
+
import * as fs from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import yargs from 'yargs';
|
|
5
|
+
import { hideBin } from 'yargs/helpers';
|
|
6
|
+
import invariant2 from 'tiny-invariant';
|
|
7
|
+
|
|
8
|
+
// src/cli/main.ts
|
|
9
|
+
|
|
10
|
+
// src/api/defineOntology.ts
|
|
11
|
+
var ontologyDefinition;
|
|
12
|
+
async function defineOntology(ns, body) {
|
|
13
|
+
ontologyDefinition = {
|
|
14
|
+
actionTypes: {},
|
|
15
|
+
interfaceTypes: {},
|
|
16
|
+
objectTypes: {},
|
|
17
|
+
queryTypes: {},
|
|
18
|
+
sharedPropertyTypes: {}
|
|
19
|
+
};
|
|
20
|
+
try {
|
|
21
|
+
await body();
|
|
22
|
+
} catch (e) {
|
|
23
|
+
console.error("Unexpected error while processing the body of the ontology", e);
|
|
24
|
+
throw e;
|
|
25
|
+
}
|
|
26
|
+
return ontologyDefinition;
|
|
27
|
+
}
|
|
28
|
+
function defineSharedPropertyType(apiName, opts) {
|
|
29
|
+
!(ontologyDefinition.sharedPropertyTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Shared property type ${apiName} already exists`) : invariant2(false) : void 0;
|
|
30
|
+
return ontologyDefinition.sharedPropertyTypes[apiName] = {
|
|
31
|
+
apiName,
|
|
32
|
+
...opts
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/api/defineInterface.ts
|
|
37
|
+
function defineInterface(apiName, opts) {
|
|
38
|
+
!(ontologyDefinition.interfaceTypes[apiName] === void 0) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Interface ${apiName} already exists`) : invariant2(false) : void 0;
|
|
39
|
+
const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName2, type]) => {
|
|
40
|
+
if (typeof type === "string") {
|
|
41
|
+
!isSimpleType(type) ? process.env.NODE_ENV !== "production" ? invariant2(false, `Invalid data type ${type} for property ${apiName2} on InterfaceType ${apiName2}`) : invariant2(false) : void 0;
|
|
42
|
+
const spt = defineSharedPropertyType(apiName2, {
|
|
43
|
+
displayName: apiName2,
|
|
44
|
+
type,
|
|
45
|
+
array: false
|
|
46
|
+
});
|
|
47
|
+
return [apiName2, spt];
|
|
48
|
+
} else {
|
|
49
|
+
!(apiName2 === type.apiName) ? process.env.NODE_ENV !== "production" ? invariant2(false, `property key and it's apiName must be identical. ${JSON.stringify({
|
|
50
|
+
key: apiName2,
|
|
51
|
+
apiName: type.apiName
|
|
52
|
+
})}`) : invariant2(false) : void 0;
|
|
53
|
+
return [apiName2, type];
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
return ontologyDefinition.interfaceTypes[apiName] = {
|
|
57
|
+
apiName,
|
|
58
|
+
displayName: opts.displayName ?? apiName,
|
|
59
|
+
extendsInterfaces: [],
|
|
60
|
+
links: {},
|
|
61
|
+
properties,
|
|
62
|
+
rid: "",
|
|
63
|
+
description: opts.description ?? opts.displayName ?? apiName
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function isSimpleType(v) {
|
|
67
|
+
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";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/cli/main.ts
|
|
71
|
+
async function main(args = process.argv) {
|
|
72
|
+
const commandLineOpts = await yargs(hideBin(args)).version("0.0.0").wrap(Math.min(150, yargs().terminalWidth())).strict().help().options({
|
|
73
|
+
input: {
|
|
74
|
+
alias: "i",
|
|
75
|
+
describe: "Input file",
|
|
76
|
+
type: "string",
|
|
77
|
+
default: ".ontology/ontology.ts"
|
|
78
|
+
},
|
|
79
|
+
output: {
|
|
80
|
+
alias: "o",
|
|
81
|
+
describe: "Output file",
|
|
82
|
+
type: "string",
|
|
83
|
+
default: "ontology.json"
|
|
84
|
+
},
|
|
85
|
+
snapshotDir: {
|
|
86
|
+
alias: "s",
|
|
87
|
+
describe: "Snapshot directory",
|
|
88
|
+
type: "string",
|
|
89
|
+
default: "snapshots"
|
|
90
|
+
}
|
|
91
|
+
}).parseAsync();
|
|
92
|
+
const fullInputPath = join(process.cwd(), commandLineOpts.input);
|
|
93
|
+
const fullOutputPath = join(process.cwd(), commandLineOpts.output);
|
|
94
|
+
consola.info(`Loading ontology from ${fullInputPath}`);
|
|
95
|
+
const ontology = await loadOntology(fullInputPath);
|
|
96
|
+
consola.info(`Saving ontology to ${fullOutputPath}`);
|
|
97
|
+
fs.writeFile(fullOutputPath, JSON.stringify(ontology, null, 2));
|
|
98
|
+
}
|
|
99
|
+
async function loadOntology(input) {
|
|
100
|
+
const q = await defineOntology("", async () => await import(input));
|
|
101
|
+
return q;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { main as default, defineInterface, defineSharedPropertyType };
|
|
105
|
+
//# sourceMappingURL=out.js.map
|
|
106
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/cli/main.ts","../../src/api/defineInterface.ts","../../src/api/defineOntology.ts","../../src/api/defineSpt.ts","../../src/api/defineLink.ts","../../src/api/defineObject.ts"],"names":["invariant","apiName"],"mappings":";AAgBA,SAAS,eAAe;AACxB,YAAY,QAAQ;AACpB,SAAS,YAAY;AACrB,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACJxB,OAAOA,gBAAe;;;ACCf,IAAI;AAGJ,IAAI;AACX,eAAsB,eAAe,IAAI,MAAM;AAC7C,cAAY;AACZ,uBAAqB;AAAA,IACnB,aAAa,CAAC;AAAA,IACd,gBAAgB,CAAC;AAAA,IACjB,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,qBAAqB,CAAC;AAAA,EACxB;AACA,MAAI;AACF,UAAM,KAAK;AAAA,EACb,SAAS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UAAU,UAAU,MAAM,CAAC,CAAC;AAChE;AAmCA,eAAe,aAAa,OAAO;AAQjC,QAAM,IAAI,MAAM,eAAe,IAAI,YAAY,MAAM,OAAO,MAAM;AAClE,SAAO;AACT","sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { consola } from \"consola\";\nimport * as fs from \"node:fs/promises\";\nimport { join } 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 },\n output: {\n alias: \"o\",\n describe: \"Output file\",\n type: \"string\",\n default: \"ontology.json\"\n },\n snapshotDir: {\n alias: \"s\",\n describe: \"Snapshot directory\",\n type: \"string\",\n default: \"snapshots\"\n }\n }).parseAsync();\n const fullInputPath = join(process.cwd(), commandLineOpts.input);\n const fullOutputPath = join(process.cwd(), commandLineOpts.output);\n consola.info(`Loading ontology from ${fullInputPath}`);\n const ontology = await loadOntology(fullInputPath);\n consola.info(`Saving ontology to ${fullOutputPath}`);\n fs.writeFile(fullOutputPath, 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 fullPath = join(process.cwd(), input);\n const q = await import(fullPath);\n return q;\n}\nasync function loadOntology(input) {\n // Object.assign(globalThis, {\n // defineInterface,\n // defineLink,\n // defineObject,\n // defineSharedPropertyType,\n // });\n\n const q = await defineOntology(\"\", async () => await import(input));\n return q;\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nimport { defineSharedPropertyType } from \"./defineSpt.js\";\nexport function defineInterface(apiName, opts) {\n !(ontologyDefinition.interfaceTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Interface ${apiName} already exists`) : invariant(false) : void 0;\n const properties = Object.fromEntries(Object.entries(opts.properties ?? {}).map(([apiName, type]) => {\n if (typeof type === \"string\") {\n !isSimpleType(type) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Invalid data type ${type} for property ${apiName} on InterfaceType ${apiName}`) : invariant(false) : void 0;\n // switch (v) {\n // case \"boolean\":\n // case \"byte\":\n // case \"date\":\n // case \"float\":\n // case \"geopoint\":\n // case \"geoshape\":\n // case \"integer\":\n // case \"decimal\":\n // case \"double\":\n // case \"long\":\n // case \"short\":\n // case \"string\":\n // case \"timestamp\":\n // return [\n // k,\n // {\n // rid: \"idk\",\n // apiName: k,\n // displayName: k,\n // dataType: {\n // type: v,\n // },\n // } satisfies SharedPropertyType,\n // ];\n // }\n\n const spt = defineSharedPropertyType(apiName, {\n displayName: apiName,\n type,\n array: false\n });\n return [apiName, spt];\n } else {\n !(apiName === type.apiName) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `property key and it's apiName must be identical. ${JSON.stringify({\n key: apiName,\n apiName: type.apiName\n })}`) : invariant(false) : void 0;\n return [apiName, type];\n }\n }));\n return ontologyDefinition.interfaceTypes[apiName] = {\n apiName,\n displayName: opts.displayName ?? apiName,\n extendsInterfaces: [],\n links: {},\n properties,\n rid: \"\",\n description: opts.description ?? opts.displayName ?? apiName\n };\n}\nfunction isSimpleType(v) {\n return v === \"boolean\" || v === \"byte\" || v === \"date\" || v === \"decimal\" || v === \"double\" || v === \"float\" || v === \"geopoint\" || v === \"geoshape\" || v === \"integer\" || v === \"long\" || v === \"marking\" || v === \"short\" || v === \"string\" || v === \"timestamp\";\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/** @internal */\nexport let ontologyDefinition;\n\n/** @internal */\nexport let namespace;\nexport async function defineOntology(ns, body) {\n namespace = ns;\n ontologyDefinition = {\n actionTypes: {},\n interfaceTypes: {},\n objectTypes: {},\n queryTypes: {},\n sharedPropertyTypes: {}\n };\n try {\n await body();\n } catch (e) {\n // eslint-disable-next-line no-console\n console.error(\"Unexpected error while processing the body of the ontology\", e);\n throw e;\n }\n return ontologyDefinition;\n}\nexport function dumpOntologyFullMetadata() {\n return {\n ontology: {\n apiName: \"IDK\",\n description: \"IDK\",\n displayName: \"IDK\",\n rid: \"IDK\"\n },\n ...ontologyDefinition,\n sharedPropertyTypes: Object.fromEntries(Object.entries(ontologyDefinition.sharedPropertyTypes).map(([apiName, spt]) => [apiName, convertSpt(spt)])),\n interfaceTypes: Object.fromEntries(Object.entries(ontologyDefinition.interfaceTypes).map(([apiName, {\n displayName,\n description,\n properties\n }]) => {\n return [apiName, {\n rid: \"IDK\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n extendsInterfaces: [],\n links: {},\n properties: Object.fromEntries(Object.entries(properties).map(([apiName, spt]) => [apiName, convertSpt(spt)]))\n }];\n }))\n };\n}\nfunction convertSpt({\n type,\n array,\n description,\n apiName,\n displayName\n}) {\n return {\n rid: \"IDK\",\n apiName,\n displayName: displayName ?? apiName,\n description,\n dataType: array ? {\n type: \"array\",\n subType: {\n type\n }\n } : {\n type\n }\n };\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nexport function defineSharedPropertyType(apiName, opts) {\n !(ontologyDefinition.sharedPropertyTypes[apiName] === undefined) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Shared property type ${apiName} already exists`) : invariant(false) : void 0;\n return ontologyDefinition.sharedPropertyTypes[apiName] = {\n apiName,\n ...opts\n };\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nexport function defineLink(from, opts) {\n const apiName = opts.one ?? opts.many;\n const toApiName = opts.reverse.one ?? opts.reverse.many;\n const to = opts.to;\n !(from.linkTypes[apiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${apiName} already exists on ${from.data.objectType.apiName}`) : invariant(false) : void 0;\n !(from.linkTypes[toApiName] == null) ? process.env.NODE_ENV !== \"production\" ? invariant(false, `Link with apiName ${toApiName} already exists on ${to.data.objectType.apiName}`) : invariant(false) : void 0;\n from.linkTypes[apiName] = {\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: to.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n to.linkTypes[toApiName] = {\n apiName: toApiName,\n cardinality: \"ONE\",\n displayName: apiName,\n objectTypeApiName: from.data.objectType.apiName,\n status: \"ACTIVE\"\n };\n}","/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport invariant from \"tiny-invariant\";\nimport { ontologyDefinition } from \"./defineOntology.js\";\nexport function defineObject(apiName, opts) {\n ontologyDefinition.objectTypes[apiName] = {\n implementsInterfaces: [],\n linkTypes: [],\n objectType: {\n apiName,\n primaryKey: opts.primaryKey.apiName,\n properties: {\n [opts.primaryKey.apiName]: {\n dataType: convertType(opts.primaryKey)\n }\n },\n rid: \"PLACEHOLDER\",\n status: \"ACTIVE\",\n titleProperty: opts.primaryKey.apiName\n },\n sharedPropertyTypeMapping: {}\n };\n\n // FIXME: dont return the raw value\n return {\n data: ontologyDefinition.objectTypes[apiName],\n linkTypes: {}\n };\n}\nfunction convertType(t) {\n switch (true) {\n case t.multiplicity === true:\n return {\n type: \"array\",\n subType: convertType({\n ...t,\n multiplicity: false\n })\n };\n case t.type === \"stringTimeseries\":\n return {\n itemType: {\n type: \"string\"\n },\n type: \"timeseries\"\n };\n break;\n case t.type === \"numericTimeseries\":\n return {\n itemType: {\n type: \"double\"\n },\n type: \"timeseries\"\n };\n case t.type === \"datetime\":\n return {\n type: \"timestamp\"\n };\n default:\n return {\n type: t.type\n };\n }\n !false ? process.env.NODE_ENV !== \"production\" ? invariant(false) : invariant(false) : void 0;\n}"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PropertyTypeType, SharedPropertyType } from "./types.js";
|
|
2
|
+
export declare function defineInterface(apiName: string, opts: {
|
|
3
|
+
displayName?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
properties?: Record<string, SharedPropertyType | PropertyTypeType>;
|
|
6
|
+
}): {
|
|
7
|
+
apiName: string;
|
|
8
|
+
displayName: string;
|
|
9
|
+
extendsInterfaces: never[];
|
|
10
|
+
links: {};
|
|
11
|
+
properties: {
|
|
12
|
+
[k: string]: SharedPropertyType;
|
|
13
|
+
};
|
|
14
|
+
rid: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=defineInterface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineInterface.d.ts","sourceRoot":"","sources":["../../../src/api/defineInterface.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEvE,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;IACJ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CACjB,MAAM,EACN,kBAAkB,GAAG,gBAAgB,CACtC,CAAC;CACH;;;;;;;;;;EAwEF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ObjectType } from "./defineObject.js";
|
|
2
|
+
export declare function defineLink(from: ObjectType, opts: {
|
|
3
|
+
many: string;
|
|
4
|
+
to: ObjectType;
|
|
5
|
+
reverse: {
|
|
6
|
+
one: string;
|
|
7
|
+
};
|
|
8
|
+
}): unknown;
|
|
9
|
+
export declare function defineLink(from: ObjectType, opts: {
|
|
10
|
+
one: string;
|
|
11
|
+
to: ObjectType;
|
|
12
|
+
reverse: {
|
|
13
|
+
one: string;
|
|
14
|
+
} | {
|
|
15
|
+
many: string;
|
|
16
|
+
};
|
|
17
|
+
}): unknown;
|
|
18
|
+
//# sourceMappingURL=defineLink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineLink.d.ts","sourceRoot":"","sources":["../../../src/api/defineLink.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,wBAAgB,UAAU,CACxB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE;IACJ,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,UAAU,CAAC;IACf,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1B,GACA,OAAO,CAAC;AACX,wBAAgB,UAAU,CACxB,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE;IACJ,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,UAAU,CAAC;IACf,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAC7C,GACA,OAAO,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type * as api from "@osdk/api";
|
|
2
|
+
import type { ObjectTypeFullMetadata } from "@osdk/gateway/types";
|
|
3
|
+
export interface ObjectType {
|
|
4
|
+
data: ObjectTypeFullMetadata;
|
|
5
|
+
linkTypes: Record<string, {}>;
|
|
6
|
+
}
|
|
7
|
+
export declare function defineObject(apiName: string, opts: {
|
|
8
|
+
displayName?: string;
|
|
9
|
+
pluralDisplayName?: string;
|
|
10
|
+
primaryKey: api.ObjectTypePropertyDefinition & {
|
|
11
|
+
apiName: string;
|
|
12
|
+
};
|
|
13
|
+
properties?: Record<string, api.WirePropertyTypes | api.ObjectTypePropertyDefinition>;
|
|
14
|
+
}): ObjectType;
|
|
15
|
+
//# sourceMappingURL=defineObject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineObject.d.ts","sourceRoot":"","sources":["../../../src/api/defineObject.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,KAAK,GAAG,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,sBAAsB,EAAc,MAAM,qBAAqB,CAAC;AAS9E,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,sBAAsB,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,EAIzB,CAAC,CAAC;CACJ;AAED,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;IACJ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,GAAG,CAAC,4BAA4B,GAAG;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,UAAU,CAAC,EAAE,MAAM,CACjB,MAAM,EACJ,GAAG,CAAC,iBAAiB,GACrB,GAAG,CAAC,4BAA4B,CACnC,CAAC;CACH,GACA,UAAU,CAyBZ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type * as Gateway from "@osdk/gateway/types";
|
|
2
|
+
import type { Ontology } from "./types.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export declare let ontologyDefinition: Ontology;
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare let namespace: string;
|
|
7
|
+
export declare function defineOntology(ns: string, body: () => void | Promise<void>): Promise<Ontology>;
|
|
8
|
+
export declare function dumpOntologyFullMetadata(): Gateway.OntologyFullMetadata;
|
|
9
|
+
//# sourceMappingURL=defineOntology.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineOntology.d.ts","sourceRoot":"","sources":["../../../src/api/defineOntology.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,KAAK,OAAO,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAsB,MAAM,YAAY,CAAC;AAE/D,gBAAgB;AAChB,eAAO,IAAI,kBAAkB,EAAE,QAAQ,CAAC;AAExC,gBAAgB;AAChB,eAAO,IAAI,SAAS,EAAE,MAAM,CAAC;AAE7B,wBAAsB,cAAc,CAClC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,qBAuBjC;AAED,wBAAgB,wBAAwB,IAAI,OAAO,CAAC,oBAAoB,CAyCvE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PropertyTypeType, SharedPropertyType } from "./types.js";
|
|
2
|
+
export declare function defineSharedPropertyType(apiName: string, opts: {
|
|
3
|
+
type: PropertyTypeType;
|
|
4
|
+
array?: boolean;
|
|
5
|
+
description?: string;
|
|
6
|
+
displayName?: string;
|
|
7
|
+
}): SharedPropertyType;
|
|
8
|
+
//# sourceMappingURL=defineSpt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineSpt.d.ts","sourceRoot":"","sources":["../../../src/api/defineSpt.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEvE,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE;IACJ,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GACA,kBAAkB,CAUpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overall.test.d.ts","sourceRoot":"","sources":["../../../src/api/overall.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as Gateway from "@osdk/gateway/types";
|
|
2
|
+
export interface Ontology extends Omit<Gateway.OntologyFullMetadata, "ontology" | "sharedPropertyTypes" | "interfaceTypes"> {
|
|
3
|
+
interfaceTypes: Record<string, InterfaceType>;
|
|
4
|
+
sharedPropertyTypes: Record<string, SharedPropertyType>;
|
|
5
|
+
}
|
|
6
|
+
export interface InterfaceType extends Omit<Gateway.InterfaceType, "properties"> {
|
|
7
|
+
properties: Record<string, SharedPropertyType>;
|
|
8
|
+
}
|
|
9
|
+
export interface PropertyType {
|
|
10
|
+
type: PropertyTypeType;
|
|
11
|
+
array?: boolean;
|
|
12
|
+
description?: string;
|
|
13
|
+
displayName?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SharedPropertyType extends PropertyType {
|
|
16
|
+
apiName: string;
|
|
17
|
+
}
|
|
18
|
+
export type PropertyTypeType = "boolean" | "byte" | "date" | "decimal" | "double" | "float" | "geopoint" | "geoshape" | "integer" | "long" | "marking" | "short" | "string" | "timestamp";
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/api/types.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,KAAK,OAAO,MAAM,qBAAqB,CAAC;AAEpD,MAAM,WAAW,QAAS,SACxB,IAAI,CACF,OAAO,CAAC,oBAAoB,EAC5B,UAAU,GAAG,qBAAqB,GAAG,gBAAgB,CACtD;IAED,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC9C,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,aACf,SAAQ,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,YAAY,CAAC;IAEjD,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,gBAAgB,GACxB,SAAS,GACT,MAAM,GACN,MAAM,GACN,SAAS,GACT,QAAQ,GACR,OAAO,GACP,UAAU,GACV,UAAU,GACV,SAAS,GACT,MAAM,GACN,SAAS,GACT,OAAO,GACP,QAAQ,GACR,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/cli/main.ts"],"names":[],"mappings":"AA2BA,wBAA8B,IAAI,CAAC,IAAI,GAAE,MAAM,EAAiB,iBAuC/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@osdk/maker",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/palantir/osdk-ts.git"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./build/types/index.d.ts",
|
|
12
|
+
"import": "./build/js/index.mjs",
|
|
13
|
+
"require": "./build/js/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./*": {
|
|
16
|
+
"types": "./build/types/public/*.d.ts",
|
|
17
|
+
"import": "./build/js/public/*.mjs",
|
|
18
|
+
"require": "./build/js/public/*.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"consola": "^3.2.3",
|
|
23
|
+
"jiti": "^1.21.0",
|
|
24
|
+
"tiny-invariant": "^1.3.3",
|
|
25
|
+
"ts-node": "^10.9.2",
|
|
26
|
+
"yargs": "^17.7.2",
|
|
27
|
+
"@osdk/api": "1.4.0",
|
|
28
|
+
"@osdk/gateway": "2.0.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/yargs": "^17.0.32",
|
|
32
|
+
"typescript": "^5.4.2",
|
|
33
|
+
"vitest": "^1.3.1"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"bin": "bin/maker.mjs",
|
|
39
|
+
"files": [
|
|
40
|
+
"build/types",
|
|
41
|
+
"build/js",
|
|
42
|
+
"changelog",
|
|
43
|
+
"CHANGELOG_OLD.md",
|
|
44
|
+
"package.json",
|
|
45
|
+
"templates",
|
|
46
|
+
"*.d.ts"
|
|
47
|
+
],
|
|
48
|
+
"main": "./build/js/index.cjs",
|
|
49
|
+
"module": "./build/js/index.mjs",
|
|
50
|
+
"types": "./build/types/index.d.ts",
|
|
51
|
+
"type": "module",
|
|
52
|
+
"scripts": {
|
|
53
|
+
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
|
|
54
|
+
"dev:transpile": "tsup --watch",
|
|
55
|
+
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
|
|
56
|
+
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
|
|
57
|
+
"transpile": "tsup",
|
|
58
|
+
"typecheck": "tsc-absolute --build"
|
|
59
|
+
}
|
|
60
|
+
}
|