@salesforce/lds-worker-api 1.361.0 → 1.363.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.
@@ -56,24 +56,31 @@ function extractWireAdapterName(adapterName) {
56
56
  }
57
57
  let lazyDMLAdapterMap = undefined;
58
58
  let lazyImperativeAdapterMap = undefined;
59
+ function buildAdapterMaps(map) {
60
+ const imperativeAdapterNames = keys(map).filter((name) => name.endsWith(IMPERATIVE_ADAPTER_SUFFIX));
61
+ const imperativeAdapterMap = {};
62
+ for (const adapterName of imperativeAdapterNames) {
63
+ const adapter = map[adapterName];
64
+ imperativeAdapterMap[adapterName] = adapter;
65
+ delete map[adapterName];
66
+ // remove the corresponding wire adapter from the adapter map
67
+ const wireAdapterName = extractWireAdapterName(adapterName);
68
+ delete map[wireAdapterName];
69
+ }
70
+ return {
71
+ dmlAdapterMap: map,
72
+ imperativeAdapterMap,
73
+ };
74
+ }
59
75
  // this function builds the adapter maps lazily
60
76
  function getAdapterMaps() {
61
77
  if (lazyDMLAdapterMap === undefined || lazyImperativeAdapterMap === undefined) {
62
78
  // We should eventually be explicit about what we expose here instead of exporting everything from the modules,
63
79
  // this is our API contract to native callers and should be explicit
64
80
  const map = Object.assign({}, gqlApi, lightningAppsApi, lightningLayoutApi, lightningLayoutUserStateApi, lightningListApi, lightningLookupsApi, lightningObjectApi, lightningRecordActionsApi, lightningRecordApi, lightningRecordAvatarApi, lightningRelatedListApi, lightningGraphQLApi, unstableLightningAppsApi, unstableLightningLayoutApi, unstableLightningListApi, unstableLightningLookupsApi, unstableLightningObjectApi, unstableLightningRecordActionsApi, unstableLightningRecordApi, unstableLightningRecordAvatarApi, unstableLightningRelatedListApi);
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;
81
+ const { dmlAdapterMap, imperativeAdapterMap } = buildAdapterMaps(map);
82
+ lazyDMLAdapterMap = dmlAdapterMap;
83
+ lazyImperativeAdapterMap = imperativeAdapterMap;
77
84
  }
78
85
  return { dmlAdapterMap: lazyDMLAdapterMap, imperativeAdapterMap: lazyImperativeAdapterMap };
79
86
  }
@@ -1118,6 +1125,95 @@ function handleInstrumentation(activity, stat, progress) {
1118
1125
  }
1119
1126
  }
1120
1127
 
