@coexist/devtools 0.2.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/LICENSE +21 -0
- package/README.md +68 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Coaction
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @coexist/devtools
|
|
2
|
+
|
|
3
|
+
> Timeline inspection plugin for [Coexist](../../README.md): records a chronological log of app setup, module creation, actions, patches, state changes, and errors for development tooling.
|
|
4
|
+
|
|
5
|
+
This is a headless data source — it records events and lets you subscribe to or read the timeline. Build your own UI on top, or pipe it into logging.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add -D @coexist/devtools
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createApp } from "@coexist/core";
|
|
17
|
+
import { createDevtoolsPlugin } from "@coexist/devtools";
|
|
18
|
+
|
|
19
|
+
const devtools = createDevtoolsPlugin();
|
|
20
|
+
|
|
21
|
+
const app = createApp({
|
|
22
|
+
plugins: [devtools],
|
|
23
|
+
providers: [Counter],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const unsubscribe = devtools.subscribe((event) => {
|
|
27
|
+
console.log(event.type, event.time);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log(devtools.getTimeline());
|
|
31
|
+
unsubscribe();
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Options
|
|
35
|
+
|
|
36
|
+
| Option | Type | Default | Description |
|
|
37
|
+
| ----------- | -------------- | ---------- | ------------------------------------------------------ |
|
|
38
|
+
| `maxEvents` | `number` | `1000` | Ring-buffer size; oldest events are dropped past this. |
|
|
39
|
+
| `now` | `() => number` | `Date.now` | Clock used for the `time` stamp on every event. |
|
|
40
|
+
|
|
41
|
+
## Timeline events
|
|
42
|
+
|
|
43
|
+
Each entry is a `DevtoolsTimelineEvent` with a `type` and a `time`:
|
|
44
|
+
|
|
45
|
+
| `type` | Payload |
|
|
46
|
+
| --------------------------------- | ------------------------------- |
|
|
47
|
+
| `"setup"` | `{ app }` |
|
|
48
|
+
| `"module"` | `{ event: ModuleCreatedEvent }` |
|
|
49
|
+
| `"action:start"` / `"action:end"` | `{ event: ActionEvent }` |
|
|
50
|
+
| `"patch"` | `{ event: PatchEvent }` |
|
|
51
|
+
| `"state"` | `{ event: StateChangeEvent }` |
|
|
52
|
+
| `"error"` | `{ error, context }` |
|
|
53
|
+
|
|
54
|
+
## Plugin methods
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
devtools.getTimeline(); // readonly snapshot of recorded events
|
|
58
|
+
devtools.subscribe(listener); // → unsubscribe; fires on each new event
|
|
59
|
+
devtools.clearTimeline(); // reset the buffer
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Exports
|
|
63
|
+
|
|
64
|
+
`createDevtoolsPlugin`, and the `DevtoolsPlugin`, `DevtoolsOptions`, `DevtoolsTimelineEvent`, `DevtoolsTimelineListener` types.
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
[MIT](../../LICENSE) © Coaction
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ActionEvent, App, ErrorContext, ModuleCreatedEvent, PatchEvent, Plugin, StateChangeEvent } from "@coexist/core";
|
|
2
|
+
|
|
3
|
+
//#region src/index.d.ts
|
|
4
|
+
type DevtoolsTimelineEvent = {
|
|
5
|
+
readonly type: "setup";
|
|
6
|
+
readonly app: App;
|
|
7
|
+
readonly time: number;
|
|
8
|
+
} | {
|
|
9
|
+
readonly type: "action:start" | "action:end";
|
|
10
|
+
readonly event: ActionEvent;
|
|
11
|
+
readonly time: number;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "module";
|
|
14
|
+
readonly event: ModuleCreatedEvent;
|
|
15
|
+
readonly time: number;
|
|
16
|
+
} | {
|
|
17
|
+
readonly type: "patch";
|
|
18
|
+
readonly event: PatchEvent;
|
|
19
|
+
readonly time: number;
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "state";
|
|
22
|
+
readonly event: StateChangeEvent;
|
|
23
|
+
readonly time: number;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "error";
|
|
26
|
+
readonly error: unknown;
|
|
27
|
+
readonly context: ErrorContext;
|
|
28
|
+
readonly time: number;
|
|
29
|
+
};
|
|
30
|
+
interface DevtoolsPlugin extends Plugin {
|
|
31
|
+
getTimeline(): readonly DevtoolsTimelineEvent[];
|
|
32
|
+
subscribe(listener: DevtoolsTimelineListener): () => void;
|
|
33
|
+
clearTimeline(): void;
|
|
34
|
+
}
|
|
35
|
+
type DevtoolsTimelineListener = (event: DevtoolsTimelineEvent) => void;
|
|
36
|
+
interface DevtoolsOptions {
|
|
37
|
+
readonly maxEvents?: number;
|
|
38
|
+
readonly now?: () => number;
|
|
39
|
+
}
|
|
40
|
+
declare function createDevtoolsPlugin(options?: DevtoolsOptions): DevtoolsPlugin;
|
|
41
|
+
//#endregion
|
|
42
|
+
export { DevtoolsOptions, DevtoolsPlugin, DevtoolsTimelineEvent, DevtoolsTimelineListener, createDevtoolsPlugin };
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;KAUY,qBAAA;EAAA,SAEG,IAAA;EAAA,SACA,GAAA,EAAK,GAAA;EAAA,SACL,IAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,KAAA,EAAO,WAAA;EAAA,SACP,IAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,KAAA,EAAO,kBAAA;EAAA,SACP,IAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,KAAA,EAAO,UAAA;EAAA,SACP,IAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,KAAA,EAAO,gBAAA;EAAA,SACP,IAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,KAAA;EAAA,SACA,OAAA,EAAS,YAAA;EAAA,SACT,IAAA;AAAA;AAAA,UAGE,cAAA,SAAuB,MAAA;EACtC,WAAA,aAAwB,qBAAA;EACxB,SAAA,CAAU,QAAA,EAAU,wBAAA;EACpB,aAAA;AAAA;AAAA,KAGU,wBAAA,IAA4B,KAAO,EAAA,qBAAA;AAAA,UAE9B,eAAA;EAAA,SACN,SAAA;EAAA,SACA,GAAA;AAAA;AAAA,iBAGK,oBAAA,CAAqB,OAAA,GAAS,eAAA,GAAuB,cAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
//#region src/index.ts
|
|
2
|
+
function createDevtoolsPlugin(options = {}) {
|
|
3
|
+
const timeline = [];
|
|
4
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
5
|
+
const maxEvents = options.maxEvents ?? 1e3;
|
|
6
|
+
const now = options.now ?? Date.now;
|
|
7
|
+
const push = (event) => {
|
|
8
|
+
timeline.push(event);
|
|
9
|
+
if (timeline.length > maxEvents) timeline.splice(0, timeline.length - maxEvents);
|
|
10
|
+
for (const listener of listeners) try {
|
|
11
|
+
const result = listener(event);
|
|
12
|
+
if (isPromiseLike(result)) Promise.resolve(result).catch(() => void 0);
|
|
13
|
+
} catch {}
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
name: "coexist:devtools",
|
|
17
|
+
clearTimeline() {
|
|
18
|
+
timeline.length = 0;
|
|
19
|
+
},
|
|
20
|
+
getTimeline() {
|
|
21
|
+
return [...timeline];
|
|
22
|
+
},
|
|
23
|
+
subscribe(listener) {
|
|
24
|
+
listeners.add(listener);
|
|
25
|
+
return () => {
|
|
26
|
+
listeners.delete(listener);
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
onActionEnd(event) {
|
|
30
|
+
push({
|
|
31
|
+
event,
|
|
32
|
+
time: now(),
|
|
33
|
+
type: "action:end"
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
onActionStart(event) {
|
|
37
|
+
push({
|
|
38
|
+
event,
|
|
39
|
+
time: now(),
|
|
40
|
+
type: "action:start"
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
onError(error, context) {
|
|
44
|
+
push({
|
|
45
|
+
context,
|
|
46
|
+
error,
|
|
47
|
+
time: now(),
|
|
48
|
+
type: "error"
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
onModuleCreated(event) {
|
|
52
|
+
push({
|
|
53
|
+
event,
|
|
54
|
+
time: now(),
|
|
55
|
+
type: "module"
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
onPatch(event) {
|
|
59
|
+
push({
|
|
60
|
+
event,
|
|
61
|
+
time: now(),
|
|
62
|
+
type: "patch"
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
onStateChange(event) {
|
|
66
|
+
push({
|
|
67
|
+
event,
|
|
68
|
+
time: now(),
|
|
69
|
+
type: "state"
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
setup(app) {
|
|
73
|
+
push({
|
|
74
|
+
app,
|
|
75
|
+
time: now(),
|
|
76
|
+
type: "setup"
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function isPromiseLike(value) {
|
|
82
|
+
return (typeof value === "object" || typeof value === "function") && value !== null && "then" in value && typeof value.then === "function";
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { createDevtoolsPlugin };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n ActionEvent,\n App,\n ErrorContext,\n ModuleCreatedEvent,\n PatchEvent,\n Plugin,\n StateChangeEvent,\n} from \"@coexist/core\";\n\nexport type DevtoolsTimelineEvent =\n | {\n readonly type: \"setup\";\n readonly app: App;\n readonly time: number;\n }\n | {\n readonly type: \"action:start\" | \"action:end\";\n readonly event: ActionEvent;\n readonly time: number;\n }\n | {\n readonly type: \"module\";\n readonly event: ModuleCreatedEvent;\n readonly time: number;\n }\n | {\n readonly type: \"patch\";\n readonly event: PatchEvent;\n readonly time: number;\n }\n | {\n readonly type: \"state\";\n readonly event: StateChangeEvent;\n readonly time: number;\n }\n | {\n readonly type: \"error\";\n readonly error: unknown;\n readonly context: ErrorContext;\n readonly time: number;\n };\n\nexport interface DevtoolsPlugin extends Plugin {\n getTimeline(): readonly DevtoolsTimelineEvent[];\n subscribe(listener: DevtoolsTimelineListener): () => void;\n clearTimeline(): void;\n}\n\nexport type DevtoolsTimelineListener = (event: DevtoolsTimelineEvent) => void;\n\nexport interface DevtoolsOptions {\n readonly maxEvents?: number;\n readonly now?: () => number;\n}\n\nexport function createDevtoolsPlugin(options: DevtoolsOptions = {}): DevtoolsPlugin {\n const timeline: DevtoolsTimelineEvent[] = [];\n const listeners = new Set<DevtoolsTimelineListener>();\n const maxEvents = options.maxEvents ?? 1_000;\n const now = options.now ?? Date.now;\n\n const push = (event: DevtoolsTimelineEvent): void => {\n timeline.push(event);\n\n if (timeline.length > maxEvents) {\n timeline.splice(0, timeline.length - maxEvents);\n }\n\n for (const listener of listeners) {\n try {\n const result = (listener as (event: DevtoolsTimelineEvent) => unknown)(event);\n\n if (isPromiseLike(result)) {\n void Promise.resolve(result).catch(() => undefined);\n }\n } catch {\n // Timeline observers must not interrupt app hooks or later subscribers.\n }\n }\n };\n\n return {\n name: \"coexist:devtools\",\n clearTimeline() {\n timeline.length = 0;\n },\n getTimeline() {\n return [...timeline];\n },\n subscribe(listener) {\n listeners.add(listener);\n\n return () => {\n listeners.delete(listener);\n };\n },\n onActionEnd(event) {\n push({\n event,\n time: now(),\n type: \"action:end\",\n });\n },\n onActionStart(event) {\n push({\n event,\n time: now(),\n type: \"action:start\",\n });\n },\n onError(error, context) {\n push({\n context,\n error,\n time: now(),\n type: \"error\",\n });\n },\n onModuleCreated(event) {\n push({\n event,\n time: now(),\n type: \"module\",\n });\n },\n onPatch(event) {\n push({\n event,\n time: now(),\n type: \"patch\",\n });\n },\n onStateChange(event) {\n push({\n event,\n time: now(),\n type: \"state\",\n });\n },\n setup(app) {\n push({\n app,\n time: now(),\n type: \"setup\",\n });\n },\n };\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return (\n (typeof value === \"object\" || typeof value === \"function\") &&\n value !== null &&\n \"then\" in value &&\n typeof value.then === \"function\"\n );\n}\n"],"mappings":";AAwDA,SAAgB,qBAAqB,UAA2B,CAAC,GAAmB;CAClF,MAAM,WAAoC,CAAC;CAC3C,MAAM,4BAAY,IAAI,IAA8B;CACpD,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,MAAM,QAAQ,OAAO,KAAK;CAEhC,MAAM,QAAQ,UAAuC;EACnD,SAAS,KAAK,KAAK;EAEnB,IAAI,SAAS,SAAS,WACpB,SAAS,OAAO,GAAG,SAAS,SAAS,SAAS;EAGhD,KAAK,MAAM,YAAY,WACrB,IAAI;GACF,MAAM,SAAU,SAAuD,KAAK;GAE5E,IAAI,cAAc,MAAM,GACtB,QAAa,QAAQ,MAAM,CAAC,CAAC,YAAY,KAAA,CAAS;EAEtD,QAAQ,CAER;CAEJ;CAEA,OAAO;EACL,MAAM;EACN,gBAAgB;GACd,SAAS,SAAS;EACpB;EACA,cAAc;GACZ,OAAO,CAAC,GAAG,QAAQ;EACrB;EACA,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GAEtB,aAAa;IACX,UAAU,OAAO,QAAQ;GAC3B;EACF;EACA,YAAY,OAAO;GACjB,KAAK;IACH;IACA,MAAM,IAAI;IACV,MAAM;GACR,CAAC;EACH;EACA,cAAc,OAAO;GACnB,KAAK;IACH;IACA,MAAM,IAAI;IACV,MAAM;GACR,CAAC;EACH;EACA,QAAQ,OAAO,SAAS;GACtB,KAAK;IACH;IACA;IACA,MAAM,IAAI;IACV,MAAM;GACR,CAAC;EACH;EACA,gBAAgB,OAAO;GACrB,KAAK;IACH;IACA,MAAM,IAAI;IACV,MAAM;GACR,CAAC;EACH;EACA,QAAQ,OAAO;GACb,KAAK;IACH;IACA,MAAM,IAAI;IACV,MAAM;GACR,CAAC;EACH;EACA,cAAc,OAAO;GACnB,KAAK;IACH;IACA,MAAM,IAAI;IACV,MAAM;GACR,CAAC;EACH;EACA,MAAM,KAAK;GACT,KAAK;IACH;IACA,MAAM,IAAI;IACV,MAAM;GACR,CAAC;EACH;CACF;AACF;AAEA,SAAS,cAAc,OAA+C;CACpE,QACG,OAAO,UAAU,YAAY,OAAO,UAAU,eAC/C,UAAU,QACV,UAAU,SACV,OAAO,MAAM,SAAS;AAE1B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coexist/devtools",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Dev inspection plugin for Coexist.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/coactionjs/coexist.git",
|
|
9
|
+
"directory": "packages/devtools"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"module": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@coexist/core": "0.2.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"tsdown": "0.22.3",
|
|
32
|
+
"typescript": "6.0.3",
|
|
33
|
+
"vitest": "4.1.9",
|
|
34
|
+
"@coexist/tsconfig": "0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsdown",
|
|
38
|
+
"clean": "rm -rf coverage dist .turbo",
|
|
39
|
+
"dev": "tsdown --watch",
|
|
40
|
+
"test": "cd ../.. && vitest run --project @coexist/devtools",
|
|
41
|
+
"test:coverage": "cd ../.. && vitest run --coverage --project @coexist/devtools",
|
|
42
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
43
|
+
}
|
|
44
|
+
}
|