@osdk/generator 1.12.0-main-20240530094422 → 1.12.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 +56 -6
- package/build/browser/index.js +144 -39
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +146 -39
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.cts +2 -1
- package/build/cjs/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts.map +1 -1
- package/build/cjs/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.cts +2 -0
- package/build/cjs/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts.map +1 -0
- package/build/cjs/shared/propertyJsdoc.d.cts +6 -0
- package/build/cjs/shared/propertyJsdoc.d.ts.map +1 -0
- package/build/cjs/shared/wireObjectTypeV2ToSdkObjectConst.d.ts.map +1 -1
- package/build/cjs/shared/wireQueryDataTypeToQueryDataTypeDefinition.d.cts +1 -1
- package/build/cjs/shared/wireQueryDataTypeToQueryDataTypeDefinition.d.ts.map +1 -1
- package/build/cjs/shared/wireQueryTypeV2ToSdkQueryDefinition.d.cts +10 -2
- package/build/cjs/shared/wireQueryTypeV2ToSdkQueryDefinition.d.ts.map +1 -1
- package/build/cjs/util/stringify.d.cts +3 -3
- package/build/cjs/util/stringify.d.ts.map +1 -1
- package/build/cjs/util/test/createMockMinimalFiles.d.ts.map +1 -1
- package/build/cjs/util/{verifyOutdir.d.cts → verifyOutDir.d.cts} +2 -2
- package/build/cjs/util/{verifyOutdir.d.ts.map → verifyOutDir.d.ts.map} +1 -1
- package/build/cjs/v1.1/backcompat/generateOntologyRuntimeDistDir.d.ts.map +1 -1
- package/build/cjs/v1.1/generatePerQueryDataFiles.d.cts +1 -1
- package/build/cjs/v1.1/generatePerQueryDataFiles.d.ts.map +1 -1
- package/build/cjs/v2.0/generateClientSdkVersionTwoPointZero.d.ts.map +1 -1
- package/build/esm/index.js +144 -39
- package/build/esm/index.js.map +1 -1
- package/build/esm/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts +2 -1
- package/build/esm/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.d.ts.map +1 -1
- package/build/esm/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts +2 -0
- package/build/esm/shared/UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst.test.d.ts.map +1 -0
- package/build/esm/shared/propertyJsdoc.d.ts +6 -0
- package/build/esm/shared/propertyJsdoc.d.ts.map +1 -0
- package/build/esm/shared/wireObjectTypeV2ToSdkObjectConst.d.ts.map +1 -1
- package/build/esm/shared/wireQueryDataTypeToQueryDataTypeDefinition.d.ts +1 -1
- package/build/esm/shared/wireQueryDataTypeToQueryDataTypeDefinition.d.ts.map +1 -1
- package/build/esm/shared/wireQueryTypeV2ToSdkQueryDefinition.d.ts +10 -2
- package/build/esm/shared/wireQueryTypeV2ToSdkQueryDefinition.d.ts.map +1 -1
- package/build/esm/util/stringify.d.ts +3 -3
- package/build/esm/util/stringify.d.ts.map +1 -1
- package/build/esm/util/test/createMockMinimalFiles.d.ts.map +1 -1
- package/build/esm/util/{verifyOutdir.d.ts → verifyOutDir.d.ts} +2 -2
- package/build/esm/util/{verifyOutdir.d.ts.map → verifyOutDir.d.ts.map} +1 -1
- package/build/esm/v1.1/backcompat/generateOntologyRuntimeDistDir.d.ts.map +1 -1
- package/build/esm/v1.1/generatePerQueryDataFiles.d.ts +1 -1
- package/build/esm/v1.1/generatePerQueryDataFiles.d.ts.map +1 -1
- package/build/esm/v2.0/generateClientSdkVersionTwoPointZero.d.ts.map +1 -1
- package/package.json +18 -13
package/build/cjs/index.cjs
CHANGED
|
@@ -5,6 +5,8 @@ var path16 = require('path');
|
|
|
5
5
|
var prettier = require('prettier');
|
|
6
6
|
var organizeImports = require('prettier-plugin-organize-imports');
|
|
7
7
|
var generatorConverters = require('@osdk/generator-converters');
|
|
8
|
+
var fastDeepEqual = require('fast-deep-equal');
|
|
9
|
+
var invariant = require('tiny-invariant');
|
|
8
10
|
|
|
9
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
12
|
|
|
@@ -29,6 +31,8 @@ function _interopNamespace(e) {
|
|
|
29
31
|
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
30
32
|
var path16__namespace = /*#__PURE__*/_interopNamespace(path16);
|
|
31
33
|
var organizeImports__default = /*#__PURE__*/_interopDefault(organizeImports);
|
|
34
|
+
var fastDeepEqual__default = /*#__PURE__*/_interopDefault(fastDeepEqual);
|
|
35
|
+
var invariant__default = /*#__PURE__*/_interopDefault(invariant);
|
|
32
36
|
|
|
33
37
|
// src/generateClientSdkPackage.ts
|
|
34
38
|
|
|
@@ -243,6 +247,38 @@ function createModifiedEntities(addedObjects, modifiedObjects) {
|
|
|
243
247
|
}
|
|
244
248
|
return entities;
|
|
245
249
|
}
|
|
250
|
+
|
|
251
|
+
// src/shared/propertyJsdoc.ts
|
|
252
|
+
function propertyJsdoc(property, {
|
|
253
|
+
isInherited,
|
|
254
|
+
apiName
|
|
255
|
+
}) {
|
|
256
|
+
let ret = `/**
|
|
257
|
+
`;
|
|
258
|
+
const renderDisplayName = property.displayName && property.displayName !== apiName;
|
|
259
|
+
if (isInherited || renderDisplayName || property.description) {
|
|
260
|
+
if (isInherited) {
|
|
261
|
+
ret += ` * (inherited from parent)
|
|
262
|
+
`;
|
|
263
|
+
}
|
|
264
|
+
if (renderDisplayName) {
|
|
265
|
+
ret += ` * display name: '${property.displayName}'${property.description ? "," : ""}
|
|
266
|
+
`;
|
|
267
|
+
}
|
|
268
|
+
if (property.description) {
|
|
269
|
+
ret += ` * description: ${property.description}
|
|
270
|
+
`;
|
|
271
|
+
}
|
|
272
|
+
} else {
|
|
273
|
+
ret += ` * (no ontology metadata)
|
|
274
|
+
`;
|
|
275
|
+
}
|
|
276
|
+
ret += ` */
|
|
277
|
+
`;
|
|
278
|
+
return ret;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// src/shared/wireObjectTypeV2ToSdkObjectConst.ts
|
|
246
282
|
function getObjectDefIdentifier(name, v2) {
|
|
247
283
|
return v2 ? name : `${name}Def`;
|
|
248
284
|
}
|
|
@@ -281,7 +317,9 @@ function wireObjectTypeV2ToSdkObjectConst(object, importExt, v2 = false) {
|
|
|
281
317
|
}`,
|
|
282
318
|
properties: (_value) => `{
|
|
283
319
|
${stringify(definition.properties, {
|
|
284
|
-
"*": (propertyDefinition) =>
|
|
320
|
+
"*": (propertyDefinition, _, apiName) => [`${propertyJsdoc(propertyDefinition, {
|
|
321
|
+
apiName
|
|
322
|
+
})}${apiName}`, `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`]
|
|
285
323
|
})}
|
|
286
324
|
}`
|
|
287
325
|
})}
|
|
@@ -356,13 +394,13 @@ async function generatePerActionDataFiles(ontology, fs2, outDir, importExt, v2)
|
|
|
356
394
|
|
|
357
395
|
|
|
358
396
|
// Represents the runtime arguments for the action
|
|
359
|
-
export type ${paramsIdentifier} = NOOP<OsdkActionParameters<${paramsDefIdentifier}
|
|
397
|
+
export type ${paramsIdentifier} = NOOP<OsdkActionParameters<${paramsDefIdentifier}>> | NOOP<OsdkActionParameters<${paramsDefIdentifier}>>[];
|
|
360
398
|
|
|
361
399
|
|
|
362
400
|
// Represents a fqn of the action
|
|
363
401
|
export interface ${action.apiName} {
|
|
364
402
|
${getDescriptionIfPresent(action.description)}
|
|
365
|
-
<OP extends ApplyActionOptions>(args:
|
|
403
|
+
<P extends ${paramsIdentifier}, OP extends P extends NOOP<OsdkActionParameters<${paramsDefIdentifier}>>[]? ApplyBatchActionOptions: ApplyActionOptions>(args: P, options?: OP): Promise<ActionReturnTypeForOptions<OP>>;
|
|
366
404
|
}
|
|
367
405
|
|
|
368
406
|
|
|
@@ -400,7 +438,7 @@ async function generatePerActionDataFiles(ontology, fs2, outDir, importExt, v2)
|
|
|
400
438
|
const importObjects = referencedObjectDefs.size > 0 ? `import type {${[...referencedObjectDefs].join(",")}} from "../objects${importExt}";` : "";
|
|
401
439
|
await fs2.writeFile(path16__namespace.default.join(outDir, `${action.apiName}.ts`), await formatTs(`
|
|
402
440
|
import type { ActionDefinition, ObjectActionDataType, ObjectSetActionDataType } from "@osdk/api";
|
|
403
|
-
import type { ActionSignature, ApplyActionOptions, OsdkActionParameters,ActionReturnTypeForOptions, NOOP } from '@osdk/client.api';
|
|
441
|
+
import type { ActionSignature, ApplyActionOptions, ApplyBatchActionOptions, OsdkActionParameters,ActionReturnTypeForOptions, NOOP } from '@osdk/client.api';
|
|
404
442
|
import { $osdkMetadata} from "../../OntologyMetadata${importExt}";
|
|
405
443
|
${importObjects}
|
|
406
444
|
|
|
@@ -471,8 +509,8 @@ function camelize(name) {
|
|
|
471
509
|
return name.replace(/-./g, (segment) => segment[1].toUpperCase());
|
|
472
510
|
}
|
|
473
511
|
|
|
474
|
-
// src/util/
|
|
475
|
-
async function
|
|
512
|
+
// src/util/verifyOutDir.ts
|
|
513
|
+
async function verifyOutDir(outDir, fs2) {
|
|
476
514
|
try {
|
|
477
515
|
const contents = await fs2.readdir(outDir);
|
|
478
516
|
if (contents.length !== 0) {
|
|
@@ -570,7 +608,7 @@ function reexportConsts(typesToExport) {
|
|
|
570
608
|
import { ${typesToExport.map((q) => `${q} as OG_${q}`).join(", ")}} from "@osdk/legacy-client";
|
|
571
609
|
|
|
572
610
|
${typesToExport.map((q) => `
|
|
573
|
-
/** @deprecated submodule imports
|
|
611
|
+
/** @deprecated submodule imports aren't public api **/
|
|
574
612
|
export const ${q} = OG_${q};
|
|
575
613
|
`).join("\n\n")}
|
|
576
614
|
`;
|
|
@@ -620,7 +658,7 @@ function reexportTypes(typesToExport, genericArgsLeft = "", genericArgsRight = c
|
|
|
620
658
|
import type { ${typesToExport.map((q) => `${q} as OG_${q}`).join(", ")}} from "@osdk/legacy-client";
|
|
621
659
|
|
|
622
660
|
${typesToExport.map((q) => `
|
|
623
|
-
/** @deprecated submodule imports
|
|
661
|
+
/** @deprecated submodule imports aren't public api **/
|
|
624
662
|
export type ${q}${genericArgsLeft} = OG_${q}${genericArgsRight};
|
|
625
663
|
`).join("\n\n")}
|
|
626
664
|
`;
|
|
@@ -628,8 +666,7 @@ function reexportTypes(typesToExport, genericArgsLeft = "", genericArgsRight = c
|
|
|
628
666
|
var captureInBracketsRegex = /<(.*?)>/;
|
|
629
667
|
var captureGenericParamNameRegex = /^\s?(.+?)( extends .*?)?( = .*?)?\s?$/;
|
|
630
668
|
function cleanup(s) {
|
|
631
|
-
if (s.length === 0)
|
|
632
|
-
return "";
|
|
669
|
+
if (s.length === 0) return "";
|
|
633
670
|
const genericParameterNames = captureInBracketsRegex.exec(s)?.[1]?.split(",")?.map((a) => {
|
|
634
671
|
return captureGenericParamNameRegex.exec(a)?.[1] ?? a;
|
|
635
672
|
});
|
|
@@ -931,10 +968,7 @@ async function generateOntologyRuntimeDistDir(outDir, fs2, importExt = "") {
|
|
|
931
968
|
await generateBaseTypesDir(runtimeDistDir, fs2, importExt);
|
|
932
969
|
await generateClientDir(runtimeDistDir, fs2, importExt);
|
|
933
970
|
await generateFiltersDir(runtimeDistDir, fs2, importExt);
|
|
934
|
-
await fs2.writeFile(
|
|
935
|
-
path16__namespace.join(runtimeDistDir, "index.ts"),
|
|
936
|
-
// TRASHFIXME
|
|
937
|
-
await formatTs(`
|
|
971
|
+
await fs2.writeFile(path16__namespace.join(runtimeDistDir, "index.ts"), await formatTs(`
|
|
938
972
|
export * from "./aggregations/index${importExt}";
|
|
939
973
|
export * from "./baseTypes/index${importExt}";
|
|
940
974
|
${""}
|
|
@@ -944,8 +978,7 @@ async function generateOntologyRuntimeDistDir(outDir, fs2, importExt = "") {
|
|
|
944
978
|
|
|
945
979
|
export * from "./ontologyProvider/index${importExt}";
|
|
946
980
|
export * from "./paging/index${importExt}";
|
|
947
|
-
`)
|
|
948
|
-
);
|
|
981
|
+
`));
|
|
949
982
|
}
|
|
950
983
|
|
|
951
984
|
// src/v1.1/generateBackCompatDeprecatedExports.ts
|
|
@@ -1308,10 +1341,10 @@ function wireQueryDataTypeToQueryDataTypeDefinition(input) {
|
|
|
1308
1341
|
case "union":
|
|
1309
1342
|
const allowNulls = isNullableQueryDataType(input);
|
|
1310
1343
|
if (allowNulls && input.unionTypes.length === 2) {
|
|
1311
|
-
const
|
|
1312
|
-
if (
|
|
1344
|
+
const nonNull = input.unionTypes.find((t) => t.type != null);
|
|
1345
|
+
if (nonNull) {
|
|
1313
1346
|
return {
|
|
1314
|
-
...wireQueryDataTypeToQueryDataTypeDefinition(
|
|
1347
|
+
...wireQueryDataTypeToQueryDataTypeDefinition(nonNull),
|
|
1315
1348
|
nullable: true
|
|
1316
1349
|
};
|
|
1317
1350
|
}
|
|
@@ -1336,12 +1369,14 @@ function wireQueryDataTypeToQueryDataTypeDefinition(input) {
|
|
|
1336
1369
|
case "twoDimensionalAggregation":
|
|
1337
1370
|
return {
|
|
1338
1371
|
type: "twoDimensionalAggregation",
|
|
1339
|
-
twoDimensionalAggregation: get2DQueryAggregationProps(input)
|
|
1372
|
+
twoDimensionalAggregation: get2DQueryAggregationProps(input),
|
|
1373
|
+
nullable: false
|
|
1340
1374
|
};
|
|
1341
1375
|
case "threeDimensionalAggregation":
|
|
1342
1376
|
return {
|
|
1343
1377
|
type: "threeDimensionalAggregation",
|
|
1344
|
-
threeDimensionalAggregation: get3DQueryAggregationProps(input)
|
|
1378
|
+
threeDimensionalAggregation: get3DQueryAggregationProps(input),
|
|
1379
|
+
nullable: false
|
|
1345
1380
|
};
|
|
1346
1381
|
case "null":
|
|
1347
1382
|
case "unsupported":
|
|
@@ -1400,6 +1435,15 @@ function wireQueryTypeV2ToSdkQueryDefinition(input) {
|
|
|
1400
1435
|
output: wireQueryDataTypeToQueryDataTypeDefinition(input.output)
|
|
1401
1436
|
};
|
|
1402
1437
|
}
|
|
1438
|
+
function wireQueryTypeV2ToSdkQueryDefinitionNoParams(input) {
|
|
1439
|
+
return {
|
|
1440
|
+
type: "query",
|
|
1441
|
+
apiName: input.apiName,
|
|
1442
|
+
description: input.description,
|
|
1443
|
+
displayName: input.displayName,
|
|
1444
|
+
version: input.version
|
|
1445
|
+
};
|
|
1446
|
+
}
|
|
1403
1447
|
function wireQueryParameterV2ToQueryParameterDefinition(parameter) {
|
|
1404
1448
|
return {
|
|
1405
1449
|
description: parameter.description,
|
|
@@ -1408,19 +1452,36 @@ function wireQueryParameterV2ToQueryParameterDefinition(parameter) {
|
|
|
1408
1452
|
}
|
|
1409
1453
|
|
|
1410
1454
|
// src/v1.1/generatePerQueryDataFiles.ts
|
|
1411
|
-
async function generatePerQueryDataFiles(ontology, fs2, outDir, importExt = "") {
|
|
1455
|
+
async function generatePerQueryDataFiles(ontology, fs2, outDir, importExt = "", v2 = false) {
|
|
1412
1456
|
await fs2.mkdir(outDir, {
|
|
1413
1457
|
recursive: true
|
|
1414
1458
|
});
|
|
1415
1459
|
await Promise.all(Object.values(ontology.queryTypes).map(async (query) => {
|
|
1416
1460
|
const objectTypes = getObjectTypesFromQuery(query);
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1461
|
+
const importObjects = objectTypes.length > 0 ? `import {${[...objectTypes].join(",")}} from "../objects${importExt}";` : "";
|
|
1462
|
+
if (v2) {
|
|
1463
|
+
await fs2.writeFile(path16__namespace.default.join(outDir, `${query.apiName}.ts`), await formatTs(`
|
|
1464
|
+
import { QueryDefinition } from "@osdk/api";
|
|
1465
|
+
${importObjects}
|
|
1466
|
+
export const ${query.apiName} = {
|
|
1467
|
+
${stringify(deleteUndefineds(wireQueryTypeV2ToSdkQueryDefinitionNoParams(query)))},
|
|
1468
|
+
parameters: {${Object.entries(query.parameters).map(([name, parameter]) => {
|
|
1469
|
+
return `${name} : {${stringify(deleteUndefineds(wireQueryParameterV2ToQueryParameterDefinition(parameter)))},
|
|
1470
|
+
${parameter.dataType.type === "object" || parameter.dataType.type === "objectSet" ? getOsdkTargetTypeIfPresent(parameter.dataType.objectTypeApiName, v2) : ``}}`;
|
|
1471
|
+
})}},
|
|
1472
|
+
output: {${stringify(deleteUndefineds(wireQueryDataTypeToQueryDataTypeDefinition(query.output)))},
|
|
1473
|
+
${query.output.type === "object" || query.output.type === "objectSet" ? getOsdkTargetTypeIfPresent(query.output.objectTypeApiName, v2) : ``}}
|
|
1474
|
+
} ${getQueryDefSatisfies(query.apiName, objectTypes)}`));
|
|
1475
|
+
} else {
|
|
1476
|
+
await fs2.writeFile(path16__namespace.default.join(outDir, `${query.apiName}.ts`), await formatTs(`
|
|
1477
|
+
import { QueryDefinition } from "@osdk/api";
|
|
1478
|
+
|
|
1479
|
+
export const ${query.apiName} = ${JSON.stringify(wireQueryTypeV2ToSdkQueryDefinition(query))} ${getQueryDefSatisfies(query.apiName, objectTypes)}`));
|
|
1480
|
+
}
|
|
1421
1481
|
}));
|
|
1422
1482
|
await fs2.writeFile(path16__namespace.default.join(outDir, "index.ts"), await formatTs(`
|
|
1423
1483
|
${Object.values(ontology.queryTypes).map((query) => `export * from "./${query.apiName}${importExt}";`).join("\n")}
|
|
1484
|
+
${Object.keys(ontology.queryTypes).length === 0 ? "export {};" : ""}
|
|
1424
1485
|
`));
|
|
1425
1486
|
}
|
|
1426
1487
|
function getObjectTypesFromQuery(query) {
|
|
@@ -1473,6 +1534,14 @@ function getObjectTypesFromDataType(dataType, types) {
|
|
|
1473
1534
|
throw new Error(`Cannot find object types from unsupported QueryDataType ${dataType.type}`);
|
|
1474
1535
|
}
|
|
1475
1536
|
}
|
|
1537
|
+
function getQueryDefSatisfies(apiName, objectTypes) {
|
|
1538
|
+
return `satisfies QueryDefinition<"${apiName}", ${objectTypes.length > 0 ? objectTypes.map((apiNameObj) => `"${apiNameObj}"`).join("|") : "never"}>;`;
|
|
1539
|
+
}
|
|
1540
|
+
function getOsdkTargetTypeIfPresent(objectTypeApiName, v2) {
|
|
1541
|
+
return `
|
|
1542
|
+
__OsdkTargetType: ${getObjectDefIdentifier(objectTypeApiName, v2)}
|
|
1543
|
+
`;
|
|
1544
|
+
}
|
|
1476
1545
|
async function generateQueries(ontology, fs2, outDir, importExt = "") {
|
|
1477
1546
|
const importedObjects = /* @__PURE__ */ new Set();
|
|
1478
1547
|
const signatures = [];
|
|
@@ -1622,7 +1691,7 @@ async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs2, outDi
|
|
|
1622
1691
|
const objectsDir = path16__namespace.join(outDir, "ontology", "objects");
|
|
1623
1692
|
const actionsDir = path16__namespace.join(outDir, "ontology", "actions");
|
|
1624
1693
|
const queriesDir = path16__namespace.join(outDir, "ontology", "queries");
|
|
1625
|
-
await
|
|
1694
|
+
await verifyOutDir(outDir, fs2);
|
|
1626
1695
|
await fs2.mkdir(outDir, {
|
|
1627
1696
|
recursive: true
|
|
1628
1697
|
});
|
|
@@ -1642,9 +1711,37 @@ async function generateClientSdkVersionOneDotOne(ontology, userAgent, fs2, outDi
|
|
|
1642
1711
|
await generateIndexFile(fs2, outDir, importExt);
|
|
1643
1712
|
await generateBackCompatDeprecatedExports(fs2, outDir, importExt);
|
|
1644
1713
|
}
|
|
1645
|
-
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, v2 = false) {
|
|
1714
|
+
function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, ontology, v2 = false) {
|
|
1646
1715
|
const definition = deleteUndefineds(generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(interfaceDef, v2));
|
|
1647
1716
|
const objectDefIdentifier = getObjectDefIdentifier(interfaceDef.apiName, v2);
|
|
1717
|
+
const parents = definition.implements?.map((p) => {
|
|
1718
|
+
!(ontology.interfaceTypes[p] != null) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Expected to find a parent interface named ${p} in the ontology and did not.`) : invariant__default.default(false) : void 0;
|
|
1719
|
+
const it = deleteUndefineds(generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(ontology.interfaceTypes[p], v2));
|
|
1720
|
+
return it;
|
|
1721
|
+
}) ?? [];
|
|
1722
|
+
const mergedProperties = {
|
|
1723
|
+
...definition.properties
|
|
1724
|
+
};
|
|
1725
|
+
for (const parent of parents) {
|
|
1726
|
+
for (const apiName of Object.keys(parent.properties)) {
|
|
1727
|
+
if (definition.properties[apiName] != null) {
|
|
1728
|
+
!fastDeepEqual__default.default(definition.properties[apiName], parent.properties[apiName]) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Interface ${definition.apiName} redefines property '${apiName}' from parent '${parent.apiName}' but the properties do not match`) : invariant__default.default(false) : void 0;
|
|
1729
|
+
} else if (mergedProperties[apiName] != null) {
|
|
1730
|
+
!fastDeepEqual__default.default(mergedProperties[apiName], parent.properties[apiName]) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Some interface defines a conflicting property '${apiName}' that does not match property from parent '${parent.apiName}'`) : invariant__default.default(false) : void 0;
|
|
1731
|
+
}
|
|
1732
|
+
mergedProperties[apiName] = parent.properties[apiName];
|
|
1733
|
+
}
|
|
1734
|
+
}
|
|
1735
|
+
const ogProperties = definition.properties;
|
|
1736
|
+
definition.properties = mergedProperties;
|
|
1737
|
+
function localPropertyJsdoc(apiName) {
|
|
1738
|
+
const property = definition.properties[apiName];
|
|
1739
|
+
const isInherited = ogProperties[apiName] == null;
|
|
1740
|
+
return propertyJsdoc(property, {
|
|
1741
|
+
isInherited,
|
|
1742
|
+
apiName
|
|
1743
|
+
});
|
|
1744
|
+
}
|
|
1648
1745
|
function getV2Types() {
|
|
1649
1746
|
return `
|
|
1650
1747
|
export interface ${objectDefIdentifier} extends InterfaceDefinition<"${interfaceDef.apiName}", ${interfaceDef.apiName}>, VersionBound<$ExpectedClientVersion> {
|
|
@@ -1658,9 +1755,9 @@ function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, v2 = false
|
|
|
1658
1755
|
"*": (definition2) => `ObjectTypeLinkDefinition<${getObjectDefIdentifier(definition2.targetType, v2)}, ${definition2.multiplicity}>`
|
|
1659
1756
|
})}
|
|
1660
1757
|
}`,
|
|
1661
|
-
properties: (
|
|
1662
|
-
${stringify(
|
|
1663
|
-
"*": (propertyDefinition) => `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`
|
|
1758
|
+
properties: (properties) => `{
|
|
1759
|
+
${stringify(properties, {
|
|
1760
|
+
"*": (propertyDefinition, _, key) => [`${localPropertyJsdoc(key)}${key}`, `PropertyDef<"${propertyDefinition.type}", "${propertyDefinition.nullable ? "nullable" : "non-nullable"}", "${propertyDefinition.multiplicity ? "array" : "single"}">`]
|
|
1664
1761
|
})}
|
|
1665
1762
|
}`
|
|
1666
1763
|
})}
|
|
@@ -1681,7 +1778,7 @@ function __UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(interfaceDef, v2 = false
|
|
|
1681
1778
|
|
|
1682
1779
|
};`;
|
|
1683
1780
|
}
|
|
1684
|
-
var ExpectedOsdkVersion = "0.
|
|
1781
|
+
var ExpectedOsdkVersion = "0.20.0";
|
|
1685
1782
|
async function generateOntologyMetadataFile(ontology, userAgent, fs2, outDir) {
|
|
1686
1783
|
fs2.writeFile(path16__namespace.default.join(outDir, "OntologyMetadata.ts"), await formatTs(`
|
|
1687
1784
|
import { OntologyMetadata as OM } from "@osdk/api";
|
|
@@ -1702,11 +1799,11 @@ async function generateOntologyMetadataFile(ontology, userAgent, fs2, outDir) {
|
|
|
1702
1799
|
|
|
1703
1800
|
// src/v2.0/generateClientSdkVersionTwoPointZero.ts
|
|
1704
1801
|
async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs2, outDir, packageType = "commonjs") {
|
|
1705
|
-
await
|
|
1802
|
+
await verifyOutDir(outDir, fs2);
|
|
1706
1803
|
const sanitizedOntology = sanitizeMetadata(ontology);
|
|
1707
1804
|
const objectNames = Object.keys(sanitizedOntology.objectTypes).sort((a, b) => a.localeCompare(b));
|
|
1708
1805
|
const actionNames = Object.keys(sanitizedOntology.actionTypes).sort((a, b) => a.localeCompare(b));
|
|
1709
|
-
Object.keys(sanitizedOntology.queryTypes).sort((a, b) => a.localeCompare(b));
|
|
1806
|
+
const queryNames = Object.keys(sanitizedOntology.queryTypes).sort((a, b) => a.localeCompare(b));
|
|
1710
1807
|
const interfaceNames = Object.keys(sanitizedOntology.interfaceTypes ?? {}).sort((a, b) => a.localeCompare(b));
|
|
1711
1808
|
const importExt = packageType === "module" ? ".js" : "";
|
|
1712
1809
|
await fs2.mkdir(outDir, {
|
|
@@ -1717,6 +1814,7 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs2, ou
|
|
|
1717
1814
|
export * from "./ontology/actions/index${importExt}";
|
|
1718
1815
|
export * from "./ontology/objects${importExt}";
|
|
1719
1816
|
export * from "./ontology/interfaces${importExt}";
|
|
1817
|
+
export * from "./ontology/queries/index${importExt}";
|
|
1720
1818
|
`));
|
|
1721
1819
|
await generateOntologyMetadataFile(sanitizedOntology, userAgent, fs2, outDir);
|
|
1722
1820
|
await fs2.writeFile(path16__namespace.default.join(outDir, "Ontology.ts"), await formatTs(`
|
|
@@ -1724,6 +1822,7 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs2, ou
|
|
|
1724
1822
|
import * as Actions from "./ontology/actions/index${importExt}";
|
|
1725
1823
|
import * as Objects from "./ontology/objects${importExt}";
|
|
1726
1824
|
import * as Interfaces from "./ontology/interfaces${importExt}";
|
|
1825
|
+
import * as Queries from "./ontology/queries/index${importExt}";
|
|
1727
1826
|
import { OntologyMetadata } from "./OntologyMetadata${importExt}";
|
|
1728
1827
|
|
|
1729
1828
|
export interface Ontology extends OntologyDefinition<${stringUnionFrom2(objectNames)}> {
|
|
@@ -1739,7 +1838,9 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs2, ou
|
|
|
1739
1838
|
}).join(",\n")}
|
|
1740
1839
|
},
|
|
1741
1840
|
queries: {
|
|
1742
|
-
|
|
1841
|
+
${queryNames.map((queryName) => {
|
|
1842
|
+
return `${queryName}: typeof Queries.${queryName}`;
|
|
1843
|
+
}).join(",\n")}
|
|
1743
1844
|
},
|
|
1744
1845
|
interfaces: {
|
|
1745
1846
|
${interfaceNames.map((objectName) => {
|
|
@@ -1762,7 +1863,9 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs2, ou
|
|
|
1762
1863
|
}).join(",\n")}
|
|
1763
1864
|
},
|
|
1764
1865
|
queries: {
|
|
1765
|
-
|
|
1866
|
+
${queryNames.map((queryName) => {
|
|
1867
|
+
return `${queryName}: Queries.${queryName}`;
|
|
1868
|
+
}).join(",\n")}
|
|
1766
1869
|
},
|
|
1767
1870
|
interfaces: {
|
|
1768
1871
|
${interfaceNames.map((objectName) => {
|
|
@@ -1797,6 +1900,11 @@ async function generateClientSdkVersionTwoPointZero(ontology, userAgent, fs2, ou
|
|
|
1797
1900
|
${Object.keys(ontology.objectTypes).sort((a, b) => a.localeCompare(b)).map((apiName) => `export * from "./objects/${apiName}${importExt}";`).join("\n")}
|
|
1798
1901
|
${Object.keys(ontology.objectTypes).length === 0 ? "export {};" : ""}
|
|
1799
1902
|
`));
|
|
1903
|
+
const queriesDir = path16__namespace.default.join(outDir, "ontology", "queries");
|
|
1904
|
+
await fs2.mkdir(queriesDir, {
|
|
1905
|
+
recursive: true
|
|
1906
|
+
});
|
|
1907
|
+
await generatePerQueryDataFiles(sanitizedOntology, fs2, queriesDir, importExt, true);
|
|
1800
1908
|
}
|
|
1801
1909
|
function stringUnionFrom2(values) {
|
|
1802
1910
|
if (values.length === 0) {
|
|
@@ -1818,7 +1926,7 @@ async function generateOntologyInterfaces(fs2, outDir, interfaceNames, ontology,
|
|
|
1818
1926
|
import { $osdkMetadata, $expectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1819
1927
|
import type { $ExpectedClientVersion } from "../../OntologyMetadata${importExt}";
|
|
1820
1928
|
|
|
1821
|
-
${__UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(obj, true)}
|
|
1929
|
+
${__UNSTABLE_wireInterfaceTypeV2ToSdkObjectConst(obj, ontology, true)}
|
|
1822
1930
|
`));
|
|
1823
1931
|
}
|
|
1824
1932
|
await fs2.writeFile(interfacesDir + ".ts", await formatTs(`
|
|
@@ -1829,8 +1937,7 @@ async function generateOntologyInterfaces(fs2, outDir, interfaceNames, ontology,
|
|
|
1829
1937
|
|
|
1830
1938
|
// src/generateClientSdkPackage.ts
|
|
1831
1939
|
async function generateClientSdkPackage(packageName, packageVersion, sdkVersion, baseOutDir, ontology, minimalFs, dependencyVersions, cliVersion) {
|
|
1832
|
-
if (!packageName)
|
|
1833
|
-
throw new Error("Package name is require");
|
|
1940
|
+
if (!packageName) throw new Error("Package name is require");
|
|
1834
1941
|
for (const packageType of ["module", "commonjs"]) {
|
|
1835
1942
|
const outDir = path16__namespace.join(baseOutDir, "dist", packageType);
|
|
1836
1943
|
await (sdkVersion === "1.1" ? generateClientSdkVersionOneDotOne : sdkVersion === "2.0" ? generateClientSdkVersionTwoPointZero : void 0)(ontology, `typescript-sdk/${packageVersion} osdk-cli/${cliVersion}`, minimalFs, outDir, packageType);
|