@salesforce/lds-adapters-apex 1.253.0 → 1.256.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.
@@ -461,6 +461,10 @@ function splitQualifiedFieldApiName(fieldApiName) {
461
461
  }
462
462
  return [fieldApiName.substring(0, idx), fieldApiName.substring(idx + 1)];
463
463
  }
464
+ function isPromise(value) {
465
+ // check for Thenable due to test frameworks using custom Promise impls
466
+ return value !== null && value !== undefined && typeof value.then === 'function';
467
+ }
464
468
 
465
469
  function createResourceRequest(config) {
466
470
  const headers = {};
@@ -596,15 +600,55 @@ const invoker = (luvio, invokerParams) => {
596
600
  const ldsAdapter = postApexAdapterFactory(luvio, namespace, classname, method, isContinuation);
597
601
  return getInvoker(ldsAdapter);
598
602
  };
603
+ function handleSnapshot(snapshot) {
604
+ if (snapshot.state === 'Error') {
605
+ throw snapshot.error;
606
+ }
607
+ return snapshot.data;
608
+ }
609
+ function asPromiseLike(snapshot) {
610
+ if (snapshot === null) {
611
+ if (process.env.NODE_ENV !== 'production') {
612
+ throw new Error("Imperative adapters should never have a null snapshot... how'd y'all get here?");
613
+ }
614
+ }
615
+ return {
616
+ then: (onFulfilled, onRejected) => {
617
+ try {
618
+ const data = handleSnapshot(snapshot);
619
+ if (onFulfilled) {
620
+ return onFulfilled(data);
621
+ }
622
+ }
623
+ catch (e) {
624
+ if (onRejected) {
625
+ return onRejected(e);
626
+ }
627
+ return {
628
+ catch: (callback) => {
629
+ callback(e);
630
+ },
631
+ };
632
+ }
633
+ },
634
+ catch: (callback) => {
635
+ try {
636
+ handleSnapshot(snapshot);
637
+ }
638
+ catch (e) {
639
+ callback(e);
640
+ }
641
+ },
642
+ };
643
+ }
599
644
  function getInvoker(ldsAdapter) {
600
645
  return (config, requestContext) => {
601
646
  const snapshotOrPromise = ldsAdapter(config, requestContext);
602
- return Promise.resolve(snapshotOrPromise).then((snapshot) => {
603
- if (snapshot.state === 'Error') {
604
- throw snapshot.error;
605
- }
606
- return snapshot.data;
607
- });
647
+ if (isPromise(snapshotOrPromise)) {
648
+ return Promise.resolve(snapshotOrPromise).then(handleSnapshot);
649
+ }
650
+ // to preserve previous behavior return a PromiseLike
651
+ return asPromiseLike(snapshotOrPromise);
608
652
  };
609
653
  }
610
654
  function postApexAdapterFactory(luvio, namespace, classname, method, isContinuation) {
@@ -24,3 +24,4 @@ export declare function getFieldApiName(value: string | FieldId): string;
24
24
  * @return The object and field API names.
25
25
  */
26
26
  export declare function splitQualifiedFieldApiName(fieldApiName: string): string[];
27
+ export declare function isPromise<D>(value: D | Promise<D> | null): value is Promise<D>;
@@ -7,4 +7,11 @@ export declare function ingestSuccess(luvio: Luvio, resourceParams: ResourceRequ
7
7
  export declare function onFetchResponseSuccess(luvio: Luvio, context: AdapterContext, _config: ApexAdapterConfig, resourceParams: ResourceRequestConfig, response: FetchResponse<any>): Promise<FulfilledSnapshot<any, any> | StaleSnapshot<any, any>>;
8
8
  export declare function onFetchResponseError(luvio: Luvio, _context: AdapterContext, _config: ApexAdapterConfig, _resourceParams: ResourceRequestConfig, response: ErrorResponse): Promise<import("@luvio/engine").ErrorSnapshot>;
9
9
  export declare function buildNetworkSnapshot(luvio: Luvio, context: AdapterContext, config: ApexAdapterConfig, options?: DispatchResourceRequestContext): Promise<Snapshot<any>>;
10
- export declare const invoker: (luvio: Luvio, invokerParams: ApexInvokerParams) => (config: unknown, requestContext?: AdapterRequestContext) => Promise<any>;
10
+ export declare const invoker: (luvio: Luvio, invokerParams: ApexInvokerParams) => (config: unknown, requestContext?: AdapterRequestContext) => Promise<any> | {
11
+ then: (onFulfilled?: ((result: any) => any) | undefined, onRejected?: ((reason: any) => any) | undefined) => any;
12
+ catch: (callback: any) => void;
13
+ };
14
+ export declare function asPromiseLike(snapshot: Snapshot<any> | null): {
15
+ then: (onFulfilled?: ((result: any) => any) | undefined, onRejected?: ((reason: any) => any) | undefined) => any;
16
+ catch: (callback: any) => void;
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-adapters-apex",
3
- "version": "1.253.0",
3
+ "version": "1.256.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "Wire adapters for Apex",
6
6
  "main": "dist/es/es2018/apex-service.js",
@@ -31,12 +31,12 @@
31
31
  ]
32
32
  },
33
33
  "dependencies": {
34
- "@salesforce/lds-bindings": "*",
35
- "@salesforce/lds-default-luvio": "*"
34
+ "@salesforce/lds-bindings": "^1.256.0",
35
+ "@salesforce/lds-default-luvio": "^1.256.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@salesforce/lds-compiler-plugins": "*",
39
- "@salesforce/lds-karma": "*"
38
+ "@salesforce/lds-compiler-plugins": "^1.256.0",
39
+ "@salesforce/lds-karma": "^1.256.0"
40
40
  },
41
41
  "nx": {
42
42
  "targets": {
package/sfdc/index.js CHANGED
@@ -440,6 +440,10 @@ function stableJSONStringify(node) {
440
440
  }
441
441
  return '{' + out + '}';
442
442
  }
443
+ function isPromise(value) {
444
+ // check for Thenable due to test frameworks using custom Promise impls
445
+ return value !== null && value !== undefined && typeof value.then === 'function';
446
+ }
443
447
 
444
448
  function createResourceRequest(config) {
445
449
  const headers = {};
@@ -575,15 +579,55 @@ const invoker = (luvio, invokerParams) => {
575
579
  const ldsAdapter = postApexAdapterFactory(luvio, namespace, classname, method, isContinuation);
576
580
  return getInvoker(ldsAdapter);
577
581
  };
582
+ function handleSnapshot(snapshot) {
583
+ if (snapshot.state === 'Error') {
584
+ throw snapshot.error;
585
+ }
586
+ return snapshot.data;
587
+ }
588
+ function asPromiseLike(snapshot) {
589
+ if (snapshot === null) {
590
+ if (process.env.NODE_ENV !== 'production') {
591
+ throw new Error("Imperative adapters should never have a null snapshot... how'd y'all get here?");
592
+ }
593
+ }
594
+ return {
595
+ then: (onFulfilled, onRejected) => {
596
+ try {
597
+ const data = handleSnapshot(snapshot);
598
+ if (onFulfilled) {
599
+ return onFulfilled(data);
600
+ }
601
+ }
602
+ catch (e) {
603
+ if (onRejected) {
604
+ return onRejected(e);
605
+ }
606
+ return {
607
+ catch: (callback) => {
608
+ callback(e);
609
+ },
610
+ };
611
+ }
612
+ },
613
+ catch: (callback) => {
614
+ try {
615
+ handleSnapshot(snapshot);
616
+ }
617
+ catch (e) {
618
+ callback(e);
619
+ }
620
+ },
621
+ };
622
+ }
578
623
  function getInvoker(ldsAdapter) {
579
624
  return (config, requestContext) => {
580
625
  const snapshotOrPromise = ldsAdapter(config, requestContext);
581
- return Promise.resolve(snapshotOrPromise).then((snapshot) => {
582
- if (snapshot.state === 'Error') {
583
- throw snapshot.error;
584
- }
585
- return snapshot.data;
586
- });
626
+ if (isPromise(snapshotOrPromise)) {
627
+ return Promise.resolve(snapshotOrPromise).then(handleSnapshot);
628
+ }
629
+ // to preserve previous behavior return a PromiseLike
630
+ return asPromiseLike(snapshotOrPromise);
587
631
  };
588
632
  }
589
633
  function postApexAdapterFactory(luvio, namespace, classname, method, isContinuation) {
@@ -638,4 +682,4 @@ const getApexInvoker = function (namespace, classname, method, isContinuation) {
638
682
  };
639
683
 
640
684
  export { getApexInvoker, refreshApex };
641
- // version: 1.253.0-15fc9805a
685
+ // version: 1.256.0-fb019fbad