@tachybase/plugin-workflow-test 1.6.21 → 1.6.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  module.exports = {
2
- "@tachybase/client": "1.6.21",
2
+ "@tachybase/client": "1.6.23",
3
3
  "dayjs": "1.11.13",
4
4
  "lodash": "4.17.21",
5
- "@tachybase/test": "1.6.11",
6
- "@tego/server": "1.6.11"
5
+ "@tachybase/test": "1.6.16",
6
+ "@tego/server": "1.6.16"
7
7
  };
@@ -1,26 +1,4 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var categories_exports = {};
19
- __export(categories_exports, {
20
- default: () => categories_default
21
- });
22
- module.exports = __toCommonJS(categories_exports);
23
- var categories_default = {
1
+ module.exports = {
24
2
  name: "categories",
25
3
  fields: [
26
4
  {
@@ -1,26 +1,4 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var comments_exports = {};
19
- __export(comments_exports, {
20
- default: () => comments_default
21
- });
22
- module.exports = __toCommonJS(comments_exports);
23
- var comments_default = {
1
+ module.exports = {
24
2
  name: "comments",
25
3
  fields: [
26
4
  {
@@ -1,26 +1,4 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var posts_exports = {};
19
- __export(posts_exports, {
20
- default: () => posts_default
21
- });
22
- module.exports = __toCommonJS(posts_exports);
23
- var posts_default = {
1
+ module.exports = {
24
2
  name: "posts",
25
3
  createdBy: true,
26
4
  updatedBy: true,
@@ -50,11 +28,6 @@ var posts_default = {
50
28
  {
51
29
  type: "belongsToMany",
52
30
  name: "tags"
53
- },
54
- {
55
- type: "integer",
56
- name: "read",
57
- defaultValue: 0
58
31
  }
59
32
  ]
60
33
  };
@@ -1,31 +1,13 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var replies_exports = {};
19
- __export(replies_exports, {
20
- default: () => replies_default
21
- });
22
- module.exports = __toCommonJS(replies_exports);
23
- var replies_default = {
1
+ module.exports = {
24
2
  name: "replies",
25
3
  fields: [
26
4
  {
27
5
  type: "string",
28
6
  name: "content"
7
+ },
8
+ {
9
+ type: "belongsTo",
10
+ name: "comment"
29
11
  }
30
12
  ]
31
13
  };
@@ -1,26 +1,4 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var tags_exports = {};
19
- __export(tags_exports, {
20
- default: () => tags_default
21
- });
22
- module.exports = __toCommonJS(tags_exports);
23
- var tags_default = {
1
+ module.exports = {
24
2
  name: "tags",
25
3
  fields: [
26
4
  {
@@ -1,7 +1,8 @@
1
- import { MockServer } from '@tachybase/test';
1
+ import { type MockServer } from '@tachybase/test';
2
2
  import { ApplicationOptions, Plugin } from '@tego/server';
3
3
  export interface MockServerOptions extends ApplicationOptions {
4
4
  collectionsPath?: string;
5
+ withAnotherDataSource?: boolean;
5
6
  }
6
7
  export declare function sleep(ms: number): Promise<unknown>;
7
8
  export declare function getApp(options?: MockServerOptions): Promise<MockServer>;
@@ -32,6 +32,7 @@ __export(server_exports, {
32
32
  sleep: () => sleep
33
33
  });
34
34
  module.exports = __toCommonJS(server_exports);
35
+ var import_node_fs = __toESM(require("node:fs"));
35
36
  var import_node_path = __toESM(require("node:path"));
36
37
  var import_test = require("@tachybase/test");
37
38
  var import_server = require("@tego/server");
@@ -44,17 +45,58 @@ function sleep(ms) {
44
45
  });
45
46
  }
46
47
  async function getApp(options = {}) {
47
- const { plugins = [], collectionsPath, ...others } = options;
48
+ const { plugins = [], collectionsPath, withAnotherDataSource = false, ...others } = options;
49
+ const defaultCollectionsPath = import_node_path.default.resolve(__dirname, "collections");
50
+ const compiledCollectionsPath = import_node_path.default.resolve(__dirname, "../../dist/server/collections");
51
+ const resolvedCollectionsPath = collectionsPath || (import_node_fs.default.existsSync(compiledCollectionsPath) ? compiledCollectionsPath : defaultCollectionsPath);
48
52
  class TestCollectionPlugin extends import_server.Plugin {
49
53
  async load() {
50
- if (collectionsPath) {
51
- await this.db.import({ directory: collectionsPath });
54
+ if (resolvedCollectionsPath) {
55
+ await this.db.import({ directory: resolvedCollectionsPath });
56
+ }
57
+ }
58
+ }
59
+ class TestAuthStatusPlugin extends import_server.Plugin {
60
+ async load() {
61
+ if (!this.app.authManager.userStatusService) {
62
+ this.app.authManager.setUserStatusService({
63
+ async checkUserStatus() {
64
+ return {
65
+ allowed: true,
66
+ status: "active",
67
+ statusInfo: {
68
+ title: "Active",
69
+ color: "green",
70
+ allowLogin: true
71
+ },
72
+ errorMessage: "",
73
+ isExpired: false
74
+ };
75
+ },
76
+ async setUserStatusCache() {
77
+ },
78
+ async getUserStatusFromCache() {
79
+ return null;
80
+ },
81
+ getUserStatusCacheKey(userId) {
82
+ return `test-user-status:${userId}`;
83
+ },
84
+ async restoreUserStatus() {
85
+ },
86
+ async clearUserStatusCache() {
87
+ },
88
+ async recordStatusHistoryIfNotExists() {
89
+ }
90
+ });
52
91
  }
53
92
  }
54
93
  }
55
94
  const app = await (0, import_test.createMockServer)({
56
95
  ...others,
57
96
  plugins: [
97
+ "error-handler",
98
+ "collection",
99
+ "user",
58
100
  [
59
101
  "workflow",
60
102
  {
@@ -65,27 +107,30 @@ async function getApp(options = {}) {
65
107
  ],
66
108
  "workflow-test",
67
109
  TestCollectionPlugin,
68
- ...plugins
110
+ ...plugins,
111
+ TestAuthStatusPlugin
69
112
  ]
70
113
  });
71
- await app.dataSourceManager.add(
72
- new import_server.SequelizeDataSource({
73
- name: "another",
74
- collectionManager: {
75
- database: (0, import_test.mockDatabase)({
76
- tablePrefix: `t${(0, import_server.uid)(5)}`
77
- })
78
- },
79
- resourceManager: {}
80
- })
81
- );
82
- const another = app.dataSourceManager.dataSources.get("another");
83
- const anotherDB = another.collectionManager.db;
84
- await anotherDB.import({
85
- directory: import_node_path.default.resolve(__dirname, "collections")
86
- });
87
- await anotherDB.sync();
88
- another.acl.allow("*", "*");
114
+ if (withAnotherDataSource) {
115
+ await app.dataSourceManager.add(
116
+ new import_server.SequelizeDataSource({
117
+ name: "another",
118
+ collectionManager: {
119
+ database: (0, import_server.mockDatabase)({
120
+ tablePrefix: `t${(0, import_server.uid)(5)}`
121
+ })
122
+ },
123
+ resourceManager: {}
124
+ })
125
+ );
126
+ const another = app.dataSourceManager.dataSources.get("another");
127
+ const anotherDB = another.collectionManager.db;
128
+ await anotherDB.import({
129
+ directory: resolvedCollectionsPath
130
+ });
131
+ await anotherDB.sync();
132
+ another.acl.allow("*", "*");
133
+ }
89
134
  return app;
90
135
  }
91
136
  class WorkflowTestPlugin extends import_server.Plugin {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-workflow-test",
3
3
  "displayName": "Workflow: test kit",
4
- "version": "1.6.21",
4
+ "version": "1.6.23",
5
5
  "description": "Workflow Test Toolkit",
6
6
  "keywords": [
7
7
  "Workflow"
@@ -19,12 +19,12 @@
19
19
  "main": "dist/server/index.js",
20
20
  "types": "./dist/server/index.d.ts",
21
21
  "devDependencies": {
22
- "@tachybase/test": "1.6.11",
23
- "@tego/client": "1.6.11",
24
- "@tego/server": "1.6.11",
22
+ "@tachybase/test": "1.6.16",
23
+ "@tego/client": "1.6.16",
24
+ "@tego/server": "1.6.16",
25
25
  "dayjs": "1.11.13",
26
26
  "lodash": "4.17.21",
27
- "@tachybase/client": "1.6.21"
27
+ "@tachybase/client": "1.6.23"
28
28
  },
29
29
  "description.zh-CN": "工作流测试工具包",
30
30
  "displayName.zh-CN": "工作流:测试工具包"
@@ -1,6 +1,4 @@
1
- import { CollectionOptions } from '@tego/server';
2
-
3
- export default {
1
+ module.exports = {
4
2
  name: 'categories',
5
3
  fields: [
6
4
  {
@@ -12,4 +10,4 @@ export default {
12
10
  name: 'posts',
13
11
  },
14
12
  ],
15
- } as CollectionOptions;
13
+ };
@@ -1,6 +1,4 @@
1
- import { CollectionOptions } from '@tego/server';
2
-
3
- export default {
1
+ module.exports = {
4
2
  name: 'comments',
5
3
  fields: [
6
4
  {
@@ -21,4 +19,4 @@ export default {
21
19
  name: 'replies',
22
20
  },
23
21
  ],
24
- } as CollectionOptions;
22
+ };
@@ -1,6 +1,4 @@
1
- import { CollectionOptions } from '@tego/server';
2
-
3
- export default {
1
+ module.exports = {
4
2
  name: 'posts',
5
3
  createdBy: true,
6
4
  updatedBy: true,
@@ -31,10 +29,5 @@ export default {
31
29
  type: 'belongsToMany',
32
30
  name: 'tags',
33
31
  },
34
- {
35
- type: 'integer',
36
- name: 'read',
37
- defaultValue: 0,
38
- },
39
32
  ],
40
- } as CollectionOptions;
33
+ };
@@ -1,9 +1,13 @@
1
- export default {
1
+ module.exports = {
2
2
  name: 'replies',
3
3
  fields: [
4
4
  {
5
5
  type: 'string',
6
6
  name: 'content',
7
7
  },
8
+ {
9
+ type: 'belongsTo',
10
+ name: 'comment',
11
+ },
8
12
  ],
9
13
  };
@@ -1,6 +1,4 @@
1
- import { CollectionOptions } from '@tego/server';
2
-
3
- export default {
1
+ module.exports = {
4
2
  name: 'tags',
5
3
  fields: [
6
4
  {
@@ -12,4 +10,4 @@ export default {
12
10
  name: 'name',
13
11
  },
14
12
  ],
15
- } as CollectionOptions;
13
+ };
@@ -1,6 +1,7 @@
1
+ import fs from 'node:fs';
1
2
  import path from 'node:path';
2
- import { createMockServer, mockDatabase, MockServer } from '@tachybase/test';
3
- import { ApplicationOptions, Plugin, Resourcer, SequelizeDataSource, uid } from '@tego/server';
3
+ import { createMockServer, type MockServer } from '@tachybase/test';
4
+ import { ApplicationOptions, mockDatabase, Plugin, Resourcer, SequelizeDataSource, uid } from '@tego/server';
4
5
 
5
6
  import functions from './functions';
6
7
  import instructions from './instructions';
@@ -8,6 +9,7 @@ import triggers from './triggers';
8
9
 
9
10
  export interface MockServerOptions extends ApplicationOptions {
10
11
  collectionsPath?: string;
12
+ withAnotherDataSource?: boolean;
11
13
  }
12
14
 
13
15
  // async function createMockServer(options: MockServerOptions) {
@@ -24,17 +26,56 @@ export function sleep(ms: number) {
24
26
  }
25
27
 
26
28
  export async function getApp(options: MockServerOptions = {}): Promise<MockServer> {
27
- const { plugins = [], collectionsPath, ...others } = options;
29
+ const { plugins = [], collectionsPath, withAnotherDataSource = false, ...others } = options;
30
+ const defaultCollectionsPath = path.resolve(__dirname, 'collections');
31
+ const compiledCollectionsPath = path.resolve(__dirname, '../../dist/server/collections');
32
+ const resolvedCollectionsPath =
33
+ collectionsPath || (fs.existsSync(compiledCollectionsPath) ? compiledCollectionsPath : defaultCollectionsPath);
34
+
28
35
  class TestCollectionPlugin extends Plugin {
29
36
  async load() {
30
- if (collectionsPath) {
31
- await this.db.import({ directory: collectionsPath });
37
+ if (resolvedCollectionsPath) {
38
+ await this.db.import({ directory: resolvedCollectionsPath });
39
+ }
40
+ }
41
+ }
42
+ class TestAuthStatusPlugin extends Plugin {
43
+ async load() {
44
+ if (!this.app.authManager.userStatusService) {
45
+ this.app.authManager.setUserStatusService({
46
+ async checkUserStatus() {
47
+ return {
48
+ allowed: true,
49
+ status: 'active',
50
+ statusInfo: {
51
+ title: 'Active',
52
+ color: 'green',
53
+ allowLogin: true,
54
+ },
55
+ errorMessage: '',
56
+ isExpired: false,
57
+ };
58
+ },
59
+ async setUserStatusCache() {},
60
+ async getUserStatusFromCache() {
61
+ return null;
62
+ },
63
+ getUserStatusCacheKey(userId: number) {
64
+ return `test-user-status:${userId}`;
65
+ },
66
+ async restoreUserStatus() {},
67
+ async clearUserStatusCache() {},
68
+ async recordStatusHistoryIfNotExists() {},
69
+ });
32
70
  }
33
71
  }
34
72
  }
35
73
  const app = await createMockServer({
36
74
  ...others,
37
75
  plugins: [
76
+ 'error-handler',
77
+ 'collection',
78
+ 'user',
38
79
  [
39
80
  'workflow',
40
81
  {
@@ -46,30 +87,33 @@ export async function getApp(options: MockServerOptions = {}): Promise<MockServe
46
87
  'workflow-test',
47
88
  TestCollectionPlugin,
48
89
  ...plugins,
90
+ TestAuthStatusPlugin,
49
91
  ],
50
92
  });
51
93
 
52
- await app.dataSourceManager.add(
53
- new SequelizeDataSource({
54
- name: 'another',
55
- collectionManager: {
56
- database: mockDatabase({
57
- tablePrefix: `t${uid(5)}`,
58
- }),
59
- },
60
- resourceManager: {},
61
- }),
62
- );
63
- const another = app.dataSourceManager.dataSources.get('another');
64
- // @ts-ignore
65
- const anotherDB = another.collectionManager.db;
94
+ if (withAnotherDataSource) {
95
+ await app.dataSourceManager.add(
96
+ new SequelizeDataSource({
97
+ name: 'another',
98
+ collectionManager: {
99
+ database: mockDatabase({
100
+ tablePrefix: `t${uid(5)}`,
101
+ }),
102
+ },
103
+ resourceManager: {},
104
+ }),
105
+ );
106
+ const another = app.dataSourceManager.dataSources.get('another');
107
+ // @ts-ignore
108
+ const anotherDB = another.collectionManager.db;
66
109
 
67
- await anotherDB.import({
68
- directory: path.resolve(__dirname, 'collections'),
69
- });
70
- await anotherDB.sync();
110
+ await anotherDB.import({
111
+ directory: resolvedCollectionsPath,
112
+ });
113
+ await anotherDB.sync();
71
114
 
72
- another.acl.allow('*', '*');
115
+ another.acl.allow('*', '*');
116
+ }
73
117
 
74
118
  return app;
75
119
  }
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@tego/server';
2
- declare const _default: CollectionOptions;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@tego/server';
2
- declare const _default: CollectionOptions;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@tego/server';
2
- declare const _default: CollectionOptions;
3
- export default _default;
@@ -1,8 +0,0 @@
1
- declare const _default: {
2
- name: string;
3
- fields: {
4
- type: string;
5
- name: string;
6
- }[];
7
- };
8
- export default _default;
@@ -1,3 +0,0 @@
1
- import { CollectionOptions } from '@tego/server';
2
- declare const _default: CollectionOptions;
3
- export default _default;