@salesforce/lds-worker-api 1.125.0 → 1.127.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sfdc/es/draftQueueImplementation.d.ts +2 -2
- package/dist/sfdc/es/executeAdapter.d.ts +83 -83
- package/dist/sfdc/es/language.d.ts +13 -13
- package/dist/sfdc/es/ldsWorkerApi.js +692 -682
- package/dist/sfdc/es/lightningAdapterApi.d.ts +11 -11
- package/dist/sfdc/es/main.d.ts +8 -8
- package/dist/sfdc/es/nimbusDraftQueue.d.ts +6 -6
- package/dist/sfdc/es/primingApi.d.ts +23 -23
- package/dist/sfdc/es/responses.d.ts +44 -44
- package/dist/sfdc/es/standalone-stubs/instrumentation.d.ts +21 -21
- package/dist/sfdc/es/standalone-stubs/o11y.d.ts +18 -18
- package/dist/sfdc/es/standalone-stubs/unwrap.d.ts +1 -1
- package/dist/sfdc/es/standalone.d.ts +1 -1
- package/dist/sfdc/es/ttl.d.ts +2 -2
- package/dist/standalone/es/draftQueueImplementation.d.ts +2 -2
- package/dist/standalone/es/executeAdapter.d.ts +83 -83
- package/dist/standalone/es/language.d.ts +13 -13
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/currency.d.ts +2 -2
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateFormat.d.ts +2 -2
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateTimeFormat.d.ts +2 -2
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortTimeFormat.d.ts +2 -2
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/locale.d.ts +2 -2
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/timeZone.d.ts +2 -2
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/user/Id.d.ts +2 -2
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/lightning/i18nCldrOptions.d.ts +2 -2
- package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/lightning/i18nService.d.ts +10 -10
- package/dist/standalone/es/lds-worker-api/src/standalone-stubs/unwrap.d.ts +1 -1
- package/dist/standalone/es/lds-worker-api.js +730 -717
- package/dist/standalone/es/lightningAdapterApi.d.ts +11 -11
- package/dist/standalone/es/main.d.ts +8 -8
- package/dist/standalone/es/nimbusDraftQueue.d.ts +6 -6
- package/dist/standalone/es/primingApi.d.ts +23 -23
- package/dist/standalone/es/responses.d.ts +44 -44
- package/dist/standalone/es/standalone-stubs/instrumentation.d.ts +21 -21
- package/dist/standalone/es/standalone-stubs/o11y.d.ts +18 -18
- package/dist/standalone/es/standalone.d.ts +1 -1
- package/dist/standalone/es/ttl.d.ts +2 -2
- package/dist/standalone/umd/draftQueueImplementation.d.ts +2 -2
- package/dist/standalone/umd/executeAdapter.d.ts +83 -83
- package/dist/standalone/umd/language.d.ts +13 -13
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/currency.d.ts +2 -2
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateFormat.d.ts +2 -2
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateTimeFormat.d.ts +2 -2
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortTimeFormat.d.ts +2 -2
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/locale.d.ts +2 -2
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/timeZone.d.ts +2 -2
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/user/Id.d.ts +2 -2
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/lightning/i18nCldrOptions.d.ts +2 -2
- package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/lightning/i18nService.d.ts +10 -10
- package/dist/standalone/umd/lds-worker-api/src/standalone-stubs/unwrap.d.ts +1 -1
- package/dist/standalone/umd/lds-worker-api.js +730 -717
- package/dist/standalone/umd/lightningAdapterApi.d.ts +11 -11
- package/dist/standalone/umd/main.d.ts +8 -8
- package/dist/standalone/umd/nimbusDraftQueue.d.ts +6 -6
- package/dist/standalone/umd/primingApi.d.ts +23 -23
- package/dist/standalone/umd/responses.d.ts +44 -44
- package/dist/standalone/umd/standalone-stubs/instrumentation.d.ts +21 -21
- package/dist/standalone/umd/standalone-stubs/o11y.d.ts +18 -18
- package/dist/standalone/umd/standalone.d.ts +1 -1
- package/dist/standalone/umd/ttl.d.ts +2 -2
- package/package.json +1 -1
- package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/date-predicate.adapter-testcase.json +23 -0
- package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/date-predicate.server-response.network-mock.json +56 -0
- package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/date-predicate.adapter-snapshot.result.json +18 -0
|
@@ -38,643 +38,653 @@ export { registerReportObserver } from 'native/ldsRuntimeMobile';
|
|
|
38
38
|
import { HttpStatusCode } from 'force/luvioEngine';
|
|
39
39
|
import { withDefaultLuvio } from 'native/ldsEngineMobile';
|
|
40
40
|
|
|
41
|
-
const { create, keys } = Object;
|
|
42
|
-
const { stringify, parse } = JSON;
|
|
41
|
+
const { create, keys } = Object;
|
|
42
|
+
const { stringify, parse } = JSON;
|
|
43
43
|
const { isArray } = Array;
|
|
44
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);
|
|
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
91
|
}
|
|
92
92
|
|
|
93
93
|
const { draftManager, draftQueue } = getRuntime();
|
|
94
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));
|
|
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
160
|
}
|
|
161
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
|
|
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
281
|
configObject.query = gql `
|
|
282
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.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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), async (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
|
+
const managerState = await draftManager.getQueue();
|
|
426
|
+
const existingMetadata = (managerState.items.find((i) => i.id === draftId) || {}).metadata || {};
|
|
427
|
+
draftManager
|
|
428
|
+
.setMetadata(draftId, { ...existingMetadata, ...metadata })
|
|
429
|
+
.then(() => {
|
|
430
|
+
onResponse(responseValue);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
let response = responseValue;
|
|
435
|
+
response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
|
|
436
|
+
onResponse(response);
|
|
437
|
+
}
|
|
438
|
+
}, nativeAdapterRequestContext);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
/*
|
|
442
|
+
//TODO W-10284305: Remove this function in 238
|
|
443
|
+
This is a special case version of the invokeAdapterWithMetadata function
|
|
444
|
+
which should only be used for the deleteRecord wire adapter, since it does not
|
|
445
|
+
contain record data in the result and has to do special querying of the draft queue
|
|
446
|
+
*/
|
|
447
|
+
function invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponse, nativeAdapterRequestContext) {
|
|
448
|
+
const targetedRecordId = parse(config);
|
|
449
|
+
let priorDraftIds;
|
|
450
|
+
draftManager.getQueue().then((draftState) => {
|
|
451
|
+
priorDraftIds = draftState.items.map((item) => {
|
|
452
|
+
return item.id;
|
|
453
|
+
});
|
|
454
|
+
invokeDmlAdapter(adapter, parse(config), (responseValue) => {
|
|
455
|
+
if (responseValue.error === undefined &&
|
|
456
|
+
responseValue.errors === undefined &&
|
|
457
|
+
responseValue.data === undefined) {
|
|
458
|
+
draftManager.getQueue().then((newState) => {
|
|
459
|
+
const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
|
|
460
|
+
const newDrafts = newState.items;
|
|
461
|
+
const addedDrafts = newDrafts.filter((item) => {
|
|
462
|
+
const isNew = draftIdsToFilter.indexOf(item.id) < 0;
|
|
463
|
+
const targetIdMatches = item.targetId === targetedRecordId;
|
|
464
|
+
return isNew && targetIdMatches;
|
|
465
|
+
});
|
|
466
|
+
if (addedDrafts.length !== 1) {
|
|
467
|
+
let response = {
|
|
468
|
+
error: createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE),
|
|
469
|
+
};
|
|
470
|
+
onResponse(response);
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
draftManager.setMetadata(addedDrafts[0].id, metadata).then(() => {
|
|
474
|
+
onResponse(responseValue);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
let response = responseValue;
|
|
481
|
+
response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
|
|
482
|
+
onResponse(response);
|
|
483
|
+
}
|
|
484
|
+
}, nativeAdapterRequestContext);
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
/*
|
|
488
|
+
//TODO W-10284305: Remove this function in 238
|
|
489
|
+
This is a special case version of the invokeAdapterWithDraftToReplace function
|
|
490
|
+
which should only be used for the deleteRecord wire adapter, since it does not
|
|
491
|
+
contain record data in the result and has to do special querying of the draft queue
|
|
492
|
+
*/
|
|
493
|
+
function invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
|
|
494
|
+
const targetedRecordId = parse(config);
|
|
495
|
+
let priorDraftIds;
|
|
496
|
+
draftManager.getQueue().then((draftState) => {
|
|
497
|
+
priorDraftIds = draftState.items.map((item) => {
|
|
498
|
+
return item.id;
|
|
499
|
+
});
|
|
500
|
+
invokeDmlAdapter(adapter, parse(config), (responseValue) => {
|
|
501
|
+
if (responseValue.error === undefined &&
|
|
502
|
+
responseValue.errors === undefined &&
|
|
503
|
+
responseValue.data === undefined) {
|
|
504
|
+
draftManager.getQueue().then((newState) => {
|
|
505
|
+
const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
|
|
506
|
+
const newDrafts = newState.items;
|
|
507
|
+
const addedDrafts = newDrafts.filter((item) => {
|
|
508
|
+
const isNew = draftIdsToFilter.indexOf(item.id) < 0;
|
|
509
|
+
const targetIdMatches = item.targetId === targetedRecordId;
|
|
510
|
+
return isNew && targetIdMatches;
|
|
511
|
+
});
|
|
512
|
+
if (addedDrafts.length !== 1) {
|
|
513
|
+
let response = {
|
|
514
|
+
error: createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE),
|
|
515
|
+
};
|
|
516
|
+
onResponse(response);
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
draftManager
|
|
520
|
+
.replaceAction(draftIdToReplace, addedDrafts[0].id)
|
|
521
|
+
.then(() => {
|
|
522
|
+
onResponse(responseValue);
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
let response = responseValue;
|
|
529
|
+
response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
|
|
530
|
+
onResponse(response);
|
|
531
|
+
}
|
|
532
|
+
}, nativeAdapterRequestContext);
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
function draftIdsForResponseValue(response) {
|
|
536
|
+
if (response.data !== undefined &&
|
|
537
|
+
response.data.drafts !== undefined &&
|
|
538
|
+
response.data.drafts.draftActionIds !== undefined) {
|
|
539
|
+
return response.data.drafts.draftActionIds;
|
|
540
|
+
}
|
|
541
|
+
if (response.data !== undefined &&
|
|
542
|
+
response.data.contentVersion !== undefined &&
|
|
543
|
+
response.data.contentVersion.drafts !== undefined &&
|
|
544
|
+
response.data.contentVersion.drafts.draftActionIds !== undefined) {
|
|
545
|
+
return response.data.contentVersion.drafts.draftActionIds;
|
|
546
|
+
}
|
|
547
|
+
return undefined;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Executes the specified adapter with the given adapterId and config. Will call
|
|
551
|
+
* onResponse callback once with data or error.
|
|
552
|
+
*
|
|
553
|
+
* This function throws an error if the given adapterId cannot be found or if it
|
|
554
|
+
* fails to parse the given config string.
|
|
555
|
+
*/
|
|
556
|
+
function invokeAdapter(adapterId, config, onResponse, nativeAdapterRequestContext) {
|
|
557
|
+
const onResponseDelegate = (value) => {
|
|
558
|
+
onResponse(buildNativeCallbackValue(value));
|
|
559
|
+
};
|
|
560
|
+
const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
|
|
561
|
+
const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
|
|
562
|
+
const configObject = parse(config);
|
|
563
|
+
// currently all uiapi GET adapters have a corresponding imperative adapter
|
|
564
|
+
if (imperativeAdapter !== undefined) {
|
|
565
|
+
// Check if it's graphQl adapter
|
|
566
|
+
// Parse the query in that case
|
|
567
|
+
const isGql = isGqlAdapter(imperativeAdapterIdentifier);
|
|
568
|
+
if (isGql) {
|
|
569
|
+
try {
|
|
570
|
+
// gql config needs gql query string turned into AST object
|
|
571
|
+
configObject.query = parseAndVisit(configObject.query);
|
|
572
|
+
}
|
|
573
|
+
catch (err) {
|
|
574
|
+
const parseError = normalizeError(err);
|
|
575
|
+
reportGraphqlQueryParseError(parseError);
|
|
576
|
+
// call the callback with error
|
|
577
|
+
onResponseDelegate({
|
|
578
|
+
data: undefined,
|
|
579
|
+
error: createNativeFetchErrorResponse(parseError.message),
|
|
580
|
+
});
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
//unstable_graphql_imperative
|
|
585
|
+
if (imperativeAdapterIdentifier.includes('graphql')) {
|
|
586
|
+
try {
|
|
587
|
+
//we need to use the gql literal to convert into a document node
|
|
588
|
+
//in order to get through the gql imperative adapter
|
|
579
589
|
configObject.query = gql `
|
|
580
590
|
${configObject.query}
|
|
581
|
-
`;
|
|
582
|
-
}
|
|
583
|
-
catch (err) {
|
|
584
|
-
const parseError = normalizeError(err);
|
|
585
|
-
reportGraphqlQueryParseError(parseError);
|
|
586
|
-
// call the callback with error
|
|
587
|
-
onResponseDelegate({
|
|
588
|
-
data: undefined,
|
|
589
|
-
error: createNativeFetchErrorResponse(parseError.message),
|
|
590
|
-
});
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
}
|
|
594
|
-
try {
|
|
595
|
-
imperativeAdapter.invoke(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
|
|
596
|
-
}
|
|
597
|
-
catch (err) {
|
|
598
|
-
if (isGql) {
|
|
599
|
-
reportGraphqlQueryParseError(err);
|
|
600
|
-
}
|
|
601
|
-
onResponseDelegate(buildInvalidConfigError(err));
|
|
602
|
-
}
|
|
603
|
-
return;
|
|
604
|
-
}
|
|
605
|
-
const adapter = getDMLAdapterFromName(adapterId);
|
|
606
|
-
if (adapter === undefined) {
|
|
607
|
-
throw Error(`adapter ${adapterId} not recognized`);
|
|
608
|
-
}
|
|
609
|
-
invokeDmlAdapter(adapter, configObject, onResponseDelegate, nativeAdapterRequestContext);
|
|
610
|
-
}
|
|
611
|
-
/**
|
|
612
|
-
* @deprecated Use invokeAdapter or subscribeToAdapter instead
|
|
613
|
-
*
|
|
614
|
-
* W-9173084 Will remove this
|
|
615
|
-
*/
|
|
616
|
-
function executeAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
|
|
617
|
-
return subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext);
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* @deprecated Use invokeAdapter instead
|
|
621
|
-
*
|
|
622
|
-
* W-9173084 Will remove this
|
|
623
|
-
*/
|
|
624
|
-
function executeMutatingAdapter(adapterId, config, onResult, nativeAdapterRequestContext) {
|
|
625
|
-
invokeAdapter(adapterId, config, onResult, nativeAdapterRequestContext);
|
|
591
|
+
`;
|
|
592
|
+
}
|
|
593
|
+
catch (err) {
|
|
594
|
+
const parseError = normalizeError(err);
|
|
595
|
+
reportGraphqlQueryParseError(parseError);
|
|
596
|
+
// call the callback with error
|
|
597
|
+
onResponseDelegate({
|
|
598
|
+
data: undefined,
|
|
599
|
+
error: createNativeFetchErrorResponse(parseError.message),
|
|
600
|
+
});
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
try {
|
|
605
|
+
imperativeAdapter.invoke(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
|
|
606
|
+
}
|
|
607
|
+
catch (err) {
|
|
608
|
+
if (isGql) {
|
|
609
|
+
reportGraphqlQueryParseError(err);
|
|
610
|
+
}
|
|
611
|
+
onResponseDelegate(buildInvalidConfigError(err));
|
|
612
|
+
}
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
const adapter = getDMLAdapterFromName(adapterId);
|
|
616
|
+
if (adapter === undefined) {
|
|
617
|
+
throw Error(`adapter ${adapterId} not recognized`);
|
|
618
|
+
}
|
|
619
|
+
invokeDmlAdapter(adapter, configObject, onResponseDelegate, nativeAdapterRequestContext);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* @deprecated Use invokeAdapter or subscribeToAdapter instead
|
|
623
|
+
*
|
|
624
|
+
* W-9173084 Will remove this
|
|
625
|
+
*/
|
|
626
|
+
function executeAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
|
|
627
|
+
return subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext);
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* @deprecated Use invokeAdapter instead
|
|
631
|
+
*
|
|
632
|
+
* W-9173084 Will remove this
|
|
633
|
+
*/
|
|
634
|
+
function executeMutatingAdapter(adapterId, config, onResult, nativeAdapterRequestContext) {
|
|
635
|
+
invokeAdapter(adapterId, config, onResult, nativeAdapterRequestContext);
|
|
626
636
|
}
|
|
627
637
|
|
|
628
|
-
/* istanbul ignore file */
|
|
629
|
-
// A allowlist of methods that we allow to be proxied from another LDS instance
|
|
630
|
-
const allowList = ['enqueue', 'getQueueActions'];
|
|
631
|
-
/**
|
|
632
|
-
* Implements the DraftQueue interface from nimbus-plugin-lds by passing requests
|
|
633
|
-
* to the instance of the lds-drafts' DraftQueue implementation
|
|
634
|
-
*/
|
|
635
|
-
const nimbusDraftQueue = {
|
|
636
|
-
callProxyMethod(methodName, serializedArgsArray, resultCallback, errorCallback) {
|
|
637
|
-
const method = draftQueue[methodName];
|
|
638
|
-
if (method === undefined) {
|
|
639
|
-
return errorCallback(stringify({
|
|
640
|
-
message: 'Method does not exist on the draft queue',
|
|
641
|
-
}));
|
|
642
|
-
}
|
|
643
|
-
if (allowList.includes(methodName) === false) {
|
|
644
|
-
return errorCallback(stringify({
|
|
645
|
-
message: `Method ${methodName} is not available for proxy invocation`,
|
|
646
|
-
}));
|
|
647
|
-
}
|
|
648
|
-
const parsedArgs = parse(serializedArgsArray);
|
|
649
|
-
// TODO [W-9933226]: we should validate the argument list based on which method is being called
|
|
650
|
-
if (isArray(parsedArgs) === false) {
|
|
651
|
-
return errorCallback(stringify({
|
|
652
|
-
message: 'expected array argument list',
|
|
653
|
-
}));
|
|
654
|
-
}
|
|
655
|
-
let methodResult = undefined;
|
|
656
|
-
try {
|
|
657
|
-
if (parsedArgs === undefined) {
|
|
658
|
-
methodResult = method.call(draftQueue);
|
|
659
|
-
}
|
|
660
|
-
else {
|
|
661
|
-
methodResult = method.call(draftQueue, ...parsedArgs);
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
catch (err) {
|
|
665
|
-
return errorCallback(stringify(err));
|
|
666
|
-
}
|
|
667
|
-
if (methodResult.then === undefined) {
|
|
668
|
-
return resultCallback(stringify(methodResult));
|
|
669
|
-
}
|
|
670
|
-
methodResult
|
|
671
|
-
.then((result) => {
|
|
672
|
-
resultCallback(stringify(result));
|
|
673
|
-
})
|
|
674
|
-
.catch((err) => {
|
|
675
|
-
errorCallback(stringify(err));
|
|
676
|
-
});
|
|
677
|
-
},
|
|
638
|
+
/* istanbul ignore file */
|
|
639
|
+
// A allowlist of methods that we allow to be proxied from another LDS instance
|
|
640
|
+
const allowList = ['enqueue', 'getQueueActions'];
|
|
641
|
+
/**
|
|
642
|
+
* Implements the DraftQueue interface from nimbus-plugin-lds by passing requests
|
|
643
|
+
* to the instance of the lds-drafts' DraftQueue implementation
|
|
644
|
+
*/
|
|
645
|
+
const nimbusDraftQueue = {
|
|
646
|
+
callProxyMethod(methodName, serializedArgsArray, resultCallback, errorCallback) {
|
|
647
|
+
const method = draftQueue[methodName];
|
|
648
|
+
if (method === undefined) {
|
|
649
|
+
return errorCallback(stringify({
|
|
650
|
+
message: 'Method does not exist on the draft queue',
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
if (allowList.includes(methodName) === false) {
|
|
654
|
+
return errorCallback(stringify({
|
|
655
|
+
message: `Method ${methodName} is not available for proxy invocation`,
|
|
656
|
+
}));
|
|
657
|
+
}
|
|
658
|
+
const parsedArgs = parse(serializedArgsArray);
|
|
659
|
+
// TODO [W-9933226]: we should validate the argument list based on which method is being called
|
|
660
|
+
if (isArray(parsedArgs) === false) {
|
|
661
|
+
return errorCallback(stringify({
|
|
662
|
+
message: 'expected array argument list',
|
|
663
|
+
}));
|
|
664
|
+
}
|
|
665
|
+
let methodResult = undefined;
|
|
666
|
+
try {
|
|
667
|
+
if (parsedArgs === undefined) {
|
|
668
|
+
methodResult = method.call(draftQueue);
|
|
669
|
+
}
|
|
670
|
+
else {
|
|
671
|
+
methodResult = method.call(draftQueue, ...parsedArgs);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
catch (err) {
|
|
675
|
+
return errorCallback(stringify(err));
|
|
676
|
+
}
|
|
677
|
+
if (methodResult.then === undefined) {
|
|
678
|
+
return resultCallback(stringify(methodResult));
|
|
679
|
+
}
|
|
680
|
+
methodResult
|
|
681
|
+
.then((result) => {
|
|
682
|
+
resultCallback(stringify(result));
|
|
683
|
+
})
|
|
684
|
+
.catch((err) => {
|
|
685
|
+
errorCallback(stringify(err));
|
|
686
|
+
});
|
|
687
|
+
},
|
|
678
688
|
};
|
|
679
689
|
|
|
680
690
|
/**
|
|
@@ -686,69 +696,69 @@ const nimbusDraftQueue = {
|
|
|
686
696
|
const API_NAMESPACE = 'UiApi';
|
|
687
697
|
const RECORD_REPRESENTATION_NAME = 'RecordRepresentation';
|
|
688
698
|
|
|
689
|
-
let luvio = undefined;
|
|
690
|
-
let uiApiRecordTTL;
|
|
691
|
-
let metadataTTL;
|
|
692
|
-
withDefaultLuvio((_luvio) => {
|
|
693
|
-
luvio = _luvio;
|
|
694
|
-
if (uiApiRecordTTL !== undefined) {
|
|
695
|
-
// Note: This should rarely get hit and the durable store implementation
|
|
696
|
-
// should have read write synchronization to protect against race conditions
|
|
697
|
-
// Here since we are on a synchronous path we cannot await the Promise
|
|
698
|
-
setUiApiRecordTTL(uiApiRecordTTL);
|
|
699
|
-
}
|
|
700
|
-
if (metadataTTL !== undefined) {
|
|
701
|
-
// Note: This should rarely get hit and the durable store implementation
|
|
702
|
-
// should have read write synchronization to protect against race conditions
|
|
703
|
-
// Here since we are on a synchronous path we cannot await the Promise
|
|
704
|
-
setMetadataTTL(metadataTTL);
|
|
705
|
-
}
|
|
706
|
-
});
|
|
707
|
-
function setUiApiRecordTTL(ttl) {
|
|
708
|
-
uiApiRecordTTL = ttl;
|
|
709
|
-
if (luvio === undefined) {
|
|
710
|
-
return Promise.resolve();
|
|
711
|
-
}
|
|
712
|
-
return luvio.storeSetTTLOverride(API_NAMESPACE, RECORD_REPRESENTATION_NAME, ttl);
|
|
713
|
-
}
|
|
714
|
-
function setMetadataTTL(ttl) {
|
|
715
|
-
metadataTTL = ttl;
|
|
716
|
-
if (luvio === undefined) {
|
|
717
|
-
return Promise.resolve();
|
|
718
|
-
}
|
|
719
|
-
return luvio.storeSetDefaultTTLOverride(ttl);
|
|
699
|
+
let luvio = undefined;
|
|
700
|
+
let uiApiRecordTTL;
|
|
701
|
+
let metadataTTL;
|
|
702
|
+
withDefaultLuvio((_luvio) => {
|
|
703
|
+
luvio = _luvio;
|
|
704
|
+
if (uiApiRecordTTL !== undefined) {
|
|
705
|
+
// Note: This should rarely get hit and the durable store implementation
|
|
706
|
+
// should have read write synchronization to protect against race conditions
|
|
707
|
+
// Here since we are on a synchronous path we cannot await the Promise
|
|
708
|
+
setUiApiRecordTTL(uiApiRecordTTL);
|
|
709
|
+
}
|
|
710
|
+
if (metadataTTL !== undefined) {
|
|
711
|
+
// Note: This should rarely get hit and the durable store implementation
|
|
712
|
+
// should have read write synchronization to protect against race conditions
|
|
713
|
+
// Here since we are on a synchronous path we cannot await the Promise
|
|
714
|
+
setMetadataTTL(metadataTTL);
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
function setUiApiRecordTTL(ttl) {
|
|
718
|
+
uiApiRecordTTL = ttl;
|
|
719
|
+
if (luvio === undefined) {
|
|
720
|
+
return Promise.resolve();
|
|
721
|
+
}
|
|
722
|
+
return luvio.storeSetTTLOverride(API_NAMESPACE, RECORD_REPRESENTATION_NAME, ttl);
|
|
723
|
+
}
|
|
724
|
+
function setMetadataTTL(ttl) {
|
|
725
|
+
metadataTTL = ttl;
|
|
726
|
+
if (luvio === undefined) {
|
|
727
|
+
return Promise.resolve();
|
|
728
|
+
}
|
|
729
|
+
return luvio.storeSetDefaultTTLOverride(ttl);
|
|
720
730
|
}
|
|
721
731
|
|
|
722
|
-
function createPrimingSession(config) {
|
|
723
|
-
const { createPrimingSession } = getRuntime();
|
|
724
|
-
const { primingEventHandler, concurrency, batchSize } = config;
|
|
725
|
-
const session = createPrimingSession({ concurrency, batchSize });
|
|
726
|
-
if (primingEventHandler) {
|
|
727
|
-
const { onError, onPrimed } = primingEventHandler;
|
|
728
|
-
if (onError) {
|
|
729
|
-
session.on('error', onError.bind(primingEventHandler));
|
|
730
|
-
}
|
|
731
|
-
if (onPrimed) {
|
|
732
|
-
session.on('primed', onPrimed.bind(primingEventHandler));
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
return {
|
|
736
|
-
enqueue: session.enqueue.bind(session),
|
|
737
|
-
cancel: session.cancel.bind(session),
|
|
738
|
-
on: session.on.bind(session),
|
|
739
|
-
once: session.once.bind(session),
|
|
740
|
-
off: session.off.bind(session),
|
|
741
|
-
};
|
|
732
|
+
function createPrimingSession(config) {
|
|
733
|
+
const { createPrimingSession } = getRuntime();
|
|
734
|
+
const { primingEventHandler, concurrency, batchSize } = config;
|
|
735
|
+
const session = createPrimingSession({ concurrency, batchSize });
|
|
736
|
+
if (primingEventHandler) {
|
|
737
|
+
const { onError, onPrimed } = primingEventHandler;
|
|
738
|
+
if (onError) {
|
|
739
|
+
session.on('error', onError.bind(primingEventHandler));
|
|
740
|
+
}
|
|
741
|
+
if (onPrimed) {
|
|
742
|
+
session.on('primed', onPrimed.bind(primingEventHandler));
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
enqueue: session.enqueue.bind(session),
|
|
747
|
+
cancel: session.cancel.bind(session),
|
|
748
|
+
on: session.on.bind(session),
|
|
749
|
+
once: session.once.bind(session),
|
|
750
|
+
off: session.off.bind(session),
|
|
751
|
+
};
|
|
742
752
|
}
|
|
743
753
|
|
|
744
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
745
|
-
// eslint-disable-next-line no-undef
|
|
746
|
-
withDefaultLuvio((luvio) => {
|
|
747
|
-
// eslint-disable-next-line no-undef
|
|
748
|
-
const global = typeof globalThis === 'undefined' ? {} : globalThis;
|
|
749
|
-
global.luvio = luvio;
|
|
750
|
-
});
|
|
754
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
755
|
+
// eslint-disable-next-line no-undef
|
|
756
|
+
withDefaultLuvio((luvio) => {
|
|
757
|
+
// eslint-disable-next-line no-undef
|
|
758
|
+
const global = typeof globalThis === 'undefined' ? {} : globalThis;
|
|
759
|
+
global.luvio = luvio;
|
|
760
|
+
});
|
|
751
761
|
}
|
|
752
762
|
|
|
753
763
|
export { createPrimingSession, draftManager, draftQueue, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, subscribeToAdapter };
|
|
754
|
-
// version: 1.
|
|
764
|
+
// version: 1.127.0-48f9732df
|