-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
694bf0c
commit 9fae6a3
Showing
24 changed files
with
135 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
}, | ||
"dependencies": { | ||
"@effect/schema": "^0.67.18", | ||
"effect": "^3.2.8" | ||
"effect": "^3.5.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
}, | ||
"dependencies": { | ||
"@echo/core-types": "^1.0.0", | ||
"effect": "^3.2.8" | ||
"effect": "^3.5.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
}, | ||
"dependencies": { | ||
"@echo/core-types": "^1.0.0", | ||
"effect": "^3.2.8" | ||
"effect": "^3.5.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,6 @@ | |
}, | ||
"dependencies": { | ||
"@echo/core-types": "^1.0.0", | ||
"effect": "^3.2.8" | ||
"effect": "^3.5.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { PlayerStateRef } from "./src/state"; | ||
export { PlayerLive } from "./src/player"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@echo/services-player", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "Contains the implementation for the Player service", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@echo/core-types": "^1.0.0", | ||
"effect": "^3.5.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Player, type PlayerState } from "@echo/core-types"; | ||
import { Effect, Layer, Option, PubSub, Ref, Stream } from "effect"; | ||
import { PlayerStateRef } from "./state"; | ||
|
||
const PlayerLiveWithState = Layer.effect( | ||
Player, | ||
Effect.gen(function* () { | ||
const state = yield* PlayerStateRef; | ||
const statePubSub = yield* PubSub.dropping<PlayerState>({ | ||
capacity: 1, | ||
replay: 1, | ||
}); | ||
|
||
// Yield initial state to subscribers. | ||
yield* statePubSub.publish(yield* state.get); | ||
|
||
return Player.of({ | ||
playAlbum: (_album) => | ||
Effect.gen(function* () { | ||
yield* Ref.update(state, (current) => ({ | ||
...current, | ||
status: "playing" as const, | ||
})); | ||
|
||
yield* statePubSub.publish(yield* state.get); | ||
}), | ||
observe: Effect.sync(() => | ||
Stream.fromPubSub(statePubSub).pipe( | ||
Stream.tap((state) => Effect.logInfo("Player state changed", state)), | ||
Stream.ensuring(Effect.logInfo("Player state stream closed")), | ||
), | ||
), | ||
}); | ||
}), | ||
); | ||
|
||
const PlayerStateLive = Layer.effect( | ||
PlayerStateRef, | ||
Ref.make({ | ||
comingUpTracks: [], | ||
previouslyPlayedTracks: [], | ||
currentTrack: Option.none(), | ||
status: "stopped", | ||
} as PlayerState), | ||
); | ||
|
||
export const PlayerLive = PlayerLiveWithState.pipe( | ||
Layer.provide(PlayerStateLive), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { PlayerState } from "@echo/core-types"; | ||
import { Context, Ref } from "effect"; | ||
|
||
/** | ||
* Tag that can provide a ref to the current state of the player. | ||
*/ | ||
export class PlayerStateRef extends Context.Tag( | ||
"@echo/services-player/PlayerStateRef", | ||
)<PlayerStateRef, Ref.Ref<PlayerState>>() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"include": [ | ||
"src", | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 7 additions & 15 deletions
22
tools/plop-templates/infrastructure/template/package.json.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
{ | ||
"name": "@echo/infrastructure-{{dashCase name}}", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "Contains the {{properCase name}} related infrastructure", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@echo/core-types": "^1.0.0", | ||
"effect": "^3.2.8" | ||
} | ||
} | ||
{ "name": "@echo/infrastructure-{{dashCase name}}", "private": true, "version": | ||
"1.0.0", "description": "Contains the | ||
{{properCase name}} | ||
related infrastructure", "main": "index.js", "scripts": { "lint": "eslint . | ||
--ext ts,tsx --report-unused-disable-directives --max-warnings 0", "typecheck": | ||
"tsc --noEmit" }, "dependencies": { "@echo/core-types": "^1.0.0", "effect": | ||
"^3.5.8" } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
{ | ||
"name": "@echo/services-{{dashCase name}}", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "Contains the implementation for the {{properCase name}} service", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"@echo/core-types": "^1.0.0", | ||
"effect": "^3.2.8" | ||
} | ||
} | ||
{ "name": "@echo/services-{{dashCase name}}", "private": true, "version": | ||
"1.0.0", "description": "Contains the implementation for the | ||
{{properCase name}} | ||
service", "main": "index.js", "scripts": { "lint": "eslint . --ext ts,tsx | ||
--report-unused-disable-directives --max-warnings 0", "typecheck": "tsc | ||
--noEmit" }, "dependencies": { "@echo/core-types": "^1.0.0", "effect": "^3.5.8" | ||
} } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters