pema 0.1.0 → 0.2.1

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 (358) hide show
  1. package/LICENSE +19 -0
  2. package/lib/private/ArrayType.d.ts +31 -5
  3. package/lib/private/ArrayType.js +86 -22
  4. package/lib/private/BigIntDataType.d.ts +3 -0
  5. package/lib/private/BigIntDataType.js +2 -0
  6. package/lib/private/BigIntType.d.ts +8 -3
  7. package/lib/private/BigIntType.js +7 -4
  8. package/lib/private/BigUintDataType.d.ts +3 -0
  9. package/lib/private/BigUintDataType.js +2 -0
  10. package/lib/private/BigUintType.d.ts +10 -0
  11. package/lib/private/BigUintType.js +10 -0
  12. package/lib/private/BlobType.d.ts +12 -2
  13. package/lib/private/BlobType.js +12 -2
  14. package/lib/private/BooleanType.d.ts +10 -2
  15. package/lib/private/BooleanType.js +14 -2
  16. package/lib/private/BuiltinType.d.ts +7 -5
  17. package/lib/private/BuiltinType.js +18 -17
  18. package/lib/private/CoerceKey.d.ts +4 -0
  19. package/lib/private/CoerceKey.js +3 -0
  20. package/lib/private/ConstructorType.d.ts +10 -4
  21. package/lib/private/ConstructorType.js +13 -11
  22. package/lib/private/DataKey.d.ts +4 -0
  23. package/lib/private/DataKey.js +2 -0
  24. package/lib/private/DataType.d.ts +23 -0
  25. package/lib/private/DataType.js +2 -0
  26. package/lib/private/DateType.d.ts +12 -2
  27. package/lib/private/DateType.js +15 -2
  28. package/lib/private/DecrementDepth.d.ts +3 -0
  29. package/lib/private/DecrementDepth.js +2 -0
  30. package/lib/private/DefaultType.d.ts +13 -6
  31. package/lib/private/DefaultType.js +19 -11
  32. package/lib/private/FileType.d.ts +12 -2
  33. package/lib/private/FileType.js +12 -2
  34. package/lib/private/FloatDataType.d.ts +3 -0
  35. package/lib/private/FloatDataType.js +2 -0
  36. package/lib/private/GenericType.d.ts +2 -2
  37. package/lib/private/GenericType.js +2 -2
  38. package/lib/private/Id.d.ts +3 -0
  39. package/lib/private/Id.js +2 -0
  40. package/lib/private/Infer.d.ts +2 -2
  41. package/lib/private/InferInputSchema.d.ts +26 -0
  42. package/lib/private/InferInputSchema.js +2 -0
  43. package/lib/private/InferSchema.d.ts +5 -5
  44. package/lib/private/InferStore.d.ts +9 -0
  45. package/lib/private/InferStore.js +2 -0
  46. package/lib/private/InferStoreOut.d.ts +8 -0
  47. package/lib/private/InferStoreOut.js +2 -0
  48. package/lib/private/IntDataType.d.ts +3 -0
  49. package/lib/private/IntDataType.js +2 -0
  50. package/lib/private/IntType.d.ts +10 -5
  51. package/lib/private/IntType.js +13 -12
  52. package/lib/private/Issue.d.ts +6 -0
  53. package/lib/private/Issue.js +2 -0
  54. package/lib/private/LiteralType.d.ts +9 -2
  55. package/lib/private/LiteralType.js +17 -9
  56. package/lib/private/NormalizeSchema.d.ts +12 -7
  57. package/lib/private/NullType.d.ts +6 -2
  58. package/lib/private/NullType.js +11 -11
  59. package/lib/private/NumberType.d.ts +7 -3
  60. package/lib/private/NumberType.js +7 -4
  61. package/lib/private/NumericType.d.ts +25 -0
  62. package/lib/private/NumericType.js +38 -0
  63. package/lib/private/ObjectType.d.ts +23 -0
  64. package/lib/private/ObjectType.js +53 -0
  65. package/lib/private/OptionalType.d.ts +12 -5
  66. package/lib/private/OptionalType.js +16 -4
  67. package/lib/private/ParseError.d.ts +10 -0
  68. package/lib/private/ParseError.js +51 -0
  69. package/lib/private/ParseIssue.d.ts +5 -0
  70. package/lib/private/ParseIssue.js +2 -0
  71. package/lib/private/ParseOptions.d.ts +10 -0
  72. package/lib/private/ParseOptions.js +3 -0
  73. package/lib/private/Parsed.d.ts +24 -0
  74. package/lib/private/Parsed.js +17 -0
  75. package/lib/private/ParsedKey.d.ts +4 -0
  76. package/lib/private/ParsedKey.js +3 -0
  77. package/lib/private/PartialType.d.ts +25 -0
  78. package/lib/private/PartialType.js +69 -0
  79. package/lib/private/Partialable.d.ts +5 -0
  80. package/lib/private/Partialable.js +2 -0
  81. package/lib/private/PrimaryType.d.ts +14 -0
  82. package/lib/private/PrimaryType.js +26 -0
  83. package/lib/private/PrimitiveType.d.ts +12 -4
  84. package/lib/private/PrimitiveType.js +50 -17
  85. package/lib/private/PureType.d.ts +15 -0
  86. package/lib/private/PureType.js +21 -0
  87. package/lib/private/RecordType.d.ts +19 -4
  88. package/lib/private/RecordType.js +43 -14
  89. package/lib/private/RecordTypeKey.d.ts +1 -1
  90. package/lib/private/Schema.d.ts +3 -3
  91. package/lib/private/SchemaError.d.ts +4 -0
  92. package/lib/private/SchemaError.js +8 -0
  93. package/lib/private/Serialized.d.ts +72 -0
  94. package/lib/private/Serialized.js +2 -0
  95. package/lib/private/StoreId.d.ts +6 -0
  96. package/lib/private/StoreId.js +2 -0
  97. package/lib/private/StoreSchema.d.ts +8 -0
  98. package/lib/private/StoreSchema.js +2 -0
  99. package/lib/private/StoreType.d.ts +21 -0
  100. package/lib/private/StoreType.js +45 -0
  101. package/lib/private/Storeable.d.ts +15 -0
  102. package/lib/private/Storeable.js +7 -0
  103. package/lib/private/StringType.d.ts +17 -5
  104. package/lib/private/StringType.js +47 -13
  105. package/lib/private/SymbolType.d.ts +4 -1
  106. package/lib/private/SymbolType.js +5 -2
  107. package/lib/private/TupleType.d.ts +11 -4
  108. package/lib/private/TupleType.js +16 -22
  109. package/lib/private/Type.d.ts +5 -3
  110. package/lib/private/Type.js +2 -2
  111. package/lib/private/URLType.d.ts +16 -2
  112. package/lib/private/URLType.js +12 -2
  113. package/lib/private/UintDataType.d.ts +3 -0
  114. package/lib/private/UintDataType.js +2 -0
  115. package/lib/private/UintType.d.ts +14 -7
  116. package/lib/private/UintType.js +20 -12
  117. package/lib/private/UndefinedType.d.ts +4 -1
  118. package/lib/private/UndefinedType.js +7 -2
  119. package/lib/private/UnionType.d.ts +15 -4
  120. package/lib/private/UnionType.js +32 -26
  121. package/lib/private/UnknownType.d.ts +5 -0
  122. package/lib/private/UnknownType.js +7 -0
  123. package/lib/private/Validator.d.ts +1 -1
  124. package/lib/private/VirtualType.d.ts +6 -0
  125. package/lib/private/VirtualType.js +11 -0
  126. package/lib/private/array.d.ts +6 -3
  127. package/lib/private/array.js +7 -1
  128. package/lib/private/bigint.d.ts +1 -3
  129. package/lib/private/bigint.js +1 -2
  130. package/lib/private/biguint.d.ts +2 -0
  131. package/lib/private/biguint.js +2 -0
  132. package/lib/private/boolean.d.ts +3 -0
  133. package/lib/private/boolean.js +3 -0
  134. package/lib/private/coerce/bigint.d.ts +2 -0
  135. package/lib/private/coerce/bigint.js +13 -0
  136. package/lib/private/coerce/date.d.ts +2 -0
  137. package/lib/private/coerce/date.js +56 -0
  138. package/lib/private/coerce/int.d.ts +2 -0
  139. package/lib/private/coerce/int.js +8 -0
  140. package/lib/private/constructor.d.ts +5 -2
  141. package/lib/private/constructor.js +3 -0
  142. package/lib/private/error/fail.d.ts +3 -0
  143. package/lib/private/error/fail.js +5 -0
  144. package/lib/private/error/schemafail.d.ts +3 -0
  145. package/lib/private/error/schemafail.js +5 -0
  146. package/lib/private/error.d.ts +3 -2
  147. package/lib/private/error.js +10 -3
  148. package/lib/private/expect.d.ts +12 -11
  149. package/lib/private/expect.js +22 -11
  150. package/lib/private/expected.js +10 -1
  151. package/lib/private/f32.d.ts +4 -0
  152. package/lib/private/f32.js +4 -0
  153. package/lib/private/f64.d.ts +4 -0
  154. package/lib/private/f64.js +3 -0
  155. package/lib/private/i128.d.ts +4 -0
  156. package/lib/private/i128.js +6 -0
  157. package/lib/private/i16.d.ts +4 -0
  158. package/lib/private/i16.js +6 -0
  159. package/lib/private/i32.d.ts +4 -0
  160. package/lib/private/i32.js +6 -0
  161. package/lib/private/i64.d.ts +4 -0
  162. package/lib/private/i64.js +6 -0
  163. package/lib/private/i8.d.ts +4 -0
  164. package/lib/private/i8.js +6 -0
  165. package/lib/private/index.d.ts +4 -2
  166. package/lib/private/index.js +5 -40
  167. package/lib/private/int.d.ts +1 -3
  168. package/lib/private/int.js +1 -2
  169. package/lib/private/is-parsed-type.d.ts +3 -0
  170. package/lib/private/is-parsed-type.js +6 -0
  171. package/lib/private/json/JSONIssue.d.ts +6 -0
  172. package/lib/private/json/JSONIssue.js +2 -0
  173. package/lib/private/json/JSONPayload.d.ts +5 -0
  174. package/lib/private/json/JSONPayload.js +2 -0
  175. package/lib/private/literal.d.ts +1 -2
  176. package/lib/private/literal.js +1 -1
  177. package/lib/private/normalize.d.ts +4 -0
  178. package/lib/private/normalize.js +42 -0
  179. package/lib/private/number.d.ts +1 -3
  180. package/lib/private/number.js +1 -2
  181. package/lib/private/object.d.ts +11 -0
  182. package/lib/private/object.js +10 -0
  183. package/lib/private/optional.d.ts +2 -2
  184. package/lib/private/partial.d.ts +9 -0
  185. package/lib/private/partial.js +8 -0
  186. package/lib/private/path/join.d.ts +3 -0
  187. package/lib/private/path/join.js +13 -0
  188. package/lib/private/path/next.d.ts +9 -0
  189. package/lib/private/path/next.js +9 -0
  190. package/lib/private/path/rebase.d.ts +3 -0
  191. package/lib/private/path/rebase.js +9 -0
  192. package/lib/private/primary.d.ts +4 -0
  193. package/lib/private/primary.js +3 -0
  194. package/lib/private/pure.d.ts +3 -0
  195. package/lib/private/pure.js +5 -0
  196. package/lib/private/record.d.ts +5 -2
  197. package/lib/private/record.js +3 -0
  198. package/lib/private/spec/bigint.d.ts +5 -0
  199. package/lib/private/spec/bigint.js +73 -0
  200. package/lib/private/spec/biguint.d.ts +5 -0
  201. package/lib/private/spec/biguint.js +73 -0
  202. package/lib/private/spec/int.d.ts +5 -0
  203. package/lib/private/spec/int.js +70 -0
  204. package/lib/private/spec/uint.d.ts +5 -0
  205. package/lib/private/spec/uint.js +73 -0
  206. package/lib/private/string.d.ts +3 -0
  207. package/lib/private/string.js +3 -0
  208. package/lib/private/test/messages-of.d.ts +3 -0
  209. package/lib/private/test/messages-of.js +4 -0
  210. package/lib/private/test/paths-of.d.ts +3 -0
  211. package/lib/private/test/paths-of.js +4 -0
  212. package/lib/private/test/throws-issues.d.ts +4 -0
  213. package/lib/private/test/throws-issues.js +13 -0
  214. package/lib/private/trait/Default.d.ts +9 -0
  215. package/lib/private/trait/Default.js +4 -0
  216. package/lib/private/trait/Optional.d.ts +11 -0
  217. package/lib/private/trait/Optional.js +4 -0
  218. package/lib/private/tuple.d.ts +6 -2
  219. package/lib/private/tuple.js +6 -1
  220. package/lib/private/u128.d.ts +4 -0
  221. package/lib/private/u128.js +6 -0
  222. package/lib/private/u16.d.ts +4 -0
  223. package/lib/private/u16.js +6 -0
  224. package/lib/private/u32.d.ts +7 -0
  225. package/lib/private/u32.js +9 -0
  226. package/lib/private/u64.d.ts +4 -0
  227. package/lib/private/u64.js +6 -0
  228. package/lib/private/u8.d.ts +4 -0
  229. package/lib/private/u8.js +6 -0
  230. package/lib/private/uint.d.ts +1 -3
  231. package/lib/private/uint.js +1 -2
  232. package/lib/private/union.d.ts +6 -5
  233. package/lib/private/union.js +4 -1
  234. package/lib/private/unknown.d.ts +7 -0
  235. package/lib/private/unknown.js +6 -0
  236. package/lib/private/validator/email.d.ts +3 -0
  237. package/lib/private/validator/email.js +4 -0
  238. package/lib/private/validator/ends-with.d.ts +4 -0
  239. package/lib/private/validator/ends-with.js +11 -0
  240. package/lib/private/validator/f32.d.ts +2 -0
  241. package/lib/private/validator/f32.js +11 -0
  242. package/lib/private/validator/integer.d.ts +3 -0
  243. package/lib/private/validator/integer.js +12 -0
  244. package/lib/private/validator/isotime.d.ts +2 -0
  245. package/lib/private/validator/isotime.js +30 -0
  246. package/lib/private/validator/length.d.ts +5 -0
  247. package/lib/private/validator/length.js +29 -0
  248. package/lib/private/validator/max.d.ts +6 -0
  249. package/lib/private/validator/max.js +37 -0
  250. package/lib/private/validator/min.d.ts +6 -0
  251. package/lib/private/validator/min.js +37 -0
  252. package/lib/private/validator/port.d.ts +3 -0
  253. package/lib/private/validator/port.js +15 -0
  254. package/lib/private/validator/range.d.ts +3 -0
  255. package/lib/private/validator/range.js +22 -0
  256. package/lib/private/validator/regex.d.ts +5 -0
  257. package/lib/private/validator/regex.js +15 -0
  258. package/lib/private/validator/starts-with.d.ts +4 -0
  259. package/lib/private/validator/starts-with.js +11 -0
  260. package/lib/private/validator/unique-by.d.ts +2 -0
  261. package/lib/private/validator/unique-by.js +23 -0
  262. package/lib/private/validator/unique-with.d.ts +2 -0
  263. package/lib/private/validator/unique-with.js +18 -0
  264. package/lib/private/validator/unique.d.ts +2 -0
  265. package/lib/private/validator/unique.js +19 -0
  266. package/lib/private/validator/uuid.d.ts +3 -0
  267. package/lib/private/validator/uuid.js +4 -0
  268. package/lib/private/validator/values.d.ts +4 -0
  269. package/lib/private/validator/values.js +14 -0
  270. package/lib/public/DataType.d.ts +2 -0
  271. package/lib/public/DataType.js +2 -0
  272. package/lib/public/Id.d.ts +2 -0
  273. package/lib/public/Id.js +2 -0
  274. package/lib/public/InferStore.d.ts +2 -0
  275. package/lib/public/InferStore.js +2 -0
  276. package/lib/public/InferStoreOut.d.ts +2 -0
  277. package/lib/public/InferStoreOut.js +2 -0
  278. package/lib/public/Issue.d.ts +2 -0
  279. package/lib/public/Issue.js +2 -0
  280. package/lib/public/JSONPayload.d.ts +2 -0
  281. package/lib/public/JSONPayload.js +2 -0
  282. package/lib/public/ParseError.d.ts +2 -0
  283. package/lib/public/ParseError.js +2 -0
  284. package/lib/public/Serialized.d.ts +2 -0
  285. package/lib/public/Serialized.js +2 -0
  286. package/lib/public/StoreId.d.ts +2 -0
  287. package/lib/public/StoreId.js +2 -0
  288. package/lib/public/StoreSchema.d.ts +2 -0
  289. package/lib/public/StoreSchema.js +2 -0
  290. package/lib/public/StoreType.d.ts +3 -0
  291. package/lib/public/StoreType.js +2 -0
  292. package/lib/public/array.d.ts +3 -0
  293. package/lib/public/array.js +3 -0
  294. package/lib/public/bigint.d.ts +2 -0
  295. package/lib/public/bigint.js +2 -0
  296. package/lib/public/biguint.d.ts +2 -0
  297. package/lib/public/biguint.js +2 -0
  298. package/lib/public/boolean.d.ts +1 -0
  299. package/lib/public/boolean.js +1 -0
  300. package/lib/public/constructor.d.ts +1 -0
  301. package/lib/public/constructor.js +1 -0
  302. package/lib/public/f32.d.ts +2 -0
  303. package/lib/public/f32.js +2 -0
  304. package/lib/public/f64.d.ts +2 -0
  305. package/lib/public/f64.js +2 -0
  306. package/lib/public/i128.d.ts +2 -0
  307. package/lib/public/i128.js +2 -0
  308. package/lib/public/i16.d.ts +2 -0
  309. package/lib/public/i16.js +2 -0
  310. package/lib/public/i32.d.ts +2 -0
  311. package/lib/public/i32.js +2 -0
  312. package/lib/public/i64.d.ts +2 -0
  313. package/lib/public/i64.js +2 -0
  314. package/lib/public/i8.d.ts +2 -0
  315. package/lib/public/i8.js +2 -0
  316. package/lib/public/index.d.ts +6 -0
  317. package/lib/public/index.js +6 -0
  318. package/lib/public/number.d.ts +1 -0
  319. package/lib/public/number.js +1 -0
  320. package/lib/public/primary.d.ts +2 -0
  321. package/lib/public/primary.js +2 -0
  322. package/lib/public/pure.d.ts +2 -0
  323. package/lib/public/pure.js +2 -0
  324. package/lib/public/record.d.ts +1 -0
  325. package/lib/public/record.js +1 -0
  326. package/lib/public/string.d.ts +1 -0
  327. package/lib/public/string.js +1 -0
  328. package/lib/public/u128.d.ts +2 -0
  329. package/lib/public/u128.js +2 -0
  330. package/lib/public/u16.d.ts +2 -0
  331. package/lib/public/u16.js +2 -0
  332. package/lib/public/u32.d.ts +2 -0
  333. package/lib/public/u32.js +2 -0
  334. package/lib/public/u64.d.ts +2 -0
  335. package/lib/public/u64.js +2 -0
  336. package/lib/public/u8.d.ts +2 -0
  337. package/lib/public/u8.js +2 -0
  338. package/lib/public/uint.d.ts +3 -0
  339. package/lib/public/uint.js +3 -0
  340. package/lib/public/union.d.ts +1 -0
  341. package/lib/public/union.js +1 -0
  342. package/lib/public/unknown.d.ts +3 -0
  343. package/lib/public/unknown.js +2 -0
  344. package/package.json +14 -11
  345. package/lib/private/AbstractConstructor.d.ts +0 -3
  346. package/lib/private/AbstractConstructor.js +0 -2
  347. package/lib/private/MaybeInt.d.ts +0 -3
  348. package/lib/private/MaybeInt.js +0 -2
  349. package/lib/private/SchemaType.d.ts +0 -13
  350. package/lib/private/SchemaType.js +0 -63
  351. package/lib/private/Validated.d.ts +0 -8
  352. package/lib/private/Validated.js +0 -10
  353. package/lib/private/ValidatedKey.d.ts +0 -4
  354. package/lib/private/ValidatedKey.js +0 -3
  355. package/lib/private/is-int.d.ts +0 -3
  356. package/lib/private/is-int.js +0 -5
  357. package/lib/private/is_validated_type.d.ts +0 -4
  358. package/lib/private/is_validated_type.js +0 -5
