@elysiajs/eden 0.2.0-rc.7 → 0.2.0-rc.9
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/types.d.ts +5 -10
- package/package.json +2 -2
- package/src/types.ts +19 -10
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="bun-types" />
|
|
2
2
|
import type { Elysia, SCHEMA, TypedRoute, IsPathParameter } from 'elysia';
|
|
3
3
|
import type { EdenWS } from '.';
|
|
4
|
+
declare type IsAny<T> = unknown extends T ? [T] extends [object] ? true : false : false;
|
|
4
5
|
export declare type Eden<App extends Elysia<any>> = App['store'] extends {
|
|
5
|
-
[key in typeof SCHEMA]:
|
|
6
|
-
} ?
|
|
6
|
+
[key in typeof SCHEMA]: infer Schema extends Record<string, Record<string, TypedRoute>>;
|
|
7
|
+
} ? IsAny<Elysia> extends true ? 'Please installed Elysia before using Eden' : UnionToIntersection<Schema> : never;
|
|
7
8
|
export interface EdenCall {
|
|
8
9
|
[x: string]: any;
|
|
9
10
|
$fetch?: RequestInit;
|
|
@@ -17,11 +18,7 @@ declare type TypedRouteToParams<Route extends TypedRoute> = (Route['body'] exten
|
|
|
17
18
|
} : {});
|
|
18
19
|
export declare type CreateEden<Server extends Record<string, Record<string, TypedRoute>>, Path extends string = keyof Server extends string ? keyof Server : never, Full extends string = ''> = Path extends `/${infer Start}` ? CreateEden<Server, Start, Path> : Path extends `${infer A}/${infer B}` ? IsPathParameter<A> extends never ? {
|
|
19
20
|
[key in A]: CreateEden<Server, B, Full>;
|
|
20
|
-
} : {
|
|
21
|
-
[x: string]: CreateEden<Server, B, Full>;
|
|
22
|
-
} & {
|
|
23
|
-
$params: `Expected path parameters ':${A}', replace this with any string`;
|
|
24
|
-
} : // Iterate until last string then catch method
|
|
21
|
+
} : Record<string, CreateEden<Server, B, Full>> & Record<`$${A}`, `Expected path parameters ':${A}', replace this with any string`> : // Iterate until last string then catch method
|
|
25
22
|
{
|
|
26
23
|
[key in Path extends '' ? 'index' : Path extends `:${infer params}` ? string : Path | CamelCase<Path>]: Full extends keyof Server ? {
|
|
27
24
|
[key in keyof Server[Full] extends string ? Lowercase<keyof Server[Full]> : keyof Server[Full]]: keyof TypedRouteToParams<Server[Full][key extends string ? Uppercase<key> : key]> extends never ? key extends 'subscribe' ? unknown extends NonNullable<Server[Full][key]['query']> ? (params?: {
|
|
@@ -50,9 +47,7 @@ export declare type CreateEden<Server extends Record<string, Record<string, Type
|
|
|
50
47
|
200: infer ReturnedType;
|
|
51
48
|
} ? ReturnedType : unknown>;
|
|
52
49
|
} : never;
|
|
53
|
-
} & (Path extends `:${infer params}` ? {
|
|
54
|
-
$params: `Expected path parameters ':${params}', replace this with any string`;
|
|
55
|
-
} : {});
|
|
50
|
+
} & (Path extends `:${infer params}` ? Record<`$${params}`, `Expected path parameters ':${params}', replace this with any string`> : {});
|
|
56
51
|
declare type CamelCase<S extends string> = S extends `${infer P1}-${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : Lowercase<S>;
|
|
57
52
|
export interface EdenWSOnMessage<Data = unknown> extends MessageEvent {
|
|
58
53
|
data: Data;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysiajs/eden",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.9",
|
|
4
4
|
"description": "Fully type-safe Elysia client",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "saltyAom",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@elysiajs/cors": "^0.1.0",
|
|
41
|
-
"@elysiajs/websocket": "^0.2.
|
|
41
|
+
"@elysiajs/websocket": "^0.2.6-rc.0",
|
|
42
42
|
"@sinclair/typebox": "^0.25.21",
|
|
43
43
|
"@types/node": "^18.11.7",
|
|
44
44
|
"bun-types": "^0.3.0",
|
package/src/types.ts
CHANGED
|
@@ -3,10 +3,18 @@ import type { TObject } from '@sinclair/typebox'
|
|
|
3
3
|
|
|
4
4
|
import type { EdenWS } from '.'
|
|
5
5
|
|
|
6
|
+
type IsAny<T> = unknown extends T
|
|
7
|
+
? [T] extends [object]
|
|
8
|
+
? true
|
|
9
|
+
: false
|
|
10
|
+
: false
|
|
11
|
+
|
|
6
12
|
export type Eden<App extends Elysia<any>> = App['store'] extends {
|
|
7
|
-
[key in typeof SCHEMA]:
|
|
13
|
+
[key in typeof SCHEMA]: infer Schema extends Record<string, Record<string, TypedRoute>>
|
|
8
14
|
}
|
|
9
|
-
?
|
|
15
|
+
? IsAny<Elysia> extends true
|
|
16
|
+
? 'Please installed Elysia before using Eden'
|
|
17
|
+
: UnionToIntersection<Schema>
|
|
10
18
|
: never
|
|
11
19
|
|
|
12
20
|
export interface EdenCall {
|
|
@@ -50,11 +58,11 @@ export type CreateEden<
|
|
|
50
58
|
? {
|
|
51
59
|
[key in A]: CreateEden<Server, B, Full>
|
|
52
60
|
}
|
|
53
|
-
:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
: Record<string, CreateEden<Server, B, Full>> &
|
|
62
|
+
Record<
|
|
63
|
+
`$${A}`,
|
|
64
|
+
`Expected path parameters ':${A}', replace this with any string`
|
|
65
|
+
>
|
|
58
66
|
: // Iterate until last string then catch method
|
|
59
67
|
{
|
|
60
68
|
[key in Path extends ''
|
|
@@ -139,9 +147,10 @@ export type CreateEden<
|
|
|
139
147
|
}
|
|
140
148
|
: never
|
|
141
149
|
} & (Path extends `:${infer params}`
|
|
142
|
-
?
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
? Record<
|
|
151
|
+
`$${params}`,
|
|
152
|
+
`Expected path parameters ':${params}', replace this with any string`
|
|
153
|
+
>
|
|
145
154
|
: {})
|
|
146
155
|
|
|
147
156
|
// https://stackoverflow.com/questions/59623524/typescript-how-to-map-type-keys-to-camelcase
|