@osdk/client 0.5.0 → 0.7.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-MCG6J7IR.cjs → chunk-EU5GNJBK.cjs} +13 -8
- package/build/js/chunk-EU5GNJBK.cjs.map +1 -0
- package/build/js/{chunk-2KAHVPSN.mjs → chunk-OBZVMJLZ.mjs} +13 -9
- package/build/js/chunk-OBZVMJLZ.mjs.map +1 -0
- package/build/js/index.cjs +99 -23
- package/build/js/index.cjs.map +1 -1
- package/build/js/index.mjs +95 -20
- 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/createClient.test.d.ts +1 -0
- 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/UserAgent.d.ts +1 -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 +4 -3
- 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-OBZVMJLZ.mjs';
|
|
2
|
+
export { object_exports as Objects } from './chunk-OBZVMJLZ.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,
|
|
@@ -663,9 +735,12 @@ function createObjectSetCreator(client, clientContext) {
|
|
|
663
735
|
});
|
|
664
736
|
}
|
|
665
737
|
|
|
738
|
+
// src/util/UserAgent.ts
|
|
739
|
+
var USER_AGENT = `osdk-client/${"0.7.0"}`;
|
|
740
|
+
|
|
666
741
|
// src/createClient.ts
|
|
667
742
|
function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {
|
|
668
|
-
const clientCtx = createClientContext(ontology, stack, tokenProvider,
|
|
743
|
+
const clientCtx = createClientContext(ontology, stack, tokenProvider, USER_AGENT, fetchFn);
|
|
669
744
|
const objectSetFactory = (type) => createObjectSet2(type, clientCtx);
|
|
670
745
|
const client = Object.defineProperties({}, {
|
|
671
746
|
objectSet: {
|
|
@@ -695,6 +770,6 @@ function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {
|
|
|
695
770
|
return client;
|
|
696
771
|
}
|
|
697
772
|
|
|
698
|
-
export { createClient };
|
|
773
|
+
export { ActionValidationError, createClient };
|
|
699
774
|
//# sourceMappingURL=out.js.map
|
|
700
775
|
//# sourceMappingURL=index.mjs.map
|