@guren/core 1.11.0 → 1.12.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.
@@ -0,0 +1 @@
1
+ export * from "@guren/server/internal/route-path";
@@ -0,0 +1,2 @@
1
+ export * from "@guren/server/internal/route-path";
2
+ export {};
@@ -1,142 +1 @@
1
- //#region src/internal/zod-compat.d.ts
2
- /**
3
- * Zod 4 schema-reading primitives shared by `@guren/cli`'s TypeScript-type
4
- * renderer (`src/schema-type-extractor.ts`) and the OpenAPI schema-object
5
- * renderer (`@guren/openapi`).
6
- *
7
- * Internal by the rules in `contributing/api-stability.md`: reachable only
8
- * through a deep import under `internal/`, never re-exported from
9
- * `@guren/core`'s index.
10
- *
11
- * Zod 4 only. The zod 3 API (whether from the old `zod@3` package or the
12
- * `zod/v3` subpath that zod 4 ships for migration) tags every node with
13
- * `_def.typeName` and overloads `_def.type` to hold a nested schema — the
14
- * ambiguity behind a bug this module's predecessors fixed twice. Rather than
15
- * carrying both dialects forever, a v3 node is detected up front
16
- * (`isZod3Schema`) and refused with `ZOD3_UNSUPPORTED_MESSAGE`; everything
17
- * below it assumes the v4 layout, where `_def.type` is always the type name.
18
- *
19
- * What does NOT belong here: the two type switches that turn a node into an
20
- * output (a TypeScript type string vs. an OpenAPI schema object). Their leaf
21
- * vocabularies have legitimately diverged — the CLI renders `void`/`any`/
22
- * `never`, which OpenAPI has no way to express — and that is a rendering
23
- * decision, not schema-reading knowledge.
24
- *
25
- * Neither walker's `isOptional` belongs here either, but for a weaker reason
26
- * than "they are both right": the CLI reads only the side of a `.pipe()` it
27
- * renders, the OpenAPI walker requires both sides to permit omission, and
28
- * *both* are approximations that a sufficiently odd pipeline can fool. Fixing
29
- * them properly means simulating a parse, which is well beyond reading a
30
- * `_def`. They stay with their callers until someone does that.
31
- */
32
- interface ZodSchemaLike {
33
- _def?: Record<string, unknown>;
34
- /** zod 4's internal container; `values` is its own computed set of accepted literals. */
35
- _zod?: {
36
- values?: Set<unknown>;
37
- };
38
- type?: string;
39
- shape?: Record<string, ZodSchemaLike>;
40
- }
41
- /**
42
- * Which side of a schema is being read.
43
- *
44
- * - `output` — the parsed value, i.e. what a controller receives after
45
- * validation, or what a response body looks like.
46
- * - `input` — the value a client has to send over the wire. Coercing and
47
- * piped schemas can differ here from their output side.
48
- */
49
- type SchemaIo = 'input' | 'output';
50
- /**
51
- * Whether this node was authored with the zod 3 API. Only v3 sets
52
- * `_def.typeName` (`"ZodString"`), so its presence is the discriminator —
53
- * checked before any other read, because on a v3 node `_def.type` holds a
54
- * nested *schema* and every v4-shaped read below would misfire on it.
55
- */
56
- declare function isZod3Schema(schema: ZodSchemaLike): boolean;
57
- /**
58
- * The one refusal message, stated once so the CLI's console warning and the
59
- * OpenAPI document's warnings array cannot drift apart.
60
- */
61
- declare const ZOD3_UNSUPPORTED_MESSAGE = "this schema was authored with the zod v3 API (zod@3 or the zod/v3 subpath), which Guren does not support. Rewrite it with the zod 4 API (`import { z } from 'zod'`).";
62
- /** The node's type name: `_def.type` (`"string"`, `"object"`, …) or the schema's own `.type`. */
63
- declare function getTypeName(schema: ZodSchemaLike): string | undefined;
64
- /** `getTypeName` with `'unknown'` for a node that has no readable name. */
65
- declare function typeOf(schema: ZodSchemaLike): string;
66
- /**
67
- * The schema at `def[key]`, if it actually holds one. The object check is
68
- * load-bearing: `_def` is untyped data from someone else's package, and a key
69
- * holding a string or function must read as absent, not as a schema. (The
70
- * v3-era version of this helper took a key *list* and returned the first
71
- * match; with one dialect there is no precedence left to encode.)
72
- */
73
- declare function schemaAt(def: Record<string, unknown>, key: string): ZodSchemaLike | undefined;
74
- /** The schema wrapped by a single-child wrapper (`.optional()`, `.readonly()`, `.catch()`, …) — always `_def.innerType` in zod 4. */
75
- declare function innerSchema(def: Record<string, unknown>): ZodSchemaLike | undefined;
76
- /** An array's element schema — `_def.element`, never `_def.type`, which holds the string `'array'`. */
77
- declare function arrayElement(def: Record<string, unknown>): ZodSchemaLike | undefined;
78
- /** A record's value schema — `_def.valueType`. */
79
- declare function recordValueType(def: Record<string, unknown>): ZodSchemaLike | undefined;
80
- /**
81
- * Whether this node is a `.transform()`'s output half — a wrapped function
82
- * with no type to read, as opposed to a schema that genuinely parses to
83
- * `unknown`.
84
- */
85
- declare function isTransform(schema: ZodSchemaLike): boolean;
86
- /**
87
- * Both halves of a `.pipe()`. Zod 4 uses one `pipe` node for both `.pipe()`
88
- * and `.transform()`: `_def.in` is what a caller sends, `_def.out` what a
89
- * controller receives — except for a transform, whose out side is the
90
- * transform function itself and so has no type to read. `to` is therefore
91
- * absent for a transform, leaving `from` as the only readable answer.
92
- */
93
- declare function pipeSides(def: Record<string, unknown>): {
94
- from: ZodSchemaLike | undefined;
95
- to: ZodSchemaLike | undefined;
96
- };
97
- /** The one side of a `.pipe()` that describes the `io` direction being rendered. */
98
- declare function pipeSide(def: Record<string, unknown>, io: SchemaIo): ZodSchemaLike | undefined;
99
- /** An object's property map — `_def.shape`, or the schema's own `.shape`. */
100
- declare function objectShape(schema: ZodSchemaLike): Record<string, ZodSchemaLike> | undefined;
101
- /**
102
- * An enum's accepted values, read from zod's own computed set at
103
- * `_zod.values` rather than re-derived from `_def.entries`. The distinction
104
- * matters because `z.nativeEnum` produces the same node and a real TypeScript
105
- * numeric enum's runtime object carries reverse mappings (`{ A: 0, '0': 'A' }`)
106
- * — and any hand-rolled filter for those has a false positive: in
107
- * `{ A: 'B', B: 1 }`, the key `A` *looks* like a reverse entry (`entries['B']`
108
- * is a number) but zod accepts `'B'`. Reading zod's set makes what we document
109
- * what zod parses, by construction. The `entries` fallback (values unfiltered)
110
- * only runs if a future zod 4.x stops exposing the set.
111
- */
112
- declare function enumValues(schema: ZodSchemaLike): Array<string | number>;
113
- /** A literal's values — always the `_def.values` array in zod 4, which may hold more than one. */
114
- declare function literalValues(def: Record<string, unknown>): unknown[];
115
- /**
116
- * Wrappers that neither add to a rendered type nor decide whether a field may
117
- * be omitted — whatever they wrap answers both questions. (`lazy` is here for
118
- * membership only: its child hides behind `_def.getter`, which no walker
119
- * calls, so looking through it reads as "contents unavailable" rather than
120
- * "unsupported type".)
121
- */
122
- declare const TRANSPARENT_WRAPPERS: ReadonlySet<string>;
123
- /**
124
- * Wrappers that pass their type through but *do* decide presence: each makes a
125
- * field omissible, or (in `nonoptional`'s case) re-requires one.
126
- */
127
- declare const PRESENCE_WRAPPERS: ReadonlySet<string>;
128
- /**
129
- * Every type name that carries exactly one nested schema and no shape of its
130
- * own — the union of the two sets above plus the two that render specially
131
- * (`nullable` becomes a union with null; a pipe holds one schema per side).
132
- *
133
- * This is the vocabulary, not a policy: callers partition it however their
134
- * rendering needs (the CLI splits transparent from presence-deciding because
135
- * it walks types and presence separately; the OpenAPI walker looks through all
136
- * of them uniformly). What none of them may do is disagree about *membership*
137
- * — a name known to one walker and not the other silently changes an output,
138
- * which is why the list lives here rather than once per package.
139
- */
140
- declare const SINGLE_CHILD_WRAPPERS: ReadonlySet<string>;
141
- //#endregion
142
- export { PRESENCE_WRAPPERS, SINGLE_CHILD_WRAPPERS, SchemaIo, TRANSPARENT_WRAPPERS, ZOD3_UNSUPPORTED_MESSAGE, ZodSchemaLike, arrayElement, enumValues, getTypeName, innerSchema, isTransform, isZod3Schema, literalValues, objectShape, pipeSide, pipeSides, recordValueType, schemaAt, typeOf };
1
+ export * from "@guren/server/internal/zod-compat";
@@ -1,141 +1,2 @@
1
- //#region src/internal/zod-compat.ts
2
- /**
3
- * Whether this node was authored with the zod 3 API. Only v3 sets
4
- * `_def.typeName` (`"ZodString"`), so its presence is the discriminator —
5
- * checked before any other read, because on a v3 node `_def.type` holds a
6
- * nested *schema* and every v4-shaped read below would misfire on it.
7
- */
8
- function isZod3Schema(schema) {
9
- return typeof schema._def?.typeName === "string";
10
- }
11
- /**
12
- * The one refusal message, stated once so the CLI's console warning and the
13
- * OpenAPI document's warnings array cannot drift apart.
14
- */
15
- const ZOD3_UNSUPPORTED_MESSAGE = "this schema was authored with the zod v3 API (zod@3 or the zod/v3 subpath), which Guren does not support. Rewrite it with the zod 4 API (`import { z } from 'zod'`).";
16
- /** The node's type name: `_def.type` (`"string"`, `"object"`, …) or the schema's own `.type`. */
17
- function getTypeName(schema) {
18
- const name = schema._def?.type ?? schema.type;
19
- return typeof name === "string" ? name : void 0;
20
- }
21
- /** `getTypeName` with `'unknown'` for a node that has no readable name. */
22
- function typeOf(schema) {
23
- return getTypeName(schema) ?? "unknown";
24
- }
25
- /**
26
- * The schema at `def[key]`, if it actually holds one. The object check is
27
- * load-bearing: `_def` is untyped data from someone else's package, and a key
28
- * holding a string or function must read as absent, not as a schema. (The
29
- * v3-era version of this helper took a key *list* and returned the first
30
- * match; with one dialect there is no precedence left to encode.)
31
- */
32
- function schemaAt(def, key) {
33
- const candidate = def[key];
34
- return candidate && typeof candidate === "object" ? candidate : void 0;
35
- }
36
- /** The schema wrapped by a single-child wrapper (`.optional()`, `.readonly()`, `.catch()`, …) — always `_def.innerType` in zod 4. */
37
- function innerSchema(def) {
38
- return schemaAt(def, "innerType");
39
- }
40
- /** An array's element schema — `_def.element`, never `_def.type`, which holds the string `'array'`. */
41
- function arrayElement(def) {
42
- return schemaAt(def, "element");
43
- }
44
- /** A record's value schema — `_def.valueType`. */
45
- function recordValueType(def) {
46
- return schemaAt(def, "valueType");
47
- }
48
- /**
49
- * Whether this node is a `.transform()`'s output half — a wrapped function
50
- * with no type to read, as opposed to a schema that genuinely parses to
51
- * `unknown`.
52
- */
53
- function isTransform(schema) {
54
- return typeOf(schema) === "transform";
55
- }
56
- /**
57
- * Both halves of a `.pipe()`. Zod 4 uses one `pipe` node for both `.pipe()`
58
- * and `.transform()`: `_def.in` is what a caller sends, `_def.out` what a
59
- * controller receives — except for a transform, whose out side is the
60
- * transform function itself and so has no type to read. `to` is therefore
61
- * absent for a transform, leaving `from` as the only readable answer.
62
- */
63
- function pipeSides(def) {
64
- const to = schemaAt(def, "out");
65
- return {
66
- from: schemaAt(def, "in"),
67
- to: to && !isTransform(to) ? to : void 0
68
- };
69
- }
70
- /** The one side of a `.pipe()` that describes the `io` direction being rendered. */
71
- function pipeSide(def, io) {
72
- const { from, to } = pipeSides(def);
73
- return io === "output" && to ? to : from;
74
- }
75
- /** An object's property map — `_def.shape`, or the schema's own `.shape`. */
76
- function objectShape(schema) {
77
- return (schema._def ?? {}).shape ?? schema.shape;
78
- }
79
- /**
80
- * An enum's accepted values, read from zod's own computed set at
81
- * `_zod.values` rather than re-derived from `_def.entries`. The distinction
82
- * matters because `z.nativeEnum` produces the same node and a real TypeScript
83
- * numeric enum's runtime object carries reverse mappings (`{ A: 0, '0': 'A' }`)
84
- * — and any hand-rolled filter for those has a false positive: in
85
- * `{ A: 'B', B: 1 }`, the key `A` *looks* like a reverse entry (`entries['B']`
86
- * is a number) but zod accepts `'B'`. Reading zod's set makes what we document
87
- * what zod parses, by construction. The `entries` fallback (values unfiltered)
88
- * only runs if a future zod 4.x stops exposing the set.
89
- */
90
- function enumValues(schema) {
91
- const values = schema._zod?.values;
92
- if (values) return [...values].filter((value) => typeof value === "string" || typeof value === "number");
93
- const entries = schema._def?.entries;
94
- return entries ? Object.values(entries) : [];
95
- }
96
- /** A literal's values — always the `_def.values` array in zod 4, which may hold more than one. */
97
- function literalValues(def) {
98
- return Array.isArray(def.values) ? def.values : [];
99
- }
100
- /**
101
- * Wrappers that neither add to a rendered type nor decide whether a field may
102
- * be omitted — whatever they wrap answers both questions. (`lazy` is here for
103
- * membership only: its child hides behind `_def.getter`, which no walker
104
- * calls, so looking through it reads as "contents unavailable" rather than
105
- * "unsupported type".)
106
- */
107
- const TRANSPARENT_WRAPPERS = /* @__PURE__ */ new Set([
108
- "catch",
109
- "readonly",
110
- "lazy"
111
- ]);
112
- /**
113
- * Wrappers that pass their type through but *do* decide presence: each makes a
114
- * field omissible, or (in `nonoptional`'s case) re-requires one.
115
- */
116
- const PRESENCE_WRAPPERS = /* @__PURE__ */ new Set([
117
- "optional",
118
- "default",
119
- "prefault",
120
- "nonoptional"
121
- ]);
122
- /**
123
- * Every type name that carries exactly one nested schema and no shape of its
124
- * own — the union of the two sets above plus the two that render specially
125
- * (`nullable` becomes a union with null; a pipe holds one schema per side).
126
- *
127
- * This is the vocabulary, not a policy: callers partition it however their
128
- * rendering needs (the CLI splits transparent from presence-deciding because
129
- * it walks types and presence separately; the OpenAPI walker looks through all
130
- * of them uniformly). What none of them may do is disagree about *membership*
131
- * — a name known to one walker and not the other silently changes an output,
132
- * which is why the list lives here rather than once per package.
133
- */
134
- const SINGLE_CHILD_WRAPPERS = /* @__PURE__ */ new Set([
135
- ...TRANSPARENT_WRAPPERS,
136
- ...PRESENCE_WRAPPERS,
137
- "nullable",
138
- "pipe"
139
- ]);
140
- //#endregion
141
- export { PRESENCE_WRAPPERS, SINGLE_CHILD_WRAPPERS, TRANSPARENT_WRAPPERS, ZOD3_UNSUPPORTED_MESSAGE, arrayElement, enumValues, getTypeName, innerSchema, isTransform, isZod3Schema, literalValues, objectShape, pipeSide, pipeSides, recordValueType, schemaAt, typeOf };
1
+ export * from "@guren/server/internal/zod-compat";
2
+ export {};
@@ -0,0 +1 @@
1
+ export * from "@guren/server/internal/zod-json-schema";
@@ -0,0 +1,2 @@
1
+ export * from "@guren/server/internal/zod-json-schema";
2
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/core",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "./src/bin.ts",
@@ -49,10 +49,18 @@
49
49
  "types": "./dist/internal/deploy-build.d.ts",
