@raubjo/architect-core 0.1.0 → 0.1.1
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/README.md +162 -0
- package/bun.lock +82 -1
- package/package.json +54 -6
- package/src/cache/cache.ts +2 -2
- package/src/cache/manager.ts +93 -83
- package/src/config/adapters/esm.ts +26 -0
- package/src/config/clone.ts +5 -5
- package/src/config/env.global.d.ts +2 -1
- package/src/config/env.ts +53 -55
- package/src/config/env_test.helpers.ts +58 -0
- package/src/config/repository.ts +180 -142
- package/src/container/adapters/builtin.ts +347 -0
- package/src/container/adapters/inversify.ts +123 -0
- package/src/container/contract.ts +58 -0
- package/src/container/runtime.ts +149 -0
- package/src/filesystem/adapters/local.ts +92 -83
- package/src/filesystem/adapters/local_test.helpers.ts +50 -0
- package/src/filesystem/filesystem.ts +11 -11
- package/src/foundation/application.ts +205 -175
- package/src/foundation/application_test.helpers.ts +31 -0
- package/src/index.ts +15 -6
- package/src/react.ts +2 -0
- package/src/renderers/adapters/react.tsx +35 -0
- package/src/renderers/adapters/solid.tsx +32 -0
- package/src/renderers/adapters/svelte.ts +44 -0
- package/src/renderers/adapters/vue.ts +28 -0
- package/src/renderers/contract.ts +15 -0
- package/src/runtimes/react.tsx +24 -12
- package/src/runtimes/solid.tsx +30 -0
- package/src/runtimes/svelte.ts +23 -0
- package/src/runtimes/vue.ts +20 -0
- package/src/solid.ts +2 -0
- package/src/storage/adapters/contract.ts +10 -0
- package/src/storage/adapters/indexed-db.ts +170 -156
- package/src/storage/adapters/local-storage.ts +34 -34
- package/src/storage/adapters/memory.ts +25 -25
- package/src/storage/manager.ts +65 -61
- package/src/storage/storage.ts +1 -8
- package/src/support/facades/cache.ts +40 -40
- package/src/support/facades/config.ts +78 -48
- package/src/support/facades/facade.ts +43 -28
- package/src/support/facades/storage.ts +41 -41
- package/src/support/service-provider.ts +11 -11
- package/src/support/str.ts +94 -90
- package/src/support/str_test.helpers.ts +26 -0
- package/src/svelte.ts +2 -0
- package/src/vue.ts +2 -0
- package/tsconfig.json +16 -0
- package/coverage/lcov.info +0 -1078
- package/src/config/app.ts +0 -5
- package/src/rendering/adapters/react.tsx +0 -27
- package/src/rendering/renderer.ts +0 -13
- package/src/support/providers/config-service-provider.ts +0 -19
- package/tests/application.test.ts +0 -236
- package/tests/cache-facade.test.ts +0 -45
- package/tests/cache.test.ts +0 -68
- package/tests/config-clone.test.ts +0 -31
- package/tests/config-env.test.ts +0 -88
- package/tests/config-facade.test.ts +0 -96
- package/tests/config-repository.test.ts +0 -124
- package/tests/facade-base.test.ts +0 -80
- package/tests/filesystem.test.ts +0 -81
- package/tests/runtime-react.test.tsx +0 -37
- package/tests/service-provider.test.ts +0 -23
- package/tests/storage-facade.test.ts +0 -46
- package/tests/storage.test.ts +0 -264
- package/tests/str.test.ts +0 -73
|
@@ -1,104 +1,113 @@
|
|
|
1
|
-
import type { ConfigItems } from "
|
|
2
|
-
import type { FileSystemAdapter } from "
|
|
1
|
+
import type { ConfigItems } from "@/config/repository";
|
|
2
|
+
import type { FileSystemAdapter } from "@/filesystem/filesystem";
|
|
3
3
|
|
|
4
4
|
type ConfigModule = { default?: unknown };
|
|
5
5
|
type GlobLoader = (
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
pattern: string | string[],
|
|
7
|
+
options?: { eager?: boolean },
|
|
8
8
|
) => Record<string, unknown>;
|
|
9
9
|
|
|
10
10
|
function fileNameWithoutExtension(path: string): string {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const file = path.split("/").pop() ?? path;
|
|
12
|
+
return file.replace(/\.[^/.]+$/, "");
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function normalizeBasePath(basePath: string): string {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const trimmed = basePath.trim();
|
|
17
|
+
if (!trimmed || trimmed === "." || trimmed === "./" || trimmed === "/") {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
let normalized = trimmed.replace(/\\/g, "/");
|
|
22
|
+
normalized = normalized.replace(/^\.\//, "");
|
|
23
|
+
normalized = normalized.replace(/^\/+/, "");
|
|
24
|
+
normalized = normalized.replace(/\/+$/, "");
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
return normalized;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
function isPathInConfigDirectories(path: string, basePath: string): boolean {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
30
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
31
|
+
const trimmedPath = normalizedPath.replace(/^\/+/, "").replace(/^\.\//, "");
|
|
32
|
+
const normalizedBasePath = normalizeBasePath(basePath);
|
|
33
|
+
|
|
34
|
+
const targets =
|
|
35
|
+
normalizedBasePath ?
|
|
36
|
+
[
|
|
37
|
+
`${normalizedBasePath}/config/`,
|
|
38
|
+
`${normalizedBasePath}/src/config/`,
|
|
39
|
+
]
|
|
40
|
+
: ["config/", "src/config/"];
|
|
41
|
+
|
|
42
|
+
for (const target of targets) {
|
|
43
|
+
if (
|
|
44
|
+
trimmedPath.startsWith(target) ||
|
|
45
|
+
normalizedPath.includes(`/${target}`) ||
|
|
46
|
+
normalizedPath.endsWith(`/${target.slice(0, -1)}`)
|
|
47
|
+
) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
|
-
}
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
return false;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
export default class LocalAdapter implements FileSystemAdapter {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
56
|
+
constructor() {}
|
|
57
|
+
|
|
58
|
+
loadConfigItems(basePath: string): ConfigItems {
|
|
59
|
+
const runtimeModules = (
|
|
60
|
+
globalThis as {
|
|
61
|
+
__iocConfigModules?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
).__iocConfigModules;
|
|
64
|
+
const viteGlob = (
|
|
65
|
+
import.meta as ImportMeta & {
|
|
66
|
+
glob?: GlobLoader;
|
|
67
|
+
}
|
|
68
|
+
).glob;
|
|
69
|
+
const runtimeGlob = (
|
|
70
|
+
globalThis as {
|
|
71
|
+
__iocConfigGlob?: GlobLoader;
|
|
72
|
+
}
|
|
73
|
+
).__iocConfigGlob;
|
|
74
|
+
const testGlob = (
|
|
75
|
+
globalThis as {
|
|
76
|
+
__iocConfigGlobForTests?: GlobLoader;
|
|
77
|
+
}
|
|
78
|
+
).__iocConfigGlobForTests;
|
|
79
|
+
const glob =
|
|
80
|
+
typeof viteGlob === "function" ? viteGlob
|
|
81
|
+
: typeof runtimeGlob === "function" ? runtimeGlob
|
|
82
|
+
: typeof testGlob === "function" ? testGlob
|
|
83
|
+
: null;
|
|
84
|
+
if (!runtimeModules && !glob) {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const modules =
|
|
89
|
+
runtimeModules ??
|
|
90
|
+
(glob(
|
|
91
|
+
[
|
|
92
|
+
"/config/*.{js,mjs,cjs,ts,mts,cts}",
|
|
93
|
+
"/src/config/*.{js,mjs,cjs,ts,mts,cts}",
|
|
94
|
+
],
|
|
95
|
+
{ eager: true },
|
|
96
|
+
) as Record<string, unknown>);
|
|
97
|
+
|
|
98
|
+
const discovered: ConfigItems = {};
|
|
99
|
+
for (const [path, loaded] of Object.entries(modules)) {
|
|
100
|
+
if (!isPathInConfigDirectories(path, basePath)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const key = fileNameWithoutExtension(path);
|
|
105
|
+
const module = loaded as ConfigModule;
|
|
106
|
+
if (module && "default" in module && module.default !== undefined) {
|
|
107
|
+
discovered[key] = module.default;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return discovered;
|
|
94
112
|
}
|
|
95
|
-
|
|
96
|
-
return discovered;
|
|
97
|
-
}
|
|
98
113
|
}
|
|
99
|
-
|
|
100
|
-
export const __localAdapterTesting = {
|
|
101
|
-
fileNameWithoutExtension,
|
|
102
|
-
normalizeBasePath,
|
|
103
|
-
isPathInConfigDirectories,
|
|
104
|
-
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
function fileNameWithoutExtension(path: string): string {
|
|
2
|
+
const file = path.split("/").pop() ?? path;
|
|
3
|
+
return file.replace(/\.[^/.]+$/, "");
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
function normalizeBasePath(basePath: string): string {
|
|
7
|
+
const trimmed = basePath.trim();
|
|
8
|
+
if (!trimmed || trimmed === "." || trimmed === "./" || trimmed === "/") {
|
|
9
|
+
return "";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let normalized = trimmed.replace(/\\/g, "/");
|
|
13
|
+
normalized = normalized.replace(/^\.\//, "");
|
|
14
|
+
normalized = normalized.replace(/^\/+/, "");
|
|
15
|
+
normalized = normalized.replace(/\/+$/, "");
|
|
16
|
+
|
|
17
|
+
return normalized;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isPathInConfigDirectories(path: string, basePath: string): boolean {
|
|
21
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
22
|
+
const trimmedPath = normalizedPath.replace(/^\/+/, "").replace(/^\.\//, "");
|
|
23
|
+
const normalizedBasePath = normalizeBasePath(basePath);
|
|
24
|
+
|
|
25
|
+
const targets =
|
|
26
|
+
normalizedBasePath ?
|
|
27
|
+
[
|
|
28
|
+
`${normalizedBasePath}/config/`,
|
|
29
|
+
`${normalizedBasePath}/src/config/`,
|
|
30
|
+
]
|
|
31
|
+
: ["config/", "src/config/"];
|
|
32
|
+
|
|
33
|
+
for (const target of targets) {
|
|
34
|
+
if (
|
|
35
|
+
trimmedPath.startsWith(target) ||
|
|
36
|
+
normalizedPath.includes(`/${target}`) ||
|
|
37
|
+
normalizedPath.endsWith(`/${target.slice(0, -1)}`)
|
|
38
|
+
) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const localAdapterTestingHelpers = {
|
|
47
|
+
fileNameWithoutExtension,
|
|
48
|
+
normalizeBasePath,
|
|
49
|
+
isPathInConfigDirectories,
|
|
50
|
+
};
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import type { ConfigItems } from "../config/repository";
|
|
2
2
|
|
|
3
3
|
export interface FileSystemAdapter {
|
|
4
|
-
|
|
4
|
+
loadConfigItems(basePath: string): ConfigItems;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export class FileSystem {
|
|
8
|
-
|
|
8
|
+
protected adapter: FileSystemAdapter;
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
constructor(adapter: FileSystemAdapter) {
|
|
11
|
+
this.adapter = adapter;
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
setAdapter(adapter: FileSystemAdapter): void {
|
|
15
|
+
this.adapter = adapter;
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
loadConfigItems(basePath: string): ConfigItems {
|
|
19
|
+
return this.adapter.loadConfigItems(basePath);
|
|
20
|
+
}
|
|
21
21
|
}
|