@tinacms/graphql 0.56.1 → 0.57.0-hotfix

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.
@@ -1,26 +1,21 @@
1
1
  /**
2
+
2
3
  Copyright 2021 Forestry.io Holdings, Inc.
4
+
3
5
  Licensed under the Apache License, Version 2.0 (the "License");
4
6
  you may not use this file except in compliance with the License.
5
7
  You may obtain a copy of the License at
8
+
6
9
  http://www.apache.org/licenses/LICENSE-2.0
10
+
7
11
  Unless required by applicable law or agreed to in writing, software
8
12
  distributed under the License is distributed on an "AS IS" BASIS,
9
13
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
14
  See the License for the specific language governing permissions and
11
15
  limitations under the License.
16
+
12
17
  */
13
- export declare const clearCache: ({ owner, repo, ref, path, }: {
14
- owner: string;
15
- repo: string;
16
- ref: string;
17
- path?: string;
18
- }) => void;
19
- /**
20
- * This is just an example of what you can provide for caching
21
- * it should be replaced with a scalable solution which shares a cache
22
- * across lambda instances (like redis)
23
- */
24
- export declare const simpleCache: {
25
- get: (keyName: string, setter: () => Promise<any>) => Promise<any>;
26
- };
18
+ import { parseMDX } from './parse';
19
+ import { stringifyMDX } from './stringify';
20
+ export { parseMDX };
21
+ export { stringifyMDX };
@@ -0,0 +1,229 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type { Content } from 'mdast';
19
+ import type { RichTypeInner } from '../types';
20
+ export declare const parseMDX: (value: string, field: RichTypeInner) => {
21
+ type: string;
22
+ children: any;
23
+ };
24
+ /**
25
+ * ### Convert the MDXAST into an API-friendly format
26
+ *
27
+ * When we parse with Remark + MDX we get an AST which has a ton of JS capabilities, meaning
28
+ * we could pass this back into a JS runtime and evaluate it. Ex.
29
+ *
30
+ * ```mdx
31
+ * ## Hello world! The time and date is: {(new Date().toLocaleString())}
32
+ * ```
33
+ *
34
+ * However, as an intentional constraint we don't want this information as part of our API, as
35
+ * we don't intend to support the true JS runtime properties of MDX. Rather, we're using MDX for
36
+ * it's expressive syntax and it's advanced tooling with how it parses JSX inside Markdown.
37
+ *
38
+ * Parsing here does 2 things:
39
+ *
40
+ * #### Remove non-literal uses of JSX
41
+ * Things like <MyComponent myProp={() => alert("HI")} /> are not supported and will be ignored
42
+ *
43
+ * #### Convert remark nodes to slate-compatible nodes
44
+ *
45
+ * A remark node might look like this:
46
+ * ```js
47
+ * {
48
+ * type: "heading",
49
+ * depth: 1
50
+ * children: [{type: 'text', value: 'Hello'}]
51
+ * }
52
+ * ```
53
+ * A slate-compatible node would be:
54
+ * ```js
55
+ * {
56
+ * type: "heading_one",
57
+ * children: [{type: 'text', text: 'Hello'}]
58
+ * }
59
+ * ```
60
+ * It's not a huge difference, but in general slate does better with less layers of indirection.
61
+ *
62
+ * While it may be desirable to ultimately serve a remark AST shape as part of the API response,
63
+ * it's currently much easier to only support the shape that works with Slate. This is ok for now for 2
64
+ * reasons.
65
+ *
66
+ * 1. Us providing the `TinaMarkdown` component on the frontend abstracts away an work the developer
67
+ * would need to do, so it doesn't really matter what shape the response is as long as the external API
68
+ * doesn't change
69
+ *
70
+ * 2. We don't need to do any client-side parsing. Since TinaMarkdown and the slate editor work with the same
71
+ * format we can just allow Tina to do it's thing and update the form valuse with no additional work.
72
+ */
73
+ export declare const parseMDXInner: (tree: any, field: RichTypeInner) => {
74
+ type: string;
75
+ children: any;
76
+ };
77
+ export interface NodeTypes {
78
+ paragraph: string;
79
+ block_quote: string;
80
+ code_block: string;
81
+ link: string;
82
+ image: string;
83
+ ul_list: string;
84
+ ol_list: string;
85
+ listItem: string;
86
+ heading: {
87
+ 1: string;
88
+ 2: string;
89
+ 3: string;
90
+ 4: string;
91
+ 5: string;
92
+ 6: string;
93
+ };
94
+ emphasis_mark: string;
95
+ strong_mark: string;
96
+ delete_mark: string;
97
+ inline_code_mark: string;
98
+ thematic_break: string;
99
+ }
100
+ export declare type SlateNodeType = {
101
+ type: 'heading_one';
102
+ children: SlateNodeType[];
103
+ } | {
104
+ type: 'heading_two';
105
+ children: SlateNodeType[];
106
+ } | {
107
+ type: 'heading_three';
108
+ children: SlateNodeType[];
109
+ } | {
110
+ type: 'heading_four';
111
+ children: SlateNodeType[];
112
+ } | {
113
+ type: 'heading_five';
114
+ children: SlateNodeType[];
115
+ } | {
116
+ type: 'heading_six';
117
+ children: SlateNodeType[];
118
+ } | {
119
+ type: 'paragraph';
120
+ children: SlateNodeType[];
121
+ } | {
122
+ children: SlateNodeType[];
123
+ link: string;
124
+ type: 'link';
125
+ } | {
126
+ type: 'block_quote';
127
+ children: SlateNodeType[];
128
+ } | {
129
+ type: 'text';
130
+ text: string;
131
+ } | {
132
+ type: 'mdxJsxTextElement';
133
+ props: object;
134
+ children: SlateNodeType[];
135
+ name: string;
136
+ } | {
137
+ type: 'mdxJsxFlowElement';
138
+ props: object;
139
+ children: SlateNodeType[];
140
+ name: string;
141
+ } | {
142
+ type: 'block_quote';
143
+ children: SlateNodeType[];
144
+ } | {
145
+ type: 'code_block';
146
+ language: string;
147
+ value: string;
148
+ } | {
149
+ type: 'image';
150
+ link: string;
151
+ caption: string;
152
+ } | {
153
+ type: 'thematic_break';
154
+ };
155
+ declare type RecursivePartial<T> = {
156
+ [P in keyof T]?: RecursivePartial<T[P]>;
157
+ };
158
+ export interface OptionType {
159
+ nodeTypes?: RecursivePartial<NodeTypes>;
160
+ linkDestinationKey?: string;
161
+ imageSourceKey?: string;
162
+ imageCaptionKey?: string;
163
+ }
164
+ export interface MdastNode {
165
+ type?: string;
166
+ ordered?: boolean;
167
+ value?: string;
168
+ text?: string;
169
+ children?: Array<MdastNode>;
170
+ depth?: 1 | 2 | 3 | 4 | 5 | 6;
171
+ url?: string;
172
+ alt?: string;
173
+ lang?: string;
174
+ position?: any;
175
+ spread?: any;
176
+ checked?: any;
177
+ indent?: any;
178
+ }
179
+ declare type MdxJsxFlowElement = {
180
+ type: 'mdxJsxFlowElement';
181
+ name: string;
182
+ attributes: object;
183
+ children: MdxAstNode[];
184
+ };
185
+ declare type MdxJsxTextElement = {
186
+ type: 'mdxJsxTextElement';
187
+ name: string;
188
+ attributes: object;
189
+ children: MdxAstNode[];
190
+ };
191
+ declare type MdxAstNode = Content | MdxJsxFlowElement | MdxJsxTextElement;
192
+ export declare const plateElements: {
193
+ ELEMENT_H1: string;
194
+ ELEMENT_H2: string;
195
+ ELEMENT_H3: string;
196
+ ELEMENT_H4: string;
197
+ ELEMENT_H5: string;
198
+ ELEMENT_H6: string;
199
+ ELEMENT_HR: string;
200
+ ELEMENT_ALIGN_CENTER: string;
201
+ ELEMENT_ALIGN_JUSTIFY: string;
202
+ ELEMENT_ALIGN_LEFT: string;
203
+ ELEMENT_ALIGN_RIGHT: string;
204
+ ELEMENT_BLOCKQUOTE: string;
205
+ ELEMENT_CODE_BLOCK: string;
206
+ ELEMENT_CODE_LINE: string;
207
+ ELEMENT_DEFAULT: string;
208
+ ELEMENT_IMAGE: string;
209
+ ELEMENT_LI: string;
210
+ ELEMENT_LIC: string;
211
+ ELEMENT_LINK: string;
212
+ ELEMENT_MEDIA_EMBED: string;
213
+ ELEMENT_MENTION: string;
214
+ ELEMENT_OL: string;
215
+ ELEMENT_PARAGRAPH: string;
216
+ ELEMENT_TABLE: string;
217
+ ELEMENT_TD: string;
218
+ ELEMENT_TH: string;
219
+ ELEMENT_TODO_LI: string;
220
+ ELEMENT_TR: string;
221
+ ELEMENT_UL: string;
222
+ MARK_ITALIC: string;
223
+ MARK_BOLD: string;
224
+ MARK_STRIKETHROUGH: string;
225
+ MARK_UNDERLINE: string;
226
+ };
227
+ export declare const defaultNodeTypes: NodeTypes;
228
+ export default function remarkToSlate(node: MdxAstNode): any;
229
+ export {};
@@ -0,0 +1,24 @@
1
+ /**
2
+
3
+ Copyright 2021 Forestry.io Holdings, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ */
18
+ import type { RichTypeInner } from '../types';
19
+ import { plateElements } from './parse';
20
+ import type { Content } from 'mdast';
21
+ export declare const stringifyMDX: (value: unknown, field: RichTypeInner) => string;
22
+ export declare const stringify: (node: {
23
+ type: typeof plateElements;
24
+ }, field: RichTypeInner) => Content;
@@ -10,7 +10,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
10
  See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
