@zveltio/sdk 3.0.0-beta.110 → 3.0.0-beta.113
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/dist/extension/capabilities.d.ts +0 -1
- package/dist/extension/capabilities.d.ts.map +1 -1
- package/dist/extension/capabilities.js +0 -1
- package/dist/extension/index.d.ts +55 -23
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/tests/validate-manifest-routes.test.js +30 -0
- package/dist/tests/view-runtime.test.d.ts +2 -0
- package/dist/tests/view-runtime.test.d.ts.map +1 -0
- package/dist/tests/view-runtime.test.js +158 -0
- package/dist/tests/view.test.d.ts +2 -0
- package/dist/tests/view.test.d.ts.map +1 -0
- package/dist/tests/view.test.js +200 -0
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +30 -0
- package/dist/view/index.d.ts +172 -0
- package/dist/view/index.d.ts.map +1 -0
- package/dist/view/index.js +367 -0
- package/dist/view/runtime.d.ts +71 -0
- package/dist/view/runtime.d.ts.map +1 -0
- package/dist/view/runtime.js +185 -0
- package/dist/view/schema.d.ts +20 -0
- package/dist/view/schema.d.ts.map +1 -0
- package/dist/view/schema.js +357 -0
- package/dist/view/types.generated.d.ts +318 -0
- package/dist/view/types.generated.d.ts.map +1 -0
- package/dist/view/types.generated.js +2 -0
- package/package.json +7 -1
- package/schemas/view-2.schema.json +2047 -0
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAK/D,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,C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;;;;;GAOG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAW5C,CAAC;AAwHF,MAAM,WAAW,mBAAmB;IAClC,2DAA2D;IAC3D,MAAM,EAAE,OAAO,CAAC;IAChB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;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"}
|
package/dist/validate/index.js
CHANGED
|
@@ -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,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