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