-
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 global intelliSense helper interface, upda…
…te all packages and add cache module
- Loading branch information
Showing
18 changed files
with
215 additions
and
5 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,9 @@ | ||
--- | ||
"@nailyjs/typeorm": patch | ||
"@nailyjs/config": patch | ||
"@nailyjs/eslint": patch | ||
"@nailyjs/cache": patch | ||
"@nailyjs/ioc": patch | ||
--- | ||
|
||
feat: add global intelliSense helper interface, update all packages and add cache 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "@nailyjs/cache", | ||
"type": "module", | ||
"version": "2.0.1", | ||
"description": "Cache manager package 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:*", | ||
"cache-manager": "^6.1.2" | ||
}, | ||
"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,40 @@ | ||
import { Value } from '@nailyjs/config' | ||
import { Autowired, ClassWrapper, Container, Optional, Service } from '@nailyjs/ioc' | ||
import { createCache } from 'cache-manager' | ||
import { CustomCacheManager } from './configure-cache-protocol' | ||
|
||
export const CACHE_MANAGER = '__naily_cache_manager__' | ||
|
||
@Service() | ||
export class CacheFactoryService { | ||
constructor( | ||
@Value('naily.cacheManager') | ||
private cacheOptions: Naily.Configuration.NailyUserConfig['cacheManager'], | ||
@Optional() | ||
@Autowired(CustomCacheManager) | ||
private readonly configureService: CustomCacheManager, | ||
) {} | ||
|
||
async setup(container: Container): Promise<void> { | ||
let cacheOptions = this.cacheOptions | ||
if (this.configureService && typeof this.configureService.configure === 'function') | ||
cacheOptions = await this.configureService.configure(cacheOptions) | ||
|
||
if (Array.isArray(cacheOptions)) { | ||
for (const cacheOption of cacheOptions) { | ||
const cacheInstance = createCache(cacheOption) | ||
container.createConstantWrapper(cacheOption.injectionToken, cacheInstance).save() | ||
} | ||
} | ||
else { | ||
const cacheInstance = createCache() | ||
container.createConstantWrapper(CACHE_MANAGER, cacheInstance).save() | ||
} | ||
} | ||
|
||
static getInstance(container: Container): CacheFactoryService { | ||
const wrapper = container.getContainer().get(CacheFactoryService) as ClassWrapper<CacheFactoryService> | ||
if (wrapper && wrapper.wrapperType === 'class') return wrapper.getClassFactory().getOrCreateInstance() | ||
return container.createClassWrapper(CacheFactoryService).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,4 @@ | ||
export const CustomCacheManager = '__naily_custom_cache_manager__' | ||
export interface CustomCacheManager { | ||
configure(cacheManagerOptions: Naily.Configuration.NailyUserConfig['cache']): Naily.Configuration.NailyUserConfig['cache'] | Promise<Naily.Configuration.NailyUserConfig['cache']> | ||
} |
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 * from './cache.service' | ||
export * from './configure-cache-protocol' | ||
export * from './plugin' | ||
export * from './types' |
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 { CacheFactoryService } from './cache.service' | ||
|
||
class CachePluginImpl implements IocPlugin { | ||
name: string = 'naily:cache-manager-plugin' | ||
|
||
beforeRun(container: Container): void { | ||
CacheFactoryService.getInstance(container).setup(container) | ||
} | ||
} | ||
|
||
export function CachePlugin(): IocPlugin { | ||
return new CachePluginImpl() | ||
} |
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,24 @@ | ||
import { InjectionTokenable } from '@nailyjs/ioc' | ||
import { CreateCacheOptions } from 'cache-manager' | ||
|
||
declare global { | ||
namespace Naily { | ||
namespace Configuration { | ||
interface NailyUserConfig { | ||
/** | ||
* Cache manager options. | ||
* | ||
* @see https://github.com/jaredwray/cacheable | ||
* @see https://www.npmjs.com/package/cache-manager | ||
*/ | ||
cacheManager?: CacheManagerOptions | InjectionTokenable<CacheManagerOptions>[] | ||
} | ||
interface NailyUserIntelliSense { | ||
cacheManager?: CacheManagerOptions | ||
} | ||
} | ||
} | ||
} | ||
|
||
export interface CacheManagerOptions extends CreateCacheOptions { | ||
} |
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'], | ||
}) |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.