@fabrika/app 0.8.2 → 0.9.0-cloudflare.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/package.json +40 -24
  2. package/skill/SKILL.md +29 -3
  3. package/skill/references/app-setup.md +29 -11
  4. package/skill/references/dev.md +2 -1
  5. package/skill/references/endpoint.md +12 -3
  6. package/skill/references/errors.md +39 -35
  7. package/skill/references/files.md +4 -2
  8. package/skill/references/jobs.md +9 -0
  9. package/skill/references/table-and-migration.md +19 -2
  10. package/skill/references/tests.md +33 -1
  11. package/skill/references/webhooks-links-connectors.md +1 -1
  12. package/src/build-recipe.ts +198 -0
  13. package/src/build.ts +60 -4
  14. package/src/bun.ts +33 -8
  15. package/src/cloudflare/application.ts +352 -0
  16. package/src/cloudflare/bindings.ts +159 -0
  17. package/src/cloudflare/names.ts +16 -0
  18. package/src/cloudflare/ops.ts +246 -0
  19. package/src/cloudflare/r2-files.ts +172 -0
  20. package/src/cloudflare.ts +99 -146
  21. package/src/contract/app-id.ts +5 -0
  22. package/src/contract/artifact-schema.ts +8 -1
  23. package/src/contract/build.ts +68 -11
  24. package/src/contract/compile.ts +1 -0
  25. package/src/contract/context.ts +9 -0
  26. package/src/contract/declaration.ts +2 -0
  27. package/src/contract/define.ts +28 -2
  28. package/src/contract/group.ts +10 -1
  29. package/src/contract/kit.ts +6 -2
  30. package/src/contract/platform.ts +3 -2
  31. package/src/contract/vocabulary.ts +26 -8
  32. package/src/dev/changes.ts +35 -0
  33. package/src/dev/contract-digest.ts +17 -0
  34. package/src/dev/index.ts +11 -0
  35. package/src/dev/launcher.ts +713 -0
  36. package/src/dev/output.ts +72 -0
  37. package/src/dev/wire.ts +136 -0
  38. package/src/disk-assets.ts +8 -3
  39. package/src/files/archive.ts +2 -2
  40. package/src/files/job-names.ts +12 -0
  41. package/src/files/kinds.ts +19 -7
  42. package/src/files/scan.ts +3 -4
  43. package/src/files/streams.ts +3 -1
  44. package/src/implement/anonymous.ts +11 -1
  45. package/src/implement/boot.ts +70 -7
  46. package/src/implement/bounded.ts +21 -2
  47. package/src/implement/capability.ts +18 -3
  48. package/src/implement/dispatch.ts +251 -147
  49. package/src/implement/egress.ts +341 -8
  50. package/src/implement/failures.ts +17 -1
  51. package/src/implement/faults.ts +1 -0
  52. package/src/implement/index.ts +1 -0
  53. package/src/implement/invocation.ts +18 -9
  54. package/src/implement/principal.ts +25 -2
  55. package/src/implement/terminals.ts +93 -0
  56. package/src/implement/workload.ts +24 -13
  57. package/src/jobs/report.ts +5 -1
  58. package/src/jobs/runner.ts +40 -19
  59. package/src/jobs/schedule.ts +7 -1
  60. package/src/jobs/scrub.ts +14 -1
  61. package/src/spa-fallback.ts +12 -0
  62. package/src/testing/endpoint-access.ts +307 -152
  63. package/src/testing/isolation.ts +8 -1
  64. package/src/testing/kit.ts +20 -2
  65. package/src/testing/proxy.ts +5 -5
  66. package/types/src/agent-skill.d.ts +29 -0
  67. package/types/src/build-recipe.d.ts +70 -0
  68. package/types/src/build.d.ts +29 -0
  69. package/types/src/bun.d.ts +66 -0
  70. package/types/src/client/caller.d.ts +19 -0
  71. package/types/src/client/contract.d.ts +131 -0
  72. package/types/src/client/error-reporting.d.ts +66 -0
  73. package/types/src/client/index.d.ts +4 -0
  74. package/types/src/client/rpc.d.ts +14 -0
  75. package/types/src/client/share.d.ts +2 -0
  76. package/types/src/client/transport.d.ts +42 -0
  77. package/types/src/cloudflare/application.d.ts +42 -0
  78. package/types/src/cloudflare/bindings.d.ts +33 -0
  79. package/types/src/cloudflare/names.d.ts +11 -0
  80. package/types/src/cloudflare/ops.d.ts +46 -0
  81. package/types/src/cloudflare/r2-files.d.ts +9 -0
  82. package/types/src/cloudflare.d.ts +42 -0
  83. package/types/src/contract/app-id.d.ts +2 -0
  84. package/types/src/contract/artifact-schema.d.ts +8 -0
  85. package/types/src/contract/attachment.d.ts +41 -0
  86. package/types/src/contract/build.d.ts +12 -0
  87. package/types/src/contract/compile.d.ts +11 -0
  88. package/types/src/contract/connect.d.ts +51 -0
  89. package/types/src/contract/context.d.ts +510 -0
  90. package/types/src/contract/declaration.d.ts +307 -0
  91. package/types/src/contract/defaults.d.ts +208 -0
  92. package/types/src/contract/define.d.ts +376 -0
  93. package/types/src/contract/file.d.ts +44 -0
  94. package/types/src/contract/group.d.ts +282 -0
  95. package/types/src/contract/handled.d.ts +18 -0
  96. package/types/src/contract/index.d.ts +19 -0
  97. package/types/src/contract/kit.d.ts +211 -0
  98. package/types/src/contract/platform.d.ts +9 -0
  99. package/types/src/contract/problems.d.ts +14 -0
  100. package/types/src/contract/redirect.d.ts +25 -0
  101. package/types/src/contract/schema-from-shape.d.ts +10 -0
  102. package/types/src/contract/schema-shape.d.ts +5 -0
  103. package/types/src/contract/snapshot-source.d.ts +15 -0
  104. package/types/src/contract/token.d.ts +58 -0
  105. package/types/src/contract/vocabulary.d.ts +32 -0
  106. package/types/src/contract/webhook-binding.d.ts +24 -0
  107. package/types/src/contract/webhook-scheme.d.ts +23 -0
  108. package/types/src/dev/changes.d.ts +7 -0
  109. package/types/src/dev/contract-digest.d.ts +1 -0
  110. package/types/src/dev/index.d.ts +2 -0
  111. package/types/src/dev/launcher.d.ts +32 -0
  112. package/types/src/dev/output.d.ts +28 -0
  113. package/types/src/dev/wire.d.ts +126 -0
  114. package/types/src/disk-assets.d.ts +6 -0
  115. package/types/src/errors.d.ts +46 -0
  116. package/types/src/fetch.d.ts +7 -0
  117. package/types/src/files/archive.d.ts +26 -0
  118. package/types/src/files/clamscan.d.ts +32 -0
  119. package/types/src/files/handle.d.ts +106 -0
  120. package/types/src/files/job-names.d.ts +9 -0
  121. package/types/src/files/kinds.d.ts +101 -0
  122. package/types/src/files/scan.d.ts +78 -0
  123. package/types/src/files/sniff.d.ts +7 -0
  124. package/types/src/files/streams.d.ts +17 -0
  125. package/types/src/files/treatment.d.ts +18 -0
  126. package/types/src/from-row.d.ts +20 -0
  127. package/types/src/honeypot.d.ts +2 -0
  128. package/types/src/implement/anonymous.d.ts +28 -0
  129. package/types/src/implement/attachment.d.ts +14 -0
  130. package/types/src/implement/boot.d.ts +120 -0
  131. package/types/src/implement/bounded.d.ts +32 -0
  132. package/types/src/implement/browser-config.d.ts +19 -0
  133. package/types/src/implement/capability.d.ts +144 -0
  134. package/types/src/implement/challenge.d.ts +75 -0
  135. package/types/src/implement/client-address.d.ts +11 -0
  136. package/types/src/implement/connect.d.ts +67 -0
  137. package/types/src/implement/crashes.d.ts +31 -0
  138. package/types/src/implement/dispatch.d.ts +221 -0
  139. package/types/src/implement/egress.d.ts +49 -0
  140. package/types/src/implement/environment.d.ts +14 -0
  141. package/types/src/implement/failures.d.ts +39 -0
  142. package/types/src/implement/faults.d.ts +45 -0
  143. package/types/src/implement/headers.d.ts +7 -0
  144. package/types/src/implement/implement.d.ts +58 -0
  145. package/types/src/implement/index.d.ts +25 -0
  146. package/types/src/implement/invocation.d.ts +125 -0
  147. package/types/src/implement/membership.d.ts +201 -0
  148. package/types/src/implement/multipart.d.ts +36 -0
  149. package/types/src/implement/params.d.ts +7 -0
  150. package/types/src/implement/principal.d.ts +57 -0
  151. package/types/src/implement/project.d.ts +11 -0
  152. package/types/src/implement/public.d.ts +61 -0
  153. package/types/src/implement/serve.d.ts +25 -0
  154. package/types/src/implement/terminals.d.ts +33 -0
  155. package/types/src/implement/tokens.d.ts +49 -0
  156. package/types/src/implement/types.d.ts +243 -0
  157. package/types/src/implement/urls.d.ts +15 -0
  158. package/types/src/implement/verifiers.d.ts +19 -0
  159. package/types/src/implement/webhook.d.ts +55 -0
  160. package/types/src/implement/workload.d.ts +56 -0
  161. package/types/src/implement/xlsx.d.ts +6 -0
  162. package/types/src/index.d.ts +12 -0
  163. package/types/src/jobs/exception.d.ts +40 -0
  164. package/types/src/jobs/mail.d.ts +67 -0
  165. package/types/src/jobs/report.d.ts +56 -0
  166. package/types/src/jobs/runner.d.ts +154 -0
  167. package/types/src/jobs/schedule.d.ts +17 -0
  168. package/types/src/jobs/scrub.d.ts +12 -0
  169. package/types/src/jobs/types.d.ts +98 -0
  170. package/types/src/react/caller.d.ts +30 -0
  171. package/types/src/react/errors.d.ts +40 -0
  172. package/types/src/react/hooks.d.ts +110 -0
  173. package/types/src/react/index.d.ts +5 -0
  174. package/types/src/react/provider.d.ts +58 -0
  175. package/types/src/react/store.d.ts +68 -0
  176. package/types/src/react/testing.d.ts +28 -0
  177. package/types/src/react/types.d.ts +33 -0
  178. package/types/src/rpc/builder.d.ts +52 -0
  179. package/types/src/rpc/contract.d.ts +23 -0
  180. package/types/src/rpc/dispatcher.d.ts +11 -0
  181. package/types/src/rpc/types.d.ts +62 -0
  182. package/types/src/service/define.d.ts +42 -0
  183. package/types/src/service/index.d.ts +3 -0
  184. package/types/src/service/serve.d.ts +28 -0
  185. package/types/src/spa-fallback.d.ts +2 -0
  186. package/types/src/standard-schema.d.ts +55 -0
  187. package/types/src/testing/caller.d.ts +95 -0
  188. package/types/src/testing/challenge.d.ts +11 -0
  189. package/types/src/testing/dev.d.ts +97 -0
  190. package/types/src/testing/endpoint-access.d.ts +131 -0
  191. package/types/src/testing/index.d.ts +12 -0
  192. package/types/src/testing/isolation.d.ts +3 -0
  193. package/types/src/testing/kit.d.ts +187 -0
  194. package/types/src/testing/membership.d.ts +132 -0
  195. package/types/src/testing/policy-isolation.d.ts +113 -0
  196. package/types/src/testing/preload.d.ts +1 -0
  197. package/types/src/testing/proxy.d.ts +40 -0
  198. package/types/src/testing/runner.d.ts +8 -0
  199. package/types/src/testing/sample-file.d.ts +5 -0
  200. package/types/src/testing/status.d.ts +4 -0
  201. package/types/src/undumpable.d.ts +5 -0
