@composable-os/sdk 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/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.js +1 -2
- package/dist/checklists.d.ts +41 -0
- package/dist/checklists.js +75 -0
- package/dist/contract.d.ts +495 -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 +944 -56
- package/dist/manifest.js +1036 -60
- 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 +153 -2
- package/dist/sellable.js +188 -0
- 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 +17 -1
- package/dist/states.js +48 -20
- 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 +1 -2
- package/src/checklists.ts +118 -0
- package/src/contract.ts +489 -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 +1236 -65
- 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 +344 -0
- package/src/slug.ts +7 -2
- package/src/staffed.ts +474 -0
- package/src/states.ts +68 -26
- 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
package/src/worked-on.ts
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// The `workedOn` declaration (stage 58 step 1, ADR 0850): a record time can be recorded against (a
|
|
2
|
+
// job). Its manifest schema and contract checks live here; the host's side (the time entries,
|
|
3
|
+
// refused by the database when one person's overlap) is packages/core/src/staffing/time.ts.
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import type { ExtensionManifest, FieldManifest, ObjectManifest } from "./manifest.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Time can be recorded against this record (ADR 0850): a job a tradesperson spends three hours
|
|
9
|
+
* on. A staff member's **time entry** is the one record of time worked; an entry against a shift
|
|
10
|
+
* (a `staffed` record) is against the roster, an entry against a `workedOn` record is against the
|
|
11
|
+
* job, and an entry against neither is other work. The record keeps no hours of its own: its
|
|
12
|
+
* time is the entries against it, read through the host (the same entries pay counts), never a
|
|
13
|
+
* second "time spent" record, and never in a `rec_*` view.
|
|
14
|
+
*
|
|
15
|
+
* - `live`: the states of the object's `states` in which time may be recorded against it. A
|
|
16
|
+
* record in any other state, or in the Trash, takes no new time.
|
|
17
|
+
* - `title`: a field of this object, shown on the entry, the timesheet and the export.
|
|
18
|
+
* - `kind` (optional): a relation (one record) of this object, shown as the export's kind.
|
|
19
|
+
* - `place` (optional): a field, or `relation.field`, shown beside the entry.
|
|
20
|
+
* - `readers`: a permission of this extension's tools: who reads the time recorded against a
|
|
21
|
+
* record (person, date, minutes and state; never a note).
|
|
22
|
+
* - `partOf` (optional), on a `staffed` object only (a scheduled visit to a site): a relation (one
|
|
23
|
+
* record) to another of this extension's objects that declares `workedOn` (the job); time
|
|
24
|
+
* recorded against the visit also counts to it.
|
|
25
|
+
*
|
|
26
|
+
* Only shipped packs and the org's own extensions declare it: time worked feeds pay.
|
|
27
|
+
*/
|
|
28
|
+
export interface WorkedOnSpec {
|
|
29
|
+
live: readonly string[];
|
|
30
|
+
title: string;
|
|
31
|
+
kind?: string;
|
|
32
|
+
place?: string;
|
|
33
|
+
readers: string;
|
|
34
|
+
partOf?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const fieldName = z.string().max(40);
|
|
38
|
+
|
|
39
|
+
export const workedOnManifestSchema = z
|
|
40
|
+
.object({
|
|
41
|
+
live: z.array(z.string().min(1).max(100)).min(1).max(20),
|
|
42
|
+
title: fieldName,
|
|
43
|
+
kind: fieldName.optional(),
|
|
44
|
+
place: z.string().max(81).optional(),
|
|
45
|
+
readers: z.string().max(80),
|
|
46
|
+
partOf: fieldName.optional(),
|
|
47
|
+
})
|
|
48
|
+
.strict();
|
|
49
|
+
export type WorkedOnManifest = z.infer<typeof workedOnManifestSchema>;
|
|
50
|
+
|
|
51
|
+
/** Reports problems with `objects.<name>.workedOn` through `contract`. */
|
|
52
|
+
export function checkObjectWorkedOn(
|
|
53
|
+
m: ExtensionManifest,
|
|
54
|
+
name: string,
|
|
55
|
+
object: ObjectManifest,
|
|
56
|
+
contract: (path: string, message: string) => void,
|
|
57
|
+
): void {
|
|
58
|
+
const declared = object.workedOn;
|
|
59
|
+
if (!declared) return;
|
|
60
|
+
const at = `objects.${name}.workedOn`;
|
|
61
|
+
const own = (o: ObjectManifest, local: string): FieldManifest | undefined =>
|
|
62
|
+
Object.hasOwn(o.fields, local) ? o.fields[local] : undefined;
|
|
63
|
+
|
|
64
|
+
// The states in which time may be recorded against it.
|
|
65
|
+
const states = object.states;
|
|
66
|
+
if (!states) {
|
|
67
|
+
contract(`${at}.live`, `${name} must declare states: time is recorded in some of them`);
|
|
68
|
+
} else {
|
|
69
|
+
const field = own(object, states.field);
|
|
70
|
+
const values = new Set((field?.options ?? []).map((o) => o.value));
|
|
71
|
+
for (const state of declared.live) {
|
|
72
|
+
if (!values.has(state)) contract(`${at}.live`, `"${state}" is not a state of ${name}`);
|
|
73
|
+
}
|
|
74
|
+
if (new Set(declared.live).size !== declared.live.length) {
|
|
75
|
+
contract(`${at}.live`, "List each state once");
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// What it is called, of what kind, and where.
|
|
80
|
+
const title = own(object, declared.title);
|
|
81
|
+
if (!title || title.many) {
|
|
82
|
+
contract(`${at}.title`, `"${declared.title}" must be a field (one value) of ${name}`);
|
|
83
|
+
}
|
|
84
|
+
if (declared.kind !== undefined) {
|
|
85
|
+
const kind = own(object, declared.kind);
|
|
86
|
+
if (kind?.type !== "relation" || kind.many) {
|
|
87
|
+
contract(`${at}.kind`, `"${declared.kind}" must be a relation field (one record) of ${name}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (declared.place !== undefined) {
|
|
91
|
+
const [first, second, ...rest] = declared.place.split(".");
|
|
92
|
+
const field = first === undefined ? undefined : own(object, first);
|
|
93
|
+
if (!field || rest.length || (second !== undefined && field.type !== "relation")) {
|
|
94
|
+
contract(
|
|
95
|
+
`${at}.place`,
|
|
96
|
+
`"${declared.place}" must be a field of ${name}, or a relation of it and a field of what it names`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Who reads its time: a permission this extension's tools declare.
|
|
102
|
+
const permissions = new Set(
|
|
103
|
+
Object.values(m.tools).flatMap((t) =>
|
|
104
|
+
t.permission === undefined
|
|
105
|
+
? []
|
|
106
|
+
: typeof t.permission === "string"
|
|
107
|
+
? [t.permission]
|
|
108
|
+
: t.permission,
|
|
109
|
+
),
|
|
110
|
+
);
|
|
111
|
+
if (!declared.readers.startsWith(`${m.id}:`) || !permissions.has(declared.readers)) {
|
|
112
|
+
contract(
|
|
113
|
+
`${at}.readers`,
|
|
114
|
+
`"${declared.readers}" must be a permission of this extension's tools (${m.id}:<word>)`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// What a staffed visit's time also counts to.
|
|
119
|
+
if (declared.partOf !== undefined) {
|
|
120
|
+
if (!object.staffed) {
|
|
121
|
+
contract(`${at}.partOf`, `Only a shift (an object that declares staffed) is part of a job`);
|
|
122
|
+
}
|
|
123
|
+
const via = own(object, declared.partOf);
|
|
124
|
+
const target = via?.type === "relation" && !via.many ? via.to : undefined;
|
|
125
|
+
const local = target?.startsWith(`${m.id}.`) ? target.slice(m.id.length + 1) : undefined;
|
|
126
|
+
const job = local && Object.hasOwn(m.objects, local) ? m.objects[local] : undefined;
|
|
127
|
+
if (!job || local === name || !job.workedOn || job.workedOn.partOf !== undefined) {
|
|
128
|
+
contract(
|
|
129
|
+
`${at}.partOf`,
|
|
130
|
+
`"${declared.partOf}" must be a relation field (one record) to another of this extension's objects that declares workedOn`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|