@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.
Files changed (54) hide show
  1. package/README.md +2 -0
  2. package/dist/contract-tests/apps.d.ts +105 -0
  3. package/dist/contract-tests/apps.js +167 -0
  4. package/dist/contract-tests/harness.d.ts +11 -0
  5. package/dist/contract-tests/harness.js +40 -0
  6. package/dist/contract-tests/helpers.d.ts +5 -0
  7. package/dist/contract-tests/helpers.js +25 -0
  8. package/dist/contract-tests/index.d.ts +4 -2
  9. package/dist/contract-tests/index.js +3 -1
  10. package/dist/contract-tests/standalone-apps.d.ts +183 -0
  11. package/dist/contract-tests/standalone-apps.js +178 -0
  12. package/dist/contract-tests/standalone.d.ts +2 -0
  13. package/dist/contract-tests/standalone.js +709 -0
  14. package/dist/contract-tests/suite.d.ts +10 -3
  15. package/dist/contract-tests/suite.js +536 -44
  16. package/dist/src/client/connect.d.ts +13 -3
  17. package/dist/src/client/connect.js +21 -3
  18. package/dist/src/client/handshake-client.d.ts +2 -0
  19. package/dist/src/client/handshake-client.js +2 -0
  20. package/dist/src/client/http-transport.d.ts +18 -0
  21. package/dist/src/client/http-transport.js +76 -0
  22. package/dist/src/client/live.d.ts +39 -0
  23. package/dist/src/client/live.js +122 -0
  24. package/dist/src/contract/errors.d.ts +1 -1
  25. package/dist/src/contract/principals.d.ts +30 -0
  26. package/dist/src/contract/principals.js +12 -0
  27. package/dist/src/contract/recipients.d.ts +8 -2
  28. package/dist/src/contract/types.d.ts +18 -2
  29. package/dist/src/contract/types.js +1 -1
  30. package/dist/src/engine/audit.d.ts +2 -2
  31. package/dist/src/engine/audit.js +8 -6
  32. package/dist/src/engine/db-indexes.js +6 -1
  33. package/dist/src/engine/engine.d.ts +60 -22
  34. package/dist/src/engine/engine.js +281 -162
  35. package/dist/src/engine/host.d.ts +2 -2
  36. package/dist/src/engine/host.js +1 -1
  37. package/dist/src/engine/in-process.d.ts +2 -2
  38. package/dist/src/engine/index.d.ts +3 -1
  39. package/dist/src/engine/index.js +1 -0
  40. package/dist/src/engine/memory-store.d.ts +32 -0
  41. package/dist/src/engine/memory-store.js +123 -0
  42. package/dist/src/engine/runner.d.ts +2 -2
  43. package/dist/src/engine/runner.js +31 -26
  44. package/dist/src/engine/state.d.ts +21 -15
  45. package/dist/src/engine/state.js +31 -3
  46. package/dist/src/engine/store.d.ts +48 -0
  47. package/dist/src/engine/store.js +1 -0
  48. package/dist/src/engine/tasks.d.ts +4 -6
  49. package/dist/src/engine/tasks.js +27 -24
  50. package/dist/src/index.d.ts +1 -0
  51. package/dist/src/index.js +1 -0
  52. package/dist/src/jobs/define.d.ts +2 -2
  53. package/dist/src/platform-types.d.ts +2 -2
  54. package/package.json +4 -4
@@ -1,42 +1,67 @@
1
- import { type Dataset, type Principal } from '@quad-education/canonical';
1
+ import { type Dataset } from '@quad-education/canonical';
2
2
  import { type AppSchema, type Manifest } from '@quad-education/schema';
