@elysiajs/eden 0.1.0-rc.1 → 0.1.0-rc.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/cjs/index.js +2 -1
- package/dist/cjs/types.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/index.ts +4 -1
- package/src/types.ts +9 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.eden = void 0;
|
|
4
|
+
const camelToDash = (str) => str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
4
5
|
const composePath = (domain, path, query) => {
|
|
5
6
|
if (!domain.endsWith('/'))
|
|
6
7
|
domain += '/';
|
|
7
|
-
path = path.replace(/index/g, '');
|
|
8
|
+
path = camelToDash(path.replace(/index/g, ''));
|
|
8
9
|
if (!query || !Object.keys(query).length)
|
|
9
10
|
return `${domain}${path}`;
|
|
10
11
|
let q = '';
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare type TypedRouteToParams<Route extends TypedRoute> = (Route['body'] exten
|
|
|
12
12
|
export declare type CreateEden<Server extends Record<string, Record<string, TypedRoute>>, Path extends string = keyof Server, Full extends string = ''> = Path extends `/${infer Start}` ? CreateEden<Server, Start, Path> : Path extends `${infer A}/${infer B}` ? {
|
|
13
13
|
[key in A]: CreateEden<Server, B, Full>;
|
|
14
14
|
} : {
|
|
15
|
-
[key in Path extends '' ? 'index' : Path extends `:${infer params}` ? string : Path]: Full extends keyof Server ? {
|
|
15
|
+
[key in Path extends '' ? 'index' : Path extends `:${infer params}` ? string : Path | CamelCase<Path>]: Full extends keyof Server ? {
|
|
16
16
|
[key in keyof Server[Full]]: keyof TypedRouteToParams<Server[Full][key]> extends never ? (params?: {
|
|
17
17
|
$query?: EdenCall['$query'];
|
|
18
18
|
$fetch?: EdenCall['$fetch'];
|
|
@@ -22,4 +22,5 @@ export declare type CreateEden<Server extends Record<string, Record<string, Type
|
|
|
22
22
|
}) => Promise<Server[Full][key]['response']>;
|
|
23
23
|
} : never;
|
|
24
24
|
};
|
|
25
|
+
declare type CamelCase<S extends string> = S extends `${infer P1}-${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : Lowercase<S>;
|
|
25
26
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
const camelToDash = (str) => str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
1
2
|
const composePath = (domain, path, query) => {
|
|
2
3
|
if (!domain.endsWith('/'))
|
|
3
4
|
domain += '/';
|
|
4
|
-
path = path.replace(/index/g, '');
|
|
5
|
+
path = camelToDash(path.replace(/index/g, ''));
|
|
5
6
|
if (!query || !Object.keys(query).length)
|
|
6
7
|
return `${domain}${path}`;
|
|
7
8
|
let q = '';
|
package/dist/types.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ declare type TypedRouteToParams<Route extends TypedRoute> = (Route['body'] exten
|
|
|
12
12
|
export declare type CreateEden<Server extends Record<string, Record<string, TypedRoute>>, Path extends string = keyof Server, Full extends string = ''> = Path extends `/${infer Start}` ? CreateEden<Server, Start, Path> : Path extends `${infer A}/${infer B}` ? {
|
|
13
13
|
[key in A]: CreateEden<Server, B, Full>;
|
|
14
14
|
} : {
|
|
15
|
-
[key in Path extends '' ? 'index' : Path extends `:${infer params}` ? string : Path]: Full extends keyof Server ? {
|
|
15
|
+
[key in Path extends '' ? 'index' : Path extends `:${infer params}` ? string : Path | CamelCase<Path>]: Full extends keyof Server ? {
|
|
16
16
|
[key in keyof Server[Full]]: keyof TypedRouteToParams<Server[Full][key]> extends never ? (params?: {
|
|
17
17
|
$query?: EdenCall['$query'];
|
|
18
18
|
$fetch?: EdenCall['$fetch'];
|
|
@@ -22,4 +22,5 @@ export declare type CreateEden<Server extends Record<string, Record<string, Type
|
|
|
22
22
|
}) => Promise<Server[Full][key]['response']>;
|
|
23
23
|
} : never;
|
|
24
24
|
};
|
|
25
|
+
declare type CamelCase<S extends string> = S extends `${infer P1}-${infer P2}${infer P3}` ? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}` : Lowercase<S>;
|
|
25
26
|
export {};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,6 +3,9 @@ import type { HTTPMethod } from 'elysia'
|
|
|
3
3
|
|
|
4
4
|
import { CreateEden, EdenCall, UnionToIntersection } from './types'
|
|
5
5
|
|
|
6
|
+
const camelToDash = (str: string) =>
|
|
7
|
+
str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
|
|
8
|
+
|
|
6
9
|
const composePath = (
|
|
7
10
|
domain: string,
|
|
8
11
|
path: string,
|
|
@@ -10,7 +13,7 @@ const composePath = (
|
|
|
10
13
|
) => {
|
|
11
14
|
if (!domain.endsWith('/')) domain += '/'
|
|
12
15
|
|
|
13
|
-
path = path.replace(/index/g, '')
|
|
16
|
+
path = camelToDash(path.replace(/index/g, ''))
|
|
14
17
|
if (!query || !Object.keys(query).length) return `${domain}${path}`
|
|
15
18
|
|
|
16
19
|
let q = ''
|
package/src/types.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type CreateEden<
|
|
|
36
36
|
? 'index'
|
|
37
37
|
: Path extends `:${infer params}`
|
|
38
38
|
? string
|
|
39
|
-
: Path]: Full extends keyof Server
|
|
39
|
+
: Path | CamelCase<Path>]: Full extends keyof Server
|
|
40
40
|
? {
|
|
41
41
|
[key in keyof Server[Full]]: keyof TypedRouteToParams<
|
|
42
42
|
Server[Full][key]
|
|
@@ -54,3 +54,11 @@ export type CreateEden<
|
|
|
54
54
|
}
|
|
55
55
|
: never
|
|
56
56
|
}
|
|
57
|
+
|
|
58
|
+
// https://stackoverflow.com/questions/59623524/typescript-how-to-map-type-keys-to-camelcase
|
|
59
|
+
type CamelCase<S extends string> =
|
|
60
|
+
S extends `${infer P1}-${infer P2}${infer P3}`
|
|
61
|
+
? `${Lowercase<P1>}${Uppercase<P2>}${CamelCase<P3>}`
|
|
62
|
+
: Lowercase<S>
|
|
63
|
+
|
|
64
|
+
type A = CamelCase<'sign-in'>
|