ampless 0.2.0-alpha.5 → 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/README.ja.md +49 -0
- package/README.md +3 -0
- package/dist/index.d.ts +46 -1
- package/dist/index.js +15 -0
- package/package.json +1 -1
package/README.ja.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
> English: [README.md](./README.md)
|
|
2
|
+
>
|
|
3
|
+
|
|
4
|
+
# ampless
|
|
5
|
+
|
|
6
|
+
AWS Amplify 向け CMS コアライブラリ。
|
|
7
|
+
|
|
8
|
+
> **プレリリース / アルファ版。** v1.0 まではマイナーバージョンでも破壊的変更が入る可能性があります。全文ドキュメントは [ルート README](https://github.com/heavymoons/ampless#readme) を参照してください。
|
|
9
|
+
|
|
10
|
+
## 概要
|
|
11
|
+
|
|
12
|
+
`ampless` は [ampless](https://github.com/heavymoons/ampless) CMS を支えるコアライブラリです。以下を公開しています:
|
|
13
|
+
|
|
14
|
+
- `defineConfig()` — ユーザー向け `cms.config.ts` スキーマ
|
|
15
|
+
- `defineSchema()` — コンテンツタイプ定義(カスタムコンテンツタイプシステムは v0.2 で完成予定)
|
|
16
|
+
- `Post` / `Page` / `Media` / `AuthContext` 共有型
|
|
17
|
+
- プラグインコントラクト(`definePlugin`、`AmplessPlugin`、フック、`PluginRuntimeContext`、イベント型、`escapeXml` / `formatPublicAssetUrl`)
|
|
18
|
+
- DI スタイルの `setPostsProvider()` — テンプレートの Amplify データラッパーが注入します。未設定の場合は API がダミーの投稿を返すため、AWS を接続する前にプロトタイプを作成できます。
|
|
19
|
+
|
|
20
|
+
通常は `ampless` に直接依存する必要はありません — `create-ampless` のブログテンプレートや `@ampless/plugin-*` が依存パッケージとして取り込みます。独自のプラグインやテーマを作成する場合にのみ直接インストールしてください。
|
|
21
|
+
|
|
22
|
+
## インストール
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install ampless@alpha
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 使い方
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { defineConfig } from 'ampless'
|
|
32
|
+
|
|
33
|
+
export default defineConfig({
|
|
34
|
+
site: {
|
|
35
|
+
name: 'My Blog',
|
|
36
|
+
url: 'https://example.com',
|
|
37
|
+
},
|
|
38
|
+
plugins: [],
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 動作要件
|
|
43
|
+
|
|
44
|
+
- Node.js >= 20
|
|
45
|
+
- AWS Amplify Gen 2
|
|
46
|
+
|
|
47
|
+
## ライセンス
|
|
48
|
+
|
|
49
|
+
[MIT](../../LICENSE)
|
package/README.md
CHANGED
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,
|