tinybase 2.2.3 → 2.2.5

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.
@@ -91,7 +91,8 @@ const camel = (str, firstCap = 0) =>
91
91
  substr(word, 1),
92
92
  ),
93
93
  );
94
- const snake = (str) => upper(join(str.split(NON_ALPHANUMERIC), '_'));
94
+ const snake = (str) =>
95
+ upper(join((str ? str : ' ').split(NON_ALPHANUMERIC), '_'));
95
96
  const comment = (doc) => `/** ${doc}. */`;
96
97
  const getCodeFunctions = () => {
97
98
  const allImports = pairNewMap();
@@ -220,7 +221,7 @@ const getListenerTypeDoc = (childNoun = 0, parentNoun = 0) =>
220
221
  `${A_FUNCTION_FOR} listening to changes to ${nouns[childNoun]} in ${nouns[parentNoun]}`;
221
222
  const getListenerDoc = (childNoun, parentNoun, pluralChild = 0) =>
222
223
  `${REGISTERS_A_LISTENER} whenever ${childNoun} in ${parentNoun} change` +
223
- (pluralChild ? '' : 's');
224
+ (pluralChild ? EMPTY_STRING : 's');
224
225
  const getStoreContentDoc = (verb = 0) =>
225
226
  `${verbs[verb]} ${THE_CONTENT_OF_THE_STORE}`;
226
227
  const getTableDoc = (tableId) => `the '${tableId}' Table`;
package/lib/es6/tools.js CHANGED
@@ -1 +1 @@
1
- const e=e=>typeof e,l="",t=e(l),a=e(!0),o=e(0),r="type",n="default",d=(e,l)=>e.every(l),s=(e,l)=>e.sort(l),$=(e,l)=>e.forEach(l),i=(e,l)=>e.map(l),I=e=>e.length,c=e=>0==I(e),b=(e,...l)=>e.push(...l),w=e=>e.pop(),u=(e,...l)=>e.unshift(...l),C=e=>e.shift(),h=JSON.parse,g=isFinite,T=e=>null==e,f=e=>e==t||e==a,R=l=>e(l)==t,p=e=>Array.isArray(e),m=(e,l)=>{var t;return null!=(t=null==e?void 0:e.has(l))&&t},v=e=>{var l;return[...null!=(l=null==e?void 0:e.values())?l:[]]},y=(e,l)=>null==e?void 0:e.forEach(l),L=(e,l)=>null==e?void 0:e.delete(l),S=e=>new Map(e),k=(e,l)=>null==e?void 0:e.get(l),E=(e,l)=>y(e,((e,t)=>l(t,e))),O=(e,l)=>{var t;return i([...null!=(t=null==e?void 0:e.entries())?t:[]],(([e,t])=>l(t,e)))},j=(e,l,t)=>T(t)?(L(e,l),e):null==e?void 0:e.set(l,t),x=(e,l,t)=>(m(e,l)||j(e,l,t()),k(e,l)),A=e=>new Set(p(e)||T(e)?e:[e]),J=(e,l)=>null==e?void 0:e.add(l),N=e=>[e,e],P=()=>[S(),S()],z=/[^A-Za-z0-9]+/,D=/^( *)\/\*\* *(.*?) *\*\/$/gm,F=(e,l,t)=>e.substring(l,t),G=e=>e.toUpperCase(),M=e=>e.toLowerCase(),W=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return m(e,o)?W(e,l,t,a+1):(j(e,o,t),o)},_=e=>e.replace(D,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,t=l)=>e.join(t),Z=e=>e.flat(1e3),q=(e,l=0)=>U(i(e.split(z),((e,t)=>(t>0||l?G:M)(F(e,0,1))+F(e,1)))),B=e=>G(U(e.split(z),"_")),H=e=>`/** ${e}. */`,K=()=>{const e=P(),t=S(),a=S(),o=S();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>$(a,(a=>J(x(e[l],t,A),a))),(e,l="",a="")=>W(t,e,[l,a]),(e,l,t,o,r,n="")=>W(a,e,[l,t,o,r,n]),(e,l,t)=>W(o,e,p(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>k(o,e)===l?e:W(o,e,l),t=>[...s(O(e[t],((e,l)=>`import {${U(s(v(e)),", ")}} from '${l}';`))),l],()=>O(t,(([e,t],a)=>[H(t),`export type ${a} = ${e};`,l])),e=>O(a,(([t,a,o,r,n],d)=>{const s=e?[`${d}: ${n}(${t}): ${a} => ${o},`]:[`${d}${n}(${t}): ${a};`];return e||u(s,H(r)),b(s,l),s})),()=>O(o,((e,t)=>(e=p(e)?e:[e],b(e,w(e)+";"),[`const ${t} = ${C(e)}`,e,l])))]},V=Object,X=V.keys,Y=V.freeze,ee=(e,l)=>i(V.entries(e),(([e,t])=>l(t,e))),le=e=>c(X(e)),te=l=>{const t=e(l);return f(t)||t==o&&g(l)?t:void 0},ae=e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))},oe="the content of",re="the Store",ne="A function for",de="export",se="listener",$e=" | undefined",ie=`Registers a ${se} that will be called`,Ie="Represents",ce=" => void",be=`${oe} ${re}`,we="the end of the transaction",ue="the specified Row",Ce=(e,l=0)=>`${Ie} a Row when ${l?"s":"g"}etting ${oe} the '${e}' Table`,he=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,ge=(e,l)=>`Calls a function for each ${e} in ${l}`,Te=(e,l=re)=>`Gets whether ${e} exists in ${l}`,fe=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${ne} listening to changes to ${je[e]} in ${je[l]}`,pe=(e,l,t=0)=>`${ie} whenever ${e} in ${l} change`+(t?"":"s"),me=(e=0)=>`${Oe[e]} ${be}`,ve=e=>`the '${e}' Table`,ye=e=>`${ue} in ${ve(e)}`,Le=e=>`the '${e}' Cell`,Se=(e,l=0)=>`${Oe[l]} ${oe} ${ve(e)}`,ke=(e,l=0)=>`${Oe[l]} ${oe} ${ye(e)}`,Ee=(e,l,t=0)=>`${Oe[t]} ${Le(l)} for ${ye(e)}`,Oe=["Gets","Sets","Sets part of","Deletes"],je=[re,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],xe=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Ae=(e,t=l,a=l)=>`store.${e}(${t})${a?" as "+a:l}`,Je=(e,t=l)=>`fluent(() => ${Ae(e,t)})`,Ne=(e,t=l,a=l)=>`store.${e}(${t?t+", ":l}proxy(${se})${a?", "+a:l})`,Pe=(e,t)=>{if(le(e))return N(l);const[o,d,s,$,i,I,c,b,w,u]=K(),C=`./${q(t)}.d`,h=q(t,1),g=q(h),f=S(),p=t=>ee(e,((e,a)=>t(a,x(f,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${Ie} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,t,a)=>`'${e}'${T(a)?"?":l}: ${t};`))," ")}}`,Ce(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,Ce(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${ce}`,fe(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${ce})${ce}`,fe(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(B(a),`'${a}'`)))),m=(l,t)=>ee(e[l],((e,l)=>t(l,e[r],e[n],I(B(l),`'${l}'`),q(l,1)))),y=s("Tables",`{${U(p(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${Ie} ${be}`),L=s("TableId",U(p((e=>`'${e}'`))," | "),"A Table Id in "+re),k=s("TableCallback",`(...[tableId, rowCallback]: ${U(p(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${ce}]`))," | ")})${ce}`,fe("a Table Id, and a Row iterator")),O=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(p(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,ne+" returning information about any Cell's changes during a transaction"),A=s("TablesListener",`(${g}: ${h}, getCellChange: ${O}${$e})${ce}`,Re(1)),J=s("TableIdsListener",`(${g}: ${h})${ce}`,Re(2)),P=s("TableListener",`(${g}: ${h}, tableId: ${L}, getCellChange: ${O}${$e})${ce}`,Re(3)),z=s("RowIdsListener",`(${g}: ${h}, tableId: ${L})${ce}`,Re(4,3)),D=s("RowListener",`(${g}: ${h}, tableId: ${L}, rowId: Id, getCellChange: ${O}${$e})${ce}`,Re(5,3)),F=s("CellIdsListener",`(${g}: ${h}, tableId: ${L}, rowId: Id)`+ce,Re(6,5)),G=s("CellListener",`(...[${g}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(p((e=>m(e,((l,t)=>`[${g}: ${h}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${$e}, oldCell: ${t}${$e}, getCellChange: ${O} | undefined]`)))))," | ")})${ce}`,Re(7,5)),M=s("InvalidCellListener",`(${g}: ${h}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${ce}`,Re(8)),W=s("TransactionListener",`(${g}: ${h}, cellsTouched: boolean)${ce}`,ne+" listening to the completion of a transaction");$("hasTables",l,a,Ae("hasTables"),Te("any Table")),$("getTables",l,y,Ae("getTables"),me()),$("setTables","tables: "+y,h,Je("setTables","tables"),me(1)),$("delTables",l,h,Je("delTables"),me(3)),$("getTableIds",l,L+"[]",Ae("getTableIds",l,L+"[]"),he("Table",re)),$("forEachTable","tableCallback: "+k,"void",Ae("forEachTable","tableCallback as any"),ge("Table",re));const _=S();return p(((e,[t,o,r,n,s,i],I,c)=>{d(1,C,t,o,r,n,s,i),$(`has${I}Table`,l,a,Ae("hasTable",c),Te(ve(e))),$(`get${I}Table`,l,t,Ae("getTable",c,t),Se(e)),$(`set${I}Table`,"table: "+t,h,Je("setTable",c+", table"),Se(e,1)),$(`del${I}Table`,l,h,Je("delTable",c),Se(e,3)),$(`get${I}RowIds`,l,"Ids",Ae("getRowIds",c),he("Row",ve(e))),$(`get${I}SortedRowIds`,`cellId?: ${n}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ae("getSortedRowIds",c+", cellId, descending, offset, limit"),he("Row",ve(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Ae("forEachRow",c+", rowCallback as any"),ge("Row",ve(e))),$(`has${I}Row`,"rowId: Id",a,Ae("hasRow",c+", rowId"),Te(ue,ve(e))),$(`get${I}Row`,"rowId: Id",o,Ae("getRow",c+", rowId",o),ke(e)),$(`set${I}Row`,"rowId: Id, row: "+r,h,Je("setRow",c+", rowId, row"),ke(e,1)),$(`add${I}Row`,"row: "+r,"Id"+$e,Ae("addRow",c+", row"),"Adds a new Row to "+ve(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+r,h,Je("setPartialRow",c+", rowId, partialRow"),ke(e,2)),$(`del${I}Row`,"rowId: Id",h,Je("delRow",c+", rowId"),ke(e,3)),$(`get${I}CellIds`,"rowId: Id",n+"[]",Ae("getCellIds",c+", rowId",n+"[]"),he("Cell",ye(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Ae("forEachCell",c+", rowId, cellCallback as any"),ge("Cell",ye(e))),m(e,((t,o,r,n,d)=>{const s="Map"+q(o,1);j(_,o,s),$(`has${I}${d}Cell`,"rowId: Id",a,Ae("hasCell",`${c}, rowId, ${n}`),Te(Le(t),ye(e)));const i=`${o}${T(r)?$e:l}`;$(`get${I}${d}Cell`,"rowId: Id",i,Ae("getCell",`${c}, rowId, ${n}`,i),Ee(e,t)),$(`set${I}${d}Cell`,`rowId: Id, cell: ${o} | ${s}`,h,Je("setCell",`${c}, rowId, ${n}, cell as any`),Ee(e,t,1)),$(`del${I}${d}Cell`,"rowId: Id",h,Je("delCell",`${c}, rowId, ${n}`),Ee(e,t,3))}))})),$("getJson",l,"Json",Ae("getJson"),`${Oe[0]} a string serialization ${be}`),$("setJson","json: Json",h,Je("setJson","json"),`${Oe[1]} ${be} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Ae("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",l,h,Je("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",h,Je("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${se}: ${A}, mutator?: boolean`,"Id",Ne("addTablesListener",l,"mutator"),`${ie} whenever ${be} changes`),$("addTableIdsListener",`${se}: ${J}, mutator?: boolean`,"Id",Ne("addTableIdsListener",l,"mutator"),pe("the Table Ids",re,1)),$("addTableListener",`tableId: ${L} | null, ${se}: ${P}, mutator?: boolean`,"Id",Ne("addTableListener","tableId","mutator"),pe("a Table",re)),$("addRowIdsListener",`tableId: ${L} | null, ${se}: ${z}, mutator?: boolean`,"Id",Ne("addRowIdsListener","tableId","mutator"),pe("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${L} | null, rowId: IdOrNull, ${se}: ${D}, mutator?: boolean`,"Id",Ne("addRowListener","tableId, rowId","mutator"),pe("a Row","a Table")),$("addCellIdsListener",`tableId: ${L} | null, rowId: IdOrNull, ${se}: ${F}, mutator?: boolean`,"Id",Ne("addCellIdsListener","tableId, rowId","mutator"),pe("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${L} | null, rowId: IdOrNull, cellId: ${U(p(((e,l)=>l[3]))," | ")} | null, ${se}: ${G}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),pe("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${se}: ${M}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),ie+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${se}: ${W}`,"Id",Ne("addWillFinishTransactionListener"),`${ie} just before ${we}`),$("addDidFinishTransactionListener",`${se}: ${W}`,"Id",Ne("addDidFinishTransactionListener"),`${ie} just after ${we}`),$("callListener",se+"Id: Id",h,Je("callListener",se+"Id"),`Manually provoke a ${se} to be called`),$("delListener",se+"Id: Id",h,Je("delListener",se+"Id"),`Remove a ${se} that was previously added to ${re}`),$("getStore",l,"Store","store",Oe[0]+" the underlying Store object"),E(_,((e,l)=>s(l,`(cell: ${e}${$e}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(0,"tinybase","CellChange",...xe),d(1,"tinybase","createStore",...xe),d(1,C,h,`create${h} as create${h}Decl`,y,L,k,A,J,P,z,D,F,G,M,W,...v(_)),I("store",["createStore().setSchema({",Z(p(((e,t,a,o)=>[`[${o}]: {`,...m(e,((e,t,a,o)=>`[${o}]: {[${I(B(r),`'${r}'`)}]: ${I(B(t),`'${t}'`)}${T(a)?l:`, [${I(B(n),`'${n}'`)}]: ${R(a)?I(B(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${g};`]),i("proxy",se+": any",`(_: Store, ...args: any[]) => ${se}(${g}, ...args)`),I(g,["{",...w(1),"}"]),[o(...c(0),...b(),`${de} interface ${h} {`,...w(0),"}",l,H(`Creates a ${h} object`),`${de} function create${h}(): ${h};`),o(...c(1),`${de} const create${h}: typeof create${h}Decl = () => {`,...u(),`return Object.freeze(${g});`,"};")]};var ze=Object.defineProperty,De=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable,Me=(e,l,t)=>l in e?ze(e,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[l]=t,We=(e,l)=>{for(var t in l||(l={}))Fe.call(l,t)&&Me(e,t,l[t]);if(De)for(var t of De(l))Ge.call(l,t)&&Me(e,t,l[t]);return e},_e=(e,l,t)=>new Promise(((a,o)=>{var r=e=>{try{d(t.next(e))}catch(e){o(e)}},n=e=>{try{d(t.throw(e))}catch(e){o(e)}},d=e=>e.done?a(e.value):Promise.resolve(e.value).then(r,n);d((t=t.apply(e,l)).next())}));const Qe={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ue=ae((e=>{const l=()=>{const l=h(e.getSchemaJson());return!le(l)||d(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=S();if(d(a,(l=>d(e.getCellIds(t,l),(a=>{const r=e.getCell(t,l,a),n=x(o,a,(()=>[te(r),S(),[0],0])),[d,s,[$]]=n,i=x(s,r,(()=>0))+1;return i>$&&(n[2]=[i,r]),j(s,r,i),n[3]++,d==te(r)})))))return l[t]={},y(o,(([e,,[,o],d],s)=>{l[t][s]=We({[r]:e},d==I(a)?{[n]:o}:{})})),1}))?l:{}},t=e=>Pe(l(),e),a=e=>_e(void 0,null,(function*(){let l;try{l=(yield import("prettier")).format}catch(e){l=e=>e}return i(t(e),(e=>_(l(e,Qe))))}));return Y({getStoreStats:l=>{let t=0,a=0,o=0;const r={};return e.forEachTable(((e,n)=>{t++;let d=0,s=0;const $={};n(((e,t)=>{d++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=d,o+=s,l&&(r[e]={tableRows:d,tableCells:s,rows:$})})),We({totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson())},l?{detail:{tables:r}}:{})},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));export{Ue as createTools};
1
+ const e=e=>typeof e,l="",t=e(l),a=e(!0),o=e(0),r="type",n="default",d=(e,l)=>e.every(l),s=(e,l)=>e.sort(l),$=(e,l)=>e.forEach(l),i=(e,l)=>e.map(l),I=e=>e.length,c=e=>0==I(e),b=(e,...l)=>e.push(...l),w=e=>e.pop(),u=(e,...l)=>e.unshift(...l),C=e=>e.shift(),h=JSON.parse,g=isFinite,T=e=>null==e,f=e=>e==t||e==a,R=l=>e(l)==t,p=e=>Array.isArray(e),m=(e,l)=>{var t;return null!=(t=null==e?void 0:e.has(l))&&t},v=e=>{var l;return[...null!=(l=null==e?void 0:e.values())?l:[]]},y=(e,l)=>null==e?void 0:e.forEach(l),L=(e,l)=>null==e?void 0:e.delete(l),S=e=>new Map(e),k=(e,l)=>null==e?void 0:e.get(l),E=(e,l)=>y(e,((e,t)=>l(t,e))),O=(e,l)=>{var t;return i([...null!=(t=null==e?void 0:e.entries())?t:[]],(([e,t])=>l(t,e)))},j=(e,l,t)=>T(t)?(L(e,l),e):null==e?void 0:e.set(l,t),x=(e,l,t)=>(m(e,l)||j(e,l,t()),k(e,l)),A=e=>new Set(p(e)||T(e)?e:[e]),J=(e,l)=>null==e?void 0:e.add(l),N=e=>[e,e],P=()=>[S(),S()],z=/[^A-Za-z0-9]+/,D=/^( *)\/\*\* *(.*?) *\*\/$/gm,F=(e,l,t)=>e.substring(l,t),G=e=>e.toUpperCase(),M=e=>e.toLowerCase(),W=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return m(e,o)?W(e,l,t,a+1):(j(e,o,t),o)},_=e=>e.replace(D,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,t=l)=>e.join(t),Z=e=>e.flat(1e3),q=(e,l=0)=>U(i(e.split(z),((e,t)=>(t>0||l?G:M)(F(e,0,1))+F(e,1)))),B=e=>G(U((e||" ").split(z),"_")),H=e=>`/** ${e}. */`,K=()=>{const e=P(),t=S(),a=S(),o=S();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>$(a,(a=>J(x(e[l],t,A),a))),(e,l="",a="")=>W(t,e,[l,a]),(e,l,t,o,r,n="")=>W(a,e,[l,t,o,r,n]),(e,l,t)=>W(o,e,p(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>k(o,e)===l?e:W(o,e,l),t=>[...s(O(e[t],((e,l)=>`import {${U(s(v(e)),", ")}} from '${l}';`))),l],()=>O(t,(([e,t],a)=>[H(t),`export type ${a} = ${e};`,l])),e=>O(a,(([t,a,o,r,n],d)=>{const s=e?[`${d}: ${n}(${t}): ${a} => ${o},`]:[`${d}${n}(${t}): ${a};`];return e||u(s,H(r)),b(s,l),s})),()=>O(o,((e,t)=>(e=p(e)?e:[e],b(e,w(e)+";"),[`const ${t} = ${C(e)}`,e,l])))]},V=Object,X=V.keys,Y=V.freeze,ee=(e,l)=>i(V.entries(e),(([e,t])=>l(t,e))),le=e=>c(X(e)),te=l=>{const t=e(l);return f(t)||t==o&&g(l)?t:void 0},ae=e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))},oe="the content of",re="the Store",ne="A function for",de="export",se="listener",$e=" | undefined",ie=`Registers a ${se} that will be called`,Ie="Represents",ce=" => void",be=`${oe} ${re}`,we="the end of the transaction",ue="the specified Row",Ce=(e,l=0)=>`${Ie} a Row when ${l?"s":"g"}etting ${oe} the '${e}' Table`,he=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,ge=(e,l)=>`Calls a function for each ${e} in ${l}`,Te=(e,l=re)=>`Gets whether ${e} exists in ${l}`,fe=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${ne} listening to changes to ${je[e]} in ${je[l]}`,pe=(e,t,a=0)=>`${ie} whenever ${e} in ${t} change`+(a?l:"s"),me=(e=0)=>`${Oe[e]} ${be}`,ve=e=>`the '${e}' Table`,ye=e=>`${ue} in ${ve(e)}`,Le=e=>`the '${e}' Cell`,Se=(e,l=0)=>`${Oe[l]} ${oe} ${ve(e)}`,ke=(e,l=0)=>`${Oe[l]} ${oe} ${ye(e)}`,Ee=(e,l,t=0)=>`${Oe[t]} ${Le(l)} for ${ye(e)}`,Oe=["Gets","Sets","Sets part of","Deletes"],je=[re,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],xe=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Ae=(e,t=l,a=l)=>`store.${e}(${t})${a?" as "+a:l}`,Je=(e,t=l)=>`fluent(() => ${Ae(e,t)})`,Ne=(e,t=l,a=l)=>`store.${e}(${t?t+", ":l}proxy(${se})${a?", "+a:l})`,Pe=(e,t)=>{if(le(e))return N(l);const[o,d,s,$,i,I,c,b,w,u]=K(),C=`./${q(t)}.d`,h=q(t,1),g=q(h),f=S(),p=t=>ee(e,((e,a)=>t(a,x(f,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${Ie} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,t,a)=>`'${e}'${T(a)?"?":l}: ${t};`))," ")}}`,Ce(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,Ce(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${ce}`,fe(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${ce})${ce}`,fe(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(B(a),`'${a}'`)))),m=(l,t)=>ee(e[l],((e,l)=>t(l,e[r],e[n],I(B(l),`'${l}'`),q(l,1)))),y=s("Tables",`{${U(p(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${Ie} ${be}`),L=s("TableId",U(p((e=>`'${e}'`))," | "),"A Table Id in "+re),k=s("TableCallback",`(...[tableId, rowCallback]: ${U(p(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${ce}]`))," | ")})${ce}`,fe("a Table Id, and a Row iterator")),O=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(p(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,ne+" returning information about any Cell's changes during a transaction"),A=s("TablesListener",`(${g}: ${h}, getCellChange: ${O}${$e})${ce}`,Re(1)),J=s("TableIdsListener",`(${g}: ${h})${ce}`,Re(2)),P=s("TableListener",`(${g}: ${h}, tableId: ${L}, getCellChange: ${O}${$e})${ce}`,Re(3)),z=s("RowIdsListener",`(${g}: ${h}, tableId: ${L})${ce}`,Re(4,3)),D=s("RowListener",`(${g}: ${h}, tableId: ${L}, rowId: Id, getCellChange: ${O}${$e})${ce}`,Re(5,3)),F=s("CellIdsListener",`(${g}: ${h}, tableId: ${L}, rowId: Id)`+ce,Re(6,5)),G=s("CellListener",`(...[${g}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(p((e=>m(e,((l,t)=>`[${g}: ${h}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${$e}, oldCell: ${t}${$e}, getCellChange: ${O} | undefined]`)))))," | ")})${ce}`,Re(7,5)),M=s("InvalidCellListener",`(${g}: ${h}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${ce}`,Re(8)),W=s("TransactionListener",`(${g}: ${h}, cellsTouched: boolean)${ce}`,ne+" listening to the completion of a transaction");$("hasTables",l,a,Ae("hasTables"),Te("any Table")),$("getTables",l,y,Ae("getTables"),me()),$("setTables","tables: "+y,h,Je("setTables","tables"),me(1)),$("delTables",l,h,Je("delTables"),me(3)),$("getTableIds",l,L+"[]",Ae("getTableIds",l,L+"[]"),he("Table",re)),$("forEachTable","tableCallback: "+k,"void",Ae("forEachTable","tableCallback as any"),ge("Table",re));const _=S();return p(((e,[t,o,r,n,s,i],I,c)=>{d(1,C,t,o,r,n,s,i),$(`has${I}Table`,l,a,Ae("hasTable",c),Te(ve(e))),$(`get${I}Table`,l,t,Ae("getTable",c,t),Se(e)),$(`set${I}Table`,"table: "+t,h,Je("setTable",c+", table"),Se(e,1)),$(`del${I}Table`,l,h,Je("delTable",c),Se(e,3)),$(`get${I}RowIds`,l,"Ids",Ae("getRowIds",c),he("Row",ve(e))),$(`get${I}SortedRowIds`,`cellId?: ${n}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ae("getSortedRowIds",c+", cellId, descending, offset, limit"),he("Row",ve(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Ae("forEachRow",c+", rowCallback as any"),ge("Row",ve(e))),$(`has${I}Row`,"rowId: Id",a,Ae("hasRow",c+", rowId"),Te(ue,ve(e))),$(`get${I}Row`,"rowId: Id",o,Ae("getRow",c+", rowId",o),ke(e)),$(`set${I}Row`,"rowId: Id, row: "+r,h,Je("setRow",c+", rowId, row"),ke(e,1)),$(`add${I}Row`,"row: "+r,"Id"+$e,Ae("addRow",c+", row"),"Adds a new Row to "+ve(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+r,h,Je("setPartialRow",c+", rowId, partialRow"),ke(e,2)),$(`del${I}Row`,"rowId: Id",h,Je("delRow",c+", rowId"),ke(e,3)),$(`get${I}CellIds`,"rowId: Id",n+"[]",Ae("getCellIds",c+", rowId",n+"[]"),he("Cell",ye(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Ae("forEachCell",c+", rowId, cellCallback as any"),ge("Cell",ye(e))),m(e,((t,o,r,n,d)=>{const s="Map"+q(o,1);j(_,o,s),$(`has${I}${d}Cell`,"rowId: Id",a,Ae("hasCell",`${c}, rowId, ${n}`),Te(Le(t),ye(e)));const i=`${o}${T(r)?$e:l}`;$(`get${I}${d}Cell`,"rowId: Id",i,Ae("getCell",`${c}, rowId, ${n}`,i),Ee(e,t)),$(`set${I}${d}Cell`,`rowId: Id, cell: ${o} | ${s}`,h,Je("setCell",`${c}, rowId, ${n}, cell as any`),Ee(e,t,1)),$(`del${I}${d}Cell`,"rowId: Id",h,Je("delCell",`${c}, rowId, ${n}`),Ee(e,t,3))}))})),$("getJson",l,"Json",Ae("getJson"),`${Oe[0]} a string serialization ${be}`),$("setJson","json: Json",h,Je("setJson","json"),`${Oe[1]} ${be} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Ae("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",l,h,Je("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",h,Je("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${se}: ${A}, mutator?: boolean`,"Id",Ne("addTablesListener",l,"mutator"),`${ie} whenever ${be} changes`),$("addTableIdsListener",`${se}: ${J}, mutator?: boolean`,"Id",Ne("addTableIdsListener",l,"mutator"),pe("the Table Ids",re,1)),$("addTableListener",`tableId: ${L} | null, ${se}: ${P}, mutator?: boolean`,"Id",Ne("addTableListener","tableId","mutator"),pe("a Table",re)),$("addRowIdsListener",`tableId: ${L} | null, ${se}: ${z}, mutator?: boolean`,"Id",Ne("addRowIdsListener","tableId","mutator"),pe("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${L} | null, rowId: IdOrNull, ${se}: ${D}, mutator?: boolean`,"Id",Ne("addRowListener","tableId, rowId","mutator"),pe("a Row","a Table")),$("addCellIdsListener",`tableId: ${L} | null, rowId: IdOrNull, ${se}: ${F}, mutator?: boolean`,"Id",Ne("addCellIdsListener","tableId, rowId","mutator"),pe("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${L} | null, rowId: IdOrNull, cellId: ${U(p(((e,l)=>l[3]))," | ")} | null, ${se}: ${G}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),pe("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${se}: ${M}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),ie+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${se}: ${W}`,"Id",Ne("addWillFinishTransactionListener"),`${ie} just before ${we}`),$("addDidFinishTransactionListener",`${se}: ${W}`,"Id",Ne("addDidFinishTransactionListener"),`${ie} just after ${we}`),$("callListener",se+"Id: Id",h,Je("callListener",se+"Id"),`Manually provoke a ${se} to be called`),$("delListener",se+"Id: Id",h,Je("delListener",se+"Id"),`Remove a ${se} that was previously added to ${re}`),$("getStore",l,"Store","store",Oe[0]+" the underlying Store object"),E(_,((e,l)=>s(l,`(cell: ${e}${$e}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(0,"tinybase","CellChange",...xe),d(1,"tinybase","createStore",...xe),d(1,C,h,`create${h} as create${h}Decl`,y,L,k,A,J,P,z,D,F,G,M,W,...v(_)),I("store",["createStore().setSchema({",Z(p(((e,t,a,o)=>[`[${o}]: {`,...m(e,((e,t,a,o)=>`[${o}]: {[${I(B(r),`'${r}'`)}]: ${I(B(t),`'${t}'`)}${T(a)?l:`, [${I(B(n),`'${n}'`)}]: ${R(a)?I(B(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${g};`]),i("proxy",se+": any",`(_: Store, ...args: any[]) => ${se}(${g}, ...args)`),I(g,["{",...w(1),"}"]),[o(...c(0),...b(),`${de} interface ${h} {`,...w(0),"}",l,H(`Creates a ${h} object`),`${de} function create${h}(): ${h};`),o(...c(1),`${de} const create${h}: typeof create${h}Decl = () => {`,...u(),`return Object.freeze(${g});`,"};")]};var ze=Object.defineProperty,De=Object.getOwnPropertySymbols,Fe=Object.prototype.hasOwnProperty,Ge=Object.prototype.propertyIsEnumerable,Me=(e,l,t)=>l in e?ze(e,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[l]=t,We=(e,l)=>{for(var t in l||(l={}))Fe.call(l,t)&&Me(e,t,l[t]);if(De)for(var t of De(l))Ge.call(l,t)&&Me(e,t,l[t]);return e},_e=(e,l,t)=>new Promise(((a,o)=>{var r=e=>{try{d(t.next(e))}catch(e){o(e)}},n=e=>{try{d(t.throw(e))}catch(e){o(e)}},d=e=>e.done?a(e.value):Promise.resolve(e.value).then(r,n);d((t=t.apply(e,l)).next())}));const Qe={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ue=ae((e=>{const l=()=>{const l=h(e.getSchemaJson());return!le(l)||d(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=S();if(d(a,(l=>d(e.getCellIds(t,l),(a=>{const r=e.getCell(t,l,a),n=x(o,a,(()=>[te(r),S(),[0],0])),[d,s,[$]]=n,i=x(s,r,(()=>0))+1;return i>$&&(n[2]=[i,r]),j(s,r,i),n[3]++,d==te(r)})))))return l[t]={},y(o,(([e,,[,o],d],s)=>{l[t][s]=We({[r]:e},d==I(a)?{[n]:o}:{})})),1}))?l:{}},t=e=>Pe(l(),e),a=e=>_e(void 0,null,(function*(){let l;try{l=(yield import("prettier")).format}catch(e){l=e=>e}return i(t(e),(e=>_(l(e,Qe))))}));return Y({getStoreStats:l=>{let t=0,a=0,o=0;const r={};return e.forEachTable(((e,n)=>{t++;let d=0,s=0;const $={};n(((e,t)=>{d++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=d,o+=s,l&&(r[e]={tableRows:d,tableCells:s,rows:$})})),We({totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson())},l?{detail:{tables:r}}:{})},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));export{Ue as createTools};
Binary file
package/lib/tools.js CHANGED
@@ -1 +1 @@
1
- const e=e=>typeof e,l="",t=e(l),a=e(!0),o=e(0),n="type",r="default",d=(e,l)=>e.every(l),s=(e,l)=>e.sort(l),$=(e,l)=>e.forEach(l),i=(e,l)=>e.map(l),I=e=>e.length,c=e=>0==I(e),b=(e,...l)=>e.push(...l),w=e=>e.pop(),C=(e,...l)=>e.unshift(...l),h=e=>e.shift(),g=JSON.parse,u=isFinite,T=e=>null==e,R=e=>e==t||e==a,f=l=>e(l)==t,p=e=>Array.isArray(e),m=(e,l)=>e?.has(l)??!1,L=e=>[...e?.values()??[]],y=(e,l)=>e?.forEach(l),S=(e,l)=>e?.delete(l),v=e=>new Map(e),k=(e,l)=>e?.get(l),E=(e,l)=>y(e,((e,t)=>l(t,e))),j=(e,l)=>i([...e?.entries()??[]],(([e,t])=>l(t,e))),x=(e,l,t)=>T(t)?(S(e,l),e):e?.set(l,t),A=(e,l,t)=>(m(e,l)||x(e,l,t()),k(e,l)),J=e=>new Set(p(e)||T(e)?e:[e]),O=(e,l)=>e?.add(l),N=e=>[e,e],z=()=>[v(),v()],D=/[^A-Za-z0-9]+/,F=/^( *)\/\*\* *(.*?) *\*\/$/gm,G=(e,l,t)=>e.substring(l,t),M=e=>e.toUpperCase(),W=e=>e.toLowerCase(),P=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return m(e,o)?P(e,l,t,a+1):(x(e,o,t),o)},_=e=>e.replace(F,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,t=l)=>e.join(t),Z=e=>e.flat(1e3),q=(e,l=0)=>U(i(e.split(D),((e,t)=>(t>0||l?M:W)(G(e,0,1))+G(e,1)))),B=e=>M(U(e.split(D),"_")),H=e=>`/** ${e}. */`,K=()=>{const e=z(),t=v(),a=v(),o=v();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>$(a,(a=>O(A(e[l],t,J),a))),(e,l="",a="")=>P(t,e,[l,a]),(e,l,t,o,n,r="")=>P(a,e,[l,t,o,n,r]),(e,l,t)=>P(o,e,p(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>k(o,e)===l?e:P(o,e,l),t=>[...s(j(e[t],((e,l)=>`import {${U(s(L(e)),", ")}} from '${l}';`))),l],()=>j(t,(([e,t],a)=>[H(t),`export type ${a} = ${e};`,l])),e=>j(a,(([t,a,o,n,r],d)=>{const s=e?[`${d}: ${r}(${t}): ${a} => ${o},`]:[`${d}${r}(${t}): ${a};`];return e||C(s,H(n)),b(s,l),s})),()=>j(o,((e,t)=>(e=p(e)?e:[e],b(e,w(e)+";"),[`const ${t} = ${h(e)}`,e,l])))]},V=Object,X=V.keys,Y=V.freeze,ee=(e,l)=>i(V.entries(e),(([e,t])=>l(t,e))),le=e=>c(X(e)),te=l=>{const t=e(l);return R(t)||t==o&&u(l)?t:void 0},ae="the content of",oe="the Store",ne="A function for",re="export",de="listener",se=" | undefined",$e=`Registers a ${de} that will be called`,ie="Represents",Ie=" => void",ce=`${ae} ${oe}`,be="the end of the transaction",we="the specified Row",Ce=(e,l=0)=>`${ie} a Row when ${l?"s":"g"}etting ${ae} the '${e}' Table`,he=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,ge=(e,l)=>`Calls a function for each ${e} in ${l}`,ue=(e,l=oe)=>`Gets whether ${e} exists in ${l}`,Te=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${ne} listening to changes to ${je[e]} in ${je[l]}`,fe=(e,l,t=0)=>`${$e} whenever ${e} in ${l} change`+(t?"":"s"),pe=(e=0)=>`${Ee[e]} ${ce}`,me=e=>`the '${e}' Table`,Le=e=>`${we} in ${me(e)}`,ye=e=>`the '${e}' Cell`,Se=(e,l=0)=>`${Ee[l]} ${ae} ${me(e)}`,ve=(e,l=0)=>`${Ee[l]} ${ae} ${Le(e)}`,ke=(e,l,t=0)=>`${Ee[t]} ${ye(l)} for ${Le(e)}`,Ee=["Gets","Sets","Sets part of","Deletes"],je=[oe,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],xe=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Ae=(e,t=l,a=l)=>`store.${e}(${t})${a?" as "+a:l}`,Je=(e,t=l)=>`fluent(() => ${Ae(e,t)})`,Oe=(e,t=l,a=l)=>`store.${e}(${t?t+", ":l}proxy(${de})${a?", "+a:l})`,Ne=(e,t)=>{if(le(e))return N(l);const[o,d,s,$,i,I,c,b,w,C]=K(),h=`./${q(t)}.d`,g=q(t,1),u=q(g),R=v(),p=t=>ee(e,((e,a)=>t(a,A(R,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ie} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,t,a)=>`'${e}'${T(a)?"?":l}: ${t};`))," ")}}`,Ce(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,Ce(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${Ie}`,Te(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${Ie})${Ie}`,Te(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(B(a),`'${a}'`)))),m=(l,t)=>ee(e[l],((e,l)=>t(l,e[n],e[r],I(B(l),`'${l}'`),q(l,1)))),y=s("Tables",`{${U(p(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${ie} ${ce}`),S=s("TableId",U(p((e=>`'${e}'`))," | "),"A Table Id in "+oe),k=s("TableCallback",`(...[tableId, rowCallback]: ${U(p(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${Ie}]`))," | ")})${Ie}`,Te("a Table Id, and a Row iterator")),j=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(p(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,ne+" returning information about any Cell's changes during a transaction"),J=s("TablesListener",`(${u}: ${g}, getCellChange: ${j}${se})${Ie}`,Re(1)),O=s("TableIdsListener",`(${u}: ${g})${Ie}`,Re(2)),z=s("TableListener",`(${u}: ${g}, tableId: ${S}, getCellChange: ${j}${se})${Ie}`,Re(3)),D=s("RowIdsListener",`(${u}: ${g}, tableId: ${S})${Ie}`,Re(4,3)),F=s("RowListener",`(${u}: ${g}, tableId: ${S}, rowId: Id, getCellChange: ${j}${se})${Ie}`,Re(5,3)),G=s("CellIdsListener",`(${u}: ${g}, tableId: ${S}, rowId: Id)`+Ie,Re(6,5)),M=s("CellListener",`(...[${u}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(p((e=>m(e,((l,t)=>`[${u}: ${g}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${se}, oldCell: ${t}${se}, getCellChange: ${j} | undefined]`)))))," | ")})${Ie}`,Re(7,5)),W=s("InvalidCellListener",`(${u}: ${g}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${Ie}`,Re(8)),P=s("TransactionListener",`(${u}: ${g}, cellsTouched: boolean)${Ie}`,ne+" listening to the completion of a transaction");$("hasTables",l,a,Ae("hasTables"),ue("any Table")),$("getTables",l,y,Ae("getTables"),pe()),$("setTables","tables: "+y,g,Je("setTables","tables"),pe(1)),$("delTables",l,g,Je("delTables"),pe(3)),$("getTableIds",l,S+"[]",Ae("getTableIds",l,S+"[]"),he("Table",oe)),$("forEachTable","tableCallback: "+k,"void",Ae("forEachTable","tableCallback as any"),ge("Table",oe));const _=v();return p(((e,[t,o,n,r,s,i],I,c)=>{d(1,h,t,o,n,r,s,i),$(`has${I}Table`,l,a,Ae("hasTable",c),ue(me(e))),$(`get${I}Table`,l,t,Ae("getTable",c,t),Se(e)),$(`set${I}Table`,"table: "+t,g,Je("setTable",c+", table"),Se(e,1)),$(`del${I}Table`,l,g,Je("delTable",c),Se(e,3)),$(`get${I}RowIds`,l,"Ids",Ae("getRowIds",c),he("Row",me(e))),$(`get${I}SortedRowIds`,`cellId?: ${r}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ae("getSortedRowIds",c+", cellId, descending, offset, limit"),he("Row",me(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Ae("forEachRow",c+", rowCallback as any"),ge("Row",me(e))),$(`has${I}Row`,"rowId: Id",a,Ae("hasRow",c+", rowId"),ue(we,me(e))),$(`get${I}Row`,"rowId: Id",o,Ae("getRow",c+", rowId",o),ve(e)),$(`set${I}Row`,"rowId: Id, row: "+n,g,Je("setRow",c+", rowId, row"),ve(e,1)),$(`add${I}Row`,"row: "+n,"Id"+se,Ae("addRow",c+", row"),"Adds a new Row to "+me(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+n,g,Je("setPartialRow",c+", rowId, partialRow"),ve(e,2)),$(`del${I}Row`,"rowId: Id",g,Je("delRow",c+", rowId"),ve(e,3)),$(`get${I}CellIds`,"rowId: Id",r+"[]",Ae("getCellIds",c+", rowId",r+"[]"),he("Cell",Le(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Ae("forEachCell",c+", rowId, cellCallback as any"),ge("Cell",Le(e))),m(e,((t,o,n,r,d)=>{const s="Map"+q(o,1);x(_,o,s),$(`has${I}${d}Cell`,"rowId: Id",a,Ae("hasCell",`${c}, rowId, ${r}`),ue(ye(t),Le(e)));const i=`${o}${T(n)?se:l}`;$(`get${I}${d}Cell`,"rowId: Id",i,Ae("getCell",`${c}, rowId, ${r}`,i),ke(e,t)),$(`set${I}${d}Cell`,`rowId: Id, cell: ${o} | ${s}`,g,Je("setCell",`${c}, rowId, ${r}, cell as any`),ke(e,t,1)),$(`del${I}${d}Cell`,"rowId: Id",g,Je("delCell",`${c}, rowId, ${r}`),ke(e,t,3))}))})),$("getJson",l,"Json",Ae("getJson"),`${Ee[0]} a string serialization ${ce}`),$("setJson","json: Json",g,Je("setJson","json"),`${Ee[1]} ${ce} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Ae("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",l,g,Je("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",g,Je("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${de}: ${J}, mutator?: boolean`,"Id",Oe("addTablesListener",l,"mutator"),`${$e} whenever ${ce} changes`),$("addTableIdsListener",`${de}: ${O}, mutator?: boolean`,"Id",Oe("addTableIdsListener",l,"mutator"),fe("the Table Ids",oe,1)),$("addTableListener",`tableId: ${S} | null, ${de}: ${z}, mutator?: boolean`,"Id",Oe("addTableListener","tableId","mutator"),fe("a Table",oe)),$("addRowIdsListener",`tableId: ${S} | null, ${de}: ${D}, mutator?: boolean`,"Id",Oe("addRowIdsListener","tableId","mutator"),fe("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${S} | null, rowId: IdOrNull, ${de}: ${F}, mutator?: boolean`,"Id",Oe("addRowListener","tableId, rowId","mutator"),fe("a Row","a Table")),$("addCellIdsListener",`tableId: ${S} | null, rowId: IdOrNull, ${de}: ${G}, mutator?: boolean`,"Id",Oe("addCellIdsListener","tableId, rowId","mutator"),fe("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${S} | null, rowId: IdOrNull, cellId: ${U(p(((e,l)=>l[3]))," | ")} | null, ${de}: ${M}, mutator?: boolean`,"Id",Oe("addCellListener","tableId, rowId, cellId","mutator"),fe("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${de}: ${W}, mutator?: boolean`,"Id",Oe("addCellListener","tableId, rowId, cellId","mutator"),$e+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${de}: ${P}`,"Id",Oe("addWillFinishTransactionListener"),`${$e} just before ${be}`),$("addDidFinishTransactionListener",`${de}: ${P}`,"Id",Oe("addDidFinishTransactionListener"),`${$e} just after ${be}`),$("callListener",de+"Id: Id",g,Je("callListener",de+"Id"),`Manually provoke a ${de} to be called`),$("delListener",de+"Id: Id",g,Je("delListener",de+"Id"),`Remove a ${de} that was previously added to ${oe}`),$("getStore",l,"Store","store",Ee[0]+" the underlying Store object"),E(_,((e,l)=>s(l,`(cell: ${e}${se}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(0,"tinybase","CellChange",...xe),d(1,"tinybase","createStore",...xe),d(1,h,g,`create${g} as create${g}Decl`,y,S,k,J,O,z,D,F,G,M,W,P,...L(_)),I("store",["createStore().setSchema({",Z(p(((e,t,a,o)=>[`[${o}]: {`,...m(e,((e,t,a,o)=>`[${o}]: {[${I(B(n),`'${n}'`)}]: ${I(B(t),`'${t}'`)}${T(a)?l:`, [${I(B(r),`'${r}'`)}]: ${f(a)?I(B(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${u};`]),i("proxy",de+": any",`(_: Store, ...args: any[]) => ${de}(${u}, ...args)`),I(u,["{",...w(1),"}"]),[o(...c(0),...b(),`${re} interface ${g} {`,...w(0),"}",l,H(`Creates a ${g} object`),`${re} function create${g}(): ${g};`),o(...c(1),`${re} const create${g}: typeof create${g}Decl = () => {`,...C(),`return Object.freeze(${u});`,"};")]},ze={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},De=(e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))})((e=>{const l=()=>{const l=g(e.getSchemaJson());return!le(l)||d(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=v();if(d(a,(l=>d(e.getCellIds(t,l),(a=>{const n=e.getCell(t,l,a),r=A(o,a,(()=>[te(n),v(),[0],0])),[d,s,[$]]=r,i=A(s,n,(()=>0))+1;return i>$&&(r[2]=[i,n]),x(s,n,i),r[3]++,d==te(n)})))))return l[t]={},y(o,(([e,,[,o],d],s)=>{l[t][s]={[n]:e,...d==I(a)?{[r]:o}:{}}})),1}))?l:{}},t=e=>Ne(l(),e),a=async e=>{let l;try{l=(await import("prettier")).format}catch{l=e=>e}return i(t(e),(e=>_(l(e,ze))))};return Y({getStoreStats:l=>{let t=0,a=0,o=0;const n={};return e.forEachTable(((e,r)=>{t++;let d=0,s=0;const $={};r(((e,t)=>{d++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=d,o+=s,l&&(n[e]={tableRows:d,tableCells:s,rows:$})})),{totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson()),...l?{detail:{tables:n}}:{}}},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));export{De as createTools};
1
+ const e=e=>typeof e,l="",t=e(l),a=e(!0),o=e(0),n="type",r="default",d=(e,l)=>e.every(l),s=(e,l)=>e.sort(l),$=(e,l)=>e.forEach(l),i=(e,l)=>e.map(l),I=e=>e.length,c=e=>0==I(e),b=(e,...l)=>e.push(...l),w=e=>e.pop(),C=(e,...l)=>e.unshift(...l),h=e=>e.shift(),g=JSON.parse,u=isFinite,T=e=>null==e,R=e=>e==t||e==a,f=l=>e(l)==t,p=e=>Array.isArray(e),m=(e,l)=>e?.has(l)??!1,L=e=>[...e?.values()??[]],y=(e,l)=>e?.forEach(l),S=(e,l)=>e?.delete(l),v=e=>new Map(e),k=(e,l)=>e?.get(l),E=(e,l)=>y(e,((e,t)=>l(t,e))),j=(e,l)=>i([...e?.entries()??[]],(([e,t])=>l(t,e))),x=(e,l,t)=>T(t)?(S(e,l),e):e?.set(l,t),A=(e,l,t)=>(m(e,l)||x(e,l,t()),k(e,l)),J=e=>new Set(p(e)||T(e)?e:[e]),O=(e,l)=>e?.add(l),N=e=>[e,e],z=()=>[v(),v()],D=/[^A-Za-z0-9]+/,F=/^( *)\/\*\* *(.*?) *\*\/$/gm,G=(e,l,t)=>e.substring(l,t),M=e=>e.toUpperCase(),W=e=>e.toLowerCase(),P=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return m(e,o)?P(e,l,t,a+1):(x(e,o,t),o)},_=e=>e.replace(F,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,t=l)=>e.join(t),Z=e=>e.flat(1e3),q=(e,l=0)=>U(i(e.split(D),((e,t)=>(t>0||l?M:W)(G(e,0,1))+G(e,1)))),B=e=>M(U((e||" ").split(D),"_")),H=e=>`/** ${e}. */`,K=()=>{const e=z(),t=v(),a=v(),o=v();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>$(a,(a=>O(A(e[l],t,J),a))),(e,l="",a="")=>P(t,e,[l,a]),(e,l,t,o,n,r="")=>P(a,e,[l,t,o,n,r]),(e,l,t)=>P(o,e,p(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>k(o,e)===l?e:P(o,e,l),t=>[...s(j(e[t],((e,l)=>`import {${U(s(L(e)),", ")}} from '${l}';`))),l],()=>j(t,(([e,t],a)=>[H(t),`export type ${a} = ${e};`,l])),e=>j(a,(([t,a,o,n,r],d)=>{const s=e?[`${d}: ${r}(${t}): ${a} => ${o},`]:[`${d}${r}(${t}): ${a};`];return e||C(s,H(n)),b(s,l),s})),()=>j(o,((e,t)=>(e=p(e)?e:[e],b(e,w(e)+";"),[`const ${t} = ${h(e)}`,e,l])))]},V=Object,X=V.keys,Y=V.freeze,ee=(e,l)=>i(V.entries(e),(([e,t])=>l(t,e))),le=e=>c(X(e)),te=l=>{const t=e(l);return R(t)||t==o&&u(l)?t:void 0},ae="the content of",oe="the Store",ne="A function for",re="export",de="listener",se=" | undefined",$e=`Registers a ${de} that will be called`,ie="Represents",Ie=" => void",ce=`${ae} ${oe}`,be="the end of the transaction",we="the specified Row",Ce=(e,l=0)=>`${ie} a Row when ${l?"s":"g"}etting ${ae} the '${e}' Table`,he=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,ge=(e,l)=>`Calls a function for each ${e} in ${l}`,ue=(e,l=oe)=>`Gets whether ${e} exists in ${l}`,Te=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${ne} listening to changes to ${je[e]} in ${je[l]}`,fe=(e,t,a=0)=>`${$e} whenever ${e} in ${t} change`+(a?l:"s"),pe=(e=0)=>`${Ee[e]} ${ce}`,me=e=>`the '${e}' Table`,Le=e=>`${we} in ${me(e)}`,ye=e=>`the '${e}' Cell`,Se=(e,l=0)=>`${Ee[l]} ${ae} ${me(e)}`,ve=(e,l=0)=>`${Ee[l]} ${ae} ${Le(e)}`,ke=(e,l,t=0)=>`${Ee[t]} ${ye(l)} for ${Le(e)}`,Ee=["Gets","Sets","Sets part of","Deletes"],je=[oe,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],xe=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Ae=(e,t=l,a=l)=>`store.${e}(${t})${a?" as "+a:l}`,Je=(e,t=l)=>`fluent(() => ${Ae(e,t)})`,Oe=(e,t=l,a=l)=>`store.${e}(${t?t+", ":l}proxy(${de})${a?", "+a:l})`,Ne=(e,t)=>{if(le(e))return N(l);const[o,d,s,$,i,I,c,b,w,C]=K(),h=`./${q(t)}.d`,g=q(t,1),u=q(g),R=v(),p=t=>ee(e,((e,a)=>t(a,A(R,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ie} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,t,a)=>`'${e}'${T(a)?"?":l}: ${t};`))," ")}}`,Ce(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,Ce(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${Ie}`,Te(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${Ie})${Ie}`,Te(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(B(a),`'${a}'`)))),m=(l,t)=>ee(e[l],((e,l)=>t(l,e[n],e[r],I(B(l),`'${l}'`),q(l,1)))),y=s("Tables",`{${U(p(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${ie} ${ce}`),S=s("TableId",U(p((e=>`'${e}'`))," | "),"A Table Id in "+oe),k=s("TableCallback",`(...[tableId, rowCallback]: ${U(p(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${Ie}]`))," | ")})${Ie}`,Te("a Table Id, and a Row iterator")),j=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(p(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,ne+" returning information about any Cell's changes during a transaction"),J=s("TablesListener",`(${u}: ${g}, getCellChange: ${j}${se})${Ie}`,Re(1)),O=s("TableIdsListener",`(${u}: ${g})${Ie}`,Re(2)),z=s("TableListener",`(${u}: ${g}, tableId: ${S}, getCellChange: ${j}${se})${Ie}`,Re(3)),D=s("RowIdsListener",`(${u}: ${g}, tableId: ${S})${Ie}`,Re(4,3)),F=s("RowListener",`(${u}: ${g}, tableId: ${S}, rowId: Id, getCellChange: ${j}${se})${Ie}`,Re(5,3)),G=s("CellIdsListener",`(${u}: ${g}, tableId: ${S}, rowId: Id)`+Ie,Re(6,5)),M=s("CellListener",`(...[${u}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(p((e=>m(e,((l,t)=>`[${u}: ${g}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${se}, oldCell: ${t}${se}, getCellChange: ${j} | undefined]`)))))," | ")})${Ie}`,Re(7,5)),W=s("InvalidCellListener",`(${u}: ${g}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${Ie}`,Re(8)),P=s("TransactionListener",`(${u}: ${g}, cellsTouched: boolean)${Ie}`,ne+" listening to the completion of a transaction");$("hasTables",l,a,Ae("hasTables"),ue("any Table")),$("getTables",l,y,Ae("getTables"),pe()),$("setTables","tables: "+y,g,Je("setTables","tables"),pe(1)),$("delTables",l,g,Je("delTables"),pe(3)),$("getTableIds",l,S+"[]",Ae("getTableIds",l,S+"[]"),he("Table",oe)),$("forEachTable","tableCallback: "+k,"void",Ae("forEachTable","tableCallback as any"),ge("Table",oe));const _=v();return p(((e,[t,o,n,r,s,i],I,c)=>{d(1,h,t,o,n,r,s,i),$(`has${I}Table`,l,a,Ae("hasTable",c),ue(me(e))),$(`get${I}Table`,l,t,Ae("getTable",c,t),Se(e)),$(`set${I}Table`,"table: "+t,g,Je("setTable",c+", table"),Se(e,1)),$(`del${I}Table`,l,g,Je("delTable",c),Se(e,3)),$(`get${I}RowIds`,l,"Ids",Ae("getRowIds",c),he("Row",me(e))),$(`get${I}SortedRowIds`,`cellId?: ${r}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ae("getSortedRowIds",c+", cellId, descending, offset, limit"),he("Row",me(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Ae("forEachRow",c+", rowCallback as any"),ge("Row",me(e))),$(`has${I}Row`,"rowId: Id",a,Ae("hasRow",c+", rowId"),ue(we,me(e))),$(`get${I}Row`,"rowId: Id",o,Ae("getRow",c+", rowId",o),ve(e)),$(`set${I}Row`,"rowId: Id, row: "+n,g,Je("setRow",c+", rowId, row"),ve(e,1)),$(`add${I}Row`,"row: "+n,"Id"+se,Ae("addRow",c+", row"),"Adds a new Row to "+me(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+n,g,Je("setPartialRow",c+", rowId, partialRow"),ve(e,2)),$(`del${I}Row`,"rowId: Id",g,Je("delRow",c+", rowId"),ve(e,3)),$(`get${I}CellIds`,"rowId: Id",r+"[]",Ae("getCellIds",c+", rowId",r+"[]"),he("Cell",Le(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Ae("forEachCell",c+", rowId, cellCallback as any"),ge("Cell",Le(e))),m(e,((t,o,n,r,d)=>{const s="Map"+q(o,1);x(_,o,s),$(`has${I}${d}Cell`,"rowId: Id",a,Ae("hasCell",`${c}, rowId, ${r}`),ue(ye(t),Le(e)));const i=`${o}${T(n)?se:l}`;$(`get${I}${d}Cell`,"rowId: Id",i,Ae("getCell",`${c}, rowId, ${r}`,i),ke(e,t)),$(`set${I}${d}Cell`,`rowId: Id, cell: ${o} | ${s}`,g,Je("setCell",`${c}, rowId, ${r}, cell as any`),ke(e,t,1)),$(`del${I}${d}Cell`,"rowId: Id",g,Je("delCell",`${c}, rowId, ${r}`),ke(e,t,3))}))})),$("getJson",l,"Json",Ae("getJson"),`${Ee[0]} a string serialization ${ce}`),$("setJson","json: Json",g,Je("setJson","json"),`${Ee[1]} ${ce} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Ae("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",l,g,Je("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",g,Je("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${de}: ${J}, mutator?: boolean`,"Id",Oe("addTablesListener",l,"mutator"),`${$e} whenever ${ce} changes`),$("addTableIdsListener",`${de}: ${O}, mutator?: boolean`,"Id",Oe("addTableIdsListener",l,"mutator"),fe("the Table Ids",oe,1)),$("addTableListener",`tableId: ${S} | null, ${de}: ${z}, mutator?: boolean`,"Id",Oe("addTableListener","tableId","mutator"),fe("a Table",oe)),$("addRowIdsListener",`tableId: ${S} | null, ${de}: ${D}, mutator?: boolean`,"Id",Oe("addRowIdsListener","tableId","mutator"),fe("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${S} | null, rowId: IdOrNull, ${de}: ${F}, mutator?: boolean`,"Id",Oe("addRowListener","tableId, rowId","mutator"),fe("a Row","a Table")),$("addCellIdsListener",`tableId: ${S} | null, rowId: IdOrNull, ${de}: ${G}, mutator?: boolean`,"Id",Oe("addCellIdsListener","tableId, rowId","mutator"),fe("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${S} | null, rowId: IdOrNull, cellId: ${U(p(((e,l)=>l[3]))," | ")} | null, ${de}: ${M}, mutator?: boolean`,"Id",Oe("addCellListener","tableId, rowId, cellId","mutator"),fe("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${de}: ${W}, mutator?: boolean`,"Id",Oe("addCellListener","tableId, rowId, cellId","mutator"),$e+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${de}: ${P}`,"Id",Oe("addWillFinishTransactionListener"),`${$e} just before ${be}`),$("addDidFinishTransactionListener",`${de}: ${P}`,"Id",Oe("addDidFinishTransactionListener"),`${$e} just after ${be}`),$("callListener",de+"Id: Id",g,Je("callListener",de+"Id"),`Manually provoke a ${de} to be called`),$("delListener",de+"Id: Id",g,Je("delListener",de+"Id"),`Remove a ${de} that was previously added to ${oe}`),$("getStore",l,"Store","store",Ee[0]+" the underlying Store object"),E(_,((e,l)=>s(l,`(cell: ${e}${se}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(0,"tinybase","CellChange",...xe),d(1,"tinybase","createStore",...xe),d(1,h,g,`create${g} as create${g}Decl`,y,S,k,J,O,z,D,F,G,M,W,P,...L(_)),I("store",["createStore().setSchema({",Z(p(((e,t,a,o)=>[`[${o}]: {`,...m(e,((e,t,a,o)=>`[${o}]: {[${I(B(n),`'${n}'`)}]: ${I(B(t),`'${t}'`)}${T(a)?l:`, [${I(B(r),`'${r}'`)}]: ${f(a)?I(B(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${u};`]),i("proxy",de+": any",`(_: Store, ...args: any[]) => ${de}(${u}, ...args)`),I(u,["{",...w(1),"}"]),[o(...c(0),...b(),`${re} interface ${g} {`,...w(0),"}",l,H(`Creates a ${g} object`),`${re} function create${g}(): ${g};`),o(...c(1),`${re} const create${g}: typeof create${g}Decl = () => {`,...C(),`return Object.freeze(${u});`,"};")]},ze={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},De=(e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))})((e=>{const l=()=>{const l=g(e.getSchemaJson());return!le(l)||d(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=v();if(d(a,(l=>d(e.getCellIds(t,l),(a=>{const n=e.getCell(t,l,a),r=A(o,a,(()=>[te(n),v(),[0],0])),[d,s,[$]]=r,i=A(s,n,(()=>0))+1;return i>$&&(r[2]=[i,n]),x(s,n,i),r[3]++,d==te(n)})))))return l[t]={},y(o,(([e,,[,o],d],s)=>{l[t][s]={[n]:e,...d==I(a)?{[r]:o}:{}}})),1}))?l:{}},t=e=>Ne(l(),e),a=async e=>{let l;try{l=(await import("prettier")).format}catch{l=e=>e}return i(t(e),(e=>_(l(e,ze))))};return Y({getStoreStats:l=>{let t=0,a=0,o=0;const n={};return e.forEachTable(((e,r)=>{t++;let d=0,s=0;const $={};r(((e,t)=>{d++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=d,o+=s,l&&(n[e]={tableRows:d,tableCells:s,rows:$})})),{totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson()),...l?{detail:{tables:n}}:{}}},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));export{De as createTools};
package/lib/tools.js.gz CHANGED
Binary file
package/lib/umd/tools.js CHANGED
@@ -1 +1 @@
1
- var e,l;e=this,l=function(e){"use strict";const l=e=>typeof e,t="",a=l(t),o=l(!0),n=l(0),d="type",r="default",s=(e,l)=>e.every(l),$=(e,l)=>e.sort(l),i=(e,l)=>e.forEach(l),I=(e,l)=>e.map(l),c=e=>e.length,b=e=>0==c(e),w=(e,...l)=>e.push(...l),C=e=>e.pop(),h=(e,...l)=>e.unshift(...l),u=e=>e.shift(),g=JSON.parse,T=isFinite,f=e=>null==e,R=e=>e==a||e==o,p=e=>l(e)==a,m=e=>Array.isArray(e),y=(e,l)=>e?.has(l)??!1,L=e=>[...e?.values()??[]],v=(e,l)=>e?.forEach(l),S=(e,l)=>e?.delete(l),k=e=>new Map(e),E=(e,l)=>e?.get(l),j=(e,l)=>v(e,((e,t)=>l(t,e))),x=(e,l)=>I([...e?.entries()??[]],(([e,t])=>l(t,e))),A=(e,l,t)=>f(t)?(S(e,l),e):e?.set(l,t),J=(e,l,t)=>(y(e,l)||A(e,l,t()),E(e,l)),O=e=>new Set(m(e)||f(e)?e:[e]),N=(e,l)=>e?.add(l),z=e=>[e,e],D=()=>[k(),k()],F=/[^A-Za-z0-9]+/,G=/^( *)\/\*\* *(.*?) *\*\/$/gm,M=(e,l,t)=>e.substring(l,t),W=e=>e.toUpperCase(),P=e=>e.toLowerCase(),_=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return y(e,o)?_(e,l,t,a+1):(A(e,o,t),o)},B=e=>e.replace(G,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,l=t)=>e.join(l),Z=e=>e.flat(1e3),q=(e,l=0)=>U(I(e.split(F),((e,t)=>(t>0||l?W:P)(M(e,0,1))+M(e,1)))),H=e=>W(U(e.split(F),"_")),K=e=>`/** ${e}. */`,V=()=>{const e=D(),l=k(),a=k(),o=k();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>i(a,(a=>N(J(e[l],t,O),a))),(e,t="",a="")=>_(l,e,[t,a]),(e,l,t,o,n,d="")=>_(a,e,[l,t,o,n,d]),(e,l,t)=>_(o,e,m(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>E(o,e)===l?e:_(o,e,l),l=>[...$(x(e[l],((e,l)=>`import {${U($(L(e)),", ")}} from '${l}';`))),t],()=>x(l,(([e,l],a)=>[K(l),`export type ${a} = ${e};`,t])),e=>x(a,(([l,a,o,n,d],r)=>{const s=e?[`${r}: ${d}(${l}): ${a} => ${o},`]:[`${r}${d}(${l}): ${a};`];return e||h(s,K(n)),w(s,t),s})),()=>x(o,((e,l)=>(e=m(e)?e:[e],w(e,C(e)+";"),[`const ${l} = ${u(e)}`,e,t])))]},X=Object,Y=X.keys,ee=X.freeze,le=(e,l)=>I(X.entries(e),(([e,t])=>l(t,e))),te=e=>b(Y(e)),ae=e=>{const t=l(e);return R(t)||t==n&&T(e)?t:void 0},oe="the content of",ne="the Store",de="A function for",re="export",se="listener",$e=" | undefined",ie=`Registers a ${se} that will be called`,Ie="Represents",ce=" => void",be=`${oe} ${ne}`,we="the end of the transaction",Ce="the specified Row",he=(e,l=0)=>`${Ie} a Row when ${l?"s":"g"}etting ${oe} the '${e}' Table`,ue=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,ge=(e,l)=>`Calls a function for each ${e} in ${l}`,Te=(e,l=ne)=>`Gets whether ${e} exists in ${l}`,fe=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${de} listening to changes to ${xe[e]} in ${xe[l]}`,pe=(e,l,t=0)=>`${ie} whenever ${e} in ${l} change`+(t?"":"s"),me=(e=0)=>`${je[e]} ${be}`,ye=e=>`the '${e}' Table`,Le=e=>`${Ce} in ${ye(e)}`,ve=e=>`the '${e}' Cell`,Se=(e,l=0)=>`${je[l]} ${oe} ${ye(e)}`,ke=(e,l=0)=>`${je[l]} ${oe} ${Le(e)}`,Ee=(e,l,t=0)=>`${je[t]} ${ve(l)} for ${Le(e)}`,je=["Gets","Sets","Sets part of","Deletes"],xe=[ne,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],Ae=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Je=(e,l=t,a=t)=>`store.${e}(${l})${a?" as "+a:t}`,Oe=(e,l=t)=>`fluent(() => ${Je(e,l)})`,Ne=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(${se})${a?", "+a:t})`,ze=(e,l)=>{if(te(e))return z(t);const[a,n,s,$,i,I,c,b,w,C]=V(),h=`./${q(l)}.d`,u=q(l,1),g=q(u),T=k(),R=l=>le(e,((e,a)=>l(a,J(T,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${Ie} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,l,a)=>`'${e}'${f(a)?"?":t}: ${l};`))," ")}}`,he(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,he(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${ce}`,fe(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${ce})${ce}`,fe(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(H(a),`'${a}'`)))),m=(l,t)=>le(e[l],((e,l)=>t(l,e[d],e[r],I(H(l),`'${l}'`),q(l,1)))),y=s("Tables",`{${U(R(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${Ie} ${be}`),v=s("TableId",U(R((e=>`'${e}'`))," | "),"A Table Id in "+ne),S=s("TableCallback",`(...[tableId, rowCallback]: ${U(R(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${ce}]`))," | ")})${ce}`,fe("a Table Id, and a Row iterator")),E=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(R(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),x=s("TablesListener",`(${g}: ${u}, getCellChange: ${E}${$e})${ce}`,Re(1)),O=s("TableIdsListener",`(${g}: ${u})${ce}`,Re(2)),N=s("TableListener",`(${g}: ${u}, tableId: ${v}, getCellChange: ${E}${$e})${ce}`,Re(3)),D=s("RowIdsListener",`(${g}: ${u}, tableId: ${v})${ce}`,Re(4,3)),F=s("RowListener",`(${g}: ${u}, tableId: ${v}, rowId: Id, getCellChange: ${E}${$e})${ce}`,Re(5,3)),G=s("CellIdsListener",`(${g}: ${u}, tableId: ${v}, rowId: Id)`+ce,Re(6,5)),M=s("CellListener",`(...[${g}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(R((e=>m(e,((l,t)=>`[${g}: ${u}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${$e}, oldCell: ${t}${$e}, getCellChange: ${E} | undefined]`)))))," | ")})${ce}`,Re(7,5)),W=s("InvalidCellListener",`(${g}: ${u}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${ce}`,Re(8)),P=s("TransactionListener",`(${g}: ${u}, cellsTouched: boolean)${ce}`,de+" listening to the completion of a transaction");$("hasTables",t,o,Je("hasTables"),Te("any Table")),$("getTables",t,y,Je("getTables"),me()),$("setTables","tables: "+y,u,Oe("setTables","tables"),me(1)),$("delTables",t,u,Oe("delTables"),me(3)),$("getTableIds",t,v+"[]",Je("getTableIds",t,v+"[]"),ue("Table",ne)),$("forEachTable","tableCallback: "+S,"void",Je("forEachTable","tableCallback as any"),ge("Table",ne));const _=k();return R(((e,[l,a,d,r,s,i],I,c)=>{n(1,h,l,a,d,r,s,i),$(`has${I}Table`,t,o,Je("hasTable",c),Te(ye(e))),$(`get${I}Table`,t,l,Je("getTable",c,l),Se(e)),$(`set${I}Table`,"table: "+l,u,Oe("setTable",c+", table"),Se(e,1)),$(`del${I}Table`,t,u,Oe("delTable",c),Se(e,3)),$(`get${I}RowIds`,t,"Ids",Je("getRowIds",c),ue("Row",ye(e))),$(`get${I}SortedRowIds`,`cellId?: ${r}, descending?: boolean, offset?: number, limit?: number`,"Ids",Je("getSortedRowIds",c+", cellId, descending, offset, limit"),ue("Row",ye(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Je("forEachRow",c+", rowCallback as any"),ge("Row",ye(e))),$(`has${I}Row`,"rowId: Id",o,Je("hasRow",c+", rowId"),Te(Ce,ye(e))),$(`get${I}Row`,"rowId: Id",a,Je("getRow",c+", rowId",a),ke(e)),$(`set${I}Row`,"rowId: Id, row: "+d,u,Oe("setRow",c+", rowId, row"),ke(e,1)),$(`add${I}Row`,"row: "+d,"Id"+$e,Je("addRow",c+", row"),"Adds a new Row to "+ye(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+d,u,Oe("setPartialRow",c+", rowId, partialRow"),ke(e,2)),$(`del${I}Row`,"rowId: Id",u,Oe("delRow",c+", rowId"),ke(e,3)),$(`get${I}CellIds`,"rowId: Id",r+"[]",Je("getCellIds",c+", rowId",r+"[]"),ue("Cell",Le(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Je("forEachCell",c+", rowId, cellCallback as any"),ge("Cell",Le(e))),m(e,((l,a,n,d,r)=>{const s="Map"+q(a,1);A(_,a,s),$(`has${I}${r}Cell`,"rowId: Id",o,Je("hasCell",`${c}, rowId, ${d}`),Te(ve(l),Le(e)));const i=`${a}${f(n)?$e:t}`;$(`get${I}${r}Cell`,"rowId: Id",i,Je("getCell",`${c}, rowId, ${d}`,i),Ee(e,l)),$(`set${I}${r}Cell`,`rowId: Id, cell: ${a} | ${s}`,u,Oe("setCell",`${c}, rowId, ${d}, cell as any`),Ee(e,l,1)),$(`del${I}${r}Cell`,"rowId: Id",u,Oe("delCell",`${c}, rowId, ${d}`),Ee(e,l,3))}))})),$("getJson",t,"Json",Je("getJson"),`${je[0]} a string serialization ${be}`),$("setJson","json: Json",u,Oe("setJson","json"),`${je[1]} ${be} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Je("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",t,u,Oe("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",u,Oe("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${se}: ${x}, mutator?: boolean`,"Id",Ne("addTablesListener",t,"mutator"),`${ie} whenever ${be} changes`),$("addTableIdsListener",`${se}: ${O}, mutator?: boolean`,"Id",Ne("addTableIdsListener",t,"mutator"),pe("the Table Ids",ne,1)),$("addTableListener",`tableId: ${v} | null, ${se}: ${N}, mutator?: boolean`,"Id",Ne("addTableListener","tableId","mutator"),pe("a Table",ne)),$("addRowIdsListener",`tableId: ${v} | null, ${se}: ${D}, mutator?: boolean`,"Id",Ne("addRowIdsListener","tableId","mutator"),pe("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${v} | null, rowId: IdOrNull, ${se}: ${F}, mutator?: boolean`,"Id",Ne("addRowListener","tableId, rowId","mutator"),pe("a Row","a Table")),$("addCellIdsListener",`tableId: ${v} | null, rowId: IdOrNull, ${se}: ${G}, mutator?: boolean`,"Id",Ne("addCellIdsListener","tableId, rowId","mutator"),pe("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${v} | null, rowId: IdOrNull, cellId: ${U(R(((e,l)=>l[3]))," | ")} | null, ${se}: ${M}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),pe("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${se}: ${W}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),ie+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${se}: ${P}`,"Id",Ne("addWillFinishTransactionListener"),`${ie} just before ${we}`),$("addDidFinishTransactionListener",`${se}: ${P}`,"Id",Ne("addDidFinishTransactionListener"),`${ie} just after ${we}`),$("callListener",se+"Id: Id",u,Oe("callListener",se+"Id"),`Manually provoke a ${se} to be called`),$("delListener",se+"Id: Id",u,Oe("delListener",se+"Id"),`Remove a ${se} that was previously added to ${ne}`),$("getStore",t,"Store","store",je[0]+" the underlying Store object"),j(_,((e,l)=>s(l,`(cell: ${e}${$e}) => ${e}`,`Takes a ${e} Cell value and returns another`))),n(0,"tinybase","CellChange",...Ae),n(1,"tinybase","createStore",...Ae),n(1,h,u,`create${u} as create${u}Decl`,y,v,S,x,O,N,D,F,G,M,W,P,...L(_)),I("store",["createStore().setSchema({",Z(R(((e,l,a,o)=>[`[${o}]: {`,...m(e,((e,l,a,o)=>`[${o}]: {[${I(H(d),`'${d}'`)}]: ${I(H(l),`'${l}'`)}${f(a)?t:`, [${I(H(r),`'${r}'`)}]: ${p(a)?I(H(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${g};`]),i("proxy",se+": any",`(_: Store, ...args: any[]) => ${se}(${g}, ...args)`),I(g,["{",...w(1),"}"]),[a(...c(0),...b(),`${re} interface ${u} {`,...w(0),"}",t,K(`Creates a ${u} object`),`${re} function create${u}(): ${u};`),a(...c(1),`${re} const create${u}: typeof create${u}Decl = () => {`,...C(),`return Object.freeze(${g});`,"};")]},De={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Fe=(e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))})((e=>{const l=()=>{const l=g(e.getSchemaJson());return!te(l)||s(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=k();if(s(a,(l=>s(e.getCellIds(t,l),(a=>{const n=e.getCell(t,l,a),d=J(o,a,(()=>[ae(n),k(),[0],0])),[r,s,[$]]=d,i=J(s,n,(()=>0))+1;return i>$&&(d[2]=[i,n]),A(s,n,i),d[3]++,r==ae(n)})))))return l[t]={},v(o,(([e,,[,o],n],s)=>{l[t][s]={[d]:e,...n==c(a)?{[r]:o}:{}}})),1}))?l:{}},t=e=>ze(l(),e),a=async e=>{let l;try{l=(await import("prettier")).format}catch{l=e=>e}return I(t(e),(e=>B(l(e,De))))};return ee({getStoreStats:l=>{let t=0,a=0,o=0;const n={};return e.forEachTable(((e,d)=>{t++;let r=0,s=0;const $={};d(((e,t)=>{r++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=r,o+=s,l&&(n[e]={tableRows:r,tableCells:s,rows:$})})),{totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson()),...l?{detail:{tables:n}}:{}}},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));e.createTools=Fe},"object"==typeof exports&&"undefined"!=typeof module?l(exports):"function"==typeof define&&define.amd?define(["exports"],l):l((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
1
+ var e,l;e=this,l=function(e){"use strict";const l=e=>typeof e,t="",a=l(t),o=l(!0),n=l(0),d="type",r="default",s=(e,l)=>e.every(l),$=(e,l)=>e.sort(l),i=(e,l)=>e.forEach(l),I=(e,l)=>e.map(l),c=e=>e.length,b=e=>0==c(e),w=(e,...l)=>e.push(...l),C=e=>e.pop(),h=(e,...l)=>e.unshift(...l),u=e=>e.shift(),g=JSON.parse,T=isFinite,f=e=>null==e,R=e=>e==a||e==o,p=e=>l(e)==a,m=e=>Array.isArray(e),y=(e,l)=>e?.has(l)??!1,L=e=>[...e?.values()??[]],v=(e,l)=>e?.forEach(l),S=(e,l)=>e?.delete(l),k=e=>new Map(e),E=(e,l)=>e?.get(l),j=(e,l)=>v(e,((e,t)=>l(t,e))),x=(e,l)=>I([...e?.entries()??[]],(([e,t])=>l(t,e))),A=(e,l,t)=>f(t)?(S(e,l),e):e?.set(l,t),J=(e,l,t)=>(y(e,l)||A(e,l,t()),E(e,l)),O=e=>new Set(m(e)||f(e)?e:[e]),N=(e,l)=>e?.add(l),z=e=>[e,e],D=()=>[k(),k()],F=/[^A-Za-z0-9]+/,G=/^( *)\/\*\* *(.*?) *\*\/$/gm,M=(e,l,t)=>e.substring(l,t),W=e=>e.toUpperCase(),P=e=>e.toLowerCase(),_=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return y(e,o)?_(e,l,t,a+1):(A(e,o,t),o)},B=e=>e.replace(G,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,l=t)=>e.join(l),Z=e=>e.flat(1e3),q=(e,l=0)=>U(I(e.split(F),((e,t)=>(t>0||l?W:P)(M(e,0,1))+M(e,1)))),H=e=>W(U((e||" ").split(F),"_")),K=e=>`/** ${e}. */`,V=()=>{const e=D(),l=k(),a=k(),o=k();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>i(a,(a=>N(J(e[l],t,O),a))),(e,t="",a="")=>_(l,e,[t,a]),(e,l,t,o,n,d="")=>_(a,e,[l,t,o,n,d]),(e,l,t)=>_(o,e,m(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>E(o,e)===l?e:_(o,e,l),l=>[...$(x(e[l],((e,l)=>`import {${U($(L(e)),", ")}} from '${l}';`))),t],()=>x(l,(([e,l],a)=>[K(l),`export type ${a} = ${e};`,t])),e=>x(a,(([l,a,o,n,d],r)=>{const s=e?[`${r}: ${d}(${l}): ${a} => ${o},`]:[`${r}${d}(${l}): ${a};`];return e||h(s,K(n)),w(s,t),s})),()=>x(o,((e,l)=>(e=m(e)?e:[e],w(e,C(e)+";"),[`const ${l} = ${u(e)}`,e,t])))]},X=Object,Y=X.keys,ee=X.freeze,le=(e,l)=>I(X.entries(e),(([e,t])=>l(t,e))),te=e=>b(Y(e)),ae=e=>{const t=l(e);return R(t)||t==n&&T(e)?t:void 0},oe="the content of",ne="the Store",de="A function for",re="export",se="listener",$e=" | undefined",ie=`Registers a ${se} that will be called`,Ie="Represents",ce=" => void",be=`${oe} ${ne}`,we="the end of the transaction",Ce="the specified Row",he=(e,l=0)=>`${Ie} a Row when ${l?"s":"g"}etting ${oe} the '${e}' Table`,ue=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,ge=(e,l)=>`Calls a function for each ${e} in ${l}`,Te=(e,l=ne)=>`Gets whether ${e} exists in ${l}`,fe=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${de} listening to changes to ${xe[e]} in ${xe[l]}`,pe=(e,l,a=0)=>`${ie} whenever ${e} in ${l} change`+(a?t:"s"),me=(e=0)=>`${je[e]} ${be}`,ye=e=>`the '${e}' Table`,Le=e=>`${Ce} in ${ye(e)}`,ve=e=>`the '${e}' Cell`,Se=(e,l=0)=>`${je[l]} ${oe} ${ye(e)}`,ke=(e,l=0)=>`${je[l]} ${oe} ${Le(e)}`,Ee=(e,l,t=0)=>`${je[t]} ${ve(l)} for ${Le(e)}`,je=["Gets","Sets","Sets part of","Deletes"],xe=[ne,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],Ae=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Je=(e,l=t,a=t)=>`store.${e}(${l})${a?" as "+a:t}`,Oe=(e,l=t)=>`fluent(() => ${Je(e,l)})`,Ne=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(${se})${a?", "+a:t})`,ze=(e,l)=>{if(te(e))return z(t);const[a,n,s,$,i,I,c,b,w,C]=V(),h=`./${q(l)}.d`,u=q(l,1),g=q(u),T=k(),R=l=>le(e,((e,a)=>l(a,J(T,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${Ie} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,l,a)=>`'${e}'${f(a)?"?":t}: ${l};`))," ")}}`,he(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,he(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${ce}`,fe(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${ce})${ce}`,fe(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(H(a),`'${a}'`)))),m=(l,t)=>le(e[l],((e,l)=>t(l,e[d],e[r],I(H(l),`'${l}'`),q(l,1)))),y=s("Tables",`{${U(R(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${Ie} ${be}`),v=s("TableId",U(R((e=>`'${e}'`))," | "),"A Table Id in "+ne),S=s("TableCallback",`(...[tableId, rowCallback]: ${U(R(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${ce}]`))," | ")})${ce}`,fe("a Table Id, and a Row iterator")),E=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(R(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),x=s("TablesListener",`(${g}: ${u}, getCellChange: ${E}${$e})${ce}`,Re(1)),O=s("TableIdsListener",`(${g}: ${u})${ce}`,Re(2)),N=s("TableListener",`(${g}: ${u}, tableId: ${v}, getCellChange: ${E}${$e})${ce}`,Re(3)),D=s("RowIdsListener",`(${g}: ${u}, tableId: ${v})${ce}`,Re(4,3)),F=s("RowListener",`(${g}: ${u}, tableId: ${v}, rowId: Id, getCellChange: ${E}${$e})${ce}`,Re(5,3)),G=s("CellIdsListener",`(${g}: ${u}, tableId: ${v}, rowId: Id)`+ce,Re(6,5)),M=s("CellListener",`(...[${g}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(R((e=>m(e,((l,t)=>`[${g}: ${u}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${$e}, oldCell: ${t}${$e}, getCellChange: ${E} | undefined]`)))))," | ")})${ce}`,Re(7,5)),W=s("InvalidCellListener",`(${g}: ${u}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${ce}`,Re(8)),P=s("TransactionListener",`(${g}: ${u}, cellsTouched: boolean)${ce}`,de+" listening to the completion of a transaction");$("hasTables",t,o,Je("hasTables"),Te("any Table")),$("getTables",t,y,Je("getTables"),me()),$("setTables","tables: "+y,u,Oe("setTables","tables"),me(1)),$("delTables",t,u,Oe("delTables"),me(3)),$("getTableIds",t,v+"[]",Je("getTableIds",t,v+"[]"),ue("Table",ne)),$("forEachTable","tableCallback: "+S,"void",Je("forEachTable","tableCallback as any"),ge("Table",ne));const _=k();return R(((e,[l,a,d,r,s,i],I,c)=>{n(1,h,l,a,d,r,s,i),$(`has${I}Table`,t,o,Je("hasTable",c),Te(ye(e))),$(`get${I}Table`,t,l,Je("getTable",c,l),Se(e)),$(`set${I}Table`,"table: "+l,u,Oe("setTable",c+", table"),Se(e,1)),$(`del${I}Table`,t,u,Oe("delTable",c),Se(e,3)),$(`get${I}RowIds`,t,"Ids",Je("getRowIds",c),ue("Row",ye(e))),$(`get${I}SortedRowIds`,`cellId?: ${r}, descending?: boolean, offset?: number, limit?: number`,"Ids",Je("getSortedRowIds",c+", cellId, descending, offset, limit"),ue("Row",ye(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Je("forEachRow",c+", rowCallback as any"),ge("Row",ye(e))),$(`has${I}Row`,"rowId: Id",o,Je("hasRow",c+", rowId"),Te(Ce,ye(e))),$(`get${I}Row`,"rowId: Id",a,Je("getRow",c+", rowId",a),ke(e)),$(`set${I}Row`,"rowId: Id, row: "+d,u,Oe("setRow",c+", rowId, row"),ke(e,1)),$(`add${I}Row`,"row: "+d,"Id"+$e,Je("addRow",c+", row"),"Adds a new Row to "+ye(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+d,u,Oe("setPartialRow",c+", rowId, partialRow"),ke(e,2)),$(`del${I}Row`,"rowId: Id",u,Oe("delRow",c+", rowId"),ke(e,3)),$(`get${I}CellIds`,"rowId: Id",r+"[]",Je("getCellIds",c+", rowId",r+"[]"),ue("Cell",Le(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Je("forEachCell",c+", rowId, cellCallback as any"),ge("Cell",Le(e))),m(e,((l,a,n,d,r)=>{const s="Map"+q(a,1);A(_,a,s),$(`has${I}${r}Cell`,"rowId: Id",o,Je("hasCell",`${c}, rowId, ${d}`),Te(ve(l),Le(e)));const i=`${a}${f(n)?$e:t}`;$(`get${I}${r}Cell`,"rowId: Id",i,Je("getCell",`${c}, rowId, ${d}`,i),Ee(e,l)),$(`set${I}${r}Cell`,`rowId: Id, cell: ${a} | ${s}`,u,Oe("setCell",`${c}, rowId, ${d}, cell as any`),Ee(e,l,1)),$(`del${I}${r}Cell`,"rowId: Id",u,Oe("delCell",`${c}, rowId, ${d}`),Ee(e,l,3))}))})),$("getJson",t,"Json",Je("getJson"),`${je[0]} a string serialization ${be}`),$("setJson","json: Json",u,Oe("setJson","json"),`${je[1]} ${be} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Je("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",t,u,Oe("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",u,Oe("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${se}: ${x}, mutator?: boolean`,"Id",Ne("addTablesListener",t,"mutator"),`${ie} whenever ${be} changes`),$("addTableIdsListener",`${se}: ${O}, mutator?: boolean`,"Id",Ne("addTableIdsListener",t,"mutator"),pe("the Table Ids",ne,1)),$("addTableListener",`tableId: ${v} | null, ${se}: ${N}, mutator?: boolean`,"Id",Ne("addTableListener","tableId","mutator"),pe("a Table",ne)),$("addRowIdsListener",`tableId: ${v} | null, ${se}: ${D}, mutator?: boolean`,"Id",Ne("addRowIdsListener","tableId","mutator"),pe("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${v} | null, rowId: IdOrNull, ${se}: ${F}, mutator?: boolean`,"Id",Ne("addRowListener","tableId, rowId","mutator"),pe("a Row","a Table")),$("addCellIdsListener",`tableId: ${v} | null, rowId: IdOrNull, ${se}: ${G}, mutator?: boolean`,"Id",Ne("addCellIdsListener","tableId, rowId","mutator"),pe("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${v} | null, rowId: IdOrNull, cellId: ${U(R(((e,l)=>l[3]))," | ")} | null, ${se}: ${M}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),pe("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${se}: ${W}, mutator?: boolean`,"Id",Ne("addCellListener","tableId, rowId, cellId","mutator"),ie+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${se}: ${P}`,"Id",Ne("addWillFinishTransactionListener"),`${ie} just before ${we}`),$("addDidFinishTransactionListener",`${se}: ${P}`,"Id",Ne("addDidFinishTransactionListener"),`${ie} just after ${we}`),$("callListener",se+"Id: Id",u,Oe("callListener",se+"Id"),`Manually provoke a ${se} to be called`),$("delListener",se+"Id: Id",u,Oe("delListener",se+"Id"),`Remove a ${se} that was previously added to ${ne}`),$("getStore",t,"Store","store",je[0]+" the underlying Store object"),j(_,((e,l)=>s(l,`(cell: ${e}${$e}) => ${e}`,`Takes a ${e} Cell value and returns another`))),n(0,"tinybase","CellChange",...Ae),n(1,"tinybase","createStore",...Ae),n(1,h,u,`create${u} as create${u}Decl`,y,v,S,x,O,N,D,F,G,M,W,P,...L(_)),I("store",["createStore().setSchema({",Z(R(((e,l,a,o)=>[`[${o}]: {`,...m(e,((e,l,a,o)=>`[${o}]: {[${I(H(d),`'${d}'`)}]: ${I(H(l),`'${l}'`)}${f(a)?t:`, [${I(H(r),`'${r}'`)}]: ${p(a)?I(H(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${g};`]),i("proxy",se+": any",`(_: Store, ...args: any[]) => ${se}(${g}, ...args)`),I(g,["{",...w(1),"}"]),[a(...c(0),...b(),`${re} interface ${u} {`,...w(0),"}",t,K(`Creates a ${u} object`),`${re} function create${u}(): ${u};`),a(...c(1),`${re} const create${u}: typeof create${u}Decl = () => {`,...C(),`return Object.freeze(${g});`,"};")]},De={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Fe=(e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))})((e=>{const l=()=>{const l=g(e.getSchemaJson());return!te(l)||s(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=k();if(s(a,(l=>s(e.getCellIds(t,l),(a=>{const n=e.getCell(t,l,a),d=J(o,a,(()=>[ae(n),k(),[0],0])),[r,s,[$]]=d,i=J(s,n,(()=>0))+1;return i>$&&(d[2]=[i,n]),A(s,n,i),d[3]++,r==ae(n)})))))return l[t]={},v(o,(([e,,[,o],n],s)=>{l[t][s]={[d]:e,...n==c(a)?{[r]:o}:{}}})),1}))?l:{}},t=e=>ze(l(),e),a=async e=>{let l;try{l=(await import("prettier")).format}catch{l=e=>e}return I(t(e),(e=>B(l(e,De))))};return ee({getStoreStats:l=>{let t=0,a=0,o=0;const n={};return e.forEachTable(((e,d)=>{t++;let r=0,s=0;const $={};d(((e,t)=>{r++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=r,o+=s,l&&(n[e]={tableRows:r,tableCells:s,rows:$})})),{totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson()),...l?{detail:{tables:n}}:{}}},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));e.createTools=Fe},"object"==typeof exports&&"undefined"!=typeof module?l(exports):"function"==typeof define&&define.amd?define(["exports"],l):l((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
Binary file
@@ -1 +1 @@
1
- var e,l;e=this,l=function(e){"use strict";const l=e=>typeof e,t="",a=l(t),o=l(!0),n=l(0),r="type",d="default",s=(e,l)=>e.every(l),$=(e,l)=>e.sort(l),i=(e,l)=>e.forEach(l),I=(e,l)=>e.map(l),c=e=>e.length,b=e=>0==c(e),w=(e,...l)=>e.push(...l),u=e=>e.pop(),h=(e,...l)=>e.unshift(...l),C=e=>e.shift(),g=JSON.parse,f=isFinite,T=e=>null==e,p=e=>e==a||e==o,R=e=>l(e)==a,m=e=>Array.isArray(e),v=(e,l)=>{var t;return null!=(t=null==e?void 0:e.has(l))&&t},y=e=>{var l;return[...null!=(l=null==e?void 0:e.values())?l:[]]},L=(e,l)=>null==e?void 0:e.forEach(l),S=(e,l)=>null==e?void 0:e.delete(l),k=e=>new Map(e),j=(e,l)=>null==e?void 0:e.get(l),E=(e,l)=>L(e,((e,t)=>l(t,e))),O=(e,l)=>{var t;return I([...null!=(t=null==e?void 0:e.entries())?t:[]],(([e,t])=>l(t,e)))},x=(e,l,t)=>T(t)?(S(e,l),e):null==e?void 0:e.set(l,t),A=(e,l,t)=>(v(e,l)||x(e,l,t()),j(e,l)),J=e=>new Set(m(e)||T(e)?e:[e]),N=(e,l)=>null==e?void 0:e.add(l),P=e=>[e,e],z=()=>[k(),k()],D=/[^A-Za-z0-9]+/,F=/^( *)\/\*\* *(.*?) *\*\/$/gm,G=(e,l,t)=>e.substring(l,t),M=e=>e.toUpperCase(),W=e=>e.toLowerCase(),_=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return v(e,o)?_(e,l,t,a+1):(x(e,o,t),o)},B=e=>e.replace(F,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,l=t)=>e.join(l),Z=e=>e.flat(1e3),q=(e,l=0)=>U(I(e.split(D),((e,t)=>(t>0||l?M:W)(G(e,0,1))+G(e,1)))),H=e=>M(U(e.split(D),"_")),K=e=>`/** ${e}. */`,V=()=>{const e=z(),l=k(),a=k(),o=k();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>i(a,(a=>N(A(e[l],t,J),a))),(e,t="",a="")=>_(l,e,[t,a]),(e,l,t,o,n,r="")=>_(a,e,[l,t,o,n,r]),(e,l,t)=>_(o,e,m(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>j(o,e)===l?e:_(o,e,l),l=>[...$(O(e[l],((e,l)=>`import {${U($(y(e)),", ")}} from '${l}';`))),t],()=>O(l,(([e,l],a)=>[K(l),`export type ${a} = ${e};`,t])),e=>O(a,(([l,a,o,n,r],d)=>{const s=e?[`${d}: ${r}(${l}): ${a} => ${o},`]:[`${d}${r}(${l}): ${a};`];return e||h(s,K(n)),w(s,t),s})),()=>O(o,((e,l)=>(e=m(e)?e:[e],w(e,u(e)+";"),[`const ${l} = ${C(e)}`,e,t])))]},X=Object,Y=X.keys,ee=X.freeze,le=(e,l)=>I(X.entries(e),(([e,t])=>l(t,e))),te=e=>b(Y(e)),ae=e=>{const t=l(e);return p(t)||t==n&&f(e)?t:void 0},oe=e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))},ne="the content of",re="the Store",de="A function for",se="export",$e="listener",ie=" | undefined",Ie=`Registers a ${$e} that will be called`,ce="Represents",be=" => void",we=`${ne} ${re}`,ue="the end of the transaction",he="the specified Row",Ce=(e,l=0)=>`${ce} a Row when ${l?"s":"g"}etting ${ne} the '${e}' Table`,ge=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,fe=(e,l)=>`Calls a function for each ${e} in ${l}`,Te=(e,l=re)=>`Gets whether ${e} exists in ${l}`,pe=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${de} listening to changes to ${xe[e]} in ${xe[l]}`,me=(e,l,t=0)=>`${Ie} whenever ${e} in ${l} change`+(t?"":"s"),ve=(e=0)=>`${Oe[e]} ${we}`,ye=e=>`the '${e}' Table`,Le=e=>`${he} in ${ye(e)}`,Se=e=>`the '${e}' Cell`,ke=(e,l=0)=>`${Oe[l]} ${ne} ${ye(e)}`,je=(e,l=0)=>`${Oe[l]} ${ne} ${Le(e)}`,Ee=(e,l,t=0)=>`${Oe[t]} ${Se(l)} for ${Le(e)}`,Oe=["Gets","Sets","Sets part of","Deletes"],xe=[re,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],Ae=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Je=(e,l=t,a=t)=>`store.${e}(${l})${a?" as "+a:t}`,Ne=(e,l=t)=>`fluent(() => ${Je(e,l)})`,Pe=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(${$e})${a?", "+a:t})`,ze=(e,l)=>{if(te(e))return P(t);const[a,n,s,$,i,I,c,b,w,u]=V(),h=`./${q(l)}.d`,C=q(l,1),g=q(C),f=k(),p=l=>le(e,((e,a)=>l(a,A(f,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ce} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,l,a)=>`'${e}'${T(a)?"?":t}: ${l};`))," ")}}`,Ce(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,Ce(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${be}`,pe(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${be})${be}`,pe(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(H(a),`'${a}'`)))),m=(l,t)=>le(e[l],((e,l)=>t(l,e[r],e[d],I(H(l),`'${l}'`),q(l,1)))),v=s("Tables",`{${U(p(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${ce} ${we}`),L=s("TableId",U(p((e=>`'${e}'`))," | "),"A Table Id in "+re),S=s("TableCallback",`(...[tableId, rowCallback]: ${U(p(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${be}]`))," | ")})${be}`,pe("a Table Id, and a Row iterator")),j=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(p(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),O=s("TablesListener",`(${g}: ${C}, getCellChange: ${j}${ie})${be}`,Re(1)),J=s("TableIdsListener",`(${g}: ${C})${be}`,Re(2)),N=s("TableListener",`(${g}: ${C}, tableId: ${L}, getCellChange: ${j}${ie})${be}`,Re(3)),z=s("RowIdsListener",`(${g}: ${C}, tableId: ${L})${be}`,Re(4,3)),D=s("RowListener",`(${g}: ${C}, tableId: ${L}, rowId: Id, getCellChange: ${j}${ie})${be}`,Re(5,3)),F=s("CellIdsListener",`(${g}: ${C}, tableId: ${L}, rowId: Id)`+be,Re(6,5)),G=s("CellListener",`(...[${g}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(p((e=>m(e,((l,t)=>`[${g}: ${C}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${ie}, oldCell: ${t}${ie}, getCellChange: ${j} | undefined]`)))))," | ")})${be}`,Re(7,5)),M=s("InvalidCellListener",`(${g}: ${C}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${be}`,Re(8)),W=s("TransactionListener",`(${g}: ${C}, cellsTouched: boolean)${be}`,de+" listening to the completion of a transaction");$("hasTables",t,o,Je("hasTables"),Te("any Table")),$("getTables",t,v,Je("getTables"),ve()),$("setTables","tables: "+v,C,Ne("setTables","tables"),ve(1)),$("delTables",t,C,Ne("delTables"),ve(3)),$("getTableIds",t,L+"[]",Je("getTableIds",t,L+"[]"),ge("Table",re)),$("forEachTable","tableCallback: "+S,"void",Je("forEachTable","tableCallback as any"),fe("Table",re));const _=k();return p(((e,[l,a,r,d,s,i],I,c)=>{n(1,h,l,a,r,d,s,i),$(`has${I}Table`,t,o,Je("hasTable",c),Te(ye(e))),$(`get${I}Table`,t,l,Je("getTable",c,l),ke(e)),$(`set${I}Table`,"table: "+l,C,Ne("setTable",c+", table"),ke(e,1)),$(`del${I}Table`,t,C,Ne("delTable",c),ke(e,3)),$(`get${I}RowIds`,t,"Ids",Je("getRowIds",c),ge("Row",ye(e))),$(`get${I}SortedRowIds`,`cellId?: ${d}, descending?: boolean, offset?: number, limit?: number`,"Ids",Je("getSortedRowIds",c+", cellId, descending, offset, limit"),ge("Row",ye(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Je("forEachRow",c+", rowCallback as any"),fe("Row",ye(e))),$(`has${I}Row`,"rowId: Id",o,Je("hasRow",c+", rowId"),Te(he,ye(e))),$(`get${I}Row`,"rowId: Id",a,Je("getRow",c+", rowId",a),je(e)),$(`set${I}Row`,"rowId: Id, row: "+r,C,Ne("setRow",c+", rowId, row"),je(e,1)),$(`add${I}Row`,"row: "+r,"Id"+ie,Je("addRow",c+", row"),"Adds a new Row to "+ye(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+r,C,Ne("setPartialRow",c+", rowId, partialRow"),je(e,2)),$(`del${I}Row`,"rowId: Id",C,Ne("delRow",c+", rowId"),je(e,3)),$(`get${I}CellIds`,"rowId: Id",d+"[]",Je("getCellIds",c+", rowId",d+"[]"),ge("Cell",Le(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Je("forEachCell",c+", rowId, cellCallback as any"),fe("Cell",Le(e))),m(e,((l,a,n,r,d)=>{const s="Map"+q(a,1);x(_,a,s),$(`has${I}${d}Cell`,"rowId: Id",o,Je("hasCell",`${c}, rowId, ${r}`),Te(Se(l),Le(e)));const i=`${a}${T(n)?ie:t}`;$(`get${I}${d}Cell`,"rowId: Id",i,Je("getCell",`${c}, rowId, ${r}`,i),Ee(e,l)),$(`set${I}${d}Cell`,`rowId: Id, cell: ${a} | ${s}`,C,Ne("setCell",`${c}, rowId, ${r}, cell as any`),Ee(e,l,1)),$(`del${I}${d}Cell`,"rowId: Id",C,Ne("delCell",`${c}, rowId, ${r}`),Ee(e,l,3))}))})),$("getJson",t,"Json",Je("getJson"),`${Oe[0]} a string serialization ${we}`),$("setJson","json: Json",C,Ne("setJson","json"),`${Oe[1]} ${we} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Je("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",t,C,Ne("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",C,Ne("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${$e}: ${O}, mutator?: boolean`,"Id",Pe("addTablesListener",t,"mutator"),`${Ie} whenever ${we} changes`),$("addTableIdsListener",`${$e}: ${J}, mutator?: boolean`,"Id",Pe("addTableIdsListener",t,"mutator"),me("the Table Ids",re,1)),$("addTableListener",`tableId: ${L} | null, ${$e}: ${N}, mutator?: boolean`,"Id",Pe("addTableListener","tableId","mutator"),me("a Table",re)),$("addRowIdsListener",`tableId: ${L} | null, ${$e}: ${z}, mutator?: boolean`,"Id",Pe("addRowIdsListener","tableId","mutator"),me("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${L} | null, rowId: IdOrNull, ${$e}: ${D}, mutator?: boolean`,"Id",Pe("addRowListener","tableId, rowId","mutator"),me("a Row","a Table")),$("addCellIdsListener",`tableId: ${L} | null, rowId: IdOrNull, ${$e}: ${F}, mutator?: boolean`,"Id",Pe("addCellIdsListener","tableId, rowId","mutator"),me("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${L} | null, rowId: IdOrNull, cellId: ${U(p(((e,l)=>l[3]))," | ")} | null, ${$e}: ${G}, mutator?: boolean`,"Id",Pe("addCellListener","tableId, rowId, cellId","mutator"),me("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${$e}: ${M}, mutator?: boolean`,"Id",Pe("addCellListener","tableId, rowId, cellId","mutator"),Ie+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${$e}: ${W}`,"Id",Pe("addWillFinishTransactionListener"),`${Ie} just before ${ue}`),$("addDidFinishTransactionListener",`${$e}: ${W}`,"Id",Pe("addDidFinishTransactionListener"),`${Ie} just after ${ue}`),$("callListener",$e+"Id: Id",C,Ne("callListener",$e+"Id"),`Manually provoke a ${$e} to be called`),$("delListener",$e+"Id: Id",C,Ne("delListener",$e+"Id"),`Remove a ${$e} that was previously added to ${re}`),$("getStore",t,"Store","store",Oe[0]+" the underlying Store object"),E(_,((e,l)=>s(l,`(cell: ${e}${ie}) => ${e}`,`Takes a ${e} Cell value and returns another`))),n(0,"tinybase","CellChange",...Ae),n(1,"tinybase","createStore",...Ae),n(1,h,C,`create${C} as create${C}Decl`,v,L,S,O,J,N,z,D,F,G,M,W,...y(_)),I("store",["createStore().setSchema({",Z(p(((e,l,a,o)=>[`[${o}]: {`,...m(e,((e,l,a,o)=>`[${o}]: {[${I(H(r),`'${r}'`)}]: ${I(H(l),`'${l}'`)}${T(a)?t:`, [${I(H(d),`'${d}'`)}]: ${R(a)?I(H(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${g};`]),i("proxy",$e+": any",`(_: Store, ...args: any[]) => ${$e}(${g}, ...args)`),I(g,["{",...w(1),"}"]),[a(...c(0),...b(),`${se} interface ${C} {`,...w(0),"}",t,K(`Creates a ${C} object`),`${se} function create${C}(): ${C};`),a(...c(1),`${se} const create${C}: typeof create${C}Decl = () => {`,...u(),`return Object.freeze(${g});`,"};")]};var De=Object.defineProperty,Fe=Object.getOwnPropertySymbols,Ge=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,We=(e,l,t)=>l in e?De(e,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[l]=t,_e=(e,l)=>{for(var t in l||(l={}))Ge.call(l,t)&&We(e,t,l[t]);if(Fe)for(var t of Fe(l))Me.call(l,t)&&We(e,t,l[t]);return e},Be=(e,l,t)=>new Promise(((a,o)=>{var n=e=>{try{d(t.next(e))}catch(e){o(e)}},r=e=>{try{d(t.throw(e))}catch(e){o(e)}},d=e=>e.done?a(e.value):Promise.resolve(e.value).then(n,r);d((t=t.apply(e,l)).next())}));const Qe={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ue=oe((e=>{const l=()=>{const l=g(e.getSchemaJson());return!te(l)||s(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=k();if(s(a,(l=>s(e.getCellIds(t,l),(a=>{const n=e.getCell(t,l,a),r=A(o,a,(()=>[ae(n),k(),[0],0])),[d,s,[$]]=r,i=A(s,n,(()=>0))+1;return i>$&&(r[2]=[i,n]),x(s,n,i),r[3]++,d==ae(n)})))))return l[t]={},L(o,(([e,,[,o],n],s)=>{l[t][s]=_e({[r]:e},n==c(a)?{[d]:o}:{})})),1}))?l:{}},t=e=>ze(l(),e),a=e=>Be(void 0,null,(function*(){let l;try{l=(yield import("prettier")).format}catch(e){l=e=>e}return I(t(e),(e=>B(l(e,Qe))))}));return ee({getStoreStats:l=>{let t=0,a=0,o=0;const n={};return e.forEachTable(((e,r)=>{t++;let d=0,s=0;const $={};r(((e,t)=>{d++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=d,o+=s,l&&(n[e]={tableRows:d,tableCells:s,rows:$})})),_e({totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson())},l?{detail:{tables:n}}:{})},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));e.createTools=Ue},"object"==typeof exports&&"undefined"!=typeof module?l(exports):"function"==typeof define&&define.amd?define(["exports"],l):l((e="undefined"!=typeof globalThis?globalThis:e||self).TinyBaseTools={});
1
+ var e,l;e=this,l=function(e){"use strict";const l=e=>typeof e,t="",a=l(t),o=l(!0),n=l(0),r="type",d="default",s=(e,l)=>e.every(l),$=(e,l)=>e.sort(l),i=(e,l)=>e.forEach(l),I=(e,l)=>e.map(l),c=e=>e.length,b=e=>0==c(e),w=(e,...l)=>e.push(...l),u=e=>e.pop(),h=(e,...l)=>e.unshift(...l),C=e=>e.shift(),g=JSON.parse,f=isFinite,T=e=>null==e,p=e=>e==a||e==o,R=e=>l(e)==a,m=e=>Array.isArray(e),v=(e,l)=>{var t;return null!=(t=null==e?void 0:e.has(l))&&t},y=e=>{var l;return[...null!=(l=null==e?void 0:e.values())?l:[]]},L=(e,l)=>null==e?void 0:e.forEach(l),S=(e,l)=>null==e?void 0:e.delete(l),k=e=>new Map(e),j=(e,l)=>null==e?void 0:e.get(l),E=(e,l)=>L(e,((e,t)=>l(t,e))),O=(e,l)=>{var t;return I([...null!=(t=null==e?void 0:e.entries())?t:[]],(([e,t])=>l(t,e)))},x=(e,l,t)=>T(t)?(S(e,l),e):null==e?void 0:e.set(l,t),A=(e,l,t)=>(v(e,l)||x(e,l,t()),j(e,l)),J=e=>new Set(m(e)||T(e)?e:[e]),N=(e,l)=>null==e?void 0:e.add(l),P=e=>[e,e],z=()=>[k(),k()],D=/[^A-Za-z0-9]+/,F=/^( *)\/\*\* *(.*?) *\*\/$/gm,G=(e,l,t)=>e.substring(l,t),M=e=>e.toUpperCase(),W=e=>e.toLowerCase(),_=(e,l,t,a=1)=>{const o=`${l}${1==a?"":a}`;return v(e,o)?_(e,l,t,a+1):(x(e,o,t),o)},B=e=>e.replace(F,((e,l,t)=>{const a=77-Q(l);return`${l}/**\n${t.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),l+" * $1\n")}${l} */`})),Q=e=>e.length,U=(e,l=t)=>e.join(l),Z=e=>e.flat(1e3),q=(e,l=0)=>U(I(e.split(D),((e,t)=>(t>0||l?M:W)(G(e,0,1))+G(e,1)))),H=e=>M(U((e||" ").split(D),"_")),K=e=>`/** ${e}. */`,V=()=>{const e=z(),l=k(),a=k(),o=k();return[(...e)=>U(Z(e),"\n"),(l,t,...a)=>i(a,(a=>N(A(e[l],t,J),a))),(e,t="",a="")=>_(l,e,[t,a]),(e,l,t,o,n,r="")=>_(a,e,[l,t,o,n,r]),(e,l,t)=>_(o,e,m(t)?[`(${l}) => {`,t,"}"]:[`(${l}) => ${t}`]),(e,l)=>j(o,e)===l?e:_(o,e,l),l=>[...$(O(e[l],((e,l)=>`import {${U($(y(e)),", ")}} from '${l}';`))),t],()=>O(l,(([e,l],a)=>[K(l),`export type ${a} = ${e};`,t])),e=>O(a,(([l,a,o,n,r],d)=>{const s=e?[`${d}: ${r}(${l}): ${a} => ${o},`]:[`${d}${r}(${l}): ${a};`];return e||h(s,K(n)),w(s,t),s})),()=>O(o,((e,l)=>(e=m(e)?e:[e],w(e,u(e)+";"),[`const ${l} = ${C(e)}`,e,t])))]},X=Object,Y=X.keys,ee=X.freeze,le=(e,l)=>I(X.entries(e),(([e,t])=>l(t,e))),te=e=>b(Y(e)),ae=e=>{const t=l(e);return p(t)||t==n&&f(e)?t:void 0},oe=e=>{const l=new WeakMap;return t=>(l.has(t)||l.set(t,e(t)),l.get(t))},ne="the content of",re="the Store",de="A function for",se="export",$e="listener",ie=" | undefined",Ie=`Registers a ${$e} that will be called`,ce="Represents",be=" => void",we=`${ne} ${re}`,ue="the end of the transaction",he="the specified Row",Ce=(e,l=0)=>`${ce} a Row when ${l?"s":"g"}etting ${ne} the '${e}' Table`,ge=(e,l,t=0)=>`Gets ${t?"sorted, paginated":"the"} Ids of the ${e}s in ${l}`,fe=(e,l)=>`Calls a function for each ${e} in ${l}`,Te=(e,l=re)=>`Gets whether ${e} exists in ${l}`,pe=e=>"A function that takes "+e,Re=(e=0,l=0)=>`${de} listening to changes to ${xe[e]} in ${xe[l]}`,me=(e,l,a=0)=>`${Ie} whenever ${e} in ${l} change`+(a?t:"s"),ve=(e=0)=>`${Oe[e]} ${we}`,ye=e=>`the '${e}' Table`,Le=e=>`${he} in ${ye(e)}`,Se=e=>`the '${e}' Cell`,ke=(e,l=0)=>`${Oe[l]} ${ne} ${ye(e)}`,je=(e,l=0)=>`${Oe[l]} ${ne} ${Le(e)}`,Ee=(e,l,t=0)=>`${Oe[t]} ${Se(l)} for ${Le(e)}`,Oe=["Gets","Sets","Sets part of","Deletes"],xe=[re,"anything","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes"],Ae=["ChangedCells","Id","IdOrNull","Ids","InvalidCells","Json","Store"],Je=(e,l=t,a=t)=>`store.${e}(${l})${a?" as "+a:t}`,Ne=(e,l=t)=>`fluent(() => ${Je(e,l)})`,Pe=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(${$e})${a?", "+a:t})`,ze=(e,l)=>{if(te(e))return P(t);const[a,n,s,$,i,I,c,b,w,u]=V(),h=`./${q(l)}.d`,C=q(l,1),g=q(C),f=k(),p=l=>le(e,((e,a)=>l(a,A(f,a,(()=>{const e=q(a,1);return[s(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ce} the '${a}' Table`),s(e+"Row",`{${U(m(a,((e,l,a)=>`'${e}'${T(a)?"?":t}: ${l};`))," ")}}`,Ce(a)),s(e+"RowWhenSet",`{${U(m(a,((e,l)=>`'${e}'?: ${l};`))," ")}}`,Ce(a,1)),s(e+"CellId",U(m(a,(e=>`'${e}'`))," | "),`A Cell Id for the '${a}' Table`),s(e+"CellCallback",`(...[cellId, cell]: ${U(m(a,((e,l)=>`[cellId: '${e}', cell: ${l}]`))," | ")})${be}`,pe(`a Cell Id and value from a Row in the '${a}' Table`)),s(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${be})${be}`,pe(`a Row Id from the '${a}' Table, and a Cell iterator`))]})),q(a,1),I(H(a),`'${a}'`)))),m=(l,t)=>le(e[l],((e,l)=>t(l,e[r],e[d],I(H(l),`'${l}'`),q(l,1)))),v=s("Tables",`{${U(p(((e,l)=>`'${e}'?: ${l[0]};`))," ")}}`,`${ce} ${we}`),L=s("TableId",U(p((e=>`'${e}'`))," | "),"A Table Id in "+re),S=s("TableCallback",`(...[tableId, rowCallback]: ${U(p(((e,l)=>`[tableId: '${e}', forEachRow: (rowCallback: ${l[5]})${be}]`))," | ")})${be}`,pe("a Table Id, and a Row iterator")),j=s("GetCellChange",`(...[tableId, rowId, cellId]: ${U(p(((e,l)=>`[tableId: '${e}', rowId: Id, cellId: ${l[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),O=s("TablesListener",`(${g}: ${C}, getCellChange: ${j}${ie})${be}`,Re(1)),J=s("TableIdsListener",`(${g}: ${C})${be}`,Re(2)),N=s("TableListener",`(${g}: ${C}, tableId: ${L}, getCellChange: ${j}${ie})${be}`,Re(3)),z=s("RowIdsListener",`(${g}: ${C}, tableId: ${L})${be}`,Re(4,3)),D=s("RowListener",`(${g}: ${C}, tableId: ${L}, rowId: Id, getCellChange: ${j}${ie})${be}`,Re(5,3)),F=s("CellIdsListener",`(${g}: ${C}, tableId: ${L}, rowId: Id)`+be,Re(6,5)),G=s("CellListener",`(...[${g}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${U(Z(p((e=>m(e,((l,t)=>`[${g}: ${C}, tableId: '${e}', rowId: Id, cellId: '${l}', newCell: ${t}${ie}, oldCell: ${t}${ie}, getCellChange: ${j} | undefined]`)))))," | ")})${be}`,Re(7,5)),M=s("InvalidCellListener",`(${g}: ${C}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${be}`,Re(8)),W=s("TransactionListener",`(${g}: ${C}, cellsTouched: boolean)${be}`,de+" listening to the completion of a transaction");$("hasTables",t,o,Je("hasTables"),Te("any Table")),$("getTables",t,v,Je("getTables"),ve()),$("setTables","tables: "+v,C,Ne("setTables","tables"),ve(1)),$("delTables",t,C,Ne("delTables"),ve(3)),$("getTableIds",t,L+"[]",Je("getTableIds",t,L+"[]"),ge("Table",re)),$("forEachTable","tableCallback: "+S,"void",Je("forEachTable","tableCallback as any"),fe("Table",re));const _=k();return p(((e,[l,a,r,d,s,i],I,c)=>{n(1,h,l,a,r,d,s,i),$(`has${I}Table`,t,o,Je("hasTable",c),Te(ye(e))),$(`get${I}Table`,t,l,Je("getTable",c,l),ke(e)),$(`set${I}Table`,"table: "+l,C,Ne("setTable",c+", table"),ke(e,1)),$(`del${I}Table`,t,C,Ne("delTable",c),ke(e,3)),$(`get${I}RowIds`,t,"Ids",Je("getRowIds",c),ge("Row",ye(e))),$(`get${I}SortedRowIds`,`cellId?: ${d}, descending?: boolean, offset?: number, limit?: number`,"Ids",Je("getSortedRowIds",c+", cellId, descending, offset, limit"),ge("Row",ye(e),1)),$(`forEach${I}Row`,"rowCallback: "+i,"void",Je("forEachRow",c+", rowCallback as any"),fe("Row",ye(e))),$(`has${I}Row`,"rowId: Id",o,Je("hasRow",c+", rowId"),Te(he,ye(e))),$(`get${I}Row`,"rowId: Id",a,Je("getRow",c+", rowId",a),je(e)),$(`set${I}Row`,"rowId: Id, row: "+r,C,Ne("setRow",c+", rowId, row"),je(e,1)),$(`add${I}Row`,"row: "+r,"Id"+ie,Je("addRow",c+", row"),"Adds a new Row to "+ye(e)),$(`set${I}PartialRow`,"rowId: Id, partialRow: "+r,C,Ne("setPartialRow",c+", rowId, partialRow"),je(e,2)),$(`del${I}Row`,"rowId: Id",C,Ne("delRow",c+", rowId"),je(e,3)),$(`get${I}CellIds`,"rowId: Id",d+"[]",Je("getCellIds",c+", rowId",d+"[]"),ge("Cell",Le(e))),$(`forEach${I}Cell`,"rowId: Id, cellCallback: "+s,"void",Je("forEachCell",c+", rowId, cellCallback as any"),fe("Cell",Le(e))),m(e,((l,a,n,r,d)=>{const s="Map"+q(a,1);x(_,a,s),$(`has${I}${d}Cell`,"rowId: Id",o,Je("hasCell",`${c}, rowId, ${r}`),Te(Se(l),Le(e)));const i=`${a}${T(n)?ie:t}`;$(`get${I}${d}Cell`,"rowId: Id",i,Je("getCell",`${c}, rowId, ${r}`,i),Ee(e,l)),$(`set${I}${d}Cell`,`rowId: Id, cell: ${a} | ${s}`,C,Ne("setCell",`${c}, rowId, ${r}, cell as any`),Ee(e,l,1)),$(`del${I}${d}Cell`,"rowId: Id",C,Ne("delCell",`${c}, rowId, ${r}`),Ee(e,l,3))}))})),$("getJson",t,"Json",Je("getJson"),`${Oe[0]} a string serialization ${we}`),$("setJson","json: Json",C,Ne("setJson","json"),`${Oe[1]} ${we} from a serialized string`),$("transaction","actions: () => Return, doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean","Return",Je("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),$("startTransaction",t,C,Ne("startTransaction"),"Explicitly starts a transaction"),$("finishTransaction","doRollback?: (changedCells: ChangedCells, invalidCells: InvalidCells) => boolean,",C,Ne("finishTransaction","doRollback"),"Explicitly finishes a transaction"),$("addTablesListener",`${$e}: ${O}, mutator?: boolean`,"Id",Pe("addTablesListener",t,"mutator"),`${Ie} whenever ${we} changes`),$("addTableIdsListener",`${$e}: ${J}, mutator?: boolean`,"Id",Pe("addTableIdsListener",t,"mutator"),me("the Table Ids",re,1)),$("addTableListener",`tableId: ${L} | null, ${$e}: ${N}, mutator?: boolean`,"Id",Pe("addTableListener","tableId","mutator"),me("a Table",re)),$("addRowIdsListener",`tableId: ${L} | null, ${$e}: ${z}, mutator?: boolean`,"Id",Pe("addRowIdsListener","tableId","mutator"),me("the Row Ids","a Table",1)),$("addRowListener",`tableId: ${L} | null, rowId: IdOrNull, ${$e}: ${D}, mutator?: boolean`,"Id",Pe("addRowListener","tableId, rowId","mutator"),me("a Row","a Table")),$("addCellIdsListener",`tableId: ${L} | null, rowId: IdOrNull, ${$e}: ${F}, mutator?: boolean`,"Id",Pe("addCellIdsListener","tableId, rowId","mutator"),me("the Cell Ids","a Row",1)),$("addCellListener",`tableId: ${L} | null, rowId: IdOrNull, cellId: ${U(p(((e,l)=>l[3]))," | ")} | null, ${$e}: ${G}, mutator?: boolean`,"Id",Pe("addCellListener","tableId, rowId, cellId","mutator"),me("a Cell","a Row")),$("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${$e}: ${M}, mutator?: boolean`,"Id",Pe("addCellListener","tableId, rowId, cellId","mutator"),Ie+" whenever an invalid Cell change was attempted"),$("addWillFinishTransactionListener",`${$e}: ${W}`,"Id",Pe("addWillFinishTransactionListener"),`${Ie} just before ${ue}`),$("addDidFinishTransactionListener",`${$e}: ${W}`,"Id",Pe("addDidFinishTransactionListener"),`${Ie} just after ${ue}`),$("callListener",$e+"Id: Id",C,Ne("callListener",$e+"Id"),`Manually provoke a ${$e} to be called`),$("delListener",$e+"Id: Id",C,Ne("delListener",$e+"Id"),`Remove a ${$e} that was previously added to ${re}`),$("getStore",t,"Store","store",Oe[0]+" the underlying Store object"),E(_,((e,l)=>s(l,`(cell: ${e}${ie}) => ${e}`,`Takes a ${e} Cell value and returns another`))),n(0,"tinybase","CellChange",...Ae),n(1,"tinybase","createStore",...Ae),n(1,h,C,`create${C} as create${C}Decl`,v,L,S,O,J,N,z,D,F,G,M,W,...y(_)),I("store",["createStore().setSchema({",Z(p(((e,l,a,o)=>[`[${o}]: {`,...m(e,((e,l,a,o)=>`[${o}]: {[${I(H(r),`'${r}'`)}]: ${I(H(l),`'${l}'`)}${T(a)?t:`, [${I(H(d),`'${d}'`)}]: ${R(a)?I(H(a),`'${a}'`):a}`}},`)),"},"]))),"})"]),i("fluent","actions: () => Store",["actions();",`return ${g};`]),i("proxy",$e+": any",`(_: Store, ...args: any[]) => ${$e}(${g}, ...args)`),I(g,["{",...w(1),"}"]),[a(...c(0),...b(),`${se} interface ${C} {`,...w(0),"}",t,K(`Creates a ${C} object`),`${se} function create${C}(): ${C};`),a(...c(1),`${se} const create${C}: typeof create${C}Decl = () => {`,...u(),`return Object.freeze(${g});`,"};")]};var De=Object.defineProperty,Fe=Object.getOwnPropertySymbols,Ge=Object.prototype.hasOwnProperty,Me=Object.prototype.propertyIsEnumerable,We=(e,l,t)=>l in e?De(e,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[l]=t,_e=(e,l)=>{for(var t in l||(l={}))Ge.call(l,t)&&We(e,t,l[t]);if(Fe)for(var t of Fe(l))Me.call(l,t)&&We(e,t,l[t]);return e},Be=(e,l,t)=>new Promise(((a,o)=>{var n=e=>{try{d(t.next(e))}catch(e){o(e)}},r=e=>{try{d(t.throw(e))}catch(e){o(e)}},d=e=>e.done?a(e.value):Promise.resolve(e.value).then(n,r);d((t=t.apply(e,l)).next())}));const Qe={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ue=oe((e=>{const l=()=>{const l=g(e.getSchemaJson());return!te(l)||s(e.getTableIds(),(t=>{const a=e.getRowIds(t),o=k();if(s(a,(l=>s(e.getCellIds(t,l),(a=>{const n=e.getCell(t,l,a),r=A(o,a,(()=>[ae(n),k(),[0],0])),[d,s,[$]]=r,i=A(s,n,(()=>0))+1;return i>$&&(r[2]=[i,n]),x(s,n,i),r[3]++,d==ae(n)})))))return l[t]={},L(o,(([e,,[,o],n],s)=>{l[t][s]=_e({[r]:e},n==c(a)?{[d]:o}:{})})),1}))?l:{}},t=e=>ze(l(),e),a=e=>Be(void 0,null,(function*(){let l;try{l=(yield import("prettier")).format}catch(e){l=e=>e}return I(t(e),(e=>B(l(e,Qe))))}));return ee({getStoreStats:l=>{let t=0,a=0,o=0;const n={};return e.forEachTable(((e,r)=>{t++;let d=0,s=0;const $={};r(((e,t)=>{d++;let a=0;t((()=>a++)),s+=a,l&&($[e]={rowCells:a})})),a+=d,o+=s,l&&(n[e]={tableRows:d,tableCells:s,rows:$})})),_e({totalTables:t,totalRows:a,totalCells:o,jsonLength:Q(e.getJson())},l?{detail:{tables:n}}:{})},getStoreSchema:l,getStoreApi:t,getPrettyStoreApi:a})}));e.createTools=Ue},"object"==typeof exports&&"undefined"!=typeof module?l(exports):"function"==typeof define&&define.amd?define(["exports"],l):l((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": "2.2.3",
3
+ "version": "2.2.5",
4
4
  "author": "jamesgpearce",
5
5
  "repository": "github:tinyplex/tinybase",
6
6
  "license": "MIT",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "devDependencies": {
66
66
  "@babel/cli": "^7.19.3",
67
- "@babel/core": "^7.20.2",
67
+ "@babel/core": "^7.20.5",
68
68
  "@babel/preset-env": "^7.20.2",
69
69
  "@babel/preset-react": "^7.18.6",
70
70
  "@babel/preset-typescript": "^7.18.6",
@@ -73,26 +73,26 @@
73
73
  "@types/asciichart": "^1.5.6",
74
74
  "@types/expect-puppeteer": "^5.0.2",
75
75
  "@types/http-server": "^0.12.1",
76
- "@types/jest": "^29.2.3",
76
+ "@types/jest": "^29.2.4",
77
77
  "@types/jest-environment-puppeteer": "^5.0.3",
78
78
  "@types/less": "^3.0.3",
79
- "@types/node": "^18.11.9",
79
+ "@types/node": "^18.11.14",
80
80
  "@types/puppeteer": "^5.4.7",
81
81
  "@types/react": "^17.0.41",
82
82
  "@types/react-dom": "^17.0.14",
83
83
  "@types/react-test-renderer": "^17.0.1",
84
84
  "@types/tmp": "^0.2.3",
85
- "@typescript-eslint/eslint-plugin": "^5.44.0",
86
- "@typescript-eslint/parser": "^5.44.0",
85
+ "@typescript-eslint/eslint-plugin": "^5.46.1",
86
+ "@typescript-eslint/parser": "^5.46.1",
87
87
  "asciichart": "^1.5.25",
88
88
  "babel-eslint": "^10.1.0",
89
89
  "babel-jest": "^29.3.1",
90
90
  "babel-preset-minify": "^0.5.2",
91
91
  "buffer-replace": "^1.0.0",
92
92
  "country-flag-emoji-json": "^2.0.0",
93
- "cspell": "^6.15.0",
93
+ "cspell": "^6.17.0",
94
94
  "esbuild": "^0.15.15",
95
- "eslint": "^8.28.0",
95
+ "eslint": "^8.29.0",
96
96
  "eslint-config-prettier": "^8.5.0",
97
97
  "eslint-plugin-jest": "^27.1.6",
98
98
  "eslint-plugin-jsdoc": "^39.6.4",
@@ -104,26 +104,26 @@
104
104
  "jest": "^29.3.1",
105
105
  "jest-environment-jsdom": "^29.3.1",
106
106
  "jest-fetch-mock": "^3.0.3",
107
- "jest-puppeteer": "^6.1.1",
107
+ "jest-puppeteer": "^6.2.0",
108
108
  "less": "^4.1.3",
109
- "prettier": "^2.8.0",
109
+ "prettier": "^2.8.1",
110
110
  "puppeteer": "^17.1.3",
111
111
  "react": "^17.0.2",
112
112
  "react-dom": "^17.0.2",
113
113
  "react-test-renderer": "^17.0.2",
114
- "rollup": "^3.4.0",
114
+ "rollup": "^3.7.4",
115
115
  "rollup-plugin-esbuild": "^5.0.0",
116
116
  "rollup-plugin-gzip": "^3.1.0",
117
117
  "rollup-plugin-preserve-shebang": "^1.0.1",
118
118
  "rollup-plugin-prettier": "^3.0.0",
119
119
  "tinydocs": "^0.1.15",
120
120
  "tmp": "^0.2.1",
121
- "ts-unused-exports": "^8.0.0",
122
- "typescript": "4.9.3"
121
+ "ts-unused-exports": "^8.0.5",
122
+ "typescript": "4.9.4"
123
123
  },
124
124
  "peerDependencies": {
125
125
  "prettier": "^2.0.0",
126
- "react": "^17.0.0"
126
+ "react": ">=17.0.0"
127
127
  },
128
128
  "peerDependenciesMeta": {
129
129
  "react": {
package/readme.md CHANGED
@@ -254,4 +254,4 @@ export const createShop: typeof createShopDecl = () => {
254
254
  };
255
255
  ```
256
256
 
257
- <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>3.5kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>7.9kB</em>.</p><p>The <code>ui-react</code> adaptor is just another <em>3.2kB</em>, the developer <a href="https://tinybase.org/api/tools"><code>tools</code></a> module is <em>4.7kB</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>3.5kB</td><td>7.7kB</td><td>33.2kB</td><td>127.2kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/metrics">metrics</a></th><td>1.8kB</td><td>3.5kB</td><td>14.7kB</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.5kB</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.6kB</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.4kB</td><td>2.8kB</td><td>11.3kB</td><td>33.0kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/persisters">persisters</a></th><td>0.8kB</td><td>1.6kB</td><td>5.0kB</td><td>26.8kB</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>7.9kB</td><td>18.4kB</td><td>81.0kB</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,249</td><td>1,249</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,353</td><td>1,353</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>511</td><td>511</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>471</td><td>471</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">2,157</td></tr><tr><th class="right">Assertions</th><td colspan="3">11,068</td></tr></tbody></table></div><hr><p><a id="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> and <a href="https://facebook.com/tinybasejs">Facebook</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/2.2.3">NPM</a>.</li><li><a href="https://github.com/tinyplex/tinybase/issues">Issues</a> on <a href="https://github.com/tinyplex/tinybase">GitHub</a>.</li></ul></section><section><h2 id="about">About</h2><p>Building TinyBase was an interesting exercise 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 we hope you enjoy using it!</p></section>
257
+ <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>3.5kB</em> to your app. You can incrementally add the other modules as you need more functionality, or get it all for <em>7.9kB</em>.</p><p>The <code>ui-react</code> adaptor is just another <em>3.2kB</em>, the developer <a href="https://tinybase.org/api/tools"><code>tools</code></a> module is <em>4.7kB</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>3.5kB</td><td>7.7kB</td><td>33.2kB</td><td>127.2kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/metrics">metrics</a></th><td>1.8kB</td><td>3.5kB</td><td>14.7kB</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.5kB</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.6kB</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.4kB</td><td>2.8kB</td><td>11.3kB</td><td>33.0kB</td></tr><tr><th class="right"><a href="https://tinybase.org/api/persisters">persisters</a></th><td>0.8kB</td><td>1.6kB</td><td>5.0kB</td><td>26.8kB</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>7.9kB</td><td>18.4kB</td><td>81.0kB</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,249</td><td>1,249</td><td>100.0%</td></tr><tr><th class="right">Statements</th><td>1,353</td><td>1,353</td><td>100.0%</td></tr><tr><th class="right">Functions</th><td>511</td><td>511</td><td>100.0%</td></tr><tr><th class="right">Branches</th><td>471</td><td>471</td><td>100.0%</td></tr><tr><th class="right">Tests</th><td colspan="3">2,157</td></tr><tr><th class="right">Assertions</th><td colspan="3">11,068</td></tr></tbody></table></div><hr><p><a id="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> and <a href="https://facebook.com/tinybasejs">Facebook</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/2.2.5">NPM</a>.</li><li><a href="https://github.com/tinyplex/tinybase/issues">Issues</a> on <a href="https://github.com/tinyplex/tinybase">GitHub</a>.</li></ul></section><section><h2 id="about">About</h2><p>Building TinyBase was an interesting exercise 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 we hope you enjoy using it!</p></section>