pangea-server 3.2.3 → 3.2.5

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,2 +1,3 @@
1
- export declare function ColJson(): (target: any, propertyName: string) => void;
1
+ import type { ColGeneralOptions } from '../../../database/database.types';
2
+ export declare function ColJson(options?: ColGeneralOptions): (target: any, propertyName: string) => void;
2
3
  export declare function ColStrArray(): (target: any, propertyName: string) => void;
@@ -26,8 +26,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ColStrArray = exports.ColJson = void 0;
27
27
  const seq = __importStar(require("sequelize-typescript"));
28
28
  const column_1 = require("./column");
29
- function ColJson() {
30
- return (0, column_1.Column)('JSON', { defaultValue: {} });
29
+ function ColJson(options) {
30
+ return function (target, propertyName) {
31
+ (0, column_1.Column)(seq.DataType.TEXT('long'), {
32
+ ...options,
33
+ defaultValue: options?.defaultValue !== undefined ? JSON.stringify(options.defaultValue) : undefined,
34
+ get() {
35
+ const val = this.getDataValue(propertyName);
36
+ return val ? JSON.parse(val) : null;
37
+ },
38
+ set(val) {
39
+ this.setDataValue(propertyName, val ? JSON.stringify(val) : null);
40
+ },
41
+ })(target, propertyName);
42
+ };
31
43
  }
32
44
  exports.ColJson = ColJson;
33
45
  function ColStrArray() {
@@ -35,16 +47,10 @@ function ColStrArray() {
35
47
  (0, column_1.Column)(seq.DataType.TEXT('long'), {
36
48
  defaultValue: '',
37
49
  get() {
38
- console.log('get: ', propertyName);
39
50
  const val = this.getDataValue(propertyName);
40
- console.log('val: ', val);
41
- console.log('type: ', typeof val);
42
- return typeof val === 'string' && val.length > 0 ? val.split(',') : [];
51
+ return val.length ? val.split(',') : [];
43
52
  },
44
53
  set(val) {
45
- console.log('set: ', propertyName);
46
- console.log('val: ', val);
47
- console.log('type: ', typeof val);
48
54
  this.setDataValue(propertyName, val.join(','));
49
55
  },
50
56
  })(target, propertyName);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.2.3",
4
+ "version": "3.2.5",
5
5
  "files": [
6
6
  "dist"
7
7
  ],