oak-domain 1.0.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.
Files changed (89) hide show
  1. package/lib/OakError.d.ts +7 -0
  2. package/lib/OakError.js +29 -0
  3. package/lib/actions/action.d.ts +6 -0
  4. package/lib/actions/action.js +12 -0
  5. package/lib/actions/relation.d.ts +1 -0
  6. package/lib/actions/relation.js +2 -0
  7. package/lib/compiler/env.d.ts +10 -0
  8. package/lib/compiler/env.js +26 -0
  9. package/lib/compiler/schemalBuilder.d.ts +2 -0
  10. package/lib/compiler/schemalBuilder.js +2738 -0
  11. package/lib/compiler/uiBuilder.d.ts +1 -0
  12. package/lib/compiler/uiBuilder.js +3 -0
  13. package/lib/compiler/utils.d.ts +2 -0
  14. package/lib/compiler/utils.js +11 -0
  15. package/lib/store/CascadeStore.d.ts +38 -0
  16. package/lib/store/CascadeStore.js +681 -0
  17. package/lib/store/TriggerExecutor.d.ts +30 -0
  18. package/lib/store/TriggerExecutor.js +549 -0
  19. package/lib/store/UniversalContext.d.ts +26 -0
  20. package/lib/store/UniversalContext.js +208 -0
  21. package/lib/store/actionDef.d.ts +8 -0
  22. package/lib/store/actionDef.js +241 -0
  23. package/lib/store/filter.d.ts +36 -0
  24. package/lib/store/filter.js +121 -0
  25. package/lib/store/relation.d.ts +13 -0
  26. package/lib/store/relation.js +64 -0
  27. package/lib/store/watchers.d.ts +2 -0
  28. package/lib/store/watchers.js +32 -0
  29. package/lib/types/Action.d.ts +14 -0
  30. package/lib/types/Action.js +2 -0
  31. package/lib/types/AppLoader.d.ts +11 -0
  32. package/lib/types/AppLoader.js +10 -0
  33. package/lib/types/Aspect.d.ts +12 -0
  34. package/lib/types/Aspect.js +4 -0
  35. package/lib/types/Auth.d.ts +28 -0
  36. package/lib/types/Auth.js +2 -0
  37. package/lib/types/Connector.d.ts +26 -0
  38. package/lib/types/Connector.js +9 -0
  39. package/lib/types/Context.d.ts +14 -0
  40. package/lib/types/Context.js +3 -0
  41. package/lib/types/DataType.d.ts +17 -0
  42. package/lib/types/DataType.js +5 -0
  43. package/lib/types/Demand.d.ts +77 -0
  44. package/lib/types/Demand.js +9 -0
  45. package/lib/types/Entity.d.ts +138 -0
  46. package/lib/types/Entity.js +8 -0
  47. package/lib/types/Exception.d.ts +48 -0
  48. package/lib/types/Exception.js +178 -0
  49. package/lib/types/Expression.d.ts +132 -0
  50. package/lib/types/Expression.js +378 -0
  51. package/lib/types/Geo.d.ts +18 -0
  52. package/lib/types/Geo.js +2 -0
  53. package/lib/types/Locale.d.ts +24 -0
  54. package/lib/types/Locale.js +2 -0
  55. package/lib/types/Logger.d.ts +5 -0
  56. package/lib/types/Logger.js +3 -0
  57. package/lib/types/Polyfill.d.ts +23 -0
  58. package/lib/types/Polyfill.js +2 -0
  59. package/lib/types/RowStore.d.ts +22 -0
  60. package/lib/types/RowStore.js +33 -0
  61. package/lib/types/Storage.d.ts +48 -0
  62. package/lib/types/Storage.js +2 -0
  63. package/lib/types/Trigger.d.ts +105 -0
  64. package/lib/types/Trigger.js +24 -0
  65. package/lib/types/Txn.d.ts +2 -0
  66. package/lib/types/Txn.js +3 -0
  67. package/lib/types/Watcher.d.ts +19 -0
  68. package/lib/types/Watcher.js +4 -0
  69. package/lib/types/index.d.ts +18 -0
  70. package/lib/types/index.js +30 -0
  71. package/lib/types/schema/DataTypes.d.ts +32 -0
  72. package/lib/types/schema/DataTypes.js +3 -0
  73. package/lib/utils/SimpleConnector.d.ts +29 -0
  74. package/lib/utils/SimpleConnector.js +145 -0
  75. package/lib/utils/assert.d.ts +5 -0
  76. package/lib/utils/assert.js +11 -0
  77. package/lib/utils/concurrent.d.ts +15 -0
  78. package/lib/utils/concurrent.js +138 -0
  79. package/lib/utils/geo.d.ts +4 -0
  80. package/lib/utils/geo.js +24 -0
  81. package/lib/utils/lodash.d.ts +16 -0
  82. package/lib/utils/lodash.js +32 -0
  83. package/lib/utils/string.d.ts +2 -0
  84. package/lib/utils/string.js +11 -0
  85. package/lib/utils/uuid.d.ts +2 -0
  86. package/lib/utils/uuid.js +11 -0
  87. package/lib/utils/validator.d.ts +23 -0
  88. package/lib/utils/validator.js +123 -0
  89. package/package.json +38 -0
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.makeException = exports.OakCongruentRowExists = exports.OakUserUnpermittedException = exports.OakInputIllegalException = exports.OakRowInconsistencyException = exports.OakUserException = exports.OakExternalException = exports.OakException = void 0;
19
+ var OakException = /** @class */ (function (_super) {
20
+ __extends(OakException, _super);
21
+ function OakException(message) {
22
+ var _newTarget = this.constructor;
23
+ var _this = _super.call(this, message) || this;
24
+ _this.name = _newTarget.name;
25
+ if (typeof Error.captureStackTrace === 'function') {
26
+ Error.captureStackTrace(_this, _newTarget);
27
+ }
28
+ if (typeof Object.setPrototypeOf === 'function') {
29
+ Object.setPrototypeOf(_this, _newTarget.prototype);
30
+ }
31
+ else {
32
+ _this.__proto__ = _newTarget.prototype;
33
+ }
34
+ return _this;
35
+ }
36
+ OakException.prototype.toString = function () {
37
+ return JSON.stringify({
38
+ name: this.constructor.name,
39
+ message: this.message,
40
+ });
41
+ };
42
+ return OakException;
43
+ }(Error));
44
+ exports.OakException = OakException;
45
+ var OakExternalException = /** @class */ (function (_super) {
46
+ __extends(OakExternalException, _super);
47
+ function OakExternalException() {
48
+ return _super !== null && _super.apply(this, arguments) || this;
49
+ }
50
+ return OakExternalException;
51
+ }(Error));
52
+ exports.OakExternalException = OakExternalException;
53
+ var OakUserException = /** @class */ (function (_super) {
54
+ __extends(OakUserException, _super);
55
+ function OakUserException() {
56
+ return _super !== null && _super.apply(this, arguments) || this;
57
+ }
58
+ return OakUserException;
59
+ }(OakException));
60
+ exports.OakUserException = OakUserException;
61
+ ;
62
+ // 在系统更新数据时,以下三个异常应按规范依次抛出。
63
+ /**
64
+ * 数据不一致异常,系统认为现有的数据不允许相应的动作时抛此异常
65
+ *
66
+ */
67
+ var OakRowInconsistencyException = /** @class */ (function (_super) {
68
+ __extends(OakRowInconsistencyException, _super);
69
+ function OakRowInconsistencyException(data, message) {
70
+ var _this = _super.call(this, message) || this;
71
+ _this.data = data;
72
+ return _this;
73
+ }
74
+ OakRowInconsistencyException.prototype.getData = function () {
75
+ return this.data;
76
+ };
77
+ OakRowInconsistencyException.prototype.toString = function () {
78
+ return JSON.stringify({
79
+ name: this.constructor.name,
80
+ message: this.message,
81
+ data: this.data,
82
+ });
83
+ };
84
+ return OakRowInconsistencyException;
85
+ }(OakUserException));
86
+ exports.OakRowInconsistencyException = OakRowInconsistencyException;
87
+ ;
88
+ /**
89
+ * 当输入的数据非法时抛此异常,attributes表示非法的属性
90
+ */
91
+ var OakInputIllegalException = /** @class */ (function (_super) {
92
+ __extends(OakInputIllegalException, _super);
93
+ function OakInputIllegalException(attributes, message) {
94
+ var _this = _super.call(this, message) || this;
95
+ _this.attributes = attributes;
96
+ return _this;
97
+ }
98
+ OakInputIllegalException.prototype.getAttributes = function () {
99
+ return this.attributes;
100
+ };
101
+ OakInputIllegalException.prototype.addAttributesPrefix = function (prefix) {
102
+ this.attributes = this.attributes.map(function (ele) { return "".concat(prefix, ".").concat(ele); });
103
+ };
104
+ OakInputIllegalException.prototype.toString = function () {
105
+ return JSON.stringify({
106
+ name: this.constructor.name,
107
+ message: this.message,
108
+ attributes: this.attributes,
109
+ });
110
+ };
111
+ return OakInputIllegalException;
112
+ }(OakUserException));
113
+ exports.OakInputIllegalException = OakInputIllegalException;
114
+ ;
115
+ /**
116
+ * 用户权限不够时抛的异常
117
+ */
118
+ var OakUserUnpermittedException = /** @class */ (function (_super) {
119
+ __extends(OakUserUnpermittedException, _super);
120
+ function OakUserUnpermittedException() {
121
+ return _super !== null && _super.apply(this, arguments) || this;
122
+ }
123
+ return OakUserUnpermittedException;
124
+ }(OakUserException));
125
+ exports.OakUserUnpermittedException = OakUserUnpermittedException;
126
+ ;
127
+ /**
128
+ * 要插入行时,发现已经有相同的行数据
129
+ */
130
+ var OakCongruentRowExists = /** @class */ (function (_super) {
131
+ __extends(OakCongruentRowExists, _super);
132
+ function OakCongruentRowExists(data, message) {
133
+ var _this = _super.call(this, message) || this;
134
+ _this.data = data;
135
+ return _this;
136
+ }
137
+ OakCongruentRowExists.prototype.getData = function () {
138
+ return this.data;
139
+ };
140
+ OakCongruentRowExists.prototype.toString = function () {
141
+ return JSON.stringify({
142
+ name: this.constructor.name,
143
+ message: this.message,
144
+ data: this.data,
145
+ });
146
+ };
147
+ return OakCongruentRowExists;
148
+ }(OakUserException));
149
+ exports.OakCongruentRowExists = OakCongruentRowExists;
150
+ function makeException(data) {
151
+ var name = data.name;
152
+ switch (name) {
153
+ case OakException.name: {
154
+ return new OakException(data.message);
155
+ }
156
+ case OakUserException.name: {
157
+ return new OakUserException(data.message);
158
+ }
159
+ case OakExternalException.name: {
160
+ return new OakExternalException(data.message);
161
+ }
162
+ case OakRowInconsistencyException.name: {
163
+ return new OakRowInconsistencyException(data.data, data.message);
164
+ }
165
+ case OakInputIllegalException.name: {
166
+ return new OakInputIllegalException(data.attributes, data.message);
167
+ }
168
+ case OakUserUnpermittedException.name: {
169
+ return new OakUserUnpermittedException(data.message);
170
+ }
171
+ case OakCongruentRowExists.name: {
172
+ return new OakCongruentRowExists(data.data, data.message);
173
+ }
174
+ default:
175
+ return;
176
+ }
177
+ }
178
+ exports.makeException = makeException;
@@ -0,0 +1,132 @@
1
+ import { RefAttr } from "./Demand";
2
+ import { Geo } from "./Geo";
3
+ export declare type RefOrExpression<A> = RefAttr<A> | Expression<A>;
4
+ declare type MathType<A> = RefOrExpression<A> | number;
5
+ declare type StringType<A> = RefOrExpression<A> | string;
6
+ interface Add<A> {
7
+ $add: (MathType<A> | StringType<A>)[];
8
+ }
9
+ interface Subtract<A> {
10
+ $subtract: [MathType<A>, MathType<A>];
11
+ }
12
+ interface Multiply<A> {
13
+ $multiply: (MathType<A>)[];
14
+ }
15
+ interface Divide<A> {
16
+ $divide: [MathType<A>, MathType<A>];
17
+ }
18
+ interface Abs<A> {
19
+ $abs: MathType<A>;
20
+ }
21
+ interface Round<A> {
22
+ $round: [MathType<A>, MathType<A>];
23
+ }
24
+ interface Floor<A> {
25
+ $floor: MathType<A>;
26
+ }
27
+ interface Ceil<A> {
28
+ $ceil: MathType<A>;
29
+ }
30
+ interface Pow<A> {
31
+ $pow: [MathType<A>, MathType<A>];
32
+ }
33
+ declare type MathExpression<A> = Add<A> | Subtract<A> | Multiply<A> | Divide<A> | Abs<A> | Round<A> | Floor<A> | Ceil<A> | Pow<A>;
34
+ declare type CmpType<A> = RefOrExpression<A> | string | number;
35
+ interface Gt<A> {
36
+ $gt: [CmpType<A>, CmpType<A>];
37
+ }
38
+ interface Lt<A> {
39
+ $lt: [CmpType<A>, CmpType<A>];
40
+ }
41
+ interface Eq<A> {
42
+ $eq: [CmpType<A>, CmpType<A>];
43
+ }
44
+ interface Gte<A> {
45
+ $gte: [CmpType<A>, CmpType<A>];
46
+ }
47
+ interface Lte<A> {
48
+ $lte: [CmpType<A>, CmpType<A>];
49
+ }
50
+ interface Ne<A> {
51
+ $ne: [CmpType<A>, CmpType<A>];
52
+ }
53
+ interface StartsWith<A> {
54
+ $startsWith: [RefOrExpression<A> | string, RefOrExpression<A> | string];
55
+ }
56
+ interface EndsWith<A> {
57
+ $endsWith: [RefOrExpression<A> | string, RefOrExpression<A> | string];
58
+ }
59
+ interface Includes<A> {
60
+ $includes: [RefOrExpression<A> | string, RefOrExpression<A> | string];
61
+ }
62
+ declare type CompareExpression<A> = Lt<A> | Gt<A> | Lte<A> | Gte<A> | Eq<A> | Ne<A> | StartsWith<A> | EndsWith<A> | Includes<A>;
63
+ interface BoolTrue<A> {
64
+ $true: Expression<A>;
65
+ }
66
+ interface BoolFalse<A> {
67
+ $false: Expression<A>;
68
+ }
69
+ declare type BoolExpression<A> = BoolTrue<A> | BoolFalse<A>;
70
+ interface LogicAnd<A> {
71
+ $and: Expression<A>[];
72
+ }
73
+ interface LogicOr<A> {
74
+ $or: Expression<A>[];
75
+ }
76
+ interface LogicNot<A> {
77
+ $not: Expression<A>;
78
+ }
79
+ declare type LogicExpression<A> = LogicAnd<A> | LogicOr<A> | LogicNot<A>;
80
+ interface DateYear<A> {
81
+ $year: RefOrExpression<A> | Date | number;
82
+ }
83
+ interface DateMonth<A> {
84
+ $month: RefOrExpression<A> | Date | number;
85
+ }
86
+ interface DateWeekday<A> {
87
+ $weekday: RefOrExpression<A> | Date | number;
88
+ }
89
+ interface DateWeekOfYear<A> {
90
+ $weekOfYear: RefOrExpression<A> | Date | number;
91
+ }
92
+ interface DateDay<A> {
93
+ $day: RefOrExpression<A> | Date | number;
94
+ }
95
+ interface DateDayOfMonth<A> {
96
+ $dayOfMonth: RefOrExpression<A> | Date | number;
97
+ }
98
+ interface DateDayOfWeek<A> {
99
+ $dayOfWeek: RefOrExpression<A> | Date | number;
100
+ }
101
+ interface DateDayOfYear<A> {
102
+ $dayOfYear: RefOrExpression<A> | Date | number;
103
+ }
104
+ interface DateDiff<A> {
105
+ $dateDiff: [RefOrExpression<A> | Date | number, RefOrExpression<A> | Date | number, 'y' | 'M' | 'd' | 'h' | 'm' | 's'];
106
+ }
107
+ interface DateCeiling<A> {
108
+ $dateCeil: [RefOrExpression<A> | Date | number, 'y' | 'M' | 'd' | 'h' | 'm' | 's'];
109
+ }
110
+ interface DateFloor<A> {
111
+ $dateFloor: [RefOrExpression<A> | Date | number, 'y' | 'M' | 'd' | 'h' | 'm' | 's'];
112
+ }
113
+ declare type DateExpression<A> = DateYear<A> | DateMonth<A> | DateWeekday<A> | DateWeekOfYear<A> | DateDay<A> | DateDayOfYear<A> | DateDayOfMonth<A> | DateDayOfWeek<A> | DateDiff<A> | DateCeiling<A> | DateFloor<A>;
114
+ interface GeoContains<A> {
115
+ $contains: [RefOrExpression<A> | Geo, RefOrExpression<A> | Geo];
116
+ }
117
+ interface GeoDistance<A> {
118
+ $distance: [RefOrExpression<A> | Geo, RefOrExpression<A> | Geo];
119
+ }
120
+ declare type GeoExpression<A> = GeoContains<A> | GeoDistance<A>;
121
+ export declare type Expression<A> = GeoExpression<A> | DateExpression<A> | LogicExpression<A> | BoolExpression<A> | CompareExpression<A> | MathExpression<A>;
122
+ export declare type ExpressionConstant = Geo | number | Date | string | boolean;
123
+ export declare function isGeoExpression<A>(expression: any): expression is GeoExpression<A>;
124
+ export declare function isDateExpression<A>(expression: any): expression is DateExpression<A>;
125
+ export declare function isLogicExpression<A>(expression: any): expression is LogicExpression<A>;
126
+ export declare function isBoolExpression<A>(expression: any): expression is BoolExpression<A>;
127
+ export declare function isCompareExpression<A>(expression: any): expression is CompareExpression<A>;
128
+ export declare function isMathExpression<A>(expression: any): expression is MathExpression<A>;
129
+ export declare function isExpression<A>(expression: any): expression is Expression<A>;
130
+ export declare function opMultipleParams(op: string): boolean;
131
+ export declare function execOp(op: string, params: any, obscure?: boolean): ExpressionConstant;
132
+ export {};
@@ -0,0 +1,378 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ var __importDefault = (this && this.__importDefault) || function (mod) {
30
+ return (mod && mod.__esModule) ? mod : { "default": mod };
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.execOp = exports.opMultipleParams = exports.isExpression = exports.isMathExpression = exports.isCompareExpression = exports.isBoolExpression = exports.isLogicExpression = exports.isDateExpression = exports.isGeoExpression = void 0;
34
+ var assert_1 = __importDefault(require("assert"));
35
+ var dayjs_1 = __importDefault(require("dayjs"));
36
+ var weekOfYear_1 = __importDefault(require("dayjs/plugin/weekOfYear"));
37
+ var dayOfYear_1 = __importDefault(require("dayjs/plugin/dayOfYear"));
38
+ var geo_1 = require("../utils/geo");
39
+ dayjs_1.default.extend(weekOfYear_1.default);
40
+ dayjs_1.default.extend(dayOfYear_1.default);
41
+ ;
42
+ ;
43
+ ;
44
+ ;
45
+ ;
46
+ ;
47
+ ;
48
+ ;
49
+ ;
50
+ ;
51
+ ;
52
+ ;
53
+ ;
54
+ ;
55
+ ;
56
+ ;
57
+ ;
58
+ ;
59
+ ;
60
+ ;
61
+ ;
62
+ ;
63
+ ;
64
+ ;
65
+ ;
66
+ ;
67
+ ;
68
+ ;
69
+ ;
70
+ ;
71
+ ;
72
+ ;
73
+ ;
74
+ function isGeoExpression(expression) {
75
+ if (Object.keys(expression).length == 1) {
76
+ var op = Object.keys(expression)[0];
77
+ if (['$contains', '$distance'].includes(op)) {
78
+ return true;
79
+ }
80
+ }
81
+ return false;
82
+ }
83
+ exports.isGeoExpression = isGeoExpression;
84
+ function isDateExpression(expression) {
85
+ if (Object.keys(expression).length == 1) {
86
+ var op = Object.keys(expression)[0];
87
+ if (['$year', '$month', '$weekday', '$weekOfYear', '$day', '$dayOfMonth',
88
+ '$dayOfWeek', '$dayOfYear', '$dateDiff', '$dateCeil', '$dateFloor'].includes(op)) {
89
+ return true;
90
+ }
91
+ }
92
+ return false;
93
+ }
94
+ exports.isDateExpression = isDateExpression;
95
+ function isLogicExpression(expression) {
96
+ if (Object.keys(expression).length == 1) {
97
+ var op = Object.keys(expression)[0];
98
+ if (['$and', '$or', '$not'].includes(op)) {
99
+ return true;
100
+ }
101
+ }
102
+ return false;
103
+ }
104
+ exports.isLogicExpression = isLogicExpression;
105
+ function isBoolExpression(expression) {
106
+ if (Object.keys(expression).length == 1) {
107
+ var op = Object.keys(expression)[0];
108
+ if (['$true', '$false'].includes(op)) {
109
+ return true;
110
+ }
111
+ }
112
+ return false;
113
+ }
114
+ exports.isBoolExpression = isBoolExpression;
115
+ function isCompareExpression(expression) {
116
+ if (Object.keys(expression).length == 1) {
117
+ var op = Object.keys(expression)[0];
118
+ if (['$gt', '$lt', '$gte', '$lte', '$eq', '$ne',
119
+ '$startsWith', '$endsWith', '$includes'].includes(op)) {
120
+ return true;
121
+ }
122
+ }
123
+ return false;
124
+ }
125
+ exports.isCompareExpression = isCompareExpression;
126
+ function isMathExpression(expression) {
127
+ if (Object.keys(expression).length == 1) {
128
+ var op = Object.keys(expression)[0];
129
+ if (['$add', '$subtract', '$multiply', '$divide', '$abs', '$pow',
130
+ '$round', '$floor', '$ceil'].includes(op)) {
131
+ return true;
132
+ }
133
+ }
134
+ return false;
135
+ }
136
+ exports.isMathExpression = isMathExpression;
137
+ function isExpression(expression) {
138
+ return typeof expression === 'object' && Object.keys(expression).length === 1 && Object.keys(expression)[0].startsWith('$');
139
+ }
140
+ exports.isExpression = isExpression;
141
+ function opMultipleParams(op) {
142
+ return !['$year', '$month', '$weekday', '$weekOfYear', '$day', '$dayOfMonth',
143
+ '$dayOfWeek', '$dayOfYear', '$not', '$true', '$false', '$abs', '$round', '$floor', '$ceil'].includes(op);
144
+ }
145
+ exports.opMultipleParams = opMultipleParams;
146
+ function execOp(op, params, obscure) {
147
+ var e_1, _a, e_2, _b;
148
+ if (obscure && (params === undefined || params.includes(undefined))) {
149
+ return true;
150
+ }
151
+ switch (op) {
152
+ case '$gt': {
153
+ return params[0] > params[1];
154
+ }
155
+ case '$lt': {
156
+ return params[0] < params[1];
157
+ }
158
+ case '$gte': {
159
+ return params[0] >= params[1];
160
+ }
161
+ case '$lte': {
162
+ return params[0] <= params[1];
163
+ }
164
+ case '$eq': {
165
+ return params[0] === params[1];
166
+ }
167
+ case '$ne': {
168
+ return params[0] !== params[1];
169
+ }
170
+ case '$startsWith': {
171
+ return params[0].startsWith(params[1]);
172
+ }
173
+ case '$endsWith': {
174
+ return params[0].endsWith(params[1]);
175
+ }
176
+ case '$includes': {
177
+ return params[0].includes(params[1]);
178
+ }
179
+ case '$add': {
180
+ if (typeof params[0] === 'number') {
181
+ var result_1 = 0;
182
+ params.forEach(function (ele) { return result_1 += ele; });
183
+ return result_1;
184
+ }
185
+ else {
186
+ var result_2 = '';
187
+ params.forEach(function (ele) { return result_2 += ele; });
188
+ return result_2;
189
+ }
190
+ }
191
+ case '$subtract': {
192
+ return params[0] - params[1];
193
+ }
194
+ case '$multiply': {
195
+ var result_3 = 1;
196
+ params.forEach(function (ele) { return result_3 = result_3 * ele; });
197
+ return result_3;
198
+ }
199
+ case '$divide': {
200
+ return params[0] / params[1];
201
+ }
202
+ case '$abs': {
203
+ return Math.abs(params);
204
+ }
205
+ case '$round': {
206
+ return Math.round(params);
207
+ }
208
+ case '$ceil': {
209
+ return Math.ceil(params);
210
+ }
211
+ case '$floor': {
212
+ return Math.floor(params);
213
+ }
214
+ case '$round': {
215
+ return Math.round(params);
216
+ }
217
+ case '$pow': {
218
+ return Math.pow(params[0], params[1]);
219
+ }
220
+ case '$true': {
221
+ return !!params;
222
+ }
223
+ case '$false':
224
+ case '$not': {
225
+ return !params;
226
+ }
227
+ case '$and': {
228
+ try {
229
+ for (var params_1 = __values(params), params_1_1 = params_1.next(); !params_1_1.done; params_1_1 = params_1.next()) {
230
+ var p = params_1_1.value;
231
+ if (!p) {
232
+ return false;
233
+ }
234
+ }
235
+ }
236
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
237
+ finally {
238
+ try {
239
+ if (params_1_1 && !params_1_1.done && (_a = params_1.return)) _a.call(params_1);
240
+ }
241
+ finally { if (e_1) throw e_1.error; }
242
+ }
243
+ return true;
244
+ }
245
+ case '$or': {
246
+ try {
247
+ for (var params_2 = __values(params), params_2_1 = params_2.next(); !params_2_1.done; params_2_1 = params_2.next()) {
248
+ var p = params_2_1.value;
249
+ if (!!p) {
250
+ return true;
251
+ }
252
+ }
253
+ }
254
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
255
+ finally {
256
+ try {
257
+ if (params_2_1 && !params_2_1.done && (_b = params_2.return)) _b.call(params_2);
258
+ }
259
+ finally { if (e_2) throw e_2.error; }
260
+ }
261
+ return false;
262
+ }
263
+ case '$year': {
264
+ var value = (0, dayjs_1.default)(params);
265
+ return value.year();
266
+ }
267
+ case '$month': {
268
+ var value = (0, dayjs_1.default)(params);
269
+ return value.month();
270
+ }
271
+ case '$weekday': {
272
+ var value = (0, dayjs_1.default)(params);
273
+ return value.day(); // 0~6
274
+ }
275
+ case '$weekOfYear': {
276
+ var value = (0, dayjs_1.default)(params);
277
+ return value.week();
278
+ }
279
+ case '$day':
280
+ case '$dayOfMonth': {
281
+ var value = (0, dayjs_1.default)(params);
282
+ return value.date();
283
+ }
284
+ case '$dayOfWeek': {
285
+ var value = (0, dayjs_1.default)(params);
286
+ return value.day(); // 0~6
287
+ }
288
+ case '$dayOfYear': {
289
+ var value = (0, dayjs_1.default)(params);
290
+ return value.dayOfYear(); // 0~6
291
+ }
292
+ case '$dateDiff': {
293
+ var value1 = (0, dayjs_1.default)(params[0]);
294
+ var value2 = (0, dayjs_1.default)(params[1]);
295
+ switch (params[2]) {
296
+ case 'y':
297
+ case 'M':
298
+ case 'd':
299
+ case 'h':
300
+ case 'm':
301
+ case 's': {
302
+ return value1.diff(value2, params[2]);
303
+ }
304
+ default: {
305
+ (0, assert_1.default)(false);
306
+ }
307
+ }
308
+ }
309
+ case '$dateCeil': {
310
+ var value = (0, dayjs_1.default)(params[0]);
311
+ switch (params[1]) {
312
+ case 'y': {
313
+ return value.startOf('year').millisecond();
314
+ }
315
+ case 'M': {
316
+ return value.startOf('month').millisecond();
317
+ }
318
+ case 'd': {
319
+ return value.startOf('day').millisecond();
320
+ }
321
+ case 'h': {
322
+ return value.startOf('hour').millisecond();
323
+ }
324
+ case 'm': {
325
+ return value.startOf('minute').millisecond();
326
+ }
327
+ case 's': {
328
+ return value.startOf('second').millisecond();
329
+ }
330
+ default: {
331
+ (0, assert_1.default)(false);
332
+ }
333
+ }
334
+ }
335
+ case '$dateFloor': {
336
+ var value = (0, dayjs_1.default)(params[0]);
337
+ switch (params[1]) {
338
+ case 'y': {
339
+ return value.endOf('year').millisecond();
340
+ }
341
+ case 'M': {
342
+ return value.endOf('month').millisecond();
343
+ }
344
+ case 'd': {
345
+ return value.endOf('day').millisecond();
346
+ }
347
+ case 'h': {
348
+ return value.endOf('hour').millisecond();
349
+ }
350
+ case 'm': {
351
+ return value.endOf('minute').millisecond();
352
+ }
353
+ case 's': {
354
+ return value.endOf('second').millisecond();
355
+ }
356
+ default: {
357
+ (0, assert_1.default)(false);
358
+ }
359
+ }
360
+ }
361
+ case '$distance': {
362
+ var _c = __read(params, 2), geo1 = _c[0], geo2 = _c[1];
363
+ var type1 = geo1.type, coordinate1 = geo1.coordinate;
364
+ var type2 = geo2.type, coordinate2 = geo2.coordinate;
365
+ if (type1 !== 'point' || type2 !== 'point') {
366
+ throw new Error('目前只支持point类型的距离运算');
367
+ }
368
+ return (0, geo_1.getDistanceBetweenPoints)(coordinate1[1], coordinate1[0], coordinate2[1], coordinate2[0]);
369
+ }
370
+ case '$contains': {
371
+ throw new Error('$contains类型未实现');
372
+ }
373
+ default: {
374
+ (0, assert_1.default)(false, "\u4E0D\u80FD\u8BC6\u522B\u7684expression\u8FD0\u7B97\u7B26\uFF1A".concat(op));
375
+ }
376
+ }
377
+ }
378
+ exports.execOp = execOp;
@@ -0,0 +1,18 @@
1
+ export declare type Point = [number, number];
2
+ export declare type Path = Array<Point>;
3
+ export declare type Polygon = Array<Path>;
4
+ export declare type Circle = [Point, number];
5
+ export declare type SingleGeo = {
6
+ type: 'point';
7
+ coordinate: Point;
8
+ } | {
9
+ type: 'path';
10
+ coordinate: Path;
11
+ } | {
12
+ type: 'polygon';
13
+ coordinate: Polygon;
14
+ } | {
15
+ type: 'circle';
16
+ coordinate: Circle;
17
+ };
18
+ export declare type Geo = SingleGeo | SingleGeo[];