@osdk/client 0.4.1 → 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.
Files changed (31) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/js/{chunk-DVD5PAXO.mjs → chunk-ACK45YZ2.mjs} +6 -10
  3. package/build/js/chunk-ACK45YZ2.mjs.map +1 -0
  4. package/build/js/{chunk-YVZITKIQ.cjs → chunk-SAQ3VGLL.cjs} +6 -9
  5. package/build/js/chunk-SAQ3VGLL.cjs.map +1 -0
  6. package/build/js/index.cjs +109 -24
  7. package/build/js/index.cjs.map +1 -1
  8. package/build/js/index.mjs +105 -21
  9. package/build/js/index.mjs.map +1 -1
  10. package/build/js/public/objects.cjs +3 -3
  11. package/build/js/public/objects.mjs +1 -1
  12. package/build/types/Client.d.ts +0 -1
  13. package/build/types/ObjectSetCreator.d.ts +2 -1
  14. package/build/types/ObjectSetCreator.test.d.ts +1 -0
  15. package/build/types/actions/ActionValidationError.d.ts +5 -0
  16. package/build/types/actions/Actions.d.ts +11 -5
  17. package/build/types/actions/actions.test.d.ts +1 -0
  18. package/build/types/actions/applyAction.d.ts +14 -6
  19. package/build/types/actions/createActionInvoker.d.ts +2 -1
  20. package/build/types/generatedNoCheck/Ontology.d.ts +12 -0
  21. package/build/types/generatedNoCheck/ontology/actions/actionTakesAttachment.d.ts +12 -0
  22. package/build/types/generatedNoCheck/ontology/actions/index.d.ts +1 -0
  23. package/build/types/index.d.ts +2 -0
  24. package/build/types/objectSet/ObjectSet.d.ts +2 -0
  25. package/build/types/util/WireObjectSet.d.ts +2 -0
  26. package/build/types/util/isOntologyObjectV2.d.ts +2 -0
  27. package/build/types/util/toDataValue.d.ts +7 -0
  28. package/build/types/util/toDataValue.test.d.ts +1 -0
  29. package/package.json +5 -5
  30. package/build/js/chunk-DVD5PAXO.mjs.map +0 -1
  31. package/build/js/chunk-YVZITKIQ.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import { aggregateOrThrow, fetchPageOrThrow, modernToLegacyWhereClause, convertWireToOsdkObjects } from './chunk-DVD5PAXO.mjs';
2
- export { object_exports as Objects } from './chunk-DVD5PAXO.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,
@@ -641,12 +713,24 @@ function createObjectSet2(objectType, clientCtx, objectSet = {
641
713
  }
642
714
 
643
715
  // src/ObjectSetCreator.ts
644
- function createObjectSetCreator(client) {
716
+ function createObjectSetCreator(client, clientContext) {
645
717
  return new Proxy({}, {
646
718
  get: (target, p, receiver) => {
647
719
  if (typeof p === "string")
648
720
  return client.objectSet(p);
649
721
  return void 0;
722
+ },
723
+ ownKeys(target) {
724
+ return Object.keys(clientContext.ontology.objects);
725
+ },
726
+ getOwnPropertyDescriptor(target, p) {
727
+ if (typeof p === "string") {
728
+ return {
729
+ enumerable: clientContext.ontology.objects[p] != null,
730
+ configurable: true,
731
+ value: client.objectSet(p)
732
+ };
733
+ }
650
734
  }
651
735
  });
652
736
  }
@@ -660,7 +744,7 @@ function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {
660
744
  get: () => objectSetFactory
661
745
  },
662
746
  objects: {
663
- get: () => createObjectSetCreator(client)
747
+ get: () => createObjectSetCreator(client, clientCtx)
664
748
  },
665
749
  actions: {
666
750
  get: () => createActionInvoker(clientCtx)
@@ -683,6 +767,6 @@ function createClient(ontology, stack, tokenProvider, fetchFn = fetch) {
683
767
  return client;
684
768
  }
685
769
 
686
- export { createClient };
770
+ export { ActionValidationError, createClient };
687
771
  //# sourceMappingURL=out.js.map
688
772
  //# sourceMappingURL=index.mjs.map