@salesforce/lds-runtime-mobile 1.327.0 → 1.329.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/main.js CHANGED
@@ -2126,6 +2126,12 @@ class DurableDraftQueue {
2126
2126
  draftCount: this.draftStore.getCount(),
2127
2127
  });
2128
2128
  }
2129
+ stopQueueWhileRunning(action) {
2130
+ this.stopQueueManually(true);
2131
+ return action().finally(() => {
2132
+ this.startQueueSafe();
2133
+ });
2134
+ }
2129
2135
  /**
2130
2136
  * Used to stop the queue within DraftQueue without user interaction
2131
2137
  */
@@ -2910,6 +2916,14 @@ class DraftManager {
2910
2916
  stopQueue() {
2911
2917
  return this.draftQueue.stopQueue();
2912
2918
  }
2919
+ /**
2920
+ * Stops the draft queue manually without notifying the user and then runs the passed action.
2921
+ * After the action is completed it will safely start the queue if the user had set it to be
2922
+ * started.
2923
+ */
2924
+ stopQueueWhileRunning(action) {
2925
+ return this.draftQueue.stopQueueWhileRunning(action);
2926
+ }
2913
2927
  /**
2914
2928
  * Subscribes the listener to changes to the draft queue.
2915
2929
  *
@@ -42852,24 +42866,37 @@ function isCreateContentDocumentAndVersionDraftAdapterEvent(customEvent) {
42852
42866
  // so eslint doesn't complain about nimbus
42853
42867
  /* global __nimbus */
42854
42868
  function chunkToBase64(chunk) {
42855
- let binary = '';
42856
- const chunkSize = 32 * 1024;
42857
- for (let i = 0; i < chunk.length; i += chunkSize) {
42858
- binary += String.fromCharCode.apply(null, chunk.subarray(i, i + chunkSize));
42859
- }
42869
+ const bytes = new Uint8Array(chunk);
42870
+ const binary = String.fromCharCode.apply(null, bytes);
42860
42871
  return btoa(binary);
42861
42872
  }
42862
- async function streamBufferToBinaryStore(binaryStore, buffer, mimeType) {
42873
+ async function streamBufferToBinaryStore(binaryStore, file, mimeType) {
42863
42874
  const uri = await binaryStore.createStream(mimeType);
42864
- const bufferSize = 64 * 1024; // 64k buffer size
42865
- const uint8Array = new Uint8Array(buffer);
42866
- for (let offset = 0; offset < uint8Array.length; offset += bufferSize) {
42867
- const chunk = uint8Array.subarray(offset, Math.min(offset + bufferSize, uint8Array.length));
42868
- const base64Chunk = chunkToBase64(chunk);
42869
- await binaryStore.writeToStream(uri, base64Chunk);
42875
+ const CHUNK_SIZE = 64 * 1024; // 64KB
42876
+ const fileSize = file.size;
42877
+ let offset = 0;
42878
+ try {
42879
+ while (offset < fileSize) {
42880
+ const end = Math.min(offset + CHUNK_SIZE, fileSize);
42881
+ const chunk = file.slice(offset, end);
42882
+ const arrayBuffer = await chunk.arrayBuffer();
42883
+ const base64Chunk = chunkToBase64(arrayBuffer);
42884
+ await binaryStore.writeToStream(uri, base64Chunk);
42885
+ offset = end;
42886
+ }
42887
+ await binaryStore.closeStream(uri);
42888
+ return uri;
42889
+ }
42890
+ catch (error) {
42891
+ await binaryStore.closeStream(uri);
42892
+ throw error;
42870
42893
  }
42871
- await binaryStore.closeStream(uri);
42872
- return uri;
42894
+ }
42895
+ function isFileLike(object) {
42896
+ return (object &&
42897
+ typeof object === 'object' &&
42898
+ typeof object.size === 'number' &&
42899
+ typeof object.slice === 'function');
42873
42900
  }
42874
42901
  function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore, actionHandler, durableRecordStore) {
42875
42902
  return async function createContentDocumentAndVersionDraftAdapter(config, buildResourceRequest, requestContext) {
@@ -42884,14 +42911,20 @@ function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore,
42884
42911
  if (!isFileReference(config.fileData)) {
42885
42912
  const { fileData } = config;
42886
42913
  const { name, size, type } = fileData;
42887
- const buffer = await fileData.arrayBuffer();
42888
- var uri;
42889
- // see if new chunking-api exists, if it doesnt fall back to memory-intensive mobile api
42914
+ let uri = ''; // Initialize uri with an empty string
42915
+ // Check if chunking API exists, fallback if it doesn't
42890
42916
  if (!__nimbus.plugins.LdsBinaryStorePlugin.createStream) {
42917
+ const buffer = await fileData.arrayBuffer();
42891
42918
  uri = await binaryStore.store(new Uint8Array(buffer), type, size);
42892
42919
  }
42920
+ else if (isFileLike(fileData)) {
42921
+ // Only pass to streamBufferToBinaryStore if it's FileLike
42922
+ uri = await streamBufferToBinaryStore(binaryStore, fileData, type);
42923
+ }
42893
42924
  else {
42894
- uri = await streamBufferToBinaryStore(binaryStore, buffer, type);
42925
+ if (process.env.NODE_ENV !== 'production') {
42926
+ throw new Error('fileData does not support streaming and cannot be processed with createStream API');
42927
+ }
42895
42928
  }
42896
42929
  config.fileData = {
42897
42930
  isFileReference: true,
@@ -49291,18 +49324,6 @@ function createSeenRecords(ids, currentSnapshot) {
49291
49324
  }
49292
49325
  return seenRecords;
49293
49326
  }
49294
- function createErrorSnapshot(result, snapshot) {
49295
- return {
49296
- ...snapshot,
49297
- data: undefined,
49298
- state: 'Error',
49299
- error: {
49300
- body: {
49301
- message: result.errors,
49302
- },
49303
- },
49304
- };
49305
- }
49306
49327
  function createLocalEvalSnapshot(data, seenRecords, recordId, rebuildWithLocalEval, refresh) {
49307
49328
  return {
49308
49329
  refresh,
@@ -49820,7 +49841,18 @@ function draftAwareGraphQLAdapterFactory(userId, objectInfoService, store, luvio
49820
49841
  // currently by design if there are any graphql errors we return an ErrorSnapshot
49821
49842
  // partial results are not supported at this time
49822
49843
  if (gqlResult.errors !== undefined && gqlResult.errors.length > 0) {
49823
- return createErrorSnapshot(gqlResult, nonEvaluatedSnapshot);
49844
+ const errors = gqlResult.errors || [];
49845
+ let responseErrors = errors.map((e) => {
49846
+ return { message: e instanceof Error ? e.message : String(e) };
49847
+ });
49848
+ return {
49849
+ data: undefined,
49850
+ state: 'Error',
49851
+ error: {
49852
+ errorType: 'adapterError',
49853
+ error: responseErrors,
49854
+ },
49855
+ };
49824
49856
  }
49825
49857
  // if the non-eval'ed snapshot was an error then we return a synthetic
49826
49858
  // Fulfilled snapshot (this only happens in this code path if
@@ -50996,6 +51028,9 @@ class NimbusDraftQueue {
50996
51028
  stopQueue() {
50997
51029
  return Promise.reject(new Error('Cannot call stopQueue from the NimbusDraftQueue'));
50998
51030
  }
51031
+ stopQueueWhileRunning(_action) {
51032
+ return Promise.reject(new Error('Cannot call stopQueueWhileRunning from the NimbusDraftQueue'));
51033
+ }
50999
51034
  replaceAction(_actionId, _withActionId) {
51000
51035
  return Promise.reject(new Error('Cannot call replaceAction from the NimbusDraftQueue'));
51001
51036
  }
@@ -55297,4 +55332,4 @@ register({
55297
55332
  });
55298
55333
 
55299
55334
  export { O11Y_NAMESPACE_LDS_MOBILE, getRuntime, registerReportObserver, reportGraphqlQueryParseError };
55300
- // version: 1.327.0-8614d511e1
55335
+ // version: 1.329.0-9b52e8059d
@@ -16,6 +16,7 @@ export declare class NimbusDraftQueue implements DraftQueue {
16
16
  removeDraftAction(_actionId: string): Promise<void>;
17
17
  startQueue(): Promise<void>;
18
18
  stopQueue(): Promise<void>;
19
+ stopQueueWhileRunning(_action: () => Promise<void>): Promise<void>;
19
20
  replaceAction<Data, Response>(_actionId: string, _withActionId: string): Promise<DraftAction<Data, Response>>;
20
21
  mergeActions<Data, Response>(_targetActionId: string, _sourceActionId: string): Promise<DraftAction<Data, Response>>;
21
22
  retryAction<Data, Response>(_actionId: string): Promise<DraftAction<Data, Response>>;
@@ -3,4 +3,8 @@ import type { BinaryStore } from '@salesforce/lds-store-binary';
3
3
  import type { DraftAwareCreateContentDocumentAndVersionAdapter } from '@salesforce/lds-adapters-uiapi';
4
4
  import type { ContentDocumentCompositeRepresentationActionHandler } from '../../ContentDocumentCompositeRepresentationActionHandler';
5
5
  import type { DurableRecordStore } from '../../../../durableStore/DurableRecordStore';
6
+ export interface FileLike {
7
+ size: number;
8
+ slice(start: number, end: number, contentType?: string): Blob;
9
+ }
6
10
  export declare function createContentDocumentAndVersionDraftAdapterFactory(luvio: Luvio, binaryStore: BinaryStore, actionHandler: ContentDocumentCompositeRepresentationActionHandler, durableRecordStore: DurableRecordStore): DraftAwareCreateContentDocumentAndVersionAdapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-mobile",
3
- "version": "1.327.0",
3
+ "version": "1.329.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS runtime for mobile/hybrid environments.",
6
6
  "main": "dist/main.js",
@@ -32,23 +32,23 @@
32
32
  "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-runtime-mobile"
33
33
  },
34
34
  "dependencies": {
35
- "@salesforce/lds-adapters-uiapi": "^1.327.0",
36
- "@salesforce/lds-bindings": "^1.327.0",
37
- "@salesforce/lds-instrumentation": "^1.327.0",
35
+ "@salesforce/lds-adapters-uiapi": "^1.329.0",
36
+ "@salesforce/lds-bindings": "^1.329.0",
37
+ "@salesforce/lds-instrumentation": "^1.329.0",
38
38
  "@salesforce/user": "0.0.21",
39
39
  "o11y": "250.7.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@salesforce/lds-adapters-graphql": "^1.327.0",
43
- "@salesforce/lds-drafts": "^1.327.0",
44
- "@salesforce/lds-durable-records": "^1.327.0",
45
- "@salesforce/lds-network-adapter": "^1.327.0",
46
- "@salesforce/lds-network-nimbus": "^1.327.0",
47
- "@salesforce/lds-store-binary": "^1.327.0",
48
- "@salesforce/lds-store-nimbus": "^1.327.0",
49
- "@salesforce/lds-store-sql": "^1.327.0",
50
- "@salesforce/lds-utils-adapters": "^1.327.0",
51
- "@salesforce/nimbus-plugin-lds": "^1.327.0",
42
+ "@salesforce/lds-adapters-graphql": "^1.329.0",
43
+ "@salesforce/lds-drafts": "^1.329.0",
44
+ "@salesforce/lds-durable-records": "^1.329.0",
45
+ "@salesforce/lds-network-adapter": "^1.329.0",
46
+ "@salesforce/lds-network-nimbus": "^1.329.0",
47
+ "@salesforce/lds-store-binary": "^1.329.0",
48
+ "@salesforce/lds-store-nimbus": "^1.329.0",
49
+ "@salesforce/lds-store-sql": "^1.329.0",
50
+ "@salesforce/lds-utils-adapters": "^1.329.0",
51
+ "@salesforce/nimbus-plugin-lds": "^1.329.0",
52
52
  "babel-plugin-dynamic-import-node": "^2.3.3",
53
53
  "wait-for-expect": "^3.0.2"
54
54
  },
package/sfdc/main.js CHANGED
@@ -2126,6 +2126,12 @@ class DurableDraftQueue {
2126
2126
  draftCount: this.draftStore.getCount(),
2127
2127
  });
2128
2128
  }
2129
+ stopQueueWhileRunning(action) {
2130
+ this.stopQueueManually(true);
2131
+ return action().finally(() => {
2132
+ this.startQueueSafe();
2133
+ });
2134
+ }
2129
2135
  /**
2130
2136
  * Used to stop the queue within DraftQueue without user interaction
2131
2137
  */
@@ -2910,6 +2916,14 @@ class DraftManager {
2910
2916
  stopQueue() {
2911
2917
  return this.draftQueue.stopQueue();
2912
2918
  }
2919
+ /**
2920
+ * Stops the draft queue manually without notifying the user and then runs the passed action.
2921
+ * After the action is completed it will safely start the queue if the user had set it to be
2922
+ * started.
2923
+ */
2924
+ stopQueueWhileRunning(action) {
2925
+ return this.draftQueue.stopQueueWhileRunning(action);
2926
+ }
2913
2927
  /**
2914
2928
  * Subscribes the listener to changes to the draft queue.
2915
2929
  *
@@ -42852,24 +42866,37 @@ function isCreateContentDocumentAndVersionDraftAdapterEvent(customEvent) {
42852
42866
  // so eslint doesn't complain about nimbus
42853
42867
  /* global __nimbus */
42854
42868
  function chunkToBase64(chunk) {
42855
- let binary = '';
42856
- const chunkSize = 32 * 1024;
42857
- for (let i = 0; i < chunk.length; i += chunkSize) {
42858
- binary += String.fromCharCode.apply(null, chunk.subarray(i, i + chunkSize));
42859
- }
42869
+ const bytes = new Uint8Array(chunk);
42870
+ const binary = String.fromCharCode.apply(null, bytes);
42860
42871
  return btoa(binary);
42861
42872
  }
42862
- async function streamBufferToBinaryStore(binaryStore, buffer, mimeType) {
42873
+ async function streamBufferToBinaryStore(binaryStore, file, mimeType) {
42863
42874
  const uri = await binaryStore.createStream(mimeType);
42864
- const bufferSize = 64 * 1024; // 64k buffer size
42865
- const uint8Array = new Uint8Array(buffer);
42866
- for (let offset = 0; offset < uint8Array.length; offset += bufferSize) {
42867
- const chunk = uint8Array.subarray(offset, Math.min(offset + bufferSize, uint8Array.length));
42868
- const base64Chunk = chunkToBase64(chunk);
42869
- await binaryStore.writeToStream(uri, base64Chunk);
42875
+ const CHUNK_SIZE = 64 * 1024; // 64KB
42876
+ const fileSize = file.size;
42877
+ let offset = 0;
42878
+ try {
42879
+ while (offset < fileSize) {
42880
+ const end = Math.min(offset + CHUNK_SIZE, fileSize);
42881
+ const chunk = file.slice(offset, end);
42882
+ const arrayBuffer = await chunk.arrayBuffer();
42883
+ const base64Chunk = chunkToBase64(arrayBuffer);
42884
+ await binaryStore.writeToStream(uri, base64Chunk);
42885
+ offset = end;
42886
+ }
42887
+ await binaryStore.closeStream(uri);
42888
+ return uri;
42889
+ }
42890
+ catch (error) {
42891
+ await binaryStore.closeStream(uri);
42892
+ throw error;
42870
42893
  }
42871
- await binaryStore.closeStream(uri);
42872
- return uri;
42894
+ }
42895
+ function isFileLike(object) {
42896
+ return (object &&
42897
+ typeof object === 'object' &&
42898
+ typeof object.size === 'number' &&
42899
+ typeof object.slice === 'function');
42873
42900
  }
42874
42901
  function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore, actionHandler, durableRecordStore) {
42875
42902
  return async function createContentDocumentAndVersionDraftAdapter(config, buildResourceRequest, requestContext) {
@@ -42884,14 +42911,20 @@ function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore,
42884
42911
  if (!isFileReference(config.fileData)) {
42885
42912
  const { fileData } = config;
42886
42913
  const { name, size, type } = fileData;
42887
- const buffer = await fileData.arrayBuffer();
42888
- var uri;
42889
- // see if new chunking-api exists, if it doesnt fall back to memory-intensive mobile api
42914
+ let uri = ''; // Initialize uri with an empty string
42915
+ // Check if chunking API exists, fallback if it doesn't
42890
42916
  if (!__nimbus.plugins.LdsBinaryStorePlugin.createStream) {
42917
+ const buffer = await fileData.arrayBuffer();
42891
42918
  uri = await binaryStore.store(new Uint8Array(buffer), type, size);
42892
42919
  }
42920
+ else if (isFileLike(fileData)) {
42921
+ // Only pass to streamBufferToBinaryStore if it's FileLike
42922
+ uri = await streamBufferToBinaryStore(binaryStore, fileData, type);
42923
+ }
42893
42924
  else {
42894
- uri = await streamBufferToBinaryStore(binaryStore, buffer, type);
42925
+ if (process.env.NODE_ENV !== 'production') {
42926
+ throw new Error('fileData does not support streaming and cannot be processed with createStream API');
42927
+ }
42895
42928
  }
42896
42929
  config.fileData = {
42897
42930
  isFileReference: true,
@@ -49291,18 +49324,6 @@ function createSeenRecords(ids, currentSnapshot) {
49291
49324
  }
49292
49325
  return seenRecords;
49293
49326
  }
49294
- function createErrorSnapshot(result, snapshot) {
49295
- return {
49296
- ...snapshot,
49297
- data: undefined,
49298
- state: 'Error',
49299
- error: {
49300
- body: {
49301
- message: result.errors,
49302
- },
49303
- },
49304
- };
49305
- }
49306
49327
  function createLocalEvalSnapshot(data, seenRecords, recordId, rebuildWithLocalEval, refresh) {
49307
49328
  return {
49308
49329
  refresh,
@@ -49820,7 +49841,18 @@ function draftAwareGraphQLAdapterFactory(userId, objectInfoService, store, luvio
49820
49841
  // currently by design if there are any graphql errors we return an ErrorSnapshot
49821
49842
  // partial results are not supported at this time
49822
49843
  if (gqlResult.errors !== undefined && gqlResult.errors.length > 0) {
49823
- return createErrorSnapshot(gqlResult, nonEvaluatedSnapshot);
49844
+ const errors = gqlResult.errors || [];
49845
+ let responseErrors = errors.map((e) => {
49846
+ return { message: e instanceof Error ? e.message : String(e) };
49847
+ });
49848
+ return {
49849
+ data: undefined,
49850
+ state: 'Error',
49851
+ error: {
49852
+ errorType: 'adapterError',
49853
+ error: responseErrors,
49854
+ },
49855
+ };
49824
49856
  }
49825
49857
  // if the non-eval'ed snapshot was an error then we return a synthetic
49826
49858
  // Fulfilled snapshot (this only happens in this code path if
@@ -50996,6 +51028,9 @@ class NimbusDraftQueue {
50996
51028
  stopQueue() {
50997
51029
  return Promise.reject(new Error('Cannot call stopQueue from the NimbusDraftQueue'));
50998
51030
  }
51031
+ stopQueueWhileRunning(_action) {
51032
+ return Promise.reject(new Error('Cannot call stopQueueWhileRunning from the NimbusDraftQueue'));
51033
+ }
50999
51034
  replaceAction(_actionId, _withActionId) {
51000
51035
  return Promise.reject(new Error('Cannot call replaceAction from the NimbusDraftQueue'));
51001
51036
  }
@@ -55297,4 +55332,4 @@ register({
55297
55332
  });
55298
55333
 
55299
55334
  export { O11Y_NAMESPACE_LDS_MOBILE, getRuntime, registerReportObserver, reportGraphqlQueryParseError };
55300
- // version: 1.327.0-8614d511e1
55335
+ // version: 1.329.0-9b52e8059d
@@ -16,6 +16,7 @@ export declare class NimbusDraftQueue implements DraftQueue {
16
16
  removeDraftAction(_actionId: string): Promise<void>;
17
17
  startQueue(): Promise<void>;
18
18
  stopQueue(): Promise<void>;
19
+ stopQueueWhileRunning(_action: () => Promise<void>): Promise<void>;
19
20
  replaceAction<Data, Response>(_actionId: string, _withActionId: string): Promise<DraftAction<Data, Response>>;
20
21
  mergeActions<Data, Response>(_targetActionId: string, _sourceActionId: string): Promise<DraftAction<Data, Response>>;
21
22
  retryAction<Data, Response>(_actionId: string): Promise<DraftAction<Data, Response>>;
@@ -3,4 +3,8 @@ import type { BinaryStore } from '@salesforce/lds-store-binary';
3
3
  import type { DraftAwareCreateContentDocumentAndVersionAdapter } from '@salesforce/lds-adapters-uiapi';
4
4
  import type { ContentDocumentCompositeRepresentationActionHandler } from '../../ContentDocumentCompositeRepresentationActionHandler';
5
5
  import type { DurableRecordStore } from '../../../../durableStore/DurableRecordStore';
6
+ export interface FileLike {
7
+ size: number;
8
+ slice(start: number, end: number, contentType?: string): Blob;
9
+ }
6
10
  export declare function createContentDocumentAndVersionDraftAdapterFactory(luvio: Luvio, binaryStore: BinaryStore, actionHandler: ContentDocumentCompositeRepresentationActionHandler, durableRecordStore: DurableRecordStore): DraftAwareCreateContentDocumentAndVersionAdapter;