mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix: move workspace to top level (#2717)
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { PermissionType } from '@affine/workspace/affine/api';
|
||||
import type {
|
||||
AffineLegacyCloudWorkspace,
|
||||
LocalWorkspace,
|
||||
} from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
} from '@affine/env/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { PermissionType } from '@affine/env/workspace/legacy-cloud';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import { SettingsIcon } from '@blocksuite/icons';
|
||||
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
|
||||
import type { FC } from 'react';
|
||||
|
||||
@@ -3,6 +3,12 @@
|
||||
*/
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import type {
|
||||
Filter,
|
||||
LiteralValue,
|
||||
Ref,
|
||||
VariableMap,
|
||||
} from '@affine/env/filter';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { render } from '@testing-library/react';
|
||||
import { useState } from 'react';
|
||||
@@ -10,12 +16,6 @@ import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { Condition } from '../filter/condition';
|
||||
import { tBoolean, tDate } from '../filter/logical/custom-type';
|
||||
import type {
|
||||
Filter,
|
||||
LiteralValue,
|
||||
Ref,
|
||||
VariableMap,
|
||||
} from '../filter/shared-types';
|
||||
import { toLiteral } from '../filter/shared-types';
|
||||
import type { FilterMatcherDataType } from '../filter/vars';
|
||||
import { filterMatcher } from '../filter/vars';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Filter, Literal } from '@affine/env/filter';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
@@ -5,7 +6,6 @@ import { Menu, MenuItem } from '../../../ui/menu';
|
||||
import * as styles from './index.css';
|
||||
import { literalMatcher } from './literal-matcher';
|
||||
import type { TFunction, TType } from './logical/typesystem';
|
||||
import type { Filter, Literal } from './shared-types';
|
||||
import { filterMatcher, VariableSelect, vars } from './vars';
|
||||
|
||||
export const Condition = ({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Filter, Literal, Ref, VariableMap } from './shared-types';
|
||||
import type { Filter, Literal, Ref, VariableMap } from '@affine/env/filter';
|
||||
|
||||
import { filterMatcher } from './vars';
|
||||
|
||||
const evalRef = (ref: Ref, variableMap: VariableMap) => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Filter } from '@affine/env/filter';
|
||||
import { CloseIcon, PlusIcon } from '@blocksuite/icons';
|
||||
|
||||
import { Menu } from '../../..';
|
||||
import { Condition } from './condition';
|
||||
import * as styles from './index.css';
|
||||
import type { Filter } from './shared-types';
|
||||
import { CreateFilterMenu } from './vars';
|
||||
export const FilterList = ({
|
||||
value,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Literal } from '@affine/env/filter';
|
||||
import dayjs from 'dayjs';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
@@ -6,7 +7,6 @@ import { tBoolean, tDate } from './logical/custom-type';
|
||||
import { Matcher } from './logical/matcher';
|
||||
import type { TType } from './logical/typesystem';
|
||||
import { typesystem } from './logical/typesystem';
|
||||
import type { Literal } from './shared-types';
|
||||
|
||||
export const literalMatcher = new Matcher<{
|
||||
render: (props: {
|
||||
|
||||
@@ -1,34 +1,14 @@
|
||||
import type { Literal, LiteralValue, VariableMap } from '@affine/env/filter';
|
||||
import { DateTimeIcon, FavoritedIcon } from '@blocksuite/icons';
|
||||
import type { ReactElement } from 'react';
|
||||
|
||||
import { tBoolean, tDate } from './logical/custom-type';
|
||||
import type { TType } from './logical/typesystem';
|
||||
|
||||
export type Ref = {
|
||||
type: 'ref';
|
||||
name: keyof VariableMap;
|
||||
};
|
||||
|
||||
export type Filter = {
|
||||
type: 'filter';
|
||||
left: Ref;
|
||||
funcName: string;
|
||||
args: Literal[];
|
||||
};
|
||||
export type LiteralValue =
|
||||
| number
|
||||
| string
|
||||
| boolean
|
||||
| { [K: string]: LiteralValue }
|
||||
| Array<LiteralValue>;
|
||||
export const toLiteral = (value: LiteralValue): Literal => ({
|
||||
type: 'literal',
|
||||
value,
|
||||
});
|
||||
export type Literal = {
|
||||
type: 'literal';
|
||||
value: LiteralValue;
|
||||
};
|
||||
|
||||
export type FilterVariable = {
|
||||
name: keyof VariableMap;
|
||||
@@ -56,11 +36,12 @@ export const variableDefineMap = {
|
||||
// type: tBoolean.create(),
|
||||
// },
|
||||
} as const;
|
||||
export type VariableMap = {
|
||||
|
||||
export type InternalVariableMap = {
|
||||
[K in keyof typeof variableDefineMap]: LiteralValue;
|
||||
};
|
||||
export type View = {
|
||||
id: string;
|
||||
name: string;
|
||||
filterList: Filter[];
|
||||
};
|
||||
|
||||
declare module '@affine/env/filter' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface VariableMap extends InternalVariableMap {}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Filter, LiteralValue, VariableMap } from '@affine/env/filter';
|
||||
import dayjs from 'dayjs';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
@@ -7,12 +8,7 @@ import { tBoolean, tDate } from './logical/custom-type';
|
||||
import { Matcher } from './logical/matcher';
|
||||
import type { TFunction } from './logical/typesystem';
|
||||
import { tFunction, typesystem } from './logical/typesystem';
|
||||
import type {
|
||||
Filter,
|
||||
FilterVariable,
|
||||
LiteralValue,
|
||||
VariableMap,
|
||||
} from './shared-types';
|
||||
import type { FilterVariable } from './shared-types';
|
||||
import { variableDefineMap } from './shared-types';
|
||||
|
||||
export const vars: FilterVariable[] = Object.entries(variableDefineMap).map(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { Filter, VariableMap, View } from '@affine/env/filter';
|
||||
import type { DBSchema } from 'idb';
|
||||
import { openDB } from 'idb';
|
||||
import type { IDBPDatabase } from 'idb/build/entry';
|
||||
@@ -8,7 +9,6 @@ import useSWRImmutable from 'swr/immutable';
|
||||
import { NIL } from 'uuid';
|
||||
|
||||
import { evalFilterList } from './filter';
|
||||
import type { Filter, VariableMap, View } from './filter/shared-types';
|
||||
|
||||
type PersistenceView = View;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { Filter, View } from '@affine/env/filter';
|
||||
import { SaveIcon } from '@blocksuite/icons';
|
||||
import { uuidv4 } from '@blocksuite/store';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { Button, Input, Modal, ModalWrapper } from '../../..';
|
||||
import { FilterList } from '../filter';
|
||||
import type { Filter, View } from '../filter/shared-types';
|
||||
import * as styles from './view-list.css';
|
||||
|
||||
type CreateViewProps = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type {
|
||||
AffineLegacyCloudWorkspace,
|
||||
LocalWorkspace,
|
||||
} from '@affine/workspace/type';
|
||||
} from '@affine/env/workspace';
|
||||
import { ExportIcon, PublishIcon, ShareIcon } from '@blocksuite/icons';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { prefixUrl } from '@affine/env';
|
||||
import type { LocalWorkspace } from '@affine/env/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { Trans } from '@affine/i18n';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import type { LocalWorkspace } from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { useBlockSuiteWorkspacePageIsPublic } from '@toeverything/hooks/use-block-suite-workspace-page-is-public';
|
||||
import type { FC } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import type {
|
||||
AffineLegacyCloudWorkspace,
|
||||
LocalWorkspace,
|
||||
} from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
} from '@affine/env/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import type { FC } from 'react';
|
||||
|
||||
import { descriptionStyle, menuItemStyle } from './index.css';
|
||||
|
||||
@@ -2,7 +2,7 @@ import type {
|
||||
AffineLegacyCloudWorkspace,
|
||||
AffinePublicWorkspace,
|
||||
LocalWorkspace,
|
||||
} from '@affine/workspace/type';
|
||||
} from '@affine/env/workspace';
|
||||
import type { Workspace } from '@blocksuite/store';
|
||||
import * as RadixAvatar from '@radix-ui/react-avatar';
|
||||
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type {
|
||||
AffineLegacyCloudWorkspace,
|
||||
LocalWorkspace,
|
||||
} from '@affine/workspace/type';
|
||||
} from '@affine/env/workspace';
|
||||
import type { DragEndEvent } from '@dnd-kit/core';
|
||||
import {
|
||||
DndContext,
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"exclude": [
|
||||
"lib",
|
||||
"./src/components/page-list/filter/shared-types.tsx",
|
||||
"./src/components/page-list/filter/logic/custom-type.ts",
|
||||
"./src/components/page-list/filter/logic/matcher.ts",
|
||||
"./src/components/page-list/filter/logic/typesystem.ts"
|
||||
],
|
||||
"exclude": ["lib"],
|
||||
"include": ["./src/**/*", "./src/**/*.json"],
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
@@ -30,7 +24,6 @@
|
||||
{
|
||||
"path": "../../apps/electron"
|
||||
},
|
||||
{ "path": "./tsconfig.workspace.json" },
|
||||
{ "path": "../../tests/fixtures" }
|
||||
]
|
||||
}
|
||||
|
||||
3
packages/env/package.json
vendored
3
packages/env/package.json
vendored
@@ -15,6 +15,9 @@
|
||||
".": "./src/index.ts",
|
||||
"./config": "./src/config.ts",
|
||||
"./constant": "./src/constant.ts",
|
||||
"./workspace": "./src/workspace.ts",
|
||||
"./workspace/legacy-cloud": "./src/workspace/legacy-cloud/index.ts",
|
||||
"./filter": "./src/filter.ts",
|
||||
"./blocksuite": "./src/blocksuite/index.ts"
|
||||
},
|
||||
"peerDependencies": {
|
||||
|
||||
32
packages/env/src/filter.ts
vendored
Normal file
32
packages/env/src/filter.ts
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
export type LiteralValue =
|
||||
| number
|
||||
| string
|
||||
| boolean
|
||||
| { [K: string]: LiteralValue }
|
||||
| Array<LiteralValue>;
|
||||
|
||||
export type Ref = {
|
||||
type: 'ref';
|
||||
name: keyof VariableMap;
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
export interface VariableMap {}
|
||||
|
||||
export type Literal = {
|
||||
type: 'literal';
|
||||
value: LiteralValue;
|
||||
};
|
||||
|
||||
export type Filter = {
|
||||
type: 'filter';
|
||||
left: Ref;
|
||||
funcName: string;
|
||||
args: Literal[];
|
||||
};
|
||||
|
||||
export type View = {
|
||||
id: string;
|
||||
name: string;
|
||||
filterList: Filter[];
|
||||
};
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { View } from '@affine/component/page-list/filter/shared-types';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import type { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import type { FC, PropsWithChildren } from 'react';
|
||||
|
||||
import type { Workspace as RemoteWorkspace } from './affine/api';
|
||||
import type { View } from './filter';
|
||||
import type { Workspace as RemoteWorkspace } from './workspace/legacy-cloud';
|
||||
|
||||
export enum WorkspaceSubPath {
|
||||
ALL = 'all',
|
||||
129
packages/env/src/workspace/legacy-cloud/index.ts
vendored
Normal file
129
packages/env/src/workspace/legacy-cloud/index.ts
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar_url: string;
|
||||
create_at: string;
|
||||
}
|
||||
|
||||
export interface GetUserByEmailParams {
|
||||
email: string;
|
||||
workspace_id: string;
|
||||
}
|
||||
|
||||
export const usageResponseSchema = z.object({
|
||||
blob_usage: z.object({
|
||||
usage: z.number(),
|
||||
max_usage: z.number(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type UsageResponse = z.infer<typeof usageResponseSchema>;
|
||||
|
||||
export interface GetWorkspaceDetailParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export enum WorkspaceType {
|
||||
Private = 0,
|
||||
Normal = 1,
|
||||
}
|
||||
|
||||
export enum PermissionType {
|
||||
Read = 0,
|
||||
Write = 1,
|
||||
Admin = 10,
|
||||
Owner = 99,
|
||||
}
|
||||
|
||||
export const userSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
avatar_url: z.string(),
|
||||
created_at: z.number(),
|
||||
});
|
||||
|
||||
export const workspaceSchema = z.object({
|
||||
id: z.string(),
|
||||
type: z.nativeEnum(WorkspaceType),
|
||||
public: z.boolean(),
|
||||
permission: z.nativeEnum(PermissionType),
|
||||
});
|
||||
|
||||
export type Workspace = z.infer<typeof workspaceSchema>;
|
||||
|
||||
export const workspaceDetailSchema = z.object({
|
||||
...workspaceSchema.shape,
|
||||
permission: z.undefined(),
|
||||
owner: userSchema,
|
||||
member_count: z.number(),
|
||||
});
|
||||
|
||||
export type WorkspaceDetail = z.infer<typeof workspaceDetailSchema>;
|
||||
|
||||
export interface Permission {
|
||||
id: string;
|
||||
type: PermissionType;
|
||||
workspace_id: string;
|
||||
user_id: string;
|
||||
user_email: string;
|
||||
accepted: boolean;
|
||||
create_at: number;
|
||||
}
|
||||
|
||||
export interface RegisteredUser extends User {
|
||||
type: 'Registered';
|
||||
}
|
||||
|
||||
export interface UnregisteredUser {
|
||||
type: 'Unregistered';
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface Member extends Permission {
|
||||
user: RegisteredUser | UnregisteredUser;
|
||||
}
|
||||
|
||||
export interface GetWorkspaceMembersParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface CreateWorkspaceParams {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface UpdateWorkspaceParams {
|
||||
id: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
export interface DeleteWorkspaceParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface InviteMemberParams {
|
||||
id: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface RemoveMemberParams {
|
||||
permissionId: number;
|
||||
}
|
||||
|
||||
export interface AcceptInvitingParams {
|
||||
invitingCode: string;
|
||||
}
|
||||
|
||||
export interface LeaveWorkspaceParams {
|
||||
id: number | string;
|
||||
}
|
||||
|
||||
export const createWorkspaceResponseSchema = z.object({
|
||||
id: z.string(),
|
||||
public: z.boolean(),
|
||||
type: z.nativeEnum(WorkspaceType),
|
||||
created_at: z.number(),
|
||||
});
|
||||
@@ -3,7 +3,6 @@
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"dependencies": {
|
||||
"@affine/env": "workspace:*",
|
||||
"jotai": "^2.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { env } from '@affine/env';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import { atom } from 'jotai';
|
||||
|
||||
export const lottieAtom = atom(import('lottie-web').then(m => m.default));
|
||||
|
||||
export const editorContainerModuleAtom = atom<Promise<typeof EditorContainer>>(
|
||||
env.isServer
|
||||
typeof window === 'undefined'
|
||||
? async () =>
|
||||
import('@blocksuite/editor').then(module => module.EditorContainer)
|
||||
: (import('@blocksuite/editor').then(
|
||||
|
||||
@@ -5,6 +5,5 @@
|
||||
"composite": true,
|
||||
"noEmit": false,
|
||||
"outDir": "lib"
|
||||
},
|
||||
"references": [{ "path": "../env" }]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { toast } from '@affine/component';
|
||||
import { BlockCard } from '@affine/component/card/block-card';
|
||||
import { WorkspaceCard } from '@affine/component/card/workspace-card';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { EdgelessIcon, PageIcon } from '@blocksuite/icons';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BlockSuiteEditor } from '@affine/component/block-suite-editor';
|
||||
import { ImagePreviewModal } from '@affine/component/image-preview-modal';
|
||||
import { initEmptyPage } from '@affine/env/blocksuite';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
|
||||
import type { Meta } from '@storybook/react';
|
||||
|
||||
|
||||
@@ -2,12 +2,15 @@ import { toast } from '@affine/component';
|
||||
import { PublicLinkDisableModal } from '@affine/component/share-menu/disable-public-link';
|
||||
import { ShareMenu } from '@affine/component/share-menu/share-menu';
|
||||
import { StyledDisableButton } from '@affine/component/share-menu/styles';
|
||||
import { PermissionType, WorkspaceType } from '@affine/workspace/affine/api';
|
||||
import type {
|
||||
AffineLegacyCloudWorkspace,
|
||||
LocalWorkspace,
|
||||
} from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
} from '@affine/env/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import {
|
||||
PermissionType,
|
||||
WorkspaceType,
|
||||
} from '@affine/env/workspace/legacy-cloud';
|
||||
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { expect } from '@storybook/jest';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { WorkspaceAvatarProps } from '@affine/component/workspace-avatar';
|
||||
import { WorkspaceAvatar } from '@affine/component/workspace-avatar';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import type { Meta, StoryFn } from '@storybook/react';
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { WorkspaceListProps } from '@affine/component/workspace-list';
|
||||
import { WorkspaceList } from '@affine/component/workspace-list';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
|
||||
import { arrayMove } from '@dnd-kit/sortable';
|
||||
import type { Meta } from '@storybook/react';
|
||||
|
||||
@@ -6,6 +6,11 @@ import 'fake-indexeddb/auto';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
import { MessageCode } from '@affine/env/constant';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import {
|
||||
createWorkspaceResponseSchema,
|
||||
usageResponseSchema,
|
||||
} from '@affine/env/workspace/legacy-cloud';
|
||||
import user1 from '@affine-test/fixtures/built-in-user1.json';
|
||||
import user2 from '@affine-test/fixtures/built-in-user2.json';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
@@ -17,15 +22,8 @@ import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
import { WebSocket } from 'ws';
|
||||
import { applyUpdate } from 'yjs';
|
||||
|
||||
import { WorkspaceFlavour } from '../../type';
|
||||
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
||||
import {
|
||||
createUserApis,
|
||||
createWorkspaceApis,
|
||||
createWorkspaceResponseSchema,
|
||||
RequestError,
|
||||
usageResponseSchema,
|
||||
} from '../api';
|
||||
import { createUserApis, createWorkspaceApis, RequestError } from '../api';
|
||||
import { createStatusApis } from '../api/status';
|
||||
import { KeckProvider } from '../keck';
|
||||
import {
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
*/
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import type { Workspace } from '@affine/env/workspace/legacy-cloud';
|
||||
import { PermissionType } from '@affine/env/workspace/legacy-cloud';
|
||||
import user1 from '@affine-test/fixtures/built-in-user1.json';
|
||||
import user2 from '@affine-test/fixtures/built-in-user2.json';
|
||||
import type { ParagraphBlockModel } from '@blocksuite/blocks/models';
|
||||
@@ -13,10 +16,8 @@ import { WebSocket } from 'ws';
|
||||
|
||||
import type { LoginResponse } from '../../affine/login';
|
||||
import { loginResponseSchema } from '../../affine/login';
|
||||
import { WorkspaceFlavour } from '../../type';
|
||||
import { createEmptyBlockSuiteWorkspace } from '../../utils';
|
||||
import type { Workspace } from '../api';
|
||||
import { createWorkspaceApis, PermissionType } from '../api';
|
||||
import { createWorkspaceApis } from '../api';
|
||||
import { KeckProvider } from '../keck';
|
||||
|
||||
declare module '@blocksuite/store' {
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
import { MessageCode, Messages } from '@affine/env';
|
||||
import { z } from 'zod';
|
||||
import type {
|
||||
AcceptInvitingParams,
|
||||
DeleteWorkspaceParams,
|
||||
GetUserByEmailParams,
|
||||
GetWorkspaceDetailParams,
|
||||
InviteMemberParams,
|
||||
LeaveWorkspaceParams,
|
||||
Member,
|
||||
Permission,
|
||||
RemoveMemberParams,
|
||||
UpdateWorkspaceParams,
|
||||
UsageResponse,
|
||||
User,
|
||||
Workspace,
|
||||
WorkspaceDetail,
|
||||
} from '@affine/env/workspace/legacy-cloud';
|
||||
|
||||
import { checkLoginStorage } from '../login';
|
||||
|
||||
@@ -28,28 +43,6 @@ function sendMessage(code: (typeof MessageCode)[keyof typeof MessageCode]) {
|
||||
);
|
||||
}
|
||||
|
||||
export interface User {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
avatar_url: string;
|
||||
create_at: string;
|
||||
}
|
||||
|
||||
export interface GetUserByEmailParams {
|
||||
email: string;
|
||||
workspace_id: string;
|
||||
}
|
||||
|
||||
export const usageResponseSchema = z.object({
|
||||
blob_usage: z.object({
|
||||
usage: z.number(),
|
||||
max_usage: z.number(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type UsageResponse = z.infer<typeof usageResponseSchema>;
|
||||
|
||||
export function createUserApis(prefixUrl = '/') {
|
||||
return {
|
||||
getUsage: async (): Promise<UsageResponse> => {
|
||||
@@ -78,112 +71,6 @@ export function createUserApis(prefixUrl = '/') {
|
||||
} as const;
|
||||
}
|
||||
|
||||
export interface GetWorkspaceDetailParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export enum WorkspaceType {
|
||||
Private = 0,
|
||||
Normal = 1,
|
||||
}
|
||||
|
||||
export enum PermissionType {
|
||||
Read = 0,
|
||||
Write = 1,
|
||||
Admin = 10,
|
||||
Owner = 99,
|
||||
}
|
||||
|
||||
export const userSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
email: z.string(),
|
||||
avatar_url: z.string(),
|
||||
created_at: z.number(),
|
||||
});
|
||||
|
||||
export const workspaceSchema = z.object({
|
||||
id: z.string(),
|
||||
type: z.nativeEnum(WorkspaceType),
|
||||
public: z.boolean(),
|
||||
permission: z.nativeEnum(PermissionType),
|
||||
});
|
||||
|
||||
export type Workspace = z.infer<typeof workspaceSchema>;
|
||||
|
||||
export const workspaceDetailSchema = z.object({
|
||||
...workspaceSchema.shape,
|
||||
permission: z.undefined(),
|
||||
owner: userSchema,
|
||||
member_count: z.number(),
|
||||
});
|
||||
|
||||
export type WorkspaceDetail = z.infer<typeof workspaceDetailSchema>;
|
||||
|
||||
export interface Permission {
|
||||
id: string;
|
||||
type: PermissionType;
|
||||
workspace_id: string;
|
||||
user_id: string;
|
||||
user_email: string;
|
||||
accepted: boolean;
|
||||
create_at: number;
|
||||
}
|
||||
|
||||
export interface RegisteredUser extends User {
|
||||
type: 'Registered';
|
||||
}
|
||||
|
||||
export interface UnregisteredUser {
|
||||
type: 'Unregistered';
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface Member extends Permission {
|
||||
user: RegisteredUser | UnregisteredUser;
|
||||
}
|
||||
|
||||
export interface GetWorkspaceMembersParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface CreateWorkspaceParams {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface UpdateWorkspaceParams {
|
||||
id: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
export interface DeleteWorkspaceParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
export interface InviteMemberParams {
|
||||
id: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface RemoveMemberParams {
|
||||
permissionId: number;
|
||||
}
|
||||
|
||||
export interface AcceptInvitingParams {
|
||||
invitingCode: string;
|
||||
}
|
||||
|
||||
export interface LeaveWorkspaceParams {
|
||||
id: number | string;
|
||||
}
|
||||
|
||||
export const createWorkspaceResponseSchema = z.object({
|
||||
id: z.string(),
|
||||
public: z.boolean(),
|
||||
type: z.nativeEnum(WorkspaceType),
|
||||
created_at: z.number(),
|
||||
});
|
||||
|
||||
export function createWorkspaceApis(prefixUrl = '/') {
|
||||
return {
|
||||
getWorkspaces: async (): Promise<Workspace[]> => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import * as url from 'lib0/url';
|
||||
import * as websocket from 'lib0/websocket';
|
||||
|
||||
import { getLoginStorage, isExpired, parseIdToken } from '../affine/login';
|
||||
import { WorkspaceFlavour } from '../type';
|
||||
import { cleanupWorkspace } from '../utils';
|
||||
|
||||
const RECONNECT_INTERVAL_TIME = 500;
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { websocketPrefixUrl } from '@affine/env/api';
|
||||
import type { WorkspaceCRUD } from '@affine/env/workspace';
|
||||
import type { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import {
|
||||
workspaceDetailSchema,
|
||||
workspaceSchema,
|
||||
} from '@affine/env/workspace/legacy-cloud';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import type { Disposable } from '@blocksuite/store';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { workspaceDetailSchema, workspaceSchema } from '../affine/api';
|
||||
import { WebsocketClient } from '../affine/channel';
|
||||
import { storageChangeSlot } from '../affine/login';
|
||||
import { rootStore, rootWorkspacesMetadataAtom } from '../atom';
|
||||
import type { WorkspaceCRUD } from '../type';
|
||||
import type { WorkspaceFlavour } from '../type';
|
||||
|
||||
const logger = new DebugLogger('affine-sync');
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import type { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import { atom, createStore } from 'jotai';
|
||||
import { atomWithStorage, createJSONStorage } from 'jotai/utils';
|
||||
import Router from 'next/router';
|
||||
|
||||
import type { WorkspaceFlavour } from './type';
|
||||
|
||||
export type RootWorkspaceMetadata = {
|
||||
id: string;
|
||||
flavour: WorkspaceFlavour;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
*/
|
||||
import 'fake-indexeddb/auto';
|
||||
|
||||
import type { LocalWorkspace, WorkspaceCRUD } from '@affine/env/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import { Workspace } from '@blocksuite/store';
|
||||
import { afterEach, assertType, describe, expect, test } from 'vitest';
|
||||
|
||||
import type { LocalWorkspace, WorkspaceCRUD } from '../../type';
|
||||
import { WorkspaceFlavour } from '../../type';
|
||||
import { CRUD } from '../crud';
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { LocalWorkspace, WorkspaceCRUD } from '@affine/env/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { nanoid, Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { createIndexedDBProvider } from '@toeverything/y-indexeddb';
|
||||
import { createJSONStorage } from 'jotai/utils';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createLocalProviders } from '../providers';
|
||||
import type { LocalWorkspace, WorkspaceCRUD } from '../type';
|
||||
import { WorkspaceFlavour } from '../type';
|
||||
import { createEmptyBlockSuiteWorkspace } from '../utils';
|
||||
|
||||
const getStorage = () => createJSONStorage(() => localStorage);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import type {
|
||||
SQLiteDBDownloadProvider,
|
||||
SQLiteProvider,
|
||||
} from '@affine/env/workspace';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import type { Y as YType } from '@blocksuite/store';
|
||||
import { uuidv4, Workspace } from '@blocksuite/store';
|
||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import type { SQLiteDBDownloadProvider, SQLiteProvider } from '../../type';
|
||||
import { createSQLiteDBDownloadProvider, createSQLiteProvider } from '../index';
|
||||
|
||||
const Y = Workspace.Y;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { AffineDownloadProvider } from '@affine/env/workspace';
|
||||
import { assertExists, Workspace } from '@blocksuite/store';
|
||||
|
||||
import { affineApis } from '../affine/shared';
|
||||
import type { AffineDownloadProvider } from '../type';
|
||||
|
||||
const hashMap = new Map<string, ArrayBuffer>();
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { BroadCastChannelProvider } from '@affine/env/workspace';
|
||||
import { Workspace as BlockSuiteWorkspace } from '@blocksuite/store';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import type { Awareness } from 'y-protocols/awareness';
|
||||
@@ -6,7 +7,6 @@ import {
|
||||
encodeAwarenessUpdate,
|
||||
} from 'y-protocols/awareness';
|
||||
|
||||
import type { BroadCastChannelProvider } from '../../type';
|
||||
import { CallbackSet } from '../../utils';
|
||||
import { localProviderLogger } from '../logger';
|
||||
import type {
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
import { config, websocketPrefixUrl } from '@affine/env';
|
||||
import type {
|
||||
AffineWebSocketProvider,
|
||||
LocalIndexedDBBackgroundProvider,
|
||||
LocalIndexedDBDownloadProvider,
|
||||
Provider,
|
||||
SQLiteDBDownloadProvider,
|
||||
SQLiteProvider,
|
||||
} from '@affine/env/workspace';
|
||||
import type { BlobManager, Disposable } from '@blocksuite/store';
|
||||
import {
|
||||
assertExists,
|
||||
@@ -12,14 +20,6 @@ import {
|
||||
|
||||
import { KeckProvider } from '../affine/keck';
|
||||
import { getLoginStorage, storageChangeSlot } from '../affine/login';
|
||||
import type {
|
||||
AffineWebSocketProvider,
|
||||
LocalIndexedDBBackgroundProvider,
|
||||
LocalIndexedDBDownloadProvider,
|
||||
Provider,
|
||||
SQLiteDBDownloadProvider,
|
||||
SQLiteProvider,
|
||||
} from '../type';
|
||||
import { CallbackSet } from '../utils';
|
||||
import { createAffineDownloadProvider } from './affine-download';
|
||||
import { createBroadCastChannelProvider } from './broad-cast-channel';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { __unstableSchemas, AffineSchemas } from '@blocksuite/blocks/models';
|
||||
import type { Generator, StoreOptions } from '@blocksuite/store';
|
||||
import { createIndexeddbStorage, Workspace } from '@blocksuite/store';
|
||||
@@ -6,7 +7,6 @@ import type { createWorkspaceApis } from './affine/api';
|
||||
import { rootStore, rootWorkspacesMetadataAtom } from './atom';
|
||||
import { createAffineBlobStorage } from './blob';
|
||||
import { createSQLiteStorage } from './blob/sqlite-blob-storage';
|
||||
import { WorkspaceFlavour } from './type';
|
||||
|
||||
export function cleanupWorkspace(flavour: WorkspaceFlavour) {
|
||||
rootStore.set(rootWorkspacesMetadataAtom, metas =>
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
{ "path": "../env" },
|
||||
{ "path": "../debug" },
|
||||
{ "path": "../hooks" },
|
||||
{ "path": "../component/tsconfig.workspace.json" },
|
||||
{ "path": "../../apps/electron" }
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user