Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: open api #6334

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ machine-learning/
misc/
mobile/

server/node_modules
server/node_modules/
server/coverage/
server/.reverse-geocoding-dump/
server/upload/
Expand All @@ -19,7 +19,10 @@ web/coverage/
web/.svelte-kit
web/build/

cli/node_modules
cli/node_modules/
cli/.reverse-geocoding-dump/
cli/upload/
cli/dist/
cli/dist/

open-api/typescript-sdk/node_modules/
open-api/typescript-sdk/build/
13 changes: 4 additions & 9 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ mobile/openapi/.openapi-generator/FILES linguist-generated=true
mobile/lib/**/*.g.dart -diff -merge
mobile/lib/**/*.g.dart linguist-generated=true

cli/src/api/open-api/**/*.md -diff -merge
cli/src/api/open-api/**/*.md linguist-generated=true
cli/src/api/open-api/**/*.ts -diff -merge
cli/src/api/open-api/**/*.ts linguist-generated=true

web/src/api/open-api/**/*.md -diff -merge
web/src/api/open-api/**/*.md linguist-generated=true
web/src/api/open-api/**/*.ts -diff -merge
web/src/api/open-api/**/*.ts linguist-generated=true
open-api/typescript-sdk/client/**/*.md -diff -merge
open-api/typescript-sdk/client/**/*.md linguist-generated=true
open-api/typescript-sdk/client/**/*.ts -diff -merge
open-api/typescript-sdk/client/**/*.ts linguist-generated=true

*.sh text eol=lf
24 changes: 18 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Run npm install in cli
- name: Run setup typescript-sdk
run: npm ci && npm run build
working-directory: ./open-api/typescript-sdk

- name: Run npm install (cli)
run: npm ci

- name: Run npm install in server
- name: Run npm install (server)
run: npm ci
working-directory: ./server

Expand Down Expand Up @@ -143,10 +147,14 @@ jobs:
with:
submodules: "recursive"

- name: Run npm install in cli
- name: Run setup typescript-sdk
run: npm ci && npm run build
working-directory: ./open-api/typescript-sdk

- name: Run npm install (cli)
run: npm ci

- name: Run npm install in server
- name: Run npm install (server)
run: npm ci
working-directory: ./server

Expand All @@ -164,6 +172,10 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Run setup typescript-sdk
run: npm ci && npm run build
working-directory: ./open-api/typescript-sdk

- name: Run npm install
run: npm ci

