@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,120 @@
|
|
|
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.crudRegistry = exports.UserCrud = void 0;
|
|
51
|
+
exports.buildCrudSummary = buildCrudSummary;
|
|
52
|
+
const index_1 = require("../index");
|
|
53
|
+
const registry = (0, index_1.createDecoratorRegistry)({ namespace: 'crud-example' });
|
|
54
|
+
exports.crudRegistry = registry;
|
|
55
|
+
const Crud = registry.for();
|
|
56
|
+
const Resource = Crud.class('resource');
|
|
57
|
+
const IdField = Crud.property('idField');
|
|
58
|
+
const Route = Crud.method('route');
|
|
59
|
+
let UserCrud = (() => {
|
|
60
|
+
let _classDecorators = [Resource({ name: 'users' })];
|
|
61
|
+
let _classDescriptor;
|
|
62
|
+
let _classExtraInitializers = [];
|
|
63
|
+
let _classThis;
|
|
64
|
+
let _instanceExtraInitializers = [];
|
|
65
|
+
let _id_decorators;
|
|
66
|
+
let _id_initializers = [];
|
|
67
|
+
let _id_extraInitializers = [];
|
|
68
|
+
let _get_decorators;
|
|
69
|
+
let _create_decorators;
|
|
70
|
+
var UserCrud = _classThis = class {
|
|
71
|
+
get(id) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return { id, email: 'ray@example.com' };
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
create(input) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
return { id: 'new-id', email: input.email };
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
constructor() {
|
|
82
|
+
this.id = (__runInitializers(this, _instanceExtraInitializers), __runInitializers(this, _id_initializers, 'user-1'));
|
|
83
|
+
__runInitializers(this, _id_extraInitializers);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
__setFunctionName(_classThis, "UserCrud");
|
|
87
|
+
(() => {
|
|
88
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
89
|
+
_id_decorators = [IdField.on('id')];
|
|
90
|
+
_get_decorators = [Route('get', { method: 'GET', path: '/users/:id' })];
|
|
91
|
+
_create_decorators = [Route.on('create', { method: 'POST', path: '/users' })];
|
|
92
|
+
__esDecorate(_classThis, null, _get_decorators, { kind: "method", name: "get", static: false, private: false, access: { has: obj => "get" in obj, get: obj => obj.get }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
93
|
+
__esDecorate(_classThis, null, _create_decorators, { kind: "method", name: "create", static: false, private: false, access: { has: obj => "create" in obj, get: obj => obj.create }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
94
|
+
__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);
|
|
95
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
96
|
+
UserCrud = _classThis = _classDescriptor.value;
|
|
97
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
98
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
99
|
+
})();
|
|
100
|
+
return UserCrud = _classThis;
|
|
101
|
+
})();
|
|
102
|
+
exports.UserCrud = UserCrud;
|
|
103
|
+
function buildCrudSummary() {
|
|
104
|
+
const snapshot = registry.read(UserCrud);
|
|
105
|
+
const resource = snapshot.firstClass('resource');
|
|
106
|
+
if (resource === undefined)
|
|
107
|
+
throw new Error('Missing @Resource metadata.');
|
|
108
|
+
return {
|
|
109
|
+
resource: resource.metadata.name,
|
|
110
|
+
routes: snapshot.methodRecords('route').map((record) => {
|
|
111
|
+
const metadata = record.metadata;
|
|
112
|
+
return `${metadata.method} ${metadata.path}`;
|
|
113
|
+
}),
|
|
114
|
+
idFields: snapshot.propertyRecords('idField').map((record) => {
|
|
115
|
+
if (record.memberName === undefined)
|
|
116
|
+
throw new Error('Missing member name.');
|
|
117
|
+
return record.memberName;
|
|
118
|
+
}),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
type OrmDecorators = {
|
|
2
|
+
class: {
|
|
3
|
+
entity: {
|
|
4
|
+
metadata: {
|
|
5
|
+
table: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
property: {
|
|
10
|
+
column: {
|
|
11
|
+
metadata: {
|
|
12
|
+
type: 'uuid' | 'varchar';
|
|
13
|
+
primary?: boolean;
|
|
14
|
+
};
|
|
15
|
+
target: string;
|
|
16
|
+
};
|
|
17
|
+
serializable: {
|
|
18
|
+
metadata: undefined;
|
|
19
|
+
target: unknown;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
method: {};
|
|
23
|
+
accessor: {};
|
|
24
|
+
};
|
|
25
|
+
type UserModelContract = {
|
|
26
|
+
id: string;
|
|
27
|
+
email: string;
|
|
28
|
+
};
|
|
29
|
+
declare const registry: import("../types").DecoratorRegistry<OrmDecorators>;
|
|
30
|
+
declare class UserModel implements UserModelContract {
|
|
31
|
+
id: string;
|
|
32
|
+
email: string;
|
|
33
|
+
}
|
|
34
|
+
export type TableColumn = {
|
|
35
|
+
name: string | symbol;
|
|
36
|
+
type: 'uuid' | 'varchar';
|
|
37
|
+
primary: boolean;
|
|
38
|
+
};
|
|
39
|
+
export type TableSchema = {
|
|
40
|
+
table: string;
|
|
41
|
+
columns: TableColumn[];
|
|
42
|
+
serializableFields: Array<string | symbol>;
|
|
43
|
+
};
|
|
44
|
+
export declare function buildUserTableSchema(): TableSchema;
|
|
45
|
+
export { UserModel, registry as ormRegistry };
|
|
@@ -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,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
|
+
}
|