@bunary/core 0.0.5 → 0.0.7
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 +17 -3
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -28
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Foundation module for the Bunary framework — configuration, environment helpers, and shared utilities.
|
|
4
4
|
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
Canonical documentation for this package lives in [`docs/index.md`](./docs/index.md).
|
|
8
|
+
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
7
11
|
```bash
|
|
@@ -29,15 +33,19 @@ if (isDev()) {
|
|
|
29
33
|
### Configuration
|
|
30
34
|
|
|
31
35
|
```typescript
|
|
32
|
-
import { defineConfig } from '@bunary/core';
|
|
36
|
+
import { createConfig, defineConfig } from '@bunary/core';
|
|
33
37
|
|
|
34
|
-
export
|
|
38
|
+
export const configStore = createConfig(defineConfig({
|
|
35
39
|
app: {
|
|
36
40
|
name: 'MyApp',
|
|
37
41
|
env: 'development',
|
|
38
42
|
debug: true,
|
|
39
43
|
},
|
|
40
|
-
});
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
// The resolved config object (use this in most app code)
|
|
47
|
+
export default configStore.get();
|
|
48
|
+
|
|
41
49
|
```
|
|
42
50
|
|
|
43
51
|
## API
|
|
@@ -62,6 +70,12 @@ Returns `true` if `NODE_ENV` is `"test"`.
|
|
|
62
70
|
|
|
63
71
|
Type-safe configuration helper with defaults.
|
|
64
72
|
|
|
73
|
+
|
|
74
|
+
### `createConfig(config?: BunaryConfig): BunaryConfigStore`
|
|
75
|
+
|
|
76
|
+
Create an **instance-scoped** configuration store with `get()`, `set()`, and `clear()`.
|
|
77
|
+
|
|
78
|
+
|
|
65
79
|
## Requirements
|
|
66
80
|
|
|
67
81
|
- Bun ≥1.0.0
|
package/dist/config.d.ts
CHANGED
|
@@ -1,4 +1,33 @@
|
|
|
1
1
|
import type { BunaryConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Instance-scoped configuration container.
|
|
4
|
+
*
|
|
5
|
+
* This replaces global mutable config and allows multiple independent app instances
|
|
6
|
+
* to exist in the same process.
|
|
7
|
+
*/
|
|
8
|
+
export interface BunaryConfigStore {
|
|
9
|
+
/** Set the current config for this instance */
|
|
10
|
+
set: (config: BunaryConfig) => void;
|
|
11
|
+
/** Get the current config for this instance */
|
|
12
|
+
get: () => BunaryConfig;
|
|
13
|
+
/** Clear the current config for this instance (useful for tests) */
|
|
14
|
+
clear: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create an isolated Bunary config store.
|
|
18
|
+
*
|
|
19
|
+
* @param initial - Optional initial config to set
|
|
20
|
+
* @returns A config store with get/set/clear methods
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { createConfig, defineConfig } from "@bunary/core";
|
|
25
|
+
*
|
|
26
|
+
* const config = createConfig(defineConfig({ app: { name: "MyApp" } }));
|
|
27
|
+
* const current = config.get();
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function createConfig(initial?: BunaryConfig): BunaryConfigStore;
|
|
2
31
|
/**
|
|
3
32
|
* Define Bunary configuration with type safety
|
|
4
33
|
*
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAS5C;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,+CAA+C;IAC/C,GAAG,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IACpC,+CAA+C;IAC/C,GAAG,EAAE,MAAM,YAAY,CAAC;IACxB,oEAAoE;IACpE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,iBAAiB,CAiBtE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAiB/D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAI9C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @bunary/core
|
|
3
3
|
* Foundation module for Bunary - config, environment, and app helpers
|
|
4
4
|
*/
|
|
5
|
-
export { defineConfig, getBunaryConfig, clearBunaryConfig } from "./config";
|
|
5
|
+
export { createConfig, defineConfig, getBunaryConfig, clearBunaryConfig, } from "./config";
|
|
6
6
|
export { Environment, type EnvironmentType } from "./constants";
|
|
7
7
|
export { env, isDev, isProd, isTest } from "./environment";
|
|
8
8
|
export type { BunaryConfig, AppConfig, OrmConfig } from "./types";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC3D,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6,34 +6,6 @@ var Environment = {
|
|
|
6
6
|
TEST: "test"
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
// src/config.ts
|
|
10
|
-
var globalBunaryConfig = null;
|
|
11
|
-
globalThis.__bunaryCoreConfig = {
|
|
12
|
-
getConfig: () => globalBunaryConfig
|
|
13
|
-
};
|
|
14
|
-
function defineConfig(config) {
|
|
15
|
-
const validated = {
|
|
16
|
-
app: {
|
|
17
|
-
name: config.app.name,
|
|
18
|
-
env: config.app.env ?? Bun.env.NODE_ENV ?? Environment.DEVELOPMENT,
|
|
19
|
-
debug: config.app.debug ?? Bun.env.DEBUG === "true"
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
if (config.orm) {
|
|
23
|
-
validated.orm = config.orm;
|
|
24
|
-
}
|
|
25
|
-
globalBunaryConfig = validated;
|
|
26
|
-
return validated;
|
|
27
|
-
}
|
|
28
|
-
function getBunaryConfig() {
|
|
29
|
-
if (!globalBunaryConfig) {
|
|
30
|
-
throw new Error("Bunary configuration not set. Call defineConfig() first.");
|
|
31
|
-
}
|
|
32
|
-
return globalBunaryConfig;
|
|
33
|
-
}
|
|
34
|
-
function clearBunaryConfig() {
|
|
35
|
-
globalBunaryConfig = null;
|
|
36
|
-
}
|
|
37
9
|
// src/environment.ts
|
|
38
10
|
function env(key, defaultValue) {
|
|
39
11
|
const value = Bun.env[key];
|
|
@@ -58,6 +30,52 @@ function isProd() {
|
|
|
58
30
|
function isTest() {
|
|
59
31
|
return Bun.env.NODE_ENV === Environment.TEST;
|
|
60
32
|
}
|
|
33
|
+
|
|
34
|
+
// src/config.ts
|
|
35
|
+
function normalizeEnv(value) {
|
|
36
|
+
if (value === Environment.DEVELOPMENT)
|
|
37
|
+
return Environment.DEVELOPMENT;
|
|
38
|
+
if (value === Environment.PRODUCTION)
|
|
39
|
+
return Environment.PRODUCTION;
|
|
40
|
+
if (value === Environment.TEST)
|
|
41
|
+
return Environment.TEST;
|
|
42
|
+
return Environment.DEVELOPMENT;
|
|
43
|
+
}
|
|
44
|
+
function createConfig(initial) {
|
|
45
|
+
let current = initial ? defineConfig(initial) : null;
|
|
46
|
+
return {
|
|
47
|
+
set: (config) => {
|
|
48
|
+
current = defineConfig(config);
|
|
49
|
+
},
|
|
50
|
+
get: () => {
|
|
51
|
+
if (!current) {
|
|
52
|
+
throw new Error("Bunary configuration not set. Call set() first.");
|
|
53
|
+
}
|
|
54
|
+
return current;
|
|
55
|
+
},
|
|
56
|
+
clear: () => {
|
|
57
|
+
current = null;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function defineConfig(config) {
|
|
62
|
+
const rawEnv = config.app.env ?? Bun.env.NODE_ENV;
|
|
63
|
+
const validated = {
|
|
64
|
+
app: {
|
|
65
|
+
name: config.app.name,
|
|
66
|
+
env: normalizeEnv(rawEnv),
|
|
67
|
+
debug: config.app.debug ?? env("DEBUG", false)
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (config.orm) {
|
|
71
|
+
validated.orm = config.orm;
|
|
72
|
+
}
|
|
73
|
+
return validated;
|
|
74
|
+
}
|
|
75
|
+
function getBunaryConfig() {
|
|
76
|
+
throw new Error("Global Bunary configuration has been removed. Create an instance config store with createConfig() and call store.get().");
|
|
77
|
+
}
|
|
78
|
+
function clearBunaryConfig() {}
|
|
61
79
|
export {
|
|
62
80
|
isTest,
|
|
63
81
|
isProd,
|
|
@@ -65,6 +83,7 @@ export {
|
|
|
65
83
|
getBunaryConfig,
|
|
66
84
|
env,
|
|
67
85
|
defineConfig,
|
|
86
|
+
createConfig,
|
|
68
87
|
clearBunaryConfig,
|
|
69
88
|
Environment
|
|
70
89
|
};
|
package/dist/types.d.ts
CHANGED
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,iBAAiB;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE;QACR,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;QACtC,MAAM,CAAC,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;QACF,KAAK,CAAC,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,EAAE,MAAM,CAAC;YACjB,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;KACH,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,SAAS,CAAC;IACf,oDAAoD;IACpD,GAAG,CAAC,EAAE,SAAS,CAAC;CACjB"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,iBAAiB;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE;QACR,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC;QACtC,MAAM,CAAC,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;SACd,CAAC;QACF,KAAK,CAAC,EAAE;YACN,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,EAAE,MAAM,CAAC;YACjB,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;QACF,QAAQ,CAAC,EAAE;YACT,IAAI,EAAE,MAAM,CAAC;YACb,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,IAAI,EAAE,MAAM,CAAC;YACb,QAAQ,EAAE,MAAM,CAAC;YACjB,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;KACH,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,SAAS,CAAC;IACf,oDAAoD;IACpD,GAAG,CAAC,EAAE,SAAS,CAAC;CACjB"}
|