@salesforce/lds-worker-api 1.125.0 → 1.126.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/sfdc/es/draftQueueImplementation.d.ts +2 -2
  2. package/dist/sfdc/es/executeAdapter.d.ts +83 -83
  3. package/dist/sfdc/es/language.d.ts +13 -13
  4. package/dist/sfdc/es/ldsWorkerApi.js +692 -682
  5. package/dist/sfdc/es/lightningAdapterApi.d.ts +11 -11
  6. package/dist/sfdc/es/main.d.ts +8 -8
  7. package/dist/sfdc/es/nimbusDraftQueue.d.ts +6 -6
  8. package/dist/sfdc/es/primingApi.d.ts +23 -23
  9. package/dist/sfdc/es/responses.d.ts +44 -44
  10. package/dist/sfdc/es/standalone-stubs/instrumentation.d.ts +21 -21
  11. package/dist/sfdc/es/standalone-stubs/o11y.d.ts +18 -18
  12. package/dist/sfdc/es/standalone-stubs/unwrap.d.ts +1 -1
  13. package/dist/sfdc/es/standalone.d.ts +1 -1
  14. package/dist/sfdc/es/ttl.d.ts +2 -2
  15. package/dist/standalone/es/draftQueueImplementation.d.ts +2 -2
  16. package/dist/standalone/es/executeAdapter.d.ts +83 -83
  17. package/dist/standalone/es/language.d.ts +13 -13
  18. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/currency.d.ts +2 -2
  19. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateFormat.d.ts +2 -2
  20. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateTimeFormat.d.ts +2 -2
  21. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortTimeFormat.d.ts +2 -2
  22. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/locale.d.ts +2 -2
  23. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/timeZone.d.ts +2 -2
  24. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/@salesforce/user/Id.d.ts +2 -2
  25. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/lightning/i18nCldrOptions.d.ts +2 -2
  26. package/dist/standalone/es/lds-runtime-mobile/src/__mocks__/lightning/i18nService.d.ts +10 -10
  27. package/dist/standalone/es/lds-worker-api/src/standalone-stubs/unwrap.d.ts +1 -1
  28. package/dist/standalone/es/lds-worker-api.js +730 -717
  29. package/dist/standalone/es/lightningAdapterApi.d.ts +11 -11
  30. package/dist/standalone/es/main.d.ts +8 -8
  31. package/dist/standalone/es/nimbusDraftQueue.d.ts +6 -6
  32. package/dist/standalone/es/primingApi.d.ts +23 -23
  33. package/dist/standalone/es/responses.d.ts +44 -44
  34. package/dist/standalone/es/standalone-stubs/instrumentation.d.ts +21 -21
  35. package/dist/standalone/es/standalone-stubs/o11y.d.ts +18 -18
  36. package/dist/standalone/es/standalone.d.ts +1 -1
  37. package/dist/standalone/es/ttl.d.ts +2 -2
  38. package/dist/standalone/umd/draftQueueImplementation.d.ts +2 -2
  39. package/dist/standalone/umd/executeAdapter.d.ts +83 -83
  40. package/dist/standalone/umd/language.d.ts +13 -13
  41. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/currency.d.ts +2 -2
  42. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateFormat.d.ts +2 -2
  43. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortDateTimeFormat.d.ts +2 -2
  44. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/dateTime.shortTimeFormat.d.ts +2 -2
  45. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/locale.d.ts +2 -2
  46. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/i18n/timeZone.d.ts +2 -2
  47. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/@salesforce/user/Id.d.ts +2 -2
  48. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/lightning/i18nCldrOptions.d.ts +2 -2
  49. package/dist/standalone/umd/lds-runtime-mobile/src/__mocks__/lightning/i18nService.d.ts +10 -10
  50. package/dist/standalone/umd/lds-worker-api/src/standalone-stubs/unwrap.d.ts +1 -1
  51. package/dist/standalone/umd/lds-worker-api.js +730 -717
  52. package/dist/standalone/umd/lightningAdapterApi.d.ts +11 -11
  53. package/dist/standalone/umd/main.d.ts +8 -8
  54. package/dist/standalone/umd/nimbusDraftQueue.d.ts +6 -6
  55. package/dist/standalone/umd/primingApi.d.ts +23 -23
  56. package/dist/standalone/umd/responses.d.ts +44 -44
  57. package/dist/standalone/umd/standalone-stubs/instrumentation.d.ts +21 -21
  58. package/dist/standalone/umd/standalone-stubs/o11y.d.ts +18 -18
  59. package/dist/standalone/umd/standalone.d.ts +1 -1
  60. package/dist/standalone/umd/ttl.d.ts +2 -2
  61. package/package.json +1 -1
  62. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/date-predicate.adapter-testcase.json +23 -0
  63. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/serverresponse/date-predicate.server-response.network-mock.json +56 -0
  64. package/src/__tests__/data-driven-tests/fixtures/adapter-testcases/graphQL/snapshotdata/date-predicate.adapter-snapshot.result.json +18 -0
@@ -3782,13 +3782,13 @@
3782
3782
  }
3783
3783
  callbacks.push(callback);
3784
3784
  }
3785
- // version: 1.125.0-242b72352
3785
+ // version: 1.126.0-86fa082d1
3786
3786
 
3787
- // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
3788
- function instrumentAdapter$1(createFunction, _metadata) {
3789
- return createFunction;
3790
- }
3791
- function setLdsNetworkAdapterInstrumentation(_networkAdapterRegistration) { }
3787
+ // TODO [TD-0081508]: once that TD is fulfilled we can probably change this file
3788
+ function instrumentAdapter$1(createFunction, _metadata) {
3789
+ return createFunction;
3790
+ }
3791
+ function setLdsNetworkAdapterInstrumentation(_networkAdapterRegistration) { }
3792
3792
  function instrumentLuvio(_context) { }
3793
3793
 
