@bunary/core 0.0.2 → 0.0.4
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 +19 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/environment.d.ts +4 -1
- package/dist/environment.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -7
- package/dist/types.d.ts +23 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -1
package/dist/config.d.ts
CHANGED
|
@@ -11,8 +11,27 @@ import type { BunaryConfig } from "./types";
|
|
|
11
11
|
* name: "MyApp",
|
|
12
12
|
* env: "development",
|
|
13
13
|
* },
|
|
14
|
+
* orm: {
|
|
15
|
+
* database: {
|
|
16
|
+
* type: "sqlite",
|
|
17
|
+
* sqlite: { path: "./database.sqlite" }
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
14
20
|
* });
|
|
15
21
|
* ```
|
|
16
22
|
*/
|
|
17
23
|
export declare function defineConfig(config: BunaryConfig): BunaryConfig;
|
|
24
|
+
/**
|
|
25
|
+
* Get the global Bunary configuration
|
|
26
|
+
*
|
|
27
|
+
* @returns The current Bunary configuration
|
|
28
|
+
* @throws If configuration has not been set
|
|
29
|
+
*/
|
|
30
|
+
export declare function getBunaryConfig(): BunaryConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Clear the global Bunary configuration (useful for testing)
|
|
33
|
+
*
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export declare function clearBunaryConfig(): void;
|
|
18
37
|
//# sourceMappingURL=config.d.ts.map
|
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":"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"}
|
|
@@ -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"}
|
package/dist/environment.d.ts
CHANGED
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
* const secret = env('SECRET'); // Returns string | undefined
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export declare function env
|
|
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;
|
|
18
21
|
/**
|
|
19
22
|
* Check if running in development mode
|
|
20
23
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"
|
|
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
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* @bunary/core
|
|
3
3
|
* Foundation module for Bunary - config, environment, and app helpers
|
|
4
4
|
*/
|
|
5
|
-
export { defineConfig } from "./config";
|
|
5
|
+
export { defineConfig, getBunaryConfig, clearBunaryConfig } from "./config";
|
|
6
|
+
export { Environment, type EnvironmentType } from "./constants";
|
|
6
7
|
export { env, isDev, isProd, isTest } from "./environment";
|
|
7
|
-
export type { BunaryConfig, AppConfig } from "./types";
|
|
8
|
+
export type { BunaryConfig, AppConfig, OrmConfig } from "./types";
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
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,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;
|
|
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"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
// src/constants.ts
|
|
3
|
+
var Environment = {
|
|
4
|
+
DEVELOPMENT: "development",
|
|
5
|
+
PRODUCTION: "production",
|
|
6
|
+
TEST: "test"
|
|
7
|
+
};
|
|
8
|
+
|
|
2
9
|
// src/config.ts
|
|
10
|
+
var globalBunaryConfig = null;
|
|
3
11
|
function defineConfig(config) {
|
|
4
|
-
|
|
12
|
+
const validated = {
|
|
5
13
|
app: {
|
|
6
14
|
name: config.app.name,
|
|
7
|
-
env: config.app.env ?? Bun.env.NODE_ENV ??
|
|
15
|
+
env: config.app.env ?? Bun.env.NODE_ENV ?? Environment.DEVELOPMENT,
|
|
8
16
|
debug: config.app.debug ?? Bun.env.DEBUG === "true"
|
|
9
17
|
}
|
|
10
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;
|
|
11
33
|
}
|
|
12
34
|
// src/environment.ts
|
|
13
35
|
function env(key, defaultValue) {
|
|
@@ -16,7 +38,7 @@ function env(key, defaultValue) {
|
|
|
16
38
|
return defaultValue;
|
|
17
39
|
}
|
|
18
40
|
if (typeof defaultValue === "boolean") {
|
|
19
|
-
return value === "true";
|
|
41
|
+
return value === "true" || value === "1" || value === "yes";
|
|
20
42
|
}
|
|
21
43
|
if (typeof defaultValue === "number") {
|
|
22
44
|
const num = Number(value);
|
|
@@ -25,18 +47,21 @@ function env(key, defaultValue) {
|
|
|
25
47
|
return value;
|
|
26
48
|
}
|
|
27
49
|
function isDev() {
|
|
28
|
-
return Bun.env.NODE_ENV ===
|
|
50
|
+
return Bun.env.NODE_ENV === Environment.DEVELOPMENT || !Bun.env.NODE_ENV;
|
|
29
51
|
}
|
|
30
52
|
function isProd() {
|
|
31
|
-
return Bun.env.NODE_ENV ===
|
|
53
|
+
return Bun.env.NODE_ENV === Environment.PRODUCTION;
|
|
32
54
|
}
|
|
33
55
|
function isTest() {
|
|
34
|
-
return Bun.env.NODE_ENV ===
|
|
56
|
+
return Bun.env.NODE_ENV === Environment.TEST;
|
|
35
57
|
}
|
|
36
58
|
export {
|
|
37
59
|
isTest,
|
|
38
60
|
isProd,
|
|
39
61
|
isDev,
|
|
62
|
+
getBunaryConfig,
|
|
40
63
|
env,
|
|
41
|
-
defineConfig
|
|
64
|
+
defineConfig,
|
|
65
|
+
clearBunaryConfig,
|
|
66
|
+
Environment
|
|
42
67
|
};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EnvironmentType } from "./constants.js";
|
|
1
2
|
/**
|
|
2
3
|
* App configuration
|
|
3
4
|
*/
|
|
@@ -5,14 +6,35 @@ export interface AppConfig {
|
|
|
5
6
|
/** Application name */
|
|
6
7
|
name: string;
|
|
7
8
|
/** Environment: development, production, test */
|
|
8
|
-
env?:
|
|
9
|
+
env?: EnvironmentType;
|
|
9
10
|
/** Debug mode */
|
|
10
11
|
debug?: boolean;
|
|
11
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* ORM configuration type (matches @bunary/orm OrmConfig)
|
|
15
|
+
* Defined here to avoid circular dependency
|
|
16
|
+
*/
|
|
17
|
+
export interface OrmConfig {
|
|
18
|
+
database: {
|
|
19
|
+
type: "sqlite" | "mysql" | "postgres";
|
|
20
|
+
sqlite?: {
|
|
21
|
+
path: string;
|
|
22
|
+
};
|
|
23
|
+
mysql?: {
|
|
24
|
+
host: string;
|
|
25
|
+
port?: number;
|
|
26
|
+
user: string;
|
|
27
|
+
password: string;
|
|
28
|
+
database: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
12
32
|
/**
|
|
13
33
|
* Root Bunary configuration
|
|
14
34
|
*/
|
|
15
35
|
export interface BunaryConfig {
|
|
16
36
|
app: AppConfig;
|
|
37
|
+
/** Optional ORM configuration (from @bunary/orm) */
|
|
38
|
+
orm?: OrmConfig;
|
|
17
39
|
}
|
|
18
40
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,GAAG,CAAC,EAAE,
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bunary/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Foundation module for Bunary - config, environment, and app helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,6 +30,14 @@
|
|
|
30
30
|
],
|
|
31
31
|
"author": "Paul Radford",
|
|
32
32
|
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/bunary-dev/core.git"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/bunary-dev/core#readme",
|
|
38
|
+
"bugs": {
|
|
39
|
+
"url": "https://github.com/bunary-dev/core/issues"
|
|
40
|
+
},
|
|
33
41
|
"engines": {
|
|
34
42
|
"bun": ">=1.0.0"
|
|
35
43
|
},
|