ampless 0.2.0-alpha.6 → 0.2.0-alpha.7
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 +46 -1
- package/dist/index.js +15 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -484,6 +484,51 @@ declare function formatDate(input: Date | string | number, format?: DateFormat,
|
|
|
484
484
|
|
|
485
485
|
declare function escapeXml(s: string): string;
|
|
486
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Encode / decode helpers for AppSync's AWSJSON scalar.
|
|
489
|
+
*
|
|
490
|
+
* Every `a.json()` field in the schema (Post.body, Post.metadata,
|
|
491
|
+
* Page.body, KvStore.value, ...) carries a *JSON-encoded string* on
|
|
492
|
+
* the GraphQL wire — regardless of whether the underlying value is a
|
|
493
|
+
* string, object, or array. That rule holds for both write paths:
|
|
494
|
+
*
|
|
495
|
+
* 1. Amplify-generated client (`generateClient<Schema>().models.X.
|
|
496
|
+
* create({ body: ... })`) — Amplify does NOT auto-stringify, the
|
|
497
|
+
* caller must JSON.stringify before passing the value in.
|
|
498
|
+
* 2. Raw GraphQL fetch (variables map, e.g. the MCP Lambda) — same
|
|
499
|
+
* rule, the variable must be a JSON-encoded string.
|
|
500
|
+
*
|
|
501
|
+
* Skipping the stringify for raw string inputs (a common mistake when
|
|
502
|
+
* `format: 'markdown'`) trips AppSync's variable validator with
|
|
503
|
+
*
|
|
504
|
+
* Variable 'body' has an invalid value.
|
|
505
|
+
*
|
|
506
|
+
* On the read side two wire shapes coexist:
|
|
507
|
+
*
|
|
508
|
+
* - JSON-encoded string — what the auto-generated CRUD resolver and
|
|
509
|
+
* custom resolvers usually return.
|
|
510
|
+
* - Native object / Map — DynamoDBDocumentClient unmarshals
|
|
511
|
+
* AWSJSON-stored maps straight into JS objects when read directly
|
|
512
|
+
* from DynamoDB (the path used by the trusted processor and the
|
|
513
|
+
* MCP Lambda).
|
|
514
|
+
*
|
|
515
|
+
* `decodeAwsJson` tolerates both: pass strings through `JSON.parse`,
|
|
516
|
+
* everything else as-is, fall back to the raw string on parse errors
|
|
517
|
+
* so legacy bare-string rows aren't lost.
|
|
518
|
+
*/
|
|
519
|
+
/**
|
|
520
|
+
* Serialise a value for an AWSJSON variable. `undefined` / `null` both
|
|
521
|
+
* collapse to the literal string `"null"` (valid JSON) so AppSync sees
|
|
522
|
+
* a well-formed AWSJSON payload either way.
|
|
523
|
+
*/
|
|
524
|
+
declare function encodeAwsJson(value: unknown): string;
|
|
525
|
+
/**
|
|
526
|
+
* Deserialise an AWSJSON value from a GraphQL / DynamoDB read.
|
|
527
|
+
* Tolerates both the wire-string shape and the auto-unmarshalled
|
|
528
|
+
* native value. Returns the raw string when `JSON.parse` rejects it.
|
|
529
|
+
*/
|
|
530
|
+
declare function decodeAwsJson(value: unknown): unknown;
|
|
531
|
+
|
|
487
532
|
/**
|
|
488
533
|
* Build the public S3 URL for an object key, in the regional virtual-host
|
|
489
534
|
* style: `https://{bucket}.s3.{region}.amazonaws.com/{key}`. The legacy
|
|
@@ -719,4 +764,4 @@ declare function resolveThemeValues(manifest: ThemeManifest, stored: Record<stri
|
|
|
719
764
|
|
|
720
765
|
declare const VERSION = "0.0.1";
|
|
721
766
|
|
|
722
|
-
export { type AmplessEvent, type AmplessPlugin, type AuthContext, type Config, type ContentEventPayload, type ContentEventType, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_SITE_ID, type DateFormat, type EventPayloadOf, type EventType, type FieldDefinition, type FieldType, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type LocalizedString, type Media, type MediaEventPayload, type MediaEventType, type MediaProcessingDefaults, type OgImageConfig, type OgImageFont, type OgImageRenderContext, type Page, type PluginEventHandler, type PluginMetadata, type PluginRuntimeContext, type Post, type PostMetadata, type PostStatus, type PostsProvider, type Role, SITE_CONFIG_PK, type SiteConfig, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StreamEventName, 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, VERSION, composeSiteIdSlug, composeSiteIdStatus, createPost, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, escapeXml, extractFirstImageUrl, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isMultiSite, isTagListUrl, listPosts, listSiteSettings, parseColorPair, parseLinkList, resolveLocalized, resolveSiteId, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, siteFor, stringifyLinkList, themeSettingKey, unflattenSettings, updatePost, validateThemeValue };
|
|
767
|
+
export { type AmplessEvent, type AmplessPlugin, type AuthContext, type Config, type ContentEventPayload, type ContentEventType, type ContentFormat, type ContentTypeDefinition, type CreatePostInput, DEFAULT_SITE_ID, type DateFormat, type EventPayloadOf, type EventType, type FieldDefinition, type FieldType, type ImageDisplay, type KvItem, type KvStore, type LinkListItem, type ListOptions, type LocalizedString, type Media, type MediaEventPayload, type MediaEventType, type MediaProcessingDefaults, type OgImageConfig, type OgImageFont, type OgImageRenderContext, type Page, type PluginEventHandler, type PluginMetadata, type PluginRuntimeContext, type Post, type PostMetadata, type PostStatus, type PostsProvider, type Role, SITE_CONFIG_PK, type SiteConfig, type SiteSettingsEventPayload, type SiteSettingsEventType, type StaticPostBody, type StreamEventName, 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, VERSION, composeSiteIdSlug, composeSiteIdStatus, createPost, decodeAwsJson, defineConfig, definePlugin, defineSchema, defineTheme, defineThemeModule, deletePost, deleteSiteSetting, detectContentEvents, encodeAwsJson, escapeXml, extractFirstImageUrl, flattenSettings, formatColorPair, formatDate, formatPublicAssetUrl, getKvStore, getPost, getPostById, getSiteSetting, hasKvStore, hasPostsProvider, isMultiSite, isTagListUrl, listPosts, listSiteSettings, parseColorPair, parseLinkList, resolveLocalized, resolveSiteId, resolveThemeValues, setKvStore, setPostsProvider, setSiteSetting, siteFor, stringifyLinkList, themeSettingKey, unflattenSettings, updatePost, validateThemeValue };
|
package/dist/index.js
CHANGED
|
@@ -234,6 +234,19 @@ function escapeXml(s) {
|
|
|
234
234
|
return s.replace(/[&<>"']/g, (c) => XML_ESCAPES[c]);
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
// src/awsjson.ts
|
|
238
|
+
function encodeAwsJson(value) {
|
|
239
|
+
return JSON.stringify(value ?? null);
|
|
240
|
+
}
|
|
241
|
+
function decodeAwsJson(value) {
|
|
242
|
+
if (typeof value !== "string") return value;
|
|
243
|
+
try {
|
|
244
|
+
return JSON.parse(value);
|
|
245
|
+
} catch {
|
|
246
|
+
return value;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
237
250
|
// src/storage.ts
|
|
238
251
|
function formatPublicAssetUrl(bucket, region, key) {
|
|
239
252
|
return `https://${bucket}.s3.${region}.amazonaws.com/${key}`;
|
|
@@ -464,6 +477,7 @@ export {
|
|
|
464
477
|
composeSiteIdSlug,
|
|
465
478
|
composeSiteIdStatus,
|
|
466
479
|
createPost,
|
|
480
|
+
decodeAwsJson,
|
|
467
481
|
defineConfig,
|
|
468
482
|
definePlugin,
|
|
469
483
|
defineSchema,
|
|
@@ -472,6 +486,7 @@ export {
|
|
|
472
486
|
deletePost,
|
|
473
487
|
deleteSiteSetting,
|
|
474
488
|
detectContentEvents,
|
|
489
|
+
encodeAwsJson,
|
|
475
490
|
escapeXml,
|
|
476
491
|
extractFirstImageUrl,
|
|
477
492
|
flattenSettings,
|