@blueshed/joined 0.2.2 → 0.3.1
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/.claude/skills/joined/SKILL.md +9 -1
- package/.claude/skills/joined/reference.md +316 -63
- package/.claude/skills/joined-door/SKILL.md +57 -0
- package/README.md +19 -50
- package/docs/design.md +158 -37
- package/docs/introduction.md +27 -27
- package/docs/light-and-shadow.svg +2 -1
- package/docs/links-and-trust.svg +1 -0
- package/docs/stories-to-code.svg +2 -1
- package/docs/wire-op.svg +1 -0
- package/examples/README.md +20 -0
- package/examples/account/account.json +1 -0
- package/examples/account/derive.ts +41 -0
- package/examples/account/generated/elements.ts +52 -0
- package/examples/account/generated/rows.ts +22 -0
- package/examples/account/generated/rules.ts +32 -0
- package/examples/account/routes.ts +5 -0
- package/examples/app.css +11 -1
- package/examples/cafe/books.html +2 -2
- package/examples/cafe/cafe.css +96 -85
- package/examples/cafe/generated/books.rows.ts +22 -0
- package/examples/cafe/generated/books.rules.ts +3 -2
- package/examples/cafe/generated/kitchen.rows.ts +27 -0
- package/examples/cafe/generated/kitchen.rules.ts +11 -1
- package/examples/cafe/generated/menu.rows.ts +22 -0
- package/examples/cafe/generated/menu.rules.ts +3 -2
- package/examples/cafe/generated/order.rows.ts +27 -0
- package/examples/cafe/generated/order.rules.ts +11 -1
- package/examples/cafe/generated/staff.elements.ts +7 -2
- package/examples/cafe/generated/staff.rows.ts +22 -0
- package/examples/cafe/generated/staff.rules.ts +9 -1
- package/examples/cafe/generated/supplies.queries.ts +4 -2
- package/examples/cafe/generated/supplies.rows.ts +22 -0
- package/examples/cafe/generated/supplies.rules.ts +17 -1
- package/examples/cafe/generated/till.queries.ts +2 -0
- package/examples/cafe/generated/till.rows.ts +27 -0
- package/examples/cafe/generated/till.rules.ts +11 -1
- package/examples/cafe/index.html +14 -15
- package/examples/cafe/kitchen.css +11 -19
- package/examples/cafe/kitchen.ts +7 -3
- package/examples/cafe/look.ts +30 -0
- package/examples/cafe/menu.html +10 -26
- package/examples/cafe/menu.ts +8 -80
- package/examples/cafe/migrations/002-guard-supplies.ts +15 -0
- package/examples/cafe/order.html +8 -7
- package/examples/cafe/order.ts +6 -2
- package/examples/cafe/routes.ts +0 -1
- package/examples/cafe/staff.json +5 -0
- package/examples/cafe/stories.jsonl +6 -2
- package/examples/cafe/supplies.html +35 -34
- package/examples/cafe/supplies.ts +59 -39
- package/examples/cafe/till.ts +19 -11
- package/examples/cafe/views.ts +7 -5
- package/examples/chart/arches.ts +150 -0
- package/examples/chart/chart.css +11 -0
- package/examples/chart/chart.json +87 -0
- package/examples/chart/generated/elements.ts +105 -0
- package/examples/chart/generated/queries.ts +36 -0
- package/examples/chart/generated/rows.ts +27 -0
- package/examples/chart/generated/rules.ts +111 -0
- package/examples/chart/grid.ts +118 -0
- package/examples/chart/index.html +78 -0
- package/examples/chart/migrations/001-chart.ts +6 -0
- package/examples/chart/migrations/002-create-conditions.ts +6 -0
- package/examples/chart/page.ts +20 -0
- package/examples/chart/routes.ts +7 -0
- package/examples/chart/stories.jsonl +14 -0
- package/examples/chart/teeth.ts +57 -0
- package/examples/desk/desk.css +6 -10
- package/examples/desk/generated/elements.ts +1 -1
- package/examples/desk/generated/rows.ts +22 -0
- package/examples/desk/generated/rules.ts +34 -1
- package/examples/desk/index.html +10 -3
- package/examples/desk/lanes.css +21 -19
- package/examples/desk/routes.ts +0 -2
- package/examples/desk/stories.jsonl +4 -3
- package/examples/desk/tally.css +1 -1
- package/examples/desk/thumbs.ts +2 -2
- package/examples/docs.ts +7 -4
- package/examples/hello/generated/elements.ts +2 -2
- package/examples/hello/generated/rules.ts +3 -2
- package/examples/hello/hello.css +2 -4
- package/examples/hello/index.html +10 -3
- package/examples/hello/page.ts +4 -4
- package/examples/index.html +20 -12
- package/examples/notes/generated/elements.ts +112 -0
- package/examples/notes/generated/queries.ts +42 -0
- package/examples/notes/generated/rows.ts +27 -0
- package/examples/notes/generated/rules.ts +133 -0
- package/examples/notes/index.html +32 -0
- package/examples/notes/look.ts +41 -0
- package/examples/notes/migrations/001-notes.ts +7 -0
- package/examples/notes/notes.json +78 -0
- package/examples/notes/page.ts +21 -0
- package/examples/notes/routes.ts +6 -0
- package/examples/notes/stories.jsonl +24 -0
- package/examples/page.ts +9 -2
- package/examples/people/generated/rows.ts +22 -0
- package/examples/people/generated/rules.ts +11 -1
- package/examples/people/links.ts +8 -9
- package/examples/people/people.css +1 -1
- package/examples/people/routes.ts +1 -3
- package/examples/people/stories.jsonl +1 -0
- package/examples/people/view.ts +5 -2
- package/examples/trip/generated/elements.ts +5 -3
- package/examples/trip/generated/queries.ts +12 -1
- package/examples/trip/generated/rows.ts +27 -0
- package/examples/trip/generated/rules.ts +56 -2
- package/examples/trip/index.html +58 -12
- package/examples/trip/line.css +186 -0
- package/examples/trip/line.ts +51 -40
- package/examples/trip/page.ts +65 -71
- package/examples/trip/routes.ts +9 -5
- package/examples/trip/stays.css +13 -13
- package/examples/trip/stays.ts +15 -10
- package/examples/trip/stories.jsonl +2 -0
- package/examples/trip/told.ts +3 -26
- package/examples/trip/trip.css +16 -0
- package/examples/trips/generated/elements.ts +1 -1
- package/examples/trips/generated/rows.ts +22 -0
- package/examples/trips/generated/rules.ts +9 -1
- package/examples/trips/index.html +10 -10
- package/examples/trips/map.ts +3 -14
- package/examples/trips/new-trip.ts +14 -16
- package/examples/trips/trips.css +24 -23
- package/examples/weeks/generated/elements.ts +1 -1
- package/examples/weeks/generated/queries.ts +11 -0
- package/examples/weeks/generated/rows.ts +22 -0
- package/examples/weeks/generated/rules.ts +11 -5
- package/examples/weeks/routes.ts +3 -2
- package/examples/weeks/stories.jsonl +1 -0
- package/examples/welcome.css +43 -33
- package/package.json +8 -2
- package/src/attachment.ts +17 -2
- package/src/awesome.ts +103 -0
- package/src/board.css +76 -0
- package/src/board.ts +173 -0
- package/src/cli.ts +28 -3
- package/src/compile.ts +821 -109
- package/src/definitions.ts +113 -27
- package/src/demo.css +2 -5
- package/src/draft.ts +48 -27
- package/src/drawer.ts +248 -0
- package/src/engine.ts +253 -170
- package/src/fields.ts +341 -0
- package/src/file-value.ts +12 -2
- package/src/files.ts +113 -33
- package/src/ground.ts +110 -0
- package/src/icon-names.ts +19 -2
- package/src/keep.ts +16 -3
- package/src/kit.ts +51 -0
- package/src/link.ts +3 -3
- package/src/map.css +140 -0
- package/src/map.ts +200 -0
- package/src/mcp.ts +129 -24
- package/src/members/demo.ts +13 -12
- package/src/members/generated/rows.ts +22 -0
- package/src/members/generated/rules.ts +3 -2
- package/src/members/group.ts +105 -55
- package/src/members/keys.ts +95 -79
- package/src/members/panel.css +40 -35
- package/src/members/panel.ts +58 -37
- package/src/migrate.ts +178 -125
- package/src/migrations/005-change-kept.ts +7 -0
- package/src/month.css +129 -0
- package/src/month.ts +179 -0
- package/src/ops.ts +40 -1
- package/src/page.css +11 -2
- package/src/page.ts +68 -17
- package/src/parts.css +614 -230
- package/src/parts.ts +259 -36
- package/src/plane.css +61 -0
- package/src/plane.ts +153 -0
- package/src/postgres-server.ts +60 -0
- package/src/reading.css +73 -0
- package/src/reading.ts +238 -0
- package/src/rows.css +289 -0
- package/src/rows.ts +864 -0
- package/src/search.css +80 -0
- package/src/search.ts +130 -0
- package/src/server.ts +355 -137
- package/src/settings.ts +9 -4
- package/src/sheet.ts +116 -0
- package/src/skill.ts +40 -0
- package/src/slots.css +90 -0
- package/src/slots.ts +213 -0
- package/src/specs.ts +38 -0
- package/src/starter.ts +19 -2
- package/src/store.ts +224 -161
- package/src/stories.ts +43 -11
- package/src/surface.ts +164 -0
- package/src/time.ts +2 -0
- package/src/timeline.css +111 -0
- package/src/timeline.ts +235 -0
- package/src/toast.ts +21 -48
- package/src/together.ts +15 -24
- package/src/tokens.css +89 -3
- package/src/tokens.json +287 -7
- package/src/tool.ts +210 -0
- package/src/upkeep.ts +47 -22
- package/src/views.css +43 -0
- package/src/views.ts +111 -0
- package/src/week.css +150 -0
- package/src/week.ts +254 -0
- package/src/write.ts +326 -78
- package/starter/CHANGELOG.md +8 -0
- package/starter/CLAUDE.md +9 -3
- package/starter/bunfig +5 -0
- package/starter/githooks/pre-commit +13 -0
- package/starter/prettierignore +5 -0
- package/starter/tests/hello.test.ts +2 -0
- package/starter/tests/records.test.ts +40 -0
- package/starter/todo.jsonl +0 -0
- package/docs/learning.md +0 -76
- package/examples/cafe/trust.ts +0 -20
- package/examples/desk/trust.ts +0 -24
- package/examples/people/trust.ts +0 -14
- package/examples/trip/answer-rows.ts +0 -70
- package/examples/trip/bar.ts +0 -89
- package/examples/trip/calendar-map.css +0 -711
- package/examples/trip/calendar-map.ts +0 -249
- package/examples/trip/drags.ts +0 -143
- package/examples/trip/drawer.ts +0 -250
- package/examples/trip/event-form.ts +0 -200
- package/examples/trip/holding.ts +0 -61
- package/examples/trip/map.ts +0 -234
- package/examples/trip/month.ts +0 -87
- package/examples/trip/other-weeks.ts +0 -67
- package/examples/trip/peek.ts +0 -71
- package/examples/trip/people-chips.ts +0 -74
- package/examples/trip/shell.ts +0 -39
- package/examples/trip/trust.ts +0 -51
- package/examples/trip/week.ts +0 -237
- package/examples/trip/writes.ts +0 -91
- package/examples/trip/zones.ts +0 -16
- package/examples/weeks/derive.ts +0 -23
- package/src/scrim.ts +0 -81
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
|
|
4
4
|
|
|
5
5
|
/** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
|
|
6
|
-
* what each link is to. */
|
|
6
|
+
* what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
|
|
7
7
|
export const doc = "books";
|
|
8
8
|
export const collections = {
|
|
9
9
|
"entries": {
|
|
@@ -23,7 +23,8 @@ export const collections = {
|
|
|
23
23
|
"side",
|
|
24
24
|
"total"
|
|
25
25
|
],
|
|
26
|
-
"links": {}
|
|
26
|
+
"links": {},
|
|
27
|
+
"pops": {}
|
|
27
28
|
}
|
|
28
29
|
} as const;
|
|
29
30
|
/** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
// Each collection of kitchen as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
|
|
4
|
+
// extended, by define() from joined/rows, and holds each collection's element in its rows:
|
|
5
|
+
// <j-orders-rows><j-orders></j-orders><j-lines></j-lines></j-orders-rows>
|
|
6
|
+
// <j-lines-rows><j-lines></j-lines></j-lines-rows>
|
|
7
|
+
// A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
|
|
8
|
+
// To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
|
|
9
|
+
// step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
|
|
10
|
+
// under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
|
|
11
|
+
// use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
|
|
12
|
+
// elements. Never change this file: change the stories.
|
|
13
|
+
|
|
14
|
+
import { rows, type Spec } from "joined/rows";
|
|
15
|
+
import { JOrder, JLine } from "./kitchen.elements.ts";
|
|
16
|
+
|
|
17
|
+
const orders: Spec = {"doc":"kitchen","name":"orders","place":"j-orders","tag":"j-order","one":"order","title":"customer","fields":[{"name":"customer","type":"string","needed":true},{"name":"status","type":"string","how":"moves","steps":["placed","being made","ready"]},{"name":"placed","type":"instant","how":"filled"},{"name":"code","type":"string","how":"filled"},{"name":"total","type":"integer","how":"filled"}]};
|
|
18
|
+
const lines: Spec = {"doc":"kitchen","name":"lines","place":"j-lines","tag":"j-line","one":"line","title":"name","under":{"field":"order","in":"orders"},"fields":[{"name":"order","type":"integer","needed":true,"how":"one","to":{"tag":"j-order","title":"customer"}},{"name":"item","type":"integer","needed":true,"how":"one","to":{"tag":"j-item"},"ref":true},{"name":"qty","type":"integer","needed":true},{"name":"name","type":"string"},{"name":"price","type":"integer"}]};
|
|
19
|
+
|
|
20
|
+
/** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
|
|
21
|
+
export const specs = { "orders": orders, "lines": lines };
|
|
22
|
+
|
|
23
|
+
/** <j-orders-rows>: kitchen's orders as rows, each named by its customer, its lines under it. */
|
|
24
|
+
export class JOrdersRows extends rows(orders, { "j-order": JOrder, "j-line": JLine }, lines) {}
|
|
25
|
+
|
|
26
|
+
/** <j-lines-rows>: kitchen's lines as rows, each named by its name. */
|
|
27
|
+
export class JLinesRows extends rows(lines, { "j-line": JLine }) {}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
|
|
4
4
|
|
|
5
5
|
/** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
|
|
6
|
-
* what each link is to. */
|
|
6
|
+
* what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
|
|
7
7
|
export const doc = "kitchen";
|
|
8
8
|
export const collections = {
|
|
9
9
|
"orders": {
|
|
@@ -20,6 +20,11 @@ export const collections = {
|
|
|
20
20
|
"customer"
|
|
21
21
|
],
|
|
22
22
|
"links": {},
|
|
23
|
+
"pops": {
|
|
24
|
+
"placed": {
|
|
25
|
+
"form": "instant"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
23
28
|
"fills": {
|
|
24
29
|
"status": "placed",
|
|
25
30
|
"placed": "now",
|
|
@@ -45,6 +50,11 @@ export const collections = {
|
|
|
45
50
|
"links": {
|
|
46
51
|
"order": "orders",
|
|
47
52
|
"item": "items"
|
|
53
|
+
},
|
|
54
|
+
"pops": {
|
|
55
|
+
"item": {
|
|
56
|
+
"to": "items"
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
59
|
}
|
|
50
60
|
} as const;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
// Each collection of menu as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
|
|
4
|
+
// extended, by define() from joined/rows, and holds each collection's element in its rows:
|
|
5
|
+
// <j-items-rows><j-items></j-items></j-items-rows>
|
|
6
|
+
// A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
|
|
7
|
+
// To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
|
|
8
|
+
// step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
|
|
9
|
+
// under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
|
|
10
|
+
// use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
|
|
11
|
+
// elements. Never change this file: change the stories.
|
|
12
|
+
|
|
13
|
+
import { rows, type Spec } from "joined/rows";
|
|
14
|
+
import { JItem } from "./menu.elements.ts";
|
|
15
|
+
|
|
16
|
+
const items: Spec = {"doc":"menu","name":"items","place":"j-items","tag":"j-item","one":"item","title":"name","fields":[{"name":"name","type":"string","needed":true},{"name":"price","type":"integer","needed":true},{"name":"stock","type":"integer","needed":true}]};
|
|
17
|
+
|
|
18
|
+
/** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
|
|
19
|
+
export const specs = { "items": items };
|
|
20
|
+
|
|
21
|
+
/** <j-items-rows>: menu's items as rows, each named by its name. */
|
|
22
|
+
export class JItemsRows extends rows(items, { "j-item": JItem }) {}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
|
|
4
4
|
|
|
5
5
|
/** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
|
|
6
|
-
* what each link is to. */
|
|
6
|
+
* what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
|
|
7
7
|
export const doc = "menu";
|
|
8
8
|
export const collections = {
|
|
9
9
|
"items": {
|
|
@@ -19,7 +19,8 @@ export const collections = {
|
|
|
19
19
|
"price",
|
|
20
20
|
"stock"
|
|
21
21
|
],
|
|
22
|
-
"links": {}
|
|
22
|
+
"links": {},
|
|
23
|
+
"pops": {}
|
|
23
24
|
}
|
|
24
25
|
} as const;
|
|
25
26
|
/** Whether every story is anonymous, none told as a member: where every app's is, the project has no members. */
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
// Each collection of order as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
|
|
4
|
+
// extended, by define() from joined/rows, and holds each collection's element in its rows:
|
|
5
|
+
// <j-orders-rows><j-orders></j-orders><j-lines></j-lines></j-orders-rows>
|
|
6
|
+
// <j-lines-rows><j-lines></j-lines></j-lines-rows>
|
|
7
|
+
// A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
|
|
8
|
+
// To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
|
|
9
|
+
// step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
|
|
10
|
+
// under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
|
|
11
|
+
// use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
|
|
12
|
+
// elements. Never change this file: change the stories.
|
|
13
|
+
|
|
14
|
+
import { rows, type Spec } from "joined/rows";
|
|
15
|
+
import { JOrder, JLine } from "./order.elements.ts";
|
|
16
|
+
|
|
17
|
+
const orders: Spec = {"doc":"order","name":"orders","place":"j-orders","tag":"j-order","one":"order","title":"customer","fields":[{"name":"customer","type":"string","needed":true},{"name":"status","type":"string","how":"moves","steps":["placed","cancelled"]},{"name":"placed","type":"instant","how":"filled"},{"name":"code","type":"string","how":"filled"},{"name":"total","type":"integer","how":"filled"}]};
|
|
18
|
+
const lines: Spec = {"doc":"order","name":"lines","place":"j-lines","tag":"j-line","one":"line","title":"name","under":{"field":"order","in":"orders"},"fields":[{"name":"order","type":"integer","needed":true,"how":"one","to":{"tag":"j-order","title":"customer"}},{"name":"item","type":"integer","needed":true,"how":"one","to":{"tag":"j-item"},"ref":true},{"name":"qty","type":"integer","needed":true},{"name":"name","type":"string"},{"name":"price","type":"integer"}]};
|
|
19
|
+
|
|
20
|
+
/** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
|
|
21
|
+
export const specs = { "orders": orders, "lines": lines };
|
|
22
|
+
|
|
23
|
+
/** <j-orders-rows>: order's orders as rows, each named by its customer, its lines under it. */
|
|
24
|
+
export class JOrdersRows extends rows(orders, { "j-order": JOrder, "j-line": JLine }, lines) {}
|
|
25
|
+
|
|
26
|
+
/** <j-lines-rows>: order's lines as rows, each named by its name. */
|
|
27
|
+
export class JLinesRows extends rows(lines, { "j-line": JLine }) {}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
|
|
4
4
|
|
|
5
5
|
/** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
|
|
6
|
-
* what each link is to. */
|
|
6
|
+
* what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
|
|
7
7
|
export const doc = "order";
|
|
8
8
|
export const collections = {
|
|
9
9
|
"orders": {
|
|
@@ -20,6 +20,11 @@ export const collections = {
|
|
|
20
20
|
"customer"
|
|
21
21
|
],
|
|
22
22
|
"links": {},
|
|
23
|
+
"pops": {
|
|
24
|
+
"placed": {
|
|
25
|
+
"form": "instant"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
23
28
|
"fills": {
|
|
24
29
|
"status": "placed",
|
|
25
30
|
"placed": "now",
|
|
@@ -45,6 +50,11 @@ export const collections = {
|
|
|
45
50
|
"links": {
|
|
46
51
|
"order": "orders",
|
|
47
52
|
"item": "items"
|
|
53
|
+
},
|
|
54
|
+
"pops": {
|
|
55
|
+
"item": {
|
|
56
|
+
"to": "items"
|
|
57
|
+
}
|
|
48
58
|
}
|
|
49
59
|
}
|
|
50
60
|
} as const;
|
|
@@ -17,7 +17,7 @@ const send = (from: Element, ops: object[], why?: string) => new Promise<Answer>
|
|
|
17
17
|
/** A post's fields, as the stories give them. */
|
|
18
18
|
export type JPostData = { "role": string; "members": number[] };
|
|
19
19
|
/** An add of a post, as it's sent: its fields as the stories write them. */
|
|
20
|
-
export type JPostValue = { "role": string; "members": number[] };
|
|
20
|
+
export type JPostValue = { "role": string; "members": (number | `$${number}`)[] };
|
|
21
21
|
|
|
22
22
|
/** <j-post key>: role (string), members (ids in members), each an attribute. */
|
|
23
23
|
export class JPost extends HTMLElement {
|
|
@@ -33,6 +33,10 @@ export class JPost extends HTMLElement {
|
|
|
33
33
|
/** How a view shows it, drawn again whenever an attribute changes (what its person may do, its may, too). */
|
|
34
34
|
draw?(): void;
|
|
35
35
|
attributeChangedCallback() { this.#data = undefined; this.draw?.(); }
|
|
36
|
+
/** Replace some of its fields (members): one write for all of them. */
|
|
37
|
+
replace(fields: Partial<Pick<JPostData, "members">>, why?: string) {
|
|
38
|
+
return send(this, Object.entries(fields).filter(([, value]) => value !== undefined).map(([field, value]) => ({ op: "replace", path: `${this.path}/${field.replace(".", "/")}`, value })), why);
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
/** <j-posts>: the document's posts, each a <j-post> inside it. */
|
|
@@ -48,7 +52,8 @@ customElements.define("j-posts", JPosts);
|
|
|
48
52
|
|
|
49
53
|
/** An op on staff the stories allow, in any of its collections. */
|
|
50
54
|
export type StaffOp =
|
|
51
|
-
| { op: "add"; path: "/posts/-"; value: JPostValue }
|
|
55
|
+
| { op: "add"; path: "/posts/-"; value: JPostValue }
|
|
56
|
+
| { op: "replace"; path: `/posts/${number}/members`; value: number[] };
|
|
52
57
|
|
|
53
58
|
/** One write to staff across its collections (a move with its legs): sent from an element of it, checked
|
|
54
59
|
* whole by its rules, and made whole or not at all. */
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
// Each collection of staff as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
|
|
4
|
+
// extended, by define() from joined/rows, and holds each collection's element in its rows:
|
|
5
|
+
// <j-posts-rows><j-posts></j-posts></j-posts-rows>
|
|
6
|
+
// A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
|
|
7
|
+
// To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
|
|
8
|
+
// step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
|
|
9
|
+
// under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
|
|
10
|
+
// use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
|
|
11
|
+
// elements. Never change this file: change the stories.
|
|
12
|
+
|
|
13
|
+
import { rows, type Spec } from "joined/rows";
|
|
14
|
+
import { JPost } from "./staff.elements.ts";
|
|
15
|
+
|
|
16
|
+
const posts: Spec = {"doc":"staff","name":"posts","place":"j-posts","tag":"j-post","one":"post","title":"role","fields":[{"name":"role","type":"string","needed":true},{"name":"members","type":"ids","needed":true,"how":"ids","to":{"tag":"j-member","people":true},"ref":true}]};
|
|
17
|
+
|
|
18
|
+
/** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
|
|
19
|
+
export const specs = { "posts": posts };
|
|
20
|
+
|
|
21
|
+
/** <j-posts-rows>: staff's posts as rows, each named by its role. */
|
|
22
|
+
export class JPostsRows extends rows(posts, { "j-post": JPost }) {}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
|
|
4
4
|
|
|
5
5
|
/** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
|
|
6
|
-
* what each link is to. */
|
|
6
|
+
* what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
|
|
7
7
|
export const doc = "staff";
|
|
8
8
|
export const collections = {
|
|
9
9
|
"posts": {
|
|
@@ -19,6 +19,11 @@ export const collections = {
|
|
|
19
19
|
],
|
|
20
20
|
"links": {
|
|
21
21
|
"members": "members"
|
|
22
|
+
},
|
|
23
|
+
"pops": {
|
|
24
|
+
"members": {
|
|
25
|
+
"to": "members"
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
}
|
|
24
29
|
} as const;
|
|
@@ -40,6 +45,9 @@ export const kind = null;
|
|
|
40
45
|
export const grants: Record<string, string[]> = {
|
|
41
46
|
"add posts": [
|
|
42
47
|
"manager"
|
|
48
|
+
],
|
|
49
|
+
"replace posts.members": [
|
|
50
|
+
"manager"
|
|
43
51
|
]
|
|
44
52
|
};
|
|
45
53
|
|
|
@@ -25,7 +25,8 @@ export const triggers: string[] = [
|
|
|
25
25
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_gives_supplies_add\" AFTER INSERT ON main.\"supplies\" WHEN NEW.\"delivered\" = 1 BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" + NEW.\"qty\" WHERE id = NEW.\"item\"; END",
|
|
26
26
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_gives_supplies_remove\" AFTER DELETE ON main.\"supplies\" WHEN OLD.\"delivered\" = 1 BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" - OLD.\"qty\" WHERE id = OLD.\"item\"; END",
|
|
27
27
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_gives_supplies_replace\" AFTER UPDATE OF \"qty\", \"item\", \"delivered\" ON main.\"supplies\" BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" - OLD.\"qty\" WHERE id = OLD.\"item\" AND OLD.\"delivered\" = 1; UPDATE \"items\" SET \"stock\" = \"stock\" + NEW.\"qty\" WHERE id = NEW.\"item\" AND NEW.\"delivered\" = 1; END",
|
|
28
|
-
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_gives_supplies_none\" BEFORE UPDATE OF \"stock\" ON main.\"items\" BEGIN SELECT RAISE(ABORT, 'The kitchen has ' || OLD.\"stock\" || ' of ' || OLD.\"name\" || ': not enough to take ' || (OLD.\"stock\" - NEW.\"stock\") || '.') WHERE NEW.\"stock\" < 0; END"
|
|
28
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_gives_supplies_none\" BEFORE UPDATE OF \"stock\" ON main.\"items\" BEGIN SELECT RAISE(ABORT, 'The kitchen has ' || OLD.\"stock\" || ' of ' || OLD.\"name\" || ': not enough to take ' || (OLD.\"stock\" - NEW.\"stock\") || '.') WHERE NEW.\"stock\" < 0; END",
|
|
29
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_frozen_supplies\" BEFORE UPDATE ON main.\"supplies\" BEGIN SELECT RAISE(ABORT, 'a delivered supply keeps its price and terms') WHERE OLD.\"delivered\" = 1 AND (NEW.\"price\" IS NOT OLD.\"price\" OR NEW.\"terms.days\" IS NOT OLD.\"terms.days\" OR NEW.\"terms.by\" IS NOT OLD.\"terms.by\"); END"
|
|
29
30
|
];
|
|
30
31
|
|
|
31
32
|
/** Its items, its query and its triggers, as Postgres says them. */
|
|
@@ -38,6 +39,7 @@ export const postgres = {
|
|
|
38
39
|
"CREATE OR REPLACE FUNCTION \"joined_gives_supplies_add_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF NEW.\"delivered\" = 1 THEN UPDATE \"items\" SET \"stock\" = \"stock\" + NEW.\"qty\" WHERE id = NEW.\"item\"; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_gives_supplies_add\" AFTER INSERT ON \"supplies\" FOR EACH ROW EXECUTE FUNCTION \"joined_gives_supplies_add_fn\"()",
|
|
39
40
|
"CREATE OR REPLACE FUNCTION \"joined_gives_supplies_remove_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF OLD.\"delivered\" = 1 THEN UPDATE \"items\" SET \"stock\" = \"stock\" - OLD.\"qty\" WHERE id = OLD.\"item\"; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_gives_supplies_remove\" AFTER DELETE ON \"supplies\" FOR EACH ROW EXECUTE FUNCTION \"joined_gives_supplies_remove_fn\"()",
|
|
40
41
|
"CREATE OR REPLACE FUNCTION \"joined_gives_supplies_replace_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" - OLD.\"qty\" WHERE id = OLD.\"item\" AND OLD.\"delivered\" = 1; UPDATE \"items\" SET \"stock\" = \"stock\" + NEW.\"qty\" WHERE id = NEW.\"item\" AND NEW.\"delivered\" = 1; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_gives_supplies_replace\" AFTER UPDATE OF \"qty\", \"item\", \"delivered\" ON \"supplies\" FOR EACH ROW EXECUTE FUNCTION \"joined_gives_supplies_replace_fn\"()",
|
|
41
|
-
"CREATE OR REPLACE FUNCTION \"joined_gives_supplies_none_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF NEW.\"stock\" < 0 THEN RAISE EXCEPTION '%', 'The kitchen has ' || OLD.\"stock\" || ' of ' || OLD.\"name\" || ': not enough to take ' || (OLD.\"stock\" - NEW.\"stock\") || '.'; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_gives_supplies_none\" BEFORE UPDATE OF \"stock\" ON \"items\" FOR EACH ROW EXECUTE FUNCTION \"joined_gives_supplies_none_fn\"()"
|
|
42
|
+
"CREATE OR REPLACE FUNCTION \"joined_gives_supplies_none_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF NEW.\"stock\" < 0 THEN RAISE EXCEPTION '%', 'The kitchen has ' || OLD.\"stock\" || ' of ' || OLD.\"name\" || ': not enough to take ' || (OLD.\"stock\" - NEW.\"stock\") || '.'; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_gives_supplies_none\" BEFORE UPDATE OF \"stock\" ON \"items\" FOR EACH ROW EXECUTE FUNCTION \"joined_gives_supplies_none_fn\"()",
|
|
43
|
+
"CREATE OR REPLACE FUNCTION \"joined_frozen_supplies_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF OLD.\"delivered\" = 1 AND (NEW.\"price\" IS DISTINCT FROM OLD.\"price\" OR NEW.\"terms.days\" IS DISTINCT FROM OLD.\"terms.days\" OR NEW.\"terms.by\" IS DISTINCT FROM OLD.\"terms.by\") THEN RAISE EXCEPTION '%', 'a delivered supply keeps its price and terms'; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_frozen_supplies\" BEFORE UPDATE ON \"supplies\" FOR EACH ROW EXECUTE FUNCTION \"joined_frozen_supplies_fn\"()"
|
|
42
44
|
]
|
|
43
45
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
// Each collection of supplies as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
|
|
4
|
+
// extended, by define() from joined/rows, and holds each collection's element in its rows:
|
|
5
|
+
// <j-supplies-rows><j-supplies></j-supplies></j-supplies-rows>
|
|
6
|
+
// A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
|
|
7
|
+
// To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
|
|
8
|
+
// step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
|
|
9
|
+
// under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
|
|
10
|
+
// use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
|
|
11
|
+
// elements. Never change this file: change the stories.
|
|
12
|
+
|
|
13
|
+
import { rows, type Spec } from "joined/rows";
|
|
14
|
+
import { JSupply } from "./supplies.elements.ts";
|
|
15
|
+
|
|
16
|
+
const supplies: Spec = {"doc":"supplies","name":"supplies","place":"j-supplies","tag":"j-supply","one":"supply","title":"title","fields":[{"name":"title","type":"string","needed":true},{"name":"item","type":"integer","needed":true,"how":"one","to":{"tag":"j-item"},"ref":true},{"name":"qty","type":"integer","needed":true},{"name":"price","type":"integer","needed":true},{"name":"buyer","type":"integer","needed":true,"how":"one","to":{"tag":"j-member","people":true},"ref":true},{"name":"supplier","type":"integer","needed":true,"how":"one","to":{"tag":"j-member","people":true},"ref":true},{"name":"delivered","type":"boolean","needed":true}]};
|
|
17
|
+
|
|
18
|
+
/** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
|
|
19
|
+
export const specs = { "supplies": supplies };
|
|
20
|
+
|
|
21
|
+
/** <j-supplies-rows>: supplies's supplies as rows, each named by its title. */
|
|
22
|
+
export class JSuppliesRows extends rows(supplies, { "j-supply": JSupply }) {}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
|
|
4
4
|
|
|
5
5
|
/** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
|
|
6
|
-
* what each link is to. */
|
|
6
|
+
* what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
|
|
7
7
|
export const doc = "supplies";
|
|
8
8
|
export const collections = {
|
|
9
9
|
"supplies": {
|
|
@@ -35,6 +35,17 @@ export const collections = {
|
|
|
35
35
|
"item": "items",
|
|
36
36
|
"buyer": "members",
|
|
37
37
|
"supplier": "members"
|
|
38
|
+
},
|
|
39
|
+
"pops": {
|
|
40
|
+
"item": {
|
|
41
|
+
"to": "items"
|
|
42
|
+
},
|
|
43
|
+
"buyer": {
|
|
44
|
+
"to": "members"
|
|
45
|
+
},
|
|
46
|
+
"supplier": {
|
|
47
|
+
"to": "members"
|
|
48
|
+
}
|
|
38
49
|
}
|
|
39
50
|
}
|
|
40
51
|
} as const;
|
|
@@ -45,6 +56,11 @@ export const anonymous = false;
|
|
|
45
56
|
export const type = "shared";
|
|
46
57
|
/** The parts of supplies a page may hold alone, by its query's parameters (its definitions' window): null, none. */
|
|
47
58
|
export const window = null;
|
|
59
|
+
/** Each link whose every id names one a who-path finds, its test and the words another is refused in (its
|
|
60
|
+
* definitions' links, holds). */
|
|
61
|
+
export const names: Record<string, readonly [(m: number, read: (doc: string) => any, doc: string) => boolean, string]> = {
|
|
62
|
+
"supplier": [(m, read, doc) => (read("staff")["posts"] ?? []).some((i: any) => String(i["role"]) === "supplier" && (i["members"] === m || (Array.isArray(i["members"]) && i["members"].includes(m)))), "supplier names someone who isn't among staff's posts with role supplier"],
|
|
63
|
+
};
|
|
48
64
|
/** The document as one statement over its tables (generated/supplies.queries.ts). */
|
|
49
65
|
export { query, postgres, items, triggers } from "./supplies.queries.ts";
|
|
50
66
|
|
|
@@ -32,6 +32,7 @@ export const triggers: string[] = [
|
|
|
32
32
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_takes_lines_remove\" AFTER DELETE ON main.\"lines\" WHEN (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = OLD.\"order\") IS NOT 'cancelled' BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" + OLD.\"qty\" WHERE id = OLD.\"item\"; END",
|
|
33
33
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_takes_lines_replace\" AFTER UPDATE OF \"qty\", \"item\" ON main.\"lines\" BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" + OLD.\"qty\" WHERE id = OLD.\"item\" AND (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = OLD.\"order\") IS NOT 'cancelled'; UPDATE \"items\" SET \"stock\" = \"stock\" - NEW.\"qty\" WHERE id = NEW.\"item\" AND (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = NEW.\"order\") IS NOT 'cancelled'; END",
|
|
34
34
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_takes_lines_none\" BEFORE UPDATE OF \"stock\" ON main.\"items\" BEGIN SELECT RAISE(ABORT, 'The kitchen has ' || OLD.\"stock\" || ' of ' || OLD.\"name\" || ': not enough to take ' || (OLD.\"stock\" - NEW.\"stock\") || '.') WHERE NEW.\"stock\" < 0; END",
|
|
35
|
+
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_with_lines_order\" BEFORE INSERT ON main.\"lines\" BEGIN SELECT RAISE(ABORT, 'an order''s lines are set when it''s placed') WHERE NOT EXISTS (SELECT 1 FROM temp.joined_touched t WHERE t.tbl = 'orders' AND t.id = NEW.\"order\" AND t.before IS NULL); END",
|
|
35
36
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_totals_orders_total_add\" AFTER INSERT ON main.\"lines\" BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.\"order\") WHERE id = NEW.\"order\"; END",
|
|
36
37
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_totals_orders_total_remove\" AFTER DELETE ON main.\"lines\" BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = OLD.\"order\") WHERE id = OLD.\"order\"; END",
|
|
37
38
|
"CREATE TEMP TRIGGER IF NOT EXISTS \"joined_totals_orders_total_replace\" AFTER UPDATE ON main.\"lines\" BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = OLD.\"order\") WHERE id = OLD.\"order\"; UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.\"order\") WHERE id = NEW.\"order\"; END"
|
|
@@ -50,6 +51,7 @@ export const postgres = {
|
|
|
50
51
|
"CREATE OR REPLACE FUNCTION \"joined_takes_lines_remove_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = OLD.\"order\") IS DISTINCT FROM 'cancelled' THEN UPDATE \"items\" SET \"stock\" = \"stock\" + OLD.\"qty\" WHERE id = OLD.\"item\"; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_takes_lines_remove\" AFTER DELETE ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_takes_lines_remove_fn\"()",
|
|
51
52
|
"CREATE OR REPLACE FUNCTION \"joined_takes_lines_replace_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"items\" SET \"stock\" = \"stock\" + OLD.\"qty\" WHERE id = OLD.\"item\" AND (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = OLD.\"order\") IS DISTINCT FROM 'cancelled'; UPDATE \"items\" SET \"stock\" = \"stock\" - NEW.\"qty\" WHERE id = NEW.\"item\" AND (SELECT o.\"status\" FROM \"orders\" o WHERE o.id = NEW.\"order\") IS DISTINCT FROM 'cancelled'; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_takes_lines_replace\" AFTER UPDATE OF \"qty\", \"item\" ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_takes_lines_replace_fn\"()",
|
|
52
53
|
"CREATE OR REPLACE FUNCTION \"joined_takes_lines_none_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF NEW.\"stock\" < 0 THEN RAISE EXCEPTION '%', 'The kitchen has ' || OLD.\"stock\" || ' of ' || OLD.\"name\" || ': not enough to take ' || (OLD.\"stock\" - NEW.\"stock\") || '.'; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_takes_lines_none\" BEFORE UPDATE OF \"stock\" ON \"items\" FOR EACH ROW EXECUTE FUNCTION \"joined_takes_lines_none_fn\"()",
|
|
54
|
+
"CREATE OR REPLACE FUNCTION \"joined_with_lines_order_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_temp.joined_touched t WHERE t.tbl = 'orders' AND t.id = NEW.\"order\" AND t.before IS NULL) THEN RAISE EXCEPTION '%', 'an order''s lines are set when it''s placed'; END IF; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_with_lines_order\" BEFORE INSERT ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_with_lines_order_fn\"()",
|
|
53
55
|
"CREATE OR REPLACE FUNCTION \"joined_totals_orders_total_add_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.\"order\") WHERE id = NEW.\"order\"; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_totals_orders_total_add\" AFTER INSERT ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_totals_orders_total_add_fn\"()",
|
|
54
56
|
"CREATE OR REPLACE FUNCTION \"joined_totals_orders_total_remove_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = OLD.\"order\") WHERE id = OLD.\"order\"; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_totals_orders_total_remove\" AFTER DELETE ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_totals_orders_total_remove_fn\"()",
|
|
55
57
|
"CREATE OR REPLACE FUNCTION \"joined_totals_orders_total_replace_fn\"() RETURNS trigger LANGUAGE plpgsql AS $joined$ BEGIN UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = OLD.\"order\") WHERE id = OLD.\"order\"; UPDATE \"orders\" SET \"total\" = (SELECT COALESCE(SUM(i.\"qty\" * i.\"price\"), 0) FROM \"lines\" i WHERE i.\"order\" = NEW.\"order\") WHERE id = NEW.\"order\"; IF TG_OP = 'DELETE' THEN RETURN OLD; END IF; RETURN NEW; END $joined$; CREATE OR REPLACE TRIGGER \"joined_totals_orders_total_replace\" AFTER UPDATE ON \"lines\" FOR EACH ROW EXECUTE FUNCTION \"joined_totals_orders_total_replace_fn\"()"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Written by src/compile.ts from examples/cafe/stories.jsonl: change the stories, not this.
|
|
2
|
+
|
|
3
|
+
// Each collection of till as rows (joined/rows, the skill's §3): a page defines the ones it shows, as they are or
|
|
4
|
+
// extended, by define() from joined/rows, and holds each collection's element in its rows:
|
|
5
|
+
// <j-orders-rows><j-orders></j-orders><j-lines></j-lines></j-orders-rows>
|
|
6
|
+
// <j-lines-rows><j-lines></j-lines></j-lines-rows>
|
|
7
|
+
// A collection whose items are each of one of another's is drawn under it there, where its element is put in too.
|
|
8
|
+
// To change what one says or does, extend its class and override a part (label, named, says, facts, deeds, row,
|
|
9
|
+
// step, asks); to change how it looks, style its parts (::part(row), title, state, facts, deeds, mine, step, add,
|
|
10
|
+
// under, drawer). Its sheet, a search of it and how a field reads are joined/kit's, given these collections by
|
|
11
|
+
// use(specs) (define() gives a display's own). To draw something else altogether, don't define it: a display of the app's own holds the same
|
|
12
|
+
// elements. Never change this file: change the stories.
|
|
13
|
+
|
|
14
|
+
import { rows, type Spec } from "joined/rows";
|
|
15
|
+
import { JOrder, JLine } from "./till.elements.ts";
|
|
16
|
+
|
|
17
|
+
const orders: Spec = {"doc":"till","name":"orders","place":"j-orders","tag":"j-order","one":"order","title":"customer","fields":[{"name":"customer","type":"string","needed":true},{"name":"status","type":"string","how":"moves","steps":["placed","cancelled","ready","collected"]},{"name":"placed","type":"instant","how":"filled"},{"name":"code","type":"string","how":"filled"},{"name":"total","type":"integer","how":"filled"}]};
|
|
18
|
+
const lines: Spec = {"doc":"till","name":"lines","place":"j-lines","tag":"j-line","one":"line","under":{"field":"order","in":"orders"},"fields":[{"name":"order","type":"integer","needed":true,"how":"one","to":{"tag":"j-order","title":"customer"}},{"name":"item","type":"integer","needed":true,"how":"one","to":{"tag":"j-item"},"ref":true},{"name":"qty","type":"integer","needed":true},{"name":"name","type":"string","how":"filled"},{"name":"price","type":"integer","how":"filled"}]};
|
|
19
|
+
|
|
20
|
+
/** Each collection as joined's kit (joined/kit) is given it, by name: use(specs). */
|
|
21
|
+
export const specs = { "orders": orders, "lines": lines };
|
|
22
|
+
|
|
23
|
+
/** <j-orders-rows>: till's orders as rows, each named by its customer, its lines under it. */
|
|
24
|
+
export class JOrdersRows extends rows(orders, { "j-order": JOrder, "j-line": JLine }, lines) {}
|
|
25
|
+
|
|
26
|
+
/** <j-lines-rows>: till's lines as rows. */
|
|
27
|
+
export class JLinesRows extends rows(lines, { "j-line": JLine }) {}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
export type Op = { op: "add" | "replace" | "remove"; path: string; value?: any };
|
|
4
4
|
|
|
5
5
|
/** The document, and each collection: its element, the element its items are, their fields, those an add needs, and
|
|
6
|
-
* what each link is to. */
|
|
6
|
+
* what each link is to and what each field pops (a value with a form, its view; a reference, what it points at). */
|
|
7
7
|
export const doc = "till";
|
|
8
8
|
export const collections = {
|
|
9
9
|
"orders": {
|
|
@@ -20,6 +20,11 @@ export const collections = {
|
|
|
20
20
|
"customer"
|
|
21
21
|
],
|
|
22
22
|
"links": {},
|
|
23
|
+
"pops": {
|
|
24
|
+
"placed": {
|
|
25
|
+
"form": "instant"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
23
28
|
"fills": {
|
|
24
29
|
"status": "placed",
|
|
25
30
|
"placed": "now",
|
|
@@ -46,6 +51,11 @@ export const collections = {
|
|
|
46
51
|
"order": "orders",
|
|
47
52
|
"item": "items"
|
|
48
53
|
},
|
|
54
|
+
"pops": {
|
|
55
|
+
"item": {
|
|
56
|
+
"to": "items"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
49
59
|
"copies": {
|
|
50
60
|
"from": "item",
|
|
51
61
|
"fields": [
|
package/examples/cafe/index.html
CHANGED
|
@@ -27,27 +27,26 @@
|
|
|
27
27
|
</nav>
|
|
28
28
|
</header>
|
|
29
29
|
<main class="cafe till">
|
|
30
|
-
<
|
|
30
|
+
<wa-card class="card" aria-label="New order">
|
|
31
31
|
<h2>New order</h2>
|
|
32
32
|
<form class="place">
|
|
33
33
|
<j-items doc="menu" aria-label="The menu"></j-items>
|
|
34
34
|
<div class="order" aria-label="The order">
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/></label>
|
|
35
|
+
<wa-input
|
|
36
|
+
name="customer"
|
|
37
|
+
label="For"
|
|
38
|
+
placeholder="Their name"
|
|
39
|
+
required
|
|
40
|
+
maxlength="40"
|
|
41
|
+
autocomplete="off"
|
|
42
|
+
></wa-input>
|
|
44
43
|
<ul class="lines"></ul>
|
|
45
44
|
<p class="total"><span>Total</span><b>£0.00</b></p>
|
|
46
45
|
<button class="act ink" data-icon="check">Place order</button>
|
|
47
46
|
<p class="said" role="status"></p>
|
|
48
47
|
</div>
|
|
49
48
|
</form>
|
|
50
|
-
</
|
|
49
|
+
</wa-card>
|
|
51
50
|
<section class="card board" aria-label="Orders">
|
|
52
51
|
<div class="heads">
|
|
53
52
|
<h2>In the kitchen</h2>
|
|
@@ -58,13 +57,13 @@
|
|
|
58
57
|
<j-lines doc="till"></j-lines>
|
|
59
58
|
</section>
|
|
60
59
|
</main>
|
|
61
|
-
<dialog class="ask">
|
|
62
|
-
<h2></h2>
|
|
63
|
-
<footer>
|
|
60
|
+
<wa-dialog class="ask" light-dismiss>
|
|
61
|
+
<h2 slot="label"></h2>
|
|
62
|
+
<footer slot="footer">
|
|
64
63
|
<button type="button" class="act" name="keep">Never mind</button>
|
|
65
64
|
<button type="button" class="act danger" name="sure">Cancel it</button>
|
|
66
65
|
</footer>
|
|
67
|
-
</dialog>
|
|
66
|
+
</wa-dialog>
|
|
68
67
|
<script type="module" src="./till.ts"></script>
|
|
69
68
|
</body>
|
|
70
69
|
</html>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* <kitchen-rail>'s look, adopted in its shadow (with joined's parts): a kitchen's screen, read from across the room,
|
|
2
|
-
|
|
3
|
-
edge, ink words, how long it's waited
|
|
4
|
-
filled
|
|
2
|
+
who and what large. Its colours are the cafe's, as the till's and a customer's order are drawn: a ticket a card in
|
|
3
|
+
its edge, ink words, how long it's waited in muted words beside who it's for; late, after ten minutes, it says so,
|
|
4
|
+
a tag filled in the page's flavour, and the ticket edged in it. Light and dark as the device asks. */
|
|
5
5
|
:host {
|
|
6
6
|
display: block;
|
|
7
7
|
}
|
|
@@ -19,11 +19,11 @@
|
|
|
19
19
|
}
|
|
20
20
|
section {
|
|
21
21
|
min-height: 8rem;
|
|
22
|
-
border-radius:
|
|
22
|
+
border-radius: var(--radius);
|
|
23
23
|
}
|
|
24
24
|
section[over] {
|
|
25
|
-
outline:
|
|
26
|
-
outline-offset:
|
|
25
|
+
outline: var(--size-ring) dashed var(--ink);
|
|
26
|
+
outline-offset: var(--size-ring);
|
|
27
27
|
}
|
|
28
28
|
h3 {
|
|
29
29
|
margin: 0 0 var(--space-8);
|
|
@@ -43,7 +43,7 @@ ol {
|
|
|
43
43
|
gap: var(--space-8);
|
|
44
44
|
padding: var(--space-12);
|
|
45
45
|
border: 1px solid var(--edge);
|
|
46
|
-
border-radius:
|
|
46
|
+
border-radius: var(--radius);
|
|
47
47
|
background: var(--card);
|
|
48
48
|
color: var(--ink);
|
|
49
49
|
}
|
|
@@ -63,19 +63,11 @@ ol {
|
|
|
63
63
|
}
|
|
64
64
|
.wait {
|
|
65
65
|
padding: 0 var(--space-8);
|
|
66
|
-
border-radius:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
font: var(--font-heading);
|
|
66
|
+
border-radius: var(--radius-pill);
|
|
67
|
+
color: var(--muted);
|
|
68
|
+
font: var(--font-row);
|
|
70
69
|
white-space: nowrap;
|
|
71
70
|
}
|
|
72
|
-
.ticket[data-status="being made"] .wait {
|
|
73
|
-
background: color-mix(in srgb, var(--flavour) 24%, transparent);
|
|
74
|
-
}
|
|
75
|
-
.ticket[data-status="ready"] .wait {
|
|
76
|
-
background: none;
|
|
77
|
-
box-shadow: inset 0 0 0 1px var(--flavour-deep);
|
|
78
|
-
}
|
|
79
71
|
.ticket[late] .wait {
|
|
80
72
|
background: var(--flavour-solid);
|
|
81
73
|
color: var(--on-flavour);
|
|
@@ -93,7 +85,7 @@ ul {
|
|
|
93
85
|
.acts .act {
|
|
94
86
|
width: 100%;
|
|
95
87
|
justify-content: center;
|
|
96
|
-
min-height:
|
|
88
|
+
min-height: var(--size-finger);
|
|
97
89
|
}
|
|
98
90
|
/* a ticket picked up: over the rest, following the pointer */
|
|
99
91
|
.ticket[dragged] {
|
package/examples/cafe/kitchen.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// may (the order's may): its button, or the ticket dragged to the next column (./rail-drag.ts). Ready, it waits there
|
|
6
6
|
// until the till hands it over, and leaves the kitchen's document, and its ticket the rail. A change makes again only
|
|
7
7
|
// the tickets whose orders it changed (keep); each minute the waits are said again. It's the smallest display to
|
|
8
|
-
// copy: the trip's
|
|
8
|
+
// copy: the trip's line (../trip/line.ts) is the same, grown, a reading of the kit's.
|
|
9
9
|
|
|
10
10
|
import "joined/panel";
|
|
11
11
|
import "joined/toast";
|
|
@@ -85,14 +85,18 @@ class KitchenRail extends HTMLElement {
|
|
|
85
85
|
make: () => {
|
|
86
86
|
const ticket = Object.assign(document.createElement("li"), { className: "ticket" });
|
|
87
87
|
ticket.dataset.status = status;
|
|
88
|
-
|
|
88
|
+
const late = status !== "ready" && waited >= 10;
|
|
89
|
+
ticket.toggleAttribute("late", late);
|
|
89
90
|
const head = Object.assign(document.createElement("p"), { className: "head" }),
|
|
90
91
|
acts = Object.assign(document.createElement("p"), { className: "acts" }),
|
|
91
92
|
why = Object.assign(document.createElement("p"), { className: "said", role: "status" });
|
|
92
93
|
// read from across the room: who, and how long they've waited, large; its column says where it is
|
|
93
94
|
head.append(
|
|
94
95
|
Object.assign(document.createElement("b"), { textContent: `#${order.key} ${customer}` }),
|
|
95
|
-
Object.assign(document.createElement("span"), {
|
|
96
|
+
Object.assign(document.createElement("span"), {
|
|
97
|
+
className: "wait",
|
|
98
|
+
textContent: `${late ? "late, " : ""}${waitOf(waited)}`,
|
|
99
|
+
}),
|
|
96
100
|
);
|
|
97
101
|
const list = document.createElement("ul");
|
|
98
102
|
list.append(...lines.map((words) => Object.assign(document.createElement("li"), { textContent: words })));
|