@bunary/core 0.0.5 → 0.1.0

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
@@ -1,6 +1,6 @@
1
1
  # @bunary/core
2
2
 
3
- Foundation module for the Bunary framework configuration, environment helpers, and shared utilities.
3
+ Foundation for the Bunary framework: config (defineConfig, createConfig), environment (env, isDev, isProd, isTest). Full reference: [docs/index.md](./docs/index.md).
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,63 +8,17 @@ Foundation module for the Bunary framework — configuration, environment helper
8
8
  bun add @bunary/core
9
9
  ```
10
10
 
11
- ## Usage
12
-
13
- ### Environment Variables
14
-
15
- ```typescript
16
- import { env, isDev, isProd, isTest } from '@bunary/core';
17
-
18
- // Get environment variable with automatic type coercion
19
- const port = env('PORT', 3000); // Returns number
20
- const debug = env('DEBUG', false); // Returns boolean
21
- const name = env('APP_NAME', 'myapp'); // Returns string
22
-
23
- // Environment detection
24
- if (isDev()) {
25
- console.log('Running in development mode');
26
- }
27
- ```
28
-
29
- ### Configuration
11
+ ## Quick start
30
12
 
31
13
  ```typescript
32
- import { defineConfig } from '@bunary/core';
14
+ import { env, createConfig, defineConfig } from "@bunary/core";
33
15
 
34
- export default defineConfig({
35
- app: {
36
- name: 'MyApp',
37
- env: 'development',
38
- debug: true,
39
- },
40
- });
16
+ const port = env("PORT", 3000);
17
+ const configStore = createConfig(defineConfig({ app: { name: "MyApp", env: "development", debug: true } }));
18
+ export default configStore.get();
41
19
  ```
42
20
 
43
- ## API
44
-
45
- ### `env<T>(key: string, defaultValue?: T): T`
46
-
47
- Get an environment variable with optional default and automatic type coercion.
48
-
49
- ### `isDev(): boolean`
50
-
51
- Returns `true` if `NODE_ENV` is `"development"` or not set.
52
-
53
- ### `isProd(): boolean`
54
-
55
- Returns `true` if `NODE_ENV` is `"production"`.
56
-
57
- ### `isTest(): boolean`
58
-
59
- Returns `true` if `NODE_ENV` is `"test"`.
60
-
61
- ### `defineConfig(config: BunaryConfig): BunaryConfig`
62
-
63
- Type-safe configuration helper with defaults.
64
-
65
- ## Requirements
66
-
67
- - Bun ≥1.0.0
21
+ For API details, see [docs/index.md](./docs/index.md).
68
22
 
69
23
  ## License
70
24
 
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;AAU5C;;;;;;;;;;;;;;;;;;;;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,8 +2,8 @@
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 { clearBunaryConfig, createConfig, defineConfig, getBunaryConfig, } from "./config";
6
6
  export { Environment, type EnvironmentType } from "./constants";
7
7
  export { env, isDev, isProd, isTest } from "./environment";
8
- export type { BunaryConfig, AppConfig, OrmConfig } from "./types";
8
+ export type { AppConfig, BunaryConfig, OrmConfig } from "./types";
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -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,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,GAChB,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,SAAS,EAAE,YAAY,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
@@ -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,I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,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.5",
3
+ "version": "0.1.0",
4
4
  "description": "Foundation module for Bunary - config, environment, and app helpers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -42,7 +42,7 @@
42
42
  "bun": ">=1.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@biomejs/biome": "^1.9.4",
45
+ "@biomejs/biome": "^2.3.13",
46
46
  "bun-types": "latest"
47
47
  }
48
48
  }