@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
package/src/testing/kit.ts
CHANGED
|
@@ -39,11 +39,10 @@ import { type IamGateway, REQUEST_ID_HEADER, stripFabrikaCookies } from '@fabrik
|
|
|
39
39
|
import { exportJWK, generateKeyPair, SignJWT } from 'jose'
|
|
40
40
|
import { existsSync } from 'node:fs'
|
|
41
41
|
import { resolve } from 'node:path'
|
|
42
|
-
import type { z } from 'zod/v4'
|
|
43
42
|
import { challengeUrl } from '../client/contract'
|
|
44
43
|
import type { RpcFetch } from '../client/transport'
|
|
45
44
|
import { compileContract } from '../contract/compile'
|
|
46
|
-
import type { AnyContract, DimensionOf } from '../contract/define'
|
|
45
|
+
import type { AnyContract, DimensionOf, SchemaInput } from '../contract/define'
|
|
47
46
|
import type { TokenPurpose } from '../contract/token'
|
|
48
47
|
import { diskAssets } from '../disk-assets'
|
|
49
48
|
import type { RequestExecutionContext } from '../fetch'
|
|
@@ -247,7 +246,8 @@ type TokensOf<C> = C extends { readonly surface: { readonly tokens: infer T } }
|
|
|
247
246
|
export type TokenPurposeName<C> = keyof TokensOf<C> & string
|
|
248
247
|
|
|
249
248
|
/** What a token of purpose `P` carries, as a site passes it to `sign`. */
|
|
250
|
-
export type TokenClaimsInput<C, P extends string> = TokensOf<C> extends { readonly [K in P]: TokenPurpose<infer Claims> } ?
|
|
249
|
+
export type TokenClaimsInput<C, P extends string> = TokensOf<C> extends { readonly [K in P]: TokenPurpose<infer Claims> } ? SchemaInput<Claims>
|
|
250
|
+
: never
|
|
251
251
|
|
|
252
252
|
/** Each SPA mount from its built directory under `root` when one exists, as the deploy serves it; an empty page otherwise. */
|
|
253
253
|
function builtAssets(root: string): SpaAssets {
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
type RevokeMemberResult,
|
|
50
50
|
type Scope,
|
|
51
51
|
} from '@fabrika/auth-core'
|
|
52
|
-
import type
|
|
52
|
+
import { type LabelledTestCaller, relationEntries, type TestCaller, type TestScope } from './caller'
|
|
53
53
|
|
|
54
54
|
/** A role a test caller holds in one scope value, or globally (`null`). */
|
|
55
55
|
export interface TestMembership {
|
|
@@ -411,10 +411,12 @@ function membershipChanges(artifact: ContractArtifact, callers: DirectoryCallers
|
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
413
|
|
|
414
|
-
/** The permissions a role grants in `scope`, as IAM resolves a membership. */
|
|
414
|
+
/** The permissions a role grants in `scope`, its relations' included, as IAM resolves a membership. */
|
|
415
415
|
function roleEntries(artifact: ContractArtifact, held: TestMembership): PermissionEntry[] {
|
|
416
416
|
const scope = held.scope === null ? null : { type: held.scope.type, value: held.scope.value }
|
|
417
|
-
|
|
417
|
+
const role = artifact.roles[held.role]
|
|
418
|
+
const entries: PermissionEntry[] = (role?.grants ?? []).map((action) => ({ action, scope, source: 'grant' }))
|
|
419
|
+
return role === undefined || role.external === true ? entries : [...entries, ...relationEntries(role.via, scope)]
|
|
418
420
|
}
|
|
419
421
|
|
|
420
422
|
const samePermission = (left: PermissionEntry, right: PermissionEntry): boolean =>
|
|
@@ -521,7 +523,8 @@ export function kitMembership(artifact: ContractArtifact, callers: DirectoryCall
|
|
|
521
523
|
|
|
522
524
|
/**
|
|
523
525
|
* Could `caller` give `role` in `scope`: it holds an assigning role — there, or an application-wide role globally —
|
|
524
|
-
* and every action the role grants there
|
|
526
|
+
* and every action the role grants there, through a relation included, by a plain grant (`permits` reads no `~`
|
|
527
|
+
* entry).
|
|
525
528
|
*/
|
|
526
529
|
const roleProblem = (caller: TestCaller, scope: Scope, role: string): MembershipFailure | null => {
|
|
527
530
|
const declared = Object.hasOwn(artifact.roles, role) ? artifact.roles[role] : undefined
|
|
@@ -536,7 +539,8 @@ export function kitMembership(artifact: ContractArtifact, callers: DirectoryCall
|
|
|
536
539
|
const held = [...changes.rolesOf(caller.id, scope), ...appWide.map((grant) => grant.role)]
|
|
537
540
|
if (!declared.member.assignableBy.some((assigner) => held.includes(assigner))) return NOT_ALLOWED
|
|
538
541
|
const perms = [...permsOf(caller)]
|
|
539
|
-
|
|
542
|
+
const delegated = [...declared.grants, ...Object.values(declared.via ?? {}).flat()]
|
|
543
|
+
return delegated.every((action) => permits(perms, action, scope)) ? null : NOT_ALLOWED
|
|
540
544
|
}
|
|
541
545
|
|
|
542
546
|
const requestDelegation = (input: RequestDelegationInput): RequestDelegationResult => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/src/build.d.ts
CHANGED
|
@@ -6,6 +6,11 @@ export declare const GENERATED_ENTRY_FILE = "fabrika/entry.generated.ts";
|
|
|
6
6
|
export declare const IMPLEMENTATION_FILE = "src/app.ts";
|
|
7
7
|
/** The application's migrations as a module, relative to the application root: a Worker reads no file system. */
|
|
8
8
|
export declare const GENERATED_MIGRATIONS_FILE = "fabrika/migrations.generated.ts";
|
|
9
|
+
/**
|
|
10
|
+
* The compiled contract as a module, relative to the application root: the Cloudflare entrypoint hands it to boot, which
|
|
11
|
+
* checks its digest and reads it instead of compiling the contract inside the isolate.
|
|
12
|
+
*/
|
|
13
|
+
export declare const GENERATED_CONTRACT_FILE = "fabrika/contract.generated.ts";
|
|
9
14
|
/** Where an application keeps its migrations, relative to its root; `fabrika db new` writes there. */
|
|
10
15
|
export declare const MIGRATIONS_DIRECTORY = "db/migrations";
|
|
11
16
|
export type EntryRuntime = 'bun' | 'cloudflare';
|
|
@@ -13,8 +18,18 @@ export * from './build-recipe.js';
|
|
|
13
18
|
export { CLOUDFLARE_APPLICATION_BINDING, CLOUDFLARE_APPLICATION_CLASS, CLOUDFLARE_ASSETS_BINDING, CLOUDFLARE_FILES_BINDING, } from './cloudflare/names.js';
|
|
14
19
|
/** The entrypoint source for one runtime. */
|
|
15
20
|
export declare function generatedEntry(runtime: EntryRuntime): string;
|
|
16
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Writes the entrypoint under `root` and returns its path; the Cloudflare one also writes the migrations and the compiled
|
|
23
|
+
* contract modules it imports.
|
|
24
|
+
*/
|
|
17
25
|
export declare function writeGeneratedEntry(root: string, runtime: EntryRuntime): Promise<string>;
|
|
26
|
+
/** The compiled contract module source: the artifact's shared encoding (`encodeArtifact`) as one string, verbatim. */
|
|
27
|
+
export declare function generatedContract(encoded: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Compiles the application's contract in a child process, which loads `src/app.ts` with no variable but `PATH` and
|
|
30
|
+
* `HOME`, writes the module under `root` and returns its path. A contract that does not compile fails the build.
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeGeneratedContract(root: string): Promise<string>;
|
|
18
33
|
/** The application's migrations under `root`, every `.sql` file of `db/migrations` by name; none without the directory. */
|
|
19
34
|
export declare function applicationMigrations(root: string): Promise<readonly {
|
|
20
35
|
readonly name: string;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { z } from 'zod/v4';
|
|
2
1
|
import { type AttachmentBrand } from '../contract/attachment';
|
|
3
2
|
import { type ProcedureType } from '../contract/declaration';
|
|
4
|
-
import type { AnyContract, InputSchema, Procedure, Schema } from '../contract/define';
|
|
3
|
+
import type { AnyContract, InputSchema, Procedure, Schema, SchemaInput, SchemaOutput } from '../contract/define';
|
|
5
4
|
import { type ClientInput, type FileBrand } from '../contract/file';
|
|
6
5
|
import { type BounceOption, type RpcFetch } from './transport';
|
|
7
6
|
type SurfaceOf<C> = C extends {
|
|
@@ -17,7 +16,7 @@ export type ClientMount<C> = {
|
|
|
17
16
|
* One procedure: its input as the caller writes it (defaults optional), its output as parsed, and the output schema
|
|
18
17
|
* it parses with (`@fabrika/app/react` reads a cached answer back through it).
|
|
19
18
|
*/
|
|
20
|
-
export type ProcedureCall<I, O extends Schema> = ([I] extends [InputSchema] ? (input: ClientInput<
|
|
19
|
+
export type ProcedureCall<I, O extends Schema> = ([I] extends [InputSchema] ? (input: ClientInput<SchemaInput<I>>) => Promise<SchemaOutput<O>> : (input?: Record<never, never>) => Promise<SchemaOutput<O>>) & {
|
|
21
20
|
readonly output: O;
|
|
22
21
|
};
|
|
23
22
|
export type ClientTree<T> = {
|
|
@@ -114,7 +113,7 @@ export declare function attachmentAt(value: unknown): {
|
|
|
114
113
|
readonly path: string;
|
|
115
114
|
} | null;
|
|
116
115
|
/** The input `download` takes: the procedure's, or none. */
|
|
117
|
-
export type DownloadInput<I> = [I] extends [InputSchema] ? [input:
|
|
116
|
+
export type DownloadInput<I> = [I] extends [InputSchema] ? [input: SchemaInput<I>] : [input?: Record<never, never>];
|
|
118
117
|
/**
|
|
119
118
|
* Calls a procedure that answers a file (an attachment, or a `file('<kind>')` output) with the caller's credential, and
|
|
120
119
|
* answers the file: `blob()`, `stream()`, `save()`. An attachment is also offered as a download in a browser, under the
|
|
@@ -15,6 +15,8 @@ export interface ApplicationMigration {
|
|
|
15
15
|
export interface ContractWorkerOptions {
|
|
16
16
|
/** The application's own SQLite migrations, applied as the bundle `app` after the framework's `fabrika`. */
|
|
17
17
|
readonly migrations?: readonly ApplicationMigration[];
|
|
18
|
+
/** The contract artifact the build compiled, in its shared encoding, which boot reads instead of compiling (`BootOptions`). */
|
|
19
|
+
readonly approvedContract?: string;
|
|
18
20
|
/** Where the isolate hears of an unhandled rejection; the global `unhandledrejection` event by default. */
|
|
19
21
|
readonly rejections?: CrashEvents;
|
|
20
22
|
/** What posts a report to Operations' ingest; `fetch` by default. */
|
|
@@ -8,3 +8,11 @@ export declare const outputShapeSchema: z.ZodType<OutputShape>;
|
|
|
8
8
|
export declare const contractArtifactSchema: z.ZodType<ContractArtifact>;
|
|
9
9
|
/** Parses JSON that should be a contract artifact; throws a `ZodError` naming every mismatch. */
|
|
10
10
|
export declare function parseContractArtifact(value: unknown): ContractArtifact;
|
|
11
|
+
/** Whether a stored artifact is in the shared encoding, which `parseEncodedArtifact` reads, rather than plain. */
|
|
12
|
+
export declare function isEncodedArtifact(value: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Parses an artifact in the shared encoding (`encodeArtifact`): each shared shape over the shapes written before it,
|
|
15
|
+
* then the artifact over all of them. The result is the canonical artifact, its shared shapes one object each; throws a
|
|
16
|
+
* `ZodError` naming every mismatch.
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseEncodedArtifact(value: unknown): ContractArtifact;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
import { type ZodOf } from '../schema/data-schema';
|
|
2
3
|
import { type AttachmentDeclaration } from './declaration';
|
|
3
4
|
import type { InputSchema, NotLoose, Schema } from './define';
|
|
4
5
|
declare const ATTACHMENT: unique symbol;
|
|
@@ -7,8 +8,8 @@ export interface AttachmentMark {
|
|
|
7
8
|
readonly declaration: AttachmentDeclaration;
|
|
8
9
|
readonly row: InputSchema;
|
|
9
10
|
}
|
|
10
|
-
/** An attachment output of rows `R`: the handler returns `
|
|
11
|
-
export type Attachment<R extends InputSchema> = z.ZodArray<R
|
|
11
|
+
/** An attachment output of rows `R`: the handler returns `SchemaInput<R>[]`, and the caller receives a file. */
|
|
12
|
+
export type Attachment<R extends InputSchema> = z.ZodArray<ZodOf<R>> & AttachmentBrand;
|
|
12
13
|
/** What tells an attachment output from a JSON one in the types. */
|
|
13
14
|
export interface AttachmentBrand {
|
|
14
15
|
readonly [ATTACHMENT]: AttachmentMark;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { JobMailer, RpcCaller } from '@fabrika/auth-core';
|
|
2
2
|
import type { RowRef } from '@fabrika/db/capability';
|
|
3
3
|
import type { AnyDbIndex, ApplicationTables, ClaimedRowHandle, DataKind, FragmentTable, NoUnscoped, PublicApplicationTables, ReferenceTables, ScopedApplicationTables, ScopeTarget, TargetForm, Unavailable, UnscopedTables, WithinTables } from '@fabrika/db/tables';
|
|
4
|
-
import type { z } from 'zod/v4';
|
|
5
4
|
import type { StoredFilesHandle, StoredFilesReadHandle } from '../files/handle';
|
|
6
5
|
import type { AppCapability, Ref, Within } from '../implement/capability';
|
|
7
6
|
import type { ApplicationDirectory, LinkIssuing, MemberDirectory, MemberLookup, MemberManagement } from '../implement/membership';
|
|
@@ -11,7 +10,7 @@ import type { CapabilityOf, ConnectCall, RequestContext } from '../implement/typ
|
|
|
11
10
|
import type { WebhookDelivery, WebhookPrincipal } from '../implement/webhook';
|
|
12
11
|
import type { AppMail, JobContext } from '../jobs/types';
|
|
13
12
|
import type { ConnectSnapshot } from './connect';
|
|
14
|
-
import type { MemberAccess, Schema } from './define';
|
|
13
|
+
import type { MemberAccess, Schema, SchemaOutput } from './define';
|
|
15
14
|
import type { App } from './kit';
|
|
16
15
|
import type { TokenPurposes, TokenSigning } from './token';
|
|
17
16
|
import type { WebhookBindings } from './webhook-binding';
|
|
@@ -89,7 +88,7 @@ export type SqlValue = string | number | boolean | bigint | Date | null | readon
|
|
|
89
88
|
* transaction; each row is parsed (snake_case → camelCase, `Date` → ISO text, then `Row`).
|
|
90
89
|
*/
|
|
91
90
|
export interface SqlTag<Ix extends AnyDbIndex = AnyDbIndex, M extends SqlMode = SqlMode> {
|
|
92
|
-
<Row extends Schema>(row: Row): (text: TemplateStringsArray, ...values: readonly (SqlValue | SqlScope)[]) => Promise<
|
|
91
|
+
<Row extends Schema>(row: Row): (text: TemplateStringsArray, ...values: readonly (SqlValue | SqlScope)[]) => Promise<SchemaOutput<Row>[]>;
|
|
93
92
|
/**
|
|
94
93
|
* The capability's whole predicate on `table`: the object's key and every link of its chain for a `Ref`, what
|
|
95
94
|
* `ctx.db.within` matches for a `Within`, every row for `ctx.app`. Interpolated as
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BuiltinRoleKey, ChallengeProvider, Locale, MailTemplates, RpcCaller, WebhookScheme } from '@fabrika/auth-core';
|
|
2
2
|
import type { z } from 'zod/v4';
|
|
3
|
+
import type { DataObject, DataSchema, ZodOf } from '../schema/data-schema';
|
|
3
4
|
import { type CronDeclaration, type CspDeclaration, type ExportAccessDeclaration, type ExportDeclaration, type FileKindDeclaration, type HealthMountDeclaration, type ImportDeclaration, type LinkAccessDeclaration, type LinkMountDeclaration, type ProcedureDeclaration, type ProcedureTreeDeclaration, type ProcedureType, type RpcMountDeclaration, type SpaAccessDeclaration, type SpaMountDeclaration, type WebhookMountDeclaration } from './declaration';
|
|
4
5
|
import type { TokenPurposes } from './token';
|
|
5
6
|
export type Path = `/${string}`;
|
|
@@ -9,16 +10,24 @@ export declare function isPath(value: string): value is Path;
|
|
|
9
10
|
export interface JobLimitsOption {
|
|
10
11
|
readonly timeoutMs?: number;
|
|
11
12
|
}
|
|
12
|
-
/**
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Any zod 4 schema, or one held as data (`@fabrika/app/schema`). `compileContract` refuses every form outside the
|
|
15
|
+
* contract subset.
|
|
16
|
+
*/
|
|
17
|
+
export type Schema = z.core.$ZodType | DataSchema;
|
|
18
|
+
/** What a schema admits once parsed. */
|
|
19
|
+
export type SchemaOutput<S> = z.output<ZodOf<S>>;
|
|
20
|
+
/** What a schema takes before parsing. */
|
|
21
|
+
export type SchemaInput<S> = z.input<ZodOf<S>>;
|
|
14
22
|
/**
|
|
15
23
|
* An input object. zod 4's types do not tell `z.object` from `z.strictObject`, so the type refuses only loose
|
|
16
24
|
* objects; `compileContract` and `@fabrika/check` refuse `z.object` too.
|
|
17
25
|
*/
|
|
18
|
-
export type InputSchema = z.ZodObject<z.core.$ZodShape, z.core.$ZodObjectConfig>;
|
|
26
|
+
export type InputSchema = z.ZodObject<z.core.$ZodShape, z.core.$ZodObjectConfig> | DataObject<z.core.$ZodShape, z.core.$ZodObjectConfig>;
|
|
19
27
|
type LooseMessage = 'a loose object admits undeclared keys: declare it with z.strictObject({ … })';
|
|
20
28
|
/** `S`, unless it is an object that admits undeclared keys (`.loose()`, `.passthrough()`, `.catchall()`). */
|
|
21
|
-
export type NotLoose<S> = S extends
|
|
29
|
+
export type NotLoose<S> = S extends Schema ? LooseChecked<S, ZodOf<S>> : S;
|
|
30
|
+
type LooseChecked<S, Z> = Z extends z.ZodObject<z.core.$ZodShape, infer Config extends z.core.$ZodObjectConfig> ? string extends keyof Config['out'] ? LooseMessage : S : S;
|
|
22
31
|
/** Fields a builder sets itself: an options object that carries one does not type-check. */
|
|
23
32
|
type Owned<K extends string> = {
|
|
24
33
|
readonly [P in K]?: never;
|
|
@@ -66,7 +75,8 @@ export interface RoleDef<A extends string, D extends string, R extends string> {
|
|
|
66
75
|
readonly external?: true;
|
|
67
76
|
/**
|
|
68
77
|
* Relation → actions: a holder of this role, granted globally, holds them at each node a row of the relation's
|
|
69
|
-
* source names them at (`via: { owner: ['projects.edit'] }`). A
|
|
78
|
+
* source names them at (`via: { owner: ['projects.edit'] }`). A grant at a value holds them only on rows inside that
|
|
79
|
+
* value, so a membership role's relation has the role's dimension or one inside it. An external role takes none.
|
|
70
80
|
*/
|
|
71
81
|
readonly via?: {
|
|
72
82
|
readonly [relation: string]: readonly A[];
|
|
@@ -182,7 +192,7 @@ export interface PublicAccess {
|
|
|
182
192
|
readonly public: true;
|
|
183
193
|
}
|
|
184
194
|
/** Without an `input`, TS infers `I` as its whole constraint, not the `null` default; both mean "no input". */
|
|
185
|
-
export type InputOf<I> = [I] extends [InputSchema] ?
|
|
195
|
+
export type InputOf<I> = [I] extends [InputSchema] ? SchemaOutput<I> : Record<never, never>;
|
|
186
196
|
/** Input fields of string type: the only fields a scope value can be read from. */
|
|
187
197
|
export type StringField<In> = {
|
|
188
198
|
[K in keyof In]-?: In[K] extends string ? K : never;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { EndpointCache, RpcCaller } from '@fabrika/auth-core';
|
|
2
2
|
import type { AnyDbIndex, ReadOnlyUnscoped, Unavailable, UnscopedDeclaration, UnscopedMode } from '@fabrika/db/tables';
|
|
3
|
-
import type { z } from 'zod/v4';
|
|
4
3
|
import type { Snake } from '../from-row';
|
|
5
4
|
import type { ExtraKeys, HandlerInput, IsAny } from '../implement/types';
|
|
6
5
|
import type { AttachmentBrand } from './attachment';
|
|
7
6
|
import type { CheckedAccess, Declared, EndpointContext, ExportContext, ImportOf, KickContext, KitTypes, LinkContext, PublicContext, SqlMode, TokensContext, WebhooksContext } from './context';
|
|
8
7
|
import type { ProcedureType } from './declaration';
|
|
9
|
-
import type { AppAccess, CapabilitiesAccess, CapabilityAccess, ChallengeOption, InputOf, InputSchema, LinkAccess, MemberAccess, MutationAccess, NotLoose, Procedure, PublicAccess, QueryAccess, Schema } from './define';
|
|
8
|
+
import type { AppAccess, CapabilitiesAccess, CapabilityAccess, ChallengeOption, InputOf, InputSchema, LinkAccess, MemberAccess, MutationAccess, NotLoose, Procedure, PublicAccess, QueryAccess, Schema, SchemaInput, SchemaOutput } from './define';
|
|
10
9
|
import type { WithClaims } from './token';
|
|
11
10
|
/** Fields a builder sets itself: a definition that carries one does not type-check. */
|
|
12
11
|
type Owned<K extends string> = {
|
|
@@ -74,7 +73,15 @@ export type SignsField<Sg, Purposes extends string> = {
|
|
|
74
73
|
* guard on the global `fetch` refuses any other while the site runs; a public procedure declares none.
|
|
75
74
|
*/
|
|
76
75
|
export interface EgressField {
|
|
77
|
-
readonly egress?: readonly `https://${string}`[]
|
|
76
|
+
readonly egress?: readonly `https://${string}`[] | Unavailable<"egress: 'public' is a cron job's only: record a row and kick a job that declares it">;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A cron job's `egress`: its exact HTTPS origins, or `'public'`, every public host over HTTPS or HTTP on its default
|
|
80
|
+
* port, for a job that calls the websites its operators name (ADR-0075). The guard refuses IP addresses, local and
|
|
81
|
+
* internal names and the installation's own hosts, checks each redirect, and bounds each request's time and body.
|
|
82
|
+
*/
|
|
83
|
+
export interface JobEgressField {
|
|
84
|
+
readonly egress?: readonly `https://${string}`[] | 'public';
|
|
78
85
|
}
|
|
79
86
|
/** Each purpose `signs` names is one of `defineApp`'s `tokens`. */
|
|
80
87
|
type KnownPurposes<Sg, Purposes extends string> = Sg extends readonly (infer P extends string)[] ? [Exclude<P, Purposes>] extends [never] ? LiteralList<Sg> : Unavailable<`signs names ${ListOf<Exclude<P, Purposes>>}, which defineApp's tokens do not declare`> : unknown;
|
|
@@ -149,7 +156,7 @@ type LastOf<U> = (U extends unknown ? (member: () => U) => void : never) extends
|
|
|
149
156
|
/** `'a' | 'b'` → `'a, b'`, for a message. */
|
|
150
157
|
export type ListOf<U extends string, Listed extends string = ''> = [U] extends [never] ? Listed : ListOf<Exclude<U, LastOf<U>>, Listed extends '' ? LastOf<U> & string : `${LastOf<U> & string}, ${Listed}`>;
|
|
151
158
|
/** The fields, at any depth, that a handler `F` returns and the output `O` does not declare. */
|
|
152
|
-
export type UndeclaredFields<F, O extends Schema> = ExtraKeys<Returned<F>,
|
|
159
|
+
export type UndeclaredFields<F, O extends Schema> = ExtraKeys<Returned<F>, SchemaInput<O>>;
|
|
153
160
|
/** An object with a camelCase field, which a database row names in snake_case. */
|
|
154
161
|
type HasCamel<V> = {
|
|
155
162
|
[K in keyof V]: K extends string ? (Snake<K> extends K ? never : K) : never;
|
|
@@ -168,7 +175,7 @@ type RowShaped<V> = V extends readonly (infer Item)[] ? readonly RowShaped<Item>
|
|
|
168
175
|
* `ExactReturn` refuses with the fix, as it refuses anything but rows from an attachment's handler. Any other mistake
|
|
169
176
|
* keeps the compiler's own message about the output.
|
|
170
177
|
*/
|
|
171
|
-
export type HandlerReturn<F, O extends Schema> = [Returned<F>] extends [
|
|
178
|
+
export type HandlerReturn<F, O extends Schema> = [Returned<F>] extends [SchemaInput<O>] ? SchemaInput<O> : [O] extends [AttachmentBrand] ? unknown : [Returned<F>] extends [RowShaped<SchemaInput<O>>] ? RowShaped<SchemaInput<O>> : SchemaInput<O>;
|
|
172
179
|
/** A kit endpoint's handler, returning `R`; `X` adds what its HTTP shape reads beside the input (`query`). */
|
|
173
180
|
export type KitHandler<In, Ctx, R, X = unknown> = (args: {
|
|
174
181
|
readonly input: In;
|
|
@@ -179,7 +186,7 @@ export type KitHandler<In, Ctx, R, X = unknown> = (args: {
|
|
|
179
186
|
* as the claims of its purpose.
|
|
180
187
|
*/
|
|
181
188
|
export type QueryArgs<Q, T = Record<never, never>> = [Q] extends [never] ? unknown : Q extends InputSchema ? {
|
|
182
|
-
readonly query: WithClaims<
|
|
189
|
+
readonly query: WithClaims<SchemaOutput<Q>, T>;
|
|
183
190
|
} : unknown;
|
|
184
191
|
/**
|
|
185
192
|
* The wire of a procedure: `POST` with a JSON body by default; a query may be `GET`, its input then flat scalar URL
|
|
@@ -200,7 +207,7 @@ export interface HttpOption<Q> {
|
|
|
200
207
|
* returns a database row where the output is camelCase, anything but rows for an attachment, or, at any depth, a
|
|
201
208
|
* field the output does not declare. A field whose type is an error elsewhere in the handler is not reported again here.
|
|
202
209
|
*/
|
|
203
|
-
export type ExactReturn<F, O extends Schema, E> = [Returned<F>] extends [
|
|
210
|
+
export type ExactReturn<F, O extends Schema, E> = [Returned<F>] extends [SchemaInput<O>] ? [UndeclaredFields<F, O>] extends [never] ? E : IsAny<UndeclaredFields<F, O>> extends true ? E : Unavailable<`the handler returns ${ListOf<UndeclaredFields<F, O> & string>}, which the output does not declare: return only declared fields`> : [O] extends [AttachmentBrand] ? Unavailable<'an attachment handler returns its rows: an array of its row schema, with nothing around it'> : Unavailable<`the handler returns a database row (${ListOf<UndeclaredFields<F, O> & string>}) where the output is camelCase: map it with fromRow(Schema, row) from @fabrika/app`>;
|
|
204
211
|
/** A declared, handled endpoint: what a group holds. Its type keeps the declaration and drops the handler's. */
|
|
205
212
|
export interface Endpoint<T extends ProcedureType, I extends InputSchema | null, O extends Schema, Acc, D> extends Procedure<T, I, O, Acc> {
|
|
206
213
|
readonly declared: D;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { contractArtifactSchema, parseContractArtifact, schemaShapeSchema } from './artifact-schema';
|
|
1
|
+
export { contractArtifactSchema, isEncodedArtifact, parseContractArtifact, parseEncodedArtifact, schemaShapeSchema } from './artifact-schema';
|
|
2
2
|
export { type Attachment, attachment, type AttachmentBrand, type AttachmentMark, attachmentOf, type AttachmentOptions, attachmentOutput, } from './attachment';
|
|
3
3
|
export { buildArtifact } from './build';
|
|
4
4
|
export { deniedCaseRuledOutBy } from './capability-cases';
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { JobMailer, RpcCaller, WebhookScheme } from '@fabrika/auth-core';
|
|
2
2
|
import type { AnyDbIndex, DbIndex, Tables, Unavailable, UnscopedDeclaration, UnscopedMode } from '@fabrika/db/tables';
|
|
3
|
-
import type { z } from 'zod/v4';
|
|
4
3
|
import type { Declared, JobKitContext, KickContext, KitImports, KitTypes, NoTablesIndex, SqlMode, TokensContext, WebhookKitContext } from './context';
|
|
5
4
|
import { type ExportAccessDeclaration, type ImportDeclaration, type LinkAccessDeclaration, type ProcedureType } from './declaration';
|
|
6
|
-
import { type Contract, type CreatableDimension, type CronJob, type Export, type InputSchema, type JobLimitsOption, type Kit, type LinkMount, type NotLoose, type Path, type ProcedureTree, type RpcMount, type Schema, type Surface, type WebhookMount } from './define';
|
|
7
|
-
import type { DeclaredFields, EgressField, Endpoint, ExportKit, Group, GroupBuild, GroupInput, GroupKit, KicksField, LimitsOption, LinkGroupKit, ListOf, PendingIn, SignsField } from './group';
|
|
5
|
+
import { type Contract, type CreatableDimension, type CronJob, type Export, type InputSchema, type JobLimitsOption, type Kit, type LinkMount, type NotLoose, type Path, type ProcedureTree, type RpcMount, type Schema, type SchemaOutput, type Surface, type WebhookMount } from './define';
|
|
6
|
+
import type { DeclaredFields, EgressField, Endpoint, ExportKit, Group, GroupBuild, GroupInput, GroupKit, JobEgressField, KicksField, LimitsOption, LinkGroupKit, ListOf, PendingIn, SignsField } from './group';
|
|
8
7
|
import type { TokenPurposes } from './token';
|
|
9
8
|
import type { AnyAppVocabulary, AppVocabulary } from './vocabulary';
|
|
10
9
|
/** Fields a builder sets itself: an options object that carries one does not type-check. */
|
|
@@ -31,7 +30,7 @@ export type CronOptions<Acts, S, U, Is, Ix extends AnyDbIndex, M = never, Ks = n
|
|
|
31
30
|
readonly actions: Acts;
|
|
32
31
|
readonly limits?: JobLimitsOption;
|
|
33
32
|
readonly retries?: number;
|
|
34
|
-
} & DeclaredFields<S, U, never, Is, Ix> & MailerField<M> & KicksField<Ks> & SignsField<Sg, Purposes> &
|
|
33
|
+
} & DeclaredFields<S, U, never, Is, Ix> & MailerField<M> & KicksField<Ks> & SignsField<Sg, Purposes> & JobEgressField;
|
|
35
34
|
/** The mail transport a job reaches, inferred from its optional field and then required, like a declared field. */
|
|
36
35
|
type MailerField<M> = {
|
|
37
36
|
/** `'installation'`: the installation's mail transport; `'own'`: the application's own. */
|
|
@@ -64,7 +63,7 @@ export interface KitWebhook<B extends string, Acts extends string, I extends Sch
|
|
|
64
63
|
/** A webhook before `.handle`: the contract refuses it as a mount. */
|
|
65
64
|
export interface WebhookBuilder<K extends KitTypes, B extends string, Acts extends string, I extends InputSchema, D extends Declared<SqlMode, unknown, never, never>, Ks = never, Sg = never> {
|
|
66
65
|
handle(handler: (args: {
|
|
67
|
-
readonly input:
|
|
66
|
+
readonly input: SchemaOutput<I>;
|
|
68
67
|
readonly ctx: WebhookKitContext<K, B, Acts, D> & KickContext<Ks> & TokensContext<K, Sg>;
|
|
69
68
|
}) => void | Promise<void>): KitWebhook<B, Acts, I, D>;
|
|
70
69
|
}
|
|
@@ -8,6 +8,7 @@ export declare class ContractError extends Error {
|
|
|
8
8
|
export declare class Problems {
|
|
9
9
|
#private;
|
|
10
10
|
add(where: string, problem: string): void;
|
|
11
|
+
isEmpty(): boolean;
|
|
11
12
|
throwIfAny(): void;
|
|
12
13
|
}
|
|
13
14
|
/** A builder of the staged kit whose signature is fixed and whose runtime a later work unit of the sprint adds. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SchemaShape } from '@fabrika/auth-core';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
|
+
import { type DataSchema } from '../schema/data-schema';
|
|
3
4
|
import type { Problems } from './problems';
|
|
4
|
-
/** A schema's shape, or `null` after recording why it has none. */
|
|
5
|
-
export declare function describeSchema(
|
|
5
|
+
/** A schema's shape, or `null` after recording why it has none. A schema held as data is read as the zod it builds. */
|
|
6
|
+
export declare function describeSchema(described: z.core.$ZodType | DataSchema, where: string, problems: Problems): SchemaShape | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
-
import type { InputSchema, NotLoose, Schema } from './define';
|
|
2
|
+
import type { InputSchema, NotLoose, Schema, SchemaInput, SchemaOutput } from './define';
|
|
3
3
|
declare const SIGNED_TOKEN: unique symbol;
|
|
4
4
|
/** The longest token a field admits: a purpose's claims, a key id, an expiry and a signature, URL-safe. */
|
|
5
5
|
export declare const SIGNED_TOKEN_MAX_LENGTH = 4096;
|
|
@@ -44,14 +44,14 @@ export type TokenPurposeOf<V> = V extends {
|
|
|
44
44
|
readonly [z.core.$brand]: infer B;
|
|
45
45
|
} ? keyof B extends TokenBrand<infer P> ? P : never : never;
|
|
46
46
|
/** One field as the handler holds it: a signed token as the claims of its purpose, any other field as it is. */
|
|
47
|
-
type ClaimsField<V, T> = [TokenPurposeOf<NonNullable<V>>] extends [never] ? V : (TokenPurposeOf<NonNullable<V>> extends keyof T ? T[TokenPurposeOf<NonNullable<V>>] extends TokenPurpose<infer C> ?
|
|
47
|
+
type ClaimsField<V, T> = [TokenPurposeOf<NonNullable<V>>] extends [never] ? V : (TokenPurposeOf<NonNullable<V>> extends keyof T ? T[TokenPurposeOf<NonNullable<V>>] extends TokenPurpose<infer C> ? SchemaOutput<C> : never : never) | (undefined extends V ? undefined : never);
|
|
48
48
|
/** An input as its handler receives it: each signed token field replaced by the verified claims of its purpose. */
|
|
49
49
|
export type WithClaims<In, T> = [keyof In] extends [never] ? In : {
|
|
50
50
|
readonly [F in keyof In]: ClaimsField<In[F], T>;
|
|
51
51
|
};
|
|
52
52
|
/** `ctx.tokens` of a site that declares `signs`: a token of one of those purposes, valid for `days`. */
|
|
53
53
|
export interface TokenSigning<T extends TokenPurposes, S extends string> {
|
|
54
|
-
sign<const P extends S & keyof T & string>(purpose: P, claims:
|
|
54
|
+
sign<const P extends S & keyof T & string>(purpose: P, claims: SchemaInput<T[P]['claims']>, options: {
|
|
55
55
|
readonly days: number;
|
|
56
56
|
}): string;
|
|
57
57
|
}
|
package/types/src/from-row.d.ts
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
import type { SchemaInput, SchemaOutput } from './contract/define';
|
|
3
|
+
import { type DataObject } from './schema/data-schema';
|
|
4
|
+
/** An object schema: a zod one, or one held as data. */
|
|
5
|
+
type ObjectSchema = z.ZodObject | DataObject<z.core.$ZodShape, z.core.$ZodObjectConfig>;
|
|
2
6
|
/** `companyId` → `company_id`: the column a field is read from. */
|
|
3
7
|
export type Snake<S extends string> = S extends `${infer Head}${infer Tail}` ? `${Head extends Lowercase<Head> ? Head : `_${Lowercase<Head>}`}${Snake<Tail>}` : S;
|
|
4
8
|
/** A row value a field accepts: text for a literal string (the schema checks it), a `Date` for ISO text. */
|
|
5
9
|
type Widened<V> = V extends string ? string | Date : V;
|
|
6
10
|
/** The row `fromRow` takes for `S`: one column per declared field; any other column is allowed and dropped. */
|
|
7
|
-
export type RowInput<S extends
|
|
8
|
-
readonly [K in keyof
|
|
11
|
+
export type RowInput<S extends ObjectSchema> = {
|
|
12
|
+
readonly [K in keyof SchemaInput<S> as Snake<K & string>]: Widened<SchemaInput<S>[K]>;
|
|
9
13
|
};
|
|
10
14
|
/** The row as `schema`'s output; a row the schema refuses throws, as a handler's bug. */
|
|
11
|
-
export declare function fromRow<const S extends
|
|
15
|
+
export declare function fromRow<const S extends ObjectSchema>(schema: S, row: RowInput<S>): SchemaOutput<S>;
|
|
12
16
|
/** A list's page as a page output: each row through `fromRow`, and `next` as the list answered it. */
|
|
13
|
-
export declare function fromPage<const S extends
|
|
17
|
+
export declare function fromPage<const S extends ObjectSchema>(schema: S, page: {
|
|
14
18
|
readonly items: readonly RowInput<S>[];
|
|
15
19
|
readonly next: string | null;
|
|
16
20
|
}): {
|
|
17
|
-
items:
|
|
21
|
+
items: SchemaOutput<S>[];
|
|
18
22
|
next: string | null;
|
|
19
23
|
};
|
|
20
24
|
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type EndpointRow, type SchemaShape } from '@fabrika/auth-core';
|
|
2
|
+
import type { Schema } from '../contract/define';
|
|
3
|
+
/** `schema`, the endpoint's input, once its shape is the row's. */
|
|
4
|
+
export declare function approvedInput(row: EndpointRow, schema: Schema): Schema;
|
|
5
|
+
/**
|
|
6
|
+
* `schema`, the endpoint's JSON output, once its shape is the row's. A redirect's target, an attachment's rows and a
|
|
7
|
+
* file stand in the row in a form of their own, so their schemas are not compared.
|
|
8
|
+
*/
|
|
9
|
+
export declare function approvedOutput(row: EndpointRow, schema: Schema): Schema;
|
|
10
|
+
/** Whether `schema` reads to the canonical shape `expected`; a schema outside the subset never does. */
|
|
11
|
+
export declare function hasShape(schema: Schema, expected: SchemaShape, where: string): boolean;
|
|
@@ -10,6 +10,7 @@ import { type ContractJobs } from '../jobs/runner';
|
|
|
10
10
|
import type { ChallengeFetch, ChallengeWork } from './challenge';
|
|
11
11
|
import { type ConnectFetch } from './connect';
|
|
12
12
|
import { type SpaAssets } from './dispatch';
|
|
13
|
+
import { type HostResolver } from './egress';
|
|
13
14
|
import type { CapturedEnvironment } from './environment';
|
|
14
15
|
import { type HandlerErrorSink } from './failures';
|
|
15
16
|
import type { ContractImplementation } from './implement';
|
|
@@ -22,6 +23,12 @@ export interface BootOptions {
|
|
|
22
23
|
/** The variables `captureEnvironment` took before the application's modules loaded. */
|
|
23
24
|
readonly environment: CapturedEnvironment;
|
|
24
25
|
readonly iam: IamKeySource;
|
|
26
|
+
/**
|
|
27
|
+
* The contract artifact the build compiled, as the text of its shared encoding (`fabrika/contract.generated.ts`). Boot
|
|
28
|
+
* decodes it, checks its digest against `FABRIKA_CONTRACT_DIGEST` and reads it instead of compiling the contract;
|
|
29
|
+
* without it, boot compiles.
|
|
30
|
+
*/
|
|
31
|
+
readonly approvedContract?: string;
|
|
25
32
|
/** Serves the SPA mounts. Without it, a contract that declares one does not boot. */
|
|
26
33
|
readonly assets?: SpaAssets;
|
|
27
34
|
/** The application's Postgres connection, which the Bun adapter opens. Without it, an application on `@fabrika/db` does not boot. */
|
|
@@ -64,6 +71,11 @@ export interface BootOptions {
|
|
|
64
71
|
* with a job or a webhook does not boot.
|
|
65
72
|
*/
|
|
66
73
|
readonly workloadTokens?: WorkloadTokenSource;
|
|
74
|
+
/**
|
|
75
|
+
* Resolves a host name to its addresses, which the Bun adapter supplies (`node:dns`): a cron job's public egress then
|
|
76
|
+
* refuses a public name of a private address before each hop. A Worker exposes no resolution and passes none.
|
|
77
|
+
*/
|
|
78
|
+
readonly resolveHost?: HostResolver;
|
|
67
79
|
/** What posts a report to Operations' ingest; `fetch` by default. */
|
|
68
80
|
readonly operationsFetch?: (request: Request) => Promise<Response>;
|
|
69
81
|
/** What asks a public procedure's challenge provider to verify a token; `fetch` by default. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AppCapability as AppCapabilityType, type CapabilityAuthority, type ContainerGrant, type LeaseFence, type Ref as RefCapability, type RowGrant, type RowRef as RowRefCapability, type Within as WithinCapability } from '@fabrika/db/capability';
|
|
1
|
+
import { type AppCapability as AppCapabilityType, type CapabilityAuthority, type ContainerGrant, type LeaseFence, type Ref as RefCapability, type RelationHold, type RowGrant, type RowRef as RowRefCapability, type Within as WithinCapability, type WithinGrant } from '@fabrika/db/capability';
|
|
2
2
|
/** Why a capability or a handle was refused, as a closed catalog with the fixed text a log may print. */
|
|
3
3
|
export declare const CAPABILITY_REFUSALS: {
|
|
4
4
|
readonly not_minted: "a value the framework did not mint was used as a capability; pass the ctx.target or ctx.within of this request";
|
|
@@ -11,7 +11,11 @@ export declare const CAPABILITY_REFUSALS: {
|
|
|
11
11
|
readonly undeclared_binding: "the site named a webhook it does not declare in binds";
|
|
12
12
|
readonly undeclared_signs: "the site signed a token of a purpose it does not declare in signs, or for longer than the purpose allows";
|
|
13
13
|
readonly undeclared_egress: "the site called an origin it does not declare in egress";
|
|
14
|
+
readonly refused_egress: "the site's public egress refused the host: an IP address, a local or internal name, a non-default port, credentials in the URL, a host of this installation, or a name that resolves to a private address";
|
|
15
|
+
readonly oversized_egress: "a response to the site's public egress was larger than it reads";
|
|
16
|
+
readonly encoded_egress: "a response to the site's public egress came compressed, which it neither asks for nor decodes";
|
|
14
17
|
readonly wrong_binding: "a webhook binding was handed a capability of another kind or dimension than the webhook is bound to";
|
|
18
|
+
readonly conditional_binding: "a webhook binding was handed a Ref held through a relation, a member reveal or a secondary path, which a binding would outlive";
|
|
15
19
|
readonly missing_id: "the job named an object without an id";
|
|
16
20
|
readonly wrong_capability: "an operation was handed a capability of another dimension or action than it needs";
|
|
17
21
|
};
|
|
@@ -27,6 +31,8 @@ export declare class CapabilityRefusedError extends Error {
|
|
|
27
31
|
export declare class CapabilityLimitError extends Error {
|
|
28
32
|
readonly name = "CapabilityLimitError";
|
|
29
33
|
}
|
|
34
|
+
/** The caller's grants of `action` in `dimension`, as a `Within` of it would carry them; no values when it holds none. */
|
|
35
|
+
export type Standing = (dimension: string, action: string) => WithinGrant;
|
|
30
36
|
/**
|
|
31
37
|
* One request's lifetime, or one job attempt's. A capability minted in it is usable only while it runs, and only
|
|
32
38
|
* inside it; a job attempt's writes also need its lease (`fence`).
|
|
@@ -39,10 +45,13 @@ export declare class RequestFrame {
|
|
|
39
45
|
readonly readOnly: boolean;
|
|
40
46
|
/** The endpoint the request is served by; `ctx.connect` checks it against each import's `usedBy`. */
|
|
41
47
|
readonly endpoint: string | null;
|
|
48
|
+
/** What the request's caller holds of an action in a dimension; none for work without a caller (a job, a webhook). */
|
|
49
|
+
readonly standing: Standing | null;
|
|
42
50
|
constructor(id: string, options?: {
|
|
43
51
|
readonly fence?: LeaseFence | null;
|
|
44
52
|
readonly readOnly?: boolean;
|
|
45
53
|
readonly endpoint?: string | null;
|
|
54
|
+
readonly standing?: Standing | null;
|
|
46
55
|
});
|
|
47
56
|
get ended(): boolean;
|
|
48
57
|
end(): void;
|
|
@@ -63,7 +72,7 @@ export declare class Ref<D extends string, A extends string> implements RefCapab
|
|
|
63
72
|
readonly dimension: D;
|
|
64
73
|
readonly action: A;
|
|
65
74
|
};
|
|
66
|
-
constructor(token: typeof MINT, issuer: object, frame: RequestFrame, dimension: D, action: A, principal: string, id: string, chain: ReadonlyMap<string, string>, relations: readonly
|
|
75
|
+
constructor(token: typeof MINT, issuer: object, frame: RequestFrame, dimension: D, action: A, principal: string, id: string, chain: ReadonlyMap<string, string>, relations: readonly RelationHold[], revealing: readonly ContainerGrant[], paths: readonly ContainerGrant[]);
|
|
67
76
|
get dimension(): D;
|
|
68
77
|
get action(): A;
|
|
69
78
|
/** The object's id: the value of its dimension. */
|
|
@@ -82,7 +91,7 @@ export declare class Within<D extends string, A extends string> implements Withi
|
|
|
82
91
|
readonly dimension: D;
|
|
83
92
|
readonly action: A;
|
|
84
93
|
};
|
|
85
|
-
constructor(token: typeof MINT, issuer: object, frame: RequestFrame, dimension: D, action: A, principal: string, values: readonly string[] | 'all', containers: readonly ContainerGrant[], contained: readonly ContainerGrant[], relations: readonly
|
|
94
|
+
constructor(token: typeof MINT, issuer: object, frame: RequestFrame, dimension: D, action: A, principal: string, values: readonly string[] | 'all', containers: readonly ContainerGrant[], contained: readonly ContainerGrant[], relations: readonly RelationHold[], revealing: readonly ContainerGrant[]);
|
|
86
95
|
get dimension(): D;
|
|
87
96
|
get action(): A;
|
|
88
97
|
/** The values of this dimension itself. */
|
|
@@ -124,8 +133,8 @@ export declare class RowRef<T extends string, A extends string> implements RowRe
|
|
|
124
133
|
}
|
|
125
134
|
/** Makes the capabilities one authority accepts; a runtime's is held by the `boot` call that made it alone. */
|
|
126
135
|
export interface CapabilityMint {
|
|
127
|
-
ref<D extends string, A extends string>(frame: RequestFrame, dimension: D, action: A, principal: string, id: string, chain: ReadonlyMap<string, string>, relations?: readonly
|
|
128
|
-
within<D extends string, A extends string>(frame: RequestFrame, dimension: D, action: A, principal: string, values: readonly string[] | 'all', containers?: readonly ContainerGrant[], contained?: readonly ContainerGrant[], relations?: readonly
|
|
136
|
+
ref<D extends string, A extends string>(frame: RequestFrame, dimension: D, action: A, principal: string, id: string, chain: ReadonlyMap<string, string>, relations?: readonly RelationHold[], revealing?: readonly ContainerGrant[], paths?: readonly ContainerGrant[]): Ref<D, A>;
|
|
137
|
+
within<D extends string, A extends string>(frame: RequestFrame, dimension: D, action: A, principal: string, values: readonly string[] | 'all', containers?: readonly ContainerGrant[], contained?: readonly ContainerGrant[], relations?: readonly RelationHold[], revealing?: readonly ContainerGrant[]): Within<D, A>;
|
|
129
138
|
app<A extends string>(frame: RequestFrame, action: A, principal: string): AppCapability<A>;
|
|
130
139
|
}
|
|
131
140
|
/** A mint and the one authority that accepts what it mints. */
|
|
@@ -12,6 +12,7 @@ import type { BrowserConfig } from './browser-config';
|
|
|
12
12
|
import { type CapabilityMint } from './capability';
|
|
13
13
|
import type { ChallengeIssuer } from './challenge';
|
|
14
14
|
import { type ImportWire } from './connect';
|
|
15
|
+
import { type SiteEgress } from './egress';
|
|
15
16
|
import type { FailureReports } from './failures';
|
|
16
17
|
import { type HeaderPolicy } from './headers';
|
|
17
18
|
import type { ContractDatabase } from './implement';
|
|
@@ -97,7 +98,7 @@ export type ServedEndpoint = {
|
|
|
97
98
|
/** A staged-kit site, which gets `ctx.db`; a handler `implement` bound has none. */
|
|
98
99
|
readonly site?: ServedSite;
|
|
99
100
|
/** The origins a staged-kit site's `fetch` reaches while its handler runs; absent for a handler `implement` bound. */
|
|
100
|
-
readonly egress?:
|
|
101
|
+
readonly egress?: SiteEgress;
|
|
101
102
|
/** Its buckets and time limit; without them (a generated endpoint) no bucket and the request budget. */
|
|
102
103
|
readonly admission?: ProcedureAdmission;
|
|
103
104
|
/** A POST's `query`, parsed from the URL beside the body: its schema and its shape. */
|
|
@@ -193,6 +194,11 @@ export interface RevealedNode {
|
|
|
193
194
|
readonly dimension: string;
|
|
194
195
|
readonly actions: readonly string[];
|
|
195
196
|
}
|
|
197
|
+
/** A secondary path of a dimension's table: the dimension it reaches, and the actions a Ref holds through it. */
|
|
198
|
+
export interface HeldPath {
|
|
199
|
+
readonly dimension: string;
|
|
200
|
+
readonly actions: readonly string[];
|
|
201
|
+
}
|
|
196
202
|
export interface RuntimeParts {
|
|
197
203
|
readonly table: CompiledEndpointTable;
|
|
198
204
|
readonly endpoints: ReadonlyMap<string, ServedEndpoint>;
|
|
@@ -215,6 +221,8 @@ export interface RuntimeParts {
|
|
|
215
221
|
readonly reveals: ReadonlyMap<string, readonly RevealedNode[]>;
|
|
216
222
|
/** Each dimension's member reveals: a grant of one of their actions at its node also reads under the ancestor they reveal. */
|
|
217
223
|
readonly memberReveals: ReadonlyMap<string, readonly RevealedNode[]>;
|
|
224
|
+
/** Each dimension's secondary paths that hold actions for a Ref: a grant of one at the node a path names reaches the object. */
|
|
225
|
+
readonly paths: ReadonlyMap<string, readonly HeldPath[]>;
|
|
218
226
|
readonly assets: SpaAssets | null;
|
|
219
227
|
/** IAM's membership operations; `boot` refuses a contract that needs them when the adapter supplies none. */
|
|
220
228
|
readonly membership: IamMembership | null;
|