typebox 1.1.31 → 1.1.33

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.
Files changed (87) hide show
  1. package/build/guard/guard.d.mts +4 -0
  2. package/build/guard/guard.mjs +6 -0
  3. package/build/system/locale/_config.d.mts +1 -1
  4. package/build/system/locale/ar_001.d.mts +1 -1
  5. package/build/system/locale/bn_BD.d.mts +1 -1
  6. package/build/system/locale/cs_CZ.d.mts +1 -1
  7. package/build/system/locale/de_DE.d.mts +1 -1
  8. package/build/system/locale/el_GR.d.mts +1 -1
  9. package/build/system/locale/en_US.d.mts +1 -1
  10. package/build/system/locale/es_419.d.mts +1 -1
  11. package/build/system/locale/es_AR.d.mts +1 -1
  12. package/build/system/locale/es_ES.d.mts +1 -1
  13. package/build/system/locale/es_MX.d.mts +1 -1
  14. package/build/system/locale/fa_IR.d.mts +1 -1
  15. package/build/system/locale/fil_PH.d.mts +1 -1
  16. package/build/system/locale/fr_CA.d.mts +1 -1
  17. package/build/system/locale/fr_FR.d.mts +1 -1
  18. package/build/system/locale/ha_NG.d.mts +1 -1
  19. package/build/system/locale/hi_IN.d.mts +1 -1
  20. package/build/system/locale/hu_HU.d.mts +1 -1
  21. package/build/system/locale/id_ID.d.mts +1 -1
  22. package/build/system/locale/it_IT.d.mts +1 -1
  23. package/build/system/locale/ja_JP.d.mts +1 -1
  24. package/build/system/locale/ko_KR.d.mts +1 -1
  25. package/build/system/locale/ms_MY.d.mts +1 -1
  26. package/build/system/locale/nl_NL.d.mts +1 -1
  27. package/build/system/locale/pl_PL.d.mts +1 -1
  28. package/build/system/locale/pt_BR.d.mts +1 -1
  29. package/build/system/locale/pt_PT.d.mts +1 -1
  30. package/build/system/locale/ro_RO.d.mts +1 -1
  31. package/build/system/locale/ru_RU.d.mts +1 -1
  32. package/build/system/locale/sv_SE.d.mts +1 -1
  33. package/build/system/locale/sw_TZ.d.mts +1 -1
  34. package/build/system/locale/th_TH.d.mts +1 -1
  35. package/build/system/locale/tr_TR.d.mts +1 -1
  36. package/build/system/locale/uk_UA.d.mts +1 -1
  37. package/build/system/locale/ur_PK.d.mts +1 -1
  38. package/build/system/locale/vi_VN.d.mts +1 -1
  39. package/build/system/locale/yo_NG.d.mts +1 -1
  40. package/build/system/locale/zh_Hans.d.mts +1 -1
  41. package/build/system/locale/zh_Hant.d.mts +1 -1
  42. package/build/type/engine/call/distribute-arguments.mjs +1 -7
  43. package/build/type/engine/call/resolve-arguments.mjs +3 -9
  44. package/build/type/engine/cyclic/candidates.d.mts +1 -1
  45. package/build/type/engine/cyclic/check.mjs +4 -7
  46. package/build/type/engine/evaluate/distribute.mjs +7 -17
  47. package/build/type/engine/evaluate/flatten.d.mts +1 -1
  48. package/build/type/engine/evaluate/narrow.d.mts +3 -3
  49. package/build/type/engine/indexable/from-literal.d.mts +1 -1
  50. package/build/type/engine/indexable/from-type.d.mts +6 -6
  51. package/build/type/engine/instantiate.d.mts +2 -2
  52. package/build/type/engine/instantiate.mjs +5 -9
  53. package/build/type/engine/object/from-union.mjs +3 -10
  54. package/build/type/engine/ref/instantiate.d.mts +1 -1
  55. package/build/type/engine/template-literal/decode.d.mts +2 -2
  56. package/build/type/engine/template-literal/decode.mjs +4 -10
  57. package/build/type/engine/template-literal/encode.d.mts +1 -1
  58. package/build/type/engine/template-literal/encode.mjs +3 -9
  59. package/build/type/engine/template-literal/is-finite.mjs +3 -7
  60. package/build/type/engine/this/expand-this.mjs +6 -6
  61. package/build/type/extends/extends-right.mjs +3 -2
  62. package/build/type/extends/inference.mjs +1 -1
  63. package/build/type/extends/literal.d.mts +1 -1
  64. package/build/type/extends/literal.mjs +1 -1
  65. package/build/type/extends/parameters.mjs +3 -2
  66. package/build/type/extends/result.d.mts +1 -4
  67. package/build/type/extends/result.mjs +0 -3
  68. package/build/type/extends/tuple.mjs +3 -3
  69. package/build/type/extends/union.mjs +3 -2
  70. package/build/type/script/token/internal/guard.d.mts +1 -1
  71. package/build/type/script/token/internal/guard.mjs +1 -1
  72. package/build/type/script/token/internal/take.mjs +5 -9
  73. package/build/type/script/token/until.mjs +4 -7
  74. package/build/type/types/array.d.mts +2 -1
  75. package/build/type/types/array.mjs +2 -1
  76. package/build/type/types/function.mjs +1 -1
  77. package/build/type/types/object.mjs +1 -1
  78. package/build/value/clean/from-cyclic.d.mts +1 -1
  79. package/build/value/convert/from-literal.d.mts +1 -1
  80. package/build/value/convert/try/try-bigint.d.mts +1 -1
  81. package/build/value/convert/try/try-boolean.d.mts +1 -1
  82. package/build/value/convert/try/try-null.d.mts +1 -1
  83. package/build/value/convert/try/try-number.d.mts +1 -1
  84. package/build/value/convert/try/try-string.d.mts +1 -1
  85. package/build/value/convert/try/try-undefined.d.mts +1 -1
  86. package/build/value/default/from-intersect.d.mts +1 -1
  87. package/package.json +30 -30