- import { FieldDefinitionNode, ScalarTypeDefinitionNode, InputValueDefinitionNode, ObjectTypeDefinitionNode, InterfaceTypeDefinitionNode, NamedTypeNode, UnionTypeDefinitionNode, TypeDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, InputObjectTypeDefinitionNode, DocumentNode } from 'graphql';
13
+ import { FieldDefinitionNode, ScalarTypeDefinitionNode, InputValueDefinitionNode, ObjectTypeDefinitionNode, InterfaceTypeDefinitionNode, NamedTypeNode, UnionTypeDefinitionNode, TypeDefinitionNode, DirectiveNode, EnumTypeDefinitionNode, InputObjectTypeDefinitionNode, DocumentNode, FragmentDefinitionNode, SelectionNode, FieldNode, InlineFragmentNode, OperationDefinitionNode } from 'graphql';
14
14
  /**
15
15
  * the `gql` module provides functions and types which can be
16
16
  * used to build up the GraphQL AST. The primary reason for us using
@@ -45,6 +45,13 @@ export declare const astBuilder: {
45
45
  required?: boolean;
46
46
  values: string[];
47
47
  }) => EnumTypeDefinitionNode;
48
+ FieldNodeDefinition: ({ name, type, args, list, required, }: {
49
+ name: string;
50
+ type: string | TypeDefinitionNode;
51
+ required?: boolean;
52
+ list?: boolean;
53
+ args?: InputValueDefinitionNode[];
54
+ }) => FieldNode;
48
55
  FieldDefinition: ({ name, type, args, list, required, }: {
49
56
  name: string;
50
57
  type: string | TypeDefinitionNode;
@@ -75,6 +82,29 @@ export declare const astBuilder: {
75
82
  directives?: DirectiveNode[];
76
83
  args?: NamedTypeNode[];
77
84
  }) => ObjectTypeDefinitionNode;
85
+ FieldWithSelectionSetDefinition: ({ name, selections, }: {
86
+ name: string;
87
+ selections: SelectionNode[];
88
+ }) => {
89
+ name: {
90
+ kind: "Name";
91
+ value: string;
92
+ };
93
+ kind: "Field";
94
+ selectionSet: {
95
+ kind: "SelectionSet";
96
+ selections: SelectionNode[];
97
+ };
98
+ };
99
+ InlineFragmentDefinition: ({ name, selections, }: {
100
+ name: string;
101
+ selections: SelectionNode[];
102
+ }) => InlineFragmentNode;
103
+ FragmentDefinition: ({ name, fragmentName, selections, }: {
104
+ name: string;
105
+ fragmentName: string;
106
+ selections: SelectionNode[];
107
+ }) => FragmentDefinitionNode;
78
108
  TYPES: {
79
109
  Scalar: (type: scalarNames) => string;
80
110
  MultiCollectionDocument: string;
@@ -92,6 +122,14 @@ export declare const astBuilder: {
92
122
  Number: string;
93
123
  Document: string;
94
124
  };
125
+ QueryOperationDefinition: ({ queryName, fragName, }: {
126
+ queryName: string;
127
+ fragName: string;
128
+ }) => OperationDefinitionNode;
129
+ ListQueryOperationDefinition: ({ queryName, fragName, }: {
130
+ queryName: string;
131
+ fragName: string;
132
+ }) => OperationDefinitionNode;
95
133
  toGraphQLAst: (ast: {
96
134
  globalTemplates: TypeDefinitionNode[];
97
135
  query: TypeDefinitionNode;
@@ -111,6 +149,7 @@ export declare const NAMER: {
111
149
  createName: (namespace: string[]) => string;
112
150
  queryName: (namespace: string[]) => string;
113
151
  generateQueryListName: (namespace: string[]) => string;
152
+ fragmentName: (namespace: string[]) => string;
114
153
  collectionTypeName: (namespace: string[]) => string;
115
154
  documentTypeName: (namespace: string[]) => string;
116
155
  dataTypeName: (namespace: string[]) => string;
@@ -11,8 +11,8 @@ See the License for the specific language governing permissions and
11
11
  limitations under the License.
12
12
  */
