@ampless/runtime 1.0.0-alpha.41 → 1.0.0-alpha.43
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.js +34 -22
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -24,8 +24,8 @@ function createStorage(outputs) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/posts.ts
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
27
|
+
import { generateServerClientUsingReqRes } from "@aws-amplify/adapter-nextjs/api";
|
|
28
|
+
import { createServerRunner } from "@aws-amplify/adapter-nextjs";
|
|
29
29
|
import { decodeAwsJson } from "ampless";
|
|
30
30
|
function decodeMetadata(value) {
|
|
31
31
|
if (value === null || value === void 0) return void 0;
|
|
@@ -48,37 +48,44 @@ function toCorePost(p) {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
function createPostsApi(outputs) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
const { runWithAmplifyServerContext } = createServerRunner({
|
|
52
|
+
config: outputs
|
|
53
|
+
});
|
|
54
|
+
const client = generateServerClientUsingReqRes({
|
|
54
55
|
config: outputs,
|
|
55
|
-
cookies,
|
|
56
56
|
authMode: "apiKey"
|
|
57
57
|
});
|
|
58
58
|
return {
|
|
59
59
|
async listPublishedPosts(opts = {}) {
|
|
60
|
-
const { data, errors } = await
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const { data, errors } = await runWithAmplifyServerContext({
|
|
61
|
+
nextServerContext: null,
|
|
62
|
+
operation: (contextSpec) => client.queries.listPublishedPosts(contextSpec, {
|
|
63
|
+
from: opts.from,
|
|
64
|
+
to: opts.to,
|
|
65
|
+
limit: opts.limit ?? 20,
|
|
66
|
+
nextToken: opts.nextToken
|
|
67
|
+
})
|
|
65
68
|
});
|
|
66
69
|
if (errors) throw new Error(errors[0]?.message ?? "Failed to list posts");
|
|
67
70
|
const items = (data?.items ?? []).filter((p) => p !== null).map(toCorePost);
|
|
68
71
|
return { items, nextToken: data?.nextToken ?? null };
|
|
69
72
|
},
|
|
70
73
|
async getPublishedPost(slug) {
|
|
71
|
-
const { data, errors } = await
|
|
72
|
-
|
|
74
|
+
const { data, errors } = await runWithAmplifyServerContext({
|
|
75
|
+
nextServerContext: null,
|
|
76
|
+
operation: (contextSpec) => client.queries.getPublishedPost(contextSpec, { slug })
|
|
73
77
|
});
|
|
74
78
|
if (errors) throw new Error(errors[0]?.message ?? "Failed to get post");
|
|
75
79
|
return data ? toCorePost(data) : null;
|
|
76
80
|
},
|
|
77
81
|
async listPostsByTag(tag, opts = {}) {
|
|
78
|
-
const { data, errors } = await
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
const { data, errors } = await runWithAmplifyServerContext({
|
|
83
|
+
nextServerContext: null,
|
|
84
|
+
operation: (contextSpec) => client.queries.listPostsByTag(contextSpec, {
|
|
85
|
+
tag,
|
|
86
|
+
limit: opts.limit ?? 20,
|
|
87
|
+
nextToken: opts.nextToken
|
|
88
|
+
})
|
|
82
89
|
});
|
|
83
90
|
if (errors) throw new Error(errors[0]?.message ?? "Failed to list posts by tag");
|
|
84
91
|
const items = (data?.items ?? []).filter((p) => p !== null).map(toCorePost);
|
|
@@ -88,8 +95,8 @@ function createPostsApi(outputs) {
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
// src/media.ts
|
|
91
|
-
import {
|
|
92
|
-
import {
|
|
98
|
+
import { generateServerClientUsingReqRes as generateServerClientUsingReqRes2 } from "@aws-amplify/adapter-nextjs/api";
|
|
99
|
+
import { createServerRunner as createServerRunner2 } from "@aws-amplify/adapter-nextjs";
|
|
93
100
|
import { decodeAwsJson as decodeAwsJson2 } from "ampless";
|
|
94
101
|
function decodeMediaMetadata(value) {
|
|
95
102
|
if (value === null || value === void 0) return null;
|
|
@@ -100,15 +107,20 @@ function decodeMediaMetadata(value) {
|
|
|
100
107
|
return null;
|
|
101
108
|
}
|
|
102
109
|
function createMediaApi(outputs) {
|
|
103
|
-
const
|
|
110
|
+
const { runWithAmplifyServerContext } = createServerRunner2({
|
|
111
|
+
config: outputs
|
|
112
|
+
});
|
|
113
|
+
const client = generateServerClientUsingReqRes2({
|
|
104
114
|
config: outputs,
|
|
105
|
-
cookies: cookies2,
|
|
106
115
|
authMode: "apiKey"
|
|
107
116
|
});
|
|
108
117
|
return {
|
|
109
118
|
async getMediaBySrc(src) {
|
|
110
119
|
try {
|
|
111
|
-
const { data, errors } = await
|
|
120
|
+
const { data, errors } = await runWithAmplifyServerContext({
|
|
121
|
+
nextServerContext: null,
|
|
122
|
+
operation: (contextSpec) => client.queries.getMediaBySrc(contextSpec, { src })
|
|
123
|
+
});
|
|
112
124
|
if (errors && errors.length > 0) {
|
|
113
125
|
console.error(
|
|
114
126
|
`[media-api] getMediaBySrc errors for ${src}`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampless/runtime",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.43",
|
|
4
4
|
"description": "Public-side runtime for ampless: post fetching, theme dispatch, middleware, public route handlers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"marked": "^18.0.4",
|
|
51
51
|
"sanitize-html": "^2.17.4",
|
|
52
52
|
"tailwind-merge": "^3.6.0",
|
|
53
|
-
"@ampless/plugin-og-image": "0.2.0-alpha.
|
|
54
|
-
"ampless": "1.0.0-alpha.
|
|
53
|
+
"@ampless/plugin-og-image": "0.2.0-alpha.34",
|
|
54
|
+
"ampless": "1.0.0-alpha.34"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@aws-amplify/adapter-nextjs": "^1",
|