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