3
+ import { type AccountDirectory, type AccountRecord, type ActingAs } from '../contract/principals.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
- import type { App, Ctx, Kernel, ResolvedRecipients, StoredRun } from './state.ts';
7
- import { type PlatformKind } from './storage.ts';
7
+ import { type App, type Ctx, type Kernel, type ResolvedRecipients, type StoredRun } from './state.ts';
8
+ import type { AppStore, PlatformKind } from './store.ts';
8
9
  export type EngineOptions = {
9
- dataset: Dataset;
10
- indexedDB: IDBFactory;
10
+ /** The school. Absent, with `school: false`, for an engine that has none, like the data API (V2c). */
11
+ dataset?: Dataset;
12
+ /** Where in-browser state is kept; ignored when `store` is given. */
13
+ indexedDB?: IDBFactory;
14
+ /** Quad accounts a standalone app may notify and assign to, with their app roles (V2c, D100). */
15
+ accounts?: readonly AccountRecord[] | AccountDirectory;
16
+ /** False for an environment with no school: every school call is NOT_AVAILABLE (V2c, D100). */
17
+ school?: boolean;
11
18
  /** IndexedDB database name; defaults to `quad-engine`. */
12
19
  dbName?: string;
20
+ /** Keep state here instead of in memory and IndexedDB (the data API's DynamoDB store). */
21
+ store?: AppStore;
22
+ /** The timezone of an engine with no school; defaults to Australia/Sydney. */
23
+ timezone?: string;
13
24
  };
