@proteinjs/db 1.55.1 → 1.56.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 (42) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/generated/index.js +1 -1
  3. package/dist/generated/index.js.map +1 -1
  4. package/dist/generated/test/index.d.ts.map +1 -1
  5. package/dist/generated/test/index.js +5 -1
  6. package/dist/generated/test/index.js.map +1 -1
  7. package/dist/src/Db.d.ts +15 -6
  8. package/dist/src/Db.d.ts.map +1 -1
  9. package/dist/src/Db.js +26 -15
  10. package/dist/src/Db.js.map +1 -1
  11. package/dist/src/TableWatcher.d.ts +15 -6
  12. package/dist/src/TableWatcher.d.ts.map +1 -1
  13. package/dist/src/TableWatcher.js.map +1 -1
  14. package/dist/src/TableWatcherRunner.d.ts +14 -6
  15. package/dist/src/TableWatcherRunner.d.ts.map +1 -1
  16. package/dist/src/TableWatcherRunner.js +19 -12
  17. package/dist/src/TableWatcherRunner.js.map +1 -1
  18. package/dist/test/index.d.ts +2 -0
  19. package/dist/test/index.d.ts.map +1 -1
  20. package/dist/test/index.js +2 -0
  21. package/dist/test/index.js.map +1 -1
  22. package/dist/test/reusable/TableWatcherAuthorityTests.d.ts +13 -0
  23. package/dist/test/reusable/TableWatcherAuthorityTests.d.ts.map +1 -0
  24. package/dist/test/reusable/TableWatcherAuthorityTests.js +392 -0
  25. package/dist/test/reusable/TableWatcherAuthorityTests.js.map +1 -0
  26. package/dist/test/util/DbTestEnvironment.d.ts.map +1 -1
  27. package/dist/test/util/DbTestEnvironment.js +3 -2
  28. package/dist/test/util/DbTestEnvironment.js.map +1 -1
  29. package/dist/test/util/tables/tableWatcherAuthorityTestTables.d.ts +35 -0
  30. package/dist/test/util/tables/tableWatcherAuthorityTestTables.d.ts.map +1 -0
  31. package/dist/test/util/tables/tableWatcherAuthorityTestTables.js +113 -0
  32. package/dist/test/util/tables/tableWatcherAuthorityTestTables.js.map +1 -0
  33. package/generated/index.ts +1 -1
  34. package/generated/test/index.ts +5 -1
  35. package/package.json +2 -2
  36. package/src/Db.ts +40 -21
  37. package/src/TableWatcher.ts +17 -6
  38. package/src/TableWatcherRunner.ts +25 -12
  39. package/test/index.ts +2 -0
  40. package/test/reusable/TableWatcherAuthorityTests.ts +204 -0
  41. package/test/util/DbTestEnvironment.ts +2 -0
  42. package/test/util/tables/tableWatcherAuthorityTestTables.ts +61 -0
@@ -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;AAAD,CAAC,AAjBD,CAAyC,UAAK,GAiB7C;AAjBY,kDAAmB;AAmBnB,QAAA,+BAA+B,GAAG;IAC7C,WAAW,EAAE,IAAI,gBAAgB,EAAwB;IACzD,cAAc,EAAE,IAAI,mBAAmB,EAA2B;CACnE,CAAC"}