@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.
Files changed (152) hide show
  1. package/LICENSE +201 -0
  2. package/lib/acl/available-action.d.ts +5 -0
  3. package/lib/acl/available-action.js +62 -0
  4. package/lib/acl/index.d.ts +2 -0
  5. package/lib/acl/index.js +49 -0
  6. package/lib/aes-encryptor.d.ts +11 -0
  7. package/lib/aes-encryptor.js +116 -0
  8. package/lib/app-command.d.ts +12 -0
  9. package/lib/app-command.js +76 -0
  10. package/lib/app-supervisor.d.ts +61 -0
  11. package/lib/app-supervisor.js +299 -0
  12. package/lib/application.d.ts +354 -0
  13. package/lib/application.js +878 -0
  14. package/lib/cache/index.d.ts +3 -0
  15. package/lib/cache/index.js +35 -0
  16. package/lib/commands/console.d.ts +3 -0
  17. package/lib/commands/console.js +48 -0
  18. package/lib/commands/create-migration.d.ts +3 -0
  19. package/lib/commands/create-migration.js +80 -0
  20. package/lib/commands/db-auth.d.ts +3 -0
  21. package/lib/commands/db-auth.js +28 -0
  22. package/lib/commands/db-clean.d.ts +3 -0
  23. package/lib/commands/db-clean.js +31 -0
  24. package/lib/commands/db-sync.d.ts +3 -0
  25. package/lib/commands/db-sync.js +40 -0
  26. package/lib/commands/destroy.d.ts +3 -0
  27. package/lib/commands/destroy.js +30 -0
  28. package/lib/commands/index.d.ts +2 -0
  29. package/lib/commands/index.js +71 -0
  30. package/lib/commands/install.d.ts +3 -0
  31. package/lib/commands/install.js +33 -0
  32. package/lib/commands/migrator.d.ts +3 -0
  33. package/lib/commands/migrator.js +31 -0
  34. package/lib/commands/pm.d.ts +3 -0
  35. package/lib/commands/pm.js +75 -0
  36. package/lib/commands/refresh.d.ts +3 -0
  37. package/lib/commands/refresh.js +31 -0
  38. package/lib/commands/restart.d.ts +3 -0
  39. package/lib/commands/restart.js +35 -0
  40. package/lib/commands/start.d.ts +3 -0
  41. package/lib/commands/start.js +74 -0
  42. package/lib/commands/stop.d.ts +3 -0
  43. package/lib/commands/stop.js +34 -0
  44. package/lib/commands/upgrade.d.ts +3 -0
  45. package/lib/commands/upgrade.js +29 -0
  46. package/lib/cron/cron-job-manager.d.ts +25 -0
  47. package/lib/cron/cron-job-manager.js +89 -0
  48. package/lib/environment.d.ts +10 -0
  49. package/lib/environment.js +73 -0
  50. package/lib/errors/application-not-install.d.ts +4 -0
  51. package/lib/errors/application-not-install.js +35 -0
  52. package/lib/errors/handler.d.ts +3 -0
  53. package/lib/errors/handler.js +41 -0
  54. package/lib/errors/plugin-command-error.d.ts +2 -0
  55. package/lib/errors/plugin-command-error.js +31 -0
  56. package/lib/errors/plugin-not-exist.d.ts +2 -0
  57. package/lib/errors/plugin-not-exist.js +31 -0
  58. package/lib/gateway/errors.d.ts +22 -0
  59. package/lib/gateway/errors.js +138 -0
  60. package/lib/gateway/gateway.d.ts +56 -0
  61. package/lib/gateway/gateway.js +408 -0
  62. package/lib/gateway/index.d.ts +2 -0
  63. package/lib/gateway/index.js +30 -0
  64. package/lib/gateway/ipc-socket-client.d.ts +17 -0
  65. package/lib/gateway/ipc-socket-client.js +99 -0
  66. package/lib/gateway/ipc-socket-server.d.ts +12 -0
  67. package/lib/gateway/ipc-socket-server.js +140 -0
  68. package/lib/gateway/types.d.ts +25 -0
  69. package/lib/gateway/types.js +15 -0
  70. package/lib/gateway/ws-server.d.ts +63 -0
  71. package/lib/gateway/ws-server.js +335 -0
  72. package/lib/helper.d.ts +11 -0
  73. package/lib/helper.js +193 -0
  74. package/lib/helpers/application-version.d.ts +10 -0
  75. package/lib/helpers/application-version.js +77 -0
  76. package/lib/helpers/multiple-instance-manager.d.ts +6 -0
  77. package/lib/helpers/multiple-instance-manager.js +40 -0
  78. package/lib/index.d.ts +10 -0
  79. package/lib/index.js +57 -0
  80. package/lib/locale/index.d.ts +1 -0
  81. package/lib/locale/index.js +21 -0
  82. package/lib/locale/locale.d.ts +22 -0
  83. package/lib/locale/locale.js +166 -0
  84. package/lib/locale/resource.d.ts +1 -0
  85. package/lib/locale/resource.js +74 -0
  86. package/lib/main-data-source.d.ts +4 -0
  87. package/lib/main-data-source.js +45 -0
  88. package/lib/middlewares/data-template.d.ts +2 -0
  89. package/lib/middlewares/data-template.js +39 -0
  90. package/lib/middlewares/data-wrapping.d.ts +3 -0
  91. package/lib/middlewares/data-wrapping.js +90 -0
  92. package/lib/middlewares/db2resource.d.ts +6 -0
  93. package/lib/middlewares/db2resource.js +76 -0
  94. package/lib/middlewares/extract-client-ip.d.ts +2 -0
  95. package/lib/middlewares/extract-client-ip.js +37 -0
  96. package/lib/middlewares/i18n.d.ts +1 -0
  97. package/lib/middlewares/i18n.js +44 -0
  98. package/lib/middlewares/index.d.ts +3 -0
  99. package/lib/middlewares/index.js +32 -0
  100. package/lib/middlewares/parse-variables.d.ts +1 -0
  101. package/lib/middlewares/parse-variables.js +84 -0
  102. package/lib/migration.d.ts +12 -0
  103. package/lib/migration.js +47 -0
  104. package/lib/migrations/20230912193824-package-name-unique.d.ts +6 -0
  105. package/lib/migrations/20230912193824-package-name-unique.js +52 -0
  106. package/lib/migrations/20230912294620-update-pkg.d.ts +6 -0
  107. package/lib/migrations/20230912294620-update-pkg.js +58 -0
  108. package/lib/migrations/20240106082756-update-plugins.d.ts +6 -0
  109. package/lib/migrations/20240106082756-update-plugins.js +44 -0
  110. package/lib/migrations/20240705000001-remove-pkgs-approval.d.ts +6 -0
  111. package/lib/migrations/20240705000001-remove-pkgs-approval.js +47 -0
  112. package/lib/notice/index.d.ts +25 -0
  113. package/lib/notice/index.js +91 -0
  114. package/lib/plugin-manager/clientStaticUtils.d.ts +24 -0
  115. package/lib/plugin-manager/clientStaticUtils.js +156 -0
  116. package/lib/plugin-manager/constants.d.ts +7 -0
  117. package/lib/plugin-manager/constants.js +120 -0
  118. package/lib/plugin-manager/deps.d.ts +2 -0
  119. package/lib/plugin-manager/deps.js +68 -0
  120. package/lib/plugin-manager/index.d.ts +2 -0
  121. package/lib/plugin-manager/index.js +23 -0
  122. package/lib/plugin-manager/middleware.d.ts +2 -0
  123. package/lib/plugin-manager/middleware.js +36 -0
  124. package/lib/plugin-manager/options/collection.d.ts +2 -0
  125. package/lib/plugin-manager/options/collection.js +39 -0
  126. package/lib/plugin-manager/options/resource.d.ts +15 -0
  127. package/lib/plugin-manager/options/resource.js +185 -0
  128. package/lib/plugin-manager/plugin-manager-repository.d.ts +27 -0
  129. package/lib/plugin-manager/plugin-manager-repository.js +136 -0
  130. package/lib/plugin-manager/plugin-manager.d.ts +205 -0
  131. package/lib/plugin-manager/plugin-manager.js +1032 -0
  132. package/lib/plugin-manager/types.d.ts +15 -0
  133. package/lib/plugin-manager/types.js +15 -0
  134. package/lib/plugin-manager/utils.d.ts +101 -0
  135. package/lib/plugin-manager/utils.js +513 -0
  136. package/lib/plugin-manager/web-service.d.ts +6 -0
  137. package/lib/plugin-manager/web-service.js +116 -0
  138. package/lib/plugin.d.ts +125 -0
  139. package/lib/plugin.js +359 -0
  140. package/lib/pub-sub-manager/handler-manager.d.ts +28 -0
  141. package/lib/pub-sub-manager/handler-manager.js +149 -0
  142. package/lib/pub-sub-manager/index.d.ts +3 -0
  143. package/lib/pub-sub-manager/index.js +25 -0
  144. package/lib/pub-sub-manager/memory-pub-sub-adapter.d.ts +21 -0
  145. package/lib/pub-sub-manager/memory-pub-sub-adapter.js +82 -0
  146. package/lib/pub-sub-manager/pub-sub-manager.d.ts +19 -0
  147. package/lib/pub-sub-manager/pub-sub-manager.js +108 -0
  148. package/lib/pub-sub-manager/types.d.ts +20 -0
  149. package/lib/pub-sub-manager/types.js +15 -0
  150. package/lib/sync-message-manager.d.ts +16 -0
  151. package/lib/sync-message-manager.js +112 -0
  152. package/package.json +58 -0
