@composable-os/cli 0.1.0-beta.11 → 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/{accounts-UHYLCLEY.js → accounts-GOCNY6WI.js} +17 -13
- package/dist/app-RPRZMLU5.js +43 -0
- package/dist/app-upload-YJVEKZC6.js +198 -0
- package/dist/{blocks-5IFU25J6.js → blocks-DE4RRWPJ.js} +207 -25
- package/dist/{chunk-XIDLW3EP.js → chunk-2B6YUYZV.js} +23499 -11766
- package/dist/{run-7P4RQALH.js → chunk-2CCHB37H.js} +9 -146
- package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
- package/dist/{chunk-DHS2CV2M.js → chunk-5D7BDF4Y.js} +15 -13
- package/dist/{chunk-ZAWES2UD.js → chunk-6CM3WZG5.js} +13 -2483
- package/dist/{chunk-7D4GKZOX.js → chunk-CIBJGB5H.js} +422 -75
- package/dist/chunk-EPDTPGZJ.js +330 -0
- package/dist/{chunk-LAAL4YGR.js → chunk-HAYF4G5V.js} +66 -23
- package/dist/chunk-HCG6T53D.js +61904 -0
- package/dist/{chunk-K34UKWEI.js → chunk-JX4IFWNT.js} +64 -32
- package/dist/{chunk-6XTU2MTP.js → chunk-KFHKNXGH.js} +632 -418
- package/dist/chunk-KMFMD52Z.js +13276 -0
- package/dist/{chunk-E4WCYTCT.js → chunk-LX2TTLVY.js} +174 -55
- package/dist/{chunk-GYTEW66E.js → chunk-O3R4FS2J.js} +1 -1
- package/dist/{chunk-E64SG24J.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/{chunk-MBIKVRAC.js → chunk-QJZGYJVV.js} +823 -44
- package/dist/{chunk-PDD2ETVF.js → chunk-QQ3YSL5F.js} +172 -16
- package/dist/chunk-RGKJKC5T.js +876 -0
- package/dist/{chunk-YFTLIEWU.js → chunk-RSEWEFAV.js} +12 -2
- package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
- package/dist/{chunk-LO6WGU5Y.js → chunk-U72NEGCT.js} +8089 -3464
- package/dist/{chunk-P6UWZ6QQ.js → chunk-Z4IKF23A.js} +11 -7
- package/dist/{chunk-2IVEVPMY.js → chunk-Z7OVQ6BC.js} +105 -61
- package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
- package/dist/{cli-5UNY5G5L.js → cli-OKQHHSOE.js} +17 -25
- package/dist/{cli-UYZMVQMR.js → cli-VYSD2S4Z.js} +227 -81
- package/dist/cli.js +5 -5
- package/dist/{client-repo-SE4EKG6W.js → client-repo-NNUCHQ2Y.js} +7 -5
- package/dist/create.js +5 -5
- package/dist/{fields-FTWWMD7N.js → fields-GTHE6TTS.js} +27 -3
- package/dist/gateway-DPPEQZT4.js +25 -0
- package/dist/grants-6JY4XZO7.js +27 -0
- package/dist/invoke-MRONRZ5Q.js +33 -0
- package/dist/moves-UAUCMWL5.js +36 -0
- package/dist/{order-U4KZLLSJ.js → order-RKLGT74L.js} +2 -2
- package/dist/{person-UHLVBVLR.js → person-YOZTFV4Q.js} +11 -10
- package/dist/plan-on-sale-H4F26YIN.js +26 -0
- package/dist/platform/migrations/0730_practitioners.sql +79 -0
- package/dist/platform/migrations/0750_routine_mail.sql +98 -0
- package/dist/platform/migrations/0770_clear_fixed_role_grants.sql +64 -0
- package/dist/platform/migrations/0810_recurrence_exceptions.sql +66 -0
- package/dist/platform/migrations/0811_staff_time.sql +109 -0
- package/dist/platform/migrations/0812_staff_offers.sql +112 -0
- package/dist/platform/migrations/0813_pay_periods.sql +241 -0
- package/dist/platform/migrations/0814_staff_feed.sql +47 -0
- package/dist/platform/migrations/0815_checklists.sql +237 -0
- package/dist/platform/migrations/0816_checklist_schedules.sql +121 -0
- package/dist/platform/migrations/0817_checklist_day_window.sql +35 -0
- package/dist/platform/migrations/0850_agreements.sql +271 -0
- package/dist/platform/migrations/0851_agreement_acceptances.sql +387 -0
- package/dist/platform/migrations/0853_agreement_enforcement.sql +58 -0
- package/dist/platform/migrations/0854_agreement_copy.sql +149 -0
- package/dist/platform/migrations/0855_agreement_retention.sql +279 -0
- package/dist/platform/migrations/0856_subscription_cooling_off.sql +159 -0
- package/dist/platform/migrations/0857_agreement_copy_guardian.sql +337 -0
- package/dist/platform/migrations/0858_agreement_desk.sql +175 -0
- package/dist/platform/migrations/0910_routine_messages.sql +99 -0
- package/dist/platform/migrations/0911_texts.sql +60 -0
- package/dist/platform/migrations/0913_contact_consent.sql +93 -0
- package/dist/platform/migrations/0916_contact_mailbox_index.sql +29 -0
- package/dist/platform/migrations/0930_stock_movements.sql +95 -0
- package/dist/platform/migrations/0931_stock_low.sql +25 -0
- package/dist/platform/migrations/0932_order_delivery.sql +78 -0
- package/dist/platform/migrations/0950_order_adjustments.sql +111 -0
- package/dist/platform/migrations/0951_order_price_guards.sql +33 -0
- package/dist/platform/migrations/0952_order_paid_another_way.sql +194 -0
- package/dist/platform/migrations/0953_discount_uses.sql +183 -0
- package/dist/platform/migrations/0955_folded_addresses.sql +92 -0
- package/dist/platform/migrations/0970_published_text.sql +59 -0
- package/dist/platform/migrations/0971_publish_acks.sql +68 -0
- package/dist/platform/migrations/0990_customer_email_change.sql +65 -0
- package/dist/platform/migrations/1010_intake_links.sql +148 -0
- package/dist/platform/migrations/1030_invoices.sql +747 -0
- package/dist/platform/migrations/1031_invoice_orders.sql +327 -0
- package/dist/platform/migrations/1050_inbox_conversations.sql +83 -0
- package/dist/platform/migrations/1090_staff_hours.sql +43 -0
- package/dist/platform/migrations/1091_staff_time_margins.sql +12 -0
- package/dist/platform/migrations/1092_client_guard.sql +26 -0
- package/dist/platform/migrations/1095_thing_time.sql +70 -0
- package/dist/platform/migrations/1130_devices.sql +162 -0
- package/dist/platform/migrations/1135_person_codes.sql +88 -0
- package/dist/platform/migrations/1150_finance_periods.sql +316 -0
- package/dist/platform/migrations/1151_payouts.sql +202 -0
- package/dist/platform/migrations/1153_finance_money_dates.sql +18 -0
- package/dist/platform/migrations/1170_journeys.sql +318 -0
- package/dist/platform/migrations/1171_person_birthday.sql +52 -0
- package/dist/platform/migrations/1175_person_signals.sql +29 -0
- package/dist/platform/migrations/1190_restricted_values.sql +25 -0
- package/dist/platform/migrations/1230_note_levels.sql +113 -0
- package/dist/platform/migrations/1231_person_carers.sql +33 -0
- package/dist/platform/migrations/1232_note_kinds.sql +122 -0
- package/dist/platform/migrations/1270_time_entries.sql +145 -0
- package/dist/platform/migrations/1271_leave.sql +249 -0
- package/dist/platform/migrations/1273_time_entry_reopened.sql +21 -0
- package/dist/platform/migrations/1330_accounting.sql +260 -0
- package/dist/platform/migrations/1350_customer_feed.sql +24 -0
- package/dist/platform/migrations/1390_locations.sql +77 -0
- package/dist/platform/migrations/1410_outside_copy.sql +213 -0
- package/dist/platform/migrations/1430_inbox_activities.sql +231 -0
- package/dist/platform/migrations/1450_wrong_guesses.sql +23 -0
- package/dist/platform/sdk/acknowledge.ts +100 -0
- package/dist/platform/sdk/agreements.ts +185 -0
- package/dist/platform/sdk/allowance.ts +98 -8
- package/dist/platform/sdk/automation-check.ts +120 -9
- package/dist/platform/sdk/automation.ts +78 -10
- package/dist/platform/sdk/behaviour.ts +26 -6
- package/dist/platform/sdk/calendar-entry.ts +258 -0
- package/dist/platform/sdk/capacity.ts +1 -2
- package/dist/platform/sdk/checklists.ts +118 -0
- package/dist/platform/sdk/contract.ts +489 -27
- package/dist/platform/sdk/discount.ts +408 -0
- package/dist/platform/sdk/document.ts +4 -2
- package/dist/platform/sdk/field-types.ts +5 -0
- package/dist/platform/sdk/formula/compile.ts +10 -0
- package/dist/platform/sdk/index.ts +17 -0
- package/dist/platform/sdk/intake.ts +380 -0
- package/dist/platform/sdk/journey-signals.ts +215 -0
- package/dist/platform/sdk/manifest.ts +1236 -65
- package/dist/platform/sdk/mine.ts +161 -0
- package/dist/platform/sdk/occupies.ts +192 -0
- package/dist/platform/sdk/questions.ts +681 -0
- package/dist/platform/sdk/recurring.ts +90 -9
- package/dist/platform/sdk/restricted-fields.ts +129 -0
- package/dist/platform/sdk/rich-text.ts +112 -0
- package/dist/platform/sdk/routine-mail.ts +1272 -0
- package/dist/platform/sdk/runtime.ts +25 -12
- package/dist/platform/sdk/screens.ts +91 -0
- package/dist/platform/sdk/sellable.ts +344 -0
- package/dist/platform/sdk/slug.ts +7 -2
- package/dist/platform/sdk/staffed.ts +474 -0
- package/dist/platform/sdk/states.ts +68 -26
- package/dist/platform/sdk/stock.ts +332 -0
- package/dist/platform/sdk/team.ts +83 -0
- package/dist/platform/sdk/testing.ts +70 -6
- package/dist/platform/sdk/worked-on.ts +134 -0
- package/dist/{products-2H5DR232.js → products-GCQLSZ3U.js} +2 -2
- package/dist/run-7ID64RA6.js +65 -0
- package/dist/run-FH7OGGTV.js +131 -0
- package/dist/run-OYZIAP6M.js +3363 -0
- package/dist/{run-ZCGFMEZF.js → run-QOFRRSZV.js} +41 -60
- package/dist/{run-PO3W5BFA.js → run-TJAEWR5U.js} +21 -51
- package/dist/{src-I3IJ4NKC.js → src-52VERUPK.js} +306 -4
- package/dist/src-PHRELWN5.js +40 -0
- package/dist/{visibility-TVXZ67FD.js → visibility-SZCINPP4.js} +21 -4
- package/package.json +2 -2
- package/dist/chunk-2TWV3SVB.js +0 -349
- package/dist/chunk-2XC5JLBO.js +0 -1931
- package/dist/chunk-324WJXNP.js +0 -320
- package/dist/chunk-6ELZRNUU.js +0 -116
- package/dist/chunk-6WGFA2IV.js +0 -643
- package/dist/chunk-7CQGMVDO.js +0 -63
- package/dist/chunk-7OGCMQXG.js +0 -284
- package/dist/chunk-FJIZGS5Q.js +0 -698
- package/dist/chunk-UB4I2QKR.js +0 -31575
- package/dist/chunk-WHKJGF36.js +0 -2418
- package/dist/chunk-YNUZRTPH.js +0 -182
- package/dist/chunk-ZZFWMVJO.js +0 -704
- package/dist/grants-LOW6TSWD.js +0 -32
- package/dist/invoke-6KVT6WJI.js +0 -41
- package/dist/moves-E2HKYCTK.js +0 -41
- package/dist/plan-on-sale-TJPFCNL7.js +0 -26
- package/dist/src-CRO35DYY.js +0 -46
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
// The `staffed` behaviour (stage 45 step 2, ADR 0621): a record that is a shift, a time someone
|
|
2
|
+
// works. Its declaration, its manifest schema and its contract checks live here; the host's side
|
|
3
|
+
// (the time claim, refused by the database, and the warnings) is packages/core/src/staffing/.
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifest.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A shift (ADR 0621): a time, a kind of work, and at most one staff account working it. The host
|
|
9
|
+
* keeps a **time claim** for every live, covered shift and refuses, in the database, a second
|
|
10
|
+
* shift that overlaps one account's time, for every actor and however many write at once
|
|
11
|
+
* (`conflict`, `rule: "double_booked"`). It answers a write with **warnings** it does not refuse:
|
|
12
|
+
* the person is away, not qualified for the kind, or the shift is left with no one.
|
|
13
|
+
*
|
|
14
|
+
* - `who`: the person. `{ field: "staff" }` is a `user` field of this object (the staff account
|
|
15
|
+
* itself). `{ field: "coach", account: "user" }` is a relation (one record) to another of this
|
|
16
|
+
* extension's objects whose `user` field holds the account (a class's coach profile); a profile
|
|
17
|
+
* with no account covers the shift for members but claims no one's time.
|
|
18
|
+
* - `starts`, `ends`: datetime fields of this object, the shift's own time. Ranges are half-open:
|
|
19
|
+
* 06:00 to 07:00 and 07:00 to 08:00 do not clash.
|
|
20
|
+
* - `zone`: a timezone field (optional), the shift's local zone.
|
|
21
|
+
* - `kind`: a relation (one record) to what qualifications are for (a class type, a duty).
|
|
22
|
+
* - `live`: the states of the object's `states` in which the record is a shift. A record in any
|
|
23
|
+
* other state, or in the Trash, claims nothing.
|
|
24
|
+
* - `place` (optional): a field, or `relation.field`, shown on the roster and in the feed.
|
|
25
|
+
* - `pattern` (optional): the series field that is the shift's regular person (`link` is the
|
|
26
|
+
* series' `recurring.link` on this object, `who` the series field copied onto `who.field`).
|
|
27
|
+
* - `payBefore`, `payAfter` (optional): `kind.field` number paths, minutes counted for pay only
|
|
28
|
+
* (preparation and pack-down); they never enter the time claim.
|
|
29
|
+
* - `claimBefore`, `claimAfter` (optional, ADR 0760): `kind.field` number paths, minutes kept free
|
|
30
|
+
* before and after the shift (a service's buffer). They enter the time claim, never the shift's
|
|
31
|
+
* own times or pay; the kind must be another of this extension's objects, so the host follows a
|
|
32
|
+
* change of its minutes. Classes declare none: two back to back stay allowed.
|
|
33
|
+
* - `account` (optional, ADR 0760): `"required"`: a live shift whose person is a profile holding
|
|
34
|
+
* no account is refused, at write and by the database, so no shift with a person escapes the
|
|
35
|
+
* claim (an appointment). A shift with nobody on it stays allowed (uncovered). Only with
|
|
36
|
+
* `who.account`: a user field always is the account.
|
|
37
|
+
* - `private` (optional, ADR 0761): the record's title may name a client (an appointment). The
|
|
38
|
+
* roster shows the shift as its kind to anyone but its person and those who roster, a clash
|
|
39
|
+
* answer names it by its kind, and it is never offered to others. The feed never shows a title.
|
|
40
|
+
* - `open` (optional, ADRs 0762 and 0763): the shift is booked at free times (an appointment).
|
|
41
|
+
* The host answers the free start times of a kind (`staffing.free`): its providers' open hours,
|
|
42
|
+
* less time off, their claims with margins, taken rooms, closures and the client's own shifts,
|
|
43
|
+
* on the kind's step; and staff writes are warned `outside_hours` and `client_busy`.
|
|
44
|
+
* - `length`: `kind.field`, the minutes a shift of the kind lasts (a service's length).
|
|
45
|
+
* - `step` (optional): `kind.field`, the minutes between start times (15, 30 or 60; 30 when
|
|
46
|
+
* empty), counted from the organisation's local midnight.
|
|
47
|
+
* - `rooms` (optional): `kind.field`, a relation (many) of the kind to the things this object
|
|
48
|
+
* `occupies`, in the order they are offered; empty on a kind record, it needs none.
|
|
49
|
+
* - `client` (optional): a relation field (one record) of this object to a Person: one client's
|
|
50
|
+
* live shifts of this object do not overlap.
|
|
51
|
+
* - `closedBy` (optional): another of this extension's objects whose records are date ranges
|
|
52
|
+
* (`from`, `until`: date fields): nothing is free on their dates.
|
|
53
|
+
* - `customer` (optional): `true`: a create or move by a customer or the public must be on a
|
|
54
|
+
* free time, by every door, in the batch that writes it.
|
|
55
|
+
* - `evidence` (optional): what shows a shift was worked, beside its pay line (ADR 0627): another
|
|
56
|
+
* object of this extension whose records name the shift (`link`, a relation to this object) and
|
|
57
|
+
* the staff account that marked each (`by`, a user field): a class's bookings, ticked by whoever
|
|
58
|
+
* took the list. The host reads only that the list was taken, and by whom.
|
|
59
|
+
* - `timesFrom` (optional, ADR 0751): a relation (one record, required) to another of this
|
|
60
|
+
* extension's objects whose time this shift is: a crew member's place on a visit. The host
|
|
61
|
+
* copies the record's `starts`, `ends`, `zone` (when declared) and `kind` fields, which that
|
|
62
|
+
* object has under the same names, onto the shift at create, when it is pointed elsewhere, and
|
|
63
|
+
* whenever the record changes them, in the same statement (triggers the reconciler builds), so
|
|
64
|
+
* every place moves with its visit and the time claim is checked for each: a move that would put
|
|
65
|
+
* one person on two overlapping shifts fails whole, naming them. The shift's own time fields are
|
|
66
|
+
* then read-only, written by the host alone. Not with a series making the shift (`pattern`).
|
|
67
|
+
*
|
|
68
|
+
* Only shipped packs and the org's own extensions declare it: who works when feeds pay.
|
|
69
|
+
*/
|
|
70
|
+
export interface StaffedSpec {
|
|
71
|
+
who: { field: string; account?: string };
|
|
72
|
+
starts: string;
|
|
73
|
+
ends: string;
|
|
74
|
+
zone?: string;
|
|
75
|
+
kind: string;
|
|
76
|
+
live: readonly string[];
|
|
77
|
+
place?: string;
|
|
78
|
+
pattern?: { link: string; who: string };
|
|
79
|
+
payBefore?: { field: string };
|
|
80
|
+
payAfter?: { field: string };
|
|
81
|
+
claimBefore?: { field: string };
|
|
82
|
+
claimAfter?: { field: string };
|
|
83
|
+
account?: "required";
|
|
84
|
+
private?: boolean;
|
|
85
|
+
open?: StaffedOpenSpec;
|
|
86
|
+
evidence?: { object: string; link: string; by: string };
|
|
87
|
+
timesFrom?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** A shift booked at free times (ADRs 0762 and 0763): see `StaffedSpec.open`. */
|
|
91
|
+
export interface StaffedOpenSpec {
|
|
92
|
+
length: { field: string };
|
|
93
|
+
step?: { field: string };
|
|
94
|
+
rooms?: { field: string };
|
|
95
|
+
client?: string;
|
|
96
|
+
closedBy?: { object: string; from: string; until: string };
|
|
97
|
+
customer?: true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const fieldName = z.string().max(40);
|
|
101
|
+
const path = z.string().max(81);
|
|
102
|
+
|
|
103
|
+
export const staffedManifestSchema = z
|
|
104
|
+
.object({
|
|
105
|
+
who: z.object({ field: fieldName, account: fieldName.optional() }).strict(),
|
|
106
|
+
starts: fieldName,
|
|
107
|
+
ends: fieldName,
|
|
108
|
+
zone: fieldName.optional(),
|
|
109
|
+
kind: fieldName,
|
|
110
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20),
|
|
111
|
+
place: path.optional(),
|
|
112
|
+
pattern: z.object({ link: fieldName, who: fieldName }).strict().optional(),
|
|
113
|
+
payBefore: z.object({ field: path }).strict().optional(),
|
|
114
|
+
payAfter: z.object({ field: path }).strict().optional(),
|
|
115
|
+
claimBefore: z.object({ field: path }).strict().optional(),
|
|
116
|
+
claimAfter: z.object({ field: path }).strict().optional(),
|
|
117
|
+
account: z.literal("required").optional(),
|
|
118
|
+
private: z.boolean().optional(),
|
|
119
|
+
open: z
|
|
120
|
+
.object({
|
|
121
|
+
length: z.object({ field: path }).strict(),
|
|
122
|
+
step: z.object({ field: path }).strict().optional(),
|
|
123
|
+
rooms: z.object({ field: path }).strict().optional(),
|
|
124
|
+
client: fieldName.optional(),
|
|
125
|
+
closedBy: z
|
|
126
|
+
.object({ object: fieldName, from: fieldName, until: fieldName })
|
|
127
|
+
.strict()
|
|
128
|
+
.optional(),
|
|
129
|
+
customer: z.literal(true).optional(),
|
|
130
|
+
})
|
|
131
|
+
.strict()
|
|
132
|
+
.optional(),
|
|
133
|
+
evidence: z.object({ object: fieldName, link: fieldName, by: fieldName }).strict().optional(),
|
|
134
|
+
timesFrom: fieldName.optional(),
|
|
135
|
+
})
|
|
136
|
+
.strict();
|
|
137
|
+
export type StaffedManifest = z.infer<typeof staffedManifestSchema>;
|
|
138
|
+
|
|
139
|
+
/** Reports problems with `objects.<name>.staffed` through `contract`. */
|
|
140
|
+
export function checkObjectStaffed(
|
|
141
|
+
m: ExtensionManifest,
|
|
142
|
+
name: string,
|
|
143
|
+
object: ObjectManifest,
|
|
144
|
+
contract: (path: string, message: string) => void,
|
|
145
|
+
): void {
|
|
146
|
+
const staffed = object.staffed;
|
|
147
|
+
if (!staffed) return;
|
|
148
|
+
const at = `objects.${name}.staffed`;
|
|
149
|
+
const own = (o: ObjectManifest, local: string): FieldManifest | undefined =>
|
|
150
|
+
Object.hasOwn(o.fields, local) ? o.fields[local] : undefined;
|
|
151
|
+
const single = (field: FieldManifest | undefined, types: readonly string[]) =>
|
|
152
|
+
field !== undefined && types.includes(field.type) && !field.many;
|
|
153
|
+
|
|
154
|
+
// The person.
|
|
155
|
+
const who = own(object, staffed.who.field);
|
|
156
|
+
if (staffed.who.account === undefined) {
|
|
157
|
+
if (!single(who, ["user"])) {
|
|
158
|
+
contract(`${at}.who.field`, `"${staffed.who.field}" must be a user field of ${name}`);
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
const target = who?.type === "relation" && !who.many ? who.to : undefined;
|
|
162
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
163
|
+
const holder = local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
164
|
+
if (!holder || local === name) {
|
|
165
|
+
contract(
|
|
166
|
+
`${at}.who.field`,
|
|
167
|
+
`"${staffed.who.field}" must be a relation field (one record) to another of this extension's objects`,
|
|
168
|
+
);
|
|
169
|
+
} else if (!single(own(holder, staffed.who.account), ["user"])) {
|
|
170
|
+
contract(
|
|
171
|
+
`${at}.who.account`,
|
|
172
|
+
`"${staffed.who.account}" must be a user field of ${target as string}`,
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// The time and the zone.
|
|
177
|
+
for (const key of ["starts", "ends"] as const) {
|
|
178
|
+
if (!single(own(object, staffed[key]), ["datetime"])) {
|
|
179
|
+
contract(`${at}.${key}`, `"${staffed[key]}" must be a datetime field of ${name}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (staffed.starts === staffed.ends) {
|
|
183
|
+
contract(`${at}.ends`, "A shift's start and end are two fields");
|
|
184
|
+
}
|
|
185
|
+
if (staffed.zone !== undefined && !single(own(object, staffed.zone), ["timezone"])) {
|
|
186
|
+
contract(`${at}.zone`, `"${staffed.zone}" must be a timezone field of ${name}`);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// The kind.
|
|
190
|
+
const kind = own(object, staffed.kind);
|
|
191
|
+
if (kind?.type !== "relation" || kind.many) {
|
|
192
|
+
contract(`${at}.kind`, `"${staffed.kind}" must be a relation field (one record) of ${name}`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// The states in which it is a shift.
|
|
196
|
+
const states = object.states;
|
|
197
|
+
if (!states) {
|
|
198
|
+
contract(`${at}.live`, `${name} must declare states: a shift is live in some of them`);
|
|
199
|
+
} else {
|
|
200
|
+
const field = own(object, states.field);
|
|
201
|
+
const values = new Set((field?.options ?? []).map((o) => o.value));
|
|
202
|
+
for (const state of staffed.live) {
|
|
203
|
+
if (!values.has(state)) contract(`${at}.live`, `"${state}" is not a state of ${name}`);
|
|
204
|
+
}
|
|
205
|
+
if (new Set(staffed.live).size !== staffed.live.length) {
|
|
206
|
+
contract(`${at}.live`, "List each state once");
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Where it is.
|
|
211
|
+
if (staffed.place !== undefined) {
|
|
212
|
+
const [first, second, ...rest] = staffed.place.split(".");
|
|
213
|
+
const field = first === undefined ? undefined : own(object, first);
|
|
214
|
+
if (!field || rest.length || (second !== undefined && field.type !== "relation")) {
|
|
215
|
+
contract(
|
|
216
|
+
`${at}.place`,
|
|
217
|
+
`"${staffed.place}" must be a field of ${name}, or a relation of it and a field of what it names`,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// The pattern: a series of this extension making these records, copying its person onto them.
|
|
223
|
+
if (staffed.pattern) {
|
|
224
|
+
const series = Object.entries(m.objects).find(
|
|
225
|
+
([, o]) => o.recurring?.generates === name && o.recurring.link === staffed.pattern?.link,
|
|
226
|
+
);
|
|
227
|
+
if (!series) {
|
|
228
|
+
contract(
|
|
229
|
+
`${at}.pattern.link`,
|
|
230
|
+
`"${staffed.pattern.link}" must be the link of a series of this extension that makes ${name}`,
|
|
231
|
+
);
|
|
232
|
+
} else if (series[1].recurring?.copy?.[staffed.who.field] !== staffed.pattern.who) {
|
|
233
|
+
contract(
|
|
234
|
+
`${at}.pattern.who`,
|
|
235
|
+
`${series[0]} must copy "${staffed.pattern.who}" onto "${staffed.who.field}"`,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Minutes for pay only, read from the kind.
|
|
241
|
+
for (const key of ["payBefore", "payAfter"] as const) {
|
|
242
|
+
const declared = staffed[key];
|
|
243
|
+
if (!declared) continue;
|
|
244
|
+
const [via, field, ...rest] = declared.field.split(".");
|
|
245
|
+
if (via !== staffed.kind || !field || rest.length) {
|
|
246
|
+
contract(
|
|
247
|
+
`${at}.${key}.field`,
|
|
248
|
+
`"${declared.field}" must be ${staffed.kind}.<a number field of what it names>`,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Minutes kept free around the shift, in its claim (ADR 0760): a number field of its kind, which
|
|
254
|
+
// is another of this extension's objects (the host builds triggers on its table to follow it).
|
|
255
|
+
const kindTarget = kind?.type === "relation" && !kind.many ? kind.to : undefined;
|
|
256
|
+
const kindLocal = kindTarget?.startsWith(`${m.id}.`)
|
|
257
|
+
? kindTarget.slice(m.id.length + 1)
|
|
258
|
+
: undefined;
|
|
259
|
+
const kindObject =
|
|
260
|
+
kindLocal && kindLocal !== name && Object.hasOwn(m.objects, kindLocal)
|
|
261
|
+
? m.objects[kindLocal]
|
|
262
|
+
: undefined;
|
|
263
|
+
for (const key of ["claimBefore", "claimAfter"] as const) {
|
|
264
|
+
const declared = staffed[key];
|
|
265
|
+
if (!declared) continue;
|
|
266
|
+
const [via, field, ...rest] = declared.field.split(".");
|
|
267
|
+
if (via !== staffed.kind || !field || rest.length) {
|
|
268
|
+
contract(
|
|
269
|
+
`${at}.${key}.field`,
|
|
270
|
+
`"${declared.field}" must be ${staffed.kind}.<a number field of what it names>`,
|
|
271
|
+
);
|
|
272
|
+
} else if (!kindObject) {
|
|
273
|
+
contract(
|
|
274
|
+
`${at}.${key}.field`,
|
|
275
|
+
`"${staffed.kind}" must name another of this extension's objects for minutes in the claim`,
|
|
276
|
+
);
|
|
277
|
+
} else if (!single(own(kindObject, field), ["number"])) {
|
|
278
|
+
contract(
|
|
279
|
+
`${at}.${key}.field`,
|
|
280
|
+
`"${field}" must be a number field of ${kindTarget as string}`,
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// An account required: only a profile can hold none.
|
|
286
|
+
if (staffed.account === "required" && staffed.who.account === undefined) {
|
|
287
|
+
contract(
|
|
288
|
+
`${at}.account`,
|
|
289
|
+
`"required" needs who.account: "${staffed.who.field}" is a user field, always an account`,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Booked at free times (ADRs 0762 and 0763): the kind's length, step and rooms, the client, the
|
|
294
|
+
// closures.
|
|
295
|
+
if (staffed.open) {
|
|
296
|
+
const open = staffed.open;
|
|
297
|
+
// A field of the kind (null once a problem with the path is reported).
|
|
298
|
+
const kindField = (key: "length" | "step" | "rooms"): FieldManifest | undefined | null => {
|
|
299
|
+
const declared = open[key];
|
|
300
|
+
if (!declared) return null;
|
|
301
|
+
const [via, field, ...rest] = declared.field.split(".");
|
|
302
|
+
if (via !== staffed.kind || !field || rest.length) {
|
|
303
|
+
contract(
|
|
304
|
+
`${at}.open.${key}.field`,
|
|
305
|
+
`"${declared.field}" must be ${staffed.kind}.<a field of what it names>`,
|
|
306
|
+
);
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
if (!kindObject) {
|
|
310
|
+
contract(
|
|
311
|
+
`${at}.open.${key}.field`,
|
|
312
|
+
`"${staffed.kind}" must name another of this extension's objects for free times`,
|
|
313
|
+
);
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
return own(kindObject, field);
|
|
317
|
+
};
|
|
318
|
+
for (const key of ["length", "step"] as const) {
|
|
319
|
+
const field = kindField(key);
|
|
320
|
+
if (field !== null && !single(field, ["number"])) {
|
|
321
|
+
contract(
|
|
322
|
+
`${at}.open.${key}.field`,
|
|
323
|
+
`"${open[key]?.field}" must be a number field of ${kindTarget as string}`,
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
const rooms = kindField("rooms");
|
|
328
|
+
if (rooms !== null) {
|
|
329
|
+
const thingField = object.occupies ? own(object, object.occupies.thing) : undefined;
|
|
330
|
+
if (!thingField) {
|
|
331
|
+
contract(`${at}.open.rooms`, `${name} must declare occupies for the rooms it is booked in`);
|
|
332
|
+
} else if (rooms?.type !== "relation" || !rooms.many || rooms.to !== thingField.to) {
|
|
333
|
+
contract(
|
|
334
|
+
`${at}.open.rooms.field`,
|
|
335
|
+
`"${open.rooms?.field}" must be a relation field (many) of ${kindTarget as string} to ${thingField.to as string}`,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (open.client !== undefined) {
|
|
340
|
+
const client = own(object, open.client);
|
|
341
|
+
if (client?.type !== "relation" || client.many || client.to !== "person") {
|
|
342
|
+
contract(
|
|
343
|
+
`${at}.open.client`,
|
|
344
|
+
`"${open.client}" must be a relation field (one record) of ${name} to person`,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (open.closedBy) {
|
|
349
|
+
const c = open.closedBy;
|
|
350
|
+
const closure =
|
|
351
|
+
c.object !== name && Object.hasOwn(m.objects, c.object) ? m.objects[c.object] : undefined;
|
|
352
|
+
if (!closure) {
|
|
353
|
+
contract(
|
|
354
|
+
`${at}.open.closedBy.object`,
|
|
355
|
+
`"${c.object}" must be another object of this extension`,
|
|
356
|
+
);
|
|
357
|
+
} else {
|
|
358
|
+
for (const key of ["from", "until"] as const) {
|
|
359
|
+
if (!single(own(closure, c[key]), ["date"])) {
|
|
360
|
+
contract(
|
|
361
|
+
`${at}.open.closedBy.${key}`,
|
|
362
|
+
`"${c[key]}" must be a date field of ${c.object}`,
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// The evidence a shift was worked: another object of this extension naming it, and who marked.
|
|
371
|
+
if (staffed.evidence) {
|
|
372
|
+
const { object: other, link, by } = staffed.evidence;
|
|
373
|
+
const evidence =
|
|
374
|
+
other !== name && Object.hasOwn(m.objects, other) ? m.objects[other] : undefined;
|
|
375
|
+
const linkField = evidence ? own(evidence, link) : undefined;
|
|
376
|
+
if (!evidence) {
|
|
377
|
+
contract(`${at}.evidence.object`, `"${other}" must be another object of this extension`);
|
|
378
|
+
} else if (
|
|
379
|
+
linkField?.type !== "relation" ||
|
|
380
|
+
linkField.many ||
|
|
381
|
+
linkField.to !== `${m.id}.${name}`
|
|
382
|
+
) {
|
|
383
|
+
contract(
|
|
384
|
+
`${at}.evidence.link`,
|
|
385
|
+
`"${link}" must be a relation field (one record) of ${other} to ${m.id}.${name}`,
|
|
386
|
+
);
|
|
387
|
+
} else if (!single(own(evidence, by), ["user"])) {
|
|
388
|
+
contract(`${at}.evidence.by`, `"${by}" must be a user field of ${other}`);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Times that follow another record (ADR 0751): copied by the host from what a relation names.
|
|
393
|
+
if (staffed.timesFrom !== undefined) checkTimesFrom(m, name, object, staffed, contract);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* `staffed.timesFrom` (ADR 0751): a required relation (one record) to another of this extension's
|
|
398
|
+
* objects that has the shift's time fields under the same names and types (its kind a relation to
|
|
399
|
+
* the same object); the shift's own copies are read-only, and no series makes the shift.
|
|
400
|
+
*/
|
|
401
|
+
function checkTimesFrom(
|
|
402
|
+
m: ExtensionManifest,
|
|
403
|
+
name: string,
|
|
404
|
+
object: ObjectManifest,
|
|
405
|
+
staffed: StaffedManifest,
|
|
406
|
+
contract: (path: string, message: string) => void,
|
|
407
|
+
): void {
|
|
408
|
+
const at = `objects.${name}.staffed.timesFrom`;
|
|
409
|
+
const local = staffed.timesFrom as string;
|
|
410
|
+
const own = (o: ObjectManifest, f: string): FieldManifest | undefined =>
|
|
411
|
+
Object.hasOwn(o.fields, f) ? o.fields[f] : undefined;
|
|
412
|
+
const link = own(object, local);
|
|
413
|
+
const target = link?.type === "relation" && !link.many ? link.to : undefined;
|
|
414
|
+
const parentName = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
415
|
+
const parent =
|
|
416
|
+
parentName && parentName !== name && Object.hasOwn(m.objects, parentName)
|
|
417
|
+
? m.objects[parentName]
|
|
418
|
+
: undefined;
|
|
419
|
+
if (!parent) {
|
|
420
|
+
contract(
|
|
421
|
+
at,
|
|
422
|
+
`"${local}" must be a relation field (one record) of ${name} to another of this extension's objects`,
|
|
423
|
+
);
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (!link?.required) {
|
|
427
|
+
contract(at, `"${local}" must be required: a shift whose times follow a record names one`);
|
|
428
|
+
}
|
|
429
|
+
if (local === staffed.who.field || local === staffed.kind) {
|
|
430
|
+
contract(at, `"${local}" is the shift's person or kind, not the record its times follow`);
|
|
431
|
+
}
|
|
432
|
+
const followed: [string, string][] = [
|
|
433
|
+
[staffed.starts, "datetime"],
|
|
434
|
+
[staffed.ends, "datetime"],
|
|
435
|
+
...(staffed.zone !== undefined ? ([[staffed.zone, "timezone"]] as [string, string][]) : []),
|
|
436
|
+
[staffed.kind, "relation"],
|
|
437
|
+
];
|
|
438
|
+
for (const [field, type] of followed) {
|
|
439
|
+
const mine = own(object, field);
|
|
440
|
+
const theirs = own(parent, field);
|
|
441
|
+
if (
|
|
442
|
+
!theirs ||
|
|
443
|
+
theirs.type !== type ||
|
|
444
|
+
theirs.many ||
|
|
445
|
+
(type === "relation" && theirs.to !== mine?.to)
|
|
446
|
+
) {
|
|
447
|
+
contract(
|
|
448
|
+
at,
|
|
449
|
+
`${target as string} must have "${field}" as ${name} has it (${type === "relation" ? `a relation to ${mine?.to ?? "the same object"}` : `a ${type} field`}): the host copies it from there`,
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
if (mine && !mine.readOnly) {
|
|
453
|
+
contract(
|
|
454
|
+
`objects.${name}.fields.${field}.readOnly`,
|
|
455
|
+
`"${field}" must be readOnly: the host copies it from ${local}, nobody edits it`,
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
// One step only (the review of PR #419): the host reads the shifts that follow a record before it
|
|
460
|
+
// moves, not theirs in turn, so a record whose own times follow another is not followed.
|
|
461
|
+
if (parent.staffed?.timesFrom !== undefined) {
|
|
462
|
+
contract(
|
|
463
|
+
at,
|
|
464
|
+
`${target as string}'s own times follow another record: a shift's times follow a record whose times are its own`,
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
const series = Object.values(m.objects).some((o) => o.recurring?.generates === name);
|
|
468
|
+
if (staffed.pattern || series) {
|
|
469
|
+
contract(
|
|
470
|
+
at,
|
|
471
|
+
`${name} is made by a series, which sets its times: its times cannot follow ${local}`,
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
@@ -75,6 +75,11 @@ export interface TimedMove {
|
|
|
75
75
|
* relation) is in one of these states: a class whose attendance was taken has someone ticked.
|
|
76
76
|
*/
|
|
77
77
|
ifAnyIn?: readonly string[];
|
|
78
|
+
/**
|
|
79
|
+
* Only while each of these fields of the record has a value (stage 49, ADR 0764): an appointment
|
|
80
|
+
* whose coach left is never marked attended for a session nobody gave.
|
|
81
|
+
*/
|
|
82
|
+
ifSet?: readonly string[];
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
/**
|
|
@@ -144,6 +149,12 @@ export interface StatesSpec {
|
|
|
144
149
|
* one, staff included (no booking into a class that was cancelled or is over).
|
|
145
150
|
*/
|
|
146
151
|
closed?: string | readonly string[];
|
|
152
|
+
/**
|
|
153
|
+
* Fields every create must give a value (stage 49, ADR 0764), whoever makes it, the host
|
|
154
|
+
* included: an appointment is made for a client. Unlike `required`, the field may be emptied
|
|
155
|
+
* later (erasing the Person keeps the record for the business's books, ADR 0320).
|
|
156
|
+
*/
|
|
157
|
+
requires?: readonly string[];
|
|
147
158
|
};
|
|
148
159
|
/**
|
|
149
160
|
* Moves a caller asks for by name, resolved by the host (ADR 0503): writing the name (`cancel`)
|
|
@@ -158,7 +169,10 @@ export interface StatesSpec {
|
|
|
158
169
|
* state named in `when`, the host moves every live record of this object pointing at it, and in
|
|
159
170
|
* one of `from`, to the state `when` gives, in the same batch, as the host (a class cancelled
|
|
160
171
|
* moves its bookings to `cancelled_by_us`: their places released, their uses given back). Each
|
|
161
|
-
* target needs a `host` move from each of `from`.
|
|
172
|
+
* target needs a `host` move from each of `from`. The parent is another of this extension's
|
|
173
|
+
* objects, or one of an extension this one `requires`, named in full (`ticketing.event`); a
|
|
174
|
+
* parent others draw places from as a pool is followed only by an object that draws none
|
|
175
|
+
* (ADR 0841).
|
|
162
176
|
*/
|
|
163
177
|
follows?: {
|
|
164
178
|
relation: string;
|
|
@@ -225,6 +239,7 @@ export const statesManifestSchema = z.object({
|
|
|
225
239
|
window: moveWindow.optional(),
|
|
226
240
|
staffOnly: staffOnlyPaths.optional(),
|
|
227
241
|
closed: staffOnlyPaths.optional(),
|
|
242
|
+
requires: z.array(fieldName).min(1).max(20).optional(),
|
|
228
243
|
})
|
|
229
244
|
.strict()
|
|
230
245
|
.optional(),
|
|
@@ -251,6 +266,7 @@ export const statesManifestSchema = z.object({
|
|
|
251
266
|
at: fieldPath,
|
|
252
267
|
minutesAfter: z.number().int().min(0).max(10_080).optional(),
|
|
253
268
|
ifAnyIn: z.array(stateValue).min(1).max(20).optional(),
|
|
269
|
+
ifSet: z.array(fieldName).min(1).max(5).optional(),
|
|
254
270
|
})
|
|
255
271
|
.strict(),
|
|
256
272
|
)
|
|
@@ -409,40 +425,63 @@ export function checkObjectStates(
|
|
|
409
425
|
for (const p of staffOnlyPathsOf(states.create.closed)) {
|
|
410
426
|
checkPath(p, `${sp}.create.closed`, "boolean");
|
|
411
427
|
}
|
|
428
|
+
for (const required of states.create.requires ?? []) {
|
|
429
|
+
if (!fieldOf(required)) {
|
|
430
|
+
contract(`${sp}.create.requires`, `"${required}" is not a field of ${name}`);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
412
433
|
}
|
|
413
434
|
if (states.follows) {
|
|
414
435
|
const fp = `${sp}.follows`;
|
|
415
436
|
const f = states.follows;
|
|
416
437
|
const rel = fieldOf(f.relation);
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
438
|
+
const to = rel?.type === "relation" && !rel.many ? rel.to : undefined;
|
|
439
|
+
const own = to?.startsWith(`${m.id}.`) ? to.slice(m.id.length + 1) : undefined;
|
|
440
|
+
const target = own !== undefined && Object.hasOwn(m.objects, own) ? m.objects[own] : undefined;
|
|
441
|
+
// A parent in another extension this one requires (ADR 0841): its states are the host's to
|
|
442
|
+
// check, at install and on every upgrade of either extension (core's checkManifest).
|
|
443
|
+
const otherExt = to && own === undefined && to.includes(".") ? to.split(".")[0] : undefined;
|
|
444
|
+
const required = otherExt !== undefined && (m.requires ?? []).includes(otherExt);
|
|
445
|
+
if (!target?.states && !required) {
|
|
422
446
|
contract(
|
|
423
447
|
`${fp}.relation`,
|
|
424
|
-
`"${f.relation}" must be a relation (one record) of ${name} to another of this extension's objects that declares states`,
|
|
448
|
+
`"${f.relation}" must be a relation (one record) of ${name} to another of this extension's objects that declares states, or to an object of an extension this one requires`,
|
|
425
449
|
);
|
|
426
450
|
} else {
|
|
427
|
-
// A parent whose places other records draw on as a pool
|
|
428
|
-
//
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
451
|
+
// A parent whose places other records draw on as a pool counts claims that are not its
|
|
452
|
+
// own, which the cascade's check at commit cannot read (ADR 0550). A child that draws on
|
|
453
|
+
// it (a member of the pool, or claiming places on the parent or on a member) is refused;
|
|
454
|
+
// one that draws nothing moves no places and may follow it (ADR 0841). A pool is always in
|
|
455
|
+
// the parent's own extension, so a parent in another extension is never drawn on from here.
|
|
456
|
+
if (target && own !== undefined) {
|
|
457
|
+
const localOf = (ref: string | undefined) =>
|
|
458
|
+
ref?.startsWith(`${m.id}.`) ? ref.slice(m.id.length + 1) : ref;
|
|
459
|
+
const poolOf = (other: ObjectManifest | undefined) => {
|
|
460
|
+
const poolField = other?.capacity?.pool;
|
|
461
|
+
return poolField ? localOf(other?.fields[poolField]?.to) : undefined;
|
|
462
|
+
};
|
|
463
|
+
const members = new Set(
|
|
464
|
+
Object.entries(m.objects)
|
|
465
|
+
.filter(([, other]) => poolOf(other) === own)
|
|
466
|
+
.map(([key]) => key),
|
|
438
467
|
);
|
|
468
|
+
const claimsOn = object.claims ? localOf(object.fields[object.claims.on]?.to) : undefined;
|
|
469
|
+
const draws =
|
|
470
|
+
members.has(name) ||
|
|
471
|
+
(claimsOn !== undefined && (claimsOn === own || members.has(claimsOn)));
|
|
472
|
+
if (members.size && draws) {
|
|
473
|
+
contract(
|
|
474
|
+
`${fp}.relation`,
|
|
475
|
+
`${to} is a pool other records draw places from, and ${name} draws places from it: a cascade cannot follow it`,
|
|
476
|
+
);
|
|
477
|
+
}
|
|
439
478
|
}
|
|
440
|
-
const parentStates =
|
|
441
|
-
(target.fields[target.states.field]?.options ?? []).map((o) => o.value)
|
|
442
|
-
|
|
443
|
-
for (const [when,
|
|
444
|
-
if (!parentStates.has(when)) {
|
|
445
|
-
contract(`${fp}.when`, `"${when}" is not a state of ${
|
|
479
|
+
const parentStates = target?.states
|
|
480
|
+
? new Set((target.fields[target.states.field]?.options ?? []).map((o) => o.value))
|
|
481
|
+
: null;
|
|
482
|
+
for (const [when, into] of Object.entries(f.when)) {
|
|
483
|
+
if (parentStates && !parentStates.has(when)) {
|
|
484
|
+
contract(`${fp}.when`, `"${when}" is not a state of ${to ?? f.relation}`);
|
|
446
485
|
}
|
|
447
486
|
for (const from of f.from) {
|
|
448
487
|
if (!isState(from))
|
|
@@ -450,10 +489,10 @@ export function checkObjectStates(
|
|
|
450
489
|
else if (
|
|
451
490
|
!states.moves.some(
|
|
452
491
|
(move) =>
|
|
453
|
-
move.to ===
|
|
492
|
+
move.to === into && move.by.includes("host") && moveOrigins(move).includes(from),
|
|
454
493
|
)
|
|
455
494
|
) {
|
|
456
|
-
contract(`${fp}.when`, `${name} needs a host move from "${from}" to "${
|
|
495
|
+
contract(`${fp}.when`, `${name} needs a host move from "${from}" to "${into}"`);
|
|
457
496
|
}
|
|
458
497
|
}
|
|
459
498
|
}
|
|
@@ -485,6 +524,9 @@ export function checkObjectStates(
|
|
|
485
524
|
`"${rule.at}" must be a datetime field of ${name}, or <relation>.<field> on another of this extension's objects`,
|
|
486
525
|
);
|
|
487
526
|
}
|
|
527
|
+
for (const f of rule.ifSet ?? []) {
|
|
528
|
+
if (!fieldOf(f)) contract(`${tp}.ifSet`, `"${f}" is not a field of ${name}`);
|
|
529
|
+
}
|
|
488
530
|
if (rule.ifAnyIn) {
|
|
489
531
|
if (parts.length !== 2) {
|
|
490
532
|
contract(`${tp}.ifAnyIn`, "ifAnyIn needs at one relation away: the records it compares");
|