cogsbox-state 0.5.21 → 0.5.22
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.
|
@@ -1,36 +1,38 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
import { getGlobalStore as
|
|
1
|
+
import { o as d } from "./node_modules/@trpc/server/dist/observable-ade1bad8.js";
|
|
2
|
+
import { getGlobalStore as i } from "./store.js";
|
|
3
3
|
const m = () => {
|
|
4
|
-
const s =
|
|
5
|
-
return () => (
|
|
6
|
-
(n) =>
|
|
7
|
-
next(
|
|
8
|
-
n.next(
|
|
4
|
+
const s = i.getState().addValidationError;
|
|
5
|
+
return () => (g) => ({ next: l, op: a }) => d(
|
|
6
|
+
(n) => l(a).subscribe({
|
|
7
|
+
next(o) {
|
|
8
|
+
n.next(o);
|
|
9
9
|
},
|
|
10
|
-
error(
|
|
11
|
-
console.log("link error1",
|
|
10
|
+
error(o) {
|
|
11
|
+
console.log("link error1", o);
|
|
12
12
|
try {
|
|
13
|
-
const
|
|
14
|
-
console.log("link error2",
|
|
15
|
-
(
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const t = JSON.parse(o.message);
|
|
14
|
+
console.log("link error2", t), Array.isArray(t) ? t.forEach(
|
|
15
|
+
(r) => {
|
|
16
|
+
const e = `${a.path}.${r.path.join(".")}`;
|
|
17
|
+
console.log(
|
|
18
|
+
"Adding validation error",
|
|
19
|
+
e,
|
|
20
|
+
r.message
|
|
21
|
+
), console.log(
|
|
22
|
+
"Current validation store before:",
|
|
23
|
+
i.getState().validationErrors
|
|
24
|
+
), s(e, r.message), console.log(
|
|
25
|
+
"Current validation store after:",
|
|
26
|
+
i.getState().validationErrors
|
|
20
27
|
);
|
|
21
28
|
}
|
|
22
|
-
) : typeof
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
c,
|
|
27
|
-
a
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
);
|
|
29
|
+
) : typeof t == "object" && t !== null && Object.entries(t).forEach(([r, e]) => {
|
|
30
|
+
const c = `${a.path}.${r}`;
|
|
31
|
+
s(c, e);
|
|
32
|
+
});
|
|
31
33
|
} catch {
|
|
32
34
|
}
|
|
33
|
-
n.error(
|
|
35
|
+
n.error(o);
|
|
34
36
|
},
|
|
35
37
|
complete() {
|
|
36
38
|
n.complete();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TRPCValidationLink.js","sources":["../src/TRPCValidationLink.ts"],"sourcesContent":["import { observable } from \"@trpc/server/observable\";\r\nimport type { AnyRouter } from \"@trpc/server\";\r\nimport type { TRPCLink } from \"@trpc/client\";\r\nimport type { Operation } from \"@trpc/client\";\r\nimport type { TRPCClientError } from \"@trpc/client\";\r\nimport { getGlobalStore } from \"./store\";\r\nimport type { Observer } from \"@trpc/server/observable\";\r\nexport const useCogsTrpcValidationLink = <TRouter extends AnyRouter>() => {\r\n
|
|
1
|
+
{"version":3,"file":"TRPCValidationLink.js","sources":["../src/TRPCValidationLink.ts"],"sourcesContent":["import { observable } from \"@trpc/server/observable\";\r\nimport type { AnyRouter } from \"@trpc/server\";\r\nimport type { TRPCLink } from \"@trpc/client\";\r\nimport type { Operation } from \"@trpc/client\";\r\nimport type { TRPCClientError } from \"@trpc/client\";\r\nimport { getGlobalStore } from \"./store\";\r\nimport type { Observer } from \"@trpc/server/observable\";\r\nexport const useCogsTrpcValidationLink = <TRouter extends AnyRouter>() => {\r\n const addValidationError = getGlobalStore.getState().addValidationError;\r\n\r\n const TrpcValidationLink = (): TRPCLink<TRouter> => {\r\n return (opts) => {\r\n return ({ next, op }: { next: any; op: Operation }) => {\r\n return observable(\r\n (observer: Observer<any, TRPCClientError<TRouter>>) => {\r\n const unsubscribe = next(op).subscribe({\r\n next(value: unknown) {\r\n observer.next(value);\r\n },\r\n error(err: TRPCClientError<TRouter>) {\r\n console.log(\"link error1\", err);\r\n try {\r\n const errorObject = JSON.parse(err.message);\r\n console.log(\"link error2\", errorObject);\r\n\r\n if (Array.isArray(errorObject)) {\r\n errorObject.forEach(\r\n (error: { path: string[]; message: string }) => {\r\n const fullpath = `${op.path}.${error.path.join(\".\")}`;\r\n // In your TRPC link\r\n console.log(\r\n \"Adding validation error\",\r\n fullpath,\r\n error.message\r\n );\r\n console.log(\r\n \"Current validation store before:\",\r\n getGlobalStore.getState().validationErrors\r\n );\r\n addValidationError(fullpath, error.message);\r\n console.log(\r\n \"Current validation store after:\",\r\n getGlobalStore.getState().validationErrors\r\n );\r\n }\r\n );\r\n } else if (\r\n typeof errorObject === \"object\" &&\r\n errorObject !== null\r\n ) {\r\n Object.entries(errorObject).forEach(([key, value]) => {\r\n const fullpath = `${op.path}.${key}`;\r\n addValidationError(fullpath, value as string);\r\n });\r\n }\r\n } catch (e) {\r\n // Silently handle parse errors\r\n }\r\n\r\n observer.error(err);\r\n },\r\n complete() {\r\n observer.complete();\r\n },\r\n });\r\n return unsubscribe;\r\n }\r\n );\r\n };\r\n };\r\n };\r\n return TrpcValidationLink;\r\n};\r\n"],"names":["useCogsTrpcValidationLink","addValidationError","getGlobalStore","opts","next","op","observable","observer","value","err","errorObject","error","fullpath","key"],"mappings":";;AAOO,MAAMA,IAA4B,MAAiC;AAClE,QAAAC,IAAqBC,EAAe,SAAA,EAAW;AA+D9C,SA7DoB,MAClB,CAACC,MACC,CAAC,EAAE,MAAAC,GAAM,IAAAC,QACPC;AAAA,IACL,CAACC,MACqBH,EAAKC,CAAE,EAAE,UAAU;AAAA,MACrC,KAAKG,GAAgB;AACnB,QAAAD,EAAS,KAAKC,CAAK;AAAA,MACrB;AAAA,MACA,MAAMC,GAA+B;AAC3B,gBAAA,IAAI,eAAeA,CAAG;AAC1B,YAAA;AACF,gBAAMC,IAAc,KAAK,MAAMD,EAAI,OAAO;AAClC,kBAAA,IAAI,eAAeC,CAAW,GAElC,MAAM,QAAQA,CAAW,IACfA,EAAA;AAAA,YACV,CAACC,MAA+C;AACxC,oBAAAC,IAAW,GAAGP,EAAG,IAAI,IAAIM,EAAM,KAAK,KAAK,GAAG,CAAC;AAE3C,sBAAA;AAAA,gBACN;AAAA,gBACAC;AAAA,gBACAD,EAAM;AAAA,cACR,GACQ,QAAA;AAAA,gBACN;AAAA,gBACAT,EAAe,WAAW;AAAA,cAC5B,GACmBD,EAAAW,GAAUD,EAAM,OAAO,GAClC,QAAA;AAAA,gBACN;AAAA,gBACAT,EAAe,WAAW;AAAA,cAC5B;AAAA,YAAA;AAAA,UAEJ,IAEA,OAAOQ,KAAgB,YACvBA,MAAgB,QAET,OAAA,QAAQA,CAAW,EAAE,QAAQ,CAAC,CAACG,GAAKL,CAAK,MAAM;AACpD,kBAAMI,IAAW,GAAGP,EAAG,IAAI,IAAIQ,CAAG;AAClC,YAAAZ,EAAmBW,GAAUJ,CAAe;AAAA,UAAA,CAC7C;AAAA,gBAEO;AAAA,QAAA;AAIZ,QAAAD,EAAS,MAAME,CAAG;AAAA,MACpB;AAAA,MACA,WAAW;AACT,QAAAF,EAAS,SAAS;AAAA,MAAA;AAAA,IACpB,CACD;AAAA,EAGL;AAKR;"}
|