@quad-education/sdk 0.1.3 → 0.2.0
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/README.md +2 -0
- package/dist/contract-tests/apps.d.ts +105 -0
- package/dist/contract-tests/apps.js +167 -0
- package/dist/contract-tests/harness.d.ts +11 -0
- package/dist/contract-tests/harness.js +40 -0
- package/dist/contract-tests/helpers.d.ts +5 -0
- package/dist/contract-tests/helpers.js +25 -0
- package/dist/contract-tests/index.d.ts +4 -2
- package/dist/contract-tests/index.js +3 -1
- package/dist/contract-tests/standalone-apps.d.ts +183 -0
- package/dist/contract-tests/standalone-apps.js +178 -0
- package/dist/contract-tests/standalone.d.ts +2 -0
- package/dist/contract-tests/standalone.js +709 -0
- package/dist/contract-tests/suite.d.ts +10 -3
- package/dist/contract-tests/suite.js +536 -44
- package/dist/src/client/connect.d.ts +13 -3
- package/dist/src/client/connect.js +21 -3
- package/dist/src/client/handshake-client.d.ts +2 -0
- package/dist/src/client/handshake-client.js +2 -0
- package/dist/src/client/http-transport.d.ts +18 -0
- package/dist/src/client/http-transport.js +76 -0
- package/dist/src/client/live.d.ts +39 -0
- package/dist/src/client/live.js +122 -0
- package/dist/src/contract/errors.d.ts +1 -1
- package/dist/src/contract/principals.d.ts +30 -0
- package/dist/src/contract/principals.js +12 -0
- package/dist/src/contract/recipients.d.ts +8 -2
- package/dist/src/contract/types.d.ts +18 -2
- package/dist/src/contract/types.js +1 -1
- package/dist/src/engine/audit.d.ts +2 -2
- package/dist/src/engine/audit.js +8 -6
- package/dist/src/engine/db-indexes.js +6 -1
- package/dist/src/engine/engine.d.ts +60 -22
- package/dist/src/engine/engine.js +281 -162
- package/dist/src/engine/host.d.ts +2 -2
- package/dist/src/engine/host.js +1 -1
- package/dist/src/engine/in-process.d.ts +2 -2
- package/dist/src/engine/index.d.ts +3 -1
- package/dist/src/engine/index.js +1 -0
- package/dist/src/engine/memory-store.d.ts +32 -0
- package/dist/src/engine/memory-store.js +123 -0
- package/dist/src/engine/runner.d.ts +2 -2
- package/dist/src/engine/runner.js +31 -26
- package/dist/src/engine/state.d.ts +21 -15
- package/dist/src/engine/state.js +31 -3
- package/dist/src/engine/store.d.ts +48 -0
- package/dist/src/engine/store.js +1 -0
- package/dist/src/engine/tasks.d.ts +4 -6
- package/dist/src/engine/tasks.js +27 -24
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/jobs/define.d.ts +2 -2
- package/dist/src/platform-types.d.ts +2 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -95,6 +95,8 @@ The types allow `orderBy` and ranges only on indexed fields, so most mistakes ar
|
|
|
95
95
|
|
|
96
96
|
## Versions
|
|
97
97
|
|
|
98
|
+
- **0.2.0 (V2c).** For standalone apps that go live, where there is no school. Two new principals beside the school's users: a Quad **account**, holding the app's own roles, and a **guest**, who isn't signed in and is known by a device id. `auth.me()` returns `{ kind: 'account', account, roles }` and `{ kind: 'guest', guest }`. A new error code, `NOT_AVAILABLE`, is returned for everything under `sdk.school`, for `{ person }`, `parentsOf`, `staffOf` and `studentsOf` recipients and for `regarding`, whenever the caller is an account or guest, the app is standalone, or the environment has no school. Access rules match all of an account's roles, ignoring case, and the reserved role `guest` may only be given `own`. `createdBy, createdAt` is an implicit index, so a list of one's own records can be sorted. Notifications and tasks accept `{ account: id }` and `{ role: '<app role>' }`; guests can't send, assign or schedule. A version 1 manifest gains `guests?: boolean` (standalone apps only, and it needs 0.2.0). Nothing changes for school apps. The in-browser engine (`@quad-education/sdk/engine`, platform-side only) now keeps its state behind an `AppStore`, so the serverless data API can run the same rules over DynamoDB; as a result its `inbox`, `runs`, `auditLog`, `effectsSnapshot` and `runPrincipal` return promises, and an engine can be created with `school: false`. **A live app connects the same way**: `connect()` from `@quad-education/sdk/client` (and `<QuadProvider>` from `@quad-education/sdk-react`) works in the shell's iframe and, with no shell, at a live address, where it asks its own origin who is signed in and sends calls to the data API with a short-lived token. With nobody signed in it goes to Quad's sign-in, or, if the app allows guests, throws `SignInRequired` (`QuadProvider` shows sign-in and guest choices; `signIn()` and `continueAsGuest()` are exported). A live app needs 0.2.0.
|
|
99
|
+
- **0.1.4** (19 Oct 2026). The same SDK calls. The canonical model grows to what V2s S4 builds, which is what an app's `sdk.school.<entity>` and its types come from, so **0.1.3 cannot use any of it**: the attendance register (`sessionAttendance`, which must be filtered by student or date; `studentAbsences`, `attendanceSummaries`), behaviour and achievements, learning support, medical events and notes, staff absences and admissions applicants, and the demographic fields on `students`. It also adds two sensitivity tiers, `sensitive` and `hr`, which are staff-only (a student or parent never receives them), audited, and need manifest version 1 and a reason. A version 1 manifest still needs 0.1.3 or newer.
|
|
98
100
|
- **0.1.3** (18 Oct 2026). The same SDK calls, plus what V2s needs to run: manifest version 1 (`data`, `reasons`, `roles` and `schoolRoles`), declared-field types and stripping for school data, the new school entities (`periods`, `rooms`, `subjects`, `lessons`, with `lessons` generated on demand) and the test toolkit that understands all of it. **A version 1 manifest needs 0.1.3 or newer**: the test toolkit in 0.1.2 only reads version 0 manifests and fails every test with `invalid manifest: manifestVersion: expected 0`. The starter templates ask for `^0.1.3`.
|
|
99
101
|
- **0.1.2** (9 Oct 2026). The same contract as 0.1.1, and the first version to stay on npm. All the `@quad-education/*` packages were published on 9 Oct 2026 (0.1.0, and 0.1.1 for this one), then unpublished the same day to move the npm org to a new owner, and npm never allows an unpublished version again; every package is now 0.1.2. `SDK_VERSION` (`sdk.version`) now matches the package version; it had stayed at 0.1.0 through 0.1.1.
|
|
100
102
|
- **0.1.1** (8 Oct 2026). Contract change: `sdk.db` list `orderBy` and range filters need a declared index (or `id`/`createdAt`), and both the types and the engine enforce it (D37). The schema DSL keeps `indexes` as literal types, and `DbListOptions` gains `DbWhere`, `DbOrderBy` and `IndexedField`. The packages also moved from `@quad/*` to `@quad-education/*`, because the `@quad` npm scope belongs to someone else (D41); only the import paths change, and the version stays 0.1.1 because nothing was published under the old name. Before the first publish, the engine also stopped treating names inherited from `Object.prototype` (`constructor`, `toString`) as entities or fields; they now fail with `VALIDATION`, as any unknown name does.
|
|
@@ -67,6 +67,111 @@ export declare const TEST_APP: {
|
|
|
67
67
|
manifest: Manifest;
|
|
68
68
|
schema: typeof TEST_SCHEMA;
|
|
69
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* A demographics app (S4.5): version 1, because a staff-only tier needs a reason. It asks for the seven sensitive
|
|
72
|
+
* fields of a student and nothing else that varies.
|
|
73
|
+
*/
|
|
74
|
+
export declare const DEMOGRAPHICS_APP: {
|
|
75
|
+
manifest: Manifest;
|
|
76
|
+
schema: typeof TEST_SCHEMA;
|
|
77
|
+
};
|
|
78
|
+
/** An awards app: achievements are academic, so it needs no pastoral scope and is not in the pastoral audit (S4.3). */
|
|
79
|
+
export declare const AWARDS_APP: {
|
|
80
|
+
manifest: Manifest;
|
|
81
|
+
schema: typeof TEST_SCHEMA;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* A staff leave app (S4.6): version 1, because a staff-only tier needs a reason. It asks for the staff reference and the
|
|
85
|
+
* `hr` fields of an absence.
|
|
86
|
+
*/
|
|
87
|
+
export declare const HR_APP: {
|
|
88
|
+
manifest: Manifest;
|
|
89
|
+
schema: typeof TEST_SCHEMA;
|
|
90
|
+
};
|
|
91
|
+
/** A first-aid and learning support app: it holds the medical tier too, so it receives diagnoses (S4.4). */
|
|
92
|
+
export declare const WELLBEING_APP: {
|
|
93
|
+
manifest: Manifest;
|
|
94
|
+
schema: typeof TEST_SCHEMA;
|
|
95
|
+
};
|
|
96
|
+
/** The account directory the contract suite's engines are given: who exists and which app roles they hold. */
|
|
97
|
+
export declare const TEST_ACCOUNTS: readonly [{
|
|
98
|
+
readonly id: "acc-ada";
|
|
99
|
+
readonly displayName: "Ada Teacher";
|
|
100
|
+
readonly roles: readonly ["Teacher"];
|
|
101
|
+
}, {
|
|
102
|
+
readonly id: "acc-ben";
|
|
103
|
+
readonly displayName: "Ben Both";
|
|
104
|
+
readonly roles: readonly ["Teacher", "Student"];
|
|
105
|
+
}, {
|
|
106
|
+
readonly id: "acc-cai";
|
|
107
|
+
readonly displayName: "Cai Student";
|
|
108
|
+
readonly roles: readonly ["Student"];
|
|
109
|
+
}, {
|
|
110
|
+
readonly id: "acc-dee";
|
|
111
|
+
readonly displayName: "Dee Student";
|
|
112
|
+
readonly roles: readonly ["Student"];
|
|
113
|
+
}, {
|
|
114
|
+
readonly id: "acc-eve";
|
|
115
|
+
readonly displayName: "Eve Staff";
|
|
116
|
+
readonly roles: readonly ["Staff"];
|
|
117
|
+
}, {
|
|
118
|
+
readonly id: "acc-gus";
|
|
119
|
+
readonly displayName: "Gus Staff";
|
|
120
|
+
readonly roles: readonly ["Staff"];
|
|
121
|
+
}];
|
|
122
|
+
declare const ACCOUNT_SCHEMA: {
|
|
123
|
+
readonly note: {
|
|
124
|
+
readonly fields: {
|
|
125
|
+
readonly body: {
|
|
126
|
+
readonly kind: "text";
|
|
127
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
128
|
+
};
|
|
129
|
+
readonly score: {
|
|
130
|
+
readonly kind: "number";
|
|
131
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
132
|
+
} & {
|
|
133
|
+
readonly optional: true;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
readonly indexes: readonly [readonly ["score"]];
|
|
137
|
+
readonly subject?: "score" | "body";
|
|
138
|
+
readonly access?: {
|
|
139
|
+
readonly teacher: {
|
|
140
|
+
readonly read: "all";
|
|
141
|
+
readonly create: "all";
|
|
142
|
+
readonly update: "all";
|
|
143
|
+
readonly delete: "all";
|
|
144
|
+
};
|
|
145
|
+
readonly Student: {
|
|
146
|
+
readonly read: "own";
|
|
147
|
+
readonly create: "own";
|
|
148
|
+
readonly update: "own";
|
|
149
|
+
readonly delete: "own";
|
|
150
|
+
};
|
|
151
|
+
readonly guest: {
|
|
152
|
+
readonly read: "own";
|
|
153
|
+
readonly create: "own";
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
type AccountApp = {
|
|
159
|
+
roles: 'teacher' | 'student';
|
|
160
|
+
scopes: never;
|
|
161
|
+
notifications: 'test.message';
|
|
162
|
+
tasks: 'test.review';
|
|
163
|
+
scheduled: 'remind';
|
|
164
|
+
schema: typeof ACCOUNT_SCHEMA;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* A standalone app (version 1) with two app roles and guests (V2c). It reads no school data, so everything under
|
|
168
|
+
* `sdk.school` is NOT_AVAILABLE for it, whoever is asking.
|
|
169
|
+
*/
|
|
170
|
+
export declare const ACCOUNT_APP: {
|
|
171
|
+
manifest: Manifest;
|
|
172
|
+
schema: typeof ACCOUNT_SCHEMA;
|
|
173
|
+
jobs: Job<AccountApp>[];
|
|
174
|
+
};
|
|
70
175
|
/** A test app with only `students.basic:read`. */
|
|
71
176
|
export declare const BASIC_APP: {
|
|
72
177
|
manifest: Manifest;
|
|
@@ -61,11 +61,178 @@ export const TEST_APP = {
|
|
|
61
61
|
'periods.basic:read',
|
|
62
62
|
'rooms.basic:read',
|
|
63
63
|
'subjects.basic:read',
|
|
64
|
+
'sessionAttendance.basic:read',
|
|
65
|
+
'sessionAttendance.academic:read',
|
|
66
|
+
'sessionAttendance.pastoral:read',
|
|
67
|
+
'studentAbsences.basic:read',
|
|
68
|
+
'studentAbsences.academic:read',
|
|
69
|
+
'attendanceSummaries.basic:read',
|
|
70
|
+
'attendanceSummaries.academic:read',
|
|
71
|
+
'behaviours.basic:read',
|
|
72
|
+
'behaviours.pastoral:read',
|
|
73
|
+
'achievements.basic:read',
|
|
74
|
+
'achievements.academic:read',
|
|
75
|
+
'learningSupportNeeds.basic:read',
|
|
76
|
+
'learningSupportNeeds.pastoral:read',
|
|
77
|
+
'applicants.basic:read',
|
|
78
|
+
'applicants.contact:read',
|
|
64
79
|
],
|
|
65
80
|
notifications: ['test.message', 'test.reminder'],
|
|
66
81
|
},
|
|
67
82
|
schema: TEST_SCHEMA,
|
|
68
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* A demographics app (S4.5): version 1, because a staff-only tier needs a reason. It asks for the seven sensitive
|
|
86
|
+
* fields of a student and nothing else that varies.
|
|
87
|
+
*/
|
|
88
|
+
export const DEMOGRAPHICS_APP = {
|
|
89
|
+
manifest: {
|
|
90
|
+
...TEST_APP.manifest,
|
|
91
|
+
manifestVersion: 1,
|
|
92
|
+
id: 'contract-demographics',
|
|
93
|
+
name: 'Demographics app',
|
|
94
|
+
scopes: ['parents.basic:read', 'students.basic:read', 'students.sensitive:read'],
|
|
95
|
+
data: {
|
|
96
|
+
parents: { required: [], optional: ['title'] },
|
|
97
|
+
students: {
|
|
98
|
+
required: [],
|
|
99
|
+
optional: [
|
|
100
|
+
'firstLanguage',
|
|
101
|
+
'englishAsAdditionalLanguage',
|
|
102
|
+
'ethnicity',
|
|
103
|
+
'nationality',
|
|
104
|
+
'religion',
|
|
105
|
+
'birthPlace',
|
|
106
|
+
'freeSchoolMeals',
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
reasons: {
|
|
111
|
+
'students.sensitive:read': 'To plan language support and cultural events with families’ agreement.',
|
|
112
|
+
},
|
|
113
|
+
notifications: ['test.message'],
|
|
114
|
+
},
|
|
115
|
+
schema: TEST_SCHEMA,
|
|
116
|
+
};
|
|
117
|
+
/** An awards app: achievements are academic, so it needs no pastoral scope and is not in the pastoral audit (S4.3). */
|
|
118
|
+
export const AWARDS_APP = {
|
|
119
|
+
manifest: {
|
|
120
|
+
...TEST_APP.manifest,
|
|
121
|
+
id: 'contract-awards',
|
|
122
|
+
name: 'Awards app',
|
|
123
|
+
scopes: ['achievements.basic:read', 'achievements.academic:read'],
|
|
124
|
+
notifications: ['test.message'],
|
|
125
|
+
},
|
|
126
|
+
schema: TEST_SCHEMA,
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* A staff leave app (S4.6): version 1, because a staff-only tier needs a reason. It asks for the staff reference and the
|
|
130
|
+
* `hr` fields of an absence.
|
|
131
|
+
*/
|
|
132
|
+
export const HR_APP = {
|
|
133
|
+
manifest: {
|
|
134
|
+
...TEST_APP.manifest,
|
|
135
|
+
manifestVersion: 1,
|
|
136
|
+
id: 'contract-hr',
|
|
137
|
+
name: 'Staff leave app',
|
|
138
|
+
scopes: ['employeeAbsences.basic:read', 'employeeAbsences.hr:read'],
|
|
139
|
+
data: {
|
|
140
|
+
employeeAbsences: {
|
|
141
|
+
required: [],
|
|
142
|
+
optional: [
|
|
143
|
+
'staffId',
|
|
144
|
+
'startAt',
|
|
145
|
+
'endAt',
|
|
146
|
+
'absenceType',
|
|
147
|
+
'illnessCategory',
|
|
148
|
+
'workingDays',
|
|
149
|
+
'hours',
|
|
150
|
+
'note',
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
reasons: {
|
|
155
|
+
'employeeAbsences.hr:read': 'To roster relief staff and report on leave taken across the year.',
|
|
156
|
+
},
|
|
157
|
+
notifications: ['test.message'],
|
|
158
|
+
},
|
|
159
|
+
schema: TEST_SCHEMA,
|
|
160
|
+
};
|
|
161
|
+
/** A first-aid and learning support app: it holds the medical tier too, so it receives diagnoses (S4.4). */
|
|
162
|
+
export const WELLBEING_APP = {
|
|
163
|
+
manifest: {
|
|
164
|
+
...TEST_APP.manifest,
|
|
165
|
+
id: 'contract-wellbeing',
|
|
166
|
+
name: 'Wellbeing app',
|
|
167
|
+
scopes: [
|
|
168
|
+
'learningSupportNeeds.basic:read',
|
|
169
|
+
'learningSupportNeeds.pastoral:read',
|
|
170
|
+
'learningSupportNeeds.medical:read',
|
|
171
|
+
'medicalEvents.basic:read',
|
|
172
|
+
'medicalEvents.medical:read',
|
|
173
|
+
'medicalNotes.basic:read',
|
|
174
|
+
'medicalNotes.medical:read',
|
|
175
|
+
],
|
|
176
|
+
notifications: ['test.message'],
|
|
177
|
+
},
|
|
178
|
+
schema: TEST_SCHEMA,
|
|
179
|
+
};
|
|
180
|
+
// ---- Accounts and guests (V2c, D100) ----
|
|
181
|
+
/** The account directory the contract suite's engines are given: who exists and which app roles they hold. */
|
|
182
|
+
export const TEST_ACCOUNTS = [
|
|
183
|
+
{ id: 'acc-ada', displayName: 'Ada Teacher', roles: ['Teacher'] },
|
|
184
|
+
{ id: 'acc-ben', displayName: 'Ben Both', roles: ['Teacher', 'Student'] },
|
|
185
|
+
{ id: 'acc-cai', displayName: 'Cai Student', roles: ['Student'] },
|
|
186
|
+
{ id: 'acc-dee', displayName: 'Dee Student', roles: ['Student'] },
|
|
187
|
+
{ id: 'acc-eve', displayName: 'Eve Staff', roles: ['Staff'] },
|
|
188
|
+
{ id: 'acc-gus', displayName: 'Gus Staff', roles: ['Staff'] },
|
|
189
|
+
];
|
|
190
|
+
const ACCOUNT_SCHEMA = defineSchema({
|
|
191
|
+
note: entity({
|
|
192
|
+
fields: { body: text(), score: number({ optional: true }) },
|
|
193
|
+
indexes: [['score']],
|
|
194
|
+
// The keys are written in different cases on purpose: they match the app's roles ignoring case.
|
|
195
|
+
access: {
|
|
196
|
+
teacher: { read: 'all', create: 'all', update: 'all', delete: 'all' },
|
|
197
|
+
Student: { read: 'own', create: 'own', update: 'own', delete: 'own' },
|
|
198
|
+
guest: { read: 'own', create: 'own' },
|
|
199
|
+
},
|
|
200
|
+
}),
|
|
201
|
+
});
|
|
202
|
+
/** Records who it ran as, so a test can see the run-as principal of a job an account scheduled. */
|
|
203
|
+
const remind = defineJob({
|
|
204
|
+
name: 'remind',
|
|
205
|
+
async run({ sdk, runId }) {
|
|
206
|
+
const me = await sdk.auth.me();
|
|
207
|
+
await sdk.db
|
|
208
|
+
.entity('note')
|
|
209
|
+
.create({ body: JSON.stringify(me) }, { idempotencyKey: `remind:${runId}` });
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
/**
|
|
213
|
+
* A standalone app (version 1) with two app roles and guests (V2c). It reads no school data, so everything under
|
|
214
|
+
* `sdk.school` is NOT_AVAILABLE for it, whoever is asking.
|
|
215
|
+
*/
|
|
216
|
+
export const ACCOUNT_APP = {
|
|
217
|
+
manifest: {
|
|
218
|
+
manifestVersion: 1,
|
|
219
|
+
id: 'contract-accounts',
|
|
220
|
+
name: 'Accounts app',
|
|
221
|
+
sdk: '^0.2.0',
|
|
222
|
+
kit: 'react-ui',
|
|
223
|
+
roles: ['Teacher', 'Student'],
|
|
224
|
+
schoolRoles: [],
|
|
225
|
+
guests: true,
|
|
226
|
+
scopes: [],
|
|
227
|
+
data: {},
|
|
228
|
+
notifications: ['test.message'],
|
|
229
|
+
tasks: ['test.review'],
|
|
230
|
+
scheduled: ['remind'],
|
|
231
|
+
cron: [],
|
|
232
|
+
},
|
|
233
|
+
schema: ACCOUNT_SCHEMA,
|
|
234
|
+
jobs: [remind],
|
|
235
|
+
};
|
|
69
236
|
/** A test app with only `students.basic:read`. */
|
|
70
237
|
export const BASIC_APP = {
|
|
71
238
|
manifest: {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ActingAs } from '../src/contract/principals.ts';
|
|
2
|
+
import type { ContractEnv, TestApp } from './suite.ts';
|
|
3
|
+
import type { QuadSdk } from '../src/contract/types.ts';
|
|
4
|
+
import type { Engine } from '../src/engine/index.ts';
|
|
5
|
+
type SliceBControl = Pick<ContractEnv['control'], 'advanceClock' | 'runDueJobs' | 'redeliver' | 'runs' | 'inbox' | 'auditLog'>;
|
|
6
|
+
/**
|
|
7
|
+
* The job-running and inspection controls, shared by both contract runners. Each job runs
|
|
8
|
+
* as its run's principal through whatever transport `connect` uses.
|
|
9
|
+
*/
|
|
10
|
+
export declare function sliceBControls(engine: () => Engine, app: () => TestApp, connect: (principal: ActingAs) => Promise<QuadSdk>, onClock?: () => Promise<void>): SliceBControl;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { executeRun } from "../src/jobs/define.js";
|
|
2
|
+
/**
|
|
3
|
+
* The job-running and inspection controls, shared by both contract runners. Each job runs
|
|
4
|
+
* as its run's principal through whatever transport `connect` uses.
|
|
5
|
+
*/
|
|
6
|
+
export function sliceBControls(engine, app, connect, onClock = async () => { }) {
|
|
7
|
+
const appId = () => app().manifest.id;
|
|
8
|
+
return {
|
|
9
|
+
async advanceClock(ms) {
|
|
10
|
+
engine().advanceClock(ms);
|
|
11
|
+
await onClock();
|
|
12
|
+
},
|
|
13
|
+
async runDueJobs() {
|
|
14
|
+
const started = await engine().startDueRuns(appId());
|
|
15
|
+
return Promise.all(started.map(async (run) => {
|
|
16
|
+
// Each run acts as its own principal: cron as the system, scheduled jobs as whoever scheduled them (D7).
|
|
17
|
+
const sdk = await connect(run.runAs);
|
|
18
|
+
const result = await executeRun(app().jobs ?? [], run, sdk);
|
|
19
|
+
await engine().finishRun(appId(), run.runId, result);
|
|
20
|
+
return {
|
|
21
|
+
runId: run.runId,
|
|
22
|
+
jobName: run.jobName,
|
|
23
|
+
scheduledFor: run.scheduledFor,
|
|
24
|
+
ok: result.ok,
|
|
25
|
+
};
|
|
26
|
+
}));
|
|
27
|
+
},
|
|
28
|
+
redeliver: (runId) => engine().redeliverRun(appId(), runId),
|
|
29
|
+
runs: async () => (await engine().runs(appId())).map(({ id, jobName, scheduledFor, status, attempts, deliveries }) => ({
|
|
30
|
+
id,
|
|
31
|
+
jobName,
|
|
32
|
+
scheduledFor,
|
|
33
|
+
status,
|
|
34
|
+
attempts,
|
|
35
|
+
deliveries,
|
|
36
|
+
})),
|
|
37
|
+
inbox: async (personId) => engine().inbox(appId(), personId),
|
|
38
|
+
auditLog: async () => engine().auditLog(appId()),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function listAll(collection: any, options?: Record<string, unknown>): Promise<any[]>;
|
|
2
|
+
export declare function expectError(promise: Promise<unknown>, code: string): Promise<Error>;
|
|
3
|
+
export declare const ids: (records: readonly {
|
|
4
|
+
id: string;
|
|
5
|
+
}[]) => string[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any -- the suite drives the SDK untyped, like plain JS would */
|
|
2
|
+
import { expect } from 'vitest';
|
|
3
|
+
import { isQuadError } from "../src/index.js";
|
|
4
|
+
export async function listAll(collection, options = {}) {
|
|
5
|
+
const items = [];
|
|
6
|
+
let cursor;
|
|
7
|
+
do {
|
|
8
|
+
const page = await collection.list({ ...options, limit: 200, ...(cursor ? { cursor } : {}) });
|
|
9
|
+
items.push(...page.items);
|
|
10
|
+
cursor = page.nextCursor ?? undefined;
|
|
11
|
+
} while (cursor);
|
|
12
|
+
return items;
|
|
13
|
+
}
|
|
14
|
+
export async function expectError(promise, code) {
|
|
15
|
+
try {
|
|
16
|
+
await promise;
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
expect(isQuadError(e), `expected a QuadError, got ${String(e)}`).toBe(true);
|
|
20
|
+
expect(e.code).toBe(code);
|
|
21
|
+
return e;
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`expected ${code}, but the call succeeded`);
|
|
24
|
+
}
|
|
25
|
+
export const ids = (records) => records.map((r) => r.id).sort();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { defineContractSuite } from './suite.ts';
|
|
2
|
-
export type { ContractEnv, ContractFactory, TestApp } from './suite.ts';
|
|
3
|
-
export {
|
|
2
|
+
export type { ContractEnv, ContractFactory, ContractOptions, TestApp } from './suite.ts';
|
|
3
|
+
export { sliceBControls } from './harness.ts';
|
|
4
|
+
export { STANDALONE_APP } from './standalone-apps.ts';
|
|
5
|
+
export { ACCESS_APP, ACCOUNT_APP, AWARDS_APP, BASIC_APP, DEMOGRAPHICS_APP, HR_APP, JOBS_APP, TEST_APP, TEST_ACCOUNTS, WELLBEING_APP, slowGate, } from './apps.ts';
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { defineContractSuite } from "./suite.js";
|
|
2
|
-
export {
|
|
2
|
+
export { sliceBControls } from "./harness.js";
|
|
3
|
+
export { STANDALONE_APP } from "./standalone-apps.js";
|
|
4
|
+
export { ACCESS_APP, ACCOUNT_APP, AWARDS_APP, BASIC_APP, DEMOGRAPHICS_APP, HR_APP, JOBS_APP, TEST_APP, TEST_ACCOUNTS, WELLBEING_APP, slowGate, } from "./apps.js";
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { type Manifest } from '@quad-education/schema';
|
|
2
|
+
import { type Job } from '../src/jobs/index.ts';
|
|
3
|
+
export declare const STANDALONE_SCHEMA: {
|
|
4
|
+
readonly post: {
|
|
5
|
+
readonly fields: {
|
|
6
|
+
readonly message: {
|
|
7
|
+
readonly kind: "text";
|
|
8
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
9
|
+
};
|
|
10
|
+
readonly tone: {
|
|
11
|
+
readonly kind: "enum";
|
|
12
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
13
|
+
} & {
|
|
14
|
+
values: readonly ["warm", "formal"];
|
|
15
|
+
};
|
|
16
|
+
readonly note: {
|
|
17
|
+
readonly kind: "text";
|
|
18
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
19
|
+
} & {
|
|
20
|
+
readonly optional: true;
|
|
21
|
+
};
|
|
22
|
+
readonly staffNote: {
|
|
23
|
+
readonly kind: "text";
|
|
24
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
25
|
+
} & {
|
|
26
|
+
readonly optional: true;
|
|
27
|
+
} & {
|
|
28
|
+
readonly visibleTo: readonly ["staff"];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
readonly indexes: readonly [readonly ["message"], readonly ["tone", "message"]];
|
|
32
|
+
readonly subject?: "note" | "message" | "tone" | "staffNote";
|
|
33
|
+
readonly access?: {
|
|
34
|
+
readonly Staff: {
|
|
35
|
+
readonly read: "all";
|
|
36
|
+
readonly create: "all";
|
|
37
|
+
readonly update: "all";
|
|
38
|
+
readonly delete: "all";
|
|
39
|
+
};
|
|
40
|
+
readonly Student: {
|
|
41
|
+
readonly read: "own";
|
|
42
|
+
readonly create: "own";
|
|
43
|
+
readonly update: "own";
|
|
44
|
+
readonly delete: "own";
|
|
45
|
+
};
|
|
46
|
+
readonly guest: {
|
|
47
|
+
readonly read: "own";
|
|
48
|
+
readonly create: "own";
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
readonly reply: {
|
|
53
|
+
readonly fields: {
|
|
54
|
+
readonly postId: {
|
|
55
|
+
readonly kind: "ref";
|
|
56
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
57
|
+
} & {
|
|
58
|
+
to: "post";
|
|
59
|
+
};
|
|
60
|
+
readonly message: {
|
|
61
|
+
readonly kind: "text";
|
|
62
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
readonly indexes: readonly [];
|
|
66
|
+
readonly subject?: "message" | "postId";
|
|
67
|
+
readonly access?: {
|
|
68
|
+
readonly Staff: {
|
|
69
|
+
readonly read: "all";
|
|
70
|
+
readonly create: "all";
|
|
71
|
+
};
|
|
72
|
+
readonly Student: {
|
|
73
|
+
readonly read: "own";
|
|
74
|
+
readonly create: "own";
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/** No access block: only the system principal reaches it. */
|
|
79
|
+
readonly secret: {
|
|
80
|
+
readonly fields: {
|
|
81
|
+
readonly body: {
|
|
82
|
+
readonly kind: "text";
|
|
83
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
readonly indexes: readonly [];
|
|
87
|
+
readonly subject?: "body";
|
|
88
|
+
readonly access?: import("@quad-education/schema").AccessPolicy;
|
|
89
|
+
};
|
|
90
|
+
/** A staff-only log that test jobs write to, so tests can see what ran and as whom. */
|
|
91
|
+
readonly staffLog: {
|
|
92
|
+
readonly fields: {
|
|
93
|
+
readonly jobName: {
|
|
94
|
+
readonly kind: "text";
|
|
95
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
96
|
+
};
|
|
97
|
+
readonly runId: {
|
|
98
|
+
readonly kind: "text";
|
|
99
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
100
|
+
};
|
|
101
|
+
readonly scheduledFor: {
|
|
102
|
+
readonly kind: "text";
|
|
103
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
104
|
+
};
|
|
105
|
+
readonly principal: {
|
|
106
|
+
readonly kind: "text";
|
|
107
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
108
|
+
};
|
|
109
|
+
readonly note: {
|
|
110
|
+
readonly kind: "text";
|
|
111
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
112
|
+
} & {
|
|
113
|
+
readonly optional: true;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
readonly indexes: readonly [];
|
|
117
|
+
readonly subject?: "note" | "runId" | "jobName" | "scheduledFor" | "principal";
|
|
118
|
+
readonly access?: {
|
|
119
|
+
readonly Staff: {
|
|
120
|
+
readonly read: "all";
|
|
121
|
+
readonly create: "all";
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/** What a job could see and do, recorded by the job itself (D7 run-as tests). */
|
|
126
|
+
readonly probe: {
|
|
127
|
+
readonly fields: {
|
|
128
|
+
readonly runId: {
|
|
129
|
+
readonly kind: "text";
|
|
130
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
131
|
+
};
|
|
132
|
+
readonly principal: {
|
|
133
|
+
readonly kind: "text";
|
|
134
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
135
|
+
};
|
|
136
|
+
readonly postsSeen: {
|
|
137
|
+
readonly kind: "number";
|
|
138
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
139
|
+
};
|
|
140
|
+
readonly otherPostVisible: {
|
|
141
|
+
readonly kind: "boolean";
|
|
142
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
143
|
+
};
|
|
144
|
+
readonly staffWriteAllowed: {
|
|
145
|
+
readonly kind: "boolean";
|
|
146
|
+
readonly tier: import("@quad-education/canonical").Tier;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
readonly indexes: readonly [];
|
|
150
|
+
readonly subject?: "runId" | "principal" | "postsSeen" | "otherPostVisible" | "staffWriteAllowed";
|
|
151
|
+
readonly access?: {
|
|
152
|
+
readonly Staff: {
|
|
153
|
+
readonly read: "all";
|
|
154
|
+
readonly create: "all";
|
|
155
|
+
};
|
|
156
|
+
readonly Student: {
|
|
157
|
+
readonly read: "own";
|
|
158
|
+
readonly create: "own";
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
type StandaloneApp = {
|
|
164
|
+
roles: 'staff' | 'student';
|
|
165
|
+
scopes: never;
|
|
166
|
+
notifications: 'test.message';
|
|
167
|
+
tasks: 'test.review';
|
|
168
|
+
scheduled: 'follow-up' | 'slow' | 'flaky' | 'probe' | 'chain';
|
|
169
|
+
schema: typeof STANDALONE_SCHEMA;
|
|
170
|
+
};
|
|
171
|
+
/** Lets a test hold the `slow` job mid-run, to prove runs of one job never overlap. */
|
|
172
|
+
export declare const standaloneSlowGate: {
|
|
173
|
+
release: () => void;
|
|
174
|
+
wait: Promise<void>;
|
|
175
|
+
reset(): void;
|
|
176
|
+
};
|
|
177
|
+
/** A version 1 standalone app with two app roles and guests, plus jobs and a weekly cron. */
|
|
178
|
+
export declare const STANDALONE_APP: {
|
|
179
|
+
manifest: Manifest;
|
|
180
|
+
schema: typeof STANDALONE_SCHEMA;
|
|
181
|
+
jobs: Job<StandaloneApp>[];
|
|
182
|
+
};
|
|
183
|
+
export {};
|