@docstack/react 0.0.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/components/StackProvider/index.d.ts +12 -0
- package/lib/components/index.d.ts +0 -0
- package/lib/hooks/class.d.ts +20 -0
- package/lib/hooks/domain.d.ts +20 -0
- package/lib/hooks/index.d.ts +20 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +3 -0
- package/lib/index.js.LICENSE.txt +9 -0
- package/lib/index.js.map +1 -0
- package/package.json +50 -0
- package/src/components/StackProvider/index.tsx +58 -0
- package/src/components/index.ts +0 -0
- package/src/hooks/class.ts +302 -0
- package/src/hooks/domain.ts +294 -0
- package/src/hooks/index.ts +129 -0
- package/src/index.ts +10 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { DocStack } from '@docstack/client';
|
|
3
|
+
import { ClientCredentials, StackConfig } from '@docstack/shared';
|
|
4
|
+
export declare const DocStackContext: import("react").Context<DocStack | null>;
|
|
5
|
+
export declare const useDocStack: () => DocStack | null;
|
|
6
|
+
export interface DocStackProviderProps {
|
|
7
|
+
config: StackConfig[];
|
|
8
|
+
credentials?: ClientCredentials | ClientCredentials[];
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
declare const StackProvider: (props: DocStackProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export default StackProvider;
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Class } from "@docstack/client";
|
|
2
|
+
import { Document } from "@docstack/shared";
|
|
3
|
+
export declare const useClassCreate: (stack: string) => (className: string, classDesc?: string) => Promise<Class | null>;
|
|
4
|
+
export declare const useClassList: (stack: string, selector: {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}) => {
|
|
7
|
+
classList: Class[];
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: null;
|
|
10
|
+
};
|
|
11
|
+
export declare const useClass: (stack: string, className: string) => {
|
|
12
|
+
loading: boolean;
|
|
13
|
+
error: undefined;
|
|
14
|
+
classObj: Class | undefined;
|
|
15
|
+
};
|
|
16
|
+
export declare const useClassDocs: (stack: string, className: string, query?: {}) => {
|
|
17
|
+
docs: Document[];
|
|
18
|
+
loading: boolean;
|
|
19
|
+
error: null;
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Class } from "@docstack/client";
|
|
2
|
+
import { Domain, RelationDocument } from "@docstack/shared";
|
|
3
|
+
export declare const useDomainCreate: (stack: string) => (domainName: string, cardinality: "1:1" | "1:N" | "N:1" | "N:N", sourceClass: Class, targetClass: Class, domainDesc?: string) => Promise<Domain | null>;
|
|
4
|
+
export declare const useDomainList: (stack: string, selector: {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}) => {
|
|
7
|
+
domainList: Domain[];
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: null;
|
|
10
|
+
};
|
|
11
|
+
export declare const useDomain: (stack: string, domainName: string) => {
|
|
12
|
+
loading: boolean;
|
|
13
|
+
error: undefined;
|
|
14
|
+
domain: Domain | undefined;
|
|
15
|
+
};
|
|
16
|
+
export declare const useDomainRelations: (stack: string, domainName: string, query?: {}) => {
|
|
17
|
+
docs: RelationDocument[];
|
|
18
|
+
loading: boolean;
|
|
19
|
+
error: null;
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Document, SelectAST, UnionAST } from '@docstack/shared';
|
|
2
|
+
export declare const useQuerySQL: (stack: string, sql: string, ...params: any[]) => {
|
|
3
|
+
loading: boolean;
|
|
4
|
+
result: {
|
|
5
|
+
rows: any[];
|
|
6
|
+
ast: (SelectAST | UnionAST)[] | null;
|
|
7
|
+
};
|
|
8
|
+
error: null;
|
|
9
|
+
};
|
|
10
|
+
export declare const useFind: (stack: string, query: {
|
|
11
|
+
selector: {
|
|
12
|
+
[key: string]: string | number;
|
|
13
|
+
};
|
|
14
|
+
fields?: string[];
|
|
15
|
+
}, sort?: any, limit?: number) => {
|
|
16
|
+
docs: Document[];
|
|
17
|
+
loading: boolean;
|
|
18
|
+
error: null;
|
|
19
|
+
};
|
|
20
|
+
export declare const useClassCreate: () => void;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import StackProvider, { DocStackContext, useDocStack } from "./components/StackProvider";
|
|
2
|
+
import { useFind, useQuerySQL } from "./hooks/";
|
|
3
|
+
import { useClass, useClassList, useClassDocs, useClassCreate } from "./hooks/class";
|
|
4
|
+
import { useDomainList, useDomain, useDomainRelations, useDomainCreate } from "./hooks/domain";
|
|
5
|
+
export { StackProvider, DocStackContext, useDocStack };
|
|
6
|
+
export { useFind, useQuerySQL };
|
|
7
|
+
export { useClassList, useClass, useClassDocs, useClassCreate };
|
|
8
|
+
export { useDomainList, useDomain, useDomainRelations, useDomainCreate };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
+
import{createContext as e,useCallback as n,useContext as t,useEffect as r,useRef as o,useState as c}from"react";import{Class as i,DocStack as s}from"@docstack/client";import{Domain as l}from"@docstack/shared";var d={698(e,n){var t=Symbol.for("react.transitional.element");Symbol.for("react.fragment"),n.jsx=function(e,n,r){var o=null;if(void 0!==r&&(o=""+r),void 0!==n.key&&(o=""+n.key),"key"in n)for(var c in r={},n)"key"!==c&&(r[c]=n[c]);else r=n;return n=r.ref,{$$typeof:t,type:e,key:o,ref:void 0!==n?n:null,props:r}}},848(e,n,t){e.exports=t(698)}},a={};function u(e){var n=a[e];if(void 0!==n)return n.exports;var t=a[e]={exports:{}};return d[e](t,t.exports,u),t.exports}u.d=(e,n)=>{for(var t in n)u.o(n,t)&&!u.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},u.o=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);var f=u(848);const v=e(null),g=()=>t(v),y=e=>{const{config:t,children:i,credentials:l}=e,d=o(null),[a,u]=c(null),g=n(()=>{u(d.current)},[]);return r(()=>{if(null===d.current&&t.length){console.log("DocStack provider - init instance",{config:t});const e=t.map((e,n)=>{const t=Array.isArray(l)?l[n]:l;return"string"==typeof e?t?{connection:e,credentials:t}:e:t?Object.assign(Object.assign({},e),{credentials:t}):e}),n=new s(...e);d.current=n,d.current.addEventListener("ready",g)}return()=>{d.current}},[t,l,g]),(0,f.jsx)(v.Provider,{value:a,children:i})};var h=function(e,n,t,r){return new(t||(t=Promise))(function(o,c){function i(e){try{l(r.next(e))}catch(e){c(e)}}function s(e){try{l(r.throw(e))}catch(e){c(e)}}function l(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(i,s)}l((r=r.apply(e,n||[])).next())})};const m=(e,n,...i)=>{const s=t(v),[l,d]=c({rows:[],ast:[]}),[a,u]=c(!0),[f,g]=c(null),y=o(!1);return r(()=>s?(y.current?console.log("Already performing query"):(y.current=!0,u(!0),h(void 0,void 0,void 0,function*(){try{const t=s.getStack(e);if(t){console.log("Preparing to run query",{sql:n,params:i});const e=yield t.query(n,...i);d(e)}else console.log("Could not find corresponding stack",{stack:e})}catch(e){console.log("Got error while running query",{error:e}),g(e)}finally{u(!1)}})),()=>{}):(console.error("useClassList must be used within a DocStackProvider."),void u(!1)),[s,e,i]),{loading:a,result:l,error:f}},p=(e,n,o,i=50)=>{const s=t(v),[l,d]=c([]),[a,u]=c(!0),[f,g]=c(null);return r(()=>{if(!s)return console.error("useFind must be used within a DocStackProvider."),void u(!1);u(!0),h(void 0,void 0,void 0,function*(){try{const t=s.getStack(e);if(t){const e=yield t.findDocuments(n.selector,n.fields);if(e.docs.length){let n=e.docs;d(n)}}}catch(e){g(e)}finally{u(!1)}});const t=e=>{};return s.addEventListener("change",t),()=>{s.removeEventListener("change",t)}},[s,JSON.stringify(n)]),{docs:l,loading:a,error:f}};var k=function(e,n,t,r){return new(t||(t=Promise))(function(o,c){function i(e){try{l(r.next(e))}catch(e){c(e)}}function s(e){try{l(r.throw(e))}catch(e){c(e)}}function l(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(i,s)}l((r=r.apply(e,n||[])).next())})};const S=e=>{const r=t(v);return n((n,t)=>k(void 0,void 0,void 0,function*(){try{if(!r)return console.error("useClassCreate must be used within a DocStackProvider."),Promise.resolve(null);const o=r.getStack(e);if(o){const e=yield i.create(o,n,"class",t);return yield o.addClass(e),e}return null}catch(e){return console.error(e),null}}),[r,e])},w=(e,n)=>{const s=t(v),[l,d]=c(),[a,u]=c([]),f=o([]),[g,y]=c(!0),[h,m]=c(null);return r(()=>{if(s)return k(void 0,void 0,void 0,function*(){y(!0),m(null);try{const n=s.getStack(e);if(n){const e=yield n.getClass("class");e&&d(e)}}catch(e){m(e),y(!1)}}),()=>{};y(!1)},[s,e]),r(()=>{l&&k(void 0,void 0,void 0,function*(){y(!0);try{const t=yield l.getCards(n),r=[],o=s.getStack(e);for(const e of t){const n=yield i.buildFromModel(o,e);r.push(n)}f.current=r,u(f.current)}catch(e){m(e)}finally{y(!1)}const t=e=>{const n=e.detail.doc;if(console.log("useClassDocs - detail",{detail:e.detail}),n.active){const e=f.current.findIndex(e=>e.id==n._id);-1!=e?f.current=[...f.current.slice(0,e),n,...f.current.slice(e+1,f.current.length)]:f.current.push(n)}else{console.log("useClassDocs - a doc was deleted",{doc:n});const e=f.current.findIndex(e=>e.id==n._id);-1!=e&&(f.current=[...f.current.slice(0,e),...f.current.slice(e+1,f.current.length)])}u([...f.current])};return l.addEventListener("doc",t),()=>{l.removeEventListener("doc",t)}})},[l,JSON.stringify(n)]),{classList:a,loading:g,error:h}},C=(e,n)=>{const i=t(v),[s,l]=c(!1),[d,a]=c(),[u,f]=c(),g=o(!1);return r(()=>i?(g.current||(g.current=!0,l(!0),k(void 0,void 0,void 0,function*(){try{const t=i.getStack(e);if(t){const e=yield t.getClass(n);e&&f(e)}}catch(e){a(e)}finally{l(!1)}})),()=>{}):(console.error("useClass must be used within a DocStackProvider."),void l(!1)),[i,e,n]),{loading:s,error:d,classObj:u}},x=(e,n,i={})=>{const s=t(v),[l,d]=c(),[a,u]=c([]),f=o([]),[g,y]=c(!0),[h,m]=c(null);return r(()=>{if(s&&n)return k(void 0,void 0,void 0,function*(){y(!0),m(null);try{const t=s.getStack(e);if(t){const e=yield t.getClass(n);e&&d(e)}}catch(e){m(e),y(!1)}}),()=>{};y(!1)},[s,e,n]),r(()=>{l&&k(void 0,void 0,void 0,function*(){y(!0);try{const e=yield l.getCards(i);f.current=e,u(f.current)}catch(e){m(e)}finally{y(!1)}const e=e=>{const n=e.detail.doc;if(console.log("useClassDocs - detail",{detail:e.detail}),n.active){console.log("useClassDocs - a doc was changed or added",{doc:n});const e=f.current.findIndex(e=>e._id==n._id);-1!=e?(console.log("useClassDocs - a doc was changed",{doc:n}),f.current=[...f.current.slice(0,e),n,...f.current.slice(e+1,f.current.length)]):(console.log("useClassDocs - a doc was added",{doc:n}),f.current.push(n))}else{console.log("useClassDocs - a doc was deleted",{doc:n});const e=f.current.findIndex(e=>e._id==n._id);-1!=e&&(f.current=[...f.current.slice(0,e),...f.current.slice(e+1,f.current.length)])}u([...f.current])};return l.addEventListener("doc",e),()=>{l.removeEventListener("doc",e)}})},[l,JSON.stringify(i)]),{docs:a,loading:g,error:h}};var D=function(e,n,t,r){return new(t||(t=Promise))(function(o,c){function i(e){try{l(r.next(e))}catch(e){c(e)}}function s(e){try{l(r.throw(e))}catch(e){c(e)}}function l(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(i,s)}l((r=r.apply(e,n||[])).next())})};const b=e=>{const r=t(v);return n((n,t,o,c,i)=>D(void 0,void 0,void 0,function*(){try{if(!r)return console.error("useDomainCreate must be used within a DocStackProvider."),Promise.resolve(null);const s=r.getStack(e);return s?yield l.create(s,null,n,"domain",t,o,c,i):null}catch(e){return console.error(e),null}}),[r,e])},P=(e,n)=>{const i=t(v),[s,d]=c(),[a,u]=c([]),f=o([]),[g,y]=c(!0),[h,m]=c(null);return r(()=>{if(i)return D(void 0,void 0,void 0,function*(){y(!0),m(null);try{const n=i.getStack(e);if(n){const e=yield n.getClass("domain");e&&d(e)}}catch(e){m(e),y(!1)}}),()=>{};y(!1)},[i,e]),r(()=>{s&&D(void 0,void 0,void 0,function*(){y(!0);try{const t=i.getStack(e),r=yield s.getCards(n),o=yield Promise.all(r.map(e=>D(void 0,void 0,void 0,function*(){return yield l.buildFromModel(t,e)})));f.current=o,u(f.current)}catch(e){m(e)}finally{y(!1)}const t=e=>{const n=e.detail.doc;if(n.active){const e=f.current.findIndex(e=>e.id==n._id);-1!=e?f.current=[...f.current.slice(0,e),n,...f.current.slice(e+1,f.current.length)]:f.current.push(n)}else{const e=f.current.findIndex(e=>e.id==n._id);-1!=e&&(f.current=[...f.current.slice(0,e),...f.current.slice(e+1,f.current.length)])}u([...f.current])};return s.addEventListener("doc",t),()=>{s.removeEventListener("doc",t)}})},[s,JSON.stringify(n)]),{domainList:a,loading:g,error:h}},L=(e,n)=>{const i=t(v),[s,l]=c(!1),[d,a]=c(),[u,f]=c(),g=o(!1);return r(()=>i?(g.current||(g.current=!0,l(!0),D(void 0,void 0,void 0,function*(){try{const t=i.getStack(e);if(t){const e=yield t.getDomain(n);e&&f(e)}}catch(e){a(e)}finally{l(!1)}})),()=>{}):(console.error("useDomain must be used within a DocStackProvider."),void l(!1)),[i,e,n]),{loading:s,error:d,domain:u}},E=(e,n,i={})=>{const s=t(v),[l,d]=c(),[a,u]=c([]),f=o([]),[g,y]=c(!0),[h,m]=c(null);return r(()=>{if(s&&n)return D(void 0,void 0,void 0,function*(){y(!0),m(null);try{const t=s.getStack(e);if(t){const e=yield t.getDomain(n);e&&d(e)}}catch(e){m(e),y(!1)}}),()=>{};y(!1)},[s,e,n]),r(()=>{l&&D(void 0,void 0,void 0,function*(){y(!0);try{const e=yield l.getRelations(i);f.current=e,u(f.current)}catch(e){m(e)}finally{y(!1)}const e=e=>{const n=e.detail.doc;if(n.active){console.log("useDomainRelations - a doc was changed or added",{doc:n});const e=f.current.findIndex(e=>e._id==n._id);-1!=e?(console.log("useDomainRelations - a doc was changed",{doc:n}),f.current=[...f.current.slice(0,e),n,...f.current.slice(e+1,f.current.length)]):(console.log("useDomainRelations - a doc was added",{doc:n}),f.current.push(n))}else{const e=f.current.findIndex(e=>e._id==n._id);-1!=e&&(f.current=[...f.current.slice(0,e),...f.current.slice(e+1,f.current.length)])}u([...f.current])};return l.addEventListener("doc",e),()=>{l.removeEventListener("doc",e)}})},[l,JSON.stringify(i)]),{docs:a,loading:g,error:h}};export{v as DocStackContext,y as StackProvider,C as useClass,S as useClassCreate,x as useClassDocs,w as useClassList,g as useDocStack,L as useDomain,b as useDomainCreate,P as useDomainList,E as useDomainRelations,p as useFind,m as useQuerySQL};
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","mappings":";qOAWIA,EAAqBC,OAAOC,IAAI,8BACZD,OAAOC,IAAI,kBAoBnCC,EAAQC,IAnBR,SAAiBC,EAAMC,EAAQC,GAC7B,IAAIC,EAAM,KAGV,QAFA,IAAWD,IAAaC,EAAM,GAAKD,QACnC,IAAWD,EAAOE,MAAQA,EAAM,GAAKF,EAAOE,KACxC,QAASF,EAEX,IAAK,IAAIG,KADTF,EAAW,CAAC,EACSD,EACnB,QAAUG,IAAaF,EAASE,GAAYH,EAAOG,SAChDF,EAAWD,EAElB,OADAA,EAASC,EAASG,IACX,CACLC,SAAUX,EACVK,KAAMA,EACNG,IAAKA,EACLE,SAAK,IAAWJ,EAASA,EAAS,KAClCM,MAAOL,EAEX,C,aC3BEM,EAAOV,QAAU,EAAjB,I,GCFEW,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OA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kB,EAAkBC,IACpB,MAAMwB,EAAMxB,EAAOyB,OAAOD,IAC1B,GAAKA,EAAIE,OAUJ,CAEDrF,QAAQC,IAAI,kDAAmD,CAAEkF,QACjE,MAAMG,EAAWW,EAAQnG,QAAQyF,UAAW7G,GAAMA,EAAE+G,KAAON,EAAIM,MAC9C,GAAbH,GAEAtF,QAAQC,IAAI,yCAA0C,CAAEkF,QACxDc,EAAQnG,QAAU,IACXmG,EAAQnG,QAAQ4F,MAAM,EAAGJ,GAC5BH,KACGc,EAAQnG,QAAQ4F,MAAMJ,EAAW,EAAGW,EAAQnG,QAAQC,WAK3DC,QAAQC,IAAI,uCAAwC,CAAEkF,QACtDc,EAAQnG,QAAQoF,KAAKC,GAE7B,KA5BiB,CAEb,MAAMG,EAAWW,EAAQnG,QAAQyF,UAAW7G,GAAMA,EAAE+G,KAAON,EAAIM,MAC9C,GAAbH,IACAW,EAAQnG,QAAU,IACXmG,EAAQnG,QAAQ4F,MAAM,EAAGJ,MACzBW,EAAQnG,QAAQ4F,MAAMJ,EAAW,EAAGW,EAAQnG,QAAQC,SAGnE,CAoBAsD,EAAQ,IAAI4C,EAAQnG,WAGxB,OADAmH,EAAOrG,iBAAiB,MAAO8C,GACxB,KACHuD,EAAOrD,oBAAoB,MAAOF,GAE1C,IAED,CAACuD,EAAQpD,KAAKC,UAAUf,KACpB,CAAEK,OAAMb,UAASE,iB","sources":["webpack://@docstack/react/./node_modules/react/cjs/react-jsx-runtime.production.js","webpack://@docstack/react/./node_modules/react/jsx-runtime.js","webpack://@docstack/react/webpack/bootstrap","webpack://@docstack/react/webpack/runtime/define property getters","webpack://@docstack/react/webpack/runtime/hasOwnProperty shorthand","webpack://@docstack/react/./src/components/StackProvider/index.tsx","webpack://@docstack/react/./src/hooks/index.ts","webpack://@docstack/react/./src/hooks/class.ts","webpack://@docstack/react/./src/hooks/domain.ts"],"sourcesContent":["/**\n * @license React\n * react-jsx-runtime.production.js\n *\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n\"use strict\";\nvar REACT_ELEMENT_TYPE = Symbol.for(\"react.transitional.element\"),\n REACT_FRAGMENT_TYPE = Symbol.for(\"react.fragment\");\nfunction jsxProd(type, config, maybeKey) {\n var key = null;\n void 0 !== maybeKey && (key = \"\" + maybeKey);\n void 0 !== config.key && (key = \"\" + config.key);\n if (\"key\" in config) {\n maybeKey = {};\n for (var propName in config)\n \"key\" !== propName && (maybeKey[propName] = config[propName]);\n } else maybeKey = config;\n config = maybeKey.ref;\n return {\n $$typeof: REACT_ELEMENT_TYPE,\n type: type,\n key: key,\n ref: void 0 !== config ? config : null,\n props: maybeKey\n };\n}\nexports.Fragment = REACT_FRAGMENT_TYPE;\nexports.jsx = jsxProd;\nexports.jsxs = jsxProd;\n","'use strict';\n\nif (process.env.NODE_ENV === 'production') {\n module.exports = require('./cjs/react-jsx-runtime.production.js');\n} else {\n module.exports = require('./cjs/react-jsx-runtime.development.js');\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { createContext, useContext, useRef, useCallback, useEffect, useState } from 'react';\nimport { DocStack } from '@docstack/client'; // Import your DocStack class\n// You can give it a default value, e.g., null, which can be checked later.\nexport const DocStackContext = createContext(null);\nexport const useDocStack = () => {\n return useContext(DocStackContext);\n};\nconst StackProvider = (props) => {\n const { config, children, credentials } = props;\n // Use a ref to store the DocStack instance\n const docStackRef = useRef(null);\n const [docStack, setDocStack] = useState(null);\n const setsDocStackWhenReady = useCallback(() => {\n setDocStack(docStackRef.current);\n }, []);\n useEffect(() => {\n if (docStackRef.current === null && config.length) {\n console.log(\"DocStack provider - init instance\", { config });\n const mergedConfig = config.map((cfg, idx) => {\n const cred = Array.isArray(credentials) ? credentials[idx] : credentials;\n if (typeof cfg === \"string\") {\n return cred ? { connection: cfg, credentials: cred } : cfg;\n }\n return cred ? Object.assign(Object.assign({}, cfg), { credentials: cred }) : cfg;\n });\n const instance = new DocStack(...mergedConfig);\n docStackRef.current = instance;\n docStackRef.current.addEventListener(\"ready\", setsDocStackWhenReady);\n }\n // Optional: Cleanup function to remove listeners\n return () => {\n if (docStackRef.current) {\n // docStackRef.current.removeEventListener(\"ready\", setsDocStackWhenReady);\n // docStackRef.current.getStore().removeAllListeners();\n }\n };\n }, [config, credentials, setsDocStackWhenReady]);\n return (_jsx(DocStackContext.Provider, { value: docStack, children: children }));\n};\nexport default StackProvider;\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\n// src/hooks/useFind.js\nimport { useContext, useEffect, useRef, useState } from 'react';\nimport { DocStackContext } from '../components/StackProvider';\nexport const useQuerySQL = (stack, sql, ...params) => {\n const docStack = useContext(DocStackContext);\n const [result, setResult] = useState({ rows: [], ast: [] });\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n // [TODO] Solve bounce of component because of StrictMode or other reasons\n const queryRef = useRef(false);\n useEffect(() => {\n if (!docStack) {\n // Handle the case where the provider is not yet initialized or missing\n // You could throw an error or return an empty state.\n console.error('useClassList must be used within a DocStackProvider.');\n setLoading(false);\n return;\n }\n const runQuery = () => __awaiter(void 0, void 0, void 0, function* () {\n try {\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n // Run the initial query\n console.log(\"Preparing to run query\", { sql, params });\n // debugger\n const queryResult = yield stackInstance.query(sql, ...params);\n setResult(queryResult);\n }\n else {\n console.log(\"Could not find corresponding stack\", { stack });\n }\n }\n catch (err) {\n console.log(\"Got error while running query\", { error: err });\n setError(err);\n }\n finally {\n setLoading(false);\n }\n });\n if (!queryRef.current) {\n queryRef.current = true;\n setLoading(true);\n runQuery();\n }\n else {\n console.log(\"Already performing query\");\n }\n return () => {\n //\n };\n }, [docStack, stack, params]);\n return { loading, result, error };\n};\nexport const useFind = (stack, query, sort, limit = 50) => {\n const docStack = useContext(DocStackContext);\n const [docs, setDocs] = useState([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n useEffect(() => {\n // Check if the docStack instance is available\n if (!docStack) {\n // Handle the case where the provider is not yet initialized or missing\n // You could throw an error or return an empty state.\n console.error('useFind must be used within a DocStackProvider.');\n setLoading(false);\n return;\n }\n setLoading(true);\n const runQuery = () => __awaiter(void 0, void 0, void 0, function* () {\n try {\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n // Run the initial query\n const initialDocs = yield stackInstance.findDocuments(query.selector, query.fields);\n if (initialDocs.docs.length) {\n let docs = initialDocs.docs; // [TODO] Check types\n setDocs(docs);\n }\n }\n }\n catch (err) {\n setError(err);\n }\n finally {\n setLoading(false);\n }\n });\n runQuery();\n // Set up the listener for changes\n const changeListener = (change) => {\n // Logic to handle the change and update the docs state\n // This part is crucial for real-time updates.\n // You'll need to re-run the query or intelligently update the docs array\n // based on the change object (add, update, delete).\n // A simple way is to re-run the query.\n // runQuery();\n };\n // [TODO] Implement events\n docStack.addEventListener('change', changeListener);\n // Cleanup function: remove the listener when the component unmounts\n return () => {\n docStack.removeEventListener('change', changeListener);\n };\n }, [docStack, JSON.stringify(query)]); // Re-run if docStack or query changes\n return { docs, loading, error };\n};\nexport const useClassCreate = () => {\n};\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { useContext, useCallback, useEffect, useRef, useState } from \"react\";\nimport { DocStackContext } from \"../components/StackProvider\";\nimport { Class } from \"@docstack/client\";\nexport const useClassCreate = (stack) => {\n const docStack = useContext(DocStackContext);\n return useCallback((className, classDesc) => __awaiter(void 0, void 0, void 0, function* () {\n try {\n if (!docStack) {\n // Handle the case where the provider is not yet initialized or missing\n // You could throw an error or return an empty state.\n console.error('useClassCreate must be used within a DocStackProvider.');\n // setLoading(false);\n return Promise.resolve(null);\n }\n // Run the initial query\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n const classObj_ = yield Class.create(stackInstance, className, \"class\", classDesc);\n yield stackInstance.addClass(classObj_);\n return classObj_;\n }\n return null;\n }\n catch (err) {\n // setError(err);\n console.error(err);\n return null;\n }\n }), [docStack, stack]);\n};\nexport const useClassList = (stack, selector) => {\n const docStack = useContext(DocStackContext);\n const [originClass, setOriginClass] = useState();\n const [classList, setClassList] = useState([]);\n const classListRef = useRef([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n useEffect(() => {\n // Only run if the docStack is available and a className is provided\n if (!docStack) {\n setLoading(false);\n return;\n }\n const fetchClass = () => __awaiter(void 0, void 0, void 0, function* () {\n setLoading(true);\n setError(null);\n try {\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n const retrievedClass = yield stackInstance.getClass('class');\n if (retrievedClass) {\n setOriginClass(retrievedClass);\n }\n }\n }\n catch (err) {\n setError(err);\n setLoading(false);\n }\n });\n fetchClass();\n return () => {\n // clean what?\n };\n }, [docStack, stack]); // Dependency on docStack and stack\n useEffect(() => {\n if (!originClass) {\n return;\n }\n const runQueryAndListen = () => __awaiter(void 0, void 0, void 0, function* () {\n setLoading(true);\n try {\n const initialClassModelList = yield originClass.getCards(selector);\n const initialClassList = [];\n const stackInstance = docStack.getStack(stack);\n for (const cls of initialClassModelList) {\n const classInstance = yield Class.buildFromModel(stackInstance, cls);\n initialClassList.push(classInstance);\n }\n classListRef.current = initialClassList;\n setClassList(classListRef.current);\n }\n catch (err) {\n setError(err);\n }\n finally {\n setLoading(false);\n }\n const changeListener = (change) => {\n const doc = change.detail.doc;\n console.log(\"useClassDocs - detail\", { detail: change.detail });\n if (!doc.active) {\n // A doc was deleted\n console.log(\"useClassDocs - a doc was deleted\", { doc });\n const docIndex = classListRef.current.findIndex((d) => d.id == doc._id);\n if (docIndex != -1) {\n classListRef.current = [\n ...classListRef.current.slice(0, docIndex),\n ...classListRef.current.slice(docIndex + 1, classListRef.current.length)\n ];\n }\n }\n else {\n // A doc was changed or added\n const docIndex = classListRef.current.findIndex((d) => d.id == doc._id);\n if (docIndex != -1) {\n // A doc was changed\n classListRef.current = [\n ...classListRef.current.slice(0, docIndex),\n doc,\n ...classListRef.current.slice(docIndex + 1, classListRef.current.length)\n ];\n }\n else {\n // A doc was added\n classListRef.current.push(doc);\n }\n }\n setClassList([...classListRef.current]);\n };\n originClass.addEventListener('doc', changeListener);\n return () => {\n originClass.removeEventListener('doc', changeListener);\n };\n });\n runQueryAndListen();\n }, [originClass, JSON.stringify(selector)]); // Dependency on classObj and query\n return { classList, loading, error };\n};\nexport const useClass = (stack, className) => {\n const docStack = useContext(DocStackContext);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState();\n const [classObj, setClass] = useState();\n const reqRef = useRef(false);\n useEffect(() => {\n if (!docStack) {\n // Handle the case where the provider is not yet initialized or missing\n // You could throw an error or return an empty state.\n console.error('useClass must be used within a DocStackProvider.');\n setLoading(false);\n return;\n }\n const fetchClass = () => __awaiter(void 0, void 0, void 0, function* () {\n try {\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n const res = yield stackInstance.getClass(className);\n // TODO: manage class model (schema!) updates\n if (res) {\n setClass(res);\n }\n }\n }\n catch (e) {\n setError(e);\n }\n finally {\n setLoading(false);\n }\n });\n if (!reqRef.current) {\n reqRef.current = true;\n setLoading(true);\n fetchClass();\n }\n return () => {\n // reqRef.current = false;\n };\n }, [docStack, stack, className]);\n return { loading, error, classObj };\n};\nexport const useClassDocs = (stack, className, query = {}) => {\n const docStack = useContext(DocStackContext);\n const [classObj, setClass] = useState();\n const [docs, setDocs] = useState([]);\n const docsRef = useRef([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n useEffect(() => {\n // Only run if the docStack is available and a className is provided\n if (!docStack || !className) {\n setLoading(false);\n return;\n }\n const fetchClass = () => __awaiter(void 0, void 0, void 0, function* () {\n setLoading(true);\n setError(null);\n try {\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n const retrievedClass = yield stackInstance.getClass(className);\n if (retrievedClass) {\n setClass(retrievedClass);\n }\n }\n }\n catch (err) {\n setError(err);\n setLoading(false);\n }\n });\n fetchClass();\n return () => {\n // clean what?\n };\n }, [docStack, stack, className]); // Dependency on docStack and className\n useEffect(() => {\n if (!classObj) {\n return;\n }\n const runQueryAndListen = () => __awaiter(void 0, void 0, void 0, function* () {\n setLoading(true);\n try {\n debugger;\n const initialDocs = yield classObj.getCards(query);\n docsRef.current = initialDocs;\n setDocs(docsRef.current);\n }\n catch (err) {\n setError(err);\n }\n finally {\n setLoading(false);\n }\n const changeListener = (change) => {\n const doc = change.detail.doc;\n console.log(\"useClassDocs - detail\", { detail: change.detail });\n if (!doc.active) {\n // A doc was deleted\n console.log(\"useClassDocs - a doc was deleted\", { doc });\n const docIndex = docsRef.current.findIndex((d) => d._id == doc._id);\n if (docIndex != -1) {\n docsRef.current = [\n ...docsRef.current.slice(0, docIndex),\n ...docsRef.current.slice(docIndex + 1, docsRef.current.length)\n ];\n }\n }\n else {\n // A doc was changed or added\n console.log(\"useClassDocs - a doc was changed or added\", { doc });\n const docIndex = docsRef.current.findIndex((d) => d._id == doc._id);\n if (docIndex != -1) {\n // A doc was changed\n console.log(\"useClassDocs - a doc was changed\", { doc });\n docsRef.current = [\n ...docsRef.current.slice(0, docIndex),\n doc,\n ...docsRef.current.slice(docIndex + 1, docsRef.current.length)\n ];\n }\n else {\n // A doc was added\n console.log(\"useClassDocs - a doc was added\", { doc });\n docsRef.current.push(doc);\n }\n }\n setDocs([...docsRef.current]);\n };\n classObj.addEventListener('doc', changeListener);\n return () => {\n classObj.removeEventListener('doc', changeListener);\n };\n });\n runQueryAndListen();\n }, [classObj, JSON.stringify(query)]); // Dependency on classObj and query\n return { docs, loading, error };\n};\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { useContext, useCallback, useEffect, useRef, useState } from \"react\";\nimport { DocStackContext } from \"../components/StackProvider\";\nimport { Domain } from \"@docstack/shared\";\nexport const useDomainCreate = (stack) => {\n const docStack = useContext(DocStackContext);\n return useCallback((domainName, cardinality, sourceClass, targetClass, domainDesc) => __awaiter(void 0, void 0, void 0, function* () {\n try {\n if (!docStack) {\n // Handle the case where the provider is not yet initialized or missing\n // You could throw an error or return an empty state.\n console.error('useDomainCreate must be used within a DocStackProvider.');\n // setLoading(false);\n return Promise.resolve(null);\n }\n // Run the initial query\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n const domain = yield Domain.create(stackInstance, null, domainName, \"domain\", cardinality, sourceClass, targetClass, domainDesc);\n return domain;\n }\n return null;\n }\n catch (err) {\n // setError(err);\n console.error(err);\n return null;\n }\n }), [docStack, stack]);\n};\nexport const useDomainList = (stack, selector) => {\n const docStack = useContext(DocStackContext);\n const [originClass, setOriginClass] = useState();\n const [domainList, setDomainList] = useState([]);\n const domainListRef = useRef([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n useEffect(() => {\n // Only run if the docStack is available and a className is provided\n if (!docStack) {\n setLoading(false);\n return;\n }\n const fetchClass = () => __awaiter(void 0, void 0, void 0, function* () {\n setLoading(true);\n setError(null);\n try {\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n const retrievedClass = yield stackInstance.getClass('domain');\n if (retrievedClass) {\n setOriginClass(retrievedClass);\n }\n }\n }\n catch (err) {\n setError(err);\n setLoading(false);\n }\n });\n fetchClass();\n return () => {\n // clean what?\n };\n }, [docStack, stack]); // Dependency on docStack and stack\n useEffect(() => {\n if (!originClass) {\n return;\n }\n const runQueryAndListen = () => __awaiter(void 0, void 0, void 0, function* () {\n setLoading(true);\n try {\n const stackInstance = docStack.getStack(stack);\n const initialDomainModelList = yield originClass.getCards(selector);\n const initDomainList = yield Promise.all(initialDomainModelList.map((dm) => __awaiter(void 0, void 0, void 0, function* () { return yield Domain.buildFromModel(stackInstance, dm); })));\n domainListRef.current = initDomainList;\n setDomainList(domainListRef.current);\n }\n catch (err) {\n setError(err);\n }\n finally {\n setLoading(false);\n }\n const changeListener = (change) => {\n const doc = change.detail.doc;\n if (!doc.active) {\n // A doc was deleted\n const docIndex = domainListRef.current.findIndex((d) => d.id == doc._id);\n if (docIndex != -1) {\n domainListRef.current = [\n ...domainListRef.current.slice(0, docIndex),\n ...domainListRef.current.slice(docIndex + 1, domainListRef.current.length)\n ];\n }\n }\n else {\n // A doc was changed or added\n const docIndex = domainListRef.current.findIndex((d) => d.id == doc._id);\n if (docIndex != -1) {\n // A doc was changed\n domainListRef.current = [\n ...domainListRef.current.slice(0, docIndex),\n doc,\n ...domainListRef.current.slice(docIndex + 1, domainListRef.current.length)\n ];\n }\n else {\n // A doc was added\n domainListRef.current.push(doc);\n }\n }\n setDomainList([...domainListRef.current]);\n };\n originClass.addEventListener('doc', changeListener);\n return () => {\n originClass.removeEventListener('doc', changeListener);\n };\n });\n runQueryAndListen();\n }, [originClass, JSON.stringify(selector)]); // Dependency on classObj and query\n return { domainList, loading, error };\n};\nexport const useDomain = (stack, domainName) => {\n const docStack = useContext(DocStackContext);\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState();\n const [domain, setDomain] = useState();\n const reqRef = useRef(false);\n useEffect(() => {\n if (!docStack) {\n // Handle the case where the provider is not yet initialized or missing\n // You could throw an error or return an empty state.\n console.error('useDomain must be used within a DocStackProvider.');\n setLoading(false);\n return;\n }\n const fetchClass = () => __awaiter(void 0, void 0, void 0, function* () {\n try {\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n const res = yield stackInstance.getDomain(domainName);\n // TODO: manage class model (schema!) updates\n if (res) {\n setDomain(res);\n }\n }\n }\n catch (e) {\n setError(e);\n }\n finally {\n setLoading(false);\n }\n });\n if (!reqRef.current) {\n reqRef.current = true;\n setLoading(true);\n fetchClass();\n }\n return () => {\n // reqRef.current = false;\n };\n }, [docStack, stack, domainName]);\n return { loading, error, domain };\n};\nexport const useDomainRelations = (stack, domainName, query = {}) => {\n const docStack = useContext(DocStackContext);\n const [domain, setDomain] = useState();\n const [docs, setDocs] = useState([]);\n const docsRef = useRef([]);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n useEffect(() => {\n // Only run if the docStack is available and a className is provided\n if (!docStack || !domainName) {\n setLoading(false);\n return;\n }\n const fetchClass = () => __awaiter(void 0, void 0, void 0, function* () {\n setLoading(true);\n setError(null);\n try {\n const stackInstance = docStack.getStack(stack);\n if (stackInstance) {\n const retrievedDomain = yield stackInstance.getDomain(domainName);\n if (retrievedDomain) {\n setDomain(retrievedDomain);\n }\n }\n }\n catch (err) {\n setError(err);\n setLoading(false);\n }\n });\n fetchClass();\n return () => {\n // clean what?\n };\n }, [docStack, stack, domainName]); // Dependency on docStack and className\n useEffect(() => {\n if (!domain) {\n return;\n }\n const runQueryAndListen = () => __awaiter(void 0, void 0, void 0, function* () {\n setLoading(true);\n try {\n const initialDocs = yield domain.getRelations(query);\n docsRef.current = initialDocs;\n setDocs(docsRef.current);\n }\n catch (err) {\n setError(err);\n }\n finally {\n setLoading(false);\n }\n const changeListener = (change) => {\n const doc = change.detail.doc;\n if (!doc.active) {\n // A doc was deleted\n const docIndex = docsRef.current.findIndex((d) => d._id == doc._id);\n if (docIndex != -1) {\n docsRef.current = [\n ...docsRef.current.slice(0, docIndex),\n ...docsRef.current.slice(docIndex + 1, docsRef.current.length)\n ];\n }\n }\n else {\n // A doc was changed or added\n console.log(\"useDomainRelations - a doc was changed or added\", { doc });\n const docIndex = docsRef.current.findIndex((d) => d._id == doc._id);\n if (docIndex != -1) {\n // A doc was changed\n console.log(\"useDomainRelations - a doc was changed\", { doc });\n docsRef.current = [\n ...docsRef.current.slice(0, docIndex),\n doc,\n ...docsRef.current.slice(docIndex + 1, docsRef.current.length)\n ];\n }\n else {\n // A doc was added\n console.log(\"useDomainRelations - a doc was added\", { doc });\n docsRef.current.push(doc);\n }\n }\n setDocs([...docsRef.current]);\n };\n domain.addEventListener('doc', changeListener);\n return () => {\n domain.removeEventListener('doc', changeListener);\n };\n });\n runQueryAndListen();\n }, [domain, JSON.stringify(query)]); // Dependency on classObj and query\n return { docs, loading, error };\n};\n"],"names":["REACT_ELEMENT_TYPE","Symbol","for","exports","jsx","type","config","maybeKey","key","propName","ref","$$typeof","props","module","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","d","definition","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","DocStackContext","useDocStack","children","credentials","docStackRef","docStack","setDocStack","setsDocStackWhenReady","current","length","console","log","mergedConfig","map","cfg","idx","cred","Array","isArray","connection","assign","instance","addEventListener","Provider","value","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","then","apply","useQuerySQL","stack","sql","params","setResult","rows","ast","loading","setLoading","error","setError","queryRef","stackInstance","getStack","queryResult","query","err","useFind","sort","limit","docs","setDocs","initialDocs","findDocuments","selector","fields","changeListener","change","removeEventListener","JSON","stringify","className","classDesc","classObj_","create","addClass","useClassList","originClass","setOriginClass","classList","setClassList","classListRef","retrievedClass","getClass","initialClassModelList","getCards","initialClassList","cls","classInstance","buildFromModel","push","doc","detail","active","docIndex","findIndex","id","_id","slice","useClass","classObj","setClass","reqRef","res","useClassDocs","docsRef","useDomainCreate","domainName","cardinality","sourceClass","targetClass","domainDesc","useDomainList","domainList","setDomainList","domainListRef","initialDomainModelList","initDomainList","all","dm","useDomain","domain","setDomain","getDomain","useDomainRelations","retrievedDomain","getRelations"],"ignoreList":[],"sourceRoot":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@docstack/react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "One does not simply stack documents.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"src": "src/index.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "npm run build:prod",
|
|
14
|
+
"build:dev": "webpack --node-env=development",
|
|
15
|
+
"build:prod": "webpack --node-env=production"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/onyx-og/docstack.git"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"react",
|
|
23
|
+
"components",
|
|
24
|
+
"database",
|
|
25
|
+
"documents",
|
|
26
|
+
"nosql", "sql",
|
|
27
|
+
"storage",
|
|
28
|
+
"state-management"
|
|
29
|
+
],
|
|
30
|
+
"author": "Onyx <hello@onyx.ac> (https://onyx.ac)",
|
|
31
|
+
"license": "CC-BY-SA-4.0",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/onyx-og/docstack/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://onyx.ac/docstack",
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": "^19.2.3",
|
|
38
|
+
"react-dom": "^19.2.3"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@docstack/client": "^0.0.8",
|
|
42
|
+
"@docstack/shared": "^0.0.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"eslint": "^9.38.0",
|
|
46
|
+
"eslint-webpack-plugin": "^5.0.2",
|
|
47
|
+
"https-browserify": "^1.0.0",
|
|
48
|
+
"stream-http": "^3.2.0"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ReactNode, createContext, useContext, useRef, useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import {DocStack} from '@docstack/client'; // Import your DocStack class
|
|
3
|
+
import { ClientCredentials, StackConfig } from '@docstack/shared';
|
|
4
|
+
|
|
5
|
+
// You can give it a default value, e.g., null, which can be checked later.
|
|
6
|
+
export const DocStackContext = createContext<DocStack | null>(null);
|
|
7
|
+
|
|
8
|
+
export const useDocStack = () => {
|
|
9
|
+
return useContext(DocStackContext);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export interface DocStackProviderProps {
|
|
13
|
+
config: StackConfig[];
|
|
14
|
+
credentials?: ClientCredentials | ClientCredentials[];
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
const StackProvider = (props: DocStackProviderProps) => {
|
|
18
|
+
const { config, children, credentials } = props;
|
|
19
|
+
// Use a ref to store the DocStack instance
|
|
20
|
+
const docStackRef = useRef<DocStack | null>(null);
|
|
21
|
+
const [docStack, setDocStack] = useState<DocStack | null>(null);
|
|
22
|
+
|
|
23
|
+
const setsDocStackWhenReady = useCallback(() => {
|
|
24
|
+
setDocStack(docStackRef.current)
|
|
25
|
+
},[]);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (docStackRef.current === null && config.length) {
|
|
29
|
+
console.log("DocStack provider - init instance", {config});
|
|
30
|
+
const mergedConfig = config.map((cfg, idx) => {
|
|
31
|
+
const cred = Array.isArray(credentials) ? credentials[idx] : credentials;
|
|
32
|
+
if (typeof cfg === "string") {
|
|
33
|
+
return cred ? { connection: cfg, credentials: cred } : cfg;
|
|
34
|
+
}
|
|
35
|
+
return cred ? { ...cfg, credentials: cred } : cfg;
|
|
36
|
+
});
|
|
37
|
+
const instance = new DocStack(...mergedConfig as StackConfig[]);
|
|
38
|
+
docStackRef.current = instance;
|
|
39
|
+
docStackRef.current.addEventListener("ready", setsDocStackWhenReady);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Optional: Cleanup function to remove listeners
|
|
43
|
+
return () => {
|
|
44
|
+
if (docStackRef.current) {
|
|
45
|
+
// docStackRef.current.removeEventListener("ready", setsDocStackWhenReady);
|
|
46
|
+
// docStackRef.current.getStore().removeAllListeners();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}, [config, credentials, setsDocStackWhenReady]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<DocStackContext.Provider value={docStack}>
|
|
53
|
+
{children}
|
|
54
|
+
</DocStackContext.Provider>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export default StackProvider;
|
|
File without changes
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { useContext, useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { DocStackContext } from "../components/StackProvider";
|
|
3
|
+
import { Class } from "@docstack/client";
|
|
4
|
+
import {ClassModel, Document} from "@docstack/shared";
|
|
5
|
+
|
|
6
|
+
export const useClassCreate = (stack: string) => {
|
|
7
|
+
const docStack = useContext(DocStackContext);
|
|
8
|
+
|
|
9
|
+
return useCallback(
|
|
10
|
+
async ( className: string, classDesc?: string) => {
|
|
11
|
+
try {
|
|
12
|
+
if (!docStack) {
|
|
13
|
+
// Handle the case where the provider is not yet initialized or missing
|
|
14
|
+
// You could throw an error or return an empty state.
|
|
15
|
+
console.error('useClassCreate must be used within a DocStackProvider.');
|
|
16
|
+
// setLoading(false);
|
|
17
|
+
return Promise.resolve(null);
|
|
18
|
+
}
|
|
19
|
+
// Run the initial query
|
|
20
|
+
const stackInstance = docStack.getStack(stack);
|
|
21
|
+
if (stackInstance) {
|
|
22
|
+
const classObj_ = await Class.create(stackInstance, className, "class", classDesc);
|
|
23
|
+
await stackInstance.addClass(classObj_);
|
|
24
|
+
return classObj_;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
|
|
28
|
+
} catch (err: any) {
|
|
29
|
+
// setError(err);
|
|
30
|
+
console.error(err);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}, [docStack, stack]
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const useClassList = (stack: string, selector: {[key: string]: any}) => {
|
|
38
|
+
const docStack = useContext(DocStackContext);
|
|
39
|
+
const [originClass, setOriginClass] = useState<Class>();
|
|
40
|
+
const [classList, setClassList] = useState<Class[]>([]);
|
|
41
|
+
const classListRef = useRef<Class[]>([]);
|
|
42
|
+
|
|
43
|
+
const [loading, setLoading] = useState(true);
|
|
44
|
+
const [error, setError] = useState(null);
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
// Only run if the docStack is available and a className is provided
|
|
49
|
+
if (!docStack) {
|
|
50
|
+
setLoading(false);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const fetchClass = async () => {
|
|
55
|
+
setLoading(true);
|
|
56
|
+
setError(null);
|
|
57
|
+
try {
|
|
58
|
+
const stackInstance = docStack.getStack(stack);
|
|
59
|
+
if (stackInstance) {
|
|
60
|
+
const retrievedClass = await stackInstance.getClass('class');
|
|
61
|
+
if (retrievedClass) {
|
|
62
|
+
setOriginClass(retrievedClass);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} catch (err: any) {
|
|
67
|
+
setError(err);
|
|
68
|
+
setLoading(false);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
fetchClass();
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
// clean what?
|
|
76
|
+
};
|
|
77
|
+
}, [docStack, stack]); // Dependency on docStack and stack
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!originClass) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const runQueryAndListen = async () => {
|
|
85
|
+
setLoading(true);
|
|
86
|
+
try {
|
|
87
|
+
const initialClassModelList = await originClass.getCards(selector) as ClassModel[];
|
|
88
|
+
const initialClassList: Class[] = [];
|
|
89
|
+
const stackInstance = docStack!.getStack(stack);
|
|
90
|
+
for (const cls of initialClassModelList) {
|
|
91
|
+
const classInstance = await Class.buildFromModel(stackInstance!, cls);
|
|
92
|
+
initialClassList.push(classInstance);
|
|
93
|
+
}
|
|
94
|
+
classListRef.current = initialClassList;
|
|
95
|
+
setClassList(classListRef.current);
|
|
96
|
+
} catch (err: any) {
|
|
97
|
+
setError(err);
|
|
98
|
+
} finally {
|
|
99
|
+
setLoading(false);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const changeListener = (change: CustomEvent) => {
|
|
103
|
+
const doc = change.detail.doc;
|
|
104
|
+
console.log("useClassDocs - detail", {detail: change.detail});
|
|
105
|
+
if (!doc.active) {
|
|
106
|
+
// A doc was deleted
|
|
107
|
+
console.log("useClassDocs - a doc was deleted", {doc});
|
|
108
|
+
const docIndex = classListRef.current.findIndex((d) => d.id == doc._id)
|
|
109
|
+
if (docIndex != -1) {
|
|
110
|
+
classListRef.current = [
|
|
111
|
+
...classListRef.current.slice(0, docIndex),
|
|
112
|
+
...classListRef.current.slice(docIndex+1, classListRef.current.length)
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
// A doc was changed or added
|
|
117
|
+
const docIndex = classListRef.current.findIndex((d) => d.id == doc._id)
|
|
118
|
+
if (docIndex != -1) {
|
|
119
|
+
// A doc was changed
|
|
120
|
+
classListRef.current = [
|
|
121
|
+
...classListRef.current.slice(0, docIndex),
|
|
122
|
+
doc,
|
|
123
|
+
...classListRef.current.slice(docIndex+1, classListRef.current.length)
|
|
124
|
+
];
|
|
125
|
+
} else {
|
|
126
|
+
// A doc was added
|
|
127
|
+
classListRef.current.push(doc);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
setClassList([...classListRef.current])
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
originClass.addEventListener('doc', changeListener as EventListener);
|
|
134
|
+
|
|
135
|
+
return () => {
|
|
136
|
+
originClass.removeEventListener('doc', changeListener as EventListener);
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
runQueryAndListen();
|
|
141
|
+
}, [originClass, JSON.stringify(selector)]); // Dependency on classObj and query
|
|
142
|
+
|
|
143
|
+
return { classList, loading, error };
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const useClass = (stack: string, className: string) => {
|
|
147
|
+
const docStack = useContext(DocStackContext);
|
|
148
|
+
const [loading, setLoading] = useState<boolean>(false);
|
|
149
|
+
const [error, setError] = useState();
|
|
150
|
+
const [classObj, setClass] = useState<Class>();
|
|
151
|
+
const reqRef = useRef(false);
|
|
152
|
+
|
|
153
|
+
useEffect( () => {
|
|
154
|
+
if (!docStack) {
|
|
155
|
+
// Handle the case where the provider is not yet initialized or missing
|
|
156
|
+
// You could throw an error or return an empty state.
|
|
157
|
+
console.error('useClass must be used within a DocStackProvider.');
|
|
158
|
+
setLoading(false);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const fetchClass = async () => {
|
|
163
|
+
try {
|
|
164
|
+
const stackInstance = docStack.getStack(stack);
|
|
165
|
+
if (stackInstance) {
|
|
166
|
+
const res = await stackInstance.getClass(className);
|
|
167
|
+
// TODO: manage class model (schema!) updates
|
|
168
|
+
if (res) {
|
|
169
|
+
setClass(res);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
} catch (e: any) {
|
|
174
|
+
setError(e);
|
|
175
|
+
} finally {
|
|
176
|
+
setLoading(false)
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (!reqRef.current) {
|
|
181
|
+
reqRef.current = true;
|
|
182
|
+
setLoading(true);
|
|
183
|
+
fetchClass()
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return () => {
|
|
187
|
+
// reqRef.current = false;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
}, [docStack, stack, className]);
|
|
191
|
+
|
|
192
|
+
return {loading, error, classObj}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
export const useClassDocs = (stack: string, className: string, query = {}) => {
|
|
197
|
+
const docStack = useContext(DocStackContext);
|
|
198
|
+
|
|
199
|
+
const [classObj, setClass] = useState<Class>();
|
|
200
|
+
const [docs, setDocs] = useState<Document[]>([]);
|
|
201
|
+
const docsRef = useRef<Document[]>([]);
|
|
202
|
+
|
|
203
|
+
const [loading, setLoading] = useState(true);
|
|
204
|
+
const [error, setError] = useState(null);
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
// Only run if the docStack is available and a className is provided
|
|
209
|
+
if (!docStack || !className) {
|
|
210
|
+
setLoading(false);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const fetchClass = async () => {
|
|
215
|
+
setLoading(true);
|
|
216
|
+
setError(null);
|
|
217
|
+
try {
|
|
218
|
+
const stackInstance = docStack.getStack(stack);
|
|
219
|
+
if (stackInstance) {
|
|
220
|
+
const retrievedClass = await stackInstance.getClass(className);
|
|
221
|
+
if (retrievedClass) {
|
|
222
|
+
setClass(retrievedClass);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
} catch (err: any) {
|
|
227
|
+
setError(err);
|
|
228
|
+
setLoading(false);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
fetchClass();
|
|
233
|
+
|
|
234
|
+
return () => {
|
|
235
|
+
// clean what?
|
|
236
|
+
};
|
|
237
|
+
}, [docStack, stack, className]); // Dependency on docStack and className
|
|
238
|
+
|
|
239
|
+
useEffect(() => {
|
|
240
|
+
if (!classObj) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const runQueryAndListen = async () => {
|
|
245
|
+
setLoading(true);
|
|
246
|
+
try {
|
|
247
|
+
debugger;
|
|
248
|
+
const initialDocs = await classObj.getCards(query) as Document[];
|
|
249
|
+
docsRef.current = initialDocs;
|
|
250
|
+
setDocs(docsRef.current);
|
|
251
|
+
} catch (err: any) {
|
|
252
|
+
setError(err);
|
|
253
|
+
} finally {
|
|
254
|
+
setLoading(false);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const changeListener = (change: CustomEvent) => {
|
|
258
|
+
const doc = change.detail.doc;
|
|
259
|
+
console.log("useClassDocs - detail", {detail: change.detail});
|
|
260
|
+
if (!doc.active) {
|
|
261
|
+
// A doc was deleted
|
|
262
|
+
console.log("useClassDocs - a doc was deleted", {doc});
|
|
263
|
+
const docIndex = docsRef.current.findIndex((d) => d._id == doc._id)
|
|
264
|
+
if (docIndex != -1) {
|
|
265
|
+
docsRef.current = [
|
|
266
|
+
...docsRef.current.slice(0, docIndex),
|
|
267
|
+
...docsRef.current.slice(docIndex+1, docsRef.current.length)
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
} else {
|
|
271
|
+
// A doc was changed or added
|
|
272
|
+
console.log("useClassDocs - a doc was changed or added", {doc});
|
|
273
|
+
const docIndex = docsRef.current.findIndex((d) => d._id == doc._id)
|
|
274
|
+
if (docIndex != -1) {
|
|
275
|
+
// A doc was changed
|
|
276
|
+
console.log("useClassDocs - a doc was changed", {doc});
|
|
277
|
+
docsRef.current = [
|
|
278
|
+
...docsRef.current.slice(0, docIndex),
|
|
279
|
+
doc,
|
|
280
|
+
...docsRef.current.slice(docIndex+1, docsRef.current.length)
|
|
281
|
+
];
|
|
282
|
+
} else {
|
|
283
|
+
// A doc was added
|
|
284
|
+
console.log("useClassDocs - a doc was added", {doc});
|
|
285
|
+
docsRef.current.push(doc);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
setDocs([...docsRef.current])
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
classObj.addEventListener('doc', changeListener as EventListener);
|
|
292
|
+
|
|
293
|
+
return () => {
|
|
294
|
+
classObj.removeEventListener('doc', changeListener as EventListener);
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
runQueryAndListen();
|
|
299
|
+
}, [classObj, JSON.stringify(query)]); // Dependency on classObj and query
|
|
300
|
+
|
|
301
|
+
return { docs, loading, error };
|
|
302
|
+
};
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { useContext, useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { DocStackContext } from "../components/StackProvider";
|
|
3
|
+
import { Class } from "@docstack/client";
|
|
4
|
+
import {Document, Domain, DomainModel, RelationDocument, SelectAST, UnionAST} from "@docstack/shared";
|
|
5
|
+
|
|
6
|
+
export const useDomainCreate = (stack: string) => {
|
|
7
|
+
const docStack = useContext(DocStackContext);
|
|
8
|
+
|
|
9
|
+
return useCallback(
|
|
10
|
+
async (domainName: string, cardinality: "1:1" | "1:N" | "N:1" | "N:N", sourceClass: Class, targetClass: Class, domainDesc?: string) => {
|
|
11
|
+
try {
|
|
12
|
+
if (!docStack) {
|
|
13
|
+
// Handle the case where the provider is not yet initialized or missing
|
|
14
|
+
// You could throw an error or return an empty state.
|
|
15
|
+
console.error('useDomainCreate must be used within a DocStackProvider.');
|
|
16
|
+
// setLoading(false);
|
|
17
|
+
return Promise.resolve(null);
|
|
18
|
+
}
|
|
19
|
+
// Run the initial query
|
|
20
|
+
const stackInstance = docStack.getStack(stack);
|
|
21
|
+
if (stackInstance) {
|
|
22
|
+
const domain = await Domain.create(stackInstance, null, domainName, "domain", cardinality, sourceClass, targetClass, domainDesc);
|
|
23
|
+
return domain;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
|
|
27
|
+
} catch (err: any) {
|
|
28
|
+
// setError(err);
|
|
29
|
+
console.error(err);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}, [docStack, stack]
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const useDomainList = (stack: string, selector: {[key: string]: any}) => {
|
|
37
|
+
const docStack = useContext(DocStackContext);
|
|
38
|
+
|
|
39
|
+
const [originClass, setOriginClass] = useState<Class>();
|
|
40
|
+
const [domainList, setDomainList] = useState<Domain[]>([]);
|
|
41
|
+
const domainListRef = useRef<Domain[]>([]);
|
|
42
|
+
|
|
43
|
+
const [loading, setLoading] = useState(true);
|
|
44
|
+
const [error, setError] = useState(null);
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
// Only run if the docStack is available and a className is provided
|
|
49
|
+
if (!docStack) {
|
|
50
|
+
setLoading(false);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const fetchClass = async () => {
|
|
55
|
+
setLoading(true);
|
|
56
|
+
setError(null);
|
|
57
|
+
try {
|
|
58
|
+
const stackInstance = docStack.getStack(stack);
|
|
59
|
+
if (stackInstance) {
|
|
60
|
+
const retrievedClass = await stackInstance.getClass('domain');
|
|
61
|
+
if (retrievedClass) {
|
|
62
|
+
setOriginClass(retrievedClass);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} catch (err: any) {
|
|
67
|
+
setError(err);
|
|
68
|
+
setLoading(false);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
fetchClass();
|
|
73
|
+
|
|
74
|
+
return () => {
|
|
75
|
+
// clean what?
|
|
76
|
+
};
|
|
77
|
+
}, [docStack, stack]); // Dependency on docStack and stack
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!originClass) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const runQueryAndListen = async () => {
|
|
85
|
+
setLoading(true);
|
|
86
|
+
try {
|
|
87
|
+
const stackInstance = docStack!.getStack(stack)!;
|
|
88
|
+
const initialDomainModelList = await originClass.getCards(selector) as DomainModel[];
|
|
89
|
+
const initDomainList = await Promise.all(initialDomainModelList.map(async (dm) => await Domain.buildFromModel(stackInstance, dm)));
|
|
90
|
+
|
|
91
|
+
domainListRef.current = initDomainList;
|
|
92
|
+
setDomainList(domainListRef.current);
|
|
93
|
+
} catch (err: any) {
|
|
94
|
+
setError(err);
|
|
95
|
+
} finally {
|
|
96
|
+
setLoading(false);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const changeListener = (change: CustomEvent) => {
|
|
100
|
+
const doc = change.detail.doc;
|
|
101
|
+
if (!doc.active) {
|
|
102
|
+
// A doc was deleted
|
|
103
|
+
const docIndex = domainListRef.current.findIndex((d) => d.id == doc._id)
|
|
104
|
+
if (docIndex != -1) {
|
|
105
|
+
domainListRef.current = [
|
|
106
|
+
...domainListRef.current.slice(0, docIndex),
|
|
107
|
+
...domainListRef.current.slice(docIndex+1, domainListRef.current.length)
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
// A doc was changed or added
|
|
112
|
+
const docIndex = domainListRef.current.findIndex((d) => d.id == doc._id)
|
|
113
|
+
if (docIndex != -1) {
|
|
114
|
+
// A doc was changed
|
|
115
|
+
domainListRef.current = [
|
|
116
|
+
...domainListRef.current.slice(0, docIndex),
|
|
117
|
+
doc,
|
|
118
|
+
...domainListRef.current.slice(docIndex+1, domainListRef.current.length)
|
|
119
|
+
];
|
|
120
|
+
} else {
|
|
121
|
+
// A doc was added
|
|
122
|
+
domainListRef.current.push(doc);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
setDomainList([...domainListRef.current])
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
originClass.addEventListener('doc', changeListener as EventListener);
|
|
129
|
+
|
|
130
|
+
return () => {
|
|
131
|
+
originClass.removeEventListener('doc', changeListener as EventListener);
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
runQueryAndListen();
|
|
136
|
+
}, [originClass, JSON.stringify(selector)]); // Dependency on classObj and query
|
|
137
|
+
|
|
138
|
+
return { domainList, loading, error };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const useDomain = (stack: string, domainName: string) => {
|
|
142
|
+
const docStack = useContext(DocStackContext);
|
|
143
|
+
const [loading, setLoading] = useState<boolean>(false);
|
|
144
|
+
const [error, setError] = useState();
|
|
145
|
+
const [domain, setDomain] = useState<Domain>();
|
|
146
|
+
const reqRef = useRef(false);
|
|
147
|
+
|
|
148
|
+
useEffect( () => {
|
|
149
|
+
if (!docStack) {
|
|
150
|
+
// Handle the case where the provider is not yet initialized or missing
|
|
151
|
+
// You could throw an error or return an empty state.
|
|
152
|
+
console.error('useDomain must be used within a DocStackProvider.');
|
|
153
|
+
setLoading(false);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const fetchClass = async () => {
|
|
158
|
+
try {
|
|
159
|
+
const stackInstance = docStack.getStack(stack);
|
|
160
|
+
if (stackInstance) {
|
|
161
|
+
const res = await stackInstance.getDomain(domainName);
|
|
162
|
+
// TODO: manage class model (schema!) updates
|
|
163
|
+
if (res) {
|
|
164
|
+
setDomain(res);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
} catch (e: any) {
|
|
169
|
+
setError(e);
|
|
170
|
+
} finally {
|
|
171
|
+
setLoading(false)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!reqRef.current) {
|
|
176
|
+
reqRef.current = true;
|
|
177
|
+
setLoading(true);
|
|
178
|
+
fetchClass()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return () => {
|
|
182
|
+
// reqRef.current = false;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}, [docStack, stack, domainName]);
|
|
186
|
+
|
|
187
|
+
return {loading, error, domain}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
export const useDomainRelations = (stack: string, domainName: string, query = {}) => {
|
|
192
|
+
const docStack = useContext(DocStackContext);
|
|
193
|
+
|
|
194
|
+
const [domain, setDomain] = useState<Domain>();
|
|
195
|
+
const [docs, setDocs] = useState<RelationDocument[]>([]);
|
|
196
|
+
const docsRef = useRef<RelationDocument[]>([]);
|
|
197
|
+
|
|
198
|
+
const [loading, setLoading] = useState(true);
|
|
199
|
+
const [error, setError] = useState(null);
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
useEffect(() => {
|
|
203
|
+
// Only run if the docStack is available and a className is provided
|
|
204
|
+
if (!docStack || !domainName) {
|
|
205
|
+
setLoading(false);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const fetchClass = async () => {
|
|
210
|
+
setLoading(true);
|
|
211
|
+
setError(null);
|
|
212
|
+
try {
|
|
213
|
+
const stackInstance = docStack.getStack(stack);
|
|
214
|
+
if (stackInstance) {
|
|
215
|
+
const retrievedDomain = await stackInstance.getDomain(domainName);
|
|
216
|
+
if (retrievedDomain) {
|
|
217
|
+
setDomain(retrievedDomain);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
} catch (err: any) {
|
|
222
|
+
setError(err);
|
|
223
|
+
setLoading(false);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
fetchClass();
|
|
228
|
+
|
|
229
|
+
return () => {
|
|
230
|
+
// clean what?
|
|
231
|
+
};
|
|
232
|
+
}, [docStack, stack, domainName]); // Dependency on docStack and className
|
|
233
|
+
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
if (!domain) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const runQueryAndListen = async () => {
|
|
240
|
+
setLoading(true);
|
|
241
|
+
try {
|
|
242
|
+
const initialDocs = await domain.getRelations(query);
|
|
243
|
+
docsRef.current = initialDocs;
|
|
244
|
+
setDocs(docsRef.current);
|
|
245
|
+
} catch (err: any) {
|
|
246
|
+
setError(err);
|
|
247
|
+
} finally {
|
|
248
|
+
setLoading(false);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const changeListener = (change: CustomEvent) => {
|
|
252
|
+
const doc = change.detail.doc;
|
|
253
|
+
if (!doc.active) {
|
|
254
|
+
// A doc was deleted
|
|
255
|
+
const docIndex = docsRef.current.findIndex((d) => d._id == doc._id)
|
|
256
|
+
if (docIndex != -1) {
|
|
257
|
+
docsRef.current = [
|
|
258
|
+
...docsRef.current.slice(0, docIndex),
|
|
259
|
+
...docsRef.current.slice(docIndex+1, docsRef.current.length)
|
|
260
|
+
];
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
// A doc was changed or added
|
|
264
|
+
console.log("useDomainRelations - a doc was changed or added", {doc});
|
|
265
|
+
const docIndex = docsRef.current.findIndex((d) => d._id == doc._id)
|
|
266
|
+
if (docIndex != -1) {
|
|
267
|
+
// A doc was changed
|
|
268
|
+
console.log("useDomainRelations - a doc was changed", {doc});
|
|
269
|
+
docsRef.current = [
|
|
270
|
+
...docsRef.current.slice(0, docIndex),
|
|
271
|
+
doc,
|
|
272
|
+
...docsRef.current.slice(docIndex+1, docsRef.current.length)
|
|
273
|
+
];
|
|
274
|
+
} else {
|
|
275
|
+
// A doc was added
|
|
276
|
+
console.log("useDomainRelations - a doc was added", {doc});
|
|
277
|
+
docsRef.current.push(doc);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
setDocs([...docsRef.current])
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
domain.addEventListener('doc', changeListener as EventListener);
|
|
284
|
+
|
|
285
|
+
return () => {
|
|
286
|
+
domain.removeEventListener('doc', changeListener as EventListener);
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
runQueryAndListen();
|
|
291
|
+
}, [domain, JSON.stringify(query)]); // Dependency on classObj and query
|
|
292
|
+
|
|
293
|
+
return { docs, loading, error };
|
|
294
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// src/hooks/useFind.js
|
|
2
|
+
import { useContext, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { DocStackContext } from '../components/StackProvider';
|
|
4
|
+
import { Document, SelectAST, UnionAST } from '@docstack/shared';
|
|
5
|
+
|
|
6
|
+
export const useQuerySQL = (stack: string, sql: string, ...params: any[]) => {
|
|
7
|
+
const docStack = useContext(DocStackContext);
|
|
8
|
+
const [result, setResult] = useState<{ rows: any[]; ast: (SelectAST | UnionAST)[] | null; }>({ rows: [], ast: [] });
|
|
9
|
+
const [loading, setLoading] = useState(true);
|
|
10
|
+
const [error, setError] = useState(null);
|
|
11
|
+
// [TODO] Solve bounce of component because of StrictMode or other reasons
|
|
12
|
+
const queryRef = useRef(false);
|
|
13
|
+
|
|
14
|
+
useEffect( () => {
|
|
15
|
+
if (!docStack) {
|
|
16
|
+
// Handle the case where the provider is not yet initialized or missing
|
|
17
|
+
// You could throw an error or return an empty state.
|
|
18
|
+
console.error('useClassList must be used within a DocStackProvider.');
|
|
19
|
+
setLoading(false);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const runQuery = async () => {
|
|
24
|
+
try {
|
|
25
|
+
const stackInstance = docStack.getStack(stack);
|
|
26
|
+
if (stackInstance) {
|
|
27
|
+
// Run the initial query
|
|
28
|
+
console.log("Preparing to run query", {sql, params})
|
|
29
|
+
// debugger
|
|
30
|
+
const queryResult = await stackInstance.query(sql, ...params);
|
|
31
|
+
setResult(queryResult);
|
|
32
|
+
|
|
33
|
+
} else {
|
|
34
|
+
console.log("Could not find corresponding stack", {stack})
|
|
35
|
+
}
|
|
36
|
+
} catch (err: any) {
|
|
37
|
+
console.log("Got error while running query", {error: err})
|
|
38
|
+
setError(err);
|
|
39
|
+
} finally {
|
|
40
|
+
setLoading(false);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
if (!queryRef.current) {
|
|
45
|
+
queryRef.current = true;
|
|
46
|
+
setLoading(true);
|
|
47
|
+
runQuery();
|
|
48
|
+
} else {
|
|
49
|
+
console.log("Already performing query");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
//
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
}, [docStack, stack, params]);
|
|
58
|
+
|
|
59
|
+
return { loading, result, error };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const useFind = (stack: string, query: {
|
|
63
|
+
selector: { [key: string]: string | number },
|
|
64
|
+
fields?: string[]
|
|
65
|
+
}, sort?: any, limit: number = 50) => {
|
|
66
|
+
const docStack = useContext(DocStackContext);
|
|
67
|
+
const [docs, setDocs] = useState<Document[]>([]);
|
|
68
|
+
const [loading, setLoading] = useState(true);
|
|
69
|
+
const [error, setError] = useState(null);
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
// Check if the docStack instance is available
|
|
73
|
+
if (!docStack) {
|
|
74
|
+
// Handle the case where the provider is not yet initialized or missing
|
|
75
|
+
// You could throw an error or return an empty state.
|
|
76
|
+
console.error('useFind must be used within a DocStackProvider.');
|
|
77
|
+
setLoading(false);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
setLoading(true);
|
|
82
|
+
|
|
83
|
+
const runQuery = async () => {
|
|
84
|
+
try {
|
|
85
|
+
const stackInstance = docStack.getStack(stack);
|
|
86
|
+
if (stackInstance) {
|
|
87
|
+
// Run the initial query
|
|
88
|
+
const initialDocs = await stackInstance.findDocuments(query.selector, query.fields);
|
|
89
|
+
if (initialDocs.docs.length) {
|
|
90
|
+
let docs = initialDocs.docs as Document[]; // [TODO] Check types
|
|
91
|
+
setDocs(docs);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
} catch (err: any) {
|
|
96
|
+
setError(err);
|
|
97
|
+
} finally {
|
|
98
|
+
setLoading(false);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
runQuery();
|
|
103
|
+
|
|
104
|
+
// Set up the listener for changes
|
|
105
|
+
const changeListener = (change: any) => {
|
|
106
|
+
// Logic to handle the change and update the docs state
|
|
107
|
+
// This part is crucial for real-time updates.
|
|
108
|
+
// You'll need to re-run the query or intelligently update the docs array
|
|
109
|
+
// based on the change object (add, update, delete).
|
|
110
|
+
// A simple way is to re-run the query.
|
|
111
|
+
// runQuery();
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// [TODO] Implement events
|
|
115
|
+
docStack.addEventListener('change', changeListener);
|
|
116
|
+
|
|
117
|
+
// Cleanup function: remove the listener when the component unmounts
|
|
118
|
+
return () => {
|
|
119
|
+
docStack.removeEventListener('change', changeListener);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
}, [docStack, JSON.stringify(query)]); // Re-run if docStack or query changes
|
|
123
|
+
|
|
124
|
+
return { docs, loading, error };
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const useClassCreate = () => {
|
|
128
|
+
|
|
129
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import StackProvider, {DocStackContext, useDocStack} from "./components/StackProvider";
|
|
2
|
+
import { useFind, useQuerySQL } from "./hooks/";
|
|
3
|
+
import { useClass, useClassList, useClassDocs, useClassCreate } from "./hooks/class";
|
|
4
|
+
import { useDomainList, useDomain, useDomainRelations, useDomainCreate } from "./hooks/domain";
|
|
5
|
+
|
|
6
|
+
export { StackProvider, DocStackContext, useDocStack };
|
|
7
|
+
export { useFind, useQuerySQL };
|
|
8
|
+
|
|
9
|
+
export { useClassList, useClass, useClassDocs, useClassCreate };
|
|
10
|
+
export { useDomainList, useDomain, useDomainRelations, useDomainCreate };
|