@salesforce/lds-worker-api 1.100.2

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 (111) hide show
  1. package/LICENSE.txt +82 -0
  2. package/README.md +9 -0
  3. package/dist/sfdc/es/draftQueueImplementation.d.ts +2 -0
  4. package/dist/sfdc/es/executeAdapter.d.ts +71 -0
  5. package/dist/sfdc/es/language.d.ts +13 -0
  6. package/dist/sfdc/es/ldsWorkerApi.js +746 -0
  7. package/dist/sfdc/es/lightningAdapterApi.d.ts +11 -0
  8. package/dist/sfdc/es/main.d.ts +8 -0
  9. package/dist/sfdc/es/nimbusDraftQueue.d.ts +6 -0
  10. package/dist/sfdc/es/primingApi.d.ts +19 -0
  11. package/dist/sfdc/es/responses.d.ts +44 -0
  12. package/dist/sfdc/es/standalone-stubs/instrumentation.d.ts +21 -0
  13. package/dist/sfdc/es/standalone-stubs/o11y.d.ts +18 -0
  14. package/dist/sfdc/es/standalone-stubs/unwrap.d.ts +1 -0
  15. package/dist/sfdc/es/standalone.d.ts +1 -0
  16. package/dist/sfdc/es/ttl.d.ts +2 -0
  17. package/dist/standalone/es/draftQueueImplementation.d.ts +2 -0
  18. package/dist/standalone/es/executeAdapter.d.ts +71 -0
  19. package/dist/standalone/es/language.d.ts +13 -0
  20. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/currency.d.ts +2 -0
  21. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateFormat.d.ts +2 -0
  22. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateTimeFormat.d.ts +2 -0
  23. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortTimeFormat.d.ts +2 -0
  24. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/locale.d.ts +2 -0
  25. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/timeZone.d.ts +2 -0
  26. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/user/Id.d.ts +2 -0
  27. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/lightning/i18nCldrOptions.d.ts +2 -0
  28. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/lightning/i18nService.d.ts +10 -0
  29. package/dist/standalone/es/lds-worker-api/src/standalone-stubs/unwrap.d.ts +1 -0
  30. package/dist/standalone/es/lds-worker-api.js +79227 -0
  31. package/dist/standalone/es/lightningAdapterApi.d.ts +11 -0
  32. package/dist/standalone/es/main.d.ts +8 -0
  33. package/dist/standalone/es/nimbusDraftQueue.d.ts +6 -0
  34. package/dist/standalone/es/primingApi.d.ts +19 -0
  35. package/dist/standalone/es/responses.d.ts +44 -0
  36. package/dist/standalone/es/standalone-stubs/instrumentation.d.ts +21 -0
  37. package/dist/standalone/es/standalone-stubs/o11y.d.ts +18 -0
  38. package/dist/standalone/es/standalone.d.ts +1 -0
  39. package/dist/standalone/es/ttl.d.ts +2 -0
  40. package/dist/standalone/umd/draftQueueImplementation.d.ts +2 -0
  41. package/dist/standalone/umd/executeAdapter.d.ts +71 -0
  42. package/dist/standalone/umd/language.d.ts +13 -0
  43. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/currency.d.ts +2 -0
  44. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateFormat.d.ts +2 -0
  45. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateTimeFormat.d.ts +2 -0
  46. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortTimeFormat.d.ts +2 -0
  47. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/locale.d.ts +2 -0
  48. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/timeZone.d.ts +2 -0
  49. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/user/Id.d.ts +2 -0
  50. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/lightning/i18nCldrOptions.d.ts +2 -0
  51. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/lightning/i18nService.d.ts +10 -0
  52. package/dist/standalone/umd/lds-worker-api/src/standalone-stubs/unwrap.d.ts +1 -0
  53. package/dist/standalone/umd/lds-worker-api.js +79250 -0
  54. package/dist/standalone/umd/lightningAdapterApi.d.ts +11 -0
  55. package/dist/standalone/umd/main.d.ts +8 -0
  56. package/dist/standalone/umd/nimbusDraftQueue.d.ts +6 -0
  57. package/dist/standalone/umd/primingApi.d.ts +19 -0
  58. package/dist/standalone/umd/responses.d.ts +44 -0
  59. package/dist/standalone/umd/standalone-stubs/instrumentation.d.ts +21 -0
  60. package/dist/standalone/umd/standalone-stubs/o11y.d.ts +18 -0
  61. package/dist/standalone/umd/standalone.d.ts +1 -0
  62. package/dist/standalone/umd/ttl.d.ts +2 -0
  63. package/package.json +74 -0
  64. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/adapter-testcase.schema.json +83 -0
  65. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/name-displayValue-response.adapter-snapshot.result.json +61 -0
  66. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/name-displayValue.adapter-testcase.json +67 -0
  67. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/objectInfos/Aircraft-objectInfo.network-mock.json +517 -0
  68. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/objectInfos/Pilot-objectInfo.network-mock.json +347 -0
  69. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/scalar-displayValue-nonIntl-fallback-response.adapter-snapshot.result.json +82 -0
  70. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/scalar-displayValue-nonIntl-fallback.adapter-testcase.json +25 -0
  71. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/scalar-displayValue-response.adapter-snapshot.result.json +82 -0
  72. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/scalar-displayValue.adapter-testcase.json +23 -0
  73. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-assignedtome.adapter-testcase.json +34 -0
  74. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-baseline.adapter-testcase.json +24 -0
  75. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-child-relationship.adapter-testcase.json +29 -0
  76. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-parent-relationship.adapter-testcase.json +29 -0
  77. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-reserved-entity-name.adapter-testcase.json +25 -0
  78. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/assignedtome.adapter-testcase.json +33 -0
  79. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/l2DataSet.js +250 -0
  80. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-baseline.adapter-testcase.json +21 -0
  81. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where-orderby-allfields-spanningfield-500records.adapter-testcase.json +28 -0
  82. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where-orderby-allfields-spanningfield.adapter-testcase.json +28 -0
  83. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where-orderby-allfields.adapter-testcase.json +21 -0
  84. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where-orderby.adapter-testcase.json +21 -0
  85. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where.adapter-testcase.json +21 -0
  86. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/Account.network-mock.json +2784 -0
  87. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/AssignedResource.network-mock.json +863 -0
  88. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/Case.network-mock.json +1856 -0
  89. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/ServiceAppointment.network-mock.json +2888 -0
  90. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/ServiceResource.network-mock.json +1316 -0
  91. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/TimeSheetEntry.network-mock.json +977 -0
  92. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/WorkOrder.network-mock.json +3058 -0
  93. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/WorkType.network-mock.json +940 -0
  94. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectinfo.adapter-testcase.json +18 -0
  95. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/polyfield.adapter-testcase.json +43 -0
  96. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/adapter-forward-baseline.server-response.network-mock.json +416 -0
  97. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/adapter-forward-child-relationship.server-response.network-mock.json +103 -0
  98. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/adapter-forward-parent-relationship.server-response.network-mock.json +93 -0
  99. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/adapter-forward-reserved-entity-name.server-response.network-mock.json +97 -0
  100. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/assignedtome.server-response.network-mock.json +666 -0
  101. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/objectinfos.server-response.network-mock.json +210 -0
  102. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/polyfield.server-response.network-mock.json +724 -0
  103. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/adapter-forward-assignedtome.adapter-snapshot.result.json +72 -0
  104. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/adapter-forward-baseline.adapter-snapshot.result.json +245 -0
  105. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/adapter-forward-child-relationship.adapter-snapshot.result.json +30 -0
  106. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/adapter-forward-parent-relationship.adapter-snapshot.result.json +26 -0
  107. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/adapter-forward-reserved-entity-name.adapter-snapshot.result.json +32 -0
  108. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/assignedtome.adapter-snapshot.result.json +70 -0
  109. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/objectinfos.adapter-snapshot.result.json +170 -0
  110. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/polyfield.adapter-snapshot.result.json +29 -0
  111. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/network-mock.schema.json +14 -0
