diff --git a/apps/app/tests/helpers/core.ts b/apps/app/tests/helpers/core.ts index e6e466bc..84f1986e 100644 --- a/apps/app/tests/helpers/core.ts +++ b/apps/app/tests/helpers/core.ts @@ -57,6 +57,8 @@ export async function trappingCoreRuntime(marker: string) { SheetHandle: Trapping, FileBytes: glue.FileBytes, ExportSession: glue.ExportSession, + PreviewBuilder: glue.PreviewBuilder, + clean_svg: glue.clean_svg, } }, } diff --git a/crates/wasm/src/lib.rs b/crates/wasm/src/lib.rs index 05651039..b1fb4532 100644 --- a/crates/wasm/src/lib.rs +++ b/crates/wasm/src/lib.rs @@ -4,6 +4,7 @@ //! the application behind the sheet and import paths (`packages/core-wasm/src/runtime.ts`). use faunosteo_core::domain::sheet::LoadedSheet; +use faunosteo_core::domain::sheet::preview::PreviewDrawing; use faunosteo_core::pdf::read::MAX_PDF_BYTES; use wasm_bindgen::prelude::{JsError, wasm_bindgen}; @@ -63,6 +64,85 @@ impl SheetHandle { } } +/// A stored sheet version being gathered for preview (V1-2.2, contract §10): the page adds +/// each downloaded drawing with the sha256 of its row, then builds the `PreviewSheet` from +/// the version's status, document text and stored fingerprint. The bytes are copied once +/// into the module's memory by the glue; nothing is read before `build`. +#[wasm_bindgen] +pub struct PreviewBuilder { + drawings: Vec, +} + +#[wasm_bindgen] +impl PreviewBuilder { + #[wasm_bindgen(constructor)] + pub fn new() -> PreviewBuilder { + PreviewBuilder { + drawings: Vec::new(), + } + } + + pub fn add_drawing(&mut self, asset_id: &str, sha256: &str, bytes: &[u8]) { + self.drawings.push(PreviewDrawing { + asset_id: asset_id.to_owned(), + sha256: sha256.to_owned(), + bytes: bytes.to_vec(), + }); + } + + /// Consumes the builder; throws an `Error` worded `: ` (`invalid_document`, + /// `drawing_missing`, `drawing_hash_mismatch`, `fingerprint_mismatch`, `caps`, or + /// `invalid_shape` / `invalid_json` for the input). + pub fn build(self, input: &str) -> Result { + faunosteo_core::facade::load_preview(input, self.drawings) + .map(|sheet| PreviewSheet { sheet }) + .map_err(|failure| JsError::new(&format!("{}: {}", failure.kind, failure.detail))) + } +} + +impl Default for PreviewBuilder { + fn default() -> Self { + Self::new() + } +} + +/// A stored version loaded for the catalogue, the admin preview and the editor: no report +/// migration map, never a report session. +#[wasm_bindgen] +pub struct PreviewSheet { + sheet: faunosteo_core::domain::sheet::preview::PreviewSheet, +} + +#[wasm_bindgen] +impl PreviewSheet { + /// `preview.state` or `view.canvas`; the envelope of `call`. + pub fn call(&self, op: &str, input: &str) -> String { + faunosteo_core::facade::call_with_preview(&self.sheet, op, input) + } + + /// A draft's document after an edit; the drawings are not read again. + pub fn replace_document(&mut self, text: &str) -> String { + faunosteo_core::facade::replace_preview_document(&mut self.sheet, text) + } + + /// A drawing uploaded while the draft is open. + pub fn add_drawing(&mut self, asset_id: &str, sha256: &str, bytes: &[u8]) -> String { + let drawing = PreviewDrawing { + asset_id: asset_id.to_owned(), + sha256: sha256.to_owned(), + bytes: bytes.to_vec(), + }; + faunosteo_core::facade::add_preview_drawing(&mut self.sheet, drawing) + } +} + +/// The cleaning answer for a file picked for upload (contract §9.2): the envelope of `call` +/// with an `SvgCleaning` value. +#[wasm_bindgen] +pub fn clean_svg(bytes: &[u8]) -> String { + faunosteo_core::facade::clean_svg(bytes) +} + /// The incremental PDF export (R4.6, plan §B.1.4, OD-2): the application opens a session on /// its `ExportInput` JSON, then alternates `next()` (the rasters the next step needs) with /// `add_raster` or `raster_failed` per key, and closes with `finish()`. Every answer is the diff --git a/packages/core-wasm/src/index.ts b/packages/core-wasm/src/index.ts index 43ec13fa..15c4bec3 100644 --- a/packages/core-wasm/src/index.ts +++ b/packages/core-wasm/src/index.ts @@ -14,6 +14,8 @@ export { type GlueExportSession, type GlueFileBytes, type GlueModule, + type GluePreviewBuilder, + type GluePreviewSheet, type GlueSheetHandle, } from './runtime' export { CoreExportSession, openExportSession } from './export' diff --git a/packages/core-wasm/src/runtime.ts b/packages/core-wasm/src/runtime.ts index fe817c1a..e6ff4922 100644 --- a/packages/core-wasm/src/runtime.ts +++ b/packages/core-wasm/src/runtime.ts @@ -26,6 +26,30 @@ export interface GlueModule { FileBytes: new (expected: number) => GlueFileBytes /** R4.6: the incremental export; the constructor throws `: ` on a refused input. */ ExportSession: new (inputJson: string) => GlueExportSession + /** V1-2.2: a stored version gathered for preview (drawings first, then `build`). */ + PreviewBuilder: new () => GluePreviewBuilder + /** V1-2.2: the cleaning answer for a file picked for upload (`SvgCleaning` envelope). */ + clean_svg(bytes: Uint8Array): string +} + +/** A stored version being gathered (crates/wasm `PreviewBuilder`). */ +export interface GluePreviewBuilder { + add_drawing(assetId: string, sha256: string, bytes: Uint8Array): void + /** Consumes the builder; throws `: ` (`invalid_document`, `drawing_missing`, + * `drawing_hash_mismatch`, `fingerprint_mismatch`, `caps`, `invalid_shape`, `invalid_json`). */ + build(inputJson: string): GluePreviewSheet + free(): void +} + +/** A stored version loaded for the catalogue, the preview and the editor (crates/wasm + * `PreviewSheet`): no report migration map, never a report session. */ +export interface GluePreviewSheet { + /** `preview.state` or `view.canvas`; outcome envelopes out. */ + call(op: string, input: string): string + /** A draft's document after an edit, the drawings kept as read. */ + replace_document(text: string): string + add_drawing(assetId: string, sha256: string, bytes: Uint8Array): string + free(): void } /** The export session of the module (crates/wasm `ExportSession`): outcome envelopes out. */ diff --git a/packages/core-wasm/tests/preview.test.ts b/packages/core-wasm/tests/preview.test.ts new file mode 100644 index 00000000..d3b46ef3 --- /dev/null +++ b/packages/core-wasm/tests/preview.test.ts @@ -0,0 +1,154 @@ +/** + * V1-2.2 on the shipped module (contract §8.1, §9.2, §10): the equine draft previews with the + * index, the fingerprint and the canvases of the bundled sheet; hash and fingerprint + * mismatches refuse the build with their closed kind; a draft's document is replaced and + * redrawn; the edit commands run through `call`; every hostile SVG and flood gets a closed + * cleaning answer with no trap. The Rust suites hold the rules; this proves the facade. + */ +import { readFileSync, readdirSync } from 'node:fs' +import { fileURLToPath } from 'node:url' + +import type { GlueModule } from '../src/index' +import { nodeCoreSource } from '../src/node' + +const ROOT = '../../../' +const SEED = `${ROOT}supabase/seed/anatomical-sheets/equine/draft/` +const HOSTILE = `${ROOT}crates/core/tests/fixtures/svg/hostile/` +const HORSE_ID = '7f767f74-3b36-51a7-8465-52dd7e2ead4a' +const HORSE_SHA = '0ea5202fa3b95bac167b87c12ee969ab0272e085b60c2d34dbca6202c5f08541' +const FINGERPRINT = '12d788727c1e532641bd5b3a7ecf39dbdd25e70350f8a76be5ca917b262874e2' +const path = (p: string) => fileURLToPath(new URL(p, import.meta.url)) +const text = (p: string) => readFileSync(path(p), 'utf8') + +const documentText = text(`${SEED}document.json`) +const horse = new Uint8Array(readFileSync(path(`${SEED}assets/horse.svg`))) + +let glue: GlueModule + +beforeAll(async () => { + const source = nodeCoreSource('pkg') + glue = await source.importGlue(0) + await glue.default({ module_or_path: await source.compile() }) +}) + +const value = (envelope: string) => { + const outcome = JSON.parse(envelope) + expect(outcome.ok).toBe(true) + return outcome.value +} + +function build(status: string, drawing: Uint8Array | null, fingerprint?: string, doc = documentText) { + const builder = new glue.PreviewBuilder() + if (drawing) builder.add_drawing(HORSE_ID, HORSE_SHA, drawing) + return builder.build(JSON.stringify({ status, document: doc, fingerprint })) +} + +function refusal(run: () => unknown): string { + try { + run() + } catch (error) { + return (error as Error).message + } + throw new Error('no refusal') +} + +describe('PreviewSheet through the shipped module', () => { + it('previews the equine draft as the bundled sheet', () => { + const preview = build('published', horse, FINGERPRINT) + const state = value(preview.call('preview.state', '{}')) + expect(state.fingerprint).toBe(FINGERPRINT) + expect(state.report.groups).toHaveLength(30) + const handle = new glue.SheetHandle( + JSON.stringify({ + status: 'draft', + ref: JSON.parse(text(`${SEED}sheet-ref.json`)), + document: JSON.parse(documentText), + migrationMap: JSON.parse(text(`${SEED}report-migration-map.json`)), + assets: { [HORSE_ID]: new TextDecoder().decode(horse) }, + assetHashes: { [HORSE_ID]: HORSE_SHA }, + }), + ) + const index = value(handle.call('index_data', '{}')) + expect(state.index.main_view_id).toBe(index.mainViewId) + expect(state.index.view_by_id).toEqual(index.viewById) + expect(state.index.annotation_by_id).toEqual(index.annotationById) + expect(state.index.finding_zone_by_id).toEqual(index.findingZoneById) + expect(state.index.names).toEqual(index.names) + expect(state.index.node_keys).toEqual(index.nodeKeys) + for (const viewId of ['main', 'head']) { + const input = JSON.stringify({ viewId }) + expect(preview.call('view.canvas', input)).toBe(handle.call('view.canvas', input)) + } + handle.free() + preview.free() + }) + + it('refuses a hash or a fingerprint mismatch with its closed kind', () => { + const altered = horse.slice() + altered[200] ^= 1 + expect(refusal(() => build('draft', altered))).toBe(`drawing_hash_mismatch: ${HORSE_ID}`) + expect(refusal(() => build('published', horse, 'a'.repeat(64)))).toBe('fingerprint_mismatch: ') + expect(refusal(() => build('deprecated', null, FINGERPRINT))).toBe(`drawing_missing: ${HORSE_ID}`) + expect(refusal(() => build('draft', horse, undefined, '{'))).toMatch(/^invalid_document: /) + }) + + it('replaces a draft document and redraws it', () => { + const draft = build('draft', horse) + const before = draft.call('view.canvas', '{"viewId":"main"}') + const edited = JSON.parse(documentText) + edited.annotations = edited.annotations.slice(0, 2) + expect(draft.replace_document(JSON.stringify(edited))).toBe('{"ok":true,"value":null}') + const after = draft.call('view.canvas', '{"viewId":"main"}') + expect(value(after).svg).not.toBe(value(before).svg) + expect(value(draft.call('preview.state', '{}')).document.annotations).toHaveLength(2) + const published = build('published', horse, FINGERPRINT) + expect(JSON.parse(published.replace_document(documentText)).kind).toBe('read_only') + draft.free() + published.free() + }) + + it('runs the edit commands and lists dependents', () => { + const document = JSON.parse(documentText) + const id = document.annotations[0].id + const command = { op: 'remove', key: { kind: 'annotation', id } } + const edited = value(glue.call('sheet.edit', JSON.stringify({ document, command }))) + expect(edited.document.annotations).toHaveLength(document.annotations.length - 1) + const unknown = JSON.parse( + glue.call('sheet.edit', JSON.stringify({ document, command: { op: 'remove', key: { kind: 'annotation', id: 'zz' } } })), + ) + expect(unknown.kind).toBe('unknown_key') + const head = value( + glue.call('sheet.dependents', JSON.stringify({ document, key: { kind: 'view', id: 'head' } })), + ) + expect(head.dependents.length).toBeGreaterThan(0) + }) +}) + +describe('clean_svg through the shipped module', () => { + it('answers every hostile file and flood with a closed outcome, no trap', () => { + const encoder = new TextEncoder() + const files = readdirSync(path(HOSTILE)).filter((f) => f.endsWith('.svg')) + const floods = { + 'deep 99,000 levels': `${''.repeat(99_000)}`, + 'nodes 20,001': `${''.repeat(20_000)}`, + 'bytes 2 MiB + 1': ``, + } + const inputs: [string, Uint8Array][] = [ + ...files.map((f): [string, Uint8Array] => [f, new Uint8Array(readFileSync(path(`${HOSTILE}${f}`)))]), + ...Object.entries(floods).map(([name, svg]): [string, Uint8Array] => [name, encoder.encode(svg)]), + ] + let slowest = 0 + for (const [name, bytes] of inputs) { + const started = performance.now() + const cleaning = value(glue.clean_svg(bytes)) + slowest = Math.max(slowest, performance.now() - started) + expect(['clean', 'cleanable', 'rejected'], name).toContain(cleaning.outcome) + } + expect(value(glue.clean_svg(new Uint8Array(readFileSync(path(`${HOSTILE}script.svg`))))).reason).toBe( + 'svg_active_content', + ) + expect(value(glue.clean_svg(horse)).outcome).toBe('clean') + console.info(`[core-wasm] clean_svg: ${inputs.length} inputs, slowest ${slowest.toFixed(1)} ms`) + expect(glue.core_version()).toMatch(/^\d+\.\d+\.\d+$/) + }) +}) diff --git a/packages/core-wasm/types/CapName.ts b/packages/core-wasm/types/CapName.ts new file mode 100644 index 00000000..53a0dbfc --- /dev/null +++ b/packages/core-wasm/types/CapName.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +/** + * One cap, by name. + */ +export type CapName = "views" | "annotations" | "finding_nodes" | "finding_depth" | "label_length" | "drawings" | "drawing_bytes" | "drawings_total_bytes" | "document_bytes"; diff --git a/packages/core-wasm/types/CapsReport.ts b/packages/core-wasm/types/CapsReport.ts new file mode 100644 index 00000000..275e566e --- /dev/null +++ b/packages/core-wasm/types/CapsReport.ts @@ -0,0 +1,27 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { CapName } from "./CapName"; + +/** + * What the sheet holds against each cap, and the caps it passes. + */ +export type CapsReport = { views: number, annotations: number, +/** + * Finding categories and nodes, categories counted. + */ +finding_nodes: number, +/** + * Deepest finding level, a category at 1. + */ +finding_depth: number, +/** + * Longest `name` label, `fr` or `en`, in UTF-16 units. + */ +longest_label: number, +/** + * Distinct drawings the views reference. + */ +drawings: number, largest_drawing_bytes: number, drawings_total_bytes: number, +/** + * The server's measure of the document (`octet_length(content::text)`). + */ +document_bytes: number, exceeded: Array, }; diff --git a/packages/core-wasm/types/ChangeKind.ts b/packages/core-wasm/types/ChangeKind.ts new file mode 100644 index 00000000..9ba27afc --- /dev/null +++ b/packages/core-wasm/types/ChangeKind.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type ChangeKind = "added" | "removed" | "changed" | "status_changed"; diff --git a/packages/core-wasm/types/CleaningOutcome.ts b/packages/core-wasm/types/CleaningOutcome.ts new file mode 100644 index 00000000..dad44980 --- /dev/null +++ b/packages/core-wasm/types/CleaningOutcome.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type CleaningOutcome = "clean" | "cleanable" | "rejected"; diff --git a/packages/core-wasm/types/Completeness.ts b/packages/core-wasm/types/Completeness.ts new file mode 100644 index 00000000..6d638760 --- /dev/null +++ b/packages/core-wasm/types/Completeness.ts @@ -0,0 +1,8 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { StatusCounts } from "./StatusCounts"; + +/** + * Shown, never blocking (§6.7): the markings, the vet referral nodes, and the finding + * categories and nodes that cite no reference. + */ +export type Completeness = { statuses: StatusCounts, vet_referrals: number, uncited: number, }; diff --git a/packages/core-wasm/types/Dependent.ts b/packages/core-wasm/types/Dependent.ts new file mode 100644 index 00000000..3c55ee06 --- /dev/null +++ b/packages/core-wasm/types/Dependent.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ElementKey } from "./ElementKey"; +import type { Relation } from "./Relation"; + +export type Dependent = { element: ElementKey, relation: Relation, }; diff --git a/packages/core-wasm/types/DrawingCheck.ts b/packages/core-wasm/types/DrawingCheck.ts new file mode 100644 index 00000000..c63c9f6f --- /dev/null +++ b/packages/core-wasm/types/DrawingCheck.ts @@ -0,0 +1,15 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { DrawingResult } from "./DrawingResult"; + +/** + * One drawing the views reference, as the verdict found it. + */ +export type DrawingCheck = { asset_id: string, +/** + * The row's sha256; absent when no row was given. + */ +sha256: string | null, +/** + * The row's byte size; absent when no row was given. + */ +byte_size: number | null, result: DrawingResult, detail: string | null, }; diff --git a/packages/core-wasm/types/DrawingResult.ts b/packages/core-wasm/types/DrawingResult.ts new file mode 100644 index 00000000..b4ef01c4 --- /dev/null +++ b/packages/core-wasm/types/DrawingResult.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type DrawingResult = "ok" | "missing" | "size_mismatch" | "hash_mismatch" | "svg_rejected" | "svg_removal"; diff --git a/packages/core-wasm/types/EditCommand.ts b/packages/core-wasm/types/EditCommand.ts new file mode 100644 index 00000000..99130a36 --- /dev/null +++ b/packages/core-wasm/types/EditCommand.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ElementKey } from "./ElementKey"; +import type { Marking } from "./Marking"; +import type { NewElement } from "./NewElement"; + +export type EditCommand = { "op": "insert", element: NewElement, parent?: ElementKey, position?: number, } | { "op": "update", key: ElementKey, element: NewElement, } | { "op": "remove", key: ElementKey, } | { "op": "move", key: ElementKey, position: number, } | { "op": "set_status", key: ElementKey, status: Marking, } | { "op": "mark_reviewed", key: ElementKey, }; diff --git a/packages/core-wasm/types/ElementChange.ts b/packages/core-wasm/types/ElementChange.ts new file mode 100644 index 00000000..b121cdad --- /dev/null +++ b/packages/core-wasm/types/ElementChange.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { ChangeKind } from "./ChangeKind"; +import type { ElementKey } from "./ElementKey"; +import type { ReviewStatus } from "./ReviewStatus"; + +export type ElementChange = { group: string, element: ElementKey, change: ChangeKind, status_before: ReviewStatus | null, status_after: ReviewStatus | null, }; diff --git a/packages/core-wasm/types/ElementKey.ts b/packages/core-wasm/types/ElementKey.ts new file mode 100644 index 00000000..dd6555b6 --- /dev/null +++ b/packages/core-wasm/types/ElementKey.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type ElementKey = { "kind": "sheet" } | { "kind": "reference", id: string, } | { "kind": "region", code: string, } | { "kind": "category", id: string, } | { "kind": "view", id: string, } | { "kind": "annotation", id: string, } | { "kind": "zone", id: string, } | { "kind": "finding", zone_id: string, path: Array, }; diff --git a/packages/core-wasm/types/Marking.ts b/packages/core-wasm/types/Marking.ts new file mode 100644 index 00000000..383859ab --- /dev/null +++ b/packages/core-wasm/types/Marking.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +/** + * The two markings an editor sets by hand. + */ +export type Marking = "to_confirm" | "reviewed"; diff --git a/packages/core-wasm/types/NewElement.ts b/packages/core-wasm/types/NewElement.ts new file mode 100644 index 00000000..b9f8d09a --- /dev/null +++ b/packages/core-wasm/types/NewElement.ts @@ -0,0 +1,15 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Annotation } from "./Annotation"; +import type { AnnotationCategory } from "./AnnotationCategory"; +import type { FindingCategory } from "./FindingCategory"; +import type { FindingNode } from "./FindingNode"; +import type { FindingZone } from "./FindingZone"; +import type { Reference } from "./Reference"; +import type { SheetTexts } from "./SheetTexts"; +import type { SheetView } from "./SheetView"; +import type { VertebralRegion } from "./VertebralRegion"; + +/** + * An element as the editor writes it, by kind. + */ +export type NewElement = { "kind": "sheet", "value": SheetTexts } | { "kind": "reference", "value": Reference } | { "kind": "region", "value": VertebralRegion } | { "kind": "category", "value": AnnotationCategory } | { "kind": "view", "value": SheetView } | { "kind": "annotation", "value": Annotation } | { "kind": "zone", "value": FindingZone } | { "kind": "finding_category", "value": FindingCategory } | { "kind": "finding_node", "value": FindingNode }; diff --git a/packages/core-wasm/types/PreviewDrawingState.ts b/packages/core-wasm/types/PreviewDrawingState.ts new file mode 100644 index 00000000..e9c34c30 --- /dev/null +++ b/packages/core-wasm/types/PreviewDrawingState.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { PreviewDrawingStatus } from "./PreviewDrawingStatus"; + +export type PreviewDrawingState = { asset_id: string, state: PreviewDrawingStatus, detail: string | null, }; diff --git a/packages/core-wasm/types/PreviewDrawingStatus.ts b/packages/core-wasm/types/PreviewDrawingStatus.ts new file mode 100644 index 00000000..98d9b9d5 --- /dev/null +++ b/packages/core-wasm/types/PreviewDrawingStatus.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type PreviewDrawingStatus = "ok" | "missing" | "rejected"; diff --git a/packages/core-wasm/types/PreviewIndex.ts b/packages/core-wasm/types/PreviewIndex.ts new file mode 100644 index 00000000..2d1919ed --- /dev/null +++ b/packages/core-wasm/types/PreviewIndex.ts @@ -0,0 +1,8 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { LocalizedText } from "./LocalizedText"; + +/** + * The lookups the canvas and the catalogue read (the `SheetIndexData` tables), present when + * the document has a main view. + */ +export type PreviewIndex = { main_view_id: string, view_by_id: { [key in string]: number }, annotation_by_id: { [key in string]: number }, finding_zone_by_id: { [key in string]: number }, names: { [key in string]: LocalizedText }, spine_ids: Array, node_keys: Array, }; diff --git a/packages/core-wasm/types/PreviewInput.ts b/packages/core-wasm/types/PreviewInput.ts new file mode 100644 index 00000000..3b5b4b2e --- /dev/null +++ b/packages/core-wasm/types/PreviewInput.ts @@ -0,0 +1,8 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { PreviewStatus } from "./PreviewStatus"; + +/** + * The version as `get_sheet_version` gives it: status, document text, stored fingerprint + * (published and deprecated versions). + */ +export type PreviewInput = { status: PreviewStatus, document: string, fingerprint?: string, }; diff --git a/packages/core-wasm/types/PreviewState.ts b/packages/core-wasm/types/PreviewState.ts new file mode 100644 index 00000000..27048036 --- /dev/null +++ b/packages/core-wasm/types/PreviewState.ts @@ -0,0 +1,19 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AnatomicalSheetDocument } from "./AnatomicalSheetDocument"; +import type { PreviewDrawingState } from "./PreviewDrawingState"; +import type { PreviewIndex } from "./PreviewIndex"; +import type { PreviewStatus } from "./PreviewStatus"; +import type { SheetReport } from "./SheetReport"; + +/** + * What a page reads of a loaded version, after load and after each replacement. + */ +export type PreviewState = { status: PreviewStatus, +/** + * Recomputed; absent when the document has an integrity error. + */ +fingerprint: string | null, report: SheetReport, drawings: Array, index: PreviewIndex | null, +/** + * The document as read (defaults filled in). + */ +document: AnatomicalSheetDocument, }; diff --git a/packages/core-wasm/types/PreviewStatus.ts b/packages/core-wasm/types/PreviewStatus.ts new file mode 100644 index 00000000..ccb83e84 --- /dev/null +++ b/packages/core-wasm/types/PreviewStatus.ts @@ -0,0 +1,3 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +export type PreviewStatus = "draft" | "published" | "deprecated"; diff --git a/packages/core-wasm/types/Relation.ts b/packages/core-wasm/types/Relation.ts new file mode 100644 index 00000000..f0debce1 --- /dev/null +++ b/packages/core-wasm/types/Relation.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +/** + * How a dependent relates to the element about to be removed. + */ +export type Relation = "drawn_in" | "child_view" | "opens" | "uses_category" | "links_zone" | "cites" | "uses_region" | "descendant"; diff --git a/packages/core-wasm/types/ReviewGroup.ts b/packages/core-wasm/types/ReviewGroup.ts new file mode 100644 index 00000000..af93fe4c --- /dev/null +++ b/packages/core-wasm/types/ReviewGroup.ts @@ -0,0 +1,11 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { StatusCounts } from "./StatusCounts"; + +/** + * One review group of a verdict (the shape `acknowledge_sheet_review_group` reads). + */ +export type ReviewGroup = { key: string, digest: string, coverable: boolean, +/** + * A base view or zone the version no longer has. + */ +removed: boolean, statuses: StatusCounts, }; diff --git a/packages/core-wasm/types/SheetDependents.ts b/packages/core-wasm/types/SheetDependents.ts new file mode 100644 index 00000000..c0ebb7f1 --- /dev/null +++ b/packages/core-wasm/types/SheetDependents.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Dependent } from "./Dependent"; + +export type SheetDependents = { dependents: Array, }; diff --git a/packages/core-wasm/types/SheetDependentsInput.ts b/packages/core-wasm/types/SheetDependentsInput.ts new file mode 100644 index 00000000..9146ca4a --- /dev/null +++ b/packages/core-wasm/types/SheetDependentsInput.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AnatomicalSheetDocument } from "./AnatomicalSheetDocument"; +import type { ElementKey } from "./ElementKey"; + +export type SheetDependentsInput = { document: AnatomicalSheetDocument, key: ElementKey, }; diff --git a/packages/core-wasm/types/SheetEditInput.ts b/packages/core-wasm/types/SheetEditInput.ts new file mode 100644 index 00000000..ddbdd7bf --- /dev/null +++ b/packages/core-wasm/types/SheetEditInput.ts @@ -0,0 +1,5 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AnatomicalSheetDocument } from "./AnatomicalSheetDocument"; +import type { EditCommand } from "./EditCommand"; + +export type SheetEditInput = { document: AnatomicalSheetDocument, command: EditCommand, }; diff --git a/packages/core-wasm/types/SheetEditOutput.ts b/packages/core-wasm/types/SheetEditOutput.ts new file mode 100644 index 00000000..8a1ef1fc --- /dev/null +++ b/packages/core-wasm/types/SheetEditOutput.ts @@ -0,0 +1,4 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { AnatomicalSheetDocument } from "./AnatomicalSheetDocument"; + +export type SheetEditOutput = { document: AnatomicalSheetDocument, }; diff --git a/packages/core-wasm/types/SheetReport.ts b/packages/core-wasm/types/SheetReport.ts new file mode 100644 index 00000000..431fb580 --- /dev/null +++ b/packages/core-wasm/types/SheetReport.ts @@ -0,0 +1,7 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { CapsReport } from "./CapsReport"; +import type { Completeness } from "./Completeness"; +import type { ReviewGroup } from "./ReviewGroup"; +import type { SheetIssue } from "./SheetIssue"; + +export type SheetReport = { document_bytes: number, issues: Array, caps: CapsReport, completeness: Completeness, groups: Array, }; diff --git a/packages/core-wasm/types/SheetTexts.ts b/packages/core-wasm/types/SheetTexts.ts new file mode 100644 index 00000000..62860549 --- /dev/null +++ b/packages/core-wasm/types/SheetTexts.ts @@ -0,0 +1,9 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { Attribution } from "./Attribution"; +import type { LocalizedOptionalText } from "./LocalizedOptionalText"; +import type { LocalizedText } from "./LocalizedText"; + +/** + * The sheet's own texts, set as one element. + */ +export type SheetTexts = { name: LocalizedText, description: LocalizedOptionalText, scope_disclaimer: LocalizedOptionalText, attribution: Attribution, }; diff --git a/packages/core-wasm/types/StatusCounts.ts b/packages/core-wasm/types/StatusCounts.ts new file mode 100644 index 00000000..ad45ccf0 --- /dev/null +++ b/packages/core-wasm/types/StatusCounts.ts @@ -0,0 +1,6 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. + +/** + * Elements per review marking. + */ +export type StatusCounts = { to_confirm: number, reviewed: number, inherited: number, }; diff --git a/packages/core-wasm/types/SvgCleaning.ts b/packages/core-wasm/types/SvgCleaning.ts new file mode 100644 index 00000000..c2193c0c --- /dev/null +++ b/packages/core-wasm/types/SvgCleaning.ts @@ -0,0 +1,32 @@ +// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. +import type { CleaningOutcome } from "./CleaningOutcome"; + +export type SvgCleaning = { outcome: CleaningOutcome, +/** + * Rejected: the reader's reason, `malformed`, `too_large` or `svg_active_content`. + */ +reason: string | null, +/** + * Every removal, `tag` or `tag@attribute`, in document order. + */ +removed: Array, +/** + * The removals that carried active or external content. + */ +active: Array, +/** + * A `