feat: add filter schema (#3479)
This commit is contained in:
1
packages/env/package.json
vendored
1
packages/env/package.json
vendored
@@ -12,6 +12,7 @@
|
|||||||
"zod": "^3.21.4"
|
"zod": "^3.21.4"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
|
"./automation": "./src/automation.ts",
|
||||||
"./global": "./src/global.ts",
|
"./global": "./src/global.ts",
|
||||||
"./constant": "./src/constant.ts",
|
"./constant": "./src/constant.ts",
|
||||||
"./workspace": "./src/workspace.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 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 =
|
export type LiteralValue =
|
||||||
| number
|
| number
|
||||||
@@ -7,6 +17,11 @@ export type LiteralValue =
|
|||||||
| { [K: string]: LiteralValue }
|
| { [K: string]: LiteralValue }
|
||||||
| Array<LiteralValue>;
|
| Array<LiteralValue>;
|
||||||
|
|
||||||
|
export const refSchema: z.ZodType<Ref, z.ZodTypeDef> = z.object({
|
||||||
|
type: z.literal('ref'),
|
||||||
|
name: z.never(),
|
||||||
|
});
|
||||||
|
|
||||||
export type Ref = {
|
export type Ref = {
|
||||||
type: 'ref';
|
type: 'ref';
|
||||||
name: keyof VariableMap;
|
name: keyof VariableMap;
|
||||||
@@ -15,32 +30,40 @@ export type Ref = {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||||
export interface VariableMap {}
|
export interface VariableMap {}
|
||||||
|
|
||||||
export type Literal = {
|
export const literalSchema = z.object({
|
||||||
type: 'literal';
|
type: z.literal('literal'),
|
||||||
value: LiteralValue;
|
value: literalValueSchema,
|
||||||
};
|
});
|
||||||
|
|
||||||
export type Filter = {
|
export type Literal = z.input<typeof literalSchema>;
|
||||||
type: 'filter';
|
|
||||||
left: Ref;
|
|
||||||
funcName: string;
|
|
||||||
args: Literal[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type Collection = {
|
export const filterSchema = z.object({
|
||||||
id: string;
|
type: z.literal('filter'),
|
||||||
workspaceId: string;
|
left: refSchema,
|
||||||
name: string;
|
funcName: z.string(),
|
||||||
pinned?: boolean;
|
args: z.array(literalSchema),
|
||||||
filterList: Filter[];
|
});
|
||||||
allowList?: string[];
|
|
||||||
excludeList?: string[];
|
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'];
|
export type PropertiesMeta = Workspace['meta']['properties'];
|
||||||
|
|||||||
Reference in New Issue
Block a user