@makoojs/core 0.2.1 → 0.3.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/README.md CHANGED
@@ -1,272 +1,709 @@
1
- # @makoojs/core
1
+ # Core API Reference
2
2
 
3
- `@makoojs/core` is Makoo's framework-agnostic runtime core. It declares injection tasks, starts task batches, waits for target DOM nodes, mounts artifacts, manages alive reinjection, binds event listeners, and provides lifecycle observation, logging, and error infrastructure.
3
+ ## API Index
4
4
 
5
- Projects should usually start with `@makoojs/cli`. Use core directly when you want to integrate Makoo's runtime without the CLI-generated entry.
5
+ ### Tasks
6
6
 
7
- > [!NOTE]
8
- > `@makoojs/core` is the parent package for the rest of Makoo. Other packages depend on its types or runtime capabilities either directly or indirectly.
7
+ - [`createMakoo()`](#createmakoo): creates a runtime
8
+ - [`inject()`](#inject): declares a component task
9
+ - [`listen()`](#listen): declares a listener task
9
10
 
10
- ## Use Cases
11
+ ### Observation and state
11
12
 
12
- - Write a custom `ResolvableMountAdapter` so Makoo can mount a new artifact type.
13
- - Create a Makoo runtime with `createMakoo()` and start explicit task declarations.
14
- - Listen to injection lifecycle events for debugging, analytics, error reporting, or visual devtools.
15
- - Use low-level tools such as `DOMWatcher` and `createActivityStore` for custom integrations.
13
+ - [`createObserverHub()`](#createobserverhub): creates a lifecycle event hub
14
+ - [`createActivityStore()`](#createactivitystore): creates subscribable state
15
+ - [`DOMWatcher`](#domwatcher): observes DOM targets
16
16
 
17
- ## Installation
17
+ ### Infrastructure
18
18
 
19
- ```bash
20
- // npm install @makoojs/core
21
- // yarn add @makoojs/core
22
- pnpm add @makoojs/core
19
+ - [`Logger`](#logger): logger implementation
20
+ - [Error classes](#error-classes): structured errors
21
+ - [Constants](#constants): actions, event names, and error codes
22
+
23
+ ### TypeScript types
24
+
25
+ - [Adapter types](#adapter-types)
26
+ - [Task types](#task-types)
27
+ - [Observer types](#observer-types)
28
+ - [Signal types](#signal-types)
29
+ - [Logger types](#logger-types)
30
+ - [Error types](#error-types)
31
+
32
+ ## `createMakoo()`
33
+
34
+ Creates a Makoo runtime.
35
+
36
+ ### Type
37
+
38
+ ```ts
39
+ function createMakoo(options?: CreateMakooOptions): MakooRuntime;
23
40
  ```
24
41
 
25
- ## Minimal Runtime Example
42
+ ### Parameters
43
+
44
+ `options` uses `CreateMakooOptions`:
45
+
46
+ | Field | Type | Default | Description |
47
+ | --- | --- | --- | --- |
48
+ | `defaults` | `Partial<MakooDefaults>` | `{}` | Sets the default injection options |
49
+ | `adapters` | `ResolvableMountAdapter[]` | `[]` | Registers adapters that can mount artifacts |
50
+ | `hooks` | `LifecycleHookMap` | `undefined` | Registers global lifecycle hooks |
51
+ | `logger` | `ILogger` | `new Logger()` | Sets the logger implementation |
52
+ | `observer` | `ObserverHub` | `createObserverHub(logger)` | Sets the lifecycle event hub |
53
+
54
+ ### Details
55
+
56
+ The final default values of `defaults` are:
26
57
 
27
58
  ```ts
28
- import {
29
- createMakoo,
30
- inject,
31
- type ResolvableMountAdapter
32
- } from '@makoojs/core';
59
+ {
60
+ alive: false,
61
+ scope: 'local',
62
+ timeout: 5000
63
+ }
64
+ ```
33
65
 
34
- type TextArtifact = {
35
- kind: 'text';
36
- text: string;
37
- };
66
+ ### Returns
38
67
 
39
- const textAdapter: ResolvableMountAdapter<TextArtifact, HTMLElement> = {
40
- name: 'text',
41
- matches(artifact): artifact is TextArtifact {
42
- return (
43
- typeof artifact === 'object' &&
44
- artifact !== null &&
45
- (artifact as { kind?: unknown }).kind === 'text'
46
- );
47
- },
48
- mount({ mountPoint, artifact }) {
49
- const el = document.createElement('span');
50
- el.textContent = artifact.text;
51
- mountPoint.appendChild(el);
52
-
53
- return { handle: el };
54
- },
55
- unmount({ handle }) {
56
- handle.remove();
57
- }
58
- };
68
+ Returns `MakooRuntime`:
69
+
70
+ | Method | Returns | Description |
71
+ | --- | --- | --- |
72
+ | `start(tasks)` | `StartedTasks` | Registers and starts a batch of `MakooTaskDeclaration`; an empty array throws `TaskError` |
73
+ | `reset(taskId)` | `void` | Resets a task and releases its current resources |
74
+ | `destroy(taskId)` | `void` | Destroys and removes a task |
75
+ | `resetAll()` | `void` | Resets every task in the runtime |
76
+ | `destroyAll()` | `void` | Destroys every task in the runtime |
77
+ | `enableAlive(taskId)` | `void` | Enables alive observation for a component task |
78
+ | `disableAlive(taskId)` | `void` | Disables alive observation for a component task |
79
+ | `on(event, hook)` | `() => void` | Subscribes to an event and returns an unsubscribe function |
80
+ | `onTask(taskId, event, hook)` | `() => void` | Subscribes to an event for one task and returns an unsubscribe function |
81
+ | `onAny(hook)` | `() => void` | Subscribes to all events and returns an unsubscribe function |
82
+ | `off(event, hook?)` | `void` | Removes one or all hooks for an event |
83
+ | `offTask(taskId, event?, hook?)` | `void` | Removes task hooks |
84
+ | `offAny(hook)` | `void` | Removes a hook registered with `onAny()` |
85
+ | `getLogger()` | `ILogger` | Returns the current logger |
86
+
87
+ Duplicate task IDs are skipped and are not included in the `StartedTasks.tasks` returned by that `start()` call.
88
+
89
+ ### Example
59
90
 
91
+ ```ts
60
92
  const makoo = createMakoo({
61
- defaults: {
62
- alive: true,
63
- scope: 'local',
64
- timeout: 5000
65
- },
66
- adapters: [textAdapter]
93
+ adapters: [adapter]
67
94
  });
68
95
 
69
- makoo.start([
70
- inject('#app', {
71
- kind: 'text',
72
- text: 'Hello from Makoo core'
73
- })
96
+ const started = makoo.start([
97
+ inject({ injectAt: '#app', artifact })
74
98
  ]);
75
99
  ```
76
100
 
77
- ## Runtime Basics
101
+ ## `inject()`
78
102
 
79
- `inject()` and `listen()` are declaration helpers. They do not touch the DOM and do not register tasks by themselves. `makoo.start([...])` registers the declarations in the provided batch and immediately schedules those tasks.
103
+ Creates a component task declaration. `inject()` does not register or start the task; pass its result to `MakooRuntime.start()`.
80
104
 
81
- `inject()` has two forms. The positional form is concise:
105
+ ### Type
82
106
 
83
107
  ```ts
84
- inject('#toolbar', toolbarArtifact, {
85
- alive: true
86
- });
108
+ function inject<TArtifact>(
109
+ input: MakooInjectionInput<TArtifact>
110
+ ): MakooInjectionDeclaration<TArtifact>;
111
+ ```
112
+
113
+ ### Parameters
114
+
115
+ ```ts
116
+ type MakooInjectionInput<TArtifact = unknown> = {
117
+ id?: string;
118
+ injectAt: string;
119
+ artifact: TArtifact;
120
+ options?: ArtifactOptions;
121
+ };
87
122
  ```
88
123
 
89
- The object form keeps the declaration fields together. Its optional `id` is used as the task id, which is useful when you want to look up or control that task later:
124
+ When `id` is omitted, the runtime derives a task ID from the artifact and `injectAt`.
125
+
126
+ #### `ArtifactOptions`
127
+
128
+ | Field | Type | Description |
129
+ | --- | --- | --- |
130
+ | `alive` | `boolean` | Attempts to mount again after the target is replaced |
131
+ | `scope` | `'local' \| 'global'` | Observation scope used by alive mode |
132
+ | `timeout` | `number` | Milliseconds to wait for the target element |
133
+ | `on` | `MakooListenerDeclaration` | Event listener registered with the component |
134
+ | `hooks` | `LifecycleHookMap` | Lifecycle hooks for this task |
135
+
136
+ ### Returns
137
+
138
+ Returns `MakooInjectionDeclaration<TArtifact>`.
139
+
140
+ ### Example
90
141
 
91
142
  ```ts
92
- inject({
143
+ const declaration = inject({
93
144
  id: 'settings-panel',
94
145
  injectAt: '#settings',
95
- artifact: settingsArtifact,
146
+ artifact: settingsPanel,
96
147
  options: {
97
- alive: true
148
+ alive: true,
149
+ scope: 'global'
98
150
  }
99
151
  });
100
152
  ```
101
153
 
102
- When `id` is omitted, Makoo infers a task id from the artifact and target selector.
154
+ ## `listen()`
155
+
156
+ Creates a listener task declaration. `listen()` does not register or start the task. Pass its result to `MakooRuntime.start()` or use it as `ArtifactOptions.on`.
157
+
158
+ ### Type
103
159
 
104
160
  ```ts
105
- import { createMakoo, inject, listen } from '@makoojs/core';
161
+ function listen(input: MakooListenerInput): MakooListenerDeclaration;
162
+ ```
106
163
 
107
- const makoo = createMakoo({
108
- defaults: {
109
- alive: false,
110
- scope: 'local',
111
- timeout: 5000
112
- },
113
- adapters: [myAdapter],
114
- hooks: {
115
- 'start:requested': (event) => {
116
- console.log(event.name);
117
- }
118
- }
164
+ ### Parameters
165
+
166
+ ```ts
167
+ type MakooListenerInput = {
168
+ id?: string;
169
+ listenAt: string;
170
+ type: string;
171
+ callback: EventListener;
172
+ activitySignal?: () => ActivitySignalSource<boolean>;
173
+ };
174
+ ```
175
+
176
+ When `id` is omitted, the runtime uses `listener-${listenAt}-${type}` as the task ID.
177
+
178
+ ### Returns
179
+
180
+ Returns `MakooListenerDeclaration`. It can be started as a standalone task or assigned to `ArtifactOptions.on`.
181
+
182
+ ### Example
183
+
184
+ ```ts
185
+ const declaration = listen({
186
+ id: 'escape-close',
187
+ listenAt: 'body',
188
+ type: 'keydown',
189
+ callback: onEscape
119
190
  });
191
+ ```
120
192
 
121
- const started = makoo.start([
122
- inject('#toolbar', toolbarArtifact, {
123
- alive: true
124
- }),
125
- inject({
126
- id: 'settings-panel',
127
- injectAt: '#settings',
128
- artifact: settingsArtifact,
129
- options: {
130
- alive: true
131
- }
132
- }),
133
- inject('#save-tip', saveTipArtifact, {
134
- on: listen('#save', 'click', () => {
135
- console.log('save clicked');
136
- })
137
- }),
138
- listen('#escape', 'keydown', onEscape)
139
- ]);
193
+ ## `createObserverHub()`
194
+
195
+ Creates an event hub. `logger` defaults to `new Logger()`.
196
+
197
+ ### Type
198
+
199
+ ```ts
200
+ function createObserverHub(logger?: ILogger): ObserverHub;
140
201
  ```
141
202
 
142
- `start()` returns `StartedTasks` for batch-scoped control:
203
+ ### Parameters
204
+
205
+ - `logger`: optional `ILogger`. A `Logger` is created when omitted.
206
+
207
+ ### Returns
208
+
209
+ Returns `ObserverHub`:
210
+
211
+ | Method | Returns | Description |
212
+ | --- | --- | --- |
213
+ | `on(event, hook)` | `() => void` | Registers a hook for an event |
214
+ | `onTask(taskId, event, hook)` | `() => void` | Registers a task-specific hook |
215
+ | `onAny(hook)` | `() => void` | Registers a hook for every event |
216
+ | `off(event, hook?)` | `void` | Removes event hooks |
217
+ | `offTask(taskId, event?, hook?)` | `void` | Removes task hooks |
218
+ | `offAny(hook)` | `void` | Removes a global hook |
219
+ | `clear()` | `void` | Removes all hooks |
220
+ | `hasHooks(event?)` | `boolean` | Checks whether any or a specific event has hooks |
221
+ | `emit(event)` | `void` | Emits an event |
222
+ | `emitOnTask(taskId, event)` | `void` | Emits an event for a task |
223
+
224
+ Task events run task hooks, same-name event hooks, and `onAny()` hooks in that order. `stopPropagation()` prevents the next group from running. `stopImmediatePropagation()` also stops the remaining hooks in the current group. If a hook throws, the error is logged and the other hooks continue.
225
+
226
+ ### Example
143
227
 
144
228
  ```ts
145
- const toolbar = started.get('Toolbar@#toolbar');
229
+ const observer = createObserverHub();
230
+ const off = observer.on('artifact:mountSuccess', (event) => {
231
+ console.log(event.taskId);
232
+ });
146
233
 
147
- if (toolbar?.kind === 'component') {
148
- toolbar.disableAlive();
149
- toolbar.enableAlive();
150
- }
234
+ off();
235
+ ```
236
+
237
+ ## `createActivityStore()`
238
+
239
+ Creates readable, subscribable, and writable state.
240
+
241
+ ### Type
151
242
 
152
- started.destroyAll();
243
+ ```ts
244
+ function createActivityStore<T>(initialValue: T): {
245
+ get(): T;
246
+ subscribe(listener: (value: T) => void): SignalUnsubscribe;
247
+ set(value: T): void;
248
+ update(updater: (value: T) => T): void;
249
+ };
153
250
  ```
154
251
 
155
- `started.destroyAll()` only affects tasks created by that start batch. `makoo.destroyAll()` affects the whole runtime.
252
+ ### Parameters
253
+
254
+ - `initialValue`: the initial state value.
255
+
256
+ ### Returns
257
+
258
+ Returns an object with `get()`, `subscribe()`, `set()`, and `update()`.
259
+
260
+ ### Details
156
261
 
157
- ## Adapter Contract
262
+ `set()` and `update()` compare the new and current values with `Object.is()` and do not notify subscribers when the value is unchanged.
158
263
 
159
- core does not care whether an artifact is a Vue component, a React component, or another object. It only requires adapters to implement a unified mounting protocol.
264
+ ### Example
160
265
 
161
266
  ```ts
162
- import type { ResolvableMountAdapter } from '@makoojs/core';
267
+ const active = createActivityStore(true);
268
+ const unsubscribe = active.subscribe((value) => {
269
+ console.log(value);
270
+ });
271
+
272
+ active.set(false);
273
+ active.update((value) => !value);
274
+ unsubscribe();
275
+ ```
276
+
277
+ ## `DOMWatcher`
278
+
279
+ ### `DOMWatcher.onDomReady()`
280
+
281
+ Finds an existing matching element and observes subsequently added elements with `MutationObserver`.
163
282
 
164
- const adapter: ResolvableMountAdapter<MyArtifact, MyHandle, MyInstance> = {
165
- name: 'my-adapter',
166
- matches(artifact): artifact is MyArtifact {
167
- return isMyArtifact(artifact);
168
- },
169
- mount(input) {
170
- return {
171
- handle,
172
- instance
173
- };
174
- },
175
- unmount(input) {
176
- // Clean up according to input.reason.
283
+ #### Type
284
+
285
+ ```ts
286
+ DOMWatcher.onDomReady(
287
+ selector: string,
288
+ callback: (element: HTMLElement, observer?: MutationObserver) => void,
289
+ root: Document | HTMLElement = document,
290
+ options: { once: boolean; timeout?: number } | { once?: boolean; timeout: number },
291
+ runtime?: {
292
+ logger: ILogger;
293
+ emit: (name:
294
+ | 'dom:targetFound'
295
+ | 'dom:targetTimeout'
296
+ | 'dom:targetRemoved'
297
+ | 'dom:targetRestored'
298
+ ) => void;
177
299
  }
178
- };
300
+ ): () => void;
179
301
  ```
180
302
 
181
- `mount(input)` receives the target host, generated mount point, artifact, task ID, selector, and task-scoped `makoo` context.
303
+ #### Details
182
304
 
183
- ## Listener And Activity Signal
305
+ - Calls `callback` when an element is found.
306
+ - Stops after the first match when `once: true`.
307
+ - Stops when `timeout` expires.
308
+ - Returns a function that stops observation.
184
309
 
185
- Standalone listeners are declared with `listen()`.
310
+ ### `DOMWatcher.onDomAlive()`
311
+
312
+ Observes removal of `target` and calls `onRestore` when a new element matching `selector` appears.
313
+
314
+ #### Type
186
315
 
187
316
  ```ts
188
- import { createActivityStore, createMakoo, listen } from '@makoojs/core';
317
+ DOMWatcher.onDomAlive(
318
+ target: HTMLElement,
319
+ selector: string,
320
+ onRemove: () => void,
321
+ onRestore: (element: HTMLElement, observer?: MutationObserver) => void,
322
+ root: Document | HTMLElement = document,
323
+ options: { once: boolean; timeout?: number } | { once?: boolean; timeout: number },
324
+ runtime?: {
325
+ logger: ILogger;
326
+ emit: (name:
327
+ | 'dom:targetFound'
328
+ | 'dom:targetTimeout'
329
+ | 'dom:targetRemoved'
330
+ | 'dom:targetRestored'
331
+ ) => void;
332
+ }
333
+ ): () => void;
334
+ ```
189
335
 
190
- const enabled = createActivityStore(true);
191
- const makoo = createMakoo();
336
+ #### Returns
192
337
 
193
- makoo.start([
194
- listen(
195
- '#save',
196
- 'click',
197
- () => {
198
- console.log('save clicked');
199
- },
200
- {
201
- activitySignal: () => enabled
202
- }
203
- )
204
- ]);
338
+ Returns a function that stops both removal and restoration observation.
339
+
340
+ ## `Logger`
205
341
 
206
- enabled.set(false);
207
- enabled.set(true);
342
+ Makoo's default logger implementation.
343
+
344
+ ### Type
345
+
346
+ ```ts
347
+ class Logger implements ILogger {
348
+ static readonly PREFIX = '[Makoo]';
349
+
350
+ constructor(level?: LoggerLevel);
351
+ setLevel(level: LoggerLevel): void;
352
+ getLevel(): LoggerLevel;
353
+ log(level: LoggerLevel, message: string, ...args: unknown[]): void;
354
+ debug(message: string, ...args: unknown[]): void;
355
+ info(message: string, ...args: unknown[]): void;
356
+ warn(message: string, ...args: unknown[]): void;
357
+ error(message: string, ...args: unknown[]): void;
358
+ }
208
359
  ```
209
360
 
210
- ## Observation Events
361
+ The default level is `info`. Level order is `debug`, `info`, `warn`, and `error`; messages below the current level are not emitted.
362
+
363
+ ## Error classes
211
364
 
212
- core emits observation events during declaration registration, starting, mounting, listener work, alive mode, DOM watching, and task status changes.
365
+ ### `MakooError`
213
366
 
214
367
  ```ts
215
- const off = makoo.on('artifact:mountSuccess', (event) => {
216
- console.log(event.taskId, event.injectAt);
217
- });
368
+ class MakooError extends Error {
369
+ readonly code: string;
370
+ readonly issues: MakooIssue[];
371
+ override readonly cause?: Error;
372
+
373
+ constructor(
374
+ message: string,
375
+ issues?: MakooIssue[],
376
+ code?: string,
377
+ cause?: Error
378
+ );
379
+ }
380
+ ```
218
381
 
219
- makoo.onAny((event, ctrl) => {
220
- if (event.name === 'artifact:mountFail') {
221
- ctrl.stopPropagation();
222
- }
223
- });
382
+ `message` receives a `[makoo]` prefix and includes the `issues` and `cause` error chain.
224
383
 
225
- off();
384
+ ### `AdapterError`
385
+
386
+ ```ts
387
+ class AdapterError extends MakooError;
226
388
  ```
227
389
 
228
- Common events include:
390
+ Default code: `ErrorCode.ADAPTER_NOT_FOUND`.
229
391
 
230
- - `register:start`
231
- - `register:success`
232
- - `start:requested`
233
- - `start:taskScheduled`
234
- - `artifact:mountStart`
235
- - `artifact:mountSuccess`
236
- - `artifact:mountFail`
237
- - `listener:attached`
238
- - `alive:enabled`
239
- - `alive:observerStarted`
240
- - `task:statusChange`
241
- - `dom:targetFound`
242
- - `dom:targetTimeout`
392
+ ### `SignalError`
243
393
 
244
- The full event name list is available from `OBSERVE_EVENT_NAMES`.
394
+ ```ts
395
+ class SignalError extends MakooError;
396
+ ```
245
397
 
246
- ## DOMWatcher
398
+ Default code: `ErrorCode.TASK_SIGNAL_INVALID`.
247
399
 
248
- `DOMWatcher` is core's low-level DOM observation utility. You usually do not need to use it directly because `makoo.start()` and alive mode already wrap target waiting and restoration.
400
+ ### `TaskError`
249
401
 
250
- ## Logging And Errors
402
+ ```ts
403
+ class TaskError extends MakooError;
404
+ ```
405
+
406
+ Default code: `ErrorCode.TASK_NO_REGISTERED`.
407
+
408
+ ## Constants
251
409
 
252
- core uses `Logger` by default and prints logs with the `[Makoo]` prefix. You can pass a custom logger to `createMakoo({ logger })`.
410
+ ### `Action`
253
411
 
254
- core also exports these error-related types:
412
+ ```ts
413
+ enum Action {
414
+ OPEN = 'OPEN',
415
+ CLOSE = 'CLOSE'
416
+ }
255
417
 
256
- - `MakooError`
257
- - `AdapterError`
258
- - `TaskError`
259
- - `ErrorCode`
260
- - `MakooIssue`
418
+ type ActionEvent = `${Action}`;
419
+ ```
261
420
 
262
- ## Public Exports Overview
421
+ ### `OBSERVE_EVENT_NAMES`
263
422
 
264
- | Category | Representative exports |
423
+ ```ts
424
+ const OBSERVE_EVENT_NAMES = [
425
+ 'register:start',
426
+ 'register:success',
427
+ 'register:duplicate',
428
+ 'register:error',
429
+ 'start:requested',
430
+ 'start:taskScheduled',
431
+ 'start:taskSkipped',
432
+ 'artifact:mountStart',
433
+ 'artifact:mountSuccess',
434
+ 'artifact:mountFail',
435
+ 'listener:attached',
436
+ 'listener:detached',
437
+ 'listener:attachFail',
438
+ 'alive:enabled',
439
+ 'alive:disabled',
440
+ 'alive:observerStarted',
441
+ 'alive:observerStopped',
442
+ 'task:targetReady',
443
+ 'task:statusChange',
444
+ 'task:beforeReset',
445
+ 'task:afterReset',
446
+ 'task:beforeDestroy',
447
+ 'task:afterDestroy',
448
+ 'signal:watcherReleased',
449
+ 'resource:listenerReleased',
450
+ 'artifact:unmounted',
451
+ 'dom:targetFound',
452
+ 'dom:targetTimeout',
453
+ 'dom:targetRemoved',
454
+ 'dom:targetRestored'
455
+ ] as const;
456
+ ```
457
+
458
+ ### `ErrorCode`
459
+
460
+ | Field | Value |
265
461
  | --- | --- |
266
- | Runtime API | `createMakoo`, `inject`, `listen`, `MakooRuntime`, `StartedTasks` |
267
- | Adapter protocol | `MountAdapter`, `ResolvableMountAdapter`, `AdapterMountInput`, `AdapterUnmountInput`, `MakooContext` |
268
- | Lifecycle observation | `ObserverHub`, `OBSERVE_EVENT_NAMES`, `ObserveEvent`, `ObserveHook`, `LifecycleHookMap` |
269
- | DOM observation | `DOMWatcher` |
270
- | Listener signal | `createActivityStore`, `ActivitySignalSource` |
271
- | Logging | `Logger`, `ILogger`, `LoggerLevel` |
272
- | Errors | `MakooError`, `AdapterError`, `TaskError`, `ErrorCode` |
462
+ | `UNKNOWN` | `MAKOO_UNKNOWN` |
463
+ | `ADAPTER_NOT_FOUND` | `MAKOO_ADAPTER_NOT_FOUND` |
464
+ | `ADAPTER_MOUNT_FAIL` | `MAKOO_ADAPTER_MOUNT_FAIL` |
465
+ | `ADAPTER_UNMOUNT_FAIL` | `MAKOO_ADAPTER_UNMOUNT_FAIL` |
466
+ | `TASK_NO_REGISTERED` | `MAKOO_TASK_NO_REGISTERED` |
467
+ | `TASK_NOT_FOUND` | `MAKOO_TASK_NOT_FOUND` |
468
+ | `TASK_INJECT_FAIL` | `MAKOO_TASK_INJECT_FAIL` |
469
+ | `TASK_ALREADY_MOUNTED` | `MAKOO_TASK_ALREADY_MOUNTED` |
470
+ | `TASK_TARGET_DETACHED` | `MAKOO_TASK_TARGET_DETACHED` |
471
+ | `TASK_LISTENER_ATTACH_FAIL` | `MAKOO_TASK_LISTENER_ATTACH_FAIL` |
472
+ | `TASK_SIGNAL_INVALID` | `MAKOO_TASK_SIGNAL_INVALID` |
473
+ | `TASK_SIGNAL_BIND_FAIL` | `MAKOO_TASK_SIGNAL_BIND_FAIL` |
474
+ | `CLI_SOURCE_DIR_NOT_FOUND` | `MAKOO_CLI_SOURCE_DIR_NOT_FOUND` |
475
+ | `CLI_MANIFEST_LOAD_FAIL` | `MAKOO_CLI_MANIFEST_LOAD_FAIL` |
476
+ | `CLI_MODULE_MANIFEST_LOAD_FAIL` | `MAKOO_CLI_MODULE_MANIFEST_LOAD_FAIL` |
477
+ | `CLI_MANIFEST_NOT_FOUND` | `MAKOO_CLI_MANIFEST_NOT_FOUND` |
478
+ | `CLI_MANIFEST_BINDING_NOT_FOUND` | `MAKOO_CLI_MANIFEST_BINDING_NOT_FOUND` |
479
+ | `CLI_MANIFEST_IMPORT_NOT_FOUND` | `MAKOO_CLI_MANIFEST_IMPORT_NOT_FOUND` |
480
+ | `CLI_FUNCTION_SERIALIZATION_UNSUPPORTED` | `MAKOO_CLI_FUNCTION_SERIALIZATION_UNSUPPORTED` |
481
+ | `CLI_NO_ENABLED_TASKS` | `MAKOO_CLI_NO_ENABLED_TASKS` |
482
+ | `CLI_COMPONENT_NOT_FOUND` | `MAKOO_CLI_COMPONENT_NOT_FOUND` |
483
+ | `CLI_CONFIG_INVALID` | `MAKOO_CLI_CONFIG_INVALID` |
484
+ | `CLI_UNKNOWN_FRAMEWORK` | `MAKOO_CLI_UNKNOWN_FRAMEWORK` |
485
+ | `CLI_UNSUPPORTED_FRAMEWORK` | `MAKOO_CLI_UNSUPPORTED_FRAMEWORK` |
486
+ | `CLI_MODULE_ALREADY_EXISTS` | `MAKOO_CLI_MODULE_ALREADY_EXISTS` |
487
+ | `CLI_MANIFEST_VALIDATION_FAIL` | `MAKOO_CLI_MANIFEST_VALIDATION_FAIL` |
488
+ | `CLI_VITE_CONFIG_NOT_FOUND` | `MAKOO_CLI_VITE_CONFIG_NOT_FOUND` |
489
+ | `CLI_PLUGIN_NOT_FOUND` | `MAKOO_CLI_PLUGIN_NOT_FOUND` |
490
+ | `CLI_RUNTIME_SETUP_NOT_FOUND` | `MAKOO_CLI_RUNTIME_SETUP_NOT_FOUND` |
491
+
492
+ ## Adapter types
493
+
494
+ ### `MountAdapter`
495
+
496
+ ```ts
497
+ interface MountAdapter<TArtifact = unknown, THandle = unknown, TInstance = unknown> {
498
+ name: string;
499
+ mount(input: AdapterMountInput<TArtifact>): AdapterMountResult<THandle, TInstance>;
500
+ unmount(input: AdapterUnmountInput<THandle>): void;
501
+ }
502
+ ```
503
+
504
+ ### `ResolvableMountAdapter`
505
+
506
+ ```ts
507
+ interface ResolvableMountAdapter<TArtifact = unknown, THandle = unknown, TInstance = unknown>
508
+ extends MountAdapter<TArtifact, THandle, TInstance> {
509
+ matches(artifact: unknown): artifact is TArtifact;
510
+ }
511
+ ```
512
+
513
+ ### `AdapterMountInput`
514
+
515
+ | Field | Type |
516
+ | --- | --- |
517
+ | `host` | `HTMLElement` |
518
+ | `mountPoint` | `HTMLElement` |
519
+ | `artifact` | `TArtifact` |
520
+ | `taskId` | `string` |
521
+ | `injectAt` | `string` |
522
+ | `makoo` | `MakooContext` |
523
+
524
+ ### `AdapterMountResult`
525
+
526
+ ```ts
527
+ type AdapterMountResult<THandle = unknown, TInstance = unknown> = {
528
+ handle: THandle;
529
+ instance?: TInstance;
530
+ };
531
+ ```
532
+
533
+ ### `AdapterUnmountInput`
534
+
535
+ | Field | Type |
536
+ | --- | --- |
537
+ | `host` | `HTMLElement \| undefined` |
538
+ | `mountPoint` | `HTMLElement` |
539
+ | `handle` | `THandle` |
540
+ | `taskId` | `string` |
541
+ | `injectAt` | `string` |
542
+ | `reason` | `AdapterUnmountReason` |
543
+
544
+ ```ts
545
+ type AdapterUnmountReason = 'destroy' | 'reset' | 'remount' | 'manual';
546
+ type AdapterResolver = (artifact: unknown) => MountAdapter | undefined;
547
+ ```
548
+
549
+ ### `MakooContext`
550
+
551
+ ```ts
552
+ type MakooContext = {
553
+ taskId: string;
554
+ injectAt: string;
555
+ enableAlive(): void;
556
+ disableAlive(): void;
557
+ reset(): void;
558
+ destroy(): void;
559
+ on(event: ObserveEventName, hook: ObserveHook): () => void;
560
+ onTask(event: ObserveEventName, hook: ObserveHook): () => void;
561
+ off(event: ObserveEventName, hook?: ObserveHook): void;
562
+ offTask(event?: ObserveEventName, hook?: ObserveHook): void;
563
+ getLogger(): ILogger;
564
+ bindListenerSignal(source: ActivitySignalSource<boolean>): boolean;
565
+ controlListener(event: ActionEvent): boolean;
566
+ };
567
+ ```
568
+
569
+ ## Task types
570
+
571
+ ```ts
572
+ type MakooDefaults = {
573
+ alive: boolean;
574
+ scope: 'local' | 'global';
575
+ timeout: number;
576
+ };
577
+
578
+ type MakooInjectionDeclaration<TArtifact = unknown> = {
579
+ kind: 'component';
580
+ id?: string;
581
+ injectAt: string;
582
+ artifact: TArtifact;
583
+ options?: ArtifactOptions;
584
+ };
585
+
586
+ type MakooListenerDeclaration = {
587
+ kind: 'listener';
588
+ id?: string;
589
+ listenAt: string;
590
+ event: string;
591
+ type: string;
592
+ callback: EventListener;
593
+ activitySignal?: () => ActivitySignalSource<boolean>;
594
+ };
595
+
596
+ type MakooTaskDeclaration<TArtifact = unknown> =
597
+ | MakooInjectionDeclaration<TArtifact>
598
+ | MakooListenerDeclaration;
599
+ ```
600
+
601
+ ### `StartedTasks`
602
+
603
+ ```ts
604
+ type StartedComponentTask = {
605
+ kind: 'component';
606
+ taskId: string;
607
+ enableAlive(): void;
608
+ disableAlive(): void;
609
+ reset(): void;
610
+ destroy(): void;
611
+ };
612
+
613
+ type StartedListenerTask = {
614
+ kind: 'listener';
615
+ taskId: string;
616
+ open(): boolean;
617
+ close(): boolean;
618
+ destroy(): void;
619
+ };
620
+
621
+ type StartedTask = StartedComponentTask | StartedListenerTask;
622
+
623
+ type StartedTasks = {
624
+ tasks: StartedTask[];
625
+ get(taskId: string): StartedTask | undefined;
626
+ resetAll(): void;
627
+ destroyAll(): void;
628
+ };
629
+ ```
630
+
631
+ `StartedTasks.resetAll()` and `StartedTasks.destroyAll()` only affect the task batch returned by that `start()` call.
632
+
633
+ ### `InjectionConfig`
634
+
635
+ ```ts
636
+ type InjectionConfig = MakooDefaults & {
637
+ logger: ILogger;
638
+ observer?: ObserverHub;
639
+ hooks?: LifecycleHookMap;
640
+ };
641
+ ```
642
+
643
+ ## Observer types
644
+
645
+ ```ts
646
+ type ObserveEventName = (typeof OBSERVE_EVENT_NAMES)[number];
647
+
648
+ type ObserveEvent = {
649
+ name: ObserveEventName;
650
+ ts: number;
651
+ taskId?: string;
652
+ kind?: 'component' | 'listener';
653
+ injectAt?: string;
654
+ status?: 'idle' | 'pending' | 'active';
655
+ durationMs?: number;
656
+ error?: unknown;
657
+ preStatus?: 'idle' | 'pending' | 'active';
658
+ meta?: Record<string, unknown>;
659
+ };
660
+
661
+ type ObserveHook = (
662
+ event: ObserveEvent,
663
+ ctrl: {
664
+ stopPropagation(): void;
665
+ stopImmediatePropagation(): void;
666
+ }
667
+ ) => void;
668
+
669
+ type LifecycleHookMap = Partial<
670
+ Record<ObserveEventName, ObserveHook | ObserveHook[]>
671
+ >;
672
+ ```
673
+
674
+ ## Signal types
675
+
676
+ ```ts
677
+ type SignalUnsubscribe = (() => void) | { unsubscribe(): void };
678
+
679
+ type ActivitySignalSource<T = boolean> = {
680
+ get(): T;
681
+ subscribe(listener: (value: T) => void): SignalUnsubscribe;
682
+ };
683
+
684
+ type ActivitySignalSubscribable<T = boolean> = ActivitySignalSource<T>;
685
+ ```
686
+
687
+ ## Logger types
688
+
689
+ ```ts
690
+ type LoggerLevel = 'debug' | 'info' | 'warn' | 'error';
691
+
692
+ interface ILogger {
693
+ info(message: string, ...args: unknown[]): void;
694
+ warn(message: string, ...args: unknown[]): void;
695
+ error(message: string, ...args: unknown[]): void;
696
+ debug(message: string, ...args: unknown[]): void;
697
+ }
698
+ ```
699
+
700
+ ## Error types
701
+
702
+ ```ts
703
+ type MakooIssue = {
704
+ path: string;
705
+ message: string;
706
+ };
707
+
708
+ type ErrorCodeValue = (typeof ErrorCode)[keyof typeof ErrorCode];
709
+ ```