tinybase 3.0.0 → 3.0.2

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 (77) hide show
  1. package/lib/cjs/checkpoints.cjs +1 -0
  2. package/lib/cjs/checkpoints.cjs.gz +0 -0
  3. package/lib/cjs/checkpoints.d.ts +959 -0
  4. package/lib/cjs/common.cjs +1 -0
  5. package/lib/cjs/common.cjs.gz +0 -0
  6. package/lib/cjs/common.d.ts +115 -0
  7. package/lib/cjs/indexes.cjs +1 -0
  8. package/lib/cjs/indexes.cjs.gz +0 -0
  9. package/lib/cjs/indexes.d.ts +966 -0
  10. package/lib/cjs/metrics.cjs +1 -0
  11. package/lib/cjs/metrics.cjs.gz +0 -0
  12. package/lib/cjs/metrics.d.ts +827 -0
  13. package/lib/cjs/persisters.cjs +1 -0
  14. package/lib/cjs/persisters.cjs.gz +0 -0
  15. package/lib/cjs/persisters.d.ts +727 -0
  16. package/lib/cjs/queries.cjs +1 -0
  17. package/lib/cjs/queries.cjs.gz +0 -0
  18. package/lib/cjs/queries.d.ts +3024 -0
  19. package/lib/cjs/relationships.cjs +1 -0
  20. package/lib/cjs/relationships.cjs.gz +0 -0
  21. package/lib/cjs/relationships.d.ts +1201 -0
  22. package/lib/cjs/store.cjs +1 -0
  23. package/lib/cjs/store.cjs.gz +0 -0
  24. package/lib/cjs/store.d.ts +5244 -0
  25. package/lib/cjs/tinybase.cjs +1 -0
  26. package/lib/cjs/tinybase.cjs.gz +0 -0
  27. package/lib/cjs/tinybase.d.ts +14 -0
  28. package/lib/cjs/tools.cjs +1 -0
  29. package/lib/cjs/tools.cjs.gz +0 -0
  30. package/lib/cjs/tools.d.ts +512 -0
  31. package/lib/cjs/ui-react.cjs +1 -0
  32. package/lib/cjs/ui-react.cjs.gz +0 -0
  33. package/lib/cjs/ui-react.d.ts +10921 -0
  34. package/lib/cjs-es6/checkpoints.cjs +1 -0
  35. package/lib/cjs-es6/checkpoints.cjs.gz +0 -0
  36. package/lib/cjs-es6/checkpoints.d.ts +959 -0
  37. package/lib/cjs-es6/common.cjs +1 -0
  38. package/lib/cjs-es6/common.cjs.gz +0 -0
  39. package/lib/cjs-es6/common.d.ts +115 -0
  40. package/lib/cjs-es6/indexes.cjs +1 -0
  41. package/lib/cjs-es6/indexes.cjs.gz +0 -0
  42. package/lib/cjs-es6/indexes.d.ts +966 -0
  43. package/lib/cjs-es6/metrics.cjs +1 -0
  44. package/lib/cjs-es6/metrics.cjs.gz +0 -0
  45. package/lib/cjs-es6/metrics.d.ts +827 -0
  46. package/lib/cjs-es6/persisters.cjs +1 -0
  47. package/lib/cjs-es6/persisters.cjs.gz +0 -0
  48. package/lib/cjs-es6/persisters.d.ts +727 -0
  49. package/lib/cjs-es6/queries.cjs +1 -0
  50. package/lib/cjs-es6/queries.cjs.gz +0 -0
  51. package/lib/cjs-es6/queries.d.ts +3024 -0
  52. package/lib/cjs-es6/relationships.cjs +1 -0
  53. package/lib/cjs-es6/relationships.cjs.gz +0 -0
  54. package/lib/cjs-es6/relationships.d.ts +1201 -0
  55. package/lib/cjs-es6/store.cjs +1 -0
  56. package/lib/cjs-es6/store.cjs.gz +0 -0
  57. package/lib/cjs-es6/store.d.ts +5244 -0
  58. package/lib/cjs-es6/tinybase.cjs +1 -0
  59. package/lib/cjs-es6/tinybase.cjs.gz +0 -0
  60. package/lib/cjs-es6/tinybase.d.ts +14 -0
  61. package/lib/cjs-es6/tools.cjs +1 -0
  62. package/lib/cjs-es6/tools.cjs.gz +0 -0
  63. package/lib/cjs-es6/tools.d.ts +512 -0
  64. package/lib/cjs-es6/ui-react.cjs +1 -0
  65. package/lib/cjs-es6/ui-react.cjs.gz +0 -0
  66. package/lib/cjs-es6/ui-react.d.ts +10921 -0
  67. package/lib/debug/tools.js +2 -1
  68. package/lib/es6/tools.js +1 -1
  69. package/lib/es6/tools.js.gz +0 -0
  70. package/lib/tools.js +1 -1
  71. package/lib/tools.js.gz +0 -0
  72. package/lib/umd/tools.js +1 -1
  73. package/lib/umd/tools.js.gz +0 -0
  74. package/lib/umd-es6/tools.js +1 -1
  75. package/lib/umd-es6/tools.js.gz +0 -0
  76. package/package.json +28 -20
  77. package/readme.md +1 -1
@@ -936,7 +936,7 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
936
936
  `getValues`,
937
937
  EMPTY_STRING,
938
938
  valuesType,
939
- storeMethod('getValues'),
939
+ storeMethod('getValues', EMPTY_STRING, valuesType),
940
940
  getTheContentOfTheStoreDoc(0, 2),
941
941
  );
