@proteinjs/user 1.0.1

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 (55) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -0
  3. package/dist/generated/index.d.ts +9 -0
  4. package/dist/generated/index.d.ts.map +1 -0
  5. package/dist/generated/index.js +39 -0
  6. package/dist/generated/index.js.map +1 -0
  7. package/dist/index.d.ts +9 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +25 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/src/ScopedRecord.d.ts +17 -0
  12. package/dist/src/ScopedRecord.d.ts.map +1 -0
  13. package/dist/src/ScopedRecord.js +82 -0
  14. package/dist/src/ScopedRecord.js.map +1 -0
  15. package/dist/src/UserRepo.d.ts +7 -0
  16. package/dist/src/UserRepo.d.ts.map +1 -0
  17. package/dist/src/UserRepo.js +20 -0
  18. package/dist/src/UserRepo.js.map +1 -0
  19. package/dist/src/cacheKeys.d.ts +2 -0
  20. package/dist/src/cacheKeys.d.ts.map +1 -0
  21. package/dist/src/cacheKeys.js +5 -0
  22. package/dist/src/cacheKeys.js.map +1 -0
  23. package/dist/src/routes.d.ts +7 -0
  24. package/dist/src/routes.d.ts.map +1 -0
  25. package/dist/src/routes.js +9 -0
  26. package/dist/src/routes.js.map +1 -0
  27. package/dist/src/tables/SessionTable.d.ts +21 -0
  28. package/dist/src/tables/SessionTable.d.ts.map +1 -0
  29. package/dist/src/tables/SessionTable.js +37 -0
  30. package/dist/src/tables/SessionTable.js.map +1 -0
  31. package/dist/src/tables/UserTable.d.ts +23 -0
  32. package/dist/src/tables/UserTable.d.ts.map +1 -0
  33. package/dist/src/tables/UserTable.js +38 -0
  34. package/dist/src/tables/UserTable.js.map +1 -0
  35. package/dist/src/tables/tables.d.ts +8 -0
  36. package/dist/src/tables/tables.d.ts.map +1 -0
  37. package/dist/src/tables/tables.js +10 -0
  38. package/dist/src/tables/tables.js.map +1 -0
  39. package/dist/test/ScopedRecord.test.d.ts +17 -0
  40. package/dist/test/ScopedRecord.test.d.ts.map +1 -0
  41. package/dist/test/ScopedRecord.test.js +178 -0
  42. package/dist/test/ScopedRecord.test.js.map +1 -0
  43. package/generated/index.ts +35 -0
  44. package/index.ts +9 -0
  45. package/jest.config.js +18 -0
  46. package/package.json +44 -0
  47. package/src/ScopedRecord.ts +43 -0
  48. package/src/UserRepo.ts +16 -0
  49. package/src/cacheKeys.ts +1 -0
  50. package/src/routes.ts +5 -0
  51. package/src/tables/SessionTable.ts +18 -0
  52. package/src/tables/UserTable.ts +20 -0
  53. package/src/tables/tables.ts +8 -0
  54. package/test/ScopedRecord.test.ts +74 -0
  55. package/tsconfig.json +18 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.1 (2024-04-19)
