@anvil-di/bellows 0.0.5 → 0.0.6
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/decorators.d.ts +25 -8
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +21 -0
- package/dist/decorators.js.map +1 -1
- package/package.json +2 -2
- package/src/decorators.ts +21 -56
- package/src/dual-decorators.test.ts +43 -0
package/dist/decorators.d.ts
CHANGED
|
@@ -16,16 +16,33 @@ export declare function Patch(_path: string): <This, Args extends readonly unkno
|
|
|
16
16
|
* an injected `SseStream` param — see `@anvil-di/bellows`'s `SseStream`.
|
|
17
17
|
*/
|
|
18
18
|
export declare function Sse(_path: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Usable as either a class or method decorator: `@Middleware(fn) class Ctrl {}`
|
|
21
|
+
* or `@Middleware(fn) handler() {}`. Deliberately has no typed overloads —
|
|
22
|
+
* TS's decorator-overload resolution always binds the first matching
|
|
23
|
+
* signature regardless of the actual target, so a class-decorator overload
|
|
24
|
+
* and a method-decorator overload with identical outer parameter lists can't
|
|
25
|
+
* coexist (whichever is declared second fails to typecheck at its call
|
|
26
|
+
* sites). A single loosely-typed signature checks correctly at both.
|
|
27
|
+
*/
|
|
28
|
+
export declare function Middleware(..._fns: ExpressMiddleware[]): any;
|
|
21
29
|
export declare function Tag(_name: string): <T extends abstract new (...args: never[]) => unknown>(target: T, ctx: ClassDecoratorContext<T>) => T;
|
|
22
30
|
export declare function Returns(_status: number, _schema?: unknown): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export declare function
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Usable as either a class or method decorator — see the note on
|
|
33
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
34
|
+
*/
|
|
35
|
+
export declare function Security(_scheme: string): any;
|
|
36
|
+
/**
|
|
37
|
+
* Usable as either a class or method decorator — see the note on
|
|
38
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
39
|
+
*/
|
|
40
|
+
export declare function Authn(..._services: AuthnServiceClass[]): any;
|
|
41
|
+
/**
|
|
42
|
+
* Usable as either a class or method decorator — see the note on
|
|
43
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
44
|
+
*/
|
|
45
|
+
export declare function Authz(..._services: AuthzServiceClass[]): any;
|
|
29
46
|
export declare function Deprecated(_reason?: string): <This, Args extends readonly unknown[], Return>(target: (this: This, ...args: Args) => Return, ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
|
|
30
47
|
export {};
|
|
31
48
|
//# sourceMappingURL=decorators.d.ts.map
|
package/dist/decorators.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE7D,MAAM,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAG/C,KAAK,iBAAiB,GAAG,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC1E,KAAK,iBAAiB,GAAG,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,YAAY,CAAC;AAEhE,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,GACZ,CAAC,CAAC,S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G,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,KAC1E,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAEzC;AAED;;;GAGG;AAEH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAE7C;AAED;;;GAGG;AAEH,wBAAgB,KAAK,CAAC,GAAG,SAAS,EAAE,iBAAiB,EAAE,GAAG,GAAG,CAE5D;AAED;;;GAGG;AAEH,wBAAgB,KAAK,CAAC,GAAG,SAAS,EAAE,iBAAiB,EAAE,GAAG,GAAG,CAE5D;AAED,wBAAgB,UAAU,CACxB,OAAO,CAAC,EAAE,MAAM,GACf,CAAC,IAAI,EAAE,IAAI,SAAS,SAAS,OAAO,EAAE,EAAE,MAAM,EAC/C,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,EAC7C,GAAG,EAAE,2BAA2B,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,KAC1E,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAEzC"}
|
package/dist/decorators.js
CHANGED
|
@@ -25,6 +25,15 @@ export function Patch(_path) {
|
|
|
25
25
|
export function Sse(_path) {
|
|
26
26
|
return (target, _ctx) => target;
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Usable as either a class or method decorator: `@Middleware(fn) class Ctrl {}`
|
|
30
|
+
* or `@Middleware(fn) handler() {}`. Deliberately has no typed overloads —
|
|
31
|
+
* TS's decorator-overload resolution always binds the first matching
|
|
32
|
+
* signature regardless of the actual target, so a class-decorator overload
|
|
33
|
+
* and a method-decorator overload with identical outer parameter lists can't
|
|
34
|
+
* coexist (whichever is declared second fails to typecheck at its call
|
|
35
|
+
* sites). A single loosely-typed signature checks correctly at both.
|
|
36
|
+
*/
|
|
28
37
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
38
|
export function Middleware(..._fns) {
|
|
30
39
|
return (target) => target;
|
|
@@ -35,14 +44,26 @@ export function Tag(_name) {
|
|
|
35
44
|
export function Returns(_status, _schema) {
|
|
36
45
|
return (target, _ctx) => target;
|
|
37
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Usable as either a class or method decorator — see the note on
|
|
49
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
50
|
+
*/
|
|
38
51
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
52
|
export function Security(_scheme) {
|
|
40
53
|
return (target) => target;
|
|
41
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Usable as either a class or method decorator — see the note on
|
|
57
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
58
|
+
*/
|
|
42
59
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
60
|
export function Authn(..._services) {
|
|
44
61
|
return (target) => target;
|
|
45
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Usable as either a class or method decorator — see the note on
|
|
65
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
66
|
+
*/
|
|
46
67
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
68
|
export function Authz(..._services) {
|
|
48
69
|
return (target) => target;
|
package/dist/decorators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,UAAU,CACxB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,GAAG,CACjB,KAAa;IAKb,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,IAAI,CAClB,KAAa;IAKb,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
|
4
4
|
"description": "Runtime types and decorator stubs for anvil-bellows NestJS-style controller codegen.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"src"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@anvil-di/bellows-cli": "0.0.
|
|
21
|
+
"@anvil-di/bellows-cli": "0.0.6"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"express": ">=4"
|
package/src/decorators.ts
CHANGED
|
@@ -76,20 +76,15 @@ export function Sse(
|
|
|
76
76
|
return (target, _ctx) => target;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
...fns: ExpressMiddleware[]
|
|
89
|
-
): <This, Args extends readonly unknown[], Return>(
|
|
90
|
-
target: (this: This, ...args: Args) => Return,
|
|
91
|
-
ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>,
|
|
92
|
-
) => (this: This, ...args: Args) => Return;
|
|
79
|
+
/**
|
|
80
|
+
* Usable as either a class or method decorator: `@Middleware(fn) class Ctrl {}`
|
|
81
|
+
* or `@Middleware(fn) handler() {}`. Deliberately has no typed overloads —
|
|
82
|
+
* TS's decorator-overload resolution always binds the first matching
|
|
83
|
+
* signature regardless of the actual target, so a class-decorator overload
|
|
84
|
+
* and a method-decorator overload with identical outer parameter lists can't
|
|
85
|
+
* coexist (whichever is declared second fails to typecheck at its call
|
|
86
|
+
* sites). A single loosely-typed signature checks correctly at both.
|
|
87
|
+
*/
|
|
93
88
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
89
|
export function Middleware(..._fns: ExpressMiddleware[]): any {
|
|
95
90
|
return (target: unknown) => target;
|
|
@@ -114,58 +109,28 @@ export function Returns(
|
|
|
114
109
|
return (target, _ctx) => target;
|
|
115
110
|
}
|
|
116
111
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
target: T,
|
|
122
|
-
ctx: ClassDecoratorContext<T>,
|
|
123
|
-
) => T;
|
|
124
|
-
// Method-decorator overload: `@Security("bearer") handler() {}`
|
|
125
|
-
export function Security(
|
|
126
|
-
scheme: string,
|
|
127
|
-
): <This, Args extends readonly unknown[], Return>(
|
|
128
|
-
target: (this: This, ...args: Args) => Return,
|
|
129
|
-
ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>,
|
|
130
|
-
) => (this: This, ...args: Args) => Return;
|
|
112
|
+
/**
|
|
113
|
+
* Usable as either a class or method decorator — see the note on
|
|
114
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
115
|
+
*/
|
|
131
116
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
117
|
export function Security(_scheme: string): any {
|
|
133
118
|
return (target: unknown) => target;
|
|
134
119
|
}
|
|
135
120
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
target: T,
|
|
141
|
-
ctx: ClassDecoratorContext<T>,
|
|
142
|
-
) => T;
|
|
143
|
-
// Method-decorator overload: `@Authn(SessionAuthn) handler() {}`
|
|
144
|
-
export function Authn(
|
|
145
|
-
...services: AuthnServiceClass[]
|
|
146
|
-
): <This, Args extends readonly unknown[], Return>(
|
|
147
|
-
target: (this: This, ...args: Args) => Return,
|
|
148
|
-
ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>,
|
|
149
|
-
) => (this: This, ...args: Args) => Return;
|
|
121
|
+
/**
|
|
122
|
+
* Usable as either a class or method decorator — see the note on
|
|
123
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
124
|
+
*/
|
|
150
125
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
126
|
export function Authn(..._services: AuthnServiceClass[]): any {
|
|
152
127
|
return (target: unknown) => target;
|
|
153
128
|
}
|
|
154
129
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
target: T,
|
|
160
|
-
ctx: ClassDecoratorContext<T>,
|
|
161
|
-
) => T;
|
|
162
|
-
// Method-decorator overload: `@Authz(RoleAuthz) handler() {}`
|
|
163
|
-
export function Authz(
|
|
164
|
-
...services: AuthzServiceClass[]
|
|
165
|
-
): <This, Args extends readonly unknown[], Return>(
|
|
166
|
-
target: (this: This, ...args: Args) => Return,
|
|
167
|
-
ctx: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>,
|
|
168
|
-
) => (this: This, ...args: Args) => Return;
|
|
130
|
+
/**
|
|
131
|
+
* Usable as either a class or method decorator — see the note on
|
|
132
|
+
* `Middleware`'s signature above for why this has no typed overloads.
|
|
133
|
+
*/
|
|
169
134
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
170
135
|
export function Authz(..._services: AuthzServiceClass[]): any {
|
|
171
136
|
return (target: unknown) => target;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { Authn, Authz, Middleware, Security } from "./decorators.js";
|
|
3
|
+
import type { AuthnResult, AuthnService, AuthzDecision, AuthzService } from "./authz.js";
|
|
4
|
+
|
|
5
|
+
// Regression test for a TS decorator-overload bug: `Authn`/`Authz`/`Middleware`/
|
|
6
|
+
// `Security` must typecheck when applied as BOTH a class decorator and a
|
|
7
|
+
// method decorator in the same compilation unit. Overloaded signatures with
|
|
8
|
+
// identical outer parameter lists can't be disambiguated by TS's decorator
|
|
9
|
+
// checker (it always binds the first match regardless of target), so these
|
|
10
|
+
// decorators are intentionally loosely typed — this file exists to catch a
|
|
11
|
+
// regression to typed overloads at compile time.
|
|
12
|
+
|
|
13
|
+
class NoopAuthn implements AuthnService<{ id: string }, "bearerAuth"> {
|
|
14
|
+
identify(): AuthnResult<{ id: string }> {
|
|
15
|
+
return { identified: false };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
class NoopAuthz implements AuthzService {
|
|
20
|
+
authorize(): AuthzDecision {
|
|
21
|
+
return "next";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const noopMiddleware = (_req: unknown, _res: unknown, next: () => void): void => next();
|
|
26
|
+
|
|
27
|
+
@Authn(NoopAuthn)
|
|
28
|
+
@Authz(NoopAuthz)
|
|
29
|
+
@Middleware(noopMiddleware)
|
|
30
|
+
@Security("bearerAuth")
|
|
31
|
+
class ClassLevelController {
|
|
32
|
+
@Authn(NoopAuthn)
|
|
33
|
+
@Authz(NoopAuthz)
|
|
34
|
+
@Middleware(noopMiddleware)
|
|
35
|
+
@Security("bearerAuth")
|
|
36
|
+
handler(): void {}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe("dual class/method decorators", () => {
|
|
40
|
+
it("compiles and constructs at both levels", () => {
|
|
41
|
+
expect(new ClassLevelController()).toBeInstanceOf(ClassLevelController);
|
|
42
|
+
});
|
|
43
|
+
});
|