3794
3794
  /**
@@ -15206,15 +15206,15 @@
15206
15206
  updateReferenceMapWithKnownKey(ast, luvioDocumentNode);
15207
15207
  return luvioDocumentNode;
15208
15208
  }
15209
- // version: 1.125.0-242b72352
15209
+ // version: 1.126.0-86fa082d1
15210
15210
 
15211
- function unwrap(data) {
15212
- // The lwc-luvio bindings import a function from lwc called "unwrap".
15213
- // The problem is by bringing that version of unwrap in it also brings
15214
- // in a bunch of other LWC stuff that calls DOM apis. JSContext can't
15215
- // handle that so for now we just fake in our own version of unwrap
15216
- // that does nothing but returns the same data.
15217
- return data;
15211
+ function unwrap(data) {
15212
+ // The lwc-luvio bindings import a function from lwc called "unwrap".
15213
+ // The problem is by bringing that version of unwrap in it also brings
15214
+ // in a bunch of other LWC stuff that calls DOM apis. JSContext can't
15215
+ // handle that so for now we just fake in our own version of unwrap
15216
+ // that does nothing but returns the same data.
15217
+ return data;
15218
15218
  }
15219
15219
 
15220
15220
  /**
@@ -16119,7 +16119,7 @@
16119
16119
  const { apiFamily, name } = metadata;
16120
16120
  return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
16121
16121
  }
16122
- // version: 1.125.0-242b72352
16122
+ // version: 1.126.0-86fa082d1
16123
16123
 
16124
16124
  /**
16125
16125
  * Copyright (c) 2022, Salesforce, Inc.,
@@ -44353,30 +44353,30 @@
44353
44353
  dropFunction: instrumentation$2.notifyRecordUpdateAvailableDropped,
44354
44354
  });
44355
44355
  });
44356
- // version: 1.125.0-445942bb7
44356
+ // version: 1.126.0-a3465b50e
44357
44357
 
44358
44358
  var caseSensitiveUserId = '005B0000000GR4OIAW';
44359
44359
 
44360
- function requestIdleDetectedCallback(_callback) { }
44361
- function declareNotifierTaskSingle(_name) {
44362
- return {
44363
- isBusy: false,
44364
- done: function () { },
44365
- };
44366
- }
44367
- function declareNotifierTaskMulti(_name, _existingBusyCount) {
44368
- return {
44369
- isBusy: false,
44370
- add: function () { },
44371
- done: function () { },
44372
- };
44373
- }
44374
- function declarePollableTaskMulti(_name, _isBusyChecker) { }
44375
- const idleDetector = {
44376
- requestIdleDetectedCallback,
44377
- declareNotifierTaskSingle,
44378
- declareNotifierTaskMulti,
44379
- declarePollableTaskMulti,
44360
+ function requestIdleDetectedCallback(_callback) { }
44361
+ function declareNotifierTaskSingle(_name) {
44362
+ return {
44363
+ isBusy: false,
44364
+ done: function () { },
44365
+ };
44366
+ }
44367
+ function declareNotifierTaskMulti(_name, _existingBusyCount) {
44368
+ return {
44369
+ isBusy: false,
44370
+ add: function () { },
44371
+ done: function () { },
44372
+ };
44373
+ }
44374
+ function declarePollableTaskMulti(_name, _isBusyChecker) { }
44375
+ const idleDetector = {
44376
+ requestIdleDetectedCallback,
44377
+ declareNotifierTaskSingle,
44378
+ declareNotifierTaskMulti,
44379
+ declarePollableTaskMulti,
44380
44380
  };
44381
44381
 
44382
44382
  var LOCALE = 'en-US';
@@ -44391,29 +44391,29 @@
44391
44391
 
44392
44392
  var shortDateTimeFormat = 'M/d/yyyy, h:mm a';
44393
44393
 
44394
- function getNumberFormat() {
44395
- return {
44396
- format: () => 'formatted',
44397
- };
44398
- }
44399
- function getDateTimeFormat() {
44400
- return {
44401
- format: (date) => {
44402
- if (isNaN(date)) {
44403
- throw RangeError('invalid date');
44404
- }
44405
- return 'formatted';
44406
- },
44407
- };
44408
- }
44409
- function getDateTimeISO8601Parser() {
44410
- return {
44411
- parse: (input) => (input.indexOf(':') > 0 ? new Date() : Date.parse(input)),
44412
- };
44394
+ function getNumberFormat() {
44395
+ return {
44396
+ format: () => 'formatted',
44397
+ };
44398
+ }
44399
+ function getDateTimeFormat() {
44400
+ return {
44401
+ format: (date) => {
44402
+ if (isNaN(date)) {
44403
+ throw RangeError('invalid date');
44404
+ }
44405
+ return 'formatted';
44406
+ },
44407
+ };
44408
+ }
44409
+ function getDateTimeISO8601Parser() {
44410
+ return {
44411
+ parse: (input) => (input.indexOf(':') > 0 ? new Date() : Date.parse(input)),
44412
+ };
44413
44413
  }
44414
44414
 
44415
- function formattingOptions(pattern) {
44416
- return pattern;
44415
+ function formattingOptions(pattern) {
44416
+ return pattern;
44417
44417
  }
44418
44418
 
44419
44419
  /**
@@ -50710,7 +50710,7 @@
50710
50710
  function recordLoaderFactory(query) {
50711
50711
  async function batchRecordQuery(ids) {
50712
50712
  const varbinds = Array(ids.length).fill('?').join(',');
50713
- const { rows } = await query(`select data from lds_data where json_extract(data,'$.id') in (${varbinds})`, ids);
50713
+ const { rows } = await query(`select data from lds_data where key like 'UiApi::RecordRepresentation:%' and json_extract(data,'$.id') in (${varbinds})`, ids);
50714
50714
  return ids.map((id) => {
50715
50715
  let foundRow = null;
50716
50716
  rows.forEach((row) => {
@@ -51030,6 +51030,9 @@
51030
51030
  isCaseSensitive: false,
51031
51031
  };
51032
51032
  if (value !== undefined) {
51033
+ const dateFn = field.dataType === 'Date' ? 'date' : 'datetime';
51034
+ predicate.value = `${dateFn}(?)`;
51035
+ predicate.bindings = [value];
51033
51036
  return predicate;
51034
51037
  }
51035
51038
  else if (literal !== undefined) {
@@ -59861,10 +59864,10 @@
59861
59864
  id: '@salesforce/lds-network-adapter',
59862
59865
  instrument: instrument$1,
59863
59866
  });
59864
- // version: 1.125.0-242b72352
59867
+ // version: 1.126.0-86fa082d1
59865
59868
 
59866
- const { create: create$2, keys: keys$2 } = Object;
59867
- const { stringify: stringify$1, parse: parse$1 } = JSON;
59869
+ const { create: create$2, keys: keys$2 } = Object;
59870
+ const { stringify: stringify$1, parse: parse$1 } = JSON;
59868
59871
  const { isArray: isArray$1 } = Array;
59869
59872
 
59870
59873
  /**
@@ -74126,7 +74129,7 @@
74126
74129
  configuration: { ...configurationForGraphQLAdapters },
74127
74130
  instrument,
74128
74131
  });
74129
- // version: 1.125.0-445942bb7
74132
+ // version: 1.126.0-a3465b50e
74130
74133
 
74131
74134
  // On core the unstable adapters are re-exported with different names,
74132
74135
 
@@ -76194,7 +76197,7 @@
76194
76197
  return null;
76195
76198
  }
76196
76199
  const { query, variables, useUiApiAdapter } = validatedConfig;
76197
- if (useUiApiAdapter === undefined || useUiApiAdapter === true) {
76200
+ if (useUiApiAdapter === true) {
76198
76201
  // Forward to new adapters
76199
76202
  const resolvedQuery = astResolver(query);
76200
76203
  if (resolvedQuery === undefined) {
@@ -76255,7 +76258,7 @@
76255
76258
  unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
76256
76259
  graphQLImperative = ldsAdapter;
76257
76260
  });
76258
- // version: 1.125.0-445942bb7
76261
+ // version: 1.126.0-a3465b50e
76259
76262
 
76260
76263
  var gqlApi = /*#__PURE__*/Object.freeze({
76261
76264
  __proto__: null,
@@ -76264,676 +76267,686 @@
76264
76267
  get unstable_graphQL_imperative () { return unstable_graphQL_imperative; }
76265
76268
  });
76266
76269
 
