cogsbox-state 0.5.55 → 0.5.56
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,4 +1,6 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { TRPCLink } from '@trpc/client';
|
|
3
3
|
|
|
4
|
-
export declare const useCogsTrpcValidationLink: <TRouter extends AnyRouter>(
|
|
4
|
+
export declare const useCogsTrpcValidationLink: <TRouter extends AnyRouter>(passedOpts?: {
|
|
5
|
+
log?: boolean;
|
|
6
|
+
}) => () => TRPCLink<TRouter>;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
import { getGlobalStore as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
return () => (b) => ({ next:
|
|
6
|
-
(a) =>
|
|
7
|
-
next(
|
|
8
|
-
a.next(
|
|
1
|
+
import { o as u } from "./node_modules/@trpc/server/dist/observable-ade1bad8.js";
|
|
2
|
+
import { getGlobalStore as f } from "./store.js";
|
|
3
|
+
const d = (l) => {
|
|
4
|
+
const c = f.getState().addValidationError;
|
|
5
|
+
return () => (b) => ({ next: s, op: n }) => u(
|
|
6
|
+
(a) => s(n).subscribe({
|
|
7
|
+
next(t) {
|
|
8
|
+
a.next(t);
|
|
9
9
|
},
|
|
10
|
-
error(
|
|
10
|
+
error(t) {
|
|
11
11
|
try {
|
|
12
|
-
const
|
|
13
|
-
Array.isArray(
|
|
14
|
-
(
|
|
15
|
-
const
|
|
16
|
-
|
|
12
|
+
const o = JSON.parse(t.message);
|
|
13
|
+
l?.log && console.log("errorObject", o), Array.isArray(o) ? o.forEach(
|
|
14
|
+
(r) => {
|
|
15
|
+
const e = `${n.path}.${r.path.join(".")}`;
|
|
16
|
+
l?.log && console.log("fullpath 1", e), c(e, r.message);
|
|
17
17
|
}
|
|
18
|
-
) : typeof
|
|
19
|
-
const
|
|
20
|
-
|
|
18
|
+
) : typeof o == "object" && o !== null && Object.entries(o).forEach(([r, e]) => {
|
|
19
|
+
const i = `${n.path}.${r}`;
|
|
20
|
+
l?.log && console.log("fullpath 2", i), c(i, e);
|
|
21
21
|
});
|
|
22
22
|
} catch {
|
|
23
23
|
}
|
|
24
|
-
a.error(
|
|
24
|
+
a.error(t);
|
|
25
25
|
},
|
|
26
26
|
complete() {
|
|
27
27
|
a.complete();
|
|
@@ -30,6 +30,6 @@ const m = () => {
|
|
|
30
30
|
);
|
|
31
31
|
};
|
|
32
32
|
export {
|
|
33
|
-
|
|
33
|
+
d as useCogsTrpcValidationLink
|
|
34
34
|
};
|
|
35
35
|
//# sourceMappingURL=TRPCValidationLink.js.map
|
|
@@ -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 =
|
|
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 = <\r\n TRouter extends AnyRouter,\r\n>(passedOpts?: {\r\n log?: boolean;\r\n}) => {\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 try {\r\n const errorObject = JSON.parse(err.message);\r\n if (passedOpts?.log) {\r\n console.log(\"errorObject\", 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 if (passedOpts?.log) {\r\n console.log(\"fullpath 1\", fullpath);\r\n }\r\n addValidationError(fullpath, error.message);\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 if (passedOpts?.log) {\r\n console.log(\"fullpath 2\", fullpath);\r\n }\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","passedOpts","addValidationError","getGlobalStore","opts","next","op","observable","observer","value","err","errorObject","error","fullpath","key"],"mappings":";;AAOa,MAAAA,IAA4B,CAEvCC,MAEI;AACE,QAAAC,IAAqBC,EAAe,SAAA,EAAW;AAwD9C,SAtDoB,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;AAC/B,YAAA;AACF,gBAAMC,IAAc,KAAK,MAAMD,EAAI,OAAO;AAC1C,UAAIT,GAAY,OACN,QAAA,IAAI,eAAeU,CAAW,GAEpC,MAAM,QAAQA,CAAW,IACfA,EAAA;AAAA,YACV,CAACC,MAA+C;AACxC,oBAAAC,IAAW,GAAGP,EAAG,IAAI,IAAIM,EAAM,KAAK,KAAK,GAAG,CAAC;AAEnD,cAAIX,GAAY,OACN,QAAA,IAAI,cAAcY,CAAQ,GAEjBX,EAAAW,GAAUD,EAAM,OAAO;AAAA,YAAA;AAAA,UAE9C,IAEA,OAAOD,KAAgB,YACvBA,MAAgB,QAET,OAAA,QAAQA,CAAW,EAAE,QAAQ,CAAC,CAACG,GAAKL,CAAK,MAAM;AACpD,kBAAMI,IAAW,GAAGP,EAAG,IAAI,IAAIQ,CAAG;AAClC,YAAIb,GAAY,OACN,QAAA,IAAI,cAAcY,CAAQ,GAEpCX,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;"}
|