Skip to content

Commit

Permalink
Move services to separate layer
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyfran committed Jul 26, 2024
1 parent d8787bb commit 694bf0c
Show file tree
Hide file tree
Showing 26 changed files with 70 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"packages/components/*",
"packages/core/*",
"packages/infrastructure/*",
"packages/services/*",
"packages/workflows/*",
"packages/workers/*"
]
Expand Down
2 changes: 1 addition & 1 deletion packages/components/state/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dependencies": {
"@echo/components-effect-bridge": "^1.0.0",
"@echo/core-types": "^1.0.0",
"@echo/infrastructure-bootstrap": "^1.0.0",
"@echo/services-bootstrap": "^1.0.0",
"effect": "^3.2.8",
"jotai": "^2.8.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/components/state/src/provider.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type ProviderMetadata,
type ProviderStatus,
} from "@echo/core-types";
import { MainLive } from "@echo/infrastructure-bootstrap";
import { MainLive } from "@echo/services-bootstrap";
import { Effect, Fiber } from "effect";
import { atom, useAtom } from "jotai";
import { useCallback, useRef } from "react";
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export * from "./artist";
export * from "./authentication";
export * from "./common";
export * from "./file-system";
export * from "./player-state";
export * from "./provider-metadata";
export * from "./track";
32 changes: 32 additions & 0 deletions packages/core/types/src/model/player-state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Option } from "effect";
import type { Track } from "./track";

/**
* Defines whether the player is playing, paused or stopped.
*/
export type PlayingStatus = "playing" | "paused" | "stopped";

/**
* Represents the current state of the player.
*/
export type PlayerState = {
/**
* Whether the player is playing, paused or stopped.
*/
status: PlayingStatus;

/**
* Current track that is being played, if any.
*/
currentTrack: Option.Option<Track>;

/**
* List of tracks that have been played before the current track.
*/
previouslyPlayedTracks: Track[];

/**
* List of tracks that will be played after the current track.
*/
comingUpTracks: Track[];
};
1 change: 1 addition & 0 deletions packages/core/types/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./database";
export * from "./library";
export * from "./metadata-provider";
export * from "./mediaProvider";
export * from "./player";
18 changes: 18 additions & 0 deletions packages/core/types/src/services/player.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Context, Effect } from "effect";
import type { Album } from "../model";

/**
* Service that provides a way to interact with the player and its state.
*/
export type Player = {
/**
* Plays the given album, detecting the source from each track and delegating
* the playback to the appropriate media provider.
*/
readonly playAlbum: (album: Album) => Effect.Effect<void>;
};

/**
* Tag to identify the player service.
*/
export const Player = Context.GenericTag<Player>("@echo/core-types/Player");
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@echo/infrastructure-bootstrap",
"name": "@echo/services-bootstrap",
"private": true,
"version": "1.0.0",
"description": "Contains the Bootstrap related infrastructure",
"description": "Orchestrates the initialization of the layers for the application and workers",
"main": "index.js",
"scripts": {
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
Expand All @@ -13,7 +13,7 @@
"@echo/infrastructure-broadcast-channel": "^1.0.0",
"@echo/infrastructure-browser-crypto": "^1.0.0",
"@echo/infrastructure-dexie-database": "^1.0.0",
"@echo/infrastructure-library": "^1.0.0",
"@echo/services-library": "^1.0.0",
"@echo/infrastructure-mmb-metadata-provider": "^1.0.0",
"@echo/infrastructure-onedrive-provider": "^1.0.0",
"@echo/workers-media-provider": "^1.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from "@echo/infrastructure-broadcast-channel";
import { BrowserCryptoLive } from "@echo/infrastructure-browser-crypto";
import { DexieDatabaseLive } from "@echo/infrastructure-dexie-database";
import { LibraryLive } from "@echo/infrastructure-library";
import { LibraryLive } from "@echo/services-library";
import { MmbMetadataProviderLive } from "@echo/infrastructure-mmb-metadata-provider";
import { LazyLoadedProviderLive } from "./loaders/provider";
import { AppConfigLive } from "./app-config";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type LazyLoadedProvider = {
* Tag to identify the lazy loaded provider service.
*/
export const LazyLoadedProvider = Context.GenericTag<LazyLoadedProvider>(
"@echo/infrastructure-bootstrap/LazyLoadedProvider",
"@echo/services-bootstrap/LazyLoadedProvider",
);

/**
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@echo/infrastructure-library",
"name": "@echo/services-library",
"private": true,
"version": "1.0.0",
"description": "Implementation of the library service that uses the underlying database mechanism",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@echo/components-effect-bridge": "^1.0.0",
"@echo/components-state": "^1.0.0",
"@echo/core-types": "^1.0.0",
"@echo/infrastructure-bootstrap": "^1.0.0",
"@echo/services-bootstrap": "^1.0.0",
"effect": "^3.2.8",
"jotai": "^2.8.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
providerStateAtom,
} from "@echo/components-state";
import { Effect, Fiber, Match } from "effect";
import { LazyLoadedProvider, MainLive } from "@echo/infrastructure-bootstrap";
import { LazyLoadedProvider, MainLive } from "@echo/services-bootstrap";
import { useAtom } from "jotai";

const retrieveLazyLoader = Effect.gen(function* () {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { createRoot } from "react-dom/client";
import { App } from "./App";
import { initializeWorkers } from "@echo/infrastructure-bootstrap";
import { initializeWorkers } from "@echo/services-bootstrap";

initializeWorkers();

Expand Down
2 changes: 1 addition & 1 deletion packages/workers/media-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@echo/core-types": "^1.0.0",
"@echo/infrastructure-broadcast-channel": "^1.0.0",
"@echo/infrastructure-browser-crypto": "^1.0.0",
"@echo/infrastructure-bootstrap": "^1.0.0",
"@echo/services-bootstrap": "^1.0.0",
"@effect/schema": "^0.67.18",
"effect": "^3.2.8"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { WorkerLive } from "@echo/infrastructure-bootstrap";
import { WorkerLive } from "@echo/services-bootstrap";
import { Effect, Match, Ref, Stream } from "effect";
import * as S from "@effect/schema/Schema";
import { InitMessage, init } from "./init";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Database,
Crypto,
} from "@echo/core-types";
import { LazyLoadedProvider } from "@echo/infrastructure-bootstrap";
import { LazyLoadedProvider } from "@echo/services-bootstrap";
import { Effect, Match, Ref } from "effect";
import type { WorkerState } from "../state";
import { isValidToken } from "@echo/core-auth";
Expand Down
7 changes: 3 additions & 4 deletions packages/workers/media-provider/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type WorkerState = {
/**
* Tag that can provide a ref to the current worker state.
*/
export class WorkerStateRef extends Context.Tag("")<
WorkerStateRef,
Ref.Ref<WorkerState>
>() {}
export class WorkerStateRef extends Context.Tag(
"@echo/workers-media-provider/WorkerStateRef",
)<WorkerStateRef, Ref.Ref<WorkerState>>() {}

0 comments on commit 694bf0c

Please sign in to comment.