@frankmeza/affirm 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +33 -9
- package/README.md +62 -26
- package/dist/affirm.d.ts +4 -4
- package/dist/checks/arrays.d.ts +6 -6
- package/dist/checks/composition.d.ts +4 -4
- package/dist/checks/equality.d.ts +5 -5
- package/dist/checks/nullish.d.ts +7 -7
- package/dist/checks/numbers.d.ts +1 -1
- package/dist/checks/objects.d.ts +7 -7
- package/dist/checks/runtime-type.d.ts +3 -3
- package/dist/checks/size.d.ts +6 -6
- package/dist/checks/strings.d.ts +4 -4
- package/dist/core/check-def.d.ts +2 -2
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/evaluate.d.ts +3 -3
- package/dist/core/registry.d.ts +2 -2
- package/dist/core/validate-params.d.ts +1 -1
- package/dist/eslint.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/affirmed.d.ts +11 -11
- package/dist/types/arrays.d.ts +3 -3
- package/dist/types/composition.d.ts +4 -4
- package/dist/types/contradictions.d.ts +1 -1
- package/dist/types/equality.d.ts +1 -1
- package/dist/types/nullish.d.ts +1 -1
- package/dist/types/numbers.d.ts +1 -1
- package/dist/types/objects.d.ts +3 -3
- package/dist/types/params.d.ts +9 -9
- package/dist/types/runtime-type.d.ts +2 -2
- package/dist/types/size.d.ts +2 -2
- package/dist/types/strings.d.ts +1 -1
- package/docs/client-usage.md +3 -11
- package/package.json +22 -5
package/AGENTS.md
CHANGED
|
@@ -2,13 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
`affirm(value, params)` replaces compound data checks with one object of named checks. It returns a boolean and narrows `value`'s type.
|
|
4
4
|
|
|
5
|
+
Instead of:
|
|
6
|
+
|
|
5
7
|
```ts
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
+
function getTotal(order: unknown): number | undefined {
|
|
9
|
+
if (
|
|
10
|
+
typeof order === 'object' &&
|
|
11
|
+
order !== null &&
|
|
12
|
+
Object.hasOwn(order, 'total') && // own key only: ignores inherited properties
|
|
13
|
+
'total' in order && // repeated so TypeScript narrows `order.total`
|
|
14
|
+
typeof order.total === 'number' &&
|
|
15
|
+
order.total > 0
|
|
16
|
+
) {
|
|
17
|
+
return order.total // number
|
|
18
|
+
}
|
|
19
|
+
return undefined
|
|
20
|
+
}
|
|
21
|
+
```
|
|
8
22
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
Write:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { affirm } from '@frankmeza/affirm'
|
|
27
|
+
|
|
28
|
+
function getTotal(order: unknown): number | undefined {
|
|
29
|
+
// `order` is a non-null object with an own key `total`,
|
|
30
|
+
// and `total` is a number greater than 0.
|
|
31
|
+
if (affirm(order, { shape: { total: { isType: 'number', isPositive: true } } })) {
|
|
32
|
+
return order.total // number
|
|
33
|
+
}
|
|
34
|
+
return undefined
|
|
12
35
|
}
|
|
13
36
|
```
|
|
14
37
|
|
|
@@ -58,7 +81,7 @@ export default [affirm.configs.recommended, { settings: { affirm: { guards: '^is
|
|
|
58
81
|
| Equality | `is`, `isNot`, `isOneOf`, `isNotOneOf`, `isDeepEqual` |
|
|
59
82
|
| Nullish | `isNull`, `isUndefined`, `isNullish`, `isDefined` (≠ undefined), `isPresent` (≠ null and ≠ undefined), `isTruthy`, `isFalsy` |
|
|
60
83
|
| Runtime type | `isType` (`'string'`, `'number'`, `'boolean'`, `'bigint'`, `'symbol'`, `'function'`, `'object'`, a type guard, or a sync Standard Schema), `isArray`, `isPlainObject`, `isFunction`, `isInstanceOf`, `isValidDate`, `isInteger`, `isFiniteNumber`, `isNaN` |
|
|
61
|
-
| Size (strings, arrays, Maps, Sets) | `isEmpty`, `isNotEmpty` (also plain objects), `isBlank`, `hasLength`, `hasMinLength`, `hasMaxLength` |
|
|
84
|
+
| Size (strings, arrays, Maps, Sets) | `isEmpty`, `isNotEmpty` (both also plain objects), `isBlank`, `hasLength`, `hasMinLength`, `hasMaxLength` |
|
|
62
85
|
| Numbers | `isGreaterThan`, `isAtLeast` (≥), `isLessThan`, `isAtMost` (≤), `isBetween: [min, max]` (**inclusive**), `isPositive`, `isNegative`, `isMultipleOf` |
|
|
63
86
|
| Strings | `startsWith`, `endsWith`, `includes` (strings only), `matches: RegExp` |
|
|
64
87
|
| Objects | `shape: { field: params }`, `hasKey`, `hasKeys`, `hasAnyKey`, `hasOnlyKeys`, `hasPath: 'a.b.0.c'` |
|
|
@@ -94,8 +117,9 @@ affirm(order.items, {
|
|
|
94
117
|
// Exact keys only
|
|
95
118
|
affirm(query, { isPlainObject: true, hasOnlyKeys: ['page', 'limit'] })
|
|
96
119
|
|
|
97
|
-
// Cross-field rule: `satisfies` receives `unknown`, so guard first
|
|
98
|
-
|
|
120
|
+
// Cross-field rule: `satisfies` receives `unknown`, so guard first.
|
|
121
|
+
// Annotate `(r: unknown)`: an unannotated inline function turns off narrowing for the whole call.
|
|
122
|
+
affirm(range, { satisfies: (r: unknown) => isRange(r) && r.min <= r.max })
|
|
99
123
|
|
|
100
124
|
// An existing Zod / Valibot / ArkType schema (sync only; validates, never transforms)
|
|
101
125
|
affirm(body, { isType: OrderSchema })
|
|
@@ -111,7 +135,7 @@ if (!report.ok) return badRequest(report.failures.map((f) => f.reason))
|
|
|
111
135
|
|
|
112
136
|
## Type narrowing
|
|
113
137
|
|
|
114
|
-
- **Exact checks** narrow both branches. These are `isNull`, `isUndefined`, `isNullish`, `isDefined`, `isPresent`, `isType` with a
|
|
138
|
+
- **Exact checks** narrow both branches. These are `isNull`, `isUndefined`, `isNullish`, `isDefined`, `isPresent`, `isType` with a type guard or any tag except `'object'`, `isArray: true`, `isFunction: true`, `is`/`isOneOf` with literals, and `anyOf` of exact branches. Example: with `x: string | null`, after `if (affirm(x, { isNull: true })) return`, `x` is `string`.
|
|
115
139
|
- **Refined checks** (all others) narrow only the `if` branch. The type gets a phantom `& Refined` marker, which you can ignore: a `string & Refined` works anywhere a `string` does. The `else` branch keeps the full type, because a value can fail for other reasons.
|
|
116
140
|
- **No narrowing at all** happens for refined checks whose result could be `null` or `undefined` (e.g. `isFalsy` on `string | null`). TypeScript can't express that soundly, so `affirm` returns a plain boolean. If you need narrowing, split the check: `affirm(x, { isPresent: true }) && affirm(x, { … })`.
|
|
117
141
|
- **Contradictions are compile errors**, e.g. "`isNull: true` contradicts `isPresent: true`" or "`hasMinLength: 10` is greater than `hasMaxLength: 9`". So are unknown keys at any depth.
|
package/README.md
CHANGED
|
@@ -2,13 +2,43 @@
|
|
|
2
2
|
|
|
3
3
|
Runtime checks that read like a spec. `affirm(value, params)` replaces a compound `if` with one object of named checks. It returns a boolean and narrows `value`'s type.
|
|
4
4
|
|
|
5
|
+
Before: what is this actually checking?
|
|
6
|
+
|
|
5
7
|
```ts
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
+
function getTotal(order: unknown): number | undefined {
|
|
9
|
+
if (
|
|
10
|
+
typeof order === "object" &&
|
|
11
|
+
order !== null &&
|
|
12
|
+
Object.hasOwn(order, "total") && // own key only: ignores inherited properties
|
|
13
|
+
"total" in order && // repeated so TypeScript narrows `order.total`
|
|
14
|
+
typeof order.total === "number" &&
|
|
15
|
+
order.total > 0
|
|
16
|
+
) {
|
|
17
|
+
return order.total // number
|
|
18
|
+
}
|
|
19
|
+
return undefined
|
|
20
|
+
}
|
|
21
|
+
```
|
|
8
22
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
After:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { affirm } from "@frankmeza/affirm"
|
|
27
|
+
|
|
28
|
+
// a non-null object with an own key `total`,
|
|
29
|
+
// and `total` is a number greater than 0.
|
|
30
|
+
const affirmIsNonZeroPositiveNumber = {
|
|
31
|
+
shape: {
|
|
32
|
+
total: { isType: "number", isPositive: true },
|
|
33
|
+
},
|
|
34
|
+
} as const
|
|
35
|
+
|
|
36
|
+
function getTotal(order: unknown): number | undefined {
|
|
37
|
+
if (affirm(order, affirmIsNonZeroPositiveNumber)) {
|
|
38
|
+
return order.total // number
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return undefined
|
|
12
42
|
}
|
|
13
43
|
```
|
|
14
44
|
|
|
@@ -46,15 +76,17 @@ affirm.assert(value, params, message?) // throws AffirmError on failure; narrow
|
|
|
46
76
|
|
|
47
77
|
```ts
|
|
48
78
|
// Present, non-empty string
|
|
49
|
-
affirm(name, { isType:
|
|
79
|
+
affirm(name, { isType: "string", isBlank: false })
|
|
50
80
|
|
|
51
81
|
// Enum
|
|
52
|
-
affirm(status, { isOneOf: [
|
|
82
|
+
affirm(status, { isOneOf: ["draft", "published", "archived"] })
|
|
53
83
|
|
|
54
84
|
// Array of objects
|
|
55
85
|
affirm(order.items, {
|
|
56
86
|
isNotEmpty: true,
|
|
57
|
-
everyItem: {
|
|
87
|
+
everyItem: {
|
|
88
|
+
shape: { sku: { isBlank: false }, qty: { isInteger: true, isAtLeast: 1 } },
|
|
89
|
+
},
|
|
58
90
|
})
|
|
59
91
|
|
|
60
92
|
// OR
|
|
@@ -64,44 +96,48 @@ affirm(input, { anyOf: [{ isNullish: true }, { isEmpty: true }] })
|
|
|
64
96
|
affirm(body, { isType: OrderSchema })
|
|
65
97
|
|
|
66
98
|
// Config at startup: throw with a clear message
|
|
67
|
-
affirm.assert(
|
|
99
|
+
affirm.assert(
|
|
100
|
+
env.PORT,
|
|
101
|
+
{ isType: "string", matches: /^\d+$/ },
|
|
102
|
+
"PORT must be numeric",
|
|
103
|
+
)
|
|
68
104
|
|
|
69
105
|
// Explain why a request body failed
|
|
70
106
|
const report = affirm.explain(body, { shape: { email: { matches: /@/ } } })
|
|
71
107
|
if (!report.ok) return badRequest(report.failures.map((f) => f.reason))
|
|
72
108
|
```
|
|
73
109
|
|
|
74
|
-
Keys combine with AND, an omitted or `undefined` key is skipped, and there's no coercion: `isGreaterThan: 5` fails on `'10'`. Mistakes in the params themselves, such as an unknown key or an empty `{}`, throw a `TypeError`
|
|
110
|
+
Keys combine with AND, an omitted or `undefined` key is skipped, and there's no coercion: `isGreaterThan: 5` fails on `'10'`. Mistakes in the params themselves, such as an unknown key or an empty `{}`, throw a `TypeError` that says how to fix them (an unknown key gets a "did you mean" hint), so they can't pass silently.
|
|
75
111
|
|
|
76
|
-
| Group
|
|
77
|
-
|
|
|
78
|
-
| Equality
|
|
79
|
-
| Nullish
|
|
112
|
+
| Group | Keys |
|
|
113
|
+
| ------------ | ------------------------------------------------------------------------------------------------------------------------- |
|
|
114
|
+
| Equality | `is`, `isNot`, `isOneOf`, `isNotOneOf`, `isDeepEqual` |
|
|
115
|
+
| Nullish | `isNull`, `isUndefined`, `isNullish`, `isDefined`, `isPresent`, `isTruthy`, `isFalsy` |
|
|
80
116
|
| Runtime type | `isType`, `isArray`, `isPlainObject`, `isFunction`, `isInstanceOf`, `isValidDate`, `isInteger`, `isFiniteNumber`, `isNaN` |
|
|
81
|
-
| Size
|
|
82
|
-
| Numbers
|
|
83
|
-
| Strings
|
|
84
|
-
| Objects
|
|
85
|
-
| Arrays
|
|
86
|
-
| Composition
|
|
117
|
+
| Size | `isEmpty`, `isNotEmpty`, `isBlank`, `hasLength`, `hasMinLength`, `hasMaxLength` |
|
|
118
|
+
| Numbers | `isGreaterThan`, `isAtLeast`, `isLessThan`, `isAtMost`, `isBetween`, `isPositive`, `isNegative`, `isMultipleOf` |
|
|
119
|
+
| Strings | `startsWith`, `endsWith`, `includes`, `matches` |
|
|
120
|
+
| Objects | `shape`, `hasKey`, `hasKeys`, `hasAnyKey`, `hasOnlyKeys`, `hasPath` |
|
|
121
|
+
| Arrays | `contains`, `containsAll`, `containsAny`, `everyItem`, `someItem` |
|
|
122
|
+
| Composition | `not`, `anyOf`, `satisfies` |
|
|
87
123
|
|
|
88
124
|
## ESLint plugin
|
|
89
125
|
|
|
90
126
|
```js
|
|
91
127
|
// eslint.config.js
|
|
92
|
-
import affirm from
|
|
128
|
+
import affirm from "@frankmeza/affirm/eslint"
|
|
93
129
|
|
|
94
130
|
export default [
|
|
95
131
|
affirm.configs.recommended,
|
|
96
|
-
{ settings: { affirm: { guards:
|
|
132
|
+
{ settings: { affirm: { guards: "^isValid" } } },
|
|
97
133
|
]
|
|
98
134
|
```
|
|
99
135
|
|
|
100
|
-
| Rule
|
|
101
|
-
|
|
|
136
|
+
| Rule | Catches |
|
|
137
|
+
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
102
138
|
| `affirm/no-negated-affirm` | `!affirm(…)` and negated guards. `affirm` is an AND of narrow checks, so its negation only means "something failed", which is too broad to act on. Use `affirm.assert`, `affirm.explain`, or a positive check instead. |
|
|
103
|
-
| `affirm/guard-naming`
|
|
104
|
-
| `affirm/const-params`
|
|
139
|
+
| `affirm/guard-naming` | Guards built on `affirm` that don't follow the `guards` naming pattern, which is how negated guards are caught across files. |
|
|
140
|
+
| `affirm/const-params` | Params stored in a variable without `as const`, which lose their literal types before `affirm` sees them. Autofixable. |
|
|
105
141
|
|
|
106
142
|
Requires ESLint 9 or 10 with a flat config. `eslint` is an optional peer dependency.
|
|
107
143
|
|
package/dist/affirm.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AffirmReport } from './core/report';
|
|
2
|
-
import type { Affirmed, CanNarrow } from './types/affirmed';
|
|
3
|
-
import type { ParamsCheck } from './types/contradictions';
|
|
4
|
-
import type { AffirmParams } from './types/params';
|
|
1
|
+
import type { AffirmReport } from './core/report.js';
|
|
2
|
+
import type { Affirmed, CanNarrow } from './types/affirmed.js';
|
|
3
|
+
import type { ParamsCheck } from './types/contradictions.js';
|
|
4
|
+
import type { AffirmParams } from './types/params.js';
|
|
5
5
|
/** Makes the narrowing overload inapplicable (so the boolean one is picked) when narrowing is unsound. */
|
|
6
6
|
type IfNarrowable<V, P> = CanNarrow<V, P> extends true ? unknown : never;
|
|
7
7
|
/**
|
package/dist/checks/arrays.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { AffirmParams } from '../types/params';
|
|
1
|
+
import type { AffirmParams } from '../types/params.js';
|
|
2
2
|
export declare const arrayChecks: {
|
|
3
|
-
contains: import("../core/check-def").CheckDef<unknown>;
|
|
4
|
-
containsAll: import("../core/check-def").CheckDef<readonly unknown[]>;
|
|
5
|
-
containsAny: import("../core/check-def").CheckDef<readonly unknown[]>;
|
|
3
|
+
contains: import("../core/check-def.js").CheckDef<unknown>;
|
|
4
|
+
containsAll: import("../core/check-def.js").CheckDef<readonly unknown[]>;
|
|
5
|
+
containsAny: import("../core/check-def.js").CheckDef<readonly unknown[]>;
|
|
6
6
|
/** Failures carry the item path: `items[2].id`. Vacuously true on `[]`. */
|
|
7
|
-
everyItem: import("../core/check-def").CheckDef<AffirmParams>;
|
|
7
|
+
everyItem: import("../core/check-def.js").CheckDef<AffirmParams>;
|
|
8
8
|
/** One failure when no item passes (per-item failures would just be noise). False on `[]`. */
|
|
9
|
-
someItem: import("../core/check-def").CheckDef<AffirmParams>;
|
|
9
|
+
someItem: import("../core/check-def.js").CheckDef<AffirmParams>;
|
|
10
10
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { AffirmParams } from '../types/params';
|
|
1
|
+
import type { AffirmParams } from '../types/params.js';
|
|
2
2
|
export declare const compositionChecks: {
|
|
3
|
-
not: import("../core/check-def").CheckDef<AffirmParams>;
|
|
3
|
+
not: import("../core/check-def.js").CheckDef<AffirmParams>;
|
|
4
4
|
/**
|
|
5
5
|
* Passes when any branch passes. The failure lists every branch's failures in `branches`
|
|
6
6
|
* (all of them under `explain()`, the first per branch under `affirm()`).
|
|
7
7
|
*/
|
|
8
|
-
anyOf: import("../core/check-def").CheckDef<readonly AffirmParams[]>;
|
|
9
|
-
satisfies: import("../core/check-def").CheckDef<(value: unknown) => boolean>;
|
|
8
|
+
anyOf: import("../core/check-def.js").CheckDef<readonly AffirmParams[]>;
|
|
9
|
+
satisfies: import("../core/check-def.js").CheckDef<(value: unknown) => boolean>;
|
|
10
10
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const equalityChecks: {
|
|
2
|
-
is: import("../core/check-def").CheckDef<unknown>;
|
|
3
|
-
isNot: import("../core/check-def").CheckDef<unknown>;
|
|
4
|
-
isOneOf: import("../core/check-def").CheckDef<readonly unknown[]>;
|
|
5
|
-
isNotOneOf: import("../core/check-def").CheckDef<readonly unknown[]>;
|
|
6
|
-
isDeepEqual: import("../core/check-def").CheckDef<unknown>;
|
|
2
|
+
is: import("../core/check-def.js").CheckDef<unknown>;
|
|
3
|
+
isNot: import("../core/check-def.js").CheckDef<unknown>;
|
|
4
|
+
isOneOf: import("../core/check-def.js").CheckDef<readonly unknown[]>;
|
|
5
|
+
isNotOneOf: import("../core/check-def.js").CheckDef<readonly unknown[]>;
|
|
6
|
+
isDeepEqual: import("../core/check-def.js").CheckDef<unknown>;
|
|
7
7
|
};
|
package/dist/checks/nullish.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare const nullishChecks: {
|
|
2
|
-
isNull: import("../core/check-def").CheckDef<boolean>;
|
|
3
|
-
isUndefined: import("../core/check-def").CheckDef<boolean>;
|
|
4
|
-
isNullish: import("../core/check-def").CheckDef<boolean>;
|
|
5
|
-
isDefined: import("../core/check-def").CheckDef<boolean>;
|
|
6
|
-
isPresent: import("../core/check-def").CheckDef<boolean>;
|
|
7
|
-
isTruthy: import("../core/check-def").CheckDef<boolean>;
|
|
8
|
-
isFalsy: import("../core/check-def").CheckDef<boolean>;
|
|
2
|
+
isNull: import("../core/check-def.js").CheckDef<boolean>;
|
|
3
|
+
isUndefined: import("../core/check-def.js").CheckDef<boolean>;
|
|
4
|
+
isNullish: import("../core/check-def.js").CheckDef<boolean>;
|
|
5
|
+
isDefined: import("../core/check-def.js").CheckDef<boolean>;
|
|
6
|
+
isPresent: import("../core/check-def.js").CheckDef<boolean>;
|
|
7
|
+
isTruthy: import("../core/check-def.js").CheckDef<boolean>;
|
|
8
|
+
isFalsy: import("../core/check-def.js").CheckDef<boolean>;
|
|
9
9
|
};
|
package/dist/checks/numbers.d.ts
CHANGED
package/dist/checks/objects.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { AffirmParams } from '../types/params';
|
|
1
|
+
import type { AffirmParams } from '../types/params.js';
|
|
2
2
|
export declare const objectChecks: {
|
|
3
|
-
shape: import("../core/check-def").CheckDef<Readonly<Record<string, AffirmParams>>>;
|
|
4
|
-
hasKey: import("../core/check-def").CheckDef<PropertyKey>;
|
|
5
|
-
hasKeys: import("../core/check-def").CheckDef<readonly PropertyKey[]>;
|
|
6
|
-
hasAnyKey: import("../core/check-def").CheckDef<readonly PropertyKey[]>;
|
|
7
|
-
hasOnlyKeys: import("../core/check-def").CheckDef<readonly PropertyKey[]>;
|
|
8
|
-
hasPath: import("../core/check-def").CheckDef<string>;
|
|
3
|
+
shape: import("../core/check-def.js").CheckDef<Readonly<Record<string, AffirmParams>>>;
|
|
4
|
+
hasKey: import("../core/check-def.js").CheckDef<PropertyKey>;
|
|
5
|
+
hasKeys: import("../core/check-def.js").CheckDef<readonly PropertyKey[]>;
|
|
6
|
+
hasAnyKey: import("../core/check-def.js").CheckDef<readonly PropertyKey[]>;
|
|
7
|
+
hasOnlyKeys: import("../core/check-def.js").CheckDef<readonly PropertyKey[]>;
|
|
8
|
+
hasPath: import("../core/check-def.js").CheckDef<string>;
|
|
9
9
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type CheckDef } from '../core/check-def';
|
|
2
|
-
import { type StandardSchemaV1 } from '../core/util/standard-schema';
|
|
3
|
-
import type { TypeGuard, TypeTag } from '../types/runtime-type';
|
|
1
|
+
import { type CheckDef } from '../core/check-def.js';
|
|
2
|
+
import { type StandardSchemaV1 } from '../core/util/standard-schema.js';
|
|
3
|
+
import type { TypeGuard, TypeTag } from '../types/runtime-type.js';
|
|
4
4
|
export declare const runtimeTypeChecks: {
|
|
5
5
|
isType: CheckDef<StandardSchemaV1<unknown, unknown> | TypeGuard | TypeTag>;
|
|
6
6
|
isArray: CheckDef<boolean>;
|
package/dist/checks/size.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const sizeChecks: {
|
|
2
|
-
isEmpty: import("../core/check-def").CheckDef<boolean>;
|
|
3
|
-
isNotEmpty: import("../core/check-def").CheckDef<boolean>;
|
|
4
|
-
isBlank: import("../core/check-def").CheckDef<boolean>;
|
|
5
|
-
hasLength: import("../core/check-def").CheckDef<number>;
|
|
6
|
-
hasMinLength: import("../core/check-def").CheckDef<number>;
|
|
7
|
-
hasMaxLength: import("../core/check-def").CheckDef<number>;
|
|
2
|
+
isEmpty: import("../core/check-def.js").CheckDef<boolean>;
|
|
3
|
+
isNotEmpty: import("../core/check-def.js").CheckDef<boolean>;
|
|
4
|
+
isBlank: import("../core/check-def.js").CheckDef<boolean>;
|
|
5
|
+
hasLength: import("../core/check-def.js").CheckDef<number>;
|
|
6
|
+
hasMinLength: import("../core/check-def.js").CheckDef<number>;
|
|
7
|
+
hasMaxLength: import("../core/check-def.js").CheckDef<number>;
|
|
8
8
|
};
|
package/dist/checks/strings.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const stringChecks: {
|
|
2
|
-
startsWith: import("../core/check-def").CheckDef<string>;
|
|
3
|
-
endsWith: import("../core/check-def").CheckDef<string>;
|
|
4
|
-
includes: import("../core/check-def").CheckDef<string>;
|
|
5
|
-
matches: import("../core/check-def").CheckDef<RegExp>;
|
|
2
|
+
startsWith: import("../core/check-def.js").CheckDef<string>;
|
|
3
|
+
endsWith: import("../core/check-def.js").CheckDef<string>;
|
|
4
|
+
includes: import("../core/check-def.js").CheckDef<string>;
|
|
5
|
+
matches: import("../core/check-def.js").CheckDef<RegExp>;
|
|
6
6
|
};
|
package/dist/core/check-def.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AffirmParams } from '../types/params';
|
|
2
|
-
import { type AffirmFailure } from './report';
|
|
1
|
+
import type { AffirmParams } from '../types/params.js';
|
|
2
|
+
import { type AffirmFailure } from './report.js';
|
|
3
3
|
/** Canonical evaluation phases (design §4 rule 7). Lower runs first. */
|
|
4
4
|
export declare const Phase: {
|
|
5
5
|
/** Cheap type / nullish / equality checks. */
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AffirmReport } from './report';
|
|
1
|
+
import type { AffirmReport } from './report.js';
|
|
2
2
|
/**
|
|
3
3
|
* Thrown by `affirm.assert` when data fails its checks (design §9). `report` has every failure.
|
|
4
4
|
* The default message lists the first three reasons, then `(+N more)`.
|
package/dist/core/evaluate.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AffirmParams } from '../types/params';
|
|
2
|
-
import type { Mode } from './check-def';
|
|
3
|
-
import type { AffirmFailure } from './report';
|
|
1
|
+
import type { AffirmParams } from '../types/params.js';
|
|
2
|
+
import type { Mode } from './check-def.js';
|
|
3
|
+
import type { AffirmFailure } from './report.js';
|
|
4
4
|
/**
|
|
5
5
|
* Runs already-validated params against a value in canonical key order (design §4 rule 7).
|
|
6
6
|
* `'first'` stops at the first failing key; `'all'` collects every failure.
|
package/dist/core/registry.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AffirmParams } from '../types/params';
|
|
2
|
-
import type { CheckDef, CheckGroup } from './check-def';
|
|
1
|
+
import type { AffirmParams } from '../types/params.js';
|
|
2
|
+
import type { CheckDef, CheckGroup } from './check-def.js';
|
|
3
3
|
type AnyGroup = Readonly<Record<string, CheckDef<any>>>;
|
|
4
4
|
type UnionToIntersection<U> = (U extends unknown ? (u: U) => void : never) extends (i: infer I) => void ? I : never;
|
|
5
5
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AffirmParams } from '../types/params';
|
|
1
|
+
import type { AffirmParams } from '../types/params.js';
|
|
2
2
|
/**
|
|
3
3
|
* Throws `TypeError` for programmer errors (design §4 rule 6, D4):
|
|
4
4
|
* params that are not an object, empty params `{}`, unknown keys, and wrong param types.
|