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