@domain.js/main 1.0.0-alpha.2 → 1.0.0-alpha.3

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.
@@ -1,11 +1,11 @@
1
- import { Redis } from "ioredis";
1
+ import { Redis, RedisOptions } from "ioredis";
2
2
  import { LRUCache } from "lru-cache";
3
3
  export interface CnfDef {
4
4
  cache: {
5
5
  isMulti?: boolean;
6
6
  delSignalChannel?: string;
7
7
  } & LRUCache.Options<{}, {}, unknown>;
8
- redis?: any;
8
+ redis?: RedisOptions;
9
9
  }
10
10
  export interface DepsDef {
11
11
  IORedis: typeof Redis;
@@ -40,7 +40,7 @@ function Main(cnf, deps) {
40
40
  const needToBroad = Boolean(cnf.cache.isMulti);
41
41
  // 如果不是多节点分部署部署,则不需要处理
42
42
  // 开启多节点分布式部署后,要通过redis广播cache的del事件,依次来保持cache的有效性
43
- if (needToBroad) {
43
+ if (needToBroad && cnf.redis) {
44
44
  const pub = new IORedis(cnf.redis);
45
45
  const sub = new IORedis(cnf.redis);
46
46
  const { delSignalChannel = "LRU_DEL_SIGNAL_CHANNEL" } = cnf.cache;
package/dist/index.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import { Defaults } from "./defaults";
2
2
  import Deps = require("./deps/defines");
3
- import type { CnfDef as CacheCnfDef } from "./deps/cache";
3
+ export { Errors } from "./Errors";
4
4
  export { Main as Cfg } from "./cfg";
5
5
  export * as DM from "./dm";
6
- export { Errors } from "./Errors";
7
6
  export { Main as Http } from "./http";
8
7
  export * as utils from "./utils";
9
8
  export declare const basicErrors: Readonly<Record<"notFound" | "notAllowed" | "noAuth", import("./Errors").ErrorFn>>;
10
9
  type TDeps = typeof Deps;
10
+ export type Feature = keyof typeof Deps;
11
11
  /**
12
12
  * 获取模块配置类型
13
13
  */
14
- type ModuleConfig<T extends keyof TDeps> = T extends "cache" ? CacheCnfDef : TDeps[T]["Main"] extends (arg: infer R, ...args: any[]) => any ? R : {};
14
+ type ModuleConfig<T extends keyof TDeps> = Parameters<TDeps[T]["Main"]>[0];
15
15
  /**
16
16
  * 获取模块返回类型
17
17
  */
@@ -19,8 +19,8 @@ type ModuleReturn<T extends keyof TDeps> = ReturnType<TDeps[T]["Main"]>;
19
19
  /**
20
20
  * 合并多个模块的配置类型(可选)
21
21
  */
22
- type MergeConfigs<T extends readonly (keyof TDeps)[]> = {
23
- [K in T[number]]?: ModuleConfig<K>;
22
+ type Merge<T> = {
23
+ [k in keyof T]: T[k];
24
24
  };
25
25
  /**
26
26
  * 合并多个模块的返回类型
@@ -28,4 +28,4 @@ type MergeConfigs<T extends readonly (keyof TDeps)[]> = {
28
28
  type MergeReturns<T extends readonly (keyof TDeps)[]> = {
29
29
  [K in T[number]]: ModuleReturn<K>;
30
30
  };
31
- export declare function Main<T extends readonly (keyof TDeps)[]>(features: T): (cnf?: MergeConfigs<T>) => MergeReturns<T> & Defaults;
31
+ export declare function Main<T extends Feature[] | Readonly<Feature[]> | ReadonlyArray<Feature>>(features: T): (cnf?: Merge<ModuleConfig<T[number]>>) => MergeReturns<T> & Defaults;
package/dist/index.js CHANGED
@@ -36,17 +36,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.basicErrors = exports.utils = exports.Http = exports.Errors = exports.DM = exports.Cfg = void 0;
39
+ exports.basicErrors = exports.utils = exports.Http = exports.DM = exports.Cfg = exports.Errors = void 0;
40
40
  exports.Main = Main;
41
41
  const lodash_1 = __importDefault(require("lodash"));
42
42
  const defaults_1 = require("./defaults");
43
43
  const DM = __importStar(require("./dm"));
44
44
  const Deps = require("./deps/defines");
45
+ // 显式导入 cache 模块的类型定义
46
+ var Errors_1 = require("./Errors");
47
+ Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return Errors_1.Errors; } });
45
48
  var cfg_1 = require("./cfg");
46
49
  Object.defineProperty(exports, "Cfg", { enumerable: true, get: function () { return cfg_1.Main; } });
47
50
  exports.DM = __importStar(require("./dm"));
48
- var Errors_1 = require("./Errors");
49
- Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return Errors_1.Errors; } });
50
51
  var http_1 = require("./http");
51
52
  Object.defineProperty(exports, "Http", { enumerable: true, get: function () { return http_1.Main; } });
52
53
  exports.utils = __importStar(require("./utils"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.3",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {