@cosystem/devtools 0.0.2 → 1.0.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/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionEvent, App, ErrorContext, PatchEvent, Plugin, StateChangeEvent } from "@cosystem/core";
|
|
1
|
+
import { ActionEvent, App, ErrorContext, ModuleCreatedEvent, PatchEvent, Plugin, StateChangeEvent } from "@cosystem/core";
|
|
2
2
|
|
|
3
3
|
//#region src/index.d.ts
|
|
4
4
|
type DevtoolsTimelineEvent = {
|
|
@@ -9,6 +9,10 @@ type DevtoolsTimelineEvent = {
|
|
|
9
9
|
readonly type: "action:start" | "action:end";
|
|
10
10
|
readonly event: ActionEvent;
|
|
11
11
|
readonly time: number;
|
|
12
|
+
} | {
|
|
13
|
+
readonly type: "module";
|
|
14
|
+
readonly event: ModuleCreatedEvent;
|
|
15
|
+
readonly time: number;
|
|
12
16
|
} | {
|
|
13
17
|
readonly type: "patch";
|
|
14
18
|
readonly event: PatchEvent;
|
|
@@ -25,13 +29,15 @@ type DevtoolsTimelineEvent = {
|
|
|
25
29
|
};
|
|
26
30
|
interface DevtoolsPlugin extends Plugin {
|
|
27
31
|
getTimeline(): readonly DevtoolsTimelineEvent[];
|
|
32
|
+
subscribe(listener: DevtoolsTimelineListener): () => void;
|
|
28
33
|
clearTimeline(): void;
|
|
29
34
|
}
|
|
35
|
+
type DevtoolsTimelineListener = (event: DevtoolsTimelineEvent) => void;
|
|
30
36
|
interface DevtoolsOptions {
|
|
31
37
|
readonly maxEvents?: number;
|
|
32
38
|
readonly now?: () => number;
|
|
33
39
|
}
|
|
34
40
|
declare function createDevtoolsPlugin(options?: DevtoolsOptions): DevtoolsPlugin;
|
|
35
41
|
//#endregion
|
|
36
|
-
export { DevtoolsOptions, DevtoolsPlugin, DevtoolsTimelineEvent, createDevtoolsPlugin };
|
|
42
|
+
export { DevtoolsOptions, DevtoolsPlugin, DevtoolsTimelineEvent, DevtoolsTimelineListener, createDevtoolsPlugin };
|
|
37
43
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;
|
|
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
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
//#region src/index.ts
|
|
2
2
|
function createDevtoolsPlugin(options = {}) {
|
|
3
3
|
const timeline = [];
|
|
4
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
4
5
|
const maxEvents = options.maxEvents ?? 1e3;
|
|
5
6
|
const now = options.now ?? Date.now;
|
|
6
7
|
const push = (event) => {
|
|
7
8
|
timeline.push(event);
|
|
8
9
|
if (timeline.length > maxEvents) timeline.splice(0, timeline.length - maxEvents);
|
|
10
|
+
for (const listener of listeners) listener(event);
|
|
9
11
|
};
|
|
10
12
|
return {
|
|
11
13
|
name: "cosystem:devtools",
|
|
@@ -15,6 +17,12 @@ function createDevtoolsPlugin(options = {}) {
|
|
|
15
17
|
getTimeline() {
|
|
16
18
|
return timeline;
|
|
17
19
|
},
|
|
20
|
+
subscribe(listener) {
|
|
21
|
+
listeners.add(listener);
|
|
22
|
+
return () => {
|
|
23
|
+
listeners.delete(listener);
|
|
24
|
+
};
|
|
25
|
+
},
|
|
18
26
|
onActionEnd(event) {
|
|
19
27
|
push({
|
|
20
28
|
event,
|
|
@@ -37,6 +45,13 @@ function createDevtoolsPlugin(options = {}) {
|
|
|
37
45
|
type: "error"
|
|
38
46
|
});
|
|
39
47
|
},
|
|
48
|
+
onModuleCreated(event) {
|
|
49
|
+
push({
|
|
50
|
+
event,
|
|
51
|
+
time: now(),
|
|
52
|
+
type: "module"
|
|
53
|
+
});
|
|
54
|
+
},
|
|
40
55
|
onPatch(event) {
|
|
41
56
|
push({
|
|
42
57
|
event,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type {\n ActionEvent,\n App,\n ErrorContext,\n PatchEvent,\n Plugin,\n StateChangeEvent,\n} from \"@cosystem/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: \"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 clearTimeline(): void;\n}\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 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\n return {\n name: \"cosystem:devtools\",\n clearTimeline() {\n timeline.length = 0;\n },\n getTimeline() {\n return timeline;\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 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"],"mappings":";
|
|
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 \"@cosystem/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 listener(event);\n }\n };\n\n return {\n name: \"cosystem: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"],"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,SAAS,KAAK;CAElB;CAEA,OAAO;EACL,MAAM;EACN,gBAAgB;GACd,SAAS,SAAS;EACpB;EACA,cAAc;GACZ,OAAO;EACT;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"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosystem/devtools",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Dev inspection plugin for CoSystem.",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/coactionjs/cosystem.git",
|
|
9
|
+
"directory": "packages/devtools"
|
|
10
|
+
},
|
|
6
11
|
"files": [
|
|
7
12
|
"dist"
|
|
8
13
|
],
|
|
@@ -20,7 +25,7 @@
|
|
|
20
25
|
"access": "public"
|
|
21
26
|
},
|
|
22
27
|
"dependencies": {
|
|
23
|
-
"@cosystem/core": "0.0
|
|
28
|
+
"@cosystem/core": "1.0.0"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
31
|
"tsdown": "0.22.3",
|