dexie 4.1.0-alpha.12 → 4.1.0-alpha.23

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/dexie.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.1.0-alpha.12, Wed Oct 16 2024
7
+ * Version 4.1.0-alpha.23, Wed Nov 27 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -364,6 +364,119 @@ export interface PromiseExtended<T = any> extends Promise<T> {
364
364
  finally<U>(onFinally?: () => U | PromiseLike<U>): PromiseExtended<T>;
365
365
  timeout(ms: number, msg?: string): PromiseExtended<T>;
366
366
  }
367
+ export type KeyPathIgnoreObject = ArrayBuffer | ArrayBufferView | RegExp | Blob | FileList | FileSystemFileHandle | FileSystemDirectoryHandle | DataView | ImageBitmap | ImageData | Map<any, any> | Set<any> | CryptoKey | Promise<any> | ReadableStream<any> | ReadableStreamDefaultReader<any> | ReadableStreamDefaultController<any> | {
368
+ whenLoaded: Promise<any>;
369
+ }; // Y.Doc
370
+ export type KeyPaths<T, MAXDEPTH = "II", CURRDEPTH extends string = ""> = {
371
+ [P in keyof T]: P extends string ? CURRDEPTH extends MAXDEPTH ? P : T[P] extends Array<infer K> ? K extends any[] // Array of arrays (issue #2026)
372
+ ? P | `${P}.${number}` | `${P}.${number}.${number}` : K extends object // only drill into the array element if it's an object
373
+ ? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<Required<K>>}` : P | `${P}.${number}` : T[P] extends (...args: any[]) => any // Method
374
+ ? never : T[P] extends KeyPathIgnoreObject // Not valid in update spec or where clause (+ avoid circular reference)
375
+ ? P : T[P] extends object ? P | `${P}.${KeyPaths<Required<T[P]>, MAXDEPTH, `${CURRDEPTH}I`>}` : P : never;
376
+ }[keyof T];
377
+ export type KeyPathValue<T, PATH> = PATH extends `${infer R}.${infer S}` ? R extends keyof T ? KeyPathValue<Required<T[R]>, S> : T extends any[] ? PATH extends `${number}.${infer S}` ? KeyPathValue<Required<T[number]>, S> : void : void : PATH extends `${number}` ? T extends any[] ? T[number] : void : PATH extends keyof T ? T[PATH] : any;
378
+ export declare const PropModSymbol: unique symbol;
379
+ export type PropModSpec = {
380
+ replacePrefix?: [
381
+ string,
382
+ string
383
+ ];
384
+ add?: number | bigint | Array<string | number>;
385
+ remove?: number | bigint | Array<string | number>;
386
+ };
387
+ export class PropModification implements PropModSpec {
388
+ [PropModSymbol]?: true;
389
+ replacePrefix?: [
390
+ string,
391
+ string
392
+ ];
393
+ add?: number | bigint | Array<string | number>;
394
+ remove?: number | bigint | Array<string | number>;
395
+ execute<T>(value: T): T;
396
+ constructor(spec: PropModSpec);
397
+ }
398
+ export type UpdateSpec<T> = {
399
+ [KP in KeyPaths<Required<T>>]?: KeyPathValue<Required<T>, KP> | PropModification;
400
+ };
401
+ export interface Collection<T = any, TKey = IndexableType, TInsertType = T> {
402
+ db: Dexie;
403
+ and(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
404
+ clone(props?: Object): Collection<T, TKey, TInsertType>;
405
+ count(): PromiseExtended<number>;
406
+ count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>;
407
+ distinct(): Collection<T, TKey, TInsertType>;
408
+ each(callback: (obj: T, cursor: {
409
+ key: IndexableType;
410
+ primaryKey: TKey;
411
+ }) => any): PromiseExtended<void>;
412
+ eachKey(callback: (key: IndexableType, cursor: {
413
+ key: IndexableType;
414
+ primaryKey: TKey;
415
+ }) => any): PromiseExtended<void>;
416
+ eachPrimaryKey(callback: (key: TKey, cursor: {
417
+ key: IndexableType;
418
+ primaryKey: TKey;
419
+ }) => any): PromiseExtended<void>;
420
+ eachUniqueKey(callback: (key: IndexableType, cursor: {
421
+ key: IndexableType;
422
+ primaryKey: TKey;
423
+ }) => any): PromiseExtended<void>;
424
+ filter<S extends T>(filter: (x: T) => x is S): Collection<S, TKey>;
425
+ filter(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
426
+ first(): PromiseExtended<T | undefined>;
427
+ first<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
428
+ keys(): PromiseExtended<IndexableTypeArray>;
429
+ keys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
430
+ primaryKeys(): PromiseExtended<TKey[]>;
431
+ primaryKeys<R>(thenShortcut: ThenShortcut<TKey[], R>): PromiseExtended<R>;
432
+ last(): PromiseExtended<T | undefined>;
433
+ last<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
434
+ limit(n: number): Collection<T, TKey, TInsertType>;
435
+ offset(n: number): Collection<T, TKey, TInsertType>;
436
+ or(indexOrPrimayKey: string): WhereClause<T, TKey, TInsertType>;
437
+ raw(): Collection<T, TKey, TInsertType>;
438
+ reverse(): Collection<T, TKey, TInsertType>;
439
+ sortBy(keyPath: string): PromiseExtended<T[]>;
440
+ sortBy<R>(keyPath: string, thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
441
+ toArray(): PromiseExtended<Array<T>>;
442
+ toArray<R>(thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
443
+ uniqueKeys(): PromiseExtended<IndexableTypeArray>;
444
+ uniqueKeys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
445
+ until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection<T, TKey, TInsertType>;
446
+ // Mutating methods
447
+ delete(): PromiseExtended<number>;
448
+ modify(changeCallback: (obj: T, ctx: {
449
+ value: TInsertType;
450
+ }) => void | boolean): PromiseExtended<number>;
451
+ modify(changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
452
+ }
453
+ export type IntervalTree = IntervalTreeNode | EmptyRange;
454
+ export interface IntervalTreeNode {
455
+ from: IndexableType; // lower bound
456
+ to: IndexableType; // upper bound
457
+ l?: IntervalTreeNode | null; // left
458
+ r?: IntervalTreeNode | null; // right
459
+ d: number; // depth
460
+ }
461
+ export interface EmptyRange {
462
+ d: 0;
463
+ }
464
+ export interface RangeSetPrototype {
465
+ add(rangeSet: IntervalTree | {
466
+ from: IndexableType;
467
+ to: IndexableType;
468
+ }): RangeSet;
469
+ addKey(key: IndexableType): RangeSet;
470
+ addKeys(keys: IndexableType[]): RangeSet;
471
+ hasKey(key: IndexableType): boolean;
472
+ [Symbol.iterator](): Iterator<IntervalTreeNode, undefined, IndexableType | undefined>;
473
+ }
474
+ export type RangeSet = RangeSetPrototype & IntervalTree;
475
+ export interface RangeSetConstructor {
476
+ (tree: IntervalTree): RangeSet;
477
+ new (): RangeSet;
478
+ new (from: IndexableType, to?: IndexableType): RangeSet;
479
+ }
367
480
  // There typings are extracted from https://github.com/tc39/proposal-observable
368
481
  declare global {
369
482
  interface SymbolConstructor {
@@ -530,116 +643,6 @@ export interface YDocCache {
530
643
  add: (doc: YjsDoc) => void;
531
644
  delete: (doc: YjsDoc) => void;
532
645
  }
533
- export type KeyPaths<T> = {
534
- [P in keyof T]: P extends string ? T[P] extends Array<infer K> ? K extends any[] // Array of arrays (issue #2026)
535
- ? P | `${P}.${number}` | `${P}.${number}.${number}` : K extends object // only drill into the array element if it's an object
536
- ? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}` : P | `${P}.${number}` : T[P] extends (...args: any[]) => any // Method
537
- ? never : T[P] extends YjsDoc // Not valid in update spec or where clause (+ avoid circular reference)
538
- ? never : T[P] extends object ? P | `${P}.${KeyPaths<T[P]>}` : P : never;
539
- }[keyof T];
540
- export type KeyPathValue<T, PATH> = PATH extends `${infer R}.${infer S}` ? R extends keyof T ? KeyPathValue<T[R], S> : T extends any[] ? PATH extends `${number}.${infer S}` ? KeyPathValue<T[number], S> : void : void : PATH extends `${number}` ? T extends any[] ? T[number] : void : PATH extends keyof T ? T[PATH] : any;
541
- export declare const PropModSymbol: unique symbol;
542
- export type PropModSpec = {
543
- replacePrefix?: [
544
- string,
545
- string
546
- ];
547
- add?: number | bigint | Array<string | number>;
548
- remove?: number | bigint | Array<string | number>;
549
- };
550
- export class PropModification implements PropModSpec {
551
- [PropModSymbol]?: true;
552
- replacePrefix?: [
553
- string,
554
- string
555
- ];
556
- add?: number | bigint | Array<string | number>;
557
- remove?: number | bigint | Array<string | number>;
558
- execute<T>(value: T): T;
559
- constructor(spec: PropModSpec);
560
- }
561
- export type UpdateSpec<T> = {
562
- [KP in KeyPaths<T>]?: KeyPathValue<T, KP> | PropModification;
563
- };
564
- export interface Collection<T = any, TKey = IndexableType, TInsertType = T> {
565
- db: Dexie;
566
- and(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
567
- clone(props?: Object): Collection<T, TKey, TInsertType>;
568
- count(): PromiseExtended<number>;
569
- count<R>(thenShortcut: ThenShortcut<number, R>): PromiseExtended<R>;
570
- distinct(): Collection<T, TKey, TInsertType>;
571
- each(callback: (obj: T, cursor: {
572
- key: IndexableType;
573
- primaryKey: TKey;
574
- }) => any): PromiseExtended<void>;
575
- eachKey(callback: (key: IndexableType, cursor: {
576
- key: IndexableType;
577
- primaryKey: TKey;
578
- }) => any): PromiseExtended<void>;
579
- eachPrimaryKey(callback: (key: TKey, cursor: {
580
- key: IndexableType;
581
- primaryKey: TKey;
582
- }) => any): PromiseExtended<void>;
583
- eachUniqueKey(callback: (key: IndexableType, cursor: {
584
- key: IndexableType;
585
- primaryKey: TKey;
586
- }) => any): PromiseExtended<void>;
587
- filter<S extends T>(filter: (x: T) => x is S): Collection<S, TKey>;
588
- filter(filter: (x: T) => boolean): Collection<T, TKey, TInsertType>;
589
- first(): PromiseExtended<T | undefined>;
590
- first<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
591
- keys(): PromiseExtended<IndexableTypeArray>;
592
- keys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
593
- primaryKeys(): PromiseExtended<TKey[]>;
594
- primaryKeys<R>(thenShortcut: ThenShortcut<TKey[], R>): PromiseExtended<R>;
595
- last(): PromiseExtended<T | undefined>;
596
- last<R>(thenShortcut: ThenShortcut<T | undefined, R>): PromiseExtended<R>;
597
- limit(n: number): Collection<T, TKey, TInsertType>;
598
- offset(n: number): Collection<T, TKey, TInsertType>;
599
- or(indexOrPrimayKey: string): WhereClause<T, TKey, TInsertType>;
600
- raw(): Collection<T, TKey, TInsertType>;
601
- reverse(): Collection<T, TKey, TInsertType>;
602
- sortBy(keyPath: string): PromiseExtended<T[]>;
603
- sortBy<R>(keyPath: string, thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
604
- toArray(): PromiseExtended<Array<T>>;
605
- toArray<R>(thenShortcut: ThenShortcut<T[], R>): PromiseExtended<R>;
606
- uniqueKeys(): PromiseExtended<IndexableTypeArray>;
607
- uniqueKeys<R>(thenShortcut: ThenShortcut<IndexableTypeArray, R>): PromiseExtended<R>;
608
- until(filter: (value: T) => boolean, includeStopEntry?: boolean): Collection<T, TKey, TInsertType>;
609
- // Mutating methods
610
- delete(): PromiseExtended<number>;
611
- modify(changeCallback: (obj: T, ctx: {
612
- value: TInsertType;
613
- }) => void | boolean): PromiseExtended<number>;
614
- modify(changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
615
- }
616
- export type IntervalTree = IntervalTreeNode | EmptyRange;
617
- export interface IntervalTreeNode {
618
- from: IndexableType; // lower bound
619
- to: IndexableType; // upper bound
620
- l?: IntervalTreeNode | null; // left
621
- r?: IntervalTreeNode | null; // right
622
- d: number; // depth
623
- }
624
- export interface EmptyRange {
625
- d: 0;
626
- }
627
- export interface RangeSetPrototype {
628
- add(rangeSet: IntervalTree | {
629
- from: IndexableType;
630
- to: IndexableType;
631
- }): RangeSet;
632
- addKey(key: IndexableType): RangeSet;
633
- addKeys(keys: IndexableType[]): RangeSet;
634
- hasKey(key: IndexableType): boolean;
635
- [Symbol.iterator](): Iterator<IntervalTreeNode, undefined, IndexableType | undefined>;
636
- }
637
- export type RangeSet = RangeSetPrototype & IntervalTree;
638
- export interface RangeSetConstructor {
639
- (tree: IntervalTree): RangeSet;
640
- new (): RangeSet;
641
- new (from: IndexableType, to?: IndexableType): RangeSet;
642
- }
643
646
  export interface DexieOnReadyEvent {
644
647
  subscribe(fn: (vipDb: Dexie) => any, bSticky: boolean): void;
645
648
  unsubscribe(fn: (vipDb: Dexie) => any): void;
@@ -935,11 +938,10 @@ export interface Table<T = any, TKey = any, TInsertType = T> {
935
938
  reverse(): Collection<T, TKey, TInsertType>;
936
939
  mapToClass(constructor: Function): Function;
937
940
  add(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
938
- update(key: TKey | T, changes: ((obj: T, ctx: {
941
+ update(key: TKey | T, changes: UpdateSpec<TInsertType> | ((obj: T, ctx: {
939
942
  value: any;
940
943
  primKey: IndexableType;
941
944
  }) => void | boolean)): PromiseExtended<number>;
942
- update(key: TKey | T, changes: UpdateSpec<TInsertType>): PromiseExtended<number>;
943
945
  put(item: TInsertType, key?: TKey): PromiseExtended<TKey>;
944
946
  delete(key: TKey): PromiseExtended<void>;
945
947
  clear(): PromiseExtended<void>;
@@ -989,7 +991,7 @@ export interface Middleware<TStack extends {
989
991
  export interface DexieStacks {
990
992
  dbcore: DBCore;
991
993
  }
992
- export type TableProp<DX extends Dexie> = {
994
+ export type TableProp<DX> = {
993
995
  [K in keyof DX]: DX[K] extends {
994
996
  schema: any;
995
997
  get: any;
@@ -1252,7 +1254,9 @@ export interface DexieOptions {
1252
1254
  upperBound: Function;
1253
1255
  };
1254
1256
  allowEmptyDB?: boolean;
1255
- modifyChunkSize?: number;
1257
+ modifyChunkSize?: number | {
1258
+ [key: string]: number;
1259
+ };
1256
1260
  chromeTransactionDurability?: ChromeTransactionDurability;
1257
1261
  cache?: "immutable" | "cloned" | "disabled";
1258
1262
  Y?: YjsLib; // Caller supplies Y from the following: import * as Y from 'yjs';
@@ -1260,7 +1264,7 @@ export interface DexieOptions {
1260
1264
  }
1261
1265
  export interface DexieConstructor extends DexieExceptionClasses {
1262
1266
  new (databaseName: string, options?: DexieOptions): Dexie;
1263
- prototype: Dexie;
1267
+ prototype: any;
1264
1268
  addons: Array<(db: Dexie) => void>;
1265
1269
  version: number;
1266
1270
  semVer: string;
package/dist/dexie.js CHANGED
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * By David Fahlander, david.fahlander@gmail.com
6
6
  *
7
- * Version 4.1.0-alpha.12, Wed Oct 16 2024
7
+ * Version 4.1.0-alpha.23, Wed Nov 27 2024
8
8
  *
9
9
  * https://dexie.org
10
10
  *
@@ -803,6 +803,8 @@
803
803
  }); });
804
804
  });
805
805
  });
806
+ if (NativePromise.withResolvers)
807
+ DexiePromise.withResolvers = NativePromise.withResolvers;
806
808
  }
807
809
  function executePromiseTask(promise, fn) {
808
810
  try {
@@ -1177,7 +1179,7 @@
1177
1179
  }
1178
1180
  }
1179
1181
 
1180
- var DEXIE_VERSION = '4.1.0-alpha.12';
1182
+ var DEXIE_VERSION = '4.1.0-alpha.23';
1181
1183
  var maxString = String.fromCharCode(65535);
1182
1184
  var minKey = -Infinity;
1183
1185
  var INVALID_KEY_ARGUMENT = "Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.";
@@ -1309,16 +1311,25 @@
1309
1311
  return docRef ? docRef.deref() : undefined;
1310
1312
  },
1311
1313
  add: function (doc) {
1312
- var _a = doc.meta, parentTable = _a.parentTable, parentId = _a.parentId, parentProp = _a.parentProp;
1314
+ var _a;
1315
+ var _b = doc.meta, parentTable = _b.parentTable, parentId = _b.parentId, parentProp = _b.parentProp;
1313
1316
  if (!parentTable || !parentProp || parentId == null)
1314
1317
  throw new Error("Missing Dexie-related metadata in Y.Doc");
1315
1318
  var cacheKey = getYDocCacheKey(parentTable, parentId, parentProp);
1319
+ var existingDoc = (_a = this.cache[cacheKey]) === null || _a === void 0 ? void 0 : _a.deref();
1320
+ if (existingDoc) {
1321
+ docRegistry.unregister(existingDoc);
1322
+ }
1316
1323
  this.cache[cacheKey] = new WeakRef(doc);
1317
1324
  docRegistry.register(doc, { cache: this.cache, key: cacheKey });
1318
1325
  },
1319
1326
  delete: function (doc) {
1320
1327
  docRegistry.unregister(doc);
1321
- delete this.cache[getYDocCacheKey(doc.meta.parentTable, doc.meta.parentId, doc.meta.parentProp)];
1328
+ var cacheKey = getYDocCacheKey(doc.meta.parentTable, doc.meta.parentId, doc.meta.parentProp);
1329
+ var cacheEntry = this.cache[cacheKey];
1330
+ if ((cacheEntry === null || cacheEntry === void 0 ? void 0 : cacheEntry.deref()) === doc) {
1331
+ delete this.cache[cacheKey];
1332
+ }
1322
1333
  },
1323
1334
  });
1324
1335
  }
@@ -1462,9 +1473,8 @@
1462
1473
  console.warn("The query ".concat(JSON.stringify(indexOrCrit), " on ").concat(this.name, " would benefit from a ") +
1463
1474
  "compound index [".concat(keyPaths.join('+'), "]"));
1464
1475
  var idxByName = this.schema.idxByName;
1465
- var idb = this.db._deps.indexedDB;
1466
1476
  function equals(a, b) {
1467
- return idb.cmp(a, b) === 0;
1477
+ return cmp(a, b) === 0;
1468
1478
  }
1469
1479
  var _a = __read(keyPaths.reduce(function (_a, keyPath) {
1470
1480
  var _b = __read(_a, 2), prevIndex = _b[0], prevFilterFn = _b[1];
@@ -2079,7 +2089,7 @@
2079
2089
  var order = this._ctx.dir === "next" ? 1 : -1;
2080
2090
  function sorter(a, b) {
2081
2091
  var aVal = getval(a, lastIndex), bVal = getval(b, lastIndex);
2082
- return aVal < bVal ? -order : aVal > bVal ? order : 0;
2092
+ return cmp(aVal, bVal) * order;
2083
2093
  }
2084
2094
  return this.toArray(function (a) {
2085
2095
  return a.sort(sorter);
@@ -2299,7 +2309,16 @@
2299
2309
  }
2300
2310
  var coreTable = ctx.table.core;
2301
2311
  var _a = coreTable.schema.primaryKey, outbound = _a.outbound, extractKey = _a.extractKey;
2302
- var limit = _this.db._options.modifyChunkSize || 200;
2312
+ var limit = 200;
2313
+ var modifyChunkSize = _this.db._options.modifyChunkSize;
2314
+ if (modifyChunkSize) {
2315
+ if (typeof modifyChunkSize == 'object') {
2316
+ limit = modifyChunkSize[coreTable.name] || modifyChunkSize['*'] || 200;
2317
+ }
2318
+ else {
2319
+ limit = modifyChunkSize;
2320
+ }
2321
+ }
2303
2322
  var totalFailures = [];
2304
2323
  var successCount = 0;
2305
2324
  var failedKeys = [];
@@ -4990,6 +5009,7 @@
4990
5009
  var extractKey = primaryKey.extractKey, outbound = primaryKey.outbound;
4991
5010
  var indexesWithAutoIncPK = primaryKey.autoIncrement && indexes.filter(function (index) { return index.compound && index.keyPath.includes(primaryKey.keyPath); });
4992
5011
  var tableClone = __assign(__assign({}, table), { mutate: function (req) {
5012
+ var _a, _b;
4993
5013
  var trans = req.trans;
4994
5014
  var mutatedParts = req.mutatedParts || (req.mutatedParts = {});
4995
5015
  var getRangeSet = function (indexName) {
@@ -5000,13 +5020,13 @@
5000
5020
  var pkRangeSet = getRangeSet("");
5001
5021
  var delsRangeSet = getRangeSet(":dels");
5002
5022
  var type = req.type;
5003
- var _a = __read(req.type === "deleteRange"
5023
+ var _c = __read(req.type === "deleteRange"
5004
5024
  ? [req.range]
5005
5025
  : req.type === "delete"
5006
5026
  ? [req.keys]
5007
5027
  : req.values.length < 50
5008
5028
  ? [getEffectiveKeys(primaryKey, req).filter(function (id) { return id; }), req.values]
5009
- : [], 2), keys = _a[0], newObjs = _a[1];
5029
+ : [], 2), keys = _c[0], newObjs = _c[1];
5010
5030
  var oldCache = req.trans["_cache"];
5011
5031
  if (isArray(keys)) {
5012
5032
  pkRangeSet.addKeys(keys);
@@ -5019,7 +5039,10 @@
5019
5039
  }
5020
5040
  }
5021
5041
  else if (keys) {
5022
- var range = { from: keys.lower, to: keys.upper };
5042
+ var range = {
5043
+ from: (_a = keys.lower) !== null && _a !== void 0 ? _a : core.MIN_KEY,
5044
+ to: (_b = keys.upper) !== null && _b !== void 0 ? _b : core.MAX_KEY
5045
+ };
5023
5046
  delsRangeSet.add(range);
5024
5047
  pkRangeSet.add(range);
5025
5048
  }
@@ -5035,7 +5058,9 @@
5035
5058
  indexesWithAutoIncPK.forEach(function (idx) {
5036
5059
  var idxVals = req.values.map(function (v) { return idx.extractKey(v); });
5037
5060
  var pkPos = idx.keyPath.findIndex(function (prop) { return prop === primaryKey.keyPath; });
5038
- res.results.forEach(function (pk) { return idxVals[pkPos] = pk; });
5061
+ for (var i = 0, len = res.results.length; i < len; ++i) {
5062
+ idxVals[i][pkPos] = res.results[i];
5063
+ }
5039
5064
  getRangeSet(idx.name).addKeys(idxVals);
5040
5065
  });
5041
5066
  }
@@ -5243,12 +5268,27 @@
5243
5268
  }
5244
5269
  }
5245
5270
  switch (op.type) {
5246
- case 'add':
5271
+ case 'add': {
5272
+ var existingKeys_1 = new RangeSet().addKeys(req.values ? result.map(function (v) { return extractPrimKey(v); }) : result);
5247
5273
  modifedResult = result.concat(req.values
5248
- ? includedValues
5249
- : includedValues.map(function (v) { return extractPrimKey(v); }));
5274
+ ? includedValues.filter(function (v) {
5275
+ var key = extractPrimKey(v);
5276
+ if (existingKeys_1.hasKey(key))
5277
+ return false;
5278
+ existingKeys_1.addKey(key);
5279
+ return true;
5280
+ })
5281
+ : includedValues
5282
+ .map(function (v) { return extractPrimKey(v); })
5283
+ .filter(function (k) {
5284
+ if (existingKeys_1.hasKey(k))
5285
+ return false;
5286
+ existingKeys_1.addKey(k);
5287
+ return true;
5288
+ }));
5250
5289
  break;
5251
- case 'put':
5290
+ }
5291
+ case 'put': {
5252
5292
  var keySet_1 = new RangeSet().addKeys(op.values.map(function (v) { return extractPrimKey(v); }));
5253
5293
  modifedResult = result
5254
5294
  .filter(
@@ -5258,9 +5298,12 @@
5258
5298
  ? includedValues
5259
5299
  : includedValues.map(function (v) { return extractPrimKey(v); }));
5260
5300
  break;
5301
+ }
5261
5302
  case 'delete':
5262
5303
  var keysToDelete_1 = new RangeSet().addKeys(op.keys);
5263
- modifedResult = result.filter(function (item) { return !keysToDelete_1.hasKey(req.values ? extractPrimKey(item) : item); });
5304
+ modifedResult = result.filter(function (item) {
5305
+ return !keysToDelete_1.hasKey(req.values ? extractPrimKey(item) : item);
5306
+ });
5264
5307
  break;
5265
5308
  case 'deleteRange':
5266
5309
  var range_1 = op.range;
@@ -5520,7 +5563,8 @@
5520
5563
  var trans = PSD.trans;
5521
5564
  if (primKey.outbound ||
5522
5565
  trans.db._options.cache === 'disabled' ||
5523
- trans.explicit
5566
+ trans.explicit ||
5567
+ trans.idbtrans.mode !== 'readwrite'
5524
5568
  ) {
5525
5569
  return downTable.mutate(req);
5526
5570
  }
@@ -5532,6 +5576,8 @@
5532
5576
  promise.then(function (res) {
5533
5577
  var reqWithResolvedKeys = __assign(__assign({}, req), { values: req.values.map(function (value, i) {
5534
5578
  var _a;
5579
+ if (res.failures[i])
5580
+ return value;
5535
5581
  var valueWithKey = ((_a = primKey.keyPath) === null || _a === void 0 ? void 0 : _a.includes('.'))
5536
5582
  ? deepClone(value)
5537
5583
  : __assign({}, value);