@zveltio/sdk 3.0.0-beta.127 → 3.0.0-beta.135
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/client.d.ts.map +1 -1
- package/dist/client.js +10 -3
- package/dist/extension/capabilities.d.ts +1 -2
- package/dist/extension/capabilities.d.ts.map +1 -1
- package/dist/extension/capabilities.js +0 -2
- package/dist/extension/index.d.ts +67 -71
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/extension/reserved-paths.d.ts +5 -1
- package/dist/extension/reserved-paths.d.ts.map +1 -1
- package/dist/extension/reserved-paths.js +8 -1
- package/dist/sync-manager.d.ts +5 -0
- package/dist/sync-manager.d.ts.map +1 -1
- package/dist/sync-manager.js +23 -4
- package/dist/tests/client.test.js +19 -0
- package/dist/tests/reserved-paths.test.js +4 -1
- package/dist/tests/sync-manager.test.js +42 -0
- package/dist/tests/validate-manifest-forward-credentials.test.js +12 -11
- package/dist/tests/validate-manifest-routes.test.js +6 -1
- package/dist/tests/validate-sdui-data-endpoints.test.js +19 -3
- package/dist/tests/view-runtime.test.js +36 -2
- package/dist/tests/view.test.js +122 -3
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +181 -48
- package/dist/view/index.d.ts +22 -0
- package/dist/view/index.d.ts.map +1 -1
- package/dist/view/index.js +111 -1
- package/dist/view/runtime.d.ts +26 -0
- package/dist/view/runtime.d.ts.map +1 -1
- package/dist/view/runtime.js +60 -6
- package/dist/view/schema.d.ts.map +1 -1
- package/dist/view/schema.js +29 -5
- package/dist/view/types.generated.d.ts +17 -3
- package/dist/view/types.generated.d.ts.map +1 -1
- package/package.json +3 -2
- package/schemas/extension-manifest.schema.json +15 -26
- package/schemas/view-2.schema.json +73 -3
|
@@ -27,6 +27,17 @@ describe('ZveltioClient URL building', () => {
|
|
|
27
27
|
'https://engine.test/api/data/products/a%2Fb',
|
|
28
28
|
]);
|
|
29
29
|
});
|
|
30
|
+
it('refuses a caller value that is a dot segment instead of letting fetch resolve it', async () => {
|
|
31
|
+
const urls = captureUrls();
|
|
32
|
+
const client = createZveltioClient({ baseUrl: 'https://engine.test' });
|
|
33
|
+
await expect(client.collection('..').delete('me')).rejects.toThrow(TypeError);
|
|
34
|
+
await expect(client.collection('products').get('.')).rejects.toThrow(TypeError);
|
|
35
|
+
await expect(client.auth.apiKeys.revoke('..')).rejects.toThrow(TypeError);
|
|
36
|
+
await expect(client.storage.delete('..')).rejects.toThrow(TypeError);
|
|
37
|
+
await expect(client.get('/api/data/%2E%2e/x')).rejects.toThrow(TypeError);
|
|
38
|
+
await client.collection('products').get('..x');
|
|
39
|
+
expect(urls).toEqual(['https://engine.test/api/data/products/..x']);
|
|
40
|
+
});
|
|
30
41
|
it('aggregate() names the route and the query the engine parses (ADR 0050)', async () => {
|
|
31
42
|
const urls = captureUrls();
|
|
32
43
|
const client = createZveltioClient({ baseUrl: 'https://engine.test' });
|
|
@@ -47,6 +58,14 @@ describe('ZveltioClient URL building', () => {
|
|
|
47
58
|
limit: '10',
|
|
48
59
|
});
|
|
49
60
|
});
|
|
61
|
+
it('sends a zero page or limit for the engine to refuse, instead of dropping it', async () => {
|
|
62
|
+
const urls = captureUrls();
|
|
63
|
+
const client = createZveltioClient({ baseUrl: 'https://engine.test' });
|
|
64
|
+
await client.collection('orders').list({ page: 0, limit: 0 });
|
|
65
|
+
await client.collection('orders').aggregate({ fn: ['count'], limit: 0 });
|
|
66
|
+
expect(new URL(urls[0]).search).toBe('?page=0&limit=0');
|
|
67
|
+
expect(new URL(urls[1]).searchParams.get('limit')).toBe('0');
|
|
68
|
+
});
|
|
50
69
|
it('asks the engine who its key is at the route that answers it', async () => {
|
|
51
70
|
const urls = captureUrls();
|
|
52
71
|
const client = createZveltioClient({ baseUrl: 'https://engine.test', apiKey: 'zvk_x' });
|
|
@@ -11,11 +11,14 @@ describe('isReservedPath', () => {
|
|
|
11
11
|
'.well-known/x',
|
|
12
12
|
'favicon.ico',
|
|
13
13
|
'robots.txt',
|
|
14
|
+
'files/x',
|
|
15
|
+
'health',
|
|
16
|
+
'metrics',
|
|
14
17
|
])
|
|
15
18
|
expect(isReservedPath(p)).toBe(true);
|
|
16
19
|
});
|
|
17
20
|
it('accepts a path that only starts with the same letters', () => {
|
|
18
|
-
for (const p of ['apps', 'about', 'administrator', 'blog/admin', '', '/'])
|
|
21
|
+
for (const p of ['apps', 'about', 'administrator', 'blog/admin', 'filesystem', '', '/'])
|
|
19
22
|
expect(isReservedPath(p)).toBe(false);
|
|
20
23
|
});
|
|
21
24
|
});
|
|
@@ -98,6 +98,48 @@ describe('SyncManager — clearLocalData', () => {
|
|
|
98
98
|
await other.close();
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
|
+
describe('SyncManager — clearLocalData during a fetch', () => {
|
|
102
|
+
// A pull or realtime read still waiting on the server when the user signed
|
|
103
|
+
// out wrote that user's rows into the cleared store for the next user.
|
|
104
|
+
it('drops what a pull or realtime read fetched before the clear', async () => {
|
|
105
|
+
let release;
|
|
106
|
+
const held = new Promise((r) => {
|
|
107
|
+
release = r;
|
|
108
|
+
});
|
|
109
|
+
const client = {
|
|
110
|
+
collection: () => ({
|
|
111
|
+
get: async (id) => {
|
|
112
|
+
await held;
|
|
113
|
+
return { id, title: 'previous user' };
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
post: async () => {
|
|
117
|
+
await held;
|
|
118
|
+
return {
|
|
119
|
+
changes: [
|
|
120
|
+
{ collection: 'zvd_posts', id: 'p2', data: { title: 'x' }, operation: 'upsert' },
|
|
121
|
+
],
|
|
122
|
+
hasMore: false,
|
|
123
|
+
cursors: { zvd_posts: 'c1' },
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
sync = new SyncManager(client, { syncInterval: 60_000 });
|
|
128
|
+
await sync.open();
|
|
129
|
+
const store = sync.store;
|
|
130
|
+
await store.clear();
|
|
131
|
+
const rt = fakeRealtime();
|
|
132
|
+
sync.realtime = rt;
|
|
133
|
+
sync.collection('posts').subscribe(() => { });
|
|
134
|
+
const pushing = rt.push({ type: 'event', collection: 'posts', event: 'insert', id: 'p1' });
|
|
135
|
+
const pulling = sync.pull(['posts']);
|
|
136
|
+
await sync.clearLocalData();
|
|
137
|
+
release();
|
|
138
|
+
await Promise.all([pushing, pulling]);
|
|
139
|
+
expect(await store.list('posts')).toEqual([]);
|
|
140
|
+
expect(await store.getMeta('sync_pull_cursors')).toBeUndefined();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
101
143
|
describe('SyncManager — paged pull reads the list the engine sends', () => {
|
|
102
144
|
// A client the sync routes refuse (an API key, 403) pages `list()` instead.
|
|
103
145
|
// That path read `result.data`, which `GET /api/data/:collection` has never
|
|
@@ -7,21 +7,22 @@ const base = {
|
|
|
7
7
|
category: 'custom',
|
|
8
8
|
description: 'd',
|
|
9
9
|
version: '1.0.0',
|
|
10
|
-
publicRoutes: ['/scim/*'],
|
|
11
10
|
};
|
|
12
|
-
const
|
|
13
|
-
|
|
11
|
+
const route = { method: 'POST', path: '/scim', access: 'public', handler: 'scim' };
|
|
12
|
+
const errors = (manifest) => validateManifest({ manifest: { ...base, ...manifest } }).filter((e) => e.code === 'MANIFEST_BAD_FORWARD_CREDENTIALS');
|
|
13
|
+
const onRoute = (forwardCredentials, extra = {}) => errors({ routes: [{ ...route, ...extra, forwardCredentials }] });
|
|
14
|
+
describe('manifest routes[].forwardCredentials (v2 entry 7)', () => {
|
|
14
15
|
it('accepts a credential header on a public route', () => {
|
|
15
|
-
expect(
|
|
16
|
+
expect(onRoute(['authorization'])).toEqual([]);
|
|
16
17
|
});
|
|
17
|
-
it('refuses an unknown header, a
|
|
18
|
-
expect(
|
|
19
|
-
expect(
|
|
20
|
-
expect(
|
|
18
|
+
it('refuses an unknown header, a caller route and a non-list', () => {
|
|
19
|
+
expect(onRoute(['stripe-signature'])).toHaveLength(1);
|
|
20
|
+
expect(onRoute(['cookie'], { access: 'caller' })).toHaveLength(1);
|
|
21
|
+
expect(onRoute('authorization')).toHaveLength(1);
|
|
21
22
|
});
|
|
22
|
-
//
|
|
23
|
-
it('refuses
|
|
24
|
-
expect(errors({ '/scim
|
|
23
|
+
// Keyed by a path, an approved header reached every method on it.
|
|
24
|
+
it('refuses the top-level path-keyed map', () => {
|
|
25
|
+
expect(errors({ routes: [route], forwardCredentials: { '/scim': ['authorization'] } })).toHaveLength(1);
|
|
25
26
|
});
|
|
26
27
|
});
|
|
27
28
|
describe('manifest apiKeyRoutes', () => {
|
|
@@ -23,7 +23,7 @@ describe('manifest routes', () => {
|
|
|
23
23
|
expect(codes({ routes: [{ ...hook, access: 'caller' }], jobs: [job] })).toEqual([
|
|
24
24
|
'MANIFEST_BAD_JOB',
|
|
25
25
|
]);
|
|
26
|
-
expect(codes({ routes: [hook
|
|
26
|
+
expect(codes({ routes: [{ ...hook, forwardCredentials: ['authorization'] }] })).toEqual([]);
|
|
27
27
|
});
|
|
28
28
|
it('refuses what the engine refuses', () => {
|
|
29
29
|
for (const bad of [
|
|
@@ -69,6 +69,11 @@ describe('manifest signInProviders (ADR 0039 decision 8)', () => {
|
|
|
69
69
|
expect(codes({ routes: [{ ...login, access: 'caller' }], signInProviders: [dir] })).toEqual([
|
|
70
70
|
'MANIFEST_BAD_SIGN_IN_PROVIDER',
|
|
71
71
|
]);
|
|
72
|
+
// A route with a parameter cannot start a sign-in: there is nothing to fill it.
|
|
73
|
+
const param = { ...login, path: '/login/:realm' };
|
|
74
|
+
expect(codes({ routes: [param], signInProviders: [{ ...dir, route: param.path }] })).toEqual([
|
|
75
|
+
'MANIFEST_BAD_SIGN_IN_PROVIDER',
|
|
76
|
+
]);
|
|
72
77
|
expect(codes({ routes: [login], signInProviders: [dir, dir] })).toEqual([
|
|
73
78
|
'MANIFEST_BAD_SIGN_IN_PROVIDER',
|
|
74
79
|
]);
|
|
@@ -25,17 +25,33 @@ describe('SDUI data API endpoints', () => {
|
|
|
25
25
|
expect(foreign('/api/data/invoices', ['projects'])).toEqual(['/api/data/invoices']);
|
|
26
26
|
expect(foreign('/api/data/projects')).toEqual(['/api/data/projects']);
|
|
27
27
|
});
|
|
28
|
-
it('refuses every other path, a deeper one
|
|
28
|
+
it('refuses every other path, a deeper one included', () => {
|
|
29
29
|
for (const e of [
|
|
30
30
|
'/api/users',
|
|
31
31
|
'/api/data',
|
|
32
32
|
'/api/data/projects/{id}/history',
|
|
33
|
-
'/api/data/projects/../users',
|
|
34
|
-
'/api/data/projects/..',
|
|
35
33
|
'/api/collections/projects',
|
|
36
34
|
'/api/data/Projects',
|
|
37
35
|
]) {
|
|
38
36
|
expect(foreign(e, ['projects'])).toEqual([e]);
|
|
39
37
|
}
|
|
40
38
|
});
|
|
39
|
+
it('refuses a dot segment, raw or percent-encoded, even under a dependency mount', () => {
|
|
40
|
+
const dot = (endpoint) => validateSduiSchema({
|
|
41
|
+
schema: { title: 't', resources: [{ name: 'r', dataSource: endpoint }] },
|
|
42
|
+
extName: 'projects/management',
|
|
43
|
+
dependencies: ['dep'],
|
|
44
|
+
collections: ['projects'],
|
|
45
|
+
}).map((e) => e.code);
|
|
46
|
+
for (const e of [
|
|
47
|
+
'/ext/dep/../../api/admin/users',
|
|
48
|
+
'/ext/dep/%2E%2e/%2e./api/admin/users',
|
|
49
|
+
'/ext/dep/./x',
|
|
50
|
+
'/api/data/projects/../users',
|
|
51
|
+
'/api/data/projects/..',
|
|
52
|
+
]) {
|
|
53
|
+
expect(dot(e)).toEqual(['SDUI_ENDPOINT_DOT_SEGMENT']);
|
|
54
|
+
}
|
|
55
|
+
expect(dot('/ext/dep/a..b?x=../y')).toEqual([]);
|
|
56
|
+
});
|
|
41
57
|
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { describe, expect, it } from 'bun:test';
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
|
-
import { $, actionPath, defaultView, fallbackFor, isBound, isEditable, matches, fileIds, readActionResult, resolveFiles, resolveInput, toFilter, toSort, validateView, } from '../view/index.js';
|
|
6
|
+
import { $, actionPath, defaultView, fallbackFor, isBound, isEditable, matches, fileIds, readActionResult, resolveFiles, resolveInput, resolveValue, toFilter, toSort, validateView, } from '../view/index.js';
|
|
7
7
|
const scope = {
|
|
8
8
|
record: { id: 'r1', status: 'open', total: 5 },
|
|
9
9
|
selected: { folders: 'f9' },
|
|
@@ -37,6 +37,28 @@ describe('references', () => {
|
|
|
37
37
|
expect(toFilter([$.where('folder_id', 'eq', $.selected('other'))], scope)).toBeNull();
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
|
+
describe('a name an object inherits', () => {
|
|
41
|
+
// A Name may be `constructor`; `{}.constructor` is `Object`, so a record
|
|
42
|
+
// without that field read as bound and a `notnull` on it held.
|
|
43
|
+
const empty = { record: {}, params: {}, selected: {}, selection: [{}] };
|
|
44
|
+
for (const name of ['constructor', 'toString', 'hasOwnProperty']) {
|
|
45
|
+
it(`reads \`${name}\` as missing on a record that lacks it`, () => {
|
|
46
|
+
expect(resolveValue({ $record: name }, empty)).toBeUndefined();
|
|
47
|
+
expect(resolveValue({ $param: name }, empty)).toBeUndefined();
|
|
48
|
+
expect(resolveValue({ $selected: name }, empty)).toBeUndefined();
|
|
49
|
+
expect(resolveValue({ $selection: name }, empty)).toEqual([undefined]);
|
|
50
|
+
expect(isBound({ action: 'a', input: { x: { $record: name } } }, empty)).toBe(false);
|
|
51
|
+
expect(resolveInput({ x: { $record: name } }, empty)).toBeNull();
|
|
52
|
+
expect(matches([{ field: name, op: 'not_null' }], {}, empty)).toBe(false);
|
|
53
|
+
expect(matches([{ field: name, op: 'null' }], {}, empty)).toBe(true);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
it('still reads an own field named `constructor`', () => {
|
|
57
|
+
const s = { record: { constructor: 'c1' } };
|
|
58
|
+
expect(resolveValue({ $record: 'constructor' }, s)).toBe('c1');
|
|
59
|
+
expect(matches([{ field: 'constructor', op: 'eq', value: 'c1' }], s.record, s)).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
40
62
|
describe('a button whose reference has no value yet', () => {
|
|
41
63
|
const none = { ...scope, selected: {} };
|
|
42
64
|
it('is not bound while the pane it names has no selection, and is once it has', () => {
|
|
@@ -94,6 +116,12 @@ describe('cross-key checks', () => {
|
|
|
94
116
|
}));
|
|
95
117
|
expect(r.ok ? [] : r.issues.map((i) => i.path)).toEqual(['/rowActions/0/prompt/0']);
|
|
96
118
|
});
|
|
119
|
+
it('refuses a file prompt whose input the button binds', () => {
|
|
120
|
+
const button = (input) => doc({ rowActions: [{ action: 'load', input, files: { prompt: { input: 'file' } } }] });
|
|
121
|
+
const r = validateView(button({ file: $.record('id') }));
|
|
122
|
+
expect(r.ok ? [] : r.issues.map((i) => i.path)).toEqual(['/rowActions/0/files/prompt/input']);
|
|
123
|
+
expect(validateView(button({ id: $.record('id') })).ok).toBe(true);
|
|
124
|
+
});
|
|
97
125
|
});
|
|
98
126
|
describe('matches', () => {
|
|
99
127
|
it('checks a row against conditions', () => {
|
|
@@ -158,7 +186,7 @@ describe('actions', () => {
|
|
|
158
186
|
expect(() => actionPath(ext, action)).toThrow();
|
|
159
187
|
}
|
|
160
188
|
});
|
|
161
|
-
it('reads a result as navigation, view, file, reveal or values', () => {
|
|
189
|
+
it('reads a result as navigation, view, file, reveal, redirect or values', () => {
|
|
162
190
|
expect(readActionResult({ view: 'mail.compose', params: { draft_id: 'd' } })).toEqual({
|
|
163
191
|
kind: 'navigate',
|
|
164
192
|
view: 'mail.compose',
|
|
@@ -167,6 +195,12 @@ describe('actions', () => {
|
|
|
167
195
|
expect(readActionResult({ view: { type: 'list', collection: 'x' } }).kind).toBe('view');
|
|
168
196
|
expect(readActionResult({ file: 'f1' })).toEqual({ kind: 'file', file: 'f1' });
|
|
169
197
|
expect(readActionResult({ reveal: 'k' })).toEqual({ kind: 'reveal', value: 'k' });
|
|
198
|
+
expect(readActionResult({ redirect: 'https://a.example/x' })).toEqual({
|
|
199
|
+
kind: 'redirect',
|
|
200
|
+
url: 'https://a.example/x',
|
|
201
|
+
});
|
|
202
|
+
// Only https: anything else is invalid, never a navigation.
|
|
203
|
+
expect(readActionResult({ redirect: 'javascript:alert(1)' }).kind).toBe('invalid');
|
|
170
204
|
expect(readActionResult({ total: 3 })).toEqual({ kind: 'values', values: { total: 3 } });
|
|
171
205
|
expect(readActionResult(null)).toEqual({ kind: 'values', values: null });
|
|
172
206
|
// A tagged object that is none of the closed forms is not values: no guessing.
|
package/dist/tests/view.test.js
CHANGED
|
@@ -5,10 +5,9 @@
|
|
|
5
5
|
import { describe, expect, it } from 'bun:test';
|
|
6
6
|
import { readFileSync } from 'node:fs';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
|
-
import { $, isViewDocument, VIEW_SPEC, validateView, view, viewNameIssues } from '../view/index.js';
|
|
8
|
+
import { $, facetOptions, isViewDocument, pickIssues, VIEW_SPEC, validateView, view, viewNameIssues, withFacets, } from '../view/index.js';
|
|
9
9
|
// Parsed, not imported: an import would turn the `__proto__` key into a prototype.
|
|
10
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
11
|
const fixtures = JSON.parse(readFileSync(join(import.meta.dir, '../../src/tests/fixtures/view-2.json'), 'utf8'));
|
|
13
12
|
const issues = (input) => {
|
|
14
13
|
const r = validateView(input);
|
|
@@ -85,7 +84,8 @@ describe('viewNameIssues', () => {
|
|
|
85
84
|
});
|
|
86
85
|
it('a $selected names an earlier pane of an enclosing split; pane ids are unique', () => {
|
|
87
86
|
const v = view.document(view.split({
|
|
88
|
-
|
|
87
|
+
// An input is values, but a reference in it is still checked.
|
|
88
|
+
actions: [{ action: 'sync', input: { a: $.selected('second'), b: $.selected('nowhere') } }],
|
|
89
89
|
panes: [
|
|
90
90
|
view.list({
|
|
91
91
|
id: 'first',
|
|
@@ -104,6 +104,7 @@ describe('viewNameIssues', () => {
|
|
|
104
104
|
'/panes/0/filter/0/value/$selected',
|
|
105
105
|
'/panes/2/id',
|
|
106
106
|
'/panes/2/record/$selected',
|
|
107
|
+
'/actions/0/input/b/$selected',
|
|
107
108
|
]);
|
|
108
109
|
});
|
|
109
110
|
it('navigate and open name a view of the extension; a message key must be shipped', () => {
|
|
@@ -210,3 +211,121 @@ describe('builder', () => {
|
|
|
210
211
|
expect(issues(built)).toEqual([]);
|
|
211
212
|
});
|
|
212
213
|
});
|
|
214
|
+
describe('pick and facets (DR-45)', () => {
|
|
215
|
+
const button = (extra) => ({
|
|
216
|
+
spec: VIEW_SPEC,
|
|
217
|
+
type: 'list',
|
|
218
|
+
collection: 'deals',
|
|
219
|
+
rowActions: [{ action: 'assign', ...extra }],
|
|
220
|
+
});
|
|
221
|
+
const names = {
|
|
222
|
+
collections: ['deals', 'people'],
|
|
223
|
+
actions: ['assign'],
|
|
224
|
+
fields: new Map([['deals', ['id', 'stage', 'won', 'notes']]]),
|
|
225
|
+
facetFields: new Map([['deals', ['stage', 'won']]]),
|
|
226
|
+
};
|
|
227
|
+
it('a button `pick` must be an input it asks for (`prompt`) and does not set (`input`)', () => {
|
|
228
|
+
expect(issues(button({ prompt: ['owner'], pick: { owner: 'people' } }))).toEqual([]);
|
|
229
|
+
expect(paths(button({ pick: { owner: 'people' } }))).toEqual(['/rowActions/0/pick/owner']);
|
|
230
|
+
expect(paths(button({ prompt: ['owner'], input: { owner: 'x' }, pick: { owner: 'people' } }))).toContain('/rowActions/0/pick/owner');
|
|
231
|
+
});
|
|
232
|
+
it('an action form `pick` is accepted; a collection form takes none', () => {
|
|
233
|
+
expect(issues({ spec: VIEW_SPEC, type: 'form', action: 'assign', pick: { owner: 'people' } })).toEqual([]);
|
|
234
|
+
expect(paths({ spec: VIEW_SPEC, type: 'form', collection: 'deals', pick: { owner: 'people' } })).toEqual(['/pick']);
|
|
235
|
+
});
|
|
236
|
+
it('a `pick` collection must be one the extension owns', () => {
|
|
237
|
+
const v = button({ prompt: ['owner'], pick: { owner: 'contacts' } });
|
|
238
|
+
expect(viewNameIssues(v, names).map((i) => i.path)).toEqual(['/rowActions/0/pick/owner']);
|
|
239
|
+
expect(viewNameIssues(button({ prompt: ['owner'], pick: { owner: 'people' } }), names)).toEqual([]);
|
|
240
|
+
// The input name is the caller's: a key named `action` or `collection` is no reference.
|
|
241
|
+
const odd = { spec: VIEW_SPEC, type: 'form', action: 'assign', pick: { action: 'people' } };
|
|
242
|
+
expect(viewNameIssues(odd, names)).toEqual([]);
|
|
243
|
+
});
|
|
244
|
+
it('a `pick` input must be a string property of its action input', () => {
|
|
245
|
+
const inputs = new Map([
|
|
246
|
+
[
|
|
247
|
+
'assign',
|
|
248
|
+
{
|
|
249
|
+
properties: {
|
|
250
|
+
owner: { type: 'string' },
|
|
251
|
+
maybe: { type: ['string', 'null'] },
|
|
252
|
+
n: { type: 'integer' },
|
|
253
|
+
kind: { type: 'string', enum: ['a'] },
|
|
254
|
+
many: { type: 'array', items: { type: 'string' } },
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
]);
|
|
259
|
+
const v = (pick) => button({ prompt: Object.keys(pick), pick });
|
|
260
|
+
expect(pickIssues(v({ owner: 'people', maybe: 'people' }), inputs)).toEqual([]);
|
|
261
|
+
expect(pickIssues(v({ n: 'people', kind: 'people', many: 'people', ghost: 'people' }), inputs).map((i) => i.path)).toEqual([
|
|
262
|
+
'/rowActions/0/pick/n',
|
|
263
|
+
'/rowActions/0/pick/kind',
|
|
264
|
+
'/rowActions/0/pick/many',
|
|
265
|
+
'/rowActions/0/pick/ghost',
|
|
266
|
+
]);
|
|
267
|
+
// An action with no known schema (a dependency's) is not checked.
|
|
268
|
+
expect(pickIssues(v({ n: 'people' }), new Map())).toEqual([]);
|
|
269
|
+
});
|
|
270
|
+
const facets = (extra) => ({
|
|
271
|
+
spec: VIEW_SPEC,
|
|
272
|
+
type: 'list',
|
|
273
|
+
collection: 'deals',
|
|
274
|
+
...extra,
|
|
275
|
+
});
|
|
276
|
+
it('a facet on a field the view `filter` constrains is refused', () => {
|
|
277
|
+
expect(issues(facets({ facets: ['stage'] }))).toEqual([]);
|
|
278
|
+
expect(paths(facets({ facets: ['stage', 'won'], filter: [{ field: 'won', op: 'eq', value: true }] }))).toEqual(['/facets/1']);
|
|
279
|
+
});
|
|
280
|
+
it('a facet must be a field of the collection with choices, or a boolean', () => {
|
|
281
|
+
expect(viewNameIssues(facets({ facets: ['stage', 'won'] }), names)).toEqual([]);
|
|
282
|
+
expect(viewNameIssues(facets({ facets: ['notes', 'ghost'] }), names).map((i) => [i.path, i.message])).toEqual([
|
|
283
|
+
['/facets/1', 'field "ghost" is not a field of "deals"'],
|
|
284
|
+
[
|
|
285
|
+
'/facets/0',
|
|
286
|
+
'field "notes" is neither a boolean nor a single-value field with declared choices',
|
|
287
|
+
],
|
|
288
|
+
]);
|
|
289
|
+
});
|
|
290
|
+
it('a facet field listed twice is refused', () => {
|
|
291
|
+
expect(paths(facets({ facets: ['stage', 'won', 'stage'] }))).toEqual(['/facets/2']);
|
|
292
|
+
});
|
|
293
|
+
it("facetOptions reads the engine's enum declaration (`options.values`)", () => {
|
|
294
|
+
// The shape every extension collection file and Studio's field editor write.
|
|
295
|
+
expect(facetOptions({ name: 'status', type: 'enum', options: { values: ['draft', 'sent'] } })).toEqual([
|
|
296
|
+
{ value: 'draft', label: 'draft' },
|
|
297
|
+
{ value: 'sent', label: 'sent' },
|
|
298
|
+
]);
|
|
299
|
+
});
|
|
300
|
+
it('facetOptions keeps a choice typed; a multi-value select offers none', () => {
|
|
301
|
+
expect(facetOptions({
|
|
302
|
+
name: 'n',
|
|
303
|
+
type: 'select',
|
|
304
|
+
options: { choices: [1, { value: 2, label: 'Two' }, true] },
|
|
305
|
+
})).toEqual([
|
|
306
|
+
{ value: 1, label: '1' },
|
|
307
|
+
{ value: 2, label: 'Two' },
|
|
308
|
+
{ value: true, label: 'true' },
|
|
309
|
+
]);
|
|
310
|
+
expect(facetOptions({ name: 'm', type: 'select', options: { multiple: true, choices: ['a'] } })).toEqual([]);
|
|
311
|
+
});
|
|
312
|
+
it('facetOptions: choices, or true and false for a boolean; withFacets keeps the view filter', () => {
|
|
313
|
+
expect(facetOptions({
|
|
314
|
+
name: 's',
|
|
315
|
+
type: 'select',
|
|
316
|
+
options: { choices: ['a', { value: 'b', label: 'B' }] },
|
|
317
|
+
})).toEqual([
|
|
318
|
+
{ value: 'a', label: 'a' },
|
|
319
|
+
{ value: 'b', label: 'B' },
|
|
320
|
+
]);
|
|
321
|
+
expect(facetOptions({ name: 'w', type: 'boolean' }).map((o) => o.value)).toEqual([true, false]);
|
|
322
|
+
expect(facetOptions({ name: 't', type: 'text' })).toEqual([]);
|
|
323
|
+
const own = [{ field: 'a', op: 'eq', value: 1 }];
|
|
324
|
+
expect(withFacets(own, { b: 'x', w: false, gone: undefined })).toEqual([
|
|
325
|
+
{ field: 'a', op: 'eq', value: 1 },
|
|
326
|
+
{ field: 'b', op: 'eq', value: 'x' },
|
|
327
|
+
{ field: 'w', op: 'eq', value: false },
|
|
328
|
+
]);
|
|
329
|
+
expect(withFacets(own, { a: 'x' })).toBe(own);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH,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,CAAC;IAChB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd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