@orpc/server 0.1.0 → 0.1.2
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/chunk-26DTFWOI.js +200 -0
- package/dist/chunk-26DTFWOI.js.map +1 -0
- package/dist/fetch.js +87 -91
- package/dist/fetch.js.map +1 -1
- package/dist/index.js +6 -9
- package/dist/index.js.map +1 -1
- package/dist/src/adapters/fetch.d.ts +9 -3
- package/dist/src/adapters/fetch.d.ts.map +1 -1
- package/dist/src/builder.d.ts +4 -4
- package/dist/src/builder.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/middleware.d.ts +17 -7
- package/dist/src/middleware.d.ts.map +1 -1
- package/dist/src/procedure-builder.d.ts +4 -4
- package/dist/src/procedure-builder.d.ts.map +1 -1
- package/dist/src/procedure-caller.d.ts +0 -5
- package/dist/src/procedure-caller.d.ts.map +1 -1
- package/dist/src/procedure-implementer.d.ts +4 -5
- package/dist/src/procedure-implementer.d.ts.map +1 -1
- package/dist/src/procedure.d.ts +8 -9
- package/dist/src/procedure.d.ts.map +1 -1
- package/dist/src/router-builder.d.ts +2 -2
- package/dist/src/router-builder.d.ts.map +1 -1
- package/dist/src/router-caller.d.ts +1 -6
- package/dist/src/router-caller.d.ts.map +1 -1
- package/dist/src/router-implementer.d.ts +2 -2
- package/dist/src/router-implementer.d.ts.map +1 -1
- package/dist/src/router.d.ts +1 -1
- package/dist/src/router.d.ts.map +1 -1
- package/dist/src/types.d.ts +1 -10
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils.d.ts +1 -2
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/adapters/fetch.test.ts +32 -17
- package/src/adapters/fetch.ts +134 -123
- package/src/builder.test.ts +48 -39
- package/src/builder.ts +32 -30
- package/src/index.ts +2 -2
- package/src/middleware.test.ts +54 -73
- package/src/middleware.ts +39 -22
- package/src/procedure-builder.test.ts +26 -22
- package/src/procedure-builder.ts +15 -15
- package/src/procedure-caller.test.ts +25 -70
- package/src/procedure-caller.ts +69 -88
- package/src/procedure-implementer.test.ts +27 -22
- package/src/procedure-implementer.ts +16 -17
- package/src/procedure.test.ts +17 -12
- package/src/procedure.ts +46 -45
- package/src/router-builder.test.ts +4 -4
- package/src/router-builder.ts +12 -10
- package/src/router-caller.test.ts +6 -6
- package/src/router-caller.ts +5 -16
- package/src/router-implementer.test.ts +12 -12
- package/src/router-implementer.ts +9 -6
- package/src/router.test.ts +4 -4
- package/src/router.ts +12 -10
- package/src/types.test.ts +1 -1
- package/src/types.ts +1 -15
- package/src/utils.test.ts +2 -229
- package/src/utils.ts +5 -84
- package/dist/chunk-ACLC6USM.js +0 -262
- package/dist/chunk-ACLC6USM.js.map +0 -1
package/src/procedure-builder.ts
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import type { MapInputMiddleware, Middleware } from './middleware'
|
2
|
+
import type { Context, MergeContext } from './types'
|
1
3
|
import {
|
2
4
|
type ContractProcedure,
|
3
5
|
DecoratedContractProcedure,
|
@@ -6,14 +8,12 @@ import {
|
|
6
8
|
type SchemaInput,
|
7
9
|
type SchemaOutput,
|
8
10
|
} from '@orpc/contract'
|
9
|
-
import type { MapInputMiddleware, Middleware } from './middleware'
|
10
11
|
import {
|
11
12
|
type DecoratedProcedure,
|
12
|
-
type ProcedureHandler,
|
13
13
|
decorateProcedure,
|
14
|
+
type ProcedureHandler,
|
14
15
|
} from './procedure'
|
15
16
|
import { ProcedureImplementer } from './procedure-implementer'
|
16
|
-
import type { Context, MergeContext } from './types'
|
17
17
|
|
18
18
|
export class ProcedureBuilder<
|
19
19
|
TContext extends Context,
|
@@ -75,14 +75,14 @@ export class ProcedureBuilder<
|
|
75
75
|
|
76
76
|
use<
|
77
77
|
UExtraContext extends
|
78
|
-
|
79
|
-
|
78
|
+
| Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>>
|
79
|
+
| undefined = undefined,
|
80
80
|
>(
|
81
81
|
middleware: Middleware<
|
82
82
|
MergeContext<TContext, TExtraContext>,
|
83
83
|
UExtraContext,
|
84
84
|
SchemaOutput<TInputSchema>,
|
85
|
-
|
85
|
+
SchemaInput<TOutputSchema>
|
86
86
|
>,
|
87
87
|
): ProcedureImplementer<
|
88
88
|
TContext,
|
@@ -93,15 +93,15 @@ export class ProcedureBuilder<
|
|
93
93
|
|
94
94
|
use<
|
95
95
|
UExtraContext extends
|
96
|
-
|
97
|
-
|
96
|
+
| Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>>
|
97
|
+
| undefined = undefined,
|
98
98
|
UMappedInput = unknown,
|
99
99
|
>(
|
100
100
|
middleware: Middleware<
|
101
101
|
MergeContext<TContext, TExtraContext>,
|
102
102
|
UExtraContext,
|
103
103
|
UMappedInput,
|
104
|
-
|
104
|
+
SchemaInput<TOutputSchema>
|
105
105
|
>,
|
106
106
|
mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UMappedInput>,
|
107
107
|
): ProcedureImplementer<
|
@@ -141,12 +141,12 @@ export class ProcedureBuilder<
|
|
141
141
|
UHandlerOutput
|
142
142
|
>,
|
143
143
|
): DecoratedProcedure<
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
144
|
+
TContext,
|
145
|
+
TExtraContext,
|
146
|
+
TInputSchema,
|
147
|
+
TOutputSchema,
|
148
|
+
UHandlerOutput
|
149
|
+
> {
|
150
150
|
return decorateProcedure({
|
151
151
|
zz$p: {
|
152
152
|
middlewares: this.zz$pb.middlewares,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { z } from 'zod'
|
2
|
-
import {
|
2
|
+
import { createProcedureCaller, os } from '.'
|
3
3
|
|
4
4
|
describe('createProcedureCaller', () => {
|
5
5
|
let internal = false
|
@@ -8,8 +8,8 @@ describe('createProcedureCaller', () => {
|
|
8
8
|
|
9
9
|
const osw = os.context<{ auth?: boolean }>()
|
10
10
|
const procedure = osw
|
11
|
-
.input(z.object({ value: z.string().transform(
|
12
|
-
.output(z.object({ value: z.number().transform(
|
11
|
+
.input(z.object({ value: z.string().transform(v => Number(v)) }))
|
12
|
+
.output(z.object({ value: z.number().transform(v => v.toString()) }))
|
13
13
|
.handler((input, context, meta) => {
|
14
14
|
expect(context).toEqual(context)
|
15
15
|
expect(meta.internal).toBe(internal)
|
@@ -47,7 +47,7 @@ describe('createProcedureCaller', () => {
|
|
47
47
|
|
48
48
|
expect(await caller({ value: '123' })).toEqual({ value: '123' })
|
49
49
|
|
50
|
-
// @ts-expect-error
|
50
|
+
// @ts-expect-error - invalid input
|
51
51
|
expect(caller({ value: {} })).rejects.toThrowError(
|
52
52
|
'Validation input failed',
|
53
53
|
)
|
@@ -101,44 +101,44 @@ describe('createProcedureCaller', () => {
|
|
101
101
|
const ref = { value: 0 }
|
102
102
|
|
103
103
|
const mid1 = vi.fn(
|
104
|
-
osw.middleware((input: { id: string }, context, meta) => {
|
104
|
+
osw.middleware(async (input: { id: string }, context, meta) => {
|
105
105
|
expect(input).toEqual({ id: '1' })
|
106
106
|
|
107
107
|
expect(ref.value).toBe(0)
|
108
108
|
ref.value++
|
109
109
|
|
110
|
-
|
111
|
-
|
110
|
+
try {
|
111
|
+
const result = await meta.next({
|
112
|
+
context: {
|
113
|
+
userId: '1',
|
114
|
+
},
|
115
|
+
})
|
116
|
+
expect(ref.value).toBe(5)
|
112
117
|
ref.value++
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
expect(ref.value).toBe(
|
118
|
+
return result
|
119
|
+
}
|
120
|
+
finally {
|
121
|
+
expect(ref.value).toBe(6)
|
117
122
|
ref.value++
|
118
|
-
})
|
119
|
-
|
120
|
-
return {
|
121
|
-
context: {
|
122
|
-
userId: '1',
|
123
|
-
},
|
124
123
|
}
|
125
124
|
}),
|
126
125
|
)
|
127
126
|
|
128
127
|
const mid2 = vi.fn(
|
129
|
-
osw.middleware((input, context, meta) => {
|
128
|
+
osw.middleware(async (input, context, meta) => {
|
130
129
|
expect(ref.value).toBe(1)
|
131
130
|
ref.value++
|
132
131
|
|
133
|
-
|
134
|
-
|
132
|
+
try {
|
133
|
+
const result = await meta.next({})
|
134
|
+
expect(ref.value).toBe(3)
|
135
135
|
ref.value++
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
expect(ref.value).toBe(
|
136
|
+
return result
|
137
|
+
}
|
138
|
+
finally {
|
139
|
+
expect(ref.value).toBe(4)
|
140
140
|
ref.value++
|
141
|
-
}
|
141
|
+
}
|
142
142
|
}),
|
143
143
|
)
|
144
144
|
|
@@ -152,16 +152,6 @@ describe('createProcedureCaller', () => {
|
|
152
152
|
expect(ref.value).toBe(2)
|
153
153
|
ref.value++
|
154
154
|
|
155
|
-
meta.onSuccess(() => {
|
156
|
-
expect(ref.value).toBe(3)
|
157
|
-
ref.value++
|
158
|
-
})
|
159
|
-
|
160
|
-
meta.onFinish(() => {
|
161
|
-
expect(ref.value).toBe(4)
|
162
|
-
ref.value++
|
163
|
-
})
|
164
|
-
|
165
155
|
return 'pong'
|
166
156
|
})
|
167
157
|
|
@@ -172,39 +162,4 @@ describe('createProcedureCaller', () => {
|
|
172
162
|
|
173
163
|
expect(caller({ id: '1' })).resolves.toEqual('pong')
|
174
164
|
})
|
175
|
-
|
176
|
-
it('hooks', async () => {
|
177
|
-
const ref = { value: 0 }
|
178
|
-
|
179
|
-
const caller = createProcedureCaller({
|
180
|
-
procedure: procedure,
|
181
|
-
context: context,
|
182
|
-
internal: internal,
|
183
|
-
path: path,
|
184
|
-
hooks: (context, meta) => {
|
185
|
-
expect(context).toEqual(context)
|
186
|
-
expect(meta.internal).toBe(internal)
|
187
|
-
expect(meta.path).toBe(path)
|
188
|
-
expect(meta.procedure).toBe(procedure)
|
189
|
-
|
190
|
-
expect(ref.value).toBe(0)
|
191
|
-
ref.value++
|
192
|
-
|
193
|
-
meta.onSuccess(() => {
|
194
|
-
expect(ref.value).toBe(1)
|
195
|
-
ref.value++
|
196
|
-
})
|
197
|
-
|
198
|
-
meta.onFinish(() => {
|
199
|
-
expect(ref.value).toBe(2)
|
200
|
-
ref.value++
|
201
|
-
|
202
|
-
throw new Error('foo')
|
203
|
-
})
|
204
|
-
},
|
205
|
-
})
|
206
|
-
|
207
|
-
await expect(caller({ value: '1243' })).rejects.toThrow('foo')
|
208
|
-
expect(ref.value).toBe(3)
|
209
|
-
})
|
210
165
|
})
|
package/src/procedure-caller.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { SchemaInput, SchemaOutput } from '@orpc/contract'
|
2
|
-
import {
|
3
|
-
import type { Middleware } from './middleware'
|
2
|
+
import type { MiddlewareMeta } from './middleware'
|
4
3
|
import type { Procedure } from './procedure'
|
5
|
-
import type { Context
|
6
|
-
import {
|
4
|
+
import type { Context } from './types'
|
5
|
+
import { ORPCError } from '@orpc/shared/error'
|
6
|
+
import { mergeContext } from './utils'
|
7
7
|
|
8
8
|
export interface CreateProcedureCallerOptions<
|
9
9
|
TProcedure extends Procedure<any, any, any, any, any>,
|
@@ -18,16 +18,6 @@ export interface CreateProcedureCallerOptions<
|
|
18
18
|
? UContext
|
19
19
|
: never
|
20
20
|
|
21
|
-
/**
|
22
|
-
* Helpful hooks to do some logics on specific time.
|
23
|
-
*/
|
24
|
-
hooks?: (
|
25
|
-
context: TProcedure extends Procedure<infer UContext, any, any, any, any>
|
26
|
-
? UContext
|
27
|
-
: never,
|
28
|
-
meta: Meta<unknown>,
|
29
|
-
) => Promisable<void>
|
30
|
-
|
31
21
|
/**
|
32
22
|
* This is helpful for logging and analytics.
|
33
23
|
*/
|
@@ -80,85 +70,76 @@ export function createProcedureCaller<
|
|
80
70
|
const procedure = options.procedure
|
81
71
|
const validate = options.validate ?? true
|
82
72
|
|
83
|
-
const caller = async (input: unknown) => {
|
84
|
-
const
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
input,
|
100
|
-
mergeContext(context, mid?.context),
|
101
|
-
partialMeta,
|
102
|
-
rest,
|
103
|
-
)
|
73
|
+
const caller = async (input: unknown): Promise<unknown> => {
|
74
|
+
const validInput = (() => {
|
75
|
+
if (!validate)
|
76
|
+
return input
|
77
|
+
const schema = procedure.zz$p.contract.zz$cp.InputSchema
|
78
|
+
if (!schema)
|
79
|
+
return input
|
80
|
+
|
81
|
+
try {
|
82
|
+
return schema.parse(input)
|
83
|
+
}
|
84
|
+
catch (e) {
|
85
|
+
throw new ORPCError({
|
86
|
+
message: 'Validation input failed',
|
87
|
+
code: 'BAD_REQUEST',
|
88
|
+
cause: e,
|
104
89
|
})
|
105
90
|
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
91
|
+
})()
|
92
|
+
|
93
|
+
const middlewares = procedure.zz$p.middlewares ?? []
|
94
|
+
let currentMidIndex = 0
|
95
|
+
let currentContext: Context = options.context
|
96
|
+
|
97
|
+
const next: MiddlewareMeta<unknown>['next'] = async (nextOptions) => {
|
98
|
+
const mid = middlewares[currentMidIndex]
|
99
|
+
currentMidIndex += 1
|
100
|
+
currentContext = mergeContext(currentContext, nextOptions.context)
|
101
|
+
|
102
|
+
if (mid) {
|
103
|
+
return await mid(validInput, currentContext, {
|
104
|
+
path,
|
105
|
+
procedure,
|
106
|
+
internal,
|
107
|
+
next,
|
108
|
+
output: output => ({ output, context: undefined }),
|
111
109
|
})
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
})
|
124
|
-
return result.data
|
125
|
-
})()
|
126
|
-
|
127
|
-
return validOutput
|
128
|
-
})
|
110
|
+
}
|
111
|
+
else {
|
112
|
+
return {
|
113
|
+
output: await await procedure.zz$p.handler(validInput, currentContext, {
|
114
|
+
path,
|
115
|
+
procedure,
|
116
|
+
internal,
|
117
|
+
}),
|
118
|
+
context: currentContext,
|
119
|
+
}
|
120
|
+
}
|
129
121
|
}
|
130
122
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
const
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
})
|
152
|
-
}
|
153
|
-
})()
|
154
|
-
|
155
|
-
return await handler(
|
156
|
-
validInput,
|
157
|
-
options.context,
|
158
|
-
{ path, procedure, internal },
|
159
|
-
procedure.zz$p.middlewares ?? [],
|
160
|
-
)
|
161
|
-
})
|
123
|
+
const output = (await next({})).output
|
124
|
+
|
125
|
+
const validOutput = await (async () => {
|
126
|
+
if (!validate)
|
127
|
+
return output
|
128
|
+
const schema = procedure.zz$p.contract.zz$cp.OutputSchema
|
129
|
+
if (!schema)
|
130
|
+
return output
|
131
|
+
const result = await schema.safeParseAsync(output)
|
132
|
+
if (result.error) {
|
133
|
+
throw new ORPCError({
|
134
|
+
message: 'Validation output failed',
|
135
|
+
code: 'INTERNAL_SERVER_ERROR',
|
136
|
+
cause: result.error,
|
137
|
+
})
|
138
|
+
}
|
139
|
+
return result.data
|
140
|
+
})()
|
141
|
+
|
142
|
+
return validOutput
|
162
143
|
}
|
163
144
|
|
164
145
|
return caller as ProcedureCaller<TProcedure, TValidate>
|
@@ -1,6 +1,7 @@
|
|
1
|
+
import type { DecoratedProcedure, Meta, MiddlewareMeta } from '.'
|
1
2
|
import { DecoratedContractProcedure } from '@orpc/contract'
|
2
3
|
import { z } from 'zod'
|
3
|
-
import {
|
4
|
+
import { isProcedure, os } from '.'
|
4
5
|
import { ProcedureImplementer } from './procedure-implementer'
|
5
6
|
|
6
7
|
const p1 = new DecoratedContractProcedure({
|
@@ -39,20 +40,22 @@ describe('use middleware', () => {
|
|
39
40
|
.use((input, context, meta) => {
|
40
41
|
expectTypeOf(input).toEqualTypeOf<unknown>()
|
41
42
|
expectTypeOf(context).toEqualTypeOf<{ auth: boolean }>()
|
42
|
-
expectTypeOf(meta).toEqualTypeOf<
|
43
|
+
expectTypeOf(meta).toEqualTypeOf<MiddlewareMeta<unknown>>()
|
43
44
|
|
44
|
-
return {
|
45
|
+
return meta.next({
|
45
46
|
context: {
|
46
47
|
userId: '1',
|
47
48
|
},
|
48
|
-
}
|
49
|
+
})
|
49
50
|
})
|
50
51
|
.use((input, context, meta) => {
|
51
52
|
expectTypeOf(input).toEqualTypeOf<unknown>()
|
52
53
|
expectTypeOf(context).toEqualTypeOf<
|
53
54
|
{ userId: string } & { auth: boolean }
|
54
55
|
>()
|
55
|
-
expectTypeOf(meta).toEqualTypeOf<
|
56
|
+
expectTypeOf(meta).toEqualTypeOf<MiddlewareMeta<unknown>>()
|
57
|
+
|
58
|
+
return meta.next({})
|
56
59
|
})
|
57
60
|
|
58
61
|
expectTypeOf(i).toEqualTypeOf<
|
@@ -72,27 +75,27 @@ describe('use middleware', () => {
|
|
72
75
|
})
|
73
76
|
|
74
77
|
implementer2.use(
|
75
|
-
(input: { postId: string }) => {
|
76
|
-
return { context: { a: 'a' } }
|
78
|
+
(input: { postId: string }, _, meta) => {
|
79
|
+
return meta.next({ context: { a: 'a' } })
|
77
80
|
},
|
78
81
|
// @ts-expect-error mismatch input
|
79
|
-
|
82
|
+
input => ({ postId: 12455 }),
|
80
83
|
)
|
81
84
|
|
82
85
|
implementer2.use(
|
83
|
-
(input: { postId: string }) => {},
|
84
|
-
|
86
|
+
(input: { postId: string }, context, meta) => meta.next({}),
|
87
|
+
input => ({ postId: '12455' }),
|
85
88
|
)
|
86
89
|
|
87
90
|
const i = implementer2.use(
|
88
|
-
(input: { id: number }) => {
|
89
|
-
return {
|
91
|
+
(input: { id: number }, _, meta) => {
|
92
|
+
return meta.next({
|
90
93
|
context: {
|
91
94
|
userIdd: '1',
|
92
95
|
},
|
93
|
-
}
|
96
|
+
})
|
94
97
|
},
|
95
|
-
|
98
|
+
input => ({ id: Number.parseInt(input.id) }),
|
96
99
|
)
|
97
100
|
|
98
101
|
expectTypeOf(i).toEqualTypeOf<
|
@@ -142,7 +145,7 @@ describe('handler', () => {
|
|
142
145
|
const handler = implementer1.handler((input, context, meta) => {
|
143
146
|
expectTypeOf(input).toEqualTypeOf<unknown>()
|
144
147
|
expectTypeOf(context).toEqualTypeOf<{ auth: boolean }>()
|
145
|
-
expectTypeOf(meta).toEqualTypeOf<Meta
|
148
|
+
expectTypeOf(meta).toEqualTypeOf<Meta>()
|
146
149
|
|
147
150
|
return {
|
148
151
|
name: 'unnoq',
|
@@ -163,7 +166,7 @@ describe('handler', () => {
|
|
163
166
|
implementer2.handler((input, context, meta) => {
|
164
167
|
expectTypeOf(input).toEqualTypeOf<{ id: string }>()
|
165
168
|
expectTypeOf(context).toEqualTypeOf<{ auth: boolean }>()
|
166
|
-
expectTypeOf(meta).toEqualTypeOf<Meta
|
169
|
+
expectTypeOf(meta).toEqualTypeOf<Meta>()
|
167
170
|
|
168
171
|
return {
|
169
172
|
name: 'unnoq',
|
@@ -175,15 +178,17 @@ describe('handler', () => {
|
|
175
178
|
})
|
176
179
|
|
177
180
|
it('combine middlewares', () => {
|
178
|
-
const mid1 = () => {
|
179
|
-
return {
|
181
|
+
const mid1 = os.middleware((input, context, meta) => {
|
182
|
+
return meta.next({
|
180
183
|
context: {
|
181
184
|
userId: '1',
|
182
185
|
},
|
183
|
-
}
|
184
|
-
}
|
186
|
+
})
|
187
|
+
})
|
185
188
|
|
186
|
-
const mid2 = () => {
|
189
|
+
const mid2 = os.middleware((input, context, meta) => {
|
190
|
+
return meta.next({ })
|
191
|
+
})
|
187
192
|
|
188
193
|
const handler = implementer2
|
189
194
|
.use(mid1)
|
@@ -193,7 +198,7 @@ describe('handler', () => {
|
|
193
198
|
expectTypeOf(context).toEqualTypeOf<
|
194
199
|
{ auth: boolean } & { userId: string }
|
195
200
|
>()
|
196
|
-
expectTypeOf(meta).toEqualTypeOf<Meta
|
201
|
+
expectTypeOf(meta).toEqualTypeOf<Meta>()
|
197
202
|
|
198
203
|
return {
|
199
204
|
name: 'unnoq',
|
@@ -1,16 +1,15 @@
|
|
1
|
-
import type { ContractProcedure, SchemaOutput } from '@orpc/contract'
|
2
|
-
import type {
|
1
|
+
import type { ContractProcedure, Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
|
2
|
+
import type { Context, MergeContext } from './types'
|
3
3
|
import {
|
4
|
+
decorateMiddleware,
|
4
5
|
type MapInputMiddleware,
|
5
6
|
type Middleware,
|
6
|
-
decorateMiddleware,
|
7
7
|
} from './middleware'
|
8
8
|
import {
|
9
9
|
type DecoratedProcedure,
|
10
|
-
type ProcedureHandler,
|
11
10
|
decorateProcedure,
|
11
|
+
type ProcedureHandler,
|
12
12
|
} from './procedure'
|
13
|
-
import type { Context, MergeContext } from './types'
|
14
13
|
|
15
14
|
export class ProcedureImplementer<
|
16
15
|
TContext extends Context,
|
@@ -27,14 +26,14 @@ export class ProcedureImplementer<
|
|
27
26
|
|
28
27
|
use<
|
29
28
|
UExtraContext extends
|
30
|
-
|
31
|
-
|
29
|
+
| Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>>
|
30
|
+
| undefined = undefined,
|
32
31
|
>(
|
33
32
|
middleware: Middleware<
|
34
33
|
MergeContext<TContext, TExtraContext>,
|
35
34
|
UExtraContext,
|
36
35
|
SchemaOutput<TInputSchema>,
|
37
|
-
|
36
|
+
SchemaInput<TOutputSchema>
|
38
37
|
>,
|
39
38
|
): ProcedureImplementer<
|
40
39
|
TContext,
|
@@ -45,15 +44,15 @@ export class ProcedureImplementer<
|
|
45
44
|
|
46
45
|
use<
|
47
46
|
UExtraContext extends
|
48
|
-
|
49
|
-
|
47
|
+
| Partial<MergeContext<Context, MergeContext<TContext, TExtraContext>>>
|
48
|
+
| undefined = undefined,
|
50
49
|
UMappedInput = unknown,
|
51
50
|
>(
|
52
51
|
middleware: Middleware<
|
53
52
|
MergeContext<TContext, TExtraContext>,
|
54
53
|
UExtraContext,
|
55
54
|
UMappedInput,
|
56
|
-
|
55
|
+
SchemaInput<TOutputSchema>
|
57
56
|
>,
|
58
57
|
mapInput: MapInputMiddleware<SchemaOutput<TInputSchema>, UMappedInput>,
|
59
58
|
): ProcedureImplementer<
|
@@ -86,12 +85,12 @@ export class ProcedureImplementer<
|
|
86
85
|
UHandlerOutput
|
87
86
|
>,
|
88
87
|
): DecoratedProcedure<
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
88
|
+
TContext,
|
89
|
+
TExtraContext,
|
90
|
+
TInputSchema,
|
91
|
+
TOutputSchema,
|
92
|
+
UHandlerOutput
|
93
|
+
> {
|
95
94
|
return decorateProcedure({
|
96
95
|
zz$p: {
|
97
96
|
middlewares: this.zz$pi.middlewares,
|