@composable-os/sdk 0.1.0-beta.10 → 0.1.0-beta.13
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/acknowledge.d.ts +38 -0
- package/dist/acknowledge.js +30 -0
- package/dist/agreements.d.ts +80 -0
- package/dist/agreements.js +109 -0
- package/dist/allowance.d.ts +47 -5
- package/dist/allowance.js +59 -4
- package/dist/automation-check.d.ts +6 -1
- package/dist/automation-check.js +93 -8
- package/dist/automation.d.ts +62 -4
- package/dist/automation.js +32 -9
- package/dist/behaviour.js +25 -6
- package/dist/calendar-entry.d.ts +97 -0
- package/dist/calendar-entry.js +180 -0
- package/dist/capacity.d.ts +69 -0
- package/dist/capacity.js +63 -2
- package/dist/checklists.d.ts +41 -0
- package/dist/checklists.js +75 -0
- package/dist/contract.d.ts +527 -26
- package/dist/contract.js +21 -3
- package/dist/discount.d.ts +135 -0
- package/dist/discount.js +281 -0
- package/dist/document.d.ts +2 -1
- package/dist/document.js +2 -1
- package/dist/field-types.d.ts +1 -1
- package/dist/field-types.js +5 -0
- package/dist/formula/compile.d.ts +15 -0
- package/dist/formula/compile.js +9 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -0
- package/dist/intake.d.ts +134 -0
- package/dist/intake.js +239 -0
- package/dist/journey-signals.d.ts +89 -0
- package/dist/journey-signals.js +151 -0
- package/dist/manifest.d.ts +1060 -60
- package/dist/manifest.js +1111 -61
- package/dist/mine.d.ts +45 -0
- package/dist/mine.js +119 -0
- package/dist/occupies.d.ts +64 -0
- package/dist/occupies.js +122 -0
- package/dist/questions.d.ts +179 -0
- package/dist/questions.js +514 -0
- package/dist/recurring.d.ts +33 -4
- package/dist/recurring.js +50 -3
- package/dist/restricted-fields.d.ts +15 -0
- package/dist/restricted-fields.js +97 -0
- package/dist/rich-text.d.ts +22 -0
- package/dist/rich-text.js +91 -0
- package/dist/routine-mail.d.ts +400 -0
- package/dist/routine-mail.js +955 -0
- package/dist/runtime.d.ts +5 -11
- package/dist/runtime.js +21 -11
- package/dist/screens.d.ts +3 -0
- package/dist/screens.js +74 -0
- package/dist/sellable.d.ts +231 -2
- package/dist/sellable.js +342 -1
- package/dist/slug.d.ts +2 -0
- package/dist/slug.js +6 -2
- package/dist/staffed.d.ts +178 -0
- package/dist/staffed.js +287 -0
- package/dist/states.d.ts +74 -4
- package/dist/states.js +154 -58
- package/dist/stock.d.ts +129 -0
- package/dist/stock.js +205 -0
- package/dist/team.d.ts +28 -0
- package/dist/team.js +52 -0
- package/dist/testing.d.ts +22 -1
- package/dist/testing.js +47 -5
- package/dist/worked-on.d.ts +42 -0
- package/dist/worked-on.js +79 -0
- package/package.json +9 -1
- package/src/acknowledge.ts +100 -0
- package/src/agreements.ts +185 -0
- package/src/allowance.ts +98 -8
- package/src/automation-check.ts +120 -9
- package/src/automation.ts +78 -10
- package/src/behaviour.ts +26 -6
- package/src/calendar-entry.ts +258 -0
- package/src/capacity.ts +103 -2
- package/src/checklists.ts +118 -0
- package/src/contract.ts +514 -27
- package/src/discount.ts +408 -0
- package/src/document.ts +4 -2
- package/src/field-types.ts +5 -0
- package/src/formula/compile.ts +10 -0
- package/src/index.ts +17 -0
- package/src/intake.ts +380 -0
- package/src/journey-signals.ts +215 -0
- package/src/manifest.ts +1313 -66
- package/src/mine.ts +161 -0
- package/src/occupies.ts +192 -0
- package/src/questions.ts +681 -0
- package/src/recurring.ts +90 -9
- package/src/restricted-fields.ts +129 -0
- package/src/rich-text.ts +112 -0
- package/src/routine-mail.ts +1272 -0
- package/src/runtime.ts +25 -12
- package/src/screens.ts +91 -0
- package/src/sellable.ts +595 -1
- package/src/slug.ts +7 -2
- package/src/staffed.ts +474 -0
- package/src/states.ts +220 -64
- package/src/stock.ts +332 -0
- package/src/team.ts +83 -0
- package/src/testing.ts +70 -6
- package/src/worked-on.ts +134 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// The `calendarEntry` declaration (stage 62 step 1, ADR 0891): an object whose records are events
|
|
2
|
+
// in its customer's calendar feed. Its manifest schema, the path walker the host's check shares,
|
|
3
|
+
// and the contract checks live here; the host's side (the feed's read, through the visibility seam
|
|
4
|
+
// as the customer) is packages/core/src/customers/calendar-feed.ts.
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const path = z.string().min(1).max(122);
|
|
7
|
+
export const calendarEntryManifestSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
starts: path,
|
|
10
|
+
ends: path,
|
|
11
|
+
title: path,
|
|
12
|
+
place: path.optional(),
|
|
13
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20),
|
|
14
|
+
})
|
|
15
|
+
.strict();
|
|
16
|
+
/** At most two relations, then the field: `class.room.name`. */
|
|
17
|
+
export const CALENDAR_PATH_MAX_SEGMENTS = 3;
|
|
18
|
+
/** What a path's last field may be, by key. */
|
|
19
|
+
export const CALENDAR_PATH_TYPES = {
|
|
20
|
+
starts: ["datetime"],
|
|
21
|
+
ends: ["datetime"],
|
|
22
|
+
title: ["text", "select"],
|
|
23
|
+
place: ["text", "select"],
|
|
24
|
+
};
|
|
25
|
+
/** The keys whose fields past the first must be public (shown text, never only a time). */
|
|
26
|
+
export const CALENDAR_PUBLIC_ONLY_KEYS = new Set(["title", "place"]);
|
|
27
|
+
const PUBLIC_ONLY = CALENDAR_PUBLIC_ONLY_KEYS;
|
|
28
|
+
/**
|
|
29
|
+
* Walks `path` from `origin`, the object declaring the entry, whose customer reads
|
|
30
|
+
* `originRead`. `lookup` answers an object by registry name: undefined to defer it (not this
|
|
31
|
+
* checker's), null when there is no such object. Pure.
|
|
32
|
+
*/
|
|
33
|
+
export function walkCalendarPath(origin, originRead, path, lookup,
|
|
34
|
+
/**
|
|
35
|
+
* Past the first field, only what the related object makes `public` or `signedIn` (a title or
|
|
36
|
+
* a place, ADR 0891): never a field the customer reads only through their own record, such as a
|
|
37
|
+
* class's own title, which may name another member. The feed is a bearer link.
|
|
38
|
+
*/
|
|
39
|
+
publicOnly = false) {
|
|
40
|
+
const segments = path.split(".");
|
|
41
|
+
if (segments.length > CALENDAR_PATH_MAX_SEGMENTS || segments.some((s) => s === "")) {
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
message: `"${path}" must be a field, or at most two relations and a field`,
|
|
45
|
+
foreign: false,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
let object = origin;
|
|
49
|
+
let readable = originRead;
|
|
50
|
+
let foreign = false;
|
|
51
|
+
for (const [i, segment] of segments.entries()) {
|
|
52
|
+
const field = object.field(segment);
|
|
53
|
+
if (!field) {
|
|
54
|
+
return { ok: false, message: `"${segment}" is not a field of ${object.name}`, foreign };
|
|
55
|
+
}
|
|
56
|
+
if (!readable.has(segment)) {
|
|
57
|
+
return {
|
|
58
|
+
ok: false,
|
|
59
|
+
message: i === 0
|
|
60
|
+
? `"${segment}" must be in ${object.name}'s customer.read: the feed shows only what the customer reads`
|
|
61
|
+
: publicOnly
|
|
62
|
+
? `"${segment}" is not a public field of ${object.name}: a title or place shows only what ${object.name} makes public or signedIn`
|
|
63
|
+
: `"${segment}" is not a field a customer reads of ${object.name} (its public, signedIn or customerVia read)`,
|
|
64
|
+
foreign,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (i === segments.length - 1)
|
|
68
|
+
return { ok: true, type: field.type, foreign };
|
|
69
|
+
if (field.type !== "relation" || field.many || !field.to) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
message: `"${segment}" must be a relation to one record to reach "${segments[i + 1]}"`,
|
|
73
|
+
foreign,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const next = lookup(field.to);
|
|
77
|
+
if (next === undefined)
|
|
78
|
+
return { ok: "deferred" };
|
|
79
|
+
foreign ||= !field.to.startsWith(`${origin.name.split(".")[0]}.`);
|
|
80
|
+
if (next === null)
|
|
81
|
+
return { ok: false, message: `${field.to} is not installed here`, foreign };
|
|
82
|
+
if (next.hasCustomer) {
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
message: `${next.name} declares a customer of its own: a path cannot pass through it`,
|
|
86
|
+
foreign,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
// Only one relation away does a customerVia from the declaring object count (the seam's
|
|
90
|
+
// `via` scope reaches what the customer's own records point to, no further), and never for a
|
|
91
|
+
// title or a place.
|
|
92
|
+
const via = i === 0 && !publicOnly;
|
|
93
|
+
readable = next.readable(via ? origin.name : null, via ? segment : null);
|
|
94
|
+
object = next;
|
|
95
|
+
}
|
|
96
|
+
return { ok: false, message: `"${path}" is empty`, foreign };
|
|
97
|
+
}
|
|
98
|
+
/** A manifest object as the walker sees it. */
|
|
99
|
+
export function manifestPathObject(extensionId, local, object) {
|
|
100
|
+
const name = `${extensionId}.${local}`;
|
|
101
|
+
return {
|
|
102
|
+
name,
|
|
103
|
+
hasCustomer: object.customer !== undefined,
|
|
104
|
+
field(fieldName) {
|
|
105
|
+
const field = Object.hasOwn(object.fields, fieldName)
|
|
106
|
+
? object.fields[fieldName]
|
|
107
|
+
: undefined;
|
|
108
|
+
return field ? { type: field.type, many: field.many === true, to: field.to } : undefined;
|
|
109
|
+
},
|
|
110
|
+
readable(from, via) {
|
|
111
|
+
const out = new Set([
|
|
112
|
+
...(object.public?.read ?? []),
|
|
113
|
+
...(object.signedIn?.read ?? []),
|
|
114
|
+
]);
|
|
115
|
+
const v = object.customerVia;
|
|
116
|
+
if (v && from !== null && v.from === from && v.field === via) {
|
|
117
|
+
for (const f of v.read)
|
|
118
|
+
out.add(f);
|
|
119
|
+
}
|
|
120
|
+
return out;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Reports problems with `objects.<name>.calendarEntry` through `contract`. */
|
|
125
|
+
export function checkObjectCalendarEntry(m, name, object, contract) {
|
|
126
|
+
const entry = object.calendarEntry;
|
|
127
|
+
if (!entry)
|
|
128
|
+
return;
|
|
129
|
+
const at = `objects.${name}.calendarEntry`;
|
|
130
|
+
const customer = object.customer;
|
|
131
|
+
if (!customer) {
|
|
132
|
+
contract(at, `${name} must declare a customer: a calendar entry is in its customer's feed`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const read = new Set(customer.read);
|
|
136
|
+
// The states in which a record shows, which the customer reads.
|
|
137
|
+
const states = object.states;
|
|
138
|
+
if (!states) {
|
|
139
|
+
contract(`${at}.live`, `${name} must declare states: a record shows in some of them`);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
const field = Object.hasOwn(object.fields, states.field) ? object.fields[states.field] : null;
|
|
143
|
+
const values = new Set((field?.options ?? []).map((o) => o.value));
|
|
144
|
+
for (const state of entry.live) {
|
|
145
|
+
if (!values.has(state))
|
|
146
|
+
contract(`${at}.live`, `"${state}" is not a state of ${name}`);
|
|
147
|
+
}
|
|
148
|
+
if (new Set(entry.live).size !== entry.live.length) {
|
|
149
|
+
contract(`${at}.live`, "List each state once");
|
|
150
|
+
}
|
|
151
|
+
if (!read.has(states.field)) {
|
|
152
|
+
contract(`${at}.live`, `"${states.field}" must be in ${name}'s customer.read: the feed reads the state as the customer`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Each path, as far as this extension's own objects go; the host checks another extension's.
|
|
156
|
+
const origin = manifestPathObject(m.id, name, object);
|
|
157
|
+
const lookup = (target) => {
|
|
158
|
+
const local = target.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
159
|
+
if (local === undefined)
|
|
160
|
+
return undefined;
|
|
161
|
+
return Object.hasOwn(m.objects, local)
|
|
162
|
+
? manifestPathObject(m.id, local, m.objects[local])
|
|
163
|
+
: null;
|
|
164
|
+
};
|
|
165
|
+
for (const key of ["starts", "ends", "title", "place"]) {
|
|
166
|
+
const declared = entry[key];
|
|
167
|
+
if (declared === undefined)
|
|
168
|
+
continue;
|
|
169
|
+
const result = walkCalendarPath(origin, read, declared, lookup, PUBLIC_ONLY.has(key));
|
|
170
|
+
if (result.ok === "deferred")
|
|
171
|
+
continue;
|
|
172
|
+
if (!result.ok)
|
|
173
|
+
contract(`${at}.${key}`, result.message);
|
|
174
|
+
else if (!CALENDAR_PATH_TYPES[key].includes(result.type)) {
|
|
175
|
+
contract(`${at}.${key}`, `"${declared}" must end at a ${CALENDAR_PATH_TYPES[key].join(" or ")} field`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (entry.starts === entry.ends)
|
|
179
|
+
contract(`${at}.ends`, "An event's start and end are two fields");
|
|
180
|
+
}
|
package/dist/capacity.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { ExtensionManifest, ObjectManifest } from "./manifest.ts";
|
|
3
|
+
import { type WindowBound } from "./states.ts";
|
|
3
4
|
/**
|
|
4
5
|
* What customers and the public are told about a record's places (staff always see the real
|
|
5
6
|
* numbers): `exact`, the number left; `low`, available, "only N left" at or below `lowAt`, or sold
|
|
@@ -66,11 +67,79 @@ export interface ClaimsSpec {
|
|
|
66
67
|
on: string;
|
|
67
68
|
held?: readonly string[];
|
|
68
69
|
confirmed?: readonly string[];
|
|
70
|
+
waitlist?: WaitlistSpec;
|
|
69
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* A waitlist on the claimed record's places (stage 31, ADR 0520). A record in `state` waits: it
|
|
74
|
+
* holds no place and spends nothing. It may be made only while the record it claims on is full
|
|
75
|
+
* and before `until`. Until then, a place given back while anyone waits is handed to the waitlist
|
|
76
|
+
* in the same statements that give it back, as a hold of its own that nobody booking directly
|
|
77
|
+
* can take. The host then promotes the first waiter (by when the record was made) from a current
|
|
78
|
+
* read: the move from `state` into `promote` takes the waitlist's hold, and whatever that move
|
|
79
|
+
* spends is spent then. A waiter who cannot be moved in (their spend is refused) is passed over
|
|
80
|
+
* and stays waiting; a hold nobody can take is given back to everyone. From `until`, nobody is
|
|
81
|
+
* promoted and a place given back goes to whoever claims first.
|
|
82
|
+
*
|
|
83
|
+
* - `state` is a state of the object that neither holds nor takes a place, and is not final.
|
|
84
|
+
* - `promote` is one of `confirmed`; a move from `state` to it must be declared for the host.
|
|
85
|
+
* Declared for a customer too (with a window), it lets a waiter take a free place themselves:
|
|
86
|
+
* only the host's promotion takes a place the waitlist holds, so nobody jumps the queue.
|
|
87
|
+
* - `until` is a moment, named as a window's end is (`{ at: "class.startsAt", minutesBefore:
|
|
88
|
+
* { field: "class.classType.promotionMinutes", setting: "promotionMinutes" } }`).
|
|
89
|
+
* - `promotedAt`, `passedOverAt` (read-only datetimes) and `passedOverReason` (read-only text)
|
|
90
|
+
* are what the host writes when it promotes a waiter or passes one over, for messages.
|
|
91
|
+
* - The claimed object has no pool.
|
|
92
|
+
*/
|
|
93
|
+
export interface WaitlistSpec {
|
|
94
|
+
state: string;
|
|
95
|
+
promote: string;
|
|
96
|
+
until: string | WindowBound;
|
|
97
|
+
promotedAt?: string;
|
|
98
|
+
passedOverAt?: string;
|
|
99
|
+
passedOverReason?: string;
|
|
100
|
+
}
|
|
101
|
+
export declare const waitlistManifestSchema: z.ZodObject<{
|
|
102
|
+
state: z.ZodString;
|
|
103
|
+
promote: z.ZodString;
|
|
104
|
+
until: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
105
|
+
at: z.ZodString;
|
|
106
|
+
daysBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
107
|
+
field: z.ZodOptional<z.ZodString>;
|
|
108
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
109
|
+
}, z.core.$strict>]>>;
|
|
110
|
+
minutesBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
111
|
+
field: z.ZodOptional<z.ZodString>;
|
|
112
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
113
|
+
}, z.core.$strict>]>>;
|
|
114
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
115
|
+
}, z.core.$strict>]>;
|
|
116
|
+
promotedAt: z.ZodOptional<z.ZodString>;
|
|
117
|
+
passedOverAt: z.ZodOptional<z.ZodString>;
|
|
118
|
+
passedOverReason: z.ZodOptional<z.ZodString>;
|
|
119
|
+
}, z.core.$strict>;
|
|
70
120
|
export declare const claimsManifestSchema: z.ZodObject<{
|
|
71
121
|
on: z.ZodString;
|
|
72
122
|
held: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
73
123
|
confirmed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
124
|
+
waitlist: z.ZodOptional<z.ZodObject<{
|
|
125
|
+
state: z.ZodString;
|
|
126
|
+
promote: z.ZodString;
|
|
127
|
+
until: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
128
|
+
at: z.ZodString;
|
|
129
|
+
daysBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
130
|
+
field: z.ZodOptional<z.ZodString>;
|
|
131
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
132
|
+
}, z.core.$strict>]>>;
|
|
133
|
+
minutesBefore: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodObject<{
|
|
134
|
+
field: z.ZodOptional<z.ZodString>;
|
|
135
|
+
setting: z.ZodOptional<z.ZodString>;
|
|
136
|
+
}, z.core.$strict>]>>;
|
|
137
|
+
zone: z.ZodOptional<z.ZodString>;
|
|
138
|
+
}, z.core.$strict>]>;
|
|
139
|
+
promotedAt: z.ZodOptional<z.ZodString>;
|
|
140
|
+
passedOverAt: z.ZodOptional<z.ZodString>;
|
|
141
|
+
passedOverReason: z.ZodOptional<z.ZodString>;
|
|
142
|
+
}, z.core.$strict>>;
|
|
74
143
|
}, z.core.$strict>;
|
|
75
144
|
export type ClaimsManifest = z.infer<typeof claimsManifestSchema>;
|
|
76
145
|
/** Reports problems with `objects.<name>.claims` through `contract`. */
|
package/dist/capacity.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// actor. Its declaration, its manifest schema and its contract checks live here; the host's side
|
|
4
4
|
// is packages/core/src/capacity/.
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { moveOrigins, windowBoundSchema, windowChecks } from "./states.js";
|
|
6
7
|
/**
|
|
7
8
|
* What customers and the public are told about a record's places (staff always see the real
|
|
8
9
|
* numbers): `exact`, the number left; `low`, available, "only N left" at or below `lowAt`, or sold
|
|
@@ -66,11 +67,22 @@ export function checkObjectCapacity(m, name, object, contract) {
|
|
|
66
67
|
contract(`${path}.lowAt`, 'show: "low" needs lowAt, the number at or below which it says so');
|
|
67
68
|
}
|
|
68
69
|
}
|
|
70
|
+
export const waitlistManifestSchema = z
|
|
71
|
+
.object({
|
|
72
|
+
state: z.string().min(1).max(100),
|
|
73
|
+
promote: z.string().min(1).max(100),
|
|
74
|
+
until: windowBoundSchema,
|
|
75
|
+
promotedAt: fieldName.optional(),
|
|
76
|
+
passedOverAt: fieldName.optional(),
|
|
77
|
+
passedOverReason: fieldName.optional(),
|
|
78
|
+
})
|
|
79
|
+
.strict();
|
|
69
80
|
export const claimsManifestSchema = z
|
|
70
81
|
.object({
|
|
71
82
|
on: fieldName,
|
|
72
83
|
held: z.array(z.string().min(1).max(100)).max(20).optional(),
|
|
73
84
|
confirmed: z.array(z.string().min(1).max(100)).max(20).optional(),
|
|
85
|
+
waitlist: waitlistManifestSchema.optional(),
|
|
74
86
|
})
|
|
75
87
|
.strict();
|
|
76
88
|
/** Reports problems with `objects.<name>.claims` through `contract`. */
|
|
@@ -119,9 +131,58 @@ export function checkObjectClaims(m, name, object, contract) {
|
|
|
119
131
|
contract(path, `"${both[0]}" cannot both hold and take a place`);
|
|
120
132
|
}
|
|
121
133
|
states.moves.forEach((move, i) => {
|
|
122
|
-
|
|
123
|
-
if (held.includes(move.to) && from.some((state) => confirmed.includes(state))) {
|
|
134
|
+
if (held.includes(move.to) && moveOrigins(move).some((state) => confirmed.includes(state))) {
|
|
124
135
|
contract(`objects.${name}.states.moves.${i}`, `A move from a state that takes a place cannot go back to one that only holds it ("${move.to}")`);
|
|
125
136
|
}
|
|
126
137
|
});
|
|
138
|
+
const waitlist = claims.waitlist;
|
|
139
|
+
if (!waitlist)
|
|
140
|
+
return;
|
|
141
|
+
// A waitlist (ADR 0520).
|
|
142
|
+
const wp = `${path}.waitlist`;
|
|
143
|
+
if (!values.has(waitlist.state)) {
|
|
144
|
+
contract(`${wp}.state`, `"${waitlist.state}" is not a state of ${name}`);
|
|
145
|
+
}
|
|
146
|
+
else if (held.includes(waitlist.state) || confirmed.includes(waitlist.state)) {
|
|
147
|
+
contract(`${wp}.state`, `"${waitlist.state}" waits: it can neither hold nor take a place`);
|
|
148
|
+
}
|
|
149
|
+
else if (states.moves.some((move) => move.final && move.to === waitlist.state)) {
|
|
150
|
+
contract(`${wp}.state`, `"${waitlist.state}" is final: nobody waits in it`);
|
|
151
|
+
}
|
|
152
|
+
else if (states.initial !== waitlist.state &&
|
|
153
|
+
!Object.hasOwn(states.create?.in ?? {}, waitlist.state)) {
|
|
154
|
+
contract(`${wp}.state`, `"${waitlist.state}" must be a state ${name} may be created in (states.create.in): a waiter joins by being made waiting`);
|
|
155
|
+
}
|
|
156
|
+
if (!confirmed.includes(waitlist.promote)) {
|
|
157
|
+
contract(`${wp}.promote`, `"${waitlist.promote}" must be one of claims.confirmed`);
|
|
158
|
+
}
|
|
159
|
+
const promotions = states.moves.filter((move) => move.to === waitlist.promote && moveOrigins(move).includes(waitlist.state));
|
|
160
|
+
if (!promotions.some((move) => move.by.includes("host"))) {
|
|
161
|
+
contract(`${wp}.promote`, `Declare a move from "${waitlist.state}" to "${waitlist.promote}" by the host: promotion is the host's`);
|
|
162
|
+
}
|
|
163
|
+
// A customer may move their own waiting record in, but only onto a free place: the host's
|
|
164
|
+
// promotion alone takes a place the waitlist holds, so nobody moves themselves ahead of it.
|
|
165
|
+
// Their move needs the create's window, so they cannot claim a place booking would refuse.
|
|
166
|
+
promotions.forEach((move) => {
|
|
167
|
+
if (move.by.includes("customer") && !move.window) {
|
|
168
|
+
contract(`${wp}.promote`, `A customer's move from "${waitlist.state}" to "${waitlist.promote}" needs a window (the create's): it books them`);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
windowChecks(m, object, name, contract).checkBound(waitlist.until, `${wp}.until`);
|
|
172
|
+
for (const [key, type] of [
|
|
173
|
+
["promotedAt", "datetime"],
|
|
174
|
+
["passedOverAt", "datetime"],
|
|
175
|
+
["passedOverReason", "text"],
|
|
176
|
+
]) {
|
|
177
|
+
const local = waitlist[key];
|
|
178
|
+
if (local === undefined)
|
|
179
|
+
continue;
|
|
180
|
+
const field = Object.hasOwn(object.fields, local) ? object.fields[local] : undefined;
|
|
181
|
+
if (field?.type !== type || field.many || !field.readOnly) {
|
|
182
|
+
contract(`${wp}.${key}`, `"${local}" must be a read-only ${type} field of ${name}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (targetObject?.capacity?.pool !== undefined) {
|
|
186
|
+
contract(`${wp}`, `A waitlist is on places with no pool; ${target} has one`);
|
|
187
|
+
}
|
|
127
188
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ExtensionManifest, ObjectManifest } from "./manifest.ts";
|
|
3
|
+
/**
|
|
4
|
+
* A checklist a record's person ticks off (ADR 0650). A business writes a checklist once (its
|
|
5
|
+
* steps, in Settings → Checklists) and picks it on something that happens (a duty); each record
|
|
6
|
+
* that is live with one gets a **run** of it, made by the host a day before it opens, with the
|
|
7
|
+
* steps copied as they were then (a template changed later changes no run already made). Its
|
|
8
|
+
* person ticks it off from when it opens until it closes and a grace period after; someone who
|
|
9
|
+
* rosters may tick for them, with a reason, recorded as theirs for that person. A run marked done
|
|
10
|
+
* never changes, refused by the database for every writer; one not done by its close and grace is
|
|
11
|
+
* closed by the host as missed, and the rosterers are told. How a run went is read only by its
|
|
12
|
+
* person and by those who roster, never by other staff, any rec_* view or an AI.
|
|
13
|
+
*
|
|
14
|
+
* - `template`: the field naming the checklist, of type `checklist`: one of this object's, or
|
|
15
|
+
* `relation.field` through a relation (one record) to another of this extension's objects (a
|
|
16
|
+
* duty shift's `duty.checklist`).
|
|
17
|
+
* - `who`: the `user` field holding the staff account who ticks it (the shift's person).
|
|
18
|
+
* - `opens`, `closes`: datetime fields of this object, when it may be ticked (the shift's start and
|
|
19
|
+
* end).
|
|
20
|
+
* - `live`: the states of the object's `states` in which it applies. A record in any other state,
|
|
21
|
+
* or in the Trash, at its close is closed as cancelled, not missed.
|
|
22
|
+
*
|
|
23
|
+
* Only shipped packs and the org's own extensions declare it: who ticks what is a staff record.
|
|
24
|
+
*/
|
|
25
|
+
export interface ChecklistsSpec {
|
|
26
|
+
template: string;
|
|
27
|
+
who: string;
|
|
28
|
+
opens: string;
|
|
29
|
+
closes: string;
|
|
30
|
+
live: readonly string[];
|
|
31
|
+
}
|
|
32
|
+
export declare const checklistsManifestSchema: z.ZodObject<{
|
|
33
|
+
template: z.ZodString;
|
|
34
|
+
who: z.ZodString;
|
|
35
|
+
opens: z.ZodString;
|
|
36
|
+
closes: z.ZodString;
|
|
37
|
+
live: z.ZodArray<z.ZodString>;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
export type ChecklistsManifest = z.infer<typeof checklistsManifestSchema>;
|
|
40
|
+
/** Reports problems with `objects.<name>.checklists` through `contract`. */
|
|
41
|
+
export declare function checkObjectChecklists(m: ExtensionManifest, name: string, object: ObjectManifest, contract: (path: string, message: string) => void): void;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The `checklists` declaration (stage 45 step 4b, ADR 0650): a record its person ticks a checklist
|
|
2
|
+
// off on. Its manifest schema and contract checks live here; the host's side (the templates, the
|
|
3
|
+
// runs and their ticks, a completed run kept unchanged by the database, who reads how it went) is
|
|
4
|
+
// packages/core/src/checklists/.
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const fieldName = z.string().max(40);
|
|
7
|
+
export const checklistsManifestSchema = z
|
|
8
|
+
.object({
|
|
9
|
+
template: z.string().max(81),
|
|
10
|
+
who: fieldName,
|
|
11
|
+
opens: fieldName,
|
|
12
|
+
closes: fieldName,
|
|
13
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20),
|
|
14
|
+
})
|
|
15
|
+
.strict();
|
|
16
|
+
/** Reports problems with `objects.<name>.checklists` through `contract`. */
|
|
17
|
+
export function checkObjectChecklists(m, name, object, contract) {
|
|
18
|
+
const declared = object.checklists;
|
|
19
|
+
if (!declared)
|
|
20
|
+
return;
|
|
21
|
+
const at = `objects.${name}.checklists`;
|
|
22
|
+
const own = (o, local) => Object.hasOwn(o.fields, local) ? o.fields[local] : undefined;
|
|
23
|
+
const single = (field, types) => field !== undefined && types.includes(field.type) && !field.many;
|
|
24
|
+
// The template: a checklist field of this object, or of what a relation of it names.
|
|
25
|
+
const [first, second, ...rest] = declared.template.split(".");
|
|
26
|
+
if (first === undefined || rest.length) {
|
|
27
|
+
contract(`${at}.template`, `"${declared.template}" must be a field, or relation.field`);
|
|
28
|
+
}
|
|
29
|
+
else if (second === undefined) {
|
|
30
|
+
if (!single(own(object, first), ["checklist"])) {
|
|
31
|
+
contract(`${at}.template`, `"${first}" must be a checklist field of ${name}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const via = own(object, first);
|
|
36
|
+
const target = via?.type === "relation" && !via.many ? via.to : undefined;
|
|
37
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
38
|
+
const holder = local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
39
|
+
if (!holder || local === name) {
|
|
40
|
+
contract(`${at}.template`, `"${first}" must be a relation field (one record) to another of this extension's objects`);
|
|
41
|
+
}
|
|
42
|
+
else if (!single(own(holder, second), ["checklist"])) {
|
|
43
|
+
contract(`${at}.template`, `"${second}" must be a checklist field of ${target}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Who ticks it.
|
|
47
|
+
if (!single(own(object, declared.who), ["user"])) {
|
|
48
|
+
contract(`${at}.who`, `"${declared.who}" must be a user field of ${name}`);
|
|
49
|
+
}
|
|
50
|
+
// When it opens and closes.
|
|
51
|
+
for (const key of ["opens", "closes"]) {
|
|
52
|
+
if (!single(own(object, declared[key]), ["datetime"])) {
|
|
53
|
+
contract(`${at}.${key}`, `"${declared[key]}" must be a datetime field of ${name}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (declared.opens === declared.closes) {
|
|
57
|
+
contract(`${at}.closes`, "A checklist opens and closes at two fields");
|
|
58
|
+
}
|
|
59
|
+
// The states in which it applies.
|
|
60
|
+
const states = object.states;
|
|
61
|
+
if (!states) {
|
|
62
|
+
contract(`${at}.live`, `${name} must declare states: a checklist applies in some of them`);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const field = own(object, states.field);
|
|
66
|
+
const values = new Set((field?.options ?? []).map((o) => o.value));
|
|
67
|
+
for (const state of declared.live) {
|
|
68
|
+
if (!values.has(state))
|
|
69
|
+
contract(`${at}.live`, `"${state}" is not a state of ${name}`);
|
|
70
|
+
}
|
|
71
|
+
if (new Set(declared.live).size !== declared.live.length) {
|
|
72
|
+
contract(`${at}.live`, "List each state once");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|