@aws-amplify/adapter-nextjs 1.0.1-api-v6-models.cfd348e.0 → 1.0.1-api-v6-models.e8fc3ba.0
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/api/package.json +7 -0
- package/lib/api/generateServerClient.d.ts +10 -14
- package/lib/api/generateServerClient.js +13 -17
- package/lib/api/generateServerClient.js.map +1 -1
- package/lib/createServerRunner.d.ts +19 -0
- package/lib/createServerRunner.js +20 -8
- package/lib/createServerRunner.js.map +1 -1
- package/lib-esm/api/generateServerClient.d.ts +10 -14
- package/lib-esm/api/generateServerClient.js +13 -17
- package/lib-esm/api/generateServerClient.js.map +1 -1
- package/lib-esm/createServerRunner.d.ts +19 -0
- package/lib-esm/createServerRunner.js +20 -8
- package/lib-esm/createServerRunner.js.map +1 -1
- package/package.json +8 -7
- package/src/api/generateServerClient.ts +14 -18
- package/src/createServerRunner.ts +21 -12
package/api/package.json
ADDED
|
@@ -4,30 +4,26 @@ import { NextServer } from '../types';
|
|
|
4
4
|
* Generates an API client that can be used inside a Next.js Server Component with Dynamic Rendering
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* ```ts
|
|
8
7
|
* import { cookies } from "next/headers"
|
|
9
8
|
*
|
|
10
|
-
* const client = generateServerClientUsingCookies({ cookies })
|
|
11
|
-
* const result = await client.graphql({query: listPosts})
|
|
12
|
-
* ```
|
|
9
|
+
* const client = generateServerClientUsingCookies({ cookies });
|
|
10
|
+
* const result = await client.graphql({ query: listPosts });
|
|
13
11
|
*/
|
|
14
12
|
export declare function generateServerClientUsingCookies<T extends Record<any, any> = never>({ config, cookies, }: NextServer.ServerComponentContext & NextServer.CreateServerRunnerInput): V6ClientSSRCookies<T>;
|
|
15
13
|
/**
|
|
16
14
|
* Generates an API client that can be used with both Pages Router and App Router
|
|
17
15
|
*
|
|
18
16
|
* @example
|
|
19
|
-
*
|
|
17
|
+
* import config from './amplifyconfiguration.json';
|
|
18
|
+
* import { listPosts } from './graphql/queries';
|
|
20
19
|
*
|
|
21
|
-
* const client =
|
|
20
|
+
* const client = generateServerClientUsingReqRes();
|
|
22
21
|
*
|
|
23
22
|
* result = await runWithAmplifyServerContext({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
})
|
|
31
|
-
* ```
|
|
23
|
+
* nextServerContext: { request, response },
|
|
24
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
25
|
+
* query: listPosts,
|
|
26
|
+
* }),
|
|
27
|
+
* });
|
|
32
28
|
*/
|
|
33
29
|
export declare function generateServerClientUsingReqRes<T extends Record<any, any> = never>({ config }: NextServer.CreateServerRunnerInput): V6ClientSSRRequest<T>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.generateServerClientUsingReqRes = exports.generateServerClientUsingCookies = void 0;
|
|
6
|
-
const
|
|
6
|
+
const internals_1 = require("@aws-amplify/api/internals");
|
|
7
7
|
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
8
8
|
const api_graphql_1 = require("@aws-amplify/api-graphql");
|
|
9
9
|
const createServerRunnerForAPI_1 = require("./createServerRunnerForAPI");
|
|
@@ -12,12 +12,10 @@ const utils_1 = require("../utils");
|
|
|
12
12
|
* Generates an API client that can be used inside a Next.js Server Component with Dynamic Rendering
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
|
-
* ```ts
|
|
16
15
|
* import { cookies } from "next/headers"
|
|
17
16
|
*
|
|
18
|
-
* const client = generateServerClientUsingCookies({ cookies })
|
|
19
|
-
* const result = await client.graphql({query: listPosts})
|
|
20
|
-
* ```
|
|
17
|
+
* const client = generateServerClientUsingCookies({ cookies });
|
|
18
|
+
* const result = await client.graphql({ query: listPosts });
|
|
21
19
|
*/
|
|
22
20
|
function generateServerClientUsingCookies({ config, cookies, }) {
|
|
23
21
|
if (typeof cookies !== 'function') {
|
|
@@ -35,7 +33,7 @@ function generateServerClientUsingCookies({ config, cookies, }) {
|
|
|
35
33
|
nextServerContext: { cookies },
|
|
36
34
|
operation: contextSpec => fn((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify),
|
|
37
35
|
});
|
|
38
|
-
return (0,
|
|
36
|
+
return (0, internals_1.generateServerClient)({
|
|
39
37
|
amplify: getAmplify,
|
|
40
38
|
config: resourcesConfig,
|
|
41
39
|
});
|
|
@@ -45,25 +43,23 @@ exports.generateServerClientUsingCookies = generateServerClientUsingCookies;
|
|
|
45
43
|
* Generates an API client that can be used with both Pages Router and App Router
|
|
46
44
|
*
|
|
47
45
|
* @example
|
|
48
|
-
*
|
|
46
|
+
* import config from './amplifyconfiguration.json';
|
|
47
|
+
* import { listPosts } from './graphql/queries';
|
|
49
48
|
*
|
|
50
|
-
* const client =
|
|
49
|
+
* const client = generateServerClientUsingReqRes();
|
|
51
50
|
*
|
|
52
51
|
* result = await runWithAmplifyServerContext({
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
* ```
|
|
52
|
+
* nextServerContext: { request, response },
|
|
53
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
54
|
+
* query: listPosts,
|
|
55
|
+
* }),
|
|
56
|
+
* });
|
|
61
57
|
*/
|
|
62
58
|
function generateServerClientUsingReqRes({ config }) {
|
|
63
59
|
const amplifyConfig = (0, utils_1.getAmplifyConfig)(config);
|
|
64
60
|
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
65
61
|
// from server context
|
|
66
|
-
const client = (0,
|
|
62
|
+
const client = (0, internals_1.generateServerClient)({
|
|
67
63
|
amplify: null,
|
|
68
64
|
config: amplifyConfig,
|
|
69
65
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateServerClient.js","sourceRoot":"","sources":["../../src/api/generateServerClient.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,
|
|
1
|
+
{"version":3,"file":"generateServerClient.js","sourceRoot":"","sources":["../../src/api/generateServerClient.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,0DAAkE;AAClE,2EAGkD;AAClD,0DAMkC;AAElC,yEAAsE;AACtE,oCAA4C;AAE5C;;;;;;;;GAQG;AACH,SAAgB,gCAAgC,CAE9C,EACD,MAAM,EACN,OAAO,GAE2B;IAClC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;QAClC,MAAM,IAAI,wCAAyB,CAAC;YACnC,OAAO,EACN,yHAAyH;YAC1H,qBAAqB;YACrB,kBAAkB,EACjB,+FAA+F;SAChG,CAAC,CAAC;KACH;IAED,MAAM,EAAE,2BAA2B,EAAE,eAAe,EAAE,GACrD,IAAA,mDAAwB,EAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAEtC,4EAA4E;IAC5E,wDAAwD;IACxD,wEAAwE;IACxE,MAAM,UAAU,GAAG,CAAC,EAAkC,EAAE,EAAE,CACzD,2BAA2B,CAAC;QAC3B,iBAAiB,EAAE,EAAE,OAAO,EAAE;QAC9B,SAAS,EAAE,WAAW,CAAC,EAAE,CACxB,EAAE,CAAC,IAAA,sCAAuB,EAAC,WAAW,CAAC,CAAC,OAAO,CAAC;KACjD,CAAC,CAAC;IAEJ,OAAO,IAAA,gCAAoB,EAA2B;QACrD,OAAO,EAAE,UAAU;QACnB,MAAM,EAAE,eAAe;KACvB,CAAC,CAAC;AACJ,CAAC;AAlCD,4EAkCC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,+BAA+B,CAE7C,EAAE,MAAM,EAAsC;IAC/C,MAAM,aAAa,GAAG,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAC;IAC/C,4FAA4F;IAC5F,sBAAsB;IACtB,MAAM,MAAM,GAAG,IAAA,gCAAoB,EAA2B;QAC7D,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,aAAa;KACrB,CAAC,CAAC;IAEH,uCAAuC;IACvC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAmC,CAAC;IAE/D,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,iBAAkB,EAAE,EAAE;QACnE,MAAM,eAAe,GAAG,IAAA,sCAAuB,EAAC,WAAW,CAAC,CAAC,OAAO,CAAC;QACrE,OAAO,WAAW,CAAC,IAAI,CACtB,EAAE,CAAC,uBAAS,CAAC,EAAE,eAAe,EAAE,EAChC,OAAO,EACP,iBAAwB,CACxB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,OAAO,GAAG,cAA6C,CAAC;IAC/D,OAAO,MAAM,CAAC;AACf,CAAC;AAzBD,0EAyBC"}
|
|
@@ -1,2 +1,21 @@
|
|
|
1
1
|
import { NextServer } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This function should be called only once; you can use the returned `runWithAmplifyServerContext` across
|
|
7
|
+
* your codebase.
|
|
8
|
+
*
|
|
9
|
+
* @param input The input used to create the `runWithAmplifyServerContext` function.
|
|
10
|
+
* @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually
|
|
11
|
+
* created.
|
|
12
|
+
* @returns An object that contains the `runWithAmplifyServerContext` function.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { createServerRunner } from '@aws-amplify/adapter-nextjs';
|
|
16
|
+
* import config from './amplifyconfiguration.json';
|
|
17
|
+
*
|
|
18
|
+
* export const { runWithAmplifyServerContext } = createServerRunner({ config })
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
2
21
|
export declare const createServerRunner: NextServer.CreateServerRunner;
|
|
@@ -3,16 +3,28 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.createServerRunner = void 0;
|
|
6
|
-
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
7
6
|
const utils_1 = require("./utils");
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This function should be called only once; you can use the returned `runWithAmplifyServerContext` across
|
|
12
|
+
* your codebase.
|
|
13
|
+
*
|
|
14
|
+
* @param input The input used to create the `runWithAmplifyServerContext` function.
|
|
15
|
+
* @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually
|
|
16
|
+
* created.
|
|
17
|
+
* @returns An object that contains the `runWithAmplifyServerContext` function.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import { createServerRunner } from '@aws-amplify/adapter-nextjs';
|
|
21
|
+
* import config from './amplifyconfiguration.json';
|
|
22
|
+
*
|
|
23
|
+
* export const { runWithAmplifyServerContext } = createServerRunner({ config })
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
9
26
|
const createServerRunner = ({ config, }) => {
|
|
10
|
-
|
|
11
|
-
throw new adapter_core_1.AmplifyServerContextError({
|
|
12
|
-
message: '`createServerRunner` needs to be called only once.',
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
amplifyConfig = (0, utils_1.getAmplifyConfig)(config);
|
|
27
|
+
const amplifyConfig = (0, utils_1.getAmplifyConfig)(config);
|
|
16
28
|
return {
|
|
17
29
|
runWithAmplifyServerContext: (0, utils_1.createRunWithAmplifyServerContext)({
|
|
18
30
|
config: amplifyConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerRunner.js","sourceRoot":"","sources":["../src/createServerRunner.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;
|
|
1
|
+
{"version":3,"file":"createServerRunner.js","sourceRoot":"","sources":["../src/createServerRunner.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAGtC,mCAA8E;AAG9E;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,kBAAkB,GAAkC,CAAC,EACjE,MAAM,GACN,EAAE,EAAE;IACJ,MAAM,aAAa,GAAG,IAAA,wBAAgB,EAAC,MAAM,CAAC,CAAC;IAE/C,OAAO;QACN,2BAA2B,EAAE,IAAA,yCAAiC,EAAC;YAC9D,MAAM,EAAE,aAAa;SACrB,CAAC;KACF,CAAC;AACH,CAAC,CAAC;AAVW,QAAA,kBAAkB,sBAU7B"}
|
|
@@ -4,30 +4,26 @@ import { NextServer } from '../types';
|
|
|
4
4
|
* Generates an API client that can be used inside a Next.js Server Component with Dynamic Rendering
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
|
-
* ```ts
|
|
8
7
|
* import { cookies } from "next/headers"
|
|
9
8
|
*
|
|
10
|
-
* const client = generateServerClientUsingCookies({ cookies })
|
|
11
|
-
* const result = await client.graphql({query: listPosts})
|
|
12
|
-
* ```
|
|
9
|
+
* const client = generateServerClientUsingCookies({ cookies });
|
|
10
|
+
* const result = await client.graphql({ query: listPosts });
|
|
13
11
|
*/
|
|
14
12
|
export declare function generateServerClientUsingCookies<T extends Record<any, any> = never>({ config, cookies, }: NextServer.ServerComponentContext & NextServer.CreateServerRunnerInput): V6ClientSSRCookies<T>;
|
|
15
13
|
/**
|
|
16
14
|
* Generates an API client that can be used with both Pages Router and App Router
|
|
17
15
|
*
|
|
18
16
|
* @example
|
|
19
|
-
*
|
|
17
|
+
* import config from './amplifyconfiguration.json';
|
|
18
|
+
* import { listPosts } from './graphql/queries';
|
|
20
19
|
*
|
|
21
|
-
* const client =
|
|
20
|
+
* const client = generateServerClientUsingReqRes();
|
|
22
21
|
*
|
|
23
22
|
* result = await runWithAmplifyServerContext({
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
})
|
|
31
|
-
* ```
|
|
23
|
+
* nextServerContext: { request, response },
|
|
24
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
25
|
+
* query: listPosts,
|
|
26
|
+
* }),
|
|
27
|
+
* });
|
|
32
28
|
*/
|
|
33
29
|
export declare function generateServerClientUsingReqRes<T extends Record<any, any> = never>({ config }: NextServer.CreateServerRunnerInput): V6ClientSSRRequest<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import { generateServerClient } from '@aws-amplify/api/internals';
|
|
4
4
|
import { getAmplifyServerContext, AmplifyServerContextError, } from '@aws-amplify/core/internals/adapter-core';
|
|
5
5
|
import { __amplify, } from '@aws-amplify/api-graphql';
|
|
6
6
|
import { createServerRunnerForAPI } from './createServerRunnerForAPI';
|
|
@@ -9,12 +9,10 @@ import { getAmplifyConfig } from '../utils';
|
|
|
9
9
|
* Generates an API client that can be used inside a Next.js Server Component with Dynamic Rendering
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
|
-
* ```ts
|
|
13
12
|
* import { cookies } from "next/headers"
|
|
14
13
|
*
|
|
15
|
-
* const client = generateServerClientUsingCookies({ cookies })
|
|
16
|
-
* const result = await client.graphql({query: listPosts})
|
|
17
|
-
* ```
|
|
14
|
+
* const client = generateServerClientUsingCookies({ cookies });
|
|
15
|
+
* const result = await client.graphql({ query: listPosts });
|
|
18
16
|
*/
|
|
19
17
|
export function generateServerClientUsingCookies({ config, cookies, }) {
|
|
20
18
|
if (typeof cookies !== 'function') {
|
|
@@ -32,7 +30,7 @@ export function generateServerClientUsingCookies({ config, cookies, }) {
|
|
|
32
30
|
nextServerContext: { cookies },
|
|
33
31
|
operation: contextSpec => fn(getAmplifyServerContext(contextSpec).amplify),
|
|
34
32
|
});
|
|
35
|
-
return
|
|
33
|
+
return generateServerClient({
|
|
36
34
|
amplify: getAmplify,
|
|
37
35
|
config: resourcesConfig,
|
|
38
36
|
});
|
|
@@ -41,25 +39,23 @@ export function generateServerClientUsingCookies({ config, cookies, }) {
|
|
|
41
39
|
* Generates an API client that can be used with both Pages Router and App Router
|
|
42
40
|
*
|
|
43
41
|
* @example
|
|
44
|
-
*
|
|
42
|
+
* import config from './amplifyconfiguration.json';
|
|
43
|
+
* import { listPosts } from './graphql/queries';
|
|
45
44
|
*
|
|
46
|
-
* const client =
|
|
45
|
+
* const client = generateServerClientUsingReqRes();
|
|
47
46
|
*
|
|
48
47
|
* result = await runWithAmplifyServerContext({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
})
|
|
56
|
-
* ```
|
|
48
|
+
* nextServerContext: { request, response },
|
|
49
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
50
|
+
* query: listPosts,
|
|
51
|
+
* }),
|
|
52
|
+
* });
|
|
57
53
|
*/
|
|
58
54
|
export function generateServerClientUsingReqRes({ config }) {
|
|
59
55
|
const amplifyConfig = getAmplifyConfig(config);
|
|
60
56
|
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
61
57
|
// from server context
|
|
62
|
-
const client =
|
|
58
|
+
const client = generateServerClient({
|
|
63
59
|
amplify: null,
|
|
64
60
|
config: amplifyConfig,
|
|
65
61
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateServerClient.js","sourceRoot":"","sources":["../../src/api/generateServerClient.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"generateServerClient.js","sourceRoot":"","sources":["../../src/api/generateServerClient.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EACN,uBAAuB,EACvB,yBAAyB,GACzB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAKN,SAAS,GACT,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;GAQG;AACH,MAAM,UAAU,gCAAgC,CAE9C,EACD,MAAM,EACN,OAAO,GAE2B;IAClC,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;QAClC,MAAM,IAAI,yBAAyB,CAAC;YACnC,OAAO,EACN,yHAAyH;YAC1H,qBAAqB;YACrB,kBAAkB,EACjB,+FAA+F;SAChG,CAAC,CAAC;KACH;IAED,MAAM,EAAE,2BAA2B,EAAE,eAAe,EAAE,GACrD,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IAEtC,4EAA4E;IAC5E,wDAAwD;IACxD,wEAAwE;IACxE,MAAM,UAAU,GAAG,CAAC,EAAkC,EAAE,EAAE,CACzD,2BAA2B,CAAC;QAC3B,iBAAiB,EAAE,EAAE,OAAO,EAAE;QAC9B,SAAS,EAAE,WAAW,CAAC,EAAE,CACxB,EAAE,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC;KACjD,CAAC,CAAC;IAEJ,OAAO,oBAAoB,CAA2B;QACrD,OAAO,EAAE,UAAU;QACnB,MAAM,EAAE,eAAe;KACvB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,+BAA+B,CAE7C,EAAE,MAAM,EAAsC;IAC/C,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/C,4FAA4F;IAC5F,sBAAsB;IACtB,MAAM,MAAM,GAAG,oBAAoB,CAA2B;QAC7D,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,aAAa;KACrB,CAAC,CAAC;IAEH,uCAAuC;IACvC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAmC,CAAC;IAE/D,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,iBAAkB,EAAE,EAAE;QACnE,MAAM,eAAe,GAAG,uBAAuB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC;QACrE,OAAO,WAAW,CAAC,IAAI,CACtB,EAAE,CAAC,SAAS,CAAC,EAAE,eAAe,EAAE,EAChC,OAAO,EACP,iBAAwB,CACxB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,OAAO,GAAG,cAA6C,CAAC;IAC/D,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -1,2 +1,21 @@
|
|
|
1
1
|
import { NextServer } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This function should be called only once; you can use the returned `runWithAmplifyServerContext` across
|
|
7
|
+
* your codebase.
|
|
8
|
+
*
|
|
9
|
+
* @param input The input used to create the `runWithAmplifyServerContext` function.
|
|
10
|
+
* @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually
|
|
11
|
+
* created.
|
|
12
|
+
* @returns An object that contains the `runWithAmplifyServerContext` function.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { createServerRunner } from '@aws-amplify/adapter-nextjs';
|
|
16
|
+
* import config from './amplifyconfiguration.json';
|
|
17
|
+
*
|
|
18
|
+
* export const { runWithAmplifyServerContext } = createServerRunner({ config })
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
2
21
|
export declare const createServerRunner: NextServer.CreateServerRunner;
|
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
|
|
4
3
|
import { createRunWithAmplifyServerContext, getAmplifyConfig } from './utils';
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This function should be called only once; you can use the returned `runWithAmplifyServerContext` across
|
|
9
|
+
* your codebase.
|
|
10
|
+
*
|
|
11
|
+
* @param input The input used to create the `runWithAmplifyServerContext` function.
|
|
12
|
+
* @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually
|
|
13
|
+
* created.
|
|
14
|
+
* @returns An object that contains the `runWithAmplifyServerContext` function.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import { createServerRunner } from '@aws-amplify/adapter-nextjs';
|
|
18
|
+
* import config from './amplifyconfiguration.json';
|
|
19
|
+
*
|
|
20
|
+
* export const { runWithAmplifyServerContext } = createServerRunner({ config })
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
6
23
|
export const createServerRunner = ({ config, }) => {
|
|
7
|
-
|
|
8
|
-
throw new AmplifyServerContextError({
|
|
9
|
-
message: '`createServerRunner` needs to be called only once.',
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
amplifyConfig = getAmplifyConfig(config);
|
|
24
|
+
const amplifyConfig = getAmplifyConfig(config);
|
|
13
25
|
return {
|
|
14
26
|
runWithAmplifyServerContext: createRunWithAmplifyServerContext({
|
|
15
27
|
config: amplifyConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerRunner.js","sourceRoot":"","sources":["../src/createServerRunner.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;
|
|
1
|
+
{"version":3,"file":"createServerRunner.js","sourceRoot":"","sources":["../src/createServerRunner.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAGtC,OAAO,EAAE,iCAAiC,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAG9E;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAkC,CAAC,EACjE,MAAM,GACN,EAAE,EAAE;IACJ,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE/C,OAAO;QACN,2BAA2B,EAAE,iCAAiC,CAAC;YAC9D,MAAM,EAAE,aAAa;SACrB,CAAC;KACF,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"name": "@aws-amplify/adapter-nextjs",
|
|
4
4
|
"description": "The adapter for the supporting of using Amplify APIs in Next.js.",
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"aws-amplify": "6.0.1-api-v6-models.
|
|
7
|
-
"next": ">=13.4.0 <
|
|
6
|
+
"aws-amplify": "6.0.1-api-v6-models.e8fc3ba.0+e8fc3ba",
|
|
7
|
+
"next": ">=13.4.0 <15.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"cookie": "0.5.0",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"@types/node": "^20.3.1",
|
|
16
16
|
"@types/react": "^18.2.13",
|
|
17
17
|
"@types/react-dom": "^18.2.6",
|
|
18
|
-
"aws-amplify": "6.0.1-api-v6-models.
|
|
18
|
+
"aws-amplify": "6.0.1-api-v6-models.e8fc3ba.0+e8fc3ba",
|
|
19
19
|
"jest-fetch-mock": "3.0.3",
|
|
20
|
-
"next": ">= 13.4.0 <
|
|
20
|
+
"next": ">= 13.4.0 < 15.0.0",
|
|
21
21
|
"typescript": "5.1.6"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
@@ -54,7 +54,8 @@
|
|
|
54
54
|
"lib-esm",
|
|
55
55
|
"src",
|
|
56
56
|
"with-amplify",
|
|
57
|
-
"internals"
|
|
57
|
+
"internals",
|
|
58
|
+
"api"
|
|
58
59
|
],
|
|
59
60
|
"homepage": "https://aws-amplify.github.io/",
|
|
60
61
|
"jest": {
|
|
@@ -120,6 +121,6 @@
|
|
|
120
121
|
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 90.31"
|
|
121
122
|
},
|
|
122
123
|
"typings": "./lib-esm/index.d.ts",
|
|
123
|
-
"version": "1.0.1-api-v6-models.
|
|
124
|
-
"gitHead": "
|
|
124
|
+
"version": "1.0.1-api-v6-models.e8fc3ba.0+e8fc3ba",
|
|
125
|
+
"gitHead": "e8fc3ba880c70b8ba4f2ccdfb1d99ed7268a5d29"
|
|
125
126
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { generateServerClient } from '@aws-amplify/api/internals';
|
|
5
5
|
import {
|
|
6
6
|
getAmplifyServerContext,
|
|
7
7
|
AmplifyServerContextError,
|
|
@@ -21,12 +21,10 @@ import { getAmplifyConfig } from '../utils';
|
|
|
21
21
|
* Generates an API client that can be used inside a Next.js Server Component with Dynamic Rendering
|
|
22
22
|
*
|
|
23
23
|
* @example
|
|
24
|
-
* ```ts
|
|
25
24
|
* import { cookies } from "next/headers"
|
|
26
25
|
*
|
|
27
|
-
* const client = generateServerClientUsingCookies({ cookies })
|
|
28
|
-
* const result = await client.graphql({query: listPosts})
|
|
29
|
-
* ```
|
|
26
|
+
* const client = generateServerClientUsingCookies({ cookies });
|
|
27
|
+
* const result = await client.graphql({ query: listPosts });
|
|
30
28
|
*/
|
|
31
29
|
export function generateServerClientUsingCookies<
|
|
32
30
|
T extends Record<any, any> = never
|
|
@@ -58,7 +56,7 @@ export function generateServerClientUsingCookies<
|
|
|
58
56
|
fn(getAmplifyServerContext(contextSpec).amplify),
|
|
59
57
|
});
|
|
60
58
|
|
|
61
|
-
return
|
|
59
|
+
return generateServerClient<T, V6ClientSSRCookies<T>>({
|
|
62
60
|
amplify: getAmplify,
|
|
63
61
|
config: resourcesConfig,
|
|
64
62
|
});
|
|
@@ -68,19 +66,17 @@ export function generateServerClientUsingCookies<
|
|
|
68
66
|
* Generates an API client that can be used with both Pages Router and App Router
|
|
69
67
|
*
|
|
70
68
|
* @example
|
|
71
|
-
*
|
|
69
|
+
* import config from './amplifyconfiguration.json';
|
|
70
|
+
* import { listPosts } from './graphql/queries';
|
|
71
|
+
*
|
|
72
|
+
* const client = generateServerClientUsingReqRes();
|
|
72
73
|
*
|
|
73
|
-
* const client = generateServerClient()
|
|
74
|
-
*
|
|
75
74
|
* result = await runWithAmplifyServerContext({
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
})
|
|
83
|
-
* ```
|
|
75
|
+
* nextServerContext: { request, response },
|
|
76
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
77
|
+
* query: listPosts,
|
|
78
|
+
* }),
|
|
79
|
+
* });
|
|
84
80
|
*/
|
|
85
81
|
export function generateServerClientUsingReqRes<
|
|
86
82
|
T extends Record<any, any> = never
|
|
@@ -88,7 +84,7 @@ export function generateServerClientUsingReqRes<
|
|
|
88
84
|
const amplifyConfig = getAmplifyConfig(config);
|
|
89
85
|
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
90
86
|
// from server context
|
|
91
|
-
const client =
|
|
87
|
+
const client = generateServerClient<T, V6ClientSSRRequest<T>>({
|
|
92
88
|
amplify: null,
|
|
93
89
|
config: amplifyConfig,
|
|
94
90
|
});
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { ResourcesConfig } from '
|
|
5
|
-
import { parseAWSExports } from '@aws-amplify/core/internals/utils';
|
|
6
|
-
import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core';
|
|
4
|
+
import { ResourcesConfig } from 'aws-amplify';
|
|
7
5
|
import { createRunWithAmplifyServerContext, getAmplifyConfig } from './utils';
|
|
8
6
|
import { NextServer } from './types';
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* This function should be called only once; you can use the returned `runWithAmplifyServerContext` across
|
|
13
|
+
* your codebase.
|
|
14
|
+
*
|
|
15
|
+
* @param input The input used to create the `runWithAmplifyServerContext` function.
|
|
16
|
+
* @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually
|
|
17
|
+
* created.
|
|
18
|
+
* @returns An object that contains the `runWithAmplifyServerContext` function.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* import { createServerRunner } from '@aws-amplify/adapter-nextjs';
|
|
22
|
+
* import config from './amplifyconfiguration.json';
|
|
23
|
+
*
|
|
24
|
+
* export const { runWithAmplifyServerContext } = createServerRunner({ config })
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
12
27
|
export const createServerRunner: NextServer.CreateServerRunner = ({
|
|
13
28
|
config,
|
|
14
29
|
}) => {
|
|
15
|
-
|
|
16
|
-
throw new AmplifyServerContextError({
|
|
17
|
-
message: '`createServerRunner` needs to be called only once.',
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
amplifyConfig = getAmplifyConfig(config);
|
|
30
|
+
const amplifyConfig = getAmplifyConfig(config);
|
|
22
31
|
|
|
23
32
|
return {
|
|
24
33
|
runWithAmplifyServerContext: createRunWithAmplifyServerContext({
|