@e22m4u/ts-rest-router 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/.c8rc +9 -0
- package/.commitlintrc +5 -0
- package/.editorconfig +13 -0
- package/.husky/commit-msg +1 -0
- package/.husky/pre-commit +6 -0
- package/.mocharc.json +5 -0
- package/.prettierrc +7 -0
- package/LICENSE +21 -0
- package/README-ru.md +41 -0
- package/README.md +41 -0
- package/build-cjs.js +16 -0
- package/dist/cjs/index.cjs +692 -0
- package/dist/esm/controller-registry.d.ts +65 -0
- package/dist/esm/controller-registry.js +281 -0
- package/dist/esm/controller-registry.spec.d.ts +1 -0
- package/dist/esm/controller-registry.spec.js +719 -0
- package/dist/esm/debuggable-service.d.ts +18 -0
- package/dist/esm/debuggable-service.js +23 -0
- package/dist/esm/debuggable-service.spec.d.ts +1 -0
- package/dist/esm/debuggable-service.spec.js +16 -0
- package/dist/esm/decorators/action/action-decorator.d.ts +53 -0
- package/dist/esm/decorators/action/action-decorator.js +66 -0
- package/dist/esm/decorators/action/action-decorator.spec.d.ts +1 -0
- package/dist/esm/decorators/action/action-decorator.spec.js +59 -0
- package/dist/esm/decorators/action/action-metadata.d.ts +23 -0
- package/dist/esm/decorators/action/action-metadata.js +5 -0
- package/dist/esm/decorators/action/action-reflector.d.ts +22 -0
- package/dist/esm/decorators/action/action-reflector.js +29 -0
- package/dist/esm/decorators/action/action-reflector.spec.d.ts +1 -0
- package/dist/esm/decorators/action/action-reflector.spec.js +84 -0
- package/dist/esm/decorators/action/index.d.ts +3 -0
- package/dist/esm/decorators/action/index.js +3 -0
- package/dist/esm/decorators/controller/controller-decorator.d.ts +13 -0
- package/dist/esm/decorators/controller/controller-decorator.js +20 -0
- package/dist/esm/decorators/controller/controller-decorator.spec.d.ts +1 -0
- package/dist/esm/decorators/controller/controller-decorator.spec.js +53 -0
- package/dist/esm/decorators/controller/controller-metadata.d.ts +17 -0
- package/dist/esm/decorators/controller/controller-metadata.js +5 -0
- package/dist/esm/decorators/controller/controller-reflector.d.ts +20 -0
- package/dist/esm/decorators/controller/controller-reflector.js +24 -0
- package/dist/esm/decorators/controller/controller-reflector.spec.d.ts +1 -0
- package/dist/esm/decorators/controller/controller-reflector.spec.js +45 -0
- package/dist/esm/decorators/controller/index.d.ts +3 -0
- package/dist/esm/decorators/controller/index.js +3 -0
- package/dist/esm/decorators/index.d.ts +4 -0
- package/dist/esm/decorators/index.js +4 -0
- package/dist/esm/decorators/request-context/index.d.ts +3 -0
- package/dist/esm/decorators/request-context/index.js +3 -0
- package/dist/esm/decorators/request-context/request-context-decorator.d.ts +17 -0
- package/dist/esm/decorators/request-context/request-context-decorator.js +32 -0
- package/dist/esm/decorators/request-context/request-context-decorator.spec.d.ts +1 -0
- package/dist/esm/decorators/request-context/request-context-decorator.spec.js +59 -0
- package/dist/esm/decorators/request-context/request-context-metadata.d.ts +17 -0
- package/dist/esm/decorators/request-context/request-context-metadata.js +5 -0
- package/dist/esm/decorators/request-context/request-context-reflector.d.ts +24 -0
- package/dist/esm/decorators/request-context/request-context-reflector.js +31 -0
- package/dist/esm/decorators/request-context/request-context-reflector.spec.d.ts +1 -0
- package/dist/esm/decorators/request-context/request-context-reflector.spec.js +59 -0
- package/dist/esm/decorators/request-data/index.d.ts +3 -0
- package/dist/esm/decorators/request-data/index.js +3 -0
- package/dist/esm/decorators/request-data/request-data-decorator.d.ts +28 -0
- package/dist/esm/decorators/request-data/request-data-decorator.js +84 -0
- package/dist/esm/decorators/request-data/request-data-decorator.spec.d.ts +1 -0
- package/dist/esm/decorators/request-data/request-data-decorator.spec.js +534 -0
- package/dist/esm/decorators/request-data/request-data-metadata.d.ts +29 -0
- package/dist/esm/decorators/request-data/request-data-metadata.js +16 -0
- package/dist/esm/decorators/request-data/request-data-reflector.d.ts +24 -0
- package/dist/esm/decorators/request-data/request-data-reflector.js +31 -0
- package/dist/esm/decorators/request-data/request-data-reflector.spec.d.ts +1 -0
- package/dist/esm/decorators/request-data/request-data-reflector.spec.js +60 -0
- package/dist/esm/errors/index.d.ts +1 -0
- package/dist/esm/errors/index.js +1 -0
- package/dist/esm/errors/not-a-controller-error.d.ts +12 -0
- package/dist/esm/errors/not-a-controller-error.js +14 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/rest-router.d.ts +19 -0
- package/dist/esm/rest-router.js +24 -0
- package/dist/esm/types.d.ts +57 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/utils/capitalize.d.ts +6 -0
- package/dist/esm/utils/capitalize.js +8 -0
- package/dist/esm/utils/capitalize.spec.d.ts +1 -0
- package/dist/esm/utils/capitalize.spec.js +8 -0
- package/dist/esm/utils/create-debugger.d.ts +11 -0
- package/dist/esm/utils/create-debugger.js +15 -0
- package/dist/esm/utils/create-debugger.spec.d.ts +1 -0
- package/dist/esm/utils/create-debugger.spec.js +8 -0
- package/dist/esm/utils/create-error.d.ts +10 -0
- package/dist/esm/utils/create-error.js +13 -0
- package/dist/esm/utils/create-error.spec.d.ts +1 -0
- package/dist/esm/utils/create-error.spec.js +8 -0
- package/dist/esm/utils/index.d.ts +4 -0
- package/dist/esm/utils/index.js +4 -0
- package/dist/esm/utils/to-camel-case.d.ts +6 -0
- package/dist/esm/utils/to-camel-case.js +11 -0
- package/dist/esm/utils/to-camel-case.spec.d.ts +1 -0
- package/dist/esm/utils/to-camel-case.spec.js +10 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/eslint.config.js +43 -0
- package/package.json +74 -0
- package/src/controller-registry.spec.ts +592 -0
- package/src/controller-registry.ts +355 -0
- package/src/debuggable-service.spec.ts +18 -0
- package/src/debuggable-service.ts +27 -0
- package/src/decorators/action/action-decorator.spec.ts +42 -0
- package/src/decorators/action/action-decorator.ts +100 -0
- package/src/decorators/action/action-metadata.ts +28 -0
- package/src/decorators/action/action-reflector.spec.ts +84 -0
- package/src/decorators/action/action-reflector.ts +38 -0
- package/src/decorators/action/index.ts +3 -0
- package/src/decorators/controller/controller-decorator.spec.ts +41 -0
- package/src/decorators/controller/controller-decorator.ts +29 -0
- package/src/decorators/controller/controller-metadata.ts +21 -0
- package/src/decorators/controller/controller-reflector.spec.ts +45 -0
- package/src/decorators/controller/controller-reflector.ts +28 -0
- package/src/decorators/controller/index.ts +3 -0
- package/src/decorators/index.ts +4 -0
- package/src/decorators/request-context/index.ts +3 -0
- package/src/decorators/request-context/request-context-decorator.spec.ts +41 -0
- package/src/decorators/request-context/request-context-decorator.ts +57 -0
- package/src/decorators/request-context/request-context-metadata.ts +21 -0
- package/src/decorators/request-context/request-context-reflector.spec.ts +77 -0
- package/src/decorators/request-context/request-context-reflector.ts +57 -0
- package/src/decorators/request-data/index.ts +3 -0
- package/src/decorators/request-data/request-data-decorator.spec.ts +477 -0
- package/src/decorators/request-data/request-data-decorator.ts +106 -0
- package/src/decorators/request-data/request-data-metadata.ts +34 -0
- package/src/decorators/request-data/request-data-reflector.spec.ts +78 -0
- package/src/decorators/request-data/request-data-reflector.ts +57 -0
- package/src/errors/index.ts +1 -0
- package/src/errors/not-a-controller-error.ts +15 -0
- package/src/index.ts +5 -0
- package/src/rest-router.ts +31 -0
- package/src/types.ts +59 -0
- package/src/utils/capitalize.spec.ts +9 -0
- package/src/utils/capitalize.ts +8 -0
- package/src/utils/create-debugger.spec.ts +9 -0
- package/src/utils/create-debugger.ts +21 -0
- package/src/utils/create-error.spec.ts +9 -0
- package/src/utils/create-error.ts +19 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/to-camel-case.spec.ts +11 -0
- package/src/utils/to-camel-case.ts +11 -0
- package/tsconfig.json +17 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
import { expect } from 'chai';
|
2
|
+
import { describe } from 'mocha';
|
3
|
+
import { Reflector } from '@e22m4u/ts-reflector';
|
4
|
+
import { RequestDataSource } from './request-data-metadata.js';
|
5
|
+
import { RequestDataReflector } from './request-data-reflector.js';
|
6
|
+
import { REQUEST_DATA_METADATA_KEY } from './request-data-metadata.js';
|
7
|
+
describe('RequestDataReflector', function () {
|
8
|
+
describe('setMetadata', function () {
|
9
|
+
it('sets a given value as target metadata', function () {
|
10
|
+
class Target {
|
11
|
+
}
|
12
|
+
const md1 = { source: RequestDataSource.PARAMS };
|
13
|
+
const md2 = { source: RequestDataSource.QUERY };
|
14
|
+
RequestDataReflector.setMetadata(md1, Target, 0, 'propertyKey');
|
15
|
+
RequestDataReflector.setMetadata(md2, Target, 1, 'propertyKey');
|
16
|
+
const res = Reflector.getOwnMetadata(REQUEST_DATA_METADATA_KEY, Target, 'propertyKey');
|
17
|
+
expect(res).to.be.instanceof(Map);
|
18
|
+
expect(res.get(0)).to.be.eq(md1);
|
19
|
+
expect(res.get(1)).to.be.eq(md2);
|
20
|
+
});
|
21
|
+
it('overrides existing metadata', function () {
|
22
|
+
class Target {
|
23
|
+
}
|
24
|
+
const md1 = { source: RequestDataSource.PARAMS };
|
25
|
+
const md2 = { source: RequestDataSource.QUERY };
|
26
|
+
RequestDataReflector.setMetadata(md1, Target, 0, 'propertyKey');
|
27
|
+
const res1 = Reflector.getOwnMetadata(REQUEST_DATA_METADATA_KEY, Target, 'propertyKey');
|
28
|
+
expect(res1).to.be.instanceof(Map);
|
29
|
+
expect(res1.get(0)).to.be.eq(md1);
|
30
|
+
RequestDataReflector.setMetadata(md2, Target, 0, 'propertyKey');
|
31
|
+
const res2 = Reflector.getOwnMetadata(REQUEST_DATA_METADATA_KEY, Target, 'propertyKey');
|
32
|
+
expect(res2).to.be.instanceof(Map);
|
33
|
+
expect(res2.get(0)).to.be.eq(md2);
|
34
|
+
});
|
35
|
+
});
|
36
|
+
describe('getMetadata', function () {
|
37
|
+
it('returns an existing metadata of the target', function () {
|
38
|
+
class Target {
|
39
|
+
}
|
40
|
+
const md1 = { source: RequestDataSource.PARAMS };
|
41
|
+
const md2 = { source: RequestDataSource.QUERY };
|
42
|
+
const mdMap = new Map([
|
43
|
+
[0, md1],
|
44
|
+
[1, md2],
|
45
|
+
]);
|
46
|
+
Reflector.defineMetadata(REQUEST_DATA_METADATA_KEY, mdMap, Target, 'propertyKey');
|
47
|
+
const res = RequestDataReflector.getMetadata(Target, 'propertyKey');
|
48
|
+
expect(res).to.be.instanceof(Map);
|
49
|
+
expect(res.get(0)).to.be.eq(md1);
|
50
|
+
expect(res.get(1)).to.be.eq(md2);
|
51
|
+
});
|
52
|
+
it('returns an empty map if no metadata', function () {
|
53
|
+
class Target {
|
54
|
+
}
|
55
|
+
const res = RequestDataReflector.getMetadata(Target, 'propertyKey');
|
56
|
+
expect(res).to.be.instanceof(Map);
|
57
|
+
expect(res).to.be.empty;
|
58
|
+
});
|
59
|
+
});
|
60
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './not-a-controller-error.js';
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './not-a-controller-error.js';
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Errorf } from '@e22m4u/js-format';
|
2
|
+
/**
|
3
|
+
* Not a controller error.
|
4
|
+
*/
|
5
|
+
export class NotAControllerError extends Errorf {
|
6
|
+
/**
|
7
|
+
* Constructor.
|
8
|
+
*
|
9
|
+
* @param value
|
10
|
+
*/
|
11
|
+
constructor(value) {
|
12
|
+
super('%v is not a controller, do use @controller decorator on it.', value);
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Constructor } from './types.js';
|
2
|
+
import { DebuggableService } from './debuggable-service.js';
|
3
|
+
import { ControllerRootOptions } from './controller-registry.js';
|
4
|
+
/**
|
5
|
+
* Rest router.
|
6
|
+
*/
|
7
|
+
export declare class RestRouter extends DebuggableService {
|
8
|
+
/**
|
9
|
+
* Request listener.
|
10
|
+
*/
|
11
|
+
get requestListener(): import("http").RequestListener;
|
12
|
+
/**
|
13
|
+
* Add controller.
|
14
|
+
*
|
15
|
+
* @param ctor
|
16
|
+
* @param options
|
17
|
+
*/
|
18
|
+
addController<T extends object>(ctor: Constructor<T>, options?: ControllerRootOptions): this;
|
19
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { TrieRouter } from '@e22m4u/js-trie-router';
|
2
|
+
import { DebuggableService } from './debuggable-service.js';
|
3
|
+
import { ControllerRegistry } from './controller-registry.js';
|
4
|
+
/**
|
5
|
+
* Rest router.
|
6
|
+
*/
|
7
|
+
export class RestRouter extends DebuggableService {
|
8
|
+
/**
|
9
|
+
* Request listener.
|
10
|
+
*/
|
11
|
+
get requestListener() {
|
12
|
+
return this.getService(TrieRouter).requestListener;
|
13
|
+
}
|
14
|
+
/**
|
15
|
+
* Add controller.
|
16
|
+
*
|
17
|
+
* @param ctor
|
18
|
+
* @param options
|
19
|
+
*/
|
20
|
+
addController(ctor, options) {
|
21
|
+
this.getService(ControllerRegistry).addController(ctor, options);
|
22
|
+
return this;
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
/**
|
2
|
+
* Function type that excludes
|
3
|
+
* class and constructor types.
|
4
|
+
*/
|
5
|
+
export type Callable<T = unknown> = (...args: any[]) => T;
|
6
|
+
/**
|
7
|
+
* Callable type with the "new" operator
|
8
|
+
* that allows class and constructor types.
|
9
|
+
*/
|
10
|
+
export interface Constructor<T = unknown> {
|
11
|
+
new (...args: any[]): T;
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Object prototype that excludes
|
15
|
+
* function and scalar values.
|
16
|
+
*/
|
17
|
+
export type Prototype<T = unknown> = T & object & {
|
18
|
+
bind?: never;
|
19
|
+
} & {
|
20
|
+
call?: never;
|
21
|
+
} & {
|
22
|
+
prototype?: object;
|
23
|
+
};
|
24
|
+
/**
|
25
|
+
* Make a specific property as optional.
|
26
|
+
*/
|
27
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
28
|
+
/**
|
29
|
+
* A part of the Flatten type.
|
30
|
+
*/
|
31
|
+
export type Identity<T> = T;
|
32
|
+
/**
|
33
|
+
* Makes T more human-readable.
|
34
|
+
*/
|
35
|
+
export type Flatten<T> = Identity<{
|
36
|
+
[k in keyof T]: T[k];
|
37
|
+
}>;
|
38
|
+
/**
|
39
|
+
* A promise or value.
|
40
|
+
*/
|
41
|
+
export type ValueOrPromise<T> = T | PromiseLike<T>;
|
42
|
+
/**
|
43
|
+
* Plain object.
|
44
|
+
*/
|
45
|
+
export type PlainObject = {
|
46
|
+
[key: string]: unknown;
|
47
|
+
};
|
48
|
+
/**
|
49
|
+
* Remove null and undefined from T.
|
50
|
+
*/
|
51
|
+
export type NoUndef<T> = Exclude<T, null | undefined>;
|
52
|
+
/**
|
53
|
+
* Object type with open properties.
|
54
|
+
*/
|
55
|
+
export type AnyObject = {
|
56
|
+
[property: PropertyKey]: any;
|
57
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { expect } from 'chai';
|
2
|
+
import { capitalize } from './capitalize.js';
|
3
|
+
describe('capitalize', function () {
|
4
|
+
it('makes the first letter to upper case', function () {
|
5
|
+
expect(capitalize('foo')).to.be.eq('Foo');
|
6
|
+
expect(capitalize('foo bar')).to.be.eq('Foo bar');
|
7
|
+
});
|
8
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { format } from '@e22m4u/js-format';
|
2
|
+
/**
|
3
|
+
* Debugger.
|
4
|
+
*/
|
5
|
+
export type Debugger = (...args: Parameters<typeof format>) => void;
|
6
|
+
/**
|
7
|
+
* Create debugger.
|
8
|
+
*
|
9
|
+
* @param name
|
10
|
+
*/
|
11
|
+
export declare function createDebugger(name: string): Debugger;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import DebugFactory from 'debug';
|
2
|
+
import { format } from '@e22m4u/js-format';
|
3
|
+
/**
|
4
|
+
* Create debugger.
|
5
|
+
*
|
6
|
+
* @param name
|
7
|
+
*/
|
8
|
+
export function createDebugger(name) {
|
9
|
+
const debug = DebugFactory(`tsRestRouter:${name}`);
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
11
|
+
return function (message, ...args) {
|
12
|
+
const interpolatedMessage = format(message, ...args);
|
13
|
+
return debug(interpolatedMessage);
|
14
|
+
};
|
15
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Constructor } from '../types.js';
|
2
|
+
/**
|
3
|
+
* Create error.
|
4
|
+
*
|
5
|
+
* @param {Function} errorCtor
|
6
|
+
* @param {string} message
|
7
|
+
* @param {*[]|undefined} args
|
8
|
+
* @returns {object}
|
9
|
+
*/
|
10
|
+
export declare function createError<T>(errorCtor: Constructor<T>, message: string, ...args: unknown[]): T;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { format } from '@e22m4u/js-format';
|
2
|
+
/**
|
3
|
+
* Create error.
|
4
|
+
*
|
5
|
+
* @param {Function} errorCtor
|
6
|
+
* @param {string} message
|
7
|
+
* @param {*[]|undefined} args
|
8
|
+
* @returns {object}
|
9
|
+
*/
|
10
|
+
export function createError(errorCtor, message, ...args) {
|
11
|
+
const interpolatedMessage = format(message, ...args);
|
12
|
+
return new errorCtor(interpolatedMessage);
|
13
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { expect } from 'chai';
|
2
|
+
import { createError } from './create-error.js';
|
3
|
+
describe('createError', function () {
|
4
|
+
it('interpolates the given message with arguments', function () {
|
5
|
+
const res = createError(Error, 'My %s', 'message');
|
6
|
+
expect(res.message).to.be.eq('My message');
|
7
|
+
});
|
8
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { expect } from 'chai';
|
2
|
+
import { toCamelCase } from './to-camel-case.js';
|
3
|
+
describe('toCamelCase', function () {
|
4
|
+
it('returns a camelCase string', function () {
|
5
|
+
expect(toCamelCase('TestString')).to.be.eq('testString');
|
6
|
+
expect(toCamelCase('test-string')).to.be.eq('testString');
|
7
|
+
expect(toCamelCase('test string')).to.be.eq('testString');
|
8
|
+
expect(toCamelCase('Test string')).to.be.eq('testString');
|
9
|
+
});
|
10
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
{"root":["../src/controller-registry.spec.ts","../src/controller-registry.ts","../src/debuggable-service.spec.ts","../src/debuggable-service.ts","../src/index.ts","../src/rest-router.ts","../src/types.ts","../src/decorators/index.ts","../src/decorators/action/action-decorator.spec.ts","../src/decorators/action/action-decorator.ts","../src/decorators/action/action-metadata.ts","../src/decorators/action/action-reflector.spec.ts","../src/decorators/action/action-reflector.ts","../src/decorators/action/index.ts","../src/decorators/controller/controller-decorator.spec.ts","../src/decorators/controller/controller-decorator.ts","../src/decorators/controller/controller-metadata.ts","../src/decorators/controller/controller-reflector.spec.ts","../src/decorators/controller/controller-reflector.ts","../src/decorators/controller/index.ts","../src/decorators/request-context/index.ts","../src/decorators/request-context/request-context-decorator.spec.ts","../src/decorators/request-context/request-context-decorator.ts","../src/decorators/request-context/request-context-metadata.ts","../src/decorators/request-context/request-context-reflector.spec.ts","../src/decorators/request-context/request-context-reflector.ts","../src/decorators/request-data/index.ts","../src/decorators/request-data/request-data-decorator.spec.ts","../src/decorators/request-data/request-data-decorator.ts","../src/decorators/request-data/request-data-metadata.ts","../src/decorators/request-data/request-data-reflector.spec.ts","../src/decorators/request-data/request-data-reflector.ts","../src/errors/index.ts","../src/errors/not-a-controller-error.ts","../src/utils/capitalize.spec.ts","../src/utils/capitalize.ts","../src/utils/create-debugger.spec.ts","../src/utils/create-debugger.ts","../src/utils/create-error.spec.ts","../src/utils/create-error.ts","../src/utils/index.ts","../src/utils/to-camel-case.spec.ts","../src/utils/to-camel-case.ts"],"version":"5.6.3"}
|
package/eslint.config.js
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
import globals from 'globals';
|
2
|
+
import eslintJs from '@eslint/js';
|
3
|
+
import eslintTypescript from 'typescript-eslint';
|
4
|
+
import eslintMochaPlugin from 'eslint-plugin-mocha';
|
5
|
+
import eslintPrettierConfig from 'eslint-config-prettier';
|
6
|
+
import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
|
7
|
+
|
8
|
+
export default [
|
9
|
+
{
|
10
|
+
ignores: ['**/*.js'],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
files: ['src/**/*.ts'],
|
14
|
+
languageOptions: {
|
15
|
+
globals: {
|
16
|
+
...globals.node,
|
17
|
+
...globals.es2021,
|
18
|
+
...globals.mocha,
|
19
|
+
},
|
20
|
+
parser: eslintTypescript.parser,
|
21
|
+
parserOptions: {
|
22
|
+
projectService: true,
|
23
|
+
tsconfigRootDir: import.meta.dirname,
|
24
|
+
},
|
25
|
+
},
|
26
|
+
plugins: {
|
27
|
+
'@typescript-eslint': eslintTypescript.plugin,
|
28
|
+
'mocha': eslintMochaPlugin,
|
29
|
+
'chai-expect': eslintChaiExpectPlugin,
|
30
|
+
},
|
31
|
+
rules: {
|
32
|
+
...eslintJs.configs.recommended.rules,
|
33
|
+
...eslintPrettierConfig.rules,
|
34
|
+
...eslintMochaPlugin.configs.flat.recommended.rules,
|
35
|
+
...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
|
36
|
+
...eslintTypescript.configs.recommended.reduce(
|
37
|
+
(rules, config) => ({...rules, ...config.rules}),
|
38
|
+
{},
|
39
|
+
),
|
40
|
+
'@typescript-eslint/no-unused-expressions': 'off',
|
41
|
+
},
|
42
|
+
},
|
43
|
+
];
|
package/package.json
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
{
|
2
|
+
"name": "@e22m4u/ts-rest-router",
|
3
|
+
"version": "0.0.2",
|
4
|
+
"description": "Controllers-based REST router implementation for TypeScript",
|
5
|
+
"author": "e22m4u <e22m4u@yandex.ru>",
|
6
|
+
"keywords": [
|
7
|
+
"rest",
|
8
|
+
"http",
|
9
|
+
"router",
|
10
|
+
"server",
|
11
|
+
"controller"
|
12
|
+
],
|
13
|
+
"homepage": "https://github.com/e22m4u/ts-rest-router",
|
14
|
+
"repository": {
|
15
|
+
"type": "git",
|
16
|
+
"url": "git+https://github.com/e22m4u/ts-rest-router.git"
|
17
|
+
},
|
18
|
+
"type": "module",
|
19
|
+
"module": "./dist/esm/index.js",
|
20
|
+
"main": "./dist/cjs/index.cjs",
|
21
|
+
"exports": {
|
22
|
+
"types": "./dist/esm/index.d.ts",
|
23
|
+
"import": "./dist/esm/index.js",
|
24
|
+
"require": "./dist/cjs/index.cjs"
|
25
|
+
},
|
26
|
+
"engines": {
|
27
|
+
"node": ">=16"
|
28
|
+
},
|
29
|
+
"scripts": {
|
30
|
+
"build:esm": "tsc --build",
|
31
|
+
"build:cjs": "rimraf ./dist/cjs && node --no-warnings=ExperimentalWarning build-cjs.js",
|
32
|
+
"build": "rimraf dist && npm run build:esm && npm run build:cjs",
|
33
|
+
"lint": "eslint ./src",
|
34
|
+
"lint:fix": "eslint ./src --fix",
|
35
|
+
"format": "prettier --write \"./src/**/*.ts\"",
|
36
|
+
"test": "npm run lint && c8 --reporter=text-summary mocha --bail",
|
37
|
+
"test:coverage": "npm run lint && c8 --reporter=text mocha --bail",
|
38
|
+
"prepare": "husky"
|
39
|
+
},
|
40
|
+
"dependencies": {
|
41
|
+
"@e22m4u/js-format": "0.1.x",
|
42
|
+
"@e22m4u/js-service": "0.1.x",
|
43
|
+
"@e22m4u/js-trie-router": "0.0.x",
|
44
|
+
"@e22m4u/ts-data-schema": "0.0.x",
|
45
|
+
"@e22m4u/ts-reflector": "0.1.x",
|
46
|
+
"debug": "~4.3.7",
|
47
|
+
"http-errors": "~2.0.0"
|
48
|
+
},
|
49
|
+
"devDependencies": {
|
50
|
+
"@commitlint/cli": "~19.5.0",
|
51
|
+
"@commitlint/config-conventional": "~19.5.0",
|
52
|
+
"@eslint/js": "~9.14.0",
|
53
|
+
"@types/chai": "~5.0.1",
|
54
|
+
"@types/debug": "~4.1.12",
|
55
|
+
"@types/http-errors": "~2.0.4",
|
56
|
+
"@types/mocha": "~10.0.9",
|
57
|
+
"@types/node": "~22.9.0",
|
58
|
+
"c8": "~10.1.2",
|
59
|
+
"chai": "~5.1.2",
|
60
|
+
"esbuild": "~0.24.0",
|
61
|
+
"eslint": "~9.14.0",
|
62
|
+
"eslint-config-prettier": "~9.1.0",
|
63
|
+
"eslint-plugin-chai-expect": "~3.1.0",
|
64
|
+
"eslint-plugin-mocha": "~10.5.0",
|
65
|
+
"husky": "~9.1.6",
|
66
|
+
"mocha": "~10.8.2",
|
67
|
+
"prettier": "~3.3.3",
|
68
|
+
"rimraf": "~6.0.1",
|
69
|
+
"tsx": "~4.19.2",
|
70
|
+
"typescript": "~5.6.3",
|
71
|
+
"typescript-eslint": "~8.13.0"
|
72
|
+
},
|
73
|
+
"license": "MIT"
|
74
|
+
}
|