@based/react 0.6.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +32 -0
- package/dist/bundle.js +1 -0
- package/dist/clients.d.ts +30 -0
- package/dist/clients.js +139 -0
- package/dist/clients.js.map +1 -0
- package/dist/genOptsId.d.ts +4 -0
- package/dist/genOptsId.js +14 -0
- package/dist/genOptsId.js.map +1 -0
- package/dist/gql.d.ts +9 -0
- package/dist/gql.js +158 -0
- package/dist/gql.js.map +1 -0
- package/dist/index.d.ts +5 -39
- package/dist/index.js +25 -229
- package/dist/index.js.map +1 -1
- package/dist/meta.d.ts +8 -0
- package/dist/meta.js +70 -0
- package/dist/meta.js.map +1 -0
- package/dist/reducer.d.ts +18 -0
- package/dist/reducer.js +35 -0
- package/dist/reducer.js.map +1 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +9 -5
- package/src/clients.ts +160 -0
- package/src/genOptsId.ts +13 -0
- package/src/gql.ts +210 -0
- package/src/index.ts +12 -266
- package/src/meta.ts +74 -0
- package/src/reducer.ts +42 -0
- package/src/types.ts +5 -0
- package/tsconfig.tsbuildinfo +0 -1
package/build/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const { build } = require('esbuild')
|
|
2
|
+
const { join } = require('path')
|
|
3
|
+
|
|
4
|
+
const b = async () => {
|
|
5
|
+
// make a seperate build for stream for both node and the index
|
|
6
|
+
|
|
7
|
+
const makeAllPackagesExternalPlugin = {
|
|
8
|
+
name: 'make-all-packages-external',
|
|
9
|
+
setup(build) {
|
|
10
|
+
// eslint-disable-next-line
|
|
11
|
+
const filter = /(\.\/stream)|(^[^.\/]|^\.[^.\/]|^\.\.[^\/])/ // Must not start with "/" or "./" or "../"
|
|
12
|
+
build.onResolve({ filter }, (args) => {
|
|
13
|
+
return {
|
|
14
|
+
path: args.path,
|
|
15
|
+
external: true,
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
build({
|
|
22
|
+
outfile: join(__dirname, '../dist/bundle.js'),
|
|
23
|
+
bundle: true,
|
|
24
|
+
minify: true,
|
|
25
|
+
target: 'es2017',
|
|
26
|
+
platform: 'node',
|
|
27
|
+
entryPoints: [join(__dirname, '../src/index.ts')],
|
|
28
|
+
plugins: [makeAllPackagesExternalPlugin],
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
b()
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var te=Object.create;var S=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols,se=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable;var K=(e,r,t)=>r in e?S(e,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[r]=t,W=(e,r)=>{for(var t in r||(r={}))V.call(r,t)&&K(e,t,r[t]);if(H)for(var t of H(r))ie.call(r,t)&&K(e,t,r[t]);return e};var ae=(e,r)=>{for(var t in r)S(e,t,{get:r[t],enumerable:!0})},J=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of oe(r))!V.call(e,n)&&n!==t&&S(e,n,{get:()=>r[n],enumerable:!(i=ne(r,n))||i.enumerable});return e};var X=(e,r,t)=>(t=e!=null?te(se(e)):{},J(r||!e||!e.__esModule?S(t,"default",{value:e,enumerable:!0}):t,e)),ue=e=>J(S({},"__esModule",{value:!0}),e);var ke={};ae(ke,{BasedContext:()=>Q,Provider:()=>le,defaultCreateClient:()=>Y,updateMeta:()=>g,useAuth:()=>pe,useBasedContext:()=>Z,useClient:()=>C,useClients:()=>fe,useData:()=>re,useError:()=>ge,useLoading:()=>de,useQuery:()=>me,useSchema:()=>be,useTrack:()=>he});module.exports=ue(ke);var f=require("react"),O=require("@based/client");function j(e,r){return r.error&&(e.error=r.error),r.data&&(e.checksum=r.checksum||0,e.data=r.data,e.loading=!1,e.error&&delete e.error),r.merge&&(e.checksum=r.checksum||0,e.data?Object.assign(e.data,r.merge):e.data=r.merge,e.loading=!1,e.error&&delete e.error),r.loading&&(e.loading=r.loading),W({},e)}var B=e=>{if(!!e)return e.key?e.key:`${e.env}_${e.project}_${e.org}_${e.cluster||""}_${e.name||""}`};var k=X(require("react")),w=X(require("@based/client"));var $=new Set,Q=(0,k.createContext)({clients:{},removeClient:(...e)=>{}}),Y=e=>{if(typeof e=="object")return process.env.CLUSTER&&process.env.CLUSTER.startsWith("local")&&!e.cluster&&(e.cluster=process.env.CLUSTER),(0,w.default)(e);console.error("Cannot create client from "+e)},le=({client:e,children:r,clients:t,createClient:i})=>(!t&&e?t={default:e}:t&&e&&(t.default=e),k.default.createElement(Q.Provider,{value:{clients:t,createClient:i||Y,removeClient:o=>{if(o instanceof w.Based){for(let h in t)if(t[h]===o){o=h;break}if(typeof o!="string"){console.error("Cannot find client to remove from ctx",o);return}}else typeof o!="string"&&(o=B(o));t[o]&&(t[o].disconnect(),delete t[o],$.forEach(h=>h()))}}},r)),Z=()=>(0,k.useContext)(Q);function ce(e){return e+1}var fe=()=>{let e=Z(),[,r]=(0,k.useReducer)(ce,0);return(0,k.useEffect)(()=>{let t,i=()=>{t=setTimeout(r,0)};return $.add(i),()=>{$.delete(i),clearTimeout(t)}},[]),Object.values(e.clients)},C=(e="default")=>{let r=(0,k.useContext)(Q);if(typeof e=="object"&&!(e.env&&e.project&&e.org))return;let t;typeof e=="string"?t=e:t=e.key||B(e);let i=r.clients[t];return!i&&r.createClient&&(i=r.createClient(e),i&&(r.clients[t]=i,$.forEach(n=>n()))),i};var v=require("react"),E={},P=new Set,N=new Set,q=new Set,D=!1,F="",I=0,_=I+F;function g(e,r,t){t?(F=t,e in E?E[e]=t:(E[e]=t,I++)):e in E&&(I--,delete E[e]);let i=I+F;i!==_&&(_=i,P.forEach(o=>o(_))),r?N.add(e):N.delete(e);let n=!!N.size;n!==D&&(D=n,q.forEach(o=>o(D)))}function de(){let[,e]=(0,v.useState)(D);return q.add(e),(0,v.useEffect)(()=>()=>{q.delete(e)},[]),{loading:D}}function ge(){let[,e]=(0,v.useState)(_);return P.add(e),(0,v.useEffect)(()=>()=>{P.delete(e)},[]),{error:I?F:null,errors:Object.values(E)}}var s=require("react"),b=require("@based/client");var M=require("@saulx/hash"),ee=(0,b.generateSubscriptionId)({$subscribe_schema:"default"});function me(e,r={},t){let[i,n]=(0,s.useReducer)(j,{loading:!0,data:{},checksum:0}),o=(0,s.useRef)({checksum:0,fns:{}}),h=t||"default",c=C(h);if(e){let[x,R]=(0,s.useState)(0);if((0,s.useEffect)(()=>{let[,u]=(0,b.addSubscriber)(c.client,{$subscribe_schema:"default"},(d,l)=>{c.client.configuration||(c.client.configuration={dbs:[],schema:{},functions:{}}),c.client.configuration.schema.default=d,R(l)},d=>{d&&console.error(d)},d=>{console.error(d)},ee);return()=>{(0,b.removeSubscriber)(c.client,ee,u)}},[]),x){let u;typeof e=="string"?u=c.gql(e):u=e,u=(0,b.handleGraphqlVariables)(u,u,r);let d={},l={};for(let m in u.ops){if(u.ops[m].fnObserve){let{name:L,payload:a}=u.ops[m].fnObserve;d[m]={name:L,payload:a,key:m};continue}l[m]=u.ops[m].get}let U=(0,s.useMemo)(()=>(0,M.hashObjectIgnoreKeyOrder)(d),[d]),T=(0,s.useMemo)(()=>(0,b.generateSubscriptionId)(l),[l]),z=typeof h=="string"?h:B(h);if(c){let m=z+T;(0,s.useEffect)(()=>{let L=[];for(let a in d)L.push((0,b.addSubscriber)(c.client,d[a].payload,(p,A)=>{g(m,!1,!1),o.current.fns[a]!==A&&(o.current.fns[a]=A,n({merge:{[a]:p},checksum:(0,M.hashObjectIgnoreKeyOrder)(o.current)}))},p=>{p&&(console.error(p),n({error:p,loading:!1}))},p=>{console.error(p),g(m,!1,p),n({error:p})},void 0,d[a].name));return()=>{for(let[a,p]of L)(0,b.removeSubscriber)(c.client,a,p)}},[U]),(0,s.useEffect)(()=>{if(!x)return;g(m,!0,!1);let[,L]=(0,b.addSubscriber)(c.client,l,(a,p)=>{g(m,!1,!1),o.current.checksum!==p&&(o.current.checksum=p,n({merge:a,checksum:(0,M.hashObjectIgnoreKeyOrder)(o.current)}))},a=>{a&&(console.error(a),g(m,!1,a),n({error:a,loading:!1}))},a=>{console.error(a),g(m,!1,a),n({error:a})},T);return()=>{g(m,!1,!1),(0,b.removeSubscriber)(c.client,T,L)}},[T,z,x])}else(0,s.useEffect)(y,[null,null])}else(0,s.useMemo)(y,[null]),(0,s.useMemo)(y,[null]),(0,s.useEffect)(y,[null]),(0,s.useEffect)(y,[null,null,null])}else(0,s.useState)(null),(0,s.useEffect)(y,[null]),(0,s.useMemo)(y,[null]),(0,s.useMemo)(y,[null]),(0,s.useEffect)(y,[null]),(0,s.useEffect)(y,[null,null,null]);return i}function y(){}function pe(e){let r=C(e),[t,i]=(0,f.useState)(!1);return(0,f.useEffect)(()=>{let n=()=>i(r.getToken());return r.on("auth",n),()=>{r.removeListener("auth",n)}},[]),t}function be(e="default",r){let t=re(e?{$subscribe_schema:e}:null,r);return{loading:t.loading,error:t.error,schema:t.data}}function he(e,r,t){if(e){let n=C(t||"default"),o=(0,f.useMemo)(()=>(0,O.generateSubscriptionId)(r,e),[e,r]);(0,f.useEffect)(()=>(n.track(e,r),()=>{n.untrack(e,r)}),[o])}else C(t),(0,f.useMemo)(()=>{},[]),(0,f.useEffect)(G,[null,null])}function re(e,r,t){let[i,n]=(0,f.useReducer)(j,{loading:!0,data:{},checksum:0});if(e){let o=(0,f.useMemo)(()=>(0,O.generateSubscriptionId)(typeof e=="string"?[e,r]:e),[r,e]),h=typeof e=="string",c=t||(h?"default":r),x=C(c),R=typeof c=="string"?c:B(c);if(x){let u=R+o;(0,f.useEffect)(()=>{g(u,!0,!1),n({error:null,loading:!0,data:{}});let[,d]=(0,O.addSubscriber)(x.client,h?r:e,(l,U)=>{g(u,!1,!1),n({data:l,checksum:U})},l=>{l&&(console.error(l),g(u,!1,l),n({error:l,loading:!1}))},l=>{console.error(l),g(u,!1,l),n({error:l})},o,typeof e=="string"?e:void 0);return()=>{g(u,!1,!1),(0,O.removeSubscriber)(x.client,o,d)}},[o,R])}else(0,f.useEffect)(G,[null,null])}else(0,f.useMemo)(G,[r,e]),C(t),(0,f.useEffect)(G,[null,null]);return i}function G(){}0&&(module.exports={BasedContext,Provider,defaultCreateClient,updateMeta,useAuth,useBasedContext,useClient,useClients,useData,useError,useLoading,useQuery,useSchema,useTrack});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { FunctionComponent, ReactNode } from 'react';
|
|
2
|
+
import { Based, BasedOpts } from '@based/client';
|
|
3
|
+
export declare type CreateClient = (selector: string | (BasedOpts & {
|
|
4
|
+
key?: string;
|
|
5
|
+
})) => Based;
|
|
6
|
+
interface BasedContextType {
|
|
7
|
+
clients: {
|
|
8
|
+
[key: string]: Based;
|
|
9
|
+
};
|
|
10
|
+
createClient?: CreateClient;
|
|
11
|
+
removeClient: (selector: string | (BasedOpts & {
|
|
12
|
+
key?: string;
|
|
13
|
+
}) | Based) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const BasedContext: React.Context<BasedContextType>;
|
|
16
|
+
export declare const defaultCreateClient: CreateClient;
|
|
17
|
+
export declare const Provider: FunctionComponent<{
|
|
18
|
+
client?: Based;
|
|
19
|
+
clients?: {
|
|
20
|
+
[key: string]: Based;
|
|
21
|
+
};
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
createClient?: CreateClient;
|
|
24
|
+
}>;
|
|
25
|
+
export declare const useBasedContext: () => BasedContextType;
|
|
26
|
+
export declare const useClients: () => Based[];
|
|
27
|
+
export declare const useClient: (selector?: string | (BasedOpts & {
|
|
28
|
+
key?: string;
|
|
29
|
+
})) => Based;
|
|
30
|
+
export {};
|
package/dist/clients.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.useClient = exports.useClients = exports.useBasedContext = exports.Provider = exports.defaultCreateClient = exports.BasedContext = void 0;
|
|
23
|
+
const react_1 = __importStar(require("react"));
|
|
24
|
+
const client_1 = __importStar(require("@based/client"));
|
|
25
|
+
const genOptsId_1 = require("./genOptsId");
|
|
26
|
+
const newClientListeners = new Set();
|
|
27
|
+
exports.BasedContext = (0, react_1.createContext)({
|
|
28
|
+
clients: {},
|
|
29
|
+
// eslint-disable-next-line
|
|
30
|
+
removeClient: (...args) => { },
|
|
31
|
+
});
|
|
32
|
+
const defaultCreateClient = (selector) => {
|
|
33
|
+
if (typeof selector === 'object') {
|
|
34
|
+
if (process.env.CLUSTER &&
|
|
35
|
+
process.env.CLUSTER.startsWith('local') &&
|
|
36
|
+
!selector.cluster) {
|
|
37
|
+
selector.cluster = process.env.CLUSTER;
|
|
38
|
+
}
|
|
39
|
+
return (0, client_1.default)(selector);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// default
|
|
43
|
+
console.error('Cannot create client from ' + selector);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.defaultCreateClient = defaultCreateClient;
|
|
47
|
+
const Provider = ({ client, children, clients, createClient }) => {
|
|
48
|
+
if (!clients && client) {
|
|
49
|
+
clients = {
|
|
50
|
+
default: client,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
else if (clients && client) {
|
|
54
|
+
clients.default = client;
|
|
55
|
+
}
|
|
56
|
+
const ctx = react_1.default.createElement(exports.BasedContext.Provider, {
|
|
57
|
+
value: {
|
|
58
|
+
clients,
|
|
59
|
+
createClient: createClient || exports.defaultCreateClient,
|
|
60
|
+
removeClient: (selector) => {
|
|
61
|
+
if (selector instanceof client_1.Based) {
|
|
62
|
+
for (const cl in clients) {
|
|
63
|
+
if (clients[cl] === selector) {
|
|
64
|
+
selector = cl;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (typeof selector !== 'string') {
|
|
69
|
+
console.error('Cannot find client to remove from ctx', selector);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (typeof selector !== 'string') {
|
|
74
|
+
selector = (0, genOptsId_1.genOptsId)(selector);
|
|
75
|
+
}
|
|
76
|
+
// @ts-ignore
|
|
77
|
+
if (clients[selector]) {
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
clients[selector].disconnect();
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
delete clients[selector];
|
|
82
|
+
newClientListeners.forEach((fn) => fn());
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
}, children);
|
|
87
|
+
return ctx;
|
|
88
|
+
};
|
|
89
|
+
exports.Provider = Provider;
|
|
90
|
+
const useBasedContext = () => {
|
|
91
|
+
return (0, react_1.useContext)(exports.BasedContext);
|
|
92
|
+
};
|
|
93
|
+
exports.useBasedContext = useBasedContext;
|
|
94
|
+
function forceUpdate(state) {
|
|
95
|
+
return state + 1;
|
|
96
|
+
}
|
|
97
|
+
const useClients = () => {
|
|
98
|
+
const ctx = (0, exports.useBasedContext)();
|
|
99
|
+
const [, update] = (0, react_1.useReducer)(forceUpdate, 0);
|
|
100
|
+
(0, react_1.useEffect)(() => {
|
|
101
|
+
let timer;
|
|
102
|
+
const fn = () => {
|
|
103
|
+
timer = setTimeout(update, 0);
|
|
104
|
+
};
|
|
105
|
+
newClientListeners.add(fn);
|
|
106
|
+
return () => {
|
|
107
|
+
newClientListeners.delete(fn);
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
};
|
|
110
|
+
}, []);
|
|
111
|
+
return Object.values(ctx.clients);
|
|
112
|
+
};
|
|
113
|
+
exports.useClients = useClients;
|
|
114
|
+
const useClient = (selector = 'default') => {
|
|
115
|
+
const basedCtx = (0, react_1.useContext)(exports.BasedContext);
|
|
116
|
+
if (typeof selector === 'object') {
|
|
117
|
+
if (!(selector.env && selector.project && selector.org)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
let key;
|
|
122
|
+
if (typeof selector === 'string') {
|
|
123
|
+
key = selector;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
key = selector.key || (0, genOptsId_1.genOptsId)(selector);
|
|
127
|
+
}
|
|
128
|
+
let client = basedCtx.clients[key];
|
|
129
|
+
if (!client && basedCtx.createClient) {
|
|
130
|
+
client = basedCtx.createClient(selector);
|
|
131
|
+
if (client) {
|
|
132
|
+
basedCtx.clients[key] = client;
|
|
133
|
+
newClientListeners.forEach((fn) => fn());
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return client;
|
|
137
|
+
};
|
|
138
|
+
exports.useClient = useClient;
|
|
139
|
+
//# sourceMappingURL=clients.js.map
|
|
@@ -0,0 +1 @@
|
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,CAAC,QAAQ,CAAC,CAAA;QAExC,IAAI,MAAM,EAAE;YACV,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;YAC9B,kBAAkB,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA;SACzC;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AA/BY,QAAA,SAAS,aA+BrB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genOptsId = void 0;
|
|
4
|
+
const genOptsId = (opts) => {
|
|
5
|
+
if (!opts) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (opts.key) {
|
|
9
|
+
return opts.key;
|
|
10
|
+
}
|
|
11
|
+
return `${opts.env}_${opts.project}_${opts.org}_${opts.cluster || ''}_${opts.name || ''}`;
|
|
12
|
+
};
|
|
13
|
+
exports.genOptsId = genOptsId;
|
|
14
|
+
//# sourceMappingURL=genOptsId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genOptsId.js","sourceRoot":"","sources":["../src/genOptsId.ts"],"names":[],"mappings":";;;AAEO,MAAM,SAAS,GAAG,CAAC,IAAkC,EAAU,EAAE;IACtE,IAAI,CAAC,IAAI,EAAE;QACT,OAAM;KACP;IACD,IAAI,IAAI,CAAC,GAAG,EAAE;QACZ,OAAO,IAAI,CAAC,GAAG,CAAA;KAChB;IACD,OAAO,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,IAAI,EAAE,IAClE,IAAI,CAAC,IAAI,IAAI,EACf,EAAE,CAAA;AACJ,CAAC,CAAA;AAVY,QAAA,SAAS,aAUrB"}
|
package/dist/gql.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BasedGraphQL, BasedOpts } from '@based/client';
|
|
2
|
+
import { Loading, Data } from './types';
|
|
3
|
+
export declare function useQuery(query?: string | BasedGraphQL, variables?: Record<string, any>, clientSelector?: string | (BasedOpts & {
|
|
4
|
+
key?: string;
|
|
5
|
+
})): {
|
|
6
|
+
data: Data;
|
|
7
|
+
error?: Error;
|
|
8
|
+
loading: Loading;
|
|
9
|
+
};
|
package/dist/gql.js
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useQuery = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const client_1 = require("@based/client");
|
|
6
|
+
const reducer_1 = require("./reducer");
|
|
7
|
+
const clients_1 = require("./clients");
|
|
8
|
+
const genOptsId_1 = require("./genOptsId");
|
|
9
|
+
const meta_1 = require("./meta");
|
|
10
|
+
const hash_1 = require("@saulx/hash");
|
|
11
|
+
const schemaSubId = (0, client_1.generateSubscriptionId)({ $subscribe_schema: 'default' });
|
|
12
|
+
// step one make 1 useEffect
|
|
13
|
+
// - and the nessecary if
|
|
14
|
+
function useQuery(query, variables = {}, clientSelector) {
|
|
15
|
+
const [result, dispatch] = (0, react_1.useReducer)(reducer_1.resultReducer, {
|
|
16
|
+
loading: true,
|
|
17
|
+
data: {},
|
|
18
|
+
checksum: 0,
|
|
19
|
+
});
|
|
20
|
+
const r = (0, react_1.useRef)({ checksum: 0, fns: {} });
|
|
21
|
+
const selector = clientSelector || 'default';
|
|
22
|
+
const client = (0, clients_1.useClient)(selector);
|
|
23
|
+
if (query) {
|
|
24
|
+
const [configState, updateConfigState] = (0, react_1.useState)(0);
|
|
25
|
+
(0, react_1.useEffect)(() => {
|
|
26
|
+
const [, subscriberId] = (0, client_1.addSubscriber)(client.client,
|
|
27
|
+
// FIXME dont want too many updates plz this has to become 1 use effect
|
|
28
|
+
{ $subscribe_schema: 'default' }, (d, checksum) => {
|
|
29
|
+
if (!client.client.configuration) {
|
|
30
|
+
client.client.configuration = { dbs: [], schema: {}, functions: {} };
|
|
31
|
+
}
|
|
32
|
+
client.client.configuration.schema.default = d;
|
|
33
|
+
updateConfigState(checksum);
|
|
34
|
+
}, (err) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
console.error(err);
|
|
37
|
+
}
|
|
38
|
+
}, (err) => {
|
|
39
|
+
console.error(err);
|
|
40
|
+
}, schemaSubId);
|
|
41
|
+
return () => {
|
|
42
|
+
(0, client_1.removeSubscriber)(client.client, schemaSubId, subscriberId);
|
|
43
|
+
};
|
|
44
|
+
return () => { };
|
|
45
|
+
}, []);
|
|
46
|
+
if (configState) {
|
|
47
|
+
let op;
|
|
48
|
+
if (typeof query === 'string') {
|
|
49
|
+
op = client.gql(query);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
op = query;
|
|
53
|
+
}
|
|
54
|
+
op = (0, client_1.handleGraphqlVariables)(op, op, variables);
|
|
55
|
+
const fns = {};
|
|
56
|
+
const queryObj = {};
|
|
57
|
+
for (const key in op.ops) {
|
|
58
|
+
if (op.ops[key].fnObserve) {
|
|
59
|
+
const { name, payload } = op.ops[key].fnObserve;
|
|
60
|
+
fns[key] = { name: name, payload, key };
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
queryObj[key] = op.ops[key].get;
|
|
64
|
+
}
|
|
65
|
+
const fnHash = (0, react_1.useMemo)(() => {
|
|
66
|
+
return (0, hash_1.hashObjectIgnoreKeyOrder)(fns);
|
|
67
|
+
}, [fns]);
|
|
68
|
+
const subId = (0, react_1.useMemo)(() => {
|
|
69
|
+
// fn?
|
|
70
|
+
return (0, client_1.generateSubscriptionId)(queryObj);
|
|
71
|
+
}, [queryObj]);
|
|
72
|
+
const clientKey = typeof selector === 'string' ? selector : (0, genOptsId_1.genOptsId)(selector);
|
|
73
|
+
if (client) {
|
|
74
|
+
const subKey = clientKey + subId;
|
|
75
|
+
(0, react_1.useEffect)(() => {
|
|
76
|
+
const subs = [];
|
|
77
|
+
for (const key in fns) {
|
|
78
|
+
subs.push((0, client_1.addSubscriber)(client.client, fns[key].payload, (d, checksum) => {
|
|
79
|
+
(0, meta_1.updateMeta)(subKey, false, false);
|
|
80
|
+
if (r.current.fns[key] !== checksum) {
|
|
81
|
+
r.current.fns[key] = checksum;
|
|
82
|
+
dispatch({
|
|
83
|
+
merge: { [key]: d },
|
|
84
|
+
checksum: (0, hash_1.hashObjectIgnoreKeyOrder)(r.current),
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}, (err) => {
|
|
88
|
+
if (err) {
|
|
89
|
+
console.error(err);
|
|
90
|
+
dispatch({ error: err, loading: false });
|
|
91
|
+
}
|
|
92
|
+
}, (err) => {
|
|
93
|
+
console.error(err);
|
|
94
|
+
(0, meta_1.updateMeta)(subKey, false, err);
|
|
95
|
+
dispatch({ error: err });
|
|
96
|
+
}, undefined, fns[key].name));
|
|
97
|
+
}
|
|
98
|
+
return () => {
|
|
99
|
+
for (const [subId, subscriberId] of subs) {
|
|
100
|
+
(0, client_1.removeSubscriber)(client.client, subId, subscriberId);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}, [fnHash]);
|
|
104
|
+
(0, react_1.useEffect)(() => {
|
|
105
|
+
if (!configState) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
(0, meta_1.updateMeta)(subKey, true, false);
|
|
109
|
+
const [, subscriberId] = (0, client_1.addSubscriber)(client.client, queryObj, (d, checksum) => {
|
|
110
|
+
(0, meta_1.updateMeta)(subKey, false, false);
|
|
111
|
+
if (r.current.checksum !== checksum) {
|
|
112
|
+
r.current.checksum = checksum;
|
|
113
|
+
dispatch({
|
|
114
|
+
merge: d,
|
|
115
|
+
checksum: (0, hash_1.hashObjectIgnoreKeyOrder)(r.current),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}, (err) => {
|
|
119
|
+
if (err) {
|
|
120
|
+
console.error(err);
|
|
121
|
+
(0, meta_1.updateMeta)(subKey, false, err);
|
|
122
|
+
dispatch({ error: err, loading: false });
|
|
123
|
+
}
|
|
124
|
+
}, (err) => {
|
|
125
|
+
console.error(err);
|
|
126
|
+
(0, meta_1.updateMeta)(subKey, false, err);
|
|
127
|
+
dispatch({ error: err });
|
|
128
|
+
}, subId);
|
|
129
|
+
return () => {
|
|
130
|
+
(0, meta_1.updateMeta)(subKey, false, false);
|
|
131
|
+
(0, client_1.removeSubscriber)(client.client, subId, subscriberId);
|
|
132
|
+
};
|
|
133
|
+
}, [subId, clientKey, configState]);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
(0, react_1.useEffect)(stubFn, [null, null]);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
(0, react_1.useMemo)(stubFn, [null]);
|
|
141
|
+
(0, react_1.useMemo)(stubFn, [null]);
|
|
142
|
+
(0, react_1.useEffect)(stubFn, [null]);
|
|
143
|
+
(0, react_1.useEffect)(stubFn, [null, null, null]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
(0, react_1.useState)(null);
|
|
148
|
+
(0, react_1.useEffect)(stubFn, [null]);
|
|
149
|
+
(0, react_1.useMemo)(stubFn, [null]);
|
|
150
|
+
(0, react_1.useMemo)(stubFn, [null]);
|
|
151
|
+
(0, react_1.useEffect)(stubFn, [null]);
|
|
152
|
+
(0, react_1.useEffect)(stubFn, [null, null, null]);
|
|
153
|
+
}
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
exports.useQuery = useQuery;
|
|
157
|
+
function stubFn() { }
|
|
158
|
+
//# sourceMappingURL=gql.js.map
|
package/dist/gql.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gql.js","sourceRoot":"","sources":["../src/gql.ts"],"names":[],"mappings":";;;AAAA,iCAAwE;AACxE,0CAOsB;AAEtB,uCAAyC;AACzC,uCAAqC;AACrC,2CA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CAAC,CAAA;YACzB,IAAA,iBAAS,EAAC,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;SACtC;KACF;SAAM;QACL,IAAA,gBAAQ,EAAC,IAAI,CAAC,CAAA;QACd,IAAA,iBAAS,EAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QACzB,IAAA,eAAO,EAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QACvB,IAAA,eAAO,EAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QACvB,IAAA,iBAAS,EAAC,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;QACzB,IAAA,iBAAS,EAAC,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;KACtC;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AA1LD,4BA0LC;AAED,SAAS,MAAM,KAAI,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,34 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
interface BasedContextType {
|
|
7
|
-
clients: {
|
|
8
|
-
[key: string]: Based;
|
|
9
|
-
};
|
|
10
|
-
createClient?: CreateClient;
|
|
11
|
-
removeClient: (selector: string | (BasedOpts & {
|
|
12
|
-
key?: string;
|
|
13
|
-
}) | Based) => void;
|
|
14
|
-
}
|
|
15
|
-
export declare const BasedContext: React.Context<BasedContextType>;
|
|
16
|
-
export declare const defaultCreateClient: CreateClient;
|
|
17
|
-
export declare const Provider: FunctionComponent<{
|
|
18
|
-
client?: Based;
|
|
19
|
-
clients?: {
|
|
20
|
-
[key: string]: Based;
|
|
21
|
-
};
|
|
22
|
-
children: ReactNode;
|
|
23
|
-
createClient?: CreateClient;
|
|
24
|
-
}>;
|
|
25
|
-
export declare const useBasedContext: () => BasedContextType;
|
|
26
|
-
export declare const useClients: () => Based[];
|
|
27
|
-
export declare const useClient: (selector?: string | (BasedOpts & {
|
|
28
|
-
key?: string;
|
|
29
|
-
})) => Based;
|
|
30
|
-
declare type Data = GenericObject;
|
|
31
|
-
declare type Loading = boolean;
|
|
1
|
+
import { Query, BasedOpts } from '@based/client';
|
|
2
|
+
import { Loading, Data } from './types';
|
|
3
|
+
export * from './meta';
|
|
4
|
+
export * from './clients';
|
|
5
|
+
export * from './gql';
|
|
32
6
|
export declare function useAuth(clientSelector?: string | (BasedOpts & {
|
|
33
7
|
key?: string;
|
|
34
8
|
})): string | false;
|
|
@@ -66,11 +40,3 @@ export declare function useData(name: string, payload: any, clientSelector?: str
|
|
|
66
40
|
loading: Loading;
|
|
67
41
|
checksum: number;
|
|
68
42
|
};
|
|
69
|
-
export declare function useLoading(): {
|
|
70
|
-
loading: boolean;
|
|
71
|
-
};
|
|
72
|
-
export declare function useError(): {
|
|
73
|
-
error: string;
|
|
74
|
-
errors: unknown[];
|
|
75
|
-
};
|
|
76
|
-
export {};
|