@osdk/client 2.3.0-beta.5 → 2.3.0-beta.7

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 (127) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/build/browser/actions/ActionValidationError.js.map +1 -1
  3. package/build/browser/actions/applyAction.js +9 -8
  4. package/build/browser/actions/applyAction.js.map +1 -1
  5. package/build/browser/createClient.js +8 -1
  6. package/build/browser/createClient.js.map +1 -1
  7. package/build/browser/logger/BaseLogger.js +1 -1
  8. package/build/browser/logger/BaseLogger.js.map +1 -1
  9. package/build/browser/object/mediaUpload.js +3 -0
  10. package/build/browser/object/mediaUpload.js.map +1 -1
  11. package/build/browser/observable/ObservableClient.js +17 -1
  12. package/build/browser/observable/ObservableClient.js.map +1 -1
  13. package/build/browser/observable/OptimisticBuilder.js.map +1 -1
  14. package/build/browser/observable/internal/ActionApplication.js +31 -30
  15. package/build/browser/observable/internal/ActionApplication.js.map +1 -1
  16. package/build/browser/observable/internal/Changes.js +5 -1
  17. package/build/browser/observable/internal/Changes.js.map +1 -1
  18. package/build/browser/observable/internal/ListQuery.js +24 -22
  19. package/build/browser/observable/internal/ListQuery.js.map +1 -1
  20. package/build/browser/observable/internal/ObjectQuery.js +30 -1
  21. package/build/browser/observable/internal/ObjectQuery.js.map +1 -1
  22. package/build/browser/observable/internal/ObservableClientImpl.js +1 -2
  23. package/build/browser/observable/internal/ObservableClientImpl.js.map +1 -1
  24. package/build/browser/observable/internal/OptimisticJob.js +8 -0
  25. package/build/browser/observable/internal/OptimisticJob.js.map +1 -1
  26. package/build/browser/observable/internal/Query.js +2 -2
  27. package/build/browser/observable/internal/Query.js.map +1 -1
  28. package/build/browser/observable/internal/Store.js +4 -0
  29. package/build/browser/observable/internal/Store.js.map +1 -1
  30. package/build/browser/observable/internal/Store.test.js +45 -5
  31. package/build/browser/observable/internal/Store.test.js.map +1 -1
  32. package/build/browser/observable/internal/testUtils.js.map +1 -1
  33. package/build/browser/observable/internal/tombstone.js +18 -0
  34. package/build/browser/observable/internal/tombstone.js.map +1 -0
  35. package/build/browser/util/UserAgent.js +2 -1
  36. package/build/browser/util/UserAgent.js.map +1 -1
  37. package/build/browser/util/extractRdpDefinition.js +2 -0
  38. package/build/browser/util/extractRdpDefinition.js.map +1 -1
  39. package/build/browser/util/toDataValue.js +20 -10
  40. package/build/browser/util/toDataValue.js.map +1 -1
  41. package/build/browser/util/toDataValue.test.js +50 -11
  42. package/build/browser/util/toDataValue.test.js.map +1 -1
  43. package/build/cjs/chunk-BITDNXFO.cjs +1804 -0
  44. package/build/cjs/chunk-BITDNXFO.cjs.map +1 -0
  45. package/build/cjs/{chunk-MZ4JZQUU.cjs → chunk-HTPVXLYY.cjs} +649 -42
  46. package/build/cjs/chunk-HTPVXLYY.cjs.map +1 -0
  47. package/build/cjs/index.cjs +16 -1769
  48. package/build/cjs/index.cjs.map +1 -1
  49. package/build/cjs/index.d.cts +4 -3
  50. package/build/cjs/public/internal.cjs +7 -8
  51. package/build/cjs/public/internal.cjs.map +1 -1
  52. package/build/cjs/public/unstable-do-not-use.cjs +182 -123
  53. package/build/cjs/public/unstable-do-not-use.cjs.map +1 -1
  54. package/build/cjs/public/unstable-do-not-use.d.cts +2 -1
  55. package/build/esm/actions/ActionValidationError.js.map +1 -1
  56. package/build/esm/actions/applyAction.js +9 -8
  57. package/build/esm/actions/applyAction.js.map +1 -1
  58. package/build/esm/createClient.js +8 -1
  59. package/build/esm/createClient.js.map +1 -1
  60. package/build/esm/logger/BaseLogger.js +1 -1
  61. package/build/esm/logger/BaseLogger.js.map +1 -1
  62. package/build/esm/object/mediaUpload.js +3 -0
  63. package/build/esm/object/mediaUpload.js.map +1 -1
  64. package/build/esm/observable/ObservableClient.js +17 -1
  65. package/build/esm/observable/ObservableClient.js.map +1 -1
  66. package/build/esm/observable/OptimisticBuilder.js.map +1 -1
  67. package/build/esm/observable/internal/ActionApplication.js +31 -30
  68. package/build/esm/observable/internal/ActionApplication.js.map +1 -1
  69. package/build/esm/observable/internal/Changes.js +5 -1
  70. package/build/esm/observable/internal/Changes.js.map +1 -1
  71. package/build/esm/observable/internal/ListQuery.js +24 -22
  72. package/build/esm/observable/internal/ListQuery.js.map +1 -1
  73. package/build/esm/observable/internal/ObjectQuery.js +30 -1
  74. package/build/esm/observable/internal/ObjectQuery.js.map +1 -1
  75. package/build/esm/observable/internal/ObservableClientImpl.js +1 -2
  76. package/build/esm/observable/internal/ObservableClientImpl.js.map +1 -1
  77. package/build/esm/observable/internal/OptimisticJob.js +8 -0
  78. package/build/esm/observable/internal/OptimisticJob.js.map +1 -1
  79. package/build/esm/observable/internal/Query.js +2 -2
  80. package/build/esm/observable/internal/Query.js.map +1 -1
  81. package/build/esm/observable/internal/Store.js +4 -0
  82. package/build/esm/observable/internal/Store.js.map +1 -1
  83. package/build/esm/observable/internal/Store.test.js +45 -5
  84. package/build/esm/observable/internal/Store.test.js.map +1 -1
  85. package/build/esm/observable/internal/testUtils.js.map +1 -1
  86. package/build/esm/observable/internal/tombstone.js +18 -0
  87. package/build/esm/observable/internal/tombstone.js.map +1 -0
  88. package/build/esm/util/UserAgent.js +2 -1
  89. package/build/esm/util/UserAgent.js.map +1 -1
  90. package/build/esm/util/extractRdpDefinition.js +2 -0
  91. package/build/esm/util/extractRdpDefinition.js.map +1 -1
  92. package/build/esm/util/toDataValue.js +20 -10
  93. package/build/esm/util/toDataValue.js.map +1 -1
  94. package/build/esm/util/toDataValue.test.js +50 -11
  95. package/build/esm/util/toDataValue.test.js.map +1 -1
  96. package/build/types/actions/ActionValidationError.d.ts +1 -1
  97. package/build/types/actions/ActionValidationError.d.ts.map +1 -1
  98. package/build/types/actions/applyAction.d.ts.map +1 -1
  99. package/build/types/createClient.d.ts.map +1 -1
  100. package/build/types/object/mediaUpload.d.ts +2 -1
  101. package/build/types/object/mediaUpload.d.ts.map +1 -1
  102. package/build/types/observable/ObservableClient.d.ts +2 -2
  103. package/build/types/observable/ObservableClient.d.ts.map +1 -1
  104. package/build/types/observable/OptimisticBuilder.d.ts +1 -0
  105. package/build/types/observable/OptimisticBuilder.d.ts.map +1 -1
  106. package/build/types/observable/internal/ActionApplication.d.ts +1 -1
  107. package/build/types/observable/internal/ActionApplication.d.ts.map +1 -1
  108. package/build/types/observable/internal/Changes.d.ts +2 -0
  109. package/build/types/observable/internal/Changes.d.ts.map +1 -1
  110. package/build/types/observable/internal/ListQuery.d.ts.map +1 -1
  111. package/build/types/observable/internal/ObjectQuery.d.ts +1 -0
  112. package/build/types/observable/internal/ObjectQuery.d.ts.map +1 -1
  113. package/build/types/observable/internal/OptimisticJob.d.ts.map +1 -1
  114. package/build/types/observable/internal/Store.d.ts +2 -1
  115. package/build/types/observable/internal/Store.d.ts.map +1 -1
  116. package/build/types/observable/internal/testUtils.d.ts +1 -1
  117. package/build/types/observable/internal/testUtils.d.ts.map +1 -1
  118. package/build/types/observable/internal/tombstone.d.ts +1 -0
  119. package/build/types/observable/internal/tombstone.d.ts.map +1 -0
  120. package/build/types/util/UserAgent.d.ts +1 -0
  121. package/build/types/util/UserAgent.d.ts.map +1 -1
  122. package/package.json +11 -11
  123. package/build/cjs/chunk-C5D7744G.cjs +0 -615
  124. package/build/cjs/chunk-C5D7744G.cjs.map +0 -1
  125. package/build/cjs/chunk-MZ4JZQUU.cjs.map +0 -1
  126. package/build/cjs/chunk-T4NIFYZS.cjs +0 -14
  127. package/build/cjs/chunk-T4NIFYZS.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @osdk/client
2
2
 
3
+ ## 2.3.0-beta.7
4
+
5
+ ### Minor Changes
6
+
7
+ - 2a23cca: ObservableClient now adds to the fetch-user-agent
8
+ - f8db93d: improve media upload (beta)
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [f8db93d]
13
+ - @osdk/generator-converters@2.3.0-beta.7
14
+ - @osdk/client.unstable@2.3.0-beta.7
15
+ - @osdk/api@2.3.0-beta.7
16
+
17
+ ## 2.3.0-beta.6
18
+
19
+ ### Minor Changes
20
+
21
+ - 9839eab: Bumps conjure-lite
22
+ - cd911a6: Properly handles lat,long strings in action arguments
23
+ - 2c800e5: Fix bug where we sent over longitude/latitude for geohash properties, when the backend actually expects latitude/longitude.
24
+ - cd911a6: ObservableClient can now do optimistic writes for deletes
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [9839eab]
29
+ - @osdk/client.unstable@2.3.0-beta.6
30
+ - @osdk/api@2.3.0-beta.6
31
+ - @osdk/generator-converters@2.3.0-beta.6
32
+
3
33
  ## 2.3.0-beta.5
4
34
 
5
35
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"ActionValidationError.js","names":["ActionValidationError","Error","constructor","validation","JSON","stringify"],"sources":["ActionValidationError.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ActionValidationResponse } from \"@osdk/api\";\n\nexport class ActionValidationError extends Error {\n constructor(public validation: ActionValidationResponse) {\n super(\"Validation Error: \" + JSON.stringify(validation, null, 2));\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,MAAMA,qBAAqB,SAASC,KAAK,CAAC;EAC/CC,WAAWA,CAAQC,UAAoC,EAAE;IACvD,KAAK,CAAC,oBAAoB,GAAGC,IAAI,CAACC,SAAS,CAACF,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAAC,KADjDA,UAAoC,GAApCA,UAAoC;EAEvD;AACF","ignoreList":[]}
1
+ {"version":3,"file":"ActionValidationError.js","names":["ActionValidationError","Error","constructor","validation","JSON","stringify"],"sources":["ActionValidationError.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ValidateActionResponseV2 as ActionValidationResponse } from \"@osdk/foundry.ontologies\";\n\nexport class ActionValidationError extends Error {\n constructor(public validation: ActionValidationResponse) {\n super(\"Validation Error: \" + JSON.stringify(validation, null, 2));\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,MAAMA,qBAAqB,SAASC,KAAK,CAAC;EAC/CC,WAAWA,CAAQC,UAAoC,EAAE;IACvD,KAAK,CAAC,oBAAoB,GAAGC,IAAI,CAACC,SAAS,CAACF,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAAC,KADjDA,UAAoC,GAApCA,UAAoC;EAEvD;AACF","ignoreList":[]}
@@ -25,7 +25,7 @@ export async function applyAction(client, action, parameters, options = {}) {
25
25
  })), action);
