tinybase 2.1.1 → 2.2.0-beta.1

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.
Files changed (114) hide show
  1. package/bin/cli.js +2 -0
  2. package/lib/checkpoints.d.ts +0 -2
  3. package/lib/checkpoints.js +1 -1
  4. package/lib/checkpoints.js.gz +0 -0
  5. package/lib/debug/checkpoints.d.ts +0 -2
  6. package/lib/debug/checkpoints.js +4 -2
  7. package/lib/debug/indexes.d.ts +0 -2
  8. package/lib/debug/indexes.js +2 -1
  9. package/lib/debug/metrics.d.ts +0 -2
  10. package/lib/debug/metrics.js +2 -1
  11. package/lib/debug/queries.d.ts +0 -2
  12. package/lib/debug/queries.js +4 -3
  13. package/lib/debug/relationships.d.ts +0 -2
  14. package/lib/debug/relationships.js +2 -1
  15. package/lib/debug/store.d.ts +1 -1
  16. package/lib/debug/store.js +15 -17
  17. package/lib/debug/tinybase.js +18 -19
  18. package/lib/debug/tools.d.ts +440 -0
  19. package/lib/debug/tools.js +1012 -0
  20. package/lib/es6/checkpoints.d.ts +0 -2
  21. package/lib/es6/checkpoints.js +1 -1
  22. package/lib/es6/checkpoints.js.gz +0 -0
  23. package/lib/es6/indexes.d.ts +0 -2
  24. package/lib/es6/indexes.js +1 -1
  25. package/lib/es6/indexes.js.gz +0 -0
  26. package/lib/es6/metrics.d.ts +0 -2
  27. package/lib/es6/metrics.js +1 -1
  28. package/lib/es6/metrics.js.gz +0 -0
  29. package/lib/es6/queries.d.ts +0 -2
  30. package/lib/es6/queries.js +1 -1
  31. package/lib/es6/queries.js.gz +0 -0
  32. package/lib/es6/relationships.d.ts +0 -2
  33. package/lib/es6/relationships.js +1 -1
  34. package/lib/es6/relationships.js.gz +0 -0
  35. package/lib/es6/store.d.ts +1 -1
  36. package/lib/es6/store.js +1 -1
  37. package/lib/es6/store.js.gz +0 -0
  38. package/lib/es6/tinybase.js +1 -1
  39. package/lib/es6/tinybase.js.gz +0 -0
  40. package/lib/es6/tools.d.ts +440 -0
  41. package/lib/es6/tools.js +1 -0
  42. package/lib/es6/tools.js.gz +0 -0
  43. package/lib/es6/ui-react.js +1 -1
  44. package/lib/es6/ui-react.js.gz +0 -0
  45. package/lib/indexes.d.ts +0 -2
  46. package/lib/indexes.js +1 -1
  47. package/lib/indexes.js.gz +0 -0
  48. package/lib/metrics.d.ts +0 -2
  49. package/lib/metrics.js +1 -1
  50. package/lib/metrics.js.gz +0 -0
  51. package/lib/queries.d.ts +0 -2
  52. package/lib/queries.js +1 -1
  53. package/lib/queries.js.gz +0 -0
  54. package/lib/relationships.d.ts +0 -2
  55. package/lib/relationships.js +1 -1
  56. package/lib/relationships.js.gz +0 -0
  57. package/lib/store.d.ts +1 -1
  58. package/lib/store.js +1 -1
  59. package/lib/store.js.gz +0 -0
  60. package/lib/tinybase.js +1 -1
  61. package/lib/tinybase.js.gz +0 -0
  62. package/lib/tools.d.ts +440 -0
  63. package/lib/tools.js +1 -0
  64. package/lib/tools.js.gz +0 -0
  65. package/lib/umd/checkpoints.d.ts +0 -2
  66. package/lib/umd/checkpoints.js +1 -1
  67. package/lib/umd/checkpoints.js.gz +0 -0
  68. package/lib/umd/indexes.d.ts +0 -2
  69. package/lib/umd/indexes.js +1 -1
  70. package/lib/umd/indexes.js.gz +0 -0
  71. package/lib/umd/metrics.d.ts +0 -2
  72. package/lib/umd/metrics.js +1 -1
  73. package/lib/umd/metrics.js.gz +0 -0
  74. package/lib/umd/queries.d.ts +0 -2
  75. package/lib/umd/queries.js +1 -1
  76. package/lib/umd/queries.js.gz +0 -0
  77. package/lib/umd/relationships.d.ts +0 -2
  78. package/lib/umd/relationships.js +1 -1
  79. package/lib/umd/relationships.js.gz +0 -0
  80. package/lib/umd/store.d.ts +1 -1
  81. package/lib/umd/store.js +1 -1
  82. package/lib/umd/store.js.gz +0 -0
  83. package/lib/umd/tinybase.js +1 -1
  84. package/lib/umd/tinybase.js.gz +0 -0
  85. package/lib/umd/tools.d.ts +440 -0
  86. package/lib/umd/tools.js +1 -0
  87. package/lib/umd/tools.js.gz +0 -0
  88. package/lib/umd-es6/checkpoints.d.ts +0 -2
  89. package/lib/umd-es6/checkpoints.js +1 -1
  90. package/lib/umd-es6/checkpoints.js.gz +0 -0
  91. package/lib/umd-es6/indexes.d.ts +0 -2
  92. package/lib/umd-es6/indexes.js +1 -1
  93. package/lib/umd-es6/indexes.js.gz +0 -0
  94. package/lib/umd-es6/metrics.d.ts +0 -2
  95. package/lib/umd-es6/metrics.js +1 -1
  96. package/lib/umd-es6/metrics.js.gz +0 -0
  97. package/lib/umd-es6/queries.d.ts +0 -2
  98. package/lib/umd-es6/queries.js +1 -1
  99. package/lib/umd-es6/queries.js.gz +0 -0
  100. package/lib/umd-es6/relationships.d.ts +0 -2
  101. package/lib/umd-es6/relationships.js +1 -1
  102. package/lib/umd-es6/relationships.js.gz +0 -0
  103. package/lib/umd-es6/store.d.ts +1 -1
  104. package/lib/umd-es6/store.js +1 -1
  105. package/lib/umd-es6/store.js.gz +0 -0
  106. package/lib/umd-es6/tinybase.js +1 -1
  107. package/lib/umd-es6/tinybase.js.gz +0 -0
  108. package/lib/umd-es6/tools.d.ts +440 -0
  109. package/lib/umd-es6/tools.js +1 -0
  110. package/lib/umd-es6/tools.js.gz +0 -0
  111. package/lib/umd-es6/ui-react.js +1 -1
  112. package/lib/umd-es6/ui-react.js.gz +0 -0
  113. package/package.json +27 -17
  114. package/readme.md +31 -12
