Skip to content

Instantly share code, notes, and snippets.

View tim-smart's full-sized avatar

Tim tim-smart

View GitHub Profile
import {
Data,
Effect,
Layer,
pipe,
PubSub,
Schedule,
Scope,
Stream,
} from "effect"
import * as Fs from "node:fs/promises"
export async function* readLinesReverse(path: string, chunkSize = 1024) {
const file = await Fs.open(path, "r")
const stat = await file.stat()
let pos = stat.size
let buffer: Buffer | null = null
while (true) {
pos = Math.max(0, pos - chunkSize)
import {
HttpApi,
HttpApiBuilder,
HttpApiEndpoint,
HttpApiGroup,
HttpApiMiddleware,
HttpApiSwagger,
HttpServerRequest
} from "@effect/platform"
import { NodeHttpServer, NodeRuntime } from "@effect/platform-node"
import { Schema } from "@effect/schema"
import * as Model from "./Model.js"
import { DateTime } from "effect"
export const GroupId = Schema.Number.pipe(Schema.brand("GroupId"))
export class Group extends Model.Class<Group>("Group")({
id: Model.PrimaryKey(GroupId),
name: Schema.NonEmptyTrimmedString,
createdAt: Model.CreatedAt,
import * as Http from "@effect/platform/HttpClient"
Http.request.post("https://accounts.spotify.com/api/token").pipe(
Http.request.basicAuth(clientId, clientSecret)
Http.request.urlParamsBody({
grant_type: "refresh_token",
refresh_token: refreshToken,
client_id: clientId,
}),
Http.client.fetchOk,
import * as Http from "@effect/platform/HttpClient"
import { Schema } from "@effect/schema"
import { Array, Config, Context, Data, Effect, Layer, flow } from "effect"
import { Inngest as Inngest_ } from "inngest"
class InngestRun extends Schema.Class<InngestRun>("InngestRun")({
run_id: Schema.String,
status: Schema.Literal("Running", "Completed", "Failed", "Cancelled"),
}) {
static decodeArray = Http.response.schemaBodyJsonScoped(
import * as Http from "@effect/platform/HttpClient"
import { Context, Effect, Layer, pipe } from "effect"
const headers = {
Accept:
"application/graphql-response+json; charset=utf-8, application/json; charset=utf-8",
"Content-Type": "application/json",
}
export class GraphQLClient extends Context.Tag("graphql-codegen/GraphQLClient")<
import type { Duration, Scope } from "effect"
import { Effect, SynchronizedRef } from "effect"
export const make = (limit: number, window: Duration.DurationInput): Effect.Effect<
<A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>,
never,
Scope.Scope
> =>
Effect.gen(function*(_) {
const scope = yield* _(Effect.scope)
import { Schema, TreeFormatter } from "@effect/schema"
import {
Cause,
Context,
Data,
Effect,
Either,
Layer,
Option,
PrimaryKey,