@@ -0,0 +1,74 @@
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 resource_exports = {};
30
+ __export(resource_exports, {
31
+ getResource: () => getResource
32
+ });
33
+ module.exports = __toCommonJS(resource_exports);
34
+ var import_utils = require("@tachybase/utils");
35
+ const arr2obj = /* @__PURE__ */ __name((items) => {
36
+ const obj = {};
37
+ for (const item of items) {
38
+ Object.assign(obj, item);
39
+ }
40
+ return obj;
41
+ }, "arr2obj");
42
+ const getResource = /* @__PURE__ */ __name((packageName, lang, isPlugin = true) => {
43
+ const resources = [];
44
+ const prefixes = [isPlugin ? "dist" : "lib"];
45
+ if (process.env.APP_ENV !== "production") {
46
+ try {
47
+ require.resolve("@tachybase/client/src");
48
+ if (packageName === "@tachybase/module-web") {
49
+ packageName = "@tachybase/client";
50
+ }
51
+ } catch (error) {
52
+ }
53
+ prefixes.unshift("src");
54
+ }
55
+ for (const prefix of prefixes) {
56
+ try {
57
+ let file = `${packageName}/${prefix}/locale/${lang}`;
58
+ const resource = (0, import_utils.requireModule)(file);
59
+ resources.push(resource);
60
+ } catch (error) {
61
+ }
62
+ if (resources.length) {
63
+ break;
64
+ }
65
+ }
66
+ if (resources.length === 0 && lang.replace("-", "_") !== lang) {
67
+ return getResource(packageName, lang.replace("-", "_"));
68
+ }
69
+ return arr2obj(resources);
70
+ }, "getResource");
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ getResource
74
+ });
@@ -0,0 +1,4 @@
1
+ import { DataSourceOptions, SequelizeDataSource } from '@tachybase/data-source';
2
+ export declare class MainDataSource extends SequelizeDataSource {
3
+ init(options?: DataSourceOptions): void;
4
+ }
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var main_data_source_exports = {};
20
+ __export(main_data_source_exports, {
21
+ MainDataSource: () => MainDataSource
22
+ });
23
+ module.exports = __toCommonJS(main_data_source_exports);
24
+ var import_data_source = require("@tachybase/data-source");
25
+ const _MainDataSource = class _MainDataSource extends import_data_source.SequelizeDataSource {
26
+ init(options = {}) {
27
+ const { acl, resourceManager, database } = options;
28
+ this.acl = acl;
29
+ this.resourceManager = resourceManager;
30
+ this.collectionManager = this.createCollectionManager({
31
+ collectionManager: {
32
+ database,
33
+ collectionsFilter: /* @__PURE__ */ __name((collection) => {
34
+ return collection.options.loadedFromCollectionManager;
35
+ }, "collectionsFilter")
36
+ }
37
+ });
38
+ }
39
+ };
40
+ __name(_MainDataSource, "MainDataSource");
41
+ let MainDataSource = _MainDataSource;
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ MainDataSource
45
+ });
@@ -0,0 +1,2 @@
1
+ import { Context } from '@tachybase/actions';
2
+ export declare const dataTemplate: (ctx: Context, next: any) => Promise<void>;
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var data_template_exports = {};
20
+ __export(data_template_exports, {
21
+ dataTemplate: () => dataTemplate
22
+ });
23
+ module.exports = __toCommonJS(data_template_exports);
24
+ var import_database = require("@tachybase/database");
25
+ const dataTemplate = /* @__PURE__ */ __name(async (ctx, next) => {
26
+ const { resourceName, actionName } = ctx.action;
27
+ const { isTemplate, fields } = ctx.action.params;
28
+ await next();
29
+ if (isTemplate && actionName === "get" && fields.length > 0) {
30
+ ctx.body = (0, import_database.traverseJSON)(JSON.parse(JSON.stringify(ctx.body)), {
31
+ collection: ctx.db.getCollection(resourceName),
32
+ include: fields
33
+ });
34
+ }
35
+ }, "dataTemplate");
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ dataTemplate
39
+ });
@@ -0,0 +1,3 @@
1
+ import { Context, Next } from '@tachybase/actions';
2
+ export declare function dataWrapping(): (ctx: Context, next: Next) => Promise<void>;
3
+ export default dataWrapping;
@@ -0,0 +1,90 @@
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 data_wrapping_exports = {};
30
+ __export(data_wrapping_exports, {
31
+ dataWrapping: () => dataWrapping,
32
+ default: () => data_wrapping_default
33
+ });
34
+ module.exports = __toCommonJS(data_wrapping_exports);
35
+ var import_node_stream = __toESM(require("node:stream"));
36
+ function dataWrapping() {
37
+ return /* @__PURE__ */ __name(async function dataWrapping2(ctx, next) {
38
+ var _a, _b;
39
+ await next();
40
+ if (ctx.withoutDataWrapping) {
41
+ return;
42
+ }
43
+ if (ctx.body instanceof import_node_stream.default.Readable) {
44
+ return;
45
+ }
46
+ if (ctx.body instanceof Buffer) {
47
+ return;
48
+ }
49
+ if (!ctx.body) {
50
+ if (((_a = ctx.action) == null ? void 0 : _a.actionName) === "get") {
51
+ ctx.status = 200;
52
+ }
53
+ }
54
+ if (Array.isArray(ctx.body)) {
55
+ ctx.body = {
56
+ data: ctx.body
57
+ };
58
+ } else {
59
+ if (ctx.body) {
60
+ const { rows, ...meta } = ctx.body;
61
+ if (rows) {
62
+ ctx.body = {
63
+ data: rows,
64
+ meta
65
+ };
66
+ } else {
67
+ ctx.body = {
68
+ data: ctx.body
69
+ };
70
+ if (ctx.bodyMeta) {
71
+ ctx.body.meta = ctx.bodyMeta;
72
+ }
73
+ }
74
+ } else if (ctx.action) {
75
+ ctx.body = {
76
+ data: ctx.body
77
+ };
78
+ }
79
+ }
80
+ if (ctx.body && ((_b = ctx.state.messages) == null ? void 0 : _b.length)) {
81
+ ctx.body.messages = ctx.state.messages;
82
+ }
83
+ }, "dataWrapping");
84
+ }
85
+ __name(dataWrapping, "dataWrapping");
86
+ var data_wrapping_default = dataWrapping;
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ dataWrapping
90
+ });
@@ -0,0 +1,6 @@
1
+ import Database from '@tachybase/database';
2
+ import { ResourcerContext } from '@tachybase/resourcer';
3
+ export declare function db2resource(ctx: ResourcerContext & {
4
+ db: Database;
5
+ }, next: () => Promise<any>): Promise<any>;
6
+ export default db2resource;
@@ -0,0 +1,76 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var db2resource_exports = {};
20
+ __export(db2resource_exports, {
21
+ db2resource: () => db2resource,
22
+ default: () => db2resource_default
23
+ });
24
+ module.exports = __toCommonJS(db2resource_exports);
25
+ var import_resourcer = require("@tachybase/resourcer");
26
+ async function db2resource(ctx, next) {
27
+ const dataSource = ctx.get("x-data-source");
28
+ if (dataSource) {
29
+ return next();
30
+ }
31
+ const resourcer = ctx.resourcer;
32
+ const database = ctx.db;
33
+ const params = (0, import_resourcer.parseRequest)(
34
+ {
35
+ path: ctx.request.path,
36
+ method: ctx.request.method
37
+ },
38
+ {
39
+ prefix: resourcer.options.prefix,
40
+ accessors: resourcer.options.accessors
41
+ }
42
+ );
43
+ if (!params) {
44
+ return next();
45
+ }
46
+ const resourceName = (0, import_resourcer.getNameByParams)(params);
47
+ if (resourcer.isDefined(resourceName)) {
48
+ return next();
49
+ }
50
+ const splitResult = resourceName.split(".");
51
+ let collectionName = splitResult[0];
52
+ const fieldName = splitResult[1];
53
+ if (collectionName.includes("@")) {
54
+ collectionName = collectionName.split("@")[1];
55
+ }
56
+ if (!database.hasCollection(collectionName)) {
57
+ return next();
58
+ }
59
+ const collection = database.getCollection(collectionName);
60
+ let resourceType = "single";
61
+ if (fieldName && collection.hasField(fieldName)) {
62
+ const field = collection.getField(fieldName);
63
+ resourceType = field.type;
64
+ }
65
+ resourcer.define({
66
+ type: resourceType,
67
+ name: resourceName
68
+ });
69
+ return next();
70
+ }
71
+ __name(db2resource, "db2resource");
72
+ var db2resource_default = db2resource;
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ db2resource
76
+ });
@@ -0,0 +1,2 @@
1
+ import { Context, Next } from '@tachybase/actions';
2
+ export declare function extractClientIp(): (ctx: Context, next: Next) => Promise<void>;
@@ -0,0 +1,37 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var extract_client_ip_exports = {};
20
+ __export(extract_client_ip_exports, {
21
+ extractClientIp: () => extractClientIp
22
+ });
23
+ module.exports = __toCommonJS(extract_client_ip_exports);
24
+ function extractClientIp() {
25
+ return /* @__PURE__ */ __name(async function extractClientIp2(ctx, next) {
26
+ const forwardedFor = ctx.get("X-Forwarded-For");
27
+ const ipArray = forwardedFor ? forwardedFor.split(",") : [];
28
+ const clientIp = ipArray.length > 0 ? ipArray[0].trim() : ctx.request.ip;
29
+ ctx.state.clientIp = clientIp;
30
+ await next();
31
+ }, "extractClientIp");
32
+ }
33
+ __name(extractClientIp, "extractClientIp");
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ extractClientIp
37
+ });
@@ -0,0 +1 @@
1
+ export declare function i18n(ctx: any, next: any): Promise<void>;
@@ -0,0 +1,44 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var i18n_exports = {};
20
+ __export(i18n_exports, {
21
+ i18n: () => i18n
22
+ });
23
+ module.exports = __toCommonJS(i18n_exports);
24
+ async function i18n(ctx, next) {
25
+ ctx.getCurrentLocale = () => {
26
+ const lng2 = ctx.get("X-Locale") || ctx.request.query.locale || ctx.app.i18n.language || ctx.acceptsLanguages().shift() || "en-US";
27
+ return lng2;
28
+ };
29
+ const lng = ctx.getCurrentLocale();
30
+ const localeManager = ctx.app.localeManager;
31
+ const i18n2 = await localeManager.getI18nInstance(lng);
32
+ ctx.i18n = i18n2;
33
+ ctx.t = i18n2.t.bind(i18n2);
34
+ if (lng !== "*" && lng) {
35
+ i18n2.changeLanguage(lng);
36
+ await localeManager.loadResourcesByLang(lng);
37
+ }
38
+ await next();
39
+ }
40
+ __name(i18n, "i18n");
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ i18n
44
+ });
@@ -0,0 +1,3 @@
1
+ export * from './data-wrapping';
2
+ export * from './db2resource';
3
+ export { parseVariables } from './parse-variables';
@@ -0,0 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var middlewares_exports = {};
20
+ __export(middlewares_exports, {
21
+ parseVariables: () => import_parse_variables.parseVariables
22
+ });
23
+ module.exports = __toCommonJS(middlewares_exports);
24
+ __reExport(middlewares_exports, require("./data-wrapping"), module.exports);
25
+ __reExport(middlewares_exports, require("./db2resource"), module.exports);
26
+ var import_parse_variables = require("./parse-variables");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ parseVariables,
30
+ ...require("./data-wrapping"),
31
+ ...require("./db2resource")
32
+ });
@@ -0,0 +1 @@
1
+ export declare const parseVariables: (ctx: any, next: any) => Promise<any>;
@@ -0,0 +1,84 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var parse_variables_exports = {};
20
+ __export(parse_variables_exports, {
21
+ parseVariables: () => parseVariables
22
+ });
23
+ module.exports = __toCommonJS(parse_variables_exports);
24
+ var import_utils = require("@tachybase/utils");
25
+ function getUser(ctx) {
26
+ return async ({ fields }) => {
27
+ var _a, _b;
28
+ const userFields = fields.filter((f) => f && ctx.db.getFieldByPath("users." + f));
29
+ (_a = ctx.logger) == null ? void 0 : _a.info("filter-parse: ", { userFields });
30
+ if (!ctx.state.currentUser) {
31
+ return;
32
+ }
33
+ if (!userFields.length) {
34
+ return;
35
+ }
36
+ const user = await ctx.db.getRepository("users").findOne({
37
+ filterByTk: ctx.state.currentUser.id,
38
+ fields: userFields
39
+ });
40
+ (_b = ctx.logger) == null ? void 0 : _b.info("filter-parse: ", {
41
+ $user: user == null ? void 0 : user.toJSON()
42
+ });
43
+ return user;
44
+ };
45
+ }
46
+ __name(getUser, "getUser");
47
+ function isNumeric(str) {
48
+ if (typeof str === "number") return true;
49
+ if (typeof str != "string") return false;
50
+ return !isNaN(str) && !isNaN(parseFloat(str));
51
+ }
52
+ __name(isNumeric, "isNumeric");
53
+ const parseVariables = /* @__PURE__ */ __name(async (ctx, next) => {
54
+ const filter = ctx.action.params.filter;
55
+ if (!filter) {
56
+ return next();
57
+ }
58
+ ctx.action.params.filter = await (0, import_utils.parseFilter)(filter, {
59
+ timezone: ctx.get("x-timezone"),
60
+ now: (/* @__PURE__ */ new Date()).toISOString(),
61
+ getField: /* @__PURE__ */ __name((path) => {
62
+ const fieldPath = path.split(".").filter((p) => !p.startsWith("$") && !isNumeric(p)).join(".");
63
+ const { resourceName } = ctx.action;
64
+ return ctx.db.getFieldByPath(`${resourceName}.${fieldPath}`);
65
+ }, "getField"),
66
+ vars: {
67
+ // @deprecated
68
+ $system: {
69
+ now: (/* @__PURE__ */ new Date()).toISOString()
70
+ },
71
+ // @deprecated
72
+ $date: (0, import_utils.getDateVars)(),
73
+ // 新的命名方式,防止和 formily 内置变量冲突
74
+ $nDate: (0, import_utils.getDateVars)(),
75
+ $user: getUser(ctx),
76
+ $nRole: ctx.state.currentRole
77
+ }
78
+ });
79
+ await next();
80
+ }, "parseVariables");
81
+ // Annotate the CommonJS export names for ESM import in node:
82
+ 0 && (module.exports = {
83
+ parseVariables
84
+ });
@@ -0,0 +1,12 @@
1
+ import { Migration as DbMigration } from '@tachybase/database';
2
+ import Application from './application';
3
+ import Plugin from './plugin';
4
+ import { PluginManager } from './plugin-manager';
5
+ export declare class Migration extends DbMigration {
6
+ appVersion: string;
7
+ pluginVersion: string;
8
+ on: string;
9
+ get app(): Application;
10
+ get pm(): PluginManager;
11
+ get plugin(): Plugin;
12
+ }
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var migration_exports = {};
20
+ __export(migration_exports, {
21
+ Migration: () => Migration
22
+ });
23
+ module.exports = __toCommonJS(migration_exports);
24
+ var import_database = require("@tachybase/database");
25
+ const _Migration = class _Migration extends import_database.Migration {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.appVersion = "";
29
+ this.pluginVersion = "";
30
+ this.on = "afterLoad";
31
+ }
32
+ get app() {
33
+ return this.context.app;
34
+ }
35
+ get pm() {
36
+ return this.context.app.pm;
37
+ }
38
+ get plugin() {
39
+ return this.context.plugin;
40
+ }
41
+ };
42
+ __name(_Migration, "Migration");
43
+ let Migration = _Migration;
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ Migration
47
+ });
@@ -0,0 +1,6 @@
1
+ import { Migration } from '../migration';
2
+ export default class extends Migration {
3
+ on: string;
4
+ appVersion: string;
5
+ up(): Promise<void>;
6
+ }