@hamak/microkernel-impl 0.1.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.
@@ -0,0 +1 @@
1
+ $ tsc -p tsconfig.lib.json
@@ -0,0 +1,6 @@
1
+ export * from './runtime/di';
2
+ export * from './runtime/registries';
3
+ export * from './runtime/loader';
4
+ export * from './runtime/host';
5
+ export * from './ui/adapter';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './runtime/di';
2
+ export * from './runtime/registries';
3
+ export * from './runtime/loader';
4
+ export * from './runtime/host';
5
+ export * from './ui/adapter';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { Provider, Token } from '@amk/microkernel-api';
2
+ export declare function Injectable(deps?: Token[]): ClassDecorator;
3
+ export declare class Container {
4
+ private parent?;
5
+ private providers;
6
+ private instances;
7
+ constructor(parent?: Container);
8
+ createChild(): Container;
9
+ provide<T>(prov: Provider<T>): this;
10
+ resolve<T>(token: Token<T>): T;
11
+ }
12
+ //# sourceMappingURL=di.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"di.d.ts","sourceRoot":"","sources":["../../src/runtime/di.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE5D,wBAAgB,UAAU,CAAC,IAAI,GAAE,KAAK,EAAO,GAAG,cAAc,CAA2D;AACzH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAC,CAAY;IAAC,OAAO,CAAC,SAAS,CAA8B;IAAC,OAAO,CAAC,SAAS,CAAyB;gBAC1G,MAAM,CAAC,EAAE,SAAS;IAC9B,WAAW,IAAI,SAAS;IACxB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI;IACnC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;CAY/B"}
@@ -0,0 +1,38 @@
1
+ const INJECT_KEY = Symbol('di:inject');
2
+ export function Injectable(deps = []) { return (t) => { t[INJECT_KEY] = deps; }; }
3
+ export class Container {
4
+ constructor(parent) {
5
+ this.providers = new Map();
6
+ this.instances = new Map();
7
+ this.parent = parent;
8
+ }
9
+ createChild() { return new Container(this); }
10
+ provide(prov) { this.providers.set(prov.provide, prov); return this; }
11
+ resolve(token) {
12
+ if (this.instances.has(token))
13
+ return this.instances.get(token);
14
+ if (this.providers.has(token)) {
15
+ const prov = this.providers.get(token);
16
+ let value;
17
+ if ('useValue' in prov)
18
+ value = prov.useValue;
19
+ else if ('useClass' in prov) {
20
+ const C = prov.useClass;
21
+ const deps = C[INJECT_KEY] || [];
22
+ const args = deps.map((d) => this.resolve(d));
23
+ value = new C(...args);
24
+ }
25
+ else {
26
+ const deps = prov.deps || [];
27
+ const args = deps.map((d) => this.resolve(d));
28
+ value = prov.useFactory(...args);
29
+ }
30
+ this.instances.set(token, value);
31
+ return value;
32
+ }
33
+ if (this.parent)
34
+ return this.parent.resolve(token);
35
+ throw new Error(`No provider for token: ${token.toString?.() ?? String(token)}`);
36
+ }
37
+ }
38
+ //# sourceMappingURL=di.js.map
@@ -0,0 +1 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IAAI,EAAE,CAAC;gBAAC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAC,EAAE,CAAA,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBAAC,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;YAAC,CAAC;iBAC7K,CAAC;gBAAC,MAAM,IAAI,GAAY,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;gBAAC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAC,EAAE,CAAA,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;YAAC,CAAC;YAC9H,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAAC,OAAO,KAAK,CAAC;QACjD,CAAC;QACD,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,0BAA0B,KAAK,CAAC,QAAQ,EAAE,EAAE,IAAI,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACnF,CAAC;CACF"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Dependency graph utilities for topological sorting
3
+ */
4
+ export interface DependencyNode {
5
+ name: string;
6
+ dependsOn?: string[];
7
+ }
8
+ /**
9
+ * Performs topological sort on items based on their dependencies
10
+ * @param items Items to sort (must have name and optional dependsOn properties)
11
+ * @returns Sorted items in dependency order
12
+ * @throws Error if circular dependency is detected
13
+ */
14
+ export declare function topologicalSort<T extends DependencyNode>(items: T[]): T[];
15
+ //# sourceMappingURL=graph-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-utils.d.ts","sourceRoot":"","sources":["../../src/runtime/graph-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,cAAc,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAkCzE"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Dependency graph utilities for topological sorting
3
+ */
4
+ /**
5
+ * Performs topological sort on items based on their dependencies
6
+ * @param items Items to sort (must have name and optional dependsOn properties)
7
+ * @returns Sorted items in dependency order
8
+ * @throws Error if circular dependency is detected
9
+ */
10
+ export function topologicalSort(items) {
11
+ const index = new Map(items.map(i => [i.name, i]));
12
+ const visited = new Set();
13
+ const result = [];
14
+ const visit = (item, path = new Set()) => {
15
+ if (visited.has(item.name))
16
+ return;
17
+ // Cycle detection
18
+ if (path.has(item.name)) {
19
+ throw new Error(`Circular dependency detected: ${[...path, item.name].join(' -> ')}`);
20
+ }
21
+ path.add(item.name);
22
+ (item.dependsOn ?? []).forEach(depName => {
23
+ const dep = index.get(depName);
24
+ if (!dep) {
25
+ console.warn(`Dependency not found: ${depName} (required by ${item.name})`);
26
+ return;
27
+ }
28
+ visit(dep, new Set(path));
29
+ });
30
+ visited.add(item.name);
31
+ result.push(item);
32
+ };
33
+ items.forEach(item => visit(item));
34
+ return result;
35
+ }
36
+ //# sourceMappingURL=graph-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-utils.js","sourceRoot":"","sources":["../../src/runtime/graph-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAA2B,KAAU;IAClE,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAA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, IChildHost, IHost, PluginManifest, Provider } from '@amk/microkernel-api';
2
+ import { Container } from './di';
3
+ import type { PluginModule } from '@amk/microkernel-spi';
4
+ export declare class Host implements IHost {
5
+ readonly root: Container;
6
+ private readonly _registry;
7
+ private env?;
8
+ rootActivationCtx?: ActivateContext;
9
+ constructor(initialProviders?: Provider[], env?: Record<string, any>);
10
+ loadPlugins(manifests: Array<string | PluginManifest>): Promise<void>;
11
+ /**
12
+ * Register a plugin programmatically (useful for testing/inline plugins)
13
+ * @param name Plugin name
14
+ * @param manifest Plugin manifest
15
+ * @param module Plugin module implementation
16
+ */
17
+ registerPlugin(name: string, manifest: PluginManifest, module: PluginModule): void;
18
+ /**
19
+ * Get plugin manifest by name
20
+ * @param name Plugin name
21
+ * @returns Plugin manifest or undefined if not found
22
+ */
23
+ getPlugin(name: string): PluginManifest | undefined;
24
+ /**
25
+ * List all loaded plugins
26
+ * @returns Array of plugin manifests
27
+ */
28
+ listPlugins(): PluginManifest[];
29
+ bootstrapAllAtRoot(): Promise<void>;
30
+ createChildHost(overrides?: Provider[], env?: Record<string, any>): IChildHost;
31
+ }
32
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/runtime/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAwC,MAAM,sBAAsB,CAAC;AAC/I,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAGjC,OAAO,KAAK,EAAyB,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAoDhF,qBAAa,IAAK,YAAW,KAAK;IAChC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAsB;IAClC,iBAAiB,CAAC,EAAE,eAAe,CAAC;gBAExB,gBAAgB,GAAE,QAAQ,EAAO,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOlE,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,MAAM,GAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzE;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI;IAIlF;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAInD;;;OAGG;IACH,WAAW,IAAI,cAAc,EAAE;IAIzB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;IAkCzC,eAAe,CAAC,SAAS,GAAE,QAAQ,EAAO,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,UAAU;CAMnF"}
@@ -0,0 +1,146 @@
1
+ import { Container } from './di';
2
+ import { createCommandRegistry, createHooks, createViewRegistry } from './registries';
3
+ import { PluginRegistry } from './loader';
4
+ function createSharedRegistries() {
5
+ return {
6
+ commands: createCommandRegistry(),
7
+ views: createViewRegistry(),
8
+ hooks: createHooks(),
9
+ };
10
+ }
11
+ function createInitContext(container, registries, env) {
12
+ return {
13
+ provide: (prov) => container.provide(prov),
14
+ resolve: (t) => container.resolve(t),
15
+ commands: {
16
+ register: (id, h) => registries.commands.register(id, h)
17
+ },
18
+ views: {
19
+ register: (slot, vf) => registries.views.register(slot, vf)
20
+ },
21
+ hooks: {
22
+ on: (ev, fn) => registries.hooks.on(ev, fn),
23
+ emit: (ev, ...a) => registries.hooks.emit(ev, ...a)
24
+ },
25
+ env,
26
+ };
27
+ }
28
+ function createActivateContext(container, registries, env) {
29
+ return {
30
+ resolve: (t) => container.resolve(t),
31
+ commands: registries.commands,
32
+ views: registries.views,
33
+ hooks: registries.hooks,
34
+ env,
35
+ };
36
+ }
37
+ export class Host {
38
+ constructor(initialProviders = [], env) {
39
+ this.root = new Container();
40
+ initialProviders.forEach(p => this.root.provide(p));
41
+ this._registry = new PluginRegistry();
42
+ this.env = env;
43
+ }
44
+ async loadPlugins(manifests) {
45
+ await this._registry.loadAllAtRoot(manifests);
46
+ }
47
+ /**
48
+ * Register a plugin programmatically (useful for testing/inline plugins)
49
+ * @param name Plugin name
50
+ * @param manifest Plugin manifest
51
+ * @param module Plugin module implementation
52
+ */
53
+ registerPlugin(name, manifest, module) {
54
+ this._registry.register(name, manifest, module);
55
+ }
56
+ /**
57
+ * Get plugin manifest by name
58
+ * @param name Plugin name
59
+ * @returns Plugin manifest or undefined if not found
60
+ */
61
+ getPlugin(name) {
62
+ return this._registry.get(name)?.manifest;
63
+ }
64
+ /**
65
+ * List all loaded plugins
66
+ * @returns Array of plugin manifests
67
+ */
68
+ listPlugins() {
69
+ return this._registry.list();
70
+ }
71
+ async bootstrapAllAtRoot() {
72
+ const registries = createSharedRegistries();
73
+ const initCtx = createInitContext(this.root, registries, this.env);
74
+ const mods = this._registry.getModulesInOrder('all');
75
+ // Initialize phase with error handling
76
+ for (const m of mods) {
77
+ try {
78
+ await m.initialize?.(initCtx);
79
+ }
80
+ catch (error) {
81
+ const err = error instanceof Error ? error : new Error(String(error));
82
+ const initError = new Error(`Plugin initialization failed: ${err.message}`);
83
+ initError.cause = error;
84
+ throw initError;
85
+ }
86
+ }
87
+ const actCtx = createActivateContext(this.root, registries, this.env);
88
+ this.rootActivationCtx = actCtx;
89
+ // Activation phase with error handling
90
+ for (const m of mods) {
91
+ try {
92
+ await m.activate?.(actCtx);
93
+ }
94
+ catch (error) {
95
+ const err = error instanceof Error ? error : new Error(String(error));
96
+ console.error(`Plugin activation failed:`, err);
97
+ // Continue with other plugins rather than failing completely
98
+ }
99
+ }
100
+ actCtx.hooks.emit('host:activated');
101
+ }
102
+ createChildHost(overrides = [], env) {
103
+ const child = this.root.createChild();
104
+ overrides.forEach(p => child.provide(p));
105
+ const childEnv = { ...(this.env || {}), ...(env || {}) };
106
+ return new ChildHost(child, this._registry, childEnv);
107
+ }
108
+ }
109
+ class ChildHost {
110
+ constructor(container, registry, env) {
111
+ this.container = container;
112
+ this.registry = registry;
113
+ this.env = env;
114
+ }
115
+ async bootstrap(pluginNames = 'all') {
116
+ const registries = createSharedRegistries();
117
+ const initCtx = createInitContext(this.container, registries, this.env);
118
+ const mods = this.registry.getModulesInOrder(pluginNames);
119
+ // Initialize phase with error handling
120
+ for (const m of mods) {
121
+ try {
122
+ await m.initialize?.(initCtx);
123
+ }
124
+ catch (error) {
125
+ const err = error instanceof Error ? error : new Error(String(error));
126
+ const initError = new Error(`Plugin initialization failed: ${err.message}`);
127
+ initError.cause = error;
128
+ throw initError;
129
+ }
130
+ }
131
+ const actCtx = createActivateContext(this.container, registries, this.env);
132
+ // Activation phase with error handling
133
+ for (const m of mods) {
134
+ try {
135
+ await m.activate?.(actCtx);
136
+ }
137
+ catch (error) {
138
+ const err = error instanceof Error ? error : new Error(String(error));
139
+ console.error(`Plugin activation failed:`, err);
140
+ // Continue with other plugins rather than failing completely
141
+ }
142
+ }
143
+ actCtx.hooks.emit('child:activated');
144
+ }
145
+ }
146
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/runtime/host.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAS1C,SAAS,sBAAsB;IAC7B,OAAO;QACL,QAAQ,EAAE,qBAAqB,EAAE;QACjC,KAAK,EAAE,kBAAkB,EAAE;QAC3B,KAAK,EAAE,WAAW,EAAE;KACrB,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CACxB,SAAoB,EACpB,UAA4B,EAC5B,GAAy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AI,CAAC;gBACH,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC;YAC7B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBACtE,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;gBAChD,6DAA6D;YAC/D,CAAC;QACH,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,32 @@
1
+ import type { PluginManifest } from '@amk/microkernel-api';
2
+ import type { PluginModule } from '@amk/microkernel-spi';
3
+ declare class PluginRecord {
4
+ manifest: PluginManifest;
5
+ module?: PluginModule | undefined;
6
+ constructor(manifest: PluginManifest, module?: PluginModule | undefined);
7
+ }
8
+ export declare class PluginRegistry {
9
+ private byName;
10
+ /**
11
+ * Get a plugin record by name
12
+ */
13
+ get(name: string): PluginRecord | undefined;
14
+ /**
15
+ * List all loaded plugin manifests
16
+ */
17
+ list(): PluginManifest[];
18
+ /**
19
+ * Register a plugin programmatically (useful for testing/inline plugins)
20
+ */
21
+ register(name: string, manifest: PluginManifest, module: PluginModule): void;
22
+ /**
23
+ * Load plugins from manifest URLs or objects
24
+ */
25
+ loadAllAtRoot(manifestInputs: Array<string | PluginManifest>): Promise<void>;
26
+ /**
27
+ * Get plugin modules in dependency order
28
+ */
29
+ getModulesInOrder(names?: string[] | 'all'): PluginModule[];
30
+ }
31
+ export {};
32
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/runtime/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGzD,cAAM,YAAY;IACG,QAAQ,EAAE,cAAc;IAAS,MAAM,CAAC;gBAAxC,QAAQ,EAAE,cAAc,EAAS,MAAM,CAAC,0BAAc;CAC1E;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAmC;IAEjD;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM;IAIhB;;OAEG;IACH,IAAI;IAIJ;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI;IAI5E;;OAEG;IACG,aAAa,CAAC,cAAc,EAAE,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC;IAiBlE;;OAEG;IACH,iBAAiB,CAAC,KAAK,GAAE,MAAM,EAAE,GAAG,KAAa;CAKlD"}
@@ -0,0 +1,59 @@
1
+ import { topologicalSort } from './graph-utils';
2
+ class PluginRecord {
3
+ constructor(manifest, module) {
4
+ this.manifest = manifest;
5
+ this.module = module;
6
+ }
7
+ }
8
+ export class PluginRegistry {
9
+ constructor() {
10
+ this.byName = new Map();
11
+ }
12
+ /**
13
+ * Get a plugin record by name
14
+ */
15
+ get(name) {
16
+ return this.byName.get(name);
17
+ }
18
+ /**
19
+ * List all loaded plugin manifests
20
+ */
21
+ list() {
22
+ return [...this.byName.values()].map(r => r.manifest);
23
+ }
24
+ /**
25
+ * Register a plugin programmatically (useful for testing/inline plugins)
26
+ */
27
+ register(name, manifest, module) {
28
+ this.byName.set(name, new PluginRecord(manifest, module));
29
+ }
30
+ /**
31
+ * Load plugins from manifest URLs or objects
32
+ */
33
+ async loadAllAtRoot(manifestInputs) {
34
+ const mfs = [];
35
+ for (const m of manifestInputs) {
36
+ if (typeof m === 'string') {
37
+ mfs.push(await fetch(m).then(r => r.json()));
38
+ }
39
+ else {
40
+ mfs.push(m);
41
+ }
42
+ }
43
+ const sorted = topologicalSort(mfs);
44
+ for (const m of sorted) {
45
+ const url = new URL(m.entry, (m.baseUrl ?? location.origin) + '/').toString();
46
+ const mod = await import(/* @vite-ignore */ url);
47
+ this.byName.set(m.name, new PluginRecord(m, mod));
48
+ }
49
+ }
50
+ /**
51
+ * Get plugin modules in dependency order
52
+ */
53
+ getModulesInOrder(names = 'all') {
54
+ const t = names === 'all' ? [...this.byName.keys()] : names;
55
+ const order = topologicalSort(t.map(n => this.byName.get(n).manifest));
56
+ return order.map(m => this.byName.get(m.name).module).filter(Boolean);
57
+ }
58
+ }
59
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/runtime/loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,YAAY;IAChB,YAAmB,QAAwB,EAAS,MAAqB;QAAtD,aAAQ,GAAR,QAAQ,CAAgB;QAAS,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;CAC9E;AAED,MAAM,OAAO,cAAc;IAA3B;QACU,WAAM,GAAG,IAAI,GAAG,EAAwB,CAAC;IAmDnD,CAAC;IAjDC;;OAEG;IACH,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,IAAI;QACF,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,IAAY,EAAE,QAAwB,EAAE,MAAoB;QACnE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,KA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CAAC,CAAC,CAAC;QACxE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAE,CAAC,MAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import type { CommandRegistry, Hooks, ViewRegistry } from '@amk/microkernel-api';
2
+ export declare function createHooks(): Hooks;
3
+ export declare function createCommandRegistry(): CommandRegistry;
4
+ export declare function createViewRegistry(): ViewRegistry;
5
+ //# sourceMappingURL=registries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registries.d.ts","sourceRoot":"","sources":["../../src/runtime/registries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACjF,wBAAgB,WAAW,IAAI,KAAK,CAA2T;AAC/V,wBAAgB,qBAAqB,IAAI,eAAe,CAAmR;AAC3U,wBAAgB,kBAAkB,IAAI,YAAY,CAAiM"}
@@ -0,0 +1,7 @@
1
+ export function createHooks() { const map = new Map(); return { on(e, f) { if (!map.has(e))
2
+ map.set(e, new Set()); map.get(e).add(f); }, off(e, f) { map.get(e)?.delete(f); }, emit(e, ...a) { for (const fn of map.get(e) ?? [])
3
+ fn(...a); } }; }
4
+ export function createCommandRegistry() { const h = new Map(); return { register(id, fn) { h.set(id, fn); }, run(id, ...a) { const fn = h.get(id); if (!fn)
5
+ throw new Error(`Command not found: ${id}`); return fn(...a); }, has(id) { return h.has(id); } }; }
6
+ export function createViewRegistry() { const s = new Map(); return { register(slot, v) { const arr = s.get(slot) ?? []; arr.push(v); s.set(slot, arr); }, list(slot) { return [...(s.get(slot) ?? [])]; } }; }
7
+ //# sourceMappingURL=registries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registries.js","sourceRoot":"","sources":["../../src/runtime/registries.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AAE,CAAC,CAAC,CAAC;AAC3U,MAAM,UAAU,kBAAkB,KAAmB,MAAM,CAAC,GAAC,IAAI,GAAG,EAAgB,CAAC,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAY,EAAC,CAAM,IAAG,MAAM,GAAG,GAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,IAAY,IAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { ProvidedServices } from '@amk/microkernel-api';
2
+ export declare const UI: {
3
+ registerView(ctx: ProvidedServices, slot: string, viewFactory: any): void;
4
+ getViews(ctx: ProvidedServices, slot: string): any[];
5
+ };
6
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/ui/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,eAAO,MAAM,EAAE;sBAAuB,gBAAgB,QAAQ,MAAM,eAAe,GAAG;kBAA2D,gBAAgB,QAAQ,MAAM;CAAmC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const UI = { registerView(ctx, slot, viewFactory) { ctx.views.register(slot, viewFactory); }, getViews(ctx, slot) { return ctx.views.list(slot); } };
2
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../src/ui/adapter.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,YAAY,CAAC,GAAqB,EAAE,IAAY,EAAE,WAAgB,IAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAqB,EAAE,IAAY,IAAG,OAAO,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@hamak/microkernel-impl",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Microkernel Implementation - Core microkernel functionality",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/amah/app-framework.git",
12
+ "directory": "packages/microkernel/microkernel-impl"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.lib.json",
19
+ "clean": "rm -rf dist"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ }
26
+ },
27
+ "dependencies": {
28
+ "@hamak/microkernel-api": "0.1.0",
29
+ "@hamak/microkernel-spi": "0.1.0"
30
+ }
31
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './runtime/di';
2
+ export * from './runtime/registries';
3
+ export * from './runtime/loader';
4
+ export * from './runtime/host';
5
+ export * from './ui/adapter';
@@ -0,0 +1,21 @@
1
+ import type { Provider, Token } from '@amk/microkernel-api';
2
+ const INJECT_KEY = Symbol('di:inject');
3
+ export function Injectable(deps: Token[] = []): ClassDecorator { return (t: any) => { (t as any)[INJECT_KEY] = deps; }; }
4
+ export class Container {
5
+ private parent?: Container; private providers = new Map<Token, Provider>(); private instances = new Map<Token, any>();
6
+ constructor(parent?: Container) { this.parent = parent; }
7
+ createChild(): Container { return new Container(this); }
8
+ provide<T>(prov: Provider<T>): this { this.providers.set(prov.provide, prov); return this; }
9
+ resolve<T>(token: Token<T>): T {
10
+ if (this.instances.has(token)) return this.instances.get(token);
11
+ if (this.providers.has(token)) {
12
+ const prov: any = this.providers.get(token)!; let value: any;
13
+ if ('useValue' in prov) value = prov.useValue;
14
+ else if ('useClass' in prov) { const C = prov.useClass; const deps: Token[] = (C as any)[INJECT_KEY] || []; const args = deps.map((d)=>this.resolve(d)); value = new C(...args); }
15
+ else { const deps: Token[] = prov.deps || []; const args = deps.map((d)=>this.resolve(d)); value = prov.useFactory(...args); }
16
+ this.instances.set(token, value); return value;
17
+ }
18
+ if (this.parent) return this.parent.resolve(token);
19
+ throw new Error(`No provider for token: ${token.toString?.() ?? String(token)}`);
20
+ }
21
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Dependency graph utilities for topological sorting
3
+ */
4
+
5
+ export interface DependencyNode {
6
+ name: string;
7
+ dependsOn?: string[];
8
+ }
9
+
10
+ /**
11
+ * Performs topological sort on items based on their dependencies
12
+ * @param items Items to sort (must have name and optional dependsOn properties)
13
+ * @returns Sorted items in dependency order
14
+ * @throws Error if circular dependency is detected
15
+ */
16
+ export function topologicalSort<T extends DependencyNode>(items: T[]): T[] {
17
+ const index = new Map(items.map(i => [i.name, i]));
18
+ const visited = new Set<string>();
19
+ const result: T[] = [];
20
+
21
+ const visit = (item: T, path: Set<string> = new Set()) => {
22
+ if (visited.has(item.name)) return;
23
+
24
+ // Cycle detection
25
+ if (path.has(item.name)) {
26
+ throw new Error(
27
+ `Circular dependency detected: ${[...path, item.name].join(' -> ')}`
28
+ );
29
+ }
30
+
31
+ path.add(item.name);
32
+
33
+ (item.dependsOn ?? []).forEach(depName => {
34
+ const dep = index.get(depName);
35
+ if (!dep) {
36
+ console.warn(
37
+ `Dependency not found: ${depName} (required by ${item.name})`
38
+ );
39
+ return;
40
+ }
41
+ visit(dep, new Set(path));
42
+ });
43
+
44
+ visited.add(item.name);
45
+ result.push(item);
46
+ };
47
+
48
+ items.forEach(item => visit(item));
49
+ return result;
50
+ }
@@ -0,0 +1,177 @@
1
+ import type { ActivateContext, IChildHost, IHost, PluginManifest, Provider, CommandRegistry, ViewRegistry, Hooks } from '@amk/microkernel-api';
2
+ import { Container } from './di';
3
+ import { createCommandRegistry, createHooks, createViewRegistry } from './registries';
4
+ import { PluginRegistry } from './loader';
5
+ import type { InitializationContext, PluginModule } from '@amk/microkernel-spi';
6
+
7
+ type SharedRegistries = {
8
+ commands: CommandRegistry;
9
+ views: ViewRegistry;
10
+ hooks: Hooks;
11
+ };
12
+
13
+ function createSharedRegistries(): SharedRegistries {
14
+ return {
15
+ commands: createCommandRegistry(),
16
+ views: createViewRegistry(),
17
+ hooks: createHooks(),
18
+ };
19
+ }
20
+
21
+ function createInitContext(
22
+ container: Container,
23
+ registries: SharedRegistries,
24
+ env?: Record<string, any>
25
+ ): InitializationContext {
26
+ return {
27
+ provide: (prov: Provider) => container.provide(prov),
28
+ resolve: <T>(t: any) => container.resolve(t),
29
+ commands: {
30
+ register: (id: string, h: (...a: any[]) => any) => registries.commands.register(id, h)
31
+ },
32
+ views: {
33
+ register: (slot: string, vf: any) => registries.views.register(slot, vf)
34
+ },
35
+ hooks: {
36
+ on: (ev: string, fn: (...a: any[]) => void) => registries.hooks.on(ev, fn),
37
+ emit: (ev: string, ...a: any[]) => registries.hooks.emit(ev, ...a)
38
+ },
39
+ env,
40
+ };
41
+ }
42
+
43
+ function createActivateContext(
44
+ container: Container,
45
+ registries: SharedRegistries,
46
+ env?: Record<string, any>
47
+ ): ActivateContext {
48
+ return {
49
+ resolve: <T>(t: any) => container.resolve(t),
50
+ commands: registries.commands,
51
+ views: registries.views,
52
+ hooks: registries.hooks,
53
+ env,
54
+ };
55
+ }
56
+
57
+ export class Host implements IHost {
58
+ readonly root: Container;
59
+ private readonly _registry: PluginRegistry;
60
+ private env?: Record<string, any>;
61
+ rootActivationCtx?: ActivateContext;
62
+
63
+ constructor(initialProviders: Provider[] = [], env?: Record<string, any>){
64
+ this.root = new Container();
65
+ initialProviders.forEach(p=>this.root.provide(p));
66
+ this._registry = new PluginRegistry();
67
+ this.env = env;
68
+ }
69
+
70
+ async loadPlugins(manifests: Array<string|PluginManifest>): Promise<void>{
71
+ await this._registry.loadAllAtRoot(manifests);
72
+ }
73
+
74
+ /**
75
+ * Register a plugin programmatically (useful for testing/inline plugins)
76
+ * @param name Plugin name
77
+ * @param manifest Plugin manifest
78
+ * @param module Plugin module implementation
79
+ */
80
+ registerPlugin(name: string, manifest: PluginManifest, module: PluginModule): void {
81
+ this._registry.register(name, manifest, module);
82
+ }
83
+
84
+ /**
85
+ * Get plugin manifest by name
86
+ * @param name Plugin name
87
+ * @returns Plugin manifest or undefined if not found
88
+ */
89
+ getPlugin(name: string): PluginManifest | undefined {
90
+ return this._registry.get(name)?.manifest;
91
+ }
92
+
93
+ /**
94
+ * List all loaded plugins
95
+ * @returns Array of plugin manifests
96
+ */
97
+ listPlugins(): PluginManifest[] {
98
+ return this._registry.list();
99
+ }
100
+
101
+ async bootstrapAllAtRoot(): Promise<void>{
102
+ const registries = createSharedRegistries();
103
+ const initCtx = createInitContext(this.root, registries, this.env);
104
+ const mods = this._registry.getModulesInOrder('all');
105
+
106
+ // Initialize phase with error handling
107
+ for(const m of mods) {
108
+ try {
109
+ await m.initialize?.(initCtx);
110
+ } catch (error) {
111
+ const err = error instanceof Error ? error : new Error(String(error));
112
+ const initError = new Error(`Plugin initialization failed: ${err.message}`);
113
+ (initError as any).cause = error;
114
+ throw initError;
115
+ }
116
+ }
117
+
118
+ const actCtx = createActivateContext(this.root, registries, this.env);
119
+ this.rootActivationCtx = actCtx;
120
+
121
+ // Activation phase with error handling
122
+ for(const m of mods) {
123
+ try {
124
+ await m.activate?.(actCtx);
125
+ } catch (error) {
126
+ const err = error instanceof Error ? error : new Error(String(error));
127
+ console.error(`Plugin activation failed:`, err);
128
+ // Continue with other plugins rather than failing completely
129
+ }
130
+ }
131
+
132
+ actCtx.hooks.emit('host:activated');
133
+ }
134
+
135
+ createChildHost(overrides: Provider[] = [], env?: Record<string, any>): IChildHost {
136
+ const child = this.root.createChild();
137
+ overrides.forEach(p=>child.provide(p));
138
+ const childEnv = { ...(this.env||{}), ...(env||{}) };
139
+ return new ChildHost(child, this._registry, childEnv);
140
+ }
141
+ }
142
+
143
+ class ChildHost implements IChildHost {
144
+ constructor(private readonly container: Container, private readonly registry: PluginRegistry, private readonly env?: Record<string, any>) {}
145
+ async bootstrap(pluginNames: string[]|'all'='all'): Promise<void>{
146
+ const registries = createSharedRegistries();
147
+ const initCtx = createInitContext(this.container, registries, this.env);
148
+ const mods = this.registry.getModulesInOrder(pluginNames);
149
+
150
+ // Initialize phase with error handling
151
+ for(const m of mods) {
152
+ try {
153
+ await m.initialize?.(initCtx);
154
+ } catch (error) {
155
+ const err = error instanceof Error ? error : new Error(String(error));
156
+ const initError = new Error(`Plugin initialization failed: ${err.message}`);
157
+ (initError as any).cause = error;
158
+ throw initError;
159
+ }
160
+ }
161
+
162
+ const actCtx = createActivateContext(this.container, registries, this.env);
163
+
164
+ // Activation phase with error handling
165
+ for(const m of mods) {
166
+ try {
167
+ await m.activate?.(actCtx);
168
+ } catch (error) {
169
+ const err = error instanceof Error ? error : new Error(String(error));
170
+ console.error(`Plugin activation failed:`, err);
171
+ // Continue with other plugins rather than failing completely
172
+ }
173
+ }
174
+
175
+ actCtx.hooks.emit('child:activated');
176
+ }
177
+ }
@@ -0,0 +1,61 @@
1
+ import type { PluginManifest } from '@amk/microkernel-api';
2
+ import type { PluginModule } from '@amk/microkernel-spi';
3
+ import { topologicalSort } from './graph-utils';
4
+
5
+ class PluginRecord {
6
+ constructor(public manifest: PluginManifest, public module?: PluginModule) {}
7
+ }
8
+
9
+ export class PluginRegistry {
10
+ private byName = new Map<string, PluginRecord>();
11
+
12
+ /**
13
+ * Get a plugin record by name
14
+ */
15
+ get(name: string) {
16
+ return this.byName.get(name);
17
+ }
18
+
19
+ /**
20
+ * List all loaded plugin manifests
21
+ */
22
+ list() {
23
+ return [...this.byName.values()].map(r => r.manifest);
24
+ }
25
+
26
+ /**
27
+ * Register a plugin programmatically (useful for testing/inline plugins)
28
+ */
29
+ register(name: string, manifest: PluginManifest, module: PluginModule): void {
30
+ this.byName.set(name, new PluginRecord(manifest, module));
31
+ }
32
+
33
+ /**
34
+ * Load plugins from manifest URLs or objects
35
+ */
36
+ async loadAllAtRoot(manifestInputs: Array<string | PluginManifest>) {
37
+ const mfs: PluginManifest[] = [];
38
+ for (const m of manifestInputs) {
39
+ if (typeof m === 'string') {
40
+ mfs.push(await fetch(m).then(r => r.json()));
41
+ } else {
42
+ mfs.push(m);
43
+ }
44
+ }
45
+ const sorted = topologicalSort(mfs);
46
+ for (const m of sorted) {
47
+ const url = new URL(m.entry, (m.baseUrl ?? location.origin) + '/').toString();
48
+ const mod: PluginModule = await import(/* @vite-ignore */ url);
49
+ this.byName.set(m.name, new PluginRecord(m, mod));
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Get plugin modules in dependency order
55
+ */
56
+ getModulesInOrder(names: string[] | 'all' = 'all') {
57
+ const t = names === 'all' ? [...this.byName.keys()] : names;
58
+ const order = topologicalSort(t.map(n => this.byName.get(n)!.manifest));
59
+ return order.map(m => this.byName.get(m.name)!.module!).filter(Boolean);
60
+ }
61
+ }
@@ -0,0 +1,4 @@
1
+ import type { CommandRegistry, Hooks, ViewRegistry } from '@amk/microkernel-api';
2
+ export function createHooks(): Hooks { const map = new Map<string, Set<(...a:any[])=>void>>(); return { on(e: string,f: (...a: any[]) => void){ if(!map.has(e)) map.set(e,new Set()); map.get(e)!.add(f); }, off(e: string,f: (...a: any[]) => void){ map.get(e)?.delete(f); }, emit(e: string,...a: any[]){ for(const fn of map.get(e) ?? []) fn(...a); } }; }
3
+ export function createCommandRegistry(): CommandRegistry { const h=new Map<string,(...a:any[])=>any>(); return { register(id: string,fn: (...a:any[])=>any){h.set(id,fn);}, run(id: string,...a: any[]){const fn=h.get(id); if(!fn) throw new Error(`Command not found: ${id}`); return fn(...a);}, has(id: string){return h.has(id);} }; }
4
+ export function createViewRegistry(): ViewRegistry { const s=new Map<string,any[]>(); return { register(slot: string,v: any){ const arr=s.get(slot)??[]; arr.push(v); s.set(slot,arr); }, list(slot: string){ return [...(s.get(slot)??[])]; } }; }
@@ -0,0 +1,2 @@
1
+ import type { ProvidedServices } from '@amk/microkernel-api';
2
+ export const UI = { registerView(ctx: ProvidedServices, slot: string, viewFactory: any){ ctx.views.register(slot, viewFactory); }, getViews(ctx: ProvidedServices, slot: string){ return ctx.views.list(slot); } };
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": ["ES2020", "DOM"],
5
+ "module": "ESNext",
6
+ "moduleResolution": "Bundler",
7
+ "rootDir": "./src",
8
+ "outDir": "./dist",
9
+ "declaration": true,
10
+ "declarationMap": true,
11
+ "sourceMap": true,
12
+ "strict": true,
13
+ "esModuleInterop": true,
14
+ "skipLibCheck": true,
15
+ "types": []
16
+ },
17
+ "include": [
18
+ "src/**/*.ts"
19
+ ],
20
+ "exclude": [
21
+ "node_modules",
22
+ "dist"
23
+ ]
24
+ }