scripts/validate_shapes.mjs
scripts/validate_shapes.mjsBrowse 4 files
711 tokens
2,387 bytes
Token encoding: o200k_base
Snapshot 24fd22b
← Back to SKILL.md
1#!/usr/bin/env node2// validate_shapes.mjs — verify that the note/text/frame records this skill3// documents are valid against the real tldraw SDK v5 schema.4//5// Usage:6// npm install @tldraw/tlschema7// node validate_shapes.mjs8//9// Exits 0 when all sample records validate, 1 otherwise. No network, no DOM.10 11import { createTLSchema, toRichText, createShapeId, PageRecordType } from '@tldraw/tlschema'12 13const schema = createTLSchema()14const shapeRecord = schema.types.shape15const pageId = PageRecordType.createId()16 17// Complete default prop sets (required when building raw records outside the editor).18const COMPLETE = {19 note: {20 richText: toRichText(''), color: 'black', labelColor: 'black', size: 'm',21 font: 'draw', align: 'middle', verticalAlign: 'middle', growY: 0,22 fontSizeAdjustment: 0, url: '', scale: 1, textLastEditedBy: '',23 },24 text: {25 richText: toRichText(''), color: 'black', size: 'm', font: 'draw',26 textAlign: 'start', w: 8, scale: 1, autoSize: true,27 },28 frame: { w: 300, h: 640, name: '', color: 'black' },29}30 31function makeRecord(type, props, meta = {}, x = 0, y = 0) {32 return {33 id: createShapeId(), typeName: 'shape', type, parentId: pageId, index: 'a1',34 x, y, rotation: 0, isLocked: false, opacity: 1, meta,35 props: { ...COMPLETE[type], ...props },36 }37}38 39const cases = [40 ['frame', makeRecord('frame', { w: 300, h: 640, name: 'To Do' }, { role: 'column' })],41 ['text', makeRecord('text', { richText: toRichText('To Do · WIP 2'), size: 's', color: 'grey', font: 'sans' }, { role: 'count' }, 8, -34)],42 ['note', makeRecord('note', { richText: toRichText('Design the thing'), size: 's' }, { role: 'card' }, 20, 48)],43]44 45let ok = 046const validated = []47for (const [name, rec] of cases) {48 try {49 validated.push(shapeRecord.validate(rec))50 console.log(`OK ${name}`)51 ok++52 } catch (e) {53 console.log(`FAIL ${name}: ${String(e.message).split('\n')[0]}`)54 }55}56 57// Round-trip through JSON to mimic file save/load.58let rok = 059for (const v of validated) {60 try { shapeRecord.validate(JSON.parse(JSON.stringify(v))); rok++ } catch { /* counted below */ }61}62 63console.log(`\n${ok}/${cases.length} shape records valid against the tldraw schema.`)64console.log(`${rok}/${validated.length} survive a JSON round-trip (file save/load).`)65process.exit(ok === cases.length && rok === validated.length ? 0 : 1)66 Referenced from SKILL.md
SKILL.mdView in source ↗
Source excerpt starting at line 226.SKILL.mdView in source ↗226fill defaults). When building **raw records** for a file snapshot, every prop227below is required (run `scripts/validate_shapes.mjs`):
Source excerpt starting at line 267.267- **Shape schema (offline, no app):** `node scripts/validate_shapes.mjs` — builds268 the real tldraw schema and validates note/text/frame. Passing prints `3/3`.