@jayfong/x-server 2.51.1 → 2.52.1

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.
@@ -29,7 +29,8 @@ class CorsPlugin {
29
29
  });
30
30
  fastify.register(_cors.default, {
31
31
  origin: (origin, cb) => allowAll ? cb(null, true) : cb(null, origin ? check(origin) : true),
32
- maxAge: (0, _vtils.ms)(this.options.ttl, true)
32
+ maxAge: (0, _vtils.ms)(this.options.ttl, true),
33
+ ...(0, _vtils.omitStrict)(this.options, ['allow', 'ttl'])
33
34
  });
34
35
  }
35
36
  }
@@ -247,7 +247,7 @@ class CacheService {
247
247
  }
248
248
  if (this.options.memory) {
249
249
  this.memoryCache.forEach((_v, k) => {
250
- if (prefixes.some(prefix => k.startsWith(prefix))) {
250
+ if (prefixes.some(prefix => k.startsWith(Array.isArray(prefix) ? prefix.join('_') : String(prefix)))) {
251
251
  this.memoryCache.delete(k);
252
252
  }
253
253
  });
@@ -1,7 +1,8 @@
1
- import { BasePlugin } from './base';
1
+ import { FastifyCorsOptions } from '@fastify/cors';
2
2
  import { FastifyInstance } from 'fastify';
3
3
  import { MsValue } from 'vtils';
4
- export interface CorsPluginOptions {
4
+ import { BasePlugin } from './base';
5
+ export interface CorsPluginOptions extends FastifyCorsOptions {
5
6
  /**
6
7
  * 允许的来源,支持位于开头的 * 通配符
7
8
  */
@@ -1,5 +1,5 @@
1
1
  import FastifyCors from '@fastify/cors';
2
- import { memoize } from 'vtils';
2
+ import { memoize, omitStrict } from 'vtils';
3
3
  import { ms } from 'vtils';
4
4
  /**
5
5
  * CORS 支持插件
@@ -25,7 +25,8 @@ export class CorsPlugin {
25
25
  });
26
26
  fastify.register(FastifyCors, {
27
27
  origin: (origin, cb) => allowAll ? cb(null, true) : cb(null, origin ? check(origin) : true),
28
- maxAge: ms(this.options.ttl, true)
28
+ maxAge: ms(this.options.ttl, true),
29
+ ...omitStrict(this.options, ['allow', 'ttl'])
29
30
  });
30
31
  }
31
32
  }
@@ -18,11 +18,14 @@ type KeyPathForNumberValue<T extends Data> = {
18
18
  [K in keyof T]: T[K] extends (...args: infer X) => number ? IsEmptyArray<X> extends true ? K : [K, ...X] : never;
19
19
  }[keyof T];
20
20
  type Value<T extends Data, P extends KeyPath<T>> = ReturnType<T[P extends any[] ? P[0] : P]>;
21
+ type KeyPartialPath<T extends Data> = {
22
+ [K in keyof T]: T[K] extends (...args: infer X) => any ? IsEmptyArray<X> extends true ? K : [K, ...Partial<X>] : never;
23
+ }[keyof T];
21
24
  type CacheSetTTL<V> = MsValue | ((data: V, defaultTTL: MsValue) => MsValue);
22
25
  type CacheSetOptions<V> = CacheSetTTL<V> | {
23
26
  ttl?: CacheSetTTL<V>;
24
27
  };
25
- export declare class CacheService<TData extends Data = Data, TKey extends Key<TData> = any, TKeyPath extends KeyPath<TData> = any, TKeyPathForNumberValue extends KeyPathForNumberValue<TData> = any> implements BaseService {
28
+ export declare class CacheService<TData extends Data = Data, TKey extends Key<TData> = any, TKeyPath extends KeyPath<TData> = any, TKeyPathForNumberValue extends KeyPathForNumberValue<TData> = any, TKeyPartialPath extends KeyPartialPath<TData> = any> implements BaseService {
26
29
  options: CacheServiceOptions;
27
30
  serviceName: string;
28
31
  private prefix;
@@ -118,11 +121,11 @@ export declare class CacheService<TData extends Data = Data, TKey extends Key<TD
118
121
  /**
119
122
  * 清空指定前缀的缓存。
120
123
  */
121
- clear<K extends TKey>(...prefixes: K[]): Promise<number>;
124
+ clear(...prefixes: Array<TKey | TKeyPartialPath>): Promise<number>;
122
125
  /**
123
126
  * 派生出一个指定类型的缓存服务。
124
127
  */
125
- fork<TNextData extends Data>(options?: Partial<CacheServiceOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>>;
128
+ fork<TNextData extends Data>(options?: Partial<CacheServiceOptions>): CacheService<TNextData, Key<TNextData>, KeyPath<TNextData>, KeyPathForNumberValue<TNextData>, KeyPartialPath<TNextData>>;
126
129
  }
127
130
  declare module '../x' {
128
131
  interface X {
@@ -242,7 +242,7 @@ export class CacheService {
242
242
  }
243
243
  if (this.options.memory) {
244
244
  this.memoryCache.forEach((_v, k) => {
245
- if (prefixes.some(prefix => k.startsWith(prefix))) {
245
+ if (prefixes.some(prefix => k.startsWith(Array.isArray(prefix) ? prefix.join('_') : String(prefix)))) {
246
246
  this.memoryCache.delete(k);
247
247
  }
248
248
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.51.1",
3
+ "version": "2.52.1",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",