@osdk/client 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/js/{chunk-2KAHVPSN.mjs → chunk-ACK45YZ2.mjs} +5 -2
- package/build/js/chunk-ACK45YZ2.mjs.map +1 -0
- package/build/js/{chunk-MCG6J7IR.cjs → chunk-SAQ3VGLL.cjs} +5 -1
- package/build/js/chunk-SAQ3VGLL.cjs.map +1 -0
- package/build/js/index.cjs +95 -22
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +91 -19
- package/build/js/index.mjs.map +1 -1
- package/build/js/public/objects.cjs +3 -3
- package/build/js/public/objects.mjs +1 -1
- package/build/types/actions/ActionValidationError.d.ts +5 -0
- package/build/types/actions/Actions.d.ts +11 -5
- package/build/types/actions/actions.test.d.ts +1 -0
- package/build/types/actions/applyAction.d.ts +14 -6
- package/build/types/actions/createActionInvoker.d.ts +2 -1
- package/build/types/generatedNoCheck/Ontology.d.ts +12 -0
- package/build/types/generatedNoCheck/ontology/actions/actionTakesAttachment.d.ts +12 -0
- package/build/types/generatedNoCheck/ontology/actions/index.d.ts +1 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/objectSet/ObjectSet.d.ts +2 -0
- package/build/types/util/WireObjectSet.d.ts +2 -0
- package/build/types/util/isOntologyObjectV2.d.ts +2 -0
- package/build/types/util/toDataValue.d.ts +7 -0
- package/build/types/util/toDataValue.test.d.ts +1 -0
- package/package.json +5 -5
- package/build/js/chunk-2KAHVPSN.mjs.map +0 -1
- package/build/js/chunk-MCG6J7IR.cjs.map +0 -1
package/build/js/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { aggregateOrThrow, fetchPageOrThrow, modernToLegacyWhereClause, convertWireToOsdkObjects } from './chunk-
|
|
2
|
-
export { object_exports as Objects } from './chunk-
|
|
1
|
+
import { aggregateOrThrow, fetchPageOrThrow, modernToLegacyWhereClause, isAttachment, convertWireToOsdkObjects } from './chunk-ACK45YZ2.mjs';
|
|
2
|
+
export { object_exports as Objects } from './chunk-ACK45YZ2.mjs';
|
|
3
3
|
import { createClientContext, createOpenApiRequest } from '@osdk/shared.net';
|
|
4
4
|
export { createClientContext, isOk } from '@osdk/shared.net';
|
|
5
5
|
import { applyActionV2, getObjectTypeV2 } from '@osdk/gateway/requests';
|
|
@@ -7,40 +7,111 @@ import WebSocket from 'isomorphic-ws';
|
|
|
7
7
|
import invariant from 'tiny-invariant';
|
|
8
8
|
import { conjureFetch } from 'conjure-lite';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// src/util/isOntologyObjectV2.ts
|
|
11
|
+
function isOntologyObjectV2(o) {
|
|
12
|
+
return o && typeof o === "object" && typeof o.__apiName === "string" && o.__primaryKey != null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/util/WireObjectSet.ts
|
|
16
|
+
var WIRE_OBJECT_SET_TYPES = /* @__PURE__ */ new Set(["base", "filter", "intersect", "reference", "searchAround", "static", "subtract", "union"]);
|
|
17
|
+
function isWireObjectSet(o) {
|
|
18
|
+
return o != null && typeof o === "object" && WIRE_OBJECT_SET_TYPES.has(o.type);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/util/toDataValue.ts
|
|
22
|
+
function toDataValue(value) {
|
|
23
|
+
if (value == null) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value) || value instanceof Set) {
|
|
27
|
+
return Array.from(value, toDataValue);
|
|
28
|
+
}
|
|
29
|
+
if (isAttachment(value)) {
|
|
30
|
+
return value.rid;
|
|
31
|
+
}
|
|
32
|
+
if (isOntologyObjectV2(value)) {
|
|
33
|
+
return toDataValue(value.__primaryKey);
|
|
34
|
+
}
|
|
35
|
+
if (isWireObjectSet(value)) {
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
if (isObjectSet(value)) {
|
|
39
|
+
return value.definition;
|
|
40
|
+
}
|
|
41
|
+
if (typeof value === "object") {
|
|
42
|
+
return Object.entries(value).reduce((acc, [key, structValue]) => {
|
|
43
|
+
acc[key] = toDataValue(structValue);
|
|
44
|
+
return acc;
|
|
45
|
+
}, {});
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function isObjectSet(o) {
|
|
50
|
+
return o != null && typeof o === "object" && isWireObjectSet(o.definition);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/actions/ActionValidationError.ts
|
|
54
|
+
var ActionValidationError = class extends Error {
|
|
55
|
+
constructor(validation) {
|
|
56
|
+
super("Validation Error");
|
|
57
|
+
this.validation = validation;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/actions/applyAction.ts
|
|
62
|
+
async function applyAction(client, actionApiName, parameters, options = {}) {
|
|
11
63
|
const response = await applyActionV2(createOpenApiRequest(client.stack, client.fetch), client.ontology.metadata.ontologyApiName, actionApiName, {
|
|
12
|
-
parameters,
|
|
64
|
+
parameters: remapActionParams(parameters),
|
|
13
65
|
options: {
|
|
14
66
|
mode: options?.validateOnly ? "VALIDATE_ONLY" : "VALIDATE_AND_EXECUTE",
|
|
15
67
|
returnEdits: options?.returnEdits ? "ALL" : "NONE"
|
|
16
68
|
}
|
|
17
69
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}
|
|
70
|
+
if (options?.validateOnly) {
|
|
71
|
+
return response.validation;
|
|
72
|
+
}
|
|
73
|
+
if (response.validation?.result === "INVALID") {
|
|
74
|
+
throw new ActionValidationError(response.validation);
|
|
75
|
+
}
|
|
76
|
+
return options?.returnEdits ? response.edits : void 0;
|
|
77
|
+
}
|
|
78
|
+
function remapActionParams(params) {
|
|
79
|
+
if (params == null) {
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
const parameterMap = {};
|
|
83
|
+
const remappedParams = Object.entries(params).reduce((acc, [key, value]) => {
|
|
84
|
+
acc[key] = toDataValue(value);
|
|
85
|
+
return acc;
|
|
86
|
+
}, parameterMap);
|
|
87
|
+
return remappedParams;
|
|
30
88
|
}
|
|
31
89
|
|
|
32
90
|
// src/actions/createActionInvoker.ts
|
|
33
91
|
function createActionInvoker(client) {
|
|
34
|
-
|
|
35
|
-
get: (
|
|
92
|
+
const proxy = new Proxy({}, {
|
|
93
|
+
get: (_target, p, _receiver) => {
|
|
36
94
|
if (typeof p === "string") {
|
|
37
95
|
return function(...args) {
|
|
38
96
|
return applyAction(client, p, ...args);
|
|
39
97
|
};
|
|
40
98
|
}
|
|
41
99
|
return void 0;
|
|
100
|
+
},
|
|
101
|
+
ownKeys(_target) {
|
|
102
|
+
return Object.keys(client.ontology.actions);
|
|
103
|
+
},
|
|
104
|
+
getOwnPropertyDescriptor(_target, p) {
|
|
105
|
+
if (typeof p === "string") {
|
|
106
|
+
return {
|
|
107
|
+
enumerable: client.ontology.actions[p] != null,
|
|
108
|
+
configurable: true,
|
|
109
|
+
value: proxy[p]
|
|
110
|
+
};
|
|
111
|
+
}
|
|
42
112
|
}
|
|
43
113
|
});
|
|
114
|
+
return proxy;
|
|
44
115
|
}
|
|
45
116
|
async function createTemporaryObjectSet(ctx, request) {
|
|
46
117
|
return conjureFetch(ctx, `/objectSets/temporary`, "POST", request);
|
|
@@ -581,6 +652,7 @@ function createObjectSet2(objectType, clientCtx, objectSet = {
|
|
|
581
652
|
objectType
|
|
582
653
|
}) {
|
|
583
654
|
const base = {
|
|
655
|
+
definition: objectSet,
|
|
584
656
|
// aggregate: <
|
|
585
657
|
// AC extends AggregationClause<O, K>,
|
|
586
658
|
// GBC extends GroupByClause<O, K> | undefined = undefined,
|
|
@@ -695,6 +767,6 @@ function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {
|
|
|
695
767
|
return client;
|
|
696
768
|
}
|
|
697
769
|
|
|
698
|
-
export { createClient };
|
|
770
|
+
export { ActionValidationError, createClient };
|
|
699
771
|
//# sourceMappingURL=out.js.map
|
|
700
772
|
//# sourceMappingURL=index.mjs.map
|