tinybase 3.0.2 → 3.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/tools.d.ts +59 -35
- package/lib/cjs/ui-react.cjs +1 -1
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/tools.d.ts +59 -35
- package/lib/cjs-es6/ui-react.cjs +1 -1
- package/lib/cjs-es6/ui-react.cjs.gz +0 -0
- package/lib/debug/queries.js +4 -3
- package/lib/debug/store.js +7 -6
- package/lib/debug/tinybase.js +8 -7
- package/lib/debug/tools.d.ts +59 -35
- package/lib/debug/tools.js +1637 -727
- package/lib/debug/ui-react.js +30 -28
- package/lib/es6/tools.d.ts +59 -35
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/tools.d.ts +59 -35
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/tools.d.ts +59 -35
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.d.ts +59 -35
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +10 -10
- package/readme.md +14 -14
package/lib/cjs/tools.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=e=>typeof e,a="",l=e(a),t=e(!0),s=e(0),o="type",n="default",d=(e,a)=>e.every(a),r=(e,a)=>e.sort(a),$=(e,a)=>e.forEach(a),i=(e,a)=>e.map(a),u=e=>e.length,I=e=>0==u(e),c=(e,...a)=>e.push(...a),b=e=>e.pop(),w=(e,...a)=>e.unshift(...a),h=e=>e.shift(),g=JSON.parse,C=isFinite,T=(e,a)=>e instanceof a,V=e=>null==e,f=e=>e==l||e==t,R=a=>e(a)==l,m=e=>Array.isArray(e),v=a=>{const l=e(a);return f(l)||l==s&&C(a)?l:void 0},p=(e,a)=>e?.has(a)??!1,L=e=>[...e?.values()??[]],y=(e,a)=>e?.forEach(a),S=(e,a)=>e?.delete(a),k=e=>new Map(e),J=(e,a)=>e?.get(a),E=(e,a)=>y(e,((e,l)=>a(l,e))),A=(e,a)=>i([...e?.entries()??[]],(([e,l])=>a(l,e))),j=(e,a,l)=>V(l)?(S(e,a),e):e?.set(a,l),O=(e,a,l)=>(p(e,a)||j(e,a,l()),J(e,a)),x=e=>new Set(m(e)||V(e)?e:[e]),D=(e,a)=>e?.add(a),N=e=>[e,e],G=()=>[k(),k()],z=/[^A-Za-z]+/,F=/[^A-Za-z0-9]+/,P=/^( *)\/\*\* *(.*?) *\*\/$/gm,W=(e,a,l)=>e.substring(a,l),M=e=>e.toUpperCase(),Z=e=>e.toLowerCase(),_=(e,a,l,t=1)=>{const s=`${a}${1==t?"":t}`;return p(e,s)?_(e,a,l,t+1):(j(e,s,l),s)},Q=e=>e.replace(P,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,l=a)=>e.join(l),B=e=>e.flat(1e3),H=(e,a=0)=>q(i(e.split(F),((e,l)=>(l>0||a?M:Z)(W(e,0,1))+W(e,1)))),K=e=>M(q((e&&!z.test(e[0])?e:" "+e).split(F),"_")),X=e=>`/** ${e}. */`,Y=()=>{const e=G(),l=k(),t=k(),s=k();return[(...e)=>q(B(e),"\n"),(a,l,...t)=>$(t,(t=>D(O(e[a],l,x),t))),(e,a,t)=>_(l,e,[a,t]),(e,a,l,s,o,n="")=>_(t,e,[a,l,s,o,n]),(e,a,l)=>_(s,e,m(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>J(s,e)===a?e:_(s,e,a),l=>[...r(A(e[l],((e,a)=>`import {${q(r(L(e)),", ")}} from '${a}';`))),a],()=>A(l,(([e,l],t)=>[X(l),`export type ${t} = ${e};`,a])),e=>A(t,(([l,t,s,o,n],d)=>{const r=e?[`${d}: ${n}(${l}): ${t} => ${s},`]:[`${d}${n}(${l}): ${t};`];return e||w(r,X(o)),c(r,a),r})),()=>A(s,((e,l)=>(e=m(e)?e:[e],c(e,b(e)+";"),[`const ${l} = ${h(e)}`,e,a])))]},ee=Object,ae=ee.keys,le=ee.freeze,te=e=>T(e,ee)&&e.constructor==ee,se=(e,a)=>i(ee.entries(e),(([e,l])=>a(l,e))),oe=e=>te(e)&&I(ae(e)),ne="the Store",de="A function for",re="export",$e="listener",ie=" | undefined",ue=`Registers a ${$e} that will be called`,Ie="Represents",ce=" => void",be="the end of the transaction",we="the specified Row",he="a string serialization of",ge=(e=0,a=0)=>`the ${De[e]}content of${a?" "+ne:""}`,Ce=(e,a=0,l=0)=>`${Oe[e]} ${ge(a,1)}${l?" when set":""}`,Te=(e,a=0)=>`${Ie} a Row when ${a?"s":"g"}etting ${ge()} the '${e}' Table`,Ve=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,fe=(e,a)=>`Calls a function for each ${e} in ${a}`,Re=(e,a=ne)=>`Gets whether ${e} exists in ${a}`,me=e=>"A function that takes "+e,ve=(e,a=0)=>`${de} listening to changes to ${xe[e]} in ${xe[a]}`,pe=(e,l,t=0)=>`${ue} whenever ${e} in ${l} change`+(t?a:"s"),Le=e=>`the '${e}' Table`,ye=e=>`${we} in ${Le(e)}`,Se=e=>`the '${e}' Cell`,ke=e=>`the '${e}' Value`,Je=(e,a=0)=>`${Oe[a]} ${ge()} ${Le(e)}`,Ee=(e,a=0)=>`${Oe[a]} ${ge()} ${ye(e)}`,Ae=(e,a,l=0)=>`${Oe[l]} ${Se(a)} for ${ye(e)}`,je=(e,a=0)=>`${Oe[a]} ${ke(e)}`,Oe=["Gets","Sets","Sets part of","Deletes",Ie,"Gets "+he,"Sets "+he,ue+" whenever"],xe=[ne,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],De=["","tabular ","keyed value "],Ne=["DoRollback","Id","IdOrNull","Ids","Json","Store"],Ge=(e,l=a,t=a)=>`store.${e}(${l})${t?" as "+t:a}`,ze=(e,l=a)=>`fluent(() => ${Ge(e,l)})`,Fe=(e,l=a,t=a)=>`store.${e}(${l?l+", ":a}proxy(${$e})${t?", "+t:a})`,Pe=(e,l,s)=>{if(oe(e)&&oe(l))return N(a);const[d,r,$,i,u,I,b,w,h,g]=Y(),C=`./${H(s)}.d`,T=H(s,1),f=H(T),m=[],v=k(),p=l=>se(e,((e,t)=>l(t,O(v,t,(()=>{const e=H(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${Ie} the '${t}' Table`),$(e+"Row",`{${q(y(t,((e,l,t)=>`'${e}'${V(t)?"?":a}: ${l};`))," ")}}`,Te(t)),$(e+"RowWhenSet",`{${q(y(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,Te(t,1)),$(e+"CellId",q(y(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(y(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${ce}`,me(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${ce})${ce}`,me(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),H(t,1),I(K(t),`'${t}'`)))),y=(a,l)=>se(e[a],((e,a)=>l(a,e[o],e[n],I(K(a),`'${a}'`),H(a,1)))),S=e=>se(l,((a,l)=>e(l,a[o],a[n],I(K(l),`'${l}'`),H(l,1))));if(r(1,C,T,`create${T} as create${T}Decl`),!oe(e)){const e=$("Tables",`{${q(p(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Ce(4,1)),l=$("TableId",q(p((e=>`'${e}'`))," | "),"A Table Id in "+ne),s=$("TableCallback",`(...[tableId, rowCallback]: ${q(p(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${ce}]`))," | ")})${ce}`,me("a Table Id, and a Row iterator")),d=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(p(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${f}: ${T}, getCellChange: ${d}${ie})${ce}`,ve(1)),b=$("TableIdsListener",`(${f}: ${T})${ce}`,ve(2)),w=$("TableListener",`(${f}: ${T}, tableId: ${l}, getCellChange: ${d}${ie})${ce}`,ve(3)),h=$("RowIdsListener",`(${f}: ${T}, tableId: ${l})`+ce,ve(4,3)),g=$("RowListener",`(${f}: ${T}, tableId: ${l}, rowId: Id, getCellChange: ${d}${ie})${ce}`,ve(5,3)),v=$("CellIdsListener",`(${f}: ${T}, tableId: ${l}, rowId: Id)`+ce,ve(6,5)),S=$("CellListener",`(...[${f}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(B(p((e=>y(e,((a,l)=>`[${f}: ${T}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${ie}, oldCell: ${l}${ie}, getCellChange: ${d} | undefined]`)))))," | ")})${ce}`,ve(7,5)),J=$("InvalidCellListener",`(${f}: ${T}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${ce}`,ve(8));i("hasTables",a,t,Ge("hasTables"),Re("any Table")),i("getTables",a,e,Ge("getTables"),Ce(0,1)),i("setTables","tables: "+e,T,ze("setTables","tables"),Ce(1,1)),i("delTables",a,T,ze("delTables"),Ce(3,1)),i("getTableIds",a,l+"[]",Ge("getTableIds",a,l+"[]"),Ve("Table",ne)),i("forEachTable","tableCallback: "+s,"void",Ge("forEachTable","tableCallback as any"),fe("Table",ne));const A=k();p(((e,[l,s,o,n,d,$],u,I)=>{r(1,C,l,s,o,n,d,$),i(`has${u}Table`,a,t,Ge("hasTable",I),Re(Le(e))),i(`get${u}Table`,a,l,Ge("getTable",I,l),Je(e)),i(`set${u}Table`,"table: "+l,T,ze("setTable",I+", table"),Je(e,1)),i(`del${u}Table`,a,T,ze("delTable",I),Je(e,3)),i(`get${u}RowIds`,a,"Ids",Ge("getRowIds",I),Ve("Row",Le(e))),i(`get${u}SortedRowIds`,`cellId?: ${n}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ge("getSortedRowIds",I+", cellId, descending, offset, limit"),Ve("Row",Le(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",Ge("forEachRow",I+", rowCallback as any"),fe("Row",Le(e))),i(`has${u}Row`,"rowId: Id",t,Ge("hasRow",I+", rowId"),Re(we,Le(e))),i(`get${u}Row`,"rowId: Id",s,Ge("getRow",I+", rowId",s),Ee(e)),i(`set${u}Row`,"rowId: Id, row: "+o,T,ze("setRow",I+", rowId, row"),Ee(e,1)),i(`add${u}Row`,"row: "+o,"Id"+ie,Ge("addRow",I+", row"),"Adds a new Row to "+Le(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+o,T,ze("setPartialRow",I+", rowId, partialRow"),Ee(e,2)),i(`del${u}Row`,"rowId: Id",T,ze("delRow",I+", rowId"),Ee(e,3)),i(`get${u}CellIds`,"rowId: Id",n+"[]",Ge("getCellIds",I+", rowId",n+"[]"),Ve("Cell",ye(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+d,"void",Ge("forEachCell",I+", rowId, cellCallback as any"),fe("Cell",ye(e))),y(e,((l,s,o,n,d)=>{const r="Map"+H(s,1);j(A,s,r),i(`has${u}${d}Cell`,"rowId: Id",t,Ge("hasCell",`${I}, rowId, ${n}`),Re(Se(l),ye(e)));const $=`${s}${V(o)?ie:a}`;i(`get${u}${d}Cell`,"rowId: Id",$,Ge("getCell",`${I}, rowId, ${n}`,$),Ae(e,l)),i(`set${u}${d}Cell`,`rowId: Id, cell: ${s} | ${r}`,T,ze("setCell",`${I}, rowId, ${n}, cell as any`),Ae(e,l,1)),i(`del${u}${d}Cell`,"rowId: Id",T,ze("delCell",`${I}, rowId, ${n}`),Ae(e,l,3))}))})),i("getTablesJson",a,"Json",Ge("getTablesJson"),Ce(5,1)),i("setTablesJson","tablesJson: Json",T,ze("setTablesJson","tablesJson"),Ce(6,1)),i("addTablesListener",`${$e}: ${u}, mutator?: boolean`,"Id",Fe("addTablesListener",a,"mutator"),Ce(7,1)+" changes"),i("addTableIdsListener",`${$e}: ${b}, mutator?: boolean`,"Id",Fe("addTableIdsListener",a,"mutator"),pe("the Table Ids",ne,1)),i("addTableListener",`tableId: ${l} | null, ${$e}: ${w}, mutator?: boolean`,"Id",Fe("addTableListener","tableId","mutator"),pe("a Table",ne)),i("addRowIdsListener",`tableId: ${l} | null, ${$e}: ${h}, mutator?: boolean`,"Id",Fe("addRowIdsListener","tableId","mutator"),pe("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${l} | null, rowId: IdOrNull, ${$e}: ${g}, mutator?: boolean`,"Id",Fe("addRowListener","tableId, rowId","mutator"),pe("a Row","a Table")),i("addCellIdsListener",`tableId: ${l} | null, rowId: IdOrNull, ${$e}: ${v}, mutator?: boolean`,"Id",Fe("addCellIdsListener","tableId, rowId","mutator"),pe("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${l} | null, rowId: IdOrNull, cellId: ${q(p(((e,a)=>a[3]))," | ")} | null, ${$e}: ${S}, mutator?: boolean`,"Id",Fe("addCellListener","tableId, rowId, cellId","mutator"),pe("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${$e}: ${J}, mutator?: boolean`,"Id",Fe("addInvalidCellListener","tableId, rowId, cellId","mutator"),ue+" whenever an invalid Cell change was attempted"),E(A,((e,a)=>$(a,`(cell: ${e}${ie}) => ${e}`,`Takes a ${e} Cell value and returns another`))),r(1,C,e,l,s,u,b,w,h,g,v,S,J,...L(A)),r(0,"tinybase","CellChange"),c(m,".setTablesSchema({",B(p(((e,l,t,s)=>[`[${s}]: {`,...y(e,((e,l,t,s)=>`[${s}]: {[${I(K(o),`'${o}'`)}]: ${I(K(l),`'${l}'`)}${V(t)?a:`, [${I(K(n),`'${n}'`)}]: ${R(t)?I(K(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!oe(l)){const e=$("Values",`{${q(S(((e,l,t)=>`'${e}'${V(t)?"?":a}: ${l};`))," ")}}`,Ce(4,2)),l=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ce(4,2,1)),s=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+ne),d=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${ce}`,me("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${s}) => ValueChange`,de+" returning information about any Value's changes during a transaction"),b=$("ValuesListener",`(${f}: ${T}, getValueChange: ${u}${ie})`+ce,ve(9)),w=$("ValueIdsListener",`(${f}: ${T})${ce}`,ve(10)),h=$("ValueListener",`(...[${f}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${f}: ${T}, valueId: '${e}', newValue: ${a}${ie}, oldValue: ${a}${ie}, getValueChange: ${u} | undefined]`))," | ")})${ce}`,ve(11)),g=$("InvalidValueListener",`(${f}: ${T}, valueId: Id, invalidValues: any[])${ce}`,ve(12));i("hasValues",a,t,Ge("hasValues"),Re("any Value")),i("getValues",a,e,Ge("getValues",a,e),Ce(0,2)),i("setValues","values: "+l,T,ze("setValues","values"),Ce(1,2)),i("setPartialValues","partialValues: "+l,T,ze("setPartialValues","partialValues"),Ce(2,2)),i("delValues",a,T,ze("delValues"),Ce(3,2)),i("getValueIds",a,s+"[]",Ge("getValueIds",a,s+"[]"),Ve("Value",ne)),i("forEachValue","valueCallback: "+d,"void",Ge("forEachValue","valueCallback as any"),fe("Value",ne)),S(((e,l,s,o,n)=>{i(`has${n}Value`,a,t,Ge("hasValue",o),Re(ke(e))),i(`get${n}Value`,a,l,Ge("getValue",o,l),je(e)),i(`set${n}Value`,"value: "+l,T,ze("setValue",o+", value"),je(e,1)),i(`del${n}Value`,a,T,ze("delValue",o),je(e,3))})),i("getValuesJson",a,"Json",Ge("getValuesJson"),Ce(5,2)),i("setValuesJson","valuesJson: Json",T,ze("setValuesJson","valuesJson"),Ce(6,2)),i("addValuesListener",`${$e}: ${b}, mutator?: boolean`,"Id",Fe("addValuesListener",a,"mutator"),Ce(7,2)+" changes"),i("addValueIdsListener",`${$e}: ${w}, mutator?: boolean`,"Id",Fe("addValueIdsListener",a,"mutator"),pe("the Value Ids",ne,1)),i("addValueListener",`valueId: ${s} | null, ${$e}: ${h}, mutator?: boolean`,"Id",Fe("addValueListener","valueId","mutator"),pe("a Value",ne)),i("addInvalidValueListener",`valueId: IdOrNull, ${$e}: ${g}, mutator?: boolean`,"Id",Fe("addInvalidValueListener","valueId","mutator"),ue+" whenever an invalid Cell change was attempted"),r(1,C,e,l,s,d,b,w,h,g),r(0,"tinybase","ValueChange"),c(m,".setValuesSchema({",S(((e,l,t,s)=>[`[${s}]: {[${I(K(o),`'${o}'`)}]: ${I(K(l),`'${l}'`)}${V(t)?a:`, [${I(K(n),`'${n}'`)}]: ${R(t)?I(K(t),`'${t}'`):t}`}},`])),"})")}r(0,"tinybase",...Ne);const J=$("TransactionListener",`(${f}: ${T}, cellsTouched: boolean, valuesTouched: boolean)${ce}`,de+" listening to the completion of a transaction");return i("getJson",a,"Json",Ge("getJson"),Ce(5)),i("setJson","json: Json",T,ze("setJson","json"),Ce(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",Ge("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",a,T,ze("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",T,ze("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${$e}: ${J}`,"Id",Fe("addWillFinishTransactionListener"),`${ue} just before ${be}`),i("addDidFinishTransactionListener",`${$e}: ${J}`,"Id",Fe("addDidFinishTransactionListener"),`${ue} just after ${be}`),i("callListener",$e+"Id: Id",T,ze("callListener",$e+"Id"),`Manually provoke a ${$e} to be called`),i("delListener",$e+"Id: Id",T,ze("delListener",$e+"Id"),`Remove a ${$e} that was previously added to ${ne}`),i("getStore",a,"Store","store",Oe[0]+" the underlying Store object"),r(1,"tinybase","createStore",...Ne),r(1,C,T,`create${T} as create${T}Decl`,J),I("store",["createStore()",...m]),u("fluent","actions: () => Store",["actions();",`return ${f};`]),u("proxy",$e+": any",`(_: Store, ...args: any[]) => ${$e}(${f}, ...args)`),I(f,["{",...h(1),"}"]),[d(...b(0),...w(),`${re} interface ${T} {`,...h(0),"}",a,X(`Creates a ${T} object`),`${re} function create${T}(): ${T};`),d(...b(1),`${re} const create${T}: typeof create${T}Decl = () => {`,...g(),`return Object.freeze(${f});`,"};")]},We={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Me=(e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))})((e=>{const a=()=>{const a=g(e.getTablesSchemaJson());return!oe(a)||d(e.getTableIds(),(l=>{const t=e.getRowIds(l),s=k();if(d(t,(a=>d(e.getCellIds(l,a),(t=>{const o=e.getCell(l,a,t),n=O(s,t,(()=>[v(o),k(),[0],0])),[d,r,[$]]=n,i=O(r,o,(()=>0))+1;return i>$&&(n[2]=[i,o]),j(r,o,i),n[3]++,d==v(o)})))))return a[l]={},y(s,(([e,,[,s],d],r)=>{a[l][r]={[o]:e,...d==u(t)?{[n]:s}:{}}})),1}))?a:{}},l=()=>{const a=g(e.getValuesSchemaJson());return oe(a)&&e.forEachValue(((e,l)=>{a[e]={[o]:v(l)}})),a},t=e=>Pe(a(),l(),e),s=async e=>{let a;try{a=(await import("prettier")).format}catch{a=e=>e}return i(t(e),(e=>Q(a(e,We))))};return le({getStoreStats:a=>{let l=0,t=0,s=0;const o={};return e.forEachTable(((e,n)=>{l++;let d=0,r=0;const $={};n(((e,l)=>{d++;let t=0;l((()=>t++)),r+=t,a&&($[e]={rowCells:t})})),t+=d,s+=r,a&&(o[e]={tableRows:d,tableCells:r,rows:$})})),{totalTables:l,totalRows:t,totalCells:s,totalValues:u(e.getValueIds()),jsonLength:U(e.getJson()),...a?{detail:{tables:o}}:{}}},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:s,getStore:()=>e})}));exports.createTools=Me;
|
|
1
|
+
"use strict";const e=e=>typeof e,t="",l=e(t),a=e(!0),n=e(0),o="type",r="default",s="Listener",d="get",$="add",c="Ids",i="Table",u=i+"s",I=i+c,b="Row",h=b+c,p="Sorted"+b+c,g="Cell",f=g+c,w="Value",C=w+"s",m=w+c,v=(e,t)=>e.every(t),y=(e,t)=>e.sort(t),R=(e,t)=>e.forEach(t),S=(e,t)=>e.map(t),k=e=>e.length,V=e=>0==k(e),x=(e,t)=>e.filter(t),O=(e,...t)=>e.push(...t),D=e=>e.pop(),T=(e,...t)=>e.unshift(...t),A=e=>e.shift(),N=JSON.parse,P=isFinite,j=(e,t)=>e instanceof t,E=e=>null==e,M=e=>e==l||e==a,z=t=>e(t)==l,G=e=>Array.isArray(e),J=t=>{const l=e(t);return M(l)||l==n&&P(t)?l:void 0},L=(e,t)=>e?.has(t)??!1,W=e=>[...e?.values()??[]],B=(e,t)=>e?.forEach(t),F=(e,t)=>e?.delete(t),U=e=>new Map(e),_=(e,t)=>e?.get(t),Z=(e,t)=>B(e,((e,l)=>t(l,e))),H=(e,t)=>S([...e?.entries()??[]],(([e,l])=>t(l,e))),Q=(e,t,l)=>E(l)?(F(e,t),e):e?.set(t,l),q=(e,t,l)=>(L(e,t)||Q(e,t,l()),_(e,t)),K=e=>e.toUpperCase(),X=e=>e.toLowerCase(),Y="a ",ee="A function for",te="Callback",le="Del",ae="export",ne="Id",oe="Invalid",re="Json",se=X(s),de=" | undefined",$e="Partial",ce=`Registers a ${se} that will be called`,ie="Represents",ue="Set",Ie="[]",be="the Store",he="Transaction",pe=X(he),ge="the end of the "+pe,fe="void",we=" => "+fe,Ce=Y+"string serialization of",me=" ",ve="Gets a callback that can ",ye="the ",Re=(e=0,l=0)=>`the ${Je[e]}content of`+(l?me+be:t),Se=(e=0,l,a=0)=>ze[l]+me+Re(e,1)+(a?" when set":t),ke=(e,t=0)=>ie+` a Row when ${t?"s":"g"}etting ${Re()} the '${e}' `+i,Ve=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,xe=(e,t)=>`Calls a function for each ${e} in `+t,Oe=e=>"A function that takes "+e,De=(e,t=0)=>ee+" listening to changes to "+Ge[e]+" in "+Ge[t],Te=(e,l,a=0)=>ce+" whenever "+Ge[e]+" in "+Ge[l]+" change"+(a?t:"s"),Ae=e=>`the '${e}' `+i,Ne=e=>"the specified Row in "+Ae(e),Pe=(e,t=0)=>ze[t]+` ${Re()} `+Ae(e),je=(e,t=0)=>ze[t]+` ${Re()} `+Ne(e),Ee=(e,t,l=0)=>ze[l]+` the '${t}' Cell for `+Ne(e),Me=(e,t=0)=>ze[t]+` the '${e}' Value`,ze=["Gets","Checks existence of","Sets","Deletes","Sets part of",ie,"Gets "+Ce,"Sets "+Ce,ce+" whenever",ve+"set",ve+"add",ve+"set part of",ve+"delete"],Ge=[be,u,ye+i+me+c,Y+i,ye+b+me+c,Y+b,ye+g+me+c,Y+g,"invalid Cell changes",C,ye+w+me+c,Y+w,"invalid Value changes",ye+"sorted "+b+me+c],Je=[t,"tabular ","keyed value "],Le=e=>new Set(G(e)||E(e)?e:[e]),We=(e,t)=>e?.add(t),Be=/[^A-Za-z]+/,Fe=/[^A-Za-z0-9]+/,Ue=/^( *)\/\*\* *(.*?) *\*\/$/gm,_e=(e,t,l)=>e.substring(t,l),Ze=e=>e.includes(","),He=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return L(e,n)?He(e,t,l,a+1):(Q(e,n,l),n)},Qe=e=>e.replace(Ue,((e,t,l)=>{const a=77-qe(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),qe=e=>e.length,Ke=(e,l=t)=>e.join(l),Xe=e=>e.flat(1e3),Ye=(e,t=0)=>Ke(S(e.split(Fe),((e,l)=>(l>0||t?K:X)(_e(e,0,1))+_e(e,1)))),et=e=>K(Ke((e&&!Be.test(e[0])?e:" "+e).split(Fe),"_")),tt=e=>`/** ${e}. */`,lt=(...e)=>Ke(x(e,(e=>e)),", "),at=()=>{const e=[U(),U(),U(),U()],l=U(),a=U();return[(...e)=>Ke(Xe(e),"\n"),(t,l,...a)=>R(a,(a=>R([0,1],(n=>(t??n)==n?We(q(e[n],l,Le),a):0)))),(e,t,a)=>He(l,e,[t,a]),(e,t,l)=>He(a,e,G(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>_(a,e)===t?e:He(a,e,t),(l=0)=>S([...y(H(e[l],((e,t)=>`import {${Ke(y(W(e)),", ")}} from '${t}';`)),((e,t)=>Ze(e)!=Ze(t)?Ze(e)?-1:1:e>t?1:-1)),t],(e=>e.replace("{React}","React"))),()=>H(l,(([e,l],a)=>[tt(l),`${ae} type ${a} = ${e};`,t])),()=>H(a,((e,l)=>(e=G(e)?e:[e],O(e,D(e)+";"),[`const ${l} = ${A(e)}`,e,t])))]},nt=Object,ot=nt.keys,rt=nt.freeze,st=e=>j(e,nt)&&e.constructor==nt,dt=(e,t)=>S(nt.entries(e),(([e,l])=>t(l,e))),$t=e=>st(e)&&V(ot(e)),ct=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},it=(e,t,l)=>[t=>dt(e,((e,a)=>t(a,Ye(a,1),l(et(a),`'${a}'`)))),(t,a)=>dt(e[t],((e,t)=>a(t,e[o],e[r],l(et(t),`'${t}'`),Ye(t,1)))),e=>dt(t,((t,a)=>e(a,t[o],t[r],l(et(a),`'${a}'`),Ye(a,1))))],ut=[d,"has","set","del","set","forEach",$,t],It=(e,l=t,a=t)=>`store.${e}(${l})`+(a?" as "+a:t),bt=(e,l=t)=>`fluent(() => ${It(e,l)})`,ht=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(listener)${a?", "+a:t})`,pt=(e,l,n)=>{const[d,v,y,S,k,V,x,D]=at(),[A,N,P]=it(e,l,k),j=U(),M=(e=0)=>H(j,(([l,a,n,o,r],s)=>{const d=e?[s+`: ${r}(${l}): ${a} => ${n},`]:[s+r+`(${l}): ${a};`];return e||T(d,tt(o)),O(d,t),d})),G=(e,l,a,n,o,r=t)=>He(j,e,[l,a,n,o,r]),J=(e,l,a,n,o,r=t,s=t,d=t)=>G(ut[e]+l+(4==e?$e:t)+a,r,n,(n==F?bt:It)(ut[e]+(4==e?$e:t)+a,s,e?void 0:n),o,d),L=(e,l,a,n=t,o=t,r=1)=>G($+e+s,(n?n+", ":t)+se+": "+l+(r?", mutator?: boolean":t),ne,ht($+e+s,o,r?"mutator":t),a),B=`./${Ye(n)}.d`,F=Ye(n,1),q=Ye(F),K=[],X=U();let le=[],ue=[];if(v(1,B,F,`create${F} as create${F}Decl`),!$t(e)){const e=U();A(((l,a)=>{const n=[y(a+i,`{[rowId: Id]: ${a}Row}`,ie+` the '${l}' `+i),y(a+b,`{${Ke(N(l,((e,l,a)=>`'${e}'${E(a)?"?":t}: ${l};`))," ")}}`,ke(l)),y(a+b+"WhenSet",`{${Ke(N(l,((e,t)=>`'${e}'?: ${t};`))," ")}}`,ke(l,1)),y(a+g+ne,Ke(N(l,(e=>`'${e}'`))," | "),`A Cell Id for the '${l}' `+i),y(a+g+te,`(...[cellId, cell]: ${Ke(N(l,((e,t)=>`[cellId: '${e}', cell: ${t}]`))," | ")})`+we,Oe(`a Cell Id and value from a Row in the '${l}' `+i)),y(a+b+te,`(rowId: Id, forEachCell: (cellCallback: ${a}CellCallback)`+we+")"+we,Oe(`a Row Id from the '${l}' Table, and a Cell iterator`))];Q(e,l,n),v(1,B,...n)}));const l=y(u,`{${Ke(A((t=>`'${t}'?: ${_(e,t)?.[0]};`))," ")}}`,Se(1,5)),n=y(i+ne,Ke(A((e=>`'${e}'`))," | "),"A "+i+" Id in "+be),d=y(i+te,`(...[tableId, rowCallback]: ${Ke(A((t=>`[tableId: '${t}', forEachRow: (rowCallback: ${_(e,t)?.[5]})${we}]`))," | ")})`+we,Oe(Y+i+" Id, and a Row iterator")),$=y("GetCellChange",`(...[tableId, rowId, cellId]: ${Ke(A((t=>`[tableId: '${t}', rowId: Id, cellId: ${_(e,t)?.[3]}]`))," | ")}) => CellChange`,ee+" returning information about any Cell's changes during a "+pe),w=y(u+s,`(${q}: ${F}, getCellChange: ${$}${de})`+we,De(1)),C=y(I+s,`(${q}: ${F})`+we,De(2)),m=y(i+s,`(${q}: ${F}, tableId: ${n}, getCellChange: ${$}${de})`+we,De(3)),S=y(h+s,`(${q}: ${F}, tableId: ${n})`+we,De(4,3)),V=y(p+s,"("+lt(q+": "+F,"tableId: "+n,"cellId: Id"+de,"descending: boolean","offset: number","limit: number"+de,"sortedRowIds: Ids")+")"+we,De(13,3)),x=y(b+s,`(${q}: ${F}, tableId: ${n}, rowId: Id, getCellChange: ${$}${de})`+we,De(5,3)),D=y(f+s,`(${q}: ${F}, tableId: ${n}, rowId: Id)`+we,De(6,5)),T=y(g+s,`(...[${q}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${Ke(Xe(A((e=>N(e,((t,l)=>`[${q}: ${F}, tableId: '${e}', rowId: Id, cellId: '${t}', newCell: ${l}${de}, oldCell: ${l}${de}, getCellChange: ${$} | undefined]`)))))," | ")})`+we,De(7,5)),P=y(oe+g+s,`(${q}: ${F}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])`+we,De(8));le=[l,n,w,C,m,S,V,x,D,T,e],R([[l],[a],[F,"tables: "+l,"tables"],[F]],(([e,l,a],n)=>J(n,t,u,e,Se(1,n),l,a))),J(0,t,I,n+Ie,Ve(i,be)),J(5,t,i,fe,xe(i,be),"tableCallback: "+d,"tableCallback as any"),A(((l,n,o)=>{const[r,s,d,$,u,I]=_(e,l);R([[r],[a],[F,"table: "+r,", table"],[F]],(([e,a,r=t],s)=>J(s,n,i,e,Pe(l,s),a,o+r))),J(0,n,h,c,Ve(b,Ae(l)),t,o),J(0,n,p,c,Ve(b,Ae(l),1),"cellId?: "+$+", descending?: boolean, offset?: number, limit?: number",o+", cellId, descending, offset, limit"),J(5,n,b,fe,xe(b,Ae(l)),"rowCallback: "+I,o+", rowCallback as any"),R([[s],[a],[F,", row: "+d,", row"],[F],[F,", partialRow: "+d,", partialRow"]],(([e,a=t,r=t],s)=>J(s,n,b,e,je(l,s),"rowId: Id"+a,o+", rowId"+r))),J(6,n,b,ne+de,"Adds a new Row to "+Ae(l),"row: "+d,o+", row"),J(0,n,f,$+Ie,Ve(g,Ne(l)),"rowId: "+ne,o+", rowId"),J(5,n,g,fe,xe(g,Ne(l)),"rowId: Id, cellCallback: "+u,o+", rowId, cellCallback as any"),N(l,((e,r,s,d,$)=>{const c="Map"+Ye(r,1);Q(X,r,c);const i=r+(E(s)?de:t);R([[i],[a],[F,`, cell: ${r} | `+c,", cell as any"],[F]],(([a,r=t,s=t],c)=>J(c,n+$,g,a,Ee(l,e,c),"rowId: Id"+r,o+", rowId, "+d+s)))}))})),J(0,t,u+re,re,Se(1,6)),J(2,t,u+re,F,Se(1,7),"tablesJson: "+re,"tables"+re),L(u,w,Se(1,8)+" changes"),L(I,C,Te(2,0,1)),L(i,m,Te(3,0),`tableId: ${n} | null`,"tableId"),L(h,S,Te(4,3,1),`tableId: ${n} | null`,"tableId"),L(p,V,Te(13,3,1),lt("tableId: "+n,"cellId: Id"+de,"descending: boolean","offset: number","limit: number"+de),lt("tableId","cellId","descending","offset","limit")),L(b,x,Te(5,3),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),L(f,D,Te(6,5,1),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),L(g,T,Te(7,5),`tableId: ${n} | null, rowId: IdOrNull, cellId: ${Ke(A((l=>_(e,l)?.[3]??t))," | ")} | null`,"tableId, rowId, cellId"),L(oe+g,P,ce+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),v(1,B,l,n,d,w,C,m,S,V,x,D,T,P,...W(X)),v(0,"tinybase","CellChange"),O(K,".setTablesSchema({",Xe(A(((e,l,a)=>[`[${a}]: {`,...N(e,((e,l,a,n)=>`[${n}]: {[${k(et(o),`'${o}'`)}]: ${k(et(l),`'${l}'`)}${E(a)?t:`, [${k(et(r),`'${r}'`)}]: `+(z(a)?k(et(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(!$t(l)){const e=y(C,"{"+Ke(P(((e,l,a)=>`'${e}'${E(a)?"?":t}: ${l};`))," ")+"}",Se(2,5)),l=y(C+"WhenSet","{"+Ke(P(((e,t)=>`'${e}'?: ${t};`))," ")+"}",Se(2,5,1)),n=y(w+ne,Ke(P((e=>`'${e}'`))," | "),"A Value Id in "+be),d=y(w+te,`(...[valueId, rowCallback]: ${Ke(P(((e,t)=>`[valueId: '${e}', value: ${t}]`))," | ")})`+we,Oe("a Value Id, and value")),$=y("GetValueChange",`(valueId: ${n}) => ValueChange`,ee+" returning information about any Value's changes during a "+pe),c=y(C+s,`(${q}: ${F}, getValueChange: ${$}${de})`+we,De(9)),i=y(m+s,`(${q}: ${F})`+we,De(10)),u=y(w+s,`(...[${q}, valueId, newValue, oldValue, getValueChange]: ${Ke(P(((e,t)=>`[${q}: ${F}, valueId: '${e}', newValue: ${t}${de}, oldValue: ${t}${de}, getValueChange: ${$} | undefined]`))," | ")})`+we,De(11)),I=y(oe+w+s,`(${q}: ${F}, valueId: Id, invalidValues: any[])`+we,De(12));ue=[e,l,n,c,i,u],R([[e],[a],[F,"values: "+l,"values"],[F],[F,"partialValues: "+l,"partialValues"]],(([e,l,a],n)=>J(n,t,C,e,Se(2,n),l,a))),J(0,t,m,n+Ie,Ve(w,be)),J(5,t,w,"void",xe(w,be),"valueCallback: "+d,"valueCallback as any"),P(((e,l,n,o,r)=>{const s="Map"+Ye(l,1);Q(X,l,s),R([[l],[a],[F,`value: ${l} | `+s,", value as any"],[F]],(([l,a,n=t],s)=>J(s,r,w,l,Me(e,s),a,o+n)))})),J(0,t,C+re,re,Se(2,6)),J(2,t,C+re,F,Se(2,7),"valuesJson: "+re,"values"+re),L(C,c,Se(2,8)+" changes"),L(m,i,Te(10,0,1)),L(w,u,Te(11,0),`valueId: ${n} | null`,"valueId"),L(oe+w,I,ce+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),v(1,B,e,l,n,d,c,i,u,I),v(0,"tinybase","ValueChange"),O(K,".setValuesSchema({",P(((e,l,a,n)=>[`[${n}]: {[${k(et(o),`'${o}'`)}]: ${k(et(l),`'${l}'`)}${E(a)?t:`, [${k(et(r),`'${r}'`)}]: `+(z(a)?k(et(a),`'${a}'`):a)}},`])),"})")}Z(X,((e,t)=>y(t,`(cell: ${e}${de}) => `+e,`Takes a ${e} Cell value and returns another`))),v(null,"tinybase","DoRollback",ne,"IdOrNull",c,re,"Store");const Ce=y(he+s,`(${q}: ${F}, cellsTouched: boolean, valuesTouched: boolean)`+we,ee+" listening to the completion of a "+pe);return J(0,t,re,re,Se(0,6)),J(2,t,re,F,Se(0,7),"json: "+re,"json"),J(7,t,pe,"Return","Execute a "+pe+" to make multiple mutations","actions: () => Return, doRollback?: DoRollback","actions, doRollback","<Return>"),J(7,t,"start"+he,F,"Explicitly starts a "+pe),J(7,t,"finish"+he,F,"Explicitly finishes a "+pe,"doRollback?: DoRollback,","doRollback"),L("WillFinish"+he,Ce,ce+" just before "+ge,t,t,0),L("DidFinish"+he,Ce,ce+" just after "+ge,t,t,0),J(7,t,"call"+s,F,"Manually provoke a listener to be called","listenerId: Id","listenerId"),J(3,t,s,F,"Remove a listener that was previously added to "+be,"listenerId: Id","listenerId"),G("getStore",t,"Store","store",ze[0]+" the underlying Store object"),v(1,"tinybase","createStore"),v(1,B,F,`create${F} as create${F}Decl`,Ce),k("store",["createStore()",...K]),S("fluent","actions: () => Store",["actions();",`return ${q};`]),S("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${q}, ...params)`),k(q,["{",...M(1),"}"]),[d(...V(0),...x(),ae+" interface "+F+" {",...M(0),"}",t,tt(`Creates a ${F} object`),ae+" function create"+F+"(): "+F+";"),d(...V(1),ae+" const create"+F+": typeof create"+F+"Decl = () => {",...D(),`return Object.freeze(${q});`,"};"),le,ue]},gt="Deps",ft=e=>d+e,wt=e=>lt(ft(e),ft(e)+gt),Ct="Parameter",mt=": (parameter: "+Ct+", store: Store) => ",vt="const contextValue = useContext(Context);",yt=", and registers a listener so that any changes to that result will cause a re-render",Rt=", based on a parameter",St=": ",kt=Ct+"ized"+te+"<"+Ct+">",Vt="<"+Ct+",>",xt=gt+"?: React.DependencyList",Ot="then"+xt,Dt="then?: (store: Store",Tt=lt(Dt+")"+we,Ot),At="then, then"+gt,Nt="rowId",Pt=Nt+St+ne,jt=(e,...t)=>lt(...t,se+": "+e,se+xt,"mutator?: boolean"),Et=(...e)=>lt(...e,se,se+gt,"mutator"),Mt=(e,l,a,n,o)=>{const[r,d,$,v,y,R,S,k]=at(),[V,x,D]=it(e,l,y),A=`./${Ye(a)}.d`,N=`./${Ye(a)}-ui-react.d`,P="tinybase/ui-react",j=Ye(a,1),M=Ye(j),z=j+"Or"+j+ne,J=M+"Or"+j+ne,L=U(),W=(e,l,a,n,o,r=t)=>(d(1,N,e+" as "+e+"Decl"),He(L,e,[l,a,G(n)?["{",n,"}"]:n,o,r])),B=(e,l,a,n,o,r=t)=>W("use"+e,l,a,n,o,r),F=(e,l,a,n,o=t,r=t,s=t,$=t,c=t)=>{d(1,P,`use${l} as use${l}Core`),B(e,lt(o,X,$),a,ee+`(${J}, use${l}Core, [`+(r||t)+(c?"], ["+c:t)+"])",n,s)},Z=(e,t,l,a)=>W(e,t,1,l,a),Q=(e=0)=>H(L,(([l,a,n,o,r],s)=>{const d=e?[ae+` const ${s}: typeof ${s}Decl = ${r}(${l}): ${1==a?"any":a} =>`,n]:[ae+` function ${s}${r}(${l}): ${1==a?"ComponentReturnType":a};`];return e||T(d,tt(o)),O(d,t),d}));d(null,"tinybase",ne,c,"IdOrNull","Store",te,Ct+"ized"+te),d(0,P,"ComponentReturnType"),d(0,A,j);const q=$(z,j+" | "+ne,`Used when you need to refer to a ${j} in a React hook or component`),K=$("ProviderProps",`{readonly ${M}?: ${j}; readonly ${M}ById?: {[${M}Id: Id]: ${j}}}`,`Used with the Provider component, so that a ${j} can be passed into the context of an application`);d(1,"react","React"),d(1,N,q,K);const X=J+"?: "+q;y("{createContext, useContext, useMemo}","React"),y("Context",`createContext<[${j}?, {[${M}Id: Id]: ${j}}?]>([])`),B("Create"+j,`create: () => ${j}, create`+xt,j,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${j} within a React application with convenient memoization`);const Y=B(j,"id?: Id",j+de,[vt,"return id == null ? contextValue[0] : contextValue[1]?.[id];"],`Get a reference to a ${j} from within a Provider component context`),ee=v("useHook",J+`: ${q} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${M} = ${Y}(${J} as Id);`,`return hook(...preParams, ((${J} == null || typeof ${J} == 'string')`,`? ${M} : ${J})?.getStore(), ...postParams)`]);if(!$t(e)){const[e,l,a,o,r,$,w,C,m,v,y]=n;d(null,A,e,l,a,o,r,$,w,C,m,v),d(1,P),d(1,A,j),F(u,u,e,Se(1,0)+yt),F(I,I,l+Ie,Ve(i,be)+yt),F(ue+u+te,ue+u+te,kt,Se(1,9)+Rt,lt(ft(u)+mt+e,ft(u)+xt),wt(u),Vt,lt(Dt,`tables: ${e})`+we,Ot),At),F(le+u+te,le+u+te,te,Se(1,12),t,t,t,Tt,At),V(((e,l,a)=>{const[n,o,r,s]=_(y,e);d(0,A,n,o,r,s),d(1,A,n,o,r,s),F(l+i,i,n,Pe(e)+yt,t,a),F(l+h,h,c,Ve(b,Ae(e))+yt,t,a),F(l+p,p,c,Ve(b,Ae(e),1)+yt,"cellId?: "+s+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit"),F(l+b,b,o,je(e)+yt,Pt,lt(a,Nt)),F(l+f,f,s+Ie,Ve(g,Ne(e))+yt,Pt,lt(a,Nt)),F(ue+l+i+te,ue+i+te,kt,Pe(e,9)+Rt,lt(ft(i)+mt+n,ft(i)+xt),lt(a,wt(i)),Vt,lt(Dt,`table: ${n})`+we,Ot),At),F(le+l+i+te,le+i+te,te,Pe(e,12),t,a,t,Tt,At),F(ue+l+b+te,ue+b+te,kt,je(e,9)+Rt,lt(Pt,ft(b)+mt+r,ft(b)+xt),lt(a,Nt,wt(b)),Vt,lt(Dt,`row: ${r})`+we,Ot),At),F("Add"+l+b+te,"Add"+b+te,kt,je(e,10)+Rt,lt(ft(b)+mt+r,ft(b)+xt),lt(a,wt(b)),Vt,"then?: ("+lt(Pt+de,"store: Store","row: "+r+")"+we,"then"+xt),At),F(ue+l+$e+b+te,ue+$e+b+te,kt,je(e,11)+Rt,lt(Pt,ft($e+b)+mt+r,ft($e+b)+xt),lt(a,Nt,wt($e+b)),Vt,lt(Dt,`partialRow: ${r})`+we,Ot),At),F(le+l+b+te,le+b+te,te,je(e,12),Pt,lt(a,Nt),t,Tt,At),x(e,((n,o,r,s,$)=>{const c="Map"+Ye(o,1);d(0,A,c),d(1,A,c),F(l+$+g,g,o+(E(r)?de:t),Ee(e,n)+yt,Pt,lt(a,Nt,s)),F(ue+l+$+g+te,ue+g+te,kt,Ee(e,n,9)+Rt,lt(Pt,ft(g)+mt+o+" | "+c,ft(g)+xt),lt(a,Nt,s,wt(g)),Vt,lt(Dt,`cell: ${o} | ${c})`+we,Ot),At),F(le+l+$+g+te,le+g+te,te,Ee(e,n,12),lt(Pt,"forceDel?: boolean"),lt(a,Nt,s,"forceDel"),t,Tt,At)}))}));const R=Ke(V((e=>_(y,e)?.[3]??t))," | ");F(u+s,u+s,fe,Se(1,8)+" changes",jt(a),Et()),F(I+s,I+s,fe,Te(2,0,1),jt(o),Et()),F(i+s,i+s,fe,Te(3,0),jt(r,`tableId: ${l} | null`),Et("tableId")),F(h+s,h+s,fe,Te(4,3,1),jt($,`tableId: ${l} | null`),Et("tableId")),F(p+s,p+s,fe,Te(13,3,1),jt(w,`tableId: ${l} | null`,"cellId: "+R+de,"descending: boolean","offset: number","limit: number"+de),Et("tableId","cellId","descending","offset","limit")),F(b+s,b+s,fe,Te(5,3),jt(C,`tableId: ${l} | null`,Nt+": IdOrNull"),Et("tableId",Nt)),F(f+s,f+s,fe,Te(6,5,1),jt(m,`tableId: ${l} | null`,Nt+": IdOrNull"),Et("tableId",Nt)),F(g+s,g+s,fe,Te(7,5),jt(v,`tableId: ${l} | null`,Nt+": IdOrNull",`cellId: ${R} | null`),Et("tableId",Nt,"cellId"))}if(!$t(l)){const[e,l,a,n,r,$]=o;d(null,A,...o),F(C,C,e,Se(2,0)+yt),F(m,m,a+Ie,Ve(w,be)+yt),F(ue+C+te,ue+C+te,kt,Se(2,9)+Rt,lt(ft(C)+mt+l,ft(C)+xt),wt(C),Vt,lt(Dt,`values: ${l})`+we,Ot),At),F(ue+$e+C+te,ue+$e+C+te,kt,Se(2,11)+Rt,lt(ft($e+C)+mt+l,ft($e+C)+xt),wt($e+C),Vt,lt(Dt,`partialValues: ${l})`+we,Ot),At),F(le+C+te,le+C+te,te,Se(2,12),t,t,t,Tt,At),D(((e,l,a,n,o)=>{const r="Map"+Ye(l,1);d(0,A,r),d(1,A,r),F(o+w,w,l,Me(e)+yt,t,n),F(ue+o+w+te,ue+w+te,kt,Me(e,9)+Rt,lt(ft(w)+mt+l+" | "+r,ft(w)+xt),lt(n,wt(w)),Vt,lt(Dt,`value: ${l} | ${r})`+we,Ot),At),F(le+o+w+te,le+w+te,te,Me(e,12),t,n,t,Tt,At)})),F(C+s,C+s,fe,Se(2,8)+" changes",jt(n),Et()),F(m+s,m+s,fe,Te(10,0,1),jt(r),Et()),F(w+s,w+s,fe,Te(11,0),jt($,`valueId: ${a} | null`),Et("valueId"))}return Z("Provider",`{${M}, ${M}ById, children}: `+K+" & {children: React.ReactNode}",[vt,"return (","<Context.Provider","value={useMemo(",`() => [${M} ?? contextValue[0], {...contextValue[1], ...${M}ById}],`,`[${M}, ${M}ById, contextValue],`,")}>","{children}","</Context.Provider>",");"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[r(...R(0),...S(),...Q(0)),r(...R(1),...k(),...Q(1))]},zt=(e,l,a)=>{if($t(e)&&$t(l))return[t,t,t,t];const[n,o,r,s]=pt(e,l,a);return[n,o,...Mt(e,l,a,r,s)]},Gt={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Jt=ct((e=>{const t=()=>{const t=N(e.getTablesSchemaJson());return!$t(t)||v(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=U();if(v(a,(t=>v(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),r=q(n,a,(()=>[J(o),U(),[0],0])),[s,d,[$]]=r,c=q(d,o,(()=>0))+1;return c>$&&(r[2]=[c,o]),Q(d,o,c),r[3]++,s==J(o)})))))return t[l]={},B(n,(([e,,[,n],s],d)=>{t[l][d]={[o]:e,...s==k(a)?{[r]:n}:{}}})),1}))?t:{}},l=()=>{const t=N(e.getValuesSchemaJson());return $t(t)&&e.forEachValue(((e,l)=>{t[e]={[o]:J(l)}})),t},a=e=>zt(t(),l(),e),n=async e=>{const t=["d.ts","ts","d.ts","tsx"];let l;try{l=(await import("prettier")).format}catch(e){l=e=>e}return S(a(e),((e,a)=>Qe(l(e,{...Gt,filepath:"_."+t[a]}))))};return rt({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,r)=>{l++;let s=0,d=0;const $={};r(((e,l)=>{s++;let a=0;l((()=>a++)),d+=a,t&&($[e]={rowCells:a})})),a+=s,n+=d,t&&(o[e]={tableRows:s,tableCells:d,rows:$})})),{totalTables:l,totalRows:a,totalCells:n,totalValues:k(e.getValueIds()),jsonLength:qe(e.getJson()),...t?{detail:{tables:o}}:{}}},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));exports.createTools=Jt;
|
package/lib/cjs/tools.cjs.gz
CHANGED
|
Binary file
|
package/lib/cjs/tools.d.ts
CHANGED
|
@@ -272,26 +272,35 @@ export interface Tools {
|
|
|
272
272
|
getStoreValuesSchema(): ValuesSchema;
|
|
273
273
|
|
|
274
274
|
/**
|
|
275
|
-
* The getStoreApi method returns
|
|
276
|
-
*
|
|
275
|
+
* The getStoreApi method returns code-generated .d.ts and .ts(x) files that
|
|
276
|
+
* describe the schema of a Store and React bindings (since v3.1.0) in an ORM
|
|
277
|
+
* style.
|
|
277
278
|
*
|
|
278
|
-
* If the Store does not already have an explicit TablesSchema
|
|
279
|
-
* it, the data in the Store will be scanned to attempt to
|
|
280
|
-
*
|
|
281
|
-
* files) though if no schema can be inferred, the strings will be empty.
|
|
279
|
+
* If the Store does not already have an explicit TablesSchema or ValuesSchema
|
|
280
|
+
* associated with it, the data in the Store will be scanned to attempt to
|
|
281
|
+
* infer new schemas. The method returns four strings (which should be saved
|
|
282
|
+
* as files) though if no schema can be inferred, the strings will be empty.
|
|
282
283
|
*
|
|
283
284
|
* The method takes a single argument which represents the name you want the
|
|
284
|
-
* generated store object to have in code. You are expected to save the
|
|
285
|
-
*
|
|
286
|
-
*
|
|
285
|
+
* generated store object to have in code. You are expected to save the four
|
|
286
|
+
* files yourself, as, respectively:
|
|
287
|
+
*
|
|
288
|
+
* - `[storeName].d.ts`
|
|
289
|
+
* - `[storeName].ts`
|
|
290
|
+
* - `[storeName]-ui-react.d.ts`
|
|
291
|
+
* - `[storeName]-ui-react.tsx`
|
|
292
|
+
*
|
|
293
|
+
* Also you should save these alongside each other so that the .ts(x) files
|
|
294
|
+
* can import types from the .d.ts files.
|
|
287
295
|
*
|
|
288
|
-
* The .d.ts and .ts files that are generated are designed to resemble the
|
|
289
|
-
* main TinyBase
|
|
290
|
-
*
|
|
296
|
+
* The .d.ts and .ts(x) files that are generated are designed to resemble the
|
|
297
|
+
* main TinyBase Store and React binding files, but provide named types and
|
|
298
|
+
* methods that describe the domain of the schema in the store.
|
|
291
299
|
*
|
|
292
300
|
* For example, from a Store that has a `pets` Table, you will get methods
|
|
293
|
-
* like `getPetsTable`,
|
|
294
|
-
* versions of the underlying getTable method or the Row
|
|
301
|
+
* like `getPetsTable`, types like `PetsRow`, and hooks and components that
|
|
302
|
+
* are more specific versions of the underlying getTable method or the Row
|
|
303
|
+
* type, and so on. For example:
|
|
295
304
|
*
|
|
296
305
|
* |Store type|Equivalent generated type|
|
|
297
306
|
* |-|-|
|
|
@@ -321,9 +330,9 @@ export interface Tools {
|
|
|
321
330
|
* directly.
|
|
322
331
|
*
|
|
323
332
|
* @param storeName The name you want to provide to the generated Store, which
|
|
324
|
-
* should also be used to save the `.d.ts
|
|
325
|
-
* @returns A
|
|
326
|
-
* `.ts` files.
|
|
333
|
+
* should also be used to save the `.d.ts`, `.ts`, and `.tsx` files.
|
|
334
|
+
* @returns A set of four strings representing the contents of the `.d.ts`,
|
|
335
|
+
* `.ts`, and `.tsx` files for the generated Store and React modules.
|
|
327
336
|
* @example
|
|
328
337
|
* This example creates a Tools object and generates code for a Store that
|
|
329
338
|
* already has a TablesSchema.
|
|
@@ -333,7 +342,8 @@ export interface Tools {
|
|
|
333
342
|
* price: {type: 'number'},
|
|
334
343
|
* },
|
|
335
344
|
* });
|
|
336
|
-
* const [dTs, ts] =
|
|
345
|
+
* const [dTs, ts, dTsUiReact, tsUiReact] =
|
|
346
|
+
* createTools(store).getStoreApi('shop');
|
|
337
347
|
*
|
|
338
348
|
* const dTsLines = dTs.split('\n');
|
|
339
349
|
* console.log(dTsLines[3]);
|
|
@@ -342,7 +352,7 @@ export interface Tools {
|
|
|
342
352
|
* // -> 'export type PetsRow = {\'price\'?: number;};'
|
|
343
353
|
*
|
|
344
354
|
* const tsLines = ts.split('\n');
|
|
345
|
-
* console.log(tsLines[
|
|
355
|
+
* console.log(tsLines[39]);
|
|
346
356
|
* // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
|
|
347
357
|
* ```
|
|
348
358
|
* @example
|
|
@@ -353,7 +363,8 @@ export interface Tools {
|
|
|
353
363
|
* fido: {price: 5},
|
|
354
364
|
* felix: {price: 4},
|
|
355
365
|
* });
|
|
356
|
-
* const [dTs, ts] =
|
|
366
|
+
* const [dTs, ts, dTsUiReact, tsUiReact] =
|
|
367
|
+
* createTools(store).getStoreApi('shop');
|
|
357
368
|
*
|
|
358
369
|
* const dTsLines = dTs.split('\n');
|
|
359
370
|
* console.log(dTsLines[3]);
|
|
@@ -362,18 +373,18 @@ export interface Tools {
|
|
|
362
373
|
* // -> 'export type PetsRow = {\'price\': number;};'
|
|
363
374
|
*
|
|
364
375
|
* const tsLines = ts.split('\n');
|
|
365
|
-
* console.log(tsLines[
|
|
376
|
+
* console.log(tsLines[41]);
|
|
366
377
|
* // -> 'getPetsTable: (): PetsTable => store.getTable(PETS) as PetsTable,'
|
|
367
378
|
* ```
|
|
368
379
|
* @category Modelling
|
|
369
380
|
* @since v2.2.0
|
|
370
381
|
*/
|
|
371
|
-
getStoreApi(storeName: string): [string, string];
|
|
382
|
+
getStoreApi(storeName: string): [string, string, string, string];
|
|
372
383
|
|
|
373
384
|
/**
|
|
374
385
|
* The getPrettyStoreApi method attempts to returns a prettified
|
|
375
|
-
* code-generated .d.ts
|
|
376
|
-
*
|
|
386
|
+
* code-generated .d.ts and .ts(x) files that describe the schema of a Store
|
|
387
|
+
* and React bindings (since v3.1.0) in an ORM style.
|
|
377
388
|
*
|
|
378
389
|
* This is simply a wrapper around the getStoreApi method that attempts to
|
|
379
390
|
* invoke the `prettier` module (which it hopes you have installed) to format
|
|
@@ -384,17 +395,24 @@ export interface Tools {
|
|
|
384
395
|
* the results as a promise.
|
|
385
396
|
*
|
|
386
397
|
* The method takes a single argument which represents the name you want the
|
|
387
|
-
* generated store object to have in code. You are expected to save the
|
|
388
|
-
*
|
|
389
|
-
*
|
|
398
|
+
* generated store object to have in code. You are expected to save the four
|
|
399
|
+
* files yourself, as, respectively:
|
|
400
|
+
*
|
|
401
|
+
* - `[storeName].d.ts`
|
|
402
|
+
* - `[storeName].ts`
|
|
403
|
+
* - `[storeName]-ui-react.d.ts`
|
|
404
|
+
* - `[storeName]-ui-react.tsx`
|
|
405
|
+
*
|
|
406
|
+
* Also you should save these alongside each other so that the .ts(x) files
|
|
407
|
+
* can import types from the .d.ts files.
|
|
390
408
|
*
|
|
391
409
|
* See the documentation for the getStoreApi method for details of the content
|
|
392
410
|
* of the generated files.
|
|
393
411
|
*
|
|
394
412
|
* @param storeName The name you want to provide to the generated Store, which
|
|
395
|
-
* should also be used to save the `.d.ts
|
|
396
|
-
* @returns A
|
|
397
|
-
* `.ts` files.
|
|
413
|
+
* should also be used to save the `.d.ts`, `.ts`, and `.tsx` files.
|
|
414
|
+
* @returns A set of four strings representing the contents of the `.d.ts`,
|
|
415
|
+
* `.ts`, and `.tsx` files for the generated Store and React modules.
|
|
398
416
|
* @example
|
|
399
417
|
* This example creates a Tools object and generates code for a Store that
|
|
400
418
|
* already has a TablesSchema.
|
|
@@ -405,7 +423,9 @@ export interface Tools {
|
|
|
405
423
|
* },
|
|
406
424
|
* });
|
|
407
425
|
* const tools = createTools(store);
|
|
408
|
-
* const [dTs, ts] = await
|
|
426
|
+
* const [dTs, ts, dTsUiReact, tsUiReact] = await createTools(
|
|
427
|
+
* store,
|
|
428
|
+
* ).getPrettyStoreApi('shop');
|
|
409
429
|
*
|
|
410
430
|
* const dTsLines = dTs.split('\n');
|
|
411
431
|
* console.log(dTsLines[5]);
|
|
@@ -414,7 +434,7 @@ export interface Tools {
|
|
|
414
434
|
* // -> 'export type PetsRow = {price?: number};'
|
|
415
435
|
*
|
|
416
436
|
* const tsLines = ts.split('\n');
|
|
417
|
-
* console.log(tsLines[
|
|
437
|
+
* console.log(tsLines[75]);
|
|
418
438
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
419
439
|
* ```
|
|
420
440
|
* @example
|
|
@@ -426,7 +446,9 @@ export interface Tools {
|
|
|
426
446
|
* felix: {price: 4},
|
|
427
447
|
* });
|
|
428
448
|
* const tools = createTools(store);
|
|
429
|
-
* const [dTs, ts] = await
|
|
449
|
+
* const [dTs, ts, dTsUiReact, tsUiReact] = await createTools(
|
|
450
|
+
* store,
|
|
451
|
+
* ).getPrettyStoreApi('shop');
|
|
430
452
|
*
|
|
431
453
|
* const dTsLines = dTs.split('\n');
|
|
432
454
|
* console.log(dTsLines[5]);
|
|
@@ -435,13 +457,15 @@ export interface Tools {
|
|
|
435
457
|
* // -> 'export type PetsRow = {price: number};'
|
|
436
458
|
*
|
|
437
459
|
* const tsLines = ts.split('\n');
|
|
438
|
-
* console.log(tsLines[
|
|
460
|
+
* console.log(tsLines[77]);
|
|
439
461
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
440
462
|
* ```
|
|
441
463
|
* @category Modelling
|
|
442
464
|
* @since v2.2.0
|
|
443
465
|
*/
|
|
444
|
-
getPrettyStoreApi(
|
|
466
|
+
getPrettyStoreApi(
|
|
467
|
+
storeName: string,
|
|
468
|
+
): Promise<[string, string, string, string]>;
|
|
445
469
|
|
|
446
470
|
/**
|
|
447
471
|
* The getStore method returns a reference to the underlying Store that is
|
package/lib/cjs/ui-react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("react");const s=e=>typeof e,t=s(""),o=(e,s)=>e.map(s),r=e=>null==e,l=(e,s,t)=>r(e)?t?.():s(e),d=()=>{},{createContext:u,useContext:a}=e,n=u([]),p=(e,s)=>{const t=a(n);return r(e)?t[s]:((e,s)=>l(e,(e=>e[s])))(t[s+1],e)},i=(e,o)=>{const l=p(e,o);return r(e)||(e=>s(e)==t)(e)?l:e},I=e=>i(e,0),c=e=>i(e,2),x=e=>i(e,4),w=e=>i(e,6),R=e=>i(e,8),C=e=>i(e,10),{useCallback:b,useEffect:k,useMemo:g,useRef:V,useState:m}=e,L=(e,s,t=[])=>{const o=g((()=>s(e)),[e,...t]);return k((()=>()=>o.destroy()),[o]),o},h=(e,s,t,o=[],l)=>{const[,d]=m(),u=b((()=>s?.["get"+e]?.(...o)??t),[s,...o]),[a]=m(u),n=V(a);return g((()=>n.current=u()),[u]),T(e,s,((...e)=>{n.current=r(l)?u():e[l],d([])}),[],o),n.current},T=(e,s,t,o=[],r=[],...l)=>k((()=>{const o=s?.["add"+e+"Listener"]?.(...r,t,...l);return()=>s?.delListener(o)}),[s,...r,...o,...l]),S=(e,s,t,o=[],r=d,u=[],...a)=>{const n=I(e);return b((e=>l(n,(o=>l(t(e,o),(e=>r(o["set"+s](...a,e),e)))))),[n,s,...o,...u,...a])},y=(e,s,t=d,o=[],...r)=>{const l=I(e);return b((()=>t(l?.["del"+s](...r))),[l,s,...o,...r])},v=(e,s,t)=>{const o=C(e);return b((()=>o?.[s](t)),[o,s,t])},P=e=>h("TableIds",I(e),[],[]),q=(e,s)=>h("RowIds",I(s),[],[e]),f=(e,s,t,o=0,r,l)=>h("SortedRowIds",I(l),[],[e,s,t,o,r],6),B=(e,s,t)=>h("CellIds",I(t),[],[e,s]),M=(e,s,t,o)=>h("Cell",I(o),void 0,[e,s,t],4),D=e=>h("ValueIds",I(e),[],[]),A=(e,s)=>h("Value",I(s),void 0,[e]),F=(e,s)=>h("Metric",c(s),void 0,[e]),G=(e,s)=>h("SliceIds",x(s),[],[e]),E=(e,s,t)=>h("SliceRowIds",x(t),[],[e,s]),Q=(e,s,t)=>h("RemoteRowId",w(t),void 0,[e,s]),U=(e,s,t)=>h("LocalRowIds",w(t),[],[e,s]),j=(e,s,t)=>h("LinkedRowIds",w(t),[],[e,s]),z=(e,s)=>h("ResultRowIds",R(s),[],[e]),H=(e,s,t,o=0,r,l)=>h("ResultSortedRowIds",R(l),[],[e,s,t,o,r],6),J=(e,s,t)=>h("ResultCellIds",R(t),[],[e,s]),K=(e,s,t,o)=>h("ResultCell",R(o),void 0,[e,s,t]),N=e=>h("CheckpointIds",C(e),[[],void 0,[]]),O=(e,s)=>h("Checkpoint",C(s),void 0,[e]),W=e=>v(e,"goBackward"),X=e=>v(e,"goForward"),{createElement:Y,useMemo:Z}=e,$=({tableId:e,store:s,rowComponent:t=de,getRowComponentProps:r,separator:l,debugIds:d},u)=>re(o(u,(o=>Y(t,{...oe(r,o),key:o,tableId:e,rowId:o,store:s,debugIds:d}))),l,d,e),_=({queryId:e,queries:s,resultRowComponent:t=ie,getResultRowComponentProps:r,separator:l,debugIds:d},u)=>re(o(u,(o=>Y(t,{...oe(r,o),key:o,queryId:e,rowId:o,queries:s,debugIds:d}))),l,d,e),ee=e=>{const s=w(e);return[s,s?.getStore()]},se=({relationshipId:e,relationships:s,rowComponent:t=de,getRowComponentProps:r,separator:l,debugIds:d},u,a)=>{const[n,p]=ee(s),i=n?.getLocalTableId(e),I=u(e,a,n);return re(o(I,(e=>Y(t,{...oe(r,e),key:e,tableId:i,rowId:e,store:p,debugIds:d}))),l,d,a)},te=e=>({checkpoints:s,checkpointComponent:t=Ie,getCheckpointComponentProps:r,separator:l,debugIds:d})=>{const u=C(s);return re(o(e(N(u)),(e=>Y(t,{...oe(r,e),key:e,checkpoints:u,checkpointId:e,debugIds:d}))),l)},oe=(e,s)=>r(e)?{}:e(s),re=(e,s,t,l)=>{const d=r(s)||!Array.isArray(e)?e:o(e,((e,t)=>t>0?[s,e]:e));return t?[l,":{",d,"}"]:d},le=({tableId:e,rowId:s,cellId:t,store:o,debugIds:r})=>re(""+(M(e,s,t,o)??""),void 0,r,t),de=({tableId:e,rowId:s,store:t,cellComponent:r=le,getCellComponentProps:l,separator:d,debugIds:u})=>re(o(B(e,s,t),(o=>Y(r,{...oe(l,o),key:o,tableId:e,rowId:s,cellId:o,store:t,debugIds:u}))),d,u,s),ue=e=>$(e,q(e.tableId,e.store)),ae=({valueId:e,store:s,debugIds:t})=>re(""+(A(e,s)??""),void 0,t,e),ne=({indexId:e,sliceId:s,indexes:t,rowComponent:r=de,getRowComponentProps:l,separator:d,debugIds:u})=>{const a=x(t),n=a?.getStore(),p=a?.getTableId(e),i=E(e,s,a);return re(o(i,(e=>Y(r,{...oe(l,e),key:e,tableId:p,rowId:e,store:n,debugIds:u}))),d,u,s)},pe=({queryId:e,rowId:s,cellId:t,queries:o,debugIds:r})=>re(""+(K(e,s,t,o)??""),void 0,r,t),ie=({queryId:e,rowId:s,queries:t,resultCellComponent:r=pe,getResultCellComponentProps:l,separator:d,debugIds:u})=>re(o(J(e,s,t),(o=>Y(r,{...oe(l,o),key:o,queryId:e,rowId:s,cellId:o,queries:t,debugIds:u}))),d,u,s),Ie=({checkpoints:e,checkpointId:s,debugIds:t})=>re(O(s,e)??"",void 0,t,s),ce=te((e=>e[0])),xe=te((e=>r(e[1])?[]:[e[1]])),we=te((e=>e[2]));exports.BackwardCheckpointsView=ce,exports.CellView=le,exports.CheckpointView=Ie,exports.CurrentCheckpointView=xe,exports.ForwardCheckpointsView=we,exports.IndexView=({indexId:e,indexes:s,sliceComponent:t=ne,getSliceComponentProps:r,separator:l,debugIds:d})=>re(o(G(e,s),(o=>Y(t,{...oe(r,o),key:o,indexId:e,sliceId:o,indexes:s,debugIds:d}))),l,d,e),exports.LinkedRowsView=e=>se(e,j,e.firstRowId),exports.LocalRowsView=e=>se(e,U,e.remoteRowId),exports.MetricView=({metricId:e,metrics:s,debugIds:t})=>re(F(e,s)??"",void 0,t,e),exports.Provider=({store:s,storesById:t,metrics:o,metricsById:r,indexes:l,indexesById:d,relationships:u,relationshipsById:a,queries:p,queriesById:i,checkpoints:I,checkpointsById:c,children:x})=>{const w=e.useContext(n);return Y(n.Provider,{value:Z((()=>[s??w[0],{...w[1],...t},o??w[2],{...w[3],...r},l??w[4],{...w[5],...d},u??w[6],{...w[7],...a},p??w[8],{...w[9],...i},I??w[10],{...w[11],...c}]),[s,t,o,r,l,d,u,a,p,i,I,c,w])},x)},exports.RemoteRowView=({relationshipId:e,localRowId:s,relationships:t,rowComponent:o=de,getRowComponentProps:l,debugIds:d})=>{const[u,a]=ee(t),n=u?.getRemoteTableId(e),p=Q(e,s,u);return re(r(n)||r(p)?null:Y(o,{...oe(l,p),key:p,tableId:n,rowId:p,store:a,debugIds:d}),void 0,d,s)},exports.ResultCellView=pe,exports.ResultRowView=ie,exports.ResultSortedTableView=({cellId:e,descending:s,offset:t,limit:o,...r})=>_(r,H(r.queryId,e,s,t,o,r.queries)),exports.ResultTableView=e=>_(e,z(e.queryId,e.queries)),exports.RowView=de,exports.SliceView=ne,exports.SortedTableView=({cellId:e,descending:s,offset:t,limit:o,...r})=>$(r,f(r.tableId,e,s,t,o,r.store)),exports.TableView=ue,exports.TablesView=({store:e,tableComponent:s=ue,getTableComponentProps:t,separator:r,debugIds:l})=>re(o(P(e),(o=>Y(s,{...oe(t,o),key:o,tableId:o,store:e,debugIds:l}))),r),exports.ValueView=ae,exports.ValuesView=({store:e,valueComponent:s=ae,getValueComponentProps:t,separator:r,debugIds:l})=>re(o(D(e),(o=>Y(s,{...oe(t,o),key:o,valueId:o,store:e,debugIds:l}))),r),exports.tableView=$,exports.useAddRowCallback=(e,s,t=[],o,r=d,u=[])=>{const a=I(o);return b((t=>l(a,(o=>l(s(t,o),(s=>r(o.addRow(e,s),o,s)))))),[a,e,...t,...u])},exports.useCell=M,exports.useCellIds=B,exports.useCellIdsListener=(e,s,t,o,r,l)=>T("CellIds",I(l),t,o,[e,s],r),exports.useCellListener=(e,s,t,o,r,l,d)=>T("Cell",I(d),o,r,[e,s,t],l),exports.useCheckpoint=O,exports.useCheckpointIds=N,exports.useCheckpointIdsListener=(e,s,t)=>T("CheckpointIds",C(t),e,s),exports.useCheckpointListener=(e,s,t,o)=>T("Checkpoint",C(o),s,t,[e]),exports.useCheckpoints=e=>p(e,10),exports.useCreateCheckpoints=(e,s,t)=>L(e,s,t),exports.useCreateIndexes=(e,s,t)=>L(e,s,t),exports.useCreateMetrics=(e,s,t)=>L(e,s,t),exports.useCreatePersister=(e,s,t=[],o,r=[])=>{const[,l]=m(),d=g((()=>s(e)),[e,...t]);return k((()=>((async()=>{await(o?.(d)),l(1)})(),()=>{d.destroy()})),[d,...r]),d},exports.useCreateQueries=(e,s,t)=>L(e,s,t),exports.useCreateRelationships=(e,s,t)=>L(e,s,t),exports.useCreateStore=(e,s=[])=>g(e,s),exports.useDelCellCallback=(e,s,t,o,r,l,d)=>y(r,"Cell",l,d,e,s,t,o),exports.useDelRowCallback=(e,s,t,o,r)=>y(t,"Row",o,r,e,s),exports.useDelTableCallback=(e,s,t,o)=>y(s,"Table",t,o,e),exports.useDelTablesCallback=(e,s,t)=>y(e,"Tables",s,t),exports.useDelValueCallback=(e,s,t,o)=>y(s,"Value",t,o,e),exports.useDelValuesCallback=(e,s,t)=>y(e,"Values",s,t),exports.useGoBackwardCallback=W,exports.useGoForwardCallback=X,exports.useGoToCallback=(e,s=[],t,o=d,r=[])=>{const u=C(t);return b((s=>l(u,(t=>l(e(s),(e=>o(t.goTo(e),e)))))),[u,...s,...r])},exports.useIndexes=e=>p(e,4),exports.useLinkedRowIds=j,exports.useLinkedRowIdsListener=(e,s,t,o,r)=>T("LinkedRowIds",w(r),t,o,[e,s]),exports.useLocalRowIds=U,exports.useLocalRowIdsListener=(e,s,t,o,r)=>T("LocalRowIds",w(r),t,o,[e,s]),exports.useMetric=F,exports.useMetricListener=(e,s,t,o)=>T("Metric",c(o),s,t,[e]),exports.useMetrics=e=>p(e,2),exports.useQueries=e=>p(e,8),exports.useRedoInformation=e=>{const s=C(e),[,,[t]]=N(s);return[!r(t),X(s),t,l(t,(e=>s?.getCheckpoint(e)))??""]},exports.useRelationships=e=>p(e,6),exports.useRemoteRowId=Q,exports.useRemoteRowIdListener=(e,s,t,o,r)=>T("RemoteRowId",w(r),t,o,[e,s]),exports.useResultCell=K,exports.useResultCellIds=J,exports.useResultCellIdsListener=(e,s,t,o,r)=>T("ResultCellIds",R(r),t,o,[e,s]),exports.useResultCellListener=(e,s,t,o,r,l)=>T("ResultCell",R(l),o,r,[e,s,t]),exports.useResultRow=(e,s,t)=>h("ResultRow",R(t),{},[e,s]),exports.useResultRowIds=z,exports.useResultRowIdsListener=(e,s,t,o)=>T("ResultRowIds",R(o),s,t,[e]),exports.useResultRowListener=(e,s,t,o,r)=>T("ResultRow",R(r),t,o,[e,s]),exports.useResultSortedRowIds=H,exports.useResultSortedRowIdsListener=(e,s,t,o,r,l,d,u)=>T("ResultSortedRowIds",R(u),l,d,[e,s,t,o,r]),exports.useResultTable=(e,s)=>h("ResultTable",R(s),{},[e]),exports.useResultTableListener=(e,s,t,o)=>T("ResultTable",R(o),s,t,[e]),exports.useRow=(e,s,t)=>h("Row",I(t),{},[e,s]),exports.useRowIds=q,exports.useRowIdsListener=(e,s,t,o,r)=>T("RowIds",I(r),s,t,[e],o),exports.useRowListener=(e,s,t,o,r,l)=>T("Row",I(l),t,o,[e,s],r),exports.useSetCellCallback=(e,s,t,o,r,l,d,u)=>S(l,"Cell",o,r,d,u,e,s,t),exports.useSetCheckpointCallback=(e=d,s=[],t,o=d,r=[])=>{const u=C(t);return b((s=>l(u,(t=>{const r=e(s);o(t.addCheckpoint(r),t,r)}))),[u,...s,...r])},exports.useSetPartialRowCallback=(e,s,t,o,r,l,d)=>S(r,"PartialRow",t,o,l,d,e,s),exports.useSetPartialValuesCallback=(e,s,t,o,r)=>S(t,"PartialValues",e,s,o,r),exports.useSetRowCallback=(e,s,t,o,r,l,d)=>S(r,"Row",t,o,l,d,e,s),exports.useSetTableCallback=(e,s,t,o,r,l)=>S(o,"Table",s,t,r,l,e),exports.useSetTablesCallback=(e,s,t,o,r)=>S(t,"Tables",e,s,o,r),exports.useSetValueCallback=(e,s,t,o,r,l)=>S(o,"Value",s,t,r,l,e),exports.useSetValuesCallback=(e,s,t,o,r)=>S(t,"Values",e,s,o,r),exports.useSliceIds=G,exports.useSliceIdsListener=(e,s,t,o)=>T("SliceIds",x(o),s,t,[e]),exports.useSliceRowIds=E,exports.useSliceRowIdsListener=(e,s,t,o,r)=>T("SliceRowIds",x(r),t,o,[e,s]),exports.useSortedRowIds=f,exports.useSortedRowIdsListener=(e,s,t,o,r,l,d,u,a)=>T("SortedRowIds",I(a),l,d,[e,s,t,o,r],u),exports.useStore=e=>p(e,0),exports.useTable=(e,s)=>h("Table",I(s),{},[e]),exports.useTableIds=P,exports.useTableIdsListener=(e,s,t,o)=>T("TableIds",I(o),e,s,[],t),exports.useTableListener=(e,s,t,o,r)=>T("Table",I(r),s,t,[e],o),exports.useTables=e=>h("Tables",I(e),{}),exports.useTablesListener=(e,s,t,o)=>T("Tables",I(o),e,s,[],t),exports.useUndoInformation=e=>{const s=C(e),[t,o]=N(s);return[(r=t,!(0==(e=>e.length)(r))),W(s),o,l(o,(e=>s?.getCheckpoint(e)))??""];var r},exports.useValue=A,exports.useValueIds=D,exports.useValueIdsListener=(e,s,t,o)=>T("ValueIds",I(o),e,s,[],t),exports.useValueListener=(e,s,t,o,r)=>T("Value",I(r),s,t,[e],o),exports.useValues=e=>h("Values",I(e),{}),exports.useValuesListener=(e,s,t,o)=>T("Values",I(o),e,s,[],t);
|
|
1
|
+
"use strict";var e=require("react");const s=e=>typeof e,t=s(""),o=(e,s)=>e.map(s),r=e=>null==e,l=(e,s,t)=>r(e)?t?.():s(e),d=e=>s(e)==t,u=()=>{},{createContext:a,useContext:n}=e,p=a([]),i=(e,s)=>{const t=n(p);return r(e)?t[s]:d(e)?((e,s)=>l(e,(e=>e[s])))(t[s+1],e):e},I=(e,s)=>{const t=i(e,s);return r(e)||d(e)?t:e},c=e=>I(e,0),x=e=>I(e,2),w=e=>I(e,4),R=e=>I(e,6),C=e=>I(e,8),b=e=>I(e,10),{useCallback:k,useEffect:g,useMemo:V,useRef:m,useState:L}=e,h=(e,s,t=[])=>{const o=V((()=>s(e)),[e,...t]);return g((()=>()=>o.destroy()),[o]),o},T=(e,s,t,o=[],l)=>{const[,d]=L(),u=k((()=>s?.["get"+e]?.(...o)??t),[s,...o]),[a]=L(u),n=m(a);return V((()=>n.current=u()),[u]),S(e,s,((...e)=>{n.current=r(l)?u():e[l],d([])}),[],o),n.current},S=(e,s,t,o=[],r=[],...l)=>g((()=>{const o=s?.["add"+e+"Listener"]?.(...r,t,...l);return()=>s?.delListener(o)}),[s,...r,...o,...l]),y=(e,s,t,o=[],r=u,d=[],...a)=>{const n=c(e);return k((e=>l(n,(o=>l(t(e,o),(e=>r(o["set"+s](...a,e),e)))))),[n,s,...o,...d,...a])},v=(e,s,t=u,o=[],...r)=>{const l=c(e);return k((()=>t(l?.["del"+s](...r))),[l,s,...o,...r])},P=(e,s,t)=>{const o=b(e);return k((()=>o?.[s](t)),[o,s,t])},q=e=>T("TableIds",c(e),[],[]),f=(e,s)=>T("RowIds",c(s),[],[e]),B=(e,s,t,o=0,r,l)=>T("SortedRowIds",c(l),[],[e,s,t,o,r],6),M=(e,s,t)=>T("CellIds",c(t),[],[e,s]),D=(e,s,t,o)=>T("Cell",c(o),void 0,[e,s,t],4),A=e=>T("ValueIds",c(e),[],[]),F=(e,s)=>T("Value",c(s),void 0,[e]),G=(e,s)=>T("Metric",x(s),void 0,[e]),E=(e,s)=>T("SliceIds",w(s),[],[e]),Q=(e,s,t)=>T("SliceRowIds",w(t),[],[e,s]),U=(e,s,t)=>T("RemoteRowId",R(t),void 0,[e,s]),j=(e,s,t)=>T("LocalRowIds",R(t),[],[e,s]),z=(e,s,t)=>T("LinkedRowIds",R(t),[],[e,s]),H=(e,s)=>T("ResultRowIds",C(s),[],[e]),J=(e,s,t,o=0,r,l)=>T("ResultSortedRowIds",C(l),[],[e,s,t,o,r],6),K=(e,s,t)=>T("ResultCellIds",C(t),[],[e,s]),N=(e,s,t,o)=>T("ResultCell",C(o),void 0,[e,s,t]),O=e=>T("CheckpointIds",b(e),[[],void 0,[]]),W=(e,s)=>T("Checkpoint",b(s),void 0,[e]),X=e=>P(e,"goBackward"),Y=e=>P(e,"goForward"),{createElement:Z,useMemo:$}=e,_=({tableId:e,store:s,rowComponent:t=ue,getRowComponentProps:r,separator:l,debugIds:d},u)=>le(o(u,(o=>Z(t,{...re(r,o),key:o,tableId:e,rowId:o,store:s,debugIds:d}))),l,d,e),ee=({queryId:e,queries:s,resultRowComponent:t=Ie,getResultRowComponentProps:r,separator:l,debugIds:d},u)=>le(o(u,(o=>Z(t,{...re(r,o),key:o,queryId:e,rowId:o,queries:s,debugIds:d}))),l,d,e),se=e=>{const s=R(e);return[s,s?.getStore()]},te=({relationshipId:e,relationships:s,rowComponent:t=ue,getRowComponentProps:r,separator:l,debugIds:d},u,a)=>{const[n,p]=se(s),i=n?.getLocalTableId(e),I=u(e,a,n);return le(o(I,(e=>Z(t,{...re(r,e),key:e,tableId:i,rowId:e,store:p,debugIds:d}))),l,d,a)},oe=e=>({checkpoints:s,checkpointComponent:t=ce,getCheckpointComponentProps:r,separator:l,debugIds:d})=>{const u=b(s);return le(o(e(O(u)),(e=>Z(t,{...re(r,e),key:e,checkpoints:u,checkpointId:e,debugIds:d}))),l)},re=(e,s)=>r(e)?{}:e(s),le=(e,s,t,l)=>{const d=r(s)||!Array.isArray(e)?e:o(e,((e,t)=>t>0?[s,e]:e));return t?[l,":{",d,"}"]:d},de=({tableId:e,rowId:s,cellId:t,store:o,debugIds:r})=>le(""+(D(e,s,t,o)??""),void 0,r,t),ue=({tableId:e,rowId:s,store:t,cellComponent:r=de,getCellComponentProps:l,separator:d,debugIds:u})=>le(o(M(e,s,t),(o=>Z(r,{...re(l,o),key:o,tableId:e,rowId:s,cellId:o,store:t,debugIds:u}))),d,u,s),ae=e=>_(e,f(e.tableId,e.store)),ne=({valueId:e,store:s,debugIds:t})=>le(""+(F(e,s)??""),void 0,t,e),pe=({indexId:e,sliceId:s,indexes:t,rowComponent:r=ue,getRowComponentProps:l,separator:d,debugIds:u})=>{const a=w(t),n=a?.getStore(),p=a?.getTableId(e),i=Q(e,s,a);return le(o(i,(e=>Z(r,{...re(l,e),key:e,tableId:p,rowId:e,store:n,debugIds:u}))),d,u,s)},ie=({queryId:e,rowId:s,cellId:t,queries:o,debugIds:r})=>le(""+(N(e,s,t,o)??""),void 0,r,t),Ie=({queryId:e,rowId:s,queries:t,resultCellComponent:r=ie,getResultCellComponentProps:l,separator:d,debugIds:u})=>le(o(K(e,s,t),(o=>Z(r,{...re(l,o),key:o,queryId:e,rowId:s,cellId:o,queries:t,debugIds:u}))),d,u,s),ce=({checkpoints:e,checkpointId:s,debugIds:t})=>le(W(s,e)??"",void 0,t,s),xe=oe((e=>e[0])),we=oe((e=>r(e[1])?[]:[e[1]])),Re=oe((e=>e[2]));exports.BackwardCheckpointsView=xe,exports.CellView=de,exports.CheckpointView=ce,exports.CurrentCheckpointView=we,exports.ForwardCheckpointsView=Re,exports.IndexView=({indexId:e,indexes:s,sliceComponent:t=pe,getSliceComponentProps:r,separator:l,debugIds:d})=>le(o(E(e,s),(o=>Z(t,{...re(r,o),key:o,indexId:e,sliceId:o,indexes:s,debugIds:d}))),l,d,e),exports.LinkedRowsView=e=>te(e,z,e.firstRowId),exports.LocalRowsView=e=>te(e,j,e.remoteRowId),exports.MetricView=({metricId:e,metrics:s,debugIds:t})=>le(G(e,s)??"",void 0,t,e),exports.Provider=({store:s,storesById:t,metrics:o,metricsById:r,indexes:l,indexesById:d,relationships:u,relationshipsById:a,queries:n,queriesById:i,checkpoints:I,checkpointsById:c,children:x})=>{const w=e.useContext(p);return Z(p.Provider,{value:$((()=>[s??w[0],{...w[1],...t},o??w[2],{...w[3],...r},l??w[4],{...w[5],...d},u??w[6],{...w[7],...a},n??w[8],{...w[9],...i},I??w[10],{...w[11],...c}]),[s,t,o,r,l,d,u,a,n,i,I,c,w])},x)},exports.RemoteRowView=({relationshipId:e,localRowId:s,relationships:t,rowComponent:o=ue,getRowComponentProps:l,debugIds:d})=>{const[u,a]=se(t),n=u?.getRemoteTableId(e),p=U(e,s,u);return le(r(n)||r(p)?null:Z(o,{...re(l,p),key:p,tableId:n,rowId:p,store:a,debugIds:d}),void 0,d,s)},exports.ResultCellView=ie,exports.ResultRowView=Ie,exports.ResultSortedTableView=({cellId:e,descending:s,offset:t,limit:o,...r})=>ee(r,J(r.queryId,e,s,t,o,r.queries)),exports.ResultTableView=e=>ee(e,H(e.queryId,e.queries)),exports.RowView=ue,exports.SliceView=pe,exports.SortedTableView=({cellId:e,descending:s,offset:t,limit:o,...r})=>_(r,B(r.tableId,e,s,t,o,r.store)),exports.TableView=ae,exports.TablesView=({store:e,tableComponent:s=ae,getTableComponentProps:t,separator:r,debugIds:l})=>le(o(q(e),(o=>Z(s,{...re(t,o),key:o,tableId:o,store:e,debugIds:l}))),r),exports.ValueView=ne,exports.ValuesView=({store:e,valueComponent:s=ne,getValueComponentProps:t,separator:r,debugIds:l})=>le(o(A(e),(o=>Z(s,{...re(t,o),key:o,valueId:o,store:e,debugIds:l}))),r),exports.tableView=_,exports.useAddRowCallback=(e,s,t=[],o,r=u,d=[])=>{const a=c(o);return k((t=>l(a,(o=>l(s(t,o),(s=>r(o.addRow(e,s),o,s)))))),[a,e,...t,...d])},exports.useCell=D,exports.useCellIds=M,exports.useCellIdsListener=(e,s,t,o,r,l)=>S("CellIds",c(l),t,o,[e,s],r),exports.useCellListener=(e,s,t,o,r,l,d)=>S("Cell",c(d),o,r,[e,s,t],l),exports.useCheckpoint=W,exports.useCheckpointIds=O,exports.useCheckpointIdsListener=(e,s,t)=>S("CheckpointIds",b(t),e,s),exports.useCheckpointListener=(e,s,t,o)=>S("Checkpoint",b(o),s,t,[e]),exports.useCheckpoints=e=>i(e,10),exports.useCreateCheckpoints=(e,s,t)=>h(e,s,t),exports.useCreateIndexes=(e,s,t)=>h(e,s,t),exports.useCreateMetrics=(e,s,t)=>h(e,s,t),exports.useCreatePersister=(e,s,t=[],o,r=[])=>{const[,l]=L(),d=V((()=>s(e)),[e,...t]);return g((()=>((async()=>{await(o?.(d)),l(1)})(),()=>{d.destroy()})),[d,...r]),d},exports.useCreateQueries=(e,s,t)=>h(e,s,t),exports.useCreateRelationships=(e,s,t)=>h(e,s,t),exports.useCreateStore=(e,s=[])=>V(e,s),exports.useDelCellCallback=(e,s,t,o,r,l,d)=>v(r,"Cell",l,d,e,s,t,o),exports.useDelRowCallback=(e,s,t,o,r)=>v(t,"Row",o,r,e,s),exports.useDelTableCallback=(e,s,t,o)=>v(s,"Table",t,o,e),exports.useDelTablesCallback=(e,s,t)=>v(e,"Tables",s,t),exports.useDelValueCallback=(e,s,t,o)=>v(s,"Value",t,o,e),exports.useDelValuesCallback=(e,s,t)=>v(e,"Values",s,t),exports.useGoBackwardCallback=X,exports.useGoForwardCallback=Y,exports.useGoToCallback=(e,s=[],t,o=u,r=[])=>{const d=b(t);return k((s=>l(d,(t=>l(e(s),(e=>o(t.goTo(e),e)))))),[d,...s,...r])},exports.useIndexes=e=>i(e,4),exports.useLinkedRowIds=z,exports.useLinkedRowIdsListener=(e,s,t,o,r)=>S("LinkedRowIds",R(r),t,o,[e,s]),exports.useLocalRowIds=j,exports.useLocalRowIdsListener=(e,s,t,o,r)=>S("LocalRowIds",R(r),t,o,[e,s]),exports.useMetric=G,exports.useMetricListener=(e,s,t,o)=>S("Metric",x(o),s,t,[e]),exports.useMetrics=e=>i(e,2),exports.useQueries=e=>i(e,8),exports.useRedoInformation=e=>{const s=b(e),[,,[t]]=O(s);return[!r(t),Y(s),t,l(t,(e=>s?.getCheckpoint(e)))??""]},exports.useRelationships=e=>i(e,6),exports.useRemoteRowId=U,exports.useRemoteRowIdListener=(e,s,t,o,r)=>S("RemoteRowId",R(r),t,o,[e,s]),exports.useResultCell=N,exports.useResultCellIds=K,exports.useResultCellIdsListener=(e,s,t,o,r)=>S("ResultCellIds",C(r),t,o,[e,s]),exports.useResultCellListener=(e,s,t,o,r,l)=>S("ResultCell",C(l),o,r,[e,s,t]),exports.useResultRow=(e,s,t)=>T("ResultRow",C(t),{},[e,s]),exports.useResultRowIds=H,exports.useResultRowIdsListener=(e,s,t,o)=>S("ResultRowIds",C(o),s,t,[e]),exports.useResultRowListener=(e,s,t,o,r)=>S("ResultRow",C(r),t,o,[e,s]),exports.useResultSortedRowIds=J,exports.useResultSortedRowIdsListener=(e,s,t,o,r,l,d,u)=>S("ResultSortedRowIds",C(u),l,d,[e,s,t,o,r]),exports.useResultTable=(e,s)=>T("ResultTable",C(s),{},[e]),exports.useResultTableListener=(e,s,t,o)=>S("ResultTable",C(o),s,t,[e]),exports.useRow=(e,s,t)=>T("Row",c(t),{},[e,s]),exports.useRowIds=f,exports.useRowIdsListener=(e,s,t,o,r)=>S("RowIds",c(r),s,t,[e],o),exports.useRowListener=(e,s,t,o,r,l)=>S("Row",c(l),t,o,[e,s],r),exports.useSetCellCallback=(e,s,t,o,r,l,d,u)=>y(l,"Cell",o,r,d,u,e,s,t),exports.useSetCheckpointCallback=(e=u,s=[],t,o=u,r=[])=>{const d=b(t);return k((s=>l(d,(t=>{const r=e(s);o(t.addCheckpoint(r),t,r)}))),[d,...s,...r])},exports.useSetPartialRowCallback=(e,s,t,o,r,l,d)=>y(r,"PartialRow",t,o,l,d,e,s),exports.useSetPartialValuesCallback=(e,s,t,o,r)=>y(t,"PartialValues",e,s,o,r),exports.useSetRowCallback=(e,s,t,o,r,l,d)=>y(r,"Row",t,o,l,d,e,s),exports.useSetTableCallback=(e,s,t,o,r,l)=>y(o,"Table",s,t,r,l,e),exports.useSetTablesCallback=(e,s,t,o,r)=>y(t,"Tables",e,s,o,r),exports.useSetValueCallback=(e,s,t,o,r,l)=>y(o,"Value",s,t,r,l,e),exports.useSetValuesCallback=(e,s,t,o,r)=>y(t,"Values",e,s,o,r),exports.useSliceIds=E,exports.useSliceIdsListener=(e,s,t,o)=>S("SliceIds",w(o),s,t,[e]),exports.useSliceRowIds=Q,exports.useSliceRowIdsListener=(e,s,t,o,r)=>S("SliceRowIds",w(r),t,o,[e,s]),exports.useSortedRowIds=B,exports.useSortedRowIdsListener=(e,s,t,o,r,l,d,u,a)=>S("SortedRowIds",c(a),l,d,[e,s,t,o,r],u),exports.useStore=e=>i(e,0),exports.useTable=(e,s)=>T("Table",c(s),{},[e]),exports.useTableIds=q,exports.useTableIdsListener=(e,s,t,o)=>S("TableIds",c(o),e,s,[],t),exports.useTableListener=(e,s,t,o,r)=>S("Table",c(r),s,t,[e],o),exports.useTables=e=>T("Tables",c(e),{}),exports.useTablesListener=(e,s,t,o)=>S("Tables",c(o),e,s,[],t),exports.useUndoInformation=e=>{const s=b(e),[t,o]=O(s);return[(r=t,!(0==(e=>e.length)(r))),X(s),o,l(o,(e=>s?.getCheckpoint(e)))??""];var r},exports.useValue=F,exports.useValueIds=A,exports.useValueIdsListener=(e,s,t,o)=>S("ValueIds",c(o),e,s,[],t),exports.useValueListener=(e,s,t,o,r)=>S("Value",c(r),s,t,[e],o),exports.useValues=e=>T("Values",c(e),{}),exports.useValuesListener=(e,s,t,o)=>S("Values",c(o),e,s,[],t);
|
package/lib/cjs/ui-react.cjs.gz
CHANGED
|
Binary file
|
package/lib/cjs-es6/tools.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=e=>typeof e,a="",l=e(a),t=e(!0),o=e(0),s="type",n="default",r=(e,a)=>e.every(a),d=(e,a)=>e.sort(a),$=(e,a)=>e.forEach(a),i=(e,a)=>e.map(a),u=e=>e.length,I=e=>0==u(e),c=(e,...a)=>e.push(...a),b=e=>e.pop(),w=(e,...a)=>e.unshift(...a),h=e=>e.shift(),g=JSON.parse,C=isFinite,T=(e,a)=>e instanceof a,V=e=>null==e,v=e=>e==l||e==t,f=a=>e(a)==l,R=e=>Array.isArray(e),m=a=>{const l=e(a);return v(l)||l==o&&C(a)?l:void 0},p=(e,a)=>{var l;return null!=(l=null==e?void 0:e.has(a))&&l},L=e=>{var a;return[...null!=(a=null==e?void 0:e.values())?a:[]]},y=(e,a)=>null==e?void 0:e.forEach(a),S=(e,a)=>null==e?void 0:e.delete(a),k=e=>new Map(e),J=(e,a)=>null==e?void 0:e.get(a),E=(e,a)=>y(e,((e,l)=>a(l,e))),O=(e,a)=>{var l;return i([...null!=(l=null==e?void 0:e.entries())?l:[]],(([e,l])=>a(l,e)))},j=(e,a,l)=>V(l)?(S(e,a),e):null==e?void 0:e.set(a,l),x=(e,a,l)=>(p(e,a)||j(e,a,l()),J(e,a)),A=e=>new Set(R(e)||V(e)?e:[e]),P=(e,a)=>null==e?void 0:e.add(a),D=e=>[e,e],N=()=>[k(),k()],G=/[^A-Za-z]+/,z=/[^A-Za-z0-9]+/,F=/^( *)\/\*\* *(.*?) *\*\/$/gm,W=(e,a,l)=>e.substring(a,l),M=e=>e.toUpperCase(),Z=e=>e.toLowerCase(),_=(e,a,l,t=1)=>{const o=`${a}${1==t?"":t}`;return p(e,o)?_(e,a,l,t+1):(j(e,o,l),o)},Q=e=>e.replace(F,((e,a,l)=>{const t=77-U(a);return`${a}/**\n${l.replace(RegExp(`([^\\n]{1,${t}})(\\s|$)`,"g"),a+" * $1\n")}${a} */`})),U=e=>e.length,q=(e,l=a)=>e.join(l),B=e=>e.flat(1e3),H=(e,a=0)=>q(i(e.split(z),((e,l)=>(l>0||a?M:Z)(W(e,0,1))+W(e,1)))),K=e=>M(q((e&&!G.test(e[0])?e:" "+e).split(z),"_")),X=e=>`/** ${e}. */`,Y=()=>{const e=N(),l=k(),t=k(),o=k();return[(...e)=>q(B(e),"\n"),(a,l,...t)=>$(t,(t=>P(x(e[a],l,A),t))),(e,a,t)=>_(l,e,[a,t]),(e,a,l,o,s,n="")=>_(t,e,[a,l,o,s,n]),(e,a,l)=>_(o,e,R(l)?[`(${a}) => {`,l,"}"]:[`(${a}) => ${l}`]),(e,a)=>J(o,e)===a?e:_(o,e,a),l=>[...d(O(e[l],((e,a)=>`import {${q(d(L(e)),", ")}} from '${a}';`))),a],()=>O(l,(([e,l],t)=>[X(l),`export type ${t} = ${e};`,a])),e=>O(t,(([l,t,o,s,n],r)=>{const d=e?[`${r}: ${n}(${l}): ${t} => ${o},`]:[`${r}${n}(${l}): ${t};`];return e||w(d,X(s)),c(d,a),d})),()=>O(o,((e,l)=>(e=R(e)?e:[e],c(e,b(e)+";"),[`const ${l} = ${h(e)}`,e,a])))]},ee=Object,ae=ee.keys,le=ee.freeze,te=e=>T(e,ee)&&e.constructor==ee,oe=(e,a)=>i(ee.entries(e),(([e,l])=>a(l,e))),se=e=>te(e)&&I(ae(e)),ne=e=>{const a=new WeakMap;return l=>(a.has(l)||a.set(l,e(l)),a.get(l))},re="the Store",de="A function for",$e="export",ie="listener",ue=" | undefined",Ie=`Registers a ${ie} that will be called`,ce="Represents",be=" => void",we="the end of the transaction",he="the specified Row",ge="a string serialization of",Ce=(e=0,a=0)=>`the ${De[e]}content of${a?" "+re:""}`,Te=(e,a=0,l=0)=>`${Ae[e]} ${Ce(a,1)}${l?" when set":""}`,Ve=(e,a=0)=>`${ce} a Row when ${a?"s":"g"}etting ${Ce()} the '${e}' Table`,ve=(e,a,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in ${a}`,fe=(e,a)=>`Calls a function for each ${e} in ${a}`,Re=(e,a=re)=>`Gets whether ${e} exists in ${a}`,me=e=>"A function that takes "+e,pe=(e,a=0)=>`${de} listening to changes to ${Pe[e]} in ${Pe[a]}`,Le=(e,l,t=0)=>`${Ie} whenever ${e} in ${l} change`+(t?a:"s"),ye=e=>`the '${e}' Table`,Se=e=>`${he} in ${ye(e)}`,ke=e=>`the '${e}' Cell`,Je=e=>`the '${e}' Value`,Ee=(e,a=0)=>`${Ae[a]} ${Ce()} ${ye(e)}`,Oe=(e,a=0)=>`${Ae[a]} ${Ce()} ${Se(e)}`,je=(e,a,l=0)=>`${Ae[l]} ${ke(a)} for ${Se(e)}`,xe=(e,a=0)=>`${Ae[a]} ${Je(e)}`,Ae=["Gets","Sets","Sets part of","Deletes",ce,"Gets "+ge,"Sets "+ge,Ie+" whenever"],Pe=[re,"Tables","Table Ids","a Table","Row Ids","a Row","Cell Ids","a Cell","invalid Cell changes","Values","Value Ids","a Value","invalid Value changes"],De=["","tabular ","keyed value "],Ne=["DoRollback","Id","IdOrNull","Ids","Json","Store"],Ge=(e,l=a,t=a)=>`store.${e}(${l})${t?" as "+t:a}`,ze=(e,l=a)=>`fluent(() => ${Ge(e,l)})`,Fe=(e,l=a,t=a)=>`store.${e}(${l?l+", ":a}proxy(${ie})${t?", "+t:a})`,We=(e,l,o)=>{if(se(e)&&se(l))return D(a);const[r,d,$,i,u,I,b,w,h,g]=Y(),C=`./${H(o)}.d`,T=H(o,1),v=H(T),R=[],m=k(),p=l=>oe(e,((e,t)=>l(t,x(m,t,(()=>{const e=H(t,1);return[$(e+"Table",`{[rowId: Id]: ${e}Row}`,`${ce} the '${t}' Table`),$(e+"Row",`{${q(y(t,((e,l,t)=>`'${e}'${V(t)?"?":a}: ${l};`))," ")}}`,Ve(t)),$(e+"RowWhenSet",`{${q(y(t,((e,a)=>`'${e}'?: ${a};`))," ")}}`,Ve(t,1)),$(e+"CellId",q(y(t,(e=>`'${e}'`))," | "),`A Cell Id for the '${t}' Table`),$(e+"CellCallback",`(...[cellId, cell]: ${q(y(t,((e,a)=>`[cellId: '${e}', cell: ${a}]`))," | ")})${be}`,me(`a Cell Id and value from a Row in the '${t}' Table`)),$(e+"RowCallback",`(rowId: Id, forEachCell: (cellCallback: ${e}CellCallback)${be})${be}`,me(`a Row Id from the '${t}' Table, and a Cell iterator`))]})),H(t,1),I(K(t),`'${t}'`)))),y=(a,l)=>oe(e[a],((e,a)=>l(a,e[s],e[n],I(K(a),`'${a}'`),H(a,1)))),S=e=>oe(l,((a,l)=>e(l,a[s],a[n],I(K(l),`'${l}'`),H(l,1))));if(d(1,C,T,`create${T} as create${T}Decl`),!se(e)){const e=$("Tables",`{${q(p(((e,a)=>`'${e}'?: ${a[0]};`))," ")}}`,Te(4,1)),l=$("TableId",q(p((e=>`'${e}'`))," | "),"A Table Id in "+re),o=$("TableCallback",`(...[tableId, rowCallback]: ${q(p(((e,a)=>`[tableId: '${e}', forEachRow: (rowCallback: ${a[5]})${be}]`))," | ")})${be}`,me("a Table Id, and a Row iterator")),r=$("GetCellChange",`(...[tableId, rowId, cellId]: ${q(p(((e,a)=>`[tableId: '${e}', rowId: Id, cellId: ${a[3]}]`))," | ")}) => CellChange`,de+" returning information about any Cell's changes during a transaction"),u=$("TablesListener",`(${v}: ${T}, getCellChange: ${r}${ue})${be}`,pe(1)),b=$("TableIdsListener",`(${v}: ${T})${be}`,pe(2)),w=$("TableListener",`(${v}: ${T}, tableId: ${l}, getCellChange: ${r}${ue})${be}`,pe(3)),h=$("RowIdsListener",`(${v}: ${T}, tableId: ${l})`+be,pe(4,3)),g=$("RowListener",`(${v}: ${T}, tableId: ${l}, rowId: Id, getCellChange: ${r}${ue})${be}`,pe(5,3)),m=$("CellIdsListener",`(${v}: ${T}, tableId: ${l}, rowId: Id)`+be,pe(6,5)),S=$("CellListener",`(...[${v}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${q(B(p((e=>y(e,((a,l)=>`[${v}: ${T}, tableId: '${e}', rowId: Id, cellId: '${a}', newCell: ${l}${ue}, oldCell: ${l}${ue}, getCellChange: ${r} | undefined]`)))))," | ")})${be}`,pe(7,5)),J=$("InvalidCellListener",`(${v}: ${T}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])${be}`,pe(8));i("hasTables",a,t,Ge("hasTables"),Re("any Table")),i("getTables",a,e,Ge("getTables"),Te(0,1)),i("setTables","tables: "+e,T,ze("setTables","tables"),Te(1,1)),i("delTables",a,T,ze("delTables"),Te(3,1)),i("getTableIds",a,l+"[]",Ge("getTableIds",a,l+"[]"),ve("Table",re)),i("forEachTable","tableCallback: "+o,"void",Ge("forEachTable","tableCallback as any"),fe("Table",re));const O=k();p(((e,[l,o,s,n,r,$],u,I)=>{d(1,C,l,o,s,n,r,$),i(`has${u}Table`,a,t,Ge("hasTable",I),Re(ye(e))),i(`get${u}Table`,a,l,Ge("getTable",I,l),Ee(e)),i(`set${u}Table`,"table: "+l,T,ze("setTable",I+", table"),Ee(e,1)),i(`del${u}Table`,a,T,ze("delTable",I),Ee(e,3)),i(`get${u}RowIds`,a,"Ids",Ge("getRowIds",I),ve("Row",ye(e))),i(`get${u}SortedRowIds`,`cellId?: ${n}, descending?: boolean, offset?: number, limit?: number`,"Ids",Ge("getSortedRowIds",I+", cellId, descending, offset, limit"),ve("Row",ye(e),1)),i(`forEach${u}Row`,"rowCallback: "+$,"void",Ge("forEachRow",I+", rowCallback as any"),fe("Row",ye(e))),i(`has${u}Row`,"rowId: Id",t,Ge("hasRow",I+", rowId"),Re(he,ye(e))),i(`get${u}Row`,"rowId: Id",o,Ge("getRow",I+", rowId",o),Oe(e)),i(`set${u}Row`,"rowId: Id, row: "+s,T,ze("setRow",I+", rowId, row"),Oe(e,1)),i(`add${u}Row`,"row: "+s,"Id"+ue,Ge("addRow",I+", row"),"Adds a new Row to "+ye(e)),i(`set${u}PartialRow`,"rowId: Id, partialRow: "+s,T,ze("setPartialRow",I+", rowId, partialRow"),Oe(e,2)),i(`del${u}Row`,"rowId: Id",T,ze("delRow",I+", rowId"),Oe(e,3)),i(`get${u}CellIds`,"rowId: Id",n+"[]",Ge("getCellIds",I+", rowId",n+"[]"),ve("Cell",Se(e))),i(`forEach${u}Cell`,"rowId: Id, cellCallback: "+r,"void",Ge("forEachCell",I+", rowId, cellCallback as any"),fe("Cell",Se(e))),y(e,((l,o,s,n,r)=>{const d="Map"+H(o,1);j(O,o,d),i(`has${u}${r}Cell`,"rowId: Id",t,Ge("hasCell",`${I}, rowId, ${n}`),Re(ke(l),Se(e)));const $=`${o}${V(s)?ue:a}`;i(`get${u}${r}Cell`,"rowId: Id",$,Ge("getCell",`${I}, rowId, ${n}`,$),je(e,l)),i(`set${u}${r}Cell`,`rowId: Id, cell: ${o} | ${d}`,T,ze("setCell",`${I}, rowId, ${n}, cell as any`),je(e,l,1)),i(`del${u}${r}Cell`,"rowId: Id",T,ze("delCell",`${I}, rowId, ${n}`),je(e,l,3))}))})),i("getTablesJson",a,"Json",Ge("getTablesJson"),Te(5,1)),i("setTablesJson","tablesJson: Json",T,ze("setTablesJson","tablesJson"),Te(6,1)),i("addTablesListener",`${ie}: ${u}, mutator?: boolean`,"Id",Fe("addTablesListener",a,"mutator"),Te(7,1)+" changes"),i("addTableIdsListener",`${ie}: ${b}, mutator?: boolean`,"Id",Fe("addTableIdsListener",a,"mutator"),Le("the Table Ids",re,1)),i("addTableListener",`tableId: ${l} | null, ${ie}: ${w}, mutator?: boolean`,"Id",Fe("addTableListener","tableId","mutator"),Le("a Table",re)),i("addRowIdsListener",`tableId: ${l} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Fe("addRowIdsListener","tableId","mutator"),Le("the Row Ids","a Table",1)),i("addRowListener",`tableId: ${l} | null, rowId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Fe("addRowListener","tableId, rowId","mutator"),Le("a Row","a Table")),i("addCellIdsListener",`tableId: ${l} | null, rowId: IdOrNull, ${ie}: ${m}, mutator?: boolean`,"Id",Fe("addCellIdsListener","tableId, rowId","mutator"),Le("the Cell Ids","a Row",1)),i("addCellListener",`tableId: ${l} | null, rowId: IdOrNull, cellId: ${q(p(((e,a)=>a[3]))," | ")} | null, ${ie}: ${S}, mutator?: boolean`,"Id",Fe("addCellListener","tableId, rowId, cellId","mutator"),Le("a Cell","a Row")),i("addInvalidCellListener",`tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull, ${ie}: ${J}, mutator?: boolean`,"Id",Fe("addInvalidCellListener","tableId, rowId, cellId","mutator"),Ie+" whenever an invalid Cell change was attempted"),E(O,((e,a)=>$(a,`(cell: ${e}${ue}) => ${e}`,`Takes a ${e} Cell value and returns another`))),d(1,C,e,l,o,u,b,w,h,g,m,S,J,...L(O)),d(0,"tinybase","CellChange"),c(R,".setTablesSchema({",B(p(((e,l,t,o)=>[`[${o}]: {`,...y(e,((e,l,t,o)=>`[${o}]: {[${I(K(s),`'${s}'`)}]: ${I(K(l),`'${l}'`)}${V(t)?a:`, [${I(K(n),`'${n}'`)}]: ${f(t)?I(K(t),`'${t}'`):t}`}},`)),"},"]))),"})")}if(!se(l)){const e=$("Values",`{${q(S(((e,l,t)=>`'${e}'${V(t)?"?":a}: ${l};`))," ")}}`,Te(4,2)),l=$("ValuesWhenSet",`{${q(S(((e,a)=>`'${e}'?: ${a};`))," ")}}`,Te(4,2,1)),o=$("ValueId",q(S((e=>`'${e}'`))," | "),"A Value Id in "+re),r=$("ValueCallback",`(...[valueId, rowCallback]: ${q(S(((e,a)=>`[valueId: '${e}', value: ${a}]`))," | ")})${be}`,me("a Value Id, and value")),u=$("GetValueChange",`(valueId: ${o}) => ValueChange`,de+" returning information about any Value's changes during a transaction"),b=$("ValuesListener",`(${v}: ${T}, getValueChange: ${u}${ue})`+be,pe(9)),w=$("ValueIdsListener",`(${v}: ${T})${be}`,pe(10)),h=$("ValueListener",`(...[${v}, valueId, newValue, oldValue, getValueChange]: ${q(S(((e,a)=>`[${v}: ${T}, valueId: '${e}', newValue: ${a}${ue}, oldValue: ${a}${ue}, getValueChange: ${u} | undefined]`))," | ")})${be}`,pe(11)),g=$("InvalidValueListener",`(${v}: ${T}, valueId: Id, invalidValues: any[])${be}`,pe(12));i("hasValues",a,t,Ge("hasValues"),Re("any Value")),i("getValues",a,e,Ge("getValues",a,e),Te(0,2)),i("setValues","values: "+l,T,ze("setValues","values"),Te(1,2)),i("setPartialValues","partialValues: "+l,T,ze("setPartialValues","partialValues"),Te(2,2)),i("delValues",a,T,ze("delValues"),Te(3,2)),i("getValueIds",a,o+"[]",Ge("getValueIds",a,o+"[]"),ve("Value",re)),i("forEachValue","valueCallback: "+r,"void",Ge("forEachValue","valueCallback as any"),fe("Value",re)),S(((e,l,o,s,n)=>{i(`has${n}Value`,a,t,Ge("hasValue",s),Re(Je(e))),i(`get${n}Value`,a,l,Ge("getValue",s,l),xe(e)),i(`set${n}Value`,"value: "+l,T,ze("setValue",s+", value"),xe(e,1)),i(`del${n}Value`,a,T,ze("delValue",s),xe(e,3))})),i("getValuesJson",a,"Json",Ge("getValuesJson"),Te(5,2)),i("setValuesJson","valuesJson: Json",T,ze("setValuesJson","valuesJson"),Te(6,2)),i("addValuesListener",`${ie}: ${b}, mutator?: boolean`,"Id",Fe("addValuesListener",a,"mutator"),Te(7,2)+" changes"),i("addValueIdsListener",`${ie}: ${w}, mutator?: boolean`,"Id",Fe("addValueIdsListener",a,"mutator"),Le("the Value Ids",re,1)),i("addValueListener",`valueId: ${o} | null, ${ie}: ${h}, mutator?: boolean`,"Id",Fe("addValueListener","valueId","mutator"),Le("a Value",re)),i("addInvalidValueListener",`valueId: IdOrNull, ${ie}: ${g}, mutator?: boolean`,"Id",Fe("addInvalidValueListener","valueId","mutator"),Ie+" whenever an invalid Cell change was attempted"),d(1,C,e,l,o,r,b,w,h,g),d(0,"tinybase","ValueChange"),c(R,".setValuesSchema({",S(((e,l,t,o)=>[`[${o}]: {[${I(K(s),`'${s}'`)}]: ${I(K(l),`'${l}'`)}${V(t)?a:`, [${I(K(n),`'${n}'`)}]: ${f(t)?I(K(t),`'${t}'`):t}`}},`])),"})")}d(0,"tinybase",...Ne);const J=$("TransactionListener",`(${v}: ${T}, cellsTouched: boolean, valuesTouched: boolean)${be}`,de+" listening to the completion of a transaction");return i("getJson",a,"Json",Ge("getJson"),Te(5)),i("setJson","json: Json",T,ze("setJson","json"),Te(6)),i("transaction","actions: () => Return, doRollback?: DoRollback","Return",Ge("transaction","actions, doRollback"),"Execute a transaction to make multiple mutations","<Return>"),i("startTransaction",a,T,ze("startTransaction"),"Explicitly starts a transaction"),i("finishTransaction","doRollback?: DoRollback,",T,ze("finishTransaction","doRollback"),"Explicitly finishes a transaction"),i("addWillFinishTransactionListener",`${ie}: ${J}`,"Id",Fe("addWillFinishTransactionListener"),`${Ie} just before ${we}`),i("addDidFinishTransactionListener",`${ie}: ${J}`,"Id",Fe("addDidFinishTransactionListener"),`${Ie} just after ${we}`),i("callListener",ie+"Id: Id",T,ze("callListener",ie+"Id"),`Manually provoke a ${ie} to be called`),i("delListener",ie+"Id: Id",T,ze("delListener",ie+"Id"),`Remove a ${ie} that was previously added to ${re}`),i("getStore",a,"Store","store",Ae[0]+" the underlying Store object"),d(1,"tinybase","createStore",...Ne),d(1,C,T,`create${T} as create${T}Decl`,J),I("store",["createStore()",...R]),u("fluent","actions: () => Store",["actions();",`return ${v};`]),u("proxy",ie+": any",`(_: Store, ...args: any[]) => ${ie}(${v}, ...args)`),I(v,["{",...h(1),"}"]),[r(...b(0),...w(),`${$e} interface ${T} {`,...h(0),"}",a,X(`Creates a ${T} object`),`${$e} function create${T}(): ${T};`),r(...b(1),`${$e} const create${T}: typeof create${T}Decl = () => {`,...g(),`return Object.freeze(${v});`,"};")]};var Me=Object.defineProperty,Ze=Object.getOwnPropertySymbols,_e=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Ue=(e,a,l)=>a in e?Me(e,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[a]=l,qe=(e,a)=>{for(var l in a||(a={}))_e.call(a,l)&&Ue(e,l,a[l]);if(Ze)for(var l of Ze(a))Qe.call(a,l)&&Ue(e,l,a[l]);return e},Be=(e,a,l)=>new Promise(((t,o)=>{var s=e=>{try{r(l.next(e))}catch(e){o(e)}},n=e=>{try{r(l.throw(e))}catch(e){o(e)}},r=e=>e.done?t(e.value):Promise.resolve(e.value).then(s,n);r((l=l.apply(e,a)).next())}));const He={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},Ke=ne((e=>{const a=()=>{const a=g(e.getTablesSchemaJson());return!se(a)||r(e.getTableIds(),(l=>{const t=e.getRowIds(l),o=k();if(r(t,(a=>r(e.getCellIds(l,a),(t=>{const s=e.getCell(l,a,t),n=x(o,t,(()=>[m(s),k(),[0],0])),[r,d,[$]]=n,i=x(d,s,(()=>0))+1;return i>$&&(n[2]=[i,s]),j(d,s,i),n[3]++,r==m(s)})))))return a[l]={},y(o,(([e,,[,o],r],d)=>{a[l][d]=qe({[s]:e},r==u(t)?{[n]:o}:{})})),1}))?a:{}},l=()=>{const a=g(e.getValuesSchemaJson());return se(a)&&e.forEachValue(((e,l)=>{a[e]={[s]:m(l)}})),a},t=e=>We(a(),l(),e),o=e=>Be(void 0,null,(function*(){let a;try{a=(yield import("prettier")).format}catch(e){a=e=>e}return i(t(e),(e=>Q(a(e,He))))}));return le({getStoreStats:a=>{let l=0,t=0,o=0;const s={};return e.forEachTable(((e,n)=>{l++;let r=0,d=0;const $={};n(((e,l)=>{r++;let t=0;l((()=>t++)),d+=t,a&&($[e]={rowCells:t})})),t+=r,o+=d,a&&(s[e]={tableRows:r,tableCells:d,rows:$})})),qe({totalTables:l,totalRows:t,totalCells:o,totalValues:u(e.getValueIds()),jsonLength:U(e.getJson())},a?{detail:{tables:s}}:{})},getStoreTablesSchema:a,getStoreValuesSchema:l,getStoreApi:t,getPrettyStoreApi:o,getStore:()=>e})}));exports.createTools=Ke;
|
|
1
|
+
"use strict";const e=e=>typeof e,t="",l=e(t),a=e(!0),n=e(0),o="type",r="default",s="Listener",d="get",c="add",i="Ids",$="Table",u=$+"s",I=$+i,b="Row",h=b+i,p="Sorted"+b+i,f="Cell",g=f+i,v="Value",w=v+"s",C=v+i,m=(e,t)=>e.every(t),y=(e,t)=>e.sort(t),R=(e,t)=>e.forEach(t),S=(e,t)=>e.map(t),k=e=>e.length,V=e=>0==k(e),x=(e,t)=>e.filter(t),O=(e,...t)=>e.push(...t),P=e=>e.pop(),j=(e,...t)=>e.unshift(...t),D=e=>e.shift(),T=JSON.parse,A=isFinite,N=(e,t)=>e instanceof t,E=e=>null==e,M=e=>e==l||e==a,z=t=>e(t)==l,G=e=>Array.isArray(e),J=t=>{const l=e(t);return M(l)||l==n&&A(t)?l:void 0},L=(e,t)=>{var l;return null!=(l=null==e?void 0:e.has(t))&&l},W=e=>{var t;return[...null!=(t=null==e?void 0:e.values())?t:[]]},B=(e,t)=>null==e?void 0:e.forEach(t),F=(e,t)=>null==e?void 0:e.delete(t),U=e=>new Map(e),_=(e,t)=>null==e?void 0:e.get(t),Z=(e,t)=>B(e,((e,l)=>t(l,e))),H=(e,t)=>{var l;return S([...null!=(l=null==e?void 0:e.entries())?l:[]],(([e,l])=>t(l,e)))},Q=(e,t,l)=>E(l)?(F(e,t),e):null==e?void 0:e.set(t,l),q=(e,t,l)=>(L(e,t)||Q(e,t,l()),_(e,t)),K=e=>e.toUpperCase(),X=e=>e.toLowerCase(),Y="a ",ee="A function for",te="Callback",le="Del",ae="export",ne="Id",oe="Invalid",re="Json",se=X(s),de=" | undefined",ce="Partial",ie=`Registers a ${se} that will be called`,$e="Represents",ue="Set",Ie="[]",be="the Store",he="Transaction",pe=X(he),fe="the end of the "+pe,ge="void",ve=" => "+ge,we=Y+"string serialization of",Ce=" ",me="Gets a callback that can ",ye="the ",Re=(e=0,l=0)=>`the ${Je[e]}content of`+(l?Ce+be:t),Se=(e=0,l,a=0)=>ze[l]+Ce+Re(e,1)+(a?" when set":t),ke=(e,t=0)=>$e+` a Row when ${t?"s":"g"}etting ${Re()} the '${e}' `+$,Ve=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,xe=(e,t)=>`Calls a function for each ${e} in `+t,Oe=e=>"A function that takes "+e,Pe=(e,t=0)=>ee+" listening to changes to "+Ge[e]+" in "+Ge[t],je=(e,l,a=0)=>ie+" whenever "+Ge[e]+" in "+Ge[l]+" change"+(a?t:"s"),De=e=>`the '${e}' `+$,Te=e=>"the specified Row in "+De(e),Ae=(e,t=0)=>ze[t]+` ${Re()} `+De(e),Ne=(e,t=0)=>ze[t]+` ${Re()} `+Te(e),Ee=(e,t,l=0)=>ze[l]+` the '${t}' Cell for `+Te(e),Me=(e,t=0)=>ze[t]+` the '${e}' Value`,ze=["Gets","Checks existence of","Sets","Deletes","Sets part of",$e,"Gets "+we,"Sets "+we,ie+" whenever",me+"set",me+"add",me+"set part of",me+"delete"],Ge=[be,u,ye+$+Ce+i,Y+$,ye+b+Ce+i,Y+b,ye+f+Ce+i,Y+f,"invalid Cell changes",w,ye+v+Ce+i,Y+v,"invalid Value changes",ye+"sorted "+b+Ce+i],Je=[t,"tabular ","keyed value "],Le=e=>new Set(G(e)||E(e)?e:[e]),We=(e,t)=>null==e?void 0:e.add(t),Be=/[^A-Za-z]+/,Fe=/[^A-Za-z0-9]+/,Ue=/^( *)\/\*\* *(.*?) *\*\/$/gm,_e=(e,t,l)=>e.substring(t,l),Ze=e=>e.includes(","),He=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return L(e,n)?He(e,t,l,a+1):(Q(e,n,l),n)},Qe=e=>e.replace(Ue,((e,t,l)=>{const a=77-qe(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),qe=e=>e.length,Ke=(e,l=t)=>e.join(l),Xe=e=>e.flat(1e3),Ye=(e,t=0)=>Ke(S(e.split(Fe),((e,l)=>(l>0||t?K:X)(_e(e,0,1))+_e(e,1)))),et=e=>K(Ke((e&&!Be.test(e[0])?e:" "+e).split(Fe),"_")),tt=e=>`/** ${e}. */`,lt=(...e)=>Ke(x(e,(e=>e)),", "),at=()=>{const e=[U(),U(),U(),U()],l=U(),a=U();return[(...e)=>Ke(Xe(e),"\n"),(t,l,...a)=>R(a,(a=>R([0,1],(n=>(null!=t?t:n)==n?We(q(e[n],l,Le),a):0)))),(e,t,a)=>He(l,e,[t,a]),(e,t,l)=>He(a,e,G(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>_(a,e)===t?e:He(a,e,t),(l=0)=>S([...y(H(e[l],((e,t)=>`import {${Ke(y(W(e)),", ")}} from '${t}';`)),((e,t)=>Ze(e)!=Ze(t)?Ze(e)?-1:1:e>t?1:-1)),t],(e=>e.replace("{React}","React"))),()=>H(l,(([e,l],a)=>[tt(l),`${ae} type ${a} = ${e};`,t])),()=>H(a,((e,l)=>(e=G(e)?e:[e],O(e,P(e)+";"),[`const ${l} = ${D(e)}`,e,t])))]},nt=Object,ot=nt.keys,rt=nt.freeze,st=e=>N(e,nt)&&e.constructor==nt,dt=(e,t)=>S(nt.entries(e),(([e,l])=>t(l,e))),ct=e=>st(e)&&V(ot(e)),it=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},$t=(e,t,l)=>[t=>dt(e,((e,a)=>t(a,Ye(a,1),l(et(a),`'${a}'`)))),(t,a)=>dt(e[t],((e,t)=>a(t,e[o],e[r],l(et(t),`'${t}'`),Ye(t,1)))),e=>dt(t,((t,a)=>e(a,t[o],t[r],l(et(a),`'${a}'`),Ye(a,1))))],ut=[d,"has","set","del","set","forEach",c,t],It=(e,l=t,a=t)=>`store.${e}(${l})`+(a?" as "+a:t),bt=(e,l=t)=>`fluent(() => ${It(e,l)})`,ht=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(listener)${a?", "+a:t})`,pt=(e,l,n)=>{const[d,m,y,S,k,V,x,P]=at(),[D,T,A]=$t(e,l,k),N=U(),M=(e=0)=>H(N,(([l,a,n,o,r],s)=>{const d=e?[s+`: ${r}(${l}): ${a} => ${n},`]:[s+r+`(${l}): ${a};`];return e||j(d,tt(o)),O(d,t),d})),G=(e,l,a,n,o,r=t)=>He(N,e,[l,a,n,o,r]),J=(e,l,a,n,o,r=t,s=t,d=t)=>G(ut[e]+l+(4==e?ce:t)+a,r,n,(n==F?bt:It)(ut[e]+(4==e?ce:t)+a,s,e?void 0:n),o,d),L=(e,l,a,n=t,o=t,r=1)=>G(c+e+s,(n?n+", ":t)+se+": "+l+(r?", mutator?: boolean":t),ne,ht(c+e+s,o,r?"mutator":t),a),B=`./${Ye(n)}.d`,F=Ye(n,1),q=Ye(F),K=[],X=U();let le=[],ue=[];if(m(1,B,F,`create${F} as create${F}Decl`),!ct(e)){const e=U();D(((l,a)=>{const n=[y(a+$,`{[rowId: Id]: ${a}Row}`,$e+` the '${l}' `+$),y(a+b,`{${Ke(T(l,((e,l,a)=>`'${e}'${E(a)?"?":t}: ${l};`))," ")}}`,ke(l)),y(a+b+"WhenSet",`{${Ke(T(l,((e,t)=>`'${e}'?: ${t};`))," ")}}`,ke(l,1)),y(a+f+ne,Ke(T(l,(e=>`'${e}'`))," | "),`A Cell Id for the '${l}' `+$),y(a+f+te,`(...[cellId, cell]: ${Ke(T(l,((e,t)=>`[cellId: '${e}', cell: ${t}]`))," | ")})`+ve,Oe(`a Cell Id and value from a Row in the '${l}' `+$)),y(a+b+te,`(rowId: Id, forEachCell: (cellCallback: ${a}CellCallback)`+ve+")"+ve,Oe(`a Row Id from the '${l}' Table, and a Cell iterator`))];Q(e,l,n),m(1,B,...n)}));const l=y(u,`{${Ke(D((t=>{var l;return`'${t}'?: ${null==(l=_(e,t))?void 0:l[0]};`}))," ")}}`,Se(1,5)),n=y($+ne,Ke(D((e=>`'${e}'`))," | "),"A "+$+" Id in "+be),d=y($+te,`(...[tableId, rowCallback]: ${Ke(D((t=>{var l;return`[tableId: '${t}', forEachRow: (rowCallback: ${null==(l=_(e,t))?void 0:l[5]})${ve}]`}))," | ")})`+ve,Oe(Y+$+" Id, and a Row iterator")),c=y("GetCellChange",`(...[tableId, rowId, cellId]: ${Ke(D((t=>{var l;return`[tableId: '${t}', rowId: Id, cellId: ${null==(l=_(e,t))?void 0:l[3]}]`}))," | ")}) => CellChange`,ee+" returning information about any Cell's changes during a "+pe),v=y(u+s,`(${q}: ${F}, getCellChange: ${c}${de})`+ve,Pe(1)),w=y(I+s,`(${q}: ${F})`+ve,Pe(2)),C=y($+s,`(${q}: ${F}, tableId: ${n}, getCellChange: ${c}${de})`+ve,Pe(3)),S=y(h+s,`(${q}: ${F}, tableId: ${n})`+ve,Pe(4,3)),V=y(p+s,"("+lt(q+": "+F,"tableId: "+n,"cellId: Id"+de,"descending: boolean","offset: number","limit: number"+de,"sortedRowIds: Ids")+")"+ve,Pe(13,3)),x=y(b+s,`(${q}: ${F}, tableId: ${n}, rowId: Id, getCellChange: ${c}${de})`+ve,Pe(5,3)),P=y(g+s,`(${q}: ${F}, tableId: ${n}, rowId: Id)`+ve,Pe(6,5)),j=y(f+s,`(...[${q}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${Ke(Xe(D((e=>T(e,((t,l)=>`[${q}: ${F}, tableId: '${e}', rowId: Id, cellId: '${t}', newCell: ${l}${de}, oldCell: ${l}${de}, getCellChange: ${c} | undefined]`)))))," | ")})`+ve,Pe(7,5)),A=y(oe+f+s,`(${q}: ${F}, tableId: Id, rowId: Id, cellId: Id, invalidCells: any[])`+ve,Pe(8));le=[l,n,v,w,C,S,V,x,P,j,e],R([[l],[a],[F,"tables: "+l,"tables"],[F]],(([e,l,a],n)=>J(n,t,u,e,Se(1,n),l,a))),J(0,t,I,n+Ie,Ve($,be)),J(5,t,$,ge,xe($,be),"tableCallback: "+d,"tableCallback as any"),D(((l,n,o)=>{const[r,s,d,c,u,I]=_(e,l);R([[r],[a],[F,"table: "+r,", table"],[F]],(([e,a,r=t],s)=>J(s,n,$,e,Ae(l,s),a,o+r))),J(0,n,h,i,Ve(b,De(l)),t,o),J(0,n,p,i,Ve(b,De(l),1),"cellId?: "+c+", descending?: boolean, offset?: number, limit?: number",o+", cellId, descending, offset, limit"),J(5,n,b,ge,xe(b,De(l)),"rowCallback: "+I,o+", rowCallback as any"),R([[s],[a],[F,", row: "+d,", row"],[F],[F,", partialRow: "+d,", partialRow"]],(([e,a=t,r=t],s)=>J(s,n,b,e,Ne(l,s),"rowId: Id"+a,o+", rowId"+r))),J(6,n,b,ne+de,"Adds a new Row to "+De(l),"row: "+d,o+", row"),J(0,n,g,c+Ie,Ve(f,Te(l)),"rowId: "+ne,o+", rowId"),J(5,n,f,ge,xe(f,Te(l)),"rowId: Id, cellCallback: "+u,o+", rowId, cellCallback as any"),T(l,((e,r,s,d,c)=>{const i="Map"+Ye(r,1);Q(X,r,i);const $=r+(E(s)?de:t);R([[$],[a],[F,`, cell: ${r} | `+i,", cell as any"],[F]],(([a,r=t,s=t],i)=>J(i,n+c,f,a,Ee(l,e,i),"rowId: Id"+r,o+", rowId, "+d+s)))}))})),J(0,t,u+re,re,Se(1,6)),J(2,t,u+re,F,Se(1,7),"tablesJson: "+re,"tables"+re),L(u,v,Se(1,8)+" changes"),L(I,w,je(2,0,1)),L($,C,je(3,0),`tableId: ${n} | null`,"tableId"),L(h,S,je(4,3,1),`tableId: ${n} | null`,"tableId"),L(p,V,je(13,3,1),lt("tableId: "+n,"cellId: Id"+de,"descending: boolean","offset: number","limit: number"+de),lt("tableId","cellId","descending","offset","limit")),L(b,x,je(5,3),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),L(g,P,je(6,5,1),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),L(f,j,je(7,5),`tableId: ${n} | null, rowId: IdOrNull, cellId: ${Ke(D((l=>{var a,n;return null!=(n=null==(a=_(e,l))?void 0:a[3])?n:t}))," | ")} | null`,"tableId, rowId, cellId"),L(oe+f,A,ie+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),m(1,B,l,n,d,v,w,C,S,V,x,P,j,A,...W(X)),m(0,"tinybase","CellChange"),O(K,".setTablesSchema({",Xe(D(((e,l,a)=>[`[${a}]: {`,...T(e,((e,l,a,n)=>`[${n}]: {[${k(et(o),`'${o}'`)}]: ${k(et(l),`'${l}'`)}${E(a)?t:`, [${k(et(r),`'${r}'`)}]: `+(z(a)?k(et(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(!ct(l)){const e=y(w,"{"+Ke(A(((e,l,a)=>`'${e}'${E(a)?"?":t}: ${l};`))," ")+"}",Se(2,5)),l=y(w+"WhenSet","{"+Ke(A(((e,t)=>`'${e}'?: ${t};`))," ")+"}",Se(2,5,1)),n=y(v+ne,Ke(A((e=>`'${e}'`))," | "),"A Value Id in "+be),d=y(v+te,`(...[valueId, rowCallback]: ${Ke(A(((e,t)=>`[valueId: '${e}', value: ${t}]`))," | ")})`+ve,Oe("a Value Id, and value")),c=y("GetValueChange",`(valueId: ${n}) => ValueChange`,ee+" returning information about any Value's changes during a "+pe),i=y(w+s,`(${q}: ${F}, getValueChange: ${c}${de})`+ve,Pe(9)),$=y(C+s,`(${q}: ${F})`+ve,Pe(10)),u=y(v+s,`(...[${q}, valueId, newValue, oldValue, getValueChange]: ${Ke(A(((e,t)=>`[${q}: ${F}, valueId: '${e}', newValue: ${t}${de}, oldValue: ${t}${de}, getValueChange: ${c} | undefined]`))," | ")})`+ve,Pe(11)),I=y(oe+v+s,`(${q}: ${F}, valueId: Id, invalidValues: any[])`+ve,Pe(12));ue=[e,l,n,i,$,u],R([[e],[a],[F,"values: "+l,"values"],[F],[F,"partialValues: "+l,"partialValues"]],(([e,l,a],n)=>J(n,t,w,e,Se(2,n),l,a))),J(0,t,C,n+Ie,Ve(v,be)),J(5,t,v,"void",xe(v,be),"valueCallback: "+d,"valueCallback as any"),A(((e,l,n,o,r)=>{const s="Map"+Ye(l,1);Q(X,l,s),R([[l],[a],[F,`value: ${l} | `+s,", value as any"],[F]],(([l,a,n=t],s)=>J(s,r,v,l,Me(e,s),a,o+n)))})),J(0,t,w+re,re,Se(2,6)),J(2,t,w+re,F,Se(2,7),"valuesJson: "+re,"values"+re),L(w,i,Se(2,8)+" changes"),L(C,$,je(10,0,1)),L(v,u,je(11,0),`valueId: ${n} | null`,"valueId"),L(oe+v,I,ie+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),m(1,B,e,l,n,d,i,$,u,I),m(0,"tinybase","ValueChange"),O(K,".setValuesSchema({",A(((e,l,a,n)=>[`[${n}]: {[${k(et(o),`'${o}'`)}]: ${k(et(l),`'${l}'`)}${E(a)?t:`, [${k(et(r),`'${r}'`)}]: `+(z(a)?k(et(a),`'${a}'`):a)}},`])),"})")}Z(X,((e,t)=>y(t,`(cell: ${e}${de}) => `+e,`Takes a ${e} Cell value and returns another`))),m(null,"tinybase","DoRollback",ne,"IdOrNull",i,re,"Store");const we=y(he+s,`(${q}: ${F}, cellsTouched: boolean, valuesTouched: boolean)`+ve,ee+" listening to the completion of a "+pe);return J(0,t,re,re,Se(0,6)),J(2,t,re,F,Se(0,7),"json: "+re,"json"),J(7,t,pe,"Return","Execute a "+pe+" to make multiple mutations","actions: () => Return, doRollback?: DoRollback","actions, doRollback","<Return>"),J(7,t,"start"+he,F,"Explicitly starts a "+pe),J(7,t,"finish"+he,F,"Explicitly finishes a "+pe,"doRollback?: DoRollback,","doRollback"),L("WillFinish"+he,we,ie+" just before "+fe,t,t,0),L("DidFinish"+he,we,ie+" just after "+fe,t,t,0),J(7,t,"call"+s,F,"Manually provoke a listener to be called","listenerId: Id","listenerId"),J(3,t,s,F,"Remove a listener that was previously added to "+be,"listenerId: Id","listenerId"),G("getStore",t,"Store","store",ze[0]+" the underlying Store object"),m(1,"tinybase","createStore"),m(1,B,F,`create${F} as create${F}Decl`,we),k("store",["createStore()",...K]),S("fluent","actions: () => Store",["actions();",`return ${q};`]),S("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${q}, ...params)`),k(q,["{",...M(1),"}"]),[d(...V(0),...x(),ae+" interface "+F+" {",...M(0),"}",t,tt(`Creates a ${F} object`),ae+" function create"+F+"(): "+F+";"),d(...V(1),ae+" const create"+F+": typeof create"+F+"Decl = () => {",...P(),`return Object.freeze(${q});`,"};"),le,ue]},ft="Deps",gt=e=>d+e,vt=e=>lt(gt(e),gt(e)+ft),wt="Parameter",Ct=": (parameter: "+wt+", store: Store) => ",mt="const contextValue = useContext(Context);",yt=", and registers a listener so that any changes to that result will cause a re-render",Rt=", based on a parameter",St=": ",kt=wt+"ized"+te+"<"+wt+">",Vt="<"+wt+",>",xt=ft+"?: React.DependencyList",Ot="then"+xt,Pt="then?: (store: Store",jt=lt(Pt+")"+ve,Ot),Dt="then, then"+ft,Tt="rowId",At=Tt+St+ne,Nt=(e,...t)=>lt(...t,se+": "+e,se+xt,"mutator?: boolean"),Et=(...e)=>lt(...e,se,se+ft,"mutator"),Mt=(e,l,a,n,o)=>{const[r,d,c,m,y,R,S,k]=at(),[V,x,P]=$t(e,l,y),D=`./${Ye(a)}.d`,T=`./${Ye(a)}-ui-react.d`,A="tinybase/ui-react",N=Ye(a,1),M=Ye(N),z=N+"Or"+N+ne,J=M+"Or"+N+ne,L=U(),W=(e,l,a,n,o,r=t)=>(d(1,T,e+" as "+e+"Decl"),He(L,e,[l,a,G(n)?["{",n,"}"]:n,o,r])),B=(e,l,a,n,o,r=t)=>W("use"+e,l,a,n,o,r),F=(e,l,a,n,o=t,r=t,s=t,c=t,i=t)=>{d(1,A,`use${l} as use${l}Core`),B(e,lt(o,X,c),a,ee+`(${J}, use${l}Core, [`+(r||t)+(i?"], ["+i:t)+"])",n,s)},Z=(e,t,l,a)=>W(e,t,1,l,a),Q=(e=0)=>H(L,(([l,a,n,o,r],s)=>{const d=e?[ae+` const ${s}: typeof ${s}Decl = ${r}(${l}): ${1==a?"any":a} =>`,n]:[ae+` function ${s}${r}(${l}): ${1==a?"ComponentReturnType":a};`];return e||j(d,tt(o)),O(d,t),d}));d(null,"tinybase",ne,i,"IdOrNull","Store",te,wt+"ized"+te),d(0,A,"ComponentReturnType"),d(0,D,N);const q=c(z,N+" | "+ne,`Used when you need to refer to a ${N} in a React hook or component`),K=c("ProviderProps",`{readonly ${M}?: ${N}; readonly ${M}ById?: {[${M}Id: Id]: ${N}}}`,`Used with the Provider component, so that a ${N} can be passed into the context of an application`);d(1,"react","React"),d(1,T,q,K);const X=J+"?: "+q;y("{createContext, useContext, useMemo}","React"),y("Context",`createContext<[${N}?, {[${M}Id: Id]: ${N}}?]>([])`),B("Create"+N,`create: () => ${N}, create`+xt,N,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${N} within a React application with convenient memoization`);const Y=B(N,"id?: Id",N+de,[mt,"return id == null ? contextValue[0] : contextValue[1]?.[id];"],`Get a reference to a ${N} from within a Provider component context`),ee=m("useHook",J+`: ${q} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${M} = ${Y}(${J} as Id);`,`return hook(...preParams, ((${J} == null || typeof ${J} == 'string')`,`? ${M} : ${J})?.getStore(), ...postParams)`]);if(!ct(e)){const[e,l,a,o,r,c,v,w,C,m,y]=n;d(null,D,e,l,a,o,r,c,v,w,C,m),d(1,A),d(1,D,N),F(u,u,e,Se(1,0)+yt),F(I,I,l+Ie,Ve($,be)+yt),F(ue+u+te,ue+u+te,kt,Se(1,9)+Rt,lt(gt(u)+Ct+e,gt(u)+xt),vt(u),Vt,lt(Pt,`tables: ${e})`+ve,Ot),Dt),F(le+u+te,le+u+te,te,Se(1,12),t,t,t,jt,Dt),V(((e,l,a)=>{const[n,o,r,s]=_(y,e);d(0,D,n,o,r,s),d(1,D,n,o,r,s),F(l+$,$,n,Ae(e)+yt,t,a),F(l+h,h,i,Ve(b,De(e))+yt,t,a),F(l+p,p,i,Ve(b,De(e),1)+yt,"cellId?: "+s+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit"),F(l+b,b,o,Ne(e)+yt,At,lt(a,Tt)),F(l+g,g,s+Ie,Ve(f,Te(e))+yt,At,lt(a,Tt)),F(ue+l+$+te,ue+$+te,kt,Ae(e,9)+Rt,lt(gt($)+Ct+n,gt($)+xt),lt(a,vt($)),Vt,lt(Pt,`table: ${n})`+ve,Ot),Dt),F(le+l+$+te,le+$+te,te,Ae(e,12),t,a,t,jt,Dt),F(ue+l+b+te,ue+b+te,kt,Ne(e,9)+Rt,lt(At,gt(b)+Ct+r,gt(b)+xt),lt(a,Tt,vt(b)),Vt,lt(Pt,`row: ${r})`+ve,Ot),Dt),F("Add"+l+b+te,"Add"+b+te,kt,Ne(e,10)+Rt,lt(gt(b)+Ct+r,gt(b)+xt),lt(a,vt(b)),Vt,"then?: ("+lt(At+de,"store: Store","row: "+r+")"+ve,"then"+xt),Dt),F(ue+l+ce+b+te,ue+ce+b+te,kt,Ne(e,11)+Rt,lt(At,gt(ce+b)+Ct+r,gt(ce+b)+xt),lt(a,Tt,vt(ce+b)),Vt,lt(Pt,`partialRow: ${r})`+ve,Ot),Dt),F(le+l+b+te,le+b+te,te,Ne(e,12),At,lt(a,Tt),t,jt,Dt),x(e,((n,o,r,s,c)=>{const i="Map"+Ye(o,1);d(0,D,i),d(1,D,i),F(l+c+f,f,o+(E(r)?de:t),Ee(e,n)+yt,At,lt(a,Tt,s)),F(ue+l+c+f+te,ue+f+te,kt,Ee(e,n,9)+Rt,lt(At,gt(f)+Ct+o+" | "+i,gt(f)+xt),lt(a,Tt,s,vt(f)),Vt,lt(Pt,`cell: ${o} | ${i})`+ve,Ot),Dt),F(le+l+c+f+te,le+f+te,te,Ee(e,n,12),lt(At,"forceDel?: boolean"),lt(a,Tt,s,"forceDel"),t,jt,Dt)}))}));const R=Ke(V((e=>{var l,a;return null!=(a=null==(l=_(y,e))?void 0:l[3])?a:t}))," | ");F(u+s,u+s,ge,Se(1,8)+" changes",Nt(a),Et()),F(I+s,I+s,ge,je(2,0,1),Nt(o),Et()),F($+s,$+s,ge,je(3,0),Nt(r,`tableId: ${l} | null`),Et("tableId")),F(h+s,h+s,ge,je(4,3,1),Nt(c,`tableId: ${l} | null`),Et("tableId")),F(p+s,p+s,ge,je(13,3,1),Nt(v,`tableId: ${l} | null`,"cellId: "+R+de,"descending: boolean","offset: number","limit: number"+de),Et("tableId","cellId","descending","offset","limit")),F(b+s,b+s,ge,je(5,3),Nt(w,`tableId: ${l} | null`,Tt+": IdOrNull"),Et("tableId",Tt)),F(g+s,g+s,ge,je(6,5,1),Nt(C,`tableId: ${l} | null`,Tt+": IdOrNull"),Et("tableId",Tt)),F(f+s,f+s,ge,je(7,5),Nt(m,`tableId: ${l} | null`,Tt+": IdOrNull",`cellId: ${R} | null`),Et("tableId",Tt,"cellId"))}if(!ct(l)){const[e,l,a,n,r,c]=o;d(null,D,...o),F(w,w,e,Se(2,0)+yt),F(C,C,a+Ie,Ve(v,be)+yt),F(ue+w+te,ue+w+te,kt,Se(2,9)+Rt,lt(gt(w)+Ct+l,gt(w)+xt),vt(w),Vt,lt(Pt,`values: ${l})`+ve,Ot),Dt),F(ue+ce+w+te,ue+ce+w+te,kt,Se(2,11)+Rt,lt(gt(ce+w)+Ct+l,gt(ce+w)+xt),vt(ce+w),Vt,lt(Pt,`partialValues: ${l})`+ve,Ot),Dt),F(le+w+te,le+w+te,te,Se(2,12),t,t,t,jt,Dt),P(((e,l,a,n,o)=>{const r="Map"+Ye(l,1);d(0,D,r),d(1,D,r),F(o+v,v,l,Me(e)+yt,t,n),F(ue+o+v+te,ue+v+te,kt,Me(e,9)+Rt,lt(gt(v)+Ct+l+" | "+r,gt(v)+xt),lt(n,vt(v)),Vt,lt(Pt,`value: ${l} | ${r})`+ve,Ot),Dt),F(le+o+v+te,le+v+te,te,Me(e,12),t,n,t,jt,Dt)})),F(w+s,w+s,ge,Se(2,8)+" changes",Nt(n),Et()),F(C+s,C+s,ge,je(10,0,1),Nt(r),Et()),F(v+s,v+s,ge,je(11,0),Nt(c,`valueId: ${a} | null`),Et("valueId"))}return Z("Provider",`{${M}, ${M}ById, children}: `+K+" & {children: React.ReactNode}",[mt,"return (","<Context.Provider","value={useMemo(",`() => [${M} ?? contextValue[0], {...contextValue[1], ...${M}ById}],`,`[${M}, ${M}ById, contextValue],`,")}>","{children}","</Context.Provider>",");"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[r(...R(0),...S(),...Q(0)),r(...R(1),...k(),...Q(1))]},zt=(e,l,a)=>{if(ct(e)&&ct(l))return[t,t,t,t];const[n,o,r,s]=pt(e,l,a);return[n,o,...Mt(e,l,a,r,s)]};var Gt=Object.defineProperty,Jt=Object.defineProperties,Lt=Object.getOwnPropertyDescriptors,Wt=Object.getOwnPropertySymbols,Bt=Object.prototype.hasOwnProperty,Ft=Object.prototype.propertyIsEnumerable,Ut=(e,t,l)=>t in e?Gt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l,_t=(e,t)=>{for(var l in t||(t={}))Bt.call(t,l)&&Ut(e,l,t[l]);if(Wt)for(var l of Wt(t))Ft.call(t,l)&&Ut(e,l,t[l]);return e},Zt=(e,t)=>Jt(e,Lt(t)),Ht=(e,t,l)=>new Promise(((a,n)=>{var o=e=>{try{s(l.next(e))}catch(e){n(e)}},r=e=>{try{s(l.throw(e))}catch(e){n(e)}},s=e=>e.done?a(e.value):Promise.resolve(e.value).then(o,r);s((l=l.apply(e,t)).next())}));const Qt={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},qt=it((e=>{const t=()=>{const t=T(e.getTablesSchemaJson());return!ct(t)||m(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=U();if(m(a,(t=>m(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),r=q(n,a,(()=>[J(o),U(),[0],0])),[s,d,[c]]=r,i=q(d,o,(()=>0))+1;return i>c&&(r[2]=[i,o]),Q(d,o,i),r[3]++,s==J(o)})))))return t[l]={},B(n,(([e,,[,n],s],d)=>{t[l][d]=_t({[o]:e},s==k(a)?{[r]:n}:{})})),1}))?t:{}},l=()=>{const t=T(e.getValuesSchemaJson());return ct(t)&&e.forEachValue(((e,l)=>{t[e]={[o]:J(l)}})),t},a=e=>zt(t(),l(),e),n=e=>Ht(void 0,null,(function*(){const t=["d.ts","ts","d.ts","tsx"];let l;try{l=(yield import("prettier")).format}catch(e){l=e=>e}return S(a(e),((e,a)=>Qe(l(e,Zt(_t({},Qt),{filepath:"_."+t[a]})))))}));return rt({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,r)=>{l++;let s=0,d=0;const c={};r(((e,l)=>{s++;let a=0;l((()=>a++)),d+=a,t&&(c[e]={rowCells:a})})),a+=s,n+=d,t&&(o[e]={tableRows:s,tableCells:d,rows:c})})),_t({totalTables:l,totalRows:a,totalCells:n,totalValues:k(e.getValueIds()),jsonLength:qe(e.getJson())},t?{detail:{tables:o}}:{})},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));exports.createTools=qt;
|
package/lib/cjs-es6/tools.cjs.gz
CHANGED
|
Binary file
|