@osdk/client 2.0.0-beta.11 → 2.0.0-beta.13
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 +41 -0
- package/build/browser/{chunk-WGFCR4UM.js → chunk-CG25K4WC.js} +734 -620
- package/build/browser/chunk-CG25K4WC.js.map +1 -0
- package/build/browser/index.js +716 -3
- package/build/browser/index.js.map +1 -1
- package/build/browser/public/unstable-do-not-use.js +1 -878
- package/build/browser/public/unstable-do-not-use.js.map +1 -1
- package/build/esm/Client.d.ts +25 -6
- package/build/esm/Client.d.ts.map +1 -1
- package/build/esm/actions/applyAction.d.ts +4 -4
- package/build/esm/actions/applyAction.d.ts.map +1 -1
- package/build/esm/{chunk-WGFCR4UM.js → chunk-MQTCPUPF.js} +737 -620
- package/build/esm/chunk-MQTCPUPF.js.map +1 -0
- package/build/esm/createClient.d.ts.map +1 -1
- package/build/esm/index.js +716 -3
- package/build/esm/index.js.map +1 -1
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.d.ts +2 -2
- package/build/esm/object/convertWireToOsdkObjects/InterfaceHolder.d.ts.map +1 -1
- package/build/esm/object/fetchPage.d.ts.map +1 -1
- package/build/esm/object/object.test.d.ts +3 -4
- package/build/esm/object/object.test.d.ts.map +1 -1
- package/build/esm/objectSet/ObjectSetListenerWebsocket.d.ts.map +1 -1
- package/build/esm/ontology/OntologyProvider.d.ts +6 -6
- package/build/esm/ontology/OntologyProvider.d.ts.map +1 -1
- package/build/esm/ontology/StandardOntologyProvider.d.ts.map +1 -1
- package/build/esm/ontology/loadActionMetadata.d.ts +4 -0
- package/build/esm/ontology/loadActionMetadata.d.ts.map +1 -0
- package/build/esm/ontology/loadFullObjectMetadata.d.ts +2 -2
- package/build/esm/ontology/loadFullObjectMetadata.d.ts.map +1 -1
- package/build/esm/ontology/loadInterfaceMetadata.d.ts +4 -0
- package/build/esm/ontology/loadInterfaceMetadata.d.ts.map +1 -0
- package/build/esm/ontology/loadQueryMetadata.d.ts +4 -0
- package/build/esm/ontology/loadQueryMetadata.d.ts.map +1 -0
- package/build/esm/public/unstable-do-not-use.d.ts +0 -4
- package/build/esm/public/unstable-do-not-use.d.ts.map +1 -1
- package/build/esm/public/unstable-do-not-use.js +1 -881
- package/build/esm/public/unstable-do-not-use.js.map +1 -1
- package/build/esm/queries/applyQuery.d.ts +2 -2
- package/build/esm/queries/applyQuery.d.ts.map +1 -1
- package/build/esm/queries/types.d.ts +3 -3
- package/build/esm/queries/types.d.ts.map +1 -1
- package/package.json +12 -12
- package/build/browser/chunk-WGFCR4UM.js.map +0 -1
- package/build/esm/__unstable/UNSTABLE_createClient.d.ts +0 -4
- package/build/esm/__unstable/UNSTABLE_createClient.d.ts.map +0 -1
- package/build/esm/__unstable/UnstableClient.d.ts +0 -12
- package/build/esm/__unstable/UnstableClient.d.ts.map +0 -1
- package/build/esm/chunk-WGFCR4UM.js.map +0 -1
- package/build/esm/objectSet/ObjectSetListener.d.ts +0 -18
- package/build/esm/objectSet/ObjectSetListener.d.ts.map +0 -1
- package/build/esm/objectSet/createUnstableObjectSet.d.ts +0 -8
- package/build/esm/objectSet/createUnstableObjectSet.d.ts.map +0 -1
- package/build/esm/ontology/loadInterfaceDefinition.d.ts +0 -4
- package/build/esm/ontology/loadInterfaceDefinition.d.ts.map +0 -1
- package/build/esm/ontology/loadQueryDefinition.d.ts +0 -4
- package/build/esm/ontology/loadQueryDefinition.d.ts.map +0 -1
package/build/browser/index.js
CHANGED
|
@@ -1,13 +1,726 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { createObjectSet, metadataCacheClient, conjureUnionType, makeConjureContext, InterfaceDefinitions, createAsyncClientCache, addUserAgentAndRequestContextHeaders, augmentRequestContext, esm_exports, createAttachmentFromRid, isWireObjectSet, isObjectSet, getWireObjectSet } from './chunk-CG25K4WC.js';
|
|
2
|
+
export { createAttachmentFromRid } from './chunk-CG25K4WC.js';
|
|
3
3
|
export { isOk } from '@osdk/client.api';
|
|
4
4
|
export { PalantirApiError } from '@osdk/shared.net.errors';
|
|
5
|
+
import { __EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks, __EXPERIMENTAL__NOT_SUPPORTED_YET__preexistingObjectSet } from '@osdk/client.api/unstable';
|
|
6
|
+
import { symbolClientContext } from '@osdk/shared.client';
|
|
7
|
+
import { getBulkLinksPage } from '@osdk/client.unstable';
|
|
8
|
+
import invariant from 'tiny-invariant';
|
|
5
9
|
import { createSharedClientContext } from '@osdk/shared.client.impl';
|
|
10
|
+
import { wireActionTypeV2ToSdkActionMetadata, wireObjectTypeFullMetadataToSdkObjectMetadata, __UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition, wireQueryTypeV2ToSdkQueryMetadata } from '@osdk/generator-converters';
|
|
6
11
|
|
|
12
|
+
// src/actions/ActionValidationError.ts
|
|
13
|
+
var ActionValidationError = class extends Error {
|
|
14
|
+
constructor(validation) {
|
|
15
|
+
super("Validation Error");
|
|
16
|
+
this.validation = validation;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/pageRequestAsAsyncIter.ts
|
|
21
|
+
function getResults(x) {
|
|
22
|
+
return x.results;
|
|
23
|
+
}
|
|
24
|
+
function applyPageToken(payload, {
|
|
25
|
+
pageToken
|
|
26
|
+
}) {
|
|
27
|
+
return pageToken ? {
|
|
28
|
+
...payload,
|
|
29
|
+
pageToken
|
|
30
|
+
} : void 0;
|
|
31
|
+
}
|
|
32
|
+
async function* pageRequestAsAsyncIter(call, values, nextArgs, initialPayload) {
|
|
33
|
+
let payload = initialPayload;
|
|
34
|
+
while (payload) {
|
|
35
|
+
const r = await call(payload);
|
|
36
|
+
for (const q of values(r)) {
|
|
37
|
+
yield q;
|
|
38
|
+
}
|
|
39
|
+
payload = nextArgs(payload, r);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/__unstable/createBulkLinksAsyncIterFactory.ts
|
|
44
|
+
function createBulkLinksAsyncIterFactory(ctx) {
|
|
45
|
+
return async function* (objs, linkTypes) {
|
|
46
|
+
if (objs.length === 0) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
ctx.logger?.debug("Preparing to fetch bulk links");
|
|
50
|
+
!objs.every((a) => a.$objectType === objs[0].$objectType) ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0;
|
|
51
|
+
const mcc = await metadataCacheClient(ctx);
|
|
52
|
+
const helper = await mcc.forObjectByApiName(objs[0].$objectType);
|
|
53
|
+
const [objectTypeRid, propertyMapping, fullLinkMapping] = await Promise.all([helper.getRid(), helper.getPropertyMapping(), helper.getLinkMapping()]);
|
|
54
|
+
const linkMapping = Object.fromEntries(Object.entries(fullLinkMapping).filter(([apiName]) => linkTypes.includes(apiName)));
|
|
55
|
+
for (const linkType of linkTypes) {
|
|
56
|
+
if (linkMapping[linkType] == null) {
|
|
57
|
+
throw "Unable to find link type: " + linkType;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const req = {
|
|
61
|
+
objectSetContext: {
|
|
62
|
+
forkRid: void 0,
|
|
63
|
+
objectSetFilterContext: {
|
|
64
|
+
parameterOverrides: {}
|
|
65
|
+
},
|
|
66
|
+
ontologyBranchRid: void 0,
|
|
67
|
+
owningRid: void 0,
|
|
68
|
+
reportUsage: void 0,
|
|
69
|
+
workstateRid: void 0
|
|
70
|
+
},
|
|
71
|
+
responseOptions: {
|
|
72
|
+
includeObjectSetEntities: true,
|
|
73
|
+
includeUsageCost: false
|
|
74
|
+
},
|
|
75
|
+
pageSize: 1e3,
|
|
76
|
+
pageToken: void 0,
|
|
77
|
+
linksRequests: [{
|
|
78
|
+
directedLinkTypes: Object.values(linkMapping).map(({
|
|
79
|
+
directedLinkTypeRid
|
|
80
|
+
}) => directedLinkTypeRid),
|
|
81
|
+
objects: conjureUnionType("objects", objs.map((o) => conjureUnionType("objectLocatorV2", {
|
|
82
|
+
objectTypeRid,
|
|
83
|
+
objectPrimaryKey: {
|
|
84
|
+
[propertyMapping.pk.rid]: conjureUnionType(propertyMapping.pk.type.type, o.$primaryKey)
|
|
85
|
+
}
|
|
86
|
+
})))
|
|
87
|
+
}]
|
|
88
|
+
};
|
|
89
|
+
const bulkLinksIter = pageRequestAsAsyncIter(getBulkLinksPage.bind(void 0, makeConjureContext(ctx, "/object-set-service/api")), getResults, applyPageToken, req);
|
|
90
|
+
for await (const item of bulkLinksIter) {
|
|
91
|
+
const {
|
|
92
|
+
objectIdentifier
|
|
93
|
+
} = item;
|
|
94
|
+
const obj = findObject(objectIdentifier, objs);
|
|
95
|
+
for (const link of item.links) {
|
|
96
|
+
const ref = link.link[link.linkSide === "SOURCE" ? "objectSideB" : "objectSideA"];
|
|
97
|
+
const pk = getPrimaryKeyOrThrow(ref);
|
|
98
|
+
const otherObjectApiName = await (await mcc.forObjectByRid(pk.objectTypeRid)).getApiName();
|
|
99
|
+
const mappedLink = Object.values(linkMapping).find((a) => a.directedLinkTypeRid.linkTypeRid === link.link.linkTypeRid && a.directedLinkTypeRid.linkSide === link.linkSide);
|
|
100
|
+
if (!mappedLink) throw new Error("Could not find link type");
|
|
101
|
+
yield {
|
|
102
|
+
object: obj,
|
|
103
|
+
linkApiName: mappedLink.apiName,
|
|
104
|
+
otherObjectApiName,
|
|
105
|
+
otherObjectPk: pk.pkValue
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function findObject(objectIdentifier, objs) {
|
|
112
|
+
const {
|
|
113
|
+
pkValue
|
|
114
|
+
} = getPrimaryKeyOrThrow(objectIdentifier);
|
|
115
|
+
const obj = objs.find((o) => o.$primaryKey === pkValue);
|
|
116
|
+
if (obj == null) {
|
|
117
|
+
throw new Error(`Needed to find object with pk ${pkValue}} and could not`);
|
|
118
|
+
}
|
|
119
|
+
return obj;
|
|
120
|
+
}
|
|
121
|
+
function getPrimaryKeyOrThrow(ref) {
|
|
122
|
+
if ("type" in ref && ref.type !== "objectLocatorV2") {
|
|
123
|
+
throw new Error("We do not support looking up object by rid");
|
|
124
|
+
}
|
|
125
|
+
const pks = Object.entries(ref.objectLocatorV2.objectPrimaryKey);
|
|
126
|
+
if (pks.length !== 1) {
|
|
127
|
+
throw new Error("Unable to support this request due to multiple pks");
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
objectTypeRid: ref.objectLocatorV2.objectTypeRid,
|
|
131
|
+
pkValue: pks[0][1][pks[0][1].type]
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/object/AttachmentUpload.ts
|
|
136
|
+
function isAttachmentUpload(o) {
|
|
137
|
+
return o instanceof Blob && "name" in o;
|
|
138
|
+
}
|
|
139
|
+
function createAttachmentUpload(data, name) {
|
|
140
|
+
const attachmentUpload = Object.create(data, {
|
|
141
|
+
name: {
|
|
142
|
+
value: name
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return attachmentUpload;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/util/isOntologyObjectV2.ts
|
|
149
|
+
function isOntologyObjectV2(o) {
|
|
150
|
+
return o && typeof o === "object" && typeof o.__apiName === "string" && o.__primaryKey != null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/util/isOsdkObject.ts
|
|
154
|
+
function isOsdkBaseObject(o) {
|
|
155
|
+
return o && typeof o === "object" && typeof o.$apiName === "string" && o.$primaryKey != null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/util/toDataValue.ts
|
|
159
|
+
async function toDataValue(value, client) {
|
|
160
|
+
if (value == null) {
|
|
161
|
+
return value;
|
|
162
|
+
}
|
|
163
|
+
if (Array.isArray(value) || value instanceof Set) {
|
|
164
|
+
const promiseArray = Array.from(value, async (innerValue) => await toDataValue(innerValue, client));
|
|
165
|
+
return Promise.all(promiseArray);
|
|
166
|
+
}
|
|
167
|
+
if (isAttachmentUpload(value)) {
|
|
168
|
+
const attachment = await esm_exports.Attachments.uploadAttachmentV2(client, value, {
|
|
169
|
+
filename: value.name
|
|
170
|
+
});
|
|
171
|
+
return await toDataValue(attachment.rid, client);
|
|
172
|
+
}
|
|
173
|
+
if (isOntologyObjectV2(value)) {
|
|
174
|
+
return await toDataValue(value.__primaryKey, client);
|
|
175
|
+
}
|
|
176
|
+
if (isOsdkBaseObject(value)) {
|
|
177
|
+
return await toDataValue(value.$primaryKey, client);
|
|
178
|
+
}
|
|
179
|
+
if (isWireObjectSet(value)) {
|
|
180
|
+
return value;
|
|
181
|
+
}
|
|
182
|
+
if (isObjectSet(value)) {
|
|
183
|
+
return getWireObjectSet(value);
|
|
184
|
+
}
|
|
185
|
+
if (typeof value === "object") {
|
|
186
|
+
return Object.entries(value).reduce(async (promisedAcc, [key, structValue]) => {
|
|
187
|
+
const acc = await promisedAcc;
|
|
188
|
+
acc[key] = await toDataValue(structValue, client);
|
|
189
|
+
return acc;
|
|
190
|
+
}, Promise.resolve({}));
|
|
191
|
+
}
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/actions/applyAction.ts
|
|
196
|
+
async function applyAction(client, action, parameters, options = {}) {
|
|
197
|
+
const clientWithHeaders = addUserAgentAndRequestContextHeaders(augmentRequestContext(client, (_) => ({
|
|
198
|
+
finalMethodCall: "applyAction"
|
|
199
|
+
})), action);
|
|
200
|
+
if (Array.isArray(parameters)) {
|
|
201
|
+
const response = await esm_exports.Actions.applyActionBatchV2(clientWithHeaders, await client.ontologyRid, action.apiName, {
|
|
202
|
+
requests: parameters ? await remapBatchActionParams(parameters, client) : [],
|
|
203
|
+
options: {
|
|
204
|
+
returnEdits: options?.$returnEdits ? "ALL" : "NONE"
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
const edits = response.edits;
|
|
208
|
+
return options?.$returnEdits ? edits?.type === "edits" ? remapActionResponse(response) : edits : void 0;
|
|
209
|
+
} else {
|
|
210
|
+
const response = await esm_exports.Actions.applyActionV2(clientWithHeaders, await client.ontologyRid, action.apiName, {
|
|
211
|
+
parameters: await remapActionParams(parameters, client),
|
|
212
|
+
options: {
|
|
213
|
+
mode: options?.$validateOnly ? "VALIDATE_ONLY" : "VALIDATE_AND_EXECUTE",
|
|
214
|
+
returnEdits: options?.$returnEdits ? "ALL" : "NONE"
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
if (options?.$validateOnly) {
|
|
218
|
+
return response.validation;
|
|
219
|
+
}
|
|
220
|
+
if (response.validation?.result === "INVALID") {
|
|
221
|
+
throw new ActionValidationError(response.validation);
|
|
222
|
+
}
|
|
223
|
+
const edits = response.edits;
|
|
224
|
+
return options?.$returnEdits ? edits?.type === "edits" ? remapActionResponse(response) : edits : void 0;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function remapActionParams(params, client) {
|
|
228
|
+
if (params == null) {
|
|
229
|
+
return {};
|
|
230
|
+
}
|
|
231
|
+
const parameterMap = {};
|
|
232
|
+
for (const [key, value] of Object.entries(params)) {
|
|
233
|
+
parameterMap[key] = await toDataValue(value, client);
|
|
234
|
+
}
|
|
235
|
+
return parameterMap;
|
|
236
|
+
}
|
|
237
|
+
async function remapBatchActionParams(params, client) {
|
|
238
|
+
const remappedParams = await Promise.all(params.map(async (param) => {
|
|
239
|
+
return {
|
|
240
|
+
parameters: await remapActionParams(param, client)
|
|
241
|
+
};
|
|
242
|
+
}));
|
|
243
|
+
return remappedParams;
|
|
244
|
+
}
|
|
245
|
+
function remapActionResponse(response) {
|
|
246
|
+
const editResponses = response?.edits;
|
|
247
|
+
if (editResponses?.type === "edits") {
|
|
248
|
+
const remappedActionResponse = {
|
|
249
|
+
type: editResponses.type,
|
|
250
|
+
deletedLinksCount: editResponses.deletedLinksCount,
|
|
251
|
+
deletedObjectsCount: editResponses.deletedObjectsCount,
|
|
252
|
+
addedLinks: [],
|
|
253
|
+
addedObjects: [],
|
|
254
|
+
modifiedObjects: [],
|
|
255
|
+
editedObjectTypes: []
|
|
256
|
+
};
|
|
257
|
+
const editedObjectTypesSet = /* @__PURE__ */ new Set();
|
|
258
|
+
for (const edit of editResponses.edits) {
|
|
259
|
+
if (edit.type === "addLink") {
|
|
260
|
+
remappedActionResponse.addedLinks.push({
|
|
261
|
+
linkTypeApiNameAtoB: edit.linkTypeApiNameAtoB,
|
|
262
|
+
linkTypeApiNameBtoA: edit.linkTypeApiNameBtoA,
|
|
263
|
+
aSideObject: edit.aSideObject,
|
|
264
|
+
bSideObject: edit.bSideObject
|
|
265
|
+
});
|
|
266
|
+
editedObjectTypesSet.add(edit.aSideObject.objectType);
|
|
267
|
+
editedObjectTypesSet.add(edit.bSideObject.objectType);
|
|
268
|
+
} else if (edit.type === "addObject") {
|
|
269
|
+
remappedActionResponse.addedObjects.push({
|
|
270
|
+
objectType: edit.objectType,
|
|
271
|
+
primaryKey: edit.primaryKey
|
|
272
|
+
});
|
|
273
|
+
editedObjectTypesSet.add(edit.objectType);
|
|
274
|
+
} else if (edit.type === "modifyObject") {
|
|
275
|
+
remappedActionResponse.modifiedObjects.push({
|
|
276
|
+
objectType: edit.objectType,
|
|
277
|
+
primaryKey: edit.primaryKey
|
|
278
|
+
});
|
|
279
|
+
editedObjectTypesSet.add(edit.objectType);
|
|
280
|
+
} else {
|
|
281
|
+
process.env.NODE_ENV !== "production" ? invariant(false, "Unknown edit type") : invariant(false) ;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
remappedActionResponse.editedObjectTypes = [...editedObjectTypesSet];
|
|
285
|
+
return remappedActionResponse;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async function loadActionMetadata(client, actionType) {
|
|
289
|
+
const r = await esm_exports.ActionTypesV2.getActionTypeV2(client, await client.ontologyRid, actionType);
|
|
290
|
+
return wireActionTypeV2ToSdkActionMetadata(r);
|
|
291
|
+
}
|
|
292
|
+
async function loadFullObjectMetadata(client, objectType) {
|
|
293
|
+
const full = await esm_exports.ObjectTypesV2.getObjectTypeFullMetadata(client, await client.ontologyRid, objectType, {
|
|
294
|
+
preview: true
|
|
295
|
+
});
|
|
296
|
+
const ret = wireObjectTypeFullMetadataToSdkObjectMetadata(full, true);
|
|
297
|
+
client.logger?.debug(`END loadFullObjectMetadata(${objectType})`);
|
|
298
|
+
return {
|
|
299
|
+
...ret
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
async function loadInterfaceMetadata(client, objectType) {
|
|
303
|
+
const r = await esm_exports.OntologyInterfaces.getInterfaceType(client, await client.ontologyRid, objectType, {
|
|
304
|
+
preview: true
|
|
305
|
+
});
|
|
306
|
+
return __UNSTABLE_wireInterfaceTypeV2ToSdkObjectDefinition(r, true);
|
|
307
|
+
}
|
|
308
|
+
async function loadQueryMetadata(client, queryType) {
|
|
309
|
+
const r = await esm_exports.QueryTypes.getQueryTypeV2(client, await client.ontologyRid, queryType);
|
|
310
|
+
return wireQueryTypeV2ToSdkQueryMetadata(r);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/ontology/StandardOntologyProvider.ts
|
|
314
|
+
var createStandardOntologyProviderFactory = (client) => {
|
|
315
|
+
return (client2) => {
|
|
316
|
+
async function loadObject(client3, key) {
|
|
317
|
+
let objectDef = await loadFullObjectMetadata(client3, key);
|
|
318
|
+
const interfaceDefs = Object.fromEntries((await Promise.all(objectDef.implements?.map((i) => ret.getInterfaceDefinition(i)) ?? [])).map((i) => [i.apiName, {
|
|
319
|
+
def: i,
|
|
320
|
+
handler: void 0
|
|
321
|
+
}]));
|
|
322
|
+
const fullObjectDef = {
|
|
323
|
+
...objectDef,
|
|
324
|
+
[InterfaceDefinitions]: interfaceDefs
|
|
325
|
+
};
|
|
326
|
+
return fullObjectDef;
|
|
327
|
+
}
|
|
328
|
+
async function loadInterface(client3, key) {
|
|
329
|
+
return loadInterfaceMetadata(client3, key);
|
|
330
|
+
}
|
|
331
|
+
async function loadQuery(client3, key) {
|
|
332
|
+
const r = await loadQueryMetadata(client3, key);
|
|
333
|
+
return r;
|
|
334
|
+
}
|
|
335
|
+
async function loadAction(client3, key) {
|
|
336
|
+
const r = await loadActionMetadata(client3, key);
|
|
337
|
+
return r;
|
|
338
|
+
}
|
|
339
|
+
function makeGetter(fn) {
|
|
340
|
+
const cache = createAsyncClientCache((client3, key) => fn(client3, key, false));
|
|
341
|
+
return async (apiName) => {
|
|
342
|
+
return await cache.get(client2, apiName);
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
const ret = {
|
|
346
|
+
getObjectDefinition: makeGetter(loadObject),
|
|
347
|
+
getInterfaceDefinition: makeGetter(loadInterface),
|
|
348
|
+
getQueryDefinition: makeGetter(loadQuery),
|
|
349
|
+
getActionDefinition: makeGetter(loadAction)
|
|
350
|
+
};
|
|
351
|
+
return ret;
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// src/util/UserAgent.ts
|
|
356
|
+
var USER_AGENT = `osdk-client/${"2.0.0-beta.13"}`;
|
|
357
|
+
|
|
358
|
+
// src/createMinimalClient.ts
|
|
359
|
+
function createMinimalClient(metadata, baseUrl, tokenProvider, options = {}, fetchFn = global.fetch, objectSetFactory = createObjectSet) {
|
|
360
|
+
if (process?.env?.NODE_ENV !== "production") {
|
|
361
|
+
try {
|
|
362
|
+
new URL(baseUrl);
|
|
363
|
+
} catch (e) {
|
|
364
|
+
const hint = !baseUrl.startsWith("http://") || !baseUrl.startsWith("https://") ? ". Did you forget to add 'http://' or 'https://'?" : "";
|
|
365
|
+
throw new Error(`Invalid stack URL: ${baseUrl}${hint}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const minimalClient = {
|
|
369
|
+
...createSharedClientContext(baseUrl, tokenProvider, USER_AGENT, fetchFn),
|
|
370
|
+
objectSetFactory,
|
|
371
|
+
ontologyRid: metadata.ontologyRid,
|
|
372
|
+
logger: options.logger,
|
|
373
|
+
clientCacheKey: {},
|
|
374
|
+
requestContext: {}
|
|
375
|
+
};
|
|
376
|
+
return Object.assign(minimalClient, {
|
|
377
|
+
ontologyProvider: createStandardOntologyProviderFactory()(minimalClient)
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// src/fetchMetadata.ts
|
|
382
|
+
var fetchMetadataInternal = async (client, definition) => {
|
|
383
|
+
if (definition.type === "object") {
|
|
384
|
+
const {
|
|
385
|
+
[InterfaceDefinitions]: interfaceDefs,
|
|
386
|
+
...objectTypeDef
|
|
387
|
+
} = await client.ontologyProvider.getObjectDefinition(definition.apiName);
|
|
388
|
+
return objectTypeDef;
|
|
389
|
+
} else if (definition.type === "interface") {
|
|
390
|
+
return client.ontologyProvider.getInterfaceDefinition(definition.apiName);
|
|
391
|
+
} else if (definition.type === "action") {
|
|
392
|
+
return client.ontologyProvider.getActionDefinition(definition.apiName);
|
|
393
|
+
} else if (definition.type === "query") {
|
|
394
|
+
return client.ontologyProvider.getQueryDefinition(definition.apiName);
|
|
395
|
+
} else {
|
|
396
|
+
throw new Error("Not implemented for given definition");
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// src/util/isOsdkBaseObject.ts
|
|
401
|
+
function isOsdkBaseObject2(o) {
|
|
402
|
+
return o && typeof o === "object" && typeof o.$apiName === "string" && o.$primaryKey != null;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/util/toDataValueQueries.ts
|
|
406
|
+
async function toDataValueQueries(value, client, desiredType) {
|
|
407
|
+
if (value == null) {
|
|
408
|
+
return value;
|
|
409
|
+
}
|
|
410
|
+
if (Array.isArray(value) && desiredType.multiplicity) {
|
|
411
|
+
const promiseArray = Array.from(value, async (innerValue) => await toDataValueQueries(innerValue, client, desiredType));
|
|
412
|
+
return Promise.all(promiseArray);
|
|
413
|
+
}
|
|
414
|
+
switch (desiredType.type) {
|
|
415
|
+
case "attachment": {
|
|
416
|
+
if (isAttachmentUpload(value)) {
|
|
417
|
+
const attachment = await esm_exports.Attachments.uploadAttachmentV2(client, value, {
|
|
418
|
+
filename: value.name
|
|
419
|
+
});
|
|
420
|
+
return attachment.rid;
|
|
421
|
+
}
|
|
422
|
+
return value;
|
|
423
|
+
}
|
|
424
|
+
case "twoDimensionalAggregation": {
|
|
425
|
+
return {
|
|
426
|
+
groups: value
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
case "threeDimensionalAggregation": {
|
|
430
|
+
return {
|
|
431
|
+
groups: value
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
case "set": {
|
|
435
|
+
if (value instanceof Set) {
|
|
436
|
+
const promiseArray = Array.from(value, async (innerValue) => await toDataValueQueries(innerValue, client, desiredType["set"]));
|
|
437
|
+
return Promise.all(promiseArray);
|
|
438
|
+
}
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
case "object": {
|
|
442
|
+
if (isOsdkBaseObject2(value)) {
|
|
443
|
+
return value.$primaryKey;
|
|
444
|
+
}
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
case "objectSet": {
|
|
448
|
+
if (isWireObjectSet(value)) {
|
|
449
|
+
return value;
|
|
450
|
+
}
|
|
451
|
+
if (isObjectSet(value)) {
|
|
452
|
+
return getWireObjectSet(value);
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
case "struct": {
|
|
457
|
+
if (typeof value === "object") {
|
|
458
|
+
const structMap = {};
|
|
459
|
+
for (const [key, structValue] of Object.entries(value)) {
|
|
460
|
+
structMap[key] = await toDataValueQueries(structValue, client, desiredType["struct"][key]);
|
|
461
|
+
}
|
|
462
|
+
return structMap;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
case "boolean":
|
|
466
|
+
case "date":
|
|
467
|
+
case "double":
|
|
468
|
+
case "float":
|
|
469
|
+
case "integer":
|
|
470
|
+
case "long":
|
|
471
|
+
case "string":
|
|
472
|
+
case "timestamp":
|
|
473
|
+
return value;
|
|
474
|
+
}
|
|
475
|
+
return value;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// src/queries/applyQuery.ts
|
|
479
|
+
async function applyQuery(client, query, params) {
|
|
480
|
+
const qd = await client.ontologyProvider.getQueryDefinition(query.apiName);
|
|
481
|
+
const response = await esm_exports.Queries.executeQueryV2(addUserAgentAndRequestContextHeaders(augmentRequestContext(client, (_) => ({
|
|
482
|
+
finalMethodCall: "applyQuery"
|
|
483
|
+
})), query), await client.ontologyRid, query.apiName, {
|
|
484
|
+
parameters: params ? await remapQueryParams(params, client, qd.parameters) : {}
|
|
485
|
+
});
|
|
486
|
+
const objectOutputDefs = await getRequiredDefinitions(qd.output, client);
|
|
487
|
+
const remappedResponse = await remapQueryResponse(client, qd.output, response.value, objectOutputDefs);
|
|
488
|
+
return remappedResponse;
|
|
489
|
+
}
|
|
490
|
+
async function remapQueryParams(params, client, paramTypes) {
|
|
491
|
+
const parameterMap = {};
|
|
492
|
+
for (const [key, value] of Object.entries(params)) {
|
|
493
|
+
parameterMap[key] = await toDataValueQueries(value, client, paramTypes[key]);
|
|
494
|
+
}
|
|
495
|
+
return parameterMap;
|
|
496
|
+
}
|
|
497
|
+
async function remapQueryResponse(client, responseDataType, responseValue, definitions) {
|
|
498
|
+
if (responseValue == null) {
|
|
499
|
+
if (responseDataType.nullable) {
|
|
500
|
+
return void 0;
|
|
501
|
+
} else {
|
|
502
|
+
throw new Error("Got null response when nullable was not allowed");
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (responseDataType.multiplicity != null && responseDataType.multiplicity !== false) {
|
|
506
|
+
const withoutMultiplicity = {
|
|
507
|
+
...responseDataType,
|
|
508
|
+
multiplicity: false
|
|
509
|
+
};
|
|
510
|
+
for (let i = 0; i < responseValue.length; i++) {
|
|
511
|
+
responseValue[i] = await remapQueryResponse(responseValue[i], withoutMultiplicity, client, definitions);
|
|
512
|
+
}
|
|
513
|
+
return responseValue;
|
|
514
|
+
}
|
|
515
|
+
switch (responseDataType.type) {
|
|
516
|
+
case "union": {
|
|
517
|
+
throw new Error("Union return types are not yet supported");
|
|
518
|
+
}
|
|
519
|
+
case "set": {
|
|
520
|
+
for (let i = 0; i < responseValue.length; i++) {
|
|
521
|
+
responseValue[i] = await remapQueryResponse(responseValue[i], responseDataType.set, client, definitions);
|
|
522
|
+
}
|
|
523
|
+
return responseValue;
|
|
524
|
+
}
|
|
525
|
+
case "attachment": {
|
|
526
|
+
return createAttachmentFromRid(client, responseValue);
|
|
527
|
+
}
|
|
528
|
+
case "object": {
|
|
529
|
+
const def = definitions.get(responseDataType.object);
|
|
530
|
+
if (!def) {
|
|
531
|
+
throw new Error(`Missing definition for ${responseDataType.object}`);
|
|
532
|
+
}
|
|
533
|
+
return createQueryObjectResponse(responseValue, def);
|
|
534
|
+
}
|
|
535
|
+
case "objectSet": {
|
|
536
|
+
const def = definitions.get(responseDataType.objectSet);
|
|
537
|
+
if (!def) {
|
|
538
|
+
throw new Error(`Missing definition for ${responseDataType.objectSet}`);
|
|
539
|
+
}
|
|
540
|
+
if (typeof responseValue === "string") {
|
|
541
|
+
return createObjectSet(def, client, {
|
|
542
|
+
type: "intersect",
|
|
543
|
+
objectSets: [{
|
|
544
|
+
type: "base",
|
|
545
|
+
objectType: responseDataType.objectSet
|
|
546
|
+
}, {
|
|
547
|
+
type: "reference",
|
|
548
|
+
reference: responseValue
|
|
549
|
+
}]
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
return createObjectSet(def, client, responseValue);
|
|
553
|
+
}
|
|
554
|
+
case "struct": {
|
|
555
|
+
for (const [key, subtype] of Object.entries(responseDataType.struct)) {
|
|
556
|
+
if (requiresConversion(subtype)) {
|
|
557
|
+
responseValue[key] = await remapQueryResponse(responseValue[key], subtype, client, definitions);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return responseValue;
|
|
561
|
+
}
|
|
562
|
+
case "twoDimensionalAggregation": {
|
|
563
|
+
const result = [];
|
|
564
|
+
for (const {
|
|
565
|
+
key,
|
|
566
|
+
value
|
|
567
|
+
} of responseValue.groups) {
|
|
568
|
+
result.push({
|
|
569
|
+
key,
|
|
570
|
+
value
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
case "threeDimensionalAggregation": {
|
|
576
|
+
const result = [];
|
|
577
|
+
for (const {
|
|
578
|
+
key,
|
|
579
|
+
groups
|
|
580
|
+
} of responseValue.groups) {
|
|
581
|
+
const subResult = [];
|
|
582
|
+
for (const {
|
|
583
|
+
key: subKey,
|
|
584
|
+
value
|
|
585
|
+
} of groups) {
|
|
586
|
+
subResult.push({
|
|
587
|
+
key: subKey,
|
|
588
|
+
value
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
result.push({
|
|
592
|
+
key,
|
|
593
|
+
groups: subResult
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
return result;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return responseValue;
|
|
600
|
+
}
|
|
601
|
+
async function getRequiredDefinitions(dataType, client) {
|
|
602
|
+
const result = /* @__PURE__ */ new Map();
|
|
603
|
+
switch (dataType.type) {
|
|
604
|
+
case "objectSet": {
|
|
605
|
+
const objectDef = await client.ontologyProvider.getObjectDefinition(dataType.objectSet);
|
|
606
|
+
result.set(dataType.objectSet, objectDef);
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
case "object": {
|
|
610
|
+
const objectDef = await client.ontologyProvider.getObjectDefinition(dataType.object);
|
|
611
|
+
result.set(dataType.object, objectDef);
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
case "set": {
|
|
615
|
+
return getRequiredDefinitions(dataType.set, client);
|
|
616
|
+
}
|
|
617
|
+
case "struct": {
|
|
618
|
+
for (const value of Object.values(dataType.struct)) {
|
|
619
|
+
for (const [type, objectDef] of await getRequiredDefinitions(value, client)) {
|
|
620
|
+
result.set(type, objectDef);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
return result;
|
|
627
|
+
}
|
|
628
|
+
function requiresConversion(dataType) {
|
|
629
|
+
switch (dataType.type) {
|
|
630
|
+
case "boolean":
|
|
631
|
+
case "date":
|
|
632
|
+
case "double":
|
|
633
|
+
case "float":
|
|
634
|
+
case "integer":
|
|
635
|
+
case "long":
|
|
636
|
+
case "object":
|
|
637
|
+
case "string":
|
|
638
|
+
case "timestamp":
|
|
639
|
+
return false;
|
|
640
|
+
case "union":
|
|
641
|
+
return true;
|
|
642
|
+
case "struct":
|
|
643
|
+
return Object.values(dataType.struct).some(requiresConversion);
|
|
644
|
+
case "set":
|
|
645
|
+
return requiresConversion(dataType.set);
|
|
646
|
+
case "attachment":
|
|
647
|
+
case "objectSet":
|
|
648
|
+
case "twoDimensionalAggregation":
|
|
649
|
+
case "threeDimensionalAggregation":
|
|
650
|
+
return true;
|
|
651
|
+
default:
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
function createQueryObjectResponse(primaryKey, objectDef) {
|
|
656
|
+
return {
|
|
657
|
+
$apiName: objectDef.apiName,
|
|
658
|
+
$title: void 0,
|
|
659
|
+
$objectType: objectDef.apiName,
|
|
660
|
+
$primaryKey: primaryKey
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/createClient.ts
|
|
665
|
+
var ActionInvoker = class {
|
|
666
|
+
constructor(clientCtx, actionDef) {
|
|
667
|
+
this.applyAction = applyAction.bind(void 0, clientCtx, actionDef);
|
|
668
|
+
this.batchApplyAction = applyAction.bind(void 0, clientCtx, actionDef);
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
var QueryInvoker = class {
|
|
672
|
+
constructor(clientCtx, queryDef) {
|
|
673
|
+
this.executeFunction = applyQuery.bind(void 0, clientCtx, queryDef);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
function createClientInternal(objectSetFactory, baseUrl, ontologyRid, tokenProvider, options = void 0, fetchFn = fetch) {
|
|
677
|
+
const clientCtx = createMinimalClient({
|
|
678
|
+
ontologyRid
|
|
679
|
+
}, baseUrl, tokenProvider, options, fetchFn, objectSetFactory);
|
|
680
|
+
function clientFn(o) {
|
|
681
|
+
if (o.type === "object" || o.type === "interface") {
|
|
682
|
+
return objectSetFactory(o, clientCtx);
|
|
683
|
+
} else if (o.type === "action") {
|
|
684
|
+
return new ActionInvoker(clientCtx, o);
|
|
685
|
+
} else if (o.type === "query") {
|
|
686
|
+
return new QueryInvoker(clientCtx, o);
|
|
687
|
+
} else {
|
|
688
|
+
throw new Error("not implemented");
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
const fetchMetadata = fetchMetadataInternal.bind(void 0, clientCtx);
|
|
692
|
+
const client = Object.defineProperties(clientFn, {
|
|
693
|
+
[symbolClientContext]: {
|
|
694
|
+
value: clientCtx
|
|
695
|
+
},
|
|
696
|
+
[__EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks]: {
|
|
697
|
+
get: () => createBulkLinksAsyncIterFactory(clientCtx)
|
|
698
|
+
},
|
|
699
|
+
[__EXPERIMENTAL__NOT_SUPPORTED_YET__preexistingObjectSet]: {
|
|
700
|
+
get: () => (definition, rid) => {
|
|
701
|
+
return createObjectSet(definition, client[symbolClientContext], {
|
|
702
|
+
type: "intersect",
|
|
703
|
+
objectSets: [{
|
|
704
|
+
type: "base",
|
|
705
|
+
objectType: definition.apiName
|
|
706
|
+
}, {
|
|
707
|
+
type: "reference",
|
|
708
|
+
reference: rid
|
|
709
|
+
}]
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
},
|
|
713
|
+
fetchMetadata: {
|
|
714
|
+
value: fetchMetadata
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
return client;
|
|
718
|
+
}
|
|
719
|
+
var createClient = createClientInternal.bind(void 0, createObjectSet);
|
|
7
720
|
function createPlatformClient(baseUrl, tokenProvider, options = void 0, fetchFn = fetch) {
|
|
8
721
|
return createSharedClientContext(baseUrl, tokenProvider, USER_AGENT, fetchFn);
|
|
9
722
|
}
|
|
10
723
|
|
|
11
|
-
export { createPlatformClient };
|
|
724
|
+
export { ActionValidationError, createAttachmentUpload, createClient, createPlatformClient };
|
|
12
725
|
//# sourceMappingURL=index.js.map
|
|
13
726
|
//# sourceMappingURL=index.js.map
|