Skip to content

Commit

Permalink
Merge pull request #202 from FoxxMD/validateGranular
Browse files Browse the repository at this point in the history
feat: Improve client/source schema validation generation and error handling
  • Loading branch information
FoxxMD authored Oct 9, 2024
2 parents fdaeb8f + 6b92920 commit db63242
Show file tree
Hide file tree
Showing 28 changed files with 629 additions and 221 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ build
*.secrets
.devcontainer
.vscode
**/act/*
**/act/*
tmp-*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,5 @@ flatpak/generated-sources.json
build
!setupProxy.js
**/generated-sources.*
.github/act/out
.github/act/out
tmp-*
3 changes: 2 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"reporter": "dot",
"extension": "ts",
"import": "tsx/esm",
"spec": "./src/backend/tests/**/*.test.ts"
"spec": "./src/backend/tests/**/*.test.ts",
"exit": true
}
12 changes: 11 additions & 1 deletion config/lastfm.json.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
[
{
"name": "myLastFm",
"name": "myLastFmClient",
"enable": true,
"configureAs": "client",
"data": {
"apiKey": "a89cba1569901a0671d5a9875fed4be1",
"secret": "ec42e09d5ae0ee0f0816ca151008412a",
"redirectUri": "http://localhost:9078/lastfm/callback"
}
},
{
"name": "myLastFmSource",
"enable": true,
"configureAs": "source",
"data": {
"apiKey": "a89cba1569901a0671d5a9875fed4be1",
"secret": "ec42e09d5ae0ee0f0816ca151008412a",
"redirectUri": "http://localhost:9078/lastfm/callback"
}
}
]
11 changes: 10 additions & 1 deletion config/listenbrainz.json.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
[
{
"name": "brainz",
"name": "brainzClient",
"enable": true,
"configureAs": "client",
"data": {
"token": "029b081ba-9156-4pe7-88e5-3be671f5ea2b",
"username": "FoxxMD"
}
},
{
"name": "brainzSource",
"enable": true,
"configureAs": "source",
"data": {
"token": "029b081ba-9156-4pe7-88e5-3be671f5ea2b",
"username": "FoxxMD"
}
}
]
2 changes: 1 addition & 1 deletion config/webscrobbler.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "MyWebScrobbler",
"data": {
"slug": null,
"slug": "MyOptionalSlug",
"whitelist": [],
"blacklist": []
}
Expand Down
144 changes: 126 additions & 18 deletions package-lock.json

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

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"fast-deep-equal": "^3.1.3",
"fixed-size-list": "^0.3.0",
"formidable": "^3.5",
"glob": "^11.0.0",
"gotify": "^1.1.0",
"iso-websocket": "^0.3.0",
"iti": "^0.6.0",
Expand Down Expand Up @@ -157,7 +158,8 @@
"typescript": "^5.5.4",
"typescript-eslint": "^7.0.1",
"typescript-json-schema": "^0.61.0",
"vite": "^5.2.12"
"vite": "^5.2.12",
"with-local-tmp-dir": "^5.1.1"
},
"browserslist": {
"production": [
Expand All @@ -174,6 +176,11 @@
"overrides": {
"spotify-web-api-node": {
"superagent": "$superagent"
},
"with-local-tmp-dir": {
"tmp-promise": {
"tmp": "0.2.1"
}
}
}
}
7 changes: 7 additions & 0 deletions src/backend/common/infrastructure/Atomic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const sourceTypes: SourceType[] = [
'vlc'
];

export const isSourceType = (data: string): data is SourceType => {
return sourceTypes.includes(data as SourceType);
}

export const lowGranularitySources: SourceType[] = ['subsonic', 'ytmusic'];

export type ClientType =
Expand All @@ -59,6 +63,9 @@ export const clientTypes: ClientType[] = [
'lastfm',
'listenbrainz'
];
export const isClientType = (data: string): data is ClientType => {
return clientTypes.includes(data as ClientType);
}

export type InitState = 0 | 1 | 2;
export const NOT_INITIALIZED: InitState = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/backend/common/infrastructure/config/aioConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RequestRetryOptions } from "./common.js";
import { WebhookConfig } from "./health/webhooks.js";
import { CommonSourceOptions, SourceRetryOptions } from "./source/index.js";
import { SourceAIOConfig } from "./source/sources.js";
import { ClientType, SourceType } from "../Atomic.js";


export interface SourceDefaults extends CommonSourceOptions {
Expand Down Expand Up @@ -70,7 +71,22 @@ export interface AIOClientConfig {
clients?: ClientAIOConfig[]
}

export interface AIOClientRelaxedConfig {
clientDefaults?: RequestRetryOptions
clients?: object[]
}

export interface AIOSourceConfig {
sourceDefaults?: SourceRetryOptions
sources?: SourceAIOConfig[]
}

export interface AIOSourceRelaxedConfig {
sourceDefaults?: SourceRetryOptions
sources?: object[]
}

export interface TypedConfig<T = string> {
type: T
// [key: string]: any
}
2 changes: 1 addition & 1 deletion src/backend/common/infrastructure/config/source/deezer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface DeezerData extends CommonSourceData {
* @default "http://localhost:9078/deezer/callback"
* @examples ["http://localhost:9078/deezer/callback"]
* */
redirectUri: string
redirectUri?: string
/**
* optional, how long to wait before calling spotify for new tracks (in seconds)
*
Expand Down
3 changes: 3 additions & 0 deletions src/backend/common/infrastructure/config/source/jellyfin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ export interface JellyApiSourceConfig extends CommonSourceConfig {
export interface JellyApiSourceAIOConfig extends JellyApiSourceConfig {
type: 'jellyfin'
}


export type JellyfinCompatConfig = JellyApiSourceConfig | JellySourceConfig;
2 changes: 1 addition & 1 deletion src/backend/common/infrastructure/config/source/spotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface SpotifySourceData extends CommonSourceData, PollingOptions {
* @default "http://localhost:9078/callback"
* @examples ["http://localhost:9078/callback"]
* */
redirectUri: string
redirectUri?: string
/**
* How long to wait before polling the source API for new tracks (in seconds)
*
Expand Down
Loading

0 comments on commit db63242

Please sign in to comment.