@bunary/core 0.0.4 → 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 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 default defineConfig({
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
  *
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAI5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAmB/D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAK9C;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC"}
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";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC5E,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"}
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,31 +6,6 @@ var Environment = {
6
6
  TEST: "test"
7
7
  };
8
8
 
9
- // src/config.ts
10
- var globalBunaryConfig = null;
11
- function defineConfig(config) {
12
- const validated = {
13
- app: {
14
- name: config.app.name,
15
- env: config.app.env ?? Bun.env.NODE_ENV ?? Environment.DEVELOPMENT,
16
- debug: config.app.debug ?? Bun.env.DEBUG === "true"
17
- }
18
- };
19
- if (config.orm) {
20
- validated.orm = config.orm;
21
- }
22
- globalBunaryConfig = validated;
23
- return validated;
24
- }
25
- function getBunaryConfig() {
26
- if (!globalBunaryConfig) {
27
- throw new Error("Bunary configuration not set. Call defineConfig() first.");
28
- }
29
- return globalBunaryConfig;
30
- }
31
- function clearBunaryConfig() {
32
- globalBunaryConfig = null;
33
- }
34
9
  // src/environment.ts
35
10
  function env(key, defaultValue) {
36
11
  const value = Bun.env[key];
@@ -55,6 +30,52 @@ function isProd() {
55
30
  function isTest() {
56
31
  return Bun.env.NODE_ENV === Environment.TEST;
57
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() {}
58
79
  export {
59
80
  isTest,
60
81
  isProd,
@@ -62,6 +83,7 @@ export {
62
83
  getBunaryConfig,
63
84
  env,
64
85
  defineConfig,
86
+ createConfig,
65
87
  clearBunaryConfig,
66
88
  Environment
67
89
  };
package/dist/types.d.ts CHANGED
@@ -27,6 +27,13 @@ export interface OrmConfig {
27
27
  password: string;
28
28
  database: string;
29
29
  };
30
+ postgres?: {
31
+ host: string;
32
+ port?: number;
33
+ user: string;
34
+ password: string;
35
+ database: string;
36
+ };
30
37
  };
31
38
  }
32
39
  /**
@@ -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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bunary/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.7",
4
4
  "description": "Foundation module for Bunary - config, environment, and app helpers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",