diff --git a/package.json b/package.json index fc82c5509..1f8ef9fa3 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "husky": "^9.1.7", "lint-staged": "^15.2.11", "msw": "^2.6.8", - "oxlint": "0.16.8", + "oxlint": "0.16.9", "prettier": "^3.4.2", "semver": "^7.6.3", "serve": "^14.2.4", diff --git a/packages/backend/server/src/plugins/copilot/providers/types.ts b/packages/backend/server/src/plugins/copilot/providers/types.ts index 2a23ffb19..f83609a44 100644 --- a/packages/backend/server/src/plugins/copilot/providers/types.ts +++ b/packages/backend/server/src/plugins/copilot/providers/types.ts @@ -76,7 +76,7 @@ const CopilotProviderOptionsSchema = z.object({ user: z.string().optional(), }); -const CopilotChatOptionsSchema = CopilotProviderOptionsSchema.merge( +export const CopilotChatOptionsSchema = CopilotProviderOptionsSchema.merge( PromptConfigStrictSchema ) .extend({ @@ -87,15 +87,16 @@ const CopilotChatOptionsSchema = CopilotProviderOptionsSchema.merge( export type CopilotChatOptions = z.infer; -const CopilotEmbeddingOptionsSchema = CopilotProviderOptionsSchema.extend({ - dimensions: z.number(), -}).optional(); +export const CopilotEmbeddingOptionsSchema = + CopilotProviderOptionsSchema.extend({ + dimensions: z.number(), + }).optional(); export type CopilotEmbeddingOptions = z.infer< typeof CopilotEmbeddingOptionsSchema >; -const CopilotImageOptionsSchema = CopilotProviderOptionsSchema.merge( +export const CopilotImageOptionsSchema = CopilotProviderOptionsSchema.merge( PromptConfigStrictSchema ) .extend({ diff --git a/packages/frontend/admin/src/components/ui/use-toast.ts b/packages/frontend/admin/src/components/ui/use-toast.ts index d5bfcce7b..8b5c5a955 100644 --- a/packages/frontend/admin/src/components/ui/use-toast.ts +++ b/packages/frontend/admin/src/components/ui/use-toast.ts @@ -15,13 +15,6 @@ type ToasterToast = ToastProps & { action?: ToastActionElement; }; -const actionTypes = { - ADD_TOAST: 'ADD_TOAST', - UPDATE_TOAST: 'UPDATE_TOAST', - DISMISS_TOAST: 'DISMISS_TOAST', - REMOVE_TOAST: 'REMOVE_TOAST', -} as const; - let count = 0; function genId() { @@ -29,7 +22,12 @@ function genId() { return count.toString(); } -type ActionType = typeof actionTypes; +type ActionType = { + ADD_TOAST: 'ADD_TOAST'; + UPDATE_TOAST: 'UPDATE_TOAST'; + DISMISS_TOAST: 'DISMISS_TOAST'; + REMOVE_TOAST: 'REMOVE_TOAST'; +}; type Action = | { diff --git a/packages/frontend/admin/src/modules/about/about.tsx b/packages/frontend/admin/src/modules/about/about.tsx index 762107b95..0b1df0ede 100644 --- a/packages/frontend/admin/src/modules/about/about.tsx +++ b/packages/frontend/admin/src/modules/about/about.tsx @@ -8,11 +8,8 @@ import { MailWarningIcon, UploadCloudIcon, } from 'lucide-react'; -import { z } from 'zod'; -const appChannelSchema = z.enum(['stable', 'canary', 'beta', 'internal']); - -type Channel = z.infer; +type Channel = 'stable' | 'canary' | 'beta' | 'internal'; const appNames = { stable: 'AFFiNE', diff --git a/packages/frontend/core/src/utils/channel.ts b/packages/frontend/core/src/utils/channel.ts index 8c1a00145..ab4b6567e 100644 --- a/packages/frontend/core/src/utils/channel.ts +++ b/packages/frontend/core/src/utils/channel.ts @@ -8,10 +8,8 @@ export const appSchemes = z.enum([ 'affine-dev', ]); -const appChannelSchemes = z.enum(['stable', 'canary', 'beta', 'internal']); - export type Scheme = z.infer; -export type Channel = z.infer; +export type Channel = 'stable' | 'canary' | 'beta' | 'internal'; export const schemeToChannel = { affine: 'stable', diff --git a/packages/frontend/track/src/events.ts b/packages/frontend/track/src/events.ts index 3db14350d..b545e8d32 100644 --- a/packages/frontend/track/src/events.ts +++ b/packages/frontend/track/src/events.ts @@ -214,7 +214,7 @@ interface PageDivision { }; } -const PageEvents = { +interface PageEvents extends PageDivision { // page: { // $: {} // ^ if empty @@ -225,9 +225,9 @@ const PageEvents = { // to: page.$.segment.module.event1() $: { $: { - $: ['createWorkspace', 'checkout'], - auth: ['requestSignIn', 'signIn', 'signedIn', 'signInFail', 'signOut'], - }, + $: ['createWorkspace', 'checkout']; + auth: ['requestSignIn', 'signIn', 'signedIn', 'signInFail', 'signOut']; + }; sharePanel: { $: [ 'createShareLink', @@ -237,29 +237,29 @@ const PageEvents = { 'modifyDocDefaultRole', 'modifyUserDocRole', 'inviteUserDocRole', - ], - }, + ]; + }; docInfoPanel: { - $: ['open'], - property: ['editProperty', 'addProperty', 'editPropertyMeta'], - databaseProperty: ['editProperty'], - }, + $: ['open']; + property: ['editProperty', 'addProperty', 'editPropertyMeta']; + databaseProperty: ['editProperty']; + }; settingsPanel: { - menu: ['openSettings'], + menu: ['openSettings']; workspace: [ 'viewPlans', 'export', 'addProperty', 'editPropertyMeta', 'deleteUnusedBlob', - ], + ]; archivedWorkspaces: [ 'recoverArchivedWorkspace', 'deleteArchivedWorkspace', - ], - profileAndBadge: ['viewPlans'], - accountUsage: ['viewPlans'], - accountSettings: ['uploadAvatar', 'removeAvatar', 'updateUserName'], + ]; + profileAndBadge: ['viewPlans']; + accountUsage: ['viewPlans']; + accountSettings: ['uploadAvatar', 'removeAvatar', 'updateUserName']; plans: [ 'checkout', 'subscribe', @@ -269,9 +269,9 @@ const PageEvents = { 'confirmCancelingSubscription', 'resumeSubscription', 'confirmResumingSubscription', - ], - billing: ['viewPlans', 'bookDemo'], - about: ['checkUpdates', 'downloadUpdate', 'changeAppSetting'], + ]; + billing: ['viewPlans', 'bookDemo']; + about: ['checkUpdates', 'downloadUpdate', 'changeAppSetting']; integrationList: [ 'connectIntegration', 'disconnectIntegration', @@ -281,17 +281,17 @@ const PageEvents = { 'confirmIntegrationImport', 'abortIntegrationImport', 'completeIntegrationImport', - ], - meetings: ['toggleMeetingFeatureFlag'], - }, + ]; + meetings: ['toggleMeetingFeatureFlag']; + }; cmdk: { - recent: ['recentDocs'], - results: ['searchResultsDocs'], - general: ['copyShareLink', 'goBack', 'goForward', 'findInPage'], - creation: ['createDoc'], - workspace: ['createWorkspace'], - settings: ['openSettings', 'changeAppSetting'], - navigation: ['navigate'], + recent: ['recentDocs']; + results: ['searchResultsDocs']; + general: ['copyShareLink', 'goBack', 'goForward', 'findInPage']; + creation: ['createDoc']; + workspace: ['createWorkspace']; + settings: ['openSettings', 'changeAppSetting']; + navigation: ['navigate']; editor: [ 'toggleFavorite', 'switchPageMode', @@ -299,14 +299,14 @@ const PageEvents = { 'export', 'deleteDoc', 'restoreDoc', - ], - docInfo: ['open'], - docHistory: ['open'], - updates: ['quitAndInstall'], - help: ['contactUs', 'openChangelog'], - }, + ]; + docInfo: ['open']; + docHistory: ['open']; + updates: ['quitAndInstall']; + help: ['contactUs', 'openChangelog']; + }; navigationPanel: { - $: ['quickSearch', 'createDoc', 'navigate', 'openSettings', 'toggle'], + $: ['quickSearch', 'createDoc', 'navigate', 'openSettings', 'toggle']; organize: [ 'createOrganizeItem', 'renameOrganizeItem', @@ -317,54 +317,54 @@ const PageEvents = { 'openInSplitView', 'toggleFavorite', 'drop', - ], - docs: ['createDoc', 'deleteDoc', 'linkDoc', 'drop'], + ]; + docs: ['createDoc', 'deleteDoc', 'linkDoc', 'drop']; collections: [ 'createDoc', 'addDocToCollection', 'removeOrganizeItem', 'drop', - ], - folders: ['createDoc', 'drop'], - tags: ['createDoc', 'tagDoc', 'drop'], - favorites: ['createDoc', 'drop'], - migrationData: ['openMigrationDataHelp'], + ]; + folders: ['createDoc', 'drop']; + tags: ['createDoc', 'tagDoc', 'drop']; + favorites: ['createDoc', 'drop']; + migrationData: ['openMigrationDataHelp']; bottomButtons: [ 'downloadApp', 'quitAndInstall', 'openChangelog', 'dismissChangelog', - ], - others: ['navigate'], - importModal: ['open'], + ]; + others: ['navigate']; + importModal: ['open']; workspaceList: [ 'requestSignIn', 'open', 'createWorkspace', 'createDoc', 'openSettings', - ], - profileAndBadge: ['openSettings'], - journal: ['navigate'], - }, + ]; + profileAndBadge: ['openSettings']; + journal: ['navigate']; + }; aiOnboarding: { - dialog: ['viewPlans'], - }, + dialog: ['viewPlans']; + }; docHistory: { - $: ['open', 'close', 'switchPageMode', 'viewPlans'], - }, + $: ['open', 'close', 'switchPageMode', 'viewPlans']; + }; importModal: { - $: ['open', 'import', 'createDoc'], - }, + $: ['open', 'import', 'createDoc']; + }; paywall: { - storage: ['viewPlans'], - aiAction: ['viewPlans'], - }, + storage: ['viewPlans']; + aiAction: ['viewPlans']; + }; appTabsHeader: { - $: ['tabAction', 'dragStart'], - }, + $: ['tabAction', 'dragStart']; + }; header: { - $: ['dragStart'], + $: ['dragStart']; actions: [ 'createDoc', 'createWorkspace', @@ -372,7 +372,7 @@ const PageEvents = { 'toggleFavorite', 'openDocInfo', 'renameDoc', - ], + ]; docOptions: [ 'open', 'deleteDoc', @@ -382,15 +382,15 @@ const PageEvents = { 'import', 'toggleFavorite', 'export', - ], - history: ['open'], - pageInfo: ['open'], - importModal: ['open'], - snapshot: ['import', 'export'], - }, + ]; + history: ['open']; + pageInfo: ['open']; + importModal: ['open']; + snapshot: ['import', 'export']; + }; chatPanel: { - chatPanelInput: ['addEmbeddingDoc'], - }, + chatPanelInput: ['addEmbeddingDoc']; + }; attachment: { $: [ 'openAttachmentInFullscreen', @@ -398,57 +398,57 @@ const PageEvents = { 'openAttachmentInPeekView', 'openAttachmentInSplitView', 'openPDFRendererFail', - ], - }, + ]; + }; sidebar: { - newDoc: ['quickStart'], - template: ['openTemplateListMenu', 'quickStart'], - notifications: ['openInbox', 'clickNotification'], - }, + newDoc: ['quickStart']; + template: ['openTemplateListMenu', 'quickStart']; + notifications: ['openInbox', 'clickNotification']; + }; splitViewIndicator: { - $: ['splitViewAction', 'openInSplitView', 'openInPeekView'], - }, - }, + $: ['splitViewAction', 'openInSplitView', 'openInPeekView']; + }; + }; doc: { $: { - $: ['loadDoc'], - }, + $: ['loadDoc']; + }; editor: { - slashMenu: ['linkDoc', 'createDoc', 'bookmark'], + slashMenu: ['linkDoc', 'createDoc', 'bookmark']; atMenu: [ 'linkDoc', 'import', 'createDoc', 'mentionMember', 'noAccessPrompted', - ], - quickSearch: ['createDoc'], - formatToolbar: ['bold'], - pageRef: ['navigate'], + ]; + quickSearch: ['createDoc']; + formatToolbar: ['bold']; + pageRef: ['navigate']; toolbar: [ 'copyBlockToLink', 'openInSplitView', 'openInNewTab', 'openInPeekView', - ], - aiActions: ['requestSignIn'], - starterBar: ['quickStart', 'openTemplateListMenu'], - audioBlock: ['transcribeRecording', 'openTranscribeNotes'], - }, + ]; + aiActions: ['requestSignIn']; + starterBar: ['quickStart', 'openTemplateListMenu']; + audioBlock: ['transcribeRecording', 'openTranscribeNotes']; + }; inlineDocInfo: { - $: ['toggle'], - property: ['editProperty', 'editPropertyMeta', 'addProperty'], - databaseProperty: ['editProperty'], - }, + $: ['toggle']; + property: ['editProperty', 'editPropertyMeta', 'addProperty']; + databaseProperty: ['editProperty']; + }; sidepanel: { - property: ['addProperty', 'editPropertyMeta'], - }, + property: ['addProperty', 'editPropertyMeta']; + }; biDirectionalLinksPanel: { - $: ['toggle'], - backlinkTitle: ['toggle', 'navigate'], - backlinkPreview: ['navigate'], - }, - }, + $: ['toggle']; + backlinkTitle: ['toggle', 'navigate']; + backlinkPreview: ['navigate']; + }; + }; edgeless: { pageBlock: { headerToolbar: [ @@ -456,18 +456,18 @@ const PageEvents = { 'openDocInfo', 'copyBlockToLink', 'switchPageMode', - ], - }, - }, + ]; + }; + }; workspace: { $: { - $: ['upgradeWorkspace'], - }, - }, + $: ['upgradeWorkspace']; + }; + }; allDocs: { header: { - actions: ['createDoc', 'createWorkspace'], - }, + actions: ['createDoc', 'createWorkspace']; + }; list: { docMenu: [ 'createDoc', @@ -475,26 +475,26 @@ const PageEvents = { 'openInSplitView', 'toggleFavorite', 'openInNewTab', - ], - }, - }, + ]; + }; + }; collection: { docList: { - docMenu: ['removeOrganizeItem'], - }, - }, - tag: {}, - trash: {}, + docMenu: ['removeOrganizeItem']; + }; + }; + tag: {}; + trash: {}; subscriptionLanding: { $: { - $: ['checkout'], - }, - }, + $: ['checkout']; + }; + }; menubarApp: { menubarActionsMenu: { - menubarActionsList: ['activeMenubarAppItem', 'startRecording'], - }, - }, + menubarActionsList: ['activeMenubarAppItem', 'startRecording']; + }; + }; popup: { $: { recordingBar: [ @@ -502,10 +502,10 @@ const PageEvents = { 'startRecording', 'dismissRecording', 'finishRecording', - ], - }, - }, -} as const satisfies PageDivision; + ]; + }; + }; +} type OrganizeItemType = 'doc' | 'folder' | 'collection' | 'tag' | 'favorite'; type OrganizeItemArgs = @@ -732,4 +732,4 @@ export const YOU_MUST_DEFINE_ARGS_WITH_WRONG_EVENT_NAME: keyof EventArgs extends ? true : false = true; -export type Events = typeof PageEvents; +export type Events = PageEvents; diff --git a/packages/frontend/track/src/index.ts b/packages/frontend/track/src/index.ts index 036e48361..330bacd57 100644 --- a/packages/frontend/track/src/index.ts +++ b/packages/frontend/track/src/index.ts @@ -1,10 +1,10 @@ import { enableAutoTrack, makeTracker } from './auto'; +import { type Events } from './events'; import { mixpanel } from './mixpanel'; import { sentry } from './sentry'; - export const track = makeTracker((event, props) => { mixpanel.track(event, props); }); -export { enableAutoTrack, mixpanel, sentry }; +export { enableAutoTrack, type Events, mixpanel, sentry }; export default track; diff --git a/packages/frontend/track/src/types.ts b/packages/frontend/track/src/types.ts index 5569a09a0..dd5c4be74 100644 --- a/packages/frontend/track/src/types.ts +++ b/packages/frontend/track/src/types.ts @@ -11,7 +11,6 @@ export type CallableEventsChain = { [Page in keyof Events]: { [Segment in keyof Events[Page]]: { [Module in keyof Events[Page][Segment]]: { - // @ts-expect-error ignore `symbol | number` as key [Event in Events[Page][Segment][Module][number]]: Event extends keyof EventArgs ? ( // we make all args partial to simply satisfies nullish type checking @@ -29,7 +28,6 @@ export type EventsUnion = { [Module in keyof Events[Page][Segment]]: { // @ts-expect-error ignore `symbol | number` as key [Event in Events[Page][Segment][Module][number]]: `${Page}.${Segment}.${Module}.${Event}`; - // @ts-expect-error ignore `symbol | number` as key }[Events[Page][Segment][Module][number]]; }[keyof Events[Page][Segment]]; }[keyof Events[Page]]; diff --git a/yarn.lock b/yarn.lock index eb07a1c5b..1bf696285 100644 --- a/yarn.lock +++ b/yarn.lock @@ -787,7 +787,7 @@ __metadata: husky: "npm:^9.1.7" lint-staged: "npm:^15.2.11" msw: "npm:^2.6.8" - oxlint: "npm:0.16.8" + oxlint: "npm:0.16.9" prettier: "npm:^3.4.2" semver: "npm:^7.6.3" serve: "npm:^14.2.4" @@ -10520,58 +10520,58 @@ __metadata: languageName: node linkType: hard -"@oxlint/darwin-arm64@npm:0.16.8": - version: 0.16.8 - resolution: "@oxlint/darwin-arm64@npm:0.16.8" +"@oxlint/darwin-arm64@npm:0.16.9": + version: 0.16.9 + resolution: "@oxlint/darwin-arm64@npm:0.16.9" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@oxlint/darwin-x64@npm:0.16.8": - version: 0.16.8 - resolution: "@oxlint/darwin-x64@npm:0.16.8" +"@oxlint/darwin-x64@npm:0.16.9": + version: 0.16.9 + resolution: "@oxlint/darwin-x64@npm:0.16.9" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@oxlint/linux-arm64-gnu@npm:0.16.8": - version: 0.16.8 - resolution: "@oxlint/linux-arm64-gnu@npm:0.16.8" +"@oxlint/linux-arm64-gnu@npm:0.16.9": + version: 0.16.9 + resolution: "@oxlint/linux-arm64-gnu@npm:0.16.9" conditions: os=linux & cpu=arm64 & libc=glibc languageName: node linkType: hard -"@oxlint/linux-arm64-musl@npm:0.16.8": - version: 0.16.8 - resolution: "@oxlint/linux-arm64-musl@npm:0.16.8" +"@oxlint/linux-arm64-musl@npm:0.16.9": + version: 0.16.9 + resolution: "@oxlint/linux-arm64-musl@npm:0.16.9" conditions: os=linux & cpu=arm64 & libc=musl languageName: node linkType: hard -"@oxlint/linux-x64-gnu@npm:0.16.8": - version: 0.16.8 - resolution: "@oxlint/linux-x64-gnu@npm:0.16.8" +"@oxlint/linux-x64-gnu@npm:0.16.9": + version: 0.16.9 + resolution: "@oxlint/linux-x64-gnu@npm:0.16.9" conditions: os=linux & cpu=x64 & libc=glibc languageName: node linkType: hard -"@oxlint/linux-x64-musl@npm:0.16.8": - version: 0.16.8 - resolution: "@oxlint/linux-x64-musl@npm:0.16.8" +"@oxlint/linux-x64-musl@npm:0.16.9": + version: 0.16.9 + resolution: "@oxlint/linux-x64-musl@npm:0.16.9" conditions: os=linux & cpu=x64 & libc=musl languageName: node linkType: hard -"@oxlint/win32-arm64@npm:0.16.8": - version: 0.16.8 - resolution: "@oxlint/win32-arm64@npm:0.16.8" +"@oxlint/win32-arm64@npm:0.16.9": + version: 0.16.9 + resolution: "@oxlint/win32-arm64@npm:0.16.9" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@oxlint/win32-x64@npm:0.16.8": - version: 0.16.8 - resolution: "@oxlint/win32-x64@npm:0.16.8" +"@oxlint/win32-x64@npm:0.16.9": + version: 0.16.9 + resolution: "@oxlint/win32-x64@npm:0.16.9" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -27977,18 +27977,18 @@ __metadata: languageName: node linkType: hard -"oxlint@npm:0.16.8": - version: 0.16.8 - resolution: "oxlint@npm:0.16.8" +"oxlint@npm:0.16.9": + version: 0.16.9 + resolution: "oxlint@npm:0.16.9" dependencies: - "@oxlint/darwin-arm64": "npm:0.16.8" - "@oxlint/darwin-x64": "npm:0.16.8" - "@oxlint/linux-arm64-gnu": "npm:0.16.8" - "@oxlint/linux-arm64-musl": "npm:0.16.8" - "@oxlint/linux-x64-gnu": "npm:0.16.8" - "@oxlint/linux-x64-musl": "npm:0.16.8" - "@oxlint/win32-arm64": "npm:0.16.8" - "@oxlint/win32-x64": "npm:0.16.8" + "@oxlint/darwin-arm64": "npm:0.16.9" + "@oxlint/darwin-x64": "npm:0.16.9" + "@oxlint/linux-arm64-gnu": "npm:0.16.9" + "@oxlint/linux-arm64-musl": "npm:0.16.9" + "@oxlint/linux-x64-gnu": "npm:0.16.9" + "@oxlint/linux-x64-musl": "npm:0.16.9" + "@oxlint/win32-arm64": "npm:0.16.9" + "@oxlint/win32-x64": "npm:0.16.9" dependenciesMeta: "@oxlint/darwin-arm64": optional: true @@ -28009,7 +28009,7 @@ __metadata: bin: oxc_language_server: bin/oxc_language_server oxlint: bin/oxlint - checksum: 10/f49bba9ca742ecae611443b5450a7bd58789b0deb3f853f9de2cccbf8b38d714726ef669d59400de3333107ecd122b1f7ab9368b5dd2c2e41edad3b32afb60b8 + checksum: 10/94231e74a8484d48b886e9773152870d2481fa7f770f4c7d12666230a697d6a4c5ca277f6ecd9e6c725abc40052d6adcb6bfa5e5ed565df49e5f875a340e0793 languageName: node linkType: hard