76267
- const IMPERATIVE_ADAPTER_SUFFIX = '_imperative';
76268
- const UNSTABLE_ADAPTER_PREFIX = 'unstable_';
76269
- function extractWireAdapterName(adapterName) {
76270
- const parts = adapterName.split(UNSTABLE_ADAPTER_PREFIX);
76271
- if (parts.length > 1) {
76272
- return parts[1].substr(0, parts[1].indexOf(IMPERATIVE_ADAPTER_SUFFIX));
76273
- }
76274
- return adapterName.substr(0, adapterName.indexOf(IMPERATIVE_ADAPTER_SUFFIX));
76275
- }
76276
- let lazyDMLAdapterMap = undefined;
76277
- let lazyImperativeAdapterMap = undefined;
76278
- // this function builds the adapter maps lazily
76279
- function getAdapterMaps() {
76280
- if (lazyDMLAdapterMap === undefined || lazyImperativeAdapterMap === undefined) {
76281
- const map = Object.assign({
76282
- // We should eventually move all adapter names into this explicit list,
76283
- // this is our API contract to native callers and should be explicit
76284
- ['createContentDocumentAndVersion']: createContentDocumentAndVersion,
76285
- ['createContentVersion']: createContentVersion,
76286
- }, gqlApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi);
76287
- const imperativeAdapterNames = keys$2(map).filter((name) => name.endsWith(IMPERATIVE_ADAPTER_SUFFIX));
76288
- const imperativeMap = {};
76289
- for (const adapterName of imperativeAdapterNames) {
76290
- const adapter = map[adapterName];
76291
- imperativeMap[adapterName] = adapter;
76292
- delete map[adapterName];
76293
- // remove the corresponding wire adapter from the adapter map
76294
- const wireAdapterName = extractWireAdapterName(adapterName);
76295
- delete map[wireAdapterName];
76296
- }
76297
- lazyDMLAdapterMap = map;
76298
- lazyImperativeAdapterMap = imperativeMap;
76299
- }
76300
- return { dmlAdapterMap: lazyDMLAdapterMap, imperativeAdapterMap: lazyImperativeAdapterMap };
76301
- }
76302
- function getDMLAdapterFromName(name) {
76303
- const { dmlAdapterMap } = getAdapterMaps();
76304
- return dmlAdapterMap[name];
76305
- }
76306
- function getImperativeAdapterFromName(name) {
76307
- const { imperativeAdapterMap } = getAdapterMaps();
76308
- return imperativeAdapterMap[name];
76309
- }
76310
- function getImperativeAdapterNames() {
76311
- const { imperativeAdapterMap } = getAdapterMaps();
76312
- return keys$2(imperativeAdapterMap);
76270
+ const IMPERATIVE_ADAPTER_SUFFIX = '_imperative';
76271
+ const UNSTABLE_ADAPTER_PREFIX = 'unstable_';
76272
+ function extractWireAdapterName(adapterName) {
76273
+ const parts = adapterName.split(UNSTABLE_ADAPTER_PREFIX);
76274
+ if (parts.length > 1) {
76275
+ return parts[1].substr(0, parts[1].indexOf(IMPERATIVE_ADAPTER_SUFFIX));
76276
+ }
76277
+ return adapterName.substr(0, adapterName.indexOf(IMPERATIVE_ADAPTER_SUFFIX));
76278
+ }
76279
+ let lazyDMLAdapterMap = undefined;
76280
+ let lazyImperativeAdapterMap = undefined;
76281
+ // this function builds the adapter maps lazily
76282
+ function getAdapterMaps() {
76283
+ if (lazyDMLAdapterMap === undefined || lazyImperativeAdapterMap === undefined) {
76284
+ const map = Object.assign({
76285
+ // We should eventually move all adapter names into this explicit list,
76286
+ // this is our API contract to native callers and should be explicit
76287
+ ['createContentDocumentAndVersion']: createContentDocumentAndVersion,
76288
+ ['createContentVersion']: createContentVersion,
76289
+ }, gqlApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi, unstableLightningRelatedListApi);
76290
+ const imperativeAdapterNames = keys$2(map).filter((name) => name.endsWith(IMPERATIVE_ADAPTER_SUFFIX));
76291
+ const imperativeMap = {};
76292
+ for (const adapterName of imperativeAdapterNames) {
76293
+ const adapter = map[adapterName];
76294
+ imperativeMap[adapterName] = adapter;
76295
+ delete map[adapterName];
76296
+ // remove the corresponding wire adapter from the adapter map
76297
+ const wireAdapterName = extractWireAdapterName(adapterName);
76298
+ delete map[wireAdapterName];
76299
+ }
76300
+ lazyDMLAdapterMap = map;
76301
+ lazyImperativeAdapterMap = imperativeMap;
76302
+ }
76303
+ return { dmlAdapterMap: lazyDMLAdapterMap, imperativeAdapterMap: lazyImperativeAdapterMap };
76304
+ }
76305
+ function getDMLAdapterFromName(name) {
76306
+ const { dmlAdapterMap } = getAdapterMaps();
76307
+ return dmlAdapterMap[name];
76308
+ }
76309
+ function getImperativeAdapterFromName(name) {
76310
+ const { imperativeAdapterMap } = getAdapterMaps();
76311
+ return imperativeAdapterMap[name];
76312
+ }
76313
+ function getImperativeAdapterNames() {
76314
+ const { imperativeAdapterMap } = getAdapterMaps();
76315
+ return keys$2(imperativeAdapterMap);
76313
76316
  }
76314
76317
 
76315
76318
  const { draftManager, draftQueue } = getRuntime();
76316
76319
 
76317
- const NATIVE_ERROR_CODE = 'NATIVE_ERROR';
76318
- const NON_MUTATING_ADAPTER_MESSAGE = 'adapterId must be a mutating adapter';
76319
- const NO_DRAFT_CREATED_MESSAGE = 'the adapter did not generate a draft';
76320
- const DRAFT_DOESNT_EXIST_MESSAGE = 'the specified draft does not exist';
76321
- /**
76322
- * Error objects don't serialize well over the js-native wire, so our class turns
76323
- * an Error into an object that serializes real nice
76324
- */
76325
- class NativeNetworkAdapterErrorResponse {
76326
- constructor(error) {
76327
- this.errorType = 'networkAdapterError';
76328
- this.message = error.message;
76329
- this.name = error.name;
76330
- }
76331
- }
76332
- class NativeFetchResponse {
76333
- constructor(status, body) {
76334
- this.headers = {};
76335
- this.status = status;
76336
- this.body = body;
76337
- }
76338
- get statusText() {
76339
- const { status } = this;
76340
- switch (status) {
76341
- case HttpStatusCode$1.Ok:
76342
- return 'OK';
76343
- case HttpStatusCode$1.Created:
76344
- return 'Created';
76345
- case HttpStatusCode$1.NoContent:
76346
- return 'No Content';
76347
- case HttpStatusCode$1.BadRequest:
76348
- return 'Bad Request';
76349
- case HttpStatusCode$1.ServerError:
76350
- return 'Server Error';
76351
- default:
76352
- return `Unexpected HTTP Status Code: ${status}`;
76353
- }
76354
- }
76355
- get ok() {
76356
- return this.status >= 200 && this.status < 300;
76357
- }
76358
- }
76359
- class NativeFetchErrorResponse extends NativeFetchResponse {
76360
- constructor() {
76361
- super(...arguments);
76362
- this.errorType = 'fetchResponse';
76363
- }
76364
- }
76365
- function createNativeFetchErrorResponse(message) {
76366
- return new NativeFetchErrorResponse(HttpStatusCode$1.BadRequest, {
76367
- errorCode: NATIVE_ERROR_CODE,
76368
- message: message,
76369
- });
76370
- }
76371
- /**
76372
- * This function takes an unknown error and normalizes it to an Error object
76373
- */
76374
- function normalizeError(error) {
76375
- if (typeof error === 'object' && error instanceof Error) {
76376
- return error;
76377
- }
76378
- else if (typeof error === 'string') {
76379
- return new Error(error);
76380
- }
76381
- return new Error(stringify$1(error));
76320
+ const NATIVE_ERROR_CODE = 'NATIVE_ERROR';
76321
+ const NON_MUTATING_ADAPTER_MESSAGE = 'adapterId must be a mutating adapter';
76322
+ const NO_DRAFT_CREATED_MESSAGE = 'the adapter did not generate a draft';
76323
+ const DRAFT_DOESNT_EXIST_MESSAGE = 'the specified draft does not exist';
76324
+ /**
76325
+ * Error objects don't serialize well over the js-native wire, so our class turns
76326
+ * an Error into an object that serializes real nice
76327
+ */
76328
+ class NativeNetworkAdapterErrorResponse {
76329
+ constructor(error) {
76330
+ this.errorType = 'networkAdapterError';
76331
+ this.message = error.message;
76332
+ this.name = error.name;
76333
+ }
76334
+ }
76335
+ class NativeFetchResponse {
76336
+ constructor(status, body) {
76337
+ this.headers = {};
76338
+ this.status = status;
76339
+ this.body = body;
76340
+ }
76341
+ get statusText() {
76342
+ const { status } = this;
76343
+ switch (status) {
76344
+ case HttpStatusCode$1.Ok:
76345
+ return 'OK';
76346
+ case HttpStatusCode$1.Created:
76347
+ return 'Created';
76348
+ case HttpStatusCode$1.NoContent:
76349
+ return 'No Content';
76350
+ case HttpStatusCode$1.BadRequest:
76351
+ return 'Bad Request';
76352
+ case HttpStatusCode$1.ServerError:
76353
+ return 'Server Error';
76354
+ default:
76355
+ return `Unexpected HTTP Status Code: ${status}`;
76356
+ }
76357
+ }
76358
+ get ok() {
76359
+ return this.status >= 200 && this.status < 300;
76360
+ }
76361
+ }
76362
+ class NativeFetchErrorResponse extends NativeFetchResponse {
76363
+ constructor() {
76364
+ super(...arguments);
76365
+ this.errorType = 'fetchResponse';
76366
+ }
76367
+ }
76368
+ function createNativeFetchErrorResponse(message) {
76369
+ return new NativeFetchErrorResponse(HttpStatusCode$1.BadRequest, {
76370
+ errorCode: NATIVE_ERROR_CODE,
76371
+ message: message,
76372
+ });
76373
+ }
76374
+ /**
76375
+ * This function takes an unknown error and normalizes it to an Error object
76376
+ */
76377
+ function normalizeError(error) {
76378
+ if (typeof error === 'object' && error instanceof Error) {
76379
+ return error;
76380
+ }
76381
+ else if (typeof error === 'string') {
76382
+ return new Error(error);
76383
+ }
76384
+ return new Error(stringify$1(error));
76382
76385
  }
76383
76386
 
76384
- /**
76385
- * Coerces a cache policy passed in from native to a luvio cache policy
76386
- * @param nativeCachePolicy The cache policy passed in from native
76387
- * @returns A coerced luvio cache policy
76388
- */
76389
- function buildCachePolicy(nativeCachePolicy) {
76390
- if (nativeCachePolicy === undefined) {
76391
- return undefined;
76392
- }
76393
- // currently the types match exactly, if we ever decide to deviate then we should coerce here
76394
- return nativeCachePolicy;
76395
- }
76396
- /**
76397
- * Coerces a request context passed in from native to a luvio request context
76398
- * @param nativeRequestContext request context passed in from native
76399
- * @returns Coerced luvio request context
76400
- */
76401
- function buildAdapterRequestContext(nativeRequestContext) {
76402
- if (nativeRequestContext === undefined) {
76403
- return undefined;
76404
- }
76405
- const { cachePolicy, priority, observabilityContext, luvioEventObserver } = nativeRequestContext;
76406
- const requestContext = {
76407
- cachePolicy: buildCachePolicy(cachePolicy),
76408
- priority,
76409
- };
76410
- if (observabilityContext !== undefined) {
76411
- requestContext.requestCorrelator = {
76412
- observabilityContext,
76413
- };
76414
- }
76415
- if (luvioEventObserver !== undefined) {
76416
- requestContext.eventObservers = [luvioEventObserver];
76417
- }
76418
- return requestContext;
76419
- }
76420
- function buildInvalidConfigError(error) {
76421
- return {
76422
- data: undefined,
76423
- error: {
76424
- ok: false,
76425
- status: 400,
76426
- statusText: 'INVALID_CONFIG',
76427
- body: error,
76428
- headers: {},
76429
- errorType: 'fetchResponse',
76430
- },
76431
- };
76432
- }
76433
- function buildNativeCallbackValue(adapterCallbackValue) {
76434
- const { error } = adapterCallbackValue;
76435
- // Luvio NetworkAdapterError objects (which are just Error objects) must be
76436
- // turned into NativeNetworkAdapterErrorResponse because it serializes well
76437
- if (error !== undefined && error.errorType === 'networkAdapterError') {
76438
- return {
76439
- data: undefined,
76440
- error: new NativeNetworkAdapterErrorResponse(error),
76441
- };
76442
- }
76443
- // any other callback value does not need coercion, just retype
76444
- return adapterCallbackValue;
76445
- }
76446
- /**
76447
- *
76448
- * @param adapterId
76449
- * @returns imperative adapter key
76450
- */
76451
- function imperativeAdapterKeyBuilder(adapterId) {
76452
- if (adapterId.startsWith(UNSTABLE_ADAPTER_PREFIX)) {
76453
- return `${adapterId}${IMPERATIVE_ADAPTER_SUFFIX}`;
76454
- }
76455
- return `${UNSTABLE_ADAPTER_PREFIX}${adapterId}${IMPERATIVE_ADAPTER_SUFFIX}`;
76456
- }
76457
- /**
76458
- * Executes the adapter with the given adapterId and config. Will call onSnapshot
76459
- * callback with data or error. Returns an unsubscribe function that should
76460
- * be called to stop receiving updated snapshots.
76461
- *
76462
- * This function throws an error if the given adapterId cannot be found or is not
76463
- * a GET wire adapter. It will also throw if it fails to parse the config string.
76464
- */
76465
- function subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
76466
- const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
76467
- const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
76468
- const onResponseDelegate = (value) => {
76469
- onSnapshot(buildNativeCallbackValue(value));
76470
- };
76471
- if (imperativeAdapter === undefined) {
76472
- // This check is here for legacy purpose
76473
- // So the consumers still get the same errors
76474
- if (getDMLAdapterFromName(adapterId) === undefined) {
76475
- throw Error(`adapter ${adapterId} not recognized`);
76476
- }
76477
- throw Error(`${adapterId} is not a GET wire adapter.`);
76478
- }
76479
- const configObject = parse$1(config);
76480
- // Check if it's graphQl adapter
76481
- // Parse the query in that case
76482
- const isGql = isGqlAdapter(imperativeAdapterIdentifier);
76483
- if (isGql) {
76484
- try {
76485
- // gql config needs gql query string turned into AST object
76486
- configObject.query = parseAndVisit(configObject.query);
76487
- }
76488
- catch (err) {
76489
- const parseError = normalizeError(err);
76490
- reportGraphqlQueryParseError(parseError);
76491
- // call the callback with error
76492
- onResponseDelegate({
76493
- data: undefined,
76494
- error: createNativeFetchErrorResponse(parseError.message),
76495
- });
76496
- return () => { };
76497
- }
76498
- }
76499
- if (imperativeAdapterIdentifier.includes('graphql')) {
76500
- try {
76501
- //we need to use the gql literal to convert into a document node
76502
- //in order to get through the gql imperative adapter
76387
+ /**
76388
+ * Coerces a cache policy passed in from native to a luvio cache policy
76389
+ * @param nativeCachePolicy The cache policy passed in from native
76390
+ * @returns A coerced luvio cache policy
76391
+ */
76392
+ function buildCachePolicy(nativeCachePolicy) {
76393
+ if (nativeCachePolicy === undefined) {
76394
+ return undefined;
76395
+ }
76396
+ // currently the types match exactly, if we ever decide to deviate then we should coerce here
76397
+ return nativeCachePolicy;
76398
+ }
76399
+ /**
76400
+ * Coerces a request context passed in from native to a luvio request context
76401
+ * @param nativeRequestContext request context passed in from native
76402
+ * @returns Coerced luvio request context
76403
+ */
76404
+ function buildAdapterRequestContext(nativeRequestContext) {
76405
+ if (nativeRequestContext === undefined) {
76406
+ return undefined;
76407
+ }
76408
+ const { cachePolicy, priority, observabilityContext, luvioEventObserver } = nativeRequestContext;
76409
+ const requestContext = {
76410
+ cachePolicy: buildCachePolicy(cachePolicy),
76411
+ priority,
76412
+ };
76413
+ if (observabilityContext !== undefined) {
76414
+ requestContext.requestCorrelator = {
76415
+ observabilityContext,
76416
+ };
76417
+ }
76418
+ if (luvioEventObserver !== undefined) {
76419
+ requestContext.eventObservers = [luvioEventObserver];
76420
+ }
76421
+ return requestContext;
76422
+ }
76423
+ function buildInvalidConfigError(error) {
76424
+ return {
76425
+ data: undefined,
76426
+ error: {
76427
+ ok: false,
76428
+ status: 400,
76429
+ statusText: 'INVALID_CONFIG',
76430
+ body: error,
76431
+ headers: {},
76432
+ errorType: 'fetchResponse',
76433
+ },
76434
+ };
76435
+ }
76436
+ function buildNativeCallbackValue(adapterCallbackValue) {
76437
+ const { error } = adapterCallbackValue;
76438
+ // Luvio NetworkAdapterError objects (which are just Error objects) must be
76439
+ // turned into NativeNetworkAdapterErrorResponse because it serializes well
76440
+ if (error !== undefined && error.errorType === 'networkAdapterError') {
76441
+ return {
76442
+ data: undefined,
76443
+ error: new NativeNetworkAdapterErrorResponse(error),
76444
+ };
76445
+ }
76446
+ // any other callback value does not need coercion, just retype
76447
+ return adapterCallbackValue;
76448
+ }
76449
+ /**
76450
+ *
76451
+ * @param adapterId
76452
+ * @returns imperative adapter key
76453
+ */
76454
+ function imperativeAdapterKeyBuilder(adapterId) {
76455
+ if (adapterId.startsWith(UNSTABLE_ADAPTER_PREFIX)) {
76456
+ return `${adapterId}${IMPERATIVE_ADAPTER_SUFFIX}`;
76457
+ }
76458
+ return `${UNSTABLE_ADAPTER_PREFIX}${adapterId}${IMPERATIVE_ADAPTER_SUFFIX}`;
76459
+ }
76460
+ /**
76461
+ * Executes the adapter with the given adapterId and config. Will call onSnapshot
76462
+ * callback with data or error. Returns an unsubscribe function that should
76463
+ * be called to stop receiving updated snapshots.
76464
+ *
76465
+ * This function throws an error if the given adapterId cannot be found or is not
76466
+ * a GET wire adapter. It will also throw if it fails to parse the config string.
76467
+ */
76468
+ function subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
76469
+ const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
76470
+ const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
76471
+ const onResponseDelegate = (value) => {
76472
+ onSnapshot(buildNativeCallbackValue(value));
76473
+ };
76474
+ if (imperativeAdapter === undefined) {
76475
+ // This check is here for legacy purpose
76476
+ // So the consumers still get the same errors
76477
+ if (getDMLAdapterFromName(adapterId) === undefined) {
76478
+ throw Error(`adapter ${adapterId} not recognized`);
76479
+ }
76480
+ throw Error(`${adapterId} is not a GET wire adapter.`);
76481
+ }
76482
+ const configObject = parse$1(config);
76483
+ // Check if it's graphQl adapter
76484
+ // Parse the query in that case
76485
+ const isGql = isGqlAdapter(imperativeAdapterIdentifier);
76486
+ if (isGql) {
76487
+ try {
76488
+ // gql config needs gql query string turned into AST object
76489
+ configObject.query = parseAndVisit(configObject.query);
76490
+ }
76491
+ catch (err) {
76492
+ const parseError = normalizeError(err);
76493
+ reportGraphqlQueryParseError(parseError);
76494
+ // call the callback with error
76495
+ onResponseDelegate({
76496
+ data: undefined,
76497
+ error: createNativeFetchErrorResponse(parseError.message),
76498
+ });
76499
+ return () => { };
76500
+ }
76501
+ }
76502
+ if (imperativeAdapterIdentifier.includes('graphql')) {
76503
+ try {
76504
+ //we need to use the gql literal to convert into a document node
76505
+ //in order to get through the gql imperative adapter
76503
76506
  configObject.query = gql `
76504
76507
  ${configObject.query}
76505
- `;
76506
- }
76507
- catch (err) {
76508
- const parseError = normalizeError(err);
76509
- reportGraphqlQueryParseError(parseError);
76510
- // call the callback with error
76511
- onResponseDelegate({
76512
- data: undefined,
76513
- error: createNativeFetchErrorResponse(parseError.message),
76514
- });
76515
- return () => { };
76516
- }
76517
- }
76518
- try {
76519
- return imperativeAdapter.subscribe(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
76520
- }
76521
- catch (err) {
76522
- if (isGql) {
76523
- reportGraphqlQueryParseError(err);
76524
- }
76525
- onResponseDelegate(buildInvalidConfigError(err));
76526
- return () => { };
76527
- }
76528
- }
76529
- /**
76530
- * Checks if the given adapter id is a graphQL adapter
76531
- *
76532
- * @param imperativeAdapterIdentifier The adapter id to check
76533
- * @returns true if the adapter is graphQL, false otherwise
76534
- */
76535
- function isGqlAdapter(imperativeAdapterIdentifier) {
76536
- return keys$2(gqlApi).indexOf(imperativeAdapterIdentifier) > -1;
76537
- }
76538
- /**
76539
- * Executes a DML adapter and calls the onResponse callback upon receiving a response.
76540
- *
76541
- * @param adapter : DML Adapter
76542
- * @param configObject : parsed config
76543
- * @param onResponse : OnResponse
76544
- * @param nativeAdapterRequestContext: Specify cache policy, priority and observability parameters
76545
- */
76546
- function invokeDmlAdapter(adapter, configObject, onResponse, nativeAdapterRequestContext) {
76547
- try {
76548
- adapter(configObject, buildAdapterRequestContext(nativeAdapterRequestContext)).then((data) => {
76549
- onResponse({ data, error: undefined });
76550
- }, (error) => {
76551
- onResponse({ data: undefined, error });
76552
- });
76553
- }
76554
- catch (err) {
76555
- // For catching the synchronous error in adapter
76556
- onResponse(buildInvalidConfigError(err));
76557
- }
76558
- }
76559
- /**
76560
- * Executes the specified adapter with the given adapterId and config. Then
76561
- * it replaces the draft with the given id with the draft generated
76562
- * by the mutating adapter. Will call onResult callback once with data or error.
76563
- *
76564
- * This function throws an error if the given adapterId cannot be found, or if the
76565
- * adapterId is not a mutating adapter, or if a draft isn't created, or if it
76566
- * fails to parse the given config string.
76567
- */
76568
- function invokeAdapterWithDraftToReplace(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
76569
- draftManager.getQueue().then((draftInfo) => {
76570
- const draftIds = draftInfo.items.map((draft) => draft.id);
76571
- if (draftIds.includes(draftIdToReplace) === false) {
76572
- onResponse({
76573
- data: undefined,
76574
- error: createNativeFetchErrorResponse(DRAFT_DOESNT_EXIST_MESSAGE),
76575
- });
76576
- return;
76577
- }
76578
- const adapter = getDMLAdapterFromName(adapterId);
76579
- if (adapter === undefined) {
76580
- // This check is here for legacy purpose
76581
- // So the consumers still get the same errors
76582
- if (getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined) {
76583
- onResponse({
76584
- data: undefined,
76585
- error: createNativeFetchErrorResponse(NON_MUTATING_ADAPTER_MESSAGE),
76586
- });
76587
- return;
76588
- }
76589
- throw Error(`adapter ${adapterId} not recognized`);
76590
- }
76591
- if (adapterId === 'deleteRecord') {
76592
- invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext);
76593
- }
76594
- else {
76595
- invokeDmlAdapter(adapter, parse$1(config), (responseValue) => {
76596
- const draftIds = draftIdsForResponseValue(responseValue);
76597
- if (responseValue.error === undefined &&
76598
- draftIds !== undefined &&
76599
- draftIds.length > 0) {
76600
- const draftId = draftIds[draftIds.length - 1];
76601
- draftManager.replaceAction(draftIdToReplace, draftId).then(() => {
76602
- onResponse(responseValue);
76603
- });
76604
- }
76605
- else {
76606
- let response = responseValue;
76607
- response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
76608
- onResponse(response);
76609
- }
76610
- }, nativeAdapterRequestContext);
76611
- }
76612
- });
76613
- }
76614
- /**
76615
- * Executes the specified adapter with the given adapterId and config. Then
76616
- * it sets the given metadata on the draft created by the mutating adapter. Will call
76617
- * onResult callback once with data or error.
76618
- *
76619
- * This function throws an error if the given adapterId cannot be found, or if the
76620
- * adapterId is not a mutating adapter, or if a draft isn't created, or if it
76621
- * fails to parse the given config string.
76622
- */
76623
- function invokeAdapterWithMetadata(adapterId, config, metadata, onResponse, nativeAdapterRequestContext) {
76624
- const adapter = getDMLAdapterFromName(adapterId);
76625
- if (adapter === undefined) {
76626
- // This check is here for legacy purpose
76627
- // So the consumers still get the same errors
76628
- if (getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined) {
76629
- onResponse({
76630
- data: undefined,
76631
- error: createNativeFetchErrorResponse(NON_MUTATING_ADAPTER_MESSAGE),
76632
- });
76633
- return;
76634
- }
76635
- throw Error(`adapter ${adapterId} not recognized`);
76636
- }
76637
- if (adapterId === 'deleteRecord') {
76638
- invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponse, nativeAdapterRequestContext);
76639
- }
76640
- else {
76641
- invokeDmlAdapter(adapter, parse$1(config), (responseValue) => {
76642
- const draftIds = draftIdsForResponseValue(responseValue);
76643
- if (responseValue.error === undefined &&
76644
- draftIds !== undefined &&
76645
- draftIds.length > 0) {
76646
- const draftId = draftIds[draftIds.length - 1];
76647
- draftManager.setMetadata(draftId, metadata).then(() => {
76648
- onResponse(responseValue);
76649
- });
76650
- }
76651
- else {
76652
- let response = responseValue;
76653
- response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
76654
- onResponse(response);
76655
- }
76656
- }, nativeAdapterRequestContext);
76657
- }
76658
- }
76659
- /*
76660
- //TODO W-10284305: Remove this function in 238
76661
- This is a special case version of the invokeAdapterWithMetadata function
76662
- which should only be used for the deleteRecord wire adapter, since it does not
76663
- contain record data in the result and has to do special querying of the draft queue
76664
- */
76665
- function invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponse, nativeAdapterRequestContext) {
76666
- const targetedRecordId = parse$1(config);
76667
- let priorDraftIds;
76668
- draftManager.getQueue().then((draftState) => {
76669
- priorDraftIds = draftState.items.map((item) => {
76670
- return item.id;
76671
- });
76672
- invokeDmlAdapter(adapter, parse$1(config), (responseValue) => {
76673
- if (responseValue.error === undefined &&
76674
- responseValue.errors === undefined &&
76675
- responseValue.data === undefined) {
76676
- draftManager.getQueue().then((newState) => {
76677
- const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
76678
- const newDrafts = newState.items;
76679
- const addedDrafts = newDrafts.filter((item) => {
76680
- const isNew = draftIdsToFilter.indexOf(item.id) < 0;
76681
- const targetIdMatches = item.targetId === targetedRecordId;
76682
- return isNew && targetIdMatches;
76683
- });
76684
- if (addedDrafts.length !== 1) {
76685
- let response = {
76686
- error: createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE),
76687
- };
76688
- onResponse(response);
76689
- }
76690
- else {
76691
- draftManager.setMetadata(addedDrafts[0].id, metadata).then(() => {
76692
- onResponse(responseValue);
76693
- });
76694
- }
76695
- });
76696
- }
76697
- else {
76698
- let response = responseValue;
76699
- response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
76700
- onResponse(response);
76701
- }
76702
- }, nativeAdapterRequestContext);
76703
- });
76704
- }
76705
- /*
76706
- //TODO W-10284305: Remove this function in 238
76707
- This is a special case version of the invokeAdapterWithDraftToReplace function
76708
- which should only be used for the deleteRecord wire adapter, since it does not
76709
- contain record data in the result and has to do special querying of the draft queue
76710
- */
76711
- function invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
76712
- const targetedRecordId = parse$1(config);
76713
- let priorDraftIds;
76714
- draftManager.getQueue().then((draftState) => {
76715
- priorDraftIds = draftState.items.map((item) => {
76716
- return item.id;
76717
- });
76718
- invokeDmlAdapter(adapter, parse$1(config), (responseValue) => {
76719
- if (responseValue.error === undefined &&
76720
- responseValue.errors === undefined &&
76721
- responseValue.data === undefined) {
76722
- draftManager.getQueue().then((newState) => {
76723
- const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
76724
- const newDrafts = newState.items;
76725
- const addedDrafts = newDrafts.filter((item) => {
76726
- const isNew = draftIdsToFilter.indexOf(item.id) < 0;
76727
- const targetIdMatches = item.targetId === targetedRecordId;
76728
- return isNew && targetIdMatches;
76729
- });
76730
- if (addedDrafts.length !== 1) {
76731
- let response = {
76732
- error: createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE),
76733
- };
76734
- onResponse(response);
76735
- }
76736
- else {
76737
- draftManager
76738
- .replaceAction(draftIdToReplace, addedDrafts[0].id)
76739
- .then(() => {
76740
- onResponse(responseValue);
76741
- });
76742
- }
76743
- });
76744
- }
76745
- else {
76746
- let response = responseValue;
76747
- response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
76748
- onResponse(response);
76749
- }
76750
- }, nativeAdapterRequestContext);
76751
- });
76752
- }
76753
- function draftIdsForResponseValue(response) {
76754
- if (response.data !== undefined &&
76755
- response.data.drafts !== undefined &&
76756
- response.data.drafts.draftActionIds !== undefined) {
76757
- return response.data.drafts.draftActionIds;
76758
- }
76759
- return undefined;
76760
- }
76761
- /**
76762
- * Executes the specified adapter with the given adapterId and config. Will call
76763
- * onResponse callback once with data or error.
76764
- *
76765
- * This function throws an error if the given adapterId cannot be found or if it
76766
- * fails to parse the given config string.
76767
- */
76768
- function invokeAdapter(adapterId, config, onResponse, nativeAdapterRequestContext) {
76769
- const onResponseDelegate = (value) => {
76770
- onResponse(buildNativeCallbackValue(value));
76771
- };
76772
- const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
76773
- const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
76774
- const configObject = parse$1(config);
76775
- // currently all uiapi GET adapters have a corresponding imperative adapter
76776
- if (imperativeAdapter !== undefined) {
76777
- // Check if it's graphQl adapter
76778
- // Parse the query in that case
76779
- const isGql = isGqlAdapter(imperativeAdapterIdentifier);
76780
- if (isGql) {
76781
- try {
76782
- // gql config needs gql query string turned into AST object
76783
- configObject.query = parseAndVisit(configObject.query);
76784
- }
76785
- catch (err) {
76786
- const parseError = normalizeError(err);
76787
- reportGraphqlQueryParseError(parseError);
76788
- // call the callback with error
76789
- onResponseDelegate({
76790
- data: undefined,
76791
- error: createNativeFetchErrorResponse(parseError.message),
76792
- });
76793
- return;
76794
- }
76795
- }
76796
- //unstable_graphql_imperative
76797
- if (imperativeAdapterIdentifier.includes('graphql')) {
76798
- try {
76799
- //we need to use the gql literal to convert into a document node
76800
- //in order to get through the gql imperative adapter
76508
+ `;
76509
+ }
76510
+ catch (err) {
76511
+ const parseError = normalizeError(err);
76512
+ reportGraphqlQueryParseError(parseError);
76513
+ // call the callback with error
76514
+ onResponseDelegate({
76515
+ data: undefined,
76516
+ error: createNativeFetchErrorResponse(parseError.message),
76517
+ });
76518
+ return () => { };
76519
+ }
76520
+ }
76521
+ try {
76522
+ return imperativeAdapter.subscribe(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
76523
+ }
76524
+ catch (err) {
76525
+ if (isGql) {
76526
+ reportGraphqlQueryParseError(err);
76527
+ }
76528
+ onResponseDelegate(buildInvalidConfigError(err));
76529
+ return () => { };
76530
+ }
76531
+ }
76532
+ /**
76533
+ * Checks if the given adapter id is a graphQL adapter
76534
+ *
76535
+ * @param imperativeAdapterIdentifier The adapter id to check
76536
+ * @returns true if the adapter is graphQL, false otherwise
76537
+ */
76538
+ function isGqlAdapter(imperativeAdapterIdentifier) {
76539
+ return keys$2(gqlApi).indexOf(imperativeAdapterIdentifier) > -1;
76540
+ }
76541
+ /**
76542
+ * Executes a DML adapter and calls the onResponse callback upon receiving a response.
76543
+ *
76544
+ * @param adapter : DML Adapter
76545
+ * @param configObject : parsed config
76546
+ * @param onResponse : OnResponse
76547
+ * @param nativeAdapterRequestContext: Specify cache policy, priority and observability parameters
76548
+ */
76549
+ function invokeDmlAdapter(adapter, configObject, onResponse, nativeAdapterRequestContext) {
76550
+ try {
76551
+ adapter(configObject, buildAdapterRequestContext(nativeAdapterRequestContext)).then((data) => {
76552
+ onResponse({ data, error: undefined });
76553
+ }, (error) => {
76554
+ onResponse({ data: undefined, error });
76555
+ });
76556
+ }
76557
+ catch (err) {
76558
+ // For catching the synchronous error in adapter
76559
+ onResponse(buildInvalidConfigError(err));
76560
+ }
76561
+ }
76562
+ /**
76563
+ * Executes the specified adapter with the given adapterId and config. Then
76564
+ * it replaces the draft with the given id with the draft generated
76565
+ * by the mutating adapter. Will call onResult callback once with data or error.
76566
+ *
76567
+ * This function throws an error if the given adapterId cannot be found, or if the
76568
+ * adapterId is not a mutating adapter, or if a draft isn't created, or if it
76569
+ * fails to parse the given config string.
76570
+ */
76571
+ function invokeAdapterWithDraftToReplace(adapterId, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
76572
+ draftManager.getQueue().then((draftInfo) => {
76573
+ const draftIds = draftInfo.items.map((draft) => draft.id);
76574
+ if (draftIds.includes(draftIdToReplace) === false) {
76575
+ onResponse({
76576
+ data: undefined,
76577
+ error: createNativeFetchErrorResponse(DRAFT_DOESNT_EXIST_MESSAGE),
76578
+ });
76579
+ return;
76580
+ }
76581
+ const adapter = getDMLAdapterFromName(adapterId);
76582
+ if (adapter === undefined) {
76583
+ // This check is here for legacy purpose
76584
+ // So the consumers still get the same errors
76585
+ if (getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined) {
76586
+ onResponse({
76587
+ data: undefined,
76588
+ error: createNativeFetchErrorResponse(NON_MUTATING_ADAPTER_MESSAGE),
76589
+ });
76590
+ return;
76591
+ }
76592
+ throw Error(`adapter ${adapterId} not recognized`);
76593
+ }
76594
+ if (adapterId === 'deleteRecord') {
76595
+ invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext);
76596
+ }
76597
+ else {
76598
+ invokeDmlAdapter(adapter, parse$1(config), (responseValue) => {
76599
+ const draftIds = draftIdsForResponseValue(responseValue);
76600
+ if (responseValue.error === undefined &&
76601
+ draftIds !== undefined &&
76602
+ draftIds.length > 0) {
76603
+ const draftId = draftIds[draftIds.length - 1];
76604
+ draftManager.replaceAction(draftIdToReplace, draftId).then(() => {
76605
+ onResponse(responseValue);
76606
+ });
76607
+ }
76608
+ else {
76609
+ let response = responseValue;
76610
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
76611
+ onResponse(response);
76612
+ }
76613
+ }, nativeAdapterRequestContext);
76614
+ }
76615
+ });
76616
+ }
76617
+ /**
76618
+ * Executes the specified adapter with the given adapterId and config. Then
76619
+ * it sets the given metadata on the draft created by the mutating adapter. Will call
76620
+ * onResult callback once with data or error.
76621
+ *
76622
+ * This function throws an error if the given adapterId cannot be found, or if the
76623
+ * adapterId is not a mutating adapter, or if a draft isn't created, or if it
76624
+ * fails to parse the given config string.
76625
+ */
76626
+ function invokeAdapterWithMetadata(adapterId, config, metadata, onResponse, nativeAdapterRequestContext) {
76627
+ const adapter = getDMLAdapterFromName(adapterId);
76628
+ if (adapter === undefined) {
76629
+ // This check is here for legacy purpose
76630
+ // So the consumers still get the same errors
76631
+ if (getImperativeAdapterFromName(imperativeAdapterKeyBuilder(adapterId)) !== undefined) {
76632
+ onResponse({
76633
+ data: undefined,
76634
+ error: createNativeFetchErrorResponse(NON_MUTATING_ADAPTER_MESSAGE),
76635
+ });
76636
+ return;
76637
+ }
76638
+ throw Error(`adapter ${adapterId} not recognized`);
76639
+ }
76640
+ if (adapterId === 'deleteRecord') {
76641
+ invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponse, nativeAdapterRequestContext);
76642
+ }
76643
+ else {
76644
+ invokeDmlAdapter(adapter, parse$1(config), async (responseValue) => {
76645
+ const draftIds = draftIdsForResponseValue(responseValue);
76646
+ if (responseValue.error === undefined &&
76647
+ draftIds !== undefined &&
76648
+ draftIds.length > 0) {
76649
+ const draftId = draftIds[draftIds.length - 1];
76650
+ const managerState = await draftManager.getQueue();
76651
+ const existingMetadata = (managerState.items.find((i) => i.id === draftId) || {}).metadata || {};
76652
+ draftManager
76653
+ .setMetadata(draftId, { ...existingMetadata, ...metadata })
76654
+ .then(() => {
76655
+ onResponse(responseValue);
76656
+ });
76657
+ }
76658
+ else {
76659
+ let response = responseValue;
76660
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
76661
+ onResponse(response);
76662
+ }
76663
+ }, nativeAdapterRequestContext);
76664
+ }
76665
+ }
76666
+ /*
76667
+ //TODO W-10284305: Remove this function in 238
76668
+ This is a special case version of the invokeAdapterWithMetadata function
76669
+ which should only be used for the deleteRecord wire adapter, since it does not
76670
+ contain record data in the result and has to do special querying of the draft queue
76671
+ */
76672
+ function invokeAdapterWithMetadataDeleteRecord(adapter, config, metadata, onResponse, nativeAdapterRequestContext) {
76673
+ const targetedRecordId = parse$1(config);
76674
+ let priorDraftIds;
76675
+ draftManager.getQueue().then((draftState) => {
76676
+ priorDraftIds = draftState.items.map((item) => {
76677
+ return item.id;
76678
+ });
76679
+ invokeDmlAdapter(adapter, parse$1(config), (responseValue) => {
76680
+ if (responseValue.error === undefined &&
76681
+ responseValue.errors === undefined &&
76682
+ responseValue.data === undefined) {
76683
+ draftManager.getQueue().then((newState) => {
76684
+ const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
76685
+ const newDrafts = newState.items;
76686
+ const addedDrafts = newDrafts.filter((item) => {
76687
+ const isNew = draftIdsToFilter.indexOf(item.id) < 0;
76688
+ const targetIdMatches = item.targetId === targetedRecordId;
76689
+ return isNew && targetIdMatches;
76690
+ });
76691
+ if (addedDrafts.length !== 1) {
76692
+ let response = {
76693
+ error: createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE),
76694
+ };
76695
+ onResponse(response);
76696
+ }
76697
+ else {
76698
+ draftManager.setMetadata(addedDrafts[0].id, metadata).then(() => {
76699
+ onResponse(responseValue);
76700
+ });
76701
+ }
76702
+ });
76703
+ }
76704
+ else {
76705
+ let response = responseValue;
76706
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
76707
+ onResponse(response);
76708
+ }
76709
+ }, nativeAdapterRequestContext);
76710
+ });
76711
+ }
76712
+ /*
76713
+ //TODO W-10284305: Remove this function in 238
76714
+ This is a special case version of the invokeAdapterWithDraftToReplace function
76715
+ which should only be used for the deleteRecord wire adapter, since it does not
76716
+ contain record data in the result and has to do special querying of the draft queue
76717
+ */
76718
+ function invokeAdapterWithDraftToReplaceDeleteRecord(adapter, config, draftIdToReplace, onResponse, nativeAdapterRequestContext) {
76719
+ const targetedRecordId = parse$1(config);
76720
+ let priorDraftIds;
76721
+ draftManager.getQueue().then((draftState) => {
76722
+ priorDraftIds = draftState.items.map((item) => {
76723
+ return item.id;
76724
+ });
76725
+ invokeDmlAdapter(adapter, parse$1(config), (responseValue) => {
76726
+ if (responseValue.error === undefined &&
76727
+ responseValue.errors === undefined &&
76728
+ responseValue.data === undefined) {
76729
+ draftManager.getQueue().then((newState) => {
76730
+ const draftIdsToFilter = priorDraftIds ? priorDraftIds : [];
76731
+ const newDrafts = newState.items;
76732
+ const addedDrafts = newDrafts.filter((item) => {
76733
+ const isNew = draftIdsToFilter.indexOf(item.id) < 0;
76734
+ const targetIdMatches = item.targetId === targetedRecordId;
76735
+ return isNew && targetIdMatches;
76736
+ });
76737
+ if (addedDrafts.length !== 1) {
76738
+ let response = {
76739
+ error: createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE),
76740
+ };
76741
+ onResponse(response);
76742
+ }
76743
+ else {
76744
+ draftManager
76745
+ .replaceAction(draftIdToReplace, addedDrafts[0].id)
76746
+ .then(() => {
76747
+ onResponse(responseValue);
76748
+ });
76749
+ }
76750
+ });
76751
+ }
76752
+ else {
76753
+ let response = responseValue;
76754
+ response.error = createNativeFetchErrorResponse(NO_DRAFT_CREATED_MESSAGE);
76755
+ onResponse(response);
76756
+ }
76757
+ }, nativeAdapterRequestContext);
76758
+ });
76759
+ }
76760
+ function draftIdsForResponseValue(response) {
76761
+ if (response.data !== undefined &&
76762
+ response.data.drafts !== undefined &&
76763
+ response.data.drafts.draftActionIds !== undefined) {
76764
+ return response.data.drafts.draftActionIds;
76765
+ }
76766
+ if (response.data !== undefined &&
76767
+ response.data.contentVersion !== undefined &&
76768
+ response.data.contentVersion.drafts !== undefined &&
76769
+ response.data.contentVersion.drafts.draftActionIds !== undefined) {
76770
+ return response.data.contentVersion.drafts.draftActionIds;
76771
+ }
76772
+ return undefined;
76773
+ }
76774
+ /**
76775
+ * Executes the specified adapter with the given adapterId and config. Will call
76776
+ * onResponse callback once with data or error.
76777
+ *
76778
+ * This function throws an error if the given adapterId cannot be found or if it
76779
+ * fails to parse the given config string.
76780
+ */
76781
+ function invokeAdapter(adapterId, config, onResponse, nativeAdapterRequestContext) {
76782
+ const onResponseDelegate = (value) => {
76783
+ onResponse(buildNativeCallbackValue(value));
76784
+ };
76785
+ const imperativeAdapterIdentifier = imperativeAdapterKeyBuilder(adapterId);
76786
+ const imperativeAdapter = getImperativeAdapterFromName(imperativeAdapterIdentifier);
76787
+ const configObject = parse$1(config);
76788
+ // currently all uiapi GET adapters have a corresponding imperative adapter
76789
+ if (imperativeAdapter !== undefined) {
76790
+ // Check if it's graphQl adapter
76791
+ // Parse the query in that case
76792
+ const isGql = isGqlAdapter(imperativeAdapterIdentifier);
76793
+ if (isGql) {
76794
+ try {
76795
+ // gql config needs gql query string turned into AST object
76796
+ configObject.query = parseAndVisit(configObject.query);
76797
+ }
76798
+ catch (err) {
76799
+ const parseError = normalizeError(err);
76800
+ reportGraphqlQueryParseError(parseError);
76801
+ // call the callback with error
76802
+ onResponseDelegate({
76803
+ data: undefined,
76804
+ error: createNativeFetchErrorResponse(parseError.message),
76805
+ });
76806
+ return;
76807
+ }
76808
+ }
76809
+ //unstable_graphql_imperative
76810
+ if (imperativeAdapterIdentifier.includes('graphql')) {
76811
+ try {
76812
+ //we need to use the gql literal to convert into a document node
76813
+ //in order to get through the gql imperative adapter
76801
76814
  configObject.query = gql `
76802
76815
  ${configObject.query}
76803
- `;
76804
- }
76805
- catch (err) {
76806
- const parseError = normalizeError(err);
76807
- reportGraphqlQueryParseError(parseError);
76808
- // call the callback with error
76809
- onResponseDelegate({
76810
- data: undefined,
76811
- error: createNativeFetchErrorResponse(parseError.message),
76812
- });
76813
- return;
76814
- }
76815
- }
76816
- try {
76817
- imperativeAdapter.invoke(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
76818
- }
76819
- catch (err) {
76820
- if (isGql) {
76821
- reportGraphqlQueryParseError(err);
76822
- }
76823
- onResponseDelegate(buildInvalidConfigError(err));
76824
- }
76825
- return;
76826
- }
76827
- const adapter = getDMLAdapterFromName(adapterId);
76828
- if (adapter === undefined) {
76829
- throw Error(`adapter ${adapterId} not recognized`);
76830
- }
76831
- invokeDmlAdapter(adapter, configObject, onResponseDelegate, nativeAdapterRequestContext);
76832
- }
76833
- /**
76834
- * @deprecated Use invokeAdapter or subscribeToAdapter instead
76835
- *
76836
- * W-9173084 Will remove this
76837
- */
76838
- function executeAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
76839
- return subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext);
76840
- }
76841
- /**
76842
- * @deprecated Use invokeAdapter instead
76843
- *
76844
- * W-9173084 Will remove this
76845
- */
76846
- function executeMutatingAdapter(adapterId, config, onResult, nativeAdapterRequestContext) {
76847
- invokeAdapter(adapterId, config, onResult, nativeAdapterRequestContext);
76816
+ `;
76817
+ }
76818
+ catch (err) {
76819
+ const parseError = normalizeError(err);
76820
+ reportGraphqlQueryParseError(parseError);
76821
+ // call the callback with error
76822
+ onResponseDelegate({
76823
+ data: undefined,
76824
+ error: createNativeFetchErrorResponse(parseError.message),
76825
+ });
76826
+ return;
76827
+ }
76828
+ }
76829
+ try {
76830
+ imperativeAdapter.invoke(configObject, buildAdapterRequestContext(nativeAdapterRequestContext), onResponseDelegate);
76831
+ }
76832
+ catch (err) {
76833
+ if (isGql) {
76834
+ reportGraphqlQueryParseError(err);
76835
+ }
76836
+ onResponseDelegate(buildInvalidConfigError(err));
76837
+ }
76838
+ return;
76839
+ }
76840
+ const adapter = getDMLAdapterFromName(adapterId);
76841
+ if (adapter === undefined) {
76842
+ throw Error(`adapter ${adapterId} not recognized`);
76843
+ }
76844
+ invokeDmlAdapter(adapter, configObject, onResponseDelegate, nativeAdapterRequestContext);
76845
+ }
76846
+ /**
76847
+ * @deprecated Use invokeAdapter or subscribeToAdapter instead
76848
+ *
76849
+ * W-9173084 Will remove this
76850
+ */
76851
+ function executeAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext) {
76852
+ return subscribeToAdapter(adapterId, config, onSnapshot, nativeAdapterRequestContext);
76853
+ }
76854
+ /**
76855
+ * @deprecated Use invokeAdapter instead
76856
+ *
76857
+ * W-9173084 Will remove this
76858
+ */
76859
+ function executeMutatingAdapter(adapterId, config, onResult, nativeAdapterRequestContext) {
76860
+ invokeAdapter(adapterId, config, onResult, nativeAdapterRequestContext);
76848
76861
  }
