@osdk/client 2.0.0-beta.11 → 2.0.0-beta.13
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 +41 -0
- package/build/browser/{chunk-WGFCR4UM.js → chunk-CG25K4WC.js} +734 -620
- package/build/browser/chunk-CG25K4WC.js.map +1 -0
- package/build/browser/index.js +716 -3
- package/build/browser/index.js.map +1 -1
- package/build/browser/public/unstable-do-not-use.js +1 -878
- package/build/browser/public/unstable-do-not-use.js.map +1 -1
- package/build/esm/Client.d.ts +25 -6
- package/build/esm/Client.d.ts.map +1 -1
- package/build/esm/actions/applyAction.d.ts +4 -4
- package/build/esm/actions/applyAction.d.ts.map +1 -1
- package/build/esm/{chunk-WGFCR4UM.js → chunk-MQTCPUPF.js} +737 -620
- package/build/esm/chunk-MQTCPUPF.js.map +1 -0
- package/build/esm/createClient.d.ts.map +1 -1
- package/build/esm/index.js +716 -3
- package/build/esm/index.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.d.ts +2 -2
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.d.ts.map +1 -1
- package/build/esm/object/fetchPage.d.ts.map +1 -1
- package/build/esm/object/object.test.d.ts +3 -4
- package/build/esm/object/object.test.d.ts.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.d.ts.map +1 -1
- package/build/esm/ontology/OntologyProvider.d.ts +6 -6
- package/build/esm/ontology/OntologyProvider.d.ts.map +1 -1
- package/build/esm/ontology/StandardOntologyProvider.d.ts.map +1 -1
- package/build/esm/ontology/loadActionMetadata.d.ts +4 -0
- package/build/esm/ontology/loadActionMetadata.d.ts.map +1 -0
- package/build/esm/ontology/loadFullObjectMetadata.d.ts +2 -2
- package/build/esm/ontology/loadFullObjectMetadata.d.ts.map +1 -1
- package/build/esm/ontology/loadInterfaceMetadata.d.ts +4 -0
- package/build/esm/ontology/loadInterfaceMetadata.d.ts.map +1 -0
- package/build/esm/ontology/loadQueryMetadata.d.ts +4 -0
- package/build/esm/ontology/loadQueryMetadata.d.ts.map +1 -0
- package/build/esm/public/unstable-do-not-use.d.ts +0 -4
- package/build/esm/public/unstable-do-not-use.d.ts.map +1 -1
- package/build/esm/public/unstable-do-not-use.js +1 -881
- package/build/esm/public/unstable-do-not-use.js.map +1 -1
- package/build/esm/queries/applyQuery.d.ts +2 -2
- package/build/esm/queries/applyQuery.d.ts.map +1 -1
- package/build/esm/queries/types.d.ts +3 -3
- package/build/esm/queries/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/build/browser/chunk-WGFCR4UM.js.map +0 -1
- package/build/esm/__unstable/UNSTABLE_createClient.d.ts +0 -4
- package/build/esm/__unstable/UNSTABLE_createClient.d.ts.map +0 -1
- package/build/esm/__unstable/UnstableClient.d.ts +0 -12
- package/build/esm/__unstable/UnstableClient.d.ts.map +0 -1
- package/build/esm/chunk-WGFCR4UM.js.map +0 -1
- package/build/esm/objectSet/ObjectSetListener.d.ts +0 -18
- package/build/esm/objectSet/ObjectSetListener.d.ts.map +0 -1
- package/build/esm/objectSet/createUnstableObjectSet.d.ts +0 -8
- package/build/esm/objectSet/createUnstableObjectSet.d.ts.map +0 -1
- package/build/esm/ontology/loadInterfaceDefinition.d.ts +0 -4
- package/build/esm/ontology/loadInterfaceDefinition.d.ts.map +0 -1
- package/build/esm/ontology/loadQueryDefinition.d.ts +0 -4
- package/build/esm/ontology/loadQueryDefinition.d.ts.map +0 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { symbolClientContext } from '@osdk/shared.client';
|
|
2
2
|
import { PalantirApiError, UnknownError } from '@osdk/shared.net.errors';
|
|
3
3
|
import { createFetchHeaderMutator } from '@osdk/shared.net.fetch';
|
|
4
|
-
import
|
|
5
|
-
import { DistanceUnitMapping,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import invariant5 from 'tiny-invariant';
|
|
5
|
+
import { DistanceUnitMapping, DurationMapping, TimeSeriesProperty, TimeseriesDurationMapping } from '@osdk/client.api';
|
|
6
|
+
import { __EXPERIMENTAL__NOT_SUPPORTED_YET_subscribe } from '@osdk/client.api/unstable';
|
|
7
|
+
import { createTemporaryObjectSet, getLinkTypesForObjectTypes, bulkLoadOntologyEntities, loadAllOntologies } from '@osdk/client.unstable';
|
|
8
|
+
import { batchEnableWatcher } from '@osdk/client.unstable.osw';
|
|
9
|
+
import WebSocket from 'isomorphic-ws';
|
|
8
10
|
|
|
9
11
|
var __defProp = Object.defineProperty;
|
|
10
12
|
var __export = (target, all) => {
|
|
@@ -12,14 +14,6 @@ var __export = (target, all) => {
|
|
|
12
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
// src/actions/ActionValidationError.ts
|
|
16
|
-
var ActionValidationError = class extends Error {
|
|
17
|
-
constructor(validation) {
|
|
18
|
-
super("Validation Error");
|
|
19
|
-
this.validation = validation;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
17
|
// ../internal.foundry.datasets/build/esm/chunk-PZ5AY32C.js
|
|
24
18
|
var __defProp2 = Object.defineProperty;
|
|
25
19
|
var __export2 = (target, all) => {
|
|
@@ -696,19 +690,6 @@ function createAttachmentFromRid(client, rid) {
|
|
|
696
690
|
}
|
|
697
691
|
};
|
|
698
692
|
}
|
|
699
|
-
|
|
700
|
-
// src/object/AttachmentUpload.ts
|
|
701
|
-
function isAttachmentUpload(o) {
|
|
702
|
-
return o instanceof Blob && "name" in o;
|
|
703
|
-
}
|
|
704
|
-
function createAttachmentUpload(data, name) {
|
|
705
|
-
const attachmentUpload = Object.create(data, {
|
|
706
|
-
name: {
|
|
707
|
-
value: name
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
return attachmentUpload;
|
|
711
|
-
}
|
|
712
693
|
var addUserAgentAndRequestContextHeaders = (client, withMetadata) => ({
|
|
713
694
|
...client,
|
|
714
695
|
fetch: createFetchHeaderMutator(client.fetch, (headers) => {
|
|
@@ -1125,7 +1106,7 @@ function makeGeoFilterPolygon(field, coordinates, filterType) {
|
|
|
1125
1106
|
};
|
|
1126
1107
|
}
|
|
1127
1108
|
function handleWherePair([field, filter]) {
|
|
1128
|
-
!(filter != null) ? process.env.NODE_ENV !== "production" ?
|
|
1109
|
+
!(filter != null) ? process.env.NODE_ENV !== "production" ? invariant5(false, "Defined key values are only allowed when they are not undefined.") : invariant5(false) : void 0;
|
|
1129
1110
|
if (typeof filter === "string" || typeof filter === "number" || typeof filter === "boolean") {
|
|
1130
1111
|
return {
|
|
1131
1112
|
type: "eq",
|
|
@@ -1135,12 +1116,12 @@ function handleWherePair([field, filter]) {
|
|
|
1135
1116
|
}
|
|
1136
1117
|
const keysOfFilter = Object.keys(filter);
|
|
1137
1118
|
const hasDollarSign = keysOfFilter.some((key) => key.startsWith("$"));
|
|
1138
|
-
!(!hasDollarSign || keysOfFilter.length === 1) ? process.env.NODE_ENV !== "production" ?
|
|
1119
|
+
!(!hasDollarSign || keysOfFilter.length === 1) ? process.env.NODE_ENV !== "production" ? invariant5(false, "WhereClause Filter with multiple clauses isn't allowed") : invariant5(false) : void 0;
|
|
1139
1120
|
if (!hasDollarSign) {
|
|
1140
1121
|
throw new Error(`Unsupported filter. Did you forget to use a $-prefixed filter? (${JSON.stringify(filter)})`);
|
|
1141
1122
|
}
|
|
1142
1123
|
const firstKey = keysOfFilter[0];
|
|
1143
|
-
!(filter[firstKey] != null) ? process.env.NODE_ENV !== "production" ?
|
|
1124
|
+
!(filter[firstKey] != null) ? process.env.NODE_ENV !== "production" ? invariant5(false) : invariant5(false) : void 0;
|
|
1144
1125
|
if (firstKey === "$ne") {
|
|
1145
1126
|
return {
|
|
1146
1127
|
type: "not",
|
|
@@ -1200,7 +1181,7 @@ function legacyToModernSingleAggregationResult(entry) {
|
|
|
1200
1181
|
if (parts[0] === "count") {
|
|
1201
1182
|
return accumulator;
|
|
1202
1183
|
}
|
|
1203
|
-
!(parts.length === 2) ? process.env.NODE_ENV !== "production" ?
|
|
1184
|
+
!(parts.length === 2) ? process.env.NODE_ENV !== "production" ? invariant5(false, "assumed we were getting a `${key}.${type}`") : invariant5(false) : void 0;
|
|
1204
1185
|
const property = parts[0];
|
|
1205
1186
|
const metricType = parts[1];
|
|
1206
1187
|
if (!(property in accumulator)) {
|
|
@@ -1300,7 +1281,7 @@ async function aggregate(clientCtx, objectType, objectSet = {
|
|
|
1300
1281
|
aggregation: body.aggregation
|
|
1301
1282
|
});
|
|
1302
1283
|
if (!req.$groupBy) {
|
|
1303
|
-
!(result.data.length === 1) ? process.env.NODE_ENV !== "production" ?
|
|
1284
|
+
!(result.data.length === 1) ? process.env.NODE_ENV !== "production" ? invariant5(false, "no group by clause should mean only one data result") : invariant5(false) : void 0;
|
|
1304
1285
|
return {
|
|
1305
1286
|
...aggregationToCountResult(result.data[0]),
|
|
1306
1287
|
...legacyToModernSingleAggregationResult(result.data[0])
|
|
@@ -1367,6 +1348,721 @@ function isWireObjectSet(o) {
|
|
|
1367
1348
|
return o != null && typeof o === "object" && WIRE_OBJECT_SET_TYPES.has(o.type);
|
|
1368
1349
|
}
|
|
1369
1350
|
|
|
1351
|
+
// src/ontology/makeConjureContext.ts
|
|
1352
|
+
function makeConjureContext({
|
|
1353
|
+
baseUrl,
|
|
1354
|
+
fetch: fetchFn,
|
|
1355
|
+
tokenProvider
|
|
1356
|
+
}, servicePath) {
|
|
1357
|
+
return {
|
|
1358
|
+
baseUrl,
|
|
1359
|
+
servicePath,
|
|
1360
|
+
fetchFn,
|
|
1361
|
+
tokenProvider
|
|
1362
|
+
};
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
// src/__unstable/ConjureSupport.ts
|
|
1366
|
+
var cachedAllOntologies;
|
|
1367
|
+
async function getOntologyVersionForRid(ctx, ontologyRid) {
|
|
1368
|
+
cachedAllOntologies ??= await loadAllOntologies(ctx, {});
|
|
1369
|
+
!cachedAllOntologies.ontologies[ontologyRid] ? process.env.NODE_ENV !== "production" ? invariant5(false, "ontology should be loaded") : invariant5(false) : void 0;
|
|
1370
|
+
return cachedAllOntologies.ontologies[ontologyRid].currentOntologyVersion;
|
|
1371
|
+
}
|
|
1372
|
+
var strongMemoAsync = (fn) => createSimpleAsyncCache("strong", fn).get;
|
|
1373
|
+
var weakMemoAsync = (fn) => createSimpleAsyncCache("weak", fn).get;
|
|
1374
|
+
var MetadataClient = class {
|
|
1375
|
+
#client;
|
|
1376
|
+
#ctx;
|
|
1377
|
+
#logger;
|
|
1378
|
+
constructor(client) {
|
|
1379
|
+
this.#client = client;
|
|
1380
|
+
this.#ctx = makeConjureContext(client, "/ontology-metadata/api");
|
|
1381
|
+
this.#client.ontologyProvider.getObjectDefinition;
|
|
1382
|
+
this.#logger = this.#client.logger?.child({
|
|
1383
|
+
mcc: true
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
forObjectByRid = strongMemoAsync(async (rid) => {
|
|
1387
|
+
return Promise.resolve({
|
|
1388
|
+
getPropertyMapping: this.#objectPropertyMapping.bind(this, rid),
|
|
1389
|
+
getLinkMapping: this.#objectLinkMapping.bind(this, rid),
|
|
1390
|
+
getRid: () => rid,
|
|
1391
|
+
getApiName: async () => (await this.#getConjureObjectType(rid)).apiName
|
|
1392
|
+
});
|
|
1393
|
+
});
|
|
1394
|
+
forObjectByApiName = strongMemoAsync(async (objectApiName) => {
|
|
1395
|
+
const objectDef = await this.#client.ontologyProvider.getObjectDefinition(objectApiName);
|
|
1396
|
+
return this.forObjectByRid(objectDef.rid);
|
|
1397
|
+
});
|
|
1398
|
+
#objectPropertyMapping = strongMemoAsync(async (objectTypeRid) => {
|
|
1399
|
+
const conjureObjectType = await this.#getConjureObjectType(objectTypeRid);
|
|
1400
|
+
return createObjectPropertyMapping(conjureObjectType);
|
|
1401
|
+
});
|
|
1402
|
+
#objectLinkMapping = strongMemoAsync(async (objectTypeRid) => {
|
|
1403
|
+
const linkTypes = await getLinkTypesForObjectTypes(this.#ctx, {
|
|
1404
|
+
includeObjectTypesWithoutSearchableDatasources: true,
|
|
1405
|
+
loadRedacted: false,
|
|
1406
|
+
objectTypeBranches: {},
|
|
1407
|
+
objectTypeVersions: {
|
|
1408
|
+
[objectTypeRid]: await this.ontologyVersion("")
|
|
1409
|
+
}
|
|
1410
|
+
});
|
|
1411
|
+
!linkTypes.linkTypes[objectTypeRid] ? process.env.NODE_ENV !== "production" ? invariant5(false, "link type should be loaded") : invariant5(false) : void 0;
|
|
1412
|
+
const ret = {};
|
|
1413
|
+
for (const l of linkTypes.linkTypes[objectTypeRid]) {
|
|
1414
|
+
const helper = ({
|
|
1415
|
+
apiName
|
|
1416
|
+
}, linkSide, otherObjectType) => {
|
|
1417
|
+
if (apiName) {
|
|
1418
|
+
ret[apiName] = {
|
|
1419
|
+
apiName,
|
|
1420
|
+
directedLinkTypeRid: {
|
|
1421
|
+
linkTypeRid: l.rid,
|
|
1422
|
+
linkSide
|
|
1423
|
+
},
|
|
1424
|
+
otherObjectType
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
if (l.definition.type === "oneToMany") {
|
|
1429
|
+
const {
|
|
1430
|
+
oneToMany: {
|
|
1431
|
+
objectTypeRidManySide,
|
|
1432
|
+
manyToOneLinkMetadata,
|
|
1433
|
+
objectTypeRidOneSide,
|
|
1434
|
+
oneToManyLinkMetadata
|
|
1435
|
+
}
|
|
1436
|
+
} = l.definition;
|
|
1437
|
+
if (objectTypeRidManySide === objectTypeRid) {
|
|
1438
|
+
helper(manyToOneLinkMetadata, "TARGET", objectTypeRidOneSide);
|
|
1439
|
+
}
|
|
1440
|
+
if (objectTypeRidOneSide === objectTypeRid) {
|
|
1441
|
+
helper(oneToManyLinkMetadata, "SOURCE", objectTypeRidManySide);
|
|
1442
|
+
}
|
|
1443
|
+
} else if (l.definition.type === "manyToMany") {
|
|
1444
|
+
const {
|
|
1445
|
+
manyToMany: {
|
|
1446
|
+
objectTypeRidA,
|
|
1447
|
+
objectTypeAToBLinkMetadata,
|
|
1448
|
+
objectTypeRidB,
|
|
1449
|
+
objectTypeBToALinkMetadata
|
|
1450
|
+
}
|
|
1451
|
+
} = l.definition;
|
|
1452
|
+
if (objectTypeRidA === objectTypeRid) {
|
|
1453
|
+
helper(objectTypeAToBLinkMetadata, "SOURCE", objectTypeRidB);
|
|
1454
|
+
}
|
|
1455
|
+
if (objectTypeRidB === objectTypeRid) {
|
|
1456
|
+
helper(objectTypeBToALinkMetadata, "TARGET", objectTypeRidA);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
return ret;
|
|
1461
|
+
});
|
|
1462
|
+
#getConjureObjectType = strongMemoAsync(async (objectTypeRid) => {
|
|
1463
|
+
this.#logger?.debug(`getConjureObjectType(${objectTypeRid})`);
|
|
1464
|
+
const body = {
|
|
1465
|
+
datasourceTypes: [],
|
|
1466
|
+
objectTypes: [{
|
|
1467
|
+
identifier: {
|
|
1468
|
+
type: "objectTypeRid",
|
|
1469
|
+
objectTypeRid
|
|
1470
|
+
},
|
|
1471
|
+
versionReference: {
|
|
1472
|
+
type: "ontologyVersion",
|
|
1473
|
+
ontologyVersion: await this.ontologyVersion("")
|
|
1474
|
+
}
|
|
1475
|
+
}],
|
|
1476
|
+
linkTypes: [],
|
|
1477
|
+
sharedPropertyTypes: [],
|
|
1478
|
+
interfaceTypes: [],
|
|
1479
|
+
typeGroups: [],
|
|
1480
|
+
loadRedacted: false,
|
|
1481
|
+
includeObjectTypeCount: void 0,
|
|
1482
|
+
includeObjectTypesWithoutSearchableDatasources: true,
|
|
1483
|
+
includeEntityMetadata: void 0
|
|
1484
|
+
};
|
|
1485
|
+
const entities = await bulkLoadOntologyEntities(this.#ctx, void 0, body);
|
|
1486
|
+
!entities.objectTypes[0]?.objectType ? process.env.NODE_ENV !== "production" ? invariant5(false, "object type should be loaded") : invariant5(false) : void 0;
|
|
1487
|
+
return entities.objectTypes[0].objectType;
|
|
1488
|
+
});
|
|
1489
|
+
ontologyVersion = strongMemoAsync(async (_) => getOntologyVersionForRid(this.#ctx, await this.#client.ontologyRid));
|
|
1490
|
+
};
|
|
1491
|
+
var metadataCacheClient = weakMemoAsync((client) => Promise.resolve(new MetadataClient(client)));
|
|
1492
|
+
function createObjectPropertyMapping(conjureOT) {
|
|
1493
|
+
!(conjureOT.primaryKeys.length === 1) ? process.env.NODE_ENV !== "production" ? invariant5(false, `only one primary key supported, got ${conjureOT.primaryKeys.length}`) : invariant5(false) : void 0;
|
|
1494
|
+
const pkRid = conjureOT.primaryKeys[0];
|
|
1495
|
+
const pkProperty = Object.values(conjureOT.propertyTypes).find((a) => a.rid === pkRid);
|
|
1496
|
+
if (!pkProperty) {
|
|
1497
|
+
throw new Error(`Could not find PK property by rid: ${pkRid}`);
|
|
1498
|
+
}
|
|
1499
|
+
const propertyIdToApiNameMapping = Object.fromEntries(Object.values(conjureOT.propertyTypes).map((property) => {
|
|
1500
|
+
return [property.id, property.apiName];
|
|
1501
|
+
}));
|
|
1502
|
+
const propertyApiNameToIdMapping = Object.fromEntries(Object.values(conjureOT.propertyTypes).map((property) => {
|
|
1503
|
+
return [property.apiName, property.id];
|
|
1504
|
+
}));
|
|
1505
|
+
return {
|
|
1506
|
+
apiName: conjureOT.apiName,
|
|
1507
|
+
id: conjureOT.id,
|
|
1508
|
+
propertyIdToApiNameMapping,
|
|
1509
|
+
propertyApiNameToIdMapping,
|
|
1510
|
+
pk: {
|
|
1511
|
+
rid: pkRid,
|
|
1512
|
+
apiName: pkProperty.apiName,
|
|
1513
|
+
type: pkProperty.type
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
// src/objectSet/conjureUnionType.ts
|
|
1519
|
+
function conjureUnionType(type, value) {
|
|
1520
|
+
return {
|
|
1521
|
+
type,
|
|
1522
|
+
[type]: value
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
// src/objectSet/toConjureObjectSet.ts
|
|
1527
|
+
function toConjureObjectSet(objectSet, objectPropertyMapping) {
|
|
1528
|
+
switch (objectSet.type) {
|
|
1529
|
+
case "base":
|
|
1530
|
+
return conjureUnionType("base", {
|
|
1531
|
+
objectTypeId: objectPropertyMapping.id
|
|
1532
|
+
});
|
|
1533
|
+
case "static":
|
|
1534
|
+
return conjureUnionType("static", {
|
|
1535
|
+
objectRids: objectSet.objects,
|
|
1536
|
+
provenance: void 0
|
|
1537
|
+
});
|
|
1538
|
+
case "reference":
|
|
1539
|
+
return conjureUnionType("referenced", {
|
|
1540
|
+
objectSetRid: objectSet.reference
|
|
1541
|
+
});
|
|
1542
|
+
case "filter":
|
|
1543
|
+
return conjureUnionType("filtered", {
|
|
1544
|
+
objectSet: toConjureObjectSet(objectSet.objectSet, objectPropertyMapping),
|
|
1545
|
+
runtimeDerivedProperties: void 0,
|
|
1546
|
+
filter: mapWhereClauseToObjectSetFilter(objectSet.where, objectPropertyMapping)
|
|
1547
|
+
});
|
|
1548
|
+
case "union":
|
|
1549
|
+
return conjureUnionType("unioned", {
|
|
1550
|
+
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
1551
|
+
});
|
|
1552
|
+
case "intersect":
|
|
1553
|
+
return conjureUnionType("intersected", {
|
|
1554
|
+
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
1555
|
+
});
|
|
1556
|
+
case "subtract":
|
|
1557
|
+
return conjureUnionType("subtracted", {
|
|
1558
|
+
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
1559
|
+
});
|
|
1560
|
+
case "searchAround":
|
|
1561
|
+
throw new Error("not implemented");
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
async function getObjectSetBaseType(objectSet) {
|
|
1565
|
+
switch (objectSet.type) {
|
|
1566
|
+
case "base":
|
|
1567
|
+
return objectSet.objectType;
|
|
1568
|
+
case "static":
|
|
1569
|
+
throw new Error("not implemented");
|
|
1570
|
+
case "reference":
|
|
1571
|
+
throw new Error("not implemented");
|
|
1572
|
+
case "filter":
|
|
1573
|
+
return getObjectSetBaseType(objectSet.objectSet);
|
|
1574
|
+
case "union":
|
|
1575
|
+
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
1576
|
+
case "intersect":
|
|
1577
|
+
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
1578
|
+
case "subtract":
|
|
1579
|
+
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
1580
|
+
case "searchAround":
|
|
1581
|
+
throw new Error("not implemented");
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
function mapWhereClauseToObjectSetFilter(objectSetFilter, propertyMapping) {
|
|
1585
|
+
switch (objectSetFilter.type) {
|
|
1586
|
+
case "lt":
|
|
1587
|
+
return conjureUnionType("range", {
|
|
1588
|
+
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
1589
|
+
lt: objectSetFilter.value,
|
|
1590
|
+
lte: void 0,
|
|
1591
|
+
gt: void 0,
|
|
1592
|
+
gte: void 0
|
|
1593
|
+
});
|
|
1594
|
+
case "gt":
|
|
1595
|
+
return conjureUnionType("range", {
|
|
1596
|
+
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
1597
|
+
gt: objectSetFilter.value,
|
|
1598
|
+
lte: void 0,
|
|
1599
|
+
lt: void 0,
|
|
1600
|
+
gte: void 0
|
|
1601
|
+
});
|
|
1602
|
+
case "lte":
|
|
1603
|
+
return conjureUnionType("range", {
|
|
1604
|
+
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
1605
|
+
lte: objectSetFilter.value,
|
|
1606
|
+
lt: void 0,
|
|
1607
|
+
gt: void 0,
|
|
1608
|
+
gte: void 0
|
|
1609
|
+
});
|
|
1610
|
+
case "gte":
|
|
1611
|
+
return conjureUnionType("range", {
|
|
1612
|
+
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
1613
|
+
gte: objectSetFilter.value,
|
|
1614
|
+
lt: void 0,
|
|
1615
|
+
lte: void 0,
|
|
1616
|
+
gt: void 0
|
|
1617
|
+
});
|
|
1618
|
+
case "eq":
|
|
1619
|
+
return conjureUnionType("exactMatch", {
|
|
1620
|
+
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
1621
|
+
terms: [objectSetFilter.value]
|
|
1622
|
+
});
|
|
1623
|
+
case "and":
|
|
1624
|
+
return conjureUnionType("and", {
|
|
1625
|
+
filters: objectSetFilter.value.map((filter) => mapWhereClauseToObjectSetFilter(filter, propertyMapping))
|
|
1626
|
+
});
|
|
1627
|
+
case "or":
|
|
1628
|
+
return conjureUnionType("or", {
|
|
1629
|
+
filters: objectSetFilter.value.map((filter) => mapWhereClauseToObjectSetFilter(filter, propertyMapping))
|
|
1630
|
+
});
|
|
1631
|
+
case "isNull":
|
|
1632
|
+
return conjureUnionType("not", {
|
|
1633
|
+
filter: {
|
|
1634
|
+
type: "hasProperty",
|
|
1635
|
+
hasProperty: {
|
|
1636
|
+
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field]
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
});
|
|
1640
|
+
case "not":
|
|
1641
|
+
return conjureUnionType("not", {
|
|
1642
|
+
filter: mapWhereClauseToObjectSetFilter(objectSetFilter.value, propertyMapping)
|
|
1643
|
+
});
|
|
1644
|
+
case "contains":
|
|
1645
|
+
case "startsWith":
|
|
1646
|
+
case "containsAllTermsInOrder":
|
|
1647
|
+
case "containsAnyTerm":
|
|
1648
|
+
case "containsAllTerms":
|
|
1649
|
+
case "withinDistanceOf":
|
|
1650
|
+
case "withinBoundingBox":
|
|
1651
|
+
case "intersectsBoundingBox":
|
|
1652
|
+
case "doesNotIntersectBoundingBox":
|
|
1653
|
+
case "withinPolygon":
|
|
1654
|
+
case "intersectsPolygon":
|
|
1655
|
+
case "doesNotIntersectPolygon":
|
|
1656
|
+
case "containsAllTermsInOrderPrefixLastTerm":
|
|
1657
|
+
case "in":
|
|
1658
|
+
throw new Error("not implemented");
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
// src/objectSet/ObjectSetListenerWebsocket.ts
|
|
1663
|
+
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
1664
|
+
var MINIMUM_RECONNECT_DELAY_MS = 5 * 1e3;
|
|
1665
|
+
function doNothing() {
|
|
1666
|
+
}
|
|
1667
|
+
function fillOutListener({
|
|
1668
|
+
onChange = doNothing,
|
|
1669
|
+
onError = doNothing,
|
|
1670
|
+
onOutOfDate = doNothing
|
|
1671
|
+
}) {
|
|
1672
|
+
return {
|
|
1673
|
+
onChange,
|
|
1674
|
+
onError,
|
|
1675
|
+
onOutOfDate
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
function isReady(sub) {
|
|
1679
|
+
return sub.temporaryObjectSetId != null;
|
|
1680
|
+
}
|
|
1681
|
+
function subscriptionIsDone(sub) {
|
|
1682
|
+
return sub.status === "done" || sub.status === "error";
|
|
1683
|
+
}
|
|
1684
|
+
var ObjectSetListenerWebsocket = class _ObjectSetListenerWebsocket {
|
|
1685
|
+
static #instances = /* @__PURE__ */ new WeakMap();
|
|
1686
|
+
// FIXME
|
|
1687
|
+
static getInstance(client) {
|
|
1688
|
+
let instance = _ObjectSetListenerWebsocket.#instances.get(client.clientCacheKey);
|
|
1689
|
+
if (instance == null) {
|
|
1690
|
+
instance = new _ObjectSetListenerWebsocket(client);
|
|
1691
|
+
_ObjectSetListenerWebsocket.#instances.set(client.clientCacheKey, instance);
|
|
1692
|
+
}
|
|
1693
|
+
return instance;
|
|
1694
|
+
}
|
|
1695
|
+
#ws;
|
|
1696
|
+
#lastWsConnect = 0;
|
|
1697
|
+
#client;
|
|
1698
|
+
#logger;
|
|
1699
|
+
/**
|
|
1700
|
+
* map of requestId to all active subscriptions at the time of the request
|
|
1701
|
+
*/
|
|
1702
|
+
#pendingSubscriptions = /* @__PURE__ */ new Map();
|
|
1703
|
+
/**
|
|
1704
|
+
* Map of subscriptionId to Subscription. Note: the subscriptionId may be
|
|
1705
|
+
* temporary and not the actual subscriptionId from the server.
|
|
1706
|
+
*/
|
|
1707
|
+
#subscriptions = /* @__PURE__ */ new Map();
|
|
1708
|
+
#oswContext;
|
|
1709
|
+
#metadataContext;
|
|
1710
|
+
#ossContext;
|
|
1711
|
+
#maybeDisconnectTimeout;
|
|
1712
|
+
// DO NOT CONSTRUCT DIRECTLY. ONLY EXPOSED AS A TESTING SEAM
|
|
1713
|
+
constructor(client, {
|
|
1714
|
+
objectSetExpiryMs = ONE_DAY_MS,
|
|
1715
|
+
minimumReconnectDelayMs = MINIMUM_RECONNECT_DELAY_MS
|
|
1716
|
+
} = {}) {
|
|
1717
|
+
this.OBJECT_SET_EXPIRY_MS = objectSetExpiryMs;
|
|
1718
|
+
this.MINIMUM_RECONNECT_DELAY_MS = minimumReconnectDelayMs;
|
|
1719
|
+
this.#client = client;
|
|
1720
|
+
this.#logger = client.logger?.child({}, {
|
|
1721
|
+
msgPrefix: "<OSW> "
|
|
1722
|
+
});
|
|
1723
|
+
!(client.baseUrl.startsWith("https://") || client.baseUrl.startsWith("http://")) ? process.env.NODE_ENV !== "production" ? invariant5(false, "Stack must be a URL") : invariant5(false) : void 0;
|
|
1724
|
+
this.#oswContext = {
|
|
1725
|
+
baseUrl: client.baseUrl,
|
|
1726
|
+
servicePath: "/object-set-watcher/api",
|
|
1727
|
+
fetchFn: client.fetch,
|
|
1728
|
+
tokenProvider: async () => await client.tokenProvider()
|
|
1729
|
+
};
|
|
1730
|
+
this.#ossContext = {
|
|
1731
|
+
...this.#oswContext,
|
|
1732
|
+
servicePath: "/object-set-service/api"
|
|
1733
|
+
};
|
|
1734
|
+
this.#metadataContext = {
|
|
1735
|
+
...this.#oswContext,
|
|
1736
|
+
servicePath: "/ontology-metadata/api"
|
|
1737
|
+
};
|
|
1738
|
+
}
|
|
1739
|
+
async subscribe(objectSet, listener) {
|
|
1740
|
+
{
|
|
1741
|
+
globalThis.crypto ??= (await import('crypto')).webcrypto;
|
|
1742
|
+
}
|
|
1743
|
+
const sub = {
|
|
1744
|
+
listener: fillOutListener(listener),
|
|
1745
|
+
objectSet,
|
|
1746
|
+
status: "preparing",
|
|
1747
|
+
// Since we don't have a real subscription id yet but we need to keep
|
|
1748
|
+
// track of this reference, we can just use a random uuid.
|
|
1749
|
+
subscriptionId: `TMP-${crypto.randomUUID()}`
|
|
1750
|
+
};
|
|
1751
|
+
this.#subscriptions.set(sub.subscriptionId, sub);
|
|
1752
|
+
this.#initiateSubscribe(sub);
|
|
1753
|
+
return () => {
|
|
1754
|
+
this.#unsubscribe(sub);
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Called at least once for every subscription.
|
|
1759
|
+
*
|
|
1760
|
+
* - Resets pending expiry
|
|
1761
|
+
* - Recreates temporary object set
|
|
1762
|
+
* - Triggers a full subscribe message
|
|
1763
|
+
*
|
|
1764
|
+
* @returns
|
|
1765
|
+
*/
|
|
1766
|
+
async #initiateSubscribe(sub) {
|
|
1767
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
1768
|
+
this.#logger?.trace("#initiateSubscribe()");
|
|
1769
|
+
}
|
|
1770
|
+
if (sub.expiry) {
|
|
1771
|
+
clearTimeout(sub.expiry);
|
|
1772
|
+
}
|
|
1773
|
+
sub.expiry = setTimeout(() => this.#expire(sub), this.OBJECT_SET_EXPIRY_MS);
|
|
1774
|
+
const ontologyRid = await this.#client.ontologyRid;
|
|
1775
|
+
try {
|
|
1776
|
+
const [temporaryObjectSet] = await Promise.all([
|
|
1777
|
+
// create a time-bounded object set representation for watching
|
|
1778
|
+
this.#createTemporaryObjectSet(sub.objectSet),
|
|
1779
|
+
this.#ensureWebsocket(),
|
|
1780
|
+
// look up the object type's rid and ensure that we have enabled object set watcher for that rid
|
|
1781
|
+
// TODO ???
|
|
1782
|
+
getObjectSetBaseType(sub.objectSet).then((baseType) => esm_exports.ObjectTypesV2.getObjectTypeV2(this.#client, ontologyRid, baseType)).then((objectType) => this.#enableObjectSetsWatcher([objectType.rid]))
|
|
1783
|
+
]);
|
|
1784
|
+
if (subscriptionIsDone(sub)) {
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
sub.temporaryObjectSetId = temporaryObjectSet.objectSetRid;
|
|
1788
|
+
if (this.#ws?.readyState === WebSocket.OPEN) {
|
|
1789
|
+
this.#sendSubscribeMessage();
|
|
1790
|
+
}
|
|
1791
|
+
} catch (error) {
|
|
1792
|
+
this.#logger?.error(error, "Error in #initiateSubscribe");
|
|
1793
|
+
sub.listener.onError(error);
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1796
|
+
#sendSubscribeMessage() {
|
|
1797
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
1798
|
+
this.#logger?.trace("#sendSubscribeMessage()");
|
|
1799
|
+
}
|
|
1800
|
+
const readySubs = [...this.#subscriptions.values()].filter(isReady);
|
|
1801
|
+
if (readySubs.length === 0) {
|
|
1802
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
1803
|
+
this.#logger?.trace("#sendSubscribeMessage(): aborting due to no ready subscriptions");
|
|
1804
|
+
}
|
|
1805
|
+
return;
|
|
1806
|
+
}
|
|
1807
|
+
const id = crypto.randomUUID();
|
|
1808
|
+
this.#pendingSubscriptions.set(id, readySubs);
|
|
1809
|
+
const subscribe = {
|
|
1810
|
+
id,
|
|
1811
|
+
requests: readySubs.map(({
|
|
1812
|
+
temporaryObjectSetId
|
|
1813
|
+
}) => ({
|
|
1814
|
+
objectSet: temporaryObjectSetId,
|
|
1815
|
+
objectSetContext: {
|
|
1816
|
+
objectSetFilterContext: {
|
|
1817
|
+
parameterOverrides: {}
|
|
1818
|
+
}
|
|
1819
|
+
},
|
|
1820
|
+
watchAllLinks: false
|
|
1821
|
+
}))
|
|
1822
|
+
};
|
|
1823
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
1824
|
+
this.#logger?.trace({
|
|
1825
|
+
payload: subscribe
|
|
1826
|
+
}, "sending subscribe message");
|
|
1827
|
+
}
|
|
1828
|
+
this.#ws?.send(JSON.stringify(subscribe));
|
|
1829
|
+
}
|
|
1830
|
+
#expire(sub) {
|
|
1831
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
1832
|
+
this.#logger?.trace({
|
|
1833
|
+
subscription: sub
|
|
1834
|
+
}, "#expire()");
|
|
1835
|
+
}
|
|
1836
|
+
sub.status = "expired";
|
|
1837
|
+
this.#initiateSubscribe(sub);
|
|
1838
|
+
}
|
|
1839
|
+
#unsubscribe(sub, newStatus = "done") {
|
|
1840
|
+
if (subscriptionIsDone(sub)) {
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
sub.status = newStatus;
|
|
1844
|
+
sub.listener = fillOutListener({});
|
|
1845
|
+
if (sub.expiry) {
|
|
1846
|
+
clearTimeout(sub.expiry);
|
|
1847
|
+
sub.expiry = void 0;
|
|
1848
|
+
}
|
|
1849
|
+
this.#subscriptions.delete(sub.subscriptionId);
|
|
1850
|
+
if (this.#maybeDisconnectTimeout) {
|
|
1851
|
+
clearTimeout(this.#maybeDisconnectTimeout);
|
|
1852
|
+
}
|
|
1853
|
+
this.#maybeDisconnectTimeout = setTimeout(
|
|
1854
|
+
() => {
|
|
1855
|
+
this.#maybeDisconnectTimeout = void 0;
|
|
1856
|
+
if (this.#subscriptions.size === 0) {
|
|
1857
|
+
this.#cycleWebsocket();
|
|
1858
|
+
}
|
|
1859
|
+
},
|
|
1860
|
+
15e3
|
|
1861
|
+
/* ms */
|
|
1862
|
+
);
|
|
1863
|
+
}
|
|
1864
|
+
async #ensureWebsocket() {
|
|
1865
|
+
if (this.#ws == null) {
|
|
1866
|
+
const {
|
|
1867
|
+
baseUrl,
|
|
1868
|
+
tokenProvider
|
|
1869
|
+
} = this.#client;
|
|
1870
|
+
const base = new URL(baseUrl);
|
|
1871
|
+
const url = `wss://${base.host}/object-set-watcher/ws/subscriptions`;
|
|
1872
|
+
const token = await tokenProvider();
|
|
1873
|
+
if (this.#ws == null) {
|
|
1874
|
+
const nextConnectTime = (this.#lastWsConnect ?? 0) + this.MINIMUM_RECONNECT_DELAY_MS;
|
|
1875
|
+
if (nextConnectTime > Date.now()) {
|
|
1876
|
+
await new Promise((resolve) => {
|
|
1877
|
+
setTimeout(resolve, nextConnectTime - Date.now());
|
|
1878
|
+
});
|
|
1879
|
+
}
|
|
1880
|
+
this.#lastWsConnect = Date.now();
|
|
1881
|
+
if (this.#ws == null) {
|
|
1882
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
1883
|
+
this.#logger?.trace("Creating websocket");
|
|
1884
|
+
}
|
|
1885
|
+
this.#ws = new WebSocket(url, [`Bearer-${token}`]);
|
|
1886
|
+
this.#ws.addEventListener("close", this.#onClose);
|
|
1887
|
+
this.#ws.addEventListener("message", this.#onMessage);
|
|
1888
|
+
this.#ws.addEventListener("open", this.#onOpen);
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
if (this.#ws.readyState === WebSocket.CONNECTING) {
|
|
1892
|
+
const ws = this.#ws;
|
|
1893
|
+
return new Promise((resolve, reject) => {
|
|
1894
|
+
function cleanup() {
|
|
1895
|
+
ws.removeEventListener("open", open);
|
|
1896
|
+
ws.removeEventListener("error", error);
|
|
1897
|
+
ws.removeEventListener("close", cleanup);
|
|
1898
|
+
}
|
|
1899
|
+
function open() {
|
|
1900
|
+
cleanup();
|
|
1901
|
+
resolve();
|
|
1902
|
+
}
|
|
1903
|
+
function error(evt) {
|
|
1904
|
+
cleanup();
|
|
1905
|
+
reject(evt);
|
|
1906
|
+
}
|
|
1907
|
+
ws.addEventListener("open", open);
|
|
1908
|
+
ws.addEventListener("error", error);
|
|
1909
|
+
ws.addEventListener("close", cleanup);
|
|
1910
|
+
});
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
#onOpen = () => {
|
|
1915
|
+
this.#sendSubscribeMessage();
|
|
1916
|
+
};
|
|
1917
|
+
#onMessage = async (message) => {
|
|
1918
|
+
const data = JSON.parse(message.data.toString());
|
|
1919
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
1920
|
+
this.#logger?.trace({
|
|
1921
|
+
payload: data
|
|
1922
|
+
}, "received message from ws");
|
|
1923
|
+
}
|
|
1924
|
+
switch (data.type) {
|
|
1925
|
+
case "objectSetChanged":
|
|
1926
|
+
return this.#handleMessage_objectSetChanged(data.objectSetChanged);
|
|
1927
|
+
case "refreshObjectSet":
|
|
1928
|
+
return this.#handleMessage_refreshObjectSet(data.refreshObjectSet);
|
|
1929
|
+
case "subscribeResponses":
|
|
1930
|
+
return this.#handleMessage_subscribeResponses(data.subscribeResponses);
|
|
1931
|
+
case "subscriptionClosed": {
|
|
1932
|
+
const payload = data.subscriptionClosed;
|
|
1933
|
+
return this.#handleMessage_subscriptionClosed(payload);
|
|
1934
|
+
}
|
|
1935
|
+
default:
|
|
1936
|
+
process.env.NODE_ENV !== "production" ? invariant5(false, "Unexpected message type") : invariant5(false) ;
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
#handleMessage_objectSetChanged = async (payload) => {
|
|
1940
|
+
const sub = this.#subscriptions.get(payload.id);
|
|
1941
|
+
!sub ? process.env.NODE_ENV !== "production" ? invariant5(false, `Expected subscription id ${payload.id}`) : invariant5(false) : void 0;
|
|
1942
|
+
if ("confidenceValue" in payload) {
|
|
1943
|
+
sub.listener.onOutOfDate();
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
const objects = payload.updates.filter(function(a) {
|
|
1947
|
+
return a.type === "object";
|
|
1948
|
+
}).map((a) => a.object);
|
|
1949
|
+
!(objects.length === payload.updates.length) ? process.env.NODE_ENV !== "production" ? invariant5(false, "currently only support full updates not reference updates") : invariant5(false) : void 0;
|
|
1950
|
+
sub.listener.onChange(await convertFoundryToOsdkObjects(this.#client, this.#metadataContext, objects));
|
|
1951
|
+
};
|
|
1952
|
+
#handleMessage_refreshObjectSet = (payload) => {
|
|
1953
|
+
const sub = this.#subscriptions.get(payload.id);
|
|
1954
|
+
!sub ? process.env.NODE_ENV !== "production" ? invariant5(false, `Expected subscription id ${payload.id}`) : invariant5(false) : void 0;
|
|
1955
|
+
sub.listener.onOutOfDate();
|
|
1956
|
+
};
|
|
1957
|
+
#handleMessage_subscribeResponses = (payload) => {
|
|
1958
|
+
const {
|
|
1959
|
+
id,
|
|
1960
|
+
responses
|
|
1961
|
+
} = payload;
|
|
1962
|
+
const subs = this.#pendingSubscriptions.get(id);
|
|
1963
|
+
!subs ? process.env.NODE_ENV !== "production" ? invariant5(false, `should have a pending subscription for ${id}`) : invariant5(false) : void 0;
|
|
1964
|
+
this.#pendingSubscriptions.delete(id);
|
|
1965
|
+
for (let i = 0; i < responses.length; i++) {
|
|
1966
|
+
const sub = subs[i];
|
|
1967
|
+
const response = responses[i];
|
|
1968
|
+
switch (response.type) {
|
|
1969
|
+
case "error":
|
|
1970
|
+
sub.listener.onError(response.error);
|
|
1971
|
+
this.#unsubscribe(sub, "error");
|
|
1972
|
+
break;
|
|
1973
|
+
case "qos":
|
|
1974
|
+
this.#cycleWebsocket();
|
|
1975
|
+
break;
|
|
1976
|
+
case "success":
|
|
1977
|
+
const shouldFireOutOfDate = sub.status === "expired" || sub.status === "reconnecting";
|
|
1978
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
1979
|
+
this.#logger?.trace({
|
|
1980
|
+
shouldFireOutOfDate
|
|
1981
|
+
}, "success");
|
|
1982
|
+
}
|
|
1983
|
+
sub.status = "subscribed";
|
|
1984
|
+
if (sub.subscriptionId !== response.success.id) {
|
|
1985
|
+
this.#subscriptions.delete(sub.subscriptionId);
|
|
1986
|
+
sub.subscriptionId = response.success.id;
|
|
1987
|
+
this.#subscriptions.set(sub.subscriptionId, sub);
|
|
1988
|
+
}
|
|
1989
|
+
if (shouldFireOutOfDate) sub.listener.onOutOfDate();
|
|
1990
|
+
break;
|
|
1991
|
+
default:
|
|
1992
|
+
sub.listener.onError(response);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
};
|
|
1996
|
+
#handleMessage_subscriptionClosed(payload) {
|
|
1997
|
+
const sub = this.#subscriptions.get(payload.id);
|
|
1998
|
+
!sub ? process.env.NODE_ENV !== "production" ? invariant5(false, `Expected subscription id ${payload.id}`) : invariant5(false) : void 0;
|
|
1999
|
+
sub.listener.onError(payload.error);
|
|
2000
|
+
this.#unsubscribe(sub, "error");
|
|
2001
|
+
}
|
|
2002
|
+
#onClose = (event) => {
|
|
2003
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
2004
|
+
this.#logger?.trace({
|
|
2005
|
+
event
|
|
2006
|
+
}, "Received close event from ws", event);
|
|
2007
|
+
}
|
|
2008
|
+
this.#cycleWebsocket();
|
|
2009
|
+
};
|
|
2010
|
+
async #enableObjectSetsWatcher(objectTypeRids) {
|
|
2011
|
+
return batchEnableWatcher(this.#oswContext, {
|
|
2012
|
+
requests: objectTypeRids
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
async #createTemporaryObjectSet(objectSet) {
|
|
2016
|
+
const objectSetBaseType = await getObjectSetBaseType(objectSet);
|
|
2017
|
+
const mcc = await metadataCacheClient(this.#client);
|
|
2018
|
+
const objectInfo = await mcc.forObjectByApiName(objectSetBaseType);
|
|
2019
|
+
const propMapping = await objectInfo.getPropertyMapping();
|
|
2020
|
+
const temporaryObjectSet = await createTemporaryObjectSet(this.#ossContext, {
|
|
2021
|
+
objectSet: toConjureObjectSet(objectSet, propMapping),
|
|
2022
|
+
timeToLive: "ONE_DAY",
|
|
2023
|
+
// MUST keep in sync with the value for expiry in `#initiateSubscribe`.
|
|
2024
|
+
objectSetFilterContext: {
|
|
2025
|
+
parameterOverrides: {}
|
|
2026
|
+
}
|
|
2027
|
+
});
|
|
2028
|
+
return {
|
|
2029
|
+
objectSetRid: temporaryObjectSet.objectSetRid
|
|
2030
|
+
};
|
|
2031
|
+
}
|
|
2032
|
+
#cycleWebsocket = () => {
|
|
2033
|
+
if (this.#ws) {
|
|
2034
|
+
this.#ws.removeEventListener("open", this.#onOpen);
|
|
2035
|
+
this.#ws.removeEventListener("message", this.#onMessage);
|
|
2036
|
+
this.#ws.removeEventListener("close", this.#onClose);
|
|
2037
|
+
if (this.#ws.readyState !== WebSocket.CLOSING && this.#ws.readyState !== WebSocket.CLOSED) {
|
|
2038
|
+
this.#ws.close();
|
|
2039
|
+
}
|
|
2040
|
+
this.#ws = void 0;
|
|
2041
|
+
}
|
|
2042
|
+
if (this.#subscriptions.size > 0) {
|
|
2043
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
2044
|
+
for (const s of this.#subscriptions.values()) {
|
|
2045
|
+
!(s.status !== "done" && s.status !== "error") ? process.env.NODE_ENV !== "production" ? invariant5(false, "should not have done/error subscriptions still") : invariant5(false) : void 0;
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
for (const s of this.#subscriptions.values()) {
|
|
2049
|
+
if (s.status === "subscribed") s.status = "reconnecting";
|
|
2050
|
+
}
|
|
2051
|
+
this.#ensureWebsocket();
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
};
|
|
2055
|
+
async function convertFoundryToOsdkObjects(client, ctx, objects) {
|
|
2056
|
+
const osdkObjects = await Promise.all(objects.map(async (object) => {
|
|
2057
|
+
const propertyMapping = await (await (await metadataCacheClient(client)).forObjectByRid(object.type)).getPropertyMapping();
|
|
2058
|
+
const convertedObject = Object.fromEntries([...Object.entries(object.properties).map(([key, value]) => {
|
|
2059
|
+
return [propertyMapping?.propertyIdToApiNameMapping[key], value];
|
|
2060
|
+
}), [propertyMapping?.propertyIdToApiNameMapping[Object.entries(object.key)[0][0]], Object.entries(object.key)[0][1]], ["__apiName", propertyMapping?.apiName], ["$apiName", propertyMapping?.apiName]]);
|
|
2061
|
+
return convertedObject;
|
|
2062
|
+
}));
|
|
2063
|
+
return await convertWireToOsdkObjects(client, osdkObjects, void 0);
|
|
2064
|
+
}
|
|
2065
|
+
|
|
1370
2066
|
// src/objectSet/createObjectSet.ts
|
|
1371
2067
|
function isObjectTypeDefinition(def) {
|
|
1372
2068
|
return def.type === "object";
|
|
@@ -1420,12 +2116,13 @@ function createObjectSet(objectType, clientCtx, objectSet = {
|
|
|
1420
2116
|
objectSets: [objectSet, ...objectSets.map((os) => objectSetDefinitions.get(os))]
|
|
1421
2117
|
});
|
|
1422
2118
|
},
|
|
1423
|
-
asyncIter: async function* () {
|
|
2119
|
+
asyncIter: async function* (args) {
|
|
1424
2120
|
let $nextPageToken = void 0;
|
|
1425
2121
|
do {
|
|
1426
2122
|
const result = await fetchPageInternal(augmentRequestContext(clientCtx, (_) => ({
|
|
1427
2123
|
finalMethodCall: "asyncIter"
|
|
1428
2124
|
})), objectType, objectSet, {
|
|
2125
|
+
...args,
|
|
1429
2126
|
$nextPageToken
|
|
1430
2127
|
});
|
|
1431
2128
|
$nextPageToken = result.nextPageToken;
|
|
@@ -1443,7 +2140,11 @@ function createObjectSet(objectType, clientCtx, objectSet = {
|
|
|
1443
2140
|
return await fetchSingleWithErrors(augmentRequestContext(clientCtx, (_) => ({
|
|
1444
2141
|
finalMethodCall: "fetchOneWithErrors"
|
|
1445
2142
|
})), objectType, options, await createWithPk(clientCtx, objectType, objectSet, primaryKey));
|
|
1446
|
-
} : void 0
|
|
2143
|
+
} : void 0,
|
|
2144
|
+
[__EXPERIMENTAL__NOT_SUPPORTED_YET_subscribe]: (listener) => {
|
|
2145
|
+
const pendingSubscribe = ObjectSetListenerWebsocket.getInstance(clientCtx).subscribe(objectSet, listener);
|
|
2146
|
+
return async () => (await pendingSubscribe)();
|
|
2147
|
+
}
|
|
1447
2148
|
};
|
|
1448
2149
|
function createSearchAround(link) {
|
|
1449
2150
|
return () => {
|
|
@@ -1607,7 +2308,7 @@ async function convertWireToOsdkObjects(client, objects, interfaceApiName, force
|
|
|
1607
2308
|
const ret = [];
|
|
1608
2309
|
for (const rawObj of objects) {
|
|
1609
2310
|
const objectDef = await client.ontologyProvider.getObjectDefinition(rawObj.$apiName);
|
|
1610
|
-
!objectDef ? process.env.NODE_ENV !== "production" ?
|
|
2311
|
+
!objectDef ? process.env.NODE_ENV !== "production" ? invariant5(false, `Missing definition for '${rawObj.$apiName}'`) : invariant5(false) : void 0;
|
|
1611
2312
|
let objProps;
|
|
1612
2313
|
let conforming = true;
|
|
1613
2314
|
if (ifaceDef && ifaceSelected) {
|
|
@@ -1799,590 +2500,6 @@ async function fetchObjectPage(client, objectType, args, objectSet) {
|
|
|
1799
2500
|
});
|
|
1800
2501
|
}
|
|
1801
2502
|
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
}
|
|
1806
|
-
|
|
1807
|
-
// src/util/isOsdkObject.ts
|
|
1808
|
-
function isOsdkBaseObject(o) {
|
|
1809
|
-
return o && typeof o === "object" && typeof o.$apiName === "string" && o.$primaryKey != null;
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
// src/util/toDataValue.ts
|
|
1813
|
-
async function toDataValue(value, client) {
|
|
1814
|
-
if (value == null) {
|
|
1815
|
-
return value;
|
|
1816
|
-
}
|
|
1817
|
-
if (Array.isArray(value) || value instanceof Set) {
|
|
1818
|
-
const promiseArray = Array.from(value, async (innerValue) => await toDataValue(innerValue, client));
|
|
1819
|
-
return Promise.all(promiseArray);
|
|
1820
|
-
}
|
|
1821
|
-
if (isAttachmentUpload(value)) {
|
|
1822
|
-
const attachment = await esm_exports.Attachments.uploadAttachmentV2(client, value, {
|
|
1823
|
-
filename: value.name
|
|
1824
|
-
});
|
|
1825
|
-
return await toDataValue(attachment.rid, client);
|
|
1826
|
-
}
|
|
1827
|
-
if (isOntologyObjectV2(value)) {
|
|
1828
|
-
return await toDataValue(value.__primaryKey, client);
|
|
1829
|
-
}
|
|
1830
|
-
if (isOsdkBaseObject(value)) {
|
|
1831
|
-
return await toDataValue(value.$primaryKey, client);
|
|
1832
|
-
}
|
|
1833
|
-
if (isWireObjectSet(value)) {
|
|
1834
|
-
return value;
|
|
1835
|
-
}
|
|
1836
|
-
if (isObjectSet(value)) {
|
|
1837
|
-
return getWireObjectSet(value);
|
|
1838
|
-
}
|
|
1839
|
-
if (typeof value === "object") {
|
|
1840
|
-
return Object.entries(value).reduce(async (promisedAcc, [key, structValue]) => {
|
|
1841
|
-
const acc = await promisedAcc;
|
|
1842
|
-
acc[key] = await toDataValue(structValue, client);
|
|
1843
|
-
return acc;
|
|
1844
|
-
}, Promise.resolve({}));
|
|
1845
|
-
}
|
|
1846
|
-
return value;
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
// src/actions/applyAction.ts
|
|
1850
|
-
async function applyAction2(client, action, parameters, options = {}) {
|
|
1851
|
-
const clientWithHeaders = addUserAgentAndRequestContextHeaders(augmentRequestContext(client, (_) => ({
|
|
1852
|
-
finalMethodCall: "applyAction"
|
|
1853
|
-
})), action);
|
|
1854
|
-
if (Array.isArray(parameters)) {
|
|
1855
|
-
const response = await esm_exports.Actions.applyActionBatchV2(clientWithHeaders, await client.ontologyRid, action.apiName, {
|
|
1856
|
-
requests: parameters ? await remapBatchActionParams(parameters, client) : [],
|
|
1857
|
-
options: {
|
|
1858
|
-
returnEdits: options?.$returnEdits ? "ALL" : "NONE"
|
|
1859
|
-
}
|
|
1860
|
-
});
|
|
1861
|
-
const edits = response.edits;
|
|
1862
|
-
return options?.$returnEdits ? edits?.type === "edits" ? remapActionResponse(response) : edits : void 0;
|
|
1863
|
-
} else {
|
|
1864
|
-
const response = await esm_exports.Actions.applyActionV2(clientWithHeaders, await client.ontologyRid, action.apiName, {
|
|
1865
|
-
parameters: await remapActionParams(parameters, client),
|
|
1866
|
-
options: {
|
|
1867
|
-
mode: options?.$validateOnly ? "VALIDATE_ONLY" : "VALIDATE_AND_EXECUTE",
|
|
1868
|
-
returnEdits: options?.$returnEdits ? "ALL" : "NONE"
|
|
1869
|
-
}
|
|
1870
|
-
});
|
|
1871
|
-
if (options?.$validateOnly) {
|
|
1872
|
-
return response.validation;
|
|
1873
|
-
}
|
|
1874
|
-
if (response.validation?.result === "INVALID") {
|
|
1875
|
-
throw new ActionValidationError(response.validation);
|
|
1876
|
-
}
|
|
1877
|
-
const edits = response.edits;
|
|
1878
|
-
return options?.$returnEdits ? edits?.type === "edits" ? remapActionResponse(response) : edits : void 0;
|
|
1879
|
-
}
|
|
1880
|
-
}
|
|
1881
|
-
async function remapActionParams(params, client) {
|
|
1882
|
-
if (params == null) {
|
|
1883
|
-
return {};
|
|
1884
|
-
}
|
|
1885
|
-
const parameterMap = {};
|
|
1886
|
-
for (const [key, value] of Object.entries(params)) {
|
|
1887
|
-
parameterMap[key] = await toDataValue(value, client);
|
|
1888
|
-
}
|
|
1889
|
-
return parameterMap;
|
|
1890
|
-
}
|
|
1891
|
-
async function remapBatchActionParams(params, client) {
|
|
1892
|
-
const remappedParams = await Promise.all(params.map(async (param) => {
|
|
1893
|
-
return {
|
|
1894
|
-
parameters: await remapActionParams(param, client)
|
|
1895
|
-
};
|
|
1896
|
-
}));
|
|
1897
|
-
return remappedParams;
|
|
1898
|
-
}
|
|
1899
|
-
function remapActionResponse(response) {
|
|
1900
|
-
const editResponses = response?.edits;
|
|
1901
|
-
if (editResponses?.type === "edits") {
|
|
1902
|
-
const remappedActionResponse = {
|
|
1903
|
-
type: editResponses.type,
|
|
1904
|
-
deletedLinksCount: editResponses.deletedLinksCount,
|
|
1905
|
-
deletedObjectsCount: editResponses.deletedObjectsCount,
|
|
1906
|
-
addedLinks: [],
|
|
1907
|
-
addedObjects: [],
|
|
1908
|
-
modifiedObjects: [],
|
|
1909
|
-
editedObjectTypes: []
|
|
1910
|
-
};
|
|
1911
|
-
const editedObjectTypesSet = /* @__PURE__ */ new Set();
|
|
1912
|
-
for (const edit of editResponses.edits) {
|
|
1913
|
-
if (edit.type === "addLink") {
|
|
1914
|
-
remappedActionResponse.addedLinks.push({
|
|
1915
|
-
linkTypeApiNameAtoB: edit.linkTypeApiNameAtoB,
|
|
1916
|
-
linkTypeApiNameBtoA: edit.linkTypeApiNameBtoA,
|
|
1917
|
-
aSideObject: edit.aSideObject,
|
|
1918
|
-
bSideObject: edit.bSideObject
|
|
1919
|
-
});
|
|
1920
|
-
editedObjectTypesSet.add(edit.aSideObject.objectType);
|
|
1921
|
-
editedObjectTypesSet.add(edit.bSideObject.objectType);
|
|
1922
|
-
} else if (edit.type === "addObject") {
|
|
1923
|
-
remappedActionResponse.addedObjects.push({
|
|
1924
|
-
objectType: edit.objectType,
|
|
1925
|
-
primaryKey: edit.primaryKey
|
|
1926
|
-
});
|
|
1927
|
-
editedObjectTypesSet.add(edit.objectType);
|
|
1928
|
-
} else if (edit.type === "modifyObject") {
|
|
1929
|
-
remappedActionResponse.modifiedObjects.push({
|
|
1930
|
-
objectType: edit.objectType,
|
|
1931
|
-
primaryKey: edit.primaryKey
|
|
1932
|
-
});
|
|
1933
|
-
editedObjectTypesSet.add(edit.objectType);
|
|
1934
|
-
} else {
|
|
1935
|
-
process.env.NODE_ENV !== "production" ? invariant(false, "Unknown edit type") : invariant(false) ;
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
remappedActionResponse.editedObjectTypes = [...editedObjectTypesSet];
|
|
1939
|
-
return remappedActionResponse;
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
async function loadFullObjectMetadata(client, objectType) {
|
|
1943
|
-
const full = await esm_exports.ObjectTypesV2.getObjectTypeFullMetadata(client, await client.ontologyRid, objectType, {
|
|
1944
|
-
preview: true
|
|
1945
|
-
});
|
|
1946
|
-
const ret = wireObjectTypeFullMetadataToSdkObjectTypeDefinition(full, true);
|
|
1947
|
-
client.logger?.debug(`END loadFullObjectMetadata(${objectType})`);
|
|
1948
|
-
return {
|
|
1949
|
-
...ret,
|
|
1950
|
-
rid: full.objectType.rid
|
|
1951
|
-
};
|
|
1952
|
-
}
|
|
1953
|
-
async function loadInterfaceDefinition(client, objectType) {
|
|
1954
|
-
const r = await esm_exports.OntologyInterfaces.getInterfaceType(client, await client.ontologyRid, objectType, {
|
|
1955
|
-
preview: true
|
|
1956
|
-
});
|
|
1957
|
-
return __UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(r, true);
|
|
1958
|
-
}
|
|
1959
|
-
async function loadQueryDefinition(client, queryType) {
|
|
1960
|
-
const r = await esm_exports.QueryTypes.getQueryTypeV2(client, await client.ontologyRid, queryType);
|
|
1961
|
-
return wireQueryTypeV2ToSdkQueryDefinition(r);
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
// src/ontology/StandardOntologyProvider.ts
|
|
1965
|
-
var createStandardOntologyProviderFactory = (client) => {
|
|
1966
|
-
return (client2) => {
|
|
1967
|
-
async function loadObject(client3, key) {
|
|
1968
|
-
let objectDef = await loadFullObjectMetadata(client3, key);
|
|
1969
|
-
const interfaceDefs = Object.fromEntries((await Promise.all(objectDef.implements?.map((i) => ret.getInterfaceDefinition(i)) ?? [])).map((i) => [i.apiName, {
|
|
1970
|
-
def: i,
|
|
1971
|
-
handler: void 0
|
|
1972
|
-
}]));
|
|
1973
|
-
const fullObjectDef = {
|
|
1974
|
-
...objectDef,
|
|
1975
|
-
[InterfaceDefinitions]: interfaceDefs
|
|
1976
|
-
};
|
|
1977
|
-
return fullObjectDef;
|
|
1978
|
-
}
|
|
1979
|
-
async function loadInterface(client3, key) {
|
|
1980
|
-
return loadInterfaceDefinition(client3, key);
|
|
1981
|
-
}
|
|
1982
|
-
async function loadQuery(client3, key) {
|
|
1983
|
-
const r = await loadQueryDefinition(client3, key);
|
|
1984
|
-
return r;
|
|
1985
|
-
}
|
|
1986
|
-
function makeGetter(fn) {
|
|
1987
|
-
const cache = createAsyncClientCache((client3, key) => fn(client3, key, false));
|
|
1988
|
-
return async (apiName) => {
|
|
1989
|
-
return await cache.get(client2, apiName);
|
|
1990
|
-
};
|
|
1991
|
-
}
|
|
1992
|
-
const ret = {
|
|
1993
|
-
getObjectDefinition: makeGetter(loadObject),
|
|
1994
|
-
getInterfaceDefinition: makeGetter(loadInterface),
|
|
1995
|
-
getQueryDefinition: makeGetter(loadQuery)
|
|
1996
|
-
};
|
|
1997
|
-
return ret;
|
|
1998
|
-
};
|
|
1999
|
-
};
|
|
2000
|
-
|
|
2001
|
-
// src/util/UserAgent.ts
|
|
2002
|
-
var USER_AGENT = `osdk-client/${"2.0.0-beta.11"}`;
|
|
2003
|
-
|
|
2004
|
-
// src/createMinimalClient.ts
|
|
2005
|
-
function createMinimalClient(metadata, baseUrl, tokenProvider, options = {}, fetchFn = global.fetch, objectSetFactory = createObjectSet) {
|
|
2006
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
2007
|
-
try {
|
|
2008
|
-
new URL(baseUrl);
|
|
2009
|
-
} catch (e) {
|
|
2010
|
-
const hint = !baseUrl.startsWith("http://") || !baseUrl.startsWith("https://") ? ". Did you forget to add 'http://' or 'https://'?" : "";
|
|
2011
|
-
throw new Error(`Invalid stack URL: ${baseUrl}${hint}`);
|
|
2012
|
-
}
|
|
2013
|
-
}
|
|
2014
|
-
const minimalClient = {
|
|
2015
|
-
...createSharedClientContext(baseUrl, tokenProvider, USER_AGENT, fetchFn),
|
|
2016
|
-
objectSetFactory,
|
|
2017
|
-
ontologyRid: metadata.ontologyRid,
|
|
2018
|
-
logger: options.logger,
|
|
2019
|
-
clientCacheKey: {},
|
|
2020
|
-
requestContext: {}
|
|
2021
|
-
};
|
|
2022
|
-
return Object.assign(minimalClient, {
|
|
2023
|
-
ontologyProvider: createStandardOntologyProviderFactory()(minimalClient)
|
|
2024
|
-
});
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
// src/fetchMetadata.ts
|
|
2028
|
-
var fetchMetadataInternal = async (client, definition) => {
|
|
2029
|
-
if (definition.type === "object") {
|
|
2030
|
-
return fetchObjectMetadata(client, definition);
|
|
2031
|
-
} else if (definition.type === "interface") {
|
|
2032
|
-
return fetchInterfaceMetadata(client, definition);
|
|
2033
|
-
} else if (definition.type === "action") {
|
|
2034
|
-
return fetchActionMetadata(client, definition);
|
|
2035
|
-
} else if (definition.type === "query") {
|
|
2036
|
-
return fetchQueryMetadata(client, definition);
|
|
2037
|
-
} else {
|
|
2038
|
-
throw new Error("Not implemented for given definition");
|
|
2039
|
-
}
|
|
2040
|
-
};
|
|
2041
|
-
var fetchObjectMetadata = async (client, objectType) => {
|
|
2042
|
-
const response = await esm_exports.ObjectTypesV2.getObjectTypeFullMetadata(addUserAgentAndRequestContextHeaders(client, objectType), await client.ontologyRid, objectType.apiName, {
|
|
2043
|
-
preview: true
|
|
2044
|
-
});
|
|
2045
|
-
const supportedIconTypes = ["blueprint"];
|
|
2046
|
-
return {
|
|
2047
|
-
description: response.objectType.description,
|
|
2048
|
-
displayName: response.objectType.displayName,
|
|
2049
|
-
visibility: response.objectType.visibility,
|
|
2050
|
-
pluralDisplayName: response.objectType.pluralDisplayName,
|
|
2051
|
-
icon: supportedIconTypes.includes(response.objectType.icon.type) ? response.objectType.icon : void 0,
|
|
2052
|
-
rid: response.objectType.rid
|
|
2053
|
-
};
|
|
2054
|
-
};
|
|
2055
|
-
var fetchInterfaceMetadata = async (client, interfaceType) => {
|
|
2056
|
-
const response = await esm_exports.OntologyInterfaces.getInterfaceType(addUserAgentAndRequestContextHeaders(client, interfaceType), await client.ontologyRid, interfaceType.apiName, {
|
|
2057
|
-
preview: true
|
|
2058
|
-
});
|
|
2059
|
-
return {
|
|
2060
|
-
displayName: response.displayName,
|
|
2061
|
-
description: response.description,
|
|
2062
|
-
rid: response.rid
|
|
2063
|
-
};
|
|
2064
|
-
};
|
|
2065
|
-
var fetchActionMetadata = async (client, actionType) => {
|
|
2066
|
-
const response = await esm_exports.ActionTypesV2.getActionTypeV2(addUserAgentAndRequestContextHeaders(client, actionType), await client.ontologyRid, actionType.apiName);
|
|
2067
|
-
return {
|
|
2068
|
-
displayName: response.displayName,
|
|
2069
|
-
description: response.description,
|
|
2070
|
-
rid: response.rid
|
|
2071
|
-
};
|
|
2072
|
-
};
|
|
2073
|
-
var fetchQueryMetadata = async (client, queryType) => {
|
|
2074
|
-
const response = await esm_exports.QueryTypes.getQueryTypeV2(addUserAgentAndRequestContextHeaders(client, queryType), await client.ontologyRid, queryType.apiName);
|
|
2075
|
-
return {
|
|
2076
|
-
displayName: response.displayName,
|
|
2077
|
-
description: response.description,
|
|
2078
|
-
rid: response.rid
|
|
2079
|
-
};
|
|
2080
|
-
};
|
|
2081
|
-
|
|
2082
|
-
// src/util/isOsdkBaseObject.ts
|
|
2083
|
-
function isOsdkBaseObject2(o) {
|
|
2084
|
-
return o && typeof o === "object" && typeof o.$apiName === "string" && o.$primaryKey != null;
|
|
2085
|
-
}
|
|
2086
|
-
|
|
2087
|
-
// src/util/toDataValueQueries.ts
|
|
2088
|
-
async function toDataValueQueries(value, client, desiredType) {
|
|
2089
|
-
if (value == null) {
|
|
2090
|
-
return value;
|
|
2091
|
-
}
|
|
2092
|
-
if (Array.isArray(value) && desiredType.multiplicity) {
|
|
2093
|
-
const promiseArray = Array.from(value, async (innerValue) => await toDataValueQueries(innerValue, client, desiredType));
|
|
2094
|
-
return Promise.all(promiseArray);
|
|
2095
|
-
}
|
|
2096
|
-
switch (desiredType.type) {
|
|
2097
|
-
case "attachment": {
|
|
2098
|
-
if (isAttachmentUpload(value)) {
|
|
2099
|
-
const attachment = await esm_exports.Attachments.uploadAttachmentV2(client, value, {
|
|
2100
|
-
filename: value.name
|
|
2101
|
-
});
|
|
2102
|
-
return attachment.rid;
|
|
2103
|
-
}
|
|
2104
|
-
return value;
|
|
2105
|
-
}
|
|
2106
|
-
case "twoDimensionalAggregation": {
|
|
2107
|
-
return {
|
|
2108
|
-
groups: value
|
|
2109
|
-
};
|
|
2110
|
-
}
|
|
2111
|
-
case "threeDimensionalAggregation": {
|
|
2112
|
-
return {
|
|
2113
|
-
groups: value
|
|
2114
|
-
};
|
|
2115
|
-
}
|
|
2116
|
-
case "set": {
|
|
2117
|
-
if (value instanceof Set) {
|
|
2118
|
-
const promiseArray = Array.from(value, async (innerValue) => await toDataValueQueries(innerValue, client, desiredType["set"]));
|
|
2119
|
-
return Promise.all(promiseArray);
|
|
2120
|
-
}
|
|
2121
|
-
break;
|
|
2122
|
-
}
|
|
2123
|
-
case "object": {
|
|
2124
|
-
if (isOsdkBaseObject2(value)) {
|
|
2125
|
-
return value.$primaryKey;
|
|
2126
|
-
}
|
|
2127
|
-
break;
|
|
2128
|
-
}
|
|
2129
|
-
case "objectSet": {
|
|
2130
|
-
if (isWireObjectSet(value)) {
|
|
2131
|
-
return value;
|
|
2132
|
-
}
|
|
2133
|
-
if (isObjectSet(value)) {
|
|
2134
|
-
return getWireObjectSet(value);
|
|
2135
|
-
}
|
|
2136
|
-
break;
|
|
2137
|
-
}
|
|
2138
|
-
case "struct": {
|
|
2139
|
-
if (typeof value === "object") {
|
|
2140
|
-
const structMap = {};
|
|
2141
|
-
for (const [key, structValue] of Object.entries(value)) {
|
|
2142
|
-
structMap[key] = await toDataValueQueries(structValue, client, desiredType["struct"][key]);
|
|
2143
|
-
}
|
|
2144
|
-
return structMap;
|
|
2145
|
-
}
|
|
2146
|
-
}
|
|
2147
|
-
case "boolean":
|
|
2148
|
-
case "date":
|
|
2149
|
-
case "double":
|
|
2150
|
-
case "float":
|
|
2151
|
-
case "integer":
|
|
2152
|
-
case "long":
|
|
2153
|
-
case "string":
|
|
2154
|
-
case "timestamp":
|
|
2155
|
-
return value;
|
|
2156
|
-
}
|
|
2157
|
-
return value;
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
// src/queries/applyQuery.ts
|
|
2161
|
-
async function applyQuery(client, query, params) {
|
|
2162
|
-
const qd = await client.ontologyProvider.getQueryDefinition(query.apiName);
|
|
2163
|
-
const response = await esm_exports.Queries.executeQueryV2(addUserAgentAndRequestContextHeaders(augmentRequestContext(client, (_) => ({
|
|
2164
|
-
finalMethodCall: "applyQuery"
|
|
2165
|
-
})), query), await client.ontologyRid, query.apiName, {
|
|
2166
|
-
parameters: params ? await remapQueryParams(params, client, qd.parameters) : {}
|
|
2167
|
-
});
|
|
2168
|
-
const objectOutputDefs = await getRequiredDefinitions(qd.output, client);
|
|
2169
|
-
const remappedResponse = await remapQueryResponse(client, qd.output, response.value, objectOutputDefs);
|
|
2170
|
-
return remappedResponse;
|
|
2171
|
-
}
|
|
2172
|
-
async function remapQueryParams(params, client, paramTypes) {
|
|
2173
|
-
const parameterMap = {};
|
|
2174
|
-
for (const [key, value] of Object.entries(params)) {
|
|
2175
|
-
parameterMap[key] = await toDataValueQueries(value, client, paramTypes[key]);
|
|
2176
|
-
}
|
|
2177
|
-
return parameterMap;
|
|
2178
|
-
}
|
|
2179
|
-
async function remapQueryResponse(client, responseDataType, responseValue, definitions) {
|
|
2180
|
-
if (responseValue == null) {
|
|
2181
|
-
if (responseDataType.nullable) {
|
|
2182
|
-
return void 0;
|
|
2183
|
-
} else {
|
|
2184
|
-
throw new Error("Got null response when nullable was not allowed");
|
|
2185
|
-
}
|
|
2186
|
-
}
|
|
2187
|
-
if (responseDataType.multiplicity != null && responseDataType.multiplicity !== false) {
|
|
2188
|
-
const withoutMultiplicity = {
|
|
2189
|
-
...responseDataType,
|
|
2190
|
-
multiplicity: false
|
|
2191
|
-
};
|
|
2192
|
-
for (let i = 0; i < responseValue.length; i++) {
|
|
2193
|
-
responseValue[i] = await remapQueryResponse(responseValue[i], withoutMultiplicity, client, definitions);
|
|
2194
|
-
}
|
|
2195
|
-
return responseValue;
|
|
2196
|
-
}
|
|
2197
|
-
switch (responseDataType.type) {
|
|
2198
|
-
case "union": {
|
|
2199
|
-
throw new Error("Union return types are not yet supported");
|
|
2200
|
-
}
|
|
2201
|
-
case "set": {
|
|
2202
|
-
for (let i = 0; i < responseValue.length; i++) {
|
|
2203
|
-
responseValue[i] = await remapQueryResponse(responseValue[i], responseDataType.set, client, definitions);
|
|
2204
|
-
}
|
|
2205
|
-
return responseValue;
|
|
2206
|
-
}
|
|
2207
|
-
case "attachment": {
|
|
2208
|
-
return createAttachmentFromRid(client, responseValue);
|
|
2209
|
-
}
|
|
2210
|
-
case "object": {
|
|
2211
|
-
const def = definitions.get(responseDataType.object);
|
|
2212
|
-
if (!def) {
|
|
2213
|
-
throw new Error(`Missing definition for ${responseDataType.object}`);
|
|
2214
|
-
}
|
|
2215
|
-
return createQueryObjectResponse(responseValue, def);
|
|
2216
|
-
}
|
|
2217
|
-
case "objectSet": {
|
|
2218
|
-
const def = definitions.get(responseDataType.objectSet);
|
|
2219
|
-
if (!def) {
|
|
2220
|
-
throw new Error(`Missing definition for ${responseDataType.objectSet}`);
|
|
2221
|
-
}
|
|
2222
|
-
if (typeof responseValue === "string") {
|
|
2223
|
-
return createObjectSet(def, client, {
|
|
2224
|
-
type: "intersect",
|
|
2225
|
-
objectSets: [{
|
|
2226
|
-
type: "base",
|
|
2227
|
-
objectType: responseDataType.objectSet
|
|
2228
|
-
}, {
|
|
2229
|
-
type: "reference",
|
|
2230
|
-
reference: responseValue
|
|
2231
|
-
}]
|
|
2232
|
-
});
|
|
2233
|
-
}
|
|
2234
|
-
return createObjectSet(def, client, responseValue);
|
|
2235
|
-
}
|
|
2236
|
-
case "struct": {
|
|
2237
|
-
for (const [key, subtype] of Object.entries(responseDataType.struct)) {
|
|
2238
|
-
if (requiresConversion(subtype)) {
|
|
2239
|
-
responseValue[key] = await remapQueryResponse(responseValue[key], subtype, client, definitions);
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
return responseValue;
|
|
2243
|
-
}
|
|
2244
|
-
case "twoDimensionalAggregation": {
|
|
2245
|
-
const result = [];
|
|
2246
|
-
for (const {
|
|
2247
|
-
key,
|
|
2248
|
-
value
|
|
2249
|
-
} of responseValue.groups) {
|
|
2250
|
-
result.push({
|
|
2251
|
-
key,
|
|
2252
|
-
value
|
|
2253
|
-
});
|
|
2254
|
-
}
|
|
2255
|
-
return result;
|
|
2256
|
-
}
|
|
2257
|
-
case "threeDimensionalAggregation": {
|
|
2258
|
-
const result = [];
|
|
2259
|
-
for (const {
|
|
2260
|
-
key,
|
|
2261
|
-
groups
|
|
2262
|
-
} of responseValue.groups) {
|
|
2263
|
-
const subResult = [];
|
|
2264
|
-
for (const {
|
|
2265
|
-
key: subKey,
|
|
2266
|
-
value
|
|
2267
|
-
} of groups) {
|
|
2268
|
-
subResult.push({
|
|
2269
|
-
key: subKey,
|
|
2270
|
-
value
|
|
2271
|
-
});
|
|
2272
|
-
}
|
|
2273
|
-
result.push({
|
|
2274
|
-
key,
|
|
2275
|
-
groups: subResult
|
|
2276
|
-
});
|
|
2277
|
-
}
|
|
2278
|
-
return result;
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
|
-
return responseValue;
|
|
2282
|
-
}
|
|
2283
|
-
async function getRequiredDefinitions(dataType, client) {
|
|
2284
|
-
const result = /* @__PURE__ */ new Map();
|
|
2285
|
-
switch (dataType.type) {
|
|
2286
|
-
case "objectSet": {
|
|
2287
|
-
const objectDef = await client.ontologyProvider.getObjectDefinition(dataType.objectSet);
|
|
2288
|
-
result.set(dataType.objectSet, objectDef);
|
|
2289
|
-
break;
|
|
2290
|
-
}
|
|
2291
|
-
case "object": {
|
|
2292
|
-
const objectDef = await client.ontologyProvider.getObjectDefinition(dataType.object);
|
|
2293
|
-
result.set(dataType.object, objectDef);
|
|
2294
|
-
break;
|
|
2295
|
-
}
|
|
2296
|
-
case "set": {
|
|
2297
|
-
return getRequiredDefinitions(dataType.set, client);
|
|
2298
|
-
}
|
|
2299
|
-
case "struct": {
|
|
2300
|
-
for (const value of Object.values(dataType.struct)) {
|
|
2301
|
-
for (const [type, objectDef] of await getRequiredDefinitions(value, client)) {
|
|
2302
|
-
result.set(type, objectDef);
|
|
2303
|
-
}
|
|
2304
|
-
}
|
|
2305
|
-
break;
|
|
2306
|
-
}
|
|
2307
|
-
}
|
|
2308
|
-
return result;
|
|
2309
|
-
}
|
|
2310
|
-
function requiresConversion(dataType) {
|
|
2311
|
-
switch (dataType.type) {
|
|
2312
|
-
case "boolean":
|
|
2313
|
-
case "date":
|
|
2314
|
-
case "double":
|
|
2315
|
-
case "float":
|
|
2316
|
-
case "integer":
|
|
2317
|
-
case "long":
|
|
2318
|
-
case "object":
|
|
2319
|
-
case "string":
|
|
2320
|
-
case "timestamp":
|
|
2321
|
-
return false;
|
|
2322
|
-
case "union":
|
|
2323
|
-
return true;
|
|
2324
|
-
case "struct":
|
|
2325
|
-
return Object.values(dataType.struct).some(requiresConversion);
|
|
2326
|
-
case "set":
|
|
2327
|
-
return requiresConversion(dataType.set);
|
|
2328
|
-
case "attachment":
|
|
2329
|
-
case "objectSet":
|
|
2330
|
-
case "twoDimensionalAggregation":
|
|
2331
|
-
case "threeDimensionalAggregation":
|
|
2332
|
-
return true;
|
|
2333
|
-
default:
|
|
2334
|
-
return false;
|
|
2335
|
-
}
|
|
2336
|
-
}
|
|
2337
|
-
function createQueryObjectResponse(primaryKey, objectDef) {
|
|
2338
|
-
return {
|
|
2339
|
-
$apiName: objectDef.apiName,
|
|
2340
|
-
$title: void 0,
|
|
2341
|
-
$objectType: objectDef.apiName,
|
|
2342
|
-
$primaryKey: primaryKey
|
|
2343
|
-
};
|
|
2344
|
-
}
|
|
2345
|
-
|
|
2346
|
-
// src/createClient.ts
|
|
2347
|
-
var ActionInvoker = class {
|
|
2348
|
-
constructor(clientCtx, actionDef) {
|
|
2349
|
-
this.applyAction = applyAction2.bind(void 0, clientCtx, actionDef);
|
|
2350
|
-
this.batchApplyAction = applyAction2.bind(void 0, clientCtx, actionDef);
|
|
2351
|
-
}
|
|
2352
|
-
};
|
|
2353
|
-
var QueryInvoker = class {
|
|
2354
|
-
constructor(clientCtx, queryDef) {
|
|
2355
|
-
this.executeFunction = applyQuery.bind(void 0, clientCtx, queryDef);
|
|
2356
|
-
}
|
|
2357
|
-
};
|
|
2358
|
-
function createClientInternal(objectSetFactory, baseUrl, ontologyRid, tokenProvider, options = void 0, fetchFn = fetch) {
|
|
2359
|
-
const clientCtx = createMinimalClient({
|
|
2360
|
-
ontologyRid
|
|
2361
|
-
}, baseUrl, tokenProvider, options, fetchFn, objectSetFactory);
|
|
2362
|
-
function clientFn(o) {
|
|
2363
|
-
if (o.type === "object" || o.type === "interface") {
|
|
2364
|
-
return objectSetFactory(o, clientCtx);
|
|
2365
|
-
} else if (o.type === "action") {
|
|
2366
|
-
return new ActionInvoker(clientCtx, o);
|
|
2367
|
-
} else if (o.type === "query") {
|
|
2368
|
-
return new QueryInvoker(clientCtx, o);
|
|
2369
|
-
} else {
|
|
2370
|
-
throw new Error("not implemented");
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
const fetchMetadata = fetchMetadataInternal.bind(void 0, clientCtx);
|
|
2374
|
-
const client = Object.defineProperties(clientFn, {
|
|
2375
|
-
[symbolClientContext]: {
|
|
2376
|
-
value: clientCtx
|
|
2377
|
-
},
|
|
2378
|
-
fetchMetadata: {
|
|
2379
|
-
value: fetchMetadata
|
|
2380
|
-
}
|
|
2381
|
-
});
|
|
2382
|
-
return client;
|
|
2383
|
-
}
|
|
2384
|
-
var createClient = createClientInternal.bind(void 0, createObjectSet);
|
|
2385
|
-
|
|
2386
|
-
export { ActionValidationError, USER_AGENT, augment, convertWireToOsdkObjects, createAttachmentFromRid, createAttachmentUpload, createClient, createClientInternal, createObjectSet, createSimpleAsyncCache, esm_exports };
|
|
2387
|
-
//# sourceMappingURL=chunk-WGFCR4UM.js.map
|
|
2388
|
-
//# sourceMappingURL=chunk-WGFCR4UM.js.map
|
|
2503
|
+
export { InterfaceDefinitions, addUserAgentAndRequestContextHeaders, augment, augmentRequestContext, conjureUnionType, createAsyncClientCache, createAttachmentFromRid, createObjectSet, esm_exports, getWireObjectSet, isObjectSet, isWireObjectSet, makeConjureContext, metadataCacheClient };
|
|
2504
|
+
//# sourceMappingURL=chunk-MQTCPUPF.js.map
|
|
2505
|
+
//# sourceMappingURL=chunk-MQTCPUPF.js.map
|