@osdk/maker-experimental 0.6.0-beta.9 → 0.6.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/CHANGELOG.md +61 -0
- package/build/browser/api/defineOntologyV2.js +6 -1
- package/build/browser/api/defineOntologyV2.js.map +1 -1
- package/build/browser/cli/generateBackingDataset.js +82 -36
- package/build/browser/cli/generateBackingDataset.js.map +1 -1
- package/build/browser/cli/main.js +55 -4
- package/build/browser/cli/main.js.map +1 -1
- package/build/cjs/index.cjs +109 -31
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/index.d.cts +1 -0
- package/build/esm/api/defineOntologyV2.js +6 -1
- package/build/esm/api/defineOntologyV2.js.map +1 -1
- package/build/esm/cli/generateBackingDataset.js +82 -36
- package/build/esm/cli/generateBackingDataset.js.map +1 -1
- package/build/esm/cli/main.js +55 -4
- package/build/esm/cli/main.js.map +1 -1
- package/build/types/api/defineOntologyV2.d.ts +1 -0
- package/build/types/api/defineOntologyV2.d.ts.map +1 -1
- package/build/types/cli/generateBackingDataset.d.ts +5 -1
- package/build/types/cli/generateBackingDataset.d.ts.map +1 -1
- package/build/types/cli/main.d.ts.map +1 -1
- package/package.json +6 -6
package/build/cjs/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var chunkXMO5RRJG_cjs = require('./chunk-XMO5RRJG.cjs');
|
|
6
|
+
var maker = require('@osdk/maker');
|
|
6
7
|
var consola = require('consola');
|
|
7
8
|
var jiti = require('jiti');
|
|
8
9
|
var fs = require('fs');
|
|
@@ -10,7 +11,6 @@ var path = require('path');
|
|
|
10
11
|
var invariant5 = require('tiny-invariant');
|
|
11
12
|
var yargs = require('yargs');
|
|
12
13
|
var helpers = require('yargs/helpers');
|
|
13
|
-
var maker = require('@osdk/maker');
|
|
14
14
|
|
|
15
15
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
16
16
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -4052,10 +4052,15 @@ async function defineOntologyV2(ns, body, randomnessKey) {
|
|
|
4052
4052
|
const ontDef = convertOntologyDefinition(ontologyDefinition, ridGenerator, randomnessKey);
|
|
4053
4053
|
const shapes = await getShapes(ontDef.ontology, ridGenerator, randomnessKey);
|
|
4054
4054
|
const backingDatasourceApiNames = Object.entries(ontologyDefinition[maker.OntologyEntityTypeEnum.OBJECT_TYPE]).filter(([_, obj]) => obj.includeEmptyBackingDatasource === true).map(([apiName]) => apiName);
|
|
4055
|
+
const backingDatasourceLinkApiNames = Object.entries(ontologyDefinition[maker.OntologyEntityTypeEnum.LINK_TYPE]).filter(([_, link]) => {
|
|
4056
|
+
const lt = link;
|
|
4057
|
+
return "many" in lt && !("intermediaryObjectType" in lt) && lt.includeEmptyBackingDatasource === true;
|
|
4058
|
+
}).map(([apiName]) => apiName);
|
|
4055
4059
|
return {
|
|
4056
4060
|
ontologyIr: ontDef,
|
|
4057
4061
|
shapes,
|
|
4058
|
-
backingDatasourceApiNames
|
|
4062
|
+
backingDatasourceApiNames,
|
|
4063
|
+
backingDatasourceLinkApiNames
|
|
4059
4064
|
};
|
|
4060
4065
|
}
|
|
4061
4066
|
function propertyTypeToSchemaType(propType) {
|
|
@@ -4109,23 +4114,16 @@ function getNonEditOnlyProperties(objectTypeBlockData) {
|
|
|
4109
4114
|
const editOnlyRids = getEditOnlyPropertyRids(objectTypeBlockData.datasources);
|
|
4110
4115
|
return Object.entries(objectTypeBlockData.objectType.propertyTypes).filter(([rid]) => !editOnlyRids.has(rid)).map(([_, prop]) => prop);
|
|
4111
4116
|
}
|
|
4112
|
-
async function
|
|
4113
|
-
const apiName = objectTypeBlockData.objectType.apiName;
|
|
4114
|
-
const nonEditOnlyProps = getNonEditOnlyProperties(objectTypeBlockData);
|
|
4115
|
-
const dsName = `${apiName}-backing-ds`;
|
|
4117
|
+
async function generateBackingDatasetBlock(datasetName, blockIdentifier, dirSuffix, columns, buildDir, randomnessKey) {
|
|
4116
4118
|
const outputs = {};
|
|
4117
|
-
const datasourceReadableId = chunkXMO5RRJG_cjs.ReadableIdGenerator.getForDatasetOutput(
|
|
4118
|
-
const columnReadableIds =
|
|
4119
|
-
for (const prop of nonEditOnlyProps) {
|
|
4120
|
-
const colReadableId = chunkXMO5RRJG_cjs.ReadableIdGenerator.getForDatasetColumnOutput(apiName, prop.apiName);
|
|
4121
|
-
columnReadableIds.push(colReadableId);
|
|
4122
|
-
}
|
|
4119
|
+
const datasourceReadableId = chunkXMO5RRJG_cjs.ReadableIdGenerator.getForDatasetOutput(datasetName);
|
|
4120
|
+
const columnReadableIds = columns.map((col) => chunkXMO5RRJG_cjs.ReadableIdGenerator.getForDatasetColumnOutput(datasetName, col.name));
|
|
4123
4121
|
const datasourceBlockInternalId = chunkXMO5RRJG_cjs.toBlockShapeId(datasourceReadableId, randomnessKey);
|
|
4124
4122
|
outputs[datasourceReadableId] = {
|
|
4125
4123
|
type: "tabularDatasource",
|
|
4126
4124
|
tabularDatasource: {
|
|
4127
4125
|
about: {
|
|
4128
|
-
fallbackTitle:
|
|
4126
|
+
fallbackTitle: blockIdentifier,
|
|
4129
4127
|
fallbackDescription: "",
|
|
4130
4128
|
localizedTitle: {},
|
|
4131
4129
|
localizedDescription: {}
|
|
@@ -4137,32 +4135,32 @@ async function generateBackingDatasetBlockResult(objectTypeBlockData, buildDir,
|
|
|
4137
4135
|
}
|
|
4138
4136
|
}
|
|
4139
4137
|
};
|
|
4140
|
-
for (let i = 0; i <
|
|
4141
|
-
const
|
|
4138
|
+
for (let i = 0; i < columns.length; i++) {
|
|
4139
|
+
const col = columns[i];
|
|
4142
4140
|
const colReadableId = columnReadableIds[i];
|
|
4143
4141
|
outputs[colReadableId] = {
|
|
4144
4142
|
type: "datasourceColumn",
|
|
4145
4143
|
datasourceColumn: {
|
|
4146
4144
|
about: {
|
|
4147
|
-
fallbackTitle:
|
|
4145
|
+
fallbackTitle: col.name,
|
|
4148
4146
|
fallbackDescription: "",
|
|
4149
4147
|
localizedTitle: {},
|
|
4150
4148
|
localizedDescription: {}
|
|
4151
4149
|
},
|
|
4152
4150
|
type: {
|
|
4153
4151
|
type: "concrete",
|
|
4154
|
-
concrete: typeToConcreteDataType(
|
|
4152
|
+
concrete: typeToConcreteDataType(col.type)
|
|
4155
4153
|
},
|
|
4156
4154
|
datasource: datasourceBlockInternalId,
|
|
4157
4155
|
typeclasses: []
|
|
4158
4156
|
}
|
|
4159
4157
|
};
|
|
4160
4158
|
}
|
|
4161
|
-
const columnInternalIds =
|
|
4162
|
-
const compassReadableId = `${
|
|
4159
|
+
const columnInternalIds = columns.map((col) => chunkXMO5RRJG_cjs.toBlockShapeId(`column-internal-${datasetName}-${col.name}`, randomnessKey));
|
|
4160
|
+
const compassReadableId = `${blockIdentifier}-compass-resource`;
|
|
4163
4161
|
const compassBlockShapeId = chunkXMO5RRJG_cjs.toBlockShapeId(compassReadableId, randomnessKey);
|
|
4164
|
-
const datasourceInternalId = chunkXMO5RRJG_cjs.toBlockShapeId(`datasource-internal-${
|
|
4165
|
-
const locationInternalId = chunkXMO5RRJG_cjs.toBlockShapeId(`location-internal-${
|
|
4162
|
+
const datasourceInternalId = chunkXMO5RRJG_cjs.toBlockShapeId(`datasource-internal-${datasetName}`, randomnessKey);
|
|
4163
|
+
const locationInternalId = chunkXMO5RRJG_cjs.toBlockShapeId(`location-internal-${datasetName}`, randomnessKey);
|
|
4166
4164
|
const addOnOverride = {
|
|
4167
4165
|
idToBlockShapeId: {
|
|
4168
4166
|
"dataset-internal-shape-id": datasourceBlockInternalId,
|
|
@@ -4175,14 +4173,14 @@ async function generateBackingDatasetBlockResult(objectTypeBlockData, buildDir,
|
|
|
4175
4173
|
[datasourceBlockInternalId]: compassBlockShapeId
|
|
4176
4174
|
}
|
|
4177
4175
|
};
|
|
4178
|
-
const dsBlockDataDir = path__namespace.join(buildDir, `temp_block_data_${
|
|
4176
|
+
const dsBlockDataDir = path__namespace.join(buildDir, `temp_block_data_${dirSuffix}`);
|
|
4179
4177
|
await fs__namespace.promises.mkdir(dsBlockDataDir, {
|
|
4180
4178
|
recursive: true
|
|
4181
4179
|
});
|
|
4182
4180
|
const schemaJson = {
|
|
4183
|
-
fieldSchemaList:
|
|
4184
|
-
type: propertyTypeToSchemaType(
|
|
4185
|
-
name:
|
|
4181
|
+
fieldSchemaList: columns.map((col) => ({
|
|
4182
|
+
type: propertyTypeToSchemaType(col.type),
|
|
4183
|
+
name: col.name,
|
|
4186
4184
|
nullable: null,
|
|
4187
4185
|
userDefinedTypeClass: null,
|
|
4188
4186
|
customMetadata: {},
|
|
@@ -4204,7 +4202,7 @@ async function generateBackingDatasetBlockResult(objectTypeBlockData, buildDir,
|
|
|
4204
4202
|
const blockDataJson = {
|
|
4205
4203
|
type: "v1",
|
|
4206
4204
|
v1: {
|
|
4207
|
-
columns: Object.fromEntries(
|
|
4205
|
+
columns: Object.fromEntries(columns.map((col, i) => [columnInternalIds[i], col.name])),
|
|
4208
4206
|
hasSchema: true
|
|
4209
4207
|
}
|
|
4210
4208
|
};
|
|
@@ -4217,7 +4215,7 @@ async function generateBackingDatasetBlockResult(objectTypeBlockData, buildDir,
|
|
|
4217
4215
|
type: "compassResource",
|
|
4218
4216
|
compassResource: {
|
|
4219
4217
|
about: {
|
|
4220
|
-
fallbackTitle:
|
|
4218
|
+
fallbackTitle: blockIdentifier,
|
|
4221
4219
|
fallbackDescription: "",
|
|
4222
4220
|
localizedTitle: {},
|
|
4223
4221
|
localizedDescription: {}
|
|
@@ -4232,7 +4230,7 @@ async function generateBackingDatasetBlockResult(objectTypeBlockData, buildDir,
|
|
|
4232
4230
|
}
|
|
4233
4231
|
};
|
|
4234
4232
|
return {
|
|
4235
|
-
block_identifier:
|
|
4233
|
+
block_identifier: blockIdentifier,
|
|
4236
4234
|
block_data_directory: dsBlockDataDir,
|
|
4237
4235
|
oci_block_data_metadata: void 0,
|
|
4238
4236
|
maven_block_data_metadata: void 0,
|
|
@@ -4245,13 +4243,55 @@ async function generateBackingDatasetBlockResult(objectTypeBlockData, buildDir,
|
|
|
4245
4243
|
block_type: "STATIC_DATASET"
|
|
4246
4244
|
};
|
|
4247
4245
|
}
|
|
4246
|
+
async function generateBackingDatasetBlockResult(objectTypeBlockData, buildDir, randomnessKey) {
|
|
4247
|
+
const apiName = objectTypeBlockData.objectType.apiName;
|
|
4248
|
+
const nonEditOnlyProps = getNonEditOnlyProperties(objectTypeBlockData);
|
|
4249
|
+
const columns = nonEditOnlyProps.map((prop) => ({
|
|
4250
|
+
name: prop.apiName,
|
|
4251
|
+
type: prop.type
|
|
4252
|
+
}));
|
|
4253
|
+
return generateBackingDatasetBlock(apiName, `${apiName}-backing-ds`, `${apiName}_backing_ds`, columns, buildDir, randomnessKey);
|
|
4254
|
+
}
|
|
4255
|
+
async function generateBackingDatasetBlockResultForLink(linkTypeBlockData, linkApiName, objectTypes, buildDir, randomnessKey) {
|
|
4256
|
+
const definition = linkTypeBlockData.linkType.definition;
|
|
4257
|
+
if (definition.type !== "manyToMany") {
|
|
4258
|
+
throw new Error(`Link type "${linkApiName}" is not a many-to-many link type`);
|
|
4259
|
+
}
|
|
4260
|
+
const m2m = definition.manyToMany;
|
|
4261
|
+
const datasource = linkTypeBlockData.datasources[0]?.datasource;
|
|
4262
|
+
if (!datasource || datasource.type !== "dataset") {
|
|
4263
|
+
throw new Error(`Link type "${linkApiName}" does not have a dataset datasource`);
|
|
4264
|
+
}
|
|
4265
|
+
const ds = datasource.dataset;
|
|
4266
|
+
const pkRidA = Object.keys(ds.objectTypeAPrimaryKeyMapping)[0];
|
|
4267
|
+
const columnA = Object.values(ds.objectTypeAPrimaryKeyMapping)[0];
|
|
4268
|
+
const pkRidB = Object.keys(ds.objectTypeBPrimaryKeyMapping)[0];
|
|
4269
|
+
const columnB = Object.values(ds.objectTypeBPrimaryKeyMapping)[0];
|
|
4270
|
+
const objectTypeA = objectTypes[m2m.objectTypeRidA];
|
|
4271
|
+
const objectTypeB = objectTypes[m2m.objectTypeRidB];
|
|
4272
|
+
if (!objectTypeA || !objectTypeB) {
|
|
4273
|
+
throw new Error(`Could not find object types for link "${linkApiName}"`);
|
|
4274
|
+
}
|
|
4275
|
+
const propTypeA = objectTypeA.objectType.propertyTypes[pkRidA]?.type;
|
|
4276
|
+
const propTypeB = objectTypeB.objectType.propertyTypes[pkRidB]?.type;
|
|
4277
|
+
if (!propTypeA || !propTypeB) {
|
|
4278
|
+
throw new Error(`Could not find primary key property types for link "${linkApiName}"`);
|
|
4279
|
+
}
|
|
4280
|
+
return generateBackingDatasetBlock(`link.${linkApiName}`, `${linkApiName}-link-backing-ds`, `${linkApiName}_link_backing_ds`, [{
|
|
4281
|
+
name: columnA,
|
|
4282
|
+
type: propTypeA
|
|
4283
|
+
}, {
|
|
4284
|
+
name: columnB,
|
|
4285
|
+
type: propTypeB
|
|
4286
|
+
}], buildDir, randomnessKey);
|
|
4287
|
+
}
|
|
4248
4288
|
|
|
4249
4289
|
// src/cli/main.ts
|
|
4250
4290
|
var apiNamespaceRegex = /^[a-z0-9-]+(\.[a-z0-9-]+)*\.$/;
|
|
4251
4291
|
var uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
4252
4292
|
async function main(args = process.argv) {
|
|
4253
4293
|
consola.consola.log("Generating BlockGeneratorResult for ontology...");
|
|
4254
|
-
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.6.0
|
|
4294
|
+
const commandLineOpts = await yargs__default.default(helpers.hideBin(args)).version("0.6.0").wrap(Math.min(150, yargs__default.default().terminalWidth())).strict().help().options({
|
|
4255
4295
|
input: {
|
|
4256
4296
|
alias: "i",
|
|
4257
4297
|
describe: "Input file",
|
|
@@ -4296,7 +4336,8 @@ async function main(args = process.argv) {
|
|
|
4296
4336
|
const {
|
|
4297
4337
|
ontologyIr,
|
|
4298
4338
|
shapes,
|
|
4299
|
-
backingDatasourceApiNames
|
|
4339
|
+
backingDatasourceApiNames,
|
|
4340
|
+
backingDatasourceLinkApiNames
|
|
4300
4341
|
} = await loadOntology(commandLineOpts.input, apiNamespace, commandLineOpts.randomnessKey);
|
|
4301
4342
|
const blockDataDir = path__namespace.join(commandLineOpts.buildDir, "temp_block_data");
|
|
4302
4343
|
if (!fs__namespace.existsSync(blockDataDir)) {
|
|
@@ -4332,6 +4373,33 @@ async function main(args = process.argv) {
|
|
|
4332
4373
|
}
|
|
4333
4374
|
}
|
|
4334
4375
|
}
|
|
4376
|
+
for (const linkApiName of backingDatasourceLinkApiNames) {
|
|
4377
|
+
const linkTypeBlockData = findLinkTypeByApiName(ontologyIr.ontology.linkTypes, linkApiName);
|
|
4378
|
+
if (!linkTypeBlockData) continue;
|
|
4379
|
+
const datasetName = `link.${linkApiName}`;
|
|
4380
|
+
const inputDsId = chunkXMO5RRJG_cjs.ReadableIdGenerator.getForDataset(datasetName);
|
|
4381
|
+
const outputDsId = chunkXMO5RRJG_cjs.ReadableIdGenerator.getForDatasetOutput(datasetName);
|
|
4382
|
+
if (shapes.inputShapes.has(inputDsId)) {
|
|
4383
|
+
ontologyInputMappingEntries.push({
|
|
4384
|
+
input: inputDsId,
|
|
4385
|
+
output: outputDsId
|
|
4386
|
+
});
|
|
4387
|
+
}
|
|
4388
|
+
const ds = linkTypeBlockData.datasources[0]?.datasource;
|
|
4389
|
+
if (ds?.type === "dataset") {
|
|
4390
|
+
const columnNames = [...Object.values(ds.dataset.objectTypeAPrimaryKeyMapping).map(String), ...Object.values(ds.dataset.objectTypeBPrimaryKeyMapping).map(String)];
|
|
4391
|
+
for (const colName of columnNames) {
|
|
4392
|
+
const colInputId = chunkXMO5RRJG_cjs.ReadableIdGenerator.getForDatasetColumn(datasetName, colName);
|
|
4393
|
+
const colOutputId = chunkXMO5RRJG_cjs.ReadableIdGenerator.getForDatasetColumnOutput(datasetName, colName);
|
|
4394
|
+
if (shapes.inputShapes.has(colInputId)) {
|
|
4395
|
+
ontologyInputMappingEntries.push({
|
|
4396
|
+
input: colInputId,
|
|
4397
|
+
output: colOutputId
|
|
4398
|
+
});
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4401
|
+
}
|
|
4402
|
+
}
|
|
4335
4403
|
const backingDsGeneratorResults = await Promise.all(backingDatasourceApiNames.filter((apiName) => {
|
|
4336
4404
|
const objectTypeBlockData = findObjectTypeByApiName(ontologyIr.ontology.objectTypes, apiName);
|
|
4337
4405
|
return objectTypeBlockData !== void 0;
|
|
@@ -4340,6 +4408,12 @@ async function main(args = process.argv) {
|
|
|
4340
4408
|
consola.consola.info(`Generating backing datasource BlockGeneratorResult for ${apiName}...`);
|
|
4341
4409
|
return await generateBackingDatasetBlockResult(objectTypeBlockData, commandLineOpts.buildDir, commandLineOpts.randomnessKey);
|
|
4342
4410
|
}));
|
|
4411
|
+
const backingDsLinkGeneratorResults = await Promise.all(backingDatasourceLinkApiNames.map((linkApiName) => {
|
|
4412
|
+
const linkTypeBlockData = findLinkTypeByApiName(ontologyIr.ontology.linkTypes, linkApiName);
|
|
4413
|
+
if (!linkTypeBlockData) return void 0;
|
|
4414
|
+
consola.consola.info(`Generating backing datasource BlockGeneratorResult for link ${linkApiName}...`);
|
|
4415
|
+
return generateBackingDatasetBlockResultForLink(linkTypeBlockData, linkApiName, ontologyIr.ontology.objectTypes, commandLineOpts.buildDir, commandLineOpts.randomnessKey);
|
|
4416
|
+
}).filter((p) => p !== void 0));
|
|
4343
4417
|
const blockGeneratorResult = {
|
|
4344
4418
|
block_identifier: "ontology",
|
|
4345
4419
|
block_data_directory: blockDataDir,
|
|
@@ -4353,7 +4427,7 @@ async function main(args = process.argv) {
|
|
|
4353
4427
|
input_shape_metadata: Object.fromEntries(shapes.inputShapeMetadata),
|
|
4354
4428
|
block_type: "ONTOLOGY"
|
|
4355
4429
|
};
|
|
4356
|
-
const blockGeneratorResultJson = JSON.stringify([blockGeneratorResult, ...backingDsGeneratorResults], null, 2);
|
|
4430
|
+
const blockGeneratorResultJson = JSON.stringify([blockGeneratorResult, ...backingDsGeneratorResults, ...backingDsLinkGeneratorResults], null, 2);
|
|
4357
4431
|
await fs__namespace.promises.writeFile(commandLineOpts.output, blockGeneratorResultJson);
|
|
4358
4432
|
consola.consola.success(`BlockGeneratorResult written to ${commandLineOpts.output}`);
|
|
4359
4433
|
consola.consola.info(`Block data directory: ${blockDataDir}`);
|
|
@@ -4372,6 +4446,10 @@ async function loadOntology(input, apiNamespace, randomnessKey) {
|
|
|
4372
4446
|
function findObjectTypeByApiName(objectTypes, apiName) {
|
|
4373
4447
|
return Object.values(objectTypes).find((objectTypeBlockData) => objectTypeBlockData.objectType.apiName === apiName);
|
|
4374
4448
|
}
|
|
4449
|
+
function findLinkTypeByApiName(linkTypes, apiName) {
|
|
4450
|
+
const linkTypeId = maker.cleanAndValidateLinkTypeId(apiName);
|
|
4451
|
+
return Object.values(linkTypes).find((lt) => lt.linkType.id === linkTypeId);
|
|
4452
|
+
}
|
|
4375
4453
|
function defineImportObject(objectDef) {
|
|
4376
4454
|
const properties = Object.entries(objectDef.properties ?? {}).map(([apiName, type]) => ({
|
|
4377
4455
|
apiName,
|