@jayfong/x-server 2.53.0 → 2.54.0

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.
package/lib/_cjs/index.js CHANGED
@@ -145,6 +145,12 @@ Object.keys(_captcha).forEach(function (key) {
145
145
  if (key in exports && exports[key] === _captcha[key]) return;
146
146
  exports[key] = _captcha[key];
147
147
  });
148
+ var _db_value = require("./services/db_value");
149
+ Object.keys(_db_value).forEach(function (key) {
150
+ if (key === "default" || key === "__esModule") return;
151
+ if (key in exports && exports[key] === _db_value[key]) return;
152
+ exports[key] = _db_value[key];
153
+ });
148
154
  var _dingtalk = require("./services/dingtalk");
149
155
  Object.keys(_dingtalk).forEach(function (key) {
150
156
  if (key === "default" || key === "__esModule") return;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.DbValueService = void 0;
5
+ var _vtils = require("vtils");
6
+ class DbValueService {
7
+ constructor() {
8
+ this.serviceName = 'dbValue';
9
+ this.SimpleArray = class {
10
+ constructor(options) {
11
+ this.separator = void 0;
12
+ this.affix = void 0;
13
+ this.number = void 0;
14
+ this.add = (value, defaultValue = []) => {
15
+ const text = (!value || !Array.isArray(value) ? defaultValue : value.filter(v => v != null && v !== '')).join(this.separator);
16
+ return !text || !this.affix ? text : `${this.affix}${text}${this.affix}`;
17
+ };
18
+ this.get = value => {
19
+ const res = !value ? [] : String(!this.affix ? value : value.substring(this.affix.length, value.length - this.affix.length)).split(this.separator).filter(v => v !== '');
20
+ return this.number ? res.map(Number) : res;
21
+ };
22
+ this.update = value => {
23
+ const text = !value || !Array.isArray(value) ? undefined : value.filter(v => v != null && v !== '').join(this.separator);
24
+ return !text || !this.affix ? text : `${this.affix}${text}${this.affix}`;
25
+ };
26
+ this.separator = (options == null ? void 0 : options.separator) || ',';
27
+ this.affix = (options == null ? void 0 : options.affix) || '';
28
+ this.number = !!(options != null && options.number);
29
+ }
30
+ };
31
+ this.JsonArray = class {
32
+ constructor() {
33
+ this.add = (value, defaultValue = []) => {
34
+ return JSON.stringify(!value || !Array.isArray(value) ? defaultValue : value);
35
+ };
36
+ this.get = value => {
37
+ return !value ? [] : JSON.parse(value);
38
+ };
39
+ this.update = value => {
40
+ return !value || !Array.isArray(value) ? undefined : JSON.stringify(value);
41
+ };
42
+ }
43
+ };
44
+ this.JsonObject = class {
45
+ constructor() {
46
+ this.add = (value, defaultValue = {}) => {
47
+ return JSON.stringify(!value || !(0, _vtils.isPlainObject)(value) ? defaultValue : value);
48
+ };
49
+ this.get = value => {
50
+ return !value ? {} : JSON.parse(value);
51
+ };
52
+ this.update = value => {
53
+ return !value || !(0, _vtils.isPlainObject)(value) ? undefined : JSON.stringify(value);
54
+ };
55
+ }
56
+ };
57
+ }
58
+ }
59
+ exports.DbValueService = DbValueService;
package/lib/_cjs/x.js CHANGED
@@ -3,9 +3,10 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
4
  exports.__esModule = true;
5
5
  exports.x = void 0;
6
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
7
6
  var _os = _interopRequireDefault(require("os"));
8
7
  var _path = _interopRequireDefault(require("path"));
8
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
+ var _db_value = require("./services/db_value");
9
10
  var _dispose = require("./services/dispose");
10
11
  var _emoji = require("./services/emoji");
11
12
  var _log = require("./services/log");
@@ -24,4 +25,4 @@ const x = exports.x = {
24
25
  _fsExtra.default.ensureDirSync(x.dataDir);
25
26
  x.register(new _dispose.DisposeService({
26
27
  disposeOnExit: true
27
- }), new _log.LogService(), new _emoji.EmojiService());
28
+ }), new _log.LogService(), new _emoji.EmojiService(), new _db_value.DbValueService());
package/lib/index.d.ts CHANGED
@@ -22,6 +22,7 @@ export * from './plugins/xml_parser';
22
22
  export * from './services/base';
23
23
  export * from './services/cache';
24
24
  export * from './services/captcha';
25
+ export * from './services/db_value';
25
26
  export * from './services/dingtalk';
26
27
  export * from './services/dispose';
27
28
  export * from './services/emoji';
package/lib/index.js CHANGED
@@ -23,6 +23,7 @@ export * from "./plugins/xml_parser";
23
23
  export * from "./services/base";
24
24
  export * from "./services/cache";
25
25
  export * from "./services/captcha";
26
+ export * from "./services/db_value";
26
27
  export * from "./services/dingtalk";
27
28
  export * from "./services/dispose";
28
29
  export * from "./services/emoji";
