@fabrika/app 0.9.0-dev.1 → 0.9.0-dev.10
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 +32 -26
- package/skill/SKILL.md +46 -15
- package/skill/references/app-setup.md +43 -12
- package/skill/references/dev.md +5 -2
- package/skill/references/endpoint.md +39 -28
- package/skill/references/errors.md +50 -37
- package/skill/references/files.md +8 -4
- package/skill/references/jobs.md +39 -7
- package/skill/references/table-and-migration.md +47 -3
- package/skill/references/tests.md +61 -10
- package/skill/references/webhooks-links-connectors.md +1 -1
- package/src/build-recipe.ts +198 -0
- package/src/build.ts +60 -4
- package/src/bun.ts +181 -13
- package/src/cloudflare/application.ts +822 -0
- package/src/cloudflare/bindings.ts +159 -0
- package/src/cloudflare/export.ts +621 -0
- package/src/cloudflare/import.ts +888 -0
- package/src/cloudflare/maintenance.ts +518 -0
- package/src/cloudflare/names.ts +16 -0
- package/src/cloudflare/ops.ts +375 -0
- package/src/cloudflare/r2-files.ts +172 -0
- package/src/cloudflare/restore.ts +167 -0
- package/src/cloudflare/tracker.ts +192 -0
- package/src/cloudflare.ts +100 -146
- package/src/contract/app-id.ts +5 -0
- package/src/contract/artifact-schema.ts +9 -1
- package/src/contract/build.ts +40 -2
- package/src/contract/capability-cases.ts +30 -0
- package/src/contract/compile.ts +1 -0
- package/src/contract/containers.ts +19 -0
- package/src/contract/context.ts +35 -9
- package/src/contract/declaration.ts +2 -0
- package/src/contract/defaults.ts +22 -2
- package/src/contract/define.ts +29 -3
- package/src/contract/index.ts +1 -0
- package/src/contract/kit.ts +4 -1
- package/src/contract/platform.ts +3 -2
- package/src/contract/vocabulary.ts +26 -8
- package/src/dev/changes.ts +5 -43
- package/src/dev/contract-digest.ts +17 -0
- package/src/dev/index.ts +1 -1
- package/src/dev/launcher.ts +197 -41
- package/src/dev/output.ts +13 -3
- package/src/dev/wire.ts +11 -1
- package/src/disk-assets.ts +8 -3
- package/src/files/archive.ts +2 -2
- package/src/files/handle.ts +2 -1
- package/src/files/job-names.ts +12 -0
- package/src/files/kinds.ts +74 -32
- package/src/files/scan.ts +3 -4
- package/src/files/streams.ts +3 -1
- package/src/implement/anonymous.ts +12 -11
- package/src/implement/boot.ts +84 -27
- package/src/implement/bounded.ts +21 -2
- package/src/implement/capability.ts +16 -4
- package/src/implement/dispatch.ts +423 -178
- package/src/implement/failures.ts +59 -4
- package/src/implement/faults.ts +5 -1
- package/src/implement/index.ts +1 -0
- package/src/implement/invocation.ts +62 -11
- package/src/implement/principal.ts +25 -2
- package/src/implement/terminals.ts +93 -0
- package/src/implement/tokens.ts +4 -2
- package/src/implement/types.ts +22 -4
- package/src/implement/workload.ts +42 -16
- package/src/jobs/mail.ts +8 -0
- package/src/jobs/report.ts +5 -1
- package/src/jobs/runner.ts +702 -126
- package/src/jobs/schedule.ts +7 -1
- package/src/jobs/scrub.ts +14 -1
- package/src/jobs/types.ts +6 -0
- package/src/spa-fallback.ts +12 -0
- package/src/testing/endpoint-access.ts +331 -169
- package/src/testing/index.ts +1 -1
- package/src/testing/isolation.ts +8 -1
- package/src/testing/kit.ts +86 -4
- package/src/testing/policy-isolation.ts +2 -2
- package/src/testing/proxy.ts +15 -10
- package/types/src/agent-skill.d.ts +29 -0
- package/types/src/build-recipe.d.ts +70 -0
- package/types/src/build.d.ts +29 -0
- package/types/src/bun.d.ts +99 -0
- package/types/src/client/caller.d.ts +19 -0
- package/types/src/client/contract.d.ts +131 -0
- package/types/src/client/error-reporting.d.ts +66 -0
- package/types/src/client/index.d.ts +4 -0
- package/types/src/client/rpc.d.ts +14 -0
- package/types/src/client/share.d.ts +2 -0
- package/types/src/client/transport.d.ts +42 -0
- package/types/src/cloudflare/application.d.ts +73 -0
- package/types/src/cloudflare/bindings.d.ts +33 -0
- package/types/src/cloudflare/export.d.ts +16 -0
- package/types/src/cloudflare/import.d.ts +47 -0
- package/types/src/cloudflare/maintenance.d.ts +117 -0
- package/types/src/cloudflare/names.d.ts +11 -0
- package/types/src/cloudflare/ops.d.ts +81 -0
- package/types/src/cloudflare/r2-files.d.ts +9 -0
- package/types/src/cloudflare/restore.d.ts +9 -0
- package/types/src/cloudflare/tracker.d.ts +29 -0
- package/types/src/cloudflare.d.ts +43 -0
- package/types/src/contract/app-id.d.ts +2 -0
- package/types/src/contract/artifact-schema.d.ts +10 -0
- package/types/src/contract/attachment.d.ts +41 -0
- package/types/src/contract/build.d.ts +12 -0
- package/types/src/contract/capability-cases.d.ts +9 -0
- package/types/src/contract/compile.d.ts +11 -0
- package/types/src/contract/connect.d.ts +51 -0
- package/types/src/contract/containers.d.ts +3 -0
- package/types/src/contract/context.d.ts +525 -0
- package/types/src/contract/declaration.d.ts +307 -0
- package/types/src/contract/defaults.d.ts +226 -0
- package/types/src/contract/define.d.ts +376 -0
- package/types/src/contract/file.d.ts +44 -0
- package/types/src/contract/group.d.ts +274 -0
- package/types/src/contract/handled.d.ts +18 -0
- package/types/src/contract/index.d.ts +20 -0
- package/types/src/contract/kit.d.ts +211 -0
- package/types/src/contract/platform.d.ts +9 -0
- package/types/src/contract/problems.d.ts +14 -0
- package/types/src/contract/redirect.d.ts +25 -0
- package/types/src/contract/schema-from-shape.d.ts +10 -0
- package/types/src/contract/schema-shape.d.ts +5 -0
- package/types/src/contract/snapshot-source.d.ts +15 -0
- package/types/src/contract/token.d.ts +58 -0
- package/types/src/contract/vocabulary.d.ts +32 -0
- package/types/src/contract/webhook-binding.d.ts +24 -0
- package/types/src/contract/webhook-scheme.d.ts +23 -0
- package/types/src/dev/changes.d.ts +7 -0
- package/types/src/dev/contract-digest.d.ts +1 -0
- package/types/src/dev/index.d.ts +2 -0
- package/types/src/dev/launcher.d.ts +32 -0
- package/types/src/dev/output.d.ts +28 -0
- package/types/src/dev/wire.d.ts +126 -0
- package/types/src/disk-assets.d.ts +6 -0
- package/types/src/errors.d.ts +46 -0
- package/types/src/fetch.d.ts +7 -0
- package/types/src/files/archive.d.ts +26 -0
- package/types/src/files/clamscan.d.ts +32 -0
- package/types/src/files/handle.d.ts +107 -0
- package/types/src/files/job-names.d.ts +9 -0
- package/types/src/files/kinds.d.ts +112 -0
- package/types/src/files/scan.d.ts +78 -0
- package/types/src/files/sniff.d.ts +7 -0
- package/types/src/files/streams.d.ts +17 -0
- package/types/src/files/treatment.d.ts +18 -0
- package/types/src/from-row.d.ts +20 -0
- package/types/src/honeypot.d.ts +2 -0
- package/types/src/implement/anonymous.d.ts +24 -0
- package/types/src/implement/attachment.d.ts +14 -0
- package/types/src/implement/boot.d.ts +128 -0
- package/types/src/implement/bounded.d.ts +32 -0
- package/types/src/implement/browser-config.d.ts +19 -0
- package/types/src/implement/capability.d.ts +142 -0
- package/types/src/implement/challenge.d.ts +75 -0
- package/types/src/implement/client-address.d.ts +11 -0
- package/types/src/implement/connect.d.ts +67 -0
- package/types/src/implement/crashes.d.ts +31 -0
- package/types/src/implement/dispatch.d.ts +251 -0
- package/types/src/implement/egress.d.ts +14 -0
- package/types/src/implement/environment.d.ts +14 -0
- package/types/src/implement/failures.d.ts +58 -0
- package/types/src/implement/faults.d.ts +48 -0
- package/types/src/implement/headers.d.ts +7 -0
- package/types/src/implement/implement.d.ts +58 -0
- package/types/src/implement/index.d.ts +25 -0
- package/types/src/implement/invocation.d.ts +136 -0
- package/types/src/implement/membership.d.ts +201 -0
- package/types/src/implement/multipart.d.ts +36 -0
- package/types/src/implement/params.d.ts +7 -0
- package/types/src/implement/principal.d.ts +57 -0
- package/types/src/implement/project.d.ts +11 -0
- package/types/src/implement/public.d.ts +61 -0
- package/types/src/implement/serve.d.ts +25 -0
- package/types/src/implement/terminals.d.ts +33 -0
- package/types/src/implement/tokens.d.ts +49 -0
- package/types/src/implement/types.d.ts +263 -0
- package/types/src/implement/urls.d.ts +15 -0
- package/types/src/implement/verifiers.d.ts +19 -0
- package/types/src/implement/webhook.d.ts +55 -0
- package/types/src/implement/workload.d.ts +61 -0
- package/types/src/implement/xlsx.d.ts +6 -0
- package/types/src/index.d.ts +12 -0
- package/types/src/jobs/exception.d.ts +40 -0
- package/types/src/jobs/mail.d.ts +67 -0
- package/types/src/jobs/report.d.ts +56 -0
- package/types/src/jobs/runner.d.ts +218 -0
- package/types/src/jobs/schedule.d.ts +17 -0
- package/types/src/jobs/scrub.d.ts +12 -0
- package/types/src/jobs/types.d.ts +98 -0
- package/types/src/react/caller.d.ts +30 -0
- package/types/src/react/errors.d.ts +40 -0
- package/types/src/react/hooks.d.ts +110 -0
- package/types/src/react/index.d.ts +5 -0
- package/types/src/react/provider.d.ts +58 -0
- package/types/src/react/store.d.ts +68 -0
- package/types/src/react/testing.d.ts +28 -0
- package/types/src/react/types.d.ts +33 -0
- package/types/src/rpc/builder.d.ts +52 -0
- package/types/src/rpc/contract.d.ts +23 -0
- package/types/src/rpc/dispatcher.d.ts +11 -0
- package/types/src/rpc/types.d.ts +62 -0
- package/types/src/service/define.d.ts +42 -0
- package/types/src/service/index.d.ts +3 -0
- package/types/src/service/serve.d.ts +28 -0
- package/types/src/spa-fallback.d.ts +2 -0
- package/types/src/standard-schema.d.ts +55 -0
- package/types/src/testing/caller.d.ts +95 -0
- package/types/src/testing/challenge.d.ts +11 -0
- package/types/src/testing/dev.d.ts +97 -0
- package/types/src/testing/endpoint-access.d.ts +132 -0
- package/types/src/testing/index.d.ts +12 -0
- package/types/src/testing/isolation.d.ts +3 -0
- package/types/src/testing/kit.d.ts +207 -0
- package/types/src/testing/membership.d.ts +132 -0
- package/types/src/testing/policy-isolation.d.ts +113 -0
- package/types/src/testing/preload.d.ts +1 -0
- package/types/src/testing/proxy.d.ts +40 -0
- package/types/src/testing/runner.d.ts +8 -0
- package/types/src/testing/sample-file.d.ts +5 -0
- package/types/src/testing/status.d.ts +4 -0
- package/types/src/undumpable.d.ts +5 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type ApplicationObjects, type OpsBootFailureContent, type OpsOperation } from '@fabrika/auth-core';
|
|
2
|
+
import type { SqliteCursor, SqliteStorage, SqliteValue } from '@fabrika/db/sqlite';
|
|
3
|
+
import type { SqliteMigrationBundle } from '@fabrika/db/sqlite-migrate';
|
|
4
|
+
import type { MaintenanceBarrier } from './maintenance.js';
|
|
5
|
+
/** What the view reads of the object's storage; workerd's `DurableObjectStorage` has every optional member. */
|
|
6
|
+
export interface OpsStorage {
|
|
7
|
+
readonly sql: {
|
|
8
|
+
exec(query: string, ...bindings: SqliteValue[]): SqliteCursor;
|
|
9
|
+
/** The bun:sqlite test double has no size. */
|
|
10
|
+
readonly databaseSize?: number;
|
|
11
|
+
};
|
|
12
|
+
/** The bun:sqlite test double has no alarm. */
|
|
13
|
+
getAlarm?(): Promise<number | null>;
|
|
14
|
+
/** The object's KV storage, which point-in-time recovery rewinds with its SQLite; the bun:sqlite double has none. */
|
|
15
|
+
get?(key: string): Promise<unknown>;
|
|
16
|
+
put?(key: string, value: unknown): Promise<void>;
|
|
17
|
+
/** The synchronous KV of a SQLite-backed object, in the same database; the bun:sqlite test double has none. */
|
|
18
|
+
readonly kv?: {
|
|
19
|
+
get(key: string): unknown;
|
|
20
|
+
put(key: string, value: unknown): void;
|
|
21
|
+
delete(key: string): boolean;
|
|
22
|
+
};
|
|
23
|
+
/** Wipes the object's database, its KV and its alarm; the bun:sqlite test double has none. */
|
|
24
|
+
deleteAll?(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The object's point-in-time recovery: workerd's storage bookmarks and the abort that resets the object. `null` where the
|
|
28
|
+
* storage has none (the bun:sqlite double, a runtime without PITR).
|
|
29
|
+
*/
|
|
30
|
+
export interface OpsRecovery {
|
|
31
|
+
getCurrentBookmark(): Promise<string>;
|
|
32
|
+
getBookmarkForTime(time: number): Promise<string>;
|
|
33
|
+
onNextSessionRestoreBookmark(bookmark: string): Promise<string>;
|
|
34
|
+
abort(reason: string): void;
|
|
35
|
+
}
|
|
36
|
+
/** `X-Fabrika-Endpoint` of the composed ops row, the only value an ops request may carry (ADR-0022 rule 3). */
|
|
37
|
+
export declare const OPS_ENDPOINT: string;
|
|
38
|
+
/** What the platform wrote for the ops channel: the key digests and the objects a request may name. */
|
|
39
|
+
export interface OpsAccess {
|
|
40
|
+
readonly digests: readonly Uint8Array[];
|
|
41
|
+
readonly objects: ApplicationObjects;
|
|
42
|
+
}
|
|
43
|
+
/** The environment's ops access, or `null` (an older deploy, or a malformed value), which refuses every ops request. */
|
|
44
|
+
export declare function opsAccess(env: Readonly<Record<string, unknown>>): OpsAccess | null;
|
|
45
|
+
/** What an ops request reads of the object it reached. */
|
|
46
|
+
export interface OpsTarget {
|
|
47
|
+
readonly storage: OpsStorage & SqliteStorage;
|
|
48
|
+
/** The environment's bucket (the `FABRIKA_FILES` R2 binding), where dumps and the maintenance state live. */
|
|
49
|
+
readonly bucket: unknown;
|
|
50
|
+
readonly recovery: OpsRecovery | null;
|
|
51
|
+
/** The digest of the contract this release was deployed with (`FABRIKA_CONTRACT_DIGEST`); a dump's manifest records it. */
|
|
52
|
+
readonly contractDigest: string | null;
|
|
53
|
+
/** The release's migration bundles in the order the object applies them: the framework's, then the application's. */
|
|
54
|
+
readonly migrations: readonly SqliteMigrationBundle[];
|
|
55
|
+
/**
|
|
56
|
+
* The instance's last failed boot, the application's error text included. Asked only after authentication: it
|
|
57
|
+
* waits for a boot under way and never starts one.
|
|
58
|
+
*/
|
|
59
|
+
bootFailure(): Promise<OpsBootFailureContent | null>;
|
|
60
|
+
/** The barrier of the object named `object`, read from R2 on a cold start; rejects while R2 cannot be read. */
|
|
61
|
+
maintenance(object: string): Promise<MaintenanceBarrier>;
|
|
62
|
+
/** Runs the pending migrations and boots the application; `false` when the boot failed. */
|
|
63
|
+
migrate(): Promise<boolean>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Answers an ops request the Worker forwarded with the proxy secret, which the object checked before. Authentication
|
|
67
|
+
* runs first; an unknown operation, a malformed body and an object name the list lacks are refused after it. Every
|
|
68
|
+
* operation needs the barrier, so while R2 cannot be read each answers 503.
|
|
69
|
+
*/
|
|
70
|
+
export declare function serveOps(request: Request, access: OpsAccess | null, target: OpsTarget): Promise<Response>;
|
|
71
|
+
/** The object an ops request names, read with its operation's strict parser; `null` for a body that does not parse. */
|
|
72
|
+
export declare function objectNamed(operation: OpsOperation, body: unknown): string | null;
|
|
73
|
+
/** The request's body as JSON, or `undefined` when it is none: every parser refuses `undefined`. */
|
|
74
|
+
export declare function jsonBody(request: {
|
|
75
|
+
text(): Promise<string>;
|
|
76
|
+
}): Promise<unknown>;
|
|
77
|
+
/**
|
|
78
|
+
* Control's credentials on an ops request: the row's method, its endpoint header, and a key whose digest is one the
|
|
79
|
+
* platform wrote, compared in constant time. The Worker and the object both run it; it reads nothing the body names.
|
|
80
|
+
*/
|
|
81
|
+
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,9 @@
|
|
|
1
|
+
import { type OpsRestoreRequest } from '@fabrika/auth-core';
|
|
2
|
+
import type { MaintenanceBarrier } from './maintenance.js';
|
|
3
|
+
import type { OpsTarget } from './ops.js';
|
|
4
|
+
/**
|
|
5
|
+
* One step of the original object's point-in-time restore (ADR-0070 §9 step 6). `prepare` and `arm` run in the
|
|
6
|
+
* barrier's turn, only under the published generation, on an object that is not the one ordinary traffic reaches
|
|
7
|
+
* (`serving`), while it is `inspect`; `verify` writes nothing and runs in any mode.
|
|
8
|
+
*/
|
|
9
|
+
export declare function serveRestore(target: OpsTarget, barrier: MaintenanceBarrier, step: OpsRestoreRequest, serving: boolean): Promise<Response>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type OpsTimersRequest, type OpsTimersView } from '@fabrika/auth-core';
|
|
2
|
+
import { type Scrubber } from '../jobs/scrub.js';
|
|
3
|
+
/** The global timers the tracker wraps while it is on; `globalThis` fits it. */
|
|
4
|
+
export interface TimerScope {
|
|
5
|
+
setTimeout(handler: unknown, delay?: unknown, ...args: unknown[]): unknown;
|
|
6
|
+
setInterval(handler: unknown, delay?: unknown, ...args: unknown[]): unknown;
|
|
7
|
+
clearTimeout(id?: unknown): void;
|
|
8
|
+
clearInterval(id?: unknown): void;
|
|
9
|
+
}
|
|
10
|
+
export interface TimerTracker {
|
|
11
|
+
/** Switches tracking on (wrapping the scope's timers) or off (restoring them and forgetting every record). */
|
|
12
|
+
track(on: boolean): void;
|
|
13
|
+
/**
|
|
14
|
+
* While tracking is on, records `promise` until it settles and answers a chain that settles as it does, rejection
|
|
15
|
+
* included, so the caller hands the chain to `waitUntil` and an unhandled rejection stays unhandled. Off, `promise`.
|
|
16
|
+
*/
|
|
17
|
+
pending<T>(promise: Promise<T>): Promise<T>;
|
|
18
|
+
/** The live records, oldest first, at most `OPS_TIMERS_CAP` of them. */
|
|
19
|
+
view(): OpsTimersView;
|
|
20
|
+
}
|
|
21
|
+
/** A tracker over `scope`'s timers, off until `track(true)`; each stack is scrubbed by `scrubber`. */
|
|
22
|
+
export declare function timerTracker(scope: TimerScope, now: () => number, scrubber: Scrubber): TimerTracker;
|
|
23
|
+
/**
|
|
24
|
+
* Records a promise an object hands to `waitUntil` while the tracker is on. Hand the answer, not `promise`, to
|
|
25
|
+
* `waitUntil`: it rejects as `promise` does, so an unhandled rejection still reaches the crash reporting.
|
|
26
|
+
*/
|
|
27
|
+
export declare function trackPending<T>(promise: Promise<T>): Promise<T>;
|
|
28
|
+
/** The isolate's live timers and `waitUntil` promises; `track` switches the isolate's tracker on or off first. */
|
|
29
|
+
export declare function serveTimers(request: OpsTimersRequest): Response;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 repair tick: the
|
|
39
|
+
* object's alarm runs the jobs, and the tick repairs its wakes and arms an alarm nothing armed yet.
|
|
40
|
+
* An ops request goes to the object its body names instead (ADR-0069). The object captures the environment, imports
|
|
41
|
+
* the application and boots it.
|
|
42
|
+
*/
|
|
43
|
+
export declare function createContractWorker(load: ImplementationLoader, options?: ContractWorkerOptions): ContractWorker;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ContractArtifact, type OutputShape, type SchemaShape } from '@fabrika/auth-core';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
/** A file's object key starts with its kind: the framework keeps its own objects in the files bucket under this prefix. */
|
|
4
|
+
export declare const RESERVED_FILE_KIND_PREFIX = "__fabrika";
|
|
5
|
+
/** A `SchemaShape` read back as JSON. */
|
|
6
|
+
export declare const schemaShapeSchema: z.ZodType<SchemaShape>;
|
|
7
|
+
export declare const outputShapeSchema: z.ZodType<OutputShape>;
|
|
8
|
+
export declare const contractArtifactSchema: z.ZodType<ContractArtifact>;
|
|
9
|
+
/** Parses JSON that should be a contract artifact; throws a `ZodError` naming every mismatch. */
|
|
10
|
+
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,9 @@
|
|
|
1
|
+
import type { CapabilityRequirement, DimensionArtifact } from '@fabrika/auth-core';
|
|
2
|
+
/**
|
|
3
|
+
* The capability that rules out `name`'s denied case, or `undefined` when `name` has one. Only an `over` capability
|
|
4
|
+
* loses it: to another capability that needs the same action on its dimension, on a container of it or on a dimension
|
|
5
|
+
* inside it. Every caller that passes that other one holds the action where the runtime lists the `over` dimension from
|
|
6
|
+
* (a value of it, of a container, or of a dimension inside it, through the same `containersOf`), so none is refused the
|
|
7
|
+
* list. Another one on an unrelated dimension leaves the case: a caller holding the action only there is refused (403).
|
|
8
|
+
*/
|
|
9
|
+
export declare function deniedCaseRuledOutBy(capabilities: Readonly<Record<string, CapabilityRequirement>>, name: string, dimensions: Readonly<Record<string, DimensionArtifact>>): string | undefined;
|
|
@@ -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[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { DimensionArtifact } from '@fabrika/auth-core';
|
|
2
|
+
/** Every dimension's containers, nearest first (`note → [workspace, organization]`); `buildArtifact` refuses a cycle. */
|
|
3
|
+
export declare function containersOf(dimensions: Readonly<Record<string, DimensionArtifact>>): ReadonlyMap<string, readonly string[]>;
|