Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 12x 12x 12x 6x 8x 5x | import type { Sketch } from "@shared/schema";
import { randomUUID } from "node:crypto";
/**
* Read-only source behind GET /api/sketches. It holds only the seeded default
* sketch the editor starts from; the API offers no sketch mutations, so nothing
* a client sends can grow this state.
*/
export class DefaultSketchStore {
private readonly sketches: ReadonlyMap<string, Sketch>;
constructor() {
const now = new Date();
const defaultSketch: Sketch = {
id: randomUUID(),
name: "sketch.ino",
content: `
void setup() {
// put your setup code here, to run once
}
void loop() {
// put your main code here, to run repeatedly
}`,
createdAt: now,
updatedAt: now,
};
this.sketches = new Map([[defaultSketch.id, defaultSketch]]);
}
async getSketch(id: string): Promise<Sketch | undefined> {
return this.sketches.get(id);
}
async getAllSketches(): Promise<Sketch[]> {
return Array.from(this.sketches.values());
}
}
export const storage = new DefaultSketchStore();
|