@@ -0,0 +1,33 @@
1
+ import type { IamMembershipRpc, IamTerminalRpc } from '@fabrika/auth-core';
2
+ import type { IamKeySource } from '../implement/boot.js';
3
+ import { type ConnectFetch } from '../implement/connect.js';
4
+ import type { SpaAssets } from '../implement/dispatch.js';
5
+ import type { WorkloadTokenSource } from '../implement/workload.js';
6
+ /** The method `name` of a binding, bound to it, or `null` when it has none. */
7
+ export declare function method(target: unknown, name: string): ((...args: unknown[]) => unknown) | null;
8
+ export declare function bindingKeySource(binding: unknown): IamKeySource;
9
+ /**
10
+ * IAM's membership operations on the `IAM` binding (`PropustkaApplication`), every answer decoded like the HTTP
11
+ * transport's. A binding without them is no membership transport, and `boot` refuses a contract that needs one.
12
+ */
13
+ export declare function bindingMembership(binding: unknown): IamMembershipRpc | undefined;
14
+ /** The identifications at a terminal over the IAM binding, when its entrypoint serves them (ADR-0067). */
15
+ export declare function bindingTerminals(binding: unknown): IamTerminalRpc | undefined;
16
+ /**
17
+ * IAM's token exchange on the `IAM` binding (`mintFromKey`), for the keys of the jobs, webhooks and public procedures.
18
+ * An answer that is not IAM's decided outcome throws: "IAM could not be asked".
19
+ */
20
+ export declare function bindingWorkloadTokens(binding: unknown): WorkloadTokenSource | undefined;
21
+ /**
22
+ * The SPA and link mounts' files from the Workers Assets binding, whose directory mirrors the request paths: the mount
23
+ * `/admin` reads `admin/…` of it, the root mount the rest (the Cloudflare deploy stages each mount's `dir` there). A page
24
+ * route that names no file (`isPageRoute`) gets the mount's `index.html`, as `diskAssets` serves it: Workers Assets
25
+ * answers `<prefix>/` with it. A missing asset stays 404.
26
+ */
27
+ export declare function bindingAssets(binding: unknown): SpaAssets | undefined;
28
+ /**
29
+ * The service bindings to owners' proxy Workers (`FABRIKA_CONNECT_<IMPORT>`), which `captureEnvironment` keeps from
30
+ * the application because no `FABRIKA_*` value reaches it. A binding routes by itself: the URL it is called with
31
+ * carries the owner's host, which the proxy Worker selects the application by.
32
+ */
33
+ export declare function connectBindings(env: Readonly<Record<string, unknown>>): Record<string, ConnectFetch>;
@@ -0,0 +1,11 @@
1
+ /** The Durable Object class the Cloudflare entry exports: one object per application environment runs it (ADR-0065). */
2
+ export declare const CLOUDFLARE_APPLICATION_CLASS = "FabrikaApplication";
3
+ /** The binding through which the application's Worker reaches its object. */
4
+ export declare const CLOUDFLARE_APPLICATION_BINDING = "FABRIKA_APPLICATION";
5
+ /** The R2 bucket binding of the environment's stored files. */
6
+ export declare const CLOUDFLARE_FILES_BINDING = "FABRIKA_FILES";
7
+ /**
8
+ * The Workers Assets binding the SPA and link mounts serve their files from. Its directory mirrors the request paths:
9
+ * the mount `/admin` serves `<directory>/admin/…`, the root mount `<directory>/…`.
10
+ */
11
+ export declare const CLOUDFLARE_ASSETS_BINDING = "ASSETS";
@@ -0,0 +1,46 @@
1
+ import { type ApplicationObjects, type OpsBootFailureContent, type OpsOperation } from '@fabrika/auth-core';
2
+ import type { SqliteCursor, SqliteValue } from '@fabrika/db/sqlite';
3
+ /** What the view reads of the object's storage; workerd's `DurableObjectStorage` has both optional members. */
4
+ export interface OpsStorage {
5
+ readonly sql: {
6
+ exec(query: string, ...bindings: SqliteValue[]): SqliteCursor;
7
+ /** The bun:sqlite test double has no size. */
8
+ readonly databaseSize?: number;
9
+ };
10
+ /** The bun:sqlite test double has no alarm. */
11
+ getAlarm?(): Promise<number | null>;
12
+ }
13
+ /** `X-Fabrika-Endpoint` of the composed ops row, the only value an ops request may carry (ADR-0022 rule 3). */
14
+ export declare const OPS_ENDPOINT: string;
15
+ /** What the platform wrote for the ops channel: the key digests and the objects a request may name. */
16
+ export interface OpsAccess {
17
+ readonly digests: readonly Uint8Array[];
18
+ readonly objects: ApplicationObjects;
19
+ }
20
+ /** The environment's ops access, or `null` (an older deploy, or a malformed value), which refuses every ops request. */
21
+ export declare function opsAccess(env: Readonly<Record<string, unknown>>): OpsAccess | null;
22
+ /** What an ops request reads of the object it reached. */
23
+ export interface OpsTarget {
24
+ readonly storage: OpsStorage;
25
+ /**
26
+ * The instance's last failed boot, the application's error text included. Asked only after authentication: it
27
+ * waits for a boot under way and never starts one.
28
+ */
29
+ bootFailure(): Promise<OpsBootFailureContent | null>;
30
+ }
31
+ /**
32
+ * Answers an ops request the Worker forwarded with the proxy secret, which the object checked before. Authentication
33
+ * runs first; an unknown operation, a malformed body and an object name the list lacks are refused after it.
34
+ */
35
+ export declare function serveOps(request: Request, access: OpsAccess | null, target: OpsTarget): Promise<Response>;
36
+ /** The object an ops request names, read with its operation's strict parser; `null` for a body that does not parse. */
37
+ export declare function objectNamed(operation: OpsOperation, body: unknown): string | null;
38
+ /** The request's body as JSON, or `undefined` when it is none: every parser refuses `undefined`. */
39
+ export declare function jsonBody(request: {
40
+ text(): Promise<string>;
41
+ }): Promise<unknown>;
42
+ /**
43
+ * Control's credentials on an ops request: the row's method, its endpoint header, and a key whose digest is one the
44
+ * platform wrote, compared in constant time. The Worker and the object both run it; it reads nothing the body names.
45
+ */
46
+ export declare function opsAuthenticated(request: Request, access: OpsAccess): boolean;
@@ -0,0 +1,9 @@
1
+ import { type FileObjectStore } from '@fabrika/platform';
2
+ /**
3
+ * R2 stores a stream only when its length is known up front, which an upload's is not. A body up to this size is
4
+ * buffered and written in one conditional put; a longer one goes up in parts of this size, so an object holds at most
5
+ * one part in memory. R2 takes parts of at least 5 MiB, all but the last of one size.
6
+ */
7
+ export declare const R2_PART_BYTES: number;
8
+ /** `bucket` (an R2 binding) as the files' object store, or `undefined` when the environment binds none. */
9
+ export declare function r2FileObjectStore(bucket: unknown): FileObjectStore | undefined;
@@ -0,0 +1,42 @@
1
+ import { type ContractWorkerOptions, type ImplementationLoader } from './cloudflare/application.js';
2
+ import type { FetchService, RequestExecutionContext } from './fetch.js';
3
+ export { markProductionProcess } from '@fabrika/db/production';
4
+ export { type ApplicationMigration, type ApplicationState, type ApplicationStorage, type ContractWorkerOptions, FabrikaApplication, type ImplementationLoader, } from './cloudflare/application.js';
5
+ /** Minimal structural view of a Workers `ExecutionContext`. */
6
+ export interface CloudflareExecutionContext extends RequestExecutionContext {
7
+ passThroughOnException(): void;
8
+ }
9
+ /** Minimal structural view of a Workers cron `ScheduledController`. */
10
+ export interface CloudflareScheduledController {
11
+ readonly scheduledTime: number;
12
+ readonly cron: string;
13
+ noRetry(): void;
14
+ }
15
+ /** Minimal structural view of a Workers queue `MessageBatch`. */
16
+ export interface CloudflareMessageBatch {
17
+ readonly queue: string;
18
+ readonly messages: ReadonlyArray<unknown>;
19
+ }
20
+ export interface CloudflareWorkerOptions<Env> {
21
+ scheduled?: (controller: CloudflareScheduledController, env: Env, exec: CloudflareExecutionContext) => Promise<void>;
22
+ queue?: (batch: CloudflareMessageBatch, env: Env, exec: CloudflareExecutionContext) => Promise<void>;
23
+ }
24
+ export interface CloudflareWorker<Env> {
25
+ fetch(request: Request, env: Env, exec: CloudflareExecutionContext): Promise<Response>;
26
+ scheduled?(controller: CloudflareScheduledController, env: Env, exec: CloudflareExecutionContext): Promise<void>;
27
+ queue?(batch: CloudflareMessageBatch, env: Env, exec: CloudflareExecutionContext): Promise<void>;
28
+ }
29
+ /** Adapt a runtime-neutral `{ fetch }` service to a Workers module export. */
30
+ export declare function createCloudflareWorker<Env>(app: FetchService<Env>, options?: CloudflareWorkerOptions<Env>): CloudflareWorker<Env>;
31
+ export interface ContractWorker {
32
+ fetch(request: Request, env: Readonly<Record<string, unknown>>, exec: CloudflareExecutionContext): Promise<Response>;
33
+ scheduled(controller: CloudflareScheduledController, env: Readonly<Record<string, unknown>>, exec: CloudflareExecutionContext): Promise<void>;
34
+ }
35
+ /**
36
+ * The Worker module of a contract application, called only by the generated entrypoint, which also exports
37
+ * `FabrikaApplication`. The application runs in the environment's Durable Object (ADR-0065): `fetch` forwards every
38
+ * request to it with the proxy secret, the proxy's own headers unchanged, and `scheduled` forwards the minute tick.
39
+ * An ops request goes to the object its body names instead (ADR-0069). The object captures the environment, imports
40
+ * the application and boots it.
41
+ */
42
+ export declare function createContractWorker(load: ImplementationLoader, options?: ContractWorkerOptions): ContractWorker;
@@ -0,0 +1,2 @@
1
+ /** The contract's application id rule; an id that holds to it reaches a generated script unquoted. */
2
+ export declare const CONTRACT_APP_ID_PATTERN: RegExp;
@@ -0,0 +1,8 @@
1
+ import { type ContractArtifact, type OutputShape, type SchemaShape } from '@fabrika/auth-core';
2
+ import { z } from 'zod/v4';
3
+ /** A `SchemaShape` read back as JSON. */
4
+ export declare const schemaShapeSchema: z.ZodType<SchemaShape>;
5
+ export declare const outputShapeSchema: z.ZodType<OutputShape>;
6
+ export declare const contractArtifactSchema: z.ZodType<ContractArtifact>;
7
+ /** Parses JSON that should be a contract artifact; throws a `ZodError` naming every mismatch. */
8
+ export declare function parseContractArtifact(value: unknown): ContractArtifact;
@@ -0,0 +1,41 @@
1
+ import { z } from 'zod/v4';
2
+ import { type AttachmentDeclaration } from './declaration';
3
+ import type { InputSchema, NotLoose, Schema } from './define';
4
+ declare const ATTACHMENT: unique symbol;
5
+ /** What `attachment()` adds to the rows' array schema: its declaration and its row schema. */
6
+ export interface AttachmentMark {
7
+ readonly declaration: AttachmentDeclaration;
8
+ readonly row: InputSchema;
9
+ }
10
+ /** An attachment output of rows `R`: the handler returns `z.input<R>[]`, and the caller receives a file. */
11
+ export type Attachment<R extends InputSchema> = z.ZodArray<R> & AttachmentBrand;
12
+ /** What tells an attachment output from a JSON one in the types. */
13
+ export interface AttachmentBrand {
14
+ readonly [ATTACHMENT]: AttachmentMark;
15
+ }
16
+ export interface AttachmentOptions<R> {
17
+ /**
18
+ * `'csv'`: RFC 4180, UTF-8 with a byte order mark, a header line of the row's field names. `'xlsx'`: one sheet, the
19
+ * header row of the field names, then a number, boolean or text cell per value, and a date cell for a string whose
20
+ * schema is `z.iso.date()` or `z.iso.datetime()`.
21
+ */
22
+ readonly format: 'csv' | 'xlsx';
23
+ /** The file name the browser saves: `[A-Za-z0-9._-]`, ending in `.csv` or `.xlsx`, as the format. */
24
+ readonly filename: string;
25
+ /** The row schema: a strict object of scalar fields, in the file's column order. */
26
+ readonly row: R;
27
+ /** The encoded file's limit; an encoding over it fails the invocation and sends no body. */
28
+ readonly maxBytes: number;
29
+ /** At most this many rows; 10 000 when left out. */
30
+ readonly maxRows?: number;
31
+ }
32
+ /**
33
+ * The output of a procedure that answers a file of `row`s. Like every builder it validates nothing: `compileContract`
34
+ * and the checker refuse a format, a name, a limit or a column outside what an attachment may be.
35
+ */
36
+ export declare function attachment<R extends InputSchema>(options: AttachmentOptions<R & NotLoose<R>>): Attachment<R>;
37
+ /** The rows' array schema marked with `declaration`; the static reader builds the evaluated value with it. */
38
+ export declare function attachmentOutput<R extends InputSchema>(row: R, declaration: AttachmentDeclaration): Attachment<R>;
39
+ /** The mark of an `attachment()` output, or `null` for any other schema. */
40
+ export declare function attachmentOf(schema: Schema): AttachmentMark | null;
41
+ export {};
@@ -0,0 +1,12 @@
1
+ import { type ContractArtifact, type FileShape, type SchemaShape, type TablePolicyArtifact } from '@fabrika/auth-core';
2
+ import { type ContractDeclaration } from './declaration';
3
+ /** Turnstile's `action`: the procedure's endpoint id, which the verification expects back. */
4
+ /** Validates a described contract against its table policies and normalizes it; throws `ContractError` with every problem. */
5
+ export declare function buildArtifact(contract: ContractDeclaration<SchemaShape>, tables: Readonly<Record<string, TablePolicyArtifact>>): ContractArtifact;
6
+ /** Whether a schema holds a file anywhere. */
7
+ export declare function containsFile(shape: SchemaShape): boolean;
8
+ /** The file fields of an input, by name: the parts a multipart body carries beside its JSON. */
9
+ export declare function fileFieldsOf(input: SchemaShape | null): ReadonlyMap<string, FileShape & {
10
+ readonly many: boolean;
11
+ readonly max: number;
12
+ }>;
@@ -0,0 +1,11 @@
1
+ import type { ContractArtifact, SchemaShape, TablePolicyArtifact } from '@fabrika/auth-core';
2
+ import { type Tables } from '@fabrika/db/tables';
3
+ import { type ContractDeclaration } from './declaration';
4
+ import type { AnyContract } from './define';
5
+ /**
6
+ * The normalized artifact of a contract and its table policies: what `defineTables` returned (`src/db/tables.ts`),
7
+ * or the artifact form of each policy.
8
+ */
9
+ export declare function compileContract<DB, P>(contract: AnyContract, tables: Tables<DB, P> | Readonly<Record<string, TablePolicyArtifact>>): ContractArtifact;
10
+ /** The contract with its schemas read as shapes; throws `ContractError` for a schema outside the subset. */
11
+ export declare function describeContract(contract: AnyContract): ContractDeclaration<SchemaShape>;
@@ -0,0 +1,51 @@
1
+ import { type ContractArtifact, type ExportDescription } from '@fabrika/auth-core';
2
+ import { z } from 'zod/v4';
3
+ import type { InputSchema, Schema } from './define';
4
+ /** One vendored procedure: the zod schemas `fabrika connect add` generated from the owner's description. */
5
+ export interface SnapshotProcedure {
6
+ readonly input: InputSchema | null;
7
+ readonly output: Schema;
8
+ }
9
+ /**
10
+ * The vendored description of another application's export, as `fabrika connect add` writes it to
11
+ * `fabrika/connect/<app>.<export>.v<version>.ts`. The consumer passes it to `implement({ connect })` and imports its
12
+ * digest into the contract.
13
+ */
14
+ export interface ConnectSnapshot {
15
+ readonly app: string;
16
+ readonly export: string;
17
+ readonly version: number;
18
+ readonly audience: string;
19
+ readonly digest: string;
20
+ /** By the procedure's dotted path in the export. */
21
+ readonly procedures: {
22
+ readonly [path: string]: SnapshotProcedure;
23
+ };
24
+ }
25
+ /** The description the owner serves for `name`, or `null` when the artifact declares no such export. */
26
+ export declare function exportDescription(artifact: ContractArtifact, name: string): ExportDescription | null;
27
+ /**
28
+ * The description a snapshot's schemas describe now, with the digest of that. A snapshot whose recomputed digest is
29
+ * not its own `digest` was edited after `fabrika connect add` wrote it. Throws `ContractError` for a schema outside
30
+ * the contract subset.
31
+ */
32
+ export declare function describeSnapshot(snapshot: ConnectSnapshot): ExportDescription;
33
+ /** The parser of a description another application served; the digest is checked by `parseExportDescription`. */
34
+ export declare const exportDescriptionSchema: z.ZodType<ExportDescription>;
35
+ /** A served description, parsed, whose digest is the digest of what it describes; throws `ContractError` otherwise. */
36
+ export declare function parseExportDescription(value: unknown): ExportDescription;
37
+ /**
38
+ * What an owner's change of one export version breaks for a consumer that imports `procedures` of it: a removed
39
+ * procedure, an input that accepts less, a changed output, or a changed audience. An output may not even gain a field,
40
+ * because the consumer parses every answer against its vendored schema, whose objects are strict; an input object may
41
+ * gain optional fields. Every other change is a new version. Empty when the change is compatible.
42
+ */
43
+ export declare function incompatibleChanges(before: ExportDescription, after: ExportDescription, procedures: readonly string[]): string[];
44
+ /**
45
+ * What `after` breaks for the callers of each mount `before` promises `compatibility: 'backward'`: a procedure it
46
+ * removes (including its generated challenge endpoint), an input or a query that accepts less, another output, another
47
+ * HTTP shape (method, path, body codec), file answer or access (its kind, callers, requirement and cross-origin form), or a
48
+ * mount moved. The promise binds the
49
+ * publication that drops it too, so a breaking change is a new mount beside the old one. Empty when compatible.
50
+ */
51
+ export declare function incompatibleMountChanges(before: ContractArtifact, after: ContractArtifact): string[];