MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeNotes

Function makeNotes

packages/effect/test/ui/StreamQuery.test.ts:44–99  ·  view source on GitHub ↗
(options: {
  readonly idleTimeToLive?: Duration.Input
  readonly refetchInterval?: Duration.Input
  readonly persist?: boolean
  readonly reactivityKeys?: (
    args: { readonly id: string }
  ) => Reactivity.KeysInput
} = {})

Source from the content-addressed store, hash-verified

42}
43
44const makeNotes = (options: {
45 readonly idleTimeToLive?: Duration.Input
46 readonly refetchInterval?: Duration.Input
47 readonly persist?: boolean
48 readonly reactivityKeys?: (
49 args: { readonly id: string }
50 ) => Reactivity.KeysInput
51} = {}) => {
52 const streams: Array<NoteStream> = []
53 class GetNote extends Query.StreamService<GetNote>()(
54 "notes/GetNote",
55 // @ts-expect-error: a stream query doesn't poll, even through a variable
56 {
57 args: { id: Schema.String },
58 success: Note,
59 error: Schema.String,
60 ...options
61 }
62 ) {
63 static readonly layer = this.toLayer(({ id }) =>
64 Stream.callback<Note, string>((queue) =>
65 Effect.acquireRelease(
66 Effect.map(Effect.context<never>(), (context) => {
67 const handle: NoteStream = {
68 id,
69 emit: (title) => {
70 Queue.offerUnsafe(queue, { id, title })
71 },
72 fail: (error) => {
73 Queue.failCauseUnsafe(queue, Cause.fail(error))
74 },
75 end: () => {
76 Queue.endUnsafe(queue)
77 },
78 reconnect: () => {
79 Effect.runSyncWith(context)(Query.reconnecting)
80 },
81 closed: false
82 }
83 streams.push(handle)
84 return handle
85 }),
86 (handle) =>
87 Effect.sync(() => {
88 handle.closed = true
89 })
90 )
91 )
92 )
93 }
94 return {
95 streams,
96 GetNote,
97 provide: Effect.provide(Layer.merge(GetNote.layer, TestQuery.layer()))
98 }
99}
100
101const watch = Effect.fnUntraced(

Callers 2

EntitySql.test.tsFile · 0.85

Calls 3

mergeMethod · 0.65
provideMethod · 0.45
layerMethod · 0.45

Tested by

no test coverage detected