refactor(server): rename @affine/storage to @affine/server-native (#6682)

- Close https://github.com/toeverything/AFFiNE/issues/6680
This commit is contained in:
Brooooooklyn 2024-04-29 02:14:20 +00:00
parent 236c6e00df
commit fed2503782
No known key found for this signature in database
GPG Key ID: 30B1140CE1C07C99
26 changed files with 76 additions and 79 deletions

View File

@ -9,10 +9,10 @@ corepack prepare yarn@stable --activate
yarn install
# Build Server Dependencies
yarn workspace @affine/storage build
yarn workspace @affine/server-native build
# Create database
yarn workspace @affine/server prisma db push
# Create user username: affine, password: affine
echo "INSERT INTO \"users\"(\"id\",\"name\",\"email\",\"email_verified\",\"created_at\",\"password\") VALUES('99f3ad04-7c9b-441e-a6db-79f73aa64db9','affine','affine@affine.pro','2024-02-26 15:54:16.974','2024-02-26 15:54:16.974+00','\$argon2id\$v=19\$m=19456,t=2,p=1\$esDS3QCHRH0Kmeh87YPm5Q\$9S+jf+xzw2Hicj6nkWltvaaaXX3dQIxAFwCfFa9o38A');" | yarn workspace @affine/server prisma db execute --stdin
echo "INSERT INTO \"users\"(\"id\",\"name\",\"email\",\"email_verified\",\"created_at\",\"password\") VALUES('99f3ad04-7c9b-441e-a6db-79f73aa64db9','affine','affine@affine.pro','2024-02-26 15:54:16.974','2024-02-26 15:54:16.974+00','\$argon2id\$v=19\$m=19456,t=2,p=1\$esDS3QCHRH0Kmeh87YPm5Q\$9S+jf+xzw2Hicj6nkWltvaaaXX3dQIxAFwCfFa9o38A');" | yarn workspace @affine/server prisma db execute --stdin

4
.github/labeler.yml vendored
View File

@ -44,10 +44,10 @@ mod:component:
- any-glob-to-any-file:
- 'packages/frontend/component/**/*'
mod:storage:
mod:server-native:
- changed-files:
- any-glob-to-any-file:
- 'packages/backend/storage/**/*'
- 'packages/backend/native/**/*'
mod:native:
- changed-files:

View File

@ -66,18 +66,18 @@ jobs:
path: ./packages/frontend/web/dist
if-no-files-found: error
build-storage:
name: Build Storage - ${{ matrix.targets.name }}
build-server-native:
name: Build Server native - ${{ matrix.targets.name }}
runs-on: ubuntu-latest
strategy:
matrix:
targets:
- name: x86_64-unknown-linux-gnu
file: storage.node
file: server-native.node
- name: aarch64-unknown-linux-gnu
file: storage.arm64.node
file: server-native.arm64.node
- name: armv7-unknown-linux-gnueabihf
file: storage.armv7.node
file: server-native.armv7.node
steps:
- uses: actions/checkout@v4
@ -88,18 +88,18 @@ jobs:
uses: ./.github/actions/setup-node
with:
electron-install: false
extra-flags: workspaces focus @affine/storage
extra-flags: workspaces focus @affine/server-native
- name: Build Rust
uses: ./.github/actions/build-rust
with:
target: ${{ matrix.targets.name }}
package: '@affine/storage'
package: '@affine/server-native'
nx_token: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
- name: Upload ${{ matrix.targets.file }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.targets.file }}
path: ./packages/backend/storage/storage.node
path: ./packages/backend/native/server-native.node
if-no-files-found: error
build-docker:
@ -108,7 +108,7 @@ jobs:
needs:
- build-server
- build-web-selfhost
- build-storage
- build-server-native
steps:
- uses: actions/checkout@v4
- name: Download server dist
@ -116,25 +116,25 @@ jobs:
with:
name: server-dist
path: ./packages/backend/server/dist
- name: Download storage.node
- name: Download server-native.node
uses: actions/download-artifact@v4
with:
name: storage.node
name: server-native.node
path: ./packages/backend/server
- name: Download storage.node arm64
- name: Download server-native.node arm64
uses: actions/download-artifact@v4
with:
name: storage.arm64.node
path: ./packages/backend/storage
- name: Download storage.node arm64
name: server-native.arm64.node
path: ./packages/backend/native
- name: Download server-native.node arm64
uses: actions/download-artifact@v4
with:
name: storage.armv7.node
name: server-native.armv7.node
path: .
- name: move storage files
- name: move server-native files
run: |
mv ./packages/backend/storage/storage.node ./packages/backend/server/storage.arm64.node
mv storage.node ./packages/backend/server/storage.armv7.node
mv ./packages/backend/native/server-native.node ./packages/backend/server/server-native.arm64.node
mv server-native.node ./packages/backend/server/server-native.armv7.node
- name: Setup env
run: |
echo "GIT_SHORT_HASH=$(git rev-parse --short HEAD)" >> "$GITHUB_ENV"

