tinybase 1.3.5 → 1.3.6

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.
@@ -1 +1 @@
1
- const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,s=e=>0==n(e),r=e=>e.slice(1),o=(e,t)=>e.push(t),c=e=>e.pop(),l=e=>null==e,i=(e,t,n)=>l(e)?n?.():t(e),a=(e,t)=>e?.has(t)??!1,d=e=>l(e)||0==(e=>e.size)(e),h=(e,t)=>e?.forEach(t),u=(e,t)=>e?.delete(t),p=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>l(n)?(u(e,t),e):e?.set(t,n),k=(e,t,n)=>(a(e,t)||e.set(t,n()),C(e,t)),f=e=>new Set(e),L=(e,t,o)=>n(o)<2?((e,t)=>e?.add(t))(s(o)?e:k(e,o[0],f),t):L(k(e,o[0],p),t,r(o)),w=e=>{const n=(o,c,...l)=>i(o,(o=>s(l)?e(o,c):t([l[0],null],(e=>n(C(o,e),c,...r(l))))));return n},v=Object.freeze,S=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((r=>{let S,z,E,I=100,M=p(),b=1;const j=f(),x=p(),[y,B,F]=(e=>{let s,r=0;const a=[],d=p();return[(t,n,o=[])=>{s??=e();const l=c(a)??""+r++;return g(d,l,[t,n,o]),L(n,l,o),l},(e,t=[],...n)=>w(h)(e,(e=>i(C(d,e),(([e])=>e(s,...t,...n)))),...t),e=>i(C(d,e),(([,t,s])=>(w(u)(t,e,...s),g(d,e),n(a)<1e3&&o(a,e),s)),(()=>[])),(e,r,o)=>i(C(d,e),(([e,,c])=>{const i=(...a)=>{const d=n(a);d==n(c)?e(s,...a,...o(a)):l(c[d])?t(r[d](...a),(e=>i(...a,e))):i(...a,c[d])};i()}))]})((()=>V)),O=p(),T=p(),W=[],m=[],q=(e,t)=>{b=0,r.transaction((()=>h(C(O,t),((t,n)=>h(t,((t,s)=>h(t,((t,o)=>l(t[e])?r.delCell(n,s,o,!0):r.setCell(n,s,o,t[e]))))))))),b=1},A=e=>{g(O,e),g(T,e),B(x,[e])},D=(e,s)=>t(((e,t)=>e.splice(0,t))(e,s??n(e)),A),G=()=>D(W,n(W)-I),H=r.addCellListener(null,null,null,((e,t,n,s,r,l)=>{if(b){i(S,(()=>{o(W,S),G(),D(m),S=void 0,E=1}));const e=k(M,t,p),a=k(e,n,p),h=k(a,s,(()=>[l,void 0]));h[1]=r,h[0]===r&&d(g(a,s))&&d(g(e,n))&&d(g(M,t))&&(S=c(W),E=1),P()}})),J=(e="")=>(l(S)&&(S=""+z++,g(O,S,M),R(S,e),M=p(),E=1),S),K=()=>{s(W)||(m.unshift(J()),q(0,S),S=c(W),E=1)},N=()=>{s(m)||(o(W,S),S=m.shift(),q(1,S),E=1)},P=()=>{E&&(B(j),E=0)},Q=e=>{const t=J(e);return P(),t},R=(e,t)=>(U(e)&&C(T,e)!==t&&(g(T,e,t),B(x,[e])),V),U=e=>a(O,e),V={setSize:e=>(I=e,G(),V),addCheckpoint:Q,setCheckpoint:R,getStore:()=>r,getCheckpointIds:()=>[[...W],S,[...m]],forEachCheckpoint:e=>{return t=e,h(T,((e,n)=>t(n,e)));var t},hasCheckpoint:U,getCheckpoint:e=>C(T,e),goBackward:()=>(K(),P(),V),goForward:()=>(N(),P(),V),goTo:t=>{const n=e(W,t)?K:e(m,t)?N:null;for(;!l(n)&&t!=S;)n();return P(),V},addCheckpointIdsListener:e=>y(e,j),addCheckpointListener:(e,t)=>y(t,x,[e]),delListener:e=>(F(e),V),clear:()=>(D(W),D(m),l(S)||A(S),S=void 0,z=0,Q(),V),destroy:()=>{r.delListener(H)},getListenerStats:()=>({})};return v(V.clear())}));export{S as createCheckpoints};
1
+ const e=(e,t)=>e.includes(t),t=(e,t)=>e.forEach(t),n=e=>e.length,r=e=>0==n(e),s=e=>e.slice(1),o=(e,t)=>e.push(t),c=e=>e.pop(),l=e=>null==e,i=(e,t,n)=>l(e)?n?.():t(e),a=(e,t)=>e?.has(t)??!1,d=e=>l(e)||0==(e=>e.size)(e),h=(e,t)=>e?.forEach(t),u=(e,t)=>e?.delete(t),p=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>l(n)?(u(e,t),e):e?.set(t,n),k=(e,t,n)=>(a(e,t)||g(e,t,n()),C(e,t)),f=e=>new Set(e),L=(e,t,o)=>n(o)<2?((e,t)=>e?.add(t))(r(o)?e:k(e,o[0],f),t):L(k(e,o[0],p),t,s(o)),w=e=>{const n=(o,c,...l)=>i(o,(o=>r(l)?e(o,c):t([l[0],null],(e=>n(C(o,e),c,...s(l))))));return n},v=Object.freeze,S=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((s=>{let S,z,E,I=100,M=p(),b=1;const j=f(),x=p(),[y,B,F]=(e=>{let r,s=0;const a=[],d=p();return[(t,n,o=[])=>{r??=e();const l=c(a)??""+s++;return g(d,l,[t,n,o]),L(n,l,o),l},(e,t=[],...n)=>w(h)(e,(e=>i(C(d,e),(([e])=>e(r,...t,...n)))),...t),e=>i(C(d,e),(([,t,r])=>(w(u)(t,e,...r),g(d,e),n(a)<1e3&&o(a,e),r)),(()=>[])),(e,s,o)=>i(C(d,e),(([e,,c])=>{const i=(...a)=>{const d=n(a);d==n(c)?e(r,...a,...o(a)):l(c[d])?t(s[d](...a),(e=>i(...a,e))):i(...a,c[d])};i()}))]})((()=>V)),O=p(),T=p(),W=[],m=[],q=(e,t)=>{b=0,s.transaction((()=>h(C(O,t),((t,n)=>h(t,((t,r)=>h(t,((t,o)=>l(t[e])?s.delCell(n,r,o,!0):s.setCell(n,r,o,t[e]))))))))),b=1},A=e=>{g(O,e),g(T,e),B(x,[e])},D=(e,r)=>t(((e,t)=>e.splice(0,t))(e,r??n(e)),A),G=()=>D(W,n(W)-I),H=s.addCellListener(null,null,null,((e,t,n,r,s,l)=>{if(b){i(S,(()=>{o(W,S),G(),D(m),S=void 0,E=1}));const e=k(M,t,p),a=k(e,n,p),h=k(a,r,(()=>[l,void 0]));h[1]=s,h[0]===s&&d(g(a,r))&&d(g(e,n))&&d(g(M,t))&&(S=c(W),E=1),P()}})),J=(e="")=>(l(S)&&(S=""+z++,g(O,S,M),R(S,e),M=p(),E=1),S),K=()=>{r(W)||(m.unshift(J()),q(0,S),S=c(W),E=1)},N=()=>{r(m)||(o(W,S),S=m.shift(),q(1,S),E=1)},P=()=>{E&&(B(j),E=0)},Q=e=>{const t=J(e);return P(),t},R=(e,t)=>(U(e)&&C(T,e)!==t&&(g(T,e,t),B(x,[e])),V),U=e=>a(O,e),V={setSize:e=>(I=e,G(),V),addCheckpoint:Q,setCheckpoint:R,getStore:()=>s,getCheckpointIds:()=>[[...W],S,[...m]],forEachCheckpoint:e=>{return t=e,h(T,((e,n)=>t(n,e)));var t},hasCheckpoint:U,getCheckpoint:e=>C(T,e),goBackward:()=>(K(),P(),V),goForward:()=>(N(),P(),V),goTo:t=>{const n=e(W,t)?K:e(m,t)?N:null;for(;!l(n)&&t!=S;)n();return P(),V},addCheckpointIdsListener:e=>y(e,j),addCheckpointListener:(e,t)=>y(t,x,[e]),delListener:e=>(F(e),V),clear:()=>(D(W),D(m),l(S)||A(S),S=void 0,z=0,Q(),V),destroy:()=>{s.delListener(H)},getListenerStats:()=>({})};return v(V.clear())}));export{S as createCheckpoints};
Binary file
package/lib/common.js CHANGED
@@ -1 +1 @@
1
- const o=(o,t)=>o<t?-1:1;export{o as defaultSorter};
1
+ const o=(o,t)=>o<t?-1:1,t=o=>""+o;export{o as defaultSorter,t as id};
package/lib/common.js.gz CHANGED
Binary file
@@ -30,7 +30,7 @@ const mapSet = (map, key, value) =>
30
30
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
31
31
  const mapEnsure = (map, key, getDefaultValue) => {
32
32
  if (!collHas(map, key)) {
33
- map.set(key, getDefaultValue());
33
+ mapSet(map, key, getDefaultValue());
34
34
  }
35
35
  return mapGet(map, key);
36
36
  };
