Compare commits

...

6 Commits

Author SHA1 Message Date
0ba82716dc 设计tracer 2025-11-13 20:48:49 +08:00
e34e2389f8 设计tracer 2025-11-13 20:46:41 +08:00
7033208b06 设计tracer 2025-11-13 20:41:25 +08:00
0ade49a589 设计tracer 2025-11-10 22:39:27 +08:00
8f5493eaf0 设计tracer 2025-11-10 02:49:58 +08:00
9c99af4781 设计tracer 2025-11-10 02:44:50 +08:00
21 changed files with 173 additions and 136 deletions

View File

@@ -1,29 +0,0 @@
{
"lockfileVersion": 1,
"workspaces": {
"": {
"name": "structrail-design",
"devDependencies": {
"@types/bun": "latest",
},
"peerDependencies": {
"typescript": "^5",
},
},
},
"packages": {
"@types/bun": ["@types/bun@1.2.23", "", { "dependencies": { "bun-types": "1.2.23" } }, "sha512-le8ueOY5b6VKYf19xT3McVbXqLqmxzPXHsQT/q9JHgikJ2X22wyTW3g3ohz2ZMnp7dod6aduIiq8A14Xyimm0A=="],
"@types/node": ["@types/node@24.7.1", "", { "dependencies": { "undici-types": "~7.14.0" } }, "sha512-CmyhGZanP88uuC5GpWU9q+fI61j2SkhO3UGMUdfYRE6Bcy0ccyzn1Rqj9YAB/ZY4kOXmNf0ocah5GtphmLMP6Q=="],
"@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
"bun-types": ["bun-types@1.2.23", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-R9f0hKAZXgFU3mlrA0YpE/fiDvwV0FT9rORApt2aQVWSuJDzZOyB5QLc0N/4HF57CS8IXJ6+L5E4W1bW6NS2Aw=="],
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
"undici-types": ["undici-types@7.14.0", "", {}, "sha512-QQiYxHuyZ9gQUIrmPo3IA+hUl4KYk8uSA7cHrcKd/l3p1OTpZcM0Tbp9x7FAtXdAYhlasd60ncPpgu6ihG6TOA=="],
}
}

View File

@@ -1,12 +0,0 @@
import { Commander } from "./tracers.ts/commander";
import { ArrayTracer } from "./tracers.ts/tracers";
const arrayTracer = ArrayTracer.define<number>({
description: "Array Tracer",
});
arrayTracer.preset([1, 2, 3]);
const commander = Commander.getInstance();
const commands = commander.output();
console.log(commands);

View File

@@ -1,55 +0,0 @@
import { Commander } from "../commander";
import { Registry } from "../registry";
export interface ArrayTracerOption<T> {
description: string;
serializeFn?: (value: T) => string;
}
export class ArrayTracer<T> {
private tracerId: string;
private serializeFn?: (value: T) => string;
private constructor(option: ArrayTracerOption<T>) {
this.tracerId = crypto.randomUUID();
this.serializeFn = option.serializeFn;
}
public static define<T>(option: ArrayTracerOption<T>): ArrayTracer<T> {
const arrayTracer = new ArrayTracer(option);
const registry = Registry.getInstance();
registry.register("ArrayTracer", arrayTracer.tracerId);
const commander = Commander.getInstance();
commander.command({
tracer: null,
action: "define",
params: {
type: "ArrayTracer",
id: arrayTracer.tracerId,
desc: option.description,
},
});
return arrayTracer;
}
public preset(array: T[]) {
const commander = Commander.getInstance();
commander.command({
tracer: this.tracerId,
action: "preset",
params: array,
});
}
public expand(size: number) {}
public reduce(size: number) {}
public pick(index: number) {}
public drop(index: number) {}
public patch(index: number, value: T) {}
public reset(index: number) {}
}

View File

@@ -1 +0,0 @@
export * from "./array-tracer";

View File

@@ -1,5 +0,0 @@
import type { ArrayTracerCommand } from "../command";
export type ArrayTracerAction = ArrayTracerCommand["action"];
export type TracerAction = ArrayTracerAction;

View File

@@ -1,5 +0,0 @@
import type { ArrayTracerCommand } from "./array-tracer-command";
export * from "./array-tracer-command";
export type TracerCommand = ArrayTracerCommand

View File

@@ -1,5 +0,0 @@
import type { ArrayTracerDefineCommand } from "../command";
type ArrayTracer = ArrayTracerDefineCommand["params"]["type"];
export type TracerType = ArrayTracer;

View File

View File

@@ -1,4 +1,4 @@
# structrail-design
# tracers.ts
To install dependencies:

29
tracers.ts/bun.lock Normal file
View File

@@ -0,0 +1,29 @@
{
"lockfileVersion": 1,
"workspaces": {
"": {
"name": "tracers.ts",
"devDependencies": {
"@types/bun": "latest",
},
"peerDependencies": {
"typescript": "^5",
},
},
},
"packages": {
"@types/bun": ["@types/bun@1.3.2", "", { "dependencies": { "bun-types": "1.3.2" } }, "sha512-t15P7k5UIgHKkxwnMNkJbWlh/617rkDGEdSsDbu+qNHTaz9SKf7aC8fiIlUdD5RPpH6GEkP0cK7WlvmrEBRtWg=="],
"@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="],
"@types/react": ["@types/react@19.2.4", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-tBFxBp9Nfyy5rsmefN+WXc1JeW/j2BpBHFdLZbEVfs9wn3E3NRFxwV0pJg8M1qQAexFpvz73hJXFofV0ZAu92A=="],
"bun-types": ["bun-types@1.3.2", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-i/Gln4tbzKNuxP70OWhJRZz1MRfvqExowP7U6JKoI8cntFrtxg7RJK3jvz7wQW54UuvNC8tbKHHri5fy74FVqg=="],
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
}
}

View File

@@ -1,5 +1,5 @@
{
"name": "structrail-design",
"name": "tracers.ts",
"module": "index.ts",
"type": "module",
"private": true,

View File

@@ -1,10 +1,10 @@
import type { TracerCommand } from "../types/command";
import type { TracerCommand } from '../types/command';
export class Commander {
private commands: TracerCommand[];
private commands: TracerCommand<unknown>[];
private constructor() {
this.commands = [];
this.commands = [];
}
private static instance: Commander | null = null;
@@ -16,11 +16,11 @@ export class Commander {
return this.instance;
}
public command(command: TracerCommand) {
public command<T = never>(command: TracerCommand<T>) {
this.commands.push(command);
}
public output() {
return this.commands;
return JSON.stringify(this.commands);
}
}

10
tracers.ts/src/index.ts Normal file
View File

@@ -0,0 +1,10 @@
import { Commander } from './commander';
import { ArrayTracer } from './tracer';
const arrayTracer = ArrayTracer.define<number>({ description: 'Array Tracer' });
arrayTracer.preset([1, 2, 3]);
const commander = Commander.getInstance();
const commands = commander.output();
console.log(commands);

View File

@@ -0,0 +1,94 @@
import { Commander } from '../commander';
import { Registry } from '../registry';
export interface ArrayTracerOption<T> {
description: string;
}
export class ArrayTracer<T> {
private tracerId: string;
private constructor() {
this.tracerId = crypto.randomUUID();
}
public static define<T>(option: ArrayTracerOption<T>): ArrayTracer<T> {
const arrayTracer = new ArrayTracer();
const registry = Registry.getInstance();
registry.register('ArrayTracer', arrayTracer.tracerId);
const commander = Commander.getInstance();
commander.command({
action: 'define',
tracer: null,
payload: {
type: 'ArrayTracer',
id: arrayTracer.tracerId,
desc: option.description,
},
});
return arrayTracer;
}
public preset(array: T[]) {
const commander = Commander.getInstance();
commander.command({
action: 'preset',
tracer: this.tracerId,
payload: array,
});
}
public extend(size: number) {
const commander = Commander.getInstance();
commander.command({
action: 'extend',
tracer: this.tracerId,
payload: { size },
});
}
public shrink(size: number) {
const commander = Commander.getInstance();
commander.command({
action: 'shrink',
tracer: this.tracerId,
payload: { size },
});
}
public pick(index: number) {
const commander = Commander.getInstance();
commander.command({
action: 'pick',
tracer: this.tracerId,
payload: { index },
});
}
public drop(index: number) {
const commander = Commander.getInstance();
commander.command({
action: 'drop',
tracer: this.tracerId,
payload: { index },
});
}
public patch(index: number, value: T) {
const commander = Commander.getInstance();
commander.command({
action: 'patch',
tracer: this.tracerId,
payload: { index, value },
});
}
public reset(index: number) {
const commander = Commander.getInstance();
commander.command({
action: 'reset',
tracer: this.tracerId,
payload: { index },
});
}
}

View File

@@ -0,0 +1 @@
export * from "./array-tracer";

View File

@@ -0,0 +1,5 @@
import type { ArrayTracerCommand } from '../command';
export type ArrayTracerAction = ArrayTracerCommand['action'];
export type TracerAction = ArrayTracerAction;

View File

@@ -1,52 +1,52 @@
export type ArrayTracerDefineCommand = {
action: 'define';
tracer: null;
action: "define";
params: { type: "ArrayTracer"; id: string; desc?: string };
payload: { type: 'ArrayTracer'; id: string; desc?: string };
};
export type ArrayTracerPresetCommand<T = unknown> = {
action: 'preset';
tracer: string;
action: "preset";
params: T[];
payload: T[];
};
export type ArrayTracerExtendCommand = {
action: 'extend';
tracer: string;
action: "extend";
params: { size: number };
payload: { size: number };
};
export type ArrayTracerShrinkCommand = {
action: 'shrink';
tracer: string;
action: "shrink";
params: { size: number };
payload: { size: number };
};
export type ArrayTracerPickCommand = {
action: 'pick';
tracer: string;
action: "pick";
params: { index: number };
payload: { index: number };
};
export type ArrayTracerDropCommand = {
action: 'drop';
tracer: string;
action: "drop";
params: { index: number };
payload: { index: number };
};
export type ArrayTracerPatchCommand<T = unknown> = {
action: 'patch';
tracer: string;
action: "patch";
params: { index: number; value: T };
payload: { index: number; value: T };
};
export type ArrayTracerResetCommand = {
action: 'reset';
tracer: string;
action: "reset";
params: null;
payload: { index: number };
};
export type ArrayTracerCommand<T = unknown> =
export type ArrayTracerCommand<T = never> =
| ArrayTracerDefineCommand
| ArrayTracerPresetCommand<T>
| ArrayTracerExtendCommand

View File

@@ -0,0 +1,5 @@
import type { ArrayTracerCommand } from './array-tracer-command';
export * from './array-tracer-command';
export type TracerCommand<T = never> = ArrayTracerCommand<T>;

View File

@@ -0,0 +1,5 @@
import type { ArrayTracerDefineCommand } from '../command';
type ArrayTracer = ArrayTracerDefineCommand['payload']['type'];
export type TracerType = ArrayTracer;