@tinacms/graphql 0.0.0-0a77b75-20241004023651

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.
@@ -0,0 +1,7 @@
1
+ import { ManyLevelGuest } from 'many-level';
2
+ export declare class TinaLevelClient extends ManyLevelGuest<string, Record<string, any>> {
3
+ private port;
4
+ private _connected;
5
+ constructor(port?: number);
6
+ openConnection(): void;
7
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import { parseMDX, stringifyMDX } from '@tinacms/mdx';
7
+ export { parseMDX };
8
+ export { stringifyMDX };
@@ -0,0 +1,21 @@
1
+ /**
2
+
3
+ */
4
+ import type { GraphQLConfig } from './types';
5
+ import type { Database } from './database';
6
+ export declare const resolve: ({ config, query, variables, database, silenceErrors, verbose, isAudit, ctxUser, }: {
7
+ config?: GraphQLConfig;
8
+ query: string;
9
+ variables: object;
10
+ database: Database;
11
+ silenceErrors?: boolean;
12
+ verbose?: boolean;
13
+ isAudit?: boolean;
14
+ ctxUser?: {
15
+ sub: string;
16
+ };
17
+ }) => Promise<import("graphql").ExecutionResult<{
18
+ [key: string]: any;
19
+ }, {
20
+ [key: string]: any;
21
+ }>>;
@@ -0,0 +1,46 @@
1
+ /**
2
+
3
+ */
4
+ import { ASTNode, GraphQLError, Source, SourceLocation } from 'graphql';
5
+ export declare class TinaGraphQLError extends Error implements GraphQLError {
6
+ extensions: Record<string, any>;
7
+ readonly name: string;
8
+ readonly locations: ReadonlyArray<SourceLocation> | undefined;
9
+ readonly path: ReadonlyArray<string | number> | undefined;
10
+ readonly source: Source | undefined;
11
+ readonly positions: ReadonlyArray<number> | undefined;
12
+ readonly nodes: ReadonlyArray<ASTNode> | undefined;
13
+ originalError: Error | null | undefined;
14
+ [key: string]: any;
15
+ constructor(message: string, extensions?: Record<string, any>);
16
+ }
17
+ export type TypeFetchErrorArgs = {
18
+ stack?: string;
19
+ file?: string;
20
+ includeAuditMessage?: boolean;
21
+ originalError: Error;
22
+ collection?: string;
23
+ };
24
+ export declare class TinaFetchError extends Error {
25
+ stack?: string;
26
+ collection?: string;
27
+ file?: string;
28
+ originalError: Error;
29
+ constructor(message: string, args: TypeFetchErrorArgs);
30
+ }
31
+ export declare class TinaQueryError extends TinaFetchError {
32
+ stack?: string;
33
+ collection?: string;
34
+ file?: string;
35
+ originalError: Error;
36
+ constructor(args: TypeFetchErrorArgs);
37
+ }
38
+ export declare class TinaParseDocumentError extends TinaFetchError {
39
+ stack?: string;
40
+ collection?: string;
41
+ file?: string;
42
+ originalError: Error;
43
+ constructor(args: TypeFetchErrorArgs);
44
+ toString(): string;
45
+ }
46
+ export declare const handleFetchErrorError: (e: unknown, verbose: any) => never;
@@ -0,0 +1,13 @@
1
+ /**
2
+
3
+ */
4
+ import type { ReferenceType, TinaField } from '@tinacms/schema-tools';
5
+ import { FilterCondition } from '../database/datalayer';
6
+ export type ReferenceResolver = (filter: Record<string, object>, fieldDefinition: ReferenceType) => Promise<{
7
+ edges: {
8
+ node: any;
9
+ }[];
10
+ values: any[];
11
+ }>;
12
+ export declare const resolveReferences: (filter: any, fields: TinaField[], resolver: ReferenceResolver) => Promise<void>;
13
+ export declare const collectConditionsForField: (fieldName: string, field: TinaField, filterNode: Record<string, object>, pathExpression: string, collectCondition: (condition: FilterCondition) => void) => void;
@@ -0,0 +1,352 @@
1
+ /**
2
+
3
+ */
4
+ import { Database } from '../database';
5
+ import type { Collectable, Collection, TinaField, Template, TinaSchema } from '@tinacms/schema-tools';
6
+ import type { GraphQLConfig } from '../types';
7
+ interface ResolverConfig {
8
+ config?: GraphQLConfig;
9
+ database: Database;
10
+ tinaSchema: TinaSchema;
11
+ isAudit: boolean;
12
+ }
13
+ export declare const createResolver: (args: ResolverConfig) => Resolver;
14
+ export declare const transformDocumentIntoPayload: (fullPath: string, rawData: {
15
+ _collection: any;
16
+ _template: any;
17
+ }, tinaSchema: TinaSchema, config?: GraphQLConfig, isAudit?: boolean) => Promise<{
18
+ _sys: {
19
+ title: any;
20
+ basename: string;
21
+ filename: string;
22
+ extension: string;
23
+ path: string;
24
+ relativePath: string;
25
+ breadcrumbs: string[];
26
+ collection: Collection<true>;
27
+ template: string | number;
28
+ };
29
+ _values: {
30
+ _collection: any;
31
+ _template: any;
32
+ };
33
+ _rawData: {
34
+ _collection: any;
35
+ _template: any;
36
+ };
37
+ _collection: any;
38
+ _template: any;
39
+ __typename: string;
40
+ id: string;
41
+ }>;
42
+ /**
43
+ * The resolver provides functions for all possible types of lookup
44
+ * values and retrieves them from the database
45
+ */
46
+ export declare class Resolver {
47
+ init: ResolverConfig;
48
+ config: GraphQLConfig;
49
+ database: Database;
50
+ tinaSchema: TinaSchema;
51
+ isAudit: boolean;
52
+ constructor(init: ResolverConfig);
53
+ resolveCollection: (args: any, collectionName: string, hasDocuments?: boolean) => Promise<{
54
+ fields: TinaField<true>[];
55
+ templates?: undefined;
56
+ label?: string;
57
+ name: string;
58
+ path: string;
59
+ indexes?: {
60
+ name: string;
61
+ fields: {
62
+ name: string;
63
+ }[];
64
+ }[];
65
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "yml" | "toml";
66
+ ui?: import("@tinacms/schema-tools").UICollection;
67
+ defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
68
+ frontmatterFormat?: "yaml" | "toml" | "json";
69
+ frontmatterDelimiters?: [string, string] | string;
70
+ match?: {
71
+ include?: string;
72
+ exclude?: string;
73
+ };
74
+ isDetached?: boolean;
75
+ isAuthCollection?: boolean;
76
+ namespace: string[];
77
+ documents: {
78
+ collection: Collection<true>;
79
+ hasDocuments: boolean;
80
+ };
81
+ } | {
82
+ templates: Template<true>[];
83
+ fields?: undefined;
84
+ label?: string;
85
+ name: string;
86
+ path: string;
87
+ indexes?: {
88
+ name: string;
89
+ fields: {
90
+ name: string;
91
+ }[];
92
+ }[];
93
+ format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "yml" | "toml";
94
+ ui?: import("@tinacms/schema-tools").UICollection;
95
+ defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
96
+ frontmatterFormat?: "yaml" | "toml" | "json";
97
+ frontmatterDelimiters?: [string, string] | string;
98
+ match?: {
99
+ include?: string;
100
+ exclude?: string;
101
+ };
102
+ isDetached?: boolean;
103
+ isAuthCollection?: boolean;
104
+ namespace: string[];
105
+ documents: {
106
+ collection: Collection<true>;
107
+ hasDocuments: boolean;
108
+ };
109
+ }>;
110
+ getRaw: (fullPath: unknown) => Promise<{
111
+ _collection: string;
112
+ _template: string;
113
+ }>;
114
+ getDocumentOrDirectory: (fullPath: unknown) => Promise<{
115
+ _sys: {
116
+ title: any;
117
+ basename: string;
118
+ filename: string;
119
+ extension: string;
120
+ path: string;
121
+ relativePath: string;
122
+ breadcrumbs: string[];
123
+ collection: Collection<true>;
124
+ template: string | number;
125
+ };
126
+ _values: {
127
+ _collection: any;
128
+ _template: any;
129
+ };
130
+ _rawData: {
131
+ _collection: any;
132
+ _template: any;
133
+ };
134
+ _collection: any;
135
+ _template: any;
136
+ __typename: string;
137
+ id: string;
138
+ } | {
139
+ __typename: string;
140
+ name: any;
141
+ path: any;
142
+ }>;
143
+ getDocument: (fullPath: unknown) => Promise<{
144
+ _sys: {
145
+ title: any;
146
+ basename: string;
147
+ filename: string;
148
+ extension: string;
149
+ path: string;
150
+ relativePath: string;
151
+ breadcrumbs: string[];
152
+ collection: Collection<true>;
153
+ template: string | number;
154
+ };
155
+ _values: {
156
+ _collection: any;
157
+ _template: any;
158
+ };
159
+ _rawData: {
160
+ _collection: any;
161
+ _template: any;
162
+ };
163
+ _collection: any;
164
+ _template: any;
165
+ __typename: string;
166
+ id: string;
167
+ }>;
168
+ deleteDocument: (fullPath: unknown) => Promise<void>;
169
+ buildObjectMutations: (fieldValue: any, field: Collectable, existingData?: Record<string, any> | Record<string, any>[]) => Promise<{
170
+ [key: string]: unknown;
171
+ } | {
172
+ [key: string]: unknown;
173
+ }[] | {
174
+ _template: string;
175
+ }[]>;
176
+ createResolveDocument: ({ collection, realPath, args, isAddPendingDocument, }: {
177
+ collection: Collection<true>;
178
+ realPath: string;
179
+ args: unknown;
180
+ isAddPendingDocument: boolean;
181
+ }) => Promise<{
182
+ _sys: {
183
+ title: any;
184
+ basename: string;
185
+ filename: string;
186
+ extension: string;
187
+ path: string;
188
+ relativePath: string;
189
+ breadcrumbs: string[];
190
+ collection: Collection<true>;
191
+ template: string | number;
192
+ };
193
+ _values: {
194
+ _collection: any;
195
+ _template: any;
196
+ };
197
+ _rawData: {
198
+ _collection: any;
199
+ _template: any;
200
+ };
201
+ _collection: any;
202
+ _template: any;
203
+ __typename: string;
204
+ id: string;
205
+ }>;
206
+ updateResolveDocument: ({ collection, realPath, args, isAddPendingDocument, isCollectionSpecific, }: {
207
+ collection: Collection<true>;
208
+ realPath: string;
209
+ args: unknown;
210
+ isAddPendingDocument: boolean;
211
+ isCollectionSpecific: boolean;
212
+ }) => Promise<{
213
+ _sys: {
214
+ title: any;
215
+ basename: string;
216
+ filename: string;
217
+ extension: string;
218
+ path: string;
219
+ relativePath: string;
220
+ breadcrumbs: string[];
221
+ collection: Collection<true>;
222
+ template: string | number;
223
+ };
224
+ _values: {
225
+ _collection: any;
226
+ _template: any;
227
+ };
228
+ _rawData: {
229
+ _collection: any;
230
+ _template: any;
231
+ };
232
+ _collection: any;
233
+ _template: any;
234
+ __typename: string;
235
+ id: string;
236
+ }>;
237
+ /**
238
+ * Returns top-level fields which are not defined in the collection, so their
239
+ * values are not eliminated from Tina when new values are saved
240
+ */
241
+ resolveLegacyValues: (oldDoc: any, collection: Collection<true>) => {};
242
+ resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isFolderCreation, isAddPendingDocument, isCollectionSpecific, isUpdateName, }: {
243
+ args: unknown;
244
+ collection?: string;
245
+ isMutation: boolean;
246
+ isCreation?: boolean;
247
+ isDeletion?: boolean;
248
+ isFolderCreation?: boolean;
249
+ isAddPendingDocument?: boolean;
250
+ isCollectionSpecific?: boolean;
251
+ isUpdateName?: boolean;
252
+ }) => Promise<{
253
+ _sys: {
254
+ title: any;
255
+ basename: string;
256
+ filename: string;
257
+ extension: string;
258
+ path: string;
259
+ relativePath: string;
260
+ breadcrumbs: string[];
261
+ collection: Collection<true>;
262
+ template: string | number;
263
+ };
264
+ _values: {
265
+ _collection: any;
266
+ _template: any;
267
+ };
268
+ _rawData: {
269
+ _collection: any;
270
+ _template: any;
271
+ };
272
+ _collection: any;
273
+ _template: any;
274
+ __typename: string;
275
+ id: string;
276
+ }>;
277
+ resolveCollectionConnections: ({ ids }: {
278
+ ids: string[];
279
+ }) => Promise<{
280
+ totalCount: number;
281
+ edges: {
282
+ node: {
283
+ _sys: {
284
+ title: any;
285
+ basename: string;
286
+ filename: string;
287
+ extension: string;
288
+ path: string;
289
+ relativePath: string;
290
+ breadcrumbs: string[];
291
+ collection: Collection<true>;
292
+ template: string | number;
293
+ };
294
+ _values: {
295
+ _collection: any;
296
+ _template: any;
297
+ };
298
+ _rawData: {
299
+ _collection: any;
300
+ _template: any;
301
+ };
302
+ _collection: any;
303
+ _template: any;
304
+ __typename: string;
305
+ id: string;
306
+ };
307
+ }[];
308
+ }>;
309
+ private referenceResolver;
310
+ private resolveFilterConditions;
311
+ resolveCollectionConnection: ({ args, collection, hydrator, }: {
312
+ args: Record<string, Record<string, object> | string | number>;
313
+ collection: Collection<true>;
314
+ hydrator?: (string: any) => any;
315
+ }) => Promise<{
316
+ totalCount: number;
317
+ edges: {
318
+ node: any;
319
+ cursor: string;
320
+ }[];
321
+ pageInfo: {
322
+ hasPreviousPage: boolean;
323
+ hasNextPage: boolean;
324
+ startCursor: string;
325
+ endCursor: string;
326
+ };
327
+ }>;
328
+ private buildFieldMutations;
329
+ /**
330
+ * A mutation looks nearly identical between updateDocument:
331
+ * ```graphql
332
+ * updateDocument(collection: $collection,relativePath: $path, params: {
333
+ * post: {
334
+ * title: "Hello, World"
335
+ * }
336
+ * })`
337
+ * ```
338
+ * and `updatePostDocument`:
339
+ * ```graphql
340
+ * updatePostDocument(relativePath: $path, params: {
341
+ * title: "Hello, World"
342
+ * })
343
+ * ```
344
+ * The problem here is that we don't know whether the payload came from `updateDocument`
345
+ * or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
346
+ * But we do know that when given a `args.collection` value, we can assume that
347
+ * this was a `updateDocument` request, and thus - should grab the data
348
+ * from the corresponding field name in the key
349
+ */
350
+ private buildParams;
351
+ }
352
+ export {};
@@ -0,0 +1,21 @@
1
+ /**
2
+
3
+ */
4
+ import type { GraphQLConfig } from '../types';
5
+ import type { Schema } from '@tinacms/schema-tools';
6
+ /**
7
+ * Strips away the Tina Cloud Asset URL from an `image` value
8
+ *
9
+ * @param {string | string[]} value
10
+ * @param {GraphQLConfig} config
11
+ * @returns {string}
12
+ */
13
+ export declare const resolveMediaCloudToRelative: (value: string | string[], config: GraphQLConfig, schema: Schema<true>) => string | string[];
14
+ /**
15
+ * Adds Tina Cloud Asset URL to an `image` value
16
+ *
17
+ * @param {string | string[]} value
18
+ * @param {GraphQLConfig} config
19
+ * @returns {string}
20
+ */
21
+ export declare const resolveMediaRelativeToCloud: (value: string | string[], config: GraphQLConfig, schema: Schema<true>) => string | string[];
@@ -0,0 +1,8 @@
1
+ /**
2
+
3
+ */
4
+ import { TinaSchema, Schema } from '@tinacms/schema-tools';
5
+ export declare const createSchema: ({ schema, flags, }: {
6
+ schema: Schema;
7
+ flags?: string[];
8
+ }) => Promise<TinaSchema>;
@@ -0,0 +1,11 @@
1
+ /**
2
+
3
+ */
4
+ import { type Schema, type Collection } from '@tinacms/schema-tools';
5
+ export declare const validateSchema: (schema: Schema) => Promise<{
6
+ collections: Collection<true>[];
7
+ config: import("@tinacms/schema-tools").Config<undefined, undefined, undefined, undefined, undefined>;
8
+ } | {
9
+ collections: Collection<true>[];
10
+ config?: undefined;
11
+ }>;
@@ -0,0 +1,5 @@
1
+ /**
2
+
3
+ */
4
+ import type { TinaSchema } from '@tinacms/schema-tools';
5
+ export declare const buildSKD: (tinaSchema: TinaSchema) => string;
@@ -0,0 +1,32 @@
1
+ /**
2
+
3
+ */
4
+ import type { Schema } from '@tinacms/schema-tools';
5
+ import { Database } from '../database';
6
+ import { Level } from '../database/level';
7
+ export declare const setup: (rootPath: string, schema: Schema, level: Level) => Promise<{
8
+ database: Database;
9
+ }>;
10
+ export declare const print: (fixture: Fixture) => string;
11
+ export type Fixture = {
12
+ description?: string;
13
+ name: string;
14
+ assert: 'output';
15
+ message?: string;
16
+ expectError?: boolean;
17
+ } | {
18
+ description?: string;
19
+ name: string;
20
+ assert: 'file';
21
+ filename: string;
22
+ message?: string;
23
+ expectError?: boolean;
24
+ };
25
+ export declare const setupFixture: (rootPath: string, schema: Schema, level: Level, fixture: Fixture, suffix?: string, queryName?: string, folder?: string) => Promise<{
26
+ responses: string[];
27
+ expectedResponsePaths: string[];
28
+ }>;
29
+ export declare const setupFixture2: (rootPath: string, schema: Schema, level: Level, fixture: Fixture, suffix?: string, queryName?: string, folder?: string) => Promise<{
30
+ responses: string[];
31
+ expectedResponsePaths: string[];
32
+ }>;
@@ -0,0 +1,10 @@
1
+ /**
2
+
3
+ */
4
+ export type GraphQLConfig = {
5
+ useRelativeMedia: true;
6
+ } | {
7
+ useRelativeMedia: false;
8
+ clientId: string;
9
+ assetsHost: string;
10
+ };
package/dist/util.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+
3
+ */
4
+ import * as yup from 'yup';
5
+ /**
6
+ * Iterate through an array of promises sequentially, ensuring the order
7
+ * is preserved.
8
+ *
9
+ * ```js
10
+ * await sequential(templates, async (template) => {
11
+ * await doSomething(template)
12
+ * })
13
+ * ```
14
+ */
15
+ export declare const sequential: <A, B>(items: A[] | undefined, callback: (args: A, idx: number) => Promise<B>) => Promise<B[]>;
16
+ export declare function assertShape<T>(value: unknown, yupSchema: (args: typeof yup) => yup.AnySchema, errorMessage?: string): asserts value is T;
17
+ export declare const atob: (b64Encoded: string) => string;
18
+ export declare const btoa: (string: string) => string;
19
+ export declare const lastItem: (arr: (number | string)[]) => string | number;
20
+ export declare const get: (obj: any, path: any, defaultValue?: any) => any;
21
+ export declare const flattenDeep: (arr: any) => any;
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@tinacms/graphql",
3
+ "version": "0.0.0-0a77b75-20241004023651",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.mjs",
6
+ "typings": "dist/index.d.ts",
7
+ "files": [
8
+ "package.json",
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js"
14
+ },
15
+ "license": "SEE LICENSE IN LICENSE",
16
+ "buildConfig": {
17
+ "entryPoints": [
18
+ {
19
+ "name": "src/index.ts",
20
+ "target": "node",
21
+ "bundle": []
22
+ }
23
+ ]
24
+ },
25
+ "dependencies": {
26
+ "@iarna/toml": "^2.2.5",
27
+ "abstract-level": "^1.0.4",
28
+ "date-fns": "^2.30.0",
29
+ "fast-glob": "^3.3.2",
30
+ "fs-extra": "^11.2.0",
31
+ "glob-parent": "^6.0.2",
32
+ "graphql": "15.8.0",
33
+ "gray-matter": "^4.0.3",
34
+ "isomorphic-git": "^1.27.1",
35
+ "js-sha1": "^0.6.0",
36
+ "js-yaml": "^3.14.1",
37
+ "jsonpath-plus": "^6.0.1",
38
+ "lodash.clonedeep": "^4.5.0",
39
+ "lodash.set": "^4.3.2",
40
+ "lodash.uniqby": "^4.7.0",
41
+ "many-level": "^2.0.0",
42
+ "micromatch": "4.0.8",
43
+ "normalize-path": "^3.0.0",
44
+ "readable-stream": "^4.5.2",
45
+ "scmp": "^2.1.0",
46
+ "yup": "^0.32.11",
47
+ "@tinacms/mdx": "0.0.0-0a77b75-20241004023651",
48
+ "@tinacms/schema-tools": "0.0.0-0a77b75-20241004023651"
49
+ },
50
+ "publishConfig": {
51
+ "registry": "https://registry.npmjs.org"
52
+ },
53
+ "repository": {
54
+ "url": "https://github.com/tinacms/tinacms.git",
55
+ "directory": "packages/tina-graphql"
56
+ },
57
+ "devDependencies": {
58
+ "@types/cors": "^2.8.17",
59
+ "@types/estree": "^0.0.50",
60
+ "@types/express": "^4.17.21",
61
+ "@types/fs-extra": "^9.0.13",
62
+ "@types/jest": "^26.0.24",
63
+ "@types/js-yaml": "^3.12.10",
64
+ "@types/lodash.camelcase": "^4.3.9",
65
+ "@types/lodash.upperfirst": "^4.3.9",
66
+ "@types/lru-cache": "^5.1.1",
67
+ "@types/mdast": "^3.0.15",
68
+ "@types/micromatch": "^4.0.9",
69
+ "@types/node": "^22.7.4",
70
+ "@types/normalize-path": "^3.0.2",
71
+ "@types/ws": "^7.4.7",
72
+ "@types/yup": "^0.29.14",
73
+ "jest": "^29.7.0",
74
+ "jest-diff": "^29.7.0",
75
+ "jest-file-snapshot": "^0.5.0",
76
+ "jest-matcher-utils": "^29.7.0",
77
+ "memory-level": "^1.0.0",
78
+ "nodemon": "3.1.4",
79
+ "typescript": "^5.6.2",
80
+ "@tinacms/schema-tools": "0.0.0-0a77b75-20241004023651",
81
+ "@tinacms/scripts": "1.2.3"
82
+ },
83
+ "scripts": {
84
+ "types": "pnpm tsc",
85
+ "build": "tinacms-scripts build",
86
+ "docs": "pnpm typedoc",
87
+ "serve": "pnpm nodemon dist/server.js",
88
+ "test": "jest",
89
+ "test-watch": "jest --watch"
90
+ }
91
+ }