@salesforce/lds-worker-api 0.1.0-dev1

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 (120) hide show
  1. package/LICENSE.txt +82 -0
  2. package/README.md +9 -0
  3. package/dist/sfdc/es/ldsWorkerApi.js +1374 -0
  4. package/dist/sfdc/es/types/cachePurging.d.ts +50 -0
  5. package/dist/sfdc/es/types/customLuvioAdapter.d.ts +13 -0
  6. package/dist/sfdc/es/types/customOneStoreAdapter.d.ts +21 -0
  7. package/dist/sfdc/es/types/draftQueueImplementation.d.ts +2 -0
  8. package/dist/sfdc/es/types/executeAdapter.d.ts +103 -0
  9. package/dist/sfdc/es/types/language.d.ts +13 -0
  10. package/dist/sfdc/es/types/lightningAdapterApi.d.ts +15 -0
  11. package/dist/sfdc/es/types/main.d.ts +11 -0
  12. package/dist/sfdc/es/types/nimbusDraftQueue.d.ts +6 -0
  13. package/dist/sfdc/es/types/primingApi.d.ts +25 -0
  14. package/dist/sfdc/es/types/responses.d.ts +44 -0
  15. package/dist/sfdc/es/types/standalone-stubs/instrumentation.d.ts +21 -0
  16. package/dist/sfdc/es/types/standalone-stubs/o11y.d.ts +23 -0
  17. package/dist/sfdc/es/types/standalone-stubs/unwrap.d.ts +1 -0
  18. package/dist/sfdc/es/types/standalone.d.ts +1 -0
  19. package/dist/sfdc/es/types/ttl.d.ts +2 -0
  20. package/dist/standalone/es/lds-worker-api.js +134127 -0
  21. package/dist/standalone/es/types/cachePurging.d.ts +50 -0
  22. package/dist/standalone/es/types/customLuvioAdapter.d.ts +13 -0
  23. package/dist/standalone/es/types/customOneStoreAdapter.d.ts +21 -0
  24. package/dist/standalone/es/types/draftQueueImplementation.d.ts +2 -0
  25. package/dist/standalone/es/types/executeAdapter.d.ts +103 -0
  26. package/dist/standalone/es/types/language.d.ts +13 -0
  27. package/dist/standalone/es/types/lightningAdapterApi.d.ts +15 -0
  28. package/dist/standalone/es/types/main.d.ts +11 -0
  29. package/dist/standalone/es/types/nimbusDraftQueue.d.ts +6 -0
  30. package/dist/standalone/es/types/primingApi.d.ts +25 -0
  31. package/dist/standalone/es/types/responses.d.ts +44 -0
  32. package/dist/standalone/es/types/standalone-stubs/instrumentation.d.ts +21 -0
  33. package/dist/standalone/es/types/standalone-stubs/o11y.d.ts +23 -0
  34. package/dist/standalone/es/types/standalone-stubs/unwrap.d.ts +1 -0
  35. package/dist/standalone/es/types/standalone.d.ts +1 -0
  36. package/dist/standalone/es/types/ttl.d.ts +2 -0
  37. package/dist/standalone/umd/lds-worker-api.js +134154 -0
  38. package/dist/standalone/umd/types/cachePurging.d.ts +50 -0
  39. package/dist/standalone/umd/types/customLuvioAdapter.d.ts +13 -0
  40. package/dist/standalone/umd/types/customOneStoreAdapter.d.ts +21 -0
  41. package/dist/standalone/umd/types/draftQueueImplementation.d.ts +2 -0
  42. package/dist/standalone/umd/types/executeAdapter.d.ts +103 -0
  43. package/dist/standalone/umd/types/language.d.ts +13 -0
  44. package/dist/standalone/umd/types/lightningAdapterApi.d.ts +15 -0
  45. package/dist/standalone/umd/types/main.d.ts +11 -0
  46. package/dist/standalone/umd/types/nimbusDraftQueue.d.ts +6 -0
  47. package/dist/standalone/umd/types/primingApi.d.ts +25 -0
  48. package/dist/standalone/umd/types/responses.d.ts +44 -0
  49. package/dist/standalone/umd/types/standalone-stubs/instrumentation.d.ts +21 -0
  50. package/dist/standalone/umd/types/standalone-stubs/o11y.d.ts +23 -0
  51. package/dist/standalone/umd/types/standalone-stubs/unwrap.d.ts +1 -0
  52. package/dist/standalone/umd/types/standalone.d.ts +1 -0
  53. package/dist/standalone/umd/types/ttl.d.ts +2 -0
  54. package/package.json +78 -0
  55. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/adapter-testcase.schema.json +83 -0
  56. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/name-displayValue-response.adapter-snapshot.result.json +61 -0
  57. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/name-displayValue.adapter-testcase.json +67 -0
  58. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/objectInfos/Aircraft-objectInfo.network-mock.json +582 -0
  59. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/objectInfos/Pilot-objectInfo.network-mock.json +367 -0
  60. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/scalar-displayValue-nonIntl-fallback-response.adapter-snapshot.result.json +90 -0
  61. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/scalar-displayValue-nonIntl-fallback.adapter-testcase.json +25 -0
  62. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/scalar-displayValue-response.adapter-snapshot.result.json +90 -0
  63. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/createRecord/scalar-displayValue.adapter-testcase.json +24 -0
  64. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-assignedtome.adapter-testcase.json +37 -0
  65. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-baseline.adapter-testcase.json +27 -0
  66. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-child-relationship.adapter-testcase.json +32 -0
  67. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-parent-relationship.adapter-testcase.json +32 -0
  68. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/adapter-forward-reserved-entity-name.adapter-testcase.json +28 -0
  69. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/assignedtome.adapter-testcase.json +36 -0
  70. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/date-predicate.adapter-testcase.json +26 -0
  71. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/graphql-get-errors.adapter-testcase.json +26 -0
  72. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/l2DataSet.js +252 -0
  73. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-baseline.adapter-testcase.json +21 -0
  74. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where-orderby-allfields-spanningfield-500records.adapter-testcase.json +28 -0
  75. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where-orderby-allfields-spanningfield.adapter-testcase.json +28 -0
  76. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where-orderby-allfields.adapter-testcase.json +21 -0
  77. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where-orderby.adapter-testcase.json +21 -0
  78. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/legacy/getTimeSheetEntry-where.adapter-testcase.json +21 -0
  79. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/multiple-recordquery.adapter-testcase.json +31 -0
  80. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/Account.network-mock.json +2920 -0
  81. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/AssignedResource.network-mock.json +928 -0
  82. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/Case.network-mock.json +2008 -0
  83. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/ServiceAppointment.network-mock.json +3123 -0
  84. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/ServiceResource.network-mock.json +1412 -0
  85. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/TimeSheetEntry.network-mock.json +1027 -0
  86. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/User.network-mock.json +7031 -0
  87. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/WorkOrder.network-mock.json +3216 -0
  88. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectInfos/WorkType.network-mock.json +986 -0
  89. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/objectinfo.adapter-testcase.json +21 -0
  90. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/polyfield.adapter-testcase.json +46 -0
  91. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/polyquery-and-operator.adapter-testcase.json +31 -0
  92. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/adapter-forward-baseline.server-response.network-mock.json +416 -0
  93. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/adapter-forward-child-relationship.server-response.network-mock.json +103 -0
  94. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/adapter-forward-parent-relationship.server-response.network-mock.json +93 -0
  95. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/adapter-forward-reserved-entity-name.server-response.network-mock.json +97 -0
  96. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/assignedtome.server-response.network-mock.json +666 -0
  97. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/date-predicate.server-response.network-mock.json +56 -0
  98. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/graphql-get-errors.server-response.network-mock.json +19 -0
  99. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/multiple-recordquery.server-response.network-mock.json +201 -0
  100. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/objectinfos.server-response.network-mock.json +210 -0
  101. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/polyfield.server-response.network-mock.json +724 -0
  102. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/polyquery-and-operator.server-response.network-mock.json +103 -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/date-predicate.adapter-snapshot.result.json +18 -0
  110. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/graphql-get-errors.adapter-snapshot.result.json +16 -0
  111. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/multiple-recordquery.adapter-snapshot.result.json +53 -0
  112. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/objectinfos.adapter-snapshot.result.json +170 -0
  113. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/polyfield.adapter-snapshot.result.json +29 -0
  114. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/polyquery-and-operator.adapter-snapshot.result.json +23 -0
  115. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/metadataVersion/adapter-snapshot.result.json +9 -0
  116. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/metadataVersion/old-metadata-fails-cache-only-adapter-call.adapter-testcase.json +16 -0
  117. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/metadataVersion/old-metadata-fails-cache-only-adapter-call.l2DataSet.tsv +2 -0
  118. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/metadataVersion/old-version-fails-cache-only-adapter-call.adapter-testcase.json +16 -0
  119. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/metadataVersion/old-version-fails-cache-only-adapter-call.l2DataSet.tsv +2 -0
  120. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/network-mock.schema.json +14 -0
