@aenode/constants 0.0.0-stage → 0.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.
- package/README.md +24 -2
- package/assets/favicon.svg +1 -0
- package/bin/constants.mjs +3 -0
- package/dist/env.d.ts +108 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +236 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -4
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
   
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://aenode.github.io/aenode/libs/constants/assets/favicon.svg" alt="aenode Logo" height="128" width="128" style="border-radius: 32px;"/>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
## @aenode/constants
|
|
8
|
+
|
|
9
|
+
Common environment keys and constants
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
bun add @aenode/constants
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Examples
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const message = 'Hello there';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
[](https://cash.app/$puqlib) [](mailto:aenode+aenode@-constantsproton.me)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" height="48px" width="48px" fill="#5985E1"><path d="M22.93,41.57Q22.5,41.14 22.5,40.5V27.6l-9.1,9.1q-0.44,0.45-1.04,0.45T11.3,36.71t-0.45-1.05T11.3,34.6l9.1-9.1H7.5q-0.64,0-1.07-0.43T6,23.99t0.43-1.07T7.5,22.5H20.45L11.3,13.35q-0.45-0.44-0.45-1.05t0.44-1.05t1.05-0.45t1.06,0.45l9.1,9.1V7.5q0-0.64 0.43-1.07T24.01,6t1.07,0.43T25.5,7.5V20.4l9.15-9.15q0.44-0.45 1.05-0.45t1.05,0.44t0.45,1.05t-0.45,1.06L27.6,22.5H40.5q0.64,0 1.07,0.43T42,24.01t-0.43,1.07T40.5,25.5H27.65l9.1,9.1q0.45,0.44 0.45,1.04T36.76,36.7t-1.05,0.45T34.65,36.7L25.5,27.55V40.5q0,0.64-0.43,1.07T23.99,42t-1.07-0.43Z"/></svg>
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export declare class Duration {
|
|
2
|
+
static readonly SECOND = 1000;
|
|
3
|
+
static readonly SECONDS_5: number;
|
|
4
|
+
static readonly SECONDS_10: number;
|
|
5
|
+
static readonly SECONDS_20: number;
|
|
6
|
+
static readonly MINUTE: number;
|
|
7
|
+
static readonly MINUTES_5: number;
|
|
8
|
+
}
|
|
9
|
+
export declare abstract class BaseEnv {
|
|
10
|
+
__profile?: string;
|
|
11
|
+
protected get profile(): string;
|
|
12
|
+
protected prep(key: string): string;
|
|
13
|
+
constructor(profile?: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class EnvApp extends BaseEnv {
|
|
16
|
+
static readonly NAME = "NAME";
|
|
17
|
+
static readonly PORT = "PORT";
|
|
18
|
+
static readonly API_PREFIX = "API_PREFIX";
|
|
19
|
+
static readonly DESCRIPTION = "DESCRIPTION";
|
|
20
|
+
static readonly PROFILE = "PROFILE";
|
|
21
|
+
get NAME(): string;
|
|
22
|
+
get PORT(): string;
|
|
23
|
+
get API_PREFIX(): string;
|
|
24
|
+
get DESCRIPTION(): string;
|
|
25
|
+
}
|
|
26
|
+
export declare class EnvAuth extends BaseEnv {
|
|
27
|
+
static readonly JWT_SECRET = "JWT_SECRET";
|
|
28
|
+
static readonly ENCRIPTION_SECRET = "ENCRIPTION_SECRET";
|
|
29
|
+
static readonly ROOT_USERANME = "ROOT_USERANME";
|
|
30
|
+
static readonly ROOT_PASSWORD = "ROOT_PASSWORD";
|
|
31
|
+
static readonly AUTH_PROFILE = "AUTH_PROFILE";
|
|
32
|
+
static readonly ALLOWED_ORIGINS = "ALLOWED_ORIGINS";
|
|
33
|
+
get JWT_SECRET(): string;
|
|
34
|
+
get ENCRIPTION_SECRET(): string;
|
|
35
|
+
get ROOT_USERANME(): string;
|
|
36
|
+
get ROOT_PASSWORD(): string;
|
|
37
|
+
get AUTH_PROFILE(): string;
|
|
38
|
+
get ALLOWED_ORIGINS(): string;
|
|
39
|
+
}
|
|
40
|
+
export declare class EnvPg extends BaseEnv {
|
|
41
|
+
/**
|
|
42
|
+
* The maximum number of clients/connections allowed in this pool. Default is usually 10. Don't set this higher than your PostgreSQL server's max_connections limit.
|
|
43
|
+
*/
|
|
44
|
+
static readonly MAX = "MAX";
|
|
45
|
+
/**
|
|
46
|
+
* How long (in milliseconds) a request will wait to acquire an available client from the pool before throwing a timeout error. Default is 0 (wait indefinitely). In production, set this (e.g., 5000 ms) to prevent requests from hanging indefinitely during high traffic spikes.
|
|
47
|
+
*/
|
|
48
|
+
static readonly CONNECTION_TIMEOUT_MILLIS = "CONNECTION_TIMEOUT_MILLIS";
|
|
49
|
+
/**
|
|
50
|
+
* How long (in milliseconds) a connection can sit unused in the pool before being closed and discarded. Default is usually 10000 (10 seconds). Keeps connection counts low during quiet periods.
|
|
51
|
+
*/
|
|
52
|
+
static readonly IDLE_TIMEOUT_MILLIS = "IDLE_TIMEOUT_MILLIS";
|
|
53
|
+
/**
|
|
54
|
+
* The maximum number of times a single connection can be checked out and reused before the pool closes and replaces it. Default is 0 (unlimited). Useful to set (e.g., 7500) to mitigate subtle memory leaks or clean up stale session-level state in long-lived node processes.
|
|
55
|
+
*/
|
|
56
|
+
static readonly MAX_USES = "MAX_USES";
|
|
57
|
+
/**
|
|
58
|
+
* Aborts any individual SQL statement that takes longer than the specified number of milliseconds. Your primary circuit breaker. Prevents runaway, un-indexed, or slow queries from bogging down your database. 5000 miliseconds is ideal
|
|
59
|
+
*/
|
|
60
|
+
static readonly STATEMENT_TIMEOUT = "STATEMENT_TIMEOUT";
|
|
61
|
+
/**
|
|
62
|
+
* Node-side timeout for a query to complete before the driver rejects the Promise. Acts as a client-side backup if the network connection drops while waiting for Postgres to return results.
|
|
63
|
+
*/
|
|
64
|
+
static readonly QUERY_TIMEOUT = "QUERY_TIMEOUT";
|
|
65
|
+
/**
|
|
66
|
+
* Aborts any statement if it waits longer than this value (in ms) to acquire an explicit or implicit table/row lock. Essential for high-concurrency DBs. Stops long schema migrations or transactions from creating massive lock queues (blocking reads/writes).
|
|
67
|
+
*/
|
|
68
|
+
static readonly LOCK_TIMEOUT = "LOCK_TIMEOUT";
|
|
69
|
+
static readonly DEFAULT_MAX = 10;
|
|
70
|
+
static readonly DEFAULT_CONNECTION_TIMEOUT_MILLIS: number;
|
|
71
|
+
static readonly DEFAULT_IDLE_TIMEOUT_MILLIS: number;
|
|
72
|
+
static readonly DEFAULT_MAX_USES = 7500;
|
|
73
|
+
static readonly DEFAULT_STATEMENT_TIMEOUT: number;
|
|
74
|
+
static readonly DEFAULT_QUERY_TIMEOUT: number;
|
|
75
|
+
static readonly DEFAULT_LOCK_TIMEOUT: number;
|
|
76
|
+
get MAX(): string;
|
|
77
|
+
get CONNECTION_TIMEOUT_MILLIS(): string;
|
|
78
|
+
get IDLE_TIMEOUT_MILLIS(): string;
|
|
79
|
+
get MAX_USES(): string;
|
|
80
|
+
get STATEMENT_TIMEOUT(): string;
|
|
81
|
+
get QUERY_TIMEOUT(): string;
|
|
82
|
+
get LOCK_TIMEOUT(): string;
|
|
83
|
+
}
|
|
84
|
+
export declare class EnvDB extends BaseEnv {
|
|
85
|
+
static readonly DATABASE_USERNAME = "DATABASE_USERNAME";
|
|
86
|
+
static readonly DATABASE_PASSWORD = "DATABASE_PASSWORD";
|
|
87
|
+
static readonly DATABASE_URL = "DATABASE_URL";
|
|
88
|
+
static readonly DATABASE_SCHEMA = "DATABASE_SCHEMA";
|
|
89
|
+
static readonly PG: typeof EnvPg;
|
|
90
|
+
get DATABASE_USERNAME(): string;
|
|
91
|
+
get DATABASE_PASSWORD(): string;
|
|
92
|
+
get DATABASE_SCHEMA(): string;
|
|
93
|
+
get DATABASE_URL(): string;
|
|
94
|
+
get PG(): EnvPg;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Environment vriable keys
|
|
98
|
+
*/
|
|
99
|
+
export declare class Env extends BaseEnv {
|
|
100
|
+
static readonly DEFAULT = "default";
|
|
101
|
+
static readonly APP: typeof EnvApp;
|
|
102
|
+
static readonly DB: typeof EnvDB;
|
|
103
|
+
static readonly AUTH: typeof EnvAuth;
|
|
104
|
+
get APP(): EnvApp;
|
|
105
|
+
get DB(): EnvDB;
|
|
106
|
+
get AUTH(): EnvAuth;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACnB,MAAM,CAAC,QAAQ,CAAC,MAAM,QAAQ;IAC9B,MAAM,CAAC,QAAQ,CAAC,SAAS,SAAmB;IAC5C,MAAM,CAAC,QAAQ,CAAC,UAAU,SAAoB;IAC9C,MAAM,CAAC,QAAQ,CAAC,UAAU,SAAoB;IAC9C,MAAM,CAAC,QAAQ,CAAC,MAAM,SAAoB;IAC1C,MAAM,CAAC,QAAQ,CAAC,SAAS,SAAmB;CAC7C;AAED,8BAAsB,OAAO;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,SAAS,KAAK,OAAO,WAEpB;IAED,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM;gBAId,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED,qBAAa,MAAO,SAAQ,OAAO;IACjC,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAC9B,MAAM,CAAC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.SECOND = 1000;
|
|
4
|
+
}
|
|
5
|
+
static{
|
|
6
|
+
this.SECONDS_5 = this.SECOND * 5;
|
|
7
|
+
}
|
|
8
|
+
static{
|
|
9
|
+
this.SECONDS_10 = this.SECOND * 10;
|
|
10
|
+
}
|
|
11
|
+
static{
|
|
12
|
+
this.SECONDS_20 = this.SECOND * 20;
|
|
13
|
+
}
|
|
14
|
+
static{
|
|
15
|
+
this.MINUTE = this.SECOND * 60;
|
|
16
|
+
}
|
|
17
|
+
static{
|
|
18
|
+
this.MINUTES_5 = this.MINUTE * 5;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class BaseEnv {
|
|
22
|
+
get profile() {
|
|
23
|
+
return this.__profile ? `${this.__profile}_` : '';
|
|
24
|
+
}
|
|
25
|
+
prep(key) {
|
|
26
|
+
return `${this.profile}${key}`;
|
|
27
|
+
}
|
|
28
|
+
constructor(profile){
|
|
29
|
+
this.__profile = profile;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export class EnvApp extends BaseEnv {
|
|
33
|
+
static{
|
|
34
|
+
this.NAME = 'NAME';
|
|
35
|
+
}
|
|
36
|
+
static{
|
|
37
|
+
this.PORT = 'PORT';
|
|
38
|
+
}
|
|
39
|
+
static{
|
|
40
|
+
this.API_PREFIX = 'API_PREFIX';
|
|
41
|
+
}
|
|
42
|
+
static{
|
|
43
|
+
this.DESCRIPTION = 'DESCRIPTION';
|
|
44
|
+
}
|
|
45
|
+
static{
|
|
46
|
+
this.PROFILE = 'PROFILE';
|
|
47
|
+
}
|
|
48
|
+
get NAME() {
|
|
49
|
+
return this.prep(EnvApp.NAME);
|
|
50
|
+
}
|
|
51
|
+
get PORT() {
|
|
52
|
+
return this.prep(EnvApp.PORT);
|
|
53
|
+
}
|
|
54
|
+
get API_PREFIX() {
|
|
55
|
+
return this.prep(EnvApp.API_PREFIX);
|
|
56
|
+
}
|
|
57
|
+
get DESCRIPTION() {
|
|
58
|
+
return this.prep(EnvApp.DESCRIPTION);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export class EnvAuth extends BaseEnv {
|
|
62
|
+
static{
|
|
63
|
+
this.JWT_SECRET = 'JWT_SECRET';
|
|
64
|
+
}
|
|
65
|
+
static{
|
|
66
|
+
this.ENCRIPTION_SECRET = 'ENCRIPTION_SECRET';
|
|
67
|
+
}
|
|
68
|
+
static{
|
|
69
|
+
this.ROOT_USERANME = 'ROOT_USERANME';
|
|
70
|
+
}
|
|
71
|
+
static{
|
|
72
|
+
this.ROOT_PASSWORD = 'ROOT_PASSWORD';
|
|
73
|
+
}
|
|
74
|
+
static{
|
|
75
|
+
this.AUTH_PROFILE = 'AUTH_PROFILE';
|
|
76
|
+
}
|
|
77
|
+
static{
|
|
78
|
+
this.ALLOWED_ORIGINS = 'ALLOWED_ORIGINS';
|
|
79
|
+
}
|
|
80
|
+
get JWT_SECRET() {
|
|
81
|
+
return this.prep(EnvAuth.JWT_SECRET);
|
|
82
|
+
}
|
|
83
|
+
get ENCRIPTION_SECRET() {
|
|
84
|
+
return this.prep(EnvAuth.ENCRIPTION_SECRET);
|
|
85
|
+
}
|
|
86
|
+
get ROOT_USERANME() {
|
|
87
|
+
return this.prep(EnvAuth.ROOT_USERANME);
|
|
88
|
+
}
|
|
89
|
+
get ROOT_PASSWORD() {
|
|
90
|
+
return this.prep(EnvAuth.ROOT_PASSWORD);
|
|
91
|
+
}
|
|
92
|
+
get AUTH_PROFILE() {
|
|
93
|
+
return this.prep(EnvAuth.AUTH_PROFILE);
|
|
94
|
+
}
|
|
95
|
+
get ALLOWED_ORIGINS() {
|
|
96
|
+
return this.prep(EnvAuth.ALLOWED_ORIGINS);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export class EnvPg extends BaseEnv {
|
|
100
|
+
static{
|
|
101
|
+
/**
|
|
102
|
+
* The maximum number of clients/connections allowed in this pool. Default is usually 10. Don't set this higher than your PostgreSQL server's max_connections limit.
|
|
103
|
+
*/ this.MAX = 'MAX';
|
|
104
|
+
}
|
|
105
|
+
static{
|
|
106
|
+
/**
|
|
107
|
+
* How long (in milliseconds) a request will wait to acquire an available client from the pool before throwing a timeout error. Default is 0 (wait indefinitely). In production, set this (e.g., 5000 ms) to prevent requests from hanging indefinitely during high traffic spikes.
|
|
108
|
+
*/ this.CONNECTION_TIMEOUT_MILLIS = 'CONNECTION_TIMEOUT_MILLIS';
|
|
109
|
+
}
|
|
110
|
+
static{
|
|
111
|
+
/**
|
|
112
|
+
* How long (in milliseconds) a connection can sit unused in the pool before being closed and discarded. Default is usually 10000 (10 seconds). Keeps connection counts low during quiet periods.
|
|
113
|
+
*/ this.IDLE_TIMEOUT_MILLIS = 'IDLE_TIMEOUT_MILLIS';
|
|
114
|
+
}
|
|
115
|
+
static{
|
|
116
|
+
/**
|
|
117
|
+
* The maximum number of times a single connection can be checked out and reused before the pool closes and replaces it. Default is 0 (unlimited). Useful to set (e.g., 7500) to mitigate subtle memory leaks or clean up stale session-level state in long-lived node processes.
|
|
118
|
+
*/ this.MAX_USES = 'MAX_USES';
|
|
119
|
+
}
|
|
120
|
+
static{
|
|
121
|
+
/**
|
|
122
|
+
* Aborts any individual SQL statement that takes longer than the specified number of milliseconds. Your primary circuit breaker. Prevents runaway, un-indexed, or slow queries from bogging down your database. 5000 miliseconds is ideal
|
|
123
|
+
*/ this.STATEMENT_TIMEOUT = 'STATEMENT_TIMEOUT';
|
|
124
|
+
}
|
|
125
|
+
static{
|
|
126
|
+
/**
|
|
127
|
+
* Node-side timeout for a query to complete before the driver rejects the Promise. Acts as a client-side backup if the network connection drops while waiting for Postgres to return results.
|
|
128
|
+
*/ this.QUERY_TIMEOUT = 'QUERY_TIMEOUT';
|
|
129
|
+
}
|
|
130
|
+
static{
|
|
131
|
+
/**
|
|
132
|
+
* Aborts any statement if it waits longer than this value (in ms) to acquire an explicit or implicit table/row lock. Essential for high-concurrency DBs. Stops long schema migrations or transactions from creating massive lock queues (blocking reads/writes).
|
|
133
|
+
*/ this.LOCK_TIMEOUT = 'LOCK_TIMEOUT';
|
|
134
|
+
}
|
|
135
|
+
static{
|
|
136
|
+
this.DEFAULT_MAX = 10;
|
|
137
|
+
}
|
|
138
|
+
static{
|
|
139
|
+
this.DEFAULT_CONNECTION_TIMEOUT_MILLIS = Duration.SECONDS_5;
|
|
140
|
+
}
|
|
141
|
+
static{
|
|
142
|
+
this.DEFAULT_IDLE_TIMEOUT_MILLIS = Duration.SECONDS_10;
|
|
143
|
+
}
|
|
144
|
+
static{
|
|
145
|
+
this.DEFAULT_MAX_USES = 7500;
|
|
146
|
+
}
|
|
147
|
+
static{
|
|
148
|
+
this.DEFAULT_STATEMENT_TIMEOUT = Duration.SECONDS_5;
|
|
149
|
+
}
|
|
150
|
+
static{
|
|
151
|
+
this.DEFAULT_QUERY_TIMEOUT = Duration.SECONDS_10;
|
|
152
|
+
}
|
|
153
|
+
static{
|
|
154
|
+
this.DEFAULT_LOCK_TIMEOUT = Duration.SECONDS_10;
|
|
155
|
+
}
|
|
156
|
+
get MAX() {
|
|
157
|
+
return this.prep(EnvPg.MAX);
|
|
158
|
+
}
|
|
159
|
+
get CONNECTION_TIMEOUT_MILLIS() {
|
|
160
|
+
return this.prep(EnvPg.CONNECTION_TIMEOUT_MILLIS);
|
|
161
|
+
}
|
|
162
|
+
get IDLE_TIMEOUT_MILLIS() {
|
|
163
|
+
return this.prep(EnvPg.IDLE_TIMEOUT_MILLIS);
|
|
164
|
+
}
|
|
165
|
+
get MAX_USES() {
|
|
166
|
+
return this.prep(EnvPg.MAX_USES);
|
|
167
|
+
}
|
|
168
|
+
get STATEMENT_TIMEOUT() {
|
|
169
|
+
return this.prep(EnvPg.STATEMENT_TIMEOUT);
|
|
170
|
+
}
|
|
171
|
+
get QUERY_TIMEOUT() {
|
|
172
|
+
return this.prep(EnvPg.QUERY_TIMEOUT);
|
|
173
|
+
}
|
|
174
|
+
get LOCK_TIMEOUT() {
|
|
175
|
+
return this.prep(EnvPg.LOCK_TIMEOUT);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
export class EnvDB extends BaseEnv {
|
|
179
|
+
static{
|
|
180
|
+
this.DATABASE_USERNAME = 'DATABASE_USERNAME';
|
|
181
|
+
}
|
|
182
|
+
static{
|
|
183
|
+
this.DATABASE_PASSWORD = 'DATABASE_PASSWORD';
|
|
184
|
+
}
|
|
185
|
+
static{
|
|
186
|
+
this.DATABASE_URL = 'DATABASE_URL';
|
|
187
|
+
}
|
|
188
|
+
static{
|
|
189
|
+
this.DATABASE_SCHEMA = 'DATABASE_SCHEMA';
|
|
190
|
+
}
|
|
191
|
+
static{
|
|
192
|
+
this.PG = EnvPg;
|
|
193
|
+
}
|
|
194
|
+
get DATABASE_USERNAME() {
|
|
195
|
+
return this.prep(EnvDB.DATABASE_USERNAME);
|
|
196
|
+
}
|
|
197
|
+
get DATABASE_PASSWORD() {
|
|
198
|
+
return this.prep(EnvDB.DATABASE_PASSWORD);
|
|
199
|
+
}
|
|
200
|
+
get DATABASE_SCHEMA() {
|
|
201
|
+
return this.prep(EnvDB.DATABASE_SCHEMA);
|
|
202
|
+
}
|
|
203
|
+
get DATABASE_URL() {
|
|
204
|
+
return this.prep(EnvDB.DATABASE_URL);
|
|
205
|
+
}
|
|
206
|
+
get PG() {
|
|
207
|
+
return new EnvPg(this.profile);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Environment vriable keys
|
|
212
|
+
*/ export class Env extends BaseEnv {
|
|
213
|
+
static{
|
|
214
|
+
this.DEFAULT = 'default';
|
|
215
|
+
}
|
|
216
|
+
static{
|
|
217
|
+
this.APP = EnvApp;
|
|
218
|
+
}
|
|
219
|
+
static{
|
|
220
|
+
this.DB = EnvDB;
|
|
221
|
+
}
|
|
222
|
+
static{
|
|
223
|
+
this.AUTH = EnvAuth;
|
|
224
|
+
}
|
|
225
|
+
get APP() {
|
|
226
|
+
return new EnvApp(this.profile);
|
|
227
|
+
}
|
|
228
|
+
get DB() {
|
|
229
|
+
return new EnvDB(this.profile);
|
|
230
|
+
}
|
|
231
|
+
get AUTH() {
|
|
232
|
+
return new EnvAuth(this.profile);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/env.ts"],"sourcesContent":["export class Duration {\n static readonly SECOND = 1000;\n static readonly SECONDS_5 = this.SECOND * 5;\n static readonly SECONDS_10 = this.SECOND * 10;\n static readonly SECONDS_20 = this.SECOND * 20;\n static readonly MINUTE = this.SECOND * 60;\n static readonly MINUTES_5 = this.MINUTE * 5;\n}\n\nexport abstract class BaseEnv {\n __profile?: string;\n\n protected get profile() {\n return this.__profile ? `${this.__profile}_` : '';\n }\n\n protected prep(key: string) {\n return `${this.profile}${key}`;\n }\n\n constructor(profile?: string) {\n this.__profile = profile;\n }\n}\n\nexport class EnvApp extends BaseEnv {\n static readonly NAME = 'NAME';\n static readonly PORT = 'PORT';\n static readonly API_PREFIX = 'API_PREFIX';\n static readonly DESCRIPTION = 'DESCRIPTION';\n static readonly PROFILE = 'PROFILE';\n\n get NAME() {\n return this.prep(EnvApp.NAME);\n }\n get PORT() {\n return this.prep(EnvApp.PORT);\n }\n get API_PREFIX() {\n return this.prep(EnvApp.API_PREFIX);\n }\n get DESCRIPTION() {\n return this.prep(EnvApp.DESCRIPTION);\n }\n}\n\nexport class EnvAuth extends BaseEnv {\n static readonly JWT_SECRET = 'JWT_SECRET';\n static readonly ENCRIPTION_SECRET = 'ENCRIPTION_SECRET';\n static readonly ROOT_USERANME = 'ROOT_USERANME';\n static readonly ROOT_PASSWORD = 'ROOT_PASSWORD';\n static readonly AUTH_PROFILE = 'AUTH_PROFILE';\n static readonly ALLOWED_ORIGINS = 'ALLOWED_ORIGINS';\n\n get JWT_SECRET() {\n return this.prep(EnvAuth.JWT_SECRET);\n }\n\n get ENCRIPTION_SECRET() {\n return this.prep(EnvAuth.ENCRIPTION_SECRET);\n }\n\n get ROOT_USERANME() {\n return this.prep(EnvAuth.ROOT_USERANME);\n }\n\n get ROOT_PASSWORD() {\n return this.prep(EnvAuth.ROOT_PASSWORD);\n }\n\n get AUTH_PROFILE() {\n return this.prep(EnvAuth.AUTH_PROFILE);\n }\n\n get ALLOWED_ORIGINS() {\n return this.prep(EnvAuth.ALLOWED_ORIGINS);\n }\n}\n\nexport class EnvPg extends BaseEnv {\n /**\n * The maximum number of clients/connections allowed in this pool.\tDefault is usually 10. Don't set this higher than your PostgreSQL server's max_connections limit.\n */\n static readonly MAX = 'MAX';\n\n /**\n * How long (in milliseconds) a request will wait to acquire an available client from the pool before throwing a timeout error.\tDefault is 0 (wait indefinitely). In production, set this (e.g., 5000 ms) to prevent requests from hanging indefinitely during high traffic spikes.\n */\n static readonly CONNECTION_TIMEOUT_MILLIS = 'CONNECTION_TIMEOUT_MILLIS';\n\n /**\n * How long (in milliseconds) a connection can sit unused in the pool before being closed and discarded.\tDefault is usually 10000 (10 seconds). Keeps connection counts low during quiet periods.\n */\n static readonly IDLE_TIMEOUT_MILLIS = 'IDLE_TIMEOUT_MILLIS';\n\n /**\n * The maximum number of times a single connection can be checked out and reused before the pool closes and replaces it.\tDefault is 0 (unlimited). Useful to set (e.g., 7500) to mitigate subtle memory leaks or clean up stale session-level state in long-lived node processes.\n */\n static readonly MAX_USES = 'MAX_USES';\n\n /**\n * Aborts any individual SQL statement that takes longer than the specified number of milliseconds.\tYour primary circuit breaker. Prevents runaway, un-indexed, or slow queries from bogging down your database. 5000 miliseconds is ideal\n */\n static readonly STATEMENT_TIMEOUT = 'STATEMENT_TIMEOUT';\n\n /**\n * Node-side timeout for a query to complete before the driver rejects the Promise.\tActs as a client-side backup if the network connection drops while waiting for Postgres to return results.\n */\n static readonly QUERY_TIMEOUT = 'QUERY_TIMEOUT';\n\n /**\n * Aborts any statement if it waits longer than this value (in ms) to acquire an explicit or implicit table/row lock.\tEssential for high-concurrency DBs. Stops long schema migrations or transactions from creating massive lock queues (blocking reads/writes).\n */\n static readonly LOCK_TIMEOUT = 'LOCK_TIMEOUT';\n\n static readonly DEFAULT_MAX = 10;\n static readonly DEFAULT_CONNECTION_TIMEOUT_MILLIS = Duration.SECONDS_5;\n static readonly DEFAULT_IDLE_TIMEOUT_MILLIS = Duration.SECONDS_10;\n static readonly DEFAULT_MAX_USES = 7500;\n static readonly DEFAULT_STATEMENT_TIMEOUT = Duration.SECONDS_5;\n static readonly DEFAULT_QUERY_TIMEOUT = Duration.SECONDS_10;\n static readonly DEFAULT_LOCK_TIMEOUT = Duration.SECONDS_10;\n\n get MAX() {\n return this.prep(EnvPg.MAX);\n }\n\n get CONNECTION_TIMEOUT_MILLIS() {\n return this.prep(EnvPg.CONNECTION_TIMEOUT_MILLIS);\n }\n\n get IDLE_TIMEOUT_MILLIS() {\n return this.prep(EnvPg.IDLE_TIMEOUT_MILLIS);\n }\n\n get MAX_USES() {\n return this.prep(EnvPg.MAX_USES);\n }\n\n get STATEMENT_TIMEOUT() {\n return this.prep(EnvPg.STATEMENT_TIMEOUT);\n }\n\n get QUERY_TIMEOUT() {\n return this.prep(EnvPg.QUERY_TIMEOUT);\n }\n\n get LOCK_TIMEOUT() {\n return this.prep(EnvPg.LOCK_TIMEOUT);\n }\n}\n\nexport class EnvDB extends BaseEnv {\n static readonly DATABASE_USERNAME = 'DATABASE_USERNAME';\n static readonly DATABASE_PASSWORD = 'DATABASE_PASSWORD';\n static readonly DATABASE_URL = 'DATABASE_URL';\n static readonly DATABASE_SCHEMA = 'DATABASE_SCHEMA';\n static readonly PG = EnvPg;\n\n get DATABASE_USERNAME() {\n return this.prep(EnvDB.DATABASE_USERNAME);\n }\n\n get DATABASE_PASSWORD() {\n return this.prep(EnvDB.DATABASE_PASSWORD);\n }\n\n get DATABASE_SCHEMA() {\n return this.prep(EnvDB.DATABASE_SCHEMA);\n }\n\n get DATABASE_URL() {\n return this.prep(EnvDB.DATABASE_URL);\n }\n\n get PG() {\n return new EnvPg(this.profile);\n }\n}\n\n/**\n * Environment vriable keys\n */\nexport class Env extends BaseEnv {\n static readonly DEFAULT = 'default';\n static readonly APP = EnvApp;\n static readonly DB = EnvDB;\n static readonly AUTH = EnvAuth;\n\n get APP() {\n return new EnvApp(this.profile);\n }\n\n get DB() {\n return new EnvDB(this.profile);\n }\n\n get AUTH() {\n return new EnvAuth(this.profile);\n }\n}\n"],"names":["Duration","SECOND","SECONDS_5","SECONDS_10","SECONDS_20","MINUTE","MINUTES_5","BaseEnv","profile","__profile","prep","key","EnvApp","NAME","PORT","API_PREFIX","DESCRIPTION","PROFILE","EnvAuth","JWT_SECRET","ENCRIPTION_SECRET","ROOT_USERANME","ROOT_PASSWORD","AUTH_PROFILE","ALLOWED_ORIGINS","EnvPg","MAX","CONNECTION_TIMEOUT_MILLIS","IDLE_TIMEOUT_MILLIS","MAX_USES","STATEMENT_TIMEOUT","QUERY_TIMEOUT","LOCK_TIMEOUT","DEFAULT_MAX","DEFAULT_CONNECTION_TIMEOUT_MILLIS","DEFAULT_IDLE_TIMEOUT_MILLIS","DEFAULT_MAX_USES","DEFAULT_STATEMENT_TIMEOUT","DEFAULT_QUERY_TIMEOUT","DEFAULT_LOCK_TIMEOUT","EnvDB","DATABASE_USERNAME","DATABASE_PASSWORD","DATABASE_URL","DATABASE_SCHEMA","PG","Env","DEFAULT","APP","DB","AUTH"],"mappings":"AAAA,OAAO,MAAMA;;aACKC,SAAS;;;aACTC,YAAY,IAAI,CAACD,MAAM,GAAG;;;aAC1BE,aAAa,IAAI,CAACF,MAAM,GAAG;;;aAC3BG,aAAa,IAAI,CAACH,MAAM,GAAG;;;aAC3BI,SAAS,IAAI,CAACJ,MAAM,GAAG;;;aACvBK,YAAY,IAAI,CAACD,MAAM,GAAG;;AAC5C;AAEA,OAAO,MAAeE;IAGpB,IAAcC,UAAU;QACtB,OAAO,IAAI,CAACC,SAAS,GAAG,GAAG,IAAI,CAACA,SAAS,CAAC,CAAC,CA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kBAAkB;QACpB,OAAO,IAAI,CAAClC,IAAI,CAAC8B,MAAMI,eAAe;IACxC;IAEA,IAAID,eAAe;QACjB,OAAO,IAAI,CAACjC,IAAI,CAAC8B,MAAMG,YAAY;IACrC;IAEA,IAAIE,KAAK;QACP,OAAO,IAAIpB,MAAM,IAAI,CAACjB,OAAO;IAC/B;AACF;AAEA;;CAEC,GACD,OAAO,MAAMsC,YAAYvC;;aACPwC,UAAU;;;aACVC,MAAMpC;;;aACNqC,KAAKT;;;aACLU,OAAOhC;;IAEvB,IAAI8B,MAAM;QACR,OAAO,IAAIpC,OAAO,IAAI,CAACJ,OAAO;IAChC;IAEA,IAAIyC,KAAK;QACP,OAAO,IAAIT,MAAM,IAAI,CAAChC,OAAO;IAC/B;IAEA,IAAI0C,OAAO;QACT,OAAO,IAAIhC,QAAQ,IAAI,CAACV,OAAO;IACjC;AACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './env.js';\n"],"names":[],"mappings":"AAAA,cAAc,WAAW"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aenode/constants",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Common environment keys and constants",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Ahmet Emrebas",
|
|
7
|
+
"email": "aenode+aenode@-constantsproton.me",
|
|
8
|
+
"url": "https://aenode.github.io/#profile"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"aenode-constants": "./bin/constants.mjs"
|
|
12
|
+
},
|
|
13
|
+
"funding": "https://cash.app/$puqlib",
|
|
14
|
+
"homepage": "https://aenode.github.io/aenode/libs/constants",
|
|
15
|
+
"repository": {
|
|
16
|
+
"directory": "libs/constants",
|
|
17
|
+
"type": "github",
|
|
18
|
+
"url": "https://github.com/aenode/aenode/tree/main/libs/constants"
|
|
19
|
+
},
|
|
20
|
+
"icon": "https://aenode.github.io/aenode/libs/constants/assets/favicon.svg",
|
|
21
|
+
"keywords": [
|
|
22
|
+
"lib"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"tag": "latest"
|
|
27
|
+
},
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
"./package.json": "./package.json",
|
|
34
|
+
".": {
|
|
35
|
+
"bun": "./src/index.ts",
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"default": "./dist/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"assets",
|
|
43
|
+
"bin",
|
|
44
|
+
"dist",
|
|
45
|
+
"generators.json",
|
|
46
|
+
"!**/*.tsbuildinfo"
|
|
47
|
+
],
|
|
48
|
+
"nx": {
|
|
49
|
+
"sourceRoot": "libs/constants/src",
|
|
50
|
+
"tags": [
|
|
51
|
+
"lib:common"
|
|
52
|
+
],
|
|
53
|
+
"targets": {
|
|
54
|
+
"build": {},
|
|
55
|
+
"doc": {}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@swc/helpers": "~0.5.18"
|
|
60
|
+
}
|
|
61
|
+
}
|