atomaric 0.0.36 → 0.0.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/build/atomaric.js +71 -70
- package/build/atomaric.umd.cjs +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +4 -3
- package/types/paths.ts +67 -12
package/build/atomaric.js
CHANGED
|
@@ -4,22 +4,22 @@ let M = () => {
|
|
|
4
4
|
const $ = {}, v = (e) => {
|
|
5
5
|
$.useSyncExternalStore = M = e.useSyncExternalStore, $.keyPathSeparator = e.keyPathSeparator;
|
|
6
6
|
}, B = (e) => M(e.subscribe, e.get), G = (e) => e.set, K = (e) => e.setDeferred, O = (e) => e.get, ee = (e) => e.do, te = (e) => [B(e), G(e)], se = (e, r) => new q(e, r), U = (e, r, i) => {
|
|
7
|
-
let
|
|
8
|
-
typeof e == "number" ?
|
|
7
|
+
let h = null;
|
|
8
|
+
typeof e == "number" ? h = j(
|
|
9
9
|
r,
|
|
10
10
|
(s) => ({
|
|
11
11
|
increment: (n) => {
|
|
12
12
|
s.set(+s.get() + (n ?? 0));
|
|
13
13
|
}
|
|
14
14
|
})
|
|
15
|
-
) : typeof e == "boolean" ?
|
|
15
|
+
) : typeof e == "boolean" ? h = j(
|
|
16
16
|
r,
|
|
17
17
|
(s) => ({
|
|
18
18
|
toggle: () => {
|
|
19
19
|
s.set(!s.get());
|
|
20
20
|
}
|
|
21
21
|
})
|
|
22
|
-
) : Array.isArray(e) ?
|
|
22
|
+
) : Array.isArray(e) ? h = j(
|
|
23
23
|
r,
|
|
24
24
|
(s) => ({
|
|
25
25
|
push: (...n) => {
|
|
@@ -36,11 +36,11 @@ const $ = {}, v = (e) => {
|
|
|
36
36
|
s.set(s.get().filter(n ?? W));
|
|
37
37
|
},
|
|
38
38
|
toggle: (n, c) => {
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const p = s.get().slice(), a = p.indexOf(n);
|
|
40
|
+
a < 0 ? c ? p.unshift(n) : p.push(n) : p.splice(a, 1), s.set(p);
|
|
41
41
|
}
|
|
42
42
|
})
|
|
43
|
-
) : e instanceof Set ?
|
|
43
|
+
) : e instanceof Set ? h = j(
|
|
44
44
|
r,
|
|
45
45
|
(s) => ({
|
|
46
46
|
add: (n) => {
|
|
@@ -62,7 +62,7 @@ const $ = {}, v = (e) => {
|
|
|
62
62
|
n(c), s.set(c);
|
|
63
63
|
}
|
|
64
64
|
})
|
|
65
|
-
) : e instanceof Object && (
|
|
65
|
+
) : e instanceof Object && (h = j(
|
|
66
66
|
r,
|
|
67
67
|
(s) => ({
|
|
68
68
|
setPartial: (n) => s.set((c) => ({
|
|
@@ -73,143 +73,144 @@ const $ = {}, v = (e) => {
|
|
|
73
73
|
const c = { ...s.get() };
|
|
74
74
|
n(c), s.set(c);
|
|
75
75
|
},
|
|
76
|
-
setDeepPartial: (n, c,
|
|
77
|
-
if (n.includes(
|
|
78
|
-
let
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
let
|
|
83
|
-
for (const
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
setDeepPartial: (n, c, p, a = $.keyPathSeparator ?? ".") => {
|
|
77
|
+
if (n.includes(a)) {
|
|
78
|
+
let d = n.split(a);
|
|
79
|
+
const T = d[d.length - 1];
|
|
80
|
+
d = d.slice(0, -1);
|
|
81
|
+
const b = { ...s.get() };
|
|
82
|
+
let g = b, x = p;
|
|
83
|
+
for (const w of d) {
|
|
84
|
+
let f = g[w];
|
|
85
|
+
const _ = x = x == null ? void 0 : x[Array.isArray(x) ? "0" : w];
|
|
86
|
+
if (f == null && (f = Array.isArray(_) ? [] : {}), f == null || typeof f != "object") {
|
|
86
87
|
s.do.setPartial({ [n]: typeof c == "function" ? c(void 0) : c });
|
|
87
88
|
return;
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
+
g = g[w] = Array.isArray(f) ? [...f] : { ...f };
|
|
90
91
|
}
|
|
91
|
-
|
|
92
|
+
g[T] = typeof c == "function" ? c(g[T]) : c, s.set(b);
|
|
92
93
|
} else s.do.setPartial({ [n]: c });
|
|
93
94
|
}
|
|
94
95
|
})
|
|
95
96
|
));
|
|
96
|
-
const
|
|
97
|
+
const S = typeof i == "object" && i != null && "do" in i ? i.do(
|
|
97
98
|
(s, n) => r.set(s, n),
|
|
98
99
|
() => r.get(),
|
|
99
100
|
r,
|
|
100
101
|
(s, n, c) => r.setDeferred(s, n, c)
|
|
101
|
-
) : null,
|
|
102
|
-
return
|
|
103
|
-
(s) => Object.defineProperty(
|
|
104
|
-
),
|
|
105
|
-
}, W = (e) => e,
|
|
102
|
+
) : null, A = {};
|
|
103
|
+
return S && Object.keys(S).forEach((s) => Object.defineProperty(A, s, { get: () => S[s] })), h && Object.keys(h).forEach(
|
|
104
|
+
(s) => Object.defineProperty(A, s, { get: () => h[s] })
|
|
105
|
+
), A;
|
|
106
|
+
}, W = (e) => e, j = (e, r, i) => r(e);
|
|
106
107
|
class q {
|
|
107
108
|
constructor(r, i) {
|
|
108
|
-
const
|
|
109
|
-
let n = r, c,
|
|
110
|
-
},
|
|
111
|
-
const t = U(r,
|
|
112
|
-
return
|
|
109
|
+
const h = (t) => n = t, S = () => n, A = /* @__PURE__ */ new Set(), s = (t) => t(a());
|
|
110
|
+
let n = r, c, p = () => {
|
|
111
|
+
}, a = () => S(), d = null, T = () => {
|
|
112
|
+
const t = U(r, b, i);
|
|
113
|
+
return T = () => t, t;
|
|
113
114
|
};
|
|
114
|
-
const
|
|
115
|
-
get: (t, u) => u === "do" ?
|
|
115
|
+
const b = new Proxy(this, {
|
|
116
|
+
get: (t, u) => u === "do" ? T() : t[u],
|
|
116
117
|
set: Q
|
|
117
|
-
}),
|
|
118
|
-
const
|
|
119
|
-
if (!(
|
|
120
|
-
|
|
118
|
+
}), g = (t, u) => {
|
|
119
|
+
const y = typeof t == "function" ? t(a()) : t;
|
|
120
|
+
if (!(y === a() || y === void 0 || typeof y == "number" && isNaN(y))) {
|
|
121
|
+
h(y), A.forEach(s, this);
|
|
121
122
|
try {
|
|
122
|
-
N.postMessage({ key: l, value:
|
|
123
|
+
N.postMessage({ key: l, value: S() });
|
|
123
124
|
} catch {
|
|
124
125
|
}
|
|
125
|
-
u !== !0 &&
|
|
126
|
+
u !== !0 && p(y);
|
|
126
127
|
}
|
|
127
128
|
};
|
|
128
|
-
this.set = (t, u) =>
|
|
129
|
-
|
|
129
|
+
this.set = (t, u) => g(t, u), this.get = () => a(), this.initialValue = r, this.isInitialValue = () => r === S(), this.subscribe = (t) => (A.add(t), () => {
|
|
130
|
+
A.delete(t);
|
|
130
131
|
}), this.reset = () => {
|
|
131
|
-
|
|
132
|
+
g(r, !0), A.forEach(s, this);
|
|
132
133
|
};
|
|
133
|
-
const
|
|
134
|
-
|
|
134
|
+
const x = (t, u) => {
|
|
135
|
+
g(t, u), c = void 0;
|
|
135
136
|
};
|
|
136
|
-
if (this.setDeferred = (t, u = 500,
|
|
137
|
-
L && c === void 0 &&
|
|
138
|
-
}, i == null) return
|
|
139
|
-
let
|
|
137
|
+
if (this.setDeferred = (t, u = 500, y, L = !0) => {
|
|
138
|
+
L && c === void 0 && g(t, y), clearTimeout(c), c = setTimeout(x, u, t, y);
|
|
139
|
+
}, i == null) return b;
|
|
140
|
+
let w = null, f = null, _ = !0, E = !0, P = !1, V = -1, C = r instanceof Set ? (t) => new Set(t) : (t) => t, m = r instanceof Set ? (t) => {
|
|
140
141
|
if (t instanceof Set) return Array.from(t);
|
|
141
142
|
throw console.error(t), "The value is not Set instance";
|
|
142
143
|
} : (t) => t;
|
|
143
144
|
if (typeof i == "string")
|
|
144
|
-
|
|
145
|
+
w = i;
|
|
145
146
|
else if ("storeKey" in i)
|
|
146
|
-
|
|
147
|
-
else return
|
|
148
|
-
const l = `${R}${
|
|
147
|
+
_ = i.warnOnDuplicateStoreKey ?? _, E = i.listenStorageChanges ?? E, w = i.storeKey, C = i.unzipValue ?? C, m = i.zipValue ?? m, P = i.unchangable ?? P, f = i.exp ?? f;
|
|
148
|
+
else return b;
|
|
149
|
+
const l = `${R}${w}`, F = f === null || !(f(b, l in o) instanceof Date) ? (t) => JSON.stringify([m(t)]) : (t) => (d ?? (d = {}), d.exp = f(b, l in o).getTime() + 0.2866, d.exp - Date.now() < 24 * 60 * 60 * 1e3 && (clearTimeout(V), clearTimeout(k[l]), V = setTimeout(() => this.reset(), d.exp - Date.now())), JSON.stringify([m(t), d])), J = (t) => {
|
|
149
150
|
const u = JSON.parse(t);
|
|
150
|
-
return
|
|
151
|
+
return d = u[1], C(u[0]);
|
|
151
152
|
};
|
|
152
153
|
let H = !0;
|
|
153
|
-
if (z[l] =
|
|
154
|
-
if (
|
|
154
|
+
if (z[l] = b, o[`atom/${w}`] && (o[l] || (o[l] = `[${o[`atom/${w}`]}]`), delete o[`atom/${w}`]), a = () => {
|
|
155
|
+
if (a = S, H) {
|
|
155
156
|
H = !1;
|
|
156
157
|
try {
|
|
157
|
-
|
|
158
|
+
h(l in o ? J(o[l]) : r);
|
|
158
159
|
} catch {
|
|
159
160
|
console.warn("Invalid json value", o[l]);
|
|
160
161
|
}
|
|
161
162
|
}
|
|
162
|
-
return
|
|
163
|
-
},
|
|
163
|
+
return S();
|
|
164
|
+
}, p = (t) => {
|
|
164
165
|
if (t === r) {
|
|
165
166
|
this.reset();
|
|
166
167
|
return;
|
|
167
168
|
}
|
|
168
169
|
o[l] = F(t);
|
|
169
170
|
}, this.reset = () => {
|
|
170
|
-
delete o[l],
|
|
171
|
-
},
|
|
171
|
+
delete o[l], g(r, !0);
|
|
172
|
+
}, _ && D[l] !== void 0 && console.warn("Duplicate Atom key", w), E)
|
|
172
173
|
if (P) {
|
|
173
174
|
let t = !1, u;
|
|
174
|
-
|
|
175
|
-
clearTimeout(u), u = setTimeout(() => t = !1, 10), !t && (t = !0, o[l] = F(
|
|
175
|
+
I[l] = this, D[l] = () => {
|
|
176
|
+
clearTimeout(u), u = setTimeout(() => t = !1, 10), !t && (t = !0, o[l] = F(S()));
|
|
176
177
|
};
|
|
177
178
|
} else
|
|
178
|
-
|
|
179
|
+
D[l] = (t) => {
|
|
179
180
|
if (t.newValue === null) {
|
|
180
181
|
this.reset();
|
|
181
182
|
return;
|
|
182
183
|
}
|
|
183
184
|
try {
|
|
184
|
-
|
|
185
|
+
g(J(t.newValue));
|
|
185
186
|
} catch {
|
|
186
187
|
console.warn("Invalid json value", t.newValue);
|
|
187
188
|
}
|
|
188
189
|
};
|
|
189
|
-
return
|
|
190
|
+
return b;
|
|
190
191
|
}
|
|
191
192
|
}
|
|
192
193
|
let N;
|
|
193
194
|
try {
|
|
194
195
|
N = new BroadcastChannel("updateHere"), N.addEventListener("message", (e) => {
|
|
195
196
|
var r;
|
|
196
|
-
(r =
|
|
197
|
+
(r = I[e.data.key]) == null || r.set(e.data.value, !0);
|
|
197
198
|
});
|
|
198
199
|
} catch {
|
|
199
200
|
}
|
|
200
|
-
const o = window.localStorage,
|
|
201
|
+
const o = window.localStorage, D = {}, I = {}, Q = (e, r) => {
|
|
201
202
|
throw `${r} is readonly property`;
|
|
202
203
|
};
|
|
203
204
|
window.addEventListener("storage", (e) => {
|
|
204
205
|
var r;
|
|
205
|
-
e.key === null || e.newValue === e.oldValue || (r =
|
|
206
|
+
e.key === null || e.newValue === e.oldValue || (r = D[e.key]) == null || r.call(D, e);
|
|
206
207
|
});
|
|
207
208
|
const X = o.setItem.bind(o), Y = o.removeItem.bind(o);
|
|
208
209
|
o.setItem = (e, r) => {
|
|
209
|
-
|
|
210
|
+
I[e] === void 0 && X.call(o, e, r);
|
|
210
211
|
};
|
|
211
212
|
o.removeItem = (e) => {
|
|
212
|
-
|
|
213
|
+
I[e] === void 0 && Y.call(o, e);
|
|
213
214
|
};
|
|
214
215
|
const Z = /"exp":(\d+)\.2866/, R = "atom\\", z = {}, k = {};
|
|
215
216
|
setTimeout(() => {
|
package/build/atomaric.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(f,
|
|
1
|
+
(function(f,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(f=typeof globalThis<"u"?globalThis:f||self,D(f.atomaric={}))})(this,function(f){"use strict";let D=()=>{throw"call configureAtomaric() before all!"};const P={},q=e=>{P.useSyncExternalStore=D=e.useSyncExternalStore,P.keyPathSeparator=e.keyPathSeparator},J=e=>D(e.subscribe,e.get),M=e=>e.set,Q=e=>e.setDeferred,X=e=>e.get,Y=e=>e.do,Z=e=>[J(e),M(e)],v=(e,r)=>new G(e,r),K=(e,r,i)=>{let S=null;typeof e=="number"?S=_(r,n=>({increment:s=>{n.set(+n.get()+(s??0))}})):typeof e=="boolean"?S=_(r,n=>({toggle:()=>{n.set(!n.get())}})):Array.isArray(e)?S=_(r,n=>({push:(...s)=>{n.set(n.get().concat(s))},unshift:(...s)=>{n.set(s.concat(n.get()))},update:s=>{const c=n.get().slice();s(c),n.set(c)},filter:s=>{n.set(n.get().filter(s??O))},toggle:(s,c)=>{const y=n.get().slice(),d=y.indexOf(s);d<0?c?y.unshift(s):y.push(s):y.splice(d,1),n.set(y)}})):e instanceof Set?S=_(r,n=>({add:s=>{n.set(new Set(n.get()).add(s))},delete:s=>{const c=new Set(n.get());c.delete(s),n.set(c)},toggle:s=>{const c=new Set(n.get());c.has(s)?c.delete(s):c.add(s),n.set(c)},clear:()=>{n.set(new Set)},update:s=>{const c=new Set(n.get());s(c),n.set(c)}})):e instanceof Object&&(S=_(r,n=>({setPartial:s=>n.set(c=>({...c,...typeof s=="function"?s(n.get()):s})),update:s=>{const c={...n.get()};s(c),n.set(c)},setDeepPartial:(s,c,y,d=P.keyPathSeparator??".")=>{if(s.includes(d)){let g=s.split(d);const I=g[g.length-1];g=g.slice(0,-1);const b={...n.get()};let h=b,T=y;for(const w of g){let a=h[w];const E=T=T==null?void 0:T[Array.isArray(T)?"0":w];if(a==null&&(a=Array.isArray(E)?[]:{}),a==null||typeof a!="object"){n.do.setPartial({[s]:typeof c=="function"?c(void 0):c});return}h=h[w]=Array.isArray(a)?[...a]:{...a}}h[I]=typeof c=="function"?c(h[I]):c,n.set(b)}else n.do.setPartial({[s]:c})}})));const A=typeof i=="object"&&i!=null&&"do"in i?i.do((n,s)=>r.set(n,s),()=>r.get(),r,(n,s,c)=>r.setDeferred(n,s,c)):null,m={};return A&&Object.keys(A).forEach(n=>Object.defineProperty(m,n,{get:()=>A[n]})),S&&Object.keys(S).forEach(n=>Object.defineProperty(m,n,{get:()=>S[n]})),m},O=e=>e,_=(e,r,i)=>r(e);class G{constructor(r,i){const S=t=>s=t,A=()=>s,m=new Set,n=t=>t(d());let s=r,c,y=()=>{},d=()=>A(),g=null,I=()=>{const t=K(r,b,i);return I=()=>t,t};const b=new Proxy(this,{get:(t,u)=>u==="do"?I():t[u],set:ee}),h=(t,u)=>{const p=typeof t=="function"?t(d()):t;if(!(p===d()||p===void 0||typeof p=="number"&&isNaN(p))){S(p),m.forEach(n,this);try{$.postMessage({key:l,value:A()})}catch{}u!==!0&&y(p)}};this.set=(t,u)=>h(t,u),this.get=()=>d(),this.initialValue=r,this.isInitialValue=()=>r===A(),this.subscribe=t=>(m.add(t),()=>{m.delete(t)}),this.reset=()=>{h(r,!0),m.forEach(n,this)};const T=(t,u)=>{h(t,u),c=void 0};if(this.setDeferred=(t,u=500,p,W=!0)=>{W&&c===void 0&&h(t,p),clearTimeout(c),c=setTimeout(T,u,t,p)},i==null)return b;let w=null,a=null,E=!0,V=!0,z=!1,R=-1,F=r instanceof Set?t=>new Set(t):t=>t,C=r instanceof Set?t=>{if(t instanceof Set)return Array.from(t);throw console.error(t),"The value is not Set instance"}:t=>t;if(typeof i=="string")w=i;else if("storeKey"in i)E=i.warnOnDuplicateStoreKey??E,V=i.listenStorageChanges??V,w=i.storeKey,F=i.unzipValue??F,C=i.zipValue??C,z=i.unchangable??z,a=i.exp??a;else return b;const l=`${H}${w}`,k=a===null||!(a(b,l in o)instanceof Date)?t=>JSON.stringify([C(t)]):t=>(g??(g={}),g.exp=a(b,l in o).getTime()+.2866,g.exp-Date.now()<24*60*60*1e3&&(clearTimeout(R),clearTimeout(L[l]),R=setTimeout(()=>this.reset(),g.exp-Date.now())),JSON.stringify([C(t),g])),B=t=>{const u=JSON.parse(t);return g=u[1],F(u[0])};let U=!0;if(N[l]=b,o[`atom/${w}`]&&(o[l]||(o[l]=`[${o[`atom/${w}`]}]`),delete o[`atom/${w}`]),d=()=>{if(d=A,U){U=!1;try{S(l in o?B(o[l]):r)}catch{console.warn("Invalid json value",o[l])}}return A()},y=t=>{if(t===r){this.reset();return}o[l]=k(t)},this.reset=()=>{delete o[l],h(r,!0)},E&&j[l]!==void 0&&console.warn("Duplicate Atom key",w),V)if(z){let t=!1,u;x[l]=this,j[l]=()=>{clearTimeout(u),u=setTimeout(()=>t=!1,10),!t&&(t=!0,o[l]=k(A()))}}else j[l]=t=>{if(t.newValue===null){this.reset();return}try{h(B(t.newValue))}catch{console.warn("Invalid json value",t.newValue)}};return b}}let $;try{$=new BroadcastChannel("updateHere"),$.addEventListener("message",e=>{var r;(r=x[e.data.key])==null||r.set(e.data.value,!0)})}catch{}const o=window.localStorage,j={},x={},ee=(e,r)=>{throw`${r} is readonly property`};window.addEventListener("storage",e=>{var r;e.key===null||e.newValue===e.oldValue||(r=j[e.key])==null||r.call(j,e)});const te=o.setItem.bind(o),ne=o.removeItem.bind(o);o.setItem=(e,r)=>{x[e]===void 0&&te.call(o,e,r)},o.removeItem=e=>{x[e]===void 0&&ne.call(o,e)};const se=/"exp":(\d+)\.2866/,H="atom\\",N={},L={};setTimeout(()=>{Object.keys(o).forEach(e=>{var i;if(!e.startsWith(H)||typeof o[e]!="string")return;const r=+((i=o[e].match(se))==null?void 0:i[1]);r&&r-Date.now()<24*60*60*1e3&&(L[e]=setTimeout(()=>{N[e]?N[e].reset():delete o[e]},r-Date.now()))})},1e3),f.Atom=G,f.atom=v,f.configureAtomaric=q,f.configuredOptions=P,f.useAtom=Z,f.useAtomDo=Y,f.useAtomGet=X,f.useAtomSet=M,f.useAtomSetDeferred=Q,f.useAtomValue=J,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSyncExternalStore } from 'react';
|
|
2
|
-
import { Path,
|
|
2
|
+
import { Path, PathValue, PathValueDonor } from './paths';
|
|
3
3
|
|
|
4
4
|
export interface Register {}
|
|
5
5
|
|
|
@@ -68,11 +68,12 @@ export type ObjectActions<Value> = UpdateAction<Value> & {
|
|
|
68
68
|
/** pass partial value to update some deep values by flat path */
|
|
69
69
|
setDeepPartial: <
|
|
70
70
|
ValuePath extends Path<Value, Sep>,
|
|
71
|
-
Val extends
|
|
71
|
+
Val extends PathValue<Value, Sep, ValuePath>,
|
|
72
72
|
Sep extends string = ObjectActionsSetDeepPartial,
|
|
73
73
|
>(
|
|
74
74
|
path: ValuePath,
|
|
75
|
-
value:
|
|
75
|
+
value: Val | ((value: Val) => Val),
|
|
76
|
+
donor: PathValueDonor<Value, Sep, ValuePath> | null,
|
|
76
77
|
separator?: Sep,
|
|
77
78
|
) => void;
|
|
78
79
|
};
|
package/types/paths.ts
CHANGED
|
@@ -30,18 +30,6 @@ type PathImpl<K extends string | number, Sep extends string, V, TraversedTypes>
|
|
|
30
30
|
? `${K}`
|
|
31
31
|
: `${K}` | `${K}${Sep}${PathInternal<V, Sep, TraversedTypes | V>}`;
|
|
32
32
|
|
|
33
|
-
type ArrayKey = number;
|
|
34
|
-
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
35
|
-
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
36
|
-
type BrowserNativeObject = Date | FileList | File;
|
|
37
|
-
|
|
38
|
-
type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
|
|
39
|
-
type IsEqual<T1, T2> = T1 extends T2
|
|
40
|
-
? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2
|
|
41
|
-
? true
|
|
42
|
-
: false
|
|
43
|
-
: false;
|
|
44
|
-
|
|
45
33
|
////////////////////////////////////////////////////////////////////////////
|
|
46
34
|
////////////////////////////////////////////////////////////////////////////
|
|
47
35
|
////////////////////////////////////////////////////////////////////////////
|
|
@@ -76,6 +64,73 @@ type TPathValue<T, Sep extends string, P extends Path<T, Sep> | ArrayPath<T, Sep
|
|
|
76
64
|
: never
|
|
77
65
|
: never;
|
|
78
66
|
|
|
67
|
+
////////////////////////////////////////////////////////////////////////////
|
|
68
|
+
////////////////////////////////////////////////////////////////////////////
|
|
69
|
+
////////////////////////////////////////////////////////////////////////////
|
|
70
|
+
////////////////////////////////////////////////////////////////////////////
|
|
71
|
+
////////////////////////////////////////////////////////////////////////////
|
|
72
|
+
////////////////////////////////////////////////////////////////////////////
|
|
73
|
+
////////////////////////////////////////////////////////////////////////////
|
|
74
|
+
////////////////////////////////////////////////////////////////////////////
|
|
75
|
+
////////////////////////////////////////////////////////////////////////////
|
|
76
|
+
////////////////////////////////////////////////////////////////////////////
|
|
77
|
+
////////////////////////////////////////////////////////////////////////////
|
|
78
|
+
////////////////////////////////////////////////////////////////////////////
|
|
79
|
+
////////////////////////////////////////////////////////////////////////////
|
|
80
|
+
|
|
81
|
+
export type PathValueDonor<
|
|
82
|
+
Value,
|
|
83
|
+
Sep extends string,
|
|
84
|
+
FullPath extends Path<Value, Sep> | ArrayPath<Value, Sep>,
|
|
85
|
+
> = Value extends any
|
|
86
|
+
? FullPath extends `${infer Key}${Sep}${infer KeyRest}`
|
|
87
|
+
? Key extends keyof Value
|
|
88
|
+
? KeyRest extends Path<Value[Key], Sep>
|
|
89
|
+
? Required<Record<Key, PathValueDonor<Value[Key], Sep, KeyRest>>>
|
|
90
|
+
: never
|
|
91
|
+
: Key extends `${ArrayKey}`
|
|
92
|
+
? Value extends ReadonlyArray<infer V>
|
|
93
|
+
? [PathValueDonor<V, Sep, KeyRest & Path<V, Sep>>]
|
|
94
|
+
: never
|
|
95
|
+
: never
|
|
96
|
+
: FullPath extends keyof Value
|
|
97
|
+
? FullPath extends `${string}${Sep}${string}${string}`
|
|
98
|
+
? Required<Record<FullPath, Value[FullPath]>>
|
|
99
|
+
: Partial<Record<string, unknown>>
|
|
100
|
+
: FullPath extends `${ArrayKey}`
|
|
101
|
+
? Value extends ReadonlyArray<infer V>
|
|
102
|
+
? FullPath extends `${string}${Sep}${string}${string}`
|
|
103
|
+
? [V]
|
|
104
|
+
: []
|
|
105
|
+
: never
|
|
106
|
+
: never
|
|
107
|
+
: never;
|
|
108
|
+
|
|
109
|
+
/////////////////////////////////////////////////////////
|
|
110
|
+
/////////////////////////////////////////////////////////
|
|
111
|
+
/////////////////////////////////////////////////////////
|
|
112
|
+
/////////////////////////////////////////////////////////
|
|
113
|
+
/////////////////////////////////////////////////////////
|
|
114
|
+
/////////////////////////////////////////////////////////
|
|
115
|
+
/////////////////////////////////////////////////////////
|
|
116
|
+
/////////////////////////////////////////////////////////
|
|
117
|
+
/////////////////////////////////////////////////////////
|
|
118
|
+
/////////////////////////////////////////////////////////
|
|
119
|
+
/////////////////////////////////////////////////////////
|
|
120
|
+
/////////////////////////////////////////////////////////
|
|
121
|
+
|
|
122
|
+
type ArrayKey = number;
|
|
123
|
+
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
124
|
+
type IsTuple<T extends ReadonlyArray<any>> = number extends T['length'] ? false : true;
|
|
125
|
+
type BrowserNativeObject = Date | FileList | File;
|
|
126
|
+
|
|
127
|
+
type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
|
|
128
|
+
type IsEqual<T1, T2> = T1 extends T2
|
|
129
|
+
? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2
|
|
130
|
+
? true
|
|
131
|
+
: false
|
|
132
|
+
: false;
|
|
133
|
+
|
|
79
134
|
type ArrayPath<T, Sep extends string> = T extends any ? ArrayPathInternal<T, Sep> : never;
|
|
80
135
|
|
|
81
136
|
type ArrayPathInternal<T, Sep extends string, TraversedTypes = T> = T extends ReadonlyArray<infer V>
|