There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
feat: add filter schema (#3479)
Alex Yang03f12f6aa427
diff --git a/packages/env/package.json b/packages/env/package.jsonindex 6414c9b360..52c50c4ecc 100644--- a/packages/env/package.json+++ b/packages/env/package.json@@ -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",diff --git a/packages/env/src/automation.ts b/packages/env/src/automation.tsnew file mode 100644index 0000000000..08b53a8dd0--- /dev/null+++ b/packages/env/src/automation.ts@@ -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;+};diff --git a/packages/env/src/filter.ts b/packages/env/src/filter.tsindex 0f45e6c1c6..4b41f9a389 100644--- a/packages/env/src/filter.ts+++ b/packages/env/src/filter.ts@@ -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-interfaceexport 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'];