@@ -1,3 +1,6 @@
1
+ const EMPTY_STRING = '';
2
+
1
3
  const defaultSorter = (sortKey1, sortKey2) => (sortKey1 < sortKey2 ? -1 : 1);
4
+ const id = (key) => EMPTY_STRING + key;
2
5
 
3
- export {defaultSorter};
6
+ export {defaultSorter, id};
@@ -41,7 +41,7 @@ const mapSet = (map, key, value) =>
41
41
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
42
42
  const mapEnsure = (map, key, getDefaultValue) => {
43
43
  if (!collHas(map, key)) {
44
- map.set(key, getDefaultValue());
44
+ mapSet(map, key, getDefaultValue());
45
45
  }
46
46
  return mapGet(map, key);
47
47
  };
@@ -46,7 +46,7 @@ const mapSet = (map, key, value) =>
46
46
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
47
47
  const mapEnsure = (map, key, getDefaultValue) => {
48
48
  if (!collHas(map, key)) {
49
- map.set(key, getDefaultValue());
49
+ mapSet(map, key, getDefaultValue());
50
50
  }
51
51
  return mapGet(map, key);
52
52
  };
@@ -36,7 +36,7 @@ const mapSet = (map, key, value) =>
36
36
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
37
37
  const mapEnsure = (map, key, getDefaultValue) => {
38
38
  if (!collHas(map, key)) {
39
- map.set(key, getDefaultValue());
39
+ mapSet(map, key, getDefaultValue());
40
40
  }
41
41
  return mapGet(map, key);
42
42
  };
