pullfrog 0.1.30 → 0.1.32
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/README.md +17 -1
- package/dist/agents/claudePretoolGate.d.ts +5 -1
- package/dist/agents/opencodePlugin.d.ts +2 -2
- package/dist/agents/postRun.d.ts +8 -31
- package/dist/agents/shared.d.ts +6 -0
- package/dist/agents/subagentToolGates.d.ts +22 -40
- package/dist/cli.mjs +63822 -59863
- package/dist/external.d.ts +45 -2
- package/dist/index.js +62340 -58381
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal.js +98 -26
- package/dist/mcp/checkSuite.d.ts +3 -1
- package/dist/mcp/checkout.d.ts +4 -2
- package/dist/mcp/comment.d.ts +12 -4
- package/dist/mcp/commitInfo.d.ts +3 -1
- package/dist/mcp/dependencies.d.ts +6 -2
- package/dist/mcp/git.d.ts +26 -7
- package/dist/mcp/issue.d.ts +26 -1
- package/dist/mcp/issueComments.d.ts +3 -1
- package/dist/mcp/issueEvents.d.ts +3 -1
- package/dist/mcp/issueInfo.d.ts +3 -1
- package/dist/mcp/labels.d.ts +16 -1
- package/dist/mcp/output.d.ts +6 -2
- package/dist/mcp/pr.d.ts +19 -2
- package/dist/mcp/prInfo.d.ts +3 -1
- package/dist/mcp/resolveRepoCtx.d.ts +34 -0
- package/dist/mcp/review.d.ts +50 -3
- package/dist/mcp/reviewComments.d.ts +9 -3
- package/dist/mcp/selectMode.d.ts +3 -1
- package/dist/mcp/server.d.ts +6 -1
- package/dist/mcp/shared.d.ts +18 -1
- package/dist/mcp/shell.d.ts +6 -2
- package/dist/mcp/upload.d.ts +3 -1
- package/dist/mcp/xrepo.d.ts +15 -0
- package/dist/models.d.ts +58 -5
- package/dist/toolState.d.ts +73 -16
- package/dist/utils/agent.d.ts +3 -1
- package/dist/utils/apiKeys.d.ts +4 -0
- package/dist/utils/buildPullfrogFooter.d.ts +34 -0
- package/dist/utils/errorReport.d.ts +2 -2
- package/dist/utils/github.d.ts +1 -1
- package/dist/utils/instructions.d.ts +8 -0
- package/dist/utils/isTransientNetworkError.d.ts +19 -0
- package/dist/utils/learnings.d.ts +14 -0
- package/dist/utils/modelAccess.d.ts +64 -0
- package/dist/utils/payload.d.ts +26 -1
- package/dist/utils/runContext.d.ts +3 -0
- package/dist/utils/runContextData.d.ts +10 -0
- package/dist/utils/setup.d.ts +18 -3
- package/dist/utils/statusChecks.d.ts +25 -0
- package/dist/utils/token.d.ts +10 -2
- package/dist/yes/index.d.ts +58 -0
- package/dist/yes/standard-schema.d.ts +117 -0
- package/dist/yes.js +1281 -0
- package/package.json +19 -10
- package/dist/utils/retry.d.ts +0 -13
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-access gate for explicitly-requested per-run models (`--opus`,
|
|
3
|
+
* `--model=<slug>`). An explicit model the run can't serve hard-fails *before*
|
|
4
|
+
* the agent starts with one consistent, reason-tailored error.
|
|
5
|
+
*
|
|
6
|
+
* The provenance split lives upstream: `payload.modelExplicit` is true only for
|
|
7
|
+
* a flag in the triggerer's own @pullfrog prompt. A standing default (repo
|
|
8
|
+
* setting, a model flag in org/repo `baseInstructions`, or a trigger's fallback
|
|
9
|
+
* instructions) keeps `modelExplicit = false` and never reaches the error
|
|
10
|
+
* branches here — a missing key for a standing default surfaces through
|
|
11
|
+
* `validateAgentApiKey`'s missing-key error instead (#938).
|
|
12
|
+
*
|
|
13
|
+
* `decideModelAccess` is pure (no env / IO) so the branching is unit-testable;
|
|
14
|
+
* `buildModelAccessError` renders the user-facing markdown that `main.ts`
|
|
15
|
+
* throws and `runErrorRenderer.ts` re-surfaces on both run surfaces.
|
|
16
|
+
*/
|
|
17
|
+
export type ModelAccessReason = "oss" | "byok_no_key" | "router";
|
|
18
|
+
export type ModelAccessDecision = {
|
|
19
|
+
kind: "ok";
|
|
20
|
+
}
|
|
21
|
+
/** route through the Router/OSS proxy, re-targeted to the requested model. */
|
|
22
|
+
| {
|
|
23
|
+
kind: "proxy";
|
|
24
|
+
target: string;
|
|
25
|
+
}
|
|
26
|
+
/** run BYOK with the requested model — clear the minted proxy target. */
|
|
27
|
+
| {
|
|
28
|
+
kind: "byok";
|
|
29
|
+
} | {
|
|
30
|
+
kind: "error";
|
|
31
|
+
reason: ModelAccessReason;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* decide whether an (already-resolved) requested model can run, and how.
|
|
35
|
+
*
|
|
36
|
+
* - non-explicit / no model → `ok` (caller's missing-key validation applies).
|
|
37
|
+
* - proxy active + OSS → only the funded subsidy target routes; a different
|
|
38
|
+
* model needs the repo's own key (`byok`) else `error("oss")`.
|
|
39
|
+
* - proxy active + Router → honor any Router-servable model (`proxy`); fall to
|
|
40
|
+
* BYOK when locally authorized, else `error("router")`.
|
|
41
|
+
* - no proxy → the resolved model must be locally authorized, else
|
|
42
|
+
* `error("byok_no_key")`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function decideModelAccess(input: {
|
|
45
|
+
modelExplicit: boolean;
|
|
46
|
+
model: string | undefined;
|
|
47
|
+
oss: boolean;
|
|
48
|
+
proxyActive: boolean;
|
|
49
|
+
subsidyTarget: string | undefined;
|
|
50
|
+
resolvedModel: string | undefined;
|
|
51
|
+
authorized: Set<string>;
|
|
52
|
+
}): ModelAccessDecision;
|
|
53
|
+
/** marker on the throw message so `runErrorRenderer` can reclassify it. */
|
|
54
|
+
export declare const MODEL_ACCESS_MARKER = "requested model is not available";
|
|
55
|
+
/**
|
|
56
|
+
* render the model-access failure body (used for both the thrown error and the
|
|
57
|
+
* PR comment / job summary). one shape, reason-branched why → CTA.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildModelAccessError(input: {
|
|
60
|
+
reason: ModelAccessReason;
|
|
61
|
+
model: string;
|
|
62
|
+
owner: string;
|
|
63
|
+
name: string;
|
|
64
|
+
}): string;
|
package/dist/utils/payload.d.ts
CHANGED
|
@@ -5,10 +5,18 @@ export declare const JsonPayload: import("arktype/internal/variants/object.ts").
|
|
|
5
5
|
version: string;
|
|
6
6
|
prompt: string;
|
|
7
7
|
model?: string | undefined;
|
|
8
|
+
modelExplicit?: boolean | undefined;
|
|
8
9
|
triggerer?: string | undefined;
|
|
10
|
+
baseInstructions?: string | undefined;
|
|
9
11
|
eventInstructions?: string;
|
|
10
12
|
previousRunsNote?: string;
|
|
11
13
|
event?: object;
|
|
14
|
+
xrepo?: {
|
|
15
|
+
mode: "all" | "explicit";
|
|
16
|
+
read: string[];
|
|
17
|
+
write: string[];
|
|
18
|
+
unavailable?: string[];
|
|
19
|
+
} | undefined;
|
|
12
20
|
timeout?: string | undefined;
|
|
13
21
|
progressComment?: {
|
|
14
22
|
id: string;
|
|
@@ -17,26 +25,42 @@ export declare const JsonPayload: import("arktype/internal/variants/object.ts").
|
|
|
17
25
|
generateSummary?: boolean | undefined;
|
|
18
26
|
}, {}>;
|
|
19
27
|
export declare const Inputs: import("arktype/internal/variants/object.ts").ObjectType<{
|
|
20
|
-
prompt
|
|
28
|
+
prompt?: string | undefined;
|
|
29
|
+
prompt_file?: string | undefined;
|
|
21
30
|
model?: string | undefined;
|
|
22
31
|
timeout?: string | undefined;
|
|
23
32
|
push?: "disabled" | "enabled" | "restricted" | undefined;
|
|
24
33
|
shell?: "disabled" | "enabled" | "restricted" | undefined;
|
|
34
|
+
status_checks?: "disabled" | "enabled" | undefined;
|
|
25
35
|
cwd?: string | undefined;
|
|
26
36
|
output_schema?: string | undefined;
|
|
27
37
|
}, {}>;
|
|
28
38
|
export type Inputs = typeof Inputs.infer;
|
|
29
39
|
export type ResolvedPromptInput = string | typeof JsonPayload.infer;
|
|
30
40
|
export declare function resolvePromptInput(): ResolvedPromptInput;
|
|
41
|
+
/**
|
|
42
|
+
* true when `actor` is Pullfrog's own GitHub identity — the bot login
|
|
43
|
+
* (`pullfrog[bot]` / `pullfrogdev[bot]`) or the bare account. used to skip
|
|
44
|
+
* self-triggered events and to recognize Pullfrog-originated review threads.
|
|
45
|
+
*/
|
|
46
|
+
export declare const isPullfrog: (actor: string | null | undefined) => boolean;
|
|
31
47
|
export declare function resolvePayload(resolvedPromptInput: ResolvedPromptInput, repoSettings: RepoSettings): {
|
|
32
48
|
"~pullfrog": true;
|
|
33
49
|
version: string;
|
|
34
50
|
model: string | undefined;
|
|
51
|
+
modelExplicit: boolean;
|
|
35
52
|
prompt: string;
|
|
36
53
|
triggerer: string | undefined;
|
|
54
|
+
baseInstructions: string | undefined;
|
|
37
55
|
eventInstructions: string | undefined;
|
|
38
56
|
previousRunsNote: string | undefined;
|
|
39
57
|
event: PayloadEvent;
|
|
58
|
+
xrepo: {
|
|
59
|
+
mode: "all" | "explicit";
|
|
60
|
+
read: string[];
|
|
61
|
+
write: string[];
|
|
62
|
+
unavailable?: string[];
|
|
63
|
+
} | undefined;
|
|
40
64
|
timeout: string | undefined;
|
|
41
65
|
cwd: string | undefined;
|
|
42
66
|
progressComment: {
|
|
@@ -46,6 +70,7 @@ export declare function resolvePayload(resolvedPromptInput: ResolvedPromptInput,
|
|
|
46
70
|
generateSummary: boolean | undefined;
|
|
47
71
|
push: import("../external.ts").PushPermission;
|
|
48
72
|
shell: import("../external.ts").ShellPermission;
|
|
73
|
+
statusChecks: boolean;
|
|
49
74
|
proxyModel: string | undefined;
|
|
50
75
|
};
|
|
51
76
|
export type ResolvedPayload = ReturnType<typeof resolvePayload>;
|
|
@@ -36,6 +36,9 @@ export interface RepoSettings {
|
|
|
36
36
|
learnings: string | null;
|
|
37
37
|
learningsHeadings: LearningsHeading[];
|
|
38
38
|
envAllowlist: string | null;
|
|
39
|
+
xrepoBrief: string | null;
|
|
40
|
+
xrepoLearnings: string | null;
|
|
41
|
+
xrepoLearningsHeadings: LearningsHeading[];
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
44
|
* Account-level billing plan. Orthogonal to repo-level OSS status. Mirrors
|
|
@@ -18,6 +18,16 @@ interface ResolveRunContextDataParams {
|
|
|
18
18
|
octokit: OctokitWithPlugins;
|
|
19
19
|
token: string;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* true when the action is pinned to a full commit SHA (vs the moving `@v0`
|
|
23
|
+
* tag or a branch). GitHub runs the action's `post:` hook (and reads
|
|
24
|
+
* `action.yml`) straight from the checked-out action ref, so a SHA pin freezes
|
|
25
|
+
* that checkout forever: the main agent still floats to the latest `^semver`
|
|
26
|
+
* via the npm bootstrap (this code is proof — it ran), but the post-run
|
|
27
|
+
* cleanup step keeps executing the pinned commit's source and never receives
|
|
28
|
+
* fixes. surfaced in the log and PR footers to nudge repos back to `@v0`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isActionPinnedToSha(): boolean;
|
|
21
31
|
/**
|
|
22
32
|
* initialize run context data: parse context, fetch repo info and settings
|
|
23
33
|
*/
|
package/dist/utils/setup.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ShellPermission } from "../external.ts";
|
|
2
|
-
import type
|
|
2
|
+
import { type ToolState } from "../toolState.ts";
|
|
3
3
|
import type { OctokitWithPlugins } from "./github.ts";
|
|
4
4
|
export interface SetupOptions {
|
|
5
5
|
tempDir: string;
|
|
@@ -61,15 +61,30 @@ export interface GitContext {
|
|
|
61
61
|
postCheckoutScript: string | null;
|
|
62
62
|
}
|
|
63
63
|
export type SetupGitParams = GitContext;
|
|
64
|
+
/** GitContext plus an explicit working-tree directory (primary cwd or a
|
|
65
|
+
* secondary clone under ctx.tmpdir/xrepo/<name>). */
|
|
66
|
+
export interface ConfigureRepoGitParams extends GitContext {
|
|
67
|
+
dir: string;
|
|
68
|
+
}
|
|
64
69
|
/**
|
|
65
|
-
* setup git configuration
|
|
70
|
+
* setup git configuration + authentication for the PRIMARY repo working tree
|
|
71
|
+
* (process.cwd()). thin wrapper over configureRepoGit. preserves the existing
|
|
72
|
+
* single-repo call shape in main.ts.
|
|
73
|
+
*/
|
|
74
|
+
export declare function setupGit(params: SetupGitParams): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* setup git configuration and authentication for a repository working tree at
|
|
77
|
+
* `params.dir`. used for the primary repo (dir = cwd) and for secondary repos
|
|
78
|
+
* cloned on demand by checkout_repo (dir = ctx.tmpdir/xrepo/<name>).
|
|
66
79
|
* - configures git identity (user.email, user.name)
|
|
67
80
|
* - sets up authentication via gitToken (minimal contents:write)
|
|
81
|
+
* - records pushUrl + initialHead onto the repo's RepoToolState (must already
|
|
82
|
+
* be registered in toolState.repos)
|
|
68
83
|
*
|
|
69
84
|
* gitToken is a minimal-permission token (contents + workflows) used for git operations.
|
|
70
85
|
* it is assumed to be potentially exfiltratable, so it has limited scope.
|
|
71
86
|
*/
|
|
72
|
-
export declare function
|
|
87
|
+
export declare function configureRepoGit(params: ConfigureRepoGitParams): Promise<void>;
|
|
73
88
|
/**
|
|
74
89
|
* snapshot the current HEAD as either a branch name (when on a named branch)
|
|
75
90
|
* or a literal SHA (when detached). used by setupGit to pin the run-entry
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ToolContext } from "../mcp/server.ts";
|
|
2
|
+
/**
|
|
3
|
+
* post the opt-in `pullfrog` (run completion) and `pullfrog-approval` (review
|
|
4
|
+
* verdict) commit-status check-runs so they can be required by branch
|
|
5
|
+
* protection. no-op unless the `status_checks` input is enabled and the run is
|
|
6
|
+
* on a pull request.
|
|
7
|
+
*
|
|
8
|
+
* terminal-only by design: we never create an `in_progress` check. a
|
|
9
|
+
* hard-cancelled run (SIGKILL) would strand a required check `in_progress` and
|
|
10
|
+
* block merges forever; an absent required check already blocks merge the same
|
|
11
|
+
* way while the run is in flight, with no stuck-check failure mode.
|
|
12
|
+
*
|
|
13
|
+
* - `pullfrog` is posted on every PR run: success iff the run finished
|
|
14
|
+
* successfully, failure on error/timeout. review-verdict-agnostic.
|
|
15
|
+
* - `pullfrog-approval` is posted only when this run produced an approval
|
|
16
|
+
* verdict (`toolState.approval`, set by create_pull_request_review),
|
|
17
|
+
* anchored to the reviewed sha so a mid-run push leaves the new head
|
|
18
|
+
* unapproved until the follow-up re-review reports.
|
|
19
|
+
*
|
|
20
|
+
* best-effort throughout: a check-post failure (fork PR head not in the base
|
|
21
|
+
* repo, transient 5xx, closed PR) must never flip the run's own outcome.
|
|
22
|
+
*/
|
|
23
|
+
export declare function reportStatusChecks(ctx: ToolContext, params: {
|
|
24
|
+
runSucceeded: boolean;
|
|
25
|
+
}): Promise<void>;
|
package/dist/utils/token.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PushPermission } from "../external.ts";
|
|
1
|
+
import type { PushPermission, XrepoConfig } from "../external.ts";
|
|
2
2
|
import { acquireNewToken, type OidcCredentials } from "./github.ts";
|
|
3
3
|
export { acquireNewToken as acquireInstallationToken };
|
|
4
4
|
export { revokeGitHubInstallationToken as revokeInstallationToken };
|
|
@@ -20,10 +20,13 @@ export declare function getJobToken(): string;
|
|
|
20
20
|
export type TokenRef = {
|
|
21
21
|
gitToken: string;
|
|
22
22
|
mcpToken: string;
|
|
23
|
+
readToken?: string | undefined;
|
|
24
|
+
refreshGitToken?: ((stale: string) => Promise<string>) | undefined;
|
|
23
25
|
[Symbol.asyncDispose]: () => Promise<void>;
|
|
24
26
|
};
|
|
25
27
|
type ResolveTokensParams = {
|
|
26
28
|
push: PushPermission;
|
|
29
|
+
xrepo?: XrepoConfig | undefined;
|
|
27
30
|
/**
|
|
28
31
|
* OIDC credentials stashed by main.ts before the restricted-mode env wipe —
|
|
29
32
|
* the mid-run MCP token refresh mints from this snapshot (#891). null when
|
|
@@ -34,11 +37,16 @@ type ResolveTokensParams = {
|
|
|
34
37
|
/**
|
|
35
38
|
* resolve tokens for the action run.
|
|
36
39
|
*
|
|
37
|
-
* creates two separate tokens:
|
|
40
|
+
* creates two separate tokens (three on cross-repo runs):
|
|
38
41
|
* - gitToken: contents permission based on `push` setting (assumed exfiltratable)
|
|
39
42
|
* - push: enabled → contents:write (can push)
|
|
40
43
|
* - push: disabled → contents:read (read-only)
|
|
41
44
|
* - mcpToken: full installation token - used for GitHub API calls in MCP tools (not exfiltratable)
|
|
45
|
+
* - readToken (xrepo only): contents:read over the read set, for cloning read-tier secondaries
|
|
46
|
+
*
|
|
47
|
+
* on cross-repo runs, gitToken + mcpToken are scoped to the WRITE set (always
|
|
48
|
+
* incl. the primary), so a writable secondary can take PRs; read-only
|
|
49
|
+
* secondaries route through readToken instead.
|
|
42
50
|
*
|
|
43
51
|
* security-conscious users can pass their own token via GH_TOKEN env var or inputs.token.
|
|
44
52
|
*/
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "./standard-schema.ts";
|
|
2
|
+
export type { StandardSchemaV1 } from "./standard-schema.ts";
|
|
3
|
+
export declare function range(n: number): number[];
|
|
4
|
+
export declare function range(start: number, end: number): number[];
|
|
5
|
+
export declare function range(n: number, fn: (i: number) => number): number[];
|
|
6
|
+
export declare function schedule(fn: (i: number) => number, count: number): number[];
|
|
7
|
+
/**
|
|
8
|
+
* read a retry delay (ms) from a thrown HTTP error's response headers, honoring
|
|
9
|
+
* GitHub's rate-limit backoff hints on octokit errors (`error.response.headers`):
|
|
10
|
+
* - `retry-after` (RFC 9110 delta-seconds or an HTTP-date) — an explicit
|
|
11
|
+
* backoff directive whenever present (covers secondary rate limits, which
|
|
12
|
+
* carry it with `x-ratelimit-remaining > 0`).
|
|
13
|
+
* - else `x-ratelimit-reset` (epoch seconds) but ONLY when
|
|
14
|
+
* `x-ratelimit-remaining` is `"0"` — GitHub sends the reset header on ~every
|
|
15
|
+
* response (~1h ahead), so it's a backoff hint only under actual primary
|
|
16
|
+
* rate-limit exhaustion (matching octokit's throttling plugin). without this
|
|
17
|
+
* gate a non-rate-limit retried error (e.g. a permissions 403) would be
|
|
18
|
+
* wrongly delayed to the reset time.
|
|
19
|
+
* returns `undefined` when no applicable hint is present/parseable.
|
|
20
|
+
*/
|
|
21
|
+
export declare function retryAfterMs(error: unknown): number | undefined;
|
|
22
|
+
type InferInput<S> = S extends StandardSchemaV1<infer I, any> ? I : never;
|
|
23
|
+
type InferOutput<S> = S extends StandardSchemaV1<any, infer O> ? O : never;
|
|
24
|
+
export interface OpOptions<TReturn = any> {
|
|
25
|
+
name?: string;
|
|
26
|
+
ttl?: number;
|
|
27
|
+
maxItems?: number;
|
|
28
|
+
retries?: number[];
|
|
29
|
+
/**
|
|
30
|
+
* honor a server backoff hint on retries: when a retried error carries a
|
|
31
|
+
* `retry-after` / `x-ratelimit-reset` header, schedule the next retry from
|
|
32
|
+
* that value (clamped to `[fixed delay, retryAfterCap]`) instead of the fixed
|
|
33
|
+
* `retries[attempt]` backoff. `true` uses the built-in `retryAfterMs` reader;
|
|
34
|
+
* a function extracts a delay-ms from a custom error shape. errors without the
|
|
35
|
+
* header fall back to the fixed backoff.
|
|
36
|
+
*/
|
|
37
|
+
retryAfter?: boolean | ((error: unknown) => number | undefined);
|
|
38
|
+
/** cap (ms) on a honored retry-after hint. default 20000. */
|
|
39
|
+
retryAfterCap?: number;
|
|
40
|
+
cacheHit?: ((key: string) => void) | null;
|
|
41
|
+
cacheMiss?: ((key: string) => void) | null;
|
|
42
|
+
skipCache?: (result: TReturn) => boolean;
|
|
43
|
+
bail?: (error: unknown) => boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface OpObjectOptions<TInputSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined, TRun extends (input: TInputSchema extends StandardSchemaV1 ? InferOutput<TInputSchema> : any, ctx?: any) => Promise<TOutputSchema extends StandardSchemaV1 ? InferInput<TOutputSchema> : any> = (input: TInputSchema extends StandardSchemaV1 ? InferOutput<TInputSchema> : any, ctx?: any) => Promise<TOutputSchema extends StandardSchemaV1 ? InferInput<TOutputSchema> : any>> extends OpOptions<TOutputSchema extends StandardSchemaV1 ? InferOutput<TOutputSchema> : Awaited<ReturnType<TRun>>> {
|
|
46
|
+
input?: TInputSchema;
|
|
47
|
+
output?: TOutputSchema;
|
|
48
|
+
run: TRun;
|
|
49
|
+
}
|
|
50
|
+
type AnyAsyncFn = (...args: any[]) => Promise<any>;
|
|
51
|
+
type Input<F extends AnyAsyncFn> = Parameters<F>[0];
|
|
52
|
+
export type OpFunction<F extends AnyAsyncFn> = F & {
|
|
53
|
+
clear: (key?: Input<F>) => void;
|
|
54
|
+
has: (key: Input<F>) => boolean;
|
|
55
|
+
invalidate: (predicate: (key: Input<F>) => boolean) => number;
|
|
56
|
+
};
|
|
57
|
+
export declare function op<F extends AnyAsyncFn>(fn: F, options?: OpOptions<Awaited<ReturnType<F>>>): OpFunction<F>;
|
|
58
|
+
export declare function op<TInputSchema extends StandardSchemaV1 | undefined = undefined, TOutputSchema extends StandardSchemaV1 | undefined = undefined, TRun extends (input: TInputSchema extends StandardSchemaV1 ? InferOutput<TInputSchema> : any, ctx?: any) => Promise<TOutputSchema extends StandardSchemaV1 ? InferInput<TOutputSchema> : any> = (input: TInputSchema extends StandardSchemaV1 ? InferOutput<TInputSchema> : any, ctx?: any) => Promise<TOutputSchema extends StandardSchemaV1 ? InferInput<TOutputSchema> : any>>(options: OpObjectOptions<TInputSchema, TOutputSchema, TRun>): OpFunction<(input: TInputSchema extends StandardSchemaV1 ? InferInput<TInputSchema> : Parameters<TRun>[0], ctx?: TRun extends (input: any, ctx: infer C, ...rest: any[]) => any ? C : never) => Promise<TOutputSchema extends StandardSchemaV1 ? InferOutput<TOutputSchema> : Awaited<ReturnType<TRun>>>>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
2
|
+
export interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
3
|
+
/** The Standard properties. */
|
|
4
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
5
|
+
}
|
|
6
|
+
export declare namespace StandardTypedV1 {
|
|
7
|
+
/** The Standard Typed properties interface. */
|
|
8
|
+
interface Props<Input = unknown, Output = Input> {
|
|
9
|
+
/** The version number of the standard. */
|
|
10
|
+
readonly version: 1;
|
|
11
|
+
/** The vendor name of the schema library. */
|
|
12
|
+
readonly vendor: string;
|
|
13
|
+
/** Inferred types associated with the schema. */
|
|
14
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
15
|
+
}
|
|
16
|
+
/** The Standard Typed types interface. */
|
|
17
|
+
interface Types<Input = unknown, Output = Input> {
|
|
18
|
+
/** The input type of the schema. */
|
|
19
|
+
readonly input: Input;
|
|
20
|
+
/** The output type of the schema. */
|
|
21
|
+
readonly output: Output;
|
|
22
|
+
}
|
|
23
|
+
/** Infers the input type of a Standard Typed. */
|
|
24
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
25
|
+
/** Infers the output type of a Standard Typed. */
|
|
26
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
27
|
+
}
|
|
28
|
+
/** The Standard Schema interface. */
|
|
29
|
+
export interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
30
|
+
/** The Standard Schema properties. */
|
|
31
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
32
|
+
}
|
|
33
|
+
export declare namespace StandardSchemaV1 {
|
|
34
|
+
/** The Standard Schema properties interface. */
|
|
35
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
36
|
+
/** Validates unknown input values. */
|
|
37
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
38
|
+
}
|
|
39
|
+
/** The result interface of the validate function. */
|
|
40
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
41
|
+
/** The result interface if validation succeeds. */
|
|
42
|
+
interface SuccessResult<Output> {
|
|
43
|
+
/** The typed output value. */
|
|
44
|
+
readonly value: Output;
|
|
45
|
+
/** A falsy value for `issues` indicates success. */
|
|
46
|
+
readonly issues?: undefined;
|
|
47
|
+
}
|
|
48
|
+
interface Options {
|
|
49
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
50
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
51
|
+
}
|
|
52
|
+
/** The result interface if validation fails. */
|
|
53
|
+
interface FailureResult {
|
|
54
|
+
/** The issues of failed validation. */
|
|
55
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
56
|
+
}
|
|
57
|
+
/** The issue interface of the failure output. */
|
|
58
|
+
interface Issue {
|
|
59
|
+
/** The error message of the issue. */
|
|
60
|
+
readonly message: string;
|
|
61
|
+
/** The path of the issue, if any. */
|
|
62
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** The path segment interface of the issue. */
|
|
65
|
+
interface PathSegment {
|
|
66
|
+
/** The key representing a path segment. */
|
|
67
|
+
readonly key: PropertyKey;
|
|
68
|
+
}
|
|
69
|
+
/** The Standard types interface. */
|
|
70
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
71
|
+
}
|
|
72
|
+
/** Infers the input type of a Standard. */
|
|
73
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
74
|
+
/** Infers the output type of a Standard. */
|
|
75
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
76
|
+
}
|
|
77
|
+
/** The Standard JSON Schema interface. */
|
|
78
|
+
export interface StandardJSONSchemaV1<Input = unknown, Output = Input> {
|
|
79
|
+
/** The Standard JSON Schema properties. */
|
|
80
|
+
readonly "~standard": StandardJSONSchemaV1.Props<Input, Output>;
|
|
81
|
+
}
|
|
82
|
+
export declare namespace StandardJSONSchemaV1 {
|
|
83
|
+
/** The Standard JSON Schema properties interface. */
|
|
84
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
85
|
+
/** Methods for generating the input/output JSON Schema. */
|
|
86
|
+
readonly jsonSchema: StandardJSONSchemaV1.Converter;
|
|
87
|
+
}
|
|
88
|
+
/** The Standard JSON Schema converter interface. */
|
|
89
|
+
interface Converter {
|
|
90
|
+
/** Converts the input type to JSON Schema. May throw if conversion is not supported. */
|
|
91
|
+
readonly input: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
92
|
+
/** Converts the output type to JSON Schema. May throw if conversion is not supported. */
|
|
93
|
+
readonly output: (options: StandardJSONSchemaV1.Options) => Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* The target version of the generated JSON Schema.
|
|
97
|
+
*
|
|
98
|
+
* It is *strongly recommended* that implementers support `"draft-2020-12"` and `"draft-07"`, as they are both in wide use. All other targets can be implemented on a best-effort basis. Libraries should throw if they don't support a specified target.
|
|
99
|
+
*
|
|
100
|
+
* The `"openapi-3.0"` target is intended as a standardized specifier for OpenAPI 3.0 which is a superset of JSON Schema `"draft-04"`.
|
|
101
|
+
*/
|
|
102
|
+
type Target = "draft-2020-12" | "draft-07" | "openapi-3.0" | ({} & string);
|
|
103
|
+
/** The options for the input/output methods. */
|
|
104
|
+
interface Options {
|
|
105
|
+
/** Specifies the target version of the generated JSON Schema. Support for all versions is on a best-effort basis. If a given version is not supported, the library should throw. */
|
|
106
|
+
readonly target: Target;
|
|
107
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
108
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
109
|
+
}
|
|
110
|
+
/** The Standard types interface. */
|
|
111
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {
|
|
112
|
+
}
|
|
113
|
+
/** Infers the input type of a Standard. */
|
|
114
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
115
|
+
/** Infers the output type of a Standard. */
|
|
116
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
117
|
+
}
|