@h3ravel/shared 0.16.0 → 0.16.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/package.json +5 -1
- package/CHANGELOG.md +0 -153
- package/src/Contracts/BindingsContract.ts +0 -43
- package/src/Contracts/IApplication.ts +0 -57
- package/src/Contracts/IContainer.ts +0 -40
- package/src/Contracts/IHttp.ts +0 -142
- package/src/Contracts/IRequest.ts +0 -55
- package/src/Contracts/IResponse.ts +0 -66
- package/src/Contracts/IServiceProvider.ts +0 -23
- package/src/Contracts/ObjContract.ts +0 -44
- package/src/Utils/PathLoader.ts +0 -48
- package/src/index.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/shared",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "Shared Utilities.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"types": "./dist/index.d.ts"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
16
20
|
"publishConfig": {
|
|
17
21
|
"access": "public"
|
|
18
22
|
},
|
package/CHANGELOG.md
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
# @h3ravel/shared
|
|
2
|
-
|
|
3
|
-
## 0.16.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- 79f4045: feat: add add exports to package.json
|
|
8
|
-
|
|
9
|
-
## 0.15.4
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- feat: implement full IoC container resolution
|
|
14
|
-
|
|
15
|
-
## 0.15.3
|
|
16
|
-
|
|
17
|
-
### Patch Changes
|
|
18
|
-
|
|
19
|
-
- e3b3d6c: feat: add downloads count shield.
|
|
20
|
-
|
|
21
|
-
## 0.15.2
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- feat: add homepage and repository to all packages.
|
|
26
|
-
|
|
27
|
-
## 0.15.1
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- chore: update readme accros all packages
|
|
32
|
-
|
|
33
|
-
## 0.15.0
|
|
34
|
-
|
|
35
|
-
### Minor Changes
|
|
36
|
-
|
|
37
|
-
- d07ff49: feat: reserve the `app.` namespace for generic service provider resolution.
|
|
38
|
-
|
|
39
|
-
## 0.14.0
|
|
40
|
-
|
|
41
|
-
### Minor Changes
|
|
42
|
-
|
|
43
|
-
- feat: add app to HttpContext interface
|
|
44
|
-
|
|
45
|
-
## 0.13.0
|
|
46
|
-
|
|
47
|
-
### Minor Changes
|
|
48
|
-
|
|
49
|
-
- 6e249fe: feat: bind view as a self contained method to render views
|
|
50
|
-
|
|
51
|
-
## 0.12.1
|
|
52
|
-
|
|
53
|
-
### Patch Changes
|
|
54
|
-
|
|
55
|
-
- chore: regularize all interfaces.
|
|
56
|
-
|
|
57
|
-
## 0.12.0
|
|
58
|
-
|
|
59
|
-
### Minor Changes
|
|
60
|
-
|
|
61
|
-
- feat: add the current app instance to the Request and Response object
|
|
62
|
-
|
|
63
|
-
## 0.11.0
|
|
64
|
-
|
|
65
|
-
### Minor Changes
|
|
66
|
-
|
|
67
|
-
- remove 'name' from RouterEnd and only join in apiResource.
|
|
68
|
-
|
|
69
|
-
## 0.10.0
|
|
70
|
-
|
|
71
|
-
### Minor Changes
|
|
72
|
-
|
|
73
|
-
- feat: hide RouterEnd from itslelf to prevent unintentional chaining.
|
|
74
|
-
|
|
75
|
-
## 0.9.0
|
|
76
|
-
|
|
77
|
-
### Minor Changes
|
|
78
|
-
|
|
79
|
-
- refactor!: make route definition more similar to the way it is handled in laravel.
|
|
80
|
-
|
|
81
|
-
## 0.8.0
|
|
82
|
-
|
|
83
|
-
### Minor Changes
|
|
84
|
-
|
|
85
|
-
- feat: convert Request params and query from a method to a property and add Request headers
|
|
86
|
-
|
|
87
|
-
## 0.7.1
|
|
88
|
-
|
|
89
|
-
### Patch Changes
|
|
90
|
-
|
|
91
|
-
- chore: add download count to readme
|
|
92
|
-
|
|
93
|
-
## 0.7.0
|
|
94
|
-
|
|
95
|
-
### Minor Changes
|
|
96
|
-
|
|
97
|
-
- b0d1b7c: feat: flip @h3ravel/shared dependency on @h3ravel/support as it should be.
|
|
98
|
-
|
|
99
|
-
## 0.6.0
|
|
100
|
-
|
|
101
|
-
### Minor Changes
|
|
102
|
-
|
|
103
|
-
- b40caeb: feat: make service providers sortable and unique while only loading the core providers by default.
|
|
104
|
-
Service providers are no longer loaded by default, asides the ones provided by @h3ravel/core
|
|
105
|
-
Service provides are sorted by an optional order and priority property.
|
|
106
|
-
|
|
107
|
-
### Patch Changes
|
|
108
|
-
|
|
109
|
-
- Updated dependencies [b40caeb]
|
|
110
|
-
- @h3ravel/support@0.6.0
|
|
111
|
-
|
|
112
|
-
## 0.5.0
|
|
113
|
-
|
|
114
|
-
### Minor Changes
|
|
115
|
-
|
|
116
|
-
- rebuild all dependencies
|
|
117
|
-
|
|
118
|
-
### Patch Changes
|
|
119
|
-
|
|
120
|
-
- Updated dependencies
|
|
121
|
-
- @h3ravel/support@0.5.0
|
|
122
|
-
|
|
123
|
-
## 0.4.0
|
|
124
|
-
|
|
125
|
-
### Minor Changes
|
|
126
|
-
|
|
127
|
-
- 8ceb2c1: implement the Application class directly since it already implements the IClass contract
|
|
128
|
-
|
|
129
|
-
### Patch Changes
|
|
130
|
-
|
|
131
|
-
- a27f452: chore: fix all linting issues.
|
|
132
|
-
- c906050: chore: migrate tests suite to jest
|
|
133
|
-
- Updated dependencies [8ceb2c1]
|
|
134
|
-
- Updated dependencies [a27f452]
|
|
135
|
-
- Updated dependencies [c906050]
|
|
136
|
-
- @h3ravel/support@0.4.0
|
|
137
|
-
|
|
138
|
-
## 0.3.0
|
|
139
|
-
|
|
140
|
-
### Minor Changes
|
|
141
|
-
|
|
142
|
-
- 3ff97bf: refactor: add a shared package to be extended by others to avoid cyclic dependency issues.
|
|
143
|
-
|
|
144
|
-
### Patch Changes
|
|
145
|
-
|
|
146
|
-
- Updated dependencies [3ff97bf]
|
|
147
|
-
- @h3ravel/support@0.3.0
|
|
148
|
-
|
|
149
|
-
## 0.2.0
|
|
150
|
-
|
|
151
|
-
### Minor Changes
|
|
152
|
-
|
|
153
|
-
- aea734f: Fix all known bugs and improved interdependecy between packages.
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// import { DotNestedKeys, DotNestedValue } from "@h3ravel/support";
|
|
2
|
-
import type { H3, serve } from 'h3'
|
|
3
|
-
|
|
4
|
-
import type { Edge } from 'edge.js'
|
|
5
|
-
import { IRequest } from './IRequest'
|
|
6
|
-
import { IResponse } from './IResponse'
|
|
7
|
-
import { IRouter } from './IHttp'
|
|
8
|
-
import { PathLoader } from '../Utils/PathLoader'
|
|
9
|
-
|
|
10
|
-
type RemoveIndexSignature<T> = {
|
|
11
|
-
[K in keyof T as string extends K
|
|
12
|
-
? never
|
|
13
|
-
: number extends K
|
|
14
|
-
? never
|
|
15
|
-
: K]: T[K]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type Bindings = {
|
|
19
|
-
[key: string]: any;
|
|
20
|
-
[key: `app.${string}`]: any;
|
|
21
|
-
env (): NodeJS.ProcessEnv
|
|
22
|
-
env<T extends string> (key: T, def?: any): any
|
|
23
|
-
view (templatePath: string, state?: Record<string, any>): Promise<string>
|
|
24
|
-
edge: Edge;
|
|
25
|
-
asset (key: string, def?: string): string
|
|
26
|
-
router: IRouter
|
|
27
|
-
config: {
|
|
28
|
-
// get<X extends Record<string, any>> (): X
|
|
29
|
-
// get<X extends Record<string, any>, K extends DotNestedKeys<X>> (key: K, def?: any): DotNestedValue<X, K>
|
|
30
|
-
get<X extends Record<string, any>> (): X
|
|
31
|
-
get<X extends Record<string, any>, T extends Extract<keyof X, string>> (key: T, def?: any): X[T]
|
|
32
|
-
set<T extends string> (key: T, value: any): void
|
|
33
|
-
load?(): any
|
|
34
|
-
}
|
|
35
|
-
'http.app': H3
|
|
36
|
-
'path.base': string
|
|
37
|
-
'load.paths': PathLoader
|
|
38
|
-
'http.serve': typeof serve
|
|
39
|
-
'http.request': IRequest
|
|
40
|
-
'http.response': IResponse
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type UseKey = keyof RemoveIndexSignature<Bindings>
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { IContainer } from './IContainer';
|
|
2
|
-
import { IServiceProvider } from './IServiceProvider'
|
|
3
|
-
|
|
4
|
-
export type IPathName = 'views' | 'routes' | 'assets' | 'base' | 'public' | 'storage' | 'config'
|
|
5
|
-
|
|
6
|
-
export interface IApplication extends IContainer {
|
|
7
|
-
/**
|
|
8
|
-
* Registers configured service providers.
|
|
9
|
-
*/
|
|
10
|
-
registerConfiguredProviders (): Promise<void>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Registers an array of external service provider classes.
|
|
14
|
-
* @param providers - Array of service provider constructor functions.
|
|
15
|
-
*/
|
|
16
|
-
registerProviders (providers: Array<new (app: IApplication) => IServiceProvider>): void;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Registers a single service provider.
|
|
20
|
-
* @param provider - The service provider instance to register.
|
|
21
|
-
*/
|
|
22
|
-
register (provider: IServiceProvider): Promise<void>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Boots all registered providers.
|
|
26
|
-
*/
|
|
27
|
-
boot (): Promise<void>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Gets the base path of the application.
|
|
31
|
-
* @returns The base path as a string.
|
|
32
|
-
*/
|
|
33
|
-
getBasePath (): string;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Retrieves a path by name, optionally appending a sub-path.
|
|
37
|
-
* @param name - The name of the path property.
|
|
38
|
-
* @param pth - Optional sub-path to append.
|
|
39
|
-
* @returns The resolved path as a string.
|
|
40
|
-
*/
|
|
41
|
-
getPath (name: string, pth?: string): string;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Sets a path for a given name.
|
|
45
|
-
* @param name - The name of the path property.
|
|
46
|
-
* @param path - The path to set.
|
|
47
|
-
* @returns
|
|
48
|
-
*/
|
|
49
|
-
setPath (name: IPathName, path: string): void;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Gets the version of the application or TypeScript.
|
|
53
|
-
* @param key - The key to retrieve ('app' or 'ts').
|
|
54
|
-
* @returns The version string or undefined.
|
|
55
|
-
*/
|
|
56
|
-
getVersion (key: 'app' | 'ts'): string | undefined;
|
|
57
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { Bindings, UseKey } from './BindingsContract';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Interface for the Container contract, defining methods for dependency injection and service resolution.
|
|
5
|
-
*/
|
|
6
|
-
export interface IContainer {
|
|
7
|
-
/**
|
|
8
|
-
* Binds a transient service to the container.
|
|
9
|
-
* @param key - The key or constructor for the service.
|
|
10
|
-
* @param factory - The factory function to create the service instance.
|
|
11
|
-
*/
|
|
12
|
-
bind<T> (key: new (...args: any[]) => T, factory: () => T): void;
|
|
13
|
-
bind<T extends UseKey> (key: T, factory: () => Bindings[T]): void;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Binds a singleton service to the container.
|
|
17
|
-
* @param key - The key or constructor for the service.
|
|
18
|
-
* @param factory - The factory function to create the singleton instance.
|
|
19
|
-
*/
|
|
20
|
-
singleton<T extends UseKey> (
|
|
21
|
-
key: T | (new (...args: any[]) => Bindings[T]),
|
|
22
|
-
factory: () => Bindings[T]
|
|
23
|
-
): void;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Resolves a service from the container.
|
|
27
|
-
* @param key - The key or constructor for the service.
|
|
28
|
-
* @returns The resolved service instance.
|
|
29
|
-
*/
|
|
30
|
-
make<T extends UseKey, X = undefined> (
|
|
31
|
-
key: T | (new (..._args: any[]) => Bindings[T])
|
|
32
|
-
): X extends undefined ? Bindings[T] : X
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Checks if a service is registered in the container.
|
|
36
|
-
* @param key - The key to check.
|
|
37
|
-
* @returns True if the service is registered, false otherwise.
|
|
38
|
-
*/
|
|
39
|
-
has (key: UseKey): boolean;
|
|
40
|
-
}
|
package/src/Contracts/IHttp.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import type { Middleware, MiddlewareOptions } from 'h3'
|
|
2
|
-
|
|
3
|
-
import { IApplication } from './IApplication'
|
|
4
|
-
import { IRequest } from './IRequest'
|
|
5
|
-
import { IResponse } from './IResponse'
|
|
6
|
-
|
|
7
|
-
export type RouterEnd = 'get' | 'delete' | 'put' | 'post' | 'apiResource' | 'group' | 'route';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Interface for the Router contract, defining methods for HTTP routing.
|
|
11
|
-
*/
|
|
12
|
-
export interface IRouter {
|
|
13
|
-
/**
|
|
14
|
-
* Registers a GET route.
|
|
15
|
-
* @param path - The route path.
|
|
16
|
-
* @param definition - The handler function or [controller class, method] array.
|
|
17
|
-
* @param name - Optional route name.
|
|
18
|
-
* @param middleware - Optional middleware array.
|
|
19
|
-
*/
|
|
20
|
-
get (
|
|
21
|
-
path: string,
|
|
22
|
-
definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],
|
|
23
|
-
name?: string,
|
|
24
|
-
middleware?: IMiddleware[]
|
|
25
|
-
): Omit<this, RouterEnd>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Registers a POST route.
|
|
29
|
-
* @param path - The route path.
|
|
30
|
-
* @param definition - The handler function or [controller class, method] array.
|
|
31
|
-
* @param name - Optional route name.
|
|
32
|
-
* @param middleware - Optional middleware array.
|
|
33
|
-
*/
|
|
34
|
-
post (
|
|
35
|
-
path: string,
|
|
36
|
-
definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],
|
|
37
|
-
name?: string,
|
|
38
|
-
middleware?: IMiddleware[]
|
|
39
|
-
): Omit<this, RouterEnd>;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Registers a PUT route.
|
|
43
|
-
* @param path - The route path.
|
|
44
|
-
* @param definition - The handler function or [controller class, method] array.
|
|
45
|
-
* @param name - Optional route name.
|
|
46
|
-
* @param middleware - Optional middleware array.
|
|
47
|
-
*/
|
|
48
|
-
put (
|
|
49
|
-
path: string,
|
|
50
|
-
definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],
|
|
51
|
-
name?: string,
|
|
52
|
-
middleware?: IMiddleware[]
|
|
53
|
-
): Omit<this, RouterEnd>;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Registers a DELETE route.
|
|
57
|
-
* @param path - The route path.
|
|
58
|
-
* @param definition - The handler function or [controller class, method] array.
|
|
59
|
-
* @param name - Optional route name.
|
|
60
|
-
* @param middleware - Optional middleware array.
|
|
61
|
-
*/
|
|
62
|
-
delete (
|
|
63
|
-
path: string,
|
|
64
|
-
definition: EventHandler | [(new (...args: any[]) => IController), methodName: string],
|
|
65
|
-
name?: string,
|
|
66
|
-
middleware?: IMiddleware[]
|
|
67
|
-
): Omit<this, RouterEnd>;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Registers an API resource with standard CRUD routes.
|
|
71
|
-
* @param path - The base path for the resource.
|
|
72
|
-
* @param controller - The controller class handling the resource.
|
|
73
|
-
* @param middleware - Optional middleware array.
|
|
74
|
-
*/
|
|
75
|
-
apiResource (
|
|
76
|
-
path: string,
|
|
77
|
-
controller: new (app: IApplication) => IController,
|
|
78
|
-
middleware?: IMiddleware[]
|
|
79
|
-
): Omit<this, RouterEnd | 'name'>;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Generates a URL for a named route.
|
|
83
|
-
* @param name - The name of the route.
|
|
84
|
-
* @param params - Optional parameters to replace in the route path.
|
|
85
|
-
* @returns The generated URL or undefined if the route is not found.
|
|
86
|
-
*/
|
|
87
|
-
route (name: string, params?: Record<string, string>): string | undefined;
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Set the name of the current route
|
|
92
|
-
*
|
|
93
|
-
* @param name
|
|
94
|
-
*/
|
|
95
|
-
name (name: string): this
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Groups routes with shared prefix or middleware.
|
|
99
|
-
* @param options - Configuration for prefix or middleware.
|
|
100
|
-
* @param callback - Callback function defining grouped routes.
|
|
101
|
-
*/
|
|
102
|
-
group (options: { prefix?: string; middleware?: EventHandler[] }, callback: () => void): this;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Registers middleware for a specific path.
|
|
106
|
-
* @param path - The path to apply the middleware.
|
|
107
|
-
* @param handler - The middleware handler.
|
|
108
|
-
* @param opts - Optional middleware options.
|
|
109
|
-
*/
|
|
110
|
-
middleware (path: string | IMiddleware[], handler: Middleware, opts?: MiddlewareOptions): this;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export interface HttpContext {
|
|
114
|
-
app: IApplication
|
|
115
|
-
request: IRequest
|
|
116
|
-
response: IResponse
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Type for EventHandler, representing a function that handles an H3 event.
|
|
121
|
-
*/
|
|
122
|
-
export type EventHandler = (ctx: HttpContext) => any
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Defines the contract for all controllers.
|
|
126
|
-
* Any controller implementing this must define these methods.
|
|
127
|
-
*/
|
|
128
|
-
export interface IController {
|
|
129
|
-
show (ctx: HttpContext): any
|
|
130
|
-
index (ctx: HttpContext): any
|
|
131
|
-
store (ctx: HttpContext): any
|
|
132
|
-
update (ctx: HttpContext): any
|
|
133
|
-
destroy (ctx: HttpContext): any
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Defines the contract for all middlewares.
|
|
138
|
-
* Any middleware implementing this must define these methods.
|
|
139
|
-
*/
|
|
140
|
-
export interface IMiddleware {
|
|
141
|
-
handle (context: HttpContext, next: () => Promise<any>): Promise<any>
|
|
142
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { DotNestedKeys, DotNestedValue } from './ObjContract'
|
|
2
|
-
import type { ResponseHeaderMap, TypedHeaders } from 'fetchdts'
|
|
3
|
-
|
|
4
|
-
import type { H3Event } from 'h3'
|
|
5
|
-
import type { IApplication } from './IApplication';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Interface for the Request contract, defining methods for handling HTTP request data.
|
|
9
|
-
*/
|
|
10
|
-
export interface IRequest {
|
|
11
|
-
/**
|
|
12
|
-
* The current app instance
|
|
13
|
-
*/
|
|
14
|
-
app: IApplication
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Gets route parameters.
|
|
18
|
-
* @returns An object containing route parameters.
|
|
19
|
-
*/
|
|
20
|
-
params: NonNullable<H3Event["context"]["params"]>;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Gets query parameters.
|
|
24
|
-
* @returns An object containing query parameters.
|
|
25
|
-
*/
|
|
26
|
-
query: Record<string, any>;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Gets the request headers.
|
|
30
|
-
* @returns An object containing request headers.
|
|
31
|
-
*/
|
|
32
|
-
headers: TypedHeaders<Record<keyof ResponseHeaderMap, string>>;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Gets all input data (query parameters, route parameters, and body).
|
|
36
|
-
* @returns A promise resolving to an object containing all input data.
|
|
37
|
-
*/
|
|
38
|
-
all<T = Record<string, unknown>> (): Promise<T>;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Gets a single input field from query or body.
|
|
42
|
-
* @param key - The key of the input field.
|
|
43
|
-
* @param defaultValue - Optional default value if the key is not found.
|
|
44
|
-
* @returns A promise resolving to the value of the input field or the default value.
|
|
45
|
-
*/
|
|
46
|
-
input<T = unknown> (key: string, defaultValue?: T): Promise<T>;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Gets the underlying event object or a specific property of it.
|
|
50
|
-
* @param key - Optional key to access a nested property of the event.
|
|
51
|
-
* @returns The entire event object or the value of the specified property.
|
|
52
|
-
*/
|
|
53
|
-
getEvent (): H3Event;
|
|
54
|
-
getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>;
|
|
55
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { DotNestedKeys, DotNestedValue } from './ObjContract'
|
|
2
|
-
|
|
3
|
-
import type { H3Event } from 'h3'
|
|
4
|
-
import type { IApplication } from './IApplication';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Interface for the Response contract, defining methods for handling HTTP responses.
|
|
8
|
-
*/
|
|
9
|
-
export interface IResponse {
|
|
10
|
-
/**
|
|
11
|
-
* The current app instance
|
|
12
|
-
*/
|
|
13
|
-
app: IApplication
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Sets the HTTP status code for the response.
|
|
17
|
-
* @param code - The HTTP status code.
|
|
18
|
-
* @returns The instance for method chaining.
|
|
19
|
-
*/
|
|
20
|
-
setStatusCode (code: number): this;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Sets a response header.
|
|
24
|
-
* @param name - The header name.
|
|
25
|
-
* @param value - The header value.
|
|
26
|
-
* @returns The instance for method chaining.
|
|
27
|
-
*/
|
|
28
|
-
setHeader (name: string, value: string): this;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Sends an HTML response.
|
|
32
|
-
* @param content - The HTML content to send.
|
|
33
|
-
* @returns The HTML content.
|
|
34
|
-
*/
|
|
35
|
-
html (content: string): string;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Sends a JSON response.
|
|
39
|
-
* @param data - The data to send as JSON.
|
|
40
|
-
* @returns The input data.
|
|
41
|
-
*/
|
|
42
|
-
json<T = unknown> (data: T): T;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Sends a plain text response.
|
|
46
|
-
* @param data - The text content to send.
|
|
47
|
-
* @returns The text content.
|
|
48
|
-
*/
|
|
49
|
-
text (data: string): string;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Redirects to another URL.
|
|
53
|
-
* @param url - The URL to redirect to.
|
|
54
|
-
* @param status - The HTTP status code for the redirect (default: 302).
|
|
55
|
-
* @returns The redirect URL.
|
|
56
|
-
*/
|
|
57
|
-
redirect (url: string, status?: number): string;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Gets the underlying event object or a specific property of it.
|
|
61
|
-
* @param key - Optional key to access a nested property of the event.
|
|
62
|
-
* @returns The entire event object or the value of the specified property.
|
|
63
|
-
*/
|
|
64
|
-
getEvent (): H3Event;
|
|
65
|
-
getEvent<K extends DotNestedKeys<H3Event>> (key: K): DotNestedValue<H3Event, K>;
|
|
66
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface IServiceProvider {
|
|
2
|
-
/**
|
|
3
|
-
* Sort order
|
|
4
|
-
*/
|
|
5
|
-
order?: `before:${string}` | `after:${string}` | string | undefined
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Sort priority
|
|
9
|
-
*/
|
|
10
|
-
priority?: number;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Register bindings to the container.
|
|
14
|
-
* Runs before boot().
|
|
15
|
-
*/
|
|
16
|
-
register (): void | Promise<void>
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Perform post-registration booting of services.
|
|
20
|
-
* Runs after all providers have been registered.
|
|
21
|
-
*/
|
|
22
|
-
boot?(): void | Promise<void>
|
|
23
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds a dot prefix to nested keys
|
|
3
|
-
*/
|
|
4
|
-
type DotPrefix<T extends string, U extends string> =
|
|
5
|
-
T extends '' ? U : `${T}.${U}`
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Converts a union of objects into a single merged object
|
|
9
|
-
*/
|
|
10
|
-
type MergeUnion<T> =
|
|
11
|
-
(T extends any ? (k: T) => void : never) extends
|
|
12
|
-
(k: infer I) => void ? { [K in keyof I]: I[K] } : never
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Flattens nested objects into dotted keys
|
|
16
|
-
*/
|
|
17
|
-
export type DotFlatten<T, Prefix extends string = ''> = MergeUnion<{
|
|
18
|
-
[K in keyof T & string]:
|
|
19
|
-
T[K] extends Record<string, any>
|
|
20
|
-
? DotFlatten<T[K], DotPrefix<Prefix, K>>
|
|
21
|
-
: { [P in DotPrefix<Prefix, K>]: T[K] }
|
|
22
|
-
}[keyof T & string]>
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Builds "nested.key" paths for autocompletion
|
|
26
|
-
*/
|
|
27
|
-
export type DotNestedKeys<T> = {
|
|
28
|
-
[K in keyof T & string]:
|
|
29
|
-
T[K] extends object
|
|
30
|
-
? `${K}` | `${K}.${DotNestedKeys<T[K]>}`
|
|
31
|
-
: `${K}`
|
|
32
|
-
}[keyof T & string]
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Retrieves type at a given dot-path
|
|
36
|
-
*/
|
|
37
|
-
export type DotNestedValue<T, Path extends string> =
|
|
38
|
-
Path extends `${infer Key}.${infer Rest}`
|
|
39
|
-
? Key extends keyof T
|
|
40
|
-
? DotNestedValue<T[Key], Rest>
|
|
41
|
-
: never
|
|
42
|
-
: Path extends keyof T
|
|
43
|
-
? T[Path]
|
|
44
|
-
: never
|
package/src/Utils/PathLoader.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { IPathName } from '../Contracts/IApplication'
|
|
2
|
-
import nodepath from 'path'
|
|
3
|
-
|
|
4
|
-
export class PathLoader {
|
|
5
|
-
private paths = {
|
|
6
|
-
base: '',
|
|
7
|
-
views: '/src/resources/views',
|
|
8
|
-
assets: '/public/assets',
|
|
9
|
-
routes: '/src/routes',
|
|
10
|
-
config: '/src/config',
|
|
11
|
-
public: '/public',
|
|
12
|
-
storage: '/storage',
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Dynamically retrieves a path property from the class.
|
|
17
|
-
* Any property ending with "Path" is accessible automatically.
|
|
18
|
-
*
|
|
19
|
-
* @param name - The base name of the path property
|
|
20
|
-
* @param base - The base path to include to the path
|
|
21
|
-
* @returns
|
|
22
|
-
*/
|
|
23
|
-
getPath (name: IPathName, base?: string): string {
|
|
24
|
-
let path: string;
|
|
25
|
-
|
|
26
|
-
if (base && name !== 'base') {
|
|
27
|
-
path = nodepath.join(base, this.paths[name])
|
|
28
|
-
} else {
|
|
29
|
-
path = this.paths[name]
|
|
30
|
-
}
|
|
31
|
-
return path.replace('/src/', `/${process.env.SRC_PATH ?? 'src'}/`.replace(/([^:]\/)\/+/g, "$1"))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Programatically set the paths.
|
|
36
|
-
*
|
|
37
|
-
* @param name - The base name of the path property
|
|
38
|
-
* @param path - The new path
|
|
39
|
-
* @param base - The base path to include to the path
|
|
40
|
-
*/
|
|
41
|
-
setPath (name: IPathName, path: string, base?: string) {
|
|
42
|
-
if (base && name !== 'base') {
|
|
43
|
-
this.paths[name] = nodepath.join(base, path)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
this.paths[name] = path
|
|
47
|
-
}
|
|
48
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Automatically generated by barrelsby.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export * from './Contracts/BindingsContract';
|
|
6
|
-
export * from './Contracts/IApplication';
|
|
7
|
-
export * from './Contracts/IContainer';
|
|
8
|
-
export * from './Contracts/IHttp';
|
|
9
|
-
export * from './Contracts/IRequest';
|
|
10
|
-
export * from './Contracts/IResponse';
|
|
11
|
-
export * from './Contracts/IServiceProvider';
|
|
12
|
-
export * from './Contracts/ObjContract';
|
|
13
|
-
export * from './Utils/PathLoader';
|