@stephenchenorg/astro 1.5.0 → 2.0.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/dist/api/fetch.d.ts +8 -3
- package/dist/api/fetch.js +6 -5
- package/dist/page/field/helpers.d.ts +1 -1
- package/package.json +9 -9
package/dist/api/fetch.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { APIContext } from 'astro';
|
|
1
2
|
import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
2
3
|
export interface CreateGraphQLAPIOptions {
|
|
3
4
|
endpoint: string;
|
|
4
|
-
defaultVariables?: Record<string, any> | (() => Record<string, any>);
|
|
5
|
-
fetchOptions?: RequestInit | (() => RequestInit);
|
|
5
|
+
defaultVariables?: Record<string, any> | ((astroContext?: APIContext) => Record<string, any>);
|
|
6
|
+
fetchOptions?: RequestInit | ((astroContext?: APIContext) => RequestInit);
|
|
6
7
|
}
|
|
7
|
-
export declare function createGraphQLAPI(
|
|
8
|
+
export declare function createGraphQLAPI(globalOptions: CreateGraphQLAPIOptions): <TData extends Record<string, any>, TVariables extends Record<string, any> = Record<string, any>>(query: TypedDocumentNode<TData, TVariables>, options?: {
|
|
9
|
+
variables?: TVariables;
|
|
10
|
+
fetchOptions?: RequestInit;
|
|
11
|
+
Astro?: APIContext;
|
|
12
|
+
}) => Promise<TData>;
|
|
8
13
|
export { gql } from 'graphql-tag';
|
package/dist/api/fetch.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { AwesomeGraphQLClient, GraphQLRequestError as AwesomeGraphQLRequestError } from "awesome-graphql-client";
|
|
2
2
|
import { print } from "graphql/language/printer";
|
|
3
3
|
import { GraphQLNotFoundError, GraphQLRequestError, GraphQLValidationError } from "./error.js";
|
|
4
|
-
export function createGraphQLAPI(
|
|
4
|
+
export function createGraphQLAPI(globalOptions) {
|
|
5
5
|
const client = new AwesomeGraphQLClient({
|
|
6
|
-
endpoint:
|
|
6
|
+
endpoint: globalOptions.endpoint,
|
|
7
7
|
formatQuery: (query) => print(query)
|
|
8
8
|
});
|
|
9
|
-
return function graphQLAPI(query,
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
return function graphQLAPI(query, options) {
|
|
10
|
+
const { variables, fetchOptions, Astro: astroContext } = options || {};
|
|
11
|
+
const defaultVariables = typeof globalOptions.defaultVariables === "function" ? globalOptions.defaultVariables(astroContext) : globalOptions.defaultVariables;
|
|
12
|
+
const defaultFetchOptions = typeof globalOptions.fetchOptions === "function" ? globalOptions.fetchOptions(astroContext) : globalOptions.fetchOptions;
|
|
12
13
|
return new Promise((resolve, reject) => {
|
|
13
14
|
client.request(query, {
|
|
14
15
|
...defaultVariables,
|
|
@@ -3,5 +3,5 @@ export declare function isPlainTextField(field: PageField): field is PagePlainTe
|
|
|
3
3
|
export declare function isPlainTextareaField(field: PageField): field is PagePlainTextareaField;
|
|
4
4
|
export declare function isContentField(field: PageField): field is PageContentField;
|
|
5
5
|
export declare function isImageField(field: PageField): field is PageImageField;
|
|
6
|
-
export declare function pageTextField(fields: PageField[], key: string):
|
|
6
|
+
export declare function pageTextField(fields: PageField[], key: string): string | null;
|
|
7
7
|
export declare function pageImageFieldForBackground(fields: PageField[], key: string): string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stephenchenorg/astro",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "Stephenchenorg Astro 前端通用套件",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://stephenchenorg-astro.netlify.app",
|
|
@@ -67,19 +67,19 @@
|
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
69
69
|
"awesome-graphql-client": "^2.1.0",
|
|
70
|
-
"graphql": "^16.
|
|
70
|
+
"graphql": "^16.11.0",
|
|
71
71
|
"graphql-tag": "^2.12.6",
|
|
72
|
-
"nanostores": "^0.
|
|
73
|
-
"query-string": "^9.
|
|
72
|
+
"nanostores": "^1.0.1",
|
|
73
|
+
"query-string": "^9.2.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@astrojs/check": "^0.9.4",
|
|
77
77
|
"@ycs77/eslint-config": "^4.1.0",
|
|
78
|
-
"astro": "^5.
|
|
79
|
-
"bumpp": "^10.
|
|
80
|
-
"eslint": "^9.
|
|
78
|
+
"astro": "^5.8.0",
|
|
79
|
+
"bumpp": "^10.1.1",
|
|
80
|
+
"eslint": "^9.27.0",
|
|
81
81
|
"eslint-plugin-astro": "^1.3.1",
|
|
82
|
-
"mkdist": "^2.
|
|
83
|
-
"typescript": "~5.
|
|
82
|
+
"mkdist": "^2.3.0",
|
|
83
|
+
"typescript": "~5.8.3"
|
|
84
84
|
}
|
|
85
85
|
}
|