76849
76862
 
76850
- /* istanbul ignore file */
76851
- // A allowlist of methods that we allow to be proxied from another LDS instance
76852
- const allowList = ['enqueue', 'getQueueActions'];
76853
- /**
76854
- * Implements the DraftQueue interface from nimbus-plugin-lds by passing requests
76855
- * to the instance of the lds-drafts' DraftQueue implementation
76856
- */
76857
- const nimbusDraftQueue = {
76858
- callProxyMethod(methodName, serializedArgsArray, resultCallback, errorCallback) {
76859
- const method = draftQueue[methodName];
76860
- if (method === undefined) {
76861
- return errorCallback(stringify$1({
76862
- message: 'Method does not exist on the draft queue',
76863
- }));
76864
- }
76865
- if (allowList.includes(methodName) === false) {
76866
- return errorCallback(stringify$1({
76867
- message: `Method ${methodName} is not available for proxy invocation`,
76868
- }));
76869
- }
76870
- const parsedArgs = parse$1(serializedArgsArray);
76871
- // TODO [W-9933226]: we should validate the argument list based on which method is being called
76872
- if (isArray$1(parsedArgs) === false) {
76873
- return errorCallback(stringify$1({
76874
- message: 'expected array argument list',
76875
- }));
76876
- }
76877
- let methodResult = undefined;
76878
- try {
76879
- if (parsedArgs === undefined) {
76880
- methodResult = method.call(draftQueue);
76881
- }
76882
- else {
76883
- methodResult = method.call(draftQueue, ...parsedArgs);
76884
- }
76885
- }
76886
- catch (err) {
76887
- return errorCallback(stringify$1(err));
76888
- }
76889
- if (methodResult.then === undefined) {
76890
- return resultCallback(stringify$1(methodResult));
76891
- }
76892
- methodResult
76893
- .then((result) => {
76894
- resultCallback(stringify$1(result));
76895
- })
76896
- .catch((err) => {
76897
- errorCallback(stringify$1(err));
76898
- });
76899
- },
76863
+ /* istanbul ignore file */
76864
+ // A allowlist of methods that we allow to be proxied from another LDS instance
76865
+ const allowList = ['enqueue', 'getQueueActions'];
76866
+ /**
76867
+ * Implements the DraftQueue interface from nimbus-plugin-lds by passing requests
76868
+ * to the instance of the lds-drafts' DraftQueue implementation
76869
+ */
76870
+ const nimbusDraftQueue = {
76871
+ callProxyMethod(methodName, serializedArgsArray, resultCallback, errorCallback) {
76872
+ const method = draftQueue[methodName];
76873
+ if (method === undefined) {
76874
+ return errorCallback(stringify$1({
76875
+ message: 'Method does not exist on the draft queue',
76876
+ }));
76877
+ }
76878
+ if (allowList.includes(methodName) === false) {
76879
+ return errorCallback(stringify$1({
76880
+ message: `Method ${methodName} is not available for proxy invocation`,
76881
+ }));
76882
+ }
76883
+ const parsedArgs = parse$1(serializedArgsArray);
76884
+ // TODO [W-9933226]: we should validate the argument list based on which method is being called
76885
+ if (isArray$1(parsedArgs) === false) {
76886
+ return errorCallback(stringify$1({
76887
+ message: 'expected array argument list',
76888
+ }));
76889
+ }
76890
+ let methodResult = undefined;
76891
+ try {
76892
+ if (parsedArgs === undefined) {
76893
+ methodResult = method.call(draftQueue);
76894
+ }
76895
+ else {
76896
+ methodResult = method.call(draftQueue, ...parsedArgs);
76897
+ }
76898
+ }
76899
+ catch (err) {
76900
+ return errorCallback(stringify$1(err));
76901
+ }
76902
+ if (methodResult.then === undefined) {
76903
+ return resultCallback(stringify$1(methodResult));
76904
+ }
76905
+ methodResult
76906
+ .then((result) => {
76907
+ resultCallback(stringify$1(result));
76908
+ })
76909
+ .catch((err) => {
76910
+ errorCallback(stringify$1(err));
76911
+ });
76912
+ },
76900
76913
  };
76901
76914
 
76902
- function setUiApiRecordTTL(ttl) {
76903
- {
76904
- return Promise.resolve();
76905
- }
76906
- }
76907
- function setMetadataTTL(ttl) {
76908
- {
76909
- return Promise.resolve();
76910
- }
76915
+ function setUiApiRecordTTL(ttl) {
76916
+ {
76917
+ return Promise.resolve();
76918
+ }
76919
+ }
76920
+ function setMetadataTTL(ttl) {
76921
+ {
76922
+ return Promise.resolve();
76923
+ }
76911
76924
  }
76912
76925
 
76913
- function createPrimingSession(config) {
76914
- const { createPrimingSession } = getRuntime();
76915
- const { primingEventHandler, concurrency, batchSize } = config;
76916
- const session = createPrimingSession({ concurrency, batchSize });
76917
- if (primingEventHandler) {
76918
- const { onError, onPrimed } = primingEventHandler;
76919
- if (onError) {
76920
- session.on('error', onError.bind(primingEventHandler));
76921
- }
76922
- if (onPrimed) {
76923
- session.on('primed', onPrimed.bind(primingEventHandler));
76924
- }
76925
- }
76926
- return {
76927
- enqueue: session.enqueue.bind(session),
76928
- cancel: session.cancel.bind(session),
76929
- on: session.on.bind(session),
76930
- once: session.once.bind(session),
76931
- off: session.off.bind(session),
76932
- };
76926
+ function createPrimingSession(config) {
76927
+ const { createPrimingSession } = getRuntime();
76928
+ const { primingEventHandler, concurrency, batchSize } = config;
76929
+ const session = createPrimingSession({ concurrency, batchSize });
76930
+ if (primingEventHandler) {
76931
+ const { onError, onPrimed } = primingEventHandler;
76932
+ if (onError) {
76933
+ session.on('error', onError.bind(primingEventHandler));
76934
+ }
76935
+ if (onPrimed) {
76936
+ session.on('primed', onPrimed.bind(primingEventHandler));
76937
+ }
76938
+ }
76939
+ return {
76940
+ enqueue: session.enqueue.bind(session),
76941
+ cancel: session.cancel.bind(session),
76942
+ on: session.on.bind(session),
76943
+ once: session.once.bind(session),
76944
+ off: session.off.bind(session),
76945
+ };
76933
76946
  }
76934
76947
 
76935
- // LWR has a "setupLDS" bootstrap service/loader hook, we simulate this in
76936
- const { luvio } = getRuntime();
76948
+ // LWR has a "setupLDS" bootstrap service/loader hook, we simulate this in
76949
+ const { luvio } = getRuntime();
76937
76950
  setDefaultLuvio({ luvio });
76938
76951
 
76939
76952
  exports.createPrimingSession = createPrimingSession;
@@ -76954,4 +76967,4 @@
76954
76967
  Object.defineProperty(exports, '__esModule', { value: true });
76955
76968
 
76956
76969
  }));
76957
- // version: 1.125.0-242b72352
76970
+ // version: 1.126.0-86fa082d1