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

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 (29) 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/package.json +6 -11
@@ -0,0 +1,3 @@
1
+ export declare function cloneDeep<T>(value: T, seen?: WeakMap<object, unknown>): T;
2
+ export declare function deepFreeze<T>(value: T, seen?: WeakSet<object>): T;
3
+ export declare function immutableClone<T>(value: T): T;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cloneDeep = cloneDeep;
4
+ exports.deepFreeze = deepFreeze;
5
+ exports.immutableClone = immutableClone;
6
+ function isObjectLike(value) {
7
+ return (typeof value === 'object' && value !== null) || typeof value === 'function';
8
+ }
9
+ function cloneDeep(value, seen = new WeakMap()) {
10
+ if (!isObjectLike(value))
11
+ return value;
12
+ if (typeof value === 'function')
13
+ return value;
14
+ const existing = seen.get(value);
15
+ if (existing !== undefined)
16
+ return existing;
17
+ if (value instanceof Date) {
18
+ return new Date(value.getTime());
19
+ }
20
+ if (value instanceof RegExp) {
21
+ return new RegExp(value.source, value.flags);
22
+ }
23
+ if (value instanceof Map) {
24
+ const cloned = new Map();
25
+ seen.set(value, cloned);
26
+ for (const [key, mapValue] of value.entries()) {
27
+ cloned.set(cloneDeep(key, seen), cloneDeep(mapValue, seen));
28
+ }
29
+ return cloned;
30
+ }
31
+ if (value instanceof Set) {
32
+ const cloned = new Set();
33
+ seen.set(value, cloned);
34
+ for (const setValue of value.values()) {
35
+ cloned.add(cloneDeep(setValue, seen));
36
+ }
37
+ return cloned;
38
+ }
39
+ if (Array.isArray(value)) {
40
+ const cloned = [];
41
+ seen.set(value, cloned);
42
+ for (const item of value)
43
+ cloned.push(cloneDeep(item, seen));
44
+ return cloned;
45
+ }
46
+ const cloned = Object.create(Object.getPrototypeOf(value));
47
+ seen.set(value, cloned);
48
+ for (const key of Reflect.ownKeys(value)) {
49
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
50
+ if (descriptor === undefined)
51
+ continue;
52
+ if ('value' in descriptor) {
53
+ descriptor.value = cloneDeep(descriptor.value, seen);
54
+ }
55
+ Object.defineProperty(cloned, key, descriptor);
56
+ }
57
+ return cloned;
58
+ }
59
+ function deepFreeze(value, seen = new WeakSet()) {
60
+ if (!isObjectLike(value))
61
+ return value;
62
+ if (seen.has(value))
63
+ return value;
64
+ seen.add(value);
65
+ if (value instanceof Map) {
66
+ for (const [key, mapValue] of value.entries()) {
67
+ deepFreeze(key, seen);
68
+ deepFreeze(mapValue, seen);
69
+ }
70
+ }
71
+ else if (value instanceof Set) {
72
+ for (const setValue of value.values()) {
73
+ deepFreeze(setValue, seen);
74
+ }
75
+ }
76
+ else {
77
+ for (const key of Reflect.ownKeys(value)) {
78
+ deepFreeze(value[key], seen);
79
+ }
80
+ }
81
+ return Object.freeze(value);
82
+ }
83
+ function immutableClone(value) {
84
+ return deepFreeze(cloneDeep(value));
85
+ }
@@ -0,0 +1,2 @@
1
+ import type { CreateDecoratorRegistryOptions, DecoratorRegistry, DecoratorSchema } from './types';
2
+ export declare function createDecoratorRegistry<TSchema extends DecoratorSchema>(options?: CreateDecoratorRegistryOptions): DecoratorRegistry<TSchema>;
@@ -0,0 +1,213 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDecoratorRegistry = createDecoratorRegistry;
4
+ const clone_1 = require("./clone");
5
+ const snapshot_1 = require("./snapshot");
6
+ const symbolMetadata_1 = require("./symbolMetadata");
7
+ function isPropertyKey(value) {
8
+ return typeof value === 'string' || typeof value === 'symbol';
9
+ }
10
+ function assertPropertyKey(value, decoratorName) {
11
+ if (isPropertyKey(value))
12
+ return value;
13
+ throw new TypeError(`Decorator "${decoratorName}" expected a string or symbol member key, but received ${typeof value}.`);
14
+ }
15
+ function parseDirectArgs(args, decoratorName) {
16
+ if (args.length === 0) {
17
+ return { metadata: undefined };
18
+ }
19
+ if (args.length === 1) {
20
+ return { metadata: args[0] };
21
+ }
22
+ return {
23
+ key: assertPropertyKey(args[0], decoratorName),
24
+ metadata: args[1],
25
+ };
26
+ }
27
+ function parseOnArgs(args, decoratorName) {
28
+ if (args.length === 0) {
29
+ throw new TypeError(`Decorator "${decoratorName}.on" requires a member key.`);
30
+ }
31
+ return {
32
+ key: assertPropertyKey(args[0], `${decoratorName}.on`),
33
+ metadata: args.length > 1 ? args[1] : undefined,
34
+ };
35
+ }
36
+ function assertContextKind(expectedKind, decoratorName, context) {
37
+ if (expectedKind === 'class' && context.kind === 'class')
38
+ return;
39
+ if (expectedKind === 'property' && context.kind === 'field')
40
+ return;
41
+ if (expectedKind === 'method' && context.kind === 'method')
42
+ return;
43
+ if (expectedKind === 'accessor' &&
44
+ (context.kind === 'accessor' || context.kind === 'getter' || context.kind === 'setter')) {
45
+ return;
46
+ }
47
+ throw new TypeError(`Decorator "${decoratorName}" can only be used on ${expectedKind} targets, but was used on ${context.kind}.`);
48
+ }
49
+ function getTargetConstructor(target) {
50
+ if (typeof target === 'function') {
51
+ return target;
52
+ }
53
+ const constructor = target.constructor;
54
+ return typeof constructor === 'function' ? constructor : undefined;
55
+ }
56
+ function getConstructorChain(constructor, includeInherited) {
57
+ if (!includeInherited)
58
+ return [constructor];
59
+ const chain = [];
60
+ let current = constructor;
61
+ while (typeof current === 'function' && current !== Function.prototype) {
62
+ chain.push(current);
63
+ current = Object.getPrototypeOf(current);
64
+ }
65
+ return chain.reverse();
66
+ }
67
+ function getOwnMetadataObject(constructor) {
68
+ if (!Object.prototype.hasOwnProperty.call(constructor, symbolMetadata_1.symbolMetadata)) {
69
+ return undefined;
70
+ }
71
+ const metadata = constructor[symbolMetadata_1.symbolMetadata];
72
+ return typeof metadata === 'object' && metadata !== null ? metadata : undefined;
73
+ }
74
+ function samePropertyKey(left, right) {
75
+ return left === right;
76
+ }
77
+ class ModernDecoratorRegistry {
78
+ constructor(options = {}) {
79
+ var _a, _b;
80
+ this.nextOrder = 0;
81
+ this.recordsByMetadata = new WeakMap();
82
+ this.namespace = (_a = options.namespace) !== null && _a !== void 0 ? _a : 'default';
83
+ this.allowPrivateMembers = (_b = options.allowPrivateMembers) !== null && _b !== void 0 ? _b : false;
84
+ }
85
+ class(name) {
86
+ return this.createClassFactory(String(name));
87
+ }
88
+ for() {
89
+ return Object.freeze({
90
+ class: (name) => this.createScopedClassFactory(String(name)),
91
+ property: (name) => this.createPropertyFactory(String(name)),
92
+ method: (name) => this.createMethodFactory(String(name)),
93
+ accessor: (name) => this.createAccessorFactory(String(name)),
94
+ });
95
+ }
96
+ read(target, options = {}) {
97
+ var _a;
98
+ const constructor = getTargetConstructor(target);
99
+ if (constructor === undefined) {
100
+ return (0, snapshot_1.createSnapshot)([]);
101
+ }
102
+ const includeInherited = (_a = options.includeInherited) !== null && _a !== void 0 ? _a : true;
103
+ const constructors = getConstructorChain(constructor, includeInherited);
104
+ const records = [];
105
+ for (const current of constructors) {
106
+ const metadata = getOwnMetadataObject(current);
107
+ if (metadata === undefined)
108
+ continue;
109
+ const ownRecords = this.recordsByMetadata.get(metadata);
110
+ if (ownRecords !== undefined)
111
+ records.push(...ownRecords);
112
+ }
113
+ return (0, snapshot_1.createSnapshot)(records);
114
+ }
115
+ createClassFactory(decoratorName) {
116
+ const factory = ((...args) => {
117
+ const metadata = args.length === 0 ? undefined : args[0];
118
+ return (_value, context) => {
119
+ assertContextKind('class', decoratorName, context);
120
+ this.register(context.metadata, {
121
+ kind: 'class',
122
+ decorator: decoratorName,
123
+ metadata,
124
+ static: false,
125
+ private: false,
126
+ });
127
+ };
128
+ });
129
+ return factory;
130
+ }
131
+ createScopedClassFactory(decoratorName) {
132
+ return ((...args) => {
133
+ const metadata = args.length === 0 ? undefined : args[0];
134
+ return (_value, context) => {
135
+ assertContextKind('class', decoratorName, context);
136
+ this.register(context.metadata, {
137
+ kind: 'class',
138
+ decorator: decoratorName,
139
+ metadata,
140
+ static: false,
141
+ private: false,
142
+ });
143
+ };
144
+ });
145
+ }
146
+ createPropertyFactory(decoratorName) {
147
+ const factory = ((...args) => {
148
+ const parsed = parseDirectArgs(args, decoratorName);
149
+ return this.createMemberDecorator('property', decoratorName, parsed);
150
+ });
151
+ factory.on = ((...args) => {
152
+ const parsed = parseOnArgs(args, decoratorName);
153
+ return this.createMemberDecorator('property', decoratorName, parsed);
154
+ });
155
+ return factory;
156
+ }
157
+ createMethodFactory(decoratorName) {
158
+ const factory = ((...args) => {
159
+ const parsed = parseDirectArgs(args, decoratorName);
160
+ return this.createMemberDecorator('method', decoratorName, parsed);
161
+ });
162
+ factory.on = ((...args) => {
163
+ const parsed = parseOnArgs(args, decoratorName);
164
+ return this.createMemberDecorator('method', decoratorName, parsed);
165
+ });
166
+ return factory;
167
+ }
168
+ createAccessorFactory(decoratorName) {
169
+ const factory = ((...args) => {
170
+ const parsed = parseDirectArgs(args, decoratorName);
171
+ return this.createMemberDecorator('accessor', decoratorName, parsed);
172
+ });
173
+ factory.on = ((...args) => {
174
+ const parsed = parseOnArgs(args, decoratorName);
175
+ return this.createMemberDecorator('accessor', decoratorName, parsed);
176
+ });
177
+ return factory;
178
+ }
179
+ createMemberDecorator(kind, decoratorName, parsed) {
180
+ return (_value, context) => {
181
+ assertContextKind(kind, decoratorName, context);
182
+ if (context.private && !this.allowPrivateMembers) {
183
+ throw new Error(`Decorator "${decoratorName}" cannot be used on private member "${String(context.name)}" unless allowPrivateMembers is true.`);
184
+ }
185
+ if (parsed.key !== undefined && !samePropertyKey(parsed.key, context.name)) {
186
+ throw new Error(`Decorator "${decoratorName}" was keyed for "${String(parsed.key)}" but applied to "${String(context.name)}".`);
187
+ }
188
+ this.register(context.metadata, {
189
+ kind,
190
+ decorator: decoratorName,
191
+ metadata: parsed.metadata,
192
+ memberName: context.name,
193
+ static: context.static,
194
+ private: context.private,
195
+ });
196
+ };
197
+ }
198
+ register(metadataObject, record) {
199
+ const order = this.nextOrder;
200
+ this.nextOrder += 1;
201
+ const immutableRecord = Object.freeze(Object.assign(Object.assign({}, record), { id: `${this.namespace}:${record.kind}:${record.decorator}:${order}`, order, metadata: (0, clone_1.immutableClone)(record.metadata) }));
202
+ const existing = this.recordsByMetadata.get(metadataObject);
203
+ if (existing === undefined) {
204
+ this.recordsByMetadata.set(metadataObject, [immutableRecord]);
205
+ }
206
+ else {
207
+ existing.push(immutableRecord);
208
+ }
209
+ }
210
+ }
211
+ function createDecoratorRegistry(options = {}) {
212
+ return new ModernDecoratorRegistry(options);
213
+ }
@@ -0,0 +1,25 @@
1
+ type ViewDecorators = {
2
+ class: {};
3
+ property: {};
4
+ method: {};
5
+ accessor: {
6
+ cached: {
7
+ metadata: {
8
+ ttlMs?: number;
9
+ };
10
+ target: string;
11
+ };
12
+ };
13
+ };
14
+ type UserViewContract = {
15
+ displayName: string;
16
+ };
17
+ declare const registry: import("../types").DecoratorRegistry<ViewDecorators>;
18
+ declare class UserView implements UserViewContract {
19
+ accessor displayName: string;
20
+ }
21
+ export declare function readAccessorMetadata(): {
22
+ memberName: string | symbol;
23
+ ttlMs: number | undefined;
24
+ }[];
25
+ export { UserView, registry as accessorRegistry };
@@ -0,0 +1,87 @@
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 __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
37
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
38
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
39
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
40
+ };
41
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
42
+ if (kind === "m") throw new TypeError("Private method is not writable");
43
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
44
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
45
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.accessorRegistry = exports.UserView = void 0;
49
+ exports.readAccessorMetadata = readAccessorMetadata;
50
+ const index_1 = require("../index");
51
+ const registry = (0, index_1.createDecoratorRegistry)({ namespace: 'accessor-example' });
52
+ exports.accessorRegistry = registry;
53
+ const View = registry.for();
54
+ const Cached = View.accessor('cached');
55
+ let UserView = (() => {
56
+ var _a, _UserView_displayName_accessor_storage;
57
+ let _displayName_decorators;
58
+ let _displayName_initializers = [];
59
+ let _displayName_extraInitializers = [];
60
+ return _a = class UserView {
61
+ get displayName() { return __classPrivateFieldGet(this, _UserView_displayName_accessor_storage, "f"); }
62
+ set displayName(value) { __classPrivateFieldSet(this, _UserView_displayName_accessor_storage, value, "f"); }
63
+ constructor() {
64
+ _UserView_displayName_accessor_storage.set(this, __runInitializers(this, _displayName_initializers, 'Ray'));
65
+ __runInitializers(this, _displayName_extraInitializers);
66
+ }
67
+ },
68
+ _UserView_displayName_accessor_storage = new WeakMap(),
69
+ (() => {
70
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
71
+ _displayName_decorators = [Cached('displayName', { ttlMs: 1000 })];
72
+ __esDecorate(_a, null, _displayName_decorators, { kind: "accessor", name: "displayName", static: false, private: false, access: { has: obj => "displayName" in obj, get: obj => obj.displayName, set: (obj, value) => { obj.displayName = value; } }, metadata: _metadata }, _displayName_initializers, _displayName_extraInitializers);
73
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
74
+ })(),
75
+ _a;
76
+ })();
77
+ exports.UserView = UserView;
78
+ function readAccessorMetadata() {
79
+ return registry.read(UserView).accessorRecords('cached').map((record) => {
80
+ if (record.memberName === undefined)
81
+ throw new Error('Missing member name.');
82
+ return {
83
+ memberName: record.memberName,
84
+ ttlMs: record.metadata.ttlMs,
85
+ };
86
+ });
87
+ }
@@ -0,0 +1,50 @@
1
+ type CrudController<TEntity, TCreateInput> = {
2
+ id: string;
3
+ get(id: string): Promise<TEntity>;
4
+ create(input: TCreateInput): Promise<TEntity>;
5
+ };
6
+ type UserDto = {
7
+ id: string;
8
+ email: string;
9
+ };
10
+ type CreateUserInput = {
11
+ email: string;
12
+ };
13
+ type UserCrudController = CrudController<UserDto, CreateUserInput>;
14
+ type CrudDecorators = {
15
+ class: {
16
+ resource: {
17
+ metadata: {
18
+ name: string;
19
+ };
20
+ };
21
+ };
22
+ property: {
23
+ idField: {
24
+ metadata: undefined;
25
+ target: string;
26
+ };
27
+ };
28
+ method: {
29
+ route: {
30
+ metadata: {
31
+ method: 'GET' | 'POST';
32
+ path: string;
33
+ };
34
+ target: (...args: any[]) => Promise<unknown>;
35
+ };
36
+ };
37
+ accessor: {};
38
+ };
39
+ declare const registry: import("../types").DecoratorRegistry<CrudDecorators>;
40
+ declare class UserCrud implements UserCrudController {
41
+ id: string;
42
+ get(id: string): Promise<UserDto>;
43
+ create(input: CreateUserInput): Promise<UserDto>;
44
+ }
45
+ export declare function buildCrudSummary(): {
46
+ resource: string;
47
+ routes: string[];
48
+ idFields: Array<string | symbol>;
49
+ };
50
+ export { UserCrud, registry as crudRegistry };
@@ -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 };