View File

@ -241,8 +241,8 @@ jobs:
path: ./packages/frontend/native/${{ steps.filename.outputs.filename }}
if-no-files-found: error
build-storage:
name: Build Storage
build-server-native:
name: Build Server native
runs-on: ubuntu-latest
env:
CARGO_PROFILE_RELEASE_DEBUG: '1'
@ -251,19 +251,19 @@ jobs:
- name: Setup Node.js
uses: ./.github/actions/setup-node
with:
extra-flags: workspaces focus @affine/storage
extra-flags: workspaces focus @affine/server-native
electron-install: false
- name: Build Rust
uses: ./.github/actions/build-rust
with:
target: 'x86_64-unknown-linux-gnu'
package: '@affine/storage'
package: '@affine/server-native'
nx_token: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
- name: Upload storage.node
- name: Upload server-native.node
uses: actions/upload-artifact@v4
with:
name: storage.node
path: ./packages/backend/storage/storage.node
name: server-native.node
path: ./packages/backend/native/server-native.node
if-no-files-found: error
build-web:
@ -294,7 +294,7 @@ jobs:
server-test:
name: Server Test
runs-on: ubuntu-latest
needs: build-storage
needs: build-server-native
env:
NODE_ENV: test
DISTRIBUTION: browser
@ -324,10 +324,10 @@ jobs:
electron-install: false
full-cache: true
- name: Download storage.node
- name: Download server-native.node
uses: actions/download-artifact@v4
with:
name: storage.node
name: server-native.node
path: ./packages/backend/server
- name: Initialize database
@ -383,7 +383,7 @@ jobs:
yarn workspace @affine/electron build:dev
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- yarn workspace @affine-test/affine-desktop-cloud e2e
needs:
- build-storage
- build-server-native
- build-native
services:
postgres:
@ -411,10 +411,10 @@ jobs:
playwright-install: true
hard-link-nm: false
- name: Download storage.node
- name: Download server-native.node
uses: actions/download-artifact@v4
with:
name: storage.node
name: server-native.node
path: ./packages/backend/server
- name: Download affine.linux-x64-gnu.node

View File

@ -21,6 +21,6 @@ packages/frontend/templates/onboarding
# auto-generated by NAPI-RS
# fixme(@joooye34): need script to check and generate ignore list here
packages/backend/storage/index.d.ts
packages/backend/native/index.d.ts
packages/frontend/native/index.d.ts
packages/frontend/native/index.js

2
Cargo.lock generated
View File

