@epsilon-asi/foundation 0.0.1-testing
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/.npm/_logs/2026-05-02T22_04_53_277Z-debug-0.log +22 -0
- package/.npm/_logs/2026-05-02T22_04_53_601Z-debug-0.log +18 -0
- package/.npm/_logs/2026-05-02T22_04_58_522Z-debug-0.log +18 -0
- package/.npm/_logs/2026-05-02T22_05_00_812Z-debug-0.log +19 -0
- package/.npm/_logs/2026-05-02T22_05_00_961Z-debug-0.log +14 -0
- package/build/decorators/factory/clone.d.ts +3 -0
- package/build/decorators/factory/clone.js +85 -0
- package/build/decorators/factory/decoratorRegistry.d.ts +2 -0
- package/build/decorators/factory/decoratorRegistry.js +213 -0
- package/build/decorators/factory/examples/accessors.d.ts +25 -0
- package/build/decorators/factory/examples/accessors.js +87 -0
- package/build/decorators/factory/examples/crud.d.ts +50 -0
- package/build/decorators/factory/examples/crud.js +120 -0
- package/build/decorators/factory/examples/orm.d.ts +45 -0
- package/build/decorators/factory/examples/orm.js +107 -0
- package/build/decorators/factory/examples/routing.d.ts +43 -0
- package/build/decorators/factory/examples/routing.js +112 -0
- package/build/decorators/factory/examples/runExamples.d.ts +1 -0
- package/build/decorators/factory/examples/runExamples.js +22 -0
- package/build/decorators/factory/examples/serialization.d.ts +24 -0
- package/build/decorators/factory/examples/serialization.js +79 -0
- package/build/decorators/factory/index.d.ts +3 -0
- package/build/decorators/factory/index.js +8 -0
- package/build/decorators/factory/snapshot.d.ts +2 -0
- package/build/decorators/factory/snapshot.js +75 -0
- package/build/decorators/factory/symbolMetadata.d.ts +2 -0
- package/build/decorators/factory/symbolMetadata.js +17 -0
- package/build/decorators/factory/types.d.ts +123 -0
- package/build/decorators/factory/types.js +2 -0
- package/build/decorators/validation/validatable.d.ts +0 -0
- package/build/decorators/validation/validatable.js +64 -0
- package/build/index.d.ts +5 -0
- package/build/index.js +12 -0
- package/build/package.json +49 -0
- package/coverage/clover.xml +220 -0
- package/coverage/coverage-final.json +6 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/clone.ts.html +352 -0
- package/coverage/lcov-report/decoratorRegistry.ts.html +1183 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +176 -0
- package/coverage/lcov-report/index.ts.html +145 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/snapshot.ts.html +370 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/symbolMetadata.ts.html +145 -0
- package/coverage/lcov.info +490 -0
- package/package.json +47 -0
- package/src/decorators/factory/__tests__/cloneAndSnapshot.test.ts +223 -0
- package/src/decorators/factory/__tests__/decoratorRegistry.test.ts +292 -0
- package/src/decorators/factory/__tests__/decoratorRegistryEdges.test.ts +262 -0
- package/src/decorators/factory/clone.ts +89 -0
- package/src/decorators/factory/decoratorRegistry.ts +366 -0
- package/src/decorators/factory/examples/accessors.ts +38 -0
- package/src/decorators/factory/examples/crud.ts +82 -0
- package/src/decorators/factory/examples/orm.ts +83 -0
- package/src/decorators/factory/examples/routing.ts +70 -0
- package/src/decorators/factory/examples/runExamples.ts +22 -0
- package/src/decorators/factory/examples/serialization.ts +47 -0
- package/src/decorators/factory/index.ts +20 -0
- package/src/decorators/factory/snapshot.ts +95 -0
- package/src/decorators/factory/symbolMetadata.ts +20 -0
- package/src/decorators/factory/type-tests/decoratorRegistry.type-test.ts +302 -0
- package/src/decorators/factory/types.ts +259 -0
- package/src/decorators/validation/validatable.ts +63 -0
- package/src/index.ts +9 -0
- package/tsconfig.json +19 -0
- package/tsconfig.type-tests.json +8 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
export type AnyFunction = (...args: any[]) => any;
|
|
2
|
+
export type Constructor<T = unknown> = abstract new (...args: any[]) => T;
|
|
3
|
+
export type PublicMemberKey = string | symbol;
|
|
4
|
+
|
|
5
|
+
export type DecorationKind = 'class' | 'property' | 'method' | 'accessor';
|
|
6
|
+
|
|
7
|
+
export interface ClassDecoratorDefinition<TMetadata = unknown> {
|
|
8
|
+
metadata: TMetadata;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PropertyDecoratorDefinition<TMetadata = unknown, TTarget = unknown> {
|
|
12
|
+
metadata: TMetadata;
|
|
13
|
+
target: TTarget;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface MethodDecoratorDefinition<
|
|
17
|
+
TMetadata = unknown,
|
|
18
|
+
TTarget extends AnyFunction = AnyFunction,
|
|
19
|
+
> {
|
|
20
|
+
metadata: TMetadata;
|
|
21
|
+
target: TTarget;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AccessorDecoratorDefinition<TMetadata = unknown, TTarget = unknown> {
|
|
25
|
+
metadata: TMetadata;
|
|
26
|
+
target: TTarget;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type DecoratorSchema = {
|
|
30
|
+
class: Record<string, ClassDecoratorDefinition<any>>;
|
|
31
|
+
property: Record<string, PropertyDecoratorDefinition<any, any>>;
|
|
32
|
+
method: Record<string, MethodDecoratorDefinition<any, AnyFunction>>;
|
|
33
|
+
accessor: Record<string, AccessorDecoratorDefinition<any, any>>;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type MetadataOf<TDefinition> = TDefinition extends { metadata: infer TMetadata }
|
|
37
|
+
? TMetadata
|
|
38
|
+
: never;
|
|
39
|
+
|
|
40
|
+
export type TargetOf<TDefinition> = TDefinition extends { target: infer TTarget }
|
|
41
|
+
? TTarget
|
|
42
|
+
: unknown;
|
|
43
|
+
|
|
44
|
+
export type StringKeyOf<TObject> = Extract<keyof TObject, string>;
|
|
45
|
+
export type MemberKeyOf<TObject> = Extract<keyof TObject, PublicMemberKey>;
|
|
46
|
+
|
|
47
|
+
export type KeysOfType<TObject, TValue> = {
|
|
48
|
+
[K in MemberKeyOf<TObject>]-?: TObject[K] extends TValue ? K : never;
|
|
49
|
+
}[MemberKeyOf<TObject>];
|
|
50
|
+
|
|
51
|
+
export type MethodKeysOfType<TObject, TValue extends AnyFunction> = {
|
|
52
|
+
[K in MemberKeyOf<TObject>]-?: TObject[K] extends TValue
|
|
53
|
+
? TObject[K] extends AnyFunction
|
|
54
|
+
? K
|
|
55
|
+
: never
|
|
56
|
+
: never;
|
|
57
|
+
}[MemberKeyOf<TObject>];
|
|
58
|
+
|
|
59
|
+
export type MetadataArgs<TMetadata> = [TMetadata] extends [undefined]
|
|
60
|
+
? []
|
|
61
|
+
: [metadata: TMetadata];
|
|
62
|
+
|
|
63
|
+
export type KeyedMetadataArgs<TKey extends PublicMemberKey, TMetadata> = [TMetadata] extends [undefined]
|
|
64
|
+
? [key: TKey]
|
|
65
|
+
: [key: TKey, metadata: TMetadata];
|
|
66
|
+
|
|
67
|
+
export type DirectKeyedMetadataArgs<TKey extends PublicMemberKey, TMetadata> = [
|
|
68
|
+
TMetadata,
|
|
69
|
+
] extends [undefined]
|
|
70
|
+
? [key: never]
|
|
71
|
+
: [key: TKey, metadata: TMetadata];
|
|
72
|
+
|
|
73
|
+
export interface DecorationRecord {
|
|
74
|
+
id: string;
|
|
75
|
+
kind: DecorationKind;
|
|
76
|
+
decorator: string;
|
|
77
|
+
metadata: unknown;
|
|
78
|
+
memberName?: string | symbol;
|
|
79
|
+
static: boolean;
|
|
80
|
+
private: boolean;
|
|
81
|
+
order: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface RegistryMetadataSnapshot {
|
|
85
|
+
readonly all: readonly DecorationRecord[];
|
|
86
|
+
readonly classes: readonly DecorationRecord[];
|
|
87
|
+
readonly properties: readonly DecorationRecord[];
|
|
88
|
+
readonly methods: readonly DecorationRecord[];
|
|
89
|
+
readonly accessors: readonly DecorationRecord[];
|
|
90
|
+
|
|
91
|
+
firstClass(decorator: string): DecorationRecord | undefined;
|
|
92
|
+
|
|
93
|
+
classRecords(decorator?: string): readonly DecorationRecord[];
|
|
94
|
+
propertyRecords(decorator?: string): readonly DecorationRecord[];
|
|
95
|
+
methodRecords(decorator?: string): readonly DecorationRecord[];
|
|
96
|
+
accessorRecords(decorator?: string): readonly DecorationRecord[];
|
|
97
|
+
|
|
98
|
+
propertyMap(decorator?: string): ReadonlyMap<string | symbol, readonly DecorationRecord[]>;
|
|
99
|
+
methodMap(decorator?: string): ReadonlyMap<string | symbol, readonly DecorationRecord[]>;
|
|
100
|
+
accessorMap(decorator?: string): ReadonlyMap<string | symbol, readonly DecorationRecord[]>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface CreateDecoratorRegistryOptions {
|
|
104
|
+
namespace?: string;
|
|
105
|
+
allowPrivateMembers?: boolean;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface RegistryReadOptions {
|
|
109
|
+
includeInherited?: boolean;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type StandardClassDecorator<TExpected, TMetadata> = (
|
|
113
|
+
...args: MetadataArgs<TMetadata>
|
|
114
|
+
) => <TClass extends Constructor<TExpected>>(
|
|
115
|
+
value: TClass,
|
|
116
|
+
context: ClassDecoratorContext<TClass>,
|
|
117
|
+
) => void;
|
|
118
|
+
|
|
119
|
+
export type UnscopedClassDecoratorFactory<TMetadata> = <TExpected = unknown>(
|
|
120
|
+
...args: MetadataArgs<TMetadata>
|
|
121
|
+
) => <TClass extends Constructor<TExpected>>(
|
|
122
|
+
value: TClass,
|
|
123
|
+
context: ClassDecoratorContext<TClass>,
|
|
124
|
+
) => void;
|
|
125
|
+
|
|
126
|
+
export interface PropertyDecoratorFactory<TContract, TTarget, TMetadata> {
|
|
127
|
+
(...args: MetadataArgs<TMetadata>): (
|
|
128
|
+
value: undefined,
|
|
129
|
+
context: ClassFieldDecoratorContext<any, TTarget>,
|
|
130
|
+
) => void;
|
|
131
|
+
|
|
132
|
+
<K extends KeysOfType<TContract, TTarget>>(
|
|
133
|
+
...args: DirectKeyedMetadataArgs<K, TMetadata>
|
|
134
|
+
): (
|
|
135
|
+
value: undefined,
|
|
136
|
+
context: ClassFieldDecoratorContext<TContract, TContract[K]> & { name: K },
|
|
137
|
+
) => void;
|
|
138
|
+
|
|
139
|
+
on<K extends KeysOfType<TContract, TTarget>>(
|
|
140
|
+
...args: KeyedMetadataArgs<K, TMetadata>
|
|
141
|
+
): (
|
|
142
|
+
value: undefined,
|
|
143
|
+
context: ClassFieldDecoratorContext<TContract, TContract[K]> & { name: K },
|
|
144
|
+
) => void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface MethodDecoratorFactory<
|
|
148
|
+
TContract,
|
|
149
|
+
TTarget extends AnyFunction,
|
|
150
|
+
TMetadata,
|
|
151
|
+
> {
|
|
152
|
+
(...args: MetadataArgs<TMetadata>): (
|
|
153
|
+
value: TTarget,
|
|
154
|
+
context: ClassMethodDecoratorContext<any, TTarget>,
|
|
155
|
+
) => void;
|
|
156
|
+
|
|
157
|
+
<K extends MethodKeysOfType<TContract, TTarget>>(
|
|
158
|
+
...args: DirectKeyedMetadataArgs<K, TMetadata>
|
|
159
|
+
): (
|
|
160
|
+
value: TContract[K] extends AnyFunction ? TContract[K] : never,
|
|
161
|
+
context: ClassMethodDecoratorContext<
|
|
162
|
+
TContract,
|
|
163
|
+
TContract[K] extends AnyFunction ? TContract[K] : never
|
|
164
|
+
> & { name: K },
|
|
165
|
+
) => void;
|
|
166
|
+
|
|
167
|
+
on<K extends MethodKeysOfType<TContract, TTarget>>(
|
|
168
|
+
...args: KeyedMetadataArgs<K, TMetadata>
|
|
169
|
+
): (
|
|
170
|
+
value: TContract[K] extends AnyFunction ? TContract[K] : never,
|
|
171
|
+
context: ClassMethodDecoratorContext<
|
|
172
|
+
TContract,
|
|
173
|
+
TContract[K] extends AnyFunction ? TContract[K] : never
|
|
174
|
+
> & { name: K },
|
|
175
|
+
) => void;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export type GetterDecorator<TContract, TTarget, K extends PublicMemberKey = PublicMemberKey> = (
|
|
179
|
+
value: (this: TContract) => TTarget,
|
|
180
|
+
context: ClassGetterDecoratorContext<TContract, TTarget> & { name: K },
|
|
181
|
+
) => void;
|
|
182
|
+
|
|
183
|
+
export type SetterDecorator<TContract, TTarget, K extends PublicMemberKey = PublicMemberKey> = (
|
|
184
|
+
value: (this: TContract, value: TTarget) => void,
|
|
185
|
+
context: ClassSetterDecoratorContext<TContract, TTarget> & { name: K },
|
|
186
|
+
) => void;
|
|
187
|
+
|
|
188
|
+
export type AutoAccessorDecorator<
|
|
189
|
+
TContract,
|
|
190
|
+
TTarget,
|
|
191
|
+
K extends PublicMemberKey = PublicMemberKey,
|
|
192
|
+
> = (
|
|
193
|
+
value: ClassAccessorDecoratorTarget<TContract, TTarget>,
|
|
194
|
+
context: ClassAccessorDecoratorContext<TContract, TTarget> & { name: K },
|
|
195
|
+
) => void;
|
|
196
|
+
|
|
197
|
+
export interface AccessorDecoratorFactory<TContract, TTarget, TMetadata> {
|
|
198
|
+
(...args: MetadataArgs<TMetadata>):
|
|
199
|
+
& GetterDecorator<any, TTarget>
|
|
200
|
+
& SetterDecorator<any, TTarget>
|
|
201
|
+
& AutoAccessorDecorator<any, TTarget>;
|
|
202
|
+
|
|
203
|
+
<K extends KeysOfType<TContract, TTarget>>(
|
|
204
|
+
...args: DirectKeyedMetadataArgs<K, TMetadata>
|
|
205
|
+
):
|
|
206
|
+
& GetterDecorator<TContract, TContract[K], K>
|
|
207
|
+
& SetterDecorator<TContract, TContract[K], K>
|
|
208
|
+
& AutoAccessorDecorator<TContract, TContract[K], K>;
|
|
209
|
+
|
|
210
|
+
on<K extends KeysOfType<TContract, TTarget>>(
|
|
211
|
+
...args: KeyedMetadataArgs<K, TMetadata>
|
|
212
|
+
):
|
|
213
|
+
& GetterDecorator<TContract, TContract[K], K>
|
|
214
|
+
& SetterDecorator<TContract, TContract[K], K>
|
|
215
|
+
& AutoAccessorDecorator<TContract, TContract[K], K>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export type ScopedDecoratorBuilder<TSchema extends DecoratorSchema, TContract> = {
|
|
219
|
+
class<K extends StringKeyOf<TSchema['class']>>(
|
|
220
|
+
name: K,
|
|
221
|
+
): StandardClassDecorator<TContract, MetadataOf<TSchema['class'][K]>>;
|
|
222
|
+
|
|
223
|
+
property<K extends StringKeyOf<TSchema['property']>>(
|
|
224
|
+
name: K,
|
|
225
|
+
): PropertyDecoratorFactory<
|
|
226
|
+
TContract,
|
|
227
|
+
TargetOf<TSchema['property'][K]>,
|
|
228
|
+
MetadataOf<TSchema['property'][K]>
|
|
229
|
+
>;
|
|
230
|
+
|
|
231
|
+
method<K extends StringKeyOf<TSchema['method']>>(
|
|
232
|
+
name: K,
|
|
233
|
+
): MethodDecoratorFactory<
|
|
234
|
+
TContract,
|
|
235
|
+
Extract<TargetOf<TSchema['method'][K]>, AnyFunction>,
|
|
236
|
+
MetadataOf<TSchema['method'][K]>
|
|
237
|
+
>;
|
|
238
|
+
|
|
239
|
+
accessor<K extends StringKeyOf<TSchema['accessor']>>(
|
|
240
|
+
name: K,
|
|
241
|
+
): AccessorDecoratorFactory<
|
|
242
|
+
TContract,
|
|
243
|
+
TargetOf<TSchema['accessor'][K]>,
|
|
244
|
+
MetadataOf<TSchema['accessor'][K]>
|
|
245
|
+
>;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export interface DecoratorRegistry<TSchema extends DecoratorSchema> {
|
|
249
|
+
readonly namespace: string;
|
|
250
|
+
readonly allowPrivateMembers: boolean;
|
|
251
|
+
|
|
252
|
+
class<K extends StringKeyOf<TSchema['class']>>(
|
|
253
|
+
name: K,
|
|
254
|
+
): UnscopedClassDecoratorFactory<MetadataOf<TSchema['class'][K]>>;
|
|
255
|
+
|
|
256
|
+
for<TContract>(): ScopedDecoratorBuilder<TSchema, TContract>;
|
|
257
|
+
|
|
258
|
+
read(target: Constructor | object, options?: RegistryReadOptions): RegistryMetadataSnapshot;
|
|
259
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// import {createDecoratorRegistry} from "../factory";
|
|
2
|
+
// export class ValidatableClass<T = any> {}
|
|
3
|
+
//
|
|
4
|
+
// type CrudDecorators = {
|
|
5
|
+
// class:{
|
|
6
|
+
// crud: {
|
|
7
|
+
// metadata: {
|
|
8
|
+
// aiTool?: boolean,
|
|
9
|
+
// listable?: boolean,
|
|
10
|
+
// filters?: string[],
|
|
11
|
+
// sorting?: string[],
|
|
12
|
+
// }
|
|
13
|
+
// }
|
|
14
|
+
// },
|
|
15
|
+
// property: {
|
|
16
|
+
// CrudID: {
|
|
17
|
+
// metadata: {
|
|
18
|
+
// editable: false,
|
|
19
|
+
// },
|
|
20
|
+
// target: string
|
|
21
|
+
// },
|
|
22
|
+
// CrudProperty: {
|
|
23
|
+
// metadata: {
|
|
24
|
+
// editable: boolean | "onCreate" | "onEdit",
|
|
25
|
+
// source?: "body" | "param" | "query" | "header" // Defaults to body.
|
|
26
|
+
// },
|
|
27
|
+
// target: string | boolean | number | Date,
|
|
28
|
+
// },
|
|
29
|
+
// },
|
|
30
|
+
// method: {},
|
|
31
|
+
// accessor: {},
|
|
32
|
+
// }
|
|
33
|
+
// const registry = createDecoratorRegistry<CrudDecorators>({ namespace: 'crud-example' });
|
|
34
|
+
// const ValidatableRegistry = registry.for<ValidatableClass>()
|
|
35
|
+
// const CRUD = ValidatableRegistry.class('crud');
|
|
36
|
+
// const CrudProperty = ValidatableRegistry.property('CrudProperty');
|
|
37
|
+
// const CrudID = ValidatableRegistry.property('CrudID');
|
|
38
|
+
//
|
|
39
|
+
//
|
|
40
|
+
// @CRUD({
|
|
41
|
+
// aiTool: true,
|
|
42
|
+
// listable: true,
|
|
43
|
+
// filters: [],
|
|
44
|
+
// sorting: [],
|
|
45
|
+
// })
|
|
46
|
+
// export class CrudExample {
|
|
47
|
+
// @CrudID({
|
|
48
|
+
// editable: false
|
|
49
|
+
// })
|
|
50
|
+
// id!: string
|
|
51
|
+
//
|
|
52
|
+
// @CrudProperty({
|
|
53
|
+
// editable: false
|
|
54
|
+
// })
|
|
55
|
+
// property!: string
|
|
56
|
+
//
|
|
57
|
+
// @CrudProperty({
|
|
58
|
+
// editable: true,
|
|
59
|
+
// })
|
|
60
|
+
// other!: string
|
|
61
|
+
// }
|
|
62
|
+
//
|
|
63
|
+
// const x = registry.read(CrudExample);
|
package/src/index.ts
ADDED
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2016",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2022", "DOM", "esnext.decorators"],
|
|
6
|
+
"rootDir": "./src",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "./build",
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"strict": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"experimentalDecorators": false,
|
|
14
|
+
"emitDecoratorMetadata": false,
|
|
15
|
+
"moduleResolution": "node"
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*.ts"],
|
|
18
|
+
"exclude": ["src/**/*.test.ts", "src/**/*.type-test.ts"]
|
|
19
|
+
}
|