@nocobase/client-v2 2.0.0-alpha.20

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.
Files changed (70) hide show
  1. package/LICENSE.txt +172 -0
  2. package/lib/Application.d.ts +124 -0
  3. package/lib/Application.js +489 -0
  4. package/lib/MockApplication.d.ts +16 -0
  5. package/lib/MockApplication.js +96 -0
  6. package/lib/Plugin.d.ts +33 -0
  7. package/lib/Plugin.js +89 -0
  8. package/lib/PluginManager.d.ts +46 -0
  9. package/lib/PluginManager.js +114 -0
  10. package/lib/PluginSettingsManager.d.ts +67 -0
  11. package/lib/PluginSettingsManager.js +148 -0
  12. package/lib/RouterManager.d.ts +61 -0
  13. package/lib/RouterManager.js +198 -0
  14. package/lib/WebSocketClient.d.ts +45 -0
  15. package/lib/WebSocketClient.js +217 -0
  16. package/lib/components/BlankComponent.d.ts +12 -0
  17. package/lib/components/BlankComponent.js +48 -0
  18. package/lib/components/MainComponent.d.ts +10 -0
  19. package/lib/components/MainComponent.js +54 -0
  20. package/lib/components/RouterBridge.d.ts +13 -0
  21. package/lib/components/RouterBridge.js +66 -0
  22. package/lib/components/RouterContextCleaner.d.ts +12 -0
  23. package/lib/components/RouterContextCleaner.js +61 -0
  24. package/lib/components/index.d.ts +10 -0
  25. package/lib/components/index.js +32 -0
  26. package/lib/context.d.ts +11 -0
  27. package/lib/context.js +38 -0
  28. package/lib/hooks/index.d.ts +11 -0
  29. package/lib/hooks/index.js +34 -0
  30. package/lib/hooks/useApp.d.ts +10 -0
  31. package/lib/hooks/useApp.js +41 -0
  32. package/lib/hooks/usePlugin.d.ts +11 -0
  33. package/lib/hooks/usePlugin.js +42 -0
  34. package/lib/hooks/useRouter.d.ts +9 -0
  35. package/lib/hooks/useRouter.js +41 -0
  36. package/lib/index.d.ts +14 -0
  37. package/lib/index.js +40 -0
  38. package/lib/utils/index.d.ts +11 -0
  39. package/lib/utils/index.js +79 -0
  40. package/lib/utils/remotePlugins.d.ts +44 -0
  41. package/lib/utils/remotePlugins.js +131 -0
  42. package/lib/utils/requirejs.d.ts +18 -0
  43. package/lib/utils/requirejs.js +1361 -0
  44. package/lib/utils/types.d.ts +330 -0
  45. package/lib/utils/types.js +28 -0
  46. package/package.json +16 -0
  47. package/src/Application.tsx +539 -0
  48. package/src/MockApplication.tsx +53 -0
  49. package/src/Plugin.ts +78 -0
  50. package/src/PluginManager.ts +114 -0
  51. package/src/PluginSettingsManager.ts +182 -0
  52. package/src/RouterManager.tsx +239 -0
  53. package/src/WebSocketClient.ts +220 -0
  54. package/src/__tests__/app.test.tsx +141 -0
  55. package/src/components/BlankComponent.tsx +12 -0
  56. package/src/components/MainComponent.tsx +20 -0
  57. package/src/components/RouterBridge.tsx +38 -0
  58. package/src/components/RouterContextCleaner.tsx +26 -0
  59. package/src/components/index.ts +11 -0
  60. package/src/context.ts +14 -0
  61. package/src/hooks/index.ts +12 -0
  62. package/src/hooks/useApp.ts +16 -0
  63. package/src/hooks/usePlugin.ts +17 -0
  64. package/src/hooks/useRouter.ts +15 -0
  65. package/src/index.ts +15 -0
  66. package/src/utils/index.tsx +48 -0
  67. package/src/utils/remotePlugins.ts +140 -0
  68. package/src/utils/requirejs.ts +2164 -0
  69. package/src/utils/types.ts +375 -0
  70. package/tsconfig.json +7 -0
