tinybase 2.2.0-beta.0 → 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 (80) hide show
  1. package/bin/cli.js +1 -1
  2. package/lib/checkpoints.js +1 -1
  3. package/lib/checkpoints.js.gz +0 -0
  4. package/lib/debug/queries.js +4 -3
  5. package/lib/debug/store.js +5 -5
  6. package/lib/debug/tinybase.js +6 -6
  7. package/lib/debug/tools.d.ts +155 -5
  8. package/lib/debug/tools.js +488 -431
  9. package/lib/es6/checkpoints.js +1 -1
  10. package/lib/es6/checkpoints.js.gz +0 -0
  11. package/lib/es6/indexes.js +1 -1
  12. package/lib/es6/indexes.js.gz +0 -0
  13. package/lib/es6/metrics.js +1 -1
  14. package/lib/es6/metrics.js.gz +0 -0
  15. package/lib/es6/queries.js +1 -1
  16. package/lib/es6/queries.js.gz +0 -0
  17. package/lib/es6/relationships.js +1 -1
  18. package/lib/es6/relationships.js.gz +0 -0
  19. package/lib/es6/store.js +1 -1
  20. package/lib/es6/store.js.gz +0 -0
  21. package/lib/es6/tinybase.js +1 -1
  22. package/lib/es6/tinybase.js.gz +0 -0
  23. package/lib/es6/tools.d.ts +155 -5
  24. package/lib/es6/tools.js +1 -1
  25. package/lib/es6/tools.js.gz +0 -0
  26. package/lib/es6/ui-react.js +1 -1
  27. package/lib/es6/ui-react.js.gz +0 -0
  28. package/lib/indexes.js +1 -1
  29. package/lib/indexes.js.gz +0 -0
  30. package/lib/metrics.js +1 -1
  31. package/lib/metrics.js.gz +0 -0
  32. package/lib/queries.js +1 -1
  33. package/lib/queries.js.gz +0 -0
  34. package/lib/relationships.js +1 -1
  35. package/lib/relationships.js.gz +0 -0
  36. package/lib/store.js +1 -1
  37. package/lib/store.js.gz +0 -0
  38. package/lib/tinybase.js +1 -1
  39. package/lib/tinybase.js.gz +0 -0
  40. package/lib/tools.d.ts +155 -5
  41. package/lib/tools.js +1 -1
  42. package/lib/tools.js.gz +0 -0
  43. package/lib/umd/checkpoints.js +1 -1
  44. package/lib/umd/checkpoints.js.gz +0 -0
  45. package/lib/umd/indexes.js +1 -1
  46. package/lib/umd/indexes.js.gz +0 -0
  47. package/lib/umd/metrics.js +1 -1
  48. package/lib/umd/metrics.js.gz +0 -0
  49. package/lib/umd/queries.js +1 -1
  50. package/lib/umd/queries.js.gz +0 -0
  51. package/lib/umd/relationships.js +1 -1
  52. package/lib/umd/relationships.js.gz +0 -0
  53. package/lib/umd/store.js +1 -1
  54. package/lib/umd/store.js.gz +0 -0
  55. package/lib/umd/tinybase.js +1 -1
  56. package/lib/umd/tinybase.js.gz +0 -0
  57. package/lib/umd/tools.d.ts +155 -5
  58. package/lib/umd/tools.js +1 -1
  59. package/lib/umd/tools.js.gz +0 -0
  60. package/lib/umd-es6/checkpoints.js +1 -1
  61. package/lib/umd-es6/checkpoints.js.gz +0 -0
  62. package/lib/umd-es6/indexes.js +1 -1
  63. package/lib/umd-es6/indexes.js.gz +0 -0
  64. package/lib/umd-es6/metrics.js +1 -1
  65. package/lib/umd-es6/metrics.js.gz +0 -0
  66. package/lib/umd-es6/queries.js +1 -1
  67. package/lib/umd-es6/queries.js.gz +0 -0
  68. package/lib/umd-es6/relationships.js +1 -1
  69. package/lib/umd-es6/relationships.js.gz +0 -0
  70. package/lib/umd-es6/store.js +1 -1
  71. package/lib/umd-es6/store.js.gz +0 -0
  72. package/lib/umd-es6/tinybase.js +1 -1
  73. package/lib/umd-es6/tinybase.js.gz +0 -0
  74. package/lib/umd-es6/tools.d.ts +155 -5
  75. package/lib/umd-es6/tools.js +1 -1
  76. package/lib/umd-es6/tools.js.gz +0 -0
  77. package/lib/umd-es6/ui-react.js +1 -1
  78. package/lib/umd-es6/ui-react.js.gz +0 -0
  79. package/package.json +6 -5
  80. package/readme.md +21 -2