26
26
  if (Array.isArray(parameters)) {
27
27
  const response = await OntologiesV2.Actions.applyBatch(clientWithHeaders, await client.ontologyRid, action.apiName, {
28
- requests: parameters ? await remapBatchActionParams(parameters, client) : [],
28
+ requests: parameters ? await remapBatchActionParams(parameters, client, await client.ontologyProvider.getActionDefinition(action.apiName)) : [],
29
29
  options: {
30
30
  returnEdits: options?.$returnEdits ? "ALL" : "NONE"
31
31
  }
@@ -34,7 +34,7 @@ export async function applyAction(client, action, parameters, options = {}) {
34
34
  return options?.$returnEdits ? edits?.type === "edits" ? remapActionResponse(response) : edits : undefined;
35
35
  } else {
36
36
  const response = await OntologiesV2.Actions.apply(clientWithHeaders, await client.ontologyRid, action.apiName, {
37
- parameters: await remapActionParams(parameters, client),
37
+ parameters: await remapActionParams(parameters, client, await client.ontologyProvider.getActionDefinition(action.apiName)),
38
38
  options: {
39
39
  mode: options?.$validateOnly ? "VALIDATE_ONLY" : "VALIDATE_AND_EXECUTE",
40
40
  returnEdits: options?.$returnEdits ? "ALL_V2_WITH_DELETIONS" : "NONE"
@@ -43,27 +43,28 @@ export async function applyAction(client, action, parameters, options = {}) {
43
43
  if (options?.$validateOnly) {
44
44
  return response.validation;
45
45
  }
46
- if (response.validation?.result === "INVALID") {
47
- throw new ActionValidationError(response.validation);
46
+ if (response.validation && response.validation?.result === "INVALID") {
47
+ const validation = response.validation;
48
+ throw new ActionValidationError(validation);
48
49
  }
49
50
  const edits = response.edits;
50
51
  return options?.$returnEdits ? edits?.type === "edits" ? remapActionResponse(response) : edits : undefined;
51
52
  }
52
53
  }
53
- async function remapActionParams(params, client) {
54
+ async function remapActionParams(params, client, actionMetadata) {
54
55
  if (params == null) {
55
56
  return {};
56
57
  }
57
58
  const parameterMap = {};
58
59
  for (const [key, value] of Object.entries(params)) {
59
- parameterMap[key] = await toDataValue(value, client);
60
+ parameterMap[key] = await toDataValue(value, client, actionMetadata);
60
61
  }
61
62
  return parameterMap;
62
63
  }
63
- async function remapBatchActionParams(params, client) {
64
+ async function remapBatchActionParams(params, client, actionMetadata) {
64
65
  const remappedParams = await Promise.all(params.map(async param => {
65
66
  return {
66
- parameters: await remapActionParams(param, client)
67
+ parameters: await remapActionParams(param, client, actionMetadata)
67
68
  };
68
69
  }));
69
70
  return remappedParams;
@@ -1 +1 @@
1
- {"version":3,"file":"applyAction.js","names":["OntologiesV2","addUserAgentAndRequestContextHeaders","augmentRequestContext","toDataValue","ActionValidationError","applyAction","client","action","parameters","options","clientWithHeaders","finalMethodCall","Array","isArray","response","Actions","applyBatch","ontologyRid","apiName","requests","remapBatchActionParams","returnEdits","$returnEdits","edits","type","remapActionResponse","undefined","apply","remapActionParams","mode","$validateOnly","validation","result","params","parameterMap","key","value","Object","entries","remappedParams","Promise","all","map","param","editResponses","remappedActionResponse","deletedLinksCount","deletedObjectsCount","addedLinks","deletedLinks","addedObjects","deletedObjects","modifiedObjects","editedObjectTypes","editedObjectTypesSet","Set","edit","osdkEdit","linkTypeApiNameAtoB","linkTypeApiNameBtoA","aSideObject","bSideObject","push","add","objectType","primaryKey","process","env","NODE_ENV","console","warn","JSON","stringify"],"sources":["applyAction.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ActionDefinition,\n ActionEditResponse,\n ActionMetadata,\n ActionParam,\n ActionReturnTypeForOptions,\n ApplyActionOptions,\n ApplyBatchActionOptions,\n CompileTimeMetadata as CompileTimeActionMetadata,\n DataValueClientToWire,\n} from \"@osdk/api\";\nimport type {\n BatchApplyActionResponseV2,\n DataValue,\n SyncApplyActionResponseV2,\n} from \"@osdk/foundry.ontologies\";\nimport * as OntologiesV2 from \"@osdk/foundry.ontologies\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\nimport { addUserAgentAndRequestContextHeaders } from \"../util/addUserAgentAndRequestContextHeaders.js\";\nimport { augmentRequestContext } from \"../util/augmentRequestContext.js\";\nimport type { NOOP } from \"../util/NOOP.js\";\nimport type { NullableProps } from \"../util/NullableProps.js\";\nimport type { PartialBy } from \"../util/partialBy.js\";\nimport { toDataValue } from \"../util/toDataValue.js\";\nimport { ActionValidationError } from \"./ActionValidationError.js\";\n\ntype BaseType<APD extends Pick<ActionMetadata.Parameter<any>, \"type\">> =\n APD[\"type\"] extends ActionMetadata.DataType.Object<infer TTargetType>\n ? ActionParam.ObjectType<TTargetType>\n : APD[\"type\"] extends ActionMetadata.DataType.ObjectSet<infer TTargetType>\n ? ActionParam.ObjectSetType<TTargetType>\n : APD[\"type\"] extends ActionMetadata.DataType.Struct<infer TStructType>\n ? ActionParam.StructType<TStructType>\n : APD[\"type\"] extends keyof DataValueClientToWire\n ? ActionParam.PrimitiveType<APD[\"type\"]>\n : never;\n\ntype MaybeArrayType<APD extends ActionMetadata.Parameter<any>> =\n APD[\"multiplicity\"] extends true ? Array<BaseType<APD>>\n : BaseType<APD>;\n\ntype NotOptionalParams<X extends ActionParametersDefinition> = {\n [P in keyof X]: MaybeArrayType<X[P]>;\n};\n\nexport type OsdkActionParameters<\n X extends ActionParametersDefinition,\n> = NullableProps<X> extends never ? NotOptionalParams<X>\n : PartialBy<NotOptionalParams<X>, NullableProps<X>>;\n\nexport type ActionSignatureFromDef<\n T extends ActionDefinition<any>,\n> = {\n applyAction:\n [CompileTimeActionMetadata<T>[\"signatures\"][\"applyAction\"]] extends [never]\n ? ActionSignature<CompileTimeActionMetadata<T>[\"parameters\"]>\n : CompileTimeActionMetadata<T>[\"signatures\"][\"applyAction\"];\n\n batchApplyAction:\n [CompileTimeActionMetadata<T>[\"signatures\"][\"batchApplyAction\"]] extends\n [never] ? BatchActionSignature<CompileTimeActionMetadata<T>[\"parameters\"]>\n : CompileTimeActionMetadata<T>[\"signatures\"][\"batchApplyAction\"];\n};\n\ntype ActionParametersDefinition = Record<\n any,\n ActionMetadata.Parameter<any>\n>;\n\nexport type ActionSignature<\n X extends Record<any, ActionMetadata.Parameter<any>>,\n> = <\n A extends NOOP<OsdkActionParameters<X>>,\n OP extends ApplyActionOptions,\n>(\n args: A,\n options?: OP,\n) => Promise<\n ActionReturnTypeForOptions<OP>\n>;\n\nexport type BatchActionSignature<\n X extends Record<any, ActionMetadata.Parameter<any>>,\n> = <\n A extends NOOP<OsdkActionParameters<X>>[],\n OP extends ApplyBatchActionOptions,\n>(\n args: A,\n options?: OP,\n) => Promise<\n ActionReturnTypeForOptions<OP>\n>;\n\nexport async function applyAction<\n AD extends ActionDefinition<any>,\n P extends\n | OsdkActionParameters<CompileTimeActionMetadata<AD>[\"parameters\"]>\n | OsdkActionParameters<CompileTimeActionMetadata<AD>[\"parameters\"]>[],\n Op extends P extends OsdkActionParameters<\n CompileTimeActionMetadata<AD>[\"parameters\"]\n >[] ? ApplyBatchActionOptions\n : ApplyActionOptions,\n>(\n client: MinimalClient,\n action: AD,\n parameters?: P,\n options: Op = {} as Op,\n): Promise<\n ActionReturnTypeForOptions<Op>\n> {\n const clientWithHeaders = addUserAgentAndRequestContextHeaders(\n augmentRequestContext(client, _ => ({ finalMethodCall: \"applyAction\" })),\n action,\n );\n if (Array.isArray(parameters)) {\n const response = await OntologiesV2.Actions.applyBatch(\n clientWithHeaders,\n await client.ontologyRid,\n action.apiName,\n {\n requests: parameters\n ? await remapBatchActionParams(parameters, client)\n : [],\n options: {\n returnEdits: options?.$returnEdits ? \"ALL\" : \"NONE\",\n },\n },\n );\n\n const edits = response.edits;\n return (options?.$returnEdits\n ? edits?.type === \"edits\" ? remapActionResponse(response) : edits\n : undefined) as ActionReturnTypeForOptions<Op>;\n } else {\n const response = await OntologiesV2.Actions.apply(\n clientWithHeaders,\n await client.ontologyRid,\n action.apiName,\n {\n parameters: await remapActionParams(\n parameters as OsdkActionParameters<\n CompileTimeActionMetadata<AD>[\"parameters\"]\n >,\n client,\n ),\n options: {\n mode: (options as ApplyActionOptions)?.$validateOnly\n ? \"VALIDATE_ONLY\"\n : \"VALIDATE_AND_EXECUTE\",\n returnEdits: options\n ?.$returnEdits\n ? \"ALL_V2_WITH_DELETIONS\"\n : \"NONE\",\n },\n },\n );\n\n if ((options as ApplyActionOptions)?.$validateOnly) {\n return response.validation as ActionReturnTypeForOptions<Op>;\n }\n\n if (response.validation?.result === \"INVALID\") {\n throw new ActionValidationError(response.validation);\n }\n\n const edits = response.edits;\n return (options?.$returnEdits\n ? edits?.type === \"edits\" ? remapActionResponse(response) : edits\n : undefined) as ActionReturnTypeForOptions<Op>;\n }\n}\n\nasync function remapActionParams<AD extends ActionDefinition<any>>(\n params:\n | OsdkActionParameters<CompileTimeActionMetadata<AD>[\"parameters\"]>\n | undefined,\n client: MinimalClient,\n): Promise<Record<string, DataValue>> {\n if (params == null) {\n return {};\n }\n\n const parameterMap: { [parameterName: string]: unknown } = {};\n for (const [key, value] of Object.entries(params)) {\n parameterMap[key] = await toDataValue(value, client);\n }\n\n return parameterMap;\n}\n\nasync function remapBatchActionParams<\n AD extends ActionDefinition<any>,\n>(\n params: OsdkActionParameters<CompileTimeActionMetadata<AD>[\"parameters\"]>[],\n client: MinimalClient,\n) {\n const remappedParams = await Promise.all(params.map(\n async param => {\n return { parameters: await remapActionParams<AD>(param, client) };\n },\n ));\n\n return remappedParams;\n}\n\nexport function remapActionResponse(\n response: SyncApplyActionResponseV2 | BatchApplyActionResponseV2,\n): ActionEditResponse | undefined {\n const editResponses = response?.edits;\n if (editResponses?.type === \"edits\") {\n const remappedActionResponse: ActionEditResponse = {\n type: editResponses.type,\n deletedLinksCount: editResponses.deletedLinksCount,\n deletedObjectsCount: editResponses.deletedObjectsCount,\n addedLinks: [],\n deletedLinks: [],\n addedObjects: [],\n deletedObjects: [],\n modifiedObjects: [],\n editedObjectTypes: [],\n };\n\n const editedObjectTypesSet = new Set<string>();\n for (const edit of editResponses.edits) {\n if (edit.type === \"addLink\" || edit.type === \"deleteLink\") {\n const osdkEdit = {\n linkTypeApiNameAtoB: edit.linkTypeApiNameAtoB,\n linkTypeApiNameBtoA: edit.linkTypeApiNameBtoA,\n aSideObject: edit.aSideObject,\n bSideObject: edit.bSideObject,\n };\n edit.type === \"addLink\"\n ? remappedActionResponse.addedLinks.push(\n osdkEdit,\n )\n : remappedActionResponse.deletedLinks?.push(osdkEdit);\n editedObjectTypesSet.add(edit.aSideObject.objectType);\n editedObjectTypesSet.add(edit.bSideObject.objectType);\n } else if (\n edit.type === \"addObject\" || edit.type === \"deleteObject\"\n || edit.type === \"modifyObject\"\n ) {\n const osdkEdit = {\n objectType: edit.objectType,\n primaryKey: edit.primaryKey,\n };\n if (edit.type === \"addObject\") {\n remappedActionResponse.addedObjects.push(osdkEdit);\n } else if (edit.type === \"deleteObject\") {\n remappedActionResponse.deletedObjects?.push(osdkEdit);\n } else if (edit.type === \"modifyObject\") {\n remappedActionResponse.modifiedObjects.push(osdkEdit);\n }\n editedObjectTypesSet.add(edit.objectType);\n } else {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\n `Unexpected edit type: ${JSON.stringify(edit)}`,\n );\n }\n }\n }\n remappedActionResponse.editedObjectTypes = [...editedObjectTypesSet];\n return remappedActionResponse;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA,OAAO,KAAKA,YAAY,MAAM,0BAA0B;AAExD,SAASC,oCAAoC,QAAQ,iDAAiD;AACtG,SAASC,qBAAqB,QAAQ,kCAAkC;AAIxE,SAASC,WAAW,QAAQ,wBAAwB;AACpD,SAASC,qBAAqB,QAAQ,4BAA4B;AAqElE,OAAO,eAAeC,WAAWA,CAU/BC,MAAqB,EACrBC,MAAU,EACVC,UAAc,EACdC,OAAW,GAAG,CAAC,CAAO,EAGtB;EACA,MAAMC,iBAAiB,GAAGT,oCAAoC,CAC5DC,qBAAqB,CAACI,MAAM,EAAE,OAAM;IAAEK,eAAe,EAAE;EAAc,CAAC,CAAC,CAAC,EACxEJ,MACF,CAAC;EACD,IAAIK,KAAK,CAACC,OAAO,CAACL,UAAU,CAAC,EAAE;IAC7B,MAAMM,QAA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AAsB,CAACO,eAAe,CAACU,IAAI,CAACL,QAAQ,CAAC;QACvD;QACAH,oBAAoB,CAACS,GAAG,CAACP,IAAI,CAACQ,UAAU,CAAC;MAC3C,CAAC,MAAM;QACL,IAAIE,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,EAAE;UACzC;UACAC,OAAO,CAACC,IAAI,CACV,yBAAyBC,IAAI,CAACC,SAAS,CAAChB,IAAI,CAAC,EAC/C,CAAC;QACH;MACF;IACF;IACAX,sBAAsB,CAACQ,iBAAiB,GAAG,CAAC,GAAGC,oBAAoB,CAAC;IACpE,OAAOT,sBAAsB;EAC/B;AACF","ignoreList":[]}
1
+ {"version":3,"file":"applyAction.js","names":["OntologiesV2","addUserAgentAndRequestContextHeaders","augmentRequestContext","toDataValue","ActionValidationError","applyAction","client","action","parameters","options","clientWithHeaders","finalMethodCall","Array","isArray","response","Actions","applyBatch","ontologyRid","apiName","requests","remapBatchActionParams","ontologyProvider","getActionDefinition","returnEdits","$returnEdits","edits","type","remapActionResponse","undefined","apply","remapActionParams","mode","$validateOnly","validation","result","params","actionMetadata","parameterMap","key","value","Object","entries","remappedParams","Promise","all","map","param","editResponses","remappedActionResponse","deletedLinksCount","deletedObjectsCount","addedLinks","deletedLinks","addedObjects","deletedObjects","modifiedObjects","editedObjectTypes","editedObjectTypesSet","Set","edit","osdkEdit","linkTypeApiNameAtoB","linkTypeApiNameBtoA","aSideObject","bSideObject","push","add","objectType","primaryKey","process","env","NODE_ENV","console","warn","JSON","stringify"],"sources":["applyAction.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ActionDefinition,\n ActionEditResponse,\n ActionMetadata,\n ActionParam,\n ActionReturnTypeForOptions,\n ApplyActionOptions,\n ApplyBatchActionOptions,\n CompileTimeMetadata as CompileTimeActionMetadata,\n DataValueClientToWire,\n} from \"@osdk/api\";\nimport type {\n BatchApplyActionResponseV2,\n DataValue,\n SyncApplyActionResponseV2,\n} from \"@osdk/foundry.ontologies\";\nimport * as OntologiesV2 from \"@osdk/foundry.ontologies\";\nimport type { MinimalClient } from \"../MinimalClientContext.js\";\nimport { addUserAgentAndRequestContextHeaders } from \"../util/addUserAgentAndRequestContextHeaders.js\";\nimport { augmentRequestContext } from \"../util/augmentRequestContext.js\";\nimport type { NOOP } from \"../util/NOOP.js\";\nimport type { NullableProps } from \"../util/NullableProps.js\";\nimport type { PartialBy } from \"../util/partialBy.js\";\nimport { toDataValue } from \"../util/toDataValue.js\";\nimport { ActionValidationError } from \"./ActionValidationError.js\";\n\ntype BaseType<APD extends Pick<ActionMetadata.Parameter<any>, \"type\">> =\n APD[\"type\"] extends ActionMetadata.DataType.Object<infer TTargetType>\n ? ActionParam.ObjectType<TTargetType>\n : APD[\"type\"] extends ActionMetadata.DataType.ObjectSet<infer TTargetType>\n ? ActionParam.ObjectSetType<TTargetType>\n : APD[\"type\"] extends ActionMetadata.DataType.Struct<infer TStructType>\n ? ActionParam.StructType<TStructType>\n : APD[\"type\"] extends keyof DataValueClientToWire\n ? ActionParam.PrimitiveType<APD[\"type\"]>\n : never;\n\ntype MaybeArrayType<APD extends ActionMetadata.Parameter<any>> =\n APD[\"multiplicity\"] extends true ? Array<BaseType<APD>>\n : BaseType<APD>;\n\ntype NotOptionalParams<X extends ActionParametersDefinition> = {\n [P in keyof X]: MaybeArrayType<X[P]>;\n};\n\nexport type OsdkActionParameters<\n X extends ActionParametersDefinition,\n> = NullableProps<X> extends never ? NotOptionalParams<X>\n : PartialBy<NotOptionalParams<X>, NullableProps<X>>;\n\nexport type ActionSignatureFromDef<\n T extends ActionDefinition<any>,\n> = {\n applyAction:\n [CompileTimeActionMetadata<T>[\"signatures\"][\"applyAction\"]] extends [never]\n ? ActionSignature<CompileTimeActionMetadata<T>[\"parameters\"]>\n : CompileTimeActionMetadata<T>[\"signatures\"][\"applyAction\"];\n\n batchApplyAction:\n [CompileTimeActionMetadata<T>[\"signatures\"][\"batchApplyAction\"]] extends\n [never] ? BatchActionSignature<CompileTimeActionMetadata<T>[\"parameters\"]>\n : CompileTimeActionMetadata<T>[\"signatures\"][\"batchApplyAction\"];\n};\n\ntype ActionParametersDefinition = Record<\n any,\n ActionMetadata.Parameter<any>\n>;\n\nexport type ActionSignature<\n X extends Record<any, ActionMetadata.Parameter<any>>,\n> = <\n A extends NOOP<OsdkActionParameters<X>>,\n OP extends ApplyActionOptions,\n>(\n args: A,\n options?: OP,\n) => Promise<\n ActionReturnTypeForOptions<OP>\n>;\n\nexport type BatchActionSignature<\n X extends Record<any, ActionMetadata.Parameter<any>>,\n> = <\n A extends NOOP<OsdkActionParameters<X>>[],\n OP extends ApplyBatchActionOptions,\n>(\n args: A,\n options?: OP,\n) => Promise<\n ActionReturnTypeForOptions<OP>\n>;\n\nexport async function applyAction<\n AD extends ActionDefinition<any>,\n P extends\n | OsdkActionParameters<CompileTimeActionMetadata<AD>[\"parameters\"]>\n | OsdkActionParameters<CompileTimeActionMetadata<AD>[\"parameters\"]>[],\n Op extends P extends OsdkActionParameters<\n CompileTimeActionMetadata<AD>[\"parameters\"]\n >[] ? ApplyBatchActionOptions\n : ApplyActionOptions,\n>(\n client: MinimalClient,\n action: AD,\n parameters?: P,\n options: Op = {} as Op,\n): Promise<\n ActionReturnTypeForOptions<Op>\n> {\n const clientWithHeaders = addUserAgentAndRequestContextHeaders(\n augmentRequestContext(client, _ => ({ finalMethodCall: \"applyAction\" })),\n action,\n );\n if (Array.isArray(parameters)) {\n const response = await OntologiesV2.Actions.applyBatch(\n clientWithHeaders,\n await client.ontologyRid,\n action.apiName,\n {\n requests: parameters\n ? await remapBatchActionParams(\n parameters,\n client,\n await client.ontologyProvider.getActionDefinition(action.apiName),\n )\n : [],\n options: {\n returnEdits: options?.$returnEdits ? \"ALL\" : \"NONE\",\n },\n },\n );\n\n const edits = response.edits;\n return (options?.$returnEdits\n ? edits?.type === \"edits\" ? remapActionResponse(response) : edits\n : undefined) as ActionReturnTypeForOptions<Op>;\n } else {\n const response = await OntologiesV2.Actions.apply(\n clientWithHeaders,\n await client.ontologyRid,\n action.apiName,\n {\n parameters: await remapActionParams(\n parameters as OsdkActionParameters<\n CompileTimeActionMetadata<AD>[\"parameters\"]\n >,\n client,\n await client.ontologyProvider.getActionDefinition(action.apiName),\n ),\n options: {\n mode: (options as ApplyActionOptions)?.$validateOnly\n ? \"VALIDATE_ONLY\"\n : \"VALIDATE_AND_EXECUTE\",\n returnEdits: options\n ?.$returnEdits\n ? \"ALL_V2_WITH_DELETIONS\"\n : \"NONE\",\n },\n },\n );\n\n if ((options as ApplyActionOptions)?.$validateOnly) {\n return response.validation as ActionReturnTypeForOptions<Op>;\n }\n\n if (response.validation && response.validation?.result === \"INVALID\") {\n const validation = response.validation;\n throw new ActionValidationError(validation);\n }\n\n const edits = response.edits;\n return (options?.$returnEdits\n ? edits?.type === \"edits\" ? remapActionResponse(response) : edits\n : undefined) as ActionReturnTypeForOptions<Op>;\n }\n}\n\nasync function remapActionParams<AD extends ActionDefinition<any>>(\n params:\n | OsdkActionParameters<CompileTimeActionMetadata<AD>[\"parameters\"]>\n | undefined,\n client: MinimalClient,\n actionMetadata: ActionMetadata,\n): Promise<Record<string, DataValue>> {\n if (params == null) {\n return {};\n }\n\n const parameterMap: { [parameterName: string]: unknown } = {};\n for (const [key, value] of Object.entries(params)) {\n parameterMap[key] = await toDataValue(value, client, actionMetadata);\n }\n\n return parameterMap;\n}\n\nasync function remapBatchActionParams<\n AD extends ActionDefinition<any>,\n>(\n params: OsdkActionParameters<CompileTimeActionMetadata<AD>[\"parameters\"]>[],\n client: MinimalClient,\n actionMetadata: ActionMetadata,\n) {\n const remappedParams = await Promise.all(params.map(\n async param => {\n return {\n parameters: await remapActionParams<AD>(param, client, actionMetadata),\n };\n },\n ));\n\n return remappedParams;\n}\n\nexport function remapActionResponse(\n response: SyncApplyActionResponseV2 | BatchApplyActionResponseV2,\n): ActionEditResponse | undefined {\n const editResponses = response?.edits;\n if (editResponses?.type === \"edits\") {\n const remappedActionResponse: ActionEditResponse = {\n type: editResponses.type,\n deletedLinksCount: editResponses.deletedLinksCount,\n deletedObjectsCount: editResponses.deletedObjectsCount,\n addedLinks: [],\n deletedLinks: [],\n addedObjects: [],\n deletedObjects: [],\n modifiedObjects: [],\n editedObjectTypes: [],\n };\n\n const editedObjectTypesSet = new Set<string>();\n for (const edit of editResponses.edits) {\n if (edit.type === \"addLink\" || edit.type === \"deleteLink\") {\n const osdkEdit = {\n linkTypeApiNameAtoB: edit.linkTypeApiNameAtoB,\n linkTypeApiNameBtoA: edit.linkTypeApiNameBtoA,\n aSideObject: edit.aSideObject,\n bSideObject: edit.bSideObject,\n };\n edit.type === \"addLink\"\n ? remappedActionResponse.addedLinks.push(\n osdkEdit,\n )\n : remappedActionResponse.deletedLinks?.push(osdkEdit);\n editedObjectTypesSet.add(edit.aSideObject.objectType);\n editedObjectTypesSet.add(edit.bSideObject.objectType);\n } else if (\n edit.type === \"addObject\" || edit.type === \"deleteObject\"\n || edit.type === \"modifyObject\"\n ) {\n const osdkEdit = {\n objectType: edit.objectType,\n primaryKey: edit.primaryKey,\n };\n if (edit.type === \"addObject\") {\n remappedActionResponse.addedObjects.push(osdkEdit);\n } else if (edit.type === \"deleteObject\") {\n remappedActionResponse.deletedObjects?.push(osdkEdit);\n } else if (edit.type === \"modifyObject\") {\n remappedActionResponse.modifiedObjects.push(osdkEdit);\n }\n editedObjectTypesSet.add(edit.objectType);\n } else {\n if (process.env.NODE_ENV !== \"production\") {\n // eslint-disable-next-line no-console\n console.warn(\n `Unexpected edit type: ${JSON.stringify(edit)}`,\n );\n }\n }\n }\n remappedActionResponse.editedObjectTypes = [...editedObjectTypesSet];\n return remappedActionResponse;\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBA,OAAO,KAAKA,YAAY,MAAM,0BAA0B;AAExD,SAASC,oCAAoC,QAAQ,iDAAiD;AACtG,SAASC,qBAAqB,QAAQ,kCAAkC;AAIxE,SAASC,WAAW,QAAQ,wBAAwB;AACpD,SAASC,qBAAqB,QAAQ,4BAA4B;AAqElE,OAAO,eAAeC,WAAWA,CAU/BC,MAAqB,EACrBC,MAAU,EACVC,UAAc,EACdC,OAAW,GAAG,CAAC,CAAO,EAGtB;EACA,MAAMC,iBAAiB,GAAGT,oCAAoC,CAC5DC,qBAAqB,CAACI,MAAM,EAAE,OAAM;IAAEK,eAAe,EAAE;EAAc,CAAC,CAAC,CAAC,EACxEJ,MACF,CAAC;EACD,IAAIK,KAAK,CAACC,OAAO,CAACL,UAAU,CAAC,EAAE;IAC7B,MAAMM,QAAQ,GAAG,MAAMd,YAAY,CAACe,OAAO,CAACC,UAAU,CACpDN,iBAAiB,EACjB,MAAMJ,MAAM,CAACW,WAAW,EACxBV,MAAM,CAACW,OAAO,EACd;MACEC,QAAQ,EAAEX,UAAU,GAChB,MAAMY,sBAAsB,CAC5BZ,UAAU,EACVF,MAAM,EACN,MAAMA,MAAM,CAACe,gBAAgB,CAACC,mBAAmB,CAACf,MAAM,CAACW,OAAO,CAClE,CAAC,GACC,EAAE;MACNT,OAAO,EAAE;QACPc,WAAW,EAAEd,OAAO,EAAEe,YAAY,GAAG,KAAK,GAAG;MAC/C;IACF,CACF,CAAC;IAED,MAAMC,KAAK,GAAGX,QAAQ,CAACW,KAAK;IAC5B,OAAQhB,OAAO,EAAEe,YAAY,GACzBC,KAAK,EAAEC,IAAI,KAAK,OAAO,GAAGC,mBAAmB,CAACb,QAAQ,CAAC,GAAGW,KA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AAC;QACH;MACF;IACF;IACAX,sBAAsB,CAACQ,iBAAiB,GAAG,CAAC,GAAGC,oBAAoB,CAAC;IACpE,OAAOT,sBAAsB;EAC/B;AACF","ignoreList":[]}
@@ -73,10 +73,17 @@ baseUrl, ontologyRid, tokenProvider, options = undefined, fetchFn = fetch) {
73
73
  ...options,
74
74
  logger: options?.logger ?? new MinimalLogger()
75
75
  }, fetchFn, objectSetFactory);
76
+ return createClientFromContext(clientCtx);
77
+ }
78
+
79
+ /**
80
+ * @internal
81
+ */
82
+ export function createClientFromContext(clientCtx) {
76
83
  const fetchMetadata = fetchMetadataInternal.bind(undefined, clientCtx);
77
84
  const client = Object.defineProperties(function (o) {
78
85
  if (o.type === "object" || o.type === "interface") {
79
- return objectSetFactory(o, clientCtx);
86
+ return clientCtx.objectSetFactory(o, clientCtx);
80
87
  } else if (o.type === "action") {
81
88
  return new ActionInvoker(clientCtx, o); // then as any for dealing with the conditional return value
82
89
  } else if (o.type === "query") {
@@ -1 +1 @@
1
- {"version":3,"file":"createClient.js","names":["__EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference","__EXPERIMENTAL__NOT_SUPPORTED_YET__fetchOneByRid","__EXPERIMENTAL__NOT_SUPPORTED_YET__fetchPageByRid","__EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks","OntologiesV2","symbolClientContext","oldSymbolClientContext","createBulkLinksAsyncIterFactory","applyAction","additionalContext","createMinimalClient","fetchMetadataInternal","MinimalLogger","fetchPage","fetchSingle","createObjectSet","applyQuery","ActionInvoker","constructor","clientCtx","actionDef","bind","undefined","batchApplyAction","QueryInvoker","queryDef","executeFunction","createClientInternal","objectSetFactory","baseUrl","ontologyRid","tokenProvider","options","fetchFn","fetch","startsWith","Error","then","logger","fetchMetadata","client","Object","defineProperties","o","type","name","getBulkLinks","fetchOneByRid","objectType","rid","createWithRid","createMediaReference","args","data","fileName","propertyType","MediaReferenceProperties","upload","apiName","mediaItemPath","preview","fetchPageByRid","objectOrInterfaceType","rids","value","createClient"],"sources":["createClient.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ActionDefinition,\n FetchPageArgs,\n InterfaceDefinition,\n Logger,\n NullabilityAdherence,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SelectArg,\n} from \"@osdk/api\";\nimport type {\n Experiment,\n ExperimentFns,\n MinimalObjectSet,\n} from \"@osdk/api/unstable\";\nimport {\n __EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference,\n __EXPERIMENTAL__NOT_SUPPORTED_YET__fetchOneByRid,\n __EXPERIMENTAL__NOT_SUPPORTED_YET__fetchPageByRid,\n __EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks,\n} from \"@osdk/api/unstable\";\nimport type { ObjectSet as WireObjectSet } from \"@osdk/foundry.ontologies\";\nimport * as OntologiesV2 from \"@osdk/foundry.ontologies\";\nimport { symbolClientContext as oldSymbolClientContext } from \"@osdk/shared.client\";\nimport { createBulkLinksAsyncIterFactory } from \"./__unstable/createBulkLinksAsyncIterFactory.js\";\nimport type { ActionSignatureFromDef } from \"./actions/applyAction.js\";\nimport { applyAction } from \"./actions/applyAction.js\";\nimport { additionalContext, type Client } from \"./Client.js\";\nimport { createMinimalClient } from \"./createMinimalClient.js\";\nimport { fetchMetadataInternal } from \"./fetchMetadata.js\";\nimport { MinimalLogger } from \"./logger/MinimalLogger.js\";\nimport type { MinimalClient } from \"./MinimalClientContext.js\";\nimport { fetchPage } from \"./object/fetchPage.js\";\nimport { fetchSingle } from \"./object/fetchSingle.js\";\nimport { createObjectSet } from \"./objectSet/createObjectSet.js\";\nimport type { ObjectSetFactory } from \"./objectSet/ObjectSetFactory.js\";\nimport { applyQuery } from \"./queries/applyQuery.js\";\nimport type { QuerySignatureFromDef } from \"./queries/types.js\";\n\n// We import it this way to keep compatible with CJS. If we referenced the\n// value of `symbolClientContext` directly, then we would have to a dynamic import\n// in `createClientInternal` which would make it async and a break.\n// Since this is just a string in `@osdk/shared.client2` instead of a symbol,\n// we can safely perform this trick.\ntype newSymbolClientContext =\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n typeof import(\"@osdk/shared.client2\").symbolClientContext;\n\nclass ActionInvoker<Q extends ActionDefinition<any>>\n implements ActionSignatureFromDef<Q>\n{\n constructor(\n clientCtx: MinimalClient,\n actionDef: ActionDefinition<any>,\n ) {\n // We type the property as a generic function as binding `applyAction`\n // doesn't return a type thats all that useful anyway\n // The implements covers us for the most part here as this exact type doesn't\n // escape this file\n this.applyAction = applyAction.bind(undefined, clientCtx, actionDef);\n this.batchApplyAction = applyAction.bind(undefined, clientCtx, actionDef);\n }\n\n applyAction: (...args: any[]) => any;\n batchApplyAction: (...args: any[]) => any;\n}\n\nclass QueryInvoker<Q extends QueryDefinition<any>>\n implements QuerySignatureFromDef<Q>\n{\n constructor(\n clientCtx: MinimalClient,\n queryDef: QueryDefinition<any>,\n ) {\n this.executeFunction = applyQuery.bind(undefined, clientCtx, queryDef);\n }\n\n executeFunction: (...args: any[]) => any;\n}\n\n/** @internal */\nexport function createClientInternal(\n objectSetFactory: ObjectSetFactory<any, any>, // first so i can bind\n baseUrl: string,\n ontologyRid: string | Promise<string>,\n tokenProvider: () => Promise<string>,\n options: { logger?: Logger } | undefined = undefined,\n fetchFn: typeof globalThis.fetch = fetch,\n): Client {\n if (typeof ontologyRid === \"string\") {\n if (!ontologyRid.startsWith(\"ri.\")) {\n throw new Error(\"Invalid ontology RID\");\n }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n ontologyRid.then((ontologyRid) => {\n if (!ontologyRid.startsWith(\"ri.\")) {\n // FIXME this promise is not await so this just shows up as an unhandled promise rejection\n throw new Error(\"Invalid ontology RID\");\n }\n });\n }\n\n const clientCtx: MinimalClient = createMinimalClient(\n { ontologyRid },\n baseUrl,\n tokenProvider,\n { ...options, logger: options?.logger ?? new MinimalLogger() },\n fetchFn,\n objectSetFactory,\n );\n\n function clientFn<\n T extends\n | ObjectOrInterfaceDefinition\n | ActionDefinition<any>\n | QueryDefinition<any>\n | Experiment<\"2.0.8\">\n | Experiment<\"2.1.0\">,\n >(o: T): T extends ObjectTypeDefinition ? ObjectSet<T>\n : T extends InterfaceDefinition ? MinimalObjectSet<T>\n : T extends ActionDefinition<any> ? ActionSignatureFromDef<T>\n : T extends QueryDefinition<any> ? QuerySignatureFromDef<T>\n : T extends Experiment<\"2.0.8\"> | Experiment<\"2.1.0\">\n ? { invoke: ExperimentFns<T> }\n : never\n {\n if (o.type === \"object\" || o.type === \"interface\") {\n return objectSetFactory(o, clientCtx) as any;\n } else if (o.type === \"action\") {\n return new ActionInvoker(\n clientCtx,\n o,\n ) as (T extends ActionDefinition<any>\n // first `as` to the action definition for our \"real\" typecheck\n ? ActionSignatureFromDef<T>\n : never) as any; // then as any for dealing with the conditional return value\n } else if (o.type === \"query\") {\n return new QueryInvoker(\n clientCtx,\n o,\n ) as (T extends QueryDefinition<any> ? QuerySignatureFromDef<T>\n : never) as any;\n } else if (o.type === \"experiment\") {\n switch (o.name) {\n case __EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks.name:\n return {\n getBulkLinks: createBulkLinksAsyncIterFactory(\n clientCtx,\n ),\n } as any;\n case __EXPERIMENTAL__NOT_SUPPORTED_YET__fetchOneByRid.name:\n return {\n fetchOneByRid: async <\n Q extends ObjectTypeDefinition,\n const L extends PropertyKeys<Q>,\n const R extends boolean,\n const S extends false | \"throw\" = NullabilityAdherence.Default,\n >(\n objectType: Q,\n rid: string,\n options: SelectArg<Q, L, R, S>,\n ) => {\n return await fetchSingle(\n clientCtx,\n objectType,\n options,\n createWithRid(\n [rid],\n ),\n ) as Osdk<Q>;\n },\n } as any;\n case __EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference.name:\n return {\n createMediaReference: async <\n Q extends ObjectTypeDefinition,\n const L extends PropertyKeys.Filtered<Q, \"mediaReference\">,\n >(args: {\n data: Blob;\n fileName: string;\n objectType: Q;\n propertyType: L;\n }) => {\n const { data, fileName, objectType, propertyType } = args;\n return await OntologiesV2.MediaReferenceProperties.upload(\n clientCtx,\n await clientCtx.ontologyRid,\n objectType.apiName,\n propertyType as string,\n data,\n {\n mediaItemPath: fileName,\n preview: true,\n },\n );\n },\n } as any;\n\n case __EXPERIMENTAL__NOT_SUPPORTED_YET__fetchPageByRid.name:\n return {\n fetchPageByRid: async <\n Q extends ObjectOrInterfaceDefinition,\n const L extends PropertyKeys<Q>,\n const R extends boolean,\n const S extends false | \"throw\" = NullabilityAdherence.Default,\n >(\n objectOrInterfaceType: Q,\n rids: string[],\n options: FetchPageArgs<Q, L, R, any, S> = {},\n ) => {\n return await fetchPage(\n clientCtx,\n objectOrInterfaceType,\n options,\n createWithRid(rids),\n );\n },\n } as any;\n }\n\n throw new Error(\"not implemented\");\n } else {\n throw new Error(\"not implemented\");\n }\n }\n\n const fetchMetadata = fetchMetadataInternal.bind(\n undefined,\n clientCtx,\n );\n\n const symbolClientContext: newSymbolClientContext = \"__osdkClientContext\";\n\n const client: Client = Object.defineProperties<Client>(\n clientFn as Client,\n {\n [oldSymbolClientContext]: {\n value: clientCtx,\n },\n [symbolClientContext]: {\n value: clientCtx,\n },\n [additionalContext]: {\n value: clientCtx,\n },\n fetchMetadata: {\n value: fetchMetadata,\n },\n } satisfies Record<keyof Client, PropertyDescriptor>,\n );\n\n return client;\n}\n\nexport const createClient: (\n baseUrl: string,\n ontologyRid: string | Promise<string>,\n tokenProvider: () => Promise<string>,\n options?: {\n logger?: Logger;\n } | undefined,\n fetchFn?: typeof fetch | undefined,\n) => Client = createClientInternal.bind(\n undefined,\n createObjectSet,\n);\n\nfunction createWithRid(\n rids: string[],\n) {\n const withRid: WireObjectSet = {\n type: \"static\",\n \"objects\": rids,\n };\n\n return withRid;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqBA,SACEA,uDAAuD,EACvDC,gDAAgD,EAChDC,iDAAiD,EACjDC,+CAA+C,QAC1C,oBAAoB;AAE3B,OAAO,KAAKC,YAAY,MAAM,0BAA0B;AACxD,SAASC,mBAAmB,IAAIC,sBAAsB,QAAQ,qBAAqB;AACnF,SAASC,+BAA+B,QAAQ,iDAAiD;AAEjG,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,iBAAiB,QAAqB,aAAa;AAC5D,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,qBAAqB,QAAQ,oBAAoB;AAC1D,SAASC,aAAa,QAAQ,2BAA2B;AAEzD,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,WAAW,QAAQ,yBAAyB;AACrD,SAASC,eAAe,QAAQ,gCAAgC;AAEhE,SAASC,UAAU,QAAQ,yBAAyB;;AAGpD;AACA;AACA;AACA;AACA;;AAKA,MAAMC,aAAa,CAEnB;EACEC,WAAWA,CACTC,SAAwB,EACxBC,SAAgC,EAChC;IACA;IACA;IACA;IACA;IACA,IAAI,CAACZ,WAAW,GAAGA,WAAW,CAACa,IAAI,CAACC,SAAS,EAAEH,SAAS,EAAEC,SAAS,CAAC;IACpE,IAAI,CAACG,gBAAgB,GAAGf,WAAW,CAACa,IAAI,CAACC,SAAS,EAAEH,SAAS,EAAEC,SAAS,CAAC;EAC3E;AAIF;AAEA,MAAMI,YAAY,CAElB;EACEN,WAAWA,CACTC,SAAwB,EACxBM,QAA8B,EAC9B;IACA,IAAI,CAACC,eAAe,GAA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AAI,CACpB,CAAC;YACH;UACF,CAAC;MACL;MAEA,MAAM,IAAI3B,KAAK,CAAC,iBAAiB,CAAC;IACpC,CAAC,MAAM;MACL,MAAM,IAAIA,KAAK,CAAC,iBAAiB,CAAC;IACpC;EACF,CAAC,EAWC;IACE,CAAC9B,sBAAsB,GAAG;MACxB0D,KAAK,EAAE7C;IACT,CAAC;IACD,CARgD,qBAAqB,GAQ9C;MACrB6C,KAAK,EAAE7C;IACT,CAAC;IACD,CAACV,iBAAiB,GAAG;MACnBuD,KAAK,EAAE7C;IACT,CAAC;IACDoB,aAAa,EAAE;MACbyB,KAAK,EAAEzB;IACT;EACF,CACF,CAAC;EAED,OAAOC,MAAM;AACf;AAEA,OAAO,MAAMyB,YAQF,GAAGtC,oBAAoB,CAACN,IAAI,CACrCC,SAAS,EACTP,eACF,CAAC;AAED,SAASmC,aAAaA,CACpBa,IAAc,EACd;EAMA,OAL+B;IAC7BnB,IAAI,EAAE,QAAQ;IACd,SAAS,EAAEmB;EACb,CAAC;AAGH","ignoreList":[]}
1
+ {"version":3,"file":"createClient.js","names":["__EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference","__EXPERIMENTAL__NOT_SUPPORTED_YET__fetchOneByRid","__EXPERIMENTAL__NOT_SUPPORTED_YET__fetchPageByRid","__EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks","OntologiesV2","symbolClientContext","oldSymbolClientContext","createBulkLinksAsyncIterFactory","applyAction","additionalContext","createMinimalClient","fetchMetadataInternal","MinimalLogger","fetchPage","fetchSingle","createObjectSet","applyQuery","ActionInvoker","constructor","clientCtx","actionDef","bind","undefined","batchApplyAction","QueryInvoker","queryDef","executeFunction","createClientInternal","objectSetFactory","baseUrl","ontologyRid","tokenProvider","options","fetchFn","fetch","startsWith","Error","then","logger","createClientFromContext","fetchMetadata","client","Object","defineProperties","o","type","name","getBulkLinks","fetchOneByRid","objectType","rid","createWithRid","createMediaReference","args","data","fileName","propertyType","MediaReferenceProperties","upload","apiName","mediaItemPath","preview","fetchPageByRid","objectOrInterfaceType","rids","value","createClient"],"sources":["createClient.ts"],"sourcesContent":["/*\n * Copyright 2024 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ActionDefinition,\n FetchPageArgs,\n InterfaceDefinition,\n Logger,\n NullabilityAdherence,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SelectArg,\n} from \"@osdk/api\";\nimport type {\n Experiment,\n ExperimentFns,\n MinimalObjectSet,\n} from \"@osdk/api/unstable\";\nimport {\n __EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference,\n __EXPERIMENTAL__NOT_SUPPORTED_YET__fetchOneByRid,\n __EXPERIMENTAL__NOT_SUPPORTED_YET__fetchPageByRid,\n __EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks,\n} from \"@osdk/api/unstable\";\nimport type { ObjectSet as WireObjectSet } from \"@osdk/foundry.ontologies\";\nimport * as OntologiesV2 from \"@osdk/foundry.ontologies\";\nimport { symbolClientContext as oldSymbolClientContext } from \"@osdk/shared.client\";\nimport { createBulkLinksAsyncIterFactory } from \"./__unstable/createBulkLinksAsyncIterFactory.js\";\nimport type { ActionSignatureFromDef } from \"./actions/applyAction.js\";\nimport { applyAction } from \"./actions/applyAction.js\";\nimport { additionalContext, type Client } from \"./Client.js\";\nimport { createMinimalClient } from \"./createMinimalClient.js\";\nimport { fetchMetadataInternal } from \"./fetchMetadata.js\";\nimport { MinimalLogger } from \"./logger/MinimalLogger.js\";\nimport type { MinimalClient } from \"./MinimalClientContext.js\";\nimport { fetchPage } from \"./object/fetchPage.js\";\nimport { fetchSingle } from \"./object/fetchSingle.js\";\nimport { createObjectSet } from \"./objectSet/createObjectSet.js\";\nimport type { ObjectSetFactory } from \"./objectSet/ObjectSetFactory.js\";\nimport { applyQuery } from \"./queries/applyQuery.js\";\nimport type { QuerySignatureFromDef } from \"./queries/types.js\";\n\n// We import it this way to keep compatible with CJS. If we referenced the\n// value of `symbolClientContext` directly, then we would have to a dynamic import\n// in `createClientInternal` which would make it async and a break.\n// Since this is just a string in `@osdk/shared.client2` instead of a symbol,\n// we can safely perform this trick.\ntype newSymbolClientContext =\n // eslint-disable-next-line @typescript-eslint/consistent-type-imports\n typeof import(\"@osdk/shared.client2\").symbolClientContext;\n\nclass ActionInvoker<Q extends ActionDefinition<any>>\n implements ActionSignatureFromDef<Q>\n{\n constructor(\n clientCtx: MinimalClient,\n actionDef: ActionDefinition<any>,\n ) {\n // We type the property as a generic function as binding `applyAction`\n // doesn't return a type thats all that useful anyway\n // The implements covers us for the most part here as this exact type doesn't\n // escape this file\n this.applyAction = applyAction.bind(undefined, clientCtx, actionDef);\n this.batchApplyAction = applyAction.bind(undefined, clientCtx, actionDef);\n }\n\n applyAction: (...args: any[]) => any;\n batchApplyAction: (...args: any[]) => any;\n}\n\nclass QueryInvoker<Q extends QueryDefinition<any>>\n implements QuerySignatureFromDef<Q>\n{\n constructor(\n clientCtx: MinimalClient,\n queryDef: QueryDefinition<any>,\n ) {\n this.executeFunction = applyQuery.bind(undefined, clientCtx, queryDef);\n }\n\n executeFunction: (...args: any[]) => any;\n}\n\n/** @internal */\nexport function createClientInternal(\n objectSetFactory: ObjectSetFactory<any, any>, // first so i can bind\n baseUrl: string,\n ontologyRid: string | Promise<string>,\n tokenProvider: () => Promise<string>,\n options: { logger?: Logger } | undefined = undefined,\n fetchFn: typeof globalThis.fetch = fetch,\n): Client {\n if (typeof ontologyRid === \"string\") {\n if (!ontologyRid.startsWith(\"ri.\")) {\n throw new Error(\"Invalid ontology RID\");\n }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n ontologyRid.then((ontologyRid) => {\n if (!ontologyRid.startsWith(\"ri.\")) {\n // FIXME this promise is not await so this just shows up as an unhandled promise rejection\n throw new Error(\"Invalid ontology RID\");\n }\n });\n }\n\n const clientCtx: MinimalClient = createMinimalClient(\n { ontologyRid },\n baseUrl,\n tokenProvider,\n { ...options, logger: options?.logger ?? new MinimalLogger() },\n fetchFn,\n objectSetFactory,\n );\n\n return createClientFromContext(clientCtx);\n}\n\n/**\n * @internal\n */\nexport function createClientFromContext(clientCtx: MinimalClient) {\n function clientFn<\n T extends\n | ObjectOrInterfaceDefinition\n | ActionDefinition<any>\n | QueryDefinition<any>\n | Experiment<\"2.0.8\">\n | Experiment<\"2.1.0\">,\n >(o: T): T extends ObjectTypeDefinition ? ObjectSet<T>\n : T extends InterfaceDefinition ? MinimalObjectSet<T>\n : T extends ActionDefinition<any> ? ActionSignatureFromDef<T>\n : T extends QueryDefinition<any> ? QuerySignatureFromDef<T>\n : T extends Experiment<\"2.0.8\"> | Experiment<\"2.1.0\">\n ? { invoke: ExperimentFns<T> }\n : never\n {\n if (o.type === \"object\" || o.type === \"interface\") {\n return clientCtx.objectSetFactory(o, clientCtx) as any;\n } else if (o.type === \"action\") {\n return new ActionInvoker(\n clientCtx,\n o,\n ) as (T extends ActionDefinition<any>\n // first `as` to the action definition for our \"real\" typecheck\n ? ActionSignatureFromDef<T>\n : never) as any; // then as any for dealing with the conditional return value\n } else if (o.type === \"query\") {\n return new QueryInvoker(\n clientCtx,\n o,\n ) as (T extends QueryDefinition<any> ? QuerySignatureFromDef<T>\n : never) as any;\n } else if (o.type === \"experiment\") {\n switch (o.name) {\n case __EXPERIMENTAL__NOT_SUPPORTED_YET__getBulkLinks.name:\n return {\n getBulkLinks: createBulkLinksAsyncIterFactory(\n clientCtx,\n ),\n } as any;\n case __EXPERIMENTAL__NOT_SUPPORTED_YET__fetchOneByRid.name:\n return {\n fetchOneByRid: async <\n Q extends ObjectTypeDefinition,\n const L extends PropertyKeys<Q>,\n const R extends boolean,\n const S extends false | \"throw\" = NullabilityAdherence.Default,\n >(\n objectType: Q,\n rid: string,\n options: SelectArg<Q, L, R, S>,\n ) => {\n return await fetchSingle(\n clientCtx,\n objectType,\n options,\n createWithRid(\n [rid],\n ),\n ) as Osdk<Q>;\n },\n } as any;\n case __EXPERIMENTAL__NOT_SUPPORTED_YET__createMediaReference.name:\n return {\n createMediaReference: async <\n Q extends ObjectTypeDefinition,\n const L extends PropertyKeys.Filtered<Q, \"mediaReference\">,\n >(args: {\n data: Blob;\n fileName: string;\n objectType: Q;\n propertyType: L;\n }) => {\n const { data, fileName, objectType, propertyType } = args;\n return await OntologiesV2.MediaReferenceProperties.upload(\n clientCtx,\n await clientCtx.ontologyRid,\n objectType.apiName,\n propertyType as string,\n data,\n {\n mediaItemPath: fileName,\n preview: true,\n },\n );\n },\n } as any;\n\n case __EXPERIMENTAL__NOT_SUPPORTED_YET__fetchPageByRid.name:\n return {\n fetchPageByRid: async <\n Q extends ObjectOrInterfaceDefinition,\n const L extends PropertyKeys<Q>,\n const R extends boolean,\n const S extends false | \"throw\" = NullabilityAdherence.Default,\n >(\n objectOrInterfaceType: Q,\n rids: string[],\n options: FetchPageArgs<Q, L, R, any, S> = {},\n ) => {\n return await fetchPage(\n clientCtx,\n objectOrInterfaceType,\n options,\n createWithRid(rids),\n );\n },\n } as any;\n }\n\n throw new Error(\"not implemented\");\n } else {\n throw new Error(\"not implemented\");\n }\n }\n\n const fetchMetadata = fetchMetadataInternal.bind(\n undefined,\n clientCtx,\n );\n\n const symbolClientContext: newSymbolClientContext = \"__osdkClientContext\";\n\n const client: Client = Object.defineProperties<Client>(\n clientFn as Client,\n {\n [oldSymbolClientContext]: {\n value: clientCtx,\n },\n [symbolClientContext]: {\n value: clientCtx,\n },\n [additionalContext]: {\n value: clientCtx,\n },\n fetchMetadata: {\n value: fetchMetadata,\n },\n } satisfies Record<keyof Client, PropertyDescriptor>,\n );\n\n return client;\n}\n\nexport const createClient: (\n baseUrl: string,\n ontologyRid: string | Promise<string>,\n tokenProvider: () => Promise<string>,\n options?: {\n logger?: Logger;\n } | undefined,\n fetchFn?: typeof fetch | undefined,\n) => Client = createClientInternal.bind(\n undefined,\n createObjectSet,\n);\n\nfunction createWithRid(\n rids: string[],\n) {\n const withRid: WireObjectSet = {\n type: \"static\",\n \"objects\": rids,\n };\n\n return withRid;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqBA,SACEA,uDAAuD,EACvDC,gDAAgD,EAChDC,iDAAiD,EACjDC,+CAA+C,QAC1C,oBAAoB;AAE3B,OAAO,KAAKC,YAAY,MAAM,0BAA0B;AACxD,SAASC,mBAAmB,IAAIC,sBAAsB,QAAQ,qBAAqB;AACnF,SAASC,+BAA+B,QAAQ,iDAAiD;AAEjG,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,iBAAiB,QAAqB,aAAa;AAC5D,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,qBAAqB,QAAQ,oBAAoB;AAC1D,SAASC,aAAa,QAAQ,2BAA2B;AAEzD,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,WAAW,QAAQ,yBAAyB;AACrD,SAASC,eAAe,QAAQ,gCAAgC;AAEhE,SAASC,UAAU,QAAQ,yBAAyB;;AAGpD;AACA;AACA;AACA;AACA;;AAKA,MAAMC,aAAa,CAEnB;EACEC,WAAWA,CACTC,SAAwB,EACxBC,SAAgC,EAChC;IACA;IACA;IACA;IACA;IACA,IAAI,CAACZ,WAAW,GAAGA,WAAW,CAACa,IAAI,CAACC,SAAS,EAAEH,SAAS,EAAEC,SAAS,CAAC;IACpE,IAAI,CAACG,gBAAgB,GAAGf,WAAW,CAACa,IAAI,CAACC,SAAS,EAAEH,SAAS,EAAEC,SAAS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YACH;UACF,CAAC;QAEH,KAAK3D,iDAAiD,CAAC4C,IAAI;UACzD,OAAO;YACLgB,cAAc,EAAE,MAAAA,CAMdC,qBAAwB,EACxBC,IAAc,EACdhC,OAAuC,GAAG,CAAC,CAAC,KACzC;cACH,OAAO,MAAMnB,SAAS,CACpBM,SAAS,EACT4C,qBAAqB,EACrB/B,OAAO,EACPmB,aAAa,CAACa,IAAI,CACpB,CAAC;YACH;UACF,CAAC;MACL;MAEA,MAAM,IAAI5B,KAAK,CAAC,iBAAiB,CAAC;IACpC,CAAC,MAAM;MACL,MAAM,IAAIA,KAAK,CAAC,iBAAiB,CAAC;IACpC;EACF,CAAC,EAWC;IACE,CAAC9B,sBAAsB,GAAG;MACxB2D,KAAK,EAAE9C;IACT,CAAC;IACD,CARgD,qBAAqB,GAQ9C;MACrB8C,KAAK,EAAE9C;IACT,CAAC;IACD,CAACV,iBAAiB,GAAG;MACnBwD,KAAK,EAAE9C;IACT,CAAC;IACDqB,aAAa,EAAE;MACbyB,KAAK,EAAEzB;IACT;EACF,CACF,CAAC;EAED,OAAOC,MAAM;AACf;AAEA,OAAO,MAAMyB,YAQF,GAAGvC,oBAAoB,CAACN,IAAI,CACrCC,SAAS,EACTP,eACF,CAAC;AAED,SAASoC,aAAaA,CACpBa,IAAc,EACd;EAMA,OAL+B;IAC7BnB,IAAI,EAAE,QAAQ;IACd,SAAS,EAAEmB;EACb,CAAC;AAGH","ignoreList":[]}
@@ -47,7 +47,7 @@ export class BaseLogger {
47
47
  ...this.bindings,
48
48
  ...bindings
49
49
  }, {
50
- level: (options ?? this.options)?.level,
50
+ level: options?.level ?? this.options?.level,
51
51
  msgPrefix: [this.options?.msgPrefix, options?.msgPrefix].filter(x => x).join(" ")
52
52
  });
53
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"BaseLogger.js","names":["noop","levels","trace","debug","info","warn","error","fatal","BaseLogger","factory","constructor","bindings","options","k","level","isLevelEnabled","createLogMethod","child","msgPrefix","filter","x","join","ourLevel"],"sources":["BaseLogger.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Logger } from \"@osdk/api\";\n\nexport function noop(): any {\n}\n\ninterface LoggerConstructor {\n new(\n bindings: Record<string, any>,\n options?: { level?: string; msgPrefix?: string },\n ): Logger;\n}\n\nconst levels = {\n trace: 10,\n debug: 20,\n info: 30,\n warn: 40,\n error: 50,\n fatal: 60,\n};\n\nexport abstract class BaseLogger implements Logger {\n protected bindings: Record<string, any>;\n protected options: { level?: string; msgPrefix?: string } | undefined;\n #factory: LoggerConstructor;\n\n constructor(\n bindings: Record<string, any>,\n options: { level?: string; msgPrefix?: string } = {},\n factory: LoggerConstructor,\n ) {\n this.bindings = bindings;\n this.options = options;\n this.#factory = factory;\n\n for (\n const k of [\"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"] as const\n ) {\n if (this.options?.level && !this.isLevelEnabled(k)) {\n continue;\n }\n this[k] = this.createLogMethod(k, bindings);\n }\n }\n\n protected abstract createLogMethod(\n name: \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\",\n bindings: Record<string, any>,\n ): Logger.LogFn;\n\n trace: Logger.LogFn = noop;\n debug: Logger.LogFn = noop;\n warn: Logger.LogFn = noop;\n info: Logger.LogFn = noop;\n error: Logger.LogFn = noop;\n fatal: Logger.LogFn = noop;\n\n child(\n bindings: Record<string, any>,\n options?: { level?: string; msgPrefix?: string },\n ): Logger {\n return new this.#factory({\n ...this.bindings,\n ...bindings,\n }, {\n level: (options ?? this.options)?.level,\n msgPrefix: [this.options?.msgPrefix, options?.msgPrefix].filter(x => x)\n .join(\" \"),\n });\n }\n\n isLevelEnabled(level: string): boolean {\n const ourLevel = (this.options?.level ?? \"info\") as keyof typeof levels;\n\n return level in levels && ourLevel in levels\n && levels[level as keyof typeof levels] >= levels[ourLevel];\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASA,IAAIA,CAAA,EAAQ,CAC5B;AASA,MAAMC,MAAM,GAAG;EACbC,KAAK,EAAE,EAAE;EACTC,KAAK,EAAE,EAAE;EACTC,IAAI,EAAE,EAAE;EACRC,IAAI,EAAE,EAAE;EACRC,KAAK,EAAE,EAAE;EACTC,KAAK,EAAE;AACT,CAAC;AAED,OAAO,MAAeC,UAAU,CAAmB;EAGjD,CAACC,OAAO;EAERC,WAAWA,CACTC,QAA6B,EAC7BC,OAA+C,GAAG,CAAC,CAAC,EACpDH,OAA0B,EAC1B;IACA,IAAI,CAACE,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACC,OAAO,GAAGA,OAAO;IACtB,IAAI,CAAC,CAACH,OAAO,GAAGA,OAAO;IAEvB,KACE,MAAMI,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAC/D;MACA,IAAI,IAAI,CAACD,OAAO,EAAEE,KAAK,IAAI,CAAC,IAAI,CAACC,cAAc,CAACF,CAAC,CAAC,EAAE;QAClD;MACF;MACA,IAAI,CAACA,CAAC,CAAC,GAAG,IAAI,CAACG,eAAe,CAACH,CAAC,EAAEF,QAAQ,CAAC;IAC7C;EACF;EAOAT,KAAK,GAAiBF,IAAI;EAC1BG,KAAK,GAAiBH,IAAI;EAC1BK,IAAI,GAAiBL,IAAI;EACzBI,IAAI,GAAiBJ,IAAI;EACzBM,KAAK,GAAiBN,IAAI;EAC1BO,KAAK,GAAiBP,IAAI;EAE1BiB,KAAKA,CACHN,QAA6B,EAC7BC,OAAgD,EACxC;IACR,OAAO,IAAI,IAAI,CAAC,CAACH,OAAO,CAAC;MACvB,GAAG,IAAI,CAACE,QAAQ;MAChB,GAAGA;IACL,CAAC,EAAE;MACDG,KAAK,EAAE,CAACF,OAAO,IAAI,IAAI,CAACA,OAAO,GAAGE,KAAK;MACvCI,SAAS,EAAE,CAAC,IAAI,CAACN,OAAO,EAAEM,SAAS,EAAEN,OAAO,EAAEM,SAAS,CAAC,CAACC,MAAM,CAACC,CAAC,IAAIA,CAAC,CAAC,CACpEC,IAAI,CAAC,GAAG;IACb,CAAC,CAAC;EACJ;EAEAN,cAAcA,CAACD,KAAa,EAAW;IACrC,MAAMQ,QAAQ,GAAI,IAAI,CAACV,OAAO,EAAEE,KAAK,IAAI,MAA8B;IAEvE,OAAOA,KAAK,IAAIb,MAAM,IAAIqB,QAAQ,IAAIrB,MAAM,IACvCA,MAAM,CAACa,KAAK,CAAwB,IAAIb,MAAM,CAACqB,QAAQ,CAAC;EAC/D;AACF","ignoreList":[]}
1
+ {"version":3,"file":"BaseLogger.js","names":["noop","levels","trace","debug","info","warn","error","fatal","BaseLogger","factory","constructor","bindings","options","k","level","isLevelEnabled","createLogMethod","child","msgPrefix","filter","x","join","ourLevel"],"sources":["BaseLogger.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Logger } from \"@osdk/api\";\n\nexport function noop(): any {\n}\n\ninterface LoggerConstructor {\n new(\n bindings: Record<string, any>,\n options?: { level?: string; msgPrefix?: string },\n ): Logger;\n}\n\nconst levels = {\n trace: 10,\n debug: 20,\n info: 30,\n warn: 40,\n error: 50,\n fatal: 60,\n};\n\nexport abstract class BaseLogger implements Logger {\n protected bindings: Record<string, any>;\n protected options: { level?: string; msgPrefix?: string } | undefined;\n #factory: LoggerConstructor;\n\n constructor(\n bindings: Record<string, any>,\n options: { level?: string; msgPrefix?: string } = {},\n factory: LoggerConstructor,\n ) {\n this.bindings = bindings;\n this.options = options;\n this.#factory = factory;\n\n for (\n const k of [\"trace\", \"debug\", \"info\", \"warn\", \"error\", \"fatal\"] as const\n ) {\n if (this.options?.level && !this.isLevelEnabled(k)) {\n continue;\n }\n this[k] = this.createLogMethod(k, bindings);\n }\n }\n\n protected abstract createLogMethod(\n name: \"trace\" | \"debug\" | \"info\" | \"warn\" | \"error\" | \"fatal\",\n bindings: Record<string, any>,\n ): Logger.LogFn;\n\n trace: Logger.LogFn = noop;\n debug: Logger.LogFn = noop;\n warn: Logger.LogFn = noop;\n info: Logger.LogFn = noop;\n error: Logger.LogFn = noop;\n fatal: Logger.LogFn = noop;\n\n child(\n bindings: Record<string, any>,\n options?: { level?: string; msgPrefix?: string },\n ): Logger {\n return new this.#factory({\n ...this.bindings,\n ...bindings,\n }, {\n level: options?.level ?? this.options?.level,\n msgPrefix: [this.options?.msgPrefix, options?.msgPrefix].filter(x => x)\n .join(\" \"),\n });\n }\n\n isLevelEnabled(level: string): boolean {\n const ourLevel = (this.options?.level ?? \"info\") as keyof typeof levels;\n\n return level in levels && ourLevel in levels\n && levels[level as keyof typeof levels] >= levels[ourLevel];\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASA,IAAIA,CAAA,EAAQ,CAC5B;AASA,MAAMC,MAAM,GAAG;EACbC,KAAK,EAAE,EAAE;EACTC,KAAK,EAAE,EAAE;EACTC,IAAI,EAAE,EA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AC;EACJ;EAEAN,cAAcA,CAACD,KAAa,EAAW;IACrC,MAAMQ,QAAQ,GAAI,IAAI,CAACV,OAAO,EAAEE,KAAK,IAAI,MAA8B;IAEvE,OAAOA,KAAK,IAAIb,MAAM,IAAIqB,QAAQ,IAAIrB,MAAM,IACvCA,MAAM,CAACa,KAAK,CAAwB,IAAIb,MAAM,CAACqB,QAAQ,CAAC;EAC/D;AACF","ignoreList":[]}
@@ -17,4 +17,7 @@
17
17
  export function isMediaReference(o) {
18
18
  return typeof o === `object` && typeof o.mimeType === "string" && "reference" in o && typeof o.reference === "object" && o.reference.type === "mediaSetViewItem" && "mediaSetViewItem" in o.reference && typeof o.reference.mediaSetViewItem === "object" && typeof o.reference.mediaSetViewItem.mediaSetRid === "string" && typeof o.reference.mediaSetViewItem.mediaSetViewRid === "string" && typeof o.reference.mediaSetViewItem.mediaItemRid === "string";
19
19
  }
20
+ export function isMediaUpload(o) {
21
+ return typeof o === "object" && "path" in o && typeof o.path === "string" && "data" in o && typeof o.data === "object" && o.data instanceof Blob;
22
+ }
20
23
  //# sourceMappingURL=mediaUpload.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mediaUpload.js","names":["isMediaReference","o","mimeType","reference","type","mediaSetViewItem","mediaSetRid","mediaSetViewRid","mediaItemRid"],"sources":["mediaUpload.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { MediaReference } from \"@osdk/api\";\n\nexport function isMediaReference(o: any): o is MediaReference {\n return typeof o === `object`\n && typeof o.mimeType === \"string\"\n && \"reference\" in o\n && typeof o.reference === \"object\"\n && o.reference.type === \"mediaSetViewItem\"\n && \"mediaSetViewItem\" in o.reference\n && typeof o.reference.mediaSetViewItem === \"object\"\n && typeof o.reference.mediaSetViewItem.mediaSetRid === \"string\"\n && typeof o.reference.mediaSetViewItem.mediaSetViewRid === \"string\"\n && typeof o.reference.mediaSetViewItem.mediaItemRid === \"string\";\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASA,gBAAgBA,CAACC,CAAM,EAAuB;EAC5D,OAAO,OAAOA,CAAC,KAAK,QAAQ,IACvB,OAAOA,CAAC,CAACC,QAAQ,KAAK,QAAQ,IAC9B,WAAW,IAAID,CAAC,IAChB,OAAOA,CAAC,CAACE,SAAS,KAAK,QAAQ,IAC/BF,CAAC,CAACE,SAAS,CAACC,IAAI,KAAK,kBAAkB,IACvC,kBAAkB,IAAIH,CAAC,CAACE,SAAS,IACjC,OAAOF,CAAC,CAACE,SAAS,CAACE,gBAAgB,KAAK,QAAQ,IAChD,OAAOJ,CAAC,CAACE,SAAS,CAACE,gBAAgB,CAACC,WAAW,KAAK,QAAQ,IAC5D,OAAOL,CAAC,CAACE,SAAS,CAACE,gBAAgB,CAACE,eAAe,KAAK,QAAQ,IAChE,OAAON,CAAC,CAACE,SAAS,CAACE,gBAAgB,CAACG,YAAY,KAAK,QAAQ;AACpE","ignoreList":[]}
1
+ {"version":3,"file":"mediaUpload.js","names":["isMediaReference","o","mimeType","reference","type","mediaSetViewItem","mediaSetRid","mediaSetViewRid","mediaItemRid","isMediaUpload","path","data","Blob"],"sources":["mediaUpload.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { MediaReference, MediaUpload } from \"@osdk/api\";\n\nexport function isMediaReference(o: any): o is MediaReference {\n return typeof o === `object`\n && typeof o.mimeType === \"string\"\n && \"reference\" in o\n && typeof o.reference === \"object\"\n && o.reference.type === \"mediaSetViewItem\"\n && \"mediaSetViewItem\" in o.reference\n && typeof o.reference.mediaSetViewItem === \"object\"\n && typeof o.reference.mediaSetViewItem.mediaSetRid === \"string\"\n && typeof o.reference.mediaSetViewItem.mediaSetViewRid === \"string\"\n && typeof o.reference.mediaSetViewItem.mediaItemRid === \"string\";\n}\n\nexport function isMediaUpload(o: any): o is MediaUpload {\n return typeof o === \"object\"\n && \"path\" in o\n && typeof o.path === \"string\"\n && \"data\" in o\n && typeof o.data === \"object\"\n && o.data instanceof Blob;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,SAASA,gBAAgBA,CAACC,CAAM,EAAuB;EAC5D,OAAO,OAAOA,CAAC,KAAK,QAAQ,IACvB,OAAOA,CAAC,CAACC,QAAQ,KAAK,QAAQ,IAC9B,WAAW,IAAID,CAAC,IAChB,OAAOA,CAAC,CAACE,SAAS,KAAK,QAAQ,IAC/BF,CAAC,CAACE,SAAS,CAACC,IAAI,KAAK,kBAAkB,IACvC,kBAAkB,IAAIH,CAAC,CAACE,SAAS,IACjC,OAAOF,CAAC,CAACE,SAAS,CAACE,gBAAgB,KAAK,QAAQ,IAChD,OAAOJ,CAAC,CAACE,SAAS,CAACE,gBAAgB,CAACC,WAAW,KAAK,QAAQ,IAC5D,OAAOL,CAAC,CAACE,SAAS,CAACE,gBAAgB,CAACE,eAAe,KAAK,QAAQ,IAChE,OAAON,CAAC,CAACE,SAAS,CAACE,gBAAgB,CAACG,YAAY,KAAK,QAAQ;AACpE;AAEA,OAAO,SAASC,aAAaA,CAACR,CAAM,EAAoB;EACtD,OAAO,OAAOA,CAAC,KAAK,QAAQ,IACvB,MAAM,IAAIA,CAAC,IACX,OAAOA,CAAC,CAACS,IAAI,KAAK,QAAQ,IAC1B,MAAM,IAAIT,CAAC,IACX,OAAOA,CAAC,CAACU,IAAI,KAAK,QAAQ,IAC1BV,CAAC,CAACU,IAAI,YAAYC,IAAI;AAC7B","ignoreList":[]}
@@ -14,10 +14,26 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import { createFetchHeaderMutator } from "@osdk/shared.net.fetch";
18
+ import { additionalContext } from "../Client.js";
19
+ import { createClientFromContext } from "../createClient.js";
20
+ import { OBSERVABLE_USER_AGENT } from "../util/UserAgent.js";
17
21
  import { ObservableClientImpl } from "./internal/ObservableClientImpl.js";
18
22
  import { Store } from "./internal/Store.js";
19
23
  export let ObservableClient;
20
24
  export function createObservableClient(client) {
21
- return new ObservableClientImpl(new Store(client));
25
+ // First we need a modified client that adds an extra header so we know its
26
+ // an observable client
27
+ const tweakedClient = createClientFromContext({
28
+ ...client[additionalContext],
29
+ fetch: createFetchHeaderMutator(client[additionalContext].fetch, headers => {
30
+ headers.set("Fetch-User-Agent", [headers.get("Fetch-User-Agent"), OBSERVABLE_USER_AGENT].filter(x => x && x?.length > 0).join(" "));
31
+ return headers;
32
+ })
33
+ });
34
+
35
+ // Then we use that client instead. Because the `client` does not hold
36
+ // any real state, this whole thing works.
37
+ return new ObservableClientImpl(new Store(tweakedClient));
22
38
  }
23
39
  //# sourceMappingURL=ObservableClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ObservableClient.js","names":["ObservableClientImpl","Store","ObservableClient","createObservableClient","client"],"sources":["ObservableClient.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ActionDefinition,\n InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/api\";\nimport type { ActionSignatureFromDef } from \"../actions/applyAction.js\";\nimport type { Client } from \"../Client.js\";\nimport type { Canonical } from \"./internal/Canonical.js\";\nimport { ObservableClientImpl } from \"./internal/ObservableClientImpl.js\";\nimport { Store } from \"./internal/Store.js\";\nimport type { OptimisticBuilder } from \"./OptimisticBuilder.js\";\n\nexport type Status = \"init\" | \"loading\" | \"loaded\" | \"error\";\n\nexport interface Observer<T> {\n next: (value: T) => void;\n error: (err: any) => void;\n complete: () => void;\n}\n\nexport namespace ObservableClient {\n export interface ApplyActionOptions {\n optimisticUpdate?: (ctx: OptimisticBuilder) => void;\n }\n}\n\nexport interface CommonObserveOptions {\n dedupeInterval?: number;\n}\n\nexport interface ObserveOptions {\n mode?: \"offline\" | \"force\";\n}\n\nexport interface ObserveObjectOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> extends ObserveOptions {\n select?: PropertyKeys<T>[];\n}\n\nexport type OrderBy<Q extends ObjectTypeDefinition | InterfaceDefinition> = {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\" | undefined;\n};\n\nexport interface ObserveListOptions<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n> extends CommonObserveOptions, ObserveOptions {\n type: Pick<Q, \"apiName\" | \"type\">;\n where?: WhereClause<Q>;\n pageSize?: number;\n orderBy?: OrderBy<Q>;\n invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n expectedLength?: number;\n streamUpdates?: boolean;\n}\n\nexport interface ObserveObjectArgs<T extends ObjectTypeDefinition> {\n object: Osdk.Instance<T> | undefined;\n isOptimistic: boolean;\n status: Status;\n lastUpdated: number;\n}\n\nexport interface ObserveObjectsArgs<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n resolvedList: Array<Osdk.Instance<T>>;\n isOptimistic: boolean;\n lastUpdated: number;\n fetchMore: () => Promise<unknown>;\n hasMore: boolean;\n status: Status;\n}\n\nexport interface ObservableClient {\n observeObject<T extends ObjectTypeDefinition>(\n apiName: T[\"apiName\"] | T,\n pk: PrimaryKeyType<T>,\n options: ObserveOptions,\n subFn: Observer<ObserveObjectArgs<T>>,\n ): Unsubscribable;\n\n observeList<T extends ObjectTypeDefinition | InterfaceDefinition>(\n options: ObserveListOptions<T>,\n subFn: Observer<ObserveObjectsArgs<T>>,\n ): Unsubscribable;\n\n applyAction: <Q extends ActionDefinition<any>>(\n action: Q,\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts?: ObservableClient.ApplyActionOptions,\n ) => Promise<unknown>;\n\n canonicalizeWhereClause: <\n T extends ObjectTypeDefinition | InterfaceDefinition,\n >(\n where: WhereClause<T>,\n ) => Canonical<WhereClause<T>>;\n}\n\nexport function createObservableClient(client: Client): ObservableClient {\n return new ObservableClientImpl(new Store(client));\n}\n\nexport interface Unsubscribable {\n unsubscribe: () => void;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAcA,SAASA,oBAAoB,QAAQ,oCAAoC;AACzE,SAASC,KAAK,QAAQ,qBAAqB;AAAC,WAW3BC,gBAAgB;AAgFjC,OAAO,SAASC,sBAAsBA,CAACC,MAAc,EAAoB;EACvE,OAAO,IAAIJ,oBAAoB,CAAC,IAAIC,KAAK,CAACG,MAAM,CAAC,CAAC;AACpD","ignoreList":[]}
1
+ {"version":3,"file":"ObservableClient.js","names":["createFetchHeaderMutator","additionalContext","createClientFromContext","OBSERVABLE_USER_AGENT","ObservableClientImpl","Store","ObservableClient","createObservableClient","client","tweakedClient","fetch","headers","set","get","filter","x","length","join"],"sources":["ObservableClient.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ActionDefinition,\n InterfaceDefinition,\n ObjectTypeDefinition,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n WhereClause,\n} from \"@osdk/api\";\nimport { createFetchHeaderMutator } from \"@osdk/shared.net.fetch\";\nimport type { ActionSignatureFromDef } from \"../actions/applyAction.js\";\nimport { additionalContext, type Client } from \"../Client.js\";\nimport { createClientFromContext } from \"../createClient.js\";\nimport { OBSERVABLE_USER_AGENT } from \"../util/UserAgent.js\";\nimport type { Canonical } from \"./internal/Canonical.js\";\nimport { ObservableClientImpl } from \"./internal/ObservableClientImpl.js\";\nimport { Store } from \"./internal/Store.js\";\nimport type { OptimisticBuilder } from \"./OptimisticBuilder.js\";\n\nexport type Status = \"init\" | \"loading\" | \"loaded\" | \"error\";\n\nexport interface Observer<T> {\n next: (value: T) => void;\n error: (err: any) => void;\n complete: () => void;\n}\n\nexport namespace ObservableClient {\n export interface ApplyActionOptions {\n optimisticUpdate?: (ctx: OptimisticBuilder) => void;\n }\n}\n\nexport interface CommonObserveOptions {\n dedupeInterval?: number;\n}\n\nexport interface ObserveOptions {\n mode?: \"offline\" | \"force\";\n}\n\nexport interface ObserveObjectOptions<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> extends ObserveOptions {\n select?: PropertyKeys<T>[];\n}\n\nexport type OrderBy<Q extends ObjectTypeDefinition | InterfaceDefinition> = {\n [K in PropertyKeys<Q>]?: \"asc\" | \"desc\" | undefined;\n};\n\nexport interface ObserveListOptions<\n Q extends ObjectTypeDefinition | InterfaceDefinition,\n> extends CommonObserveOptions, ObserveOptions {\n type: Pick<Q, \"apiName\" | \"type\">;\n where?: WhereClause<Q>;\n pageSize?: number;\n orderBy?: OrderBy<Q>;\n invalidationMode?: \"in-place\" | \"wait\" | \"reset\";\n expectedLength?: number;\n streamUpdates?: boolean;\n}\n\nexport interface ObserveObjectArgs<T extends ObjectTypeDefinition> {\n object: Osdk.Instance<T> | undefined;\n isOptimistic: boolean;\n status: Status;\n lastUpdated: number;\n}\n\nexport interface ObserveObjectsArgs<\n T extends ObjectTypeDefinition | InterfaceDefinition,\n> {\n resolvedList: Array<Osdk.Instance<T>>;\n isOptimistic: boolean;\n lastUpdated: number;\n fetchMore: () => Promise<unknown>;\n hasMore: boolean;\n status: Status;\n}\n\nexport interface ObservableClient {\n observeObject<T extends ObjectTypeDefinition>(\n apiName: T[\"apiName\"] | T,\n pk: PrimaryKeyType<T>,\n options: ObserveOptions,\n subFn: Observer<ObserveObjectArgs<T>>,\n ): Unsubscribable;\n\n observeList<T extends ObjectTypeDefinition | InterfaceDefinition>(\n options: ObserveListOptions<T>,\n subFn: Observer<ObserveObjectsArgs<T>>,\n ): Unsubscribable;\n\n applyAction: <Q extends ActionDefinition<any>>(\n action: Q,\n args:\n | Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]\n | Array<Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]>,\n opts?: ObservableClient.ApplyActionOptions,\n ) => Promise<unknown>;\n\n canonicalizeWhereClause: <\n T extends ObjectTypeDefinition | InterfaceDefinition,\n >(\n where: WhereClause<T>,\n ) => Canonical<WhereClause<T>>;\n}\n\nexport function createObservableClient(client: Client): ObservableClient {\n // First we need a modified client that adds an extra header so we know its\n // an observable client\n const tweakedClient = createClientFromContext({\n ...client[additionalContext],\n\n fetch: createFetchHeaderMutator(\n client[additionalContext].fetch,\n (headers) => {\n headers.set(\n \"Fetch-User-Agent\",\n [\n headers.get(\"Fetch-User-Agent\"),\n OBSERVABLE_USER_AGENT,\n ].filter(x => x && x?.length > 0).join(\" \"),\n );\n return headers;\n },\n ),\n });\n\n // Then we use that client instead. Because the `client` does not hold\n // any real state, this whole thing works.\n return new ObservableClientImpl(new Store(tweakedClient));\n}\n\nexport interface Unsubscribable {\n unsubscribe: () => void;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,SAASA,wBAAwB,QAAQ,wBAAwB;AAEjE,SAASC,iBAAiB,QAAqB,cAAc;AAC7D,SAASC,uBAAuB,QAAQ,oBAAoB;AAC5D,SAASC,qBAAqB,QAAQ,sBAAsB;AAE5D,SAASC,oBAAoB,QAAQ,oCAAoC;AACzE,SAASC,KAAK,QAAQ,qBAAqB;AAAC,WAW3BC,gBAAgB;AAkFjC,OAAO,SAASC,sBAAsBA,CAACC,MAAc,EAAoB;EACvE;EACA;EACA,MAAMC,aAAa,GAAGP,uBAAuB,CAAC;IAC5C,GAAGM,MAAM,CAACP,iBAAiB,CAAC;IAE5BS,KAAK,EAAEV,wBAAwB,CAC7BQ,MAAM,CAACP,iBAAiB,CAAC,CAACS,KAAK,EAC9BC,OAAO,IAAK;MACXA,OAAO,CAACC,GAAG,CACT,kBAAkB,EAClB,CACED,OAAO,CAACE,GAAG,CAAC,kBAAkB,CAAC,EAC/BV,qBAAqB,CACtB,CAACW,MAAM,CAACC,CAAC,IAAIA,CAAC,IAAIA,CAAC,EAAEC,MAAM,GAAG,CAAC,CAAC,CAACC,IAAI,CAAC,GAAG,CAC5C,CAAC;MACD,OAAON,OAAO;IAChB,CACF;EACF,CAAC,CAAC;;EAEF;EACA;EACA,OAAO,IAAIP,oBAAoB,CAAC,IAAIC,KAAK,CAACI,aAAa,CAAC,CAAC;AAC3D","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"OptimisticBuilder.js","names":[],"sources":["OptimisticBuilder.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectTypeDefinition,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n} from \"@osdk/api\";\n\nexport interface OptimisticBuilder {\n updateObject: <T extends ObjectTypeDefinition>(\n value: Osdk.Instance<T>,\n ) => this;\n createObject: <T extends ObjectTypeDefinition>(\n type: T,\n primaryKey: PrimaryKeyType<T>,\n properties: Pick<Osdk.Instance<T>, PropertyKeys<T>>,\n ) => this;\n}\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"OptimisticBuilder.js","names":[],"sources":["OptimisticBuilder.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectTypeDefinition,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n} from \"@osdk/api\";\n\nexport interface OptimisticBuilder {\n updateObject: <T extends ObjectTypeDefinition>(\n value: Osdk.Instance<T>,\n ) => this;\n createObject: <T extends ObjectTypeDefinition>(\n type: T,\n primaryKey: PrimaryKeyType<T>,\n properties: Pick<Osdk.Instance<T>, PropertyKeys<T>>,\n ) => this;\n deleteObject: <T extends ObjectTypeDefinition>(\n value: Osdk.Instance<T>,\n ) => this;\n}\n"],"mappings":"","ignoreList":[]}
@@ -15,7 +15,6 @@
15
15
  */
16
16
 
17
17
  import delay from "delay";
18
- import { createChangedObjects } from "./Changes.js";
19
18
  import { runOptimisticJob } from "./OptimisticJob.js";
20
19
  const ACTION_DELAY = process.env.NODE_ENV === "production" ? 0 : 1000;
21
20
  export class ActionApplication {
@@ -31,6 +30,17 @@ export class ActionApplication {
31
30
  const removeOptimisticResult = runOptimisticJob(this.store, optimisticUpdate);
32
31
  return await (async () => {
33
32
  try {
33
+ if (Array.isArray(args)) {
34
+ if (process.env.NODE_ENV !== "production") {
35
+ logger?.debug("applying action to multiple args", args);
36
+ }
37
+ const results = await this.store.client(action).batchApplyAction(args, {
38
+ $returnEdits: true
39
+ });
40
+ await this.#invalidateActionEditResponse(results);
41
+ return results;
42
+ }
43
+
34
44
  // The types for client get confused when we dynamically applyAction so we
35
45
  // have to deal with the `any` here and force cast it to what it should be.
36
46
  // TODO: Update the types so this doesn't happen!
@@ -56,47 +66,38 @@ export class ActionApplication {
56
66
  }
57
67
  })();
58
68
  };
59
- #invalidateActionEditResponse = async value => {
60
- const typesToInvalidate = new Set();
69
+ #invalidateActionEditResponse = async ({
70
+ deletedObjects,
71
+ modifiedObjects,
72
+ addedObjects,
73
+ editedObjectTypes,
74
+ type
75
+ }) => {
61
76
  let changes;
62
- if (value.type === "edits") {
77
+ if (type === "edits") {
63
78
  const promisesToWait = [];
64
- // TODO we need an backend update for deletes
65
- for (const obj of value.modifiedObjects) {
66
- promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
67
- }
68
- for (const obj of value.addedObjects) {
69
- promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
70
- typesToInvalidate.add(obj.objectType);
79
+ for (const list of [deletedObjects, modifiedObjects, addedObjects]) {
80
+ for (const obj of list ?? []) {
81
+ promisesToWait.push(this.store.invalidateObject(obj.objectType, obj.primaryKey));
82
+ }
71
83
  }
72
- await Promise.all(promisesToWait);
73
-
74
- // the action invocation just gives back object ids,
75
- // but the invalidateObject calls above should have put the
76
- // actual objects in the cache
77
- const changes = createChangedObjects();
78
- for (const changeType of ["addedObjects", "modifiedObjects"]) {
84
+ this.store.batch({}, batch => {
79
85
  for (const {
80
86
  objectType,
81
87
  primaryKey
82
- } of value[changeType] ?? []) {
88
+ } of deletedObjects ?? []) {
83
89
  const cacheKey = this.store.getCacheKey("object", objectType, primaryKey);
84
- // N.B. this probably isn't right. `getValue`() will give you the "top"
85
- // value but I think we want the "truth" guaranteed.
86
- const obj = this.store.getValue(cacheKey);
87
- if (obj && obj.value) {
88
- changes[changeType].set(objectType, obj.value);
89
- (changeType === "addedObjects" ? changes.added : changes.modified).add(cacheKey);
90
- }
90
+ this.store.peekQuery(cacheKey)?.deleteFromStore("loaded",
91
+ // this is probably not the best value to use
92
+ batch);
91
93
  }
92
- }
94
+ });
95
+ await Promise.all(promisesToWait);
93
96
  } else {
94
- for (const apiName of value.editedObjectTypes) {
95
- typesToInvalidate.add(apiName.toString());
97
+ for (const apiName of editedObjectTypes) {
96
98
  await this.store.invalidateObjectType(apiName, changes);
97
99
  }
98
100
  }
99
- return value;
100
101
  };
101
102
  }
102
103
  //# sourceMappingURL=ActionApplication.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ActionApplication.js","names":["delay","createChangedObjects","runOptimisticJob","ACTION_DELAY","process","env","NODE_ENV","ActionApplication","constructor","store","applyAction","action","args","optimisticUpdate","logger","child","methodName","removeOptimisticResult","actionResults","client","$returnEdits","debug","invalidateActionEditResponse","value","typesToInvalidate","Set","changes","type","promisesToWait","obj","modifiedObjects","push","invalidateObject","objectType","primaryKey","addedObjects","add","Promise","all","changeType","cacheKey","getCacheKey","getValue","set","added","modified","apiName","editedObjectTypes","toString","invalidateObjectType"],"sources":["ActionApplication.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { ActionDefinition, ActionEditResponse } from \"@osdk/api\";\nimport delay from \"delay\";\nimport type { ActionSignatureFromDef } from \"../../actions/applyAction.js\";\nimport { type Changes, createChangedObjects } from \"./Changes.js\";\nimport type { ObjectCacheKey } from \"./ObjectQuery.js\";\nimport { runOptimisticJob } from \"./OptimisticJob.js\";\nimport type { Store } from \"./Store.js\";\n\nconst ACTION_DELAY = process.env.NODE_ENV === \"production\" ? 0 : 1000;\n\nexport class ActionApplication {\n constructor(private store: Store) {}\n\n applyAction: <Q extends ActionDefinition<any>>(\n action: Q,\n args: Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0],\n opts?: Store.ApplyActionOptions,\n ) => Promise<ActionEditResponse> = async (\n action,\n args,\n { optimisticUpdate } = {},\n ) => {\n const logger = process.env.NODE_ENV !== \"production\"\n ? this.store.logger?.child({ methodName: \"applyAction\" })\n : this.store.logger;\n const removeOptimisticResult = runOptimisticJob(\n this.store,\n optimisticUpdate,\n );\n\n return await (async () => {\n try {\n // The types for client get confused when we dynamically applyAction so we\n // have to deal with the `any` here and force cast it to what it should be.\n // TODO: Update the types so this doesn't happen!\n\n const actionResults: ActionEditResponse = await this.store.client(\n action,\n ).applyAction(args as any, { $returnEdits: true });\n\n if (process.env.NODE_ENV !== \"production\") {\n if (ACTION_DELAY > 0) {\n logger?.debug(\"action done, pausing\", actionResults);\n await delay(ACTION_DELAY);\n logger?.debug(\"action done, pausing done\");\n }\n }\n await this.#invalidateActionEditResponse(actionResults);\n return actionResults;\n } finally {\n if (process.env.NODE_ENV !== \"production\") {\n logger?.debug(\n \"optimistic action complete; remove the results\",\n );\n }\n // make sure this happens even if the action fails\n await removeOptimisticResult();\n }\n })();\n };\n\n #invalidateActionEditResponse = async (\n value: ActionEditResponse,\n ): Promise<ActionEditResponse> => {\n const typesToInvalidate = new Set<string>();\n\n let changes: Changes | undefined;\n if (value.type === \"edits\") {\n const promisesToWait: Promise<any>[] = [];\n // TODO we need an backend update for deletes\n for (const obj of value.modifiedObjects) {\n promisesToWait.push(\n this.store.invalidateObject(obj.objectType, obj.primaryKey),\n );\n }\n\n for (const obj of value.addedObjects) {\n promisesToWait.push(\n this.store.invalidateObject(obj.objectType, obj.primaryKey),\n );\n\n typesToInvalidate.add(obj.objectType);\n }\n\n await Promise.all(promisesToWait);\n\n // the action invocation just gives back object ids,\n // but the invalidateObject calls above should have put the\n // actual objects in the cache\n const changes = createChangedObjects();\n for (const changeType of [\"addedObjects\", \"modifiedObjects\"] as const) {\n for (const { objectType, primaryKey } of (value[changeType] ?? [])) {\n const cacheKey = this.store.getCacheKey<ObjectCacheKey>(\n \"object\",\n objectType,\n primaryKey,\n );\n // N.B. this probably isn't right. `getValue`() will give you the \"top\"\n // value but I think we want the \"truth\" guaranteed.\n const obj = this.store.getValue(cacheKey);\n if (obj && obj.value) {\n changes[changeType].set(objectType, obj.value);\n (changeType === \"addedObjects\" ? changes.added : changes.modified)\n .add(cacheKey);\n }\n }\n }\n } else {\n for (const apiName of value.editedObjectTypes) {\n typesToInvalidate.add(apiName.toString());\n await this.store.invalidateObjectType(apiName as string, changes);\n }\n }\n\n return value;\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAAuBC,oBAAoB,QAAQ,cAAc;AAEjE,SAASC,gBAAgB,QAAQ,oBAAoB;A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,GAAG,IAAIA,GAAG,CAACN,KAAK,EAAE;YACpBG,OAAO,CAACa,UAAU,CAAC,CAACI,GAAG,CAACV,UAAU,EAAEJ,GAAG,CAACN,KAAK,CAAC;YAC9C,CAACgB,UAAU,KAAK,cAAc,GAAGb,OAAO,CAACkB,KAAK,GAAGlB,OAAO,CAACmB,QAAQ,EAC9DT,GAAG,CAACI,QAAQ,CAAC;UAClB;QACF;MACF;IACF,CAAC,MAAM;MACL,KAAK,MAAMM,OAAO,IAAIvB,KAAK,CAACwB,iBAAiB,EAAE;QAC7CvB,iBAAiB,CAACY,GAAG,CAACU,OAAO,CAACE,QAAQ,CAAC,CAAC,CAAC;QACzC,MAAM,IAAI,CAACvC,KAAK,CAACwC,oBAAoB,CAACH,OAAO,EAAYpB,OAAO,CAAC;MACnE;IACF;IAEA,OAAOH,KAAK;EACd,CAAC;AACH","ignoreList":[]}
1
+ {"version":3,"file":"ActionApplication.js","names":["delay","runOptimisticJob","ACTION_DELAY","process","env","NODE_ENV","ActionApplication","constructor","store","applyAction","action","args","optimisticUpdate","logger","child","methodName","removeOptimisticResult","Array","isArray","debug","results","client","batchApplyAction","$returnEdits","invalidateActionEditResponse","actionResults","#invalidateActionEditResponse","deletedObjects","modifiedObjects","addedObjects","editedObjectTypes","type","changes","promisesToWait","list","obj","push","invalidateObject","objectType","primaryKey","batch","cacheKey","getCacheKey","peekQuery","deleteFromStore","Promise","all","apiName","invalidateObjectType"],"sources":["ActionApplication.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ActionDefinition,\n ActionEditResponse,\n ActionReturnTypeForOptions,\n} from \"@osdk/api\";\nimport delay from \"delay\";\nimport type { ActionSignatureFromDef } from \"../../actions/applyAction.js\";\nimport { type Changes } from \"./Changes.js\";\nimport type { ObjectCacheKey } from \"./ObjectQuery.js\";\nimport { runOptimisticJob } from \"./OptimisticJob.js\";\nimport type { Store } from \"./Store.js\";\n\nconst ACTION_DELAY = process.env.NODE_ENV === \"production\" ? 0 : 1000;\n\nexport class ActionApplication {\n constructor(private store: Store) {}\n\n applyAction: <Q extends ActionDefinition<any>>(\n action: Q,\n args:\n | Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]\n | Array<Parameters<ActionSignatureFromDef<Q>[\"applyAction\"]>[0]>,\n opts?: Store.ApplyActionOptions,\n ) => Promise<ActionEditResponse> = async (\n action,\n args,\n { optimisticUpdate } = {},\n ) => {\n const logger = process.env.NODE_ENV !== \"production\"\n ? this.store.logger?.child({ methodName: \"applyAction\" })\n : this.store.logger;\n const removeOptimisticResult = runOptimisticJob(\n this.store,\n optimisticUpdate,\n );\n\n return await (async () => {\n try {\n if (Array.isArray(args)) {\n if (process.env.NODE_ENV !== \"production\") {\n logger?.debug(\"applying action to multiple args\", args);\n }\n\n const results: ActionReturnTypeForOptions<{ $returnEdits: true }> =\n await this.store\n .client(action).batchApplyAction(\n args,\n { $returnEdits: true },\n );\n\n await this.#invalidateActionEditResponse(results);\n\n return results;\n }\n\n // The types for client get confused when we dynamically applyAction so we\n // have to deal with the `any` here and force cast it to what it should be.\n // TODO: Update the types so this doesn't happen!\n\n const actionResults: ActionEditResponse = await this.store.client(\n action,\n ).applyAction(args as any, { $returnEdits: true });\n\n if (process.env.NODE_ENV !== \"production\") {\n if (ACTION_DELAY > 0) {\n logger?.debug(\"action done, pausing\", actionResults);\n await delay(ACTION_DELAY);\n logger?.debug(\"action done, pausing done\");\n }\n }\n await this.#invalidateActionEditResponse(actionResults);\n return actionResults;\n } finally {\n if (process.env.NODE_ENV !== \"production\") {\n logger?.debug(\n \"optimistic action complete; remove the results\",\n );\n }\n // make sure this happens even if the action fails\n await removeOptimisticResult();\n }\n })();\n };\n\n #invalidateActionEditResponse = async (\n { deletedObjects, modifiedObjects, addedObjects, editedObjectTypes, type }:\n ActionEditResponse,\n ): Promise<void> => {\n let changes: Changes | undefined;\n if (type === \"edits\") {\n const promisesToWait: Promise<any>[] = [];\n\n for (const list of [deletedObjects, modifiedObjects, addedObjects]) {\n for (const obj of list ?? []) {\n promisesToWait.push(\n this.store.invalidateObject(obj.objectType, obj.primaryKey),\n );\n }\n }\n\n this.store.batch({}, (batch) => {\n for (const { objectType, primaryKey } of deletedObjects ?? []) {\n const cacheKey = this.store.getCacheKey<ObjectCacheKey>(\n \"object\",\n objectType,\n primaryKey,\n );\n this.store.peekQuery(cacheKey)?.deleteFromStore(\n \"loaded\", // this is probably not the best value to use\n batch,\n );\n }\n });\n await Promise.all(promisesToWait);\n } else {\n for (const apiName of editedObjectTypes) {\n await this.store.invalidateObjectType(apiName as string, changes);\n }\n }\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,OAAOA,KAAK,MAAM,OAAO;AAIzB,SAASC,gBAAgB,QAAQ,oBAAoB;AAGrD,MAAMC,YAAY,GAAGC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAAG,CAAC,GAAG,IAAI;AAErE,OAAO,MAAMC,iBAAiB,CAAC;EAC7BC,WAAWA,CAASC,KAAY,EAAE;IAAA,KAAdA,KAAY,GAAZA,KAAY;EAAG;EAEnCC,WAAW,GAMwB,MAAAA,CACjCC,MAAM,EACNC,IAAI,EACJ;IAAEC;EAAiB,CAAC,GAAG,CAAC,CAAC,KACtB;IACH,MAAMC,MAAM,GAAGV,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,GAChD,IAAI,CAACG,KAAK,CAACK,MAAM,EAAEC,KAA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 export class Changes {
21
21
  addedObjects = new MultiMap();
22
22
  added = new Set();
23
23
  modified = new Set();
24
+ deleted = new Set();
24
25
  registerObject = (cacheKey, data, isNew) => {
25
26
  this[isNew ? "addedObjects" : "modifiedObjects"].set(data.$apiName, data);
26
27
  this[isNew ? "added" : "modified"].add(cacheKey);
27
28
  };
29
+ deleteObject = cacheKey => {
30
+ this.deleted.add(cacheKey);
31
+ };
28
32
  registerList = key => {
29
33
  this.modified.add(key);
30
34
  };
31
35
  isEmpty() {
32
- return this.modifiedObjects.size === 0 && this.addedObjects.size === 0 && this.added.size === 0 && this.modified.size === 0;
36
+ return this.modifiedObjects.size === 0 && this.addedObjects.size === 0 && this.added.size === 0 && this.modified.size === 0 && this.deleted.size === 0;
33
37
  }
34
38
  }
35
39
  export function createChangedObjects() {