mm-share-lib 0.0.4 → 0.0.5
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/.eslintrc.js +25 -25
- package/.prettierrc +3 -3
- package/README.md +73 -73
- package/dist/src/exception/bad-request-error.exception.d.ts +4 -0
- package/dist/src/exception/bad-request-error.exception.js +12 -0
- package/dist/src/exception/bad-request-error.exception.js.map +1 -0
- package/dist/src/exception/base.exception.d.ts +21 -0
- package/dist/src/exception/base.exception.js +16 -0
- package/dist/src/exception/base.exception.js.map +1 -0
- package/dist/src/exception/conflict-error.exception.d.ts +4 -0
- package/dist/src/exception/conflict-error.exception.js +12 -0
- package/dist/src/exception/conflict-error.exception.js.map +1 -0
- package/dist/src/exception/forbidden-error.exception.d.ts +4 -0
- package/dist/src/exception/forbidden-error.exception.js +12 -0
- package/dist/src/exception/forbidden-error.exception.js.map +1 -0
- package/dist/src/exception/index.d.ts +7 -0
- package/dist/src/exception/index.js +23 -0
- package/dist/src/exception/index.js.map +1 -1
- package/dist/src/exception/internal-server-error.exception.d.ts +4 -0
- package/dist/src/exception/internal-server-error.exception.js +12 -0
- package/dist/src/exception/internal-server-error.exception.js.map +1 -0
- package/dist/src/exception/not-found-error.exception.d.ts +4 -0
- package/dist/src/exception/not-found-error.exception.js +12 -0
- package/dist/src/exception/not-found-error.exception.js.map +1 -0
- package/dist/src/exception/unauthorized-error.exception.d.ts +4 -0
- package/dist/src/exception/unauthorized-error.exception.js +12 -0
- package/dist/src/exception/unauthorized-error.exception.js.map +1 -0
- package/dist/src/filter/http-exception.filter.d.ts +4 -0
- package/dist/src/filter/http-exception.filter.js +27 -0
- package/dist/src/filter/http-exception.filter.js.map +1 -0
- package/dist/src/filter/index.d.ts +1 -0
- package/dist/src/filter/index.js +18 -0
- package/dist/src/filter/index.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/setup/index.d.ts +1 -0
- package/dist/src/setup/index.js +18 -0
- package/dist/src/setup/index.js.map +1 -0
- package/dist/src/setup/microservice.setup.d.ts +2 -0
- package/dist/src/setup/microservice.setup.js +25 -0
- package/dist/src/setup/microservice.setup.js.map +1 -0
- package/dist/src/setup/swagger.setup.d.ts +0 -0
- package/dist/src/setup/swagger.setup.js +1 -0
- package/dist/src/setup/swagger.setup.js.map +1 -0
- package/dist/src/util/app.utils.d.ts +4 -0
- package/dist/src/util/app.utils.js +21 -0
- package/dist/src/util/app.utils.js.map +1 -0
- package/dist/src/util/index.d.ts +1 -0
- package/dist/src/util/index.js +1 -0
- package/dist/src/util/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/index.ts +1 -1
- package/nest-cli.json +8 -8
- package/package.json +82 -81
- package/src/constant/entity-state.constant.ts +4 -4
- package/src/constant/index.ts +1 -1
- package/src/dto/base-filter.dto.ts +4 -4
- package/src/dto/index.ts +2 -2
- package/src/dto/pagination.dto.ts +4 -4
- package/src/exception/bad-request-error.exception.spec.ts +24 -0
- package/src/exception/bad-request-error.exception.ts +8 -0
- package/src/exception/base.exception.ts +36 -0
- package/src/exception/conflict-error.exception.spec.ts +23 -0
- package/src/exception/conflict-error.exception.ts +8 -0
- package/src/exception/forbidden-error.exception.spec.ts +23 -0
- package/src/exception/forbidden-error.exception.ts +8 -0
- package/src/exception/index.ts +7 -0
- package/src/exception/internal-server-error.exception.spec.ts +23 -0
- package/src/exception/internal-server-error.exception.ts +12 -0
- package/src/exception/not-found-error.exception.spec.ts +23 -0
- package/src/exception/not-found-error.exception.ts +8 -0
- package/src/exception/unauthorized-error.exception.spec.ts +23 -0
- package/src/exception/unauthorized-error.exception.ts +12 -0
- package/src/filter/http-exception.filter.ts +23 -0
- package/src/filter/index.ts +1 -0
- package/src/generic/entity/entity.generic.ts +34 -34
- package/src/generic/entity/index.ts +1 -1
- package/src/generic/index.ts +2 -2
- package/src/generic/service/index.ts +1 -1
- package/src/generic/service/service.generic.ts +112 -112
- package/src/index.ts +2 -0
- package/src/lib/index.ts +1 -1
- package/src/lib/search-engine/document/base.document.ts +2 -2
- package/src/lib/search-engine/index.ts +1 -1
- package/src/lib/search-engine/interface/index.ts +1 -1
- package/src/lib/search-engine/interface/search-document.interface.ts +5 -5
- package/src/lib/search-engine/interface/transform-service.interface.ts +10 -10
- package/src/lib/search-engine/typesense/index.ts +3 -3
- package/src/lib/search-engine/typesense/metadata/index.ts +1 -1
- package/src/lib/search-engine/typesense/metadata/schema.metadata.ts +13 -13
- package/src/lib/search-engine/typesense/metadata/typesense.metadata-registry.ts +28 -28
- package/src/lib/search-engine/typesense/service/client.service.ts +258 -258
- package/src/lib/search-engine/typesense/typesense-module.interface.ts +36 -36
- package/src/lib/search-engine/typesense/typesense.constants.ts +1 -1
- package/src/lib/search-engine/typesense/typesense.module.test.ts +94 -94
- package/src/lib/search-engine/typesense/typesense.module.ts +76 -76
- package/src/lib/search-engine/typesense/typesense.providers.ts +42 -42
- package/src/response/index.ts +1 -1
- package/src/response/pagination.response.ts +37 -37
- package/src/setup/index.ts +1 -0
- package/src/setup/microservice.setup.ts +29 -0
- package/src/setup/swagger.setup.ts +0 -0
- package/src/util/app.utils.ts +18 -0
- package/src/util/date.util.spec.ts +49 -49
- package/src/util/date.util.ts +10 -10
- package/src/util/generator.util.spec.ts +79 -79
- package/src/util/generator.util.ts +34 -34
- package/src/util/index.ts +3 -2
- package/test/app.e2e-spec.ts +24 -24
- package/test/jest-e2e.json +9 -9
- package/tsconfig.build.json +4 -4
- package/tsconfig.json +21 -21
@@ -1,94 +1,94 @@
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
2
|
-
|
3
|
-
import { Module } from '@nestjs/common'
|
4
|
-
import { Test } from '@nestjs/testing'
|
5
|
-
|
6
|
-
import { TypesenseModuleOptions } from './typesense-module.interface'
|
7
|
-
import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants'
|
8
|
-
import { TypesenseModule } from './typesense.module'
|
9
|
-
|
10
|
-
describe('typesense', () => {
|
11
|
-
describe('module', () => {
|
12
|
-
let module
|
13
|
-
|
14
|
-
afterEach(async () => {
|
15
|
-
await module.close()
|
16
|
-
})
|
17
|
-
|
18
|
-
it(`register`, async () => {
|
19
|
-
module = await Test.createTestingModule({
|
20
|
-
imports: [
|
21
|
-
TypesenseModule.register({
|
22
|
-
apiKey: 'test',
|
23
|
-
}),
|
24
|
-
],
|
25
|
-
}).compile()
|
26
|
-
|
27
|
-
expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
|
28
|
-
})
|
29
|
-
|
30
|
-
it(`register async use factory`, async () => {
|
31
|
-
module = await Test.createTestingModule({
|
32
|
-
imports: [
|
33
|
-
TypesenseModule.registerAsync({
|
34
|
-
useFactory: () => ({
|
35
|
-
apiKey: 'test',
|
36
|
-
}),
|
37
|
-
}),
|
38
|
-
],
|
39
|
-
}).compile()
|
40
|
-
|
41
|
-
expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
|
42
|
-
})
|
43
|
-
|
44
|
-
it(`register async use class`, async () => {
|
45
|
-
class TestTypesenseModuleOptions {
|
46
|
-
createTypesenseOptions(): TypesenseModuleOptions {
|
47
|
-
return {
|
48
|
-
apiKey: 'test',
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
module = await Test.createTestingModule({
|
54
|
-
imports: [
|
55
|
-
TypesenseModule.registerAsync({
|
56
|
-
useClass: TestTypesenseModuleOptions,
|
57
|
-
}),
|
58
|
-
],
|
59
|
-
}).compile()
|
60
|
-
|
61
|
-
expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
|
62
|
-
})
|
63
|
-
|
64
|
-
it(`register async use exists`, async () => {
|
65
|
-
class TestTypesenseModuleOptions {
|
66
|
-
createTypesenseOptions(): TypesenseModuleOptions {
|
67
|
-
return {
|
68
|
-
apiKey: 'test',
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
@Module({})
|
74
|
-
class TestTypesenseModule {}
|
75
|
-
|
76
|
-
module = await Test.createTestingModule({
|
77
|
-
imports: [
|
78
|
-
TypesenseModule.registerAsync({
|
79
|
-
imports: [
|
80
|
-
{
|
81
|
-
module: TestTypesenseModule,
|
82
|
-
providers: [TestTypesenseModuleOptions],
|
83
|
-
exports: [TestTypesenseModuleOptions],
|
84
|
-
},
|
85
|
-
],
|
86
|
-
useExisting: TestTypesenseModuleOptions,
|
87
|
-
}),
|
88
|
-
],
|
89
|
-
}).compile()
|
90
|
-
|
91
|
-
expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
|
92
|
-
})
|
93
|
-
})
|
94
|
-
})
|
1
|
+
/* eslint-disable max-classes-per-file */
|
2
|
+
|
3
|
+
import { Module } from '@nestjs/common'
|
4
|
+
import { Test } from '@nestjs/testing'
|
5
|
+
|
6
|
+
import { TypesenseModuleOptions } from './typesense-module.interface'
|
7
|
+
import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants'
|
8
|
+
import { TypesenseModule } from './typesense.module'
|
9
|
+
|
10
|
+
describe('typesense', () => {
|
11
|
+
describe('module', () => {
|
12
|
+
let module
|
13
|
+
|
14
|
+
afterEach(async () => {
|
15
|
+
await module.close()
|
16
|
+
})
|
17
|
+
|
18
|
+
it(`register`, async () => {
|
19
|
+
module = await Test.createTestingModule({
|
20
|
+
imports: [
|
21
|
+
TypesenseModule.register({
|
22
|
+
apiKey: 'test',
|
23
|
+
}),
|
24
|
+
],
|
25
|
+
}).compile()
|
26
|
+
|
27
|
+
expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
|
28
|
+
})
|
29
|
+
|
30
|
+
it(`register async use factory`, async () => {
|
31
|
+
module = await Test.createTestingModule({
|
32
|
+
imports: [
|
33
|
+
TypesenseModule.registerAsync({
|
34
|
+
useFactory: () => ({
|
35
|
+
apiKey: 'test',
|
36
|
+
}),
|
37
|
+
}),
|
38
|
+
],
|
39
|
+
}).compile()
|
40
|
+
|
41
|
+
expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
|
42
|
+
})
|
43
|
+
|
44
|
+
it(`register async use class`, async () => {
|
45
|
+
class TestTypesenseModuleOptions {
|
46
|
+
createTypesenseOptions(): TypesenseModuleOptions {
|
47
|
+
return {
|
48
|
+
apiKey: 'test',
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
module = await Test.createTestingModule({
|
54
|
+
imports: [
|
55
|
+
TypesenseModule.registerAsync({
|
56
|
+
useClass: TestTypesenseModuleOptions,
|
57
|
+
}),
|
58
|
+
],
|
59
|
+
}).compile()
|
60
|
+
|
61
|
+
expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
|
62
|
+
})
|
63
|
+
|
64
|
+
it(`register async use exists`, async () => {
|
65
|
+
class TestTypesenseModuleOptions {
|
66
|
+
createTypesenseOptions(): TypesenseModuleOptions {
|
67
|
+
return {
|
68
|
+
apiKey: 'test',
|
69
|
+
}
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
@Module({})
|
74
|
+
class TestTypesenseModule {}
|
75
|
+
|
76
|
+
module = await Test.createTestingModule({
|
77
|
+
imports: [
|
78
|
+
TypesenseModule.registerAsync({
|
79
|
+
imports: [
|
80
|
+
{
|
81
|
+
module: TestTypesenseModule,
|
82
|
+
providers: [TestTypesenseModuleOptions],
|
83
|
+
exports: [TestTypesenseModuleOptions],
|
84
|
+
},
|
85
|
+
],
|
86
|
+
useExisting: TestTypesenseModuleOptions,
|
87
|
+
}),
|
88
|
+
],
|
89
|
+
}).compile()
|
90
|
+
|
91
|
+
expect(module.get(TYPESENSE_MODULE_OPTIONS)).toBeDefined()
|
92
|
+
})
|
93
|
+
})
|
94
|
+
})
|
@@ -1,76 +1,76 @@
|
|
1
|
-
import { DynamicModule, Module, Provider } from '@nestjs/common';
|
2
|
-
import { DiscoveryModule } from '@nestjs/core';
|
3
|
-
import {
|
4
|
-
TypesenseModuleAsyncOptions,
|
5
|
-
TypesenseOptionsFactory,
|
6
|
-
TypesenseModuleOptions,
|
7
|
-
} from './typesense-module.interface';
|
8
|
-
import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants';
|
9
|
-
import {
|
10
|
-
createTypesenseExportsProvider,
|
11
|
-
createTypesenseOptionsProvider,
|
12
|
-
} from './typesense.providers';
|
13
|
-
|
14
|
-
@Module({
|
15
|
-
imports: [DiscoveryModule],
|
16
|
-
})
|
17
|
-
export class TypesenseModule {
|
18
|
-
static register(options: TypesenseModuleOptions = {}): DynamicModule {
|
19
|
-
const optionsProviders = createTypesenseOptionsProvider(options);
|
20
|
-
const exportsProviders = createTypesenseExportsProvider();
|
21
|
-
|
22
|
-
return {
|
23
|
-
global: true,
|
24
|
-
module: TypesenseModule,
|
25
|
-
providers: [...optionsProviders, ...exportsProviders],
|
26
|
-
exports: exportsProviders,
|
27
|
-
};
|
28
|
-
}
|
29
|
-
|
30
|
-
static registerAsync(options: TypesenseModuleAsyncOptions): DynamicModule {
|
31
|
-
const exportsProviders = createTypesenseExportsProvider();
|
32
|
-
|
33
|
-
return {
|
34
|
-
global: true,
|
35
|
-
module: TypesenseModule,
|
36
|
-
imports: options.imports || [],
|
37
|
-
providers: [...this.createAsyncProviders(options), ...exportsProviders],
|
38
|
-
exports: exportsProviders,
|
39
|
-
};
|
40
|
-
}
|
41
|
-
|
42
|
-
private static createAsyncProviders(
|
43
|
-
options: TypesenseModuleAsyncOptions,
|
44
|
-
): Provider[] {
|
45
|
-
if (options.useExisting || options.useFactory) {
|
46
|
-
return [this.createAsyncOptionsProvider(options)];
|
47
|
-
}
|
48
|
-
|
49
|
-
return [
|
50
|
-
this.createAsyncOptionsProvider(options),
|
51
|
-
{
|
52
|
-
provide: options?.useClass,
|
53
|
-
useClass: options?.useClass,
|
54
|
-
},
|
55
|
-
];
|
56
|
-
}
|
57
|
-
|
58
|
-
private static createAsyncOptionsProvider(
|
59
|
-
options: TypesenseModuleAsyncOptions,
|
60
|
-
): Provider {
|
61
|
-
if (options.useFactory) {
|
62
|
-
return {
|
63
|
-
provide: TYPESENSE_MODULE_OPTIONS,
|
64
|
-
useFactory: options.useFactory,
|
65
|
-
inject: options.inject || [],
|
66
|
-
};
|
67
|
-
}
|
68
|
-
|
69
|
-
return {
|
70
|
-
provide: TYPESENSE_MODULE_OPTIONS,
|
71
|
-
useFactory: (optionsFactory: TypesenseOptionsFactory) =>
|
72
|
-
optionsFactory.createTypesenseOptions(),
|
73
|
-
inject: [options?.useExisting || options?.useClass],
|
74
|
-
};
|
75
|
-
}
|
76
|
-
}
|
1
|
+
import { DynamicModule, Module, Provider } from '@nestjs/common';
|
2
|
+
import { DiscoveryModule } from '@nestjs/core';
|
3
|
+
import {
|
4
|
+
TypesenseModuleAsyncOptions,
|
5
|
+
TypesenseOptionsFactory,
|
6
|
+
TypesenseModuleOptions,
|
7
|
+
} from './typesense-module.interface';
|
8
|
+
import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants';
|
9
|
+
import {
|
10
|
+
createTypesenseExportsProvider,
|
11
|
+
createTypesenseOptionsProvider,
|
12
|
+
} from './typesense.providers';
|
13
|
+
|
14
|
+
@Module({
|
15
|
+
imports: [DiscoveryModule],
|
16
|
+
})
|
17
|
+
export class TypesenseModule {
|
18
|
+
static register(options: TypesenseModuleOptions = {}): DynamicModule {
|
19
|
+
const optionsProviders = createTypesenseOptionsProvider(options);
|
20
|
+
const exportsProviders = createTypesenseExportsProvider();
|
21
|
+
|
22
|
+
return {
|
23
|
+
global: true,
|
24
|
+
module: TypesenseModule,
|
25
|
+
providers: [...optionsProviders, ...exportsProviders],
|
26
|
+
exports: exportsProviders,
|
27
|
+
};
|
28
|
+
}
|
29
|
+
|
30
|
+
static registerAsync(options: TypesenseModuleAsyncOptions): DynamicModule {
|
31
|
+
const exportsProviders = createTypesenseExportsProvider();
|
32
|
+
|
33
|
+
return {
|
34
|
+
global: true,
|
35
|
+
module: TypesenseModule,
|
36
|
+
imports: options.imports || [],
|
37
|
+
providers: [...this.createAsyncProviders(options), ...exportsProviders],
|
38
|
+
exports: exportsProviders,
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
|
+
private static createAsyncProviders(
|
43
|
+
options: TypesenseModuleAsyncOptions,
|
44
|
+
): Provider[] {
|
45
|
+
if (options.useExisting || options.useFactory) {
|
46
|
+
return [this.createAsyncOptionsProvider(options)];
|
47
|
+
}
|
48
|
+
|
49
|
+
return [
|
50
|
+
this.createAsyncOptionsProvider(options),
|
51
|
+
{
|
52
|
+
provide: options?.useClass,
|
53
|
+
useClass: options?.useClass,
|
54
|
+
},
|
55
|
+
];
|
56
|
+
}
|
57
|
+
|
58
|
+
private static createAsyncOptionsProvider(
|
59
|
+
options: TypesenseModuleAsyncOptions,
|
60
|
+
): Provider {
|
61
|
+
if (options.useFactory) {
|
62
|
+
return {
|
63
|
+
provide: TYPESENSE_MODULE_OPTIONS,
|
64
|
+
useFactory: options.useFactory,
|
65
|
+
inject: options.inject || [],
|
66
|
+
};
|
67
|
+
}
|
68
|
+
|
69
|
+
return {
|
70
|
+
provide: TYPESENSE_MODULE_OPTIONS,
|
71
|
+
useFactory: (optionsFactory: TypesenseOptionsFactory) =>
|
72
|
+
optionsFactory.createTypesenseOptions(),
|
73
|
+
inject: [options?.useExisting || options?.useClass],
|
74
|
+
};
|
75
|
+
}
|
76
|
+
}
|
@@ -1,42 +1,42 @@
|
|
1
|
-
import { Provider } from '@nestjs/common';
|
2
|
-
import { Client } from 'typesense';
|
3
|
-
import { TypesenseMetadataRegistry } from './metadata';
|
4
|
-
import { TypesenseModuleOptions } from './typesense-module.interface';
|
5
|
-
import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants';
|
6
|
-
|
7
|
-
export const createTypesenseOptionsProvider = (
|
8
|
-
options: TypesenseModuleOptions = {},
|
9
|
-
): Provider[] => [
|
10
|
-
{
|
11
|
-
provide: TYPESENSE_MODULE_OPTIONS,
|
12
|
-
useValue: options,
|
13
|
-
},
|
14
|
-
];
|
15
|
-
|
16
|
-
export const createTypesenseExportsProvider = (): Provider[] => [
|
17
|
-
TypesenseMetadataRegistry,
|
18
|
-
{
|
19
|
-
provide: Client,
|
20
|
-
useFactory: (options: TypesenseModuleOptions) =>
|
21
|
-
new Client({
|
22
|
-
nodes: options.nodes || [
|
23
|
-
{
|
24
|
-
host:
|
25
|
-
process.env.TYPESENSE_HOST ||
|
26
|
-
process.env.NODE_ENV === 'production'
|
27
|
-
? 'ts.typesense.svc.cluster.local'
|
28
|
-
: 'localhost',
|
29
|
-
port: 8108,
|
30
|
-
protocol: 'http',
|
31
|
-
},
|
32
|
-
],
|
33
|
-
numRetries: options.numRetries || 10,
|
34
|
-
apiKey: options.apiKey || process.env.TYPESENSE_API_KEY,
|
35
|
-
connectionTimeoutSeconds: options.connectionTimeoutSeconds || 10,
|
36
|
-
retryIntervalSeconds: options.retryIntervalSeconds || 0.1,
|
37
|
-
healthcheckIntervalSeconds: options.healthcheckIntervalSeconds || 2,
|
38
|
-
logLevel: options.logLevel || 'info',
|
39
|
-
}),
|
40
|
-
inject: [TYPESENSE_MODULE_OPTIONS],
|
41
|
-
},
|
42
|
-
];
|
1
|
+
import { Provider } from '@nestjs/common';
|
2
|
+
import { Client } from 'typesense';
|
3
|
+
import { TypesenseMetadataRegistry } from './metadata';
|
4
|
+
import { TypesenseModuleOptions } from './typesense-module.interface';
|
5
|
+
import { TYPESENSE_MODULE_OPTIONS } from './typesense.constants';
|
6
|
+
|
7
|
+
export const createTypesenseOptionsProvider = (
|
8
|
+
options: TypesenseModuleOptions = {},
|
9
|
+
): Provider[] => [
|
10
|
+
{
|
11
|
+
provide: TYPESENSE_MODULE_OPTIONS,
|
12
|
+
useValue: options,
|
13
|
+
},
|
14
|
+
];
|
15
|
+
|
16
|
+
export const createTypesenseExportsProvider = (): Provider[] => [
|
17
|
+
TypesenseMetadataRegistry,
|
18
|
+
{
|
19
|
+
provide: Client,
|
20
|
+
useFactory: (options: TypesenseModuleOptions) =>
|
21
|
+
new Client({
|
22
|
+
nodes: options.nodes || [
|
23
|
+
{
|
24
|
+
host:
|
25
|
+
process.env.TYPESENSE_HOST ||
|
26
|
+
process.env.NODE_ENV === 'production'
|
27
|
+
? 'ts.typesense.svc.cluster.local'
|
28
|
+
: 'localhost',
|
29
|
+
port: 8108,
|
30
|
+
protocol: 'http',
|
31
|
+
},
|
32
|
+
],
|
33
|
+
numRetries: options.numRetries || 10,
|
34
|
+
apiKey: options.apiKey || process.env.TYPESENSE_API_KEY,
|
35
|
+
connectionTimeoutSeconds: options.connectionTimeoutSeconds || 10,
|
36
|
+
retryIntervalSeconds: options.retryIntervalSeconds || 0.1,
|
37
|
+
healthcheckIntervalSeconds: options.healthcheckIntervalSeconds || 2,
|
38
|
+
logLevel: options.logLevel || 'info',
|
39
|
+
}),
|
40
|
+
inject: [TYPESENSE_MODULE_OPTIONS],
|
41
|
+
},
|
42
|
+
];
|
package/src/response/index.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from './pagination.response';
|
1
|
+
export * from './pagination.response';
|
@@ -1,37 +1,37 @@
|
|
1
|
-
export class PaginationResponse<T> {
|
2
|
-
data: T[];
|
3
|
-
total?: number;
|
4
|
-
offset?: number;
|
5
|
-
limit?: number;
|
6
|
-
hasNext?: boolean;
|
7
|
-
|
8
|
-
constructor(
|
9
|
-
data: T[],
|
10
|
-
total: number = data?.length || 0,
|
11
|
-
limit?: number,
|
12
|
-
offset?: number,
|
13
|
-
) {
|
14
|
-
this.data = data;
|
15
|
-
this.total = total;
|
16
|
-
this.offset = offset;
|
17
|
-
this.limit = limit;
|
18
|
-
this.hasNext = this.offset + this.limit < this.total;
|
19
|
-
}
|
20
|
-
|
21
|
-
toJSON() {
|
22
|
-
return {
|
23
|
-
data: this.data,
|
24
|
-
total: this.total,
|
25
|
-
count: this.data.length,
|
26
|
-
offset: this.offset,
|
27
|
-
limit: this.limit,
|
28
|
-
hasNext: this.hasNext,
|
29
|
-
};
|
30
|
-
}
|
31
|
-
|
32
|
-
promise(): Promise<PaginationResponse<T>> {
|
33
|
-
return new Promise((resolve, reject) => {
|
34
|
-
resolve(this);
|
35
|
-
});
|
36
|
-
}
|
37
|
-
}
|
1
|
+
export class PaginationResponse<T> {
|
2
|
+
data: T[];
|
3
|
+
total?: number;
|
4
|
+
offset?: number;
|
5
|
+
limit?: number;
|
6
|
+
hasNext?: boolean;
|
7
|
+
|
8
|
+
constructor(
|
9
|
+
data: T[],
|
10
|
+
total: number = data?.length || 0,
|
11
|
+
limit?: number,
|
12
|
+
offset?: number,
|
13
|
+
) {
|
14
|
+
this.data = data;
|
15
|
+
this.total = total;
|
16
|
+
this.offset = offset;
|
17
|
+
this.limit = limit;
|
18
|
+
this.hasNext = this.offset + this.limit < this.total;
|
19
|
+
}
|
20
|
+
|
21
|
+
toJSON() {
|
22
|
+
return {
|
23
|
+
data: this.data,
|
24
|
+
total: this.total,
|
25
|
+
count: this.data.length,
|
26
|
+
offset: this.offset,
|
27
|
+
limit: this.limit,
|
28
|
+
hasNext: this.hasNext,
|
29
|
+
};
|
30
|
+
}
|
31
|
+
|
32
|
+
promise(): Promise<PaginationResponse<T>> {
|
33
|
+
return new Promise((resolve, reject) => {
|
34
|
+
resolve(this);
|
35
|
+
});
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './microservice.setup';
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import type { INestApplication } from '@nestjs/common';
|
2
|
+
import { Logger } from '@nestjs/common';
|
3
|
+
import { Transport } from '@nestjs/microservices';
|
4
|
+
|
5
|
+
import { AppUtils } from '../util';
|
6
|
+
|
7
|
+
export async function microserviceSetup(
|
8
|
+
app: INestApplication,
|
9
|
+
serviceName: string,
|
10
|
+
) {
|
11
|
+
AppUtils.killAppWithGrace(app);
|
12
|
+
const protoBasePath = process.cwd() + '/libs/proto-schema/src/proto';
|
13
|
+
const host = process.env['GRPC_HOST'];
|
14
|
+
const port = process.env['GRPC_PORT'];
|
15
|
+
const options = {
|
16
|
+
transport: Transport.GRPC,
|
17
|
+
options: {
|
18
|
+
url: `${host}:${port}`,
|
19
|
+
protoPath: `${protoBasePath}/${serviceName}.proto`,
|
20
|
+
package: `${serviceName}`,
|
21
|
+
},
|
22
|
+
};
|
23
|
+
app.connectMicroservice(options);
|
24
|
+
await app.startAllMicroservices();
|
25
|
+
Logger.log(
|
26
|
+
`GRPC ${serviceName} running on ${options.options.url}`,
|
27
|
+
'Bootstrap',
|
28
|
+
);
|
29
|
+
}
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { INestApplication } from '@nestjs/common';
|
2
|
+
|
3
|
+
export class AppUtils {
|
4
|
+
public static killAppWithGrace = (app: INestApplication) => {
|
5
|
+
process.on('SIGINT', async () => {
|
6
|
+
setTimeout(() => process.exit(1), 5000);
|
7
|
+
await app.close();
|
8
|
+
process.exit(0);
|
9
|
+
});
|
10
|
+
|
11
|
+
// kill -15
|
12
|
+
process.on('SIGTERM', async () => {
|
13
|
+
setTimeout(() => process.exit(1), 5000);
|
14
|
+
await app.close();
|
15
|
+
process.exit(0);
|
16
|
+
});
|
17
|
+
};
|
18
|
+
}
|
@@ -1,49 +1,49 @@
|
|
1
|
-
import dayjs from 'dayjs';
|
2
|
-
import { addSecond, isExpired } from './date.util';
|
3
|
-
|
4
|
-
describe('Utility Functions', () => {
|
5
|
-
test('addSecond should return a Date object with the specified duration added', () => {
|
6
|
-
// Arrange
|
7
|
-
const duration = 10;
|
8
|
-
|
9
|
-
// Act
|
10
|
-
const result = addSecond(duration);
|
11
|
-
|
12
|
-
// Assert
|
13
|
-
const expectedDate = dayjs().add(duration, 'seconds').toDate();
|
14
|
-
expect(result).toEqual(expectedDate);
|
15
|
-
});
|
16
|
-
|
17
|
-
test('isExpired should return true for a past date', () => {
|
18
|
-
// Arrange
|
19
|
-
const pastDate = dayjs().subtract(1, 'day').toDate();
|
20
|
-
|
21
|
-
// Act
|
22
|
-
const result = isExpired(pastDate);
|
23
|
-
|
24
|
-
// Assert
|
25
|
-
expect(result).toBe(true);
|
26
|
-
});
|
27
|
-
|
28
|
-
test('isExpired should return false for a future date', () => {
|
29
|
-
// Arrange
|
30
|
-
const futureDate = dayjs().add(1, 'day').toDate();
|
31
|
-
|
32
|
-
// Act
|
33
|
-
const result = isExpired(futureDate);
|
34
|
-
|
35
|
-
// Assert
|
36
|
-
expect(result).toBe(false);
|
37
|
-
});
|
38
|
-
|
39
|
-
test('isExpired should return false for the current date', () => {
|
40
|
-
// Arrange
|
41
|
-
const currentDate = dayjs().toDate();
|
42
|
-
|
43
|
-
// Act
|
44
|
-
const result = isExpired(currentDate);
|
45
|
-
|
46
|
-
// Assert
|
47
|
-
expect(result).toBe(false);
|
48
|
-
});
|
49
|
-
});
|
1
|
+
import dayjs from 'dayjs';
|
2
|
+
import { addSecond, isExpired } from './date.util';
|
3
|
+
|
4
|
+
describe('Utility Functions', () => {
|
5
|
+
test('addSecond should return a Date object with the specified duration added', () => {
|
6
|
+
// Arrange
|
7
|
+
const duration = 10;
|
8
|
+
|
9
|
+
// Act
|
10
|
+
const result = addSecond(duration);
|
11
|
+
|
12
|
+
// Assert
|
13
|
+
const expectedDate = dayjs().add(duration, 'seconds').toDate();
|
14
|
+
expect(result).toEqual(expectedDate);
|
15
|
+
});
|
16
|
+
|
17
|
+
test('isExpired should return true for a past date', () => {
|
18
|
+
// Arrange
|
19
|
+
const pastDate = dayjs().subtract(1, 'day').toDate();
|
20
|
+
|
21
|
+
// Act
|
22
|
+
const result = isExpired(pastDate);
|
23
|
+
|
24
|
+
// Assert
|
25
|
+
expect(result).toBe(true);
|
26
|
+
});
|
27
|
+
|
28
|
+
test('isExpired should return false for a future date', () => {
|
29
|
+
// Arrange
|
30
|
+
const futureDate = dayjs().add(1, 'day').toDate();
|
31
|
+
|
32
|
+
// Act
|
33
|
+
const result = isExpired(futureDate);
|
34
|
+
|
35
|
+
// Assert
|
36
|
+
expect(result).toBe(false);
|
37
|
+
});
|
38
|
+
|
39
|
+
test('isExpired should return false for the current date', () => {
|
40
|
+
// Arrange
|
41
|
+
const currentDate = dayjs().toDate();
|
42
|
+
|
43
|
+
// Act
|
44
|
+
const result = isExpired(currentDate);
|
45
|
+
|
46
|
+
// Assert
|
47
|
+
expect(result).toBe(false);
|
48
|
+
});
|
49
|
+
});
|