@salesforce/lds-runtime-mobile 1.328.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
@@ -42866,24 +42866,37 @@ function isCreateContentDocumentAndVersionDraftAdapterEvent(customEvent) {
42866
42866
  // so eslint doesn't complain about nimbus
42867
42867
  /* global __nimbus */
42868
42868
  function chunkToBase64(chunk) {
42869
- let binary = '';
42870
- const chunkSize = 32 * 1024;
42871
- for (let i = 0; i < chunk.length; i += chunkSize) {
42872
- binary += String.fromCharCode.apply(null, chunk.subarray(i, i + chunkSize));
42873
- }
42869
+ const bytes = new Uint8Array(chunk);
42870
+ const binary = String.fromCharCode.apply(null, bytes);
42874
42871
  return btoa(binary);
42875
42872
  }
42876
- async function streamBufferToBinaryStore(binaryStore, buffer, mimeType) {
42873
+ async function streamBufferToBinaryStore(binaryStore, file, mimeType) {
42877
42874
  const uri = await binaryStore.createStream(mimeType);
42878
- const bufferSize = 64 * 1024; // 64k buffer size
42879
- const uint8Array = new Uint8Array(buffer);
42880
- for (let offset = 0; offset < uint8Array.length; offset += bufferSize) {
42881
- const chunk = uint8Array.subarray(offset, Math.min(offset + bufferSize, uint8Array.length));
42882
- const base64Chunk = chunkToBase64(chunk);
42883
- 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;
42884
42893
  }
42885
- await binaryStore.closeStream(uri);
42886
- return uri;
42894
+ }
42895
+ function isFileLike(object) {
42896
+ return (object &&
42897
+ typeof object === 'object' &&
42898
+ typeof object.size === 'number' &&
42899
+ typeof object.slice === 'function');
42887
42900
  }
42888
42901
  function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore, actionHandler, durableRecordStore) {
42889
42902
  return async function createContentDocumentAndVersionDraftAdapter(config, buildResourceRequest, requestContext) {
@@ -42898,14 +42911,20 @@ function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore,
42898
42911
  if (!isFileReference(config.fileData)) {
42899
42912
  const { fileData } = config;
42900
42913
  const { name, size, type } = fileData;
42901
- const buffer = await fileData.arrayBuffer();
42902
- var uri;
42903
- // 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
42904
42916
  if (!__nimbus.plugins.LdsBinaryStorePlugin.createStream) {
42917
+ const buffer = await fileData.arrayBuffer();
42905
42918
  uri = await binaryStore.store(new Uint8Array(buffer), type, size);
42906
42919
  }
42920
+ else if (isFileLike(fileData)) {
42921
+ // Only pass to streamBufferToBinaryStore if it's FileLike
42922
+ uri = await streamBufferToBinaryStore(binaryStore, fileData, type);
42923
+ }
42907
42924
  else {
42908
- 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
+ }
42909
42928
  }
42910
42929
  config.fileData = {
42911
42930
  isFileReference: true,
@@ -55313,4 +55332,4 @@ register({
55313
55332
  });
55314
55333
 
55315
55334
  export { O11Y_NAMESPACE_LDS_MOBILE, getRuntime, registerReportObserver, reportGraphqlQueryParseError };
55316
- // version: 1.328.0-f3d79bc783
55335
+ // version: 1.329.0-9b52e8059d
@@ -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.328.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.328.0",
36
- "@salesforce/lds-bindings": "^1.328.0",
37
- "@salesforce/lds-instrumentation": "^1.328.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.328.0",
43
- "@salesforce/lds-drafts": "^1.328.0",
44
- "@salesforce/lds-durable-records": "^1.328.0",
45
- "@salesforce/lds-network-adapter": "^1.328.0",
46
- "@salesforce/lds-network-nimbus": "^1.328.0",
47
- "@salesforce/lds-store-binary": "^1.328.0",
48
- "@salesforce/lds-store-nimbus": "^1.328.0",
49
- "@salesforce/lds-store-sql": "^1.328.0",
50
- "@salesforce/lds-utils-adapters": "^1.328.0",
51
- "@salesforce/nimbus-plugin-lds": "^1.328.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
@@ -42866,24 +42866,37 @@ function isCreateContentDocumentAndVersionDraftAdapterEvent(customEvent) {
42866
42866
  // so eslint doesn't complain about nimbus
42867
42867
  /* global __nimbus */
42868
42868
  function chunkToBase64(chunk) {
42869
- let binary = '';
42870
- const chunkSize = 32 * 1024;
42871
- for (let i = 0; i < chunk.length; i += chunkSize) {
42872
- binary += String.fromCharCode.apply(null, chunk.subarray(i, i + chunkSize));
42873
- }
42869
+ const bytes = new Uint8Array(chunk);
42870
+ const binary = String.fromCharCode.apply(null, bytes);
42874
42871
  return btoa(binary);
42875
42872
  }
42876
- async function streamBufferToBinaryStore(binaryStore, buffer, mimeType) {
42873
+ async function streamBufferToBinaryStore(binaryStore, file, mimeType) {
42877
42874
  const uri = await binaryStore.createStream(mimeType);
42878
- const bufferSize = 64 * 1024; // 64k buffer size
42879
- const uint8Array = new Uint8Array(buffer);
42880
- for (let offset = 0; offset < uint8Array.length; offset += bufferSize) {
42881
- const chunk = uint8Array.subarray(offset, Math.min(offset + bufferSize, uint8Array.length));
42882
- const base64Chunk = chunkToBase64(chunk);
42883
- 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;
42884
42893
  }
42885
- await binaryStore.closeStream(uri);
42886
- return uri;
42894
+ }
42895
+ function isFileLike(object) {
42896
+ return (object &&
42897
+ typeof object === 'object' &&
42898
+ typeof object.size === 'number' &&
42899
+ typeof object.slice === 'function');
42887
42900
  }
42888
42901
  function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore, actionHandler, durableRecordStore) {
42889
42902
  return async function createContentDocumentAndVersionDraftAdapter(config, buildResourceRequest, requestContext) {
@@ -42898,14 +42911,20 @@ function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore,
42898
42911
  if (!isFileReference(config.fileData)) {
42899
42912
  const { fileData } = config;
42900
42913
  const { name, size, type } = fileData;
42901
- const buffer = await fileData.arrayBuffer();
42902
- var uri;
42903
- // 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
42904
42916
  if (!__nimbus.plugins.LdsBinaryStorePlugin.createStream) {
42917
+ const buffer = await fileData.arrayBuffer();
42905
42918
  uri = await binaryStore.store(new Uint8Array(buffer), type, size);
42906
42919
  }
42920
+ else if (isFileLike(fileData)) {
42921
+ // Only pass to streamBufferToBinaryStore if it's FileLike
42922
+ uri = await streamBufferToBinaryStore(binaryStore, fileData, type);
42923
+ }
42907
42924
  else {
42908
- 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
+ }
42909
42928
  }
42910
42929
  config.fileData = {
42911
42930
  isFileReference: true,
@@ -55313,4 +55332,4 @@ register({
55313
55332
  });
55314
55333
 
55315
55334
  export { O11Y_NAMESPACE_LDS_MOBILE, getRuntime, registerReportObserver, reportGraphqlQueryParseError };
55316
- // version: 1.328.0-f3d79bc783
55335
+ // version: 1.329.0-9b52e8059d
@@ -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;