ampless 1.0.0-beta.58 → 1.0.0-beta.59

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/dist/index.d.ts CHANGED
@@ -2001,6 +2001,57 @@ declare function resolvePluginSettings(manifest: PluginSettingsManifest | undefi
2001
2001
  */
2002
2002
  declare function extractFirstImageUrl(post: Post): string | null;
2003
2003
 
2004
+ /** How the scan ended. `null` = the fetcher was exhausted cleanly. */
2005
+ type BoundedScanTruncation = 'limit' | 'early' | null;
2006
+ interface BoundedScanResult<T> {
2007
+ items: T[];
2008
+ /**
2009
+ * - `'limit'` — a `limit + 1`th item was actually fetched, so more
2010
+ * items exist beyond the returned `limit`; the extra item is
2011
+ * dropped from `items`.
2012
+ * - `'early'` — one of the safety bounds tripped (`maxPages` reached
2013
+ * or the same `nextToken` came back twice), so the scan may have
2014
+ * stopped with more items unread.
2015
+ * - `null` — the fetcher signalled exhaustion (no `nextToken`) at or
2016
+ * below `limit`.
2017
+ */
2018
+ truncated: BoundedScanTruncation;
2019
+ }
2020
+ interface BoundedScanOptions {
2021
+ /**
2022
+ * Target item count. The walk collects until it has `limit + 1`
2023
+ * items (the extra confirms there really are more), the fetcher is
2024
+ * exhausted, or a safety bound trips.
2025
+ */
2026
+ limit: number;
2027
+ /** Max items requested per page (default 50). */
2028
+ pageSizeCap?: number;
2029
+ /** Hard cap on pages walked regardless of items collected (default 21). */
2030
+ maxPages?: number;
2031
+ }
2032
+ interface BoundedScanPage<T> {
2033
+ items: T[];
2034
+ nextToken: string | null;
2035
+ }
2036
+ /**
2037
+ * Walk `fetchPage` pages until we have `limit + 1` items (the extra
2038
+ * item confirms there really are more items beyond `limit` — a present
2039
+ * `nextToken` alone doesn't guarantee that, since a paginated backend
2040
+ * can return a token alongside zero remaining items), the token is
2041
+ * exhausted, or one of the two safety bounds below trips:
2042
+ *
2043
+ * - `maxPages` pages walked without reaching either stop condition
2044
+ * - the same `nextToken` comes back twice (defends against a
2045
+ * misbehaving resolver looping forever)
2046
+ *
2047
+ * Returns at most `limit` items (the confirming `limit + 1`th item is
2048
+ * dropped) alongside how the scan ended.
2049
+ */
2050
+ declare function collectBounded<T>(fetchPage: (args: {
2051
+ limit: number;
2052
+ nextToken?: string;
2053
+ }) => Promise<BoundedScanPage<T>>, opts: BoundedScanOptions): Promise<BoundedScanResult<T>>;
2054
+
2004
2055
  type PostListStatusFilter = 'all' | 'draft' | 'published';
2005
2056
  type PostListSort = 'updated-desc' | 'updated-asc' | 'published-desc' | 'published-asc' | 'title-asc' | 'title-desc';
2006
2057
  interface PostListFilterOptions {
@@ -2102,4 +2153,4 @@ declare function pickDefaultEntrypoint(files: readonly {
2102
2153
 
2103
2154
  declare const VERSION = "0.0.1";
2104
2155
 
2105
- export { type AiConfig, type AmplessEvent, type AmplessPlugin, type AuthContext, type BundleExtractResult, type CacheConfig, type CacheStrategy, type Config, type ContentEventPayload, type ContentEventType, type ContentFieldRenderer, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_ENTRYPOINT, type DateFormat, type EventPayloadOf, type EventType, type ExtractedFile, type FieldDefinition, type FieldType, type HistoryConfig, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type ListPostHistoryOptions, type LocalizedString, MAX_BUNDLE_BYTES, type MarkdownEmbedMatch, type Media, type MediaEventPayload, type MediaEventType, type MediaMetadata, type MediaProcessingDefaults, type OgImageConfig, type OgImageFont, type OgImageRenderContext, PLUGIN_KEY_PATTERN, type Page, type PluginBooleanField, type PluginCapability, type PluginCodeField, type PluginEventHandler, type PluginHookResult, type PluginJsonField, type PluginMetadata, type PluginNumberField, type PluginPackageManifest, type PluginPublicRenderContext, type PluginRepeatableField, type PluginRepeatableSubField, type PluginRuntimeContext, type PluginSecretField, type PluginSelectField, type PluginSettingField, type PluginSettingsManifest, type PluginTextField, type PluginTextareaField, type PluginUninstallContext, type PluginUrlField, type Post, type PostIndexEventPayload, type PostIndexEventType, type PostListFilterOptions, type PostListSort, type PostListStatusFilter, type PostMetadata, type PostRevision, type PostRevisionConnection, type PostStatus, type PostSummary, type PostsProvider, type PublicBodyDescriptor, type PublicHeadDescriptor, type PublicPostBodyDescriptor, type PublicPostHtmlDescriptor, type PublicPostHtmlPosition, type PublicPostScriptDescriptor, type Role, SITE_CONFIG_PK, type ScriptStrategy, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StaticPostFileMeta, type StreamEventName, type SummaryListOptions, TEXT_EXTENSIONS, type ThemeColorField, type ThemeField, type ThemeFieldType, type ThemeFontFamilyField, type ThemeImageField, type ThemeLengthField, type ThemeLinkListField, type ThemeManifest, type ThemeModule, type ThemeRouteContext, type ThemeSelectField, type ThemeTextField, type TiptapNodeHtmlAdapters, type TiptapNodeMarkdownAdapters, type TiptapNodeToHtml, type TiptapNodeToMarkdown, type TiptapRenderNode, type TrustLevel, type TrustedPluginRuntimeContext, VERSION, type ValidationIssue, bundlePrefix, collectTags, createPost, decodeAwsJson, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, encodeAwsJson, escapeXml, extractFirstImageUrl, filterSortPostSummaries, findAbsolutePathRefs, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isTagListUrl, isValidPluginKey, listPostHistory, listPostSummaries, listPosts, listSiteSettings, mimeTypeFor, parseColorPair, parseLinkList, pickDefaultEntrypoint, resolveLocalized, resolvePluginSettings, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, stringifyLinkList, stripCommonPrefix, themeSettingKey, unflattenSettings, updatePost, validateBundle, validateBundlePath, validatePluginSettingValue, validatePublicAssetKey, validateThemeValue };
2156
+ export { type AiConfig, type AmplessEvent, type AmplessPlugin, type AuthContext, type BoundedScanOptions, type BoundedScanPage, type BoundedScanResult, type BoundedScanTruncation, type BundleExtractResult, type CacheConfig, type CacheStrategy, type Config, type ContentEventPayload, type ContentEventType, type ContentFieldRenderer, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_ENTRYPOINT, type DateFormat, type EventPayloadOf, type EventType, type ExtractedFile, type FieldDefinition, type FieldType, type HistoryConfig, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type ListPostHistoryOptions, type LocalizedString, MAX_BUNDLE_BYTES, type MarkdownEmbedMatch, type Media, type MediaEventPayload, type MediaEventType, type MediaMetadata, type MediaProcessingDefaults, type OgImageConfig, type OgImageFont, type OgImageRenderContext, PLUGIN_KEY_PATTERN, type Page, type PluginBooleanField, type PluginCapability, type PluginCodeField, type PluginEventHandler, type PluginHookResult, type PluginJsonField, type PluginMetadata, type PluginNumberField, type PluginPackageManifest, type PluginPublicRenderContext, type PluginRepeatableField, type PluginRepeatableSubField, type PluginRuntimeContext, type PluginSecretField, type PluginSelectField, type PluginSettingField, type PluginSettingsManifest, type PluginTextField, type PluginTextareaField, type PluginUninstallContext, type PluginUrlField, type Post, type PostIndexEventPayload, type PostIndexEventType, type PostListFilterOptions, type PostListSort, type PostListStatusFilter, type PostMetadata, type PostRevision, type PostRevisionConnection, type PostStatus, type PostSummary, type PostsProvider, type PublicBodyDescriptor, type PublicHeadDescriptor, type PublicPostBodyDescriptor, type PublicPostHtmlDescriptor, type PublicPostHtmlPosition, type PublicPostScriptDescriptor, type Role, SITE_CONFIG_PK, type ScriptStrategy, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StaticPostFileMeta, type StreamEventName, type SummaryListOptions, TEXT_EXTENSIONS, type ThemeColorField, type ThemeField, type ThemeFieldType, type ThemeFontFamilyField, type ThemeImageField, type ThemeLengthField, type ThemeLinkListField, type ThemeManifest, type ThemeModule, type ThemeRouteContext, type ThemeSelectField, type ThemeTextField, type TiptapNodeHtmlAdapters, type TiptapNodeMarkdownAdapters, type TiptapNodeToHtml, type TiptapNodeToMarkdown, type TiptapRenderNode, type TrustLevel, type TrustedPluginRuntimeContext, VERSION, type ValidationIssue, bundlePrefix, collectBounded, collectTags, createPost, decodeAwsJson, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, encodeAwsJson, escapeXml, extractFirstImageUrl, filterSortPostSummaries, findAbsolutePathRefs, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isTagListUrl, isValidPluginKey, listPostHistory, listPostSummaries, listPosts, listSiteSettings, mimeTypeFor, parseColorPair, parseLinkList, pickDefaultEntrypoint, resolveLocalized, resolvePluginSettings, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, stringifyLinkList, stripCommonPrefix, themeSettingKey, unflattenSettings, updatePost, validateBundle, validateBundlePath, validatePluginSettingValue, validatePublicAssetKey, validateThemeValue };
package/dist/index.js CHANGED
@@ -501,6 +501,55 @@ function findHtmlImage(body) {
501
501
  return m ? m[1] : null;
502
502
  }
503
503
 
504
+ // src/paging.ts
505
+ var DEFAULT_PAGE_SIZE_CAP = 50;
506
+ var DEFAULT_MAX_PAGES = 21;
507
+ function requirePositiveInt(name, value) {
508
+ if (!Number.isInteger(value) || value <= 0) {
509
+ throw new TypeError(
510
+ `collectBounded: \`${name}\` must be a finite positive integer, received ${String(value)}`
511
+ );
512
+ }
513
+ }
514
+ async function collectBounded(fetchPage, opts) {
515
+ const limit = opts.limit;
516
+ const pageSizeCap = opts.pageSizeCap ?? DEFAULT_PAGE_SIZE_CAP;
517
+ const maxPages = opts.maxPages ?? DEFAULT_MAX_PAGES;
518
+ requirePositiveInt("limit", limit);
519
+ requirePositiveInt("pageSizeCap", pageSizeCap);
520
+ requirePositiveInt("maxPages", maxPages);
521
+ const items = [];
522
+ const seenTokens = /* @__PURE__ */ new Set();
523
+ let token;
524
+ let truncated = null;
525
+ for (let page = 0; page < maxPages; page++) {
526
+ const remaining = limit + 1 - items.length;
527
+ const pageLimit = Math.min(pageSizeCap, remaining);
528
+ const res = await fetchPage({ limit: pageLimit, nextToken: token });
529
+ items.push(...res.items);
530
+ if (items.length > limit) {
531
+ truncated = "limit";
532
+ break;
533
+ }
534
+ if (!res.nextToken) {
535
+ break;
536
+ }
537
+ if (seenTokens.has(res.nextToken)) {
538
+ truncated = "early";
539
+ break;
540
+ }
541
+ seenTokens.add(res.nextToken);
542
+ token = res.nextToken;
543
+ if (page === maxPages - 1) {
544
+ truncated = "early";
545
+ }
546
+ }
547
+ return {
548
+ items: truncated === "limit" ? items.slice(0, limit) : items,
549
+ truncated
550
+ };
551
+ }
552
+
504
553
  // src/post-list-filter.ts
505
554
  function filterSortPostSummaries(rows, options = {}) {
506
555
  const query = options.query?.trim().toLowerCase() ?? "";
@@ -869,6 +918,7 @@ export {
869
918
  TEXT_EXTENSIONS,
870
919
  VERSION,
871
920
  bundlePrefix,
921
+ collectBounded,
872
922
  collectTags,
873
923
  createPost,
874
924
  decodeAwsJson,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ampless",
3
- "version": "1.0.0-beta.58",
3
+ "version": "1.0.0-beta.59",
4
4
  "description": "Serverless CMS for AWS Amplify",
5
5
  "license": "MIT",
6
6
  "type": "module",