@fluojs/core 1.0.0-beta.1
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.ko.md +165 -0
- package/README.md +167 -0
- package/dist/decorators.d.ts +51 -0
- package/dist/decorators.d.ts.map +1 -0
- package/dist/decorators.js +79 -0
- package/dist/errors.d.ts +60 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +89 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +2 -0
- package/dist/metadata/class-di.d.ts +30 -0
- package/dist/metadata/class-di.d.ts.map +1 -0
- package/dist/metadata/class-di.js +72 -0
- package/dist/metadata/controller-route.d.ts +7 -0
- package/dist/metadata/controller-route.d.ts.map +1 -0
- package/dist/metadata/controller-route.js +109 -0
- package/dist/metadata/injection.d.ts +5 -0
- package/dist/metadata/injection.d.ts.map +1 -0
- package/dist/metadata/injection.js +31 -0
- package/dist/metadata/module.d.ts +16 -0
- package/dist/metadata/module.d.ts.map +1 -0
- package/dist/metadata/module.js +57 -0
- package/dist/metadata/shared.d.ts +128 -0
- package/dist/metadata/shared.d.ts.map +1 -0
- package/dist/metadata/shared.js +231 -0
- package/dist/metadata/store.d.ts +16 -0
- package/dist/metadata/store.d.ts.map +1 -0
- package/dist/metadata/store.js +25 -0
- package/dist/metadata/symbol-metadata-polyfill.d.ts +2 -0
- package/dist/metadata/symbol-metadata-polyfill.d.ts.map +1 -0
- package/dist/metadata/symbol-metadata-polyfill.js +4 -0
- package/dist/metadata/types.d.ts +210 -0
- package/dist/metadata/types.d.ts.map +1 -0
- package/dist/metadata/types.js +1 -0
- package/dist/metadata/validation.d.ts +11 -0
- package/dist/metadata/validation.d.ts.map +1 -0
- package/dist/metadata/validation.js +93 -0
- package/dist/metadata.d.ts +9 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +7 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +19 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +103 -0
- package/package.json +52 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A constructable type that yields `T`.
|
|
3
|
+
*
|
|
4
|
+
* The `any[]` parameter list is intentional — this type models "some class that
|
|
5
|
+
* produces T" for DI token resolution, not a safely-callable constructor
|
|
6
|
+
* signature. Using `unknown[]` would break assignability for any class with
|
|
7
|
+
* typed constructor parameters (variance rules make `[string]` incompatible
|
|
8
|
+
* with `unknown[]` in `new` signatures). Every major DI framework (NestJS,
|
|
9
|
+
* Angular, tsyringe, inversify) uses the same pattern for the same reason.
|
|
10
|
+
*/
|
|
11
|
+
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
12
|
+
/**
|
|
13
|
+
* Public dependency token accepted by Fluo containers, decorators, and module metadata.
|
|
14
|
+
*
|
|
15
|
+
* Class constructors act as self-describing tokens, while strings and symbols support
|
|
16
|
+
* interface-like or cross-package registrations where no concrete class should leak.
|
|
17
|
+
*/
|
|
18
|
+
export type Token<T = unknown> = string | symbol | Constructor<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Value that may be returned synchronously or wrapped in a `Promise`.
|
|
21
|
+
*
|
|
22
|
+
* This keeps factory helpers and lifecycle hooks flexible without forcing every caller to
|
|
23
|
+
* treat the operation as asynchronous.
|
|
24
|
+
*/
|
|
25
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Factory configuration for module helpers that compute options during bootstrap.
|
|
28
|
+
*
|
|
29
|
+
* @typeParam T Resolved options shape returned to the module factory.
|
|
30
|
+
*/
|
|
31
|
+
export interface AsyncModuleOptions<T> {
|
|
32
|
+
inject?: Token[];
|
|
33
|
+
useFactory: (...deps: unknown[]) => MaybePromise<T>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Metadata property name supported by Fluo's shared metadata stores.
|
|
37
|
+
*/
|
|
38
|
+
export type MetadataPropertyKey = string | symbol;
|
|
39
|
+
/**
|
|
40
|
+
* Canonical request-data origins used by packages that describe how metadata values are bound.
|
|
41
|
+
*/
|
|
42
|
+
export type MetadataSource = 'path' | 'query' | 'header' | 'cookie' | 'body';
|
|
43
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,OAAO,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAEjE;;;;;GAKG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,GAAG,OAAO,IAAI,MAAM,GAAG,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C;;;;GAIG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,UAAU,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,MAAM,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clones a value through `structuredClone()` and falls back to the hardened internal clone path when needed.
|
|
3
|
+
*
|
|
4
|
+
* @param value Value to clone.
|
|
5
|
+
* @returns A cloned value produced by `structuredClone()` when available, or `fallbackClone()` when the runtime clone fails.
|
|
6
|
+
*/
|
|
7
|
+
export declare function cloneWithFallback<T>(value: T): T;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a best-effort deep clone for runtimes where `structuredClone()` is not available or throws.
|
|
10
|
+
*
|
|
11
|
+
* Supported fallback shapes include arrays, dates, regular expressions, maps, sets, typed arrays,
|
|
12
|
+
* array buffers, plain objects, and custom prototype-based instances with symbol-keyed properties
|
|
13
|
+
* and circular references preserved.
|
|
14
|
+
*
|
|
15
|
+
* @param value Value to clone through the fallback path.
|
|
16
|
+
* @returns A deep clone for supported runtime shapes, or the original value for primitives/functions.
|
|
17
|
+
*/
|
|
18
|
+
export declare function fallbackClone<T>(value: T): T;
|
|
19
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAmGA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAMhD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAE5C"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function cloneIntoDescriptorValue(descriptor, seen) {
|
|
2
|
+
if (!('value' in descriptor)) {
|
|
3
|
+
return descriptor;
|
|
4
|
+
}
|
|
5
|
+
return {
|
|
6
|
+
...descriptor,
|
|
7
|
+
value: cloneFallbackValue(descriptor.value, seen)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function cloneFallbackValue(value, seen) {
|
|
11
|
+
if (typeof value !== 'object' || value === null) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
const existing = seen.get(value);
|
|
15
|
+
if (existing) {
|
|
16
|
+
return existing;
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
const cloned = [];
|
|
20
|
+
seen.set(value, cloned);
|
|
21
|
+
cloned.push(...value.map(item => cloneFallbackValue(item, seen)));
|
|
22
|
+
return cloned;
|
|
23
|
+
}
|
|
24
|
+
if (value instanceof Date) {
|
|
25
|
+
const cloned = new Date(value.getTime());
|
|
26
|
+
seen.set(value, cloned);
|
|
27
|
+
return cloned;
|
|
28
|
+
}
|
|
29
|
+
if (value instanceof RegExp) {
|
|
30
|
+
const cloned = new RegExp(value.source, value.flags);
|
|
31
|
+
cloned.lastIndex = value.lastIndex;
|
|
32
|
+
seen.set(value, cloned);
|
|
33
|
+
return cloned;
|
|
34
|
+
}
|
|
35
|
+
if (value instanceof Map) {
|
|
36
|
+
const cloned = new Map();
|
|
37
|
+
seen.set(value, cloned);
|
|
38
|
+
for (const [key, entryValue] of value.entries()) {
|
|
39
|
+
cloned.set(cloneFallbackValue(key, seen), cloneFallbackValue(entryValue, seen));
|
|
40
|
+
}
|
|
41
|
+
return cloned;
|
|
42
|
+
}
|
|
43
|
+
if (value instanceof Set) {
|
|
44
|
+
const cloned = new Set();
|
|
45
|
+
seen.set(value, cloned);
|
|
46
|
+
for (const entryValue of value.values()) {
|
|
47
|
+
cloned.add(cloneFallbackValue(entryValue, seen));
|
|
48
|
+
}
|
|
49
|
+
return cloned;
|
|
50
|
+
}
|
|
51
|
+
if (value instanceof DataView) {
|
|
52
|
+
const cloned = new DataView(value.buffer.slice(value.byteOffset, value.byteOffset + value.byteLength));
|
|
53
|
+
seen.set(value, cloned);
|
|
54
|
+
return cloned;
|
|
55
|
+
}
|
|
56
|
+
if (ArrayBuffer.isView(value)) {
|
|
57
|
+
const cloned = new value.constructor(value);
|
|
58
|
+
seen.set(value, cloned);
|
|
59
|
+
return cloned;
|
|
60
|
+
}
|
|
61
|
+
if (value instanceof ArrayBuffer) {
|
|
62
|
+
const cloned = value.slice(0);
|
|
63
|
+
seen.set(value, cloned);
|
|
64
|
+
return cloned;
|
|
65
|
+
}
|
|
66
|
+
const cloned = Object.create(Object.getPrototypeOf(value));
|
|
67
|
+
seen.set(value, cloned);
|
|
68
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
69
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
70
|
+
if (descriptor) {
|
|
71
|
+
Object.defineProperty(cloned, key, cloneIntoDescriptorValue(descriptor, seen));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return cloned;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Clones a value through `structuredClone()` and falls back to the hardened internal clone path when needed.
|
|
79
|
+
*
|
|
80
|
+
* @param value Value to clone.
|
|
81
|
+
* @returns A cloned value produced by `structuredClone()` when available, or `fallbackClone()` when the runtime clone fails.
|
|
82
|
+
*/
|
|
83
|
+
export function cloneWithFallback(value) {
|
|
84
|
+
try {
|
|
85
|
+
return structuredClone(value);
|
|
86
|
+
} catch {
|
|
87
|
+
return fallbackClone(value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Creates a best-effort deep clone for runtimes where `structuredClone()` is not available or throws.
|
|
93
|
+
*
|
|
94
|
+
* Supported fallback shapes include arrays, dates, regular expressions, maps, sets, typed arrays,
|
|
95
|
+
* array buffers, plain objects, and custom prototype-based instances with symbol-keyed properties
|
|
96
|
+
* and circular references preserved.
|
|
97
|
+
*
|
|
98
|
+
* @param value Value to clone through the fallback path.
|
|
99
|
+
* @returns A deep clone for supported runtime shapes, or the original value for primitives/functions.
|
|
100
|
+
*/
|
|
101
|
+
export function fallbackClone(value) {
|
|
102
|
+
return cloneFallbackValue(value, new WeakMap());
|
|
103
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluojs/core",
|
|
3
|
+
"description": "Shared contracts, decorators, and metadata helpers that form the foundation of every Fluo package.",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"fluo",
|
|
6
|
+
"core",
|
|
7
|
+
"decorators",
|
|
8
|
+
"metadata",
|
|
9
|
+
"types",
|
|
10
|
+
"foundation"
|
|
11
|
+
],
|
|
12
|
+
"version": "1.0.0-beta.1",
|
|
13
|
+
"private": false,
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/fluojs/fluo.git",
|
|
18
|
+
"directory": "packages/core"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20.0.0"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./internal": {
|
|
33
|
+
"types": "./dist/internal.d.ts",
|
|
34
|
+
"import": "./dist/internal.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"main": "./dist/index.js",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"vitest": "^3.2.4"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"prebuild": "node ../../tooling/scripts/clean-dist.mjs",
|
|
47
|
+
"build": "pnpm exec babel src --extensions .ts --ignore 'src/**/*.test.ts' --out-dir dist --config-file ../../tooling/babel/babel.config.cjs && pnpm exec tsc -p tsconfig.build.json",
|
|
48
|
+
"typecheck": "pnpm exec tsc -p tsconfig.json --noEmit",
|
|
49
|
+
"test": "pnpm exec vitest run -c vitest.config.ts",
|
|
50
|
+
"test:watch": "pnpm exec vitest -c vitest.config.ts"
|
|
51
|
+
}
|
|
52
|
+
}
|