mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-18 19:30:27 +08:00
Update seeding policy schema
This commit is contained in:
+34
-15
@@ -12,8 +12,7 @@ import type {
|
||||
SuccessResponse,
|
||||
CodeLocation,
|
||||
Range,
|
||||
Policy,
|
||||
Scope,
|
||||
DefaultSeedingPolicy,
|
||||
} from "./lib/shared.js";
|
||||
import type { Comment, Embed, Reaction } from "./lib/project/comment.js";
|
||||
import type {
|
||||
@@ -48,7 +47,11 @@ import * as project from "./lib/project.js";
|
||||
import * as profile from "./lib/profile.js";
|
||||
import * as session from "./lib/session.js";
|
||||
import { Fetcher } from "./lib/fetcher.js";
|
||||
import { nodeConfigSchema, successResponseSchema } from "./lib/shared.js";
|
||||
import {
|
||||
nodeConfigSchema,
|
||||
scopeSchema,
|
||||
successResponseSchema,
|
||||
} from "./lib/shared.js";
|
||||
|
||||
export type {
|
||||
BaseUrl,
|
||||
@@ -60,6 +63,7 @@ export type {
|
||||
Commit,
|
||||
CommitBlob,
|
||||
CommitHeader,
|
||||
DefaultSeedingPolicy,
|
||||
Diff,
|
||||
DiffBlob,
|
||||
DiffContent,
|
||||
@@ -74,7 +78,6 @@ export type {
|
||||
Patch,
|
||||
PatchState,
|
||||
PatchUpdateAction,
|
||||
Policy,
|
||||
Project,
|
||||
ProjectListQuery,
|
||||
Range,
|
||||
@@ -82,7 +85,6 @@ export type {
|
||||
Remote,
|
||||
Review,
|
||||
Revision,
|
||||
Scope,
|
||||
TreeStats,
|
||||
Tree,
|
||||
Verdict,
|
||||
@@ -120,15 +122,18 @@ const nodeInfoSchema = object({
|
||||
),
|
||||
});
|
||||
|
||||
export type NodeTracking = z.infer<typeof nodeTrackingSchema>;
|
||||
export type NodePolicies = z.infer<typeof nodePoliciesSchema>;
|
||||
|
||||
const nodeTrackingSchema = array(
|
||||
object({
|
||||
id: string(),
|
||||
scope: string(),
|
||||
policy: string(),
|
||||
}),
|
||||
);
|
||||
const nodePoliciesSchema = object({
|
||||
rid: string(),
|
||||
policy: union([
|
||||
object({ policy: literal("block") }),
|
||||
object({
|
||||
policy: literal("allow"),
|
||||
scope: scopeSchema,
|
||||
}),
|
||||
]),
|
||||
});
|
||||
|
||||
export interface NodeStats {
|
||||
repos: { total: number };
|
||||
@@ -192,14 +197,28 @@ export class HttpdClient {
|
||||
);
|
||||
}
|
||||
|
||||
public async getTracking(options?: RequestOptions): Promise<NodeTracking> {
|
||||
public async getPolicies(options?: RequestOptions): Promise<NodePolicies[]> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "GET",
|
||||
path: "node/policies/repos",
|
||||
options,
|
||||
},
|
||||
nodeTrackingSchema,
|
||||
array(nodePoliciesSchema),
|
||||
);
|
||||
}
|
||||
|
||||
public async getPoliciesById(
|
||||
id: string,
|
||||
options?: RequestOptions,
|
||||
): Promise<NodePolicies["policy"][]> {
|
||||
return this.#fetcher.fetchOk(
|
||||
{
|
||||
method: "GET",
|
||||
path: `node/policies/repos/${id}`,
|
||||
options,
|
||||
},
|
||||
array(nodePoliciesSchema.shape.policy),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,17 @@ export const successResponseSchema = object({
|
||||
success: literal(true),
|
||||
}) satisfies ZodSchema<SuccessResponse>;
|
||||
|
||||
const policySchema = union([literal("allow"), literal("block")]);
|
||||
const scopeSchema = union([literal("followed"), literal("all")]);
|
||||
export const scopeSchema = union([literal("followed"), literal("all")]);
|
||||
|
||||
const defaultSeedingPolicySchema = union([
|
||||
object({
|
||||
default: literal("block"),
|
||||
}),
|
||||
object({
|
||||
default: literal("allow"),
|
||||
scope: scopeSchema,
|
||||
}),
|
||||
]);
|
||||
|
||||
export const nodeConfigSchema = object({
|
||||
alias: string(),
|
||||
@@ -61,14 +70,10 @@ export const nodeConfigSchema = object({
|
||||
}),
|
||||
}),
|
||||
workers: number(),
|
||||
seedingPolicy: object({
|
||||
default: policySchema,
|
||||
scope: scopeSchema.optional(),
|
||||
}),
|
||||
seedingPolicy: defaultSeedingPolicySchema,
|
||||
});
|
||||
|
||||
export type Policy = z.infer<typeof policySchema>;
|
||||
export type Scope = z.infer<typeof scopeSchema>;
|
||||
export type DefaultSeedingPolicy = z.infer<typeof defaultSeedingPolicySchema>;
|
||||
|
||||
export const rangeSchema = union([
|
||||
object({
|
||||
|
||||
Reference in New Issue
Block a user