14
- /**
15
- * The in-browser implementation of the @quad-education/sdk contract (D15). It runs in the demo
16
- * shell's origin, holds the fictional school, and enforces visibility, scopes and D17 on
17
- * every call. Apps reach it only through a transport.
18
- */
19
25
  export declare class Engine implements Kernel {
20
26
  private readonly apps;
21
27
  private clock;
22
28
  private readonly byId;
23
29
  readonly dataset: Dataset;
24
- private readonly storage;
30
+ readonly store: AppStore;
31
+ private readonly zone;
32
+ private directory;
33
+ private readonly hasSchool;
25
34
  private constructor();
26
35
  static create(options: EngineOptions): Promise<Engine>;
27
36
  close(): void;
28
37
  /** Load an app, resetting its store if the schema changed since last time (D12). */
29
- installApp({ manifest, schema }: {
38
+ installApp({ manifest, schema, timezone, }: {
30
39
  manifest: unknown;
31
40
  schema: AppSchema;
41
+ timezone?: string;
32
42
  }): Promise<void>;
43
+ /**
44
+ * Register an app that is already installed in the store, without touching its state. A stateless server
45
+ * (the data API) does this on each cold start; `installApp` is for publishing and reinstalling.
46
+ */
47
+ attachApp({ manifest, schema, timezone, }: {
48
+ manifest: unknown;
49
+ schema: AppSchema;
50
+ timezone?: string;
51
+ }): void;
52
+ /** Whether an app is registered with this engine. */
53
+ hasApp(appId: string): boolean;
54
+ /** Replace the account directory (the shell rebuilds it when a previewed app's roles change). */
55
+ setAccounts(accounts: readonly AccountRecord[]): void;
56
+ /** Whether the app has no school here, so its people are accounts and guests (V2c, D100). */
57
+ isStandalone(appId: string): boolean;
33
58
  manifest(appId: string): Manifest;
34
59
  /** Clear an app's data and outbox (the shell's reset button). */
35
60
  resetApp(appId: string): Promise<void>;
36
61
  /** Open tasks assigned to a person: the shell's inbox (D6). */
37
- inbox(appId: string, personId: string): import("../index.ts").Task[];
62
+ inbox(appId: string, personId: string): Promise<import("../index.ts").Task[]>;
38
63
  /** Every audit entry, including CIO-only ones (the shell's audit viewer, D19). */
39
- auditLog(appId: string): {
64
+ auditLog(appId: string): Promise<{
40
65
  visibility: "app" | "cio";
41
66
  id: string;
42
67
  appId: string;
@@ -51,7 +76,7 @@ export declare class Engine implements Kernel {
51
76
  data?: {
52
77
  readonly [key: string]: import("../index.ts").JsonValue;
53
78
  };
54
- }[];
79
+ }[]>;
55
80
  /** Counts of everything a job can change, for run-twice tests (D20). */
56
81
  effectsSnapshot(appId: string): Promise<{
57
82
  outbox: number;
@@ -65,12 +90,12 @@ export declare class Engine implements Kernel {
65
90
  records: Record<string, Record<string, string>>;
66
91
  }>;
67
92
  /** Runs for the job log, newest first. */
68
- runs(appId: string): StoredRun[];
93
+ runs(appId: string): Promise<StoredRun[]>;
69
94
  /**
70
95
  * Who a call from the jobs host acts as: the principal of the run it belongs to (D7).
71
96
  * Only runs that are currently running count, so a finished run's id can't be replayed.
72
97
  */
73
- runPrincipal(appId: string, runId: string | undefined): Principal;
98
+ runPrincipal(appId: string, runId: string | undefined): Promise<ActingAs>;
74
99
  /** Start due runs; the caller executes each as its `runAs` principal and calls finishRun. */
75
100
  startDueRuns(appId: string): Promise<RunRequest[]>;
76
101
  finishRun(appId: string, runId: string, result: RunResult): Promise<void>;
@@ -78,7 +103,7 @@ export declare class Engine implements Kernel {
78
103
  redeliverRun(appId: string, runId: string): Promise<void>;
79
104
  /** Move the demo clock forward (D14). Works whether it's frozen or running. */
80
105
  advanceClock(ms: number): void;
81
- timezone(): string;
106
+ timezone(app?: App): string;
82
107
  persistPlatform(app: App, kind: PlatformKind, items: readonly {
83
108
  id: string;
84
109
  }[]): Promise<void>;
@@ -93,8 +118,10 @@ export declare class Engine implements Kernel {
93
118
  nowMs(): number;
94
119
  sessionInfo(appId: string): SessionInfo;
95
120
  /** Handle one SDK call from `appId` on behalf of `principal`. */
96
- handle(appId: string, principal: Principal, method: Method, params: unknown): Promise<unknown>;
121
+ handle(appId: string, principal: ActingAs, method: Method, params: unknown): Promise<unknown>;
97
122
  private appFor;
123
+ /** A school app, in an environment that has a school: standalone apps and school-less environments have none. */
124
+ private usesSchool;
98
125
  private context;
99
126
  private me;
100
127
  private schoolInfo;
@@ -106,6 +133,13 @@ export declare class Engine implements Kernel {
106
133
  private tiers;
107
134
  private allowedFields;
108
135
  private visible;
136
+ /**
137
+ * The records a read may start from. A windowed entity (the register, V2s S4.2) is never built whole: the
138
+ * dataset makes only the slice the where clause names, for only the students the reader may see, and
139
+ * visibility, fields and the rest of the where clause apply to that slice as to any other. A dataset with no
140
+ * way to select (one wrapped with a custom registry) falls back to building everything.
141
+ */
142
+ private visibleFor;
109
143
  private shape;
110
144
  private schoolGet;
111
145
  private schoolList;
@@ -133,7 +167,6 @@ export declare class Engine implements Kernel {
133
167
  private checkWrite;
134
168
  remember(ctx: Ctx, key: string, result: unknown): Promise<void>;
135
169
  idempotencyKey(options: unknown, scope: string): string | undefined;
136
- private persist;
137
170
  private dbCreate;
138
171
  private dbUpdate;
139
172
  private dbGet;
@@ -146,11 +179,16 @@ export declare class Engine implements Kernel {
146
179
  * Resolves recipients to people, applying the app's roles and D17. Parents are only ever
147
180
  * reached about a specific student, and only through an eligible, unrestricted link.
148
181
  */
149
- resolveRecipients(ctx: Ctx, to: unknown, regarding: string | undefined): ResolvedRecipients;
182
+ resolveRecipients(ctx: Ctx, to: unknown, regarding: string | undefined): Promise<ResolvedRecipients>;
183
+ /**
184
+ * Recipients outside a school (V2c, D100): Quad accounts, by id or by one of the app's own roles, from the
185
+ * account directory. Everything that needs a school is NOT_AVAILABLE. Guests have no address, so never appear.
186
+ */
187
+ private resolveAppRecipients;
150
188
  private suppressionReason;
151
189
  /** D17/D19: each suppressed parent is recorded, visible only to the CIO view. */
152
190
  private auditSuppressed;
153
191
  /** D19: one CIO-visible entry per call that returns pastoral or medical fields. */
154
192
  private auditSensitiveRead;
155
193
  }
156
- export declare const ENGINE_SDK_VERSION = "0.1.3";
194
+ export declare const ENGINE_SDK_VERSION = "0.2.0";