Skip to content

Commit 6156182

Browse files
committed
chore: remove router options
1 parent 3663649 commit 6156182

5 files changed

Lines changed: 5 additions & 344 deletions

File tree

dev/typescript/presets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const presets = {
3434
/** RPC-style SDK with Zod validation */
3535
{
3636
contracts: {
37-
// containerName: 'contract',
37+
containerName: 'contracted',
3838
strategy: 'single',
3939
},
4040
name: '@orpc/contract',

packages/openapi-ts/src/plugins/@orpc/contract/config.ts

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,20 @@
11
import { log } from '@hey-api/codegen-core';
2-
import type { OperationsStrategy, PluginContext } from '@hey-api/shared';
3-
import { definePluginConfig, resolveNaming } from '@hey-api/shared';
2+
import { definePluginConfig } from '@hey-api/shared';
43

54
import { resolveContracts } from './contracts/config';
65
import { handler } from './plugin';
7-
import type { OrpcContractPlugin, RouterConfig, UserRouterConfig } from './types';
6+
import type { OrpcContractPlugin } from './types';
87

98
const validatorInferWarn =
109
'You set `validator: true` but no validator plugin was found in your plugins. Add a validator plugin like `zod` to enable this feature. The validator option has been disabled.';
1110

12-
function resolveRouter(
13-
input: OperationsStrategy | UserRouterConfig | undefined,
14-
context: PluginContext,
15-
): RouterConfig {
16-
if (!input || typeof input === 'string' || typeof input === 'function') {
17-
input = { strategy: input };
18-
}
19-
20-
const strategy = input.strategy ?? 'flat';
21-
22-
return context.valueToObject({
23-
defaultValue: {
24-
nesting: 'operationId',
25-
nestingDelimiters: /[./]/,
26-
strategy,
27-
strategyDefaultTag: 'default',
28-
},
29-
mappers: {
30-
object(value) {
31-
value.methodName = context.valueToObject({
32-
defaultValue: { casing: 'camelCase' },
33-
mappers: {
34-
function: (name) => ({ name }),
35-
string: (name) => ({ name }),
36-
},
37-
value: value.methodName,
38-
});
39-
value.segmentName = context.valueToObject({
40-
defaultValue: { casing: 'camelCase' },
41-
mappers: {
42-
function: (name) => ({ name }),
43-
string: (name) => ({ name }),
44-
},
45-
value: value.segmentName,
46-
});
47-
return value;
48-
},
49-
},
50-
value: input,
51-
}) as RouterConfig;
52-
}
53-
5411
export const defaultConfig: OrpcContractPlugin['Config'] = {
5512
config: {
5613
includeInEntry: false,
57-
router: {
58-
methodName: { casing: 'camelCase' },
59-
nesting: 'operationId',
60-
nestingDelimiters: /[./]/,
61-
segmentName: { casing: 'camelCase' },
62-
strategy: 'flat',
63-
strategyDefaultTag: 'default',
64-
},
65-
routerName: { name: 'router' },
6614
},
6715
handler,
6816
name: '@orpc/contract',
6917
resolveConfig: (plugin, context) => {
70-
plugin.config.router = resolveRouter(plugin.config.router, context);
71-
plugin.config.routerName = resolveNaming(plugin.config.routerName);
72-
if (!plugin.config.routerName.name) {
73-
plugin.config.routerName.name = 'router';
74-
}
75-
7618
if (typeof plugin.config.validator !== 'object') {
7719
plugin.config.validator = {
7820
input: plugin.config.validator,
Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import type { IR } from '@hey-api/shared';
2-
import { OperationPath, OperationStrategy } from '@hey-api/shared';
3-
4-
import type { RouterConfig } from '../types';
52

63
export function hasInput(operation: IR.OperationObject): boolean {
74
const hasPathParams = Boolean(
@@ -39,39 +36,3 @@ export function getSuccessResponse(
3936
export function getTags(operation: IR.OperationObject, defaultTag: string): ReadonlyArray<string> {
4037
return operation.tags && operation.tags.length > 0 ? [...operation.tags] : [defaultTag];
4138
}
42-
43-
export function getOperationPaths(
44-
operation: IR.OperationObject,
45-
routerConfig: RouterConfig,
46-
): ReadonlyArray<ReadonlyArray<string>> {
47-
const { nesting, nestingDelimiters, strategy, strategyDefaultTag } = routerConfig;
48-
49-
// Get path derivation function
50-
let pathFn = OperationPath.id();
51-
if (typeof nesting === 'function') {
52-
pathFn = nesting;
53-
} else if (nesting === 'operationId') {
54-
pathFn = OperationPath.fromOperationId({ delimiters: nestingDelimiters });
55-
}
56-
57-
// Get structure strategy function
58-
let strategyFn;
59-
if (typeof strategy === 'function') {
60-
strategyFn = strategy;
61-
} else if (strategy === 'byTags') {
62-
strategyFn = OperationStrategy.byTags({
63-
fallback: strategyDefaultTag,
64-
path: pathFn,
65-
});
66-
} else if (strategy === 'single') {
67-
strategyFn = OperationStrategy.single({
68-
path: pathFn,
69-
root: strategyDefaultTag,
70-
});
71-
} else {
72-
// flat
73-
strategyFn = OperationStrategy.flat({ path: pathFn });
74-
}
75-
76-
return strategyFn(operation);
77-
}

packages/openapi-ts/src/plugins/@orpc/contract/types.d.ts

Lines changed: 1 addition & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,8 @@
1-
import type {
2-
// Casing,
3-
DefinePlugin,
4-
// FeatureToggle,
5-
// IR,
6-
// NameTransformer,
7-
// NamingOptions,
8-
NamingConfig,
9-
NamingRule,
10-
OperationPathStrategy,
11-
OperationsStrategy,
12-
Plugin,
13-
} from '@hey-api/shared';
1+
import type { DefinePlugin, OperationsStrategy, Plugin } from '@hey-api/shared';
142

153
import type { PluginValidatorNames } from '../../types';
164
import type { ContractsConfig, UserContractsConfig } from './contracts/types';
175

18-
export interface UserRouterConfig {
19-
/**
20-
* Customize method/key names for operations in the router.
21-
*
22-
* Applied to the final segment of the path.
23-
*/
24-
methodName?: NamingRule;
25-
/**
26-
* How to derive nesting structure from operations.
27-
*
28-
* - `'operationId'` - Split operationId by delimiters (e.g., `users.list` → `{ users: { list } }`)
29-
* - `'id'` - Use operation id as-is, no nesting
30-
* - Custom function for full control
31-
*
32-
* @default 'operationId'
33-
*/
34-
nesting?: 'id' | 'operationId' | OperationPathStrategy;
35-
/**
36-
* Delimiters for splitting operationId.
37-
*
38-
* Only applies when `nesting` is `'operationId'`.
39-
*
40-
* @default /[./]/
41-
*/
42-
nestingDelimiters?: RegExp;
43-
/**
44-
* Customize segment names for nested groups.
45-
*
46-
* Applied to intermediate path segments (not the key name).
47-
*/
48-
segmentName?: NamingRule;
49-
/**
50-
* Grouping strategy.
51-
*
52-
* - `'flat'` - No grouping, all contracts at root level
53-
* - `'byTags'` - One group per operation tag
54-
* - `'single'` - All operations in one group
55-
* - Custom function for full control
56-
*
57-
* @default 'flat'
58-
*/
59-
strategy?: OperationsStrategy;
60-
/**
61-
* Default group name for operations without tags.
62-
*
63-
* Only applies when `strategy` is `'byTags'`.
64-
*
65-
* @default 'default'
66-
*/
67-
strategyDefaultTag?: string;
68-
}
69-
70-
export interface RouterConfig {
71-
/**
72-
* Customize method/key names for operations in the router.
73-
*
74-
* Applied to the final segment of the path.
75-
*/
76-
methodName: NamingConfig;
77-
/**
78-
* How to derive nesting structure from operations.
79-
*
80-
* - `'operationId'` - Split operationId by delimiters (e.g., `users.list` → `{ users: { list } }`)
81-
* - `'id'` - Use operation id as-is, no nesting
82-
* - Custom function for full control
83-
*/
84-
nesting: 'id' | 'operationId' | OperationPathStrategy;
85-
/**
86-
* Delimiters for splitting operationId.
87-
*
88-
* Only applies when `nesting` is `'operationId'`.
89-
*/
90-
nestingDelimiters: RegExp;
91-
/**
92-
* Customize segment names for nested groups.
93-
*
94-
* Applied to intermediate path segments (not the key name).
95-
*/
96-
segmentName: NamingConfig;
97-
/**
98-
* Grouping strategy.
99-
*
100-
* - `'flat'` - No grouping, all contracts at root level
101-
* - `'byTags'` - One group per operation tag
102-
* - `'single'` - All operations in one group
103-
* - Custom function for full control
104-
*/
105-
strategy: OperationsStrategy;
106-
/**
107-
* Default group name for operations without tags.
108-
*
109-
* Only applies when `strategy` is `'byTags'`.
110-
*/
111-
strategyDefaultTag: string;
112-
}
113-
1146
export type UserConfig = Plugin.Name<'@orpc/contract'> &
1157
Plugin.Hooks &
1168
Plugin.UserExports & {
@@ -128,46 +20,6 @@ export type UserConfig = Plugin.Name<'@orpc/contract'> &
12820
* @default 'flat'
12921
*/
13022
contracts?: OperationsStrategy | UserContractsConfig;
131-
/**
132-
* Router configuration for grouping and nesting operations.
133-
*
134-
* Can be a strategy string for simple cases, or an object for full control.
135-
*
136-
* @default { strategy: 'flat' }
137-
*
138-
* @example
139-
* // Simple: just set strategy
140-
* router: 'byTags'
141-
*
142-
* @example
143-
* // Full control
144-
* router: {
145-
* strategy: 'byTags',
146-
* nesting: 'operationId',
147-
* segmentName: { casing: 'camelCase' },
148-
* methodName: { casing: 'camelCase' },
149-
* }
150-
*/
151-
router?: OperationsStrategy | UserRouterConfig;
152-
/**
153-
* Naming rule for the router export.
154-
* The type export will be the PascalCase version (e.g., 'router' → 'Router').
155-
*
156-
* @default 'router'
157-
*
158-
* @example
159-
* // Simple string
160-
* routerName: 'contract'
161-
*
162-
* @example
163-
* // Template string
164-
* routerName: '{{name}}Contract'
165-
*
166-
* @example
167-
* // With casing
168-
* routerName: { name: '{{name}}Contract', casing: 'camelCase' }
169-
*/
170-
routerName?: NamingRule;
17123
/**
17224
* Validate input/output schemas.
17325
*
@@ -203,8 +55,6 @@ export type Config = Plugin.Name<'@orpc/contract'> &
20355
Plugin.Exports & {
20456
/** Define the structure of generated oRPC contracts. */
20557
contracts: ContractsConfig;
206-
router: RouterConfig;
207-
routerName: NamingConfig;
20858
/** Validate input/output schemas. */
20959
validator: {
21060
/** The validator plugin to use for input schemas. */

0 commit comments

Comments
 (0)