Skip to content

Commit

Permalink
remove obsolete helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Dec 4, 2023
1 parent 9504d3f commit 7f946cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 48 deletions.
7 changes: 7 additions & 0 deletions .changeset/calm-mails-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@effect-app/prelude": patch
"@effect-app/infra": patch
"@effect-app/core": patch
---

remove obsolete helpers
15 changes: 5 additions & 10 deletions packages/core/vendor/effect-io-tsplus.json
Original file line number Diff line number Diff line change
Expand Up @@ -4857,11 +4857,6 @@
"kind": "fluent",
"name": "flatMap"
},
{
"typeName": "effect/data/Context/Tag",
"kind": "fluent",
"name": "accessWithEffect"
},
{
"kind": "fluent",
"typeName": "effect/io/Effect",
Expand Down Expand Up @@ -4894,6 +4889,11 @@
"definitionName": "andThen",
"definitionKind": "const",
"extensions": [
{
"typeName": "effect/data/Context/Tag",
"kind": "fluent",
"name": "andThen"
},
{
"kind": "fluent",
"typeName": "effect/io/Effect",
Expand Down Expand Up @@ -5645,11 +5645,6 @@
"kind": "fluent",
"name": "map"
},
{
"typeName": "effect/data/Context/Tag",
"kind": "fluent",
"name": "accessWith"
},
{
"kind": "fluent",
"typeName": "effect/io/Effect",
Expand Down
9 changes: 2 additions & 7 deletions packages/infra/_src/services/RepositoryBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { makeCodec } from "@effect-app/infra/api/codec"
import { makeFilters } from "@effect-app/infra/filter"
import type { Schema } from "@effect-app/prelude"
import { EParserFor } from "@effect-app/prelude/schema"
import type { ServiceHelpers } from "@effect-app/prelude/service"
import { TagClassBase } from "@effect-app/prelude/service"
import type { InvalidStateError, OptimisticConcurrencyException } from "../errors.js"
import { ContextMapContainer } from "./Store/ContextMapContainer.js"

Expand All @@ -24,7 +22,7 @@ export abstract class RepositoryBaseC<
PM extends { id: string },
Evt,
ItemType extends string
> extends TagClassBase<unknown>() {
> {
abstract readonly itemType: ItemType
abstract readonly find: (id: T["id"]) => Effect<never, never, Opt<T>>
abstract readonly all: Effect<never, never, T[]>
Expand Down Expand Up @@ -348,12 +346,11 @@ export function makeStore<
}

export interface Repos<
Service,
T extends { id: string },
PM extends { id: string; _etag: string | undefined },
Evt,
ItemType extends string
> extends ServiceHelpers<Service> {
> {
make<R = never, E = never, R2 = never>(
args: [Evt] extends [never] ? {
makeInitial?: Effect<R, E, readonly T[]>
Expand Down Expand Up @@ -413,7 +410,6 @@ export const RepositoryBaseImpl = <Service>() => {
& (abstract new() => RepositoryBaseC1<T, PM, Evt, ItemType>)
& Tag<Service, Service>
& Repos<
Service,
T,
PM,
Evt,
Expand Down Expand Up @@ -451,7 +447,6 @@ export const RepositoryDefaultImpl = <Service>() => {
) => RepositoryBaseC2<T, PM, Evt, ItemType>)
& Tag<Service, Service>
& Repos<
Service,
T,
PM,
Evt,
Expand Down
33 changes: 2 additions & 31 deletions packages/prelude/_src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* https://github.com/microsoft/TypeScript/issues/52644
*/

import type * as C from "effect/Cause"
import type { TagTypeId as TagTypeIdOriginal } from "effect/Context"

export const ServiceTag = Symbol()
Expand Down Expand Up @@ -54,44 +53,16 @@ export function assignTag<Id, Service = Id>(key?: unknown) {
}
}

export interface ServiceHelpers<Id, Service = Id> {
readonly andThen: {
<X>(
f: (a: Service) => X
): [X] extends [Effect<infer R1, infer E1, infer A1>] ? Effect<Service | R1, E1, A1>
: [X] extends [Promise<infer A1>] ? Effect<Service, C.UnknownException, A1>
: Effect<Service, never, X>
<X>(f: X): [X] extends [Effect<infer R1, infer E1, infer A1>] ? Effect<Service | R1, E1, A1>
: [X] extends [Promise<infer A1>] ? Effect<Service, C.UnknownException, A1>
: Effect<Service, never, X>
}
readonly makeLayer: (svc: Service) => Layer<never, never, Service>
}

export const TagClassBase = <Id, Service = Id>() => {
abstract class TagClassBase {
static readonly andThen = (f: any): any => {
return Effect.andThen(this as Service as Tag<Service, Service>, f)
}
static readonly map = <B>(f: (a: Service) => B): Effect<Service, never, B> => {
return Effect.map(this as Service as Tag<Service, Service>, f)
}
static readonly makeLayer = (svc: Service) => {
return Layer.succeed(this as Service as Tag<Service, Service>, svc)
}
}
return TagClassBase as ServiceHelpers<Id, Service> & (abstract new() => {})
}
export function TagClass<Id, Service = Id>(key?: unknown) {
abstract class TagClass extends TagClassBase<Id, Service>() {}
abstract class TagClass {}

return assignTag<Id, Service>(key)(TagClass)
}

/** @deprecated use `Id` of TagClass for unique id */
export function ServiceTaggedClass<Id, Service = Id>() {
return <Key extends PropertyKey>(_: Key) => {
abstract class ServiceTaggedClassC extends TagClassBase() {
abstract class ServiceTaggedClassC {
static make = (t: Omit<Service, Key>) => {
return t as Service
}
Expand Down

0 comments on commit 7f946cb

Please sign in to comment.