@proteinjs/db-settings 1.0.2
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 +16 -0
- package/LICENSE +21 -0
- package/dist/generated/index.d.ts +8 -0
- package/dist/generated/index.d.ts.map +1 -0
- package/dist/generated/index.js +36 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/src/Settings.d.ts +13 -0
- package/dist/src/Settings.d.ts.map +1 -0
- package/dist/src/Settings.js +96 -0
- package/dist/src/Settings.js.map +1 -0
- package/dist/src/services/SettingsService.d.ts +7 -0
- package/dist/src/services/SettingsService.d.ts.map +1 -0
- package/dist/src/services/SettingsService.js +6 -0
- package/dist/src/services/SettingsService.js.map +1 -0
- package/dist/src/tables/SettingTable.d.ts +20 -0
- package/dist/src/tables/SettingTable.d.ts.map +1 -0
- package/dist/src/tables/SettingTable.js +43 -0
- package/dist/src/tables/SettingTable.js.map +1 -0
- package/dist/src/tables/tables.d.ts +6 -0
- package/dist/src/tables/tables.d.ts.map +1 -0
- package/dist/src/tables/tables.js +8 -0
- package/dist/src/tables/tables.js.map +1 -0
- package/generated/index.ts +32 -0
- package/index.ts +3 -0
- package/jest.config.js +18 -0
- package/package.json +41 -0
- package/src/Settings.ts +33 -0
- package/src/services/SettingsService.ts +8 -0
- package/src/tables/SettingTable.ts +22 -0
- package/src/tables/tables.ts +6 -0
- package/tsconfig.json +23 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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.2](https://github.com/brentbahry/db/compare/@proteinjs/db-settings@1.0.1...@proteinjs/db-settings@1.0.2) (2024-04-19)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @proteinjs/db-settings
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 1.0.1 (2024-04-19)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @proteinjs/db-settings
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,eAAe,CAAC;AACvB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,iBAAiB,CAAC;AACzB,OAAO,QAAQ,CAAC;AAyBhB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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/db");
|
|
19
|
+
require("@proteinjs/reflection");
|
|
20
|
+
require("@proteinjs/service");
|
|
21
|
+
require("@proteinjs/util");
|
|
22
|
+
require("moment");
|
|
23
|
+
/** Generate Source Graph */
|
|
24
|
+
var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/db-settings/Settings\",\"value\":{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"Settings\",\"filePath\":\"/home/runner/work/db/db/packages/settings/src/Settings.ts\",\"qualifiedName\":\"@proteinjs/db-settings/Settings\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceMetadata\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"get\",\"returnType\":null,\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"defaultValue\",\"type\":{\"packageName\":\"\",\"name\":\"T\",\"filePath\":null,\"qualifiedName\":\"/T\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"set\",\"returnType\":null,\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"value\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"SettingsService\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-settings/SettingsService\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/db-settings/SettingsService\",\"value\":{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"SettingsService\",\"filePath\":\"/home/runner/work/db/db/packages/settings/src/services/SettingsService.ts\",\"qualifiedName\":\"@proteinjs/db-settings/SettingsService\",\"properties\":[],\"methods\":[{\"name\":\"get\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<T>\",\"filePath\":null,\"qualifiedName\":\"/Promise<T>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"defaultValue\",\"type\":{\"packageName\":\"\",\"name\":\"T\",\"filePath\":null,\"qualifiedName\":\"/T\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"set\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"value\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/service/Service\"},{\"v\":\"@proteinjs/db-settings/Setting\",\"value\":{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"Setting\",\"filePath\":\"/home/runner/work/db/db/packages/settings/src/tables/SettingTable.ts\",\"qualifiedName\":\"@proteinjs/db-settings/Setting\",\"properties\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"value\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"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/db-settings/SettingTable\",\"value\":{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"SettingTable\",\"filePath\":\"/home/runner/work/db/db/packages/settings/src/tables/SettingTable.ts\",\"qualifiedName\":\"@proteinjs/db-settings/SettingTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"auth\",\"type\":{\"packageName\":\"\",\"name\":\"Table<Setting>['auth']\",\"filePath\":null,\"qualifiedName\":\"/Table<Setting>['auth']\",\"typeParameters\":null,\"directParents\":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/db-settings/Setting\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db/Table\"}],\"edges\":[{\"v\":\"@proteinjs/db-settings/Settings\",\"w\":\"@proteinjs/db-settings/SettingsService\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/db-settings/SettingsService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/db-settings/Setting\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/db-settings/SettingTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"}]}";
|
|
25
|
+
/** Generate Source Links */
|
|
26
|
+
var Settings_1 = require("../src/Settings");
|
|
27
|
+
var SettingTable_1 = require("../src/tables/SettingTable");
|
|
28
|
+
var sourceLinks = {
|
|
29
|
+
'@proteinjs/db-settings/Settings': Settings_1.Settings,
|
|
30
|
+
'@proteinjs/db-settings/SettingTable': SettingTable_1.SettingTable,
|
|
31
|
+
};
|
|
32
|
+
/** Load Source Graph and Links */
|
|
33
|
+
var reflection_1 = require("@proteinjs/reflection");
|
|
34
|
+
reflection_1.SourceRepository.merge(sourceGraph, sourceLinks);
|
|
35
|
+
__exportStar(require("../index"), exports);
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,yBAAuB;AACvB,iCAA+B;AAC/B,8BAA4B;AAC5B,2BAAyB;AACzB,kBAAgB;AAGhB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,woNAAwoN,CAAC;AAG7pN,4BAA4B;AAE5B,4CAA2C;AAC3C,2DAA0D;AAE1D,IAAM,WAAW,GAAG;IACnB,iCAAiC,EAAE,mBAAQ;IAC3C,qCAAqC,EAAE,2BAAY;CACnD,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAE/B,cAAc,gCAAgC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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/Settings"), exports);
|
|
18
|
+
__exportStar(require("./src/services/SettingsService"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B;AAE/B,iEAA+C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SettingsService } from './services/SettingsService';
|
|
2
|
+
export declare const getSettings: () => Settings;
|
|
3
|
+
export declare class Settings implements SettingsService {
|
|
4
|
+
private logger;
|
|
5
|
+
serviceMetadata: {
|
|
6
|
+
auth: {
|
|
7
|
+
allUsers: boolean;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
get<T>(name: string, defaultValue?: T): Promise<any>;
|
|
11
|
+
set(name: string, value: any): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=Settings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Settings.d.ts","sourceRoot":"","sources":["../../src/Settings.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAsB,MAAM,4BAA4B,CAAC;AAGjF,eAAO,MAAM,WAAW,gBAAwF,CAAC;AAEjH,qBAAa,QAAS,YAAW,eAAe;IAC9C,OAAO,CAAC,MAAM,CAAqC;IAC5C,eAAe;;;;MAIpB;IAEI,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC;IASrC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG;CAQnC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
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.Settings = exports.getSettings = void 0;
|
|
40
|
+
var db_1 = require("@proteinjs/db");
|
|
41
|
+
var util_1 = require("@proteinjs/util");
|
|
42
|
+
var SettingsService_1 = require("./services/SettingsService");
|
|
43
|
+
var tables_1 = require("./tables/tables");
|
|
44
|
+
var getSettings = function () { return typeof self === 'undefined' ? new Settings() : (0, SettingsService_1.getSettingsService)(); };
|
|
45
|
+
exports.getSettings = getSettings;
|
|
46
|
+
var Settings = /** @class */ (function () {
|
|
47
|
+
function Settings() {
|
|
48
|
+
this.logger = new util_1.Logger(this.constructor.name);
|
|
49
|
+
this.serviceMetadata = {
|
|
50
|
+
auth: {
|
|
51
|
+
allUsers: true,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
Settings.prototype.get = function (name, defaultValue) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var db, setting;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
db = (0, db_1.getDb)();
|
|
62
|
+
return [4 /*yield*/, db.get(tables_1.tables.Setting, { name: name })];
|
|
63
|
+
case 1:
|
|
64
|
+
setting = _a.sent();
|
|
65
|
+
if (!setting)
|
|
66
|
+
return [2 /*return*/, defaultValue];
|
|
67
|
+
return [2 /*return*/, setting.value];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
Settings.prototype.set = function (name, value) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
74
|
+
var db, rowsUpdated;
|
|
75
|
+
return __generator(this, function (_a) {
|
|
76
|
+
switch (_a.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
db = (0, db_1.getDb)();
|
|
79
|
+
return [4 /*yield*/, db.update(tables_1.tables.Setting, { value: value }, { name: name })];
|
|
80
|
+
case 1:
|
|
81
|
+
rowsUpdated = _a.sent();
|
|
82
|
+
if (!(rowsUpdated == 0)) return [3 /*break*/, 3];
|
|
83
|
+
this.logger.info("Creating new setting: ".concat(name));
|
|
84
|
+
return [4 /*yield*/, db.insert(tables_1.tables.Setting, { name: name, value: value })];
|
|
85
|
+
case 2:
|
|
86
|
+
_a.sent();
|
|
87
|
+
_a.label = 3;
|
|
88
|
+
case 3: return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
return Settings;
|
|
94
|
+
}());
|
|
95
|
+
exports.Settings = Settings;
|
|
96
|
+
//# sourceMappingURL=Settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Settings.js","sourceRoot":"","sources":["../../src/Settings.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAsC;AACtC,wCAAyC;AACzC,8DAAiF;AACjF,0CAAyC;AAElC,IAAM,WAAW,GAAG,cAAM,OAAA,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAA,oCAAkB,GAAc,EAA/E,CAA+E,CAAC;AAApG,QAAA,WAAW,eAAyF;AAEjH;IAAA;QACU,WAAM,GAAG,IAAI,aAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC5C,oBAAe,GAAG;YACvB,IAAI,EAAE;gBACJ,QAAQ,EAAE,IAAI;aACf;SACF,CAAC;IAmBJ,CAAC;IAjBO,sBAAG,GAAT,UAAa,IAAY,EAAE,YAAgB;;;;;;wBACnC,EAAE,GAAG,IAAA,UAAK,GAAE,CAAC;wBACH,qBAAM,EAAE,CAAC,GAAG,CAAC,eAAM,CAAC,OAAO,EAAE,EAAE,IAAI,MAAA,EAAE,CAAC,EAAA;;wBAAhD,OAAO,GAAG,SAAsC;wBACtD,IAAI,CAAC,OAAO;4BACV,sBAAO,YAAY,EAAC;wBAEtB,sBAAO,OAAO,CAAC,KAAK,EAAC;;;;KACtB;IAEK,sBAAG,GAAT,UAAU,IAAY,EAAE,KAAU;;;;;;wBAC1B,EAAE,GAAG,IAAA,UAAK,GAAE,CAAC;wBACC,qBAAM,EAAE,CAAC,MAAM,CAAC,eAAM,CAAC,OAAO,EAAE,EAAE,KAAK,OAAA,EAAE,EAAE,EAAE,IAAI,MAAA,EAAE,CAAC,EAAA;;wBAAlE,WAAW,GAAG,SAAoD;6BACpE,CAAA,WAAW,IAAI,CAAC,CAAA,EAAhB,wBAAgB;wBAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAyB,IAAI,CAAE,CAAC,CAAC;wBAClD,qBAAM,EAAE,CAAC,MAAM,CAAC,eAAM,CAAC,OAAO,EAAE,EAAE,IAAI,MAAA,EAAE,KAAK,OAAA,EAAE,CAAC,EAAA;;wBAAhD,SAAgD,CAAC;;;;;;KAEpD;IACH,eAAC;AAAD,CAAC,AAzBD,IAyBC;AAzBY,4BAAQ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Service } from '@proteinjs/service';
|
|
2
|
+
export declare const getSettingsService: () => SettingsService;
|
|
3
|
+
export interface SettingsService extends Service {
|
|
4
|
+
get<T>(name: string, defaultValue?: T): Promise<T>;
|
|
5
|
+
set(name: string, value: any): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=SettingsService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsService.d.ts","sourceRoot":"","sources":["../../../src/services/SettingsService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,oBAAoB,CAAC;AAE7D,eAAO,MAAM,kBAAkB,uBAA4E,CAAC;AAE5G,MAAM,WAAW,eAAgB,SAAQ,OAAO;IAC9C,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACnD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSettingsService = void 0;
|
|
4
|
+
var service_1 = require("@proteinjs/service");
|
|
5
|
+
exports.getSettingsService = (0, service_1.serviceFactory)('@proteinjs/db-settings/SettingsService');
|
|
6
|
+
//# sourceMappingURL=SettingsService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingsService.js","sourceRoot":"","sources":["../../../src/services/SettingsService.ts"],"names":[],"mappings":";;;AAAA,8CAA6D;AAEhD,QAAA,kBAAkB,GAAG,IAAA,wBAAc,EAAkB,wCAAwC,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Table, Record } from '@proteinjs/db';
|
|
2
|
+
export interface Setting extends Record {
|
|
3
|
+
name: string;
|
|
4
|
+
value: any;
|
|
5
|
+
}
|
|
6
|
+
export declare class SettingTable extends Table<Setting> {
|
|
7
|
+
name: string;
|
|
8
|
+
auth: Table<Setting>['auth'];
|
|
9
|
+
columns: {
|
|
10
|
+
id: import("@proteinjs/db").Column<string, any>;
|
|
11
|
+
created: import("@proteinjs/db").Column<import("moment").Moment, any>;
|
|
12
|
+
updated: import("@proteinjs/db").Column<import("moment").Moment, any>;
|
|
13
|
+
} & {} & {
|
|
14
|
+
name: import("@proteinjs/db").Column<string, any>;
|
|
15
|
+
value: import("@proteinjs/db").Column<any, any>;
|
|
16
|
+
} & {
|
|
17
|
+
value?: import("@proteinjs/db").Column<any, any> | undefined;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=SettingTable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingTable.d.ts","sourceRoot":"","sources":["../../../src/tables/SettingTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgB,MAAM,EAAmC,MAAM,eAAe,CAAC;AAE7F,MAAM,WAAW,OAAQ,SAAQ,MAAM;IACtC,IAAI,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,qBAAa,YAAa,SAAQ,KAAK,CAAC,OAAO,CAAC;IACxC,IAAI,SAAa;IACjB,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAOhC;IACI,OAAO;;;;;;;;;MAGX;CACH"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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.SettingTable = void 0;
|
|
19
|
+
var db_1 = require("@proteinjs/db");
|
|
20
|
+
var SettingTable = /** @class */ (function (_super) {
|
|
21
|
+
__extends(SettingTable, _super);
|
|
22
|
+
function SettingTable() {
|
|
23
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
24
|
+
_this.name = 'setting';
|
|
25
|
+
_this.auth = {
|
|
26
|
+
db: {
|
|
27
|
+
all: 'authenticated',
|
|
28
|
+
},
|
|
29
|
+
service: {
|
|
30
|
+
all: 'authenticated',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
_this.columns = (0, db_1.withRecordColumns)({
|
|
34
|
+
name: new db_1.StringColumn('name'),
|
|
35
|
+
value: new db_1.ObjectColumn('value'),
|
|
36
|
+
});
|
|
37
|
+
return _this;
|
|
38
|
+
}
|
|
39
|
+
return SettingTable;
|
|
40
|
+
}(db_1.Table));
|
|
41
|
+
exports.SettingTable = SettingTable;
|
|
42
|
+
;
|
|
43
|
+
//# sourceMappingURL=SettingTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SettingTable.js","sourceRoot":"","sources":["../../../src/tables/SettingTable.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,oCAA6F;AAO7F;IAAkC,gCAAc;IAAhD;QAAA,qEAcC;QAbO,UAAI,GAAG,SAAS,CAAC;QACjB,UAAI,GAA2B;YACnC,EAAE,EAAE;gBACF,GAAG,EAAE,eAAe;aACrB;YACD,OAAO,EAAE;gBACP,GAAG,EAAE,eAAe;aACrB;SACF,CAAC;QACI,aAAO,GAAG,IAAA,sBAAiB,EAAU;YACzC,IAAI,EAAE,IAAI,iBAAY,CAAC,MAAM,CAAC;YAC9B,KAAK,EAAE,IAAI,iBAAY,CAAC,OAAO,CAAC;SAClC,CAAC,CAAC;;IACJ,CAAC;IAAD,mBAAC;AAAD,CAAC,AAdD,CAAkC,UAAK,GActC;AAdY,oCAAY;AAcxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../../../src/tables/tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,OAAO,EAAgB,MAAM,gBAAgB,CAAC;AAEvD,eAAO,MAAM,MAAM;;CAElB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tables.js","sourceRoot":"","sources":["../../../src/tables/tables.ts"],"names":[],"mappings":";;;AACA,+CAAuD;AAE1C,QAAA,MAAM,GAAG;IACpB,OAAO,EAAE,IAAI,2BAAY,EAAoB;CAC9C,CAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Load Dependency Source Graphs */
|
|
2
|
+
|
|
3
|
+
import '@proteinjs/db';
|
|
4
|
+
import '@proteinjs/reflection';
|
|
5
|
+
import '@proteinjs/service';
|
|
6
|
+
import '@proteinjs/util';
|
|
7
|
+
import 'moment';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/** Generate Source Graph */
|
|
11
|
+
|
|
12
|
+
const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/db-settings/Settings\",\"value\":{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"Settings\",\"filePath\":\"/home/runner/work/db/db/packages/settings/src/Settings.ts\",\"qualifiedName\":\"@proteinjs/db-settings/Settings\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceMetadata\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"get\",\"returnType\":null,\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"defaultValue\",\"type\":{\"packageName\":\"\",\"name\":\"T\",\"filePath\":null,\"qualifiedName\":\"/T\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"set\",\"returnType\":null,\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"value\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"SettingsService\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/db-settings/SettingsService\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/db-settings/SettingsService\",\"value\":{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"SettingsService\",\"filePath\":\"/home/runner/work/db/db/packages/settings/src/services/SettingsService.ts\",\"qualifiedName\":\"@proteinjs/db-settings/SettingsService\",\"properties\":[],\"methods\":[{\"name\":\"get\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<T>\",\"filePath\":null,\"qualifiedName\":\"/Promise<T>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"defaultValue\",\"type\":{\"packageName\":\"\",\"name\":\"T\",\"filePath\":null,\"qualifiedName\":\"/T\",\"typeParameters\":null,\"directParents\":null}}]},{\"name\":\"set\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<void>\",\"filePath\":null,\"qualifiedName\":\"/Promise<void>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"value\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/service/Service\"},{\"v\":\"@proteinjs/db-settings/Setting\",\"value\":{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"Setting\",\"filePath\":\"/home/runner/work/db/db/packages/settings/src/tables/SettingTable.ts\",\"qualifiedName\":\"@proteinjs/db-settings/Setting\",\"properties\":[{\"name\":\"name\",\"type\":{\"packageName\":\"\",\"name\":\"string\",\"filePath\":null,\"qualifiedName\":\"/string\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"value\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"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/db-settings/SettingTable\",\"value\":{\"packageName\":\"@proteinjs/db-settings\",\"name\":\"SettingTable\",\"filePath\":\"/home/runner/work/db/db/packages/settings/src/tables/SettingTable.ts\",\"qualifiedName\":\"@proteinjs/db-settings/SettingTable\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"name\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"auth\",\"type\":{\"packageName\":\"\",\"name\":\"Table<Setting>['auth']\",\"filePath\":null,\"qualifiedName\":\"/Table<Setting>['auth']\",\"typeParameters\":null,\"directParents\":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/db-settings/Setting\"],\"directParentInterfaces\":[],\"directParentClasses\":[]}],\"sourceType\":2}},{\"v\":\"@proteinjs/db/Table\"}],\"edges\":[{\"v\":\"@proteinjs/db-settings/Settings\",\"w\":\"@proteinjs/db-settings/SettingsService\",\"value\":\"implements interface\"},{\"v\":\"@proteinjs/db-settings/SettingsService\",\"w\":\"@proteinjs/service/Service\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/db-settings/Setting\",\"w\":\"@proteinjs/db/Record\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/db-settings/SettingTable\",\"w\":\"@proteinjs/db/Table\",\"value\":\"extends class\"}]}";
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/** Generate Source Links */
|
|
16
|
+
|
|
17
|
+
import { Settings } from '../src/Settings';
|
|
18
|
+
import { SettingTable } from '../src/tables/SettingTable';
|
|
19
|
+
|
|
20
|
+
const sourceLinks = {
|
|
21
|
+
'@proteinjs/db-settings/Settings': Settings,
|
|
22
|
+
'@proteinjs/db-settings/SettingTable': SettingTable,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
/** Load Source Graph and Links */
|
|
27
|
+
|
|
28
|
+
import { SourceRepository } from '@proteinjs/reflection';
|
|
29
|
+
SourceRepository.merge(sourceGraph, sourceLinks);
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export * from '../index';
|
package/index.ts
ADDED
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,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@proteinjs/db-settings",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Db settings",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/brentbahry/db.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/brentbahry/db/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/brentbahry/db#readme",
|
|
16
|
+
"author": "Brent Bahry",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rm -rf dist/ node_modules/ generated/ package-lock.json",
|
|
20
|
+
"build": "reflection-build && tsc",
|
|
21
|
+
"watch": "reflection-watch"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@proteinjs/db": "^1.0.3",
|
|
25
|
+
"@proteinjs/reflection": "1.0.2",
|
|
26
|
+
"@proteinjs/service": "1.0.1",
|
|
27
|
+
"@proteinjs/util": "1.0.18",
|
|
28
|
+
"moment": "2.29.4"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@proteinjs/reflection-build": "1.0.5",
|
|
32
|
+
"@types/jest": "29.5.5",
|
|
33
|
+
"@types/node": "14.0.27",
|
|
34
|
+
"jest": "29.7.0",
|
|
35
|
+
"ts-jest": "29.1.1",
|
|
36
|
+
"typescript": "5.2.2"
|
|
37
|
+
},
|
|
38
|
+
"main": "./dist/generated/index.js",
|
|
39
|
+
"types": "./dist/generated/index.d.ts",
|
|
40
|
+
"gitHead": "05f576fa1cbd32912a08f7242b009d73103de30f"
|
|
41
|
+
}
|
package/src/Settings.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getDb } from '@proteinjs/db';
|
|
2
|
+
import { Logger } from '@proteinjs/util';
|
|
3
|
+
import { SettingsService, getSettingsService } from './services/SettingsService';
|
|
4
|
+
import { tables } from './tables/tables';
|
|
5
|
+
|
|
6
|
+
export const getSettings = () => typeof self === 'undefined' ? new Settings() : getSettingsService() as Settings;
|
|
7
|
+
|
|
8
|
+
export class Settings implements SettingsService {
|
|
9
|
+
private logger = new Logger(this.constructor.name);
|
|
10
|
+
public serviceMetadata = {
|
|
11
|
+
auth: {
|
|
12
|
+
allUsers: true,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
async get<T>(name: string, defaultValue?: T) {
|
|
17
|
+
const db = getDb();
|
|
18
|
+
const setting = await db.get(tables.Setting, { name });
|
|
19
|
+
if (!setting)
|
|
20
|
+
return defaultValue;
|
|
21
|
+
|
|
22
|
+
return setting.value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async set(name: string, value: any) {
|
|
26
|
+
const db = getDb();
|
|
27
|
+
const rowsUpdated = await db.update(tables.Setting, { value }, { name });
|
|
28
|
+
if (rowsUpdated == 0) {
|
|
29
|
+
this.logger.info(`Creating new setting: ${name}`);
|
|
30
|
+
await db.insert(tables.Setting, { name, value });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Service, serviceFactory } from '@proteinjs/service';
|
|
2
|
+
|
|
3
|
+
export const getSettingsService = serviceFactory<SettingsService>('@proteinjs/db-settings/SettingsService');
|
|
4
|
+
|
|
5
|
+
export interface SettingsService extends Service {
|
|
6
|
+
get<T>(name: string, defaultValue?: T): Promise<T>;
|
|
7
|
+
set(name: string, value: any): Promise<void>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Table, StringColumn, Record, withRecordColumns, ObjectColumn } from '@proteinjs/db';
|
|
2
|
+
|
|
3
|
+
export interface Setting extends Record {
|
|
4
|
+
name: string;
|
|
5
|
+
value: any;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class SettingTable extends Table<Setting> {
|
|
9
|
+
public name = 'setting';
|
|
10
|
+
public auth: Table<Setting>['auth'] = {
|
|
11
|
+
db: {
|
|
12
|
+
all: 'authenticated',
|
|
13
|
+
},
|
|
14
|
+
service: {
|
|
15
|
+
all: 'authenticated',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
public columns = withRecordColumns<Setting>({
|
|
19
|
+
name: new StringColumn('name'),
|
|
20
|
+
value: new ObjectColumn('value'),
|
|
21
|
+
});
|
|
22
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
"typeRoots": [
|
|
17
|
+
"./node_modules/@types"
|
|
18
|
+
],
|
|
19
|
+
"types": [
|
|
20
|
+
"node", "jest"
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
}
|