@c9up/rover 0.1.11 → 0.1.12

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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Opaque handle to a compiled template IR. The TS-side `cache` keeps these
3
+ * instances alive; when the JS GC collects the wrapper, napi-rs drops the
4
+ * inner `Arc` automatically (Arc + GC bridge — no manual dispose API).
5
+ */
6
+ export declare class RoverIr {
7
+ /**
8
+ * Every referenced partial name, in document order (descends into
9
+ * `{{#if}}` bodies). Drives the TS facade's transitive partial map build.
10
+ */
11
+ get partialNames(): Array<string>;
12
+ }
13
+ /** Compile a template source string into an opaque `RoverIr` handle. */
14
+ export declare function compile(source: string): RoverIr;
15
+ /**
16
+ * Render a compiled IR against `data` (a JSON string), resolving `{{> name}}`
17
+ * partials from the pre-resolved `partials` map. Render-time recursion ->
18
+ * `MAIL_TEMPLATE_RECURSION`.
19
+ *
20
+ * `data` crosses as a JSON STRING (the TS facade calls `JSON.stringify`), not
21
+ * as an object graph: `JSON.stringify` is own-enumerable-only, which preserves
22
+ * the engine's `Object.hasOwn` dot-path contract (inherited prototype-chain
23
+ * props must NOT be visible — `simple-template.test.ts:195-201`). It is also a
24
+ * single native stringify + one Rust parse, instead of napi walking the whole
25
+ * object graph (which would additionally surface inherited enumerable props).
26
+ */
27
+ export declare function renderIr(ir: RoverIr, dataJson: string, partials: Record<string, RoverIr>): string;
28
+ /** Crate version — useful for the TS-side `loadNapi.ts` startup diagnostic. */
29
+ export declare function engineVersion(): string;
30
+ //# sourceMappingURL=generated.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated.d.ts","sourceRoot":"","sources":["../../src/native/generated.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH,MAAM,CAAC,OAAO,OAAO,OAAO;IAC3B;;;OAGG;IACH,IAAI,YAAY,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;CAClC;AAED,wEAAwE;AAExE,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;AAEzD;;;;;;;;;;;GAWG;AAEH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC/B,EAAE,EAAE,OAAO,EACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,MAAM,CAAC;AAEV,+EAA+E;AAE/E,MAAM,CAAC,OAAO,UAAU,aAAa,IAAI,MAAM,CAAC"}
@@ -0,0 +1,7 @@
1
+ // GENERATED FROM THE RUST — do not edit.
2
+ //
3
+ // Produced by scripts/generate-napi-types.mjs from napi-derive's type-def
4
+ // output. Editing this file by hand puts it back where it started: a
5
+ // description that can disagree with the code it describes.
6
+ export {};
7
+ //# sourceMappingURL=generated.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated.js","sourceRoot":"","sources":["../../src/native/generated.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,0EAA0E;AAC1E,qEAAqE;AACrE,4DAA4D"}
@@ -1,14 +1,16 @@
1
1
  import { RoverError } from "../RoverError.js";
2
2
  /** Opaque handle to a compiled template IR (Rust `RoverIr`). */
3
- export interface NativeRoverIr {
4
- /** Referenced partial names, in document order (descends into if-bodies). */
5
- readonly partialNames: readonly string[];
6
- }
7
- interface NativeExports {
8
- readonly engineVersion: () => string;
9
- readonly compile: (source: string) => NativeRoverIr;
10
- readonly renderIr: (ir: NativeRoverIr, dataJson: string, partials: Record<string, NativeRoverIr>) => string;
11
- }
3
+ export type NativeRoverIr = import("../native/generated.js").RoverIr;
4
+ /**
5
+ * The engine's surface, as the Rust declares it.
6
+ *
7
+ * Derived from `../native/generated.js` — written by `pnpm build:napi-types`
8
+ * from napi-derive's own `type-def` output — rather than restated here, where
9
+ * nothing would notice a `pub fn` gaining a parameter or changing its return.
10
+ * The runtime guard below still checks the three exports are actually there:
11
+ * a declaration says what the Rust promises, not what a stale binary shipped.
12
+ */
13
+ type NativeExports = typeof import("../native/generated.js");
12
14
  export declare function getNative(): NativeExports;
