@regle/core 0.5.1 → 0.5.3
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/README.md +0 -4
- package/dist/regle-core.browser.js +57278 -0
- package/dist/regle-core.browser.min.js +72 -0
- package/dist/regle-core.cjs +116 -113
- package/dist/regle-core.d.cts +672 -5
- package/dist/regle-core.d.ts +672 -5
- package/dist/regle-core.min.cjs +2 -2
- package/dist/regle-core.min.mjs +2 -2
- package/dist/regle-core.mjs +117 -115
- package/package.json +2 -1
package/dist/regle-core.cjs
CHANGED
|
@@ -22,6 +22,44 @@ function isEmpty(value) {
|
|
|
22
22
|
// ../shared/utils/symbol.ts
|
|
23
23
|
var RegleRuleSymbol = Symbol("regle-rule");
|
|
24
24
|
|
|
25
|
+
// ../shared/utils/cloneDeep.ts
|
|
26
|
+
function getRegExpFlags(regExp) {
|
|
27
|
+
if (typeof regExp.source.flags == "string") {
|
|
28
|
+
return regExp.source.flags;
|
|
29
|
+
} else {
|
|
30
|
+
let flags = [];
|
|
31
|
+
regExp.global && flags.push("g");
|
|
32
|
+
regExp.ignoreCase && flags.push("i");
|
|
33
|
+
regExp.multiline && flags.push("m");
|
|
34
|
+
regExp.sticky && flags.push("y");
|
|
35
|
+
regExp.unicode && flags.push("u");
|
|
36
|
+
return flags.join("");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function cloneDeep(obj) {
|
|
40
|
+
let result = obj;
|
|
41
|
+
let type = {}.toString.call(obj).slice(8, -1);
|
|
42
|
+
if (type == "Set") {
|
|
43
|
+
result = new Set([...obj].map((value) => cloneDeep(value)));
|
|
44
|
+
}
|
|
45
|
+
if (type == "Map") {
|
|
46
|
+
result = new Map([...obj].map((kv) => [cloneDeep(kv[0]), cloneDeep(kv[1])]));
|
|
47
|
+
}
|
|
48
|
+
if (type == "Date") {
|
|
49
|
+
result = new Date(obj.getTime());
|
|
50
|
+
}
|
|
51
|
+
if (type == "RegExp") {
|
|
52
|
+
result = RegExp(obj.source, getRegExpFlags(obj));
|
|
53
|
+
}
|
|
54
|
+
if (type == "Array" || type == "Object") {
|
|
55
|
+
result = Array.isArray(obj) ? [] : {};
|
|
56
|
+
for (let key in obj) {
|
|
57
|
+
result[key] = cloneDeep(obj[key]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
25
63
|
// src/types/rules/rule.internal.types.ts
|
|
26
64
|
var InternalRuleType = /* @__PURE__ */ ((InternalRuleType2) => {
|
|
27
65
|
InternalRuleType2["Inline"] = "__inline";
|
|
@@ -151,7 +189,7 @@ function createRule(definition) {
|
|
|
151
189
|
if (typeof definition.validator === "function") {
|
|
152
190
|
let fakeParams = [];
|
|
153
191
|
const staticProcessors = defineRuleProcessors(definition, ...fakeParams);
|
|
154
|
-
const isAsync = definition.validator.constructor.name === "AsyncFunction";
|
|
192
|
+
const isAsync = definition.async ?? definition.validator.constructor.name === "AsyncFunction";
|
|
155
193
|
if (getFunctionParametersLength(definition.validator) > 1) {
|
|
156
194
|
const ruleFactory = function(...params) {
|
|
157
195
|
return defineRuleProcessors(definition, ...params);
|
|
@@ -177,110 +215,6 @@ function createRule(definition) {
|
|
|
177
215
|
}
|
|
178
216
|
throw new Error("Validator must be a function");
|
|
179
217
|
}
|
|
180
|
-
function isObject(obj) {
|
|
181
|
-
if (obj instanceof Date || obj instanceof File) {
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
185
|
-
}
|
|
186
|
-
function isRefObject(obj) {
|
|
187
|
-
if (obj.value instanceof Date || obj.value instanceof File) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
return isObject(obj.value);
|
|
191
|
-
}
|
|
192
|
-
function cloneDeep(obj) {
|
|
193
|
-
let result = obj;
|
|
194
|
-
let type = {}.toString.call(obj).slice(8, -1);
|
|
195
|
-
if (type == "Set") {
|
|
196
|
-
result = new Set([...obj].map((value) => cloneDeep(value)));
|
|
197
|
-
}
|
|
198
|
-
if (type == "Map") {
|
|
199
|
-
result = new Map([...obj].map((kv) => [cloneDeep(kv[0]), cloneDeep(kv[1])]));
|
|
200
|
-
}
|
|
201
|
-
if (type == "Date") {
|
|
202
|
-
result = new Date(obj.getTime());
|
|
203
|
-
}
|
|
204
|
-
if (type == "RegExp") {
|
|
205
|
-
result = RegExp(obj.source, getRegExpFlags(obj));
|
|
206
|
-
}
|
|
207
|
-
if (type == "Array" || type == "Object") {
|
|
208
|
-
result = Array.isArray(obj) ? [] : {};
|
|
209
|
-
for (let key in obj) {
|
|
210
|
-
result[key] = cloneDeep(obj[key]);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return result;
|
|
214
|
-
}
|
|
215
|
-
function getRegExpFlags(regExp) {
|
|
216
|
-
if (typeof regExp.source.flags == "string") {
|
|
217
|
-
return regExp.source.flags;
|
|
218
|
-
} else {
|
|
219
|
-
let flags = [];
|
|
220
|
-
regExp.global && flags.push("g");
|
|
221
|
-
regExp.ignoreCase && flags.push("i");
|
|
222
|
-
regExp.multiline && flags.push("m");
|
|
223
|
-
regExp.sticky && flags.push("y");
|
|
224
|
-
regExp.unicode && flags.push("u");
|
|
225
|
-
return flags.join("");
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
function unwrapGetter(getter, value, index) {
|
|
229
|
-
const scope = vue.effectScope();
|
|
230
|
-
let unwrapped;
|
|
231
|
-
if (getter instanceof Function) {
|
|
232
|
-
unwrapped = scope.run(() => getter(value, index ?? 0));
|
|
233
|
-
} else {
|
|
234
|
-
unwrapped = getter;
|
|
235
|
-
}
|
|
236
|
-
return { scope, unwrapped };
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// src/utils/debounce.ts
|
|
240
|
-
function debounce(func, wait, immediate) {
|
|
241
|
-
let timeout;
|
|
242
|
-
const debouncedFn = (...args) => new Promise((resolve) => {
|
|
243
|
-
clearTimeout(timeout);
|
|
244
|
-
timeout = setTimeout(() => {
|
|
245
|
-
timeout = void 0;
|
|
246
|
-
{
|
|
247
|
-
Promise.resolve(func.apply(this, [...args])).then(resolve);
|
|
248
|
-
}
|
|
249
|
-
}, wait);
|
|
250
|
-
});
|
|
251
|
-
debouncedFn.cancel = () => {
|
|
252
|
-
clearTimeout(timeout);
|
|
253
|
-
timeout = void 0;
|
|
254
|
-
};
|
|
255
|
-
return debouncedFn;
|
|
256
|
-
}
|
|
257
|
-
function versionCompare(current, other) {
|
|
258
|
-
const cp = String(current).split(".");
|
|
259
|
-
const op = String(other).split(".");
|
|
260
|
-
for (let depth = 0; depth < Math.min(cp.length, op.length); depth++) {
|
|
261
|
-
const cn = Number(cp[depth]);
|
|
262
|
-
const on = Number(op[depth]);
|
|
263
|
-
if (cn > on) return 1 /* GreaterThan */;
|
|
264
|
-
if (on > cn) return -1 /* LessThan */;
|
|
265
|
-
if (!isNaN(cn) && isNaN(on)) return 1 /* GreaterThan */;
|
|
266
|
-
if (isNaN(cn) && !isNaN(on)) return -1 /* LessThan */;
|
|
267
|
-
}
|
|
268
|
-
return 0 /* EqualTo */;
|
|
269
|
-
}
|
|
270
|
-
var isVueSuperiorOrEqualTo3dotFive = versionCompare(vue.version, "3.5.0") === -1 ? false : true;
|
|
271
|
-
|
|
272
|
-
// src/utils/randomId.ts
|
|
273
|
-
function uniqueIDNuxt() {
|
|
274
|
-
return Math.floor(Math.random() * Date.now()).toString();
|
|
275
|
-
}
|
|
276
|
-
function randomId() {
|
|
277
|
-
if (typeof window === "undefined") {
|
|
278
|
-
return uniqueIDNuxt();
|
|
279
|
-
} else {
|
|
280
|
-
const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
|
|
281
|
-
return uint32.toString(10);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
218
|
function useStorage() {
|
|
285
219
|
const ruleDeclStorage = vue.shallowRef(/* @__PURE__ */ new Map());
|
|
286
220
|
const fieldsStorage = vue.shallowRef(/* @__PURE__ */ new Map());
|
|
@@ -400,6 +334,74 @@ function useStorage() {
|
|
|
400
334
|
arrayStatusStorage
|
|
401
335
|
};
|
|
402
336
|
}
|
|
337
|
+
function isObject(obj) {
|
|
338
|
+
if (obj instanceof Date || obj instanceof File) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
342
|
+
}
|
|
343
|
+
function isRefObject(obj) {
|
|
344
|
+
if (obj.value instanceof Date || obj.value instanceof File) {
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
return isObject(obj.value);
|
|
348
|
+
}
|
|
349
|
+
function unwrapGetter(getter, value, index) {
|
|
350
|
+
const scope = vue.effectScope();
|
|
351
|
+
let unwrapped;
|
|
352
|
+
if (getter instanceof Function) {
|
|
353
|
+
unwrapped = scope.run(() => getter(value, index ?? 0));
|
|
354
|
+
} else {
|
|
355
|
+
unwrapped = getter;
|
|
356
|
+
}
|
|
357
|
+
return { scope, unwrapped };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/utils/debounce.ts
|
|
361
|
+
function debounce(func, wait, immediate) {
|
|
362
|
+
let timeout;
|
|
363
|
+
const debouncedFn = (...args) => new Promise((resolve) => {
|
|
364
|
+
clearTimeout(timeout);
|
|
365
|
+
timeout = setTimeout(() => {
|
|
366
|
+
timeout = void 0;
|
|
367
|
+
{
|
|
368
|
+
Promise.resolve(func.apply(this, [...args])).then(resolve);
|
|
369
|
+
}
|
|
370
|
+
}, wait);
|
|
371
|
+
});
|
|
372
|
+
debouncedFn.cancel = () => {
|
|
373
|
+
clearTimeout(timeout);
|
|
374
|
+
timeout = void 0;
|
|
375
|
+
};
|
|
376
|
+
return debouncedFn;
|
|
377
|
+
}
|
|
378
|
+
function versionCompare(current, other) {
|
|
379
|
+
const cp = String(current).split(".");
|
|
380
|
+
const op = String(other).split(".");
|
|
381
|
+
for (let depth = 0; depth < Math.min(cp.length, op.length); depth++) {
|
|
382
|
+
const cn = Number(cp[depth]);
|
|
383
|
+
const on = Number(op[depth]);
|
|
384
|
+
if (cn > on) return 1 /* GreaterThan */;
|
|
385
|
+
if (on > cn) return -1 /* LessThan */;
|
|
386
|
+
if (!isNaN(cn) && isNaN(on)) return 1 /* GreaterThan */;
|
|
387
|
+
if (isNaN(cn) && !isNaN(on)) return -1 /* LessThan */;
|
|
388
|
+
}
|
|
389
|
+
return 0 /* EqualTo */;
|
|
390
|
+
}
|
|
391
|
+
var isVueSuperiorOrEqualTo3dotFive = versionCompare(vue.version, "3.5.0") === -1 ? false : true;
|
|
392
|
+
|
|
393
|
+
// src/utils/randomId.ts
|
|
394
|
+
function uniqueIDNuxt() {
|
|
395
|
+
return Math.floor(Math.random() * Date.now()).toString();
|
|
396
|
+
}
|
|
397
|
+
function randomId() {
|
|
398
|
+
if (typeof window === "undefined") {
|
|
399
|
+
return uniqueIDNuxt();
|
|
400
|
+
} else {
|
|
401
|
+
const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
|
|
402
|
+
return uint32.toString(10);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
403
405
|
|
|
404
406
|
// src/core/useRegle/guards/ruleDef.guards.ts
|
|
405
407
|
function isNestedRulesDef(state, rules) {
|
|
@@ -663,7 +665,7 @@ function createReactiveRuleStatus({
|
|
|
663
665
|
});
|
|
664
666
|
}
|
|
665
667
|
|
|
666
|
-
// src/core/useRegle/
|
|
668
|
+
// src/core/useRegle/root/createReactiveFieldStatus.ts
|
|
667
669
|
function createReactiveFieldStatus({
|
|
668
670
|
state,
|
|
669
671
|
rulesDef,
|
|
@@ -1141,7 +1143,7 @@ function createCollectionElement({
|
|
|
1141
1143
|
return $status;
|
|
1142
1144
|
}
|
|
1143
1145
|
|
|
1144
|
-
// src/core/useRegle/
|
|
1146
|
+
// src/core/useRegle/root/collections/createReactiveCollectionRoot.ts
|
|
1145
1147
|
function createReactiveCollectionStatus({
|
|
1146
1148
|
state,
|
|
1147
1149
|
rulesDef,
|
|
@@ -1519,7 +1521,7 @@ function createReactiveCollectionStatus({
|
|
|
1519
1521
|
});
|
|
1520
1522
|
}
|
|
1521
1523
|
|
|
1522
|
-
// src/core/useRegle/
|
|
1524
|
+
// src/core/useRegle/root/createReactiveNestedStatus.ts
|
|
1523
1525
|
function createReactiveNestedStatus({
|
|
1524
1526
|
rulesDef,
|
|
1525
1527
|
state,
|
|
@@ -1537,7 +1539,7 @@ function createReactiveNestedStatus({
|
|
|
1537
1539
|
let $unwatchRules = null;
|
|
1538
1540
|
let $unwatchExternalErrors = null;
|
|
1539
1541
|
let $unwatchState = null;
|
|
1540
|
-
async function createReactiveFieldsStatus(
|
|
1542
|
+
async function createReactiveFieldsStatus(watch5 = true) {
|
|
1541
1543
|
const mapOfRulesDef = Object.entries(rulesDef.value);
|
|
1542
1544
|
const scopedRulesStatus = Object.fromEntries(
|
|
1543
1545
|
mapOfRulesDef.filter(([_, rule]) => !!rule).map(([statePropKey, statePropRules]) => {
|
|
@@ -1600,7 +1602,7 @@ function createReactiveNestedStatus({
|
|
|
1600
1602
|
...externalRulesStatus,
|
|
1601
1603
|
...statesWithNoRules
|
|
1602
1604
|
};
|
|
1603
|
-
if (
|
|
1605
|
+
if (watch5) {
|
|
1604
1606
|
$watch();
|
|
1605
1607
|
}
|
|
1606
1608
|
}
|
|
@@ -1944,8 +1946,8 @@ function createReactiveChildrenStatus({
|
|
|
1944
1946
|
return null;
|
|
1945
1947
|
}
|
|
1946
1948
|
|
|
1947
|
-
// src/core/useRegle/
|
|
1948
|
-
function
|
|
1949
|
+
// src/core/useRegle/root/useRootStorage.ts
|
|
1950
|
+
function useRootStorage({
|
|
1949
1951
|
initialState,
|
|
1950
1952
|
options,
|
|
1951
1953
|
scopeRules,
|
|
@@ -1991,7 +1993,7 @@ function createUseRegleComposable(customRules, options, shortcuts) {
|
|
|
1991
1993
|
};
|
|
1992
1994
|
const processedState = vue.isRef(state) ? state : vue.ref(state);
|
|
1993
1995
|
const initialState = { ...cloneDeep(processedState.value) };
|
|
1994
|
-
const regle =
|
|
1996
|
+
const regle = useRootStorage({
|
|
1995
1997
|
scopeRules,
|
|
1996
1998
|
state: processedState,
|
|
1997
1999
|
options: resolvedOptions,
|
|
@@ -2031,3 +2033,4 @@ exports.defineRegleConfig = defineRegleConfig;
|
|
|
2031
2033
|
exports.inferRules = inferRules;
|
|
2032
2034
|
exports.unwrapRuleParameters = unwrapRuleParameters;
|
|
2033
2035
|
exports.useRegle = useRegle;
|
|
2036
|
+
exports.useRootStorage = useRootStorage;
|