103 lines
1.8 KiB
TypeScript
103 lines
1.8 KiB
TypeScript
import { getTracerContext } from '../context';
|
|
import type { JsonValue } from '../types';
|
|
|
|
interface ArrayTracerCreateOptions<T extends JsonValue> {
|
|
description?: string;
|
|
array?: T[];
|
|
}
|
|
|
|
export const createArrayTracer = <T extends JsonValue>(
|
|
options: ArrayTracerCreateOptions<T>,
|
|
) => {
|
|
const { description = 'ArrayTracer', array } = options;
|
|
const tracer = crypto.randomUUID();
|
|
|
|
const { command } = getTracerContext();
|
|
|
|
command({
|
|
type: 'ArrayTracer',
|
|
tracer: tracer,
|
|
action: 'create',
|
|
params: {
|
|
description: description,
|
|
array: array,
|
|
},
|
|
});
|
|
|
|
const preset = (array: T[]) => {
|
|
command({
|
|
type: 'ArrayTracer',
|
|
tracer: tracer,
|
|
action: 'preset',
|
|
params: {
|
|
array: array,
|
|
},
|
|
});
|
|
};
|
|
|
|
const scale = (size: number) => {
|
|
command({
|
|
type: 'ArrayTracer',
|
|
tracer: tracer,
|
|
action: 'scale',
|
|
params: {
|
|
size: size,
|
|
},
|
|
});
|
|
};
|
|
|
|
const pick = (index: number) => {
|
|
command({
|
|
type: 'ArrayTracer',
|
|
tracer: tracer,
|
|
action: 'pick',
|
|
params: {
|
|
index: index,
|
|
},
|
|
});
|
|
};
|
|
|
|
const drop = (index: number) => {
|
|
command({
|
|
type: 'ArrayTracer',
|
|
tracer: tracer,
|
|
action: 'drop',
|
|
params: {
|
|
index: index,
|
|
},
|
|
});
|
|
};
|
|
|
|
const patch = (index: number, value: T) => {
|
|
command({
|
|
type: 'ArrayTracer',
|
|
tracer: tracer,
|
|
action: 'patch',
|
|
params: {
|
|
index: index,
|
|
value: value,
|
|
},
|
|
});
|
|
};
|
|
|
|
const unset = (index: number) => {
|
|
command({
|
|
type: 'ArrayTracer',
|
|
tracer: tracer,
|
|
action: 'unset',
|
|
params: {
|
|
index: index,
|
|
},
|
|
});
|
|
};
|
|
|
|
return {
|
|
// preset,
|
|
scale,
|
|
pick,
|
|
drop,
|
|
patch,
|
|
unset,
|
|
};
|
|
};
|