@taserjs/router 0.0.3 → 0.0.5
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/builder/app.cjs +22 -0
- package/dist/cjs/builder/app.cjs.map +1 -0
- package/dist/cjs/builder/app.d.cts +11 -0
- package/dist/cjs/{constants.cjs → builder/constants.cjs} +1 -1
- package/dist/cjs/builder/constants.cjs.map +1 -0
- package/dist/cjs/{factories.cjs → builder/factories.cjs} +1 -1
- package/dist/cjs/builder/factories.cjs.map +1 -0
- package/dist/cjs/{factories.d.cts → builder/factories.d.cts} +2 -2
- package/dist/cjs/{middleware.cjs → builder/middleware.cjs} +1 -1
- package/dist/cjs/builder/middleware.cjs.map +1 -0
- package/dist/cjs/{middleware.d.cts → builder/middleware.d.cts} +1 -1
- package/dist/cjs/{route.cjs → builder/route.cjs} +19 -33
- package/dist/cjs/builder/route.cjs.map +1 -0
- package/dist/cjs/{route.d.cts → builder/route.d.cts} +3 -3
- package/dist/cjs/{taser-router.cjs → builder/router.cjs} +38 -11
- package/dist/cjs/builder/router.cjs.map +1 -0
- package/dist/cjs/builder/router.d.cts +48 -0
- package/dist/cjs/{create-context.cjs → context/create-context.cjs} +1 -1
- package/dist/cjs/context/create-context.cjs.map +1 -0
- package/dist/cjs/{create-context.d.cts → context/create-context.d.cts} +2 -2
- package/dist/cjs/define/middleware.cjs +13 -3
- package/dist/cjs/define/middleware.cjs.map +1 -1
- package/dist/cjs/define/middleware.d.cts +21 -4
- package/dist/cjs/define/validators.cjs +1 -1
- package/dist/cjs/define/validators.cjs.map +1 -1
- package/dist/cjs/define/validators.d.cts +1 -1
- package/dist/cjs/index.cjs +6 -16
- package/dist/cjs/index.d.cts +6 -7
- package/dist/cjs/middleware/body-limit.cjs +2 -2
- package/dist/cjs/middleware/body-limit.cjs.map +1 -1
- package/dist/cjs/middleware/compress.cjs +2 -2
- package/dist/cjs/middleware/compress.cjs.map +1 -1
- package/dist/cjs/middleware/cors.cjs +2 -2
- package/dist/cjs/middleware/cors.cjs.map +1 -1
- package/dist/cjs/middleware/csrf.cjs +2 -2
- package/dist/cjs/middleware/csrf.cjs.map +1 -1
- package/dist/cjs/middleware/etag.cjs +2 -2
- package/dist/cjs/middleware/etag.cjs.map +1 -1
- package/dist/cjs/middleware/jwk.cjs +2 -8
- package/dist/cjs/middleware/jwk.cjs.map +1 -1
- package/dist/cjs/middleware/jwt.cjs +2 -8
- package/dist/cjs/middleware/jwt.cjs.map +1 -1
- package/dist/cjs/middleware/secure-headers.cjs +2 -2
- package/dist/cjs/middleware/secure-headers.cjs.map +1 -1
- package/dist/cjs/middleware/timing.cjs +2 -2
- package/dist/cjs/middleware/timing.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.cjs +10 -0
- package/dist/cjs/middleware/wrap-hono.cjs.map +1 -1
- package/dist/cjs/middleware/wrap-hono.d.cts +4 -0
- package/dist/cjs/types/app.d.cts +7 -7
- package/dist/cjs/types/index.d.cts +73 -17
- package/dist/cjs/types/returns.d.cts +2 -2
- package/dist/cjs/types/type-utils.d.cts +1 -2
- package/dist/cjs/types/units.cjs.map +1 -1
- package/dist/cjs/types/units.d.cts +9 -12
- package/dist/esm/builder/app.d.ts +11 -0
- package/dist/esm/builder/app.js +22 -0
- package/dist/esm/builder/app.js.map +1 -0
- package/dist/esm/{constants.js → builder/constants.js} +1 -1
- package/dist/esm/builder/constants.js.map +1 -0
- package/dist/esm/{factories.d.ts → builder/factories.d.ts} +2 -2
- package/dist/esm/{factories.js → builder/factories.js} +1 -1
- package/dist/esm/builder/factories.js.map +1 -0
- package/dist/esm/{middleware.d.ts → builder/middleware.d.ts} +1 -1
- package/dist/esm/{middleware.js → builder/middleware.js} +1 -1
- package/dist/esm/builder/middleware.js.map +1 -0
- package/dist/esm/{route.d.ts → builder/route.d.ts} +3 -3
- package/dist/esm/{route.js → builder/route.js} +19 -33
- package/dist/esm/builder/route.js.map +1 -0
- package/dist/esm/builder/router.d.ts +48 -0
- package/dist/esm/{taser-router.js → builder/router.js} +37 -10
- package/dist/esm/builder/router.js.map +1 -0
- package/dist/esm/{create-context.d.ts → context/create-context.d.ts} +2 -2
- package/dist/esm/{create-context.js → context/create-context.js} +1 -1
- package/dist/esm/context/create-context.js.map +1 -0
- package/dist/esm/define/middleware.d.ts +21 -4
- package/dist/esm/define/middleware.js +13 -3
- package/dist/esm/define/middleware.js.map +1 -1
- package/dist/esm/define/validators.d.ts +1 -1
- package/dist/esm/define/validators.js +1 -1
- package/dist/esm/define/validators.js.map +1 -1
- package/dist/esm/index.d.ts +6 -7
- package/dist/esm/index.js +5 -6
- package/dist/esm/middleware/body-limit.js +2 -2
- package/dist/esm/middleware/body-limit.js.map +1 -1
- package/dist/esm/middleware/compress.js +2 -2
- package/dist/esm/middleware/compress.js.map +1 -1
- package/dist/esm/middleware/cors.js +2 -2
- package/dist/esm/middleware/cors.js.map +1 -1
- package/dist/esm/middleware/csrf.js +2 -2
- package/dist/esm/middleware/csrf.js.map +1 -1
- package/dist/esm/middleware/etag.js +2 -2
- package/dist/esm/middleware/etag.js.map +1 -1
- package/dist/esm/middleware/jwk.js +2 -8
- package/dist/esm/middleware/jwk.js.map +1 -1
- package/dist/esm/middleware/jwt.js +2 -8
- package/dist/esm/middleware/jwt.js.map +1 -1
- package/dist/esm/middleware/secure-headers.js +2 -2
- package/dist/esm/middleware/secure-headers.js.map +1 -1
- package/dist/esm/middleware/timing.js +2 -2
- package/dist/esm/middleware/timing.js.map +1 -1
- package/dist/esm/middleware/wrap-hono.d.ts +4 -0
- package/dist/esm/middleware/wrap-hono.js +10 -1
- package/dist/esm/middleware/wrap-hono.js.map +1 -1
- package/dist/esm/types/app.d.ts +7 -7
- package/dist/esm/types/index.d.ts +73 -17
- package/dist/esm/types/returns.d.ts +2 -2
- package/dist/esm/types/type-utils.d.ts +1 -2
- package/dist/esm/types/units.d.ts +9 -12
- package/dist/esm/types/units.js.map +1 -1
- package/package.json +3 -3
- package/src/builder/app.ts +28 -0
- package/src/{factories.ts → builder/factories.ts} +2 -2
- package/src/{middleware.ts → builder/middleware.ts} +2 -2
- package/src/{route.ts → builder/route.ts} +30 -34
- package/src/builder/router.ts +347 -0
- package/src/{create-context.ts → context/create-context.ts} +2 -2
- package/src/define/middleware.ts +197 -7
- package/src/define/validators.ts +1 -1
- package/src/index.ts +9 -12
- package/src/middleware/body-limit.ts +2 -2
- package/src/middleware/compress.ts +2 -2
- package/src/middleware/cors.ts +2 -2
- package/src/middleware/csrf.ts +2 -2
- package/src/middleware/etag.ts +2 -2
- package/src/middleware/jwk.ts +2 -7
- package/src/middleware/jwt.ts +2 -7
- package/src/middleware/secure-headers.ts +2 -2
- package/src/middleware/timing.ts +2 -2
- package/src/middleware/wrap-hono.ts +13 -0
- package/src/types/app.ts +12 -8
- package/src/types/index.ts +145 -16
- package/src/types/returns.ts +2 -2
- package/src/types/type-utils.ts +1 -2
- package/src/types/units.ts +10 -9
- package/dist/cjs/constants.cjs.map +0 -1
- package/dist/cjs/create-context.cjs.map +0 -1
- package/dist/cjs/factories.cjs.map +0 -1
- package/dist/cjs/middleware.cjs.map +0 -1
- package/dist/cjs/route.cjs.map +0 -1
- package/dist/cjs/taser-app.cjs +0 -36
- package/dist/cjs/taser-app.cjs.map +0 -1
- package/dist/cjs/taser-app.d.cts +0 -18
- package/dist/cjs/taser-router.cjs.map +0 -1
- package/dist/cjs/taser-router.d.cts +0 -42
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/create-context.js.map +0 -1
- package/dist/esm/factories.js.map +0 -1
- package/dist/esm/middleware.js.map +0 -1
- package/dist/esm/route.js.map +0 -1
- package/dist/esm/taser-app.d.ts +0 -18
- package/dist/esm/taser-app.js +0 -35
- package/dist/esm/taser-app.js.map +0 -1
- package/dist/esm/taser-router.d.ts +0 -42
- package/dist/esm/taser-router.js.map +0 -1
- package/src/taser-app.ts +0 -38
- package/src/taser-router.ts +0 -165
- /package/dist/cjs/{constants.d.cts → builder/constants.d.cts} +0 -0
- /package/dist/esm/{constants.d.ts → builder/constants.d.ts} +0 -0
- /package/src/{constants.ts → builder/constants.ts} +0 -0
package/dist/esm/taser-app.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { TaserRuntime, RouteManifestShape } from '@taserjs/router-core';
|
|
2
|
-
declare class TaserServeView {
|
|
3
|
-
protected readonly runtime: TaserRuntime;
|
|
4
|
-
constructor(runtime: TaserRuntime);
|
|
5
|
-
fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response>;
|
|
6
|
-
native(native: unknown): TaserNativeBound;
|
|
7
|
-
}
|
|
8
|
-
export declare class TaserNativeBound {
|
|
9
|
-
private readonly runtime;
|
|
10
|
-
private readonly boundNative;
|
|
11
|
-
constructor(runtime: TaserRuntime, boundNative: unknown);
|
|
12
|
-
fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response>;
|
|
13
|
-
}
|
|
14
|
-
export declare class TaserApp<TManifest extends RouteManifestShape = RouteManifestShape> extends TaserServeView {
|
|
15
|
-
readonly __manifest?: TManifest;
|
|
16
|
-
constructor(runtime: TaserRuntime, manifest?: TManifest);
|
|
17
|
-
}
|
|
18
|
-
export {};
|
package/dist/esm/taser-app.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//#region src/taser-app.ts
|
|
2
|
-
var TaserServeView = class {
|
|
3
|
-
runtime;
|
|
4
|
-
constructor(runtime) {
|
|
5
|
-
this.runtime = runtime;
|
|
6
|
-
}
|
|
7
|
-
fetch(request, env, executionCtx) {
|
|
8
|
-
return this.runtime.fetch(request, env, executionCtx);
|
|
9
|
-
}
|
|
10
|
-
native(native) {
|
|
11
|
-
return new TaserNativeBound(this.runtime, native);
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
var TaserNativeBound = class {
|
|
15
|
-
runtime;
|
|
16
|
-
boundNative;
|
|
17
|
-
constructor(runtime, boundNative) {
|
|
18
|
-
this.runtime = runtime;
|
|
19
|
-
this.boundNative = boundNative;
|
|
20
|
-
}
|
|
21
|
-
fetch(request, env, executionCtx) {
|
|
22
|
-
return this.runtime.native(this.boundNative).fetch(request, env, executionCtx);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
var TaserApp = class extends TaserServeView {
|
|
26
|
-
__manifest;
|
|
27
|
-
constructor(runtime, manifest) {
|
|
28
|
-
super(runtime);
|
|
29
|
-
if (manifest !== void 0) this.__manifest = manifest;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
//#endregion
|
|
33
|
-
export { TaserApp, TaserNativeBound };
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=taser-app.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"taser-app.js","names":[],"sources":["../../src/taser-app.ts"],"sourcesContent":["import type { TaserRuntime } from \"@taserjs/router-core\";\nimport type { RouteManifestShape } from \"@taserjs/router-core\";\n\nclass TaserServeView {\n constructor(protected readonly runtime: TaserRuntime) {}\n\n fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response> {\n return this.runtime.fetch(request, env, executionCtx as never);\n }\n\n native(native: unknown): TaserNativeBound {\n return new TaserNativeBound(this.runtime, native);\n }\n}\n\nexport class TaserNativeBound {\n constructor(\n private readonly runtime: TaserRuntime,\n private readonly boundNative: unknown,\n ) {}\n\n fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response> {\n return this.runtime.native(this.boundNative).fetch(request, env, executionCtx as never);\n }\n}\n\nexport class TaserApp<\n TManifest extends RouteManifestShape = RouteManifestShape,\n> extends TaserServeView {\n readonly __manifest?: TManifest;\n\n constructor(runtime: TaserRuntime, manifest?: TManifest) {\n super(runtime);\n if (manifest !== undefined) {\n this.__manifest = manifest;\n }\n }\n}\n"],"mappings":";AAGA,IAAM,iBAAN,MAAqB;CACY;CAA/B,YAAY,SAA0C;EAAvB,KAAA,UAAA;CAAwB;CAEvD,MAAM,SAAkB,KAAe,cAA2C;EAChF,OAAO,KAAK,QAAQ,MAAM,SAAS,KAAK,YAAqB;CAC/D;CAEA,OAAO,QAAmC;EACxC,OAAO,IAAI,iBAAiB,KAAK,SAAS,MAAM;CAClD;AACF;AAEA,IAAa,mBAAb,MAA8B;CAET;CACA;CAFnB,YACE,SACA,aACA;EAFiB,KAAA,UAAA;EACA,KAAA,cAAA;CAChB;CAEH,MAAM,SAAkB,KAAe,cAA2C;EAChF,OAAO,KAAK,QAAQ,OAAO,KAAK,WAAW,CAAC,CAAC,MAAM,SAAS,KAAK,YAAqB;CACxF;AACF;AAEA,IAAa,WAAb,cAEU,eAAe;CACvB;CAEA,YAAY,SAAuB,UAAsB;EACvD,MAAM,OAAO;EACb,IAAI,aAAa,KAAA,GACf,KAAK,aAAa;CAEtB;AACF"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { NotFoundHandler, OnErrorHandler, RouteManifestShape } from '@taserjs/router-core';
|
|
2
|
-
import { TaserApp } from './taser-app.js';
|
|
3
|
-
import { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from './types/app.js';
|
|
4
|
-
import { AppContext } from './types/units.js';
|
|
5
|
-
import { HandlerBuilder, LayoutId, MiddlewareBuilder } from './types/index.js';
|
|
6
|
-
import { Schema } from './types/schema.js';
|
|
7
|
-
import { CreateAllRoute, CreateAnyRoute, CreateWithBodyRoute, CreateWithoutBodyRoute } from './factories.js';
|
|
8
|
-
type RouterState = {
|
|
9
|
-
options: CreateTaserAppOptions;
|
|
10
|
-
contextDef: ContextDefinition<Record<string, unknown>, Record<string, unknown>>;
|
|
11
|
-
onError?: OnErrorHandler;
|
|
12
|
-
notFound?: NotFoundHandler;
|
|
13
|
-
};
|
|
14
|
-
export declare class TaserRouter<TAppContext extends Record<string, unknown> = AppContext> {
|
|
15
|
-
private readonly state;
|
|
16
|
-
constructor(options?: CreateTaserAppOptions, state?: Partial<Omit<RouterState, "options">>);
|
|
17
|
-
context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(definition: ContextDefinition<TBoot, TReq>): TaserRouter<TBoot & TReq>;
|
|
18
|
-
onError<TResponses extends import('./types/returns.js').ReturnsMap = import('./types/returns.js').ReturnsMap>(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>["handle"]): this;
|
|
19
|
-
notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown): this;
|
|
20
|
-
get: CreateWithoutBodyRoute<"GET", TAppContext>;
|
|
21
|
-
post: CreateWithBodyRoute<"POST", TAppContext>;
|
|
22
|
-
put: CreateWithBodyRoute<"PUT", TAppContext>;
|
|
23
|
-
patch: CreateWithBodyRoute<"PATCH", TAppContext>;
|
|
24
|
-
delete: CreateWithoutBodyRoute<"DELETE", TAppContext>;
|
|
25
|
-
options: CreateWithoutBodyRoute<"OPTIONS", TAppContext>;
|
|
26
|
-
head: CreateWithoutBodyRoute<"HEAD", TAppContext>;
|
|
27
|
-
any: CreateAnyRoute<TAppContext>;
|
|
28
|
-
all: CreateAllRoute<TAppContext>;
|
|
29
|
-
middleware<const Layout extends LayoutId>(layout: Layout): MiddlewareBuilder<Layout, readonly [], TAppContext>;
|
|
30
|
-
defineHandler<TQuery = unknown, TParams = unknown, TBody = unknown>(options?: {
|
|
31
|
-
query?: Schema<TQuery>;
|
|
32
|
-
params?: Schema<TParams>;
|
|
33
|
-
body?: Schema<TBody>;
|
|
34
|
-
}): HandlerBuilder<readonly [], {
|
|
35
|
-
query: TQuery;
|
|
36
|
-
params: TParams;
|
|
37
|
-
body: TBody;
|
|
38
|
-
}, {}, TAppContext>;
|
|
39
|
-
create<const TManifest extends RouteManifestShape>(manifest: TManifest): TaserApp<TManifest>;
|
|
40
|
-
}
|
|
41
|
-
export declare function createTaserApp(options?: CreateTaserAppOptions): TaserRouter;
|
|
42
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"taser-router.js","names":[],"sources":["../../src/taser-router.ts"],"sourcesContent":["import {\n createTaserRuntime,\n type NotFoundHandler,\n type OnErrorHandler,\n type RouteManifestShape,\n} from \"@taserjs/router-core\";\nimport { normalizeOnError } from \"@taserjs/router-utils\";\n\nimport {\n createAllRoute,\n createAnyRoute,\n createDeleteRoute,\n createGetRoute,\n createHeadRoute,\n createOptionsRoute,\n createPatchRoute,\n createPostRoute,\n createPutRoute,\n} from \"./factories.js\";\nimport { defineHandler } from \"./define/handler.js\";\nimport { createMiddleware } from \"./middleware.js\";\nimport { TaserApp } from \"./taser-app.js\";\nimport type { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from \"./types/app.js\";\nimport type { AppContext } from \"./types/units.js\";\nimport type { HandlerBuilder, LayoutId, MiddlewareBuilder } from \"./types/index.js\";\nimport type { Schema } from \"./types/schema.js\";\nimport type {\n CreateAllRoute,\n CreateAnyRoute,\n CreateWithBodyRoute,\n CreateWithoutBodyRoute,\n} from \"./factories.js\";\n\nfunction toOnErrorHandler(\n onErrorOptions: OnErrorOptions | OnErrorOptions[\"handle\"],\n): OnErrorHandler {\n return normalizeOnError(onErrorOptions);\n}\n\ntype RouterState = {\n options: CreateTaserAppOptions;\n contextDef: ContextDefinition<Record<string, unknown>, Record<string, unknown>>;\n onError?: OnErrorHandler;\n notFound?: NotFoundHandler;\n};\n\nconst emptyContext: ContextDefinition<Record<string, unknown>, Record<string, unknown>> = {};\n\nexport class TaserRouter<TAppContext extends Record<string, unknown> = AppContext> {\n private readonly state: RouterState;\n\n constructor(options: CreateTaserAppOptions = {}, state?: Partial<Omit<RouterState, \"options\">>) {\n this.state = {\n options,\n contextDef: state?.contextDef ?? emptyContext,\n ...(state?.onError !== undefined ? { onError: state.onError } : {}),\n ...(state?.notFound !== undefined ? { notFound: state.notFound } : {}),\n };\n }\n\n context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(\n definition: ContextDefinition<TBoot, TReq>,\n ): TaserRouter<TBoot & TReq> {\n this.state.contextDef = definition;\n return this as unknown as TaserRouter<TBoot & TReq>;\n }\n\n onError<\n TResponses extends import(\"./types/returns.js\").ReturnsMap =\n import(\"./types/returns.js\").ReturnsMap,\n >(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>[\"handle\"]): this {\n this.state.onError = toOnErrorHandler(options);\n return this;\n }\n\n notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown): this {\n this.state.notFound = (ctx) => handler(ctx);\n return this;\n }\n\n get: CreateWithoutBodyRoute<\"GET\", TAppContext> = createGetRoute as CreateWithoutBodyRoute<\n \"GET\",\n TAppContext\n >;\n post: CreateWithBodyRoute<\"POST\", TAppContext> = createPostRoute as CreateWithBodyRoute<\n \"POST\",\n TAppContext\n >;\n put: CreateWithBodyRoute<\"PUT\", TAppContext> = createPutRoute as CreateWithBodyRoute<\n \"PUT\",\n TAppContext\n >;\n patch: CreateWithBodyRoute<\"PATCH\", TAppContext> = createPatchRoute as CreateWithBodyRoute<\n \"PATCH\",\n TAppContext\n >;\n delete: CreateWithoutBodyRoute<\"DELETE\", TAppContext> =\n createDeleteRoute as CreateWithoutBodyRoute<\"DELETE\", TAppContext>;\n options: CreateWithoutBodyRoute<\"OPTIONS\", TAppContext> =\n createOptionsRoute as CreateWithoutBodyRoute<\"OPTIONS\", TAppContext>;\n head: CreateWithoutBodyRoute<\"HEAD\", TAppContext> = createHeadRoute as CreateWithoutBodyRoute<\n \"HEAD\",\n TAppContext\n >;\n any: CreateAnyRoute<TAppContext> = createAnyRoute as CreateAnyRoute<TAppContext>;\n all: CreateAllRoute<TAppContext> = createAllRoute as CreateAllRoute<TAppContext>;\n\n middleware<const Layout extends LayoutId>(\n layout: Layout,\n ): MiddlewareBuilder<Layout, readonly [], TAppContext> {\n return createMiddleware(layout) as MiddlewareBuilder<Layout, readonly [], TAppContext>;\n }\n\n defineHandler<TQuery = unknown, TParams = unknown, TBody = unknown>(options?: {\n query?: Schema<TQuery>;\n params?: Schema<TParams>;\n body?: Schema<TBody>;\n }): HandlerBuilder<\n readonly [],\n { query: TQuery; params: TParams; body: TBody },\n {},\n TAppContext\n > {\n return options === undefined\n ? defineHandler<TAppContext>()\n : defineHandler<TAppContext>(options);\n }\n\n create<const TManifest extends RouteManifestShape>(manifest: TManifest): TaserApp<TManifest> {\n const definition = this.state.contextDef;\n const validateResponse = this.state.options.response?.validate ?? true;\n const onValidationFailure = this.state.options.response?.onValidationFailure;\n const basePath = this.state.options.basePath;\n\n const hasCustomContext = definition.boot !== undefined || definition.request !== undefined;\n const bootPromise = hasCustomContext\n ? Promise.resolve(definition.boot?.() ?? ({} as Record<string, unknown>))\n : undefined;\n\n const contextFactory = hasCustomContext\n ? async ({ native }: { native?: unknown } = {}) => {\n const bootContext = (await bootPromise) ?? {};\n const requestContext = (await definition.request?.({ native: native as never })) ?? {};\n return { ...bootContext, ...requestContext };\n }\n : () => ({});\n\n const runtime = createTaserRuntime(manifest, contextFactory, {\n ...(basePath !== undefined ? { basePath } : {}),\n response: {\n validate: validateResponse,\n ...(onValidationFailure !== undefined ? { onValidationFailure } : {}),\n },\n ...(this.state.onError !== undefined ? { onError: this.state.onError } : {}),\n ...(this.state.notFound !== undefined ? { notFound: this.state.notFound } : {}),\n ...(this.state.options.cookies !== undefined ? { cookies: this.state.options.cookies } : {}),\n });\n\n return new TaserApp(runtime, manifest);\n }\n}\n\nexport function createTaserApp(options: CreateTaserAppOptions = {}): TaserRouter {\n return new TaserRouter(options);\n}\n"],"mappings":";;;;;;;AAiCA,SAAS,iBACP,gBACgB;CAChB,OAAO,iBAAiB,cAAc;AACxC;AASA,IAAM,eAAoF,CAAC;AAE3F,IAAa,cAAb,MAAmF;CACjF;CAEA,YAAY,UAAiC,CAAC,GAAG,OAA+C;EAC9F,KAAK,QAAQ;GACX;GACA,YAAY,OAAO,cAAc;GACjC,GAAI,OAAO,YAAY,KAAA,IAAY,EAAE,SAAS,MAAM,QAAQ,IAAI,CAAC;GACjE,GAAI,OAAO,aAAa,KAAA,IAAY,EAAE,UAAU,MAAM,SAAS,IAAI,CAAC;EACtE;CACF;CAEA,QACE,YAC2B;EAC3B,KAAK,MAAM,aAAa;EACxB,OAAO;CACT;CAEA,QAGE,SAAkF;EAClF,KAAK,MAAM,UAAU,iBAAiB,OAAO;EAC7C,OAAO;CACT;CAEA,SAAS,SAAyE;EAChF,KAAK,MAAM,YAAY,QAAQ,QAAQ,GAAG;EAC1C,OAAO;CACT;CAEA,MAAkD;CAIlD,OAAiD;CAIjD,MAA+C;CAI/C,QAAmD;CAInD,SACE;CACF,UACE;CACF,OAAoD;CAIpD,MAAmC;CACnC,MAAmC;CAEnC,WACE,QACqD;EACrD,OAAO,iBAAiB,MAAM;CAChC;CAEA,cAAoE,SASlE;EACA,OAAO,YAAY,KAAA,IACf,cAA2B,IAC3B,cAA2B,OAAO;CACxC;CAEA,OAAmD,UAA0C;EAC3F,MAAM,aAAa,KAAK,MAAM;EAC9B,MAAM,mBAAmB,KAAK,MAAM,QAAQ,UAAU,YAAY;EAClE,MAAM,sBAAsB,KAAK,MAAM,QAAQ,UAAU;EACzD,MAAM,WAAW,KAAK,MAAM,QAAQ;EAEpC,MAAM,mBAAmB,WAAW,SAAS,KAAA,KAAa,WAAW,YAAY,KAAA;EACjF,MAAM,cAAc,mBAChB,QAAQ,QAAQ,WAAW,OAAO,KAAM,CAAC,CAA6B,IACtE,KAAA;EAqBJ,OAAO,IAAI,SAXK,mBAAmB,UARZ,mBACnB,OAAO,EAAE,WAAiC,CAAC,MAAM;GAC/C,MAAM,cAAe,MAAM,eAAgB,CAAC;GAC5C,MAAM,iBAAkB,MAAM,WAAW,UAAU,EAAU,OAAgB,CAAC,KAAM,CAAC;GACrF,OAAO;IAAE,GAAG;IAAa,GAAG;GAAe;EAC7C,WACO,CAAC,IAEiD;GAC3D,GAAI,aAAa,KAAA,IAAY,EAAE,SAAS,IAAI,CAAC;GAC7C,UAAU;IACR,UAAU;IACV,GAAI,wBAAwB,KAAA,IAAY,EAAE,oBAAoB,IAAI,CAAC;GACrE;GACA,GAAI,KAAK,MAAM,YAAY,KAAA,IAAY,EAAE,SAAS,KAAK,MAAM,QAAQ,IAAI,CAAC;GAC1E,GAAI,KAAK,MAAM,aAAa,KAAA,IAAY,EAAE,UAAU,KAAK,MAAM,SAAS,IAAI,CAAC;GAC7E,GAAI,KAAK,MAAM,QAAQ,YAAY,KAAA,IAAY,EAAE,SAAS,KAAK,MAAM,QAAQ,QAAQ,IAAI,CAAC;EAC5F,CAEoB,GAAS,QAAQ;CACvC;AACF;AAEA,SAAgB,eAAe,UAAiC,CAAC,GAAgB;CAC/E,OAAO,IAAI,YAAY,OAAO;AAChC"}
|
package/src/taser-app.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { TaserRuntime } from "@taserjs/router-core";
|
|
2
|
-
import type { RouteManifestShape } from "@taserjs/router-core";
|
|
3
|
-
|
|
4
|
-
class TaserServeView {
|
|
5
|
-
constructor(protected readonly runtime: TaserRuntime) {}
|
|
6
|
-
|
|
7
|
-
fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response> {
|
|
8
|
-
return this.runtime.fetch(request, env, executionCtx as never);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
native(native: unknown): TaserNativeBound {
|
|
12
|
-
return new TaserNativeBound(this.runtime, native);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export class TaserNativeBound {
|
|
17
|
-
constructor(
|
|
18
|
-
private readonly runtime: TaserRuntime,
|
|
19
|
-
private readonly boundNative: unknown,
|
|
20
|
-
) {}
|
|
21
|
-
|
|
22
|
-
fetch(request: Request, env?: unknown, executionCtx?: unknown): Promise<Response> {
|
|
23
|
-
return this.runtime.native(this.boundNative).fetch(request, env, executionCtx as never);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class TaserApp<
|
|
28
|
-
TManifest extends RouteManifestShape = RouteManifestShape,
|
|
29
|
-
> extends TaserServeView {
|
|
30
|
-
readonly __manifest?: TManifest;
|
|
31
|
-
|
|
32
|
-
constructor(runtime: TaserRuntime, manifest?: TManifest) {
|
|
33
|
-
super(runtime);
|
|
34
|
-
if (manifest !== undefined) {
|
|
35
|
-
this.__manifest = manifest;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/taser-router.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createTaserRuntime,
|
|
3
|
-
type NotFoundHandler,
|
|
4
|
-
type OnErrorHandler,
|
|
5
|
-
type RouteManifestShape,
|
|
6
|
-
} from "@taserjs/router-core";
|
|
7
|
-
import { normalizeOnError } from "@taserjs/router-utils";
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
createAllRoute,
|
|
11
|
-
createAnyRoute,
|
|
12
|
-
createDeleteRoute,
|
|
13
|
-
createGetRoute,
|
|
14
|
-
createHeadRoute,
|
|
15
|
-
createOptionsRoute,
|
|
16
|
-
createPatchRoute,
|
|
17
|
-
createPostRoute,
|
|
18
|
-
createPutRoute,
|
|
19
|
-
} from "./factories.js";
|
|
20
|
-
import { defineHandler } from "./define/handler.js";
|
|
21
|
-
import { createMiddleware } from "./middleware.js";
|
|
22
|
-
import { TaserApp } from "./taser-app.js";
|
|
23
|
-
import type { ContextDefinition, CreateTaserAppOptions, OnErrorOptions } from "./types/app.js";
|
|
24
|
-
import type { AppContext } from "./types/units.js";
|
|
25
|
-
import type { HandlerBuilder, LayoutId, MiddlewareBuilder } from "./types/index.js";
|
|
26
|
-
import type { Schema } from "./types/schema.js";
|
|
27
|
-
import type {
|
|
28
|
-
CreateAllRoute,
|
|
29
|
-
CreateAnyRoute,
|
|
30
|
-
CreateWithBodyRoute,
|
|
31
|
-
CreateWithoutBodyRoute,
|
|
32
|
-
} from "./factories.js";
|
|
33
|
-
|
|
34
|
-
function toOnErrorHandler(
|
|
35
|
-
onErrorOptions: OnErrorOptions | OnErrorOptions["handle"],
|
|
36
|
-
): OnErrorHandler {
|
|
37
|
-
return normalizeOnError(onErrorOptions);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type RouterState = {
|
|
41
|
-
options: CreateTaserAppOptions;
|
|
42
|
-
contextDef: ContextDefinition<Record<string, unknown>, Record<string, unknown>>;
|
|
43
|
-
onError?: OnErrorHandler;
|
|
44
|
-
notFound?: NotFoundHandler;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const emptyContext: ContextDefinition<Record<string, unknown>, Record<string, unknown>> = {};
|
|
48
|
-
|
|
49
|
-
export class TaserRouter<TAppContext extends Record<string, unknown> = AppContext> {
|
|
50
|
-
private readonly state: RouterState;
|
|
51
|
-
|
|
52
|
-
constructor(options: CreateTaserAppOptions = {}, state?: Partial<Omit<RouterState, "options">>) {
|
|
53
|
-
this.state = {
|
|
54
|
-
options,
|
|
55
|
-
contextDef: state?.contextDef ?? emptyContext,
|
|
56
|
-
...(state?.onError !== undefined ? { onError: state.onError } : {}),
|
|
57
|
-
...(state?.notFound !== undefined ? { notFound: state.notFound } : {}),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
context<TBoot extends Record<string, unknown>, TReq extends Record<string, unknown>>(
|
|
62
|
-
definition: ContextDefinition<TBoot, TReq>,
|
|
63
|
-
): TaserRouter<TBoot & TReq> {
|
|
64
|
-
this.state.contextDef = definition;
|
|
65
|
-
return this as unknown as TaserRouter<TBoot & TReq>;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
onError<
|
|
69
|
-
TResponses extends import("./types/returns.js").ReturnsMap =
|
|
70
|
-
import("./types/returns.js").ReturnsMap,
|
|
71
|
-
>(options: OnErrorOptions<TResponses> | OnErrorOptions<TResponses>["handle"]): this {
|
|
72
|
-
this.state.onError = toOnErrorHandler(options);
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
notFound(handler: (ctx: unknown) => Response | Promise<Response> | unknown): this {
|
|
77
|
-
this.state.notFound = (ctx) => handler(ctx);
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get: CreateWithoutBodyRoute<"GET", TAppContext> = createGetRoute as CreateWithoutBodyRoute<
|
|
82
|
-
"GET",
|
|
83
|
-
TAppContext
|
|
84
|
-
>;
|
|
85
|
-
post: CreateWithBodyRoute<"POST", TAppContext> = createPostRoute as CreateWithBodyRoute<
|
|
86
|
-
"POST",
|
|
87
|
-
TAppContext
|
|
88
|
-
>;
|
|
89
|
-
put: CreateWithBodyRoute<"PUT", TAppContext> = createPutRoute as CreateWithBodyRoute<
|
|
90
|
-
"PUT",
|
|
91
|
-
TAppContext
|
|
92
|
-
>;
|
|
93
|
-
patch: CreateWithBodyRoute<"PATCH", TAppContext> = createPatchRoute as CreateWithBodyRoute<
|
|
94
|
-
"PATCH",
|
|
95
|
-
TAppContext
|
|
96
|
-
>;
|
|
97
|
-
delete: CreateWithoutBodyRoute<"DELETE", TAppContext> =
|
|
98
|
-
createDeleteRoute as CreateWithoutBodyRoute<"DELETE", TAppContext>;
|
|
99
|
-
options: CreateWithoutBodyRoute<"OPTIONS", TAppContext> =
|
|
100
|
-
createOptionsRoute as CreateWithoutBodyRoute<"OPTIONS", TAppContext>;
|
|
101
|
-
head: CreateWithoutBodyRoute<"HEAD", TAppContext> = createHeadRoute as CreateWithoutBodyRoute<
|
|
102
|
-
"HEAD",
|
|
103
|
-
TAppContext
|
|
104
|
-
>;
|
|
105
|
-
any: CreateAnyRoute<TAppContext> = createAnyRoute as CreateAnyRoute<TAppContext>;
|
|
106
|
-
all: CreateAllRoute<TAppContext> = createAllRoute as CreateAllRoute<TAppContext>;
|
|
107
|
-
|
|
108
|
-
middleware<const Layout extends LayoutId>(
|
|
109
|
-
layout: Layout,
|
|
110
|
-
): MiddlewareBuilder<Layout, readonly [], TAppContext> {
|
|
111
|
-
return createMiddleware(layout) as MiddlewareBuilder<Layout, readonly [], TAppContext>;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
defineHandler<TQuery = unknown, TParams = unknown, TBody = unknown>(options?: {
|
|
115
|
-
query?: Schema<TQuery>;
|
|
116
|
-
params?: Schema<TParams>;
|
|
117
|
-
body?: Schema<TBody>;
|
|
118
|
-
}): HandlerBuilder<
|
|
119
|
-
readonly [],
|
|
120
|
-
{ query: TQuery; params: TParams; body: TBody },
|
|
121
|
-
{},
|
|
122
|
-
TAppContext
|
|
123
|
-
> {
|
|
124
|
-
return options === undefined
|
|
125
|
-
? defineHandler<TAppContext>()
|
|
126
|
-
: defineHandler<TAppContext>(options);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
create<const TManifest extends RouteManifestShape>(manifest: TManifest): TaserApp<TManifest> {
|
|
130
|
-
const definition = this.state.contextDef;
|
|
131
|
-
const validateResponse = this.state.options.response?.validate ?? true;
|
|
132
|
-
const onValidationFailure = this.state.options.response?.onValidationFailure;
|
|
133
|
-
const basePath = this.state.options.basePath;
|
|
134
|
-
|
|
135
|
-
const hasCustomContext = definition.boot !== undefined || definition.request !== undefined;
|
|
136
|
-
const bootPromise = hasCustomContext
|
|
137
|
-
? Promise.resolve(definition.boot?.() ?? ({} as Record<string, unknown>))
|
|
138
|
-
: undefined;
|
|
139
|
-
|
|
140
|
-
const contextFactory = hasCustomContext
|
|
141
|
-
? async ({ native }: { native?: unknown } = {}) => {
|
|
142
|
-
const bootContext = (await bootPromise) ?? {};
|
|
143
|
-
const requestContext = (await definition.request?.({ native: native as never })) ?? {};
|
|
144
|
-
return { ...bootContext, ...requestContext };
|
|
145
|
-
}
|
|
146
|
-
: () => ({});
|
|
147
|
-
|
|
148
|
-
const runtime = createTaserRuntime(manifest, contextFactory, {
|
|
149
|
-
...(basePath !== undefined ? { basePath } : {}),
|
|
150
|
-
response: {
|
|
151
|
-
validate: validateResponse,
|
|
152
|
-
...(onValidationFailure !== undefined ? { onValidationFailure } : {}),
|
|
153
|
-
},
|
|
154
|
-
...(this.state.onError !== undefined ? { onError: this.state.onError } : {}),
|
|
155
|
-
...(this.state.notFound !== undefined ? { notFound: this.state.notFound } : {}),
|
|
156
|
-
...(this.state.options.cookies !== undefined ? { cookies: this.state.options.cookies } : {}),
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
return new TaserApp(runtime, manifest);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export function createTaserApp(options: CreateTaserAppOptions = {}): TaserRouter {
|
|
164
|
-
return new TaserRouter(options);
|
|
165
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|