@regle/core 0.5.0 → 0.5.2
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.cjs +132 -125
- package/dist/regle-core.d.cts +674 -7
- package/dist/regle-core.d.ts +674 -7
- package/dist/regle-core.min.cjs +2 -2
- package/dist/regle-core.min.mjs +2 -2
- package/dist/regle-core.mjs +133 -127
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -9,10 +9,6 @@ Regle \ʁɛɡl\ (French word for 'rule' ) is a Typescript-first model-based vali
|
|
|
9
9
|
It's heavily inspired by Vuelidate.
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
# 📚 Documentation
|
|
13
|
-
|
|
14
|
-
[](https://regle.vercel.app/)
|
|
15
|
-
|
|
16
12
|
## 📚 Documentation
|
|
17
13
|
|
|
18
14
|
[](https://regle.vercel.app/)
|
package/dist/regle-core.cjs
CHANGED
|
@@ -2,6 +2,64 @@
|
|
|
2
2
|
|
|
3
3
|
var vue = require('vue');
|
|
4
4
|
|
|
5
|
+
// ../shared/utils/isEmpty.ts
|
|
6
|
+
function isEmpty(value) {
|
|
7
|
+
if (value === void 0 || value === null) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
if (value instanceof Date) {
|
|
11
|
+
return isNaN(value.getTime());
|
|
12
|
+
}
|
|
13
|
+
if (Array.isArray(value)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === "object" && value != null) {
|
|
17
|
+
return Object.keys(value).length === 0;
|
|
18
|
+
}
|
|
19
|
+
return !String(value).length;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// ../shared/utils/symbol.ts
|
|
23
|
+
var RegleRuleSymbol = Symbol("regle-rule");
|
|
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
|
+
|
|
5
63
|
// src/types/rules/rule.internal.types.ts
|
|
6
64
|
var InternalRuleType = /* @__PURE__ */ ((InternalRuleType2) => {
|
|
7
65
|
InternalRuleType2["Inline"] = "__inline";
|
|
@@ -120,7 +178,8 @@ function defineRuleProcessors(definition, ...params) {
|
|
|
120
178
|
_message_patched: false,
|
|
121
179
|
_tooltip_patched: false,
|
|
122
180
|
_async: isAsync,
|
|
123
|
-
_params: createReactiveParams(params)
|
|
181
|
+
_params: createReactiveParams(params),
|
|
182
|
+
_brand: RegleRuleSymbol
|
|
124
183
|
};
|
|
125
184
|
return processors;
|
|
126
185
|
}
|
|
@@ -156,110 +215,6 @@ function createRule(definition) {
|
|
|
156
215
|
}
|
|
157
216
|
throw new Error("Validator must be a function");
|
|
158
217
|
}
|
|
159
|
-
function isObject(obj) {
|
|
160
|
-
if (obj instanceof Date || obj instanceof File) {
|
|
161
|
-
return false;
|
|
162
|
-
}
|
|
163
|
-
return typeof obj === "object" && obj !== null && !Array.isArray(obj);
|
|
164
|
-
}
|
|
165
|
-
function isRefObject(obj) {
|
|
166
|
-
if (obj.value instanceof Date || obj.value instanceof File) {
|
|
167
|
-
return false;
|
|
168
|
-
}
|
|
169
|
-
return isObject(obj.value);
|
|
170
|
-
}
|
|
171
|
-
function cloneDeep(obj) {
|
|
172
|
-
let result = obj;
|
|
173
|
-
let type = {}.toString.call(obj).slice(8, -1);
|
|
174
|
-
if (type == "Set") {
|
|
175
|
-
result = new Set([...obj].map((value) => cloneDeep(value)));
|
|
176
|
-
}
|
|
177
|
-
if (type == "Map") {
|
|
178
|
-
result = new Map([...obj].map((kv) => [cloneDeep(kv[0]), cloneDeep(kv[1])]));
|
|
179
|
-
}
|
|
180
|
-
if (type == "Date") {
|
|
181
|
-
result = new Date(obj.getTime());
|
|
182
|
-
}
|
|
183
|
-
if (type == "RegExp") {
|
|
184
|
-
result = RegExp(obj.source, getRegExpFlags(obj));
|
|
185
|
-
}
|
|
186
|
-
if (type == "Array" || type == "Object") {
|
|
187
|
-
result = Array.isArray(obj) ? [] : {};
|
|
188
|
-
for (let key in obj) {
|
|
189
|
-
result[key] = cloneDeep(obj[key]);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
function getRegExpFlags(regExp) {
|
|
195
|
-
if (typeof regExp.source.flags == "string") {
|
|
196
|
-
return regExp.source.flags;
|
|
197
|
-
} else {
|
|
198
|
-
let flags = [];
|
|
199
|
-
regExp.global && flags.push("g");
|
|
200
|
-
regExp.ignoreCase && flags.push("i");
|
|
201
|
-
regExp.multiline && flags.push("m");
|
|
202
|
-
regExp.sticky && flags.push("y");
|
|
203
|
-
regExp.unicode && flags.push("u");
|
|
204
|
-
return flags.join("");
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function unwrapGetter(getter, value, index) {
|
|
208
|
-
const scope = vue.effectScope();
|
|
209
|
-
let unwrapped;
|
|
210
|
-
if (getter instanceof Function) {
|
|
211
|
-
unwrapped = scope.run(() => getter(value, index ?? 0));
|
|
212
|
-
} else {
|
|
213
|
-
unwrapped = getter;
|
|
214
|
-
}
|
|
215
|
-
return { scope, unwrapped };
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// src/utils/debounce.ts
|
|
219
|
-
function debounce(func, wait, immediate) {
|
|
220
|
-
let timeout;
|
|
221
|
-
const debouncedFn = (...args) => new Promise((resolve) => {
|
|
222
|
-
clearTimeout(timeout);
|
|
223
|
-
timeout = setTimeout(() => {
|
|
224
|
-
timeout = void 0;
|
|
225
|
-
{
|
|
226
|
-
Promise.resolve(func.apply(this, [...args])).then(resolve);
|
|
227
|
-
}
|
|
228
|
-
}, wait);
|
|
229
|
-
});
|
|
230
|
-
debouncedFn.cancel = () => {
|
|
231
|
-
clearTimeout(timeout);
|
|
232
|
-
timeout = void 0;
|
|
233
|
-
};
|
|
234
|
-
return debouncedFn;
|
|
235
|
-
}
|
|
236
|
-
function versionCompare(current, other) {
|
|
237
|
-
const cp = String(current).split(".");
|
|
238
|
-
const op = String(other).split(".");
|
|
239
|
-
for (let depth = 0; depth < Math.min(cp.length, op.length); depth++) {
|
|
240
|
-
const cn = Number(cp[depth]);
|
|
241
|
-
const on = Number(op[depth]);
|
|
242
|
-
if (cn > on) return 1 /* GreaterThan */;
|
|
243
|
-
if (on > cn) return -1 /* LessThan */;
|
|
244
|
-
if (!isNaN(cn) && isNaN(on)) return 1 /* GreaterThan */;
|
|
245
|
-
if (isNaN(cn) && !isNaN(on)) return -1 /* LessThan */;
|
|
246
|
-
}
|
|
247
|
-
return 0 /* EqualTo */;
|
|
248
|
-
}
|
|
249
|
-
var isVueSuperiorOrEqualTo3dotFive = versionCompare(vue.version, "3.5.0") === -1 ? false : true;
|
|
250
|
-
|
|
251
|
-
// src/utils/randomId.ts
|
|
252
|
-
function uniqueIDNuxt() {
|
|
253
|
-
return Math.floor(Math.random() * Date.now()).toString();
|
|
254
|
-
}
|
|
255
|
-
function randomId() {
|
|
256
|
-
if (typeof window === "undefined") {
|
|
257
|
-
return uniqueIDNuxt();
|
|
258
|
-
} else {
|
|
259
|
-
const uint32 = window.crypto.getRandomValues(new Uint32Array(1))[0];
|
|
260
|
-
return uint32.toString(10);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
218
|
function useStorage() {
|
|
264
219
|
const ruleDeclStorage = vue.shallowRef(/* @__PURE__ */ new Map());
|
|
265
220
|
const fieldsStorage = vue.shallowRef(/* @__PURE__ */ new Map());
|
|
@@ -379,22 +334,73 @@ function useStorage() {
|
|
|
379
334
|
arrayStatusStorage
|
|
380
335
|
};
|
|
381
336
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
if (value === void 0 || value === null) {
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
if (value instanceof Date) {
|
|
389
|
-
return isNaN(value.getTime());
|
|
337
|
+
function isObject(obj) {
|
|
338
|
+
if (obj instanceof Date || obj instanceof File) {
|
|
339
|
+
return false;
|
|
390
340
|
}
|
|
391
|
-
|
|
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) {
|
|
392
345
|
return false;
|
|
393
346
|
}
|
|
394
|
-
|
|
395
|
-
|
|
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);
|
|
396
403
|
}
|
|
397
|
-
return !String(value).length;
|
|
398
404
|
}
|
|
399
405
|
|
|
400
406
|
// src/core/useRegle/guards/ruleDef.guards.ts
|
|
@@ -659,7 +665,7 @@ function createReactiveRuleStatus({
|
|
|
659
665
|
});
|
|
660
666
|
}
|
|
661
667
|
|
|
662
|
-
// src/core/useRegle/
|
|
668
|
+
// src/core/useRegle/root/createReactiveFieldStatus.ts
|
|
663
669
|
function createReactiveFieldStatus({
|
|
664
670
|
state,
|
|
665
671
|
rulesDef,
|
|
@@ -1137,7 +1143,7 @@ function createCollectionElement({
|
|
|
1137
1143
|
return $status;
|
|
1138
1144
|
}
|
|
1139
1145
|
|
|
1140
|
-
// src/core/useRegle/
|
|
1146
|
+
// src/core/useRegle/root/collections/createReactiveCollectionRoot.ts
|
|
1141
1147
|
function createReactiveCollectionStatus({
|
|
1142
1148
|
state,
|
|
1143
1149
|
rulesDef,
|
|
@@ -1515,7 +1521,7 @@ function createReactiveCollectionStatus({
|
|
|
1515
1521
|
});
|
|
1516
1522
|
}
|
|
1517
1523
|
|
|
1518
|
-
// src/core/useRegle/
|
|
1524
|
+
// src/core/useRegle/root/createReactiveNestedStatus.ts
|
|
1519
1525
|
function createReactiveNestedStatus({
|
|
1520
1526
|
rulesDef,
|
|
1521
1527
|
state,
|
|
@@ -1533,7 +1539,7 @@ function createReactiveNestedStatus({
|
|
|
1533
1539
|
let $unwatchRules = null;
|
|
1534
1540
|
let $unwatchExternalErrors = null;
|
|
1535
1541
|
let $unwatchState = null;
|
|
1536
|
-
async function createReactiveFieldsStatus(
|
|
1542
|
+
async function createReactiveFieldsStatus(watch5 = true) {
|
|
1537
1543
|
const mapOfRulesDef = Object.entries(rulesDef.value);
|
|
1538
1544
|
const scopedRulesStatus = Object.fromEntries(
|
|
1539
1545
|
mapOfRulesDef.filter(([_, rule]) => !!rule).map(([statePropKey, statePropRules]) => {
|
|
@@ -1596,7 +1602,7 @@ function createReactiveNestedStatus({
|
|
|
1596
1602
|
...externalRulesStatus,
|
|
1597
1603
|
...statesWithNoRules
|
|
1598
1604
|
};
|
|
1599
|
-
if (
|
|
1605
|
+
if (watch5) {
|
|
1600
1606
|
$watch();
|
|
1601
1607
|
}
|
|
1602
1608
|
}
|
|
@@ -1940,8 +1946,8 @@ function createReactiveChildrenStatus({
|
|
|
1940
1946
|
return null;
|
|
1941
1947
|
}
|
|
1942
1948
|
|
|
1943
|
-
// src/core/useRegle/
|
|
1944
|
-
function
|
|
1949
|
+
// src/core/useRegle/root/useRootStorage.ts
|
|
1950
|
+
function useRootStorage({
|
|
1945
1951
|
initialState,
|
|
1946
1952
|
options,
|
|
1947
1953
|
scopeRules,
|
|
@@ -1987,7 +1993,7 @@ function createUseRegleComposable(customRules, options, shortcuts) {
|
|
|
1987
1993
|
};
|
|
1988
1994
|
const processedState = vue.isRef(state) ? state : vue.ref(state);
|
|
1989
1995
|
const initialState = { ...cloneDeep(processedState.value) };
|
|
1990
|
-
const regle =
|
|
1996
|
+
const regle = useRootStorage({
|
|
1991
1997
|
scopeRules,
|
|
1992
1998
|
state: processedState,
|
|
1993
1999
|
options: resolvedOptions,
|
|
@@ -2027,3 +2033,4 @@ exports.defineRegleConfig = defineRegleConfig;
|
|
|
2027
2033
|
exports.inferRules = inferRules;
|
|
2028
2034
|
exports.unwrapRuleParameters = unwrapRuleParameters;
|
|
2029
2035
|
exports.useRegle = useRegle;
|
|
2036
|
+
exports.useRootStorage = useRootStorage;
|