@@ -11,6 +11,7 @@ const DEFAULT = 'default';
11
11
  const arrayPair = (value) => [value, value];
12
12
  const arrayHas = (array, value) => array.includes(value);
13
13
  const arrayForEach = (array, cb) => array.forEach(cb);
14
+ const arrayMap = (array, cb) => array.map(cb);
14
15
  const arrayLength = (array) => array.length;
15
16
  const arrayIsEmpty = (array) => arrayLength(array) == 0;
16
17
  const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
@@ -65,7 +66,7 @@ const mapSet = (map, key, value) =>
65
66
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
66
67
  const mapEnsure = (map, key, getDefaultValue) => {
67
68
  if (!collHas(map, key)) {
68
- map.set(key, getDefaultValue());
69
+ mapSet(map, key, getDefaultValue());
69
70
  }
70
71
  return mapGet(map, key);
71
72
  };
@@ -176,15 +177,17 @@ const getListenerFunctions = (getThing) => {
176
177
  return [addListener, callListeners, delListener, callListener];
177
178
  };
178
179
 
180
+ const id = (key) => EMPTY_STRING + key;
181
+
179
182
  const transformMap = (map, toBeLikeObject, setId, delId = mapSet) => {
180
183
  const idsToDelete = arrayFilter(
181
184
  mapKeys(map),
182
- (id) => !objHas(toBeLikeObject, id),
185
+ (id2) => !objHas(toBeLikeObject, id2),
183
186
  );
184
- arrayForEach(objIds(toBeLikeObject), (id) =>
185
- setId(map, id, toBeLikeObject[id]),
187
+ arrayForEach(objIds(toBeLikeObject), (id2) =>
188
+ setId(map, id2, toBeLikeObject[id2]),
186
189
  );
187
- arrayForEach(idsToDelete, (id) => delId(map, id));
190
+ arrayForEach(idsToDelete, (id2) => delId(map, id2));
188
191
  return map;
189
192
  };
190
193
  const getCellType = (cell) => {
@@ -198,15 +201,15 @@ const validate = (obj, validateChild, onInvalidObj) => {
198
201
  onInvalidObj?.();
199
202
  return false;
200
203
  }
201
- objForEach(obj, (child, id) => {
202
- if (!validateChild(child, id)) {
203
- objDel(obj, id);
204
+ objForEach(obj, (child, id2) => {
205
+ if (!validateChild(child, id2)) {
206
+ objDel(obj, id2);
204
207
  }
205
208
  });
206
209
  return !objIsEmpty(obj);
207
210
  };
208
- const idsChanged = (ids, id, added) =>
209
- mapSet(ids, id, mapGet(ids, id) == -added ? void 0 : added);
211
+ const idsChanged = (ids, id2, added) =>
212
+ mapSet(ids, id2, mapGet(ids, id2) == -added ? void 0 : added);
210
213
  const createStore = () => {
211
214
  let hasSchema;
212
215
  let cellsTouched;
@@ -235,7 +238,7 @@ const createStore = () => {
235
238
  validate(schema, (tableSchema) =>
236
239
  validate(tableSchema, (cellSchema) => {
237
240
  if (
238
- !validate(cellSchema, (_child, id) => arrayHas([TYPE, DEFAULT], id))
241
+ !validate(cellSchema, (_child, id2) => arrayHas([TYPE, DEFAULT], id2))
239
242
  ) {
240
243
  return false;
241
244
  }
@@ -381,7 +384,7 @@ const createStore = () => {
381
384
  ),
382
385
  );
383
386
  const getNewRowId = (tableMap) => {
384
- const rowId = '' + nextRowId++;
387
+ const rowId = EMPTY_STRING + nextRowId++;
385
388
  if (!collHas(tableMap, rowId)) {
386
389
  return rowId;
387
390
  }
@@ -532,26 +535,28 @@ const createStore = () => {
532
535
  }
533
536
  }
534
537
  };
535
- const fluentTransaction = (actions) => {
536
- transaction(actions);
538
+ const fluentTransaction = (actions, ...args) => {
539
+ transaction(() => actions(...arrayMap(args, id)));
537
540
  return store;
538
541
  };
539
542
  const getTables = () =>
540
543
  mapToObj(tablesMap, (table) => mapToObj(table, mapToObj));
541
544
  const getTableIds = () => mapKeys(tablesMap);
542
- const getTable = (tableId) => mapToObj(mapGet(tablesMap, tableId), mapToObj);
543
- const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, tableId));
545
+ const getTable = (tableId) =>
546
+ mapToObj(mapGet(tablesMap, id(tableId)), mapToObj);
547
+ const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
544
548
  const getRow = (tableId, rowId) =>
545
- mapToObj(mapGet(mapGet(tablesMap, tableId), rowId));
549
+ mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
546
550
  const getCellIds = (tableId, rowId) =>
547
- mapKeys(mapGet(mapGet(tablesMap, tableId), rowId));
551
+ mapKeys(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
548
552
  const getCell = (tableId, rowId, cellId) =>
549
- mapGet(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
553
+ mapGet(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
550
554
  const hasTables = () => !collIsEmpty(tablesMap);
551
- const hasTable = (tableId) => collHas(tablesMap, tableId);
552
- const hasRow = (tableId, rowId) => collHas(mapGet(tablesMap, tableId), rowId);
555
+ const hasTable = (tableId) => collHas(tablesMap, id(tableId));
556
+ const hasRow = (tableId, rowId) =>
557
+ collHas(mapGet(tablesMap, id(tableId)), id(rowId));
553
558
  const hasCell = (tableId, rowId, cellId) =>
554
- collHas(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
559
+ collHas(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
555
560
  const getJson = () => jsonString(tablesMap);
556
561
  const getSchemaJson = () => jsonString(schemaMap);
557
562
  const setTables = (tables) =>
@@ -559,19 +564,30 @@ const createStore = () => {
559
564
  validateTables(tables) ? setValidTables(tables) : 0,
560
565
  );
561
566
  const setTable = (tableId, table) =>
562
- fluentTransaction(() =>
563
- validateTable(table, tableId) ? setValidTable(tableId, table) : 0,
567
+ fluentTransaction(
568
+ (tableId2) =>
569
+ validateTable(table, tableId2) ? setValidTable(tableId2, table) : 0,
570
+ tableId,
564
571
  );
565
572
  const setRow = (tableId, rowId, row) =>
566
- fluentTransaction(() =>
567
- validateRow(tableId, rowId, row)
568
- ? setValidRow(tableId, getOrCreateTable(tableId), rowId, row)
569
- : 0,
573
+ fluentTransaction(
574
+ (tableId2, rowId2) =>
575
+ validateRow(id(tableId2), id(rowId2), row)
576
+ ? setValidRow(
577
+ id(tableId2),
578
+ getOrCreateTable(id(tableId2)),
579
+ id(rowId2),
580
+ row,
581
+ )
582
+ : 0,
583
+ tableId,
584
+ rowId,
570
585
  );
571
586
  const addRow = (tableId, row) =>
572
587
  transaction(() => {
573
588
  let rowId = void 0;
574
589
  if (validateRow(tableId, rowId, row)) {
590
+ tableId = id(tableId);
575
591
  setValidRow(
576
592
  tableId,
577
593
  getOrCreateTable(tableId),
@@ -582,32 +598,40 @@ const createStore = () => {
582
598
  return rowId;
583
599
  });
584
600
  const setPartialRow = (tableId, rowId, partialRow) =>
585
- fluentTransaction(() => {
586
- if (validateRow(tableId, rowId, partialRow, 1)) {
587
- const table = getOrCreateTable(tableId);
588
- objForEach(partialRow, (cell, cellId) =>
589
- setCellIntoDefaultRow(tableId, table, rowId, cellId, cell),
590
- );
591
- }
592
- });
601
+ fluentTransaction(
602
+ (tableId2, rowId2) => {
603
+ if (validateRow(tableId2, rowId2, partialRow, 1)) {
604
+ const table = getOrCreateTable(tableId2);
605
+ objForEach(partialRow, (cell, cellId) =>
606
+ setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
607
+ );
608
+ }
609
+ },
610
+ tableId,
611
+ rowId,
612
+ );
593
613
  const setCell = (tableId, rowId, cellId, cell) =>
594
- fluentTransaction(() =>
595
- ifNotUndefined(
596
- getValidatedCell(
597
- tableId,
598
- rowId,
599
- cellId,
600
- isFunction(cell) ? cell(getCell(tableId, rowId, cellId)) : cell,
601
- ),
602
- (validCell) =>
603
- setCellIntoDefaultRow(
604
- tableId,
605
- getOrCreateTable(tableId),
606
- rowId,
607
- cellId,
608
- validCell,
614
+ fluentTransaction(
615
+ (tableId2, rowId2, cellId2) =>
616
+ ifNotUndefined(
617
+ getValidatedCell(
618
+ tableId2,
619
+ rowId2,
620
+ cellId2,
621
+ isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
609
622
  ),
610
- ),
623
+ (validCell) =>
624
+ setCellIntoDefaultRow(
625
+ tableId2,
626
+ getOrCreateTable(tableId2),
627
+ rowId2,
628
+ cellId2,
629
+ validCell,
630
+ ),
631
+ ),
632
+ tableId,
633
+ rowId,
634
+ cellId,
611
635
  );
612
636
  const setJson = (json) => {
613
637
  try {
@@ -628,24 +652,42 @@ const createStore = () => {
628
652
  });
629
653
  const delTables = () => fluentTransaction(() => setValidTables({}));
630
654
  const delTable = (tableId) =>
631
- fluentTransaction(() =>
632
- collHas(tablesMap, tableId) ? delValidTable(tableId) : 0,
655
+ fluentTransaction(
656
+ (tableId2) =>
657
+ collHas(tablesMap, tableId2) ? delValidTable(tableId2) : 0,
658
+ tableId,
633
659
  );
634
660
  const delRow = (tableId, rowId) =>
635
- fluentTransaction(() =>
636
- ifNotUndefined(mapGet(tablesMap, tableId), (tableMap) =>
637
- collHas(tableMap, rowId) ? delValidRow(tableId, tableMap, rowId) : 0,
638
- ),
661
+ fluentTransaction(
662
+ (tableId2, rowId2) =>
663
+ ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
664
+ collHas(tableMap, rowId2)
665
+ ? delValidRow(tableId2, tableMap, rowId2)
666
+ : 0,
667
+ ),
668
+ tableId,
669
+ rowId,
639
670
  );
640
671
  const delCell = (tableId, rowId, cellId, forceDel) =>
641
- fluentTransaction(() =>
642
- ifNotUndefined(mapGet(tablesMap, tableId), (tableMap) =>
643
- ifNotUndefined(mapGet(tableMap, rowId), (rowMap) =>
644
- collHas(rowMap, cellId)
645
- ? delValidCell(tableId, tableMap, rowId, rowMap, cellId, forceDel)
646
- : 0,
672
+ fluentTransaction(
673
+ (tableId2, rowId2, cellId2) =>
674
+ ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
675
+ ifNotUndefined(mapGet(tableMap, rowId2), (rowMap) =>
676
+ collHas(rowMap, cellId2)
677
+ ? delValidCell(
678
+ tableId2,
679
+ tableMap,
680
+ rowId2,
681
+ rowMap,
682
+ cellId2,
683
+ forceDel,
684
+ )
685
+ : 0,
686
+ ),
647
687
  ),
648
- ),
688
+ tableId,
689
+ rowId,
690
+ cellId,
649
691
  );
650
692
  const delSchema = () =>
651
693
  fluentTransaction(() => {
@@ -741,11 +783,11 @@ const createStore = () => {
741
783
  ),
742
784
  );
743
785
  const forEachRow = (tableId, rowCallback) =>
744
- collForEach(mapGet(tablesMap, tableId), (rowMap, rowId) =>
786
+ collForEach(mapGet(tablesMap, id(tableId)), (rowMap, rowId) =>
745
787
  rowCallback(rowId, (cellCallback) => mapForEach(rowMap, cellCallback)),
746
788
  );
747
789
  const forEachCell = (tableId, rowId, cellCallback) =>
748
- mapForEach(mapGet(mapGet(tablesMap, tableId), rowId), cellCallback);
790
+ mapForEach(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), cellCallback);
749
791
  const addTablesListener = (listener, mutator) =>
750
792
  addListener(listener, tablesListeners[mutator ? 1 : 0]);
751
793
  const addTableIdsListener = (listener, mutator) =>
@@ -23,6 +23,7 @@ const arrayIsSorted = (array, sorter) =>
23
23
  );
24
24
  const arraySort = (array, sorter) => array.sort(sorter);
25
25
  const arrayForEach = (array, cb) => array.forEach(cb);
26
+ const arrayMap = (array, cb) => array.map(cb);
26
27
  const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
27
28
  const arrayLength = (array) => array.length;
28
29
  const arrayIsEmpty = (array) => arrayLength(array) == 0;
@@ -83,7 +84,7 @@ const mapSet = (map, key, value) =>
83
84
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
84
85
  const mapEnsure = (map, key, getDefaultValue) => {
85
86
  if (!collHas(map, key)) {
86
- map.set(key, getDefaultValue());
87
+ mapSet(map, key, getDefaultValue());
87
88
  }
88
89
  return mapGet(map, key);
89
90
  };
@@ -518,6 +519,7 @@ const createCheckpoints = getCreateFunction((store) => {
518
519
  });
519
520
 
520
521
  const defaultSorter = (sortKey1, sortKey2) => (sortKey1 < sortKey2 ? -1 : 1);
522
+ const id = (key) => EMPTY_STRING + key;
521
523
 
522
524
  const createIndexes = getCreateFunction((store) => {
523
525
  const sliceIdsListeners = mapNew();
@@ -1200,12 +1202,12 @@ const createRelationships = getCreateFunction((store) => {
1200
1202
  const transformMap = (map, toBeLikeObject, setId, delId = mapSet) => {
1201
1203
  const idsToDelete = arrayFilter(
1202
1204
  mapKeys(map),
1203
- (id) => !objHas(toBeLikeObject, id),
1205
+ (id2) => !objHas(toBeLikeObject, id2),
1204
1206
  );
1205
- arrayForEach(objIds(toBeLikeObject), (id) =>
1206
- setId(map, id, toBeLikeObject[id]),
1207
+ arrayForEach(objIds(toBeLikeObject), (id2) =>
1208
+ setId(map, id2, toBeLikeObject[id2]),
1207
1209
  );
1208
- arrayForEach(idsToDelete, (id) => delId(map, id));
1210
+ arrayForEach(idsToDelete, (id2) => delId(map, id2));
1209
1211
  return map;
1210
1212
  };
1211
1213
  const getCellType = (cell) => {
@@ -1219,15 +1221,15 @@ const validate = (obj, validateChild, onInvalidObj) => {
1219
1221
  onInvalidObj?.();
1220
1222
  return false;
1221
1223
  }
1222
- objForEach(obj, (child, id) => {
1223
- if (!validateChild(child, id)) {
1224
- objDel(obj, id);
1224
+ objForEach(obj, (child, id2) => {
1225
+ if (!validateChild(child, id2)) {
1226
+ objDel(obj, id2);
1225
1227
  }
1226
1228
  });
1227
1229
  return !objIsEmpty(obj);
1228
1230
  };
1229
- const idsChanged = (ids, id, added) =>
1230
- mapSet(ids, id, mapGet(ids, id) == -added ? void 0 : added);
1231
+ const idsChanged = (ids, id2, added) =>
1232
+ mapSet(ids, id2, mapGet(ids, id2) == -added ? void 0 : added);
1231
1233
  const createStore = () => {
1232
1234
  let hasSchema;
1233
1235
  let cellsTouched;
@@ -1256,7 +1258,7 @@ const createStore = () => {
1256
1258
  validate(schema, (tableSchema) =>
1257
1259
  validate(tableSchema, (cellSchema) => {
1258
1260
  if (
1259
- !validate(cellSchema, (_child, id) => arrayHas([TYPE, DEFAULT], id))
1261
+ !validate(cellSchema, (_child, id2) => arrayHas([TYPE, DEFAULT], id2))
1260
1262
  ) {
1261
1263
  return false;
1262
1264
  }
@@ -1402,7 +1404,7 @@ const createStore = () => {
1402
1404
  ),
1403
1405
  );
1404
1406
  const getNewRowId = (tableMap) => {
1405
- const rowId = '' + nextRowId++;
1407
+ const rowId = EMPTY_STRING + nextRowId++;
1406
1408
  if (!collHas(tableMap, rowId)) {
1407
1409
  return rowId;
1408
1410
  }
@@ -1553,26 +1555,28 @@ const createStore = () => {
1553
1555
  }
1554
1556
  }
1555
1557
  };
1556
- const fluentTransaction = (actions) => {
1557
- transaction(actions);
1558
+ const fluentTransaction = (actions, ...args) => {
1559
+ transaction(() => actions(...arrayMap(args, id)));
1558
1560
  return store;
1559
1561
  };
1560
1562
  const getTables = () =>
1561
1563
  mapToObj(tablesMap, (table) => mapToObj(table, mapToObj));
1562
1564
  const getTableIds = () => mapKeys(tablesMap);
1563
- const getTable = (tableId) => mapToObj(mapGet(tablesMap, tableId), mapToObj);
1564
- const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, tableId));
1565
+ const getTable = (tableId) =>
1566
+ mapToObj(mapGet(tablesMap, id(tableId)), mapToObj);
1567
+ const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
1565
1568
  const getRow = (tableId, rowId) =>
1566
- mapToObj(mapGet(mapGet(tablesMap, tableId), rowId));
1569
+ mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
1567
1570
  const getCellIds = (tableId, rowId) =>
1568
- mapKeys(mapGet(mapGet(tablesMap, tableId), rowId));
1571
+ mapKeys(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
1569
1572
  const getCell = (tableId, rowId, cellId) =>
1570
- mapGet(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
1573
+ mapGet(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
1571
1574
  const hasTables = () => !collIsEmpty(tablesMap);
1572
- const hasTable = (tableId) => collHas(tablesMap, tableId);
1573
- const hasRow = (tableId, rowId) => collHas(mapGet(tablesMap, tableId), rowId);
1575
+ const hasTable = (tableId) => collHas(tablesMap, id(tableId));
1576
+ const hasRow = (tableId, rowId) =>
1577
+ collHas(mapGet(tablesMap, id(tableId)), id(rowId));
1574
1578
  const hasCell = (tableId, rowId, cellId) =>
1575
- collHas(mapGet(mapGet(tablesMap, tableId), rowId), cellId);
1579
+ collHas(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), id(cellId));
1576
1580
  const getJson = () => jsonString(tablesMap);
1577
1581
  const getSchemaJson = () => jsonString(schemaMap);
1578
1582
  const setTables = (tables) =>
@@ -1580,19 +1584,30 @@ const createStore = () => {
1580
1584
  validateTables(tables) ? setValidTables(tables) : 0,
1581
1585
  );
1582
1586
  const setTable = (tableId, table) =>
1583
- fluentTransaction(() =>
1584
- validateTable(table, tableId) ? setValidTable(tableId, table) : 0,
1587
+ fluentTransaction(
1588
+ (tableId2) =>
1589
+ validateTable(table, tableId2) ? setValidTable(tableId2, table) : 0,
1590
+ tableId,
1585
1591
  );
1586
1592
  const setRow = (tableId, rowId, row) =>
1587
- fluentTransaction(() =>
1588
- validateRow(tableId, rowId, row)
1589
- ? setValidRow(tableId, getOrCreateTable(tableId), rowId, row)
1590
- : 0,
1593
+ fluentTransaction(
1594
+ (tableId2, rowId2) =>
1595
+ validateRow(id(tableId2), id(rowId2), row)
1596
+ ? setValidRow(
1597
+ id(tableId2),
1598
+ getOrCreateTable(id(tableId2)),
1599
+ id(rowId2),
1600
+ row,
1601
+ )
1602
+ : 0,
1603
+ tableId,
1604
+ rowId,
1591
1605
  );
1592
1606
  const addRow = (tableId, row) =>
1593
1607
  transaction(() => {
1594
1608
  let rowId = void 0;
1595
1609
  if (validateRow(tableId, rowId, row)) {
1610
+ tableId = id(tableId);
1596
1611
  setValidRow(
1597
1612
  tableId,
1598
1613
  getOrCreateTable(tableId),
@@ -1603,32 +1618,40 @@ const createStore = () => {
1603
1618
  return rowId;
1604
1619
  });
1605
1620
  const setPartialRow = (tableId, rowId, partialRow) =>
1606
- fluentTransaction(() => {
1607
- if (validateRow(tableId, rowId, partialRow, 1)) {
1608
- const table = getOrCreateTable(tableId);
1609
- objForEach(partialRow, (cell, cellId) =>
1610
- setCellIntoDefaultRow(tableId, table, rowId, cellId, cell),
1611
- );
1612
- }
1613
- });
1621
+ fluentTransaction(
1622
+ (tableId2, rowId2) => {
1623
+ if (validateRow(tableId2, rowId2, partialRow, 1)) {
1624
+ const table = getOrCreateTable(tableId2);
1625
+ objForEach(partialRow, (cell, cellId) =>
1626
+ setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
1627
+ );
1628
+ }
1629
+ },
1630
+ tableId,
1631
+ rowId,
1632
+ );
1614
1633
  const setCell = (tableId, rowId, cellId, cell) =>
1615
- fluentTransaction(() =>
1616
- ifNotUndefined(
1617
- getValidatedCell(
1618
- tableId,
1619
- rowId,
1620
- cellId,
1621
- isFunction(cell) ? cell(getCell(tableId, rowId, cellId)) : cell,
1622
- ),
1623
- (validCell) =>
1624
- setCellIntoDefaultRow(
1625
- tableId,
1626
- getOrCreateTable(tableId),
1627
- rowId,
1628
- cellId,
1629
- validCell,
1634
+ fluentTransaction(
1635
+ (tableId2, rowId2, cellId2) =>
1636
+ ifNotUndefined(
1637
+ getValidatedCell(
1638
+ tableId2,
1639
+ rowId2,
1640
+ cellId2,
1641
+ isFunction(cell) ? cell(getCell(tableId2, rowId2, cellId2)) : cell,
1630
1642
  ),
1631
- ),
1643
+ (validCell) =>
1644
+ setCellIntoDefaultRow(
1645
+ tableId2,
1646
+ getOrCreateTable(tableId2),
1647
+ rowId2,
1648
+ cellId2,
1649
+ validCell,
1650
+ ),
1651
+ ),
1652
+ tableId,
1653
+ rowId,
1654
+ cellId,
1632
1655
  );
1633
1656
  const setJson = (json) => {
1634
1657
  try {
@@ -1649,24 +1672,42 @@ const createStore = () => {
1649
1672
  });
1650
1673
  const delTables = () => fluentTransaction(() => setValidTables({}));
1651
1674
  const delTable = (tableId) =>
1652
- fluentTransaction(() =>
1653
- collHas(tablesMap, tableId) ? delValidTable(tableId) : 0,
1675
+ fluentTransaction(
1676
+ (tableId2) =>
1677
+ collHas(tablesMap, tableId2) ? delValidTable(tableId2) : 0,
1678
+ tableId,
1654
1679
  );
1655
1680
  const delRow = (tableId, rowId) =>
1656
- fluentTransaction(() =>
1657
- ifNotUndefined(mapGet(tablesMap, tableId), (tableMap) =>
1658
- collHas(tableMap, rowId) ? delValidRow(tableId, tableMap, rowId) : 0,
1659
- ),
1681
+ fluentTransaction(
1682
+ (tableId2, rowId2) =>
1683
+ ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
1684
+ collHas(tableMap, rowId2)
1685
+ ? delValidRow(tableId2, tableMap, rowId2)
1686
+ : 0,
1687
+ ),
1688
+ tableId,
1689
+ rowId,
1660
1690
  );
1661
1691
  const delCell = (tableId, rowId, cellId, forceDel) =>
1662
- fluentTransaction(() =>
1663
- ifNotUndefined(mapGet(tablesMap, tableId), (tableMap) =>
1664
- ifNotUndefined(mapGet(tableMap, rowId), (rowMap) =>
1665
- collHas(rowMap, cellId)
1666
- ? delValidCell(tableId, tableMap, rowId, rowMap, cellId, forceDel)
1667
- : 0,
1692
+ fluentTransaction(
1693
+ (tableId2, rowId2, cellId2) =>
1694
+ ifNotUndefined(mapGet(tablesMap, tableId2), (tableMap) =>
1695
+ ifNotUndefined(mapGet(tableMap, rowId2), (rowMap) =>
1696
+ collHas(rowMap, cellId2)
1697
+ ? delValidCell(
1698
+ tableId2,
1699
+ tableMap,
1700
+ rowId2,
1701
+ rowMap,
1702
+ cellId2,
1703
+ forceDel,
1704
+ )
1705
+ : 0,
1706
+ ),
1668
1707
  ),
1669
- ),
1708
+ tableId,
1709
+ rowId,
1710
+ cellId,
1670
1711
  );
1671
1712
  const delSchema = () =>
1672
1713
  fluentTransaction(() => {
@@ -1762,11 +1803,11 @@ const createStore = () => {
1762
1803
  ),
1763
1804
  );
1764
1805
  const forEachRow = (tableId, rowCallback) =>
1765
- collForEach(mapGet(tablesMap, tableId), (rowMap, rowId) =>
1806
+ collForEach(mapGet(tablesMap, id(tableId)), (rowMap, rowId) =>
1766
1807
  rowCallback(rowId, (cellCallback) => mapForEach(rowMap, cellCallback)),
1767
1808
  );
1768
1809
  const forEachCell = (tableId, rowId, cellCallback) =>
1769
- mapForEach(mapGet(mapGet(tablesMap, tableId), rowId), cellCallback);
1810
+ mapForEach(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), cellCallback);
1770
1811
  const addTablesListener = (listener, mutator) =>
1771
1812
  addListener(listener, tablesListeners[mutator ? 1 : 0]);
1772
1813
  const addTableIdsListener = (listener, mutator) =>
@@ -1878,4 +1919,5 @@ export {
1878
1919
  createSessionPersister,
1879
1920
  createStore,
1880
1921
  defaultSorter,
1922
+ id,
1881
1923
  };