ampless 1.0.0-alpha.32 → 1.0.0-alpha.33

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
@@ -575,7 +575,48 @@ interface PluginMetadata {
575
575
  types?: Record<string, string>;
576
576
  };
577
577
  }
578
- type PluginEventHandler<T extends EventType = EventType> = (event: AmplessEvent<T>, ctx: PluginRuntimeContext) => Promise<void>;
578
+ /**
579
+ * Hook return value reservation (Phase 1: type only, runtime no-op).
580
+ *
581
+ * Today's runtime (after-event SQS Lambdas) ignores the return value
582
+ * entirely. The type is widened so a future PR can land additive
583
+ * directives without breaking plugin authors who publish in the
584
+ * meantime. Likely first use case:
585
+ *
586
+ * - `metrics?: Record<string, number>` — emit observability data
587
+ * without touching CloudWatch SDK directly from the plugin.
588
+ *
589
+ * `cancel` / `post` rewrite-style directives are NOT enabled by this
590
+ * type alone — they would also require `before:*` events to be wired
591
+ * to plugins (currently reserved, see events.ts) and payload shapes
592
+ * to expose mutable bodies. This PR widens the return surface only;
593
+ * richer semantics need follow-on PRs.
594
+ *
595
+ * The `readonly __amplessPluginHookResult?: never` marker is a
596
+ * type-level nominal tag: it prevents `Promise<void | PluginHookResult>`
597
+ * from silently accepting unrelated promise types like
598
+ * `Promise<string>` or `Promise<number>`. Plugin authors do not need
599
+ * to set this field — it is optional and exists only to constrain
600
+ * what the union accepts.
601
+ */
602
+ interface PluginHookResult {
603
+ readonly __amplessPluginHookResult?: never;
604
+ }
605
+ /**
606
+ * Async event hook handler.
607
+ *
608
+ * The return value is reserved (see `PluginHookResult`). Today's
609
+ * runtime ignores it — returning `undefined` (`Promise<void>`) is
610
+ * the canonical "no-op" and matches existing plugin code without
611
+ * migration. Plugins that explicitly return a `PluginHookResult`
612
+ * object type-check today but do not change runtime behaviour
613
+ * until the matching capability PR lands.
614
+ *
615
+ * Non-PluginHookResult promise types (`Promise<string>`,
616
+ * `Promise<number>`, etc.) are rejected at compile time by the
617
+ * `__amplessPluginHookResult` private marker on `PluginHookResult`.
618
+ */
619
+ type PluginEventHandler<T extends EventType = EventType> = (event: AmplessEvent<T>, ctx: PluginRuntimeContext) => Promise<void | PluginHookResult>;
579
620
  /**
580
621
  * Runtime services injected into hook handlers by the Lambda processor.
581
622
  * Decoupling plugins from concrete AWS clients lets us swap implementations
@@ -1510,4 +1551,4 @@ declare function pickDefaultEntrypoint(files: readonly {
1510
1551
 
1511
1552
  declare const VERSION = "0.0.1";
1512
1553
 
1513
- export { type AmplessEvent, type AmplessPlugin, type AuthContext, type BundleExtractResult, type CacheConfig, type CacheStrategy, type Config, type ContentEventPayload, type ContentEventType, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_ENTRYPOINT, type DateFormat, type EventPayloadOf, type EventType, type ExtractedFile, type FieldDefinition, type FieldType, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type LocalizedString, MAX_BUNDLE_BYTES, 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 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 PluginUrlField, type Post, type PostIndexEventPayload, type PostIndexEventType, type PostMetadata, type PostStatus, type PostsProvider, type PublicBodyDescriptor, type PublicHeadDescriptor, type PublicPostBodyDescriptor, type PublicPostHtmlDescriptor, type PublicPostHtmlPosition, type Role, SITE_CONFIG_PK, type ScriptStrategy, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StaticPostFileMeta, type StreamEventName, 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 TrustLevel, type TrustedPluginRuntimeContext, VERSION, type ValidationIssue, bundlePrefix, createPost, decodeAwsJson, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, encodeAwsJson, escapeXml, extractFirstImageUrl, findAbsolutePathRefs, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isTagListUrl, isValidPluginKey, listPosts, listSiteSettings, mimeTypeFor, parseColorPair, parseLinkList, pickDefaultEntrypoint, resolveLocalized, resolvePluginSettings, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, stringifyLinkList, stripCommonPrefix, themeSettingKey, unflattenSettings, updatePost, validateBundle, validateBundlePath, validatePluginSettingValue, validatePublicAssetKey, validateThemeValue };
1554
+ export { type AmplessEvent, type AmplessPlugin, type AuthContext, type BundleExtractResult, type CacheConfig, type CacheStrategy, type Config, type ContentEventPayload, type ContentEventType, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_ENTRYPOINT, type DateFormat, type EventPayloadOf, type EventType, type ExtractedFile, type FieldDefinition, type FieldType, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type LocalizedString, MAX_BUNDLE_BYTES, 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 PluginUrlField, type Post, type PostIndexEventPayload, type PostIndexEventType, type PostMetadata, type PostStatus, type PostsProvider, type PublicBodyDescriptor, type PublicHeadDescriptor, type PublicPostBodyDescriptor, type PublicPostHtmlDescriptor, type PublicPostHtmlPosition, type Role, SITE_CONFIG_PK, type ScriptStrategy, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StaticPostFileMeta, type StreamEventName, 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 TrustLevel, type TrustedPluginRuntimeContext, VERSION, type ValidationIssue, bundlePrefix, createPost, decodeAwsJson, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, encodeAwsJson, escapeXml, extractFirstImageUrl, findAbsolutePathRefs, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isTagListUrl, isValidPluginKey, listPosts, listSiteSettings, mimeTypeFor, parseColorPair, parseLinkList, pickDefaultEntrypoint, resolveLocalized, resolvePluginSettings, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, stringifyLinkList, stripCommonPrefix, themeSettingKey, unflattenSettings, updatePost, validateBundle, validateBundlePath, validatePluginSettingValue, validatePublicAssetKey, validateThemeValue };
@@ -617,7 +617,28 @@ npm 公開のスタンドアロンプラグインの場合は、`package.json#am
617
617
 
618
618
  ## 7. 非同期イベントフック
619
619
 
620
- `hooks` は SQS から到着したイベントを trust_level に対応する processor Lambda が受けて実行します。runtime context (`ctx`) の中身:
620
+ `hooks` は SQS から到着したイベントを trust_level に対応する processor Lambda が受けて実行します。
621
+
622
+ ### 戻り値の予約
623
+
624
+ `PluginEventHandler` の戻り値型は `Promise<void | PluginHookResult>`。
625
+ runtime は現状この戻り値を完全に無視する — 既存 plugin が
626
+ `Promise<void>` を返す形は migration 不要で動き続ける。
627
+ `PluginHookResult` は将来の directive (最初の用例として有力:
628
+ `metrics?: Record<string, number>` による observability emission) のた
629
+ めの予約で、今宣言するのは forward-compatibility のヒントとして
630
+ の扱い。注意: rewrite / cancel 系 directive は本 widening だけで
631
+ は有効化されない — `before:*` event の plugin 配線と payload 拡張
632
+ が別 PR で必要。
633
+
634
+ `PluginHookResult` には private な `__amplessPluginHookResult`
635
+ marker が付いており、union が `Promise<string>` / `Promise<number>`
636
+ 等の無関係な promise を silently 受け入れないようになっている —
637
+ plugin 作者がこの marker を明示的に設定する必要は無い。
638
+
639
+ ### Runtime context
640
+
641
+ runtime context (`ctx`) の中身:
621
642
 
622
643
  ```ts
623
644
  interface PluginRuntimeContext {
@@ -794,7 +794,28 @@ manifest and the factory return value:
794
794
  ## 7. Async event hooks
795
795
 
796
796
  `hooks` runs inside the trust_level-matched processor Lambda when an
797
- event arrives via SQS. The runtime context (`ctx`) carries:
797
+ event arrives via SQS.
798
+
799
+ ### Return value reservation
800
+
801
+ `PluginEventHandler` returns `Promise<void | PluginHookResult>`. The
802
+ runtime currently ignores the return value entirely — existing
803
+ plugins returning `Promise<void>` keep working without migration.
804
+ `PluginHookResult` is reserved for a future directive (likely first:
805
+ `metrics?: Record<string, number>` for observability emission);
806
+ declaring it today is a forward-compatibility hint. Note: rewrite
807
+ or cancel directives are NOT enabled by this widening alone — they
808
+ require additional `before:*` event support and payload extensions
809
+ in separate PRs.
810
+
811
+ `PluginHookResult` carries a private `__amplessPluginHookResult`
812
+ marker so that the union does not silently accept unrelated promise
813
+ types (`Promise<string>` / `Promise<number>` etc.) — plugin authors
814
+ do not need to set this field.
815
+
816
+ ### Runtime context
817
+
818
+ The runtime context (`ctx`) carries:
798
819
 
799
820
  ```ts
800
821
  interface PluginRuntimeContext {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ampless",
3
- "version": "1.0.0-alpha.32",
3
+ "version": "1.0.0-alpha.33",
4
4
  "description": "Serverless CMS for AWS Amplify",
5
5
  "license": "MIT",
6
6
  "type": "module",