@cedarjs/web 7.0.0 → 8.0.0-canary.3263
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/apollo/ApolloClientFactoryContext.d.ts +26 -0
- package/dist/apollo/ApolloClientFactoryContext.d.ts.map +1 -0
- package/dist/apollo/ApolloClientFactoryContext.js +5 -0
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts +9 -3
- package/dist/apollo/ApolloProviderWithFetchConfig.d.ts.map +1 -1
- package/dist/apollo/ApolloProviderWithFetchConfig.js +60 -37
- package/dist/apollo/CedarApolloProvider.d.ts +1 -0
- package/dist/apollo/CedarApolloProvider.d.ts.map +1 -1
- package/dist/apollo/CedarApolloProvider.js +13 -6
- package/dist/apollo/apolloLinkTypes.d.ts +9 -4
- package/dist/apollo/apolloLinkTypes.d.ts.map +1 -1
- package/dist/apollo/fragmentRegistry.d.ts +3 -3
- package/dist/apollo/fragmentRegistry.d.ts.map +1 -1
- package/dist/apollo/fragmentRegistry.js +35 -8
- package/dist/apollo/index.d.ts +4 -0
- package/dist/apollo/index.d.ts.map +1 -1
- package/dist/apollo/index.js +3 -1
- package/dist/apollo/links.d.ts +6 -5
- package/dist/apollo/links.d.ts.map +1 -1
- package/dist/apollo/links.js +14 -9
- package/dist/apollo/parsedScalars.d.ts +36 -0
- package/dist/apollo/parsedScalars.d.ts.map +1 -0
- package/dist/apollo/parsedScalars.js +75 -0
- package/dist/apollo/sseLink.d.ts +5 -8
- package/dist/apollo/sseLink.d.ts.map +1 -1
- package/dist/apollo/sseLink.js +9 -12
- package/dist/apollo/suspense.d.ts +5 -3
- package/dist/apollo/suspense.d.ts.map +1 -1
- package/dist/apollo/suspense.js +35 -7
- package/dist/apollo/typeOverrides.d.ts +8 -0
- package/dist/apollo/typeOverrides.d.ts.map +1 -0
- package/dist/apollo/typeOverrides.js +0 -0
- package/dist/apollo/useCache.d.ts +4 -6
- package/dist/apollo/useCache.d.ts.map +1 -1
- package/dist/apollo/useCache.js +1 -1
- package/dist/apollo/useCreateApolloClient.d.ts +11 -0
- package/dist/apollo/useCreateApolloClient.d.ts.map +1 -0
- package/dist/apollo/useCreateApolloClient.js +14 -0
- package/dist/bundled/apollo-upload-client.d.ts +2 -2
- package/dist/bundled/apollo-upload-client.d.ts.map +1 -1
- package/dist/bundled/apollo-upload-client.js +1562 -1734
- package/dist/components/DevFatalErrorPage.d.ts +3 -3
- package/dist/components/DevFatalErrorPage.d.ts.map +1 -1
- package/dist/components/DevFatalErrorPage.js +66 -49
- package/dist/components/FatalErrorBoundary.d.ts +1 -1
- package/dist/components/cell/CellErrorBoundary.d.ts +3 -3
- package/dist/components/cell/CellErrorBoundary.d.ts.map +1 -1
- package/dist/components/cell/cellTypes.d.ts +51 -18
- package/dist/components/cell/cellTypes.d.ts.map +1 -1
- package/dist/components/cell/createCell.d.ts +2 -1
- package/dist/components/cell/createCell.d.ts.map +1 -1
- package/dist/components/cell/createCell.js +65 -60
- package/dist/components/cell/createFragmentCell.d.ts +2 -1
- package/dist/components/cell/createFragmentCell.d.ts.map +1 -1
- package/dist/components/cell/createFragmentCell.js +4 -2
- package/dist/components/cell/createServerCell.d.ts +3 -2
- package/dist/components/cell/createServerCell.d.ts.map +1 -1
- package/dist/components/cell/createServerCell.js +4 -2
- package/dist/components/cell/createSuspendingCell.d.ts +2 -1
- package/dist/components/cell/createSuspendingCell.d.ts.map +1 -1
- package/dist/components/cell/createSuspendingCell.js +37 -34
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -5
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.d.ts.map +1 -1
- package/package.json +20 -26
- package/apollo/index.js +0 -1
- package/apollo/package.json +0 -5
- package/toast/index.js +0 -1
- package/toast/package.json +0 -5
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { GraphQLFormattedError } from 'graphql';
|
|
3
3
|
type RequestDetails = {
|
|
4
4
|
query: string;
|
|
5
5
|
operationName: string;
|
|
6
6
|
operationKind: string;
|
|
7
7
|
variables: any;
|
|
8
8
|
};
|
|
9
|
-
interface EnhancedGqlError extends
|
|
9
|
+
interface EnhancedGqlError extends GraphQLFormattedError {
|
|
10
10
|
__RedwoodEnhancedError: RequestDetails;
|
|
11
11
|
}
|
|
12
12
|
type ErrorWithRequestMeta = Error & {
|
|
13
13
|
mostRecentRequest?: RequestDetails;
|
|
14
|
-
|
|
14
|
+
errors?: EnhancedGqlError[];
|
|
15
15
|
mostRecentResponse?: any;
|
|
16
16
|
};
|
|
17
17
|
export declare const DevFatalErrorPage: (props: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DevFatalErrorPage.d.ts","sourceRoot":"","sources":["../../src/components/DevFatalErrorPage.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAsC,MAAM,OAAO,CAAA;AAE1D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"DevFatalErrorPage.d.ts","sourceRoot":"","sources":["../../src/components/DevFatalErrorPage.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAsC,MAAM,OAAO,CAAA;AAE1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAmBpD,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,GAAG,CAAA;CACf,CAAA;AAED,UAAU,gBAAiB,SAAQ,qBAAqB;IACtD,sBAAsB,EAAE,cAAc,CAAA;CACvC;AAID,KAAK,oBAAoB,GAAG,KAAK,GAAG;IAClC,iBAAiB,CAAC,EAAE,cAAc,CAAA;IAClC,MAAM,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC3B,kBAAkB,CAAC,EAAE,GAAG,CAAA;CACzB,CAAA;AA+GD,eAAO,MAAM,iBAAiB,GAAI,OAAO;IAAE,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAAE,sBA4FxE,CAAA"}
|
|
@@ -10,73 +10,90 @@ if (/^[A-Z]:\\/.test(srcRoot)) {
|
|
|
10
10
|
} else {
|
|
11
11
|
appRoot = srcRoot.substring(1);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
function formatMarkdownCode(value) {
|
|
14
|
+
const fence = "`".repeat(longestBacktickRun(value) + 1);
|
|
15
|
+
const padding = value.startsWith("`") || value.endsWith("`") ? " " : "";
|
|
16
|
+
return `${fence}${padding}${value}${padding}${fence}`;
|
|
17
|
+
}
|
|
18
|
+
function formatMarkdownCodeBlock(value, language) {
|
|
19
|
+
const fence = "`".repeat(Math.max(3, longestBacktickRun(value) + 1));
|
|
20
|
+
return `${fence}${language}
|
|
21
|
+
${value}
|
|
22
|
+
${fence}`;
|
|
23
|
+
}
|
|
24
|
+
function longestBacktickRun(value) {
|
|
25
|
+
return Array.from(value.matchAll(/`+/g)).reduce(
|
|
26
|
+
(longest, [run]) => Math.max(longest, run.length),
|
|
27
|
+
0
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function formatErrorForClipboard(stack, typeName, msg, errorWithMeta) {
|
|
31
|
+
const sections = [
|
|
32
|
+
`## Error
|
|
33
|
+
|
|
34
|
+
${formatMarkdownCode(typeName)}: ${formatMarkdownCode(msg)}`
|
|
35
|
+
];
|
|
36
|
+
const mostRecentRequest = errorWithMeta.mostRecentRequest || errorWithMeta.errors?.find((gqlErr) => gqlErr.__RedwoodEnhancedError)?.__RedwoodEnhancedError;
|
|
23
37
|
if (mostRecentRequest) {
|
|
24
|
-
|
|
25
|
-
lines.push("REQUEST CONTEXT");
|
|
26
|
-
lines.push("-".repeat(80));
|
|
27
|
-
lines.push(`Operation: ${mostRecentRequest.operationName}`);
|
|
28
|
-
lines.push(`Kind: ${mostRecentRequest.operationKind}`);
|
|
29
|
-
lines.push("");
|
|
30
|
-
lines.push("Variables:");
|
|
38
|
+
let variables;
|
|
31
39
|
try {
|
|
32
|
-
|
|
40
|
+
variables = JSON.stringify(mostRecentRequest.variables, null, 2) ?? "undefined";
|
|
33
41
|
} catch {
|
|
34
|
-
|
|
42
|
+
variables = "Unable to stringify variables";
|
|
35
43
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
sections.push(
|
|
45
|
+
[
|
|
46
|
+
"## Request",
|
|
47
|
+
"",
|
|
48
|
+
`${mostRecentRequest.operationKind} ${mostRecentRequest.operationName}`,
|
|
49
|
+
"",
|
|
50
|
+
"### Variables",
|
|
51
|
+
"",
|
|
52
|
+
formatMarkdownCodeBlock(variables, "json"),
|
|
53
|
+
"",
|
|
54
|
+
"### Query",
|
|
55
|
+
"",
|
|
56
|
+
formatMarkdownCodeBlock(mostRecentRequest.query, "graphql")
|
|
57
|
+
].join("\n")
|
|
58
|
+
);
|
|
40
59
|
}
|
|
41
60
|
if (errorWithMeta.mostRecentResponse) {
|
|
42
|
-
|
|
43
|
-
lines.push("RESPONSE CONTEXT");
|
|
44
|
-
lines.push("-".repeat(80));
|
|
61
|
+
let response;
|
|
45
62
|
try {
|
|
46
|
-
|
|
63
|
+
response = JSON.stringify(errorWithMeta.mostRecentResponse, null, 2) ?? "undefined";
|
|
47
64
|
} catch {
|
|
48
|
-
|
|
65
|
+
response = "Unable to stringify response";
|
|
49
66
|
}
|
|
50
|
-
|
|
67
|
+
sections.push(`## Response
|
|
68
|
+
|
|
69
|
+
${formatMarkdownCodeBlock(response, "json")}`);
|
|
51
70
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
lines.push("-".repeat(80));
|
|
55
|
-
stack.items.forEach((entry, i) => {
|
|
56
|
-
const fileShort = entry.fileShort || "[Unknown]";
|
|
71
|
+
const stackEntries = stack.items.map((entry, i) => {
|
|
72
|
+
const file = entry.fileShort || "[Unknown]";
|
|
57
73
|
const callee = entry.callee || "[Anonymous]";
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
lines.push(`[${i}] ${fileShort}:${line}:${column} in ${callee}`);
|
|
74
|
+
const location = `${file}:${entry.line || "?"}:${entry.column || "?"}`;
|
|
75
|
+
const lines = [`${i + 1}. \`${location}\` in \`${callee}\``];
|
|
61
76
|
const sourceFile = entry.sourceFile;
|
|
62
|
-
if (sourceFile?.lines && sourceFile.lines.length
|
|
63
|
-
const lineIndex =
|
|
77
|
+
if (sourceFile?.lines.length && entry.line && entry.line <= sourceFile.lines.length && !entry.thirdParty) {
|
|
78
|
+
const lineIndex = entry.line - 1;
|
|
64
79
|
const window = 2;
|
|
65
80
|
const start = Math.max(0, lineIndex - window);
|
|
66
81
|
const end = Math.min(sourceFile.lines.length, lineIndex + window + 1);
|
|
67
|
-
|
|
82
|
+
const sourceLines = [];
|
|
68
83
|
for (let idx = start; idx < end; idx++) {
|
|
69
|
-
const marker = idx === lineIndex ? ">
|
|
70
|
-
|
|
71
|
-
|
|
84
|
+
const marker = idx === lineIndex ? ">" : " ";
|
|
85
|
+
sourceLines.push(
|
|
86
|
+
`${marker} ${(idx + 1).toString().padStart(4)} | ${sourceFile.lines[idx]}`
|
|
72
87
|
);
|
|
73
88
|
}
|
|
74
|
-
lines.push("");
|
|
89
|
+
lines.push("", formatMarkdownCodeBlock(sourceLines.join("\n"), "text"));
|
|
75
90
|
}
|
|
91
|
+
return lines.join("\n");
|
|
76
92
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
93
|
+
sections.push(`## Stack trace
|
|
94
|
+
|
|
95
|
+
${stackEntries.join("\n\n")}`);
|
|
96
|
+
return sections.join("\n\n");
|
|
80
97
|
}
|
|
81
98
|
const DevFatalErrorPage = (props) => {
|
|
82
99
|
const [copyFeedback, setCopyFeedback] = useState("");
|
|
@@ -99,7 +116,7 @@ const DevFatalErrorPage = (props) => {
|
|
|
99
116
|
const msg = String(err?.message);
|
|
100
117
|
const FileRef = stack.items[0] ? /* @__PURE__ */ React.createElement("a", { href: toVSCodeURL(stack.items[0]) }, stack.items[0].fileName) : null;
|
|
101
118
|
const handleCopyAll = async () => {
|
|
102
|
-
const errorText = formatErrorForClipboard(
|
|
119
|
+
const errorText = formatErrorForClipboard(stack, typeName, msg, err);
|
|
103
120
|
try {
|
|
104
121
|
await navigator.clipboard.writeText(errorText);
|
|
105
122
|
setCopyFeedback("\u2713 Copied to clipboard");
|
|
@@ -194,7 +211,7 @@ function ResponseRequest(props) {
|
|
|
194
211
|
if (!props.error) {
|
|
195
212
|
return null;
|
|
196
213
|
}
|
|
197
|
-
const mostRecentRequest = props.error.mostRecentRequest || props.error.
|
|
214
|
+
const mostRecentRequest = props.error.mostRecentRequest || props.error.errors?.find((gqlErr) => gqlErr.__RedwoodEnhancedError)?.__RedwoodEnhancedError;
|
|
198
215
|
const mostRecentResponse = props.error.mostRecentResponse;
|
|
199
216
|
return /* @__PURE__ */ React.createElement("div", { className: "request-response" }, mostRecentRequest ? /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h4", null, "Request: ", mostRecentRequest.operationName), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h5", null, "Variables:"), /* @__PURE__ */ React.createElement("code", null, /* @__PURE__ */ React.createElement("pre", null, JSON.stringify(mostRecentRequest.variables, null, " ")))), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h5", null, "Query:"), /* @__PURE__ */ React.createElement("code", null, /* @__PURE__ */ React.createElement(
|
|
200
217
|
"pre",
|
|
@@ -18,7 +18,7 @@ declare class FatalErrorBoundary extends React.Component<PropsFatalErrorBoundary
|
|
|
18
18
|
hasError: boolean;
|
|
19
19
|
error: Error;
|
|
20
20
|
};
|
|
21
|
-
render(): string | number | boolean | Iterable<React.ReactNode> | React.
|
|
21
|
+
render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode> | null | undefined> | React.JSX.Element | null | undefined;
|
|
22
22
|
}
|
|
23
23
|
export { FatalErrorBoundary };
|
|
24
24
|
//# sourceMappingURL=FatalErrorBoundary.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { useQuery } from '@apollo/client/react';
|
|
3
3
|
import type { CellFailureProps } from './cellTypes.js';
|
|
4
4
|
export type FallbackProps = {
|
|
5
|
-
error:
|
|
5
|
+
error: useQuery.Result['error'];
|
|
6
6
|
resetErrorBoundary: () => void;
|
|
7
7
|
};
|
|
8
8
|
export type CellErrorBoundaryProps = {
|
|
@@ -11,7 +11,7 @@ export type CellErrorBoundaryProps = {
|
|
|
11
11
|
};
|
|
12
12
|
interface ErrState {
|
|
13
13
|
hasError: boolean;
|
|
14
|
-
error?:
|
|
14
|
+
error?: useQuery.Result['error'];
|
|
15
15
|
}
|
|
16
16
|
export declare class CellErrorBoundary extends React.Component<CellErrorBoundaryProps, ErrState> {
|
|
17
17
|
constructor(props: CellErrorBoundaryProps);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CellErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/cell/CellErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"CellErrorBoundary.d.ts","sourceRoot":"","sources":["../../../src/components/cell/CellErrorBoundary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAEpD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC/B,kBAAkB,EAAE,MAAM,IAAI,CAAA;CAC/B,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IAGnC,cAAc,EAAE,CACd,OAAO,EAAE,aAAa,KACnB,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA;IACzC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED,UAAU,QAAQ;IAChB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;CACjC;AAED,qBAAa,iBAAkB,SAAQ,KAAK,CAAC,SAAS,CACpD,sBAAsB,EACtB,QAAQ,CACT;gBACa,KAAK,EAAE,sBAAsB;IAKzC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK;;;;IAI5C,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS;IAQ1D,MAAM;CAgBP"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ComponentProps, JSXElementConstructor } from 'react';
|
|
2
|
-
import type { ApolloClient, NetworkStatus, OperationVariables,
|
|
1
|
+
import type { ComponentProps, JSX, JSXElementConstructor } from 'react';
|
|
2
|
+
import type { ApolloClient, NetworkStatus, OperationVariables, TypedDocumentNode } from '@apollo/client';
|
|
3
|
+
import type { QueryRef, SkipToken, useBackgroundQuery, useQuery } from '@apollo/client/react';
|
|
3
4
|
import type { DocumentNode } from 'graphql';
|
|
4
5
|
import type { A, L, O, U } from 'ts-toolbelt';
|
|
5
6
|
/**
|
|
@@ -21,7 +22,7 @@ type CellPropsVariables<Cell, GQLVariables> = Cell extends {
|
|
|
21
22
|
* Cell component props which is the combination of query variables and Success props.
|
|
22
23
|
*/
|
|
23
24
|
export type CellProps<CellSuccess extends keyof JSX.IntrinsicElements | JSXElementConstructor<any>, GQLResult, CellType, GQLVariables> = A.Compute<Omit<ComponentProps<CellSuccess>, keyof CellPropsVariables<CellType, GQLVariables> | keyof (GQLVariables extends Record<string, never> ? unknown : GQLVariables) | keyof GQLResult | 'updating' | 'queryResult'> & CellPropsVariables<CellType, GQLVariables>>;
|
|
24
|
-
type InputVarProps<T> = T extends {
|
|
25
|
+
type InputVarProps<T> = unknown extends T ? unknown : T extends {
|
|
25
26
|
[key: string]: never;
|
|
26
27
|
} ? unknown : T;
|
|
27
28
|
export type CellLoadingProps<TVariables extends OperationVariables = any> = {
|
|
@@ -29,7 +30,7 @@ export type CellLoadingProps<TVariables extends OperationVariables = any> = {
|
|
|
29
30
|
} & InputVarProps<TVariables>;
|
|
30
31
|
export type CellFailureProps<TVariables extends OperationVariables = any> = {
|
|
31
32
|
queryResult?: NonSuspenseCellQueryResult<TVariables, any> | SuspenseCellQueryResult;
|
|
32
|
-
error?:
|
|
33
|
+
error?: useQuery.Result['error'] | Error;
|
|
33
34
|
/**
|
|
34
35
|
* @see {@link https://www.apollographql.com/docs/apollo-server/data/errors/#error-codes}
|
|
35
36
|
*/
|
|
@@ -75,17 +76,50 @@ export type CellSuccessProps<TData = any, TVariables extends OperationVariables
|
|
|
75
76
|
export type DataObject = {
|
|
76
77
|
[key: string]: unknown;
|
|
77
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* What `beforeQuery` returns is handed straight to the GraphQL client's query
|
|
81
|
+
* hook, so any of that hook's options can be set here.
|
|
82
|
+
*/
|
|
83
|
+
export type CellBeforeQueryOptions<CellVariables> = {
|
|
84
|
+
variables: CellVariables;
|
|
85
|
+
} & Omit<useQuery.Options<DataObject, OperationVariables>, 'variables'>;
|
|
86
|
+
/**
|
|
87
|
+
* `beforeQuery` can return `skipToken` instead of an options object to keep the
|
|
88
|
+
* query from being executed at all. A skipped Cell renders nothing -- none of
|
|
89
|
+
* `Loading`, `Empty`, `Failure` or `Success` are rendered.
|
|
90
|
+
*
|
|
91
|
+
* @see {@link https://www.apollographql.com/docs/react/api/react/hooks#skiptoken}
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { skipToken } from '@apollo/client/react'
|
|
96
|
+
*
|
|
97
|
+
* export const beforeQuery = ({ id }) => {
|
|
98
|
+
* const otherId = useStore((state) => state.getOther(id))
|
|
99
|
+
*
|
|
100
|
+
* return otherId ? { variables: { id, otherId } } : skipToken
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export type CellBeforeQueryResult<CellVariables> = CellBeforeQueryOptions<CellVariables> | SkipToken;
|
|
78
105
|
/**
|
|
79
106
|
* The main interface.
|
|
107
|
+
*
|
|
108
|
+
* @param GQLResult - The shape of the data returned by `QUERY` (or, for
|
|
109
|
+
* fragment Cells, the shape of the fragment's data). This is what
|
|
110
|
+
* `Success`/`Empty` receive their data as. Defaults to `any` so Cells that
|
|
111
|
+
* don't -- or can't -- type their `QUERY` with `TypedDocumentNode` (e.g. in
|
|
112
|
+
* tests, or Cells built from a plain string) keep the pre-existing loose
|
|
113
|
+
* behavior instead of erroring.
|
|
80
114
|
*/
|
|
81
|
-
export interface CreateCellProps<CellProps, CellVariables> {
|
|
115
|
+
export interface CreateCellProps<CellProps, CellVariables extends OperationVariables = OperationVariables, GQLResult = any> {
|
|
82
116
|
/**
|
|
83
117
|
* The GraphQL syntax tree to execute or function to call that returns it.
|
|
84
118
|
* If `QUERY` is a function, it's called with the result of `beforeQuery`.
|
|
85
119
|
*
|
|
86
120
|
* Either `QUERY` or `FRAGMENT` must be provided.
|
|
87
121
|
*/
|
|
88
|
-
QUERY?: DocumentNode | ((variables: Record<string, unknown>) => DocumentNode);
|
|
122
|
+
QUERY?: TypedDocumentNode<GQLResult, CellVariables> | DocumentNode | ((variables: Record<string, unknown>) => DocumentNode);
|
|
89
123
|
/**
|
|
90
124
|
* A GraphQL fragment that declares this Cell's data requirements. Fragment
|
|
91
125
|
* Cells don't fire their own query. Instead a parent Cell spreads the
|
|
@@ -99,12 +133,11 @@ export interface CreateCellProps<CellProps, CellVariables> {
|
|
|
99
133
|
FRAGMENT?: DocumentNode;
|
|
100
134
|
/**
|
|
101
135
|
* Parse `props` into query variables. Most of the time `props` are appropriate variables as is.
|
|
136
|
+
*
|
|
137
|
+
* Any other option the GraphQL client's query hook accepts can be returned
|
|
138
|
+
* here as well. Return `skipToken` to not execute the query at all.
|
|
102
139
|
*/
|
|
103
|
-
beforeQuery?: ((props: CellProps) =>
|
|
104
|
-
variables: CellVariables;
|
|
105
|
-
}) | (() => {
|
|
106
|
-
variables: CellVariables;
|
|
107
|
-
});
|
|
140
|
+
beforeQuery?: ((props: CellProps) => CellBeforeQueryResult<CellVariables>) | (() => CellBeforeQueryResult<CellVariables>);
|
|
108
141
|
/**
|
|
109
142
|
* Sanitize the data returned from the query.
|
|
110
143
|
*/
|
|
@@ -134,19 +167,19 @@ export interface CreateCellProps<CellProps, CellVariables> {
|
|
|
134
167
|
/**
|
|
135
168
|
* If the query's in flight and there's no stale data, render this.
|
|
136
169
|
*/
|
|
137
|
-
Loading?: React.FC<CellLoadingProps & Partial<CellProps>>;
|
|
170
|
+
Loading?: React.FC<CellLoadingProps<CellVariables> & Partial<CellProps>>;
|
|
138
171
|
/**
|
|
139
172
|
* If something went wrong, render this.
|
|
140
173
|
*/
|
|
141
|
-
Failure?: React.FC<CellFailureProps & Partial<CellProps>>;
|
|
174
|
+
Failure?: React.FC<CellFailureProps<CellVariables> & Partial<CellProps>>;
|
|
142
175
|
/**
|
|
143
176
|
* If no data was returned, render this.
|
|
144
177
|
*/
|
|
145
|
-
Empty?: React.FC<CellSuccessProps & Partial<CellProps>>;
|
|
178
|
+
Empty?: React.FC<CellSuccessProps<GQLResult, CellVariables> & Partial<CellProps>>;
|
|
146
179
|
/**
|
|
147
180
|
* If data was returned, render this.
|
|
148
181
|
*/
|
|
149
|
-
Success: React.FC<CellSuccessProps & Partial<CellProps>>;
|
|
182
|
+
Success: React.FC<CellSuccessProps<GQLResult, CellVariables> & Partial<CellProps>>;
|
|
150
183
|
/**
|
|
151
184
|
* What to call the Cell. Defaults to the filename.
|
|
152
185
|
*/
|
|
@@ -157,9 +190,9 @@ export type SuspendingSuccessProps = React.PropsWithChildren<Record<string, unkn
|
|
|
157
190
|
suspenseQueryResult: SuspenseCellQueryResult<DataObject, any>;
|
|
158
191
|
userProps: Record<string, any>;
|
|
159
192
|
};
|
|
160
|
-
export type NonSuspenseCellQueryResult<TVariables extends OperationVariables = any, TData = any> = Partial<Omit<
|
|
161
|
-
export interface SuspenseCellQueryResult<_TData = any, _TVariables extends OperationVariables = any> extends
|
|
162
|
-
client: ApolloClient
|
|
193
|
+
export type NonSuspenseCellQueryResult<TVariables extends OperationVariables = any, TData = any> = Partial<Omit<useQuery.Result<TData, TVariables>, 'loading' | 'error' | 'data'>>;
|
|
194
|
+
export interface SuspenseCellQueryResult<_TData = any, _TVariables extends OperationVariables = any> extends useBackgroundQuery.Result<DataObject> {
|
|
195
|
+
client: ApolloClient;
|
|
163
196
|
networkStatus?: NetworkStatus;
|
|
164
197
|
called: boolean;
|
|
165
198
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cellTypes.d.ts","sourceRoot":"","sources":["../../../src/components/cell/cellTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"cellTypes.d.ts","sourceRoot":"","sources":["../../../src/components/cell/cellTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,OAAO,CAAA;AAEvE,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,kBAAkB,EA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,GAAG,IACT,OAAO,CACT,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,CAAC,CACvE,CAAA;AAID,MAAM,WAAW,uBAAuB,CACtC,MAAM,GAAG,GAAG,EACZ,WAAW,SAAS,kBAAkB,GAAG,GAAG,CAC5C,SAAQ,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC;IAC7C,MAAM,EAAE,YAAY,CAAA;IAEpB,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,MAAM,EAAE,OAAO,CAAA;CAChB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { OperationVariables } from '@apollo/client';
|
|
2
3
|
import type { CreateCellProps } from './cellTypes.js';
|
|
3
|
-
export declare function createCell<CellProps extends Record<string, unknown>, CellVariables extends
|
|
4
|
+
export declare function createCell<CellProps extends Record<string, unknown>, CellVariables extends OperationVariables = OperationVariables, GQLResult = any>(createCellProps: CreateCellProps<CellProps, CellVariables, GQLResult>): React.FC<CellProps>;
|
|
4
5
|
//# sourceMappingURL=createCell.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"createCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAQxD,OAAO,KAAK,EAAE,eAAe,EAAc,MAAM,gBAAgB,CAAA;AAKjE,wBAAgB,UAAU,CACxB,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,SAAS,kBAAkB,GAAG,kBAAkB,EAC7D,SAAS,GAAG,GAAG,EAEf,eAAe,EAAE,eAAe,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,GACpE,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAoCrB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { CombinedGraphQLErrors } from "@apollo/client";
|
|
3
|
+
import { useQuery } from "@apollo/client/react";
|
|
3
4
|
import { fragmentRegistry } from "../../apollo/fragmentRegistry.js";
|
|
4
5
|
import { getOperationName } from "../../graphql.js";
|
|
5
6
|
import { useCellCacheContext } from "./CellCacheContext.js";
|
|
@@ -15,7 +16,9 @@ function createCell(createCellProps) {
|
|
|
15
16
|
}
|
|
16
17
|
if (RWJS_ENV.RWJS_EXP_STREAMING_SSR) {
|
|
17
18
|
const suspendingCellProps = createCellProps;
|
|
18
|
-
return createSuspendingCell(
|
|
19
|
+
return createSuspendingCell(
|
|
20
|
+
suspendingCellProps
|
|
21
|
+
);
|
|
19
22
|
}
|
|
20
23
|
return createNonSuspendingCell(createCellProps);
|
|
21
24
|
}
|
|
@@ -50,7 +53,9 @@ function createNonSuspendingCell({
|
|
|
50
53
|
function NamedCell(props) {
|
|
51
54
|
const { children: _, ...variables } = props;
|
|
52
55
|
const options = beforeQuery(variables);
|
|
53
|
-
const
|
|
56
|
+
const queryOptions = typeof options === "symbol" ? void 0 : options;
|
|
57
|
+
const skipped = !queryOptions || queryOptions.skip === true;
|
|
58
|
+
const query = typeof cellQuery === "function" ? cellQuery(queryOptions ?? {}) : cellQuery;
|
|
54
59
|
let {
|
|
55
60
|
// eslint-disable-next-line prefer-const
|
|
56
61
|
error,
|
|
@@ -60,77 +65,77 @@ function createNonSuspendingCell({
|
|
|
60
65
|
} = useQuery(query, options);
|
|
61
66
|
if (globalThis.__REDWOOD__PRERENDERING) {
|
|
62
67
|
const { queryCache } = useCellCacheContext();
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const cellName = displayName === "Cell" ? "the cell" : displayName;
|
|
70
|
-
throw new Error(
|
|
71
|
-
`The gql query in ${cellName} is missing an operation name. Something like FindBlogPostQuery in \`query FindBlogPostQuery($id: Int!)\``
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
const queryInfo = queryCache[cacheKey];
|
|
75
|
-
if (queryInfo?.renderLoading) {
|
|
76
|
-
loading = true;
|
|
77
|
-
} else {
|
|
78
|
-
if (queryInfo?.hasProcessed) {
|
|
79
|
-
loading = false;
|
|
80
|
-
data = queryInfo.data;
|
|
81
|
-
queryResult = { variables };
|
|
68
|
+
if (!skipped) {
|
|
69
|
+
const operationName = getOperationName(query);
|
|
70
|
+
const transformedQuery = fragmentRegistry.transform(query);
|
|
71
|
+
let cacheKey;
|
|
72
|
+
if (operationName) {
|
|
73
|
+
cacheKey = operationName + "_" + JSON.stringify(variables);
|
|
82
74
|
} else {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
75
|
+
const cellName = displayName === "Cell" ? "the cell" : displayName;
|
|
76
|
+
throw new Error(
|
|
77
|
+
`The gql query in ${cellName} is missing an operation name. Something like FindBlogPostQuery in \`query FindBlogPostQuery($id: Int!)\``
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const queryInfo = queryCache[cacheKey];
|
|
81
|
+
if (queryInfo?.renderLoading) {
|
|
82
|
+
loading = true;
|
|
83
|
+
} else {
|
|
84
|
+
if (queryInfo?.hasProcessed) {
|
|
85
|
+
loading = false;
|
|
86
|
+
data = queryInfo.data;
|
|
87
|
+
queryResult = { variables };
|
|
88
|
+
} else {
|
|
89
|
+
queryCache[cacheKey] ||= {
|
|
90
|
+
query: transformedQuery,
|
|
91
|
+
variables: queryOptions.variables,
|
|
92
|
+
hasProcessed: false
|
|
93
|
+
};
|
|
94
|
+
}
|
|
88
95
|
}
|
|
89
96
|
}
|
|
90
97
|
}
|
|
98
|
+
if (skipped) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
91
101
|
if (error) {
|
|
92
102
|
if (Failure) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
errorCode:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
);
|
|
103
|
+
const failureProps = {
|
|
104
|
+
error,
|
|
105
|
+
errorCode: (
|
|
106
|
+
// Use the ad-hoc QueryResultWithErrorCode type to access the errorCode
|
|
107
|
+
queryResult.errorCode ?? (CombinedGraphQLErrors.is(error) ? error.errors[0]?.extensions?.["code"] : void 0)
|
|
108
|
+
),
|
|
109
|
+
...props,
|
|
110
|
+
updating: loading,
|
|
111
|
+
queryResult
|
|
112
|
+
};
|
|
113
|
+
return /* @__PURE__ */ React.createElement(Failure, { ...failureProps });
|
|
106
114
|
} else {
|
|
107
|
-
throw error;
|
|
115
|
+
throw error instanceof Error ? error : new Error(error.message);
|
|
108
116
|
}
|
|
109
117
|
} else if (data) {
|
|
110
118
|
const afterQueryData = afterQuery(data);
|
|
111
119
|
if (isEmpty(data, { isDataEmpty }) && Empty) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
);
|
|
120
|
+
const emptyProps = {
|
|
121
|
+
...props,
|
|
122
|
+
...afterQueryData,
|
|
123
|
+
updating: loading,
|
|
124
|
+
queryResult
|
|
125
|
+
};
|
|
126
|
+
return /* @__PURE__ */ React.createElement(Empty, { ...emptyProps });
|
|
121
127
|
} else {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
);
|
|
128
|
+
const successProps = {
|
|
129
|
+
...props,
|
|
130
|
+
...afterQueryData,
|
|
131
|
+
updating: loading,
|
|
132
|
+
queryResult
|
|
133
|
+
};
|
|
134
|
+
return /* @__PURE__ */ React.createElement(Success, { ...successProps });
|
|
131
135
|
}
|
|
132
136
|
} else if (loading) {
|
|
133
|
-
|
|
137
|
+
const loadingProps = { ...props, queryResult };
|
|
138
|
+
return /* @__PURE__ */ React.createElement(Loading, { ...loadingProps });
|
|
134
139
|
} else {
|
|
135
140
|
console.warn(
|
|
136
141
|
`If you're using Apollo Client, check for its debug logs here in the console, which may help explain the error.`
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { OperationVariables } from '@apollo/client';
|
|
2
3
|
import type { CreateCellProps } from './cellTypes.js';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a Cell out of a GraphQL fragment and components that render its
|
|
@@ -15,5 +16,5 @@ import type { CreateCellProps } from './cellTypes.js';
|
|
|
15
16
|
* mutations update the underlying entity. If the cache read is incomplete,
|
|
16
17
|
* the passed-in object itself is used as the data snapshot.
|
|
17
18
|
*/
|
|
18
|
-
export declare function createFragmentCell<CellProps extends Record<string, unknown>, CellVariables extends
|
|
19
|
+
export declare function createFragmentCell<CellProps extends Record<string, unknown>, CellVariables extends OperationVariables = OperationVariables, GQLResult = any>({ FRAGMENT, afterQuery, isEmpty, Empty, Success, displayName, }: CreateCellProps<CellProps, CellVariables, GQLResult>): React.FC<CellProps>;
|
|
19
20
|
//# sourceMappingURL=createFragmentCell.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFragmentCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createFragmentCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"createFragmentCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createFragmentCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAMxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAqDrD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,SAAS,kBAAkB,GAAG,kBAAkB,EAC7D,SAAS,GAAG,GAAG,EACf,EACA,QAAQ,EACR,UAA2B,EAC3B,OAAqB,EACrB,KAAK,EACL,OAAO,EACP,WAAoB,GACrB,EAAE,eAAe,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAiF5E"}
|
|
@@ -58,10 +58,12 @@ function createFragmentCell({
|
|
|
58
58
|
}
|
|
59
59
|
const data = fragmentResult.complete ? fragmentResult.data : dataRef ?? null;
|
|
60
60
|
const afterQueryData = afterQuery({ [propName]: data });
|
|
61
|
+
const restProps = rest;
|
|
62
|
+
const successProps = { ...restProps, ...afterQueryData };
|
|
61
63
|
if (isEmpty({ [propName]: data }, { isDataEmpty }) && Empty) {
|
|
62
|
-
return /* @__PURE__ */ React.createElement(Empty, { ...
|
|
64
|
+
return /* @__PURE__ */ React.createElement(Empty, { ...successProps });
|
|
63
65
|
}
|
|
64
|
-
return /* @__PURE__ */ React.createElement(Success, { ...
|
|
66
|
+
return /* @__PURE__ */ React.createElement(Success, { ...successProps });
|
|
65
67
|
}
|
|
66
68
|
NamedCell.displayName = displayName;
|
|
67
69
|
return (props) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { OperationVariables } from '@apollo/client';
|
|
2
3
|
import type { CreateCellProps } from './cellTypes.js';
|
|
3
|
-
type CreateServerCellProps<CellProps, CellVariables> = Omit<CreateCellProps<CellProps, CellVariables>, 'QUERY' | 'Failure'> & {
|
|
4
|
+
type CreateServerCellProps<CellProps, CellVariables extends OperationVariables = OperationVariables, GQLResult = any> = Omit<CreateCellProps<CellProps, CellVariables, GQLResult>, 'QUERY' | 'Failure'> & {
|
|
4
5
|
data: (variables?: AnyObj) => any;
|
|
5
6
|
Failure?: React.ComponentType<{
|
|
6
7
|
error: unknown;
|
|
@@ -10,6 +11,6 @@ type CreateServerCellProps<CellProps, CellVariables> = Omit<CreateCellProps<Cell
|
|
|
10
11
|
}>;
|
|
11
12
|
};
|
|
12
13
|
type AnyObj = Record<string, unknown>;
|
|
13
|
-
export declare function createServerCell<CellProps extends AnyObj, CellVariables extends
|
|
14
|
+
export declare function createServerCell<CellProps extends AnyObj, CellVariables extends OperationVariables = OperationVariables, GQLResult = any>(createCellProps: CreateServerCellProps<CellProps, CellVariables, GQLResult>): React.FC<CellProps>;
|
|
14
15
|
export {};
|
|
15
16
|
//# sourceMappingURL=createServerCell.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createServerCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createServerCell.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"createServerCell.d.ts","sourceRoot":"","sources":["../../../src/components/cell/createServerCell.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAMxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAIrD,KAAK,qBAAqB,CACxB,SAAS,EACT,aAAa,SAAS,kBAAkB,GAAG,kBAAkB,EAC7D,SAAS,GAAG,GAAG,IACb,IAAI,CACN,eAAe,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,EACpD,OAAO,GAAG,SAAS,CACpB,GAAG;IACF,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,MAAM,KAAK,GAAG,CAAA;IACjC,OAAO,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;QAC5B,KAAK,EAAE,OAAO,CAAA;QACd,WAAW,EAAE;YAAE,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,MAAM,CAAA;SAAE,CAAA;KAC3D,CAAC,CAAA;CACH,CAAA;AAED,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAErC,wBAAgB,gBAAgB,CAC9B,SAAS,SAAS,MAAM,EACxB,aAAa,SAAS,kBAAkB,GAAG,kBAAkB,EAC7D,SAAS,GAAG,GAAG,EAEf,eAAe,EAAE,qBAAqB,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC,GAC1E,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAuFrB"}
|