@superpanel-sdk/runtime 0.2.3 → 0.5.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 +28 -8
- package/dist/builder/codegen/emit.d.ts +29 -11
- package/dist/builder/codegen/emit.js +328 -61
- package/dist/builder/codegen/generate.d.ts +21 -0
- package/dist/builder/codegen/generate.js +152 -20
- package/dist/builder/company-import-graph.d.ts +2 -0
- package/dist/builder/company-import-graph.js +40 -8
- package/dist/builder/company-imports.d.ts +24 -0
- package/dist/builder/company-imports.js +114 -0
- package/dist/builder/compile/compile-sequence.d.ts +59 -8
- package/dist/builder/compile/compile-sequence.js +279 -77
- package/dist/builder/compile/function-code.d.ts +12 -2
- package/dist/builder/compile/function-code.js +87 -39
- package/dist/builder/compile/registry.d.ts +7 -3
- package/dist/builder/compile/registry.js +24 -23
- package/dist/builder/load.d.ts +70 -10
- package/dist/builder/load.js +250 -61
- package/dist/builder/paths.d.ts +3 -0
- package/dist/builder/paths.js +16 -0
- package/dist/builder/schedules.d.ts +23 -0
- package/dist/builder/schedules.js +102 -0
- package/dist/builder/slot-schema-validation.d.ts +4 -0
- package/dist/builder/slot-schema-validation.js +10 -0
- package/dist/builder/typecheck.d.ts +8 -0
- package/dist/builder/typecheck.js +105 -0
- package/dist/builder/types.d.ts +91 -19
- package/dist/builder/types.js +2 -1
- package/dist/cli/auth/auth.d.ts +37 -0
- package/dist/cli/auth/auth.js +211 -0
- package/dist/cli/auth/backend-url.d.ts +5 -0
- package/dist/cli/auth/backend-url.js +25 -0
- package/dist/cli/auth/clipboard.d.ts +9 -0
- package/dist/cli/auth/clipboard.js +38 -0
- package/dist/cli/auth/http.d.ts +20 -0
- package/dist/cli/auth/http.js +27 -0
- package/dist/cli/auth/index.d.ts +10 -0
- package/dist/cli/auth/index.js +27 -0
- package/dist/cli/auth/progress.d.ts +12 -0
- package/dist/cli/auth/progress.js +15 -0
- package/dist/cli/auth/serve-login.d.ts +8 -0
- package/dist/cli/auth/serve-login.js +24 -0
- package/dist/cli/compile/index.js +3 -0
- package/dist/cli/config.d.ts +10 -0
- package/dist/cli/config.js +52 -0
- package/dist/cli/index.js +28 -8
- package/dist/cli/serve/index.d.ts +73 -3
- package/dist/cli/serve/index.js +365 -116
- package/dist/cli/type-gen/index.js +9 -8
- package/dist/compiler.d.ts +7 -0
- package/dist/compiler.js +7 -0
- package/dist/compute-host/compute-host.d.ts +15 -23
- package/dist/compute-host/compute-host.js +25 -28
- package/dist/compute-host/index.d.ts +2 -4
- package/dist/compute-host/index.js +1 -2
- package/dist/compute-host/source-compute-host.d.ts +11 -9
- package/dist/compute-host/source-compute-host.js +46 -32
- package/dist/core/case-orchestrator/contact-hours.d.ts +50 -0
- package/dist/core/case-orchestrator/contact-hours.js +108 -0
- package/dist/core/case-orchestrator/follow-ups.d.ts +31 -0
- package/dist/core/case-orchestrator/follow-ups.js +103 -0
- package/dist/core/case-orchestrator/index.d.ts +6 -0
- package/dist/core/case-orchestrator/index.js +6 -0
- package/dist/core/case-orchestrator/render.d.ts +75 -0
- package/dist/core/case-orchestrator/render.js +239 -0
- package/dist/core/case-orchestrator/time.d.ts +11 -0
- package/dist/core/case-orchestrator/time.js +29 -0
- package/dist/core/case-orchestrator/tools.d.ts +29 -0
- package/dist/core/case-orchestrator/tools.js +31 -0
- package/dist/core/case-orchestrator/types.d.ts +753 -0
- package/dist/core/case-orchestrator/types.js +46 -0
- package/dist/core/case-orchestrator/validate.d.ts +11 -0
- package/dist/core/case-orchestrator/validate.js +63 -0
- package/dist/core/context/call.d.ts +291 -0
- package/dist/core/context/call.js +94 -0
- package/dist/core/context/channels.d.ts +60 -0
- package/dist/core/context/channels.js +35 -0
- package/dist/core/context/contact.d.ts +96 -6
- package/dist/core/context/contact.js +48 -2
- package/dist/core/context/email-message.d.ts +159 -0
- package/dist/core/context/email-message.js +59 -0
- package/dist/core/context/email.d.ts +97 -0
- package/dist/core/context/email.js +91 -0
- package/dist/core/context/exchanges.d.ts +142 -0
- package/dist/core/context/exchanges.js +63 -0
- package/dist/core/context/instances.d.ts +278 -0
- package/dist/core/context/instances.js +123 -0
- package/dist/core/context/kv.d.ts +113 -0
- package/dist/core/context/kv.js +60 -0
- package/dist/core/context/platform-registry.d.ts +509 -4
- package/dist/core/context/platform-registry.js +14 -2
- package/dist/core/context/platform.d.ts +2 -1
- package/dist/core/context/sms.d.ts +147 -0
- package/dist/core/context/sms.js +57 -0
- package/dist/core/context/types.d.ts +51 -48
- package/dist/core/context/types.js +1 -7
- package/dist/core/conversation/index.d.ts +31 -0
- package/dist/core/conversation/index.js +14 -0
- package/dist/core/functions/define/bind.d.ts +25 -0
- package/dist/core/functions/define/bind.js +14 -0
- package/dist/core/functions/define/case.d.ts +9 -0
- package/dist/core/functions/define/case.js +13 -0
- package/dist/core/functions/define/events.d.ts +20 -0
- package/dist/core/functions/define/events.js +21 -0
- package/dist/core/functions/define/no-case.d.ts +4 -0
- package/dist/core/functions/define/no-case.js +9 -0
- package/dist/core/functions/events.d.ts +247 -0
- package/dist/core/functions/events.js +32 -0
- package/dist/core/functions/func-ref.d.ts +11 -2
- package/dist/core/functions/schedules.d.ts +51 -0
- package/dist/core/functions/schedules.js +20 -0
- package/dist/core/functions/types.d.ts +62 -51
- package/dist/core/functions/types.js +6 -1
- package/dist/core/office-hours/index.d.ts +39 -0
- package/dist/core/office-hours/index.js +187 -0
- package/dist/core/page/define.d.ts +834 -0
- package/dist/core/page/define.js +477 -0
- package/dist/core/page/ops.d.ts +58 -0
- package/dist/core/page/ops.js +220 -0
- package/dist/core/page/render.d.ts +253 -0
- package/dist/core/page/render.js +840 -0
- package/dist/core/page/time-format.d.ts +19 -0
- package/dist/core/page/time-format.js +41 -0
- package/dist/core/page/timeline.d.ts +40 -0
- package/dist/core/page/timeline.js +2 -0
- package/dist/core/page/typed.d.ts +642 -0
- package/dist/core/page/typed.js +2 -0
- package/dist/core/page/workspace.d.ts +33 -0
- package/dist/core/page/workspace.js +231 -0
- package/dist/core/party/index.d.ts +3 -0
- package/dist/core/party/index.js +3 -0
- package/dist/core/party/schema.d.ts +137 -0
- package/dist/core/party/schema.js +80 -0
- package/dist/core/party/types.d.ts +40 -0
- package/dist/core/party/types.js +15 -0
- package/dist/core/sequence/define.d.ts +57 -0
- package/dist/core/sequence/define.js +10 -0
- package/dist/core/sequence/index.d.ts +63 -0
- package/dist/core/sequence/index.js +231 -0
- package/dist/core/slot/binding.d.ts +40 -0
- package/dist/core/slot/binding.js +2 -0
- package/dist/core/slot/company-metadata.d.ts +113 -0
- package/dist/core/slot/company-metadata.js +563 -0
- package/dist/core/slot/compile-schema.d.ts +19 -13
- package/dist/core/slot/compile-schema.js +51 -248
- package/dist/core/slot/contact-timezone.d.ts +110 -0
- package/dist/core/slot/contact-timezone.js +186 -0
- package/dist/core/slot/field.d.ts +2 -24
- package/dist/core/slot/field.js +0 -69
- package/dist/core/slot/id-ref.d.ts +17 -2
- package/dist/core/slot/id-ref.js +16 -8
- package/dist/core/slot/index.d.ts +12 -13
- package/dist/core/slot/index.js +11 -12
- package/dist/core/slot/naming.d.ts +15 -0
- package/dist/core/slot/naming.js +96 -0
- package/dist/core/slot/platform-fields.d.ts +119 -0
- package/dist/core/slot/platform-fields.js +121 -0
- package/dist/core/slot/ref.d.ts +16 -0
- package/dist/core/slot/ref.js +14 -0
- package/dist/core/slot/row.d.ts +2 -9
- package/dist/core/slot/row.js +13 -23
- package/dist/core/slot/schema-compat.d.ts +16 -0
- package/dist/core/slot/schema-compat.js +112 -0
- package/dist/core/slot/schema.d.ts +409 -76
- package/dist/core/slot/schema.js +178 -10
- package/dist/core/slot/types.d.ts +27 -94
- package/dist/core/slot/value.d.ts +26 -3
- package/dist/core/slot/value.js +89 -57
- package/dist/dev-overlay/protocol.d.ts +41 -8
- package/dist/fn-context/build-context.d.ts +3 -1
- package/dist/fn-context/build-context.js +20 -10
- package/dist/fn-context/fake/empty-api.js +9 -28
- package/dist/fn-context/fake/index.d.ts +11 -4
- package/dist/fn-context/fake/index.js +27 -2
- package/dist/fn-context/fn-params.d.ts +6 -0
- package/dist/fn-context/fn-params.js +13 -0
- package/dist/fn-context/index.d.ts +5 -5
- package/dist/fn-context/index.js +4 -4
- package/dist/fn-context/log.js +2 -2
- package/dist/fn-context/make-ctx.d.ts +11 -0
- package/dist/fn-context/make-ctx.js +18 -8
- package/dist/fn-context/rpc/case-orchestrator-tools.d.ts +24 -0
- package/dist/fn-context/rpc/case-orchestrator-tools.js +13 -0
- package/dist/fn-context/rpc/index.d.ts +3 -1
- package/dist/fn-context/rpc/index.js +3 -1
- package/dist/fn-context/rpc/integration/index.d.ts +4 -4
- package/dist/fn-context/rpc/integration/index.js +1 -1
- package/dist/fn-context/rpc/integration/list-surfaces.d.ts +21 -0
- package/dist/fn-context/rpc/integration/{list-bindings.js → list-surfaces.js} +4 -4
- package/dist/fn-context/rpc/platform.d.ts +2 -2
- package/dist/fn-context/rpc/platform.js +1 -1
- package/dist/fn-context/rpc/records.d.ts +78 -0
- package/dist/fn-context/rpc/records.js +26 -0
- package/dist/fn-context/rpc/trpc-client.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-client.js +88 -7
- package/dist/fn-context/rpc/trpc-init.d.ts +2 -2
- package/dist/fn-context/rpc/trpc-router-factory.d.ts +49 -3
- package/dist/fn-context/rpc/trpc-router-factory.js +2 -0
- package/dist/fn-context/run-scope.d.ts +4 -0
- package/dist/fn-context/run-scope.js +9 -0
- package/dist/fn-context/types.d.ts +36 -3
- package/dist/index.d.ts +37 -46
- package/dist/index.js +33 -33
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +41 -0
- package/dist/platform.d.ts +76 -0
- package/dist/platform.js +56 -0
- package/dist/voice-service/actions.d.ts +71 -4
- package/dist/voice-service/types.d.ts +42 -5
- package/dist/worker.d.ts +10 -0
- package/dist/worker.js +10 -0
- package/package.json +38 -19
- package/dist/builder/compile/compile-agenda.d.ts +0 -15
- package/dist/builder/compile/compile-agenda.js +0 -64
- package/dist/builder/merge.d.ts +0 -4
- package/dist/builder/merge.js +0 -19
- package/dist/compute-host/read-only-cache.d.ts +0 -20
- package/dist/compute-host/read-only-cache.js +0 -61
- package/dist/core/context/db.d.ts +0 -69
- package/dist/core/context/db.js +0 -44
- package/dist/core/context/docusign.d.ts +0 -134
- package/dist/core/context/docusign.js +0 -108
- package/dist/core/context/filevine.d.ts +0 -323
- package/dist/core/context/filevine.js +0 -254
- package/dist/core/context/http.d.ts +0 -9
- package/dist/core/context/http.js +0 -4
- package/dist/core/context/hubspot.d.ts +0 -250
- package/dist/core/context/hubspot.js +0 -191
- package/dist/core/context/twilio.d.ts +0 -50
- package/dist/core/context/twilio.js +0 -42
- package/dist/core/functions/define/case-context.d.ts +0 -14
- package/dist/core/functions/define/case-context.js +0 -15
- package/dist/core/functions/define/compute.d.ts +0 -7
- package/dist/core/functions/define/compute.js +0 -17
- package/dist/core/functions/define/custom.d.ts +0 -4
- package/dist/core/functions/define/custom.js +0 -8
- package/dist/core/functions/define/system.d.ts +0 -7
- package/dist/core/functions/define/system.js +0 -12
- package/dist/core/slot/deps.d.ts +0 -15
- package/dist/core/slot/deps.js +0 -88
- package/dist/core/slot/derived.d.ts +0 -32
- package/dist/core/slot/derived.js +0 -115
- package/dist/core/slot/platform-session-fields.d.ts +0 -38
- package/dist/core/slot/platform-session-fields.js +0 -48
- package/dist/core/slot/sf-schema.d.ts +0 -23
- package/dist/core/slot/sf-schema.js +0 -125
- package/dist/core/slot/sf-validate.d.ts +0 -14
- package/dist/core/slot/sf-validate.js +0 -132
- package/dist/core/slot/snapshot.d.ts +0 -18
- package/dist/core/slot/snapshot.js +0 -138
- package/dist/core/slot/write.d.ts +0 -48
- package/dist/core/slot/write.js +0 -426
- package/dist/core/stage/builders.d.ts +0 -54
- package/dist/core/stage/builders.js +0 -31
- package/dist/core/stage/condition.d.ts +0 -17
- package/dist/core/stage/condition.js +0 -198
- package/dist/core/stage/drive.d.ts +0 -43
- package/dist/core/stage/drive.js +0 -78
- package/dist/core/stage/finish-when.d.ts +0 -20
- package/dist/core/stage/finish-when.js +0 -82
- package/dist/core/stage/flatten.d.ts +0 -27
- package/dist/core/stage/flatten.js +0 -466
- package/dist/core/stage/index.d.ts +0 -15
- package/dist/core/stage/index.js +0 -13
- package/dist/core/stage/interrupts.d.ts +0 -28
- package/dist/core/stage/interrupts.js +0 -120
- package/dist/core/stage/ivr-fields.d.ts +0 -9
- package/dist/core/stage/ivr-fields.js +0 -75
- package/dist/core/stage/simulate.d.ts +0 -24
- package/dist/core/stage/simulate.js +0 -33
- package/dist/core/stage/transfer-fields.d.ts +0 -19
- package/dist/core/stage/transfer-fields.js +0 -129
- package/dist/core/stage/transfer-spec.d.ts +0 -48
- package/dist/core/stage/transfer-spec.js +0 -113
- package/dist/core/stage/types.d.ts +0 -208
- package/dist/core/stage/types.js +0 -2
- package/dist/core/stage/validate.d.ts +0 -11
- package/dist/core/stage/validate.js +0 -330
- package/dist/core/stage/walk.d.ts +0 -39
- package/dist/core/stage/walk.js +0 -119
- package/dist/fn-context/rpc/integration/list-bindings.d.ts +0 -21
- package/dist/fn-context/system-args.d.ts +0 -6
- package/dist/fn-context/system-args.js +0 -14
|
@@ -0,0 +1,642 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page module's types bound to one sequence (15 §10.15): what `__gen/index.ts` exports as
|
|
3
|
+
* `definePage`, `field`, `schemaField`, `createRow`, `deleteRow` and `defineAction`. Behaviour is
|
|
4
|
+
* `define.ts`'s; this file only types it.
|
|
5
|
+
*
|
|
6
|
+
* Everything starts from `PageTables`, generated per sequence into `__gen/slots.type.ts`: for each
|
|
7
|
+
* table, each field's value type, and for a ref field the table it points at (`ref`) and whether it
|
|
8
|
+
* is the parent (`parent`). From it:
|
|
9
|
+
*
|
|
10
|
+
* - a row read with `db` has `id: Id<'table'>`, `createdAt` / `updatedAt` (ISO 8601, the platform's)
|
|
11
|
+
* and one slot per field, its value typed by the schema; a lookup `include`d carries the target row
|
|
12
|
+
* in `.row`, a way back (`relatedName`) its rows as a list under its name;
|
|
13
|
+
* - `db.<table>`'s reads take only that table's fields and row times, a `where` starting at its top
|
|
14
|
+
* level from `id`, a ref field (15 §10.15 point 4), a field or a row time (the field index,
|
|
15
|
+
* 18-record-search-index §4.6), `include` of lookups and ways back only, `some` / `every` / `none` on
|
|
16
|
+
* a way back (13-data-model-v1 §23.4);
|
|
17
|
+
* - an action's arguments come from its `parameters`; `db.<table>`'s writes take only that table's fields;
|
|
18
|
+
* - the page is the conversation's: code (functions, event handlers, the Orchestrator) gets the case
|
|
19
|
+
* (`CaseInput`) and reads with `ctx.api.db`.
|
|
20
|
+
*/
|
|
21
|
+
import type { PageTime, ChooseParam, CreateRowAction, CustomAction, DeleteRowAction, FieldCell, FieldOptions, RefFieldCell, RefOption, MessageAction, MessageOptions, PageBaseContext, PageChannel, PageChannelCaps, PageConversation, PageFaq, PageFaqEntry, PageHistory, PagePersona, PageRuns, PageScheduledAction, Placeable, SchemaFieldOptions, SlotState } from './define.js';
|
|
22
|
+
declare const ID_BRAND: unique symbol;
|
|
23
|
+
/** A row id of table `T`: an `Id<'injuries'>` is not an `Id<'providers'>`, and no string is an id. */
|
|
24
|
+
export type Id<T extends string = string> = string & {
|
|
25
|
+
readonly [ID_BRAND]: T;
|
|
26
|
+
};
|
|
27
|
+
/** One field, as `__gen/slots.type.ts` describes it. */
|
|
28
|
+
export type PageFieldDesc = {
|
|
29
|
+
value: unknown;
|
|
30
|
+
ref?: string;
|
|
31
|
+
parent?: true;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A table's ways back (`$relations`, 13-data-model-v1 §23.4 items 3–4): for each `relatedName`, the
|
|
35
|
+
* table whose rows point at this one and the ref field they point with.
|
|
36
|
+
*/
|
|
37
|
+
export type PageRelationsDesc = {
|
|
38
|
+
[name: string]: {
|
|
39
|
+
table: string;
|
|
40
|
+
field: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A sequence's tables (`PageTables` in `__gen/slots.type.ts`): table → field → description, and its
|
|
45
|
+
* ways back under `$relations` (no field name starts with `$`).
|
|
46
|
+
*/
|
|
47
|
+
export type PageTablesDesc = {
|
|
48
|
+
[table: string]: {
|
|
49
|
+
[field: string]: PageFieldDesc | PageRelationsDesc;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
type TableOf<D> = Extract<keyof D, string>;
|
|
53
|
+
type FieldOf<D, T extends keyof D> = Exclude<Extract<keyof D[T], string>, '$relations'>;
|
|
54
|
+
/** The ways back to a table, by name; none when it has no `$relations`. */
|
|
55
|
+
type RelationsOf<D, T extends keyof D> = D[T] extends {
|
|
56
|
+
$relations: infer R;
|
|
57
|
+
} ? R : {};
|
|
58
|
+
type RelationOf<D, T extends keyof D> = Extract<keyof RelationsOf<D, T>, string>;
|
|
59
|
+
/** The table whose rows a way back lists. */
|
|
60
|
+
type RelationTable<D, T extends keyof D, K> = K extends keyof RelationsOf<D, T> ? RelationsOf<D, T>[K] extends {
|
|
61
|
+
table: infer R extends string;
|
|
62
|
+
} ? R & keyof D : never : never;
|
|
63
|
+
type Desc<D, T extends keyof D, F> = F extends keyof D[T] ? (D[T][F] extends PageFieldDesc ? D[T][F] : never) : never;
|
|
64
|
+
/** The table a ref field points at; never for a plain field. */
|
|
65
|
+
type RefTable<D, T extends keyof D, F> = Desc<D, T, F> extends {
|
|
66
|
+
ref: infer R extends string;
|
|
67
|
+
} ? R : never;
|
|
68
|
+
/** Lookup fields (refs that are not the parent): what `include` follows. */
|
|
69
|
+
type LookupOf<D, T extends keyof D> = {
|
|
70
|
+
[F in FieldOf<D, T>]: Desc<D, T, F> extends {
|
|
71
|
+
ref: string;
|
|
72
|
+
} ? (Desc<D, T, F> extends {
|
|
73
|
+
parent: true;
|
|
74
|
+
} ? never : F) : never;
|
|
75
|
+
}[FieldOf<D, T>];
|
|
76
|
+
/** Ref fields, parent included: what anchors a `where`. */
|
|
77
|
+
type RefFieldOf<D, T extends keyof D> = {
|
|
78
|
+
[F in FieldOf<D, T>]: Desc<D, T, F> extends {
|
|
79
|
+
ref: string;
|
|
80
|
+
} ? F : never;
|
|
81
|
+
}[FieldOf<D, T>];
|
|
82
|
+
/** Fields that are not refs: a condition on one starts a `where` through the field index. */
|
|
83
|
+
type PlainFieldOf<D, T extends keyof D> = Exclude<FieldOf<D, T>, RefFieldOf<D, T>>;
|
|
84
|
+
/** A row's times, the platform's (ISO 8601): when it was created, when it was last written. */
|
|
85
|
+
type RowTime = 'createdAt' | 'updatedAt';
|
|
86
|
+
type ParentOf<D, T extends keyof D> = {
|
|
87
|
+
[F in FieldOf<D, T>]: Desc<D, T, F> extends {
|
|
88
|
+
parent: true;
|
|
89
|
+
} ? F : never;
|
|
90
|
+
}[FieldOf<D, T>];
|
|
91
|
+
/** A field's value: a ref holds the id of a row of its table. */
|
|
92
|
+
type ValueOf<D, T extends keyof D, F> = Desc<D, T, F> extends {
|
|
93
|
+
ref: infer R extends string;
|
|
94
|
+
} ? Id<R> : Desc<D, T, F>['value'];
|
|
95
|
+
type Simplify<X> = {
|
|
96
|
+
[K in keyof X]: X[K];
|
|
97
|
+
} & {};
|
|
98
|
+
/** One field as read (15 §10.4): plain data. Judge with `.value` / `.state`. */
|
|
99
|
+
export type TypedSlot<V, T extends string, F extends string> = Readonly<{
|
|
100
|
+
value: V | null;
|
|
101
|
+
state: SlotState;
|
|
102
|
+
reason: string | null;
|
|
103
|
+
updatedAt: string | null;
|
|
104
|
+
ref: Readonly<{
|
|
105
|
+
table: T;
|
|
106
|
+
id: Id<T>;
|
|
107
|
+
field: F;
|
|
108
|
+
}>;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* What `include` takes, at most 3 levels: lookup fields, `true` or a nested `{ include }`; ways back,
|
|
112
|
+
* `true` or the rows to list (`where`, `orderBy`, `skip`, `take`) and a nested `{ include }`.
|
|
113
|
+
*/
|
|
114
|
+
export type IncludeArg<D, T extends keyof D, Depth extends unknown[] = []> = Depth['length'] extends 3 ? never : {
|
|
115
|
+
[F in LookupOf<D, T>]?: boolean | {
|
|
116
|
+
include?: IncludeArg<D, RefTable<D, T, F> & keyof D, [...Depth, unknown]>;
|
|
117
|
+
};
|
|
118
|
+
} & {
|
|
119
|
+
[K in RelationOf<D, T>]?: boolean | RelationInclude<D, RelationTable<D, T, K>, [...Depth, unknown]>;
|
|
120
|
+
};
|
|
121
|
+
/** The rows of a way back an `include` lists: filtered, ordered and paged like `findMany`. */
|
|
122
|
+
type RelationInclude<D, R extends keyof D, Depth extends unknown[]> = {
|
|
123
|
+
where?: WhereFields<D, R, true>;
|
|
124
|
+
orderBy?: OrderByArg<D, R>;
|
|
125
|
+
skip?: number;
|
|
126
|
+
take?: number;
|
|
127
|
+
include?: IncludeArg<D, R, Depth>;
|
|
128
|
+
};
|
|
129
|
+
/** What `select` takes: the fields to keep (`id` always comes). */
|
|
130
|
+
export type SelectArg<D, T extends keyof D> = {
|
|
131
|
+
[F in FieldOf<D, T>]?: boolean;
|
|
132
|
+
};
|
|
133
|
+
type IncludedRow<D, R extends keyof D, Spec> = [Spec] extends [{
|
|
134
|
+
include: infer I;
|
|
135
|
+
}] ? RowOf<D, R, I> : RowOf<D, R, undefined>;
|
|
136
|
+
/**
|
|
137
|
+
* The `.row` an `include` gives: there for sure on `true` or `{ include }`, not there on `false`, and
|
|
138
|
+
* maybe there on a `boolean` decided at run time (`include: { provider: flag }`).
|
|
139
|
+
*/
|
|
140
|
+
type IncludedSlot<D, T extends keyof D & string, F extends string, Spec> = [Spec] extends [false | undefined] ? unknown : [Spec] extends [true | {
|
|
141
|
+
include?: unknown;
|
|
142
|
+
}] ? Readonly<{
|
|
143
|
+
row: IncludedRow<D, RefTable<D, T, F> & keyof D, Spec> | null;
|
|
144
|
+
}> : Readonly<{
|
|
145
|
+
row?: IncludedRow<D, RefTable<D, T, F> & keyof D, Exclude<Spec, boolean | undefined>> | null;
|
|
146
|
+
}>;
|
|
147
|
+
/** What `include` says of `F`; with `undefined` in it when the whole `include` may be absent this time. */
|
|
148
|
+
type IncludeSpec<Inc, F extends string> = F extends keyof NonNullable<Inc> ? NonNullable<Inc>[F] | (undefined extends Inc ? undefined : never) : undefined;
|
|
149
|
+
type SlotFor<D, T extends keyof D & string, F extends string, Inc> = TypedSlot<ValueOf<D, T, F>, T, F> & IncludedSlot<D, T, F, IncludeSpec<Inc, F>>;
|
|
150
|
+
/** Whether a `select` is given for sure (not `undefined`, nor maybe `undefined`). */
|
|
151
|
+
type NoSelect<Sel> = [Sel] extends [undefined] ? true : unknown extends Sel ? true : false;
|
|
152
|
+
/** Fields there for sure: every field without a `select`, else those selected with `true`. */
|
|
153
|
+
type SureFields<D, T extends keyof D, Sel> = NoSelect<Sel> extends true ? FieldOf<D, T> : {
|
|
154
|
+
[F in keyof NonNullable<Sel>]-?: [NonNullable<Sel>[F]] extends [true] ? F : never;
|
|
155
|
+
}[keyof NonNullable<Sel>] & FieldOf<D, T>;
|
|
156
|
+
/**
|
|
157
|
+
* Fields that may be there: with a `select` that may be absent this time, every other field; with a
|
|
158
|
+
* field selected by a `boolean` decided at run time, that field.
|
|
159
|
+
*/
|
|
160
|
+
type MaybeFields<D, T extends keyof D, Sel> = NoSelect<Sel> extends true ? never : undefined extends Sel ? Exclude<FieldOf<D, T>, SureFields<D, T, Sel>> : Exclude<{
|
|
161
|
+
[F in keyof NonNullable<Sel>]-?: true extends NonNullable<Sel>[F] ? F : never;
|
|
162
|
+
}[keyof NonNullable<Sel>] & FieldOf<D, T>, SureFields<D, T, Sel>>;
|
|
163
|
+
/**
|
|
164
|
+
* The ways back an `include` lists: there for sure on `true` or `{ … }`, not there on `false`, maybe
|
|
165
|
+
* there on a `boolean` decided at run time.
|
|
166
|
+
*/
|
|
167
|
+
type RelationRows<D, T extends keyof D, Inc> = {
|
|
168
|
+
readonly [K in RelationOf<D, T> as [IncludeSpec<Inc, K>] extends [true | object] ? K : never]: ReadonlyArray<IncludedRow<D, RelationTable<D, T, K>, IncludeSpec<Inc, K>>>;
|
|
169
|
+
} & {
|
|
170
|
+
readonly [K in RelationOf<D, T> as [IncludeSpec<Inc, K>] extends [false | undefined] ? never : [IncludeSpec<Inc, K>] extends [true | object] ? never : K]?: ReadonlyArray<IncludedRow<D, RelationTable<D, T, K>, Exclude<IncludeSpec<Inc, K>, boolean | undefined>>>;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* The platform's part of a row: its id, and (a stored row, not the session) when it was created and
|
|
174
|
+
* last written, ISO 8601.
|
|
175
|
+
*/
|
|
176
|
+
type RowSystem<T> = Readonly<{
|
|
177
|
+
id: Id<T & string>;
|
|
178
|
+
}> & (T extends 'session' ? unknown : Readonly<{
|
|
179
|
+
createdAt: string;
|
|
180
|
+
updatedAt: string;
|
|
181
|
+
}>);
|
|
182
|
+
/** A row as `db` returns it: `id`, its times, one slot per field, and the ways back it `include`s. */
|
|
183
|
+
export type RowOf<D, T extends keyof D, Inc = undefined, Sel = undefined> = RowSystem<T> & {
|
|
184
|
+
readonly [F in SureFields<D, T, Sel>]: SlotFor<D, T & string, F, Inc>;
|
|
185
|
+
} & {
|
|
186
|
+
readonly [F in MaybeFields<D, T, Sel>]?: SlotFor<D, T & string, F, Inc>;
|
|
187
|
+
} & RelationRows<D, T, Inc>;
|
|
188
|
+
type Ord = 'asc' | 'desc';
|
|
189
|
+
type OrderByArg<D, T extends keyof D> = {
|
|
190
|
+
[F in FieldOf<D, T> | RowTime]?: Ord;
|
|
191
|
+
} | ReadonlyArray<{
|
|
192
|
+
[F in FieldOf<D, T> | RowTime]?: Ord;
|
|
193
|
+
}>;
|
|
194
|
+
/** A `multi_select`'s filter (27 §3.2): Prisma's scalar-list filters, plus the slot's state. */
|
|
195
|
+
type ListValueFilter<V extends readonly unknown[]> = V | null | {
|
|
196
|
+
equals?: V | null;
|
|
197
|
+
has?: V[number];
|
|
198
|
+
hasSome?: readonly V[number][];
|
|
199
|
+
hasEvery?: readonly V[number][];
|
|
200
|
+
isEmpty?: boolean;
|
|
201
|
+
state?: SlotState;
|
|
202
|
+
};
|
|
203
|
+
type ScalarFilter<V> = [V] extends [readonly unknown[]] ? ListValueFilter<V> : ScalarFilterOf<V>;
|
|
204
|
+
type ScalarFilterOf<V> = V | null | {
|
|
205
|
+
equals?: V | null;
|
|
206
|
+
in?: readonly V[];
|
|
207
|
+
notIn?: readonly V[];
|
|
208
|
+
not?: V | null;
|
|
209
|
+
lt?: V;
|
|
210
|
+
lte?: V;
|
|
211
|
+
gt?: V;
|
|
212
|
+
gte?: V;
|
|
213
|
+
contains?: string;
|
|
214
|
+
startsWith?: string;
|
|
215
|
+
endsWith?: string;
|
|
216
|
+
/** By the slot's state (`asked_unknown`, `declined`, …): the one extension to Prisma's `where`. */
|
|
217
|
+
state?: SlotState;
|
|
218
|
+
};
|
|
219
|
+
type IdFilter<R extends string> = Id<R> | null | {
|
|
220
|
+
equals?: Id<R> | null;
|
|
221
|
+
in?: readonly Id<R>[];
|
|
222
|
+
notIn?: readonly Id<R>[];
|
|
223
|
+
not?: Id<R> | null;
|
|
224
|
+
state?: SlotState;
|
|
225
|
+
};
|
|
226
|
+
/** A row time (ISO 8601), compared as the instant it names. */
|
|
227
|
+
type TimeFilter = string | {
|
|
228
|
+
equals?: string;
|
|
229
|
+
in?: readonly string[];
|
|
230
|
+
notIn?: readonly string[];
|
|
231
|
+
not?: string;
|
|
232
|
+
lt?: string;
|
|
233
|
+
lte?: string;
|
|
234
|
+
gt?: string;
|
|
235
|
+
gte?: string;
|
|
236
|
+
};
|
|
237
|
+
/** `is` / `isNot` on a ref: one level only (a nested `is` is refused; read those rows first, then `in`). */
|
|
238
|
+
type RelationFilter<D, R extends keyof D> = {
|
|
239
|
+
is?: WhereFields<D, R, false> | null;
|
|
240
|
+
isNot?: WhereFields<D, R, false> | null;
|
|
241
|
+
};
|
|
242
|
+
/** `some` / `every` / `none` on a way back: one level only, like `is`. */
|
|
243
|
+
type ListFilter<D, R extends keyof D> = {
|
|
244
|
+
some?: WhereFields<D, R, false>;
|
|
245
|
+
every?: WhereFields<D, R, false>;
|
|
246
|
+
none?: WhereFields<D, R, false>;
|
|
247
|
+
};
|
|
248
|
+
type WhereFields<D, T extends keyof D, Rel extends boolean> = {
|
|
249
|
+
id?: IdFilter<T & string>;
|
|
250
|
+
} & {
|
|
251
|
+
[K in RowTime]?: TimeFilter;
|
|
252
|
+
} & {
|
|
253
|
+
[F in FieldOf<D, T>]?: Desc<D, T, F> extends {
|
|
254
|
+
ref: infer R extends string;
|
|
255
|
+
} ? IdFilter<R> | (Rel extends true ? RelationFilter<D, R & keyof D> : never) : ScalarFilter<Desc<D, T, F>['value']>;
|
|
256
|
+
} & (Rel extends true ? {
|
|
257
|
+
[K in RelationOf<D, T>]?: ListFilter<D, RelationTable<D, T, K>>;
|
|
258
|
+
} : unknown) & {
|
|
259
|
+
AND?: WhereFields<D, T, Rel> | ReadonlyArray<WhereFields<D, T, Rel>>;
|
|
260
|
+
OR?: ReadonlyArray<WhereFields<D, T, Rel>>;
|
|
261
|
+
NOT?: WhereFields<D, T, Rel> | ReadonlyArray<WhereFields<D, T, Rel>>;
|
|
262
|
+
};
|
|
263
|
+
/** What anchors a read: an id, `{ equals: id }` or `{ in: ids }`. */
|
|
264
|
+
type Anchor<R extends string> = Id<R> | {
|
|
265
|
+
equals: Id<R>;
|
|
266
|
+
} | {
|
|
267
|
+
in: readonly Id<R>[];
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* A `where`: this table's fields and row times, starting at its top level from `id` or a ref field
|
|
271
|
+
* (the rows it pins), or from a condition on a field or a row time (the field index finds the rows;
|
|
272
|
+
* a long text cannot start one). A start inside `AND` works at run time but does not type-check: write
|
|
273
|
+
* it at the top level, it means the same.
|
|
274
|
+
*/
|
|
275
|
+
export type Where<D, T extends keyof D> = {
|
|
276
|
+
[K in 'id' | RefFieldOf<D, T>]: WhereFields<D, T, true> & {
|
|
277
|
+
[P in K]: Anchor<K extends 'id' ? T & string : RefTable<D, T, K>>;
|
|
278
|
+
};
|
|
279
|
+
}['id' | RefFieldOf<D, T>] | {
|
|
280
|
+
[K in PlainFieldOf<D, T> | RowTime]: WhereFields<D, T, true> & {
|
|
281
|
+
[P in K]-?: NonNullable<WhereFields<D, T, true>[P & keyof WhereFields<D, T, true>]>;
|
|
282
|
+
};
|
|
283
|
+
}[PlainFieldOf<D, T> | RowTime];
|
|
284
|
+
/**
|
|
285
|
+
* `include` as written, with any key that is not a lookup (a parent, another table's field, a typo)
|
|
286
|
+
* turned into `never`, at every level: an inferred argument gets no excess-property check otherwise.
|
|
287
|
+
*/
|
|
288
|
+
type ExactInclude<D, T extends keyof D, I> = {
|
|
289
|
+
[K in keyof I]: K extends LookupOf<D, T> ? I[K] extends {
|
|
290
|
+
include: infer N;
|
|
291
|
+
} ? Omit<I[K], 'include'> & {
|
|
292
|
+
include: ExactInclude<D, RefTable<D, T, K> & keyof D, N>;
|
|
293
|
+
} : I[K] : K extends RelationOf<D, T> ? I[K] extends object ? ExactRelationInclude<D, RelationTable<D, T, K>, I[K]> : I[K] : never;
|
|
294
|
+
};
|
|
295
|
+
/**
|
|
296
|
+
* A way back's `{ where, orderBy, skip, take, include }` as written, any other key `never`; its
|
|
297
|
+
* `where` checked key by key at its top level (the listed table's fields, `id`, its ways back,
|
|
298
|
+
* `AND` / `OR` / `NOT`), its `include` like any `include`.
|
|
299
|
+
*/
|
|
300
|
+
type ExactRelationInclude<D, R extends keyof D, S> = {
|
|
301
|
+
[P in keyof S]: P extends 'include' ? ExactInclude<D, R, S[P]> : P extends 'where' ? {
|
|
302
|
+
[W in keyof S[P]]: W extends FieldOf<D, R> | RelationOf<D, R> | 'id' | RowTime | 'AND' | 'OR' | 'NOT' ? S[P][W] : never;
|
|
303
|
+
} : P extends 'orderBy' | 'skip' | 'take' ? S[P] : never;
|
|
304
|
+
};
|
|
305
|
+
/** `select` as written, with any key that is not a field of the table turned into `never`. */
|
|
306
|
+
type ExactSelect<D, T extends keyof D, S> = {
|
|
307
|
+
[K in keyof S]: K extends FieldOf<D, T> ? S[K] : never;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* `include` / `select`: left out, or written. Written, the key is required here so inference keeps an
|
|
311
|
+
* `undefined` in its value (`include: flag ? { … } : undefined`); an optional key would drop it.
|
|
312
|
+
*/
|
|
313
|
+
type IncludeKey<D, T extends keyof D, I> = {
|
|
314
|
+
include?: undefined;
|
|
315
|
+
} | {
|
|
316
|
+
include: I & ExactInclude<D, T, I>;
|
|
317
|
+
};
|
|
318
|
+
type SelectKey<D, T extends keyof D, S> = {
|
|
319
|
+
select?: undefined;
|
|
320
|
+
} | {
|
|
321
|
+
select: S & ExactSelect<D, T, S>;
|
|
322
|
+
};
|
|
323
|
+
export type FindManyArgs<D, T extends keyof D, I = IncludeArg<D, T>, S = SelectArg<D, T>> = IncludeKey<D, T, I> & SelectKey<D, T, S> & {
|
|
324
|
+
where: Where<D, T>;
|
|
325
|
+
orderBy?: OrderByArg<D, T>;
|
|
326
|
+
take?: number;
|
|
327
|
+
skip?: number;
|
|
328
|
+
cursor?: {
|
|
329
|
+
id: Id<T & string>;
|
|
330
|
+
};
|
|
331
|
+
};
|
|
332
|
+
/** `findUnique`: by `id`; null when there is no such row. */
|
|
333
|
+
export type FindUniqueArgs<D, T extends keyof D, I = IncludeArg<D, T>, S = SelectArg<D, T>> = IncludeKey<D, T, I> & SelectKey<D, T, S> & {
|
|
334
|
+
where: {
|
|
335
|
+
id: Id<T & string>;
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* One table's read methods: Prisma Client's read-only subset. Only `include` / `select` are inferred
|
|
340
|
+
* (they shape the rows returned), and checked key by key (`ExactInclude`, `ExactSelect`); `where` is
|
|
341
|
+
* checked as written. A stray field anywhere is an error.
|
|
342
|
+
*/
|
|
343
|
+
export type TypedTableReader<D, T extends keyof D> = {
|
|
344
|
+
readonly $table: T;
|
|
345
|
+
findUnique<const I extends IncludeArg<D, T> | undefined = undefined, const S extends SelectArg<D, T> | undefined = undefined>(args: FindUniqueArgs<D, T, I, S>): Promise<RowOf<D, T, I, S> | null>;
|
|
346
|
+
findFirst<const I extends IncludeArg<D, T> | undefined = undefined, const S extends SelectArg<D, T> | undefined = undefined>(args: FindManyArgs<D, T, I, S>): Promise<RowOf<D, T, I, S> | null>;
|
|
347
|
+
findMany<const I extends IncludeArg<D, T> | undefined = undefined, const S extends SelectArg<D, T> | undefined = undefined>(args: FindManyArgs<D, T, I, S>): Promise<Array<RowOf<D, T, I, S>>>;
|
|
348
|
+
count(args: {
|
|
349
|
+
where: Where<D, T>;
|
|
350
|
+
}): Promise<number>;
|
|
351
|
+
};
|
|
352
|
+
/** `db` where only reading is allowed (a page render): this sequence's tables, read methods only. */
|
|
353
|
+
export type TypedReadDb<D> = {
|
|
354
|
+
readonly [T in TableOf<D>]: TypedTableReader<D, T>;
|
|
355
|
+
};
|
|
356
|
+
type WriteValueOf<D, T extends keyof D, F> = ValueOf<D, T, F>;
|
|
357
|
+
/** A new row: its parent required, any other field optional. */
|
|
358
|
+
export type CreateData<D, T extends keyof D> = Simplify<{
|
|
359
|
+
[F in ParentOf<D, T>]: WriteValueOf<D, T, F>;
|
|
360
|
+
} & {
|
|
361
|
+
[F in Exclude<FieldOf<D, T>, ParentOf<D, T>>]?: WriteValueOf<D, T, F> | null;
|
|
362
|
+
}>;
|
|
363
|
+
/** A change to a row: any field but the parent. */
|
|
364
|
+
export type UpdateData<D, T extends keyof D> = {
|
|
365
|
+
[F in Exclude<FieldOf<D, T>, ParentOf<D, T>>]?: WriteValueOf<D, T, F> | null;
|
|
366
|
+
};
|
|
367
|
+
type TableWrites<D, T extends keyof D> = {
|
|
368
|
+
update(args: {
|
|
369
|
+
where: {
|
|
370
|
+
id: Id<T & string>;
|
|
371
|
+
};
|
|
372
|
+
data: UpdateData<D, T>;
|
|
373
|
+
}): Promise<{
|
|
374
|
+
id: Id<T & string>;
|
|
375
|
+
}>;
|
|
376
|
+
delete(args: {
|
|
377
|
+
where: {
|
|
378
|
+
id: Id<T & string>;
|
|
379
|
+
};
|
|
380
|
+
reason?: string;
|
|
381
|
+
}): Promise<{
|
|
382
|
+
id: Id<T & string>;
|
|
383
|
+
}>;
|
|
384
|
+
} & (T extends 'session' ? unknown : {
|
|
385
|
+
create(args: {
|
|
386
|
+
data: CreateData<D, T>;
|
|
387
|
+
}): Promise<{
|
|
388
|
+
id: Id<T & string>;
|
|
389
|
+
}>;
|
|
390
|
+
/**
|
|
391
|
+
* The row whose `unique` field in `where` holds that value, updated; else a new row with it
|
|
392
|
+
* (18-record-search-index §4.5). `where` names exactly one `unique` field.
|
|
393
|
+
*/
|
|
394
|
+
upsert(args: {
|
|
395
|
+
where: {
|
|
396
|
+
[F in Exclude<FieldOf<D, T>, ParentOf<D, T>>]?: WriteValueOf<D, T, F>;
|
|
397
|
+
};
|
|
398
|
+
create: CreateData<D, T>;
|
|
399
|
+
update: UpdateData<D, T>;
|
|
400
|
+
}): Promise<{
|
|
401
|
+
id: Id<T & string>;
|
|
402
|
+
}>;
|
|
403
|
+
});
|
|
404
|
+
/**
|
|
405
|
+
* `db`: this sequence's tables, Prisma-shaped, reads and writes on one object. Writes are V1
|
|
406
|
+
* `create` / `update` / `delete`. A contact may be created (with
|
|
407
|
+
* no lookup for one with the same phone or email, 15 §10.6.1); session rows are not created here.
|
|
408
|
+
*/
|
|
409
|
+
export type TypedDb<D> = {
|
|
410
|
+
readonly [T in TableOf<D>]: TypedTableReader<D, T> & TableWrites<D, T>;
|
|
411
|
+
};
|
|
412
|
+
type RowIfTable<D, T extends string> = T extends keyof D ? RowOf<D, T> : never;
|
|
413
|
+
/**
|
|
414
|
+
* One channel's page function context (20 §5.2): `C` the channel, with what only it has (`ctx.call`,
|
|
415
|
+
* `ctx.sms`, `ctx.email`). Without `C`, any channel's: what a helper shared by several pages takes.
|
|
416
|
+
*/
|
|
417
|
+
export type TypedPageContext<D, S extends string, C extends PageChannel = PageChannel> = {
|
|
418
|
+
[K in C]: TypedPageBaseContext<D, S> & {
|
|
419
|
+
channel: K;
|
|
420
|
+
} & PageChannelCaps[K];
|
|
421
|
+
}[C];
|
|
422
|
+
type TypedPageBaseContext<D, S extends string> = {
|
|
423
|
+
/** Read-only: a render never writes. */
|
|
424
|
+
db: TypedReadDb<D>;
|
|
425
|
+
/** What the platform recorded (17b §7, 21 §6.7): `tried(ctx.runs, key)`, `tried(ctx.runs, key, 'case')`. */
|
|
426
|
+
runs: PageRuns;
|
|
427
|
+
/** Why this conversation happened when the platform started it; null for an inbound one. */
|
|
428
|
+
scheduledAction: PageScheduledAction | null;
|
|
429
|
+
/** The sequence's office hours now; null when it has none. */
|
|
430
|
+
officeHours: PageBaseContext['officeHours'];
|
|
431
|
+
/** The contact's agreed follow-ups still to come (09). */
|
|
432
|
+
followUps: PageBaseContext['followUps'];
|
|
433
|
+
/** The business root's id. */
|
|
434
|
+
subject: Id<S>;
|
|
435
|
+
/** The contact of the conversation; null outside one. */
|
|
436
|
+
caller: RowIfTable<D, 'contact'> | null;
|
|
437
|
+
/** This conversation's session row (the session fields, cells); null outside one. */
|
|
438
|
+
session: RowIfTable<D, 'session'> | null;
|
|
439
|
+
/** This conversation's platform facts (read-only, never a cell); null outside one. */
|
|
440
|
+
conversation: PageConversation | null;
|
|
441
|
+
/** Counts over this instance (`sessionCount`, `exchangeCount`). */
|
|
442
|
+
history: PageHistory;
|
|
443
|
+
/** ISO timestamp of this render. */
|
|
444
|
+
now: string;
|
|
445
|
+
/** A text or an email to send now (25 §8): `ctx.messages.text('link', { body })`. */
|
|
446
|
+
messages: TypedPageMessages<D>;
|
|
447
|
+
/** The contact's time zone, today there, and `format` for a time as people read it (25 §11). */
|
|
448
|
+
time: PageTime;
|
|
449
|
+
};
|
|
450
|
+
type TypedMessageOptions<D> = Omit<MessageOptions, 'to'> & {
|
|
451
|
+
/** The contact it goes to (a contact row the page read); absent: the contact of this conversation. */
|
|
452
|
+
to?: RowIfTable<D, 'contact'> | Id<'contact'>;
|
|
453
|
+
};
|
|
454
|
+
/** `ctx.messages`, its `to` a contact of this company. */
|
|
455
|
+
export type TypedPageMessages<D> = {
|
|
456
|
+
text(key: string, options?: TypedMessageOptions<D>): MessageAction;
|
|
457
|
+
email(key: string, options?: TypedMessageOptions<D> & {
|
|
458
|
+
subject?: string;
|
|
459
|
+
}): MessageAction;
|
|
460
|
+
};
|
|
461
|
+
export type TypedActionContext<D, S extends string> = {
|
|
462
|
+
db: TypedDb<D>;
|
|
463
|
+
subject: Id<S>;
|
|
464
|
+
caller: RowIfTable<D, 'contact'> | null;
|
|
465
|
+
/** On a call, this party's session for this case (25 §9); null by text and email. Written with `db.session.update`. */
|
|
466
|
+
session: RowIfTable<D, 'session'> | null;
|
|
467
|
+
now: string;
|
|
468
|
+
};
|
|
469
|
+
/** `table.field` (or `table.id`, a row) of this sequence: what `schemaField` takes. */
|
|
470
|
+
export type SchemaFieldPath<D> = {
|
|
471
|
+
[T in TableOf<D>]: `${T}.id` | `${T}.${FieldOf<D, T>}`;
|
|
472
|
+
}[TableOf<D>];
|
|
473
|
+
export type TypedSchemaFieldParam<P extends string> = {
|
|
474
|
+
readonly $schemaField: P;
|
|
475
|
+
readonly extraction?: string;
|
|
476
|
+
};
|
|
477
|
+
/** One parameter: a schema field, or plain JSON Schema (an LLM function call's `parameters`). */
|
|
478
|
+
export type TypedActionParam<D> = TypedSchemaFieldParam<SchemaFieldPath<D>> | {
|
|
479
|
+
readonly type: 'string';
|
|
480
|
+
readonly description?: string;
|
|
481
|
+
readonly enum?: readonly string[];
|
|
482
|
+
} | {
|
|
483
|
+
readonly type: 'number' | 'integer';
|
|
484
|
+
readonly description?: string;
|
|
485
|
+
readonly enum?: readonly number[];
|
|
486
|
+
} | {
|
|
487
|
+
readonly type: 'boolean';
|
|
488
|
+
readonly description?: string;
|
|
489
|
+
} | {
|
|
490
|
+
readonly type: 'array';
|
|
491
|
+
readonly items: TypedActionParam<D>;
|
|
492
|
+
readonly description?: string;
|
|
493
|
+
} | {
|
|
494
|
+
readonly type: 'object';
|
|
495
|
+
readonly properties: {
|
|
496
|
+
readonly [key: string]: TypedActionParam<D>;
|
|
497
|
+
};
|
|
498
|
+
readonly required?: readonly string[];
|
|
499
|
+
readonly description?: string;
|
|
500
|
+
};
|
|
501
|
+
export type TypedActionParameters<D> = {
|
|
502
|
+
readonly type: 'object';
|
|
503
|
+
readonly properties: {
|
|
504
|
+
readonly [key: string]: TypedActionParam<D>;
|
|
505
|
+
};
|
|
506
|
+
readonly required?: readonly string[];
|
|
507
|
+
};
|
|
508
|
+
/** What `run` gets for one parameter. */
|
|
509
|
+
type ParamValue<D, P> = P extends {
|
|
510
|
+
$schemaField: `${infer T}.${infer F}`;
|
|
511
|
+
} ? T extends keyof D ? F extends 'id' ? Id<T> : ValueOf<D, T, F> : never : P extends {
|
|
512
|
+
type: 'string';
|
|
513
|
+
enum: readonly (infer E)[];
|
|
514
|
+
} ? E : P extends {
|
|
515
|
+
type: 'string';
|
|
516
|
+
} ? string : P extends {
|
|
517
|
+
type: 'number' | 'integer';
|
|
518
|
+
enum: readonly (infer E)[];
|
|
519
|
+
} ? E : P extends {
|
|
520
|
+
type: 'number' | 'integer';
|
|
521
|
+
} ? number : P extends {
|
|
522
|
+
type: 'boolean';
|
|
523
|
+
} ? boolean : P extends {
|
|
524
|
+
type: 'array';
|
|
525
|
+
items: infer I;
|
|
526
|
+
} ? Array<ParamValue<D, I>> : P extends {
|
|
527
|
+
type: 'object';
|
|
528
|
+
properties: infer Props;
|
|
529
|
+
} ? ArgsOf<D, {
|
|
530
|
+
properties: Props;
|
|
531
|
+
required: P extends {
|
|
532
|
+
required: infer R;
|
|
533
|
+
} ? R : [];
|
|
534
|
+
}> : never;
|
|
535
|
+
type RequiredOf<P> = P extends {
|
|
536
|
+
required: readonly (infer R)[];
|
|
537
|
+
} ? R : never;
|
|
538
|
+
/** What `run` gets: every parameter, required ones present, others optional. */
|
|
539
|
+
export type ArgsOf<D, P> = P extends {
|
|
540
|
+
properties: infer Props;
|
|
541
|
+
} ? Simplify<{
|
|
542
|
+
-readonly [K in Extract<keyof Props, RequiredOf<P>>]: ParamValue<D, Props[K]>;
|
|
543
|
+
} & {
|
|
544
|
+
-readonly [K in Exclude<keyof Props, RequiredOf<P>>]?: ParamValue<D, Props[K]>;
|
|
545
|
+
}> : Record<never, never>;
|
|
546
|
+
declare const CHOOSE_BRAND: unique symbol;
|
|
547
|
+
/** `choose(rows, label)` over rows of `T` (25 §10): the rows a row parameter of `T` is chosen among. */
|
|
548
|
+
export type TypedChoose<T extends string> = ChooseParam & {
|
|
549
|
+
readonly [CHOOSE_BRAND]?: T;
|
|
550
|
+
};
|
|
551
|
+
/** What a placed action is called with: a value, or for a row parameter its row's id or `choose(...)` (25 §10). */
|
|
552
|
+
export type PrefillOf<A> = {
|
|
553
|
+
[K in keyof A]?: A[K] | (NonNullable<A[K]> extends {
|
|
554
|
+
readonly [ID_BRAND]: infer T extends string;
|
|
555
|
+
} ? TypedChoose<T> : never);
|
|
556
|
+
};
|
|
557
|
+
/**
|
|
558
|
+
* A custom action: called to prefill arguments (`markError({ injury: i.id })`, one button per row) or to
|
|
559
|
+
* offer the rows a row argument is chosen among (`cancel({ appointment: choose(rows, label) })`, 25 §10).
|
|
560
|
+
* Placing it as it is leaves a row argument to the rows the page happens to show: not recommended.
|
|
561
|
+
*/
|
|
562
|
+
export type TypedDefinedAction<A> = Placeable<CustomAction, PrefillOf<A>> & {
|
|
563
|
+
readonly actionName: string;
|
|
564
|
+
};
|
|
565
|
+
/** The page module of one sequence: `D` its tables (`PageTables`), `S` its business root table. */
|
|
566
|
+
export type TypedPageModule<D, S extends string> = {
|
|
567
|
+
/** Each channel's page is its own (17b §9.1): what a call shows and what a text shows may differ. */
|
|
568
|
+
definePage<Call = never, Sms = never, Email = never>(definition: {
|
|
569
|
+
/** Called once when the conversation starts (24 §4): the persona for `ctx.channel`. */
|
|
570
|
+
persona: (ctx: TypedPageContext<D, S>) => string | Promise<string>;
|
|
571
|
+
/** Called once when the conversation starts (24 §4): the FAQ, at most 100 entries. */
|
|
572
|
+
faq?: (ctx: TypedPageContext<D, S>) => PageFaqEntry[] | Promise<PageFaqEntry[]>;
|
|
573
|
+
call?: (ctx: TypedPageContext<D, S, 'call'>) => Call | Promise<Call>;
|
|
574
|
+
sms?: (ctx: TypedPageContext<D, S, 'sms'>) => Sms | Promise<Sms>;
|
|
575
|
+
email?: (ctx: TypedPageContext<D, S, 'email'>) => Email | Promise<Email>;
|
|
576
|
+
}): {
|
|
577
|
+
kind: 'page';
|
|
578
|
+
persona: PagePersona;
|
|
579
|
+
faq: PageFaq | null;
|
|
580
|
+
channels: {
|
|
581
|
+
call?: (ctx: TypedPageContext<D, S, 'call'>) => Call | Promise<Call>;
|
|
582
|
+
sms?: (ctx: TypedPageContext<D, S, 'sms'>) => Sms | Promise<Sms>;
|
|
583
|
+
email?: (ctx: TypedPageContext<D, S, 'email'>) => Email | Promise<Email>;
|
|
584
|
+
};
|
|
585
|
+
};
|
|
586
|
+
field<Sl extends TypedSlot<unknown, string, string>>(slot: Sl, options?: FieldOptions): FieldCell<Sl>;
|
|
587
|
+
/** A ref field (26 §16.2 #7): the rows it may point at, `{ id, label }` each, or `choose(rows, label)`. */
|
|
588
|
+
refField<Sl extends TypedSlot<unknown, string, string>>(slot: Sl, options?: {
|
|
589
|
+
options?: ReadonlyArray<RefOption & {
|
|
590
|
+
id: Sl['value'] & string;
|
|
591
|
+
}> | ChooseParam;
|
|
592
|
+
readOnly?: boolean;
|
|
593
|
+
}): RefFieldCell<Sl>;
|
|
594
|
+
schemaField<const P extends SchemaFieldPath<D>>(path: P, options?: SchemaFieldOptions): TypedSchemaFieldParam<P>;
|
|
595
|
+
createRow<T extends TableOf<D>, const F extends readonly Exclude<FieldOf<D, T>, ParentOf<D, T>>[]>(table: T | {
|
|
596
|
+
readonly $table: T;
|
|
597
|
+
}, options: {
|
|
598
|
+
fields: F;
|
|
599
|
+
required?: ReadonlyArray<F[number]>;
|
|
600
|
+
label?: string;
|
|
601
|
+
description?: string;
|
|
602
|
+
}): Placeable<CreateRowAction, Partial<CreateData<D, T>>>;
|
|
603
|
+
deleteRow(row: Id<TableOf<D>> | {
|
|
604
|
+
readonly id: Id<TableOf<D>>;
|
|
605
|
+
}, options?: {
|
|
606
|
+
reason?: string;
|
|
607
|
+
label?: string;
|
|
608
|
+
description?: string;
|
|
609
|
+
}): DeleteRowAction;
|
|
610
|
+
/** The rows a row parameter is chosen among, each with what the AI sees of it (25 §10). */
|
|
611
|
+
choose<R extends {
|
|
612
|
+
readonly id: Id<TableOf<D>>;
|
|
613
|
+
}>(rows: readonly R[], label: (row: R) => string): TypedChoose<R['id'] extends {
|
|
614
|
+
readonly [ID_BRAND]: infer T extends string;
|
|
615
|
+
} ? T : never>;
|
|
616
|
+
defineAction<const P extends TypedActionParameters<D> = {
|
|
617
|
+
type: 'object';
|
|
618
|
+
properties: {};
|
|
619
|
+
}>(definition: {
|
|
620
|
+
name: string;
|
|
621
|
+
description: string;
|
|
622
|
+
parameters?: P;
|
|
623
|
+
run: (args: ArgsOf<D, P>, ctx: TypedActionContext<D, S>) => unknown;
|
|
624
|
+
}): TypedDefinedAction<ArgsOf<D, P>>;
|
|
625
|
+
};
|
|
626
|
+
/** What a page function may return instead of the page (17b §9.8): an action to run first. */
|
|
627
|
+
type ReturnedAction = {
|
|
628
|
+
$action: string;
|
|
629
|
+
} | {
|
|
630
|
+
$perform: true;
|
|
631
|
+
} | ((...args: never[]) => unknown);
|
|
632
|
+
/**
|
|
633
|
+
* The document a page script returns: `PageDocumentOf<typeof page>` of `context.page.ts`'s default
|
|
634
|
+
* export. An action the page function returns instead (a lookup, a keypad) is not part of it.
|
|
635
|
+
*/
|
|
636
|
+
export type PageDocumentOf<P> = P extends {
|
|
637
|
+
channels: infer C;
|
|
638
|
+
} ? {
|
|
639
|
+
[K in keyof C]: C[K] extends ((...args: never[]) => infer R) | undefined ? Exclude<Awaited<R>, ReturnedAction> : never;
|
|
640
|
+
}[keyof C] : never;
|
|
641
|
+
export {};
|
|
642
|
+
//# sourceMappingURL=typed.d.ts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the AI reads of a page (24 §3, 26 §15.5): one layer, the whole page, like a rep's screen. The
|
|
3
|
+
* page decides what is on it; the platform works out nothing from it. Everything is an element; every
|
|
4
|
+
* attribute value is JSON (strings "…" with \" and \n, numbers, true/false, null, lists); free text is
|
|
5
|
+
* always a `value` attribute; flush left.
|
|
6
|
+
*
|
|
7
|
+
* <notes><note id about value/></notes> the model's own reminders (17b §8), first, all of them
|
|
8
|
+
* <guide value/> the page's `$guide`: what to do now and how
|
|
9
|
+
* <page title description fallback> the page:
|
|
10
|
+
* <definitions> once for the page, a definition per `table.field` some field
|
|
11
|
+
* <definition for label type …/> on it shows expanded (`field(slot, { expand: true })`)
|
|
12
|
+
* <block key title description> a part of the page; inside a list, without `key`
|
|
13
|
+
* <list key title description> several things of one kind (an array on the page)
|
|
14
|
+
* <field id key readonly more type value value-label one-of state reason/> one value; `more`: its
|
|
15
|
+
* definition is not shown (its type is); a ref's one-of: its rows
|
|
16
|
+
* <text key value/> read-only text
|
|
17
|
+
* <button id title does><arg …/></button>
|
|
18
|
+
*/
|
|
19
|
+
import type { BlockNode, RenderedPage } from './render.js';
|
|
20
|
+
export type WorkspaceNote = {
|
|
21
|
+
id: string;
|
|
22
|
+
text: string;
|
|
23
|
+
about?: string;
|
|
24
|
+
};
|
|
25
|
+
export type WorkspaceTextOptions = {
|
|
26
|
+
notes?: readonly WorkspaceNote[];
|
|
27
|
+
};
|
|
28
|
+
export declare function workspaceText(page: RenderedPage, options?: WorkspaceTextOptions): string;
|
|
29
|
+
/** The block at `path` (`''`: the root). */
|
|
30
|
+
export declare function blockAt(page: RenderedPage, path: string): BlockNode | null;
|
|
31
|
+
/** What `view` shows of one thing on the page (24 §3.2): a field with its definition, a button with its arguments. */
|
|
32
|
+
export declare function viewText(page: RenderedPage, id: string): string | null;
|
|
33
|
+
//# sourceMappingURL=workspace.d.ts.map
|