Skip to content
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
20 changes: 12 additions & 8 deletions packages/effect-memfs/src/MemoryFileSystemError.schema.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Predicate, Schema } from 'effect'
import * as Error from 'effect/PlatformError'

export class ShapeRefusal extends Schema.TaggedError<ShapeRefusal>()('ShapeRefusal', {
method: Schema.String,
cause: Schema.optional(Schema.Unknown),
}) {
export class ShapeRefusal
extends Schema.TaggedError<ShapeRefusal, { readonly brand: unique symbol }>()('ShapeRefusal', {
method: Schema.String,
cause: Schema.optional(Schema.Unknown),
})
{
override get message(): string {
return `The "${this.method}" call was given a value that is not a memory file system driver`
}
}

export class CursorRefusal extends Schema.TaggedError<CursorRefusal>()('CursorRefusal', {
method: Schema.String,
cause: Schema.optional(Schema.Unknown),
}) {
export class CursorRefusal
extends Schema.TaggedError<CursorRefusal, { readonly brand: unique symbol }>()('CursorRefusal', {
method: Schema.String,
cause: Schema.optional(Schema.Unknown),
})
{
override get message(): string {
return `The "${this.method}" call would move the cursor before the start of the file`
}
Expand Down
18 changes: 10 additions & 8 deletions packages/effect-memfs/src/decode-watch-event.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ const WatchEventDecisionTypeId: unique symbol = Symbol.for(
)
type WatchEventDecisionTypeId = typeof WatchEventDecisionTypeId

export class WatchCreate extends Schema.TaggedClass<WatchCreate>()('WatchCreate', {
export class WatchCreate extends Schema.TaggedClass<WatchCreate, { readonly brand: unique symbol }>()('WatchCreate', {
path: Schema.String,
}) {
readonly [WatchEventDecisionTypeId] = WatchEventDecisionTypeId
}

export class WatchUpdate extends Schema.TaggedClass<WatchUpdate>()('WatchUpdate', {
export class WatchUpdate extends Schema.TaggedClass<WatchUpdate, { readonly brand: unique symbol }>()('WatchUpdate', {
path: Schema.String,
}) {
readonly [WatchEventDecisionTypeId] = WatchEventDecisionTypeId
}

export class WatchRemove extends Schema.TaggedClass<WatchRemove>()('WatchRemove', {
export class WatchRemove extends Schema.TaggedClass<WatchRemove, { readonly brand: unique symbol }>()('WatchRemove', {
path: Schema.String,
}) {
readonly [WatchEventDecisionTypeId] = WatchEventDecisionTypeId
Expand All @@ -30,10 +30,12 @@ export type WatchEventDecision = typeof WatchEventDecision.Type
export const DriverWatchEventType = Schema.Literals(['rename', 'change'])
export type DriverWatchEventType = typeof DriverWatchEventType.Type

export class DriverWatchEvent extends Schema.TaggedClass<DriverWatchEvent>()('DriverWatchEvent', {
eventType: DriverWatchEventType,
filename: Schema.String,
exists: Schema.Boolean,
}) {
export class DriverWatchEvent
extends Schema.TaggedClass<DriverWatchEvent, { readonly brand: unique symbol }>()('DriverWatchEvent', {
eventType: DriverWatchEventType,
filename: Schema.String,
exists: Schema.Boolean,
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}
4 changes: 1 addition & 3 deletions packages/effect-memfs/src/open-file.handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ const writeChunk = (self: OpenFile, pending: Uint8Array): Effect.Effect<WriteAll
planWriteContinuation(new WriteAllChunk({ fd: self.fd, written: bytesWritten, remaining: pending.length })),
).pipe(
Effect.mapError(writeZeroRefusal),
Effect.flatMap((decision) =>
advance(self, BigInt(writtenOf(decision, pending.length))).pipe(Effect.as(decision))
),
Effect.tap((decision) => advance(self, BigInt(writtenOf(decision, pending.length)))),
)
),
)
Expand Down
10 changes: 6 additions & 4 deletions packages/effect-memfs/src/plan-read-slice.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ const ReadSliceDecisionTypeId: unique symbol = Symbol.for(
)
type ReadSliceDecisionTypeId = typeof ReadSliceDecisionTypeId

export class ReadWhole extends Schema.TaggedClass<ReadWhole>()('ReadWhole', {}) {
export class ReadWhole extends Schema.TaggedClass<ReadWhole, { readonly brand: unique symbol }>()('ReadWhole', {}) {
readonly [ReadSliceDecisionTypeId] = ReadSliceDecisionTypeId
}

export class ReadPartial extends Schema.TaggedClass<ReadPartial>()('ReadPartial', {
export class ReadPartial extends Schema.TaggedClass<ReadPartial, { readonly brand: unique symbol }>()('ReadPartial', {
bytesRead: Schema.Finite,
}) {
readonly [ReadSliceDecisionTypeId] = ReadSliceDecisionTypeId
}

export class ReadExhausted extends Schema.TaggedClass<ReadExhausted>()('ReadExhausted', {}) {
export class ReadExhausted
extends Schema.TaggedClass<ReadExhausted, { readonly brand: unique symbol }>()('ReadExhausted', {})
{
readonly [ReadSliceDecisionTypeId] = ReadSliceDecisionTypeId
}

export const ReadSliceDecision = Schema.Union([ReadWhole, ReadPartial, ReadExhausted])
export type ReadSliceDecision = typeof ReadSliceDecision.Type

export class ReadSlice extends Schema.TaggedClass<ReadSlice>()('ReadSlice', {
export class ReadSlice extends Schema.TaggedClass<ReadSlice, { readonly brand: unique symbol }>()('ReadSlice', {
bytesRead: Schema.Finite,
requested: Schema.Finite,
}) {
Expand Down
16 changes: 9 additions & 7 deletions packages/effect-memfs/src/plan-seek-position.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const SeekPositionDecisionTypeId: unique symbol = Symbol.for(
)
type SeekPositionDecisionTypeId = typeof SeekPositionDecisionTypeId

export class SeekMoved extends Schema.TaggedClass<SeekMoved>()('SeekMoved', {
export class SeekMoved extends Schema.TaggedClass<SeekMoved, { readonly brand: unique symbol }>()('SeekMoved', {
position: Schema.BigInt,
}) {
readonly [SeekPositionDecisionTypeId] = SeekPositionDecisionTypeId
}

export class SeekRefused extends Schema.TaggedClass<SeekRefused>()('SeekRefused', {
export class SeekRefused extends Schema.TaggedClass<SeekRefused, { readonly brand: unique symbol }>()('SeekRefused', {
position: Schema.BigInt,
}) {
readonly [SeekPositionDecisionTypeId] = SeekPositionDecisionTypeId
Expand All @@ -21,10 +21,12 @@ export class SeekRefused extends Schema.TaggedClass<SeekRefused>()('SeekRefused'
export const SeekPositionDecision = Schema.Union([SeekMoved, SeekRefused])
export type SeekPositionDecision = typeof SeekPositionDecision.Type

export class PlanSeekPosition extends Schema.TaggedClass<PlanSeekPosition>()('PlanSeekPosition', {
position: Schema.BigInt,
offset: Schema.BigInt,
from: Schema.Literals(['start', 'current']),
}) {
export class PlanSeekPosition
extends Schema.TaggedClass<PlanSeekPosition, { readonly brand: unique symbol }>()('PlanSeekPosition', {
position: Schema.BigInt,
offset: Schema.BigInt,
from: Schema.Literals(['start', 'current']),
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}
8 changes: 6 additions & 2 deletions packages/effect-memfs/src/plan-seek-position.workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { Match, Schema } from 'effect'
import * as Result from 'effect/Result'
import { PlanSeekPosition, SeekMoved, SeekPositionDecision, SeekRefused } from './plan-seek-position.schema.js'

class SeekBeforeStart extends Schema.TaggedClass<SeekBeforeStart>()('SeekBeforeStart', {}) {}
class SeekWithinFile extends Schema.TaggedClass<SeekWithinFile>()('SeekWithinFile', {}) {}
class SeekBeforeStart
extends Schema.TaggedClass<SeekBeforeStart, { readonly brand: unique symbol }>()('SeekBeforeStart', {})
{}
class SeekWithinFile
extends Schema.TaggedClass<SeekWithinFile, { readonly brand: unique symbol }>()('SeekWithinFile', {})
{}

type SeekStepOutcome = SeekBeforeStart | SeekWithinFile

Expand Down
20 changes: 12 additions & 8 deletions packages/effect-memfs/src/plan-truncate-cursor.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ const TruncateCursorDecisionTypeId: unique symbol = Symbol.for(
)
type TruncateCursorDecisionTypeId = typeof TruncateCursorDecisionTypeId

export class CursorKept extends Schema.TaggedClass<CursorKept>()('CursorKept', {
export class CursorKept extends Schema.TaggedClass<CursorKept, { readonly brand: unique symbol }>()('CursorKept', {
position: Schema.BigInt,
}) {
readonly [TruncateCursorDecisionTypeId] = TruncateCursorDecisionTypeId
}

export class CursorClamped extends Schema.TaggedClass<CursorClamped>()('CursorClamped', {
position: Schema.BigInt,
}) {
export class CursorClamped
extends Schema.TaggedClass<CursorClamped, { readonly brand: unique symbol }>()('CursorClamped', {
position: Schema.BigInt,
})
{
readonly [TruncateCursorDecisionTypeId] = TruncateCursorDecisionTypeId
}

export const TruncateCursorDecision = Schema.Union([CursorKept, CursorClamped])
export type TruncateCursorDecision = typeof TruncateCursorDecision.Type

export class PlanTruncateCursor extends Schema.TaggedClass<PlanTruncateCursor>()('PlanTruncateCursor', {
position: Schema.BigInt,
length: Schema.Int,
}) {
export class PlanTruncateCursor
extends Schema.TaggedClass<PlanTruncateCursor, { readonly brand: unique symbol }>()('PlanTruncateCursor', {
position: Schema.BigInt,
length: Schema.Int,
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}
26 changes: 16 additions & 10 deletions packages/effect-memfs/src/plan-write-continuation.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ const WriteAllChunkDecisionTypeId: unique symbol = Symbol.for(
)
type WriteAllChunkDecisionTypeId = typeof WriteAllChunkDecisionTypeId

export class WriteContinued extends Schema.TaggedClass<WriteContinued>()('WriteContinued', {
skip: Schema.Finite,
}) {
export class WriteContinued
extends Schema.TaggedClass<WriteContinued, { readonly brand: unique symbol }>()('WriteContinued', {
skip: Schema.Finite,
})
{
readonly [WriteAllChunkDecisionTypeId] = WriteAllChunkDecisionTypeId
}

export class WriteDrained extends Schema.TaggedClass<WriteDrained>()('WriteDrained', {}) {
export class WriteDrained
extends Schema.TaggedClass<WriteDrained, { readonly brand: unique symbol }>()('WriteDrained', {})
{
readonly [WriteAllChunkDecisionTypeId] = WriteAllChunkDecisionTypeId
}

export class WriteZero extends Schema.TaggedError<WriteZero>()('WriteZero', {
export class WriteZero extends Schema.TaggedError<WriteZero, { readonly brand: unique symbol }>()('WriteZero', {
fd: Schema.Finite,
message: Schema.String,
cause: Schema.optional(Schema.Unknown),
Expand All @@ -27,10 +31,12 @@ export class WriteZero extends Schema.TaggedError<WriteZero>()('WriteZero', {
export const WriteAllChunkDecision = Schema.Union([WriteContinued, WriteDrained])
export type WriteAllChunkDecision = typeof WriteAllChunkDecision.Type

export class WriteAllChunk extends Schema.TaggedClass<WriteAllChunk>()('WriteAllChunk', {
fd: Schema.Finite,
written: Schema.Finite,
remaining: Schema.Finite,
}) {
export class WriteAllChunk
extends Schema.TaggedClass<WriteAllChunk, { readonly brand: unique symbol }>()('WriteAllChunk', {
fd: Schema.Finite,
written: Schema.Finite,
remaining: Schema.Finite,
})
{
static readonly [Workflow.InstrumentationBrand] = {} as const
}
8 changes: 5 additions & 3 deletions packages/effect-memfs/tests/__fixtures__/open-file.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { Match, Schema } from 'effect'
/** A note of five letters, opened for reading and writing, is the subject. */
export const OpenedNoteText = 'hello'

export class HandleLeftOpen extends Schema.TaggedError<HandleLeftOpen>()('HandleLeftOpen', {
reason: Schema.String,
}) {}
export class HandleLeftOpen
extends Schema.TaggedError<HandleLeftOpen, { readonly brand: unique symbol }>()('HandleLeftOpen', {
reason: Schema.String,
})
{}

const Written = Schema.Literals(['a', 'bc', 'def'])
const Size = Schema.Literals([1, 2, 3, 5, 8])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ Feature('Handing back scratch space when the work using it is over')
When('a piece of work borrows scratch space and then finishes')('outcome', (s) =>
Effect.gen(function*() {
const borrowed = yield* Effect.scoped(
Effect.flatMap(
Effect.tap(
Effect.flatMap(filesystem, row.borrow),
(path) => Effect.as(s.fs.stat(path), path),
(path) => s.fs.stat(path),
),
)
return yield* Effect.flip(s.fs.stat(borrowed))
Expand Down
Loading