@osdk/client 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/js/index.cjs +1381 -34
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +1370 -18
- package/build/js/index.mjs.map +1 -1
- package/build/types/MinimalClientContext.d.ts +10 -6
- package/build/types/MinimalClientContext.d.ts.map +1 -1
- package/build/types/SatisfiesSemver.d.ts +4 -0
- package/build/types/SatisfiesSemver.d.ts.map +1 -0
- package/build/types/SatisfiesSemver.test.d.ts +2 -0
- package/build/types/SatisfiesSemver.test.d.ts.map +1 -0
- package/build/types/createClient.d.ts +12 -3
- package/build/types/createClient.d.ts.map +1 -1
- package/build/types/generatedNoCheck/Ontology.d.ts +2 -5
- package/build/types/generatedNoCheck/Ontology.d.ts.map +1 -1
- package/build/types/generatedNoCheck/OntologyMetadata.d.ts +5 -5
- package/build/types/generatedNoCheck/OntologyMetadata.d.ts.map +1 -1
- package/build/types/index.d.ts +9 -9
- package/build/types/index.d.ts.map +1 -1
- package/build/types/object/Result.d.ts +12 -0
- package/build/types/object/Result.d.ts.map +1 -0
- package/build/types/object/fetchPage.d.ts +8 -4
- package/build/types/object/fetchPage.d.ts.map +1 -1
- package/build/types/objectSet/ObjectSet.d.ts +4 -2
- package/build/types/objectSet/ObjectSet.d.ts.map +1 -1
- package/build/types/objectSet/createObjectSet.d.ts.map +1 -1
- package/build/types/ontology/loadFullObjectMetadata.d.ts.map +1 -1
- package/build/types/util/test/mockOntology.d.ts +1 -0
- package/build/types/util/test/mockOntology.d.ts.map +1 -1
- package/changelog/0.15.0/pr-145.v2.yml +5 -0
- package/changelog/0.15.0/pr-151.v2.yml +5 -0
- package/changelog/0.15.0/pr-155.v2.yml +5 -0
- package/changelog/0.15.0/pr-156.v2.yml +5 -0
- package/changelog/0.15.0/pr-157.v2.yml +5 -0
- package/package.json +8 -8
- package/build/js/chunk-AW6UQOAF.cjs +0 -1364
- package/build/js/chunk-AW6UQOAF.cjs.map +0 -1
- package/build/js/chunk-Y7UBQD5N.mjs +0 -1346
- package/build/js/chunk-Y7UBQD5N.mjs.map +0 -1
- package/build/js/public/objects.cjs +0 -16
- package/build/js/public/objects.cjs.map +0 -1
- package/build/js/public/objects.mjs +0 -3
- package/build/js/public/objects.mjs.map +0 -1
- package/build/types/public/objects.d.ts +0 -2
- package/build/types/public/objects.d.ts.map +0 -1
|
@@ -1,1364 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var requests = require('@osdk/gateway/requests');
|
|
4
|
-
var shared_net = require('@osdk/shared.net');
|
|
5
|
-
var invariant2 = require('tiny-invariant');
|
|
6
|
-
var WebSocket = require('isomorphic-ws');
|
|
7
|
-
var conjureLite = require('conjure-lite');
|
|
8
|
-
|
|
9
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
|
|
11
|
-
var invariant2__default = /*#__PURE__*/_interopDefault(invariant2);
|
|
12
|
-
var WebSocket__default = /*#__PURE__*/_interopDefault(WebSocket);
|
|
13
|
-
|
|
14
|
-
var __defProp = Object.defineProperty;
|
|
15
|
-
var __export = (target, all) => {
|
|
16
|
-
for (var name in all)
|
|
17
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
-
};
|
|
19
|
-
function legacyToModernSingleAggregationResult(entry) {
|
|
20
|
-
return entry.metrics.reduce((accumulator, curValue) => {
|
|
21
|
-
const parts = curValue.name.split(".");
|
|
22
|
-
if (parts[0] === "count") {
|
|
23
|
-
return accumulator;
|
|
24
|
-
}
|
|
25
|
-
!(parts.length === 2) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "assumed we were getting a `${key}.${type}`") : invariant2__default.default(false) : void 0;
|
|
26
|
-
if (!(parts[0] in accumulator)) {
|
|
27
|
-
accumulator[parts[0]] = {};
|
|
28
|
-
}
|
|
29
|
-
accumulator[parts[0]][parts[1]] = curValue.value;
|
|
30
|
-
return accumulator;
|
|
31
|
-
}, {});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/internal/conversions/modernToLegacyAggregationClause.ts
|
|
35
|
-
function modernToLegacyAggregationClause(select) {
|
|
36
|
-
return Object.entries(select).flatMap(([k, v]) => {
|
|
37
|
-
if (k === "$count") {
|
|
38
|
-
if (v)
|
|
39
|
-
return {
|
|
40
|
-
type: "count",
|
|
41
|
-
name: "count"
|
|
42
|
-
};
|
|
43
|
-
return [];
|
|
44
|
-
} else if (Array.isArray(v)) {
|
|
45
|
-
return v.map((v2) => {
|
|
46
|
-
return {
|
|
47
|
-
type: v2,
|
|
48
|
-
name: `${k}.${v2}`,
|
|
49
|
-
field: k
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
return [{
|
|
54
|
-
type: v,
|
|
55
|
-
// FIXME v has additional possible values
|
|
56
|
-
name: `${k}.${v}`,
|
|
57
|
-
field: k
|
|
58
|
-
}];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// src/query/aggregations/GroupByClause.ts
|
|
64
|
-
var DurationMapping = {
|
|
65
|
-
"sec": "SECONDS",
|
|
66
|
-
"seconds": "SECONDS",
|
|
67
|
-
"min": "MINUTES",
|
|
68
|
-
"minute": "MINUTES",
|
|
69
|
-
"minutes": "MINUTES",
|
|
70
|
-
"hr": "HOURS",
|
|
71
|
-
"hrs": "HOURS",
|
|
72
|
-
"hour": "HOURS",
|
|
73
|
-
"hours": "HOURS",
|
|
74
|
-
"day": "DAYS",
|
|
75
|
-
"days": "DAYS",
|
|
76
|
-
"wk": "WEEKS",
|
|
77
|
-
"week": "WEEKS",
|
|
78
|
-
"weeks": "WEEKS",
|
|
79
|
-
"mos": "MONTHS",
|
|
80
|
-
"month": "MONTHS",
|
|
81
|
-
"months": "MONTHS",
|
|
82
|
-
"yr": "YEARS",
|
|
83
|
-
"year": "YEARS",
|
|
84
|
-
"years": "YEARS",
|
|
85
|
-
"quarter": "QUARTERS",
|
|
86
|
-
"quarters": "QUARTERS"
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// src/internal/conversions/modernToLegacyGroupByClause.ts
|
|
90
|
-
function modernToLegacyGroupByClause(groupByClause) {
|
|
91
|
-
if (!groupByClause)
|
|
92
|
-
return [];
|
|
93
|
-
return Object.entries(groupByClause).flatMap(([field, type]) => {
|
|
94
|
-
if (type === "exact") {
|
|
95
|
-
return [{
|
|
96
|
-
type,
|
|
97
|
-
field
|
|
98
|
-
}];
|
|
99
|
-
} else if ("exactWithLimit" in type) {
|
|
100
|
-
{
|
|
101
|
-
return [{
|
|
102
|
-
type: "exact",
|
|
103
|
-
field,
|
|
104
|
-
maxGroupCount: type.exactWithLimit
|
|
105
|
-
}];
|
|
106
|
-
}
|
|
107
|
-
} else if ("fixedWidth" in type) {
|
|
108
|
-
return [{
|
|
109
|
-
type: "fixedWidth",
|
|
110
|
-
field,
|
|
111
|
-
fixedWidth: type.fixedWidth
|
|
112
|
-
}];
|
|
113
|
-
} else if ("ranges" in type) {
|
|
114
|
-
return [{
|
|
115
|
-
type: "ranges",
|
|
116
|
-
field,
|
|
117
|
-
ranges: type.ranges.map((range) => convertRange(range))
|
|
118
|
-
}];
|
|
119
|
-
} else if ("duration" in type) {
|
|
120
|
-
return [{
|
|
121
|
-
type: "duration",
|
|
122
|
-
field,
|
|
123
|
-
value: type.duration[0],
|
|
124
|
-
unit: DurationMapping[type.duration[1]]
|
|
125
|
-
}];
|
|
126
|
-
} else
|
|
127
|
-
return [];
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
function convertRange(range) {
|
|
131
|
-
return {
|
|
132
|
-
startValue: range[0],
|
|
133
|
-
endValue: range[1]
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/query/WhereClause.ts
|
|
138
|
-
var DistanceUnitMapping = {
|
|
139
|
-
"centimeter": "CENTIMETERS",
|
|
140
|
-
"centimeters": "CENTIMETERS",
|
|
141
|
-
"cm": "CENTIMETERS",
|
|
142
|
-
"meter": "METERS",
|
|
143
|
-
"meters": "METERS",
|
|
144
|
-
"m": "METERS",
|
|
145
|
-
"kilometer": "KILOMETERS",
|
|
146
|
-
"kilometers": "KILOMETERS",
|
|
147
|
-
"km": "KILOMETERS",
|
|
148
|
-
"inch": "INCHES",
|
|
149
|
-
"inches": "INCHES",
|
|
150
|
-
"foot": "FEET",
|
|
151
|
-
"feet": "FEET",
|
|
152
|
-
"yard": "YARDS",
|
|
153
|
-
"yards": "YARDS",
|
|
154
|
-
"mile": "MILES",
|
|
155
|
-
"miles": "MILES",
|
|
156
|
-
"nautical_mile": "NAUTICAL_MILES",
|
|
157
|
-
"nauticalMile": "NAUTICAL_MILES",
|
|
158
|
-
"nautical miles": "NAUTICAL_MILES"
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// src/internal/conversions/modernToLegacyWhereClause.ts
|
|
162
|
-
function modernToLegacyWhereClause(whereClause) {
|
|
163
|
-
if ("$and" in whereClause) {
|
|
164
|
-
return {
|
|
165
|
-
type: "and",
|
|
166
|
-
value: whereClause.$and.map(modernToLegacyWhereClause)
|
|
167
|
-
};
|
|
168
|
-
} else if ("$or" in whereClause) {
|
|
169
|
-
return {
|
|
170
|
-
type: "or",
|
|
171
|
-
value: whereClause.$or.map(modernToLegacyWhereClause)
|
|
172
|
-
};
|
|
173
|
-
} else if ("$not" in whereClause) {
|
|
174
|
-
return {
|
|
175
|
-
type: "not",
|
|
176
|
-
value: modernToLegacyWhereClause(whereClause.$not)
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
const parts = Object.entries(whereClause);
|
|
180
|
-
if (parts.length === 1) {
|
|
181
|
-
return handleWherePair(parts[0]);
|
|
182
|
-
}
|
|
183
|
-
return {
|
|
184
|
-
type: "and",
|
|
185
|
-
value: parts.map(handleWherePair)
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
function makeGeoFilterBbox(field, bbox, filterType) {
|
|
189
|
-
return {
|
|
190
|
-
type: filterType === "$within" ? "withinBoundingBox" : "intersectsBoundingBox",
|
|
191
|
-
field,
|
|
192
|
-
value: {
|
|
193
|
-
topLeft: {
|
|
194
|
-
type: "Point",
|
|
195
|
-
coordinates: [bbox[0], bbox[3]]
|
|
196
|
-
},
|
|
197
|
-
bottomRight: {
|
|
198
|
-
type: "Point",
|
|
199
|
-
coordinates: [bbox[2], bbox[1]]
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
function makeGeoFilterPolygon(field, coordinates, filterType) {
|
|
205
|
-
return {
|
|
206
|
-
type: filterType,
|
|
207
|
-
field,
|
|
208
|
-
value: {
|
|
209
|
-
type: "Polygon",
|
|
210
|
-
coordinates
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
function handleWherePair([field, filter]) {
|
|
215
|
-
!(filter != null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "Defined key values are only allowed when they are not undefined.") : invariant2__default.default(false) : void 0;
|
|
216
|
-
if (typeof filter === "string" || typeof filter === "number" || typeof filter === "boolean") {
|
|
217
|
-
return {
|
|
218
|
-
type: "eq",
|
|
219
|
-
field,
|
|
220
|
-
value: filter
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
const keysOfFilter = Object.keys(filter);
|
|
224
|
-
const hasDollarSign = keysOfFilter.some((key) => key.startsWith("$"));
|
|
225
|
-
!(!hasDollarSign || keysOfFilter.length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "WhereClause Filter with multiple clauses isn't allowed") : invariant2__default.default(false) : void 0;
|
|
226
|
-
if (!hasDollarSign) {
|
|
227
|
-
throw new Error(`Unsupported filter. Did you forget to use a $-prefixed filter? (${JSON.stringify(filter)})`);
|
|
228
|
-
}
|
|
229
|
-
const firstKey = keysOfFilter[0];
|
|
230
|
-
!(filter[firstKey] != null) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false) : invariant2__default.default(false) : void 0;
|
|
231
|
-
if (firstKey === "$ne") {
|
|
232
|
-
return {
|
|
233
|
-
type: "not",
|
|
234
|
-
value: {
|
|
235
|
-
type: "eq",
|
|
236
|
-
field,
|
|
237
|
-
value: filter[firstKey]
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
if (firstKey === "$within") {
|
|
242
|
-
const withinBody = filter[firstKey];
|
|
243
|
-
if (Array.isArray(withinBody)) {
|
|
244
|
-
return makeGeoFilterBbox(field, withinBody, firstKey);
|
|
245
|
-
} else if ("bbox" in withinBody && !("type" in withinBody)) {
|
|
246
|
-
return makeGeoFilterBbox(field, withinBody.bbox, firstKey);
|
|
247
|
-
} else if ("distance" in withinBody && "of" in withinBody) {
|
|
248
|
-
return {
|
|
249
|
-
type: "withinDistanceOf",
|
|
250
|
-
field,
|
|
251
|
-
value: {
|
|
252
|
-
center: Array.isArray(withinBody.of) ? {
|
|
253
|
-
type: "Point",
|
|
254
|
-
coordinates: withinBody.of
|
|
255
|
-
} : withinBody.of,
|
|
256
|
-
distance: {
|
|
257
|
-
value: withinBody.distance[0],
|
|
258
|
-
unit: DistanceUnitMapping[withinBody.distance[1]]
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
} else {
|
|
263
|
-
const coordinates = "polygon" in withinBody ? withinBody.polygon : withinBody.coordinates;
|
|
264
|
-
return makeGeoFilterPolygon(field, coordinates, "withinPolygon");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
if (firstKey === "$intersects") {
|
|
268
|
-
const intersectsBody = filter[firstKey];
|
|
269
|
-
if (Array.isArray(intersectsBody)) {
|
|
270
|
-
return makeGeoFilterBbox(field, intersectsBody, firstKey);
|
|
271
|
-
} else if ("bbox" in intersectsBody && !("type" in intersectsBody)) {
|
|
272
|
-
return makeGeoFilterBbox(field, intersectsBody.bbox, firstKey);
|
|
273
|
-
} else {
|
|
274
|
-
const coordinates = "polygon" in intersectsBody ? intersectsBody.polygon : intersectsBody.coordinates;
|
|
275
|
-
return makeGeoFilterPolygon(field, coordinates, "intersectsPolygon");
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return {
|
|
279
|
-
type: firstKey.substring(1),
|
|
280
|
-
field,
|
|
281
|
-
value: filter[firstKey]
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
async function fetchSingle(client, objectType, args, objectSet) {
|
|
285
|
-
const result = await fetchPage(client, objectType, {
|
|
286
|
-
...args,
|
|
287
|
-
pageSize: 1
|
|
288
|
-
}, objectSet);
|
|
289
|
-
if (result.data.length !== 1 || result.nextPageToken != null) {
|
|
290
|
-
throw new shared_net.PalantirApiError(`Expected a single result but got ${result.data.length} instead${result.nextPageToken != null ? " with nextPageToken set" : ""}`);
|
|
291
|
-
}
|
|
292
|
-
return result.data[0];
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// src/object/index.ts
|
|
296
|
-
var object_exports = {};
|
|
297
|
-
__export(object_exports, {
|
|
298
|
-
aggregate: () => aggregate,
|
|
299
|
-
fetchPage: () => fetchPage
|
|
300
|
-
});
|
|
301
|
-
async function aggregate(clientCtx, objectType, objectSet = {
|
|
302
|
-
type: "base",
|
|
303
|
-
objectType: objectType["apiName"]
|
|
304
|
-
}, req) {
|
|
305
|
-
const body = {
|
|
306
|
-
aggregation: modernToLegacyAggregationClause(req.select),
|
|
307
|
-
groupBy: [],
|
|
308
|
-
where: void 0
|
|
309
|
-
};
|
|
310
|
-
if (req.groupBy) {
|
|
311
|
-
body.groupBy = modernToLegacyGroupByClause(req.groupBy);
|
|
312
|
-
}
|
|
313
|
-
if (req.where) {
|
|
314
|
-
body.where = modernToLegacyWhereClause(req.where);
|
|
315
|
-
}
|
|
316
|
-
const result = await requests.aggregateObjectSetV2(shared_net.createOpenApiRequest(clientCtx.stack, clientCtx.fetch), clientCtx.ontology.metadata.ontologyApiName, {
|
|
317
|
-
objectSet,
|
|
318
|
-
groupBy: body.groupBy,
|
|
319
|
-
aggregation: body.aggregation
|
|
320
|
-
});
|
|
321
|
-
if (!req.groupBy) {
|
|
322
|
-
!(result.data.length === 1) ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "no group by clause should mean only one data result") : invariant2__default.default(false) : void 0;
|
|
323
|
-
return {
|
|
324
|
-
...aggregationToCountResult(result.data[0]),
|
|
325
|
-
...legacyToModernSingleAggregationResult(result.data[0])
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
const ret = result.data.map((entry) => {
|
|
329
|
-
return {
|
|
330
|
-
$group: entry.group,
|
|
331
|
-
...aggregationToCountResult(entry),
|
|
332
|
-
...legacyToModernSingleAggregationResult(entry)
|
|
333
|
-
};
|
|
334
|
-
});
|
|
335
|
-
return ret;
|
|
336
|
-
}
|
|
337
|
-
function aggregationToCountResult(entry) {
|
|
338
|
-
for (const aggregateResult of entry.metrics) {
|
|
339
|
-
if (aggregateResult.name === "count") {
|
|
340
|
-
return {
|
|
341
|
-
$count: aggregateResult.value
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// src/util/WireObjectSet.ts
|
|
348
|
-
var WIRE_OBJECT_SET_TYPES = /* @__PURE__ */ new Set(["base", "filter", "intersect", "reference", "searchAround", "static", "subtract", "union"]);
|
|
349
|
-
function isWireObjectSet(o) {
|
|
350
|
-
return o != null && typeof o === "object" && WIRE_OBJECT_SET_TYPES.has(o.type);
|
|
351
|
-
}
|
|
352
|
-
async function createTemporaryObjectSet(ctx, request) {
|
|
353
|
-
return conjureLite.conjureFetch(ctx, `/objectSets/temporary`, "POST", request);
|
|
354
|
-
}
|
|
355
|
-
async function batchEnableWatcher(ctx, request) {
|
|
356
|
-
return conjureLite.conjureFetch(ctx, `/object-set-watcher/batchEnableWatcher`, "POST", request);
|
|
357
|
-
}
|
|
358
|
-
async function loadAllOntologies(ctx, request) {
|
|
359
|
-
return conjureLite.conjureFetch(ctx, `/ontology/ontology/ontologies/load/all`, "POST", request);
|
|
360
|
-
}
|
|
361
|
-
async function loadOntologyEntities(ctx, request) {
|
|
362
|
-
return conjureLite.conjureFetch(ctx, `/ontology/ontology/loadEntities`, "POST", request);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// src/objectSet/toConjureObjectSet.ts
|
|
366
|
-
function toConjureObjectSet(objectSet, objectPropertyMapping) {
|
|
367
|
-
switch (objectSet.type) {
|
|
368
|
-
case "base":
|
|
369
|
-
return {
|
|
370
|
-
type: "base",
|
|
371
|
-
base: {
|
|
372
|
-
objectTypeId: objectPropertyMapping.id
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
case "static":
|
|
376
|
-
return {
|
|
377
|
-
type: "static",
|
|
378
|
-
static: {
|
|
379
|
-
objectRids: objectSet.objects,
|
|
380
|
-
provenance: void 0
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
case "reference":
|
|
384
|
-
return {
|
|
385
|
-
type: "referenced",
|
|
386
|
-
referenced: {
|
|
387
|
-
objectSetRid: objectSet.reference
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
case "filter":
|
|
391
|
-
return {
|
|
392
|
-
type: "filtered",
|
|
393
|
-
filtered: {
|
|
394
|
-
objectSet: toConjureObjectSet(objectSet.objectSet, objectPropertyMapping),
|
|
395
|
-
runtimeDerivedProperties: void 0,
|
|
396
|
-
filter: mapWhereClauseToObjectSetFilter(objectSet.where, objectPropertyMapping)
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
case "union":
|
|
400
|
-
return {
|
|
401
|
-
type: "unioned",
|
|
402
|
-
unioned: {
|
|
403
|
-
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
case "intersect":
|
|
407
|
-
return {
|
|
408
|
-
type: "intersected",
|
|
409
|
-
intersected: {
|
|
410
|
-
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
case "subtract":
|
|
414
|
-
return {
|
|
415
|
-
type: "subtracted",
|
|
416
|
-
subtracted: {
|
|
417
|
-
objectSets: objectSet.objectSets.map((os) => toConjureObjectSet(os, objectPropertyMapping))
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
case "searchAround":
|
|
421
|
-
throw new Error("not implemented");
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
async function getObjectSetBaseType(objectSet) {
|
|
425
|
-
switch (objectSet.type) {
|
|
426
|
-
case "base":
|
|
427
|
-
return objectSet.objectType;
|
|
428
|
-
case "static":
|
|
429
|
-
throw new Error("not implemented");
|
|
430
|
-
case "reference":
|
|
431
|
-
throw new Error("not implemented");
|
|
432
|
-
case "filter":
|
|
433
|
-
return getObjectSetBaseType(objectSet.objectSet);
|
|
434
|
-
case "union":
|
|
435
|
-
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
436
|
-
case "intersect":
|
|
437
|
-
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
438
|
-
case "subtract":
|
|
439
|
-
return getObjectSetBaseType(objectSet.objectSets[0]);
|
|
440
|
-
case "searchAround":
|
|
441
|
-
throw new Error("not implemented");
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
function mapWhereClauseToObjectSetFilter(objectSetFilter, propertyMapping) {
|
|
445
|
-
switch (objectSetFilter.type) {
|
|
446
|
-
case "lt":
|
|
447
|
-
return {
|
|
448
|
-
type: "range",
|
|
449
|
-
range: {
|
|
450
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
451
|
-
lt: objectSetFilter.value,
|
|
452
|
-
lte: void 0,
|
|
453
|
-
gt: void 0,
|
|
454
|
-
gte: void 0
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
case "gt":
|
|
458
|
-
return {
|
|
459
|
-
type: "range",
|
|
460
|
-
range: {
|
|
461
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
462
|
-
gt: objectSetFilter.value,
|
|
463
|
-
lte: void 0,
|
|
464
|
-
lt: void 0,
|
|
465
|
-
gte: void 0
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
case "lte":
|
|
469
|
-
return {
|
|
470
|
-
type: "range",
|
|
471
|
-
range: {
|
|
472
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
473
|
-
lte: objectSetFilter.value,
|
|
474
|
-
lt: void 0,
|
|
475
|
-
gt: void 0,
|
|
476
|
-
gte: void 0
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
case "gte":
|
|
480
|
-
return {
|
|
481
|
-
type: "range",
|
|
482
|
-
range: {
|
|
483
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
484
|
-
gte: objectSetFilter.value,
|
|
485
|
-
lt: void 0,
|
|
486
|
-
lte: void 0,
|
|
487
|
-
gt: void 0
|
|
488
|
-
}
|
|
489
|
-
};
|
|
490
|
-
case "eq":
|
|
491
|
-
return {
|
|
492
|
-
type: "exactMatch",
|
|
493
|
-
exactMatch: {
|
|
494
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field],
|
|
495
|
-
terms: []
|
|
496
|
-
}
|
|
497
|
-
};
|
|
498
|
-
case "and":
|
|
499
|
-
return {
|
|
500
|
-
type: "and",
|
|
501
|
-
and: {
|
|
502
|
-
filters: objectSetFilter.value.map((filter) => mapWhereClauseToObjectSetFilter(filter, propertyMapping))
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
case "or":
|
|
506
|
-
return {
|
|
507
|
-
type: "or",
|
|
508
|
-
or: {
|
|
509
|
-
filters: objectSetFilter.value.map((filter) => mapWhereClauseToObjectSetFilter(filter, propertyMapping))
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
case "isNull":
|
|
513
|
-
return {
|
|
514
|
-
type: "not",
|
|
515
|
-
not: {
|
|
516
|
-
filter: {
|
|
517
|
-
type: "hasProperty",
|
|
518
|
-
hasProperty: {
|
|
519
|
-
propertyId: propertyMapping.propertyApiNameToIdMapping[objectSetFilter.field]
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
};
|
|
524
|
-
case "not":
|
|
525
|
-
return {
|
|
526
|
-
type: "not",
|
|
527
|
-
not: {
|
|
528
|
-
filter: mapWhereClauseToObjectSetFilter(objectSetFilter.value, propertyMapping)
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
case "contains":
|
|
532
|
-
case "startsWith":
|
|
533
|
-
case "containsAllTermsInOrder":
|
|
534
|
-
case "containsAnyTerm":
|
|
535
|
-
case "containsAllTerms":
|
|
536
|
-
case "withinDistanceOf":
|
|
537
|
-
case "withinBoundingBox":
|
|
538
|
-
case "intersectsBoundingBox":
|
|
539
|
-
case "doesNotIntersectBoundingBox":
|
|
540
|
-
case "withinPolygon":
|
|
541
|
-
case "intersectsPolygon":
|
|
542
|
-
case "doesNotIntersectPolygon":
|
|
543
|
-
case "containsAllTermsInOrderPrefixLastTerm":
|
|
544
|
-
throw new Error("not implemented");
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
// src/objectSet/ObjectSetListenerWebsocket.ts
|
|
549
|
-
var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
|
|
550
|
-
var MINIMUM_RECONNECT_DELAY_MS = 5 * 1e3;
|
|
551
|
-
var ObjectSetListenerWebsocket = class _ObjectSetListenerWebsocket {
|
|
552
|
-
static #instances = /* @__PURE__ */ new WeakMap();
|
|
553
|
-
// FIXME
|
|
554
|
-
static getInstance(client) {
|
|
555
|
-
let instance = _ObjectSetListenerWebsocket.#instances.get(client);
|
|
556
|
-
if (instance == null) {
|
|
557
|
-
instance = new _ObjectSetListenerWebsocket(client);
|
|
558
|
-
_ObjectSetListenerWebsocket.#instances.set(client, instance);
|
|
559
|
-
}
|
|
560
|
-
return instance;
|
|
561
|
-
}
|
|
562
|
-
#ws;
|
|
563
|
-
#lastWsConnect = 0;
|
|
564
|
-
#client;
|
|
565
|
-
/** map of listenerId to listener */
|
|
566
|
-
#listeners = /* @__PURE__ */ new Map();
|
|
567
|
-
/** map of subscriptionId to listenerId */
|
|
568
|
-
#subscriptionToRequestId = /* @__PURE__ */ new Map();
|
|
569
|
-
#conjureContext;
|
|
570
|
-
#metadataContext;
|
|
571
|
-
#ossContext;
|
|
572
|
-
constructor(client) {
|
|
573
|
-
this.#client = client;
|
|
574
|
-
const stackUrl = new URL(client.stack);
|
|
575
|
-
this.#conjureContext = {
|
|
576
|
-
baseUrl: stackUrl.origin,
|
|
577
|
-
servicePath: "/object-set-watcher/api",
|
|
578
|
-
fetchFn: client.fetch,
|
|
579
|
-
tokenProvider: async () => await client.tokenProvider()
|
|
580
|
-
};
|
|
581
|
-
this.#ossContext = {
|
|
582
|
-
baseUrl: stackUrl.origin,
|
|
583
|
-
servicePath: "/object-set-service/api",
|
|
584
|
-
fetchFn: client.fetch,
|
|
585
|
-
tokenProvider: async () => await client.tokenProvider()
|
|
586
|
-
};
|
|
587
|
-
this.#metadataContext = {
|
|
588
|
-
baseUrl: stackUrl.origin,
|
|
589
|
-
servicePath: "/ontology-metadata/api",
|
|
590
|
-
fetchFn: client.fetch,
|
|
591
|
-
tokenProvider: async () => await client.tokenProvider()
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
subscribe(objectSet, listener) {
|
|
595
|
-
const requestId = crypto.randomUUID();
|
|
596
|
-
const expiry = setTimeout(() => {
|
|
597
|
-
this.#expire(requestId);
|
|
598
|
-
}, ONE_DAY_MS);
|
|
599
|
-
this.#listeners.set(requestId, {
|
|
600
|
-
listener,
|
|
601
|
-
objectSet,
|
|
602
|
-
expiry
|
|
603
|
-
});
|
|
604
|
-
this.#subscribe(requestId, objectSet);
|
|
605
|
-
return () => {
|
|
606
|
-
this.#unsubscribe(requestId);
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
async #subscribe(requestId, objectSet) {
|
|
610
|
-
try {
|
|
611
|
-
const [temporaryObjectSet] = await Promise.all([
|
|
612
|
-
// create a time-bounded object set representation for watching
|
|
613
|
-
this.#createTemporaryObjectSet(objectSet),
|
|
614
|
-
this.#ensureWebsocket(),
|
|
615
|
-
// look up the object type's rid and ensure that we have enabled object set watcher for that rid
|
|
616
|
-
// TODO ???
|
|
617
|
-
getObjectSetBaseType(objectSet).then((baseType) => requests.getObjectTypeV2(shared_net.createOpenApiRequest(this.#client.stack, this.#client.fetch), this.#client.ontology.metadata.ontologyApiName, baseType)).then((objectType) => this.#enableObjectSetsWatcher([objectType.rid]))
|
|
618
|
-
]);
|
|
619
|
-
if (!this.#listeners.has(requestId)) {
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
const subscribe = {
|
|
623
|
-
id: requestId,
|
|
624
|
-
requests: [{
|
|
625
|
-
objectSet: temporaryObjectSet.objectSetRid,
|
|
626
|
-
objectSetContext: {
|
|
627
|
-
objectSetFilterContext: {
|
|
628
|
-
parameterOverrides: {}
|
|
629
|
-
}
|
|
630
|
-
},
|
|
631
|
-
watchAllLinks: false
|
|
632
|
-
}]
|
|
633
|
-
};
|
|
634
|
-
this.#ws?.send(JSON.stringify(subscribe));
|
|
635
|
-
} catch (error) {
|
|
636
|
-
this.#getCallbackByRequestId(requestId, "onError")?.(error);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
#expire(requestId) {
|
|
640
|
-
const state = this.#listeners.get(requestId);
|
|
641
|
-
if (state) {
|
|
642
|
-
const {
|
|
643
|
-
subscriptionId,
|
|
644
|
-
objectSet
|
|
645
|
-
} = state;
|
|
646
|
-
if (subscriptionId) {
|
|
647
|
-
state.subscriptionId = void 0;
|
|
648
|
-
this.#subscriptionToRequestId.delete(subscriptionId);
|
|
649
|
-
}
|
|
650
|
-
this.#subscribe(requestId, objectSet);
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
#unsubscribe(requestId) {
|
|
654
|
-
const data = this.#listeners.get(requestId);
|
|
655
|
-
if (data == null) {
|
|
656
|
-
return;
|
|
657
|
-
}
|
|
658
|
-
this.#listeners.delete(requestId);
|
|
659
|
-
clearTimeout(data.expiry);
|
|
660
|
-
const {
|
|
661
|
-
subscriptionId
|
|
662
|
-
} = data;
|
|
663
|
-
if (subscriptionId != null) {
|
|
664
|
-
this.#subscriptionToRequestId.delete(subscriptionId);
|
|
665
|
-
}
|
|
666
|
-
if (this.#listeners.size === 0) {
|
|
667
|
-
this.#destroyWebsocket();
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
async #ensureWebsocket() {
|
|
671
|
-
if (this.#ws == null) {
|
|
672
|
-
const {
|
|
673
|
-
stack,
|
|
674
|
-
tokenProvider
|
|
675
|
-
} = this.#client;
|
|
676
|
-
const base = new URL(stack);
|
|
677
|
-
const url = `wss://${base.host}/object-set-watcher/ws/subscriptions`;
|
|
678
|
-
const token = await tokenProvider();
|
|
679
|
-
if (this.#ws == null) {
|
|
680
|
-
const nextConnectTime = (this.#lastWsConnect ?? 0) + MINIMUM_RECONNECT_DELAY_MS;
|
|
681
|
-
if (nextConnectTime > Date.now()) {
|
|
682
|
-
await new Promise((resolve) => {
|
|
683
|
-
setTimeout(resolve, nextConnectTime - Date.now());
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
this.#lastWsConnect = Date.now();
|
|
687
|
-
if (this.#ws == null) {
|
|
688
|
-
this.#ws = new WebSocket__default.default(url, [`Bearer-${token}`]);
|
|
689
|
-
this.#ws.addEventListener("close", this.#onClose);
|
|
690
|
-
this.#ws.addEventListener("message", this.#onMessage);
|
|
691
|
-
this.#ws.addEventListener("open", this.#onOpen);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
if (this.#ws.readyState === WebSocket__default.default.CONNECTING) {
|
|
695
|
-
return new Promise((resolve, reject) => {
|
|
696
|
-
this.#ws.addEventListener("open", () => {
|
|
697
|
-
resolve();
|
|
698
|
-
});
|
|
699
|
-
this.#ws.addEventListener("error", (event) => {
|
|
700
|
-
reject(new Error(event.toString()));
|
|
701
|
-
});
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
#onOpen = () => {
|
|
707
|
-
for (const [requestId, state] of this.#listeners) {
|
|
708
|
-
this.#subscribe(requestId, state.objectSet);
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
#onMessage = async (message) => {
|
|
712
|
-
const data = JSON.parse(message.data.toString());
|
|
713
|
-
switch (data.type) {
|
|
714
|
-
case "objectSetChanged": {
|
|
715
|
-
if (data.objectSetChanged.confidenceValue) {
|
|
716
|
-
this.#getCallback(data.objectSetChanged.id, "onOutOfDate")?.();
|
|
717
|
-
break;
|
|
718
|
-
}
|
|
719
|
-
const {
|
|
720
|
-
id: subscriptionId,
|
|
721
|
-
objects
|
|
722
|
-
} = data.objectSetChanged;
|
|
723
|
-
const callback = this.#getCallback(subscriptionId, "onChange");
|
|
724
|
-
if (callback) {
|
|
725
|
-
callback(await convertFoundryToOsdkObjects(this.#client, this.#metadataContext, objects));
|
|
726
|
-
}
|
|
727
|
-
break;
|
|
728
|
-
}
|
|
729
|
-
case "refreshObjectSet": {
|
|
730
|
-
const {
|
|
731
|
-
id: subscriptionId
|
|
732
|
-
} = data.refreshObjectSet;
|
|
733
|
-
this.#getCallback(subscriptionId, "onOutOfDate")?.();
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
case "subscribeResponses": {
|
|
737
|
-
const {
|
|
738
|
-
id: requestId,
|
|
739
|
-
responses
|
|
740
|
-
} = data.subscribeResponses;
|
|
741
|
-
const listenerData = this.#listeners.get(requestId);
|
|
742
|
-
if (listenerData == null) {
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
if (responses.length !== 1) {
|
|
746
|
-
throw new Error("Got more than one response but we only expect a single one");
|
|
747
|
-
}
|
|
748
|
-
const response = responses[0];
|
|
749
|
-
switch (response.type) {
|
|
750
|
-
case "error":
|
|
751
|
-
this.#getCallbackByRequestId(requestId, "onError")?.(response.error);
|
|
752
|
-
this.#unsubscribe(requestId);
|
|
753
|
-
return;
|
|
754
|
-
case "qos":
|
|
755
|
-
this.#destroyWebsocket();
|
|
756
|
-
this.#ensureWebsocket();
|
|
757
|
-
return;
|
|
758
|
-
case "success":
|
|
759
|
-
const {
|
|
760
|
-
id: subscriptionId
|
|
761
|
-
} = response.success;
|
|
762
|
-
listenerData.subscriptionId = subscriptionId;
|
|
763
|
-
this.#subscriptionToRequestId.set(subscriptionId, requestId);
|
|
764
|
-
this.#getCallbackByRequestId(requestId, "onOutOfDate")?.();
|
|
765
|
-
break;
|
|
766
|
-
default:
|
|
767
|
-
this.#getCallbackByRequestId(requestId, "onError")?.(response);
|
|
768
|
-
}
|
|
769
|
-
break;
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
};
|
|
773
|
-
#onClose = () => {
|
|
774
|
-
this.#destroyWebsocket();
|
|
775
|
-
};
|
|
776
|
-
async #enableObjectSetsWatcher(objectTypeRids) {
|
|
777
|
-
return batchEnableWatcher(this.#conjureContext, {
|
|
778
|
-
requests: objectTypeRids
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
async #createTemporaryObjectSet(objectSet) {
|
|
782
|
-
const objectSetBaseType = await getObjectSetBaseType(objectSet);
|
|
783
|
-
const mapping = await getOntologyPropertyMappingForApiName(this.#client, this.#metadataContext, objectSetBaseType);
|
|
784
|
-
const temporaryObjectSet = await createTemporaryObjectSet(this.#ossContext, {
|
|
785
|
-
objectSet: toConjureObjectSet(objectSet, mapping),
|
|
786
|
-
timeToLive: "ONE_DAY",
|
|
787
|
-
objectSetFilterContext: {
|
|
788
|
-
parameterOverrides: {}
|
|
789
|
-
}
|
|
790
|
-
});
|
|
791
|
-
return {
|
|
792
|
-
objectSetRid: temporaryObjectSet.objectSetRid
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
#destroyWebsocket = () => {
|
|
796
|
-
if (this.#ws) {
|
|
797
|
-
this.#ws.removeEventListener("open", this.#onOpen);
|
|
798
|
-
this.#ws.removeEventListener("message", this.#onMessage);
|
|
799
|
-
this.#ws.removeEventListener("close", this.#onClose);
|
|
800
|
-
if (this.#ws.readyState !== WebSocket__default.default.CLOSING && this.#ws.readyState !== WebSocket__default.default.CLOSED) {
|
|
801
|
-
this.#ws.close();
|
|
802
|
-
}
|
|
803
|
-
this.#ws = void 0;
|
|
804
|
-
}
|
|
805
|
-
this.#subscriptionToRequestId.clear();
|
|
806
|
-
for (const state of this.#listeners.values()) {
|
|
807
|
-
state.subscriptionId = void 0;
|
|
808
|
-
}
|
|
809
|
-
if (this.#listeners.size > 0) {
|
|
810
|
-
this.#ensureWebsocket();
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
|
-
#getCallbackByRequestId(requestId, type) {
|
|
814
|
-
const maybeListener = this.#listeners.get(requestId);
|
|
815
|
-
return maybeListener?.listener?.[type];
|
|
816
|
-
}
|
|
817
|
-
#getCallback(subscriptionId, type) {
|
|
818
|
-
const requestId = this.#subscriptionToRequestId.get(subscriptionId);
|
|
819
|
-
if (requestId) {
|
|
820
|
-
return this.#getCallbackByRequestId(requestId, type);
|
|
821
|
-
}
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
};
|
|
825
|
-
async function convertFoundryToOsdkObjects(client, ctx, objects) {
|
|
826
|
-
const osdkObjects = await Promise.all(objects.map(async (object) => {
|
|
827
|
-
const propertyMapping = await getOntologyPropertyMappingForRid(ctx, client.ontology.metadata.ontologyRid, object.type);
|
|
828
|
-
const convertedObject = Object.fromEntries([...Object.entries(object.properties).map(([key, value]) => {
|
|
829
|
-
return [propertyMapping?.propertyIdToApiNameMapping[key], value];
|
|
830
|
-
}), [propertyMapping?.propertyIdToApiNameMapping[Object.entries(object.key)[0][0]], Object.entries(object.key)[0][1]], ["__apiName", propertyMapping?.apiName], ["$apiName", propertyMapping?.apiName]]);
|
|
831
|
-
return convertedObject;
|
|
832
|
-
}));
|
|
833
|
-
return await convertWireToOsdkObjects(client, osdkObjects, void 0);
|
|
834
|
-
}
|
|
835
|
-
var objectTypeMapping = /* @__PURE__ */ new WeakMap();
|
|
836
|
-
var objectApiNameToRid = /* @__PURE__ */ new Map();
|
|
837
|
-
async function getOntologyPropertyMappingForApiName(client, ctx, objectApiName) {
|
|
838
|
-
if (objectApiNameToRid.has(objectApiName)) {
|
|
839
|
-
return objectTypeMapping.get(ctx)?.get(objectApiNameToRid.get(objectApiName));
|
|
840
|
-
}
|
|
841
|
-
const wireObjectType = await requests.getObjectTypeV2(shared_net.createOpenApiRequest(client.stack, client.fetch), client.ontology.metadata.ontologyApiName, objectApiName);
|
|
842
|
-
return getOntologyPropertyMappingForRid(ctx, client.ontology.metadata.ontologyRid, wireObjectType.rid);
|
|
843
|
-
}
|
|
844
|
-
var cachedAllOntologies;
|
|
845
|
-
async function getOntologyVersionForRid(ctx, ontologyRid) {
|
|
846
|
-
cachedAllOntologies ??= await loadAllOntologies(ctx, {});
|
|
847
|
-
!cachedAllOntologies.ontologies[ontologyRid] ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "ontology should be loaded") : invariant2__default.default(false) : void 0;
|
|
848
|
-
return cachedAllOntologies.ontologies[ontologyRid].currentOntologyVersion;
|
|
849
|
-
}
|
|
850
|
-
async function getOntologyPropertyMappingForRid(ctx, ontologyRid, objectRid) {
|
|
851
|
-
if (!objectTypeMapping.has(ctx)) {
|
|
852
|
-
objectTypeMapping.set(ctx, /* @__PURE__ */ new Map());
|
|
853
|
-
}
|
|
854
|
-
if (!objectTypeMapping.get(ctx).has(objectRid)) {
|
|
855
|
-
const ontologyVersion = await getOntologyVersionForRid(ctx, ontologyRid);
|
|
856
|
-
const body = {
|
|
857
|
-
objectTypeVersions: {
|
|
858
|
-
// TODO: Undefined drops this in the body
|
|
859
|
-
[objectRid]: ontologyVersion
|
|
860
|
-
},
|
|
861
|
-
linkTypeVersions: {},
|
|
862
|
-
loadRedacted: false,
|
|
863
|
-
includeObjectTypesWithoutSearchableDatasources: true
|
|
864
|
-
};
|
|
865
|
-
const entities = await loadOntologyEntities(ctx, body);
|
|
866
|
-
!entities.objectTypes[objectRid] ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "object type should be loaded") : invariant2__default.default(false) : void 0;
|
|
867
|
-
const propertyIdToApiNameMapping = Object.fromEntries(Object.values(entities.objectTypes[objectRid].propertyTypes).map((property) => {
|
|
868
|
-
return [property.id, property.apiName];
|
|
869
|
-
}));
|
|
870
|
-
const propertyApiNameToIdMapping = Object.fromEntries(Object.values(entities.objectTypes[objectRid].propertyTypes).map((property) => {
|
|
871
|
-
return [property.id, property.apiName];
|
|
872
|
-
}));
|
|
873
|
-
objectTypeMapping.get(ctx)?.set(objectRid, {
|
|
874
|
-
apiName: entities.objectTypes[objectRid].apiName,
|
|
875
|
-
id: entities.objectTypes[objectRid].id,
|
|
876
|
-
propertyIdToApiNameMapping,
|
|
877
|
-
propertyApiNameToIdMapping
|
|
878
|
-
});
|
|
879
|
-
objectApiNameToRid.set(entities.objectTypes[objectRid].apiName, objectRid);
|
|
880
|
-
}
|
|
881
|
-
return objectTypeMapping.get(ctx)?.get(objectRid);
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
// src/objectSet/createObjectSet.ts
|
|
885
|
-
function isObjectTypeDefinition(def) {
|
|
886
|
-
return def.type === "object";
|
|
887
|
-
}
|
|
888
|
-
function isObjectSet(o) {
|
|
889
|
-
return o != null && typeof o === "object" && isWireObjectSet(objectSetDefinitions.get(o));
|
|
890
|
-
}
|
|
891
|
-
function getWireObjectSet(objectSet) {
|
|
892
|
-
return objectSetDefinitions.get(objectSet);
|
|
893
|
-
}
|
|
894
|
-
var objectSetDefinitions = /* @__PURE__ */ new WeakMap();
|
|
895
|
-
function createObjectSet2(objectType, clientCtx, objectSet = {
|
|
896
|
-
type: "base",
|
|
897
|
-
objectType: objectType["apiName"]
|
|
898
|
-
}) {
|
|
899
|
-
const base = {
|
|
900
|
-
aggregate: aggregate.bind(globalThis, clientCtx, objectType, objectSet),
|
|
901
|
-
aggregateOrThrow: aggregate.bind(globalThis, clientCtx, objectType, objectSet),
|
|
902
|
-
fetchPage: fetchPageInternal.bind(globalThis, clientCtx, objectType, objectSet),
|
|
903
|
-
fetchPageOrThrow: fetchPageInternal.bind(globalThis, clientCtx, objectType, objectSet),
|
|
904
|
-
where: (clause) => {
|
|
905
|
-
return createObjectSet2(objectType, clientCtx, {
|
|
906
|
-
type: "filter",
|
|
907
|
-
objectSet,
|
|
908
|
-
where: modernToLegacyWhereClause(clause)
|
|
909
|
-
});
|
|
910
|
-
},
|
|
911
|
-
pivotTo: function(type) {
|
|
912
|
-
return createSearchAround(type)();
|
|
913
|
-
},
|
|
914
|
-
union: (...objectSets) => {
|
|
915
|
-
return createObjectSet2(objectType, clientCtx, {
|
|
916
|
-
type: "union",
|
|
917
|
-
objectSets: [objectSet, ...objectSets.map((os) => objectSetDefinitions.get(os))]
|
|
918
|
-
});
|
|
919
|
-
},
|
|
920
|
-
intersect: (...objectSets) => {
|
|
921
|
-
return createObjectSet2(objectType, clientCtx, {
|
|
922
|
-
type: "intersect",
|
|
923
|
-
objectSets: [objectSet, ...objectSets.map((os) => objectSetDefinitions.get(os))]
|
|
924
|
-
});
|
|
925
|
-
},
|
|
926
|
-
subtract: (...objectSets) => {
|
|
927
|
-
return createObjectSet2(objectType, clientCtx, {
|
|
928
|
-
type: "subtract",
|
|
929
|
-
objectSets: [objectSet, ...objectSets.map((os) => objectSetDefinitions.get(os))]
|
|
930
|
-
});
|
|
931
|
-
},
|
|
932
|
-
subscribe(listener) {
|
|
933
|
-
const instance = ObjectSetListenerWebsocket.getInstance(clientCtx);
|
|
934
|
-
return instance.subscribe(objectSet, listener);
|
|
935
|
-
},
|
|
936
|
-
asyncIter: async function* () {
|
|
937
|
-
let nextPageToken = void 0;
|
|
938
|
-
do {
|
|
939
|
-
const result = await base.fetchPage({
|
|
940
|
-
nextPageToken
|
|
941
|
-
});
|
|
942
|
-
for (const obj of await convertWireToOsdkObjects(clientCtx, result.data, void 0)) {
|
|
943
|
-
yield obj;
|
|
944
|
-
}
|
|
945
|
-
} while (nextPageToken != null);
|
|
946
|
-
},
|
|
947
|
-
get: isObjectTypeDefinition(objectType) ? async (primaryKey, options) => {
|
|
948
|
-
const withPk = {
|
|
949
|
-
type: "filter",
|
|
950
|
-
objectSet,
|
|
951
|
-
where: {
|
|
952
|
-
type: "eq",
|
|
953
|
-
field: objectType.primaryKeyApiName,
|
|
954
|
-
value: primaryKey
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
return await fetchSingle(clientCtx, objectType, options, withPk);
|
|
958
|
-
} : void 0
|
|
959
|
-
};
|
|
960
|
-
function createSearchAround(link) {
|
|
961
|
-
return () => {
|
|
962
|
-
return createObjectSet2(objectType, clientCtx, {
|
|
963
|
-
type: "searchAround",
|
|
964
|
-
objectSet,
|
|
965
|
-
link
|
|
966
|
-
});
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
objectSetDefinitions.set(base, objectSet);
|
|
970
|
-
return base;
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
// src/object/Attachment.ts
|
|
974
|
-
var Attachment = class {
|
|
975
|
-
constructor(rid) {
|
|
976
|
-
this.rid = rid;
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
function isAttachment(o) {
|
|
980
|
-
return o instanceof Attachment;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
// src/object/Cache.ts
|
|
984
|
-
function createCache(fn) {
|
|
985
|
-
const cache = /* @__PURE__ */ new WeakMap();
|
|
986
|
-
function get(client, key) {
|
|
987
|
-
if (cache.get(client) == null) {
|
|
988
|
-
cache.set(client, /* @__PURE__ */ new Map());
|
|
989
|
-
}
|
|
990
|
-
let r = cache.get(client).get(key);
|
|
991
|
-
if (r === void 0 && fn !== void 0) {
|
|
992
|
-
return set(client, key, fn(client, key));
|
|
993
|
-
} else {
|
|
994
|
-
return r;
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
function set(client, key, value) {
|
|
998
|
-
if (cache.get(client) == null) {
|
|
999
|
-
cache.set(client, /* @__PURE__ */ new Map());
|
|
1000
|
-
}
|
|
1001
|
-
cache.get(client).set(key, value);
|
|
1002
|
-
return value;
|
|
1003
|
-
}
|
|
1004
|
-
function remove(client, key) {
|
|
1005
|
-
if (cache.get(client) == null)
|
|
1006
|
-
return false;
|
|
1007
|
-
return cache.get(client).delete(key);
|
|
1008
|
-
}
|
|
1009
|
-
return {
|
|
1010
|
-
get,
|
|
1011
|
-
set,
|
|
1012
|
-
remove
|
|
1013
|
-
};
|
|
1014
|
-
}
|
|
1015
|
-
function createAsyncCache(fn, createCacheLocal = createCache) {
|
|
1016
|
-
const cache = createCacheLocal();
|
|
1017
|
-
const inProgress = createCacheLocal();
|
|
1018
|
-
const ret = {
|
|
1019
|
-
getOrUndefined: function getOrUndefined(client, key) {
|
|
1020
|
-
return cache.get(client, key);
|
|
1021
|
-
},
|
|
1022
|
-
get: async function get(client, key) {
|
|
1023
|
-
return cache.get(client, key) ?? inProgress.get(client, key) ?? ret.set(client, key, fn(client, key));
|
|
1024
|
-
},
|
|
1025
|
-
set: async function set(client, k, v) {
|
|
1026
|
-
try {
|
|
1027
|
-
const r = await inProgress.set(client, k, v);
|
|
1028
|
-
cache.set(client, k, r);
|
|
1029
|
-
inProgress.remove(client, k);
|
|
1030
|
-
return r;
|
|
1031
|
-
} catch (e) {
|
|
1032
|
-
inProgress.remove(client, k);
|
|
1033
|
-
throw e;
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
};
|
|
1037
|
-
return ret;
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
// src/object/convertWireToOsdkObjects.ts
|
|
1041
|
-
var OriginClient = Symbol();
|
|
1042
|
-
var UnderlyingObject = Symbol();
|
|
1043
|
-
var InterfaceDefinitions = Symbol();
|
|
1044
|
-
var LinkFetcherProxyHandler = class {
|
|
1045
|
-
constructor(objDef, primaryKey, client) {
|
|
1046
|
-
this.objDef = objDef;
|
|
1047
|
-
this.primaryKey = primaryKey;
|
|
1048
|
-
this.client = client;
|
|
1049
|
-
}
|
|
1050
|
-
get(_target, p) {
|
|
1051
|
-
const linkDef = this.objDef.links[p];
|
|
1052
|
-
if (linkDef == null) {
|
|
1053
|
-
return;
|
|
1054
|
-
}
|
|
1055
|
-
const objectSet = createObjectSet2(this.objDef, this.client).where({
|
|
1056
|
-
[this.objDef.primaryKeyApiName]: this.primaryKey
|
|
1057
|
-
}).pivotTo(p);
|
|
1058
|
-
if (!linkDef.multiplicity) {
|
|
1059
|
-
return {
|
|
1060
|
-
get: (options) => fetchSingle(this.client, this.objDef, options ?? {}, getWireObjectSet(objectSet))
|
|
1061
|
-
};
|
|
1062
|
-
} else {
|
|
1063
|
-
return objectSet;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
ownKeys() {
|
|
1067
|
-
return Object.keys(this.objDef.links);
|
|
1068
|
-
}
|
|
1069
|
-
getOwnPropertyDescriptor(target, p) {
|
|
1070
|
-
return {
|
|
1071
|
-
enumerable: true,
|
|
1072
|
-
configurable: true,
|
|
1073
|
-
get: () => {
|
|
1074
|
-
return this.get(target, p);
|
|
1075
|
-
}
|
|
1076
|
-
};
|
|
1077
|
-
}
|
|
1078
|
-
};
|
|
1079
|
-
function createPrototype(objDef, client) {
|
|
1080
|
-
if (process.env.NODE_ENV !== "production") {
|
|
1081
|
-
!(objDef.type === "object") ? process.env.NODE_ENV !== "production" ? invariant2__default.default(false, "Expected object definition") : invariant2__default.default(false) : void 0;
|
|
1082
|
-
}
|
|
1083
|
-
const sharedPropertyDefs = {
|
|
1084
|
-
$as: {
|
|
1085
|
-
value: $as
|
|
1086
|
-
}
|
|
1087
|
-
};
|
|
1088
|
-
const interfaceProto = Object.defineProperties({}, sharedPropertyDefs);
|
|
1089
|
-
const objectProto = Object.defineProperties({}, {
|
|
1090
|
-
$link: {
|
|
1091
|
-
get: function() {
|
|
1092
|
-
return new Proxy({}, new LinkFetcherProxyHandler(objDef, this["$primaryKey"], client));
|
|
1093
|
-
}
|
|
1094
|
-
},
|
|
1095
|
-
...sharedPropertyDefs
|
|
1096
|
-
});
|
|
1097
|
-
function $as(newDef) {
|
|
1098
|
-
if (typeof newDef === "string") {
|
|
1099
|
-
if (newDef === objDef.apiName) {
|
|
1100
|
-
return this[UnderlyingObject];
|
|
1101
|
-
}
|
|
1102
|
-
const def = objDef[InterfaceDefinitions][newDef];
|
|
1103
|
-
if (!def) {
|
|
1104
|
-
throw new Error(`Object does not implement interface '${newDef}'.`);
|
|
1105
|
-
}
|
|
1106
|
-
newDef = def;
|
|
1107
|
-
} else if (newDef.apiName === objDef.apiName) {
|
|
1108
|
-
return this[UnderlyingObject];
|
|
1109
|
-
}
|
|
1110
|
-
if (newDef.type !== "interface" && newDef.apiName !== this.$apiName) {
|
|
1111
|
-
throw new Error(`'${newDef.apiName}' is not an interface of '${this.$objectType}'.`);
|
|
1112
|
-
}
|
|
1113
|
-
const underlying = this[UnderlyingObject];
|
|
1114
|
-
const common = {
|
|
1115
|
-
enumerable: true,
|
|
1116
|
-
configurable: true
|
|
1117
|
-
};
|
|
1118
|
-
return Object.create(interfaceProto, {
|
|
1119
|
-
$apiName: {
|
|
1120
|
-
value: newDef.apiName,
|
|
1121
|
-
...common
|
|
1122
|
-
},
|
|
1123
|
-
$objectType: {
|
|
1124
|
-
value: objDef.apiName,
|
|
1125
|
-
...common
|
|
1126
|
-
},
|
|
1127
|
-
$primaryKey: {
|
|
1128
|
-
value: this["$primaryKey"],
|
|
1129
|
-
...common
|
|
1130
|
-
},
|
|
1131
|
-
...Object.fromEntries(Object.keys(newDef.properties).map((p) => {
|
|
1132
|
-
const value = underlying[objDef.spts[p]];
|
|
1133
|
-
return [p, {
|
|
1134
|
-
value,
|
|
1135
|
-
enumerable: value !== void 0
|
|
1136
|
-
}];
|
|
1137
|
-
})),
|
|
1138
|
-
[UnderlyingObject]: {
|
|
1139
|
-
value: underlying
|
|
1140
|
-
}
|
|
1141
|
-
});
|
|
1142
|
-
}
|
|
1143
|
-
return objectProto;
|
|
1144
|
-
}
|
|
1145
|
-
function createConverter(objDef) {
|
|
1146
|
-
const steps = [];
|
|
1147
|
-
for (const [key, value] of Object.entries(objDef.properties)) {
|
|
1148
|
-
if (value.type === "attachment") {
|
|
1149
|
-
steps.push((o) => {
|
|
1150
|
-
if (o[key] != null) {
|
|
1151
|
-
if (Array.isArray(o[key])) {
|
|
1152
|
-
o[key] = o[key].map((a) => new Attachment(a.rid));
|
|
1153
|
-
} else {
|
|
1154
|
-
o[key] = new Attachment(o[key].rid);
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
return steps.length > 0 ? (o) => {
|
|
1161
|
-
for (const step of steps) {
|
|
1162
|
-
step(o);
|
|
1163
|
-
}
|
|
1164
|
-
} : void 0;
|
|
1165
|
-
}
|
|
1166
|
-
var protoConverterCache = createCache((client, objectDef) => {
|
|
1167
|
-
const proto = createPrototype(objectDef, client);
|
|
1168
|
-
const converter = createConverter(objectDef);
|
|
1169
|
-
return [proto, converter];
|
|
1170
|
-
});
|
|
1171
|
-
async function convertWireToOsdkObjects(client, objects, interfaceApiName, forceRemoveRid = false) {
|
|
1172
|
-
if (forceRemoveRid) {
|
|
1173
|
-
for (const obj of objects) {
|
|
1174
|
-
delete obj.__rid;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
fixObjectPropertiesInline(objects);
|
|
1178
|
-
const localObjectCache = createLocalObjectCacheAndInitiatePreseed(objects, client);
|
|
1179
|
-
for (const obj of objects) {
|
|
1180
|
-
const objectDef = await localObjectCache.get(client, obj.$apiName);
|
|
1181
|
-
if (objectDef == null) {
|
|
1182
|
-
throw new Error(`Failed to find ontology definition for '${obj.$apiName}'`);
|
|
1183
|
-
}
|
|
1184
|
-
if (interfaceApiName !== void 0) {
|
|
1185
|
-
for (const [sptProp, regularProp] of Object.entries(objectDef.spts)) {
|
|
1186
|
-
if (sptProp in obj) {
|
|
1187
|
-
const value = obj[sptProp];
|
|
1188
|
-
delete obj[sptProp];
|
|
1189
|
-
if (value !== void 0) {
|
|
1190
|
-
obj[regularProp] = value;
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
internalConvertObjectInPlace(objectDef, client, obj);
|
|
1196
|
-
}
|
|
1197
|
-
if (interfaceApiName) {
|
|
1198
|
-
return objects.map((o) => o.$as(interfaceApiName));
|
|
1199
|
-
} else {
|
|
1200
|
-
return objects;
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
function createLocalObjectCacheAndInitiatePreseed(objects, client) {
|
|
1204
|
-
const localInterfaceCache = createAsyncCache((client2, apiName) => client2.ontology.provider.getInterfaceDefinition(apiName));
|
|
1205
|
-
const localObjectCache = createAsyncCache(async (client2, apiName) => {
|
|
1206
|
-
const objectDef = await client2.ontology.provider.getObjectDefinition(apiName);
|
|
1207
|
-
const interfaceDefs = Object.fromEntries((await Promise.all(objectDef.implements?.map((i) => localInterfaceCache.get(client2, i)) ?? [])).map((i) => [i.apiName, i]));
|
|
1208
|
-
if (objectDef[InterfaceDefinitions] == null) {
|
|
1209
|
-
Object.defineProperty(objectDef, InterfaceDefinitions, {
|
|
1210
|
-
value: interfaceDefs,
|
|
1211
|
-
enumerable: false,
|
|
1212
|
-
configurable: false,
|
|
1213
|
-
writable: false
|
|
1214
|
-
});
|
|
1215
|
-
}
|
|
1216
|
-
return objectDef;
|
|
1217
|
-
});
|
|
1218
|
-
const uniqueApiNames = /* @__PURE__ */ new Set();
|
|
1219
|
-
for (const {
|
|
1220
|
-
$apiName
|
|
1221
|
-
} of objects) {
|
|
1222
|
-
if (uniqueApiNames.has($apiName))
|
|
1223
|
-
continue;
|
|
1224
|
-
uniqueApiNames.add($apiName);
|
|
1225
|
-
localObjectCache.get(client, $apiName);
|
|
1226
|
-
}
|
|
1227
|
-
return localObjectCache;
|
|
1228
|
-
}
|
|
1229
|
-
function fixObjectPropertiesInline(objs) {
|
|
1230
|
-
for (const obj of objs) {
|
|
1231
|
-
if (obj.__rid) {
|
|
1232
|
-
obj.$rid = obj.__rid;
|
|
1233
|
-
delete obj.__rid;
|
|
1234
|
-
}
|
|
1235
|
-
obj.$apiName = obj.__apiName;
|
|
1236
|
-
obj.$objectType = obj.__apiName;
|
|
1237
|
-
obj.$primaryKey = obj.__primaryKey;
|
|
1238
|
-
{
|
|
1239
|
-
Object.defineProperties(obj, {
|
|
1240
|
-
"__apiName": {
|
|
1241
|
-
enumerable: false
|
|
1242
|
-
},
|
|
1243
|
-
"__primaryKey": {
|
|
1244
|
-
enumerable: false
|
|
1245
|
-
}
|
|
1246
|
-
});
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
function internalConvertObjectInPlace(objectDef, client, obj) {
|
|
1251
|
-
const [proto, converter] = protoConverterCache.get(client, objectDef);
|
|
1252
|
-
Object.setPrototypeOf(obj, proto);
|
|
1253
|
-
Object.defineProperties(obj, {
|
|
1254
|
-
[OriginClient]: {
|
|
1255
|
-
value: client
|
|
1256
|
-
},
|
|
1257
|
-
[UnderlyingObject]: {
|
|
1258
|
-
value: obj
|
|
1259
|
-
}
|
|
1260
|
-
});
|
|
1261
|
-
if (converter) {
|
|
1262
|
-
converter(obj);
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
|
|
1266
|
-
// src/object/fetchPage.ts
|
|
1267
|
-
function augment(type, ...properties) {
|
|
1268
|
-
return {
|
|
1269
|
-
[type.apiName]: properties
|
|
1270
|
-
};
|
|
1271
|
-
}
|
|
1272
|
-
function objectSetToSearchJsonV2(objectSet, expectedApiName, existingWhere = void 0) {
|
|
1273
|
-
if (objectSet.type === "base") {
|
|
1274
|
-
if (objectSet.objectType !== expectedApiName) {
|
|
1275
|
-
throw new Error(`Expected objectSet.objectType to be ${expectedApiName}, but got ${objectSet.objectType}`);
|
|
1276
|
-
}
|
|
1277
|
-
return existingWhere;
|
|
1278
|
-
}
|
|
1279
|
-
if (objectSet.type === "filter") {
|
|
1280
|
-
return objectSetToSearchJsonV2(objectSet.objectSet, expectedApiName, existingWhere == null ? objectSet.where : {
|
|
1281
|
-
type: "and",
|
|
1282
|
-
value: [existingWhere, objectSet.where]
|
|
1283
|
-
});
|
|
1284
|
-
}
|
|
1285
|
-
throw new Error(`Unsupported objectSet type: ${objectSet.type}`);
|
|
1286
|
-
}
|
|
1287
|
-
async function fetchInterfacePage(client, interfaceType, args, objectSet) {
|
|
1288
|
-
const result = await requests.searchObjectsForInterface(shared_net.createOpenApiRequest(client.stack, client.fetch), client.ontology.metadata.ontologyApiName, interfaceType.apiName, applyFetchArgs(args, {
|
|
1289
|
-
augmentedProperties: args.augment ?? {},
|
|
1290
|
-
augmentedSharedPropertyTypes: {},
|
|
1291
|
-
otherInterfaceTypes: [],
|
|
1292
|
-
selectedObjectTypes: [],
|
|
1293
|
-
selectedSharedPropertyTypes: args.select ?? [],
|
|
1294
|
-
where: objectSetToSearchJsonV2(objectSet, interfaceType.apiName)
|
|
1295
|
-
}), {
|
|
1296
|
-
preview: true
|
|
1297
|
-
});
|
|
1298
|
-
result.data = await convertWireToOsdkObjects(
|
|
1299
|
-
client,
|
|
1300
|
-
result.data,
|
|
1301
|
-
// drop readonly
|
|
1302
|
-
interfaceType.apiName,
|
|
1303
|
-
!args.includeRid
|
|
1304
|
-
);
|
|
1305
|
-
return result;
|
|
1306
|
-
}
|
|
1307
|
-
async function fetchPageInternal(client, objectType, objectSet, args = {}) {
|
|
1308
|
-
if (objectType.type === "interface") {
|
|
1309
|
-
return await fetchInterfacePage(client, objectType, args, objectSet);
|
|
1310
|
-
} else {
|
|
1311
|
-
return await fetchObjectPage(client, objectType, args, objectSet);
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
async function fetchPage(client, objectType, args, objectSet = {
|
|
1315
|
-
type: "base",
|
|
1316
|
-
objectType: objectType["apiName"]
|
|
1317
|
-
}) {
|
|
1318
|
-
return fetchPageInternal(client, objectType, objectSet, args);
|
|
1319
|
-
}
|
|
1320
|
-
function applyFetchArgs(args, body) {
|
|
1321
|
-
if (args?.nextPageToken) {
|
|
1322
|
-
body.pageToken = args.nextPageToken;
|
|
1323
|
-
}
|
|
1324
|
-
if (args?.pageSize != null) {
|
|
1325
|
-
body.pageSize = args.pageSize;
|
|
1326
|
-
}
|
|
1327
|
-
if (args?.orderBy != null) {
|
|
1328
|
-
body.orderBy = {
|
|
1329
|
-
fields: Object.entries(args.orderBy).map(([field, direction]) => ({
|
|
1330
|
-
field,
|
|
1331
|
-
direction
|
|
1332
|
-
}))
|
|
1333
|
-
};
|
|
1334
|
-
}
|
|
1335
|
-
return body;
|
|
1336
|
-
}
|
|
1337
|
-
async function fetchObjectPage(client, objectType, args, objectSet) {
|
|
1338
|
-
const r = await requests.loadObjectSetV2(shared_net.createOpenApiRequest(client.stack, client.fetch), client.ontology.metadata.ontologyApiName, applyFetchArgs(args, {
|
|
1339
|
-
objectSet,
|
|
1340
|
-
// We have to do the following case because LoadObjectSetRequestV2 isnt readonly
|
|
1341
|
-
select: args?.select ?? [],
|
|
1342
|
-
// FIXME?
|
|
1343
|
-
excludeRid: !args?.includeRid
|
|
1344
|
-
}));
|
|
1345
|
-
return Promise.resolve({
|
|
1346
|
-
data: await convertWireToOsdkObjects(client, r.data, void 0),
|
|
1347
|
-
nextPageToken: r.nextPageToken
|
|
1348
|
-
});
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
exports.aggregate = aggregate;
|
|
1352
|
-
exports.augment = augment;
|
|
1353
|
-
exports.createAsyncCache = createAsyncCache;
|
|
1354
|
-
exports.createObjectSet = createObjectSet2;
|
|
1355
|
-
exports.fetchPage = fetchPage;
|
|
1356
|
-
exports.getWireObjectSet = getWireObjectSet;
|
|
1357
|
-
exports.isAttachment = isAttachment;
|
|
1358
|
-
exports.isObjectSet = isObjectSet;
|
|
1359
|
-
exports.isWireObjectSet = isWireObjectSet;
|
|
1360
|
-
exports.loadAllOntologies = loadAllOntologies;
|
|
1361
|
-
exports.loadOntologyEntities = loadOntologyEntities;
|
|
1362
|
-
exports.object_exports = object_exports;
|
|
1363
|
-
//# sourceMappingURL=out.js.map
|
|
1364
|
-
//# sourceMappingURL=chunk-AW6UQOAF.cjs.map
|