@xnestjs/redisess 1.2.0 → 1.2.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Panates
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.REDISESS_MODULE_TOKEN = exports.REDISESS_MODULE_OPTIONS = void 0;
4
+ exports.REDISESS_MODULE_OPTIONS = Symbol('REDISESS_MODULE_OPTIONS');
5
+ exports.REDISESS_MODULE_TOKEN = Symbol('REDISESS_MODULE_ID');
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InjectSessionManager = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const get_session_manager_token_util_js_1 = require("../utils/get-session-manager-token.util.js");
6
+ const InjectSessionManager = (name) => (0, common_1.Inject)((0, get_session_manager_token_util_js_1.getSessionManagerToken)(name));
7
+ exports.InjectSessionManager = InjectSessionManager;
package/cjs/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./constants.js"), exports);
5
+ tslib_1.__exportStar(require("./decorators/inject-session-manager.decorators.js"), exports);
6
+ tslib_1.__exportStar(require("./interfaces/module-options.interface.js"), exports);
7
+ tslib_1.__exportStar(require("./redisess.module.js"), exports);
8
+ tslib_1.__exportStar(require("./utils/get-session-manager-token.util.js"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var RedisessCoreModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RedisessCoreModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const core_1 = require("@nestjs/core");
8
+ const crypto = tslib_1.__importStar(require("crypto"));
9
+ const redisess_1 = require("redisess");
10
+ const constants_js_1 = require("./constants.js");
11
+ const get_session_manager_token_util_js_1 = require("./utils/get-session-manager-token.util.js");
12
+ let RedisessCoreModule = RedisessCoreModule_1 = class RedisessCoreModule {
13
+ constructor(options, moduleRef) {
14
+ this.options = options;
15
+ this.moduleRef = moduleRef;
16
+ }
17
+ static forRoot(options) {
18
+ const optionsProvider = {
19
+ provide: constants_js_1.REDISESS_MODULE_OPTIONS,
20
+ useValue: options,
21
+ };
22
+ const connectionProvider = {
23
+ provide: (0, get_session_manager_token_util_js_1.getSessionManagerToken)(options.name),
24
+ useFactory: () => this.createSessionManager(options),
25
+ };
26
+ return {
27
+ module: RedisessCoreModule_1,
28
+ providers: [connectionProvider, optionsProvider],
29
+ exports: [connectionProvider],
30
+ };
31
+ }
32
+ static forRootAsync(asyncOptions) {
33
+ const connectionProvider = {
34
+ provide: (0, get_session_manager_token_util_js_1.getSessionManagerToken)(asyncOptions.name),
35
+ inject: [constants_js_1.REDISESS_MODULE_OPTIONS],
36
+ useFactory: async (oOptions) => {
37
+ const name = asyncOptions.name || oOptions.name;
38
+ return this.createSessionManager({
39
+ ...oOptions,
40
+ name,
41
+ });
42
+ },
43
+ };
44
+ const asyncProviders = this.createAsyncProviders(asyncOptions);
45
+ return {
46
+ module: RedisessCoreModule_1,
47
+ imports: asyncOptions.imports,
48
+ providers: [
49
+ ...asyncProviders,
50
+ connectionProvider,
51
+ {
52
+ provide: constants_js_1.REDISESS_MODULE_TOKEN,
53
+ useValue: crypto.randomUUID(),
54
+ },
55
+ ],
56
+ exports: [connectionProvider],
57
+ };
58
+ }
59
+ async onApplicationShutdown() {
60
+ const sessionManager = this.moduleRef.get((0, get_session_manager_token_util_js_1.getSessionManagerToken)(this.options.name));
61
+ if (sessionManager)
62
+ sessionManager.quit();
63
+ }
64
+ static createAsyncProviders(asyncOptions) {
65
+ if (asyncOptions.useExisting || asyncOptions.useFactory)
66
+ return [this.createAsyncOptionsProvider(asyncOptions)];
67
+ if (asyncOptions.useClass) {
68
+ return [
69
+ this.createAsyncOptionsProvider(asyncOptions),
70
+ {
71
+ provide: asyncOptions.useClass,
72
+ useClass: asyncOptions.useClass,
73
+ },
74
+ ];
75
+ }
76
+ throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
77
+ }
78
+ static createAsyncOptionsProvider(asyncOptions) {
79
+ if (asyncOptions.useFactory) {
80
+ return {
81
+ provide: constants_js_1.REDISESS_MODULE_OPTIONS,
82
+ useFactory: asyncOptions.useFactory,
83
+ inject: asyncOptions.inject || [],
84
+ };
85
+ }
86
+ const useClass = asyncOptions.useClass || asyncOptions.useExisting;
87
+ if (useClass) {
88
+ return {
89
+ provide: constants_js_1.REDISESS_MODULE_OPTIONS,
90
+ useFactory: (optionsFactory) => optionsFactory.createOptions(asyncOptions.name),
91
+ inject: [useClass],
92
+ };
93
+ }
94
+ throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
95
+ }
96
+ static async createSessionManager(options) {
97
+ const opts = { ...options };
98
+ delete opts.client;
99
+ delete opts.name;
100
+ return new redisess_1.SessionManager(options.client, opts);
101
+ }
102
+ };
103
+ exports.RedisessCoreModule = RedisessCoreModule;
104
+ exports.RedisessCoreModule = RedisessCoreModule = RedisessCoreModule_1 = tslib_1.__decorate([
105
+ (0, common_1.Global)(),
106
+ (0, common_1.Module)({}),
107
+ tslib_1.__param(0, (0, common_1.Inject)(constants_js_1.REDISESS_MODULE_OPTIONS)),
108
+ tslib_1.__metadata("design:paramtypes", [Object, core_1.ModuleRef])
109
+ ], RedisessCoreModule);
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var RedisessModule_1;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.RedisessModule = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const common_1 = require("@nestjs/common");
7
+ const redisess_core_module_js_1 = require("./redisess-core.module.js");
8
+ let RedisessModule = RedisessModule_1 = class RedisessModule {
9
+ static forRoot(options) {
10
+ return {
11
+ module: RedisessModule_1,
12
+ imports: [redisess_core_module_js_1.RedisessCoreModule.forRoot(options)],
13
+ };
14
+ }
15
+ static forRootAsync(options) {
16
+ return {
17
+ module: RedisessModule_1,
18
+ imports: [redisess_core_module_js_1.RedisessCoreModule.forRootAsync(options)],
19
+ };
20
+ }
21
+ };
22
+ exports.RedisessModule = RedisessModule;
23
+ exports.RedisessModule = RedisessModule = RedisessModule_1 = tslib_1.__decorate([
24
+ (0, common_1.Module)({})
25
+ ], RedisessModule);
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSessionManagerToken = getSessionManagerToken;
4
+ const redisess_1 = require("redisess");
5
+ function getSessionManagerToken(name) {
6
+ if (!name)
7
+ return redisess_1.SessionManager;
8
+ // noinspection SuspiciousTypeOfGuard
9
+ if (typeof name === 'symbol' || typeof name === 'function')
10
+ return name;
11
+ return `${name}_SessionManager`;
12
+ }
@@ -0,0 +1,2 @@
1
+ export const REDISESS_MODULE_OPTIONS = Symbol('REDISESS_MODULE_OPTIONS');
2
+ export const REDISESS_MODULE_TOKEN = Symbol('REDISESS_MODULE_ID');
@@ -0,0 +1,3 @@
1
+ import { Inject } from '@nestjs/common';
2
+ import { getSessionManagerToken } from '../utils/get-session-manager-token.util.js';
3
+ export const InjectSessionManager = (name) => Inject(getSessionManagerToken(name));
package/esm/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './constants.js';
2
+ export * from './decorators/inject-session-manager.decorators.js';
3
+ export * from './interfaces/module-options.interface.js';
4
+ export * from './redisess.module.js';
5
+ export * from './utils/get-session-manager-token.util.js';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,106 @@
1
+ var RedisessCoreModule_1;
2
+ import { __decorate, __metadata, __param } from "tslib";
3
+ import { Global, Inject, Module } from '@nestjs/common';
4
+ import { ModuleRef } from '@nestjs/core';
5
+ import * as crypto from 'crypto';
6
+ import { SessionManager } from 'redisess';
7
+ import { REDISESS_MODULE_OPTIONS, REDISESS_MODULE_TOKEN } from './constants.js';
8
+ import { getSessionManagerToken } from './utils/get-session-manager-token.util.js';
9
+ let RedisessCoreModule = RedisessCoreModule_1 = class RedisessCoreModule {
10
+ constructor(options, moduleRef) {
11
+ this.options = options;
12
+ this.moduleRef = moduleRef;
13
+ }
14
+ static forRoot(options) {
15
+ const optionsProvider = {
16
+ provide: REDISESS_MODULE_OPTIONS,
17
+ useValue: options,
18
+ };
19
+ const connectionProvider = {
20
+ provide: getSessionManagerToken(options.name),
21
+ useFactory: () => this.createSessionManager(options),
22
+ };
23
+ return {
24
+ module: RedisessCoreModule_1,
25
+ providers: [connectionProvider, optionsProvider],
26
+ exports: [connectionProvider],
27
+ };
28
+ }
29
+ static forRootAsync(asyncOptions) {
30
+ const connectionProvider = {
31
+ provide: getSessionManagerToken(asyncOptions.name),
32
+ inject: [REDISESS_MODULE_OPTIONS],
33
+ useFactory: async (oOptions) => {
34
+ const name = asyncOptions.name || oOptions.name;
35
+ return this.createSessionManager({
36
+ ...oOptions,
37
+ name,
38
+ });
39
+ },
40
+ };
41
+ const asyncProviders = this.createAsyncProviders(asyncOptions);
42
+ return {
43
+ module: RedisessCoreModule_1,
44
+ imports: asyncOptions.imports,
45
+ providers: [
46
+ ...asyncProviders,
47
+ connectionProvider,
48
+ {
49
+ provide: REDISESS_MODULE_TOKEN,
50
+ useValue: crypto.randomUUID(),
51
+ },
52
+ ],
53
+ exports: [connectionProvider],
54
+ };
55
+ }
56
+ async onApplicationShutdown() {
57
+ const sessionManager = this.moduleRef.get(getSessionManagerToken(this.options.name));
58
+ if (sessionManager)
59
+ sessionManager.quit();
60
+ }
61
+ static createAsyncProviders(asyncOptions) {
62
+ if (asyncOptions.useExisting || asyncOptions.useFactory)
63
+ return [this.createAsyncOptionsProvider(asyncOptions)];
64
+ if (asyncOptions.useClass) {
65
+ return [
66
+ this.createAsyncOptionsProvider(asyncOptions),
67
+ {
68
+ provide: asyncOptions.useClass,
69
+ useClass: asyncOptions.useClass,
70
+ },
71
+ ];
72
+ }
73
+ throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
74
+ }
75
+ static createAsyncOptionsProvider(asyncOptions) {
76
+ if (asyncOptions.useFactory) {
77
+ return {
78
+ provide: REDISESS_MODULE_OPTIONS,
79
+ useFactory: asyncOptions.useFactory,
80
+ inject: asyncOptions.inject || [],
81
+ };
82
+ }
83
+ const useClass = asyncOptions.useClass || asyncOptions.useExisting;
84
+ if (useClass) {
85
+ return {
86
+ provide: REDISESS_MODULE_OPTIONS,
87
+ useFactory: (optionsFactory) => optionsFactory.createOptions(asyncOptions.name),
88
+ inject: [useClass],
89
+ };
90
+ }
91
+ throw new Error('Invalid configuration. Must provide useFactory, useClass or useExisting');
92
+ }
93
+ static async createSessionManager(options) {
94
+ const opts = { ...options };
95
+ delete opts.client;
96
+ delete opts.name;
97
+ return new SessionManager(options.client, opts);
98
+ }
99
+ };
100
+ RedisessCoreModule = RedisessCoreModule_1 = __decorate([
101
+ Global(),
102
+ Module({}),
103
+ __param(0, Inject(REDISESS_MODULE_OPTIONS)),
104
+ __metadata("design:paramtypes", [Object, ModuleRef])
105
+ ], RedisessCoreModule);
106
+ export { RedisessCoreModule };
@@ -0,0 +1,22 @@
1
+ var RedisessModule_1;
2
+ import { __decorate } from "tslib";
3
+ import { Module } from '@nestjs/common';
4
+ import { RedisessCoreModule } from './redisess-core.module.js';
5
+ let RedisessModule = RedisessModule_1 = class RedisessModule {
6
+ static forRoot(options) {
7
+ return {
8
+ module: RedisessModule_1,
9
+ imports: [RedisessCoreModule.forRoot(options)],
10
+ };
11
+ }
12
+ static forRootAsync(options) {
13
+ return {
14
+ module: RedisessModule_1,
15
+ imports: [RedisessCoreModule.forRootAsync(options)],
16
+ };
17
+ }
18
+ };
19
+ RedisessModule = RedisessModule_1 = __decorate([
20
+ Module({})
21
+ ], RedisessModule);
22
+ export { RedisessModule };
@@ -0,0 +1,9 @@
1
+ import { SessionManager } from 'redisess';
2
+ export function getSessionManagerToken(name) {
3
+ if (!name)
4
+ return SessionManager;
5
+ // noinspection SuspiciousTypeOfGuard
6
+ if (typeof name === 'symbol' || typeof name === 'function')
7
+ return name;
8
+ return `${name}_SessionManager`;
9
+ }
package/package.json CHANGED
@@ -1,37 +1,18 @@
1
1
  {
2
2
  "name": "@xnestjs/redisess",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "NestJS extension library for redisess",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
- "scripts": {
8
- "compile": "tsc --noEmit",
9
- "prebuild": "npm run lint && npm run clean",
10
- "build": "npm run build:cjs && npm run build:esm",
11
- "build:cjs": "tsc -b tsconfig-build-cjs.json && cp ../../support/package.cjs.json ./build/cjs/package.json",
12
- "build:esm": "tsc -b tsconfig-build-esm.json && cp ../../support/package.esm.json ./build/esm/package.json",
13
- "postbuild": "cp README.md ../../LICENSE ./build && node ../../support/postbuild.cjs",
14
- "lint": "eslint . --max-warnings=0",
15
- "lint:fix": "eslint . --max-warnings=0 --fix",
16
- "format": "prettier . --write --log-level=warn",
17
- "check": "madge --circular src/**",
18
- "test": "jest",
19
- "cover": "jest --collect-coverage",
20
- "clean": "npm run clean:src && npm run clean:build && npm run clean:cover",
21
- "clean:src": "ts-cleanup -s src --all && ts-cleanup -s test --all",
22
- "clean:build": "rimraf build",
23
- "clean:cover": "rimraf coverage"
7
+ "dependencies": {
8
+ "tslib": "^2.8.1"
24
9
  },
25
10
  "peerDependencies": {
26
11
  "@nestjs/common": "^10.0.0 || ^11.0.0",
27
12
  "@nestjs/core": "^10.0.0 || ^11.0.0",
28
- "@xnestjs/ioredis": "^1.2.0",
29
13
  "ioredis": "^5.0.0",
30
14
  "redisess": "^2.0.0"
31
15
  },
32
- "devDependencies": {
33
- "@nestjs/testing": "^11.0.2"
34
- },
35
16
  "type": "module",
36
17
  "exports": {
37
18
  ".": {
@@ -0,0 +1,2 @@
1
+ export declare const REDISESS_MODULE_OPTIONS: unique symbol;
2
+ export declare const REDISESS_MODULE_TOKEN: unique symbol;
@@ -0,0 +1 @@
1
+ export declare const InjectSessionManager: (name?: string) => ParameterDecorator;
@@ -0,0 +1,5 @@
1
+ export * from './constants.js';
2
+ export * from './decorators/inject-session-manager.decorators.js';
3
+ export * from './interfaces/module-options.interface.js';
4
+ export * from './redisess.module.js';
5
+ export * from './utils/get-session-manager-token.util.js';
@@ -0,0 +1,5 @@
1
+ export * from './constants.js';
2
+ export * from './decorators/inject-session-manager.decorators.js';
3
+ export * from './interfaces/module-options.interface.js';
4
+ export * from './redisess.module.js';
5
+ export * from './utils/get-session-manager-token.util.js';
@@ -0,0 +1,21 @@
1
+ import type { Type } from '@nestjs/common';
2
+ import type { ModuleMetadata } from '@nestjs/common/interfaces';
3
+ import Redis, { Cluster } from 'ioredis';
4
+ import type { SessionManager } from 'redisess';
5
+ export interface RedisessModuleOptions extends SessionManager.Options {
6
+ /**
7
+ * Connection name
8
+ */
9
+ name?: string;
10
+ client: Redis | Cluster;
11
+ }
12
+ export interface RedisessModuleOptionsFactory {
13
+ createOptions(connectionName?: string): Promise<RedisessModuleOptions> | RedisessModuleOptions;
14
+ }
15
+ export interface RedisessModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
16
+ name?: string;
17
+ useExisting?: Type<RedisessModuleOptionsFactory>;
18
+ useClass?: Type<RedisessModuleOptionsFactory>;
19
+ useFactory?: (...args: any[]) => Promise<RedisessModuleOptions> | RedisessModuleOptions;
20
+ inject?: any[];
21
+ }
@@ -0,0 +1,14 @@
1
+ import { DynamicModule, OnApplicationShutdown } from '@nestjs/common';
2
+ import { ModuleRef } from '@nestjs/core';
3
+ import { RedisessModuleAsyncOptions, type RedisessModuleOptions } from './interfaces/module-options.interface.js';
4
+ export declare class RedisessCoreModule implements OnApplicationShutdown {
5
+ private readonly options;
6
+ private readonly moduleRef;
7
+ constructor(options: RedisessModuleOptions, moduleRef: ModuleRef);
8
+ static forRoot(options: RedisessModuleOptions): DynamicModule;
9
+ static forRootAsync(asyncOptions: RedisessModuleAsyncOptions): DynamicModule;
10
+ onApplicationShutdown(): Promise<void>;
11
+ private static createAsyncProviders;
12
+ private static createAsyncOptionsProvider;
13
+ private static createSessionManager;
14
+ }
@@ -0,0 +1,6 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import type { RedisessModuleAsyncOptions, RedisessModuleOptions } from './interfaces/module-options.interface.js';
3
+ export declare class RedisessModule {
4
+ static forRoot(options: RedisessModuleOptions): DynamicModule;
5
+ static forRootAsync(options: RedisessModuleAsyncOptions): DynamicModule;
6
+ }
@@ -0,0 +1,3 @@
1
+ import { Type } from '@nestjs/common';
2
+ import { SessionManager } from 'redisess';
3
+ export declare function getSessionManagerToken(name?: string | symbol | Type<SessionManager>): string | symbol | Type<SessionManager>;