@trytilde/ontology 3.1.1 → 5.0.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/dist/catalog.d.ts +22 -2
- package/dist/mod.d.ts +403 -180
- package/dist/mod.js +361 -126
- package/package.json +2 -2
package/dist/mod.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `@trytilde/ontology`: an ontology project in TypeScript, the single source for
|
|
3
3
|
*
|
|
4
|
-
* - **models**:
|
|
5
|
-
*
|
|
4
|
+
* - **sources and models**: every input is a `source` (a pipeline, `ingress()` or `rows()`) whose
|
|
5
|
+
* streams are current-state models; dbt-style ducktail models (`model`, `sqlFile`) over them,
|
|
6
|
+
* compiled to `manifest.json`, which ducktail executes;
|
|
6
7
|
* - **nouns**: object types with typed properties over models, links, entity resolution;
|
|
7
8
|
* - **transactional views**: a portion of the graph materialised per key in a celld SQLite
|
|
8
9
|
* cell for hot transactional work (`transactionalView`);
|
|
9
10
|
* - **verbs**: `action` (txWrite) and `read` (txRead in a view, or `read` against the lake),
|
|
10
11
|
* with zod input and output and declared `edits` and `reads` (enforced). Handlers call
|
|
11
12
|
* third parties with plain `fetch` or SDKs; `ctx.deferredFetch` sends a request durably after
|
|
12
|
-
* the action commits, with credentials from a
|
|
13
|
+
* the action commits, with credentials from a declared connection (a third-party account the
|
|
13
14
|
* environment binds, never visible to handlers) or an `auth` resolver over declared `secrets`;
|
|
14
15
|
* - **realtime views**: `realtime` reads whose results are pushed to subscribers when they
|
|
15
16
|
* change (per view instance in its cell, or across cells from the lake);
|
|
@@ -21,11 +22,15 @@
|
|
|
21
22
|
*
|
|
22
23
|
* ```ts
|
|
23
24
|
* import { z } from "zod";
|
|
24
|
-
* import { action,
|
|
25
|
+
* import { action, defineSecrets, model, object, ontology, postgres, secret, source, sql, t, transactionalView } from "@trytilde/ontology";
|
|
25
26
|
*
|
|
26
|
-
* const
|
|
27
|
-
* const
|
|
28
|
-
*
|
|
27
|
+
* const secrets = defineSecrets({ APP_DB_PASSWORD: secret() });
|
|
28
|
+
* const app = source("app", {
|
|
29
|
+
* from: postgres.cdc({ host: "db.internal", user: "replicator", password: secrets.APP_DB_PASSWORD, database: "app", tables: ["public.customers"] }),
|
|
30
|
+
* streams: { public_customers: {} },
|
|
31
|
+
* });
|
|
32
|
+
* const customersNow = app.public_customers;
|
|
33
|
+
* const crmCustomers = model({ name: "crm_customers", type: "model", schema: "cells", materialization: "cell", uniqueKey: "customer_id",
|
|
29
34
|
* columns: { customer_id: t.string(), name: t.string() },
|
|
30
35
|
* sql: ({ ref }) => sql`SELECT payload->>'id' AS customer_id, payload->>'name' AS name FROM ${ref(customersNow)}` });
|
|
31
36
|
* export const Customer = object("Customer", { id: "customer", key: "customerId", source: crmCustomers,
|
|
@@ -37,23 +42,25 @@
|
|
|
37
42
|
* edits: [Customer.notes], reads: [Customer],
|
|
38
43
|
* handler: ({ input, view, ctx }) => { ctx.update(Customer, view.key, { notes: input.notes }); return null; },
|
|
39
44
|
* });
|
|
40
|
-
* export default ontology({ objects: [Customer], views: [CustomerView], actions: [setNotes] });
|
|
45
|
+
* export default ontology({ sources: [app], secrets, objects: [Customer], views: [CustomerView], actions: [setNotes] });
|
|
41
46
|
* ```
|
|
42
47
|
*/
|
|
43
48
|
import { z } from "zod";
|
|
44
|
-
import { type PolledKind, type PolledProvider, type PolledStreams, type WebhookEvents } from "./catalog.
|
|
45
|
-
export type { PipelineKind, PolledKind, PolledProvider, PolledStreams, WebhookEvents, WebhookProvider } from "./catalog.
|
|
49
|
+
import { type PolledKind, type PolledProvider, type PolledStreams, type SyncStreams, type WebhookEvents, type WebhookProvider } from "./catalog.js";
|
|
50
|
+
export type { PipelineKind, PolledKind, PolledProvider, PolledStreams, WebhookEvents, WebhookProvider } from "./catalog.js";
|
|
46
51
|
export type Json = null | boolean | number | string | Json[] | {
|
|
47
52
|
[key: string]: Json;
|
|
48
53
|
};
|
|
49
54
|
export type SqlParam = string | number | boolean | null;
|
|
50
55
|
export type Key = string | number;
|
|
51
56
|
/** Where an ontology's data lives: `cell` (the default: SQLite cells for views, DuckLake for the
|
|
52
|
-
* lake)
|
|
53
|
-
|
|
57
|
+
* lake), `postgres` (one Postgres schema for everything; see CONTEXT.md, "Postgres storage") or
|
|
58
|
+
* `sqlite` (one SQLite database for everything, in the environment's Durable Object: the small,
|
|
59
|
+
* scale-to-zero tier; see CONTEXT.md, "SQLite storage"). */
|
|
60
|
+
export type Storage = "cell" | "postgres" | "sqlite";
|
|
54
61
|
/** The SQL dialect models and handler SQL are written in: DuckDB for `cell` storage, Postgres
|
|
55
|
-
* for `postgres`; ClickHouse for the models of a ClickHouse destination. */
|
|
56
|
-
export type Dialect = "duckdb" | "postgres" | "clickhouse";
|
|
62
|
+
* for `postgres`, SQLite for `sqlite`; ClickHouse for the models of a ClickHouse destination. */
|
|
63
|
+
export type Dialect = "duckdb" | "postgres" | "sqlite" | "clickhouse";
|
|
57
64
|
/** The kind of a named destination models can materialize to besides the storage. */
|
|
58
65
|
export type DestinationKind = "clickhouse";
|
|
59
66
|
/** A SQL text fragment (in the storage's dialect). */
|
|
@@ -142,42 +149,106 @@ export declare class SourceDef {
|
|
|
142
149
|
constructor(pipeline: string, stream: string, loc: string | null);
|
|
143
150
|
}
|
|
144
151
|
/**
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
* `
|
|
148
|
-
*
|
|
149
|
-
* `ontology({ pipelines })`.
|
|
152
|
+
* Records your code sends through Tilde's Ingress (`IngressService.WriteRecords`, by API keys,
|
|
153
|
+
* people and agents with `write_streams` on the project, or the environment's own worker). Each
|
|
154
|
+
* stream declares a zod `schema` and the `key` property; a newer record of a key replaces the
|
|
155
|
+
* older. Its raw rows are `lake.raw.ingress__<stream>`.
|
|
150
156
|
*/
|
|
151
|
-
export declare function
|
|
152
|
-
export declare function source<const S extends string>(name: string, spec: {
|
|
153
|
-
pipeline: Pipeline<S>;
|
|
154
|
-
}): PipelineSource<S>;
|
|
157
|
+
export declare function ingress(): IngressFrom;
|
|
155
158
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* `lake.raw.ingress__<name>`: read it with `src()` and `changes()` like any source (the payload
|
|
161
|
-
* is the record). List streams in `ontology({ streams })`.
|
|
159
|
+
* Reference data the version ships (a solution's tenant configuration, say): each stream's
|
|
160
|
+
* `rows`, validated against its `schema` and loaded through Ingress by every rollout, so a
|
|
161
|
+
* redeploy updates them (a record replaces the earlier one of its key; a record dropped from the
|
|
162
|
+
* list is not deleted).
|
|
162
163
|
*/
|
|
163
|
-
export declare
|
|
164
|
-
|
|
165
|
-
readonly
|
|
166
|
-
readonly
|
|
167
|
-
constructor(name: string, schema: z.ZodType, key: string, reference: readonly unknown[], loc: string | null);
|
|
164
|
+
export declare function rows(): IngressFrom;
|
|
165
|
+
export interface IngressFrom {
|
|
166
|
+
readonly kind: "ingress";
|
|
167
|
+
readonly rows: boolean;
|
|
168
168
|
}
|
|
169
|
+
/** Where a source's records come from: a pipeline (`linear.sync`, `cloudwatch.poll`,
|
|
170
|
+
* `postgres.cdc`, `tilde.events`, ...), `ingress()` or `rows()`. */
|
|
171
|
+
export type From<S extends string = string> = Pipeline<S> | IngressFrom;
|
|
169
172
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
173
|
+
* How a source stream is read. By default it is its **current state**: one row per key, the
|
|
174
|
+
* newest, keys whose newest row removes them dropped (a generated incremental model,
|
|
175
|
+
* `lake.sources.<source>__<stream>`, columns `_key`, `_newest`, `_pos`, `payload`; a
|
|
176
|
+
* `postgres.cdc` stream gets ducktail's CDC current state instead, columns `_key`, `_pos`, `_seq`,
|
|
177
|
+
* `_source_ts`, `payload`). `ref()` it, map objects onto it, `changes()` it.
|
|
175
178
|
*/
|
|
176
|
-
export
|
|
179
|
+
export interface StreamOptions {
|
|
180
|
+
/** The key: a payload property, `_key` (the default: the record's identity as ducktail writes
|
|
181
|
+
* it), or a SQL expression over the raw row. */
|
|
182
|
+
key?: string | Sql;
|
|
183
|
+
/** SQL over the raw row ordering a key's rows (the largest wins, then the latest position):
|
|
184
|
+
* default `_source_ts`, the record's own version, for the sync kinds, CloudWatch, webhooks and
|
|
185
|
+
* ingress; `_pos` for other polled kinds (Plaid, Gmail, ...), whose removals carry no time. A
|
|
186
|
+
* removal that loses its key's order is not applied until a newer one wins; an incremental
|
|
187
|
+
* build compares only with rows still held, so a late older row can bring a removed key back
|
|
188
|
+
* until a full build (the sync kinds' reconcile repairs it). */
|
|
189
|
+
newest?: string | Sql;
|
|
190
|
+
/** SQL over the raw row, true for a row that removes its key: default `_op = 'd'`. */
|
|
191
|
+
deleted?: string | Sql;
|
|
192
|
+
/** Also give the raw rows as `.history` (every version, as ingested). */
|
|
193
|
+
history?: boolean;
|
|
194
|
+
/** `false`: no current state; the stream is its raw rows (an append-only log). */
|
|
195
|
+
current?: false;
|
|
196
|
+
}
|
|
197
|
+
/** A stream of `ingress()` or `rows()`: records validated against `schema`, keyed by `key`. */
|
|
198
|
+
export interface IngressStreamOptions {
|
|
177
199
|
schema: z.ZodType;
|
|
200
|
+
/** A string or number property of the record. */
|
|
178
201
|
key: string;
|
|
179
|
-
|
|
180
|
-
|
|
202
|
+
/** The records the version ships (required with `rows()`). */
|
|
203
|
+
rows?: readonly unknown[];
|
|
204
|
+
history?: boolean;
|
|
205
|
+
current?: false;
|
|
206
|
+
}
|
|
207
|
+
/** A source stream as the definitions use it: its current state (a model), with `.history`
|
|
208
|
+
* where declared; with `current: false`, its raw rows. */
|
|
209
|
+
export type StreamOf<O> = O extends {
|
|
210
|
+
current: false;
|
|
211
|
+
} ? SourceDef : O extends {
|
|
212
|
+
history: true;
|
|
213
|
+
} ? ModelDef & {
|
|
214
|
+
readonly history: SourceDef;
|
|
215
|
+
} : ModelDef;
|
|
216
|
+
/** What `source()` declares: its name, where its records come from, and its streams. */
|
|
217
|
+
export interface SourceDecl {
|
|
218
|
+
readonly name: string;
|
|
219
|
+
readonly from: From;
|
|
220
|
+
/** Each declared stream's raw rows. */
|
|
221
|
+
readonly raw: readonly SourceDef[];
|
|
222
|
+
readonly loc: string | null;
|
|
223
|
+
}
|
|
224
|
+
/** A declared source: each stream under its name, plus the declaration. */
|
|
225
|
+
export type Source<St = Record<string, unknown>> = {
|
|
226
|
+
readonly [K in keyof St]: StreamOf<St[K]>;
|
|
227
|
+
} & {
|
|
228
|
+
readonly $source: SourceDecl;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* Every input of an ontology is a source: `source(name, { from, streams })`, where `from` is a
|
|
232
|
+
* pipeline (`linear.sync`, `github.sync`, `cloudwatch.poll`, `postgres.cdc`, `tilde.events`, your
|
|
233
|
+
* own `webhook()`, ...), `ingress()` or `rows()`, and `streams` names the streams it reads (typed
|
|
234
|
+
* by the pipeline) and how. `linear.issues` is then the current state of Linear's issues. List
|
|
235
|
+
* sources in `ontology({ sources })`. The name is the pipeline's state (cursors, backfills) and
|
|
236
|
+
* its raw tables' prefix (`lake.raw.<name>__<stream>`): renaming one starts it over.
|
|
237
|
+
*/
|
|
238
|
+
export declare function source<const S extends string, const St extends {
|
|
239
|
+
readonly [K in S]?: StreamOptions;
|
|
240
|
+
}>(name: string, spec: {
|
|
241
|
+
from: Pipeline<S>;
|
|
242
|
+
streams: St & {
|
|
243
|
+
readonly [K in Exclude<keyof St, S>]: never;
|
|
244
|
+
};
|
|
245
|
+
}): Source<St>;
|
|
246
|
+
export declare function source<const St extends {
|
|
247
|
+
readonly [name: string]: IngressStreamOptions;
|
|
248
|
+
}>(name: string, spec: {
|
|
249
|
+
from: IngressFrom;
|
|
250
|
+
streams: St;
|
|
251
|
+
}): Source<St>;
|
|
181
252
|
/** The SQL builder context of a model: evaluated twice, once per `isIncremental`. */
|
|
182
253
|
export interface ModelSqlCtx {
|
|
183
254
|
/** `lake.<schema>.<name>` of another model (a dependency), or an object type's table: the
|
|
@@ -251,10 +322,19 @@ export interface ModelIndex {
|
|
|
251
322
|
unique?: boolean;
|
|
252
323
|
method?: "btree" | "gin" | "gist" | "hash" | "brin";
|
|
253
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* What a model is for, checked by the build. `staging`: cleanup of sources (casts, renames,
|
|
327
|
+
* dedup, unnesting), private: only other models `ref()` it. It backs no object, so it is not in
|
|
328
|
+
* the object schema, but lineage docs still show it. `model`: the domain; the only kind that backs an object. `projection`: a
|
|
329
|
+
* read-shaped table over objects or models (a grid, with indexes and search) for reads and
|
|
330
|
+
* realtime; never an object's source.
|
|
331
|
+
*/
|
|
332
|
+
export type ModelType = "staging" | "model" | "projection";
|
|
254
333
|
export interface ModelSpec<C extends Props> {
|
|
255
334
|
name: string;
|
|
335
|
+
type: ModelType;
|
|
256
336
|
schema?: string;
|
|
257
|
-
|
|
337
|
+
materialization: "view" | "table" | "incremental" | "cell" | "microbatch";
|
|
258
338
|
/** `microbatch` models (Postgres storage): built batch by batch of `eventTime` from `begin`
|
|
259
339
|
* (a date, an RFC 3339 time or a duration before now; default: ducktail's `[backfill] start`),
|
|
260
340
|
* each batch replaced as a whole; the SQL filters its inputs with `batchStart` / `batchEnd`. */
|
|
@@ -296,23 +376,38 @@ export declare class ModelDef<C extends Props = Props> {
|
|
|
296
376
|
} | null;
|
|
297
377
|
constructor(spec: ModelSpec<C>, loc: string | null);
|
|
298
378
|
}
|
|
299
|
-
|
|
379
|
+
type Generated = "materialization" | "sql" | "uniqueKey" | "incrementalStrategy" | "columns" | "microbatch";
|
|
300
380
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
381
|
+
* `materialization: "diffed"`: a table recomputed from its upstreams' full state (`sql`) on every
|
|
382
|
+
* run that writes only the rows that differ from what it holds and deletes the keys that
|
|
383
|
+
* disappeared, so `changes()` over it (and realtime watches) stay as small as the real change.
|
|
384
|
+
* `gate` gives a row when the run must recompute (its upstreams' `changes`); without one, every
|
|
385
|
+
* run does. Stored as an incremental model.
|
|
306
386
|
*/
|
|
307
|
-
export
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
sql: (
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
387
|
+
export interface DiffedModelSpec<C extends Props> extends Omit<ModelSpec<C>, Generated> {
|
|
388
|
+
materialization: "diffed";
|
|
389
|
+
key: string;
|
|
390
|
+
columns: C;
|
|
391
|
+
sql: (ctx: Pick<ModelSqlCtx, "ref" | "src" | "dialect">) => Sql;
|
|
392
|
+
gate?: (ctx: Pick<ModelSqlCtx, "ref" | "changes">) => Sql;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* `materialization: "cell"` recomputed per touched key: `rows(filter)` selects the rows for the
|
|
396
|
+
* keys a SQL predicate admits (`filter` takes the caller's key expression), `touched` the keys
|
|
397
|
+
* (column `k`) any upstream change may affect. Rows of a touched key that no longer come out
|
|
398
|
+
* are deleted. `partition` is the column `touched` keys match, when it is not `key`.
|
|
399
|
+
*/
|
|
400
|
+
export interface RecomputedCellModelSpec<C extends Props> extends Omit<ModelSpec<C>, Generated> {
|
|
401
|
+
materialization: "cell";
|
|
402
|
+
key: string;
|
|
403
|
+
partition?: string;
|
|
404
|
+
columns: C;
|
|
405
|
+
rows: (ctx: Pick<ModelSqlCtx, "ref" | "src" | "dialect"> & {
|
|
406
|
+
filter: (keyExpr: string) => Sql;
|
|
407
|
+
}) => Sql;
|
|
408
|
+
touched: (ctx: Pick<ModelSqlCtx, "ref" | "changes" | "self">) => Sql;
|
|
409
|
+
}
|
|
410
|
+
export declare function model<C extends Props = Props>(spec: ModelSpec<C> | DiffedModelSpec<C> | RecomputedCellModelSpec<C>): ModelDef<C>;
|
|
316
411
|
/** A reference to one property of an object type (`Customer.notes`). */
|
|
317
412
|
export interface PropRef<O extends string = string, F extends string = string, P = Prop<unknown, boolean, boolean>> {
|
|
318
413
|
readonly kind: "prop";
|
|
@@ -332,6 +427,7 @@ type ObjectInternals<N extends string, P extends Props, K extends keyof P & stri
|
|
|
332
427
|
history?: boolean;
|
|
333
428
|
historyAt?: string;
|
|
334
429
|
replicas?: string[];
|
|
430
|
+
signals?: readonly SignalChange[];
|
|
335
431
|
};
|
|
336
432
|
readonly $loc: string | null;
|
|
337
433
|
/** Type-level only: the object row handlers see. */
|
|
@@ -351,6 +447,7 @@ export interface AnyObject {
|
|
|
351
447
|
history?: boolean;
|
|
352
448
|
historyAt?: string;
|
|
353
449
|
replicas?: string[];
|
|
450
|
+
signals?: readonly SignalChange[];
|
|
354
451
|
};
|
|
355
452
|
readonly $loc: string | null;
|
|
356
453
|
readonly $row: any;
|
|
@@ -370,6 +467,10 @@ export type ObjectDef<N extends string = string, P extends Props = Props, K exte
|
|
|
370
467
|
* read there (`ctx.lake.destination(<name>).query`): read-only (no owned properties, no
|
|
371
468
|
* history), its mappings ClickHouse SQL. `replicas: ["events"]` keeps a copy of a storage
|
|
372
469
|
* object's table in that destination, so SQL there can join it.
|
|
470
|
+
*
|
|
471
|
+
* `signals: ["created"]` (Postgres storage) makes those changes of the object signals of the
|
|
472
|
+
* environment's own Tilde connection (`tilde_ontology/<project>-<environment>`), which an
|
|
473
|
+
* agent's routine subscribes to like any connection's: see `signal`.
|
|
373
474
|
*/
|
|
374
475
|
export declare function object<const N extends string, P extends Props, const K extends keyof P & string>(name: N, spec: {
|
|
375
476
|
id: string;
|
|
@@ -380,7 +481,31 @@ export declare function object<const N extends string, P extends Props, const K
|
|
|
380
481
|
history?: boolean;
|
|
381
482
|
historyAt?: keyof P & string;
|
|
382
483
|
replicas?: string[];
|
|
484
|
+
signals?: readonly SignalChange[];
|
|
383
485
|
}): ObjectDef<N, P, K>;
|
|
486
|
+
/** A change of an object that can be a signal (`object({ signals })`). */
|
|
487
|
+
export type SignalChange = "created" | "updated" | "deleted";
|
|
488
|
+
/** A signal's data: the object's properties by API name, as JSON (keys, refs, decimals, dates and
|
|
489
|
+
* timestamps as text). For `deleted`, as they last were. */
|
|
490
|
+
export type SignalData<O extends AnyObject> = O["$row"];
|
|
491
|
+
/** One signal of an object, for the routine that takes it (`@trytilde/iac`'s
|
|
492
|
+
* `signal: { connection, type, filters }`): its `type` on the environment's connection. `$data`
|
|
493
|
+
* exists at the type level only. */
|
|
494
|
+
export interface SignalRef<O extends AnyObject = AnyObject> {
|
|
495
|
+
readonly kind: "signal";
|
|
496
|
+
readonly object: string;
|
|
497
|
+
readonly change: SignalChange;
|
|
498
|
+
/** `tilde_ontology.<object id>.<change>`. */
|
|
499
|
+
readonly type: string;
|
|
500
|
+
readonly $data: SignalData<O>;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* A signal the object declares. Tilde delivers each one at least once and, per object, in
|
|
504
|
+
* order; changes that reach the storage together are one signal (an object created and deleted
|
|
505
|
+
* at once is none), and an object that existed before it declared signals emits `created` for
|
|
506
|
+
* none of its rows. A routine's filters and templates name the data's keys (`{{ stage }}`).
|
|
507
|
+
*/
|
|
508
|
+
export declare function signal<O extends AnyObject>(object: O, change: SignalChange): SignalRef<O>;
|
|
384
509
|
/** An object type's change history (`history: true`): the relation `lake.ontology.<id>__changes`,
|
|
385
510
|
* which a view-less read declares in its `reads`, and Cedar's `Model::"<id>__changes"` (what
|
|
386
511
|
* `query` is decided on). */
|
|
@@ -517,54 +642,37 @@ export interface EnvDef {
|
|
|
517
642
|
export declare const secret: () => EnvDef;
|
|
518
643
|
export declare const setting: (defaultValue?: string) => EnvDef;
|
|
519
644
|
/**
|
|
520
|
-
* A
|
|
521
|
-
*
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
*
|
|
525
|
-
*
|
|
526
|
-
*
|
|
645
|
+
* A third-party account the project needs, which each environment binds to one of its
|
|
646
|
+
* organization's Tilde connections of that provider (and type, when given). Declared as plain
|
|
647
|
+
* data, keyed by name: `export const connections = { linear: { provider: "linear" } } satisfies
|
|
648
|
+
* Connections`, passed to `ontology({ connections })`. Name one as a request's `auth`
|
|
649
|
+
* (`deferredFetch(url, init, { auth: connections.linear })`, a read's
|
|
650
|
+
* `ctx.authHeaders(connections.linear)`): the runtime gets the account's current credentials
|
|
651
|
+
* from the control plane when the request is sent and sets them as headers. Handlers never see
|
|
652
|
+
* them. Pipelines take the same object (`linear.poll({ connection: connections.linear })`).
|
|
527
653
|
*/
|
|
528
|
-
export interface
|
|
529
|
-
readonly kind: "connection";
|
|
530
|
-
/** The slot's name (snake_case), unique among slots and `auth` resolvers. */
|
|
531
|
-
readonly name: string;
|
|
654
|
+
export interface Connection<P extends string = string> {
|
|
532
655
|
/** The Tilde connection provider (`linear`, `github`, `sentry`, `aws`, ...). */
|
|
533
|
-
readonly provider: string;
|
|
534
|
-
/** One of the provider's connection types (`api_key`, `oauth`, ...); null accepts any. */
|
|
535
|
-
readonly type: string | null;
|
|
536
|
-
readonly loc: string | null;
|
|
537
|
-
}
|
|
538
|
-
/** A connection slot; `provider` defaults to the slot's name. */
|
|
539
|
-
export declare function connection(name: string, options?: {
|
|
540
|
-
provider?: string;
|
|
541
|
-
type?: string;
|
|
542
|
-
}): ConnectionDef;
|
|
543
|
-
/** A slot as `slot()` makes it, named by `defineSlots`. */
|
|
544
|
-
export interface SlotSpec<P extends string = string> {
|
|
545
|
-
readonly kind: "slot";
|
|
546
|
-
readonly provider: P;
|
|
547
|
-
readonly type: string | null;
|
|
548
|
-
readonly loc: string | null;
|
|
549
|
-
}
|
|
550
|
-
/** A declared connection slot whose provider is `P` (`defineSlots`). */
|
|
551
|
-
export interface Slot<P extends string = string> extends ConnectionDef {
|
|
552
656
|
readonly provider: P;
|
|
657
|
+
/** One of the provider's connection types (`api_key`, `oauth`, ...); absent accepts any. */
|
|
658
|
+
readonly type?: string;
|
|
659
|
+
/**
|
|
660
|
+
* An environment may leave it unbound: it deploys without it, the pipelines that name it are
|
|
661
|
+
* skipped until it is bound and the project deployed again, and a request sent through it
|
|
662
|
+
* meanwhile fails saying so. A required connection (the default) must be bound before a deploy.
|
|
663
|
+
*/
|
|
664
|
+
readonly optional?: boolean;
|
|
553
665
|
}
|
|
554
|
-
/** A connection slot of a Tilde connection provider (and optionally one of its types), named by
|
|
555
|
-
* its key in `defineSlots`. */
|
|
556
|
-
export declare function slot<const P extends string>(provider: P, options?: {
|
|
557
|
-
type?: string;
|
|
558
|
-
}): SlotSpec<P>;
|
|
559
666
|
/**
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
* helper takes only a
|
|
563
|
-
* connections, and `ontology({ slots })` declares them.
|
|
667
|
+
* An ontology's connections by name. `satisfies Connections` keeps each provider's literal type
|
|
668
|
+
* (the catalog's providers in the union give TypeScript a literal context; `string & {}` admits
|
|
669
|
+
* any other), so a pipeline helper takes only a connection of its provider.
|
|
564
670
|
*/
|
|
565
|
-
export
|
|
566
|
-
readonly [
|
|
671
|
+
export type Connections = {
|
|
672
|
+
readonly [name: string]: Connection<PolledProvider[PolledKind] | WebhookProvider | (string & {})>;
|
|
567
673
|
};
|
|
674
|
+
/** The name of a connection `ontology({ connections })` declares, or of an `auth` resolver. */
|
|
675
|
+
export declare function authName(auth: Connection | AuthDef): string;
|
|
568
676
|
/** A declared raw secret (`defineSecrets`), which pipelines take where ducktail wants a secret. */
|
|
569
677
|
export interface SecretRef<N extends string = string> {
|
|
570
678
|
readonly kind: "secretRef";
|
|
@@ -594,13 +702,13 @@ export type PipelineValue = string | number | boolean | SecretRef | SecretText |
|
|
|
594
702
|
};
|
|
595
703
|
/**
|
|
596
704
|
* What feeds a source's raw streams (`lake.raw.<source>__<stream>`): one ducktail pipeline of
|
|
597
|
-
* `type`, optionally through a connection
|
|
705
|
+
* `type`, optionally through a connection, with its streams and ducktail's own config keys
|
|
598
706
|
* (`options`, snake_case as ducktail's README writes them). Made by the helpers below; the build
|
|
599
707
|
* compiles it into the version and the environment's rollout gives it to ducktail.
|
|
600
708
|
*/
|
|
601
709
|
export declare class Pipeline<S extends string = string> {
|
|
602
710
|
readonly type: string;
|
|
603
|
-
readonly
|
|
711
|
+
readonly connection: Connection | null;
|
|
604
712
|
readonly streams: readonly S[];
|
|
605
713
|
readonly options: {
|
|
606
714
|
readonly [key: string]: PipelineValue | undefined;
|
|
@@ -609,7 +717,7 @@ export declare class Pipeline<S extends string = string> {
|
|
|
609
717
|
/** The name the source must have (Tilde's registry events post to `tilde`), else null. */
|
|
610
718
|
readonly name: string | null;
|
|
611
719
|
readonly kind = "pipeline";
|
|
612
|
-
constructor(type: string,
|
|
720
|
+
constructor(type: string, connection: Connection | null, streams: readonly S[], options: {
|
|
613
721
|
readonly [key: string]: PipelineValue | undefined;
|
|
614
722
|
}, loc: string | null,
|
|
615
723
|
/** The name the source must have (Tilde's registry events post to `tilde`), else null. */
|
|
@@ -624,20 +732,8 @@ export declare class WebhookPipeline<S extends string = string, E extends string
|
|
|
624
732
|
readonly [event: string]: NoInfer<S>;
|
|
625
733
|
}): WebhookPipeline<S, E>;
|
|
626
734
|
}
|
|
627
|
-
/**
|
|
628
|
-
|
|
629
|
-
readonly name: string;
|
|
630
|
-
readonly pipeline: Pipeline<S>;
|
|
631
|
-
readonly loc: string | null;
|
|
632
|
-
readonly kind = "pipelineSource";
|
|
633
|
-
constructor(name: string, pipeline: Pipeline<S>, loc: string | null);
|
|
634
|
-
/** One of the pipeline's streams: `lake.raw.<name>__<stream>`. */
|
|
635
|
-
stream(stream: S): SourceDef;
|
|
636
|
-
}
|
|
637
|
-
/** Polled options every polled kind takes. */
|
|
638
|
-
interface PollOptions<St extends string> {
|
|
639
|
-
/** The streams to poll (default: all of the kind's). */
|
|
640
|
-
streams?: readonly St[];
|
|
735
|
+
/** Polled options every polled kind takes. The streams it polls are the source's. */
|
|
736
|
+
interface PollOptions {
|
|
641
737
|
interval?: Duration;
|
|
642
738
|
/** Where the first sweep starts: a date, an RFC 3339 time or a duration before now. */
|
|
643
739
|
backfill?: {
|
|
@@ -645,53 +741,85 @@ interface PollOptions<St extends string> {
|
|
|
645
741
|
};
|
|
646
742
|
requestTimeout?: Duration;
|
|
647
743
|
}
|
|
648
|
-
/**
|
|
744
|
+
/**
|
|
745
|
+
* A provider sync (ducktail's sync pipelines): one stream per entity, merging a backfill on the
|
|
746
|
+
* first run, the connection's webhooks (`webhook`, default on) and, where the provider takes
|
|
747
|
+
* it, a slow reconciling poll (`reconcile`; default 1h with webhooks, 60s without). Each row's
|
|
748
|
+
* `_key` is the entity and `_source_ts` its own version, so the source's streams are current
|
|
749
|
+
* state with no options.
|
|
750
|
+
*/
|
|
751
|
+
interface SyncOptions {
|
|
752
|
+
webhook?: boolean;
|
|
753
|
+
reconcile?: Duration;
|
|
754
|
+
/** Where the backfill starts: a date, an RFC 3339 time or a duration before now. */
|
|
755
|
+
backfill?: {
|
|
756
|
+
start: string;
|
|
757
|
+
};
|
|
758
|
+
requestTimeout?: Duration;
|
|
759
|
+
}
|
|
760
|
+
/** A provider webhook's routing: event name -> stream, the rest to `fallback`. The streams are
|
|
761
|
+
* the routes' (and the fallback's). */
|
|
649
762
|
interface WebhookOptions<P extends keyof WebhookEvents, S extends string> {
|
|
650
|
-
|
|
651
|
-
/** The pipeline's streams. */
|
|
652
|
-
streams: readonly S[];
|
|
763
|
+
connection: Connection<P>;
|
|
653
764
|
/** Event -> stream; events not listed go to `fallback` (without one, ducktail answers 422). */
|
|
654
765
|
route: {
|
|
655
|
-
readonly [E in WebhookEvents[P]]?:
|
|
766
|
+
readonly [E in WebhookEvents[P]]?: S;
|
|
656
767
|
};
|
|
657
|
-
fallback?:
|
|
768
|
+
fallback?: S;
|
|
658
769
|
}
|
|
659
|
-
/** Linear:
|
|
770
|
+
/** Linear: a sync (webhooks, backfill, reconcile), polled GraphQL alone, or the raw webhooks. */
|
|
660
771
|
export declare const linear: {
|
|
661
|
-
|
|
662
|
-
|
|
772
|
+
sync: (o: SyncOptions & {
|
|
773
|
+
connection: Connection<"linear">;
|
|
774
|
+
pageSize?: number;
|
|
775
|
+
fields?: { readonly [K in SyncStreams["linear"]]?: string; };
|
|
776
|
+
endpoint?: string;
|
|
777
|
+
}) => Pipeline<"teams" | "users" | "workflow_states" | "projects" | "cycles" | "issues" | "comments">;
|
|
778
|
+
poll: (o: PollOptions & {
|
|
779
|
+
connection: Connection<"linear">;
|
|
663
780
|
pageSize?: number;
|
|
664
781
|
/** A stream's GraphQL selection, replacing the built-in one. */
|
|
665
782
|
fields?: { readonly [K in PolledStreams["linear"]]?: string; };
|
|
666
783
|
endpoint?: string;
|
|
667
|
-
}) => Pipeline<
|
|
784
|
+
}) => Pipeline<"teams" | "users" | "workflow_states" | "projects" | "cycles" | "issues" | "comments">;
|
|
668
785
|
webhook: <const S extends string>(o: WebhookOptions<"linear", S>) => WebhookPipeline<S, "Attachment" | "AuditEntry" | "Comment" | "Customer" | "CustomerNeed" | "Cycle" | "Document" | "Initiative" | "InitiativeUpdate" | "Issue" | "IssueLabel" | "IssueSLA" | "OAuthApp" | "Project" | "ProjectUpdate" | "Reaction" | "User">;
|
|
669
786
|
};
|
|
670
|
-
|
|
787
|
+
interface SentryOptions {
|
|
788
|
+
connection: Connection<"sentry">;
|
|
789
|
+
organization: string;
|
|
790
|
+
/** Project slugs whose issues are read. */
|
|
791
|
+
projects?: readonly string[];
|
|
792
|
+
/** `https://sentry.io` (default), a regional host or self-hosted Sentry. */
|
|
793
|
+
baseUrl?: string;
|
|
794
|
+
query?: string;
|
|
795
|
+
}
|
|
796
|
+
/** Sentry: a sync (integration webhooks, backfill, reconcile), polled issues alone, or the raw webhooks. */
|
|
671
797
|
export declare const sentry: {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
organization: string;
|
|
675
|
-
/** Project slugs whose issues are polled. */
|
|
676
|
-
projects?: readonly string[];
|
|
677
|
-
/** `https://sentry.io` (default), a regional host or self-hosted Sentry. */
|
|
678
|
-
baseUrl?: string;
|
|
679
|
-
query?: string;
|
|
798
|
+
sync: (o: SyncOptions & SentryOptions) => Pipeline<"projects" | "issues">;
|
|
799
|
+
poll: (o: PollOptions & SentryOptions & {
|
|
680
800
|
fullSweepInterval?: Duration;
|
|
681
|
-
}) => Pipeline<
|
|
801
|
+
}) => Pipeline<"projects" | "issues">;
|
|
682
802
|
webhook: <const S extends string>(o: WebhookOptions<"sentry", S>) => WebhookPipeline<S, "installation" | "comment" | "error" | "event_alert" | "issue" | "metric_alert" | "seer">;
|
|
683
803
|
};
|
|
684
|
-
/** GitHub:
|
|
804
|
+
/** GitHub: a sync of the repositories, or the connection's raw webhooks. */
|
|
685
805
|
export declare const github: {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
806
|
+
/**
|
|
807
|
+
* One stream per entity: the connection's webhooks for the repositories, after a backfill of
|
|
808
|
+
* their recent pull requests, reviews, check runs and releases on the first run (default 30
|
|
809
|
+
* days). Each row's `_key` is the entity (`{repository, number}` for pull requests, else
|
|
810
|
+
* `{id}`) and `_source_ts` its own time; the payload is the webhook body. Never reconciles:
|
|
811
|
+
* GitHub's webhooks are complete. Only the listed repositories are written: deliveries from
|
|
812
|
+
* any other repository the App is installed on are dropped.
|
|
813
|
+
*/
|
|
814
|
+
sync: (o: Omit<SyncOptions, "reconcile" | "webhook"> & {
|
|
815
|
+
connection: Connection<"github">;
|
|
816
|
+
/** `owner/name`: backfilled (each once, by its own job), and the only repositories written. */
|
|
817
|
+
repositories: readonly string[];
|
|
818
|
+
baseUrl?: string;
|
|
819
|
+
pageSize?: number;
|
|
820
|
+
}) => Pipeline<"pull_requests" | "pull_request_reviews" | "check_runs" | "releases">;
|
|
821
|
+
/** The connection's webhooks as raw event streams, routed by `X-GitHub-Event`. */
|
|
822
|
+
webhook: <const S extends string>(o: WebhookOptions<"github", S>) => WebhookPipeline<S, "issues" | "check_run" | "check_suite" | "code_scanning_alert" | "create" | "delete" | "dependabot_alert" | "deployment" | "deployment_status" | "discussion" | "discussion_comment" | "fork" | "installation" | "installation_repositories" | "issue_comment" | "label" | "member" | "merge_group" | "milestone" | "ping" | "pull_request" | "pull_request_review" | "pull_request_review_comment" | "pull_request_review_thread" | "push" | "release" | "repository" | "secret_scanning_alert" | "status" | "workflow_job" | "workflow_run">;
|
|
695
823
|
};
|
|
696
824
|
/** A CloudWatch metric (`AWS/RDS` `CPUUtilization` ...). */
|
|
697
825
|
export interface CloudwatchMetric {
|
|
@@ -705,8 +833,8 @@ export interface CloudwatchMetric {
|
|
|
705
833
|
}
|
|
706
834
|
/** AWS: ECS and ELBv2 discovery, CloudWatch metrics and alarms, through an `aws` connection. */
|
|
707
835
|
export declare const cloudwatch: {
|
|
708
|
-
poll:
|
|
709
|
-
|
|
836
|
+
poll: (o: PollOptions & {
|
|
837
|
+
connection: Connection<PolledProvider["cloudwatch"]>;
|
|
710
838
|
region: string;
|
|
711
839
|
discoveryInterval?: Duration;
|
|
712
840
|
period?: Duration;
|
|
@@ -724,16 +852,16 @@ export declare const cloudwatch: {
|
|
|
724
852
|
discoverMetrics?: boolean;
|
|
725
853
|
metrics?: readonly CloudwatchMetric[];
|
|
726
854
|
endpoint?: string;
|
|
727
|
-
}) => Pipeline<
|
|
855
|
+
}) => Pipeline<"ecs_clusters" | "ecs_services" | "load_balancers" | "target_groups" | "target_health" | "metric_data" | "alarms" | "alarm_history">;
|
|
728
856
|
};
|
|
729
857
|
/** Another polled kind (Plaid, QuickBooks, Xero, Gmail, Google Calendar and Contacts, Slack):
|
|
730
858
|
* `options` are ducktail's keys for it (README, "Polled sources"). */
|
|
731
|
-
export declare function polled<K extends Exclude<PolledKind, "linear" | "sentry" | "cloudwatch"
|
|
732
|
-
|
|
859
|
+
export declare function polled<K extends Exclude<PolledKind, "linear" | "sentry" | "cloudwatch">>(kind: K, o: PollOptions & {
|
|
860
|
+
connection: Connection<PolledProvider[K]>;
|
|
733
861
|
options?: {
|
|
734
862
|
readonly [key: string]: PipelineValue | undefined;
|
|
735
863
|
};
|
|
736
|
-
}): Pipeline<
|
|
864
|
+
}): Pipeline<PolledStreams[K]>;
|
|
737
865
|
/** Postgres logical replication of tables (streams `<schema>_<table>`). */
|
|
738
866
|
export declare const postgres: {
|
|
739
867
|
cdc: <const T extends string>(o: {
|
|
@@ -771,19 +899,18 @@ export declare const kafka: {
|
|
|
771
899
|
};
|
|
772
900
|
/**
|
|
773
901
|
* A webhook pipeline of the solution's own, which Tilde delivers to (records written through
|
|
774
|
-
* Ingress, a system posting at Tilde): `POST /webhooks/<source>/<stream
|
|
775
|
-
* a header.
|
|
902
|
+
* Ingress, a system posting at Tilde): `POST /webhooks/<source>/<stream>` for each stream the
|
|
903
|
+
* source declares, or one URL routed by a header (its streams are then the routes').
|
|
776
904
|
*/
|
|
777
|
-
export declare function webhook<const S extends string>(o
|
|
778
|
-
streams: readonly S[];
|
|
905
|
+
export declare function webhook<const S extends string = string>(o?: {
|
|
779
906
|
/** The header whose value keys deliveries (`_key = {"id": ...}`). */
|
|
780
907
|
keyHeader?: string;
|
|
781
908
|
route?: {
|
|
782
909
|
header: string;
|
|
783
910
|
streams: {
|
|
784
|
-
readonly [value: string]:
|
|
911
|
+
readonly [value: string]: S;
|
|
785
912
|
};
|
|
786
|
-
fallback?:
|
|
913
|
+
fallback?: S;
|
|
787
914
|
};
|
|
788
915
|
}): Pipeline<S>;
|
|
789
916
|
/** The tables Tilde's registry events deliver (`tilde.events`). */
|
|
@@ -792,12 +919,10 @@ export type RegistryStream = "public_chat_threads" | "public_chat_runs" | "publi
|
|
|
792
919
|
export declare const tilde: {
|
|
793
920
|
/**
|
|
794
921
|
* The organization's registry events (threads, runs, tasks, invocations, inference usage,
|
|
795
|
-
* messages...), pushed by Tilde to environments that turn them on: only the streams
|
|
796
|
-
* are delivered. The source must be named `tilde`.
|
|
922
|
+
* messages...), pushed by Tilde to environments that turn them on: only the streams the
|
|
923
|
+
* source declares are delivered. The source must be named `tilde`.
|
|
797
924
|
*/
|
|
798
|
-
events:
|
|
799
|
-
streams: readonly S[];
|
|
800
|
-
}) => Pipeline<S>;
|
|
925
|
+
events: () => Pipeline<RegistryStream>;
|
|
801
926
|
};
|
|
802
927
|
/** Options of `ctx.deferredFetch`. */
|
|
803
928
|
export interface DeferredOptions {
|
|
@@ -810,8 +935,8 @@ export interface DeferredOptions {
|
|
|
810
935
|
values: Record<string, Json>;
|
|
811
936
|
};
|
|
812
937
|
/** Headers resolved when the request is sent (fresh credentials on every attempt): a
|
|
813
|
-
* connection
|
|
814
|
-
auth?: AuthDef |
|
|
938
|
+
* connection's or an `auth` resolver's. The outbox stores only the name. */
|
|
939
|
+
auth?: AuthDef | Connection;
|
|
815
940
|
/** An action of the same view to run once the request is delivered (2xx), with the
|
|
816
941
|
* response as its input (`deferredResponse`); declare it in the action's `continuations`. */
|
|
817
942
|
then?: HandlerDef;
|
|
@@ -903,11 +1028,11 @@ export interface BaseCtx {
|
|
|
903
1028
|
/** Headers from an `auth` resolver, for live calls (cached like the outbox's). A connection's
|
|
904
1029
|
* credentials are never handed to handlers: send with `fetch`. */
|
|
905
1030
|
authHeaders(auth: AuthDef): Promise<Record<string, string>>;
|
|
906
|
-
/** `fetch`, with the headers of a connection
|
|
1031
|
+
/** `fetch`, with the headers of a connection or an `auth` resolver set by the runtime
|
|
907
1032
|
* (replacing the request's): the handler gets the response, never the credentials. A 401 or
|
|
908
1033
|
* 403 drops the cached credentials. */
|
|
909
1034
|
fetch(input: string | URL | Request, init?: RequestInit, options?: {
|
|
910
|
-
auth?: AuthDef |
|
|
1035
|
+
auth?: AuthDef | Connection;
|
|
911
1036
|
}): Promise<Response>;
|
|
912
1037
|
/** Fail with `message` unless `condition` holds (a precondition). To narrow a value, use
|
|
913
1038
|
* `if (!x) return ctx.fail(...)` (assertion signatures do not survive destructuring). */
|
|
@@ -936,7 +1061,7 @@ export interface ReadCtx extends BaseCtx {
|
|
|
936
1061
|
}
|
|
937
1062
|
/** An action's ctx. No `authHeaders` or `fetch`: credentials an action could read could end up
|
|
938
1063
|
* in a deferred request and be stored, and its calls to third parties are deferred; deferred
|
|
939
|
-
* requests name their
|
|
1064
|
+
* requests name their connection or resolver (`{ auth }`). */
|
|
940
1065
|
export interface TxCtx extends Omit<ReadCtx, "authHeaders" | "fetch"> {
|
|
941
1066
|
readonly invocationId: string;
|
|
942
1067
|
readonly deferredFetch: DeferredFetch;
|
|
@@ -960,7 +1085,66 @@ export interface HandlerDef<N extends string = string, I extends z.ZodType = z.Z
|
|
|
960
1085
|
readonly output: O;
|
|
961
1086
|
readonly idempotency?: (input: any) => string;
|
|
962
1087
|
readonly handler: (args: any) => unknown;
|
|
1088
|
+
/** A list realtime view's parts (see `realtime`); the runtime runs these, not `handler`. */
|
|
1089
|
+
readonly list?: ListDef;
|
|
963
1090
|
}
|
|
1091
|
+
/** A value a list row sorts by (see `realtime`). */
|
|
1092
|
+
export type OrderValue = string | number | boolean | null;
|
|
1093
|
+
/** Which rows a list view's `rows` returns: those of `keys` the query matches (any order), or
|
|
1094
|
+
* the first `limit` rows in order after the row whose `order` is `after` (null: from the top). */
|
|
1095
|
+
export type ListSelect = {
|
|
1096
|
+
keys: string[];
|
|
1097
|
+
after?: undefined;
|
|
1098
|
+
limit?: undefined;
|
|
1099
|
+
} | {
|
|
1100
|
+
keys?: undefined;
|
|
1101
|
+
after: OrderValue[] | null;
|
|
1102
|
+
limit: number;
|
|
1103
|
+
};
|
|
1104
|
+
export interface ListDef {
|
|
1105
|
+
key: string;
|
|
1106
|
+
row: z.ZodType;
|
|
1107
|
+
order: (query: any) => {
|
|
1108
|
+
by: (row: any) => OrderValue[];
|
|
1109
|
+
desc?: boolean;
|
|
1110
|
+
};
|
|
1111
|
+
rows: (args: any) => unknown;
|
|
1112
|
+
summary?: {
|
|
1113
|
+
output: z.ZodType;
|
|
1114
|
+
handler: (args: any) => unknown;
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
/** The most rows a list view's window holds. */
|
|
1118
|
+
export declare const LIST_MAX = 1000;
|
|
1119
|
+
/** What a list view's subscriber sends: its query, how many rows from the top it shows, and
|
|
1120
|
+
* `resume` (the last update's), when widening a window it already has or reconnecting. */
|
|
1121
|
+
export declare const listInput: <I extends z.ZodType>(query: I) => z.ZodObject<{
|
|
1122
|
+
query: I;
|
|
1123
|
+
limit: z.ZodNumber;
|
|
1124
|
+
resume: z.ZodDefault<z.ZodString>;
|
|
1125
|
+
}, z.core.$strip>;
|
|
1126
|
+
declare const listUpdateShape: <R extends z.ZodType>(row: R) => {
|
|
1127
|
+
/** Drop the rows held: this update holds the whole window (the first, unless resumed). */
|
|
1128
|
+
reset: z.ZodBoolean;
|
|
1129
|
+
/** Rows that entered or changed, each at its index in the new window. */
|
|
1130
|
+
upserts: z.ZodArray<z.ZodObject<{
|
|
1131
|
+
key: z.ZodString;
|
|
1132
|
+
index: z.ZodNumber;
|
|
1133
|
+
row: R;
|
|
1134
|
+
}, z.core.$strip>>;
|
|
1135
|
+
/** Keys of rows that left the window. */
|
|
1136
|
+
removes: z.ZodArray<z.ZodString>;
|
|
1137
|
+
/** Rows exist past the window. */
|
|
1138
|
+
more: z.ZodBoolean;
|
|
1139
|
+
/** Pass back as `resume` to widen this window without starting over. */
|
|
1140
|
+
resume: z.ZodString;
|
|
1141
|
+
};
|
|
1142
|
+
type ListUpdateShape<R extends z.ZodType, S extends z.ZodType | undefined> = ReturnType<typeof listUpdateShape<R>> & (S extends z.ZodType ? {
|
|
1143
|
+
summary: z.ZodOptional<S>;
|
|
1144
|
+
} : Record<never, never>);
|
|
1145
|
+
/** A list view's update: what changed in the window since the last one (see `realtime`).
|
|
1146
|
+
* `summary` is present on a reset and when it changed. */
|
|
1147
|
+
export declare const listUpdate: <R extends z.ZodType, S extends z.ZodType | undefined>(row: R, summary?: S) => z.ZodObject<ListUpdateShape<R, S>>;
|
|
964
1148
|
/** A transactional write in one view instance. `edits` and `reads` are hard limits. */
|
|
965
1149
|
export declare function action<const N extends string, V extends ViewDef, I extends z.ZodType, O extends z.ZodType>(name: N, spec: {
|
|
966
1150
|
description?: string;
|
|
@@ -1045,6 +1229,44 @@ export declare function realtime<const N extends string, I extends z.ZodType, O
|
|
|
1045
1229
|
ctx: LakeReadCtx;
|
|
1046
1230
|
}) => z.input<O> | Promise<z.input<O>>;
|
|
1047
1231
|
}): HandlerDef<N, I, O, false>;
|
|
1232
|
+
/**
|
|
1233
|
+
* - **list** (`watch` with `row`, `key`, `order` and `rows` instead of `output` and `handler`): a
|
|
1234
|
+
* window of rows from the top of an ordered list, kept by deltas. A subscriber sends `{ query,
|
|
1235
|
+
* limit, resume }`; the first update holds the window (`reset`), later ones only the rows that
|
|
1236
|
+
* entered or changed (`upserts`, each with its index in the new window), the keys that left
|
|
1237
|
+
* (`removes`), whether more rows follow (`more`) and the `summary` when it changed. On Postgres
|
|
1238
|
+
* storage a commit to a watched model re-reads only the keys it changed (from the model's
|
|
1239
|
+
* change feed; `rows` with `keys`), as the subscriber, so Cedar and masking hold; anything
|
|
1240
|
+
* else it watches re-reads the window. A window that loses a row is topped up from below
|
|
1241
|
+
* (`rows` with `after`). Widening is a new subscription with the larger `limit` and the last
|
|
1242
|
+
* update's `resume`: it gets only the new rows. `order` sorts rows the way `rows` does (null
|
|
1243
|
+
* first, then booleans, numbers, strings by code unit; reversed by `desc`); end it with the
|
|
1244
|
+
* key so no two rows tie. Every watched model's key is the row's `key`.
|
|
1245
|
+
*/
|
|
1246
|
+
export declare function realtime<const N extends string, I extends z.ZodType, R extends z.ZodObject, S extends z.ZodType | undefined = undefined>(name: N, spec: {
|
|
1247
|
+
description?: string;
|
|
1248
|
+
watch: Watchable[];
|
|
1249
|
+
input: I;
|
|
1250
|
+
row: R;
|
|
1251
|
+
key: keyof z.infer<R> & string;
|
|
1252
|
+
order: (query: z.infer<I>) => {
|
|
1253
|
+
by: (row: z.infer<R>) => OrderValue[];
|
|
1254
|
+
desc?: boolean;
|
|
1255
|
+
};
|
|
1256
|
+
reads: Readable[];
|
|
1257
|
+
rows: (args: {
|
|
1258
|
+
input: z.infer<I>;
|
|
1259
|
+
ctx: LakeReadCtx;
|
|
1260
|
+
select: ListSelect;
|
|
1261
|
+
}) => z.input<R>[] | Promise<z.input<R>[]>;
|
|
1262
|
+
summary?: {
|
|
1263
|
+
output: S;
|
|
1264
|
+
handler: (args: {
|
|
1265
|
+
input: z.infer<I>;
|
|
1266
|
+
ctx: LakeReadCtx;
|
|
1267
|
+
}) => S extends z.ZodType ? z.input<S> | Promise<z.input<S>> : never;
|
|
1268
|
+
};
|
|
1269
|
+
}): HandlerDef<N, ReturnType<typeof listInput<I>>, ReturnType<typeof listUpdate<R, S>>, false>;
|
|
1048
1270
|
/** Cedar policy text, built with `cedar`...``. */
|
|
1049
1271
|
export interface CedarText {
|
|
1050
1272
|
readonly kind: "cedar";
|
|
@@ -1073,6 +1295,11 @@ export declare const lake: CedarText;
|
|
|
1073
1295
|
export declare const openSpace: CedarText;
|
|
1074
1296
|
/** A space of the project (`spaces/<id>/`), a Cedar resource. */
|
|
1075
1297
|
export declare function space(id: string): CedarText;
|
|
1298
|
+
/** Who may chat with a registry agent from a space (`<AgentChat>` in `@trytilde/spaces`), in which
|
|
1299
|
+
* registry thread (`context.thread`): `permit(principal, action == ${chatWithAgent}, resource == ${agent(id)}) when { ... };`. */
|
|
1300
|
+
export declare const chatWithAgent: CedarText;
|
|
1301
|
+
/** A Tilde registry agent by its id, a Cedar resource. */
|
|
1302
|
+
export declare function agent(id: string): CedarText;
|
|
1076
1303
|
/** A group: the token's subject is in each group its `groups` attribute lists (comma-separated). */
|
|
1077
1304
|
export declare function group(name: string): CedarText;
|
|
1078
1305
|
export interface PolicyDef {
|
|
@@ -1099,22 +1326,18 @@ export interface OntologySpec {
|
|
|
1099
1326
|
policies?: PolicyDef[];
|
|
1100
1327
|
/** Credential resolvers for deferred (and live) requests. */
|
|
1101
1328
|
auths?: AuthDef[];
|
|
1102
|
-
/** Third-party accounts each environment binds (`
|
|
1103
|
-
*
|
|
1104
|
-
connections?:
|
|
1105
|
-
/**
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
};
|
|
1329
|
+
/** Third-party accounts each environment binds, by name (`satisfies Connections`), for
|
|
1330
|
+
* deferred (and live) requests and pipelines. */
|
|
1331
|
+
connections?: Connections;
|
|
1332
|
+
/** Every input: `source(name, { from, streams })`. Once a source reads a pipeline, every raw
|
|
1333
|
+
* stream read must be a declared source's, and every declared stream must be read. */
|
|
1334
|
+
sources?: {
|
|
1335
|
+
readonly $source: SourceDecl;
|
|
1336
|
+
}[];
|
|
1111
1337
|
/** Raw secrets the pipelines take (`defineSecrets`), supplied by each environment. */
|
|
1112
1338
|
secrets?: {
|
|
1113
1339
|
readonly [name: string]: SecretRef;
|
|
1114
1340
|
};
|
|
1115
|
-
/** The pipelines that feed the sources (`source(name, { pipeline })`). Once there is one,
|
|
1116
|
-
* every source read must have one, and the rollout builds ducktail's config from them. */
|
|
1117
|
-
pipelines?: PipelineSource[];
|
|
1118
1341
|
/** Where the data lives (default `cell`); it also decides the dialect of every SQL text. */
|
|
1119
1342
|
storage?: Storage;
|
|
1120
1343
|
/** Named places models can materialize to besides the storage (`model({ destination })`),
|