@nocobase/plugin-ui-schema-storage 0.11.0-alpha.1 → 0.11.1-alpha.1

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.
@@ -22,7 +22,8 @@ var _default = (0, _database().defineCollection)({
22
22
  primaryKey: true
23
23
  }, {
24
24
  type: 'string',
25
- name: 'name'
25
+ name: 'name',
26
+ translation: true
26
27
  }, {
27
28
  type: 'string',
28
29
  name: 'componentName'
@@ -346,6 +346,9 @@ class UiSchemaRepository extends _database().Repository {
346
346
  transaction,
347
347
  hooks: false
348
348
  });
349
+ if (newSchema['x-server-hooks']) {
350
+ yield _this7.database.emitAsync(`${_this7.collection.name}.afterSave`, s, options);
351
+ }
349
352
  return;
350
353
  }
351
354
  const oldTree = yield _this7.getJsonSchema(rootUid, {
@@ -406,6 +409,11 @@ class UiSchemaRepository extends _database().Repository {
406
409
  hooks: false,
407
410
  transaction
408
411
  });
412
+ if (schema['x-server-hooks']) {
413
+ yield _this9.database.emitAsync(`${_this9.collection.name}.afterSave`, nodeModel, {
414
+ transaction
415
+ });
416
+ }
409
417
  })();
410
418
  }
411
419
  childrenCount(uid, transaction) {
@@ -788,6 +796,7 @@ class UiSchemaRepository extends _database().Repository {
788
796
  transaction
789
797
  });
790
798
  yield _this28.database.emitAsync(`${_this28.collection.name}.afterCreateWithAssociations`, rootModel, options);
799
+ yield _this28.database.emitAsync(`${_this28.collection.name}.afterSave`, rootModel, options);
791
800
  }
792
801
  if (options !== null && options !== void 0 && options.returnNode) {
793
802
  return nodes;
@@ -1,5 +1,5 @@
1
1
  import { Database } from '@nocobase/database';
2
- export type HookType = 'onSelfDestroy' | 'onCollectionDestroy' | 'onCollectionFieldDestroy' | 'onAnyCollectionFieldDestroy' | 'onSelfCreate' | 'onSelfMove';
2
+ export type HookType = 'onSelfDestroy' | 'onCollectionDestroy' | 'onCollectionFieldDestroy' | 'onAnyCollectionFieldDestroy' | 'onSelfCreate' | 'onSelfSave' | 'onSelfMove';
3
3
  export declare class ServerHooks {
4
4
  protected db: Database;
5
5
  hooks: Map<HookType, Map<string, any>>;
@@ -12,6 +12,7 @@ export declare class ServerHooks {
12
12
  protected onAnyCollectionFieldDestroy(fieldModel: any, options: any): Promise<void>;
13
13
  protected onCollectionFieldDestroy(fieldModel: any, options: any): Promise<void>;
14
14
  protected onUiSchemaCreate(schemaInstance: any, options: any): Promise<void>;
15
+ protected onUiSchemaSave(schemaInstance: any, options: any): Promise<void>;
15
16
  protected findHooksAndCall(hooksFilter: any, hooksArgs: any, transaction: any): Promise<void>;
16
17
  /**
17
18
  * register a server hook function
@@ -20,4 +21,5 @@ export declare class ServerHooks {
20
21
  * @param hookFunc server hook function
21
22
  */
22
23
  register(type: HookType, name: string, hookFunc: any): void;
24
+ remove(type: HookType, name: string): void;
23
25
  }
@@ -61,6 +61,14 @@ class ServerHooks {
61
61
  return _ref4.apply(this, arguments);
62
62
  };
63
63
  }());
64
+ this.db.on('uiSchemas.afterSave', /*#__PURE__*/function () {
65
+ var _ref5 = _asyncToGenerator(function* (model, options) {
66
+ yield _this.onUiSchemaSave(model, options);
67
+ });
68
+ return function (_x9, _x10) {
69
+ return _ref5.apply(this, arguments);
70
+ };
71
+ }());
64
72
  }
