@zapier/kitcore 0.7.0 → 0.8.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @zapier/kitcore
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cec12cd: Added `concatLists`, which lists one page of several paginated lists joined end to end, returning a plain promise of `{ data, nextCursor }`. Pass a page's `nextCursor` to a fresh call to resume the concatenation.
8
+
9
+ Deprecated `concatPaginated` in favor of `concatLists`. It now delegates to `concatLists` and logs a deprecation warning; awaiting it yields the same page, but the page-iterable half of its old return shape is removed.
10
+
11
+ - 769751e: Paginated list results now expose `.pages()`, a plain async iterable over pages. Unlike iterating the result directly (which still works but is deprecated), `.pages()` is not also a promise, so returning it from an `async` function no longer silently collapses it to the first page. `.items()` is unchanged and remains the way to iterate individual items across pages. The `toIterable()` helper is deprecated in favor of `.pages()` and now logs a deprecation warning.
12
+
3
13
  ## 0.7.0
4
14
 
5
15
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -31,6 +31,7 @@ __export(index_exports, {
31
31
  CoreSignal: () => CoreSignal,
32
32
  addPlugin: () => addPlugin,
33
33
  composePlugins: () => composePlugins,
34
+ concatLists: () => concatLists,
34
35
  concatPaginated: () => concatPaginated,
35
36
  coreOptionsPluginRef: () => coreOptionsPluginRef,
36
37
  createAsyncContext: () => createAsyncContext,
@@ -544,53 +545,49 @@ function decodeConcatCursor(incoming) {
544
545
  }
545
546
  return { index: 0, cursor: incoming };
546
547
  }
547
- function concatPaginated({
548
+ async function concatLists({
548
549
  sources,
549
550
  pageSize = 100,
550
551
  cursor
551
552
  }) {
552
553
  if (sources.length === 0) {
553
- const empty = { data: [] };
554
- return Object.assign(Promise.resolve(empty), {
555
- [Symbol.asyncIterator]: async function* () {
556
- yield empty;
557
- }
558
- });
554
+ return { data: [] };
559
555
  }
560
556
  const pageFunction = async (options) => {
561
- let { index, cursor: sourceCursor } = decodeConcatCursor(options.cursor);
557
+ let { index, cursor: listCursor } = decodeConcatCursor(options.cursor);
562
558
  while (index < sources.length) {
563
- const page = await sources[index]({ cursor: sourceCursor });
564
- const hasMoreInSource = page.nextCursor != null;
565
- if (page.data.length === 0 && !hasMoreInSource) {
559
+ const page = await sources[index]({ cursor: listCursor });
560
+ const hasMoreInList = page.nextCursor != null;
561
+ if (page.data.length === 0 && !hasMoreInList) {
566
562
  index++;
567
- sourceCursor = void 0;
563
+ listCursor = void 0;
568
564
  continue;
569
565
  }
570
566
  return {
571
567
  data: page.data,
572
- nextCursor: hasMoreInSource ? encodeConcatCursor(index, page.nextCursor) : index < sources.length - 1 ? encodeConcatCursor(index + 1, void 0) : void 0
568
+ nextCursor: hasMoreInList ? encodeConcatCursor(index, page.nextCursor) : index < sources.length - 1 ? encodeConcatCursor(index + 1, void 0) : void 0
573
569
  };
574
570
  }
575
571
  return { data: [] };
576
572
  };
577
- const iterator = paginateBuffered(pageFunction, { pageSize, cursor });
578
- const firstPagePromise = iterator.next().then((result) => {
579
- if (result.done) {
580
- return { data: [] };
581
- }
582
- return result.value;
583
- });
584
- return Object.assign(firstPagePromise, {
585
- [Symbol.asyncIterator]: async function* () {
586
- yield await firstPagePromise;
587
- for await (const page of { [Symbol.asyncIterator]: () => iterator }) {
588
- yield page;
589
- }
590
- }
591
- });
573
+ const result = await paginateBuffered(pageFunction, {
574
+ pageSize,
575
+ cursor
576
+ }).next();
577
+ return result.done ? { data: [] } : result.value;
578
+ }
579
+ function concatPaginated({
580
+ sources,
581
+ pageSize,
582
+ cursor
583
+ }) {
584
+ logDeprecation("concatPaginated() is deprecated. Use concatLists() instead.");
585
+ return concatLists({ sources, pageSize, cursor });
592
586
  }
593
587
  function toIterable(source) {
588
+ logDeprecation(
589
+ "toIterable() is deprecated. Call .pages() on the paginated result instead."
590
+ );
594
591
  return { [Symbol.asyncIterator]: () => source[Symbol.asyncIterator]() };
595
592
  }
596
593
 
@@ -943,6 +940,13 @@ function createPaginatedFunction(coreFn, options) {
943
940
  [Symbol.asyncIterator]() {
944
941
  return pageStream;
945
942
  },
943
+ pages: function() {
944
+ return {
945
+ [Symbol.asyncIterator]() {
946
+ return pageStream;
947
+ }
948
+ };
949
+ },
946
950
  items: function() {
947
951
  return {
948
952
  [Symbol.asyncIterator]: async function* () {
@@ -3766,6 +3770,7 @@ function openEnum(values, description) {
3766
3770
  CoreSignal,
3767
3771
  addPlugin,
3768
3772
  composePlugins,
3773
+ concatLists,
3769
3774
  concatPaginated,
3770
3775
  coreOptionsPluginRef,
3771
3776
  createAsyncContext,