feat(server): make server storage adapters (#7902)

This commit is contained in:
forehalo
2024-08-21 05:30:26 +00:00
parent 6f9f579e5d
commit e20bdbf925
29 changed files with 1987 additions and 2111 deletions
@@ -306,45 +306,49 @@ export const USER_FRIENDLY_ERRORS = {
message: 'You must verify your email before accessing this resource.',
},
// Workspace & Doc & Sync errors
workspace_not_found: {
// Workspace & Userspace & Doc & Sync errors
space_not_found: {
type: 'resource_not_found',
args: { workspaceId: 'string' },
message: ({ workspaceId }) => `Workspace ${workspaceId} not found.`,
args: { spaceId: 'string' },
message: ({ spaceId }) => `Space ${spaceId} not found.`,
},
not_in_workspace: {
not_in_space: {
type: 'action_forbidden',
args: { workspaceId: 'string' },
message: ({ workspaceId }) =>
`You should join in workspace ${workspaceId} before broadcasting messages.`,
args: { spaceId: 'string' },
message: ({ spaceId }) =>
`You should join in Space ${spaceId} before broadcasting messages.`,
},
workspace_access_denied: {
already_in_space: {
type: 'action_forbidden',
args: { spaceId: 'string' },
message: ({ spaceId }) => `You have already joined in Space ${spaceId}.`,
},
space_access_denied: {
type: 'no_permission',
args: { workspaceId: 'string' },
message: ({ workspaceId }) =>
`You do not have permission to access workspace ${workspaceId}.`,
args: { spaceId: 'string' },
message: ({ spaceId }) =>
`You do not have permission to access Space ${spaceId}.`,
},
workspace_owner_not_found: {
space_owner_not_found: {
type: 'internal_server_error',
args: { workspaceId: 'string' },
message: ({ workspaceId }) =>
`Owner of workspace ${workspaceId} not found.`,
args: { spaceId: 'string' },
message: ({ spaceId }) => `Owner of Space ${spaceId} not found.`,
},
cant_change_workspace_owner: {
cant_change_space_owner: {
type: 'action_forbidden',
message: 'You are not allowed to change the owner of a workspace.',
message: 'You are not allowed to change the owner of a Space.',
},
doc_not_found: {
type: 'resource_not_found',
args: { workspaceId: 'string', docId: 'string' },
message: ({ workspaceId, docId }) =>
`Doc ${docId} under workspace ${workspaceId} not found.`,
args: { spaceId: 'string', docId: 'string' },
message: ({ spaceId, docId }) =>
`Doc ${docId} under Space ${spaceId} not found.`,
},
doc_access_denied: {
type: 'no_permission',
args: { workspaceId: 'string', docId: 'string' },
message: ({ workspaceId, docId }) =>
`You do not have permission to access doc ${docId} under workspace ${workspaceId}.`,
args: { spaceId: 'string', docId: 'string' },
message: ({ spaceId, docId }) =>
`You do not have permission to access doc ${docId} under Space ${spaceId}.`,
},
version_rejected: {
type: 'action_forbidden',
@@ -359,28 +363,36 @@ export const USER_FRIENDLY_ERRORS = {
},
doc_history_not_found: {
type: 'resource_not_found',
args: { workspaceId: 'string', docId: 'string', timestamp: 'number' },
message: ({ workspaceId, docId, timestamp }) =>
`History of ${docId} at ${timestamp} under workspace ${workspaceId}.`,
args: { spaceId: 'string', docId: 'string', timestamp: 'number' },
message: ({ spaceId, docId, timestamp }) =>
`History of ${docId} at ${timestamp} under Space ${spaceId}.`,
},
blob_not_found: {
type: 'resource_not_found',
args: { workspaceId: 'string', blobId: 'string' },
message: ({ workspaceId, blobId }) =>
`Blob ${blobId} not found in workspace ${workspaceId}.`,
args: { spaceId: 'string', blobId: 'string' },
message: ({ spaceId, blobId }) =>
`Blob ${blobId} not found in Space ${spaceId}.`,
},
expect_to_publish_page: {
type: 'invalid_input',
message: 'Expected to publish a page, not a workspace.',
message: 'Expected to publish a page, not a Space.',
},
expect_to_revoke_public_page: {
type: 'invalid_input',
message: 'Expected to revoke a public page, not a workspace.',
message: 'Expected to revoke a public page, not a Space.',
},
page_is_not_public: {
type: 'bad_request',
message: 'Page is not public.',
},
failed_to_save_updates: {
type: 'internal_server_error',
message: 'Failed to store doc updates.',
},
failed_to_upsert_snapshot: {
type: 'internal_server_error',
message: 'Failed to store doc snapshot.',
},
// Subscription Errors
failed_to_checkout: {
@@ -173,54 +173,64 @@ export class EmailVerificationRequired extends UserFriendlyError {
}
}
@ObjectType()
class WorkspaceNotFoundDataType {
@Field() workspaceId!: string
class SpaceNotFoundDataType {
@Field() spaceId!: string
}
export class WorkspaceNotFound extends UserFriendlyError {
constructor(args: WorkspaceNotFoundDataType, message?: string | ((args: WorkspaceNotFoundDataType) => string)) {
super('resource_not_found', 'workspace_not_found', message, args);
export class SpaceNotFound extends UserFriendlyError {
constructor(args: SpaceNotFoundDataType, message?: string | ((args: SpaceNotFoundDataType) => string)) {
super('resource_not_found', 'space_not_found', message, args);
}
}
@ObjectType()
class NotInWorkspaceDataType {
@Field() workspaceId!: string
class NotInSpaceDataType {
@Field() spaceId!: string
}
export class NotInWorkspace extends UserFriendlyError {
constructor(args: NotInWorkspaceDataType, message?: string | ((args: NotInWorkspaceDataType) => string)) {
super('action_forbidden', 'not_in_workspace', message, args);
export class NotInSpace extends UserFriendlyError {
constructor(args: NotInSpaceDataType, message?: string | ((args: NotInSpaceDataType) => string)) {
super('action_forbidden', 'not_in_space', message, args);
}
}
@ObjectType()
class WorkspaceAccessDeniedDataType {
@Field() workspaceId!: string
class AlreadyInSpaceDataType {
@Field() spaceId!: string
}
export class WorkspaceAccessDenied extends UserFriendlyError {
constructor(args: WorkspaceAccessDeniedDataType, message?: string | ((args: WorkspaceAccessDeniedDataType) => string)) {
super('no_permission', 'workspace_access_denied', message, args);
export class AlreadyInSpace extends UserFriendlyError {
constructor(args: AlreadyInSpaceDataType, message?: string | ((args: AlreadyInSpaceDataType) => string)) {
super('action_forbidden', 'already_in_space', message, args);
}
}
@ObjectType()
class WorkspaceOwnerNotFoundDataType {
@Field() workspaceId!: string
class SpaceAccessDeniedDataType {
@Field() spaceId!: string
}
export class WorkspaceOwnerNotFound extends UserFriendlyError {
constructor(args: WorkspaceOwnerNotFoundDataType, message?: string | ((args: WorkspaceOwnerNotFoundDataType) => string)) {
super('internal_server_error', 'workspace_owner_not_found', message, args);
export class SpaceAccessDenied extends UserFriendlyError {
constructor(args: SpaceAccessDeniedDataType, message?: string | ((args: SpaceAccessDeniedDataType) => string)) {
super('no_permission', 'space_access_denied', message, args);
}
}
@ObjectType()
class SpaceOwnerNotFoundDataType {
@Field() spaceId!: string
}
export class SpaceOwnerNotFound extends UserFriendlyError {
constructor(args: SpaceOwnerNotFoundDataType, message?: string | ((args: SpaceOwnerNotFoundDataType) => string)) {
super('internal_server_error', 'space_owner_not_found', message, args);
}
}
export class CantChangeWorkspaceOwner extends UserFriendlyError {
export class CantChangeSpaceOwner extends UserFriendlyError {
constructor(message?: string) {
super('action_forbidden', 'cant_change_workspace_owner', message);
super('action_forbidden', 'cant_change_space_owner', message);
}
}
@ObjectType()
class DocNotFoundDataType {
@Field() workspaceId!: string
@Field() spaceId!: string
@Field() docId!: string
}
@@ -231,7 +241,7 @@ export class DocNotFound extends UserFriendlyError {
}
@ObjectType()
class DocAccessDeniedDataType {
@Field() workspaceId!: string
@Field() spaceId!: string
@Field() docId!: string
}
@@ -263,7 +273,7 @@ export class InvalidHistoryTimestamp extends UserFriendlyError {
}
@ObjectType()
class DocHistoryNotFoundDataType {
@Field() workspaceId!: string
@Field() spaceId!: string
@Field() docId!: string
@Field() timestamp!: number
}
@@ -275,7 +285,7 @@ export class DocHistoryNotFound extends UserFriendlyError {
}
@ObjectType()
class BlobNotFoundDataType {
@Field() workspaceId!: string
@Field() spaceId!: string
@Field() blobId!: string
}
@@ -303,6 +313,18 @@ export class PageIsNotPublic extends UserFriendlyError {
}
}
export class FailedToSaveUpdates extends UserFriendlyError {
constructor(message?: string) {
super('internal_server_error', 'failed_to_save_updates', message);
}
}
export class FailedToUpsertSnapshot extends UserFriendlyError {
constructor(message?: string) {
super('internal_server_error', 'failed_to_upsert_snapshot', message);
}
}
export class FailedToCheckout extends UserFriendlyError {
constructor(message?: string) {
super('internal_server_error', 'failed_to_checkout', message);
@@ -538,11 +560,12 @@ export enum ErrorNames {
ACTION_FORBIDDEN,
ACCESS_DENIED,
EMAIL_VERIFICATION_REQUIRED,
WORKSPACE_NOT_FOUND,
NOT_IN_WORKSPACE,
WORKSPACE_ACCESS_DENIED,
WORKSPACE_OWNER_NOT_FOUND,
CANT_CHANGE_WORKSPACE_OWNER,
SPACE_NOT_FOUND,
NOT_IN_SPACE,
ALREADY_IN_SPACE,
SPACE_ACCESS_DENIED,
SPACE_OWNER_NOT_FOUND,
CANT_CHANGE_SPACE_OWNER,
DOC_NOT_FOUND,
DOC_ACCESS_DENIED,
VERSION_REJECTED,
@@ -552,6 +575,8 @@ export enum ErrorNames {
EXPECT_TO_PUBLISH_PAGE,
EXPECT_TO_REVOKE_PUBLIC_PAGE,
PAGE_IS_NOT_PUBLIC,
FAILED_TO_SAVE_UPDATES,
FAILED_TO_UPSERT_SNAPSHOT,
FAILED_TO_CHECKOUT,
SUBSCRIPTION_ALREADY_EXISTS,
SUBSCRIPTION_NOT_EXISTS,
@@ -588,5 +613,5 @@ registerEnumType(ErrorNames, {
export const ErrorDataUnionType = createUnionType({
name: 'ErrorDataUnion',
types: () =>
[UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidPasswordLengthDataType, WorkspaceNotFoundDataType, NotInWorkspaceDataType, WorkspaceAccessDeniedDataType, WorkspaceOwnerNotFoundDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType] as const,
[UnknownOauthProviderDataType, MissingOauthQueryParameterDataType, InvalidPasswordLengthDataType, SpaceNotFoundDataType, NotInSpaceDataType, AlreadyInSpaceDataType, SpaceAccessDeniedDataType, SpaceOwnerNotFoundDataType, DocNotFoundDataType, DocAccessDeniedDataType, VersionRejectedDataType, InvalidHistoryTimestampDataType, DocHistoryNotFoundDataType, BlobNotFoundDataType, SubscriptionAlreadyExistsDataType, SubscriptionNotExistsDataType, SameSubscriptionRecurringDataType, SubscriptionPlanNotFoundDataType, CopilotMessageNotFoundDataType, CopilotPromptNotFoundDataType, CopilotProviderSideErrorDataType, RuntimeConfigNotFoundDataType, InvalidRuntimeConfigTypeDataType] as const,
});