@fougere/decorators 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fougere contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @fougere/decorators
|
|
2
|
+
> The configuration sugar
|
|
3
|
+
`@config` — a decorator states a **fact**; it never changes the runtime in a
|
|
4
|
+
non-obvious way.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @fougere/decorators
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
Part of [Fougere](https://github.com/chok/fougere) — one schema, a gradient from
|
|
14
|
+
monolith to distributed, the same user code.
|
|
15
|
+
Reference documentation: [the site](https://chok.github.io/fougere/) (en/fr).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TC39 Stage 3 decorator — marks a class or method as part of the frond's
|
|
3
|
+
* public contract.
|
|
4
|
+
*
|
|
5
|
+
* On a class: sets `__exposed = true` (readable via `isExposed()`).
|
|
6
|
+
* On a method: collects method name in a WeakMap keyed by class (readable via `getExposedMethods()`).
|
|
7
|
+
*
|
|
8
|
+
* This is syntactic sugar — the source of truth for exposure can also be
|
|
9
|
+
* `defineFrond({ expose: [...] })` in `frond.config.ts`, which takes precedence.
|
|
10
|
+
*/
|
|
11
|
+
export declare function expose(target: Function, context: ClassDecoratorContext): void;
|
|
12
|
+
export declare function expose(target: Function, context: ClassMethodDecoratorContext): void;
|
|
13
|
+
/** Check whether a class has been marked with `@expose`. */
|
|
14
|
+
export declare function isExposed(cls: Function): boolean;
|
|
15
|
+
/** Get method names marked with `@expose` on a class. Requires one instantiation to populate. */
|
|
16
|
+
export declare function getExposedMethods(cls: Function): Set<string>;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,wBAAgB,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAAC;AAC/E,wBAAgB,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,2BAA2B,GAAG,IAAI,CAAC;AAqBrF,4DAA4D;AAC5D,wBAAgB,SAAS,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAEhD;AAED,iGAAiG;AACjG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAM5D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TC39 Stage 3 decorator — marks a class or method as part of the frond's
|
|
3
|
+
* public contract.
|
|
4
|
+
*
|
|
5
|
+
* On a class: sets `__exposed = true` (readable via `isExposed()`).
|
|
6
|
+
* On a method: collects method name in a WeakMap keyed by class (readable via `getExposedMethods()`).
|
|
7
|
+
*
|
|
8
|
+
* This is syntactic sugar — the source of truth for exposure can also be
|
|
9
|
+
* `defineFrond({ expose: [...] })` in `frond.config.ts`, which takes precedence.
|
|
10
|
+
*/
|
|
11
|
+
const exposedMethods = new WeakMap();
|
|
12
|
+
export function expose(target, context) {
|
|
13
|
+
if (context.kind === 'class') {
|
|
14
|
+
target.__exposed = true;
|
|
15
|
+
}
|
|
16
|
+
if (context.kind === 'method') {
|
|
17
|
+
context.addInitializer(function () {
|
|
18
|
+
const ctor = this.constructor;
|
|
19
|
+
let set = exposedMethods.get(ctor);
|
|
20
|
+
if (!set) {
|
|
21
|
+
set = new Set();
|
|
22
|
+
exposedMethods.set(ctor, set);
|
|
23
|
+
}
|
|
24
|
+
set.add(context.name);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Check whether a class has been marked with `@expose`. */
|
|
29
|
+
export function isExposed(cls) {
|
|
30
|
+
return cls.__exposed === true;
|
|
31
|
+
}
|
|
32
|
+
/** Get method names marked with `@expose` on a class. Requires one instantiation to populate. */
|
|
33
|
+
export function getExposedMethods(cls) {
|
|
34
|
+
// Trigger initializers if not already done
|
|
35
|
+
if (!exposedMethods.has(cls)) {
|
|
36
|
+
try {
|
|
37
|
+
new cls();
|
|
38
|
+
}
|
|
39
|
+
catch { /* best effort */ }
|
|
40
|
+
}
|
|
41
|
+
return exposedMethods.get(cls) ?? new Set();
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,cAAc,GAAG,IAAI,OAAO,EAAuB,CAAC;AAI1D,MAAM,UAAU,MAAM,CACpB,MAAgB,EAChB,OAA4D;IAE5D,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,MAAc,CAAC,SAAS,GAAG,IAAI,CAAC;IACnC,CAAC;IACD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,CAAC,cAAc,CAAC;YACrB,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC;YAC9B,IAAI,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;gBAChB,cAAc,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YAChC,CAAC;YACD,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAc,CAAC,CAAC;QAClC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,SAAS,CAAC,GAAa;IACrC,OAAQ,GAAW,CAAC,SAAS,KAAK,IAAI,CAAC;AACzC,CAAC;AAED,iGAAiG;AACjG,MAAM,UAAU,iBAAiB,CAAC,GAAa;IAC7C,2CAA2C;IAC3C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YAAC,IAAK,GAAW,EAAE,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,EAAU,CAAC;AACtD,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fougere/decorators",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Configuration sugar (@config) — declarative, never hidden runtime.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/chok/fougere.git",
|
|
9
|
+
"directory": "packages/decorators"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "rm -rf dist && tsc",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json"
|
|
31
|
+
}
|
|
32
|
+
}
|