@veap/settings 0.1.0 → 0.1.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.
- package/README.md +3 -2
- package/dist/composition.d.ts +15 -0
- package/dist/composition.js +5 -0
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/contracts/settings.repository.d.ts +18 -1
- package/dist/contracts/settings.repository.js +4 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +7 -6
- package/dist/migrations/index.d.ts +1 -1
- package/dist/migrations/index.js +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.js +1 -1
- package/dist/models.d.ts +1 -1
- package/dist/models.js +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/settings.provider.js +23 -6
- package/dist/repositories/index.d.ts +1 -1
- package/dist/repositories/index.js +1 -1
- package/dist/repositories/setting.repository.d.ts +2 -1
- package/dist/repositories/setting.repository.js +12 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/settings.service.d.ts +14 -4
- package/dist/services/settings.service.js +22 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
[](https://github.com/veapjs/veap-settings/actions/workflows/CI.yml)
|
|
2
|
+
[](https://github.com/veapjs/veap-settings/actions/workflows/RELEASE.yml)
|
|
3
|
+
[](https://www.npmjs.com/package/@veap/settings)
|
|
3
4
|
|
|
4
5
|
# @veap/settings
|
|
5
6
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type SettingsConfig } from "./providers/settings.provider.js";
|
|
2
|
+
declare module "@veap/kernel" {
|
|
3
|
+
interface ApplicationBuilder {
|
|
4
|
+
/**
|
|
5
|
+
* Registers the SettingsServiceProvider into the application.
|
|
6
|
+
*/
|
|
7
|
+
withSettings(config?: SettingsConfig): this;
|
|
8
|
+
}
|
|
9
|
+
interface VeapConfig {
|
|
10
|
+
/**
|
|
11
|
+
* Configuration options for @veap/settings.
|
|
12
|
+
*/
|
|
13
|
+
settings?: SettingsConfig;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type ISettingsRepository, SETTINGS_REPOSITORY, } from "./settings.repository";
|
|
1
|
+
export { type ISettingsRepository, type ISettingsService, SETTINGS_REPOSITORY, SETTINGS_SERVICE, } from "./settings.repository.js";
|
package/dist/contracts/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SETTINGS_REPOSITORY, } from "./settings.repository";
|
|
1
|
+
export { SETTINGS_REPOSITORY, SETTINGS_SERVICE, } from "./settings.repository.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Token } from "@veap/kernel";
|
|
1
2
|
/**
|
|
2
3
|
* Settings persistence port.
|
|
3
4
|
*/
|
|
@@ -6,8 +7,24 @@ export interface ISettingsRepository {
|
|
|
6
7
|
set(key: string, value: unknown): Promise<void>;
|
|
7
8
|
delete(key: string): Promise<void>;
|
|
8
9
|
clear(): Promise<void>;
|
|
10
|
+
all?(): Promise<Record<string, unknown>>;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Injection token for the settings repository port.
|
|
12
14
|
*/
|
|
13
|
-
export declare const SETTINGS_REPOSITORY:
|
|
15
|
+
export declare const SETTINGS_REPOSITORY: Token<ISettingsRepository>;
|
|
16
|
+
/**
|
|
17
|
+
* Forward type reference for SettingsService in IoC tokens.
|
|
18
|
+
*/
|
|
19
|
+
export interface ISettingsService {
|
|
20
|
+
get<T>(key: string, defaultValue?: T | null): Promise<T | null>;
|
|
21
|
+
set(key: string, value: unknown): Promise<void>;
|
|
22
|
+
remove(key: string): Promise<void>;
|
|
23
|
+
clear(): Promise<void>;
|
|
24
|
+
has(key: string): Promise<boolean>;
|
|
25
|
+
all(): Promise<Record<string, unknown>>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Injection token for the settings application service.
|
|
29
|
+
*/
|
|
30
|
+
export declare const SETTINGS_SERVICE: Token<ISettingsService>;
|
|
@@ -2,3 +2,7 @@
|
|
|
2
2
|
* Injection token for the settings repository port.
|
|
3
3
|
*/
|
|
4
4
|
export const SETTINGS_REPOSITORY = Symbol.for("veap:settings:repository");
|
|
5
|
+
/**
|
|
6
|
+
* Injection token for the settings application service.
|
|
7
|
+
*/
|
|
8
|
+
export const SETTINGS_SERVICE = Symbol.for("veap:settings:service");
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
1
|
+
export * from "./composition.js";
|
|
2
|
+
export * from "./contracts/index.js";
|
|
3
|
+
export * from "./migrations/index.js";
|
|
4
|
+
export * from "./models/index.js";
|
|
5
|
+
export * from "./providers/index.js";
|
|
6
|
+
export * from "./repositories/index.js";
|
|
7
|
+
export * from "./services/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
1
|
+
export * from "./composition.js";
|
|
2
|
+
export * from "./contracts/index.js";
|
|
3
|
+
export * from "./migrations/index.js";
|
|
4
|
+
export * from "./models/index.js";
|
|
5
|
+
export * from "./providers/index.js";
|
|
6
|
+
export * from "./repositories/index.js";
|
|
7
|
+
export * from "./services/index.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as m0001 from "./0001_create_settings_table";
|
|
1
|
+
import * as m0001 from "./0001_create_settings_table.js";
|
|
2
2
|
export declare const settingsMigrations: (typeof m0001)[];
|
|
3
3
|
export declare function runSettingsMigrations(): Promise<void>;
|
|
4
4
|
export default settingsMigrations;
|
package/dist/migrations/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { runMigrations } from "@veap/database";
|
|
2
|
-
import * as m0001 from "./0001_create_settings_table";
|
|
2
|
+
import * as m0001 from "./0001_create_settings_table.js";
|
|
3
3
|
export const settingsMigrations = [m0001];
|
|
4
4
|
export async function runSettingsMigrations() {
|
|
5
5
|
await runMigrations("settings", settingsMigrations);
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Setting, type SettingAttributes, } from "./Setting";
|
|
1
|
+
export { Setting, type SettingAttributes, } from "./Setting.js";
|
package/dist/models/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Setting, } from "./Setting";
|
|
1
|
+
export { Setting, } from "./Setting.js";
|
package/dist/models.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./models/index";
|
|
1
|
+
export * from "./models/index.js";
|
package/dist/models.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./models/index";
|
|
1
|
+
export * from "./models/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { type SettingsConfig, SettingsServiceProvider, } from "./settings.provider";
|
|
1
|
+
export { type SettingsConfig, SettingsServiceProvider, } from "./settings.provider.js";
|
package/dist/providers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SettingsServiceProvider, } from "./settings.provider";
|
|
1
|
+
export { SettingsServiceProvider, } from "./settings.provider.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isDatabaseInitialized } from "@veap/database";
|
|
2
|
-
import { logger, ServiceProvider } from "@veap/kernel";
|
|
3
|
-
import { SETTINGS_REPOSITORY } from "../contracts/settings.repository";
|
|
4
|
-
import { runSettingsMigrations } from "../migrations";
|
|
5
|
-
import { ActiveRecordSettingsRepository } from "../repositories/setting.repository";
|
|
6
|
-
import { SettingsService } from "../services/settings.service";
|
|
2
|
+
import { ConfigService, logger, ServiceProvider, } from "@veap/kernel";
|
|
3
|
+
import { SETTINGS_REPOSITORY, SETTINGS_SERVICE, } from "../contracts/settings.repository.js";
|
|
4
|
+
import { runSettingsMigrations } from "../migrations/index.js";
|
|
5
|
+
import { ActiveRecordSettingsRepository } from "../repositories/setting.repository.js";
|
|
6
|
+
import { SettingsService } from "../services/settings.service.js";
|
|
7
7
|
export class SettingsServiceProvider extends ServiceProvider {
|
|
8
8
|
config;
|
|
9
9
|
constructor(container, config) {
|
|
@@ -21,9 +21,26 @@ export class SettingsServiceProvider extends ServiceProvider {
|
|
|
21
21
|
useClass: SettingsService,
|
|
22
22
|
singleton: true,
|
|
23
23
|
});
|
|
24
|
+
this.container.register({
|
|
25
|
+
token: SETTINGS_SERVICE,
|
|
26
|
+
useFactory: (service) => service,
|
|
27
|
+
inject: [SettingsService],
|
|
28
|
+
singleton: true,
|
|
29
|
+
});
|
|
24
30
|
}
|
|
25
31
|
async boot() {
|
|
26
|
-
|
|
32
|
+
const configService = this.container.has(ConfigService)
|
|
33
|
+
? await this.container.resolve(ConfigService)
|
|
34
|
+
: undefined;
|
|
35
|
+
const envAutoMigrate = configService?.get("SETTINGS_AUTO_MIGRATE") ??
|
|
36
|
+
(typeof process !== "undefined"
|
|
37
|
+
? process.env.SETTINGS_AUTO_MIGRATE
|
|
38
|
+
: undefined);
|
|
39
|
+
const shouldAutoMigrate = this.config?.autoMigrate ??
|
|
40
|
+
(envAutoMigrate !== undefined
|
|
41
|
+
? envAutoMigrate === "true" || envAutoMigrate === "1"
|
|
42
|
+
: true);
|
|
43
|
+
if (shouldAutoMigrate !== false && isDatabaseInitialized()) {
|
|
27
44
|
try {
|
|
28
45
|
await runSettingsMigrations();
|
|
29
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ActiveRecordSettingsRepository } from "./setting.repository";
|
|
1
|
+
export { ActiveRecordSettingsRepository } from "./setting.repository.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ActiveRecordSettingsRepository } from "./setting.repository";
|
|
1
|
+
export { ActiveRecordSettingsRepository } from "./setting.repository.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ISettingsRepository } from "../contracts/settings.repository";
|
|
1
|
+
import type { ISettingsRepository } from "../contracts/settings.repository.js";
|
|
2
2
|
/**
|
|
3
3
|
* `ISettingsRepository` adapter backed by the `Setting` ActiveRecord model.
|
|
4
4
|
*/
|
|
@@ -7,4 +7,5 @@ export declare class ActiveRecordSettingsRepository implements ISettingsReposito
|
|
|
7
7
|
set(key: string, value: unknown): Promise<void>;
|
|
8
8
|
delete(key: string): Promise<void>;
|
|
9
9
|
clear(): Promise<void>;
|
|
10
|
+
all(): Promise<Record<string, unknown>>;
|
|
10
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Setting } from "../models/Setting";
|
|
1
|
+
import { Setting } from "../models/Setting.js";
|
|
2
2
|
/**
|
|
3
3
|
* `ISettingsRepository` adapter backed by the `Setting` ActiveRecord model.
|
|
4
4
|
*/
|
|
@@ -15,4 +15,15 @@ export class ActiveRecordSettingsRepository {
|
|
|
15
15
|
async clear() {
|
|
16
16
|
await Setting.query().delete();
|
|
17
17
|
}
|
|
18
|
+
async all() {
|
|
19
|
+
const settings = await Setting.all();
|
|
20
|
+
const result = {};
|
|
21
|
+
for (const s of settings) {
|
|
22
|
+
const k = s.getAttribute("key");
|
|
23
|
+
if (k) {
|
|
24
|
+
result[k] = s.getAttribute("value");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
18
29
|
}
|
package/dist/server.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./index";
|
|
1
|
+
export * from "./index.js";
|
package/dist/server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./index";
|
|
1
|
+
export * from "./index.js";
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SettingsService } from "./settings.service";
|
|
1
|
+
export { SettingsService } from "./settings.service.js";
|
package/dist/services/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { SettingsService } from "./settings.service";
|
|
1
|
+
export { SettingsService } from "./settings.service.js";
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { type ICacheProvider } from "@veap/kernel";
|
|
2
|
-
import { type ISettingsRepository } from "../contracts/settings.repository";
|
|
2
|
+
import { type ISettingsRepository, type ISettingsService } from "../contracts/settings.repository.js";
|
|
3
3
|
/**
|
|
4
4
|
* Application service for reading and writing settings.
|
|
5
5
|
*
|
|
6
6
|
* It depends exclusively on ports (ICacheProvider, ISettingsRepository)
|
|
7
7
|
* that are injected through the constructor.
|
|
8
8
|
*/
|
|
9
|
-
export declare class SettingsService {
|
|
9
|
+
export declare class SettingsService implements ISettingsService {
|
|
10
10
|
private cache;
|
|
11
11
|
private repository;
|
|
12
12
|
constructor(cache: ICacheProvider, repository: ISettingsRepository);
|
|
13
13
|
/**
|
|
14
14
|
* Get a setting value by key.
|
|
15
15
|
* @param key Setting key (e.g., "system:page")
|
|
16
|
-
* @
|
|
16
|
+
* @param defaultValue Optional fallback value if the key does not exist
|
|
17
|
+
* @returns Value as T or defaultValue / null
|
|
17
18
|
*/
|
|
18
|
-
get<T>(key: string): Promise<T | null>;
|
|
19
|
+
get<T>(key: string, defaultValue?: T | null): Promise<T | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a setting exists.
|
|
22
|
+
* @param key Setting key
|
|
23
|
+
*/
|
|
24
|
+
has(key: string): Promise<boolean>;
|
|
19
25
|
/**
|
|
20
26
|
* Set a setting value.
|
|
21
27
|
* @param key Setting key
|
|
@@ -31,4 +37,8 @@ export declare class SettingsService {
|
|
|
31
37
|
* Clear all settings.
|
|
32
38
|
*/
|
|
33
39
|
clear(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Retrieve all settings as a key-value map.
|
|
42
|
+
*/
|
|
43
|
+
all(): Promise<Record<string, unknown>>;
|
|
34
44
|
}
|
|
@@ -11,7 +11,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
11
11
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
12
|
};
|
|
13
13
|
import { CACHE_PROVIDER, Inject, Injectable, } from "@veap/kernel";
|
|
14
|
-
import { SETTINGS_REPOSITORY, } from "../contracts/settings.repository";
|
|
14
|
+
import { SETTINGS_REPOSITORY, } from "../contracts/settings.repository.js";
|
|
15
15
|
/**
|
|
16
16
|
* Application service for reading and writing settings.
|
|
17
17
|
*
|
|
@@ -28,9 +28,10 @@ let SettingsService = class SettingsService {
|
|
|
28
28
|
/**
|
|
29
29
|
* Get a setting value by key.
|
|
30
30
|
* @param key Setting key (e.g., "system:page")
|
|
31
|
-
* @
|
|
31
|
+
* @param defaultValue Optional fallback value if the key does not exist
|
|
32
|
+
* @returns Value as T or defaultValue / null
|
|
32
33
|
*/
|
|
33
|
-
async get(key) {
|
|
34
|
+
async get(key, defaultValue = null) {
|
|
34
35
|
const cacheKey = `settings:${key}`;
|
|
35
36
|
const cached = await this.cache.get(cacheKey);
|
|
36
37
|
if (cached !== null)
|
|
@@ -38,8 +39,16 @@ let SettingsService = class SettingsService {
|
|
|
38
39
|
const value = await this.repository.get(key);
|
|
39
40
|
if (value !== null) {
|
|
40
41
|
await this.cache.set(cacheKey, value);
|
|
42
|
+
return value;
|
|
41
43
|
}
|
|
42
|
-
return
|
|
44
|
+
return defaultValue;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Check if a setting exists.
|
|
48
|
+
* @param key Setting key
|
|
49
|
+
*/
|
|
50
|
+
async has(key) {
|
|
51
|
+
return (await this.get(key)) !== null;
|
|
43
52
|
}
|
|
44
53
|
/**
|
|
45
54
|
* Set a setting value.
|
|
@@ -65,6 +74,15 @@ let SettingsService = class SettingsService {
|
|
|
65
74
|
await this.repository.clear();
|
|
66
75
|
await this.cache.clear();
|
|
67
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Retrieve all settings as a key-value map.
|
|
79
|
+
*/
|
|
80
|
+
async all() {
|
|
81
|
+
if (this.repository.all) {
|
|
82
|
+
return this.repository.all();
|
|
83
|
+
}
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
68
86
|
};
|
|
69
87
|
SettingsService = __decorate([
|
|
70
88
|
Injectable(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veap/settings",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Application settings management, caching, and persistence for Veap",
|
|
5
5
|
"bugs": "https://github.com/veapjs/veap-settings/issues",
|
|
6
6
|
"repository": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"test": "vitest run"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@veap/database": "0.1.
|
|
44
|
-
"@veap/kernel": "0.1.
|
|
43
|
+
"@veap/database": "0.1.1",
|
|
44
|
+
"@veap/kernel": "0.1.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^22.20.2",
|