@steedos/service-cachers-manager 2.7.0 → 2.7.1-beta.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.
@@ -1,4 +1,7 @@
1
1
  import { MetadataCacherBase } from './base';
2
2
  export declare class SettingsCacher extends MetadataCacherBase {
3
3
  constructor();
4
+ onAdded(doc: any): void;
5
+ onChanged(newDoc: any, oldDoc: any): void;
6
+ onRemoved(doc: any): void;
4
7
  }
@@ -3,11 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SettingsCacher = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var base_1 = require("./base");
6
+ var _ = require('lodash');
7
+ var formatValue = function (doc) {
8
+ if (_.isString(doc.value)) {
9
+ try {
10
+ doc.value = JSON.parse(doc.value);
11
+ }
12
+ catch (error) {
13
+ console.log(error);
14
+ }
15
+ }
16
+ return doc;
17
+ };
6
18
  var SettingsCacher = (function (_super) {
7
19
  tslib_1.__extends(SettingsCacher, _super);
8
20
  function SettingsCacher() {
9
21
  return _super.call(this, 'settings', true, { type: 'space', key: { $exists: true } }) || this;
10
22
  }
23
+ SettingsCacher.prototype.onAdded = function (doc) {
24
+ _super.prototype.onAdded.call(this, doc);
25
+ broker.broadcast("@settings.updated.".concat(doc.key), formatValue(doc));
26
+ };
27
+ SettingsCacher.prototype.onChanged = function (newDoc, oldDoc) {
28
+ console.log("settings onChanged");
29
+ _super.prototype.onChanged.call(this, newDoc, oldDoc);
30
+ console.log("broadcast settings onChanged");
31
+ broker.broadcast("@settings.updated.".concat(newDoc.key), formatValue(newDoc));
32
+ };
33
+ SettingsCacher.prototype.onRemoved = function (doc) {
34
+ _super.prototype.onRemoved.call(this, doc);
35
+ };
11
36
  return SettingsCacher;
12
37
  }(base_1.MetadataCacherBase));
13
38
  exports.SettingsCacher = SettingsCacher;
@@ -1 +1 @@
1
- {"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/metadata-cachers/settings.ts"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AC,CAAA;QAC/B,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAA;QAC3C,MAAM,CAAC,SAAS,CAAC,4BAAqB,MAAM,CAAC,GAAG,CAAE,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5E,CAAC;IAED,kCAAS,GAAT,UAAU,GAAQ;QACd,iBAAM,SAAS,YAAC,GAAG,CAAC,CAAA;IACxB,CAAC;IACL,qBAAC;AAAD,CAAC,AApBD,CAAoC,yBAAkB,GAoBrD;AApBY,wCAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-cachers-manager",
3
- "version": "2.7.0",
3
+ "version": "2.7.1-beta.1",
4
4
  "main": "package.service.js",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -8,12 +8,12 @@
8
8
  "build": "rm -rf ./lib && tsc"
9
9
  },
10
10
  "dependencies": {
11
- "@steedos/cachers": "2.7.0",
12
- "@steedos/metadata-registrar": "2.7.0",
13
- "@steedos/utils": "2.7.0"
11
+ "@steedos/cachers": "2.7.1-beta.1",
12
+ "@steedos/metadata-registrar": "2.7.1-beta.1",
13
+ "@steedos/utils": "2.7.1-beta.1"
14
14
  },
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
- "gitHead": "2f1586ea4f8af5b93753878e96f1f48adbef31a7"
18
+ "gitHead": "869f9bbc7438f42da31a8bfd91c83f088fe88079"
19
19
  }
@@ -1,7 +1,45 @@
1
+ /*
2
+ * @Author: baozhoutao@steedos.com
3
+ * @Date: 2024-04-16 09:12:58
4
+ * @LastEditors: baozhoutao@steedos.com
5
+ * @LastEditTime: 2024-04-23 11:34:54
6
+ * @Description:
7
+ */
1
8
  import { MetadataCacherBase } from './base'
2
9
 
10
+ const _ = require('lodash');
11
+
12
+ declare var broker;
13
+
14
+ const formatValue = (doc)=>{
15
+ if(_.isString(doc.value)){
16
+ try {
17
+ doc.value = JSON.parse(doc.value);
18
+ } catch (error) {
19
+ console.log(error)
20
+ }
21
+ }
22
+ return doc;
23
+ }
24
+
3
25
  export class SettingsCacher extends MetadataCacherBase{
4
26
  constructor(){
5
27
  super('settings', true, {type: 'space', key: {$exists: true}});
6
28
  }
29
+
30
+ onAdded(doc: any): void {
31
+ super.onAdded(doc);
32
+ broker.broadcast(`@settings.updated.${doc.key}`, formatValue(doc))
33
+ }
34
+
35
+ onChanged(newDoc: any, oldDoc: any): void {
36
+ console.log(`settings onChanged`)
37
+ super.onChanged(newDoc, oldDoc)
38
+ console.log(`broadcast settings onChanged`)
39
+ broker.broadcast(`@settings.updated.${newDoc.key}`, formatValue(newDoc))
40
+ }
41
+
42
+ onRemoved(doc: any): void {
43
+ super.onRemoved(doc)
44
+ }
7
45
  }