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

Class Chunk

packages/effect/src/unstable/cluster/Reply.ts:173–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171 * @since 4.0.0
172 */
173export class Chunk<R extends Rpc.Any> extends Data.TaggedClass("Chunk")<{
174 readonly requestId: Snowflake
175 readonly id: Snowflake
176 readonly sequence: number
177 readonly values: NonEmptyReadonlyArray<Rpc.SuccessChunk<R>>
178}> {
179 /**
180 * Marks this value as a runtime cluster reply.
181 *
182 * @since 4.0.0
183 */
184 readonly [TypeId] = TypeId
185
186 /**
187 * Creates an empty chunk reply for the supplied request id.
188 *
189 * @since 4.0.0
190 */
191 static emptyFrom(requestId: Snowflake) {
192 return new Chunk({
193 requestId,
194 id: Snowflake(BigInt(0)),
195 sequence: 0,
196 values: [undefined]
197 })
198 }
199
200 /**
201 * Schema that accepts any runtime chunk reply without validating payload values.
202 *
203 * @since 4.0.0
204 */
205 static readonly Any = Schema.declare((u): u is Chunk<never> => isReply(u) && u._tag === "Chunk")
206
207 /**
208 * Transformation between encoded chunk records and `Chunk` instances.
209 *
210 * @since 4.0.0
211 */
212 static readonly transform: SchemaTransformation.Transformation<any, any> = SchemaTransformation.transform({
213 decode: (a: any) => new Chunk(a),
214 encode: (a) => a as any
215 })
216
217 /**
218 * Builds a chunk schema from the streaming success schema of an RPC.
219 *
220 * @since 4.0.0
221 */
222 static schema<R extends Rpc.Any>(
223 rpc: R
224 ): Schema.declareConstructor<Chunk<R>, Chunk<R>, readonly [Rpc.SuccessExitSchema<R>]> {
225 const successSchema = ((rpc as any as Rpc.AnyWithProps).successSchema as RpcSchema.Stream<any, any>).success
226 if (!successSchema) {
227 return Schema.Never as any
228 }
229 return this.schemaFrom(successSchema) as any
230 }

Callers

nothing calls this directly

Calls 2

isReplyFunction · 0.85
transformMethod · 0.65

Tested by

no test coverage detected