13
13
  import { Database } from '../database';
14
- import type { ObjectTypeDefinitionNode } from 'graphql';
15
- import type { TinaCloudCollectionEnriched } from '../types';
14
+ import type { ObjectTypeDefinitionNode, InlineFragmentNode } from 'graphql';
15
+ import type { TinaCloudCollectionEnriched, Template } from '../types';
16
16
  import { TinaSchema } from '../schema';
17
17
  export declare const createBuilder: ({ database, tinaSchema, }: {
18
18
  database: Database;
@@ -169,6 +169,33 @@ export declare class Builder {
169
169
  * @param collection
170
170
  */
171
171
  collectionDocument: (collection: TinaCloudCollectionEnriched) => Promise<import("graphql").FieldDefinitionNode>;
172
+ /**
173
+ * Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
174
+ * ```graphql
175
+ * # ex.
176
+ * fragment AuthorsParts on Authors {
177
+ * name
178
+ * avatar
179
+ * ...
180
+ * }
181
+ * ```
182
+ *
183
+ * @public
184
+ * @param collection a Tina Cloud collection
185
+ */
186
+ collectionFragment: (collection: TinaCloudCollectionEnriched) => Promise<import("graphql").FragmentDefinitionNode | {
187
+ name: {
188
+ kind: "Name";
189
+ value: string;
190
+ };
191
+ kind: "Field";
192
+ selectionSet: {
193
+ kind: "SelectionSet";
194
+ selections: import("graphql").SelectionNode[];
195
+ };
196
+ }>;
197
+ private _buildFieldNodeForFragments;
198
+ buildTemplateFragments(template: Template<true>): Promise<InlineFragmentNode>;
172
199
  /**
173
200
  * ```graphql
174
201
  * # ex.
@@ -18,35 +18,14 @@ export declare type GithubManagerInit = {
18
18
  owner: string;
19
19
  repo: string;
20
20
  ref: string;
21
- cache?: typeof dummyCache;
22
- };
23
- declare const dummyCache: {
24
- get: <T extends string | string[]>(key: string, setter: () => Promise<T>) => Promise<T>;
25
21
  };
26
22
  export declare class GithubBridge implements Bridge {
27
23
  rootPath: string;
28
24
  repoConfig: Pick<GithubManagerInit, 'owner' | 'ref' | 'repo'>;
29
25
  appOctoKit: Octokit;
30
- cache: typeof dummyCache;
31
- constructor({ rootPath, accessToken, owner, repo, ref, cache, }: GithubManagerInit);
32
- private generateKey;
26
+ constructor({ rootPath, accessToken, owner, repo, ref }: GithubManagerInit);
33
27
  private readDir;
34
28
  glob(pattern: string): Promise<string[]>;
35
29
  get(filepath: string): Promise<string>;
36
30
  put(filepath: string, data: string): Promise<void>;
37
31
  }
38
- export declare const clearCache: ({ owner, repo, ref, path, }: {
39
- owner: string;
40
- repo: string;
41
- ref: string;
42
- path?: string;
43
- }) => void;
44
- /**
45
- * This is just an example of what you can provide for caching
46
- * it should be replaced with a scalable solution which shares a cache
47
- * across lambda instances (like redis)
48
- */
49
- export declare const simpleCache: {
50
- get: (keyName: string, setter: () => Promise<any>) => Promise<any>;
51
- };
52
- export {};
@@ -12,7 +12,6 @@ limitations under the License.
12
12
  */
13
13
  import { indexDB } from './build';
14
14
  import { resolve } from './resolve';
15
- import { simpleCache } from '../cache/lru';
16
15
  import { createDatabase } from './database';
17
16
  export { createDatabase, resolve, indexDB };
18
17
  export type { TinaCloudSchema } from './types';
@@ -25,7 +24,7 @@ export declare const gql: ({ rootPath, query, variables, }: {
25
24
  }, {
26
25
  [key: string]: any;
27
26
  }>>;
28
- export declare const githubRoute: ({ rootPath, query, variables, cacheType, branch, ...githubArgs }: {
27
+ export declare const githubRoute: ({ rootPath, query, variables, branch, ...githubArgs }: {
29
28
  accessToken: string;
30
29
  owner: string;
31
30
  repo: string;
@@ -33,7 +32,6 @@ export declare const githubRoute: ({ rootPath, query, variables, cacheType, bran
33
32
  variables: object;
34
33
  rootPath?: string;
35
34
  branch: string;
36
- cacheType?: typeof simpleCache;
37
35
  }) => Promise<import("graphql").ExecutionResult<{
38
36
  [key: string]: any;
39
37
  }, {
@@ -215,7 +215,7 @@ export declare type TinaCloudTemplateEnriched = GlobalTemplate<true>;
215
215
  /**
216
216
  * Templates allow you to define an object as polymorphic
217
217
  */
218
- declare type Template<WithNamespace extends boolean> = WithNamespace extends true ? {
218
+ export declare type Template<WithNamespace extends boolean> = WithNamespace extends true ? {
219
219
  label: string;
220
220
  name: string;
221
221
  fields: TinaFieldInner<WithNamespace>[];
@@ -0,0 +1,22 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ import type { Database } from './database';
14
+ export declare const resolve: ({ query, variables, database, }: {
15
+ query: string;
16
+ variables: object;
17
+ database: Database;
18
+ }) => Promise<import("graphql").ExecutionResult<{
19
+ [key: string]: any;
20
+ }, {
21
+ [key: string]: any;
22
+ }>>;
@@ -0,0 +1,25 @@
1
+ /**
2
+ Copyright 2021 Forestry.io Holdings, Inc.
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
12
+ */
13
+ import { ASTNode, GraphQLError, Source, SourceLocation } from 'graphql';
14
+ export declare class TinaError extends Error implements GraphQLError {
15
+ extensions: Record<string, any>;
16
+ readonly name: string;
17
+ readonly locations: ReadonlyArray<SourceLocation> | undefined;
18
+ readonly path: ReadonlyArray<string | number> | undefined;
19
+ readonly source: Source | undefined;
20
+ readonly positions: ReadonlyArray<number> | undefined;
21
+ readonly nodes: ReadonlyArray<ASTNode> | undefined;
22
+ originalError: Error | null | undefined;
23
+ [key: string]: any;
24
+ constructor(message: string, extensions?: Record<string, any>);
25
+ }