50
50
  "default": "./dist/internal/deploy-build.js"
51
51
  },
52
+ "./internal/route-path": {
53
+ "types": "./dist/internal/route-path.d.ts",
54
+ "default": "./dist/internal/route-path.js"
55
+ },
52
56
  "./internal/zod-compat": {
53
57
  "types": "./dist/internal/zod-compat.d.ts",
54
58
  "default": "./dist/internal/zod-compat.js"
55
59
  },
60
+ "./internal/zod-json-schema": {
61
+ "types": "./dist/internal/zod-json-schema.d.ts",
62
+ "default": "./dist/internal/zod-json-schema.js"
63
+ },
56
64
  "./jsx-runtime": {
57
65
  "types": "./dist/jsx-runtime.d.ts",
58
66
  "default": "./dist/jsx-runtime.js"
@@ -72,9 +80,9 @@
72
80
  "typecheck": "tsc --noEmit"
73
81
  },
74
82
  "dependencies": {
75
- "@guren/cli": "^2.12.0",
83
+ "@guren/cli": "^2.13.0",
76
84
  "@guren/orm": "^2.6.1",
77
- "@guren/server": "^2.13.0"
85
+ "@guren/server": "^2.14.0"
78
86
  },
79
87
  "devDependencies": {
80
88
  "@types/node": "^20.14.10",