golar 0.1.4 → 0.1.5
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/dist/builtin-rules.d.ts +2 -3
- package/dist/builtin-rules.generated.d.ts +3 -3
- package/dist/internal/linter/rule-creator.d.ts +3 -2
- package/dist/internal/linter/rule-creator.js +10 -10
- package/dist/internal/linter/rules/explicit-anys/config.js +3 -3
- package/dist/node_modules/.pnpm/valibot@1.3.1_typescript@5.9.3/node_modules/valibot/dist/index.d.ts +1430 -0
- package/dist/node_modules/.pnpm/valibot@1.3.1_typescript@5.9.3/node_modules/valibot/dist/index.js +658 -0
- package/dist/packages/golar/package.js +1 -1
- package/dist/workspace.js +2 -2
- package/package.json +9 -9
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.d.ts +0 -22
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/errors.js +0 -29
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/iso.js +0 -37
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/parse.d.ts +0 -16
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/parse.js +0 -19
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.d.ts +0 -208
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/classic/schemas.js +0 -578
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/api.d.ts +0 -32
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/api.js +0 -470
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.d.ts +0 -64
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/checks.js +0 -225
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.d.ts +0 -47
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js +0 -61
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/doc.js +0 -33
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.d.ts +0 -127
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js +0 -62
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema-processors.js +0 -214
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/json-schema.d.ts +0 -69
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/parse.js +0 -109
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/regexes.js +0 -58
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.d.ts +0 -31
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/registries.js +0 -49
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.d.ts +0 -805
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/schemas.js +0 -1096
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.ts +0 -120
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.ts +0 -96
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.js +0 -289
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.ts +0 -41
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js +0 -304
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.d.ts +0 -8
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.js +0 -9
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
//#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/standard-schema.d.cts
|
|
2
|
-
/** The Standard interface. */
|
|
3
|
-
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
4
|
-
/** The Standard properties. */
|
|
5
|
-
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
6
|
-
}
|
|
7
|
-
declare namespace StandardTypedV1 {
|
|
8
|
-
/** The Standard properties interface. */
|
|
9
|
-
interface Props<Input = unknown, Output = Input> {
|
|
10
|
-
/** The version number of the standard. */
|
|
11
|
-
readonly version: 1;
|
|
12
|
-
/** The vendor name of the schema library. */
|
|
13
|
-
readonly vendor: string;
|
|
14
|
-
/** Inferred types associated with the schema. */
|
|
15
|
-
readonly types?: Types<Input, Output> | undefined;
|
|
16
|
-
}
|
|
17
|
-
/** The Standard types interface. */
|
|
18
|
-
interface Types<Input = unknown, Output = Input> {
|
|
19
|
-
/** The input type of the schema. */
|
|
20
|
-
readonly input: Input;
|
|
21
|
-
/** The output type of the schema. */
|
|
22
|
-
readonly output: Output;
|
|
23
|
-
}
|
|
24
|
-
/** Infers the input type of a Standard. */
|
|
25
|
-
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
26
|
-
/** Infers the output type of a Standard. */
|
|
27
|
-
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
28
|
-
}
|
|
29
|
-
/** The Standard Schema interface. */
|
|
30
|
-
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
31
|
-
/** The Standard Schema properties. */
|
|
32
|
-
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
33
|
-
}
|
|
34
|
-
declare namespace StandardSchemaV1 {
|
|
35
|
-
/** The Standard Schema properties interface. */
|
|
36
|
-
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
37
|
-
/** Validates unknown input values. */
|
|
38
|
-
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
39
|
-
}
|
|
40
|
-
/** The result interface of the validate function. */
|
|
41
|
-
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
42
|
-
/** The result interface if validation succeeds. */
|
|
43
|
-
interface SuccessResult<Output> {
|
|
44
|
-
/** The typed output value. */
|
|
45
|
-
readonly value: Output;
|
|
46
|
-
/** The absence of issues indicates success. */
|
|
47
|
-
readonly issues?: undefined;
|
|
48
|
-
}
|
|
49
|
-
interface Options {
|
|
50
|
-
/** Implicit support for additional vendor-specific parameters, if needed. */
|
|
51
|
-
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
52
|
-
}
|
|
53
|
-
/** The result interface if validation fails. */
|
|
54
|
-
interface FailureResult {
|
|
55
|
-
/** The issues of failed validation. */
|
|
56
|
-
readonly issues: ReadonlyArray<Issue>;
|
|
57
|
-
}
|
|
58
|
-
/** The issue interface of the failure output. */
|
|
59
|
-
interface Issue {
|
|
60
|
-
/** The error message of the issue. */
|
|
61
|
-
readonly message: string;
|
|
62
|
-
/** The path of the issue, if any. */
|
|
63
|
-
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
64
|
-
}
|
|
65
|
-
/** The path segment interface of the issue. */
|
|
66
|
-
interface PathSegment {
|
|
67
|
-
/** The key representing a path segment. */
|
|
68
|
-
readonly key: PropertyKey;
|
|
69
|
-
}
|
|
70
|
-
/** The Standard types interface. */
|
|
71
|
-
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
72
|
-
/** Infers the input type of a Standard. */
|
|
73
|
-
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
74
|
-
/** Infers the output type of a Standard. */
|
|
75
|
-
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
76
|
-
}
|
|
77
|
-
/** The Standard JSON Schema interface. */
|
|
78
|
-
interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
79
|
-
/** The Standard JSON Schema properties. */
|
|
80
|
-
readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
|
|
81
|
-
}
|
|
82
|
-
declare namespace StandardJSONSchemaV1 {
|
|
83
|
-
/** The Standard JSON Schema properties interface. */
|
|
84
|
-
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
85
|
-
/** Methods for generating the input/output JSON Schema. */
|
|
86
|
-
readonly jsonSchema: Converter;
|
|
87
|
-
}
|
|
88
|
-
/** The Standard JSON Schema converter interface. */
|
|
89
|
-
interface Converter {
|
|
90
|
-
/** Converts the input type to JSON Schema. May throw if conversion is not supported. */
|
|
91
|
-
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
92
|
-
/** Converts the output type to JSON Schema. May throw if conversion is not supported. */
|
|
93
|
-
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
94
|
-
}
|
|
95
|
-
/** The target version of the generated JSON Schema.
|
|
96
|
-
*
|
|
97
|
-
* It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use.
|
|
98
|
-
*
|
|
99
|
-
* The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
|
|
100
|
-
*
|
|
101
|
-
* All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
|
|
102
|
-
*/
|
|
103
|
-
type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
|
|
104
|
-
/** The options for the input/output methods. */
|
|
105
|
-
interface Options {
|
|
106
|
-
/** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
|
|
107
|
-
readonly target: Target;
|
|
108
|
-
/** Implicit support for additional vendor-specific parameters, if needed. */
|
|
109
|
-
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
110
|
-
}
|
|
111
|
-
/** The Standard types interface. */
|
|
112
|
-
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
113
|
-
/** Infers the input type of a Standard. */
|
|
114
|
-
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
115
|
-
/** Infers the output type of a Standard. */
|
|
116
|
-
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
117
|
-
}
|
|
118
|
-
interface StandardSchemaWithJSONProps<Input = unknown, Output = Input> extends StandardSchemaV1.Props<Input, Output>, StandardJSONSchemaV1.Props<Input, Output> {}
|
|
119
|
-
//#endregion
|
|
120
|
-
export { StandardSchemaV1, StandardSchemaWithJSONProps };
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { BaseSchema } from "./json-schema.js";
|
|
2
|
-
import { StandardSchemaWithJSONProps } from "./standard-schema.js";
|
|
3
|
-
import { $ZodRegistry } from "./registries.js";
|
|
4
|
-
import { $ZodType, $ZodTypes } from "./schemas.js";
|
|
5
|
-
import { input, output } from "./core.js";
|
|
6
|
-
|
|
7
|
-
//#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.d.cts
|
|
8
|
-
type Processor<T extends $ZodType = $ZodType> = (schema: T, ctx: ToJSONSchemaContext, json: BaseSchema, params: ProcessParams) => void;
|
|
9
|
-
interface JSONSchemaGeneratorParams {
|
|
10
|
-
processors: Record<string, Processor>;
|
|
11
|
-
/** A registry used to look up metadata for each schema. Any schema with an `id` property will be extracted as a $def.
|
|
12
|
-
* @default globalRegistry */
|
|
13
|
-
metadata?: $ZodRegistry<Record<string, any>>;
|
|
14
|
-
/** The JSON Schema version to target.
|
|
15
|
-
* - `"draft-2020-12"` — Default. JSON Schema Draft 2020-12
|
|
16
|
-
* - `"draft-07"` — JSON Schema Draft 7
|
|
17
|
-
* - `"draft-04"` — JSON Schema Draft 4
|
|
18
|
-
* - `"openapi-3.0"` — OpenAPI 3.0 Schema Object */
|
|
19
|
-
target?: "draft-04" | "draft-07" | "draft-2020-12" | "openapi-3.0" | ({} & string) | undefined;
|
|
20
|
-
/** How to handle unrepresentable types.
|
|
21
|
-
* - `"throw"` — Default. Unrepresentable types throw an error
|
|
22
|
-
* - `"any"` — Unrepresentable types become `{}` */
|
|
23
|
-
unrepresentable?: "throw" | "any";
|
|
24
|
-
/** Arbitrary custom logic that can be used to modify the generated JSON Schema. */
|
|
25
|
-
override?: (ctx: {
|
|
26
|
-
zodSchema: $ZodTypes;
|
|
27
|
-
jsonSchema: BaseSchema;
|
|
28
|
-
path: (string | number)[];
|
|
29
|
-
}) => void;
|
|
30
|
-
/** Whether to extract the `"input"` or `"output"` type. Relevant to transforms, defaults, coerced primitives, etc.
|
|
31
|
-
* - `"output"` — Default. Convert the output schema.
|
|
32
|
-
* - `"input"` — Convert the input schema. */
|
|
33
|
-
io?: "input" | "output";
|
|
34
|
-
cycles?: "ref" | "throw";
|
|
35
|
-
reused?: "ref" | "inline";
|
|
36
|
-
external?: {
|
|
37
|
-
registry: $ZodRegistry<{
|
|
38
|
-
id?: string | undefined;
|
|
39
|
-
}>;
|
|
40
|
-
uri?: ((id: string) => string) | undefined;
|
|
41
|
-
defs: Record<string, BaseSchema>;
|
|
42
|
-
} | undefined;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Parameters for the toJSONSchema function.
|
|
46
|
-
*/
|
|
47
|
-
type ToJSONSchemaParams = Omit<JSONSchemaGeneratorParams, "processors" | "external">;
|
|
48
|
-
interface ProcessParams {
|
|
49
|
-
schemaPath: $ZodType[];
|
|
50
|
-
path: (string | number)[];
|
|
51
|
-
}
|
|
52
|
-
interface Seen {
|
|
53
|
-
/** JSON Schema result for this Zod schema */
|
|
54
|
-
schema: BaseSchema;
|
|
55
|
-
/** A cached version of the schema that doesn't get overwritten during ref resolution */
|
|
56
|
-
def?: BaseSchema;
|
|
57
|
-
defId?: string | undefined;
|
|
58
|
-
/** Number of times this schema was encountered during traversal */
|
|
59
|
-
count: number;
|
|
60
|
-
/** Cycle path */
|
|
61
|
-
cycle?: (string | number)[] | undefined;
|
|
62
|
-
isParent?: boolean | undefined;
|
|
63
|
-
/** Schema to inherit JSON Schema properties from (set by processor for wrappers) */
|
|
64
|
-
ref?: $ZodType | null;
|
|
65
|
-
/** JSON Schema property path for this schema */
|
|
66
|
-
path?: (string | number)[] | undefined;
|
|
67
|
-
}
|
|
68
|
-
interface ToJSONSchemaContext {
|
|
69
|
-
processors: Record<string, Processor>;
|
|
70
|
-
metadataRegistry: $ZodRegistry<Record<string, any>>;
|
|
71
|
-
target: "draft-04" | "draft-07" | "draft-2020-12" | "openapi-3.0" | ({} & string);
|
|
72
|
-
unrepresentable: "throw" | "any";
|
|
73
|
-
override: (ctx: {
|
|
74
|
-
zodSchema: $ZodType;
|
|
75
|
-
jsonSchema: BaseSchema;
|
|
76
|
-
path: (string | number)[];
|
|
77
|
-
}) => void;
|
|
78
|
-
io: "input" | "output";
|
|
79
|
-
counter: number;
|
|
80
|
-
seen: Map<$ZodType, Seen>;
|
|
81
|
-
cycles: "ref" | "throw";
|
|
82
|
-
reused: "ref" | "inline";
|
|
83
|
-
external?: {
|
|
84
|
-
registry: $ZodRegistry<{
|
|
85
|
-
id?: string | undefined;
|
|
86
|
-
}>;
|
|
87
|
-
uri?: ((id: string) => string) | undefined;
|
|
88
|
-
defs: Record<string, BaseSchema>;
|
|
89
|
-
} | undefined;
|
|
90
|
-
}
|
|
91
|
-
type ZodStandardSchemaWithJSON<T> = StandardSchemaWithJSONProps<input<T>, output<T>>;
|
|
92
|
-
interface ZodStandardJSONSchemaPayload<T> extends BaseSchema {
|
|
93
|
-
"~standard": ZodStandardSchemaWithJSON<T>;
|
|
94
|
-
}
|
|
95
|
-
//#endregion
|
|
96
|
-
export { ProcessParams, ToJSONSchemaContext, ToJSONSchemaParams, ZodStandardJSONSchemaPayload };
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { globalRegistry } from "./registries.js";
|
|
2
|
-
|
|
3
|
-
//#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/to-json-schema.js
|
|
4
|
-
function initializeContext(params) {
|
|
5
|
-
let target = params?.target ?? "draft-2020-12";
|
|
6
|
-
if (target === "draft-4") target = "draft-04";
|
|
7
|
-
if (target === "draft-7") target = "draft-07";
|
|
8
|
-
return {
|
|
9
|
-
processors: params.processors ?? {},
|
|
10
|
-
metadataRegistry: params?.metadata ?? globalRegistry,
|
|
11
|
-
target,
|
|
12
|
-
unrepresentable: params?.unrepresentable ?? "throw",
|
|
13
|
-
override: params?.override ?? (() => {}),
|
|
14
|
-
io: params?.io ?? "output",
|
|
15
|
-
counter: 0,
|
|
16
|
-
seen: /* @__PURE__ */ new Map(),
|
|
17
|
-
cycles: params?.cycles ?? "ref",
|
|
18
|
-
reused: params?.reused ?? "inline",
|
|
19
|
-
external: params?.external ?? void 0
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function process(schema, ctx, _params = {
|
|
23
|
-
path: [],
|
|
24
|
-
schemaPath: []
|
|
25
|
-
}) {
|
|
26
|
-
var _a;
|
|
27
|
-
const def = schema._zod.def;
|
|
28
|
-
const seen = ctx.seen.get(schema);
|
|
29
|
-
if (seen) {
|
|
30
|
-
seen.count++;
|
|
31
|
-
if (_params.schemaPath.includes(schema)) seen.cycle = _params.path;
|
|
32
|
-
return seen.schema;
|
|
33
|
-
}
|
|
34
|
-
const result = {
|
|
35
|
-
schema: {},
|
|
36
|
-
count: 1,
|
|
37
|
-
cycle: void 0,
|
|
38
|
-
path: _params.path
|
|
39
|
-
};
|
|
40
|
-
ctx.seen.set(schema, result);
|
|
41
|
-
const overrideSchema = schema._zod.toJSONSchema?.();
|
|
42
|
-
if (overrideSchema) result.schema = overrideSchema;
|
|
43
|
-
else {
|
|
44
|
-
const params = {
|
|
45
|
-
..._params,
|
|
46
|
-
schemaPath: [..._params.schemaPath, schema],
|
|
47
|
-
path: _params.path
|
|
48
|
-
};
|
|
49
|
-
if (schema._zod.processJSONSchema) schema._zod.processJSONSchema(ctx, result.schema, params);
|
|
50
|
-
else {
|
|
51
|
-
const _json = result.schema;
|
|
52
|
-
const processor = ctx.processors[def.type];
|
|
53
|
-
if (!processor) throw new Error(`[toJSONSchema]: Non-representable type encountered: ${def.type}`);
|
|
54
|
-
processor(schema, ctx, _json, params);
|
|
55
|
-
}
|
|
56
|
-
const parent = schema._zod.parent;
|
|
57
|
-
if (parent) {
|
|
58
|
-
if (!result.ref) result.ref = parent;
|
|
59
|
-
process(parent, ctx, params);
|
|
60
|
-
ctx.seen.get(parent).isParent = true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const meta = ctx.metadataRegistry.get(schema);
|
|
64
|
-
if (meta) Object.assign(result.schema, meta);
|
|
65
|
-
if (ctx.io === "input" && isTransforming(schema)) {
|
|
66
|
-
delete result.schema.examples;
|
|
67
|
-
delete result.schema.default;
|
|
68
|
-
}
|
|
69
|
-
if (ctx.io === "input" && result.schema._prefault) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
|
|
70
|
-
delete result.schema._prefault;
|
|
71
|
-
return ctx.seen.get(schema).schema;
|
|
72
|
-
}
|
|
73
|
-
function extractDefs(ctx, schema) {
|
|
74
|
-
const root = ctx.seen.get(schema);
|
|
75
|
-
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
76
|
-
const idToSchema = /* @__PURE__ */ new Map();
|
|
77
|
-
for (const entry of ctx.seen.entries()) {
|
|
78
|
-
const id = ctx.metadataRegistry.get(entry[0])?.id;
|
|
79
|
-
if (id) {
|
|
80
|
-
const existing = idToSchema.get(id);
|
|
81
|
-
if (existing && existing !== entry[0]) throw new Error(`Duplicate schema id "${id}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);
|
|
82
|
-
idToSchema.set(id, entry[0]);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const makeURI = (entry) => {
|
|
86
|
-
const defsSegment = ctx.target === "draft-2020-12" ? "$defs" : "definitions";
|
|
87
|
-
if (ctx.external) {
|
|
88
|
-
const externalId = ctx.external.registry.get(entry[0])?.id;
|
|
89
|
-
const uriGenerator = ctx.external.uri ?? ((id) => id);
|
|
90
|
-
if (externalId) return { ref: uriGenerator(externalId) };
|
|
91
|
-
const id = entry[1].defId ?? entry[1].schema.id ?? `schema${ctx.counter++}`;
|
|
92
|
-
entry[1].defId = id;
|
|
93
|
-
return {
|
|
94
|
-
defId: id,
|
|
95
|
-
ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
if (entry[1] === root) return { ref: "#" };
|
|
99
|
-
const defUriPrefix = `#/${defsSegment}/`;
|
|
100
|
-
const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
|
|
101
|
-
return {
|
|
102
|
-
defId,
|
|
103
|
-
ref: defUriPrefix + defId
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
const extractToDef = (entry) => {
|
|
107
|
-
if (entry[1].schema.$ref) return;
|
|
108
|
-
const seen = entry[1];
|
|
109
|
-
const { ref, defId } = makeURI(entry);
|
|
110
|
-
seen.def = { ...seen.schema };
|
|
111
|
-
if (defId) seen.defId = defId;
|
|
112
|
-
const schema = seen.schema;
|
|
113
|
-
for (const key in schema) delete schema[key];
|
|
114
|
-
schema.$ref = ref;
|
|
115
|
-
};
|
|
116
|
-
if (ctx.cycles === "throw") for (const entry of ctx.seen.entries()) {
|
|
117
|
-
const seen = entry[1];
|
|
118
|
-
if (seen.cycle) throw new Error(`Cycle detected: #/${seen.cycle?.join("/")}/<root>
|
|
119
|
-
|
|
120
|
-
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`);
|
|
121
|
-
}
|
|
122
|
-
for (const entry of ctx.seen.entries()) {
|
|
123
|
-
const seen = entry[1];
|
|
124
|
-
if (schema === entry[0]) {
|
|
125
|
-
extractToDef(entry);
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
if (ctx.external) {
|
|
129
|
-
const ext = ctx.external.registry.get(entry[0])?.id;
|
|
130
|
-
if (schema !== entry[0] && ext) {
|
|
131
|
-
extractToDef(entry);
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (ctx.metadataRegistry.get(entry[0])?.id) {
|
|
136
|
-
extractToDef(entry);
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (seen.cycle) {
|
|
140
|
-
extractToDef(entry);
|
|
141
|
-
continue;
|
|
142
|
-
}
|
|
143
|
-
if (seen.count > 1) {
|
|
144
|
-
if (ctx.reused === "ref") {
|
|
145
|
-
extractToDef(entry);
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
function finalize(ctx, schema) {
|
|
152
|
-
const root = ctx.seen.get(schema);
|
|
153
|
-
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
154
|
-
const flattenRef = (zodSchema) => {
|
|
155
|
-
const seen = ctx.seen.get(zodSchema);
|
|
156
|
-
if (seen.ref === null) return;
|
|
157
|
-
const schema = seen.def ?? seen.schema;
|
|
158
|
-
const _cached = { ...schema };
|
|
159
|
-
const ref = seen.ref;
|
|
160
|
-
seen.ref = null;
|
|
161
|
-
if (ref) {
|
|
162
|
-
flattenRef(ref);
|
|
163
|
-
const refSeen = ctx.seen.get(ref);
|
|
164
|
-
const refSchema = refSeen.schema;
|
|
165
|
-
if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
|
|
166
|
-
schema.allOf = schema.allOf ?? [];
|
|
167
|
-
schema.allOf.push(refSchema);
|
|
168
|
-
} else Object.assign(schema, refSchema);
|
|
169
|
-
Object.assign(schema, _cached);
|
|
170
|
-
if (zodSchema._zod.parent === ref) for (const key in schema) {
|
|
171
|
-
if (key === "$ref" || key === "allOf") continue;
|
|
172
|
-
if (!(key in _cached)) delete schema[key];
|
|
173
|
-
}
|
|
174
|
-
if (refSchema.$ref && refSeen.def) for (const key in schema) {
|
|
175
|
-
if (key === "$ref" || key === "allOf") continue;
|
|
176
|
-
if (key in refSeen.def && JSON.stringify(schema[key]) === JSON.stringify(refSeen.def[key])) delete schema[key];
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
const parent = zodSchema._zod.parent;
|
|
180
|
-
if (parent && parent !== ref) {
|
|
181
|
-
flattenRef(parent);
|
|
182
|
-
const parentSeen = ctx.seen.get(parent);
|
|
183
|
-
if (parentSeen?.schema.$ref) {
|
|
184
|
-
schema.$ref = parentSeen.schema.$ref;
|
|
185
|
-
if (parentSeen.def) for (const key in schema) {
|
|
186
|
-
if (key === "$ref" || key === "allOf") continue;
|
|
187
|
-
if (key in parentSeen.def && JSON.stringify(schema[key]) === JSON.stringify(parentSeen.def[key])) delete schema[key];
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
ctx.override({
|
|
192
|
-
zodSchema,
|
|
193
|
-
jsonSchema: schema,
|
|
194
|
-
path: seen.path ?? []
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
|
-
for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
|
|
198
|
-
const result = {};
|
|
199
|
-
if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
200
|
-
else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
|
|
201
|
-
else if (ctx.target === "draft-04") result.$schema = "http://json-schema.org/draft-04/schema#";
|
|
202
|
-
else if (ctx.target === "openapi-3.0") {}
|
|
203
|
-
if (ctx.external?.uri) {
|
|
204
|
-
const id = ctx.external.registry.get(schema)?.id;
|
|
205
|
-
if (!id) throw new Error("Schema is missing an `id` property");
|
|
206
|
-
result.$id = ctx.external.uri(id);
|
|
207
|
-
}
|
|
208
|
-
Object.assign(result, root.def ?? root.schema);
|
|
209
|
-
const defs = ctx.external?.defs ?? {};
|
|
210
|
-
for (const entry of ctx.seen.entries()) {
|
|
211
|
-
const seen = entry[1];
|
|
212
|
-
if (seen.def && seen.defId) defs[seen.defId] = seen.def;
|
|
213
|
-
}
|
|
214
|
-
if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
|
|
215
|
-
else result.definitions = defs;
|
|
216
|
-
try {
|
|
217
|
-
const finalized = JSON.parse(JSON.stringify(result));
|
|
218
|
-
Object.defineProperty(finalized, "~standard", {
|
|
219
|
-
value: {
|
|
220
|
-
...schema["~standard"],
|
|
221
|
-
jsonSchema: {
|
|
222
|
-
input: createStandardJSONSchemaMethod(schema, "input", ctx.processors),
|
|
223
|
-
output: createStandardJSONSchemaMethod(schema, "output", ctx.processors)
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
enumerable: false,
|
|
227
|
-
writable: false
|
|
228
|
-
});
|
|
229
|
-
return finalized;
|
|
230
|
-
} catch (_err) {
|
|
231
|
-
throw new Error("Error converting schema to JSON.");
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
function isTransforming(_schema, _ctx) {
|
|
235
|
-
const ctx = _ctx ?? { seen: /* @__PURE__ */ new Set() };
|
|
236
|
-
if (ctx.seen.has(_schema)) return false;
|
|
237
|
-
ctx.seen.add(_schema);
|
|
238
|
-
const def = _schema._zod.def;
|
|
239
|
-
if (def.type === "transform") return true;
|
|
240
|
-
if (def.type === "array") return isTransforming(def.element, ctx);
|
|
241
|
-
if (def.type === "set") return isTransforming(def.valueType, ctx);
|
|
242
|
-
if (def.type === "lazy") return isTransforming(def.getter(), ctx);
|
|
243
|
-
if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
|
|
244
|
-
if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
245
|
-
if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
246
|
-
if (def.type === "pipe") return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
247
|
-
if (def.type === "object") {
|
|
248
|
-
for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
if (def.type === "union") {
|
|
252
|
-
for (const option of def.options) if (isTransforming(option, ctx)) return true;
|
|
253
|
-
return false;
|
|
254
|
-
}
|
|
255
|
-
if (def.type === "tuple") {
|
|
256
|
-
for (const item of def.items) if (isTransforming(item, ctx)) return true;
|
|
257
|
-
if (def.rest && isTransforming(def.rest, ctx)) return true;
|
|
258
|
-
return false;
|
|
259
|
-
}
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Creates a toJSONSchema method for a schema instance.
|
|
264
|
-
* This encapsulates the logic of initializing context, processing, extracting defs, and finalizing.
|
|
265
|
-
*/
|
|
266
|
-
const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
267
|
-
const ctx = initializeContext({
|
|
268
|
-
...params,
|
|
269
|
-
processors
|
|
270
|
-
});
|
|
271
|
-
process(schema, ctx);
|
|
272
|
-
extractDefs(ctx, schema);
|
|
273
|
-
return finalize(ctx, schema);
|
|
274
|
-
};
|
|
275
|
-
const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
|
|
276
|
-
const { libraryOptions, target } = params ?? {};
|
|
277
|
-
const ctx = initializeContext({
|
|
278
|
-
...libraryOptions ?? {},
|
|
279
|
-
target,
|
|
280
|
-
io,
|
|
281
|
-
processors
|
|
282
|
-
});
|
|
283
|
-
process(schema, ctx);
|
|
284
|
-
extractDefs(ctx, schema);
|
|
285
|
-
return finalize(ctx, schema);
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
//#endregion
|
|
289
|
-
export { createStandardJSONSchemaMethod, createToJSONSchemaMethod, process };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { SomeType } from "./schemas.js";
|
|
2
|
-
|
|
3
|
-
//#region ../../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.d.cts
|
|
4
|
-
type MimeTypes = "application/json" | "application/xml" | "application/x-www-form-urlencoded" | "application/javascript" | "application/pdf" | "application/zip" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.ms-powerpoint" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/octet-stream" | "application/graphql" | "text/html" | "text/plain" | "text/css" | "text/javascript" | "text/csv" | "image/png" | "image/jpeg" | "image/gif" | "image/svg+xml" | "image/webp" | "audio/mpeg" | "audio/ogg" | "audio/wav" | "audio/webm" | "video/mp4" | "video/webm" | "video/ogg" | "font/woff" | "font/woff2" | "font/ttf" | "font/otf" | "multipart/form-data" | (string & {});
|
|
5
|
-
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
6
|
-
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
7
|
-
type MakePartial<T, K extends keyof T> = Omit<T, K> & InexactPartial<Pick<T, K>>;
|
|
8
|
-
type NoUndefined<T> = T extends undefined ? never : T;
|
|
9
|
-
type LoosePartial<T extends object> = InexactPartial<T> & {
|
|
10
|
-
[k: string]: unknown;
|
|
11
|
-
};
|
|
12
|
-
type Mask<Keys extends PropertyKey> = { [K in Keys]?: true };
|
|
13
|
-
type InexactPartial<T> = { [P in keyof T]?: T[P] | undefined };
|
|
14
|
-
type BuiltIn = (((...args: any[]) => any) | (new (...args: any[]) => any)) | {
|
|
15
|
-
readonly [Symbol.toStringTag]: string;
|
|
16
|
-
} | Date | Error | Generator | Promise<unknown> | RegExp;
|
|
17
|
-
type MakeReadonly<T> = T extends Map<infer K, infer V> ? ReadonlyMap<K, V> : T extends Set<infer V> ? ReadonlySet<V> : T extends [infer Head, ...infer Tail] ? readonly [Head, ...Tail] : T extends Array<infer V> ? ReadonlyArray<V> : T extends BuiltIn ? T : Readonly<T>;
|
|
18
|
-
type SomeObject = Record<PropertyKey, any>;
|
|
19
|
-
type Identity<T> = T;
|
|
20
|
-
type Flatten<T> = Identity<{ [k in keyof T]: T[k] }>;
|
|
21
|
-
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
22
|
-
type Extend<A extends SomeObject, B extends SomeObject> = Flatten<keyof A & keyof B extends never ? A & B : { [K in keyof A as K extends keyof B ? never : K]: A[K] } & { [K in keyof B]: B[K] }>;
|
|
23
|
-
type TupleItems = ReadonlyArray<SomeType>;
|
|
24
|
-
type AnyFunc = (...args: any[]) => any;
|
|
25
|
-
type MaybeAsync<T> = T | Promise<T>;
|
|
26
|
-
type EnumValue = string | number;
|
|
27
|
-
type EnumLike = Readonly<Record<string, EnumValue>>;
|
|
28
|
-
type ToEnum<T extends EnumValue> = Flatten<{ [k in T]: k }>;
|
|
29
|
-
type Literal = string | number | bigint | boolean | null | undefined;
|
|
30
|
-
type Primitive = string | number | symbol | bigint | boolean | null | undefined;
|
|
31
|
-
type HasLength = {
|
|
32
|
-
length: number;
|
|
33
|
-
};
|
|
34
|
-
type PropValues = Record<string, Set<Primitive>>;
|
|
35
|
-
type PrimitiveSet = Set<Primitive>;
|
|
36
|
-
type EmptyToNever<T> = keyof T extends never ? never : T;
|
|
37
|
-
declare abstract class Class {
|
|
38
|
-
constructor(..._args: any[]);
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
export { AnyFunc, Class, EmptyToNever, EnumLike, Extend, Flatten, HasLength, IsAny, Literal, LoosePartial, MakePartial, MakeReadonly, Mask, MaybeAsync, MimeTypes, NoUndefined, Prettify, Primitive, PrimitiveSet, PropValues, ToEnum, TupleItems };
|