@@ -43,8 +43,12 @@ export declare function GraphemeCount(value: string): number;
43
43
  export declare function IsMaxLength(value: string, length: number): boolean;
44
44
  /** Returns true if the string has at least the given number of graphemes */
45
45
  export declare function IsMinLength(value: string, length: number): boolean;
46
+ /** Returns true if all elements from offset satisfy the callback, short-circuiting on the first failure */
46
47
  export declare function Every<T>(value: T[], offset: number, callback: (value: T, index: number) => boolean): boolean;
48
+ /** Returns true if all elements from offset satisfy the callback, visiting every element regardless of failure */
47
49
  export declare function EveryAll<T>(value: T[], offset: number, callback: (value: T, index: number) => boolean): boolean;
50
+ /** Takes the left-most element from an array and dispatches to the true arm, or the false arm if empty */
51
+ export declare function TakeLeft<T, True extends (left: T, right: T[]) => unknown, False extends () => unknown>(array: T[], true_: True, false_: False): ReturnType<True> | ReturnType<False>;
48
52
  /** Returns true if this value has this property key */
49
53
  export declare function HasPropertyKey<Key extends PropertyKey>(value: object, key: Key): value is {
50
54
  [_ in Key]: unknown;
@@ -145,6 +145,7 @@ export function IsMinLength(value, length) {
145
145
  // --------------------------------------------------------------------------
146
146
  // Array
147
147
  // --------------------------------------------------------------------------
148
+ /** Returns true if all elements from offset satisfy the callback, short-circuiting on the first failure */
148
149
  export function Every(value, offset, callback) {
149
150
  for (let index = offset; index < value.length; index++) {
150
151
  if (!callback(value[index], index))
@@ -152,6 +153,7 @@ export function Every(value, offset, callback) {
152
153
  }
153
154
  return true;
154
155
  }
156
+ /** Returns true if all elements from offset satisfy the callback, visiting every element regardless of failure */
155
157
  export function EveryAll(value, offset, callback) {
156
158
  let result = true;
157
159
  for (let index = offset; index < value.length; index++) {
@@ -160,6 +162,10 @@ export function EveryAll(value, offset, callback) {
160
162
  }
161
163
  return result;
162
164
  }
165
+ /** Takes the left-most element from an array and dispatches to the true arm, or the false arm if empty */
166
+ export function TakeLeft(array, true_, false_) {
167
+ return (IsEqual(array.length, 0) ? false_() : true_(array[0], array.slice(1)));
168
+ }
163
169
  // --------------------------------------------------------------------------
164
170
  // Object
165
171
  // --------------------------------------------------------------------------
@@ -1,4 +1,4 @@
1
- import { TLocalizedValidationMessageCallback } from '../../error/index.mjs';
1
+ import { type TLocalizedValidationMessageCallback } from '../../error/index.mjs';
2
2
  /** Sets the locale */
3
3
  export declare function Set(callback: TLocalizedValidationMessageCallback): void;
4
4
  /** Gets the locale */
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Arabic (World) - ISO 639-1 language code 'ar' with UN M.49 region code '001' for World. */
3
3
  export declare function ar_001(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Bengali (Bangladesh) - ISO 639-1 language code 'bn' with ISO 3166-1 alpha-2 country code 'BD' for Bangladesh. */
3
3
  export declare function bn_BD(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Czech (Czech Republic) - ISO 639-1 language code 'cs' with ISO 3166-1 alpha-2 country code 'CZ' for Czech Republic. */
3
3
  export declare function cs_CZ(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** German (Germany) - ISO 639-1 language code 'de' with ISO 3166-1 alpha-2 country code 'DE' for Germany. */
3
3
  export declare function de_DE(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Greek (Greece) - ISO 639-1 language code 'el' with ISO 3166-1 alpha-2 country code 'GR' for Greece. */
3
3
  export declare function el_GR(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** en_US: English (United States) - ISO 639-1 language code 'en' with ISO 3166-1 alpha-2 country code 'US' for United States. */
3
3
  export declare function en_US(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Spanish (Latin America) - ISO 639-1 language code 'es' with UN M.49 region code '419' for Latin America and the Caribbean. */
3
3
  export declare function es_419(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Spanish (Argentina) - ISO 639-1 language code 'es' with ISO 3166-1 alpha-2 country code 'AR' for Argentina. */
3
3
  export declare function es_AR(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Spanish (Spain) - ISO 639-1 language code 'es' with ISO 3166-1 alpha-2 country code 'ES' for Spain. */
3
3
  export declare function es_ES(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Spanish (Mexico) - ISO 639-1 language code 'es' with ISO 3166-1 alpha-2 country code 'MX' for Mexico. */
3
3
  export declare function es_MX(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Persian (Iran) - ISO 639-1 language code 'fa' with ISO 3166-1 alpha-2 country code 'IR' for Iran. */
3
3
  export declare function fa_IR(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Filipino (Philippines) - ISO 639-1 language code 'fil' with ISO 3166-1 */
3
3
  export declare function fil_PH(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** French (Canada) - ISO 639-1 language code 'fr' with ISO 3166-1 alpha-2 country code 'CA' for Canada. */
3
3
  export declare function fr_CA(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** French (France) - ISO 639-1 language code 'fr' with ISO 3166-1 alpha-2 country code 'FR' for France. */
3
3
  export declare function fr_FR(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Hausa (Nigeria) - ISO 639-1 language code 'ha' with ISO 3166-1 alpha-2 country code 'NG' for Nigeria. */
3
3
  export declare function ha_NG(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Hindi (India) - ISO 639-1 language code 'hi' with ISO 3166-1 alpha-2 country code 'IN' for India. */
3
3
  export declare function hi_IN(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Hungarian (Hungary) - ISO 639-1 language code 'hu' with ISO 3166-1 alpha-2 country code 'HU' for Hungary. */
3
3
  export declare function hu_HU(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Indonesian (Indonesia) - ISO 639-1 language code 'id' with ISO 3166-1 alpha-2 country code 'ID' for Indonesia. */
3
3
  export declare function id_ID(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Italian (Italy) - ISO 639-1 language code 'it' with ISO 3166-1 alpha-2 country code 'IT' for Italy. */
3
3
  export declare function it_IT(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Japanese (Japan) - ISO 639-1 language code 'ja' with ISO 3166-1 alpha-2 country code 'JP' for Japan. */
3
3
  export declare function ja_JP(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Korean (South Korea) - ISO 639-1 language code 'ko' with ISO 3166-1 alpha-2 country code 'KR' for South Korea. */
3
3
  export declare function ko_KR(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Malay (Malaysia) - ISO 639-1 language code 'ms' with ISO 3166-1 alpha-2 country code 'MY' for Malaysia. */
3
3
  export declare function ms_MY(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Dutch (Netherlands) - ISO 639-1 language code 'nl' with ISO 3166-1 alpha-2 country code 'NL' for Netherlands. */
3
3
  export declare function nl_NL(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Polish (Poland) - ISO 639-1 language code 'pl' with ISO 3166-1 alpha-2 country code 'PL' for Poland. */
3
3
  export declare function pl_PL(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Portuguese (Brazil) - ISO 639-1 language code 'pt' with ISO 3166-1 alpha-2 country code 'BR' for Brazil. */
3
3
  export declare function pt_BR(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Portuguese (Portugal) - ISO 639-1 language code 'pt' with ISO 3166-1 alpha-2 country code 'PT' for Portugal. */
3
3
  export declare function pt_PT(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Romanian (Romania) - ISO 639-1 language code 'ro' with ISO 3166-1 alpha-2 country code 'RO' for Romania. */
3
3
  export declare function ro_RO(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Russian (Russia) - ISO 639-1 language code 'ru' with ISO 3166-1 alpha-2 country code 'RU' for Russia. */
3
3
  export declare function ru_RU(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Swedish (Sweden) - ISO 639-1 language code 'sv' with ISO 3166-1 alpha-2 country code 'SE' for Sweden. */
3
3
  export declare function sv_SE(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Swahili (Tanzania) - ISO 639-1 language code 'sw' with ISO 3166-1 alpha-2 country code 'TZ' for Tanzania (as a common representative). */
3
3
  export declare function sw_TZ(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Thai (Thailand) - ISO 639-1 language code 'th' with ISO 3166-1 alpha-2 country code 'TH' for Thailand. */
3
3
  export declare function th_TH(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Turkish (Turkey) - ISO 639-1 language code 'tr' with ISO 3166-1 alpha-2 country code 'TR' for Turkey. */
3
3
  export declare function tr_TR(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Ukrainian (Ukraine) - ISO 639-1 language code 'uk' with ISO 3166-1 alpha-2 country code 'UA' for Ukraine. */
3
3
  export declare function uk_UA(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Urdu (Pakistan) - ISO 639-1 language code 'ur' with ISO 3166-1 alpha-2 country code 'PK' for Pakistan. */
3
3
  export declare function ur_PK(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Vietnamese (Vietnam) - ISO 639-1 language code 'vi' with ISO 3166-1 alpha-2 country code 'VN' for Vietnam. */
3
3
  export declare function vi_VN(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Yoruba (Nigeria) - ISO 639-1 language code 'yo' with ISO 3166-1 alpha-2 country code 'NG' for Nigeria. */
3
3
  export declare function yo_NG(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Chinese (Simplified) - ISO 639-1 language code 'zh' with script code 'Hans' for Simplified Chinese. */
3
3
  export declare function zh_Hans(error: TValidationError): string;
@@ -1,3 +1,3 @@
1
- import { TValidationError } from '../../error/index.mjs';
1
+ import { type TValidationError } from '../../error/index.mjs';
2
2
  /** Chinese (Traditional) - ISO 639-1 language code 'zh' with script code 'Hant' for Traditional Chinese. */
3
3
  export declare function zh_Hant(error: TValidationError): string;
@@ -19,13 +19,7 @@ function BuildDistributionArray(parameters, names) {
19
19
  return parameters.reduce((result, left) => [...result, names.includes(left.name)], []);
20
20
  }
21
21
  function ZipDistributionArray(arguments_, distributionArray, result = []) {
22
- const [argumentLeft, ...argumentRight] = arguments_;
23
- const [booleanLeft, ...booleanRight] = distributionArray;
24
- return (Guard.IsGreaterThan(arguments_.length, 0)
25
- ? Guard.IsGreaterThan(distributionArray.length, 0)
26
- ? ZipDistributionArray(argumentRight, booleanRight, [...result, [booleanLeft, argumentLeft]])
27
- : result
28
- : result);
22
+ return Guard.TakeLeft(arguments_, (argumentLeft, argumentRight) => Guard.TakeLeft(distributionArray, (booleanLeft, booleanRight) => ZipDistributionArray(argumentRight, booleanRight, [...result, [booleanLeft, argumentLeft]]), () => result), () => result);
29
23
  }
30
24
  function Expand(type) {
31
25
  return (IsUnion(type)
@@ -1,6 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
+ import { Guard } from '../../../guard/index.mjs';
2
3
  import { Memory } from '../../../system/memory/index.mjs';
3
- import { IsSchema } from '../../types/schema.mjs';
4
4
  import { InstantiateType } from '../instantiate.mjs';
5
5
  import { Extends, ExtendsResult } from '../../extends/index.mjs';
6
6
  import { IsInfer } from '../../types/infer.mjs';
@@ -23,16 +23,10 @@ function BindArgument(context, state, name, extends_, type) {
23
23
  function BindArguments(context, state, parameterLeft, parameterRight, arguments_) {
24
24
  const instantiatedExtends = InstantiateType(context, state, parameterLeft.extends);
25
25
  const instantiatedEquals = InstantiateType(context, state, parameterLeft.equals);
26
- const [left, ...right] = arguments_;
27
- return (IsSchema(left)
28
- ? BindParameters(BindArgument(context, state, parameterLeft['name'], instantiatedExtends, left), state, parameterRight, right)
29
- : BindParameters(BindArgument(context, state, parameterLeft['name'], instantiatedExtends, instantiatedEquals), state, parameterRight, []));
26
+ return Guard.TakeLeft(arguments_, (left, right) => BindParameters(BindArgument(context, state, parameterLeft['name'], instantiatedExtends, left), state, parameterRight, right), () => BindParameters(BindArgument(context, state, parameterLeft['name'], instantiatedExtends, instantiatedEquals), state, parameterRight, []));
30
27
  }
31
28
  function BindParameters(context, state, parameters, arguments_) {
32
- const [left, ...right] = parameters;
33
- return (IsSchema(left)
34
- ? BindArguments(context, state, left, right, arguments_)
35
- : context);
29
+ return Guard.TakeLeft(parameters, (left, right) => BindArguments(context, state, left, right, arguments_), () => context);
36
30
  }
37
31
  export function ResolveArgumentsContext(context, state, parameters, arguments_) {
38
32
  return BindParameters(context, state, parameters, arguments_);
@@ -1,5 +1,5 @@
1
1
  import { type TUnreachable } from '../../../system/unreachable/index.mjs';
2
- import { type TProperties, TPropertyKeys } from '../../types/properties.mjs';
2
+ import { type TProperties, type TPropertyKeys } from '../../types/properties.mjs';
3
3
  import { type TCyclicCheck } from './check.mjs';
4
4
  type TResolveCandidateKeys<Context extends TProperties, Keys extends string[], Result extends string[] = []> = (Keys extends [infer Left extends string, ...infer Right extends string[]] ? Left extends keyof Context ? TCyclicCheck<[Left], Context, Context[Left]> extends true ? TResolveCandidateKeys<Context, Right, [...Result, Left]> : TResolveCandidateKeys<Context, Right, Result> : TUnreachable : Result);
5
5
  /** Returns keys for context types that need to be transformed to TCyclic. */
@@ -1,5 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
- import { IsSchema } from '../../types/schema.mjs';
2
+ import { Guard } from '../../../guard/index.mjs';
3
3
  import { IsArray } from '../../types/array.mjs';
4
4
  import { IsAsyncIterator } from '../../types/async-iterator.mjs';
5
5
  import { IsConstructor } from '../../types/constructor.mjs';
@@ -24,12 +24,9 @@ function FromProperties(stack, context, properties) {
24
24
  return FromTypes(stack, context, types);
25
25
  }
26
26
  function FromTypes(stack, context, types) {
27
- const [left, ...right] = types;
28
- return (IsSchema(left)
29
- ? FromType(stack, context, left)
30
- ? true
31
- : FromTypes(stack, context, right)
32
- : false);
27
+ return Guard.TakeLeft(types, (left, right) => FromType(stack, context, left)
28
+ ? true
29
+ : FromTypes(stack, context, right), () => false);
33
30
  }
34
31
  function FromType(stack, context, type) {
35
32
  return (IsRef(type) ? FromRef(stack, context, type.$ref) :
@@ -1,7 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
2
  // deno-fmt-ignore-file
3
3
  import { Guard } from '../../../guard/index.mjs';
4
- import { IsSchema } from '../../types/schema.mjs';
5
4
  import { IsUnion } from '../../types/union.mjs';
6
5
  import { IsObject } from '../../types/object.mjs';
7
6
  import { IsTuple } from '../../types/tuple.mjs';
@@ -32,24 +31,15 @@ function DistributeOperation(left, right) {
32
31
  return result;
33
32
  }
34
33
  function DistributeType(type, types, result = []) {
35
- const [left, ...right] = types;
36
- return (!Guard.IsUndefined(left) // TSchema[]
37
- ? DistributeType(type, right, [...result, DistributeOperation(type, left)])
38
- : result.length === 0
39
- ? [type]
40
- : result);
34
+ return Guard.TakeLeft(types, (left, right) => DistributeType(type, right, [...result, DistributeOperation(type, left)]), () => Guard.IsEqual(result.length, 0)
35
+ ? [type]
36
+ : result);
41
37
  }
42
38
  function DistributeUnion(types, distribution, result = []) {
43
- const [left, ...right] = types;
44
- return (IsSchema(left)
45
- ? DistributeUnion(right, distribution, [...result, ...Distribute([left], distribution)])
46
- : result);
39
+ return Guard.TakeLeft(types, (left, right) => DistributeUnion(right, distribution, [...result, ...Distribute([left], distribution)]), () => result);
47
40
  }
48
41
  export function Distribute(types, result = []) {
49
- const [left, ...right] = types;
50
- return (IsSchema(left)
51
- ? IsUnion(left)
52
- ? Distribute(right, DistributeUnion(left.anyOf, result))
53
- : Distribute(right, DistributeType(left, result))
54
- : result);
42
+ return Guard.TakeLeft(types, (left, right) => IsUnion(left)
43
+ ? Distribute(right, DistributeUnion(left.anyOf, result))
44
+ : Distribute(right, DistributeType(left, result)), () => result);
55
45
  }
@@ -1,4 +1,4 @@
1
- import { TSchema } from '../../types/schema.mjs';
1
+ import { type TSchema } from '../../types/schema.mjs';
2
2
  import { type TUnion } from '../../types/union.mjs';
3
3
  type TFlattenType<Type extends TSchema, Result extends TSchema[] = Type extends TUnion<infer Types extends TSchema[]> ? TFlatten<Types> : [Type]> = Result;
4
4
  export type TFlatten<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFlatten<Right, [...Result, ...TFlattenType<Left>]> : Result);
@@ -1,5 +1,5 @@
1
- import { TSchema } from '../../types/schema.mjs';
2
- import { TNever } from '../../types/never.mjs';
3
- import { TCompare, TCompareResult, ResultLeftInside, ResultRightInside, ResultEqual } from './compare.mjs';
1
+ import { type TSchema } from '../../types/schema.mjs';
2
+ import { type TNever } from '../../types/never.mjs';
3
+ import { type TCompare, type TCompareResult, ResultLeftInside, ResultRightInside, ResultEqual } from './compare.mjs';
4
4
  export type TNarrow<Left extends TSchema, Right extends TSchema, Result extends TCompareResult = TCompare<Left, Right>> = (Result extends typeof ResultLeftInside ? Left : Result extends typeof ResultRightInside ? Right : Result extends typeof ResultEqual ? Right : TNever);
5
5
  export declare function Narrow<Left extends TSchema, Right extends TSchema>(left: Left, right: Right): TNarrow<Left, Right>;
@@ -1,3 +1,3 @@
1
- import { TLiteralValue } from '../../types/literal.mjs';
1
+ import { type TLiteralValue } from '../../types/literal.mjs';
2
2
  export type TFromLiteral<Value extends TLiteralValue, Result extends string[] = [`${Value}`]> = Result;
3
3
  export declare function FromLiteral<Value extends TLiteralValue>(value: Value): TFromLiteral<Value>;
@@ -6,12 +6,12 @@ import { type TLiteral, type TLiteralValue } from '../../types/literal.mjs';
6
6
  import { type TProperties } from '../../types/properties.mjs';
7
7
  import { type TTemplateLiteral } from '../../types/template-literal.mjs';
8
8
  import { type TUnion } from '../../types/union.mjs';
9
- import { TFromCyclic } from './from-cyclic.mjs';
10
- import { TFromEnum } from './from-enum.mjs';
11
- import { TFromIntersect } from './from-intersect.mjs';
12
- import { TFromLiteral } from './from-literal.mjs';
13
- import { TFromTemplateLiteral } from './from-template-literal.mjs';
14
- import { TFromUnion } from './from-union.mjs';
9
+ import { type TFromCyclic } from './from-cyclic.mjs';
10
+ import { type TFromEnum } from './from-enum.mjs';
11
+ import { type TFromIntersect } from './from-intersect.mjs';
12
+ import { type TFromLiteral } from './from-literal.mjs';
13
+ import { type TFromTemplateLiteral } from './from-template-literal.mjs';
14
+ import { type TFromUnion } from './from-union.mjs';
15
15
  export type TFromType<Indexer extends TSchema, Result extends string[] = (Indexer extends TCyclic<infer Defs extends TProperties, infer Ref extends string> ? TFromCyclic<Defs, Ref> : Indexer extends TEnum<infer Values extends TEnumValue[]> ? TFromEnum<Values> : Indexer extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types> : Indexer extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral<Value> : Indexer extends TTemplateLiteral<infer Pattern extends string> ? TFromTemplateLiteral<Pattern> : Indexer extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : [
16
16
  ])> = Result;
17
17
  export declare function FromType<Indexer extends TSchema>(type: Indexer): TFromType<Indexer>;
@@ -1,6 +1,6 @@
1
1
  import { type TImmutable } from '../types/_immutable.mjs';
2
- import { type TOptional, TOptionalAdd, TOptionalRemove } from '../types/_optional.mjs';
3
- import { type TReadonly, TReadonlyAdd, TReadonlyRemove } from '../types/_readonly.mjs';
2
+ import { type TOptional, type TOptionalAdd, type TOptionalRemove } from '../types/_optional.mjs';
3
+ import { type TReadonly, type TReadonlyAdd, type TReadonlyRemove } from '../types/_readonly.mjs';
4
4
  import { type TSchema } from '../types/schema.mjs';
5
5
  import { type TArray } from '../types/array.mjs';
6
6
  import { type TAsyncIterator } from '../types/async-iterator.mjs';
@@ -11,8 +11,7 @@ import { IsReadonly, ReadonlyAdd, ReadonlyRemove } from '../types/_readonly.mjs'
11
11
  // Types
12
12
  // ------------------------------------------------------------------
13
13
  import { IsBase } from '../types/base.mjs';
14
- import { IsSchema } from '../types/schema.mjs';
15
- import { Array, IsArray, ArrayOptions } from '../types/array.mjs';
14
+ import { _Array_, IsArray, ArrayOptions } from '../types/array.mjs';
16
15
  import { AsyncIterator, IsAsyncIterator, AsyncIteratorOptions } from '../types/async-iterator.mjs';
17
16
  import { Constructor, IsConstructor, ConstructorOptions } from '../types/constructor.mjs';
18
17
  import { Deferred, IsDeferred } from '../types/deferred.mjs';
@@ -66,12 +65,9 @@ import { UncapitalizeInstantiate } from './intrinsics/instantiate.mjs';
66
65
  import { UppercaseInstantiate } from './intrinsics/instantiate.mjs';
67
66
  import { RestSpread } from './rest/index.mjs';
68
67
  export function CanInstantiate(types) {
69
- const [left, ...right] = types;
70
- return (IsSchema(left)
71
- ? IsRef(left)
72
- ? false
73
- : CanInstantiate(right)
74
- : true);
68
+ return Guard.TakeLeft(types, (left, right) => IsRef(left)
69
+ ? false
70
+ : CanInstantiate(right), () => true);
75
71
  }
76
72
  function ModifierActions(type, readonly, optional) {
77
73
  return (IsReadonlyRemoveAction(type) ? ModifierActions(type.type, 'remove', optional) :
@@ -138,7 +134,7 @@ export function InstantiateType(context, state, input) {
138
134
  const modifiers = ModifierActions(input, IsReadonly(input) ? 'add' : 'none', IsOptional(input) ? 'add' : 'none');
139
135
  const type = IsBase(modifiers[0]) ? modifiers[0].Clone() : modifiers[0];
140
136
  const instantiated = (IsRef(type) ? RefInstantiate(context, state, type, type.$ref) :
141
- IsArray(type) ? Array(InstantiateType(context, state, type.items), ArrayOptions(type)) :
137
+ IsArray(type) ? _Array_(InstantiateType(context, state, type.items), ArrayOptions(type)) :
142
138
  IsAsyncIterator(type) ? AsyncIterator(InstantiateType(context, state, type.iteratorItems), AsyncIteratorOptions(type)) :
143
139
  IsCall(type) ? CallInstantiate(context, state, type.target, type.arguments) :
144
140
  IsConstructor(type) ? Constructor(InstantiateTypes(context, state, type.parameters), InstantiateType(context, state, type.instanceType), ConstructorOptions(type)) :
@@ -1,7 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
- import { Unreachable } from '../../../system/unreachable/index.mjs';
3
2
  import { Guard } from '../../../guard/index.mjs';
4
- import { IsSchema } from '../../types/schema.mjs';
3
+ import { Unreachable } from '../../../system/unreachable/index.mjs';
5
4
  import { EvaluateUnion } from '../evaluate/evaluate.mjs';
6
5
  import { FromType } from './from-type.mjs';
7
6
  function CollapseUnionProperties(left, right) {
@@ -12,15 +11,9 @@ function CollapseUnionProperties(left, right) {
12
11
  return result;
13
12
  }
14
13
  function ReduceVariants(types, result) {
15
- const [left, ...right] = types;
16
- return (IsSchema(left)
17
- ? ReduceVariants(right, CollapseUnionProperties(result, FromType(left)))
18
- : result);
14
+ return Guard.TakeLeft(types, (left, right) => ReduceVariants(right, CollapseUnionProperties(result, FromType(left))), () => result);
19
15
  }
20
16
  export function FromUnion(types) {
21
- const [left, ...right] = types;
22
- return (IsSchema(left)
23
- ? ReduceVariants(right, FromType(left))
24
- : Unreachable());
17
+ return Guard.TakeLeft(types, (left, right) => ReduceVariants(right, FromType(left)), () => Unreachable());
25
18
  }
26
19
  // deno-coverage-ignore-stop
@@ -1,4 +1,4 @@
1
- import { TProperties } from '../../types/properties.mjs';
1
+ import { type TProperties } from '../../types/properties.mjs';
2
2
  import { type TState, type TInstantiateType } from '../instantiate.mjs';
3
3
  import { type TCyclicCheck } from '../cyclic/check.mjs';
4
4
  import { type TRef } from '../../types/ref.mjs';
@@ -1,6 +1,6 @@
1
- import { TUnreachable } from '../../../system/unreachable/index.mjs';
2
- import { type TLiteral, type TLiteralValue } from '../../types/literal.mjs';
1
+ import { type TUnreachable } from '../../../system/unreachable/index.mjs';
3
2
  import { type TSchema } from '../../types/schema.mjs';
3
+ import { type TLiteral, type TLiteralValue } from '../../types/literal.mjs';
4
4
  import { type TString } from '../../types/string.mjs';
5
5
  import { type TTemplateLiteral } from '../../types/template-literal.mjs';
6
6
  import { type TUnion } from '../../types/union.mjs';
@@ -1,8 +1,7 @@
1
1
  // deno-fmt-ignore-file
2
- import { Unreachable } from '../../../system/unreachable/index.mjs';
3
2
  import { Guard } from '../../../guard/index.mjs';
3
+ import { Unreachable } from '../../../system/unreachable/index.mjs';
4
4
  import { Literal, IsLiteral } from '../../types/literal.mjs';
5
- import { IsSchema } from '../../types/schema.mjs';
6
5
  import { String } from '../../types/string.mjs';
7
6
  import { IsTemplateLiteral } from '../../types/template-literal.mjs';
8
7
  import { Union, IsUnion } from '../../types/union.mjs';
@@ -10,17 +9,13 @@ import { ParsePatternIntoTypes } from '../patterns/pattern.mjs';
10
9
  import { IsTemplateLiteralFinite } from './is-finite.mjs';
11
10
  import { TemplateLiteralCreate } from './create.mjs';
12
11
  function FromLiteralPush(variants, value, result = []) {
13
- const [left, ...right] = variants;
14
- return (Guard.IsString(left) ? FromLiteralPush(right, value, [...result, `${left}${value}`]) : result);
12
+ return Guard.TakeLeft(variants, (left, right) => FromLiteralPush(right, value, [...result, `${left}${value}`]), () => result);
15
13
  }
16
14
  function FromLiteral(variants, value) {
17
15
  return (Guard.IsEqual(variants.length, 0) ? [`${value}`] : FromLiteralPush(variants, value));
18
16
  }
19
17
  function FromUnion(variants, types, result = []) {
20
- const [left, ...right] = types;
21
- return (IsSchema(left)
22
- ? FromUnion(variants, right, [...result, ...FromType(variants, left)])
23
- : result);
18
+ return Guard.TakeLeft(types, (left, right) => FromUnion(variants, right, [...result, ...FromType(variants, left)]), () => result);
24
19
  }
25
20
  // ------------------------------------------------------------------
26
21
  // deno-coverage-ignore-start - symmetric unreachable | internal
@@ -38,8 +33,7 @@ function FromType(variants, type) {
38
33
  return result;
39
34
  }
40
35
  function DecodeFromSpan(variants, types) {
41
- const [left, ...right] = types;
42
- return (IsSchema(left) ? DecodeFromSpan(FromType(variants, left), right) : variants);
36
+ return Guard.TakeLeft(types, (left, right) => DecodeFromSpan(FromType(variants, left), right), () => variants);
43
37
  }
44
38
  function VariantsToLiterals(variants) {
45
39
  return variants.map(variant => Literal(variant));
@@ -2,7 +2,7 @@ import { type TSchema } from '../../types/schema.mjs';
2
2
  import { type TEnum, type TEnumValue } from '../../types/enum.mjs';
3
3
  import { type TLiteral, type TLiteralValue } from '../../types/literal.mjs';
4
4
  import { type TUnion } from '../../types/union.mjs';
5
- import { type TTemplateLiteral, TTemplateLiteralDeferred } from '../../types/template-literal.mjs';
5
+ import { type TTemplateLiteral, type TTemplateLiteralDeferred } from '../../types/template-literal.mjs';
6
6
  import { type TBigInt, BigIntPattern } from '../../types/bigint.mjs';
7
7
  import { type TString, StringPattern } from '../../types/string.mjs';
8
8
  import { type TNumber, NumberPattern } from '../../types/number.mjs';