Expand Down Expand Up @@ -237,14 +249,14 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Run API generation
run: npm --prefix server run api:generate
run: make open-api
- name: Find file changes
uses: tj-actions/verify-changed-files@v13.1
id: verify-changed-files
with:
files: |
mobile/openapi
web/src/api/open-api
open-api/typescript-sdk
- name: Verify files have not changed
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**/node_modules/**

.DS_Store
.vscode/*
!.vscode/launch.json
Expand All @@ -12,3 +14,5 @@ mobile/gradle.properties
mobile/openapi/pubspec.lock
mobile/*.jks
mobile/libisar.dylib

open-api/typescript-sdk/build
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ prod:
prod-scale:
docker compose -f ./docker/docker-compose.prod.yml up --build -V --scale immich-server=3 --scale immich-microservices=3 --remove-orphans

api:
npm --prefix server run api:generate
.PHONY: open-api
open-api:
cd ./open-api && bash ./bin/generate-open-api.sh

open-api-dart:
cd ./open-api && bash ./bin/generate-open-api.sh dart

open-api-typescript:
cd ./open-api && bash ./bin/generate-open-api.sh typescript

sql:
npm --prefix server run sql:generate
Expand Down
1 change: 0 additions & 1 deletion cli/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ node_modules
.env
.env.*
!.env.example
src/api/open-api
*.md
*.json
coverage
Expand Down
35 changes: 30 additions & 5 deletions cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"cli"
],
"dependencies": {
"@immich/sdk": "file:../open-api/typescript-sdk",
"axios": "^1.6.2",
"byte-size": "^8.1.1",
"cli-progress": "^3.12.0",
Expand Down Expand Up @@ -57,7 +58,7 @@
"format": "prettier --check .",
"format:fix": "prettier --write .",
"check": "tsc --noEmit",
"test:e2e": "NODE_OPTIONS='--experimental-vm-modules' jest --config test/e2e/jest-e2e.json --runInBand"
"test:e2e": "jest --config test/e2e/jest-e2e.json --runInBand"
},
"jest": {
"clearMocks": true,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/api/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ServerInfoApi,
SystemConfigApi,
UserApi,
} from './open-api';
} from '@immich/sdk';
import { ApiConfiguration } from '../cores/api-configuration';
import FormData from 'form-data';

Expand Down
2 changes: 1 addition & 1 deletion cli/src/cli/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ImmichApi } from '../api/client';
import { SessionService } from '../services/session.service';
import { LoginError } from '../cores/errors/login-error';
import { exit } from 'node:process';
import { ServerVersionResponseDto, UserResponseDto } from 'src/api/open-api';
import { ServerVersionResponseDto, UserResponseDto } from '@immich/sdk';
import { BaseOptionsDto } from 'src/cores/dto/base-options-dto';

export abstract class BaseCommand {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/login/key.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseCommand } from '../../cli/base-command';

export default class LoginKey extends BaseCommand {
export class LoginKey extends BaseCommand {
public async run(instanceUrl: string, apiKey: string): Promise<void> {
console.log('Executing API key auth flow...');

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/logout.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseCommand } from '../cli/base-command';

export default class Logout extends BaseCommand {
export class Logout extends BaseCommand {
public static readonly description = 'Logout and remove persisted credentials';

public async run(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/server-info.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseCommand } from '../cli/base-command';

export default class ServerInfo extends BaseCommand {
export class ServerInfo extends BaseCommand {
public async run() {
await this.connect();
const { data: versionInfo } = await this.immichApi.serverInfoApi.getServerVersion();
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import fs from 'node:fs';
import cliProgress from 'cli-progress';
import byteSize from 'byte-size';
import { BaseCommand } from '../cli/base-command';
import axios, { AxiosRequestConfig } from 'axios';
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios';
import FormData from 'form-data';

export default class Upload extends BaseCommand {
export class Upload extends BaseCommand {
uploadLength!: number;

public async run(paths: string[], options: UploadOptionsDto): Promise<void> {
Expand Down Expand Up @@ -172,7 +172,7 @@ export default class Upload extends BaseCommand {
}
}

private async uploadAsset(data: FormData): Promise<axios.AxiosResponse> {
private async uploadAsset(data: FormData): Promise<AxiosResponse> {
const url = this.immichApi.apiConfiguration.instanceUrl + '/asset/upload';

const config: AxiosRequestConfig = {
Expand Down
8 changes: 4 additions & 4 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#! /usr/bin/env node

import { Option, Command } from 'commander';
import Upload from './commands/upload';
import ServerInfo from './commands/server-info';
import LoginKey from './commands/login/key';
import Logout from './commands/logout';
import { Upload } from './commands/upload';
import { ServerInfo } from './commands/server-info';
import { LoginKey } from './commands/login/key';
import { Logout } from './commands/logout';
import { version } from '../package.json';

import path from 'node:path';
Expand Down
5 changes: 2 additions & 3 deletions cli/src/services/session.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import {
const mockPingServer = jest.fn(() => Promise.resolve({ data: { res: 'pong' } }));
const mockUserInfo = jest.fn(() => Promise.resolve({ data: { email: 'admin@example.com' } }));

jest.mock('../api/open-api', () => {
jest.mock('@immich/sdk', () => {
return {
__esModule: true,
...jest.requireActual('../api/open-api'),
...jest.requireActual('@immich/sdk'),
UserApi: jest.fn().mockImplementation(() => {
return { getMyUserInfo: mockUserInfo };
}),
Expand Down
2 changes: 1 addition & 1 deletion cli/test/e2e/jest-e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"testRegex": ".e2e-spec.ts$",
"testTimeout": 6000000,
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
"^.+\\.ts$": "ts-jest"
},
"collectCoverageFrom": [
"<rootDir>/src/**/*.(t|j)s",
Expand Down
4 changes: 2 additions & 2 deletions cli/test/e2e/login-key.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from 'src/api/open-api';
import LoginKey from 'src/commands/login/key';
import { LoginResponseDto } from '@immich/sdk';
import { LoginKey } from 'src/commands/login/key';
import { LoginError } from 'src/cores/errors/login-error';
import { CLI_BASE_OPTIONS, spyOnConsole } from 'test/cli-test-utils';

Expand Down
4 changes: 2 additions & 2 deletions cli/test/e2e/server-info.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from 'src/api/open-api';
import ServerInfo from 'src/commands/server-info';
import { LoginResponseDto } from '@immich/sdk';
import { ServerInfo } from 'src/commands/server-info';
import { CLI_BASE_OPTIONS, spyOnConsole } from 'test/cli-test-utils';

describe(`server-info (e2e)`, () => {
Expand Down
4 changes: 2 additions & 2 deletions cli/test/e2e/upload.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { APIKeyCreateResponseDto } from '@app/domain';
import { api } from '@test/../e2e/api/client';
import { IMMICH_TEST_ASSET_PATH, restoreTempFolder, testApp } from '@test/../e2e/jobs/utils';
import { LoginResponseDto } from 'src/api/open-api';
import Upload from 'src/commands/upload';
import { LoginResponseDto } from '@immich/sdk';
import { Upload } from 'src/commands/upload';
import { CLI_BASE_OPTIONS, spyOnConsole } from 'test/cli-test-utils';

describe(`upload (e2e)`, () => {
Expand Down
3 changes: 1 addition & 2 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "Node16",
"module": "commonjs",
"strict": true,
"declaration": true,
"removeComments": true,
Expand All @@ -9,7 +9,6 @@
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"target": "es2021",
"moduleResolution": "node16",
"sourceMap": true,
"outDir": "./dist",
"incremental": true,
Expand Down
Loading
Loading