@xframework/config 0.4.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.
@@ -0,0 +1,22 @@
1
+
2
+ > @xframework/config@0.4.0 build /home/runner/work/x/x/packages/@xframework/config
3
+ > tsup
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.3.5
8
+ CLI Using tsup config: /home/runner/work/x/x/packages/@xframework/config/tsup.config.ts
9
+ CLI Target: esnext
10
+ CLI Cleaning output folder
11
+ CJS Build start
12
+ ESM Build start
13
+ CJS dist/index.cjs 1.31 KB
14
+ CJS dist/index.cjs.map 770.00 B
15
+ CJS ⚡️ Build success in 27ms
16
+ ESM dist/index.js 303.00 B
17
+ ESM dist/index.js.map 730.00 B
18
+ ESM ⚡️ Build success in 27ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 4195ms
21
+ DTS dist/index.d.cts 345.00 B
22
+ DTS dist/index.d.ts 345.00 B
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @xframework/config
2
+
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 98dd8e4: redesign
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [98dd8e4]
12
+ - @xframework/x@0.4.0
package/dist/index.cjs ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ConfigAdapter: () => ConfigAdapter
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_adapter = require("@xframework/x/adapter");
27
+ var ConfigAdapter = class extends import_adapter.SyncAdapter {
28
+ config;
29
+ constructor({ config }) {
30
+ super();
31
+ this.config = config;
32
+ }
33
+ export() {
34
+ return this.config;
35
+ }
36
+ };
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ ConfigAdapter
40
+ });
41
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { SyncAdapter } from \"@xframework/x/adapter\";\n\nexport class ConfigAdapter<\n UserConfigInstance extends Record<string, unknown>,\n> extends SyncAdapter<UserConfigInstance> {\n public config: UserConfigInstance;\n constructor({ config }: { config: UserConfigInstance }) {\n super();\n this.config = config;\n }\n\n export() {\n return this.config;\n }\n}\n\n// In the future create a more advanced config adapter with storage (sync, and async)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA4B;AAErB,IAAM,gBAAN,cAEG,2BAAgC;AAAA,EACjC;AAAA,EACP,YAAY,EAAE,OAAO,GAAmC;AACtD,UAAM;AACN,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,11 @@
1
+ import { SyncAdapter } from '@xframework/x/adapter';
2
+
3
+ declare class ConfigAdapter<UserConfigInstance extends Record<string, unknown>> extends SyncAdapter<UserConfigInstance> {
4
+ config: UserConfigInstance;
5
+ constructor({ config }: {
6
+ config: UserConfigInstance;
7
+ });
8
+ export(): UserConfigInstance;
9
+ }
10
+
11
+ export { ConfigAdapter };
@@ -0,0 +1,11 @@
1
+ import { SyncAdapter } from '@xframework/x/adapter';
2
+
3
+ declare class ConfigAdapter<UserConfigInstance extends Record<string, unknown>> extends SyncAdapter<UserConfigInstance> {
4
+ config: UserConfigInstance;
5
+ constructor({ config }: {
6
+ config: UserConfigInstance;
7
+ });
8
+ export(): UserConfigInstance;
9
+ }
10
+
11
+ export { ConfigAdapter };
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ // src/index.ts
2
+ import { SyncAdapter } from "@xframework/x/adapter";
3
+ var ConfigAdapter = class extends SyncAdapter {
4
+ config;
5
+ constructor({ config }) {
6
+ super();
7
+ this.config = config;
8
+ }
9
+ export() {
10
+ return this.config;
11
+ }
12
+ };
13
+ export {
14
+ ConfigAdapter
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { SyncAdapter } from \"@xframework/x/adapter\";\n\nexport class ConfigAdapter<\n UserConfigInstance extends Record<string, unknown>,\n> extends SyncAdapter<UserConfigInstance> {\n public config: UserConfigInstance;\n constructor({ config }: { config: UserConfigInstance }) {\n super();\n this.config = config;\n }\n\n export() {\n return this.config;\n }\n}\n\n// In the future create a more advanced config adapter with storage (sync, and async)\n"],"mappings":";AAAA,SAAS,mBAAmB;AAErB,IAAM,gBAAN,cAEG,YAAgC;AAAA,EACjC;AAAA,EACP,YAAY,EAAE,OAAO,GAAmC;AACtD,UAAM;AACN,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,SAAS;AACP,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@xframework/config",
3
+ "version": "0.4.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "require": "./dist/index.cjs",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "dependencies": {
19
+ "@xframework/x": "0.4.0"
20
+ },
21
+ "peerDependencies": {},
22
+ "devDependencies": {
23
+ "@types/node": "^20.11.24",
24
+ "tsup": "^8.2.4",
25
+ "typescript": "^5.5.4"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "dev": "tsup --watch"
30
+ }
31
+ }
@@ -0,0 +1,147 @@
1
+ import { expect, it, describe } from "vitest";
2
+ import { createX } from "@xframework/x";
3
+ import { ConfigAdapter } from "../index";
4
+
5
+ describe("ConfigAdapter", () => {
6
+ // Test with a simple config object
7
+ const simpleConfig = {
8
+ apiKey: "test-api-key",
9
+ url: "https://api.example.com",
10
+ version: 1,
11
+ } as const;
12
+
13
+ it("should properly initialize and export config instance", () => {
14
+ const adapter = new ConfigAdapter({
15
+ config: simpleConfig,
16
+ });
17
+
18
+ expect(adapter.config).toBe(simpleConfig);
19
+ expect(adapter.export()).toBe(simpleConfig);
20
+ });
21
+
22
+ it("should integrate with X framework", () => {
23
+ const x = createX()
24
+ .syncAdapter(
25
+ "config",
26
+ () =>
27
+ new ConfigAdapter({
28
+ config: simpleConfig,
29
+ }),
30
+ )
31
+ .build();
32
+
33
+ expect(x._.adapters.config).toBeInstanceOf(ConfigAdapter);
34
+ expect(x.config).toBe(simpleConfig);
35
+ expect(x.config.apiKey).toBe("test-api-key");
36
+ expect(x.config.url).toBe("https://api.example.com");
37
+ expect(x.config.version).toBe(1);
38
+ });
39
+
40
+ // Test with a nested config object
41
+ const nestedConfig = {
42
+ api: {
43
+ key: "test-api-key",
44
+ endpoints: {
45
+ users: "/api/users",
46
+ posts: "/api/posts",
47
+ },
48
+ version: 2,
49
+ },
50
+ database: {
51
+ host: "localhost",
52
+ port: 5432,
53
+ credentials: {
54
+ username: "admin",
55
+ password: "secret",
56
+ },
57
+ },
58
+ features: {
59
+ darkMode: true,
60
+ beta: {
61
+ enabled: false,
62
+ whitelist: ["user1", "user2"],
63
+ },
64
+ },
65
+ } as const;
66
+
67
+ it("should handle nested config objects", () => {
68
+ const adapter = new ConfigAdapter({
69
+ config: nestedConfig,
70
+ });
71
+
72
+ expect(adapter.config).toBe(nestedConfig);
73
+ expect(adapter.export()).toBe(nestedConfig);
74
+ });
75
+
76
+ it("should provide type-safe access to nested config through X framework", () => {
77
+ const x = createX()
78
+ .syncAdapter(
79
+ "config",
80
+ () =>
81
+ new ConfigAdapter({
82
+ config: nestedConfig,
83
+ }),
84
+ )
85
+ .build();
86
+
87
+ expect(x.config.api.key).toBe("test-api-key");
88
+ expect(x.config.api.endpoints.users).toBe("/api/users");
89
+ expect(x.config.database.credentials.username).toBe("admin");
90
+ expect(x.config.features.beta.whitelist).toEqual(["user1", "user2"]);
91
+ });
92
+
93
+ // Test with different config types
94
+ it("should handle configs with various types", () => {
95
+ const mixedConfig = {
96
+ string: "test",
97
+ number: 42,
98
+ boolean: true,
99
+ array: [1, 2, 3],
100
+ date: new Date("2024-01-01"),
101
+ nullable: null as null | string,
102
+ optional: undefined as undefined | number,
103
+ tuple: ["id", 123] as const,
104
+ union: "value" as "value" | "other",
105
+ };
106
+
107
+ const x = createX()
108
+ .syncAdapter(
109
+ "config",
110
+ () =>
111
+ new ConfigAdapter({
112
+ config: mixedConfig,
113
+ }),
114
+ )
115
+ .build();
116
+
117
+ expect(x.config.string).toBe("test");
118
+ expect(x.config.number).toBe(42);
119
+ expect(x.config.boolean).toBe(true);
120
+ expect(x.config.array).toEqual([1, 2, 3]);
121
+ expect(x.config.date).toBeInstanceOf(Date);
122
+ expect(x.config.nullable).toBeNull();
123
+ expect(x.config.optional).toBeUndefined();
124
+ expect(x.config.tuple).toEqual(["id", 123]);
125
+ expect(x.config.union).toBe("value");
126
+ });
127
+
128
+ // Test compile-time type constraints
129
+ it("should have proper TypeScript type constraints", () => {
130
+ // These would fail at compile time, but work at runtime
131
+ // @ts-expect-error Config must be a record of string keys
132
+ const nullConfig = new ConfigAdapter({ config: null });
133
+ expect(nullConfig.config).toBe(null);
134
+
135
+ // @ts-expect-error Config must be a record of string keys
136
+ const undefinedConfig = new ConfigAdapter({ config: undefined });
137
+ expect(undefinedConfig.config).toBe(undefined);
138
+
139
+ // @ts-expect-error Config must be a record of string keys
140
+ const numberConfig = new ConfigAdapter({ config: 42 });
141
+ expect(numberConfig.config).toBe(42);
142
+
143
+ // @ts-expect-error Config must be a record of string keys
144
+ const stringConfig = new ConfigAdapter({ config: "not an object" });
145
+ expect(stringConfig.config).toBe("not an object");
146
+ });
147
+ });
package/src/index.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { SyncAdapter } from "@xframework/x/adapter";
2
+
3
+ export class ConfigAdapter<
4
+ UserConfigInstance extends Record<string, unknown>,
5
+ > extends SyncAdapter<UserConfigInstance> {
6
+ public config: UserConfigInstance;
7
+ constructor({ config }: { config: UserConfigInstance }) {
8
+ super();
9
+ this.config = config;
10
+ }
11
+
12
+ export() {
13
+ return this.config;
14
+ }
15
+ }
16
+
17
+ // In the future create a more advanced config adapter with storage (sync, and async)
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "lib": ["ESNext", "DOM"]
6
+ },
7
+ "include": ["src", "tsup.config.ts"],
8
+ "exclude": ["node_modules", "dist"]
9
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { tsupConfig } from "../../../utils/tsup.config";
2
+
3
+ export default tsupConfig;