@quad-education/sdk 0.8.0 → 0.9.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 +1 -0
- package/dist/contract-tests/apps.d.ts +430 -0
- package/dist/contract-tests/apps.js +143 -1
- package/dist/contract-tests/harness.d.ts +1 -1
- package/dist/contract-tests/harness.js +4 -0
- package/dist/contract-tests/lists-and-files.d.ts +19 -0
- package/dist/contract-tests/lists-and-files.js +279 -0
- package/dist/contract-tests/live.d.ts +3 -0
- package/dist/contract-tests/live.js +156 -0
- package/dist/contract-tests/notifications.d.ts +3 -0
- package/dist/contract-tests/notifications.js +218 -0
- package/dist/contract-tests/search-and-totals.d.ts +13 -0
- package/dist/contract-tests/search-and-totals.js +226 -0
- package/dist/contract-tests/suite.d.ts +5 -0
- package/dist/contract-tests/suite.js +27 -1
- package/dist/contract-tests/writes.d.ts +3 -0
- package/dist/contract-tests/writes.js +265 -0
- package/dist/src/base64.d.ts +3 -0
- package/dist/src/base64.js +52 -0
- package/dist/src/client/connect.d.ts +1 -0
- package/dist/src/client/connect.js +1 -0
- package/dist/src/client/create-client.js +39 -5
- package/dist/src/client/save-file.d.ts +16 -0
- package/dist/src/client/save-file.js +28 -0
- package/dist/src/client/watch.d.ts +20 -0
- package/dist/src/client/watch.js +175 -0
- package/dist/src/contract/errors.d.ts +1 -1
- package/dist/src/contract/types.d.ts +214 -10
- package/dist/src/contract/types.js +4 -1
- package/dist/src/engine/engine.d.ts +68 -1
- package/dist/src/engine/engine.js +508 -57
- package/dist/src/engine/files.d.ts +25 -0
- package/dist/src/engine/files.js +88 -0
- package/dist/src/engine/index.d.ts +1 -1
- package/dist/src/engine/memory-store.d.ts +33 -3
- package/dist/src/engine/memory-store.js +116 -8
- package/dist/src/engine/notify-content.d.ts +9 -0
- package/dist/src/engine/notify-content.js +88 -0
- package/dist/src/engine/query.d.ts +14 -2
- package/dist/src/engine/query.js +45 -13
- package/dist/src/engine/search.d.ts +8 -0
- package/dist/src/engine/search.js +32 -0
- package/dist/src/engine/storage.d.ts +46 -1
- package/dist/src/engine/storage.js +46 -3
- package/dist/src/engine/store.d.ts +39 -2
- package/dist/src/engine/summary.d.ts +25 -0
- package/dist/src/engine/summary.js +107 -0
- package/dist/src/engine/validate-input.d.ts +7 -1
- package/dist/src/engine/validate-input.js +28 -1
- package/dist/src/engine/working-copy.d.ts +30 -0
- package/dist/src/engine/working-copy.js +91 -0
- package/dist/src/platform-types.d.ts +11 -1
- package/dist/src/protocol.d.ts +1 -1
- package/dist/src/protocol.js +9 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.js +9 -1
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Error codes the SDK contract can return. Both implementations use the same codes. */
|
|
2
|
-
export type QuadErrorCode = 'SCOPE_NOT_GRANTED' | 'UNDECLARED_TYPE' | 'NOT_FOUND' | 'VALIDATION' | 'FORBIDDEN' | 'NOT_PERMITTED' | 'NOT_ASSIGNEE' | 'TRANSPORT' | 'INTERNAL';
|
|
2
|
+
export type QuadErrorCode = 'SCOPE_NOT_GRANTED' | 'UNDECLARED_TYPE' | 'NOT_FOUND' | 'VALIDATION' | 'FORBIDDEN' | 'NOT_PERMITTED' | 'CONFLICT' | 'NOT_ASSIGNEE' | 'TRANSPORT' | 'INTERNAL';
|
|
3
3
|
export declare class QuadError extends Error {
|
|
4
4
|
readonly code: QuadErrorCode;
|
|
5
5
|
readonly details: unknown;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CanonicalRecord, ContactPurpose, Entities, EntityName, RecordWithTiers, Role, TiersFor } from '@quad-education/canonical';
|
|
2
2
|
import type { AppEntityDef, AppInput, AppSchema, FieldValue, SystemFields } from '@quad-education/schema';
|
|
3
3
|
import type { Recipient } from './recipients.ts';
|
|
4
|
-
export declare const SDK_VERSION = "0.
|
|
4
|
+
export declare const SDK_VERSION = "0.9.0";
|
|
5
5
|
/**
|
|
6
6
|
* Describes the current app to the type system. `quad gen` augments it from
|
|
7
7
|
* app.manifest.json and schema/ (D23); without that, nothing is readable.
|
|
@@ -61,6 +61,11 @@ export type ListOptions<R> = {
|
|
|
61
61
|
/** 1–200, default 50. */
|
|
62
62
|
readonly limit?: number;
|
|
63
63
|
readonly cursor?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Words to look for (D153): every word must appear, ignoring case and accents. School data is searched in the
|
|
66
|
+
* text the app is granted; an app's own records in the fields its entity names in `search`.
|
|
67
|
+
*/
|
|
68
|
+
readonly search?: string;
|
|
64
69
|
};
|
|
65
70
|
export type Page<R> = {
|
|
66
71
|
readonly items: readonly R[];
|
|
@@ -166,16 +171,30 @@ export type RecordFor<A extends AppConfig, E extends AppEntityDef> = Simplify<Sy
|
|
|
166
171
|
type RefFields<E extends AppEntityDef> = {
|
|
167
172
|
[K in keyof E['fields']]: E['fields'][K] extends {
|
|
168
173
|
kind: 'ref';
|
|
174
|
+
} | {
|
|
175
|
+
kind: 'list';
|
|
176
|
+
of: {
|
|
177
|
+
kind: 'ref';
|
|
178
|
+
};
|
|
169
179
|
} ? K : never;
|
|
170
180
|
}[keyof E['fields']] & string;
|
|
171
181
|
type RefTarget<E extends AppEntityDef, K extends keyof E['fields']> = E['fields'][K] extends {
|
|
172
182
|
to: infer T;
|
|
183
|
+
} ? T : E['fields'][K] extends {
|
|
184
|
+
of: {
|
|
185
|
+
to: infer T;
|
|
186
|
+
};
|
|
173
187
|
} ? T : never;
|
|
174
188
|
type Resolved<A extends AppConfig, T> = T extends `school.${infer N extends EntityName}` ? SchoolRecord<A, N> : T extends keyof A['schema'] ? RecordFor<A, A['schema'][T]> : never;
|
|
175
189
|
export type WithIncluded<A extends AppConfig, E extends AppEntityDef, I extends string> = RecordFor<A, E> & {
|
|
176
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* Included refs; null when the target doesn't exist or isn't visible to the current user. A list of refs
|
|
192
|
+
* gives a list, in the same order (D147).
|
|
193
|
+
*/
|
|
177
194
|
readonly $included: {
|
|
178
|
-
readonly [K in I]: K extends keyof E['fields'] ?
|
|
195
|
+
readonly [K in I]: K extends keyof E['fields'] ? E['fields'][K] extends {
|
|
196
|
+
kind: 'list';
|
|
197
|
+
} ? readonly (Resolved<A, RefTarget<E, K>> | null)[] : Resolved<A, RefTarget<E, K>> | null : never;
|
|
179
198
|
};
|
|
180
199
|
};
|
|
181
200
|
/**
|
|
@@ -189,9 +208,13 @@ type EqualityCondition<V> = V | {
|
|
|
189
208
|
} | {
|
|
190
209
|
readonly ne: V;
|
|
191
210
|
};
|
|
192
|
-
/**
|
|
211
|
+
/** What a list field is asked (D147): whether it has a value. */
|
|
212
|
+
export type HasCondition<V> = {
|
|
213
|
+
readonly has: V;
|
|
214
|
+
};
|
|
215
|
+
/** Like `Where`, but range conditions only on indexed fields (D37), and a list only with `has` (D147). */
|
|
193
216
|
export type DbWhere<R, IX extends string> = {
|
|
194
|
-
readonly [K in keyof R]?: R[K] extends Scalar | undefined ? K extends IX ? Condition<Exclude<R[K], undefined>> : EqualityCondition<Exclude<R[K], undefined>> : never;
|
|
217
|
+
readonly [K in keyof R]?: R[K] extends Scalar | undefined ? K extends IX ? Condition<Exclude<R[K], undefined>> : EqualityCondition<Exclude<R[K], undefined>> : Exclude<R[K], undefined> extends readonly (infer V)[] ? HasCondition<V> : never;
|
|
195
218
|
};
|
|
196
219
|
export type DbOrderBy<R, IX extends string> = {
|
|
197
220
|
readonly field: keyof R & IX & string;
|
|
@@ -202,24 +225,154 @@ export type DbListOptions<A extends AppConfig, E extends AppEntityDef, I extends
|
|
|
202
225
|
readonly orderBy?: DbOrderBy<RecordFor<A, E>, IndexedField<E>> | readonly DbOrderBy<RecordFor<A, E>, IndexedField<E>>[];
|
|
203
226
|
readonly include?: readonly I[];
|
|
204
227
|
};
|
|
205
|
-
/**
|
|
228
|
+
/**
|
|
229
|
+
* A write that happens only when the record still holds these values (D150): equality, on single-valued fields
|
|
230
|
+
* you can see; `null` means the field is empty. Otherwise CONFLICT.
|
|
231
|
+
*/
|
|
232
|
+
export type WriteCondition<R> = {
|
|
233
|
+
readonly [K in keyof R]?: Exclude<R[K], undefined> extends Scalar ? Exclude<R[K], undefined> | null : never;
|
|
234
|
+
};
|
|
235
|
+
/** One write in a `db.batch` (D150). */
|
|
236
|
+
export type DbBatchOp<A extends AppConfig> = {
|
|
237
|
+
[N in keyof A['schema'] & string]: {
|
|
238
|
+
readonly create: N;
|
|
239
|
+
readonly input: AppInput<A['schema'][N]>;
|
|
240
|
+
readonly idempotencyKey?: string;
|
|
241
|
+
} | {
|
|
242
|
+
readonly update: N;
|
|
243
|
+
readonly id: string;
|
|
244
|
+
readonly patch: Partial<AppInput<A['schema'][N]>>;
|
|
245
|
+
readonly if?: WriteCondition<RecordFor<A, A['schema'][N]>>;
|
|
246
|
+
} | {
|
|
247
|
+
readonly delete: N;
|
|
248
|
+
readonly id: string;
|
|
249
|
+
readonly if?: WriteCondition<RecordFor<A, A['schema'][N]>>;
|
|
250
|
+
};
|
|
251
|
+
}[keyof A['schema'] & string];
|
|
252
|
+
/** What each operation of a batch returns: the record it wrote, or null for a delete. */
|
|
253
|
+
export type DbBatchResults<A extends AppConfig, O extends readonly unknown[]> = {
|
|
254
|
+
readonly [I in keyof O]: O[I] extends {
|
|
255
|
+
create: infer N extends keyof A['schema'];
|
|
256
|
+
} ? RecordFor<A, A['schema'][N]> : O[I] extends {
|
|
257
|
+
update: infer N extends keyof A['schema'];
|
|
258
|
+
} ? RecordFor<A, A['schema'][N]> : null;
|
|
259
|
+
};
|
|
260
|
+
type NumberFields<E extends AppEntityDef> = {
|
|
261
|
+
[K in keyof E['fields']]: E['fields'][K] extends {
|
|
262
|
+
kind: 'number';
|
|
263
|
+
} ? K : never;
|
|
264
|
+
}[keyof E['fields']] & string;
|
|
265
|
+
type GroupFields<E extends AppEntityDef> = 'createdBy' | ({
|
|
266
|
+
[K in keyof E['fields']]: E['fields'][K] extends {
|
|
267
|
+
kind: 'list' | 'file';
|
|
268
|
+
} ? never : K;
|
|
269
|
+
}[keyof E['fields']] & string);
|
|
270
|
+
/** A count, and the totals asked for: each by field name. `min`, `max` and `avg` are null when no record has the field. */
|
|
271
|
+
export type DbTotals = {
|
|
272
|
+
readonly count: number;
|
|
273
|
+
readonly sum?: Readonly<Record<string, number>>;
|
|
274
|
+
readonly min?: Readonly<Record<string, number | null>>;
|
|
275
|
+
readonly max?: Readonly<Record<string, number | null>>;
|
|
276
|
+
readonly avg?: Readonly<Record<string, number | null>>;
|
|
277
|
+
};
|
|
278
|
+
/** What `summarise` returns (D154): the totals of every matching record, and of each group when `groupBy` is given. */
|
|
279
|
+
export type DbSummary = DbTotals & {
|
|
280
|
+
/** In order of value; `value` is null for the records that leave the field empty. */
|
|
281
|
+
readonly groups?: readonly (DbTotals & {
|
|
282
|
+
readonly value: string | number | boolean | null;
|
|
283
|
+
})[];
|
|
284
|
+
};
|
|
285
|
+
/** Operations on one app entity. */
|
|
206
286
|
export type DbOps<A extends AppConfig, E extends AppEntityDef> = {
|
|
207
287
|
/** NOT_PERMITTED if the access rules deny it, or the subject is a student you can't see (D25). */
|
|
288
|
+
/** CONFLICT if another record already holds the values of one of the entity's `unique` rules (D149). */
|
|
208
289
|
create(input: AppInput<E>, options?: {
|
|
209
290
|
idempotencyKey?: string;
|
|
210
291
|
}): Promise<RecordFor<A, E>>;
|
|
211
|
-
|
|
292
|
+
/** With `if`, only when the record still holds those values; otherwise CONFLICT (D150). */
|
|
293
|
+
update(id: string, patch: Partial<AppInput<E>>, options?: {
|
|
294
|
+
readonly if?: WriteCondition<RecordFor<A, E>>;
|
|
295
|
+
}): Promise<RecordFor<A, E>>;
|
|
212
296
|
/** NOT_FOUND if the record doesn't exist or you may not read it (D25). */
|
|
213
297
|
get(id: string): Promise<RecordFor<A, E>>;
|
|
214
298
|
/** Only records you may read; filters and pages apply after access checks (D25). */
|
|
215
299
|
list<const I extends RefFields<E> = never>(options?: DbListOptions<A, E, I>): Promise<Page<[I] extends [never] ? RecordFor<A, E> : WithIncluded<A, E, I>>>;
|
|
216
|
-
delete(id: string
|
|
300
|
+
delete(id: string, options?: {
|
|
301
|
+
readonly if?: WriteCondition<RecordFor<A, E>>;
|
|
302
|
+
}): Promise<void>;
|
|
303
|
+
/** How many records match, of those you may read (D154). */
|
|
304
|
+
count(options?: {
|
|
305
|
+
readonly where?: DbWhere<RecordFor<A, E>, IndexedField<E>>;
|
|
306
|
+
readonly search?: string;
|
|
307
|
+
}): Promise<number>;
|
|
308
|
+
/**
|
|
309
|
+
* The count of the records you may read that match, with the sum, least, greatest and average of number
|
|
310
|
+
* fields, and the same for each value of one field with `groupBy` (D154). VALIDATION past 20,000 records or
|
|
311
|
+
* 200 groups: narrow it with `where`.
|
|
312
|
+
*/
|
|
313
|
+
summarise(options?: {
|
|
314
|
+
readonly where?: DbWhere<RecordFor<A, E>, IndexedField<E>>;
|
|
315
|
+
readonly search?: string;
|
|
316
|
+
readonly groupBy?: GroupFields<E>;
|
|
317
|
+
readonly sum?: readonly NumberFields<E>[];
|
|
318
|
+
readonly min?: readonly NumberFields<E>[];
|
|
319
|
+
readonly max?: readonly NumberFields<E>[];
|
|
320
|
+
readonly avg?: readonly NumberFields<E>[];
|
|
321
|
+
}): Promise<DbSummary>;
|
|
217
322
|
};
|
|
218
323
|
/** The app's own data, stored by the platform (IndexedDB in V1). */
|
|
219
324
|
export type DbApi<A extends AppConfig> = {
|
|
220
325
|
entity<N extends keyof A['schema'] & string>(name: N): DbOps<A, A['schema'][N]>;
|
|
326
|
+
/**
|
|
327
|
+
* Up to 25 creates, updates and deletes, across the app's entities: every one is written, or none is (D150).
|
|
328
|
+
* Each is checked as it is on its own; the first to fail stops the batch with its error, and `details.index`
|
|
329
|
+
* says which it was. Results come back in order. An operation can't refer to a record created earlier in the
|
|
330
|
+
* same batch.
|
|
331
|
+
*/
|
|
332
|
+
batch<const O extends readonly DbBatchOp<A>[]>(ops: O, options?: {
|
|
333
|
+
readonly idempotencyKey?: string;
|
|
334
|
+
}): Promise<DbBatchResults<A, O>>;
|
|
335
|
+
/**
|
|
336
|
+
* Keep a screen in step with the app's records (D157). The callback runs once at the start, and again whenever
|
|
337
|
+
* a record in one of the named entities is created, changed or deleted, by anyone or by a job; read what the
|
|
338
|
+
* screen shows inside it, in the ordinary way. Quad is asked every 5 seconds (`intervalMs`, never less than
|
|
339
|
+
* 2000), not while the page is hidden, and at once after a write made through this SDK. It says that something
|
|
340
|
+
* changed, never what.
|
|
341
|
+
*/
|
|
342
|
+
watch(entities: readonly (keyof A['schema'] & string)[], callback: () => void | Promise<void>, options?: {
|
|
343
|
+
readonly intervalMs?: number;
|
|
344
|
+
/** Told when Quad can't be asked, or the callback fails. The watch carries on. */
|
|
345
|
+
readonly onError?: (error: Error) => void;
|
|
346
|
+
}): DbWatch;
|
|
347
|
+
};
|
|
348
|
+
/** A watch started with `sdk.db.watch` (D157). */
|
|
349
|
+
export type DbWatch = {
|
|
350
|
+
/** Ask now, and wait for the callback if anything changed. */
|
|
351
|
+
check(): Promise<void>;
|
|
352
|
+
/** Stop watching, when the screen goes. */
|
|
353
|
+
stop(): void;
|
|
221
354
|
};
|
|
222
355
|
export type Channel = 'inApp' | 'email';
|
|
356
|
+
/**
|
|
357
|
+
* One part of a formatted notification (D151). All text is plain text: Quad renders the blocks, and an app never
|
|
358
|
+
* writes HTML. A button's link is a path in the app, like `link`.
|
|
359
|
+
*/
|
|
360
|
+
export type NotifyBlock = {
|
|
361
|
+
readonly heading: string;
|
|
362
|
+
} | {
|
|
363
|
+
readonly text: string;
|
|
364
|
+
} | {
|
|
365
|
+
readonly list: readonly string[];
|
|
366
|
+
}
|
|
367
|
+
/** Rows of a label and a value: the facts of an event. */
|
|
368
|
+
| {
|
|
369
|
+
readonly details: readonly (readonly [label: string, value: string])[];
|
|
370
|
+
} | {
|
|
371
|
+
readonly button: {
|
|
372
|
+
readonly label: string;
|
|
373
|
+
readonly link: string;
|
|
374
|
+
};
|
|
375
|
+
};
|
|
223
376
|
export type NotifyInput<A extends AppConfig> = {
|
|
224
377
|
readonly type: A['notifications'];
|
|
225
378
|
readonly to: Recipient | readonly Recipient[];
|
|
@@ -229,11 +382,25 @@ export type NotifyInput<A extends AppConfig> = {
|
|
|
229
382
|
};
|
|
230
383
|
readonly channel?: Channel;
|
|
231
384
|
readonly subject: string;
|
|
232
|
-
readonly body: string;
|
|
233
385
|
/** An app-relative link, e.g. `/greetings/abc`. */
|
|
234
386
|
readonly link?: string;
|
|
387
|
+
/**
|
|
388
|
+
* Files to send with the message (D152): up to five ids, 10 MB in all, of files you can read. Each recipient
|
|
389
|
+
* gets a copy made now, whether or not they could read the record it came from. NOT_PERMITTED when a file's
|
|
390
|
+
* field is hidden from a recipient's role (`visibleTo`) or is at a staff-only level and a recipient is not staff.
|
|
391
|
+
*/
|
|
392
|
+
readonly attachments?: readonly string[];
|
|
235
393
|
readonly idempotencyKey?: string;
|
|
236
|
-
}
|
|
394
|
+
} & ({
|
|
395
|
+
/** The message as plain text. */
|
|
396
|
+
readonly body: string;
|
|
397
|
+
/** The message in blocks, up to 30, with at most one button (D151). */
|
|
398
|
+
readonly content?: readonly NotifyBlock[];
|
|
399
|
+
} | {
|
|
400
|
+
/** Left out, the plain text is made from `content`. */
|
|
401
|
+
readonly body?: string;
|
|
402
|
+
readonly content: readonly NotifyBlock[];
|
|
403
|
+
});
|
|
237
404
|
export type ResolvedRecipient = {
|
|
238
405
|
readonly personId: string;
|
|
239
406
|
readonly role: Role;
|
|
@@ -411,6 +578,42 @@ export type AuditApi = {
|
|
|
411
578
|
readonly cursor?: string;
|
|
412
579
|
}): Promise<Page<AuditEntry>>;
|
|
413
580
|
};
|
|
581
|
+
/** The most one file can hold: 10 MB. The same number as the schema package's, kept here so an app's bundle needs only this one. */
|
|
582
|
+
export declare const MAX_FILE_BYTES: number;
|
|
583
|
+
/** A file an app keeps. Its id is what a `file` field holds. */
|
|
584
|
+
export type FileInfo = {
|
|
585
|
+
readonly id: string;
|
|
586
|
+
readonly name: string;
|
|
587
|
+
/** The media type, e.g. `image/png`. */
|
|
588
|
+
readonly type: string;
|
|
589
|
+
/** The size in bytes. */
|
|
590
|
+
readonly size: number;
|
|
591
|
+
readonly createdAt: string;
|
|
592
|
+
readonly createdBy: string;
|
|
593
|
+
};
|
|
594
|
+
/** Anything with a type and contents: a browser's `File` or `Blob` fits. */
|
|
595
|
+
export type FileSource = {
|
|
596
|
+
readonly type: string;
|
|
597
|
+
readonly name?: string;
|
|
598
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
599
|
+
};
|
|
600
|
+
export type FilesApi = {
|
|
601
|
+
/**
|
|
602
|
+
* Keep a file. It is yours alone until you write its id into a `file` field of a record; from then on whoever
|
|
603
|
+
* can read that field can read the file, and it is removed with the field or the record. A file not attached
|
|
604
|
+
* within 24 hours is removed. VALIDATION when the file is too large or not a kind Quad keeps.
|
|
605
|
+
*/
|
|
606
|
+
upload(file: FileSource, options?: {
|
|
607
|
+
readonly name?: string;
|
|
608
|
+
}): Promise<FileInfo>;
|
|
609
|
+
/** NOT_FOUND if the file doesn't exist or you may not read the field it is attached to. */
|
|
610
|
+
info(id: string): Promise<FileInfo>;
|
|
611
|
+
/** The file's contents, to show or to save. NOT_FOUND as for `info`. */
|
|
612
|
+
read(id: string): Promise<{
|
|
613
|
+
readonly info: FileInfo;
|
|
614
|
+
readonly bytes: Uint8Array;
|
|
615
|
+
}>;
|
|
616
|
+
};
|
|
414
617
|
export type ClockApi = {
|
|
415
618
|
/** The current instant (ISO 8601, UTC). Follows the demo clock, not the wall clock (D14). */
|
|
416
619
|
now(): string;
|
|
@@ -428,6 +631,7 @@ export type QuadSdk<A extends AppConfig = CurrentApp> = {
|
|
|
428
631
|
readonly schedule: ScheduleApi<A>;
|
|
429
632
|
readonly cron: CronApi;
|
|
430
633
|
readonly audit: AuditApi;
|
|
634
|
+
readonly files: FilesApi;
|
|
431
635
|
readonly clock: ClockApi;
|
|
432
636
|
};
|
|
433
637
|
export type { ContactPurpose, Recipient, Role };
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
export const SDK_VERSION = '0.
|
|
1
|
+
export const SDK_VERSION = '0.9.0';
|
|
2
|
+
// ---- files (D148) ----
|
|
3
|
+
/** The most one file can hold: 10 MB. The same number as the schema package's, kept here so an app's bundle needs only this one. */
|
|
4
|
+
export const MAX_FILE_BYTES = 10 * 1024 * 1024;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type Dataset, type Principal } from '@quad-education/canonical';
|
|
2
2
|
import { type AppSchema, type Manifest } from '@quad-education/schema';
|
|
3
|
+
import { type FileInfo } from '../contract/types.ts';
|
|
3
4
|
import type { OutboxEntry } from '../platform-types.ts';
|
|
4
5
|
import { type ClockState, type Method, type SessionInfo } from '../protocol.ts';
|
|
5
6
|
import { type RunRequest, type RunResult } from './runner.ts';
|
|
6
7
|
import { type App, type Ctx, type Kernel, type ResolvedRecipients, type StoredRun } from './state.ts';
|
|
8
|
+
import { type StoreChannel } from './memory-store.ts';
|
|
7
9
|
import type { AppStore, PlatformKind } from './store.ts';
|
|
8
10
|
export type EngineOptions = {
|
|
9
11
|
dataset: Dataset;
|
|
@@ -13,6 +15,11 @@ export type EngineOptions = {
|
|
|
13
15
|
dbName?: string;
|
|
14
16
|
/** Keep state here instead of in memory and IndexedDB (a school instance's data API, Phase 4). */
|
|
15
17
|
store?: AppStore;
|
|
18
|
+
/**
|
|
19
|
+
* How windows of one browser share what they store (D158), with `indexedDB`: a `BroadcastChannel`. Without
|
|
20
|
+
* one, each window keeps its own copy until it is reloaded.
|
|
21
|
+
*/
|
|
22
|
+
channel?: StoreChannel;
|
|
16
23
|
};
|
|
17
24
|
export declare class Engine implements Kernel {
|
|
18
25
|
private readonly apps;
|
|
@@ -94,6 +101,7 @@ export declare class Engine implements Kernel {
|
|
|
94
101
|
};
|
|
95
102
|
audit: number;
|
|
96
103
|
records: Record<string, Record<string, string>>;
|
|
104
|
+
files: string[];
|
|
97
105
|
}>;
|
|
98
106
|
/** Runs for the job log, newest first. */
|
|
99
107
|
runs(appId: string): Promise<StoredRun[]>;
|
|
@@ -178,13 +186,72 @@ export declare class Engine implements Kernel {
|
|
|
178
186
|
private checkWrite;
|
|
179
187
|
remember(ctx: Ctx, key: string, result: unknown): Promise<void>;
|
|
180
188
|
idempotencyKey(options: unknown, scope: string): string | undefined;
|
|
189
|
+
private readonly writeQueues;
|
|
190
|
+
/**
|
|
191
|
+
* Writes to one app run one after another, so a check and the write that follows it are never interleaved with
|
|
192
|
+
* another call's: of two bookings for the last slot started together, one sees the other.
|
|
193
|
+
*/
|
|
194
|
+
private queued;
|
|
195
|
+
/** One create, update or delete: a working copy of its own, committed when it has passed every check. */
|
|
196
|
+
private single;
|
|
197
|
+
/** Up to 25 writes, all stored or none (D150). Each is checked as it is on its own. */
|
|
198
|
+
private dbBatch;
|
|
199
|
+
/** D149: no other record of the entity holds the same values for any of its unique rules. */
|
|
200
|
+
private checkUnique;
|
|
201
|
+
/** D150: the write goes ahead only when the record's fields hold the values given; null means empty. */
|
|
202
|
+
private checkIf;
|
|
181
203
|
private dbCreate;
|
|
182
204
|
private dbUpdate;
|
|
183
205
|
private dbGet;
|
|
206
|
+
/**
|
|
207
|
+
* The records of an entity the caller may read, with what a query over them may use: the fields they can see,
|
|
208
|
+
* which of those are lists, and where a search looks (D153). Access comes first: filters, pages, counts and
|
|
209
|
+
* totals only ever cover readable records.
|
|
210
|
+
*/
|
|
211
|
+
private dbReadable;
|
|
212
|
+
/**
|
|
213
|
+
* D157: a stamp for each entity, different after any write to it, for a caller who may read the entity. It
|
|
214
|
+
* reads no records. An entity's stamp also moves with every table its rules look people up in (`listed:`),
|
|
215
|
+
* because a change there changes who may read what.
|
|
216
|
+
*/
|
|
217
|
+
private dbChanges;
|
|
218
|
+
/** D154: how many records match, of those the caller may read. */
|
|
219
|
+
private dbCount;
|
|
220
|
+
/** D154: the count, and totals of number fields, of the records the caller may read; by group when asked. */
|
|
221
|
+
private dbSummarise;
|
|
184
222
|
private dbList;
|
|
185
223
|
private resolveRef;
|
|
186
224
|
private dbDelete;
|
|
225
|
+
/** A file nobody attached within a day of its upload is gone, by the engine's clock. */
|
|
226
|
+
private fileExpired;
|
|
227
|
+
private filesUpload;
|
|
228
|
+
/**
|
|
229
|
+
* A file the caller may read, or NOT_FOUND whether it is missing or just not theirs. Unattached, it is its
|
|
230
|
+
* uploader's alone; attached, it follows the field of the record that holds it.
|
|
231
|
+
*/
|
|
232
|
+
private readableFile;
|
|
233
|
+
private filesRead;
|
|
234
|
+
/**
|
|
235
|
+
* What a write does to files: which to attach and which to remove. A file is attached once, by whoever uploaded
|
|
236
|
+
* it, to one field of one record; an id the record's field already holds stays as it is.
|
|
237
|
+
*/
|
|
238
|
+
private planFiles;
|
|
239
|
+
private applyFiles;
|
|
187
240
|
private notify;
|
|
241
|
+
/** D152: the files a notification names, each one the sender can read, within the limits. */
|
|
242
|
+
private attachmentsFor;
|
|
243
|
+
/**
|
|
244
|
+
* D152: a file never goes to a role its field is hidden from (`visibleTo`), and one at a staff-only level goes
|
|
245
|
+
* only to staff. The app declared both; a notification does not get round them.
|
|
246
|
+
*/
|
|
247
|
+
private checkAttachmentRoles;
|
|
248
|
+
/** D152: the copies a message carries, made as it is sent, so they outlast the records they came from. */
|
|
249
|
+
private copyAttachments;
|
|
250
|
+
/** A file a sent notification carries, for the shell's outbox and tests. Never part of the SDK. */
|
|
251
|
+
sentFile(appId: string, id: string): Promise<{
|
|
252
|
+
info: FileInfo;
|
|
253
|
+
bytes: Uint8Array;
|
|
254
|
+
} | undefined>;
|
|
188
255
|
private roleOf;
|
|
189
256
|
/**
|
|
190
257
|
* Resolves recipients to people, applying the app's roles and D17. Parents are only ever
|
|
@@ -197,4 +264,4 @@ export declare class Engine implements Kernel {
|
|
|
197
264
|
/** D19: one CIO-visible entry per call that returns pastoral or medical fields. */
|
|
198
265
|
private auditSensitiveRead;
|
|
199
266
|
}
|
|
200
|
-
export declare const ENGINE_SDK_VERSION = "0.
|
|
267
|
+
export declare const ENGINE_SDK_VERSION = "0.9.0";
|