arktype 1.0.27-alpha → 1.1.0-dev-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 (194) hide show
  1. package/dist/main.d.ts +1018 -0
  2. package/dist/main.js +1450 -0
  3. package/package.json +36 -108
  4. package/LICENSE +0 -7
  5. package/README.md +0 -351
  6. package/dist/cjs/main.js +0 -38
  7. package/dist/cjs/nodes/branch.js +0 -140
  8. package/dist/cjs/nodes/compose.js +0 -163
  9. package/dist/cjs/nodes/discriminate.js +0 -265
  10. package/dist/cjs/nodes/node.js +0 -139
  11. package/dist/cjs/nodes/predicate.js +0 -86
  12. package/dist/cjs/nodes/rules/class.js +0 -25
  13. package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
  14. package/dist/cjs/nodes/rules/divisor.js +0 -29
  15. package/dist/cjs/nodes/rules/props.js +0 -167
  16. package/dist/cjs/nodes/rules/range.js +0 -105
  17. package/dist/cjs/nodes/rules/regex.js +0 -26
  18. package/dist/cjs/nodes/rules/rules.js +0 -123
  19. package/dist/cjs/package.json +0 -3
  20. package/dist/cjs/parse/ast/ast.js +0 -4
  21. package/dist/cjs/parse/ast/bound.js +0 -16
  22. package/dist/cjs/parse/ast/config.js +0 -13
  23. package/dist/cjs/parse/ast/distributableFunction.js +0 -48
  24. package/dist/cjs/parse/ast/divisor.js +0 -9
  25. package/dist/cjs/parse/ast/intersection.js +0 -30
  26. package/dist/cjs/parse/ast/keyof.js +0 -111
  27. package/dist/cjs/parse/ast/morph.js +0 -58
  28. package/dist/cjs/parse/ast/narrow.js +0 -22
  29. package/dist/cjs/parse/ast/node.js +0 -4
  30. package/dist/cjs/parse/ast/tuple.js +0 -94
  31. package/dist/cjs/parse/ast/union.js +0 -9
  32. package/dist/cjs/parse/ast/utils.js +0 -4
  33. package/dist/cjs/parse/definition.js +0 -61
  34. package/dist/cjs/parse/record.js +0 -37
  35. package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
  36. package/dist/cjs/parse/string/reduce/shared.js +0 -23
  37. package/dist/cjs/parse/string/reduce/static.js +0 -4
  38. package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
  39. package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
  40. package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
  41. package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
  42. package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
  43. package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
  44. package/dist/cjs/parse/string/shift/scanner.js +0 -114
  45. package/dist/cjs/parse/string/string.js +0 -43
  46. package/dist/cjs/scopes/ark.js +0 -45
  47. package/dist/cjs/scopes/cache.js +0 -52
  48. package/dist/cjs/scopes/expressions.js +0 -29
  49. package/dist/cjs/scopes/jsObjects.js +0 -93
  50. package/dist/cjs/scopes/scope.js +0 -323
  51. package/dist/cjs/scopes/tsKeywords.js +0 -113
  52. package/dist/cjs/scopes/type.js +0 -50
  53. package/dist/cjs/scopes/validation/creditCard.js +0 -47
  54. package/dist/cjs/scopes/validation/date.js +0 -62
  55. package/dist/cjs/scopes/validation/validation.js +0 -108
  56. package/dist/cjs/traverse/problems.js +0 -281
  57. package/dist/cjs/traverse/traverse.js +0 -390
  58. package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
  59. package/dist/cjs/utils/data.js +0 -53
  60. package/dist/cjs/utils/domains.js +0 -30
  61. package/dist/cjs/utils/errors.js +0 -26
  62. package/dist/cjs/utils/freeze.js +0 -15
  63. package/dist/cjs/utils/generics.js +0 -63
  64. package/dist/cjs/utils/numericLiterals.js +0 -75
  65. package/dist/cjs/utils/objectKinds.js +0 -69
  66. package/dist/cjs/utils/paths.js +0 -32
  67. package/dist/cjs/utils/serialize.js +0 -74
  68. package/dist/cjs/utils/unionToTuple.js +0 -4
  69. package/dist/mjs/main.js +0 -8
  70. package/dist/mjs/nodes/branch.js +0 -123
  71. package/dist/mjs/nodes/compose.js +0 -141
  72. package/dist/mjs/nodes/discriminate.js +0 -250
  73. package/dist/mjs/nodes/node.js +0 -117
  74. package/dist/mjs/nodes/predicate.js +0 -69
  75. package/dist/mjs/nodes/rules/class.js +0 -11
  76. package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
  77. package/dist/mjs/nodes/rules/divisor.js +0 -15
  78. package/dist/mjs/nodes/rules/props.js +0 -149
  79. package/dist/mjs/nodes/rules/range.js +0 -86
  80. package/dist/mjs/nodes/rules/regex.js +0 -11
  81. package/dist/mjs/nodes/rules/rules.js +0 -106
  82. package/dist/mjs/package.json +0 -3
  83. package/dist/mjs/parse/ast/ast.js +0 -1
  84. package/dist/mjs/parse/ast/bound.js +0 -2
  85. package/dist/mjs/parse/ast/config.js +0 -9
  86. package/dist/mjs/parse/ast/distributableFunction.js +0 -34
  87. package/dist/mjs/parse/ast/divisor.js +0 -1
  88. package/dist/mjs/parse/ast/intersection.js +0 -16
  89. package/dist/mjs/parse/ast/keyof.js +0 -103
  90. package/dist/mjs/parse/ast/morph.js +0 -44
  91. package/dist/mjs/parse/ast/narrow.js +0 -14
  92. package/dist/mjs/parse/ast/node.js +0 -1
  93. package/dist/mjs/parse/ast/tuple.js +0 -80
  94. package/dist/mjs/parse/ast/union.js +0 -1
  95. package/dist/mjs/parse/ast/utils.js +0 -1
  96. package/dist/mjs/parse/definition.js +0 -46
  97. package/dist/mjs/parse/record.js +0 -29
  98. package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
  99. package/dist/mjs/parse/string/reduce/shared.js +0 -6
  100. package/dist/mjs/parse/string/reduce/static.js +0 -1
  101. package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
  102. package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
  103. package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
  104. package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
  105. package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
  106. package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
  107. package/dist/mjs/parse/string/shift/scanner.js +0 -106
  108. package/dist/mjs/parse/string/string.js +0 -28
  109. package/dist/mjs/scopes/ark.js +0 -28
  110. package/dist/mjs/scopes/cache.js +0 -38
  111. package/dist/mjs/scopes/expressions.js +0 -89
  112. package/dist/mjs/scopes/jsObjects.js +0 -82
  113. package/dist/mjs/scopes/scope.js +0 -303
  114. package/dist/mjs/scopes/tsKeywords.js +0 -116
  115. package/dist/mjs/scopes/type.js +0 -35
  116. package/dist/mjs/scopes/validation/creditCard.js +0 -34
  117. package/dist/mjs/scopes/validation/date.js +0 -48
  118. package/dist/mjs/scopes/validation/validation.js +0 -112
  119. package/dist/mjs/traverse/problems.js +0 -260
  120. package/dist/mjs/traverse/traverse.js +0 -373
  121. package/dist/mjs/utils/chainableNoOpProxy.js +0 -15
  122. package/dist/mjs/utils/data.js +0 -38
  123. package/dist/mjs/utils/domains.js +0 -15
  124. package/dist/mjs/utils/errors.js +0 -10
  125. package/dist/mjs/utils/freeze.js +0 -7
  126. package/dist/mjs/utils/generics.js +0 -38
  127. package/dist/mjs/utils/numericLiterals.js +0 -72
  128. package/dist/mjs/utils/objectKinds.js +0 -55
  129. package/dist/mjs/utils/paths.js +0 -18
  130. package/dist/mjs/utils/serialize.js +0 -58
  131. package/dist/mjs/utils/unionToTuple.js +0 -1
  132. package/dist/tsconfig.temp.tsbuildinfo +0 -1
  133. package/dist/types/main.d.ts +0 -15
  134. package/dist/types/nodes/branch.d.ts +0 -29
  135. package/dist/types/nodes/compose.d.ts +0 -98
  136. package/dist/types/nodes/discriminate.d.ts +0 -26
  137. package/dist/types/nodes/node.d.ts +0 -69
  138. package/dist/types/nodes/predicate.d.ts +0 -18
  139. package/dist/types/nodes/rules/class.d.ts +0 -4
  140. package/dist/types/nodes/rules/collapsibleSet.d.ts +0 -4
  141. package/dist/types/nodes/rules/divisor.d.ts +0 -3
  142. package/dist/types/nodes/rules/props.d.ts +0 -43
  143. package/dist/types/nodes/rules/range.d.ts +0 -34
  144. package/dist/types/nodes/rules/regex.d.ts +0 -5
  145. package/dist/types/nodes/rules/rules.d.ts +0 -33
  146. package/dist/types/parse/ast/ast.d.ts +0 -24
  147. package/dist/types/parse/ast/bound.d.ts +0 -27
  148. package/dist/types/parse/ast/config.d.ts +0 -15
  149. package/dist/types/parse/ast/distributableFunction.d.ts +0 -18
  150. package/dist/types/parse/ast/divisor.d.ts +0 -13
  151. package/dist/types/parse/ast/intersection.d.ts +0 -31
  152. package/dist/types/parse/ast/keyof.d.ts +0 -10
  153. package/dist/types/parse/ast/morph.d.ts +0 -17
  154. package/dist/types/parse/ast/narrow.d.ts +0 -21
  155. package/dist/types/parse/ast/node.d.ts +0 -35
  156. package/dist/types/parse/ast/tuple.d.ts +0 -41
  157. package/dist/types/parse/ast/union.d.ts +0 -17
  158. package/dist/types/parse/ast/utils.d.ts +0 -7
  159. package/dist/types/parse/definition.d.ts +0 -30
  160. package/dist/types/parse/record.d.ts +0 -26
  161. package/dist/types/parse/string/reduce/dynamic.d.ts +0 -34
  162. package/dist/types/parse/string/reduce/shared.d.ts +0 -25
  163. package/dist/types/parse/string/reduce/static.d.ts +0 -130
  164. package/dist/types/parse/string/shift/operand/enclosed.d.ts +0 -28
  165. package/dist/types/parse/string/shift/operand/operand.d.ts +0 -9
  166. package/dist/types/parse/string/shift/operand/unenclosed.d.ts +0 -18
  167. package/dist/types/parse/string/shift/operator/bounds.d.ts +0 -21
  168. package/dist/types/parse/string/shift/operator/divisor.d.ts +0 -13
  169. package/dist/types/parse/string/shift/operator/operator.d.ts +0 -13
  170. package/dist/types/parse/string/shift/scanner.d.ts +0 -89
  171. package/dist/types/parse/string/string.d.ts +0 -25
  172. package/dist/types/scopes/ark.d.ts +0 -208
  173. package/dist/types/scopes/cache.d.ts +0 -14
  174. package/dist/types/scopes/expressions.d.ts +0 -136
  175. package/dist/types/scopes/jsObjects.d.ts +0 -26
  176. package/dist/types/scopes/scope.d.ts +0 -99
  177. package/dist/types/scopes/tsKeywords.d.ts +0 -50
  178. package/dist/types/scopes/type.d.ts +0 -67
  179. package/dist/types/scopes/validation/creditCard.d.ts +0 -2
  180. package/dist/types/scopes/validation/date.d.ts +0 -23
  181. package/dist/types/scopes/validation/validation.d.ts +0 -49
  182. package/dist/types/traverse/problems.d.ts +0 -88
  183. package/dist/types/traverse/traverse.d.ts +0 -55
  184. package/dist/types/utils/chainableNoOpProxy.d.ts +0 -14
  185. package/dist/types/utils/data.d.ts +0 -13
  186. package/dist/types/utils/domains.d.ts +0 -32
  187. package/dist/types/utils/errors.d.ts +0 -6
  188. package/dist/types/utils/freeze.d.ts +0 -2
  189. package/dist/types/utils/generics.d.ts +0 -125
  190. package/dist/types/utils/numericLiterals.d.ts +0 -46
  191. package/dist/types/utils/objectKinds.d.ts +0 -84
  192. package/dist/types/utils/paths.d.ts +0 -9
  193. package/dist/types/utils/serialize.d.ts +0 -37
  194. package/dist/types/utils/unionToTuple.d.ts +0 -11
