@voltro/protocol 0.83.1 → 0.85.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/rest.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as AST from 'effect/SchemaAST';
2
2
  import { DataStore } from '@voltro/database';
3
3
  import { Schema } from 'effect';
4
4
 
5
- declare interface ActionProcedureDescriptor<Name extends string, Input extends Schema.Schema.Any, Output extends Schema.Schema.Any, Error extends Schema.Schema.All> {
5
+ declare interface ActionProcedureDescriptor<Name extends string, Input extends Schema.Top, Output extends Schema.Top, Error extends Schema.Top> {
6
6
  readonly kind: 'action';
7
7
  readonly name: Name;
8
8
  readonly input: Input;
@@ -113,7 +113,7 @@ export declare const bytes: (stream: ReadableStream<Uint8Array> | (() => Readabl
113
113
  * Field by field for a struct; the object is returned unchanged for any other
114
114
  * shape (the schema then decides). Unknown keys pass through untouched.
115
115
  */
116
- export declare const coerceQueryObject: (query: unknown, input: Schema.Schema.All) => unknown;
116
+ export declare const coerceQueryObject: (query: unknown, input: Schema.Top) => unknown;
117
117
 
118
118
  /**
119
119
  * Coerce ONE query-string value toward what `ast` (an ENCODED shape) expects.
@@ -144,7 +144,7 @@ export declare const collectPublicApiRoutes: (entries: ReadonlyArray<PublicApiEn
144
144
  declare type DeclaredAccess<Input = unknown> = ReadonlyArray<AnyGuardSpec<Input> | OpenAccessSpec | ServiceAccessSpec>;
145
145
 
146
146
  /** The `_tag` literals a descriptor's `error:` union declares (empty for none). */
147
- export declare const declaredErrorTags: (error: Schema.Schema.All | undefined) => ReadonlySet<string>;
147
+ export declare const declaredErrorTags: (error: Schema.Top | undefined) => ReadonlySet<string>;
148
148
 
149
149
  /**
150
150
  * Identity helper that fixes the descriptor's types (like `defineAction` /
@@ -210,7 +210,7 @@ export declare const encodeRestSuccess: (format: RestFormat, value: unknown, ctx
210
210
 
211
211
  /** The member of an error union that declares `tag`, as a schema of its own —
212
212
  * for the spec's per-status responses. */
213
- export declare const errorMemberSchema: (error: Schema.Schema.All | undefined, tag: string) => Schema.Schema.All | undefined;
213
+ export declare const errorMemberSchema: (error: Schema.Top | undefined, tag: string) => Schema.Top | undefined;
214
214
 
215
215
  /** Normalize the `exposeAsTool` shorthand. `true` is only valid when the
216
216
  * descriptor carries a top-level `description`; callers pass that in. */
@@ -359,7 +359,7 @@ export declare const matchPathParams: (pattern: string, path: string) => Record<
359
359
  * (for example joining a room) must execute once for EACH native connection. */
360
360
  declare type MutationIdempotencyScope = 'subject' | 'connection';
361
361
 
362
- declare interface MutationProcedureDescriptor<Name extends string, Input extends Schema.Schema.Any, Output extends Schema.Schema.Any, Error extends Schema.Schema.All> {
362
+ declare interface MutationProcedureDescriptor<Name extends string, Input extends Schema.Top, Output extends Schema.Top, Error extends Schema.Top> {
363
363
  readonly kind: 'mutation';
364
364
  readonly name: Name;
365
365
  readonly input: Input;
@@ -498,7 +498,7 @@ export declare const pathParamNames: (path: string) => ReadonlyArray<string>;
498
498
  * Requires the plugin to ship the schema as a NAMED export from `module`.
499
499
  */
500
500
  declare interface PluginErrorSchema {
501
- readonly schema: Schema.Schema.All;
501
+ readonly schema: Schema.Top;
502
502
  readonly import: {
503
503
  readonly module: string;
504
504
  readonly name: string;
@@ -827,7 +827,7 @@ export declare interface PublicApiClientConfig {
827
827
  }
828
828
 
829
829
  /** A descriptor kind that can be projected to REST (streams are not, in v1). */
830
- export declare type PublicApiDescriptor = QueryProcedureDescriptor<string, Schema.Schema.Any, Schema.Schema.Any, Schema.Schema.All> | MutationProcedureDescriptor<string, Schema.Schema.Any, Schema.Schema.Any, Schema.Schema.All> | ActionProcedureDescriptor<string, Schema.Schema.Any, Schema.Schema.Any, Schema.Schema.All>;
830
+ export declare type PublicApiDescriptor = QueryProcedureDescriptor<string, Schema.Top, Schema.Top, Schema.Top> | MutationProcedureDescriptor<string, Schema.Top, Schema.Top, Schema.Top> | ActionProcedureDescriptor<string, Schema.Top, Schema.Top, Schema.Top>;
831
831
 
832
832
  /** A descriptor paired with its bound executor, for batch projection at boot. */
833
833
  export declare interface PublicApiEntry {
@@ -1061,7 +1061,7 @@ declare interface QueryCacheConfig {
1061
1061
  readonly scope: 'subject' | 'tenant' | 'global';
1062
1062
  }
1063
1063
 
1064
- declare interface QueryProcedureDescriptor<Name extends string, Input extends Schema.Schema.Any, Output extends Schema.Schema.Any, Error extends Schema.Schema.All> {
1064
+ declare interface QueryProcedureDescriptor<Name extends string, Input extends Schema.Top, Output extends Schema.Top, Error extends Schema.Top> {
1065
1065
  readonly kind: 'query';
1066
1066
  readonly name: Name;
1067
1067
  readonly input: Input;
@@ -1196,7 +1196,18 @@ export declare interface RestByteResponse {
1196
1196
  * headers CDNs purge by. A request that carries a credential (`Authorization`
1197
1197
  * or a cookie) gets `private, no-cache` and no tags, whatever is declared:
1198
1198
  * what a key or a session may see must never land in a shared cache. Every
1199
- * such answer says `Vary: Authorization, Cookie`. Errors are not affected.
1199
+ * such answer says `Vary: Authorization, Cookie`.
1200
+ *
1201
+ * With `audience`, the ANSWER decides instead of the request's cookies: an
1202
+ * answer that is the same for every reader (`'public'`) is shared even when
1203
+ * the request carries cookies (a consent choice, a signed-in reader on a
1204
+ * public page) — the cache serves it to everyone, so it says only
1205
+ * `Vary: Authorization`; an answer for this reader alone (`'private'`: a
1206
+ * members page, a running experiment) is `private, no-store`. A request with
1207
+ * `Authorization` is private either way.
1208
+ *
1209
+ * Any other answer than a 200 (a 404, a 410, a 401) of a route with `cache`
1210
+ * is `private, no-store`: one reader's "not found" can be another's page.
1200
1211
  */
1201
1212
  export declare interface RestCache {
1202
1213
  /** Seconds a cache may serve the answer without asking again. */
@@ -1206,6 +1217,12 @@ export declare interface RestCache {
1206
1217
  /** Purge tags from the answer as it goes on the wire, and the input.
1207
1218
  * A tag with whitespace or a comma is dropped (no header can carry it). */
1208
1219
  readonly tags?: (output: unknown, input: unknown) => ReadonlyArray<string>;
1220
+ /** Who may share the answer, decided by the answer and the reader it was
1221
+ * made for: `'public'` — every reader gets the same, cookies are ignored;
1222
+ * `'private'` — this reader's alone, never shared. Answer `'private'` for
1223
+ * a signed-in `subject` whenever anything in the answer depends on who
1224
+ * reads it. Without it, any cookie makes the answer private. */
1225
+ readonly audience?: (output: unknown, input: unknown, subject: Subject) => 'public' | 'private';
1209
1226
  }
1210
1227
 
1211
1228
  export declare type RestDates = 'iso' | 'epoch-ms';
@@ -1363,10 +1380,10 @@ export declare interface RestRouteDescriptor<I, O> {
1363
1380
  * before decoding. Omit for routes that take no input. The schema's
1364
1381
  * decoded `Type` flows to the handler's `input`; its `Encoded` is left
1365
1382
  * open (`any`) so any `Schema.Struct(...)` is accepted. */
1366
- readonly input?: Schema.Schema<I, any, never>;
1383
+ readonly input?: Schema.Codec<I, any, never, never>;
1367
1384
  /** Output schema. The handler returns the decoded `Type`; the desugar
1368
1385
  * encodes it to JSON for the `200` response. */
1369
- readonly output: Schema.Schema<O, any, never>;
1386
+ readonly output: Schema.Codec<O, any, never, never>;
1370
1387
  readonly handler: (input: I, ctx: RestRouteContext) => Promise<RestHandlerResult<O>> | RestHandlerResult<O>;
1371
1388
  readonly summary?: string;
1372
1389
  readonly description?: string;
@@ -1462,10 +1479,10 @@ export declare interface RestRouteProjection {
1462
1479
  /** `publicApi.idempotent` — the route honours `Idempotency-Key` (under the
1463
1480
  * app's idempotency binding); a client sends one per attempt. */
1464
1481
  readonly idempotent: boolean;
1465
- readonly input: Schema.Schema.All;
1482
+ readonly input: Schema.Top;
1466
1483
  /** The wire names of the input fields bound from the path. */
1467
1484
  readonly pathParams: ReadonlyArray<string>;
1468
- readonly output: Schema.Schema.All;
1485
+ readonly output: Schema.Top;
1469
1486
  /** The first `source` table, when the procedure declares one. */
1470
1487
  readonly source: string | undefined;
1471
1488
  /** Every failure the operation answers with a typed body, and its status:
@@ -1474,7 +1491,7 @@ export declare interface RestRouteProjection {
1474
1491
  readonly errorResponses: ReadonlyArray<{
1475
1492
  readonly status: number;
1476
1493
  readonly tag: string;
1477
- readonly schema: Schema.Schema.All;
1494
+ readonly schema: Schema.Top;
1478
1495
  }>;
1479
1496
  readonly format: RestFormat;
1480
1497
  }
@@ -1528,15 +1545,15 @@ export declare interface RestStreamResponse {
1528
1545
 
1529
1546
  /**
1530
1547
  * Rewrite a descriptor's schema into the shape the profile puts on the wire:
1531
- * `timestampMs` (`DateFromNumber`) becomes an RFC 3339 string under
1532
- * `dates: 'iso'`, and every struct's property names become `snake_case` under
1533
- * `naming: 'snake_case'` — as a transformation, so decoding a wire value yields
1534
- * the descriptor's own typed value and encoding the typed value yields the
1535
- * wire form. `JSONSchema.make` of the result documents the wire (a
1536
- * `format: date-time` string, the snake keys). Classes and other opaque
1537
- * transformations pass through unchanged; a struct inside one keeps its keys.
1548
+ * `timestampMs` becomes an RFC 3339 string under `dates: 'iso'`, and every
1549
+ * struct's property names become `snake_case` under `naming: 'snake_case'` —
1550
+ * as an encoding, so decoding a wire value yields the descriptor's own typed
1551
+ * value and encoding the typed value yields the wire form.
1552
+ * `Schema.toJsonSchemaDocument` of the result documents the wire (a
1553
+ * `format: date-time` string, the snake keys). Classes and other opaque codecs
1554
+ * pass through unchanged; a struct inside one keeps its keys.
1538
1555
  */
1539
- export declare const restViewSchema: (schema: Schema.Schema.All, format: RestFormat) => Schema.Schema.All;
1556
+ export declare const restViewSchema: (schema: Schema.Top, format: RestFormat) => Schema.Top;
1540
1557
 
1541
1558
  /**
1542
1559
  * Whether `path` is one the route declared. The underlying router folds case
@@ -1602,33 +1619,31 @@ export declare const sse: (subscribe: (emit: (chunk: string) => void) => () => v
1602
1619
  * the protocol requires — a raw `\n` inside one would truncate the event. */
1603
1620
  export declare const sseFrame: (event: string, data: unknown) => string;
1604
1621
 
1605
- declare const Subject: Schema.Union<[Schema.Struct<{
1606
- type: Schema.Literal<["user"]>;
1607
- id: typeof Schema.String;
1608
- tenantId: typeof Schema.String;
1609
- scopes: Schema.optional<Schema.Array$<typeof Schema.String>>;
1610
- metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
1622
+ declare const Subject: Schema.Union<readonly [Schema.Struct<{
1623
+ readonly type: Schema.Literal<"user">;
1624
+ readonly id: Schema.String;
1625
+ readonly tenantId: Schema.String;
1626
+ readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
1627
+ readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
1611
1628
  }>, Schema.Struct<{
1612
- type: Schema.Literal<["apiKey"]>;
1613
- id: typeof Schema.String;
1614
- tenantId: typeof Schema.String;
1615
- scopes: Schema.optional<Schema.Array$<typeof Schema.String>>;
1616
- metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
1629
+ readonly type: Schema.Literal<"apiKey">;
1630
+ readonly id: Schema.String;
1631
+ readonly tenantId: Schema.String;
1632
+ readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
1633
+ readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
1617
1634
  }>, Schema.Struct<{
1618
- type: Schema.Literal<["serviceAccount"]>;
1619
- id: typeof Schema.String;
1620
- tenantId: typeof Schema.String;
1635
+ readonly type: Schema.Literal<"serviceAccount">;
1636
+ readonly id: Schema.String;
1637
+ readonly tenantId: Schema.String;
1621
1638
  /** Application actor used for audit columns; null means machine work with
1622
1639
  * no application actor. Identity only, never a permission grant. */
1623
- auditActorId: Schema.optionalWith<Schema.NullOr<typeof Schema.String>, {
1624
- exact: true;
1625
- }>;
1626
- scopes: Schema.optional<Schema.Array$<typeof Schema.String>>;
1627
- metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
1640
+ readonly auditActorId: Schema.optionalKey<Schema.NullOr<Schema.String>>;
1641
+ readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
1642
+ readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
1628
1643
  }>, Schema.Struct<{
1629
- type: Schema.Literal<["anonymous"]>;
1630
- id: typeof Schema.Null;
1631
- tenantId: Schema.NullOr<typeof Schema.String>;
1644
+ readonly type: Schema.Literal<"anonymous">;
1645
+ readonly id: Schema.Null;
1646
+ readonly tenantId: Schema.NullOr<Schema.String>;
1632
1647
  /**
1633
1648
  * Set when this caller PRESENTED a credential and it was rejected — an
1634
1649
  * expired token above all. Absent when they presented none.
@@ -1645,21 +1660,21 @@ declare const Subject: Schema.Union<[Schema.Struct<{
1645
1660
  * must not break an `openAccess` procedure that needs no session at all. The
1646
1661
  * fact travels, and only a guard that actually refuses spends it.
1647
1662
  */
1648
- credentialRejected: Schema.optional<typeof Schema.String>;
1663
+ readonly credentialRejected: Schema.optional<Schema.String>;
1649
1664
  }>, Schema.Struct<{
1650
- type: Schema.Literal<["system"]>;
1651
- id: typeof Schema.String;
1652
- tenantId: typeof Schema.Null;
1653
- scopes: Schema.optional<Schema.Array$<typeof Schema.String>>;
1654
- metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
1665
+ readonly type: Schema.Literal<"system">;
1666
+ readonly id: Schema.String;
1667
+ readonly tenantId: Schema.Null;
1668
+ readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
1669
+ readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
1655
1670
  }>, Schema.Struct<{
1656
- type: Schema.Literal<["service"]>;
1657
- id: typeof Schema.String;
1671
+ readonly type: Schema.Literal<"service">;
1672
+ readonly id: Schema.String;
1658
1673
  /** The calling app's name, as the callee lists it in `serviceCallers`. */
1659
- service: typeof Schema.String;
1660
- tenantId: typeof Schema.Null;
1661
- scopes: Schema.optional<Schema.Array$<typeof Schema.String>>;
1662
- metadata: Schema.optional<Schema.Record$<typeof Schema.String, typeof Schema.Unknown>>;
1674
+ readonly service: Schema.String;
1675
+ readonly tenantId: Schema.Null;
1676
+ readonly scopes: Schema.optional<Schema.$Array<Schema.String>>;
1677
+ readonly metadata: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
1663
1678
  }>]>;
1664
1679
 
1665
1680
  declare type Subject = typeof Subject.Type;
@@ -1737,7 +1752,7 @@ declare interface UpdateTarget<Input = unknown, Row = unknown, Item = Record<str
1737
1752
  export declare const wireExample: (example: {
1738
1753
  readonly request?: unknown;
1739
1754
  readonly response?: unknown;
1740
- }, wireInput: Schema.Schema.All, wireOutput: Schema.Schema.All) => {
1755
+ }, wireInput: Schema.Top, wireOutput: Schema.Top) => {
1741
1756
  readonly request?: unknown;
1742
1757
  readonly response?: unknown;
1743
1758
  };