@ -45,7 +45,7 @@ name = "affine_schema"
version = "0.0.0"
[[package]]
name = "affine_storage"
name = "affine_server_native"
version = "1.0.0"
dependencies = [
"chrono",

View File

@ -3,7 +3,7 @@ resolver = "2"
members = [
"./packages/frontend/native",
"./packages/frontend/native/schema",
"./packages/backend/storage",
"./packages/backend/native",
]
[profile.dev.package.sqlx-macros]

View File

@ -93,7 +93,7 @@ yarn workspace @affine/native build
### Build Server Dependencies
```sh
yarn workspace @affine/storage build
yarn workspace @affine/server-native build
```
## Testing

View File

@ -81,7 +81,7 @@ yarn workspace @affine/server prisma studio
```
# build native
yarn workspace @affine/storage build
yarn workspace @affine/server-native build
yarn workspace @affine/native build
```

View File

@ -21,7 +21,7 @@
"dev:electron": "yarn workspace @affine/electron dev",
"build": "yarn nx build @affine/web",
"build:electron": "yarn nx build @affine/electron",
"build:storage": "yarn nx run-many -t build -p @affine/storage",
"build:server-native": "yarn nx run-many -t build -p @affine/server-native",
"start:web-static": "yarn workspace @affine/web static-server",
"serve:test-static": "yarn exec serve tests/fixtures --cors -p 8081",
"lint:eslint": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192\" eslint . --ext .js,mjs,.ts,.tsx --cache",

View File

@ -1,5 +1,5 @@
[package]
name = "affine_storage"
name = "affine_server_native"
version = "1.0.0"
edition = "2021"

View File

@ -1,5 +1,5 @@
{
"name": "@affine/storage",
"name": "@affine/server-native",
"version": "0.14.0",
"engines": {
"node": ">= 10.16.0 < 11 || >= 11.8.0"
@ -10,13 +10,13 @@
"types": "index.d.ts",
"exports": {
".": {
"require": "./storage.node",
"require": "./server-native.node",
"import": "./index.js",
"types": "./index.d.ts"
}
},
"napi": {
"binaryName": "storage",
"binaryName": "server-native",
"targets": [
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
@ -29,10 +29,7 @@
"scripts": {
"test": "node --test ./__tests__/**/*.spec.js",
"build": "napi build --release --strip --no-const-enum",
"build:debug": "napi build",
"prepublishOnly": "napi prepublish -t npm",
"artifacts": "napi artifacts",
"version": "napi version"
"build:debug": "napi build"
},
"devDependencies": {
"@napi-rs/cli": "3.0.0-alpha.46",

View File

@ -1,9 +1,9 @@
{
"name": "@affine/storage",
"name": "@affine/server-native",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"projectType": "application",
"root": "packages/backend/storage",
"sourceRoot": "packages/backend/storage/src",
"root": "packages/backend/native",
"sourceRoot": "packages/backend/native/src",
"targets": {
"build": {
"executor": "nx:run-script",

View File

@ -11,7 +11,7 @@ yarn
### Build Native binding
```bash
yarn workspace @affine/storage build
yarn workspace @affine/server-native build
```
### Run server

View File

@ -96,7 +96,7 @@
},
"devDependencies": {
"@affine-test/kit": "workspace:*",
"@affine/storage": "workspace:*",
"@affine/server-native": "workspace:*",
"@napi-rs/image": "^1.9.1",
"@nestjs/testing": "^10.3.7",
"@types/cookie-parser": "^1.4.7",

View File

@ -1,19 +1,19 @@
import { createRequire } from 'node:module';
let storageModule: typeof import('@affine/storage');
let serverNativeModule: typeof import('@affine/server-native');
try {
storageModule = await import('@affine/storage');
serverNativeModule = await import('@affine/server-native');
} catch {
const require = createRequire(import.meta.url);
storageModule =
serverNativeModule =
process.arch === 'arm64'
? require('../../../storage.arm64.node')
? require('../../../server-native.arm64.node')
: process.arch === 'arm'
? require('../../../storage.armv7.node')
: require('../../../storage.node');
? require('../../../server-native.armv7.node')
: require('../../../server-native.node');
}
export const mergeUpdatesInApplyWay = storageModule.mergeUpdatesInApplyWay;
export const mergeUpdatesInApplyWay = serverNativeModule.mergeUpdatesInApplyWay;
export const verifyChallengeResponse = async (
response: any,
@ -21,10 +21,10 @@ export const verifyChallengeResponse = async (
resource: string
) => {
if (typeof response !== 'string' || !response || !resource) return false;
return storageModule.verifyChallengeResponse(response, bits, resource);
return serverNativeModule.verifyChallengeResponse(response, bits, resource);
};
export const mintChallengeResponse = async (resource: string, bits: number) => {
if (!resource) return null;
return storageModule.mintChallengeResponse(resource, bits);
return serverNativeModule.mintChallengeResponse(resource, bits);
};

View File

@ -23,7 +23,7 @@
"path": "./tsconfig.node.json"
},
{
"path": "../storage/tsconfig.json"
"path": "../native/tsconfig.json"
}
],
"ts-node": {

View File

@ -69,7 +69,7 @@
"@toeverything/infra": ["./packages/common/infra/src"],
"@affine/native": ["./packages/frontend/native/index.d.ts"],
"@affine/native/*": ["./packages/frontend/native/*"],
"@affine/storage": ["./packages/backend/storage/index.d.ts"],
"@affine/server-native": ["./packages/backend/native/index.d.ts"],
// Development only
"@affine/electron/*": ["./packages/frontend/electron/src/*"]
}

View File

@ -644,12 +644,24 @@ __metadata:
languageName: unknown
linkType: soft
"@affine/server-native@workspace:*, @affine/server-native@workspace:packages/backend/native":
version: 0.0.0-use.local
resolution: "@affine/server-native@workspace:packages/backend/native"
dependencies:
"@napi-rs/cli": "npm:3.0.0-alpha.46"
lib0: "npm:^0.2.93"
nx: "npm:^18.2.4"
nx-cloud: "npm:^18.0.0"
yjs: "npm:^13.6.14"
languageName: unknown
linkType: soft
"@affine/server@workspace:packages/backend/server":
version: 0.0.0-use.local
resolution: "@affine/server@workspace:packages/backend/server"
dependencies:
"@affine-test/kit": "workspace:*"
"@affine/storage": "workspace:*"
"@affine/server-native": "workspace:*"
"@apollo/server": "npm:^4.10.2"
"@aws-sdk/client-s3": "npm:^3.552.0"
"@google-cloud/opentelemetry-cloud-monitoring-exporter": "npm:^0.17.0"
@ -752,18 +764,6 @@ __metadata:
languageName: unknown
linkType: soft
"@affine/storage@workspace:*, @affine/storage@workspace:packages/backend/storage":
version: 0.0.0-use.local
resolution: "@affine/storage@workspace:packages/backend/storage"
dependencies:
"@napi-rs/cli": "npm:3.0.0-alpha.46"
lib0: "npm:^0.2.93"
nx: "npm:^18.2.4"
nx-cloud: "npm:^18.0.0"
yjs: "npm:^13.6.14"
languageName: unknown
linkType: soft
"@affine/templates@workspace:*, @affine/templates@workspace:packages/frontend/templates":
version: 0.0.0-use.local
resolution: "@affine/templates@workspace:packages/frontend/templates"