@@ -0,0 +1,746 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ /* *******************************************************************************************
8
+ * ATTENTION!
9
+ * THIS IS A GENERATED FILE FROM https://github.com/salesforce-experience-platform-emu/lds-lightning-platform
10
+ * If you would like to contribute to LDS, please follow the steps outlined in the git repo.
11
+ * Any changes made to this file in p4 will be automatically overwritten.
12
+ * *******************************************************************************************
13
+ */
14
+ import { parseAndVisit, gql } from 'force/ldsGraphqlParser';
15
+ import * as lightningAppsApi from 'lightning/uiAppsApi';
16
+ import * as unstableLightningAppsApi from 'lightning/unstable_uiAppsApi';
17
+ import * as lightningLayoutApi from 'lightning/uiLayoutApi';
18
+ import * as unstableLightningLayoutApi from 'lightning/unstable_uiLayoutApi';
19
+ import * as lightningListApi from 'lightning/uiListApi';
20
+ import * as unstableLightningListApi from 'lightning/unstable_uiListApi';
21
+ import * as lightningLookupsApi from 'lightning/uiLookupsApi';
22
+ import * as unstableLightningLookupsApi from 'lightning/unstable_uiLookupsApi';
23
+ import * as lightningObjectApi from 'lightning/uiObjectInfoApi';
24
+ import * as unstableLightningObjectApi from 'lightning/unstable_uiObjectInfoApi';
25
+ import * as lightningRecordActionsApi from 'lightning/uiRecordActionsApi';
26
+ import * as unstableLightningRecordActionsApi from 'lightning/unstable_uiRecordActionsApi';
27
+ import * as lightningRecordApi from 'lightning/uiRecordApi';
28
+ import * as unstableLightningRecordApi from 'lightning/unstable_uiRecordApi';
29
+ import * as lightningRecordAvatarApi from 'lightning/uiRecordAvatarApi';
30
+ import * as unstableLightningRecordAvatarApi from 'lightning/unstable_uiRecordAvatarApi';
31
+ import * as lightningRelatedListApi from 'lightning/uiRelatedListApi';
32
+ import * as unstableLightningRelatedListApi from 'lightning/unstable_uiRelatedListApi';
33
+ import * as lightningGraphQLApi from 'lightning/uiGraphQLApi';
34
+ import { createContentDocumentAndVersion, createContentVersion } from 'force/ldsAdaptersUiapi';
35
+ import * as gqlApi from 'force/ldsAdaptersGraphql';
36
+ import { getRuntime, reportGraphqlQueryParseError } from 'native/ldsRuntimeMobile';
37
+ export { registerReportObserver } from 'native/ldsRuntimeMobile';
38
+ import { HttpStatusCode } from 'force/luvioEngine';
39
+ import { withDefaultLuvio } from 'native/ldsEngineMobile';
40
+
41
+ const { create, keys } = Object;
42
+ const { stringify, parse } = JSON;
43
+ const { isArray } = Array;
44
+
45
+ const IMPERATIVE_ADAPTER_SUFFIX = '_imperative';
46
+ const UNSTABLE_ADAPTER_PREFIX = 'unstable_';
47
+ function extractWireAdapterName(adapterName) {
48
+ const parts = adapterName.split(UNSTABLE_ADAPTER_PREFIX);
49
+ if (parts.length > 1) {
50
+ return parts[1].substr(0, parts[1].indexOf(IMPERATIVE_ADAPTER_SUFFIX));
51
+ }
52
+ return adapterName.substr(0, adapterName.indexOf(IMPERATIVE_ADAPTER_SUFFIX));
53
+ }
54
+ let lazyDMLAdapterMap = undefined;
55
+ let lazyImperativeAdapterMap = undefined;
56
+ // this function builds the adapter maps lazily
57
+ function getAdapterMaps() {
58
+ if (lazyDMLAdapterMap === undefined || lazyImperativeAdapterMap === undefined) {
59
+ const map = Object.assign({
60
+ // We should eventually move all adapter names into this explicit list,
61
+ // this is our API contract to native callers and should be explicit
62
+ ['createContentDocumentAndVersion']: createContentDocumentAndVersion,
63
+ ['createContentVersion']: createContentVersion,
64
+ }, gqlApi, lightningAppsApi, lightningLayoutApi, lightningListApi, lightningLookupsApi, lightningObjectApi, lightningRecordActionsApi, lightningRecordApi, lightningRecordAvatarApi, lightningRelatedListApi, lightningGraphQLApi, unstableLightningAppsApi, unstableLightningLayoutApi, unstableLightningListApi, unstableLightningLookupsApi, unstableLightningObjectApi, unstableLightningRecordActionsApi, unstableLightningRecordApi, unstableLightningRecordAvatarApi, unstableLightningRelatedListApi);
65
+ const imperativeAdapterNames = keys(map).filter((name) => name.endsWith(IMPERATIVE_ADAPTER_SUFFIX));
66
+ const imperativeMap = {};
67
+ for (const adapterName of imperativeAdapterNames) {
68
+ const adapter = map[adapterName];
69
+ imperativeMap[adapterName] = adapter;
70
+ delete map[adapterName];
71
+ // remove the corresponding wire adapter from the adapter map
72
+ const wireAdapterName = extractWireAdapterName(adapterName);
73
+ delete map[wireAdapterName];
74
+ }
75
+ lazyDMLAdapterMap = map;
76
+ lazyImperativeAdapterMap = imperativeMap;
77
+ }
78
+ return { dmlAdapterMap: lazyDMLAdapterMap, imperativeAdapterMap: lazyImperativeAdapterMap };
79
+ }
80
+ function getDMLAdapterFromName(name) {
81
+ const { dmlAdapterMap } = getAdapterMaps();
82
+ return dmlAdapterMap[name];
83
+ }
84
+ function getImperativeAdapterFromName(name) {
85
+ const { imperativeAdapterMap } = getAdapterMaps();
86
+ return imperativeAdapterMap[name];
87
+ }
88
+ function getImperativeAdapterNames() {
89
+ const { imperativeAdapterMap } = getAdapterMaps();
90
+ return keys(imperativeAdapterMap);
91
+ }
92
+
93
+ const { draftManager, draftQueue } = getRuntime();
94
+
95
+ const NATIVE_ERROR_CODE = 'NATIVE_ERROR';
96
+ const NON_MUTATING_ADAPTER_MESSAGE = 'adapterId must be a mutating adapter';
97
+ const NO_DRAFT_CREATED_MESSAGE = 'the adapter did not generate a draft';
98
+ const DRAFT_DOESNT_EXIST_MESSAGE = 'the specified draft does not exist';
99
+ /**
100
+ * Error objects don't serialize well over the js-native wire, so our class turns
101
+ * an Error into an object that serializes real nice
102
+ */
103
+ class NativeNetworkAdapterErrorResponse {
104
+ constructor(error) {
105
+ this.errorType = 'networkAdapterError';
106
+ this.message = error.message;
107
+ this.name = error.name;
108
+ }
109
+ }
110
+ class NativeFetchResponse {
111
+ constructor(status, body) {
112
+ this.headers = {};
113
+ this.status = status;
114
+ this.body = body;
115
+ }
116
+ get statusText() {
117
+ const { status } = this;
118
+ switch (status) {
119
+ case HttpStatusCode.Ok:
120
+ return 'OK';
121
+ case HttpStatusCode.Created:
122
+ return 'Created';
123
+ case HttpStatusCode.NoContent:
124
+ return 'No Content';
125
+ case HttpStatusCode.BadRequest:
126
+ return 'Bad Request';
127
+ case HttpStatusCode.ServerError:
128
+ return 'Server Error';
129
+ default:
130
+ return `Unexpected HTTP Status Code: ${status}`;
131
+ }
132
+ }
133
+ get ok() {
134
+ return this.status >= 200 && this.status < 300;
135
+ }
136
+ }
137
+ class NativeFetchErrorResponse extends NativeFetchResponse {
138
+ constructor() {
139
+ super(...arguments);
140
+ this.errorType = 'fetchResponse';
141
+ }
142
+ }
143
+ function createNativeFetchErrorResponse(message) {
144
+ return new NativeFetchErrorResponse(HttpStatusCode.BadRequest, {
145
+ errorCode: NATIVE_ERROR_CODE,
146
+ message: message,
147
+ });
148
+ }
149
+ /**
150
+ * This function takes an unknown error and normalizes it to an Error object
151
+ */
152
+ function normalizeError(error) {
153
+ if (typeof error === 'object' && error instanceof Error) {
154
+ return error;
155
+ }
156
+ else if (typeof error === 'string') {
157
+ return new Error(error);
158
+ }
159
+ return new Error(stringify(error));
160
+ }
161
+
162
+ /**
163
+ * Coerces a cache policy passed in from native to a luvio cache policy
164
+ * @param nativeCachePolicy The cache policy passed in from native
165
+ * @returns A coerced luvio cache policy
166
+ */
167
+ function buildCachePolicy(nativeCachePolicy) {
168
+ if (nativeCachePolicy === undefined) {
169
+ return undefined;
170
+ }
171
+ // currently the types match exactly, if we ever decide to deviate then we should coerce here
172
+ return nativeCachePolicy;
173
+ }
174
+ /**
175
+ * Coerces a request context passed in from native to a luvio request context
176
+ * @param nativeRequestContext request context passed in from native
177
+ * @returns Coerced luvio request context
178
+ */
179
+ function buildAdapterRequestContext(nativeRequestContext) {
180
+ if (nativeRequestContext === undefined) {
181
+ return undefined;
182
+ }
183
+ const { cachePolicy, priority, observabilityContext, luvioEventObserver } = nativeRequestContext;
184
+ const requestContext = {
185
+ cachePolicy: buildCachePolicy(cachePolicy),
186
+ priority,
187
+ };
188
+ if (observabilityContext !== undefined) {
189
+ requestContext.requestCorrelator = {
190
+ observabilityContext,
191
+ };
192
+ }
193
+ if (luvioEventObserver !== undefined) {
194
+ requestContext.eventObservers = [luvioEventObserver];
195
+ }
196
+ return requestContext;
197
+ }
198
+ function buildInvalidConfigError(error) {
199
+ return {
200
+ data: undefined,
201
+ error: {
202
+ ok: false,
203
+ status: 400,
204
+ statusText: 'INVALID_CONFIG',
205
+ body: error,
206
+ headers: {},
207
+ errorType: 'fetchResponse',
208
+ },
209
+ };
210
+ }
211
+ function buildNativeCallbackValue(adapterCallbackValue) {
212
+ const { error } = adapterCallbackValue;
213
+ // Luvio NetworkAdapterError objects (which are just Error objects) must be
214
+ // turned into NativeNetworkAdapterErrorResponse because it serializes well
215
+ if (error !== undefined && error.errorType === 'networkAdapterError') {
216
+ return {
217
+ data: undefined,
218
+ error: new NativeNetworkAdapterErrorResponse(error),
219
+ };
220
+ }
221
+ // any other callback value does not need coercion, just retype
222
+ return adapterCallbackValue;
223
+ }
224
+ /**
225
+ *
226
+ * @param adapterId
227
+ * @returns imperative adapter key
228
+ */
229
+ function imperativeAdapterKeyBuilder(adapterId) {
230
+ if (adapterId.startsWith(UNSTABLE_ADAPTER_PREFIX)) {
231
+ return `${adapterId}${IMPERATIVE_ADAPTER_SUFFIX}`;
232
+ }
233
+ return `${UNSTABLE_ADAPTER_PREFIX}${adapterId}${IMPERATIVE_ADAPTER_SUFFIX}`;
234
+ }
235
+ /**
236
+ * Executes the adapter with the given adapterId and config. Will call onSnapshot
237
+ * callback with data or error. Returns an unsubscribe function that should
238
+ * be called to stop receiving updated snapshots.
239
+ *
240
+ * This function throws an error if the given adapterId cannot be found or is not
241
+ * a GET wire adapter. It will also throw if it fails to parse the config string.
242
+ */
243
+ function subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
244
+ const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
245
+ const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
246
+ const onResponseDelegate = (value) => {
247
+ onSnapshot(buildNativeCallbackValue(value));
248
+ };
249
+ if (imperativeAdapter === undefined) {
250
+ // This check is here for legacy purpose
251
+ // So the consumers still get the same errors
252
+ if (getDMLAdapterFromName(adapterId) === undefined) {
253
+ throw Error(`adapter ${adapterId} not recognized`);
254
+ }
255
+ throw Error(`${adapterId} is not a GET wire adapter.`);
256
+ }
257
+ const configObject = parse(config);
258
+ // Check if it's graphQl adapter
259
+ // Parse the query in that case
260
+ const isGql = isGqlAdapter(imperativeAdapterIdentifier);
261
+ if (isGql) {
262
+ try {
263
+ // gql config needs gql query string turned into AST object
264
+ configObject.query = parseAndVisit(configObject.query);
265
+ }
266
+ catch (err) {
267
+ const parseError = normalizeError(err);
268
+ reportGraphqlQueryParseError(parseError);
269
+ // call the callback with error
270
+ onResponseDelegate({
271
+ data: undefined,
272
+ error: createNativeFetchErrorResponse(parseError.message),
273
+ });
274
+ return () => { };
275
+ }
276
+ }
277
+ if (imperativeAdapterIdentifier.includes('graphql')) {
278
+ try {
279
+ //we need to use the gql literal to convert into a document node
280
+ //in order to get through the gql imperative adapter
281
+ configObject.query = gql `
282
+ ${configObject.query}
283
+ `;
284
+ }
285
+ catch (err) {
286
+ const parseError = normalizeError(err);
287
+ reportGraphqlQueryParseError(parseError);
288
+ // call the callback with error
289
+ onResponseDelegate({
290
+ data: undefined,
291
+ error: createNativeFetchErrorResponse(parseError.message),
292
+ });
293
+ return () => { };
294
+ }
295
+ }
296
+ try {
297
+ return imperativeAdapter.subscribe(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
298
+ }
299
+ catch (err) {
300
+ if (isGql) {
301
+ reportGraphqlQueryParseError(err);
302
+ }
303
+ onResponseDelegate(buildInvalidConfigError(err));
304
+ return () => { };
305
+ }
306
+ }
307
+ /**
308
+ * Checks if the given adapter id is a graphQL adapter
309
+ *
310
+ * @param imperativeAdapterIdentifier The adapter id to check
311
+ * @returns true if the adapter is graphQL, false otherwise
312
+ */
313
+ function isGqlAdapter(imperativeAdapterIdentifier) {
314
+ return keys(gqlApi).indexOf(imperativeAdapterIdentifier) > -1;
315
+ }
316
+ /**
317
+ * Executes a DML adapter and calls the onResponse callback upon receiving a response.
318
+ *
319
+ * @param adapter : DML Adapter
320
+ * @param configObject : parsed config
321
+ * @param onResponse : OnResponse
322
+ * @param nativeAdapterRequestContext: Specify cache policy, priority and observability parameters
323
+ */
324
+ function invokeDmlAdapter(adapter, configObject, onResponse, nativeAdapterRequestContext) {
325
+ try {
326
+ adapter(configObject, buildAdapterRequestContext(nativeAdapterRequestContext)).then((data) => {
327
+ onResponse({ data, error: undefined });
328
+ }, (error) => {
329
+ onResponse({ data: undefined, error });
330
+ });
331
+ }
332
+ catch (err) {
333
+ // For catching the synchronous error in adapter
334
+ onResponse(buildInvalidConfigError(err));
335
+ }
336
+ }
337
+ /**
338
+ * Executes the specified adapter with the given adapterId and config. Then
339
+ * it replaces the draft with the given id with the draft generated
340
+ * by the mutating adapter. Will call onResult callback once with data or error.
341
+ *
342
+ * This function throws an error if the given adapterId cannot be found, or if the
343
+ * adapterId is not a mutating adapter, or if a draft isn't created, or if it
344
+ * fails to parse the given config string.
345
+ */
346
+ function invokeAdapterWithDraftToReplace(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
347
+ draftManager.getQueue().then((draftInfo) => {
348
+ const draftIds = draftInfo.items.map((draft) => draft.id);
349
+ if (draftIds.includes(draftIdToReplace) === false) {
350
+ onResponse({
351
+ data: undefined,
352
+ error: createNativeFetchErrorResponse(DRAFT_DOESNT_EXIST_MESSAGE),
353
+ });
354
+ return;
355
+ }
356
+ const adapter = getDMLAdapterFromName(adapterId);
357
+ if (adapter === undefined) {
358
+ // This check is here for legacy purpose
359
+ // So the consumers still get the same errors
360
+ if (getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined) {
361
+ onResponse({
362
+ data: undefined,
363
+ error: createNativeFetchErrorResponse(NON_MUTATING_ADAPTER_MESSAGE),
364
+ });
365
+ return;
366
+ }
367
+ throw Error(`adapter ${adapterId} not recognized`);
368
+ }
369
+ if (adapterId === 'deleteRecord') {
370
+ invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext);
371
+ }
372
+ else {
373
+ invokeDmlAdapter(adapter, parse(config), (responseValue) => {
374
+ const draftIds = draftIdsForResponseValue(responseValue);
375
+ if (responseValue.error === undefined &&
376
+ draftIds !== undefined &&
377
+ draftIds.length > 0) {
378
+ const draftId = draftIds[draftIds.length - 1];
379
+ draftManager.replaceAction(draftIdToReplace, draftId).then(() => {
380
+ onResponse(responseValue);
381
+ });
382
+ }
383
+ else {
384
+ let response = responseValue;
385
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
386
+ onResponse(response);
387
+ }
388
+ }, nativeAdapterRequestContext);
389
+ }
390
+ });
391
+ }
392
+ /**
393
+ * Executes the specified adapter with the given adapterId and config. Then
394
+ * it sets the given metadata on the draft created by the mutating adapter. Will call
395
+ * onResult callback once with data or error.
396
+ *
397
+ * This function throws an error if the given adapterId cannot be found, or if the
398
+ * adapterId is not a mutating adapter, or if a draft isn't created, or if it
399
+ * fails to parse the given config string.
400
+ */
401
+ function invokeAdapterWithMetadata(adapterId, config, metadata, onResponse, nativeAdapterRequestContext) {
402
+ const adapter = getDMLAdapterFromName(adapterId);
403
+ if (adapter === undefined) {
404
+ // This check is here for legacy purpose
405
+ // So the consumers still get the same errors
406
+ if (getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined) {
407
+ onResponse({
408
+ data: undefined,
409
+ error: createNativeFetchErrorResponse(NON_MUTATING_ADAPTER_MESSAGE),
410
+ });
411
+ return;
412
+ }
413
+ throw Error(`adapter ${adapterId} not recognized`);
414
+ }
415
+ if (adapterId === 'deleteRecord') {
416
+ invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponse, nativeAdapterRequestContext);
417
+ }
418
+ else {
419
+ invokeDmlAdapter(adapter, parse(config), (responseValue) => {
420
+ const draftIds = draftIdsForResponseValue(responseValue);
421
+ if (responseValue.error === undefined &&
422
+ draftIds !== undefined &&
423
+ draftIds.length > 0) {
424
+ const draftId = draftIds[draftIds.length - 1];
425
+ draftManager.setMetadata(draftId, metadata).then(() => {
426
+ onResponse(responseValue);
427
+ });
428
+ }
429
+ else {
430
+ let response = responseValue;
431
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
432
+ onResponse(response);
433
+ }
434
+ }, nativeAdapterRequestContext);
435
+ }
436
+ }
437
+ /*
438
+ //TODO W-10284305: Remove this function in 238
439
+ This is a special case version of the invokeAdapterWithMetadata function
440
+ which should only be used for the deleteRecord wire adapter, since it does not
441
+ contain record data in the result and has to do special querying of the draft queue
442
+ */
443
+ function invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponse, nativeAdapterRequestContext) {
444
+ const targetedRecordId = parse(config);
445
+ let priorDraftIds;
446
+ draftManager.getQueue().then((draftState) => {
447
+ priorDraftIds = draftState.items.map((item) => {
448
+ return item.id;
449
+ });
450
+ invokeDmlAdapter(adapter, parse(config), (responseValue) => {
451
+ if (responseValue.error === undefined && responseValue.data === undefined) {
452
+ draftManager.getQueue().then((newState) => {
453
+ const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
454
+ const newDrafts = newState.items;
455
+ const addedDrafts = newDrafts.filter((item) => {
456
+ const isNew = draftIdsToFilter.indexOf(item.id) < 0;
457
+ const targetIdMatches = item.targetId === targetedRecordId;
458
+ return isNew && targetIdMatches;
459
+ });
460
+ if (addedDrafts.length !== 1) {
461
+ let response = responseValue;
462
+ response.error =
463
+ createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
464
+ onResponse(response);
465
+ }
466
+ else {
467
+ draftManager.setMetadata(addedDrafts[0].id, metadata).then(() => {
468
+ onResponse(responseValue);
469
+ });
470
+ }
471
+ });
472
+ }
473
+ else {
474
+ let response = responseValue;
475
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
476
+ onResponse(response);
477
+ }
478
+ }, nativeAdapterRequestContext);
479
+ });
480
+ }
481
+ /*
482
+ //TODO W-10284305: Remove this function in 238
483
+ This is a special case version of the invokeAdapterWithDraftToReplace function
484
+ which should only be used for the deleteRecord wire adapter, since it does not
485
+ contain record data in the result and has to do special querying of the draft queue
486
+ */
487
+ function invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
488
+ const targetedRecordId = parse(config);
489
+ let priorDraftIds;
490
+ draftManager.getQueue().then((draftState) => {
491
+ priorDraftIds = draftState.items.map((item) => {
492
+ return item.id;
493
+ });
494
+ invokeDmlAdapter(adapter, parse(config), (responseValue) => {
495
+ if (responseValue.error === undefined && responseValue.data === undefined) {
496
+ draftManager.getQueue().then((newState) => {
497
+ const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
498
+ const newDrafts = newState.items;
499
+ const addedDrafts = newDrafts.filter((item) => {
500
+ const isNew = draftIdsToFilter.indexOf(item.id) < 0;
501
+ const targetIdMatches = item.targetId === targetedRecordId;
502
+ return isNew && targetIdMatches;
503
+ });
504
+ if (addedDrafts.length !== 1) {
505
+ let response = responseValue;
506
+ response.error =
507
+ createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
508
+ onResponse(response);
509
+ }
510
+ else {
511
+ draftManager
512
+ .replaceAction(draftIdToReplace, addedDrafts[0].id)
513
+ .then(() => {
514
+ onResponse(responseValue);
515
+ });
516
+ }
517
+ });
518
+ }
519
+ else {
520
+ let response = responseValue;
521
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
522
+ onResponse(response);
523
+ }
524
+ }, nativeAdapterRequestContext);
525
+ });
526
+ }
527
+ function draftIdsForResponseValue(response) {
528
+ if (response.data !== undefined &&
529
+ response.data.drafts !== undefined &&
530
+ response.data.drafts.draftActionIds !== undefined) {
531
+ return response.data.drafts.draftActionIds;
532
+ }
533
+ return undefined;
534
+ }
535
+ /**
536
+ * Executes the specified adapter with the given adapterId and config. Will call
537
+ * onResponse callback once with data or error.
538
+ *
539
+ * This function throws an error if the given adapterId cannot be found or if it
540
+ * fails to parse the given config string.
541
+ */
542
+ function invokeAdapter(adapterId, config, onResponse, nativeAdapterRequestContext) {
543
+ const onResponseDelegate = (value) => {
544
+ onResponse(buildNativeCallbackValue(value));
545
+ };
546
+ const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
547
+ const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
548
+ const configObject = parse(config);
549
+ // currently all uiapi GET adapters have a corresponding imperative adapter
550
+ if (imperativeAdapter !== undefined) {
551
+ // Check if it's graphQl adapter
552
+ // Parse the query in that case
553
+ const isGql = isGqlAdapter(imperativeAdapterIdentifier);
554
+ if (isGql) {
555
+ try {
556
+ // gql config needs gql query string turned into AST object
557
+ configObject.query = parseAndVisit(configObject.query);
558
+ }
559
+ catch (err) {
560
+ const parseError = normalizeError(err);
561
+ reportGraphqlQueryParseError(parseError);
562
+ // call the callback with error
563
+ onResponseDelegate({
564
+ data: undefined,
565
+ error: createNativeFetchErrorResponse(parseError.message),
566
+ });
567
+ return;
568
+ }
569
+ }
570
+ //unstable_graphql_imperative
571
+ if (imperativeAdapterIdentifier.includes('graphql')) {
572
+ try {
573
+ //we need to use the gql literal to convert into a document node
574
+ //in order to get through the gql imperative adapter
575
+ configObject.query = gql `
576
+ ${configObject.query}
577
+ `;
578
+ }
579
+ catch (err) {
580
+ const parseError = normalizeError(err);
581
+ reportGraphqlQueryParseError(parseError);
582
+ // call the callback with error
583
+ onResponseDelegate({
584
+ data: undefined,
585
+ error: createNativeFetchErrorResponse(parseError.message),
586
+ });
587
+ return;
588
+ }
589
+ }
590
+ try {
591
+ imperativeAdapter.invoke(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
592
+ }
593
+ catch (err) {
594
+ if (isGql) {
595
+ reportGraphqlQueryParseError(err);
596
+ }
597
+ onResponseDelegate(buildInvalidConfigError(err));
598
+ }
599
+ return;
600
+ }
601
+ const adapter = getDMLAdapterFromName(adapterId);
602
+ if (adapter === undefined) {
603
+ throw Error(`adapter ${adapterId} not recognized`);
604
+ }
605
+ invokeDmlAdapter(adapter, configObject, onResponseDelegate, nativeAdapterRequestContext);
606
+ }
607
+ /**
608
+ * @deprecated Use invokeAdapter or subscribeToAdapter instead
609
+ *
610
+ * W-9173084 Will remove this
611
+ */
612
+ function executeAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
613
+ return subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext);
614
+ }
615
+ /**
616
+ * @deprecated Use invokeAdapter instead
617
+ *
618
+ * W-9173084 Will remove this
619
+ */
620
+ function executeMutatingAdapter(adapterId, config, onResult, nativeAdapterRequestContext) {
621
+ invokeAdapter(adapterId, config, onResult, nativeAdapterRequestContext);
622
+ }
623
+
624
+ /* istanbul ignore file */
625
+ // A allowlist of methods that we allow to be proxied from another LDS instance
626
+ const allowList = ['enqueue', 'getQueueActions', 'getDataForAction'];
627
+ /**
628
+ * Implements the DraftQueue interface from nimbus-plugin-lds by passing requests
629
+ * to the instance of the lds-drafts' DraftQueue implementation
630
+ */
631
+ const nimbusDraftQueue = {
632
+ callProxyMethod(methodName, serializedArgsArray, resultCallback, errorCallback) {
633
+ const method = draftQueue[methodName];
634
+ if (method === undefined) {
635
+ return errorCallback(stringify({
636
+ message: 'Method does not exist on the draft queue',
637
+ }));
638
+ }
639
+ if (allowList.includes(methodName) === false) {
640
+ return errorCallback(stringify({
641
+ message: `Method ${methodName} is not available for proxy invocation`,
642
+ }));
643
+ }
644
+ const parsedArgs = parse(serializedArgsArray);
645
+ // TODO [W-9933226]: we should validate the argument list based on which method is being called
646
+ if (isArray(parsedArgs) === false) {
647
+ return errorCallback(stringify({
648
+ message: 'expected array argument list',
649
+ }));
650
+ }
651
+ let methodResult = undefined;
652
+ try {
653
+ if (parsedArgs === undefined) {
654
+ methodResult = method.call(draftQueue);
655
+ }
656
+ else {
657
+ methodResult = method.call(draftQueue, ...parsedArgs);
658
+ }
659
+ }
660
+ catch (err) {
661
+ return errorCallback(stringify(err));
662
+ }
663
+ if (methodResult.then === undefined) {
664
+ return resultCallback(stringify(methodResult));
665
+ }
666
+ methodResult
667
+ .then((result) => {
668
+ resultCallback(stringify(result));
669
+ })
670
+ .catch((err) => {
671
+ errorCallback(stringify(err));
672
+ });
673
+ },
674
+ };
675
+
676
+ /**
677
+ * Copyright (c) 2022, Salesforce, Inc.,
678
+ * All rights reserved.
679
+ * For full license text, see the LICENSE.txt file
680
+ */
681
+
682
+ const API_NAMESPACE = 'UiApi';
683
+ const RECORD_REPRESENTATION_NAME = 'RecordRepresentation';
684
+
685
+ let luvio = undefined;
686
+ let uiApiRecordTTL;
687
+ let metadataTTL;
688
+ withDefaultLuvio((_luvio) => {
689
+ luvio = _luvio;
690
+ if (uiApiRecordTTL !== undefined) {
691
+ // Note: This should rarely get hit and the durable store implementation
692
+ // should have read write synchronization to protect against race conditions
693
+ // Here since we are on a synchronous path we cannot await the Promise
694
+ setUiApiRecordTTL(uiApiRecordTTL);
695
+ }
696
+ if (metadataTTL !== undefined) {
697
+ // Note: This should rarely get hit and the durable store implementation
698
+ // should have read write synchronization to protect against race conditions
699
+ // Here since we are on a synchronous path we cannot await the Promise
700
+ setMetadataTTL(metadataTTL);
701
+ }
702
+ });
703
+ function setUiApiRecordTTL(ttl) {
704
+ uiApiRecordTTL = ttl;
705
+ if (luvio === undefined) {
706
+ return Promise.resolve();
707
+ }
708
+ return luvio.storeSetTTLOverride(API_NAMESPACE, RECORD_REPRESENTATION_NAME, ttl);
709
+ }
710
+ function setMetadataTTL(ttl) {
711
+ metadataTTL = ttl;
712
+ if (luvio === undefined) {
713
+ return Promise.resolve();
714
+ }
715
+ return luvio.storeSetDefaultTTLOverride(ttl);
716
+ }
717
+
718
+ function createPrimingSession(config) {
719
+ const { createPrimingSession } = getRuntime();
720
+ const { primingEventHandler, concurrency, batchSize } = config;
721
+ const session = createPrimingSession({ concurrency, batchSize });
722
+ if (primingEventHandler) {
723
+ const { onError, onPrimed } = primingEventHandler;
724
+ if (onError) {
725
+ session.on('error', onError.bind(primingEventHandler));
726
+ }
727
+ if (onPrimed) {
728
+ session.on('primed', onPrimed.bind(primingEventHandler));
729
+ }
730
+ }
731
+ return {
732
+ enqueue: session.enqueue.bind(session),
733
+ };
734
+ }
735
+
736
+ if (process.env.NODE_ENV !== 'production') {
737
+ // eslint-disable-next-line no-undef
738
+ withDefaultLuvio((luvio) => {
739
+ // eslint-disable-next-line no-undef
740
+ const global = typeof globalThis === 'undefined' ? {} : globalThis;
741
+ global.luvio = luvio;
742
+ });
743
+ }
744
+
745
+ export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
746
+ // version: 1.100.2-ca56bb821