@socketsecurity/lib 5.20.1 → 5.21.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 +96 -95
- package/dist/archives.js +13 -0
- package/dist/cacache.js +6 -8
- package/dist/cache-with-ttl.js +1 -1
- package/dist/constants/socket.js +1 -1
- package/dist/dlx/detect.js +25 -8
- package/dist/dlx/package.js +14 -1
- package/dist/fs.js +8 -2
- package/dist/globs.js +5 -1
- package/dist/ipc.js +2 -2
- package/dist/json/parse.d.ts +47 -2
- package/dist/json/parse.js +40 -2
- package/dist/json/types.d.ts +49 -0
- package/dist/memoization.d.ts +4 -23
- package/dist/memoization.js +14 -54
- package/dist/packages/specs.js +9 -2
- package/dist/process-lock.js +1 -6
- package/dist/promise-queue.d.ts +9 -4
- package/dist/promise-queue.js +9 -7
- package/dist/promises.d.ts +41 -0
- package/dist/promises.js +19 -2
- package/dist/regexps.d.ts +4 -13
- package/dist/regexps.js +60 -3
- package/dist/schema/parse.d.ts +26 -0
- package/dist/schema/parse.js +38 -0
- package/dist/schema/types.d.ts +121 -0
- package/dist/schema/validate.d.ts +35 -0
- package/dist/{validation/validate-schema.js → schema/validate.js} +4 -14
- package/dist/suppress-warnings.js +0 -2
- package/dist/url.js +5 -1
- package/dist/versions.js +2 -2
- package/dist/words.js +4 -7
- package/package.json +14 -14
- package/dist/validation/json-parser.d.ts +0 -58
- package/dist/validation/json-parser.js +0 -63
- package/dist/validation/types.d.ts +0 -118
- package/dist/validation/validate-schema.d.ts +0 -124
- /package/dist/{validation → schema}/types.js +0 -0
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Universal schema validation for Zod-style schemas (Zod v3,
|
|
3
|
-
* v4, and any `safeParse`-shaped duck type).
|
|
4
|
-
*
|
|
5
|
-
* Accepts a schema and returns a tagged result.
|
|
6
|
-
* - `{ ok: true, value }` — validation passed, `value` is typed as the
|
|
7
|
-
* schema's inferred output (`z.infer<typeof S>`).
|
|
8
|
-
* - `{ ok: false, errors }` — validation failed, `errors` is a normalized
|
|
9
|
-
* list of `{ path, message }`.
|
|
10
|
-
*
|
|
11
|
-
* Zod is detected purely structurally via `.safeParse` — no runtime import of
|
|
12
|
-
* the `zod` package is required by socket-lib.
|
|
13
|
-
*
|
|
14
|
-
* @internal
|
|
15
|
-
* Socket-lib additionally recognizes TypeBox schemas for its own internal
|
|
16
|
-
* use (e.g. `src/ipc.ts`'s stub-file validation). That path is not a
|
|
17
|
-
* supported consumer API — callers should use Zod.
|
|
18
|
-
*/
|
|
19
|
-
import type { Schema } from './types';
|
|
20
|
-
/**
|
|
21
|
-
* TypeBox's `Kind` symbol. We reference it structurally for schema detection
|
|
22
|
-
* rather than importing it from `@sinclair/typebox` — detection scans the
|
|
23
|
-
* schema's own-symbol keys for one whose description is `'TypeBox.Kind'`.
|
|
24
|
-
* The `Value` runtime is only loaded lazily when a TypeBox schema is seen.
|
|
25
|
-
*/
|
|
26
|
-
type TypeBoxKindSymbol = symbol & {
|
|
27
|
-
__typeBoxKindBrand?: never;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Structural minimum of a TypeBox `TSchema`. The phantom `static` field is
|
|
31
|
-
* the type TypeBox uses for inference (`Static<T> = T['static']`).
|
|
32
|
-
*/
|
|
33
|
-
interface TypeBoxLikeSchema {
|
|
34
|
-
[k: TypeBoxKindSymbol]: string;
|
|
35
|
-
static: unknown;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Structural shape of a Zod v4 schema — carries output type on `_zod.output`.
|
|
39
|
-
*/
|
|
40
|
-
interface ZodV4LikeSchema<O = unknown> {
|
|
41
|
-
_zod: {
|
|
42
|
-
output: O;
|
|
43
|
-
};
|
|
44
|
-
safeParse(data: unknown): unknown;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Structural shape of a Zod v3 schema — carries output type on `_output`.
|
|
48
|
-
*/
|
|
49
|
-
interface ZodV3LikeSchema<O = unknown> {
|
|
50
|
-
_output: O;
|
|
51
|
-
safeParse(data: unknown): unknown;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Any schema kind this helper accepts.
|
|
55
|
-
*/
|
|
56
|
-
export type AnySchema = TypeBoxLikeSchema | ZodV4LikeSchema<unknown> | ZodV3LikeSchema<unknown> | Schema<unknown>;
|
|
57
|
-
/**
|
|
58
|
-
* Infer the validated output type from any supported schema kind.
|
|
59
|
-
*
|
|
60
|
-
* Order matters: TypeBox schemas also carry a phantom `static` field, so we
|
|
61
|
-
* check for TypeBox before falling through to Zod and the duck-type.
|
|
62
|
-
*/
|
|
63
|
-
export type Infer<S> = S extends {
|
|
64
|
-
static: infer Static;
|
|
65
|
-
} ? Static : S extends {
|
|
66
|
-
_zod: {
|
|
67
|
-
output: infer O;
|
|
68
|
-
};
|
|
69
|
-
} ? O : S extends {
|
|
70
|
-
_output: infer O;
|
|
71
|
-
} ? O : S extends Schema<infer T> ? T : unknown;
|
|
72
|
-
/**
|
|
73
|
-
* A single normalized validation error.
|
|
74
|
-
* - `path` is a dotted or slash-separated identifier locating the bad value.
|
|
75
|
-
* - `message` is human-readable.
|
|
76
|
-
*/
|
|
77
|
-
export interface ValidationIssue {
|
|
78
|
-
/** Array path into the value (e.g. `['user', 'age']`). */
|
|
79
|
-
path: Array<string | number>;
|
|
80
|
-
/** Human-readable description of the failure. */
|
|
81
|
-
message: string;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Tagged-union result of {@link validateSchema}. Callers narrow on `ok`.
|
|
85
|
-
*/
|
|
86
|
-
export type ValidateResult<T> = {
|
|
87
|
-
ok: true;
|
|
88
|
-
value: T;
|
|
89
|
-
} | {
|
|
90
|
-
ok: false;
|
|
91
|
-
errors: ValidationIssue[];
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Validate `data` against a Zod-style `schema`. Non-throwing.
|
|
95
|
-
*
|
|
96
|
-
* Accepted schemas:
|
|
97
|
-
* - `zod` schemas, v3 and v4 (detected via `.safeParse` on the schema)
|
|
98
|
-
* - Any object conforming to {@link Schema} (the socket-lib duck type)
|
|
99
|
-
*
|
|
100
|
-
* The return type narrows `value` to {@link Infer | `Infer<S>`}, so callers
|
|
101
|
-
* get `z.infer<typeof S>` with no casts.
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* ```ts
|
|
105
|
-
* import { z } from 'zod'
|
|
106
|
-
* const U = z.object({ name: z.string() })
|
|
107
|
-
* const r = validateSchema(U, data)
|
|
108
|
-
* if (r.ok) r.value.name // string
|
|
109
|
-
* ```
|
|
110
|
-
*
|
|
111
|
-
* Errors are normalized to {@link ValidationIssue}: `{ path, message }`.
|
|
112
|
-
*/
|
|
113
|
-
export declare function validateSchema<S>(schema: S, data: unknown): ValidateResult<Infer<S>>;
|
|
114
|
-
/**
|
|
115
|
-
* Parse `data` against `schema` and return the validated value. Throws if
|
|
116
|
-
* validation fails. This is the throwing twin of {@link validateSchema}.
|
|
117
|
-
*
|
|
118
|
-
* Use when you want fail-fast semantics at a trust boundary. For recoverable
|
|
119
|
-
* validation (form input, external configs), prefer {@link validateSchema}.
|
|
120
|
-
*
|
|
121
|
-
* @throws {Error} When validation fails. The message lists all issues.
|
|
122
|
-
*/
|
|
123
|
-
export declare function parseSchema<S>(schema: S, data: unknown): Infer<S>;
|
|
124
|
-
export {};
|
|
File without changes
|