7
+
8
+ **Note:** Version bump only for package @proteinjs/user
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Brent Bahry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ /** Load Dependency Source Graphs */
2
+ import '@proteinjs/reflection';
3
+ import '@proteinjs/db';
4
+ import '@proteinjs/server-api';
5
+ import '@proteinjs/service';
6
+ import '@proteinjs/user-auth';
7
+ import 'moment';
8
+ export * from '../index';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,eAAe,CAAC;AACvB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,QAAQ,CAAC;AA2BhB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ /** Load Dependency Source Graphs */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ require("@proteinjs/reflection");
19
+ require("@proteinjs/db");
20
+ require("@proteinjs/server-api");
21
+ require("@proteinjs/service");
22
+ require("@proteinjs/user-auth");
23
+ require("moment");
24
+ /** Generate Source Graph */
25
+ var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/user/ScopedRecord\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"ScopedRecord\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/ScopedRecord.ts\",\"qualifiedName\":\"@proteinjs/user/ScopedRecord\",\"properties\":[{\"name\":\"scope\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/db/Record\"},{\"v\":\"@proteinjs/user/UserRepo\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserRepo\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/UserRepo.ts\",\"qualifiedName\":\"@proteinjs/user/UserRepo\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[{\"name\":\"getUser\",\"returnType\":{\"packageName\":\"\",\"name\":\"Omit<User, 'roles'> & AuthenticatedUser\",\"filePath\":null,\"qualifiedName\":\"/Omit<User, 'roles'> & AuthenticatedUser\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]},{\"name\":\"setUser\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"user\",\"type\":{\"packageName\":\"@proteinjs/user\",\"name\":\"User\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/User\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUserRepo\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\"},{\"v\":\"@proteinjs/user/Session\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"Session\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/tables/SessionTable.ts\",\"qualifiedName\":\"@proteinjs/user/Session\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n sessionId: string,\\n session: string,\\n expires: Date,\\n userEmail: string\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n sessionId: string,\\n session: string,\\n expires: Date,\\n userEmail: string\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/SessionTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"SessionTable\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/tables/SessionTable.ts\",\"qualifiedName\":\"@proteinjs/user/SessionTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/Session\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db/Table\"},{\"v\":\"@proteinjs/user/User\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"User\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/tables/UserTable.ts\",\"qualifiedName\":\"@proteinjs/user/User\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n name: string,\\n email: string,\\n password: string,\\n emailVerified: boolean,\\n roles: string\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n name: string,\\n email: string,\\n password: string,\\n emailVerified: boolean,\\n roles: string\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/UserTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserTable\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/tables/UserTable.ts\",\"qualifiedName\":\"@proteinjs/user/UserTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/User\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}}],\"edges\":[{\"v\":\"@proteinjs/user/ScopedRecord\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/UserRepo\",\"w\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/user/Session\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/SessionTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user/User\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/UserTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"}]}";
26
+ /** Generate Source Links */
27
+ var UserRepo_1 = require("../src/UserRepo");
28
+ var SessionTable_1 = require("../src/tables/SessionTable");
29
+ var UserTable_1 = require("../src/tables/UserTable");
30
+ var sourceLinks = {
31
+ '@proteinjs/user/UserRepo': UserRepo_1.UserRepo,
32
+ '@proteinjs/user/SessionTable': SessionTable_1.SessionTable,
33
+ '@proteinjs/user/UserTable': UserTable_1.UserTable,
34
+ };
35
+ /** Load Source Graph and Links */
36
+ var reflection_1 = require("@proteinjs/reflection");
37
+ reflection_1.SourceRepository.merge(sourceGraph, sourceLinks);
38
+ __exportStar(require("../index"), exports);
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,iCAA+B;AAC/B,yBAAuB;AACvB,iCAA+B;AAC/B,8BAA4B;AAC5B,gCAA8B;AAC9B,kBAAgB;AAGhB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,u/MAAu/M,CAAC;AAG5gN,4BAA4B;AAE5B,4CAA2C;AAC3C,2DAA0D;AAC1D,qDAAoD;AAEpD,IAAM,WAAW,GAAG;IACnB,0BAA0B,EAAE,mBAAQ;IACpC,8BAA8B,EAAE,2BAAY;IAC5C,2BAA2B,EAAE,qBAAS;CACtC,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
@@ -0,0 +1,9 @@
1
+ export * from './src/tables/UserTable';
2
+ export * from './src/tables/SessionTable';
3
+ export * from './src/tables/tables';
4
+ export * from './src/routes';
5
+ export * from './src/cacheKeys';
6
+ export * from './src/UserRepo';
7
+ export * from './src/ScopedRecord';
8
+ export * from '@proteinjs/user-auth';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AAEnC,cAAc,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./src/tables/UserTable"), exports);
18
+ __exportStar(require("./src/tables/SessionTable"), exports);
19
+ __exportStar(require("./src/tables/tables"), exports);
20
+ __exportStar(require("./src/routes"), exports);
21
+ __exportStar(require("./src/cacheKeys"), exports);
22
+ __exportStar(require("./src/UserRepo"), exports);
23
+ __exportStar(require("./src/ScopedRecord"), exports);
24
+ __exportStar(require("@proteinjs/user-auth"), exports);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,4DAA0C;AAC1C,sDAAoC;AACpC,+CAA6B;AAC7B,kDAAgC;AAChC,iDAA+B;AAC/B,qDAAmC;AAEnC,uDAAqC"}
@@ -0,0 +1,17 @@
1
+ import { Columns, Record, Table } from '@proteinjs/db';
2
+ export interface ScopedRecord extends Record {
3
+ scope: string;
4
+ }
5
+ export declare const getScopedDb: () => import("@proteinjs/db").Db<ScopedRecord>;
6
+ export declare function getScopedTables(): Table<ScopedRecord>[];
7
+ export declare function isScopedTable(table: Table<any>): boolean;
8
+ /**
9
+ * Wrapper function to add default ScopedRecord columns to your table's columns.
10
+ *
11
+ * Note: using this requires an explicit dependency on moment@2.29.4 in your package (since transient dependencies are brittle by typescript's standards)
12
+ *
13
+ * @param columns your columns
14
+ * @returns recordColumns & sourceRecordColumns & your columns
15
+ */
16
+ export declare function withScopedRecordColumns<T extends ScopedRecord>(columns: Columns<Omit<T, keyof ScopedRecord>>): Columns<ScopedRecord> & Columns<Omit<T, keyof ScopedRecord>>;
17
+ //# sourceMappingURL=ScopedRecord.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScopedRecord.d.ts","sourceRoot":"","sources":["../../src/ScopedRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAgB,MAAM,EAA4B,KAAK,EAA8B,MAAM,eAAe,CAAC;AAG3H,MAAM,WAAW,YAAa,SAAQ,MAAM;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,WAAW,gDAAsB,CAAC;AAgB/C,wBAAgB,eAAe,0BAE9B;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,WAG9C;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,CAE3K"}
@@ -0,0 +1,82 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.withScopedRecordColumns = exports.isScopedTable = exports.getScopedTables = exports.getScopedDb = void 0;
40
+ var db_1 = require("@proteinjs/db");
41
+ var UserRepo_1 = require("./UserRepo");
42
+ exports.getScopedDb = (db_1.getDb);
43
+ var scopedRecordColumns = {
44
+ scope: new db_1.StringColumn('scope', {
45
+ defaultValue: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
46
+ return [2 /*return*/, new UserRepo_1.UserRepo().getUser().id];
47
+ }); }); },
48
+ addToQuery: function (qb) { return __awaiter(void 0, void 0, void 0, function () {
49
+ return __generator(this, function (_a) {
50
+ qb.condition({
51
+ field: 'scope',
52
+ operator: 'IN',
53
+ value: [new UserRepo_1.UserRepo().getUser().id]
54
+ });
55
+ return [2 /*return*/];
56
+ });
57
+ }); },
58
+ ui: { hidden: true },
59
+ }),
60
+ };
61
+ function getScopedTables() {
62
+ return (0, db_1.getTables)().filter(function (table) { return isScopedTable(table); });
63
+ }
64
+ exports.getScopedTables = getScopedTables;
65
+ function isScopedTable(table) {
66
+ var scopeColumn = (0, db_1.getColumnByName)(table, scopedRecordColumns.scope.name);
67
+ return !!scopeColumn;
68
+ }
69
+ exports.isScopedTable = isScopedTable;
70
+ /**
71
+ * Wrapper function to add default ScopedRecord columns to your table's columns.
72
+ *
73
+ * Note: using this requires an explicit dependency on moment@2.29.4 in your package (since transient dependencies are brittle by typescript's standards)
74
+ *
75
+ * @param columns your columns
76
+ * @returns recordColumns & sourceRecordColumns & your columns
77
+ */
78
+ function withScopedRecordColumns(columns) {
79
+ return Object.assign(Object.assign({}, scopedRecordColumns), (0, db_1.withRecordColumns)(columns));
80
+ }
81
+ exports.withScopedRecordColumns = withScopedRecordColumns;
82
+ //# sourceMappingURL=ScopedRecord.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScopedRecord.js","sourceRoot":"","sources":["../../src/ScopedRecord.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAA2H;AAC3H,uCAAsC;AAMzB,QAAA,WAAW,GAAG,CAAA,UAAmB,CAAA,CAAC;AAE/C,IAAM,mBAAmB,GAAG;IAC1B,KAAK,EAAE,IAAI,iBAAY,CAAC,OAAO,EAAE;QAC/B,YAAY,EAAE;YAAa,sBAAA,IAAI,mBAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,EAAA;iBAAA;QACtD,UAAU,EAAE,UAAO,EAAE;;gBACnB,EAAE,CAAC,SAAS,CAAC;oBACX,KAAK,EAAE,OAAO;oBACd,QAAQ,EAAE,IAAI;oBACd,KAAK,EAAE,CAAC,IAAI,mBAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;iBACrC,CAAC,CAAC;;;aACJ;QACD,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;KACrB,CAAC;CACH,CAAA;AAED,SAAgB,eAAe;IAC7B,OAAO,IAAA,cAAS,GAAgB,CAAC,MAAM,CAAC,UAAA,KAAK,IAAI,OAAA,aAAa,CAAC,KAAK,CAAC,EAApB,CAAoB,CAAC,CAAC;AACzE,CAAC;AAFD,0CAEC;AAED,SAAgB,aAAa,CAAC,KAAiB;IAC7C,IAAM,WAAW,GAAG,IAAA,oBAAe,EAAC,KAAK,EAAE,mBAAmB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3E,OAAO,CAAC,CAAC,WAAW,CAAC;AACvB,CAAC;AAHD,sCAGC;AAED;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CAAyB,OAA6C;IAC3G,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,mBAAmB,CAAC,EAAE,IAAA,sBAAiB,EAAS,OAAO,CAAQ,CAAC,CAAC;AAC1G,CAAC;AAFD,0DAEC"}
@@ -0,0 +1,7 @@
1
+ import { AuthenticatedUser, AuthenticatedUserRepo } from '@proteinjs/user-auth';
2
+ import { User } from './tables/UserTable';
3
+ export declare class UserRepo implements AuthenticatedUserRepo {
4
+ getUser(): Omit<User, 'roles'> & AuthenticatedUser;
5
+ setUser(user: User): void;
6
+ }
7
+ //# sourceMappingURL=UserRepo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserRepo.d.ts","sourceRoot":"","sources":["../../src/UserRepo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,qBAAa,QAAS,YAAW,qBAAqB;IAClD,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,iBAAiB;IAMlD,OAAO,CAAC,IAAI,EAAE,IAAI;CAGrB"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserRepo = void 0;
4
+ var server_api_1 = require("@proteinjs/server-api");
5
+ var cacheKeys_1 = require("./cacheKeys");
6
+ var UserRepo = /** @class */ (function () {
7
+ function UserRepo() {
8
+ }
9
+ UserRepo.prototype.getUser = function () {
10
+ var user = Object.assign({}, server_api_1.Session.getDataByKey(cacheKeys_1.USER_SESSION_CACHE_KEY));
11
+ var roles = user.roles ? user.roles.split(',') : [];
12
+ return Object.assign(user, { roles: roles });
13
+ };
14
+ UserRepo.prototype.setUser = function (user) {
15
+ server_api_1.Session.setDataByKey(cacheKeys_1.USER_SESSION_CACHE_KEY, user);
16
+ };
17
+ return UserRepo;
18
+ }());
19
+ exports.UserRepo = UserRepo;
20
+ //# sourceMappingURL=UserRepo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserRepo.js","sourceRoot":"","sources":["../../src/UserRepo.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAGhD,yCAAqD;AAErD;IAAA;IAUA,CAAC;IATG,0BAAO,GAAP;QACI,IAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,oBAAO,CAAC,YAAY,CAAO,kCAAsB,CAAC,CAAC,CAAC;QACnF,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,0BAAO,GAAP,UAAQ,IAAU;QACd,oBAAO,CAAC,YAAY,CAAC,kCAAsB,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;IACL,eAAC;AAAD,CAAC,AAVD,IAUC;AAVY,4BAAQ"}
@@ -0,0 +1,2 @@
1
+ export declare const USER_SESSION_CACHE_KEY = "@proteinjs/user/userCache";
2
+ //# sourceMappingURL=cacheKeys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheKeys.d.ts","sourceRoot":"","sources":["../../src/cacheKeys.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,8BAA8B,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USER_SESSION_CACHE_KEY = void 0;
4
+ exports.USER_SESSION_CACHE_KEY = '@proteinjs/user/userCache';
5
+ //# sourceMappingURL=cacheKeys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cacheKeys.js","sourceRoot":"","sources":["../../src/cacheKeys.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,2BAA2B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const routes: {
2
+ [name: string]: {
3
+ path: string;
4
+ method: 'get' | 'post' | 'put' | 'patch' | 'delete';
5
+ };
6
+ };
7
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/routes.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,EAAE;IAAC,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,KAAK,GAAC,MAAM,GAAC,KAAK,GAAC,OAAO,GAAC,QAAQ,CAAA;KAAE,CAAA;CAIlG,CAAA"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.routes = void 0;
4
+ exports.routes = {
5
+ createUser: { path: '/user/create', method: 'post' },
6
+ login: { path: '/user/login', method: 'post' },
7
+ logout: { path: '/user/logout', method: 'get' },
8
+ };
9
+ //# sourceMappingURL=routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.js","sourceRoot":"","sources":["../../src/routes.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAoF;IACrG,UAAU,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE;IACpD,KAAK,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE;IAC9C,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE;CAChD,CAAA"}
@@ -0,0 +1,21 @@
1
+ import { Table, Record } from '@proteinjs/db';
2
+ export type Session = Record & {
3
+ sessionId: string;
4
+ session: string;
5
+ expires: Date;
6
+ userEmail: string;
7
+ };
8
+ export declare class SessionTable extends Table<Session> {
9
+ name: string;
10
+ columns: {
11
+ id: import("@proteinjs/db").Column<string, any>;
12
+ created: import("@proteinjs/db").Column<import("moment").Moment, any>;
13
+ updated: import("@proteinjs/db").Column<import("moment").Moment, any>;
14
+ } & {} & {
15
+ session: import("@proteinjs/db").Column<string, any>;
16
+ sessionId: import("@proteinjs/db").Column<string, any>;
17
+ expires: import("@proteinjs/db").Column<Date, any>;
18
+ userEmail: import("@proteinjs/db").Column<string, any>;
19
+ } & {};
20
+ }
21
+ //# sourceMappingURL=SessionTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionTable.d.ts","sourceRoot":"","sources":["../../../src/tables/SessionTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,EAAE,MAAM,EAAqB,MAAM,eAAe,CAAC;AAE3F,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,qBAAa,YAAa,SAAQ,KAAK,CAAC,OAAO,CAAC;IAC5C,IAAI,SAAa;IACjB,OAAO;;;;;;;;;WAKJ;CACN"}
@@ -0,0 +1,37 @@
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.SessionTable = void 0;
19
+ var db_1 = require("@proteinjs/db");
20
+ var SessionTable = /** @class */ (function (_super) {
21
+ __extends(SessionTable, _super);
22
+ function SessionTable() {
23
+ var _this = _super !== null && _super.apply(this, arguments) || this;
24
+ _this.name = 'session';
25
+ _this.columns = (0, db_1.withRecordColumns)({
26
+ sessionId: new db_1.StringColumn('session_id'),
27
+ session: new db_1.StringColumn('session', {}, 4000),
28
+ expires: new db_1.DateColumn('expires'),
29
+ userEmail: new db_1.StringColumn('user_email'),
30
+ });
31
+ return _this;
32
+ }
33
+ return SessionTable;
34
+ }(db_1.Table));
35
+ exports.SessionTable = SessionTable;
36
+ ;
37
+ //# sourceMappingURL=SessionTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionTable.js","sourceRoot":"","sources":["../../../src/tables/SessionTable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oCAA2F;AAS3F;IAAkC,gCAAc;IAAhD;QAAA,qEAQC;QAPG,UAAI,GAAG,SAAS,CAAC;QACjB,aAAO,GAAG,IAAA,sBAAiB,EAAU;YACjC,SAAS,EAAE,IAAI,iBAAY,CAAC,YAAY,CAAC;YACzC,OAAO,EAAE,IAAI,iBAAY,CAAC,SAAS,EAAE,EAAE,EAAE,IAAI,CAAC;YAC9C,OAAO,EAAE,IAAI,eAAU,CAAC,SAAS,CAAC;YAClC,SAAS,EAAE,IAAI,iBAAY,CAAC,YAAY,CAAC;SAC5C,CAAC,CAAC;;IACP,CAAC;IAAD,mBAAC;AAAD,CAAC,AARD,CAAkC,UAAK,GAQtC;AARY,oCAAY;AAQxB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Table, Record } from '@proteinjs/db';
2
+ export type User = Record & {
3
+ name: string;
4
+ email: string;
5
+ password: string;
6
+ emailVerified: boolean;
7
+ roles: string;
8
+ };
9
+ export declare class UserTable extends Table<User> {
10
+ name: string;
11
+ columns: {
12
+ id: import("@proteinjs/db").Column<string, any>;
13
+ created: import("@proteinjs/db").Column<import("moment").Moment, any>;
14
+ updated: import("@proteinjs/db").Column<import("moment").Moment, any>;
15
+ } & {} & {
16
+ name: import("@proteinjs/db").Column<string, any>;
17
+ email: import("@proteinjs/db").Column<string, any>;
18
+ password: import("@proteinjs/db").Column<string, any>;
19
+ emailVerified: import("@proteinjs/db").Column<boolean, any>;
20
+ roles: import("@proteinjs/db").Column<string, any>;
21
+ } & {};
22
+ }
23
+ //# sourceMappingURL=UserTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserTable.d.ts","sourceRoot":"","sources":["../../../src/tables/UserTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+C,KAAK,EAAE,MAAM,EAAqB,MAAM,eAAe,CAAC;AAE9G,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,qBAAa,SAAU,SAAQ,KAAK,CAAC,IAAI,CAAC;IACtC,IAAI,SAAU;IACd,OAAO;;;;;;;;;;WAMJ;CACN"}
@@ -0,0 +1,38 @@
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.UserTable = void 0;
19
+ var db_1 = require("@proteinjs/db");
20
+ var UserTable = /** @class */ (function (_super) {
21
+ __extends(UserTable, _super);
22
+ function UserTable() {
23
+ var _this = _super !== null && _super.apply(this, arguments) || this;
24
+ _this.name = 'user';
25
+ _this.columns = (0, db_1.withRecordColumns)({
26
+ name: new db_1.StringColumn('name'),
27
+ email: new db_1.StringColumn('email', {}, 250),
28
+ password: new db_1.PasswordColumn('password'),
29
+ emailVerified: new db_1.BooleanColumn('email_verified'),
30
+ roles: new db_1.StringColumn('roles'),
31
+ });
32
+ return _this;
33
+ }
34
+ return UserTable;
35
+ }(db_1.Table));
36
+ exports.UserTable = UserTable;
37
+ ;
38
+ //# sourceMappingURL=UserTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserTable.js","sourceRoot":"","sources":["../../../src/tables/UserTable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oCAA8G;AAU9G;IAA+B,6BAAW;IAA1C;QAAA,qEASC;QARG,UAAI,GAAG,MAAM,CAAC;QACd,aAAO,GAAG,IAAA,sBAAiB,EAAO;YAC9B,IAAI,EAAE,IAAI,iBAAY,CAAC,MAAM,CAAC;YAC9B,KAAK,EAAE,IAAI,iBAAY,CAAC,OAAO,EAAE,EAAE,EAAE,GAAG,CAAC;YACzC,QAAQ,EAAE,IAAI,mBAAc,CAAC,UAAU,CAAC;YACxC,aAAa,EAAE,IAAI,kBAAa,CAAC,gBAAgB,CAAC;YAClD,KAAK,EAAE,IAAI,iBAAY,CAAC,OAAO,CAAC;SACnC,CAAC,CAAC;;IACP,CAAC;IAAD,gBAAC;AAAD,CAAC,AATD,CAA+B,UAAK,GASnC;AATY,8BAAS;AASrB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { User } from './UserTable';
2
+ import { Session } from './SessionTable';
3
+ import { Table } from '@proteinjs/db';
4
+ export declare const tables: {
5
+ User: Table<User>;
6
+ Session: Table<Session>;
7
+ };
8
+ //# sourceMappingURL=tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../../src/tables/tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,IAAI,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAgB,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,eAAO,MAAM,MAAM;;;CAGlB,CAAA"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tables = void 0;
4
+ var UserTable_1 = require("./UserTable");
5
+ var SessionTable_1 = require("./SessionTable");
6
+ exports.tables = {
7
+ User: new UserTable_1.UserTable(),
8
+ Session: new SessionTable_1.SessionTable(),
9
+ };
10
+ //# sourceMappingURL=tables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/tables/tables.ts"],"names":[],"mappings":";;;AAAA,yCAA8C;AAC9C,+CAAuD;AAG1C,QAAA,MAAM,GAAG;IACpB,IAAI,EAAE,IAAI,qBAAS,EAAiB;IACpC,OAAO,EAAE,IAAI,2BAAY,EAAoB;CAC9C,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { Table, Record } from '@proteinjs/db';
2
+ export interface Favorite extends Record {
3
+ name: string;
4
+ scope?: string;
5
+ }
6
+ export declare class FavoriteTable extends Table<Favorite> {
7
+ name: string;
8
+ columns: {
9
+ id: import("@proteinjs/db").Column<string, any>;
10
+ created: import("@proteinjs/db").Column<import("moment").Moment, any>;
11
+ updated: import("@proteinjs/db").Column<import("moment").Moment, any>;
12
+ } & {} & {
13
+ name: import("@proteinjs/db").Column<string, any>;
14
+ scope: import("@proteinjs/db").Column<string | undefined, any>;
15
+ } & {};
16
+ }
17
+ //# sourceMappingURL=ScopedRecord.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScopedRecord.test.d.ts","sourceRoot":"","sources":["../../test/ScopedRecord.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,EAAE,MAAM,EAAqB,MAAM,eAAe,CAAA;AAGlF,MAAM,WAAW,QAAS,SAAQ,MAAM;IACvC,IAAI,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAMD,qBAAa,aAAc,SAAQ,KAAK,CAAC,QAAQ,CAAC;IACjD,IAAI,SAAoB;IACxB,OAAO;;;;;;;WAYJ;CACH"}
@@ -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
+ 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.FavoriteTable = void 0;
55
+ var db_1 = require("@proteinjs/db");
56
+ var db_driver_knex_1 = require("@proteinjs/db-driver-knex");
57
+ var veronicaUser = { name: 'Veronica', email: 'veroni@cake.com' };
58
+ var kevinUser = { name: 'Kevin', email: 'kev@tron.com' };
59
+ var veronicaScope = 'vvvveronica';
60
+ var kevinScope = 'kevinnn';
61
+ var FavoriteTable = /** @class */ (function (_super) {
62
+ __extends(FavoriteTable, _super);
63
+ function FavoriteTable() {
64
+ var _this = _super !== null && _super.apply(this, arguments) || this;
65
+ _this.name = 'user_test_user';
66
+ _this.columns = (0, db_1.withRecordColumns)({
67
+ name: new db_1.StringColumn('name'),
68
+ scope: new db_1.StringColumn('scope', {
69
+ defaultValue: function (favorite) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
70
+ return [2 /*return*/, favorite.name.startsWith(veronicaUser.name) ? veronicaScope : kevinScope];
71
+ }); }); },
72
+ addToQuery: function (qb) { return __awaiter(_this, void 0, void 0, function () {
73
+ return __generator(this, function (_a) {
74
+ qb.condition({
75
+ field: 'scope',
76
+ operator: 'IN',
77
+ value: [veronicaScope]
78
+ });
79
+ return [2 /*return*/];
80
+ });
81
+ }); },
82
+ }),
83
+ });
84
+ return _this;
85
+ }
86
+ return FavoriteTable;
87
+ }(db_1.Table));
88
+ exports.FavoriteTable = FavoriteTable;
89
+ var dbDriver = new db_driver_knex_1.KnexDriver({
90
+ host: 'localhost',
91
+ user: 'root',
92
+ password: '',
93
+ dbName: 'test',
94
+ });
95
+ var dropTable = function (table) { return __awaiter(void 0, void 0, void 0, function () {
96
+ return __generator(this, function (_a) {
97
+ switch (_a.label) {
98
+ case 0: return [4 /*yield*/, dbDriver.getKnex().schema.withSchema(dbDriver.getDbName()).hasTable(table.name)];
99
+ case 1:
100
+ if (!_a.sent()) return [3 /*break*/, 3];
101
+ return [4 /*yield*/, dbDriver.getKnex().schema.withSchema(dbDriver.getDbName()).dropTable(table.name)];
102
+ case 2:
103
+ _a.sent();
104
+ _a.label = 3;
105
+ case 3: return [2 /*return*/];
106
+ }
107
+ });
108
+ }); };
109
+ var getTable = function (tableName) {
110
+ var userTable = new FavoriteTable();
111
+ if (userTable.name == tableName)
112
+ return userTable;
113
+ throw new Error('Cannot find test table');
114
+ };
115
+ var db = new db_1.Db(dbDriver, getTable);
116
+ describe('Scoped Record', function () {
117
+ beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () {
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
+ case 0:
121
+ if (!dbDriver.start) return [3 /*break*/, 2];
122
+ return [4 /*yield*/, dbDriver.start()];
123
+ case 1:
124
+ _a.sent();
125
+ _a.label = 2;
126
+ case 2: return [4 /*yield*/, dbDriver.getTableManager().loadTable(new FavoriteTable())];
127
+ case 3:
128
+ _a.sent();
129
+ return [2 /*return*/];
130
+ }
131
+ });
132
+ }); });
133
+ afterAll(function () { return __awaiter(void 0, void 0, void 0, function () {
134
+ return __generator(this, function (_a) {
135
+ switch (_a.label) {
136
+ case 0: return [4 /*yield*/, dropTable(new FavoriteTable())];
137
+ case 1:
138
+ _a.sent();
139
+ if (!dbDriver.stop) return [3 /*break*/, 3];
140
+ return [4 /*yield*/, dbDriver.stop()];
141
+ case 2:
142
+ _a.sent();
143
+ _a.label = 3;
144
+ case 3: return [2 /*return*/];
145
+ }
146
+ });
147
+ }); });
148
+ test('Query scoped records', function () { return __awaiter(void 0, void 0, void 0, function () {
149
+ var favoriteTable, favorites;
150
+ return __generator(this, function (_a) {
151
+ switch (_a.label) {
152
+ case 0:
153
+ favoriteTable = new FavoriteTable();
154
+ return [4 /*yield*/, db.insert(favoriteTable, { name: "".concat(veronicaUser.name, "_favorite1") })];
155
+ case 1:
156
+ _a.sent();
157
+ return [4 /*yield*/, db.insert(favoriteTable, { name: "".concat(veronicaUser.name, "_favorite2") })];
158
+ case 2:
159
+ _a.sent();
160
+ return [4 /*yield*/, db.insert(favoriteTable, { name: "".concat(veronicaUser.name, "_favorite3") })];
161
+ case 3:
162
+ _a.sent();
163
+ return [4 /*yield*/, db.insert(favoriteTable, { name: "".concat(kevinUser.name, "_favorite1") })];
164
+ case 4:
165
+ _a.sent();
166
+ return [4 /*yield*/, db.insert(favoriteTable, { name: "".concat(kevinUser.name, "_favorite2") })];
167
+ case 5:
168
+ _a.sent();
169
+ return [4 /*yield*/, db.query(favoriteTable, {})];
170
+ case 6:
171
+ favorites = _a.sent();
172
+ expect(favorites.length).toBe(3);
173
+ return [2 /*return*/];
174
+ }
175
+ });
176
+ }); });
177
+ });
178
+ //# sourceMappingURL=ScopedRecord.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScopedRecord.test.js","sourceRoot":"","sources":["../../test/ScopedRecord.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAkF;AAClF,4DAAsD;AAOtD,IAAM,YAAY,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC;AACpE,IAAM,SAAS,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC;AAC3D,IAAM,aAAa,GAAG,aAAa,CAAC;AACpC,IAAM,UAAU,GAAG,SAAS,CAAC;AAC7B;IAAmC,iCAAe;IAAlD;QAAA,qEAeC;QAdA,UAAI,GAAG,gBAAgB,CAAC;QACxB,aAAO,GAAG,IAAA,sBAAiB,EAAW;YACrC,IAAI,EAAE,IAAI,iBAAY,CAAC,MAAM,CAAC;YAC5B,KAAK,EAAE,IAAI,iBAAY,CAAC,OAAO,EAAE;gBAC/B,YAAY,EAAE,UAAO,QAAkB;oBAAM,sBAAA,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,EAAA;yBAAA;gBACrH,UAAU,EAAE,UAAO,EAAE;;wBACnB,EAAE,CAAC,SAAS,CAAC;4BACX,KAAK,EAAE,OAAO;4BACd,QAAQ,EAAE,IAAI;4BACd,KAAK,EAAE,CAAC,aAAa,CAAC;yBACvB,CAAC,CAAC;;;qBACJ;aACF,CAAC;SACJ,CAAC,CAAC;;IACJ,CAAC;IAAD,oBAAC;AAAD,CAAC,AAfD,CAAmC,UAAK,GAevC;AAfY,sCAAa;AAiB1B,IAAM,QAAQ,GAAG,IAAI,2BAAU,CAAC;IAC/B,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,EAAE;IACZ,MAAM,EAAE,MAAM;CACd,CAAC,CAAC;AACH,IAAM,SAAS,GAAG,UAAO,KAAiB;;;oBACpC,qBAAM,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,EAAA;;qBAArF,SAAqF,EAArF,wBAAqF;gBACzF,qBAAM,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAA;;gBAAtF,SAAsF,CAAC;;;;;KACxF,CAAA;AACD,IAAM,QAAQ,GAAG,UAAC,SAAiB;IACjC,IAAM,SAAS,GAAG,IAAI,aAAa,EAAE,CAAC;IACtC,IAAI,SAAS,CAAC,IAAI,IAAI,SAAS;QAC7B,OAAO,SAAS,CAAC;IAEnB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAC5C,CAAC,CAAC;AACF,IAAM,EAAE,GAAG,IAAI,OAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAEtC,QAAQ,CAAC,eAAe,EAAE;IACxB,SAAS,CAAC;;;;yBACJ,QAAQ,CAAC,KAAK,EAAd,wBAAc;oBAChB,qBAAM,QAAQ,CAAC,KAAK,EAAE,EAAA;;oBAAtB,SAAsB,CAAC;;wBAEzB,qBAAM,QAAQ,CAAC,eAAe,EAAE,CAAC,SAAS,CAAC,IAAI,aAAa,EAAE,CAAC,EAAA;;oBAA/D,SAA+D,CAAC;;;;SACjE,CAAC,CAAA;IAEF,QAAQ,CAAC;;;wBACP,qBAAM,SAAS,CAAC,IAAI,aAAa,EAAE,CAAC,EAAA;;oBAApC,SAAoC,CAAC;yBAEjC,QAAQ,CAAC,IAAI,EAAb,wBAAa;oBACf,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;oBAArB,SAAqB,CAAC;;;;;SACzB,CAAC,CAAC;IAEH,IAAI,CAAC,sBAAsB,EAAE;;;;;oBACrB,aAAa,GAAoB,IAAI,aAAa,EAAE,CAAC;oBAC3D,qBAAM,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,UAAG,YAAY,CAAC,IAAI,eAAY,EAAE,CAAC,EAAA;;oBAA1E,SAA0E,CAAC;oBAC3E,qBAAM,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,UAAG,YAAY,CAAC,IAAI,eAAY,EAAE,CAAC,EAAA;;oBAA1E,SAA0E,CAAC;oBAC3E,qBAAM,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,UAAG,YAAY,CAAC,IAAI,eAAY,EAAE,CAAC,EAAA;;oBAA1E,SAA0E,CAAC;oBAC3E,qBAAM,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,UAAG,SAAS,CAAC,IAAI,eAAY,EAAE,CAAC,EAAA;;oBAAvE,SAAuE,CAAC;oBACxE,qBAAM,EAAE,CAAC,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,EAAE,UAAG,SAAS,CAAC,IAAI,eAAY,EAAE,CAAC,EAAA;;oBAAvE,SAAuE,CAAC;oBACtD,qBAAM,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,CAAC,EAAA;;oBAA7C,SAAS,GAAG,SAAiC;oBACnD,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;;;;SAClC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ /** Load Dependency Source Graphs */
2
+
3
+ import '@proteinjs/reflection';
4
+ import '@proteinjs/db';
5
+ import '@proteinjs/server-api';
6
+ import '@proteinjs/service';
7
+ import '@proteinjs/user-auth';
8
+ import 'moment';
9
+
10
+
11
+ /** Generate Source Graph */
12
+
13
+ const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/user/ScopedRecord\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"ScopedRecord\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/ScopedRecord.ts\",\"qualifiedName\":\"@proteinjs/user/ScopedRecord\",\"properties\":[{\"name\":\"scope\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/db/Record\"},{\"v\":\"@proteinjs/user/UserRepo\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserRepo\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/UserRepo.ts\",\"qualifiedName\":\"@proteinjs/user/UserRepo\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[{\"name\":\"getUser\",\"returnType\":{\"packageName\":\"\",\"name\":\"Omit<User, 'roles'> & AuthenticatedUser\",\"filePath\":null,\"qualifiedName\":\"/Omit<User, 'roles'> & AuthenticatedUser\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]},{\"name\":\"setUser\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"user\",\"type\":{\"packageName\":\"@proteinjs/user\",\"name\":\"User\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/User\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/user-auth\",\"name\":\"AuthenticatedUserRepo\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/user-auth/AuthenticatedUserRepo\"},{\"v\":\"@proteinjs/user/Session\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"Session\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/tables/SessionTable.ts\",\"qualifiedName\":\"@proteinjs/user/Session\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n sessionId: string,\\n session: string,\\n expires: Date,\\n userEmail: string\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n sessionId: string,\\n session: string,\\n expires: Date,\\n userEmail: string\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/SessionTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"SessionTable\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/tables/SessionTable.ts\",\"qualifiedName\":\"@proteinjs/user/SessionTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/Session\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db/Table\"},{\"v\":\"@proteinjs/user/User\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"User\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/tables/UserTable.ts\",\"qualifiedName\":\"@proteinjs/user/User\",\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Record\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Record\",\"typeParameters\":[],\"directParents\":null},{\"packageName\":\"@proteinjs/user\",\"name\":\"{\\n name: string,\\n email: string,\\n password: string,\\n emailVerified: boolean,\\n roles: string\\n}\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/user/{\\n name: string,\\n email: string,\\n password: string,\\n emailVerified: boolean,\\n roles: string\\n}\",\"typeParameters\":[],\"directParents\":null}],\"sourceType\":1}},{\"v\":\"@proteinjs/user/UserTable\",\"value\":{\"packageName\":\"@proteinjs/user\",\"name\":\"UserTable\",\"filePath\":\"/home/runner/work/user/user/packages/user/src/tables/UserTable.ts\",\"qualifiedName\":\"@proteinjs/user/UserTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"columns\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParentInterfaces\":[],\"directParentClasses\":[{\"packageName\":\"@proteinjs/db\",\"name\":\"Table\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db/Table\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[],\"methods\":[],\"typeParameters\":[\"@proteinjs/user/User\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}}],\"edges\":[{\"v\":\"@proteinjs/user/ScopedRecord\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/user/UserRepo\",\"w\":\"@proteinjs/user-auth/AuthenticatedUserRepo\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/user/Session\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/SessionTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"},{\"v\":\"@proteinjs/user/User\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends type\"},{\"v\":\"@proteinjs/user/UserTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"}]}";
14
+
15
+
16
+ /** Generate Source Links */
17
+
18
+ import { UserRepo } from '../src/UserRepo';
19
+ import { SessionTable } from '../src/tables/SessionTable';
20
+ import { UserTable } from '../src/tables/UserTable';
21
+
22
+ const sourceLinks = {
23
+ '@proteinjs/user/UserRepo': UserRepo,
24
+ '@proteinjs/user/SessionTable': SessionTable,
25
+ '@proteinjs/user/UserTable': UserTable,
26
+ };
27
+
28
+
29
+ /** Load Source Graph and Links */
30
+
31
+ import { SourceRepository } from '@proteinjs/reflection';
32
+ SourceRepository.merge(sourceGraph, sourceLinks);
33
+
34
+
35
+ export * from '../index';
package/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './src/tables/UserTable';
2
+ export * from './src/tables/SessionTable';
3
+ export * from './src/tables/tables';
4
+ export * from './src/routes';
5
+ export * from './src/cacheKeys';
6
+ export * from './src/UserRepo';
7
+ export * from './src/ScopedRecord';
8
+
9
+ export * from '@proteinjs/user-auth';
package/jest.config.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports = {
2
+ "roots": [
3
+ "<rootDir>/test"
4
+ ],
5
+ "transform": {
6
+ "^.+\\.tsx?$": "ts-jest"
7
+ },
8
+ "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
9
+ "moduleFileExtensions": [
10
+ "ts",
11
+ "tsx",
12
+ "js",
13
+ "jsx",
14
+ "json",
15
+ "node"
16
+ ],
17
+ "testEnvironment": "node"
18
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@proteinjs/user",
3
+ "version": "1.0.1",
4
+ "description": "User management",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/proteinjs/user.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/proteinjs/user/issues"
14
+ },
15
+ "homepage": "https://github.com/proteinjs/user#readme",
16
+ "author": "Brent Bahry",
17
+ "license": "MIT",
18
+ "scripts": {
19
+ "clean": "rm -rf dist/ generated/ node_modules/ package-lock.json",
20
+ "build": "reflection-build && tsc",
21
+ "watch": "reflection-watch",
22
+ "test": "jest"
23
+ },
24
+ "dependencies": {
25
+ "@proteinjs/db": "1.0.3",
26
+ "@proteinjs/reflection": "1.0.2",
27
+ "@proteinjs/server-api": "1.0.2",
28
+ "@proteinjs/service": "1.0.1",
29
+ "@proteinjs/user-auth": "1.0.1",
30
+ "moment": "2.29.4"
31
+ },
32
+ "devDependencies": {
33
+ "@proteinjs/db-driver-knex": "1.0.2",
34
+ "@proteinjs/reflection-build": "1.0.5",
35
+ "@types/jest": "29.5.5",
36
+ "@types/node": "14.0.13",
37
+ "jest": "29.7.0",
38
+ "ts-jest": "29.1.1",
39
+ "typescript": "5.2.2"
40
+ },
41
+ "main": "./dist/generated/index.js",
42
+ "types": "./dist/generated/index.d.ts",
43
+ "gitHead": "9ddea60bf3d43e1d16291ed018a1985944484009"
44
+ }
@@ -0,0 +1,43 @@
1
+ import { Columns, StringColumn, Record, withRecordColumns, getDb, Table, getColumnByName, getTables } from '@proteinjs/db';
2
+ import { UserRepo } from './UserRepo';
3
+
4
+ export interface ScopedRecord extends Record {
5
+ scope: string;
6
+ }
7
+
8
+ export const getScopedDb = getDb<ScopedRecord>;
9
+
10
+ const scopedRecordColumns = {
11
+ scope: new StringColumn('scope', {
12
+ defaultValue: async () => new UserRepo().getUser().id,
13
+ addToQuery: async (qb) => {
14
+ qb.condition({
15
+ field: 'scope',
16
+ operator: 'IN',
17
+ value: [new UserRepo().getUser().id]
18
+ });
19
+ },
20
+ ui: { hidden: true },
21
+ }),
22
+ }
23
+
24
+ export function getScopedTables() {
25
+ return getTables<ScopedRecord>().filter(table => isScopedTable(table));
26
+ }
27
+
28
+ export function isScopedTable(table: Table<any>) {
29
+ const scopeColumn = getColumnByName(table, scopedRecordColumns.scope.name);
30
+ return !!scopeColumn;
31
+ }
32
+
33
+ /**
34
+ * Wrapper function to add default ScopedRecord columns to your table's columns.
35
+ *
36
+ * Note: using this requires an explicit dependency on moment@2.29.4 in your package (since transient dependencies are brittle by typescript's standards)
37
+ *
38
+ * @param columns your columns
39
+ * @returns recordColumns & sourceRecordColumns & your columns
40
+ */
41
+ export function withScopedRecordColumns<T extends ScopedRecord>(columns: Columns<Omit<T, keyof ScopedRecord>>): Columns<ScopedRecord> & Columns<Omit<T, keyof ScopedRecord>> {
42
+ return Object.assign(Object.assign({}, scopedRecordColumns), withRecordColumns<Record>(columns) as any);
43
+ }
@@ -0,0 +1,16 @@
1
+ import { Session } from '@proteinjs/server-api';
2
+ import { AuthenticatedUser, AuthenticatedUserRepo } from '@proteinjs/user-auth';
3
+ import { User } from './tables/UserTable';
4
+ import { USER_SESSION_CACHE_KEY } from './cacheKeys';
5
+
6
+ export class UserRepo implements AuthenticatedUserRepo {
7
+ getUser(): Omit<User, 'roles'> & AuthenticatedUser {
8
+ const user = Object.assign({}, Session.getDataByKey<User>(USER_SESSION_CACHE_KEY));
9
+ const roles = user.roles ? user.roles.split(',') : [];
10
+ return Object.assign(user, { roles });
11
+ }
12
+
13
+ setUser(user: User) {
14
+ Session.setDataByKey(USER_SESSION_CACHE_KEY, user);
15
+ }
16
+ }
@@ -0,0 +1 @@
1
+ export const USER_SESSION_CACHE_KEY = '@proteinjs/user/userCache';
package/src/routes.ts ADDED
@@ -0,0 +1,5 @@
1
+ export const routes: {[name: string]: { path: string, method: 'get'|'post'|'put'|'patch'|'delete' }} = {
2
+ createUser: { path: '/user/create', method: 'post' },
3
+ login: { path: '/user/login', method: 'post' },
4
+ logout: { path: '/user/logout', method: 'get' },
5
+ }
@@ -0,0 +1,18 @@
1
+ import { DateColumn, StringColumn, Table, Record, withRecordColumns } from '@proteinjs/db';
2
+
3
+ export type Session = Record & {
4
+ sessionId: string,
5
+ session: string,
6
+ expires: Date,
7
+ userEmail: string
8
+ }
9
+
10
+ export class SessionTable extends Table<Session> {
11
+ name = 'session';
12
+ columns = withRecordColumns<Session>({
13
+ sessionId: new StringColumn('session_id'),
14
+ session: new StringColumn('session', {}, 4000),
15
+ expires: new DateColumn('expires'),
16
+ userEmail: new StringColumn('user_email'),
17
+ });
18
+ };
@@ -0,0 +1,20 @@
1
+ import { BooleanColumn, StringColumn, PasswordColumn, Table, Record, withRecordColumns } from '@proteinjs/db';
2
+
3
+ export type User = Record & {
4
+ name: string,
5
+ email: string,
6
+ password: string,
7
+ emailVerified: boolean,
8
+ roles: string
9
+ }
10
+
11
+ export class UserTable extends Table<User> {
12
+ name = 'user';
13
+ columns = withRecordColumns<User>({
14
+ name: new StringColumn('name'),
15
+ email: new StringColumn('email', {}, 250),
16
+ password: new PasswordColumn('password'),
17
+ emailVerified: new BooleanColumn('email_verified'),
18
+ roles: new StringColumn('roles'),
19
+ });
20
+ };
@@ -0,0 +1,8 @@
1
+ import { UserTable, User } from './UserTable';
2
+ import { SessionTable, Session } from './SessionTable';
3
+ import { Table } from '@proteinjs/db';
4
+
5
+ export const tables = {
6
+ User: new UserTable() as Table<User>,
7
+ Session: new SessionTable() as Table<Session>,
8
+ }
@@ -0,0 +1,74 @@
1
+ import { Db, StringColumn, Table, Record, withRecordColumns } from '@proteinjs/db'
2
+ import { KnexDriver } from '@proteinjs/db-driver-knex'
3
+
4
+ export interface Favorite extends Record {
5
+ name: string;
6
+ scope?: string;
7
+ }
8
+
9
+ const veronicaUser = { name: 'Veronica', email: 'veroni@cake.com' };
10
+ const kevinUser = { name: 'Kevin', email: 'kev@tron.com' };
11
+ const veronicaScope = 'vvvveronica';
12
+ const kevinScope = 'kevinnn';
13
+ export class FavoriteTable extends Table<Favorite> {
14
+ name = 'user_test_user';
15
+ columns = withRecordColumns<Favorite>({
16
+ name: new StringColumn('name'),
17
+ scope: new StringColumn('scope', {
18
+ defaultValue: async (favorite: Favorite) => favorite.name.startsWith(veronicaUser.name) ? veronicaScope : kevinScope,
19
+ addToQuery: async (qb) => {
20
+ qb.condition({
21
+ field: 'scope',
22
+ operator: 'IN',
23
+ value: [veronicaScope]
24
+ });
25
+ },
26
+ }),
27
+ });
28
+ }
29
+
30
+ const dbDriver = new KnexDriver({
31
+ host: 'localhost',
32
+ user: 'root',
33
+ password: '',
34
+ dbName: 'test',
35
+ });
36
+ const dropTable = async (table: Table<any>) => {
37
+ if (await dbDriver.getKnex().schema.withSchema(dbDriver.getDbName()).hasTable(table.name))
38
+ await dbDriver.getKnex().schema.withSchema(dbDriver.getDbName()).dropTable(table.name);
39
+ }
40
+ const getTable = (tableName: string) => {
41
+ const userTable = new FavoriteTable();
42
+ if (userTable.name == tableName)
43
+ return userTable;
44
+
45
+ throw new Error('Cannot find test table');
46
+ };
47
+ const db = new Db(dbDriver, getTable);
48
+
49
+ describe('Scoped Record', () => {
50
+ beforeAll(async () => {
51
+ if (dbDriver.start)
52
+ await dbDriver.start();
53
+
54
+ await dbDriver.getTableManager().loadTable(new FavoriteTable());
55
+ })
56
+
57
+ afterAll(async () => {
58
+ await dropTable(new FavoriteTable());
59
+
60
+ if (dbDriver.stop)
61
+ await dbDriver.stop();
62
+ });
63
+
64
+ test('Query scoped records', async () => {
65
+ const favoriteTable: Table<Favorite> = new FavoriteTable();
66
+ await db.insert(favoriteTable, { name: `${veronicaUser.name}_favorite1` });
67
+ await db.insert(favoriteTable, { name: `${veronicaUser.name}_favorite2` });
68
+ await db.insert(favoriteTable, { name: `${veronicaUser.name}_favorite3` });
69
+ await db.insert(favoriteTable, { name: `${kevinUser.name}_favorite1` });
70
+ await db.insert(favoriteTable, { name: `${kevinUser.name}_favorite2` });
71
+ const favorites = await db.query(favoriteTable, {});
72
+ expect(favorites.length).toBe(3);
73
+ });
74
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./",
4
+ "target": "es5",
5
+ "module": "commonjs",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "outDir": "./dist/",
10
+ "strict": true,
11
+ "noImplicitAny": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "jsx": "react"
17
+ }
18
+ }