@xframework/x 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.
Files changed (46) hide show
  1. package/.turbo/turbo-build.log +46 -0
  2. package/CHANGELOG.md +7 -0
  3. package/dist/adapter.cjs +50 -0
  4. package/dist/adapter.cjs.map +1 -0
  5. package/dist/adapter.d.cts +2 -0
  6. package/dist/adapter.d.ts +2 -0
  7. package/dist/adapter.js +21 -0
  8. package/dist/adapter.js.map +1 -0
  9. package/dist/core/adapters.cjs +48 -0
  10. package/dist/core/adapters.cjs.map +1 -0
  11. package/dist/core/adapters.d.cts +19 -0
  12. package/dist/core/adapters.d.ts +19 -0
  13. package/dist/core/adapters.js +21 -0
  14. package/dist/core/adapters.js.map +1 -0
  15. package/dist/core/types.cjs +19 -0
  16. package/dist/core/types.cjs.map +1 -0
  17. package/dist/core/types.d.cts +25 -0
  18. package/dist/core/types.d.ts +25 -0
  19. package/dist/core/types.js +1 -0
  20. package/dist/core/types.js.map +1 -0
  21. package/dist/core/x.cjs +134 -0
  22. package/dist/core/x.cjs.map +1 -0
  23. package/dist/core/x.d.cts +17 -0
  24. package/dist/core/x.d.ts +17 -0
  25. package/dist/core/x.js +107 -0
  26. package/dist/core/x.js.map +1 -0
  27. package/dist/index.cjs +134 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +2 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.js +107 -0
  32. package/dist/index.js.map +1 -0
  33. package/package.json +33 -0
  34. package/src/__tests__/async-adapter.test.ts +87 -0
  35. package/src/__tests__/composition.test.ts +45 -0
  36. package/src/__tests__/core.test.ts +23 -0
  37. package/src/__tests__/error-handling.test.ts +71 -0
  38. package/src/__tests__/sync-adapter.test.ts +83 -0
  39. package/src/__tests__/type-system.test.ts +78 -0
  40. package/src/adapter.ts +1 -0
  41. package/src/core/adapters.ts +26 -0
  42. package/src/core/types.ts +47 -0
  43. package/src/core/x.ts +163 -0
  44. package/src/index.ts +1 -0
  45. package/tsconfig.json +9 -0
  46. package/tsup.config.ts +3 -0
