@osdk/client 2.3.0-beta.4 → 2.3.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/build/browser/createClient.js +8 -1
- package/build/browser/createClient.js.map +1 -1
- package/build/browser/logger/BaseLogger.js +1 -1
- package/build/browser/logger/BaseLogger.js.map +1 -1
- package/build/browser/observable/ObservableClient.js +17 -1
- package/build/browser/observable/ObservableClient.js.map +1 -1
- package/build/browser/observable/OptimisticBuilder.js.map +1 -1
- package/build/browser/observable/internal/ActionApplication.js +31 -30
- package/build/browser/observable/internal/ActionApplication.js.map +1 -1
- package/build/browser/observable/internal/Changes.js +5 -1
- package/build/browser/observable/internal/Changes.js.map +1 -1
- package/build/browser/observable/internal/ListQuery.js +24 -22
- package/build/browser/observable/internal/ListQuery.js.map +1 -1
- package/build/browser/observable/internal/ObjectQuery.js +30 -1
- package/build/browser/observable/internal/ObjectQuery.js.map +1 -1
- package/build/browser/observable/internal/ObservableClientImpl.js +1 -2
- package/build/browser/observable/internal/ObservableClientImpl.js.map +1 -1
- package/build/browser/observable/internal/OptimisticJob.js +8 -0
- package/build/browser/observable/internal/OptimisticJob.js.map +1 -1
- package/build/browser/observable/internal/Query.js +2 -2
- package/build/browser/observable/internal/Query.js.map +1 -1
- package/build/browser/observable/internal/Store.js +4 -0
- package/build/browser/observable/internal/Store.js.map +1 -1
- package/build/browser/observable/internal/Store.test.js +45 -5
- package/build/browser/observable/internal/Store.test.js.map +1 -1
- package/build/browser/observable/internal/testUtils.js.map +1 -1
- package/build/browser/observable/internal/tombstone.js +18 -0
- package/build/browser/observable/internal/tombstone.js.map +1 -0
- package/build/browser/util/UserAgent.js +2 -1
- package/build/browser/util/UserAgent.js.map +1 -1
- package/build/browser/util/toDataValue.js +1 -1
- package/build/browser/util/toDataValue.js.map +1 -1
- package/build/cjs/chunk-DHPFI5ZJ.cjs +1793 -0
- package/build/cjs/chunk-DHPFI5ZJ.cjs.map +1 -0
- package/build/cjs/{chunk-MZ4JZQUU.cjs → chunk-N4KFUVWG.cjs} +642 -42
- package/build/cjs/chunk-N4KFUVWG.cjs.map +1 -0
- package/build/cjs/index.cjs +16 -1769
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/public/internal.cjs +7 -8
- package/build/cjs/public/internal.cjs.map +1 -1
- package/build/cjs/public/unstable-do-not-use.cjs +182 -123
- package/build/cjs/public/unstable-do-not-use.cjs.map +1 -1
- package/build/cjs/public/unstable-do-not-use.d.cts +2 -1
- package/build/esm/createClient.js +8 -1
- package/build/esm/createClient.js.map +1 -1
- package/build/esm/logger/BaseLogger.js +1 -1
- package/build/esm/logger/BaseLogger.js.map +1 -1
- package/build/esm/observable/ObservableClient.js +17 -1
- package/build/esm/observable/ObservableClient.js.map +1 -1
- package/build/esm/observable/OptimisticBuilder.js.map +1 -1
- package/build/esm/observable/internal/ActionApplication.js +31 -30
- package/build/esm/observable/internal/ActionApplication.js.map +1 -1
- package/build/esm/observable/internal/Changes.js +5 -1
- package/build/esm/observable/internal/Changes.js.map +1 -1
- package/build/esm/observable/internal/ListQuery.js +24 -22
- package/build/esm/observable/internal/ListQuery.js.map +1 -1
- package/build/esm/observable/internal/ObjectQuery.js +30 -1
- package/build/esm/observable/internal/ObjectQuery.js.map +1 -1
- package/build/esm/observable/internal/ObservableClientImpl.js +1 -2
- package/build/esm/observable/internal/ObservableClientImpl.js.map +1 -1
- package/build/esm/observable/internal/OptimisticJob.js +8 -0
- package/build/esm/observable/internal/OptimisticJob.js.map +1 -1
- package/build/esm/observable/internal/Query.js +2 -2
- package/build/esm/observable/internal/Query.js.map +1 -1
- package/build/esm/observable/internal/Store.js +4 -0
- package/build/esm/observable/internal/Store.js.map +1 -1
- package/build/esm/observable/internal/Store.test.js +45 -5
- package/build/esm/observable/internal/Store.test.js.map +1 -1
- package/build/esm/observable/internal/testUtils.js.map +1 -1
- package/build/esm/observable/internal/tombstone.js +18 -0
- package/build/esm/observable/internal/tombstone.js.map +1 -0
- package/build/esm/util/UserAgent.js +2 -1
- package/build/esm/util/UserAgent.js.map +1 -1
- package/build/esm/util/toDataValue.js +1 -1
- package/build/esm/util/toDataValue.js.map +1 -1
- package/build/types/createClient.d.ts.map +1 -1
- package/build/types/observable/ObservableClient.d.ts +2 -2
- package/build/types/observable/ObservableClient.d.ts.map +1 -1
- package/build/types/observable/OptimisticBuilder.d.ts +1 -0
- package/build/types/observable/OptimisticBuilder.d.ts.map +1 -1
- package/build/types/observable/internal/ActionApplication.d.ts +1 -1
- package/build/types/observable/internal/ActionApplication.d.ts.map +1 -1
- package/build/types/observable/internal/Changes.d.ts +2 -0
- package/build/types/observable/internal/Changes.d.ts.map +1 -1
- package/build/types/observable/internal/ListQuery.d.ts.map +1 -1
- package/build/types/observable/internal/ObjectQuery.d.ts +1 -0
- package/build/types/observable/internal/ObjectQuery.d.ts.map +1 -1
- package/build/types/observable/internal/OptimisticJob.d.ts.map +1 -1
- package/build/types/observable/internal/Store.d.ts +2 -1
- package/build/types/observable/internal/Store.d.ts.map +1 -1
- package/build/types/observable/internal/testUtils.d.ts +1 -1
- package/build/types/observable/internal/testUtils.d.ts.map +1 -1
- package/build/types/observable/internal/tombstone.d.ts +1 -0
- package/build/types/observable/internal/tombstone.d.ts.map +1 -0
- package/build/types/util/UserAgent.d.ts +1 -0
- package/build/types/util/UserAgent.d.ts.map +1 -1
- package/package.json +8 -8
- package/build/cjs/chunk-C5D7744G.cjs +0 -615
- package/build/cjs/chunk-C5D7744G.cjs.map +0 -1
- package/build/cjs/chunk-MZ4JZQUU.cjs.map +0 -1
- package/build/cjs/chunk-T4NIFYZS.cjs +0 -14
- package/build/cjs/chunk-T4NIFYZS.cjs.map +0 -1
|
@@ -0,0 +1,1793 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkN4KFUVWG_cjs = require('./chunk-N4KFUVWG.cjs');
|
|
4
|
+
var unstable = require('@osdk/api/unstable');
|
|
5
|
+
var client_unstable = require('@osdk/client.unstable');
|
|
6
|
+
var invariant = require('tiny-invariant');
|
|
7
|
+
var shared_client_impl = require('@osdk/shared.client.impl');
|
|
8
|
+
var api = require('@osdk/api');
|
|
9
|
+
var generatorConverters = require('@osdk/generator-converters');
|
|
10
|
+
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var invariant__default = /*#__PURE__*/_interopDefault(invariant);
|
|
14
|
+
|
|
15
|
+
// src/actions/ActionValidationError.ts
|
|
16
|
+
var ActionValidationError = class extends Error {
|
|
17
|
+
constructor(validation) {
|
|
18
|
+
super("Validation Error: " + JSON.stringify(validation, null, 2));
|
|
19
|
+
this.validation = validation;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/object/AttachmentUpload.ts
|
|
24
|
+
function isAttachmentUpload(o) {
|
|
25
|
+
return typeof o === `object` && "name" in o && "data" in o && o.data instanceof Blob;
|
|
26
|
+
}
|
|
27
|
+
function isAttachmentFile(o) {
|
|
28
|
+
return typeof o === "object" && o instanceof Blob && "name" in o;
|
|
29
|
+
}
|
|
30
|
+
function createAttachmentUpload(data, name) {
|
|
31
|
+
return {
|
|
32
|
+
data,
|
|
33
|
+
name
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/objectSet/conjureUnionType.ts
|
|
38
|
+
function conjureUnionType(type, value) {
|
|
39
|
+
return {
|
|
40
|
+
type,
|
|
41
|
+
[type]: value
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/ontology/makeConjureContext.ts
|
|
46
|
+
function makeConjureContext({
|
|
47
|
+
baseUrl,
|
|
48
|
+
fetch: fetchFn,
|
|
49
|
+
tokenProvider
|
|
50
|
+
}, servicePath) {
|
|
51
|
+
return {
|
|
52
|
+
baseUrl,
|
|
53
|
+
servicePath,
|
|
54
|
+
fetchFn,
|
|
55
|
+
tokenProvider
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// src/pageRequestAsAsyncIter.ts
|
|
60
|
+
function getResults(x) {
|
|
61
|
+
return x.results;
|
|
62
|
+
}
|
|
63
|
+
function applyPageToken(payload, {
|
|
64
|
+
pageToken
|
|
65
|
+
}) {
|
|
66
|
+
return pageToken ? {
|
|
67
|
+
...payload,
|
|
68
|
+
pageToken
|
|
69
|
+
} : void 0;
|
|
70
|
+
}
|
|
71
|
+
async function* pageRequestAsAsyncIter(call, values, nextArgs, initialPayload) {
|
|
72
|
+
let payload = initialPayload;
|
|
73
|
+
while (payload) {
|
|
74
|
+
const r = await call(payload);
|
|
75
|
+
for (const q of values(r)) {
|
|
76
|
+
yield q;
|
|
77
|
+
}
|
|
78
|
+
payload = nextArgs(payload, r);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/object/SimpleCache.ts
|
|
83
|
+
function createSimpleCache(map = /* @__PURE__ */ new Map(), fn) {
|
|
84
|
+
function get(key) {
|
|
85
|
+
let r = map.get(key);
|
|
86
|
+
if (r === void 0 && fn !== void 0) {
|
|
87
|
+
return set(key, fn(key));
|
|
88
|
+
} else {
|
|
89
|
+
return r;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function set(key, value) {
|
|
93
|
+
map.set(key, value);
|
|
94
|
+
return value;
|
|
95
|
+
}
|
|
96
|
+
function remove(key) {
|
|
97
|
+
return map.delete(key);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
get,
|
|
101
|
+
set,
|
|
102
|
+
remove
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function createSimpleAsyncCache(type, fn, createCacheLocal = createSimpleCache) {
|
|
106
|
+
const cache = createCacheLocal(type === "weak" ? /* @__PURE__ */ new WeakMap() : /* @__PURE__ */ new Map());
|
|
107
|
+
const inProgress = createCacheLocal(type === "weak" ? /* @__PURE__ */ new WeakMap() : /* @__PURE__ */ new Map());
|
|
108
|
+
const ret = {
|
|
109
|
+
getOrUndefined: function getOrUndefined(key) {
|
|
110
|
+
return cache.get(key);
|
|
111
|
+
},
|
|
112
|
+
get: async function get(key) {
|
|
113
|
+
return cache.get(key) ?? inProgress.get(key) ?? ret.set(key, fn(key));
|
|
114
|
+
},
|
|
115
|
+
set: async function set(k, v) {
|
|
116
|
+
try {
|
|
117
|
+
const r = await inProgress.set(k, v);
|
|
118
|
+
cache.set(k, r);
|
|
119
|
+
inProgress.remove(k);
|
|
120
|
+
return r;
|
|
121
|
+
} catch (e) {
|
|
122
|
+
inProgress.remove(k);
|
|
123
|
+
throw e;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
return ret;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/__unstable/ConjureSupport.ts
|
|
131
|
+
var cachedAllOntologies;
|
|
132
|
+
async function getOntologyVersionForRid(ctx, ontologyRid) {
|
|
133
|
+
cachedAllOntologies ??= await client_unstable.loadAllOntologies(ctx, {});
|
|
134
|
+
!cachedAllOntologies.ontologies[ontologyRid] ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "ontology should be loaded") : invariant__default.default(false) : void 0;
|
|
135
|
+
return cachedAllOntologies.ontologies[ontologyRid].currentOntologyVersion;
|
|
136
|
+
}
|
|
137
|
+
var strongMemoAsync = (fn) => createSimpleAsyncCache("strong", fn).get;
|
|
138
|
+
var weakMemoAsync = (fn) => createSimpleAsyncCache("weak", fn).get;
|
|
139
|
+
var MetadataClient = class {
|
|
140
|
+
#client;
|
|
141
|
+
#ctx;
|
|
142
|
+
#logger;
|
|
143
|
+
constructor(client) {
|
|
144
|
+
this.#client = client;
|
|
145
|
+
this.#ctx = makeConjureContext(client, "ontology-metadata/api");
|
|
146
|
+
this.#client.ontologyProvider.getObjectDefinition;
|
|
147
|
+
this.#logger = this.#client.logger?.child({
|
|
148
|
+
mcc: true
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
forObjectByRid = strongMemoAsync(async (rid) => {
|
|
152
|
+
return Promise.resolve({
|
|
153
|
+
getPropertyMapping: this.#objectPropertyMapping.bind(this, rid),
|
|
154
|
+
getLinkMapping: this.#objectLinkMapping.bind(this, rid),
|
|
155
|
+
getRid: () => rid,
|
|
156
|
+
getApiName: async () => (await this.#getConjureObjectType(rid)).apiName
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
forObjectByApiName = strongMemoAsync(async (objectApiName) => {
|
|
160
|
+
const objectDef = await this.#client.ontologyProvider.getObjectDefinition(objectApiName);
|
|
161
|
+
return this.forObjectByRid(objectDef.rid);
|
|
162
|
+
});
|
|
163
|
+
#objectPropertyMapping = strongMemoAsync(async (objectTypeRid) => {
|
|
164
|
+
const conjureObjectType = await this.#getConjureObjectType(objectTypeRid);
|
|
165
|
+
return createObjectPropertyMapping(conjureObjectType);
|
|
166
|
+
});
|
|
167
|
+
#objectLinkMapping = strongMemoAsync(async (objectTypeRid) => {
|
|
168
|
+
const linkTypes = await client_unstable.getLinkTypesForObjectTypes(this.#ctx, {
|
|
169
|
+
includeObjectTypesWithoutSearchableDatasources: true,
|
|
170
|
+
loadRedacted: false,
|
|
171
|
+
objectTypeBranches: {},
|
|
172
|
+
objectTypeVersions: {
|
|
173
|
+
[objectTypeRid]: await this.ontologyVersion("")
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
!linkTypes.linkTypes[objectTypeRid] ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "link type should be loaded") : invariant__default.default(false) : void 0;
|
|
177
|
+
const ret = {};
|
|
178
|
+
for (const l of linkTypes.linkTypes[objectTypeRid]) {
|
|
179
|
+
const helper = ({
|
|
180
|
+
apiName
|
|
181
|
+
}, linkSide, otherObjectType) => {
|
|
182
|
+
if (apiName) {
|
|
183
|
+
ret[apiName] = {
|
|
184
|
+
apiName,
|
|
185
|
+
directedLinkTypeRid: {
|
|
186
|
+
linkTypeRid: l.rid,
|
|
187
|
+
linkSide
|
|
188
|
+
},
|
|
189
|
+
otherObjectType
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
if (l.definition.type === "oneToMany") {
|
|
194
|
+
const {
|
|
195
|
+
oneToMany: {
|
|
196
|
+
objectTypeRidManySide,
|
|
197
|
+
manyToOneLinkMetadata,
|
|
198
|
+
objectTypeRidOneSide,
|
|
199
|
+
oneToManyLinkMetadata
|
|
200
|
+
}
|
|
201
|
+
} = l.definition;
|
|
202
|
+
if (objectTypeRidManySide === objectTypeRid) {
|
|
203
|
+
helper(manyToOneLinkMetadata, "TARGET", objectTypeRidOneSide);
|
|
204
|
+
}
|
|
205
|
+
if (objectTypeRidOneSide === objectTypeRid) {
|
|
206
|
+
helper(oneToManyLinkMetadata, "SOURCE", objectTypeRidManySide);
|
|
207
|
+
}
|
|
208
|
+
} else if (l.definition.type === "manyToMany") {
|
|
209
|
+
const {
|
|
210
|
+
manyToMany: {
|
|
211
|
+
objectTypeRidA,
|
|
212
|
+
objectTypeAToBLinkMetadata,
|
|
213
|
+
objectTypeRidB,
|
|
214
|
+
objectTypeBToALinkMetadata
|
|
215
|
+
}
|
|
216
|
+
} = l.definition;
|
|
217
|
+
if (objectTypeRidA === objectTypeRid) {
|
|
218
|
+
helper(objectTypeAToBLinkMetadata, "SOURCE", objectTypeRidB);
|
|
219
|
+
}
|
|
220
|
+
if (objectTypeRidB === objectTypeRid) {
|
|
221
|
+
helper(objectTypeBToALinkMetadata, "TARGET", objectTypeRidA);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return ret;
|
|
226
|
+
});
|
|
227
|
+
#getConjureObjectType = strongMemoAsync(async (objectTypeRid) => {
|
|
228
|
+
this.#logger?.debug(`getConjureObjectType(${objectTypeRid})`);
|
|
229
|
+
const body = {
|
|
230
|
+
datasourceTypes: [],
|
|
231
|
+
objectTypes: [{
|
|
232
|
+
identifier: {
|
|
233
|
+
type: "objectTypeRid",
|
|
234
|
+
objectTypeRid
|
|
235
|
+
},
|
|
236
|
+
versionReference: {
|
|
237
|
+
type: "ontologyVersion",
|
|
238
|
+
ontologyVersion: await this.ontologyVersion("")
|
|
239
|
+
}
|
|
240
|
+
}],
|
|
241
|
+
linkTypes: [],
|
|
242
|
+
sharedPropertyTypes: [],
|
|
243
|
+
interfaceTypes: [],
|
|
244
|
+
typeGroups: [],
|
|
245
|
+
loadRedacted: false,
|
|
246
|
+
includeObjectTypeCount: void 0,
|
|
247
|
+
includeObjectTypesWithoutSearchableDatasources: true,
|
|
248
|
+
includeEntityMetadata: void 0,
|
|
249
|
+
actionTypes: [],
|
|
250
|
+
includeTypeGroupEntitiesCount: void 0,
|
|
251
|
+
entityMetadata: void 0
|
|
252
|
+
};
|
|
253
|
+
const entities = await client_unstable.bulkLoadOntologyEntities(this.#ctx, void 0, body);
|
|
254
|
+
!entities.objectTypes[0]?.objectType ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "object type should be loaded") : invariant__default.default(false) : void 0;
|
|
255
|
+
return entities.objectTypes[0].objectType;
|
|
256
|
+
});
|
|
257
|
+
ontologyVersion = strongMemoAsync(async (_) => getOntologyVersionForRid(this.#ctx, await this.#client.ontologyRid));
|
|
258
|
+
};
|
|
259
|
+
var metadataCacheClient = weakMemoAsync((client) => Promise.resolve(new MetadataClient(client)));
|
|
260
|
+
function createObjectPropertyMapping(conjureOT) {
|
|
261
|
+
!(conjureOT.primaryKeys.length === 1) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `only one primary key supported, got ${conjureOT.primaryKeys.length}`) : invariant__default.default(false) : void 0;
|
|
262
|
+
const pkRid = conjureOT.primaryKeys[0];
|
|
263
|
+
const pkProperty = Object.values(conjureOT.propertyTypes).find((a) => a.rid === pkRid);
|
|
264
|
+
if (!pkProperty) {
|
|
265
|
+
throw new Error(`Could not find PK property by rid: ${pkRid}`);
|
|
266
|
+
}
|
|
267
|
+
const propertyIdToApiNameMapping = Object.fromEntries(Object.values(conjureOT.propertyTypes).map((property) => {
|
|
268
|
+
return [property.id, property.apiName];
|
|
269
|
+
}));
|
|
270
|
+
const propertyApiNameToIdMapping = Object.fromEntries(Object.values(conjureOT.propertyTypes).map((property) => {
|
|
271
|
+
return [property.apiName, property.id];
|
|
272
|
+
}));
|
|
273
|
+
return {
|
|
274
|
+
apiName: conjureOT.apiName,
|
|
275
|
+
id: conjureOT.id,
|
|
276
|
+
propertyIdToApiNameMapping,
|
|
277
|
+
propertyApiNameToIdMapping,
|
|
278
|
+
pk: {
|
|
279
|
+
rid: pkRid,
|
|
280
|
+
apiName: pkProperty.apiName,
|
|
281
|
+
type: pkProperty.type
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/__unstable/createBulkLinksAsyncIterFactory.ts
|
|
287
|
+
function createBulkLinksAsyncIterFactory(ctx) {
|
|
288
|
+
return async function* (objs, linkTypes) {
|
|
289
|
+
if (objs.length === 0) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
ctx.logger?.debug("Preparing to fetch bulk links");
|
|
293
|
+
!objs.every((a) => a.$objectType === objs[0].$objectType) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false) : invariant__default.default(false) : void 0;
|
|
294
|
+
const mcc = await metadataCacheClient(ctx);
|
|
295
|
+
const helper = await mcc.forObjectByApiName(objs[0].$objectType);
|
|
296
|
+
const [objectTypeRid, propertyMapping, fullLinkMapping] = await Promise.all([helper.getRid(), helper.getPropertyMapping(), helper.getLinkMapping()]);
|
|
297
|
+
const linkMapping = Object.fromEntries(Object.entries(fullLinkMapping).filter(([apiName]) => linkTypes.includes(apiName)));
|
|
298
|
+
for (const linkType of linkTypes) {
|
|
299
|
+
if (linkMapping[linkType] == null) {
|
|
300
|
+
throw "Unable to find link type: " + linkType;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const req = {
|
|
304
|
+
objectSetContext: {
|
|
305
|
+
forkRid: void 0,
|
|
306
|
+
objectSetFilterContext: {
|
|
307
|
+
parameterOverrides: {}
|
|
308
|
+
},
|
|
309
|
+
ontologyBranchRid: void 0,
|
|
310
|
+
owningRid: void 0,
|
|
311
|
+
reportUsage: void 0,
|
|
312
|
+
workstateRid: void 0
|
|
313
|
+
},
|
|
314
|
+
responseOptions: {
|
|
315
|
+
includeObjectSetEntities: true,
|
|
316
|
+
includeUsageCost: false
|
|
317
|
+
},
|
|
318
|
+
pageSize: 1e3,
|
|
319
|
+
pageToken: void 0,
|
|
320
|
+
linksRequests: [{
|
|
321
|
+
directedLinkTypes: Object.values(linkMapping).map(({
|
|
322
|
+
directedLinkTypeRid
|
|
323
|
+
}) => directedLinkTypeRid),
|
|
324
|
+
objects: conjureUnionType("objects", objs.map((o) => conjureUnionType("objectLocatorV2", {
|
|
325
|
+
objectTypeRid,
|
|
326
|
+
objectPrimaryKey: {
|
|
327
|
+
[propertyMapping.pk.rid]: conjureUnionType(propertyMapping.pk.type.type, o.$primaryKey)
|
|
328
|
+
}
|
|
329
|
+
})))
|
|
330
|
+
}]
|
|
331
|
+
};
|
|
332
|
+
const bulkLinksIter = pageRequestAsAsyncIter(client_unstable.getBulkLinksPage.bind(void 0, makeConjureContext(ctx, "object-set-service/api")), getResults, (prevReq, prevResult) => applyPageToken({
|
|
333
|
+
...prevReq,
|
|
334
|
+
pageToken: prevResult.pageToken
|
|
335
|
+
}, {
|
|
336
|
+
pageToken: prevResult.pageToken
|
|
337
|
+
}), req);
|
|
338
|
+
for await (const item of bulkLinksIter) {
|
|
339
|
+
const {
|
|
340
|
+
objectIdentifier
|
|
341
|
+
} = item;
|
|
342
|
+
const obj = findObject(objectIdentifier, objs);
|
|
343
|
+
for (const link of item.links) {
|
|
344
|
+
const ref = link.link[link.linkSide === "SOURCE" ? "objectSideB" : "objectSideA"];
|
|
345
|
+
const pk = getPrimaryKeyOrThrow(ref);
|
|
346
|
+
const otherObjectApiName = await (await mcc.forObjectByRid(pk.objectTypeRid)).getApiName();
|
|
347
|
+
const mappedLink = Object.values(linkMapping).find((a) => a.directedLinkTypeRid.linkTypeRid === link.link.linkTypeRid && a.directedLinkTypeRid.linkSide === link.linkSide);
|
|
348
|
+
if (!mappedLink) throw new Error("Could not find link type");
|
|
349
|
+
yield {
|
|
350
|
+
object: obj,
|
|
351
|
+
linkApiName: mappedLink.apiName,
|
|
352
|
+
otherObjectApiName,
|
|
353
|
+
otherObjectPk: pk.pkValue
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function findObject(objectIdentifier, objs) {
|
|
360
|
+
const {
|
|
361
|
+
pkValue
|
|
362
|
+
} = getPrimaryKeyOrThrow(objectIdentifier);
|
|
363
|
+
const obj = objs.find((o) => o.$primaryKey === pkValue);
|
|
364
|
+
if (obj == null) {
|
|
365
|
+
throw new Error(`Needed to find object with pk ${pkValue}} and could not`);
|
|
366
|
+
}
|
|
367
|
+
return obj;
|
|
368
|
+
}
|
|
369
|
+
function getPrimaryKeyOrThrow(ref) {
|
|
370
|
+
if ("type" in ref && ref.type !== "objectLocatorV2") {
|
|
371
|
+
throw new Error("We do not support looking up object by rid");
|
|
372
|
+
}
|
|
373
|
+
const pks = Object.entries(ref.objectLocatorV2.objectPrimaryKey);
|
|
374
|
+
if (pks.length !== 1) {
|
|
375
|
+
throw new Error("Unable to support this request due to multiple pks");
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
objectTypeRid: ref.objectLocatorV2.objectTypeRid,
|
|
379
|
+
pkValue: pks[0][1][pks[0][1].type]
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// src/object/mediaUpload.ts
|
|
384
|
+
function isMediaReference(o) {
|
|
385
|
+
return typeof o === `object` && typeof o.mimeType === "string" && "reference" in o && typeof o.reference === "object" && o.reference.type === "mediaSetViewItem" && "mediaSetViewItem" in o.reference && typeof o.reference.mediaSetViewItem === "object" && typeof o.reference.mediaSetViewItem.mediaSetRid === "string" && typeof o.reference.mediaSetViewItem.mediaSetViewRid === "string" && typeof o.reference.mediaSetViewItem.mediaItemRid === "string";
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// src/util/interfaceUtils.ts
|
|
389
|
+
function isInterfaceActionParam(o) {
|
|
390
|
+
return o != null && typeof o === "object" && "$objectType" in o && "$primaryKey" in o;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/util/isObjectSpecifiersObject.ts
|
|
394
|
+
function isObjectSpecifiersObject(o) {
|
|
395
|
+
return o && typeof o === "object" && typeof o.$apiName === "string" && o.$primaryKey != null;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/util/isOntologyObjectV2.ts
|
|
399
|
+
function isOntologyObjectV2(o) {
|
|
400
|
+
return o && typeof o === "object" && typeof o.__apiName === "string" && o.__primaryKey != null;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/util/isPoint.ts
|
|
404
|
+
function isPoint(o) {
|
|
405
|
+
return o && typeof o === "object" && "type" in o && o.type === "Point" && "coordinates" in o && o.coordinates.length === 2;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/util/toDataValue.ts
|
|
409
|
+
async function toDataValue(value, client) {
|
|
410
|
+
if (value == null) {
|
|
411
|
+
return value;
|
|
412
|
+
}
|
|
413
|
+
if (Array.isArray(value) || value instanceof Set) {
|
|
414
|
+
const values = Array.from(value);
|
|
415
|
+
if (values.some((dataValue) => isAttachmentUpload(dataValue) || isAttachmentFile(dataValue))) {
|
|
416
|
+
const converted = [];
|
|
417
|
+
for (const value2 of values) {
|
|
418
|
+
converted.push(await toDataValue(value2, client));
|
|
419
|
+
}
|
|
420
|
+
return converted;
|
|
421
|
+
}
|
|
422
|
+
const promiseArray = Array.from(value, async (innerValue) => await toDataValue(innerValue, client));
|
|
423
|
+
return Promise.all(promiseArray);
|
|
424
|
+
}
|
|
425
|
+
if (isAttachmentUpload(value)) {
|
|
426
|
+
const attachment = await chunkN4KFUVWG_cjs.Attachment_exports.upload(client, value.data, {
|
|
427
|
+
filename: value.name
|
|
428
|
+
});
|
|
429
|
+
return await toDataValue(attachment.rid, client);
|
|
430
|
+
}
|
|
431
|
+
if (isAttachmentFile(value)) {
|
|
432
|
+
const attachment = await chunkN4KFUVWG_cjs.Attachment_exports.upload(client, value, {
|
|
433
|
+
filename: value.name
|
|
434
|
+
});
|
|
435
|
+
return await toDataValue(attachment.rid, client);
|
|
436
|
+
}
|
|
437
|
+
if (isOntologyObjectV2(value)) {
|
|
438
|
+
return await toDataValue(value.__primaryKey, client);
|
|
439
|
+
}
|
|
440
|
+
if (isObjectSpecifiersObject(value)) {
|
|
441
|
+
return await toDataValue(value.$primaryKey, client);
|
|
442
|
+
}
|
|
443
|
+
if (isPoint(value)) {
|
|
444
|
+
return await toDataValue(`${value.coordinates[1]},${value.coordinates[0]}`, client);
|
|
445
|
+
}
|
|
446
|
+
if (chunkN4KFUVWG_cjs.isWireObjectSet(value)) {
|
|
447
|
+
return value;
|
|
448
|
+
}
|
|
449
|
+
if (chunkN4KFUVWG_cjs.isObjectSet(value)) {
|
|
450
|
+
return chunkN4KFUVWG_cjs.getWireObjectSet(value);
|
|
451
|
+
}
|
|
452
|
+
if (isMediaReference(value)) {
|
|
453
|
+
return value;
|
|
454
|
+
}
|
|
455
|
+
if (isInterfaceActionParam(value)) {
|
|
456
|
+
return {
|
|
457
|
+
objectTypeApiName: value.$objectType,
|
|
458
|
+
primaryKeyValue: value.$primaryKey
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
if (typeof value === "object") {
|
|
462
|
+
return Object.entries(value).reduce(async (promisedAcc, [key, structValue]) => {
|
|
463
|
+
const acc = await promisedAcc;
|
|
464
|
+
acc[key] = await toDataValue(structValue, client);
|
|
465
|
+
return acc;
|
|
466
|
+
}, Promise.resolve({}));
|
|
467
|
+
}
|
|
468
|
+
return value;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// src/actions/applyAction.ts
|
|
472
|
+
async function applyAction(client, action, parameters, options = {}) {
|
|
473
|
+
const clientWithHeaders = chunkN4KFUVWG_cjs.addUserAgentAndRequestContextHeaders(chunkN4KFUVWG_cjs.augmentRequestContext(client, (_) => ({
|
|
474
|
+
finalMethodCall: "applyAction"
|
|
475
|
+
})), action);
|
|
476
|
+
if (Array.isArray(parameters)) {
|
|
477
|
+
const response = await chunkN4KFUVWG_cjs.Action_exports.applyBatch(clientWithHeaders, await client.ontologyRid, action.apiName, {
|
|
478
|
+
requests: parameters ? await remapBatchActionParams(parameters, client) : [],
|
|
479
|
+
options: {
|
|
480
|
+
returnEdits: options?.$returnEdits ? "ALL" : "NONE"
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
const edits = response.edits;
|
|
484
|
+
return options?.$returnEdits ? edits?.type === "edits" ? remapActionResponse(response) : edits : void 0;
|
|
485
|
+
} else {
|
|
486
|
+
const response = await chunkN4KFUVWG_cjs.Action_exports.apply(clientWithHeaders, await client.ontologyRid, action.apiName, {
|
|
487
|
+
parameters: await remapActionParams(parameters, client),
|
|
488
|
+
options: {
|
|
489
|
+
mode: options?.$validateOnly ? "VALIDATE_ONLY" : "VALIDATE_AND_EXECUTE",
|
|
490
|
+
returnEdits: options?.$returnEdits ? "ALL_V2_WITH_DELETIONS" : "NONE"
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
if (options?.$validateOnly) {
|
|
494
|
+
return response.validation;
|
|
495
|
+
}
|
|
496
|
+
if (response.validation?.result === "INVALID") {
|
|
497
|
+
throw new ActionValidationError(response.validation);
|
|
498
|
+
}
|
|
499
|
+
const edits = response.edits;
|
|
500
|
+
return options?.$returnEdits ? edits?.type === "edits" ? remapActionResponse(response) : edits : void 0;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
async function remapActionParams(params, client) {
|
|
504
|
+
if (params == null) {
|
|
505
|
+
return {};
|
|
506
|
+
}
|
|
507
|
+
const parameterMap = {};
|
|
508
|
+
for (const [key, value] of Object.entries(params)) {
|
|
509
|
+
parameterMap[key] = await toDataValue(value, client);
|
|
510
|
+
}
|
|
511
|
+
return parameterMap;
|
|
512
|
+
}
|
|
513
|
+
async function remapBatchActionParams(params, client) {
|
|
514
|
+
const remappedParams = await Promise.all(params.map(async (param) => {
|
|
515
|
+
return {
|
|
516
|
+
parameters: await remapActionParams(param, client)
|
|
517
|
+
};
|
|
518
|
+
}));
|
|
519
|
+
return remappedParams;
|
|
520
|
+
}
|
|
521
|
+
function remapActionResponse(response) {
|
|
522
|
+
const editResponses = response?.edits;
|
|
523
|
+
if (editResponses?.type === "edits") {
|
|
524
|
+
const remappedActionResponse = {
|
|
525
|
+
type: editResponses.type,
|
|
526
|
+
deletedLinksCount: editResponses.deletedLinksCount,
|
|
527
|
+
deletedObjectsCount: editResponses.deletedObjectsCount,
|
|
528
|
+
addedLinks: [],
|
|
529
|
+
deletedLinks: [],
|
|
530
|
+
addedObjects: [],
|
|
531
|
+
deletedObjects: [],
|
|
532
|
+
modifiedObjects: [],
|
|
533
|
+
editedObjectTypes: []
|
|
534
|
+
};
|
|
535
|
+
const editedObjectTypesSet = /* @__PURE__ */ new Set();
|
|
536
|
+
for (const edit of editResponses.edits) {
|
|
537
|
+
if (edit.type === "addLink" || edit.type === "deleteLink") {
|
|
538
|
+
const osdkEdit = {
|
|
539
|
+
linkTypeApiNameAtoB: edit.linkTypeApiNameAtoB,
|
|
540
|
+
linkTypeApiNameBtoA: edit.linkTypeApiNameBtoA,
|
|
541
|
+
aSideObject: edit.aSideObject,
|
|
542
|
+
bSideObject: edit.bSideObject
|
|
543
|
+
};
|
|
544
|
+
edit.type === "addLink" ? remappedActionResponse.addedLinks.push(osdkEdit) : remappedActionResponse.deletedLinks?.push(osdkEdit);
|
|
545
|
+
editedObjectTypesSet.add(edit.aSideObject.objectType);
|
|
546
|
+
editedObjectTypesSet.add(edit.bSideObject.objectType);
|
|
547
|
+
} else if (edit.type === "addObject" || edit.type === "deleteObject" || edit.type === "modifyObject") {
|
|
548
|
+
const osdkEdit = {
|
|
549
|
+
objectType: edit.objectType,
|
|
550
|
+
primaryKey: edit.primaryKey
|
|
551
|
+
};
|
|
552
|
+
if (edit.type === "addObject") {
|
|
553
|
+
remappedActionResponse.addedObjects.push(osdkEdit);
|
|
554
|
+
} else if (edit.type === "deleteObject") {
|
|
555
|
+
remappedActionResponse.deletedObjects?.push(osdkEdit);
|
|
556
|
+
} else if (edit.type === "modifyObject") {
|
|
557
|
+
remappedActionResponse.modifiedObjects.push(osdkEdit);
|
|
558
|
+
}
|
|
559
|
+
editedObjectTypesSet.add(edit.objectType);
|
|
560
|
+
} else {
|
|
561
|
+
if (process.env.NODE_ENV !== "production") {
|
|
562
|
+
console.warn(`Unexpected edit type: ${JSON.stringify(edit)}`);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
remappedActionResponse.editedObjectTypes = [...editedObjectTypesSet];
|
|
567
|
+
return remappedActionResponse;
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
// src/util/streamutils.ts
|
|
572
|
+
var START_TOKEN = new Uint8Array([123, 34, 100, 97, 116, 97, 34, 58, 91]);
|
|
573
|
+
var OBJECT_OPEN_CHAR_CODE = 123;
|
|
574
|
+
var OBJECT_CLOSE_CHAR_CODE = 125;
|
|
575
|
+
async function* parseStreamedResponse(asyncIterable) {
|
|
576
|
+
const utf8decoder = new TextDecoder("utf-8");
|
|
577
|
+
let parsedStart = false;
|
|
578
|
+
let prevChunks = [];
|
|
579
|
+
let openBracesCount = 0;
|
|
580
|
+
for await (let chunk of asyncIterable) {
|
|
581
|
+
let i = 0;
|
|
582
|
+
if (!parsedStart) {
|
|
583
|
+
parsedStart = true;
|
|
584
|
+
if (startsWith(chunk, START_TOKEN)) {
|
|
585
|
+
i = START_TOKEN.length;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
for (; i < chunk.length; i++) {
|
|
589
|
+
while (openBracesCount === 0 && chunk[i] !== OBJECT_OPEN_CHAR_CODE && i < chunk.length) {
|
|
590
|
+
i++;
|
|
591
|
+
}
|
|
592
|
+
let j = i;
|
|
593
|
+
for (; j < chunk.length; j++) {
|
|
594
|
+
const c = chunk[j];
|
|
595
|
+
if (c === OBJECT_OPEN_CHAR_CODE) {
|
|
596
|
+
openBracesCount++;
|
|
597
|
+
} else if (c === OBJECT_CLOSE_CHAR_CODE) {
|
|
598
|
+
openBracesCount--;
|
|
599
|
+
if (0 === openBracesCount) {
|
|
600
|
+
yield combineAndParse(utf8decoder, prevChunks, chunk.subarray(i, j + 1));
|
|
601
|
+
prevChunks = [];
|
|
602
|
+
i = j;
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (j === chunk.length) {
|
|
608
|
+
prevChunks.push(chunk.subarray(i));
|
|
609
|
+
break;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function startsWith(a, b) {
|
|
615
|
+
if (a.length < b.length) {
|
|
616
|
+
return false;
|
|
617
|
+
}
|
|
618
|
+
for (let i = 0; i < b.length; i++) {
|
|
619
|
+
if (a[i] !== b[i]) {
|
|
620
|
+
return false;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return true;
|
|
624
|
+
}
|
|
625
|
+
function combineAndParse(utf8decoder, prev, curr) {
|
|
626
|
+
let str = "";
|
|
627
|
+
for (const chunk of prev) {
|
|
628
|
+
str += utf8decoder.decode(chunk, {
|
|
629
|
+
stream: true
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
str += utf8decoder.decode(curr);
|
|
633
|
+
return JSON.parse(str);
|
|
634
|
+
}
|
|
635
|
+
async function* iterateReadableStream(readableStream) {
|
|
636
|
+
let res = await readableStream.read();
|
|
637
|
+
while (!res.done) {
|
|
638
|
+
yield res.value;
|
|
639
|
+
res = await readableStream.read();
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// src/util/timeseriesUtils.ts
|
|
644
|
+
function getTimeRange(body) {
|
|
645
|
+
if ("$startTime" in body || "$endTime" in body) {
|
|
646
|
+
return {
|
|
647
|
+
type: "absolute",
|
|
648
|
+
startTime: body.$startTime,
|
|
649
|
+
endTime: body.$endTime
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
return body.$before ? {
|
|
653
|
+
type: "relative",
|
|
654
|
+
startTime: {
|
|
655
|
+
when: "BEFORE",
|
|
656
|
+
value: body.$before,
|
|
657
|
+
unit: api.TimeseriesDurationMapping[body.$unit]
|
|
658
|
+
}
|
|
659
|
+
} : {
|
|
660
|
+
type: "relative",
|
|
661
|
+
endTime: {
|
|
662
|
+
when: "AFTER",
|
|
663
|
+
value: body.$after,
|
|
664
|
+
unit: api.TimeseriesDurationMapping[body.$unit]
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
async function* asyncIterPointsHelper(iterator) {
|
|
669
|
+
const reader = iterator.body?.getReader();
|
|
670
|
+
for await (const point of parseStreamedResponse(iterateReadableStream(reader))) {
|
|
671
|
+
yield {
|
|
672
|
+
time: point.time,
|
|
673
|
+
value: point.value
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
// src/createGeotimeSeriesProperty.ts
|
|
679
|
+
var GeotimeSeriesPropertyImpl = class {
|
|
680
|
+
#triplet;
|
|
681
|
+
#client;
|
|
682
|
+
constructor(client, objectApiName, primaryKey, propertyName, initialValue) {
|
|
683
|
+
this.#client = client;
|
|
684
|
+
this.#triplet = [objectApiName, primaryKey, propertyName];
|
|
685
|
+
if (initialValue != null) {
|
|
686
|
+
this.lastFetchedValue = initialValue;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
async getLatestValue() {
|
|
690
|
+
const latestPointPromise = chunkN4KFUVWG_cjs.TimeSeriesValueBankProperty_exports.getLatestValue(this.#client, await this.#client.ontologyRid, ...this.#triplet);
|
|
691
|
+
latestPointPromise.then(
|
|
692
|
+
(latestPoint) => this.lastFetchedValue = latestPoint,
|
|
693
|
+
// eslint-disable-next-line no-console
|
|
694
|
+
(err) => void console.error(err)
|
|
695
|
+
);
|
|
696
|
+
return latestPointPromise;
|
|
697
|
+
}
|
|
698
|
+
async getAllValues(query) {
|
|
699
|
+
const allPoints = [];
|
|
700
|
+
for await (const point of this.asyncIterValues(query)) {
|
|
701
|
+
allPoints.push(point);
|
|
702
|
+
}
|
|
703
|
+
return allPoints;
|
|
704
|
+
}
|
|
705
|
+
async *asyncIterValues(query) {
|
|
706
|
+
const streamPointsIterator = await chunkN4KFUVWG_cjs.TimeSeriesValueBankProperty_exports.streamValues(this.#client, await this.#client.ontologyRid, ...this.#triplet, query ? {
|
|
707
|
+
range: getTimeRange(query)
|
|
708
|
+
} : {});
|
|
709
|
+
for await (const timeseriesPoint of asyncIterPointsHelper(streamPointsIterator)) {
|
|
710
|
+
yield timeseriesPoint;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
// src/createMediaReferenceProperty.ts
|
|
716
|
+
var MediaReferencePropertyImpl = class {
|
|
717
|
+
#mediaReference;
|
|
718
|
+
#triplet;
|
|
719
|
+
#client;
|
|
720
|
+
constructor(args) {
|
|
721
|
+
const {
|
|
722
|
+
client,
|
|
723
|
+
objectApiName,
|
|
724
|
+
primaryKey,
|
|
725
|
+
propertyName,
|
|
726
|
+
mediaReference
|
|
727
|
+
} = args;
|
|
728
|
+
this.#client = client;
|
|
729
|
+
this.#triplet = [objectApiName, primaryKey, propertyName];
|
|
730
|
+
this.#mediaReference = mediaReference;
|
|
731
|
+
}
|
|
732
|
+
async fetchContents() {
|
|
733
|
+
return chunkN4KFUVWG_cjs.MediaReferenceProperty_exports.getMediaContent(this.#client, await this.#client.ontologyRid, ...this.#triplet, {
|
|
734
|
+
preview: true
|
|
735
|
+
// TODO: Can turn this back off when backend is no longer in beta.
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
async fetchMetadata() {
|
|
739
|
+
const r = await chunkN4KFUVWG_cjs.MediaReferenceProperty_exports.getMediaMetadata(this.#client, await this.#client.ontologyRid, ...this.#triplet, {
|
|
740
|
+
preview: true
|
|
741
|
+
// TODO: Can turn this back off when backend is no longer in beta.
|
|
742
|
+
});
|
|
743
|
+
return {
|
|
744
|
+
path: r.path,
|
|
745
|
+
sizeBytes: Number(r.sizeBytes),
|
|
746
|
+
mediaType: r.mediaType
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
getMediaReference() {
|
|
750
|
+
return this.#mediaReference;
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
// src/createTimeseriesProperty.ts
|
|
755
|
+
var TimeSeriesPropertyImpl = class {
|
|
756
|
+
#triplet;
|
|
757
|
+
#client;
|
|
758
|
+
constructor(client, objectApiName, primaryKey, propertyName) {
|
|
759
|
+
this.#client = client;
|
|
760
|
+
this.#triplet = [objectApiName, primaryKey, propertyName];
|
|
761
|
+
}
|
|
762
|
+
async getFirstPoint() {
|
|
763
|
+
return chunkN4KFUVWG_cjs.TimeSeriesPropertyV2_exports.getFirstPoint(this.#client, await this.#client.ontologyRid, ...this.#triplet);
|
|
764
|
+
}
|
|
765
|
+
async getLastPoint() {
|
|
766
|
+
return chunkN4KFUVWG_cjs.TimeSeriesPropertyV2_exports.getLastPoint(this.#client, await this.#client.ontologyRid, ...this.#triplet);
|
|
767
|
+
}
|
|
768
|
+
async getAllPoints(query) {
|
|
769
|
+
const allPoints = [];
|
|
770
|
+
for await (const point of this.asyncIterPoints(query)) {
|
|
771
|
+
allPoints.push(point);
|
|
772
|
+
}
|
|
773
|
+
return allPoints;
|
|
774
|
+
}
|
|
775
|
+
async *asyncIterPoints(query) {
|
|
776
|
+
const streamPointsIterator = await chunkN4KFUVWG_cjs.TimeSeriesPropertyV2_exports.streamPoints(this.#client, await this.#client.ontologyRid, ...this.#triplet, query ? {
|
|
777
|
+
range: getTimeRange(query)
|
|
778
|
+
} : {});
|
|
779
|
+
for await (const timeseriesPoint of asyncIterPointsHelper(streamPointsIterator)) {
|
|
780
|
+
yield timeseriesPoint;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
// src/util/objectSpecifierUtils.ts
|
|
786
|
+
function createObjectSpecifierFromPrimaryKey(objectDef, primaryKey) {
|
|
787
|
+
return `${objectDef.apiName}:${primaryKey}`;
|
|
788
|
+
}
|
|
789
|
+
function extractPrimaryKeyFromObjectSpecifier(ObjectSpecifier) {
|
|
790
|
+
return ObjectSpecifier.split(":")[1];
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
// src/ontology/OntologyProvider.ts
|
|
794
|
+
var InterfaceDefinitions = Symbol("InterfaceDefinitions" );
|
|
795
|
+
|
|
796
|
+
// src/object/convertWireToOsdkObjects/InternalSymbols.ts
|
|
797
|
+
var UnderlyingOsdkObject = Symbol("Underlying Object" );
|
|
798
|
+
var ObjectDefRef = Symbol("ObjectDefinition" );
|
|
799
|
+
var InterfaceDefRef = Symbol("InterfaceDefinition" );
|
|
800
|
+
var ClientRef = Symbol("ClientRef" );
|
|
801
|
+
|
|
802
|
+
// src/object/convertWireToOsdkObjects/createOsdkInterface.ts
|
|
803
|
+
function createOsdkInterface(underlying, interfaceDef) {
|
|
804
|
+
const [objApiNamespace] = chunkN4KFUVWG_cjs.extractNamespace(interfaceDef.apiName);
|
|
805
|
+
return Object.freeze(Object.defineProperties({}, {
|
|
806
|
+
// first to minimize hidden classes
|
|
807
|
+
[UnderlyingOsdkObject]: {
|
|
808
|
+
value: underlying
|
|
809
|
+
},
|
|
810
|
+
"$apiName": {
|
|
811
|
+
value: interfaceDef.apiName,
|
|
812
|
+
enumerable: true
|
|
813
|
+
},
|
|
814
|
+
"$as": {
|
|
815
|
+
value: underlying.$as,
|
|
816
|
+
enumerable: false
|
|
817
|
+
},
|
|
818
|
+
"$objectType": {
|
|
819
|
+
value: underlying.$objectType,
|
|
820
|
+
enumerable: "$objectType" in underlying
|
|
821
|
+
},
|
|
822
|
+
"$primaryKey": {
|
|
823
|
+
value: underlying.$primaryKey,
|
|
824
|
+
enumerable: "$primaryKey" in underlying
|
|
825
|
+
},
|
|
826
|
+
"$objectSpecifier": {
|
|
827
|
+
value: underlying.$objectSpecifier,
|
|
828
|
+
enumerable: "$objectSpecifier" in underlying
|
|
829
|
+
},
|
|
830
|
+
"$title": {
|
|
831
|
+
value: underlying.$title,
|
|
832
|
+
enumerable: "$title" in underlying
|
|
833
|
+
},
|
|
834
|
+
"$rid": {
|
|
835
|
+
value: underlying.$rid,
|
|
836
|
+
enumerable: "$rid" in underlying
|
|
837
|
+
},
|
|
838
|
+
"$clone": {
|
|
839
|
+
value: clone,
|
|
840
|
+
enumerable: false
|
|
841
|
+
},
|
|
842
|
+
[InterfaceDefRef]: {
|
|
843
|
+
value: interfaceDef
|
|
844
|
+
},
|
|
845
|
+
...Object.fromEntries(Object.keys(interfaceDef.properties).map((p) => {
|
|
846
|
+
const objDef = underlying[ObjectDefRef];
|
|
847
|
+
const [apiNamespace, apiName] = chunkN4KFUVWG_cjs.extractNamespace(p);
|
|
848
|
+
const targetPropName = objDef.interfaceMap[interfaceDef.apiName][p];
|
|
849
|
+
return [apiNamespace === objApiNamespace ? apiName : p, {
|
|
850
|
+
enumerable: targetPropName in underlying,
|
|
851
|
+
value: underlying[targetPropName]
|
|
852
|
+
}];
|
|
853
|
+
}))
|
|
854
|
+
}));
|
|
855
|
+
function clone(update) {
|
|
856
|
+
if (update == null) {
|
|
857
|
+
return underlying.$clone().$as(interfaceDef);
|
|
858
|
+
}
|
|
859
|
+
for (const key of Object.keys(update)) {
|
|
860
|
+
if (!(key in interfaceDef.properties)) {
|
|
861
|
+
throw new Error(`Invalid property ${key} for interface ${interfaceDef.apiName}`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
const remappedProps = Object.fromEntries(Object.keys(update).map((p) => mapProperty(p, update[p])).filter((x) => x != null));
|
|
865
|
+
return underlying.$clone(remappedProps).$as(interfaceDef);
|
|
866
|
+
}
|
|
867
|
+
function mapProperty(propertyName, value) {
|
|
868
|
+
const objDef = underlying[ObjectDefRef];
|
|
869
|
+
const targetPropName = objDef.interfaceMap[interfaceDef.apiName][propertyName];
|
|
870
|
+
if (targetPropName == null) {
|
|
871
|
+
throw new Error(`Cannot clone interface with ${propertyName} as property is not implemented by the underlying object type ${objDef.apiName}`);
|
|
872
|
+
}
|
|
873
|
+
return [targetPropName, value];
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
// src/object/convertWireToOsdkObjects/getDollarAs.ts
|
|
878
|
+
var get$as = createSimpleCache(/* @__PURE__ */ new WeakMap(), $asFactory).get;
|
|
879
|
+
var osdkObjectToInterfaceView = createSimpleCache(/* @__PURE__ */ new WeakMap(), () => /* @__PURE__ */ new Map());
|
|
880
|
+
function $asFactory(objDef) {
|
|
881
|
+
return function $as(targetMinDef) {
|
|
882
|
+
let targetInterfaceApiName;
|
|
883
|
+
if (typeof targetMinDef === "string") {
|
|
884
|
+
if (targetMinDef === objDef.apiName) {
|
|
885
|
+
return this[UnderlyingOsdkObject];
|
|
886
|
+
}
|
|
887
|
+
if (objDef.interfaceMap?.[targetMinDef] == null) {
|
|
888
|
+
throw new Error(`Object does not implement interface '${targetMinDef}'.`);
|
|
889
|
+
}
|
|
890
|
+
targetInterfaceApiName = targetMinDef;
|
|
891
|
+
} else if (targetMinDef.apiName === objDef.apiName) {
|
|
892
|
+
return this[UnderlyingOsdkObject];
|
|
893
|
+
} else {
|
|
894
|
+
if (targetMinDef.type === "object") {
|
|
895
|
+
throw new Error(`'${targetMinDef.apiName}' is not an interface nor is it '${objDef.apiName}', which is the object type.`);
|
|
896
|
+
}
|
|
897
|
+
targetInterfaceApiName = targetMinDef.apiName;
|
|
898
|
+
}
|
|
899
|
+
const def = objDef[InterfaceDefinitions][targetInterfaceApiName];
|
|
900
|
+
if (!def) {
|
|
901
|
+
throw new Error(`Object does not implement interface '${targetInterfaceApiName}'.`);
|
|
902
|
+
}
|
|
903
|
+
const underlying = this[UnderlyingOsdkObject];
|
|
904
|
+
const existing = osdkObjectToInterfaceView.get(underlying).get(targetInterfaceApiName)?.deref();
|
|
905
|
+
if (existing) return existing;
|
|
906
|
+
const osdkInterface = createOsdkInterface(underlying, def.def);
|
|
907
|
+
osdkObjectToInterfaceView.get(underlying).set(targetInterfaceApiName, new WeakRef(osdkInterface));
|
|
908
|
+
return osdkInterface;
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// src/object/convertWireToOsdkObjects/getDollarLink.ts
|
|
913
|
+
function get$link(holder) {
|
|
914
|
+
const client = holder[ClientRef];
|
|
915
|
+
const objDef = holder[ObjectDefRef];
|
|
916
|
+
const rawObj = holder[UnderlyingOsdkObject];
|
|
917
|
+
return Object.freeze(Object.fromEntries(Object.keys(objDef.links).map((linkName) => {
|
|
918
|
+
const linkDef = objDef.links[linkName];
|
|
919
|
+
const objectSet = client.objectSetFactory(objDef, client).where({
|
|
920
|
+
[objDef.primaryKeyApiName]: rawObj.$primaryKey
|
|
921
|
+
}).pivotTo(linkName);
|
|
922
|
+
const value = !linkDef.multiplicity ? {
|
|
923
|
+
fetchOne: (options) => chunkN4KFUVWG_cjs.fetchSingle(client, objDef, options ?? {}, chunkN4KFUVWG_cjs.getWireObjectSet(objectSet)),
|
|
924
|
+
fetchOneWithErrors: (options) => chunkN4KFUVWG_cjs.fetchSingleWithErrors(client, objDef, options ?? {}, chunkN4KFUVWG_cjs.getWireObjectSet(objectSet))
|
|
925
|
+
} : objectSet;
|
|
926
|
+
return [linkName, value];
|
|
927
|
+
})));
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// src/object/convertWireToOsdkObjects/createOsdkObject.ts
|
|
931
|
+
var specialPropertyTypes = /* @__PURE__ */ new Set(["attachment", "geotimeSeriesReference", "mediaReference", "numericTimeseries", "stringTimeseries", "sensorTimeseries"]);
|
|
932
|
+
var basePropDefs = {
|
|
933
|
+
"$as": {
|
|
934
|
+
get: function() {
|
|
935
|
+
return get$as(this[ObjectDefRef]);
|
|
936
|
+
}
|
|
937
|
+
},
|
|
938
|
+
"$link": {
|
|
939
|
+
get: function() {
|
|
940
|
+
return get$link(this);
|
|
941
|
+
}
|
|
942
|
+
},
|
|
943
|
+
"$clone": {
|
|
944
|
+
value: function(update) {
|
|
945
|
+
const rawObj = this[UnderlyingOsdkObject];
|
|
946
|
+
const def = this[ObjectDefRef];
|
|
947
|
+
if (update == null) {
|
|
948
|
+
return createOsdkObject(this[ClientRef], def, {
|
|
949
|
+
...rawObj
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
if (def.primaryKeyApiName in update && rawObj[def.primaryKeyApiName] !== update[def.primaryKeyApiName]) {
|
|
953
|
+
throw new Error(`Cannot update ${def.apiName} object with differing primary key values `);
|
|
954
|
+
}
|
|
955
|
+
if (def.titleProperty in update && !("$title" in update)) {
|
|
956
|
+
update.$title = update[def.titleProperty];
|
|
957
|
+
}
|
|
958
|
+
const newObject = {
|
|
959
|
+
...this[UnderlyingOsdkObject],
|
|
960
|
+
...update
|
|
961
|
+
};
|
|
962
|
+
return createOsdkObject(this[ClientRef], this[ObjectDefRef], newObject);
|
|
963
|
+
}
|
|
964
|
+
},
|
|
965
|
+
"$objectSpecifier": {
|
|
966
|
+
get: function() {
|
|
967
|
+
const rawObj = this[UnderlyingOsdkObject];
|
|
968
|
+
return createObjectSpecifierFromPrimaryKey(this[ObjectDefRef], rawObj.$primaryKey);
|
|
969
|
+
},
|
|
970
|
+
enumerable: true
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
function createOsdkObject(client, objectDef, simpleOsdkProperties, derivedPropertyTypeByName = {}) {
|
|
974
|
+
const rawObj = simpleOsdkProperties;
|
|
975
|
+
Object.defineProperties(rawObj, {
|
|
976
|
+
[UnderlyingOsdkObject]: {
|
|
977
|
+
enumerable: false,
|
|
978
|
+
value: simpleOsdkProperties
|
|
979
|
+
},
|
|
980
|
+
[ObjectDefRef]: {
|
|
981
|
+
value: objectDef,
|
|
982
|
+
enumerable: false
|
|
983
|
+
},
|
|
984
|
+
[ClientRef]: {
|
|
985
|
+
value: client,
|
|
986
|
+
enumerable: false
|
|
987
|
+
},
|
|
988
|
+
...basePropDefs
|
|
989
|
+
});
|
|
990
|
+
for (const propKey of Object.keys(rawObj)) {
|
|
991
|
+
if (propKey in objectDef.properties && typeof objectDef.properties[propKey].type === "string" && specialPropertyTypes.has(objectDef.properties[propKey].type)) {
|
|
992
|
+
rawObj[propKey] = createSpecialProperty(client, objectDef, rawObj, propKey);
|
|
993
|
+
} else if (propKey in derivedPropertyTypeByName) {
|
|
994
|
+
rawObj[propKey] = modifyRdpProperties(client, derivedPropertyTypeByName, rawObj[propKey], propKey);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
return Object.freeze(rawObj);
|
|
998
|
+
}
|
|
999
|
+
function modifyRdpProperties(client, derivedPropertyTypeByName, rawValue, propKey) {
|
|
1000
|
+
if (derivedPropertyTypeByName[propKey].definition.type === "selection" && derivedPropertyTypeByName[propKey].definition.operation.type === "count") {
|
|
1001
|
+
const num = Number(rawValue);
|
|
1002
|
+
!Number.isSafeInteger(num) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Count aggregation for derived property " + propKey + " returned a value larger than safe integer.") : invariant__default.default(false) : void 0;
|
|
1003
|
+
return num;
|
|
1004
|
+
} else if (derivedPropertyTypeByName[propKey].selectedOrCollectedPropertyType != null && typeof derivedPropertyTypeByName[propKey].selectedOrCollectedPropertyType.type === "string" && specialPropertyTypes.has(derivedPropertyTypeByName[propKey].selectedOrCollectedPropertyType.type)) {
|
|
1005
|
+
switch (derivedPropertyTypeByName[propKey].selectedOrCollectedPropertyType?.type) {
|
|
1006
|
+
case "attachment":
|
|
1007
|
+
if (Array.isArray(rawValue)) {
|
|
1008
|
+
return rawValue.map((a) => chunkN4KFUVWG_cjs.hydrateAttachmentFromRidInternal(client, a.rid));
|
|
1009
|
+
} else {
|
|
1010
|
+
return chunkN4KFUVWG_cjs.hydrateAttachmentFromRidInternal(client, rawValue.rid);
|
|
1011
|
+
}
|
|
1012
|
+
default:
|
|
1013
|
+
process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Derived property aggregations for Timeseries and Media are not supported") : invariant__default.default(false) ;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
return rawValue;
|
|
1017
|
+
}
|
|
1018
|
+
function createSpecialProperty(client, objectDef, rawObject, p) {
|
|
1019
|
+
const rawValue = rawObject[p];
|
|
1020
|
+
const propDef = objectDef.properties[p];
|
|
1021
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1022
|
+
!(propDef != null && typeof propDef.type === "string" && specialPropertyTypes.has(propDef.type)) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false) : invariant__default.default(false) : void 0;
|
|
1023
|
+
}
|
|
1024
|
+
if (propDef.type === "attachment") {
|
|
1025
|
+
if (Array.isArray(rawValue)) {
|
|
1026
|
+
return rawValue.map((a) => chunkN4KFUVWG_cjs.hydrateAttachmentFromRidInternal(client, a.rid));
|
|
1027
|
+
}
|
|
1028
|
+
return chunkN4KFUVWG_cjs.hydrateAttachmentFromRidInternal(client, rawValue.rid);
|
|
1029
|
+
}
|
|
1030
|
+
if (propDef.type === "numericTimeseries" || propDef.type === "stringTimeseries" || propDef.type === "sensorTimeseries") {
|
|
1031
|
+
return new TimeSeriesPropertyImpl(client, objectDef.apiName, rawObject[objectDef.primaryKeyApiName], p);
|
|
1032
|
+
}
|
|
1033
|
+
if (propDef.type === "geotimeSeriesReference") {
|
|
1034
|
+
return new GeotimeSeriesPropertyImpl(client, objectDef.apiName, rawObject[objectDef.primaryKeyApiName], p, rawValue.type === "geotimeSeriesValue" ? {
|
|
1035
|
+
time: rawValue.timestamp,
|
|
1036
|
+
value: {
|
|
1037
|
+
type: "Point",
|
|
1038
|
+
coordinates: rawValue.position
|
|
1039
|
+
}
|
|
1040
|
+
} : void 0);
|
|
1041
|
+
}
|
|
1042
|
+
if (propDef.type === "mediaReference") {
|
|
1043
|
+
return new MediaReferencePropertyImpl({
|
|
1044
|
+
client,
|
|
1045
|
+
objectApiName: objectDef.apiName,
|
|
1046
|
+
primaryKey: rawObject[objectDef.primaryKeyApiName],
|
|
1047
|
+
propertyName: p,
|
|
1048
|
+
mediaReference: rawValue
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// src/object/convertWireToOsdkObjects.ts
|
|
1054
|
+
async function convertWireToOsdkObjects(client, objects, interfaceApiName, forceRemoveRid = false, derivedPropertyTypesByName, selectedProps, strictNonNull = false) {
|
|
1055
|
+
fixObjectPropertiesInPlace(objects, forceRemoveRid);
|
|
1056
|
+
const ifaceDef = interfaceApiName ? await client.ontologyProvider.getInterfaceDefinition(interfaceApiName) : void 0;
|
|
1057
|
+
const ifaceSelected = ifaceDef ? selectedProps ?? Object.keys(ifaceDef.properties) : void 0;
|
|
1058
|
+
const ret = [];
|
|
1059
|
+
for (const rawObj of objects) {
|
|
1060
|
+
const objectDef = await client.ontologyProvider.getObjectDefinition(rawObj.$apiName);
|
|
1061
|
+
!objectDef ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Missing definition for '${rawObj.$apiName}'`) : invariant__default.default(false) : void 0;
|
|
1062
|
+
let objProps;
|
|
1063
|
+
let conforming = true;
|
|
1064
|
+
if (ifaceDef && ifaceSelected) {
|
|
1065
|
+
invariantInterfacesAsViews(objectDef, ifaceDef.apiName, client);
|
|
1066
|
+
conforming &&= isConforming(client, ifaceDef, rawObj, ifaceSelected);
|
|
1067
|
+
reframeAsObjectInPlace(objectDef, ifaceDef.apiName, rawObj);
|
|
1068
|
+
objProps = convertInterfacePropNamesToObjectPropNames(objectDef, ifaceDef.apiName, ifaceSelected);
|
|
1069
|
+
} else {
|
|
1070
|
+
objProps = selectedProps ?? Object.keys(objectDef.properties);
|
|
1071
|
+
}
|
|
1072
|
+
conforming &&= isConforming(client, objectDef, rawObj, objProps);
|
|
1073
|
+
if (strictNonNull === "throw" && !conforming) {
|
|
1074
|
+
throw new Error("Unable to safely convert objects as some non nullable properties are null");
|
|
1075
|
+
} else if (strictNonNull === "drop" && !conforming) {
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
let osdkObject = createOsdkObject(client, objectDef, rawObj, derivedPropertyTypesByName);
|
|
1079
|
+
if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);
|
|
1080
|
+
ret.push(osdkObject);
|
|
1081
|
+
}
|
|
1082
|
+
return ret;
|
|
1083
|
+
}
|
|
1084
|
+
async function convertWireToOsdkObjects2(client, objects, interfaceApiName, derivedPropertyTypeByName, forceRemoveRid = false, selectedProps, strictNonNull = false, interfaceToObjectTypeMappings = {}) {
|
|
1085
|
+
fixObjectPropertiesInPlace(objects, forceRemoveRid);
|
|
1086
|
+
const ret = [];
|
|
1087
|
+
for (const rawObj of objects) {
|
|
1088
|
+
const objectDef = await client.ontologyProvider.getObjectDefinition(rawObj.$apiName);
|
|
1089
|
+
!objectDef ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, `Missing definition for '${rawObj.$apiName}'`) : invariant__default.default(false) : void 0;
|
|
1090
|
+
const interfaceToObjMapping = interfaceApiName ? interfaceToObjectTypeMappings[interfaceApiName][rawObj.$apiName] : void 0;
|
|
1091
|
+
const ifaceSelected = interfaceApiName && interfaceToObjMapping ? selectedProps ? Object.keys(interfaceToObjMapping).filter((val) => {
|
|
1092
|
+
selectedProps?.includes(interfaceToObjMapping[val]);
|
|
1093
|
+
}) : [...Object.values(interfaceToObjMapping), objectDef.primaryKeyApiName] : void 0;
|
|
1094
|
+
let objProps;
|
|
1095
|
+
let conforming = true;
|
|
1096
|
+
if (interfaceApiName && ifaceSelected) {
|
|
1097
|
+
invariantInterfacesAsViews(objectDef, interfaceApiName, client);
|
|
1098
|
+
objProps = ifaceSelected;
|
|
1099
|
+
} else {
|
|
1100
|
+
objProps = selectedProps ?? Object.keys(objectDef.properties);
|
|
1101
|
+
}
|
|
1102
|
+
conforming &&= isConforming(client, objectDef, rawObj, objProps);
|
|
1103
|
+
if (strictNonNull === "throw" && !conforming) {
|
|
1104
|
+
throw new Error("Unable to safely convert objects as some non nullable properties are null");
|
|
1105
|
+
} else if (strictNonNull === "drop" && !conforming) {
|
|
1106
|
+
continue;
|
|
1107
|
+
}
|
|
1108
|
+
let osdkObject = createOsdkObject(client, objectDef, rawObj, derivedPropertyTypeByName);
|
|
1109
|
+
if (interfaceApiName) osdkObject = osdkObject.$as(interfaceApiName);
|
|
1110
|
+
ret.push(osdkObject);
|
|
1111
|
+
}
|
|
1112
|
+
return ret;
|
|
1113
|
+
}
|
|
1114
|
+
function convertInterfacePropNamesToObjectPropNames(objectDef, interfaceApiName, ifacePropsToMap) {
|
|
1115
|
+
return ifacePropsToMap.map((ifaceProp) => objectDef.interfaceMap[interfaceApiName][ifaceProp]);
|
|
1116
|
+
}
|
|
1117
|
+
function reframeAsObjectInPlace(objectDef, interfaceApiName, rawObj) {
|
|
1118
|
+
const newProps = {};
|
|
1119
|
+
for (const [sptProp, regularProp] of Object.entries(objectDef.interfaceMap[interfaceApiName])) {
|
|
1120
|
+
if (sptProp in rawObj) {
|
|
1121
|
+
const value = rawObj[sptProp];
|
|
1122
|
+
delete rawObj[sptProp];
|
|
1123
|
+
if (value !== void 0) {
|
|
1124
|
+
newProps[regularProp] = value;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
Object.assign(rawObj, newProps);
|
|
1129
|
+
if (!(objectDef.primaryKeyApiName in rawObj)) {
|
|
1130
|
+
rawObj[objectDef.primaryKeyApiName] = rawObj.$primaryKey;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
function isConforming(client, def, obj, propsToCheck) {
|
|
1134
|
+
for (const propName of propsToCheck) {
|
|
1135
|
+
if (propName in def.properties && def.properties[propName].nullable === false && obj[propName] == null) {
|
|
1136
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1137
|
+
client.logger?.debug({
|
|
1138
|
+
obj: {
|
|
1139
|
+
$apiName: obj["$apiName"],
|
|
1140
|
+
$objectType: obj["$objectType"],
|
|
1141
|
+
$primaryKey: obj["$primaryKey"]
|
|
1142
|
+
}
|
|
1143
|
+
}, `Found object that does not conform to its definition. Expected ${def.apiName}'s ${propName} to not be null.`);
|
|
1144
|
+
}
|
|
1145
|
+
return false;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
return true;
|
|
1149
|
+
}
|
|
1150
|
+
function invariantInterfacesAsViews(objectDef, interfaceApiName, client) {
|
|
1151
|
+
if (objectDef.interfaceMap?.[interfaceApiName] == null) {
|
|
1152
|
+
const warning = "Interfaces are only supported 'as views' but your metadata object is missing the correct information. This suggests your interfaces have not been migrated to the newer version yet and you cannot use this version of the SDK.";
|
|
1153
|
+
if (client.logger) {
|
|
1154
|
+
client.logger.warn(warning);
|
|
1155
|
+
} else {
|
|
1156
|
+
console.error(`WARNING! ${warning}`);
|
|
1157
|
+
}
|
|
1158
|
+
throw new Error(warning);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
function fixObjectPropertiesInPlace(objs, forceRemoveRid) {
|
|
1162
|
+
for (const obj of objs) {
|
|
1163
|
+
if (forceRemoveRid) {
|
|
1164
|
+
delete obj.__rid;
|
|
1165
|
+
}
|
|
1166
|
+
if (obj.__rid) {
|
|
1167
|
+
obj.$rid = obj.__rid;
|
|
1168
|
+
delete obj.__rid;
|
|
1169
|
+
}
|
|
1170
|
+
obj.$apiName ??= obj.__apiName;
|
|
1171
|
+
obj.$objectType = obj.$apiName;
|
|
1172
|
+
obj.$primaryKey ??= obj.__primaryKey;
|
|
1173
|
+
obj.$title ??= obj.__title;
|
|
1174
|
+
delete obj.__apiName;
|
|
1175
|
+
delete obj.__primaryKey;
|
|
1176
|
+
delete obj.__title;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// src/object/Cache.ts
|
|
1181
|
+
function createClientCache(fn) {
|
|
1182
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
1183
|
+
function get(client, key) {
|
|
1184
|
+
if (cache.get(client.clientCacheKey) == null) {
|
|
1185
|
+
cache.set(client.clientCacheKey, /* @__PURE__ */ new Map());
|
|
1186
|
+
}
|
|
1187
|
+
let r = cache.get(client.clientCacheKey).get(key);
|
|
1188
|
+
if (r === void 0 && fn !== void 0) {
|
|
1189
|
+
return set(client, key, fn(client, key));
|
|
1190
|
+
} else {
|
|
1191
|
+
return r;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
function set(client, key, value) {
|
|
1195
|
+
if (cache.get(client.clientCacheKey) == null) {
|
|
1196
|
+
cache.set(client.clientCacheKey, /* @__PURE__ */ new Map());
|
|
1197
|
+
}
|
|
1198
|
+
cache.get(client.clientCacheKey).set(key, value);
|
|
1199
|
+
return value;
|
|
1200
|
+
}
|
|
1201
|
+
function remove(client, key) {
|
|
1202
|
+
if (cache.get(client.clientCacheKey) == null) return false;
|
|
1203
|
+
return cache.get(client.clientCacheKey).delete(key);
|
|
1204
|
+
}
|
|
1205
|
+
return {
|
|
1206
|
+
get,
|
|
1207
|
+
set,
|
|
1208
|
+
remove
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
function createAsyncClientCache(fn, createCacheLocal = createClientCache) {
|
|
1212
|
+
const cache = createCacheLocal();
|
|
1213
|
+
const inProgress = createCacheLocal();
|
|
1214
|
+
const ret = {
|
|
1215
|
+
getOrUndefined: function getOrUndefined(client, key) {
|
|
1216
|
+
return cache.get(client, key);
|
|
1217
|
+
},
|
|
1218
|
+
get: async function get(client, key) {
|
|
1219
|
+
return cache.get(client, key) ?? inProgress.get(client, key) ?? ret.set(client, key, fn(client, key));
|
|
1220
|
+
},
|
|
1221
|
+
set: async function set(client, k, v) {
|
|
1222
|
+
try {
|
|
1223
|
+
const r = await inProgress.set(client, k, v);
|
|
1224
|
+
cache.set(client, k, r);
|
|
1225
|
+
inProgress.remove(client, k);
|
|
1226
|
+
return r;
|
|
1227
|
+
} catch (e) {
|
|
1228
|
+
inProgress.remove(client, k);
|
|
1229
|
+
throw e;
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
return ret;
|
|
1234
|
+
}
|
|
1235
|
+
async function loadActionMetadata(client, actionType) {
|
|
1236
|
+
const r = await chunkN4KFUVWG_cjs.ActionTypeV2_exports.get(client, await client.ontologyRid, actionType);
|
|
1237
|
+
return generatorConverters.wireActionTypeV2ToSdkActionMetadata(r);
|
|
1238
|
+
}
|
|
1239
|
+
async function loadFullObjectMetadata(client, objectType) {
|
|
1240
|
+
const full = await chunkN4KFUVWG_cjs.ObjectTypeV2_exports.getFullMetadata(client, await client.ontologyRid, objectType, {
|
|
1241
|
+
preview: true
|
|
1242
|
+
});
|
|
1243
|
+
const ret = generatorConverters.wireObjectTypeFullMetadataToSdkObjectMetadata(full, true);
|
|
1244
|
+
return {
|
|
1245
|
+
...ret
|
|
1246
|
+
};
|
|
1247
|
+
}
|
|
1248
|
+
async function loadInterfaceMetadata(client, objectType) {
|
|
1249
|
+
const r = await chunkN4KFUVWG_cjs.OntologyInterface_exports.get(client, await client.ontologyRid, objectType, {
|
|
1250
|
+
preview: true
|
|
1251
|
+
});
|
|
1252
|
+
return generatorConverters.__UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(r, true);
|
|
1253
|
+
}
|
|
1254
|
+
async function loadQueryMetadata(client, queryTypeApiNameAndVersion) {
|
|
1255
|
+
const [apiName, version] = queryTypeApiNameAndVersion.split(":");
|
|
1256
|
+
const r = await chunkN4KFUVWG_cjs.QueryType_exports.get(client, await client.ontologyRid, apiName, {
|
|
1257
|
+
version
|
|
1258
|
+
});
|
|
1259
|
+
return generatorConverters.wireQueryTypeV2ToSdkQueryMetadata(r);
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// src/ontology/StandardOntologyProvider.ts
|
|
1263
|
+
var createStandardOntologyProviderFactory = (client) => {
|
|
1264
|
+
return (client2) => {
|
|
1265
|
+
async function loadObject(client3, key) {
|
|
1266
|
+
const objectDef = await loadFullObjectMetadata(client3, key);
|
|
1267
|
+
const interfaceDefs = Object.fromEntries((await Promise.all(objectDef.implements?.map((i) => ret.getInterfaceDefinition(i)) ?? [])).map((i) => [i.apiName, {
|
|
1268
|
+
def: i,
|
|
1269
|
+
handler: void 0
|
|
1270
|
+
}]));
|
|
1271
|
+
const fullObjectDef = {
|
|
1272
|
+
...objectDef,
|
|
1273
|
+
[InterfaceDefinitions]: interfaceDefs
|
|
1274
|
+
};
|
|
1275
|
+
return fullObjectDef;
|
|
1276
|
+
}
|
|
1277
|
+
async function loadInterface(client3, key) {
|
|
1278
|
+
return loadInterfaceMetadata(client3, key);
|
|
1279
|
+
}
|
|
1280
|
+
async function loadQuery(client3, key) {
|
|
1281
|
+
return loadQueryMetadata(client3, key);
|
|
1282
|
+
}
|
|
1283
|
+
async function loadAction(client3, key) {
|
|
1284
|
+
const r = await loadActionMetadata(client3, key);
|
|
1285
|
+
return r;
|
|
1286
|
+
}
|
|
1287
|
+
function makeGetter(fn) {
|
|
1288
|
+
const cache = createAsyncClientCache((client3, key) => fn(client3, key, false));
|
|
1289
|
+
return async (apiName) => {
|
|
1290
|
+
return await cache.get(client2, apiName);
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
function makeQueryGetter(client3, fn) {
|
|
1294
|
+
const queryCache = createAsyncClientCache((client4, key) => {
|
|
1295
|
+
return fn(client4, key);
|
|
1296
|
+
});
|
|
1297
|
+
return async (apiName, version) => {
|
|
1298
|
+
const key = version ? `${apiName}:${version}` : apiName;
|
|
1299
|
+
return await queryCache.get(client3, key);
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
const ret = {
|
|
1303
|
+
getObjectDefinition: makeGetter(loadObject),
|
|
1304
|
+
getInterfaceDefinition: makeGetter(loadInterface),
|
|
1305
|
+
getActionDefinition: makeGetter(loadAction),
|
|
1306
|
+
getQueryDefinition: makeQueryGetter(client2, loadQuery)
|
|
1307
|
+
};
|
|
1308
|
+
return ret;
|
|
1309
|
+
};
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
// src/util/UserAgent.ts
|
|
1313
|
+
var USER_AGENT = `osdk-client/${"2.3.0-beta.6"}`;
|
|
1314
|
+
var OBSERVABLE_USER_AGENT = `osdk-observable-client/${"2.3.0-beta.6"}`;
|
|
1315
|
+
|
|
1316
|
+
// src/createMinimalClient.ts
|
|
1317
|
+
function createMinimalClient(metadata, baseUrl, tokenProvider, options = {}, fetchFn = global.fetch, objectSetFactory = chunkN4KFUVWG_cjs.createObjectSet, createOntologyProviderFactory = createStandardOntologyProviderFactory) {
|
|
1318
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1319
|
+
try {
|
|
1320
|
+
new URL(baseUrl);
|
|
1321
|
+
} catch (e) {
|
|
1322
|
+
const hint = !baseUrl.startsWith("http://") || !baseUrl.startsWith("https://") ? ". Did you forget to add 'http://' or 'https://'?" : "";
|
|
1323
|
+
throw new Error(`Invalid stack URL: ${baseUrl}${hint}`);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
const processedBaseUrl = new URL(baseUrl);
|
|
1327
|
+
processedBaseUrl.pathname += processedBaseUrl.pathname.endsWith("/") ? "" : "/";
|
|
1328
|
+
const minimalClient = {
|
|
1329
|
+
...shared_client_impl.createSharedClientContext(processedBaseUrl.toString(), tokenProvider, USER_AGENT, fetchFn),
|
|
1330
|
+
objectSetFactory,
|
|
1331
|
+
objectFactory: convertWireToOsdkObjects,
|
|
1332
|
+
objectFactory2: convertWireToOsdkObjects2,
|
|
1333
|
+
ontologyRid: metadata.ontologyRid,
|
|
1334
|
+
logger: options.logger,
|
|
1335
|
+
clientCacheKey: {},
|
|
1336
|
+
requestContext: {}
|
|
1337
|
+
};
|
|
1338
|
+
return Object.freeze(Object.assign(minimalClient, {
|
|
1339
|
+
ontologyProvider: createOntologyProviderFactory(options)(minimalClient)
|
|
1340
|
+
}));
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// src/fetchMetadata.ts
|
|
1344
|
+
var fetchMetadataInternal = async (client, definition) => {
|
|
1345
|
+
if (definition.type === "object") {
|
|
1346
|
+
const {
|
|
1347
|
+
[InterfaceDefinitions]: interfaceDefs,
|
|
1348
|
+
...objectTypeDef
|
|
1349
|
+
} = await client.ontologyProvider.getObjectDefinition(definition.apiName);
|
|
1350
|
+
return objectTypeDef;
|
|
1351
|
+
} else if (definition.type === "interface") {
|
|
1352
|
+
return client.ontologyProvider.getInterfaceDefinition(definition.apiName);
|
|
1353
|
+
} else if (definition.type === "action") {
|
|
1354
|
+
return client.ontologyProvider.getActionDefinition(definition.apiName);
|
|
1355
|
+
} else if (definition.type === "query") {
|
|
1356
|
+
return client.ontologyProvider.getQueryDefinition(definition.apiName, definition.isFixedVersion ? definition.version : void 0);
|
|
1357
|
+
} else {
|
|
1358
|
+
throw new Error("Not implemented for given definition");
|
|
1359
|
+
}
|
|
1360
|
+
};
|
|
1361
|
+
|
|
1362
|
+
// src/util/toDataValueQueries.ts
|
|
1363
|
+
async function toDataValueQueries(value, client, desiredType) {
|
|
1364
|
+
if (value == null) {
|
|
1365
|
+
return value;
|
|
1366
|
+
}
|
|
1367
|
+
if (Array.isArray(value) && desiredType.multiplicity) {
|
|
1368
|
+
const values = Array.from(value);
|
|
1369
|
+
if (values.some((dataValue) => isAttachmentUpload(dataValue) || isAttachmentFile(dataValue))) {
|
|
1370
|
+
const converted = [];
|
|
1371
|
+
for (const value2 of values) {
|
|
1372
|
+
converted.push(await toDataValueQueries(value2, client, desiredType));
|
|
1373
|
+
}
|
|
1374
|
+
return converted;
|
|
1375
|
+
}
|
|
1376
|
+
const promiseArray = Array.from(value, async (innerValue) => await toDataValueQueries(innerValue, client, desiredType));
|
|
1377
|
+
return Promise.all(promiseArray);
|
|
1378
|
+
}
|
|
1379
|
+
switch (desiredType.type) {
|
|
1380
|
+
case "attachment": {
|
|
1381
|
+
if (isAttachmentUpload(value)) {
|
|
1382
|
+
const attachment = await chunkN4KFUVWG_cjs.Attachment_exports.upload(client, value.data, {
|
|
1383
|
+
filename: value.name
|
|
1384
|
+
});
|
|
1385
|
+
return attachment.rid;
|
|
1386
|
+
}
|
|
1387
|
+
if (isAttachmentFile(value)) {
|
|
1388
|
+
const attachment = await chunkN4KFUVWG_cjs.Attachment_exports.upload(client, value, {
|
|
1389
|
+
filename: value.name
|
|
1390
|
+
});
|
|
1391
|
+
return attachment.rid;
|
|
1392
|
+
}
|
|
1393
|
+
return value;
|
|
1394
|
+
}
|
|
1395
|
+
case "twoDimensionalAggregation": {
|
|
1396
|
+
return {
|
|
1397
|
+
groups: value
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
case "threeDimensionalAggregation": {
|
|
1401
|
+
return {
|
|
1402
|
+
groups: value
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
case "set": {
|
|
1406
|
+
if (value instanceof Set) {
|
|
1407
|
+
const promiseArray = Array.from(value, async (innerValue) => await toDataValueQueries(innerValue, client, desiredType["set"]));
|
|
1408
|
+
return Promise.all(promiseArray);
|
|
1409
|
+
}
|
|
1410
|
+
break;
|
|
1411
|
+
}
|
|
1412
|
+
case "object": {
|
|
1413
|
+
if (isObjectSpecifiersObject(value)) {
|
|
1414
|
+
return value.$primaryKey;
|
|
1415
|
+
}
|
|
1416
|
+
break;
|
|
1417
|
+
}
|
|
1418
|
+
case "objectSet": {
|
|
1419
|
+
if (chunkN4KFUVWG_cjs.isWireObjectSet(value)) {
|
|
1420
|
+
return value;
|
|
1421
|
+
}
|
|
1422
|
+
if (chunkN4KFUVWG_cjs.isObjectSet(value)) {
|
|
1423
|
+
return chunkN4KFUVWG_cjs.getWireObjectSet(value);
|
|
1424
|
+
}
|
|
1425
|
+
break;
|
|
1426
|
+
}
|
|
1427
|
+
case "map": {
|
|
1428
|
+
if (typeof value === "object") {
|
|
1429
|
+
const entrySet = [];
|
|
1430
|
+
for (const [key, mapValue] of Object.entries(value)) {
|
|
1431
|
+
entrySet.push({
|
|
1432
|
+
key: desiredType.keyType.type === "object" ? extractPrimaryKeyFromObjectSpecifier(key) : await toDataValueQueries(key, client, desiredType.keyType),
|
|
1433
|
+
value: await toDataValueQueries(mapValue, client, desiredType.valueType)
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
return entrySet;
|
|
1437
|
+
}
|
|
1438
|
+
break;
|
|
1439
|
+
}
|
|
1440
|
+
case "struct": {
|
|
1441
|
+
if (typeof value === "object") {
|
|
1442
|
+
const structMap = {};
|
|
1443
|
+
for (const [key, structValue] of Object.entries(value)) {
|
|
1444
|
+
structMap[key] = await toDataValueQueries(structValue, client, desiredType["struct"][key]);
|
|
1445
|
+
}
|
|
1446
|
+
return structMap;
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
case "boolean":
|
|
1450
|
+
case "date":
|
|
1451
|
+
case "double":
|
|
1452
|
+
case "float":
|
|
1453
|
+
case "integer":
|
|
1454
|
+
case "long":
|
|
1455
|
+
case "string":
|
|
1456
|
+
case "timestamp":
|
|
1457
|
+
return value;
|
|
1458
|
+
}
|
|
1459
|
+
return value;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
// src/queries/applyQuery.ts
|
|
1463
|
+
async function applyQuery(client, query, params) {
|
|
1464
|
+
const qd = await client.ontologyProvider.getQueryDefinition(query.apiName, query.isFixedVersion ? query.version : void 0);
|
|
1465
|
+
const response = await chunkN4KFUVWG_cjs.Query_exports.execute(chunkN4KFUVWG_cjs.addUserAgentAndRequestContextHeaders(chunkN4KFUVWG_cjs.augmentRequestContext(client, (_) => ({
|
|
1466
|
+
finalMethodCall: "applyQuery"
|
|
1467
|
+
})), query), await client.ontologyRid, query.apiName, {
|
|
1468
|
+
parameters: params ? await remapQueryParams(params, client, qd.parameters) : {}
|
|
1469
|
+
}, {
|
|
1470
|
+
version: qd.version
|
|
1471
|
+
});
|
|
1472
|
+
const objectOutputDefs = await getRequiredDefinitions(qd.output, client);
|
|
1473
|
+
const remappedResponse = await remapQueryResponse(client, qd.output, response.value, objectOutputDefs);
|
|
1474
|
+
return remappedResponse;
|
|
1475
|
+
}
|
|
1476
|
+
async function remapQueryParams(params, client, paramTypes) {
|
|
1477
|
+
const parameterMap = {};
|
|
1478
|
+
for (const [key, value] of Object.entries(params)) {
|
|
1479
|
+
parameterMap[key] = await toDataValueQueries(value, client, paramTypes[key]);
|
|
1480
|
+
}
|
|
1481
|
+
return parameterMap;
|
|
1482
|
+
}
|
|
1483
|
+
async function remapQueryResponse(client, responseDataType, responseValue, definitions) {
|
|
1484
|
+
if (responseValue == null) {
|
|
1485
|
+
if (responseDataType.nullable) {
|
|
1486
|
+
return void 0;
|
|
1487
|
+
} else {
|
|
1488
|
+
throw new Error("Got null response when nullable was not allowed");
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
if (responseDataType.multiplicity != null && responseDataType.multiplicity) {
|
|
1492
|
+
const withoutMultiplicity = {
|
|
1493
|
+
...responseDataType,
|
|
1494
|
+
multiplicity: false
|
|
1495
|
+
};
|
|
1496
|
+
for (let i = 0; i < responseValue.length; i++) {
|
|
1497
|
+
responseValue[i] = await remapQueryResponse(client, withoutMultiplicity, responseValue[i], definitions);
|
|
1498
|
+
}
|
|
1499
|
+
return responseValue;
|
|
1500
|
+
}
|
|
1501
|
+
switch (responseDataType.type) {
|
|
1502
|
+
case "union": {
|
|
1503
|
+
throw new Error("Union return types are not yet supported");
|
|
1504
|
+
}
|
|
1505
|
+
case "set": {
|
|
1506
|
+
for (let i = 0; i < responseValue.length; i++) {
|
|
1507
|
+
responseValue[i] = await remapQueryResponse(client, responseDataType.set, responseValue[i], definitions);
|
|
1508
|
+
}
|
|
1509
|
+
return responseValue;
|
|
1510
|
+
}
|
|
1511
|
+
case "attachment": {
|
|
1512
|
+
return chunkN4KFUVWG_cjs.hydrateAttachmentFromRidInternal(client, responseValue);
|
|
1513
|
+
}
|
|
1514
|
+
case "object": {
|
|
1515
|
+
const def = definitions.get(responseDataType.object);
|
|
1516
|
+
if (!def || def.type !== "object") {
|
|
1517
|
+
throw new Error(`Missing definition for ${responseDataType.object}`);
|
|
1518
|
+
}
|
|
1519
|
+
return createQueryObjectResponse(responseValue, def);
|
|
1520
|
+
}
|
|
1521
|
+
case "objectSet": {
|
|
1522
|
+
const def = definitions.get(responseDataType.objectSet);
|
|
1523
|
+
if (!def) {
|
|
1524
|
+
throw new Error(`Missing definition for ${responseDataType.objectSet}`);
|
|
1525
|
+
}
|
|
1526
|
+
if (typeof responseValue === "string") {
|
|
1527
|
+
return chunkN4KFUVWG_cjs.createObjectSet(def, client, {
|
|
1528
|
+
type: "intersect",
|
|
1529
|
+
objectSets: [{
|
|
1530
|
+
type: "base",
|
|
1531
|
+
objectType: responseDataType.objectSet
|
|
1532
|
+
}, {
|
|
1533
|
+
type: "reference",
|
|
1534
|
+
reference: responseValue
|
|
1535
|
+
}]
|
|
1536
|
+
});
|
|
1537
|
+
}
|
|
1538
|
+
return chunkN4KFUVWG_cjs.createObjectSet(def, client, responseValue);
|
|
1539
|
+
}
|
|
1540
|
+
case "struct": {
|
|
1541
|
+
for (const [key, subtype] of Object.entries(responseDataType.struct)) {
|
|
1542
|
+
if (requiresConversion(subtype)) {
|
|
1543
|
+
responseValue[key] = await remapQueryResponse(client, subtype, responseValue[key], definitions);
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
return responseValue;
|
|
1547
|
+
}
|
|
1548
|
+
case "map": {
|
|
1549
|
+
const map = {};
|
|
1550
|
+
!Array.isArray(responseValue) ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Expected array entry") : invariant__default.default(false) : void 0;
|
|
1551
|
+
for (const entry of responseValue) {
|
|
1552
|
+
!entry.key ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Expected key") : invariant__default.default(false) : void 0;
|
|
1553
|
+
!entry.value ? process.env.NODE_ENV !== "production" ? invariant__default.default(false, "Expected value") : invariant__default.default(false) : void 0;
|
|
1554
|
+
const key = responseDataType.keyType.type === "object" ? getObjectSpecifier(entry.key, responseDataType.keyType.object, definitions) : entry.key;
|
|
1555
|
+
const value = await remapQueryResponse(client, responseDataType.valueType, entry.value, definitions);
|
|
1556
|
+
map[key] = value;
|
|
1557
|
+
}
|
|
1558
|
+
return map;
|
|
1559
|
+
}
|
|
1560
|
+
case "twoDimensionalAggregation": {
|
|
1561
|
+
const result = [];
|
|
1562
|
+
for (const {
|
|
1563
|
+
key,
|
|
1564
|
+
value
|
|
1565
|
+
} of responseValue.groups) {
|
|
1566
|
+
result.push({
|
|
1567
|
+
key,
|
|
1568
|
+
value
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
return result;
|
|
1572
|
+
}
|
|
1573
|
+
case "threeDimensionalAggregation": {
|
|
1574
|
+
const result = [];
|
|
1575
|
+
for (const {
|
|
1576
|
+
key,
|
|
1577
|
+
groups
|
|
1578
|
+
} of responseValue.groups) {
|
|
1579
|
+
const subResult = [];
|
|
1580
|
+
for (const {
|
|
1581
|
+
key: subKey,
|
|
1582
|
+
value
|
|
1583
|
+
} of groups) {
|
|
1584
|
+
subResult.push({
|
|
1585
|
+
key: subKey,
|
|
1586
|
+
value
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
result.push({
|
|
1590
|
+
key,
|
|
1591
|
+
groups: subResult
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
return result;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
return responseValue;
|
|
1598
|
+
}
|
|
1599
|
+
async function getRequiredDefinitions(dataType, client) {
|
|
1600
|
+
const result = /* @__PURE__ */ new Map();
|
|
1601
|
+
switch (dataType.type) {
|
|
1602
|
+
case "objectSet": {
|
|
1603
|
+
const objectDef = await client.ontologyProvider.getObjectDefinition(dataType.objectSet);
|
|
1604
|
+
result.set(dataType.objectSet, objectDef);
|
|
1605
|
+
break;
|
|
1606
|
+
}
|
|
1607
|
+
case "object": {
|
|
1608
|
+
const objectDef = await client.ontologyProvider.getObjectDefinition(dataType.object);
|
|
1609
|
+
result.set(dataType.object, objectDef);
|
|
1610
|
+
break;
|
|
1611
|
+
}
|
|
1612
|
+
case "set": {
|
|
1613
|
+
return getRequiredDefinitions(dataType.set, client);
|
|
1614
|
+
}
|
|
1615
|
+
case "map": {
|
|
1616
|
+
for (const value of [dataType.keyType, dataType.valueType]) {
|
|
1617
|
+
for (const [type, objectDef] of await getRequiredDefinitions(value, client)) {
|
|
1618
|
+
result.set(type, objectDef);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
break;
|
|
1622
|
+
}
|
|
1623
|
+
case "struct": {
|
|
1624
|
+
for (const value of Object.values(dataType.struct)) {
|
|
1625
|
+
for (const [type, objectDef] of await getRequiredDefinitions(value, client)) {
|
|
1626
|
+
result.set(type, objectDef);
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
break;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
return result;
|
|
1633
|
+
}
|
|
1634
|
+
function requiresConversion(dataType) {
|
|
1635
|
+
switch (dataType.type) {
|
|
1636
|
+
case "boolean":
|
|
1637
|
+
case "date":
|
|
1638
|
+
case "double":
|
|
1639
|
+
case "float":
|
|
1640
|
+
case "integer":
|
|
1641
|
+
case "long":
|
|
1642
|
+
case "string":
|
|
1643
|
+
case "timestamp":
|
|
1644
|
+
return false;
|
|
1645
|
+
case "union":
|
|
1646
|
+
return true;
|
|
1647
|
+
case "struct":
|
|
1648
|
+
return Object.values(dataType.struct).some(requiresConversion);
|
|
1649
|
+
case "set":
|
|
1650
|
+
return requiresConversion(dataType.set);
|
|
1651
|
+
case "attachment":
|
|
1652
|
+
case "objectSet":
|
|
1653
|
+
case "twoDimensionalAggregation":
|
|
1654
|
+
case "threeDimensionalAggregation":
|
|
1655
|
+
case "object":
|
|
1656
|
+
return true;
|
|
1657
|
+
default:
|
|
1658
|
+
return false;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
function getObjectSpecifier(primaryKey, objectTypeApiName, definitions) {
|
|
1662
|
+
const def = definitions.get(objectTypeApiName);
|
|
1663
|
+
if (!def || def.type !== "object") {
|
|
1664
|
+
throw new Error(`Missing definition for ${objectTypeApiName}`);
|
|
1665
|
+
}
|
|
1666
|
+
return createObjectSpecifierFromPrimaryKey(def, primaryKey);
|
|
1667
|
+
}
|
|
1668
|
+
function createQueryObjectResponse(primaryKey, objectDef) {
|
|
1669
|
+
return {
|
|
1670
|
+
$apiName: objectDef.apiName,
|
|
1671
|
+
$title: void 0,
|
|
1672
|
+
$objectType: objectDef.apiName,
|
|
1673
|
+
$primaryKey: primaryKey,
|
|
1674
|
+
$objectSpecifier: createObjectSpecifierFromPrimaryKey(objectDef, primaryKey)
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
// src/createClient.ts
|
|
1679
|
+
var ActionInvoker = class {
|
|
1680
|
+
constructor(clientCtx, actionDef) {
|
|
1681
|
+
this.applyAction = applyAction.bind(void 0, clientCtx, actionDef);
|
|
1682
|
+
this.batchApplyAction = applyAction.bind(void 0, clientCtx, actionDef);
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
var QueryInvoker = class {
|
|
1686
|
+
constructor(clientCtx, queryDef) {
|
|
1687
|
+
this.executeFunction = applyQuery.bind(void 0, clientCtx, queryDef);
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
function createClientInternal(objectSetFactory, baseUrl, ontologyRid, tokenProvider, options = void 0, fetchFn = fetch) {
|
|
1691
|
+
if (typeof ontologyRid === "string") {
|
|
1692
|
+
if (!ontologyRid.startsWith("ri.")) {
|
|
1693
|
+
throw new Error("Invalid ontology RID");
|
|
1694
|
+
}
|
|
1695
|
+
} else {
|
|
1696
|
+
ontologyRid.then((ontologyRid2) => {
|
|
1697
|
+
if (!ontologyRid2.startsWith("ri.")) {
|
|
1698
|
+
throw new Error("Invalid ontology RID");
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
const clientCtx = createMinimalClient({
|
|
1703
|
+
ontologyRid
|
|
1704
|
+
}, baseUrl, tokenProvider, {
|
|
1705
|
+
...options,
|
|
1706
|
+
logger: options?.logger ?? new chunkN4KFUVWG_cjs.MinimalLogger()
|
|
1707
|
+
}, fetchFn, objectSetFactory);
|
|
1708
|
+
return createClientFromContext(clientCtx);
|
|
1709
|
+
}
|
|
1710
|
+
function createClientFromContext(clientCtx) {
|
|
1711
|
+
function clientFn(o) {
|
|
1712
|
+
if (o.type === "object" || o.type === "interface") {
|
|
1713
|
+
return clientCtx.objectSetFactory(o, clientCtx);
|
|
1714
|
+
} else if (o.type === "action") {
|
|
1715
|
+
return new ActionInvoker(clientCtx, o);
|
|
1716
|
+
} else if (o.type === "query") {
|
|
1717
|
+
return new QueryInvoker(clientCtx, o);
|
|
1718
|
+
} else if (o.type === "experiment") {
|
|
1719
|
+
switch (o.name) {
|
|
1720
|
+
case unstable.__EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks.name:
|
|
1721
|
+
return {
|
|
1722
|
+
getBulkLinks: createBulkLinksAsyncIterFactory(clientCtx)
|
|
1723
|
+
};
|
|
1724
|
+
case unstable.__EXPERIMENTAL__NOT_SUPPORTED_YET__fetchOneByRid.name:
|
|
1725
|
+
return {
|
|
1726
|
+
fetchOneByRid: async (objectType, rid, options) => {
|
|
1727
|
+
return await chunkN4KFUVWG_cjs.fetchSingle(clientCtx, objectType, options, createWithRid([rid]));
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
case unstable.__EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference.name:
|
|
1731
|
+
return {
|
|
1732
|
+
createMediaReference: async (args) => {
|
|
1733
|
+
const {
|
|
1734
|
+
data,
|
|
1735
|
+
fileName,
|
|
1736
|
+
objectType,
|
|
1737
|
+
propertyType
|
|
1738
|
+
} = args;
|
|
1739
|
+
return await chunkN4KFUVWG_cjs.MediaReferenceProperty_exports.upload(clientCtx, await clientCtx.ontologyRid, objectType.apiName, propertyType, data, {
|
|
1740
|
+
mediaItemPath: fileName,
|
|
1741
|
+
preview: true
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
case unstable.__EXPERIMENTAL__NOT_SUPPORTED_YET__fetchPageByRid.name:
|
|
1746
|
+
return {
|
|
1747
|
+
fetchPageByRid: async (objectOrInterfaceType, rids, options = {}) => {
|
|
1748
|
+
return await chunkN4KFUVWG_cjs.fetchPage(clientCtx, objectOrInterfaceType, options, createWithRid(rids));
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
throw new Error("not implemented");
|
|
1753
|
+
} else {
|
|
1754
|
+
throw new Error("not implemented");
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
const fetchMetadata = fetchMetadataInternal.bind(void 0, clientCtx);
|
|
1758
|
+
const symbolClientContext2 = "__osdkClientContext";
|
|
1759
|
+
const client = Object.defineProperties(clientFn, {
|
|
1760
|
+
[chunkN4KFUVWG_cjs.symbolClientContext]: {
|
|
1761
|
+
value: clientCtx
|
|
1762
|
+
},
|
|
1763
|
+
[symbolClientContext2]: {
|
|
1764
|
+
value: clientCtx
|
|
1765
|
+
},
|
|
1766
|
+
[chunkN4KFUVWG_cjs.additionalContext]: {
|
|
1767
|
+
value: clientCtx
|
|
1768
|
+
},
|
|
1769
|
+
fetchMetadata: {
|
|
1770
|
+
value: fetchMetadata
|
|
1771
|
+
}
|
|
1772
|
+
});
|
|
1773
|
+
return client;
|
|
1774
|
+
}
|
|
1775
|
+
var createClient = createClientInternal.bind(void 0, chunkN4KFUVWG_cjs.createObjectSet);
|
|
1776
|
+
function createWithRid(rids) {
|
|
1777
|
+
const withRid = {
|
|
1778
|
+
type: "static",
|
|
1779
|
+
"objects": rids
|
|
1780
|
+
};
|
|
1781
|
+
return withRid;
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
exports.ActionValidationError = ActionValidationError;
|
|
1785
|
+
exports.OBSERVABLE_USER_AGENT = OBSERVABLE_USER_AGENT;
|
|
1786
|
+
exports.ObjectDefRef = ObjectDefRef;
|
|
1787
|
+
exports.USER_AGENT = USER_AGENT;
|
|
1788
|
+
exports.UnderlyingOsdkObject = UnderlyingOsdkObject;
|
|
1789
|
+
exports.createAttachmentUpload = createAttachmentUpload;
|
|
1790
|
+
exports.createClient = createClient;
|
|
1791
|
+
exports.createClientFromContext = createClientFromContext;
|
|
1792
|
+
//# sourceMappingURL=chunk-DHPFI5ZJ.cjs.map
|
|
1793
|
+
//# sourceMappingURL=chunk-DHPFI5ZJ.cjs.map
|