bupkis 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +8 -8
- package/dist/commonjs/assertion/assertion-types.d.ts +33 -82
- package/dist/commonjs/assertion/assertion-types.d.ts.map +1 -1
- package/dist/commonjs/assertion/create.d.ts +5 -33
- package/dist/commonjs/assertion/create.d.ts.map +1 -1
- package/dist/commonjs/assertion/create.js +17 -6
- package/dist/commonjs/assertion/create.js.map +1 -1
- package/dist/commonjs/assertion/impl/async.d.ts +5 -5
- package/dist/commonjs/assertion/impl/async.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/async.js +2 -2
- package/dist/commonjs/assertion/impl/async.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts +24 -24
- package/dist/commonjs/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/commonjs/assertion/impl/sync-parametric.js +3 -3
- package/dist/commonjs/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/commonjs/assertion/impl/sync.d.ts +50 -50
- package/dist/commonjs/assertion/impl/sync.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.d.ts +71 -61
- package/dist/commonjs/bootstrap.d.ts.map +1 -1
- package/dist/commonjs/bootstrap.js +20 -10
- package/dist/commonjs/bootstrap.js.map +1 -1
- package/dist/commonjs/error.d.ts +12 -5
- package/dist/commonjs/error.d.ts.map +1 -1
- package/dist/commonjs/error.js +19 -4
- package/dist/commonjs/error.js.map +1 -1
- package/dist/commonjs/expect.d.ts +130 -3
- package/dist/commonjs/expect.d.ts.map +1 -1
- package/dist/commonjs/expect.js +115 -0
- package/dist/commonjs/expect.js.map +1 -1
- package/dist/commonjs/guards.d.ts +22 -15
- package/dist/commonjs/guards.d.ts.map +1 -1
- package/dist/commonjs/guards.js +34 -20
- package/dist/commonjs/guards.js.map +1 -1
- package/dist/commonjs/index.d.ts +113 -62
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +44 -42
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/metadata.d.ts +1 -27
- package/dist/commonjs/metadata.d.ts.map +1 -1
- package/dist/commonjs/metadata.js +16 -15
- package/dist/commonjs/metadata.js.map +1 -1
- package/dist/commonjs/schema.d.ts +59 -26
- package/dist/commonjs/schema.d.ts.map +1 -1
- package/dist/commonjs/schema.js +57 -24
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/types.d.ts +449 -39
- package/dist/commonjs/types.d.ts.map +1 -1
- package/dist/commonjs/types.js +12 -2
- package/dist/commonjs/types.js.map +1 -1
- package/dist/commonjs/util.d.ts +7 -0
- package/dist/commonjs/util.d.ts.map +1 -1
- package/dist/commonjs/util.js +7 -0
- package/dist/commonjs/util.js.map +1 -1
- package/dist/esm/assertion/assertion-types.d.ts +33 -82
- package/dist/esm/assertion/assertion-types.d.ts.map +1 -1
- package/dist/esm/assertion/create.d.ts +5 -33
- package/dist/esm/assertion/create.d.ts.map +1 -1
- package/dist/esm/assertion/create.js +14 -4
- package/dist/esm/assertion/create.js.map +1 -1
- package/dist/esm/assertion/impl/async.d.ts +5 -5
- package/dist/esm/assertion/impl/async.d.ts.map +1 -1
- package/dist/esm/assertion/impl/async.js +2 -2
- package/dist/esm/assertion/impl/async.js.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.d.ts +24 -24
- package/dist/esm/assertion/impl/sync-parametric.d.ts.map +1 -1
- package/dist/esm/assertion/impl/sync-parametric.js +3 -3
- package/dist/esm/assertion/impl/sync-parametric.js.map +1 -1
- package/dist/esm/assertion/impl/sync.d.ts +50 -50
- package/dist/esm/assertion/impl/sync.d.ts.map +1 -1
- package/dist/esm/bootstrap.d.ts +71 -61
- package/dist/esm/bootstrap.d.ts.map +1 -1
- package/dist/esm/bootstrap.js +19 -9
- package/dist/esm/bootstrap.js.map +1 -1
- package/dist/esm/error.d.ts +12 -5
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +19 -4
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/expect.d.ts +130 -3
- package/dist/esm/expect.d.ts.map +1 -1
- package/dist/esm/expect.js +115 -0
- package/dist/esm/expect.js.map +1 -1
- package/dist/esm/guards.d.ts +22 -15
- package/dist/esm/guards.d.ts.map +1 -1
- package/dist/esm/guards.js +29 -13
- package/dist/esm/guards.js.map +1 -1
- package/dist/esm/index.d.ts +113 -62
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +46 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/metadata.d.ts +1 -27
- package/dist/esm/metadata.d.ts.map +1 -1
- package/dist/esm/metadata.js +2 -1
- package/dist/esm/metadata.js.map +1 -1
- package/dist/esm/schema.d.ts +59 -26
- package/dist/esm/schema.d.ts.map +1 -1
- package/dist/esm/schema.js +57 -24
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/types.d.ts +449 -39
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +12 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/util.d.ts +7 -0
- package/dist/esm/util.d.ts.map +1 -1
- package/dist/esm/util.js +7 -0
- package/dist/esm/util.js.map +1 -1
- package/package.json +89 -15
- package/src/assertion/assertion-types.ts +38 -41
- package/src/assertion/create.ts +16 -65
- package/src/assertion/impl/async.ts +2 -2
- package/src/assertion/impl/sync-parametric.ts +3 -3
- package/src/bootstrap.ts +21 -10
- package/src/error.ts +21 -4
- package/src/expect.ts +269 -18
- package/src/guards.ts +29 -51
- package/src/index.ts +71 -11
- package/src/metadata.ts +3 -4
- package/src/schema.ts +59 -26
- package/src/types.ts +593 -72
- package/src/util.ts +7 -0
- package/dist/commonjs/api.d.ts +0 -93
- package/dist/commonjs/api.d.ts.map +0 -1
- package/dist/commonjs/api.js +0 -8
- package/dist/commonjs/api.js.map +0 -1
- package/dist/esm/api.d.ts +0 -93
- package/dist/esm/api.d.ts.map +0 -1
- package/dist/esm/api.js +0 -7
- package/dist/esm/api.js.map +0 -1
- package/src/api.ts +0 -149
- package/src/schema.md +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bupkis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Uncommonly extensible assertions for the beautiful people",
|
|
6
6
|
"repository": {
|
|
@@ -20,6 +20,56 @@
|
|
|
20
20
|
"module": "./dist/esm/index.js",
|
|
21
21
|
"exports": {
|
|
22
22
|
"./package.json": "./package.json",
|
|
23
|
+
"./types": {
|
|
24
|
+
"import": {
|
|
25
|
+
"types": "./dist/esm/types.d.ts",
|
|
26
|
+
"default": "./dist/esm/types.js"
|
|
27
|
+
},
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./dist/commonjs/types.d.ts",
|
|
30
|
+
"default": "./dist/commonjs/types.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"./util": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/esm/util.d.ts",
|
|
36
|
+
"default": "./dist/esm/util.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/commonjs/util.d.ts",
|
|
40
|
+
"default": "./dist/commonjs/util.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./schema": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/esm/schema.d.ts",
|
|
46
|
+
"default": "./dist/esm/schema.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/commonjs/schema.d.ts",
|
|
50
|
+
"default": "./dist/commonjs/schema.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"./guards": {
|
|
54
|
+
"import": {
|
|
55
|
+
"types": "./dist/esm/guards.d.ts",
|
|
56
|
+
"default": "./dist/esm/guards.js"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./dist/commonjs/guards.d.ts",
|
|
60
|
+
"default": "./dist/commonjs/guards.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"./assertions": {
|
|
64
|
+
"import": {
|
|
65
|
+
"types": "./dist/esm/assertion/index.d.ts",
|
|
66
|
+
"default": "./dist/esm/assertion/index.js"
|
|
67
|
+
},
|
|
68
|
+
"require": {
|
|
69
|
+
"types": "./dist/commonjs/assertion/index.d.ts",
|
|
70
|
+
"default": "./dist/commonjs/assertion/index.js"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
23
73
|
".": {
|
|
24
74
|
"import": {
|
|
25
75
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -57,11 +107,11 @@
|
|
|
57
107
|
],
|
|
58
108
|
"scripts": {
|
|
59
109
|
"build": "tshy",
|
|
60
|
-
"build:
|
|
61
|
-
"build:docs
|
|
62
|
-
"dev": "
|
|
63
|
-
"dev
|
|
64
|
-
"lint": "run-p lint:eslint lint:types lint:knip",
|
|
110
|
+
"build:dev": "tshy --watch",
|
|
111
|
+
"build:docs": "typedoc --cleanOutputDir --treatWarningsAsErrors",
|
|
112
|
+
"build:docs:dev": "run-s \"build:docs -- --watch\"",
|
|
113
|
+
"docs:dev": "run-p build:docs:dev serve",
|
|
114
|
+
"lint": "run-p lint:eslint lint:types lint:knip lint:markdown",
|
|
65
115
|
"lint:commit": "commitlint",
|
|
66
116
|
"lint:eslint": "eslint .",
|
|
67
117
|
"lint:fix": "run-s \"lint:eslint -- --fix\"",
|
|
@@ -69,15 +119,16 @@
|
|
|
69
119
|
"lint:markdown": "markdownlint-cli2 \"**/*.md\"",
|
|
70
120
|
"lint:staged": "lint-staged",
|
|
71
121
|
"lint:types": "tsc -b .config/tsconfig.eslint.json",
|
|
72
|
-
"lint:types:dev": "
|
|
122
|
+
"lint:types:dev": "run-s \"lint:types -- --watch\"",
|
|
73
123
|
"prepare": "husky; run-s build",
|
|
74
124
|
"prepublishOnly": "run-s build",
|
|
75
125
|
"serve": "serve docs",
|
|
76
|
-
"test": "node
|
|
77
|
-
"test:
|
|
78
|
-
"test:
|
|
79
|
-
"test:
|
|
80
|
-
"test:
|
|
126
|
+
"test": "node $npm_package_testConfig_test_flags \"$npm_package_testConfig_test_pattern_all\"",
|
|
127
|
+
"test:coverage": "c8 --reporter=lcov --reporter=text npm test",
|
|
128
|
+
"test:dev": "node $npm_package_testConfig_test_flags --watch \"$npm_package_testConfig_test_pattern_all\"",
|
|
129
|
+
"test:profile": "node --cpu-prof --cpu-prof-dir=.profiles $npm_package_testConfig_test_flags \"$npm_package_testConfig_test_pattern_all\"",
|
|
130
|
+
"test:property": "node $npm_package_testConfig_test_flags \"$npm_package_testConfig_test_pattern_property\"",
|
|
131
|
+
"test:property:dev": "node $npm_package_testConfig_test_flags --watch \"$npm_package_testConfig_test_pattern_property\""
|
|
81
132
|
},
|
|
82
133
|
"peerDependencies": {
|
|
83
134
|
"zod": "^4.1.5"
|
|
@@ -97,6 +148,7 @@
|
|
|
97
148
|
"@types/node": "22.18.1",
|
|
98
149
|
"@types/slug": "5.0.9",
|
|
99
150
|
"@types/wallabyjs": "0.0.15",
|
|
151
|
+
"c8": "10.1.3",
|
|
100
152
|
"eslint": "9.35.0",
|
|
101
153
|
"eslint-plugin-jsonc": "2.20.1",
|
|
102
154
|
"eslint-plugin-perfectionist": "4.15.0",
|
|
@@ -118,7 +170,10 @@
|
|
|
118
170
|
"tsx": "4.20.5",
|
|
119
171
|
"type-fest": "4.41.0",
|
|
120
172
|
"typedoc": "0.28.12",
|
|
173
|
+
"typedoc-plugin-dt-links": "2.0.18",
|
|
174
|
+
"typedoc-plugin-extras": "4.0.1",
|
|
121
175
|
"typedoc-plugin-mdn-links": "5.0.9",
|
|
176
|
+
"typedoc-plugin-redirect": "1.2.0",
|
|
122
177
|
"typedoc-plugin-zod": "1.4.2",
|
|
123
178
|
"typescript": "5.9.2",
|
|
124
179
|
"typescript-eslint": "8.42.0"
|
|
@@ -130,13 +185,15 @@
|
|
|
130
185
|
"knip": {
|
|
131
186
|
"ignoreDependencies": [
|
|
132
187
|
"@types/wallabyjs",
|
|
133
|
-
"markdownlint-cli2-formatter-pretty"
|
|
188
|
+
"markdownlint-cli2-formatter-pretty",
|
|
189
|
+
"expect-type",
|
|
190
|
+
"tsx"
|
|
134
191
|
],
|
|
135
192
|
"ignore": [
|
|
136
193
|
".wallaby.js",
|
|
137
194
|
"**/*.cts",
|
|
138
195
|
"**/*.d.ts",
|
|
139
|
-
"
|
|
196
|
+
"site/media/**/*"
|
|
140
197
|
],
|
|
141
198
|
"tags": [
|
|
142
199
|
"-knipignore"
|
|
@@ -144,7 +201,14 @@
|
|
|
144
201
|
"node": {
|
|
145
202
|
"entry": [
|
|
146
203
|
"scripts/*.js",
|
|
147
|
-
"test/**/*.test.ts"
|
|
204
|
+
"test/**/*.test.ts",
|
|
205
|
+
"test/types.types-test.ts",
|
|
206
|
+
"src/assertion/index.ts",
|
|
207
|
+
"src/index.ts",
|
|
208
|
+
"src/types.ts",
|
|
209
|
+
"src/util.ts",
|
|
210
|
+
"src/schema.ts",
|
|
211
|
+
"src/guards.ts"
|
|
148
212
|
]
|
|
149
213
|
}
|
|
150
214
|
},
|
|
@@ -168,9 +232,19 @@
|
|
|
168
232
|
"singleQuote": true,
|
|
169
233
|
"tsdoc": true
|
|
170
234
|
},
|
|
235
|
+
"testConfig": {
|
|
236
|
+
"test_flags": "--import tsx --test --test-reporter=spec",
|
|
237
|
+
"test_pattern_all": "test/**/*.ts",
|
|
238
|
+
"test_pattern_property": "test/property/**/*.test.ts"
|
|
239
|
+
},
|
|
171
240
|
"tshy": {
|
|
172
241
|
"exports": {
|
|
173
242
|
"./package.json": "./package.json",
|
|
243
|
+
"./types": "./src/types.ts",
|
|
244
|
+
"./util": "./src/util.ts",
|
|
245
|
+
"./schema": "./src/schema.ts",
|
|
246
|
+
"./guards": "./src/guards.ts",
|
|
247
|
+
"./assertions": "./src/assertion/index.ts",
|
|
174
248
|
".": "./src/index.ts"
|
|
175
249
|
}
|
|
176
250
|
}
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
import { type ArrayValues, type NonEmptyTuple } from 'type-fest';
|
|
13
13
|
import { type z } from 'zod/v4';
|
|
14
14
|
|
|
15
|
-
import type { createAssertion as _createAssertion } from './create.js';
|
|
16
15
|
import type { AsyncAssertions, SyncAssertions } from './impl/index.js';
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -46,8 +45,8 @@ export type AnyAssertions = NonEmptyTuple<AnyAssertion>;
|
|
|
46
45
|
* @see {@link AssertionSchemaAsync} for schema-based async assertions
|
|
47
46
|
*/
|
|
48
47
|
export type AnyAsyncAssertion =
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
| AssertionFunctionAsync<any, any, any>
|
|
49
|
+
| AssertionSchemaAsync<any, any, any>;
|
|
51
50
|
|
|
52
51
|
/**
|
|
53
52
|
* Non-empty tuple type containing any asynchronous assertions.
|
|
@@ -71,7 +70,6 @@ export type AnyAsyncAssertions = NonEmptyTuple<AnyAsyncAssertion>;
|
|
|
71
70
|
export type AnySyncAssertion =
|
|
72
71
|
| AssertionFunctionSync<any, any, any>
|
|
73
72
|
| AssertionSchemaSync<any, any, any>;
|
|
74
|
-
// | AssertionSync<any, any, any>;
|
|
75
73
|
|
|
76
74
|
/**
|
|
77
75
|
* Non-empty tuple type containing any synchronous assertions.
|
|
@@ -203,7 +201,7 @@ export type AssertionImpl<Parts extends AssertionParts> =
|
|
|
203
201
|
* asynchronous assertions, providing a type-safe way to handle async assertion
|
|
204
202
|
* logic.
|
|
205
203
|
*
|
|
206
|
-
* @
|
|
204
|
+
* @template Parts - The assertion parts defining the structure
|
|
207
205
|
* @see {@link AssertionImplFnAsync} for function-based async implementations
|
|
208
206
|
* @see {@link AssertionImplSchemaAsync} for schema-based async implementations
|
|
209
207
|
*/
|
|
@@ -219,7 +217,7 @@ export type AssertionImplAsync<Parts extends AssertionParts> =
|
|
|
219
217
|
* parsed values from the assertion parts and can return various types
|
|
220
218
|
* indicating validation success or failure.
|
|
221
219
|
*
|
|
222
|
-
* @
|
|
220
|
+
* @template Parts - The assertion parts defining the structure
|
|
223
221
|
* @param values - The parsed values corresponding to assertion parts
|
|
224
222
|
* @returns Promise resolving to boolean indicating pass/fail, void for success,
|
|
225
223
|
* ZodType for dynamic validation, or AssertionFailure object for detailed
|
|
@@ -241,7 +239,7 @@ export type AssertionImplFnAsync<Parts extends AssertionParts> = (
|
|
|
241
239
|
* assertion parts and can return various types indicating validation success or
|
|
242
240
|
* failure.
|
|
243
241
|
*
|
|
244
|
-
* @
|
|
242
|
+
* @template Parts - The assertion parts defining the structure
|
|
245
243
|
* @param values - The parsed values corresponding to assertion parts
|
|
246
244
|
* @returns Boolean indicating pass/fail, void for success, ZodType for dynamic
|
|
247
245
|
* validation, or AssertionFailure object for detailed error information
|
|
@@ -256,8 +254,6 @@ export type AssertionImplFnSync<Parts extends AssertionParts> = (
|
|
|
256
254
|
* Maps an {@link AssertionPart} to a parameter to an {@link AssertionImpl}.
|
|
257
255
|
*
|
|
258
256
|
* This omits {@link Phrase} parts, which are not received by the implementation.
|
|
259
|
-
*
|
|
260
|
-
* @knipignore
|
|
261
257
|
*/
|
|
262
258
|
export type AssertionImplPart<Part extends AssertionPart> = Part extends
|
|
263
259
|
| PhraseLiteral
|
|
@@ -269,8 +265,6 @@ export type AssertionImplPart<Part extends AssertionPart> = Part extends
|
|
|
269
265
|
|
|
270
266
|
/**
|
|
271
267
|
* Maps {@link AssertionParts} to their corresponding {@link AssertionImplPart}.
|
|
272
|
-
*
|
|
273
|
-
* @knipignore
|
|
274
268
|
*/
|
|
275
269
|
export type AssertionImplParts<Parts extends readonly AssertionPart[]> =
|
|
276
270
|
Parts extends readonly [
|
|
@@ -292,7 +286,7 @@ export type AssertionImplParts<Parts extends readonly AssertionPart[]> =
|
|
|
292
286
|
* the assertion parts and is branded with 'async-schema' for compile-time type
|
|
293
287
|
* safety.
|
|
294
288
|
*
|
|
295
|
-
* @
|
|
289
|
+
* @template Parts - The assertion parts tuple defining the assertion structure
|
|
296
290
|
* @see {@link AssertionImplSchemaSync} for synchronous schema implementations
|
|
297
291
|
* @see {@link AssertionImplFnAsync} for function-based async implementations
|
|
298
292
|
* @see {@link ParsedSubject} for subject type derivation
|
|
@@ -308,7 +302,7 @@ export type AssertionImplSchemaAsync<Parts extends AssertionParts> =
|
|
|
308
302
|
* assertion parts and is branded with 'sync-schema' for compile-time type
|
|
309
303
|
* safety.
|
|
310
304
|
*
|
|
311
|
-
* @
|
|
305
|
+
* @template Parts - The assertion parts tuple defining the assertion structure
|
|
312
306
|
* @see {@link AssertionImplSchemaAsync} for asynchronous schema implementations
|
|
313
307
|
* @see {@link AssertionImplFnSync} for function-based sync implementations
|
|
314
308
|
* @see {@link ParsedSubject} for subject type derivation
|
|
@@ -323,7 +317,7 @@ export type AssertionImplSchemaSync<Parts extends AssertionParts> =
|
|
|
323
317
|
* synchronous assertions. Function implementations provide custom validation
|
|
324
318
|
* logic, while schema implementations use Zod schemas for validation.
|
|
325
319
|
*
|
|
326
|
-
* @
|
|
320
|
+
* @template Parts - The assertion parts tuple defining the assertion structure
|
|
327
321
|
* @see {@link AssertionImplFnSync} for function-based implementations
|
|
328
322
|
* @see {@link AssertionImplSchemaSync} for schema-based implementations
|
|
329
323
|
* @see {@link AssertionImplAsync} for async implementation unions
|
|
@@ -335,7 +329,7 @@ export type AssertionImplSchemaSync<Parts extends AssertionParts> =
|
|
|
335
329
|
* synchronous assertions. Function implementations provide custom validation
|
|
336
330
|
* logic, while schema implementations use Zod schemas for validation.
|
|
337
331
|
*
|
|
338
|
-
* @
|
|
332
|
+
* @template Parts - The assertion parts tuple defining the assertion structure
|
|
339
333
|
* @see {@link AssertionImplFnSync} for function-based implementations
|
|
340
334
|
* @see {@link AssertionImplSchemaSync} for schema-based implementations
|
|
341
335
|
* @see {@link AssertionImplAsync} for async implementation unions
|
|
@@ -391,11 +385,10 @@ export type AssertionPart = Phrase | z.ZodType;
|
|
|
391
385
|
* type ChoiceAssertion = [z.any(), ['to be', 'to equal'], z.any()];
|
|
392
386
|
* ```
|
|
393
387
|
*
|
|
394
|
-
* @
|
|
395
|
-
* constraints
|
|
388
|
+
* @template Parts - Extends the base AssertionPart array with tuple constraints
|
|
396
389
|
* @see {@link AssertionPart} for individual part types
|
|
397
390
|
* @see {@link AssertionSlots} for compiled slot representation
|
|
398
|
-
* @see {@link
|
|
391
|
+
* @see {@link createAssertion} for assertion creation from parts
|
|
399
392
|
*/
|
|
400
393
|
export type AssertionParts = NonEmptyTuple<AssertionPart>;
|
|
401
394
|
|
|
@@ -418,7 +411,7 @@ export type AssertionParts = NonEmptyTuple<AssertionPart>;
|
|
|
418
411
|
* type Slots = [PhraseLiteralSlot<'to be a string'>, z.ZodNumber];
|
|
419
412
|
* ```
|
|
420
413
|
*
|
|
421
|
-
* @
|
|
414
|
+
* @template Parts - The readonly array of assertion parts to process
|
|
422
415
|
* @see {@link AssertionSlot} for individual slot type mapping
|
|
423
416
|
* @see {@link AssertionSlots} for filtered and properly typed slot tuples
|
|
424
417
|
* @see {@link NoNeverTuple} for filtering never entries
|
|
@@ -472,7 +465,7 @@ export interface AssertionSchemaSync<
|
|
|
472
465
|
* type Slot3 = AssertionSlot<z.ZodString>; // z.ZodString
|
|
473
466
|
* ```
|
|
474
467
|
*
|
|
475
|
-
* @
|
|
468
|
+
* @template Part - The assertion part to convert to a slot
|
|
476
469
|
* @see {@link PhraseLiteralSlot} for string literal slots
|
|
477
470
|
* @see {@link PhraseLiteralChoiceSlot} for choice-based slots
|
|
478
471
|
* @see {@link AssertionSlots} for complete slot tuples
|
|
@@ -496,8 +489,12 @@ export type AssertionSlot<Part extends AssertionPart> = Part extends string
|
|
|
496
489
|
* The resulting tuple:
|
|
497
490
|
*
|
|
498
491
|
* 1. Has `never` entries filtered out to maintain proper tuple structure
|
|
499
|
-
* 2.
|
|
500
|
-
*
|
|
492
|
+
* 2. Will include an implicit subject slot {@link AssertionParts} with a
|
|
493
|
+
* {@link PhraseLiteral}/{@link PhraseLiteralChoice} in the first position.
|
|
494
|
+
* 3. Contains branded slots for
|
|
495
|
+
* {@link PhraseLiteral PhraseLiterals}/{@link PhraseLiteralChoice PhraseLiteralChoices}
|
|
496
|
+
* to enable phrase matching; differentiates from a user-created
|
|
497
|
+
* {@link z.ZodLiteral ZodLiteral}.
|
|
501
498
|
*
|
|
502
499
|
* @example
|
|
503
500
|
*
|
|
@@ -511,7 +508,7 @@ export type AssertionSlot<Part extends AssertionPart> = Part extends string
|
|
|
511
508
|
* // Result: [z.ZodString, PhraseLiteralSlot<'to match'>, z.ZodRegExp]
|
|
512
509
|
* ```
|
|
513
510
|
*
|
|
514
|
-
* @
|
|
511
|
+
* @template Parts - The assertion parts to convert to slots
|
|
515
512
|
* @see {@link AssertionSlot} for individual slot mapping
|
|
516
513
|
* @see {@link AssertionPartsToSlots} for the underlying mapping logic
|
|
517
514
|
* @see {@link NoNeverTuple} for never filtering
|
|
@@ -558,8 +555,6 @@ export interface AssertionSync<
|
|
|
558
555
|
|
|
559
556
|
/**
|
|
560
557
|
* The base structure for parsed assertion results.
|
|
561
|
-
*
|
|
562
|
-
* @knipignore
|
|
563
558
|
*/
|
|
564
559
|
export interface BaseParsedResult<Parts extends AssertionParts> {
|
|
565
560
|
/**
|
|
@@ -570,13 +565,13 @@ export interface BaseParsedResult<Parts extends AssertionParts> {
|
|
|
570
565
|
|
|
571
566
|
/**
|
|
572
567
|
* Present only if `success` is `true`. The parsed values mapped to the slots
|
|
573
|
-
* of {@link
|
|
568
|
+
* of an {@link Assertion}.
|
|
574
569
|
*/
|
|
575
570
|
parsedValues?: ParsedValues<Parts>;
|
|
576
571
|
|
|
577
572
|
/**
|
|
578
|
-
* Whether the args were successfully parsed against the slots of
|
|
579
|
-
* {@link
|
|
573
|
+
* Whether the args were successfully parsed against the slots of an
|
|
574
|
+
* {@link Assertion}.
|
|
580
575
|
*/
|
|
581
576
|
success: boolean;
|
|
582
577
|
}
|
|
@@ -587,6 +582,7 @@ export interface BaseParsedResult<Parts extends AssertionParts> {
|
|
|
587
582
|
* This type extracts the element types from the builtin async assertions array,
|
|
588
583
|
* providing a union of all available async assertion types in the framework.
|
|
589
584
|
*
|
|
585
|
+
* @internal
|
|
590
586
|
* @see {@link BuiltinAsyncAssertions} for the full array type
|
|
591
587
|
* @see {@link AsyncAssertions} for the actual assertion implementations
|
|
592
588
|
*/
|
|
@@ -599,6 +595,7 @@ export type BuiltinAsyncAssertion = ArrayValues<BuiltinAsyncAssertions>;
|
|
|
599
595
|
* providing type information for all async assertion implementations included
|
|
600
596
|
* in the framework by default.
|
|
601
597
|
*
|
|
598
|
+
* @internal
|
|
602
599
|
* @see {@link AsyncAssertions} for the actual assertion implementations
|
|
603
600
|
* @see {@link BuiltinAsyncAssertion} for individual assertion types
|
|
604
601
|
*/
|
|
@@ -611,6 +608,7 @@ export type BuiltinAsyncAssertions = typeof AsyncAssertions;
|
|
|
611
608
|
* providing a union of all available synchronous assertion types in the
|
|
612
609
|
* framework.
|
|
613
610
|
*
|
|
611
|
+
* @internal
|
|
614
612
|
* @see {@link BuiltinSyncAssertions} for the full array type
|
|
615
613
|
* @see {@link SyncAssertions} for the actual assertion implementations
|
|
616
614
|
*/
|
|
@@ -623,6 +621,7 @@ export type BuiltinSyncAssertion = ArrayValues<BuiltinSyncAssertions>;
|
|
|
623
621
|
* providing type information for all synchronous assertion implementations
|
|
624
622
|
* included in the framework by default.
|
|
625
623
|
*
|
|
624
|
+
* @internal
|
|
626
625
|
* @see {@link SyncAssertions} for the actual assertion implementations
|
|
627
626
|
* @see {@link BuiltinSyncAssertion} for individual assertion types
|
|
628
627
|
*/
|
|
@@ -636,7 +635,7 @@ export type BuiltinSyncAssertions = typeof SyncAssertions;
|
|
|
636
635
|
* tuple). It uses `NoNeverTuple` to filter out `never` types that may arise
|
|
637
636
|
* during the recursive processing.
|
|
638
637
|
*
|
|
639
|
-
* @
|
|
638
|
+
* @template Parts - The assertion parts to process
|
|
640
639
|
* @see {@link ParsedValues} for the standard parsed values type
|
|
641
640
|
* @see {@link NoNeverTuple} for never-type filtering
|
|
642
641
|
*/
|
|
@@ -674,7 +673,7 @@ export type MaybeEmptyParsedValues<Parts extends readonly AssertionPart[]> =
|
|
|
674
673
|
* type Mixed = NoNeverTuple<readonly [boolean, never, string]>; // readonly [boolean, string]
|
|
675
674
|
* ```
|
|
676
675
|
*
|
|
677
|
-
* @
|
|
676
|
+
* @template T - The readonly tuple type to filter
|
|
678
677
|
* @see {@link AssertionPartsToSlots} for usage in slot processing
|
|
679
678
|
* @see {@link AssertionSlots} for filtered slot tuples
|
|
680
679
|
*/
|
|
@@ -710,7 +709,7 @@ export type NoNeverTuple<T extends readonly unknown[]> = T extends readonly [
|
|
|
710
709
|
* };
|
|
711
710
|
* ```
|
|
712
711
|
*
|
|
713
|
-
* @
|
|
712
|
+
* @template Parts - The assertion parts tuple defining expected structure
|
|
714
713
|
* @see {@link ParsedResultSuccess} for successful parse results
|
|
715
714
|
* @see {@link ParsedResultFailure} for failed parse results
|
|
716
715
|
* @see {@link AssertionSync.parseValues} and {@link AssertionAsync.parseValuesAsync} for usage context
|
|
@@ -743,7 +742,7 @@ export interface ParsedResultFailure extends BaseParsedResult<never> {
|
|
|
743
742
|
* interface contains the validated arguments and metadata about the match
|
|
744
743
|
* quality. The assertion can be executed using the `parsedValues`.
|
|
745
744
|
*
|
|
746
|
-
* @
|
|
745
|
+
* @template Parts - The assertion parts tuple defining the expected structure
|
|
747
746
|
* @see {@link ParsedResultFailure} for failed parsing results
|
|
748
747
|
* @see {@link BaseParsedResult} for shared result properties
|
|
749
748
|
*/
|
|
@@ -785,7 +784,7 @@ export interface ParsedResultSuccess<Parts extends AssertionParts>
|
|
|
785
784
|
* type NumericSubject = ParsedSubject<NumericParts>; // number
|
|
786
785
|
* ```
|
|
787
786
|
*
|
|
788
|
-
* @
|
|
787
|
+
* @template Parts - The assertion parts tuple defining the assertion structure
|
|
789
788
|
* @see {@link ParsedValues} for the complete parsed values tuple
|
|
790
789
|
* @see {@link AssertionImpl} for how subjects are used in implementations
|
|
791
790
|
*/
|
|
@@ -812,7 +811,7 @@ export type ParsedSubject<Parts extends AssertionParts> =
|
|
|
812
811
|
* // ParsedValues = [typeof obj, typeof shape]
|
|
813
812
|
* ```
|
|
814
813
|
*
|
|
815
|
-
* @
|
|
814
|
+
* @template Parts - The assertion parts tuple defining the expected structure
|
|
816
815
|
* @see {@link ParsedSubject} for extracting just the subject
|
|
817
816
|
* @see {@link MaybeEmptyParsedValues} for the underlying value processing
|
|
818
817
|
* @see {@link AssertionImpl} for how these values are consumed
|
|
@@ -915,7 +914,7 @@ export type PhraseLiteralChoice = NonEmptyTuple<string>;
|
|
|
915
914
|
* The `__values` property might be redundant since values should be derivable
|
|
916
915
|
* from the ZodLiteral metadata, but it provides type-level access to the
|
|
917
916
|
* choices.
|
|
918
|
-
* @
|
|
917
|
+
* @template H - The readonly tuple of string choices
|
|
919
918
|
* @see {@link PhraseLiteralChoice} for the source type
|
|
920
919
|
* @see {@link PhraseLiteralSlot} for single phrase slots
|
|
921
920
|
* @see {@link AssertionSlot} for slot type mapping
|
|
@@ -935,7 +934,7 @@ export type PhraseLiteralChoiceSlot<H extends readonly [string, ...string[]]> =
|
|
|
935
934
|
* This type might be redundant since the value should be derivable from the
|
|
936
935
|
* ZodLiteral's value property, but it provides type-level access to the
|
|
937
936
|
* literal.
|
|
938
|
-
* @
|
|
937
|
+
* @template T - The string literal type
|
|
939
938
|
* @see {@link PhraseLiteral} for the source type
|
|
940
939
|
* @see {@link PhraseLiteralChoiceSlot} for choice phrase slots
|
|
941
940
|
* @see {@link AssertionSlot} for slot type mapping
|
|
@@ -943,10 +942,7 @@ export type PhraseLiteralChoiceSlot<H extends readonly [string, ...string[]]> =
|
|
|
943
942
|
export type PhraseLiteralSlot<T extends string> = z.core.$ZodBranded<
|
|
944
943
|
z.ZodLiteral<T>,
|
|
945
944
|
'string-literal'
|
|
946
|
-
>;
|
|
947
|
-
* Object which can returned by assertion implementation functions to provide
|
|
948
|
-
* contextual information to an `AssertionError`
|
|
949
|
-
*/
|
|
945
|
+
>;
|
|
950
946
|
|
|
951
947
|
/**
|
|
952
948
|
* Type for a raw (unbranded) synchronous schema assertion implementation.
|
|
@@ -956,7 +952,8 @@ export type PhraseLiteralSlot<T extends string> = z.core.$ZodBranded<
|
|
|
956
952
|
* type is not branded and represents the underlying schema before it is
|
|
957
953
|
* processed by the assertion creation system.
|
|
958
954
|
*
|
|
959
|
-
* @
|
|
955
|
+
* @template Parts The tuple defining the assertion structure
|
|
956
|
+
* @useDeclaredType
|
|
960
957
|
* @see {@link AssertionImplSchemaSync} for the branded version
|
|
961
958
|
* @see {@link ParsedSubject} for subject type derivation
|
|
962
959
|
*/
|
package/src/assertion/create.ts
CHANGED
|
@@ -69,22 +69,16 @@
|
|
|
69
69
|
import { z } from 'zod/v4';
|
|
70
70
|
|
|
71
71
|
import type {
|
|
72
|
-
AssertionFunctionAsync,
|
|
73
|
-
AssertionFunctionSync,
|
|
74
72
|
AssertionImplAsync,
|
|
75
|
-
AssertionImplFnAsync,
|
|
76
|
-
AssertionImplFnSync,
|
|
77
|
-
AssertionImplSchemaAsync,
|
|
78
|
-
AssertionImplSchemaSync,
|
|
79
73
|
AssertionImplSync,
|
|
80
74
|
AssertionParts,
|
|
81
|
-
AssertionSchemaAsync,
|
|
82
|
-
AssertionSchemaSync,
|
|
83
|
-
AssertionSlots,
|
|
84
|
-
RawAssertionImplSchemaSync,
|
|
85
75
|
} from './assertion-types.js';
|
|
86
76
|
|
|
87
77
|
import { isFunction, isString, isZodType } from '../guards.js';
|
|
78
|
+
import {
|
|
79
|
+
type CreateAssertionFn,
|
|
80
|
+
type CreateAsyncAssertionFn,
|
|
81
|
+
} from '../types.js';
|
|
88
82
|
import {
|
|
89
83
|
BupkisAssertionFunctionAsync,
|
|
90
84
|
BupkisAssertionSchemaAsync,
|
|
@@ -96,40 +90,17 @@ import {
|
|
|
96
90
|
import { slotify } from './slotify.js';
|
|
97
91
|
|
|
98
92
|
/**
|
|
99
|
-
*
|
|
100
|
-
* {@link z.ZodType Zod schema}.
|
|
93
|
+
* {@inheritDoc CreateAssertionFn}
|
|
101
94
|
*
|
|
102
|
-
* @param parts Assertion parts defining the shape of the assertion
|
|
103
|
-
* @param impl Implementation as a Zod schema
|
|
104
|
-
* @returns New `SchemaAssertion` instance
|
|
105
95
|
* @throws {TypeError} Invalid assertion implementation type
|
|
106
96
|
*/
|
|
107
|
-
export
|
|
97
|
+
export const createAssertion: CreateAssertionFn = <
|
|
98
|
+
Impl extends AssertionImplSync<Parts>,
|
|
108
99
|
const Parts extends AssertionParts,
|
|
109
|
-
Impl extends RawAssertionImplSchemaSync<Parts>,
|
|
110
|
-
Slots extends AssertionSlots<Parts>,
|
|
111
100
|
>(
|
|
112
101
|
parts: Parts,
|
|
113
102
|
impl: Impl,
|
|
114
|
-
)
|
|
115
|
-
/**
|
|
116
|
-
* Create a synchronous `Assertion` from {@link AssertionParts parts} and an
|
|
117
|
-
* implementation function.
|
|
118
|
-
*
|
|
119
|
-
* @param parts Assertion parts defining the shape of the assertion
|
|
120
|
-
* @param impl Implementation as a function
|
|
121
|
-
* @returns New `FunctionAssertion` instance
|
|
122
|
-
* @throws {TypeError} Invalid assertion implementation type
|
|
123
|
-
*/
|
|
124
|
-
export function createAssertion<
|
|
125
|
-
const Parts extends AssertionParts,
|
|
126
|
-
Impl extends AssertionImplFnSync<Parts>,
|
|
127
|
-
Slots extends AssertionSlots<Parts>,
|
|
128
|
-
>(parts: Parts, impl: Impl): AssertionFunctionSync<Parts, Impl, Slots>;
|
|
129
|
-
export function createAssertion<
|
|
130
|
-
Impl extends AssertionImplSync<Parts>,
|
|
131
|
-
const Parts extends AssertionParts,
|
|
132
|
-
>(parts: Parts, impl: Impl) {
|
|
103
|
+
) => {
|
|
133
104
|
if (!Array.isArray(parts)) {
|
|
134
105
|
throw new TypeError('First parameter must be an array');
|
|
135
106
|
}
|
|
@@ -163,40 +134,20 @@ export function createAssertion<
|
|
|
163
134
|
throw new TypeError(
|
|
164
135
|
'Assertion implementation must be a function, Zod schema or Zod schema factory',
|
|
165
136
|
);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Create an async `Assertion` from {@link AssertionParts parts} and an async
|
|
169
|
-
* {@link z.ZodType Zod schema}.
|
|
170
|
-
*
|
|
171
|
-
* @param parts Assertion parts defining the shape of the assertion
|
|
172
|
-
* @param impl Implementation as a Zod schema (potentially async)
|
|
173
|
-
* @returns New `BupkisAssertionSchemaAsync` instance
|
|
174
|
-
* @throws {TypeError} Invalid assertion implementation type
|
|
175
|
-
*/
|
|
176
|
-
export function createAsyncAssertion<
|
|
177
|
-
const Parts extends AssertionParts,
|
|
178
|
-
Impl extends AssertionImplSchemaAsync<Parts>,
|
|
179
|
-
Slots extends AssertionSlots<Parts>,
|
|
180
|
-
>(parts: Parts, impl: Impl): AssertionSchemaAsync<Parts, Impl, Slots>;
|
|
137
|
+
};
|
|
181
138
|
|
|
182
139
|
/**
|
|
183
|
-
*
|
|
184
|
-
* implementation function.
|
|
140
|
+
* {@inheritDoc CreateAsyncAssertionFn}
|
|
185
141
|
*
|
|
186
|
-
* @param parts Assertion parts defining the shape of the assertion
|
|
187
|
-
* @param impl Implementation as a function (potentially async)
|
|
188
|
-
* @returns New `FunctionAssertion` instance
|
|
189
142
|
* @throws {TypeError} Invalid assertion implementation type
|
|
190
143
|
*/
|
|
191
|
-
export
|
|
192
|
-
const Parts extends AssertionParts,
|
|
193
|
-
Impl extends AssertionImplFnAsync<Parts>,
|
|
194
|
-
Slots extends AssertionSlots<Parts>,
|
|
195
|
-
>(parts: Parts, impl: Impl): AssertionFunctionAsync<Parts, Impl, Slots>;
|
|
196
|
-
export function createAsyncAssertion<
|
|
144
|
+
export const createAsyncAssertion: CreateAsyncAssertionFn = <
|
|
197
145
|
const Parts extends AssertionParts,
|
|
198
146
|
Impl extends AssertionImplAsync<Parts>,
|
|
199
|
-
>(
|
|
147
|
+
>(
|
|
148
|
+
parts: Parts,
|
|
149
|
+
impl: Impl,
|
|
150
|
+
) => {
|
|
200
151
|
if (!Array.isArray(parts)) {
|
|
201
152
|
throw new TypeError('First parameter must be an array');
|
|
202
153
|
}
|
|
@@ -223,4 +174,4 @@ export function createAsyncAssertion<
|
|
|
223
174
|
throw new TypeError(
|
|
224
175
|
'Assertion implementation must be a function, Zod schema or Zod schema factory',
|
|
225
176
|
);
|
|
226
|
-
}
|
|
177
|
+
};
|
|
@@ -180,7 +180,7 @@ export const AsyncAssertions = [
|
|
|
180
180
|
createAsyncAssertion(
|
|
181
181
|
[
|
|
182
182
|
WrappedPromiseLikeSchema,
|
|
183
|
-
['to fulfill with value satisfying', 'to resolve
|
|
183
|
+
['to fulfill with value satisfying', 'to resolve with value satisfying'],
|
|
184
184
|
z.union([z.string(), z.instanceof(RegExp), z.looseObject({})]),
|
|
185
185
|
],
|
|
186
186
|
async (promise, param) => {
|
|
@@ -232,7 +232,7 @@ export const AsyncAssertions = [
|
|
|
232
232
|
createAsyncAssertion(
|
|
233
233
|
[
|
|
234
234
|
FunctionSchema,
|
|
235
|
-
['to fulfill with value satisfying', 'to resolve
|
|
235
|
+
['to fulfill with value satisfying', 'to resolve with value satisfying'],
|
|
236
236
|
z.union([z.string(), z.instanceof(RegExp), z.looseObject({})]),
|
|
237
237
|
],
|
|
238
238
|
async (subject, param) => {
|
|
@@ -135,7 +135,7 @@ export const ParametricAssertions = [
|
|
|
135
135
|
|
|
136
136
|
// Number range and approximation assertions
|
|
137
137
|
createAssertion(
|
|
138
|
-
[z.number(), 'to be within', z.number(), z.number()],
|
|
138
|
+
[z.number(), ['to be within', 'to be between'], z.number(), z.number()],
|
|
139
139
|
(subject, min, max) => {
|
|
140
140
|
if (subject < min || subject > max) {
|
|
141
141
|
return {
|
|
@@ -467,13 +467,13 @@ export const ParametricAssertions = [
|
|
|
467
467
|
['to satisfy', 'to be like'],
|
|
468
468
|
z.looseObject({}),
|
|
469
469
|
],
|
|
470
|
-
(
|
|
470
|
+
(subject, shape) =>
|
|
471
471
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
472
472
|
valueToSchema(shape) as unknown as z.ZodType<{}, z.core.$loose>,
|
|
473
473
|
),
|
|
474
474
|
createAssertion(
|
|
475
475
|
[ArrayLikeSchema, ['to satisfy', 'to be like'], ArrayLikeSchema],
|
|
476
|
-
(
|
|
476
|
+
(subject, shape) =>
|
|
477
477
|
valueToSchema(shape) as unknown as typeof ArrayLikeSchema,
|
|
478
478
|
),
|
|
479
479
|
createAssertion(
|