@@ -0,0 +1,46 @@
1
+
2
+ > @xframework/x@0.4.0 build /home/runner/work/x/x/packages/@xframework/x
3
+ > tsup
4
+
5
+ CLI Building entry: src/adapter.ts, src/index.ts, src/core/adapters.ts, src/core/types.ts, src/core/x.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/x/tsup.config.ts
9
+ CLI Target: esnext
10
+ CLI Cleaning output folder
11
+ CJS Build start
12
+ ESM Build start
13
+ CJS dist/adapter.cjs 1.49 KB
14
+ CJS dist/core/adapters.cjs 1.48 KB
15
+ CJS dist/core/types.cjs 797.00 B
16
+ CJS dist/core/x.cjs 3.55 KB
17
+ CJS dist/index.cjs 3.57 KB
18
+ CJS dist/adapter.cjs.map 1.11 KB
19
+ CJS dist/core/adapters.cjs.map 1.01 KB
20
+ CJS dist/core/types.cjs.map 1.48 KB
21
+ CJS dist/core/x.cjs.map 7.67 KB
22
+ CJS dist/index.cjs.map 7.72 KB
23
+ CJS ⚡️ Build success in 17ms
24
+ ESM dist/adapter.js 420.00 B
25
+ ESM dist/index.js 2.57 KB
26
+ ESM dist/core/types.js 33.00 B
27
+ ESM dist/core/adapters.js 421.00 B
28
+ ESM dist/core/x.js 2.56 KB
29
+ ESM dist/adapter.js.map 978.00 B
30
+ ESM dist/index.js.map 7.62 KB
31
+ ESM dist/core/types.js.map 71.00 B
32
+ ESM dist/core/adapters.js.map 981.00 B
33
+ ESM dist/core/x.js.map 7.63 KB
34
+ ESM ⚡️ Build success in 18ms
35
+ DTS Build start
36
+ DTS ⚡️ Build success in 2038ms
37
+ DTS dist/core/types.d.cts 1.24 KB
38
+ DTS dist/core/adapters.d.cts 673.00 B
39
+ DTS dist/core/x.d.cts 1.28 KB
40
+ DTS dist/adapter.d.cts 106.00 B
41
+ DTS dist/index.d.cts 67.00 B
42
+ DTS dist/core/types.d.ts 1.24 KB
43
+ DTS dist/core/adapters.d.ts 672.00 B
44
+ DTS dist/core/x.d.ts 1.28 KB
45
+ DTS dist/adapter.d.ts 104.00 B
46
+ DTS dist/index.d.ts 65.00 B
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @xframework/x
2
+
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 98dd8e4: redesign
@@ -0,0 +1,50 @@
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/adapter.ts
21
+ var adapter_exports = {};
22
+ __export(adapter_exports, {
23
+ AdapterError: () => AdapterError,
24
+ AsyncAdapter: () => AsyncAdapter,
25
+ SyncAdapter: () => SyncAdapter
26
+ });
27
+ module.exports = __toCommonJS(adapter_exports);
28
+
29
+ // src/core/adapters.ts
30
+ var SyncAdapter = class {
31
+ __type = "sync";
32
+ };
33
+ var AsyncAdapter = class {
34
+ __type = "async";
35
+ };
36
+ var AdapterError = class extends Error {
37
+ constructor(message, adapterName, cause) {
38
+ super(message);
39
+ this.adapterName = adapterName;
40
+ this.cause = cause;
41
+ this.name = "AdapterError";
42
+ }
43
+ };
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ AdapterError,
47
+ AsyncAdapter,
48
+ SyncAdapter
49
+ });
50
+ //# sourceMappingURL=adapter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/adapter.ts","../src/core/adapters.ts"],"sourcesContent":["export { AsyncAdapter, SyncAdapter, AdapterError } from \"./core/adapters\";\n","import type { SyncAdapterType, AsyncAdapterType } from \"./types\";\n\nexport abstract class SyncAdapter<TExport> implements SyncAdapterType<TExport> {\n readonly __type = \"sync\" as const;\n init?(): void;\n abstract export(): TExport;\n}\n\nexport abstract class AsyncAdapter<TExport>\n implements AsyncAdapterType<TExport>\n{\n readonly __type = \"async\" as const;\n init?(): Promise<void>;\n abstract export(): Promise<TExport>;\n}\n\nexport class AdapterError extends Error {\n constructor(\n message: string,\n public readonly adapterName: string,\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"AdapterError\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAe,cAAf,MAAwE;AAAA,EACpE,SAAS;AAGpB;AAEO,IAAe,eAAf,MAEP;AAAA,EACW,SAAS;AAGpB;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,aACA,OAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,2 @@
1
+ export { AdapterError, AsyncAdapter, SyncAdapter } from './core/adapters.cjs';
2
+ import './core/types.cjs';
@@ -0,0 +1,2 @@
1
+ export { AdapterError, AsyncAdapter, SyncAdapter } from './core/adapters.js';
2
+ import './core/types.js';
@@ -0,0 +1,21 @@
1
+ // src/core/adapters.ts
2
+ var SyncAdapter = class {
3
+ __type = "sync";
4
+ };
5
+ var AsyncAdapter = class {
6
+ __type = "async";
7
+ };
8
+ var AdapterError = class extends Error {
9
+ constructor(message, adapterName, cause) {
10
+ super(message);
11
+ this.adapterName = adapterName;
12
+ this.cause = cause;
13
+ this.name = "AdapterError";
14
+ }
15
+ };
16
+ export {
17
+ AdapterError,
18
+ AsyncAdapter,
19
+ SyncAdapter
20
+ };
21
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/adapters.ts"],"sourcesContent":["import type { SyncAdapterType, AsyncAdapterType } from \"./types\";\n\nexport abstract class SyncAdapter<TExport> implements SyncAdapterType<TExport> {\n readonly __type = \"sync\" as const;\n init?(): void;\n abstract export(): TExport;\n}\n\nexport abstract class AsyncAdapter<TExport>\n implements AsyncAdapterType<TExport>\n{\n readonly __type = \"async\" as const;\n init?(): Promise<void>;\n abstract export(): Promise<TExport>;\n}\n\nexport class AdapterError extends Error {\n constructor(\n message: string,\n public readonly adapterName: string,\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"AdapterError\";\n }\n}\n"],"mappings":";AAEO,IAAe,cAAf,MAAwE;AAAA,EACpE,SAAS;AAGpB;AAEO,IAAe,eAAf,MAEP;AAAA,EACW,SAAS;AAGpB;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,aACA,OAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,48 @@
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/core/adapters.ts
21
+ var adapters_exports = {};
22
+ __export(adapters_exports, {
23
+ AdapterError: () => AdapterError,
24
+ AsyncAdapter: () => AsyncAdapter,
25
+ SyncAdapter: () => SyncAdapter
26
+ });
27
+ module.exports = __toCommonJS(adapters_exports);
28
+ var SyncAdapter = class {
29
+ __type = "sync";
30
+ };
31
+ var AsyncAdapter = class {
32
+ __type = "async";
33
+ };
34
+ var AdapterError = class extends Error {
35
+ constructor(message, adapterName, cause) {
36
+ super(message);
37
+ this.adapterName = adapterName;
38
+ this.cause = cause;
39
+ this.name = "AdapterError";
40
+ }
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ AdapterError,
45
+ AsyncAdapter,
46
+ SyncAdapter
47
+ });
48
+ //# sourceMappingURL=adapters.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/adapters.ts"],"sourcesContent":["import type { SyncAdapterType, AsyncAdapterType } from \"./types\";\n\nexport abstract class SyncAdapter<TExport> implements SyncAdapterType<TExport> {\n readonly __type = \"sync\" as const;\n init?(): void;\n abstract export(): TExport;\n}\n\nexport abstract class AsyncAdapter<TExport>\n implements AsyncAdapterType<TExport>\n{\n readonly __type = \"async\" as const;\n init?(): Promise<void>;\n abstract export(): Promise<TExport>;\n}\n\nexport class AdapterError extends Error {\n constructor(\n message: string,\n public readonly adapterName: string,\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"AdapterError\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,IAAe,cAAf,MAAwE;AAAA,EACpE,SAAS;AAGpB;AAEO,IAAe,eAAf,MAEP;AAAA,EACW,SAAS;AAGpB;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,aACA,OAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,19 @@
1
+ import { SyncAdapterType, AsyncAdapterType } from './types.cjs';
2
+
3
+ declare abstract class SyncAdapter<TExport> implements SyncAdapterType<TExport> {
4
+ readonly __type: "sync";
5
+ init?(): void;
6
+ abstract export(): TExport;
7
+ }
8
+ declare abstract class AsyncAdapter<TExport> implements AsyncAdapterType<TExport> {
9
+ readonly __type: "async";
10
+ init?(): Promise<void>;
11
+ abstract export(): Promise<TExport>;
12
+ }
13
+ declare class AdapterError extends Error {
14
+ readonly adapterName: string;
15
+ readonly cause?: unknown | undefined;
16
+ constructor(message: string, adapterName: string, cause?: unknown | undefined);
17
+ }
18
+
19
+ export { AdapterError, AsyncAdapter, SyncAdapter };
@@ -0,0 +1,19 @@
1
+ import { SyncAdapterType, AsyncAdapterType } from './types.js';
2
+
3
+ declare abstract class SyncAdapter<TExport> implements SyncAdapterType<TExport> {
4
+ readonly __type: "sync";
5
+ init?(): void;
6
+ abstract export(): TExport;
7
+ }
8
+ declare abstract class AsyncAdapter<TExport> implements AsyncAdapterType<TExport> {
9
+ readonly __type: "async";
10
+ init?(): Promise<void>;
11
+ abstract export(): Promise<TExport>;
12
+ }
13
+ declare class AdapterError extends Error {
14
+ readonly adapterName: string;
15
+ readonly cause?: unknown | undefined;
16
+ constructor(message: string, adapterName: string, cause?: unknown | undefined);
17
+ }
18
+
19
+ export { AdapterError, AsyncAdapter, SyncAdapter };
@@ -0,0 +1,21 @@
1
+ // src/core/adapters.ts
2
+ var SyncAdapter = class {
3
+ __type = "sync";
4
+ };
5
+ var AsyncAdapter = class {
6
+ __type = "async";
7
+ };
8
+ var AdapterError = class extends Error {
9
+ constructor(message, adapterName, cause) {
10
+ super(message);
11
+ this.adapterName = adapterName;
12
+ this.cause = cause;
13
+ this.name = "AdapterError";
14
+ }
15
+ };
16
+ export {
17
+ AdapterError,
18
+ AsyncAdapter,
19
+ SyncAdapter
20
+ };
21
+ //# sourceMappingURL=adapters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/adapters.ts"],"sourcesContent":["import type { SyncAdapterType, AsyncAdapterType } from \"./types\";\n\nexport abstract class SyncAdapter<TExport> implements SyncAdapterType<TExport> {\n readonly __type = \"sync\" as const;\n init?(): void;\n abstract export(): TExport;\n}\n\nexport abstract class AsyncAdapter<TExport>\n implements AsyncAdapterType<TExport>\n{\n readonly __type = \"async\" as const;\n init?(): Promise<void>;\n abstract export(): Promise<TExport>;\n}\n\nexport class AdapterError extends Error {\n constructor(\n message: string,\n public readonly adapterName: string,\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"AdapterError\";\n }\n}\n"],"mappings":";AAEO,IAAe,cAAf,MAAwE;AAAA,EACpE,SAAS;AAGpB;AAEO,IAAe,eAAf,MAEP;AAAA,EACW,SAAS;AAGpB;AAEO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,aACA,OAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -0,0 +1,19 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/core/types.ts
17
+ var types_exports = {};
18
+ module.exports = __toCommonJS(types_exports);
19
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/types.ts"],"sourcesContent":["// Core adapter type definitions\nexport type SyncAdapterType<TExport = unknown> = {\n __type: \"sync\";\n init?(): void;\n export(): TExport;\n};\n\nexport type AsyncAdapterType<TExport = unknown> = {\n __type: \"async\";\n init?(): Promise<void>;\n export(): Promise<TExport>;\n};\n\nexport type AnyAdapter = SyncAdapterType | AsyncAdapterType;\nexport type AdapterRegistry = Record<string, AnyAdapter>;\n\n// Helper type to extract the exported type from an adapter\nexport type ExportType<TAdapter> = TAdapter extends\n | SyncAdapterType<infer TExport>\n | AsyncAdapterType<infer TExport>\n ? TExport\n : never;\n\n// Result type with metadata container\nexport type AdapterResult<TAdapters extends AdapterRegistry> = {\n [Key in keyof TAdapters]: ExportType<TAdapters[Key]>;\n} & {\n _: {\n adapters: TAdapters;\n };\n};\n\nexport type BuildOutput<\n TAdapters extends AdapterRegistry,\n TIsAsync extends boolean,\n> = TIsAsync extends true\n ? Promise<AdapterResult<TAdapters>>\n : AdapterResult<TAdapters>;\n\n// Factory types\nexport type SyncAdapterCreator<TExport, TDeps extends AdapterRegistry> = (\n dependencies: AdapterResult<TDeps>,\n) => SyncAdapterType<TExport>;\n\nexport type AsyncAdapterCreator<TExport, TDeps extends AdapterRegistry> = (\n dependencies: AdapterResult<TDeps>,\n) => Promise<AsyncAdapterType<TExport>> | AsyncAdapterType<TExport>;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,25 @@
1
+ type SyncAdapterType<TExport = unknown> = {
2
+ __type: "sync";
3
+ init?(): void;
4
+ export(): TExport;
5
+ };
6
+ type AsyncAdapterType<TExport = unknown> = {
7
+ __type: "async";
8
+ init?(): Promise<void>;
9
+ export(): Promise<TExport>;
10
+ };
11
+ type AnyAdapter = SyncAdapterType | AsyncAdapterType;
12
+ type AdapterRegistry = Record<string, AnyAdapter>;
13
+ type ExportType<TAdapter> = TAdapter extends SyncAdapterType<infer TExport> | AsyncAdapterType<infer TExport> ? TExport : never;
14
+ type AdapterResult<TAdapters extends AdapterRegistry> = {
15
+ [Key in keyof TAdapters]: ExportType<TAdapters[Key]>;
16
+ } & {
17
+ _: {
18
+ adapters: TAdapters;
19
+ };
20
+ };
21
+ type BuildOutput<TAdapters extends AdapterRegistry, TIsAsync extends boolean> = TIsAsync extends true ? Promise<AdapterResult<TAdapters>> : AdapterResult<TAdapters>;
22
+ type SyncAdapterCreator<TExport, TDeps extends AdapterRegistry> = (dependencies: AdapterResult<TDeps>) => SyncAdapterType<TExport>;
23
+ type AsyncAdapterCreator<TExport, TDeps extends AdapterRegistry> = (dependencies: AdapterResult<TDeps>) => Promise<AsyncAdapterType<TExport>> | AsyncAdapterType<TExport>;
24
+
25
+ export type { AdapterRegistry, AdapterResult, AnyAdapter, AsyncAdapterCreator, AsyncAdapterType, BuildOutput, ExportType, SyncAdapterCreator, SyncAdapterType };
@@ -0,0 +1,25 @@
1
+ type SyncAdapterType<TExport = unknown> = {
2
+ __type: "sync";
3
+ init?(): void;
4
+ export(): TExport;
5
+ };
6
+ type AsyncAdapterType<TExport = unknown> = {
7
+ __type: "async";
8
+ init?(): Promise<void>;
9
+ export(): Promise<TExport>;
10
+ };
11
+ type AnyAdapter = SyncAdapterType | AsyncAdapterType;
12
+ type AdapterRegistry = Record<string, AnyAdapter>;
13
+ type ExportType<TAdapter> = TAdapter extends SyncAdapterType<infer TExport> | AsyncAdapterType<infer TExport> ? TExport : never;
14
+ type AdapterResult<TAdapters extends AdapterRegistry> = {
15
+ [Key in keyof TAdapters]: ExportType<TAdapters[Key]>;
16
+ } & {
17
+ _: {
18
+ adapters: TAdapters;
19
+ };
20
+ };
21
+ type BuildOutput<TAdapters extends AdapterRegistry, TIsAsync extends boolean> = TIsAsync extends true ? Promise<AdapterResult<TAdapters>> : AdapterResult<TAdapters>;
22
+ type SyncAdapterCreator<TExport, TDeps extends AdapterRegistry> = (dependencies: AdapterResult<TDeps>) => SyncAdapterType<TExport>;
23
+ type AsyncAdapterCreator<TExport, TDeps extends AdapterRegistry> = (dependencies: AdapterResult<TDeps>) => Promise<AsyncAdapterType<TExport>> | AsyncAdapterType<TExport>;
24
+
25
+ export type { AdapterRegistry, AdapterResult, AnyAdapter, AsyncAdapterCreator, AsyncAdapterType, BuildOutput, ExportType, SyncAdapterCreator, SyncAdapterType };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,134 @@
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/core/x.ts
21
+ var x_exports = {};
22
+ __export(x_exports, {
23
+ createX: () => createX
24
+ });
25
+ module.exports = __toCommonJS(x_exports);
26
+
27
+ // src/core/adapters.ts
28
+ var AdapterError = class extends Error {
29
+ constructor(message, adapterName, cause) {
30
+ super(message);
31
+ this.adapterName = adapterName;
32
+ this.cause = cause;
33
+ this.name = "AdapterError";
34
+ }
35
+ };
36
+
37
+ // src/core/x.ts
38
+ var X = class _X {
39
+ constructor(adapterFactories = {}, isAsync = false) {
40
+ this.adapterFactories = adapterFactories;
41
+ this.isAsync = isAsync;
42
+ }
43
+ syncAdapter(name, factory) {
44
+ const newFactories = { ...this.adapterFactories };
45
+ newFactories[name] = [
46
+ factory,
47
+ false
48
+ ];
49
+ return new _X(
50
+ newFactories,
51
+ this.isAsync
52
+ );
53
+ }
54
+ asyncAdapter(name, factory) {
55
+ const wrappedFactory = async (deps) => {
56
+ const result = factory(deps);
57
+ return result instanceof Promise ? await result : result;
58
+ };
59
+ const newFactories = { ...this.adapterFactories };
60
+ newFactories[name] = [
61
+ wrappedFactory,
62
+ true
63
+ ];
64
+ return new _X(
65
+ newFactories,
66
+ true
67
+ );
68
+ }
69
+ use(other) {
70
+ const newFactories = {
71
+ ...this.adapterFactories,
72
+ ...other["adapterFactories"]
73
+ };
74
+ return new _X(newFactories, this.isAsync || other["isAsync"]);
75
+ }
76
+ build() {
77
+ return this.isAsync ? this.buildAsync() : this.buildSync();
78
+ }
79
+ buildSync() {
80
+ const result = {
81
+ _: { adapters: {} }
82
+ };
83
+ for (const [key, [factory, isAsync]] of Object.entries(
84
+ this.adapterFactories
85
+ )) {
86
+ if (isAsync) {
87
+ throw new AdapterError(
88
+ `Cannot use async adapter "${key}" in sync build`,
89
+ key
90
+ );
91
+ }
92
+ const adapter = factory(result);
93
+ if (adapter.__type !== "sync") {
94
+ throw new AdapterError(
95
+ `Factory returned async adapter "${key}" in sync build`,
96
+ key
97
+ );
98
+ }
99
+ result._.adapters[key] = adapter;
100
+ adapter.init?.();
101
+ result[key] = adapter.export();
102
+ }
103
+ return result;
104
+ }
105
+ async buildAsync() {
106
+ const result = {
107
+ _: { adapters: {} }
108
+ };
109
+ for (const [key, [factory, isAsync]] of Object.entries(
110
+ this.adapterFactories
111
+ )) {
112
+ const currentResult = { ...result };
113
+ const adapter = isAsync ? await factory(currentResult) : factory(currentResult);
114
+ result._.adapters[key] = adapter;
115
+ if (adapter.init) {
116
+ if (adapter.__type === "async") {
117
+ await adapter.init();
118
+ } else {
119
+ adapter.init();
120
+ }
121
+ }
122
+ result[key] = adapter.__type === "async" ? await adapter.export() : adapter.export();
123
+ }
124
+ return result;
125
+ }
126
+ };
127
+ function createX() {
128
+ return new X();
129
+ }
130
+ // Annotate the CommonJS export names for ESM import in node:
131
+ 0 && (module.exports = {
132
+ createX
133
+ });
134
+ //# sourceMappingURL=x.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/core/x.ts","../../src/core/adapters.ts"],"sourcesContent":["import { AdapterError } from \"./adapters\";\nimport type {\n SyncAdapterCreator,\n SyncAdapterType,\n AsyncAdapterCreator,\n AsyncAdapterType,\n AdapterRegistry,\n AdapterResult,\n BuildOutput,\n} from \"./types\";\n\ntype AdapterFactory<T extends AdapterRegistry> =\n | [(deps: AdapterResult<T>) => SyncAdapterType<unknown>, false]\n | [(deps: AdapterResult<T>) => Promise<AsyncAdapterType<unknown>>, true];\n\nclass X<\n TAdapters extends AdapterRegistry = Record<string, never>,\n TIsAsync extends boolean = false,\n> {\n constructor(\n private readonly adapterFactories: Record<\n string,\n AdapterFactory<TAdapters>\n > = {} as Record<string, AdapterFactory<TAdapters>>,\n private readonly isAsync: TIsAsync = false as TIsAsync,\n ) {}\n\n syncAdapter<TKey extends string, TExport>(\n name: TKey,\n factory: SyncAdapterCreator<TExport, TAdapters>,\n ): X<TAdapters & Record<TKey, SyncAdapterType<TExport>>, TIsAsync> {\n type NewAdapters = TAdapters & Record<TKey, SyncAdapterType<TExport>>;\n const newFactories = { ...this.adapterFactories };\n // We know this is safe because factory is a SyncAdapterCreator\n (newFactories as Record<string, unknown>)[name] = [\n factory,\n false,\n ] as AdapterFactory<NewAdapters>;\n return new X(\n newFactories as Record<string, AdapterFactory<NewAdapters>>,\n this.isAsync,\n );\n }\n\n asyncAdapter<TKey extends string, TExport>(\n name: TKey,\n factory: AsyncAdapterCreator<TExport, TAdapters>,\n ): X<TAdapters & Record<TKey, AsyncAdapterType<TExport>>, true> {\n type NewAdapters = TAdapters & Record<TKey, AsyncAdapterType<TExport>>;\n const wrappedFactory = async (deps: AdapterResult<TAdapters>) => {\n const result = factory(deps);\n return result instanceof Promise ? await result : result;\n };\n\n const newFactories = { ...this.adapterFactories };\n // We know this is safe because wrappedFactory returns a Promise<AsyncAdapterType>\n (newFactories as Record<string, unknown>)[name] = [\n wrappedFactory,\n true,\n ] as AdapterFactory<NewAdapters>;\n return new X(\n newFactories as Record<string, AdapterFactory<NewAdapters>>,\n true,\n );\n }\n\n use<TOtherAdapters extends AdapterRegistry, TOtherAsync extends boolean>(\n other: X<TOtherAdapters, TOtherAsync>,\n ): X<TAdapters & TOtherAdapters, TIsAsync | TOtherAsync> {\n type CombinedAdapters = TAdapters & TOtherAdapters;\n const newFactories = {\n ...this.adapterFactories,\n ...other[\"adapterFactories\"],\n } as Record<string, AdapterFactory<CombinedAdapters>>;\n return new X(newFactories, this.isAsync || other[\"isAsync\"]);\n }\n\n build(): BuildOutput<TAdapters, TIsAsync> {\n return this.isAsync\n ? (this.buildAsync() as BuildOutput<TAdapters, TIsAsync>)\n : (this.buildSync() as BuildOutput<TAdapters, TIsAsync>);\n }\n\n private buildSync(): AdapterResult<TAdapters> {\n const result = {\n _: { adapters: {} as TAdapters },\n } as AdapterResult<TAdapters>;\n\n for (const [key, [factory, isAsync]] of Object.entries(\n this.adapterFactories,\n )) {\n if (isAsync) {\n throw new AdapterError(\n `Cannot use async adapter \"${key}\" in sync build`,\n key,\n );\n }\n\n const adapter = factory(result) as SyncAdapterType<unknown>;\n\n if (adapter.__type !== \"sync\") {\n throw new AdapterError(\n `Factory returned async adapter \"${key}\" in sync build`,\n key,\n );\n }\n\n (result._.adapters as Record<string, SyncAdapterType<unknown>>)[key] =\n adapter;\n adapter.init?.();\n (result as Record<string, unknown>)[key] = adapter.export();\n }\n\n return result;\n }\n\n private async buildAsync(): Promise<AdapterResult<TAdapters>> {\n const result = {\n _: { adapters: {} as TAdapters },\n } as AdapterResult<TAdapters>;\n\n for (const [key, [factory, isAsync]] of Object.entries(\n this.adapterFactories,\n )) {\n const currentResult = { ...result };\n const adapter = isAsync\n ? await (\n factory as (\n deps: AdapterResult<TAdapters>,\n ) => Promise<AsyncAdapterType<unknown>>\n )(currentResult)\n : (\n factory as (\n deps: AdapterResult<TAdapters>,\n ) => SyncAdapterType<unknown>\n )(currentResult);\n\n (\n result._.adapters as Record<\n string,\n SyncAdapterType<unknown> | AsyncAdapterType<unknown>\n >\n )[key] = adapter;\n\n if (adapter.init) {\n if (adapter.__type === \"async\") {\n await adapter.init();\n } else {\n adapter.init();\n }\n }\n\n (result as Record<string, unknown>)[key] =\n adapter.__type === \"async\" ? await adapter.export() : adapter.export();\n }\n\n return result;\n }\n}\n\nexport function createX() {\n return new X();\n}\n","import type { SyncAdapterType, AsyncAdapterType } from \"./types\";\n\nexport abstract class SyncAdapter<TExport> implements SyncAdapterType<TExport> {\n readonly __type = \"sync\" as const;\n init?(): void;\n abstract export(): TExport;\n}\n\nexport abstract class AsyncAdapter<TExport>\n implements AsyncAdapterType<TExport>\n{\n readonly __type = \"async\" as const;\n init?(): Promise<void>;\n abstract export(): Promise<TExport>;\n}\n\nexport class AdapterError extends Error {\n constructor(\n message: string,\n public readonly adapterName: string,\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"AdapterError\";\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACgBO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,aACA,OAChB;AACA,UAAM,OAAO;AAHG;AACA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ADVA,IAAM,IAAN,MAAM,GAGJ;AAAA,EACA,YACmB,mBAGb,CAAC,GACY,UAAoB,OACrC;AALiB;AAIA;AAAA,EAChB;AAAA,EAEH,YACE,MACA,SACiE;AAEjE,UAAM,eAAe,EAAE,GAAG,KAAK,iBAAiB;AAEhD,IAAC,aAAyC,IAAI,IAAI;AAAA,MAChD;AAAA,MACA;AAAA,IACF;AACA,WAAO,IAAI;AAAA,MACT;AAAA,MACA,KAAK;AAAA,IACP;AAAA,EACF;AAAA,EAEA,aACE,MACA,SAC8D;AAE9D,UAAM,iBAAiB,OAAO,SAAmC;AAC/D,YAAM,SAAS,QAAQ,IAAI;AAC3B,aAAO,kBAAkB,UAAU,MAAM,SAAS;AAAA,IACpD;AAEA,UAAM,eAAe,EAAE,GAAG,KAAK,iBAAiB;AAEhD,IAAC,aAAyC,IAAI,IAAI;AAAA,MAChD;AAAA,MACA;AAAA,IACF;AACA,WAAO,IAAI;AAAA,MACT;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA,EAEA,IACE,OACuD;AAEvD,UAAM,eAAe;AAAA,MACnB,GAAG,KAAK;AAAA,MACR,GAAG,MAAM,kBAAkB;AAAA,IAC7B;AACA,WAAO,IAAI,GAAE,cAAc,KAAK,WAAW,MAAM,SAAS,CAAC;AAAA,EAC7D;AAAA,EAEA,QAA0C;AACxC,WAAO,KAAK,UACP,KAAK,WAAW,IAChB,KAAK,UAAU;AAAA,EACtB;AAAA,EAEQ,YAAsC;AAC5C,UAAM,SAAS;AAAA,MACb,GAAG,EAAE,UAAU,CAAC,EAAe;AAAA,IACjC;AAEA,eAAW,CAAC,KAAK,CAAC,SAAS,OAAO,CAAC,KAAK,OAAO;AAAA,MAC7C,KAAK;AAAA,IACP,GAAG;AACD,UAAI,SAAS;AACX,cAAM,IAAI;AAAA,UACR,6BAA6B,GAAG;AAAA,UAChC;AAAA,QACF;AAAA,MACF;AAEA,YAAM,UAAU,QAAQ,MAAM;AAE9B,UAAI,QAAQ,WAAW,QAAQ;AAC7B,cAAM,IAAI;AAAA,UACR,mCAAmC,GAAG;AAAA,UACtC;AAAA,QACF;AAAA,MACF;AAEA,MAAC,OAAO,EAAE,SAAsD,GAAG,IACjE;AACF,cAAQ,OAAO;AACf,MAAC,OAAmC,GAAG,IAAI,QAAQ,OAAO;AAAA,IAC5D;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,MAAc,aAAgD;AAC5D,UAAM,SAAS;AAAA,MACb,GAAG,EAAE,UAAU,CAAC,EAAe;AAAA,IACjC;AAEA,eAAW,CAAC,KAAK,CAAC,SAAS,OAAO,CAAC,KAAK,OAAO;AAAA,MAC7C,KAAK;AAAA,IACP,GAAG;AACD,YAAM,gBAAgB,EAAE,GAAG,OAAO;AAClC,YAAM,UAAU,UACZ,MACE,QAGA,aAAa,IAEb,QAGA,aAAa;AAEnB,MACE,OAAO,EAAE,SAIT,GAAG,IAAI;AAET,UAAI,QAAQ,MAAM;AAChB,YAAI,QAAQ,WAAW,SAAS;AAC9B,gBAAM,QAAQ,KAAK;AAAA,QACrB,OAAO;AACL,kBAAQ,KAAK;AAAA,QACf;AAAA,MACF;AAEA,MAAC,OAAmC,GAAG,IACrC,QAAQ,WAAW,UAAU,MAAM,QAAQ,OAAO,IAAI,QAAQ,OAAO;AAAA,IACzE;AAEA,WAAO;AAAA,EACT;AACF;AAEO,SAAS,UAAU;AACxB,SAAO,IAAI,EAAE;AACf;","names":[]}
@@ -0,0 +1,17 @@
1
+ import { AdapterRegistry, SyncAdapterCreator, SyncAdapterType, AsyncAdapterCreator, AsyncAdapterType, BuildOutput, AdapterResult } from './types.cjs';
2
+
3
+ type AdapterFactory<T extends AdapterRegistry> = [(deps: AdapterResult<T>) => SyncAdapterType<unknown>, false] | [(deps: AdapterResult<T>) => Promise<AsyncAdapterType<unknown>>, true];
4
+ declare class X<TAdapters extends AdapterRegistry = Record<string, never>, TIsAsync extends boolean = false> {
5
+ private readonly adapterFactories;
6
+ private readonly isAsync;
7
+ constructor(adapterFactories?: Record<string, AdapterFactory<TAdapters>>, isAsync?: TIsAsync);
8
+ syncAdapter<TKey extends string, TExport>(name: TKey, factory: SyncAdapterCreator<TExport, TAdapters>): X<TAdapters & Record<TKey, SyncAdapterType<TExport>>, TIsAsync>;
9
+ asyncAdapter<TKey extends string, TExport>(name: TKey, factory: AsyncAdapterCreator<TExport, TAdapters>): X<TAdapters & Record<TKey, AsyncAdapterType<TExport>>, true>;
10
+ use<TOtherAdapters extends AdapterRegistry, TOtherAsync extends boolean>(other: X<TOtherAdapters, TOtherAsync>): X<TAdapters & TOtherAdapters, TIsAsync | TOtherAsync>;
11
+ build(): BuildOutput<TAdapters, TIsAsync>;
12
+ private buildSync;
13
+ private buildAsync;
14
+ }
15
+ declare function createX(): X<Record<string, never>, false>;
16
+
17
+ export { createX };
@@ -0,0 +1,17 @@
1
+ import { AdapterRegistry, SyncAdapterCreator, SyncAdapterType, AsyncAdapterCreator, AsyncAdapterType, BuildOutput, AdapterResult } from './types.js';
2
+
3
+ type AdapterFactory<T extends AdapterRegistry> = [(deps: AdapterResult<T>) => SyncAdapterType<unknown>, false] | [(deps: AdapterResult<T>) => Promise<AsyncAdapterType<unknown>>, true];
4
+ declare class X<TAdapters extends AdapterRegistry = Record<string, never>, TIsAsync extends boolean = false> {
5
+ private readonly adapterFactories;
6
+ private readonly isAsync;
7
+ constructor(adapterFactories?: Record<string, AdapterFactory<TAdapters>>, isAsync?: TIsAsync);
8
+ syncAdapter<TKey extends string, TExport>(name: TKey, factory: SyncAdapterCreator<TExport, TAdapters>): X<TAdapters & Record<TKey, SyncAdapterType<TExport>>, TIsAsync>;
9
+ asyncAdapter<TKey extends string, TExport>(name: TKey, factory: AsyncAdapterCreator<TExport, TAdapters>): X<TAdapters & Record<TKey, AsyncAdapterType<TExport>>, true>;
10
+ use<TOtherAdapters extends AdapterRegistry, TOtherAsync extends boolean>(other: X<TOtherAdapters, TOtherAsync>): X<TAdapters & TOtherAdapters, TIsAsync | TOtherAsync>;
11
+ build(): BuildOutput<TAdapters, TIsAsync>;
12
+ private buildSync;
13
+ private buildAsync;
14
+ }
15
+ declare function createX(): X<Record<string, never>, false>;
16
+
17
+ export { createX };
package/dist/core/x.js ADDED
@@ -0,0 +1,107 @@
1
+ // src/core/adapters.ts
2
+ var AdapterError = class extends Error {
3
+ constructor(message, adapterName, cause) {
4
+ super(message);
5
+ this.adapterName = adapterName;
6
+ this.cause = cause;
7
+ this.name = "AdapterError";
8
+ }
9
+ };
10
+
11
+ // src/core/x.ts
12
+ var X = class _X {
13
+ constructor(adapterFactories = {}, isAsync = false) {
14
+ this.adapterFactories = adapterFactories;
15
+ this.isAsync = isAsync;
16
+ }
17
+ syncAdapter(name, factory) {
18
+ const newFactories = { ...this.adapterFactories };
19
+ newFactories[name] = [
20
+ factory,
21
+ false
22
+ ];
23
+ return new _X(
24
+ newFactories,
25
+ this.isAsync
26
+ );
27
+ }
28
+ asyncAdapter(name, factory) {
29
+ const wrappedFactory = async (deps) => {
30
+ const result = factory(deps);
31
+ return result instanceof Promise ? await result : result;
32
+ };
33
+ const newFactories = { ...this.adapterFactories };
34
+ newFactories[name] = [
35
+ wrappedFactory,
36
+ true
37
+ ];
38
+ return new _X(
39
+ newFactories,
40
+ true
41
+ );
42
+ }
43
+ use(other) {
44
+ const newFactories = {
45
+ ...this.adapterFactories,
46
+ ...other["adapterFactories"]
47
+ };
48
+ return new _X(newFactories, this.isAsync || other["isAsync"]);
49
+ }
50
+ build() {
51
+ return this.isAsync ? this.buildAsync() : this.buildSync();
52
+ }
53
+ buildSync() {
54
+ const result = {
55
+ _: { adapters: {} }
56
+ };
57
+ for (const [key, [factory, isAsync]] of Object.entries(
58
+ this.adapterFactories
59
+ )) {
60
+ if (isAsync) {
61
+ throw new AdapterError(
62
+ `Cannot use async adapter "${key}" in sync build`,
63
+ key
64
+ );
65
+ }
66
+ const adapter = factory(result);
67
+ if (adapter.__type !== "sync") {
68
+ throw new AdapterError(
69
+ `Factory returned async adapter "${key}" in sync build`,
70
+ key
71
+ );
72
+ }
73
+ result._.adapters[key] = adapter;
74
+ adapter.init?.();
75
+ result[key] = adapter.export();
76
+ }
77
+ return result;
78
+ }
79
+ async buildAsync() {
80
+ const result = {
81
+ _: { adapters: {} }
82
+ };
83
+ for (const [key, [factory, isAsync]] of Object.entries(
84
+ this.adapterFactories
85
+ )) {
86
+ const currentResult = { ...result };
87
+ const adapter = isAsync ? await factory(currentResult) : factory(currentResult);
88
+ result._.adapters[key] = adapter;
89
+ if (adapter.init) {
90
+ if (adapter.__type === "async") {
91
+ await adapter.init();
92
+ } else {
93
+ adapter.init();
94
+ }
95
+ }
96
+ result[key] = adapter.__type === "async" ? await adapter.export() : adapter.export();
97
+ }
98
+ return result;
99
+ }
100
+ };
101
+ function createX() {
102
+ return new X();
103
+ }
104
+ export {
105
+ createX
106
+ };
107
+ //# sourceMappingURL=x.js.map