65
73
  callSchemaInstanceHooksByType(schemaInstance, options, type) {
66
74
  var _this2 = this;
@@ -74,7 +82,7 @@ class ServerHooks {
74
82
  var _this2$hooks$get;
75
83
  const hook = _step.value;
76
84
  const hookFunc = (_this2$hooks$get = _this2.hooks.get(type)) === null || _this2$hooks$get === void 0 ? void 0 : _this2$hooks$get.get(hook['method']);
77
- yield hookFunc({
85
+ yield hookFunc === null || hookFunc === void 0 ? void 0 : hookFunc({
78
86
  schemaInstance,
79
87
  options,
80
88
  db: _this2.db,
@@ -143,10 +151,16 @@ class ServerHooks {
143
151
  yield _this7.callSchemaInstanceHooksByType(schemaInstance, options, 'onSelfCreate');
144
152
  })();
145
153
  }
146
- findHooksAndCall(hooksFilter, hooksArgs, transaction) {
154
+ onUiSchemaSave(schemaInstance, options) {
147
155
  var _this8 = this;
148
156
  return _asyncToGenerator(function* () {
149
- const hooks = yield _this8.db.getRepository('uiSchemaServerHooks').find({
157
+ yield _this8.callSchemaInstanceHooksByType(schemaInstance, options, 'onSelfSave');
158
+ })();
159
+ }
160
+ findHooksAndCall(hooksFilter, hooksArgs, transaction) {
161
+ var _this9 = this;
162
+ return _asyncToGenerator(function* () {
163
+ const hooks = yield _this9.db.getRepository('uiSchemaServerHooks').find({
150
164
  filter: hooksFilter,
151
165
  appends: ['uiSchema'],
152
166
  transaction
@@ -155,14 +169,14 @@ class ServerHooks {
155
169
  _step2;
156
170
  try {
157
171
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
158
- var _this8$hooks$get;
172
+ var _this9$hooks$get;
159
173
  const hookRecord = _step2.value;
160
174
  const hoodMethodName = hookRecord.get('method');
161
- const hookFunc = (_this8$hooks$get = _this8.hooks.get(hookRecord.get('type'))) === null || _this8$hooks$get === void 0 ? void 0 : _this8$hooks$get.get(hoodMethodName);
175
+ const hookFunc = (_this9$hooks$get = _this9.hooks.get(hookRecord.get('type'))) === null || _this9$hooks$get === void 0 ? void 0 : _this9$hooks$get.get(hoodMethodName);
162
176
  if (hookFunc) {
163
177
  yield hookFunc(_objectSpread(_objectSpread({}, hooksArgs), {}, {
164
178
  schemaInstance: hookRecord.uiSchema,
165
- db: _this8.db,
179
+ db: _this9.db,
166
180
  params: hookRecord.get('params')
167
181
  }));
168
182
  }
@@ -187,5 +201,12 @@ class ServerHooks {
187
201
  const hookTypeMap = this.hooks.get(type);
188
202
  hookTypeMap.set(name, hookFunc);
189
203
  }
204
+ remove(type, name) {
205
+ if (!this.hooks.has(type)) {
206
+ return;
207
+ }
208
+ const hookTypeMap = this.hooks.get(type);
209
+ hookTypeMap.delete(name);
210
+ }
190
211
  }
191
212
  exports.ServerHooks = ServerHooks;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "UI schema",
5
5
  "description": "A plugin used for managing page UI schemas.",
6
6
  "description.zh-CN": "UI schema 配置。",
7
- "version": "0.11.0-alpha.1",
7
+ "version": "0.11.1-alpha.1",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./lib/server/index.js",
10
10
  "files": [
@@ -20,16 +20,16 @@
20
20
  ],
21
21
  "devDependencies": {
22
22
  "@formily/json-schema": "2.2.26",
23
- "@nocobase/actions": "0.11.0-alpha.1",
24
- "@nocobase/cache": "0.11.0-alpha.1",
25
- "@nocobase/client": "0.11.0-alpha.1",
26
- "@nocobase/database": "0.11.0-alpha.1",
27
- "@nocobase/plugin-error-handler": "0.11.0-alpha.1",
28
- "@nocobase/plugin-users": "0.11.0-alpha.1",
29
- "@nocobase/resourcer": "0.11.0-alpha.1",
30
- "@nocobase/server": "0.11.0-alpha.1",
31
- "@nocobase/test": "0.11.0-alpha.1",
32
- "@nocobase/utils": "0.11.0-alpha.1"
23
+ "@nocobase/actions": "0.11.1-alpha.1",
24
+ "@nocobase/cache": "0.11.1-alpha.1",
25
+ "@nocobase/client": "0.11.1-alpha.1",
26
+ "@nocobase/database": "0.11.1-alpha.1",
27
+ "@nocobase/plugin-error-handler": "0.11.1-alpha.1",
28
+ "@nocobase/plugin-users": "0.11.1-alpha.1",
29
+ "@nocobase/resourcer": "0.11.1-alpha.1",
30
+ "@nocobase/server": "0.11.1-alpha.1",
31
+ "@nocobase/test": "0.11.1-alpha.1",
32
+ "@nocobase/utils": "0.11.1-alpha.1"
33
33
  },
34
- "gitHead": "7581b6d3a3a54f09f06a9effb7e3e65328281b2b"
34
+ "gitHead": "9ed1dba520bc5f3a7cb1255ea8d92ccbefc11bc8"
35
35
  }
@@ -14,6 +14,7 @@ export default defineCollection({
14
14
  {
15
15
  type: 'string',
16
16
  name: 'name',
17
+ translation: true,
17
18
  },
18
19
  {
19
20
  type: 'string',
@@ -341,6 +341,9 @@ export class UiSchemaRepository extends Repository {
341
341
  s.set('schema', { ...s.toJSON(), ...newSchema });
342
342
  // console.log(s.toJSON());
343
343
  await s.save({ transaction, hooks: false });
344
+ if (newSchema['x-server-hooks']) {
345
+ await this.database.emitAsync(`${this.collection.name}.afterSave`, s, options);
346
+ }
344
347
  return;
345
348
  }
346
349
  const oldTree = await this.getJsonSchema(rootUid, { transaction });
@@ -389,6 +392,10 @@ export class UiSchemaRepository extends Repository {
389
392
  transaction,
390
393
  },
391
394
  );
395
+
396
+ if (schema['x-server-hooks']) {
397
+ await this.database.emitAsync(`${this.collection.name}.afterSave`, nodeModel, { transaction });
398
+ }
392
399
  }
393
400
 
394
401
  protected async childrenCount(uid, transaction) {
@@ -806,6 +813,7 @@ export class UiSchemaRepository extends Repository {
806
813
  if (rootNode['x-server-hooks']) {
807
814
  const rootModel = await this.findOne({ filter: { 'x-uid': rootNode['x-uid'] }, transaction });
808
815
  await this.database.emitAsync(`${this.collection.name}.afterCreateWithAssociations`, rootModel, options);
816
+ await this.database.emitAsync(`${this.collection.name}.afterSave`, rootModel, options);
809
817
  }
810
818
 
811
819
  if (options?.returnNode) {
@@ -8,6 +8,7 @@ export type HookType =
8
8
  | 'onCollectionFieldDestroy'
9
9
  | 'onAnyCollectionFieldDestroy'
10
10
  | 'onSelfCreate'
11
+ | 'onSelfSave'
11
12
  | 'onSelfMove';
12
13
 
13
14
  export class ServerHooks {
@@ -39,6 +40,10 @@ export class ServerHooks {
39
40
  this.db.on('uiSchemaMove', async (model, options) => {
40
41
  await this.onUiSchemaMove(model, options);
41
42
  });
43
+
44
+ this.db.on('uiSchemas.afterSave', async (model, options) => {
45
+ await this.onUiSchemaSave(model, options);
46
+ });
42
47
  }
43
48
 
44
49
  protected async callSchemaInstanceHooksByType(schemaInstance, options, type: HookType) {
@@ -48,7 +53,7 @@ export class ServerHooks {
48
53
 
49
54
  for (const hook of hooks) {
50
55
  const hookFunc = this.hooks.get(type)?.get(hook['method']);
51
- await hookFunc({
56
+ await hookFunc?.({
52
57
  schemaInstance,
53
58
  options,
54
59
  db: this.db,
@@ -117,6 +122,10 @@ export class ServerHooks {
117
122
  await this.callSchemaInstanceHooksByType(schemaInstance, options, 'onSelfCreate');
118
123
  }
119
124
 
125
+ protected async onUiSchemaSave(schemaInstance, options) {
126
+ await this.callSchemaInstanceHooksByType(schemaInstance, options, 'onSelfSave');
127
+ }
128
+
120
129
  protected async findHooksAndCall(hooksFilter, hooksArgs, transaction) {
121
130
  const hooks = (await this.db.getRepository('uiSchemaServerHooks').find({
122
131
  filter: hooksFilter,
@@ -153,4 +162,13 @@ export class ServerHooks {
153
162
  const hookTypeMap = this.hooks.get(type);
154
163
  hookTypeMap.set(name, hookFunc);
155
164
  }
165
+
166
+ remove(type: HookType, name: string) {
167
+ if (!this.hooks.has(type)) {
168
+ return;
169
+ }
170
+
171
+ const hookTypeMap = this.hooks.get(type);
172
+ hookTypeMap.delete(name);
173
+ }
156
174
  }