@tego/core 1.3.44
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 +201 -0
- package/lib/acl/available-action.d.ts +5 -0
- package/lib/acl/available-action.js +62 -0
- package/lib/acl/index.d.ts +2 -0
- package/lib/acl/index.js +49 -0
- package/lib/aes-encryptor.d.ts +11 -0
- package/lib/aes-encryptor.js +116 -0
- package/lib/app-command.d.ts +12 -0
- package/lib/app-command.js +76 -0
- package/lib/app-supervisor.d.ts +61 -0
- package/lib/app-supervisor.js +299 -0
- package/lib/application.d.ts +354 -0
- package/lib/application.js +878 -0
- package/lib/cache/index.d.ts +3 -0
- package/lib/cache/index.js +35 -0
- package/lib/commands/console.d.ts +3 -0
- package/lib/commands/console.js +48 -0
- package/lib/commands/create-migration.d.ts +3 -0
- package/lib/commands/create-migration.js +80 -0
- package/lib/commands/db-auth.d.ts +3 -0
- package/lib/commands/db-auth.js +28 -0
- package/lib/commands/db-clean.d.ts +3 -0
- package/lib/commands/db-clean.js +31 -0
- package/lib/commands/db-sync.d.ts +3 -0
- package/lib/commands/db-sync.js +40 -0
- package/lib/commands/destroy.d.ts +3 -0
- package/lib/commands/destroy.js +30 -0
- package/lib/commands/index.d.ts +2 -0
- package/lib/commands/index.js +71 -0
- package/lib/commands/install.d.ts +3 -0
- package/lib/commands/install.js +33 -0
- package/lib/commands/migrator.d.ts +3 -0
- package/lib/commands/migrator.js +31 -0
- package/lib/commands/pm.d.ts +3 -0
- package/lib/commands/pm.js +75 -0
- package/lib/commands/refresh.d.ts +3 -0
- package/lib/commands/refresh.js +31 -0
- package/lib/commands/restart.d.ts +3 -0
- package/lib/commands/restart.js +35 -0
- package/lib/commands/start.d.ts +3 -0
- package/lib/commands/start.js +74 -0
- package/lib/commands/stop.d.ts +3 -0
- package/lib/commands/stop.js +34 -0
- package/lib/commands/upgrade.d.ts +3 -0
- package/lib/commands/upgrade.js +29 -0
- package/lib/cron/cron-job-manager.d.ts +25 -0
- package/lib/cron/cron-job-manager.js +89 -0
- package/lib/environment.d.ts +10 -0
- package/lib/environment.js +73 -0
- package/lib/errors/application-not-install.d.ts +4 -0
- package/lib/errors/application-not-install.js +35 -0
- package/lib/errors/handler.d.ts +3 -0
- package/lib/errors/handler.js +41 -0
- package/lib/errors/plugin-command-error.d.ts +2 -0
- package/lib/errors/plugin-command-error.js +31 -0
- package/lib/errors/plugin-not-exist.d.ts +2 -0
- package/lib/errors/plugin-not-exist.js +31 -0
- package/lib/gateway/errors.d.ts +22 -0
- package/lib/gateway/errors.js +138 -0
- package/lib/gateway/gateway.d.ts +56 -0
- package/lib/gateway/gateway.js +408 -0
- package/lib/gateway/index.d.ts +2 -0
- package/lib/gateway/index.js +30 -0
- package/lib/gateway/ipc-socket-client.d.ts +17 -0
- package/lib/gateway/ipc-socket-client.js +99 -0
- package/lib/gateway/ipc-socket-server.d.ts +12 -0
- package/lib/gateway/ipc-socket-server.js +140 -0
- package/lib/gateway/types.d.ts +25 -0
- package/lib/gateway/types.js +15 -0
- package/lib/gateway/ws-server.d.ts +63 -0
- package/lib/gateway/ws-server.js +335 -0
- package/lib/helper.d.ts +11 -0
- package/lib/helper.js +193 -0
- package/lib/helpers/application-version.d.ts +10 -0
- package/lib/helpers/application-version.js +77 -0
- package/lib/helpers/multiple-instance-manager.d.ts +6 -0
- package/lib/helpers/multiple-instance-manager.js +40 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +57 -0
- package/lib/locale/index.d.ts +1 -0
- package/lib/locale/index.js +21 -0
- package/lib/locale/locale.d.ts +22 -0
- package/lib/locale/locale.js +166 -0
- package/lib/locale/resource.d.ts +1 -0
- package/lib/locale/resource.js +74 -0
- package/lib/main-data-source.d.ts +4 -0
- package/lib/main-data-source.js +45 -0
- package/lib/middlewares/data-template.d.ts +2 -0
- package/lib/middlewares/data-template.js +39 -0
- package/lib/middlewares/data-wrapping.d.ts +3 -0
- package/lib/middlewares/data-wrapping.js +90 -0
- package/lib/middlewares/db2resource.d.ts +6 -0
- package/lib/middlewares/db2resource.js +76 -0
- package/lib/middlewares/extract-client-ip.d.ts +2 -0
- package/lib/middlewares/extract-client-ip.js +37 -0
- package/lib/middlewares/i18n.d.ts +1 -0
- package/lib/middlewares/i18n.js +44 -0
- package/lib/middlewares/index.d.ts +3 -0
- package/lib/middlewares/index.js +32 -0
- package/lib/middlewares/parse-variables.d.ts +1 -0
- package/lib/middlewares/parse-variables.js +84 -0
- package/lib/migration.d.ts +12 -0
- package/lib/migration.js +47 -0
- package/lib/migrations/20230912193824-package-name-unique.d.ts +6 -0
- package/lib/migrations/20230912193824-package-name-unique.js +52 -0
- package/lib/migrations/20230912294620-update-pkg.d.ts +6 -0
- package/lib/migrations/20230912294620-update-pkg.js +58 -0
- package/lib/migrations/20240106082756-update-plugins.d.ts +6 -0
- package/lib/migrations/20240106082756-update-plugins.js +44 -0
- package/lib/migrations/20240705000001-remove-pkgs-approval.d.ts +6 -0
- package/lib/migrations/20240705000001-remove-pkgs-approval.js +47 -0
- package/lib/notice/index.d.ts +25 -0
- package/lib/notice/index.js +91 -0
- package/lib/plugin-manager/clientStaticUtils.d.ts +24 -0
- package/lib/plugin-manager/clientStaticUtils.js +156 -0
- package/lib/plugin-manager/constants.d.ts +7 -0
- package/lib/plugin-manager/constants.js +120 -0
- package/lib/plugin-manager/deps.d.ts +2 -0
- package/lib/plugin-manager/deps.js +68 -0
- package/lib/plugin-manager/index.d.ts +2 -0
- package/lib/plugin-manager/index.js +23 -0
- package/lib/plugin-manager/middleware.d.ts +2 -0
- package/lib/plugin-manager/middleware.js +36 -0
- package/lib/plugin-manager/options/collection.d.ts +2 -0
- package/lib/plugin-manager/options/collection.js +39 -0
- package/lib/plugin-manager/options/resource.d.ts +15 -0
- package/lib/plugin-manager/options/resource.js +185 -0
- package/lib/plugin-manager/plugin-manager-repository.d.ts +27 -0
- package/lib/plugin-manager/plugin-manager-repository.js +136 -0
- package/lib/plugin-manager/plugin-manager.d.ts +205 -0
- package/lib/plugin-manager/plugin-manager.js +1032 -0
- package/lib/plugin-manager/types.d.ts +15 -0
- package/lib/plugin-manager/types.js +15 -0
- package/lib/plugin-manager/utils.d.ts +101 -0
- package/lib/plugin-manager/utils.js +513 -0
- package/lib/plugin-manager/web-service.d.ts +6 -0
- package/lib/plugin-manager/web-service.js +116 -0
- package/lib/plugin.d.ts +125 -0
- package/lib/plugin.js +359 -0
- package/lib/pub-sub-manager/handler-manager.d.ts +28 -0
- package/lib/pub-sub-manager/handler-manager.js +149 -0
- package/lib/pub-sub-manager/index.d.ts +3 -0
- package/lib/pub-sub-manager/index.js +25 -0
- package/lib/pub-sub-manager/memory-pub-sub-adapter.d.ts +21 -0
- package/lib/pub-sub-manager/memory-pub-sub-adapter.js +82 -0
- package/lib/pub-sub-manager/pub-sub-manager.d.ts +19 -0
- package/lib/pub-sub-manager/pub-sub-manager.js +108 -0
- package/lib/pub-sub-manager/types.d.ts +20 -0
- package/lib/pub-sub-manager/types.js +15 -0
- package/lib/sync-message-manager.d.ts +16 -0
- package/lib/sync-message-manager.js +112 -0
- package/package.json +58 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
26
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
27
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
28
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
29
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
30
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
31
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
35
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
36
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
37
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
38
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
39
|
+
return __privateGet(this, extra);
|
|
40
|
+
}, set [name](x) {
|
|
41
|
+
return __privateSet(this, extra, x);
|
|
42
|
+
} }, name));
|
|
43
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
44
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
45
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
46
|
+
if (k) {
|
|
47
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
48
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
49
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
50
|
+
}
|
|
51
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
52
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
53
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
54
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
55
|
+
}
|
|
56
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
57
|
+
};
|
|
58
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
59
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
60
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
61
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
62
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
63
|
+
var web_service_exports = {};
|
|
64
|
+
__export(web_service_exports, {
|
|
65
|
+
WebControllerService: () => WebControllerService
|
|
66
|
+
});
|
|
67
|
+
module.exports = __toCommonJS(web_service_exports);
|
|
68
|
+
var import_di = require("@tachybase/di");
|
|
69
|
+
var _actions_dec, _app_dec, _WebControllerService_decorators, _init;
|
|
70
|
+
_WebControllerService_decorators = [(0, import_di.Service)()], _app_dec = [(0, import_di.App)()], _actions_dec = [(0, import_di.Inject)("actions")];
|
|
71
|
+
let _WebControllerService = class _WebControllerService {
|
|
72
|
+
constructor() {
|
|
73
|
+
this.app = __runInitializers(_init, 8, this), __runInitializers(_init, 11, this);
|
|
74
|
+
this.actions = __runInitializers(_init, 12, this), __runInitializers(_init, 15, this);
|
|
75
|
+
}
|
|
76
|
+
allow(name, actionName, acl) {
|
|
77
|
+
this.app.acl.allow(name, actionName, acl || "loggedIn");
|
|
78
|
+
}
|
|
79
|
+
async load() {
|
|
80
|
+
if (!import_di.Container.has("controller")) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const controllers = import_di.Container.getMany("controller");
|
|
84
|
+
controllers.forEach((instance) => {
|
|
85
|
+
const items = this.actions.get(instance.constructor);
|
|
86
|
+
const resourceItems = items.filter((item) => item.type === "resource");
|
|
87
|
+
if (resourceItems.length === 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const resource = {
|
|
91
|
+
name: resourceItems[0].resourceName,
|
|
92
|
+
actions: {}
|
|
93
|
+
};
|
|
94
|
+
const actionItems = items.filter((item) => item.type === "action");
|
|
95
|
+
this.app.logger.debug(`register resource [${resource.name}]`);
|
|
96
|
+
actionItems.forEach((item) => {
|
|
97
|
+
var _a;
|
|
98
|
+
resource.actions[item.actionName] = async (ctx, next) => await instance[item.method](ctx, next);
|
|
99
|
+
this.allow(resource.name, item.actionName, ((_a = item.options) == null ? void 0 : _a.acl) || "");
|
|
100
|
+
this.app.logger.debug(`register resource [${resource.name}] action [${item.actionName}]`);
|
|
101
|
+
});
|
|
102
|
+
this.app.resource(resource);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
_init = __decoratorStart(null);
|
|
107
|
+
__decorateElement(_init, 5, "app", _app_dec, _WebControllerService);
|
|
108
|
+
__decorateElement(_init, 5, "actions", _actions_dec, _WebControllerService);
|
|
109
|
+
_WebControllerService = __decorateElement(_init, 0, "WebControllerService", _WebControllerService_decorators, _WebControllerService);
|
|
110
|
+
__name(_WebControllerService, "WebControllerService");
|
|
111
|
+
__runInitializers(_init, 1, _WebControllerService);
|
|
112
|
+
let WebControllerService = _WebControllerService;
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
WebControllerService
|
|
116
|
+
});
|
package/lib/plugin.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Model, Transactionable } from '@tachybase/database';
|
|
2
|
+
import { LoggerOptions } from '@tachybase/logger';
|
|
3
|
+
import type { ParseKeys, TOptions } from 'i18next';
|
|
4
|
+
import { Application } from './application';
|
|
5
|
+
import { InstallOptions } from './plugin-manager';
|
|
6
|
+
import { PubSubManagerPublishOptions } from './pub-sub-manager';
|
|
7
|
+
export type { ParseKeys, TOptions } from 'i18next';
|
|
8
|
+
export interface PluginInterface {
|
|
9
|
+
beforeLoad?: () => void;
|
|
10
|
+
load(): any;
|
|
11
|
+
getName(): string;
|
|
12
|
+
}
|
|
13
|
+
export interface PluginOptions {
|
|
14
|
+
activate?: boolean;
|
|
15
|
+
displayName?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
version?: string;
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
install?: (this: Plugin) => void;
|
|
20
|
+
load?: (this: Plugin) => void;
|
|
21
|
+
plugin?: typeof Plugin;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}
|
|
24
|
+
export declare abstract class Plugin implements PluginInterface {
|
|
25
|
+
options: any;
|
|
26
|
+
app: Application;
|
|
27
|
+
features: (typeof Plugin)[];
|
|
28
|
+
featureInstances: Plugin[];
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated
|
|
31
|
+
*/
|
|
32
|
+
model: Model;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
state: any;
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
private _sourceDir;
|
|
41
|
+
constructor(app: Application, options?: any);
|
|
42
|
+
addFeature<T extends Plugin>(plugin: new (app: Application, options?: any) => T): void;
|
|
43
|
+
get log(): import("winston").Logger;
|
|
44
|
+
get noticeManager(): import("./notice").NoticeManager;
|
|
45
|
+
get name(): string;
|
|
46
|
+
get pm(): import("./plugin-manager").PluginManager;
|
|
47
|
+
get db(): import("@tachybase/database").default;
|
|
48
|
+
get enabled(): any;
|
|
49
|
+
set enabled(value: any);
|
|
50
|
+
get installed(): any;
|
|
51
|
+
set installed(value: any);
|
|
52
|
+
get isPreset(): any;
|
|
53
|
+
getName(): any;
|
|
54
|
+
createLogger(options: LoggerOptions): import("winston").Logger;
|
|
55
|
+
afterAdd(): void;
|
|
56
|
+
beforeLoad(): void;
|
|
57
|
+
load(): Promise<void>;
|
|
58
|
+
install(options?: InstallOptions): Promise<void>;
|
|
59
|
+
upgrade(): Promise<void>;
|
|
60
|
+
beforeEnable(): Promise<void>;
|
|
61
|
+
afterEnable(): Promise<void>;
|
|
62
|
+
beforeDisable(): Promise<void>;
|
|
63
|
+
afterDisable(): Promise<void>;
|
|
64
|
+
beforeRemove(): Promise<void>;
|
|
65
|
+
afterRemove(): Promise<void>;
|
|
66
|
+
handleSyncMessage(message: Readonly<any>): Promise<void>;
|
|
67
|
+
sendSyncMessage(message: any, options?: PubSubManagerPublishOptions & Transactionable): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated
|
|
70
|
+
*/
|
|
71
|
+
importCollections(collectionsPath: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
setOptions(options: any): void;
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
protected getSourceDir(): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
loadCommands(): Promise<void>;
|
|
84
|
+
loadCommandFromPath(basePath: string): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
loadMigrations(): Promise<{
|
|
89
|
+
beforeLoad: any[];
|
|
90
|
+
afterSync: any[];
|
|
91
|
+
afterLoad: any[];
|
|
92
|
+
}>;
|
|
93
|
+
loadMigrationsFromPath(basePath: string): Promise<{
|
|
94
|
+
beforeLoad: any[];
|
|
95
|
+
afterSync: any[];
|
|
96
|
+
afterLoad: any[];
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
loadCollections(): Promise<void>;
|
|
102
|
+
loadCollectionsFromPath(basePath: string): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated
|
|
105
|
+
*/
|
|
106
|
+
requiredPlugins(): any[];
|
|
107
|
+
t(text: ParseKeys | ParseKeys[], options?: TOptions): string;
|
|
108
|
+
/**
|
|
109
|
+
* @internal
|
|
110
|
+
* TODO 换一种判断,这类替换 NODE_MODULES_PATH 有点奇怪
|
|
111
|
+
*/
|
|
112
|
+
protected isDev(): Promise<boolean>;
|
|
113
|
+
/**
|
|
114
|
+
* @experimental
|
|
115
|
+
*/
|
|
116
|
+
toJSON(options?: any): Promise<any>;
|
|
117
|
+
}
|
|
118
|
+
export declare function InjectedPlugin<T extends Plugin>({ Services, Resources, Controllers, }: {
|
|
119
|
+
Services?: any[];
|
|
120
|
+
Resources?: any[];
|
|
121
|
+
Controllers?: any[];
|
|
122
|
+
}): (target: {
|
|
123
|
+
new (...args: any[]): T;
|
|
124
|
+
}, context: ClassDecoratorContext) => new (...args: any[]) => T;
|
|
125
|
+
export default Plugin;
|
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var plugin_exports = {};
|
|
30
|
+
__export(plugin_exports, {
|
|
31
|
+
InjectedPlugin: () => InjectedPlugin,
|
|
32
|
+
Plugin: () => Plugin,
|
|
33
|
+
default: () => plugin_default
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
36
|
+
var import_node_fs = __toESM(require("node:fs"));
|
|
37
|
+
var import_node_path = require("node:path");
|
|
38
|
+
var import_node_worker_threads = require("node:worker_threads");
|
|
39
|
+
var import_di = require("@tachybase/di");
|
|
40
|
+
var import_globals = __toESM(require("@tachybase/globals"));
|
|
41
|
+
var import_utils = require("@tachybase/utils");
|
|
42
|
+
var import_glob = require("glob");
|
|
43
|
+
var import_plugin_manager = require("./plugin-manager");
|
|
44
|
+
var import_utils2 = require("./plugin-manager/utils");
|
|
45
|
+
const _Plugin = class _Plugin {
|
|
46
|
+
constructor(app, options) {
|
|
47
|
+
/**
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
this.state = {};
|
|
51
|
+
this.app = app;
|
|
52
|
+
this.setOptions(options);
|
|
53
|
+
this.features = [];
|
|
54
|
+
this.featureInstances = [];
|
|
55
|
+
}
|
|
56
|
+
addFeature(plugin) {
|
|
57
|
+
this.features.push(plugin);
|
|
58
|
+
this.featureInstances.push(new plugin(this.app, this.options));
|
|
59
|
+
}
|
|
60
|
+
get log() {
|
|
61
|
+
return this.app.logger.child({
|
|
62
|
+
reqId: this.app.context.reqId,
|
|
63
|
+
module: this.name
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
get noticeManager() {
|
|
67
|
+
return this.app.noticeManager;
|
|
68
|
+
}
|
|
69
|
+
get name() {
|
|
70
|
+
return this.options.name;
|
|
71
|
+
}
|
|
72
|
+
get pm() {
|
|
73
|
+
return this.app.pm;
|
|
74
|
+
}
|
|
75
|
+
get db() {
|
|
76
|
+
return this.app.db;
|
|
77
|
+
}
|
|
78
|
+
get enabled() {
|
|
79
|
+
return this.options.enabled;
|
|
80
|
+
}
|
|
81
|
+
set enabled(value) {
|
|
82
|
+
this.options.enabled = value;
|
|
83
|
+
}
|
|
84
|
+
get installed() {
|
|
85
|
+
return this.options.installed;
|
|
86
|
+
}
|
|
87
|
+
set installed(value) {
|
|
88
|
+
this.options.installed = value;
|
|
89
|
+
}
|
|
90
|
+
get isPreset() {
|
|
91
|
+
return this.options.isPreset;
|
|
92
|
+
}
|
|
93
|
+
getName() {
|
|
94
|
+
return this.options.name;
|
|
95
|
+
}
|
|
96
|
+
createLogger(options) {
|
|
97
|
+
return this.app.createLogger(options);
|
|
98
|
+
}
|
|
99
|
+
afterAdd() {
|
|
100
|
+
}
|
|
101
|
+
beforeLoad() {
|
|
102
|
+
}
|
|
103
|
+
async load() {
|
|
104
|
+
}
|
|
105
|
+
async install(options) {
|
|
106
|
+
}
|
|
107
|
+
async upgrade() {
|
|
108
|
+
}
|
|
109
|
+
async beforeEnable() {
|
|
110
|
+
}
|
|
111
|
+
async afterEnable() {
|
|
112
|
+
}
|
|
113
|
+
async beforeDisable() {
|
|
114
|
+
}
|
|
115
|
+
async afterDisable() {
|
|
116
|
+
}
|
|
117
|
+
async beforeRemove() {
|
|
118
|
+
}
|
|
119
|
+
async afterRemove() {
|
|
120
|
+
}
|
|
121
|
+
async handleSyncMessage(message) {
|
|
122
|
+
}
|
|
123
|
+
async sendSyncMessage(message, options) {
|
|
124
|
+
if (!this.name) {
|
|
125
|
+
throw new Error(`plugin name invalid`);
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
await this.app.syncMessageManager.publish(this.name, message, options);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
this.app.logger.error(err);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* @deprecated
|
|
135
|
+
*/
|
|
136
|
+
async importCollections(collectionsPath) {
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
setOptions(options) {
|
|
142
|
+
this.options = options || {};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
async getSourceDir() {
|
|
148
|
+
if (this._sourceDir) {
|
|
149
|
+
return this._sourceDir;
|
|
150
|
+
}
|
|
151
|
+
if (await this.isDev()) {
|
|
152
|
+
return this._sourceDir = "src";
|
|
153
|
+
}
|
|
154
|
+
if ((0, import_node_path.basename)(__dirname) === "src") {
|
|
155
|
+
return this._sourceDir = "src";
|
|
156
|
+
}
|
|
157
|
+
if (!import_node_worker_threads.isMainThread) {
|
|
158
|
+
return "dist";
|
|
159
|
+
}
|
|
160
|
+
return this._sourceDir = this.isPreset ? "lib" : "dist";
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
async loadCommands() {
|
|
166
|
+
const pluginPaths = import_globals.default.getInstance().get("PLUGIN_PATHS");
|
|
167
|
+
for (const basePath of pluginPaths) {
|
|
168
|
+
await this.loadCommandFromPath(basePath);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async loadCommandFromPath(basePath) {
|
|
172
|
+
const extensions = ["js", "ts"];
|
|
173
|
+
const directory = (0, import_node_path.resolve)(basePath, this.options.packageName, await this.getSourceDir(), "server/commands");
|
|
174
|
+
const patten = `${directory}/*.{${extensions.join(",")}}`;
|
|
175
|
+
const files = (0, import_glob.globSync)(patten, {
|
|
176
|
+
ignore: ["**/*.d.ts"]
|
|
177
|
+
});
|
|
178
|
+
for (const file of files) {
|
|
179
|
+
let filename = (0, import_node_path.basename)(file);
|
|
180
|
+
filename = filename.substring(0, filename.lastIndexOf(".")) || filename;
|
|
181
|
+
const callback = await (0, import_utils.importModule)(file);
|
|
182
|
+
callback(this.app);
|
|
183
|
+
}
|
|
184
|
+
if (files.length) {
|
|
185
|
+
this.app.logger.debug(`load commands [${this.name}]`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @internal
|
|
190
|
+
*/
|
|
191
|
+
async loadMigrations() {
|
|
192
|
+
const result = { beforeLoad: [], afterSync: [], afterLoad: [] };
|
|
193
|
+
const pluginPaths = import_globals.default.getInstance().get("PLUGIN_PATHS");
|
|
194
|
+
for (const basePath of pluginPaths) {
|
|
195
|
+
const { beforeLoad, afterSync, afterLoad } = await this.loadMigrationsFromPath(basePath);
|
|
196
|
+
result.beforeLoad.push(...beforeLoad);
|
|
197
|
+
result.afterSync.push(...afterSync);
|
|
198
|
+
result.afterLoad.push(...afterLoad);
|
|
199
|
+
}
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
async loadMigrationsFromPath(basePath) {
|
|
203
|
+
this.app.logger.debug(`load plugin migrations [${this.name}]`);
|
|
204
|
+
if (!this.options.packageName) {
|
|
205
|
+
return { beforeLoad: [], afterSync: [], afterLoad: [] };
|
|
206
|
+
}
|
|
207
|
+
const directory = (0, import_node_path.resolve)(
|
|
208
|
+
basePath,
|
|
209
|
+
this.options.packageName,
|
|
210
|
+
await this.getSourceDir(),
|
|
211
|
+
"server/migrations"
|
|
212
|
+
).replace(/\\/g, "/");
|
|
213
|
+
return await this.app.loadMigrations({
|
|
214
|
+
directory,
|
|
215
|
+
namespace: this.options.packageName,
|
|
216
|
+
context: {
|
|
217
|
+
plugin: this
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
async loadCollections() {
|
|
225
|
+
const pluginPaths = import_globals.default.getInstance().get("PLUGIN_PATHS");
|
|
226
|
+
for (const basePath of pluginPaths) {
|
|
227
|
+
await this.loadCollectionsFromPath(basePath);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async loadCollectionsFromPath(basePath) {
|
|
231
|
+
if (!this.options.packageName) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const directory = (0, import_node_path.resolve)(basePath, this.options.packageName, await this.getSourceDir(), "server/collections");
|
|
235
|
+
if (await (0, import_utils.fsExists)(directory)) {
|
|
236
|
+
await this.db.import({
|
|
237
|
+
directory,
|
|
238
|
+
from: this.options.packageName
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @deprecated
|
|
244
|
+
*/
|
|
245
|
+
requiredPlugins() {
|
|
246
|
+
return [];
|
|
247
|
+
}
|
|
248
|
+
t(text, options = {}) {
|
|
249
|
+
return this.app.i18n.t(text, { ns: this.options["packageName"], ...options });
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @internal
|
|
253
|
+
* TODO 换一种判断,这类替换 NODE_MODULES_PATH 有点奇怪
|
|
254
|
+
*/
|
|
255
|
+
async isDev() {
|
|
256
|
+
if (!this.options.packageName) {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
const pluginPaths = [
|
|
260
|
+
...import_globals.default.getInstance().get("PLUGIN_PATHS"),
|
|
261
|
+
(0, import_node_path.resolve)(process.cwd(), "node_modules")
|
|
262
|
+
];
|
|
263
|
+
let path;
|
|
264
|
+
for (const basePath of pluginPaths) {
|
|
265
|
+
if (await (0, import_utils.fsExists)((0, import_node_path.resolve)(basePath, this.options.packageName))) {
|
|
266
|
+
path = (0, import_node_path.resolve)(basePath, this.options.packageName);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const file = await import_node_fs.default.promises.realpath(path);
|
|
271
|
+
if (file.startsWith((0, import_node_path.resolve)(process.cwd(), "packages"))) {
|
|
272
|
+
return !!process.env.IS_DEV_CMD;
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* @experimental
|
|
278
|
+
*/
|
|
279
|
+
async toJSON(options = {}) {
|
|
280
|
+
const { locale = "en-US" } = options;
|
|
281
|
+
const { name, packageName, packageJson } = this.options;
|
|
282
|
+
if (!packageName) {
|
|
283
|
+
return {
|
|
284
|
+
...this.options
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
const results = {
|
|
288
|
+
...this.options,
|
|
289
|
+
keywords: packageJson.keywords,
|
|
290
|
+
readmeUrl: (0, import_plugin_manager.getExposeReadmeUrl)(packageName, locale),
|
|
291
|
+
changelogUrl: (0, import_plugin_manager.getExposeChangelogUrl)(packageName),
|
|
292
|
+
displayName: packageJson[`displayName.${locale}`] || packageJson.displayName || name,
|
|
293
|
+
description: packageJson[`description.${locale}`] || packageJson.description,
|
|
294
|
+
homepage: packageJson[`homepage.${locale}`] || packageJson.homepage
|
|
295
|
+
};
|
|
296
|
+
if (!options.withOutOpenFile) {
|
|
297
|
+
const pluginPaths = import_globals.default.getInstance().get("PLUGIN_PATHS") || [process.env.NODE_MODULES_PATH, (0, import_node_path.resolve)(process.cwd(), "node_modules")].filter(Boolean);
|
|
298
|
+
let file;
|
|
299
|
+
for (const basePath of pluginPaths) {
|
|
300
|
+
const fullPath = (0, import_node_path.resolve)(basePath, packageName);
|
|
301
|
+
try {
|
|
302
|
+
file = await import_node_fs.default.promises.realpath(fullPath);
|
|
303
|
+
break;
|
|
304
|
+
} catch {
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (!file) {
|
|
308
|
+
throw new Error(`Cannot resolve real path for ${packageName} in any PLUGIN_PATHS`);
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
...results,
|
|
312
|
+
...await (0, import_utils2.checkAndGetCompatible)(packageName),
|
|
313
|
+
lastUpdated: (await import_node_fs.default.promises.stat(file)).ctime,
|
|
314
|
+
file,
|
|
315
|
+
updatable: file.startsWith(process.env.PLUGIN_STORAGE_PATH)
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
return results;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
__name(_Plugin, "Plugin");
|
|
322
|
+
let Plugin = _Plugin;
|
|
323
|
+
function InjectedPlugin({
|
|
324
|
+
Services = [],
|
|
325
|
+
Resources = [],
|
|
326
|
+
Controllers = []
|
|
327
|
+
}) {
|
|
328
|
+
return function(target, context) {
|
|
329
|
+
const originalLoad = target.prototype.load;
|
|
330
|
+
target.prototype.load = async function() {
|
|
331
|
+
var _a, _b, _c, _d;
|
|
332
|
+
const services = Services.map((i) => import_di.Container.get(i));
|
|
333
|
+
const resources = Resources.map((i) => import_di.Container.get(i));
|
|
334
|
+
await originalLoad.call(this);
|
|
335
|
+
for (const service of services) {
|
|
336
|
+
try {
|
|
337
|
+
await ((_a = service.load) == null ? void 0 : _a.call(service));
|
|
338
|
+
} catch (e) {
|
|
339
|
+
this.log.warn("load service error", { name: (_b = service.constructor) == null ? void 0 : _b.name, error: e });
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
for (const resource of resources) {
|
|
343
|
+
try {
|
|
344
|
+
await ((_c = resource.load) == null ? void 0 : _c.call(resource));
|
|
345
|
+
} catch (e) {
|
|
346
|
+
this.log.warn("load resource error", { name: (_d = resource.constructor) == null ? void 0 : _d.name, error: e });
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
return target;
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
__name(InjectedPlugin, "InjectedPlugin");
|
|
354
|
+
var plugin_default = Plugin;
|
|
355
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
356
|
+
0 && (module.exports = {
|
|
357
|
+
InjectedPlugin,
|
|
358
|
+
Plugin
|
|
359
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type PubSubManagerSubscribeOptions } from './types';
|
|
2
|
+
export declare class HandlerManager {
|
|
3
|
+
protected publisherId: string;
|
|
4
|
+
handlers: Map<any, any>;
|
|
5
|
+
uniqueMessageHandlers: Map<any, any>;
|
|
6
|
+
constructor(publisherId: string);
|
|
7
|
+
adapterType: string;
|
|
8
|
+
protected getMessageHash(message: any): Promise<string>;
|
|
9
|
+
protected verifyMessage({ onlySelf, skipSelf, publisherId }: {
|
|
10
|
+
onlySelf: any;
|
|
11
|
+
skipSelf: any;
|
|
12
|
+
publisherId: any;
|
|
13
|
+
}): boolean;
|
|
14
|
+
protected debounce(func: any, wait: number): any;
|
|
15
|
+
handleMessage({ channel, message, callback, debounce, callbackCaller, }: {
|
|
16
|
+
channel: string;
|
|
17
|
+
message: Readonly<any>;
|
|
18
|
+
callback: any;
|
|
19
|
+
debounce: number;
|
|
20
|
+
callbackCaller: any;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
wrapper(channel: any, callback: any, options: any): (wrappedMessage: any) => Promise<void>;
|
|
23
|
+
set(channel: string, callback: any, options: PubSubManagerSubscribeOptions): (wrappedMessage: any) => Promise<void>;
|
|
24
|
+
get(channel: string, callback: any): any;
|
|
25
|
+
delete(channel: string, callback: any): any;
|
|
26
|
+
reset(): void;
|
|
27
|
+
each(callback: any): Promise<void>;
|
|
28
|
+
}
|