@fabrika/app 0.9.0-dev.13 → 0.9.0-dev.15
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/package.json +14 -9
- package/skill/SKILL.md +3 -2
- package/skill/references/app-setup.md +17 -9
- package/skill/references/endpoint.md +15 -2
- package/skill/references/errors.md +7 -6
- package/skill/references/jobs.md +10 -0
- package/skill/references/relations.md +145 -21
- package/skill/references/table-and-migration.md +4 -1
- package/skill/references/webhooks-links-connectors.md +2 -1
- package/src/build-contract-child.ts +16 -0
- package/src/build.ts +48 -2
- package/src/bun.ts +10 -0
- package/src/client/contract.ts +6 -4
- package/src/cloudflare/application.ts +3 -0
- package/src/contract/artifact-schema.ts +367 -299
- package/src/contract/attachment.ts +4 -3
- package/src/contract/build.ts +76 -18
- package/src/contract/compile.ts +3 -2
- package/src/contract/context.ts +2 -3
- package/src/contract/define.ts +19 -6
- package/src/contract/group.ts +18 -8
- package/src/contract/index.ts +1 -1
- package/src/contract/kit.ts +4 -3
- package/src/contract/problems.ts +4 -0
- package/src/contract/schema-shape.ts +14 -2
- package/src/contract/token.ts +4 -3
- package/src/disk-assets.ts +15 -3
- package/src/from-row.ts +12 -6
- package/src/implement/approved.ts +57 -0
- package/src/implement/attachment.ts +2 -1
- package/src/implement/boot.ts +118 -17
- package/src/implement/capability.ts +82 -12
- package/src/implement/dispatch.ts +265 -45
- package/src/implement/egress.ts +410 -9
- package/src/implement/faults.ts +1 -0
- package/src/implement/implement.ts +23 -3
- package/src/implement/invocation.ts +10 -9
- package/src/implement/project.ts +3 -1
- package/src/implement/tokens.ts +3 -2
- package/src/implement/types.ts +33 -10
- package/src/implement/webhook.ts +8 -0
- package/src/jobs/runner.ts +7 -2
- package/src/react/hooks.ts +12 -11
- package/src/react/provider.tsx +2 -1
- package/src/react/types.ts +2 -2
- package/src/schema/builder.ts +146 -0
- package/src/schema/data-schema.ts +365 -0
- package/src/schema/index.ts +18 -0
- package/src/schema/replay.ts +623 -0
- package/src/source-map-path.ts +21 -0
- package/src/testing/caller.ts +20 -9
- package/src/testing/kit.ts +3 -3
- package/src/testing/membership.ts +9 -5
- package/types/src/build-contract-child.d.ts +1 -0
- package/types/src/build.d.ts +16 -1
- package/types/src/client/contract.d.ts +3 -4
- package/types/src/cloudflare/application.d.ts +2 -0
- package/types/src/contract/artifact-schema.d.ts +8 -0
- package/types/src/contract/attachment.d.ts +3 -2
- package/types/src/contract/context.d.ts +2 -3
- package/types/src/contract/define.d.ts +16 -6
- package/types/src/contract/group.d.ts +14 -7
- package/types/src/contract/index.d.ts +1 -1
- package/types/src/contract/kit.d.ts +4 -5
- package/types/src/contract/problems.d.ts +1 -0
- package/types/src/contract/schema-shape.d.ts +3 -2
- package/types/src/contract/token.d.ts +3 -3
- package/types/src/from-row.d.ts +9 -5
- package/types/src/implement/approved.d.ts +11 -0
- package/types/src/implement/boot.d.ts +12 -0
- package/types/src/implement/capability.d.ts +14 -5
- package/types/src/implement/dispatch.d.ts +9 -1
- package/types/src/implement/egress.d.ts +36 -1
- package/types/src/implement/faults.d.ts +1 -0
- package/types/src/implement/implement.d.ts +19 -3
- package/types/src/implement/invocation.d.ts +3 -3
- package/types/src/implement/project.d.ts +2 -1
- package/types/src/implement/types.d.ts +17 -8
- package/types/src/jobs/runner.d.ts +3 -0
- package/types/src/react/hooks.d.ts +4 -5
- package/types/src/react/types.d.ts +2 -2
- package/types/src/schema/builder.d.ts +45 -0
- package/types/src/schema/data-schema.d.ts +124 -0
- package/types/src/schema/index.d.ts +3 -0
- package/types/src/schema/replay.d.ts +27 -0
- package/types/src/source-map-path.d.ts +4 -0
- package/types/src/testing/caller.d.ts +6 -1
- package/types/src/testing/kit.d.ts +2 -3
- package/types/src/testing/membership.d.ts +1 -1
|
@@ -1,5 +1,40 @@
|
|
|
1
|
+
import { type DeclaredEgress } from '@fabrika/auth-core';
|
|
2
|
+
/** The addresses a host name resolves to, where the runtime exposes resolution: Bun's `node:dns`, never a Worker. */
|
|
3
|
+
export type HostResolver = (hostname: string) => Promise<readonly string[]>;
|
|
4
|
+
/** What public egress refuses beyond what a URL alone shows (`publicEgressRefusal`). */
|
|
5
|
+
export interface PublicEgressRules {
|
|
6
|
+
/** The installation's own hosts, normalized: every host a framework variable names, and `FABRIKA_EGRESS_REFUSED_HOSTS`. */
|
|
7
|
+
readonly refusedHosts: ReadonlySet<string>;
|
|
8
|
+
/** Resolves each hop's host once, before it is sent to an address checked here; `null` on Cloudflare. */
|
|
9
|
+
readonly resolve: HostResolver | null;
|
|
10
|
+
}
|
|
11
|
+
/** What one site's `fetch` reaches: its declared origins, or the rules of public egress. */
|
|
12
|
+
export type SiteEgress = readonly string[] | PublicEgressRules;
|
|
13
|
+
/**
|
|
14
|
+
* The bounds of one request under public egress, the redirects it follows included. The handler's own signal still
|
|
15
|
+
* aborts it sooner (`ctx.signal`, an `AbortSignal.timeout` of its own).
|
|
16
|
+
*/
|
|
17
|
+
export declare const PUBLIC_EGRESS_LIMITS: {
|
|
18
|
+
/** One request, its redirects and the reading of its body included: the abort also stops a body still streaming. */
|
|
19
|
+
readonly timeoutMs: 60000;
|
|
20
|
+
/** One response's body as the handler reads it; a larger one is refused, by its `Content-Length` or while it streams. */
|
|
21
|
+
readonly maxResponseBytes: number;
|
|
22
|
+
/** The redirects one request follows when its `redirect` mode is `follow`, each hop checked again. */
|
|
23
|
+
readonly maxRedirects: 10;
|
|
24
|
+
};
|
|
1
25
|
/** Runs a site's handler: every `fetch` it starts reaches only `egress`. */
|
|
2
|
-
export declare function runAsSite<T>(site: string, egress:
|
|
26
|
+
export declare function runAsSite<T>(site: string, egress: SiteEgress, work: () => Promise<T>): Promise<T>;
|
|
27
|
+
/**
|
|
28
|
+
* The egress a site runs with: its declared origins, or `rules` for `'public'`. Only a cron job's runner holds rules; a
|
|
29
|
+
* site run without them reaches nothing, though the build lets no other site declare `'public'`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function siteEgress(declared: DeclaredEgress, rules: PublicEgressRules | null): SiteEgress;
|
|
32
|
+
/**
|
|
33
|
+
* The rules of public egress in one environment: the hosts its framework variables name (IAM, Operations, its own
|
|
34
|
+
* origin, the platform's receivers, the object store), the installation hosts Control hands it, and the resolver the
|
|
35
|
+
* runtime adapter supplies.
|
|
36
|
+
*/
|
|
37
|
+
export declare function publicEgressRules(framework: Readonly<Record<string, string>>, resolve: HostResolver | null): PublicEgressRules;
|
|
3
38
|
/**
|
|
4
39
|
* `facility` with each of its methods run outside any site's scope: a framework facility a handler calls, whose own
|
|
5
40
|
* requests are the platform's, not the site's.
|
|
@@ -31,6 +31,7 @@ export declare const SERVER_FAULTS: {
|
|
|
31
31
|
readonly attachment_cell: "a cell of the attachment is longer than one cell may hold";
|
|
32
32
|
readonly attachment_size: "the encoded attachment is larger than it declares (maxBytes); no body was sent";
|
|
33
33
|
readonly redirect_refused: "the handler redirected to a target that is neither its own origin's path, an origin its redirect() lists, nor a URL a verified token of the request carries";
|
|
34
|
+
readonly schema_unapproved: "a schema the application evaluated has another shape than its approved contract holds for the endpoint";
|
|
34
35
|
readonly token_claims_refused: "the claims a site signed are not what the token purpose's claims schema admits";
|
|
35
36
|
readonly token_keys_missing: "a site signed a token, and the environment holds no token key";
|
|
36
37
|
readonly url_unbuildable: "ctx.url named no procedure of the contract, passed a parameter its HTTP shape does not read, or the environment has no public origin";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TablePolicyArtifact } from '@fabrika/auth-core';
|
|
2
2
|
import type { DataLayer } from '@fabrika/db';
|
|
3
|
-
import type { CapabilityAuthority } from '@fabrika/db/capability';
|
|
3
|
+
import type { CapabilityAuthority, ContainerGrant, RelationHold } from '@fabrika/db/capability';
|
|
4
4
|
import type { Session } from '@fabrika/db/framework';
|
|
5
5
|
import type { EmailSender } from '@fabrika/email';
|
|
6
6
|
import type { ConnectSnapshot } from '../contract/connect';
|
|
@@ -23,8 +23,24 @@ export interface ContractDatabase {
|
|
|
23
23
|
* own has none, so no Ref is ever held through a relation there.
|
|
24
24
|
*/
|
|
25
25
|
relates?(relation: string, node: string, principal: string): Promise<boolean>;
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Whether a row `relation` reaches for `principal` reveals `node` of `dimension` for `action` now; none in a layer of
|
|
28
|
+
* the application's own.
|
|
29
|
+
*/
|
|
30
|
+
reveals?(relation: string, dimension: string, node: string, principal: string, action: string): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Of `relations` and `paths`, the caller's relations and grants of `action` that reach the object through a secondary
|
|
33
|
+
* path that holds the action for a Ref (`writeThrough`); none in a layer of the application's own.
|
|
34
|
+
*/
|
|
35
|
+
holdsThrough?(dimension: string, id: string, action: string, principal: string, relations: readonly RelationHold[], paths: readonly ContainerGrant[]): Promise<{
|
|
36
|
+
readonly relations: readonly RelationHold[];
|
|
37
|
+
readonly paths: readonly ContainerGrant[];
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* Of `values`, the caller's grants of `action` at nodes of `revealing`, those whose row reveals `node` of `dimension`
|
|
41
|
+
* to its members now; none in a layer of the application's own.
|
|
42
|
+
*/
|
|
43
|
+
revealsToMembers?(revealing: string, values: readonly string[], dimension: string, node: string, action: string): Promise<readonly string[]>;
|
|
28
44
|
}
|
|
29
45
|
/** `scoped(tables)` of `@fabrika/db`, which `boot` binds, or a `ContractDatabase` of the application's own. */
|
|
30
46
|
export type ImplementationDatabase = DataLayer | ContractDatabase;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ContractArtifact, type JobMailer } from '@fabrika/auth-core';
|
|
1
|
+
import { type ContractArtifact, type DeclaredEgress, type JobMailer } from '@fabrika/auth-core';
|
|
2
2
|
import { type DataAccess, type DataHandles, type FileBinding, type NewWake, type Session, type SqlTag } from '@fabrika/db/framework';
|
|
3
3
|
import type { DataKind, UnscopedMode } from '@fabrika/db/tables';
|
|
4
4
|
import type { SqlMode } from '../contract/context';
|
|
@@ -16,8 +16,8 @@ export interface SiteDeclaration {
|
|
|
16
16
|
readonly binds: string | null;
|
|
17
17
|
/** The token purposes `ctx.tokens.sign` may sign. */
|
|
18
18
|
readonly signs: readonly string[];
|
|
19
|
-
/** The HTTPS origins the global `fetch` reaches while the site's handler runs. */
|
|
20
|
-
readonly egress:
|
|
19
|
+
/** The HTTPS origins the global `fetch` reaches while the site's handler runs, or `'public'`: every public host (a cron job). */
|
|
20
|
+
readonly egress: DeclaredEgress;
|
|
21
21
|
}
|
|
22
22
|
/** A public procedure's reach: the texts the verified signed tokens of its request carry, which name the rows it changes. */
|
|
23
23
|
export interface PublicReach {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
import { type DataSchema } from '../schema/data-schema';
|
|
2
3
|
/** No branch of a union accepts the value, whatever it is reduced to. */
|
|
3
4
|
export declare class ProjectionRefusedError extends Error {
|
|
4
5
|
readonly name = "ProjectionRefusedError";
|
|
@@ -8,4 +9,4 @@ export declare class ProjectionRefusedError extends Error {
|
|
|
8
9
|
* in declaration order, whose schema accepts the value reduced to that branch. Anything else is left for
|
|
9
10
|
* validation.
|
|
10
11
|
*/
|
|
11
|
-
export declare function project(
|
|
12
|
+
export declare function project(declared: z.core.$ZodType | DataSchema, value: unknown): unknown;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { z } from 'zod/v4';
|
|
2
1
|
import type { ConnectSnapshot } from '../contract/connect';
|
|
3
2
|
import type { SurfaceSection } from '../contract/declaration';
|
|
4
|
-
import type { Export, InputOf, InputSchema, LinkMount, MemberAccess, Procedure, RoleOf, RpcMount, Schema, WebhookMount } from '../contract/define';
|
|
3
|
+
import type { Export, InputOf, InputSchema, LinkMount, MemberAccess, Procedure, RoleOf, RpcMount, Schema, SchemaInput, SchemaOutput, WebhookMount } from '../contract/define';
|
|
5
4
|
import type { JobHandlersOf } from '../jobs/types';
|
|
6
5
|
import type { AppCapability, Ref, Within } from './capability';
|
|
7
6
|
import type { ConnectResult } from './connect';
|
|
@@ -154,7 +153,7 @@ type Without<In, F> = {
|
|
|
154
153
|
export type Handler<In, Ctx, O extends Schema> = (args: {
|
|
155
154
|
readonly input: In;
|
|
156
155
|
readonly ctx: Ctx;
|
|
157
|
-
}) =>
|
|
156
|
+
}) => SchemaInput<O> | Promise<SchemaInput<O>>;
|
|
158
157
|
type ImportsOf<C> = SurfaceOf<C> extends {
|
|
159
158
|
readonly imports: infer I;
|
|
160
159
|
} ? I : Record<never, never>;
|
|
@@ -171,7 +170,7 @@ type ImportedProcedures<C, K> = K extends keyof ImportsOf<C> ? ImportsOf<C>[K] e
|
|
|
171
170
|
readonly procedures: readonly (infer P extends string)[];
|
|
172
171
|
} ? P : never : never;
|
|
173
172
|
/** A connector call never throws for the owner's answer: it resolves to a typed outcome. */
|
|
174
|
-
export type ConnectCall<I, O extends Schema> = [I] extends [InputSchema] ? (input:
|
|
173
|
+
export type ConnectCall<I, O extends Schema> = [I] extends [InputSchema] ? (input: SchemaInput<I>) => Promise<ConnectResult<SchemaOutput<O>>> : (input?: Record<never, never>) => Promise<ConnectResult<SchemaOutput<O>>>;
|
|
175
174
|
type ConnectorOf<S, P extends string> = {
|
|
176
175
|
readonly [Path in P]: S extends {
|
|
177
176
|
readonly procedures: {
|
|
@@ -216,7 +215,7 @@ type LinkHandlers<D extends string, T> = {
|
|
|
216
215
|
* stable key. It runs at least once per delivery: a failed run is run again on GitHub's redelivery.
|
|
217
216
|
*/
|
|
218
217
|
export type WebhookHandler<B extends string, Acts extends string, I> = (args: {
|
|
219
|
-
readonly input:
|
|
218
|
+
readonly input: SchemaOutput<I>;
|
|
220
219
|
readonly ctx: RequestContext<WebhookPrincipal> & {
|
|
221
220
|
readonly refs: {
|
|
222
221
|
readonly [A in Acts]: Ref<B, A>;
|
|
@@ -240,9 +239,19 @@ export type HandlersOf<C, Snap = unknown> = {
|
|
|
240
239
|
} & JobHandlersOf<C> & ExportHandlersOf<C>;
|
|
241
240
|
/** An `any` comes from an error elsewhere in the handler; reporting it here too would only add noise. */
|
|
242
241
|
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
243
|
-
/**
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Fields of `R` that the output `O` does not declare. Each member of a union `R` is paired with `O` on its own, and a
|
|
244
|
+
* member that fits one branch of a union `O` has none.
|
|
245
|
+
*/
|
|
246
|
+
export type ExtraKeys<R, O> = IsAny<R> extends true ? never : R extends unknown ? true extends (O extends unknown ? ([ExtraKeysOf<R, O>] extends [never] ? true : false) : never) ? never : ExtraKeysOf<R, O> : never;
|
|
247
|
+
/**
|
|
248
|
+
* Optional keys that can hold only `undefined`: TypeScript adds them when it widens object literals of different
|
|
249
|
+
* shapes to one type (`{ x } | { x, y }` read as `{ x, y?: undefined }`). They carry no value, and projection drops them.
|
|
250
|
+
*/
|
|
251
|
+
type EmptyKeys<R> = {
|
|
252
|
+
[K in keyof R]-?: object extends Pick<R, K> ? ([Exclude<R[K], undefined>] extends [never] ? K : never) : never;
|
|
253
|
+
}[keyof R];
|
|
254
|
+
type ExtraKeysOf<R, O> = R extends readonly (infer RE)[] ? (O extends readonly (infer OE)[] ? ExtraKeys<RE, OE> : never) : R extends object ? O extends object ? Exclude<keyof R, keyof O | EmptyKeys<R>> | {
|
|
246
255
|
[Q in keyof R & keyof O]: ExtraKeys<R[Q], O[Q]>;
|
|
247
256
|
}[keyof R & keyof O] : never : never;
|
|
248
257
|
type Returned<F> = F extends (args: never) => infer R ? Awaited<R> : never;
|
|
@@ -4,6 +4,7 @@ import type { CapabilityAuthority } from '@fabrika/db/capability';
|
|
|
4
4
|
import { type DataAccess, type FrameworkTables, type LeaseFence, type Session } from '@fabrika/db/framework';
|
|
5
5
|
import { type StoredFileKinds } from '../files/kinds';
|
|
6
6
|
import { type CapabilityMint } from '../implement/capability';
|
|
7
|
+
import { type PublicEgressRules } from '../implement/egress';
|
|
7
8
|
import { type HandlerErrorSink } from '../implement/failures';
|
|
8
9
|
import type { ContractDatabase } from '../implement/implement';
|
|
9
10
|
import type { SignedTokens } from '../implement/tokens';
|
|
@@ -197,6 +198,8 @@ export interface JobBindingInput {
|
|
|
197
198
|
readonly tokens?: SignedTokens;
|
|
198
199
|
/** `ctx.url`: absolute links to the application's own procedures; without it every link is refused. */
|
|
199
200
|
readonly url?: AppUrl;
|
|
201
|
+
/** The rules of public egress, which `boot` reads from the environment; without them a public job reaches nothing. */
|
|
202
|
+
readonly publicEgress?: PublicEgressRules;
|
|
200
203
|
}
|
|
201
204
|
export interface BoundJobs {
|
|
202
205
|
readonly jobs: ContractJobs;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { z } from 'zod/v4';
|
|
2
1
|
import type { AttachmentProcedure, DownloadedFile, DownloadInput, FileProcedure } from '../client/contract';
|
|
3
|
-
import type { Schema } from '../contract/define';
|
|
2
|
+
import type { Schema, SchemaOutput } from '../contract/define';
|
|
4
3
|
import { type FabrikaError } from './errors';
|
|
5
4
|
import type { InputArgument, InvalidateTarget, PagedProcedure, PageInput, TypedProcedure } from './types';
|
|
6
5
|
/** Pass as the input to wait: the query sends nothing until its input is known. */
|
|
@@ -38,8 +37,8 @@ export interface QueryOptions {
|
|
|
38
37
|
* The answer of a query, cached by procedure and input: every view of one call shares one request, and a mutation
|
|
39
38
|
* that invalidates it refetches it. Pass `skip` as the input to wait for a value the input needs.
|
|
40
39
|
*/
|
|
41
|
-
export declare function useQuery<O extends Schema>(procedure: TypedProcedure<Record<never, never> | undefined, O>, input?: typeof skip): QueryState<
|
|
42
|
-
export declare function useQuery<I, O extends Schema>(procedure: TypedProcedure<I, O>, input: I | typeof skip, options?: QueryOptions): QueryState<
|
|
40
|
+
export declare function useQuery<O extends Schema>(procedure: TypedProcedure<Record<never, never> | undefined, O>, input?: typeof skip): QueryState<SchemaOutput<O>>;
|
|
41
|
+
export declare function useQuery<I, O extends Schema>(procedure: TypedProcedure<I, O>, input: I | typeof skip, options?: QueryOptions): QueryState<SchemaOutput<O>>;
|
|
43
42
|
export interface InfiniteQueryOptions {
|
|
44
43
|
/** How many pages the first load reads: `1` (the default) or every page (`'all'`, for a picker's options). */
|
|
45
44
|
readonly pages?: number | 'all';
|
|
@@ -100,7 +99,7 @@ export interface MutationOptions<T> {
|
|
|
100
99
|
* A mutation of the client: `mutate(input)` checks the input with the procedure's schema (a refused input is a
|
|
101
100
|
* `validation` error and sends nothing), calls it, and after a success refetches what `invalidates` names.
|
|
102
101
|
*/
|
|
103
|
-
export declare function useMutation<I, O extends Schema>(procedure: TypedProcedure<I, O>, options?: MutationOptions<
|
|
102
|
+
export declare function useMutation<I, O extends Schema>(procedure: TypedProcedure<I, O>, options?: MutationOptions<SchemaOutput<O>>): MutationState<InputArgument<I>, SchemaOutput<O>>;
|
|
104
103
|
/**
|
|
105
104
|
* A call that is no client procedure yet (a file upload until the client covers file collections), with the same
|
|
106
105
|
* state and error union as a mutation. It refetches only what `invalidates` names.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { z } from 'zod/v4';
|
|
2
|
-
import type { Schema } from '../contract/define';
|
|
2
|
+
import type { Schema, SchemaOutput } from '../contract/define';
|
|
3
3
|
/** A query or mutation of a client that `createClient` built. */
|
|
4
4
|
export type ClientProcedure = ((input: never) => Promise<unknown>) & {
|
|
5
5
|
readonly output: Schema;
|
|
@@ -19,7 +19,7 @@ export type TypedProcedure<I, O extends Schema> = ((input: I) => Promise<unknown
|
|
|
19
19
|
/** An input argument that may be left out when the procedure takes no input. */
|
|
20
20
|
export type InputArgument<I> = undefined extends I ? I | void : I;
|
|
21
21
|
/** The answer, as the procedure's output schema parses it. */
|
|
22
|
-
export type ProcedureResult<F extends ClientProcedure> =
|
|
22
|
+
export type ProcedureResult<F extends ClientProcedure> = SchemaOutput<F['output']>;
|
|
23
23
|
/** The answer of a cursor list: `{ items, next }`. */
|
|
24
24
|
export interface PageAnswer<Item> {
|
|
25
25
|
readonly items: readonly Item[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { z as zod } from 'zod/v4';
|
|
2
|
+
import { type AnySchema, DataEnum, DataObject, DataSchema, type DataShapeInput, type Message, type UuidOptions, type ZodList, type ZodOf, type ZodShape } from './data-schema';
|
|
3
|
+
type Primitive = string | number | boolean | null;
|
|
4
|
+
export type DatetimeOptions = string | {
|
|
5
|
+
readonly message?: string;
|
|
6
|
+
readonly error?: string;
|
|
7
|
+
readonly offset?: boolean;
|
|
8
|
+
readonly local?: boolean;
|
|
9
|
+
readonly precision?: number | null;
|
|
10
|
+
};
|
|
11
|
+
export type TimeOptions = string | {
|
|
12
|
+
readonly message?: string;
|
|
13
|
+
readonly error?: string;
|
|
14
|
+
readonly precision?: number | null;
|
|
15
|
+
};
|
|
16
|
+
/** What a schema admits once parsed, as `zod`'s `z.output`. */
|
|
17
|
+
export type output<S> = zod.output<ZodOf<S>>;
|
|
18
|
+
/** What a schema takes before parsing, as `zod`'s `z.input`. */
|
|
19
|
+
export type input<S> = zod.input<ZodOf<S>>;
|
|
20
|
+
export type { output as infer };
|
|
21
|
+
export declare function string(params?: Message): DataSchema<zod.ZodString>;
|
|
22
|
+
export declare function number(params?: Message): DataSchema<zod.ZodNumber>;
|
|
23
|
+
export declare function int(params?: Message): DataSchema<zod.ZodInt>;
|
|
24
|
+
export declare function boolean(params?: Message): DataSchema<zod.ZodBoolean>;
|
|
25
|
+
declare function _null(params?: Message): DataSchema<zod.ZodNull>;
|
|
26
|
+
export declare function uuid(params?: UuidOptions): DataSchema<zod.ZodUUID>;
|
|
27
|
+
export declare function email(params?: Message): DataSchema<zod.ZodEmail>;
|
|
28
|
+
export declare function url(params?: Message): DataSchema<zod.ZodURL>;
|
|
29
|
+
export declare function literal<const L extends Primitive | readonly Primitive[]>(value: L, params?: Message): DataSchema<zod.ZodLiteral<L extends readonly Primitive[] ? L[number] : L>>;
|
|
30
|
+
declare function _enum<const E extends readonly string[] | zod.core.util.EnumLike>(values: E, params?: Message): DataEnum<E extends readonly string[] ? zod.core.util.ToEnum<E[number]> : E>;
|
|
31
|
+
export declare function strictObject<S extends DataShapeInput>(shape: S, params?: Message): DataObject<ZodShape<S>, zod.core.$strict>;
|
|
32
|
+
export declare function array<E extends AnySchema>(element: E, params?: Message): DataSchema<zod.ZodArray<ZodOf<E>>>;
|
|
33
|
+
export declare function tuple<const I extends readonly AnySchema[], R extends AnySchema = never>(items: I, rest?: R | Message, params?: Message): DataSchema<zod.ZodTuple<Extract<ZodList<I>, zod.core.util.TupleItems>, [R] extends [never] ? null : ZodOf<R>>>;
|
|
34
|
+
export declare function union<const O extends readonly AnySchema[]>(options: O, params?: Message): DataSchema<zod.ZodUnion<Extract<ZodList<O>, readonly zod.core.SomeType[]>>>;
|
|
35
|
+
export declare function discriminatedUnion<const O extends readonly [AnySchema, ...AnySchema[]]>(discriminator: string, options: O, params?: Message): DataSchema<zod.ZodDiscriminatedUnion<Extract<ZodList<O>, readonly [zod.core.$ZodTypeDiscriminable, ...zod.core.$ZodTypeDiscriminable[]]>>>;
|
|
36
|
+
export declare function record<K extends AnySchema, V extends AnySchema>(key: K, value: V, params?: Message): DataSchema<zod.ZodRecord<Extract<ZodOf<K>, zod.core.$ZodRecordKey>, ZodOf<V>>>;
|
|
37
|
+
export declare function optional<S extends AnySchema>(inner: S): DataSchema<zod.ZodOptional<ZodOf<S>>>;
|
|
38
|
+
export declare function nullable<S extends AnySchema>(inner: S): DataSchema<zod.ZodNullable<ZodOf<S>>>;
|
|
39
|
+
export declare const iso: Readonly<{
|
|
40
|
+
date: (params?: Message) => DataSchema<zod.ZodISODate>;
|
|
41
|
+
datetime: (params?: DatetimeOptions) => DataSchema<zod.ZodISODateTime>;
|
|
42
|
+
time: (params?: TimeOptions) => DataSchema<zod.ZodISOTime>;
|
|
43
|
+
duration: (params?: Message) => DataSchema<zod.ZodISODuration>;
|
|
44
|
+
}>;
|
|
45
|
+
export { _enum as enum, _null as null };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
/** A schema a contract may hold: one held as data, or a zod schema (a framework schema such as `signedToken()`). */
|
|
3
|
+
export type AnySchema = DataSchema<z.ZodType> | z.ZodType;
|
|
4
|
+
/** The zod type a schema denotes: its own type for a zod schema. */
|
|
5
|
+
export type ZodOf<S> = S extends DataSchema<infer T extends z.core.$ZodType> ? T : S extends z.core.$ZodType ? S : never;
|
|
6
|
+
/** The fields an object is declared with. */
|
|
7
|
+
export type DataShapeInput = {
|
|
8
|
+
readonly [key: string]: AnySchema;
|
|
9
|
+
};
|
|
10
|
+
/** The zod shape of `S`, as `z.strictObject` would hold it. */
|
|
11
|
+
export type ZodShape<S extends DataShapeInput> = {
|
|
12
|
+
[K in keyof S]: ZodOf<S[K]>;
|
|
13
|
+
};
|
|
14
|
+
/** The zod types of a list of schemas, as `z.union` or `z.tuple` would hold them. */
|
|
15
|
+
export type ZodList<O extends readonly AnySchema[]> = {
|
|
16
|
+
[I in keyof O]: ZodOf<O[I]>;
|
|
17
|
+
};
|
|
18
|
+
/** An error message, or the options object that carries one. */
|
|
19
|
+
export type Message = string | {
|
|
20
|
+
readonly message?: string;
|
|
21
|
+
readonly error?: string;
|
|
22
|
+
};
|
|
23
|
+
/** What `min`, `max` and `length` bound: a string's length, an array's items, a number. */
|
|
24
|
+
type Sized = (z.ZodString | z.ZodStringFormat | z.ZodArray) & z.core.$ZodType;
|
|
25
|
+
type Bounded = (Sized | z.ZodNumber) & z.core.$ZodType;
|
|
26
|
+
type Text = (z.ZodString | z.ZodStringFormat) & z.core.$ZodType;
|
|
27
|
+
export declare class DataSchema<T extends z.core.$ZodType = z.core.$ZodType> {
|
|
28
|
+
#private;
|
|
29
|
+
/** The zod type this schema denotes; declared only, never set. */
|
|
30
|
+
readonly '~type'?: T;
|
|
31
|
+
/** The factory (`z.<name>`, `z.iso.<name>` when `iso`) or the method that made this schema. */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly iso: boolean;
|
|
34
|
+
/** The schema a method was called on; `null` for a factory. */
|
|
35
|
+
readonly receiver: DataSchema | null;
|
|
36
|
+
readonly args: readonly unknown[];
|
|
37
|
+
constructor(name: string, iso: boolean, receiver: DataSchema | null, args: readonly unknown[]);
|
|
38
|
+
/** A zod schema given where a schema stands, held as one. */
|
|
39
|
+
static wrap<S extends z.core.$ZodType>(schema: S): DataSchema<S>;
|
|
40
|
+
/** Whether this node only wraps a zod schema. */
|
|
41
|
+
get wrapped(): z.ZodType | null;
|
|
42
|
+
protected derive<U extends z.core.$ZodType>(name: string, args: readonly unknown[]): DataSchema<U>;
|
|
43
|
+
min<S extends Bounded>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
44
|
+
max<S extends Bounded>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
45
|
+
length<S extends Sized>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
46
|
+
nonempty<S extends Sized>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
47
|
+
email(this: DataSchema<z.ZodString>, params?: Message): DataSchema<z.ZodString>;
|
|
48
|
+
url(this: DataSchema<z.ZodString>, params?: Message): DataSchema<z.ZodString>;
|
|
49
|
+
uuid(this: DataSchema<z.ZodString>, params?: UuidOptions): DataSchema<z.ZodString>;
|
|
50
|
+
startsWith<S extends Text>(this: DataSchema<S>, prefix: string, params?: Message): DataSchema<S>;
|
|
51
|
+
endsWith<S extends Text>(this: DataSchema<S>, suffix: string, params?: Message): DataSchema<S>;
|
|
52
|
+
includes<S extends Text>(this: DataSchema<S>, part: string, params?: IncludesOptions): DataSchema<S>;
|
|
53
|
+
regex<S extends Text>(this: DataSchema<S>, pattern: RegExp, params?: Message): DataSchema<S>;
|
|
54
|
+
int<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
55
|
+
positive<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
56
|
+
negative<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
57
|
+
nonnegative<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
58
|
+
nonpositive<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
59
|
+
gt<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
60
|
+
gte<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
61
|
+
lt<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
62
|
+
lte<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
63
|
+
multipleOf<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
64
|
+
optional(): DataSchema<z.ZodOptional<T>>;
|
|
65
|
+
nullable(): DataSchema<z.ZodNullable<T>>;
|
|
66
|
+
nullish(): DataSchema<z.ZodOptional<z.ZodNullable<T>>>;
|
|
67
|
+
array(): DataSchema<z.ZodArray<T>>;
|
|
68
|
+
default(value: z.core.util.NoUndefined<z.output<T>>): DataSchema<z.ZodDefault<T>>;
|
|
69
|
+
describe(description: string): DataSchema<T>;
|
|
70
|
+
or<U extends AnySchema>(option: U): DataSchema<z.ZodUnion<[T, ZodOf<U>]>>;
|
|
71
|
+
/** What zod's `parse` returns for `value`, from the schema this one denotes. */
|
|
72
|
+
parse(value: unknown): z.output<T>;
|
|
73
|
+
safeParse(value: unknown): z.ZodSafeParseResult<z.output<T>>;
|
|
74
|
+
get '~standard'(): T['~standard'];
|
|
75
|
+
}
|
|
76
|
+
/** An object schema: what `z.strictObject` and the methods that derive objects make. */
|
|
77
|
+
export declare class DataObject<Shape extends z.core.$ZodShape, Config extends z.core.$ZodObjectConfig> extends DataSchema<z.ZodObject<Shape, Config>> {
|
|
78
|
+
/** The zod fields, as zod's `.shape` holds them. */
|
|
79
|
+
get shape(): Shape;
|
|
80
|
+
extend<U extends DataShapeInput>(shape: U): DataObject<z.core.util.Extend<Shape, ZodShape<U>>, Config>;
|
|
81
|
+
pick<M extends z.core.util.Mask<keyof Shape>>(mask: M): DataObject<z.core.util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Config>;
|
|
82
|
+
omit<M extends z.core.util.Mask<keyof Shape>>(mask: M): DataObject<z.core.util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, Config>;
|
|
83
|
+
partial<M extends z.core.util.Mask<keyof Shape> = {
|
|
84
|
+
[K in keyof Shape]: true;
|
|
85
|
+
}>(mask?: M): DataObject<Partialized<Shape, M>, Config>;
|
|
86
|
+
describe(description: string): DataObject<Shape, Config>;
|
|
87
|
+
}
|
|
88
|
+
/** `Shape` with the fields `M` names optional, as zod's `.partial(mask)` makes it. */
|
|
89
|
+
type Partialized<Shape extends z.core.$ZodShape, M> = {
|
|
90
|
+
[K in keyof Shape]: K extends keyof M ? z.ZodOptional<Shape[K]> : Shape[K];
|
|
91
|
+
};
|
|
92
|
+
/** An enum schema: what `z.enum` and the methods that narrow an enum make. */
|
|
93
|
+
export declare class DataEnum<E extends z.core.util.EnumLike> extends DataSchema<z.ZodEnum<E>> {
|
|
94
|
+
get options(): z.ZodEnum<E>['options'];
|
|
95
|
+
get enum(): E;
|
|
96
|
+
exclude<const U extends readonly (keyof E)[]>(keys: U, params?: Message): DataEnum<z.core.util.Flatten<Omit<E, U[number]>>>;
|
|
97
|
+
extract<const U extends readonly (keyof E)[]>(keys: U, params?: Message): DataEnum<z.core.util.Flatten<Pick<E, U[number]>>>;
|
|
98
|
+
describe(description: string): DataEnum<E>;
|
|
99
|
+
}
|
|
100
|
+
export type UuidOptions = string | {
|
|
101
|
+
readonly message?: string;
|
|
102
|
+
readonly error?: string;
|
|
103
|
+
readonly version?: 'v1' | 'v2' | 'v3' | 'v4' | 'v5' | 'v6' | 'v7' | 'v8';
|
|
104
|
+
};
|
|
105
|
+
export type IncludesOptions = {
|
|
106
|
+
readonly message?: string;
|
|
107
|
+
readonly error?: string;
|
|
108
|
+
readonly position?: number;
|
|
109
|
+
};
|
|
110
|
+
export declare function isDataSchema(value: unknown): value is DataSchema;
|
|
111
|
+
/**
|
|
112
|
+
* How many built schemas stay cached: each holds the zod of one schema something validated with, and an endpoint uses
|
|
113
|
+
* two. Sized so a runtime that serves every endpoint of a large contract stays far below a Worker's 128 MB.
|
|
114
|
+
*/
|
|
115
|
+
export declare const BUILT_SCHEMAS = 64;
|
|
116
|
+
/**
|
|
117
|
+
* The zod schema `schema` denotes: a zod schema itself, or one held as data built. A cached build is reused and becomes
|
|
118
|
+
* the most recent; a schema built anew is cached, and the least recently used beyond `BUILT_SCHEMAS` is dropped. A step
|
|
119
|
+
* outside the subset throws a `SchemaRefusal`.
|
|
120
|
+
*/
|
|
121
|
+
export declare function zodSchemaOf(schema: z.core.$ZodType | DataSchema): z.core.$ZodType;
|
|
122
|
+
/** `zodSchemaOf` with the zod type the schema denotes. */
|
|
123
|
+
export declare function zodOf<S extends z.core.$ZodType | DataSchema>(schema: S): ZodOf<S>;
|
|
124
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * as z from './builder';
|
|
2
|
+
export { type AnySchema, BUILT_SCHEMAS, DataEnum, DataObject, DataSchema, type DataShapeInput, isDataSchema, type Message, type ZodOf, zodOf, zodSchemaOf, } from './data-schema';
|
|
3
|
+
export { type ReplayArg, type ReplayStep, replayStep, SCHEMA_SUBSET, SchemaRefusal, Unreadable } from './replay';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
/** A plain argument of a step, with every schema in it already zod. */
|
|
3
|
+
export type ReplayArg = string | number | boolean | null | RegExp | z.ZodType | Unreadable | readonly ReplayArg[] | {
|
|
4
|
+
readonly [key: string]: ReplayArg;
|
|
5
|
+
};
|
|
6
|
+
/** An argument a reader of source read that is no value of the subset (a builder call, say): refused by its kind. */
|
|
7
|
+
export declare class Unreadable {
|
|
8
|
+
readonly kind: string;
|
|
9
|
+
constructor(kind: string);
|
|
10
|
+
}
|
|
11
|
+
/** `z.<factory>(…)`, `z.iso.<factory>(…)` or `.<method>(…)` on a receiver. */
|
|
12
|
+
export type ReplayStep = {
|
|
13
|
+
readonly factory: string;
|
|
14
|
+
readonly iso: boolean;
|
|
15
|
+
} | {
|
|
16
|
+
readonly method: string;
|
|
17
|
+
readonly receiver: z.ZodType;
|
|
18
|
+
};
|
|
19
|
+
export declare const SCHEMA_SUBSET = "a schema of the supported z subset (packages/check/CLAUDE.md)";
|
|
20
|
+
/** A step zod would refuse, or one outside the contract subset: what is wrong and what is allowed there. */
|
|
21
|
+
export declare class SchemaRefusal extends Error {
|
|
22
|
+
readonly name = "SchemaRefusal";
|
|
23
|
+
readonly allowed: string;
|
|
24
|
+
constructor(message: string, allowed: string);
|
|
25
|
+
}
|
|
26
|
+
/** The zod schema `step` builds from `args`; a step outside the subset, or one zod refuses, throws a `SchemaRefusal`. */
|
|
27
|
+
export declare function replayStep(step: ReplayStep, args: readonly ReplayArg[]): z.ZodType;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The last non-empty segment of `pathname`, decoded, names a `.map` file; an undecodable one is refused too. */
|
|
2
|
+
export declare function namesSourceMap(pathname: string): boolean;
|
|
3
|
+
/** A file name, already decoded, that is a source map in any case. */
|
|
4
|
+
export declare function isSourceMapName(name: string): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PermissionEntry, type PrincipalAffiliation } from '@fabrika/auth-core';
|
|
1
|
+
import { type PermissionEntry, type PrincipalAffiliation, type Scope } from '@fabrika/auth-core';
|
|
2
2
|
import type { ActionOf, AnyContract, DimensionOf, RoleOf } from '../contract/define';
|
|
3
3
|
/** `app` is the connector of another application: its key reaches only the exports that application consumes. */
|
|
4
4
|
export type TestCallerKind = 'human' | 'machine' | 'link' | 'app';
|
|
@@ -92,4 +92,9 @@ export interface LinkTestCaller extends TestCallerCredential {
|
|
|
92
92
|
export type TestCaller = LabelledTestCaller | LinkTestCaller;
|
|
93
93
|
/** The permissions `grants` resolve to: a role becomes each of its actions in the role's scope. */
|
|
94
94
|
export declare function resolveGrants<C extends AnyContract>(contract: C, grants: readonly TestGrant<C>[]): PermissionEntry[];
|
|
95
|
+
/**
|
|
96
|
+
* The entries a grant of a role with `via` adds at `scope`, as IAM resolves them: each action through its relation,
|
|
97
|
+
* anywhere (`~rel`) for a global grant and only inside the node (`~relin`) for a scoped one. A name holding `:` adds none.
|
|
98
|
+
*/
|
|
99
|
+
export declare function relationEntries(via: Readonly<Record<string, readonly string[]>> | undefined, scope: Scope | null): PermissionEntry[];
|
|
95
100
|
export {};
|
|
@@ -3,9 +3,8 @@ import type { Database } from '@fabrika/db';
|
|
|
3
3
|
import { MemoryEmailSender } from '@fabrika/email/memory';
|
|
4
4
|
import type { FileObjectStore } from '@fabrika/platform';
|
|
5
5
|
import { type IamGateway } from '@fabrika/proxy-core';
|
|
6
|
-
import type { z } from 'zod/v4';
|
|
7
6
|
import type { RpcFetch } from '../client/transport';
|
|
8
|
-
import type { AnyContract, DimensionOf } from '../contract/define';
|
|
7
|
+
import type { AnyContract, DimensionOf, SchemaInput } from '../contract/define';
|
|
9
8
|
import type { TokenPurpose } from '../contract/token';
|
|
10
9
|
import type { FILE_SWEEP_JOB } from '../files/kinds';
|
|
11
10
|
import type { FILE_SCAN_JOB, FileScanner } from '../files/scan';
|
|
@@ -184,7 +183,7 @@ export type TokenPurposeName<C> = keyof TokensOf<C> & string;
|
|
|
184
183
|
/** What a token of purpose `P` carries, as a site passes it to `sign`. */
|
|
185
184
|
export type TokenClaimsInput<C, P extends string> = TokensOf<C> extends {
|
|
186
185
|
readonly [K in P]: TokenPurpose<infer Claims>;
|
|
187
|
-
} ?
|
|
186
|
+
} ? SchemaInput<Claims> : never;
|
|
188
187
|
/** Boots `app` the way its generated entrypoint would, behind the test proxy and IAM. Throws `BootError` like `boot`. */
|
|
189
188
|
export declare function testKit<C extends AnyContract>(app: ContractImplementation<C>, options?: TestKitOptions): TestKit<C>;
|
|
190
189
|
/** The kit of the generated tests, and its stand-in IAM, which seeds the invitations and links a case names. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ContractArtifact, type IamMembershipRpc, type MemberTarget, type PermissionEntry, type RevokeMemberInput, type Scope } from '@fabrika/auth-core';
|
|
2
|
-
import type
|
|
2
|
+
import { type TestCaller, type TestScope } from './caller';
|
|
3
3
|
/** A role a test caller holds in one scope value, or globally (`null`). */
|
|
4
4
|
export interface TestMembership {
|
|
5
5
|
readonly role: string;
|