@@ -0,0 +1,489 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __typeError = (msg) => {
17
+ throw TypeError(msg);
18
+ };
19
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") {
26
+ for (let key of __getOwnPropNames(from))
27
+ if (!__hasOwnProp.call(to, key) && key !== except)
28
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
+ }
30
+ return to;
31
+ };
32
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33
+ // If the importer is in node compatibility mode or this is not an ESM
34
+ // file that has been converted to a CommonJS file using a Babel-
35
+ // compatible transform (i.e. "__esModule" has not been set), then set
36
+ // "default" to the CommonJS "module.exports" for node compatibility.
37
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
+ mod
39
+ ));
40
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
42
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
43
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
44
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
45
+ var Application_exports = {};
46
+ __export(Application_exports, {
47
+ Application: () => Application
48
+ });
49
+ module.exports = __toCommonJS(Application_exports);
50
+ var import_reactive = require("@formily/reactive");
51
+ var import_flow_engine = require("@nocobase/flow-engine");
52
+ var import_sdk = require("@nocobase/sdk");
53
+ var import_i18next = require("i18next");
54
+ var import_lodash = __toESM(require("lodash"));
55
+ var import_react = __toESM(require("react"));
56
+ var import_client = require("react-dom/client");
57
+ var import_react_i18next = require("react-i18next");
58
+ var import_react_router_dom = require("react-router-dom");
59
+ var import_PluginManager = require("./PluginManager");
60
+ var import_PluginSettingsManager = require("./PluginSettingsManager");
61
+ var import_RouterManager = require("./RouterManager");
62
+ var import_WebSocketClient = require("./WebSocketClient");
63
+ var import_components = require("./components");
64
+ var import_utils = require("./utils");
65
+ var import_requirejs = require("./utils/requirejs");
66
+ var _providers, _router;
67
+ const _Application = class _Application {
68
+ constructor(options = {}) {
69
+ this.options = options;
70
+ this.initRequireJs();
71
+ (0, import_reactive.define)(this, {
72
+ maintained: import_reactive.observable.ref,
73
+ maintaining: import_reactive.observable.ref,
74
+ error: import_reactive.observable.ref
75
+ });
76
+ this.devDynamicImport = options.devDynamicImport;
77
+ this.components = import_lodash.default.merge(this.components, options.components);
78
+ this.apiClient = new import_sdk.APIClient(options.apiClient);
79
+ this.i18n = options.i18n || (0, import_i18next.createInstance)();
80
+ this.router = new import_RouterManager.RouterManager(options.router, this);
81
+ this.pluginManager = new import_PluginManager.PluginManager(options.plugins, options.loadRemotePlugins, this);
82
+ this.flowEngine = new import_flow_engine.FlowEngine();
83
+ this.flowEngine.registerModels({ ApplicationModel });
84
+ this.model = this.flowEngine.createModel({
85
+ use: "ApplicationModel",
86
+ uid: "__app_model__"
87
+ });
88
+ this.context = this.flowEngine.context;
89
+ this.context.defineProperty("pluginManager", {
90
+ get: /* @__PURE__ */ __name(() => this.pluginManager, "get")
91
+ });
92
+ this.context.defineProperty("pluginSettingsRouter", {
93
+ get: /* @__PURE__ */ __name(() => this.pluginSettingsManager, "get")
94
+ });
95
+ this.addDefaultProviders();
96
+ this.addReactRouterComponents();
97
+ this.addProviders(options.providers || []);
98
+ this.ws = new import_WebSocketClient.WebSocketClient(options.ws);
99
+ this.ws.app = this;
100
+ this.pluginSettingsManager = new import_PluginSettingsManager.PluginSettingsManager(options.pluginSettings, this);
101
+ this.addRoutes();
102
+ this.name = this.options.name || (0, import_sdk.getSubAppName)(options.publicPath) || "main";
103
+ this.i18n.on("languageChanged", (lng) => {
104
+ this.apiClient.auth.locale = lng;
105
+ });
106
+ this.initListeners();
107
+ }
108
+ eventBus = new EventTarget();
109
+ providers = [];
110
+ router;
111
+ scopes = {};
112
+ i18n;
113
+ ws;
114
+ apiClient;
115
+ components = {
116
+ AppNotFound: /* @__PURE__ */ __name(() => /* @__PURE__ */ import_react.default.createElement("div", null, "Not Found"), "AppNotFound"),
117
+ AppError: /* @__PURE__ */ __name(() => {
118
+ var _a;
119
+ return /* @__PURE__ */ import_react.default.createElement("div", null, (_a = this.error) == null ? void 0 : _a.message);
120
+ }, "AppError"),
121
+ AppSpin: /* @__PURE__ */ __name(() => /* @__PURE__ */ import_react.default.createElement("div", null, "Loading"), "AppSpin"),
122
+ AppMaintaining: /* @__PURE__ */ __name(() => /* @__PURE__ */ import_react.default.createElement("div", null, "Maintaining"), "AppMaintaining"),
123
+ AppMaintainingDialog: /* @__PURE__ */ __name(() => /* @__PURE__ */ import_react.default.createElement("div", null, "Maintaining Dialog"), "AppMaintainingDialog")
124
+ };
125
+ pluginManager;
126
+ pluginSettingsManager;
127
+ devDynamicImport;
128
+ requirejs;
129
+ name;
130
+ favicon;
131
+ flowEngine;
132
+ context;
133
+ maintained = false;
134
+ maintaining = false;
135
+ error = null;
136
+ model;
137
+ wsAuthorized = false;
138
+ apps = {
139
+ Component: null
140
+ };
141
+ get pm() {
142
+ return this.pluginManager;
143
+ }
144
+ get disableAcl() {
145
+ return this.options.disableAcl;
146
+ }
147
+ get isWsAuthorized() {
148
+ return this.wsAuthorized;
149
+ }
150
+ updateFavicon(favicon) {
151
+ let faviconLinkElement = document.querySelector('link[rel="shortcut icon"]');
152
+ if (favicon) {
153
+ this.favicon = favicon;
154
+ }
155
+ if (!faviconLinkElement) {
156
+ faviconLinkElement = document.createElement("link");
157
+ faviconLinkElement.rel = "shortcut icon";
158
+ faviconLinkElement.href = this.favicon || "/favicon/favicon.ico";
159
+ document.head.appendChild(faviconLinkElement);
160
+ } else {
161
+ faviconLinkElement.href = this.favicon || "/favicon/favicon.ico";
162
+ }
163
+ }
164
+ setWsAuthorized(authorized) {
165
+ this.wsAuthorized = authorized;
166
+ }
167
+ initListeners() {
168
+ this.eventBus.addEventListener("auth:tokenChanged", (event) => {
169
+ this.setTokenInWebSocket(event.detail);
170
+ });
171
+ this.eventBus.addEventListener("maintaining:end", () => {
172
+ if (this.apiClient.auth.token) {
173
+ this.setTokenInWebSocket({
174
+ token: this.apiClient.auth.token,
175
+ authenticator: this.apiClient.auth.getAuthenticator()
176
+ });
177
+ }
178
+ });
179
+ }
180
+ setTokenInWebSocket(options) {
181
+ const { token, authenticator } = options;
182
+ if (this.maintaining) {
183
+ return;
184
+ }
185
+ this.ws.send(
186
+ JSON.stringify({
187
+ type: "auth:token",
188
+ payload: {
189
+ token,
190
+ authenticator
191
+ }
192
+ })
193
+ );
194
+ }
195
+ setMaintaining(maintaining) {
196
+ if (this.maintaining === maintaining) {
197
+ return;
198
+ }
199
+ this.maintaining = maintaining;
200
+ if (!maintaining) {
201
+ this.eventBus.dispatchEvent(new Event("maintaining:end"));
202
+ }
203
+ }
204
+ initRequireJs() {
205
+ if (typeof window === "undefined") {
206
+ return;
207
+ }
208
+ if (window["requirejs"]) {
209
+ this.requirejs = window["requirejs"];
210
+ return;
211
+ }
212
+ window["requirejs"] = this.requirejs = (0, import_requirejs.getRequireJs)();
213
+ window.define = this.requirejs.define;
214
+ }
215
+ addDefaultProviders() {
216
+ this.use(import_react_i18next.I18nextProvider, { i18n: this.i18n });
217
+ this.flowEngine.context.defineProperty("app", {
218
+ value: this
219
+ });
220
+ this.flowEngine.context.defineProperty("api", {
221
+ value: this.apiClient
222
+ });
223
+ this.flowEngine.context.defineProperty("i18n", {
224
+ value: this.i18n
225
+ });
226
+ this.flowEngine.context.defineProperty("router", {
227
+ get: /* @__PURE__ */ __name(() => this.router.router, "get"),
228
+ cache: false
229
+ });
230
+ this.flowEngine.context.defineProperty("documentTitle", {
231
+ get: /* @__PURE__ */ __name(() => document.title, "get")
232
+ });
233
+ this.flowEngine.context.defineProperty("route", {
234
+ get: /* @__PURE__ */ __name(() => {
235
+ }, "get"),
236
+ observable: true
237
+ });
238
+ this.flowEngine.context.defineProperty("location", {
239
+ get: /* @__PURE__ */ __name(() => location, "get"),
240
+ observable: true
241
+ });
242
+ this.use(import_flow_engine.FlowEngineProvider, { engine: this.flowEngine });
243
+ this.use(import_flow_engine.FlowEngineGlobalsContextProvider);
244
+ }
245
+ addReactRouterComponents() {
246
+ this.addComponents({
247
+ Link: import_react_router_dom.Link,
248
+ Navigate: import_react_router_dom.Navigate,
249
+ NavLink: import_react_router_dom.NavLink
250
+ });
251
+ }
252
+ addRoutes() {
253
+ this.router.add("not-found", {
254
+ path: "*",
255
+ Component: this.components["AppNotFound"]
256
+ });
257
+ }
258
+ getOptions() {
259
+ return this.options;
260
+ }
261
+ getName() {
262
+ return (0, import_sdk.getSubAppName)(this.getPublicPath()) || null;
263
+ }
264
+ getPublicPath() {
265
+ let publicPath = this.options.publicPath || "/";
266
+ if (!publicPath.endsWith("/")) {
267
+ publicPath += "/";
268
+ }
269
+ return publicPath;
270
+ }
271
+ getApiUrl(pathname = "") {
272
+ let baseURL = this.apiClient.axios["defaults"]["baseURL"];
273
+ if (!baseURL.startsWith("http://") && !baseURL.startsWith("https://")) {
274
+ const { protocol, host } = window.location;
275
+ baseURL = `${protocol}//${host}${baseURL}`;
276
+ }
277
+ return baseURL.replace(/\/$/g, "") + "/" + pathname.replace(/^\//g, "");
278
+ }
279
+ getRouteUrl(pathname) {
280
+ return this.getPublicPath() + pathname.replace(/^\//g, "");
281
+ }
282
+ getHref(pathname) {
283
+ const name = this.name;
284
+ if (name && name !== "main") {
285
+ return this.getPublicPath() + "apps/" + name + "/" + pathname.replace(/^\//g, "");
286
+ }
287
+ return this.getPublicPath() + pathname.replace(/^\//g, "");
288
+ }
289
+ /**
290
+ * @internal
291
+ */
292
+ getComposeProviders() {
293
+ const Providers = (0, import_utils.compose)(...this.providers)(import_components.BlankComponent);
294
+ Providers.displayName = "Providers";
295
+ return Providers;
296
+ }
297
+ use(component, props) {
298
+ return this.addProvider(component, props);
299
+ }
300
+ addProvider(component, props) {
301
+ return this.providers.push([component, props]);
302
+ }
303
+ addProviders(providers) {
304
+ providers.forEach((provider) => {
305
+ if (Array.isArray(provider)) {
306
+ this.addProvider(provider[0], provider[1]);
307
+ } else {
308
+ this.addProvider(provider);
309
+ }
310
+ });
311
+ }
312
+ async load() {
313
+ await this.loadWebSocket();
314
+ await this.pm.load();
315
+ await this.flowEngine.flowSettings.load();
316
+ this.updateFavicon();
317
+ }
318
+ async loadWebSocket() {
319
+ this.eventBus.addEventListener("ws:message:authorized", () => {
320
+ this.setWsAuthorized(true);
321
+ });
322
+ this.ws.on("message", (event) => {
323
+ var _a, _b, _c;
324
+ if (!event.data) {
325
+ return;
326
+ }
327
+ const data = JSON.parse(event.data);
328
+ if ((_a = data == null ? void 0 : data.payload) == null ? void 0 : _a.refresh) {
329
+ window.location.reload();
330
+ return;
331
+ }
332
+ if (data.type === "notification") {
333
+ this.context.notification[((_b = data.payload) == null ? void 0 : _b.type) || "info"]({ message: (_c = data.payload) == null ? void 0 : _c.message });
334
+ return;
335
+ }
336
+ if (this.error && data.payload.code === "APP_RUNNING") {
337
+ this.maintained = true;
338
+ this.setMaintaining(false);
339
+ this.error = null;
340
+ window.location.reload();
341
+ return;
342
+ }
343
+ const maintaining = data.type === "maintaining" && data.payload.code !== "APP_RUNNING";
344
+ console.log("ws:message", { maintaining, data });
345
+ if (maintaining) {
346
+ this.setMaintaining(true);
347
+ this.error = data.payload;
348
+ } else {
349
+ this.setMaintaining(false);
350
+ this.maintained = true;
351
+ this.error = null;
352
+ const type = data.type;
353
+ if (!type) {
354
+ return;
355
+ }
356
+ const eventName = `ws:message:${type}`;
357
+ this.eventBus.dispatchEvent(new CustomEvent(eventName, { detail: data.payload }));
358
+ }
359
+ });
360
+ this.ws.on("serverDown", () => {
361
+ this.maintaining = true;
362
+ this.maintained = false;
363
+ });
364
+ this.ws.on("open", () => {
365
+ const token = this.apiClient.auth.token;
366
+ if (token) {
367
+ this.setTokenInWebSocket({ token, authenticator: this.apiClient.auth.getAuthenticator() });
368
+ }
369
+ });
370
+ this.ws.connect();
371
+ }
372
+ getComponent(Component, isShowError = true) {
373
+ const showError = /* @__PURE__ */ __name((msg) => isShowError && console.error(msg), "showError");
374
+ if (!Component) {
375
+ showError(`getComponent called with ${Component}`);
376
+ return;
377
+ }
378
+ if (typeof Component === "function") return Component;
379
+ if (typeof Component === "string") {
380
+ const res = import_lodash.default.get(this.components, Component);
381
+ if (!res) {
382
+ showError(`Component ${Component} not found`);
383
+ return;
384
+ }
385
+ return res;
386
+ }
387
+ showError(`Component ${Component} should be a string or a React component`);
388
+ return;
389
+ }
390
+ renderComponent(Component, props, children) {
391
+ return import_react.default.createElement(this.getComponent(Component), props, children);
392
+ }
393
+ addComponent(component, name) {
394
+ const componentName = name || component.displayName || component.name;
395
+ if (!componentName) {
396
+ console.error("Component must have a displayName or pass name as second argument");
397
+ return;
398
+ }
399
+ import_lodash.default.set(this.components, componentName, component);
400
+ }
401
+ addComponents(components) {
402
+ Object.keys(components).forEach((name) => {
403
+ this.addComponent(components[name], name);
404
+ });
405
+ }
406
+ getRootComponent() {
407
+ const Root = /* @__PURE__ */ __name(() => /* @__PURE__ */ import_react.default.createElement(import_flow_engine.FlowEngineProvider, { engine: this.flowEngine }, /* @__PURE__ */ import_react.default.createElement(import_flow_engine.FlowModelRenderer, { fallback: this.renderComponent("AppSpin"), model: this.model })), "Root");
408
+ return Root;
409
+ }
410
+ mount(containerOrSelector) {
411
+ const container = (0, import_utils.normalizeContainer)(containerOrSelector);
412
+ if (!container) return;
413
+ const App = this.getRootComponent();
414
+ const root = (0, import_client.createRoot)(container);
415
+ root.render(/* @__PURE__ */ import_react.default.createElement(App, null));
416
+ return root;
417
+ }
418
+ };
419
+ __name(_Application, "Application");
420
+ let Application = _Application;
421
+ const _ApplicationModel = class _ApplicationModel extends import_flow_engine.FlowModel {
422
+ constructor() {
423
+ super(...arguments);
424
+ __privateAdd(this, _providers);
425
+ __privateAdd(this, _router);
426
+ }
427
+ get app() {
428
+ return this.context.app;
429
+ }
430
+ getProviders() {
431
+ __privateSet(this, _providers, this.app.getComposeProviders());
432
+ return __privateGet(this, _providers);
433
+ }
434
+ getRouter() {
435
+ __privateSet(this, _router, this.app.router.getRouterComponent());
436
+ return __privateGet(this, _router);
437
+ }
438
+ render() {
439
+ console.log("render", {
440
+ maintaining: this.app.maintaining,
441
+ maintained: this.app.maintained,
442
+ error: this.app.error
443
+ });
444
+ if (this.app.maintaining) {
445
+ return this.renderMaintaining();
446
+ }
447
+ if (this.app.error) {
448
+ return this.renderError();
449
+ }
450
+ return this.renderContent();
451
+ }
452
+ renderMaintaining() {
453
+ if (!this.app.maintained) {
454
+ return this.app.renderComponent("AppMaintaining");
455
+ }
456
+ return this.app.renderComponent("AppMaintainingDialog");
457
+ }
458
+ renderError() {
459
+ return this.app.renderComponent("AppError");
460
+ }
461
+ renderContent() {
462
+ const Router = this.getRouter();
463
+ const Providers = this.getProviders();
464
+ return /* @__PURE__ */ import_react.default.createElement(Router, { BaseLayout: Providers });
465
+ }
466
+ };
467
+ _providers = new WeakMap();
468
+ _router = new WeakMap();
469
+ __name(_ApplicationModel, "ApplicationModel");
470
+ let ApplicationModel = _ApplicationModel;
471
+ ApplicationModel.registerFlow({
472
+ key: "appFlow",
473
+ steps: {
474
+ init: {
475
+ async handler(ctx, params) {
476
+ try {
477
+ await ctx.app.load();
478
+ } catch (err) {
479
+ ctx.model.app.error = err;
480
+ console.error(err);
481
+ }
482
+ }
483
+ }
484
+ }
485
+ });
486
+ // Annotate the CommonJS export names for ESM import in node:
487
+ 0 && (module.exports = {
488
+ Application
489
+ });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import MockAdapter from 'axios-mock-adapter';
10
+ import { Application, type ApplicationOptions } from './Application';
11
+ declare class MockApplication extends Application {
12
+ apiMock: MockAdapter;
13
+ constructor(options?: ApplicationOptions);
14
+ }
15
+ export declare function createMockClient(options?: ApplicationOptions): MockApplication;
16
+ export {};
@@ -0,0 +1,96 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
17
+ var __export = (target, all) => {
18
+ for (var name in all)
19
+ __defProp(target, name, { get: all[name], enumerable: true });
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (let key of __getOwnPropNames(from))
24
+ if (!__hasOwnProp.call(to, key) && key !== except)
25
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
26
+ }
27
+ return to;
28
+ };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+ var MockApplication_exports = {};
39
+ __export(MockApplication_exports, {
40
+ createMockClient: () => createMockClient
41
+ });
42
+ module.exports = __toCommonJS(MockApplication_exports);
43
+ var import_axios_mock_adapter = __toESM(require("axios-mock-adapter"));
44
+ var import_Application = require("./Application");
45
+ var import_WebSocketClient = require("./WebSocketClient");
46
+ const _MockApplication = class _MockApplication extends import_Application.Application {
47
+ apiMock;
48
+ constructor(options = {}) {
49
+ super({
50
+ router: { type: "memory", initialEntries: ["/"] },
51
+ ...options
52
+ });
53
+ this.apiMock = new import_axios_mock_adapter.default(this.apiClient.axios);
54
+ this.ws = new MockWebSocketClient(options.ws || {});
55
+ }
56
+ };
57
+ __name(_MockApplication, "MockApplication");
58
+ let MockApplication = _MockApplication;
59
+ const _MockWebSocketClient = class _MockWebSocketClient extends import_WebSocketClient.WebSocketClient {
60
+ eventBus = new EventTarget();
61
+ constructor(options) {
62
+ super(options);
63
+ }
64
+ connect() {
65
+ }
66
+ close() {
67
+ }
68
+ send() {
69
+ }
70
+ on(type, listener, options) {
71
+ this.eventBus.addEventListener(
72
+ type,
73
+ (event) => listener({ data: JSON.stringify(event.detail) }),
74
+ options
75
+ );
76
+ }
77
+ emit(type, data) {
78
+ this.eventBus.dispatchEvent(new CustomEvent(type, { detail: data }));
79
+ }
80
+ off(type, listener, options) {
81
+ this.eventBus.removeEventListener(type, listener, options);
82
+ }
83
+ removeAllListeners() {
84
+ }
85
+ };
86
+ __name(_MockWebSocketClient, "MockWebSocketClient");
87
+ let MockWebSocketClient = _MockWebSocketClient;
88
+ function createMockClient(options) {
89
+ const app = new MockApplication(options);
90
+ return app;
91
+ }
92
+ __name(createMockClient, "createMockClient");
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ createMockClient
96
+ });
@@ -0,0 +1,33 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ import type { TFuncKey, TOptions } from 'i18next';
10
+ import type { Application } from './Application';
11
+ export declare class Plugin<T = any> {
12
+ options: T;
13
+ protected app: Application;
14
+ constructor(options: T, app: Application);
15
+ get pluginManager(): import("./PluginManager").PluginManager;
16
+ get context(): import("@nocobase/flow-engine").FlowEngineContext & {
17
+ pluginSettingsRouter: import("./PluginSettingsManager").PluginSettingsManager;
18
+ pluginManager: import("./PluginManager").PluginManager;
19
+ };
20
+ get flowEngine(): import("@nocobase/flow-engine").FlowEngine;
21
+ get engine(): import("@nocobase/flow-engine").FlowEngine;
22
+ get pm(): import("./PluginManager").PluginManager;
23
+ get router(): import("./RouterManager").RouterManager;
24
+ get pluginSettingsManager(): import("./PluginSettingsManager").PluginSettingsManager;
25
+ get pluginSettingsRouter(): import("./PluginSettingsManager").PluginSettingsManager;
26
+ get schemaInitializerManager(): any;
27
+ get schemaSettingsManager(): any;
28
+ get dataSourceManager(): any;
29
+ afterAdd(): Promise<void>;
30
+ beforeLoad(): Promise<void>;
31
+ load(): Promise<void>;
32
+ t(text: TFuncKey | TFuncKey[], options?: TOptions): import("i18next").TFunctionDetailedResult<object>;
33
+ }