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