mnfst-types 0.1.8 → 0.1.10
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/README.md +16 -1
- package/manifest.types.mjs +137 -46
- package/package.json +1 -1
- package/template/manifest.d.ts +323 -50
package/README.md
CHANGED
|
@@ -18,14 +18,29 @@ This writes `manifest.d.ts` in the current directory. Re-run it whenever you add
|
|
|
18
18
|
--manifest <path> Path to manifest.json (default: ./manifest.json)
|
|
19
19
|
--out <path> Output .d.ts path (default: ./manifest.d.ts)
|
|
20
20
|
--init Also write a baseline jsconfig.json (only if missing)
|
|
21
|
+
--ci Also write .github/workflows/types.yml (only if missing)
|
|
22
|
+
--check Exit 1 if the output is out of date; write nothing
|
|
21
23
|
-h, --help Show usage
|
|
22
24
|
```
|
|
23
25
|
|
|
26
|
+
## Type checks without a build
|
|
27
|
+
|
|
28
|
+
`--init` writes a `jsconfig.json` whose `paths` mirror the page's import map,
|
|
29
|
+
so JSDoc-annotated app modules type-check with no build step:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx mnfst-types --init
|
|
33
|
+
npx -p typescript@7 tsc -p jsconfig.json
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`--ci` adds a GitHub Actions workflow running `mnfst-types --check` and `tsc`
|
|
37
|
+
on every push. See https://manifestx.dev/docs/framework/getting-started/type-checks.
|
|
38
|
+
|
|
24
39
|
## How it works
|
|
25
40
|
|
|
26
41
|
1. Reads `manifest.json` and walks each entry under `data`.
|
|
27
42
|
2. For local CSV / JSON / YAML sources, samples the first ~50 rows to infer field types.
|
|
28
|
-
3. For Appwrite-table sources,
|
|
43
|
+
3. For Appwrite-table sources, types rows from the column names in the project's shared contract (manifest.json `contract`); `ManifestRows` overrides them with precise types.
|
|
29
44
|
4. For Appwrite-bucket sources, types the source as `ManifestBucketSource`.
|
|
30
45
|
5. Combines the inferred row types with the static ambient declarations and writes a single `manifest.d.ts`.
|
|
31
46
|
|
package/manifest.types.mjs
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
// Re-running the CLI overwrites the augmentation block (between the
|
|
9
9
|
// AUGMENTATION:start / AUGMENTATION:end markers in the template).
|
|
10
10
|
|
|
11
|
-
import { readFileSync, writeFileSync, existsSync, statSync } from 'node:fs';
|
|
12
|
-
import { dirname, join, resolve, isAbsolute } from 'node:path';
|
|
13
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { readFileSync, writeFileSync, existsSync, statSync, mkdirSync } from 'node:fs';
|
|
12
|
+
import { dirname, join, resolve, isAbsolute, relative } from 'node:path';
|
|
13
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
14
14
|
import { createRequire } from 'node:module';
|
|
15
15
|
|
|
16
16
|
const require = createRequire(import.meta.url);
|
|
@@ -45,18 +45,39 @@ export async function main(argv) {
|
|
|
45
45
|
const output = applyAugmentation(template, augmentation);
|
|
46
46
|
|
|
47
47
|
const outPath = resolve(cwd, opts.out);
|
|
48
|
+
if (opts.check) {
|
|
49
|
+
const current = existsSync(outPath) ? readFileSync(outPath, 'utf8') : '';
|
|
50
|
+
if (current !== output) {
|
|
51
|
+
console.error(`mnfst-types: ${opts.out} is out of date with manifest.json — run \`npx mnfst-types\` and commit it`);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.log(`mnfst-types: ${opts.out} is up to date`);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
48
58
|
writeFileSync(outPath, output);
|
|
49
59
|
console.log(`mnfst-types: wrote ${outPath}`);
|
|
50
60
|
|
|
61
|
+
const typesPath = relative(projectRoot, outPath).split('\\').join('/');
|
|
51
62
|
if (opts.init) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
writeOnce(join(projectRoot, 'jsconfig.json'), defaultJsconfig(typesPath, importMapPaths(projectRoot)));
|
|
64
|
+
}
|
|
65
|
+
if (opts.ci) {
|
|
66
|
+
writeOnce(join(projectRoot, '.github', 'workflows', 'types.yml'), defaultWorkflow(typesPath));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function writeOnce(path, content) {
|
|
71
|
+
if (existsSync(path)) {
|
|
72
|
+
console.log(`mnfst-types: ${path} already exists, leaving it alone`);
|
|
73
|
+
if (/"moduleResolution"\s*:\s*"node(10)?"/i.test(readFileSync(path, 'utf8'))) {
|
|
74
|
+
console.warn('mnfst-types: its "moduleResolution": "node" is not supported by TypeScript 7; use "bundler" (delete the file and run --init again for the current defaults)');
|
|
58
75
|
}
|
|
76
|
+
return;
|
|
59
77
|
}
|
|
78
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
79
|
+
writeFileSync(path, content);
|
|
80
|
+
console.log(`mnfst-types: wrote ${path}`);
|
|
60
81
|
}
|
|
61
82
|
|
|
62
83
|
function parseArgs(argv) {
|
|
@@ -64,12 +85,16 @@ function parseArgs(argv) {
|
|
|
64
85
|
manifest: 'manifest.json',
|
|
65
86
|
out: 'manifest.d.ts',
|
|
66
87
|
init: false,
|
|
88
|
+
ci: false,
|
|
89
|
+
check: false,
|
|
67
90
|
help: false
|
|
68
91
|
};
|
|
69
92
|
for (let i = 0; i < argv.length; i++) {
|
|
70
93
|
const a = argv[i];
|
|
71
94
|
if (a === '--help' || a === '-h') opts.help = true;
|
|
72
95
|
else if (a === '--init') opts.init = true;
|
|
96
|
+
else if (a === '--ci') opts.ci = true;
|
|
97
|
+
else if (a === '--check') opts.check = true;
|
|
73
98
|
else if (a === '--manifest') opts.manifest = argv[++i];
|
|
74
99
|
else if (a === '--out') opts.out = argv[++i];
|
|
75
100
|
else if (a.startsWith('--manifest=')) opts.manifest = a.slice('--manifest='.length);
|
|
@@ -88,30 +113,68 @@ Options:
|
|
|
88
113
|
--manifest <path> Path to manifest.json (default: ./manifest.json)
|
|
89
114
|
--out <path> Output .d.ts path (default: ./manifest.d.ts)
|
|
90
115
|
--init Also write a baseline jsconfig.json (only if missing)
|
|
116
|
+
--ci Also write .github/workflows/types.yml (only if missing)
|
|
117
|
+
--check Exit 1 if the output file is out of date; write nothing
|
|
91
118
|
-h, --help Show this message
|
|
92
119
|
`);
|
|
93
120
|
}
|
|
94
121
|
|
|
95
|
-
|
|
122
|
+
// index.html's import map as jsconfig paths: "@app/": "/app/" → "@app/*": ["./app/*"]
|
|
123
|
+
function importMapPaths(projectRoot) {
|
|
124
|
+
const paths = {};
|
|
125
|
+
let html = '';
|
|
126
|
+
try { html = readFileSync(join(projectRoot, 'index.html'), 'utf8'); } catch { return paths; }
|
|
127
|
+
const m = html.match(/<script[^>]*type=["']importmap["'][^>]*>([\s\S]*?)<\/script>/i);
|
|
128
|
+
if (!m) return paths;
|
|
129
|
+
let map;
|
|
130
|
+
try { map = JSON.parse(m[1]); } catch { return paths; }
|
|
131
|
+
for (const [key, target] of Object.entries((map && map.imports) || {})) {
|
|
132
|
+
if (typeof target !== 'string' || /^[a-z]+:|^\/\//i.test(target)) continue;
|
|
133
|
+
const local = '.' + (target.startsWith('/') ? target : '/' + target);
|
|
134
|
+
if (key.endsWith('/') && local.endsWith('/')) paths[key + '*'] = [local + '*'];
|
|
135
|
+
else paths[key] = [local];
|
|
136
|
+
}
|
|
137
|
+
return paths;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function defaultJsconfig(types, aliases = {}) {
|
|
96
141
|
return JSON.stringify({
|
|
97
142
|
compilerOptions: {
|
|
98
143
|
target: 'es2022',
|
|
99
|
-
module: '
|
|
100
|
-
moduleResolution: '
|
|
144
|
+
module: 'esnext',
|
|
145
|
+
moduleResolution: 'bundler',
|
|
101
146
|
checkJs: true,
|
|
102
147
|
allowJs: true,
|
|
103
148
|
noEmit: true,
|
|
104
149
|
strict: false,
|
|
105
|
-
|
|
150
|
+
skipLibCheck: true,
|
|
151
|
+
lib: ['es2022', 'dom', 'dom.iterable'],
|
|
152
|
+
paths: { mnfst: [`./${types}`], ...aliases }
|
|
106
153
|
},
|
|
107
|
-
include: ['
|
|
108
|
-
exclude: ['node_modules', '
|
|
109
|
-
}, null,
|
|
154
|
+
include: ['app/**/*', 'shared/**/*', types, '*.d.ts'],
|
|
155
|
+
exclude: ['node_modules', 'website']
|
|
156
|
+
}, null, 4) + '\n';
|
|
110
157
|
}
|
|
111
158
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
159
|
+
function defaultWorkflow(out) {
|
|
160
|
+
return [
|
|
161
|
+
'name: Types',
|
|
162
|
+
'',
|
|
163
|
+
'on: [push, pull_request]',
|
|
164
|
+
'',
|
|
165
|
+
'jobs:',
|
|
166
|
+
' check:',
|
|
167
|
+
' runs-on: ubuntu-latest',
|
|
168
|
+
' steps:',
|
|
169
|
+
' - uses: actions/checkout@v4',
|
|
170
|
+
' - uses: actions/setup-node@v4',
|
|
171
|
+
' with:',
|
|
172
|
+
' node-version: 22',
|
|
173
|
+
` - run: npx -y mnfst-types@latest --check --out ${out}`,
|
|
174
|
+
' - run: npx -y -p typescript@7 tsc -p jsconfig.json',
|
|
175
|
+
''
|
|
176
|
+
].join('\n');
|
|
177
|
+
}
|
|
115
178
|
|
|
116
179
|
const START_MARKER = '// AUGMENTATION:start';
|
|
117
180
|
const END_MARKER = '// AUGMENTATION:end';
|
|
@@ -149,22 +212,18 @@ function applyAugmentation(template, body) {
|
|
|
149
212
|
async function buildAugmentation(manifest, projectRoot) {
|
|
150
213
|
const data = manifest && typeof manifest === 'object' ? manifest.data : null;
|
|
151
214
|
if (!data || typeof data !== 'object' || Object.keys(data).length === 0) {
|
|
152
|
-
return [
|
|
153
|
-
'declare global {',
|
|
154
|
-
' // No data sources declared in manifest.json.',
|
|
155
|
-
'}',
|
|
156
|
-
'export {};'
|
|
157
|
-
].join('\n');
|
|
215
|
+
return '// No data sources declared in manifest.json.\nexport interface ManifestSources { [sourceName: string]: any }';
|
|
158
216
|
}
|
|
159
217
|
|
|
218
|
+
const contract = await loadContract(manifest, projectRoot);
|
|
160
219
|
const sourceTypes = [];
|
|
161
220
|
const augmentations = [];
|
|
162
221
|
|
|
163
222
|
for (const [name, config] of Object.entries(data)) {
|
|
164
|
-
const inferred = await inferSourceType(name, config, projectRoot);
|
|
223
|
+
const inferred = await inferSourceType(name, config, projectRoot, manifest, contract);
|
|
165
224
|
if (!inferred) continue;
|
|
166
225
|
sourceTypes.push(inferred.typeBlock);
|
|
167
|
-
augmentations.push(`
|
|
226
|
+
augmentations.push(` ${jsonKey(name)}: ${inferred.augmentationType};`);
|
|
168
227
|
}
|
|
169
228
|
|
|
170
229
|
const lines = [];
|
|
@@ -176,21 +235,46 @@ async function buildAugmentation(manifest, projectRoot) {
|
|
|
176
235
|
lines.push(block);
|
|
177
236
|
lines.push('');
|
|
178
237
|
}
|
|
179
|
-
lines.push('
|
|
180
|
-
lines.push(' interface ManifestSources {');
|
|
238
|
+
lines.push('export interface ManifestSources {');
|
|
181
239
|
lines.push.apply(lines, augmentations);
|
|
182
|
-
lines.push('
|
|
240
|
+
lines.push(' /** Sources added at runtime ($x.$register) or since the last generation. */');
|
|
241
|
+
lines.push(' [sourceName: string]: any;');
|
|
183
242
|
lines.push('}');
|
|
184
|
-
lines.push('');
|
|
185
|
-
lines.push('export {};');
|
|
186
243
|
return lines.join('\n');
|
|
187
244
|
}
|
|
188
245
|
|
|
246
|
+
// The project's shared contract (manifest.json `contract`), for Appwrite column names
|
|
247
|
+
async function loadContract(manifest, projectRoot) {
|
|
248
|
+
const c = manifest.contract;
|
|
249
|
+
const ref = c && typeof c === 'object' ? c.module : c;
|
|
250
|
+
if (typeof ref !== 'string' || !ref) return null;
|
|
251
|
+
const file = resolve(projectRoot, ref.replace(/^\/+/, ''));
|
|
252
|
+
if (!existsSync(file)) {
|
|
253
|
+
console.warn(`mnfst-types: contract ${ref} not found; Appwrite rows stay loose`);
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
const mod = await import(`${pathToFileURL(file).href}?mtime=${statSync(file).mtimeMs}`);
|
|
258
|
+
return mod && mod.tables && typeof mod.tables === 'object' ? mod.tables : null;
|
|
259
|
+
} catch (e) {
|
|
260
|
+
console.warn(`mnfst-types: contract ${ref} failed to load (${e.message}); Appwrite rows stay loose`);
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function contractColumns(tables, manifest, config) {
|
|
266
|
+
if (!tables) return null;
|
|
267
|
+
const defaultDb = manifest.appwrite && (manifest.appwrite.databaseId || manifest.appwrite.database);
|
|
268
|
+
const db = config.appwriteDatabaseId || defaultDb;
|
|
269
|
+
const hit = Object.entries(tables).find(([key, t]) => t && (t.id || key) === config.appwriteTableId && (!t.database || !db || t.database === db));
|
|
270
|
+
return hit && Array.isArray(hit[1].columns) ? { key: hit[0], columns: hit[1].columns.filter((c) => typeof c === 'string') } : null;
|
|
271
|
+
}
|
|
272
|
+
|
|
189
273
|
// ---------------------------------------------------------------------------
|
|
190
274
|
// Source-shape inference
|
|
191
275
|
// ---------------------------------------------------------------------------
|
|
192
276
|
|
|
193
|
-
async function inferSourceType(name, config, projectRoot) {
|
|
277
|
+
async function inferSourceType(name, config, projectRoot, manifest = {}, contract = null) {
|
|
194
278
|
const safeName = toTypeName(name);
|
|
195
279
|
|
|
196
280
|
// Appwrite bucket (storage).
|
|
@@ -201,21 +285,24 @@ async function inferSourceType(name, config, projectRoot) {
|
|
|
201
285
|
};
|
|
202
286
|
}
|
|
203
287
|
|
|
204
|
-
// Appwrite table.
|
|
288
|
+
// Appwrite table: column names from the contract when it declares the table.
|
|
205
289
|
if (config && typeof config === 'object' && config.appwriteTableId) {
|
|
206
290
|
const rowType = `Row_${safeName}`;
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
291
|
+
const declared = contractColumns(contract, manifest, config);
|
|
292
|
+
const typeBlock = declared
|
|
293
|
+
? [
|
|
294
|
+
`/** Row shape for $x.${name}: columns of "${declared.key}" in the contract (declare ManifestRows.${name} for precise types). */`,
|
|
295
|
+
`export type ${rowType} = ManifestRowSystem & {`,
|
|
296
|
+
...declared.columns.map((c) => ` ${jsonKey(c)}: any;`),
|
|
297
|
+
`};`
|
|
298
|
+
].join('\n')
|
|
299
|
+
: [
|
|
300
|
+
`/** Row shape for $x.${name} (Appwrite table; add it to the contract, or declare ManifestRows.${name}, for checked columns). */`,
|
|
301
|
+
`export type ${rowType} = ManifestRowSystem & { [field: string]: any };`
|
|
302
|
+
].join('\n');
|
|
216
303
|
return {
|
|
217
304
|
typeBlock,
|
|
218
|
-
augmentationType: `
|
|
305
|
+
augmentationType: `ManifestTableSource<ManifestRowFor<${JSON.stringify(name)}, ${rowType}>>`
|
|
219
306
|
};
|
|
220
307
|
}
|
|
221
308
|
|
|
@@ -336,8 +423,12 @@ function sampleCsv(path) {
|
|
|
336
423
|
const sampleRows = rows.slice(1, 51);
|
|
337
424
|
const firstHeader = (header[0] || '').toLowerCase();
|
|
338
425
|
|
|
339
|
-
//
|
|
340
|
-
|
|
426
|
+
// Same rule as the runtime: a table only when the first header is `id`, there
|
|
427
|
+
// are 3+ columns and most of the first values look like ids; else key → value
|
|
428
|
+
const idLike = (v) => !!v && (/^\d+$/.test(v) || (v.length < 20 && !v.includes('.')));
|
|
429
|
+
const firstFive = sampleRows.slice(0, 5);
|
|
430
|
+
const tabular = header.length > 2 && firstHeader === 'id' && firstFive.filter((r) => idLike(r[0])).length >= firstFive.length * 0.6;
|
|
431
|
+
if (!tabular) {
|
|
341
432
|
const shape = {};
|
|
342
433
|
for (const row of sampleRows) {
|
|
343
434
|
if (!row[0]) continue;
|
package/package.json
CHANGED
package/template/manifest.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
/** Appwrite-style query expression returned by helper builders. */
|
|
18
18
|
export type ManifestQueryExpr = string;
|
|
19
19
|
|
|
20
|
-
/** Appwrite-style query helpers
|
|
20
|
+
/** Appwrite-style query helpers. */
|
|
21
21
|
export interface ManifestQuery {
|
|
22
22
|
equal(field: string, value: unknown): ManifestQueryExpr;
|
|
23
23
|
notEqual(field: string, value: unknown): ManifestQueryExpr;
|
|
@@ -41,81 +41,211 @@ export interface ManifestQuery {
|
|
|
41
41
|
cursorBefore(id: string): ManifestQueryExpr;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/** A column of row type `T` (or a dot path into a relationship). Any string when `T` is loose. */
|
|
45
|
+
export type ManifestColumn<T> = string extends keyof T ? string : (keyof T & string) | `${keyof T & string}.${string}`;
|
|
46
|
+
|
|
47
|
+
type ManifestCompare = 'equal' | 'notEqual' | 'greaterThan' | 'greaterThanOrEqual' | 'greaterThanEqual'
|
|
48
|
+
| 'lessThan' | 'lessThanOrEqual' | 'lessThanEqual' | 'contains' | 'startsWith' | 'endsWith' | 'search';
|
|
49
|
+
|
|
50
|
+
/** One `$query` expression: `[method, column, ...values]`. Column names are checked against the row type. */
|
|
51
|
+
export type ManifestQueryTuple<T = any> =
|
|
52
|
+
| [ManifestCompare, ManifestColumn<T>, ...unknown[]]
|
|
53
|
+
| ['between', ManifestColumn<T>, unknown, unknown]
|
|
54
|
+
| ['isNull' | 'isNotNull' | 'orderAsc' | 'orderDesc', ManifestColumn<T>]
|
|
55
|
+
| ['orderRandom']
|
|
56
|
+
| ['limit' | 'offset', number]
|
|
57
|
+
| ['cursorAfter' | 'cursorBefore', string]
|
|
58
|
+
| ['or', ManifestQueryTuple<T>[]];
|
|
59
|
+
|
|
44
60
|
/** State flags exposed on every data source (array or object). */
|
|
45
61
|
export interface ManifestSourceState {
|
|
46
|
-
/** True
|
|
62
|
+
/** True during a fetch or mutation. */
|
|
47
63
|
readonly $loading: boolean;
|
|
48
64
|
/** Last error from a load or mutation, or null. */
|
|
49
|
-
readonly $error:
|
|
50
|
-
/** True once
|
|
65
|
+
readonly $error: string | null;
|
|
66
|
+
/** True once the source has settled (loaded, or resolved empty because its scope can't apply). */
|
|
51
67
|
readonly $ready: boolean;
|
|
52
|
-
|
|
68
|
+
/** True while cached rows show and fresh data is still loading. */
|
|
69
|
+
readonly $stale: boolean;
|
|
70
|
+
/** Resolves once fresh data has landed. */
|
|
71
|
+
readonly $fresh: Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Fields Appwrite adds to every row. */
|
|
75
|
+
export interface ManifestRowSystem {
|
|
76
|
+
$id: string;
|
|
77
|
+
$createdAt: string;
|
|
78
|
+
$updatedAt: string;
|
|
79
|
+
$sequence?: number;
|
|
80
|
+
$permissions?: string[];
|
|
81
|
+
$tableId?: string;
|
|
82
|
+
$databaseId?: string;
|
|
83
|
+
/** Files linked to the row when the source configures `storage`. */
|
|
84
|
+
$files?: ManifestFile[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A file row from an Appwrite bucket source. */
|
|
88
|
+
export interface ManifestFile {
|
|
89
|
+
$id: string;
|
|
90
|
+
name: string;
|
|
91
|
+
mimeType: string;
|
|
92
|
+
sizeOriginal: number;
|
|
93
|
+
$createdAt: string;
|
|
94
|
+
$updatedAt: string;
|
|
95
|
+
readonly $url?: string;
|
|
96
|
+
readonly $isImage?: boolean;
|
|
97
|
+
readonly $isPdf?: boolean;
|
|
98
|
+
readonly $formattedSize?: string | null;
|
|
99
|
+
readonly $thumbnailUrl?: string | null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Search weights: `{ title: 3, body: 1 }`. */
|
|
103
|
+
export type ManifestSearchWeights<T> = Partial<Record<ManifestColumn<T>, number>>;
|
|
53
104
|
|
|
54
105
|
/** Operators available on array-shaped sources (CSV tabular, JSON arrays, Appwrite tables). */
|
|
55
106
|
export interface ManifestArrayOps<T> {
|
|
56
|
-
/** Substring match across the given fields
|
|
57
|
-
$search(term: string, ...fields:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
$
|
|
63
|
-
/** Look up a single row whose `id` matches the current route param, if any. */
|
|
64
|
-
$route(path?: string): T | undefined;
|
|
107
|
+
/** Substring match across the given fields, or a ranked search with field weights. */
|
|
108
|
+
$search(term: string, ...fields: ManifestColumn<T>[]): ManifestArraySource<T>;
|
|
109
|
+
$search(term: string, weights: ManifestSearchWeights<T>): ManifestArraySource<T>;
|
|
110
|
+
/** Local sources: filter synchronously (chainable with `$search`). */
|
|
111
|
+
$query(queries: ManifestQueryTuple<T>[]): ManifestArraySource<T>;
|
|
112
|
+
/** The row whose `field` matches a segment of the current URL. */
|
|
113
|
+
$route(field?: ManifestColumn<T>): T | undefined;
|
|
65
114
|
}
|
|
66
115
|
|
|
67
|
-
/**
|
|
116
|
+
/** A cursor page from `$first`, `$next` and `$prev`. */
|
|
117
|
+
export interface ManifestCursorPage<T> {
|
|
118
|
+
items: T[];
|
|
119
|
+
cursor: string | null;
|
|
120
|
+
total: number;
|
|
121
|
+
hasMore: boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** An offset page from `$page`. */
|
|
125
|
+
export interface ManifestOffsetPage<T> {
|
|
126
|
+
items: T[];
|
|
127
|
+
page: number;
|
|
128
|
+
total: number;
|
|
129
|
+
totalPages: number;
|
|
130
|
+
hasMore: boolean;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** `$update` list form: one entry per row. */
|
|
134
|
+
export type ManifestUpdateList<T> = Array<{ id?: string; $id?: string; data: Partial<T> }>;
|
|
135
|
+
|
|
136
|
+
/** Options for `$duplicate` on table rows: field overrides plus copy controls. */
|
|
137
|
+
export type ManifestDuplicateOptions<T> = Partial<T> & { newRowId?: string; files?: 'duplicate' | 'same' | 'none' };
|
|
138
|
+
|
|
139
|
+
/** Reads, mutations and paging on Appwrite-table sources. */
|
|
68
140
|
export interface ManifestAppwriteTableOps<T> {
|
|
69
|
-
|
|
70
|
-
$
|
|
71
|
-
$
|
|
72
|
-
|
|
141
|
+
/** Server-side query with expressions or a named query from manifest.json; replaces the source's rows. */
|
|
142
|
+
$query(queriesOrName: ManifestQueryTuple<T>[] | string): Promise<T[]>;
|
|
143
|
+
$create(values: Partial<T>, rowId?: string): Promise<T>;
|
|
144
|
+
/** One row by id, several by ids, or a list of `{ id, data }` (no second argument). */
|
|
145
|
+
$update<I extends string | string[] | ManifestUpdateList<T>>(
|
|
146
|
+
target: I,
|
|
147
|
+
...values: 0 extends (1 & I) ? [values?: Partial<T>] : I extends ManifestUpdateList<T> ? [] : [values: Partial<T>]
|
|
148
|
+
): Promise<0 extends (1 & I) ? T : I extends string ? T : T[]>;
|
|
149
|
+
$delete(id: string): Promise<T>;
|
|
150
|
+
$delete(ids: string[]): Promise<T[]>;
|
|
151
|
+
$duplicate(id: string, options?: ManifestDuplicateOptions<T>): Promise<T>;
|
|
152
|
+
$first(limit?: number): Promise<ManifestCursorPage<T>>;
|
|
153
|
+
$next(cursor: string, limit?: number): Promise<ManifestCursorPage<T>>;
|
|
154
|
+
$prev(cursor: string, limit?: number): Promise<ManifestCursorPage<T>>;
|
|
155
|
+
$page(page: number, limit?: number): Promise<ManifestOffsetPage<T>>;
|
|
156
|
+
$reload(): Promise<void>;
|
|
157
|
+
/** Realtime events skipped by the growth cap since the last load. */
|
|
158
|
+
readonly $realtimeOverflow: number;
|
|
159
|
+
/** Loads the next page into the source (`paging` sources only); resolves with the rows added. */
|
|
160
|
+
$more(): Promise<number>;
|
|
161
|
+
/** Whether `$more()` can load another page; false at the end or at `max`. */
|
|
162
|
+
readonly $hasMore: boolean;
|
|
163
|
+
/** Appwrite's count for the current filters, or null when not requested. */
|
|
164
|
+
readonly $total: number | null;
|
|
165
|
+
/** True when `$total` hit Appwrite's counting ceiling. */
|
|
166
|
+
readonly $totalCapped: boolean;
|
|
167
|
+
/** Whether a write to row `id` is still unconfirmed. */
|
|
168
|
+
$saving(id: string): boolean;
|
|
169
|
+
/** Rows with an unconfirmed write. */
|
|
170
|
+
readonly $pending: number;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Detail of `manifest:data-mutation-success` / `manifest:data-mutation-error` on window. */
|
|
174
|
+
export interface ManifestMutationDetail {
|
|
175
|
+
mutationId: string;
|
|
176
|
+
type: 'create' | 'update' | 'delete';
|
|
177
|
+
dataSourceName: string;
|
|
178
|
+
entryId?: string;
|
|
179
|
+
result?: unknown;
|
|
180
|
+
error?: unknown;
|
|
73
181
|
}
|
|
74
182
|
|
|
75
183
|
/** Operations available on Appwrite-bucket (storage) sources. */
|
|
76
184
|
export interface ManifestAppwriteBucketOps {
|
|
77
|
-
$url(fileId: string): string;
|
|
78
|
-
$preview(fileId: string,
|
|
79
|
-
$download(fileId: string): string;
|
|
80
|
-
$openUrl(fileId: string): void;
|
|
81
|
-
$openPreview(fileId: string): void;
|
|
82
|
-
$openDownload(fileId: string): void;
|
|
83
|
-
$
|
|
185
|
+
$url(fileId: string, token?: string): string;
|
|
186
|
+
$preview(fileId: string, options?: Record<string, unknown>, token?: string): string;
|
|
187
|
+
$download(fileId: string, token?: string): string;
|
|
188
|
+
$openUrl(fileId: string, token?: string): void;
|
|
189
|
+
$openPreview(fileId: string, options?: Record<string, unknown>, token?: string): void;
|
|
190
|
+
$openDownload(fileId: string, filename?: string, token?: string): void;
|
|
191
|
+
$create(file: File | Blob, fileId?: string, permissions?: string[], onProgress?: (progress: unknown) => void): Promise<ManifestFile>;
|
|
192
|
+
$upload(file: File | Blob, opts?: Record<string, unknown>): Promise<ManifestFile>;
|
|
84
193
|
$remove(fileId: string): Promise<void>;
|
|
85
|
-
$
|
|
194
|
+
$delete(fileId: string | string[]): Promise<unknown>;
|
|
195
|
+
$duplicate(fileId: string, options?: { newName?: string; newFileId?: string }): Promise<ManifestFile>;
|
|
196
|
+
$filesFor(parentId: string, fieldName?: string): ManifestFile[];
|
|
197
|
+
$first(limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
|
|
198
|
+
$next(cursor: string, limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
|
|
199
|
+
$prev(cursor: string, limit?: number): Promise<ManifestCursorPage<ManifestFile>>;
|
|
200
|
+
$page(page: number, limit?: number): Promise<ManifestOffsetPage<ManifestFile>>;
|
|
86
201
|
$unlinkFrom(parentId: string, fileId: string): Promise<void>;
|
|
87
202
|
$removeFrom(parentId: string, fileId: string): Promise<void>;
|
|
88
203
|
}
|
|
89
204
|
|
|
90
205
|
/**
|
|
91
|
-
*
|
|
92
|
-
* Behaves as a regular `T[]`
|
|
93
|
-
* Manifest operators and state flags.
|
|
206
|
+
* `$x.<source>` for an array-of-rows source (CSV tabular, JSON arrays).
|
|
207
|
+
* Behaves as a regular `T[]` plus Manifest operators and state flags.
|
|
94
208
|
*/
|
|
95
209
|
export type ManifestArraySource<T> =
|
|
96
210
|
& ReadonlyArray<T>
|
|
97
211
|
& ManifestSourceState
|
|
98
|
-
& ManifestArrayOps<T
|
|
99
|
-
& Partial<ManifestAppwriteTableOps<T>>;
|
|
212
|
+
& ManifestArrayOps<T>;
|
|
100
213
|
|
|
101
|
-
/**
|
|
214
|
+
/** `$x.<source>` for an Appwrite table: rows plus server-side queries, mutations and paging. */
|
|
215
|
+
export type ManifestTableSource<T> =
|
|
216
|
+
& ReadonlyArray<T>
|
|
217
|
+
& ManifestSourceState
|
|
218
|
+
& Omit<ManifestArrayOps<T>, '$query'>
|
|
219
|
+
& ManifestAppwriteTableOps<T>;
|
|
220
|
+
|
|
221
|
+
/** `$x.<source>` for an object-shaped source (CSV key-value, JSON object, YAML map). */
|
|
102
222
|
export type ManifestObjectSource<T> = T & ManifestSourceState;
|
|
103
223
|
|
|
104
|
-
/**
|
|
105
|
-
export type ManifestBucketSource = ManifestSourceState & ManifestAppwriteBucketOps;
|
|
224
|
+
/** `$x.<source>` for an Appwrite storage bucket. */
|
|
225
|
+
export type ManifestBucketSource = ReadonlyArray<ManifestFile> & ManifestSourceState & ManifestAppwriteBucketOps;
|
|
106
226
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Precise row types, keyed by data source name. Declare them to override the
|
|
229
|
+
* column names `npx mnfst-types` reads from the contract:
|
|
230
|
+
*
|
|
231
|
+
* declare module 'mnfst' { interface ManifestRows { tasks: Task } }
|
|
232
|
+
*/
|
|
233
|
+
export interface ManifestRows { }
|
|
234
|
+
|
|
235
|
+
/** The row type for source `K`: a declared `ManifestRows` entry, else `Fallback`. */
|
|
236
|
+
export type ManifestRowFor<K extends string, Fallback> = K extends keyof ManifestRows ? ManifestRows[K] & ManifestRowSystem : Fallback;
|
|
110
237
|
|
|
111
238
|
/**
|
|
112
|
-
* Project
|
|
113
|
-
* `
|
|
114
|
-
* data (declarations appended below the AUGMENTATION marker).
|
|
239
|
+
* Project data sources, keyed by the names in `manifest.json`'s `data`.
|
|
240
|
+
* `npx mnfst-types` fills this in below the AUGMENTATION marker.
|
|
115
241
|
*/
|
|
116
|
-
export interface ManifestSources {
|
|
117
|
-
|
|
118
|
-
|
|
242
|
+
export interface ManifestSources { }
|
|
243
|
+
|
|
244
|
+
/** `$x` itself: the sources plus runtime registration and persistence controls. */
|
|
245
|
+
export type ManifestData = ManifestSources & {
|
|
246
|
+
$register(name: string, data: unknown[] | Record<string, unknown>): void;
|
|
247
|
+
$wipe(target?: string | { all: true }): Promise<void>;
|
|
248
|
+
};
|
|
119
249
|
|
|
120
250
|
/** `$auth` from the Appwrite auth plugin. Loose by design — auth API is broad. */
|
|
121
251
|
export interface ManifestAuth {
|
|
@@ -194,7 +324,7 @@ export type ManifestRoute = string;
|
|
|
194
324
|
export type ManifestModify = (attr: string) => string | undefined;
|
|
195
325
|
|
|
196
326
|
/** `$try(fn)` — run a callback and swallow any thrown error, returning undefined on failure. */
|
|
197
|
-
export type ManifestTry = <T>(fn: () => T) => T | undefined
|
|
327
|
+
export type ManifestTry = <T>(fn: () => T | Promise<T>, errorVar?: string) => Promise<T | undefined>;
|
|
198
328
|
|
|
199
329
|
/** `$pay` from the payments plugin: callable to start checkout, plus portal/state helpers. */
|
|
200
330
|
export interface ManifestPay {
|
|
@@ -306,7 +436,7 @@ export interface ManifestPush {
|
|
|
306
436
|
[extra: string]: unknown;
|
|
307
437
|
}
|
|
308
438
|
|
|
309
|
-
/** `$secure` from the device plugin —
|
|
439
|
+
/** `$secure` from the device plugin — Keychain/Keystore via a native plugin; unencrypted localStorage on the web only; rejects on native without a plugin. */
|
|
310
440
|
export interface ManifestSecure {
|
|
311
441
|
get(key: string): Promise<string | null>;
|
|
312
442
|
set(key: string, value: string): Promise<void>;
|
|
@@ -342,7 +472,14 @@ export interface ManifestHaptics {
|
|
|
342
472
|
/** `$biometric` from the device plugin. */
|
|
343
473
|
export interface ManifestBiometric {
|
|
344
474
|
available(): Promise<boolean>;
|
|
345
|
-
verify(opts?:
|
|
475
|
+
verify(opts?: {
|
|
476
|
+
reason?: string;
|
|
477
|
+
title?: string;
|
|
478
|
+
subtitle?: string;
|
|
479
|
+
cancelTitle?: string;
|
|
480
|
+
fallbackTitle?: string;
|
|
481
|
+
allowDeviceCredential?: boolean;
|
|
482
|
+
}): Promise<{ verified: boolean; error?: string; code?: string }>;
|
|
346
483
|
}
|
|
347
484
|
|
|
348
485
|
/** `$camera` from the device plugin. */
|
|
@@ -564,7 +701,109 @@ export type ManifestDirective =
|
|
|
564
701
|
| 'x-toast' | 'x-tooltip' | 'x-carousel' | 'x-virtual' | 'x-computed' | 'x-defer'
|
|
565
702
|
| 'x-chart' | 'x-date' | 'x-color' | 'x-colorpicker' | 'x-combobox'
|
|
566
703
|
| 'x-export' | 'x-import' | 'x-pay' | 'x-files' | 'x-data-files'
|
|
567
|
-
| 'x-edit' | 'x-rich-text';
|
|
704
|
+
| 'x-edit' | 'x-rich-text' | 'x-submit';
|
|
705
|
+
|
|
706
|
+
/** Detail of the `submit:sent` / `submit:error` events an `x-submit` form dispatches. */
|
|
707
|
+
export interface ManifestSubmitDetail {
|
|
708
|
+
/** True for a 2xx response whose JSON body is not `{ ok: false }`. */
|
|
709
|
+
ok: boolean;
|
|
710
|
+
/** HTTP status; 0 when the request never reached a server. */
|
|
711
|
+
status: number;
|
|
712
|
+
/** The parsed JSON body, or null. */
|
|
713
|
+
data: any;
|
|
714
|
+
response: Response | null;
|
|
715
|
+
/** Error code (the body's `error`, else 'http_error' or 'network_error'); null when sent. */
|
|
716
|
+
error: string | null;
|
|
717
|
+
message: string;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// ---------------------------------------------------------------------------
|
|
721
|
+
// App modules: components, stores and magics on `this`
|
|
722
|
+
// ---------------------------------------------------------------------------
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Alpine stores, keyed by name. Declare them so `$store.<name>` is checked:
|
|
726
|
+
*
|
|
727
|
+
* declare module 'mnfst' { interface ManifestStores { session: Session } }
|
|
728
|
+
*/
|
|
729
|
+
export interface ManifestStores { [name: string]: any }
|
|
730
|
+
|
|
731
|
+
/** Declared stores keep their types; any other name is `any` until it's declared. */
|
|
732
|
+
export type ManifestStoreMap = ManifestStores;
|
|
733
|
+
|
|
734
|
+
/** Magics available on `this` inside an Alpine component (Alpine's own plus Manifest's). */
|
|
735
|
+
export interface ManifestMagics {
|
|
736
|
+
$el: HTMLElement;
|
|
737
|
+
$root: HTMLElement;
|
|
738
|
+
$refs: Record<string, any>;
|
|
739
|
+
$store: ManifestStoreMap;
|
|
740
|
+
$data: Record<string, any>;
|
|
741
|
+
$watch(property: string, callback: (value: any, oldValue: any) => void): void;
|
|
742
|
+
$dispatch(event: string, detail?: unknown): void;
|
|
743
|
+
$nextTick(callback?: () => void): Promise<void>;
|
|
744
|
+
$id(name: string, key?: string | number): string;
|
|
745
|
+
$x: ManifestData;
|
|
746
|
+
$route: ManifestRoute;
|
|
747
|
+
$modify: ManifestModify;
|
|
748
|
+
$try: ManifestTry;
|
|
749
|
+
$computed<T>(fn: (scope: any) => T): T;
|
|
750
|
+
$auth: ManifestAuth;
|
|
751
|
+
$locale: ManifestLocale;
|
|
752
|
+
$toast: ManifestToast;
|
|
753
|
+
$color: ManifestColor;
|
|
754
|
+
$colorpicker: ManifestColorpicker;
|
|
755
|
+
$url: ManifestUrl;
|
|
756
|
+
$pay: ManifestPay;
|
|
757
|
+
$chat: ManifestChat;
|
|
758
|
+
$status: ManifestStatus;
|
|
759
|
+
$presence: ManifestPresence;
|
|
760
|
+
$date: ManifestDate;
|
|
761
|
+
$chart: ManifestChart;
|
|
762
|
+
$export: ManifestExport;
|
|
763
|
+
$import: ManifestImport;
|
|
764
|
+
$edit: ManifestEdit;
|
|
765
|
+
$rich: ManifestRichText;
|
|
766
|
+
$device: ManifestDevice;
|
|
767
|
+
$share: ManifestShare;
|
|
768
|
+
$push: ManifestPush;
|
|
769
|
+
$secure: ManifestSecure;
|
|
770
|
+
$links: ManifestLinks;
|
|
771
|
+
$app: ManifestApp;
|
|
772
|
+
$haptics: ManifestHaptics;
|
|
773
|
+
$biometric: ManifestBiometric;
|
|
774
|
+
$camera: ManifestCamera;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/** Lifecycle hooks Alpine calls on a component. */
|
|
778
|
+
export interface ManifestComponentHooks {
|
|
779
|
+
init?(): void | Promise<void>;
|
|
780
|
+
destroy?(): void;
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* A component's state with `this` typed as that state plus every magic.
|
|
785
|
+
* Pair with an identity helper so `T` is inferred from the returned object:
|
|
786
|
+
*
|
|
787
|
+
* /** @template T @param {() => import('mnfst').ManifestComponent<T>} fn *\/
|
|
788
|
+
* export const component = (fn) => fn
|
|
789
|
+
*/
|
|
790
|
+
export type ManifestComponent<T> = T & ManifestComponentHooks & ThisType<T & ManifestMagics>;
|
|
791
|
+
|
|
792
|
+
/** The `Alpine` global, as app modules use it. */
|
|
793
|
+
export interface ManifestAlpine {
|
|
794
|
+
data<T>(name: string, factory: (...args: any[]) => T): void;
|
|
795
|
+
store<T>(name: string, value: T & ThisType<T>): void;
|
|
796
|
+
store<K extends string>(name: K): ManifestStores[K];
|
|
797
|
+
magic(name: string, callback: (el: HTMLElement, options: unknown) => unknown): void;
|
|
798
|
+
directive(name: string, callback: (...args: any[]) => unknown): unknown;
|
|
799
|
+
nextTick(callback?: () => void): Promise<void>;
|
|
800
|
+
effect(callback: () => void): unknown;
|
|
801
|
+
reactive<T extends object>(value: T): T;
|
|
802
|
+
raw<T>(value: T): T;
|
|
803
|
+
evaluate(el: Element, expression: string): unknown;
|
|
804
|
+
initTree(el: Element): void;
|
|
805
|
+
$data(el: Element): Record<string, any>;
|
|
806
|
+
}
|
|
568
807
|
|
|
569
808
|
// ---------------------------------------------------------------------------
|
|
570
809
|
// Global declarations (what Alpine exposes inside `x-data`, `x-show`, etc.)
|
|
@@ -572,7 +811,11 @@ export type ManifestDirective =
|
|
|
572
811
|
|
|
573
812
|
declare global {
|
|
574
813
|
/** Project data sources registered in manifest.json. */
|
|
575
|
-
const $x:
|
|
814
|
+
const $x: ManifestData;
|
|
815
|
+
/** Alpine stores. */
|
|
816
|
+
const $store: ManifestStoreMap;
|
|
817
|
+
/** Alpine, loaded by Manifest; reach it inside `alpine:init`. */
|
|
818
|
+
const Alpine: ManifestAlpine;
|
|
576
819
|
/** The current route path (compare or .startsWith against it). */
|
|
577
820
|
const $route: ManifestRoute;
|
|
578
821
|
/** Read a parent component attribute (Manifest's prop mechanism). */
|
|
@@ -648,8 +891,17 @@ declare global {
|
|
|
648
891
|
/** The two-line same-origin /sw.js stub pinned to a framework version. */
|
|
649
892
|
swStub?(version?: string): string;
|
|
650
893
|
};
|
|
651
|
-
Alpine?:
|
|
894
|
+
Alpine?: ManifestAlpine;
|
|
652
895
|
__manifestLoaded?: unknown;
|
|
896
|
+
/** Pending work that will still change the page; mnfst-render's auto settle won't snapshot early while count > 0. */
|
|
897
|
+
ManifestPending?: {
|
|
898
|
+
/** Hold until the work's DOM update lands; call the returned function to release. */
|
|
899
|
+
hold(label?: string): () => void;
|
|
900
|
+
readonly count: number;
|
|
901
|
+
labels(): string[];
|
|
902
|
+
/** Mark a timer callback as housekeeping that never changes the page (auto settle ignores it). */
|
|
903
|
+
background<T extends Function>(fn: T): T;
|
|
904
|
+
};
|
|
653
905
|
/** Rich text engine (rich-text plugin). */
|
|
654
906
|
ManifestRichText?: {
|
|
655
907
|
attach(el: Element, options?: ManifestRichTextAttachOptions): ManifestRichTextHandle | null;
|
|
@@ -658,6 +910,26 @@ declare global {
|
|
|
658
910
|
sanitize(html: string, allowBlocks?: boolean, keepStyle?: boolean): string;
|
|
659
911
|
commands(): string[];
|
|
660
912
|
};
|
|
913
|
+
/** Form sending (submissions plugin; loaded on first x-submit). */
|
|
914
|
+
ManifestSubmissions?: {
|
|
915
|
+
readonly events: { sent: string; error: string };
|
|
916
|
+
send(form: HTMLFormElement, submitter?: HTMLElement | null): Promise<ManifestSubmitDetail>;
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
interface HTMLElementEventMap {
|
|
921
|
+
'submit:sent': CustomEvent<ManifestSubmitDetail>;
|
|
922
|
+
'submit:error': CustomEvent<ManifestSubmitDetail>;
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
interface WindowEventMap {
|
|
926
|
+
'manifest:data-mutation-success': CustomEvent<ManifestMutationDetail>;
|
|
927
|
+
'manifest:data-mutation-error': CustomEvent<ManifestMutationDetail>;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** x-virtual: the last rendered row neared the end of the list (bubbles). */
|
|
931
|
+
interface HTMLElementEventMap {
|
|
932
|
+
'virtual-end': CustomEvent<{ length: number }>;
|
|
661
933
|
}
|
|
662
934
|
|
|
663
935
|
/**
|
|
@@ -680,6 +952,7 @@ declare global {
|
|
|
680
952
|
// ---------------------------------------------------------------------------
|
|
681
953
|
|
|
682
954
|
// (No project augmentations yet — run `npx mnfst-types` to generate.)
|
|
955
|
+
export interface ManifestSources { [sourceName: string]: any }
|
|
683
956
|
|
|
684
957
|
// ---------------------------------------------------------------------------
|
|
685
958
|
// AUGMENTATION:end
|