@mepuka/skygent 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,6 +61,7 @@
61
61
 
62
62
  import { Chunk, Clock, Context, Duration, Effect, Fiber, Layer, Option, Ref, Schedule, Schema, Stream } from "effect";
63
63
  import { messageFromCause } from "./shared.js";
64
+ import type { BskyError } from "../domain/errors.js";
64
65
  import { FilterRuntime } from "./filter-runtime.js";
65
66
  import { PostParser } from "./post-parser.js";
66
67
  import { StoreCommitter } from "./store-commit.js";
@@ -155,7 +156,7 @@ export class SyncEngine extends Context.Tag("@skygent/SyncEngine")<
155
156
  source: DataSource,
156
157
  target: StoreRef,
157
158
  filter: FilterExpr,
158
- options?: { readonly policy?: SyncUpsertPolicy }
159
+ options?: { readonly policy?: SyncUpsertPolicy; readonly limit?: number }
159
160
  ) => Effect.Effect<SyncResult, SyncError>;
160
161
  readonly watch: (config: WatchConfig) => Stream.Stream<SyncEvent, SyncError>;
161
162
  }
@@ -172,7 +173,12 @@ export class SyncEngine extends Context.Tag("@skygent/SyncEngine")<
172
173
  const settings = yield* SyncSettings;
173
174
 
174
175
  const sync = Effect.fn("SyncEngine.sync")(
175
- (source: DataSource, target: StoreRef, filter: FilterExpr, options?: { readonly policy?: SyncUpsertPolicy }) =>
176
+ (
177
+ source: DataSource,
178
+ target: StoreRef,
179
+ filter: FilterExpr,
180
+ options?: { readonly policy?: SyncUpsertPolicy; readonly limit?: number }
181
+ ) =>
176
182
  Effect.gen(function* () {
177
183
  const predicate = yield* runtime
178
184
  .evaluateWithMetadata(filter)
@@ -287,7 +293,7 @@ export class SyncEngine extends Context.Tag("@skygent/SyncEngine")<
287
293
  );
288
294
  const pageLimit = settings.pageLimit;
289
295
 
290
- const stream = (() => {
296
+ let stream = (() => {
291
297
  switch (source._tag) {
292
298
  case "Timeline":
293
299
  return client.getTimeline(
@@ -360,7 +366,10 @@ export class SyncEngine extends Context.Tag("@skygent/SyncEngine")<
360
366
  })
361
367
  );
362
368
  }
363
- })();
369
+ })() as Stream.Stream<RawPost, BskyError | SyncError>;
370
+ if (options?.limit !== undefined) {
371
+ stream = stream.pipe(Stream.take(options.limit));
372
+ }
364
373
 
365
374
  type SyncState = {
366
375
  readonly result: SyncResult;