@ts-kizuna/express 1.49.7 → 1.51.0
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.cjs +4 -20
- package/dist/index.d.cts +12 -90
- package/dist/index.d.mts +12 -90
- package/dist/index.mjs +5 -21
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -108,25 +108,6 @@ function mountExpress(api, app, options) {
|
|
|
108
108
|
app.use(expressRouter);
|
|
109
109
|
return expressRouter;
|
|
110
110
|
}
|
|
111
|
-
const createServerSurface = (contract, options) => {
|
|
112
|
-
(0, _ts_kizuna_core_adapter.warnUnsupportedJobOptions)(contract.jobs, options?.jobTransport);
|
|
113
|
-
return {
|
|
114
|
-
guard: (_name, run) => run,
|
|
115
|
-
requestContext: (_name, run) => run,
|
|
116
|
-
router: (groupOrRouter, groupRouter) => groupRouter ?? groupOrRouter,
|
|
117
|
-
jobs: (handlers) => handlers,
|
|
118
|
-
api: ({ jobs, ...parts }) => {
|
|
119
|
-
const api = Object.assign((0, _ts_kizuna_core_adapter.assembleApi)(contract, parts), { [_ts_kizuna_core_adapter.JOBS_META]: contract.jobs ? {
|
|
120
|
-
jobs: contract.jobs,
|
|
121
|
-
handlers: jobs ?? {},
|
|
122
|
-
config: contract.jobsConfig,
|
|
123
|
-
transport: options?.jobTransport,
|
|
124
|
-
onError: options?.onJobError
|
|
125
|
-
} : void 0 });
|
|
126
|
-
return Object.assign(api, { mount: (app, mountOptions) => mountExpress(api, app, mountOptions) });
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
};
|
|
130
111
|
/**
|
|
131
112
|
* Turn a contract into a server handle: the serving counterpart to `Kizuna`.
|
|
132
113
|
* Keep the instance and use `server.guard` to define guards, `server.router`
|
|
@@ -149,7 +130,10 @@ const createServerSurface = (contract, options) => {
|
|
|
149
130
|
*/
|
|
150
131
|
var KizunaServer = class {
|
|
151
132
|
constructor(contract, options) {
|
|
152
|
-
Object.assign(this, createServerSurface(contract, options)
|
|
133
|
+
Object.assign(this, (0, _ts_kizuna_core_adapter.createServerSurface)(contract, options, (assembled) => {
|
|
134
|
+
const api = assembled;
|
|
135
|
+
return Object.assign(api, { mount: (app, mountOptions) => mountExpress(api, app, mountOptions) });
|
|
136
|
+
}));
|
|
153
137
|
}
|
|
154
138
|
};
|
|
155
139
|
//#endregion
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Request, Response, Router as Router$1 } from "express";
|
|
2
|
-
import { ApiWithRouter,
|
|
3
|
-
import {
|
|
4
|
-
import { Contract, CredentialOf, GuardSuccess, JobHandlers, JobsArg, RequestContextHeaderValues, RequestContextSchema, SecurityScheme, TagOptions } from "@ts-kizuna/core";
|
|
2
|
+
import { ApiWithRouter, ContractJobsRouter, ContractRouter, ErrorFormatter, GUARDS_META, JOBS_META, REQUEST_CONTEXT_META, RouteDefinition, RouteHandler as RouteHandler$1, Routes, SCHEMES_META, Server as Server$1, ServerOptions } from "@ts-kizuna/core/adapter";
|
|
3
|
+
import { Contract, RoutesOf } from "@ts-kizuna/core";
|
|
5
4
|
|
|
6
5
|
//#region src/server.d.ts
|
|
7
6
|
type ExpressApi<R extends Routes = Routes> = ApiWithRouter<R> & {
|
|
@@ -30,18 +29,12 @@ type RouteHandler<R extends RouteDefinition> = RouteHandler$1<R, ExpressHandlerC
|
|
|
30
29
|
* secured by the contract's `auth` map additionally receive each required
|
|
31
30
|
* identity's context in their handler args, under `auth`, keyed by the identity's name.
|
|
32
31
|
*/
|
|
33
|
-
type Router<C> =
|
|
32
|
+
type Router<C> = ContractRouter<C, ExpressHandlerContext>;
|
|
34
33
|
/**
|
|
35
34
|
* The handler for each of a contract's scheduled jobs, typed against it. Each
|
|
36
35
|
* receives only the job's `input`, so the same handler can be run in process.
|
|
37
36
|
*/
|
|
38
|
-
type JobsRouter<C> = C
|
|
39
|
-
/**
|
|
40
|
-
* The handlers for a group named on the contract, or for a bare route group.
|
|
41
|
-
* Both forms resolve through one signature: a second candidate of the same
|
|
42
|
-
* arity costs zero-argument handlers their contextual type.
|
|
43
|
-
*/
|
|
44
|
-
type GroupRouter<Source, GroupOrRoutes> = GroupOrRoutes extends string ? Router<Source>[Extract<GroupOrRoutes, keyof Router<Source>>] : Router<GroupOrRoutes>;
|
|
37
|
+
type JobsRouter<C> = ContractJobsRouter<C>;
|
|
45
38
|
declare global {
|
|
46
39
|
namespace Express {
|
|
47
40
|
interface Request {
|
|
@@ -72,23 +65,13 @@ interface ExpressOptions {
|
|
|
72
65
|
* authentication-only identity (no context, no access) returns nothing on
|
|
73
66
|
* success, or `deny(...)`.
|
|
74
67
|
*/
|
|
75
|
-
type GuardFns<Schemes extends Record<string, SecurityScheme>, Params> = { [Name in keyof Schemes]: (args: ExpressHandlerContext & CredentialOf<Schemes[Name]> & {
|
|
76
|
-
params: Params;
|
|
77
|
-
deny: GuardDeny;
|
|
78
|
-
scopes: string[];
|
|
79
|
-
}) => [keyof GuardSuccess<Schemes[Name]>] extends [never] ? void | GuardDenial | Promise<void | GuardDenial> : GuardSuccess<Schemes[Name]> | GuardDenial | Promise<GuardSuccess<Schemes[Name]> | GuardDenial> };
|
|
80
68
|
/**
|
|
81
69
|
* One guard per identity declared on the contract.
|
|
82
70
|
*/
|
|
83
|
-
type GuardsForSchemes<Schemes extends Record<string, SecurityScheme>> = { [Name in keyof Schemes]: GuardRun<ExpressHandlerContext> };
|
|
84
71
|
/**
|
|
85
72
|
* The resolver functions for the request context schemas declared on `kizuna`,
|
|
86
73
|
* keyed by name. Each runs on every route and returns its schema's value.
|
|
87
74
|
*/
|
|
88
|
-
type RequestResolverFns<RequestContext extends Record<string, RequestContextSchema>> = { [Name in keyof RequestContext]: (args: ExpressHandlerContext & {
|
|
89
|
-
params: Record<string, string>;
|
|
90
|
-
headers: RequestContextHeaderValues<RequestContext[Name]>;
|
|
91
|
-
}) => z.output<RequestContext[Name]['context']> | Promise<z.output<RequestContext[Name]['context']>> };
|
|
92
75
|
interface AppLike {
|
|
93
76
|
use: (router: Router$1) => unknown;
|
|
94
77
|
}
|
|
@@ -99,68 +82,7 @@ interface AppLike {
|
|
|
99
82
|
* api.mount(app);
|
|
100
83
|
*/
|
|
101
84
|
declare function mountExpress(api: ExpressApi, app: AppLike, options?: ExpressOptions): Router$1;
|
|
102
|
-
|
|
103
|
-
interface Server<R extends Routes, Schemes extends Record<string, SecurityScheme>, Auth, RequestContext extends Record<string, RequestContextSchema>, Plugins extends ContractPlugins, J extends Jobs = Jobs> {
|
|
104
|
-
/**
|
|
105
|
-
* Define a guard for one of the contract's identities. It runs before the
|
|
106
|
-
* handlers of every route whose `auth` entry requires the identity, and
|
|
107
|
-
* receives the credential its method extracted (`bearer`, `apiKey`, or
|
|
108
|
-
* `basic`, `null` when absent). Return the identity's context and access
|
|
109
|
-
* fields to allow the request, or call `deny(status, detail)`.
|
|
110
|
-
*/
|
|
111
|
-
guard<const Name extends Extract<keyof Schemes, string>>(name: Name, run: GuardFns<Schemes, GuardParams<R, Auth, Name>>[Name]): GuardRun<ExpressHandlerContext>;
|
|
112
|
-
/**
|
|
113
|
-
* Define a request context resolver declared on the contract. It runs on
|
|
114
|
-
* every route, public ones included, and never denies.
|
|
115
|
-
*/
|
|
116
|
-
requestContext<const Name extends Extract<keyof RequestContext, string>>(name: Name, run: RequestResolverFns<RequestContext>[Name]): RequestContextRun<ExpressHandlerContext>;
|
|
117
|
-
/**
|
|
118
|
-
* Write typed handlers for the contract or one of its route groups.
|
|
119
|
-
*/
|
|
120
|
-
router: {
|
|
121
|
-
<const GroupOrRoutes extends Extract<keyof Router<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>, string> | Routes>(group: GroupOrRoutes, router: GroupRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>, GroupOrRoutes>): GroupRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>, GroupOrRoutes>;
|
|
122
|
-
(router: Router<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>): Router<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>;
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Write a handler for each of the contract's jobs.
|
|
126
|
-
*
|
|
127
|
-
* Pass a `transport` to say where a queued job goes. Without one, `queue`
|
|
128
|
-
* runs the job in this process and it is lost on a crash.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* export const jobs = server.jobs({
|
|
132
|
-
* sendDigests: async () => ({
|
|
133
|
-
* status: 200,
|
|
134
|
-
* body: {
|
|
135
|
-
* sent: await sendPendingDigests(),
|
|
136
|
-
* },
|
|
137
|
-
* }),
|
|
138
|
-
* });
|
|
139
|
-
*/
|
|
140
|
-
jobs(handlers: JobsRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>): JobsRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>;
|
|
141
|
-
/**
|
|
142
|
-
* Assemble the router, guards, and job handlers into the api object.
|
|
143
|
-
*/
|
|
144
|
-
api(options: {
|
|
145
|
-
router: Router<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>;
|
|
146
|
-
} & (string extends keyof Schemes ? {
|
|
147
|
-
guards?: undefined;
|
|
148
|
-
} : {
|
|
149
|
-
guards: NoInfer<GuardsForSchemes<Schemes>>;
|
|
150
|
-
}) & (string extends keyof J ? {
|
|
151
|
-
jobs?: undefined;
|
|
152
|
-
} : {
|
|
153
|
-
jobs: NoInfer<JobsRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>>;
|
|
154
|
-
}) & (string extends keyof RequestContext ? {
|
|
155
|
-
requestContext?: undefined;
|
|
156
|
-
} : {
|
|
157
|
-
requestContext: NoInfer<{ [Name in keyof RequestContext]: RequestContextRun<ExpressHandlerContext> }>;
|
|
158
|
-
}) & (string extends keyof Plugins ? {
|
|
159
|
-
plugins?: undefined;
|
|
160
|
-
} : {
|
|
161
|
-
plugins: PluginImplementations<Plugins, ExpressHandlerContext>;
|
|
162
|
-
})): ExpressApi<R>;
|
|
163
|
-
}
|
|
85
|
+
interface Server<C extends Contract> extends Server$1<C, ExpressHandlerContext, ExpressApi<RoutesOf<C>>> {}
|
|
164
86
|
/**
|
|
165
87
|
* Turn a contract into a server handle: the serving counterpart to `Kizuna`.
|
|
166
88
|
* Keep the instance and use `server.guard` to define guards, `server.router`
|
|
@@ -181,13 +103,13 @@ interface Server<R extends Routes, Schemes extends Record<string, SecurityScheme
|
|
|
181
103
|
* },
|
|
182
104
|
* });
|
|
183
105
|
*/
|
|
184
|
-
declare class KizunaServer<
|
|
185
|
-
readonly guard: Server<
|
|
186
|
-
readonly requestContext: Server<
|
|
187
|
-
readonly router: Server<
|
|
188
|
-
readonly jobs: Server<
|
|
189
|
-
readonly api: Server<
|
|
190
|
-
constructor(contract:
|
|
106
|
+
declare class KizunaServer<C extends Contract> implements Server<C> {
|
|
107
|
+
readonly guard: Server<C>['guard'];
|
|
108
|
+
readonly requestContext: Server<C>['requestContext'];
|
|
109
|
+
readonly router: Server<C>['router'];
|
|
110
|
+
readonly jobs: Server<C>['jobs'];
|
|
111
|
+
readonly api: Server<C>['api'];
|
|
112
|
+
constructor(contract: C, options?: ServerOptions);
|
|
191
113
|
}
|
|
192
114
|
//#endregion
|
|
193
115
|
export { AppLike, ExpressApi, ExpressHandlerContext, ExpressOptions, JobsRouter, KizunaServer, RouteHandler, Router, Server, mountExpress };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Request, Response, Router as Router$1 } from "express";
|
|
2
|
-
import { ApiWithRouter,
|
|
3
|
-
import {
|
|
4
|
-
import { Contract, CredentialOf, GuardSuccess, JobHandlers, JobsArg, RequestContextHeaderValues, RequestContextSchema, SecurityScheme, TagOptions } from "@ts-kizuna/core";
|
|
2
|
+
import { ApiWithRouter, ContractJobsRouter, ContractRouter, ErrorFormatter, GUARDS_META, JOBS_META, REQUEST_CONTEXT_META, RouteDefinition, RouteHandler as RouteHandler$1, Routes, SCHEMES_META, Server as Server$1, ServerOptions } from "@ts-kizuna/core/adapter";
|
|
3
|
+
import { Contract, RoutesOf } from "@ts-kizuna/core";
|
|
5
4
|
|
|
6
5
|
//#region src/server.d.ts
|
|
7
6
|
type ExpressApi<R extends Routes = Routes> = ApiWithRouter<R> & {
|
|
@@ -30,18 +29,12 @@ type RouteHandler<R extends RouteDefinition> = RouteHandler$1<R, ExpressHandlerC
|
|
|
30
29
|
* secured by the contract's `auth` map additionally receive each required
|
|
31
30
|
* identity's context in their handler args, under `auth`, keyed by the identity's name.
|
|
32
31
|
*/
|
|
33
|
-
type Router<C> =
|
|
32
|
+
type Router<C> = ContractRouter<C, ExpressHandlerContext>;
|
|
34
33
|
/**
|
|
35
34
|
* The handler for each of a contract's scheduled jobs, typed against it. Each
|
|
36
35
|
* receives only the job's `input`, so the same handler can be run in process.
|
|
37
36
|
*/
|
|
38
|
-
type JobsRouter<C> = C
|
|
39
|
-
/**
|
|
40
|
-
* The handlers for a group named on the contract, or for a bare route group.
|
|
41
|
-
* Both forms resolve through one signature: a second candidate of the same
|
|
42
|
-
* arity costs zero-argument handlers their contextual type.
|
|
43
|
-
*/
|
|
44
|
-
type GroupRouter<Source, GroupOrRoutes> = GroupOrRoutes extends string ? Router<Source>[Extract<GroupOrRoutes, keyof Router<Source>>] : Router<GroupOrRoutes>;
|
|
37
|
+
type JobsRouter<C> = ContractJobsRouter<C>;
|
|
45
38
|
declare global {
|
|
46
39
|
namespace Express {
|
|
47
40
|
interface Request {
|
|
@@ -72,23 +65,13 @@ interface ExpressOptions {
|
|
|
72
65
|
* authentication-only identity (no context, no access) returns nothing on
|
|
73
66
|
* success, or `deny(...)`.
|
|
74
67
|
*/
|
|
75
|
-
type GuardFns<Schemes extends Record<string, SecurityScheme>, Params> = { [Name in keyof Schemes]: (args: ExpressHandlerContext & CredentialOf<Schemes[Name]> & {
|
|
76
|
-
params: Params;
|
|
77
|
-
deny: GuardDeny;
|
|
78
|
-
scopes: string[];
|
|
79
|
-
}) => [keyof GuardSuccess<Schemes[Name]>] extends [never] ? void | GuardDenial | Promise<void | GuardDenial> : GuardSuccess<Schemes[Name]> | GuardDenial | Promise<GuardSuccess<Schemes[Name]> | GuardDenial> };
|
|
80
68
|
/**
|
|
81
69
|
* One guard per identity declared on the contract.
|
|
82
70
|
*/
|
|
83
|
-
type GuardsForSchemes<Schemes extends Record<string, SecurityScheme>> = { [Name in keyof Schemes]: GuardRun<ExpressHandlerContext> };
|
|
84
71
|
/**
|
|
85
72
|
* The resolver functions for the request context schemas declared on `kizuna`,
|
|
86
73
|
* keyed by name. Each runs on every route and returns its schema's value.
|
|
87
74
|
*/
|
|
88
|
-
type RequestResolverFns<RequestContext extends Record<string, RequestContextSchema>> = { [Name in keyof RequestContext]: (args: ExpressHandlerContext & {
|
|
89
|
-
params: Record<string, string>;
|
|
90
|
-
headers: RequestContextHeaderValues<RequestContext[Name]>;
|
|
91
|
-
}) => z.output<RequestContext[Name]['context']> | Promise<z.output<RequestContext[Name]['context']>> };
|
|
92
75
|
interface AppLike {
|
|
93
76
|
use: (router: Router$1) => unknown;
|
|
94
77
|
}
|
|
@@ -99,68 +82,7 @@ interface AppLike {
|
|
|
99
82
|
* api.mount(app);
|
|
100
83
|
*/
|
|
101
84
|
declare function mountExpress(api: ExpressApi, app: AppLike, options?: ExpressOptions): Router$1;
|
|
102
|
-
|
|
103
|
-
interface Server<R extends Routes, Schemes extends Record<string, SecurityScheme>, Auth, RequestContext extends Record<string, RequestContextSchema>, Plugins extends ContractPlugins, J extends Jobs = Jobs> {
|
|
104
|
-
/**
|
|
105
|
-
* Define a guard for one of the contract's identities. It runs before the
|
|
106
|
-
* handlers of every route whose `auth` entry requires the identity, and
|
|
107
|
-
* receives the credential its method extracted (`bearer`, `apiKey`, or
|
|
108
|
-
* `basic`, `null` when absent). Return the identity's context and access
|
|
109
|
-
* fields to allow the request, or call `deny(status, detail)`.
|
|
110
|
-
*/
|
|
111
|
-
guard<const Name extends Extract<keyof Schemes, string>>(name: Name, run: GuardFns<Schemes, GuardParams<R, Auth, Name>>[Name]): GuardRun<ExpressHandlerContext>;
|
|
112
|
-
/**
|
|
113
|
-
* Define a request context resolver declared on the contract. It runs on
|
|
114
|
-
* every route, public ones included, and never denies.
|
|
115
|
-
*/
|
|
116
|
-
requestContext<const Name extends Extract<keyof RequestContext, string>>(name: Name, run: RequestResolverFns<RequestContext>[Name]): RequestContextRun<ExpressHandlerContext>;
|
|
117
|
-
/**
|
|
118
|
-
* Write typed handlers for the contract or one of its route groups.
|
|
119
|
-
*/
|
|
120
|
-
router: {
|
|
121
|
-
<const GroupOrRoutes extends Extract<keyof Router<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>, string> | Routes>(group: GroupOrRoutes, router: GroupRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>, GroupOrRoutes>): GroupRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>, GroupOrRoutes>;
|
|
122
|
-
(router: Router<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>): Router<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>;
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Write a handler for each of the contract's jobs.
|
|
126
|
-
*
|
|
127
|
-
* Pass a `transport` to say where a queued job goes. Without one, `queue`
|
|
128
|
-
* runs the job in this process and it is lost on a crash.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* export const jobs = server.jobs({
|
|
132
|
-
* sendDigests: async () => ({
|
|
133
|
-
* status: 200,
|
|
134
|
-
* body: {
|
|
135
|
-
* sent: await sendPendingDigests(),
|
|
136
|
-
* },
|
|
137
|
-
* }),
|
|
138
|
-
* });
|
|
139
|
-
*/
|
|
140
|
-
jobs(handlers: JobsRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>): JobsRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>;
|
|
141
|
-
/**
|
|
142
|
-
* Assemble the router, guards, and job handlers into the api object.
|
|
143
|
-
*/
|
|
144
|
-
api(options: {
|
|
145
|
-
router: Router<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>;
|
|
146
|
-
} & (string extends keyof Schemes ? {
|
|
147
|
-
guards?: undefined;
|
|
148
|
-
} : {
|
|
149
|
-
guards: NoInfer<GuardsForSchemes<Schemes>>;
|
|
150
|
-
}) & (string extends keyof J ? {
|
|
151
|
-
jobs?: undefined;
|
|
152
|
-
} : {
|
|
153
|
-
jobs: NoInfer<JobsRouter<ServerContract<R, Schemes, Auth, RequestContext, Plugins, J>>>;
|
|
154
|
-
}) & (string extends keyof RequestContext ? {
|
|
155
|
-
requestContext?: undefined;
|
|
156
|
-
} : {
|
|
157
|
-
requestContext: NoInfer<{ [Name in keyof RequestContext]: RequestContextRun<ExpressHandlerContext> }>;
|
|
158
|
-
}) & (string extends keyof Plugins ? {
|
|
159
|
-
plugins?: undefined;
|
|
160
|
-
} : {
|
|
161
|
-
plugins: PluginImplementations<Plugins, ExpressHandlerContext>;
|
|
162
|
-
})): ExpressApi<R>;
|
|
163
|
-
}
|
|
85
|
+
interface Server<C extends Contract> extends Server$1<C, ExpressHandlerContext, ExpressApi<RoutesOf<C>>> {}
|
|
164
86
|
/**
|
|
165
87
|
* Turn a contract into a server handle: the serving counterpart to `Kizuna`.
|
|
166
88
|
* Keep the instance and use `server.guard` to define guards, `server.router`
|
|
@@ -181,13 +103,13 @@ interface Server<R extends Routes, Schemes extends Record<string, SecurityScheme
|
|
|
181
103
|
* },
|
|
182
104
|
* });
|
|
183
105
|
*/
|
|
184
|
-
declare class KizunaServer<
|
|
185
|
-
readonly guard: Server<
|
|
186
|
-
readonly requestContext: Server<
|
|
187
|
-
readonly router: Server<
|
|
188
|
-
readonly jobs: Server<
|
|
189
|
-
readonly api: Server<
|
|
190
|
-
constructor(contract:
|
|
106
|
+
declare class KizunaServer<C extends Contract> implements Server<C> {
|
|
107
|
+
readonly guard: Server<C>['guard'];
|
|
108
|
+
readonly requestContext: Server<C>['requestContext'];
|
|
109
|
+
readonly router: Server<C>['router'];
|
|
110
|
+
readonly jobs: Server<C>['jobs'];
|
|
111
|
+
readonly api: Server<C>['api'];
|
|
112
|
+
constructor(contract: C, options?: ServerOptions);
|
|
191
113
|
}
|
|
192
114
|
//#endregion
|
|
193
115
|
export { AppLike, ExpressApi, ExpressHandlerContext, ExpressOptions, JobsRouter, KizunaServer, RouteHandler, Router, Server, mountExpress };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Router } from "express";
|
|
2
2
|
import { Readable } from "node:stream";
|
|
3
|
-
import { GUARDS_META, JOBS_META, REQUEST_CONTEXT_META, ROUTER_META, SCHEMES_META,
|
|
3
|
+
import { GUARDS_META, JOBS_META, REQUEST_CONTEXT_META, ROUTER_META, SCHEMES_META, createAdapter, createServerSurface, jobRouter, jobRoutes, jobRunnerFrom, pluginExportsOf, pluginRouterOf, pluginRoutesOf, renderJsonResult } from "@ts-kizuna/core/adapter";
|
|
4
4
|
//#region src/server.ts
|
|
5
5
|
/**
|
|
6
6
|
* Write a web `Response` to a node response. Plugins answer in web terms to stay
|
|
@@ -107,25 +107,6 @@ function mountExpress(api, app, options) {
|
|
|
107
107
|
app.use(expressRouter);
|
|
108
108
|
return expressRouter;
|
|
109
109
|
}
|
|
110
|
-
const createServerSurface = (contract, options) => {
|
|
111
|
-
warnUnsupportedJobOptions(contract.jobs, options?.jobTransport);
|
|
112
|
-
return {
|
|
113
|
-
guard: (_name, run) => run,
|
|
114
|
-
requestContext: (_name, run) => run,
|
|
115
|
-
router: (groupOrRouter, groupRouter) => groupRouter ?? groupOrRouter,
|
|
116
|
-
jobs: (handlers) => handlers,
|
|
117
|
-
api: ({ jobs, ...parts }) => {
|
|
118
|
-
const api = Object.assign(assembleApi(contract, parts), { [JOBS_META]: contract.jobs ? {
|
|
119
|
-
jobs: contract.jobs,
|
|
120
|
-
handlers: jobs ?? {},
|
|
121
|
-
config: contract.jobsConfig,
|
|
122
|
-
transport: options?.jobTransport,
|
|
123
|
-
onError: options?.onJobError
|
|
124
|
-
} : void 0 });
|
|
125
|
-
return Object.assign(api, { mount: (app, mountOptions) => mountExpress(api, app, mountOptions) });
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
110
|
/**
|
|
130
111
|
* Turn a contract into a server handle: the serving counterpart to `Kizuna`.
|
|
131
112
|
* Keep the instance and use `server.guard` to define guards, `server.router`
|
|
@@ -148,7 +129,10 @@ const createServerSurface = (contract, options) => {
|
|
|
148
129
|
*/
|
|
149
130
|
var KizunaServer = class {
|
|
150
131
|
constructor(contract, options) {
|
|
151
|
-
Object.assign(this, createServerSurface(contract, options)
|
|
132
|
+
Object.assign(this, createServerSurface(contract, options, (assembled) => {
|
|
133
|
+
const api = assembled;
|
|
134
|
+
return Object.assign(api, { mount: (app, mountOptions) => mountExpress(api, app, mountOptions) });
|
|
135
|
+
}));
|
|
152
136
|
}
|
|
153
137
|
};
|
|
154
138
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-kizuna/express",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.51.0",
|
|
4
4
|
"description": "Express adapter for ts-kizuna",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ts-kizuna",
|
|
@@ -57,15 +57,15 @@
|
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"express": "^5.0.0",
|
|
59
59
|
"zod": "^4.0.0",
|
|
60
|
-
"@ts-kizuna/core": "1.
|
|
60
|
+
"@ts-kizuna/core": "1.51.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/express": "^5.0.0",
|
|
64
64
|
"express": "^5.0.0",
|
|
65
65
|
"tsdown": "^0.21.0",
|
|
66
|
-
"typescript": "^
|
|
66
|
+
"typescript": "^6.0.3",
|
|
67
67
|
"zod": "^4.0.0",
|
|
68
|
-
"@ts-kizuna/core": "1.
|
|
68
|
+
"@ts-kizuna/core": "1.51.0"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "tsdown src/index.ts --format esm,cjs --dts --clean --external @ts-kizuna/core --external express --external zod",
|