@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.
- package/.turbo/turbo-build.log +46 -0
- package/CHANGELOG.md +7 -0
- package/dist/adapter.cjs +50 -0
- package/dist/adapter.cjs.map +1 -0
- package/dist/adapter.d.cts +2 -0
- package/dist/adapter.d.ts +2 -0
- package/dist/adapter.js +21 -0
- package/dist/adapter.js.map +1 -0
- package/dist/core/adapters.cjs +48 -0
- package/dist/core/adapters.cjs.map +1 -0
- package/dist/core/adapters.d.cts +19 -0
- package/dist/core/adapters.d.ts +19 -0
- package/dist/core/adapters.js +21 -0
- package/dist/core/adapters.js.map +1 -0
- package/dist/core/types.cjs +19 -0
- package/dist/core/types.cjs.map +1 -0
- package/dist/core/types.d.cts +25 -0
- package/dist/core/types.d.ts +25 -0
- package/dist/core/types.js +1 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/x.cjs +134 -0
- package/dist/core/x.cjs.map +1 -0
- package/dist/core/x.d.cts +17 -0
- package/dist/core/x.d.ts +17 -0
- package/dist/core/x.js +107 -0
- package/dist/core/x.js.map +1 -0
- package/dist/index.cjs +134 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
- package/src/__tests__/async-adapter.test.ts +87 -0
- package/src/__tests__/composition.test.ts +45 -0
- package/src/__tests__/core.test.ts +23 -0
- package/src/__tests__/error-handling.test.ts +71 -0
- package/src/__tests__/sync-adapter.test.ts +83 -0
- package/src/__tests__/type-system.test.ts +78 -0
- package/src/adapter.ts +1 -0
- package/src/core/adapters.ts +26 -0
- package/src/core/types.ts +47 -0
- package/src/core/x.ts +163 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +9 -0
- 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
|
+
[34mCLI[39m Building entry: src/adapter.ts, src/index.ts, src/core/adapters.ts, src/core/types.ts, src/core/x.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/x/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/adapter.cjs [22m[32m1.49 KB[39m
|
14
|
+
[32mCJS[39m [1mdist/core/adapters.cjs [22m[32m1.48 KB[39m
|
15
|
+
[32mCJS[39m [1mdist/core/types.cjs [22m[32m797.00 B[39m
|
16
|
+
[32mCJS[39m [1mdist/core/x.cjs [22m[32m3.55 KB[39m
|
17
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m3.57 KB[39m
|
18
|
+
[32mCJS[39m [1mdist/adapter.cjs.map [22m[32m1.11 KB[39m
|
19
|
+
[32mCJS[39m [1mdist/core/adapters.cjs.map [22m[32m1.01 KB[39m
|
20
|
+
[32mCJS[39m [1mdist/core/types.cjs.map [22m[32m1.48 KB[39m
|
21
|
+
[32mCJS[39m [1mdist/core/x.cjs.map [22m[32m7.67 KB[39m
|
22
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m7.72 KB[39m
|
23
|
+
[32mCJS[39m ⚡️ Build success in 17ms
|
24
|
+
[32mESM[39m [1mdist/adapter.js [22m[32m420.00 B[39m
|
25
|
+
[32mESM[39m [1mdist/index.js [22m[32m2.57 KB[39m
|
26
|
+
[32mESM[39m [1mdist/core/types.js [22m[32m33.00 B[39m
|
27
|
+
[32mESM[39m [1mdist/core/adapters.js [22m[32m421.00 B[39m
|
28
|
+
[32mESM[39m [1mdist/core/x.js [22m[32m2.56 KB[39m
|
29
|
+
[32mESM[39m [1mdist/adapter.js.map [22m[32m978.00 B[39m
|
30
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m7.62 KB[39m
|
31
|
+
[32mESM[39m [1mdist/core/types.js.map [22m[32m71.00 B[39m
|
32
|
+
[32mESM[39m [1mdist/core/adapters.js.map [22m[32m981.00 B[39m
|
33
|
+
[32mESM[39m [1mdist/core/x.js.map [22m[32m7.63 KB[39m
|
34
|
+
[32mESM[39m ⚡️ Build success in 18ms
|
35
|
+
[34mDTS[39m Build start
|
36
|
+
[32mDTS[39m ⚡️ Build success in 2038ms
|
37
|
+
[32mDTS[39m [1mdist/core/types.d.cts [22m[32m1.24 KB[39m
|
38
|
+
[32mDTS[39m [1mdist/core/adapters.d.cts [22m[32m673.00 B[39m
|
39
|
+
[32mDTS[39m [1mdist/core/x.d.cts [22m[32m1.28 KB[39m
|
40
|
+
[32mDTS[39m [1mdist/adapter.d.cts [22m[32m106.00 B[39m
|
41
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m67.00 B[39m
|
42
|
+
[32mDTS[39m [1mdist/core/types.d.ts [22m[32m1.24 KB[39m
|
43
|
+
[32mDTS[39m [1mdist/core/adapters.d.ts [22m[32m672.00 B[39m
|
44
|
+
[32mDTS[39m [1mdist/core/x.d.ts [22m[32m1.28 KB[39m
|
45
|
+
[32mDTS[39m [1mdist/adapter.d.ts [22m[32m104.00 B[39m
|
46
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m65.00 B[39m
|
package/CHANGELOG.md
ADDED
package/dist/adapter.cjs
ADDED
@@ -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":[]}
|
package/dist/adapter.js
ADDED
@@ -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":[]}
|
package/dist/core/x.cjs
ADDED
@@ -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 };
|
package/dist/core/x.d.ts
ADDED
@@ -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
|