From d835be90cb3ae073dd0c2baec636bf8978ba3656 Mon Sep 17 00:00:00 2001 From: Joooye_34 Date: Thu, 19 Oct 2023 15:17:04 +0800 Subject: [PATCH] chore: prettier ignore file generated by napi-rs (#4661) --- .prettierignore | 6 + packages/backend/storage/index.d.ts | 36 ++--- packages/frontend/native/index.d.ts | 70 ++++------ packages/frontend/native/index.js | 204 +++++++++++++--------------- 4 files changed, 143 insertions(+), 173 deletions(-) diff --git a/.prettierignore b/.prettierignore index 9ef6b67068..07576094a7 100644 --- a/.prettierignore +++ b/.prettierignore @@ -15,3 +15,9 @@ packages/backend/server/src/schema.gql packages/frontend/i18n/src/i18n-generated.ts packages/frontend/graphql/src/graphql/index.ts tests/affine-legacy/**/static + +# auto-generated by NAPI-RS +# fixme(@joooye34): need script to check and generate ignore list here +packages/backend/storage/index.d.ts +packages/frontend/native/index.d.ts +packages/frontend/native/index.js diff --git a/packages/backend/storage/index.d.ts b/packages/backend/storage/index.d.ts index a2c61f106e..bd6060f9fb 100644 --- a/packages/backend/storage/index.d.ts +++ b/packages/backend/storage/index.d.ts @@ -3,40 +3,30 @@ /* auto-generated by NAPI-RS */ -export function verifyChallengeResponse( - response: string, - bits: number, - resource: string -): Promise; -export function mintChallengeResponse( - resource: string, - bits?: number | undefined | null -): Promise; +export function verifyChallengeResponse(response: string, bits: number, resource: string): Promise +export function mintChallengeResponse(resource: string, bits?: number | undefined | null): Promise export interface Blob { - contentType: string; - lastModified: string; - size: number; - data: Buffer; + contentType: string + lastModified: string + size: number + data: Buffer } /** * Merge updates in form like `Y.applyUpdate(doc, update)` way and return the * result binary. */ -export function mergeUpdatesInApplyWay(updates: Array): Buffer; +export function mergeUpdatesInApplyWay(updates: Array): Buffer export class Storage { /** Create a storage instance and establish connection to persist store. */ - static connect( - database: string, - debugOnlyAutoMigrate?: boolean | undefined | null - ): Promise; + static connect(database: string, debugOnlyAutoMigrate?: boolean | undefined | null): Promise /** List all blobs in a workspace. */ - listBlobs(workspaceId?: string | undefined | null): Promise>; + listBlobs(workspaceId?: string | undefined | null): Promise> /** Fetch a workspace blob. */ - getBlob(workspaceId: string, name: string): Promise; + getBlob(workspaceId: string, name: string): Promise /** Upload a blob into workspace storage. */ - uploadBlob(workspaceId: string, blob: Buffer): Promise; + uploadBlob(workspaceId: string, blob: Buffer): Promise /** Delete a blob from workspace storage. */ - deleteBlob(workspaceId: string, hash: string): Promise; + deleteBlob(workspaceId: string, hash: string): Promise /** Workspace size taken by blobs. */ - blobsSize(workspaces: Array): Promise; + blobsSize(workspaces: Array): Promise } diff --git a/packages/frontend/native/index.d.ts b/packages/frontend/native/index.d.ts index a65cdbf8ad..47c9a16d5a 100644 --- a/packages/frontend/native/index.d.ts +++ b/packages/frontend/native/index.d.ts @@ -4,56 +4,46 @@ /* auto-generated by NAPI-RS */ export interface BlobRow { - key: string; - data: Buffer; - timestamp: Date; + key: string + data: Buffer + timestamp: Date } export interface UpdateRow { - id: number; - timestamp: Date; - data: Buffer; - docId?: string; + id: number + timestamp: Date + data: Buffer + docId?: string } export interface InsertRow { - docId?: string; - data: Uint8Array; + docId?: string + data: Uint8Array } export enum ValidationResult { MissingTables = 0, MissingDocIdColumn = 1, MissingVersionColumn = 2, GeneralError = 3, - Valid = 4, + Valid = 4 } -export function verifyChallengeResponse( - response: string, - bits: number, - resource: string -): Promise; -export function mintChallengeResponse( - resource: string, - bits?: number | undefined | null -): Promise; +export function verifyChallengeResponse(response: string, bits: number, resource: string): Promise +export function mintChallengeResponse(resource: string, bits?: number | undefined | null): Promise export class SqliteConnection { - constructor(path: string); - connect(): Promise; - addBlob(key: string, blob: Uint8Array): Promise; - getBlob(key: string): Promise; - deleteBlob(key: string): Promise; - getBlobKeys(): Promise>; - getUpdates(docId?: string | undefined | null): Promise>; - getUpdatesCount(docId?: string | undefined | null): Promise; - getAllUpdates(): Promise>; - insertUpdates(updates: Array): Promise; - replaceUpdates( - docId: string | undefined | null, - updates: Array - ): Promise; - initVersion(): Promise; - setVersion(version: number): Promise; - getMaxVersion(): Promise; - close(): Promise; - get isClose(): boolean; - static validate(path: string): Promise; - migrateAddDocId(): Promise; + constructor(path: string) + connect(): Promise + addBlob(key: string, blob: Uint8Array): Promise + getBlob(key: string): Promise + deleteBlob(key: string): Promise + getBlobKeys(): Promise> + getUpdates(docId?: string | undefined | null): Promise> + getUpdatesCount(docId?: string | undefined | null): Promise + getAllUpdates(): Promise> + insertUpdates(updates: Array): Promise + replaceUpdates(docId: string | undefined | null, updates: Array): Promise + initVersion(): Promise + setVersion(version: number): Promise + getMaxVersion(): Promise + close(): Promise + get isClose(): boolean + static validate(path: string): Promise + migrateAddDocId(): Promise } diff --git a/packages/frontend/native/index.js b/packages/frontend/native/index.js index dabd08f1fd..5773485893 100644 --- a/packages/frontend/native/index.js +++ b/packages/frontend/native/index.js @@ -5,29 +5,26 @@ /* auto-generated by NAPI-RS */ const { existsSync, readFileSync } = require('fs') -const { join } = require('path'); +const { join } = require('path') -const { platform, arch } = process; +const { platform, arch } = process -let nativeBinding = null; -let localFileExisted = false; -let loadError = null; +let nativeBinding = null +let localFileExisted = false +let loadError = null function isMusl() { // For Node 10 if (!process.report || typeof process.report.getReport !== 'function') { try { - const lddPath = require('child_process') - .execSync('which ldd') - .toString() - .trim(); - return readFileSync(lddPath, 'utf8').includes('musl'); + const lddPath = require('child_process').execSync('which ldd').toString().trim() + return readFileSync(lddPath, 'utf8').includes('musl') } catch (e) { - return true; + return true } } else { - const { glibcVersionRuntime } = process.report.getReport().header; - return !glibcVersionRuntime; + const { glibcVersionRuntime } = process.report.getReport().header + return !glibcVersionRuntime } } @@ -35,242 +32,229 @@ switch (platform) { case 'android': switch (arch) { case 'arm64': - localFileExisted = existsSync( - join(__dirname, 'affine.android-arm64.node') - ); + localFileExisted = existsSync(join(__dirname, 'affine.android-arm64.node')) try { if (localFileExisted) { - nativeBinding = require('./affine.android-arm64.node'); + nativeBinding = require('./affine.android-arm64.node') } else { - nativeBinding = require('@affine/native-android-arm64'); + nativeBinding = require('@affine/native-android-arm64') } } catch (e) { - loadError = e; + loadError = e } - break; + break case 'arm': - localFileExisted = existsSync( - join(__dirname, 'affine.android-arm-eabi.node') - ); + localFileExisted = existsSync(join(__dirname, 'affine.android-arm-eabi.node')) try { if (localFileExisted) { - nativeBinding = require('./affine.android-arm-eabi.node'); + nativeBinding = require('./affine.android-arm-eabi.node') } else { - nativeBinding = require('@affine/native-android-arm-eabi'); + nativeBinding = require('@affine/native-android-arm-eabi') } } catch (e) { - loadError = e; + loadError = e } - break; + break default: - throw new Error(`Unsupported architecture on Android ${arch}`); + throw new Error(`Unsupported architecture on Android ${arch}`) } - break; + break case 'win32': switch (arch) { case 'x64': localFileExisted = existsSync( join(__dirname, 'affine.win32-x64-msvc.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.win32-x64-msvc.node'); + nativeBinding = require('./affine.win32-x64-msvc.node') } else { - nativeBinding = require('@affine/native-win32-x64-msvc'); + nativeBinding = require('@affine/native-win32-x64-msvc') } } catch (e) { - loadError = e; + loadError = e } - break; + break case 'ia32': localFileExisted = existsSync( join(__dirname, 'affine.win32-ia32-msvc.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.win32-ia32-msvc.node'); + nativeBinding = require('./affine.win32-ia32-msvc.node') } else { - nativeBinding = require('@affine/native-win32-ia32-msvc'); + nativeBinding = require('@affine/native-win32-ia32-msvc') } } catch (e) { - loadError = e; + loadError = e } - break; + break case 'arm64': localFileExisted = existsSync( join(__dirname, 'affine.win32-arm64-msvc.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.win32-arm64-msvc.node'); + nativeBinding = require('./affine.win32-arm64-msvc.node') } else { - nativeBinding = require('@affine/native-win32-arm64-msvc'); + nativeBinding = require('@affine/native-win32-arm64-msvc') } } catch (e) { - loadError = e; + loadError = e } - break; + break default: - throw new Error(`Unsupported architecture on Windows: ${arch}`); + throw new Error(`Unsupported architecture on Windows: ${arch}`) } - break; + break case 'darwin': - localFileExisted = existsSync( - join(__dirname, 'affine.darwin-universal.node') - ); + localFileExisted = existsSync(join(__dirname, 'affine.darwin-universal.node')) try { if (localFileExisted) { - nativeBinding = require('./affine.darwin-universal.node'); + nativeBinding = require('./affine.darwin-universal.node') } else { - nativeBinding = require('@affine/native-darwin-universal'); + nativeBinding = require('@affine/native-darwin-universal') } - break; + break } catch {} switch (arch) { case 'x64': - localFileExisted = existsSync( - join(__dirname, 'affine.darwin-x64.node') - ); + localFileExisted = existsSync(join(__dirname, 'affine.darwin-x64.node')) try { if (localFileExisted) { - nativeBinding = require('./affine.darwin-x64.node'); + nativeBinding = require('./affine.darwin-x64.node') } else { - nativeBinding = require('@affine/native-darwin-x64'); + nativeBinding = require('@affine/native-darwin-x64') } } catch (e) { - loadError = e; + loadError = e } - break; + break case 'arm64': localFileExisted = existsSync( join(__dirname, 'affine.darwin-arm64.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.darwin-arm64.node'); + nativeBinding = require('./affine.darwin-arm64.node') } else { - nativeBinding = require('@affine/native-darwin-arm64'); + nativeBinding = require('@affine/native-darwin-arm64') } } catch (e) { - loadError = e; + loadError = e } - break; + break default: - throw new Error(`Unsupported architecture on macOS: ${arch}`); + throw new Error(`Unsupported architecture on macOS: ${arch}`) } - break; + break case 'freebsd': if (arch !== 'x64') { - throw new Error(`Unsupported architecture on FreeBSD: ${arch}`); + throw new Error(`Unsupported architecture on FreeBSD: ${arch}`) } - localFileExisted = existsSync(join(__dirname, 'affine.freebsd-x64.node')); + localFileExisted = existsSync(join(__dirname, 'affine.freebsd-x64.node')) try { if (localFileExisted) { - nativeBinding = require('./affine.freebsd-x64.node'); + nativeBinding = require('./affine.freebsd-x64.node') } else { - nativeBinding = require('@affine/native-freebsd-x64'); + nativeBinding = require('@affine/native-freebsd-x64') } } catch (e) { - loadError = e; + loadError = e } - break; + break case 'linux': switch (arch) { case 'x64': if (isMusl()) { localFileExisted = existsSync( join(__dirname, 'affine.linux-x64-musl.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.linux-x64-musl.node'); + nativeBinding = require('./affine.linux-x64-musl.node') } else { - nativeBinding = require('@affine/native-linux-x64-musl'); + nativeBinding = require('@affine/native-linux-x64-musl') } } catch (e) { - loadError = e; + loadError = e } } else { localFileExisted = existsSync( join(__dirname, 'affine.linux-x64-gnu.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.linux-x64-gnu.node'); + nativeBinding = require('./affine.linux-x64-gnu.node') } else { - nativeBinding = require('@affine/native-linux-x64-gnu'); + nativeBinding = require('@affine/native-linux-x64-gnu') } } catch (e) { - loadError = e; + loadError = e } } - break; + break case 'arm64': if (isMusl()) { localFileExisted = existsSync( join(__dirname, 'affine.linux-arm64-musl.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.linux-arm64-musl.node'); + nativeBinding = require('./affine.linux-arm64-musl.node') } else { - nativeBinding = require('@affine/native-linux-arm64-musl'); + nativeBinding = require('@affine/native-linux-arm64-musl') } } catch (e) { - loadError = e; + loadError = e } } else { localFileExisted = existsSync( join(__dirname, 'affine.linux-arm64-gnu.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.linux-arm64-gnu.node'); + nativeBinding = require('./affine.linux-arm64-gnu.node') } else { - nativeBinding = require('@affine/native-linux-arm64-gnu'); + nativeBinding = require('@affine/native-linux-arm64-gnu') } } catch (e) { - loadError = e; + loadError = e } } - break; + break case 'arm': localFileExisted = existsSync( join(__dirname, 'affine.linux-arm-gnueabihf.node') - ); + ) try { if (localFileExisted) { - nativeBinding = require('./affine.linux-arm-gnueabihf.node'); + nativeBinding = require('./affine.linux-arm-gnueabihf.node') } else { - nativeBinding = require('@affine/native-linux-arm-gnueabihf'); + nativeBinding = require('@affine/native-linux-arm-gnueabihf') } } catch (e) { - loadError = e; + loadError = e } - break; + break default: - throw new Error(`Unsupported architecture on Linux: ${arch}`); + throw new Error(`Unsupported architecture on Linux: ${arch}`) } - break; + break default: - throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`); + throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`) } if (!nativeBinding) { if (loadError) { - throw loadError; + throw loadError } - throw new Error(`Failed to load native binding`); + throw new Error(`Failed to load native binding`) } -const { - SqliteConnection, - ValidationResult, - verifyChallengeResponse, - mintChallengeResponse, -} = nativeBinding; +const { SqliteConnection, ValidationResult, verifyChallengeResponse, mintChallengeResponse } = nativeBinding -module.exports.SqliteConnection = SqliteConnection; -module.exports.ValidationResult = ValidationResult; -module.exports.verifyChallengeResponse = verifyChallengeResponse; -module.exports.mintChallengeResponse = mintChallengeResponse; +module.exports.SqliteConnection = SqliteConnection +module.exports.ValidationResult = ValidationResult +module.exports.verifyChallengeResponse = verifyChallengeResponse +module.exports.mintChallengeResponse = mintChallengeResponse