@uniweb/api 0.3.6 → 0.4.0
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 +96 -23
- package/bin/uniweb-api-mock.js +20 -2
- package/package.json +2 -2
- package/src/client.js +237 -84
- package/src/errors.js +39 -12
- package/src/hooks/useEntity.js +9 -4
- package/src/hooks/useEntityWriter.js +42 -26
- package/src/hooks/useRecords.js +18 -6
- package/src/http.js +11 -6
- package/src/ledger.js +87 -55
- package/src/mock/index.js +330 -116
- package/src/mock/node.js +6 -2
- package/src/mock/schema-shape.js +8 -0
- package/src/mock/seed.js +39 -22
- package/src/mock/store.js +580 -295
- package/src/wire.js +312 -139
package/src/mock/seed.js
CHANGED
|
@@ -3,46 +3,63 @@
|
|
|
3
3
|
* template uses and a seed nobody edits should still show something.
|
|
4
4
|
*
|
|
5
5
|
* ⭐ **A seed is the mock's whole data model**, and it is a plain object on purpose:
|
|
6
|
-
* a developer edits it in one file, diffs it, and commits it.
|
|
7
|
-
* a database would take away.
|
|
6
|
+
* a developer edits it in one file, diffs it, and commits it.
|
|
8
7
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* - **`accounts`** — `operator: true` marks the account that runs the site's
|
|
9
|
+
* service. Everyone else is a member. Seeded accounts are verified.
|
|
10
|
+
* - **`schemas`** — per Model: `creatable_by` (`any_user`, the default, or
|
|
11
|
+
* `unit_members` — the operator only) and `sections`, the Model's sections as
|
|
12
|
+
* the framework lowers them. With `sections`, writes are shape-checked.
|
|
13
|
+
* - **`entities`** — `uuid` must be a UUID, as it is on the wire; content is items,
|
|
14
|
+
* each naming its section. The entity's `brief` is derived from its brief
|
|
15
|
+
* section's item, as the backend derives it.
|
|
12
16
|
*/
|
|
13
17
|
export const DEFAULT_SEED = {
|
|
14
18
|
accounts: [
|
|
15
|
-
// The organiser
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
{ username: 'attendee', password: 'attendee', handle: 'attendee', units: [], roles: ['member'] },
|
|
19
|
+
// The organiser runs the site, so the rule on `@/track` lets them author the programme.
|
|
20
|
+
{ username: 'organiser', password: 'organiser', operator: true },
|
|
21
|
+
// The attendee is a member — the same rule refuses them, server-side, and that
|
|
22
|
+
// refusal is the demo. They may record attending, which anyone may.
|
|
23
|
+
{ username: 'attendee', password: 'attendee' },
|
|
21
24
|
],
|
|
22
25
|
schemas: {
|
|
23
|
-
'@/track': {
|
|
24
|
-
|
|
26
|
+
'@/track': {
|
|
27
|
+
creatable_by: 'unit_members',
|
|
28
|
+
sections: {
|
|
29
|
+
track: { kind: 'single', brief: true, fields: { name: { type: 'string', required: true } } },
|
|
30
|
+
sessions: {
|
|
31
|
+
kind: 'multi',
|
|
32
|
+
fields: { title: { type: 'string', required: true }, room: { type: 'string' }, minutes: { type: 'int' } },
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
25
36
|
// Check-ins are insert-only: an attendee may record attending, and nobody —
|
|
26
37
|
// including them — may edit or remove it afterwards.
|
|
27
|
-
'@/attendance': {
|
|
38
|
+
'@/attendance': {
|
|
39
|
+
creatable_by: 'any_user',
|
|
40
|
+
sections: {
|
|
41
|
+
attendance: { kind: 'single', brief: true, fields: { who: { type: 'string' } } },
|
|
42
|
+
checkins: { kind: 'multi', append_only: true, fields: { session: { type: 'string' }, at: { type: 'string' } } },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
28
45
|
},
|
|
29
46
|
entities: [
|
|
30
47
|
{
|
|
31
|
-
uuid: '
|
|
48
|
+
uuid: '01926d5e-0000-7000-8000-00000000a001',
|
|
32
49
|
model: '@/track',
|
|
33
|
-
data: { name: 'Main hall' },
|
|
34
50
|
items: [
|
|
35
|
-
{
|
|
36
|
-
{
|
|
37
|
-
{
|
|
51
|
+
{ section: 'track', data: { name: 'Main hall' } },
|
|
52
|
+
{ section: 'sessions', data: { title: 'Opening keynote', room: 'Hall A', minutes: 45 } },
|
|
53
|
+
{ section: 'sessions', data: { title: 'Designing for the edge', room: 'Hall A', minutes: 30 } },
|
|
54
|
+
{ section: 'sessions', data: { title: 'Closing panel', room: 'Hall A', minutes: 60 } },
|
|
38
55
|
],
|
|
39
56
|
},
|
|
40
57
|
{
|
|
41
|
-
uuid: '
|
|
58
|
+
uuid: '01926d5e-0000-7000-8000-00000000a002',
|
|
42
59
|
model: '@/track',
|
|
43
|
-
data: { name: 'Workshops' },
|
|
44
60
|
items: [
|
|
45
|
-
{
|
|
61
|
+
{ section: 'track', data: { name: 'Workshops' } },
|
|
62
|
+
{ section: 'sessions', data: { title: 'Hands-on: foundations', room: 'Room 2', minutes: 90 } },
|
|
46
63
|
],
|
|
47
64
|
},
|
|
48
65
|
],
|