@orpc/contract 0.0.0-next.e9dc36e → 0.0.0-next.eb37cbe
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/index.js +71 -89
- package/dist/src/builder.d.ts +6 -5
- package/dist/src/index.d.ts +2 -2
- package/dist/src/procedure-decorated.d.ts +12 -0
- package/dist/src/procedure.d.ts +16 -36
- package/dist/src/router-builder.d.ts +15 -11
- package/dist/src/router.d.ts +7 -11
- package/dist/src/types.d.ts +4 -5
- package/package.json +13 -14
- package/dist/index.js.map +0 -1
- package/dist/src/builder.d.ts.map +0 -1
- package/dist/src/constants.d.ts +0 -3
- package/dist/src/constants.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/procedure.d.ts.map +0 -1
- package/dist/src/router-builder.d.ts.map +0 -1
- package/dist/src/router.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils.d.ts +0 -4
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/builder.test.ts +0 -179
- package/src/builder.ts +0 -52
- package/src/constants.ts +0 -2
- package/src/index.ts +0 -12
- package/src/procedure.test.ts +0 -99
- package/src/procedure.ts +0 -125
- package/src/router-builder.test.ts +0 -70
- package/src/router-builder.ts +0 -46
- package/src/router.test-d.ts +0 -63
- package/src/router.test.ts +0 -24
- package/src/router.ts +0 -55
- package/src/types.test-d.ts +0 -16
- package/src/types.ts +0 -25
- package/src/utils.test.ts +0 -18
- package/src/utils.ts +0 -17
package/src/router.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { SchemaInput, SchemaOutput } from './types'
|
|
2
|
-
import {
|
|
3
|
-
type ContractProcedure,
|
|
4
|
-
type DecoratedContractProcedure,
|
|
5
|
-
isContractProcedure,
|
|
6
|
-
type WELL_DEFINED_CONTRACT_PROCEDURE,
|
|
7
|
-
} from './procedure'
|
|
8
|
-
|
|
9
|
-
export interface ContractRouter {
|
|
10
|
-
[k: string]: ContractProcedure<any, any> | ContractRouter
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type HandledContractRouter<TContract extends ContractRouter> = {
|
|
14
|
-
[K in keyof TContract]: TContract[K] extends ContractProcedure<
|
|
15
|
-
infer UInputSchema,
|
|
16
|
-
infer UOutputSchema
|
|
17
|
-
>
|
|
18
|
-
? DecoratedContractProcedure<UInputSchema, UOutputSchema>
|
|
19
|
-
: TContract[K] extends ContractRouter
|
|
20
|
-
? HandledContractRouter<TContract[K]>
|
|
21
|
-
: never
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function eachContractRouterLeaf(
|
|
25
|
-
router: ContractRouter,
|
|
26
|
-
callback: (item: WELL_DEFINED_CONTRACT_PROCEDURE, path: string[]) => void,
|
|
27
|
-
prefix: string[] = [],
|
|
28
|
-
) {
|
|
29
|
-
for (const key in router) {
|
|
30
|
-
const item = router[key]
|
|
31
|
-
|
|
32
|
-
if (isContractProcedure(item)) {
|
|
33
|
-
callback(item, [...prefix, key])
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
eachContractRouterLeaf(item as ContractRouter, callback, [...prefix, key])
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type InferContractRouterInputs<T extends ContractRouter> = {
|
|
42
|
-
[K in keyof T]: T[K] extends ContractProcedure<infer UInputSchema, any>
|
|
43
|
-
? SchemaInput<UInputSchema>
|
|
44
|
-
: T[K] extends ContractRouter
|
|
45
|
-
? InferContractRouterInputs<T[K]>
|
|
46
|
-
: never
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export type InferContractRouterOutputs<T extends ContractRouter> = {
|
|
50
|
-
[K in keyof T]: T[K] extends ContractProcedure<any, infer UOutputSchema>
|
|
51
|
-
? SchemaOutput<UOutputSchema>
|
|
52
|
-
: T[K] extends ContractRouter
|
|
53
|
-
? InferContractRouterOutputs<T[K]>
|
|
54
|
-
: never
|
|
55
|
-
}
|
package/src/types.test-d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { SchemaInput, SchemaOutput } from './types'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
|
|
4
|
-
test('SchemaInput', () => {
|
|
5
|
-
const schema = z.string()
|
|
6
|
-
|
|
7
|
-
expectTypeOf<SchemaInput<undefined>>().toEqualTypeOf<unknown>()
|
|
8
|
-
expectTypeOf<SchemaInput<typeof schema>>().toEqualTypeOf<string>()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
test('SchemaOutput', () => {
|
|
12
|
-
const schema = z.string().transform(v => Number.parseFloat(v))
|
|
13
|
-
|
|
14
|
-
expectTypeOf<SchemaOutput<undefined>>().toEqualTypeOf<unknown>()
|
|
15
|
-
expectTypeOf<SchemaOutput<typeof schema>>().toEqualTypeOf<number>()
|
|
16
|
-
})
|
package/src/types.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { input, output, ZodType } from 'zod'
|
|
2
|
-
|
|
3
|
-
export type HTTPPath = `/${string}`
|
|
4
|
-
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
5
|
-
export type HTTPStatus = number
|
|
6
|
-
|
|
7
|
-
export type Schema = ZodType<any, any, any> | undefined
|
|
8
|
-
|
|
9
|
-
export type SchemaInput<
|
|
10
|
-
TSchema extends Schema,
|
|
11
|
-
TFallback = unknown,
|
|
12
|
-
> = TSchema extends undefined
|
|
13
|
-
? TFallback
|
|
14
|
-
: TSchema extends ZodType<any, any, any>
|
|
15
|
-
? input<TSchema>
|
|
16
|
-
: TFallback
|
|
17
|
-
|
|
18
|
-
export type SchemaOutput<
|
|
19
|
-
TSchema extends Schema,
|
|
20
|
-
TFallback = unknown,
|
|
21
|
-
> = TSchema extends undefined
|
|
22
|
-
? TFallback
|
|
23
|
-
: TSchema extends ZodType<any, any, any>
|
|
24
|
-
? output<TSchema>
|
|
25
|
-
: TFallback
|
package/src/utils.test.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { prefixHTTPPath, standardizeHTTPPath } from './utils'
|
|
2
|
-
|
|
3
|
-
it('standardizeHTTPPath', () => {
|
|
4
|
-
expect(standardizeHTTPPath('/abc')).toBe('/abc')
|
|
5
|
-
expect(standardizeHTTPPath('/abc/')).toBe('/abc')
|
|
6
|
-
expect(standardizeHTTPPath('/abc//')).toBe('/abc')
|
|
7
|
-
expect(standardizeHTTPPath('//abc//')).toBe('/abc')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
it('prefixHTTPPath', () => {
|
|
11
|
-
expect(prefixHTTPPath('/', '/abc')).toBe('/abc')
|
|
12
|
-
expect(prefixHTTPPath('/', '/abc/')).toBe('/abc')
|
|
13
|
-
expect(prefixHTTPPath('/', '/abc//')).toBe('/abc')
|
|
14
|
-
expect(prefixHTTPPath('/', '//abc//')).toBe('/abc')
|
|
15
|
-
expect(prefixHTTPPath('/abc', '/abc')).toBe('/abc/abc')
|
|
16
|
-
expect(prefixHTTPPath('/abc', '/abc/')).toBe('/abc/abc')
|
|
17
|
-
expect(prefixHTTPPath('/abc', '/abc//')).toBe('/abc/abc')
|
|
18
|
-
})
|
package/src/utils.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { HTTPPath } from './types'
|
|
2
|
-
|
|
3
|
-
export function standardizeHTTPPath(path: HTTPPath): HTTPPath {
|
|
4
|
-
return `/${path.replace(/\/{2,}/g, '/').replace(/^\/|\/$/g, '')}`
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function prefixHTTPPath(prefix: HTTPPath, path: HTTPPath): HTTPPath {
|
|
8
|
-
const prefix_ = standardizeHTTPPath(prefix)
|
|
9
|
-
const path_ = standardizeHTTPPath(path)
|
|
10
|
-
|
|
11
|
-
if (prefix_ === '/')
|
|
12
|
-
return path_
|
|
13
|
-
if (path_ === '/')
|
|
14
|
-
return prefix_
|
|
15
|
-
|
|
16
|
-
return `${prefix_}${path_}`
|
|
17
|
-
}
|