quilt-wasm 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/quilt_wasm.d.ts CHANGED
@@ -1,218 +1,125 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
1
+ // Types for the quilt-wasm runtime (js/runtime.js). assemble.mjs installs this
2
+ // as the package's quilt_wasm.d.ts, adding the web build's init() below it.
3
3
 
4
- /**
5
- * A child placeholder (the `HOLE` constant in the Python runtime).
6
- */
7
- export function HOLE(): WasmCmdOrHole;
8
-
9
- /**
10
- * The `NewLine` command (the `NL` constant in the Python runtime).
11
- */
12
- export function NL(): WasmStrCmd;
13
-
14
- /**
15
- * The `Pop` command (the `POP` constant in the Python runtime).
16
- */
17
- export function POP(): WasmStrCmd;
18
-
19
- /**
20
- * A fluent term builder, mirroring the Rust `QTermBuilder` (consuming form:
21
- * each method takes `self` and returns the next builder, so chaining works
22
- * from JS exactly as `tb("x").w("a").c(child).b()`).
23
- */
24
- export class WasmBuilder {
25
- private constructor();
26
- free(): void;
27
- [Symbol.dispose](): void;
28
- /**
29
- * Build the term. Consumes the builder.
30
- */
31
- b(): WasmQTerm;
32
- /**
33
- * Splice a child term.
34
- */
35
- c(child: WasmQTerm): WasmBuilder;
36
- /**
37
- * Emit a child term (for an `Arc<QTerm>` this is the same as [`c`]).
38
- */
39
- e(child: WasmQTerm): WasmBuilder;
40
- /**
41
- * Emit a newline (respecting the current prefix).
42
- */
43
- n(): WasmBuilder;
44
- /**
45
- * Push an indentation prefix.
46
- */
47
- p(s: string): WasmBuilder;
48
- /**
49
- * Write literal source text.
50
- */
51
- w(s: string): WasmBuilder;
52
- /**
53
- * Pop an indentation prefix.
54
- */
55
- x(): WasmBuilder;
4
+ /** A single string command: `write(s)`, `NL()`, `push(s)` or `POP()`. */
5
+ export class WasmStrCmd {
6
+ private constructor();
56
7
  }
57
8
 
58
- /**
59
- * A `StrCmd` or a child placeholder (`HOLE`), used in `quote`/`unquote` cmds.
60
- */
9
+ /** A `StrCmd` or a child placeholder (`HOLE()`), for `quote`/`unquote` cmds. */
61
10
  export class WasmCmdOrHole {
62
- private constructor();
63
- free(): void;
64
- [Symbol.dispose](): void;
11
+ private constructor();
65
12
  }
66
13
 
67
- /**
68
- * A quilt term (`Arc<QTerm>`).
69
- */
14
+ /** A quilt term: immutable, and owned by the garbage collector. */
70
15
  export class WasmQTerm {
71
- private constructor();
72
- free(): void;
73
- [Symbol.dispose](): void;
74
- /**
75
- * Serialize the term back to source code.
76
- */
77
- coparse(): string;
78
- toString(): string;
16
+ private constructor();
17
+ /** Serialize the term back to source code. */
18
+ coparse(): string;
19
+ toString(): string;
20
+ /** A no-op: kept for code written when a term was a wasm handle. */
21
+ free(): void;
22
+ [Symbol.dispose](): void;
79
23
  }
80
24
 
81
- /**
82
- * A single string command (`write`/`NL`/`push`/`POP`).
83
- */
84
- export class WasmStrCmd {
85
- private constructor();
86
- free(): void;
87
- [Symbol.dispose](): void;
25
+ /** A fluent term builder; every method but `b` returns the same builder. */
26
+ export class WasmBuilder {
27
+ private constructor();
28
+ /** Splice a child term. */
29
+ c(child: WasmQTerm | string | number | boolean | bigint): WasmBuilder;
30
+ /** Splice a child term (the same as `c`; what expanded code spells). */
31
+ t(child: WasmQTerm | string | number | boolean | bigint): WasmBuilder;
32
+ /** Emit a child term. */
33
+ e(child: WasmQTerm | string | number | boolean | bigint): WasmBuilder;
34
+ /** Write literal source text. */
35
+ w(s: string): WasmBuilder;
36
+ /** Emit a newline (respecting the current prefix). */
37
+ n(): WasmBuilder;
38
+ /** Push an indentation prefix. */
39
+ p(s: string): WasmBuilder;
40
+ /** Pop an indentation prefix. */
41
+ x(): WasmBuilder;
42
+ /** Build the term. */
43
+ b(): WasmQTerm;
44
+ free(): void;
45
+ [Symbol.dispose](): void;
88
46
  }
89
47
 
90
48
  /**
91
- * Wrap a `StrCmd` as a `CmdOrHole`.
92
- */
93
- export function cmd(c: WasmStrCmd): WasmCmdOrHole;
94
-
95
- /**
96
- * A leaf node: a tag whose only content is `code`.
49
+ * A sequence of terms, for `←(items)`: the items in order, with a newline
50
+ * between them, or `sep` when given. Strings splice as their text.
97
51
  */
98
- export function leaf(tag: string, code: string): WasmQTerm;
52
+ export function qseq(items: Iterable<WasmQTerm | string | number | boolean | bigint>, sep?: string): WasmQTerm;
99
53
 
100
- /**
101
- * An identifier term (the `⟨N⟩` operator).
102
- */
103
- export function name(s: string): WasmQTerm;
104
-
105
- /**
106
- * A `Push` command.
107
- */
108
- export function push(s: string): WasmStrCmd;
54
+ /** `↑(x)` inside a `⟨str⟩` quote: the TypeScript literal for `value`, as a string. */
55
+ export function qlift_str(value: number | string | boolean | WasmQTerm): string;
109
56
 
110
- /**
111
- * Lift a JS value to a term that reconstructs it (the homogeneous `↑`
112
- * operator, TypeScript into TypeScript). Supports `number`, `string`, and
113
- * `boolean`. Numbers with no fractional part lift to integer literals;
114
- * everything is coparse-only, so the tags are advisory.
115
- *
116
- * Unlike the Python runtime's `qlift`, this does *not* pass an already-built
117
- * `QTerm` through unchanged: recovering an exported wasm-bindgen type from a
118
- * polymorphic `JsValue` needs target-specific glue. The demos never lift a
119
- * term (terms splice via `↙…↘`), so this is sufficient; a JS shim can add
120
- * pass-through later if needed.
121
- */
122
- export function qlift(value: any): WasmQTerm;
123
-
124
- /**
125
- * Lift a JS value to an HTML term (the `↑` operator with an `html` splice
126
- * target). Strings become entity-escaped `text` leaves — inert as text content
127
- * or as a double-quoted attribute value — and terms pass through unchanged, so
128
- * already-built fragments can be lifted too. Mirrors `qlift_html` in the
129
- * Python runtime, minus the `QTerm` pass-through (see [`qlift`]).
130
- */
131
- export function qlift_html(value: any): WasmQTerm;
132
-
133
- /**
134
- * A quoted fragment.
135
- */
136
- export function quote(tag: string, index: number, lang: string, term: WasmQTerm, cmds: WasmCmdOrHole[]): WasmQTerm;
137
-
138
- /**
139
- * A symbol: a leaf whose tag and code are the same.
140
- */
141
- export function sym(s: string): WasmQTerm;
57
+ declare global {
58
+ interface String {
59
+ /** A `⟨str⟩` quote's value is its own source: `coparse()` returns it. */
60
+ coparse(): string;
61
+ }
62
+ }
142
63
 
143
- /**
144
- * Start building a tuple node with the given tag.
145
- */
64
+ /** Start building a tuple node with the given tag. */
146
65
  export function tb(tag: string): WasmBuilder;
66
+ /** A leaf node: a tag whose only content is `code`. */
67
+ export function leaf(tag: string, code: string): WasmQTerm;
68
+ /** A symbol: a leaf whose tag and code are the same. */
69
+ export function sym(s: string): WasmQTerm;
70
+ /** An identifier term (the `⟨N⟩` operator). */
71
+ export function name(s: string): WasmQTerm;
72
+ /** A quoted fragment. */
73
+ export function quote(tag: string, index: number, lang: string, term: WasmQTerm, cmds: WasmCmdOrHole[]): WasmQTerm;
74
+ /** An unquoted splice. */
75
+ export function unquote(tag: string, index: number, lang: string, term: WasmQTerm, cmds: WasmCmdOrHole[]): WasmQTerm;
76
+ /** Wrap a `StrCmd` as a `CmdOrHole`. */
77
+ export function cmd(c: WasmStrCmd): WasmCmdOrHole;
78
+ /** A `Write` command. */
79
+ export function write(s: string): WasmStrCmd;
80
+ /** A `Push` command. */
81
+ export function push(s: string): WasmStrCmd;
82
+ /** The `NewLine` command. */
83
+ export function NL(): WasmStrCmd;
84
+ /** The `Pop` command. */
85
+ export function POP(): WasmStrCmd;
86
+ /** A child placeholder. */
87
+ export function HOLE(): WasmCmdOrHole;
147
88
 
148
89
  /**
149
- * An unquoted splice.
90
+ * Lift a JS value to a term that reconstructs it (the homogeneous `↑`):
91
+ * a number, string or boolean to its literal, a term to the TypeScript that
92
+ * rebuilds it.
150
93
  */
151
- export function unquote(tag: string, index: number, lang: string, term: WasmQTerm, cmds: WasmCmdOrHole[]): WasmQTerm;
152
-
94
+ export function qlift(value: number | string | boolean | WasmQTerm): WasmQTerm;
153
95
  /**
154
- * A `Write` command.
96
+ * Lift a JS value to an HTML term: a string to entity-escaped text, a term
97
+ * unchanged.
155
98
  */
156
- export function write(s: string): WasmStrCmd;
157
-
158
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
99
+ export function qlift_html(value: number | string | boolean | WasmQTerm): WasmQTerm;
159
100
 
160
- export interface InitOutput {
161
- readonly memory: WebAssembly.Memory;
162
- readonly HOLE: () => number;
163
- readonly NL: () => number;
164
- readonly POP: () => number;
165
- readonly __wbg_wasmbuilder_free: (a: number, b: number) => void;
166
- readonly __wbg_wasmcmdorhole_free: (a: number, b: number) => void;
167
- readonly __wbg_wasmqterm_free: (a: number, b: number) => void;
168
- readonly __wbg_wasmstrcmd_free: (a: number, b: number) => void;
169
- readonly cmd: (a: number) => number;
170
- readonly leaf: (a: number, b: number, c: number, d: number) => number;
171
- readonly name: (a: number, b: number) => number;
172
- readonly push: (a: number, b: number) => number;
173
- readonly qlift: (a: any) => [number, number, number];
174
- readonly qlift_html: (a: any) => [number, number, number];
175
- readonly quote: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
176
- readonly sym: (a: number, b: number) => number;
177
- readonly tb: (a: number, b: number) => number;
178
- readonly unquote: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
179
- readonly wasmbuilder_b: (a: number) => number;
180
- readonly wasmbuilder_c: (a: number, b: number) => number;
181
- readonly wasmbuilder_e: (a: number, b: number) => number;
182
- readonly wasmbuilder_n: (a: number) => number;
183
- readonly wasmbuilder_p: (a: number, b: number, c: number) => number;
184
- readonly wasmbuilder_w: (a: number, b: number, c: number) => number;
185
- readonly wasmbuilder_x: (a: number) => number;
186
- readonly wasmqterm_coparse: (a: number) => [number, number];
187
- readonly write: (a: number, b: number) => number;
188
- readonly wasmqterm_toString: (a: number) => [number, number];
189
- readonly __wbindgen_malloc: (a: number, b: number) => number;
190
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
191
- readonly __wbindgen_externrefs: WebAssembly.Table;
192
- readonly __externref_table_dealloc: (a: number) => void;
193
- readonly __externref_table_alloc: () => number;
194
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
195
- readonly __wbindgen_start: () => void;
101
+ /** A text dialect: any rule left out is JSON's (see `qlift_text`). */
102
+ export interface TextDialect {
103
+ string?(s: string): string;
104
+ in_quotes?(s: string): string;
105
+ boolean?(b: boolean): string;
106
+ float?(f: number): string;
107
+ list_open?: string;
108
+ list_sep?: string;
109
+ list_close?: string;
196
110
  }
197
-
198
- export type SyncInitInput = BufferSource | WebAssembly.Module;
199
-
111
+ /** A value in a text quote: a scalar, a term, or an array of them. */
112
+ export type TextValue = number | string | boolean | WasmQTerm | TextValue[];
200
113
  /**
201
- * Instantiates the given `module`, which can either be bytes or
202
- * a precompiled `WebAssembly.Module`.
203
- *
204
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
205
- *
206
- * @returns {InitOutput}
114
+ * Lift a JS value into a text quote: JSON's spelling unless `dialect`
115
+ * overrides a rule.
207
116
  */
208
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
209
-
117
+ export function qlift_text(value: TextValue, dialect?: TextDialect): WasmQTerm;
210
118
  /**
211
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
212
- * for everything else, calls `WebAssembly.instantiate` directly.
213
- *
214
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
215
- *
216
- * @returns {Promise<InitOutput>}
119
+ * `qlift_text` for a hole between two `"` the author wrote: a string as its
120
+ * escaped contents, an array as its elements joined by the separator.
217
121
  */
218
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
122
+ export function qlift_text_in_quotes(value: TextValue, dialect?: TextDialect): WasmQTerm;
123
+
124
+ /** Load the wasm. Await it before calling the runtime. */
125
+ export { default, initSync } from "./quilt_wasm_raw.js";