package/package.json CHANGED
@@ -1,109 +1,37 @@
1
1
  {
2
- "name": "arktype",
3
- "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
- "version": "1.0.27-alpha",
5
- "license": "MIT",
6
- "author": {
7
- "name": "David Blass",
8
- "email": "david@arktype.io",
9
- "url": "https://arktype.io"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/arktypeio/arktype.git"
14
- },
15
- "type": "module",
16
- "main": "./dist/cjs/main.js",
17
- "types": "./dist/types/main.d.ts",
18
- "exports": {
19
- ".": {
20
- "types": "./dist/types/main.d.ts",
21
- "import": "./dist/mjs/main.js",
22
- "require": "./dist/cjs/main.js"
23
- },
24
- "./internal/*": {
25
- "types": "./dist/types/*",
26
- "import": "./dist/mjs/*",
27
- "require": "./dist/cjs/*"
28
- }
29
- },
30
- "files": [
31
- "dist",
32
- "!*.tsbuildinfo"
33
- ],
34
- "packageManager": "pnpm@8.3.1",
35
- "devDependencies": {
36
- "@changesets/changelog-github": "0.4.8",
37
- "@changesets/cli": "2.26.1",
38
- "@swc/cli": "0.1.62",
39
- "@swc/core": "1.3.42",
40
- "@types/mocha": "10.0.1",
41
- "@types/node": "18.15.5",
42
- "@typescript-eslint/eslint-plugin": "5.56.0",
43
- "@typescript-eslint/parser": "5.56.0",
44
- "c8": "7.13.0",
45
- "eslint": "8.36.0",
46
- "eslint-config-prettier": "8.8.0",
47
- "eslint-define-config": "1.17.0",
48
- "eslint-plugin-only-warn": "1.1.0",
49
- "eslint-import-resolver-typescript": "3.5.3",
50
- "eslint-plugin-import": "2.27.5",
51
- "eslint-plugin-prefer-arrow": "1.2.3",
52
- "eslint-plugin-unicorn": "46.0.0",
53
- "husky": "8.0.3",
54
- "mocha": "10.2.0",
55
- "prettier": "2.8.6",
56
- "prettier-plugin-jsdoc": "0.4.2",
57
- "pretty-quick": "3.1.3",
58
- "ts-morph": "18.0.0",
59
- "ts-node": "10.9.1",
60
- "typescript": "5.0.3"
61
- },
62
- "c8": {
63
- "checkCoverage": true,
64
- "lines": 96,
65
- "src": "./src",
66
- "exclude": [
67
- "test/**",
68
- "dev/**"
69
- ],
70
- "extension": ".ts",
71
- "reporter": "lcovonly"
72
- },
73
- "prettier": {
74
- "tabWidth": 4,
75
- "semi": false,
76
- "trailingComma": "none"
77
- },
78
- "mocha": {
79
- "spec": [
80
- "./dev/test/*.test.*"
81
- ],
82
- "ignore": "**/node_modules/*",
83
- "node-option": [
84
- "loader=ts-node/esm",
85
- "no-warnings=ExperimentalWarning"
86
- ]
87
- },
88
- "eslintConfig": {
89
- "extends": "./dev/configs/.eslintrc.cjs"
90
- },
91
- "scripts": {
92
- "prChecks": "pnpm install && pnpm lint && pnpm checkFormat && pnpm testRepo && pnpm buildRepo",
93
- "build": "pnpm ts ./dev/scripts/build.ts",
94
- "buildRepo": "pnpm build && pnpm run -r build && pnpm build",
95
- "test": "pnpm ts ./dev/scripts/test.ts",
96
- "tnt": "pnpm ts ./dev/scripts/test.ts --skipTypes",
97
- "testRepo": "pnpm -r test && pnpm testTsVersions",
98
- "testTsVersions": "pnpm ts ./dev/scripts/testTsVersions.ts",
99
- "typecheck": "tsc --noEmit",
100
- "ts": "node --loader=ts-node/esm --no-warnings=ExperimentalWarning",
101
- "lint": "eslint --max-warnings=0 .",
102
- "format": "prettier --write --ignore-path ./dev/configs/.prettierignore .",
103
- "checkFormat": "prettier --check --ignore-path ./dev/configs/.prettierignore .",
104
- "findUnused": "pnpm ts ./dev/scripts/findUnusedExports.ts",
105
- "changeset": "pnpm ts ./dev/scripts/changeset.ts",
106
- "ci:version": "pnpm ts ./dev/scripts/updateVersions.ts",
107
- "ci:publish": "pnpm ts ./dev/scripts/changeset.ts publish"
108
- }
109
- }
2
+ "name": "arktype",
3
+ "description": "TypeScript's 1:1 validator, optimized from editor to runtime",
4
+ "version": "1.1.0-dev-1",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "David Blass",
8
+ "email": "david@arktype.io",
9
+ "url": "https://arktype.io"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/arktypeio/arktype.git"
14
+ },
15
+ "type": "module",
16
+ "exports": {
17
+ ".": {
18
+ "arktype-repo": "./main.js",
19
+ "import": "./dist/main.js"
20
+ },
21
+ "./internal/*": {
22
+ "arktype-repo": "./*",
23
+ "import": "./dist/*"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "scripts": {
30
+ "build": "tsup --config ../repo/tsup.config.ts",
31
+ "test": "ts ../repo/testPackage.ts"
32
+ },
33
+ "dependencies": {
34
+ "@arktype/util": "0.0.4",
35
+ "@arktype/schema": "0.0.1"
36
+ }
37
+ }
package/LICENSE DELETED
@@ -1,7 +0,0 @@
1
- Copyright 2022 ArkType
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md DELETED
@@ -1,351 +0,0 @@
1
- <h1 align="center">ArkType <sub><sup>TypeScript's 1:1 validator</sup></sub></h1>
2
-
3
- [<img src="./dev/arktype.io/static/img/arktype.gif">](https://arktype.io/try)
4
- <sub>
5
- <i>`typescript@4.9.5` in VS Code— no extensions or plugins required (<a href="#how">how?</a>) (<a href="https://arktype.io/try">try in-browser</a>)</i>
6
- </sub>
7
- <br />
8
-
9
- ## What is it?
10
-
11
- <!-- @snipStart:intro -->
12
-
13
- <p>ArkType is a runtime validation library that can infer <b>TypeScript definitions 1:1</b> and reuse them as <b>highly-optimized validators</b> for your data.</p>
14
-
15
- <p>With each character you type, you'll get <b>immediate feedback from your editor</b> in the form of either a fully-inferred <code>Type</code> or a specific and helpful <code>ParseError</code>.</p>
16
-
17
- <p>This result exactly mirrors what you can expect to happen at runtime down to the punctuation of the error message- <b>no plugins required</b>.</p>
18
-
19
- <!-- @snipEnd -->
20
-
21
- ```ts @blockFrom:dev/test/examples/type.ts
22
- import { type } from "arktype"
23
-
24
- // Definitions are statically parsed and inferred as TS.
25
- export const user = type({
26
- name: "string",
27
- device: {
28
- platform: "'android'|'ios'",
29
- "version?": "number"
30
- }
31
- })
32
-
33
- // Validators return typed data or clear, customizable errors.
34
- export const { data, problems } = user({
35
- name: "Alan Turing",
36
- device: {
37
- // problems.summary: "device/platform must be 'android' or 'ios' (was 'enigma')"
38
- platform: "enigma"
39
- }
40
- })
41
- ```
42
-
43
- Check out [how it works](#how), [try it in-browser](https://arktype.io/docs/#your-first-type), or [scroll slightly](#install) to read about installation.
44
-
45
- <a id="install" />
46
-
47
- <!-- @snipStart:install -->
48
-
49
- ## Install <sub><sub>📦`12KB` gzipped, `0` dependencies</sub></sub>
50
-
51
- <img src="./dev/arktype.io/static/img/npm.svg" alt="Npm Icon" height="16px" /> <code>npm install arktype</code>
52
- <sub>(or whatever package manager you prefer)</sub>
53
- <br />
54
-
55
- Our types are tested in [strict-mode](https://www.typescriptlang.org/tsconfig#strict) with TypeScript versions `4.8`, `4.9`, and `5.0`.
56
-
57
- _Our APIs have mostly stabilized, but details may still change during the alpha/beta stages of our 1.0 release. If you have suggestions that may require a breaking change, now is the time to let us know!_ ⛵
58
-
59
- <!-- @snipEnd -->
60
-
61
- ### Scopes
62
-
63
- [Try this example in-browser.](https://arktype.io/docs/scopes)
64
-
65
- ```ts @blockFrom:dev/test/examples/scope.ts
66
- import { scope } from "arktype"
67
-
68
- // Scopes are collections of types that can reference each other.
69
- export const types = scope({
70
- package: {
71
- name: "string",
72
- "dependencies?": "package[]",
73
- "contributors?": "contributor[]"
74
- },
75
- contributor: {
76
- // Subtypes like 'email' are inferred like 'string' but provide additional validation at runtime.
77
- email: "email",
78
- "packages?": "package[]"
79
- }
80
- }).compile()
81
-
82
- // Cyclic types are inferred to arbitrary depth...
83
- export type Package = typeof types.package.infer
84
-
85
- // And can validate cyclic data.
86
- const packageData: Package = {
87
- name: "arktype",
88
- dependencies: [{ name: "typescript" }],
89
- contributors: [{ email: "david@sharktypeio" }]
90
- }
91
- packageData.dependencies![0].dependencies = [packageData]
92
-
93
- export const { data, problems } = types.package(packageData)
94
- ```
95
-
96
- ## Syntax
97
-
98
- This is an informal, non-exhaustive list of current and upcoming ArkType syntax.
99
-
100
- There are some subjects it doesn't cover, primarily tuple expressions and scopes. As mentioned below, keep an eye out for comprehensive docs coming with the upcoming beta release. In the meantime, join [our Discord](https://discord.gg/xEzdc3fJQC) or head to our [GitHub Discussions](https://github.com/arktypeio/arktype/discussions) to ask a question and there's a good chance you'll see a response within the hour 😊
101
-
102
- ```ts
103
- export const currentTsSyntax = type({
104
- keyword: "null",
105
- stringLiteral: "'TS'",
106
- numberLiteral: "5",
107
- bigintLiteral: "5n",
108
- union: "string|number",
109
- intersection: "boolean&true",
110
- array: "Date[]",
111
- grouping: "(0|1)[]",
112
- objectLiteral: {
113
- nested: "string",
114
- "optional?": "number"
115
- },
116
- tuple: ["number", "number"]
117
- })
118
-
119
- // these features will be available in the upcoming release
120
-
121
- export const upcomingTsSyntax = type({
122
- keyof: "keyof bigint",
123
- thisKeyword: "this", // recurses to the root of the current type
124
- variadicTuples: ["true", "...false[]"]
125
- })
126
-
127
- export const validationSyntax = type({
128
- keywords: "email|uuid|creditCard|integer", // and many more
129
- builtinParsers: "parsedDate", // parses a Date from a string
130
- nativeRegexLiteral: /@arktype\.io/,
131
- embeddedRegexLiteral: "email&/@arktype\\.io/",
132
- divisibility: "number%10", // a multiple of 10
133
- bound: "alpha>10", // an alpha-only string with more than 10 characters
134
- range: "1<=email[]<99", // a list of 1 to 99 emails
135
- narrows: ["number", "=>", (n) => n % 2 === 1], // an odd integer
136
- morphs: ["string", "|>", parseFloat] // validates a string input then parses it to a number
137
- })
138
-
139
- // in the upcoming release, you can use chaining to define expressions directly
140
- // that use objects or functions that can't be embedded in strings
141
-
142
- export const parseBigintLiteral = type({ value: "string" })
143
- .and({
144
- format: "'bigint'"
145
- })
146
- .narrow((data): data is { value: `${string}n`; format: "bigint" } =>
147
- data.value.endsWith("n")
148
- )
149
- .morph((data) => BigInt(data.value.slice(-1)))
150
-
151
- export const { data, problems } = parseBigintLiteral("999n")
152
- // ^ bigint | undefined
153
- ```
154
-
155
- ## API
156
-
157
- <!--@snipStart:api -->
158
-
159
- ArkType supports many of TypeScript's built-in types and operators, as well as some new ones dedicated exclusively to runtime validation. In fact, we got a little ahead of ourselves and built a ton of cool features, but we're still working on getting caught up syntax and API docs. Keep an eye out for more in the next couple weeks ⛵
160
-
161
- In the meantime, check out the examples here and use the type hints you get to learn how you can customize your types and scopes. If you want to explore some of the more advanced features, take a look at [our unit tests](./dev/test) or ask us [on Discord](https://discord.gg/xEzdc3fJQC) if your functionality is supported. If not, [create a GitHub issue](https://github.com/arktypeio/arktype/issues/new) so we can prioritize it!
162
-
163
- <!--@snipEnd -->
164
-
165
- ## Integrations
166
-
167
- ### tRPC
168
-
169
- ArkType can easily be used with tRPC via the `assert` prop:
170
-
171
- ```ts
172
- ...
173
- t.procedure
174
- .input(
175
- type({
176
- name: "string",
177
- "age?": "number"
178
- }).assert
179
- )
180
- ...
181
- ```
182
-
183
- ## How?
184
-
185
- ArkType's isomorphic parser has parallel static and dynamic implementations. This means as soon as you type a definition in your editor, you'll know the eventual result at runtime.
186
-
187
- If you're curious, below is an example of what that looks like under the hood. If not, close that hood back up, `npm install arktype` and enjoy top-notch developer experience 🧑‍💻
188
-
189
- ```ts @blockFrom:src/parse/string/shift/operator/operator.ts:parseOperator
190
- export const parseOperator = (s: DynamicState): void => {
191
- const lookahead = s.scanner.shift()
192
- return lookahead === ""
193
- ? s.finalize()
194
- : lookahead === "["
195
- ? s.scanner.shift() === "]"
196
- ? s.rootToArray()
197
- : s.error(incompleteArrayTokenMessage)
198
- : isKeyOf(lookahead, Scanner.branchTokens)
199
- ? s.pushRootToBranch(lookahead)
200
- : lookahead === ")"
201
- ? s.finalizeGroup()
202
- : isKeyOf(lookahead, Scanner.comparatorStartChars)
203
- ? parseBound(s, lookahead)
204
- : lookahead === "%"
205
- ? parseDivisor(s)
206
- : lookahead === " "
207
- ? parseOperator(s)
208
- : throwInternalError(writeUnexpectedCharacterMessage(lookahead))
209
- }
210
-
211
- export type parseOperator<s extends StaticState> =
212
- s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned>
213
- ? lookahead extends "["
214
- ? unscanned extends Scanner.shift<"]", infer nextUnscanned>
215
- ? state.setRoot<s, [s["root"], "[]"], nextUnscanned>
216
- : error<incompleteArrayTokenMessage>
217
- : lookahead extends Scanner.BranchToken
218
- ? state.reduceBranch<s, lookahead, unscanned>
219
- : lookahead extends ")"
220
- ? state.finalizeGroup<s, unscanned>
221
- : lookahead extends Scanner.ComparatorStartChar
222
- ? parseBound<s, lookahead, unscanned>
223
- : lookahead extends "%"
224
- ? parseDivisor<s, unscanned>
225
- : lookahead extends " "
226
- ? parseOperator<state.scanTo<s, unscanned>>
227
- : error<writeUnexpectedCharacterMessage<lookahead>>
228
- : state.finalize<s>
229
- ```
230
-
231
- ## Contributions
232
-
233
- We accept and encourage pull requests from outside ArkType.
234
-
235
- Depending on your level of familiarity with type systems and TS generics, some parts of the codebase may be hard to jump into. That said, there's plenty of opportunities for more straightforward contributions.
236
-
237
- If you're planning on submitting a non-trivial fix or a new feature, please [create an issue first](https://github.com/arktypeio/arktype/issues/new) so everyone's on the same page. The last thing we want is for you to spend time on a submission we're unable to merge.
238
-
239
- When you're ready, check out our [guide](./.github/CONTRIBUTING.md) to get started!
240
-
241
- ## License
242
-
243
- This project is licensed under the terms of the
244
- [MIT license](./LICENSE).
245
-
246
- ## Collaboration
247
-
248
- I'd love to hear about what you're working on and how ArkType can help. Please reach out to david@arktype.io.
249
-
250
- ## Code of Conduct
251
-
252
- We will not tolerate any form of disrespect toward members of our community. Please refer to our [Code of Conduct](./.github/CODE_OF_CONDUCT.md) and reach out to david@arktype.io immediately if you've seen or experienced an interaction that may violate these standards.
253
-
254
- ## Sponsorship
255
-
256
- We've been working full-time on this project for over a year and it means a lot to have the community behind us.
257
-
258
- If the project has been useful to you and you are in a financial position to do so, please chip in via [GitHub Sponsors](https://github.com/sponsors/arktypeio).
259
-
260
- Otherwise, consider sending me an email (david@arktype.io) or [message me on Discord](https://arktype.io/discord) to let me know you're a fan of ArkType. Either would make my day!
261
-
262
- ### Current Sponsors 🥰
263
-
264
- <table>
265
- <tr>
266
- <th>fubhy</th>
267
- <th>sam-goodwin</th>
268
- <th>tmm</th>
269
- <th>thomasballinger</th>
270
- <th>jacksteamdev</th>
271
- </tr>
272
- <tr>
273
- <td>
274
- <a href="https://github.com/fubhy"
275
- ><img
276
- height="64px"
277
- src="https://avatars.githubusercontent.com/u/1172528"
278
- /></a>
279
- </td>
280
- <td>
281
- <a href="https://github.com/sam-goodwin"
282
- ><img
283
- height="64px"
284
- src="https://avatars.githubusercontent.com/u/38672686"
285
- /></a>
286
- </td>
287
- <td>
288
- <a href="https://github.com/tmm"
289
- ><img
290
- height="64px"
291
- src="https://avatars.githubusercontent.com/u/6759464"
292
- /></a>
293
- </td>
294
- <td>
295
- <a href="https://github.com/thomasballinger"
296
- ><img
297
- height="64px"
298
- src="https://avatars.githubusercontent.com/u/458879"
299
- /></a>
300
- </td>
301
- <td>
302
- <a href="https://github.com/jacksteamdev"
303
- ><img
304
- height="64px"
305
- src="https://avatars.githubusercontent.com/u/23390212"
306
- /></a>
307
- </td>
308
- </tr>
309
- <tr>
310
- <th>neodon</th>
311
- <th>mewhhaha</th>
312
- <th>codeandcats</th>
313
- <th>xrexy</th>
314
- <th>Timeraa</th>
315
- </tr>
316
- <tr>
317
- <td>
318
- <a href="https://github.com/neodon"
319
- ><img height="64px" src="https://avatars.githubusercontent.com/u/82944"
320
- /></a>
321
- </td>
322
- <td>
323
- <a href="https://github.com/mewhhaha"
324
- ><img
325
- height="64px"
326
- src="https://avatars.githubusercontent.com/u/3399205"
327
- /></a>
328
- </td>
329
- <td>
330
- <a href="https://github.com/codeandcats"
331
- ><img
332
- height="64px"
333
- src="https://avatars.githubusercontent.com/u/6035934"
334
- /></a>
335
- </td>
336
- <td>
337
- <a href="https://github.com/xrexy"
338
- ><img
339
- height="64px"
340
- src="https://avatars.githubusercontent.com/u/71969236"
341
- /></a>
342
- </td>
343
- <td>
344
- <a href="https://github.com/Timeraa"
345
- ><img
346
- height="64px"
347
- src="https://avatars.githubusercontent.com/u/29104008"
348
- /></a>
349
- </td>
350
- </tr>
351
- </table>
package/dist/cjs/main.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- scope: ()=>_scopeJs.scope,
13
- type: ()=>_arkJs.type,
14
- ark: ()=>_arkJs.ark,
15
- arkScope: ()=>_arkJs.arkScope,
16
- arrayOf: ()=>_expressionsJs.arrayOf,
17
- instanceOf: ()=>_expressionsJs.instanceOf,
18
- intersection: ()=>_expressionsJs.intersection,
19
- keyOf: ()=>_expressionsJs.keyOf,
20
- morph: ()=>_expressionsJs.morph,
21
- narrow: ()=>_expressionsJs.narrow,
22
- union: ()=>_expressionsJs.union,
23
- valueOf: ()=>_expressionsJs.valueOf,
24
- jsObjectsScope: ()=>_jsObjectsJs.jsObjectsScope,
25
- tsKeywordsScope: ()=>_tsKeywordsJs.tsKeywordsScope,
26
- validationScope: ()=>_validationJs.validationScope,
27
- Problems: ()=>_problemsJs.Problems,
28
- Problem: ()=>_problemsJs.Problem,
29
- parseConfigTuple: ()=>_configJs.parseConfigTuple
30
- });
31
- const _scopeJs = require("./scopes/scope.js");
32
- const _arkJs = require("./scopes/ark.js");
33
- const _expressionsJs = require("./scopes/expressions.js");
34
- const _jsObjectsJs = require("./scopes/jsObjects.js");
35
- const _tsKeywordsJs = require("./scopes/tsKeywords.js");
36
- const _validationJs = require("./scopes/validation/validation.js");
37
- const _problemsJs = require("./traverse/problems.js");
38
- const _configJs = require("./parse/ast/config.js");
@@ -1,140 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- isBranchComparison: ()=>isBranchComparison,
13
- compareBranches: ()=>compareBranches,
14
- isTransformationBranch: ()=>isTransformationBranch,
15
- flattenBranch: ()=>flattenBranch,
16
- branchIntersection: ()=>branchIntersection
17
- });
18
- const _intersectionJs = require("../parse/ast/intersection.js");
19
- const _domainsJs = require("../utils/domains.js");
20
- const _errorsJs = require("../utils/errors.js");
21
- const _composeJs = require("./compose.js");
22
- const _rulesJs = require("./rules/rules.js");
23
- const isBranchComparison = (comparison)=>comparison?.lBranches !== undefined;
24
- const compareBranches = (lConditions, rConditions, state)=>{
25
- const result = {
26
- lBranches: lConditions,
27
- rBranches: rConditions,
28
- lExtendsR: [],
29
- rExtendsL: [],
30
- equalities: [],
31
- distinctIntersections: []
32
- };
33
- const pairs = rConditions.map((condition)=>({
34
- condition,
35
- distinct: []
36
- }));
37
- lConditions.forEach((l, lIndex)=>{
38
- let lImpliesR = false;
39
- const distinct = pairs.map((rPairs, rIndex)=>{
40
- if (lImpliesR || !rPairs.distinct) {
41
- return null;
42
- }
43
- const r = rPairs.condition;
44
- const subresult = branchIntersection(l, r, state);
45
- if ((0, _composeJs.isDisjoint)(subresult)) {
46
- // doesn't tell us about any redundancies or add a distinct pair
47
- return null;
48
- } else if (subresult === l) {
49
- result.lExtendsR.push(lIndex);
50
- // If l is a subtype of the current r branch, intersections
51
- // with the remaining branches of r won't lead to distinct
52
- // branches, so we set a flag indicating we can skip them.
53
- lImpliesR = true;
54
- return null;
55
- } else if (subresult === r) {
56
- result.rExtendsL.push(rIndex);
57
- // If r is a subtype of the current l branch, it is removed
58
- // from pairsByR because future intersections won't lead to
59
- // distinct branches.
60
- rPairs.distinct = null;
61
- return null;
62
- } else if ((0, _composeJs.isEquality)(subresult)) {
63
- // Combination of l and r subtype cases.
64
- result.equalities.push([
65
- lIndex,
66
- rIndex
67
- ]);
68
- lImpliesR = true;
69
- rPairs.distinct = null;
70
- return null;
71
- } else if ((0, _domainsJs.hasDomain)(subresult, "object")) {
72
- // Neither branch is a subtype of the other, return
73
- // the result of the intersection as a candidate
74
- // branch for the final union
75
- return subresult;
76
- }
77
- return (0, _errorsJs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsJs.domainOf)(subresult)}'`);
78
- });
79
- if (!lImpliesR) {
80
- for(let i = 0; i < pairs.length; i++){
81
- if (distinct[i]) {
82
- pairs[i].distinct?.push(distinct[i]);
83
- }
84
- }
85
- }
86
- });
87
- result.distinctIntersections = pairs.flatMap((pairs)=>pairs.distinct ?? []);
88
- return result;
89
- };
90
- const isTransformationBranch = (branch)=>"rules" in branch;
91
- const flattenBranch = (branch, ctx)=>{
92
- if (isTransformationBranch(branch)) {
93
- const result = (0, _rulesJs.flattenRules)(branch.rules, ctx);
94
- if (branch.morph) {
95
- if (typeof branch.morph === "function") {
96
- result.push([
97
- "morph",
98
- branch.morph
99
- ]);
100
- } else {
101
- for (const morph of branch.morph){
102
- result.push([
103
- "morph",
104
- morph
105
- ]);
106
- }
107
- }
108
- }
109
- return result;
110
- }
111
- return (0, _rulesJs.flattenRules)(branch, ctx);
112
- };
113
- const rulesOf = (branch)=>branch.rules ?? branch;
114
- const branchIntersection = (l, r, state)=>{
115
- const lRules = rulesOf(l);
116
- const rRules = rulesOf(r);
117
- const rulesResult = (0, _rulesJs.rulesIntersection)(lRules, rRules, state);
118
- if ("morph" in l) {
119
- if ("morph" in r) {
120
- if (l.morph === r.morph) {
121
- return (0, _composeJs.isEquality)(rulesResult) || (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
122
- rules: rulesResult,
123
- morph: l.morph
124
- };
125
- }
126
- return state.lastOperator === "&" ? (0, _errorsJs.throwParseError)((0, _intersectionJs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
127
- }
128
- return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
129
- rules: (0, _composeJs.isEquality)(rulesResult) ? l.rules : rulesResult,
130
- morph: l.morph
131
- };
132
- }
133
- if ("morph" in r) {
134
- return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
135
- rules: (0, _composeJs.isEquality)(rulesResult) ? r.rules : rulesResult,
136
- morph: r.morph
137
- };
138
- }
139
- return rulesResult;
140
- };