@@ -0,0 +1,6 @@
1
+ import type Infer from "#Infer";
2
+ import type Parsed from "#Parsed";
3
+ import type StoreSchema from "#StoreSchema";
4
+ type StoreId<T extends StoreSchema> = T["id"] extends Parsed<unknown> ? NonNullable<Infer<T["id"]>> : never;
5
+ export type { StoreId as default };
6
+ //# sourceMappingURL=StoreId.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=StoreId.js.map
@@ -0,0 +1,8 @@
1
+ import type Storeable from "#Storeable";
2
+ type StoreSchema = {
3
+ [k: string]: Storeable;
4
+ } & {
5
+ id: Storeable;
6
+ };
7
+ export type { StoreSchema as default };
8
+ //# sourceMappingURL=StoreSchema.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=StoreSchema.js.map
@@ -0,0 +1,21 @@
1
+ import GenericType from "#GenericType";
2
+ import type Infer from "#Infer";
3
+ import type InferStore from "#InferStore";
4
+ import type ParseOptions from "#ParseOptions";
5
+ import PartialType from "#PartialType";
6
+ import type Serialized from "#Serialized";
7
+ import type StoreSchema from "#StoreSchema";
8
+ import type Dict from "@rcompat/type/Dict";
9
+ export default class StoreType<T extends StoreSchema> extends GenericType<T, InferStore<T>, "StoreType"> {
10
+ #private;
11
+ constructor(spec: T);
12
+ get name(): string;
13
+ get schema(): T;
14
+ partial(): PartialType<T>;
15
+ parse(x: unknown, options?: ParseOptions): Infer<this>;
16
+ toJSON(): {
17
+ type: "object";
18
+ properties: Dict<Serialized>;
19
+ };
20
+ }
21
+ //# sourceMappingURL=StoreType.d.ts.map
@@ -0,0 +1,45 @@
1
+ import GenericType from "#GenericType";
2
+ import ParsedKey from "#ParsedKey";
3
+ import PartialType from "#PartialType";
4
+ import join from "#path/join";
5
+ export default class StoreType extends GenericType {
6
+ #properties;
7
+ constructor(spec) {
8
+ super();
9
+ this.#properties = spec;
10
+ }
11
+ get name() {
12
+ return "store";
13
+ }
14
+ get schema() {
15
+ return this.#properties;
16
+ }
17
+ partial() {
18
+ return new PartialType(this.#properties);
19
+ }
20
+ parse(x, options = {}) {
21
+ const spec = this.#properties;
22
+ if (typeof x !== "object" || x === null) {
23
+ throw new Error("Expected object");
24
+ }
25
+ const result = {};
26
+ for (const k in spec) {
27
+ const r = spec[k].parse(x[k], {
28
+ ...options, [ParsedKey]: join(options[ParsedKey] ?? "", String(k)),
29
+ });
30
+ // exclude undefined (optionals)
31
+ if (r !== undefined) {
32
+ result[k] = r;
33
+ }
34
+ }
35
+ return x;
36
+ }
37
+ toJSON() {
38
+ const properties = {};
39
+ for (const [k, v] of Object.entries(this.#properties)) {
40
+ properties[k] = v.toJSON();
41
+ }
42
+ return { type: "object", properties };
43
+ }
44
+ }
45
+ //# sourceMappingURL=StoreType.js.map
@@ -0,0 +1,15 @@
1
+ import type K from "#DataKey";
2
+ import Parsed from "#Parsed";
3
+ import type Serialized from "#Serialized";
4
+ export default abstract class Storeable<T extends K = K> extends Parsed<unknown> {
5
+ abstract get datatype(): T;
6
+ abstract toJSON(): Serialized;
7
+ static serialize<N extends string, T extends K>(s: {
8
+ name: N;
9
+ datatype: T;
10
+ }): {
11
+ type: N;
12
+ datatype: T;
13
+ };
14
+ }
15
+ //# sourceMappingURL=Storeable.d.ts.map
@@ -0,0 +1,7 @@
1
+ import Parsed from "#Parsed";
2
+ export default class Storeable extends Parsed {
3
+ static serialize(s) {
4
+ return { type: s.name, datatype: s.datatype };
5
+ }
6
+ }
7
+ //# sourceMappingURL=Storeable.js.map
@@ -1,8 +1,20 @@
1
1
  import PrimitiveType from "#PrimitiveType";
2
- import type Validator from "#Validator";
3
- export default class StringType extends PrimitiveType<string, "StringType"> {
4
- constructor(validators?: Validator<string>[]);
5
- startsWith(prefix: string): StringType;
6
- endsWith(suffix: string): StringType;
2
+ import Storeable from "#Storeable";
3
+ export default class StringType extends PrimitiveType<string, "StringType"> implements Storeable<"string"> {
4
+ get name(): "string";
5
+ get datatype(): "string";
6
+ isotime(): this;
7
+ regex(pattern: RegExp): this;
8
+ email(): this;
9
+ uuid(): this;
10
+ startsWith(prefix: string): this;
11
+ endsWith(suffix: string): this;
12
+ min(limit: number): this;
13
+ max(limit: number): this;
14
+ length(from: number, to: number): this;
15
+ toJSON(): {
16
+ type: "string";
17
+ datatype: "string";
18
+ };
7
19
  }
8
20
  //# sourceMappingURL=StringType.d.ts.map
@@ -1,23 +1,57 @@
1
+ import schemafail from "#error/schemafail";
1
2
  import PrimitiveType from "#PrimitiveType";
2
- const starts_with_validator = (prefix) => (x) => {
3
- if (!x.startsWith(prefix)) {
4
- throw new Error(`"${x}" does not start with "${prefix}"`);
3
+ import Storeable from "#Storeable";
4
+ import email from "#validator/email";
5
+ import ends_with from "#validator/ends-with";
6
+ import isotime from "#validator/isotime";
7
+ import length from "#validator/length";
8
+ import max from "#validator/max";
9
+ import min from "#validator/min";
10
+ import regex from "#validator/regex";
11
+ import starts_with from "#validator/starts-with";
12
+ import uuid from "#validator/uuid";
13
+ export default class StringType extends PrimitiveType {
14
+ get name() {
15
+ return "string";
5
16
  }
6
- };
7
- const ends_with_validator = (suffix) => (x) => {
8
- if (!x.endsWith(suffix)) {
9
- throw new Error(`"${x}" does not end with "${suffix}"`);
17
+ get datatype() {
18
+ return "string";
10
19
  }
11
- };
12
- export default class StringType extends PrimitiveType {
13
- constructor(validators) {
14
- super("string", validators);
20
+ isotime() {
21
+ return this.derive({ validators: [isotime] });
22
+ }
23
+ regex(pattern) {
24
+ return this.derive({ validators: [regex(pattern)] });
25
+ }
26
+ email() {
27
+ return this.derive({ validators: [email] });
28
+ }
29
+ uuid() {
30
+ return this.derive({ validators: [uuid] });
15
31
  }
16
32
  startsWith(prefix) {
17
- return new StringType([...this.validators, starts_with_validator(prefix)]);
33
+ return this.derive({ validators: [starts_with(prefix)] });
18
34
  }
19
35
  endsWith(suffix) {
20
- return new StringType([...this.validators, ends_with_validator(suffix)]);
36
+ return this.derive({ validators: [ends_with(suffix)] });
37
+ }
38
+ min(limit) {
39
+ if (limit < 0) {
40
+ throw schemafail("min: {0} must be positive", limit);
41
+ }
42
+ return this.derive({ validators: [min(limit)] });
43
+ }
44
+ max(limit) {
45
+ if (limit < 0) {
46
+ throw schemafail("max: {0} must be positive", limit);
47
+ }
48
+ return this.derive({ validators: [max(limit)] });
49
+ }
50
+ length(from, to) {
51
+ return this.derive({ validators: [length(from, to)] });
52
+ }
53
+ toJSON() {
54
+ return Storeable.serialize(this);
21
55
  }
22
56
  }
23
57
  //# sourceMappingURL=StringType.js.map
@@ -1,5 +1,8 @@
1
1
  import PrimitiveType from "#PrimitiveType";
2
2
  export default class SymbolType extends PrimitiveType<symbol, "SymbolType"> {
3
- constructor();
3
+ get name(): "symbol";
4
+ toJSON(): {
5
+ type: "symbol";
6
+ };
4
7
  }
5
8
  //# sourceMappingURL=SymbolType.d.ts.map
@@ -1,7 +1,10 @@
1
1
  import PrimitiveType from "#PrimitiveType";
2
2
  export default class SymbolType extends PrimitiveType {
3
- constructor() {
4
- super("symbol");
3
+ get name() {
4
+ return "symbol";
5
+ }
6
+ toJSON() {
7
+ return { type: this.name };
5
8
  }
6
9
  }
7
10
  //# sourceMappingURL=SymbolType.js.map
@@ -2,16 +2,23 @@ import GenericType from "#GenericType";
2
2
  import type Infer from "#Infer";
3
3
  import type InferSchema from "#InferSchema";
4
4
  import OptionalType from "#OptionalType";
5
+ import type Parsed from "#Parsed";
6
+ import type ParseOptions from "#ParseOptions";
5
7
  import type Schema from "#Schema";
8
+ import type OptionalTrait from "#trait/Optional";
6
9
  type InferTuple<T extends Schema[]> = {
7
10
  [K in keyof T]: T[K] extends Schema ? InferSchema<T[K]> : "tuple-never";
8
11
  };
9
- export default class TupleType<T extends Schema[]> extends GenericType<T, InferTuple<T>, "TupleType"> {
12
+ export default class TupleType<T extends Parsed<unknown>[]> extends GenericType<T, InferTuple<T>, "TupleType"> implements OptionalTrait {
10
13
  #private;
11
- constructor(members: T);
14
+ constructor(items: T);
15
+ get name(): "tuple";
12
16
  optional(): OptionalType<this>;
13
- get name(): string;
14
- validate(x: unknown, key?: string): Infer<this>;
17
+ parse(x: unknown, options?: ParseOptions): Infer<this>;
18
+ toJSON(): {
19
+ type: "tuple";
20
+ of: import("./Serialized.js").default[];
21
+ };
15
22
  }
16
23
  export {};
17
24
  //# sourceMappingURL=TupleType.d.ts.map
@@ -1,40 +1,34 @@
1
1
  import error from "#error";
2
- import expected from "#expected";
3
2
  import GenericType from "#GenericType";
4
- import schema from "#index";
5
- import is_validated_type from "#is_validated_type";
6
3
  import OptionalType from "#OptionalType";
7
- const member_error = (i, key) => {
8
- return key === undefined
9
- ? `[${i}]`
10
- : `${key}[${i}]`;
11
- };
4
+ import ParseError from "#ParseError";
5
+ import next from "#path/next";
12
6
  export default class TupleType extends GenericType {
13
- #members;
14
- constructor(members) {
7
+ #items;
8
+ constructor(items) {
15
9
  super();
16
- this.#members = members;
17
- }
18
- optional() {
19
- return new OptionalType(this);
10
+ this.#items = items;
20
11
  }
21
12
  get name() {
22
13
  return "tuple";
23
14
  }
24
- validate(x, key) {
15
+ optional() {
16
+ return new OptionalType(this);
17
+ }
18
+ parse(x, options = {}) {
25
19
  if (!(!!x && Array.isArray(x))) {
26
- throw new Error(error(expected("array", x), key));
20
+ throw new ParseError(error("array", x, options));
27
21
  }
28
- this.#members.forEach((v, i) => {
29
- const validator = is_validated_type(v) ? v : schema(v);
30
- validator.validate(x[i], `${member_error(i, key)}`);
22
+ this.#items.forEach((v, i) => {
23
+ v.parse(x[i], next(i, options));
31
24
  });
32
25
  x.forEach((v, i) => {
33
- const member = this.#members[i];
34
- const validator = is_validated_type(member) ? member : schema(member);
35
- validator.validate(v, `${member_error(i, key)}`);
26
+ if (i >= this.#items.length) {
27
+ throw new ParseError(error("undefined", v, next(i, options)));
28
+ }
36
29
  });
37
30
  return x;
38
31
  }
32
+ toJSON() { return { type: this.name, of: this.#items.map(i => i.toJSON()) }; }
39
33
  }
40
34
  //# sourceMappingURL=TupleType.js.map
@@ -1,10 +1,12 @@
1
1
  import DefaultType from "#DefaultType";
2
2
  import OptionalType from "#OptionalType";
3
- import Validated from "#Validated";
3
+ import Parsed from "#Parsed";
4
+ import type DefaultTrait from "#trait/Default";
5
+ import type OptionalTrait from "#trait/Optional";
4
6
  import type Printable from "@rcompat/type/Printable";
5
- export default abstract class Type<Type, Name extends string> extends Validated<Type> implements Printable {
7
+ export default abstract class Type<T, Name extends string> extends Parsed<T> implements Printable, DefaultTrait<T>, OptionalTrait {
6
8
  optional(): OptionalType<this>;
7
- default<const S extends Type>(value: S | (() => S)): DefaultType<this, S>;
9
+ default<S extends T>(value: (() => S) | S): DefaultType<this, S>;
8
10
  get Name(): Name;
9
11
  }
10
12
  //# sourceMappingURL=Type.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import DefaultType from "#DefaultType";
2
2
  import OptionalType from "#OptionalType";
3
- import Validated from "#Validated";
4
- export default class Type extends Validated {
3
+ import Parsed from "#Parsed";
4
+ export default class Type extends Parsed {
5
5
  optional() {
6
6
  return new OptionalType(this);
7
7
  }
@@ -1,5 +1,19 @@
1
1
  import BuiltinType from "#BuiltinType";
2
- export default class URLType extends BuiltinType<URL, "URLType"> {
3
- constructor();
2
+ import Storeable from "#Storeable";
3
+ export default class URLType extends BuiltinType<URL, "URLType"> implements Storeable<"url"> {
4
+ get Type(): {
5
+ new (url: string | URL, base?: string | URL): URL;
6
+ prototype: URL;
7
+ canParse(url: string | URL, base?: string | URL): boolean;
8
+ createObjectURL(obj: Blob | MediaSource): string;
9
+ parse(url: string | URL, base?: string | URL): URL | null;
10
+ revokeObjectURL(url: string): void;
11
+ };
12
+ get name(): "url";
13
+ get datatype(): "url";
14
+ toJSON(): {
15
+ type: "url";
16
+ datatype: "url";
17
+ };
4
18
  }
5
19
  //# sourceMappingURL=URLType.d.ts.map
@@ -1,7 +1,17 @@
1
1
  import BuiltinType from "#BuiltinType";
2
+ import Storeable from "#Storeable";
2
3
  export default class URLType extends BuiltinType {
3
- constructor() {
4
- super("url", URL);
4
+ get Type() {
5
+ return URL;
6
+ }
7
+ get name() {
8
+ return "url";
9
+ }
10
+ get datatype() {
11
+ return "url";
12
+ }
13
+ toJSON() {
14
+ return Storeable.serialize(this);
5
15
  }
6
16
  }
7
17
  //# sourceMappingURL=URLType.js.map
@@ -0,0 +1,3 @@
1
+ type UintDataType = "u16" | "u32" | "u8";
2
+ export type { UintDataType as default };
3
+ //# sourceMappingURL=UintDataType.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=UintDataType.js.map
@@ -1,9 +1,16 @@
1
- import type Infer from "#Infer";
2
- import PrimitiveType from "#PrimitiveType";
3
- type Name = "UintType";
4
- export default class UintType extends PrimitiveType<number | bigint, Name> {
5
- constructor();
6
- validate(x: unknown, key?: string): Infer<this>;
1
+ import coerce from "#coerce/int";
2
+ import CoerceKey from "#CoerceKey";
3
+ import NumericType from "#NumericType";
4
+ import type ParseOptions from "#ParseOptions";
5
+ import type Storeable from "#Storeable";
6
+ import type UintDataType from "#UintDataType";
7
+ export default class UintType<T extends UintDataType> extends NumericType<T, number, "UintType"> implements Storeable<T> {
8
+ [CoerceKey]: typeof coerce;
9
+ get name(): string;
10
+ /**
11
+ * Value is a non-privileged port number (1000 - 65535).
12
+ */
13
+ port(): this;
14
+ parse(x: unknown, options?: ParseOptions<number>): import("./Infer.js").default<this>;
7
15
  }
8
- export {};
9
16
  //# sourceMappingURL=UintType.d.ts.map
@@ -1,16 +1,24 @@
1
- import PrimitiveType from "#PrimitiveType";
2
- import error from "#error";
3
- import expected from "#expected";
4
- import is_int from "#is-int";
5
- export default class UintType extends PrimitiveType {
6
- constructor() {
7
- super("uint");
1
+ import coerce from "#coerce/int";
2
+ import CoerceKey from "#CoerceKey";
3
+ import NumericType from "#NumericType";
4
+ import integer from "#validator/integer";
5
+ import port from "#validator/port";
6
+ export default class UintType extends NumericType {
7
+ [CoerceKey] = coerce;
8
+ get name() {
9
+ return "number";
8
10
  }
9
- validate(x, key) {
10
- if (!is_int(x) || x < 0) {
11
- throw new Error(error(expected("uint", x), key));
12
- }
13
- return x;
11
+ /**
12
+ * Value is a non-privileged port number (1000 - 65535).
13
+ */
14
+ port() {
15
+ return this.derive({ validators: [port] });
16
+ }
17
+ parse(x, options = {}) {
18
+ return super.parse(x, {
19
+ ...options,
20
+ validators: [integer],
21
+ });
14
22
  }
15
23
  }
16
24
  //# sourceMappingURL=UintType.js.map
@@ -1,7 +1,10 @@
1
1
  import PrimitiveType from "#PrimitiveType";
2
2
  type Name = "UndefinedType";
3
3
  export default class UndefinedType extends PrimitiveType<undefined, Name> {
4
- constructor();
4
+ get name(): "undefined";
5
+ toJSON(): {
6
+ type: "undefined";
7
+ };
5
8
  }
6
9
  export {};
7
10
  //# sourceMappingURL=UndefinedType.d.ts.map
@@ -1,7 +1,12 @@
1
1
  import PrimitiveType from "#PrimitiveType";
2
2
  export default class UndefinedType extends PrimitiveType {
3
- constructor() {
4
- super("undefined");
3
+ get name() {
4
+ return "undefined";
5
+ }
6
+ toJSON() {
7
+ return {
8
+ type: this.name,
9
+ };
5
10
  }
6
11
  }
7
12
  //# sourceMappingURL=UndefinedType.js.map
@@ -1,18 +1,29 @@
1
+ import DefaultType from "#DefaultType";
1
2
  import GenericType from "#GenericType";
2
3
  import type Infer from "#Infer";
3
4
  import type InferSchema from "#InferSchema";
4
5
  import OptionalType from "#OptionalType";
6
+ import type Parsed from "#Parsed";
7
+ import type ParseOptions from "#ParseOptions";
5
8
  import type Schema from "#Schema";
9
+ import type DefaultTrait from "#trait/Default";
10
+ import type OptionalTrait from "#trait/Optional";
6
11
  import type TupleToUnion from "@rcompat/type/TupleToUnion";
7
12
  type InferUnion<T extends Schema[]> = TupleToUnion<{
8
13
  [K in keyof T]: T[K] extends Schema ? InferSchema<T[K]> : "union-never";
9
14
  }>;
10
- export default class UnionType<T extends Schema[]> extends GenericType<T, InferUnion<T>, "UnionType"> {
15
+ export default class UnionType<T extends Parsed<unknown>[]> extends GenericType<T, InferUnion<T>, "UnionType"> implements OptionalTrait, DefaultTrait<InferUnion<T>> {
11
16
  #private;
12
- constructor(types: T);
17
+ constructor(of: T);
18
+ get name(): "union";
19
+ get schema(): T;
13
20
  optional(): OptionalType<this>;
14
- get name(): string;
15
- validate(x: unknown, key?: string): Infer<this>;
21
+ default(value: (() => InferUnion<T>) | InferUnion<T>): DefaultType<this, InferUnion<T>>;
22
+ parse(x: unknown, options?: ParseOptions): Infer<this>;
23
+ toJSON(): {
24
+ type: "union";
25
+ of: import("./Serialized.js").default[];
26
+ };
16
27
  }
17
28
  export {};
18
29
  //# sourceMappingURL=UnionType.d.ts.map
@@ -1,17 +1,14 @@
1
- import expected from "#expected";
1
+ import DefaultType from "#DefaultType";
2
+ import error from "#error";
2
3
  import GenericType from "#GenericType";
3
4
  import schema from "#index";
4
- import is_validated_type from "#is_validated_type";
5
+ import isParsedType from "#is-parsed-type";
5
6
  import OptionalType from "#OptionalType";
6
- import assert from "@rcompat/invariant/assert";
7
- const error = (message, key) => {
8
- return key === undefined
9
- ? message
10
- : `${key}: ${message}`;
11
- };
7
+ import ParseError from "#ParseError";
8
+ import assert from "@rcompat/assert";
12
9
  const print = (type) => {
13
- const validated = is_validated_type(type);
14
- if (validated) {
10
+ const parsed = isParsedType(type);
11
+ if (parsed) {
15
12
  return type.name;
16
13
  }
17
14
  const type_of = typeof type;
@@ -28,36 +25,45 @@ const print = (type) => {
28
25
  }
29
26
  return type;
30
27
  };
31
- const to_union_string = (types) => `\`${types.map(t => is_validated_type(t) ? t.name : print(t)).join(" | ")}\``;
28
+ const union_error = (types) => `\`${types.map(t => isParsedType(t) ? t.name : print(t)).join(" | ")}\``;
32
29
  export default class UnionType extends GenericType {
33
- #types;
34
- constructor(types) {
35
- assert(types.length > 1, "union type must have at least two members");
30
+ #of;
31
+ constructor(of) {
32
+ assert(of.length > 1, "union type must have at least two members");
36
33
  super();
37
- this.#types = types;
34
+ this.#of = of;
35
+ }
36
+ get name() {
37
+ return "union";
38
+ }
39
+ get schema() {
40
+ return this.#of;
38
41
  }
39
42
  optional() {
40
43
  return new OptionalType(this);
41
44
  }
42
- get name() {
43
- return "union";
45
+ default(value) {
46
+ return new DefaultType(this, value);
44
47
  }
45
- validate(x, key) {
46
- // union validates when any of its members validates
47
- const validated = this.#types.some(type => {
48
- const validator = is_validated_type(type) ? type : schema(type);
48
+ parse(x, options = {}) {
49
+ // union parses when any of its members parses
50
+ const parsed = this.#of.map(type => {
51
+ const validator = isParsedType(type) ? type : schema(type);
49
52
  try {
50
- validator.validate(x, key);
53
+ validator.parse(x, options);
51
54
  return true;
52
55
  }
53
- catch {
54
- return false;
56
+ catch (e) {
57
+ return e;
55
58
  }
56
59
  });
57
- if (!validated) {
58
- throw new Error(error(expected(to_union_string(this.#types), x), key));
60
+ if (!parsed.some(r => r === true)) {
61
+ throw new ParseError(error(union_error(this.#of), x, options));
59
62
  }
60
63
  return x;
61
64
  }
65
+ toJSON() {
66
+ return { type: this.name, of: this.#of.map(t => t.toJSON()) };
67
+ }
62
68
  }
63
69
  //# sourceMappingURL=UnionType.js.map
@@ -0,0 +1,5 @@
1
+ import PureType from "#PureType";
2
+ export default class UnknownType extends PureType<unknown, "unknown"> {
3
+ get name(): string;
4
+ }
5
+ //# sourceMappingURL=UnknownType.d.ts.map
@@ -0,0 +1,7 @@
1
+ import PureType from "#PureType";
2
+ export default class UnknownType extends PureType {
3
+ get name() {
4
+ return "unknown";
5
+ }
6
+ }
7
+ //# sourceMappingURL=UnknownType.js.map
@@ -1,3 +1,3 @@
1
- type Validator<T = unknown> = (x: T) => void;
1
+ type Validator<T> = (x: T) => void;
2
2
  export type { Validator as default };
3
3
  //# sourceMappingURL=Validator.d.ts.map
@@ -0,0 +1,6 @@
1
+ import GenericType from "#GenericType";
2
+ export default abstract class VirtualType<Type, Inferred, Name extends string> extends GenericType<Type, Inferred, Name> {
3
+ abstract get schema(): Type;
4
+ get datatype(): keyof import("./DataType.js").default;
5
+ }
6
+ //# sourceMappingURL=VirtualType.d.ts.map