@@ -0,0 +1,49 @@
1
+ import { BaseService } from './base';
2
+ export type DbValueServiceSimpleArrayOptions = {
3
+ /**
4
+ * 分隔符
5
+ *
6
+ * @default ,
7
+ */
8
+ separator?: string;
9
+ /**
10
+ * 前缀后缀
11
+ */
12
+ affix?: string;
13
+ /**
14
+ * 是否数字
15
+ */
16
+ number?: boolean;
17
+ };
18
+ export declare class DbValueService implements BaseService {
19
+ serviceName: string;
20
+ SimpleArray: {
21
+ new <T extends string | number = string>(options?: DbValueServiceSimpleArrayOptions): {
22
+ separator: string;
23
+ affix: string;
24
+ number: boolean;
25
+ add: (value?: T[], defaultValue?: T[]) => string;
26
+ get: (value?: string) => T[];
27
+ update: (value?: T[]) => string | undefined;
28
+ };
29
+ };
30
+ JsonArray: {
31
+ new <T = string>(): {
32
+ add: (value?: T[], defaultValue?: T[]) => string;
33
+ get: (value?: string) => T[];
34
+ update: (value?: T[]) => string | undefined;
35
+ };
36
+ };
37
+ JsonObject: {
38
+ new <T>(): {
39
+ add: (value?: T, defaultValue?: T) => string;
40
+ get: (value?: string) => T;
41
+ update: (value?: T) => string | undefined;
42
+ };
43
+ };
44
+ }
45
+ declare module '../x' {
46
+ interface X {
47
+ dbValue: DbValueService;
48
+ }
49
+ }
@@ -0,0 +1,54 @@
1
+ import { isPlainObject } from 'vtils';
2
+ export class DbValueService {
3
+ constructor() {
4
+ this.serviceName = 'dbValue';
5
+ this.SimpleArray = class {
6
+ constructor(options) {
7
+ this.separator = void 0;
8
+ this.affix = void 0;
9
+ this.number = void 0;
10
+ this.add = (value, defaultValue = []) => {
11
+ const text = (!value || !Array.isArray(value) ? defaultValue : value.filter(v => v != null && v !== '')).join(this.separator);
12
+ return !text || !this.affix ? text : `${this.affix}${text}${this.affix}`;
13
+ };
14
+ this.get = value => {
15
+ const res = !value ? [] : String(!this.affix ? value : value.substring(this.affix.length, value.length - this.affix.length)).split(this.separator).filter(v => v !== '');
16
+ return this.number ? res.map(Number) : res;
17
+ };
18
+ this.update = value => {
19
+ const text = !value || !Array.isArray(value) ? undefined : value.filter(v => v != null && v !== '').join(this.separator);
20
+ return !text || !this.affix ? text : `${this.affix}${text}${this.affix}`;
21
+ };
22
+ this.separator = (options == null ? void 0 : options.separator) || ',';
23
+ this.affix = (options == null ? void 0 : options.affix) || '';
24
+ this.number = !!(options != null && options.number);
25
+ }
26
+ };
27
+ this.JsonArray = class {
28
+ constructor() {
29
+ this.add = (value, defaultValue = []) => {
30
+ return JSON.stringify(!value || !Array.isArray(value) ? defaultValue : value);
31
+ };
32
+ this.get = value => {
33
+ return !value ? [] : JSON.parse(value);
34
+ };
35
+ this.update = value => {
36
+ return !value || !Array.isArray(value) ? undefined : JSON.stringify(value);
37
+ };
38
+ }
39
+ };
40
+ this.JsonObject = class {
41
+ constructor() {
42
+ this.add = (value, defaultValue = {}) => {
43
+ return JSON.stringify(!value || !isPlainObject(value) ? defaultValue : value);
44
+ };
45
+ this.get = value => {
46
+ return !value ? {} : JSON.parse(value);
47
+ };
48
+ this.update = value => {
49
+ return !value || !isPlainObject(value) ? undefined : JSON.stringify(value);
50
+ };
51
+ }
52
+ };
53
+ }
54
+ }
package/lib/x.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { BaseService } from './services/base';
3
+ import './services/db_value';
3
4
  import './services/dispose';
4
5
  import './services/emoji';
5
6
  import './services/log';
package/lib/x.js CHANGED
@@ -1,6 +1,7 @@
1
- import fs from 'fs-extra';
2
1
  import os from 'os';
3
2
  import path from 'path';
3
+ import fs from 'fs-extra';
4
+ import { DbValueService } from "./services/db_value";
4
5
  import { DisposeService } from "./services/dispose";
5
6
  import { EmojiService } from "./services/emoji";
6
7
  import { LogService } from "./services/log";
@@ -19,4 +20,4 @@ export const x = {
19
20
  fs.ensureDirSync(x.dataDir);
20
21
  x.register(new DisposeService({
21
22
  disposeOnExit: true
22
- }), new LogService(), new EmojiService());
23
+ }), new LogService(), new EmojiService(), new DbValueService());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.53.0",
3
+ "version": "2.54.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",