@@ -0,0 +1,1374 @@
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 lightningLayoutUserStateApi from 'lightning/uiLayoutUserStateApi';
19
+ import * as unstableLightningLayoutApi from 'lightning/unstable_uiLayoutApi';
20
+ import * as lightningListApi from 'lightning/uiListApi';
21
+ import * as unstableLightningListApi from 'lightning/unstable_uiListApi';
22
+ import * as lightningLookupsApi from 'lightning/uiLookupsApi';
23
+ import * as unstableLightningLookupsApi from 'lightning/unstable_uiLookupsApi';
24
+ import * as lightningObjectApi from 'lightning/uiObjectInfoApi';
25
+ import * as unstableLightningObjectApi from 'lightning/unstable_uiObjectInfoApi';
26
+ import * as lightningRecordActionsApi from 'lightning/uiRecordActionsApi';
27
+ import * as unstableLightningRecordActionsApi from 'lightning/unstable_uiRecordActionsApi';
28
+ import * as lightningRecordApi from 'lightning/uiRecordApi';
29
+ import * as unstableLightningRecordApi from 'lightning/unstable_uiRecordApi';
30
+ import * as lightningRecordAvatarApi from 'lightning/uiRecordAvatarApi';
31
+ import * as unstableLightningRecordAvatarApi from 'lightning/unstable_uiRecordAvatarApi';
32
+ import * as lightningRelatedListApi from 'lightning/uiRelatedListApi';
33
+ import * as unstableLightningRelatedListApi from 'lightning/unstable_uiRelatedListApi';
34
+ import * as lightningGraphQLApi from 'lightning/uiGraphQLApi';
35
+ import * as gqlApi from 'force/ldsAdaptersGraphql';
36
+ import { getRuntime, O11Y_NAMESPACE_LDS_MOBILE, reportGraphqlQueryParseError } from 'native/ldsRuntimeMobile';
37
+ export { registerReportObserver } from 'native/ldsRuntimeMobile';
38
+ import { HttpStatusCode } from 'force/luvioEngine';
39
+ import { getInstrumentation } from 'o11y/client';
40
+ import { API_NAMESPACE, RECORD_REPRESENTATION_NAME, keyBuilderRecord } from 'force/ldsAdaptersUiapi';
41
+ import { withDefaultLuvio } from 'native/ldsEngineMobile';
42
+ import { evictCacheRecordsByIdsSchema, evictExpiredEntriesSchema } from 'o11y_schema/sf_lds';
43
+
44
+ const { create, keys } = Object;
45
+ const { stringify, parse } = JSON;
46
+ const { isArray } = Array;
47
+
48
+ const IMPERATIVE_ADAPTER_SUFFIX = '_imperative';
49
+ const UNSTABLE_ADAPTER_PREFIX = 'unstable_';
50
+ function extractWireAdapterName(adapterName) {
51
+ const parts = adapterName.split(UNSTABLE_ADAPTER_PREFIX);
52
+ if (parts.length > 1) {
53
+ return parts[1].substr(0, parts[1].indexOf(IMPERATIVE_ADAPTER_SUFFIX));
54
+ }
55
+ return adapterName.substr(0, adapterName.indexOf(IMPERATIVE_ADAPTER_SUFFIX));
56
+ }
57
+ let lazyDMLAdapterMap = undefined;
58
+ let lazyImperativeAdapterMap = undefined;
59
+ function buildAdapterMaps(map) {
60
+ const imperativeAdapterNames = keys(map).filter((name) => name.endsWith(IMPERATIVE_ADAPTER_SUFFIX));
61
+ const imperativeAdapterMap = {};
62
+ for (const adapterName of imperativeAdapterNames) {
63
+ const adapter = map[adapterName];
64
+ imperativeAdapterMap[adapterName] = adapter;
65
+ delete map[adapterName];
66
+ // remove the corresponding wire adapter from the adapter map
67
+ const wireAdapterName = extractWireAdapterName(adapterName);
68
+ delete map[wireAdapterName];
69
+ }
70
+ return {
71
+ dmlAdapterMap: map,
72
+ imperativeAdapterMap,
73
+ };
74
+ }
75
+ // this function builds the adapter maps lazily
76
+ function getAdapterMaps() {
77
+ if (lazyDMLAdapterMap === undefined || lazyImperativeAdapterMap === undefined) {
78
+ // We should eventually be explicit about what we expose here instead of exporting everything from the modules,
79
+ // this is our API contract to native callers and should be explicit
80
+ const map = Object.assign({}, gqlApi, lightningAppsApi, lightningLayoutApi, lightningLayoutUserStateApi, lightningListApi, lightningLookupsApi, lightningObjectApi, lightningRecordActionsApi, lightningRecordApi, lightningRecordAvatarApi, lightningRelatedListApi, lightningGraphQLApi, unstableLightningAppsApi, unstableLightningLayoutApi, unstableLightningListApi, unstableLightningLookupsApi, unstableLightningObjectApi, unstableLightningRecordActionsApi, unstableLightningRecordApi, unstableLightningRecordAvatarApi, unstableLightningRelatedListApi);
81
+ const { dmlAdapterMap, imperativeAdapterMap } = buildAdapterMaps(map);
82
+ lazyDMLAdapterMap = dmlAdapterMap;
83
+ lazyImperativeAdapterMap = imperativeAdapterMap;
84
+ }
85
+ return { dmlAdapterMap: lazyDMLAdapterMap, imperativeAdapterMap: lazyImperativeAdapterMap };
86
+ }
87
+ function getDMLAdapterFromName(name) {
88
+ const { dmlAdapterMap } = getAdapterMaps();
89
+ return dmlAdapterMap[name];
90
+ }
91
+ function getImperativeAdapterFromName(name) {
92
+ const { imperativeAdapterMap } = getAdapterMaps();
93
+ return imperativeAdapterMap[name];
94
+ }
95
+ function getImperativeAdapterNames() {
96
+ const { imperativeAdapterMap } = getAdapterMaps();
97
+ return keys(imperativeAdapterMap);
98
+ }
99
+
100
+ const { draftManager, draftQueue } = getRuntime();
101
+
102
+ const NATIVE_ERROR_CODE = 'NATIVE_ERROR';
103
+ const NON_MUTATING_ADAPTER_MESSAGE = 'adapterId must be a mutating adapter';
104
+ const NO_DRAFT_CREATED_MESSAGE = 'the adapter did not generate a draft';
105
+ const DRAFT_DOESNT_EXIST_MESSAGE = 'the specified draft does not exist';
106
+ /**
107
+ * Error objects don't serialize well over the js-native wire, so our class turns
108
+ * an Error into an object that serializes real nice
109
+ */
110
+ class NativeNetworkAdapterErrorResponse {
111
+ constructor(error) {
112
+ this.errorType = 'networkAdapterError';
113
+ this.message = error.message;
114
+ this.name = error.name;
115
+ }
116
+ }
117
+ class NativeFetchResponse {
118
+ constructor(status, body) {
119
+ this.headers = {};
120
+ this.status = status;
121
+ this.body = body;
122
+ }
123
+ get statusText() {
124
+ const { status } = this;
125
+ switch (status) {
126
+ case HttpStatusCode.Ok:
127
+ return 'OK';
128
+ case HttpStatusCode.Created:
129
+ return 'Created';
130
+ case HttpStatusCode.NoContent:
131
+ return 'No Content';
132
+ case HttpStatusCode.BadRequest:
133
+ return 'Bad Request';
134
+ case HttpStatusCode.ServerError:
135
+ return 'Server Error';
136
+ default:
137
+ return `Unexpected HTTP Status Code: ${status}`;
138
+ }
139
+ }
140
+ get ok() {
141
+ return this.status >= 200 && this.status < 300;
142
+ }
143
+ }
144
+ class NativeFetchErrorResponse extends NativeFetchResponse {
145
+ constructor() {
146
+ super(...arguments);
147
+ this.errorType = 'fetchResponse';
148
+ }
149
+ }
150
+ function createNativeFetchErrorResponse(message) {
151
+ return new NativeFetchErrorResponse(HttpStatusCode.BadRequest, {
152
+ errorCode: NATIVE_ERROR_CODE,
153
+ message: message,
154
+ });
155
+ }
156
+ /**
157
+ * This function takes an unknown error and normalizes it to an Error object
158
+ */
159
+ function normalizeError(error) {
160
+ if (typeof error === 'object' && error instanceof Error) {
161
+ return error;
162
+ }
163
+ else if (typeof error === 'string') {
164
+ return new Error(error);
165
+ }
166
+ return new Error(stringify(error));
167
+ }
168
+
169
+ const ldsMobileInstrumentation$1 = getInstrumentation(O11Y_NAMESPACE_LDS_MOBILE);
170
+ /**
171
+ * Coerces a cache policy passed in from native to a luvio cache policy
172
+ * @param nativeCachePolicy The cache policy passed in from native
173
+ * @returns A coerced luvio cache policy
174
+ */
175
+ function buildCachePolicy(nativeCachePolicy) {
176
+ if (nativeCachePolicy === undefined) {
177
+ return undefined;
178
+ }
179
+ // currently the types match exactly, if we ever decide to deviate then we should coerce here
180
+ return nativeCachePolicy;
181
+ }
182
+ /**
183
+ * Coerces a request context passed in from native to a luvio request context
184
+ * @param nativeRequestContext request context passed in from native
185
+ * @returns Coerced luvio request context
186
+ */
187
+ function buildAdapterRequestContext(nativeRequestContext) {
188
+ if (nativeRequestContext === undefined) {
189
+ return undefined;
190
+ }
191
+ const { cachePolicy, priority, observabilityContext, luvioEventObserver } = nativeRequestContext;
192
+ const requestContext = {
193
+ cachePolicy: buildCachePolicy(cachePolicy),
194
+ priority,
195
+ };
196
+ if (observabilityContext !== undefined && observabilityContext !== null) {
197
+ requestContext.requestCorrelator = {
198
+ observabilityContext,
199
+ };
200
+ }
201
+ if (luvioEventObserver !== undefined) {
202
+ requestContext.eventObservers = [luvioEventObserver];
203
+ }
204
+ return requestContext;
205
+ }
206
+ function buildInvalidConfigError(error) {
207
+ return {
208
+ data: undefined,
209
+ error: {
210
+ ok: false,
211
+ status: 400,
212
+ statusText: 'INVALID_CONFIG',
213
+ body: error,
214
+ headers: {},
215
+ errorType: 'fetchResponse',
216
+ },
217
+ };
218
+ }
219
+ function buildNativeCallbackValue(adapterCallbackValue) {
220
+ const { error } = adapterCallbackValue;
221
+ // Luvio NetworkAdapterError objects (which are just Error objects) must be
222
+ // turned into NativeNetworkAdapterErrorResponse because it serializes well
223
+ if (error !== undefined && error.errorType === 'networkAdapterError') {
224
+ return {
225
+ data: undefined,
226
+ error: new NativeNetworkAdapterErrorResponse(error),
227
+ };
228
+ }
229
+ // any other callback value does not need coercion, just retype
230
+ return adapterCallbackValue;
231
+ }
232
+ /**
233
+ *
234
+ * @param adapterId
235
+ * @returns imperative adapter key
236
+ */
237
+ function imperativeAdapterKeyBuilder(adapterId) {
238
+ if (adapterId.startsWith(UNSTABLE_ADAPTER_PREFIX)) {
239
+ return `${adapterId}${IMPERATIVE_ADAPTER_SUFFIX}`;
240
+ }
241
+ return `${UNSTABLE_ADAPTER_PREFIX}${adapterId}${IMPERATIVE_ADAPTER_SUFFIX}`;
242
+ }
243
+ /**
244
+ * Executes the adapter with the given adapterId and config. Will call onSnapshot
245
+ * callback with data or error. Returns an unsubscribe function that should
246
+ * be called to stop receiving updated snapshots.
247
+ *
248
+ * This function returns an error if the given adapterId cannot be found or is not
249
+ * a GET wire adapter. It will also return an error if it fails to parse the config string.
250
+ */
251
+ function subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
252
+ const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
253
+ const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
254
+ const onResponseDelegate = (value) => {
255
+ onSnapshot(buildNativeCallbackValue(value));
256
+ };
257
+ if (imperativeAdapter === undefined) {
258
+ // This check is here for legacy purpose
259
+ // So the consumers still get the same errors
260
+ if (getDMLAdapterFromName(adapterId) === undefined) {
261
+ onResponseDelegate({
262
+ data: undefined,
263
+ error: createNativeFetchErrorResponse(`adapter ${adapterId} not recognized`),
264
+ });
265
+ return () => { };
266
+ }
267
+ onResponseDelegate({
268
+ data: undefined,
269
+ error: createNativeFetchErrorResponse(`${adapterId} is not a GET wire adapter.`),
270
+ });
271
+ return () => { };
272
+ }
273
+ const configObject = parse(config);
274
+ // Check if it's graphQl adapter
275
+ // Parse the query in that case
276
+ const isGql = isGqlAdapter(imperativeAdapterIdentifier);
277
+ if (isGql) {
278
+ try {
279
+ // gql config needs gql query string turned into AST object
280
+ configObject.query = parseAndVisit(configObject.query);
281
+ }
282
+ catch (err) {
283
+ const parseError = normalizeError(err);
284
+ reportGraphqlQueryParseError(parseError);
285
+ // call the callback with error
286
+ onResponseDelegate({
287
+ data: undefined,
288
+ error: createNativeFetchErrorResponse(parseError.message),
289
+ });
290
+ return () => { };
291
+ }
292
+ }
293
+ if (imperativeAdapterIdentifier.includes('graphql')) {
294
+ try {
295
+ //we need to use the gql literal to convert into a document node
296
+ //in order to get through the gql imperative adapter
297
+ configObject.query = gql `
298
+ ${configObject.query}
299
+ `;
300
+ }
301
+ catch (err) {
302
+ const parseError = normalizeError(err);
303
+ reportGraphqlQueryParseError(parseError);
304
+ // call the callback with error
305
+ onResponseDelegate({
306
+ data: undefined,
307
+ error: createNativeFetchErrorResponse(parseError.message),
308
+ });
309
+ return () => { };
310
+ }
311
+ }
312
+ try {
313
+ return imperativeAdapter.subscribe(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
314
+ }
315
+ catch (err) {
316
+ if (isGql) {
317
+ reportGraphqlQueryParseError(err);
318
+ }
319
+ onResponseDelegate(buildInvalidConfigError(err));
320
+ return () => { };
321
+ }
322
+ }
323
+ /**
324
+ * Checks if the given adapter id is a graphQL adapter
325
+ *
326
+ * @param imperativeAdapterIdentifier The adapter id to check
327
+ * @returns true if the adapter is graphQL, false otherwise
328
+ */
329
+ function isGqlAdapter(imperativeAdapterIdentifier) {
330
+ return keys(gqlApi).indexOf(imperativeAdapterIdentifier) > -1;
331
+ }
332
+ /**
333
+ * Executes a DML adapter and calls the onResponse callback upon receiving a response.
334
+ *
335
+ * @param adapter : DML Adapter
336
+ * @param configObject : parsed config
337
+ * @param onResponse : OnResponse
338
+ * @param nativeAdapterRequestContext: Specify cache policy, priority and observability parameters
339
+ */
340
+ function invokeDmlAdapter(adapter, configObject, onResponse, nativeAdapterRequestContext) {
341
+ try {
342
+ adapter(configObject, buildAdapterRequestContext(nativeAdapterRequestContext)).then((data) => {
343
+ onResponse({ data, error: undefined });
344
+ }, (error) => {
345
+ onResponse({ data: undefined, error });
346
+ });
347
+ }
348
+ catch (err) {
349
+ // For catching the synchronous error in adapter
350
+ onResponse(buildInvalidConfigError(err));
351
+ }
352
+ }
353
+ /**
354
+ * @deprecated There is no situation in which any consumer actually wants to replace the draft.
355
+ * call {@link invokeAdapterWithDraftToMerge} instead`.
356
+ * Keep it for now for app back compatibility.
357
+ * Will be removed in future, ideally 2 releases later.
358
+ */
359
+ function invokeAdapterWithDraftToReplace(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
360
+ invokeAdapterWithDraftToMerge(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext);
361
+ }
362
+ /**
363
+ * Executes the specified adapter with the given @param adapterId and @param config. Then
364
+ * it merges the draft with the given id with the draft generated by
365
+ * the mutating adapter. Will call onResult callback once with data or error.
366
+ *
367
+ * This function returns an error if the given adapterId cannot be found, or if the
368
+ * adapterId is not a mutating adapter if a draft isn't created, or
369
+ * if it fails to parse the given config string.
370
+ *
371
+ * If the @param adapterId is deleteRecod, the invocation of it will generate a delele draft.
372
+ * The newly generated delete draft will replace the draft specified by @param targetDraftId
373
+ */
374
+ function invokeAdapterWithDraftToMerge(adapterId, config, targetDraftId, onResponse, nativeAdapterRequestContext) {
375
+ const adapter = getDMLAdapterFromName(adapterId);
376
+ if (adapter === undefined) {
377
+ // Check if the adapter is non-mutating adapter and create proper error message.
378
+ const message = getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined
379
+ ? NON_MUTATING_ADAPTER_MESSAGE
380
+ : `adapter ${adapterId} not recognized`;
381
+ onResponse({
382
+ data: undefined,
383
+ error: createNativeFetchErrorResponse(message),
384
+ });
385
+ return;
386
+ }
387
+ // deleteRecord adapter call will generate a delete draft and
388
+ // the newly generate draft will replace the target draft
389
+ if (adapterId === 'deleteRecord') {
390
+ invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, targetDraftId, onResponse, nativeAdapterRequestContext);
391
+ return;
392
+ }
393
+ draftManager.getQueue().then((draftInfo) => {
394
+ const draftIds = draftInfo.items.map((draft) => draft.id);
395
+ if (draftIds.includes(targetDraftId) === false) {
396
+ onResponse({
397
+ data: undefined,
398
+ error: createNativeFetchErrorResponse(DRAFT_DOESNT_EXIST_MESSAGE),
399
+ });
400
+ return;
401
+ }
402
+ invokeDmlAdapter(adapter, parse(config), (responseValue) => {
403
+ const draftIds = draftIdsForResponseValue(responseValue);
404
+ if (responseValue.error === undefined &&
405
+ draftIds !== undefined &&
406
+ draftIds.length > 0) {
407
+ const draftId = draftIds[draftIds.length - 1];
408
+ draftManager
409
+ .mergeActions(targetDraftId, draftId)
410
+ .then(() => {
411
+ if (responseValue.data === undefined ||
412
+ responseValue.data.drafts === undefined) {
413
+ onResponse(responseValue);
414
+ return;
415
+ }
416
+ const newResponse = removeDraftNodeActionId(draftId, responseValue);
417
+ onResponse(newResponse);
418
+ })
419
+ .catch((error) => {
420
+ onResponse(convertErrorIntoNativeFetchError(error, `Unknown error merging draft`));
421
+ });
422
+ }
423
+ else {
424
+ let response = responseValue;
425
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
426
+ onResponse(response);
427
+ }
428
+ }, nativeAdapterRequestContext);
429
+ });
430
+ }
431
+ /**
432
+ * Executes the specified adapter with the given adapterId and config. Then
433
+ * it sets the given metadata on the draft created by the mutating adapter. Will call
434
+ * onResult callback once with data or error.
435
+ *
436
+ * This function returns an error if the given adapterId cannot be found, or if the
437
+ * adapterId is not a mutating adapter, or if a draft isn't created, or if it
438
+ * fails to parse the given config string.
439
+ */
440
+ function invokeAdapterWithMetadata(adapterId, config, metadata, onResponse, nativeAdapterRequestContext) {
441
+ const adapter = getDMLAdapterFromName(adapterId);
442
+ if (adapter === undefined) {
443
+ // This check is here for legacy purpose
444
+ // So the consumers still get the same errors
445
+ if (getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined) {
446
+ onResponse({
447
+ data: undefined,
448
+ error: createNativeFetchErrorResponse(NON_MUTATING_ADAPTER_MESSAGE),
449
+ });
450
+ return;
451
+ }
452
+ onResponse({
453
+ data: undefined,
454
+ error: createNativeFetchErrorResponse(`adapter ${adapterId} not recognized`),
455
+ });
456
+ return;
457
+ }
458
+ if (adapterId === 'deleteRecord') {
459
+ draftManager.stopQueueWhileRunning(() => {
460
+ return new Promise((resolve) => {
461
+ const onResponseWrapper = (response) => {
462
+ resolve(response);
463
+ };
464
+ invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponseWrapper, nativeAdapterRequestContext);
465
+ }).then((callbackValue) => {
466
+ onResponse(callbackValue);
467
+ });
468
+ });
469
+ }
470
+ else {
471
+ draftManager.stopQueueWhileRunning(() => {
472
+ return new Promise((resolve) => {
473
+ invokeDmlAdapter(adapter, parse(config), async (responseValue) => {
474
+ const draftIds = draftIdsForResponseValue(responseValue);
475
+ if (responseValue.error === undefined &&
476
+ draftIds !== undefined &&
477
+ draftIds.length > 0) {
478
+ const draftId = draftIds[draftIds.length - 1];
479
+ const managerState = await draftManager.getQueue();
480
+ const draftItem = managerState.items.find((x) => x.id === draftId);
481
+ if (draftItem === undefined) {
482
+ // draftItem no longer exists, might have already been uploaded
483
+ ldsMobileInstrumentation$1.log('tried to set metadata on draft item that no longer exists');
484
+ resolve(responseValue);
485
+ return;
486
+ }
487
+ draftManager
488
+ .setMetadata(draftId, { ...draftItem.metadata, ...metadata })
489
+ .then(() => {
490
+ resolve(responseValue);
491
+ })
492
+ .catch((error) => {
493
+ resolve(convertErrorIntoNativeFetchError(error, 'Unknown error setting metadata'));
494
+ });
495
+ }
496
+ else {
497
+ let response = responseValue;
498
+ response.error =
499
+ createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
500
+ resolve(response);
501
+ }
502
+ }, nativeAdapterRequestContext);
503
+ }).then((callbackValue) => {
504
+ onResponse(callbackValue);
505
+ });
506
+ });
507
+ }
508
+ }
509
+ /*
510
+ //TODO W-10284305: Remove this function in 238
511
+ This is a special case version of the invokeAdapterWithMetadata function
512
+ which should only be used for the deleteRecord wire adapter, since it does not
513
+ contain record data in the result and has to do special querying of the draft queue
514
+ */
515
+ function invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponse, nativeAdapterRequestContext) {
516
+ const targetedRecordId = parse(config);
517
+ let priorDraftIds;
518
+ draftManager.getQueue().then((draftState) => {
519
+ priorDraftIds = draftState.items.map((item) => {
520
+ return item.id;
521
+ });
522
+ invokeDmlAdapter(adapter, parse(config), (responseValue) => {
523
+ if (responseValue.error === undefined &&
524
+ responseValue.errors === undefined &&
525
+ responseValue.data === undefined) {
526
+ draftManager.getQueue().then((newState) => {
527
+ const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
528
+ const newDrafts = newState.items;
529
+ const addedDrafts = newDrafts.filter((item) => {
530
+ const isNew = draftIdsToFilter.indexOf(item.id) < 0;
531
+ const targetIdMatches = item.targetId === targetedRecordId;
532
+ return isNew && targetIdMatches;
533
+ });
534
+ if (addedDrafts.length !== 1) {
535
+ let response = {
536
+ error: createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE),
537
+ };
538
+ onResponse(response);
539
+ }
540
+ else {
541
+ draftManager
542
+ .setMetadata(addedDrafts[0].id, metadata)
543
+ .then(() => {
544
+ onResponse(responseValue);
545
+ })
546
+ .catch((error) => {
547
+ onResponse(convertErrorIntoNativeFetchError(error, 'Unknown error setting metadata'));
548
+ });
549
+ }
550
+ });
551
+ }
552
+ else {
553
+ let response = responseValue;
554
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
555
+ onResponse(response);
556
+ }
557
+ }, nativeAdapterRequestContext);
558
+ });
559
+ }
560
+ /*
561
+ //TODO W-10284305: Remove this function in 238
562
+ This is a special case version of the invokeAdapterWithDraftToMerge function
563
+ which should only be used for the deleteRecord wire adapter, since it does not
564
+ contain record data in the result and has to do special querying of the draft queue
565
+ */
566
+ function invokeAdapterWithDraftToMergeDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
567
+ const targetedRecordId = parse(config);
568
+ let priorDraftIds;
569
+ draftManager.getQueue().then((draftState) => {
570
+ priorDraftIds = draftState.items.map((item) => {
571
+ return item.id;
572
+ });
573
+ invokeDmlAdapter(adapter, parse(config), (responseValue) => {
574
+ if (responseValue.error === undefined &&
575
+ responseValue.errors === undefined &&
576
+ responseValue.data === undefined) {
577
+ draftManager.getQueue().then((newState) => {
578
+ const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
579
+ const newDrafts = newState.items;
580
+ const addedDrafts = newDrafts.filter((item) => {
581
+ const isNew = draftIdsToFilter.indexOf(item.id) < 0;
582
+ const targetIdMatches = item.targetId === targetedRecordId;
583
+ return isNew && targetIdMatches;
584
+ });
585
+ if (addedDrafts.length !== 1) {
586
+ let response = {
587
+ error: createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE),
588
+ };
589
+ onResponse(response);
590
+ }
591
+ else {
592
+ draftManager
593
+ .replaceAction(draftIdToReplace, addedDrafts[0].id)
594
+ .then(() => {
595
+ onResponse(responseValue);
596
+ })
597
+ .catch((error) => {
598
+ onResponse(convertErrorIntoNativeFetchError(error, 'Unknown error replacing action'));
599
+ });
600
+ }
601
+ });
602
+ }
603
+ else {
604
+ let response = responseValue;
605
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
606
+ onResponse(response);
607
+ }
608
+ }, nativeAdapterRequestContext);
609
+ });
610
+ }
611
+ function removeDraftNodeActionId(targetDraftId, responseValue) {
612
+ const recordDraftsNode = {
613
+ ...responseValue.data.drafts,
614
+ draftActionIds: responseValue.data.drafts.draftActionIds.filter((x) => x !== targetDraftId),
615
+ };
616
+ return { ...responseValue, data: { ...responseValue.data, drafts: recordDraftsNode } };
617
+ }
618
+ function convertErrorIntoNativeFetchError(error, defaultMessage) {
619
+ let message = defaultMessage;
620
+ if (error instanceof Error) {
621
+ message = error.message;
622
+ }
623
+ else if (typeof error === 'string') {
624
+ message = error;
625
+ }
626
+ return {
627
+ error: createNativeFetchErrorResponse(message),
628
+ };
629
+ }
630
+ function draftIdsForResponseValue(response) {
631
+ if (response.data !== undefined &&
632
+ response.data.drafts !== undefined &&
633
+ response.data.drafts.draftActionIds !== undefined) {
634
+ return response.data.drafts.draftActionIds;
635
+ }
636
+ if (response.data !== undefined &&
637
+ response.data.contentVersion !== undefined &&
638
+ response.data.contentVersion.drafts !== undefined &&
639
+ response.data.contentVersion.drafts.draftActionIds !== undefined) {
640
+ return response.data.contentVersion.drafts.draftActionIds;
641
+ }
642
+ if (response.data !== undefined &&
643
+ response.data.drafts !== undefined &&
644
+ response.data.drafts.draftActionId !== undefined) {
645
+ return [response.data.drafts.draftActionId];
646
+ }
647
+ return undefined;
648
+ }
649
+ /**
650
+ * Executes the specified adapter with the given adapterId and config. Will call
651
+ * onResponse callback once with data or error.
652
+ *
653
+ * This function returns an error if the given adapterId cannot be found or if it
654
+ * fails to parse the given config string.
655
+ */
656
+ function invokeAdapter(adapterId, config, onResponse, nativeAdapterRequestContext) {
657
+ const onResponseDelegate = (value) => {
658
+ onResponse(buildNativeCallbackValue(value));
659
+ };
660
+ const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
661
+ const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
662
+ const configObject = parse(config);
663
+ // currently all uiapi GET adapters have a corresponding imperative adapter
664
+ if (imperativeAdapter !== undefined) {
665
+ // Check if it's graphQl adapter
666
+ // Parse the query in that case
667
+ const isGql = isGqlAdapter(imperativeAdapterIdentifier);
668
+ if (isGql) {
669
+ try {
670
+ // gql config needs gql query string turned into AST object
671
+ configObject.query = parseAndVisit(configObject.query);
672
+ }
673
+ catch (err) {
674
+ const parseError = normalizeError(err);
675
+ reportGraphqlQueryParseError(parseError);
676
+ // call the callback with error
677
+ onResponseDelegate({
678
+ data: undefined,
679
+ error: createNativeFetchErrorResponse(parseError.message),
680
+ });
681
+ return;
682
+ }
683
+ }
684
+ //unstable_graphql_imperative
685
+ if (imperativeAdapterIdentifier.includes('graphql')) {
686
+ try {
687
+ //we need to use the gql literal to convert into a document node
688
+ //in order to get through the gql imperative adapter
689
+ configObject.query = gql `
690
+ ${configObject.query}
691
+ `;
692
+ }
693
+ catch (err) {
694
+ const parseError = normalizeError(err);
695
+ reportGraphqlQueryParseError(parseError);
696
+ // call the callback with error
697
+ onResponseDelegate({
698
+ data: undefined,
699
+ error: createNativeFetchErrorResponse(parseError.message),
700
+ });
701
+ return;
702
+ }
703
+ }
704
+ try {
705
+ imperativeAdapter.invoke(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
706
+ }
707
+ catch (err) {
708
+ if (isGql) {
709
+ reportGraphqlQueryParseError(err);
710
+ }
711
+ onResponseDelegate(buildInvalidConfigError(err));
712
+ }
713
+ return;
714
+ }
715
+ const adapter = getDMLAdapterFromName(adapterId);
716
+ if (adapter === undefined) {
717
+ onResponseDelegate({
718
+ data: undefined,
719
+ error: createNativeFetchErrorResponse(`adapter ${adapterId} not recognized`),
720
+ });
721
+ return;
722
+ }
723
+ invokeDmlAdapter(adapter, configObject, onResponseDelegate, nativeAdapterRequestContext);
724
+ }
725
+ /**
726
+ * @deprecated Use invokeAdapter or subscribeToAdapter instead
727
+ *
728
+ * W-9173084 Will remove this
729
+ */
730
+ function executeAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
731
+ return subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext);
732
+ }
733
+ /**
734
+ * @deprecated Use invokeAdapter instead
735
+ *
736
+ * W-9173084 Will remove this
737
+ */
738
+ function executeMutatingAdapter(adapterId, config, onResult, nativeAdapterRequestContext) {
739
+ invokeAdapter(adapterId, config, onResult, nativeAdapterRequestContext);
740
+ }
741
+
742
+ /* istanbul ignore file */
743
+ // TODO [W-9523236]: add test coverage for this file and remove above comment
744
+ // A allowlist of methods that we allow to be proxied from another LDS instance
745
+ const allowList = ['enqueue', 'getQueueActions'];
746
+ /**
747
+ * Implements the DraftQueue interface from nimbus-plugin-lds by passing requests
748
+ * to the instance of the lds-drafts' DraftQueue implementation
749
+ */
750
+ const nimbusDraftQueue = {
751
+ callProxyMethod(methodName, serializedArgsArray, resultCallback,
752
+ // NOTE: the other side of the proxy is expecting an error message string
753
+ // (not a JSON serialized Error object)
754
+ errorCallback) {
755
+ const method = draftQueue[methodName];
756
+ if (method === undefined) {
757
+ return errorCallback('Method does not exist on the draft queue');
758
+ }
759
+ if (allowList.includes(methodName) === false) {
760
+ return errorCallback(`Method ${methodName} is not available for proxy invocation`);
761
+ }
762
+ const parsedArgs = parse(serializedArgsArray);
763
+ // TODO [W-9933226]: we should validate the argument list based on which method is being called
764
+ if (isArray(parsedArgs) === false) {
765
+ return errorCallback('expected array argument list');
766
+ }
767
+ let methodResult = undefined;
768
+ try {
769
+ if (parsedArgs === undefined) {
770
+ methodResult = method.call(draftQueue);
771
+ }
772
+ else {
773
+ methodResult = method.call(draftQueue, ...parsedArgs);
774
+ }
775
+ }
776
+ catch (err) {
777
+ return errorCallback(normalizeError(err).message);
778
+ }
779
+ if (methodResult.then === undefined) {
780
+ return resultCallback(stringify(methodResult));
781
+ }
782
+ methodResult
783
+ .then((result) => {
784
+ resultCallback(stringify(result));
785
+ })
786
+ .catch((err) => {
787
+ errorCallback(normalizeError(err).message);
788
+ });
789
+ },
790
+ };
791
+
792
+ let luvio = undefined;
793
+ let internalLuvio = undefined;
794
+ let uiApiRecordTTL;
795
+ let metadataTTL;
796
+ withDefaultLuvio((_luvio) => {
797
+ luvio = _luvio;
798
+ internalLuvio = getRuntime().internalLuvio;
799
+ if (uiApiRecordTTL !== undefined) {
800
+ // Note: This should rarely get hit and the durable store implementation
801
+ // should have read write synchronization to protect against race conditions
802
+ // Here since we are on a synchronous path we cannot await the Promise
803
+ setUiApiRecordTTL(uiApiRecordTTL);
804
+ }
805
+ if (metadataTTL !== undefined) {
806
+ // Note: This should rarely get hit and the durable store implementation
807
+ // should have read write synchronization to protect against race conditions
808
+ // Here since we are on a synchronous path we cannot await the Promise
809
+ setMetadataTTL(metadataTTL);
810
+ }
811
+ });
812
+ function setUiApiRecordTTL(ttl) {
813
+ uiApiRecordTTL = ttl;
814
+ if (luvio === undefined) {
815
+ return Promise.resolve();
816
+ }
817
+ return luvio.storeSetTTLOverride(API_NAMESPACE, RECORD_REPRESENTATION_NAME, ttl).then(() => {
818
+ if (internalLuvio === undefined) {
819
+ return Promise.resolve();
820
+ }
821
+ internalLuvio.storeSetTTLOverride(API_NAMESPACE, RECORD_REPRESENTATION_NAME, ttl);
822
+ });
823
+ }
824
+ function setMetadataTTL(ttl) {
825
+ metadataTTL = ttl;
826
+ if (luvio === undefined) {
827
+ return Promise.resolve();
828
+ }
829
+ return luvio.storeSetDefaultTTLOverride(ttl).then(() => {
830
+ if (internalLuvio === undefined) {
831
+ return Promise.resolve();
832
+ }
833
+ internalLuvio.storeSetDefaultTTLOverride(ttl);
834
+ });
835
+ }
836
+
837
+ function createPrimingSession(config) {
838
+ const { createPrimingSession } = getRuntime();
839
+ const { primingEventHandler, concurrency, batchSize } = config;
840
+ const session = createPrimingSession({ concurrency, batchSize });
841
+ if (primingEventHandler) {
842
+ addEventHandler(session, primingEventHandler);
843
+ }
844
+ const registerEventHandler = (handler) => {
845
+ // bind creates a new function and we need to retain reference to that function
846
+ // in order to be able to remove it
847
+ const boundCallbacks = {
848
+ onError: handler.onError ? handler.onError.bind(handler) : undefined,
849
+ onPrimed: handler.onPrimed ? handler.onPrimed.bind(handler) : undefined,
850
+ };
851
+ addEventHandler(session, boundCallbacks);
852
+ return () => {
853
+ removeEventHandler(session, boundCallbacks);
854
+ };
855
+ };
856
+ return {
857
+ enqueue: session.enqueue.bind(session),
858
+ cancel: session.cancel.bind(session),
859
+ on: session.on.bind(session),
860
+ once: session.once.bind(session),
861
+ off: session.off.bind(session),
862
+ registerEventHandler,
863
+ };
864
+ }
865
+ function addEventHandler(session, handler) {
866
+ const { onError, onPrimed } = handler;
867
+ if (onError) {
868
+ session.on('error', onError);
869
+ }
870
+ if (onPrimed) {
871
+ session.on('primed', onPrimed);
872
+ }
873
+ }
874
+ function removeEventHandler(session, handler) {
875
+ const { onError, onPrimed } = handler;
876
+ if (onError) {
877
+ session.off('error', onError);
878
+ }
879
+ if (onPrimed) {
880
+ session.off('primed', onPrimed);
881
+ }
882
+ }
883
+
884
+ const ldsMobileInstrumentation = getInstrumentation(O11Y_NAMESPACE_LDS_MOBILE);
885
+ const MessagingDurableSegmentName = 'MESSAGING';
886
+ const DEFAULT_MAX_ENTRIES_PER_OPERATION = 500;
887
+ const EVICTION_IN_PROGESS_MESSAGE = `Cache eviction in progress. Can't start another until it is finished or canceled.`;
888
+ /**
889
+ * Only one eviction is allowed at a time. running status is return when evictCacheRecordsByIds or
890
+ * evictExpiredCacheEntries is called if there's already an eviction in progress.
891
+ */
892
+ var activeEvictionInProgress = false;
893
+ var cancelCurrentEviction = false;
894
+ /**
895
+ * Purging records specified by an array of record id from durable store
896
+ * @param recordIds record id array
897
+ * @onProgressUpdate call back to report evict progress
898
+ *
899
+ * @returns started or already running based whether there's an active eviction going on or not.
900
+ *
901
+ * The record will not be purged if the record has draft.
902
+ */
903
+ function evictCacheRecordsByIds(recordIds, onProgressUpdate) {
904
+ // Send error back if an eviction is going on.
905
+ if (activeEvictionInProgress) {
906
+ return {
907
+ status: 'Running',
908
+ message: EVICTION_IN_PROGESS_MESSAGE,
909
+ };
910
+ }
911
+ activeEvictionInProgress = true;
912
+ cancelCurrentEviction = false;
913
+ const o11yActivity = ldsMobileInstrumentation.startActivity('evictCacheRecordsByIds');
914
+ const stat = {
915
+ idCount: recordIds.length,
916
+ evictedCount: 0,
917
+ skippedCount: 0,
918
+ };
919
+ const evictAChunk = () => {
920
+ evictChunksOfRecord(recordIds).then((progress) => {
921
+ handleInstrumentation(o11yActivity, stat, progress);
922
+ onEvicted(progress);
923
+ });
924
+ };
925
+ const onEvicted = getOnEvictedCallback(o11yActivity, onProgressUpdate, evictAChunk, stat);
926
+ evictAChunk();
927
+ return { status: 'Started' };
928
+ }
929
+ /**
930
+ * Purging the db entries which passed expired time by specified days
931
+ * from durable store.
932
+ * @param expiredByDays
933
+ * @param onProgressUpdate
934
+ *
935
+ * @returns started or already running based whether there's an active eviction going on or not.
936
+ *
937
+ * Important: records with draft, objectInfo entries will not be purged even expired by the specified days.
938
+ */
939
+ function evictExpiredCacheEntries(expiredByDays, onProgressUpdate) {
940
+ // Send error back if an eviction is going on.
941
+ if (activeEvictionInProgress) {
942
+ return {
943
+ status: 'Running',
944
+ message: EVICTION_IN_PROGESS_MESSAGE,
945
+ };
946
+ }
947
+ activeEvictionInProgress = true;
948
+ cancelCurrentEviction = false;
949
+ const stat = {
950
+ expiredInDays: expiredByDays,
951
+ evictedCount: 0,
952
+ skippedCount: 0,
953
+ };
954
+ const o11yActivity = ldsMobileInstrumentation.startActivity('evictExpiredCacheEntries');
955
+ const overdueExpirationTimeStamp = Date.now() - expiredByDays * 24 * 3600 * 1000;
956
+ const evictAChunk = () => {
957
+ evictChunkOfOverdueEntries(overdueExpirationTimeStamp).then((progress) => {
958
+ handleInstrumentation(o11yActivity, stat, progress);
959
+ onEvicted(progress);
960
+ });
961
+ };
962
+ const onEvicted = getOnEvictedCallback(o11yActivity, onProgressUpdate, evictAChunk, stat);
963
+ evictAChunk();
964
+ return { status: 'Started' };
965
+ }
966
+ /**
967
+ * Signal to stop current eviction if there's an active eviction going on.
968
+ */
969
+ function stopEviction() {
970
+ if (activeEvictionInProgress) {
971
+ cancelCurrentEviction = true;
972
+ }
973
+ }
974
+ /**
975
+ * Get a callback function when a chunk of records or entries are removed.
976
+ * @param onProgressUpdate
977
+ * @param evictAChunk
978
+ * @returns a callback to call when a chunk of records or entries are removed.
979
+ */
980
+ function getOnEvictedCallback(o11yActivity, onProgressUpdate, evictAChunk, stat) {
981
+ return (progress) => {
982
+ onProgressUpdate(progress);
983
+ const { status } = progress;
984
+ if (status === 'Succeeded' || status === 'Error') {
985
+ activeEvictionInProgress = false;
986
+ }
987
+ if (status === 'Evicted') {
988
+ if (cancelCurrentEviction) {
989
+ activeEvictionInProgress = false;
990
+ const canceledProgress = { status: 'Canceled' };
991
+ onProgressUpdate(canceledProgress);
992
+ handleInstrumentation(o11yActivity, stat, canceledProgress);
993
+ }
994
+ else {
995
+ evictAChunk();
996
+ }
997
+ }
998
+ };
999
+ }
1000
+ /**
1001
+ * pull a chunk of record id, evict status back in a promise.
1002
+ * @param ids the list of record ids.
1003
+ * @returns
1004
+ */
1005
+ function evictChunksOfRecord(ids) {
1006
+ const chunk = ids.splice(0, DEFAULT_MAX_ENTRIES_PER_OPERATION);
1007
+ if (chunk.length === 0) {
1008
+ return Promise.resolve({ status: 'Succeeded' });
1009
+ }
1010
+ return new Promise((resolve) => {
1011
+ // evict the chunk
1012
+ const { luvio, nimbusSqliteStore } = getRuntime();
1013
+ const paramTemplate = chunk.map((_) => '?').join(',');
1014
+ const params = chunk.map((recordId) => keyBuilderRecord(luvio, { recordId }));
1015
+ try {
1016
+ nimbusSqliteStore
1017
+ .query(`DELETE FROM lds_data
1018
+ WHERE key IN (${paramTemplate}) AND JSON_EXTRACT(data,'$.drafts') IS NULL
1019
+ RETURNING key
1020
+ `, params)
1021
+ .then((result) => {
1022
+ const evictedEntries = result.rows.map((row) => row[0]);
1023
+ const skippedEntries = params.filter((entryKey) => evictedEntries.indexOf(entryKey) === -1);
1024
+ // broadcast entries evicted if some entries are removed
1025
+ if (evictedEntries.length > 0) {
1026
+ nimbusSqliteStore.setEntries({ notifyStoreUpdateAvailable: { data: evictedEntries } }, MessagingDurableSegmentName);
1027
+ }
1028
+ resolve({
1029
+ status: 'Evicted',
1030
+ evictedEntries,
1031
+ skippedEntries,
1032
+ });
1033
+ })
1034
+ .catch((reason) => {
1035
+ resolve({
1036
+ status: 'Error',
1037
+ message: reason.toString(),
1038
+ });
1039
+ });
1040
+ }
1041
+ catch (reason) {
1042
+ resolve({
1043
+ status: 'Error',
1044
+ message: reason.toString(),
1045
+ });
1046
+ }
1047
+ });
1048
+ }
1049
+ /**
1050
+ * Evict chunk of overdue entries from db.
1051
+ * @param overdueExpirationTimestamp
1052
+ * @returns
1053
+ */
1054
+ function evictChunkOfOverdueEntries(overdueExpirationTimestamp) {
1055
+ return new Promise((resolve) => {
1056
+ // evict the chunk
1057
+ const { nimbusSqliteStore } = getRuntime();
1058
+ try {
1059
+ nimbusSqliteStore
1060
+ .query(`DELETE FROM lds_data
1061
+ WHERE key IN (
1062
+ SELECT key
1063
+ FROM lds_data
1064
+ WHERE key NOT LIKE 'UiApi::ObjectInfoRepresentation:%'
1065
+ AND
1066
+ (
1067
+ key NOT LIKE 'UiApi::RecordRepresentation:%' AND
1068
+ JSON_EXTRACT(metadata, '$.expirationTimestamp') < ${overdueExpirationTimestamp}
1069
+ OR
1070
+ key LIKE 'UiApi::RecordRepresentation:%' AND
1071
+ JSON_EXTRACT(data, '$.drafts') IS NULL AND
1072
+ JSON_EXTRACT(metadata, '$.expirationTimestamp') < ${overdueExpirationTimestamp}
1073
+ )
1074
+ LIMIT ${DEFAULT_MAX_ENTRIES_PER_OPERATION}
1075
+ )
1076
+ RETURNING key`, [])
1077
+ .then((result) => {
1078
+ const evictedEntries = result.rows.map((row) => row[0]);
1079
+ if (evictedEntries.length > 0) {
1080
+ // broadcast entries evicted
1081
+ nimbusSqliteStore.setEntries({ notifyStoreUpdateAvailable: { data: evictedEntries } }, MessagingDurableSegmentName);
1082
+ resolve({
1083
+ status: 'Evicted',
1084
+ evictedEntries,
1085
+ skippedEntries: [],
1086
+ });
1087
+ }
1088
+ else {
1089
+ resolve({ status: 'Succeeded' });
1090
+ }
1091
+ })
1092
+ .catch((reason) => {
1093
+ resolve({
1094
+ status: 'Error',
1095
+ message: reason.toString(),
1096
+ });
1097
+ });
1098
+ }
1099
+ catch (reason) {
1100
+ resolve({
1101
+ status: 'Error',
1102
+ message: reason.toString(),
1103
+ });
1104
+ }
1105
+ });
1106
+ }
1107
+ function handleInstrumentation(activity, stat, progress) {
1108
+ const status = progress.status;
1109
+ if (status === 'Evicted') {
1110
+ const evicted = progress;
1111
+ stat.evictedCount += evicted.evictedEntries.length;
1112
+ stat.skippedCount += evicted.skippedEntries.length;
1113
+ return;
1114
+ }
1115
+ const schema = 'idCount' in stat ? evictCacheRecordsByIdsSchema : evictExpiredEntriesSchema;
1116
+ const userData = {
1117
+ ...stat,
1118
+ isCanceled: status === 'Canceled',
1119
+ };
1120
+ if (status === 'Error') {
1121
+ activity.error(progress.message);
1122
+ }
1123
+ activity.stop(schema, userData);
1124
+ }
1125
+
1126
+ const LUVIO_ADAPTER_FAMILY = /^force\/ldsAdapters/;
1127
+ async function importLuvioAdapterModule(specifier) {
1128
+ if (!LUVIO_ADAPTER_FAMILY.test(specifier)) {
1129
+ throw `${specifier} is not an allowed luvio adapter module`;
1130
+ }
1131
+ let module;
1132
+ try {
1133
+ module = await import(specifier);
1134
+ }
1135
+ catch {
1136
+ throw `module not found for specifier ${specifier}`;
1137
+ }
1138
+ return new LuvioAdapterModule(module);
1139
+ }
1140
+ class LuvioAdapterModule {
1141
+ constructor(module) {
1142
+ const map = Object.assign({}, module);
1143
+ const { dmlAdapterMap, imperativeAdapterMap } = buildAdapterMaps(map);
1144
+ this.imperativeAdapterMap = imperativeAdapterMap;
1145
+ this.dmlAdapterMap = dmlAdapterMap;
1146
+ }
1147
+ async invokeAdapter(adapterName, config, nativeAdapterRequestContext) {
1148
+ const imperativeAdapterIdentifier = `${adapterName}_imperative`;
1149
+ const imperativeAdapter = this.imperativeAdapterMap[imperativeAdapterIdentifier];
1150
+ if (imperativeAdapter === undefined) {
1151
+ const dmlAdapter = this.dmlAdapterMap[adapterName];
1152
+ if (dmlAdapter === undefined) {
1153
+ return {
1154
+ data: undefined,
1155
+ error: createNativeFetchErrorResponse(`adapter ${adapterName} not recognized`),
1156
+ };
1157
+ }
1158
+ return this.invokeDmlAdapter(dmlAdapter, config, nativeAdapterRequestContext);
1159
+ }
1160
+ return new Promise((resolve) => {
1161
+ try {
1162
+ imperativeAdapter.invoke(config, buildAdapterRequestContext(nativeAdapterRequestContext), (response) => {
1163
+ resolve(buildNativeCallbackValue(response));
1164
+ });
1165
+ }
1166
+ catch (error) {
1167
+ resolve(buildInvalidConfigError(error));
1168
+ }
1169
+ });
1170
+ }
1171
+ subscribeAdapter(adapterName, config, nativeAdapterRequestContext, callback) {
1172
+ const imperativeAdapterIdentifier = `${adapterName}_imperative`;
1173
+ const imperativeAdapter = this.imperativeAdapterMap[imperativeAdapterIdentifier];
1174
+ if (imperativeAdapter === undefined) {
1175
+ const dmlAdapter = this.dmlAdapterMap[adapterName];
1176
+ if (dmlAdapter === undefined) {
1177
+ const nativeValue = buildNativeCallbackValue({
1178
+ data: undefined,
1179
+ error: createNativeFetchErrorResponse(`adapter ${adapterName} not recognized`),
1180
+ });
1181
+ callback(nativeValue);
1182
+ return () => { };
1183
+ }
1184
+ const nativeValue = buildNativeCallbackValue({
1185
+ data: undefined,
1186
+ error: createNativeFetchErrorResponse(`${adapterName} is not a GET wire adapter and cannot be subscribed.`),
1187
+ });
1188
+ callback(nativeValue);
1189
+ return () => { };
1190
+ }
1191
+ try {
1192
+ return imperativeAdapter.subscribe(config, buildAdapterRequestContext(nativeAdapterRequestContext), callback);
1193
+ }
1194
+ catch (error) {
1195
+ callback(buildInvalidConfigError(error));
1196
+ return () => { };
1197
+ }
1198
+ }
1199
+ invokeDmlAdapter(adapter, config, nativeAdapterRequestContext) {
1200
+ return new Promise((resolve) => {
1201
+ try {
1202
+ adapter(config, buildAdapterRequestContext(nativeAdapterRequestContext)).then((data) => {
1203
+ resolve({ data, error: undefined });
1204
+ }, (error) => {
1205
+ resolve({ data: undefined, error });
1206
+ });
1207
+ }
1208
+ catch (err) {
1209
+ resolve(buildInvalidConfigError(err));
1210
+ }
1211
+ });
1212
+ }
1213
+ }
1214
+
1215
+ const ONESTORE_ADAPTER_FAMILY = /^force\/ldsAdapters/;
1216
+ function buildOneStoreError(error) {
1217
+ let errorMessage;
1218
+ if (typeof error === 'string') {
1219
+ errorMessage = error;
1220
+ }
1221
+ else if (error && error.message) {
1222
+ errorMessage = error.message;
1223
+ }
1224
+ else if (error !== null && error !== undefined) {
1225
+ errorMessage = error.toString();
1226
+ }
1227
+ else {
1228
+ errorMessage = error;
1229
+ }
1230
+ return {
1231
+ data: undefined,
1232
+ error: errorMessage,
1233
+ };
1234
+ }
1235
+ function buildInvalidAdapterError(adapterOrCommandName) {
1236
+ return {
1237
+ data: undefined,
1238
+ error: `Invalid adapter or command: ${adapterOrCommandName}`,
1239
+ };
1240
+ }
1241
+ function buildNativeResponse(response) {
1242
+ if (response && response.error) {
1243
+ return buildOneStoreError(response.error);
1244
+ }
1245
+ return response;
1246
+ }
1247
+ async function importOneStoreAdapterModule(specifier) {
1248
+ if (!ONESTORE_ADAPTER_FAMILY.test(specifier)) {
1249
+ throw `${specifier} is not an allowed onestore adapter module`;
1250
+ }
1251
+ let module;
1252
+ try {
1253
+ module = await import(specifier);
1254
+ }
1255
+ catch {
1256
+ throw `module not found for specifier ${specifier}`;
1257
+ }
1258
+ return new OneStoreAdapterModule(module);
1259
+ }
1260
+ class OneStoreAdapterModule {
1261
+ constructor(module) {
1262
+ this.module = module;
1263
+ }
1264
+ async invoke(adapterOrCommandName, config) {
1265
+ const adapterOrCommand = this.module[adapterOrCommandName];
1266
+ if (adapterOrCommand === undefined) {
1267
+ return buildInvalidAdapterError(`Command ${adapterOrCommandName} not recognized`);
1268
+ }
1269
+ return new Promise((resolve) => {
1270
+ try {
1271
+ if (this.isCommandWireAdapter(adapterOrCommand)) {
1272
+ // WIRE COMMAND
1273
+ const adapter = new adapterOrCommand((result) => {
1274
+ resolve(buildNativeResponse(result));
1275
+ adapter.disconnect();
1276
+ }, undefined, { skipEmptyEmit: true });
1277
+ adapter.connect();
1278
+ adapter.update(config);
1279
+ }
1280
+ else if (this.hasInvoke(adapterOrCommand)) {
1281
+ // IMPERATIVE LEGACY INVOKER
1282
+ adapterOrCommand.invoke(config, null, (result) => {
1283
+ resolve(buildNativeResponse(result));
1284
+ });
1285
+ }
1286
+ else {
1287
+ // IMPERATIVE INVOKER
1288
+ adapterOrCommand(config)
1289
+ .then((response) => {
1290
+ resolve(buildNativeResponse(response));
1291
+ })
1292
+ .catch((error) => {
1293
+ resolve(buildOneStoreError(error));
1294
+ });
1295
+ }
1296
+ }
1297
+ catch (error) {
1298
+ resolve(buildInvalidAdapterError(adapterOrCommandName));
1299
+ }
1300
+ });
1301
+ }
1302
+ subscribe(adapterOrCommandName, config, callback) {
1303
+ const adapterOrCommand = this.module[adapterOrCommandName];
1304
+ if (adapterOrCommand === undefined) {
1305
+ callback(buildInvalidAdapterError(adapterOrCommandName));
1306
+ return Promise.resolve(undefined);
1307
+ }
1308
+ return new Promise((resolve) => {
1309
+ try {
1310
+ if (this.isCommandWireAdapter(adapterOrCommand)) {
1311
+ // WIRE COMMAND
1312
+ const adapter = new adapterOrCommand((result) => {
1313
+ callback(buildNativeResponse(result));
1314
+ }, undefined, { skipEmptyEmit: true });
1315
+ adapter.connect();
1316
+ adapter.update(config);
1317
+ resolve(() => adapter.disconnect());
1318
+ }
1319
+ else if (this.hasSubscribe(adapterOrCommand)) {
1320
+ // IMPERATIVE LEGACY INVOKER
1321
+ const unsubscribe = adapterOrCommand.subscribe(config, null, (result) => {
1322
+ callback(buildNativeResponse(result));
1323
+ });
1324
+ resolve(unsubscribe);
1325
+ }
1326
+ else {
1327
+ // IMPERATIVE INVOKER
1328
+ adapterOrCommand(config)
1329
+ .then((response) => {
1330
+ if (response.subscribe === undefined) {
1331
+ callback(buildNativeResponse(response));
1332
+ resolve(undefined);
1333
+ }
1334
+ else {
1335
+ const unsubscribe = response.subscribe((subscriptionResult) => {
1336
+ callback(buildNativeResponse(subscriptionResult));
1337
+ });
1338
+ resolve(unsubscribe);
1339
+ }
1340
+ })
1341
+ .catch((error) => {
1342
+ callback(buildOneStoreError(error));
1343
+ resolve(undefined);
1344
+ });
1345
+ }
1346
+ }
1347
+ catch (error) {
1348
+ callback(buildInvalidAdapterError(adapterOrCommandName));
1349
+ resolve(undefined);
1350
+ }
1351
+ });
1352
+ }
1353
+ isCommandWireAdapter(adapterOrCommand) {
1354
+ return Object.getPrototypeOf(adapterOrCommand).name === 'CommandWireAdapterConstructor';
1355
+ }
1356
+ hasInvoke(adapterOrCommand) {
1357
+ return typeof adapterOrCommand.invoke === 'function';
1358
+ }
1359
+ hasSubscribe(adapterOrCommand) {
1360
+ return typeof adapterOrCommand.subscribe === 'function';
1361
+ }
1362
+ }
1363
+
1364
+ if (process.env.NODE_ENV !== 'production') {
1365
+ // eslint-disable-next-line no-undef
1366
+ withDefaultLuvio((luvio) => {
1367
+ // eslint-disable-next-line no-undef
1368
+ const global = typeof globalThis === 'undefined' ? {} : globalThis;
1369
+ global.luvio = luvio;
1370
+ });
1371
+ }
1372
+
1373
+ export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, importLuvioAdapterModule, importOneStoreAdapterModule, invokeAdapter, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1374
+ // version: 0.1.0-dev1-54c03dd38c