@composable-os/cli 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/{accounts-X4CKM3HL.js → accounts-GOCNY6WI.js} +17 -14
- package/dist/app-RPRZMLU5.js +43 -0
- package/dist/app-upload-YJVEKZC6.js +198 -0
- package/dist/{blocks-YWDHEBOK.js → blocks-DE4RRWPJ.js} +207 -25
- package/dist/{chunk-VY64DMQO.js → chunk-2B6YUYZV.js} +23576 -11674
- package/dist/{run-RT2HVWMK.js → chunk-2CCHB37H.js} +9 -146
- package/dist/{chunk-DU6OIFOU.js → chunk-3OGDWKJ3.js} +530 -434
- package/dist/chunk-5D7BDF4Y.js +141 -0
- package/dist/{chunk-WO6D3XP3.js → chunk-6CM3WZG5.js} +13 -2470
- package/dist/chunk-CIBJGB5H.js +962 -0
- package/dist/chunk-EPDTPGZJ.js +330 -0
- package/dist/{chunk-LLULPZAJ.js → chunk-HAYF4G5V.js} +66 -23
- package/dist/chunk-HCG6T53D.js +61904 -0
- package/dist/chunk-JX4IFWNT.js +330 -0
- package/dist/{chunk-A4NTSYWV.js → chunk-KFHKNXGH.js} +786 -386
- 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-LJFLENFC.js → chunk-Q6Y45DY6.js} +25 -2
- package/dist/{chunk-Y7JZFSTQ.js → chunk-QJZGYJVV.js} +823 -44
- package/dist/{chunk-6VXHPKGG.js → chunk-QQ3YSL5F.js} +172 -16
- package/dist/chunk-RGKJKC5T.js +876 -0
- package/dist/{chunk-IFG4FRW5.js → chunk-RSEWEFAV.js} +12 -2
- package/dist/{chunk-2ABSVMGB.js → chunk-SMJZIK2O.js} +1 -1
- package/dist/{chunk-CP6BXI6F.js → chunk-U72NEGCT.js} +8818 -3829
- package/dist/{chunk-WC5LHBBA.js → chunk-Z4IKF23A.js} +11 -7
- package/dist/chunk-Z7OVQ6BC.js +713 -0
- package/dist/{chunk-6UWRT4VM.js → chunk-ZJSFX4RD.js} +175 -3
- package/dist/{cli-2DFENR62.js → cli-OKQHHSOE.js} +17 -23
- package/dist/{cli-YIOVSKOD.js → cli-VYSD2S4Z.js} +231 -82
- package/dist/cli.js +5 -5
- package/dist/{client-repo-PRU3VCQQ.js → client-repo-NNUCHQ2Y.js} +7 -5
- package/dist/create.js +5 -5
- package/dist/{fields-2NC7LSYE.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-PUWD65BC.js → order-RKLGT74L.js} +2 -2
- package/dist/{person-WIQQ7ITU.js → person-YOZTFV4Q.js} +11 -11
- package/dist/plan-on-sale-H4F26YIN.js +26 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -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 +103 -2
- package/dist/platform/sdk/checklists.ts +118 -0
- package/dist/platform/sdk/contract.ts +514 -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 +1313 -66
- 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 +595 -1
- package/dist/platform/sdk/slug.ts +7 -2
- package/dist/platform/sdk/staffed.ts +474 -0
- package/dist/platform/sdk/states.ts +220 -64
- 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-Y7T4TVOL.js → run-QOFRRSZV.js} +41 -60
- package/dist/{run-PZUCSDDL.js → run-TJAEWR5U.js} +21 -51
- package/dist/{src-XTOD7EXW.js → src-52VERUPK.js} +312 -4
- package/dist/src-PHRELWN5.js +40 -0
- package/dist/visibility-SZCINPP4.js +58 -0
- package/package.json +2 -2
- package/dist/chunk-6GDEDOV7.js +0 -157
- package/dist/chunk-6UPUF4ML.js +0 -29998
- package/dist/chunk-7CQGMVDO.js +0 -63
- package/dist/chunk-GYSGVT6R.js +0 -284
- package/dist/chunk-JJHHNV46.js +0 -227
- package/dist/chunk-K6T42YCH.js +0 -704
- package/dist/chunk-M7A6FR2Z.js +0 -2586
- package/dist/chunk-O2UIZHND.js +0 -249
- package/dist/chunk-Q4N55M2Z.js +0 -552
- package/dist/chunk-QGGJ2G6Z.js +0 -349
- package/dist/chunk-R4W5XAUD.js +0 -837
- package/dist/chunk-TQFGGSA4.js +0 -748
- package/dist/chunk-YJJHF65I.js +0 -759
- package/dist/chunk-Z3RMMB6S.js +0 -668
- package/dist/grants-QXMKYMGB.js +0 -32
- package/dist/invoke-I3NNNXVL.js +0 -39
- package/dist/plan-on-sale-NB774CQL.js +0 -26
- package/dist/src-GYS6NBQB.js +0 -44
- package/dist/visibility-DLGHU4YN.js +0 -33
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// A pack role's "mine" reach (stage 39 step 3, ADR 0755): a role reaches an object's records only
|
|
2
|
+
// where a live record of its pack names the holder and leads to them (Jobs' crew: the jobs on
|
|
3
|
+
// which the account has a crew place, from a week before the visit to a week after). Its
|
|
4
|
+
// declaration, its manifest schema and its contract checks live here; what the role reaches
|
|
5
|
+
// through it is the host's (packages/core/src/pack-role-mine.ts).
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import type { ExtensionManifest, FieldManifest, ObjectManifest, RoleManifest } from "./manifest.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* How a role reaches one object's records through the records that name its holder (ADR 0755).
|
|
11
|
+
* Jobs' crew on its jobs: `{ through: "jobs.assignment", who: "staff", path: "visit.job", live:
|
|
12
|
+
* ["booked", "on_the_way", "on_site"], within: { from: "starts", to: "ends", days: 7 } }`.
|
|
13
|
+
*/
|
|
14
|
+
export interface MineSpec {
|
|
15
|
+
/** The object of this extension (`<id>.<object>`) whose records name the holder. */
|
|
16
|
+
through: string;
|
|
17
|
+
/** A `user` field of `through` (one account, `personApproves`) naming the holder. */
|
|
18
|
+
who: string;
|
|
19
|
+
/**
|
|
20
|
+
* The relations (one record each, each `personApproves`) from `through` to the object reached,
|
|
21
|
+
* dot-separated, at most three: `"visit.job"`. Left out: the object reached is `through` itself.
|
|
22
|
+
*/
|
|
23
|
+
path?: string;
|
|
24
|
+
/** The states of `through`'s `states` (its field `personApproves`) in which its record counts; left out: every record. */
|
|
25
|
+
live?: readonly string[];
|
|
26
|
+
/**
|
|
27
|
+
* A window around `through`'s own datetimes (each `personApproves`): its record counts from
|
|
28
|
+
* `days` days before `from` to `days` days after `to` (`from` when left out).
|
|
29
|
+
*/
|
|
30
|
+
within?: { from: string; to?: string; days: number };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const fieldName = z.string().max(40);
|
|
34
|
+
|
|
35
|
+
export const mineManifestSchema = z
|
|
36
|
+
.object({
|
|
37
|
+
through: z.string().max(80),
|
|
38
|
+
who: fieldName,
|
|
39
|
+
path: z.string().max(122).optional(),
|
|
40
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20).optional(),
|
|
41
|
+
within: z
|
|
42
|
+
.object({ from: fieldName, to: fieldName.optional(), days: z.number().int().min(0).max(366) })
|
|
43
|
+
.strict()
|
|
44
|
+
.optional(),
|
|
45
|
+
})
|
|
46
|
+
.strict();
|
|
47
|
+
export type MineManifest = z.infer<typeof mineManifestSchema>;
|
|
48
|
+
|
|
49
|
+
/** The most relations a path walks: a crew place to its visit to its job to its site. */
|
|
50
|
+
export const MINE_PATH_MAX = 3;
|
|
51
|
+
|
|
52
|
+
/** Reports problems with `roles.<name>.mine` through `contract`. */
|
|
53
|
+
export function checkRoleMine(
|
|
54
|
+
m: ExtensionManifest,
|
|
55
|
+
name: string,
|
|
56
|
+
role: RoleManifest,
|
|
57
|
+
contract: (path: string, message: string) => void,
|
|
58
|
+
): void {
|
|
59
|
+
const own = (object: string): ObjectManifest | undefined => {
|
|
60
|
+
const local = object.startsWith(`${m.id}.`) ? object.slice(m.id.length + 1) : null;
|
|
61
|
+
return local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
62
|
+
};
|
|
63
|
+
const fieldOf = (object: ObjectManifest, field: string): FieldManifest | undefined =>
|
|
64
|
+
Object.hasOwn(object.fields, field) ? object.fields[field] : undefined;
|
|
65
|
+
// Changing one of these widens whom the role reaches: a person's choice (ADR 0889's lesson).
|
|
66
|
+
const approved = (field: FieldManifest) => field.personApproves === true;
|
|
67
|
+
const PERSON =
|
|
68
|
+
"must be a field a person approves (personApproves): who reaches whose records is a person's to change";
|
|
69
|
+
for (const [object, spec] of Object.entries(role.mine ?? {})) {
|
|
70
|
+
const at = `roles.${name}.mine.${object}`;
|
|
71
|
+
if (!own(object)) {
|
|
72
|
+
contract(at, `"${object}" is not an object of this extension`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
for (const [kind, limits] of [
|
|
76
|
+
["today", role.today],
|
|
77
|
+
["looksAfter", role.looksAfter],
|
|
78
|
+
] as const) {
|
|
79
|
+
if (limits && Object.hasOwn(limits, object)) {
|
|
80
|
+
contract(at, `${object} is limited by ${kind} already: one limit an object`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const through = own(spec.through);
|
|
84
|
+
if (!through) {
|
|
85
|
+
contract(`${at}.through`, `"${spec.through}" is not an object of this extension`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const who = fieldOf(through, spec.who);
|
|
89
|
+
if (who?.type !== "user" || who.many) {
|
|
90
|
+
contract(`${at}.who`, `"${spec.who}" must be a user field (one account) of ${spec.through}`);
|
|
91
|
+
} else if (!approved(who)) {
|
|
92
|
+
contract(`${at}.who`, `"${spec.who}" ${PERSON}`);
|
|
93
|
+
}
|
|
94
|
+
// The path: one-record relations of this extension's objects, ending at the object reached.
|
|
95
|
+
const steps = spec.path ? spec.path.split(".") : [];
|
|
96
|
+
if (steps.length > MINE_PATH_MAX) {
|
|
97
|
+
contract(`${at}.path`, `A path walks at most ${MINE_PATH_MAX} relations`);
|
|
98
|
+
} else {
|
|
99
|
+
let current: ObjectManifest | undefined = through;
|
|
100
|
+
let currentName = spec.through;
|
|
101
|
+
for (const step of steps) {
|
|
102
|
+
const field: FieldManifest | undefined = current ? fieldOf(current, step) : undefined;
|
|
103
|
+
if (field?.type !== "relation" || field.many || !field.to || !own(field.to)) {
|
|
104
|
+
contract(
|
|
105
|
+
`${at}.path`,
|
|
106
|
+
`"${step}" must be a relation field (one record) of ${currentName} to an object of this extension`,
|
|
107
|
+
);
|
|
108
|
+
current = undefined;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (!approved(field)) contract(`${at}.path`, `"${step}" of ${currentName} ${PERSON}`);
|
|
112
|
+
currentName = field.to;
|
|
113
|
+
current = own(field.to);
|
|
114
|
+
}
|
|
115
|
+
if (current && currentName !== object) {
|
|
116
|
+
contract(
|
|
117
|
+
`${at}.path`,
|
|
118
|
+
spec.path
|
|
119
|
+
? `"${spec.path}" leads to ${currentName}, not ${object}`
|
|
120
|
+
: `Without a path the object reached is ${spec.through} itself: name the relations to ${object}`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (spec.live) {
|
|
125
|
+
const states = through.states;
|
|
126
|
+
const known = new Set(
|
|
127
|
+
states ? (fieldOf(through, states.field)?.options ?? []).map((o) => o.value) : [],
|
|
128
|
+
);
|
|
129
|
+
if (!states) {
|
|
130
|
+
contract(
|
|
131
|
+
`${at}.live`,
|
|
132
|
+
`${spec.through} has no states: leave live out (every record counts)`,
|
|
133
|
+
);
|
|
134
|
+
} else {
|
|
135
|
+
for (const [i, state] of spec.live.entries()) {
|
|
136
|
+
if (!known.has(state)) {
|
|
137
|
+
contract(`${at}.live.${i}`, `"${state}" is not a state of ${spec.through}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// Moving a record back into a live state widens the reach (a cancelled place booked again).
|
|
141
|
+
const field = fieldOf(through, states.field);
|
|
142
|
+
if (field && !approved(field)) {
|
|
143
|
+
contract(`${at}.live`, `"${states.field}" of ${spec.through} ${PERSON}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (spec.within) {
|
|
148
|
+
for (const key of ["from", "to"] as const) {
|
|
149
|
+
const value = spec.within[key];
|
|
150
|
+
if (value === undefined) continue;
|
|
151
|
+
const field = fieldOf(through, value);
|
|
152
|
+
if (field?.type !== "datetime" || field.many) {
|
|
153
|
+
contract(`${at}.within.${key}`, `"${value}" must be a datetime field of ${spec.through}`);
|
|
154
|
+
} else if (!approved(field)) {
|
|
155
|
+
// Moving the times moves the window: a place twenty days out brought into reach.
|
|
156
|
+
contract(`${at}.within.${key}`, `"${value}" ${PERSON}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// The `occupies` behaviour (stage 49 step 2, ADR 0765): a record that takes a thing (a room, a
|
|
2
|
+
// chair, a hall) for its time. Its declaration, its manifest schema and its contract checks live
|
|
3
|
+
// here; the host's side (the claim, refused by the database) is packages/core/src/occupies/.
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifest.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A claim on a thing (ADR 0765): while the record is live it takes the thing its `thing` field
|
|
9
|
+
* names for its time, and the host refuses, in the database, a second live record of any object
|
|
10
|
+
* on the same thing at an overlapping time, for every actor and however many write at once
|
|
11
|
+
* (`conflict`, `rule: "room_taken"`, naming no other record). One occupant at a time: this is not
|
|
12
|
+
* a capacity.
|
|
13
|
+
*
|
|
14
|
+
* - `thing`: a relation field of this object (one record, or many: one claim per thing) to another
|
|
15
|
+
* of this extension's objects.
|
|
16
|
+
* - `starts`, `ends`: required datetime fields of this object. Ranges are half-open: 09:00 to 10:00 and
|
|
17
|
+
* 10:00 to 11:00 do not clash.
|
|
18
|
+
* - `live`: the states of the object's `states` in which the record takes its thing. A record in
|
|
19
|
+
* any other state, or in the Trash, claims nothing.
|
|
20
|
+
* - `before`, `after` (optional): minutes the claim starts earlier and ends later than the record
|
|
21
|
+
* (a gap kept free): a number field of this object, or `relation.field`, a number field of the
|
|
22
|
+
* record a relation of this object names (a service's buffer).
|
|
23
|
+
* - `only` (optional): a boolean field of the thing. Only things with it set are claimed (a room
|
|
24
|
+
* marked "one booking at a time"); without it, every thing named is.
|
|
25
|
+
*
|
|
26
|
+
* Two keys only say how the room calendar (`rooms.week`, `rooms.check`, ADR 0844) shows a claim;
|
|
27
|
+
* the claim itself is the same with or without them:
|
|
28
|
+
*
|
|
29
|
+
* - `provisional` (optional): those of `live` in which the claim is shown as provisional (a hire
|
|
30
|
+
* held before its deposit). A provisional claim refuses a clash as a firm one does.
|
|
31
|
+
* - `title` (optional): what the calendar shows for the record: a field of this object, or
|
|
32
|
+
* `relation.field`, a field of the record a relation of this object names (an appointment's
|
|
33
|
+
* service, never its client). Left out, or empty on a record, the calendar shows the object's
|
|
34
|
+
* label. Never a field that names a person.
|
|
35
|
+
*/
|
|
36
|
+
export interface OccupiesSpec {
|
|
37
|
+
thing: string;
|
|
38
|
+
starts: string;
|
|
39
|
+
ends: string;
|
|
40
|
+
live: readonly string[];
|
|
41
|
+
before?: { field: string };
|
|
42
|
+
after?: { field: string };
|
|
43
|
+
only?: string;
|
|
44
|
+
provisional?: readonly string[];
|
|
45
|
+
title?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Field types a calendar title may be read from: text a staff member typed or chose. */
|
|
49
|
+
const TITLE_TYPES = ["text", "select"] as const;
|
|
50
|
+
|
|
51
|
+
const fieldName = z.string().max(40);
|
|
52
|
+
const path = z.string().max(81);
|
|
53
|
+
|
|
54
|
+
export const occupiesManifestSchema = z
|
|
55
|
+
.object({
|
|
56
|
+
thing: fieldName,
|
|
57
|
+
starts: fieldName,
|
|
58
|
+
ends: fieldName,
|
|
59
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20),
|
|
60
|
+
before: z.object({ field: path }).strict().optional(),
|
|
61
|
+
after: z.object({ field: path }).strict().optional(),
|
|
62
|
+
only: fieldName.optional(),
|
|
63
|
+
provisional: z.array(z.string().min(1).max(100)).min(1).max(20).optional(),
|
|
64
|
+
title: path.optional(),
|
|
65
|
+
})
|
|
66
|
+
.strict();
|
|
67
|
+
export type OccupiesManifest = z.infer<typeof occupiesManifestSchema>;
|
|
68
|
+
|
|
69
|
+
/** Reports problems with `objects.<name>.occupies` through `contract`. */
|
|
70
|
+
export function checkObjectOccupies(
|
|
71
|
+
m: ExtensionManifest,
|
|
72
|
+
name: string,
|
|
73
|
+
object: ObjectManifest,
|
|
74
|
+
contract: (path: string, message: string) => void,
|
|
75
|
+
): void {
|
|
76
|
+
const occupies = object.occupies;
|
|
77
|
+
if (!occupies) return;
|
|
78
|
+
const at = `objects.${name}.occupies`;
|
|
79
|
+
const own = (o: ObjectManifest, local: string): FieldManifest | undefined =>
|
|
80
|
+
Object.hasOwn(o.fields, local) ? o.fields[local] : undefined;
|
|
81
|
+
const single = (field: FieldManifest | undefined, types: readonly string[]) =>
|
|
82
|
+
field !== undefined && types.includes(field.type) && !field.many;
|
|
83
|
+
// Another object of this extension a relation field names (the reconciler builds triggers on
|
|
84
|
+
// its table, so it is this extension's own).
|
|
85
|
+
const named = (field: FieldManifest | undefined) => {
|
|
86
|
+
const target = field?.type === "relation" ? field.to : undefined;
|
|
87
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
88
|
+
return local && local !== name && Object.hasOwn(m.objects, local)
|
|
89
|
+
? (m.objects[local] as ObjectManifest)
|
|
90
|
+
: undefined;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// The thing.
|
|
94
|
+
const thing = named(own(object, occupies.thing));
|
|
95
|
+
if (!thing) {
|
|
96
|
+
contract(
|
|
97
|
+
`${at}.thing`,
|
|
98
|
+
`"${occupies.thing}" must be a relation field of ${name} to another of this extension's objects`,
|
|
99
|
+
);
|
|
100
|
+
} else if (occupies.only !== undefined && !single(own(thing, occupies.only), ["boolean"])) {
|
|
101
|
+
contract(
|
|
102
|
+
`${at}.only`,
|
|
103
|
+
`"${occupies.only}" must be a boolean field of ${own(object, occupies.thing)?.to as string}`,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// The time: required, or a live record with no end would sit in the room claiming nothing.
|
|
108
|
+
for (const key of ["starts", "ends"] as const) {
|
|
109
|
+
const field = own(object, occupies[key]);
|
|
110
|
+
if (!single(field, ["datetime"])) {
|
|
111
|
+
contract(`${at}.${key}`, `"${occupies[key]}" must be a datetime field of ${name}`);
|
|
112
|
+
} else if (!field?.required) {
|
|
113
|
+
contract(
|
|
114
|
+
`${at}.${key}`,
|
|
115
|
+
`"${occupies[key]}" must be required: a record with no time would take its ${occupies.thing} claiming nothing`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (occupies.starts === occupies.ends) {
|
|
120
|
+
contract(`${at}.ends`, "A record's start and end are two fields");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// The states in which it takes its thing.
|
|
124
|
+
const states = object.states;
|
|
125
|
+
if (!states) {
|
|
126
|
+
contract(`${at}.live`, `${name} must declare states: a record takes its thing in some of them`);
|
|
127
|
+
} else {
|
|
128
|
+
const field = own(object, states.field);
|
|
129
|
+
const values = new Set((field?.options ?? []).map((o) => o.value));
|
|
130
|
+
for (const state of occupies.live) {
|
|
131
|
+
if (!values.has(state)) contract(`${at}.live`, `"${state}" is not a state of ${name}`);
|
|
132
|
+
}
|
|
133
|
+
if (new Set(occupies.live).size !== occupies.live.length) {
|
|
134
|
+
contract(`${at}.live`, "List each state once");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// The states shown as provisional: some of the live ones.
|
|
139
|
+
if (occupies.provisional) {
|
|
140
|
+
for (const state of occupies.provisional) {
|
|
141
|
+
if (!occupies.live.includes(state)) {
|
|
142
|
+
contract(
|
|
143
|
+
`${at}.provisional`,
|
|
144
|
+
`"${state}" is not one of live: only a state that takes the ${occupies.thing} is provisional`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (new Set(occupies.provisional).size !== occupies.provisional.length) {
|
|
149
|
+
contract(`${at}.provisional`, "List each state once");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// The calendar's title: a text or choice of this object, or of what one of its relations names
|
|
154
|
+
// (an appointment's service). A relation to a Person or an account is never one: the calendar
|
|
155
|
+
// shows no names.
|
|
156
|
+
if (occupies.title !== undefined) {
|
|
157
|
+
const [first, second, ...rest] = occupies.title.split(".");
|
|
158
|
+
const field = first === undefined ? undefined : own(object, first);
|
|
159
|
+
let ok = false;
|
|
160
|
+
if (!rest.length && second === undefined) ok = single(field, TITLE_TYPES);
|
|
161
|
+
else if (!rest.length && second !== undefined && single(field, ["relation"])) {
|
|
162
|
+
const source = named(field);
|
|
163
|
+
ok = source !== undefined && single(own(source, second), TITLE_TYPES);
|
|
164
|
+
}
|
|
165
|
+
if (!ok) {
|
|
166
|
+
contract(
|
|
167
|
+
`${at}.title`,
|
|
168
|
+
`"${occupies.title}" must be a text or select field of ${name}, or a relation of it (one record, to another of this extension's objects) and a text or select field of what it names`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// The margins: a number field of this object, or of the record one of its relations names.
|
|
174
|
+
for (const key of ["before", "after"] as const) {
|
|
175
|
+
const declared = occupies[key];
|
|
176
|
+
if (!declared) continue;
|
|
177
|
+
const [first, second, ...rest] = declared.field.split(".");
|
|
178
|
+
const field = first === undefined ? undefined : own(object, first);
|
|
179
|
+
let ok = false;
|
|
180
|
+
if (!rest.length && second === undefined) ok = single(field, ["number"]);
|
|
181
|
+
else if (!rest.length && second !== undefined && single(field, ["relation"])) {
|
|
182
|
+
const source = named(field);
|
|
183
|
+
ok = source !== undefined && single(own(source, second), ["number"]);
|
|
184
|
+
}
|
|
185
|
+
if (!ok) {
|
|
186
|
+
contract(
|
|
187
|
+
`${at}.${key}.field`,
|
|
188
|
+
`"${declared.field}" must be a number field of ${name}, or a relation of it (one record, to another of this extension's objects) and a number field of what it names`,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|