package/bin/cli.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #! /usr/bin/env node
2
- (()=>{const[,,o,...s]=process.argv;if("pwd"!==o)return console.dir(s),void console.log("Commands: [pwd]");console.log(process.cwd())})();
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)})();
@@ -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)||(((e,...t)=>{e.unshift(...t)})(O,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
@@ -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],
@@ -134,8 +134,8 @@ const isObject = (obj) =>
134
134
  const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
135
135
  const objHas = (obj, id) => !isUndefined(objGet(obj, id));
136
136
  const objDel = (obj, id) => delete obj[id];
137
- const objForEach = (obj, cb) =>
138
- arrayForEach(object.entries(obj), ([id, value]) => cb(value, id));
137
+ const objMap = (obj, cb) =>
138
+ arrayMap(object.entries(obj), ([id, value]) => cb(value, id));
139
139
  const objIsEmpty = (obj) => arrayIsEmpty(objIds(obj));
140
140
 
141
141
  const setNew = (entryOrEntries) =>
@@ -248,7 +248,7 @@ const validate = (obj, validateChild, onInvalidObj) => {
248
248
  onInvalidObj?.();
249
249
  return false;
250
250
  }
251
- objForEach(obj, (child, id2) => {
251
+ objMap(obj, (child, id2) => {
252
252
  if (!validateChild(child, id2)) {
253
253
  objDel(obj, id2);
254
254
  }
@@ -711,7 +711,7 @@ const createStore = () => {
711
711
  (tableId2, rowId2) => {
712
712
  if (validateRow(tableId2, rowId2, partialRow, 1)) {
713
713
  const table = getOrCreateTable(tableId2);
714
- objForEach(partialRow, (cell, cellId) =>
714
+ objMap(partialRow, (cell, cellId) =>
715
715
  setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
716
716
  );
717
717
  }
@@ -1005,7 +1005,7 @@ const createStore = () => {
1005
1005
  getListenerStats,
1006
1006
  createStore,
1007
1007
  };
1008
- objForEach(
1008
+ objMap(
1009
1009
  {
1010
1010
  [TABLES]: [0, tablesListeners],
1011
1011
  [TABLE_IDS]: [0, tableIdsListeners],
@@ -392,8 +392,8 @@ const isObject = (obj) =>
392
392
  const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
393
393
  const objHas = (obj, id) => !isUndefined(objGet(obj, id));
394
394
  const objDel = (obj, id) => delete obj[id];
395
- const objForEach = (obj, cb) =>
396
- arrayForEach(object.entries(obj), ([id, value]) => cb(value, id));
395
+ const objMap = (obj, cb) =>
396
+ arrayMap(object.entries(obj), ([id, value]) => cb(value, id));
397
397
  const objIsEmpty = (obj) => arrayIsEmpty(objIds(obj));
398
398
 
399
399
  const getCellType = (cell) => {
@@ -1546,7 +1546,7 @@ const createQueries = getCreateFunction((store) => {
1546
1546
  destroy,
1547
1547
  getListenerStats,
1548
1548
  };
1549
- objForEach(
1549
+ objMap(
1550
1550
  {
1551
1551
  [TABLE]: [1, 1],
1552
1552
  [ROW_IDS]: [0, 1],
@@ -1780,7 +1780,7 @@ const validate = (obj, validateChild, onInvalidObj) => {
1780
1780
  onInvalidObj?.();
1781
1781
  return false;
1782
1782
  }
1783
- objForEach(obj, (child, id2) => {
1783
+ objMap(obj, (child, id2) => {
1784
1784
  if (!validateChild(child, id2)) {
1785
1785
  objDel(obj, id2);
1786
1786
  }
@@ -2243,7 +2243,7 @@ const createStore = () => {
2243
2243
  (tableId2, rowId2) => {
2244
2244
  if (validateRow(tableId2, rowId2, partialRow, 1)) {
2245
2245
  const table = getOrCreateTable(tableId2);
2246
- objForEach(partialRow, (cell, cellId) =>
2246
+ objMap(partialRow, (cell, cellId) =>
2247
2247
  setCellIntoDefaultRow(tableId2, table, rowId2, cellId, cell),
2248
2248
  );
2249
2249
  }
@@ -2537,7 +2537,7 @@ const createStore = () => {
2537
2537
  getListenerStats,
2538
2538
  createStore,
2539
2539
  };
2540
- objForEach(
2540
+ objMap(
2541
2541
  {
2542
2542
  [TABLES]: [0, tablesListeners],
2543
2543
  [TABLE_IDS]: [0, tableIdsListeners],
@@ -224,21 +224,171 @@ export interface Tools {
224
224
 
225
225
  /**
226
226
  * The getStoreApi method returns a code-generated .d.ts file and a .ts file
227
- * that wraps the schema of a Store.
227
+ * that describe the schema of a Store in an ORM style.
228
228
  *
229
- * This is currently in development, and further documentation is to come.
229
+ * If the Store does not already have an explicit Schema associated with it,
230
+ * the data in the Store will be scanned to attempt to infer a new Schema. The
231
+ * method returns two strings (which should be saved as files) though if no
232
+ * schema can be inferred, the strings will be empty.
233
+ *
234
+ * The method takes a single argument which represents the name you want the
235
+ * generated store object to have in code. You are expected to save the files
236
+ * as `[storeName].d.ts` and `[storeName].ts`, and alongside each other so
237
+ * that the latter can import types from the former.
238
+ *
239
+ * The .d.ts and .ts files that are generated are designed to resemble the
240
+ * main TinyBase `store.d.ts` and `store.ts` files, but provide named types
241
+ * and methods that describe the domain of the schema in the store.
242
+ *
243
+ * For example, from a Store that has a `pets` Table, you will get methods
244
+ * like `getPetsTable`, and types like `PetsRow`, that are more specific
245
+ * versions of the underlying getTable method or the Row type. For example:
246
+ *
247
+ * |Store type|Equivalent generated type|
248
+ * |-|-|
249
+ * |Table|[Table]Table|
250
+ * |Row|[Table]Row|
251
+ * |(Cell) Id|[Table]CellId|
252
+ * |CellCallback|[Table]CellCallback|
253
+ * |...|...|
254
+ *
255
+ * |Store method|Equivalent generated method|
256
+ * |-|-|
257
+ * |setTable|set[Table]Table|
258
+ * |hasRow|has[Table]Row|
259
+ * |getCell|get[Table][Cell]Cell|
260
+ * |...|...|
261
+ *
262
+ * Equivalent to the TinyBase createStore function, a `create[StoreName]`
263
+ * function will also be created. This acts as the main entry point to the
264
+ * generated implementation.
265
+ *
266
+ * Each method is refined correctly to take, or return, the types specified by
267
+ * the schema. For example, if the `pets` Table has a numeric `price` Cell in
268
+ * the schema, the `getPetsPriceCell` method will be typed to return a number.
269
+ *
270
+ * The tables above include just a sample of the generated output. For the
271
+ * full set of methods and types generated by this method, inspect the output
272
+ * directly.
273
+ *
274
+ * @param storeName The name you want to provide to the generated Store, which
275
+ * should also be used to save the `.d.ts` and `.ts` files.
276
+ * @returns A pair of strings representing the contents of the `.d.ts` and
277
+ * `.ts` files.
278
+ * @example
279
+ * This example creates a Tools object and generates code for a Store that
280
+ * already has a Schema.
281
+ * ```js
282
+ * const store = createStore().setSchema({
283
+ * pets: {
284
+ * price: {type: 'number'},
285
+ * },
286
+ * });
287
+ * const [dTs, ts] = createTools(store).getStoreApi('shop');
288
+ *
289
+ * const dTsLines = dTs.split('\n');
290
+ * console.log(dTsLines[3]);
291
+ * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
292
+ * console.log(dTsLines[6]);
293
+ * // -> 'export type PetsRow = {\'price\'?: number;};'
294
+ *
295
+ * const tsLines = ts.split('\n');
296
+ * console.log(tsLines[40]);
297
+ * // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
298
+ * ```
299
+ * @example
300
+ * This example creates a Tools object and generates code for a Store that
301
+ * doesn't already have a Schema.
302
+ * ```js
303
+ * const store = createStore().setTable('pets', {
304
+ * fido: {price: 5},
305
+ * felix: {price: 4},
306
+ * });
307
+ * const [dTs, ts] = createTools(store).getStoreApi('shop');
230
308
  *
309
+ * const dTsLines = dTs.split('\n');
310
+ * console.log(dTsLines[3]);
311
+ * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
312
+ * console.log(dTsLines[6]);
313
+ * // -> 'export type PetsRow = {\'price\': number;};'
314
+ *
315
+ * const tsLines = ts.split('\n');
316
+ * console.log(tsLines[42]);
317
+ * // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
318
+ * ```
231
319
  * @category Modelling
232
320
  * @since v2.2.0
233
321
  */
234
322
  getStoreApi(storeName: string): [string, string];
235
323
 
236
324
  /**
237
- * The getStoreApi method attempts to return a prettified code-generated .d.ts
238
- * file and a .ts file that wraps the schema of a Store.
325
+ * The getPrettyStoreApi method attempts to returns a prettified
326
+ * code-generated .d.ts file and a .ts file that describe the schema of a
327
+ * Store in an ORM style.
328
+ *
329
+ * This is simply a wrapper around the getStoreApi method that attempts to
330
+ * invoke the `prettier` module (which it hopes you have installed) to format
331
+ * the generated code. If `prettier` is not present, the output will resemble
332
+ * that of the underlying getStoreApi method.
239
333
  *
240
- * This is currently in development, and further documentation is to come.
334
+ * The method is asynchronous, so you should use the `await` keyword or handle
335
+ * the results as a promise.
241
336
  *
337
+ * The method takes a single argument which represents the name you want the
338
+ * generated store object to have in code. You are expected to save the files
339
+ * as `[storeName].d.ts` and `[storeName].ts`, and alongside each other so
340
+ * that the latter can import types from the former.
341
+ *
342
+ * See the documentation for the getStoreApi method for details of the content
343
+ * of the generated files.
344
+ *
345
+ * @param storeName The name you want to provide to the generated Store, which
346
+ * should also be used to save the `.d.ts` and `.ts` files.
347
+ * @returns A pair of strings representing the contents of the `.d.ts` and
348
+ * `.ts` files.
349
+ * @example
350
+ * This example creates a Tools object and generates code for a Store that
351
+ * already has a Schema.
352
+ * ```js
353
+ * const store = createStore().setSchema({
354
+ * pets: {
355
+ * price: {type: 'number'},
356
+ * },
357
+ * });
358
+ * const tools = createTools(store);
359
+ * const [dTs, ts] = await tools.getPrettyStoreApi('shop');
360
+ *
361
+ * const dTsLines = dTs.split('\n');
362
+ * console.log(dTsLines[14]);
363
+ * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
364
+ * console.log(dTsLines[19]);
365
+ * // -> 'export type PetsRow = {price?: number};'
366
+ *
367
+ * const tsLines = ts.split('\n');
368
+ * console.log(tsLines[73]);
369
+ * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
370
+ * ```
371
+ * @example
372
+ * This example creates a Tools object and generates code for a Store that
373
+ * doesn't already have a Schema.
374
+ * ```js
375
+ * const store = createStore().setTable('pets', {
376
+ * fido: {price: 5},
377
+ * felix: {price: 4},
378
+ * });
379
+ * const tools = createTools(store);
380
+ * const [dTs, ts] = await tools.getPrettyStoreApi('shop');
381
+ *
382
+ * const dTsLines = dTs.split('\n');
383
+ * console.log(dTsLines[14]);
384
+ * // -> 'export type PetsTable = {[rowId: Id]: PetsRow};'
385
+ * console.log(dTsLines[19]);
386
+ * // -> 'export type PetsRow = {price: number};'
387
+ *
388
+ * const tsLines = ts.split('\n');
389
+ * console.log(tsLines[75]);
390
+ * // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
391
+ * ```
242
392
  * @category Modelling
243
393
  * @since v2.2.0
244
394
  */