@stacksjs/config 0.70.88 → 0.70.91
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/dist/config.d.ts +102 -0
- package/dist/config.js +109 -0
- package/dist/defaults.d.ts +20 -0
- package/dist/defaults.js +626 -0
- package/dist/features.d.ts +39 -0
- package/dist/features.js +53 -0
- package/dist/helpers.d.ts +45 -0
- package/dist/helpers.js +153 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +4 -0
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +111 -0
- package/dist/validators.d.ts +19 -0
- package/dist/validators.js +119 -0
- package/package.json +3 -3
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { defaults } from './defaults';
|
|
2
|
+
import { overrides, overridesReady } from './overrides';
|
|
3
|
+
import type { StacksOptions } from '@stacksjs/types';
|
|
4
|
+
/*.ts` file has loaded and the
|
|
5
|
+
* `overrides` instance has been mutated in place. Use this in code paths
|
|
6
|
+
* that *must* see the merged values — typically anything outside the
|
|
7
|
+
* normal request flow (e.g. CLI commands, top-level boot scripts) where
|
|
8
|
+
* the request hasn't yet hit a route handler that already awaited.
|
|
9
|
+
*
|
|
10
|
+
* Inside request handlers / routes you generally do *not* need to await
|
|
11
|
+
* this: the router's `serverResponse()` only fires after `importRoutes()`
|
|
12
|
+
* resolves, and `importRoutes()` indirectly awaits config (it reads
|
|
13
|
+
* `app/Routes.ts`, which imports config). So the proxy returns merged
|
|
14
|
+
* values for all "normal" request-time reads.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { config, awaitConfig } from '@stacksjs/config'
|
|
19
|
+
*
|
|
20
|
+
* // CLI / top-level script — config files may not be loaded yet
|
|
21
|
+
* await awaitConfig()
|
|
22
|
+
* console.log(config.ports.api) // guaranteed to be the user value
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function awaitConfig(): Promise<StacksOptions>;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves once `database` config has been read by `@stacksjs/database`'s
|
|
28
|
+
* lazy initializer. Use it from boot scripts that need a live `db` handle
|
|
29
|
+
* before the request loop starts.
|
|
30
|
+
*
|
|
31
|
+
* Why a separate signal: `overridesReady` only signals that `~/config/database.ts`
|
|
32
|
+
* was *imported*, not that `@stacksjs/database` has actually wired up the
|
|
33
|
+
* connection. Calling `db.selectFrom(...)` immediately after `overridesReady`
|
|
34
|
+
* resolves can still race the connection setup. The database driver flips
|
|
35
|
+
* this signal to `true` once it has a working connection.
|
|
36
|
+
*/
|
|
37
|
+
export declare function awaitDatabaseConfig(): Promise<StacksOptions>;
|
|
38
|
+
/**
|
|
39
|
+
* Called by `@stacksjs/database` once the connection is live. Internal —
|
|
40
|
+
* users shouldn't need to invoke this directly.
|
|
41
|
+
*/
|
|
42
|
+
export declare function markDatabaseReady(): void;
|
|
43
|
+
export declare function getConfig(): StacksOptions;
|
|
44
|
+
export declare function determineAppEnv(): AppEnv;
|
|
45
|
+
export declare const config: StacksOptions;
|
|
46
|
+
// Per-section convenience exports.
|
|
47
|
+
//
|
|
48
|
+
// Caveat: these are *snapshots* taken at module-load time. ESM `export
|
|
49
|
+
// const x = expr` evaluates `expr` once and binds `x` to that result —
|
|
50
|
+
// there's no language-level way to make a named export re-evaluate
|
|
51
|
+
// per access. So `import { ports } from '@stacksjs/config'` returns
|
|
52
|
+
// whatever `config.ports` was when the config module first evaluated,
|
|
53
|
+
// which is *before* `overridesReady` resolves and the user's
|
|
54
|
+
// `config/*.ts` files land.
|
|
55
|
+
//
|
|
56
|
+
// These start as snapshots of the framework defaults (because the user's
|
|
57
|
+
// `config/*.ts` haven't loaded yet — see `overridesReady`). Once the
|
|
58
|
+
// async loader resolves we reassign each `let` binding so consumers of
|
|
59
|
+
// `import { ports } from '@stacksjs/config'` see the merged value.
|
|
60
|
+
//
|
|
61
|
+
// ESM live bindings make this work: when an exporting module reassigns
|
|
62
|
+
// a `let`-bound export, every importer immediately sees the new value
|
|
63
|
+
// (no re-import needed). The earlier `export const x = config.x` form
|
|
64
|
+
// captured the empty-default snapshot forever.
|
|
65
|
+
//
|
|
66
|
+
// Caveat: code that destructures (`const { ports } = config` or reads
|
|
67
|
+
// at the top of a function) before `overridesReady` resolves still
|
|
68
|
+
// gets the early snapshot. For correctness in that path, read off
|
|
69
|
+
// the `config` proxy: `config.ports.api` always pulls live.
|
|
70
|
+
export declare let ai: StacksOptions['ai'];
|
|
71
|
+
export declare let analytics: StacksOptions['analytics'];
|
|
72
|
+
export declare let app: StacksOptions['app'];
|
|
73
|
+
export declare let auth: StacksOptions['auth'];
|
|
74
|
+
export declare let realtime: StacksOptions['realtime'];
|
|
75
|
+
export declare let cache: StacksOptions['cache'];
|
|
76
|
+
export declare let cloud: StacksOptions['cloud'];
|
|
77
|
+
export declare let cli: StacksOptions['cli'];
|
|
78
|
+
export declare let dashboard: StacksOptions['dashboard'];
|
|
79
|
+
export declare let database: StacksOptions['database'];
|
|
80
|
+
export declare let dns: StacksOptions['dns'];
|
|
81
|
+
export declare let docs: StacksOptions['docs'];
|
|
82
|
+
export declare let email: StacksOptions['email'];
|
|
83
|
+
export declare let errors: StacksOptions['errors'];
|
|
84
|
+
export declare let featureFlags: StacksOptions['featureFlags'];
|
|
85
|
+
export declare let git: StacksOptions['git'];
|
|
86
|
+
export declare let hashing: StacksOptions['hashing'];
|
|
87
|
+
export declare let library: StacksOptions['library'];
|
|
88
|
+
export declare let logging: StacksOptions['logging'];
|
|
89
|
+
export declare let notification: StacksOptions['notification'];
|
|
90
|
+
export declare let payment: StacksOptions['payment'];
|
|
91
|
+
export declare let ports: StacksOptions['ports'];
|
|
92
|
+
export declare let queue: StacksOptions['queue'];
|
|
93
|
+
export declare let security: StacksOptions['security'];
|
|
94
|
+
export declare let saas: StacksOptions['saas'];
|
|
95
|
+
export declare let searchEngine: StacksOptions['searchEngine'];
|
|
96
|
+
export declare let services: StacksOptions['services'];
|
|
97
|
+
export declare let filesystems: StacksOptions['filesystems'];
|
|
98
|
+
export declare let team: StacksOptions['team'];
|
|
99
|
+
export declare let ui: StacksOptions['ui'];
|
|
100
|
+
declare type AppEnv = 'dev' | 'stage' | 'prod' | string;
|
|
101
|
+
export * from './helpers';
|
|
102
|
+
export { defaults, overrides, overridesReady };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { defaults } from "./defaults";
|
|
2
|
+
import { overrides, overridesReady } from "./overrides";
|
|
3
|
+
function readMerged(prop) {
|
|
4
|
+
const o = overrides[prop];
|
|
5
|
+
if (o !== void 0 && (typeof o !== "object" || Object.keys(o).length > 0))
|
|
6
|
+
return o;
|
|
7
|
+
return defaults[prop];
|
|
8
|
+
}
|
|
9
|
+
const proxyTarget = function configProxyTarget() {};
|
|
10
|
+
export const config = new Proxy(proxyTarget, {
|
|
11
|
+
get(_t, prop) {
|
|
12
|
+
return readMerged(prop);
|
|
13
|
+
},
|
|
14
|
+
has(_t, prop) {
|
|
15
|
+
return prop in overrides || prop in defaults;
|
|
16
|
+
},
|
|
17
|
+
ownKeys() {
|
|
18
|
+
return Array.from(new Set([
|
|
19
|
+
...Object.keys(overrides),
|
|
20
|
+
...Object.keys(defaults)
|
|
21
|
+
]));
|
|
22
|
+
},
|
|
23
|
+
getOwnPropertyDescriptor(_t, prop) {
|
|
24
|
+
if (typeof prop !== "string")
|
|
25
|
+
return;
|
|
26
|
+
if (!(prop in overrides) && !(prop in defaults))
|
|
27
|
+
return;
|
|
28
|
+
return {
|
|
29
|
+
enumerable: !0,
|
|
30
|
+
configurable: !0,
|
|
31
|
+
writable: !0,
|
|
32
|
+
value: readMerged(prop)
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
isExtensible() {
|
|
36
|
+
return !0;
|
|
37
|
+
},
|
|
38
|
+
preventExtensions() {
|
|
39
|
+
return !1;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
export async function awaitConfig() {
|
|
43
|
+
await overridesReady;
|
|
44
|
+
return config;
|
|
45
|
+
}
|
|
46
|
+
const DB_READY = Symbol.for("@stacksjs/config:databaseReady"), globalScope = globalThis;
|
|
47
|
+
export async function awaitDatabaseConfig() {
|
|
48
|
+
await overridesReady;
|
|
49
|
+
const deadline = Date.now() + 5000;
|
|
50
|
+
while (!globalScope[DB_READY] && Date.now() < deadline)
|
|
51
|
+
await new Promise((r) => setTimeout(r, 25));
|
|
52
|
+
if (!globalScope[DB_READY])
|
|
53
|
+
console.warn("[config] awaitDatabaseConfig() timed out \u2014 database driver did not signal readiness within 5s");
|
|
54
|
+
return config;
|
|
55
|
+
}
|
|
56
|
+
export function markDatabaseReady() {
|
|
57
|
+
globalScope[DB_READY] = !0;
|
|
58
|
+
}
|
|
59
|
+
export function getConfig() {
|
|
60
|
+
return config;
|
|
61
|
+
}
|
|
62
|
+
export let { ai, analytics, app, auth, realtime, cache, cloud, cli, dashboard, database, dns, docs, email, errors, featureFlags, git, hashing, library, logging, notification, payment, ports, queue, security, saas, searchEngine, services, filesystems, team, ui } = config;
|
|
63
|
+
overridesReady.then(() => {
|
|
64
|
+
ai = config.ai;
|
|
65
|
+
analytics = config.analytics;
|
|
66
|
+
app = config.app;
|
|
67
|
+
auth = config.auth;
|
|
68
|
+
realtime = config.realtime;
|
|
69
|
+
cache = config.cache;
|
|
70
|
+
cloud = config.cloud;
|
|
71
|
+
cli = config.cli;
|
|
72
|
+
dashboard = config.dashboard;
|
|
73
|
+
database = config.database;
|
|
74
|
+
dns = config.dns;
|
|
75
|
+
docs = config.docs;
|
|
76
|
+
email = config.email;
|
|
77
|
+
errors = config.errors;
|
|
78
|
+
featureFlags = config.featureFlags;
|
|
79
|
+
git = config.git;
|
|
80
|
+
hashing = config.hashing;
|
|
81
|
+
library = config.library;
|
|
82
|
+
logging = config.logging;
|
|
83
|
+
notification = config.notification;
|
|
84
|
+
payment = config.payment;
|
|
85
|
+
ports = config.ports;
|
|
86
|
+
queue = config.queue;
|
|
87
|
+
security = config.security;
|
|
88
|
+
saas = config.saas;
|
|
89
|
+
searchEngine = config.searchEngine;
|
|
90
|
+
services = config.services;
|
|
91
|
+
filesystems = config.filesystems;
|
|
92
|
+
team = config.team;
|
|
93
|
+
ui = config.ui;
|
|
94
|
+
}).catch(() => {});
|
|
95
|
+
|
|
96
|
+
export * from "./helpers";
|
|
97
|
+
export { defaults, overrides, overridesReady };
|
|
98
|
+
export function determineAppEnv() {
|
|
99
|
+
const env = config.app?.env;
|
|
100
|
+
if (env === "local" || env === "development")
|
|
101
|
+
return "dev";
|
|
102
|
+
if (env === "staging")
|
|
103
|
+
return "stage";
|
|
104
|
+
if (env === "production")
|
|
105
|
+
return "prod";
|
|
106
|
+
if (!env)
|
|
107
|
+
throw Error("Couldn't determine app environment");
|
|
108
|
+
return env;
|
|
109
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { StacksOptions } from '@stacksjs/types';
|
|
2
|
+
/**
|
|
3
|
+
* Framework-wide default scalars. Defining these as named constants
|
|
4
|
+
* (rather than re-spelling the literal in each config section) keeps
|
|
5
|
+
* "where do I change the default region?" answerable from a single
|
|
6
|
+
* line — the previous shape had `'us-east-1'` typed in 4+ places that
|
|
7
|
+
* could drift when a multi-region future lands.
|
|
8
|
+
*/
|
|
9
|
+
export declare const FRAMEWORK_DEFAULTS: {
|
|
10
|
+
/** Default AWS region for SES, S3, DynamoDB, CloudFront origin shield. */
|
|
11
|
+
awsRegion: 'us-east-1';
|
|
12
|
+
/** Default scheduler / job timezone. UTC keeps cron predictable across hosts. */
|
|
13
|
+
timezone: 'UTC';
|
|
14
|
+
/** No-reply address for transactional email (override via config.email.from). */
|
|
15
|
+
noReplyEmail: 'no-reply@stacksjs.com';
|
|
16
|
+
/** Default project domain shape for new scaffolds. */
|
|
17
|
+
fallbackDomain: 'stacks.localhost'
|
|
18
|
+
};
|
|
19
|
+
export declare const defaults: StacksOptions;
|
|
20
|
+
export default defaults;
|