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.
- package/lib/OakError.d.ts +7 -0
- package/lib/OakError.js +29 -0
- package/lib/actions/action.d.ts +6 -0
- package/lib/actions/action.js +12 -0
- package/lib/actions/relation.d.ts +1 -0
- package/lib/actions/relation.js +2 -0
- package/lib/compiler/env.d.ts +10 -0
- package/lib/compiler/env.js +26 -0
- package/lib/compiler/schemalBuilder.d.ts +2 -0
- package/lib/compiler/schemalBuilder.js +2738 -0
- package/lib/compiler/uiBuilder.d.ts +1 -0
- package/lib/compiler/uiBuilder.js +3 -0
- package/lib/compiler/utils.d.ts +2 -0
- package/lib/compiler/utils.js +11 -0
- package/lib/store/CascadeStore.d.ts +38 -0
- package/lib/store/CascadeStore.js +681 -0
- package/lib/store/TriggerExecutor.d.ts +30 -0
- package/lib/store/TriggerExecutor.js +549 -0
- package/lib/store/UniversalContext.d.ts +26 -0
- package/lib/store/UniversalContext.js +208 -0
- package/lib/store/actionDef.d.ts +8 -0
- package/lib/store/actionDef.js +241 -0
- package/lib/store/filter.d.ts +36 -0
- package/lib/store/filter.js +121 -0
- package/lib/store/relation.d.ts +13 -0
- package/lib/store/relation.js +64 -0
- package/lib/store/watchers.d.ts +2 -0
- package/lib/store/watchers.js +32 -0
- package/lib/types/Action.d.ts +14 -0
- package/lib/types/Action.js +2 -0
- package/lib/types/AppLoader.d.ts +11 -0
- package/lib/types/AppLoader.js +10 -0
- package/lib/types/Aspect.d.ts +12 -0
- package/lib/types/Aspect.js +4 -0
- package/lib/types/Auth.d.ts +28 -0
- package/lib/types/Auth.js +2 -0
- package/lib/types/Connector.d.ts +26 -0
- package/lib/types/Connector.js +9 -0
- package/lib/types/Context.d.ts +14 -0
- package/lib/types/Context.js +3 -0
- package/lib/types/DataType.d.ts +17 -0
- package/lib/types/DataType.js +5 -0
- package/lib/types/Demand.d.ts +77 -0
- package/lib/types/Demand.js +9 -0
- package/lib/types/Entity.d.ts +138 -0
- package/lib/types/Entity.js +8 -0
- package/lib/types/Exception.d.ts +48 -0
- package/lib/types/Exception.js +178 -0
- package/lib/types/Expression.d.ts +132 -0
- package/lib/types/Expression.js +378 -0
- package/lib/types/Geo.d.ts +18 -0
- package/lib/types/Geo.js +2 -0
- package/lib/types/Locale.d.ts +24 -0
- package/lib/types/Locale.js +2 -0
- package/lib/types/Logger.d.ts +5 -0
- package/lib/types/Logger.js +3 -0
- package/lib/types/Polyfill.d.ts +23 -0
- package/lib/types/Polyfill.js +2 -0
- package/lib/types/RowStore.d.ts +22 -0
- package/lib/types/RowStore.js +33 -0
- package/lib/types/Storage.d.ts +48 -0
- package/lib/types/Storage.js +2 -0
- package/lib/types/Trigger.d.ts +105 -0
- package/lib/types/Trigger.js +24 -0
- package/lib/types/Txn.d.ts +2 -0
- package/lib/types/Txn.js +3 -0
- package/lib/types/Watcher.d.ts +19 -0
- package/lib/types/Watcher.js +4 -0
- package/lib/types/index.d.ts +18 -0
- package/lib/types/index.js +30 -0
- package/lib/types/schema/DataTypes.d.ts +32 -0
- package/lib/types/schema/DataTypes.js +3 -0
- package/lib/utils/SimpleConnector.d.ts +29 -0
- package/lib/utils/SimpleConnector.js +145 -0
- package/lib/utils/assert.d.ts +5 -0
- package/lib/utils/assert.js +11 -0
- package/lib/utils/concurrent.d.ts +15 -0
- package/lib/utils/concurrent.js +138 -0
- package/lib/utils/geo.d.ts +4 -0
- package/lib/utils/geo.js +24 -0
- package/lib/utils/lodash.d.ts +16 -0
- package/lib/utils/lodash.js +32 -0
- package/lib/utils/string.d.ts +2 -0
- package/lib/utils/string.js +11 -0
- package/lib/utils/uuid.d.ts +2 -0
- package/lib/utils/uuid.js +11 -0
- package/lib/utils/validator.d.ts +23 -0
- package/lib/utils/validator.js +123 -0
- package/package.json +38 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
+
};
|
|
52
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
+
exports.UniversalContext = void 0;
|
|
54
|
+
var assert_1 = __importDefault(require("assert"));
|
|
55
|
+
var concurrent_1 = require("../utils/concurrent");
|
|
56
|
+
var UniversalContext = /** @class */ (function () {
|
|
57
|
+
function UniversalContext(store) {
|
|
58
|
+
this.rowStore = store;
|
|
59
|
+
this.opRecords = [];
|
|
60
|
+
this.rwLock = new concurrent_1.RWLock();
|
|
61
|
+
this.events = {
|
|
62
|
+
commit: [],
|
|
63
|
+
rollback: [],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
UniversalContext.prototype.getScene = function () {
|
|
67
|
+
return this.scene;
|
|
68
|
+
};
|
|
69
|
+
UniversalContext.prototype.setScene = function (scene) {
|
|
70
|
+
this.scene = scene;
|
|
71
|
+
};
|
|
72
|
+
UniversalContext.prototype.resetEvents = function () {
|
|
73
|
+
this.events = {
|
|
74
|
+
commit: [],
|
|
75
|
+
rollback: [],
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
UniversalContext.prototype.on = function (event, callback) {
|
|
79
|
+
this.uuid && this.events[event].push(callback);
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* 一个context中不应该有并发的事务,这里将事务串行化,使用的时候千万要注意不要自己等自己
|
|
83
|
+
* @param options
|
|
84
|
+
*/
|
|
85
|
+
UniversalContext.prototype.begin = function (options) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
87
|
+
var _a;
|
|
88
|
+
return __generator(this, function (_b) {
|
|
89
|
+
switch (_b.label) {
|
|
90
|
+
case 0: return [4 /*yield*/, this.rwLock.acquire('X')];
|
|
91
|
+
case 1:
|
|
92
|
+
_b.sent();
|
|
93
|
+
if (!!this.uuid) return [3 /*break*/, 3];
|
|
94
|
+
_a = this;
|
|
95
|
+
return [4 /*yield*/, this.rowStore.begin(options)];
|
|
96
|
+
case 2:
|
|
97
|
+
_a.uuid = _b.sent();
|
|
98
|
+
return [3 /*break*/, 4];
|
|
99
|
+
case 3:
|
|
100
|
+
(0, assert_1.default)(false);
|
|
101
|
+
_b.label = 4;
|
|
102
|
+
case 4: return [2 /*return*/];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
UniversalContext.prototype.commit = function () {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
var _a, _b, e, e_1_1;
|
|
110
|
+
var e_1, _c;
|
|
111
|
+
return __generator(this, function (_d) {
|
|
112
|
+
switch (_d.label) {
|
|
113
|
+
case 0:
|
|
114
|
+
if (!this.uuid) return [3 /*break*/, 10];
|
|
115
|
+
return [4 /*yield*/, this.rowStore.commit(this.uuid)];
|
|
116
|
+
case 1:
|
|
117
|
+
_d.sent();
|
|
118
|
+
// console.log('commit', this.uuid);
|
|
119
|
+
this.uuid = undefined;
|
|
120
|
+
this.rwLock.release();
|
|
121
|
+
_d.label = 2;
|
|
122
|
+
case 2:
|
|
123
|
+
_d.trys.push([2, 7, 8, 9]);
|
|
124
|
+
_a = __values(this.events.commit), _b = _a.next();
|
|
125
|
+
_d.label = 3;
|
|
126
|
+
case 3:
|
|
127
|
+
if (!!_b.done) return [3 /*break*/, 6];
|
|
128
|
+
e = _b.value;
|
|
129
|
+
return [4 /*yield*/, e()];
|
|
130
|
+
case 4:
|
|
131
|
+
_d.sent();
|
|
132
|
+
_d.label = 5;
|
|
133
|
+
case 5:
|
|
134
|
+
_b = _a.next();
|
|
135
|
+
return [3 /*break*/, 3];
|
|
136
|
+
case 6: return [3 /*break*/, 9];
|
|
137
|
+
case 7:
|
|
138
|
+
e_1_1 = _d.sent();
|
|
139
|
+
e_1 = { error: e_1_1 };
|
|
140
|
+
return [3 /*break*/, 9];
|
|
141
|
+
case 8:
|
|
142
|
+
try {
|
|
143
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
144
|
+
}
|
|
145
|
+
finally { if (e_1) throw e_1.error; }
|
|
146
|
+
return [7 /*endfinally*/];
|
|
147
|
+
case 9:
|
|
148
|
+
this.resetEvents();
|
|
149
|
+
_d.label = 10;
|
|
150
|
+
case 10: return [2 /*return*/];
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
UniversalContext.prototype.rollback = function () {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
157
|
+
var _a, _b, e, e_2_1;
|
|
158
|
+
var e_2, _c;
|
|
159
|
+
return __generator(this, function (_d) {
|
|
160
|
+
switch (_d.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
if (!this.uuid) return [3 /*break*/, 10];
|
|
163
|
+
return [4 /*yield*/, this.rowStore.rollback(this.uuid)];
|
|
164
|
+
case 1:
|
|
165
|
+
_d.sent();
|
|
166
|
+
// console.log('rollback', this.uuid);
|
|
167
|
+
this.uuid = undefined;
|
|
168
|
+
this.rwLock.release();
|
|
169
|
+
_d.label = 2;
|
|
170
|
+
case 2:
|
|
171
|
+
_d.trys.push([2, 7, 8, 9]);
|
|
172
|
+
_a = __values(this.events.rollback), _b = _a.next();
|
|
173
|
+
_d.label = 3;
|
|
174
|
+
case 3:
|
|
175
|
+
if (!!_b.done) return [3 /*break*/, 6];
|
|
176
|
+
e = _b.value;
|
|
177
|
+
return [4 /*yield*/, e()];
|
|
178
|
+
case 4:
|
|
179
|
+
_d.sent();
|
|
180
|
+
_d.label = 5;
|
|
181
|
+
case 5:
|
|
182
|
+
_b = _a.next();
|
|
183
|
+
return [3 /*break*/, 3];
|
|
184
|
+
case 6: return [3 /*break*/, 9];
|
|
185
|
+
case 7:
|
|
186
|
+
e_2_1 = _d.sent();
|
|
187
|
+
e_2 = { error: e_2_1 };
|
|
188
|
+
return [3 /*break*/, 9];
|
|
189
|
+
case 8:
|
|
190
|
+
try {
|
|
191
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
192
|
+
}
|
|
193
|
+
finally { if (e_2) throw e_2.error; }
|
|
194
|
+
return [7 /*endfinally*/];
|
|
195
|
+
case 9:
|
|
196
|
+
this.resetEvents();
|
|
197
|
+
_d.label = 10;
|
|
198
|
+
case 10: return [2 /*return*/];
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
UniversalContext.prototype.getCurrentTxnId = function () {
|
|
204
|
+
return this.uuid;
|
|
205
|
+
};
|
|
206
|
+
return UniversalContext;
|
|
207
|
+
}());
|
|
208
|
+
exports.UniversalContext = UniversalContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ActionDictOfEntityDict, Checker, Context, DeduceFilter, EntityDict, StorageSchema, Trigger, Watcher } from "../types";
|
|
2
|
+
export declare function getFullProjection<ED extends EntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>): ED[T]["Selection"]["data"];
|
|
3
|
+
export declare function checkFilterContains<ED extends EntityDict, T extends keyof ED, Cxt extends Context<ED>>(entity: T, schema: StorageSchema<ED>, contained: DeduceFilter<ED[T]['Schema']>, context: Cxt, filter?: DeduceFilter<ED[T]['Schema']>): Promise<void>;
|
|
4
|
+
export declare function analyzeActionDefDict<ED extends EntityDict, Cxt extends Context<ED>>(schema: StorageSchema<ED>, actionDefDict: ActionDictOfEntityDict<ED>): {
|
|
5
|
+
triggers: Trigger<ED, keyof ED, Cxt>[];
|
|
6
|
+
checkers: Checker<ED, keyof ED, Cxt>[];
|
|
7
|
+
watchers: Watcher<ED, keyof ED, Context<ED>>[];
|
|
8
|
+
};
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.analyzeActionDefDict = exports.checkFilterContains = exports.getFullProjection = void 0;
|
|
40
|
+
var filter_1 = require("./filter");
|
|
41
|
+
var types_1 = require("../types");
|
|
42
|
+
function getFullProjection(entity, schema) {
|
|
43
|
+
var attributes = schema[entity].attributes;
|
|
44
|
+
var projection = {
|
|
45
|
+
id: 1,
|
|
46
|
+
$$createAt$$: 1,
|
|
47
|
+
$$updateAt$$: 1,
|
|
48
|
+
$$deleteAt$$: 1,
|
|
49
|
+
};
|
|
50
|
+
Object.keys(attributes).forEach(function (k) {
|
|
51
|
+
var _a;
|
|
52
|
+
return Object.assign(projection, (_a = {},
|
|
53
|
+
_a[k] = 1,
|
|
54
|
+
_a));
|
|
55
|
+
});
|
|
56
|
+
return projection;
|
|
57
|
+
}
|
|
58
|
+
exports.getFullProjection = getFullProjection;
|
|
59
|
+
function checkFilterContains(entity, schema, contained, context, filter) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var rowStore, filter2, result, data_1;
|
|
62
|
+
var _a;
|
|
63
|
+
return __generator(this, function (_b) {
|
|
64
|
+
switch (_b.label) {
|
|
65
|
+
case 0:
|
|
66
|
+
if (!filter) {
|
|
67
|
+
throw new types_1.OakRowInconsistencyException();
|
|
68
|
+
}
|
|
69
|
+
// 优先判断两个条件是否相容
|
|
70
|
+
if ((0, filter_1.contains)(entity, schema, filter, contained)) {
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
}
|
|
73
|
+
rowStore = context.rowStore;
|
|
74
|
+
filter2 = (0, filter_1.combineFilters)([filter, {
|
|
75
|
+
$not: contained,
|
|
76
|
+
}]);
|
|
77
|
+
return [4 /*yield*/, rowStore.select(entity, {
|
|
78
|
+
data: getFullProjection(entity, schema),
|
|
79
|
+
filter: filter2,
|
|
80
|
+
indexFrom: 0,
|
|
81
|
+
count: 10,
|
|
82
|
+
}, context)];
|
|
83
|
+
case 1:
|
|
84
|
+
result = (_b.sent()).result;
|
|
85
|
+
if (result.length > 0) {
|
|
86
|
+
data_1 = {};
|
|
87
|
+
result.forEach(function (ele) {
|
|
88
|
+
var _a;
|
|
89
|
+
return Object.assign(data_1, (_a = {},
|
|
90
|
+
_a[ele.id] = ele,
|
|
91
|
+
_a));
|
|
92
|
+
});
|
|
93
|
+
throw new types_1.OakRowInconsistencyException({
|
|
94
|
+
a: 's',
|
|
95
|
+
d: (_a = {},
|
|
96
|
+
_a[entity] = data_1,
|
|
97
|
+
_a)
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return [2 /*return*/];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
exports.checkFilterContains = checkFilterContains;
|
|
106
|
+
function makeIntrinsicWatchers(schema) {
|
|
107
|
+
var _this = this;
|
|
108
|
+
var watchers = [];
|
|
109
|
+
var _loop_1 = function (entity) {
|
|
110
|
+
var attributes = schema[entity].attributes;
|
|
111
|
+
var now = Date.now();
|
|
112
|
+
var expiresAt = attributes.expiresAt, expired = attributes.expired;
|
|
113
|
+
if (expiresAt && expiresAt.type === 'datetime' && expired && expired.type === 'boolean') {
|
|
114
|
+
// 如果有定义expiresAt和expired,则自动生成一个检查的watcher
|
|
115
|
+
watchers.push({
|
|
116
|
+
entity: entity,
|
|
117
|
+
name: "\u5BF9\u8C61".concat(entity, "\u4E0A\u7684\u8FC7\u671F\u81EA\u52A8watcher"),
|
|
118
|
+
filter: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
119
|
+
return __generator(this, function (_a) {
|
|
120
|
+
return [2 /*return*/, {
|
|
121
|
+
expired: false,
|
|
122
|
+
expiresAt: {
|
|
123
|
+
$lte: now,
|
|
124
|
+
},
|
|
125
|
+
}];
|
|
126
|
+
});
|
|
127
|
+
}); },
|
|
128
|
+
action: 'update',
|
|
129
|
+
actionData: {
|
|
130
|
+
expired: true,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
for (var entity in schema) {
|
|
136
|
+
_loop_1(entity);
|
|
137
|
+
}
|
|
138
|
+
return watchers;
|
|
139
|
+
}
|
|
140
|
+
function analyzeActionDefDict(schema, actionDefDict) {
|
|
141
|
+
var _this = this;
|
|
142
|
+
var checkers = [];
|
|
143
|
+
var triggers = [];
|
|
144
|
+
var _loop_2 = function (entity) {
|
|
145
|
+
var _loop_3 = function (attr) {
|
|
146
|
+
var def = actionDefDict[entity][attr];
|
|
147
|
+
var _a = def, stm = _a.stm, is = _a.is;
|
|
148
|
+
var _loop_4 = function (action) {
|
|
149
|
+
var actionStm = stm[action];
|
|
150
|
+
checkers.push({
|
|
151
|
+
action: action,
|
|
152
|
+
type: 'row',
|
|
153
|
+
entity: entity,
|
|
154
|
+
checker: function (_a, context) {
|
|
155
|
+
var operation = _a.operation;
|
|
156
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
157
|
+
var filter, conditionalFilter;
|
|
158
|
+
var _b, _c;
|
|
159
|
+
return __generator(this, function (_d) {
|
|
160
|
+
switch (_d.label) {
|
|
161
|
+
case 0:
|
|
162
|
+
filter = operation.filter;
|
|
163
|
+
conditionalFilter = typeof actionStm[0] === 'string' ? (_b = {},
|
|
164
|
+
_b[attr] = actionStm[0],
|
|
165
|
+
_b) : (_c = {},
|
|
166
|
+
_c[attr] = {
|
|
167
|
+
$in: actionStm[0],
|
|
168
|
+
},
|
|
169
|
+
_c);
|
|
170
|
+
return [4 /*yield*/, checkFilterContains(entity, schema, conditionalFilter, context, filter)];
|
|
171
|
+
case 1:
|
|
172
|
+
_d.sent();
|
|
173
|
+
return [2 /*return*/, 0];
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
triggers.push({
|
|
180
|
+
name: "set next state of ".concat(attr, " for ").concat(entity, " on action ").concat(action),
|
|
181
|
+
action: action,
|
|
182
|
+
entity: entity,
|
|
183
|
+
when: 'before',
|
|
184
|
+
fn: function (_a) {
|
|
185
|
+
var operation = _a.operation;
|
|
186
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
187
|
+
var _b, data;
|
|
188
|
+
var _c;
|
|
189
|
+
return __generator(this, function (_d) {
|
|
190
|
+
_b = operation.data, data = _b === void 0 ? {} : _b;
|
|
191
|
+
Object.assign(operation, {
|
|
192
|
+
data: Object.assign(data, (_c = {},
|
|
193
|
+
_c[attr] = stm[action][1],
|
|
194
|
+
_c)),
|
|
195
|
+
});
|
|
196
|
+
return [2 /*return*/, 1];
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
for (var action in stm) {
|
|
203
|
+
_loop_4(action);
|
|
204
|
+
}
|
|
205
|
+
if (is) {
|
|
206
|
+
triggers.push({
|
|
207
|
+
name: "set initial state of ".concat(attr, " for ").concat(entity, " on create"),
|
|
208
|
+
action: 'create',
|
|
209
|
+
entity: entity,
|
|
210
|
+
when: 'before',
|
|
211
|
+
fn: function (_a) {
|
|
212
|
+
var operation = _a.operation;
|
|
213
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
214
|
+
var data;
|
|
215
|
+
var _b;
|
|
216
|
+
return __generator(this, function (_c) {
|
|
217
|
+
data = operation.data;
|
|
218
|
+
Object.assign(data, (_b = {},
|
|
219
|
+
_b[attr] = is,
|
|
220
|
+
_b));
|
|
221
|
+
return [2 /*return*/, 1];
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
for (var attr in actionDefDict[entity]) {
|
|
229
|
+
_loop_3(attr);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
for (var entity in actionDefDict) {
|
|
233
|
+
_loop_2(entity);
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
triggers: triggers,
|
|
237
|
+
checkers: checkers,
|
|
238
|
+
watchers: makeIntrinsicWatchers(schema),
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
exports.analyzeActionDefDict = analyzeActionDefDict;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StorageSchema } from '../types';
|
|
2
|
+
import { EntityDict } from "../types/Entity";
|
|
3
|
+
export declare function addFilterSegment<ED extends EntityDict, T extends keyof ED>(...filters: ED[T]['Selection']['filter'][]): ED[T]["Selection"]["filter"];
|
|
4
|
+
export declare function combineFilters<ED extends EntityDict, T extends keyof ED>(filters: Array<ED[T]['Selection']['filter']>): ED[T]["Selection"]["filter"];
|
|
5
|
+
/**
|
|
6
|
+
* 判断filter是否包含conditionalFilter中的查询条件,即filter查询的结果一定满足conditionalFilter的约束
|
|
7
|
+
* filter = {
|
|
8
|
+
* a: 1
|
|
9
|
+
* b: 2,
|
|
10
|
+
* c: 3,
|
|
11
|
+
* },
|
|
12
|
+
* conditionalFilter = {
|
|
13
|
+
* a: 1
|
|
14
|
+
* }
|
|
15
|
+
* 则包含
|
|
16
|
+
* @param entity
|
|
17
|
+
* @param schema
|
|
18
|
+
* @param filter
|
|
19
|
+
* @param conditionalFilter
|
|
20
|
+
*/
|
|
21
|
+
export declare function contains<ED extends EntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filter: ED[T]['Selection']['filter'], conditionalFilter: ED[T]['Selection']['filter']): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* 判断filter1和filter2是否相斥,即filter1和filter2查询的结果一定没有交集
|
|
24
|
+
* filter1 = {
|
|
25
|
+
* a: 2
|
|
26
|
+
* },
|
|
27
|
+
* filter2 = {
|
|
28
|
+
* a: 1
|
|
29
|
+
* }
|
|
30
|
+
* 则包含
|
|
31
|
+
* @param entity
|
|
32
|
+
* @param schema
|
|
33
|
+
* @param filter
|
|
34
|
+
* @param conditionalFilter
|
|
35
|
+
*/
|
|
36
|
+
export declare function repel<ED extends EntityDict, T extends keyof ED>(entity: T, schema: StorageSchema<ED>, filter1: ED[T]['Selection']['filter'], filter2: ED[T]['Selection']['filter']): boolean;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.repel = exports.contains = exports.combineFilters = exports.addFilterSegment = void 0;
|
|
29
|
+
function addFilterSegment() {
|
|
30
|
+
var filters = [];
|
|
31
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
32
|
+
filters[_i] = arguments[_i];
|
|
33
|
+
}
|
|
34
|
+
var filter = {};
|
|
35
|
+
filters.forEach(function (ele) {
|
|
36
|
+
var _a, _b, _c, _d;
|
|
37
|
+
if (ele) {
|
|
38
|
+
for (var k in ele) {
|
|
39
|
+
if (k === '$and') {
|
|
40
|
+
if (filter.$and) {
|
|
41
|
+
(_a = filter.$and).push.apply(_a, __spreadArray([], __read(ele[k]), false));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
filter.$and = ele[k];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (k === '$or') {
|
|
48
|
+
if (filter.$or) {
|
|
49
|
+
(_b = filter.$or).push.apply(_b, __spreadArray([], __read(ele[k]), false));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
filter.$or = ele[k];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (filter.hasOwnProperty(k)) {
|
|
56
|
+
if (filter.$and) {
|
|
57
|
+
filter.$and.push((_c = {},
|
|
58
|
+
_c[k] = ele[k],
|
|
59
|
+
_c));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
filter.$and = [
|
|
63
|
+
(_d = {},
|
|
64
|
+
_d[k] = ele[k],
|
|
65
|
+
_d)
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
filter[k] = ele[k];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return filter;
|
|
76
|
+
}
|
|
77
|
+
exports.addFilterSegment = addFilterSegment;
|
|
78
|
+
function combineFilters(filters) {
|
|
79
|
+
return addFilterSegment.apply(void 0, __spreadArray([], __read(filters), false));
|
|
80
|
+
}
|
|
81
|
+
exports.combineFilters = combineFilters;
|
|
82
|
+
/**
|
|
83
|
+
* 判断filter是否包含conditionalFilter中的查询条件,即filter查询的结果一定满足conditionalFilter的约束
|
|
84
|
+
* filter = {
|
|
85
|
+
* a: 1
|
|
86
|
+
* b: 2,
|
|
87
|
+
* c: 3,
|
|
88
|
+
* },
|
|
89
|
+
* conditionalFilter = {
|
|
90
|
+
* a: 1
|
|
91
|
+
* }
|
|
92
|
+
* 则包含
|
|
93
|
+
* @param entity
|
|
94
|
+
* @param schema
|
|
95
|
+
* @param filter
|
|
96
|
+
* @param conditionalFilter
|
|
97
|
+
*/
|
|
98
|
+
function contains(entity, schema, filter, conditionalFilter) {
|
|
99
|
+
// todo
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
exports.contains = contains;
|
|
103
|
+
/**
|
|
104
|
+
* 判断filter1和filter2是否相斥,即filter1和filter2查询的结果一定没有交集
|
|
105
|
+
* filter1 = {
|
|
106
|
+
* a: 2
|
|
107
|
+
* },
|
|
108
|
+
* filter2 = {
|
|
109
|
+
* a: 1
|
|
110
|
+
* }
|
|
111
|
+
* 则包含
|
|
112
|
+
* @param entity
|
|
113
|
+
* @param schema
|
|
114
|
+
* @param filter
|
|
115
|
+
* @param conditionalFilter
|
|
116
|
+
*/
|
|
117
|
+
function repel(entity, schema, filter1, filter2) {
|
|
118
|
+
// todo
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
exports.repel = repel;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EntityDef } from "../types/Entity";
|
|
2
|
+
import { StorageSchema } from "../types/Storage";
|
|
3
|
+
/**
|
|
4
|
+
* 判断对象和属性之间的关系
|
|
5
|
+
* @param schema
|
|
6
|
+
* @param entity
|
|
7
|
+
* @param attr
|
|
8
|
+
* @param row
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function judgeRelation<ED extends {
|
|
12
|
+
[E: string]: EntityDef;
|
|
13
|
+
}>(schema: StorageSchema<ED>, entity: keyof ED, attr: string): string | string[] | 1 | 0 | 2;
|