13
15
  /**
14
16
  * Translate a thrown value from a native call into a `RoverError`.
@@ -1 +1 @@
1
- {"version":3,"file":"loadNapi.d.ts","sourceRoot":"","sources":["../../src/templating/loadNapi.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAyB9C,gEAAgE;AAChE,MAAM,WAAW,aAAa;IAC7B,6EAA6E;IAC7E,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC;AAED,UAAU,aAAa;IACtB,QAAQ,CAAC,aAAa,EAAE,MAAM,MAAM,CAAC;IACrC,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,aAAa,CAAC;IACpD,QAAQ,CAAC,QAAQ,EAAE,CAClB,EAAE,EAAE,aAAa,EACjB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,KACnC,MAAM,CAAC;CACZ;AAaD,wBAAgB,SAAS,IAAI,aAAa,CA6CzC;AA6BD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAwBpD"}
1
+ {"version":3,"file":"loadNapi.d.ts","sourceRoot":"","sources":["../../src/templating/loadNapi.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAyB9C,gEAAgE;AAChE,MAAM,MAAM,aAAa,GAAG,OAAO,wBAAwB,EAAE,OAAO,CAAC;AAErE;;;;;;;;GAQG;AACH,KAAK,aAAa,GAAG,cAAc,wBAAwB,CAAC,CAAC;AAa7D,wBAAgB,SAAS,IAAI,aAAa,CA6CzC;AA6BD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,CAwBpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"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S,CAAC;QACpB,CAAC;QACD,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACrC,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9D,CAAC;QACF,CAAC;QACD,OAAO,IAAI,UAAU,CACpB,sBAAsB,EACtB,gCAAgC,GAAG,CAAC,OAAO,EAAE,CAC7C,CAAC;IACH,CAAC;IACD,OAAO,IAAI,UAAU,CACpB,sBAAsB,EACtB,+CAA+C,MAAM,CAAC,GAAG,CAAC,EAAE,CAC5D,CAAC;AACH,CAAC"}
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c9up/rover",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Mail transport for Ream — SMTP, log, and pluggable transports",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -102,7 +102,8 @@
102
102
  },
103
103
  "scripts": {
104
104
  "build": "tsc -p tsconfig.build.json",
105
- "build:napi": "cargo build --release -p rover-template-engine-napi && node scripts/copy-napi.mjs",
105
+ "build:napi": "cargo build --release -p rover-template-engine-napi && pnpm build:napi-types && node scripts/copy-napi.mjs",
106
+ "build:napi-types": "node scripts/build-napi-types.mjs",
106
107
  "test": "vitest run",
107
108
  "lint": "biome check src/",
108
109
  "test:coverage": "vitest run --coverage",
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Regenerate `src/native/generated.ts` from the Rust.
4
+ *
5
+ * Node rather than a shell script because this runs inside `build:napi`, and
6
+ * that runs on the Windows prebuild runner too: a bash `mktemp` there hands
7
+ * cargo a `/tmp/...` path the native proc-macro cannot write to, so the
8
+ * type-def file comes back empty and the build fails for no visible reason.
9
+ *
10
+ * One crate at a time on purpose: napi-derive APPENDS to `TYPE_DEF_TMP_PATH`
11
+ * while cargo compiles, and a parallel build interleaves the writes —
12
+ * definitions go missing, silently, and the generated file comes out short.
13
+ */
14
+
15
+ import { execFileSync } from 'node:child_process'
16
+ import { createRequire } from 'node:module'
17
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
18
+ import { tmpdir } from 'node:os'
19
+ import { dirname, join } from 'node:path'
20
+ import { fileURLToPath } from 'node:url'
21
+
22
+ const CRATES = ['rover-template-engine-napi']
23
+
24
+ const packageRoot = join(dirname(fileURLToPath(import.meta.url)), '..')
25
+ const output = join('src', 'native', 'generated.ts')
26
+ const scratch = mkdtempSync(join(tmpdir(), 'napi-types-'))
27
+
28
+ try {
29
+ const lines = []
30
+ for (const crate of CRATES) {
31
+ const perCrate = join(scratch, `${crate}.jsonl`)
32
+ writeFileSync(perCrate, '')
33
+ execFileSync('cargo', ['build', '-p', crate], {
34
+ cwd: packageRoot,
35
+ env: { ...process.env, TYPE_DEF_TMP_PATH: perCrate },
36
+ stdio: ['ignore', 'ignore', 'inherit'],
37
+ })
38
+ const emitted = readFileSync(perCrate, 'utf8').split('\n').filter(Boolean)
39
+ if (emitted.length === 0) {
40
+ throw new Error(
41
+ `[napi-types] ${crate} emitted nothing — is napi-derive's "type-def" feature on?`,
42
+ )
43
+ }
44
+ lines.push(...emitted)
45
+ }
46
+
47
+ const combined = join(scratch, 'combined.jsonl')
48
+ writeFileSync(combined, `${lines.join('\n')}\n`)
49
+
50
+ execFileSync(
51
+ process.execPath,
52
+ [join('scripts', 'generate-napi-types.mjs'), combined, output],
53
+ { cwd: packageRoot, stdio: 'inherit' },
54
+ )
55
+
56
+ // Formatted here rather than excluded from the linter: the file is checked
57
+ // in, so it should read like the rest of the tree — and formatting it at
58
+ // generation means it never shows up as a diff someone has to fix by hand.
59
+ // Resolved through the package entry rather than `node_modules/.bin`, whose
60
+ // shim is a shell script the Windows runner cannot execute directly.
61
+ const biome = createRequire(import.meta.url).resolve('@biomejs/biome/bin/biome')
62
+ execFileSync(process.execPath, [biome, 'format', '--write', output], {
63
+ cwd: packageRoot,
64
+ stdio: ['ignore', 'ignore', 'inherit'],
65
+ })
66
+ } finally {
67
+ rmSync(scratch, { recursive: true, force: true })
68
+ }
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Generate the TypeScript surface of the native module FROM the Rust.
4
+ *
5
+ * `napi-derive`'s `type-def` feature emits one JSON line per exported item
6
+ * while cargo compiles. Those lines are the source of truth: they are derived
7
+ * from the `#[napi]` items themselves, so a signature cannot drift from the
8
+ * Rust without this file changing.
9
+ *
10
+ * Hand-written interfaces are what this replaces, and they do drift — nothing
11
+ * on the TypeScript side notices when a `pub fn` gains a parameter or stops
12
+ * being `async`.
13
+ *
14
+ * One thing napi-rs cannot infer: the shape of a `JsFunction` callback. It
15
+ * emits `(...args: any[]) => any`. Any such parameter is refined below, by
16
+ * name, and the script fails if a refinement no longer matches anything — so
17
+ * the table cannot rot either.
18
+ *
19
+ * TYPE_DEF_TMP_PATH=<file> cargo build -p <crate>
20
+ * node scripts/generate-napi-types.mjs <file> <out.d.ts>
21
+ */
22
+
23
+ import { readFileSync, writeFileSync } from 'node:fs'
24
+
25
+ /**
26
+ * Callback signatures napi-rs erases to `any`, restored here.
27
+ *
28
+ * Keyed by `<owner>.<method>`; the value replaces the whole parameter. Every
29
+ * entry must match, or the script fails: a stale refinement is how a hand
30
+ * annotation quietly stops describing the Rust.
31
+ *
32
+ * Empty while this crate exposes no `JsFunction` parameter — add an entry the
33
+ * day one appears, rather than letting an `any` through.
34
+ */
35
+ const CALLBACK_REFINEMENTS = {}
36
+
37
+ const [input, output] = process.argv.slice(2)
38
+ if (!input || !output) {
39
+ console.error('usage: generate-napi-types.mjs <type-def file> <out.d.ts>')
40
+ process.exit(2)
41
+ }
42
+
43
+ const entries = readFileSync(input, 'utf8')
44
+ .split('\n')
45
+ .map((l) => l.trim())
46
+ .filter(Boolean)
47
+ .map((l) => JSON.parse(l))
48
+
49
+ const used = new Set()
50
+
51
+ /** Apply the refinements that belong to `owner`, tracking which ones matched. */
52
+ function refine(owner, body) {
53
+ let out = body
54
+ for (const [key, { from, to }] of Object.entries(CALLBACK_REFINEMENTS)) {
55
+ const [entryOwner] = key.split('.')
56
+ if (entryOwner !== owner) continue
57
+ if (out.includes(from)) {
58
+ out = out.replace(from, to)
59
+ used.add(key)
60
+ }
61
+ }
62
+ return out
63
+ }
64
+
65
+ /**
66
+ * JSDoc as emitted by napi-derive, indented to sit above its member.
67
+ *
68
+ * `*` followed by `/` inside the text closes the comment early — a Rust doc
69
+ * example holding a cron expression (`0 *​/5 * * *`) is enough to do it, and
70
+ * the generated file then fails to parse. Escaped rather than stripped, so the
71
+ * example still reads correctly.
72
+ */
73
+ function docBlock(doc, indent = '') {
74
+ if (!doc) return ''
75
+ // Escape every `*/` EXCEPT the one that closes the block. A Rust doc example
76
+ // holding a cron expression (`0 */5 * * *`) closes the comment early
77
+ // otherwise, and the generated file stops parsing — but escaping the closer
78
+ // too breaks it just as thoroughly, whether the block spans one line or many.
79
+ const closer = doc.lastIndexOf('*/')
80
+ const escaped =
81
+ closer === -1
82
+ ? doc
83
+ : doc.slice(0, closer).replaceAll('*/', '*\\/') + doc.slice(closer)
84
+ return (
85
+ escaped
86
+ .split('\n')
87
+ .filter((l) => l.length > 0)
88
+ .map((l) => `${indent}${l}`)
89
+ .join('\n') + '\n'
90
+ )
91
+ }
92
+
93
+ const interfaces = entries.filter((e) => e.kind === 'interface')
94
+ const structs = entries.filter((e) => e.kind === 'struct')
95
+ const impls = new Map(entries.filter((e) => e.kind === 'impl').map((e) => [e.name, e]))
96
+ const fns = entries.filter((e) => e.kind === 'fn')
97
+
98
+ const out = [
99
+ '// GENERATED FROM THE RUST — do not edit.',
100
+ '//',
101
+ "// Produced by scripts/generate-napi-types.mjs from napi-derive's type-def",
102
+ '// output. Editing this file by hand puts it back where it started: a',
103
+ '// description that can disagree with the code it describes.',
104
+ '',
105
+ ]
106
+
107
+ for (const iface of interfaces) {
108
+ out.push(docBlock(iface.js_doc))
109
+ out.push(`export interface ${iface.name} {`)
110
+ for (const line of iface.def.split('\n')) {
111
+ out.push(line ? ` ${line.trim()}` : '')
112
+ }
113
+ out.push('}', '')
114
+ }
115
+
116
+ for (const struct of structs) {
117
+ const impl = impls.get(struct.name)
118
+ out.push(docBlock(struct.js_doc))
119
+ out.push(`export declare class ${struct.name} {`)
120
+ if (impl) {
121
+ for (const line of refine(struct.name, impl.def).split('\n')) {
122
+ out.push(line ? ` ${line.trim()}` : '')
123
+ }
124
+ }
125
+ out.push('}', '')
126
+ }
127
+
128
+ for (const fn of fns) {
129
+ out.push(docBlock(fn.js_doc))
130
+ // napi-derive emits the whole declaration for a function, unlike a struct
131
+ // where `def` holds only the members.
132
+ const declaration = fn.def.trim()
133
+ out.push(
134
+ declaration.startsWith('export declare function')
135
+ ? `${declaration};`
136
+ : `export declare function ${fn.name}${declaration};`,
137
+ '',
138
+ )
139
+ }
140
+
141
+ const stale = Object.keys(CALLBACK_REFINEMENTS).filter((k) => !used.has(k))
142
+ if (stale.length > 0) {
143
+ console.error(
144
+ `[napi-types] refinement(s) that matched nothing: ${stale.join(', ')}\n` +
145
+ '[napi-types] the Rust changed under them — update or remove the entry.',
146
+ )
147
+ process.exit(1)
148
+ }
149
+
150
+ writeFileSync(output, out.join('\n'))
151
+ console.log(
152
+ `[napi-types] ${output} — ${interfaces.length} interface(s), ${structs.length} class(es), ${fns.length} function(s)`,
153
+ )
@@ -0,0 +1,46 @@
1
+ // GENERATED FROM THE RUST — do not edit.
2
+ //
3
+ // Produced by scripts/generate-napi-types.mjs from napi-derive's type-def
4
+ // output. Editing this file by hand puts it back where it started: a
5
+ // description that can disagree with the code it describes.
6
+
7
+ /**
8
+ * Opaque handle to a compiled template IR. The TS-side `cache` keeps these
9
+ * instances alive; when the JS GC collects the wrapper, napi-rs drops the
10
+ * inner `Arc` automatically (Arc + GC bridge — no manual dispose API).
11
+ */
12
+
13
+ export declare class RoverIr {
14
+ /**
15
+ * Every referenced partial name, in document order (descends into
16
+ * `{{#if}}` bodies). Drives the TS facade's transitive partial map build.
17
+ */
18
+ get partialNames(): Array<string>;
19
+ }
20
+
21
+ /** Compile a template source string into an opaque `RoverIr` handle. */
22
+
23
+ export declare function compile(source: string): RoverIr;
24
+
25
+ /**
26
+ * Render a compiled IR against `data` (a JSON string), resolving `{{> name}}`
27
+ * partials from the pre-resolved `partials` map. Render-time recursion ->
28
+ * `MAIL_TEMPLATE_RECURSION`.
29
+ *
30
+ * `data` crosses as a JSON STRING (the TS facade calls `JSON.stringify`), not
31
+ * as an object graph: `JSON.stringify` is own-enumerable-only, which preserves
32
+ * the engine's `Object.hasOwn` dot-path contract (inherited prototype-chain
33
+ * props must NOT be visible — `simple-template.test.ts:195-201`). It is also a
34
+ * single native stringify + one Rust parse, instead of napi walking the whole
35
+ * object graph (which would additionally surface inherited enumerable props).
36
+ */
37
+
38
+ export declare function renderIr(
39
+ ir: RoverIr,
40
+ dataJson: string,
41
+ partials: Record<string, RoverIr>,
42
+ ): string;
43
+
44
+ /** Crate version — useful for the TS-side `loadNapi.ts` startup diagnostic. */
45
+
46
+ export declare function engineVersion(): string;
@@ -36,20 +36,18 @@ function platformSuffix(): string {
36
36
  }