1128
+ const LUVIO_ADAPTER_FAMILY = /^force\/ldsAdapters/;
1129
+ async function importLuvioAdapterModule(specifier) {
1130
+ if (!LUVIO_ADAPTER_FAMILY.test(specifier)) {
1131
+ throw `${specifier} is not an allowed luvio adapter module`;
1132
+ }
1133
+ let module;
1134
+ try {
1135
+ module = await import(specifier);
1136
+ }
1137
+ catch {
1138
+ throw `module not found for specifier ${specifier}`;
1139
+ }
1140
+ return new LuvioAdapterModule(module);
1141
+ }
1142
+ class LuvioAdapterModule {
1143
+ constructor(module) {
1144
+ const map = Object.assign({}, module);
1145
+ const { dmlAdapterMap, imperativeAdapterMap } = buildAdapterMaps(map);
1146
+ this.imperativeAdapterMap = imperativeAdapterMap;
1147
+ this.dmlAdapterMap = dmlAdapterMap;
1148
+ }
1149
+ async invokeAdapter(adapterName, config, nativeAdapterRequestContext) {
1150
+ const imperativeAdapterIdentifier = `${adapterName}_imperative`;
1151
+ const imperativeAdapter = this.imperativeAdapterMap[imperativeAdapterIdentifier];
1152
+ if (imperativeAdapter === undefined) {
1153
+ const dmlAdapter = this.dmlAdapterMap[adapterName];
1154
+ if (dmlAdapter === undefined) {
1155
+ return {
1156
+ data: undefined,
1157
+ error: createNativeFetchErrorResponse(`adapter ${adapterName} not recognized`),
1158
+ };
1159
+ }
1160
+ return this.invokeDmlAdapter(dmlAdapter, config, nativeAdapterRequestContext);
1161
+ }
1162
+ return new Promise((resolve) => {
1163
+ try {
1164
+ imperativeAdapter.invoke(config, buildAdapterRequestContext(nativeAdapterRequestContext), (response) => {
1165
+ resolve(buildNativeCallbackValue(response));
1166
+ });
1167
+ }
1168
+ catch (error) {
1169
+ resolve(buildInvalidConfigError(error));
1170
+ }
1171
+ });
1172
+ }
1173
+ subscribeAdapter(adapterName, config, nativeAdapterRequestContext, callback) {
1174
+ const imperativeAdapterIdentifier = `${adapterName}_imperative`;
1175
+ const imperativeAdapter = this.imperativeAdapterMap[imperativeAdapterIdentifier];
1176
+ if (imperativeAdapter === undefined) {
1177
+ const dmlAdapter = this.dmlAdapterMap[adapterName];
1178
+ if (dmlAdapter === undefined) {
1179
+ const nativeValue = buildNativeCallbackValue({
1180
+ data: undefined,
1181
+ error: createNativeFetchErrorResponse(`adapter ${adapterName} not recognized`),
1182
+ });
1183
+ callback(nativeValue);
1184
+ return () => { };
1185
+ }
1186
+ const nativeValue = buildNativeCallbackValue({
1187
+ data: undefined,
1188
+ error: createNativeFetchErrorResponse(`${adapterName} is not a GET wire adapter and cannot be subscribed.`),
1189
+ });
1190
+ callback(nativeValue);
1191
+ return () => { };
1192
+ }
1193
+ try {
1194
+ return imperativeAdapter.subscribe(config, buildAdapterRequestContext(nativeAdapterRequestContext), callback);
1195
+ }
1196
+ catch (error) {
1197
+ callback(buildInvalidConfigError(error));
1198
+ return () => { };
1199
+ }
1200
+ }
1201
+ invokeDmlAdapter(adapter, config, nativeAdapterRequestContext) {
1202
+ return new Promise((resolve) => {
1203
+ try {
1204
+ adapter(config, buildAdapterRequestContext(nativeAdapterRequestContext)).then((data) => {
1205
+ resolve({ data, error: undefined });
1206
+ }, (error) => {
1207
+ resolve({ data: undefined, error });
1208
+ });
1209
+ }
1210
+ catch (err) {
1211
+ resolve(buildInvalidConfigError(err));
1212
+ }
1213
+ });
1214
+ }
1215
+ }
1216
+
1121
1217
  if (process.env.NODE_ENV !== 'production') {
1122
1218
  // eslint-disable-next-line no-undef
1123
1219
  withDefaultLuvio((luvio) => {
@@ -1127,5 +1223,5 @@ if (process.env.NODE_ENV !== 'production') {
1127
1223
  });
1128
1224
  }
1129
1225
 
1130
- export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, invokeAdapter, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1131
- // version: 1.361.0-6a70680f2b
1226
+ export { createPrimingSession, draftManager, draftQueue, evictCacheRecordsByIds, evictExpiredCacheEntries, executeAdapter, executeMutatingAdapter, getImperativeAdapterNames, importLuvioAdapterModule, invokeAdapter, invokeAdapterWithDraftToMerge, invokeAdapterWithDraftToReplace, invokeAdapterWithMetadata, nimbusDraftQueue, setMetadataTTL, setUiApiRecordTTL, stopEviction, subscribeToAdapter };
1227
+ // version: 1.363.0-99132bb508
@@ -0,0 +1,13 @@
1
+ import type { Unsubscribe } from '@luvio/engine';
2
+ import { NativeAdapterRequestContext, type NativeCallbackValue, type NativeOnSnapshot } from './executeAdapter';
3
+ import { type ImperativeAdapterMapValue, type AdapterMapValue } from './lightningAdapterApi';
4
+ export declare function importLuvioAdapterModule(specifier: string): Promise<LuvioAdapterModule>;
5
+ declare class LuvioAdapterModule {
6
+ imperativeAdapterMap: Record<string, ImperativeAdapterMapValue>;
7
+ dmlAdapterMap: Record<string, AdapterMapValue>;
8
+ constructor(module: any);
9
+ invokeAdapter<Config>(adapterName: string, config: Config, nativeAdapterRequestContext?: NativeAdapterRequestContext): Promise<NativeCallbackValue>;
10
+ subscribeAdapter<Config>(adapterName: string, config: Config, nativeAdapterRequestContext: NativeAdapterRequestContext, callback: NativeOnSnapshot): Unsubscribe;
11
+ private invokeDmlAdapter;
12
+ }
13
+ export {};
@@ -1,4 +1,5 @@
1
1
  import type { AdapterRequestContext, CachePolicy, LuvioAdapterEventObserver } from '@luvio/engine';
2
+ import type { DataCallbackTuple } from '@salesforce/lds-bindings';
2
3
  import type { DraftQueueItemMetadata } from '@salesforce/lds-drafts';
3
4
  import type { NativeErrorResponse } from './responses';
4
5
  import type { ObservabilityContext } from '@salesforce/lds-runtime-mobile';
@@ -21,12 +22,12 @@ export type NativeCallbackErrors = {
21
22
  };
22
23
  export type NativeOnSnapshot = (value: NativeCallbackValue) => void;
23
24
  export type NativeOnResponse = (value: NativeCallbackValue) => void;
24
- type Unsubscribe = () => void;
25
+ export type Unsubscribe = () => void;
25
26
  type NativeCachePolicy = CachePolicy;
26
27
  type NativeAdapterRequestPriority = 'high' | 'normal' | 'background';
27
28
  type NativeObservabilityContext = ObservabilityContext;
28
29
  type NativeLuvioEventObserver = LuvioAdapterEventObserver;
29
- interface NativeAdapterRequestContext {
30
+ export interface NativeAdapterRequestContext {
30
31
  cachePolicy?: NativeCachePolicy;
31
32
  priority?: NativeAdapterRequestPriority;
32
33
  observabilityContext?: NativeObservabilityContext;
@@ -38,6 +39,8 @@ interface NativeAdapterRequestContext {
38
39
  * @returns Coerced luvio request context
39
40
  */
40
41
  export declare function buildAdapterRequestContext(nativeRequestContext: NativeAdapterRequestContext | undefined): AdapterRequestContext | undefined;
42
+ export declare function buildInvalidConfigError(error: unknown): NativeCallbackError;
43
+ export declare function buildNativeCallbackValue(adapterCallbackValue: DataCallbackTuple<unknown>): NativeCallbackValue;
41
44
  /**
42
45
  * Executes the adapter with the given adapterId and config. Will call onSnapshot
43
46
  * callback with data or error. Returns an unsubscribe function that should
@@ -3,8 +3,12 @@ import type { Adapter } from '@luvio/engine';
3
3
  import * as gqlApi from 'force/ldsAdaptersGraphql';
4
4
  export declare const IMPERATIVE_ADAPTER_SUFFIX = "_imperative";
5
5
  export declare const UNSTABLE_ADAPTER_PREFIX = "unstable_";
6
- type AdapterMapValue = Adapter<unknown, unknown> | ImperativeAdapter<unknown, unknown> | undefined;
7
- type ImperativeAdapterMapValue = ImperativeAdapter<unknown, unknown> | undefined;
6
+ export type AdapterMapValue = Adapter<unknown, unknown> | ImperativeAdapter<unknown, unknown> | undefined;
7
+ export type ImperativeAdapterMapValue = ImperativeAdapter<unknown, unknown> | undefined;
8
+ export declare function buildAdapterMaps(map: Record<string, AdapterMapValue>): {
9
+ dmlAdapterMap: Record<string, AdapterMapValue>;
10
+ imperativeAdapterMap: Record<string, ImperativeAdapterMapValue>;
11
+ };
8
12
  declare function getDMLAdapterFromName(name: string): AdapterMapValue;
9
13
  declare function getImperativeAdapterFromName(name: string): ImperativeAdapterMapValue;
10
14
  declare function getImperativeAdapterNames(): string[];
@@ -6,4 +6,5 @@ import { setUiApiRecordTTL, setMetadataTTL } from './ttl';
6
6
  import { registerReportObserver } from '@salesforce/lds-runtime-mobile';
7
7
  import { createPrimingSession } from './primingApi';
8
8
  import { evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction } from './cachePurging';
9
- export { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithDraftToMerge, executeAdapter, executeMutatingAdapter, nimbusDraftQueue, draftQueue, draftManager, setUiApiRecordTTL, setMetadataTTL, registerReportObserver, getImperativeAdapterNames, createPrimingSession, evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction, };
9
+ import { importLuvioAdapterModule } from './customLuvioAdapter';
10
+ export { subscribeToAdapter, invokeAdapter, invokeAdapterWithMetadata, invokeAdapterWithDraftToReplace, invokeAdapterWithDraftToMerge, executeAdapter, executeMutatingAdapter, nimbusDraftQueue, draftQueue, draftManager, setUiApiRecordTTL, setMetadataTTL, registerReportObserver, getImperativeAdapterNames, createPrimingSession, evictCacheRecordsByIds, evictExpiredCacheEntries, stopEviction, importLuvioAdapterModule, };