@zintrust/core 0.1.20 → 0.1.22
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/package.json +2 -1
- package/src/boot/Application.d.ts.map +1 -1
- package/src/boot/Application.js +48 -10
- package/src/boot/bootstrap.js +2 -0
- package/src/cli/commands/MigrateCommand.d.ts.map +1 -1
- package/src/cli/commands/MigrateCommand.js +37 -4
- package/src/cli/d1/D1SqlMigrations.d.ts.map +1 -1
- package/src/cli/d1/D1SqlMigrations.js +10 -4
- package/src/cli/scaffolding/ControllerGenerator.js +4 -4
- package/src/cli/scaffolding/GovernanceScaffolder.js +1 -1
- package/src/cli/scaffolding/MigrationGenerator.js +1 -1
- package/src/cli/scaffolding/ModelGenerator.d.ts +1 -1
- package/src/cli/scaffolding/ModelGenerator.d.ts.map +1 -1
- package/src/cli/scaffolding/ModelGenerator.js +11 -3
- package/src/cli/scaffolding/RouteGenerator.js +1 -1
- package/src/cli/scaffolding/ServiceScaffolder.js +4 -4
- package/src/config/broadcast.d.ts +14 -28
- package/src/config/broadcast.d.ts.map +1 -1
- package/src/config/broadcast.js +69 -35
- package/src/config/cache.d.ts +13 -45
- package/src/config/cache.d.ts.map +1 -1
- package/src/config/cache.js +69 -25
- package/src/config/database.d.ts +22 -64
- package/src/config/database.d.ts.map +1 -1
- package/src/config/database.js +99 -31
- package/src/config/env.d.ts +6 -0
- package/src/config/env.d.ts.map +1 -1
- package/src/config/env.js +7 -0
- package/src/config/index.d.ts +32 -136
- package/src/config/index.d.ts.map +1 -1
- package/src/config/mail.d.ts +19 -55
- package/src/config/mail.d.ts.map +1 -1
- package/src/config/mail.js +63 -21
- package/src/config/middleware.d.ts +24 -0
- package/src/config/middleware.d.ts.map +1 -1
- package/src/config/middleware.js +72 -52
- package/src/config/notification.d.ts +14 -27
- package/src/config/notification.d.ts.map +1 -1
- package/src/config/notification.js +82 -36
- package/src/config/queue.d.ts +21 -51
- package/src/config/queue.d.ts.map +1 -1
- package/src/config/queue.js +72 -27
- package/src/config/storage.d.ts +27 -34
- package/src/config/storage.d.ts.map +1 -1
- package/src/config/storage.js +97 -56
- package/src/config/type.d.ts +23 -1
- package/src/config/type.d.ts.map +1 -1
- package/src/config/type.js +10 -1
- package/src/http/parsers/MultipartParser.d.ts.map +1 -1
- package/src/http/parsers/MultipartParser.js +69 -42
- package/src/index.d.ts +9 -5
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/microservices/PostgresAdapter.d.ts.map +1 -1
- package/src/microservices/PostgresAdapter.js +0 -1
- package/src/migrations/MigrationLoader.d.ts +1 -1
- package/src/migrations/MigrationLoader.d.ts.map +1 -1
- package/src/migrations/Migrator.d.ts +3 -3
- package/src/migrations/Migrator.d.ts.map +1 -1
- package/src/migrations/Migrator.js +1 -1
- package/src/migrations/MigratorFactory.d.ts +1 -1
- package/src/migrations/MigratorFactory.d.ts.map +1 -1
- package/src/migrations/MigratorFactory.js +21 -5
- package/src/migrations/enum/index.d.ts +93 -0
- package/src/migrations/enum/index.d.ts.map +1 -0
- package/src/migrations/enum/index.js +92 -0
- package/src/migrations/schema/Blueprint.d.ts +1 -1
- package/src/migrations/schema/Blueprint.d.ts.map +1 -1
- package/src/migrations/schema/Blueprint.js +27 -25
- package/src/migrations/schema/Schema.d.ts +1 -1
- package/src/migrations/schema/Schema.d.ts.map +1 -1
- package/src/migrations/schema/Schema.js +4 -3
- package/src/migrations/schema/SchemaCompiler.d.ts +1 -1
- package/src/migrations/schema/SchemaCompiler.d.ts.map +1 -1
- package/src/migrations/schema/SchemaCompiler.js +99 -91
- package/src/migrations/schema/index.d.ts +4 -4
- package/src/migrations/schema/index.d.ts.map +1 -1
- package/src/migrations/schema/index.js +3 -3
- package/src/migrations/schema/types.d.ts +2 -1
- package/src/migrations/schema/types.d.ts.map +1 -1
- package/src/node-singletons/fs.d.ts +1 -1
- package/src/node-singletons/fs.d.ts.map +1 -1
- package/src/node-singletons/fs.js +1 -1
- package/src/orm/ConnectionManager.d.ts +6 -4
- package/src/orm/ConnectionManager.d.ts.map +1 -1
- package/src/orm/ConnectionManager.js +213 -75
- package/src/orm/Database.d.ts +4 -2
- package/src/orm/Database.d.ts.map +1 -1
- package/src/orm/Database.js +110 -67
- package/src/orm/DatabaseAdapter.d.ts +4 -2
- package/src/orm/DatabaseAdapter.d.ts.map +1 -1
- package/src/orm/DatabaseAdapter.js +17 -0
- package/src/orm/DatabaseRuntimeRegistration.d.ts.map +1 -1
- package/src/orm/DatabaseRuntimeRegistration.js +12 -0
- package/src/orm/Model.d.ts.map +1 -1
- package/src/orm/Model.js +24 -2
- package/src/orm/QueryBuilder.d.ts +1 -1
- package/src/orm/QueryBuilder.d.ts.map +1 -1
- package/src/orm/QueryBuilder.js +4 -3
- package/src/orm/adapters/D1Adapter.d.ts.map +1 -1
- package/src/orm/adapters/D1Adapter.js +2 -1
- package/src/orm/adapters/D1RemoteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/D1RemoteAdapter.js +2 -1
- package/src/orm/adapters/MySQLAdapter.d.ts.map +1 -1
- package/src/orm/adapters/MySQLAdapter.js +2 -1
- package/src/orm/adapters/SQLServerAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLServerAdapter.js +2 -1
- package/src/orm/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/src/orm/adapters/SQLiteAdapter.js +3 -2
- package/src/orm/migrations/MigrationStore.d.ts.map +1 -1
- package/src/performance/Optimizer.d.ts +6 -6
- package/src/performance/Optimizer.d.ts.map +1 -1
- package/src/performance/Optimizer.js +174 -52
- package/src/profiling/RequestProfiler.d.ts.map +1 -1
- package/src/profiling/RequestProfiler.js +3 -1
- package/src/routing/doc.d.ts +4 -5
- package/src/routing/doc.d.ts.map +1 -1
- package/src/routing/doc.js +35 -20
- package/src/routing/publicRoot.d.ts +9 -0
- package/src/routing/publicRoot.d.ts.map +1 -1
- package/src/routing/publicRoot.js +63 -2
- package/src/runtime/StartupConfigFileRegistry.d.ts +21 -0
- package/src/runtime/StartupConfigFileRegistry.d.ts.map +1 -0
- package/src/runtime/StartupConfigFileRegistry.js +43 -0
- package/src/runtime/useFileLoader.d.ts +26 -0
- package/src/runtime/useFileLoader.d.ts.map +1 -0
- package/src/runtime/useFileLoader.js +188 -0
- package/src/scripts/TemplateSync.js +4 -4
- package/src/security/XssProtection.d.ts.map +1 -1
- package/src/security/XssProtection.js +62 -14
- package/src/templates/project/basic/config/broadcast.ts.tpl +33 -17
- package/src/templates/project/basic/config/cache.ts.tpl +35 -17
- package/src/templates/project/basic/config/database.ts.tpl +68 -32
- package/src/templates/project/basic/config/logging/HttpLogger.ts.tpl +7 -114
- package/src/templates/project/basic/config/mail.ts.tpl +59 -13
- package/src/templates/project/basic/config/notification.ts.tpl +28 -17
- package/src/templates/project/basic/config/queue.ts.tpl +49 -17
- package/src/templates/project/basic/config/storage.ts.tpl +55 -18
- package/src/templates/project/basic/config/type.ts.tpl +0 -1
- package/src/templates/project/basic/src/index.ts.tpl +3 -0
- package/src/templates/project/basic/config/logging/KvLogger.ts.tpl +0 -181
- package/src/templates/project/basic/config/logging/SlackLogger.ts.tpl +0 -156
|
@@ -5,33 +5,20 @@
|
|
|
5
5
|
* Driver selection must be dynamic (tests may mutate process.env).
|
|
6
6
|
*/
|
|
7
7
|
import type { KnownNotificationDriverConfig, NotificationDrivers, NotificationProviders } from './type';
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
readonly default: string;
|
|
13
|
-
/**
|
|
14
|
-
* Notification channels.
|
|
15
|
-
*
|
|
16
|
-
* You may add custom named channels (e.g. `opsSlack`, `smsMarketing`) that
|
|
17
|
-
* point to any known driver config.
|
|
18
|
-
*/
|
|
19
|
-
readonly drivers: NotificationDrivers;
|
|
20
|
-
/**
|
|
21
|
-
* Legacy provider configs (kept for backwards compatibility with wrappers).
|
|
22
|
-
*/
|
|
23
|
-
readonly providers: NotificationProviders;
|
|
24
|
-
/**
|
|
25
|
-
* Normalized notification channel name.
|
|
26
|
-
*/
|
|
27
|
-
readonly getDriverName: () => string;
|
|
28
|
-
/**
|
|
29
|
-
* Resolve a channel config.
|
|
30
|
-
* - Unknown names throw when explicitly selected.
|
|
31
|
-
* - `default` is a reserved alias of the configured default.
|
|
32
|
-
*/
|
|
33
|
-
readonly getDriverConfig: (name?: string) => KnownNotificationDriverConfig;
|
|
8
|
+
export type NotificationConfigOverrides = Partial<{
|
|
9
|
+
default: string;
|
|
10
|
+
drivers: NotificationDrivers;
|
|
11
|
+
providers: NotificationProviders;
|
|
34
12
|
}>;
|
|
35
|
-
|
|
13
|
+
type NotificationRuntimeConfig = {
|
|
14
|
+
default: string;
|
|
15
|
+
drivers: NotificationDrivers;
|
|
16
|
+
providers: NotificationProviders;
|
|
17
|
+
getDriverName: () => string;
|
|
18
|
+
getDriverConfig: (name?: string) => KnownNotificationDriverConfig;
|
|
19
|
+
};
|
|
20
|
+
declare const createNotificationConfig: () => NotificationRuntimeConfig;
|
|
21
|
+
export type NotificationConfig = ReturnType<typeof createNotificationConfig>;
|
|
22
|
+
export declare const notificationConfig: NotificationConfig;
|
|
36
23
|
export default notificationConfig;
|
|
37
24
|
//# sourceMappingURL=notification.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../../src/config/notification.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../../src/config/notification.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EACV,6BAA6B,EAE7B,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,cAAc,CAAC;AAGtB,MAAM,MAAM,2BAA2B,GAAG,OAAO,CAAC;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,SAAS,EAAE,qBAAqB,CAAC;CAClC,CAAC,CAAC;AAEH,KAAK,yBAAyB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,SAAS,EAAE,qBAAqB,CAAC;IACjC,aAAa,EAAE,MAAM,MAAM,CAAC;IAC5B,eAAe,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,6BAA6B,CAAC;CACnE,CAAC;AA2EF,QAAA,MAAM,wBAAwB,QAAO,yBA+DpC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAqB7E,eAAO,MAAM,kBAAkB,EAAE,kBAY/B,CAAC;AAEH,eAAe,kBAAkB,CAAC"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Config-first mapping of notification providers/channels.
|
|
5
5
|
* Driver selection must be dynamic (tests may mutate process.env).
|
|
6
6
|
*/
|
|
7
|
+
import { StartupConfigFile, StartupConfigFileRegistry } from '../runtime/StartupConfigFileRegistry.js';
|
|
7
8
|
import { Env } from './env.js';
|
|
8
9
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
9
10
|
const normalizeName = (value) => value.trim().toLowerCase();
|
|
@@ -61,43 +62,88 @@ const getBaseProviders = () => {
|
|
|
61
62
|
},
|
|
62
63
|
};
|
|
63
64
|
};
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
const createNotificationConfig = () => {
|
|
66
|
+
const overrides = StartupConfigFileRegistry.get(StartupConfigFile.Notification) ??
|
|
67
|
+
{};
|
|
68
|
+
const notificationConfigObj = {
|
|
69
|
+
/**
|
|
70
|
+
* Default notification channel name (normalized).
|
|
71
|
+
*/
|
|
72
|
+
get default() {
|
|
73
|
+
const overrideDefault = overrides.default;
|
|
74
|
+
if (typeof overrideDefault === 'string' && overrideDefault.trim().length > 0) {
|
|
75
|
+
const value = normalizeName(overrideDefault);
|
|
76
|
+
if (value.length > 0 && hasOwn(this.drivers, value))
|
|
77
|
+
return value;
|
|
78
|
+
throw ErrorFactory.createConfigError(`Notification channel not configured: ${value}`);
|
|
79
|
+
}
|
|
80
|
+
return getDefaultChannel(this.drivers);
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Notification channels.
|
|
84
|
+
*
|
|
85
|
+
* You may add custom named channels (e.g. `opsSlack`, `smsMarketing`) that
|
|
86
|
+
* point to any known driver config.
|
|
87
|
+
*/
|
|
88
|
+
get drivers() {
|
|
89
|
+
// Return a record of channels; can be extended by app-level config.
|
|
90
|
+
return {
|
|
91
|
+
...getBaseProviders(),
|
|
92
|
+
...(overrides.providers ?? {}),
|
|
93
|
+
...(overrides.drivers ?? {}),
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
/**
|
|
97
|
+
* Legacy provider configs (kept for backwards compatibility with wrappers).
|
|
98
|
+
*/
|
|
99
|
+
get providers() {
|
|
100
|
+
return {
|
|
101
|
+
...getBaseProviders(),
|
|
102
|
+
...(overrides.providers ?? {}),
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* Normalized notification channel name.
|
|
107
|
+
*/
|
|
108
|
+
getDriverName() {
|
|
109
|
+
return normalizeName(this.default);
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Resolve a channel config.
|
|
113
|
+
* - Unknown names throw when explicitly selected.
|
|
114
|
+
* - `default` is a reserved alias of the configured default.
|
|
115
|
+
*/
|
|
116
|
+
getDriverConfig(name) {
|
|
117
|
+
return getNotificationDriver(this, name);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
return Object.freeze(notificationConfigObj);
|
|
121
|
+
};
|
|
122
|
+
let cached = null;
|
|
123
|
+
const proxyTarget = {};
|
|
124
|
+
const ensureNotificationConfig = () => {
|
|
125
|
+
if (cached)
|
|
126
|
+
return cached;
|
|
127
|
+
cached = createNotificationConfig();
|
|
128
|
+
try {
|
|
129
|
+
Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(cached));
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// best-effort
|
|
133
|
+
}
|
|
134
|
+
return cached;
|
|
135
|
+
};
|
|
136
|
+
export const notificationConfig = new Proxy(proxyTarget, {
|
|
137
|
+
get(_target, prop) {
|
|
138
|
+
return ensureNotificationConfig()[prop];
|
|
86
139
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
getDriverName() {
|
|
91
|
-
return normalizeName(this.default);
|
|
140
|
+
ownKeys() {
|
|
141
|
+
ensureNotificationConfig();
|
|
142
|
+
return Reflect.ownKeys(proxyTarget);
|
|
92
143
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
* - `default` is a reserved alias of the configured default.
|
|
97
|
-
*/
|
|
98
|
-
getDriverConfig(name) {
|
|
99
|
-
return getNotificationDriver(this, name);
|
|
144
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
145
|
+
ensureNotificationConfig();
|
|
146
|
+
return Object.getOwnPropertyDescriptor(proxyTarget, prop);
|
|
100
147
|
},
|
|
101
|
-
};
|
|
102
|
-
export const notificationConfig = Object.freeze(notificationConfigObj);
|
|
148
|
+
});
|
|
103
149
|
export default notificationConfig;
|
package/src/config/queue.d.ts
CHANGED
|
@@ -3,61 +3,14 @@
|
|
|
3
3
|
* Background job and message queue settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
-
import type { QueueDriverName, QueueDriversConfig } from './type';
|
|
7
|
-
export
|
|
8
|
-
/**
|
|
9
|
-
* Default queue driver
|
|
10
|
-
*/
|
|
6
|
+
import type { QueueConfigWithDrivers, QueueDriverName, QueueDriversConfig } from './type';
|
|
7
|
+
export type QueueConfigOverrides = Partial<{
|
|
11
8
|
default: QueueDriverName;
|
|
12
|
-
|
|
13
|
-
* Queue drivers
|
|
14
|
-
*/
|
|
15
|
-
drivers: {
|
|
16
|
-
sync: {
|
|
17
|
-
driver: "sync";
|
|
18
|
-
};
|
|
19
|
-
database: {
|
|
20
|
-
driver: "database";
|
|
21
|
-
table: string;
|
|
22
|
-
connection: string;
|
|
23
|
-
};
|
|
24
|
-
redis: {
|
|
25
|
-
driver: "redis";
|
|
26
|
-
host: string;
|
|
27
|
-
port: number;
|
|
28
|
-
password: string;
|
|
29
|
-
database: number;
|
|
30
|
-
};
|
|
31
|
-
rabbitmq: {
|
|
32
|
-
driver: "rabbitmq";
|
|
33
|
-
host: string;
|
|
34
|
-
port: number;
|
|
35
|
-
username: string;
|
|
36
|
-
password: string;
|
|
37
|
-
vhost: string;
|
|
38
|
-
};
|
|
39
|
-
sqs: {
|
|
40
|
-
driver: "sqs";
|
|
41
|
-
key: string;
|
|
42
|
-
secret: string;
|
|
43
|
-
region: string;
|
|
44
|
-
queueUrl: string;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Get queue driver config
|
|
49
|
-
*/
|
|
50
|
-
getDriver(): QueueDriversConfig[QueueDriverName];
|
|
51
|
-
/**
|
|
52
|
-
* Failed jobs table
|
|
53
|
-
*/
|
|
9
|
+
drivers: Partial<QueueDriversConfig>;
|
|
54
10
|
failed: {
|
|
55
11
|
database: string;
|
|
56
12
|
table: string;
|
|
57
13
|
};
|
|
58
|
-
/**
|
|
59
|
-
* Job processing
|
|
60
|
-
*/
|
|
61
14
|
processing: {
|
|
62
15
|
timeout: number;
|
|
63
16
|
retries: number;
|
|
@@ -65,5 +18,22 @@ export declare const queueConfig: Readonly<{
|
|
|
65
18
|
workers: number;
|
|
66
19
|
};
|
|
67
20
|
}>;
|
|
68
|
-
|
|
21
|
+
declare const createQueueConfig: () => {
|
|
22
|
+
default: QueueDriverName;
|
|
23
|
+
drivers: QueueDriversConfig;
|
|
24
|
+
getDriver: (this: QueueConfigWithDrivers) => QueueDriversConfig[QueueDriverName];
|
|
25
|
+
failed: {
|
|
26
|
+
database: string;
|
|
27
|
+
table: string;
|
|
28
|
+
};
|
|
29
|
+
processing: {
|
|
30
|
+
timeout: number;
|
|
31
|
+
retries: number;
|
|
32
|
+
backoff: number;
|
|
33
|
+
workers: number;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type QueueConfig = ReturnType<typeof createQueueConfig>;
|
|
37
|
+
export declare const queueConfig: QueueConfig;
|
|
38
|
+
export {};
|
|
69
39
|
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/config/queue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/config/queue.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,sBAAsB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEhG,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAC;IACzC,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACrC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,UAAU,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CACpF,CAAC,CAAC;AAOH,QAAA,MAAM,iBAAiB,QAAO;IAC5B,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,SAAS,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,kBAAkB,CAAC,eAAe,CAAC,CAAC;IACjF,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5C,UAAU,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CA4FpF,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAqB/D,eAAO,MAAM,WAAW,EAAE,WAYxB,CAAC"}
|
package/src/config/queue.js
CHANGED
|
@@ -4,19 +4,15 @@
|
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
6
|
import { Env } from './env.js';
|
|
7
|
+
import { StartupConfigFile, StartupConfigFileRegistry } from '../runtime/StartupConfigFileRegistry.js';
|
|
7
8
|
const getQueueDriver = (config) => {
|
|
8
9
|
const driverName = config.default;
|
|
9
10
|
return config.drivers[driverName];
|
|
10
11
|
};
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
default: Env.get('QUEUE_DRIVER', 'sync'),
|
|
16
|
-
/**
|
|
17
|
-
* Queue drivers
|
|
18
|
-
*/
|
|
19
|
-
drivers: {
|
|
12
|
+
const createQueueConfig = () => {
|
|
13
|
+
const overrides = StartupConfigFileRegistry.get(StartupConfigFile.Queue) ?? {};
|
|
14
|
+
const baseDefault = Env.get('QUEUE_DRIVER', 'sync');
|
|
15
|
+
const baseDrivers = {
|
|
20
16
|
sync: {
|
|
21
17
|
driver: 'sync',
|
|
22
18
|
},
|
|
@@ -47,28 +43,77 @@ const queueConfigObj = {
|
|
|
47
43
|
region: Env.AWS_REGION,
|
|
48
44
|
queueUrl: Env.get('AWS_SQS_QUEUE_URL'),
|
|
49
45
|
},
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
* Get queue driver config
|
|
53
|
-
*/
|
|
54
|
-
getDriver() {
|
|
55
|
-
return getQueueDriver(this);
|
|
56
|
-
},
|
|
57
|
-
/**
|
|
58
|
-
* Failed jobs table
|
|
59
|
-
*/
|
|
60
|
-
failed: {
|
|
46
|
+
};
|
|
47
|
+
const baseFailed = {
|
|
61
48
|
database: Env.get('FAILED_JOBS_DB_CONNECTION', 'default'),
|
|
62
49
|
table: Env.get('FAILED_JOBS_TABLE', 'failed_jobs'),
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
* Job processing
|
|
66
|
-
*/
|
|
67
|
-
processing: {
|
|
50
|
+
};
|
|
51
|
+
const baseProcessing = {
|
|
68
52
|
timeout: Env.getInt('QUEUE_JOB_TIMEOUT', 60),
|
|
69
53
|
retries: Env.getInt('QUEUE_JOB_RETRIES', 3),
|
|
70
54
|
backoff: Env.getInt('QUEUE_JOB_BACKOFF', 0),
|
|
71
55
|
workers: Env.getInt('QUEUE_WORKERS', 1),
|
|
72
|
-
}
|
|
56
|
+
};
|
|
57
|
+
const mergedDrivers = {
|
|
58
|
+
...baseDrivers,
|
|
59
|
+
...(overrides.drivers ?? {}),
|
|
60
|
+
};
|
|
61
|
+
const queueConfigObj = {
|
|
62
|
+
/**
|
|
63
|
+
* Default queue driver
|
|
64
|
+
*/
|
|
65
|
+
default: (overrides.default ?? baseDefault),
|
|
66
|
+
/**
|
|
67
|
+
* Queue drivers
|
|
68
|
+
*/
|
|
69
|
+
drivers: mergedDrivers,
|
|
70
|
+
/**
|
|
71
|
+
* Get queue driver config
|
|
72
|
+
*/
|
|
73
|
+
getDriver() {
|
|
74
|
+
return getQueueDriver(this);
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Failed jobs table
|
|
78
|
+
*/
|
|
79
|
+
failed: {
|
|
80
|
+
...baseFailed,
|
|
81
|
+
...(overrides.failed ?? {}),
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Job processing
|
|
85
|
+
*/
|
|
86
|
+
processing: {
|
|
87
|
+
...baseProcessing,
|
|
88
|
+
...(overrides.processing ?? {}),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
return Object.freeze(queueConfigObj);
|
|
92
|
+
};
|
|
93
|
+
let cached = null;
|
|
94
|
+
const proxyTarget = {};
|
|
95
|
+
const ensureQueueConfig = () => {
|
|
96
|
+
if (cached)
|
|
97
|
+
return cached;
|
|
98
|
+
cached = createQueueConfig();
|
|
99
|
+
try {
|
|
100
|
+
Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(cached));
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// best-effort
|
|
104
|
+
}
|
|
105
|
+
return cached;
|
|
73
106
|
};
|
|
74
|
-
export const queueConfig =
|
|
107
|
+
export const queueConfig = new Proxy(proxyTarget, {
|
|
108
|
+
get(_target, prop) {
|
|
109
|
+
return ensureQueueConfig()[prop];
|
|
110
|
+
},
|
|
111
|
+
ownKeys() {
|
|
112
|
+
ensureQueueConfig();
|
|
113
|
+
return Reflect.ownKeys(proxyTarget);
|
|
114
|
+
},
|
|
115
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
116
|
+
ensureQueueConfig();
|
|
117
|
+
return Object.getOwnPropertyDescriptor(proxyTarget, prop);
|
|
118
|
+
},
|
|
119
|
+
});
|
package/src/config/storage.d.ts
CHANGED
|
@@ -4,49 +4,42 @@
|
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
6
|
import type { StorageConfigRuntime, StorageDriverConfig, StorageDrivers } from './type';
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
readonly default: string;
|
|
12
|
-
/**
|
|
13
|
-
* Storage drivers configuration (dynamic; tests may mutate process.env)
|
|
14
|
-
*/
|
|
15
|
-
readonly drivers: StorageDrivers;
|
|
16
|
-
/**
|
|
17
|
-
* Get storage driver config
|
|
18
|
-
*/
|
|
19
|
-
getDriver(this: StorageConfigRuntime): StorageDriverConfig;
|
|
20
|
-
/**
|
|
21
|
-
* Get a storage disk configuration by name.
|
|
22
|
-
*
|
|
23
|
-
* - When `name` is provided and not configured, this throws.
|
|
24
|
-
* - When `name` is omitted, it resolves the configured default with a backwards-compatible fallback.
|
|
25
|
-
* - Reserved name `default` aliases the configured default.
|
|
26
|
-
*/
|
|
27
|
-
getDriverConfig(this: StorageConfigRuntime, name?: string): StorageDriverConfig;
|
|
28
|
-
/**
|
|
29
|
-
* Temporary file settings
|
|
30
|
-
*/
|
|
31
|
-
readonly temp: {
|
|
7
|
+
export type StorageConfigOverrides = Partial<{
|
|
8
|
+
default: string;
|
|
9
|
+
drivers: Partial<StorageDrivers> & Record<string, StorageDriverConfig>;
|
|
10
|
+
temp: {
|
|
32
11
|
path: string;
|
|
33
12
|
maxAge: number;
|
|
34
13
|
};
|
|
35
|
-
|
|
36
|
-
* Uploads settings
|
|
37
|
-
*/
|
|
38
|
-
readonly uploads: {
|
|
14
|
+
uploads: {
|
|
39
15
|
maxSize: string;
|
|
40
16
|
allowedMimes: string;
|
|
41
17
|
path: string;
|
|
42
18
|
};
|
|
43
|
-
|
|
44
|
-
* Backups settings
|
|
45
|
-
*/
|
|
46
|
-
readonly backups: {
|
|
19
|
+
backups: {
|
|
47
20
|
path: string;
|
|
48
21
|
driver: string;
|
|
49
22
|
};
|
|
50
23
|
}>;
|
|
51
|
-
|
|
24
|
+
type StorageRuntimeConfig = StorageConfigRuntime & {
|
|
25
|
+
getDriver: (this: StorageConfigRuntime) => StorageDriverConfig;
|
|
26
|
+
getDriverConfig: (this: StorageConfigRuntime, name?: string) => StorageDriverConfig;
|
|
27
|
+
temp: {
|
|
28
|
+
path: string;
|
|
29
|
+
maxAge: number;
|
|
30
|
+
};
|
|
31
|
+
uploads: {
|
|
32
|
+
maxSize: string;
|
|
33
|
+
allowedMimes: string;
|
|
34
|
+
path: string;
|
|
35
|
+
};
|
|
36
|
+
backups: {
|
|
37
|
+
path: string;
|
|
38
|
+
driver: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
declare const createStorageConfig: () => StorageRuntimeConfig;
|
|
42
|
+
export type StorageConfig = ReturnType<typeof createStorageConfig>;
|
|
43
|
+
export declare const storageConfig: StorageConfig;
|
|
44
|
+
export {};
|
|
52
45
|
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/config/storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/config/storage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9F,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAAC;IAC3C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IACvE,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACjE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C,CAAC,CAAC;AAEH,KAAK,oBAAoB,GAAG,oBAAoB,GAAG;IACjD,SAAS,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,mBAAmB,CAAC;IAC/D,eAAe,EAAE,CAAC,IAAI,EAAE,oBAAoB,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,mBAAmB,CAAC;IACpF,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACjE,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C,CAAC;AAgEF,QAAA,MAAM,mBAAmB,QAAO,oBAgF/B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAqBnE,eAAO,MAAM,aAAa,EAAE,aAY1B,CAAC"}
|
package/src/config/storage.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* File storage and cloud storage settings
|
|
4
4
|
* Sealed namespace for immutability
|
|
5
5
|
*/
|
|
6
|
+
import { StartupConfigFile, StartupConfigFileRegistry } from '../runtime/StartupConfigFileRegistry.js';
|
|
6
7
|
import { Env } from './env.js';
|
|
7
8
|
import { ErrorFactory } from '../exceptions/ZintrustError.js';
|
|
8
9
|
const hasOwn = (obj, key) => {
|
|
@@ -59,62 +60,102 @@ const getDrivers = () => ({
|
|
|
59
60
|
url: Env.get('GCS_URL', ''),
|
|
60
61
|
},
|
|
61
62
|
});
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
63
|
+
const createStorageConfig = () => {
|
|
64
|
+
const overrides = StartupConfigFileRegistry.get(StartupConfigFile.Storage) ?? {};
|
|
65
|
+
const storageConfigObj = {
|
|
66
|
+
/**
|
|
67
|
+
* Default storage driver (dynamic; tests may mutate process.env)
|
|
68
|
+
*/
|
|
69
|
+
get default() {
|
|
70
|
+
const base = Env.get('STORAGE_CONNECTION', Env.get('STORAGE_DRIVER', 'local'))
|
|
71
|
+
.trim()
|
|
72
|
+
.toLowerCase();
|
|
73
|
+
const selected = overrides.default ?? base;
|
|
74
|
+
return String(selected).trim().toLowerCase();
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Storage drivers configuration (dynamic; tests may mutate process.env)
|
|
78
|
+
*/
|
|
79
|
+
get drivers() {
|
|
80
|
+
return {
|
|
81
|
+
...getDrivers(),
|
|
82
|
+
...overrides.drivers,
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* Get storage driver config
|
|
87
|
+
*/
|
|
88
|
+
getDriver() {
|
|
89
|
+
return getStorageDriver(this);
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Get a storage disk configuration by name.
|
|
93
|
+
*
|
|
94
|
+
* - When `name` is provided and not configured, this throws.
|
|
95
|
+
* - When `name` is omitted, it resolves the configured default with a backwards-compatible fallback.
|
|
96
|
+
* - Reserved name `default` aliases the configured default.
|
|
97
|
+
*/
|
|
98
|
+
getDriverConfig(name) {
|
|
99
|
+
return getStorageDriver(this, name);
|
|
100
|
+
},
|
|
101
|
+
/**
|
|
102
|
+
* Temporary file settings
|
|
103
|
+
*/
|
|
104
|
+
get temp() {
|
|
105
|
+
return {
|
|
106
|
+
path: Env.get('TEMP_PATH', 'storage/temp'),
|
|
107
|
+
maxAge: Env.getInt('TEMP_FILE_MAX_AGE', 86400), // 24 hours
|
|
108
|
+
...overrides.temp,
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Uploads settings
|
|
113
|
+
*/
|
|
114
|
+
get uploads() {
|
|
115
|
+
return {
|
|
116
|
+
maxSize: Env.get('MAX_UPLOAD_SIZE', '100mb'),
|
|
117
|
+
allowedMimes: Env.get('ALLOWED_UPLOAD_MIMES', 'jpg,jpeg,png,pdf,doc,docx'),
|
|
118
|
+
path: Env.get('UPLOADS_PATH', 'storage/uploads'),
|
|
119
|
+
...overrides.uploads,
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
/**
|
|
123
|
+
* Backups settings
|
|
124
|
+
*/
|
|
125
|
+
get backups() {
|
|
126
|
+
return {
|
|
127
|
+
path: Env.get('BACKUPS_PATH', 'storage/backups'),
|
|
128
|
+
driver: Env.get('BACKUP_DRIVER', 's3'),
|
|
129
|
+
...overrides.backups,
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
return Object.freeze(storageConfigObj);
|
|
134
|
+
};
|
|
135
|
+
let cached = null;
|
|
136
|
+
const proxyTarget = {};
|
|
137
|
+
const ensureStorageConfig = () => {
|
|
138
|
+
if (cached)
|
|
139
|
+
return cached;
|
|
140
|
+
cached = createStorageConfig();
|
|
141
|
+
try {
|
|
142
|
+
Object.defineProperties(proxyTarget, Object.getOwnPropertyDescriptors(cached));
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// best-effort
|
|
146
|
+
}
|
|
147
|
+
return cached;
|
|
148
|
+
};
|
|
149
|
+
export const storageConfig = new Proxy(proxyTarget, {
|
|
150
|
+
get(_target, prop) {
|
|
151
|
+
return ensureStorageConfig()[prop];
|
|
99
152
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
get uploads() {
|
|
104
|
-
return {
|
|
105
|
-
maxSize: Env.get('MAX_UPLOAD_SIZE', '100mb'),
|
|
106
|
-
allowedMimes: Env.get('ALLOWED_UPLOAD_MIMES', 'jpg,jpeg,png,pdf,doc,docx'),
|
|
107
|
-
path: Env.get('UPLOADS_PATH', 'storage/uploads'),
|
|
108
|
-
};
|
|
153
|
+
ownKeys() {
|
|
154
|
+
ensureStorageConfig();
|
|
155
|
+
return Reflect.ownKeys(proxyTarget);
|
|
109
156
|
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
get backups() {
|
|
114
|
-
return {
|
|
115
|
-
path: Env.get('BACKUPS_PATH', 'storage/backups'),
|
|
116
|
-
driver: Env.get('BACKUP_DRIVER', 's3'),
|
|
117
|
-
};
|
|
157
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
158
|
+
ensureStorageConfig();
|
|
159
|
+
return Object.getOwnPropertyDescriptor(proxyTarget, prop);
|
|
118
160
|
},
|
|
119
|
-
};
|
|
120
|
-
export const storageConfig = Object.freeze(storageConfigObj);
|
|
161
|
+
});
|