@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,880 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export { augment } from '../chunk-WGFCR4UM.js';
|
|
3
|
-
import { symbolClientContext } from '@osdk/shared.client';
|
|
4
|
-
import { getBulkLinksPage, getLinkTypesForObjectTypes, bulkLoadOntologyEntities, createTemporaryObjectSet, loadAllOntologies } from '@osdk/client.unstable';
|
|
5
|
-
import { batchEnableWatcher } from '@osdk/client.unstable.osw';
|
|
6
|
-
import WebSocket from 'isomorphic-ws';
|
|
7
|
-
import invariant2 from 'tiny-invariant';
|
|
8
|
-
|
|
9
|
-
// src/ontology/makeConjureContext.ts
|
|
10
|
-
function makeConjureContext({
|
|
11
|
-
baseUrl,
|
|
12
|
-
fetch: fetchFn,
|
|
13
|
-
tokenProvider
|
|
14
|
-
}, servicePath) {
|
|
15
|
-
return {
|
|
16
|
-
baseUrl,
|
|
17
|
-
servicePath,
|
|
18
|
-
fetchFn,
|
|
19
|
-
tokenProvider
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/__unstable/ConjureSupport.ts
|
|
24
|
-
var cachedAllOntologies;
|
|
25
|
-
async function getOntologyVersionForRid(ctx, ontologyRid) {
|
|
26
|
-
cachedAllOntologies ??= await loadAllOntologies(ctx, {});
|
|
27
|
-
!cachedAllOntologies.ontologies[ontologyRid] ? process.env.NODE_ENV !== "production" ? invariant2(false, "ontology should be loaded") : invariant2(false) : void 0;
|
|
28
|
-
return cachedAllOntologies.ontologies[ontologyRid].currentOntologyVersion;
|
|
29
|
-
}
|
|
30
|
-
var strongMemoAsync = (fn) => createSimpleAsyncCache("strong", fn).get;
|
|
31
|
-
var weakMemoAsync = (fn) => createSimpleAsyncCache("weak", fn).get;
|
|
32
|
-
var MetadataClient = class {
|
|
33
|
-
#client;
|
|
34
|
-
#ctx;
|
|
35
|
-
#logger;
|
|
36
|
-
constructor(client) {
|
|
37
|
-
this.#client = client;
|
|
38
|
-
this.#ctx = makeConjureContext(client, "/ontology-metadata/api");
|
|
39
|
-
this.#client.ontologyProvider.getObjectDefinition;
|
|
40
|
-
this.#logger = this.#client.logger?.child({
|
|
41
|
-
mcc: true
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
forObjectByRid = strongMemoAsync(async (rid) => {
|
|
45
|
-
return Promise.resolve({
|
|
46
|
-
getPropertyMapping: this.#objectPropertyMapping.bind(this, rid),
|
|
47
|
-
getLinkMapping: this.#objectLinkMapping.bind(this, rid),
|
|
48
|
-
getRid: () => rid,
|
|
49
|
-
getApiName: async () => (await this.#getConjureObjectType(rid)).apiName
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
forObjectByApiName = strongMemoAsync(async (objectApiName) => {
|
|
53
|
-
const objectDef = await this.#client.ontologyProvider.getObjectDefinition(objectApiName);
|
|
54
|
-
return this.forObjectByRid(objectDef.rid);
|
|
55
|
-
});
|
|
56
|
-
#objectPropertyMapping = strongMemoAsync(async (objectTypeRid) => {
|
|
57
|
-
const conjureObjectType = await this.#getConjureObjectType(objectTypeRid);
|
|
58
|
-
return createObjectPropertyMapping(conjureObjectType);
|
|
59
|
-
});
|
|
60
|
-
#objectLinkMapping = strongMemoAsync(async (objectTypeRid) => {
|
|
61
|
-
const linkTypes = await getLinkTypesForObjectTypes(this.#ctx, {
|
|
62
|
-
includeObjectTypesWithoutSearchableDatasources: true,
|
|
63
|
-
loadRedacted: false,
|
|
64
|
-
objectTypeBranches: {},
|
|
65
|
-
objectTypeVersions: {
|
|
66
|
-
[objectTypeRid]: await this.ontologyVersion("")
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
!linkTypes.linkTypes[objectTypeRid] ? process.env.NODE_ENV !== "production" ? invariant2(false, "link type should be loaded") : invariant2(false) : void 0;
|
|
70
|
-
const ret = {};
|
|
71
|
-
for (const l of linkTypes.linkTypes[objectTypeRid]) {
|
|
72
|
-
const helper = ({
|
|
73
|
-
apiName
|
|
74
|
-
}, linkSide, otherObjectType) => {
|
|
75
|
-
if (apiName) {
|
|
76
|
-
ret[apiName] = {
|
|
77
|
-
apiName,
|
|
78
|
-
directedLinkTypeRid: {
|
|
79
|
-
linkTypeRid: l.rid,
|
|
80
|
-
linkSide
|
|
81
|
-
},
|
|
82
|
-
otherObjectType
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
if (l.definition.type === "oneToMany") {
|
|
87
|
-
const {
|
|
88
|
-
oneToMany: {
|
|
89
|
-
objectTypeRidManySide,
|
|
90
|
-
manyToOneLinkMetadata,
|
|
91
|
-
objectTypeRidOneSide,
|
|
92
|
-
oneToManyLinkMetadata
|
|
93
|
-
}
|
|
94
|
-
} = l.definition;
|
|
95
|
-
if (objectTypeRidManySide === objectTypeRid) {
|
|
96
|
-
helper(manyToOneLinkMetadata, "TARGET", objectTypeRidOneSide);
|
|
97
|
-
}
|
|
98
|
-
if (objectTypeRidOneSide === objectTypeRid) {
|
|
99
|
-
helper(oneToManyLinkMetadata, "SOURCE", objectTypeRidManySide);
|
|
100
|
-
}
|
|
101
|
-
} else if (l.definition.type === "manyToMany") {
|
|
102
|
-
const {
|
|
103
|
-
manyToMany: {
|
|
104
|
-
objectTypeRidA,
|
|
105
|
-
objectTypeAToBLinkMetadata,
|
|
106
|
-
objectTypeRidB,
|
|
107
|
-
objectTypeBToALinkMetadata
|
|
108
|
-
}
|
|
109
|
-
} = l.definition;
|
|
110
|
-
if (objectTypeRidA === objectTypeRid) {
|
|
111
|
-
helper(objectTypeAToBLinkMetadata, "SOURCE", objectTypeRidB);
|
|
112
|
-
}
|
|
113
|
-
if (objectTypeRidB === objectTypeRid) {
|
|
114
|
-
helper(objectTypeBToALinkMetadata, "TARGET", objectTypeRidA);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return ret;
|
|
119
|
-
});
|
|
120
|
-
#getConjureObjectType = strongMemoAsync(async (objectTypeRid) => {
|
|
121
|
-
this.#logger?.debug(`getConjureObjectType(${objectTypeRid})`);
|
|
122
|
-
const body = {
|
|
123
|
-
datasourceTypes: [],
|
|
124
|
-
objectTypes: [{
|
|
125
|
-
identifier: {
|
|
126
|
-
type: "objectTypeRid",
|
|
127
|
-
objectTypeRid
|
|
128
|
-
},
|
|
129
|
-
versionReference: {
|
|
130
|
-
type: "ontologyVersion",
|
|
131
|
-
ontologyVersion: await this.ontologyVersion("")
|
|
132
|
-
}
|
|
133
|
-
}],
|
|
134
|
-
linkTypes: [],
|
|
135
|
-
sharedPropertyTypes: [],
|
|
136
|
-
interfaceTypes: [],
|
|
137
|
-
typeGroups: [],
|
|
138
|
-
loadRedacted: false,
|
|
139
|
-
includeObjectTypeCount: void 0,
|
|
140
|
-
includeObjectTypesWithoutSearchableDatasources: true,
|
|
141
|
-
includeEntityMetadata: void 0
|
|
142
|
-
};
|
|
143
|
-
const entities = await bulkLoadOntologyEntities(this.#ctx, void 0, body);
|
|
144
|
-
!entities.objectTypes[0]?.objectType ? process.env.NODE_ENV !== "production" ? invariant2(false, "object type should be loaded") : invariant2(false) : void 0;
|
|
145
|
-
return entities.objectTypes[0].objectType;
|
|
146
|
-
});
|
|
147
|
-
ontologyVersion = strongMemoAsync(async (_) => getOntologyVersionForRid(this.#ctx, await this.#client.ontologyRid));
|
|
148
|
-
};
|
|
149
|
-
var metadataCacheClient = weakMemoAsync((client) => Promise.resolve(new MetadataClient(client)));
|
|
150
|
-
function createObjectPropertyMapping(conjureOT) {
|
|
151
|
-
!(conjureOT.primaryKeys.length === 1) ? process.env.NODE_ENV !== "production" ? invariant2(false, `only one primary key supported, got ${conjureOT.primaryKeys.length}`) : invariant2(false) : void 0;
|
|
152
|
-
const pkRid = conjureOT.primaryKeys[0];
|
|
153
|
-
const pkProperty = Object.values(conjureOT.propertyTypes).find((a) => a.rid === pkRid);
|
|
154
|
-
if (!pkProperty) {
|
|
155
|
-
throw new Error(`Could not find PK property by rid: ${pkRid}`);
|
|
156
|
-
}
|
|
157
|
-
const propertyIdToApiNameMapping = Object.fromEntries(Object.values(conjureOT.propertyTypes).map((property) => {
|
|
158
|
-
return [property.id, property.apiName];
|
|
159
|
-
}));
|
|
160
|
-
const propertyApiNameToIdMapping = Object.fromEntries(Object.values(conjureOT.propertyTypes).map((property) => {
|
|
161
|
-
return [property.apiName, property.id];
|
|
162
|
-
}));
|
|
163
|
-
return {
|
|
164
|
-
apiName: conjureOT.apiName,
|
|
165
|
-
id: conjureOT.id,
|
|
166
|
-
propertyIdToApiNameMapping,
|
|
167
|
-
propertyApiNameToIdMapping,
|
|
168
|
-
pk: {
|
|
169
|
-
rid: pkRid,
|
|
170
|
-
apiName: pkProperty.apiName,
|
|
171
|
-
type: pkProperty.type
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// src/objectSet/conjureUnionType.ts
|
|
177
|
-
function conjureUnionType(type, value) {
|
|
178
|
-
return {
|
|
179
|
-
type,
|
|
180
|
-
[type]: value
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// src/objectSet/toConjureObjectSet.ts
|
|
185
|
-
function toConjureObjectSet(objectSet, objectPropertyMapping) {
|
|
186
|
-
switch (objectSet.type) {
|
|
187
|
-
case "base":
|
|
188
|
-
return conjureUnionType("base", {
|
|
189
|
-
objectTypeId: objectPropertyMapping.id
|
|
190
|
-
});
|
|
191
|
-
case "static":
|
|
192
|
-
return conjureUnionType("static", {
|
|
193
|
-
objectRids: objectSet.objects,
|
|
194
|
-
provenance: void 0
|
|
195
|
-
});
|
|
196
|
-
case "reference":
|
|
197
|
-
return conjureUnionType("referenced", {
|
|
198
|
-
objectSetRid: objectSet.reference
|
|
199
|
-
});
|
|
200
|
-
case "filter":
|
|
201
|
-
return conjureUnionType("filtered", {
|
|
202
|
-
objectSet: toConjureObjectSet(objectSet.objectSet, objectPropertyMapping),
|
|
203
|
-
runtimeDerivedProperties: void 0,
|
|
204
|
-
filter: mapWhereClauseToObjectSetFilter(objectSet.where, objectPropertyMapping)
|
|
205
|
-
});
|
|
206
|
-
case "union":
|
|
207
|
-
return conjureUnionType("unioned", {
|
|
208
|
-
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
209
|
-
});
|
|
210
|
-
case "intersect":
|
|
211
|
-
return conjureUnionType("intersected", {
|
|
212
|
-
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
213
|
-
});
|
|
214
|
-
case "subtract":
|
|
215
|
-
return conjureUnionType("subtracted", {
|
|
216
|
-
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
217
|
-
});
|
|
218
|
-
case "searchAround":
|
|
219
|
-
throw new Error("not implemented");
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
async function getObjectSetBaseType(objectSet) {
|
|
223
|
-
switch (objectSet.type) {
|
|
224
|
-
case "base":
|
|
225
|
-
return objectSet.objectType;
|
|
226
|
-
case "static":
|
|
227
|
-
throw new Error("not implemented");
|
|
228
|
-
case "reference":
|
|
229
|
-
throw new Error("not implemented");
|
|
230
|
-
case "filter":
|
|
231
|
-
return getObjectSetBaseType(objectSet.objectSet);
|
|
232
|
-
case "union":
|
|
233
|
-
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
234
|
-
case "intersect":
|
|
235
|
-
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
236
|
-
case "subtract":
|
|
237
|
-
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
238
|
-
case "searchAround":
|
|
239
|
-
throw new Error("not implemented");
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function mapWhereClauseToObjectSetFilter(objectSetFilter, propertyMapping) {
|
|
243
|
-
switch (objectSetFilter.type) {
|
|
244
|
-
case "lt":
|
|
245
|
-
return conjureUnionType("range", {
|
|
246
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
247
|
-
lt: objectSetFilter.value,
|
|
248
|
-
lte: void 0,
|
|
249
|
-
gt: void 0,
|
|
250
|
-
gte: void 0
|
|
251
|
-
});
|
|
252
|
-
case "gt":
|
|
253
|
-
return conjureUnionType("range", {
|
|
254
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
255
|
-
gt: objectSetFilter.value,
|
|
256
|
-
lte: void 0,
|
|
257
|
-
lt: void 0,
|
|
258
|
-
gte: void 0
|
|
259
|
-
});
|
|
260
|
-
case "lte":
|
|
261
|
-
return conjureUnionType("range", {
|
|
262
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
263
|
-
lte: objectSetFilter.value,
|
|
264
|
-
lt: void 0,
|
|
265
|
-
gt: void 0,
|
|
266
|
-
gte: void 0
|
|
267
|
-
});
|
|
268
|
-
case "gte":
|
|
269
|
-
return conjureUnionType("range", {
|
|
270
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
271
|
-
gte: objectSetFilter.value,
|
|
272
|
-
lt: void 0,
|
|
273
|
-
lte: void 0,
|
|
274
|
-
gt: void 0
|
|
275
|
-
});
|
|
276
|
-
case "eq":
|
|
277
|
-
return conjureUnionType("exactMatch", {
|
|
278
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
279
|
-
terms: [objectSetFilter.value]
|
|
280
|
-
});
|
|
281
|
-
case "and":
|
|
282
|
-
return conjureUnionType("and", {
|
|
283
|
-
filters: objectSetFilter.value.map((filter) => mapWhereClauseToObjectSetFilter(filter, propertyMapping))
|
|
284
|
-
});
|
|
285
|
-
case "or":
|
|
286
|
-
return conjureUnionType("or", {
|
|
287
|
-
filters: objectSetFilter.value.map((filter) => mapWhereClauseToObjectSetFilter(filter, propertyMapping))
|
|
288
|
-
});
|
|
289
|
-
case "isNull":
|
|
290
|
-
return conjureUnionType("not", {
|
|
291
|
-
filter: {
|
|
292
|
-
type: "hasProperty",
|
|
293
|
-
hasProperty: {
|
|
294
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field]
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
case "not":
|
|
299
|
-
return conjureUnionType("not", {
|
|
300
|
-
filter: mapWhereClauseToObjectSetFilter(objectSetFilter.value, propertyMapping)
|
|
301
|
-
});
|
|
302
|
-
case "contains":
|
|
303
|
-
case "startsWith":
|
|
304
|
-
case "containsAllTermsInOrder":
|
|
305
|
-
case "containsAnyTerm":
|
|
306
|
-
case "containsAllTerms":
|
|
307
|
-
case "withinDistanceOf":
|
|
308
|
-
case "withinBoundingBox":
|
|
309
|
-
case "intersectsBoundingBox":
|
|
310
|
-
case "doesNotIntersectBoundingBox":
|
|
311
|
-
case "withinPolygon":
|
|
312
|
-
case "intersectsPolygon":
|
|
313
|
-
case "doesNotIntersectPolygon":
|
|
314
|
-
case "containsAllTermsInOrderPrefixLastTerm":
|
|
315
|
-
case "in":
|
|
316
|
-
throw new Error("not implemented");
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
// src/objectSet/ObjectSetListenerWebsocket.ts
|
|
321
|
-
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
322
|
-
var MINIMUM_RECONNECT_DELAY_MS = 5 * 1e3;
|
|
323
|
-
function doNothing() {
|
|
324
|
-
}
|
|
325
|
-
function fillOutListener({
|
|
326
|
-
onChange = doNothing,
|
|
327
|
-
onError = doNothing,
|
|
328
|
-
onOutOfDate = doNothing
|
|
329
|
-
}) {
|
|
330
|
-
return {
|
|
331
|
-
onChange,
|
|
332
|
-
onError,
|
|
333
|
-
onOutOfDate
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
function isReady(sub) {
|
|
337
|
-
return sub.temporaryObjectSetId != null;
|
|
338
|
-
}
|
|
339
|
-
function subscriptionIsDone(sub) {
|
|
340
|
-
return sub.status === "done" || sub.status === "error";
|
|
341
|
-
}
|
|
342
|
-
var ObjectSetListenerWebsocket = class _ObjectSetListenerWebsocket {
|
|
343
|
-
static #instances = /* @__PURE__ */ new WeakMap();
|
|
344
|
-
// FIXME
|
|
345
|
-
static getInstance(client) {
|
|
346
|
-
let instance = _ObjectSetListenerWebsocket.#instances.get(client.clientCacheKey);
|
|
347
|
-
if (instance == null) {
|
|
348
|
-
instance = new _ObjectSetListenerWebsocket(client);
|
|
349
|
-
_ObjectSetListenerWebsocket.#instances.set(client.clientCacheKey, instance);
|
|
350
|
-
}
|
|
351
|
-
return instance;
|
|
352
|
-
}
|
|
353
|
-
#ws;
|
|
354
|
-
#lastWsConnect = 0;
|
|
355
|
-
#client;
|
|
356
|
-
#logger;
|
|
357
|
-
/**
|
|
358
|
-
* map of requestId to all active subscriptions at the time of the request
|
|
359
|
-
*/
|
|
360
|
-
#pendingSubscriptions = /* @__PURE__ */ new Map();
|
|
361
|
-
/**
|
|
362
|
-
* Map of subscriptionId to Subscription. Note: the subscriptionId may be
|
|
363
|
-
* temporary and not the actual subscriptionId from the server.
|
|
364
|
-
*/
|
|
365
|
-
#subscriptions = /* @__PURE__ */ new Map();
|
|
366
|
-
#oswContext;
|
|
367
|
-
#metadataContext;
|
|
368
|
-
#ossContext;
|
|
369
|
-
#maybeDisconnectTimeout;
|
|
370
|
-
// DO NOT CONSTRUCT DIRECTLY. ONLY EXPOSED AS A TESTING SEAM
|
|
371
|
-
constructor(client, {
|
|
372
|
-
objectSetExpiryMs = ONE_DAY_MS,
|
|
373
|
-
minimumReconnectDelayMs = MINIMUM_RECONNECT_DELAY_MS
|
|
374
|
-
} = {}) {
|
|
375
|
-
this.OBJECT_SET_EXPIRY_MS = objectSetExpiryMs;
|
|
376
|
-
this.MINIMUM_RECONNECT_DELAY_MS = minimumReconnectDelayMs;
|
|
377
|
-
this.#client = client;
|
|
378
|
-
this.#logger = client.logger?.child({}, {
|
|
379
|
-
msgPrefix: "<OSW> "
|
|
380
|
-
});
|
|
381
|
-
!(client.baseUrl.startsWith("https://") || client.baseUrl.startsWith("http://")) ? process.env.NODE_ENV !== "production" ? invariant2(false, "Stack must be a URL") : invariant2(false) : void 0;
|
|
382
|
-
this.#oswContext = {
|
|
383
|
-
baseUrl: client.baseUrl,
|
|
384
|
-
servicePath: "/object-set-watcher/api",
|
|
385
|
-
fetchFn: client.fetch,
|
|
386
|
-
tokenProvider: async () => await client.tokenProvider()
|
|
387
|
-
};
|
|
388
|
-
this.#ossContext = {
|
|
389
|
-
...this.#oswContext,
|
|
390
|
-
servicePath: "/object-set-service/api"
|
|
391
|
-
};
|
|
392
|
-
this.#metadataContext = {
|
|
393
|
-
...this.#oswContext,
|
|
394
|
-
servicePath: "/ontology-metadata/api"
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
async subscribe(objectSet, listener) {
|
|
398
|
-
const sub = {
|
|
399
|
-
listener: fillOutListener(listener),
|
|
400
|
-
objectSet,
|
|
401
|
-
status: "preparing",
|
|
402
|
-
// Since we don't have a real subscription id yet but we need to keep
|
|
403
|
-
// track of this reference, we can just use a random uuid.
|
|
404
|
-
subscriptionId: `TMP-${crypto.randomUUID()}`
|
|
405
|
-
};
|
|
406
|
-
this.#subscriptions.set(sub.subscriptionId, sub);
|
|
407
|
-
this.#initiateSubscribe(sub);
|
|
408
|
-
return () => {
|
|
409
|
-
this.#unsubscribe(sub);
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Called at least once for every subscription.
|
|
414
|
-
*
|
|
415
|
-
* - Resets pending expiry
|
|
416
|
-
* - Recreates temporary object set
|
|
417
|
-
* - Triggers a full subscribe message
|
|
418
|
-
*
|
|
419
|
-
* @returns
|
|
420
|
-
*/
|
|
421
|
-
async #initiateSubscribe(sub) {
|
|
422
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
423
|
-
this.#logger?.trace("#initiateSubscribe()");
|
|
424
|
-
}
|
|
425
|
-
if (sub.expiry) {
|
|
426
|
-
clearTimeout(sub.expiry);
|
|
427
|
-
}
|
|
428
|
-
sub.expiry = setTimeout(() => this.#expire(sub), this.OBJECT_SET_EXPIRY_MS);
|
|
429
|
-
const ontologyRid = await this.#client.ontologyRid;
|
|
430
|
-
try {
|
|
431
|
-
const [temporaryObjectSet] = await Promise.all([
|
|
432
|
-
// create a time-bounded object set representation for watching
|
|
433
|
-
this.#createTemporaryObjectSet(sub.objectSet),
|
|
434
|
-
this.#ensureWebsocket(),
|
|
435
|
-
// look up the object type's rid and ensure that we have enabled object set watcher for that rid
|
|
436
|
-
// TODO ???
|
|
437
|
-
getObjectSetBaseType(sub.objectSet).then((baseType) => esm_exports.ObjectTypesV2.getObjectTypeV2(this.#client, ontologyRid, baseType)).then((objectType) => this.#enableObjectSetsWatcher([objectType.rid]))
|
|
438
|
-
]);
|
|
439
|
-
if (subscriptionIsDone(sub)) {
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
sub.temporaryObjectSetId = temporaryObjectSet.objectSetRid;
|
|
443
|
-
if (this.#ws?.readyState === WebSocket.OPEN) {
|
|
444
|
-
this.#sendSubscribeMessage();
|
|
445
|
-
}
|
|
446
|
-
} catch (error) {
|
|
447
|
-
this.#logger?.error(error, "Error in #initiateSubscribe");
|
|
448
|
-
sub.listener.onError(error);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
#sendSubscribeMessage() {
|
|
452
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
453
|
-
this.#logger?.trace("#sendSubscribeMessage()");
|
|
454
|
-
}
|
|
455
|
-
const readySubs = [...this.#subscriptions.values()].filter(isReady);
|
|
456
|
-
if (readySubs.length === 0) {
|
|
457
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
458
|
-
this.#logger?.trace("#sendSubscribeMessage(): aborting due to no ready subscriptions");
|
|
459
|
-
}
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
const id = crypto.randomUUID();
|
|
463
|
-
this.#pendingSubscriptions.set(id, readySubs);
|
|
464
|
-
const subscribe = {
|
|
465
|
-
id,
|
|
466
|
-
requests: readySubs.map(({
|
|
467
|
-
temporaryObjectSetId
|
|
468
|
-
}) => ({
|
|
469
|
-
objectSet: temporaryObjectSetId,
|
|
470
|
-
objectSetContext: {
|
|
471
|
-
objectSetFilterContext: {
|
|
472
|
-
parameterOverrides: {}
|
|
473
|
-
}
|
|
474
|
-
},
|
|
475
|
-
watchAllLinks: false
|
|
476
|
-
}))
|
|
477
|
-
};
|
|
478
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
479
|
-
this.#logger?.trace({
|
|
480
|
-
payload: subscribe
|
|
481
|
-
}, "sending subscribe message");
|
|
482
|
-
}
|
|
483
|
-
this.#ws?.send(JSON.stringify(subscribe));
|
|
484
|
-
}
|
|
485
|
-
#expire(sub) {
|
|
486
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
487
|
-
this.#logger?.trace({
|
|
488
|
-
subscription: sub
|
|
489
|
-
}, "#expire()");
|
|
490
|
-
}
|
|
491
|
-
sub.status = "expired";
|
|
492
|
-
this.#initiateSubscribe(sub);
|
|
493
|
-
}
|
|
494
|
-
#unsubscribe(sub, newStatus = "done") {
|
|
495
|
-
if (subscriptionIsDone(sub)) {
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
sub.status = newStatus;
|
|
499
|
-
sub.listener = fillOutListener({});
|
|
500
|
-
if (sub.expiry) {
|
|
501
|
-
clearTimeout(sub.expiry);
|
|
502
|
-
sub.expiry = void 0;
|
|
503
|
-
}
|
|
504
|
-
this.#subscriptions.delete(sub.subscriptionId);
|
|
505
|
-
if (this.#maybeDisconnectTimeout) {
|
|
506
|
-
clearTimeout(this.#maybeDisconnectTimeout);
|
|
507
|
-
}
|
|
508
|
-
this.#maybeDisconnectTimeout = setTimeout(
|
|
509
|
-
() => {
|
|
510
|
-
this.#maybeDisconnectTimeout = void 0;
|
|
511
|
-
if (this.#subscriptions.size === 0) {
|
|
512
|
-
this.#cycleWebsocket();
|
|
513
|
-
}
|
|
514
|
-
},
|
|
515
|
-
15e3
|
|
516
|
-
/* ms */
|
|
517
|
-
);
|
|
518
|
-
}
|
|
519
|
-
async #ensureWebsocket() {
|
|
520
|
-
if (this.#ws == null) {
|
|
521
|
-
const {
|
|
522
|
-
baseUrl,
|
|
523
|
-
tokenProvider
|
|
524
|
-
} = this.#client;
|
|
525
|
-
const base = new URL(baseUrl);
|
|
526
|
-
const url = `wss://${base.host}/object-set-watcher/ws/subscriptions`;
|
|
527
|
-
const token = await tokenProvider();
|
|
528
|
-
if (this.#ws == null) {
|
|
529
|
-
const nextConnectTime = (this.#lastWsConnect ?? 0) + this.MINIMUM_RECONNECT_DELAY_MS;
|
|
530
|
-
if (nextConnectTime > Date.now()) {
|
|
531
|
-
await new Promise((resolve) => {
|
|
532
|
-
setTimeout(resolve, nextConnectTime - Date.now());
|
|
533
|
-
});
|
|
534
|
-
}
|
|
535
|
-
this.#lastWsConnect = Date.now();
|
|
536
|
-
if (this.#ws == null) {
|
|
537
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
538
|
-
this.#logger?.trace("Creating websocket");
|
|
539
|
-
}
|
|
540
|
-
this.#ws = new WebSocket(url, [`Bearer-${token}`]);
|
|
541
|
-
this.#ws.addEventListener("close", this.#onClose);
|
|
542
|
-
this.#ws.addEventListener("message", this.#onMessage);
|
|
543
|
-
this.#ws.addEventListener("open", this.#onOpen);
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
if (this.#ws.readyState === WebSocket.CONNECTING) {
|
|
547
|
-
const ws = this.#ws;
|
|
548
|
-
return new Promise((resolve, reject) => {
|
|
549
|
-
function cleanup() {
|
|
550
|
-
ws.removeEventListener("open", open);
|
|
551
|
-
ws.removeEventListener("error", error);
|
|
552
|
-
ws.removeEventListener("close", cleanup);
|
|
553
|
-
}
|
|
554
|
-
function open() {
|
|
555
|
-
cleanup();
|
|
556
|
-
resolve();
|
|
557
|
-
}
|
|
558
|
-
function error(evt) {
|
|
559
|
-
cleanup();
|
|
560
|
-
reject(evt);
|
|
561
|
-
}
|
|
562
|
-
ws.addEventListener("open", open);
|
|
563
|
-
ws.addEventListener("error", error);
|
|
564
|
-
ws.addEventListener("close", cleanup);
|
|
565
|
-
});
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
#onOpen = () => {
|
|
570
|
-
this.#sendSubscribeMessage();
|
|
571
|
-
};
|
|
572
|
-
#onMessage = async (message) => {
|
|
573
|
-
const data = JSON.parse(message.data.toString());
|
|
574
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
575
|
-
this.#logger?.trace({
|
|
576
|
-
payload: data
|
|
577
|
-
}, "received message from ws");
|
|
578
|
-
}
|
|
579
|
-
switch (data.type) {
|
|
580
|
-
case "objectSetChanged":
|
|
581
|
-
return this.#handleMessage_objectSetChanged(data.objectSetChanged);
|
|
582
|
-
case "refreshObjectSet":
|
|
583
|
-
return this.#handleMessage_refreshObjectSet(data.refreshObjectSet);
|
|
584
|
-
case "subscribeResponses":
|
|
585
|
-
return this.#handleMessage_subscribeResponses(data.subscribeResponses);
|
|
586
|
-
case "subscriptionClosed": {
|
|
587
|
-
const payload = data.subscriptionClosed;
|
|
588
|
-
return this.#handleMessage_subscriptionClosed(payload);
|
|
589
|
-
}
|
|
590
|
-
default:
|
|
591
|
-
process.env.NODE_ENV !== "production" ? invariant2(false, "Unexpected message type") : invariant2(false) ;
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
#handleMessage_objectSetChanged = async (payload) => {
|
|
595
|
-
const sub = this.#subscriptions.get(payload.id);
|
|
596
|
-
!sub ? process.env.NODE_ENV !== "production" ? invariant2(false, `Expected subscription id ${payload.id}`) : invariant2(false) : void 0;
|
|
597
|
-
if ("confidenceValue" in payload) {
|
|
598
|
-
sub.listener.onOutOfDate();
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
const objects = payload.updates.filter(function(a) {
|
|
602
|
-
return a.type === "object";
|
|
603
|
-
}).map((a) => a.object);
|
|
604
|
-
!(objects.length === payload.updates.length) ? process.env.NODE_ENV !== "production" ? invariant2(false, "currently only support full updates not reference updates") : invariant2(false) : void 0;
|
|
605
|
-
sub.listener.onChange(await convertFoundryToOsdkObjects(this.#client, this.#metadataContext, objects));
|
|
606
|
-
};
|
|
607
|
-
#handleMessage_refreshObjectSet = (payload) => {
|
|
608
|
-
const sub = this.#subscriptions.get(payload.id);
|
|
609
|
-
!sub ? process.env.NODE_ENV !== "production" ? invariant2(false, `Expected subscription id ${payload.id}`) : invariant2(false) : void 0;
|
|
610
|
-
sub.listener.onOutOfDate();
|
|
611
|
-
};
|
|
612
|
-
#handleMessage_subscribeResponses = (payload) => {
|
|
613
|
-
const {
|
|
614
|
-
id,
|
|
615
|
-
responses
|
|
616
|
-
} = payload;
|
|
617
|
-
const subs = this.#pendingSubscriptions.get(id);
|
|
618
|
-
!subs ? process.env.NODE_ENV !== "production" ? invariant2(false, `should have a pending subscription for ${id}`) : invariant2(false) : void 0;
|
|
619
|
-
this.#pendingSubscriptions.delete(id);
|
|
620
|
-
for (let i = 0; i < responses.length; i++) {
|
|
621
|
-
const sub = subs[i];
|
|
622
|
-
const response = responses[i];
|
|
623
|
-
switch (response.type) {
|
|
624
|
-
case "error":
|
|
625
|
-
sub.listener.onError(response.error);
|
|
626
|
-
this.#unsubscribe(sub, "error");
|
|
627
|
-
break;
|
|
628
|
-
case "qos":
|
|
629
|
-
this.#cycleWebsocket();
|
|
630
|
-
break;
|
|
631
|
-
case "success":
|
|
632
|
-
const shouldFireOutOfDate = sub.status === "expired" || sub.status === "reconnecting";
|
|
633
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
634
|
-
this.#logger?.trace({
|
|
635
|
-
shouldFireOutOfDate
|
|
636
|
-
}, "success");
|
|
637
|
-
}
|
|
638
|
-
sub.status = "subscribed";
|
|
639
|
-
if (sub.subscriptionId !== response.success.id) {
|
|
640
|
-
this.#subscriptions.delete(sub.subscriptionId);
|
|
641
|
-
sub.subscriptionId = response.success.id;
|
|
642
|
-
this.#subscriptions.set(sub.subscriptionId, sub);
|
|
643
|
-
}
|
|
644
|
-
if (shouldFireOutOfDate) sub.listener.onOutOfDate();
|
|
645
|
-
break;
|
|
646
|
-
default:
|
|
647
|
-
sub.listener.onError(response);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
#handleMessage_subscriptionClosed(payload) {
|
|
652
|
-
const sub = this.#subscriptions.get(payload.id);
|
|
653
|
-
!sub ? process.env.NODE_ENV !== "production" ? invariant2(false, `Expected subscription id ${payload.id}`) : invariant2(false) : void 0;
|
|
654
|
-
sub.listener.onError(payload.error);
|
|
655
|
-
this.#unsubscribe(sub, "error");
|
|
656
|
-
}
|
|
657
|
-
#onClose = (event) => {
|
|
658
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
659
|
-
this.#logger?.trace({
|
|
660
|
-
event
|
|
661
|
-
}, "Received close event from ws", event);
|
|
662
|
-
}
|
|
663
|
-
this.#cycleWebsocket();
|
|
664
|
-
};
|
|
665
|
-
async #enableObjectSetsWatcher(objectTypeRids) {
|
|
666
|
-
return batchEnableWatcher(this.#oswContext, {
|
|
667
|
-
requests: objectTypeRids
|
|
668
|
-
});
|
|
669
|
-
}
|
|
670
|
-
async #createTemporaryObjectSet(objectSet) {
|
|
671
|
-
const objectSetBaseType = await getObjectSetBaseType(objectSet);
|
|
672
|
-
const mcc = await metadataCacheClient(this.#client);
|
|
673
|
-
const objectInfo = await mcc.forObjectByApiName(objectSetBaseType);
|
|
674
|
-
const propMapping = await objectInfo.getPropertyMapping();
|
|
675
|
-
const temporaryObjectSet = await createTemporaryObjectSet(this.#ossContext, {
|
|
676
|
-
objectSet: toConjureObjectSet(objectSet, propMapping),
|
|
677
|
-
timeToLive: "ONE_DAY",
|
|
678
|
-
// MUST keep in sync with the value for expiry in `#initiateSubscribe`.
|
|
679
|
-
objectSetFilterContext: {
|
|
680
|
-
parameterOverrides: {}
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
return {
|
|
684
|
-
objectSetRid: temporaryObjectSet.objectSetRid
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
#cycleWebsocket = () => {
|
|
688
|
-
if (this.#ws) {
|
|
689
|
-
this.#ws.removeEventListener("open", this.#onOpen);
|
|
690
|
-
this.#ws.removeEventListener("message", this.#onMessage);
|
|
691
|
-
this.#ws.removeEventListener("close", this.#onClose);
|
|
692
|
-
if (this.#ws.readyState !== WebSocket.CLOSING && this.#ws.readyState !== WebSocket.CLOSED) {
|
|
693
|
-
this.#ws.close();
|
|
694
|
-
}
|
|
695
|
-
this.#ws = void 0;
|
|
696
|
-
}
|
|
697
|
-
if (this.#subscriptions.size > 0) {
|
|
698
|
-
if (process?.env?.NODE_ENV !== "production") {
|
|
699
|
-
for (const s of this.#subscriptions.values()) {
|
|
700
|
-
!(s.status !== "done" && s.status !== "error") ? process.env.NODE_ENV !== "production" ? invariant2(false, "should not have done/error subscriptions still") : invariant2(false) : void 0;
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
for (const s of this.#subscriptions.values()) {
|
|
704
|
-
if (s.status === "subscribed") s.status = "reconnecting";
|
|
705
|
-
}
|
|
706
|
-
this.#ensureWebsocket();
|
|
707
|
-
}
|
|
708
|
-
};
|
|
709
|
-
};
|
|
710
|
-
async function convertFoundryToOsdkObjects(client, ctx, objects) {
|
|
711
|
-
const osdkObjects = await Promise.all(objects.map(async (object) => {
|
|
712
|
-
const propertyMapping = await (await (await metadataCacheClient(client)).forObjectByRid(object.type)).getPropertyMapping();
|
|
713
|
-
const convertedObject = Object.fromEntries([...Object.entries(object.properties).map(([key, value]) => {
|
|
714
|
-
return [propertyMapping?.propertyIdToApiNameMapping[key], value];
|
|
715
|
-
}), [propertyMapping?.propertyIdToApiNameMapping[Object.entries(object.key)[0][0]], Object.entries(object.key)[0][1]], ["__apiName", propertyMapping?.apiName], ["$apiName", propertyMapping?.apiName]]);
|
|
716
|
-
return convertedObject;
|
|
717
|
-
}));
|
|
718
|
-
return await convertWireToOsdkObjects(client, osdkObjects, void 0);
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
// src/objectSet/createUnstableObjectSet.ts
|
|
722
|
-
function UNSTABLE_createObjectSet(objectType, clientCtx, objectSet = {
|
|
723
|
-
type: "base",
|
|
724
|
-
objectType: objectType["apiName"]
|
|
725
|
-
}) {
|
|
726
|
-
return Object.assign(
|
|
727
|
-
createObjectSet(objectType, clientCtx, objectSet),
|
|
728
|
-
{
|
|
729
|
-
subscribe(listener) {
|
|
730
|
-
const pendingSubscribe = ObjectSetListenerWebsocket.getInstance(clientCtx).subscribe(objectSet, listener);
|
|
731
|
-
return async () => (await pendingSubscribe)();
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
// cast is needed because we are relying on the where clause doing the right thing via client.createObjectSet
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// src/pageRequestAsAsyncIter.ts
|
|
739
|
-
function getResults(x) {
|
|
740
|
-
return x.results;
|
|
741
|
-
}
|
|
742
|
-
function applyPageToken(payload, {
|
|
743
|
-
pageToken
|
|
744
|
-
}) {
|
|
745
|
-
return pageToken ? {
|
|
746
|
-
...payload,
|
|
747
|
-
pageToken
|
|
748
|
-
} : void 0;
|
|
749
|
-
}
|
|
750
|
-
async function* pageRequestAsAsyncIter(call, values, nextArgs, initialPayload) {
|
|
751
|
-
let payload = initialPayload;
|
|
752
|
-
while (payload) {
|
|
753
|
-
const r = await call(payload);
|
|
754
|
-
for (const q of values(r)) {
|
|
755
|
-
yield q;
|
|
756
|
-
}
|
|
757
|
-
payload = nextArgs(payload, r);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
// src/__unstable/createBulkLinksAsyncIterFactory.ts
|
|
762
|
-
function createBulkLinksAsyncIterFactory(ctx) {
|
|
763
|
-
return async function* (objs, linkTypes) {
|
|
764
|
-
if (objs.length === 0) {
|
|
765
|
-
return;
|
|
766
|
-
}
|
|
767
|
-
ctx.logger?.debug("Preparing to fetch bulk links");
|
|
768
|
-
!objs.every((a) => a.$objectType === objs[0].$objectType) ? process.env.NODE_ENV !== "production" ? invariant2(false) : invariant2(false) : void 0;
|
|
769
|
-
const mcc = await metadataCacheClient(ctx);
|
|
770
|
-
const helper = await mcc.forObjectByApiName(objs[0].$objectType);
|
|
771
|
-
const [objectTypeRid, propertyMapping, fullLinkMapping] = await Promise.all([helper.getRid(), helper.getPropertyMapping(), helper.getLinkMapping()]);
|
|
772
|
-
const linkMapping = Object.fromEntries(Object.entries(fullLinkMapping).filter(([apiName]) => linkTypes.includes(apiName)));
|
|
773
|
-
for (const linkType of linkTypes) {
|
|
774
|
-
if (linkMapping[linkType] == null) {
|
|
775
|
-
throw "Unable to find link type: " + linkType;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
const req = {
|
|
779
|
-
objectSetContext: {
|
|
780
|
-
forkRid: void 0,
|
|
781
|
-
objectSetFilterContext: {
|
|
782
|
-
parameterOverrides: {}
|
|
783
|
-
},
|
|
784
|
-
ontologyBranchRid: void 0,
|
|
785
|
-
owningRid: void 0,
|
|
786
|
-
reportUsage: void 0,
|
|
787
|
-
workstateRid: void 0
|
|
788
|
-
},
|
|
789
|
-
responseOptions: {
|
|
790
|
-
includeObjectSetEntities: true,
|
|
791
|
-
includeUsageCost: false
|
|
792
|
-
},
|
|
793
|
-
pageSize: 1e3,
|
|
794
|
-
pageToken: void 0,
|
|
795
|
-
linksRequests: [{
|
|
796
|
-
directedLinkTypes: Object.values(linkMapping).map(({
|
|
797
|
-
directedLinkTypeRid
|
|
798
|
-
}) => directedLinkTypeRid),
|
|
799
|
-
objects: conjureUnionType("objects", objs.map((o) => conjureUnionType("objectLocatorV2", {
|
|
800
|
-
objectTypeRid,
|
|
801
|
-
objectPrimaryKey: {
|
|
802
|
-
[propertyMapping.pk.rid]: conjureUnionType(propertyMapping.pk.type.type, o.$primaryKey)
|
|
803
|
-
}
|
|
804
|
-
})))
|
|
805
|
-
}]
|
|
806
|
-
};
|
|
807
|
-
const bulkLinksIter = pageRequestAsAsyncIter(getBulkLinksPage.bind(void 0, makeConjureContext(ctx, "/object-set-service/api")), getResults, applyPageToken, req);
|
|
808
|
-
for await (const item of bulkLinksIter) {
|
|
809
|
-
const {
|
|
810
|
-
objectIdentifier
|
|
811
|
-
} = item;
|
|
812
|
-
const obj = findObject(objectIdentifier, objs);
|
|
813
|
-
for (const link of item.links) {
|
|
814
|
-
const ref = link.link[link.linkSide === "SOURCE" ? "objectSideB" : "objectSideA"];
|
|
815
|
-
const pk = getPrimaryKeyOrThrow(ref);
|
|
816
|
-
const otherObjectApiName = await (await mcc.forObjectByRid(pk.objectTypeRid)).getApiName();
|
|
817
|
-
const mappedLink = Object.values(linkMapping).find((a) => a.directedLinkTypeRid.linkTypeRid === link.link.linkTypeRid && a.directedLinkTypeRid.linkSide === link.linkSide);
|
|
818
|
-
if (!mappedLink) throw new Error("Could not find link type");
|
|
819
|
-
yield {
|
|
820
|
-
object: obj,
|
|
821
|
-
linkApiName: mappedLink.apiName,
|
|
822
|
-
otherObjectApiName,
|
|
823
|
-
otherObjectPk: pk.pkValue
|
|
824
|
-
};
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
};
|
|
828
|
-
}
|
|
829
|
-
function findObject(objectIdentifier, objs) {
|
|
830
|
-
const {
|
|
831
|
-
pkValue
|
|
832
|
-
} = getPrimaryKeyOrThrow(objectIdentifier);
|
|
833
|
-
const obj = objs.find((o) => o.$primaryKey === pkValue);
|
|
834
|
-
if (obj == null) {
|
|
835
|
-
throw new Error(`Needed to find object with pk ${pkValue}} and could not`);
|
|
836
|
-
}
|
|
837
|
-
return obj;
|
|
838
|
-
}
|
|
839
|
-
function getPrimaryKeyOrThrow(ref) {
|
|
840
|
-
if ("type" in ref && ref.type !== "objectLocatorV2") {
|
|
841
|
-
throw new Error("We do not support looking up object by rid");
|
|
842
|
-
}
|
|
843
|
-
const pks = Object.entries(ref.objectLocatorV2.objectPrimaryKey);
|
|
844
|
-
if (pks.length !== 1) {
|
|
845
|
-
throw new Error("Unable to support this request due to multiple pks");
|
|
846
|
-
}
|
|
847
|
-
return {
|
|
848
|
-
objectTypeRid: ref.objectLocatorV2.objectTypeRid,
|
|
849
|
-
pkValue: pks[0][1][pks[0][1].type]
|
|
850
|
-
};
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
// src/__unstable/UNSTABLE_createClient.ts
|
|
854
|
-
function UNSTABLE_createClient(...args) {
|
|
855
|
-
const client = createClientInternal(UNSTABLE_createObjectSet, ...args);
|
|
856
|
-
const unstableClient = Object.defineProperties(client, {
|
|
857
|
-
__UNSTABLE_getBulkLinks: {
|
|
858
|
-
get: () => createBulkLinksAsyncIterFactory(client[symbolClientContext])
|
|
859
|
-
},
|
|
860
|
-
__UNSTABLE_preexistingObjectSet: {
|
|
861
|
-
get: () => (definition, rid) => {
|
|
862
|
-
return UNSTABLE_createObjectSet(definition, client[symbolClientContext], {
|
|
863
|
-
type: "intersect",
|
|
864
|
-
objectSets: [{
|
|
865
|
-
type: "base",
|
|
866
|
-
objectType: definition.apiName
|
|
867
|
-
}, {
|
|
868
|
-
type: "reference",
|
|
869
|
-
reference: rid
|
|
870
|
-
}]
|
|
871
|
-
});
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
return unstableClient;
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
export { UNSTABLE_createClient as createClient };
|
|
1
|
+
export { augment } from '../chunk-CG25K4WC.js';
|
|
879
2
|
//# sourceMappingURL=unstable-do-not-use.js.map
|
|
880
3
|
//# sourceMappingURL=unstable-do-not-use.js.map
|