@bunary/core 0.0.1 → 0.0.3
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 +71 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/environment.d.ts +33 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +36 -6
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @bunary/core
|
|
2
|
+
|
|
3
|
+
Foundation module for the Bunary framework — configuration, environment helpers, and shared utilities.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @bunary/core
|
|
9
|
+
```
|
|
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
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { defineConfig } from '@bunary/core';
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
app: {
|
|
36
|
+
name: 'MyApp',
|
|
37
|
+
env: 'development',
|
|
38
|
+
debug: true,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
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
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BunaryConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Define Bunary configuration with type safety
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { defineConfig } from "@bunary/core";
|
|
8
|
+
*
|
|
9
|
+
* export default defineConfig({
|
|
10
|
+
* app: {
|
|
11
|
+
* name: "MyApp",
|
|
12
|
+
* env: "development",
|
|
13
|
+
* },
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function defineConfig(config: BunaryConfig): BunaryConfig;
|
|
18
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAW/D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Application environment constants
|
|
3
|
+
*/
|
|
4
|
+
export declare const Environment: {
|
|
5
|
+
readonly DEVELOPMENT: "development";
|
|
6
|
+
readonly PRODUCTION: "production";
|
|
7
|
+
readonly TEST: "test";
|
|
8
|
+
};
|
|
9
|
+
export type EnvironmentType = (typeof Environment)[keyof typeof Environment];
|
|
10
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,WAAW;;;;CAId,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment helpers using Bun.env
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get an environment variable with optional default and automatic type coercion
|
|
6
|
+
* @param key - Environment variable name
|
|
7
|
+
* @param defaultValue - Default value if not set (also determines return type)
|
|
8
|
+
* @returns The environment variable value, coerced to match defaultValue type
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const port = env('PORT', 3000); // Returns number
|
|
12
|
+
* const debug = env('DEBUG', false); // Returns boolean
|
|
13
|
+
* const name = env('APP_NAME', 'app'); // Returns string
|
|
14
|
+
* const secret = env('SECRET'); // Returns string | undefined
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function env(key: string): string | undefined;
|
|
18
|
+
export declare function env(key: string, defaultValue: string): string;
|
|
19
|
+
export declare function env(key: string, defaultValue: number): number;
|
|
20
|
+
export declare function env(key: string, defaultValue: boolean): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if running in development mode
|
|
23
|
+
*/
|
|
24
|
+
export declare function isDev(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Check if running in production mode
|
|
27
|
+
*/
|
|
28
|
+
export declare function isProd(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Check if running in test mode
|
|
31
|
+
*/
|
|
32
|
+
export declare function isTest(): boolean;
|
|
33
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AACA;;GAEG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACrD,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;AAC/D,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAAC;AAC/D,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC;AAuBjE;;GAEG;AACH,wBAAgB,KAAK,IAAI,OAAO,CAE/B;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAEhC;AAED;;GAEG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAEhC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @bunary/core
|
|
3
|
+
* Foundation module for Bunary - config, environment, and app helpers
|
|
4
|
+
*/
|
|
5
|
+
export { defineConfig } from "./config";
|
|
6
|
+
export { Environment, type EnvironmentType } from "./constants";
|
|
7
|
+
export { env, isDev, isProd, isTest } from "./environment";
|
|
8
|
+
export type { BunaryConfig, AppConfig } from "./types";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,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,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/constants.ts
|
|
3
|
+
var Environment = {
|
|
4
|
+
DEVELOPMENT: "development",
|
|
5
|
+
PRODUCTION: "production",
|
|
6
|
+
TEST: "test"
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/config.ts
|
|
10
|
+
function defineConfig(config) {
|
|
11
|
+
return {
|
|
12
|
+
app: {
|
|
13
|
+
name: config.app.name,
|
|
14
|
+
env: config.app.env ?? Bun.env.NODE_ENV ?? Environment.DEVELOPMENT,
|
|
15
|
+
debug: config.app.debug ?? Bun.env.DEBUG === "true"
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// src/environment.ts
|
|
20
|
+
function env(key, defaultValue) {
|
|
21
|
+
const value = Bun.env[key];
|
|
22
|
+
if (value === undefined) {
|
|
23
|
+
return defaultValue;
|
|
24
|
+
}
|
|
25
|
+
if (typeof defaultValue === "boolean") {
|
|
26
|
+
return value === "true" || value === "1" || value === "yes";
|
|
27
|
+
}
|
|
28
|
+
if (typeof defaultValue === "number") {
|
|
29
|
+
const num = Number(value);
|
|
30
|
+
return Number.isNaN(num) ? defaultValue : num;
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function isDev() {
|
|
35
|
+
return Bun.env.NODE_ENV === Environment.DEVELOPMENT || !Bun.env.NODE_ENV;
|
|
36
|
+
}
|
|
37
|
+
function isProd() {
|
|
38
|
+
return Bun.env.NODE_ENV === Environment.PRODUCTION;
|
|
39
|
+
}
|
|
40
|
+
function isTest() {
|
|
41
|
+
return Bun.env.NODE_ENV === Environment.TEST;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
isTest,
|
|
45
|
+
isProd,
|
|
46
|
+
isDev,
|
|
47
|
+
env,
|
|
48
|
+
defineConfig,
|
|
49
|
+
Environment
|
|
50
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EnvironmentType } from "./constants.js";
|
|
2
|
+
/**
|
|
3
|
+
* App configuration
|
|
4
|
+
*/
|
|
5
|
+
export interface AppConfig {
|
|
6
|
+
/** Application name */
|
|
7
|
+
name: string;
|
|
8
|
+
/** Environment: development, production, test */
|
|
9
|
+
env?: EnvironmentType;
|
|
10
|
+
/** Debug mode */
|
|
11
|
+
debug?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Root Bunary configuration
|
|
15
|
+
*/
|
|
16
|
+
export interface BunaryConfig {
|
|
17
|
+
app: AppConfig;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,SAAS,CAAC;CAChB"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bunary/core",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Foundation module for Bunary - config, environment, and app helpers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target bun && bunx tsc -p tsconfig.build.json",
|
|
20
|
+
"typecheck": "bunx tsc --noEmit",
|
|
21
|
+
"test": "bun test",
|
|
22
|
+
"lint": "bunx biome check ./src"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"bunary",
|
|
26
|
+
"bun",
|
|
27
|
+
"backend",
|
|
28
|
+
"framework",
|
|
29
|
+
"config"
|
|
30
|
+
],
|
|
31
|
+
"author": "Paul Radford",
|
|
8
32
|
"license": "MIT",
|
|
9
|
-
"
|
|
33
|
+
"engines": {
|
|
34
|
+
"bun": ">=1.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@biomejs/biome": "^1.9.4",
|
|
38
|
+
"bun-types": "latest"
|
|
39
|
+
}
|
|
10
40
|
}
|