@capacms/sdk 1.0.0-next.1 → 1.0.0-next.11
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 +487 -0
- package/README.md +1810 -183
- package/bin/capa-codegen.js +192 -5
- package/bin/capa.js +235 -0
- package/bin/graphql-project.js +142 -0
- package/bin/project-env.js +58 -0
- package/dist/client.d.ts +89 -4
- package/dist/client.js +40 -5
- 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/esm/image/index.d.ts +187 -0
- package/dist/esm/image/index.js +353 -0
- package/dist/esm/image/shared-params.generated.d.ts +314 -0
- package/dist/esm/image/shared-params.generated.js +680 -0
- package/dist/esm/nextjs/image-loader.d.ts +60 -0
- package/dist/esm/nextjs/image-loader.js +67 -0
- package/dist/esm/nextjs/overlay.d.ts +30 -0
- package/dist/esm/nextjs/overlay.js +75 -0
- package/dist/esm/overlay/index.d.ts +32 -0
- package/dist/esm/overlay/index.js +576 -0
- package/dist/esm/overlay/protocol.d.ts +187 -0
- package/dist/esm/overlay/protocol.js +240 -0
- package/dist/esm/package.json +4 -0
- package/dist/graphql-codegen.d.ts +117 -0
- package/dist/graphql-codegen.js +705 -0
- package/dist/http.js +1 -1
- package/dist/image/index.d.ts +187 -0
- package/dist/image/index.js +362 -0
- package/dist/image/shared-params.generated.d.ts +314 -0
- package/dist/image/shared-params.generated.js +700 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/next/attrs.d.ts +84 -10
- package/dist/next/attrs.js +119 -2
- package/dist/next/client.d.ts +176 -32
- package/dist/next/client.js +212 -90
- package/dist/next/entry-fields.d.ts +203 -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 +258 -0
- package/dist/next/graphql/typed.d.ts +261 -0
- package/dist/next/graphql/typed.js +146 -0
- package/dist/next/index.d.ts +30 -5
- package/dist/next/index.js +32 -1
- package/dist/next/inflate.d.ts +51 -0
- package/dist/next/inflate.js +243 -0
- package/dist/next/key-family.d.ts +31 -0
- package/dist/next/key-family.js +66 -0
- package/dist/next/select-types.d.ts +58 -5
- package/dist/next/system-keys.d.ts +27 -0
- package/dist/next/system-keys.js +42 -0
- package/dist/nextjs/image-loader.d.ts +60 -0
- package/dist/nextjs/image-loader.js +71 -0
- package/dist/nextjs/index.d.ts +484 -5
- package/dist/nextjs/index.js +688 -6
- package/dist/nextjs/overlay.d.ts +30 -0
- package/dist/nextjs/overlay.js +78 -0
- package/dist/overlay/index.d.ts +14 -2
- package/dist/overlay/index.js +282 -43
- package/dist/overlay/protocol.d.ts +98 -2
- package/dist/overlay/protocol.js +151 -4
- package/dist/webhooks.d.ts +8 -0
- package/package.json +63 -15
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* introspection.ts — the introspection query this package sends, and the part
|
|
3
|
+
* of the answer it reads.
|
|
4
|
+
*
|
|
5
|
+
* One request carries both the standard introspection selection and the
|
|
6
|
+
* `version` root field, so a schema summary always says which platform version
|
|
7
|
+
* it describes. Kept byte-stable: `@capacms/mcp` sends the same text, and a
|
|
8
|
+
* persisted copy of it is one hash for every client.
|
|
9
|
+
*
|
|
10
|
+
* Deprecated arguments and input fields are asked for too, with their
|
|
11
|
+
* reasons: graphql-js leaves them out otherwise, and a document using one
|
|
12
|
+
* would then fail codegen as unknown the day Capa deprecates it, long before
|
|
13
|
+
* a later Capa-Version removes it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const INTROSPECTION_QUERY = "query CapaIntrospection {\n version\n __schema {\n queryType { name }\n types { ...FullType }\n }\n}\n\nfragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args(includeDeprecated: true) { ...InputValue }\n type { ...TypeRef }\n isDeprecated\n deprecationReason\n }\n inputFields(includeDeprecated: true) { ...InputValue }\n interfaces { ...TypeRef }\n enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason }\n possibleTypes { ...TypeRef }\n}\n\nfragment InputValue on __InputValue {\n name\n description\n type { ...TypeRef }\n defaultValue\n isDeprecated\n deprecationReason\n}\n\nfragment TypeRef on __Type {\n kind\n name\n ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } }\n}";
|
|
16
|
+
/**
|
|
17
|
+
* The part of the schema edit mode reads (`edit-mode.ts`): each type's name
|
|
18
|
+
* and description, and each field's name and description, which is all that
|
|
19
|
+
* says which GraphQL name is which Capa namespace (N9), and none of the
|
|
20
|
+
* arguments, input types and enum values that make up most of
|
|
21
|
+
* `INTROSPECTION_QUERY`'s answer. It selects the schema and nothing else, so
|
|
22
|
+
* the API answers a repeat from its memo of that answer.
|
|
23
|
+
*/
|
|
24
|
+
export declare const FIELD_NAMES_QUERY = "query CapaFieldNames {\n __schema {\n types {\n kind\n name\n description\n fields(includeDeprecated: true) { name description }\n }\n }\n}";
|
|
25
|
+
/** `data` of a `CapaFieldNames` response. */
|
|
26
|
+
export interface CapaFieldNames {
|
|
27
|
+
__schema: {
|
|
28
|
+
types: Array<{
|
|
29
|
+
kind: string;
|
|
30
|
+
name: string;
|
|
31
|
+
description?: string | null;
|
|
32
|
+
fields?: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
description?: string | null;
|
|
35
|
+
}> | null;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface IntrospectionTypeRef {
|
|
40
|
+
kind: string;
|
|
41
|
+
name: string | null;
|
|
42
|
+
ofType?: IntrospectionTypeRef | null;
|
|
43
|
+
}
|
|
44
|
+
export interface IntrospectionInputValue {
|
|
45
|
+
name: string;
|
|
46
|
+
description?: string | null;
|
|
47
|
+
type: IntrospectionTypeRef;
|
|
48
|
+
defaultValue?: string | null;
|
|
49
|
+
isDeprecated?: boolean;
|
|
50
|
+
deprecationReason?: string | null;
|
|
51
|
+
}
|
|
52
|
+
export interface IntrospectionField {
|
|
53
|
+
name: string;
|
|
54
|
+
description?: string | null;
|
|
55
|
+
args: IntrospectionInputValue[];
|
|
56
|
+
type: IntrospectionTypeRef;
|
|
57
|
+
isDeprecated?: boolean;
|
|
58
|
+
deprecationReason?: string | null;
|
|
59
|
+
}
|
|
60
|
+
export interface IntrospectionType {
|
|
61
|
+
kind: string;
|
|
62
|
+
name: string;
|
|
63
|
+
description?: string | null;
|
|
64
|
+
fields?: IntrospectionField[] | null;
|
|
65
|
+
inputFields?: IntrospectionInputValue[] | null;
|
|
66
|
+
enumValues?: Array<{
|
|
67
|
+
name: string;
|
|
68
|
+
description?: string | null;
|
|
69
|
+
isDeprecated?: boolean;
|
|
70
|
+
deprecationReason?: string | null;
|
|
71
|
+
}> | null;
|
|
72
|
+
interfaces?: IntrospectionTypeRef[] | null;
|
|
73
|
+
possibleTypes?: IntrospectionTypeRef[] | null;
|
|
74
|
+
}
|
|
75
|
+
/** `data` of a `CapaIntrospection` response. */
|
|
76
|
+
export interface CapaIntrospection {
|
|
77
|
+
version?: string;
|
|
78
|
+
__schema: {
|
|
79
|
+
queryType: {
|
|
80
|
+
name: string;
|
|
81
|
+
};
|
|
82
|
+
types: IntrospectionType[];
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** The named type under any `NON_NULL` and `LIST` wrappers. */
|
|
86
|
+
export declare function namedType(ref: IntrospectionTypeRef): string;
|
|
87
|
+
/** The type as SDL writes it: `[Authors!]!`. */
|
|
88
|
+
export declare function printTypeRef(ref: IntrospectionTypeRef): string;
|
|
89
|
+
export declare function isListType(ref: IntrospectionTypeRef): boolean;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* introspection.ts — the introspection query this package sends, and the part
|
|
4
|
+
* of the answer it reads.
|
|
5
|
+
*
|
|
6
|
+
* One request carries both the standard introspection selection and the
|
|
7
|
+
* `version` root field, so a schema summary always says which platform version
|
|
8
|
+
* it describes. Kept byte-stable: `@capacms/mcp` sends the same text, and a
|
|
9
|
+
* persisted copy of it is one hash for every client.
|
|
10
|
+
*
|
|
11
|
+
* Deprecated arguments and input fields are asked for too, with their
|
|
12
|
+
* reasons: graphql-js leaves them out otherwise, and a document using one
|
|
13
|
+
* would then fail codegen as unknown the day Capa deprecates it, long before
|
|
14
|
+
* a later Capa-Version removes it.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.FIELD_NAMES_QUERY = exports.INTROSPECTION_QUERY = void 0;
|
|
18
|
+
exports.namedType = namedType;
|
|
19
|
+
exports.printTypeRef = printTypeRef;
|
|
20
|
+
exports.isListType = isListType;
|
|
21
|
+
exports.INTROSPECTION_QUERY = `query CapaIntrospection {
|
|
22
|
+
version
|
|
23
|
+
__schema {
|
|
24
|
+
queryType { name }
|
|
25
|
+
types { ...FullType }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
fragment FullType on __Type {
|
|
30
|
+
kind
|
|
31
|
+
name
|
|
32
|
+
description
|
|
33
|
+
fields(includeDeprecated: true) {
|
|
34
|
+
name
|
|
35
|
+
description
|
|
36
|
+
args(includeDeprecated: true) { ...InputValue }
|
|
37
|
+
type { ...TypeRef }
|
|
38
|
+
isDeprecated
|
|
39
|
+
deprecationReason
|
|
40
|
+
}
|
|
41
|
+
inputFields(includeDeprecated: true) { ...InputValue }
|
|
42
|
+
interfaces { ...TypeRef }
|
|
43
|
+
enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason }
|
|
44
|
+
possibleTypes { ...TypeRef }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fragment InputValue on __InputValue {
|
|
48
|
+
name
|
|
49
|
+
description
|
|
50
|
+
type { ...TypeRef }
|
|
51
|
+
defaultValue
|
|
52
|
+
isDeprecated
|
|
53
|
+
deprecationReason
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fragment TypeRef on __Type {
|
|
57
|
+
kind
|
|
58
|
+
name
|
|
59
|
+
ofType { kind name ofType { kind name ofType { kind name ofType { kind name } } } }
|
|
60
|
+
}`;
|
|
61
|
+
/**
|
|
62
|
+
* The part of the schema edit mode reads (`edit-mode.ts`): each type's name
|
|
63
|
+
* and description, and each field's name and description, which is all that
|
|
64
|
+
* says which GraphQL name is which Capa namespace (N9), and none of the
|
|
65
|
+
* arguments, input types and enum values that make up most of
|
|
66
|
+
* `INTROSPECTION_QUERY`'s answer. It selects the schema and nothing else, so
|
|
67
|
+
* the API answers a repeat from its memo of that answer.
|
|
68
|
+
*/
|
|
69
|
+
exports.FIELD_NAMES_QUERY = `query CapaFieldNames {
|
|
70
|
+
__schema {
|
|
71
|
+
types {
|
|
72
|
+
kind
|
|
73
|
+
name
|
|
74
|
+
description
|
|
75
|
+
fields(includeDeprecated: true) { name description }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}`;
|
|
79
|
+
/** The named type under any `NON_NULL` and `LIST` wrappers. */
|
|
80
|
+
function namedType(ref) {
|
|
81
|
+
let current = ref;
|
|
82
|
+
while (current && current.name === null)
|
|
83
|
+
current = current.ofType;
|
|
84
|
+
return current?.name ?? "";
|
|
85
|
+
}
|
|
86
|
+
/** The type as SDL writes it: `[Authors!]!`. */
|
|
87
|
+
function printTypeRef(ref) {
|
|
88
|
+
if (ref.kind === "NON_NULL" && ref.ofType)
|
|
89
|
+
return `${printTypeRef(ref.ofType)}!`;
|
|
90
|
+
if (ref.kind === "LIST" && ref.ofType)
|
|
91
|
+
return `[${printTypeRef(ref.ofType)}]`;
|
|
92
|
+
return ref.name ?? "";
|
|
93
|
+
}
|
|
94
|
+
function isListType(ref) {
|
|
95
|
+
let current = ref;
|
|
96
|
+
while (current) {
|
|
97
|
+
if (current.kind === "LIST")
|
|
98
|
+
return true;
|
|
99
|
+
current = current.ofType;
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type GraphQLFieldSummary, type GraphQLModelSummary, type GraphQLSchemaSummary } from "./summary";
|
|
2
|
+
/** One selected field: a name, or a relation or media field with its own fields. */
|
|
3
|
+
/**
|
|
4
|
+
* A relation list's sort: one value of the target's sort enum, e.g.
|
|
5
|
+
* `name_ASC`, or a list of that one value, the root's shape.
|
|
6
|
+
*/
|
|
7
|
+
export type GraphQLFieldSpecSort = string | readonly [string];
|
|
8
|
+
export type GraphQLFieldSpec = string | {
|
|
9
|
+
field: string;
|
|
10
|
+
fields?: GraphQLFieldSpec[];
|
|
11
|
+
/** Array relations only: how many related entries, 1 to 200 (default 100). */
|
|
12
|
+
first?: number;
|
|
13
|
+
/** Array relations only: see `GraphQLFieldSpecSort`. */
|
|
14
|
+
sort?: GraphQLFieldSpecSort;
|
|
15
|
+
/**
|
|
16
|
+
* Array relations in a read of one entry only: the list's `endCursor`,
|
|
17
|
+
* to read on after it. A cursor names one entry's list, so a list read
|
|
18
|
+
* refuses it, as the API does.
|
|
19
|
+
*/
|
|
20
|
+
after?: string;
|
|
21
|
+
};
|
|
22
|
+
export interface GraphQLQuerySpec {
|
|
23
|
+
/** Namespace (`articles`) or GraphQL type name (`Articles`). */
|
|
24
|
+
model: string;
|
|
25
|
+
/** `list`, or `single`, which needs `id`. The default is `single` when `id` is given, else `list`. */
|
|
26
|
+
mode?: "list" | "single";
|
|
27
|
+
/** The entry's UUID: reads that one entry. Refused beside `mode: "list"`. */
|
|
28
|
+
id?: string;
|
|
29
|
+
/** Omit for every non-relation field, single relations as `{ id }`, media as `{ id url alt }`. */
|
|
30
|
+
fields?: GraphQLFieldSpec[];
|
|
31
|
+
/**
|
|
32
|
+
* How many entries, 1 to 200 (default 25), as REST's `limit`. Beside
|
|
33
|
+
* `before` they are the entries just before that cursor, which GraphQL
|
|
34
|
+
* writes as `last`, so the query sends `last`.
|
|
35
|
+
*/
|
|
36
|
+
first?: number;
|
|
37
|
+
/** An `endCursor`: the page after it. */
|
|
38
|
+
after?: string;
|
|
39
|
+
/**
|
|
40
|
+
* A `startCursor` to page back from: the `first` entries just before it.
|
|
41
|
+
* Or `"end"`, REST's `before=end`: the last `first` entries of the list,
|
|
42
|
+
* which GraphQL reads as `last` with no `before` (spec 17, amendment 132).
|
|
43
|
+
*/
|
|
44
|
+
before?: string;
|
|
45
|
+
/** Up to 3 values of the model's sort enum, e.g. `["views_DESC"]`, or one alone, `"views_DESC"`. */
|
|
46
|
+
sort?: string | readonly string[];
|
|
47
|
+
/**
|
|
48
|
+
* The model's filter input, e.g. `{ views: { gte: 10 } }`. Each value is sent
|
|
49
|
+
* as the type the input declares: `{ views: { gte: "10" } }` goes as `10`,
|
|
50
|
+
* and `{ a_bool: { has: "true" } }` on a list of true/false values as `true`,
|
|
51
|
+
* which its `BooleanListFilter` takes.
|
|
52
|
+
*/
|
|
53
|
+
filter?: Record<string, unknown>;
|
|
54
|
+
totalCount?: boolean;
|
|
55
|
+
operationName?: string;
|
|
56
|
+
}
|
|
57
|
+
/** REST's `before=end`: the last entries of the list, read back from its end (spec 17, amendment 132). */
|
|
58
|
+
export declare const END_OF_LIST = "end";
|
|
59
|
+
/** REST's and GraphQL's root page size when none is given. */
|
|
60
|
+
export declare const LIST_DEFAULT = 25;
|
|
61
|
+
export declare class CapaBuildError extends Error {
|
|
62
|
+
/** The closest real names, nearest first. */
|
|
63
|
+
readonly didYouMean: string[];
|
|
64
|
+
/** Every name that would have been accepted. */
|
|
65
|
+
readonly available: string[];
|
|
66
|
+
constructor(message: string, didYouMean?: string[], available?: string[]);
|
|
67
|
+
}
|
|
68
|
+
/** The system fields every model type has (N6), in schema order. */
|
|
69
|
+
export declare const SYSTEM_FIELDS: readonly ["id", "model", "status", "createdAt", "updatedAt", "publishedAt", "_version", "_tags", "_folder"];
|
|
70
|
+
export declare const MEDIA_FIELDS: readonly ["id", "url", "alt", "type", "width", "height"];
|
|
71
|
+
/**
|
|
72
|
+
* Relations a query may nest below its root entry. The API reads 5 levels of
|
|
73
|
+
* entries per root field and counts the root's own as the first, so 4
|
|
74
|
+
* relations below it (spec 17, amendment 78).
|
|
75
|
+
*/
|
|
76
|
+
export declare const MAX_RELATION_DEPTH = 4;
|
|
77
|
+
export interface PlannedField {
|
|
78
|
+
/** GraphQL name. */
|
|
79
|
+
name: string;
|
|
80
|
+
/** The customer field, or null for a system field or a media subfield. */
|
|
81
|
+
field: GraphQLFieldSummary | null;
|
|
82
|
+
/** Relation, relation list and media fields carry what they select. */
|
|
83
|
+
children?: PlannedField[];
|
|
84
|
+
/** The target model of an expanded relation. */
|
|
85
|
+
target?: GraphQLModelSummary;
|
|
86
|
+
first?: number;
|
|
87
|
+
sort?: string;
|
|
88
|
+
after?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface PlannedQuery {
|
|
91
|
+
model: GraphQLModelSummary;
|
|
92
|
+
mode: "list" | "single";
|
|
93
|
+
id?: string;
|
|
94
|
+
fields: PlannedField[];
|
|
95
|
+
first?: number;
|
|
96
|
+
after?: string;
|
|
97
|
+
before?: string;
|
|
98
|
+
sort?: string[];
|
|
99
|
+
filter?: Record<string, unknown>;
|
|
100
|
+
totalCount: boolean;
|
|
101
|
+
operationName: string;
|
|
102
|
+
summary: GraphQLSchemaSummary;
|
|
103
|
+
}
|
|
104
|
+
/** Names within two edits of `wanted`, nearest first then by name, at most three. */
|
|
105
|
+
export declare function didYouMean(wanted: string, candidates: readonly string[]): string[];
|
|
106
|
+
/**
|
|
107
|
+
* A model by namespace or type name, then by any of those or its display name
|
|
108
|
+
* ignoring case (`Writers`, `scalar specimens`). An unknown name is refused
|
|
109
|
+
* with the nearest models, each by namespace, whichever of its names was near.
|
|
110
|
+
*/
|
|
111
|
+
export declare function findModel(summary: GraphQLSchemaSummary, wanted: string): GraphQLModelSummary;
|
|
112
|
+
/** Whether `key` under `field`'s filter is a hop into a field of the related model rather than an operator. */
|
|
113
|
+
export declare function isHop(field: GraphQLFieldSummary, key: string): boolean;
|
|
114
|
+
/** Resolve and check a spec. Throws `CapaBuildError`. */
|
|
115
|
+
export declare function planQuery(summary: GraphQLSchemaSummary, spec: GraphQLQuerySpec): PlannedQuery;
|