@asterflow/router 2.0.2 → 2.2.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/cjs/index.cjs +31 -29
- package/dist/mjs/index.js +21 -20
- package/dist/types/controllers/Method.d.ts +19 -3
- package/package.json +4 -4
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,38 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var h = Object.defineProperty;
|
|
3
3
|
var x = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var
|
|
4
|
+
var R = Object.getOwnPropertyNames;
|
|
5
5
|
var w = Object.prototype.hasOwnProperty;
|
|
6
6
|
var f = (r, e) => {
|
|
7
7
|
for (var t in e)
|
|
8
|
-
|
|
9
|
-
}, g = (r, e, t,
|
|
8
|
+
h(r, t, { get: e[t], enumerable: !0 });
|
|
9
|
+
}, g = (r, e, t, o) => {
|
|
10
10
|
if (e && typeof e == "object" || typeof e == "function")
|
|
11
|
-
for (let n of
|
|
12
|
-
!w.call(r, n) && n !== t &&
|
|
11
|
+
for (let n of R(e))
|
|
12
|
+
!w.call(r, n) && n !== t && h(r, n, { get: () => e[n], enumerable: !(o = x(e, n)) || o.enumerable });
|
|
13
13
|
return r;
|
|
14
14
|
};
|
|
15
|
-
var A = (r) => g(
|
|
15
|
+
var A = (r) => g(h({}, "__esModule", { value: !0 }), r);
|
|
16
16
|
// packages/router/src/index.ts
|
|
17
|
-
var
|
|
18
|
-
f(
|
|
19
|
-
Method: () =>
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
var O = {};
|
|
18
|
+
f(O, {
|
|
19
|
+
Method: () => E,
|
|
20
|
+
MethodClass: () => i,
|
|
21
|
+
MethodType: () => m,
|
|
22
|
+
Middleware: () => u,
|
|
22
23
|
RouteMethodBuilder: () => a,
|
|
23
24
|
Router: () => d,
|
|
24
25
|
RouterBuilder: () => p,
|
|
25
26
|
getRouteExtensions: () => S,
|
|
26
|
-
setRouteExtensions: () =>
|
|
27
|
+
setRouteExtensions: () => l
|
|
27
28
|
});
|
|
28
|
-
module.exports = A(
|
|
29
|
+
module.exports = A(O);
|
|
29
30
|
// packages/router/src/controllers/extensionRegistry.ts
|
|
30
|
-
var
|
|
31
|
-
function
|
|
32
|
-
Object.keys(e).length !== 0 &&
|
|
31
|
+
var c = new WeakMap();
|
|
32
|
+
function l(r, e) {
|
|
33
|
+
Object.keys(e).length !== 0 && c.set(r, e);
|
|
33
34
|
}
|
|
34
35
|
function S(r) {
|
|
35
|
-
return
|
|
36
|
+
return c.get(r);
|
|
36
37
|
}
|
|
37
38
|
// packages/router/src/controllers/Router.ts
|
|
38
39
|
var d = class r {
|
|
@@ -44,8 +45,8 @@ var d = class r {
|
|
|
44
45
|
methods;
|
|
45
46
|
use;
|
|
46
47
|
constructor(e) {
|
|
47
|
-
let { name: t, path:
|
|
48
|
-
this.name = t, this.path =
|
|
48
|
+
let { name: t, path: o, param: n, schema: y, description: P, methods: M } = e;
|
|
49
|
+
this.name = t, this.path = o ?? n, this.schema = y, this.description = P, this.methods = M, this.use = e.use;
|
|
49
50
|
}
|
|
50
51
|
static create() {
|
|
51
52
|
return (e) => new r(e);
|
|
@@ -67,12 +68,12 @@ var d = class r {
|
|
|
67
68
|
super({ ...e, methods: {} });
|
|
68
69
|
}
|
|
69
70
|
method(e, t) {
|
|
70
|
-
let
|
|
71
|
-
return this.methods[e] =
|
|
71
|
+
let o = t(new a());
|
|
72
|
+
return this.methods[e] = o.handler, Object.keys(o.registrations).length > 0 && (this.perMethodRegistrations[e] = o.registrations, l(this, this.perMethodRegistrations)), this;
|
|
72
73
|
}
|
|
73
74
|
};
|
|
74
75
|
// packages/router/src/controllers/Middleware.ts
|
|
75
|
-
var
|
|
76
|
+
var u = class {
|
|
76
77
|
name;
|
|
77
78
|
onRun;
|
|
78
79
|
constructor(e) {
|
|
@@ -80,7 +81,7 @@ var l = class {
|
|
|
80
81
|
}
|
|
81
82
|
};
|
|
82
83
|
// packages/router/src/controllers/Method.ts
|
|
83
|
-
var
|
|
84
|
+
var i = class r {
|
|
84
85
|
static ALL = "all";
|
|
85
86
|
static GET = "get";
|
|
86
87
|
static POST = "post";
|
|
@@ -98,10 +99,10 @@ var u = class r {
|
|
|
98
99
|
handler;
|
|
99
100
|
extensions = {};
|
|
100
101
|
constructor(e, t) {
|
|
101
|
-
this.path = t.path ?? t.param, this.method = e, this.schema = t.schema, this.use = t.use, this.handler = t.handler ?? ((
|
|
102
|
-
if (typeof
|
|
102
|
+
this.path = t.path ?? t.param, this.method = e, this.schema = t.schema, this.use = t.use, this.handler = t.handler ?? ((o) => {
|
|
103
|
+
if (typeof o != "function")
|
|
103
104
|
throw new TypeError("This route was built with Method.create(...) but never finished with a terminal .handler(...) call before being used.");
|
|
104
|
-
return this.handler =
|
|
105
|
+
return this.handler = o, this;
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
108
|
static create(e, t = {}) {
|
|
@@ -113,11 +114,12 @@ var u = class r {
|
|
|
113
114
|
extend(e, t) {
|
|
114
115
|
return t && Object.assign(this.extensions, t), this;
|
|
115
116
|
}
|
|
116
|
-
};
|
|
117
|
+
}, E = i;
|
|
117
118
|
// packages/router/src/types/method.ts
|
|
118
|
-
var
|
|
119
|
+
var m = ((s) => (s.all = "all", s.get = "get", s.post = "post", s.put = "put", s.delete = "delete", s.options = "options", s.head = "head", s.patch = "patch", s))(m || {});
|
|
119
120
|
0 && (module.exports = {
|
|
120
121
|
Method,
|
|
122
|
+
MethodClass,
|
|
121
123
|
MethodType,
|
|
122
124
|
Middleware,
|
|
123
125
|
RouteMethodBuilder,
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// packages/router/src/controllers/extensionRegistry.ts
|
|
2
|
-
var
|
|
3
|
-
function
|
|
4
|
-
Object.keys(e).length !== 0 &&
|
|
2
|
+
var i = new WeakMap();
|
|
3
|
+
function h(r, e) {
|
|
4
|
+
Object.keys(e).length !== 0 && i.set(r, e);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
return
|
|
6
|
+
function M(r) {
|
|
7
|
+
return i.get(r);
|
|
8
8
|
}
|
|
9
9
|
// packages/router/src/controllers/Router.ts
|
|
10
10
|
var n = class r {
|
|
@@ -16,8 +16,8 @@ var n = class r {
|
|
|
16
16
|
methods;
|
|
17
17
|
use;
|
|
18
18
|
constructor(e) {
|
|
19
|
-
let { name: t, path:
|
|
20
|
-
this.name = t, this.path =
|
|
19
|
+
let { name: t, path: o, param: u, schema: c, description: m, methods: y } = e;
|
|
20
|
+
this.name = t, this.path = o ?? u, this.schema = c, this.description = m, this.methods = y, this.use = e.use;
|
|
21
21
|
}
|
|
22
22
|
static create() {
|
|
23
23
|
return (e) => new r(e);
|
|
@@ -39,12 +39,12 @@ var n = class r {
|
|
|
39
39
|
super({ ...e, methods: {} });
|
|
40
40
|
}
|
|
41
41
|
method(e, t) {
|
|
42
|
-
let
|
|
43
|
-
return this.methods[e] =
|
|
42
|
+
let o = t(new d());
|
|
43
|
+
return this.methods[e] = o.handler, Object.keys(o.registrations).length > 0 && (this.perMethodRegistrations[e] = o.registrations, h(this, this.perMethodRegistrations)), this;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
// packages/router/src/controllers/Middleware.ts
|
|
47
|
-
var
|
|
47
|
+
var l = class {
|
|
48
48
|
name;
|
|
49
49
|
onRun;
|
|
50
50
|
constructor(e) {
|
|
@@ -52,7 +52,7 @@ var h = class {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
// packages/router/src/controllers/Method.ts
|
|
55
|
-
var
|
|
55
|
+
var p = class r {
|
|
56
56
|
static ALL = "all";
|
|
57
57
|
static GET = "get";
|
|
58
58
|
static POST = "post";
|
|
@@ -70,10 +70,10 @@ var l = class r {
|
|
|
70
70
|
handler;
|
|
71
71
|
extensions = {};
|
|
72
72
|
constructor(e, t) {
|
|
73
|
-
this.path = t.path ?? t.param, this.method = e, this.schema = t.schema, this.use = t.use, this.handler = t.handler ?? ((
|
|
74
|
-
if (typeof
|
|
73
|
+
this.path = t.path ?? t.param, this.method = e, this.schema = t.schema, this.use = t.use, this.handler = t.handler ?? ((o) => {
|
|
74
|
+
if (typeof o != "function")
|
|
75
75
|
throw new TypeError("This route was built with Method.create(...) but never finished with a terminal .handler(...) call before being used.");
|
|
76
|
-
return this.handler =
|
|
76
|
+
return this.handler = o, this;
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
static create(e, t = {}) {
|
|
@@ -85,16 +85,17 @@ var l = class r {
|
|
|
85
85
|
extend(e, t) {
|
|
86
86
|
return t && Object.assign(this.extensions, t), this;
|
|
87
87
|
}
|
|
88
|
-
};
|
|
88
|
+
}, g = p;
|
|
89
89
|
// packages/router/src/types/method.ts
|
|
90
|
-
var P = ((
|
|
90
|
+
var P = ((s) => (s.all = "all", s.get = "get", s.post = "post", s.put = "put", s.delete = "delete", s.options = "options", s.head = "head", s.patch = "patch", s))(P || {});
|
|
91
91
|
export {
|
|
92
|
-
|
|
92
|
+
g as Method,
|
|
93
|
+
p as MethodClass,
|
|
93
94
|
P as MethodType,
|
|
94
|
-
|
|
95
|
+
l as Middleware,
|
|
95
96
|
d as RouteMethodBuilder,
|
|
96
97
|
n as Router,
|
|
97
98
|
a as RouterBuilder,
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
M as getRouteExtensions,
|
|
100
|
+
h as setRouteExtensions
|
|
100
101
|
};
|
|
@@ -6,6 +6,20 @@ import type { MiddlewareOutput } from '../types/mindleware';
|
|
|
6
6
|
import type { AnySchema } from '../types/schema';
|
|
7
7
|
import type { MergeProps } from '../types/utils';
|
|
8
8
|
import type { Middleware } from './Middleware';
|
|
9
|
+
export interface MethodConstructor {
|
|
10
|
+
new <Responder extends Responders, const Path extends string = string, const Drive extends Runtime = Runtime, const MethodKey extends MethodKeys = MethodKeys, const Schema extends AnySchema = AnySchema, const Middlewares extends readonly Middleware<Responder, Schema, string, Record<string, unknown>>[] = [], const Context = MiddlewareOutput<Middlewares>, const Instance extends AnyAsterflow = AnyAsterflow, const Handler extends MethodHandler<Path, Drive, Responder, Schema, Middlewares, Context, Instance, {}> = MethodHandler<Path, Drive, Responder, Schema, Middlewares, Context, Instance, {}>>(method: MethodKey, options: MethodConstructorOptions<MethodCallProps<Responder, Path, Drive, MethodKey, Schema, Middlewares, Context, Instance, {}, Handler>>): Method<MethodCallProps<Responder, Path, Drive, MethodKey, Schema, Middlewares, Context, Instance, {}, Handler>>;
|
|
11
|
+
/** Convenience constants for `new Method(Method.POST, {...})` / `Method.create(Method.POST)` - a plain `'post'` string works just as well. */
|
|
12
|
+
readonly ALL: 'all';
|
|
13
|
+
readonly GET: 'get';
|
|
14
|
+
readonly POST: 'post';
|
|
15
|
+
readonly PUT: 'put';
|
|
16
|
+
readonly DELETE: 'delete';
|
|
17
|
+
readonly OPTIONS: 'options';
|
|
18
|
+
readonly HEAD: 'head';
|
|
19
|
+
readonly PATCH: 'patch';
|
|
20
|
+
create: typeof MethodClass.create;
|
|
21
|
+
readonly prototype: MethodClass<any>;
|
|
22
|
+
}
|
|
9
23
|
/**
|
|
10
24
|
* `handler`'s field type: a concrete `MethodHandler<...>` once finished, or
|
|
11
25
|
* - while `Handler` is `undefined` (pending) - the terminal chain call
|
|
@@ -14,7 +28,7 @@ import type { Middleware } from './Middleware';
|
|
|
14
28
|
export type MethodHandlerSlot<Props extends MethodProps> = Props['handler'] extends undefined ? <H extends MethodHandler<Props['path'], Props['drive'], Props['responder'], Props['schema'], Props['middlewares'], Props['context'], Props['instance'], Props['requestExt']>>(fn: H) => Method<MergeProps<Props, {
|
|
15
29
|
handler: H;
|
|
16
30
|
}>> : Props['handler'];
|
|
17
|
-
export declare class
|
|
31
|
+
export declare class MethodClass<const Props extends MethodProps = DefaultMethodProps> {
|
|
18
32
|
/** Convenience constants for `new Method(Method.POST, {...})` / `Method.create(Method.POST)` - a plain `'post'` string works just as well. */
|
|
19
33
|
static readonly ALL: 'all';
|
|
20
34
|
static readonly GET: 'get';
|
|
@@ -58,8 +72,8 @@ export declare class Method<const Props extends MethodProps = DefaultMethodProps
|
|
|
58
72
|
* each its own.
|
|
59
73
|
*
|
|
60
74
|
* Plugins add their own chain method via `declare module '@asterflow/router'
|
|
61
|
-
* { interface
|
|
62
|
-
* `
|
|
75
|
+
* { interface MethodClass<...> { theirMethod(...): Method<...> } }` plus a real
|
|
76
|
+
* `MethodClass.prototype.theirMethod = ...` implementation calling `extend`.
|
|
63
77
|
*/
|
|
64
78
|
static create<Responder extends Responders, const Path extends string = string, const Drive extends Runtime = Runtime, const MethodKey extends MethodKeys = MethodKeys, const Schema extends AnySchema = AnySchema, const Middlewares extends readonly Middleware<Responder, Schema, string, Record<string, unknown>>[] = []>(method: MethodKey, options?: MethodBuilderOptions<MethodCallProps<Responder, Path, Drive, MethodKey, Schema, Middlewares, MiddlewareOutput<Middlewares>, AnyAsterflow, {}, undefined>>): Method<MethodCallProps<Responder, Path, Drive, MethodKey, Schema, Middlewares, MiddlewareOutput<Middlewares>, AnyAsterflow, {}, undefined>>;
|
|
65
79
|
/**
|
|
@@ -73,3 +87,5 @@ export declare class Method<const Props extends MethodProps = DefaultMethodProps
|
|
|
73
87
|
handler: Props['handler'] extends undefined ? undefined : any;
|
|
74
88
|
}>>;
|
|
75
89
|
}
|
|
90
|
+
export type Method<Props extends MethodProps = DefaultMethodProps> = MethodClass<Props>;
|
|
91
|
+
export declare const Method: MethodConstructor;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asterflow/router",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Typed route and middleware definitions (Method, Router, Middleware) for AsterFlow applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"asterflow",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"node": ">=20"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@asterflow/request": "^2.0
|
|
40
|
-
"@asterflow/response": "^2.0
|
|
39
|
+
"@asterflow/request": "^2.2.0",
|
|
40
|
+
"@asterflow/response": "^2.2.0",
|
|
41
41
|
"@asterflow/url-parser": "^4.1.1",
|
|
42
|
-
"asterflow": "^2.0
|
|
42
|
+
"asterflow": "^2.2.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@caeljs/tsh": "^1.1.3",
|