942
942
  addMethod(
@@ -1050,6 +1050,7 @@ const getStoreApi = (tablesSchema, valuesSchema, module) => {
1050
1050
  1,
1051
1051
  moduleDefinition,
1052
1052
  valuesType,
1053
+ valuesWhenSetType,
1053
1054
  valueIdType,
1054
1055
  valueCallbackType,
1055
1056
  valuesListenerType,
package/lib/es6/tools.js CHANGED
@@ -1 +1 @@
1
- const e=e=>typeof e,a="",l=e(a),t=e(!0),o=e(0),n="type",s="default",r=(e,a)=>e.every(a),d=(e,a)=>e.sort(a),$=(e,a)=>e.forEach(a),i=(e,a)=>e.map(a),u=e=>e.length,I=e=>0==u(e),c=(e,...a)=>e.push(...a),b=e=>e.pop(),w=(e,...a)=>e.unshift(...a),h=e=>e.shift(),g=JSON.parse,C=isFinite,V=(e,a)=>e instanceof a,T=e=>null==e,v=e=>e==l||e==t,f=a=>e(a)==l,R=e=>Array.isArray(e),m=a=>{const l=e(a);return v(l)||l==o&&C(a)?l:void 0},p=(e,a)=>{var l;return null!=(l=null==e?void 0:e.has(a))&&l},L=e=>{var a;return[...null!=(a=null==e?void 0:e.values())?a:[]]},y=(e,a)=>null==e?void 0:e.forEach(a),S=(e,a)=>null==e?void 0:e.delete(a),k=e=>new Map(e),J=(e,a)=>null==e?void 0:e.get(a),E=(e,a)=>y(e,((e,l)=>a(l,e))),O=(e,a)=>{var l;return i([...null!=(l=null==e?void 0:e.entries())?l:[]],(([e,l])=>a(l,e)))},j=(e,a,l)=>T(l)?(S(e,a),e):null==e?void 0:e.set(a,l),x=(e,a,l)=>(p(e,a)||j(e,a,l()),J(e,a)),A=e=>new Set(R(e)||T(e)?e:[e]),P=(e,a)=>null==e?void 0:e.add(a),D=e=>[e,e],N=()=>[k(),k()],G=/[^A-Za-z]+/,z=/[^A-Za-z0-9]+/,F=/^( *)\/\*\* *(.*?) *\*\/$/gm,W=(e,a,l)=>e.substring(a,l),M=e=>e.toUpperCase(),Z=e=>e.toLowerCase(),_=(e,a,l,t=1)=>{const o=`${a}${1==t?"":t}`;return p(e,o)?_(e,a,l,t+1):(j(e,o,l),o)},Q=e=>e.replace(F,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,l=a)=>e.join(l),B=e=>e.flat(1e3),H=(e,a=0)=>q(i(e.split(z),((e,l)=>(l>0||a?M:Z)(W(e,0,1))+W(e,1)))),K=e=>M(q((e&&!G.test(e[0])?e:" "+e).split(z),"_")),X=e=>`/** ${e}. */`,Y=()=>{const e=N(),l=k(),t=k(),o=k();return[(...e)=>q(B(e),"\n"),(a,l,...t)=>$(t,(t=>P(x(e[a],l,A),t))),(e,a,t)=>_(l,e,[a,t]),(e,a,l,o,n,s="")=>_(t,e,[a,l,o,n,s]),(e,a,l)=>_(o,e,R(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>J(o,e)===a?e:_(o,e,a),l=>[...d(O(e[l],((e,a)=>`import {${q(d(L(e)),", ")}} from '${a}';`))),a],()=>O(l,(([e,l],t)=>[X(l),`export type ${t} = ${e};`,a])),e=>O(t,(([l,t,o,n,s],r)=>{const d=e?[`${r}: ${s}(${l}): ${t} => ${o},`]:[`${r}${s}(${l}): ${t};`];return e||w(d,X(n)),c(d,a),d})),()=>O(o,((e,l)=>(e=R(e)?e:[e],c(e,b(e)+";"),[`const ${l} = ${h(e)}`,e,a])))]},ee=Object,ae=ee.keys,le=ee.freeze,te=e=>V(e,ee)&&e.constructor==ee,oe=(e,a)=>i(ee.entries(e),(([e,l])=>a(l,e))),ne=e=>te(e)&&I(ae(e)),se=e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))},re="the Store",de="A function for",$e="export",ie="listener",ue=" | undefined",Ie=`Registers a ${ie} that will be called`,ce="Represents",be=" => void",we="the end of the transaction",he="the specified Row",ge="a string serialization of",Ce=(e=0,a=0)=>`the ${De[e]}content of${a?" "+re:""}`,Ve=(e,a=0,l=0)=>`${Ae[e]} ${Ce(a,1)}${l?" when set":""}`,Te=(e,a=0)=>`${ce} a Row when ${a?"s":"g"}etting ${Ce()} the '${e}' Table`,ve=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,fe=(e,a)=>`Calls a function for each ${e} in ${a}`,Re=(e,a=re)=>`Gets whether ${e} exists in ${a}`,me=e=>"A function that takes "+e,pe=(e,a=0)=>`${de} listening to changes to ${Pe[e]} in ${Pe[a]}`,Le=(e,l,t=0)=>`${Ie} whenever ${e} in ${l} change`+(t?a:"s"),ye=e=>`the '${e}' Table`,Se=e=>`${he} in ${ye(e)}`,ke=e=>`the '${e}' Cell`,Je=e=>`the '${e}' Value`,Ee=(e,a=0)=>`${Ae[a]} ${Ce()} ${ye(e)}`,Oe=(e,a=0)=>`${Ae[a]} ${Ce()} ${Se(e)}`,je=(e,a,l=0)=>`${Ae[l]} ${ke(a)} for ${Se(e)}`,xe=(e,a=0)=>`${Ae[a]} ${Je(e)}`,Ae=["Gets","Sets","Sets part of","Deletes",ce,"Gets "+ge,"Sets "+ge,Ie+" whenever"],Pe=[re,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],De=["","tabular ","keyed value "],Ne=["DoRollback","Id","IdOrNull","Ids","Json","Store"],Ge=(e,l=a,t=a)=>`store.${e}(${l})${t?" as "+t:a}`,ze=(e,l=a)=>`fluent(() => ${Ge(e,l)})`,Fe=(e,l=a,t=a)=>`store.${e}(${l?l+", ":a}proxy(${ie})${t?", "+t:a})`,We=(e,l,o)=>{if(ne(e)&&ne(l))return D(a);const[r,d,$,i,u,I,b,w,h,g]=Y(),C=`./${H(o)}.d`,V=H(o,1),v=H(V),R=[],m=k(),p=l=>oe(e,((e,t)=>l(t,x(m,t,(()=>{const e=H(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ce} the '${t}' Table`),$(e+"Row",`{${q(y(t,((e,l,t)=>`'${e}'${T(t)?"?":a}: ${l};`))," ")}}`,Te(t)),$(e+"RowWhenSet",`{${q(y(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,Te(t,1)),$(e+"CellId",q(y(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(y(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${be}`,me(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${be})${be}`,me(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),H(t,1),I(K(t),`'${t}'`)))),y=(a,l)=>oe(e[a],((e,a)=>l(a,e[n],e[s],I(K(a),`'${a}'`),H(a,1)))),S=e=>oe(l,((a,l)=>e(l,a[n],a[s],I(K(l),`'${l}'`),H(l,1))));if(d(1,C,V,`create${V} as create${V}Decl`),!ne(e)){const e=$("Tables",`{${q(p(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Ve(4,1)),l=$("TableId",q(p((e=>`'${e}'`))," | "),"A Table Id in "+re),o=$("TableCallback",`(...[tableId, rowCallback]: ${q(p(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${be}]`))," | ")})${be}`,me("a Table Id, and a Row iterator")),r=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(p(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${v}: ${V}, getCellChange: ${r}${ue})${be}`,pe(1)),b=$("TableIdsListener",`(${v}: ${V})${be}`,pe(2)),w=$("TableListener",`(${v}: ${V}, tableId: ${l}, getCellChange: ${r}${ue})${be}`,pe(3)),h=$("RowIdsListener",`(${v}: ${V}, tableId: ${l})`+be,pe(4,3)),g=$("RowListener",`(${v}: ${V}, tableId: ${l}, rowId: Id, getCellChange: ${r}${ue})${be}`,pe(5,3)),m=$("CellIdsListener",`(${v}: ${V}, tableId: ${l}, rowId: Id)`+be,pe(6,5)),S=$("CellListener",`(...[${v}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(B(p((e=>y(e,((a,l)=>`[${v}: ${V}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${ue}, oldCell: ${l}${ue}, getCellChange: ${r} | undefined]`)))))," | ")})${be}`,pe(7,5)),J=$("InvalidCellListener",`(${v}: ${V}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${be}`,pe(8));i("hasTables",a,t,Ge("hasTables"),Re("any Table")),i("getTables",a,e,Ge("getTables"),Ve(0,1)),i("setTables","tables: "+e,V,ze("setTables","tables"),Ve(1,1)),i("delTables",a,V,ze("delTables"),Ve(3,1)),i("getTableIds",a,l+"[]",Ge("getTableIds",a,l+"[]"),ve("Table",re)),i("forEachTable","tableCallback: "+o,"void",Ge("forEachTable","tableCallback as any"),fe("Table",re));const O=k();p(((e,[l,o,n,s,r,$],u,I)=>{d(1,C,l,o,n,s,r,$),i(`has${u}Table`,a,t,Ge("hasTable",I),Re(ye(e))),i(`get${u}Table`,a,l,Ge("getTable",I,l),Ee(e)),i(`set${u}Table`,"table: "+l,V,ze("setTable",I+", table"),Ee(e,1)),i(`del${u}Table`,a,V,ze("delTable",I),Ee(e,3)),i(`get${u}RowIds`,a,"Ids",Ge("getRowIds",I),ve("Row",ye(e))),i(`get${u}SortedRowIds`,`cellId?: ${s}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ge("getSortedRowIds",I+", cellId, descending, offset, limit"),ve("Row",ye(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",Ge("forEachRow",I+", rowCallback as any"),fe("Row",ye(e))),i(`has${u}Row`,"rowId: Id",t,Ge("hasRow",I+", rowId"),Re(he,ye(e))),i(`get${u}Row`,"rowId: Id",o,Ge("getRow",I+", rowId",o),Oe(e)),i(`set${u}Row`,"rowId: Id, row: "+n,V,ze("setRow",I+", rowId, row"),Oe(e,1)),i(`add${u}Row`,"row: "+n,"Id"+ue,Ge("addRow",I+", row"),"Adds a new Row to "+ye(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+n,V,ze("setPartialRow",I+", rowId, partialRow"),Oe(e,2)),i(`del${u}Row`,"rowId: Id",V,ze("delRow",I+", rowId"),Oe(e,3)),i(`get${u}CellIds`,"rowId: Id",s+"[]",Ge("getCellIds",I+", rowId",s+"[]"),ve("Cell",Se(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+r,"void",Ge("forEachCell",I+", rowId, cellCallback as any"),fe("Cell",Se(e))),y(e,((l,o,n,s,r)=>{const d="Map"+H(o,1);j(O,o,d),i(`has${u}${r}Cell`,"rowId: Id",t,Ge("hasCell",`${I}, rowId, ${s}`),Re(ke(l),Se(e)));const $=`${o}${T(n)?ue:a}`;i(`get${u}${r}Cell`,"rowId: Id",$,Ge("getCell",`${I}, rowId, ${s}`,$),je(e,l)),i(`set${u}${r}Cell`,`rowId: Id, cell: ${o} | ${d}`,V,ze("setCell",`${I}, rowId, ${s}, cell as any`),je(e,l,1)),i(`del${u}${r}Cell`,"rowId: Id",V,ze("delCell",`${I}, rowId, ${s}`),je(e,l,3))}))})),i("getTablesJson",a,"Json",Ge("getTablesJson"),Ve(5,1)),i("setTablesJson","tablesJson: Json",V,ze("setTablesJson","tablesJson"),Ve(6,1)),i("addTablesListener",`${ie}: ${u}, mutator?: boolean`,"Id",Fe("addTablesListener",a,"mutator"),Ve(7,1)+" changes"),i("addTableIdsListener",`${ie}: ${b}, mutator?: boolean`,"Id",Fe("addTableIdsListener",a,"mutator"),Le("the Table Ids",re,1)),i("addTableListener",`tableId: ${l} | null, ${ie}: ${w}, mutator?: boolean`,"Id",Fe("addTableListener","tableId","mutator"),Le("a Table",re)),i("addRowIdsListener",`tableId: ${l} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Fe("addRowIdsListener","tableId","mutator"),Le("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${l} | null, rowId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Fe("addRowListener","tableId, rowId","mutator"),Le("a Row","a Table")),i("addCellIdsListener",`tableId: ${l} | null, rowId: IdOrNull, ${ie}: ${m}, mutator?: boolean`,"Id",Fe("addCellIdsListener","tableId, rowId","mutator"),Le("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${l} | null, rowId: IdOrNull, cellId: ${q(p(((e,a)=>a[3]))," | ")} | null, ${ie}: ${S}, mutator?: boolean`,"Id",Fe("addCellListener","tableId, rowId, cellId","mutator"),Le("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${ie}: ${J}, mutator?: boolean`,"Id",Fe("addInvalidCellListener","tableId, rowId, cellId","mutator"),Ie+" whenever an invalid Cell change was attempted"),E(O,((e,a)=>$(a,`(cell: ${e}${ue}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(1,C,e,l,o,u,b,w,h,g,m,S,J,...L(O)),d(0,"tinybase","CellChange"),c(R,".setTablesSchema({",B(p(((e,l,t,o)=>[`[${o}]: {`,...y(e,((e,l,t,o)=>`[${o}]: {[${I(K(n),`'${n}'`)}]: ${I(K(l),`'${l}'`)}${T(t)?a:`, [${I(K(s),`'${s}'`)}]: ${f(t)?I(K(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!ne(l)){const e=$("Values",`{${q(S(((e,l,t)=>`'${e}'${T(t)?"?":a}: ${l};`))," ")}}`,Ve(4,2)),l=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ve(4,2,1)),o=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+re),r=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${be}`,me("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${o}) => ValueChange`,de+" returning information about any Value's changes during a transaction"),b=$("ValuesListener",`(${v}: ${V}, getValueChange: ${u}${ue})`+be,pe(9)),w=$("ValueIdsListener",`(${v}: ${V})${be}`,pe(10)),h=$("ValueListener",`(...[${v}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${v}: ${V}, valueId: '${e}', newValue: ${a}${ue}, oldValue: ${a}${ue}, getValueChange: ${u} | undefined]`))," | ")})${be}`,pe(11)),g=$("InvalidValueListener",`(${v}: ${V}, valueId: Id, invalidValues: any[])${be}`,pe(12));i("hasValues",a,t,Ge("hasValues"),Re("any Value")),i("getValues",a,e,Ge("getValues"),Ve(0,2)),i("setValues","values: "+l,V,ze("setValues","values"),Ve(1,2)),i("setPartialValues","partialValues: "+l,V,ze("setPartialValues","partialValues"),Ve(2,2)),i("delValues",a,V,ze("delValues"),Ve(3,2)),i("getValueIds",a,o+"[]",Ge("getValueIds",a,o+"[]"),ve("Value",re)),i("forEachValue","valueCallback: "+r,"void",Ge("forEachValue","valueCallback as any"),fe("Value",re)),S(((e,l,o,n,s)=>{i(`has${s}Value`,a,t,Ge("hasValue",n),Re(Je(e))),i(`get${s}Value`,a,l,Ge("getValue",n,l),xe(e)),i(`set${s}Value`,"value: "+l,V,ze("setValue",n+", value"),xe(e,1)),i(`del${s}Value`,a,V,ze("delValue",n),xe(e,3))})),i("getValuesJson",a,"Json",Ge("getValuesJson"),Ve(5,2)),i("setValuesJson","valuesJson: Json",V,ze("setValuesJson","valuesJson"),Ve(6,2)),i("addValuesListener",`${ie}: ${b}, mutator?: boolean`,"Id",Fe("addValuesListener",a,"mutator"),Ve(7,2)+" changes"),i("addValueIdsListener",`${ie}: ${w}, mutator?: boolean`,"Id",Fe("addValueIdsListener",a,"mutator"),Le("the Value Ids",re,1)),i("addValueListener",`valueId: ${o} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Fe("addValueListener","valueId","mutator"),Le("a Value",re)),i("addInvalidValueListener",`valueId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Fe("addInvalidValueListener","valueId","mutator"),Ie+" whenever an invalid Cell change was attempted"),d(1,C,e,o,r,b,w,h,g),d(0,"tinybase","ValueChange"),c(R,".setValuesSchema({",S(((e,l,t,o)=>[`[${o}]: {[${I(K(n),`'${n}'`)}]: ${I(K(l),`'${l}'`)}${T(t)?a:`, [${I(K(s),`'${s}'`)}]: ${f(t)?I(K(t),`'${t}'`):t}`}},`])),"})")}d(0,"tinybase",...Ne);const J=$("TransactionListener",`(${v}: ${V}, cellsTouched: boolean, valuesTouched: boolean)${be}`,de+" listening to the completion of a transaction");return i("getJson",a,"Json",Ge("getJson"),Ve(5)),i("setJson","json: Json",V,ze("setJson","json"),Ve(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",Ge("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",a,V,ze("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",V,ze("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${ie}: ${J}`,"Id",Fe("addWillFinishTransactionListener"),`${Ie} just before ${we}`),i("addDidFinishTransactionListener",`${ie}: ${J}`,"Id",Fe("addDidFinishTransactionListener"),`${Ie} just after ${we}`),i("callListener",ie+"Id: Id",V,ze("callListener",ie+"Id"),`Manually provoke a ${ie} to be called`),i("delListener",ie+"Id: Id",V,ze("delListener",ie+"Id"),`Remove a ${ie} that was previously added to ${re}`),i("getStore",a,"Store","store",Ae[0]+" the underlying Store object"),d(1,"tinybase","createStore",...Ne),d(1,C,V,`create${V} as create${V}Decl`,J),I("store",["createStore()",...R]),u("fluent","actions: () => Store",["actions();",`return ${v};`]),u("proxy",ie+": any",`(_: Store, ...args: any[]) => ${ie}(${v}, ...args)`),I(v,["{",...h(1),"}"]),[r(...b(0),...w(),`${$e} interface ${V} {`,...h(0),"}",a,X(`Creates a ${V} object`),`${$e} function create${V}(): ${V};`),r(...b(1),`${$e} const create${V}: typeof create${V}Decl = () => {`,...g(),`return Object.freeze(${v});`,"};")]};var Me=Object.defineProperty,Ze=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Ue=(e,a,l)=>a in e?Me(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,qe=(e,a)=>{for(var l in a||(a={}))_e.call(a,l)&&Ue(e,l,a[l]);if(Ze)for(var l of Ze(a))Qe.call(a,l)&&Ue(e,l,a[l]);return e},Be=(e,a,l)=>new Promise(((t,o)=>{var n=e=>{try{r(l.next(e))}catch(e){o(e)}},s=e=>{try{r(l.throw(e))}catch(e){o(e)}},r=e=>e.done?t(e.value):Promise.resolve(e.value).then(n,s);r((l=l.apply(e,a)).next())}));const He={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ke=se((e=>{const a=()=>{const a=g(e.getTablesSchemaJson());return!ne(a)||r(e.getTableIds(),(l=>{const t=e.getRowIds(l),o=k();if(r(t,(a=>r(e.getCellIds(l,a),(t=>{const n=e.getCell(l,a,t),s=x(o,t,(()=>[m(n),k(),[0],0])),[r,d,[$]]=s,i=x(d,n,(()=>0))+1;return i>$&&(s[2]=[i,n]),j(d,n,i),s[3]++,r==m(n)})))))return a[l]={},y(o,(([e,,[,o],r],d)=>{a[l][d]=qe({[n]:e},r==u(t)?{[s]:o}:{})})),1}))?a:{}},l=()=>{const a=g(e.getValuesSchemaJson());return ne(a)&&e.forEachValue(((e,l)=>{a[e]={[n]:m(l)}})),a},t=e=>We(a(),l(),e),o=e=>Be(void 0,null,(function*(){let a;try{a=(yield import("prettier")).format}catch(e){a=e=>e}return i(t(e),(e=>Q(a(e,He))))}));return le({getStoreStats:a=>{let l=0,t=0,o=0;const n={};return e.forEachTable(((e,s)=>{l++;let r=0,d=0;const $={};s(((e,l)=>{r++;let t=0;l((()=>t++)),d+=t,a&&($[e]={rowCells:t})})),t+=r,o+=d,a&&(n[e]={tableRows:r,tableCells:d,rows:$})})),qe({totalTables:l,totalRows:t,totalCells:o,totalValues:u(e.getValueIds()),jsonLength:U(e.getJson())},a?{detail:{tables:n}}:{})},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:o,getStore:()=>e})}));export{Ke as createTools};
1
+ const e=e=>typeof e,a="",l=e(a),t=e(!0),o=e(0),n="type",s="default",r=(e,a)=>e.every(a),d=(e,a)=>e.sort(a),$=(e,a)=>e.forEach(a),i=(e,a)=>e.map(a),u=e=>e.length,I=e=>0==u(e),c=(e,...a)=>e.push(...a),b=e=>e.pop(),w=(e,...a)=>e.unshift(...a),h=e=>e.shift(),g=JSON.parse,C=isFinite,V=(e,a)=>e instanceof a,T=e=>null==e,v=e=>e==l||e==t,f=a=>e(a)==l,R=e=>Array.isArray(e),m=a=>{const l=e(a);return v(l)||l==o&&C(a)?l:void 0},p=(e,a)=>{var l;return null!=(l=null==e?void 0:e.has(a))&&l},L=e=>{var a;return[...null!=(a=null==e?void 0:e.values())?a:[]]},y=(e,a)=>null==e?void 0:e.forEach(a),S=(e,a)=>null==e?void 0:e.delete(a),k=e=>new Map(e),J=(e,a)=>null==e?void 0:e.get(a),E=(e,a)=>y(e,((e,l)=>a(l,e))),O=(e,a)=>{var l;return i([...null!=(l=null==e?void 0:e.entries())?l:[]],(([e,l])=>a(l,e)))},j=(e,a,l)=>T(l)?(S(e,a),e):null==e?void 0:e.set(a,l),x=(e,a,l)=>(p(e,a)||j(e,a,l()),J(e,a)),A=e=>new Set(R(e)||T(e)?e:[e]),P=(e,a)=>null==e?void 0:e.add(a),D=e=>[e,e],N=()=>[k(),k()],G=/[^A-Za-z]+/,z=/[^A-Za-z0-9]+/,F=/^( *)\/\*\* *(.*?) *\*\/$/gm,W=(e,a,l)=>e.substring(a,l),M=e=>e.toUpperCase(),Z=e=>e.toLowerCase(),_=(e,a,l,t=1)=>{const o=`${a}${1==t?"":t}`;return p(e,o)?_(e,a,l,t+1):(j(e,o,l),o)},Q=e=>e.replace(F,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,l=a)=>e.join(l),B=e=>e.flat(1e3),H=(e,a=0)=>q(i(e.split(z),((e,l)=>(l>0||a?M:Z)(W(e,0,1))+W(e,1)))),K=e=>M(q((e&&!G.test(e[0])?e:" "+e).split(z),"_")),X=e=>`/** ${e}. */`,Y=()=>{const e=N(),l=k(),t=k(),o=k();return[(...e)=>q(B(e),"\n"),(a,l,...t)=>$(t,(t=>P(x(e[a],l,A),t))),(e,a,t)=>_(l,e,[a,t]),(e,a,l,o,n,s="")=>_(t,e,[a,l,o,n,s]),(e,a,l)=>_(o,e,R(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>J(o,e)===a?e:_(o,e,a),l=>[...d(O(e[l],((e,a)=>`import {${q(d(L(e)),", ")}} from '${a}';`))),a],()=>O(l,(([e,l],t)=>[X(l),`export type ${t} = ${e};`,a])),e=>O(t,(([l,t,o,n,s],r)=>{const d=e?[`${r}: ${s}(${l}): ${t} => ${o},`]:[`${r}${s}(${l}): ${t};`];return e||w(d,X(n)),c(d,a),d})),()=>O(o,((e,l)=>(e=R(e)?e:[e],c(e,b(e)+";"),[`const ${l} = ${h(e)}`,e,a])))]},ee=Object,ae=ee.keys,le=ee.freeze,te=e=>V(e,ee)&&e.constructor==ee,oe=(e,a)=>i(ee.entries(e),(([e,l])=>a(l,e))),ne=e=>te(e)&&I(ae(e)),se=e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))},re="the Store",de="A function for",$e="export",ie="listener",ue=" | undefined",Ie=`Registers a ${ie} that will be called`,ce="Represents",be=" => void",we="the end of the transaction",he="the specified Row",ge="a string serialization of",Ce=(e=0,a=0)=>`the ${De[e]}content of${a?" "+re:""}`,Ve=(e,a=0,l=0)=>`${Ae[e]} ${Ce(a,1)}${l?" when set":""}`,Te=(e,a=0)=>`${ce} a Row when ${a?"s":"g"}etting ${Ce()} the '${e}' Table`,ve=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,fe=(e,a)=>`Calls a function for each ${e} in ${a}`,Re=(e,a=re)=>`Gets whether ${e} exists in ${a}`,me=e=>"A function that takes "+e,pe=(e,a=0)=>`${de} listening to changes to ${Pe[e]} in ${Pe[a]}`,Le=(e,l,t=0)=>`${Ie} whenever ${e} in ${l} change`+(t?a:"s"),ye=e=>`the '${e}' Table`,Se=e=>`${he} in ${ye(e)}`,ke=e=>`the '${e}' Cell`,Je=e=>`the '${e}' Value`,Ee=(e,a=0)=>`${Ae[a]} ${Ce()} ${ye(e)}`,Oe=(e,a=0)=>`${Ae[a]} ${Ce()} ${Se(e)}`,je=(e,a,l=0)=>`${Ae[l]} ${ke(a)} for ${Se(e)}`,xe=(e,a=0)=>`${Ae[a]} ${Je(e)}`,Ae=["Gets","Sets","Sets part of","Deletes",ce,"Gets "+ge,"Sets "+ge,Ie+" whenever"],Pe=[re,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],De=["","tabular ","keyed value "],Ne=["DoRollback","Id","IdOrNull","Ids","Json","Store"],Ge=(e,l=a,t=a)=>`store.${e}(${l})${t?" as "+t:a}`,ze=(e,l=a)=>`fluent(() => ${Ge(e,l)})`,Fe=(e,l=a,t=a)=>`store.${e}(${l?l+", ":a}proxy(${ie})${t?", "+t:a})`,We=(e,l,o)=>{if(ne(e)&&ne(l))return D(a);const[r,d,$,i,u,I,b,w,h,g]=Y(),C=`./${H(o)}.d`,V=H(o,1),v=H(V),R=[],m=k(),p=l=>oe(e,((e,t)=>l(t,x(m,t,(()=>{const e=H(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ce} the '${t}' Table`),$(e+"Row",`{${q(y(t,((e,l,t)=>`'${e}'${T(t)?"?":a}: ${l};`))," ")}}`,Te(t)),$(e+"RowWhenSet",`{${q(y(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,Te(t,1)),$(e+"CellId",q(y(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(y(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${be}`,me(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${be})${be}`,me(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),H(t,1),I(K(t),`'${t}'`)))),y=(a,l)=>oe(e[a],((e,a)=>l(a,e[n],e[s],I(K(a),`'${a}'`),H(a,1)))),S=e=>oe(l,((a,l)=>e(l,a[n],a[s],I(K(l),`'${l}'`),H(l,1))));if(d(1,C,V,`create${V} as create${V}Decl`),!ne(e)){const e=$("Tables",`{${q(p(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Ve(4,1)),l=$("TableId",q(p((e=>`'${e}'`))," | "),"A Table Id in "+re),o=$("TableCallback",`(...[tableId, rowCallback]: ${q(p(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${be}]`))," | ")})${be}`,me("a Table Id, and a Row iterator")),r=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(p(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${v}: ${V}, getCellChange: ${r}${ue})${be}`,pe(1)),b=$("TableIdsListener",`(${v}: ${V})${be}`,pe(2)),w=$("TableListener",`(${v}: ${V}, tableId: ${l}, getCellChange: ${r}${ue})${be}`,pe(3)),h=$("RowIdsListener",`(${v}: ${V}, tableId: ${l})`+be,pe(4,3)),g=$("RowListener",`(${v}: ${V}, tableId: ${l}, rowId: Id, getCellChange: ${r}${ue})${be}`,pe(5,3)),m=$("CellIdsListener",`(${v}: ${V}, tableId: ${l}, rowId: Id)`+be,pe(6,5)),S=$("CellListener",`(...[${v}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(B(p((e=>y(e,((a,l)=>`[${v}: ${V}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${ue}, oldCell: ${l}${ue}, getCellChange: ${r} | undefined]`)))))," | ")})${be}`,pe(7,5)),J=$("InvalidCellListener",`(${v}: ${V}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${be}`,pe(8));i("hasTables",a,t,Ge("hasTables"),Re("any Table")),i("getTables",a,e,Ge("getTables"),Ve(0,1)),i("setTables","tables: "+e,V,ze("setTables","tables"),Ve(1,1)),i("delTables",a,V,ze("delTables"),Ve(3,1)),i("getTableIds",a,l+"[]",Ge("getTableIds",a,l+"[]"),ve("Table",re)),i("forEachTable","tableCallback: "+o,"void",Ge("forEachTable","tableCallback as any"),fe("Table",re));const O=k();p(((e,[l,o,n,s,r,$],u,I)=>{d(1,C,l,o,n,s,r,$),i(`has${u}Table`,a,t,Ge("hasTable",I),Re(ye(e))),i(`get${u}Table`,a,l,Ge("getTable",I,l),Ee(e)),i(`set${u}Table`,"table: "+l,V,ze("setTable",I+", table"),Ee(e,1)),i(`del${u}Table`,a,V,ze("delTable",I),Ee(e,3)),i(`get${u}RowIds`,a,"Ids",Ge("getRowIds",I),ve("Row",ye(e))),i(`get${u}SortedRowIds`,`cellId?: ${s}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ge("getSortedRowIds",I+", cellId, descending, offset, limit"),ve("Row",ye(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",Ge("forEachRow",I+", rowCallback as any"),fe("Row",ye(e))),i(`has${u}Row`,"rowId: Id",t,Ge("hasRow",I+", rowId"),Re(he,ye(e))),i(`get${u}Row`,"rowId: Id",o,Ge("getRow",I+", rowId",o),Oe(e)),i(`set${u}Row`,"rowId: Id, row: "+n,V,ze("setRow",I+", rowId, row"),Oe(e,1)),i(`add${u}Row`,"row: "+n,"Id"+ue,Ge("addRow",I+", row"),"Adds a new Row to "+ye(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+n,V,ze("setPartialRow",I+", rowId, partialRow"),Oe(e,2)),i(`del${u}Row`,"rowId: Id",V,ze("delRow",I+", rowId"),Oe(e,3)),i(`get${u}CellIds`,"rowId: Id",s+"[]",Ge("getCellIds",I+", rowId",s+"[]"),ve("Cell",Se(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+r,"void",Ge("forEachCell",I+", rowId, cellCallback as any"),fe("Cell",Se(e))),y(e,((l,o,n,s,r)=>{const d="Map"+H(o,1);j(O,o,d),i(`has${u}${r}Cell`,"rowId: Id",t,Ge("hasCell",`${I}, rowId, ${s}`),Re(ke(l),Se(e)));const $=`${o}${T(n)?ue:a}`;i(`get${u}${r}Cell`,"rowId: Id",$,Ge("getCell",`${I}, rowId, ${s}`,$),je(e,l)),i(`set${u}${r}Cell`,`rowId: Id, cell: ${o} | ${d}`,V,ze("setCell",`${I}, rowId, ${s}, cell as any`),je(e,l,1)),i(`del${u}${r}Cell`,"rowId: Id",V,ze("delCell",`${I}, rowId, ${s}`),je(e,l,3))}))})),i("getTablesJson",a,"Json",Ge("getTablesJson"),Ve(5,1)),i("setTablesJson","tablesJson: Json",V,ze("setTablesJson","tablesJson"),Ve(6,1)),i("addTablesListener",`${ie}: ${u}, mutator?: boolean`,"Id",Fe("addTablesListener",a,"mutator"),Ve(7,1)+" changes"),i("addTableIdsListener",`${ie}: ${b}, mutator?: boolean`,"Id",Fe("addTableIdsListener",a,"mutator"),Le("the Table Ids",re,1)),i("addTableListener",`tableId: ${l} | null, ${ie}: ${w}, mutator?: boolean`,"Id",Fe("addTableListener","tableId","mutator"),Le("a Table",re)),i("addRowIdsListener",`tableId: ${l} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Fe("addRowIdsListener","tableId","mutator"),Le("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${l} | null, rowId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Fe("addRowListener","tableId, rowId","mutator"),Le("a Row","a Table")),i("addCellIdsListener",`tableId: ${l} | null, rowId: IdOrNull, ${ie}: ${m}, mutator?: boolean`,"Id",Fe("addCellIdsListener","tableId, rowId","mutator"),Le("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${l} | null, rowId: IdOrNull, cellId: ${q(p(((e,a)=>a[3]))," | ")} | null, ${ie}: ${S}, mutator?: boolean`,"Id",Fe("addCellListener","tableId, rowId, cellId","mutator"),Le("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${ie}: ${J}, mutator?: boolean`,"Id",Fe("addInvalidCellListener","tableId, rowId, cellId","mutator"),Ie+" whenever an invalid Cell change was attempted"),E(O,((e,a)=>$(a,`(cell: ${e}${ue}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(1,C,e,l,o,u,b,w,h,g,m,S,J,...L(O)),d(0,"tinybase","CellChange"),c(R,".setTablesSchema({",B(p(((e,l,t,o)=>[`[${o}]: {`,...y(e,((e,l,t,o)=>`[${o}]: {[${I(K(n),`'${n}'`)}]: ${I(K(l),`'${l}'`)}${T(t)?a:`, [${I(K(s),`'${s}'`)}]: ${f(t)?I(K(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!ne(l)){const e=$("Values",`{${q(S(((e,l,t)=>`'${e}'${T(t)?"?":a}: ${l};`))," ")}}`,Ve(4,2)),l=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ve(4,2,1)),o=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+re),r=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${be}`,me("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${o}) => ValueChange`,de+" returning information about any Value's changes during a transaction"),b=$("ValuesListener",`(${v}: ${V}, getValueChange: ${u}${ue})`+be,pe(9)),w=$("ValueIdsListener",`(${v}: ${V})${be}`,pe(10)),h=$("ValueListener",`(...[${v}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${v}: ${V}, valueId: '${e}', newValue: ${a}${ue}, oldValue: ${a}${ue}, getValueChange: ${u} | undefined]`))," | ")})${be}`,pe(11)),g=$("InvalidValueListener",`(${v}: ${V}, valueId: Id, invalidValues: any[])${be}`,pe(12));i("hasValues",a,t,Ge("hasValues"),Re("any Value")),i("getValues",a,e,Ge("getValues",a,e),Ve(0,2)),i("setValues","values: "+l,V,ze("setValues","values"),Ve(1,2)),i("setPartialValues","partialValues: "+l,V,ze("setPartialValues","partialValues"),Ve(2,2)),i("delValues",a,V,ze("delValues"),Ve(3,2)),i("getValueIds",a,o+"[]",Ge("getValueIds",a,o+"[]"),ve("Value",re)),i("forEachValue","valueCallback: "+r,"void",Ge("forEachValue","valueCallback as any"),fe("Value",re)),S(((e,l,o,n,s)=>{i(`has${s}Value`,a,t,Ge("hasValue",n),Re(Je(e))),i(`get${s}Value`,a,l,Ge("getValue",n,l),xe(e)),i(`set${s}Value`,"value: "+l,V,ze("setValue",n+", value"),xe(e,1)),i(`del${s}Value`,a,V,ze("delValue",n),xe(e,3))})),i("getValuesJson",a,"Json",Ge("getValuesJson"),Ve(5,2)),i("setValuesJson","valuesJson: Json",V,ze("setValuesJson","valuesJson"),Ve(6,2)),i("addValuesListener",`${ie}: ${b}, mutator?: boolean`,"Id",Fe("addValuesListener",a,"mutator"),Ve(7,2)+" changes"),i("addValueIdsListener",`${ie}: ${w}, mutator?: boolean`,"Id",Fe("addValueIdsListener",a,"mutator"),Le("the Value Ids",re,1)),i("addValueListener",`valueId: ${o} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Fe("addValueListener","valueId","mutator"),Le("a Value",re)),i("addInvalidValueListener",`valueId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Fe("addInvalidValueListener","valueId","mutator"),Ie+" whenever an invalid Cell change was attempted"),d(1,C,e,l,o,r,b,w,h,g),d(0,"tinybase","ValueChange"),c(R,".setValuesSchema({",S(((e,l,t,o)=>[`[${o}]: {[${I(K(n),`'${n}'`)}]: ${I(K(l),`'${l}'`)}${T(t)?a:`, [${I(K(s),`'${s}'`)}]: ${f(t)?I(K(t),`'${t}'`):t}`}},`])),"})")}d(0,"tinybase",...Ne);const J=$("TransactionListener",`(${v}: ${V}, cellsTouched: boolean, valuesTouched: boolean)${be}`,de+" listening to the completion of a transaction");return i("getJson",a,"Json",Ge("getJson"),Ve(5)),i("setJson","json: Json",V,ze("setJson","json"),Ve(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",Ge("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",a,V,ze("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",V,ze("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${ie}: ${J}`,"Id",Fe("addWillFinishTransactionListener"),`${Ie} just before ${we}`),i("addDidFinishTransactionListener",`${ie}: ${J}`,"Id",Fe("addDidFinishTransactionListener"),`${Ie} just after ${we}`),i("callListener",ie+"Id: Id",V,ze("callListener",ie+"Id"),`Manually provoke a ${ie} to be called`),i("delListener",ie+"Id: Id",V,ze("delListener",ie+"Id"),`Remove a ${ie} that was previously added to ${re}`),i("getStore",a,"Store","store",Ae[0]+" the underlying Store object"),d(1,"tinybase","createStore",...Ne),d(1,C,V,`create${V} as create${V}Decl`,J),I("store",["createStore()",...R]),u("fluent","actions: () => Store",["actions();",`return ${v};`]),u("proxy",ie+": any",`(_: Store, ...args: any[]) => ${ie}(${v}, ...args)`),I(v,["{",...h(1),"}"]),[r(...b(0),...w(),`${$e} interface ${V} {`,...h(0),"}",a,X(`Creates a ${V} object`),`${$e} function create${V}(): ${V};`),r(...b(1),`${$e} const create${V}: typeof create${V}Decl = () => {`,...g(),`return Object.freeze(${v});`,"};")]};var Me=Object.defineProperty,Ze=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Ue=(e,a,l)=>a in e?Me(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,qe=(e,a)=>{for(var l in a||(a={}))_e.call(a,l)&&Ue(e,l,a[l]);if(Ze)for(var l of Ze(a))Qe.call(a,l)&&Ue(e,l,a[l]);return e},Be=(e,a,l)=>new Promise(((t,o)=>{var n=e=>{try{r(l.next(e))}catch(e){o(e)}},s=e=>{try{r(l.throw(e))}catch(e){o(e)}},r=e=>e.done?t(e.value):Promise.resolve(e.value).then(n,s);r((l=l.apply(e,a)).next())}));const He={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ke=se((e=>{const a=()=>{const a=g(e.getTablesSchemaJson());return!ne(a)||r(e.getTableIds(),(l=>{const t=e.getRowIds(l),o=k();if(r(t,(a=>r(e.getCellIds(l,a),(t=>{const n=e.getCell(l,a,t),s=x(o,t,(()=>[m(n),k(),[0],0])),[r,d,[$]]=s,i=x(d,n,(()=>0))+1;return i>$&&(s[2]=[i,n]),j(d,n,i),s[3]++,r==m(n)})))))return a[l]={},y(o,(([e,,[,o],r],d)=>{a[l][d]=qe({[n]:e},r==u(t)?{[s]:o}:{})})),1}))?a:{}},l=()=>{const a=g(e.getValuesSchemaJson());return ne(a)&&e.forEachValue(((e,l)=>{a[e]={[n]:m(l)}})),a},t=e=>We(a(),l(),e),o=e=>Be(void 0,null,(function*(){let a;try{a=(yield import("prettier")).format}catch(e){a=e=>e}return i(t(e),(e=>Q(a(e,He))))}));return le({getStoreStats:a=>{let l=0,t=0,o=0;const n={};return e.forEachTable(((e,s)=>{l++;let r=0,d=0;const $={};s(((e,l)=>{r++;let t=0;l((()=>t++)),d+=t,a&&($[e]={rowCells:t})})),t+=r,o+=d,a&&(n[e]={tableRows:r,tableCells:d,rows:$})})),qe({totalTables:l,totalRows:t,totalCells:o,totalValues:u(e.getValueIds()),jsonLength:U(e.getJson())},a?{detail:{tables:n}}:{})},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:o,getStore:()=>e})}));export{Ke as createTools};
Binary file
package/lib/tools.js CHANGED
@@ -1 +1 @@
1
- const e=e=>typeof e,a="",l=e(a),t=e(!0),s=e(0),o="type",n="default",d=(e,a)=>e.every(a),r=(e,a)=>e.sort(a),$=(e,a)=>e.forEach(a),i=(e,a)=>e.map(a),u=e=>e.length,I=e=>0==u(e),c=(e,...a)=>e.push(...a),b=e=>e.pop(),w=(e,...a)=>e.unshift(...a),h=e=>e.shift(),g=JSON.parse,C=isFinite,V=(e,a)=>e instanceof a,T=e=>null==e,f=e=>e==l||e==t,R=a=>e(a)==l,m=e=>Array.isArray(e),v=a=>{const l=e(a);return f(l)||l==s&&C(a)?l:void 0},p=(e,a)=>e?.has(a)??!1,L=e=>[...e?.values()??[]],y=(e,a)=>e?.forEach(a),S=(e,a)=>e?.delete(a),k=e=>new Map(e),J=(e,a)=>e?.get(a),E=(e,a)=>y(e,((e,l)=>a(l,e))),A=(e,a)=>i([...e?.entries()??[]],(([e,l])=>a(l,e))),j=(e,a,l)=>T(l)?(S(e,a),e):e?.set(a,l),O=(e,a,l)=>(p(e,a)||j(e,a,l()),J(e,a)),x=e=>new Set(m(e)||T(e)?e:[e]),D=(e,a)=>e?.add(a),N=e=>[e,e],G=()=>[k(),k()],z=/[^A-Za-z]+/,F=/[^A-Za-z0-9]+/,P=/^( *)\/\*\* *(.*?) *\*\/$/gm,W=(e,a,l)=>e.substring(a,l),M=e=>e.toUpperCase(),Z=e=>e.toLowerCase(),_=(e,a,l,t=1)=>{const s=`${a}${1==t?"":t}`;return p(e,s)?_(e,a,l,t+1):(j(e,s,l),s)},Q=e=>e.replace(P,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,l=a)=>e.join(l),B=e=>e.flat(1e3),H=(e,a=0)=>q(i(e.split(F),((e,l)=>(l>0||a?M:Z)(W(e,0,1))+W(e,1)))),K=e=>M(q((e&&!z.test(e[0])?e:" "+e).split(F),"_")),X=e=>`/** ${e}. */`,Y=()=>{const e=G(),l=k(),t=k(),s=k();return[(...e)=>q(B(e),"\n"),(a,l,...t)=>$(t,(t=>D(O(e[a],l,x),t))),(e,a,t)=>_(l,e,[a,t]),(e,a,l,s,o,n="")=>_(t,e,[a,l,s,o,n]),(e,a,l)=>_(s,e,m(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>J(s,e)===a?e:_(s,e,a),l=>[...r(A(e[l],((e,a)=>`import {${q(r(L(e)),", ")}} from '${a}';`))),a],()=>A(l,(([e,l],t)=>[X(l),`export type ${t} = ${e};`,a])),e=>A(t,(([l,t,s,o,n],d)=>{const r=e?[`${d}: ${n}(${l}): ${t} => ${s},`]:[`${d}${n}(${l}): ${t};`];return e||w(r,X(o)),c(r,a),r})),()=>A(s,((e,l)=>(e=m(e)?e:[e],c(e,b(e)+";"),[`const ${l} = ${h(e)}`,e,a])))]},ee=Object,ae=ee.keys,le=ee.freeze,te=e=>V(e,ee)&&e.constructor==ee,se=(e,a)=>i(ee.entries(e),(([e,l])=>a(l,e))),oe=e=>te(e)&&I(ae(e)),ne="the Store",de="A function for",re="export",$e="listener",ie=" | undefined",ue=`Registers a ${$e} that will be called`,Ie="Represents",ce=" => void",be="the end of the transaction",we="the specified Row",he="a string serialization of",ge=(e=0,a=0)=>`the ${De[e]}content of${a?" "+ne:""}`,Ce=(e,a=0,l=0)=>`${Oe[e]} ${ge(a,1)}${l?" when set":""}`,Ve=(e,a=0)=>`${Ie} a Row when ${a?"s":"g"}etting ${ge()} the '${e}' Table`,Te=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,fe=(e,a)=>`Calls a function for each ${e} in ${a}`,Re=(e,a=ne)=>`Gets whether ${e} exists in ${a}`,me=e=>"A function that takes "+e,ve=(e,a=0)=>`${de} listening to changes to ${xe[e]} in ${xe[a]}`,pe=(e,l,t=0)=>`${ue} whenever ${e} in ${l} change`+(t?a:"s"),Le=e=>`the '${e}' Table`,ye=e=>`${we} in ${Le(e)}`,Se=e=>`the '${e}' Cell`,ke=e=>`the '${e}' Value`,Je=(e,a=0)=>`${Oe[a]} ${ge()} ${Le(e)}`,Ee=(e,a=0)=>`${Oe[a]} ${ge()} ${ye(e)}`,Ae=(e,a,l=0)=>`${Oe[l]} ${Se(a)} for ${ye(e)}`,je=(e,a=0)=>`${Oe[a]} ${ke(e)}`,Oe=["Gets","Sets","Sets part of","Deletes",Ie,"Gets "+he,"Sets "+he,ue+" whenever"],xe=[ne,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],De=["","tabular ","keyed value "],Ne=["DoRollback","Id","IdOrNull","Ids","Json","Store"],Ge=(e,l=a,t=a)=>`store.${e}(${l})${t?" as "+t:a}`,ze=(e,l=a)=>`fluent(() => ${Ge(e,l)})`,Fe=(e,l=a,t=a)=>`store.${e}(${l?l+", ":a}proxy(${$e})${t?", "+t:a})`,Pe=(e,l,s)=>{if(oe(e)&&oe(l))return N(a);const[d,r,$,i,u,I,b,w,h,g]=Y(),C=`./${H(s)}.d`,V=H(s,1),f=H(V),m=[],v=k(),p=l=>se(e,((e,t)=>l(t,O(v,t,(()=>{const e=H(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${Ie} the '${t}' Table`),$(e+"Row",`{${q(y(t,((e,l,t)=>`'${e}'${T(t)?"?":a}: ${l};`))," ")}}`,Ve(t)),$(e+"RowWhenSet",`{${q(y(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ve(t,1)),$(e+"CellId",q(y(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(y(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${ce}`,me(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${ce})${ce}`,me(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),H(t,1),I(K(t),`'${t}'`)))),y=(a,l)=>se(e[a],((e,a)=>l(a,e[o],e[n],I(K(a),`'${a}'`),H(a,1)))),S=e=>se(l,((a,l)=>e(l,a[o],a[n],I(K(l),`'${l}'`),H(l,1))));if(r(1,C,V,`create${V} as create${V}Decl`),!oe(e)){const e=$("Tables",`{${q(p(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Ce(4,1)),l=$("TableId",q(p((e=>`'${e}'`))," | "),"A Table Id in "+ne),s=$("TableCallback",`(...[tableId, rowCallback]: ${q(p(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${ce}]`))," | ")})${ce}`,me("a Table Id, and a Row iterator")),d=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(p(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${f}: ${V}, getCellChange: ${d}${ie})${ce}`,ve(1)),b=$("TableIdsListener",`(${f}: ${V})${ce}`,ve(2)),w=$("TableListener",`(${f}: ${V}, tableId: ${l}, getCellChange: ${d}${ie})${ce}`,ve(3)),h=$("RowIdsListener",`(${f}: ${V}, tableId: ${l})`+ce,ve(4,3)),g=$("RowListener",`(${f}: ${V}, tableId: ${l}, rowId: Id, getCellChange: ${d}${ie})${ce}`,ve(5,3)),v=$("CellIdsListener",`(${f}: ${V}, tableId: ${l}, rowId: Id)`+ce,ve(6,5)),S=$("CellListener",`(...[${f}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(B(p((e=>y(e,((a,l)=>`[${f}: ${V}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${ie}, oldCell: ${l}${ie}, getCellChange: ${d} | undefined]`)))))," | ")})${ce}`,ve(7,5)),J=$("InvalidCellListener",`(${f}: ${V}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${ce}`,ve(8));i("hasTables",a,t,Ge("hasTables"),Re("any Table")),i("getTables",a,e,Ge("getTables"),Ce(0,1)),i("setTables","tables: "+e,V,ze("setTables","tables"),Ce(1,1)),i("delTables",a,V,ze("delTables"),Ce(3,1)),i("getTableIds",a,l+"[]",Ge("getTableIds",a,l+"[]"),Te("Table",ne)),i("forEachTable","tableCallback: "+s,"void",Ge("forEachTable","tableCallback as any"),fe("Table",ne));const A=k();p(((e,[l,s,o,n,d,$],u,I)=>{r(1,C,l,s,o,n,d,$),i(`has${u}Table`,a,t,Ge("hasTable",I),Re(Le(e))),i(`get${u}Table`,a,l,Ge("getTable",I,l),Je(e)),i(`set${u}Table`,"table: "+l,V,ze("setTable",I+", table"),Je(e,1)),i(`del${u}Table`,a,V,ze("delTable",I),Je(e,3)),i(`get${u}RowIds`,a,"Ids",Ge("getRowIds",I),Te("Row",Le(e))),i(`get${u}SortedRowIds`,`cellId?: ${n}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ge("getSortedRowIds",I+", cellId, descending, offset, limit"),Te("Row",Le(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",Ge("forEachRow",I+", rowCallback as any"),fe("Row",Le(e))),i(`has${u}Row`,"rowId: Id",t,Ge("hasRow",I+", rowId"),Re(we,Le(e))),i(`get${u}Row`,"rowId: Id",s,Ge("getRow",I+", rowId",s),Ee(e)),i(`set${u}Row`,"rowId: Id, row: "+o,V,ze("setRow",I+", rowId, row"),Ee(e,1)),i(`add${u}Row`,"row: "+o,"Id"+ie,Ge("addRow",I+", row"),"Adds a new Row to "+Le(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+o,V,ze("setPartialRow",I+", rowId, partialRow"),Ee(e,2)),i(`del${u}Row`,"rowId: Id",V,ze("delRow",I+", rowId"),Ee(e,3)),i(`get${u}CellIds`,"rowId: Id",n+"[]",Ge("getCellIds",I+", rowId",n+"[]"),Te("Cell",ye(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+d,"void",Ge("forEachCell",I+", rowId, cellCallback as any"),fe("Cell",ye(e))),y(e,((l,s,o,n,d)=>{const r="Map"+H(s,1);j(A,s,r),i(`has${u}${d}Cell`,"rowId: Id",t,Ge("hasCell",`${I}, rowId, ${n}`),Re(Se(l),ye(e)));const $=`${s}${T(o)?ie:a}`;i(`get${u}${d}Cell`,"rowId: Id",$,Ge("getCell",`${I}, rowId, ${n}`,$),Ae(e,l)),i(`set${u}${d}Cell`,`rowId: Id, cell: ${s} | ${r}`,V,ze("setCell",`${I}, rowId, ${n}, cell as any`),Ae(e,l,1)),i(`del${u}${d}Cell`,"rowId: Id",V,ze("delCell",`${I}, rowId, ${n}`),Ae(e,l,3))}))})),i("getTablesJson",a,"Json",Ge("getTablesJson"),Ce(5,1)),i("setTablesJson","tablesJson: Json",V,ze("setTablesJson","tablesJson"),Ce(6,1)),i("addTablesListener",`${$e}: ${u}, mutator?: boolean`,"Id",Fe("addTablesListener",a,"mutator"),Ce(7,1)+" changes"),i("addTableIdsListener",`${$e}: ${b}, mutator?: boolean`,"Id",Fe("addTableIdsListener",a,"mutator"),pe("the Table Ids",ne,1)),i("addTableListener",`tableId: ${l} | null, ${$e}: ${w}, mutator?: boolean`,"Id",Fe("addTableListener","tableId","mutator"),pe("a Table",ne)),i("addRowIdsListener",`tableId: ${l} | null, ${$e}: ${h}, mutator?: boolean`,"Id",Fe("addRowIdsListener","tableId","mutator"),pe("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${l} | null, rowId: IdOrNull, ${$e}: ${g}, mutator?: boolean`,"Id",Fe("addRowListener","tableId, rowId","mutator"),pe("a Row","a Table")),i("addCellIdsListener",`tableId: ${l} | null, rowId: IdOrNull, ${$e}: ${v}, mutator?: boolean`,"Id",Fe("addCellIdsListener","tableId, rowId","mutator"),pe("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${l} | null, rowId: IdOrNull, cellId: ${q(p(((e,a)=>a[3]))," | ")} | null, ${$e}: ${S}, mutator?: boolean`,"Id",Fe("addCellListener","tableId, rowId, cellId","mutator"),pe("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${$e}: ${J}, mutator?: boolean`,"Id",Fe("addInvalidCellListener","tableId, rowId, cellId","mutator"),ue+" whenever an invalid Cell change was attempted"),E(A,((e,a)=>$(a,`(cell: ${e}${ie}) => ${e}`,`Takes a ${e} Cell value and returns another`))),r(1,C,e,l,s,u,b,w,h,g,v,S,J,...L(A)),r(0,"tinybase","CellChange"),c(m,".setTablesSchema({",B(p(((e,l,t,s)=>[`[${s}]: {`,...y(e,((e,l,t,s)=>`[${s}]: {[${I(K(o),`'${o}'`)}]: ${I(K(l),`'${l}'`)}${T(t)?a:`, [${I(K(n),`'${n}'`)}]: ${R(t)?I(K(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!oe(l)){const e=$("Values",`{${q(S(((e,l,t)=>`'${e}'${T(t)?"?":a}: ${l};`))," ")}}`,Ce(4,2)),l=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ce(4,2,1)),s=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+ne),d=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${ce}`,me("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${s}) => ValueChange`,de+" returning information about any Value's changes during a transaction"),b=$("ValuesListener",`(${f}: ${V}, getValueChange: ${u}${ie})`+ce,ve(9)),w=$("ValueIdsListener",`(${f}: ${V})${ce}`,ve(10)),h=$("ValueListener",`(...[${f}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${f}: ${V}, valueId: '${e}', newValue: ${a}${ie}, oldValue: ${a}${ie}, getValueChange: ${u} | undefined]`))," | ")})${ce}`,ve(11)),g=$("InvalidValueListener",`(${f}: ${V}, valueId: Id, invalidValues: any[])${ce}`,ve(12));i("hasValues",a,t,Ge("hasValues"),Re("any Value")),i("getValues",a,e,Ge("getValues"),Ce(0,2)),i("setValues","values: "+l,V,ze("setValues","values"),Ce(1,2)),i("setPartialValues","partialValues: "+l,V,ze("setPartialValues","partialValues"),Ce(2,2)),i("delValues",a,V,ze("delValues"),Ce(3,2)),i("getValueIds",a,s+"[]",Ge("getValueIds",a,s+"[]"),Te("Value",ne)),i("forEachValue","valueCallback: "+d,"void",Ge("forEachValue","valueCallback as any"),fe("Value",ne)),S(((e,l,s,o,n)=>{i(`has${n}Value`,a,t,Ge("hasValue",o),Re(ke(e))),i(`get${n}Value`,a,l,Ge("getValue",o,l),je(e)),i(`set${n}Value`,"value: "+l,V,ze("setValue",o+", value"),je(e,1)),i(`del${n}Value`,a,V,ze("delValue",o),je(e,3))})),i("getValuesJson",a,"Json",Ge("getValuesJson"),Ce(5,2)),i("setValuesJson","valuesJson: Json",V,ze("setValuesJson","valuesJson"),Ce(6,2)),i("addValuesListener",`${$e}: ${b}, mutator?: boolean`,"Id",Fe("addValuesListener",a,"mutator"),Ce(7,2)+" changes"),i("addValueIdsListener",`${$e}: ${w}, mutator?: boolean`,"Id",Fe("addValueIdsListener",a,"mutator"),pe("the Value Ids",ne,1)),i("addValueListener",`valueId: ${s} | null, ${$e}: ${h}, mutator?: boolean`,"Id",Fe("addValueListener","valueId","mutator"),pe("a Value",ne)),i("addInvalidValueListener",`valueId: IdOrNull, ${$e}: ${g}, mutator?: boolean`,"Id",Fe("addInvalidValueListener","valueId","mutator"),ue+" whenever an invalid Cell change was attempted"),r(1,C,e,s,d,b,w,h,g),r(0,"tinybase","ValueChange"),c(m,".setValuesSchema({",S(((e,l,t,s)=>[`[${s}]: {[${I(K(o),`'${o}'`)}]: ${I(K(l),`'${l}'`)}${T(t)?a:`, [${I(K(n),`'${n}'`)}]: ${R(t)?I(K(t),`'${t}'`):t}`}},`])),"})")}r(0,"tinybase",...Ne);const J=$("TransactionListener",`(${f}: ${V}, cellsTouched: boolean, valuesTouched: boolean)${ce}`,de+" listening to the completion of a transaction");return i("getJson",a,"Json",Ge("getJson"),Ce(5)),i("setJson","json: Json",V,ze("setJson","json"),Ce(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",Ge("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",a,V,ze("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",V,ze("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${$e}: ${J}`,"Id",Fe("addWillFinishTransactionListener"),`${ue} just before ${be}`),i("addDidFinishTransactionListener",`${$e}: ${J}`,"Id",Fe("addDidFinishTransactionListener"),`${ue} just after ${be}`),i("callListener",$e+"Id: Id",V,ze("callListener",$e+"Id"),`Manually provoke a ${$e} to be called`),i("delListener",$e+"Id: Id",V,ze("delListener",$e+"Id"),`Remove a ${$e} that was previously added to ${ne}`),i("getStore",a,"Store","store",Oe[0]+" the underlying Store object"),r(1,"tinybase","createStore",...Ne),r(1,C,V,`create${V} as create${V}Decl`,J),I("store",["createStore()",...m]),u("fluent","actions: () => Store",["actions();",`return ${f};`]),u("proxy",$e+": any",`(_: Store, ...args: any[]) => ${$e}(${f}, ...args)`),I(f,["{",...h(1),"}"]),[d(...b(0),...w(),`${re} interface ${V} {`,...h(0),"}",a,X(`Creates a ${V} object`),`${re} function create${V}(): ${V};`),d(...b(1),`${re} const create${V}: typeof create${V}Decl = () => {`,...g(),`return Object.freeze(${f});`,"};")]},We={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Me=(e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))})((e=>{const a=()=>{const a=g(e.getTablesSchemaJson());return!oe(a)||d(e.getTableIds(),(l=>{const t=e.getRowIds(l),s=k();if(d(t,(a=>d(e.getCellIds(l,a),(t=>{const o=e.getCell(l,a,t),n=O(s,t,(()=>[v(o),k(),[0],0])),[d,r,[$]]=n,i=O(r,o,(()=>0))+1;return i>$&&(n[2]=[i,o]),j(r,o,i),n[3]++,d==v(o)})))))return a[l]={},y(s,(([e,,[,s],d],r)=>{a[l][r]={[o]:e,...d==u(t)?{[n]:s}:{}}})),1}))?a:{}},l=()=>{const a=g(e.getValuesSchemaJson());return oe(a)&&e.forEachValue(((e,l)=>{a[e]={[o]:v(l)}})),a},t=e=>Pe(a(),l(),e),s=async e=>{let a;try{a=(await import("prettier")).format}catch{a=e=>e}return i(t(e),(e=>Q(a(e,We))))};return le({getStoreStats:a=>{let l=0,t=0,s=0;const o={};return e.forEachTable(((e,n)=>{l++;let d=0,r=0;const $={};n(((e,l)=>{d++;let t=0;l((()=>t++)),r+=t,a&&($[e]={rowCells:t})})),t+=d,s+=r,a&&(o[e]={tableRows:d,tableCells:r,rows:$})})),{totalTables:l,totalRows:t,totalCells:s,totalValues:u(e.getValueIds()),jsonLength:U(e.getJson()),...a?{detail:{tables:o}}:{}}},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:s,getStore:()=>e})}));export{Me as createTools};
1
+ const e=e=>typeof e,a="",l=e(a),t=e(!0),s=e(0),o="type",n="default",d=(e,a)=>e.every(a),r=(e,a)=>e.sort(a),$=(e,a)=>e.forEach(a),i=(e,a)=>e.map(a),u=e=>e.length,I=e=>0==u(e),c=(e,...a)=>e.push(...a),b=e=>e.pop(),w=(e,...a)=>e.unshift(...a),h=e=>e.shift(),g=JSON.parse,C=isFinite,V=(e,a)=>e instanceof a,T=e=>null==e,f=e=>e==l||e==t,R=a=>e(a)==l,m=e=>Array.isArray(e),v=a=>{const l=e(a);return f(l)||l==s&&C(a)?l:void 0},p=(e,a)=>e?.has(a)??!1,L=e=>[...e?.values()??[]],y=(e,a)=>e?.forEach(a),S=(e,a)=>e?.delete(a),k=e=>new Map(e),J=(e,a)=>e?.get(a),E=(e,a)=>y(e,((e,l)=>a(l,e))),A=(e,a)=>i([...e?.entries()??[]],(([e,l])=>a(l,e))),j=(e,a,l)=>T(l)?(S(e,a),e):e?.set(a,l),O=(e,a,l)=>(p(e,a)||j(e,a,l()),J(e,a)),x=e=>new Set(m(e)||T(e)?e:[e]),D=(e,a)=>e?.add(a),N=e=>[e,e],G=()=>[k(),k()],z=/[^A-Za-z]+/,F=/[^A-Za-z0-9]+/,P=/^( *)\/\*\* *(.*?) *\*\/$/gm,W=(e,a,l)=>e.substring(a,l),M=e=>e.toUpperCase(),Z=e=>e.toLowerCase(),_=(e,a,l,t=1)=>{const s=`${a}${1==t?"":t}`;return p(e,s)?_(e,a,l,t+1):(j(e,s,l),s)},Q=e=>e.replace(P,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,l=a)=>e.join(l),B=e=>e.flat(1e3),H=(e,a=0)=>q(i(e.split(F),((e,l)=>(l>0||a?M:Z)(W(e,0,1))+W(e,1)))),K=e=>M(q((e&&!z.test(e[0])?e:" "+e).split(F),"_")),X=e=>`/** ${e}. */`,Y=()=>{const e=G(),l=k(),t=k(),s=k();return[(...e)=>q(B(e),"\n"),(a,l,...t)=>$(t,(t=>D(O(e[a],l,x),t))),(e,a,t)=>_(l,e,[a,t]),(e,a,l,s,o,n="")=>_(t,e,[a,l,s,o,n]),(e,a,l)=>_(s,e,m(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>J(s,e)===a?e:_(s,e,a),l=>[...r(A(e[l],((e,a)=>`import {${q(r(L(e)),", ")}} from '${a}';`))),a],()=>A(l,(([e,l],t)=>[X(l),`export type ${t} = ${e};`,a])),e=>A(t,(([l,t,s,o,n],d)=>{const r=e?[`${d}: ${n}(${l}): ${t} => ${s},`]:[`${d}${n}(${l}): ${t};`];return e||w(r,X(o)),c(r,a),r})),()=>A(s,((e,l)=>(e=m(e)?e:[e],c(e,b(e)+";"),[`const ${l} = ${h(e)}`,e,a])))]},ee=Object,ae=ee.keys,le=ee.freeze,te=e=>V(e,ee)&&e.constructor==ee,se=(e,a)=>i(ee.entries(e),(([e,l])=>a(l,e))),oe=e=>te(e)&&I(ae(e)),ne="the Store",de="A function for",re="export",$e="listener",ie=" | undefined",ue=`Registers a ${$e} that will be called`,Ie="Represents",ce=" => void",be="the end of the transaction",we="the specified Row",he="a string serialization of",ge=(e=0,a=0)=>`the ${De[e]}content of${a?" "+ne:""}`,Ce=(e,a=0,l=0)=>`${Oe[e]} ${ge(a,1)}${l?" when set":""}`,Ve=(e,a=0)=>`${Ie} a Row when ${a?"s":"g"}etting ${ge()} the '${e}' Table`,Te=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,fe=(e,a)=>`Calls a function for each ${e} in ${a}`,Re=(e,a=ne)=>`Gets whether ${e} exists in ${a}`,me=e=>"A function that takes "+e,ve=(e,a=0)=>`${de} listening to changes to ${xe[e]} in ${xe[a]}`,pe=(e,l,t=0)=>`${ue} whenever ${e} in ${l} change`+(t?a:"s"),Le=e=>`the '${e}' Table`,ye=e=>`${we} in ${Le(e)}`,Se=e=>`the '${e}' Cell`,ke=e=>`the '${e}' Value`,Je=(e,a=0)=>`${Oe[a]} ${ge()} ${Le(e)}`,Ee=(e,a=0)=>`${Oe[a]} ${ge()} ${ye(e)}`,Ae=(e,a,l=0)=>`${Oe[l]} ${Se(a)} for ${ye(e)}`,je=(e,a=0)=>`${Oe[a]} ${ke(e)}`,Oe=["Gets","Sets","Sets part of","Deletes",Ie,"Gets "+he,"Sets "+he,ue+" whenever"],xe=[ne,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],De=["","tabular ","keyed value "],Ne=["DoRollback","Id","IdOrNull","Ids","Json","Store"],Ge=(e,l=a,t=a)=>`store.${e}(${l})${t?" as "+t:a}`,ze=(e,l=a)=>`fluent(() => ${Ge(e,l)})`,Fe=(e,l=a,t=a)=>`store.${e}(${l?l+", ":a}proxy(${$e})${t?", "+t:a})`,Pe=(e,l,s)=>{if(oe(e)&&oe(l))return N(a);const[d,r,$,i,u,I,b,w,h,g]=Y(),C=`./${H(s)}.d`,V=H(s,1),f=H(V),m=[],v=k(),p=l=>se(e,((e,t)=>l(t,O(v,t,(()=>{const e=H(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${Ie} the '${t}' Table`),$(e+"Row",`{${q(y(t,((e,l,t)=>`'${e}'${T(t)?"?":a}: ${l};`))," ")}}`,Ve(t)),$(e+"RowWhenSet",`{${q(y(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ve(t,1)),$(e+"CellId",q(y(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(y(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${ce}`,me(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${ce})${ce}`,me(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),H(t,1),I(K(t),`'${t}'`)))),y=(a,l)=>se(e[a],((e,a)=>l(a,e[o],e[n],I(K(a),`'${a}'`),H(a,1)))),S=e=>se(l,((a,l)=>e(l,a[o],a[n],I(K(l),`'${l}'`),H(l,1))));if(r(1,C,V,`create${V} as create${V}Decl`),!oe(e)){const e=$("Tables",`{${q(p(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Ce(4,1)),l=$("TableId",q(p((e=>`'${e}'`))," | "),"A Table Id in "+ne),s=$("TableCallback",`(...[tableId, rowCallback]: ${q(p(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${ce}]`))," | ")})${ce}`,me("a Table Id, and a Row iterator")),d=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(p(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${f}: ${V}, getCellChange: ${d}${ie})${ce}`,ve(1)),b=$("TableIdsListener",`(${f}: ${V})${ce}`,ve(2)),w=$("TableListener",`(${f}: ${V}, tableId: ${l}, getCellChange: ${d}${ie})${ce}`,ve(3)),h=$("RowIdsListener",`(${f}: ${V}, tableId: ${l})`+ce,ve(4,3)),g=$("RowListener",`(${f}: ${V}, tableId: ${l}, rowId: Id, getCellChange: ${d}${ie})${ce}`,ve(5,3)),v=$("CellIdsListener",`(${f}: ${V}, tableId: ${l}, rowId: Id)`+ce,ve(6,5)),S=$("CellListener",`(...[${f}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(B(p((e=>y(e,((a,l)=>`[${f}: ${V}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${ie}, oldCell: ${l}${ie}, getCellChange: ${d} | undefined]`)))))," | ")})${ce}`,ve(7,5)),J=$("InvalidCellListener",`(${f}: ${V}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${ce}`,ve(8));i("hasTables",a,t,Ge("hasTables"),Re("any Table")),i("getTables",a,e,Ge("getTables"),Ce(0,1)),i("setTables","tables: "+e,V,ze("setTables","tables"),Ce(1,1)),i("delTables",a,V,ze("delTables"),Ce(3,1)),i("getTableIds",a,l+"[]",Ge("getTableIds",a,l+"[]"),Te("Table",ne)),i("forEachTable","tableCallback: "+s,"void",Ge("forEachTable","tableCallback as any"),fe("Table",ne));const A=k();p(((e,[l,s,o,n,d,$],u,I)=>{r(1,C,l,s,o,n,d,$),i(`has${u}Table`,a,t,Ge("hasTable",I),Re(Le(e))),i(`get${u}Table`,a,l,Ge("getTable",I,l),Je(e)),i(`set${u}Table`,"table: "+l,V,ze("setTable",I+", table"),Je(e,1)),i(`del${u}Table`,a,V,ze("delTable",I),Je(e,3)),i(`get${u}RowIds`,a,"Ids",Ge("getRowIds",I),Te("Row",Le(e))),i(`get${u}SortedRowIds`,`cellId?: ${n}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ge("getSortedRowIds",I+", cellId, descending, offset, limit"),Te("Row",Le(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",Ge("forEachRow",I+", rowCallback as any"),fe("Row",Le(e))),i(`has${u}Row`,"rowId: Id",t,Ge("hasRow",I+", rowId"),Re(we,Le(e))),i(`get${u}Row`,"rowId: Id",s,Ge("getRow",I+", rowId",s),Ee(e)),i(`set${u}Row`,"rowId: Id, row: "+o,V,ze("setRow",I+", rowId, row"),Ee(e,1)),i(`add${u}Row`,"row: "+o,"Id"+ie,Ge("addRow",I+", row"),"Adds a new Row to "+Le(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+o,V,ze("setPartialRow",I+", rowId, partialRow"),Ee(e,2)),i(`del${u}Row`,"rowId: Id",V,ze("delRow",I+", rowId"),Ee(e,3)),i(`get${u}CellIds`,"rowId: Id",n+"[]",Ge("getCellIds",I+", rowId",n+"[]"),Te("Cell",ye(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+d,"void",Ge("forEachCell",I+", rowId, cellCallback as any"),fe("Cell",ye(e))),y(e,((l,s,o,n,d)=>{const r="Map"+H(s,1);j(A,s,r),i(`has${u}${d}Cell`,"rowId: Id",t,Ge("hasCell",`${I}, rowId, ${n}`),Re(Se(l),ye(e)));const $=`${s}${T(o)?ie:a}`;i(`get${u}${d}Cell`,"rowId: Id",$,Ge("getCell",`${I}, rowId, ${n}`,$),Ae(e,l)),i(`set${u}${d}Cell`,`rowId: Id, cell: ${s} | ${r}`,V,ze("setCell",`${I}, rowId, ${n}, cell as any`),Ae(e,l,1)),i(`del${u}${d}Cell`,"rowId: Id",V,ze("delCell",`${I}, rowId, ${n}`),Ae(e,l,3))}))})),i("getTablesJson",a,"Json",Ge("getTablesJson"),Ce(5,1)),i("setTablesJson","tablesJson: Json",V,ze("setTablesJson","tablesJson"),Ce(6,1)),i("addTablesListener",`${$e}: ${u}, mutator?: boolean`,"Id",Fe("addTablesListener",a,"mutator"),Ce(7,1)+" changes"),i("addTableIdsListener",`${$e}: ${b}, mutator?: boolean`,"Id",Fe("addTableIdsListener",a,"mutator"),pe("the Table Ids",ne,1)),i("addTableListener",`tableId: ${l} | null, ${$e}: ${w}, mutator?: boolean`,"Id",Fe("addTableListener","tableId","mutator"),pe("a Table",ne)),i("addRowIdsListener",`tableId: ${l} | null, ${$e}: ${h}, mutator?: boolean`,"Id",Fe("addRowIdsListener","tableId","mutator"),pe("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${l} | null, rowId: IdOrNull, ${$e}: ${g}, mutator?: boolean`,"Id",Fe("addRowListener","tableId, rowId","mutator"),pe("a Row","a Table")),i("addCellIdsListener",`tableId: ${l} | null, rowId: IdOrNull, ${$e}: ${v}, mutator?: boolean`,"Id",Fe("addCellIdsListener","tableId, rowId","mutator"),pe("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${l} | null, rowId: IdOrNull, cellId: ${q(p(((e,a)=>a[3]))," | ")} | null, ${$e}: ${S}, mutator?: boolean`,"Id",Fe("addCellListener","tableId, rowId, cellId","mutator"),pe("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${$e}: ${J}, mutator?: boolean`,"Id",Fe("addInvalidCellListener","tableId, rowId, cellId","mutator"),ue+" whenever an invalid Cell change was attempted"),E(A,((e,a)=>$(a,`(cell: ${e}${ie}) => ${e}`,`Takes a ${e} Cell value and returns another`))),r(1,C,e,l,s,u,b,w,h,g,v,S,J,...L(A)),r(0,"tinybase","CellChange"),c(m,".setTablesSchema({",B(p(((e,l,t,s)=>[`[${s}]: {`,...y(e,((e,l,t,s)=>`[${s}]: {[${I(K(o),`'${o}'`)}]: ${I(K(l),`'${l}'`)}${T(t)?a:`, [${I(K(n),`'${n}'`)}]: ${R(t)?I(K(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!oe(l)){const e=$("Values",`{${q(S(((e,l,t)=>`'${e}'${T(t)?"?":a}: ${l};`))," ")}}`,Ce(4,2)),l=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ce(4,2,1)),s=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+ne),d=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${ce}`,me("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${s}) => ValueChange`,de+" returning information about any Value's changes during a transaction"),b=$("ValuesListener",`(${f}: ${V}, getValueChange: ${u}${ie})`+ce,ve(9)),w=$("ValueIdsListener",`(${f}: ${V})${ce}`,ve(10)),h=$("ValueListener",`(...[${f}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${f}: ${V}, valueId: '${e}', newValue: ${a}${ie}, oldValue: ${a}${ie}, getValueChange: ${u} | undefined]`))," | ")})${ce}`,ve(11)),g=$("InvalidValueListener",`(${f}: ${V}, valueId: Id, invalidValues: any[])${ce}`,ve(12));i("hasValues",a,t,Ge("hasValues"),Re("any Value")),i("getValues",a,e,Ge("getValues",a,e),Ce(0,2)),i("setValues","values: "+l,V,ze("setValues","values"),Ce(1,2)),i("setPartialValues","partialValues: "+l,V,ze("setPartialValues","partialValues"),Ce(2,2)),i("delValues",a,V,ze("delValues"),Ce(3,2)),i("getValueIds",a,s+"[]",Ge("getValueIds",a,s+"[]"),Te("Value",ne)),i("forEachValue","valueCallback: "+d,"void",Ge("forEachValue","valueCallback as any"),fe("Value",ne)),S(((e,l,s,o,n)=>{i(`has${n}Value`,a,t,Ge("hasValue",o),Re(ke(e))),i(`get${n}Value`,a,l,Ge("getValue",o,l),je(e)),i(`set${n}Value`,"value: "+l,V,ze("setValue",o+", value"),je(e,1)),i(`del${n}Value`,a,V,ze("delValue",o),je(e,3))})),i("getValuesJson",a,"Json",Ge("getValuesJson"),Ce(5,2)),i("setValuesJson","valuesJson: Json",V,ze("setValuesJson","valuesJson"),Ce(6,2)),i("addValuesListener",`${$e}: ${b}, mutator?: boolean`,"Id",Fe("addValuesListener",a,"mutator"),Ce(7,2)+" changes"),i("addValueIdsListener",`${$e}: ${w}, mutator?: boolean`,"Id",Fe("addValueIdsListener",a,"mutator"),pe("the Value Ids",ne,1)),i("addValueListener",`valueId: ${s} | null, ${$e}: ${h}, mutator?: boolean`,"Id",Fe("addValueListener","valueId","mutator"),pe("a Value",ne)),i("addInvalidValueListener",`valueId: IdOrNull, ${$e}: ${g}, mutator?: boolean`,"Id",Fe("addInvalidValueListener","valueId","mutator"),ue+" whenever an invalid Cell change was attempted"),r(1,C,e,l,s,d,b,w,h,g),r(0,"tinybase","ValueChange"),c(m,".setValuesSchema({",S(((e,l,t,s)=>[`[${s}]: {[${I(K(o),`'${o}'`)}]: ${I(K(l),`'${l}'`)}${T(t)?a:`, [${I(K(n),`'${n}'`)}]: ${R(t)?I(K(t),`'${t}'`):t}`}},`])),"})")}r(0,"tinybase",...Ne);const J=$("TransactionListener",`(${f}: ${V}, cellsTouched: boolean, valuesTouched: boolean)${ce}`,de+" listening to the completion of a transaction");return i("getJson",a,"Json",Ge("getJson"),Ce(5)),i("setJson","json: Json",V,ze("setJson","json"),Ce(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",Ge("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",a,V,ze("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",V,ze("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${$e}: ${J}`,"Id",Fe("addWillFinishTransactionListener"),`${ue} just before ${be}`),i("addDidFinishTransactionListener",`${$e}: ${J}`,"Id",Fe("addDidFinishTransactionListener"),`${ue} just after ${be}`),i("callListener",$e+"Id: Id",V,ze("callListener",$e+"Id"),`Manually provoke a ${$e} to be called`),i("delListener",$e+"Id: Id",V,ze("delListener",$e+"Id"),`Remove a ${$e} that was previously added to ${ne}`),i("getStore",a,"Store","store",Oe[0]+" the underlying Store object"),r(1,"tinybase","createStore",...Ne),r(1,C,V,`create${V} as create${V}Decl`,J),I("store",["createStore()",...m]),u("fluent","actions: () => Store",["actions();",`return ${f};`]),u("proxy",$e+": any",`(_: Store, ...args: any[]) => ${$e}(${f}, ...args)`),I(f,["{",...h(1),"}"]),[d(...b(0),...w(),`${re} interface ${V} {`,...h(0),"}",a,X(`Creates a ${V} object`),`${re} function create${V}(): ${V};`),d(...b(1),`${re} const create${V}: typeof create${V}Decl = () => {`,...g(),`return Object.freeze(${f});`,"};")]},We={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Me=(e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))})((e=>{const a=()=>{const a=g(e.getTablesSchemaJson());return!oe(a)||d(e.getTableIds(),(l=>{const t=e.getRowIds(l),s=k();if(d(t,(a=>d(e.getCellIds(l,a),(t=>{const o=e.getCell(l,a,t),n=O(s,t,(()=>[v(o),k(),[0],0])),[d,r,[$]]=n,i=O(r,o,(()=>0))+1;return i>$&&(n[2]=[i,o]),j(r,o,i),n[3]++,d==v(o)})))))return a[l]={},y(s,(([e,,[,s],d],r)=>{a[l][r]={[o]:e,...d==u(t)?{[n]:s}:{}}})),1}))?a:{}},l=()=>{const a=g(e.getValuesSchemaJson());return oe(a)&&e.forEachValue(((e,l)=>{a[e]={[o]:v(l)}})),a},t=e=>Pe(a(),l(),e),s=async e=>{let a;try{a=(await import("prettier")).format}catch{a=e=>e}return i(t(e),(e=>Q(a(e,We))))};return le({getStoreStats:a=>{let l=0,t=0,s=0;const o={};return e.forEachTable(((e,n)=>{l++;let d=0,r=0;const $={};n(((e,l)=>{d++;let t=0;l((()=>t++)),r+=t,a&&($[e]={rowCells:t})})),t+=d,s+=r,a&&(o[e]={tableRows:d,tableCells:r,rows:$})})),{totalTables:l,totalRows:t,totalCells:s,totalValues:u(e.getValueIds()),jsonLength:U(e.getJson()),...a?{detail:{tables:o}}:{}}},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:s,getStore:()=>e})}));export{Me as createTools};
package/lib/tools.js.gz CHANGED
Binary file
package/lib/umd/tools.js CHANGED
@@ -1 +1 @@
1
- var e,a;e=this,a=function(e){"use strict";const a=e=>typeof e,l="",t=a(l),s=a(!0),o=a(0),n="type",d="default",r=(e,a)=>e.every(a),$=(e,a)=>e.sort(a),i=(e,a)=>e.forEach(a),u=(e,a)=>e.map(a),I=e=>e.length,c=e=>0==I(e),b=(e,...a)=>e.push(...a),w=e=>e.pop(),h=(e,...a)=>e.unshift(...a),g=e=>e.shift(),C=JSON.parse,T=isFinite,f=(e,a)=>e instanceof a,V=e=>null==e,R=e=>e==t||e==s,m=e=>a(e)==t,p=e=>Array.isArray(e),v=e=>{const l=a(e);return R(l)||l==o&&T(e)?l:void 0},L=(e,a)=>e?.has(a)??!1,y=e=>[...e?.values()??[]],S=(e,a)=>e?.forEach(a),k=(e,a)=>e?.delete(a),J=e=>new Map(e),E=(e,a)=>e?.get(a),j=(e,a)=>S(e,((e,l)=>a(l,e))),x=(e,a)=>u([...e?.entries()??[]],(([e,l])=>a(l,e))),A=(e,a,l)=>V(l)?(k(e,a),e):e?.set(a,l),O=(e,a,l)=>(L(e,a)||A(e,a,l()),E(e,a)),D=e=>new Set(p(e)||V(e)?e:[e]),N=(e,a)=>e?.add(a),G=e=>[e,e],z=()=>[J(),J()],F=/[^A-Za-z]+/,P=/[^A-Za-z0-9]+/,W=/^( *)\/\*\* *(.*?) *\*\/$/gm,M=(e,a,l)=>e.substring(a,l),Z=e=>e.toUpperCase(),_=e=>e.toLowerCase(),B=(e,a,l,t=1)=>{const s=`${a}${1==t?"":t}`;return L(e,s)?B(e,a,l,t+1):(A(e,s,l),s)},Q=e=>e.replace(W,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,a=l)=>e.join(a),H=e=>e.flat(1e3),K=(e,a=0)=>q(u(e.split(P),((e,l)=>(l>0||a?Z:_)(M(e,0,1))+M(e,1)))),X=e=>Z(q((e&&!F.test(e[0])?e:" "+e).split(P),"_")),Y=e=>`/** ${e}. */`,ee=()=>{const e=z(),a=J(),t=J(),s=J();return[(...e)=>q(H(e),"\n"),(a,l,...t)=>i(t,(t=>N(O(e[a],l,D),t))),(e,l,t)=>B(a,e,[l,t]),(e,a,l,s,o,n="")=>B(t,e,[a,l,s,o,n]),(e,a,l)=>B(s,e,p(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>E(s,e)===a?e:B(s,e,a),a=>[...$(x(e[a],((e,a)=>`import {${q($(y(e)),", ")}} from '${a}';`))),l],()=>x(a,(([e,a],t)=>[Y(a),`export type ${t} = ${e};`,l])),e=>x(t,(([a,t,s,o,n],d)=>{const r=e?[`${d}: ${n}(${a}): ${t} => ${s},`]:[`${d}${n}(${a}): ${t};`];return e||h(r,Y(o)),b(r,l),r})),()=>x(s,((e,a)=>(e=p(e)?e:[e],b(e,w(e)+";"),[`const ${a} = ${g(e)}`,e,l])))]},ae=Object,le=ae.keys,te=ae.freeze,se=e=>f(e,ae)&&e.constructor==ae,oe=(e,a)=>u(ae.entries(e),(([e,l])=>a(l,e))),ne=e=>se(e)&&c(le(e)),de="the Store",re="A function for",$e="export",ie="listener",ue=" | undefined",Ie=`Registers a ${ie} that will be called`,ce="Represents",be=" => void",we="the end of the transaction",he="the specified Row",ge="a string serialization of",Ce=(e=0,a=0)=>`the ${Ne[e]}content of${a?" "+de:""}`,Te=(e,a=0,l=0)=>`${Oe[e]} ${Ce(a,1)}${l?" when set":""}`,fe=(e,a=0)=>`${ce} a Row when ${a?"s":"g"}etting ${Ce()} the '${e}' Table`,Ve=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,Re=(e,a)=>`Calls a function for each ${e} in ${a}`,me=(e,a=de)=>`Gets whether ${e} exists in ${a}`,pe=e=>"A function that takes "+e,ve=(e,a=0)=>`${re} listening to changes to ${De[e]} in ${De[a]}`,Le=(e,a,t=0)=>`${Ie} whenever ${e} in ${a} change`+(t?l:"s"),ye=e=>`the '${e}' Table`,Se=e=>`${he} in ${ye(e)}`,ke=e=>`the '${e}' Cell`,Je=e=>`the '${e}' Value`,Ee=(e,a=0)=>`${Oe[a]} ${Ce()} ${ye(e)}`,je=(e,a=0)=>`${Oe[a]} ${Ce()} ${Se(e)}`,xe=(e,a,l=0)=>`${Oe[l]} ${ke(a)} for ${Se(e)}`,Ae=(e,a=0)=>`${Oe[a]} ${Je(e)}`,Oe=["Gets","Sets","Sets part of","Deletes",ce,"Gets "+ge,"Sets "+ge,Ie+" whenever"],De=[de,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],Ne=["","tabular ","keyed value "],Ge=["DoRollback","Id","IdOrNull","Ids","Json","Store"],ze=(e,a=l,t=l)=>`store.${e}(${a})${t?" as "+t:l}`,Fe=(e,a=l)=>`fluent(() => ${ze(e,a)})`,Pe=(e,a=l,t=l)=>`store.${e}(${a?a+", ":l}proxy(${ie})${t?", "+t:l})`,We=(e,a,t)=>{if(ne(e)&&ne(a))return G(l);const[o,r,$,i,u,I,c,w,h,g]=ee(),C=`./${K(t)}.d`,T=K(t,1),f=K(T),R=[],p=J(),v=a=>oe(e,((e,t)=>a(t,O(p,t,(()=>{const e=K(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ce} the '${t}' Table`),$(e+"Row",`{${q(L(t,((e,a,t)=>`'${e}'${V(t)?"?":l}: ${a};`))," ")}}`,fe(t)),$(e+"RowWhenSet",`{${q(L(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,fe(t,1)),$(e+"CellId",q(L(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(L(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${be}`,pe(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${be})${be}`,pe(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),K(t,1),I(X(t),`'${t}'`)))),L=(a,l)=>oe(e[a],((e,a)=>l(a,e[n],e[d],I(X(a),`'${a}'`),K(a,1)))),S=e=>oe(a,((a,l)=>e(l,a[n],a[d],I(X(l),`'${l}'`),K(l,1))));if(r(1,C,T,`create${T} as create${T}Decl`),!ne(e)){const e=$("Tables",`{${q(v(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Te(4,1)),a=$("TableId",q(v((e=>`'${e}'`))," | "),"A Table Id in "+de),t=$("TableCallback",`(...[tableId, rowCallback]: ${q(v(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${be}]`))," | ")})${be}`,pe("a Table Id, and a Row iterator")),o=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(v(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,re+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${f}: ${T}, getCellChange: ${o}${ue})${be}`,ve(1)),c=$("TableIdsListener",`(${f}: ${T})${be}`,ve(2)),w=$("TableListener",`(${f}: ${T}, tableId: ${a}, getCellChange: ${o}${ue})${be}`,ve(3)),h=$("RowIdsListener",`(${f}: ${T}, tableId: ${a})`+be,ve(4,3)),g=$("RowListener",`(${f}: ${T}, tableId: ${a}, rowId: Id, getCellChange: ${o}${ue})${be}`,ve(5,3)),p=$("CellIdsListener",`(${f}: ${T}, tableId: ${a}, rowId: Id)`+be,ve(6,5)),S=$("CellListener",`(...[${f}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(H(v((e=>L(e,((a,l)=>`[${f}: ${T}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${ue}, oldCell: ${l}${ue}, getCellChange: ${o} | undefined]`)))))," | ")})${be}`,ve(7,5)),k=$("InvalidCellListener",`(${f}: ${T}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${be}`,ve(8));i("hasTables",l,s,ze("hasTables"),me("any Table")),i("getTables",l,e,ze("getTables"),Te(0,1)),i("setTables","tables: "+e,T,Fe("setTables","tables"),Te(1,1)),i("delTables",l,T,Fe("delTables"),Te(3,1)),i("getTableIds",l,a+"[]",ze("getTableIds",l,a+"[]"),Ve("Table",de)),i("forEachTable","tableCallback: "+t,"void",ze("forEachTable","tableCallback as any"),Re("Table",de));const E=J();v(((e,[a,t,o,n,d,$],u,I)=>{r(1,C,a,t,o,n,d,$),i(`has${u}Table`,l,s,ze("hasTable",I),me(ye(e))),i(`get${u}Table`,l,a,ze("getTable",I,a),Ee(e)),i(`set${u}Table`,"table: "+a,T,Fe("setTable",I+", table"),Ee(e,1)),i(`del${u}Table`,l,T,Fe("delTable",I),Ee(e,3)),i(`get${u}RowIds`,l,"Ids",ze("getRowIds",I),Ve("Row",ye(e))),i(`get${u}SortedRowIds`,`cellId?: ${n}, descending?: boolean, offset?: number, limit?: number`,"Ids",ze("getSortedRowIds",I+", cellId, descending, offset, limit"),Ve("Row",ye(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",ze("forEachRow",I+", rowCallback as any"),Re("Row",ye(e))),i(`has${u}Row`,"rowId: Id",s,ze("hasRow",I+", rowId"),me(he,ye(e))),i(`get${u}Row`,"rowId: Id",t,ze("getRow",I+", rowId",t),je(e)),i(`set${u}Row`,"rowId: Id, row: "+o,T,Fe("setRow",I+", rowId, row"),je(e,1)),i(`add${u}Row`,"row: "+o,"Id"+ue,ze("addRow",I+", row"),"Adds a new Row to "+ye(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+o,T,Fe("setPartialRow",I+", rowId, partialRow"),je(e,2)),i(`del${u}Row`,"rowId: Id",T,Fe("delRow",I+", rowId"),je(e,3)),i(`get${u}CellIds`,"rowId: Id",n+"[]",ze("getCellIds",I+", rowId",n+"[]"),Ve("Cell",Se(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+d,"void",ze("forEachCell",I+", rowId, cellCallback as any"),Re("Cell",Se(e))),L(e,((a,t,o,n,d)=>{const r="Map"+K(t,1);A(E,t,r),i(`has${u}${d}Cell`,"rowId: Id",s,ze("hasCell",`${I}, rowId, ${n}`),me(ke(a),Se(e)));const $=`${t}${V(o)?ue:l}`;i(`get${u}${d}Cell`,"rowId: Id",$,ze("getCell",`${I}, rowId, ${n}`,$),xe(e,a)),i(`set${u}${d}Cell`,`rowId: Id, cell: ${t} | ${r}`,T,Fe("setCell",`${I}, rowId, ${n}, cell as any`),xe(e,a,1)),i(`del${u}${d}Cell`,"rowId: Id",T,Fe("delCell",`${I}, rowId, ${n}`),xe(e,a,3))}))})),i("getTablesJson",l,"Json",ze("getTablesJson"),Te(5,1)),i("setTablesJson","tablesJson: Json",T,Fe("setTablesJson","tablesJson"),Te(6,1)),i("addTablesListener",`${ie}: ${u}, mutator?: boolean`,"Id",Pe("addTablesListener",l,"mutator"),Te(7,1)+" changes"),i("addTableIdsListener",`${ie}: ${c}, mutator?: boolean`,"Id",Pe("addTableIdsListener",l,"mutator"),Le("the Table Ids",de,1)),i("addTableListener",`tableId: ${a} | null, ${ie}: ${w}, mutator?: boolean`,"Id",Pe("addTableListener","tableId","mutator"),Le("a Table",de)),i("addRowIdsListener",`tableId: ${a} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Pe("addRowIdsListener","tableId","mutator"),Le("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${a} | null, rowId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Pe("addRowListener","tableId, rowId","mutator"),Le("a Row","a Table")),i("addCellIdsListener",`tableId: ${a} | null, rowId: IdOrNull, ${ie}: ${p}, mutator?: boolean`,"Id",Pe("addCellIdsListener","tableId, rowId","mutator"),Le("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${a} | null, rowId: IdOrNull, cellId: ${q(v(((e,a)=>a[3]))," | ")} | null, ${ie}: ${S}, mutator?: boolean`,"Id",Pe("addCellListener","tableId, rowId, cellId","mutator"),Le("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${ie}: ${k}, mutator?: boolean`,"Id",Pe("addInvalidCellListener","tableId, rowId, cellId","mutator"),Ie+" whenever an invalid Cell change was attempted"),j(E,((e,a)=>$(a,`(cell: ${e}${ue}) => ${e}`,`Takes a ${e} Cell value and returns another`))),r(1,C,e,a,t,u,c,w,h,g,p,S,k,...y(E)),r(0,"tinybase","CellChange"),b(R,".setTablesSchema({",H(v(((e,a,t,s)=>[`[${s}]: {`,...L(e,((e,a,t,s)=>`[${s}]: {[${I(X(n),`'${n}'`)}]: ${I(X(a),`'${a}'`)}${V(t)?l:`, [${I(X(d),`'${d}'`)}]: ${m(t)?I(X(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!ne(a)){const e=$("Values",`{${q(S(((e,a,t)=>`'${e}'${V(t)?"?":l}: ${a};`))," ")}}`,Te(4,2)),a=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Te(4,2,1)),t=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+de),o=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${be}`,pe("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${t}) => ValueChange`,re+" returning information about any Value's changes during a transaction"),c=$("ValuesListener",`(${f}: ${T}, getValueChange: ${u}${ue})`+be,ve(9)),w=$("ValueIdsListener",`(${f}: ${T})${be}`,ve(10)),h=$("ValueListener",`(...[${f}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${f}: ${T}, valueId: '${e}', newValue: ${a}${ue}, oldValue: ${a}${ue}, getValueChange: ${u} | undefined]`))," | ")})${be}`,ve(11)),g=$("InvalidValueListener",`(${f}: ${T}, valueId: Id, invalidValues: any[])${be}`,ve(12));i("hasValues",l,s,ze("hasValues"),me("any Value")),i("getValues",l,e,ze("getValues"),Te(0,2)),i("setValues","values: "+a,T,Fe("setValues","values"),Te(1,2)),i("setPartialValues","partialValues: "+a,T,Fe("setPartialValues","partialValues"),Te(2,2)),i("delValues",l,T,Fe("delValues"),Te(3,2)),i("getValueIds",l,t+"[]",ze("getValueIds",l,t+"[]"),Ve("Value",de)),i("forEachValue","valueCallback: "+o,"void",ze("forEachValue","valueCallback as any"),Re("Value",de)),S(((e,a,t,o,n)=>{i(`has${n}Value`,l,s,ze("hasValue",o),me(Je(e))),i(`get${n}Value`,l,a,ze("getValue",o,a),Ae(e)),i(`set${n}Value`,"value: "+a,T,Fe("setValue",o+", value"),Ae(e,1)),i(`del${n}Value`,l,T,Fe("delValue",o),Ae(e,3))})),i("getValuesJson",l,"Json",ze("getValuesJson"),Te(5,2)),i("setValuesJson","valuesJson: Json",T,Fe("setValuesJson","valuesJson"),Te(6,2)),i("addValuesListener",`${ie}: ${c}, mutator?: boolean`,"Id",Pe("addValuesListener",l,"mutator"),Te(7,2)+" changes"),i("addValueIdsListener",`${ie}: ${w}, mutator?: boolean`,"Id",Pe("addValueIdsListener",l,"mutator"),Le("the Value Ids",de,1)),i("addValueListener",`valueId: ${t} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Pe("addValueListener","valueId","mutator"),Le("a Value",de)),i("addInvalidValueListener",`valueId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Pe("addInvalidValueListener","valueId","mutator"),Ie+" whenever an invalid Cell change was attempted"),r(1,C,e,t,o,c,w,h,g),r(0,"tinybase","ValueChange"),b(R,".setValuesSchema({",S(((e,a,t,s)=>[`[${s}]: {[${I(X(n),`'${n}'`)}]: ${I(X(a),`'${a}'`)}${V(t)?l:`, [${I(X(d),`'${d}'`)}]: ${m(t)?I(X(t),`'${t}'`):t}`}},`])),"})")}r(0,"tinybase",...Ge);const k=$("TransactionListener",`(${f}: ${T}, cellsTouched: boolean, valuesTouched: boolean)${be}`,re+" listening to the completion of a transaction");return i("getJson",l,"Json",ze("getJson"),Te(5)),i("setJson","json: Json",T,Fe("setJson","json"),Te(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",ze("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",l,T,Fe("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",T,Fe("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${ie}: ${k}`,"Id",Pe("addWillFinishTransactionListener"),`${Ie} just before ${we}`),i("addDidFinishTransactionListener",`${ie}: ${k}`,"Id",Pe("addDidFinishTransactionListener"),`${Ie} just after ${we}`),i("callListener",ie+"Id: Id",T,Fe("callListener",ie+"Id"),`Manually provoke a ${ie} to be called`),i("delListener",ie+"Id: Id",T,Fe("delListener",ie+"Id"),`Remove a ${ie} that was previously added to ${de}`),i("getStore",l,"Store","store",Oe[0]+" the underlying Store object"),r(1,"tinybase","createStore",...Ge),r(1,C,T,`create${T} as create${T}Decl`,k),I("store",["createStore()",...R]),u("fluent","actions: () => Store",["actions();",`return ${f};`]),u("proxy",ie+": any",`(_: Store, ...args: any[]) => ${ie}(${f}, ...args)`),I(f,["{",...h(1),"}"]),[o(...c(0),...w(),`${$e} interface ${T} {`,...h(0),"}",l,Y(`Creates a ${T} object`),`${$e} function create${T}(): ${T};`),o(...c(1),`${$e} const create${T}: typeof create${T}Decl = () => {`,...g(),`return Object.freeze(${f});`,"};")]},Me={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ze=(e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))})((e=>{const a=()=>{const a=C(e.getTablesSchemaJson());return!ne(a)||r(e.getTableIds(),(l=>{const t=e.getRowIds(l),s=J();if(r(t,(a=>r(e.getCellIds(l,a),(t=>{const o=e.getCell(l,a,t),n=O(s,t,(()=>[v(o),J(),[0],0])),[d,r,[$]]=n,i=O(r,o,(()=>0))+1;return i>$&&(n[2]=[i,o]),A(r,o,i),n[3]++,d==v(o)})))))return a[l]={},S(s,(([e,,[,s],o],r)=>{a[l][r]={[n]:e,...o==I(t)?{[d]:s}:{}}})),1}))?a:{}},l=()=>{const a=C(e.getValuesSchemaJson());return ne(a)&&e.forEachValue(((e,l)=>{a[e]={[n]:v(l)}})),a},t=e=>We(a(),l(),e),s=async e=>{let a;try{a=(await import("prettier")).format}catch{a=e=>e}return u(t(e),(e=>Q(a(e,Me))))};return te({getStoreStats:a=>{let l=0,t=0,s=0;const o={};return e.forEachTable(((e,n)=>{l++;let d=0,r=0;const $={};n(((e,l)=>{d++;let t=0;l((()=>t++)),r+=t,a&&($[e]={rowCells:t})})),t+=d,s+=r,a&&(o[e]={tableRows:d,tableCells:r,rows:$})})),{totalTables:l,totalRows:t,totalCells:s,totalValues:I(e.getValueIds()),jsonLength:U(e.getJson()),...a?{detail:{tables:o}}:{}}},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:s,getStore:()=>e})}));e.createTools=Ze},"object"==typeof exports&&"undefined"!=typeof module?a(exports):"function"==typeof define&&define.amd?define(["exports"],a):a((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
1
+ var e,a;e=this,a=function(e){"use strict";const a=e=>typeof e,l="",t=a(l),s=a(!0),o=a(0),n="type",d="default",r=(e,a)=>e.every(a),$=(e,a)=>e.sort(a),i=(e,a)=>e.forEach(a),u=(e,a)=>e.map(a),I=e=>e.length,c=e=>0==I(e),b=(e,...a)=>e.push(...a),w=e=>e.pop(),h=(e,...a)=>e.unshift(...a),g=e=>e.shift(),C=JSON.parse,T=isFinite,f=(e,a)=>e instanceof a,V=e=>null==e,R=e=>e==t||e==s,m=e=>a(e)==t,p=e=>Array.isArray(e),v=e=>{const l=a(e);return R(l)||l==o&&T(e)?l:void 0},L=(e,a)=>e?.has(a)??!1,y=e=>[...e?.values()??[]],S=(e,a)=>e?.forEach(a),k=(e,a)=>e?.delete(a),J=e=>new Map(e),E=(e,a)=>e?.get(a),j=(e,a)=>S(e,((e,l)=>a(l,e))),x=(e,a)=>u([...e?.entries()??[]],(([e,l])=>a(l,e))),A=(e,a,l)=>V(l)?(k(e,a),e):e?.set(a,l),O=(e,a,l)=>(L(e,a)||A(e,a,l()),E(e,a)),D=e=>new Set(p(e)||V(e)?e:[e]),N=(e,a)=>e?.add(a),G=e=>[e,e],z=()=>[J(),J()],F=/[^A-Za-z]+/,P=/[^A-Za-z0-9]+/,W=/^( *)\/\*\* *(.*?) *\*\/$/gm,M=(e,a,l)=>e.substring(a,l),Z=e=>e.toUpperCase(),_=e=>e.toLowerCase(),B=(e,a,l,t=1)=>{const s=`${a}${1==t?"":t}`;return L(e,s)?B(e,a,l,t+1):(A(e,s,l),s)},Q=e=>e.replace(W,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,a=l)=>e.join(a),H=e=>e.flat(1e3),K=(e,a=0)=>q(u(e.split(P),((e,l)=>(l>0||a?Z:_)(M(e,0,1))+M(e,1)))),X=e=>Z(q((e&&!F.test(e[0])?e:" "+e).split(P),"_")),Y=e=>`/** ${e}. */`,ee=()=>{const e=z(),a=J(),t=J(),s=J();return[(...e)=>q(H(e),"\n"),(a,l,...t)=>i(t,(t=>N(O(e[a],l,D),t))),(e,l,t)=>B(a,e,[l,t]),(e,a,l,s,o,n="")=>B(t,e,[a,l,s,o,n]),(e,a,l)=>B(s,e,p(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>E(s,e)===a?e:B(s,e,a),a=>[...$(x(e[a],((e,a)=>`import {${q($(y(e)),", ")}} from '${a}';`))),l],()=>x(a,(([e,a],t)=>[Y(a),`export type ${t} = ${e};`,l])),e=>x(t,(([a,t,s,o,n],d)=>{const r=e?[`${d}: ${n}(${a}): ${t} => ${s},`]:[`${d}${n}(${a}): ${t};`];return e||h(r,Y(o)),b(r,l),r})),()=>x(s,((e,a)=>(e=p(e)?e:[e],b(e,w(e)+";"),[`const ${a} = ${g(e)}`,e,l])))]},ae=Object,le=ae.keys,te=ae.freeze,se=e=>f(e,ae)&&e.constructor==ae,oe=(e,a)=>u(ae.entries(e),(([e,l])=>a(l,e))),ne=e=>se(e)&&c(le(e)),de="the Store",re="A function for",$e="export",ie="listener",ue=" | undefined",Ie=`Registers a ${ie} that will be called`,ce="Represents",be=" => void",we="the end of the transaction",he="the specified Row",ge="a string serialization of",Ce=(e=0,a=0)=>`the ${Ne[e]}content of${a?" "+de:""}`,Te=(e,a=0,l=0)=>`${Oe[e]} ${Ce(a,1)}${l?" when set":""}`,fe=(e,a=0)=>`${ce} a Row when ${a?"s":"g"}etting ${Ce()} the '${e}' Table`,Ve=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,Re=(e,a)=>`Calls a function for each ${e} in ${a}`,me=(e,a=de)=>`Gets whether ${e} exists in ${a}`,pe=e=>"A function that takes "+e,ve=(e,a=0)=>`${re} listening to changes to ${De[e]} in ${De[a]}`,Le=(e,a,t=0)=>`${Ie} whenever ${e} in ${a} change`+(t?l:"s"),ye=e=>`the '${e}' Table`,Se=e=>`${he} in ${ye(e)}`,ke=e=>`the '${e}' Cell`,Je=e=>`the '${e}' Value`,Ee=(e,a=0)=>`${Oe[a]} ${Ce()} ${ye(e)}`,je=(e,a=0)=>`${Oe[a]} ${Ce()} ${Se(e)}`,xe=(e,a,l=0)=>`${Oe[l]} ${ke(a)} for ${Se(e)}`,Ae=(e,a=0)=>`${Oe[a]} ${Je(e)}`,Oe=["Gets","Sets","Sets part of","Deletes",ce,"Gets "+ge,"Sets "+ge,Ie+" whenever"],De=[de,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],Ne=["","tabular ","keyed value "],Ge=["DoRollback","Id","IdOrNull","Ids","Json","Store"],ze=(e,a=l,t=l)=>`store.${e}(${a})${t?" as "+t:l}`,Fe=(e,a=l)=>`fluent(() => ${ze(e,a)})`,Pe=(e,a=l,t=l)=>`store.${e}(${a?a+", ":l}proxy(${ie})${t?", "+t:l})`,We=(e,a,t)=>{if(ne(e)&&ne(a))return G(l);const[o,r,$,i,u,I,c,w,h,g]=ee(),C=`./${K(t)}.d`,T=K(t,1),f=K(T),R=[],p=J(),v=a=>oe(e,((e,t)=>a(t,O(p,t,(()=>{const e=K(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ce} the '${t}' Table`),$(e+"Row",`{${q(L(t,((e,a,t)=>`'${e}'${V(t)?"?":l}: ${a};`))," ")}}`,fe(t)),$(e+"RowWhenSet",`{${q(L(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,fe(t,1)),$(e+"CellId",q(L(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(L(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${be}`,pe(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${be})${be}`,pe(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),K(t,1),I(X(t),`'${t}'`)))),L=(a,l)=>oe(e[a],((e,a)=>l(a,e[n],e[d],I(X(a),`'${a}'`),K(a,1)))),S=e=>oe(a,((a,l)=>e(l,a[n],a[d],I(X(l),`'${l}'`),K(l,1))));if(r(1,C,T,`create${T} as create${T}Decl`),!ne(e)){const e=$("Tables",`{${q(v(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Te(4,1)),a=$("TableId",q(v((e=>`'${e}'`))," | "),"A Table Id in "+de),t=$("TableCallback",`(...[tableId, rowCallback]: ${q(v(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${be}]`))," | ")})${be}`,pe("a Table Id, and a Row iterator")),o=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(v(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,re+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${f}: ${T}, getCellChange: ${o}${ue})${be}`,ve(1)),c=$("TableIdsListener",`(${f}: ${T})${be}`,ve(2)),w=$("TableListener",`(${f}: ${T}, tableId: ${a}, getCellChange: ${o}${ue})${be}`,ve(3)),h=$("RowIdsListener",`(${f}: ${T}, tableId: ${a})`+be,ve(4,3)),g=$("RowListener",`(${f}: ${T}, tableId: ${a}, rowId: Id, getCellChange: ${o}${ue})${be}`,ve(5,3)),p=$("CellIdsListener",`(${f}: ${T}, tableId: ${a}, rowId: Id)`+be,ve(6,5)),S=$("CellListener",`(...[${f}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(H(v((e=>L(e,((a,l)=>`[${f}: ${T}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${ue}, oldCell: ${l}${ue}, getCellChange: ${o} | undefined]`)))))," | ")})${be}`,ve(7,5)),k=$("InvalidCellListener",`(${f}: ${T}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${be}`,ve(8));i("hasTables",l,s,ze("hasTables"),me("any Table")),i("getTables",l,e,ze("getTables"),Te(0,1)),i("setTables","tables: "+e,T,Fe("setTables","tables"),Te(1,1)),i("delTables",l,T,Fe("delTables"),Te(3,1)),i("getTableIds",l,a+"[]",ze("getTableIds",l,a+"[]"),Ve("Table",de)),i("forEachTable","tableCallback: "+t,"void",ze("forEachTable","tableCallback as any"),Re("Table",de));const E=J();v(((e,[a,t,o,n,d,$],u,I)=>{r(1,C,a,t,o,n,d,$),i(`has${u}Table`,l,s,ze("hasTable",I),me(ye(e))),i(`get${u}Table`,l,a,ze("getTable",I,a),Ee(e)),i(`set${u}Table`,"table: "+a,T,Fe("setTable",I+", table"),Ee(e,1)),i(`del${u}Table`,l,T,Fe("delTable",I),Ee(e,3)),i(`get${u}RowIds`,l,"Ids",ze("getRowIds",I),Ve("Row",ye(e))),i(`get${u}SortedRowIds`,`cellId?: ${n}, descending?: boolean, offset?: number, limit?: number`,"Ids",ze("getSortedRowIds",I+", cellId, descending, offset, limit"),Ve("Row",ye(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",ze("forEachRow",I+", rowCallback as any"),Re("Row",ye(e))),i(`has${u}Row`,"rowId: Id",s,ze("hasRow",I+", rowId"),me(he,ye(e))),i(`get${u}Row`,"rowId: Id",t,ze("getRow",I+", rowId",t),je(e)),i(`set${u}Row`,"rowId: Id, row: "+o,T,Fe("setRow",I+", rowId, row"),je(e,1)),i(`add${u}Row`,"row: "+o,"Id"+ue,ze("addRow",I+", row"),"Adds a new Row to "+ye(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+o,T,Fe("setPartialRow",I+", rowId, partialRow"),je(e,2)),i(`del${u}Row`,"rowId: Id",T,Fe("delRow",I+", rowId"),je(e,3)),i(`get${u}CellIds`,"rowId: Id",n+"[]",ze("getCellIds",I+", rowId",n+"[]"),Ve("Cell",Se(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+d,"void",ze("forEachCell",I+", rowId, cellCallback as any"),Re("Cell",Se(e))),L(e,((a,t,o,n,d)=>{const r="Map"+K(t,1);A(E,t,r),i(`has${u}${d}Cell`,"rowId: Id",s,ze("hasCell",`${I}, rowId, ${n}`),me(ke(a),Se(e)));const $=`${t}${V(o)?ue:l}`;i(`get${u}${d}Cell`,"rowId: Id",$,ze("getCell",`${I}, rowId, ${n}`,$),xe(e,a)),i(`set${u}${d}Cell`,`rowId: Id, cell: ${t} | ${r}`,T,Fe("setCell",`${I}, rowId, ${n}, cell as any`),xe(e,a,1)),i(`del${u}${d}Cell`,"rowId: Id",T,Fe("delCell",`${I}, rowId, ${n}`),xe(e,a,3))}))})),i("getTablesJson",l,"Json",ze("getTablesJson"),Te(5,1)),i("setTablesJson","tablesJson: Json",T,Fe("setTablesJson","tablesJson"),Te(6,1)),i("addTablesListener",`${ie}: ${u}, mutator?: boolean`,"Id",Pe("addTablesListener",l,"mutator"),Te(7,1)+" changes"),i("addTableIdsListener",`${ie}: ${c}, mutator?: boolean`,"Id",Pe("addTableIdsListener",l,"mutator"),Le("the Table Ids",de,1)),i("addTableListener",`tableId: ${a} | null, ${ie}: ${w}, mutator?: boolean`,"Id",Pe("addTableListener","tableId","mutator"),Le("a Table",de)),i("addRowIdsListener",`tableId: ${a} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Pe("addRowIdsListener","tableId","mutator"),Le("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${a} | null, rowId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Pe("addRowListener","tableId, rowId","mutator"),Le("a Row","a Table")),i("addCellIdsListener",`tableId: ${a} | null, rowId: IdOrNull, ${ie}: ${p}, mutator?: boolean`,"Id",Pe("addCellIdsListener","tableId, rowId","mutator"),Le("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${a} | null, rowId: IdOrNull, cellId: ${q(v(((e,a)=>a[3]))," | ")} | null, ${ie}: ${S}, mutator?: boolean`,"Id",Pe("addCellListener","tableId, rowId, cellId","mutator"),Le("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${ie}: ${k}, mutator?: boolean`,"Id",Pe("addInvalidCellListener","tableId, rowId, cellId","mutator"),Ie+" whenever an invalid Cell change was attempted"),j(E,((e,a)=>$(a,`(cell: ${e}${ue}) => ${e}`,`Takes a ${e} Cell value and returns another`))),r(1,C,e,a,t,u,c,w,h,g,p,S,k,...y(E)),r(0,"tinybase","CellChange"),b(R,".setTablesSchema({",H(v(((e,a,t,s)=>[`[${s}]: {`,...L(e,((e,a,t,s)=>`[${s}]: {[${I(X(n),`'${n}'`)}]: ${I(X(a),`'${a}'`)}${V(t)?l:`, [${I(X(d),`'${d}'`)}]: ${m(t)?I(X(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!ne(a)){const e=$("Values",`{${q(S(((e,a,t)=>`'${e}'${V(t)?"?":l}: ${a};`))," ")}}`,Te(4,2)),a=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Te(4,2,1)),t=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+de),o=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${be}`,pe("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${t}) => ValueChange`,re+" returning information about any Value's changes during a transaction"),c=$("ValuesListener",`(${f}: ${T}, getValueChange: ${u}${ue})`+be,ve(9)),w=$("ValueIdsListener",`(${f}: ${T})${be}`,ve(10)),h=$("ValueListener",`(...[${f}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${f}: ${T}, valueId: '${e}', newValue: ${a}${ue}, oldValue: ${a}${ue}, getValueChange: ${u} | undefined]`))," | ")})${be}`,ve(11)),g=$("InvalidValueListener",`(${f}: ${T}, valueId: Id, invalidValues: any[])${be}`,ve(12));i("hasValues",l,s,ze("hasValues"),me("any Value")),i("getValues",l,e,ze("getValues",l,e),Te(0,2)),i("setValues","values: "+a,T,Fe("setValues","values"),Te(1,2)),i("setPartialValues","partialValues: "+a,T,Fe("setPartialValues","partialValues"),Te(2,2)),i("delValues",l,T,Fe("delValues"),Te(3,2)),i("getValueIds",l,t+"[]",ze("getValueIds",l,t+"[]"),Ve("Value",de)),i("forEachValue","valueCallback: "+o,"void",ze("forEachValue","valueCallback as any"),Re("Value",de)),S(((e,a,t,o,n)=>{i(`has${n}Value`,l,s,ze("hasValue",o),me(Je(e))),i(`get${n}Value`,l,a,ze("getValue",o,a),Ae(e)),i(`set${n}Value`,"value: "+a,T,Fe("setValue",o+", value"),Ae(e,1)),i(`del${n}Value`,l,T,Fe("delValue",o),Ae(e,3))})),i("getValuesJson",l,"Json",ze("getValuesJson"),Te(5,2)),i("setValuesJson","valuesJson: Json",T,Fe("setValuesJson","valuesJson"),Te(6,2)),i("addValuesListener",`${ie}: ${c}, mutator?: boolean`,"Id",Pe("addValuesListener",l,"mutator"),Te(7,2)+" changes"),i("addValueIdsListener",`${ie}: ${w}, mutator?: boolean`,"Id",Pe("addValueIdsListener",l,"mutator"),Le("the Value Ids",de,1)),i("addValueListener",`valueId: ${t} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Pe("addValueListener","valueId","mutator"),Le("a Value",de)),i("addInvalidValueListener",`valueId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Pe("addInvalidValueListener","valueId","mutator"),Ie+" whenever an invalid Cell change was attempted"),r(1,C,e,a,t,o,c,w,h,g),r(0,"tinybase","ValueChange"),b(R,".setValuesSchema({",S(((e,a,t,s)=>[`[${s}]: {[${I(X(n),`'${n}'`)}]: ${I(X(a),`'${a}'`)}${V(t)?l:`, [${I(X(d),`'${d}'`)}]: ${m(t)?I(X(t),`'${t}'`):t}`}},`])),"})")}r(0,"tinybase",...Ge);const k=$("TransactionListener",`(${f}: ${T}, cellsTouched: boolean, valuesTouched: boolean)${be}`,re+" listening to the completion of a transaction");return i("getJson",l,"Json",ze("getJson"),Te(5)),i("setJson","json: Json",T,Fe("setJson","json"),Te(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",ze("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",l,T,Fe("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",T,Fe("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${ie}: ${k}`,"Id",Pe("addWillFinishTransactionListener"),`${Ie} just before ${we}`),i("addDidFinishTransactionListener",`${ie}: ${k}`,"Id",Pe("addDidFinishTransactionListener"),`${Ie} just after ${we}`),i("callListener",ie+"Id: Id",T,Fe("callListener",ie+"Id"),`Manually provoke a ${ie} to be called`),i("delListener",ie+"Id: Id",T,Fe("delListener",ie+"Id"),`Remove a ${ie} that was previously added to ${de}`),i("getStore",l,"Store","store",Oe[0]+" the underlying Store object"),r(1,"tinybase","createStore",...Ge),r(1,C,T,`create${T} as create${T}Decl`,k),I("store",["createStore()",...R]),u("fluent","actions: () => Store",["actions();",`return ${f};`]),u("proxy",ie+": any",`(_: Store, ...args: any[]) => ${ie}(${f}, ...args)`),I(f,["{",...h(1),"}"]),[o(...c(0),...w(),`${$e} interface ${T} {`,...h(0),"}",l,Y(`Creates a ${T} object`),`${$e} function create${T}(): ${T};`),o(...c(1),`${$e} const create${T}: typeof create${T}Decl = () => {`,...g(),`return Object.freeze(${f});`,"};")]},Me={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ze=(e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))})((e=>{const a=()=>{const a=C(e.getTablesSchemaJson());return!ne(a)||r(e.getTableIds(),(l=>{const t=e.getRowIds(l),s=J();if(r(t,(a=>r(e.getCellIds(l,a),(t=>{const o=e.getCell(l,a,t),n=O(s,t,(()=>[v(o),J(),[0],0])),[d,r,[$]]=n,i=O(r,o,(()=>0))+1;return i>$&&(n[2]=[i,o]),A(r,o,i),n[3]++,d==v(o)})))))return a[l]={},S(s,(([e,,[,s],o],r)=>{a[l][r]={[n]:e,...o==I(t)?{[d]:s}:{}}})),1}))?a:{}},l=()=>{const a=C(e.getValuesSchemaJson());return ne(a)&&e.forEachValue(((e,l)=>{a[e]={[n]:v(l)}})),a},t=e=>We(a(),l(),e),s=async e=>{let a;try{a=(await import("prettier")).format}catch{a=e=>e}return u(t(e),(e=>Q(a(e,Me))))};return te({getStoreStats:a=>{let l=0,t=0,s=0;const o={};return e.forEachTable(((e,n)=>{l++;let d=0,r=0;const $={};n(((e,l)=>{d++;let t=0;l((()=>t++)),r+=t,a&&($[e]={rowCells:t})})),t+=d,s+=r,a&&(o[e]={tableRows:d,tableCells:r,rows:$})})),{totalTables:l,totalRows:t,totalCells:s,totalValues:I(e.getValueIds()),jsonLength:U(e.getJson()),...a?{detail:{tables:o}}:{}}},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:s,getStore:()=>e})}));e.createTools=Ze},"object"==typeof exports&&"undefined"!=typeof module?a(exports):"function"==typeof define&&define.amd?define(["exports"],a):a((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
Binary file
@@ -1 +1 @@
1
- var e,a;e=this,a=function(e){"use strict";const a=e=>typeof e,l="",t=a(l),o=a(!0),n=a(0),s="type",r="default",d=(e,a)=>e.every(a),$=(e,a)=>e.sort(a),i=(e,a)=>e.forEach(a),u=(e,a)=>e.map(a),I=e=>e.length,c=e=>0==I(e),b=(e,...a)=>e.push(...a),w=e=>e.pop(),h=(e,...a)=>e.unshift(...a),g=e=>e.shift(),C=JSON.parse,f=isFinite,T=(e,a)=>e instanceof a,V=e=>null==e,v=e=>e==t||e==o,p=e=>a(e)==t,R=e=>Array.isArray(e),m=e=>{const l=a(e);return v(l)||l==n&&f(e)?l:void 0},y=(e,a)=>{var l;return null!=(l=null==e?void 0:e.has(a))&&l},L=e=>{var a;return[...null!=(a=null==e?void 0:e.values())?a:[]]},S=(e,a)=>null==e?void 0:e.forEach(a),k=(e,a)=>null==e?void 0:e.delete(a),J=e=>new Map(e),E=(e,a)=>null==e?void 0:e.get(a),O=(e,a)=>S(e,((e,l)=>a(l,e))),j=(e,a)=>{var l;return u([...null!=(l=null==e?void 0:e.entries())?l:[]],(([e,l])=>a(l,e)))},x=(e,a,l)=>V(l)?(k(e,a),e):null==e?void 0:e.set(a,l),A=(e,a,l)=>(y(e,a)||x(e,a,l()),E(e,a)),P=e=>new Set(R(e)||V(e)?e:[e]),D=(e,a)=>null==e?void 0:e.add(a),N=e=>[e,e],G=()=>[J(),J()],z=/[^A-Za-z]+/,F=/[^A-Za-z0-9]+/,W=/^( *)\/\*\* *(.*?) *\*\/$/gm,M=(e,a,l)=>e.substring(a,l),Z=e=>e.toUpperCase(),_=e=>e.toLowerCase(),B=(e,a,l,t=1)=>{const o=`${a}${1==t?"":t}`;return y(e,o)?B(e,a,l,t+1):(x(e,o,l),o)},Q=e=>e.replace(W,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,a=l)=>e.join(a),H=e=>e.flat(1e3),K=(e,a=0)=>q(u(e.split(F),((e,l)=>(l>0||a?Z:_)(M(e,0,1))+M(e,1)))),X=e=>Z(q((e&&!z.test(e[0])?e:" "+e).split(F),"_")),Y=e=>`/** ${e}. */`,ee=()=>{const e=G(),a=J(),t=J(),o=J();return[(...e)=>q(H(e),"\n"),(a,l,...t)=>i(t,(t=>D(A(e[a],l,P),t))),(e,l,t)=>B(a,e,[l,t]),(e,a,l,o,n,s="")=>B(t,e,[a,l,o,n,s]),(e,a,l)=>B(o,e,R(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>E(o,e)===a?e:B(o,e,a),a=>[...$(j(e[a],((e,a)=>`import {${q($(L(e)),", ")}} from '${a}';`))),l],()=>j(a,(([e,a],t)=>[Y(a),`export type ${t} = ${e};`,l])),e=>j(t,(([a,t,o,n,s],r)=>{const d=e?[`${r}: ${s}(${a}): ${t} => ${o},`]:[`${r}${s}(${a}): ${t};`];return e||h(d,Y(n)),b(d,l),d})),()=>j(o,((e,a)=>(e=R(e)?e:[e],b(e,w(e)+";"),[`const ${a} = ${g(e)}`,e,l])))]},ae=Object,le=ae.keys,te=ae.freeze,oe=e=>T(e,ae)&&e.constructor==ae,ne=(e,a)=>u(ae.entries(e),(([e,l])=>a(l,e))),se=e=>oe(e)&&c(le(e)),re=e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))},de="the Store",$e="A function for",ie="export",ue="listener",Ie=" | undefined",ce=`Registers a ${ue} that will be called`,be="Represents",we=" => void",he="the end of the transaction",ge="the specified Row",Ce="a string serialization of",fe=(e=0,a=0)=>`the ${Ne[e]}content of${a?" "+de:""}`,Te=(e,a=0,l=0)=>`${Pe[e]} ${fe(a,1)}${l?" when set":""}`,Ve=(e,a=0)=>`${be} a Row when ${a?"s":"g"}etting ${fe()} the '${e}' Table`,ve=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,pe=(e,a)=>`Calls a function for each ${e} in ${a}`,Re=(e,a=de)=>`Gets whether ${e} exists in ${a}`,me=e=>"A function that takes "+e,ye=(e,a=0)=>`${$e} listening to changes to ${De[e]} in ${De[a]}`,Le=(e,a,t=0)=>`${ce} whenever ${e} in ${a} change`+(t?l:"s"),Se=e=>`the '${e}' Table`,ke=e=>`${ge} in ${Se(e)}`,Je=e=>`the '${e}' Cell`,Ee=e=>`the '${e}' Value`,Oe=(e,a=0)=>`${Pe[a]} ${fe()} ${Se(e)}`,je=(e,a=0)=>`${Pe[a]} ${fe()} ${ke(e)}`,xe=(e,a,l=0)=>`${Pe[l]} ${Je(a)} for ${ke(e)}`,Ae=(e,a=0)=>`${Pe[a]} ${Ee(e)}`,Pe=["Gets","Sets","Sets part of","Deletes",be,"Gets "+Ce,"Sets "+Ce,ce+" whenever"],De=[de,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],Ne=["","tabular ","keyed value "],Ge=["DoRollback","Id","IdOrNull","Ids","Json","Store"],ze=(e,a=l,t=l)=>`store.${e}(${a})${t?" as "+t:l}`,Fe=(e,a=l)=>`fluent(() => ${ze(e,a)})`,We=(e,a=l,t=l)=>`store.${e}(${a?a+", ":l}proxy(${ue})${t?", "+t:l})`,Me=(e,a,t)=>{if(se(e)&&se(a))return N(l);const[n,d,$,i,u,I,c,w,h,g]=ee(),C=`./${K(t)}.d`,f=K(t,1),T=K(f),v=[],R=J(),m=a=>ne(e,((e,t)=>a(t,A(R,t,(()=>{const e=K(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${be} the '${t}' Table`),$(e+"Row",`{${q(y(t,((e,a,t)=>`'${e}'${V(t)?"?":l}: ${a};`))," ")}}`,Ve(t)),$(e+"RowWhenSet",`{${q(y(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ve(t,1)),$(e+"CellId",q(y(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(y(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${we}`,me(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${we})${we}`,me(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),K(t,1),I(X(t),`'${t}'`)))),y=(a,l)=>ne(e[a],((e,a)=>l(a,e[s],e[r],I(X(a),`'${a}'`),K(a,1)))),S=e=>ne(a,((a,l)=>e(l,a[s],a[r],I(X(l),`'${l}'`),K(l,1))));if(d(1,C,f,`create${f} as create${f}Decl`),!se(e)){const e=$("Tables",`{${q(m(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Te(4,1)),a=$("TableId",q(m((e=>`'${e}'`))," | "),"A Table Id in "+de),t=$("TableCallback",`(...[tableId, rowCallback]: ${q(m(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${we}]`))," | ")})${we}`,me("a Table Id, and a Row iterator")),n=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(m(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,$e+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${T}: ${f}, getCellChange: ${n}${Ie})${we}`,ye(1)),c=$("TableIdsListener",`(${T}: ${f})${we}`,ye(2)),w=$("TableListener",`(${T}: ${f}, tableId: ${a}, getCellChange: ${n}${Ie})${we}`,ye(3)),h=$("RowIdsListener",`(${T}: ${f}, tableId: ${a})`+we,ye(4,3)),g=$("RowListener",`(${T}: ${f}, tableId: ${a}, rowId: Id, getCellChange: ${n}${Ie})${we}`,ye(5,3)),R=$("CellIdsListener",`(${T}: ${f}, tableId: ${a}, rowId: Id)`+we,ye(6,5)),S=$("CellListener",`(...[${T}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(H(m((e=>y(e,((a,l)=>`[${T}: ${f}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${Ie}, oldCell: ${l}${Ie}, getCellChange: ${n} | undefined]`)))))," | ")})${we}`,ye(7,5)),k=$("InvalidCellListener",`(${T}: ${f}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${we}`,ye(8));i("hasTables",l,o,ze("hasTables"),Re("any Table")),i("getTables",l,e,ze("getTables"),Te(0,1)),i("setTables","tables: "+e,f,Fe("setTables","tables"),Te(1,1)),i("delTables",l,f,Fe("delTables"),Te(3,1)),i("getTableIds",l,a+"[]",ze("getTableIds",l,a+"[]"),ve("Table",de)),i("forEachTable","tableCallback: "+t,"void",ze("forEachTable","tableCallback as any"),pe("Table",de));const E=J();m(((e,[a,t,n,s,r,$],u,I)=>{d(1,C,a,t,n,s,r,$),i(`has${u}Table`,l,o,ze("hasTable",I),Re(Se(e))),i(`get${u}Table`,l,a,ze("getTable",I,a),Oe(e)),i(`set${u}Table`,"table: "+a,f,Fe("setTable",I+", table"),Oe(e,1)),i(`del${u}Table`,l,f,Fe("delTable",I),Oe(e,3)),i(`get${u}RowIds`,l,"Ids",ze("getRowIds",I),ve("Row",Se(e))),i(`get${u}SortedRowIds`,`cellId?: ${s}, descending?: boolean, offset?: number, limit?: number`,"Ids",ze("getSortedRowIds",I+", cellId, descending, offset, limit"),ve("Row",Se(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",ze("forEachRow",I+", rowCallback as any"),pe("Row",Se(e))),i(`has${u}Row`,"rowId: Id",o,ze("hasRow",I+", rowId"),Re(ge,Se(e))),i(`get${u}Row`,"rowId: Id",t,ze("getRow",I+", rowId",t),je(e)),i(`set${u}Row`,"rowId: Id, row: "+n,f,Fe("setRow",I+", rowId, row"),je(e,1)),i(`add${u}Row`,"row: "+n,"Id"+Ie,ze("addRow",I+", row"),"Adds a new Row to "+Se(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+n,f,Fe("setPartialRow",I+", rowId, partialRow"),je(e,2)),i(`del${u}Row`,"rowId: Id",f,Fe("delRow",I+", rowId"),je(e,3)),i(`get${u}CellIds`,"rowId: Id",s+"[]",ze("getCellIds",I+", rowId",s+"[]"),ve("Cell",ke(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+r,"void",ze("forEachCell",I+", rowId, cellCallback as any"),pe("Cell",ke(e))),y(e,((a,t,n,s,r)=>{const d="Map"+K(t,1);x(E,t,d),i(`has${u}${r}Cell`,"rowId: Id",o,ze("hasCell",`${I}, rowId, ${s}`),Re(Je(a),ke(e)));const $=`${t}${V(n)?Ie:l}`;i(`get${u}${r}Cell`,"rowId: Id",$,ze("getCell",`${I}, rowId, ${s}`,$),xe(e,a)),i(`set${u}${r}Cell`,`rowId: Id, cell: ${t} | ${d}`,f,Fe("setCell",`${I}, rowId, ${s}, cell as any`),xe(e,a,1)),i(`del${u}${r}Cell`,"rowId: Id",f,Fe("delCell",`${I}, rowId, ${s}`),xe(e,a,3))}))})),i("getTablesJson",l,"Json",ze("getTablesJson"),Te(5,1)),i("setTablesJson","tablesJson: Json",f,Fe("setTablesJson","tablesJson"),Te(6,1)),i("addTablesListener",`${ue}: ${u}, mutator?: boolean`,"Id",We("addTablesListener",l,"mutator"),Te(7,1)+" changes"),i("addTableIdsListener",`${ue}: ${c}, mutator?: boolean`,"Id",We("addTableIdsListener",l,"mutator"),Le("the Table Ids",de,1)),i("addTableListener",`tableId: ${a} | null, ${ue}: ${w}, mutator?: boolean`,"Id",We("addTableListener","tableId","mutator"),Le("a Table",de)),i("addRowIdsListener",`tableId: ${a} | null, ${ue}: ${h}, mutator?: boolean`,"Id",We("addRowIdsListener","tableId","mutator"),Le("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${a} | null, rowId: IdOrNull, ${ue}: ${g}, mutator?: boolean`,"Id",We("addRowListener","tableId, rowId","mutator"),Le("a Row","a Table")),i("addCellIdsListener",`tableId: ${a} | null, rowId: IdOrNull, ${ue}: ${R}, mutator?: boolean`,"Id",We("addCellIdsListener","tableId, rowId","mutator"),Le("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${a} | null, rowId: IdOrNull, cellId: ${q(m(((e,a)=>a[3]))," | ")} | null, ${ue}: ${S}, mutator?: boolean`,"Id",We("addCellListener","tableId, rowId, cellId","mutator"),Le("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${ue}: ${k}, mutator?: boolean`,"Id",We("addInvalidCellListener","tableId, rowId, cellId","mutator"),ce+" whenever an invalid Cell change was attempted"),O(E,((e,a)=>$(a,`(cell: ${e}${Ie}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(1,C,e,a,t,u,c,w,h,g,R,S,k,...L(E)),d(0,"tinybase","CellChange"),b(v,".setTablesSchema({",H(m(((e,a,t,o)=>[`[${o}]: {`,...y(e,((e,a,t,o)=>`[${o}]: {[${I(X(s),`'${s}'`)}]: ${I(X(a),`'${a}'`)}${V(t)?l:`, [${I(X(r),`'${r}'`)}]: ${p(t)?I(X(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!se(a)){const e=$("Values",`{${q(S(((e,a,t)=>`'${e}'${V(t)?"?":l}: ${a};`))," ")}}`,Te(4,2)),a=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Te(4,2,1)),t=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+de),n=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${we}`,me("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${t}) => ValueChange`,$e+" returning information about any Value's changes during a transaction"),c=$("ValuesListener",`(${T}: ${f}, getValueChange: ${u}${Ie})`+we,ye(9)),w=$("ValueIdsListener",`(${T}: ${f})${we}`,ye(10)),h=$("ValueListener",`(...[${T}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${T}: ${f}, valueId: '${e}', newValue: ${a}${Ie}, oldValue: ${a}${Ie}, getValueChange: ${u} | undefined]`))," | ")})${we}`,ye(11)),g=$("InvalidValueListener",`(${T}: ${f}, valueId: Id, invalidValues: any[])${we}`,ye(12));i("hasValues",l,o,ze("hasValues"),Re("any Value")),i("getValues",l,e,ze("getValues"),Te(0,2)),i("setValues","values: "+a,f,Fe("setValues","values"),Te(1,2)),i("setPartialValues","partialValues: "+a,f,Fe("setPartialValues","partialValues"),Te(2,2)),i("delValues",l,f,Fe("delValues"),Te(3,2)),i("getValueIds",l,t+"[]",ze("getValueIds",l,t+"[]"),ve("Value",de)),i("forEachValue","valueCallback: "+n,"void",ze("forEachValue","valueCallback as any"),pe("Value",de)),S(((e,a,t,n,s)=>{i(`has${s}Value`,l,o,ze("hasValue",n),Re(Ee(e))),i(`get${s}Value`,l,a,ze("getValue",n,a),Ae(e)),i(`set${s}Value`,"value: "+a,f,Fe("setValue",n+", value"),Ae(e,1)),i(`del${s}Value`,l,f,Fe("delValue",n),Ae(e,3))})),i("getValuesJson",l,"Json",ze("getValuesJson"),Te(5,2)),i("setValuesJson","valuesJson: Json",f,Fe("setValuesJson","valuesJson"),Te(6,2)),i("addValuesListener",`${ue}: ${c}, mutator?: boolean`,"Id",We("addValuesListener",l,"mutator"),Te(7,2)+" changes"),i("addValueIdsListener",`${ue}: ${w}, mutator?: boolean`,"Id",We("addValueIdsListener",l,"mutator"),Le("the Value Ids",de,1)),i("addValueListener",`valueId: ${t} | null, ${ue}: ${h}, mutator?: boolean`,"Id",We("addValueListener","valueId","mutator"),Le("a Value",de)),i("addInvalidValueListener",`valueId: IdOrNull, ${ue}: ${g}, mutator?: boolean`,"Id",We("addInvalidValueListener","valueId","mutator"),ce+" whenever an invalid Cell change was attempted"),d(1,C,e,t,n,c,w,h,g),d(0,"tinybase","ValueChange"),b(v,".setValuesSchema({",S(((e,a,t,o)=>[`[${o}]: {[${I(X(s),`'${s}'`)}]: ${I(X(a),`'${a}'`)}${V(t)?l:`, [${I(X(r),`'${r}'`)}]: ${p(t)?I(X(t),`'${t}'`):t}`}},`])),"})")}d(0,"tinybase",...Ge);const k=$("TransactionListener",`(${T}: ${f}, cellsTouched: boolean, valuesTouched: boolean)${we}`,$e+" listening to the completion of a transaction");return i("getJson",l,"Json",ze("getJson"),Te(5)),i("setJson","json: Json",f,Fe("setJson","json"),Te(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",ze("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",l,f,Fe("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",f,Fe("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${ue}: ${k}`,"Id",We("addWillFinishTransactionListener"),`${ce} just before ${he}`),i("addDidFinishTransactionListener",`${ue}: ${k}`,"Id",We("addDidFinishTransactionListener"),`${ce} just after ${he}`),i("callListener",ue+"Id: Id",f,Fe("callListener",ue+"Id"),`Manually provoke a ${ue} to be called`),i("delListener",ue+"Id: Id",f,Fe("delListener",ue+"Id"),`Remove a ${ue} that was previously added to ${de}`),i("getStore",l,"Store","store",Pe[0]+" the underlying Store object"),d(1,"tinybase","createStore",...Ge),d(1,C,f,`create${f} as create${f}Decl`,k),I("store",["createStore()",...v]),u("fluent","actions: () => Store",["actions();",`return ${T};`]),u("proxy",ue+": any",`(_: Store, ...args: any[]) => ${ue}(${T}, ...args)`),I(T,["{",...h(1),"}"]),[n(...c(0),...w(),`${ie} interface ${f} {`,...h(0),"}",l,Y(`Creates a ${f} object`),`${ie} function create${f}(): ${f};`),n(...c(1),`${ie} const create${f}: typeof create${f}Decl = () => {`,...g(),`return Object.freeze(${T});`,"};")]};var Ze=Object.defineProperty,_e=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Ue=(e,a,l)=>a in e?Ze(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,qe=(e,a)=>{for(var l in a||(a={}))Be.call(a,l)&&Ue(e,l,a[l]);if(_e)for(var l of _e(a))Qe.call(a,l)&&Ue(e,l,a[l]);return e},He=(e,a,l)=>new Promise(((t,o)=>{var n=e=>{try{r(l.next(e))}catch(e){o(e)}},s=e=>{try{r(l.throw(e))}catch(e){o(e)}},r=e=>e.done?t(e.value):Promise.resolve(e.value).then(n,s);r((l=l.apply(e,a)).next())}));const Ke={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Xe=re((e=>{const a=()=>{const a=C(e.getTablesSchemaJson());return!se(a)||d(e.getTableIds(),(l=>{const t=e.getRowIds(l),o=J();if(d(t,(a=>d(e.getCellIds(l,a),(t=>{const n=e.getCell(l,a,t),s=A(o,t,(()=>[m(n),J(),[0],0])),[r,d,[$]]=s,i=A(d,n,(()=>0))+1;return i>$&&(s[2]=[i,n]),x(d,n,i),s[3]++,r==m(n)})))))return a[l]={},S(o,(([e,,[,o],n],d)=>{a[l][d]=qe({[s]:e},n==I(t)?{[r]:o}:{})})),1}))?a:{}},l=()=>{const a=C(e.getValuesSchemaJson());return se(a)&&e.forEachValue(((e,l)=>{a[e]={[s]:m(l)}})),a},t=e=>Me(a(),l(),e),o=e=>He(void 0,null,(function*(){let a;try{a=(yield import("prettier")).format}catch(e){a=e=>e}return u(t(e),(e=>Q(a(e,Ke))))}));return te({getStoreStats:a=>{let l=0,t=0,o=0;const n={};return e.forEachTable(((e,s)=>{l++;let r=0,d=0;const $={};s(((e,l)=>{r++;let t=0;l((()=>t++)),d+=t,a&&($[e]={rowCells:t})})),t+=r,o+=d,a&&(n[e]={tableRows:r,tableCells:d,rows:$})})),qe({totalTables:l,totalRows:t,totalCells:o,totalValues:I(e.getValueIds()),jsonLength:U(e.getJson())},a?{detail:{tables:n}}:{})},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:o,getStore:()=>e})}));e.createTools=Xe},"object"==typeof exports&&"undefined"!=typeof module?a(exports):"function"==typeof define&&define.amd?define(["exports"],a):a((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
1
+ var e,a;e=this,a=function(e){"use strict";const a=e=>typeof e,l="",t=a(l),o=a(!0),n=a(0),s="type",r="default",d=(e,a)=>e.every(a),$=(e,a)=>e.sort(a),i=(e,a)=>e.forEach(a),u=(e,a)=>e.map(a),I=e=>e.length,c=e=>0==I(e),b=(e,...a)=>e.push(...a),w=e=>e.pop(),h=(e,...a)=>e.unshift(...a),g=e=>e.shift(),C=JSON.parse,f=isFinite,T=(e,a)=>e instanceof a,V=e=>null==e,v=e=>e==t||e==o,p=e=>a(e)==t,R=e=>Array.isArray(e),m=e=>{const l=a(e);return v(l)||l==n&&f(e)?l:void 0},y=(e,a)=>{var l;return null!=(l=null==e?void 0:e.has(a))&&l},L=e=>{var a;return[...null!=(a=null==e?void 0:e.values())?a:[]]},S=(e,a)=>null==e?void 0:e.forEach(a),k=(e,a)=>null==e?void 0:e.delete(a),J=e=>new Map(e),E=(e,a)=>null==e?void 0:e.get(a),O=(e,a)=>S(e,((e,l)=>a(l,e))),j=(e,a)=>{var l;return u([...null!=(l=null==e?void 0:e.entries())?l:[]],(([e,l])=>a(l,e)))},x=(e,a,l)=>V(l)?(k(e,a),e):null==e?void 0:e.set(a,l),A=(e,a,l)=>(y(e,a)||x(e,a,l()),E(e,a)),P=e=>new Set(R(e)||V(e)?e:[e]),D=(e,a)=>null==e?void 0:e.add(a),N=e=>[e,e],G=()=>[J(),J()],z=/[^A-Za-z]+/,F=/[^A-Za-z0-9]+/,W=/^( *)\/\*\* *(.*?) *\*\/$/gm,M=(e,a,l)=>e.substring(a,l),Z=e=>e.toUpperCase(),_=e=>e.toLowerCase(),B=(e,a,l,t=1)=>{const o=`${a}${1==t?"":t}`;return y(e,o)?B(e,a,l,t+1):(x(e,o,l),o)},Q=e=>e.replace(W,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,a=l)=>e.join(a),H=e=>e.flat(1e3),K=(e,a=0)=>q(u(e.split(F),((e,l)=>(l>0||a?Z:_)(M(e,0,1))+M(e,1)))),X=e=>Z(q((e&&!z.test(e[0])?e:" "+e).split(F),"_")),Y=e=>`/** ${e}. */`,ee=()=>{const e=G(),a=J(),t=J(),o=J();return[(...e)=>q(H(e),"\n"),(a,l,...t)=>i(t,(t=>D(A(e[a],l,P),t))),(e,l,t)=>B(a,e,[l,t]),(e,a,l,o,n,s="")=>B(t,e,[a,l,o,n,s]),(e,a,l)=>B(o,e,R(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>E(o,e)===a?e:B(o,e,a),a=>[...$(j(e[a],((e,a)=>`import {${q($(L(e)),", ")}} from '${a}';`))),l],()=>j(a,(([e,a],t)=>[Y(a),`export type ${t} = ${e};`,l])),e=>j(t,(([a,t,o,n,s],r)=>{const d=e?[`${r}: ${s}(${a}): ${t} => ${o},`]:[`${r}${s}(${a}): ${t};`];return e||h(d,Y(n)),b(d,l),d})),()=>j(o,((e,a)=>(e=R(e)?e:[e],b(e,w(e)+";"),[`const ${a} = ${g(e)}`,e,l])))]},ae=Object,le=ae.keys,te=ae.freeze,oe=e=>T(e,ae)&&e.constructor==ae,ne=(e,a)=>u(ae.entries(e),(([e,l])=>a(l,e))),se=e=>oe(e)&&c(le(e)),re=e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))},de="the Store",$e="A function for",ie="export",ue="listener",Ie=" | undefined",ce=`Registers a ${ue} that will be called`,be="Represents",we=" => void",he="the end of the transaction",ge="the specified Row",Ce="a string serialization of",fe=(e=0,a=0)=>`the ${Ne[e]}content of${a?" "+de:""}`,Te=(e,a=0,l=0)=>`${Pe[e]} ${fe(a,1)}${l?" when set":""}`,Ve=(e,a=0)=>`${be} a Row when ${a?"s":"g"}etting ${fe()} the '${e}' Table`,ve=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,pe=(e,a)=>`Calls a function for each ${e} in ${a}`,Re=(e,a=de)=>`Gets whether ${e} exists in ${a}`,me=e=>"A function that takes "+e,ye=(e,a=0)=>`${$e} listening to changes to ${De[e]} in ${De[a]}`,Le=(e,a,t=0)=>`${ce} whenever ${e} in ${a} change`+(t?l:"s"),Se=e=>`the '${e}' Table`,ke=e=>`${ge} in ${Se(e)}`,Je=e=>`the '${e}' Cell`,Ee=e=>`the '${e}' Value`,Oe=(e,a=0)=>`${Pe[a]} ${fe()} ${Se(e)}`,je=(e,a=0)=>`${Pe[a]} ${fe()} ${ke(e)}`,xe=(e,a,l=0)=>`${Pe[l]} ${Je(a)} for ${ke(e)}`,Ae=(e,a=0)=>`${Pe[a]} ${Ee(e)}`,Pe=["Gets","Sets","Sets part of","Deletes",be,"Gets "+Ce,"Sets "+Ce,ce+" whenever"],De=[de,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],Ne=["","tabular ","keyed value "],Ge=["DoRollback","Id","IdOrNull","Ids","Json","Store"],ze=(e,a=l,t=l)=>`store.${e}(${a})${t?" as "+t:l}`,Fe=(e,a=l)=>`fluent(() => ${ze(e,a)})`,We=(e,a=l,t=l)=>`store.${e}(${a?a+", ":l}proxy(${ue})${t?", "+t:l})`,Me=(e,a,t)=>{if(se(e)&&se(a))return N(l);const[n,d,$,i,u,I,c,w,h,g]=ee(),C=`./${K(t)}.d`,f=K(t,1),T=K(f),v=[],R=J(),m=a=>ne(e,((e,t)=>a(t,A(R,t,(()=>{const e=K(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${be} the '${t}' Table`),$(e+"Row",`{${q(y(t,((e,a,t)=>`'${e}'${V(t)?"?":l}: ${a};`))," ")}}`,Ve(t)),$(e+"RowWhenSet",`{${q(y(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ve(t,1)),$(e+"CellId",q(y(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(y(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${we}`,me(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${we})${we}`,me(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),K(t,1),I(X(t),`'${t}'`)))),y=(a,l)=>ne(e[a],((e,a)=>l(a,e[s],e[r],I(X(a),`'${a}'`),K(a,1)))),S=e=>ne(a,((a,l)=>e(l,a[s],a[r],I(X(l),`'${l}'`),K(l,1))));if(d(1,C,f,`create${f} as create${f}Decl`),!se(e)){const e=$("Tables",`{${q(m(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Te(4,1)),a=$("TableId",q(m((e=>`'${e}'`))," | "),"A Table Id in "+de),t=$("TableCallback",`(...[tableId, rowCallback]: ${q(m(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${we}]`))," | ")})${we}`,me("a Table Id, and a Row iterator")),n=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(m(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,$e+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${T}: ${f}, getCellChange: ${n}${Ie})${we}`,ye(1)),c=$("TableIdsListener",`(${T}: ${f})${we}`,ye(2)),w=$("TableListener",`(${T}: ${f}, tableId: ${a}, getCellChange: ${n}${Ie})${we}`,ye(3)),h=$("RowIdsListener",`(${T}: ${f}, tableId: ${a})`+we,ye(4,3)),g=$("RowListener",`(${T}: ${f}, tableId: ${a}, rowId: Id, getCellChange: ${n}${Ie})${we}`,ye(5,3)),R=$("CellIdsListener",`(${T}: ${f}, tableId: ${a}, rowId: Id)`+we,ye(6,5)),S=$("CellListener",`(...[${T}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(H(m((e=>y(e,((a,l)=>`[${T}: ${f}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${Ie}, oldCell: ${l}${Ie}, getCellChange: ${n} | undefined]`)))))," | ")})${we}`,ye(7,5)),k=$("InvalidCellListener",`(${T}: ${f}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${we}`,ye(8));i("hasTables",l,o,ze("hasTables"),Re("any Table")),i("getTables",l,e,ze("getTables"),Te(0,1)),i("setTables","tables: "+e,f,Fe("setTables","tables"),Te(1,1)),i("delTables",l,f,Fe("delTables"),Te(3,1)),i("getTableIds",l,a+"[]",ze("getTableIds",l,a+"[]"),ve("Table",de)),i("forEachTable","tableCallback: "+t,"void",ze("forEachTable","tableCallback as any"),pe("Table",de));const E=J();m(((e,[a,t,n,s,r,$],u,I)=>{d(1,C,a,t,n,s,r,$),i(`has${u}Table`,l,o,ze("hasTable",I),Re(Se(e))),i(`get${u}Table`,l,a,ze("getTable",I,a),Oe(e)),i(`set${u}Table`,"table: "+a,f,Fe("setTable",I+", table"),Oe(e,1)),i(`del${u}Table`,l,f,Fe("delTable",I),Oe(e,3)),i(`get${u}RowIds`,l,"Ids",ze("getRowIds",I),ve("Row",Se(e))),i(`get${u}SortedRowIds`,`cellId?: ${s}, descending?: boolean, offset?: number, limit?: number`,"Ids",ze("getSortedRowIds",I+", cellId, descending, offset, limit"),ve("Row",Se(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",ze("forEachRow",I+", rowCallback as any"),pe("Row",Se(e))),i(`has${u}Row`,"rowId: Id",o,ze("hasRow",I+", rowId"),Re(ge,Se(e))),i(`get${u}Row`,"rowId: Id",t,ze("getRow",I+", rowId",t),je(e)),i(`set${u}Row`,"rowId: Id, row: "+n,f,Fe("setRow",I+", rowId, row"),je(e,1)),i(`add${u}Row`,"row: "+n,"Id"+Ie,ze("addRow",I+", row"),"Adds a new Row to "+Se(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+n,f,Fe("setPartialRow",I+", rowId, partialRow"),je(e,2)),i(`del${u}Row`,"rowId: Id",f,Fe("delRow",I+", rowId"),je(e,3)),i(`get${u}CellIds`,"rowId: Id",s+"[]",ze("getCellIds",I+", rowId",s+"[]"),ve("Cell",ke(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+r,"void",ze("forEachCell",I+", rowId, cellCallback as any"),pe("Cell",ke(e))),y(e,((a,t,n,s,r)=>{const d="Map"+K(t,1);x(E,t,d),i(`has${u}${r}Cell`,"rowId: Id",o,ze("hasCell",`${I}, rowId, ${s}`),Re(Je(a),ke(e)));const $=`${t}${V(n)?Ie:l}`;i(`get${u}${r}Cell`,"rowId: Id",$,ze("getCell",`${I}, rowId, ${s}`,$),xe(e,a)),i(`set${u}${r}Cell`,`rowId: Id, cell: ${t} | ${d}`,f,Fe("setCell",`${I}, rowId, ${s}, cell as any`),xe(e,a,1)),i(`del${u}${r}Cell`,"rowId: Id",f,Fe("delCell",`${I}, rowId, ${s}`),xe(e,a,3))}))})),i("getTablesJson",l,"Json",ze("getTablesJson"),Te(5,1)),i("setTablesJson","tablesJson: Json",f,Fe("setTablesJson","tablesJson"),Te(6,1)),i("addTablesListener",`${ue}: ${u}, mutator?: boolean`,"Id",We("addTablesListener",l,"mutator"),Te(7,1)+" changes"),i("addTableIdsListener",`${ue}: ${c}, mutator?: boolean`,"Id",We("addTableIdsListener",l,"mutator"),Le("the Table Ids",de,1)),i("addTableListener",`tableId: ${a} | null, ${ue}: ${w}, mutator?: boolean`,"Id",We("addTableListener","tableId","mutator"),Le("a Table",de)),i("addRowIdsListener",`tableId: ${a} | null, ${ue}: ${h}, mutator?: boolean`,"Id",We("addRowIdsListener","tableId","mutator"),Le("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${a} | null, rowId: IdOrNull, ${ue}: ${g}, mutator?: boolean`,"Id",We("addRowListener","tableId, rowId","mutator"),Le("a Row","a Table")),i("addCellIdsListener",`tableId: ${a} | null, rowId: IdOrNull, ${ue}: ${R}, mutator?: boolean`,"Id",We("addCellIdsListener","tableId, rowId","mutator"),Le("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${a} | null, rowId: IdOrNull, cellId: ${q(m(((e,a)=>a[3]))," | ")} | null, ${ue}: ${S}, mutator?: boolean`,"Id",We("addCellListener","tableId, rowId, cellId","mutator"),Le("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${ue}: ${k}, mutator?: boolean`,"Id",We("addInvalidCellListener","tableId, rowId, cellId","mutator"),ce+" whenever an invalid Cell change was attempted"),O(E,((e,a)=>$(a,`(cell: ${e}${Ie}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(1,C,e,a,t,u,c,w,h,g,R,S,k,...L(E)),d(0,"tinybase","CellChange"),b(v,".setTablesSchema({",H(m(((e,a,t,o)=>[`[${o}]: {`,...y(e,((e,a,t,o)=>`[${o}]: {[${I(X(s),`'${s}'`)}]: ${I(X(a),`'${a}'`)}${V(t)?l:`, [${I(X(r),`'${r}'`)}]: ${p(t)?I(X(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!se(a)){const e=$("Values",`{${q(S(((e,a,t)=>`'${e}'${V(t)?"?":l}: ${a};`))," ")}}`,Te(4,2)),a=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Te(4,2,1)),t=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+de),n=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${we}`,me("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${t}) => ValueChange`,$e+" returning information about any Value's changes during a transaction"),c=$("ValuesListener",`(${T}: ${f}, getValueChange: ${u}${Ie})`+we,ye(9)),w=$("ValueIdsListener",`(${T}: ${f})${we}`,ye(10)),h=$("ValueListener",`(...[${T}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${T}: ${f}, valueId: '${e}', newValue: ${a}${Ie}, oldValue: ${a}${Ie}, getValueChange: ${u} | undefined]`))," | ")})${we}`,ye(11)),g=$("InvalidValueListener",`(${T}: ${f}, valueId: Id, invalidValues: any[])${we}`,ye(12));i("hasValues",l,o,ze("hasValues"),Re("any Value")),i("getValues",l,e,ze("getValues",l,e),Te(0,2)),i("setValues","values: "+a,f,Fe("setValues","values"),Te(1,2)),i("setPartialValues","partialValues: "+a,f,Fe("setPartialValues","partialValues"),Te(2,2)),i("delValues",l,f,Fe("delValues"),Te(3,2)),i("getValueIds",l,t+"[]",ze("getValueIds",l,t+"[]"),ve("Value",de)),i("forEachValue","valueCallback: "+n,"void",ze("forEachValue","valueCallback as any"),pe("Value",de)),S(((e,a,t,n,s)=>{i(`has${s}Value`,l,o,ze("hasValue",n),Re(Ee(e))),i(`get${s}Value`,l,a,ze("getValue",n,a),Ae(e)),i(`set${s}Value`,"value: "+a,f,Fe("setValue",n+", value"),Ae(e,1)),i(`del${s}Value`,l,f,Fe("delValue",n),Ae(e,3))})),i("getValuesJson",l,"Json",ze("getValuesJson"),Te(5,2)),i("setValuesJson","valuesJson: Json",f,Fe("setValuesJson","valuesJson"),Te(6,2)),i("addValuesListener",`${ue}: ${c}, mutator?: boolean`,"Id",We("addValuesListener",l,"mutator"),Te(7,2)+" changes"),i("addValueIdsListener",`${ue}: ${w}, mutator?: boolean`,"Id",We("addValueIdsListener",l,"mutator"),Le("the Value Ids",de,1)),i("addValueListener",`valueId: ${t} | null, ${ue}: ${h}, mutator?: boolean`,"Id",We("addValueListener","valueId","mutator"),Le("a Value",de)),i("addInvalidValueListener",`valueId: IdOrNull, ${ue}: ${g}, mutator?: boolean`,"Id",We("addInvalidValueListener","valueId","mutator"),ce+" whenever an invalid Cell change was attempted"),d(1,C,e,a,t,n,c,w,h,g),d(0,"tinybase","ValueChange"),b(v,".setValuesSchema({",S(((e,a,t,o)=>[`[${o}]: {[${I(X(s),`'${s}'`)}]: ${I(X(a),`'${a}'`)}${V(t)?l:`, [${I(X(r),`'${r}'`)}]: ${p(t)?I(X(t),`'${t}'`):t}`}},`])),"})")}d(0,"tinybase",...Ge);const k=$("TransactionListener",`(${T}: ${f}, cellsTouched: boolean, valuesTouched: boolean)${we}`,$e+" listening to the completion of a transaction");return i("getJson",l,"Json",ze("getJson"),Te(5)),i("setJson","json: Json",f,Fe("setJson","json"),Te(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",ze("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",l,f,Fe("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",f,Fe("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${ue}: ${k}`,"Id",We("addWillFinishTransactionListener"),`${ce} just before ${he}`),i("addDidFinishTransactionListener",`${ue}: ${k}`,"Id",We("addDidFinishTransactionListener"),`${ce} just after ${he}`),i("callListener",ue+"Id: Id",f,Fe("callListener",ue+"Id"),`Manually provoke a ${ue} to be called`),i("delListener",ue+"Id: Id",f,Fe("delListener",ue+"Id"),`Remove a ${ue} that was previously added to ${de}`),i("getStore",l,"Store","store",Pe[0]+" the underlying Store object"),d(1,"tinybase","createStore",...Ge),d(1,C,f,`create${f} as create${f}Decl`,k),I("store",["createStore()",...v]),u("fluent","actions: () => Store",["actions();",`return ${T};`]),u("proxy",ue+": any",`(_: Store, ...args: any[]) => ${ue}(${T}, ...args)`),I(T,["{",...h(1),"}"]),[n(...c(0),...w(),`${ie} interface ${f} {`,...h(0),"}",l,Y(`Creates a ${f} object`),`${ie} function create${f}(): ${f};`),n(...c(1),`${ie} const create${f}: typeof create${f}Decl = () => {`,...g(),`return Object.freeze(${T});`,"};")]};var Ze=Object.defineProperty,_e=Object.getOwnPropertySymbols,Be=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Ue=(e,a,l)=>a in e?Ze(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,qe=(e,a)=>{for(var l in a||(a={}))Be.call(a,l)&&Ue(e,l,a[l]);if(_e)for(var l of _e(a))Qe.call(a,l)&&Ue(e,l,a[l]);return e},He=(e,a,l)=>new Promise(((t,o)=>{var n=e=>{try{r(l.next(e))}catch(e){o(e)}},s=e=>{try{r(l.throw(e))}catch(e){o(e)}},r=e=>e.done?t(e.value):Promise.resolve(e.value).then(n,s);r((l=l.apply(e,a)).next())}));const Ke={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Xe=re((e=>{const a=()=>{const a=C(e.getTablesSchemaJson());return!se(a)||d(e.getTableIds(),(l=>{const t=e.getRowIds(l),o=J();if(d(t,(a=>d(e.getCellIds(l,a),(t=>{const n=e.getCell(l,a,t),s=A(o,t,(()=>[m(n),J(),[0],0])),[r,d,[$]]=s,i=A(d,n,(()=>0))+1;return i>$&&(s[2]=[i,n]),x(d,n,i),s[3]++,r==m(n)})))))return a[l]={},S(o,(([e,,[,o],n],d)=>{a[l][d]=qe({[s]:e},n==I(t)?{[r]:o}:{})})),1}))?a:{}},l=()=>{const a=C(e.getValuesSchemaJson());return se(a)&&e.forEachValue(((e,l)=>{a[e]={[s]:m(l)}})),a},t=e=>Me(a(),l(),e),o=e=>He(void 0,null,(function*(){let a;try{a=(yield import("prettier")).format}catch(e){a=e=>e}return u(t(e),(e=>Q(a(e,Ke))))}));return te({getStoreStats:a=>{let l=0,t=0,o=0;const n={};return e.forEachTable(((e,s)=>{l++;let r=0,d=0;const $={};s(((e,l)=>{r++;let t=0;l((()=>t++)),d+=t,a&&($[e]={rowCells:t})})),t+=r,o+=d,a&&(n[e]={tableRows:r,tableCells:d,rows:$})})),qe({totalTables:l,totalRows:t,totalCells:o,totalValues:I(e.getValueIds()),jsonLength:U(e.getJson())},a?{detail:{tables:n}}:{})},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:o,getStore:()=>e})}));e.createTools=Xe},"object"==typeof exports&&"undefined"!=typeof module?a(exports):"function"==typeof define&&define.amd?define(["exports"],a):a((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinybase",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "author": "jamesgpearce",
5
5
  "repository": "github:tinyplex/tinybase",
6
6
  "license": "MIT",
@@ -21,6 +21,14 @@
21
21
  "exports": {
22
22
  ".": "./lib/tinybase.js",
23
23
  "./package.json": "./package.json",
24
+ "./es6": "./lib/es6/tinybase.js",
25
+ "./debug": "./lib/debug/tinybase.js",
26
+ "./cjs": "./lib/cjs/tinybase.cjs",
27
+ "./cjs-es6": "./lib/cjs-es6/tinybase.cjs",
28
+ "./umd": "./lib/umd/tinybase.js",
29
+ "./umd-es6": "./lib/umd-es6/tinybase.js",
30
+ "./cjs/*": "./lib/cjs/*.cjs",
31
+ "./cjs-es6/*": "./lib/cjs-es6/*.cjs",
24
32
  "./*": "./lib/*.js"
25
33
  },
26
34
  "bin": {
@@ -71,55 +79,55 @@
71
79
  "@rollup/plugin-replace": "^5.0.2",
72
80
  "@rollup/plugin-terser": "^0.4.0",
73
81
  "@types/asciichart": "^1.5.6",
74
- "@types/expect-puppeteer": "^5.0.2",
82
+ "@types/expect-puppeteer": "^5.0.3",
75
83
  "@types/http-server": "^0.12.1",
76
84
  "@types/jest": "^29.4.0",
77
85
  "@types/jest-environment-puppeteer": "^5.0.3",
78
86
  "@types/less": "^3.0.3",
79
- "@types/node": "^18.11.18",
87
+ "@types/node": "^18.13.0",
80
88
  "@types/puppeteer": "^5.4.7",
81
- "@types/react": "^18.0.27",
82
- "@types/react-dom": "^18.0.10",
89
+ "@types/react": "^18.0.28",
90
+ "@types/react-dom": "^18.0.11",
83
91
  "@types/react-test-renderer": "^18.0.0",
84
92
  "@types/tmp": "^0.2.3",
85
- "@typescript-eslint/eslint-plugin": "^5.49.0",
86
- "@typescript-eslint/parser": "^5.49.0",
93
+ "@typescript-eslint/eslint-plugin": "^5.52.0",
94
+ "@typescript-eslint/parser": "^5.52.0",
87
95
  "asciichart": "^1.5.25",
88
96
  "babel-eslint": "^10.1.0",
89
- "babel-jest": "^29.4.1",
97
+ "babel-jest": "^29.4.3",
90
98
  "babel-preset-minify": "^0.5.2",
91
99
  "buffer-replace": "^1.0.0",
92
100
  "country-flag-emoji-json": "^2.0.0",
93
- "cspell": "^6.19.2",
94
- "esbuild": "^0.17.5",
95
- "eslint": "^8.33.0",
101
+ "cspell": "^6.26.3",
102
+ "esbuild": "^0.17.8",
103
+ "eslint": "^8.34.0",
96
104
  "eslint-config-prettier": "^8.6.0",
97
105
  "eslint-plugin-jest": "^27.2.1",
98
- "eslint-plugin-jsdoc": "^39.7.4",
106
+ "eslint-plugin-jsdoc": "^40.0.0",
99
107
  "eslint-plugin-react": "^7.32.2",
100
108
  "eslint-plugin-react-hooks": "^4.6.0",
101
109
  "gulp": "^4.0.2",
102
110
  "gulp-gzip": "^1.4.2",
103
111
  "http-server": "^14.1.1",
104
- "jest": "^29.4.1",
105
- "jest-environment-jsdom": "^29.4.1",
112
+ "jest": "^29.4.3",
113
+ "jest-environment-jsdom": "^29.4.3",
106
114
  "jest-fetch-mock": "^3.0.3",
107
- "jest-puppeteer": "^6.2.0",
115
+ "jest-puppeteer": "^7.0.1",
108
116
  "less": "^4.1.3",
109
- "prettier": "^2.8.3",
110
- "puppeteer": "^17.1.3",
117
+ "prettier": "^2.8.4",
118
+ "puppeteer": "^19.7.1",
111
119
  "react": "^18.2.0",
112
120
  "react-dom": "^18.2.0",
113
121
  "react-test-renderer": "^18.2.0",
114
- "rollup": "^3.12.0",
122
+ "rollup": "^3.15.0",
115
123
  "rollup-plugin-esbuild": "^5.0.0",
116
124
  "rollup-plugin-gzip": "^3.1.0",
117
125
  "rollup-plugin-preserve-shebang": "^1.0.1",
118
126
  "rollup-plugin-prettier": "^3.0.0",
119
127
  "tinydocs": "^0.1.23",
120
128
  "tmp": "^0.2.1",
121
- "ts-unused-exports": "^9.0.2",
122
- "typescript": "4.9.4"
129
+ "ts-unused-exports": "^9.0.4",
130
+ "typescript": "4.9.5"
123
131
  },
124
132
  "peerDependencies": {
125
133
  "prettier": "^2.0.0",
package/readme.md CHANGED
@@ -266,4 +266,4 @@ export const createShop: typeof createShopDecl = () => {
266
266
  };
267
267
  ```
268
268
 
269
- <section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://tinybase.org/api/store/"><code>store</code></a> module alone, you&#x27;ll only add a gzipped <em>4.2kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>8.7kB</em>.</p><p>The <a href="https://tinybase.org/api/ui-react/"><code>ui-react</code></a> module is just another <em>3.4kB</em>, the <a href="https://tinybase.org/api/tools/"><code>tools</code></a> module is <em>5.4kB</em>, and everything is fast. Life&#x27;s easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured in the <a href="https://tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>.js.gz</th><th>.js</th><th>debug.js</th><th>.d.ts</th></tr><tr><th class="right"><a href="https://tinybase.org/api/store/">store</a></th><td>4.2kB</td><td>10.0kB</td><td>43.9kB</td><td>184.6kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/metrics/">metrics</a></th><td>1.8kB</td><td>3.6kB</td><td>14.8kB</td><td>29.1kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/indexes/">indexes</a></th><td>1.9kB</td><td>3.7kB</td><td>16.6kB</td><td>33.9kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/relationships/">relationships</a></th><td>1.8kB</td><td>3.6kB</td><td>16.8kB</td><td>42.1kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/queries/">queries</a></th><td>2.6kB</td><td>5.5kB</td><td>24.9kB</td><td>106.8kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/checkpoints/">checkpoints</a></th><td>1.5kB</td><td>3.0kB</td><td>12.5kB</td><td>33.4kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/persisters/">persisters</a></th><td>0.8kB</td><td>1.7kB</td><td>5.2kB</td><td>27.2kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/common/">common</a></th><td>0.1kB</td><td>0.1kB</td><td>0.1kB</td><td>3.5kB</td></tr><tr><th class="right">tinybase (all)</th><td>8.7kB</td><td>21.1kB</td><td>92.8kB</td><td>0.3kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible to get up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://tinybase.org/guides/how-tinybase-is-built/testing/">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>1,794</td><td>1,794</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,932</td><td>1,932</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>768</td><td>768</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>628</td><td>628</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">2,581</td></tr><tr><th class="right">Assertions</th><td colspan="3">12,421</td></tr></tbody></table></div><hr><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="follow">Follow</h2><ul><li>News and updates on <a href="https://twitter.com/tinybasejs">Twitter</a>, <a href="https://discord.com/invite/mGz3mevwP8">Discord</a>, and <a href="https://facebook.com/tinybasejs">Facebook</a>.</li><li><a href="https://github.com/tinyplex/tinybase/discussion">Discussions</a> and <a href="https://github.com/tinyplex/tinybase/issues">issues</a> on <a href="https://github.com/tinyplex/tinybase">GitHub</a>.</li><li><a href="https://tinybase.org/guides/releases/">Release notes</a> for each version.</li><li>Packages on <a href="https://www.npmjs.com/package/tinybase/v/3.0.0">NPM</a>.</li></ul></section><section><h2 id="about">About</h2><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://hachyderm.io/@jamesgpearce">me</a> in API design, minification, and documentation. It could not have been built without these great <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it!</p></section>
269
+ <section><h2 id="did-we-say-tiny">Did we say tiny?</h2><p>If you use the basic <a href="https://tinybase.org/api/store/"><code>store</code></a> module alone, you&#x27;ll only add a gzipped <em>4.2kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>8.7kB</em>.</p><p>The <a href="https://tinybase.org/api/ui-react/"><code>ui-react</code></a> module is just another <em>3.4kB</em>, the <a href="https://tinybase.org/api/tools/"><code>tools</code></a> module is <em>5.4kB</em>, and everything is fast. Life&#x27;s easy when you have zero dependencies!</p><p>Read more about how TinyBase is structured in the <a href="https://tinybase.org/guides/how-tinybase-is-built/architecture/">Architecture</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>.js.gz</th><th>.js</th><th>debug.js</th><th>.d.ts</th></tr><tr><th class="right"><a href="https://tinybase.org/api/store/">store</a></th><td>4.2kB</td><td>10.0kB</td><td>43.9kB</td><td>184.6kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/metrics/">metrics</a></th><td>1.8kB</td><td>3.6kB</td><td>14.8kB</td><td>29.1kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/indexes/">indexes</a></th><td>1.9kB</td><td>3.7kB</td><td>16.6kB</td><td>33.9kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/relationships/">relationships</a></th><td>1.8kB</td><td>3.6kB</td><td>16.8kB</td><td>42.1kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/queries/">queries</a></th><td>2.6kB</td><td>5.5kB</td><td>24.9kB</td><td>106.8kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/checkpoints/">checkpoints</a></th><td>1.5kB</td><td>3.0kB</td><td>12.5kB</td><td>33.4kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/persisters/">persisters</a></th><td>0.8kB</td><td>1.7kB</td><td>5.2kB</td><td>27.2kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/common/">common</a></th><td>0.1kB</td><td>0.1kB</td><td>0.1kB</td><td>3.5kB</td></tr><tr><th class="right">tinybase (all)</th><td>8.7kB</td><td>21.1kB</td><td>92.8kB</td><td>0.3kB</td></tr></tbody></table></div><section><h2 id="well-tested-and-documented">Well tested and documented.</h2><p>TinyBase has <em>100.0%</em> test coverage, including the code throughout the documentation - even on this page! The guides, demos, and API examples are designed to make it as easy as possible to get up and running.</p><p>Read more about how TinyBase is tested in the Unit <a href="https://tinybase.org/guides/how-tinybase-is-built/testing/">Testing</a> guide.</p></section><div class="table"><table class="fixed"><tbody><tr><th width="30%"> </th><th>Total</th><th>Tested</th><th>Coverage</th></tr><tr><th class="right">Lines</th><td>1,794</td><td>1,794</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,932</td><td>1,932</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>768</td><td>768</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>628</td><td>628</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">2,581</td></tr><tr><th class="right">Assertions</th><td colspan="3">12,421</td></tr></tbody></table></div><hr><p><a class="start" href="https://tinybase.org/guides/the-basics/getting-started/">Get started</a></p><p><a href="https://tinybase.org/demos/">Try the demos</a></p><p><a href="https://tinybase.org/api/store/interfaces/store/store/">Read the docs</a></p><hr><section><h2 id="follow">Follow</h2><ul><li>News and updates on <a href="https://twitter.com/tinybasejs">Twitter</a>, <a href="https://discord.com/invite/mGz3mevwP8">Discord</a>, and <a href="https://facebook.com/tinybasejs">Facebook</a>.</li><li><a href="https://github.com/tinyplex/tinybase/discussion">Discussions</a> and <a href="https://github.com/tinyplex/tinybase/issues">issues</a> on <a href="https://github.com/tinyplex/tinybase">GitHub</a>.</li><li><a href="https://tinybase.org/guides/releases/">Release notes</a> for each version.</li><li>Packages on <a href="https://www.npmjs.com/package/tinybase/v/3.0.2">NPM</a>.</li></ul></section><section><h2 id="about">About</h2><p>Building TinyBase was originally an interesting exercise for <a rel="me" href="https://hachyderm.io/@jamesgpearce">me</a> in API design, minification, and documentation. It could not have been built without these great <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#giants">projects</a> and <a href="https://tinybase.org/guides/how-tinybase-is-built/credits/#and-friends">friends</a>, and I hope you enjoy using it!</p></section>