@veloxts/router 0.6.102 → 0.6.104

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @veloxts/router
2
2
 
3
+ ## 0.6.104
4
+
5
+ ### Patch Changes
6
+
7
+ - feat(client): smart convention-based route inference, eliminate routes.ts
8
+ - Updated dependencies
9
+ - @veloxts/core@0.6.104
10
+ - @veloxts/validation@0.6.104
11
+
12
+ ## 0.6.103
13
+
14
+ ### Patch Changes
15
+
16
+ - chore(deps): upgrade Zod from v3 to v4
17
+ - Updated dependencies
18
+ - @veloxts/core@0.6.103
19
+ - @veloxts/validation@0.6.103
20
+
3
21
  ## 0.6.102
4
22
 
5
23
  ### Patch Changes
@@ -5,34 +5,17 @@
5
5
  *
6
6
  * @module @veloxts/router/openapi/schema-converter
7
7
  */
8
- import type { ZodType } from 'zod';
8
+ import { type ZodType } from 'zod';
9
9
  import type { JSONSchema } from './types.js';
10
10
  /**
11
11
  * Options for Zod to JSON Schema conversion
12
12
  */
13
13
  export interface SchemaConversionOptions {
14
- /**
15
- * Schema name for $ref generation
16
- */
17
- name?: string;
18
14
  /**
19
15
  * Target specification format
20
16
  * @default 'openApi3'
21
17
  */
22
18
  target?: 'jsonSchema7' | 'jsonSchema2019-09' | 'openApi3';
23
- /**
24
- * How to handle $ref references
25
- * - 'none': Inline all definitions (default)
26
- * - 'root': Use $ref at root level
27
- * - 'seen': Use $ref for seen schemas
28
- * @default 'none'
29
- */
30
- refStrategy?: 'none' | 'root' | 'seen';
31
- /**
32
- * Base path for $ref URIs
33
- * @default '#/components/schemas'
34
- */
35
- basePath?: string[];
36
19
  /**
37
20
  * Remove default values from schema
38
21
  * @default false
@@ -5,7 +5,22 @@
5
5
  *
6
6
  * @module @veloxts/router/openapi/schema-converter
7
7
  */
8
- import { zodToJsonSchema } from 'zod-to-json-schema';
8
+ import { z } from 'zod';
9
+ /**
10
+ * Maps our target names to Zod 4's native `z.toJSONSchema()` target names.
11
+ *
12
+ * | Our name | Zod 4 target | Notes |
13
+ * |----------------------|------------------|-----------------------------------------------|
14
+ * | `openApi3` | `openapi-3.0` | Default for OpenAPI spec generation |
15
+ * | `jsonSchema7` | `draft-07` | JSON Schema Draft 07 |
16
+ * | `jsonSchema2019-09` | `draft-2020-12` | Zod 4 has no 2019-09 target; 2020-12 is the |
17
+ * | | | closest superset and is forwards-compatible |
18
+ */
19
+ const TARGET_MAP = {
20
+ openApi3: 'openapi-3.0',
21
+ jsonSchema7: 'draft-07',
22
+ 'jsonSchema2019-09': 'draft-2020-12',
23
+ };
9
24
  /**
10
25
  * Converts a Zod schema to JSON Schema format for OpenAPI
11
26
  *
@@ -37,16 +52,12 @@ export function zodSchemaToJsonSchema(schema, options = {}) {
37
52
  if (!schema) {
38
53
  return undefined;
39
54
  }
40
- const { name, target = 'openApi3', refStrategy = 'none', basePath = ['components', 'schemas'], removeDefaults = false, } = options;
55
+ const { target = 'openApi3', removeDefaults = false } = options;
41
56
  try {
42
- // Cast needed because zod-to-json-schema types don't include all options we use
43
- const result = zodToJsonSchema(schema, {
44
- name,
45
- target,
46
- $refStrategy: refStrategy,
47
- basePath,
48
- // OpenAPI 3.0 doesn't support $schema
49
- removeAdditionalStrategy: 'passthrough',
57
+ const result = z.toJSONSchema(schema, {
58
+ target: TARGET_MAP[target] ?? 'openapi-3.0',
59
+ unrepresentable: 'any',
60
+ reused: 'inline',
50
61
  });
51
62
  // Clean up the schema for OpenAPI compatibility
52
63
  const cleaned = cleanJsonSchema(result, { removeDefaults });
@@ -10,7 +10,7 @@
10
10
  * @module procedure/types
11
11
  */
12
12
  import type { BaseContext } from '@veloxts/core';
13
- import type { ZodType, ZodTypeDef } from 'zod';
13
+ import type { ZodType } from 'zod';
14
14
  import type { OutputForTag, ResourceSchema, TaggedResourceSchema } from '../resource/index.js';
15
15
  import type { ContextTag, ExtractTag, LevelToTag, TaggedContext } from '../resource/tags.js';
16
16
  import type { CompiledProcedure, GuardLike, MiddlewareFunction, ParentResourceConfig, ProcedureHandler, RestRouteOverride } from '../types.js';
@@ -35,16 +35,21 @@ export interface ProcedureBuilderState<TInput = unknown, TOutput = unknown, TCon
35
35
  /**
36
36
  * Constraint for valid input/output schemas
37
37
  *
38
- * Accepts any Zod schema type. The generic parameters allow us to
39
- * extract the inferred type for state accumulation.
38
+ * Uses ZodType without version-specific generics for compatibility with
39
+ * both Zod 3 (ZodType<Output, Def, Input>) and Zod 4 (ZodType<Output, Input, Internals>).
40
+ * The actual output type is extracted structurally via InferSchemaOutput.
40
41
  */
41
- export type ValidSchema<T = unknown> = ZodType<T, ZodTypeDef, unknown>;
42
+ export type ValidSchema = ZodType;
42
43
  /**
43
44
  * Extracts the output type from a Zod schema
44
45
  *
45
- * This is used internally to update builder state when .input() or .output() is called.
46
+ * Uses structural matching on the parse method return type instead of
47
+ * ZodType generic parameters. This works across Zod versions since
48
+ * all Zod schemas have a parse() method that returns the output type.
46
49
  */
47
- export type InferSchemaOutput<T> = T extends ZodType<infer O, ZodTypeDef, unknown> ? O : never;
50
+ export type InferSchemaOutput<T> = T extends {
51
+ parse: (data: unknown) => infer O;
52
+ } ? O : never;
48
53
  /**
49
54
  * Fluent procedure builder interface
50
55
  *
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @module resource/schema
9
9
  */
10
- import type { ZodType, ZodTypeDef } from 'zod';
10
+ import type { ZodType } from 'zod';
11
11
  import type { AccessLevel, ADMIN, ANONYMOUS, AUTHENTICATED, ContextTag, LevelToTag } from './tags.js';
12
12
  import type { IsVisibleToTag, VisibilityLevel } from './visibility.js';
13
13
  /**
@@ -125,7 +125,9 @@ export declare function isTaggedResourceSchema(value: unknown): value is TaggedR
125
125
  /**
126
126
  * Helper to infer the output type of a Zod schema
127
127
  */
128
- type InferZodOutput<T> = T extends ZodType<infer O, ZodTypeDef, unknown> ? O : never;
128
+ type InferZodOutput<T> = T extends {
129
+ parse: (data: unknown) => infer O;
130
+ } ? O : never;
129
131
  /**
130
132
  * Filters fields by visibility and extracts their types
131
133
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/router",
3
- "version": "0.6.102",
3
+ "version": "0.6.104",
4
4
  "description": "Procedure definitions with tRPC and REST routing for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -39,9 +39,8 @@
39
39
  "dependencies": {
40
40
  "@trpc/server": "11.9.0",
41
41
  "fastify": "5.7.4",
42
- "zod-to-json-schema": "3.25.1",
43
- "@veloxts/validation": "0.6.102",
44
- "@veloxts/core": "0.6.102"
42
+ "@veloxts/validation": "0.6.104",
43
+ "@veloxts/core": "0.6.104"
45
44
  },
46
45
  "devDependencies": {
47
46
  "@vitest/coverage-v8": "4.0.18",
@@ -49,11 +48,11 @@
49
48
  "typescript": "5.9.3",
50
49
  "vite": "7.3.1",
51
50
  "vitest": "4.0.18",
52
- "zod": "3.25.76"
51
+ "zod": "4.3.6"
53
52
  },
54
53
  "peerDependencies": {
55
54
  "fastify": "^5.7.4",
56
- "zod": "^3.25.0"
55
+ "zod": "^4.3.0"
57
56
  },
58
57
  "files": [
59
58
  "dist",