@capacms/sdk 1.0.0-next.4 → 1.0.0-next.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/CHANGELOG.md +345 -0
- package/README.md +1069 -186
- package/bin/capa-codegen.js +192 -5
- package/bin/capa.js +208 -0
- package/bin/graphql-project.js +142 -0
- package/bin/project-env.js +58 -0
- package/dist/client.d.ts +5 -0
- package/dist/client.js +17 -0
- package/dist/codegen.d.ts +55 -0
- package/dist/codegen.js +320 -39
- package/dist/config.d.ts +5 -36
- package/dist/config.js +47 -1
- package/dist/graphql-codegen.d.ts +117 -0
- package/dist/graphql-codegen.js +705 -0
- package/dist/http.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/next/attrs.d.ts +51 -12
- package/dist/next/attrs.js +74 -20
- package/dist/next/client.d.ts +112 -38
- package/dist/next/client.js +131 -83
- package/dist/next/entry-fields.d.ts +162 -0
- package/dist/next/entry-fields.js +2 -0
- package/dist/next/errors.d.ts +136 -0
- package/dist/next/errors.js +214 -0
- package/dist/next/field-names.d.ts +37 -0
- package/dist/next/field-names.js +145 -0
- package/dist/next/graphql/build.d.ts +27 -0
- package/dist/next/graphql/build.js +98 -0
- package/dist/next/graphql/documents.d.ts +67 -0
- package/dist/next/graphql/documents.js +35 -0
- package/dist/next/graphql/edit-mode.d.ts +16 -0
- package/dist/next/graphql/edit-mode.js +93 -0
- package/dist/next/graphql/filter-values.d.ts +34 -0
- package/dist/next/graphql/filter-values.js +96 -0
- package/dist/next/graphql/introspection.d.ts +89 -0
- package/dist/next/graphql/introspection.js +102 -0
- package/dist/next/graphql/plan.d.ts +115 -0
- package/dist/next/graphql/plan.js +531 -0
- package/dist/next/graphql/request.d.ts +228 -0
- package/dist/next/graphql/request.js +283 -0
- package/dist/next/graphql/rest.d.ts +66 -0
- package/dist/next/graphql/rest.js +502 -0
- package/dist/next/graphql/selection.d.ts +55 -0
- package/dist/next/graphql/selection.js +212 -0
- package/dist/next/graphql/sha256.d.ts +13 -0
- package/dist/next/graphql/sha256.js +86 -0
- package/dist/next/graphql/summary.d.ts +83 -0
- package/dist/next/graphql/summary.js +151 -0
- package/dist/next/graphql/tree-layout.d.ts +36 -0
- package/dist/next/graphql/tree-layout.js +20 -0
- package/dist/next/graphql/tree.d.ts +171 -0
- package/dist/next/graphql/tree.js +249 -0
- package/dist/next/graphql/typed.d.ts +261 -0
- package/dist/next/graphql/typed.js +146 -0
- package/dist/next/index.d.ts +28 -5
- package/dist/next/index.js +25 -1
- package/dist/next/inflate.d.ts +25 -7
- package/dist/next/inflate.js +46 -32
- package/dist/next/key-family.d.ts +34 -0
- package/dist/next/key-family.js +74 -0
- package/dist/next/select-types.d.ts +44 -8
- package/dist/next/system-keys.d.ts +27 -0
- package/dist/next/system-keys.js +42 -0
- package/dist/nextjs/index.d.ts +174 -12
- package/dist/nextjs/index.js +270 -23
- package/dist/nextjs/overlay.d.ts +5 -0
- package/dist/nextjs/overlay.js +35 -0
- package/package.json +31 -13
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* graphql-codegen.ts — `capa-codegen --graphql` and `capa persist`, the pure half.
|
|
3
|
+
*
|
|
4
|
+
* Reads a key's schema (introspection JSON) and a project's GraphQL documents,
|
|
5
|
+
* validates every document against that schema, and writes ONE TypeScript
|
|
6
|
+
* module holding:
|
|
7
|
+
*
|
|
8
|
+
* - the schema as types, for `createClient<CapaQuery>()` and the typed
|
|
9
|
+
* builder (`client.graphql.query`);
|
|
10
|
+
* - one `TypedDocument` constant per named operation, so
|
|
11
|
+
* `client.graphql(ArticlesPageDocument, vars)` infers the result and the
|
|
12
|
+
* variables with no cast, and beside it `<Name>Models`, the models it
|
|
13
|
+
* reads, for its Next.js cache tags;
|
|
14
|
+
* - for each document written as a literal (`#graphql`, `/* capa *\/` or
|
|
15
|
+
* gql(`...`)), an entry in `CapaDocuments` keyed by its exact text, so
|
|
16
|
+
* `client.graphql(LITERAL, vars)` infers them too, with no import;
|
|
17
|
+
* - `capaTreeLayout`, what `toTree` reads of the schema, so a server lays a
|
|
18
|
+
* builder result out in REST's shape without reading the schema first.
|
|
19
|
+
*
|
|
20
|
+
* The file walk and the network live in `bin/`; everything here is a function
|
|
21
|
+
* of its inputs, so it is tested without either.
|
|
22
|
+
*
|
|
23
|
+
* `graphql` (graphql-js) is loaded on first use, never at import: it is an
|
|
24
|
+
* optional peer dependency that only these commands need, and a site that
|
|
25
|
+
* only calls `client.graphql()` must not pay for it.
|
|
26
|
+
*/
|
|
27
|
+
import type * as GraphQLJs from "graphql";
|
|
28
|
+
import type { CapaIntrospection } from "./next/graphql/introspection";
|
|
29
|
+
/** graphql-js, or an error that says how to get it. */
|
|
30
|
+
export declare function loadGraphQL(): typeof GraphQLJs;
|
|
31
|
+
/** One GraphQL document found in a project, with where it came from. */
|
|
32
|
+
export interface DocumentSource {
|
|
33
|
+
file: string;
|
|
34
|
+
/** 1-based line of the document's first character in `file`. */
|
|
35
|
+
line: number;
|
|
36
|
+
/** The document's text as the program holds it at run time: a template's escapes are applied. */
|
|
37
|
+
text: string;
|
|
38
|
+
/**
|
|
39
|
+
* True for a literal whose type is its text (`#graphql`, `/* capa *\/`,
|
|
40
|
+
* gql(`...`)): it is sent exactly as written, and codegen keys its types by
|
|
41
|
+
* that text.
|
|
42
|
+
*/
|
|
43
|
+
literal?: true;
|
|
44
|
+
/** The variable a literal is assigned to (`const CARD = ...`), which another literal's `${CARD}` names. */
|
|
45
|
+
name?: string;
|
|
46
|
+
/**
|
|
47
|
+
* For a literal with `${NAME}` in it: the text around each `${}` and the
|
|
48
|
+
* names in them, resolved against the project's other literals before the
|
|
49
|
+
* literal is read. `text` holds the template with its `${NAME}`s meanwhile.
|
|
50
|
+
*/
|
|
51
|
+
template?: {
|
|
52
|
+
segments: string[];
|
|
53
|
+
names: string[];
|
|
54
|
+
asConst: boolean;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** A template codegen does not read, and why: the CLI prints each one, so none is dropped in silence. */
|
|
58
|
+
export interface SkippedDocument extends DocumentSource {
|
|
59
|
+
reason: string;
|
|
60
|
+
}
|
|
61
|
+
/** A template's text at run time, from its source text: line ends as LF, escapes applied. */
|
|
62
|
+
export declare function cookTemplate(raw: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* The GraphQL documents in one file: the whole file for `.graphql` and `.gql`,
|
|
65
|
+
* and elsewhere every template that is marked as one: a `#graphql` first
|
|
66
|
+
* line, a `/* capa *\/` comment before it, or `gql` as a tag or a function.
|
|
67
|
+
* One on a comment line is an example, not a document.
|
|
68
|
+
*
|
|
69
|
+
* `skipped` names every template codegen will not read that looks meant for
|
|
70
|
+
* it, with the reason: one with `${}` inside (its text is only known at run
|
|
71
|
+
* time, so it cannot be validated or hashed ahead of it), a named operation
|
|
72
|
+
* left unmarked, and `/nextjs`'s `graphql` used as a tag.
|
|
73
|
+
*/
|
|
74
|
+
export declare function extractDocuments(file: string, text: string): {
|
|
75
|
+
documents: DocumentSource[];
|
|
76
|
+
skipped: SkippedDocument[];
|
|
77
|
+
};
|
|
78
|
+
export interface CodegenProblem {
|
|
79
|
+
file: string;
|
|
80
|
+
line: number;
|
|
81
|
+
column: number;
|
|
82
|
+
message: string;
|
|
83
|
+
}
|
|
84
|
+
export interface GeneratedOperation {
|
|
85
|
+
name: string;
|
|
86
|
+
/** The exact text of its `<Name>Document`, and hashed for persisted queries. */
|
|
87
|
+
document: string;
|
|
88
|
+
sha256: string;
|
|
89
|
+
/** The namespaces of the models it reads, written as `<Name>Models` for its cache tags. */
|
|
90
|
+
models: string[];
|
|
91
|
+
/** For a document written as a literal: the literal's text, which is what a call with it sends, and its hash. */
|
|
92
|
+
literal?: {
|
|
93
|
+
document: string;
|
|
94
|
+
sha256: string;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
export interface GraphQLCodegenResult {
|
|
98
|
+
/** The module to write. Null when a document failed. */
|
|
99
|
+
source: string | null;
|
|
100
|
+
operations: GeneratedOperation[];
|
|
101
|
+
problems: CodegenProblem[];
|
|
102
|
+
/**
|
|
103
|
+
* Each use of a deprecated field, argument, input field or enum value, with
|
|
104
|
+
* the reason the schema gives: it still works, and a later Capa-Version
|
|
105
|
+
* removes it.
|
|
106
|
+
*/
|
|
107
|
+
warnings: CodegenProblem[];
|
|
108
|
+
/** Literals with a `${}` that names no literal of the project, so their text is only known at run time. */
|
|
109
|
+
skipped: SkippedDocument[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The generated module for a schema and a project's documents. Problems (a
|
|
113
|
+
* syntax error, a field the key cannot read, an unnamed operation, a name used
|
|
114
|
+
* twice) are returned with their file and line, and no module is produced
|
|
115
|
+
* while any remain.
|
|
116
|
+
*/
|
|
117
|
+
export declare function generateGraphQLModule(introspection: CapaIntrospection, sources: DocumentSource[]): GraphQLCodegenResult;
|