37
37
 
38
38
  /** Opaque handle to a compiled template IR (Rust `RoverIr`). */
39
- export interface NativeRoverIr {
40
- /** Referenced partial names, in document order (descends into if-bodies). */
41
- readonly partialNames: readonly string[];
42
- }
39
+ export type NativeRoverIr = import("../native/generated.js").RoverIr;
43
40
 
44
- interface NativeExports {
45
- readonly engineVersion: () => string;
46
- readonly compile: (source: string) => NativeRoverIr;
47
- readonly renderIr: (
48
- ir: NativeRoverIr,
49
- dataJson: string,
50
- partials: Record<string, NativeRoverIr>,
51
- ) => string;
52
- }
41
+ /**
42
+ * The engine's surface, as the Rust declares it.
43
+ *
44
+ * Derived from `../native/generated.js` — written by `pnpm build:napi-types`
45
+ * from napi-derive's own `type-def` output — rather than restated here, where
46
+ * nothing would notice a `pub fn` gaining a parameter or changing its return.
47
+ * The runtime guard below still checks the three exports are actually there:
48
+ * a declaration says what the Rust promises, not what a stale binary shipped.
49
+ */
50
+ type NativeExports = typeof import("../native/generated.js");
53
51
 
54
52
  function isNativeExports(value: unknown): value is NativeExports {
55
53
  if (value === null || typeof value !== "object") return false;
@@ -351,7 +351,7 @@ export function mailFake(mailer: FakeableMailer): Plugin {
351
351
  }
352
352
 
353
353
  // Typing side of the plugin — importing `@c9up/rover/testing` augments the
354
- // helix test context with `mail` (the Japa pattern).
354
+ // helix test context with `mail` (the helix pattern).
355
355
  declare module "@c9up/helix" {
356
356
  interface TestContext {
357
357
  mail: FakeMail;