mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-28 07:43:24 +03:00
feat: add filter schema (#3479)
This commit is contained in:
parent
0176d66a94
commit
03f12f6aa4
1
packages/env/package.json
vendored
1
packages/env/package.json
vendored
@ -12,6 +12,7 @@
|
||||
"zod": "^3.21.4"
|
||||
},
|
||||
"exports": {
|
||||
"./automation": "./src/automation.ts",
|
||||
"./global": "./src/global.ts",
|
||||
"./constant": "./src/constant.ts",
|
||||
"./workspace": "./src/workspace.ts",
|
||||
|
12
packages/env/src/automation.ts
vendored
Normal file
12
packages/env/src/automation.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import type { z } from 'zod';
|
||||
|
||||
export type Action<
|
||||
InputSchema extends z.ZodObject<any, any, any, any>,
|
||||
Args extends readonly any[],
|
||||
> = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
inputSchema: InputSchema;
|
||||
action: (input: z.input<InputSchema>, ...args: Args) => void;
|
||||
};
|
73
packages/env/src/filter.ts
vendored
73
packages/env/src/filter.ts
vendored
@ -1,4 +1,14 @@
|
||||
import type { Workspace } from '@blocksuite/store';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const literalValueSchema: z.ZodType<LiteralValue, z.ZodTypeDef> =
|
||||
z.union([
|
||||
z.number(),
|
||||
z.string(),
|
||||
z.boolean(),
|
||||
z.array(z.lazy(() => literalValueSchema)),
|
||||
z.record(z.lazy(() => literalValueSchema)),
|
||||
]);
|
||||
|
||||
export type LiteralValue =
|
||||
| number
|
||||
@ -7,6 +17,11 @@ export type LiteralValue =
|
||||
| { [K: string]: LiteralValue }
|
||||
| Array<LiteralValue>;
|
||||
|
||||
export const refSchema: z.ZodType<Ref, z.ZodTypeDef> = z.object({
|
||||
type: z.literal('ref'),
|
||||
name: z.never(),
|
||||
});
|
||||
|
||||
export type Ref = {
|
||||
type: 'ref';
|
||||
name: keyof VariableMap;
|
||||
@ -15,32 +30,40 @@ export type Ref = {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface VariableMap {}
|
||||
|
||||
export type Literal = {
|
||||
type: 'literal';
|
||||
value: LiteralValue;
|
||||
};
|
||||
export const literalSchema = z.object({
|
||||
type: z.literal('literal'),
|
||||
value: literalValueSchema,
|
||||
});
|
||||
|
||||
export type Filter = {
|
||||
type: 'filter';
|
||||
left: Ref;
|
||||
funcName: string;
|
||||
args: Literal[];
|
||||
};
|
||||
export type Literal = z.input<typeof literalSchema>;
|
||||
|
||||
export type Collection = {
|
||||
id: string;
|
||||
workspaceId: string;
|
||||
name: string;
|
||||
pinned?: boolean;
|
||||
filterList: Filter[];
|
||||
allowList?: string[];
|
||||
excludeList?: string[];
|
||||
};
|
||||
export const filterSchema = z.object({
|
||||
type: z.literal('filter'),
|
||||
left: refSchema,
|
||||
funcName: z.string(),
|
||||
args: z.array(literalSchema),
|
||||
});
|
||||
|
||||
export type Filter = z.input<typeof filterSchema>;
|
||||
|
||||
export const collectionSchema = z.object({
|
||||
id: z.string(),
|
||||
workspaceId: z.string(),
|
||||
name: z.string(),
|
||||
pinned: z.boolean().optional(),
|
||||
filterList: z.array(filterSchema),
|
||||
allowList: z.array(z.string()).optional(),
|
||||
excludeList: z.array(z.string()).optional(),
|
||||
});
|
||||
|
||||
export type Collection = z.input<typeof collectionSchema>;
|
||||
|
||||
export const tagSchema = z.object({
|
||||
id: z.string(),
|
||||
value: z.string(),
|
||||
color: z.string(),
|
||||
parentId: z.string().optional(),
|
||||
});
|
||||
export type Tag = z.input<typeof tagSchema>;
|
||||
|
||||
export type Tag = {
|
||||
id: string;
|
||||
value: string;
|
||||
color: string;
|
||||
parentId?: string;
|
||||
};
|
||||
export type PropertiesMeta = Workspace['meta']['properties'];
|
||||
|
Loading…
Reference in New Issue
Block a user