@proteinjs/db 1.55.1 → 1.57.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/CHANGELOG.md +22 -0
- package/dist/generated/index.js +1 -1
- package/dist/generated/index.js.map +1 -1
- package/dist/generated/test/index.d.ts.map +1 -1
- package/dist/generated/test/index.js +5 -1
- package/dist/generated/test/index.js.map +1 -1
- package/dist/src/Db.d.ts +22 -6
- package/dist/src/Db.d.ts.map +1 -1
- package/dist/src/Db.js +35 -15
- package/dist/src/Db.js.map +1 -1
- package/dist/src/TableWatcher.d.ts +15 -6
- package/dist/src/TableWatcher.d.ts.map +1 -1
- package/dist/src/TableWatcher.js.map +1 -1
- package/dist/src/TableWatcherRunner.d.ts +14 -6
- package/dist/src/TableWatcherRunner.d.ts.map +1 -1
- package/dist/src/TableWatcherRunner.js +19 -12
- package/dist/src/TableWatcherRunner.js.map +1 -1
- package/dist/test/DbIsSystem.test.d.ts +2 -0
- package/dist/test/DbIsSystem.test.d.ts.map +1 -0
- package/dist/test/DbIsSystem.test.js +280 -0
- package/dist/test/DbIsSystem.test.js.map +1 -0
- package/dist/test/index.d.ts +2 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +2 -0
- package/dist/test/index.js.map +1 -1
- package/dist/test/reusable/TableWatcherAuthorityTests.d.ts +13 -0
- package/dist/test/reusable/TableWatcherAuthorityTests.d.ts.map +1 -0
- package/dist/test/reusable/TableWatcherAuthorityTests.js +392 -0
- package/dist/test/reusable/TableWatcherAuthorityTests.js.map +1 -0
- package/dist/test/util/DbTestEnvironment.d.ts.map +1 -1
- package/dist/test/util/DbTestEnvironment.js +3 -2
- package/dist/test/util/DbTestEnvironment.js.map +1 -1
- package/dist/test/util/tables/tableWatcherAuthorityTestTables.d.ts +35 -0
- package/dist/test/util/tables/tableWatcherAuthorityTestTables.d.ts.map +1 -0
- package/dist/test/util/tables/tableWatcherAuthorityTestTables.js +113 -0
- package/dist/test/util/tables/tableWatcherAuthorityTestTables.js.map +1 -0
- package/generated/index.ts +1 -1
- package/generated/test/index.ts +5 -1
- package/package.json +2 -2
- package/src/Db.ts +50 -21
- package/src/TableWatcher.ts +17 -6
- package/src/TableWatcherRunner.ts +25 -12
- package/test/DbIsSystem.test.ts +173 -0
- package/test/index.ts +2 -0
- package/test/reusable/TableWatcherAuthorityTests.ts +204 -0
- package/test/util/DbTestEnvironment.ts +2 -0
- package/test/util/tables/tableWatcherAuthorityTestTables.ts +61 -0
|
@@ -0,0 +1,392 @@
|
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.tableWatcherAuthorityTests = exports.HOOK_HANDED_NO_DB = void 0;
|
|
49
|
+
var db_1 = require("@proteinjs/db");
|
|
50
|
+
var reflection_1 = require("@proteinjs/reflection");
|
|
51
|
+
var DbTestEnvironment_1 = require("../util/DbTestEnvironment");
|
|
52
|
+
var TableWatcherRunner_1 = require("../../src/TableWatcherRunner");
|
|
53
|
+
var tableWatcherAuthorityTestTables_1 = require("../util/tables/tableWatcherAuthorityTestTables");
|
|
54
|
+
var objectCache = function () { return reflection_1.SourceRepository.get().objectCache; };
|
|
55
|
+
var resetTableWatcherMap = function () {
|
|
56
|
+
TableWatcherRunner_1.TableWatcherRunner.tableWatcherMap = undefined;
|
|
57
|
+
};
|
|
58
|
+
/** The watcher's refusal when a hook arrives without the write's Db — the contract's first half. */
|
|
59
|
+
exports.HOOK_HANDED_NO_DB = 'the hook was handed no Db';
|
|
60
|
+
var HOOKS = ['beforeInsert', 'afterInsert', 'beforeUpdate', 'afterUpdate', 'beforeDelete', 'afterDelete'];
|
|
61
|
+
/**
|
|
62
|
+
* Journals every hook run through the HANDED Db and nothing else — the way a watcher is written
|
|
63
|
+
* once the Db hands one (chat's topic watcher deleting a deleted message's topic links, the media
|
|
64
|
+
* watcher deleting a deleted row's file, the activity watcher bumping the chat a message landed
|
|
65
|
+
* in). The journal is a guarded table, so the hook's write and read succeed only with a system
|
|
66
|
+
* Db: the one the write made, carrying its own authority.
|
|
67
|
+
*/
|
|
68
|
+
var JournalingWatcher = /** @class */ (function () {
|
|
69
|
+
function JournalingWatcher() {
|
|
70
|
+
}
|
|
71
|
+
JournalingWatcher.prototype.name = function () {
|
|
72
|
+
return 'JournalingWatcher';
|
|
73
|
+
};
|
|
74
|
+
JournalingWatcher.prototype.table = function () {
|
|
75
|
+
return tableWatcherAuthorityTestTables_1.tableWatcherAuthorityTestTables.WatchedNote;
|
|
76
|
+
};
|
|
77
|
+
JournalingWatcher.prototype.beforeInsert = function (record, db) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0: return [4 /*yield*/, this.journal(db, record.id, 'beforeInsert')];
|
|
82
|
+
case 1:
|
|
83
|
+
_a.sent();
|
|
84
|
+
return [2 /*return*/, record];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
JournalingWatcher.prototype.afterInsert = function (record, db) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0: return [4 /*yield*/, this.journal(db, record.id, 'afterInsert')];
|
|
94
|
+
case 1:
|
|
95
|
+
_a.sent();
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
JournalingWatcher.prototype.beforeUpdate = function (record, qb, db) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
103
|
+
var _i, _a, row;
|
|
104
|
+
return __generator(this, function (_b) {
|
|
105
|
+
switch (_b.label) {
|
|
106
|
+
case 0:
|
|
107
|
+
_i = 0;
|
|
108
|
+
return [4 /*yield*/, this.handed(db).query(this.table(), qb)];
|
|
109
|
+
case 1:
|
|
110
|
+
_a = _b.sent();
|
|
111
|
+
_b.label = 2;
|
|
112
|
+
case 2:
|
|
113
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
114
|
+
row = _a[_i];
|
|
115
|
+
return [4 /*yield*/, this.journal(db, row.id, 'beforeUpdate')];
|
|
116
|
+
case 3:
|
|
117
|
+
_b.sent();
|
|
118
|
+
_b.label = 4;
|
|
119
|
+
case 4:
|
|
120
|
+
_i++;
|
|
121
|
+
return [3 /*break*/, 2];
|
|
122
|
+
case 5: return [2 /*return*/, record];
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
JournalingWatcher.prototype.afterUpdate = function (recordUpdateCount, record, qb, db) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
129
|
+
var _i, _a, row;
|
|
130
|
+
return __generator(this, function (_b) {
|
|
131
|
+
switch (_b.label) {
|
|
132
|
+
case 0:
|
|
133
|
+
_i = 0;
|
|
134
|
+
return [4 /*yield*/, this.handed(db).query(this.table(), qb)];
|
|
135
|
+
case 1:
|
|
136
|
+
_a = _b.sent();
|
|
137
|
+
_b.label = 2;
|
|
138
|
+
case 2:
|
|
139
|
+
if (!(_i < _a.length)) return [3 /*break*/, 5];
|
|
140
|
+
row = _a[_i];
|
|
141
|
+
return [4 /*yield*/, this.journal(db, row.id, 'afterUpdate')];
|
|
142
|
+
case 3:
|
|
143
|
+
_b.sent();
|
|
144
|
+
_b.label = 4;
|
|
145
|
+
case 4:
|
|
146
|
+
_i++;
|
|
147
|
+
return [3 /*break*/, 2];
|
|
148
|
+
case 5: return [2 /*return*/];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
JournalingWatcher.prototype.beforeDelete = function (recordsToDelete, _initialQb, _deleteQb, db) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
155
|
+
var _i, recordsToDelete_1, row;
|
|
156
|
+
return __generator(this, function (_a) {
|
|
157
|
+
switch (_a.label) {
|
|
158
|
+
case 0:
|
|
159
|
+
_i = 0, recordsToDelete_1 = recordsToDelete;
|
|
160
|
+
_a.label = 1;
|
|
161
|
+
case 1:
|
|
162
|
+
if (!(_i < recordsToDelete_1.length)) return [3 /*break*/, 4];
|
|
163
|
+
row = recordsToDelete_1[_i];
|
|
164
|
+
return [4 /*yield*/, this.journal(db, row.id, 'beforeDelete')];
|
|
165
|
+
case 2:
|
|
166
|
+
_a.sent();
|
|
167
|
+
_a.label = 3;
|
|
168
|
+
case 3:
|
|
169
|
+
_i++;
|
|
170
|
+
return [3 /*break*/, 1];
|
|
171
|
+
case 4: return [2 /*return*/];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
JournalingWatcher.prototype.afterDelete = function (_recordDeleteCount, deletedRecords, _initialQb, _deleteQb, db) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
+
var _i, deletedRecords_1, row;
|
|
179
|
+
return __generator(this, function (_a) {
|
|
180
|
+
switch (_a.label) {
|
|
181
|
+
case 0:
|
|
182
|
+
_i = 0, deletedRecords_1 = deletedRecords;
|
|
183
|
+
_a.label = 1;
|
|
184
|
+
case 1:
|
|
185
|
+
if (!(_i < deletedRecords_1.length)) return [3 /*break*/, 5];
|
|
186
|
+
row = deletedRecords_1[_i];
|
|
187
|
+
return [4 /*yield*/, this.journal(db, row.id, 'afterDelete')];
|
|
188
|
+
case 2:
|
|
189
|
+
_a.sent();
|
|
190
|
+
// The read half of the contract: a query through the handed Db over the guarded table.
|
|
191
|
+
return [4 /*yield*/, this.handed(db).query(tableWatcherAuthorityTestTables_1.tableWatcherAuthorityTestTables.GuardedJournal, { note: row.id })];
|
|
192
|
+
case 3:
|
|
193
|
+
// The read half of the contract: a query through the handed Db over the guarded table.
|
|
194
|
+
_a.sent();
|
|
195
|
+
_a.label = 4;
|
|
196
|
+
case 4:
|
|
197
|
+
_i++;
|
|
198
|
+
return [3 /*break*/, 1];
|
|
199
|
+
case 5: return [2 /*return*/];
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
JournalingWatcher.prototype.journal = function (db, note, hook) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
206
|
+
return __generator(this, function (_a) {
|
|
207
|
+
switch (_a.label) {
|
|
208
|
+
case 0: return [4 /*yield*/, this.handed(db).insert(tableWatcherAuthorityTestTables_1.tableWatcherAuthorityTestTables.GuardedJournal, {
|
|
209
|
+
note: note,
|
|
210
|
+
hook: hook,
|
|
211
|
+
principal: 'the write',
|
|
212
|
+
})];
|
|
213
|
+
case 1:
|
|
214
|
+
_a.sent();
|
|
215
|
+
return [2 /*return*/];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
JournalingWatcher.prototype.handed = function (db) {
|
|
221
|
+
if (!db) {
|
|
222
|
+
throw new Error(exports.HOOK_HANDED_NO_DB);
|
|
223
|
+
}
|
|
224
|
+
return db;
|
|
225
|
+
};
|
|
226
|
+
return JournalingWatcher;
|
|
227
|
+
}());
|
|
228
|
+
/**
|
|
229
|
+
* A table watcher's hooks run with the authority of the write that fired them: the Db hands every
|
|
230
|
+
* hook a Db carrying its driver, tables, transaction context and system mode. Before this the
|
|
231
|
+
* hooks were handed nothing and each watcher opened a session-scoped Db of its own, which a system
|
|
232
|
+
* write in a session-less context (an account purge, a sweep) could not use — the topic links of a
|
|
233
|
+
* purged message and the file of a system-deleted media row stayed behind, and the activity bump
|
|
234
|
+
* of a system-inserted message threw.
|
|
235
|
+
*/
|
|
236
|
+
var tableWatcherAuthorityTests = function (driver, transactionContextFactory, dropTable) {
|
|
237
|
+
return function () {
|
|
238
|
+
var testEnv = new DbTestEnvironment_1.DbTestEnvironment(driver, dropTable);
|
|
239
|
+
var notes = tableWatcherAuthorityTestTables_1.tableWatcherAuthorityTestTables.WatchedNote;
|
|
240
|
+
var journal = tableWatcherAuthorityTestTables_1.tableWatcherAuthorityTestTables.GuardedJournal;
|
|
241
|
+
// Constructed in beforeAll, AFTER the watcher registration below: a Db's construction builds
|
|
242
|
+
// the runner's static watcher map, and the map must be built from the registered watcher.
|
|
243
|
+
var systemDb;
|
|
244
|
+
var sessionDb;
|
|
245
|
+
var originalWatchers;
|
|
246
|
+
/** A fresh async hop — the shape of a background context that inherits no caller's state. */
|
|
247
|
+
var inFreshContext = function (fn) {
|
|
248
|
+
return new Promise(function (resolve, reject) {
|
|
249
|
+
setImmediate(function () {
|
|
250
|
+
fn().then(resolve, reject);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
var journalHooksFor = function (noteId) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
255
|
+
switch (_a.label) {
|
|
256
|
+
case 0: return [4 /*yield*/, systemDb.query(journal, { note: noteId })];
|
|
257
|
+
case 1: return [2 /*return*/, (_a.sent()).map(function (row) { return row.hook; }).sort()];
|
|
258
|
+
}
|
|
259
|
+
}); }); };
|
|
260
|
+
beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
261
|
+
return __generator(this, function (_a) {
|
|
262
|
+
switch (_a.label) {
|
|
263
|
+
case 0:
|
|
264
|
+
originalWatchers = objectCache()['@proteinjs/db/TableWatcher'];
|
|
265
|
+
objectCache()['@proteinjs/db/TableWatcher'] = [new JournalingWatcher()];
|
|
266
|
+
resetTableWatcherMap();
|
|
267
|
+
systemDb = new db_1.Db(driver, undefined, transactionContextFactory, true);
|
|
268
|
+
sessionDb = new db_1.Db(driver, undefined, transactionContextFactory);
|
|
269
|
+
return [4 /*yield*/, testEnv.beforeAll()];
|
|
270
|
+
case 1:
|
|
271
|
+
_a.sent();
|
|
272
|
+
return [2 /*return*/];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}); }, 120000);
|
|
276
|
+
afterAll(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
277
|
+
return __generator(this, function (_a) {
|
|
278
|
+
switch (_a.label) {
|
|
279
|
+
case 0: return [4 /*yield*/, testEnv.afterAll()];
|
|
280
|
+
case 1:
|
|
281
|
+
_a.sent();
|
|
282
|
+
if (originalWatchers) {
|
|
283
|
+
objectCache()['@proteinjs/db/TableWatcher'] = originalWatchers;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
delete objectCache()['@proteinjs/db/TableWatcher'];
|
|
287
|
+
}
|
|
288
|
+
resetTableWatcherMap();
|
|
289
|
+
return [2 /*return*/];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}); }, 120000);
|
|
293
|
+
beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
294
|
+
return __generator(this, function (_a) {
|
|
295
|
+
switch (_a.label) {
|
|
296
|
+
case 0: return [4 /*yield*/, systemDb.delete(journal, {})];
|
|
297
|
+
case 1:
|
|
298
|
+
_a.sent();
|
|
299
|
+
return [4 /*yield*/, systemDb.delete(notes, {})];
|
|
300
|
+
case 2:
|
|
301
|
+
_a.sent();
|
|
302
|
+
return [2 /*return*/];
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}); });
|
|
306
|
+
describe('Table watchers carry the write’s authority', function () {
|
|
307
|
+
test('a system insert, update and delete in a session-less context: all six hooks write and read the guarded journal through the handed Db', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
308
|
+
var noteId, _a, _b;
|
|
309
|
+
return __generator(this, function (_c) {
|
|
310
|
+
switch (_c.label) {
|
|
311
|
+
case 0: return [4 /*yield*/, inFreshContext(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
312
|
+
var note;
|
|
313
|
+
return __generator(this, function (_a) {
|
|
314
|
+
switch (_a.label) {
|
|
315
|
+
case 0: return [4 /*yield*/, systemDb.insert(notes, { title: 'Kept' })];
|
|
316
|
+
case 1:
|
|
317
|
+
note = _a.sent();
|
|
318
|
+
return [4 /*yield*/, systemDb.update(notes, { title: 'Kept, renamed' }, { id: note.id })];
|
|
319
|
+
case 2:
|
|
320
|
+
_a.sent();
|
|
321
|
+
return [4 /*yield*/, systemDb.delete(notes, { id: note.id })];
|
|
322
|
+
case 3:
|
|
323
|
+
_a.sent();
|
|
324
|
+
return [2 /*return*/, note.id];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
}); })];
|
|
328
|
+
case 1:
|
|
329
|
+
noteId = _c.sent();
|
|
330
|
+
_a = expect;
|
|
331
|
+
return [4 /*yield*/, systemDb.query(notes, { id: noteId })];
|
|
332
|
+
case 2:
|
|
333
|
+
_a.apply(void 0, [_c.sent()]).toHaveLength(0);
|
|
334
|
+
_b = expect;
|
|
335
|
+
return [4 /*yield*/, journalHooksFor(noteId)];
|
|
336
|
+
case 3:
|
|
337
|
+
_b.apply(void 0, [_c.sent()]).toEqual(__spreadArray([], HOOKS, true).sort());
|
|
338
|
+
return [2 /*return*/];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}); });
|
|
342
|
+
test('a session write’s hooks run as the session, never as system: the guarded journal refuses the first hook and the write with it', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
343
|
+
var _a;
|
|
344
|
+
return __generator(this, function (_b) {
|
|
345
|
+
switch (_b.label) {
|
|
346
|
+
case 0: return [4 /*yield*/, expect(sessionDb.insert(notes, { title: 'Refused' })).rejects.toThrow(tableWatcherAuthorityTestTables_1.WATCHER_GUARDED_REFUSAL)];
|
|
347
|
+
case 1:
|
|
348
|
+
_b.sent();
|
|
349
|
+
_a = expect;
|
|
350
|
+
return [4 /*yield*/, systemDb.query(notes, { title: 'Refused' })];
|
|
351
|
+
case 2:
|
|
352
|
+
_a.apply(void 0, [_b.sent()]).toHaveLength(0);
|
|
353
|
+
return [2 /*return*/];
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}); });
|
|
357
|
+
test('the handed Db rides the write’s transaction: a rolled-back system insert leaves no journal row', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
358
|
+
var noteId, _a, _b;
|
|
359
|
+
return __generator(this, function (_c) {
|
|
360
|
+
switch (_c.label) {
|
|
361
|
+
case 0: return [4 /*yield*/, expect(systemDb.runTransaction(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
362
|
+
var note;
|
|
363
|
+
return __generator(this, function (_a) {
|
|
364
|
+
switch (_a.label) {
|
|
365
|
+
case 0: return [4 /*yield*/, systemDb.insert(notes, { title: 'Rolled back' })];
|
|
366
|
+
case 1:
|
|
367
|
+
note = _a.sent();
|
|
368
|
+
noteId = note.id;
|
|
369
|
+
throw new Error('roll back');
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}); })).rejects.toThrow('roll back')];
|
|
373
|
+
case 1:
|
|
374
|
+
_c.sent();
|
|
375
|
+
expect(noteId).toBeDefined();
|
|
376
|
+
_a = expect;
|
|
377
|
+
return [4 /*yield*/, systemDb.query(notes, { id: noteId })];
|
|
378
|
+
case 2:
|
|
379
|
+
_a.apply(void 0, [_c.sent()]).toHaveLength(0);
|
|
380
|
+
_b = expect;
|
|
381
|
+
return [4 /*yield*/, journalHooksFor(noteId)];
|
|
382
|
+
case 3:
|
|
383
|
+
_b.apply(void 0, [_c.sent()]).toEqual([]);
|
|
384
|
+
return [2 /*return*/];
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
}); });
|
|
388
|
+
});
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
exports.tableWatcherAuthorityTests = tableWatcherAuthorityTests;
|
|
392
|
+
//# sourceMappingURL=TableWatcherAuthorityTests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableWatcherAuthorityTests.js","sourceRoot":"","sources":["../../../test/reusable/TableWatcherAuthorityTests.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAoG;AAEpG,oDAAyD;AACzD,+DAA8D;AAC9D,mEAAkE;AAClE,kGAKwD;AAIxD,IAAM,WAAW,GAAG,cAAM,OAAC,6BAAgB,CAAC,GAAG,EAA2C,CAAC,WAAW,EAA5E,CAA4E,CAAC;AACvG,IAAM,oBAAoB,GAAG;IAC1B,uCAA2D,CAAC,eAAe,GAAG,SAAS,CAAC;AAC3F,CAAC,CAAC;AAEF,oGAAoG;AACvF,QAAA,iBAAiB,GAAG,2BAA2B,CAAC;AAE7D,IAAM,KAAK,GAAG,CAAC,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,CAAC,CAAC;AAE5G;;;;;;GAMG;AACH;IAAA;IA8EA,CAAC;IA7EC,gCAAI,GAAJ;QACE,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,iCAAK,GAAL;QACE,OAAO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C,WAAW,CAAC,CAAC;;;iCAC9B,CAAC,CACH,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAA;;4BAN9B,SAM8B,CAAC;4BAE/B,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;4BAC7B,KAAA,MAAM,CAAA;4BAAC,qBAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAA;;4BAAlD,kBAAO,SAA2C,EAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;4BACpE,KAAA,MAAM,CAAA;4BAAC,qBAAM,eAAe,CAAC,MAAO,CAAC,EAAA;;4BAArC,kBAAO,SAA8B,EAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;;;;iBACpD,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AApFW,QAAA,0BAA0B,8BAoFrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DbTestEnvironment.d.ts","sourceRoot":"","sources":["../../../test/util/DbTestEnvironment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"DbTestEnvironment.d.ts","sourceRoot":"","sources":["../../../test/util/DbTestEnvironment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AA2BhD;;GAEG;AACH,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,aAAa;gBADb,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC;IAGvD,SAAS;IAaT,QAAQ;CAUf"}
|
|
@@ -55,11 +55,12 @@ var recordIteratorTestTables_1 = require("./tables/recordIteratorTestTables");
|
|
|
55
55
|
var sourceRecordSyncTestTables_1 = require("./tables/sourceRecordSyncTestTables");
|
|
56
56
|
var storedValueContractTestTables_1 = require("./tables/storedValueContractTestTables");
|
|
57
57
|
var tableManagerTestTables_1 = require("./tables/tableManagerTestTables");
|
|
58
|
+
var tableWatcherAuthorityTestTables_1 = require("./tables/tableWatcherAuthorityTestTables");
|
|
58
59
|
var transactionTestTables_1 = require("./tables/transactionTestTables");
|
|
59
|
-
var TABLES = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], Object.values(cascadeDeleteTestTables_1.cascadeDeleteTestTables), true), Object.values(columnTypesTestTables_1.columnTypesTestTables), true), Object.values(crudTestTables_1.crudTestTables), true), Object.values(dynamicReferenceColumnTestTables_1.dynamicReferenceTestTables), true), Object.values(recordIteratorTestTables_1.recordIteratorTestTables), true), Object.values(sourceRecordSyncTestTables_1.sourceRecordSyncTestTables), true), [
|
|
60
|
+
var TABLES = __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], Object.values(cascadeDeleteTestTables_1.cascadeDeleteTestTables), true), Object.values(columnTypesTestTables_1.columnTypesTestTables), true), Object.values(crudTestTables_1.crudTestTables), true), Object.values(dynamicReferenceColumnTestTables_1.dynamicReferenceTestTables), true), Object.values(recordIteratorTestTables_1.recordIteratorTestTables), true), Object.values(sourceRecordSyncTestTables_1.sourceRecordSyncTestTables), true), [
|
|
60
61
|
// The member tables are the stored-value suite's own: it builds each physical column order itself.
|
|
61
62
|
storedValueContractTestTables_1.storedValueContractTestTables.Mixed
|
|
62
|
-
], false), Object.values(tableManagerTestTables_1.tableManagerTestTables), true), Object.values(transactionTestTables_1.transactionTestTables), true);
|
|
63
|
+
], false), Object.values(tableManagerTestTables_1.tableManagerTestTables), true), Object.values(tableWatcherAuthorityTestTables_1.tableWatcherAuthorityTestTables), true), Object.values(transactionTestTables_1.transactionTestTables), true);
|
|
63
64
|
/**
|
|
64
65
|
* Convenience functions for setting up a test environment
|
|
65
66
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DbTestEnvironment.js","sourceRoot":"","sources":["../../../test/util/DbTestEnvironment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uCAA6D;AAC7D,4EAA2E;AAC3E,wEAAuE;AACvE,0DAAyD;AACzD,8FAAuF;AACvF,8EAA6E;AAC7E,kFAAiF;AACjF,wFAAuF;AACvF,0EAAyE;AACzE,wEAAuE;AAEvE,IAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"DbTestEnvironment.js","sourceRoot":"","sources":["../../../test/util/DbTestEnvironment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uCAA6D;AAC7D,4EAA2E;AAC3E,wEAAuE;AACvE,0DAAyD;AACzD,8FAAuF;AACvF,8EAA6E;AAC7E,kFAAiF;AACjF,wFAAuF;AACvF,0EAAyE;AACzE,4FAA2F;AAC3F,wEAAuE;AAEvE,IAAM,MAAM,mJACP,MAAM,CAAC,MAAM,CAAC,iDAAuB,CAAC,SACtC,MAAM,CAAC,MAAM,CAAC,6CAAqB,CAAC,SACpC,MAAM,CAAC,MAAM,CAAC,+BAAc,CAAC,SAC7B,MAAM,CAAC,MAAM,CAAC,6DAA0B,CAAC,SACzC,MAAM,CAAC,MAAM,CAAC,mDAAwB,CAAC,SACvC,MAAM,CAAC,MAAM,CAAC,uDAA0B,CAAC;IAC5C,mGAAmG;IACnG,6DAA6B,CAAC,KAAK;WAChC,MAAM,CAAC,MAAM,CAAC,+CAAsB,CAAC,SACrC,MAAM,CAAC,MAAM,CAAC,iEAA+B,CAAC,SAC9C,MAAM,CAAC,MAAM,CAAC,6CAAqB,CAAC,OACxC,CAAC;AAEF;;GAEG;AACH;IACE,2BACU,QAAkB,EAClB,aAAmD;QADnD,aAAQ,GAAR,QAAQ,CAAU;QAClB,kBAAa,GAAb,aAAa,CAAsC;IAC1D,CAAC;IAEE,qCAAS,GAAf;;;;;;wBACE,yFAAyF;wBACzF,+CAA+C;wBAC/C,IAAA,2BAAgB,GAAE,CAAC;6BACf,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAnB,wBAAmB;wBACrB,qBAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAA;;wBAA3B,SAA2B,CAAC;;;8BAGJ,EAAN,iBAAM;;;6BAAN,CAAA,oBAAM,CAAA;wBAAf,KAAK;wBACd,qBAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAA;;wBAAtD,SAAsD,CAAC;;;wBADrC,IAAM,CAAA;;;;;;KAG3B;IAEK,oCAAQ,GAAd;;;;;;wBACE,IAAA,wBAAa,GAAE,CAAC;8BACoB,EAAhB,KAAA,MAAM,CAAC,OAAO,EAAE;;;6BAAhB,CAAA,cAAgB,CAAA;wBAAzB,KAAK;wBACd,qBAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAA;;wBAA/B,SAA+B,CAAC;;;wBADd,IAAgB,CAAA;;;6BAIhC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAlB,wBAAkB;wBACpB,qBAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAA1B,SAA0B,CAAC;;;;;;KAE9B;IACH,wBAAC;AAAD,CAAC,AA7BD,IA6BC;AA7BY,8CAAiB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Table, Record } from '@proteinjs/db';
|
|
2
|
+
/** The watched table: a plain row whose writes fire the suite's journaling watcher. */
|
|
3
|
+
export interface WatchedNote extends Record {
|
|
4
|
+
title: string;
|
|
5
|
+
}
|
|
6
|
+
/** The watcher's journal: one row per hook run, writable and readable as system only. */
|
|
7
|
+
export interface GuardedJournal extends Record {
|
|
8
|
+
/** The watched row's id. */
|
|
9
|
+
note: string;
|
|
10
|
+
/** The hook that wrote the row (`beforeInsert` … `afterDelete`). */
|
|
11
|
+
hook: string;
|
|
12
|
+
/** The scoped-table contract in miniature — see {@link GuardedJournalTable}. */
|
|
13
|
+
principal: string;
|
|
14
|
+
}
|
|
15
|
+
/** The journal's refusal of a non-system write or query, by name. */
|
|
16
|
+
export declare const WATCHER_GUARDED_REFUSAL = "no user in scope (journal)";
|
|
17
|
+
export declare class WatchedNoteTable extends Table<WatchedNote> {
|
|
18
|
+
name: string;
|
|
19
|
+
columns: Table<WatchedNote>['columns'];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A scoped table's shape without a dependency on one: a non-system write needs the context's
|
|
23
|
+
* user to stamp the row with, a non-system query needs it to scope the query to — there is none
|
|
24
|
+
* in a session-less context, so both refuse by name. A system write supplies the principal itself
|
|
25
|
+
* and a system query is not scoped, exactly as `@proteinjs/user`'s ScopedRecord columns behave.
|
|
26
|
+
*/
|
|
27
|
+
export declare class GuardedJournalTable extends Table<GuardedJournal> {
|
|
28
|
+
name: string;
|
|
29
|
+
columns: Table<GuardedJournal>['columns'];
|
|
30
|
+
}
|
|
31
|
+
export declare const tableWatcherAuthorityTestTables: {
|
|
32
|
+
WatchedNote: Table<WatchedNote>;
|
|
33
|
+
GuardedJournal: Table<GuardedJournal>;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=tableWatcherAuthorityTestTables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableWatcherAuthorityTestTables.d.ts","sourceRoot":"","sources":["../../../../test/util/tables/tableWatcherAuthorityTestTables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,EAAqB,MAAM,EAAE,MAAM,eAAe,CAAC;AAI/E,uFAAuF;AACvF,MAAM,WAAW,WAAY,SAAQ,MAAM;IACzC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,yFAAyF;AACzF,MAAM,WAAW,cAAe,SAAQ,MAAM;IAC5C,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,gFAAgF;IAChF,SAAS,EAAE,MAAM,CAAC;CACnB;AAKD,qEAAqE;AACrE,eAAO,MAAM,uBAAuB,+BAA+B,CAAC;AAEpE,qBAAa,gBAAiB,SAAQ,KAAK,CAAC,WAAW,CAAC;IACtD,IAAI,SAAsB;IAC1B,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,CAEnC;CACJ;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,KAAK,CAAC,cAAc,CAAC;IAC5D,IAAI,SAAyB;IAC7B,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,SAAS,CAAC,CActC;CACJ;AAED,eAAO,MAAM,+BAA+B;;;CAG3C,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
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;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.tableWatcherAuthorityTestTables = exports.GuardedJournalTable = exports.WatchedNoteTable = exports.WATCHER_GUARDED_REFUSAL = void 0;
|
|
55
|
+
var db_1 = require("@proteinjs/db");
|
|
56
|
+
var WATCHED_NOTE_TABLE = 'db_test_tw_notes';
|
|
57
|
+
var GUARDED_JOURNAL_TABLE = 'db_test_tw_guarded_journal';
|
|
58
|
+
/** The journal's refusal of a non-system write or query, by name. */
|
|
59
|
+
exports.WATCHER_GUARDED_REFUSAL = 'no user in scope (journal)';
|
|
60
|
+
var WatchedNoteTable = /** @class */ (function (_super) {
|
|
61
|
+
__extends(WatchedNoteTable, _super);
|
|
62
|
+
function WatchedNoteTable() {
|
|
63
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
64
|
+
_this.name = WATCHED_NOTE_TABLE;
|
|
65
|
+
_this.columns = (0, db_1.withRecordColumns)({
|
|
66
|
+
title: new db_1.StringColumn('title'),
|
|
67
|
+
});
|
|
68
|
+
return _this;
|
|
69
|
+
}
|
|
70
|
+
return WatchedNoteTable;
|
|
71
|
+
}(db_1.Table));
|
|
72
|
+
exports.WatchedNoteTable = WatchedNoteTable;
|
|
73
|
+
/**
|
|
74
|
+
* A scoped table's shape without a dependency on one: a non-system write needs the context's
|
|
75
|
+
* user to stamp the row with, a non-system query needs it to scope the query to — there is none
|
|
76
|
+
* in a session-less context, so both refuse by name. A system write supplies the principal itself
|
|
77
|
+
* and a system query is not scoped, exactly as `@proteinjs/user`'s ScopedRecord columns behave.
|
|
78
|
+
*/
|
|
79
|
+
var GuardedJournalTable = /** @class */ (function (_super) {
|
|
80
|
+
__extends(GuardedJournalTable, _super);
|
|
81
|
+
function GuardedJournalTable() {
|
|
82
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
83
|
+
_this.name = GUARDED_JOURNAL_TABLE;
|
|
84
|
+
_this.columns = (0, db_1.withRecordColumns)({
|
|
85
|
+
note: new db_1.StringColumn('note'),
|
|
86
|
+
hook: new db_1.StringColumn('hook'),
|
|
87
|
+
principal: new db_1.StringColumn('principal', {
|
|
88
|
+
defaultValue: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
89
|
+
return __generator(this, function (_a) {
|
|
90
|
+
throw new Error(exports.WATCHER_GUARDED_REFUSAL);
|
|
91
|
+
});
|
|
92
|
+
}); },
|
|
93
|
+
forceDefaultValue: function (runAsSystem) { return !runAsSystem; },
|
|
94
|
+
addToQuery: function (qb, runAsSystem) { return __awaiter(_this, void 0, void 0, function () {
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
if (!runAsSystem) {
|
|
97
|
+
throw new Error(exports.WATCHER_GUARDED_REFUSAL);
|
|
98
|
+
}
|
|
99
|
+
return [2 /*return*/];
|
|
100
|
+
});
|
|
101
|
+
}); },
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
return _this;
|
|
105
|
+
}
|
|
106
|
+
return GuardedJournalTable;
|
|
107
|
+
}(db_1.Table));
|
|
108
|
+
exports.GuardedJournalTable = GuardedJournalTable;
|
|
109
|
+
exports.tableWatcherAuthorityTestTables = {
|
|
110
|
+
WatchedNote: new WatchedNoteTable(),
|
|
111
|
+
GuardedJournal: new GuardedJournalTable(),
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=tableWatcherAuthorityTestTables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableWatcherAuthorityTestTables.js","sourceRoot":"","sources":["../../../../test/util/tables/tableWatcherAuthorityTestTables.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA+E;AAmB/E,IAAM,kBAAkB,GAAG,kBAAkB,CAAC;AAC9C,IAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAE3D,qEAAqE;AACxD,QAAA,uBAAuB,GAAG,4BAA4B,CAAC;AAEpE;IAAsC,oCAAkB;IAAxD;QAAA,qEAKC;QAJC,UAAI,GAAG,kBAAkB,CAAC;QAC1B,aAAO,GAAkC,IAAA,sBAAiB,EAAc;YACtE,KAAK,EAAE,IAAI,iBAAY,CAAC,OAAO,CAAC;SACjC,CAAC,CAAC;;IACL,CAAC;IAAD,uBAAC;AAAD,CAAC,AALD,CAAsC,UAAK,GAK1C;AALY,4CAAgB;AAO7B;;;;;GAKG;AACH;IAAyC,uCAAqB;IAA9D;QAAA,qEAiBC;QAhBC,UAAI,GAAG,qBAAqB,CAAC;QAC7B,aAAO,GAAqC,IAAA,sBAAiB,EAAiB;YAC5E,IAAI,EAAE,IAAI,iBAAY,CAAC,MAAM,CAAC;YAC9B,IAAI,EAAE,IAAI,iBAAY,CAAC,MAAM,CAAC;YAC9B,SAAS,EAAE,IAAI,iBAAY,CAAC,WAAW,EAAE;gBACvC,YAAY,EAAE;;wBACZ,MAAM,IAAI,KAAK,CAAC,+BAAuB,CAAC,CAAC;;qBAC1C;gBACD,iBAAiB,EAAE,UAAC,WAAW,IAAK,OAAA,CAAC,WAAW,EAAZ,CAAY;gBAChD,UAAU,EAAE,UAAO,EAAE,EAAE,WAAW;;wBAChC,IAAI,CAAC,WAAW,EAAE;4BAChB,MAAM,IAAI,KAAK,CAAC,+BAAuB,CAAC,CAAC;yBAC1C;;;qBACF;aACF,CAAC;SACH,CAAC,CAAC;;IACL,CAAC;IAAD,0BAAC;A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