Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion addons/dexie-cloud/src/DexieCloudOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface DexieCloudOptions {
*/
blobMode?: 'eager' | 'lazy';

/** Maximum string length (in characters) before offloading to blob storage during sync.
/** String length threshold (in characters) for offloading to blob storage during sync.
*
* Strings longer than this threshold are uploaded as blobs during sync,
* reducing sync payload size. The original string is kept intact in IndexedDB.
Expand All @@ -99,5 +99,10 @@ export interface DexieCloudOptions {
*
* @default 32768
*/
largeStringThreshold?: number;

/**
* @deprecated Use `largeStringThreshold` instead.
*/
maxStringLength?: number;
}
30 changes: 22 additions & 8 deletions addons/dexie-cloud/src/dexie-cloud-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,35 @@ export function dexieCloud(dexie: Dexie) {
invites: getInvitesObservable(dexie),
roles: getGlobalRolesObservable(dexie),
configure(options: DexieCloudOptions) {
// Validate maxStringLength — Infinity disables offloading, otherwise must be
// a finite number between 100 and the server limit (32768).
// Validate largeStringThreshold (preferred) or maxStringLength (deprecated) —
// Infinity disables offloading, otherwise must be a finite number between 100
// and the server limit (32768).
// Minimum 100 prevents accidental offloading of primary keys and short strings
// that would break sync.
const MIN_STRING_LENGTH = 100;
const MAX_SERVER_STRING_LENGTH = 32768;
if (options.maxStringLength !== undefined) {
console.warn(
'maxStringLength is deprecated, use largeStringThreshold instead'
);
// If largeStringThreshold is not explicitly set, migrate to new name
if (options.largeStringThreshold === undefined) {
options = {
...options,
largeStringThreshold: options.maxStringLength,
};
}
}
const thresholdValue = options.largeStringThreshold;
if (
options.maxStringLength !== undefined &&
options.maxStringLength !== Infinity &&
(!Number.isFinite(options.maxStringLength) ||
options.maxStringLength < MIN_STRING_LENGTH ||
options.maxStringLength > MAX_SERVER_STRING_LENGTH)
thresholdValue !== undefined &&
thresholdValue !== Infinity &&
(!Number.isFinite(thresholdValue) ||
thresholdValue < MIN_STRING_LENGTH ||
thresholdValue > MAX_SERVER_STRING_LENGTH)
) {
throw new Error(
`maxStringLength must be Infinity or a finite number in [${MIN_STRING_LENGTH}, ${MAX_SERVER_STRING_LENGTH}]. Got: ${options.maxStringLength}`
`largeStringThreshold must be Infinity or a finite number in [${MIN_STRING_LENGTH}, ${MAX_SERVER_STRING_LENGTH}]. Got: ${thresholdValue}`
);
}
options = dexie.cloud.options = { ...dexie.cloud.options, ...options };
Expand Down
5 changes: 4 additions & 1 deletion addons/dexie-cloud/src/sync/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ async function _sync(
// Offload large blobs to blob storage before sync
//
let processedChangeSet = clientChangeSet;
const maxStringLength = db.cloud.options?.maxStringLength ?? 32768;
const maxStringLength =
db.cloud.options?.largeStringThreshold ??
db.cloud.options?.maxStringLength ??
32768;
const hasLargeBlobs = hasLargeBlobsInOperations(
clientChangeSet,
maxStringLength
Expand Down
Loading