@zveltio/sdk 3.0.0-beta.110 → 3.0.0-beta.115

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,158 @@
1
+ // What every `view/2` renderer shares (ADR 0042 decision 8): references, the
2
+ // data API filter, `when`, the generated defaults, the fallback, action results.
3
+ import { describe, expect, it } from 'bun:test';
4
+ import { readFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ import { $, actionPath, defaultView, fallbackFor, isEditable, matches, readActionResult, resolveInput, toFilter, toSort, validateView, } from '../view/index.js';
7
+ const scope = {
8
+ record: { id: 'r1', status: 'open', total: 5 },
9
+ selected: { folders: 'f9' },
10
+ selection: [{ id: 'a' }, { id: 'b' }],
11
+ params: { id: 'p1' },
12
+ user: 'u1',
13
+ today: '2026-11-12',
14
+ };
15
+ describe('references', () => {
16
+ it('fills every reference from the scope', () => {
17
+ expect(resolveInput({
18
+ rec: $.record('id'),
19
+ sel: $.selected('folders'),
20
+ ids: $.selection('id'),
21
+ p: $.param('id'),
22
+ me: $.user(),
23
+ d: $.today(),
24
+ lit: 3,
25
+ }, scope)).toEqual({
26
+ rec: 'r1',
27
+ sel: 'f9',
28
+ ids: ['a', 'b'],
29
+ p: 'p1',
30
+ me: 'u1',
31
+ d: '2026-11-12',
32
+ lit: 3,
33
+ });
34
+ });
35
+ it('is unresolved while a pane has no selection', () => {
36
+ expect(resolveInput({ x: $.selected('other') }, scope)).toBeNull();
37
+ expect(toFilter([$.where('folder_id', 'eq', $.selected('other'))], scope)).toBeNull();
38
+ });
39
+ });
40
+ describe('toFilter', () => {
41
+ it('builds the data API JSON filter, several operators on one field', () => {
42
+ expect(toFilter([
43
+ $.where('total', 'gt', 1),
44
+ $.where('total', 'lt', 9),
45
+ $.where('owner', 'eq', $.user()),
46
+ $.where('deleted_at', 'null'),
47
+ ], scope)).toEqual({ total: { gt: 1, lt: 9 }, owner: { eq: 'u1' }, deleted_at: { null: true } });
48
+ });
49
+ });
50
+ describe('cross-key checks', () => {
51
+ const doc = (v) => ({ spec: 'zveltio.view/2', type: 'list', collection: 'a', ...v });
52
+ it('refuses the same field and operator twice in one condition list', () => {
53
+ const r = validateView(doc({ filter: [$.where('total', 'gt', 1), $.where('total', 'gt', 5)] }));
54
+ expect(r.ok ? [] : r.issues.map((i) => i.path)).toEqual(['/filter/1']);
55
+ // Two operators on one field are one data API filter: allowed.
56
+ expect(validateView(doc({ filter: [$.where('total', 'gt', 1), $.where('total', 'lt', 9)] })).ok).toBe(true);
57
+ expect(() => toFilter([$.where('a', 'eq', 1), $.where('a', 'eq', 2)], scope)).toThrow();
58
+ });
59
+ it('refuses a prompt that names an input the button binds', () => {
60
+ const r = validateView(doc({
61
+ rowActions: [{ action: 'pay', input: { id: $.record('id') }, prompt: ['id', 'note'] }],
62
+ }));
63
+ expect(r.ok ? [] : r.issues.map((i) => i.path)).toEqual(['/rowActions/0/prompt/0']);
64
+ });
65
+ });
66
+ describe('matches', () => {
67
+ it('checks a row against conditions', () => {
68
+ const row = { status: 'open', total: 5, owner: 'u1', note: null };
69
+ expect(matches(undefined, row, scope)).toBe(true);
70
+ expect(matches([$.where('status', 'eq', 'open'), $.where('total', 'gte', 5)], row, scope)).toBe(true);
71
+ expect(matches([$.where('status', 'in', ['done', 'void'])], row, scope)).toBe(false);
72
+ expect(matches([$.where('owner', 'neq', $.user())], row, scope)).toBe(false);
73
+ expect(matches([$.where('note', 'null')], row, scope)).toBe(true);
74
+ expect(matches([$.where('status', 'ilike', 'OP')], row, scope)).toBe(true);
75
+ // An unresolved reference never holds.
76
+ expect(matches([$.where('status', 'eq', $.selected('none'))], row, scope)).toBe(false);
77
+ });
78
+ });
79
+ describe('generated defaults', () => {
80
+ const fields = [
81
+ { name: 'id', type: 'uuid', is_system: true },
82
+ { name: 'title', type: 'text' },
83
+ { name: 'score', type: 'computed' },
84
+ { name: 'locked', type: 'text', readonly: true },
85
+ ...Array.from({ length: 9 }, (_, i) => ({ name: `f${i}`, type: 'text' })),
86
+ ];
87
+ it('drops system and computed fields; a list stops at eight; a form drops read-only ones', () => {
88
+ const list = defaultView('list', 'notes', fields);
89
+ expect(list.fields).toEqual(['title', 'locked', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5']);
90
+ const form = defaultView('form', 'notes', fields);
91
+ expect(form.fields).not.toContain('locked');
92
+ expect(form.fields).toHaveLength(10);
93
+ expect(defaultView('detail', 'notes', fields)).toMatchObject({ record: { $param: 'id' } });
94
+ });
95
+ it('never makes a system, computed or read-only field writable', () => {
96
+ expect(isEditable({ name: 'title', type: 'text' })).toBe(true);
97
+ expect(isEditable({ name: 'id', type: 'uuid', is_system: true })).toBe(false);
98
+ expect(isEditable({ name: 'score', type: 'computed' })).toBe(false);
99
+ expect(isEditable({ name: 'locked', type: 'text', readonly: true })).toBe(false);
100
+ });
101
+ it('falls back to the view’s own fallback, then to the list of its collection', () => {
102
+ const drawn = new Set(['list', 'form']);
103
+ const board = { type: 'board', collection: 'tasks', groupBy: 'status' };
104
+ expect(fallbackFor(board, drawn)).toEqual({ type: 'list', collection: 'tasks' });
105
+ const withOwn = { ...board, fallback: { type: 'form', collection: 'tasks' } };
106
+ expect(fallbackFor(withOwn, drawn)).toEqual({ type: 'form', collection: 'tasks' });
107
+ expect(fallbackFor({ type: 'tabs', items: [] }, drawn)).toBeNull();
108
+ });
109
+ });
110
+ describe('actions', () => {
111
+ it('names its own extension’s action or a dependency’s', () => {
112
+ expect(actionPath('billing', 'pay')).toBe('/ext/billing/actions/pay');
113
+ expect(actionPath('billing', 'mail.send')).toBe('/ext/mail/actions/send');
114
+ // A dependency with a scoped name keeps its `/`, as its routes are mounted.
115
+ expect(actionPath('x', 'finance/quotes.approve')).toBe('/ext/finance/quotes/actions/approve');
116
+ });
117
+ it('refuses a name that would leave the action route', () => {
118
+ for (const [ext, action] of [
119
+ ['billing', '..'],
120
+ ['billing', '../admin.x'],
121
+ ['billing', 'a/../b.pay'],
122
+ ['..', 'pay'],
123
+ ['billing', 'pay/../../x'],
124
+ ['billing', 'mail.'],
125
+ ]) {
126
+ expect(() => actionPath(ext, action)).toThrow();
127
+ }
128
+ });
129
+ it('reads a result as navigation, view, file, reveal or values', () => {
130
+ expect(readActionResult({ view: 'mail.compose', params: { draft_id: 'd' } })).toEqual({
131
+ kind: 'navigate',
132
+ view: 'mail.compose',
133
+ params: { draft_id: 'd' },
134
+ });
135
+ expect(readActionResult({ view: { type: 'list', collection: 'x' } }).kind).toBe('view');
136
+ expect(readActionResult({ file: 'f1' })).toEqual({ kind: 'file', file: 'f1' });
137
+ expect(readActionResult({ reveal: 'k' })).toEqual({ kind: 'reveal', value: 'k' });
138
+ expect(readActionResult({ total: 3 })).toEqual({ kind: 'values', values: { total: 3 } });
139
+ expect(readActionResult(null)).toEqual({ kind: 'values', values: null });
140
+ // A tagged object that is none of the closed forms is not values: no guessing.
141
+ const bad = readActionResult({ view: 'mail.compose', extra: 1 });
142
+ expect(bad.kind).toBe('invalid');
143
+ });
144
+ // The shared corpus: the engine's test runs the same results through the
145
+ // published JSON Schema.
146
+ const corpus = JSON.parse(readFileSync(join(import.meta.dir, '../../src/tests/fixtures/view-2.json'), 'utf8')).actionResults;
147
+ for (const [name, r] of Object.entries(corpus.valid)) {
148
+ it(`reads: ${name}`, () => expect(readActionResult(r).kind).not.toBe('invalid'));
149
+ }
150
+ for (const [name, r] of Object.entries(corpus.invalid)) {
151
+ it(`refuses: ${name}`, () => expect(readActionResult(r).kind).toBe('invalid'));
152
+ }
153
+ it('sorts by the first field, `-` descending', () => {
154
+ expect(toSort('-issued_on')).toEqual({ sort: 'issued_on', order: 'desc' });
155
+ expect(toSort(['name', '-x'])).toEqual({ sort: 'name', order: 'asc' });
156
+ expect(toSort(undefined)).toBeNull();
157
+ });
158
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=view.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.test.d.ts","sourceRoot":"","sources":["../../src/tests/view.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,200 @@
1
+ // `zveltio.view/2` (ADR 0042): the validator the CLI runs at validate and pack,
2
+ // the builder, and what the schema cannot see (names, panes, keys).
3
+ // `fixtures/view-2.json` is shared with the engine's test, which runs the same
4
+ // documents through its own check of the published JSON Schema.
5
+ import { describe, expect, it } from 'bun:test';
6
+ import { readFileSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+ import { $, isViewDocument, VIEW_SPEC, validateView, view, viewNameIssues } from '../view/index.js';
9
+ // Parsed, not imported: an import would turn the `__proto__` key into a prototype.
10
+ // Resolved through src/ so the copy tsc compiles into dist/tests finds it too.
11
+ // Parsed, not imported: an import would turn the `__proto__` key into a prototype.
12
+ const fixtures = JSON.parse(readFileSync(join(import.meta.dir, '../../src/tests/fixtures/view-2.json'), 'utf8'));
13
+ const issues = (input) => {
14
+ const r = validateView(input);
15
+ return r.ok ? [] : r.issues;
16
+ };
17
+ const paths = (input) => issues(input).map((i) => i.path);
18
+ describe('validateView', () => {
19
+ for (const [name, doc] of Object.entries(fixtures.valid)) {
20
+ it(`accepts: ${name}`, () => expect(issues(doc)).toEqual([]));
21
+ }
22
+ for (const [name, doc] of Object.entries(fixtures.invalid)) {
23
+ it(`refuses: ${name}`, () => expect(issues(doc)).not.toEqual([]));
24
+ }
25
+ // The broken fixture: a view/1 page written as if it were view/2. Without the
26
+ // validation every key below would reach a renderer.
27
+ it('names each key that is not part of the vocabulary', () => {
28
+ expect(paths(fixtures.invalid['view/1 habits'])).toEqual([
29
+ '/dataSource',
30
+ '/fields/0/class',
31
+ '/rowActions/0/icon',
32
+ ]);
33
+ expect(paths(fixtures.invalid['unknown key deep in a panel'])).toEqual([
34
+ '/panes/1/panels/0/endpoint',
35
+ ]);
36
+ });
37
+ it('refuses keys an object inherits', () => {
38
+ for (const key of ['constructor', 'toString', '__proto__']) {
39
+ expect(paths(fixtures.invalid[key])).toEqual([`/${key}`]);
40
+ }
41
+ });
42
+ it('shapes a condition by its operator', () => {
43
+ expect(paths(fixtures.invalid['in without a list'])).toEqual(['/filter/0/value']);
44
+ expect(paths(fixtures.invalid['null with a value'])).toEqual(['/filter/0/value']);
45
+ expect(paths(fixtures.invalid['eq without a value'])).toEqual(['/filter/0']);
46
+ });
47
+ it('names the kind the type names, and the missing key', () => {
48
+ expect(issues(fixtures.invalid['detail without a record'])).toEqual([
49
+ { path: '', message: 'needs "record"' },
50
+ ]);
51
+ expect(paths(fixtures.invalid['an unknown kind'])[0]).toBe('/type');
52
+ });
53
+ it('a view/1 schema is not a view/2 document', () => {
54
+ const v1 = { sduiSchema: 1, title: 't', resources: [{ id: 'r', dataSource: '/ext/x/r' }] };
55
+ expect(isViewDocument(v1)).toBe(false);
56
+ expect(issues(v1)).toEqual([{ path: '/spec', message: `must be "${VIEW_SPEC}"` }]);
57
+ });
58
+ });
59
+ describe('viewNameIssues', () => {
60
+ const names = {
61
+ collections: ['mail_accounts', 'mail_messages', 'mail_drafts'],
62
+ actions: ['sync', 'setFlags', 'deleteMessages', 'send', 'pay'],
63
+ dependencies: ['crm'],
64
+ };
65
+ it('passes a view that names only its own collections and actions', () => {
66
+ expect(viewNameIssues(fixtures.valid.inbox, names)).toEqual([]);
67
+ });
68
+ it("refuses another extension's collection and an undeclared action; allows a dependency's action", () => {
69
+ const v = view.document(view.list({
70
+ collection: 'invoices',
71
+ rowActions: [{ action: 'archive' }, { action: 'crm.link' }, { action: 'billing.pay' }],
72
+ }));
73
+ expect(viewNameIssues(v, names).map((i) => i.path)).toEqual([
74
+ '/collection',
75
+ '/rowActions/0/action',
76
+ '/rowActions/2/action',
77
+ ]);
78
+ });
79
+ it("reads an action's input as values: a key named action or collection is not a reference", () => {
80
+ const v = view.document(view.list({
81
+ collection: 'mail_messages',
82
+ rowActions: [{ action: 'pay', input: { action: 'refund', collection: 'x' } }],
83
+ }));
84
+ expect(viewNameIssues(v, names)).toEqual([]);
85
+ });
86
+ it('a $selected names an earlier pane of an enclosing split; pane ids are unique', () => {
87
+ const v = view.document(view.split({
88
+ actions: [{ action: 'sync', input: { a: $.selected('second') } }],
89
+ panes: [
90
+ view.list({
91
+ id: 'first',
92
+ collection: 'mail_messages',
93
+ filter: [$.where('a', 'eq', $.selected('second'))],
94
+ }),
95
+ view.list({
96
+ id: 'second',
97
+ collection: 'mail_messages',
98
+ filter: [$.where('a', 'eq', $.selected('first'))],
99
+ }),
100
+ view.detail({ id: 'first', collection: 'mail_messages', record: $.selected('nowhere') }),
101
+ ],
102
+ }));
103
+ expect(viewNameIssues(v, names).map((i) => i.path)).toEqual([
104
+ '/panes/0/filter/0/value/$selected',
105
+ '/panes/2/id',
106
+ '/panes/2/record/$selected',
107
+ ]);
108
+ });
109
+ it('navigate and open name a view of the extension; a message key must be shipped', () => {
110
+ const v = view.document(view.list({
111
+ collection: 'mail_messages',
112
+ title: 'mail.inbox',
113
+ open: 'mail.thread',
114
+ rowActions: [
115
+ { navigate: 'mail.nowhere', label: 'mail.typo' },
116
+ { action: 'send', label: 'Send' },
117
+ ],
118
+ }));
119
+ const found = viewNameIssues(v, {
120
+ ...names,
121
+ views: ['mail.thread'],
122
+ messageKeys: ['mail.inbox'],
123
+ });
124
+ expect(found.map((i) => i.path)).toEqual(['/rowActions/0/navigate', '/rowActions/0/label']);
125
+ });
126
+ it('reports a field the bound collection does not declare, and only with fields given', () => {
127
+ const v = {
128
+ type: 'split',
129
+ panes: [
130
+ {
131
+ type: 'list',
132
+ collection: 'mail_messages',
133
+ fields: ['subject', { field: 'sujbect', label: 'Subject' }],
134
+ filter: [{ field: 'read', op: 'eq', value: false }],
135
+ sort: ['-created_at', 'sent'],
136
+ rowActions: [{ action: 'send', label: 'Send', input: { subject: 'x' } }],
137
+ },
138
+ { type: 'board', collection: 'mail_messages', groupBy: 'folder', card: ['subject'] },
139
+ { type: 'stat', source: { collection: 'mail_messages', aggregate: 'sum', field: 'size' } },
140
+ ],
141
+ };
142
+ const fields = new Map([['mail_messages', ['id', 'created_at', 'subject', 'folder']]]);
143
+ expect(viewNameIssues(v, { ...names, fields }).map((i) => i.path)).toEqual([
144
+ '/panes/0/fields/1/field',
145
+ '/panes/0/filter/0/field',
146
+ '/panes/0/sort/1',
147
+ '/panes/2/source/field',
148
+ ]);
149
+ expect(viewNameIssues(v, names)).toEqual([]);
150
+ });
151
+ });
152
+ describe('builder', () => {
153
+ it('emits the JSON a hand-written file would hold, and it validates', () => {
154
+ const built = view.document(view.split({
155
+ panes: [
156
+ view.list({ id: 'account', collection: 'mail_accounts', fields: ['email'] }),
157
+ view.detail({
158
+ collection: 'mail_messages',
159
+ record: $.selected('account'),
160
+ panels: [
161
+ view.list({
162
+ collection: 'mail_drafts',
163
+ filter: [$.where('owner', 'eq', $.user()), $.where('sent_at', 'null')],
164
+ }),
165
+ ],
166
+ }),
167
+ ],
168
+ }), 'mail.drafts');
169
+ expect(built).toEqual({
170
+ type: 'split',
171
+ spec: VIEW_SPEC,
172
+ id: 'mail.drafts',
173
+ panes: [
174
+ { type: 'list', id: 'account', collection: 'mail_accounts', fields: ['email'] },
175
+ {
176
+ type: 'detail',
177
+ collection: 'mail_messages',
178
+ record: { $selected: 'account' },
179
+ panels: [
180
+ {
181
+ type: 'list',
182
+ collection: 'mail_drafts',
183
+ filter: [
184
+ { field: 'owner', op: 'eq', value: { $user: 'id' } },
185
+ { field: 'sent_at', op: 'null' },
186
+ ],
187
+ },
188
+ ],
189
+ },
190
+ ],
191
+ });
192
+ expect(issues(built)).toEqual([]);
193
+ });
194
+ it('drops undefined keys, as a file would not hold them', () => {
195
+ const sorted = false;
196
+ const built = view.document(view.list({ collection: 'a', sort: sorted ? 'name' : undefined, rowActions: undefined }));
197
+ expect(Object.keys(built)).toEqual(['type', 'collection', 'spec']);
198
+ expect(issues(built)).toEqual([]);
199
+ });
200
+ });
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;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AAC;IAChB;;;+CAG2C;IAC3C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;gDAE4C;IAC5C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;+EAE2E;IAC3E,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB;;mEAE+D;IAC/D,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,eAAe,EAAE,CA0FhF;AAsBD;;;;;;;;;;eAUe;AACf,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAoBzE;AAID,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,UAAU,EAAE,yBAAyB,CAAC;IACtC,YAAY,EAAE,iBAAiB,CAAC;IAChC,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,qEAAqE;IACrE,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,gBAAgB,CAkBjF"}
@@ -196,6 +196,36 @@ export function validateManifest(input) {
196
196
  if (isObject(r))
197
197
  seenRoutes.add(`${r.method} ${r.path}`);
198
198
  });
199
+ // Sign-in providers (ADR 0039 decision 8), each started by a declared public
200
+ // route: `POST` for `credentials`, `GET` for `redirect`, without parameters.
201
+ if (obj.signInProviders !== undefined && !Array.isArray(obj.signInProviders)) {
202
+ out.push(err('MANIFEST_BAD_SIGN_IN_PROVIDER', '"signInProviders" must be an array'));
203
+ }
204
+ const providerIds = new Set();
205
+ (Array.isArray(obj.signInProviders) ? obj.signInProviders : []).forEach((p, i) => {
206
+ const method = isObject(p) && p.kind === 'credentials' ? 'POST' : 'GET';
207
+ const ok = isObject(p) &&
208
+ Object.keys(p).every((k) => ['id', 'label', 'kind', 'route'].includes(k)) &&
209
+ typeof p.id === 'string' &&
210
+ /^[a-z][a-z0-9-]{0,63}$/.test(p.id) &&
211
+ typeof p.label === 'string' &&
212
+ p.label.length > 0 &&
213
+ p.label.length <= 100 &&
214
+ (p.kind === 'credentials' || p.kind === 'redirect') &&
215
+ declaredRoutes.some((r) => isObject(r) &&
216
+ r.method === method &&
217
+ r.path === p.route &&
218
+ r.access === 'public' &&
219
+ !String(p.route).includes(':'));
220
+ if (!ok) {
221
+ out.push(err('MANIFEST_BAD_SIGN_IN_PROVIDER', `signInProviders[${i}] needs an id, a label, kind (credentials|redirect) and the route of a declared public route without parameters that starts it (POST for credentials, GET for redirect)`));
222
+ }
223
+ else if (providerIds.has(p.id)) {
224
+ out.push(err('MANIFEST_BAD_SIGN_IN_PROVIDER', `sign-in provider "${p.id}" is declared twice`));
225
+ }
226
+ if (isObject(p) && typeof p.id === 'string')
227
+ providerIds.add(p.id);
228
+ });
199
229
  // `publicRoutes` (deprecated) and the declared public routes: what a job or
200
230
  // `forwardCredentials` may name.
201
231
  const publicPaths = [
@@ -0,0 +1,172 @@
1
+ /**
2
+ * `@zveltio/sdk/view` — the `zveltio.view/2` specification (ADR 0042).
3
+ *
4
+ * - `VIEW_SCHEMA`: the JSON Schema (also published as
5
+ * `@zveltio/sdk/view/schema.json`), the single source of the types below.
6
+ * - `validateView`: what `zveltio extension validate` and `pack` run; the
7
+ * engine checks the same schema when it loads an extension.
8
+ * - `viewNameIssues`: a view names only its extension's collections and
9
+ * actions, and a dependency's action.
10
+ * - `view`, `$`: a typed builder that emits the JSON.
11
+ * - `readActionResult`: an action's result, checked against `ActionResult`.
12
+ * - `resolveValue`, `toFilter`, `matches`, `defaultView`, ...: what every
13
+ * renderer does the same way (`runtime.ts`).
14
+ *
15
+ * Dependency-free: the validator interprets the subset of JSON Schema that
16
+ * `VIEW_SCHEMA` uses, so a front end can validate in the browser.
17
+ */
18
+ import { VIEW_SPEC } from './schema.js';
19
+ import type { Condition, Ref, Value, View, ViewId } from './types.generated.js';
20
+ export { VIEW_SCHEMA, VIEW_SPEC } from './schema.js';
21
+ export * from './runtime.js';
22
+ export type * from './types.generated.js';
23
+ /** A view file: a view with `spec` set at its top, and its `id` a `ViewId`. */
24
+ export type ViewDocument = View & {
25
+ spec: typeof VIEW_SPEC;
26
+ id?: ViewId;
27
+ };
28
+ export interface ViewIssue {
29
+ /** JSON Pointer to the offending value, `''` for the document. */
30
+ path: string;
31
+ message: string;
32
+ }
33
+ export type ViewValidation = {
34
+ ok: true;
35
+ view: ViewDocument;
36
+ } | {
37
+ ok: false;
38
+ issues: ViewIssue[];
39
+ };
40
+ /** A `view/2` file declares itself; anything else (a `view/1` schema) is not one. */
41
+ export declare function isViewDocument(input: unknown): boolean;
42
+ export declare function validateView(input: unknown): ViewValidation;
43
+ /**
44
+ * How a front end reads an action's `result` (`ActionResult`, ADR 0042
45
+ * decision 4): `{ view: "<id>", params? }` opens that view, `{ view: {...} }`
46
+ * draws it, `{ file }` hands over a stored file, `{ reveal }` shows a value
47
+ * once, anything else is values. An object with `view`, `file` or `reveal` that
48
+ * is none of those forms is `invalid`: a front end shows an error, never guesses.
49
+ */
50
+ export type ActionOutcome = {
51
+ kind: 'navigate';
52
+ view: ViewId;
53
+ params: Record<string, unknown>;
54
+ } | {
55
+ kind: 'view';
56
+ view: View;
57
+ } | {
58
+ kind: 'file';
59
+ file: string;
60
+ } | {
61
+ kind: 'reveal';
62
+ value: string;
63
+ } | {
64
+ kind: 'values';
65
+ values: unknown;
66
+ } | {
67
+ kind: 'invalid';
68
+ issues: ViewIssue[];
69
+ };
70
+ export declare function readActionResult(result: unknown): ActionOutcome;
71
+ export interface ViewNames {
72
+ /** The collections the extension declares (manifest `collections`). */
73
+ collections: Iterable<string>;
74
+ /** The extension's own action names (manifest `actions[].name`). */
75
+ actions: Iterable<string>;
76
+ /** Its `dependencies` and `optionalDependencies`: their actions are `<dep>.<action>`. */
77
+ dependencies?: Iterable<string>;
78
+ /** The `id`s of the extension's view files; `navigate` and `open` name one. Omit to skip. */
79
+ views?: Iterable<string>;
80
+ /** The message keys a `Text` may name (its own `en.json` and the shared ones). Omit to skip. */
81
+ messageKeys?: Iterable<string>;
82
+ /**
83
+ * Each declared collection's field names, system columns included: a view
84
+ * bound to one of them may name only these. A collection absent here is not
85
+ * checked. Omit to skip.
86
+ */
87
+ fields?: ReadonlyMap<string, Iterable<string>>;
88
+ }
89
+ /**
90
+ * What the schema cannot see in a (valid) view: a collection or action its
91
+ * extension does not own, a `$selected` that names no earlier pane, a pane id
92
+ * used twice, a `navigate`/`open` to no view of the extension, a message key
93
+ * the extension does not ship, a field its collection does not have. (`fallback` is an inline view, not a reference.)
94
+ */
95
+ export declare function viewNameIssues(view: unknown, names: ViewNames): ViewIssue[];
96
+ type Kind = View['type'];
97
+ type Of<K extends Kind> = Extract<View, {
98
+ type: K;
99
+ }>;
100
+ /**
101
+ * Typed constructors: `view.list({ collection: 'invoices', fields: ['number'] })`.
102
+ * `view.document(v)` stamps `spec` on the top-level view; `JSON.stringify` it
103
+ * into the file the manifest names.
104
+ */
105
+ export declare const view: {
106
+ list: (props: Omit<import("./types.generated.js").ListView, "type">) => import("./types.generated.js").ListView;
107
+ form: (props: Omit<{
108
+ type: "form";
109
+ id?: import("./types.generated.js").PaneId;
110
+ title?: import("./types.generated.js").Text;
111
+ actions?: import("./types.generated.js").Buttons;
112
+ fallback?: View;
113
+ collection: import("./types.generated.js").Name;
114
+ record?: Ref | "singleton";
115
+ fields?: import("./types.generated.js").Fields;
116
+ sections?: Array<{
117
+ title?: import("./types.generated.js").Text;
118
+ fields: import("./types.generated.js").Fields;
119
+ }>;
120
+ lines?: {
121
+ collection: import("./types.generated.js").Name;
122
+ fk: import("./types.generated.js").Name;
123
+ fields?: import("./types.generated.js").Fields;
124
+ order?: import("./types.generated.js").Name;
125
+ };
126
+ submit?: import("./types.generated.js").Buttons;
127
+ recalc?: import("./types.generated.js").ActionCall;
128
+ autosave?: boolean;
129
+ }, "type"> | Omit<{
130
+ type: "form";
131
+ id?: import("./types.generated.js").PaneId;
132
+ title?: import("./types.generated.js").Text;
133
+ actions?: import("./types.generated.js").Buttons;
134
+ fallback?: View;
135
+ action: import("./types.generated.js").ActionName;
136
+ fields?: import("./types.generated.js").Fields;
137
+ sections?: Array<{
138
+ title?: import("./types.generated.js").Text;
139
+ fields: import("./types.generated.js").Fields;
140
+ }>;
141
+ lines?: {
142
+ collection: import("./types.generated.js").Name;
143
+ fk: import("./types.generated.js").Name;
144
+ fields?: import("./types.generated.js").Fields;
145
+ order?: import("./types.generated.js").Name;
146
+ };
147
+ submit?: import("./types.generated.js").Buttons;
148
+ recalc?: import("./types.generated.js").ActionCall;
149
+ autosave?: boolean;
150
+ }, "type">) => Of<"form">;
151
+ detail: (props: Omit<import("./types.generated.js").DetailView, "type">) => import("./types.generated.js").DetailView;
152
+ board: (props: Omit<import("./types.generated.js").BoardView, "type">) => import("./types.generated.js").BoardView;
153
+ timeline: (props: Omit<import("./types.generated.js").TimelineView, "type">) => import("./types.generated.js").TimelineView;
154
+ tree: (props: Omit<import("./types.generated.js").TreeView, "type">) => import("./types.generated.js").TreeView;
155
+ matrix: (props: Omit<import("./types.generated.js").MatrixView, "type">) => import("./types.generated.js").MatrixView;
156
+ map: (props: Omit<import("./types.generated.js").MapView, "type">) => import("./types.generated.js").MapView;
157
+ stat: (props: Omit<import("./types.generated.js").StatView, "type">) => import("./types.generated.js").StatView;
158
+ split: (props: Omit<import("./types.generated.js").SplitView, "type">) => import("./types.generated.js").SplitView;
159
+ tabs: (props: Omit<import("./types.generated.js").TabsView, "type">) => import("./types.generated.js").TabsView;
160
+ document: (v: View, id?: ViewId) => ViewDocument;
161
+ };
162
+ /** References and conditions: `$.record('id')`, `$.where('status', 'eq', 'open')`. */
163
+ export declare const $: {
164
+ record: (field: string) => Ref;
165
+ selected: (pane: string) => Ref;
166
+ selection: (field: string) => Ref;
167
+ param: (name: string) => Ref;
168
+ user: () => Ref;
169
+ today: () => Ref;
170
+ where: (field: string, op: Condition["op"], value?: Value) => Condition;
171
+ };
172
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/view/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAe,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,KAAK,EAAgB,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,cAAc,cAAc,CAAC;AAC7B,mBAAmB,sBAAsB,CAAC;AAE1C,+EAA+E;AAC/E,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG;IAAE,IAAI,EAAE,OAAO,SAAS,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1E,MAAM,WAAW,SAAS;IACxB,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,cAAc,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,EAAE,CAAA;CAAE,CAAC;AAEnG,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAQ3D;AA2CD;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,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