package/bin/cli.js ADDED
@@ -0,0 +1,2 @@
1
+ #! /usr/bin/env node
2
+ import{writeFileSync as t,readFileSync as e}from"fs";import{createStore as r}from"tinybase";import{createTools as s}from"tinybase/tools";import{resolve as a}from"path";const o=JSON.parse,i=Object,n=(...t)=>{return e=t=>process.stdout.write(t+"\n"),t.forEach(e);var e},m=t=>o(e(t,"utf8")),p=()=>{var t,e;n("","tinybase <command>","","Usage:",""),t=c,e=([,t,e],r)=>n(` tinybase ${r} ${t}`," - "+e,""),((t,e)=>{t.map(e)})(i.entries(t),(([t,r])=>e(r,t)))},c={help:[p,"","print this message"],version:[()=>n(m("./package.json").version),"","get the current TinyBase version"],getStoreApi:[async(e,o,i)=>{try{const p=s(r().setSchema(m(e))),[c,f]=await p.getPrettyStoreApi(o),h=a(i,o+".d.ts"),u=a(i,o+".ts");t(h,c,"utf8"),t(u,f,"utf8"),n(" Definition: "+h,"Implementation: "+u)}catch{process.stderr.write("ERROR: provide a valid schemaFile, storeName, and outputDir\n")}},"<schemaFile> <storeName> <outputDir>","generate .d.ts and .ts files from a schema file"]};(()=>{const[,,t,...e]=process.argv;(c[t]?.[0]??p)(...e)})();
@@ -913,8 +913,6 @@ export interface Checkpoints {
913
913
  * The createCheckpoints function creates a Checkpoints object, and is the main
914
914
  * entry point into the checkpoints module.
915
915
  *
916
- * It is trivially simple.
917
- *
918
916
  * A given Store can only have one Checkpoints object associated with it. If you
919
917
  * call this function twice on the same Store, your second call will return a
920
918
  * reference to the Checkpoints object created by the first.
@@ -1 +1 @@
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,...t)=>e.push(...t),o=e=>e.pop(),l=e=>e.shift(),c=e=>null==e,i=(e,t,n)=>c(e)?n?.():t(e),a=(e,t)=>e?.has(t)??!1,d=e=>c(e)||0==(e=>e.size)(e),u=(e,t)=>e?.forEach(t),h=(e,t)=>e?.delete(t),p=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>c(n)?(h(e,t),e):e?.set(t,n),k=(e,t,n)=>(a(e,t)||g(e,t,n()),C(e,t)),f=(e,t,r,s,o=0)=>i((r?k:C)(e,t[o],o>n(t)-2?r:p),(l=>{if(o>n(t)-2)return s?.(l)&&g(e,t[o]),l;const c=f(l,t,r,s,o+1);return d(l)&&g(e,t[o]),c})),v=e=>new Set(Array.isArray(e)||c(e)?e:[e]),L=/^\d+$/,w=e=>{let r;const[o,a]=(()=>{const e=[];let t=0;return[()=>l(e)??""+t++,t=>{L.test(t)&&n(e)<1e3&&s(e,t)}]})(),k=p();return[(t,n,s)=>{r??=e();const l=o();var c,i;return g(k,l,[t,n,s]),c=f(n,s??[""],v),i=l,c?.add(i),l},(e,o,...l)=>t(((e,r=[""])=>{const o=[],l=(e,c)=>c==n(r)?s(o,e):null===r[c]?u(e,(e=>l(e,c+1))):t([r[c],null],(t=>l(C(e,t),c+1)));return l(e,0),o})(e,o),(e=>u(e,(e=>C(k,e)[0](r,...o??[],...l))))),e=>i(C(k,e),(([,t,n])=>(f(t,n??[""],void 0,(t=>(h(t,e),d(t)?1:0))),g(k,e),a(e),n))),(e,s,o)=>i(C(k,e),(([e,,l=[]])=>{const i=(...a)=>{const d=n(a);d==n(l)?e(r,...a,...o(a)):c(l[d])?t(s[d](...a),(e=>i(...a,e))):i(...a,l[d])};i()}))]},S=Object.freeze,y=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((h=>{let f,v,L,y=100,z=p(),E=1;const A=p(),I=p(),[M,b,j]=w((()=>Q)),x=p(),B=p(),F=[],O=[],T=(e,t)=>{E=0,h.transaction((()=>u(C(x,t),((t,n)=>u(t,((t,r)=>u(t,((t,s)=>((e,t,n,r,s)=>c(s)?e.delCell(t,n,r,!0):e.setCell(t,n,r,s))(h,n,r,s,t[e]))))))))),E=1},W=e=>{g(x,e),g(B,e),b(I,[e])},$=(e,r)=>t(((e,t)=>e.splice(0,t))(e,r??n(e)),W),m=()=>$(F,n(F)-y),q=h.addCellListener(null,null,null,((e,t,n,r,l,c)=>{if(E){i(f,(()=>{s(F,f),m(),$(O),f=void 0,L=1}));const e=k(z,t,p),a=k(e,n,p),u=k(a,r,(()=>[c,void 0]));u[1]=l,u[0]===l&&d(g(a,r))&&d(g(e,n))&&d(g(z,t))&&(f=o(F),L=1),J()}})),D=(e="")=>(c(f)&&(f=""+v++,g(x,f,z),N(f,e),z=p(),L=1),f),G=()=>{r(F)||(O.unshift(D()),T(0,f),f=o(F),L=1)},H=()=>{r(O)||(s(F,f),f=l(O),T(1,f),L=1)},J=()=>{L&&(b(A),L=0)},K=e=>{const t=D(e);return J(),t},N=(e,t)=>(P(e)&&C(B,e)!==t&&(g(B,e,t),b(I,[e])),Q),P=e=>a(x,e),Q={setSize:e=>(y=e,m(),Q),addCheckpoint:K,setCheckpoint:N,getStore:()=>h,getCheckpointIds:()=>[[...F],f,[...O]],forEachCheckpoint:e=>{return t=e,u(B,((e,n)=>t(n,e)));var t},hasCheckpoint:P,getCheckpoint:e=>C(B,e),goBackward:()=>(G(),J(),Q),goForward:()=>(H(),J(),Q),goTo:t=>{const n=e(F,t)?G:e(O,t)?H:null;for(;!c(n)&&t!=f;)n();return J(),Q},addCheckpointIdsListener:e=>M(e,A),addCheckpointListener:(e,t)=>M(t,I,[e]),delListener:e=>(j(e),Q),clear:()=>($(F),$(O),c(f)||W(f),f=void 0,v=0,K(),Q),destroy:()=>{h.delListener(q)},getListenerStats:()=>({})};return S(Q.clear())}));export{y 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,...t)=>e.push(...t),o=e=>e.pop(),l=e=>e.shift(),c=e=>null==e,i=(e,t,n)=>c(e)?n?.():t(e),a=(e,t)=>e?.has(t)??!1,d=e=>c(e)||0==(e=>e.size)(e),u=(e,t)=>e?.forEach(t),h=(e,t)=>e?.delete(t),p=e=>new Map(e),C=(e,t)=>e?.get(t),g=(e,t,n)=>c(n)?(h(e,t),e):e?.set(t,n),k=(e,t,n)=>(a(e,t)||g(e,t,n()),C(e,t)),f=(e,t,r,s,o=0)=>i((r?k:C)(e,t[o],o>n(t)-2?r:p),(l=>{if(o>n(t)-2)return s?.(l)&&g(e,t[o]),l;const c=f(l,t,r,s,o+1);return d(l)&&g(e,t[o]),c})),v=e=>new Set(Array.isArray(e)||c(e)?e:[e]),L=/^\d+$/,w=Object.freeze,S=(S=>{const y=new WeakMap;return S=>(y.has(S)||y.set(S,(S=>{let y,z,E,A=100,I=p(),M=1;const b=p(),j=p(),[x,B,F]=(e=>{let r;const[o,a]=(()=>{const e=[];let t=0;return[()=>l(e)??""+t++,t=>{L.test(t)&&n(e)<1e3&&s(e,t)}]})(),k=p();return[(e,t,n)=>{r??=V;const s=o();var l;return g(k,s,[e,t,n]),l=s,f(t,n??[""],v)?.add(l),s},(e,o,...l)=>t(((e,r=[""])=>{const o=[],l=(e,c)=>c==n(r)?s(o,e):null===r[c]?u(e,(e=>l(e,c+1))):t([r[c],null],(t=>l(C(e,t),c+1)));return l(e,0),o})(e,o),(e=>u(e,(e=>C(k,e)[0](r,...o??[],...l))))),e=>i(C(k,e),(([,t,n])=>(f(t,n??[""],void 0,(t=>(h(t,e),d(t)?1:0))),g(k,e),a(e),n))),(e,s,o)=>i(C(k,e),(([e,,l=[]])=>{const i=(...a)=>{const d=n(a);d==n(l)?e(r,...a,...o(a)):c(l[d])?t(s[d](...a),(e=>i(...a,e))):i(...a,l[d])};i()}))]})(),O=p(),T=p(),W=[],$=[],m=(e,t)=>{M=0,S.transaction((()=>u(C(O,t),((t,n)=>u(t,((t,r)=>u(t,((t,s)=>((e,t,n,r,s)=>c(s)?e.delCell(t,n,r,!0):e.setCell(t,n,r,s))(S,n,r,s,t[e]))))))))),M=1},q=e=>{g(O,e),g(T,e),B(j,[e])},D=(e,r)=>t(((e,t)=>e.splice(0,t))(e,r??n(e)),q),G=()=>D(W,n(W)-A),H=S.addCellListener(null,null,null,((e,t,n,r,l,c)=>{if(M){i(y,(()=>{s(W,y),G(),D($),y=void 0,E=1}));const e=k(I,t,p),a=k(e,n,p),u=k(a,r,(()=>[c,void 0]));u[1]=l,u[0]===l&&d(g(a,r))&&d(g(e,n))&&d(g(I,t))&&(y=o(W),E=1),P()}})),J=(e="")=>(c(y)&&(y=""+z++,g(O,y,I),R(y,e),I=p(),E=1),y),K=()=>{r(W)||(((e,...t)=>{e.unshift(...t)})($,J()),m(0,y),y=o(W),E=1)},N=()=>{r($)||(s(W,y),y=l($),m(1,y),E=1)},P=()=>{E&&(B(b),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(j,[e])),V),U=e=>a(O,e),V={setSize:e=>(A=e,G(),V),addCheckpoint:Q,setCheckpoint:R,getStore:()=>S,getCheckpointIds:()=>[[...W],y,[...$]],forEachCheckpoint:e=>{return t=e,u(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($,t)?N:null;for(;!c(n)&&t!=y;)n();return P(),V},addCheckpointIdsListener:e=>x(e,b),addCheckpointListener:(e,t)=>x(t,j,[e]),delListener:e=>(F(e),V),clear:()=>(D(W),D($),c(y)||q(y),y=void 0,z=0,Q(),V),destroy:()=>{S.delListener(H)},getListenerStats:()=>({})};return w(V.clear())})(S)),y.get(S))})();export{S as createCheckpoints};
Binary file
@@ -913,8 +913,6 @@ export interface Checkpoints {
913
913
  * The createCheckpoints function creates a Checkpoints object, and is the main
914
914
  * entry point into the checkpoints module.
915
915
  *
916
- * It is trivially simple.
917
- *
918
916
  * A given Store can only have one Checkpoints object associated with it. If you
919
917
  * call this function twice on the same Store, your second call will return a
920
918
  * reference to the Checkpoints object created by the first.
@@ -8,12 +8,14 @@ const arrayReduce = (array, cb, initial) => array.reduce(cb, initial);
8
8
  const arrayClear = (array, to) => array.splice(0, to);
9
9
  const arrayPush = (array, ...values) => array.push(...values);
10
10
  const arrayPop = (array) => array.pop();
11
+ const arrayUnshift = (array, ...values) => array.unshift(...values);
11
12
  const arrayShift = (array) => array.shift();
12
13
 
13
14
  const isUndefined = (thing) => thing == void 0;
14
15
  const ifNotUndefined = (value, then, otherwise) =>
15
16
  isUndefined(value) ? otherwise?.() : then(value);
16
17
  const isArray = (thing) => Array.isArray(thing);
18
+ const test = (regex, subject) => regex.test(subject);
17
19
 
18
20
  const collSizeN = (collSizer) => (coll) =>
19
21
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -84,7 +86,7 @@ const getPoolFunctions = () => {
84
86
  return [
85
87
  () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
86
88
  (id) => {
87
- if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
89
+ if (test(INTEGER, id) && arrayLength(pool) < 1e3) {
88
90
  arrayPush(pool, id);
89
91
  }
90
92
  },
@@ -238,7 +240,7 @@ const createCheckpoints = getCreateFunction((store) => {
238
240
  };
239
241
  const goBackwardImpl = () => {
240
242
  if (!arrayIsEmpty(backwardIds)) {
241
- forwardIds.unshift(addCheckpointImpl());
243
+ arrayUnshift(forwardIds, addCheckpointImpl());
242
244
  updateStore(0, currentId);
243
245
  currentId = arrayPop(backwardIds);
244
246
  checkpointsChanged = 1;
@@ -935,8 +935,6 @@ export interface Indexes {
935
935
  * The createIndexes function creates an Indexes object, and is the main entry
936
936
  * point into the indexes module.
937
937
  *
938
- * It is trivially simple.
939
- *
940
938
  * A given Store can only have one Indexes object associated with it. If you
941
939
  * call this function twice on the same Store, your second call will return a
942
940
  * reference to the Indexes object created by the first.
@@ -26,6 +26,7 @@ const ifNotUndefined = (value, then, otherwise) =>
26
26
  isUndefined(value) ? otherwise?.() : then(value);
27
27
  const isString = (thing) => getTypeOf(thing) == STRING;
28
28
  const isArray = (thing) => Array.isArray(thing);
29
+ const test = (regex, subject) => regex.test(subject);
29
30
 
30
31
  const collSizeN = (collSizer) => (coll) =>
31
32
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -249,7 +250,7 @@ const getPoolFunctions = () => {
249
250
  return [
250
251
  () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
251
252
  (id) => {
252
- if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
253
+ if (test(INTEGER, id) && arrayLength(pool) < 1e3) {
253
254
  arrayPush(pool, id);
254
255
  }
255
256
  },
@@ -796,8 +796,6 @@ export interface Metrics {
796
796
  * The createMetrics function creates a Metrics object, and is the main entry
797
797
  * point into the metrics module.
798
798
  *
799
- * It is trivially simple.
800
- *
801
799
  * A given Store can only have one Metrics object associated with it. If you
802
800
  * call this function twice on the same Store, your second call will return a
803
801
  * reference to the Metrics object created by the first.
@@ -28,6 +28,7 @@ const ifNotUndefined = (value, then, otherwise) =>
28
28
  const isString = (thing) => getTypeOf(thing) == STRING;
29
29
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
30
30
  const isArray = (thing) => Array.isArray(thing);
31
+ const test = (regex, subject) => regex.test(subject);
31
32
  const getUndefined = () => void 0;
32
33
 
33
34
  const collSizeN = (collSizer) => (coll) =>
@@ -318,7 +319,7 @@ const getPoolFunctions = () => {
318
319
  return [
319
320
  () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
320
321
  (id) => {
321
- if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
322
+ if (test(INTEGER, id) && arrayLength(pool) < 1e3) {
322
323
  arrayPush(pool, id);
323
324
  }
324
325
  },
@@ -2992,8 +2992,6 @@ export interface Queries {
2992
2992
  * The createQueries function creates a Queries object, and is the main entry
2993
2993
  * point into the queries module.
2994
2994
  *
2995
- * It is trivially simple.
2996
- *
2997
2995
  * A given Store can only have one Queries object associated with it. If you
2998
2996
  * call this function twice on the same Store, your second call will return a
2999
2997
  * reference to the Queries object created by the first.
@@ -24,6 +24,7 @@ const arrayIsEqual = (array1, array2) =>
24
24
  arrayLength(array1) === arrayLength(array2) &&
25
25
  arrayEvery(array1, (value1, index) => array2[index] === value1);
26
26
  const arrayForEach = (array, cb) => array.forEach(cb);
27
+ const arrayMap = (array, cb) => array.map(cb);
27
28
  const arraySum = (array) => arrayReduce(array, (i, j) => i + j, 0);
28
29
  const arrayLength = (array) => array.length;
29
30
  const arrayIsEmpty = (array) => arrayLength(array) == 0;
@@ -329,8 +330,8 @@ const getCreateFunction = (getFunction) => {
329
330
 
330
331
  const object = Object;
331
332
  const objFreeze = object.freeze;
332
- const objForEach = (obj, cb) =>
333
- arrayForEach(object.entries(obj), ([id, value]) => cb(value, id));
333
+ const objMap = (obj, cb) =>
334
+ arrayMap(object.entries(obj), ([id, value]) => cb(value, id));
334
335
 
335
336
  const createQueries = getCreateFunction((store) => {
336
337
  const createStore = store.createStore;
@@ -744,7 +745,7 @@ const createQueries = getCreateFunction((store) => {
744
745
  destroy,
745
746
  getListenerStats,
746
747
  };
747
- objForEach(
748
+ objMap(
748
749
  {
749
750
  [TABLE]: [1, 1],
750
751
  [ROW_IDS]: [0, 1],
@@ -1170,8 +1170,6 @@ export interface Relationships {
1170
1170
  * The createRelationships function creates a Relationships object, and is the
1171
1171
  * main entry point into the relationships module.
1172
1172
  *
1173
- * It is trivially simple.
1174
- *
1175
1173
  * A given Store can only have one Relationships object associated with it. If
1176
1174
  * you call this function twice on the same Store, your second call will return
1177
1175
  * a reference to the Relationships object created by the first.
@@ -18,6 +18,7 @@ const ifNotUndefined = (value, then, otherwise) =>
18
18
  isUndefined(value) ? otherwise?.() : then(value);
19
19
  const isString = (thing) => getTypeOf(thing) == STRING;
20
20
  const isArray = (thing) => Array.isArray(thing);
21
+ const test = (regex, subject) => regex.test(subject);
21
22
 
22
23
  const collSizeN = (collSizer) => (coll) =>
23
24
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -239,7 +240,7 @@ const getPoolFunctions = () => {
239
240
  return [
240
241
  () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
241
242
  (id) => {
242
- if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
243
+ if (test(INTEGER, id) && arrayLength(pool) < 1e3) {
243
244
  arrayPush(pool, id);
244
245
  }
245
246
  },
@@ -1652,7 +1652,7 @@ export interface Store {
1652
1652
  * ```
1653
1653
  * @category Setter
1654
1654
  */
1655
- setSchema(tablesSchema: Schema): Store;
1655
+ setSchema(schema: Schema): Store;
1656
1656
 
1657
1657
  /**
1658
1658
  * The delTables method lets you remove all of the data in a Store.
@@ -56,6 +56,7 @@ const ifNotUndefined = (value, then, otherwise) =>
56
56
  const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
57
57
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
58
58
  const isArray = (thing) => Array.isArray(thing);
59
+ const test = (regex, subject) => regex.test(subject);
59
60
 
60
61
  const collSizeN = (collSizer) => (coll) =>
61
62
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -75,6 +76,8 @@ const mapKeys = (map) => [...(map?.keys() ?? [])];
75
76
  const mapGet = (map, key) => map?.get(key);
76
77
  const mapForEach = (map, cb) =>
77
78
  collForEach(map, (value, key) => cb(key, value));
79
+ const mapMap = (coll, cb) =>
80
+ arrayMap([...(coll?.entries() ?? [])], ([key, value]) => cb(value, key));
78
81
  const mapSet = (map, key, value) =>
79
82
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
80
83
  const mapEnsure = (map, key, getDefaultValue) => {
@@ -131,8 +134,8 @@ const isObject = (obj) =>
131
134
  const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
132
135
  const objHas = (obj, id) => !isUndefined(objGet(obj, id));
133
136
  const objDel = (obj, id) => delete obj[id];
134
- const objForEach = (obj, cb) =>
135
- arrayForEach(object.entries(obj), ([id, value]) => cb(value, id));
137
+ const objMap = (obj, cb) =>
138
+ arrayMap(object.entries(obj), ([id, value]) => cb(value, id));
136
139
  const objIsEmpty = (obj) => arrayIsEmpty(objIds(obj));
137
140
 
138
141
  const setNew = (entryOrEntries) =>
@@ -150,7 +153,7 @@ const getPoolFunctions = () => {
150
153
  return [
151
154
  () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
152
155
  (id) => {
153
- if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
156
+ if (test(INTEGER, id) && arrayLength(pool) < 1e3) {
154
157
  arrayPush(pool, id);
155
158
  }
156
159
  },
@@ -245,7 +248,7 @@ const validate = (obj, validateChild, onInvalidObj) => {
245
248
  onInvalidObj?.();
246
249
  return false;
247
250
  }
248
- objForEach(obj, (child, id2) => {
251
+ objMap(obj, (child, id2) => {
249
252
  if (!validateChild(child, id2)) {
250
253
  objDel(obj, id2);
251
254
  }
@@ -635,18 +638,14 @@ const createStore = () => {
635
638
  const getTable = (tableId) =>
636
639
  mapToObj(mapGet(tablesMap, id(tableId)), mapToObj);
637
640
  const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
638
- const getSortedRowIds = (tableId, cellId, descending, offset = 0, limit) => {
639
- const cells = [];
640
- mapForEach(mapGet(tablesMap, id(tableId)), (rowId, row) =>
641
- arrayPush(cells, [
642
- isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
643
- rowId,
644
- ]),
645
- );
646
- return arrayMap(
641
+ const getSortedRowIds = (tableId, cellId, descending, offset = 0, limit) =>
642
+ arrayMap(
647
643
  arraySlice(
648
644
  arraySort(
649
- cells,
645
+ mapMap(mapGet(tablesMap, id(tableId)), (row, rowId) => [
646
+ isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
647
+ rowId,
648
+ ]),
650
649
  ([cell1], [cell2]) =>
651
650
  defaultSorter(cell1, cell2) * (descending ? -1 : 1),
652
651
  ),
@@ -655,7 +654,6 @@ const createStore = () => {
655
654
  ),
656
655
  ([, rowId]) => rowId,
657
656
  );
658
- };
659
657
  const getRow = (tableId, rowId) =>
660
658
  mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
661
659
  const getCellIds = (tableId, rowId) =>
@@ -713,7 +711,7 @@ const createStore = () => {
713
711
  (tableId2, rowId2) => {
714
712
  if (validateRow(tableId2, rowId2, partialRow, 1)) {
715
713
  const table = getOrCreateTable(tableId2);
716
- objForEach(partialRow, (cell, cellId) =>
714
+ objMap(partialRow, (cell, cellId) =>
717
715
  setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
718
716
  );
719
717
  }
@@ -1007,7 +1005,7 @@ const createStore = () => {
1007
1005
  getListenerStats,
1008
1006
  createStore,
1009
1007
  };
1010
- objForEach(
1008
+ objMap(
1011
1009
  {
1012
1010
  [TABLES]: [0, tablesListeners],
1013
1011
  [TABLE_IDS]: [0, tableIdsListeners],
@@ -50,6 +50,7 @@ const arraySlice = (array, start, end) => array.slice(start, end);
50
50
  const arrayClear = (array, to) => array.splice(0, to);
51
51
  const arrayPush = (array, ...values) => array.push(...values);
52
52
  const arrayPop = (array) => array.pop();
53
+ const arrayUnshift = (array, ...values) => array.unshift(...values);
53
54
  const arrayShift = (array) => array.shift();
54
55
 
55
56
  const jsonString = (obj) =>
@@ -77,6 +78,7 @@ const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
77
78
  const isString = (thing) => getTypeOf(thing) == STRING;
78
79
  const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
79
80
  const isArray = (thing) => Array.isArray(thing);
81
+ const test = (regex, subject) => regex.test(subject);
80
82
  const getUndefined = () => void 0;
81
83
 
82
84
  const collSizeN = (collSizer) => (coll) =>
@@ -97,6 +99,8 @@ const mapKeys = (map) => [...(map?.keys() ?? [])];
97
99
  const mapGet = (map, key) => map?.get(key);
98
100
  const mapForEach = (map, cb) =>
99
101
  collForEach(map, (value, key) => cb(key, value));
102
+ const mapMap = (coll, cb) =>
103
+ arrayMap([...(coll?.entries() ?? [])], ([key, value]) => cb(value, key));
100
104
  const mapSet = (map, key, value) =>
101
105
  isUndefined(value) ? (collDel(map, key), map) : map?.set(key, value);
102
106
  const mapEnsure = (map, key, getDefaultValue) => {
@@ -317,7 +321,7 @@ const getPoolFunctions = () => {
317
321
  return [
318
322
  () => arrayShift(pool) ?? EMPTY_STRING + nextId++,
319
323
  (id) => {
320
- if (INTEGER.test(id) && arrayLength(pool) < 1e3) {
324
+ if (test(INTEGER, id) && arrayLength(pool) < 1e3) {
321
325
  arrayPush(pool, id);
322
326
  }
323
327
  },
@@ -388,8 +392,8 @@ const isObject = (obj) =>
388
392
  const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
389
393
  const objHas = (obj, id) => !isUndefined(objGet(obj, id));
390
394
  const objDel = (obj, id) => delete obj[id];
391
- const objForEach = (obj, cb) =>
392
- arrayForEach(object.entries(obj), ([id, value]) => cb(value, id));
395
+ const objMap = (obj, cb) =>
396
+ arrayMap(object.entries(obj), ([id, value]) => cb(value, id));
393
397
  const objIsEmpty = (obj) => arrayIsEmpty(objIds(obj));
394
398
 
395
399
  const getCellType = (cell) => {
@@ -487,7 +491,7 @@ const createCheckpoints = getCreateFunction((store) => {
487
491
  };
488
492
  const goBackwardImpl = () => {
489
493
  if (!arrayIsEmpty(backwardIds)) {
490
- forwardIds.unshift(addCheckpointImpl());
494
+ arrayUnshift(forwardIds, addCheckpointImpl());
491
495
  updateStore(0, currentId);
492
496
  currentId = arrayPop(backwardIds);
493
497
  checkpointsChanged = 1;
@@ -1542,7 +1546,7 @@ const createQueries = getCreateFunction((store) => {
1542
1546
  destroy,
1543
1547
  getListenerStats,
1544
1548
  };
1545
- objForEach(
1549
+ objMap(
1546
1550
  {
1547
1551
  [TABLE]: [1, 1],
1548
1552
  [ROW_IDS]: [0, 1],
@@ -1776,7 +1780,7 @@ const validate = (obj, validateChild, onInvalidObj) => {
1776
1780
  onInvalidObj?.();
1777
1781
  return false;
1778
1782
  }
1779
- objForEach(obj, (child, id2) => {
1783
+ objMap(obj, (child, id2) => {
1780
1784
  if (!validateChild(child, id2)) {
1781
1785
  objDel(obj, id2);
1782
1786
  }
@@ -2166,18 +2170,14 @@ const createStore = () => {
2166
2170
  const getTable = (tableId) =>
2167
2171
  mapToObj(mapGet(tablesMap, id(tableId)), mapToObj);
2168
2172
  const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
2169
- const getSortedRowIds = (tableId, cellId, descending, offset = 0, limit) => {
2170
- const cells = [];
2171
- mapForEach(mapGet(tablesMap, id(tableId)), (rowId, row) =>
2172
- arrayPush(cells, [
2173
- isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
2174
- rowId,
2175
- ]),
2176
- );
2177
- return arrayMap(
2173
+ const getSortedRowIds = (tableId, cellId, descending, offset = 0, limit) =>
2174
+ arrayMap(
2178
2175
  arraySlice(
2179
2176
  arraySort(
2180
- cells,
2177
+ mapMap(mapGet(tablesMap, id(tableId)), (row, rowId) => [
2178
+ isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
2179
+ rowId,
2180
+ ]),
2181
2181
  ([cell1], [cell2]) =>
2182
2182
  defaultSorter(cell1, cell2) * (descending ? -1 : 1),
2183
2183
  ),
@@ -2186,7 +2186,6 @@ const createStore = () => {
2186
2186
  ),
2187
2187
  ([, rowId]) => rowId,
2188
2188
  );
2189
- };
2190
2189
  const getRow = (tableId, rowId) =>
2191
2190
  mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
2192
2191
  const getCellIds = (tableId, rowId) =>
@@ -2244,7 +2243,7 @@ const createStore = () => {
2244
2243
  (tableId2, rowId2) => {
2245
2244
  if (validateRow(tableId2, rowId2, partialRow, 1)) {
2246
2245
  const table = getOrCreateTable(tableId2);
2247
- objForEach(partialRow, (cell, cellId) =>
2246
+ objMap(partialRow, (cell, cellId) =>
2248
2247
  setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
2249
2248
  );
2250
2249
  }
@@ -2538,7 +2537,7 @@ const createStore = () => {
2538
2537
  getListenerStats,
2539
2538
  createStore,
2540
2539
  };
2541
- objForEach(
2540
+ objMap(
2542
2541
  {
2543
2542
  [TABLES]: [0, tablesListeners],
2544
2543
  [TABLE_IDS]: [0, tableIdsListeners],