-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(changeset): feat: add library template, add ioredis module
- Loading branch information
Showing
14 changed files
with
226 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@nailyjs/ioredis": patch | ||
"@nailyjs/cli": patch | ||
--- | ||
|
||
feat: add library template, add ioredis module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@nailyjs/ioredis", | ||
"type": "module", | ||
"version": "2.0.1", | ||
"description": "ioredis module for naily.js.", | ||
"author": "Naily Zero <[email protected]> (https://naily.cc)", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "tsup", | ||
"watch": "tsup -w", | ||
"prepublishOnly": "tsup" | ||
}, | ||
"dependencies": { | ||
"@nailyjs/config": "workspace:*", | ||
"@nailyjs/ioc": "workspace:*", | ||
"ioredis": "^5.4.1" | ||
}, | ||
"devDependencies": { | ||
"tsup": "^8.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const CustomIoRedis = '__naily_custom_ioredis__' | ||
export interface CustomIoRedis { | ||
configure(ioRedisOptions: Naily.Configuration.NailyUserConfig['ioRedis']): Naily.Configuration.NailyUserConfig['ioRedis'] | Promise<Naily.Configuration.NailyUserConfig['ioRedis']> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './configure-ioredis-protocol' | ||
export * from './ioredis.service' | ||
export * from './plugin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Value } from '@nailyjs/config' | ||
import { Autowired, ClassWrapper, Container, Optional, Service } from '@nailyjs/ioc' | ||
import Redis from 'ioredis' | ||
import { CustomIoRedis } from './configure-ioredis-protocol' | ||
|
||
@Service() | ||
export class IORedisFactoryService { | ||
constructor( | ||
@Value('naily.ioRedis') | ||
private readonly ioRedisOptions: Naily.Configuration.NailyUserConfig['ioRedis'], | ||
@Optional() | ||
@Autowired(CustomIoRedis) | ||
private readonly configureService: CustomIoRedis, | ||
) {} | ||
|
||
async setup(container: Container): Promise<void> { | ||
let ioRedisOptions = this.ioRedisOptions | ||
if (this.configureService && typeof this.configureService.configure === 'function') | ||
ioRedisOptions = await this.configureService.configure(ioRedisOptions) | ||
|
||
if (Array.isArray(ioRedisOptions)) { | ||
for (const ioRedisOption of ioRedisOptions) { | ||
const ioRedisInstance = new Redis(ioRedisOption) | ||
await ioRedisInstance.connect() | ||
container.createConstantWrapper(ioRedisOption.injectionToken, ioRedisInstance).save() | ||
} | ||
} | ||
else { | ||
const ioRedisInstance = new Redis(ioRedisOptions) | ||
await ioRedisInstance.connect() | ||
container.createConstantWrapper(Redis, ioRedisInstance).save() | ||
} | ||
} | ||
|
||
static getInstance(container: Container): IORedisFactoryService { | ||
const wrapper = container.getContainer().get(IORedisFactoryService) as ClassWrapper<IORedisFactoryService> | ||
if (wrapper && wrapper.wrapperType === 'class') return wrapper.getClassFactory().getOrCreateInstance() | ||
return container.createClassWrapper(IORedisFactoryService).getClassFactory().getOrCreateInstance() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Container, IocPlugin } from '@nailyjs/ioc' | ||
import { IORedisFactoryService } from './ioredis.service' | ||
|
||
class IoRedisPluginImpl implements IocPlugin { | ||
name: string = 'naily:ioredis-plugin' | ||
|
||
async beforeRun(container: Container): Promise<void> { | ||
await IORedisFactoryService.getInstance(container).setup(container) | ||
} | ||
} | ||
|
||
export function IoRedisPlugin(): IocPlugin { | ||
return new IoRedisPluginImpl() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { InjectionTokenable } from '@nailyjs/ioc' | ||
import { RedisOptions } from 'ioredis' | ||
|
||
declare global { | ||
namespace Naily { | ||
namespace Configuration { | ||
interface NailyUserConfig { | ||
ioRedis?: IoRedisOptions | InjectionTokenable<IoRedisOptions>[] | ||
} | ||
interface NailyUserIntelliSense { | ||
ioRedis?: IoRedisOptions | ||
} | ||
} | ||
} | ||
} | ||
|
||
export interface IoRedisOptions extends RedisOptions {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2022", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"module": "ES2022", | ||
"moduleResolution": "Bundler" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from 'tsup' | ||
|
||
export default defineConfig({ | ||
entry: { | ||
index: './src/index.ts', | ||
}, | ||
dts: true, | ||
sourcemap: true, | ||
clean: true, | ||
format: ['cjs', 'esm'], | ||
}) |
Oops, something went wrong.