on-zero 0.4.35 → 0.4.37
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/dist/cjs/combineZeroClients.native.js.map +1 -1
- package/dist/cjs/createUseQuery.cjs +1 -96
- package/dist/cjs/createUseQuery.native.js +1 -132
- package/dist/cjs/createUseQuery.native.js.map +1 -1
- package/dist/cjs/createUseQueryDirect.cjs +228 -0
- package/dist/cjs/createUseQueryDirect.native.js +334 -0
- package/dist/cjs/createUseQueryDirect.native.js.map +1 -0
- package/dist/cjs/createZeroClient.cjs +18 -7
- package/dist/cjs/createZeroClient.native.js +18 -7
- package/dist/cjs/createZeroClient.native.js.map +1 -1
- package/dist/cjs/helpers/recoverZeroClient.test.native.js.map +1 -1
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.native.js +2 -2
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/multi.cjs +38 -0
- package/dist/cjs/multi.native.js +41 -0
- package/dist/cjs/multi.native.js.map +1 -0
- package/dist/cjs/multiInstance.test.cjs +75 -0
- package/dist/cjs/multiInstance.test.native.js +111 -0
- package/dist/cjs/multiInstance.test.native.js.map +1 -1
- package/dist/cjs/multiInstanceNested.test.cjs +92 -12
- package/dist/cjs/multiInstanceNested.test.native.js +108 -12
- package/dist/cjs/multiInstanceNested.test.native.js.map +1 -1
- package/dist/cjs/run.cjs +6 -1
- package/dist/cjs/run.native.js +6 -1
- package/dist/cjs/run.native.js.map +1 -1
- package/dist/cjs/testSetup.cjs +26 -0
- package/dist/cjs/testSetup.native.js +32 -0
- package/dist/cjs/testSetup.native.js.map +1 -0
- package/dist/cjs/zeroRunner.cjs +4 -0
- package/dist/cjs/zeroRunner.native.js +4 -0
- package/dist/cjs/zeroRunner.native.js.map +1 -1
- package/dist/esm/combineZeroClients.mjs.map +1 -1
- package/dist/esm/combineZeroClients.native.js.map +1 -1
- package/dist/esm/createUseQuery.mjs +2 -97
- package/dist/esm/createUseQuery.mjs.map +1 -1
- package/dist/esm/createUseQuery.native.js +2 -133
- package/dist/esm/createUseQuery.native.js.map +1 -1
- package/dist/esm/createUseQueryDirect.mjs +203 -0
- package/dist/esm/createUseQueryDirect.mjs.map +1 -0
- package/dist/esm/createUseQueryDirect.native.js +306 -0
- package/dist/esm/createUseQueryDirect.native.js.map +1 -0
- package/dist/esm/createZeroClient.mjs +18 -8
- package/dist/esm/createZeroClient.mjs.map +1 -1
- package/dist/esm/createZeroClient.native.js +18 -8
- package/dist/esm/createZeroClient.native.js.map +1 -1
- package/dist/esm/helpers/recoverZeroClient.test.mjs.map +1 -1
- package/dist/esm/helpers/recoverZeroClient.test.native.js.map +1 -1
- package/dist/esm/index.js +2 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -3
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -3
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/multi.mjs +12 -0
- package/dist/esm/multi.mjs.map +1 -0
- package/dist/esm/multi.native.js +12 -0
- package/dist/esm/multi.native.js.map +1 -0
- package/dist/esm/multiInstance.test.mjs +75 -0
- package/dist/esm/multiInstance.test.mjs.map +1 -1
- package/dist/esm/multiInstance.test.native.js +111 -0
- package/dist/esm/multiInstance.test.native.js.map +1 -1
- package/dist/esm/multiInstanceNested.test.mjs +85 -5
- package/dist/esm/multiInstanceNested.test.mjs.map +1 -1
- package/dist/esm/multiInstanceNested.test.native.js +101 -5
- package/dist/esm/multiInstanceNested.test.native.js.map +1 -1
- package/dist/esm/run.mjs +7 -2
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/run.native.js +7 -2
- package/dist/esm/run.native.js.map +1 -1
- package/dist/esm/testSetup.mjs +27 -0
- package/dist/esm/testSetup.mjs.map +1 -0
- package/dist/esm/testSetup.native.js +30 -0
- package/dist/esm/testSetup.native.js.map +1 -0
- package/dist/esm/zeroRunner.mjs +4 -1
- package/dist/esm/zeroRunner.mjs.map +1 -1
- package/dist/esm/zeroRunner.native.js +4 -1
- package/dist/esm/zeroRunner.native.js.map +1 -1
- package/package.json +8 -2
- package/readme.md +10 -8
- package/src/combineZeroClients.tsx +4 -6
- package/src/createUseQuery.tsx +2 -189
- package/src/createUseQueryDirect.tsx +307 -0
- package/src/createZeroClient.tsx +65 -32
- package/src/helpers/recoverZeroClient.test.ts +8 -2
- package/src/index.ts +6 -2
- package/src/multi.ts +24 -0
- package/src/multiInstance.test.tsx +69 -0
- package/src/multiInstanceNested.test.tsx +79 -4
- package/src/run.ts +10 -2
- package/src/testSetup.ts +26 -0
- package/src/zeroRunner.ts +4 -0
- package/types/combineZeroClients.d.ts.map +1 -1
- package/types/createUseQuery.d.ts +4 -15
- package/types/createUseQuery.d.ts.map +1 -1
- package/types/createUseQueryDirect.d.ts +29 -0
- package/types/createUseQueryDirect.d.ts.map +1 -0
- package/types/createZeroClient.d.ts +51 -5
- package/types/createZeroClient.d.ts.map +1 -1
- package/types/index.d.ts +1 -2
- package/types/index.d.ts.map +1 -1
- package/types/multi.d.ts +6 -0
- package/types/multi.d.ts.map +1 -0
- package/types/multiInstanceNested.test.d.ts.map +1 -1
- package/types/run.d.ts.map +1 -1
- package/types/testSetup.d.ts +1 -0
- package/types/testSetup.d.ts.map +1 -0
- package/types/zeroRunner.d.ts +3 -0
- package/types/zeroRunner.d.ts.map +1 -1
- package/vitest.config.ts +1 -0
package/dist/esm/run.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getInstanceForQueryFn } from "./instanceRegistry.mjs";
|
|
2
2
|
import { resolveQuery } from "./resolveQuery.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { isInZeroMutation, mutatorContext } from "./helpers/mutatorContext.mjs";
|
|
4
|
+
import { getAmbientRunner, getRunner } from "./zeroRunner.mjs";
|
|
4
5
|
let customQueriesRef = null;
|
|
5
6
|
function setCustomQueries(queries) {
|
|
6
7
|
customQueriesRef = queries;
|
|
@@ -21,6 +22,10 @@ function run(queryOrFn, paramsOrMode, modeArg) {
|
|
|
21
22
|
if (queryOrFn && queryOrFn["ast"]) {
|
|
22
23
|
return getRunner()(queryOrFn, options);
|
|
23
24
|
}
|
|
25
|
+
const inMutation = isInZeroMutation();
|
|
26
|
+
if (inMutation && mutatorContext().environment === "server") {
|
|
27
|
+
throw new Error("run(namedQuery) cannot be used inside a Zero mutation. Use tx.run(zql...) for transactional mutation reads.");
|
|
28
|
+
}
|
|
24
29
|
const instance = getInstanceForQueryFn(queryOrFn);
|
|
25
30
|
const customQueries = instance?.customQueries ?? getCustomQueries();
|
|
26
31
|
const queryRequest = resolveQuery({
|
|
@@ -28,7 +33,7 @@ function run(queryOrFn, paramsOrMode, modeArg) {
|
|
|
28
33
|
fn: queryOrFn,
|
|
29
34
|
params
|
|
30
35
|
});
|
|
31
|
-
return
|
|
36
|
+
return getAmbientRunner(instance)(queryRequest, options);
|
|
32
37
|
}
|
|
33
38
|
export { run, setCustomQueries };
|
|
34
39
|
//# sourceMappingURL=run.mjs.map
|
package/dist/esm/run.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getInstanceForQueryFn","resolveQuery","getRunner","customQueriesRef","setCustomQueries","queries","getCustomQueries","Error","run","queryOrFn","paramsOrMode","modeArg","hasParams","params","mode","options","type","instance","customQueries","queryRequest","fn"],"sources":["../../src/run.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,qBAAA,QAA6B;AACtC,SAASC,YAAA,QAAuC;AAChD,SAASC,SAAA,QAAiB;
|
|
1
|
+
{"version":3,"names":["getInstanceForQueryFn","resolveQuery","isInZeroMutation","mutatorContext","getAmbientRunner","getRunner","customQueriesRef","setCustomQueries","queries","getCustomQueries","Error","run","queryOrFn","paramsOrMode","modeArg","hasParams","params","mode","options","type","inMutation","environment","instance","customQueries","queryRequest","fn"],"sources":["../../src/run.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,qBAAA,QAA6B;AACtC,SAASC,YAAA,QAAuC;AAChD,SAASC,gBAAA,EAAkBC,cAAA,QAAsB;AACjD,SAASC,gBAAA,EAAkBC,SAAA,QAAiB;AAS5C,IAAIC,gBAAA,GAA4C;AAEzC,SAASC,iBAAiBC,OAAA,EAA2B;EAC1DF,gBAAA,GAAmBE,OAAA;AACrB;AAEA,SAASC,iBAAA,EAAqC;EAC5C,IAAI,CAACH,gBAAA,EAAkB;IACrB,MAAM,IAAII,KAAA,CACR,8FACF;EACF;EACA,OAAOJ,gBAAA;AACT;AAiCO,SAASK,IACdC,SAAA,EACAC,YAAA,EACAC,OAAA,EACc;EACd,MAAMC,SAAA,GAAYD,OAAA,KAAY,UAAcD,YAAA,IAAgBA,YAAA,KAAiB;EAC7E,MAAMG,MAAA,GAASD,SAAA,GAAYF,YAAA,GAAe;EAC1C,MAAMI,IAAA,GAAOF,SAAA,GAAYD,OAAA,GAAUD,YAAA;EACnC,MAAMK,OAAA,GACJD,IAAA,KAAS,aACJ;IACCE,IAAA,EAAM;EACR,IACA;EAEN,IAAIP,SAAA,IAAaA,SAAA,CAAU,KAAK,GAAG;IAEjC,OAAOP,SAAA,CAAU,EAAEO,SAAA,EAAWM,OAAO;EACvC;EAEA,MAAME,UAAA,GAAalB,gBAAA,CAAiB;EACpC,IAAIkB,UAAA,IAAcjB,cAAA,CAAe,EAAEkB,WAAA,KAAgB,UAAU;IAC3D,MAAM,IAAIX,KAAA,CACR,6GACF;EACF;EAIA,MAAMY,QAAA,GAAWtB,qBAAA,CAAsBY,SAAS;EAChD,MAAMW,aAAA,GAAgBD,QAAA,EAAUC,aAAA,IAAiBd,gBAAA,CAAiB;EAClE,MAAMe,YAAA,GAAevB,YAAA,CAAa;IAAEsB,aAAA;IAAeE,EAAA,EAAIb,SAAA;IAAWI;EAAO,CAAC;EAE1E,OAAOZ,gBAAA,CAAiBkB,QAAQ,EAAEE,YAAA,EAAqBN,OAAO;AAChE","ignoreList":[]}
|
package/dist/esm/run.native.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getInstanceForQueryFn } from "./instanceRegistry.native.js";
|
|
2
2
|
import { resolveQuery } from "./resolveQuery.native.js";
|
|
3
|
-
import {
|
|
3
|
+
import { isInZeroMutation, mutatorContext } from "./helpers/mutatorContext.native.js";
|
|
4
|
+
import { getAmbientRunner, getRunner } from "./zeroRunner.native.js";
|
|
4
5
|
var customQueriesRef = null;
|
|
5
6
|
function setCustomQueries(queries) {
|
|
6
7
|
customQueriesRef = queries;
|
|
@@ -21,6 +22,10 @@ function run(queryOrFn, paramsOrMode, modeArg) {
|
|
|
21
22
|
if (queryOrFn && queryOrFn["ast"]) {
|
|
22
23
|
return getRunner()(queryOrFn, options);
|
|
23
24
|
}
|
|
25
|
+
var inMutation = isInZeroMutation();
|
|
26
|
+
if (inMutation && mutatorContext().environment === "server") {
|
|
27
|
+
throw new Error("run(namedQuery) cannot be used inside a Zero mutation. Use tx.run(zql...) for transactional mutation reads.");
|
|
28
|
+
}
|
|
24
29
|
var instance = getInstanceForQueryFn(queryOrFn);
|
|
25
30
|
var _instance_customQueries;
|
|
26
31
|
var customQueries = (_instance_customQueries = instance === null || instance === void 0 ? void 0 : instance.customQueries) !== null && _instance_customQueries !== void 0 ? _instance_customQueries : getCustomQueries();
|
|
@@ -29,7 +34,7 @@ function run(queryOrFn, paramsOrMode, modeArg) {
|
|
|
29
34
|
fn: queryOrFn,
|
|
30
35
|
params
|
|
31
36
|
});
|
|
32
|
-
return
|
|
37
|
+
return getAmbientRunner(instance)(queryRequest, options);
|
|
33
38
|
}
|
|
34
39
|
export { run, setCustomQueries };
|
|
35
40
|
//# sourceMappingURL=run.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getInstanceForQueryFn","resolveQuery","getRunner","customQueriesRef","setCustomQueries","queries","getCustomQueries","Error","run","queryOrFn","paramsOrMode","modeArg","hasParams","params","mode","options","type","instance","_instance_customQueries","customQueries","queryRequest","fn"],"sources":["../../src/run.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,qBAAA,QAA6B;AACtC,SAASC,YAAA,QAAuC;AAChD,SAASC,SAAA,QAAiB;
|
|
1
|
+
{"version":3,"names":["getInstanceForQueryFn","resolveQuery","isInZeroMutation","mutatorContext","getAmbientRunner","getRunner","customQueriesRef","setCustomQueries","queries","getCustomQueries","Error","run","queryOrFn","paramsOrMode","modeArg","hasParams","params","mode","options","type","inMutation","environment","instance","_instance_customQueries","customQueries","queryRequest","fn"],"sources":["../../src/run.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,qBAAA,QAA6B;AACtC,SAASC,YAAA,QAAuC;AAChD,SAASC,gBAAA,EAAkBC,cAAA,QAAsB;AACjD,SAASC,gBAAA,EAAkBC,SAAA,QAAiB;AAS5C,IAAIC,gBAAA,GAA4C;AAEzC,SAASC,iBAAiBC,OAAA,EAA2B;EAC1DF,gBAAA,GAAmBE,OAAA;AACrB;AAEA,SAASC,iBAAA,EAAqC;EAC5C,IAAI,CAACH,gBAAA,EAAkB;IACrB,MAAM,IAAII,KAAA;EAAA;EACR,OACFJ,gBAAA;AAAA;AAEF,SAAOK,IAAAC,SAAA,EAAAC,YAAA,EAAAC,OAAA;EACT,IAAAC,SAAA,GAAAD,OAAA,eAAAD,YAAA,IAAAA,YAAA;EAiCO,IAAAG,MAAS,GACdD,SACA,GAAAF,YACA,QACc;EACd,IAAAI,IAAM,GAAAF,SAAY,GAAAD,OAAY,GAAAD,YAAc;EAC5C,IAAAK,OAAM,GAAAD,IAAS,eAAY;IAC3BE,IAAM;EACN,SAAM;EAEC,IACCP,SAAM,IAAAA,SAAA;IACR,OACAP,SAAA,GAAAO,SAAA,EAAAM,OAAA;EAEN;EAEE,IAAAE,UAAO,GAAAlB,gBAAuB;EAChC,IAAAkB,UAAA,IAAAjB,cAAA,GAAAkB,WAAA;IAEA,MAAM,IAAAX,KAAA,8GAA8B;EACpC;EACE,IAAAY,QAAU,GAAAtB,qBAAA,CAAAY,SAAA;EAAA,IACRW,uBAAA;EAAA,IACFC,aAAA,IAAAD,uBAAA,GAAAD,QAAA,aAAAA,QAAA,uBAAAA,QAAA,CAAAE,aAAA,cAAAD,uBAAA,cAAAA,uBAAA,GAAAd,gBAAA;EACF,IAAAgB,YAAA,GAAAxB,YAAA;IAIAuB,aAAM;IACNE,EAAA,EAAMd,SAAA;IACNI;EAEA;EACF,OAAAZ,gBAAA,CAAAkB,QAAA,EAAAG,YAAA,EAAAP,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
if (typeof globalThis.localStorage?.getItem !== "function") {
|
|
2
|
+
const store = /* @__PURE__ */new Map();
|
|
3
|
+
Object.defineProperty(globalThis, "localStorage", {
|
|
4
|
+
configurable: true,
|
|
5
|
+
value: {
|
|
6
|
+
get length() {
|
|
7
|
+
return store.size;
|
|
8
|
+
},
|
|
9
|
+
clear() {
|
|
10
|
+
store.clear();
|
|
11
|
+
},
|
|
12
|
+
getItem(key) {
|
|
13
|
+
return store.get(String(key)) ?? null;
|
|
14
|
+
},
|
|
15
|
+
key(index) {
|
|
16
|
+
return Array.from(store.keys())[index] ?? null;
|
|
17
|
+
},
|
|
18
|
+
removeItem(key) {
|
|
19
|
+
store.delete(String(key));
|
|
20
|
+
},
|
|
21
|
+
setItem(key, value) {
|
|
22
|
+
store.set(String(key), String(value));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=testSetup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["globalThis","localStorage","getItem","store","Map","Object","defineProperty","configurable","value","length","size","clear","key","get","String","index","Array","from","keys","removeItem","delete","setItem","set"],"sources":["../../src/testSetup.ts"],"sourcesContent":[null],"mappings":"AAAA,IAAI,OAAOA,UAAA,CAAWC,YAAA,EAAcC,OAAA,KAAY,YAAY;EAC1D,MAAMC,KAAA,GAAQ,mBAAIC,GAAA,CAAoB;EACtCC,MAAA,CAAOC,cAAA,CAAeN,UAAA,EAAY,gBAAgB;IAChDO,YAAA,EAAc;IACdC,KAAA,EAAO;MACL,IAAIC,OAAA,EAAS;QACX,OAAON,KAAA,CAAMO,IAAA;MACf;MACAC,MAAA,EAAQ;QACNR,KAAA,CAAMQ,KAAA,CAAM;MACd;MACAT,QAAQU,GAAA,EAAa;QACnB,OAAOT,KAAA,CAAMU,GAAA,CAAIC,MAAA,CAAOF,GAAG,CAAC,KAAK;MACnC;MACAA,IAAIG,KAAA,EAAe;QACjB,OAAOC,KAAA,CAAMC,IAAA,CAAKd,KAAA,CAAMe,IAAA,CAAK,CAAC,EAAEH,KAAK,KAAK;MAC5C;MACAI,WAAWP,GAAA,EAAa;QACtBT,KAAA,CAAMiB,MAAA,CAAON,MAAA,CAAOF,GAAG,CAAC;MAC1B;MACAS,QAAQT,GAAA,EAAaJ,KAAA,EAAe;QAClCL,KAAA,CAAMmB,GAAA,CAAIR,MAAA,CAAOF,GAAG,GAAGE,MAAA,CAAON,KAAK,CAAC;MACtC;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var _globalThis_localStorage;
|
|
2
|
+
if (typeof ((_globalThis_localStorage = globalThis.localStorage) === null || _globalThis_localStorage === void 0 ? void 0 : _globalThis_localStorage.getItem) !== "function") {
|
|
3
|
+
var store = /* @__PURE__ */new Map();
|
|
4
|
+
Object.defineProperty(globalThis, "localStorage", {
|
|
5
|
+
configurable: true,
|
|
6
|
+
value: {
|
|
7
|
+
get length() {
|
|
8
|
+
return store.size;
|
|
9
|
+
},
|
|
10
|
+
clear() {
|
|
11
|
+
store.clear();
|
|
12
|
+
},
|
|
13
|
+
getItem(key) {
|
|
14
|
+
var _store_get;
|
|
15
|
+
return (_store_get = store.get(String(key))) !== null && _store_get !== void 0 ? _store_get : null;
|
|
16
|
+
},
|
|
17
|
+
key(index) {
|
|
18
|
+
var _Array_from_index;
|
|
19
|
+
return (_Array_from_index = Array.from(store.keys())[index]) !== null && _Array_from_index !== void 0 ? _Array_from_index : null;
|
|
20
|
+
},
|
|
21
|
+
removeItem(key) {
|
|
22
|
+
store.delete(String(key));
|
|
23
|
+
},
|
|
24
|
+
setItem(key, value) {
|
|
25
|
+
store.set(String(key), String(value));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=testSetup.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_globalThis_localStorage","globalThis","localStorage","getItem","store","Map","Object","defineProperty","configurable","value","length","size","clear","key","_store_get","get","String","index","_Array_from_index","Array","from","keys","removeItem","delete","setItem","set"],"sources":["../../src/testSetup.ts"],"sourcesContent":[null],"mappings":"AAAA,IAAIA,wBAAkB;AACpB,YAAM,CAAAA,wBAAY,GAAoBC,UAAA,CAAAC,YAAA,cAAAF,wBAAA,uBAAAA,wBAAA,CAAAG,OAAA;EACtC,IAAAC,KAAO,kBAAe,IAAAC,GAAY;EAAgBC,MAChD,CAAAC,cAAc,CAAAN,UAAA;IACdO,YAAO;IAAAC,KACL,EAAI;MACF,IAAAC,MAAOA,CAAA;QACT,OAAAN,KAAA,CAAAO,IAAA;MACA;MACEC,MAAA,EAAM;QACRR,KAAA,CAAAQ,KAAA;MACA;MACET,QAAAU,GAAO;QACT,IAAAC,UAAA;QACA,OAAI,CAAAA,UAAe,GAAAV,KAAA,CAAAW,GAAA,CAAAC,MAAA,CAAAH,GAAA,gBAAAC,UAAA,cAAAA,UAAA;MACjB;MACFD,IAAAI,KAAA;QACA,IAAAC,iBAAwB;QACtB,OAAM,CAAAA,iBAAkB,GAAAC,KAAA,CAAAC,IAAA,CAAAhB,KAAA,CAAAiB,IAAA,IAAAJ,KAAA,eAAAC,iBAAA,cAAAA,iBAAA;MAC1B;MACAI,UAAQA,CAAAT,GAAa;QACnBT,KAAA,CAAMmB,MAAI,CAAAP,MAAO,CAAGH,GAAG;MACzB;MACFW,QAAAX,GAAA,EAAAJ,KAAA;QACDL,KAAA,CAAAqB,GAAA,CAAAT,MAAA,CAAAH,GAAA,GAAAG,MAAA,CAAAP,KAAA;MACH","ignoreList":[]}
|
package/dist/esm/zeroRunner.mjs
CHANGED
|
@@ -7,6 +7,9 @@ function getRunner(instance) {
|
|
|
7
7
|
if (isInZeroMutation()) {
|
|
8
8
|
return (q, o) => mutatorContext().tx.run(q, o);
|
|
9
9
|
}
|
|
10
|
+
return getAmbientRunner(instance);
|
|
11
|
+
}
|
|
12
|
+
function getAmbientRunner(instance) {
|
|
10
13
|
if (instance?.runner) {
|
|
11
14
|
return instance.runner;
|
|
12
15
|
}
|
|
@@ -15,5 +18,5 @@ function getRunner(instance) {
|
|
|
15
18
|
}
|
|
16
19
|
return runner;
|
|
17
20
|
}
|
|
18
|
-
export { getRunner, setRunner };
|
|
21
|
+
export { getAmbientRunner, getRunner, setRunner };
|
|
19
22
|
//# sourceMappingURL=zeroRunner.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isInZeroMutation","mutatorContext","runner","setRunner","r","getRunner","instance","q","o","tx","run","Error"],"sources":["../../src/zeroRunner.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,gBAAA,EAAkBC,cAAA,QAAsB;AAgBjD,IAAIC,MAAA,GAA4B;AAEzB,SAASC,UAAUC,CAAA,EAAe;EACvCF,MAAA,GAASE,CAAA;AACX;AAEO,SAASC,UAAUC,QAAA,EAAsD;EAC9E,IAAIN,gBAAA,CAAiB,GAAG;IACtB,OAAO,CAACO,CAAA,EAAGC,CAAA,KAAMP,cAAA,CAAe,EAAEQ,EAAA,CAAGC,GAAA,CAAIH,CAAA,EAAGC,CAAC;EAC/C;
|
|
1
|
+
{"version":3,"names":["isInZeroMutation","mutatorContext","runner","setRunner","r","getRunner","instance","q","o","tx","run","getAmbientRunner","Error"],"sources":["../../src/zeroRunner.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,gBAAA,EAAkBC,cAAA,QAAsB;AAgBjD,IAAIC,MAAA,GAA4B;AAEzB,SAASC,UAAUC,CAAA,EAAe;EACvCF,MAAA,GAASE,CAAA;AACX;AAEO,SAASC,UAAUC,QAAA,EAAsD;EAC9E,IAAIN,gBAAA,CAAiB,GAAG;IACtB,OAAO,CAACO,CAAA,EAAGC,CAAA,KAAMP,cAAA,CAAe,EAAEQ,EAAA,CAAGC,GAAA,CAAIH,CAAA,EAAGC,CAAC;EAC/C;EAEA,OAAOG,gBAAA,CAAiBL,QAAQ;AAClC;AAEO,SAASK,iBAAiBL,QAAA,EAAsD;EAGrF,IAAIA,QAAA,EAAUJ,MAAA,EAAQ;IACpB,OAAOI,QAAA,CAASJ,MAAA;EAClB;EAEA,IAAI,CAACA,MAAA,EAAQ;IACX,MAAM,IAAIU,KAAA,CACR,6GACF;EACF;EAEA,OAAOV,MAAA;AACT","ignoreList":[]}
|
|
@@ -9,6 +9,9 @@ function getRunner(instance) {
|
|
|
9
9
|
return mutatorContext().tx.run(q, o);
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
+
return getAmbientRunner(instance);
|
|
13
|
+
}
|
|
14
|
+
function getAmbientRunner(instance) {
|
|
12
15
|
if (instance === null || instance === void 0 ? void 0 : instance.runner) {
|
|
13
16
|
return instance.runner;
|
|
14
17
|
}
|
|
@@ -17,5 +20,5 @@ function getRunner(instance) {
|
|
|
17
20
|
}
|
|
18
21
|
return runner;
|
|
19
22
|
}
|
|
20
|
-
export { getRunner, setRunner };
|
|
23
|
+
export { getAmbientRunner, getRunner, setRunner };
|
|
21
24
|
//# sourceMappingURL=zeroRunner.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["isInZeroMutation","mutatorContext","runner","setRunner","r","getRunner","instance","q","o","tx","run","Error"],"sources":["../../src/zeroRunner.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,gBAAA,EAAkBC,cAAA,QAAsB;AAgBjD,IAAIC,MAAA,GAA4B;AAEzB,SAASC,UAAUC,CAAA,EAAe;EACvCF,MAAA,GAASE,CAAA;AACX;AAEO,SAASC,UAAUC,QAAA,EAAsD;EAC9E,IAAIN,gBAAA,CAAiB,GAAG;IACtB,OAAO,UAAIO,CAAM,EAAAC,CAAA;MACnB,OAAAP,cAAA,GAAAQ,EAAA,CAAAC,GAAA,CAAAH,CAAA,EAAAC,CAAA;
|
|
1
|
+
{"version":3,"names":["isInZeroMutation","mutatorContext","runner","setRunner","r","getRunner","instance","q","o","tx","run","getAmbientRunner","Error"],"sources":["../../src/zeroRunner.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,gBAAA,EAAkBC,cAAA,QAAsB;AAgBjD,IAAIC,MAAA,GAA4B;AAEzB,SAASC,UAAUC,CAAA,EAAe;EACvCF,MAAA,GAASE,CAAA;AACX;AAEO,SAASC,UAAUC,QAAA,EAAsD;EAC9E,IAAIN,gBAAA,CAAiB,GAAG;IACtB,OAAO,UAAIO,CAAM,EAAAC,CAAA;MACnB,OAAAP,cAAA,GAAAQ,EAAA,CAAAC,GAAA,CAAAH,CAAA,EAAAC,CAAA;IAEA;EACF;EAEO,OAASG,gBAAA,CAAiBL,QAAA;AAG/B;AACE,SAAAK,gBAAgBA,CAAAL,QAAA;EAClB,IAAAA,QAAA,aAAAA,QAAA,uBAAAA,QAAA,CAAAJ,MAAA;IAEA,OAAKI,QAAQ,CAAAJ,MAAA;EACX;EAAU,IACR,CAAAA,MAAA;IACF,UAAAU,KAAA;EACF;EAEA,OAAOV,MAAA;AACT","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "on-zero",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.37",
|
|
4
4
|
"description": "A typed layer over @rocicorp/zero with queries, mutations, and permissions",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"source": "src/index.ts",
|
|
@@ -65,6 +65,12 @@
|
|
|
65
65
|
"import": "./dist/esm/vite-plugin.mjs",
|
|
66
66
|
"require": "./dist/cjs/vite-plugin.cjs"
|
|
67
67
|
},
|
|
68
|
+
"./multi": {
|
|
69
|
+
"react-native": "./dist/esm/multi.native.js",
|
|
70
|
+
"types": "./types/multi.d.ts",
|
|
71
|
+
"import": "./dist/esm/multi.mjs",
|
|
72
|
+
"require": "./dist/cjs/multi.cjs"
|
|
73
|
+
},
|
|
68
74
|
"./drizzle": {
|
|
69
75
|
"types": "./types/createSchemaFromDrizzle.d.ts",
|
|
70
76
|
"import": "./dist/esm/createSchemaFromDrizzle.mjs",
|
|
@@ -77,7 +83,7 @@
|
|
|
77
83
|
}
|
|
78
84
|
},
|
|
79
85
|
"dependencies": {
|
|
80
|
-
"@take-out/helpers": "0.4.
|
|
86
|
+
"@take-out/helpers": "0.4.37",
|
|
81
87
|
"chokidar": "^4.0.3",
|
|
82
88
|
"citty": "^0.1.6",
|
|
83
89
|
"valibot": "^1.1.0"
|
package/readme.md
CHANGED
|
@@ -526,9 +526,10 @@ exactly one instance — duplicate claims throw at create time. then combine
|
|
|
526
526
|
them into one consumer surface:
|
|
527
527
|
|
|
528
528
|
```tsx
|
|
529
|
-
import {
|
|
529
|
+
import { createZeroClient } from 'on-zero'
|
|
530
|
+
import { combineZeroClients, createZeroClientWithDirectQueries } from 'on-zero/multi'
|
|
530
531
|
|
|
531
|
-
const control =
|
|
532
|
+
const control = createZeroClientWithDirectQueries({
|
|
532
533
|
schema,
|
|
533
534
|
models: controlModels,
|
|
534
535
|
groupedQueries: controlQueries,
|
|
@@ -551,8 +552,8 @@ export const { useQuery, zero, run, preload, getQuery, zeroEvents } =
|
|
|
551
552
|
// client passed to combineZeroClients (or the `inner` option) must be the
|
|
552
553
|
// INNERMOST provider — zero-react's useQuery resolves the nearest provider's
|
|
553
554
|
// instance from context, so only the inner instance rides that path. all
|
|
554
|
-
// other instances
|
|
555
|
-
//
|
|
555
|
+
// other instances must opt into the context-free direct adapter through
|
|
556
|
+
// createZeroClientWithDirectQueries.
|
|
556
557
|
;<control.ProvideZero server={controlUrl} userID={user.id}>
|
|
557
558
|
<project.ProvideZero server={projectUrl} userID={`${user.id}:${projectId}`}>
|
|
558
559
|
<App />
|
|
@@ -565,11 +566,12 @@ constraints:
|
|
|
565
566
|
- each instance needs its own client-group identity (separate `userID` /
|
|
566
567
|
storage key / server url) — never swap the backing namespace under a live
|
|
567
568
|
instance.
|
|
569
|
+
- most apps should use plain `createZeroClient`; the `on-zero/multi` entrypoint
|
|
570
|
+
is only for this nested-provider edge case.
|
|
568
571
|
- give the INNER slot to the instance owning the bulk of the subscriptions —
|
|
569
|
-
inner queries
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
queries (current user, settings, directories).
|
|
572
|
+
inner queries use zero-react's native context path. outer instances use the
|
|
573
|
+
direct adapter on their own mounted zero, so keep those instances on bounded,
|
|
574
|
+
low-fanout queries (current user, settings, directories).
|
|
573
575
|
- a mutator may only read/write tables owned by its own instance. its
|
|
574
576
|
transaction runs on that instance alone; cross-instance writes are not
|
|
575
577
|
detectable at registration and will silently miss the other store.
|
|
@@ -19,12 +19,10 @@ import type { ReactNode } from 'react'
|
|
|
19
19
|
// provider is mounted INNERMOST — may use the upstream context path. by
|
|
20
20
|
// default that is the LAST client passed here (override via the `inner`
|
|
21
21
|
// option); the first client is primary and its provider is expected OUTER.
|
|
22
|
-
// the inner instance's queries ride zero-react's useQuery unchanged
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
// on the owning instance but skip view dedup — keep those instances on
|
|
27
|
-
// bounded, tiny queries.
|
|
22
|
+
// the inner instance's queries ride zero-react's useQuery unchanged. every
|
|
23
|
+
// other instance must be created through `createZeroClientWithDirectQueries`
|
|
24
|
+
// from `on-zero/multi`, which opts into the context-free adapter for this
|
|
25
|
+
// nested-provider edge case. keep those non-inner instances bounded.
|
|
28
26
|
|
|
29
27
|
type ControlQueriesProps = {
|
|
30
28
|
children: ReactNode
|
package/src/createUseQuery.tsx
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { useQuery as zeroUseQuery } from '@rocicorp/zero/react'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
useContext,
|
|
5
|
-
useEffect,
|
|
6
|
-
useMemo,
|
|
7
|
-
useRef,
|
|
8
|
-
useSyncExternalStore,
|
|
9
|
-
type Context,
|
|
10
|
-
} from 'react'
|
|
2
|
+
import { useContext, useMemo, useRef, type Context } from 'react'
|
|
11
3
|
|
|
12
4
|
import { useZeroDebug } from './helpers/useZeroDebug'
|
|
13
5
|
import { resolveQuery, type PlainQueryFn } from './resolveQuery'
|
|
@@ -50,7 +42,7 @@ export type UseQueryHook<Schema extends ZeroSchema> = {
|
|
|
50
42
|
const EMPTY_RESPONSE = [null, { type: 'unknown' }] as never
|
|
51
43
|
|
|
52
44
|
// determine if useQuery-style args are (fn, params, options) or (fn, options)
|
|
53
|
-
function parseUseQueryArgs(paramsOrOptions: any, optionsArg: any) {
|
|
45
|
+
export function parseUseQueryArgs(paramsOrOptions: any, optionsArg: any) {
|
|
54
46
|
const hasParams =
|
|
55
47
|
optionsArg !== undefined ||
|
|
56
48
|
(paramsOrOptions &&
|
|
@@ -105,182 +97,3 @@ export function createUseQuery<Schema extends ZeroSchema>({
|
|
|
105
97
|
|
|
106
98
|
return useQuery as UseQueryHook<Schema>
|
|
107
99
|
}
|
|
108
|
-
|
|
109
|
-
// --- direct (context-free) query path -------------------------------------
|
|
110
|
-
|
|
111
|
-
// zero-react's useQuery resolves its zero instance via useZero() → react
|
|
112
|
-
// context, i.e. the NEAREST mounted ZeroProvider. with multiple client
|
|
113
|
-
// instances nested on one page, every context-path query would materialize
|
|
114
|
-
// against the innermost provider's instance regardless of which instance owns
|
|
115
|
-
// the query. this hook is the context-free counterpart: it materializes the
|
|
116
|
-
// resolved query directly on the owning instance's mounted zero.
|
|
117
|
-
//
|
|
118
|
-
// tradeoffs vs the context path (acceptable for the bounded, tiny queries the
|
|
119
|
-
// non-inner instances own — see combineZeroClients):
|
|
120
|
-
// - no cross-component view dedup (zero-react's viewStore): each hook
|
|
121
|
-
// instance materializes its own view.
|
|
122
|
-
// - no strict-mode double-render protection: a discarded render's view is
|
|
123
|
-
// not destroyed until the owning zero closes.
|
|
124
|
-
|
|
125
|
-
const DISABLED_SUBSCRIBE = () => () => {}
|
|
126
|
-
// upstream zero-react returns [undefined, {type:'unknown'}] when disabled
|
|
127
|
-
const DISABLED_SNAPSHOT: readonly [undefined, { type: 'unknown' }] = [
|
|
128
|
-
undefined,
|
|
129
|
-
{ type: 'unknown' },
|
|
130
|
-
]
|
|
131
|
-
const getDisabledSnapshot = () => DISABLED_SNAPSHOT
|
|
132
|
-
|
|
133
|
-
type DirectView = {
|
|
134
|
-
subscribe: (notify: () => void) => () => void
|
|
135
|
-
getSnapshot: () => readonly [unknown, { type: string }]
|
|
136
|
-
destroy: () => void
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// method syntax for bivariant param checks — the real Zero['materialize']
|
|
140
|
-
// generic signature must remain assignable to this structural slice. ttl is
|
|
141
|
-
// untyped pass-through here, matching the context path (zeroUseQuery's
|
|
142
|
-
// options are equally unchecked against upstream's TTL type).
|
|
143
|
-
type MaterializableZero = {
|
|
144
|
-
materialize(
|
|
145
|
-
query: any,
|
|
146
|
-
options?: { ttl?: any },
|
|
147
|
-
): {
|
|
148
|
-
addListener(cb: (data: any, resultType: string) => void): void
|
|
149
|
-
destroy(): void
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function createDirectView(
|
|
154
|
-
getZero: () => MaterializableZero | null,
|
|
155
|
-
queryRequest: unknown,
|
|
156
|
-
ttl: UseQueryOptions['ttl'],
|
|
157
|
-
): DirectView {
|
|
158
|
-
let snapshot: readonly [unknown, { type: string }] = DISABLED_SNAPSHOT
|
|
159
|
-
const listeners = new Set<() => void>()
|
|
160
|
-
let view: { destroy(): void } | null = null
|
|
161
|
-
|
|
162
|
-
const materialize = () => {
|
|
163
|
-
const zero = getZero()
|
|
164
|
-
if (!zero) return
|
|
165
|
-
// zero.materialize accepts a QueryRequest (it applies the instance context
|
|
166
|
-
// itself) — the same public api the upstream ViewWrapper uses
|
|
167
|
-
const next = zero.materialize(queryRequest, ttl === undefined ? undefined : { ttl })
|
|
168
|
-
view = next
|
|
169
|
-
|
|
170
|
-
// addListener fires immediately with current data, so the snapshot is
|
|
171
|
-
// populated before react's first getSnapshot. data must be cloned: the
|
|
172
|
-
// underlying view mutates it in place, and useSyncExternalStore requires
|
|
173
|
-
// immutable snapshots to detect changes.
|
|
174
|
-
next.addListener((data, resultType) => {
|
|
175
|
-
snapshot = [
|
|
176
|
-
data === undefined ? undefined : structuredClone(data),
|
|
177
|
-
{ type: resultType },
|
|
178
|
-
]
|
|
179
|
-
for (const listener of listeners) {
|
|
180
|
-
listener()
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// eager: snapshot is warm before react's first getSnapshot
|
|
186
|
-
materialize()
|
|
187
|
-
|
|
188
|
-
return {
|
|
189
|
-
subscribe: (notify) => {
|
|
190
|
-
listeners.add(notify)
|
|
191
|
-
// react runs effect cleanup + re-setup with unchanged deps under
|
|
192
|
-
// StrictMode double-invoke and suspense hide/reveal — the cleanup
|
|
193
|
-
// destroyed the view while this memoized store survived, so the
|
|
194
|
-
// resubscribe must re-materialize or the snapshot freezes forever
|
|
195
|
-
if (view === null) {
|
|
196
|
-
materialize()
|
|
197
|
-
}
|
|
198
|
-
return () => listeners.delete(notify)
|
|
199
|
-
},
|
|
200
|
-
getSnapshot: () => snapshot,
|
|
201
|
-
destroy: () => {
|
|
202
|
-
const current = view
|
|
203
|
-
view = null
|
|
204
|
-
if (!current) return
|
|
205
|
-
// identity rotation closes the owning zero before react runs this
|
|
206
|
-
// cleanup (the version bump that swaps the view is post-commit) — the
|
|
207
|
-
// closed instance already removed the view's ttl connection record, so
|
|
208
|
-
// zero's destroy asserts ("Connection not found"). destroy-after-close
|
|
209
|
-
// is semantically a no-op; swallow it instead of killing the route.
|
|
210
|
-
try {
|
|
211
|
-
current.destroy()
|
|
212
|
-
} catch {
|
|
213
|
-
// instance closed first — nothing left to tear down
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export function createUseQueryDirect<Schema extends ZeroSchema>({
|
|
220
|
-
DisabledContext,
|
|
221
|
-
customQueries,
|
|
222
|
-
getZero,
|
|
223
|
-
zeroVersion,
|
|
224
|
-
}: {
|
|
225
|
-
DisabledContext: Context<QueryControlMode>
|
|
226
|
-
customQueries: AnyQueryRegistry
|
|
227
|
-
// the owning instance's mounted zero (null before its provider mounts)
|
|
228
|
-
getZero: () => MaterializableZero | null
|
|
229
|
-
// bumps after commit whenever the mounted zero changes (mount, rotation)
|
|
230
|
-
zeroVersion: Emitter<number>
|
|
231
|
-
}): UseQueryHook<Schema> {
|
|
232
|
-
function useQueryDirect(...args: any[]): any {
|
|
233
|
-
const disableMode = useContext(DisabledContext)
|
|
234
|
-
const lastRef = useRef<any>(EMPTY_RESPONSE)
|
|
235
|
-
const [fn, paramsOrOptions, optionsArg] = args
|
|
236
|
-
|
|
237
|
-
const version = useEmitterValue(zeroVersion)
|
|
238
|
-
const { params, options } = parseUseQueryArgs(paramsOrOptions, optionsArg)
|
|
239
|
-
|
|
240
|
-
let enabled = true
|
|
241
|
-
let ttl: UseQueryOptions['ttl']
|
|
242
|
-
if (typeof options === 'boolean') {
|
|
243
|
-
enabled = options
|
|
244
|
-
} else if (options) {
|
|
245
|
-
enabled = options.enabled !== false
|
|
246
|
-
ttl = options.ttl
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// key the view by VALUE (serialized params), not params object identity —
|
|
250
|
-
// there is no view dedup on this path, so an unstable inline params object
|
|
251
|
-
// must not re-materialize every render
|
|
252
|
-
const paramsKey = params === undefined ? '' : JSON.stringify(params)
|
|
253
|
-
|
|
254
|
-
const view = useMemo((): DirectView | null => {
|
|
255
|
-
if (!enabled || !getZero()) return null
|
|
256
|
-
const queryRequest = resolveQuery({ customQueries, fn, params })
|
|
257
|
-
return createDirectView(getZero, queryRequest, ttl)
|
|
258
|
-
// params is keyed by paramsKey; version re-materializes on a new zero
|
|
259
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
260
|
-
}, [fn, paramsKey, enabled, ttl, version])
|
|
261
|
-
|
|
262
|
-
useEffect(() => {
|
|
263
|
-
if (!view) return
|
|
264
|
-
return () => view.destroy()
|
|
265
|
-
}, [view])
|
|
266
|
-
|
|
267
|
-
const out = useSyncExternalStore(
|
|
268
|
-
view ? view.subscribe : DISABLED_SUBSCRIBE,
|
|
269
|
-
view ? view.getSnapshot : getDisabledSnapshot,
|
|
270
|
-
view ? view.getSnapshot : getDisabledSnapshot,
|
|
271
|
-
)
|
|
272
|
-
|
|
273
|
-
if (!disableMode) {
|
|
274
|
-
lastRef.current = out
|
|
275
|
-
return out
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (disableMode === 'last-value') {
|
|
279
|
-
return lastRef.current
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return EMPTY_RESPONSE
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return useQueryDirect as UseQueryHook<Schema>
|
|
286
|
-
}
|