@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.
@@ -1,5 +1,5 @@
1
- import { aggregateOrThrow, fetchPageOrThrow, modernToLegacyWhereClause, convertWireToOsdkObjects } from './chunk-2KAHVPSN.mjs';
2
- export { object_exports as Objects } from './chunk-2KAHVPSN.mjs';
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
- async function applyAction(client, actionApiName, parameters, options) {
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
- const bulkEdits = response.edits?.type == "largeScaleEdits" ? response.edits.editedObjectTypes : void 0;
19
- const edits = response.edits?.type == "edits" ? response.edits : void 0;
20
- edits?.edits[0];
21
- return {
22
- __unstable: {
23
- bulkEdits,
24
- addedLinksCount: edits?.addedLinksCount,
25
- addedObjectCount: edits?.addedObjectCount,
26
- modifiedObjectsCount: edits?.modifiedObjectsCount,
27
- edits: edits?.edits
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
- return new Proxy({}, {
35
- get: (target, p, receiver) => {
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