@epsilon-asi/foundation 0.0.0-rc1 → 0.0.1-rc2

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.
Files changed (30) hide show
  1. package/build/decorators/factory/clone.d.ts +3 -0
  2. package/build/decorators/factory/clone.js +85 -0
  3. package/build/decorators/factory/decoratorRegistry.d.ts +2 -0
  4. package/build/decorators/factory/decoratorRegistry.js +213 -0
  5. package/build/decorators/factory/examples/accessors.d.ts +25 -0
  6. package/build/decorators/factory/examples/accessors.js +87 -0
  7. package/build/decorators/factory/examples/crud.d.ts +50 -0
  8. package/build/decorators/factory/examples/crud.js +120 -0
  9. package/build/decorators/factory/examples/orm.d.ts +45 -0
  10. package/build/decorators/factory/examples/orm.js +107 -0
  11. package/build/decorators/factory/examples/routing.d.ts +43 -0
  12. package/build/decorators/factory/examples/routing.js +112 -0
  13. package/build/decorators/factory/examples/runExamples.d.ts +1 -0
  14. package/build/decorators/factory/examples/runExamples.js +22 -0
  15. package/build/decorators/factory/examples/serialization.d.ts +24 -0
  16. package/build/decorators/factory/examples/serialization.js +79 -0
  17. package/build/decorators/factory/index.d.ts +3 -0
  18. package/build/decorators/factory/index.js +8 -0
  19. package/build/decorators/factory/snapshot.d.ts +2 -0
  20. package/build/decorators/factory/snapshot.js +75 -0
  21. package/build/decorators/factory/symbolMetadata.d.ts +2 -0
  22. package/build/decorators/factory/symbolMetadata.js +17 -0
  23. package/build/decorators/factory/types.d.ts +123 -0
  24. package/build/decorators/factory/types.js +2 -0
  25. package/build/decorators/validation/validatable.d.ts +0 -0
  26. package/build/decorators/validation/validatable.js +64 -0
  27. package/build/index.d.ts +5 -0
  28. package/build/index.js +12 -0
  29. package/build/package.json +63 -0
  30. package/package.json +2 -7
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
37
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
38
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
39
+ };
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.ormRegistry = exports.UserModel = void 0;
42
+ exports.buildUserTableSchema = buildUserTableSchema;
43
+ const index_1 = require("../index");
44
+ const registry = (0, index_1.createDecoratorRegistry)({ namespace: 'orm-example' });
45
+ exports.ormRegistry = registry;
46
+ const User = registry.for();
47
+ const Entity = User.class('entity');
48
+ const Column = User.property('column');
49
+ const Serializable = User.property('serializable');
50
+ let UserModel = (() => {
51
+ let _classDecorators = [Entity({ table: 'users' })];
52
+ let _classDescriptor;
53
+ let _classExtraInitializers = [];
54
+ let _classThis;
55
+ let _id_decorators;
56
+ let _id_initializers = [];
57
+ let _id_extraInitializers = [];
58
+ let _email_decorators;
59
+ let _email_initializers = [];
60
+ let _email_extraInitializers = [];
61
+ var UserModel = _classThis = class {
62
+ constructor() {
63
+ this.id = __runInitializers(this, _id_initializers, 'user-1');
64
+ this.email = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _email_initializers, 'ray@example.com'));
65
+ __runInitializers(this, _email_extraInitializers);
66
+ }
67
+ };
68
+ __setFunctionName(_classThis, "UserModel");
69
+ (() => {
70
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
71
+ _id_decorators = [Column('id', { type: 'uuid', primary: true }), Serializable.on('id')];
72
+ _email_decorators = [Column.on('email', { type: 'varchar' }), Serializable.on('email')];
73
+ __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
74
+ __esDecorate(null, null, _email_decorators, { kind: "field", name: "email", static: false, private: false, access: { has: obj => "email" in obj, get: obj => obj.email, set: (obj, value) => { obj.email = value; } }, metadata: _metadata }, _email_initializers, _email_extraInitializers);
75
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
76
+ UserModel = _classThis = _classDescriptor.value;
77
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
78
+ __runInitializers(_classThis, _classExtraInitializers);
79
+ })();
80
+ return UserModel = _classThis;
81
+ })();
82
+ exports.UserModel = UserModel;
83
+ function buildUserTableSchema() {
84
+ const snapshot = registry.read(UserModel);
85
+ const entity = snapshot.firstClass('entity');
86
+ if (entity === undefined)
87
+ throw new Error('Missing @Entity metadata.');
88
+ const tableMetadata = entity.metadata;
89
+ const columns = snapshot.propertyRecords('column').map((record) => {
90
+ var _a, _b;
91
+ const metadata = record.metadata;
92
+ return {
93
+ name: (_a = record.memberName) !== null && _a !== void 0 ? _a : 'unknown',
94
+ type: metadata.type,
95
+ primary: (_b = metadata.primary) !== null && _b !== void 0 ? _b : false,
96
+ };
97
+ });
98
+ return {
99
+ table: tableMetadata.table,
100
+ columns,
101
+ serializableFields: snapshot.propertyRecords('serializable').map((record) => {
102
+ if (record.memberName === undefined)
103
+ throw new Error('Serializable record missing member.');
104
+ return record.memberName;
105
+ }),
106
+ };
107
+ }
@@ -0,0 +1,43 @@
1
+ type RouteDecorators = {
2
+ class: {
3
+ controller: {
4
+ metadata: {
5
+ prefix: string;
6
+ };
7
+ };
8
+ };
9
+ property: {};
10
+ method: {
11
+ route: {
12
+ metadata: {
13
+ method: 'GET' | 'POST';
14
+ path: string;
15
+ };
16
+ target: (...args: any[]) => Promise<unknown>;
17
+ };
18
+ };
19
+ accessor: {};
20
+ };
21
+ type UserDto = {
22
+ id: string;
23
+ email: string;
24
+ };
25
+ type CreateUserInput = {
26
+ email: string;
27
+ };
28
+ type UserControllerContract = {
29
+ getUser(id: string): Promise<UserDto>;
30
+ createUser(input: CreateUserInput): Promise<UserDto>;
31
+ };
32
+ declare const registry: import("../types").DecoratorRegistry<RouteDecorators>;
33
+ declare class UserController implements UserControllerContract {
34
+ getUser(id: string): Promise<UserDto>;
35
+ createUser(input: CreateUserInput): Promise<UserDto>;
36
+ }
37
+ export type RouteEntry = {
38
+ httpMethod: 'GET' | 'POST';
39
+ path: string;
40
+ handlerName: string | symbol;
41
+ };
42
+ export declare function buildRouteTable(): RouteEntry[];
43
+ export { UserController, registry as routeRegistry };
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
45
+ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
46
+ if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
47
+ return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.routeRegistry = exports.UserController = void 0;
51
+ exports.buildRouteTable = buildRouteTable;
52
+ const index_1 = require("../index");
53
+ const registry = (0, index_1.createDecoratorRegistry)({ namespace: 'route-example' });
54
+ exports.routeRegistry = registry;
55
+ const User = registry.for();
56
+ const Controller = User.class('controller');
57
+ const Route = User.method('route');
58
+ let UserController = (() => {
59
+ let _classDecorators = [Controller({ prefix: '/api' })];
60
+ let _classDescriptor;
61
+ let _classExtraInitializers = [];
62
+ let _classThis;
63
+ let _instanceExtraInitializers = [];
64
+ let _getUser_decorators;
65
+ let _createUser_decorators;
66
+ var UserController = _classThis = class {
67
+ getUser(id) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return { id, email: 'ray@example.com' };
70
+ });
71
+ }
72
+ createUser(input) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ return { id: 'new-id', email: input.email };
75
+ });
76
+ }
77
+ constructor() {
78
+ __runInitializers(this, _instanceExtraInitializers);
79
+ }
80
+ };
81
+ __setFunctionName(_classThis, "UserController");
82
+ (() => {
83
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
84
+ _getUser_decorators = [Route('getUser', { method: 'GET', path: '/users/:id' })];
85
+ _createUser_decorators = [Route.on('createUser', { method: 'POST', path: '/users' })];
86
+ __esDecorate(_classThis, null, _getUser_decorators, { kind: "method", name: "getUser", static: false, private: false, access: { has: obj => "getUser" in obj, get: obj => obj.getUser }, metadata: _metadata }, null, _instanceExtraInitializers);
87
+ __esDecorate(_classThis, null, _createUser_decorators, { kind: "method", name: "createUser", static: false, private: false, access: { has: obj => "createUser" in obj, get: obj => obj.createUser }, metadata: _metadata }, null, _instanceExtraInitializers);
88
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
89
+ UserController = _classThis = _classDescriptor.value;
90
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
91
+ __runInitializers(_classThis, _classExtraInitializers);
92
+ })();
93
+ return UserController = _classThis;
94
+ })();
95
+ exports.UserController = UserController;
96
+ function buildRouteTable() {
97
+ const snapshot = registry.read(UserController);
98
+ const controller = snapshot.firstClass('controller');
99
+ if (controller === undefined)
100
+ throw new Error('Missing @Controller metadata.');
101
+ const prefix = controller.metadata.prefix;
102
+ return snapshot.methodRecords('route').map((record) => {
103
+ if (record.memberName === undefined)
104
+ throw new Error('Route record missing member.');
105
+ const metadata = record.metadata;
106
+ return {
107
+ httpMethod: metadata.method,
108
+ path: `${prefix}${metadata.path}`,
109
+ handlerName: record.memberName,
110
+ };
111
+ });
112
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const accessors_1 = require("./accessors");
4
+ const crud_1 = require("./crud");
5
+ const orm_1 = require("./orm");
6
+ const routing_1 = require("./routing");
7
+ const serialization_1 = require("./serialization");
8
+ function stable(value) {
9
+ return JSON.stringify(value, (_key, innerValue) => {
10
+ if (typeof innerValue === 'symbol')
11
+ return innerValue.toString();
12
+ return innerValue;
13
+ });
14
+ }
15
+ const outputs = {
16
+ orm: (0, orm_1.buildUserTableSchema)(),
17
+ routing: (0, routing_1.buildRouteTable)(),
18
+ serialization: (0, serialization_1.serializeUser)(),
19
+ crud: (0, crud_1.buildCrudSummary)(),
20
+ accessors: (0, accessors_1.readAccessorMetadata)(),
21
+ };
22
+ console.log(stable(outputs));
@@ -0,0 +1,24 @@
1
+ type SerializationDecorators = {
2
+ class: {};
3
+ property: {
4
+ serializable: {
5
+ metadata: undefined;
6
+ target: unknown;
7
+ };
8
+ };
9
+ method: {};
10
+ accessor: {};
11
+ };
12
+ type UserContract = {
13
+ id: string;
14
+ email: string;
15
+ passwordHash: string;
16
+ };
17
+ declare const registry: import("../types").DecoratorRegistry<SerializationDecorators>;
18
+ declare class UserRecord implements UserContract {
19
+ id: string;
20
+ email: string;
21
+ passwordHash: string;
22
+ }
23
+ export declare function serializeUser(user?: UserRecord): Record<string, unknown>;
24
+ export { UserRecord, registry as serializationRegistry };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
+ var _, done = false;
8
+ for (var i = decorators.length - 1; i >= 0; i--) {
9
+ var context = {};
10
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
+ if (kind === "accessor") {
15
+ if (result === void 0) continue;
16
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
+ if (_ = accept(result.get)) descriptor.get = _;
18
+ if (_ = accept(result.set)) descriptor.set = _;
19
+ if (_ = accept(result.init)) initializers.unshift(_);
20
+ }
21
+ else if (_ = accept(result)) {
22
+ if (kind === "field") initializers.unshift(_);
23
+ else descriptor[key] = _;
24
+ }
25
+ }
26
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
+ done = true;
28
+ };
29
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
+ var useValue = arguments.length > 2;
31
+ for (var i = 0; i < initializers.length; i++) {
32
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
+ }
34
+ return useValue ? value : void 0;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.serializationRegistry = exports.UserRecord = void 0;
38
+ exports.serializeUser = serializeUser;
39
+ const index_1 = require("../index");
40
+ const registry = (0, index_1.createDecoratorRegistry)({ namespace: 'serialization-example' });
41
+ exports.serializationRegistry = registry;
42
+ const User = registry.for();
43
+ const Serializable = User.property('serializable');
44
+ let UserRecord = (() => {
45
+ var _a;
46
+ let _id_decorators;
47
+ let _id_initializers = [];
48
+ let _id_extraInitializers = [];
49
+ let _email_decorators;
50
+ let _email_initializers = [];
51
+ let _email_extraInitializers = [];
52
+ return _a = class UserRecord {
53
+ constructor() {
54
+ this.id = __runInitializers(this, _id_initializers, 'user-1');
55
+ this.email = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _email_initializers, 'ray@example.com'));
56
+ this.passwordHash = (__runInitializers(this, _email_extraInitializers), 'not-for-output');
57
+ }
58
+ },
59
+ (() => {
60
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
61
+ _id_decorators = [Serializable.on('id')];
62
+ _email_decorators = [Serializable.on('email')];
63
+ __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
64
+ __esDecorate(null, null, _email_decorators, { kind: "field", name: "email", static: false, private: false, access: { has: obj => "email" in obj, get: obj => obj.email, set: (obj, value) => { obj.email = value; } }, metadata: _metadata }, _email_initializers, _email_extraInitializers);
65
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
66
+ })(),
67
+ _a;
68
+ })();
69
+ exports.UserRecord = UserRecord;
70
+ function serializeUser(user = new UserRecord()) {
71
+ const snapshot = registry.read(user);
72
+ const output = {};
73
+ for (const record of snapshot.propertyRecords('serializable')) {
74
+ if (typeof record.memberName !== 'string')
75
+ continue;
76
+ output[record.memberName] = user[record.memberName];
77
+ }
78
+ return output;
79
+ }
@@ -0,0 +1,3 @@
1
+ export { createDecoratorRegistry } from './decoratorRegistry';
2
+ export { ensureSymbolMetadata, symbolMetadata } from './symbolMetadata';
3
+ export type { AccessorDecoratorDefinition, AnyFunction, ClassDecoratorDefinition, Constructor, CreateDecoratorRegistryOptions, DecorationKind, DecorationRecord, DecoratorRegistry, DecoratorSchema, MethodDecoratorDefinition, MetadataOf, PropertyDecoratorDefinition, RegistryMetadataSnapshot, RegistryReadOptions, ScopedDecoratorBuilder, TargetOf, } from './types';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.symbolMetadata = exports.ensureSymbolMetadata = exports.createDecoratorRegistry = void 0;
4
+ var decoratorRegistry_1 = require("./decoratorRegistry");
5
+ Object.defineProperty(exports, "createDecoratorRegistry", { enumerable: true, get: function () { return decoratorRegistry_1.createDecoratorRegistry; } });
6
+ var symbolMetadata_1 = require("./symbolMetadata");
7
+ Object.defineProperty(exports, "ensureSymbolMetadata", { enumerable: true, get: function () { return symbolMetadata_1.ensureSymbolMetadata; } });
8
+ Object.defineProperty(exports, "symbolMetadata", { enumerable: true, get: function () { return symbolMetadata_1.symbolMetadata; } });
@@ -0,0 +1,2 @@
1
+ import type { DecorationRecord, RegistryMetadataSnapshot } from './types';
2
+ export declare function createSnapshot(records: readonly DecorationRecord[]): RegistryMetadataSnapshot;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSnapshot = createSnapshot;
4
+ function cloneRecords(records) {
5
+ return Object.freeze(records.slice());
6
+ }
7
+ function filterRecords(records, kind, decorator) {
8
+ return Object.freeze(records.filter((record) => {
9
+ if (record.kind !== kind)
10
+ return false;
11
+ return decorator === undefined || record.decorator === decorator;
12
+ }));
13
+ }
14
+ function memberMap(records, kind, decorator) {
15
+ const mutable = new Map();
16
+ for (const record of records) {
17
+ if (record.kind !== kind)
18
+ continue;
19
+ if (decorator !== undefined && record.decorator !== decorator)
20
+ continue;
21
+ if (record.memberName === undefined)
22
+ continue;
23
+ const existing = mutable.get(record.memberName);
24
+ if (existing === undefined) {
25
+ mutable.set(record.memberName, [record]);
26
+ }
27
+ else {
28
+ existing.push(record);
29
+ }
30
+ }
31
+ const frozen = new Map();
32
+ for (const [key, value] of mutable.entries()) {
33
+ frozen.set(key, Object.freeze(value.slice()));
34
+ }
35
+ return frozen;
36
+ }
37
+ function createSnapshot(records) {
38
+ const sorted = records.slice().sort((left, right) => left.order - right.order);
39
+ const all = cloneRecords(sorted);
40
+ const classes = filterRecords(all, 'class');
41
+ const properties = filterRecords(all, 'property');
42
+ const methods = filterRecords(all, 'method');
43
+ const accessors = filterRecords(all, 'accessor');
44
+ return Object.freeze({
45
+ all,
46
+ classes,
47
+ properties,
48
+ methods,
49
+ accessors,
50
+ firstClass(decorator) {
51
+ return classes.find((record) => record.decorator === decorator);
52
+ },
53
+ classRecords(decorator) {
54
+ return filterRecords(all, 'class', decorator);
55
+ },
56
+ propertyRecords(decorator) {
57
+ return filterRecords(all, 'property', decorator);
58
+ },
59
+ methodRecords(decorator) {
60
+ return filterRecords(all, 'method', decorator);
61
+ },
62
+ accessorRecords(decorator) {
63
+ return filterRecords(all, 'accessor', decorator);
64
+ },
65
+ propertyMap(decorator) {
66
+ return memberMap(all, 'property', decorator);
67
+ },
68
+ methodMap(decorator) {
69
+ return memberMap(all, 'method', decorator);
70
+ },
71
+ accessorMap(decorator) {
72
+ return memberMap(all, 'accessor', decorator);
73
+ },
74
+ });
75
+ }
@@ -0,0 +1,2 @@
1
+ export declare function ensureSymbolMetadata(): symbol;
2
+ export declare const symbolMetadata: symbol;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.symbolMetadata = void 0;
4
+ exports.ensureSymbolMetadata = ensureSymbolMetadata;
5
+ function ensureSymbolMetadata() {
6
+ const symbolConstructor = Symbol;
7
+ if (symbolConstructor.metadata === undefined) {
8
+ Object.defineProperty(symbolConstructor, 'metadata', {
9
+ configurable: false,
10
+ enumerable: false,
11
+ writable: false,
12
+ value: Symbol('Symbol.metadata'),
13
+ });
14
+ }
15
+ return symbolConstructor.metadata;
16
+ }
17
+ exports.symbolMetadata = ensureSymbolMetadata();
@@ -0,0 +1,123 @@
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
+ export type DecorationKind = 'class' | 'property' | 'method' | 'accessor';
5
+ export interface ClassDecoratorDefinition<TMetadata = unknown> {
6
+ metadata: TMetadata;
7
+ }
8
+ export interface PropertyDecoratorDefinition<TMetadata = unknown, TTarget = unknown> {
9
+ metadata: TMetadata;
10
+ target: TTarget;
11
+ }
12
+ export interface MethodDecoratorDefinition<TMetadata = unknown, TTarget extends AnyFunction = AnyFunction> {
13
+ metadata: TMetadata;
14
+ target: TTarget;
15
+ }
16
+ export interface AccessorDecoratorDefinition<TMetadata = unknown, TTarget = unknown> {
17
+ metadata: TMetadata;
18
+ target: TTarget;
19
+ }
20
+ export type DecoratorSchema = {
21
+ class: Record<string, ClassDecoratorDefinition<any>>;
22
+ property: Record<string, PropertyDecoratorDefinition<any, any>>;
23
+ method: Record<string, MethodDecoratorDefinition<any, AnyFunction>>;
24
+ accessor: Record<string, AccessorDecoratorDefinition<any, any>>;
25
+ };
26
+ export type MetadataOf<TDefinition> = TDefinition extends {
27
+ metadata: infer TMetadata;
28
+ } ? TMetadata : never;
29
+ export type TargetOf<TDefinition> = TDefinition extends {
30
+ target: infer TTarget;
31
+ } ? TTarget : unknown;
32
+ export type StringKeyOf<TObject> = Extract<keyof TObject, string>;
33
+ export type MemberKeyOf<TObject> = Extract<keyof TObject, PublicMemberKey>;
34
+ export type KeysOfType<TObject, TValue> = {
35
+ [K in MemberKeyOf<TObject>]-?: TObject[K] extends TValue ? K : never;
36
+ }[MemberKeyOf<TObject>];
37
+ export type MethodKeysOfType<TObject, TValue extends AnyFunction> = {
38
+ [K in MemberKeyOf<TObject>]-?: TObject[K] extends TValue ? TObject[K] extends AnyFunction ? K : never : never;
39
+ }[MemberKeyOf<TObject>];
40
+ export type MetadataArgs<TMetadata> = [TMetadata] extends [undefined] ? [] : [metadata: TMetadata];
41
+ export type KeyedMetadataArgs<TKey extends PublicMemberKey, TMetadata> = [TMetadata] extends [undefined] ? [key: TKey] : [key: TKey, metadata: TMetadata];
42
+ export type DirectKeyedMetadataArgs<TKey extends PublicMemberKey, TMetadata> = [
43
+ TMetadata
44
+ ] extends [undefined] ? [key: never] : [key: TKey, metadata: TMetadata];
45
+ export interface DecorationRecord {
46
+ id: string;
47
+ kind: DecorationKind;
48
+ decorator: string;
49
+ metadata: unknown;
50
+ memberName?: string | symbol;
51
+ static: boolean;
52
+ private: boolean;
53
+ order: number;
54
+ }
55
+ export interface RegistryMetadataSnapshot {
56
+ readonly all: readonly DecorationRecord[];
57
+ readonly classes: readonly DecorationRecord[];
58
+ readonly properties: readonly DecorationRecord[];
59
+ readonly methods: readonly DecorationRecord[];
60
+ readonly accessors: readonly DecorationRecord[];
61
+ firstClass(decorator: string): DecorationRecord | undefined;
62
+ classRecords(decorator?: string): readonly DecorationRecord[];
63
+ propertyRecords(decorator?: string): readonly DecorationRecord[];
64
+ methodRecords(decorator?: string): readonly DecorationRecord[];
65
+ accessorRecords(decorator?: string): readonly DecorationRecord[];
66
+ propertyMap(decorator?: string): ReadonlyMap<string | symbol, readonly DecorationRecord[]>;
67
+ methodMap(decorator?: string): ReadonlyMap<string | symbol, readonly DecorationRecord[]>;
68
+ accessorMap(decorator?: string): ReadonlyMap<string | symbol, readonly DecorationRecord[]>;
69
+ }
70
+ export interface CreateDecoratorRegistryOptions {
71
+ namespace?: string;
72
+ allowPrivateMembers?: boolean;
73
+ }
74
+ export interface RegistryReadOptions {
75
+ includeInherited?: boolean;
76
+ }
77
+ export type StandardClassDecorator<TExpected, TMetadata> = (...args: MetadataArgs<TMetadata>) => <TClass extends Constructor<TExpected>>(value: TClass, context: ClassDecoratorContext<TClass>) => void;
78
+ export type UnscopedClassDecoratorFactory<TMetadata> = <TExpected = unknown>(...args: MetadataArgs<TMetadata>) => <TClass extends Constructor<TExpected>>(value: TClass, context: ClassDecoratorContext<TClass>) => void;
79
+ export interface PropertyDecoratorFactory<TContract, TTarget, TMetadata> {
80
+ (...args: MetadataArgs<TMetadata>): (value: undefined, context: ClassFieldDecoratorContext<any, TTarget>) => void;
81
+ <K extends KeysOfType<TContract, TTarget>>(...args: DirectKeyedMetadataArgs<K, TMetadata>): (value: undefined, context: ClassFieldDecoratorContext<TContract, TContract[K]> & {
82
+ name: K;
83
+ }) => void;
84
+ on<K extends KeysOfType<TContract, TTarget>>(...args: KeyedMetadataArgs<K, TMetadata>): (value: undefined, context: ClassFieldDecoratorContext<TContract, TContract[K]> & {
85
+ name: K;
86
+ }) => void;
87
+ }
88
+ export interface MethodDecoratorFactory<TContract, TTarget extends AnyFunction, TMetadata> {
89
+ (...args: MetadataArgs<TMetadata>): (value: TTarget, context: ClassMethodDecoratorContext<any, TTarget>) => void;
90
+ <K extends MethodKeysOfType<TContract, TTarget>>(...args: DirectKeyedMetadataArgs<K, TMetadata>): (value: TContract[K] extends AnyFunction ? TContract[K] : never, context: ClassMethodDecoratorContext<TContract, TContract[K] extends AnyFunction ? TContract[K] : never> & {
91
+ name: K;
92
+ }) => void;
93
+ on<K extends MethodKeysOfType<TContract, TTarget>>(...args: KeyedMetadataArgs<K, TMetadata>): (value: TContract[K] extends AnyFunction ? TContract[K] : never, context: ClassMethodDecoratorContext<TContract, TContract[K] extends AnyFunction ? TContract[K] : never> & {
94
+ name: K;
95
+ }) => void;
96
+ }
97
+ export type GetterDecorator<TContract, TTarget, K extends PublicMemberKey = PublicMemberKey> = (value: (this: TContract) => TTarget, context: ClassGetterDecoratorContext<TContract, TTarget> & {
98
+ name: K;
99
+ }) => void;
100
+ export type SetterDecorator<TContract, TTarget, K extends PublicMemberKey = PublicMemberKey> = (value: (this: TContract, value: TTarget) => void, context: ClassSetterDecoratorContext<TContract, TTarget> & {
101
+ name: K;
102
+ }) => void;
103
+ export type AutoAccessorDecorator<TContract, TTarget, K extends PublicMemberKey = PublicMemberKey> = (value: ClassAccessorDecoratorTarget<TContract, TTarget>, context: ClassAccessorDecoratorContext<TContract, TTarget> & {
104
+ name: K;
105
+ }) => void;
106
+ export interface AccessorDecoratorFactory<TContract, TTarget, TMetadata> {
107
+ (...args: MetadataArgs<TMetadata>): GetterDecorator<any, TTarget> & SetterDecorator<any, TTarget> & AutoAccessorDecorator<any, TTarget>;
108
+ <K extends KeysOfType<TContract, TTarget>>(...args: DirectKeyedMetadataArgs<K, TMetadata>): GetterDecorator<TContract, TContract[K], K> & SetterDecorator<TContract, TContract[K], K> & AutoAccessorDecorator<TContract, TContract[K], K>;
109
+ on<K extends KeysOfType<TContract, TTarget>>(...args: KeyedMetadataArgs<K, TMetadata>): GetterDecorator<TContract, TContract[K], K> & SetterDecorator<TContract, TContract[K], K> & AutoAccessorDecorator<TContract, TContract[K], K>;
110
+ }
111
+ export type ScopedDecoratorBuilder<TSchema extends DecoratorSchema, TContract> = {
112
+ class<K extends StringKeyOf<TSchema['class']>>(name: K): StandardClassDecorator<TContract, MetadataOf<TSchema['class'][K]>>;
113
+ property<K extends StringKeyOf<TSchema['property']>>(name: K): PropertyDecoratorFactory<TContract, TargetOf<TSchema['property'][K]>, MetadataOf<TSchema['property'][K]>>;
114
+ method<K extends StringKeyOf<TSchema['method']>>(name: K): MethodDecoratorFactory<TContract, Extract<TargetOf<TSchema['method'][K]>, AnyFunction>, MetadataOf<TSchema['method'][K]>>;
115
+ accessor<K extends StringKeyOf<TSchema['accessor']>>(name: K): AccessorDecoratorFactory<TContract, TargetOf<TSchema['accessor'][K]>, MetadataOf<TSchema['accessor'][K]>>;
116
+ };
117
+ export interface DecoratorRegistry<TSchema extends DecoratorSchema> {
118
+ readonly namespace: string;
119
+ readonly allowPrivateMembers: boolean;
120
+ class<K extends StringKeyOf<TSchema['class']>>(name: K): UnscopedClassDecoratorFactory<MetadataOf<TSchema['class'][K]>>;
121
+ for<TContract>(): ScopedDecoratorBuilder<TSchema, TContract>;
122
+ read(target: Constructor | object, options?: RegistryReadOptions): RegistryMetadataSnapshot;
123
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
File without changes