@regle/schemas 1.7.2 → 1.8.0-beta.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.
@@ -1185,11 +1185,21 @@ type InferDeepReactiveState<TState> = NonNullable<TState> extends Array<infer U
1185
1185
  //#region src/types/core/reset.types.d.ts
1186
1186
  type ResetOptions<TState extends unknown> = RequireOneOrNone<{
1187
1187
  /**
1188
- * Reset validation status and reset form state to its initial state
1188
+ * Reset validation status and reset form state to its initial state.
1189
+ *
1190
+ * Initial state is different than the original state as the initial state can be mutated when using `$reset`.
1191
+ *
1192
+ * This serve as the base comparison state for `$edited` property.
1189
1193
  *
1190
1194
  * ⚠️ This doesn't work if the state is a `reactive` object.
1191
1195
  */
1192
1196
  toInitialState?: boolean;
1197
+ /**
1198
+ * Reset validation status and reset form state to its original state.
1199
+ *
1200
+ * Original state is the unmutated state that was passed to the form when it was initialized.
1201
+ */
1202
+ toOriginalState?: boolean;
1193
1203
  /**
1194
1204
  * Reset validation status and reset form state to the given state
1195
1205
  * Also set the new state as the initial state.
@@ -1246,24 +1256,6 @@ type Not<T extends boolean> = T extends true ? false : true;
1246
1256
  * {@linkcode Types} array is `true`, otherwise returns `false`.
1247
1257
  */
1248
1258
 
1249
- /**
1250
- * Checks if all the boolean types in the {@linkcode Types} array are `true`.
1251
- */
1252
- type And<Types extends boolean[]> = Types[number] extends true ? true : false;
1253
- /**
1254
- * Represents an equality type that returns {@linkcode Right} if
1255
- * {@linkcode Left} is `true`,
1256
- * otherwise returns the negation of {@linkcode Right}.
1257
- */
1258
-
1259
- /**
1260
- * @internal
1261
- */
1262
- declare const secret: unique symbol;
1263
- /**
1264
- * @internal
1265
- */
1266
- type Secret = typeof secret;
1267
1259
  /**
1268
1260
  * Checks if the given type is `never`.
1269
1261
  */
@@ -1271,47 +1263,7 @@ type IsNever$2<T> = [T] extends [never] ? true : false;
1271
1263
  /**
1272
1264
  * Checks if the given type is `any`.
1273
1265
  */
1274
- type IsAny$2<T> = [T] extends [Secret] ? Not<IsNever$2<T>> : false;
1275
- /**
1276
- * Determines if the given type is `unknown`.
1277
- */
1278
- type IsUnknown$1<T> = [unknown] extends [T] ? Not<IsAny$2<T>> : false;
1279
- /**
1280
- * Determines if a type is either `never` or `any`.
1281
- */
1282
1266
 
1283
- /**
1284
- * Subjective "useful" keys from a type. For objects it's just `keyof` but for
1285
- * tuples/arrays it's the number keys.
1286
- *
1287
- * @example
1288
- * ```ts
1289
- * UsefulKeys<{ a: 1; b: 2 }> // 'a' | 'b'
1290
- *
1291
- * UsefulKeys<['a', 'b']> // '0' | '1'
1292
- *
1293
- * UsefulKeys<string[]> // number
1294
- * ```
1295
- */
1296
- type UsefulKeys<T> = T extends any[] ? { [K in keyof T]: K }[number] : keyof T;
1297
- /**
1298
- * Extracts the keys from a type that are required (not optional).
1299
- */
1300
- type RequiredKeys<T> = Extract<{ [K in keyof T]-?: {} extends Pick<T, K> ? never : K }[keyof T], keyof T>;
1301
- /**
1302
- * Gets the keys of an object type that are optional.
1303
- */
1304
- type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>;
1305
- /**
1306
- * Extracts the keys from a type that are not `readonly`.
1307
- */
1308
- type ReadonlyKeys<T> = Extract<{ [K in keyof T]-?: ReadonlyEquivalent<{ [_K in K]: T[K] }, { -readonly [_K in K]: T[K] }> extends true ? never : K }[keyof T], keyof T>;
1309
- /**
1310
- * Determines if two types, are equivalent in a `readonly` manner.
1311
- *
1312
- * @internal
1313
- */
1314
- type ReadonlyEquivalent<X, Y> = Extends<(<T>() => T extends X ? true : false), (<T>() => T extends Y ? true : false)>;
1315
1267
  /**
1316
1268
  * Checks if one type extends another. Note: this is not quite the same as `Left extends Right` because:
1317
1269
  * 1. If either type is `never`, the result is `true` iff the other type is also `never`.
@@ -1323,24 +1275,6 @@ type Extends<Left, Right> = IsNever$2<Left> extends true ? IsNever$2<Right> : [L
1323
1275
  * excluding `any` or `never`.
1324
1276
  */
1325
1277
 
1326
- /**
1327
- * Checks if two types are strictly equal using
1328
- * the TypeScript internal identical-to operator.
1329
- *
1330
- * @see {@link https://github.com/microsoft/TypeScript/issues/55188#issuecomment-1656328122 | much history}
1331
- */
1332
- type StrictEqualUsingTSInternalIdenticalToOperator<L, R> = (<T>() => T extends (L & T) | T ? true : false) extends (<T>() => T extends (R & T) | T ? true : false) ? IsNever$2<L> extends IsNever$2<R> ? true : false : false;
1333
- /**
1334
- * Checks that {@linkcode Left} and {@linkcode Right} extend each other.
1335
- * Not quite the same as an equality check since `any` can make it resolve
1336
- * to `true`. So should only be used when {@linkcode Left} and
1337
- * {@linkcode Right} are known to avoid `any`.
1338
- */
1339
- type MutuallyExtends<Left, Right> = And<[Extends<Left, Right>, Extends<Right, Left>]>;
1340
- /**
1341
- * @internal
1342
- */
1343
-
1344
1278
  /**
1345
1279
  * Convert a union to an intersection.
1346
1280
  * `A | B | C` -\> `A & B & C`
@@ -1375,344 +1309,6 @@ type IsUnion<T> = Not<Extends<UnionToTuple$1<T>['length'], 1>>;
1375
1309
  * ```
1376
1310
  */
1377
1311
  //#endregion
1378
- //#region ../../node_modules/.pnpm/expect-type@1.2.2/node_modules/expect-type/dist/overloads.d.ts
1379
- /**
1380
- * The simple(ish) way to get overload info from a function
1381
- * {@linkcode FunctionType}. Recent versions of TypeScript will match any
1382
- * function against a generic 10-overload type, filling in slots with
1383
- * duplicates of the function. So, we can just match against a single type
1384
- * and get all the overloads.
1385
- *
1386
- * For older versions of TypeScript, we'll need to painstakingly do
1387
- * ten separate matches.
1388
- */
1389
- type TSPost53OverloadsInfoUnion<FunctionType> = FunctionType extends {
1390
- (...args: infer A1): infer R1;
1391
- (...args: infer A2): infer R2;
1392
- (...args: infer A3): infer R3;
1393
- (...args: infer A4): infer R4;
1394
- (...args: infer A5): infer R5;
1395
- (...args: infer A6): infer R6;
1396
- (...args: infer A7): infer R7;
1397
- (...args: infer A8): infer R8;
1398
- (...args: infer A9): infer R9;
1399
- (...args: infer A10): infer R10;
1400
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : never;
1401
- /**
1402
- * A function with `unknown` parameters and return type.
1403
- */
1404
- type UnknownFunction = (...args: unknown[]) => unknown;
1405
- /**
1406
- * `true` iff {@linkcode FunctionType} is
1407
- * equivalent to `(...args: unknown[]) => unknown`,
1408
- * which is what an overload variant looks like for a non-existent overload.
1409
- * This is useful because older versions of TypeScript end up with
1410
- * 9 "useless" overloads and one real one for parameterless/generic functions.
1411
- *
1412
- * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
1413
- */
1414
- type IsUselessOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownFunction>;
1415
- /**
1416
- * Old versions of TypeScript can sometimes seem to refuse to separate out
1417
- * union members unless you put them each in a pointless tuple and add an
1418
- * extra `infer X` expression. There may be a better way to work around this
1419
- * problem, but since it's not a problem in newer versions of TypeScript,
1420
- * it's not a priority right now.
1421
- */
1422
- type Tuplify<Union> = Union extends infer X ? [X] : never;
1423
- /**
1424
- * For older versions of TypeScript, we need two separate workarounds
1425
- * to get overload info. First, we need need to use
1426
- * {@linkcode DecreasingOverloadsInfoUnion} to get the overload info for
1427
- * functions with 1-10 overloads. Then, we need to filter out the
1428
- * "useless" overloads that are present in older versions of TypeScript,
1429
- * for parameterless functions. To do this we use
1430
- * {@linkcode IsUselessOverloadInfo} to remove useless overloads.
1431
- *
1432
- * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
1433
- */
1434
- type TSPre53OverloadsInfoUnion<FunctionType> = Tuplify<DecreasingOverloadsInfoUnion<FunctionType>> extends infer Tup ? Tup extends [infer Fn] ? IsUselessOverloadInfo<Fn> extends true ? never : Fn : never : never;
1435
- /**
1436
- * For versions of TypeScript below 5.3, we need to check for 10 overloads,
1437
- * then 9, then 8, etc., to get a union of the overload variants.
1438
- */
1439
- type DecreasingOverloadsInfoUnion<F> = F extends {
1440
- (...args: infer A1): infer R1;
1441
- (...args: infer A2): infer R2;
1442
- (...args: infer A3): infer R3;
1443
- (...args: infer A4): infer R4;
1444
- (...args: infer A5): infer R5;
1445
- (...args: infer A6): infer R6;
1446
- (...args: infer A7): infer R7;
1447
- (...args: infer A8): infer R8;
1448
- (...args: infer A9): infer R9;
1449
- (...args: infer A10): infer R10;
1450
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) | ((...p: A10) => R10) : F extends {
1451
- (...args: infer A1): infer R1;
1452
- (...args: infer A2): infer R2;
1453
- (...args: infer A3): infer R3;
1454
- (...args: infer A4): infer R4;
1455
- (...args: infer A5): infer R5;
1456
- (...args: infer A6): infer R6;
1457
- (...args: infer A7): infer R7;
1458
- (...args: infer A8): infer R8;
1459
- (...args: infer A9): infer R9;
1460
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) | ((...p: A9) => R9) : F extends {
1461
- (...args: infer A1): infer R1;
1462
- (...args: infer A2): infer R2;
1463
- (...args: infer A3): infer R3;
1464
- (...args: infer A4): infer R4;
1465
- (...args: infer A5): infer R5;
1466
- (...args: infer A6): infer R6;
1467
- (...args: infer A7): infer R7;
1468
- (...args: infer A8): infer R8;
1469
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) | ((...p: A8) => R8) : F extends {
1470
- (...args: infer A1): infer R1;
1471
- (...args: infer A2): infer R2;
1472
- (...args: infer A3): infer R3;
1473
- (...args: infer A4): infer R4;
1474
- (...args: infer A5): infer R5;
1475
- (...args: infer A6): infer R6;
1476
- (...args: infer A7): infer R7;
1477
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) | ((...p: A7) => R7) : F extends {
1478
- (...args: infer A1): infer R1;
1479
- (...args: infer A2): infer R2;
1480
- (...args: infer A3): infer R3;
1481
- (...args: infer A4): infer R4;
1482
- (...args: infer A5): infer R5;
1483
- (...args: infer A6): infer R6;
1484
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) | ((...p: A6) => R6) : F extends {
1485
- (...args: infer A1): infer R1;
1486
- (...args: infer A2): infer R2;
1487
- (...args: infer A3): infer R3;
1488
- (...args: infer A4): infer R4;
1489
- (...args: infer A5): infer R5;
1490
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) | ((...p: A5) => R5) : F extends {
1491
- (...args: infer A1): infer R1;
1492
- (...args: infer A2): infer R2;
1493
- (...args: infer A3): infer R3;
1494
- (...args: infer A4): infer R4;
1495
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) | ((...p: A4) => R4) : F extends {
1496
- (...args: infer A1): infer R1;
1497
- (...args: infer A2): infer R2;
1498
- (...args: infer A3): infer R3;
1499
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) | ((...p: A3) => R3) : F extends {
1500
- (...args: infer A1): infer R1;
1501
- (...args: infer A2): infer R2;
1502
- } ? ((...p: A1) => R1) | ((...p: A2) => R2) : F extends ((...args: infer A1) => infer R1) ? ((...p: A1) => R1) : never;
1503
- /**
1504
- * Get a union of overload variants for a function {@linkcode FunctionType}.
1505
- * Does a check for whether we can do the one-shot
1506
- * 10-overload matcher (which works for ts\>5.3), and if not,
1507
- * falls back to the more complicated utility.
1508
- */
1509
- type OverloadsInfoUnion<FunctionType> = IsNever$2<TSPost53OverloadsInfoUnion<(a: 1) => 2>> extends true ? TSPre53OverloadsInfoUnion<FunctionType> : TSPost53OverloadsInfoUnion<FunctionType>;
1510
- /**
1511
- * Allows inferring any function using the `infer` keyword.
1512
- */
1513
-
1514
- /**
1515
- * The simple(ish) way to get overload info from a constructor
1516
- * {@linkcode ConstructorType}. Recent versions of TypeScript will match any
1517
- * constructor against a generic 10-overload type, filling in slots with
1518
- * duplicates of the constructor. So, we can just match against a single type
1519
- * and get all the overloads.
1520
- *
1521
- * For older versions of TypeScript,
1522
- * we'll need to painstakingly do ten separate matches.
1523
- */
1524
- type TSPost53ConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
1525
- new (...args: infer A1): infer R1;
1526
- new (...args: infer A2): infer R2;
1527
- new (...args: infer A3): infer R3;
1528
- new (...args: infer A4): infer R4;
1529
- new (...args: infer A5): infer R5;
1530
- new (...args: infer A6): infer R6;
1531
- new (...args: infer A7): infer R7;
1532
- new (...args: infer A8): infer R8;
1533
- new (...args: infer A9): infer R9;
1534
- new (...args: infer A10): infer R10;
1535
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : never;
1536
- /**
1537
- * A constructor function with `unknown` parameters and return type.
1538
- */
1539
- type UnknownConstructor = new (...args: unknown[]) => unknown;
1540
- /**
1541
- * Same as {@linkcode IsUselessOverloadInfo}, but for constructors.
1542
- */
1543
- type IsUselessConstructorOverloadInfo<FunctionType> = StrictEqualUsingTSInternalIdenticalToOperator<FunctionType, UnknownConstructor>;
1544
- /**
1545
- * For older versions of TypeScript, we need two separate workarounds to
1546
- * get constructor overload info. First, we need need to use
1547
- * {@linkcode DecreasingConstructorOverloadsInfoUnion} to get the overload
1548
- * info for constructors with 1-10 overloads. Then, we need to filter out the
1549
- * "useless" overloads that are present in older versions of TypeScript,
1550
- * for parameterless constructors. To do this we use
1551
- * {@linkcode IsUselessConstructorOverloadInfo} to remove useless overloads.
1552
- *
1553
- * @see {@link https://github.com/microsoft/TypeScript/issues/28867 | Related}
1554
- */
1555
- type TSPre53ConstructorOverloadsInfoUnion<ConstructorType> = Tuplify<DecreasingConstructorOverloadsInfoUnion<ConstructorType>> extends infer Tup ? Tup extends [infer Ctor] ? IsUselessConstructorOverloadInfo<Ctor> extends true ? never : Ctor : never : never;
1556
- /**
1557
- * For versions of TypeScript below 5.3, we need to check for 10 overloads,
1558
- * then 9, then 8, etc., to get a union of the overload variants.
1559
- */
1560
- type DecreasingConstructorOverloadsInfoUnion<ConstructorType> = ConstructorType extends {
1561
- new (...args: infer A1): infer R1;
1562
- new (...args: infer A2): infer R2;
1563
- new (...args: infer A3): infer R3;
1564
- new (...args: infer A4): infer R4;
1565
- new (...args: infer A5): infer R5;
1566
- new (...args: infer A6): infer R6;
1567
- new (...args: infer A7): infer R7;
1568
- new (...args: infer A8): infer R8;
1569
- new (...args: infer A9): infer R9;
1570
- new (...args: infer A10): infer R10;
1571
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) | (new (...p: A10) => R10) : ConstructorType extends {
1572
- new (...args: infer A1): infer R1;
1573
- new (...args: infer A2): infer R2;
1574
- new (...args: infer A3): infer R3;
1575
- new (...args: infer A4): infer R4;
1576
- new (...args: infer A5): infer R5;
1577
- new (...args: infer A6): infer R6;
1578
- new (...args: infer A7): infer R7;
1579
- new (...args: infer A8): infer R8;
1580
- new (...args: infer A9): infer R9;
1581
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) | (new (...p: A9) => R9) : ConstructorType extends {
1582
- new (...args: infer A1): infer R1;
1583
- new (...args: infer A2): infer R2;
1584
- new (...args: infer A3): infer R3;
1585
- new (...args: infer A4): infer R4;
1586
- new (...args: infer A5): infer R5;
1587
- new (...args: infer A6): infer R6;
1588
- new (...args: infer A7): infer R7;
1589
- new (...args: infer A8): infer R8;
1590
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) | (new (...p: A8) => R8) : ConstructorType extends {
1591
- new (...args: infer A1): infer R1;
1592
- new (...args: infer A2): infer R2;
1593
- new (...args: infer A3): infer R3;
1594
- new (...args: infer A4): infer R4;
1595
- new (...args: infer A5): infer R5;
1596
- new (...args: infer A6): infer R6;
1597
- new (...args: infer A7): infer R7;
1598
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) | (new (...p: A7) => R7) : ConstructorType extends {
1599
- new (...args: infer A1): infer R1;
1600
- new (...args: infer A2): infer R2;
1601
- new (...args: infer A3): infer R3;
1602
- new (...args: infer A4): infer R4;
1603
- new (...args: infer A5): infer R5;
1604
- new (...args: infer A6): infer R6;
1605
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) | (new (...p: A6) => R6) : ConstructorType extends {
1606
- new (...args: infer A1): infer R1;
1607
- new (...args: infer A2): infer R2;
1608
- new (...args: infer A3): infer R3;
1609
- new (...args: infer A4): infer R4;
1610
- new (...args: infer A5): infer R5;
1611
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) | (new (...p: A5) => R5) : ConstructorType extends {
1612
- new (...args: infer A1): infer R1;
1613
- new (...args: infer A2): infer R2;
1614
- new (...args: infer A3): infer R3;
1615
- new (...args: infer A4): infer R4;
1616
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) | (new (...p: A4) => R4) : ConstructorType extends {
1617
- new (...args: infer A1): infer R1;
1618
- new (...args: infer A2): infer R2;
1619
- new (...args: infer A3): infer R3;
1620
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) | (new (...p: A3) => R3) : ConstructorType extends {
1621
- new (...args: infer A1): infer R1;
1622
- new (...args: infer A2): infer R2;
1623
- } ? (new (...p: A1) => R1) | (new (...p: A2) => R2) : ConstructorType extends (new (...args: infer A1) => infer R1) ? (new (...p: A1) => R1) : never;
1624
- /**
1625
- * Get a union of overload variants for a constructor
1626
- * {@linkcode ConstructorType}. Does a check for whether we can do the
1627
- * one-shot 10-overload matcher (which works for ts\>5.3), and if not,
1628
- * falls back to the more complicated utility.
1629
- */
1630
- type ConstructorOverloadsUnion<ConstructorType> = IsNever$2<TSPost53ConstructorOverloadsInfoUnion<new (a: 1) => any>> extends true ? TSPre53ConstructorOverloadsInfoUnion<ConstructorType> : TSPost53ConstructorOverloadsInfoUnion<ConstructorType>;
1631
- /**
1632
- * Allows inferring any constructor using the `infer` keyword.
1633
- */
1634
- type InferConstructor<ConstructorType extends new (...args: any) => any> = ConstructorType;
1635
- /**
1636
- * A union type of the parameters allowed for any overload
1637
- * of constructor {@linkcode ConstructorType}.
1638
- */
1639
- type ConstructorOverloadParameters<ConstructorType> = ConstructorOverloadsUnion<ConstructorType> extends InferConstructor<infer Ctor> ? ConstructorParameters<Ctor> : never;
1640
- /**
1641
- * Calculates the number of overloads for a given function type.
1642
- */
1643
- type NumOverloads<FunctionType> = UnionToTuple$1<OverloadsInfoUnion<FunctionType>>['length'];
1644
- //#endregion
1645
- //#region ../../node_modules/.pnpm/expect-type@1.2.2/node_modules/expect-type/dist/branding.d.ts
1646
- /**
1647
- * Represents a deeply branded type.
1648
- *
1649
- * Recursively walk a type and replace it with a branded type related to the
1650
- * original. This is useful for equality-checking stricter than
1651
- * `A extends B ? B extends A ? true : false : false`, because it detects the
1652
- * difference between a few edge-case types that vanilla TypeScript
1653
- * doesn't by default:
1654
- * - `any` vs `unknown`
1655
- * - `{ readonly a: string }` vs `{ a: string }`
1656
- * - `{ a?: string }` vs `{ a: string | undefined }`
1657
- *
1658
- * __Note__: not very performant for complex types - this should only be used
1659
- * when you know you need it. If doing an equality check, it's almost always
1660
- * better to use {@linkcode StrictEqualUsingTSInternalIdenticalToOperator}.
1661
- */
1662
- type DeepBrand<T> = IsNever$2<T> extends true ? {
1663
- type: 'never';
1664
- } : IsAny$2<T> extends true ? {
1665
- type: 'any';
1666
- } : IsUnknown$1<T> extends true ? {
1667
- type: 'unknown';
1668
- } : T extends string | number | boolean | symbol | bigint | null | undefined | void ? {
1669
- type: 'primitive';
1670
- value: T;
1671
- } : T extends (new (...args: any[]) => any) ? {
1672
- type: 'constructor';
1673
- params: ConstructorOverloadParameters<T>;
1674
- instance: DeepBrand<InstanceType<Extract<T, new (...args: any) => any>>>;
1675
- } : T extends ((...args: infer P) => infer R) ? NumOverloads<T> extends 1 ? {
1676
- type: 'function';
1677
- params: DeepBrand<P>;
1678
- return: DeepBrand<R>;
1679
- this: DeepBrand<ThisParameterType<T>>;
1680
- props: DeepBrand<Omit<T, keyof Function>>;
1681
- } : UnionToTuple$1<OverloadsInfoUnion<T>> extends infer OverloadsTuple ? {
1682
- type: 'overloads';
1683
- overloads: { [K in keyof OverloadsTuple]: DeepBrand<OverloadsTuple[K]> };
1684
- } : never : T extends any[] ? {
1685
- type: 'array';
1686
- items: { [K in keyof T]: T[K] };
1687
- } : {
1688
- type: 'object';
1689
- properties: { [K in keyof T]: DeepBrand<T[K]> };
1690
- readonly: ReadonlyKeys<T>;
1691
- required: RequiredKeys<T>;
1692
- optional: OptionalKeys<T>;
1693
- constructorParams: DeepBrand<ConstructorOverloadParameters<T>>;
1694
- };
1695
- /**
1696
- * Checks if two types are strictly equal using branding.
1697
- */
1698
- type StrictEqualUsingBranding<Left, Right> = MutuallyExtends<DeepBrand<Left>, DeepBrand<Right>>;
1699
- //#endregion
1700
- //#region ../../node_modules/.pnpm/expect-type@1.2.2/node_modules/expect-type/dist/messages.d.ts
1701
- /**
1702
- * Determines the printable type representation for a given type.
1703
- */
1704
- type PrintType<T> = IsUnknown$1<T> extends true ? 'unknown' : IsNever$2<T> extends true ? 'never' : IsAny$2<T> extends true ? never : boolean extends T ? 'boolean' : T extends boolean ? `literal boolean: ${T}` : string extends T ? 'string' : T extends string ? `literal string: ${T}` : number extends T ? 'number' : T extends number ? `literal number: ${T}` : bigint extends T ? 'bigint' : T extends bigint ? `literal bigint: ${T}` : T extends null ? 'null' : T extends undefined ? 'undefined' : T extends ((...args: any[]) => any) ? 'function' : '...';
1705
- /**
1706
- * Helper for showing end-user a hint why their type assertion is failing.
1707
- * This swaps "leaf" types with a literal message about what the actual and
1708
- * expected types are. Needs to check for `Not<IsAny<Actual>>` because
1709
- * otherwise `LeafTypeOf<Actual>` returns `never`, which extends everything 🤔
1710
- */
1711
- type MismatchInfo<Actual, Expected> = And<[Extends<PrintType<Actual>, '...'>, Not<IsAny$2<Actual>>]> extends true ? And<[Extends<any[], Actual>, Extends<any[], Expected>]> extends true ? Array<MismatchInfo<Extract<Actual, any[]>[number], Extract<Expected, any[]>[number]>> : { [K in UsefulKeys<Actual> | UsefulKeys<Expected>]: MismatchInfo<K extends keyof Actual ? Actual[K] : never, K extends keyof Expected ? Expected[K] : never> } : StrictEqualUsingBranding<Actual, Expected> extends true ? Actual : `Expected: ${PrintType<Expected>}, Actual: ${PrintType<Exclude<Actual, Expected>>}`;
1712
- /**
1713
- * @internal
1714
- */
1715
- //#endregion
1716
1312
  //#region src/types/core/variants.types.d.ts
1717
1313
 
1718
1314
  type MaybeVariantStatus<TState extends Record<string, any> | undefined = Record<string, any>, TRules extends ReglePartialRuleTree<NonNullable<TState>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState>> extends true ? Omit<RegleStatus<TState, TRules, TShortcuts>, '$fields' | keyof RegleStatus<TState, TRules, TShortcuts>['$fields']> & {
@@ -1722,9 +1318,9 @@ type ProcessChildrenFields<TState extends Record<string, any> | undefined, TRule
1722
1318
  type FindCorrespondingVariant<TState extends Record<string, any>, TRules extends any[]> = TRules extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState> ? [F] : FindCorrespondingVariant<TState, R> : [];
1723
1319
  //#endregion
1724
1320
  //#region src/core/useRegle/useRegle.d.ts
1725
- type useRegleFnOptions<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState extends Record<string, any> ? Unwrap<TState> : {}>, TState extends Record<string, any> ? TRules : {}, TValidationGroups> & TAdditionalOptions;
1321
+ type useRegleFnOptions<TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends DeepExact<TRules, ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations>>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState extends Record<string, any> ? Unwrap<TState> : {}>, TState extends Record<string, any> ? (TRules extends Record<string, any> ? TRules : {}) : {}, TValidationGroups> & TAdditionalOptions;
1726
1322
  interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
1727
- <TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules> & TValid, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TValid = (isDeepExact<NoInferLegacy<TRules>, Unwrap<TState extends Record<string, any> ? TState : {}>> extends true ? {} : MismatchInfo<RegleRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules>, NoInferLegacy<TRules>>)>(...params: [state: Maybe<MaybeRef<TState> | DeepReactiveState<TState>>, rulesFactory: TState extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState extends Record<string, any> ? MaybeRef<TRules> | ((...args: any[]) => TRules) : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>])]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleField<NonNullable<TState>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState extends Record<string, any> ? Unwrap<TState> : {}, TRules, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
1323
+ <TState extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules extends DeepExact<TRules, ReglePartialRuleTree<Unwrap<TState extends Record<string, any> ? TState : {}>, Partial<AllRulesDeclarations> & TCustomRules>>, TDecl extends RegleRuleDecl<NonNullable<TState>, Partial<AllRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(...params: [state: Maybe<MaybeRef<TState> | DeepReactiveState<TState>>, rulesFactory: TState extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState extends Record<string, any> ? MaybeRef<TRules> | ((...args: any[]) => TRules) : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<TState, TRules, TAdditionalOptions, TValidationGroups>])]): NonNullable<TState> extends PrimitiveTypes ? RegleSingleField<NonNullable<TState>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState extends Record<string, any> ? Unwrap<TState> : {}, TRules extends Record<string, any> ? TRules : {}, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
1728
1324
  __config?: {
1729
1325
  rules?: () => CustomRulesDeclarationTree;
1730
1326
  modifiers?: RegleBehaviourOptions;
@@ -1751,6 +1347,21 @@ interface useRegleFn<TCustomRules extends Partial<AllRulesDeclarations>, TShortc
1751
1347
  * Docs: {@link https://reglejs.dev/core-concepts/}
1752
1348
  */
1753
1349
 
1350
+ //#endregion
1351
+ //#region src/types/utils/mismatch.types.d.ts
1352
+ /**
1353
+ /**
1354
+ * DeepExact<T, S> is a TypeScript utility type that recursively checks whether the structure of type S
1355
+ * exactly matches the structure of type T, including all nested properties.
1356
+ *
1357
+ * Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
1358
+ */
1359
+ type DeepExact<TInfer, TTree> = NonNullable<TTree> extends MaybeRef<RegleRuleDecl> ? TTree : NonNullable<TTree> extends MaybeRef<RegleCollectionRuleDecl> ? TTree : [keyof TInfer] extends [keyof ExtractFromGetter<TTree>] ? ExactObject<TInfer, TTree> : { [K in keyof TInfer as K extends keyof TTree ? never : K]: TypeError<`Unknown property: <${Coerce<K>}>`> };
1360
+ type ExactObject<TInfer, TTree> = { [K in keyof TTree]: NonNullable<TTree[K]> extends Record<string, any> ? ExtendOnlyRealRecord<TTree[K]> extends true ? NonNullable<TTree[K]> extends MaybeRef<RegleRuleDecl> ? TTree[K] : K extends keyof TInfer ? DeepExact<TInfer[K], NonNullable<TTree[K]>> : TTree[K] : TTree[K] : TTree[K] };
1361
+ type TypeError<Msg> = {
1362
+ [' TypeError']: Msg;
1363
+ };
1364
+ type Coerce<T> = `${T & string}`;
1754
1365
  //#endregion
1755
1366
  //#region src/types/utils/object.types.d.ts
1756
1367
  type RemoveCommonKey<T extends readonly any[], K extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K>>, ...RemoveCommonKey<R, K>] : [];
@@ -1793,10 +1404,6 @@ type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
1793
1404
  type HasNamedKeys<T> = IsUnion<T> extends true ? ProcessHasNamedKeys<LazyJoinDiscriminatedUnions<T>> : ProcessHasNamedKeys<T>;
1794
1405
  type ProcessHasNamedKeys<T> = { [K in keyof NonNullable<T>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T>] extends never ? false : true;
1795
1406
  //#endregion
1796
- //#region src/types/utils/mismatch.types.d.ts
1797
- type isDeepExact<TRules, TTree> = { [K in keyof TRules]-?: CheckDeepExact<NonNullable<TRules[K]>, K extends keyof JoinDiscriminatedUnions<TTree> ? NonNullable<JoinDiscriminatedUnions<TTree>[K]> : never> }[keyof TRules] extends true ? true : false;
1798
- type CheckDeepExact<TRules, TTree> = [TTree] extends [never] ? false : TRules extends RegleCollectionRuleDecl ? TTree extends Array<any> ? isDeepExact<NonNullable<TRules['$each']>, JoinDiscriminatedUnions<NonNullable<ArrayElement$1<TTree>>>> : TRules extends MaybeRef<RegleRuleDecl> ? true : TRules extends ReglePartialRuleTree<any> ? isDeepExact<UnwrapRef<TRules>, TTree> : false : TRules extends MaybeRef<RegleRuleDecl> ? true : TRules extends ReglePartialRuleTree<any> ? isDeepExact<UnwrapRef<TRules>, TTree> : false;
1799
- //#endregion
1800
1407
  //#region src/types/utils/infer.types.d.ts
1801
1408
 
1802
1409
  //#endregion
@@ -2012,10 +1619,6 @@ type AllRulesDeclarations = CustomRulesDeclarationTree & DefaultValidatorsTree;
2012
1619
  * @public
2013
1620
  */
2014
1621
  type ReglePartialRuleTree<TForm extends Record<string, any> = Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = { [TKey in keyof TForm]?: RegleFormPropertyType<TForm[TKey], TCustomRules> };
2015
- /**
2016
- * @public
2017
- */
2018
- type RegleRuleTree<TForm extends Record<string, any>, TCustomRules extends Partial<AllRulesDeclarations> = Partial<AllRulesDeclarations>> = { [TKey in keyof TForm]: RegleFormPropertyType<TForm[TKey], TCustomRules> };
2019
1622
  /**
2020
1623
  * @public
2021
1624
  */
@@ -2225,10 +1828,17 @@ interface RegleCommonStatus<TValue = any> {
2225
1828
  /** A reference to the original validated model. It can be used to bind your form with v-model.*/
2226
1829
  $value: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
2227
1830
  /**
2228
- * Initial value of the field.
1831
+ * This value reflect the current initial value of the field.
1832
+ * The initial value is different than the original value as the initial value can be mutated when using `$reset`.
2229
1833
  */
2230
1834
  readonly $initialValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
2231
- /** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */
1835
+ /**
1836
+ * This value reflect the original value of the field at original call. This can't be mutated
1837
+ */
1838
+ readonly $originalValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
1839
+ /**
1840
+ * `$value` variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction.
1841
+ * */
2232
1842
  $silentValue: JoinDiscriminatedUnions<UnwrapNestedRefs<TValue>>;
2233
1843
  /** Marks the field and all nested properties as $dirty. */
2234
1844
  $touch(): void;
@@ -156,6 +156,7 @@ function createUseRegleSchemaComposable(options, shortcuts) {
156
156
  const isSingleField = computed(() => !isObject(processedState.value));
157
157
  const processedState = isRef(state) ? state : ref(state);
158
158
  const initialState = ref(isObject(processedState.value) ? { ...cloneDeep(processedState.value) } : cloneDeep(processedState.value));
159
+ const originalState = isObject(processedState.value) ? { ...cloneDeep(processedState.value) } : cloneDeep(processedState.value);
159
160
  const customErrors = ref({});
160
161
  let onValidate = void 0;
161
162
  if (!computedSchema.value?.["~standard"]) throw new Error(`Only "standard-schema" compatible libraries are supported`);
@@ -227,6 +228,7 @@ function createUseRegleSchemaComposable(options, shortcuts) {
227
228
  options: resolvedOptions,
228
229
  schemaErrors: customErrors,
229
230
  initialState,
231
+ originalState,
230
232
  shortcuts,
231
233
  schemaMode: true,
232
234
  onValidate
@@ -1 +1 @@
1
- import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,isRef as r,ref as i,unref as a,watch as o}from"vue";function s(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function c(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):s(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}Symbol(`regle-rule`);function l(e){if(typeof e.source.flags==`string`)return e.source.flags;{let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}}function u(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>u(e)))),n==`Map`&&(t=new Map([...e].map(e=>[u(e[0]),u(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,l(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=u(e[n]);return t}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e,t,n,r){var i,a;if(Array.isArray(t)&&(i=t.slice(0)),typeof t==`string`&&(i=t.split(`.`)),typeof t==`symbol`&&(i=[t]),!Array.isArray(i))throw Error(`props arg must be an array, a string or a symbol`);if(a=i.pop(),!a)return!1;m(a);for(var o;o=i.shift();)if(m(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],c(e.$each[o])&&(e.$each[o]={}),e=e.$each[o]),!e||typeof e!=`object`)return!1;return r?e[a]?e[a].$self=(e[a].$self??=[]).concat(n):e[a]={...e[a],$self:n}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function p(e,t,n){if(!e)return n;var r,i;if(Array.isArray(t)&&(r=t.slice(0)),typeof t==`string`&&(r=t.split(`.`)),typeof t==`symbol`&&(r=[t]),!Array.isArray(r))throw Error(`props arg must be an array, a string or a symbol`);for(;r.length;)if(i=r.shift(),!e||!i||(e=e[i],e===void 0))return n;return e}function m(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function h(e,...t){for(var n=[].slice.call(arguments),r,i=n.length;r=n[i-1],i--;)if(!r||typeof r!=`object`&&typeof r!=`function`)throw Error(`expected object, got `+r);for(var a=n[0],o=n.slice(1),s=o.length,i=0;i<s;i++){var c=o[i];for(var l in c)a[l]=c[l]}return a}function g(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function l(e,l,m){let g=n(()=>a(l)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=m??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!d(C.value)),C=r(e)?e:i(e),w=i(d(C.value)?{...u(C.value)}:u(C.value)),T=i({}),E;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function D(e){let t={};if(e.issues){let n=e.issues.map(e=>{let t=e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``,n=e.path?.[e.path.length-1],r=typeof n==`object`?n.key:n,i=(typeof n==`object`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(p(C.value,t)),a=!i&&typeof r==`number`;return a&&(t=e.path?.slice(0,e.path.length-1)?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``),{...e,$path:t,isArray:i,$property:r,$rule:`schema`,$message:e.message}});n.forEach(({isArray:e,$path:n,...r})=>{f(t,n,[r],e)})}return t}async function O(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?T.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:T.value=D(t),t.issues||(e&&b||!e&&y)&&(k?.(),d(C.value)?C.value=h(C.value,t.value):C.value=t.value,A()),t}let k;function A(){k=o([C,g],()=>O(),{deep:!0})}A(),O(),E=async()=>{try{let e=await O(!0);return{valid:!e.issues?.length,data:C.value}}catch(e){return Promise.reject(e)}};let j=t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:T,initialState:w,shortcuts:s,schemaMode:!0,onValidate:E});return{r$:j.regle}}return l}const _=g();function v(e,t){return e}function y(){function e(e,t){return t}return e}const b=y();function x({modifiers:e,shortcuts:t}){let n=g(e,t),r=y();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:S,useScopedRegle:C}=e({customUseRegle:_}),w=t=>{let{customStore:n,customUseRegle:r=_,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{w as createScopedUseRegleSchema,x as defineRegleSchemaConfig,b as inferSchema,S as useCollectSchemaScope,_ as useRegleSchema,C as useScopedRegleSchema,v as withDeps};
1
+ import{createScopedUseRegle as e,useRootStorage as t}from"@regle/core";import{computed as n,isRef as r,ref as i,unref as a,watch as o}from"vue";function s(e){return e?.constructor.name==`File`||e?.constructor.name==`FileList`}function c(e,t=!0){return e==null?!0:e instanceof Date?isNaN(e.getTime()):s(e)?e.size<=0:Array.isArray(e)?t?e.length===0:!1:typeof e==`object`&&e?Object.keys(e).length===0:!String(e).length}Symbol(`regle-rule`);function l(e){if(typeof e.source.flags==`string`)return e.source.flags;{let t=[];return e.global&&t.push(`g`),e.ignoreCase&&t.push(`i`),e.multiline&&t.push(`m`),e.sticky&&t.push(`y`),e.unicode&&t.push(`u`),t.join(``)}}function u(e){let t=e,n={}.toString.call(e).slice(8,-1);if(n==`Set`&&(t=new Set([...e].map(e=>u(e)))),n==`Map`&&(t=new Map([...e].map(e=>[u(e[0]),u(e[1])]))),n==`Date`&&(t=new Date(e.getTime())),n==`RegExp`&&(t=RegExp(e.source,l(e))),n==`Array`||n==`Object`)for(let n in t=Array.isArray(e)?[]:{},e)t[n]=u(e[n]);return t}function d(e){return e&&(e instanceof Date||e.constructor.name==`File`||e.constructor.name==`FileList`)?!1:typeof e==`object`&&!!e&&!Array.isArray(e)}function f(e,t,n,r){var i,a;if(Array.isArray(t)&&(i=t.slice(0)),typeof t==`string`&&(i=t.split(`.`)),typeof t==`symbol`&&(i=[t]),!Array.isArray(i))throw Error(`props arg must be an array, a string or a symbol`);if(a=i.pop(),!a)return!1;m(a);for(var o;o=i.shift();)if(m(o),isNaN(parseInt(o))?(e[o]===void 0&&(e[o]={}),e=e[o]):(e.$each??=[],c(e.$each[o])&&(e.$each[o]={}),e=e.$each[o]),!e||typeof e!=`object`)return!1;return r?e[a]?e[a].$self=(e[a].$self??=[]).concat(n):e[a]={...e[a],$self:n}:Array.isArray(e[a])?e[a]=e[a].concat(n):e[a]=n,!0}function p(e,t,n){if(!e)return n;var r,i;if(Array.isArray(t)&&(r=t.slice(0)),typeof t==`string`&&(r=t.split(`.`)),typeof t==`symbol`&&(r=[t]),!Array.isArray(r))throw Error(`props arg must be an array, a string or a symbol`);for(;r.length;)if(i=r.shift(),!e||!i||(e=e[i],e===void 0))return n;return e}function m(e){if(e==`__proto__`||e==`constructor`||e==`prototype`)throw Error(`setting of prototype values not supported`)}function h(e,...t){for(var n=[].slice.call(arguments),r,i=n.length;r=n[i-1],i--;)if(!r||typeof r!=`object`&&typeof r!=`function`)throw Error(`expected object, got `+r);for(var a=n[0],o=n.slice(1),s=o.length,i=0;i<s;i++){var c=o[i];for(var l in c)a[l]=c[l]}return a}function g(e,s){let c={autoDirty:e?.autoDirty,lazy:e?.lazy,rewardEarly:e?.rewardEarly,clearExternalErrorsOnChange:e?.clearExternalErrorsOnChange};function l(e,l,m){let g=n(()=>a(l)),{syncState:_={onUpdate:!1,onValidate:!1},...v}=m??{},{onUpdate:y=!1,onValidate:b=!1}=_,x={...c,...v},S=n(()=>!d(C.value)),C=r(e)?e:i(e),w=i(d(C.value)?{...u(C.value)}:u(C.value)),T=d(C.value)?{...u(C.value)}:u(C.value),E=i({}),D;if(!g.value?.[`~standard`])throw Error(`Only "standard-schema" compatible libraries are supported`);function O(e){let t={};if(e.issues){let n=e.issues.map(e=>{let t=e.path?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``,n=e.path?.[e.path.length-1],r=typeof n==`object`?n.key:n,i=(typeof n==`object`&&`value`in n?Array.isArray(n.value):!1)||(`type`in e?e.type===`array`:!1)||Array.isArray(p(C.value,t)),a=!i&&typeof r==`number`;return a&&(t=e.path?.slice(0,e.path.length-1)?.map(e=>typeof e==`object`?e.key:e.toString()).join(`.`)??``),{...e,$path:t,isArray:i,$property:r,$rule:`schema`,$message:e.message}});n.forEach(({isArray:e,$path:n,...r})=>{f(t,n,[r],e)})}return t}async function k(e=!1){let t=g.value[`~standard`].validate(C.value);return t instanceof Promise&&(t=await t),S.value?E.value=t.issues?.map(e=>({$message:e.message,$property:e.path?.[e.path.length-1]?.toString()??`-`,$rule:`schema`,...e}))??[]:E.value=O(t),t.issues||(e&&b||!e&&y)&&(A?.(),d(C.value)?C.value=h(C.value,t.value):C.value=t.value,j()),t}let A;function j(){A=o([C,g],()=>k(),{deep:!0})}j(),k(),D=async()=>{try{let e=await k(!0);return{valid:!e.issues?.length,data:C.value}}catch(e){return Promise.reject(e)}};let M=t({scopeRules:n(()=>({})),state:C,options:x,schemaErrors:E,initialState:w,originalState:T,shortcuts:s,schemaMode:!0,onValidate:D});return{r$:M.regle}}return l}const _=g();function v(e,t){return e}function y(){function e(e,t){return t}return e}const b=y();function x({modifiers:e,shortcuts:t}){let n=g(e,t),r=y();return{useRegleSchema:n,inferSchema:r}}const{useCollectScope:S,useScopedRegle:C}=e({customUseRegle:_}),w=t=>{let{customStore:n,customUseRegle:r=_,asRecord:i=!1}=t??{};return e({customStore:n,customUseRegle:r,asRecord:i})};export{w as createScopedUseRegleSchema,x as defineRegleSchemaConfig,b as inferSchema,S as useCollectSchemaScope,_ as useRegleSchema,C as useScopedRegleSchema,v as withDeps};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@regle/schemas",
3
- "version": "1.7.2",
3
+ "version": "1.8.0-beta.2",
4
4
  "description": "Schemas adapter for Regle",
5
5
  "dependencies": {
6
6
  "@standard-schema/spec": "1.0.0",
7
- "@regle/core": "1.7.2",
8
- "@regle/rules": "1.7.2"
7
+ "@regle/core": "1.8.0-beta.2",
8
+ "@regle/rules": "1.8.0-beta.2"
9
9
  },
10
10
  "peerDependencies": {
11
11
  "valibot": "^1.0.0",