cogsbox-state 0.5.20 → 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.
@@ -0,0 +1,46 @@
1
+ import { o as d } from "./node_modules/@trpc/server/dist/observable-ade1bad8.js";
2
+ import { getGlobalStore as i } from "./store.js";
3
+ const m = () => {
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
+ },
10
+ error(o) {
11
+ console.log("link error1", o);
12
+ try {
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
27
+ );
28
+ }
29
+ ) : typeof t == "object" && t !== null && Object.entries(t).forEach(([r, e]) => {
30
+ const c = `${a.path}.${r}`;
31
+ s(c, e);
32
+ });
33
+ } catch {
34
+ }
35
+ n.error(o);
36
+ },
37
+ complete() {
38
+ n.complete();
39
+ }
40
+ })
41
+ );
42
+ };
43
+ export {
44
+ m as useCogsTrpcValidationLink
45
+ };
46
+ //# sourceMappingURL=TRPCValidationLink.js.map
@@ -0,0 +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 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;"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './CogsState.js';
2
2
  export * from './CogsStateClient.js';
3
3
  export * from './utility.js';
4
+ export * from './TRPCValidationLink.js';
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
- import { $cogsSignal as r, $cogsSignalStore as o, addStateOptions as n, createCogsState as s, notifyComponent as a, useCogsStateFn as g } from "./CogsState.jsx";
2
- import { config as i, useCogsConfig as c } from "./CogsStateClient.jsx";
3
- import { debounce as d, deleteNestedProperty as u, getArrayLengthDifferences as y, getArrayLengthDifferencesArray as S, getDifferences as l, getDifferencesArray as m, getNestedValue as A, isArray as C, isDeepEqual as D, isFunction as x, isObject as F, transformStateFunc as N, updateNestedProperty as b } from "./utility.js";
1
+ import { $cogsSignal as r, $cogsSignalStore as o, addStateOptions as n, createCogsState as s, notifyComponent as a, useCogsStateFn as i } from "./CogsState.jsx";
2
+ import { config as f, useCogsConfig as c } from "./CogsStateClient.jsx";
3
+ import { debounce as d, deleteNestedProperty as u, getArrayLengthDifferences as y, getArrayLengthDifferencesArray as S, getDifferences as l, getDifferencesArray as m, getNestedValue as C, isArray as A, isDeepEqual as D, isFunction as x, isObject as F, transformStateFunc as L, updateNestedProperty as N } from "./utility.js";
4
+ import { useCogsTrpcValidationLink as h } from "./TRPCValidationLink.js";
4
5
  export {
5
6
  r as $cogsSignal,
6
7
  o as $cogsSignalStore,
7
8
  n as addStateOptions,
8
- i as config,
9
+ f as config,
9
10
  s as createCogsState,
10
11
  d as debounce,
11
12
  u as deleteNestedProperty,
@@ -13,15 +14,16 @@ export {
13
14
  S as getArrayLengthDifferencesArray,
14
15
  l as getDifferences,
15
16
  m as getDifferencesArray,
16
- A as getNestedValue,
17
- C as isArray,
17
+ C as getNestedValue,
18
+ A as isArray,
18
19
  D as isDeepEqual,
19
20
  x as isFunction,
20
21
  F as isObject,
21
22
  a as notifyComponent,
22
- N as transformStateFunc,
23
- b as updateNestedProperty,
23
+ L as transformStateFunc,
24
+ N as updateNestedProperty,
24
25
  c as useCogsConfig,
25
- g as useCogsStateFn
26
+ i as useCogsStateFn,
27
+ h as useCogsTrpcValidationLink
26
28
  };
27
29
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
@@ -0,0 +1,43 @@
1
+ function c(e) {
2
+ return e;
3
+ }
4
+ function s(e) {
5
+ return e.length === 0 ? c : e.length === 1 ? e[0] : function(t) {
6
+ return e.reduce((r, n) => n(r), t);
7
+ };
8
+ }
9
+ function p(e) {
10
+ const i = {
11
+ subscribe(t) {
12
+ let r = null, n = !1, l = !1, o = !1;
13
+ function u() {
14
+ if (r === null) {
15
+ o = !0;
16
+ return;
17
+ }
18
+ l || (l = !0, typeof r == "function" ? r() : r && r.unsubscribe());
19
+ }
20
+ return r = e({
21
+ next(f) {
22
+ n || t.next?.(f);
23
+ },
24
+ error(f) {
25
+ n || (n = !0, t.error?.(f), u());
26
+ },
27
+ complete() {
28
+ n || (n = !0, t.complete?.(), u());
29
+ }
30
+ }), o && u(), {
31
+ unsubscribe: u
32
+ };
33
+ },
34
+ pipe(...t) {
35
+ return s(t)(i);
36
+ }
37
+ };
38
+ return i;
39
+ }
40
+ export {
41
+ p as o
42
+ };
43
+ //# sourceMappingURL=observable-ade1bad8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observable-ade1bad8.js","sources":["../../../../../node_modules/@trpc/server/dist/observable-ade1bad8.mjs"],"sourcesContent":["function identity(x) {\n return x;\n}\n\n/** @internal */ function pipeFromArray(fns) {\n if (fns.length === 0) {\n return identity;\n }\n if (fns.length === 1) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return fns[0];\n }\n return function piped(input) {\n return fns.reduce((prev, fn)=>fn(prev), input);\n };\n}\n\nfunction isObservable(x) {\n return typeof x === 'object' && x !== null && 'subscribe' in x;\n}\nfunction observable(subscribe) {\n const self = {\n subscribe (observer) {\n let teardownRef = null;\n let isDone = false;\n let unsubscribed = false;\n let teardownImmediately = false;\n function unsubscribe() {\n if (teardownRef === null) {\n teardownImmediately = true;\n return;\n }\n if (unsubscribed) {\n return;\n }\n unsubscribed = true;\n if (typeof teardownRef === 'function') {\n teardownRef();\n } else if (teardownRef) {\n teardownRef.unsubscribe();\n }\n }\n teardownRef = subscribe({\n next (value) {\n if (isDone) {\n return;\n }\n observer.next?.(value);\n },\n error (err) {\n if (isDone) {\n return;\n }\n isDone = true;\n observer.error?.(err);\n unsubscribe();\n },\n complete () {\n if (isDone) {\n return;\n }\n isDone = true;\n observer.complete?.();\n unsubscribe();\n }\n });\n if (teardownImmediately) {\n unsubscribe();\n }\n return {\n unsubscribe\n };\n },\n pipe (...operations) {\n return pipeFromArray(operations)(self);\n }\n };\n return self;\n}\n\nexport { isObservable as i, observable as o };\n"],"names":["identity","x","pipeFromArray","fns","input","prev","fn","observable","subscribe","self","observer","teardownRef","isDone","unsubscribed","teardownImmediately","unsubscribe","value","err","operations"],"mappings":"AAAA,SAASA,EAASC,GAAG;AACjB,SAAOA;AACX;AAEiB,SAASC,EAAcC,GAAK;AACzC,SAAIA,EAAI,WAAW,IACRH,IAEPG,EAAI,WAAW,IAERA,EAAI,CAAC,IAET,SAAeC,GAAO;AACzB,WAAOD,EAAI,OAAO,CAACE,GAAMC,MAAKA,EAAGD,CAAI,GAAGD,CAAK;AAAA,EAChD;AACL;AAKA,SAASG,EAAWC,GAAW;AAC3B,QAAMC,IAAO;AAAA,IACT,UAAWC,GAAU;AACjB,UAAIC,IAAc,MACdC,IAAS,IACTC,IAAe,IACfC,IAAsB;AAC1B,eAASC,IAAc;AACnB,YAAIJ,MAAgB,MAAM;AACtB,UAAAG,IAAsB;AACtB;AAAA,QACpB;AACgB,QAAID,MAGJA,IAAe,IACX,OAAOF,KAAgB,aACvBA,EAAa,IACNA,KACPA,EAAY,YAAa;AAAA,MAE7C;AACY,aAAAA,IAAcH,EAAU;AAAA,QACpB,KAAMQ,GAAO;AACT,UAAIJ,KAGJF,EAAS,OAAOM,CAAK;AAAA,QACxB;AAAA,QACD,MAAOC,GAAK;AACR,UAAIL,MAGJA,IAAS,IACTF,EAAS,QAAQO,CAAG,GACpBF,EAAa;AAAA,QAChB;AAAA,QACD,WAAY;AACR,UAAIH,MAGJA,IAAS,IACTF,EAAS,WAAY,GACrBK,EAAa;AAAA,QACjC;AAAA,MACA,CAAa,GACGD,KACAC,EAAa,GAEV;AAAA,QACH,aAAAA;AAAA,MACH;AAAA,IACJ;AAAA,IACD,QAASG,GAAY;AACjB,aAAOhB,EAAcgB,CAAU,EAAET,CAAI;AAAA,IACjD;AAAA,EACK;AACD,SAAOA;AACX;","x_google_ignoreList":[0]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogsbox-state",
3
- "version": "0.5.20",
3
+ "version": "0.5.22",
4
4
  "description": "React state management library with form controls and server sync",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",