@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.
- package/.turbo/turbo-build.log +22 -0
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/package.json +31 -0
- package/src/__tests__/index.test.ts +147 -0
- package/src/index.ts +17 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +3 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
> @xframework/config@0.4.0 build /home/runner/work/x/x/packages/@xframework/config
|
3
|
+
> tsup
|
4
|
+
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
7
|
+
[34mCLI[39m tsup v8.3.5
|
8
|
+
[34mCLI[39m Using tsup config: /home/runner/work/x/x/packages/@xframework/config/tsup.config.ts
|
9
|
+
[34mCLI[39m Target: esnext
|
10
|
+
[34mCLI[39m Cleaning output folder
|
11
|
+
[34mCJS[39m Build start
|
12
|
+
[34mESM[39m Build start
|
13
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m1.31 KB[39m
|
14
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m770.00 B[39m
|
15
|
+
[32mCJS[39m ⚡️ Build success in 27ms
|
16
|
+
[32mESM[39m [1mdist/index.js [22m[32m303.00 B[39m
|
17
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m730.00 B[39m
|
18
|
+
[32mESM[39m ⚡️ Build success in 27ms
|
19
|
+
[34mDTS[39m Build start
|
20
|
+
[32mDTS[39m ⚡️ Build success in 4195ms
|
21
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m345.00 B[39m
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m345.00 B[39m
|
package/CHANGELOG.md
ADDED
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":[]}
|
package/dist/index.d.cts
ADDED
@@ -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.d.ts
ADDED
@@ -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
package/tsup.config.ts
ADDED