@fabrika/app 0.9.0-dev.14 → 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 +2 -2
- package/skill/references/app-setup.md +10 -9
- package/skill/references/endpoint.md +8 -1
- package/src/build-contract-child.ts +16 -0
- package/src/build.ts +48 -2
- package/src/client/contract.ts +6 -4
- package/src/cloudflare/application.ts +3 -0
- package/src/contract/artifact-schema.ts +355 -301
- package/src/contract/attachment.ts +4 -3
- package/src/contract/compile.ts +3 -2
- package/src/contract/context.ts +2 -3
- package/src/contract/define.ts +17 -5
- package/src/contract/group.ts +8 -7
- package/src/contract/index.ts +1 -1
- package/src/contract/kit.ts +2 -2
- package/src/contract/problems.ts +4 -0
- package/src/contract/schema-shape.ts +14 -2
- package/src/contract/token.ts +4 -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 +90 -12
- package/src/implement/dispatch.ts +14 -10
- package/src/implement/egress.ts +7 -6
- package/src/implement/faults.ts +1 -0
- package/src/implement/project.ts +3 -1
- package/src/implement/tokens.ts +3 -2
- package/src/implement/types.ts +18 -6
- 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/testing/kit.ts +3 -3
- 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 +14 -5
- package/types/src/contract/group.d.ts +5 -6
- package/types/src/contract/index.d.ts +1 -1
- package/types/src/contract/kit.d.ts +2 -3
- 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 +6 -0
- package/types/src/implement/faults.d.ts +1 -0
- package/types/src/implement/project.d.ts +2 -1
- package/types/src/implement/types.d.ts +4 -5
- 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/testing/kit.d.ts +2 -3
|
@@ -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;
|
|
@@ -183,7 +192,7 @@ export interface PublicAccess {
|
|
|
183
192
|
readonly public: true;
|
|
184
193
|
}
|
|
185
194
|
/** Without an `input`, TS infers `I` as its whole constraint, not the `null` default; both mean "no input". */
|
|
186
|
-
export type InputOf<I> = [I] extends [InputSchema] ?
|
|
195
|
+
export type InputOf<I> = [I] extends [InputSchema] ? SchemaOutput<I> : Record<never, never>;
|
|
187
196
|
/** Input fields of string type: the only fields a scope value can be read from. */
|
|
188
197
|
export type StringField<In> = {
|
|
189
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> = {
|
|
@@ -157,7 +156,7 @@ type LastOf<U> = (U extends unknown ? (member: () => U) => void : never) extends
|
|
|
157
156
|
/** `'a' | 'b'` → `'a, b'`, for a message. */
|
|
158
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}`>;
|
|
159
158
|
/** The fields, at any depth, that a handler `F` returns and the output `O` does not declare. */
|
|
160
|
-
export type UndeclaredFields<F, O extends Schema> = ExtraKeys<Returned<F>,
|
|
159
|
+
export type UndeclaredFields<F, O extends Schema> = ExtraKeys<Returned<F>, SchemaInput<O>>;
|
|
161
160
|
/** An object with a camelCase field, which a database row names in snake_case. */
|
|
162
161
|
type HasCamel<V> = {
|
|
163
162
|
[K in keyof V]: K extends string ? (Snake<K> extends K ? never : K) : never;
|
|
@@ -176,7 +175,7 @@ type RowShaped<V> = V extends readonly (infer Item)[] ? readonly RowShaped<Item>
|
|
|
176
175
|
* `ExactReturn` refuses with the fix, as it refuses anything but rows from an attachment's handler. Any other mistake
|
|
177
176
|
* keeps the compiler's own message about the output.
|
|
178
177
|
*/
|
|
179
|
-
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>;
|
|
180
179
|
/** A kit endpoint's handler, returning `R`; `X` adds what its HTTP shape reads beside the input (`query`). */
|
|
181
180
|
export type KitHandler<In, Ctx, R, X = unknown> = (args: {
|
|
182
181
|
readonly input: In;
|
|
@@ -187,7 +186,7 @@ export type KitHandler<In, Ctx, R, X = unknown> = (args: {
|
|
|
187
186
|
* as the claims of its purpose.
|
|
188
187
|
*/
|
|
189
188
|
export type QueryArgs<Q, T = Record<never, never>> = [Q] extends [never] ? unknown : Q extends InputSchema ? {
|
|
190
|
-
readonly query: WithClaims<
|
|
189
|
+
readonly query: WithClaims<SchemaOutput<Q>, T>;
|
|
191
190
|
} : unknown;
|
|
192
191
|
/**
|
|
193
192
|
* The wire of a procedure: `POST` with a JSON body by default; a query may be `GET`, its input then flat scalar URL
|
|
@@ -208,7 +207,7 @@ export interface HttpOption<Q> {
|
|
|
208
207
|
* returns a database row where the output is camelCase, anything but rows for an attachment, or, at any depth, a
|
|
209
208
|
* field the output does not declare. A field whose type is an error elsewhere in the handler is not reported again here.
|
|
210
209
|
*/
|
|
211
|
-
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`>;
|
|
212
211
|
/** A declared, handled endpoint: what a group holds. Its type keeps the declaration and drops the handler's. */
|
|
213
212
|
export interface Endpoint<T extends ProcedureType, I extends InputSchema | null, O extends Schema, Acc, D> extends Procedure<T, I, O, Acc> {
|
|
214
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,9 +1,8 @@
|
|
|
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';
|
|
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';
|
|
7
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';
|
|
@@ -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;
|
|
@@ -23,6 +23,12 @@ export interface BootOptions {
|
|
|
23
23
|
/** The variables `captureEnvironment` took before the application's modules loaded. */
|
|
24
24
|
readonly environment: CapturedEnvironment;
|
|
25
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;
|
|
26
32
|
/** Serves the SPA mounts. Without it, a contract that declares one does not boot. */
|
|
27
33
|
readonly assets?: SpaAssets;
|
|
28
34
|
/** The application's Postgres connection, which the Bun adapter opens. Without it, an application on `@fabrika/db` does not boot. */
|
|
@@ -31,6 +31,7 @@ export declare const SERVER_FAULTS: {
|
|
|
31
31
|
readonly attachment_cell: "a cell of the attachment is longer than one cell may hold";
|
|
32
32
|
readonly attachment_size: "the encoded attachment is larger than it declares (maxBytes); no body was sent";
|
|
33
33
|
readonly redirect_refused: "the handler redirected to a target that is neither its own origin's path, an origin its redirect() lists, nor a URL a verified token of the request carries";
|
|
34
|
+
readonly schema_unapproved: "a schema the application evaluated has another shape than its approved contract holds for the endpoint";
|
|
34
35
|
readonly token_claims_refused: "the claims a site signed are not what the token purpose's claims schema admits";
|
|
35
36
|
readonly token_keys_missing: "a site signed a token, and the environment holds no token key";
|
|
36
37
|
readonly url_unbuildable: "ctx.url named no procedure of the contract, passed a parameter its HTTP shape does not read, or the environment has no public origin";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
import { type DataSchema } from '../schema/data-schema';
|
|
2
3
|
/** No branch of a union accepts the value, whatever it is reduced to. */
|
|
3
4
|
export declare class ProjectionRefusedError extends Error {
|
|
4
5
|
readonly name = "ProjectionRefusedError";
|
|
@@ -8,4 +9,4 @@ export declare class ProjectionRefusedError extends Error {
|
|
|
8
9
|
* in declaration order, whose schema accepts the value reduced to that branch. Anything else is left for
|
|
9
10
|
* validation.
|
|
10
11
|
*/
|
|
11
|
-
export declare function project(
|
|
12
|
+
export declare function project(declared: z.core.$ZodType | DataSchema, value: unknown): unknown;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { z } from 'zod/v4';
|
|
2
1
|
import type { ConnectSnapshot } from '../contract/connect';
|
|
3
2
|
import type { SurfaceSection } from '../contract/declaration';
|
|
4
|
-
import type { Export, InputOf, InputSchema, LinkMount, MemberAccess, Procedure, RoleOf, RpcMount, Schema, WebhookMount } from '../contract/define';
|
|
3
|
+
import type { Export, InputOf, InputSchema, LinkMount, MemberAccess, Procedure, RoleOf, RpcMount, Schema, SchemaInput, SchemaOutput, WebhookMount } from '../contract/define';
|
|
5
4
|
import type { JobHandlersOf } from '../jobs/types';
|
|
6
5
|
import type { AppCapability, Ref, Within } from './capability';
|
|
7
6
|
import type { ConnectResult } from './connect';
|
|
@@ -154,7 +153,7 @@ type Without<In, F> = {
|
|
|
154
153
|
export type Handler<In, Ctx, O extends Schema> = (args: {
|
|
155
154
|
readonly input: In;
|
|
156
155
|
readonly ctx: Ctx;
|
|
157
|
-
}) =>
|
|
156
|
+
}) => SchemaInput<O> | Promise<SchemaInput<O>>;
|
|
158
157
|
type ImportsOf<C> = SurfaceOf<C> extends {
|
|
159
158
|
readonly imports: infer I;
|
|
160
159
|
} ? I : Record<never, never>;
|
|
@@ -171,7 +170,7 @@ type ImportedProcedures<C, K> = K extends keyof ImportsOf<C> ? ImportsOf<C>[K] e
|
|
|
171
170
|
readonly procedures: readonly (infer P extends string)[];
|
|
172
171
|
} ? P : never : never;
|
|
173
172
|
/** A connector call never throws for the owner's answer: it resolves to a typed outcome. */
|
|
174
|
-
export type ConnectCall<I, O extends Schema> = [I] extends [InputSchema] ? (input:
|
|
173
|
+
export type ConnectCall<I, O extends Schema> = [I] extends [InputSchema] ? (input: SchemaInput<I>) => Promise<ConnectResult<SchemaOutput<O>>> : (input?: Record<never, never>) => Promise<ConnectResult<SchemaOutput<O>>>;
|
|
175
174
|
type ConnectorOf<S, P extends string> = {
|
|
176
175
|
readonly [Path in P]: S extends {
|
|
177
176
|
readonly procedures: {
|
|
@@ -216,7 +215,7 @@ type LinkHandlers<D extends string, T> = {
|
|
|
216
215
|
* stable key. It runs at least once per delivery: a failed run is run again on GitHub's redelivery.
|
|
217
216
|
*/
|
|
218
217
|
export type WebhookHandler<B extends string, Acts extends string, I> = (args: {
|
|
219
|
-
readonly input:
|
|
218
|
+
readonly input: SchemaOutput<I>;
|
|
220
219
|
readonly ctx: RequestContext<WebhookPrincipal> & {
|
|
221
220
|
readonly refs: {
|
|
222
221
|
readonly [A in Acts]: Ref<B, A>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { z } from 'zod/v4';
|
|
2
1
|
import type { AttachmentProcedure, DownloadedFile, DownloadInput, FileProcedure } from '../client/contract';
|
|
3
|
-
import type { Schema } from '../contract/define';
|
|
2
|
+
import type { Schema, SchemaOutput } from '../contract/define';
|
|
4
3
|
import { type FabrikaError } from './errors';
|
|
5
4
|
import type { InputArgument, InvalidateTarget, PagedProcedure, PageInput, TypedProcedure } from './types';
|
|
6
5
|
/** Pass as the input to wait: the query sends nothing until its input is known. */
|
|
@@ -38,8 +37,8 @@ export interface QueryOptions {
|
|
|
38
37
|
* The answer of a query, cached by procedure and input: every view of one call shares one request, and a mutation
|
|
39
38
|
* that invalidates it refetches it. Pass `skip` as the input to wait for a value the input needs.
|
|
40
39
|
*/
|
|
41
|
-
export declare function useQuery<O extends Schema>(procedure: TypedProcedure<Record<never, never> | undefined, O>, input?: typeof skip): QueryState<
|
|
42
|
-
export declare function useQuery<I, O extends Schema>(procedure: TypedProcedure<I, O>, input: I | typeof skip, options?: QueryOptions): QueryState<
|
|
40
|
+
export declare function useQuery<O extends Schema>(procedure: TypedProcedure<Record<never, never> | undefined, O>, input?: typeof skip): QueryState<SchemaOutput<O>>;
|
|
41
|
+
export declare function useQuery<I, O extends Schema>(procedure: TypedProcedure<I, O>, input: I | typeof skip, options?: QueryOptions): QueryState<SchemaOutput<O>>;
|
|
43
42
|
export interface InfiniteQueryOptions {
|
|
44
43
|
/** How many pages the first load reads: `1` (the default) or every page (`'all'`, for a picker's options). */
|
|
45
44
|
readonly pages?: number | 'all';
|
|
@@ -100,7 +99,7 @@ export interface MutationOptions<T> {
|
|
|
100
99
|
* A mutation of the client: `mutate(input)` checks the input with the procedure's schema (a refused input is a
|
|
101
100
|
* `validation` error and sends nothing), calls it, and after a success refetches what `invalidates` names.
|
|
102
101
|
*/
|
|
103
|
-
export declare function useMutation<I, O extends Schema>(procedure: TypedProcedure<I, O>, options?: MutationOptions<
|
|
102
|
+
export declare function useMutation<I, O extends Schema>(procedure: TypedProcedure<I, O>, options?: MutationOptions<SchemaOutput<O>>): MutationState<InputArgument<I>, SchemaOutput<O>>;
|
|
104
103
|
/**
|
|
105
104
|
* A call that is no client procedure yet (a file upload until the client covers file collections), with the same
|
|
106
105
|
* state and error union as a mutation. It refetches only what `invalidates` names.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { z } from 'zod/v4';
|
|
2
|
-
import type { Schema } from '../contract/define';
|
|
2
|
+
import type { Schema, SchemaOutput } from '../contract/define';
|
|
3
3
|
/** A query or mutation of a client that `createClient` built. */
|
|
4
4
|
export type ClientProcedure = ((input: never) => Promise<unknown>) & {
|
|
5
5
|
readonly output: Schema;
|
|
@@ -19,7 +19,7 @@ export type TypedProcedure<I, O extends Schema> = ((input: I) => Promise<unknown
|
|
|
19
19
|
/** An input argument that may be left out when the procedure takes no input. */
|
|
20
20
|
export type InputArgument<I> = undefined extends I ? I | void : I;
|
|
21
21
|
/** The answer, as the procedure's output schema parses it. */
|
|
22
|
-
export type ProcedureResult<F extends ClientProcedure> =
|
|
22
|
+
export type ProcedureResult<F extends ClientProcedure> = SchemaOutput<F['output']>;
|
|
23
23
|
/** The answer of a cursor list: `{ items, next }`. */
|
|
24
24
|
export interface PageAnswer<Item> {
|
|
25
25
|
readonly items: readonly Item[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { z as zod } from 'zod/v4';
|
|
2
|
+
import { type AnySchema, DataEnum, DataObject, DataSchema, type DataShapeInput, type Message, type UuidOptions, type ZodList, type ZodOf, type ZodShape } from './data-schema';
|
|
3
|
+
type Primitive = string | number | boolean | null;
|
|
4
|
+
export type DatetimeOptions = string | {
|
|
5
|
+
readonly message?: string;
|
|
6
|
+
readonly error?: string;
|
|
7
|
+
readonly offset?: boolean;
|
|
8
|
+
readonly local?: boolean;
|
|
9
|
+
readonly precision?: number | null;
|
|
10
|
+
};
|
|
11
|
+
export type TimeOptions = string | {
|
|
12
|
+
readonly message?: string;
|
|
13
|
+
readonly error?: string;
|
|
14
|
+
readonly precision?: number | null;
|
|
15
|
+
};
|
|
16
|
+
/** What a schema admits once parsed, as `zod`'s `z.output`. */
|
|
17
|
+
export type output<S> = zod.output<ZodOf<S>>;
|
|
18
|
+
/** What a schema takes before parsing, as `zod`'s `z.input`. */
|
|
19
|
+
export type input<S> = zod.input<ZodOf<S>>;
|
|
20
|
+
export type { output as infer };
|
|
21
|
+
export declare function string(params?: Message): DataSchema<zod.ZodString>;
|
|
22
|
+
export declare function number(params?: Message): DataSchema<zod.ZodNumber>;
|
|
23
|
+
export declare function int(params?: Message): DataSchema<zod.ZodInt>;
|
|
24
|
+
export declare function boolean(params?: Message): DataSchema<zod.ZodBoolean>;
|
|
25
|
+
declare function _null(params?: Message): DataSchema<zod.ZodNull>;
|
|
26
|
+
export declare function uuid(params?: UuidOptions): DataSchema<zod.ZodUUID>;
|
|
27
|
+
export declare function email(params?: Message): DataSchema<zod.ZodEmail>;
|
|
28
|
+
export declare function url(params?: Message): DataSchema<zod.ZodURL>;
|
|
29
|
+
export declare function literal<const L extends Primitive | readonly Primitive[]>(value: L, params?: Message): DataSchema<zod.ZodLiteral<L extends readonly Primitive[] ? L[number] : L>>;
|
|
30
|
+
declare function _enum<const E extends readonly string[] | zod.core.util.EnumLike>(values: E, params?: Message): DataEnum<E extends readonly string[] ? zod.core.util.ToEnum<E[number]> : E>;
|
|
31
|
+
export declare function strictObject<S extends DataShapeInput>(shape: S, params?: Message): DataObject<ZodShape<S>, zod.core.$strict>;
|
|
32
|
+
export declare function array<E extends AnySchema>(element: E, params?: Message): DataSchema<zod.ZodArray<ZodOf<E>>>;
|
|
33
|
+
export declare function tuple<const I extends readonly AnySchema[], R extends AnySchema = never>(items: I, rest?: R | Message, params?: Message): DataSchema<zod.ZodTuple<Extract<ZodList<I>, zod.core.util.TupleItems>, [R] extends [never] ? null : ZodOf<R>>>;
|
|
34
|
+
export declare function union<const O extends readonly AnySchema[]>(options: O, params?: Message): DataSchema<zod.ZodUnion<Extract<ZodList<O>, readonly zod.core.SomeType[]>>>;
|
|
35
|
+
export declare function discriminatedUnion<const O extends readonly [AnySchema, ...AnySchema[]]>(discriminator: string, options: O, params?: Message): DataSchema<zod.ZodDiscriminatedUnion<Extract<ZodList<O>, readonly [zod.core.$ZodTypeDiscriminable, ...zod.core.$ZodTypeDiscriminable[]]>>>;
|
|
36
|
+
export declare function record<K extends AnySchema, V extends AnySchema>(key: K, value: V, params?: Message): DataSchema<zod.ZodRecord<Extract<ZodOf<K>, zod.core.$ZodRecordKey>, ZodOf<V>>>;
|
|
37
|
+
export declare function optional<S extends AnySchema>(inner: S): DataSchema<zod.ZodOptional<ZodOf<S>>>;
|
|
38
|
+
export declare function nullable<S extends AnySchema>(inner: S): DataSchema<zod.ZodNullable<ZodOf<S>>>;
|
|
39
|
+
export declare const iso: Readonly<{
|
|
40
|
+
date: (params?: Message) => DataSchema<zod.ZodISODate>;
|
|
41
|
+
datetime: (params?: DatetimeOptions) => DataSchema<zod.ZodISODateTime>;
|
|
42
|
+
time: (params?: TimeOptions) => DataSchema<zod.ZodISOTime>;
|
|
43
|
+
duration: (params?: Message) => DataSchema<zod.ZodISODuration>;
|
|
44
|
+
}>;
|
|
45
|
+
export { _enum as enum, _null as null };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
/** A schema a contract may hold: one held as data, or a zod schema (a framework schema such as `signedToken()`). */
|
|
3
|
+
export type AnySchema = DataSchema<z.ZodType> | z.ZodType;
|
|
4
|
+
/** The zod type a schema denotes: its own type for a zod schema. */
|
|
5
|
+
export type ZodOf<S> = S extends DataSchema<infer T extends z.core.$ZodType> ? T : S extends z.core.$ZodType ? S : never;
|
|
6
|
+
/** The fields an object is declared with. */
|
|
7
|
+
export type DataShapeInput = {
|
|
8
|
+
readonly [key: string]: AnySchema;
|
|
9
|
+
};
|
|
10
|
+
/** The zod shape of `S`, as `z.strictObject` would hold it. */
|
|
11
|
+
export type ZodShape<S extends DataShapeInput> = {
|
|
12
|
+
[K in keyof S]: ZodOf<S[K]>;
|
|
13
|
+
};
|
|
14
|
+
/** The zod types of a list of schemas, as `z.union` or `z.tuple` would hold them. */
|
|
15
|
+
export type ZodList<O extends readonly AnySchema[]> = {
|
|
16
|
+
[I in keyof O]: ZodOf<O[I]>;
|
|
17
|
+
};
|
|
18
|
+
/** An error message, or the options object that carries one. */
|
|
19
|
+
export type Message = string | {
|
|
20
|
+
readonly message?: string;
|
|
21
|
+
readonly error?: string;
|
|
22
|
+
};
|
|
23
|
+
/** What `min`, `max` and `length` bound: a string's length, an array's items, a number. */
|
|
24
|
+
type Sized = (z.ZodString | z.ZodStringFormat | z.ZodArray) & z.core.$ZodType;
|
|
25
|
+
type Bounded = (Sized | z.ZodNumber) & z.core.$ZodType;
|
|
26
|
+
type Text = (z.ZodString | z.ZodStringFormat) & z.core.$ZodType;
|
|
27
|
+
export declare class DataSchema<T extends z.core.$ZodType = z.core.$ZodType> {
|
|
28
|
+
#private;
|
|
29
|
+
/** The zod type this schema denotes; declared only, never set. */
|
|
30
|
+
readonly '~type'?: T;
|
|
31
|
+
/** The factory (`z.<name>`, `z.iso.<name>` when `iso`) or the method that made this schema. */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly iso: boolean;
|
|
34
|
+
/** The schema a method was called on; `null` for a factory. */
|
|
35
|
+
readonly receiver: DataSchema | null;
|
|
36
|
+
readonly args: readonly unknown[];
|
|
37
|
+
constructor(name: string, iso: boolean, receiver: DataSchema | null, args: readonly unknown[]);
|
|
38
|
+
/** A zod schema given where a schema stands, held as one. */
|
|
39
|
+
static wrap<S extends z.core.$ZodType>(schema: S): DataSchema<S>;
|
|
40
|
+
/** Whether this node only wraps a zod schema. */
|
|
41
|
+
get wrapped(): z.ZodType | null;
|
|
42
|
+
protected derive<U extends z.core.$ZodType>(name: string, args: readonly unknown[]): DataSchema<U>;
|
|
43
|
+
min<S extends Bounded>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
44
|
+
max<S extends Bounded>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
45
|
+
length<S extends Sized>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
46
|
+
nonempty<S extends Sized>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
47
|
+
email(this: DataSchema<z.ZodString>, params?: Message): DataSchema<z.ZodString>;
|
|
48
|
+
url(this: DataSchema<z.ZodString>, params?: Message): DataSchema<z.ZodString>;
|
|
49
|
+
uuid(this: DataSchema<z.ZodString>, params?: UuidOptions): DataSchema<z.ZodString>;
|
|
50
|
+
startsWith<S extends Text>(this: DataSchema<S>, prefix: string, params?: Message): DataSchema<S>;
|
|
51
|
+
endsWith<S extends Text>(this: DataSchema<S>, suffix: string, params?: Message): DataSchema<S>;
|
|
52
|
+
includes<S extends Text>(this: DataSchema<S>, part: string, params?: IncludesOptions): DataSchema<S>;
|
|
53
|
+
regex<S extends Text>(this: DataSchema<S>, pattern: RegExp, params?: Message): DataSchema<S>;
|
|
54
|
+
int<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
55
|
+
positive<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
56
|
+
negative<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
57
|
+
nonnegative<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
58
|
+
nonpositive<S extends z.ZodNumber>(this: DataSchema<S>, params?: Message): DataSchema<S>;
|
|
59
|
+
gt<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
60
|
+
gte<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
61
|
+
lt<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
62
|
+
lte<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
63
|
+
multipleOf<S extends z.ZodNumber>(this: DataSchema<S>, value: number, params?: Message): DataSchema<S>;
|
|
64
|
+
optional(): DataSchema<z.ZodOptional<T>>;
|
|
65
|
+
nullable(): DataSchema<z.ZodNullable<T>>;
|
|
66
|
+
nullish(): DataSchema<z.ZodOptional<z.ZodNullable<T>>>;
|
|
67
|
+
array(): DataSchema<z.ZodArray<T>>;
|
|
68
|
+
default(value: z.core.util.NoUndefined<z.output<T>>): DataSchema<z.ZodDefault<T>>;
|
|
69
|
+
describe(description: string): DataSchema<T>;
|
|
70
|
+
or<U extends AnySchema>(option: U): DataSchema<z.ZodUnion<[T, ZodOf<U>]>>;
|
|
71
|
+
/** What zod's `parse` returns for `value`, from the schema this one denotes. */
|
|
72
|
+
parse(value: unknown): z.output<T>;
|
|
73
|
+
safeParse(value: unknown): z.ZodSafeParseResult<z.output<T>>;
|
|
74
|
+
get '~standard'(): T['~standard'];
|
|
75
|
+
}
|
|
76
|
+
/** An object schema: what `z.strictObject` and the methods that derive objects make. */
|
|
77
|
+
export declare class DataObject<Shape extends z.core.$ZodShape, Config extends z.core.$ZodObjectConfig> extends DataSchema<z.ZodObject<Shape, Config>> {
|
|
78
|
+
/** The zod fields, as zod's `.shape` holds them. */
|
|
79
|
+
get shape(): Shape;
|
|
80
|
+
extend<U extends DataShapeInput>(shape: U): DataObject<z.core.util.Extend<Shape, ZodShape<U>>, Config>;
|
|
81
|
+
pick<M extends z.core.util.Mask<keyof Shape>>(mask: M): DataObject<z.core.util.Flatten<Pick<Shape, Extract<keyof Shape, keyof M>>>, Config>;
|
|
82
|
+
omit<M extends z.core.util.Mask<keyof Shape>>(mask: M): DataObject<z.core.util.Flatten<Omit<Shape, Extract<keyof Shape, keyof M>>>, Config>;
|
|
83
|
+
partial<M extends z.core.util.Mask<keyof Shape> = {
|
|
84
|
+
[K in keyof Shape]: true;
|
|
85
|
+
}>(mask?: M): DataObject<Partialized<Shape, M>, Config>;
|
|
86
|
+
describe(description: string): DataObject<Shape, Config>;
|
|
87
|
+
}
|
|
88
|
+
/** `Shape` with the fields `M` names optional, as zod's `.partial(mask)` makes it. */
|
|
89
|
+
type Partialized<Shape extends z.core.$ZodShape, M> = {
|
|
90
|
+
[K in keyof Shape]: K extends keyof M ? z.ZodOptional<Shape[K]> : Shape[K];
|
|
91
|
+
};
|
|
92
|
+
/** An enum schema: what `z.enum` and the methods that narrow an enum make. */
|
|
93
|
+
export declare class DataEnum<E extends z.core.util.EnumLike> extends DataSchema<z.ZodEnum<E>> {
|
|
94
|
+
get options(): z.ZodEnum<E>['options'];
|
|
95
|
+
get enum(): E;
|
|
96
|
+
exclude<const U extends readonly (keyof E)[]>(keys: U, params?: Message): DataEnum<z.core.util.Flatten<Omit<E, U[number]>>>;
|
|
97
|
+
extract<const U extends readonly (keyof E)[]>(keys: U, params?: Message): DataEnum<z.core.util.Flatten<Pick<E, U[number]>>>;
|
|
98
|
+
describe(description: string): DataEnum<E>;
|
|
99
|
+
}
|
|
100
|
+
export type UuidOptions = string | {
|
|
101
|
+
readonly message?: string;
|
|
102
|
+
readonly error?: string;
|
|
103
|
+
readonly version?: 'v1' | 'v2' | 'v3' | 'v4' | 'v5' | 'v6' | 'v7' | 'v8';
|
|
104
|
+
};
|
|
105
|
+
export type IncludesOptions = {
|
|
106
|
+
readonly message?: string;
|
|
107
|
+
readonly error?: string;
|
|
108
|
+
readonly position?: number;
|
|
109
|
+
};
|
|
110
|
+
export declare function isDataSchema(value: unknown): value is DataSchema;
|
|
111
|
+
/**
|
|
112
|
+
* How many built schemas stay cached: each holds the zod of one schema something validated with, and an endpoint uses
|
|
113
|
+
* two. Sized so a runtime that serves every endpoint of a large contract stays far below a Worker's 128 MB.
|
|
114
|
+
*/
|
|
115
|
+
export declare const BUILT_SCHEMAS = 64;
|
|
116
|
+
/**
|
|
117
|
+
* The zod schema `schema` denotes: a zod schema itself, or one held as data built. A cached build is reused and becomes
|
|
118
|
+
* the most recent; a schema built anew is cached, and the least recently used beyond `BUILT_SCHEMAS` is dropped. A step
|
|
119
|
+
* outside the subset throws a `SchemaRefusal`.
|
|
120
|
+
*/
|
|
121
|
+
export declare function zodSchemaOf(schema: z.core.$ZodType | DataSchema): z.core.$ZodType;
|
|
122
|
+
/** `zodSchemaOf` with the zod type the schema denotes. */
|
|
123
|
+
export declare function zodOf<S extends z.core.$ZodType | DataSchema>(schema: S): ZodOf<S>;
|
|
124
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * as z from './builder';
|
|
2
|
+
export { type AnySchema, BUILT_SCHEMAS, DataEnum, DataObject, DataSchema, type DataShapeInput, isDataSchema, type Message, type ZodOf, zodOf, zodSchemaOf, } from './data-schema';
|
|
3
|
+
export { type ReplayArg, type ReplayStep, replayStep, SCHEMA_SUBSET, SchemaRefusal, Unreadable } from './replay';
|