@tinacms/graphql 1.0.4 → 1.1.0
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.
|
@@ -147,6 +147,7 @@ export declare const NAMER: {
|
|
|
147
147
|
dataFilterTypeName: (namespace: string[]) => string;
|
|
148
148
|
dataMutationTypeNameOn: (namespace: string[]) => string;
|
|
149
149
|
dataMutationTypeName: (namespace: string[]) => string;
|
|
150
|
+
dataMutationUpdateTypeName: (namespace: string[]) => string;
|
|
150
151
|
updateName: (namespace: string[]) => string;
|
|
151
152
|
createName: (namespace: string[]) => string;
|
|
152
153
|
documentQueryName: () => string;
|
package/dist/builder/index.d.ts
CHANGED
|
@@ -251,6 +251,7 @@ export declare class Builder {
|
|
|
251
251
|
private _buildFieldFilter;
|
|
252
252
|
private _buildFieldMutation;
|
|
253
253
|
private _buildReferenceMutation;
|
|
254
|
+
private _buildUpdateDocumentMutationParams;
|
|
254
255
|
private _buildObjectOrUnionData;
|
|
255
256
|
private _connectionFilterBuilder;
|
|
256
257
|
private _connectionFieldBuilder;
|
|
@@ -21,4 +21,10 @@ export interface Bridge {
|
|
|
21
21
|
*/
|
|
22
22
|
supportsBuilding(): boolean;
|
|
23
23
|
putConfig(filepath: string, data: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Optionally, the bridge can perform
|
|
26
|
+
* operations in a separate path.
|
|
27
|
+
*/
|
|
28
|
+
outputPath?: string;
|
|
29
|
+
addOutputPath?(outputPath: string): void;
|
|
24
30
|
}
|
package/dist/database/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ declare type IndexStatusCallback = (event: IndexStatusEvent) => Promise<void>;
|
|
|
23
23
|
declare type CreateDatabase = {
|
|
24
24
|
bridge: Bridge;
|
|
25
25
|
store: Store;
|
|
26
|
+
tinaDirectory?: string;
|
|
26
27
|
indexStatusCallback?: IndexStatusCallback;
|
|
27
28
|
};
|
|
28
29
|
export declare const createDatabase: (config: CreateDatabase) => Promise<Database>;
|
|
@@ -41,12 +42,14 @@ export declare class Database {
|
|
|
41
42
|
config: CreateDatabase;
|
|
42
43
|
bridge: Bridge;
|
|
43
44
|
store: Store;
|
|
45
|
+
tinaDirectory: string;
|
|
44
46
|
indexStatusCallback: IndexStatusCallback | undefined;
|
|
45
47
|
private tinaSchema;
|
|
46
48
|
private collectionIndexDefinitions;
|
|
47
49
|
private _lookup;
|
|
48
50
|
constructor(config: CreateDatabase);
|
|
49
51
|
private collectionForPath;
|
|
52
|
+
private getGeneratedFolder;
|
|
50
53
|
private partitionPathsByCollection;
|
|
51
54
|
get: <T extends object>(filepath: string) => Promise<T>;
|
|
52
55
|
addPendingDocument: (filepath: string, data: {
|
|
@@ -93,9 +96,10 @@ export declare class Database {
|
|
|
93
96
|
tinaSchema: TinaSchema;
|
|
94
97
|
}) => Promise<void>;
|
|
95
98
|
private indexStatusCallbackWrapper;
|
|
96
|
-
indexContent: ({ graphQLSchema, tinaSchema, }: {
|
|
99
|
+
indexContent: ({ graphQLSchema, tinaSchema, lookup: lookupFromLockFile, }: {
|
|
97
100
|
graphQLSchema: DocumentNode;
|
|
98
101
|
tinaSchema: TinaSchema;
|
|
102
|
+
lookup?: object;
|
|
99
103
|
}) => Promise<void>;
|
|
100
104
|
deleteContentByPaths: (documentPaths: string[]) => Promise<void>;
|
|
101
105
|
indexContentByPaths: (documentPaths: string[]) => Promise<void>;
|
package/dist/database/util.d.ts
CHANGED
|
@@ -11,7 +11,13 @@ See the License for the specific language governing permissions and
|
|
|
11
11
|
limitations under the License.
|
|
12
12
|
*/
|
|
13
13
|
import * as yup from 'yup';
|
|
14
|
-
export declare const stringifyFile: (content: object, format: FormatType | string, keepTemplateKey: boolean
|
|
15
|
-
|
|
14
|
+
export declare const stringifyFile: (content: object, format: FormatType | string, keepTemplateKey: boolean, markdownParseConfig?: {
|
|
15
|
+
frontmatterFormat?: 'toml' | 'yaml' | 'json';
|
|
16
|
+
frontmatterDelimiters?: [string, string] | string;
|
|
17
|
+
}) => string;
|
|
18
|
+
export declare const parseFile: <T extends object>(content: string, format: FormatType | string, yupSchema: (args: typeof yup) => yup.ObjectSchema<any>, markdownParseConfig?: {
|
|
19
|
+
frontmatterFormat?: 'toml' | 'yaml' | 'json';
|
|
20
|
+
frontmatterDelimiters?: [string, string] | string;
|
|
21
|
+
}) => T;
|
|
16
22
|
export declare type FormatType = 'json' | 'md' | 'mdx' | 'markdown';
|
|
17
23
|
export declare const normalizePath: (filepath: string) => string;
|
package/dist/index.js
CHANGED
|
@@ -1101,6 +1101,9 @@ var NAMER = {
|
|
|
1101
1101
|
dataMutationTypeName: (namespace) => {
|
|
1102
1102
|
return generateNamespacedFieldName(namespace, "Mutation");
|
|
1103
1103
|
},
|
|
1104
|
+
dataMutationUpdateTypeName: (namespace) => {
|
|
1105
|
+
return generateNamespacedFieldName(namespace, "UpdateMutation");
|
|
1106
|
+
},
|
|
1104
1107
|
updateName: (namespace) => {
|
|
1105
1108
|
return `update${generateNamespacedFieldName(namespace)}`;
|
|
1106
1109
|
},
|
|
@@ -1509,7 +1512,7 @@ var Builder = class {
|
|
|
1509
1512
|
astBuilder.InputValueDefinition({
|
|
1510
1513
|
name: "params",
|
|
1511
1514
|
required: true,
|
|
1512
|
-
type: await this.
|
|
1515
|
+
type: await this._buildUpdateDocumentMutationParams({
|
|
1513
1516
|
namespace: ["document"],
|
|
1514
1517
|
collections: collections.map((collection) => collection.name)
|
|
1515
1518
|
})
|
|
@@ -2110,6 +2113,22 @@ var Builder = class {
|
|
|
2110
2113
|
})
|
|
2111
2114
|
});
|
|
2112
2115
|
};
|
|
2116
|
+
this._buildUpdateDocumentMutationParams = async (field) => {
|
|
2117
|
+
const fields = await sequential(this.tinaSchema.getCollectionsByName(field.collections), async (collection) => {
|
|
2118
|
+
return astBuilder.InputValueDefinition({
|
|
2119
|
+
name: collection.name,
|
|
2120
|
+
type: NAMER.dataMutationTypeName([collection.name])
|
|
2121
|
+
});
|
|
2122
|
+
});
|
|
2123
|
+
fields.push(astBuilder.InputValueDefinition({
|
|
2124
|
+
name: "relativePath",
|
|
2125
|
+
type: astBuilder.TYPES.String
|
|
2126
|
+
}));
|
|
2127
|
+
return astBuilder.InputObjectTypeDefinition({
|
|
2128
|
+
name: NAMER.dataMutationUpdateTypeName(field.namespace),
|
|
2129
|
+
fields
|
|
2130
|
+
});
|
|
2131
|
+
};
|
|
2113
2132
|
this._buildObjectOrUnionData = async (collectableTemplate, extraFields = [], extraInterfaces = [], collection) => {
|
|
2114
2133
|
if (collectableTemplate.type === "union") {
|
|
2115
2134
|
const name2 = NAMER.dataTypeName(collectableTemplate.namespace);
|
|
@@ -2376,7 +2395,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
2376
2395
|
return typeof (x == null ? void 0 : x.match) === "undefined";
|
|
2377
2396
|
}).map((x) => x.path);
|
|
2378
2397
|
if (noMatchCollections.length !== new Set(noMatchCollections).size) {
|
|
2379
|
-
throw new Error("path must be unique
|
|
2398
|
+
throw new Error("path must be unique");
|
|
2380
2399
|
}
|
|
2381
2400
|
const hasMatchAndPath = collections.filter((x) => {
|
|
2382
2401
|
return typeof x.path !== "undefined" && typeof x.match !== "undefined";
|
|
@@ -2454,7 +2473,7 @@ var validateField = async (field) => {
|
|
|
2454
2473
|
|
|
2455
2474
|
// package.json
|
|
2456
2475
|
var name = "@tinacms/graphql";
|
|
2457
|
-
var version = "1.0
|
|
2476
|
+
var version = "1.1.0";
|
|
2458
2477
|
var main = "dist/index.js";
|
|
2459
2478
|
var typings = "dist/index.d.ts";
|
|
2460
2479
|
var files = [
|
|
@@ -2481,9 +2500,10 @@ var scripts = {
|
|
|
2481
2500
|
};
|
|
2482
2501
|
var dependencies = {
|
|
2483
2502
|
"@graphql-tools/relay-operation-optimizer": "^6.4.1",
|
|
2503
|
+
"@iarna/toml": "^2.2.5",
|
|
2484
2504
|
"@tinacms/datalayer": "workspace:*",
|
|
2485
|
-
"@tinacms/schema-tools": "workspace:*",
|
|
2486
2505
|
"@tinacms/mdx": "workspace:*",
|
|
2506
|
+
"@tinacms/schema-tools": "workspace:*",
|
|
2487
2507
|
"body-parser": "^1.19.0",
|
|
2488
2508
|
cors: "^2.8.5",
|
|
2489
2509
|
dataloader: "^2.0.0",
|
|
@@ -2498,7 +2518,7 @@ var dependencies = {
|
|
|
2498
2518
|
graphql: "15.8.0",
|
|
2499
2519
|
"graphql-type-json": "^0.3.2",
|
|
2500
2520
|
"gray-matter": "^4.0.2",
|
|
2501
|
-
"js-yaml": "^3.14.
|
|
2521
|
+
"js-yaml": "^3.14.1",
|
|
2502
2522
|
leveldown: "^6.1.0",
|
|
2503
2523
|
lodash: "^4.17.20",
|
|
2504
2524
|
mdast: "^3.0.0",
|
|
@@ -3143,7 +3163,8 @@ var Resolver = class {
|
|
|
3143
3163
|
isCreation,
|
|
3144
3164
|
isDeletion,
|
|
3145
3165
|
isAddPendingDocument,
|
|
3146
|
-
isCollectionSpecific
|
|
3166
|
+
isCollectionSpecific,
|
|
3167
|
+
isUpdateName
|
|
3147
3168
|
}) => {
|
|
3148
3169
|
let collectionLookup = collectionName || void 0;
|
|
3149
3170
|
if (!collectionLookup && isCollectionSpecific === false) {
|
|
@@ -3169,14 +3190,28 @@ var Resolver = class {
|
|
|
3169
3190
|
isAddPendingDocument
|
|
3170
3191
|
});
|
|
3171
3192
|
}
|
|
3172
|
-
if (
|
|
3173
|
-
if (
|
|
3193
|
+
if (!alreadyExists) {
|
|
3194
|
+
if (isDeletion) {
|
|
3174
3195
|
throw new Error(`Unable to delete document, ${realPath} does not exist`);
|
|
3175
3196
|
}
|
|
3197
|
+
if (isUpdateName) {
|
|
3198
|
+
throw new Error(`Unable to update document, ${realPath} does not exist`);
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
if (isDeletion) {
|
|
3176
3202
|
const doc = await this.getDocument(realPath);
|
|
3177
3203
|
await this.deleteDocument(realPath);
|
|
3178
3204
|
return doc;
|
|
3179
3205
|
}
|
|
3206
|
+
if (isUpdateName) {
|
|
3207
|
+
assertShape(args, (yup3) => yup3.object({ params: yup3.object().required() }));
|
|
3208
|
+
assertShape(args == null ? void 0 : args.params, (yup3) => yup3.object({ relativePath: yup3.string().required() }));
|
|
3209
|
+
const doc = await this.getDocument(realPath);
|
|
3210
|
+
const newRealPath = import_path2.default.join(collection == null ? void 0 : collection.path, args.params.relativePath);
|
|
3211
|
+
await this.database.put(newRealPath, doc._rawData, collection.name);
|
|
3212
|
+
await this.deleteDocument(realPath);
|
|
3213
|
+
return this.getDocument(newRealPath);
|
|
3214
|
+
}
|
|
3180
3215
|
if (alreadyExists === false) {
|
|
3181
3216
|
throw new Error(`Unable to update document, ${realPath} does not exist`);
|
|
3182
3217
|
}
|
|
@@ -3271,6 +3306,7 @@ var Resolver = class {
|
|
|
3271
3306
|
Object.entries(fieldParams).forEach(([fieldName, fieldValue]) => {
|
|
3272
3307
|
if (Array.isArray(fieldValue)) {
|
|
3273
3308
|
if (fieldValue.length === 0) {
|
|
3309
|
+
accum[fieldName] = [];
|
|
3274
3310
|
return;
|
|
3275
3311
|
}
|
|
3276
3312
|
}
|
|
@@ -3482,6 +3518,7 @@ var resolve = async ({
|
|
|
3482
3518
|
}
|
|
3483
3519
|
},
|
|
3484
3520
|
fieldResolver: async (source = {}, _args = {}, _context, info) => {
|
|
3521
|
+
var _a2;
|
|
3485
3522
|
try {
|
|
3486
3523
|
const args = JSON.parse(JSON.stringify(_args));
|
|
3487
3524
|
const returnType = (0, import_graphql4.getNamedType)(info.returnType).toString();
|
|
@@ -3495,8 +3532,8 @@ var resolve = async ({
|
|
|
3495
3532
|
if (info.fieldName === "collections") {
|
|
3496
3533
|
const collectionNode2 = info.fieldNodes.find((x) => x.name.value === "collections");
|
|
3497
3534
|
const hasDocuments2 = collectionNode2.selectionSet.selections.find((x) => {
|
|
3498
|
-
var
|
|
3499
|
-
return ((
|
|
3535
|
+
var _a3;
|
|
3536
|
+
return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
|
|
3500
3537
|
});
|
|
3501
3538
|
return tinaSchema.getCollections().map((collection) => {
|
|
3502
3539
|
return resolver.resolveCollection(args, collection.name, Boolean(hasDocuments2));
|
|
@@ -3504,8 +3541,8 @@ var resolve = async ({
|
|
|
3504
3541
|
}
|
|
3505
3542
|
const collectionNode = info.fieldNodes.find((x) => x.name.value === "collection");
|
|
3506
3543
|
const hasDocuments = collectionNode.selectionSet.selections.find((x) => {
|
|
3507
|
-
var
|
|
3508
|
-
return ((
|
|
3544
|
+
var _a3;
|
|
3545
|
+
return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
|
|
3509
3546
|
});
|
|
3510
3547
|
return resolver.resolveCollection(args, args.collection, Boolean(hasDocuments));
|
|
3511
3548
|
}
|
|
@@ -3554,6 +3591,7 @@ var resolve = async ({
|
|
|
3554
3591
|
isMutation,
|
|
3555
3592
|
isCreation,
|
|
3556
3593
|
isDeletion: info.fieldName === "deleteDocument",
|
|
3594
|
+
isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
|
|
3557
3595
|
isAddPendingDocument: false,
|
|
3558
3596
|
isCollectionSpecific: false
|
|
3559
3597
|
});
|
|
@@ -3650,46 +3688,67 @@ var import_path3 = __toModule(require("path"));
|
|
|
3650
3688
|
var import_graphql5 = __toModule(require("graphql"));
|
|
3651
3689
|
|
|
3652
3690
|
// src/database/util.ts
|
|
3691
|
+
var import_toml = __toModule(require("@iarna/toml"));
|
|
3692
|
+
var import_js_yaml = __toModule(require("js-yaml"));
|
|
3653
3693
|
var import_gray_matter = __toModule(require("gray-matter"));
|
|
3654
|
-
var
|
|
3694
|
+
var matterEngines = {
|
|
3695
|
+
toml: {
|
|
3696
|
+
parse: (val) => import_toml.default.parse(val),
|
|
3697
|
+
stringify: (val) => import_toml.default.stringify(val)
|
|
3698
|
+
}
|
|
3699
|
+
};
|
|
3700
|
+
var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
|
|
3701
|
+
const _a = content, {
|
|
3702
|
+
_relativePath,
|
|
3703
|
+
_keepTemplateKey,
|
|
3704
|
+
_id,
|
|
3705
|
+
_template,
|
|
3706
|
+
_collection,
|
|
3707
|
+
$_body
|
|
3708
|
+
} = _a, rest = __objRest(_a, [
|
|
3709
|
+
"_relativePath",
|
|
3710
|
+
"_keepTemplateKey",
|
|
3711
|
+
"_id",
|
|
3712
|
+
"_template",
|
|
3713
|
+
"_collection",
|
|
3714
|
+
"$_body"
|
|
3715
|
+
]);
|
|
3716
|
+
const extra = {};
|
|
3717
|
+
if (keepTemplateKey) {
|
|
3718
|
+
extra["_template"] = _template;
|
|
3719
|
+
}
|
|
3720
|
+
const strippedContent = __spreadValues(__spreadValues({}, rest), extra);
|
|
3655
3721
|
switch (format) {
|
|
3656
3722
|
case ".markdown":
|
|
3657
3723
|
case ".mdx":
|
|
3658
3724
|
case ".md":
|
|
3659
|
-
const _a = content, {
|
|
3660
|
-
_relativePath,
|
|
3661
|
-
_keepTemplateKey,
|
|
3662
|
-
_id,
|
|
3663
|
-
_template,
|
|
3664
|
-
_collection,
|
|
3665
|
-
$_body
|
|
3666
|
-
} = _a, rest = __objRest(_a, [
|
|
3667
|
-
"_relativePath",
|
|
3668
|
-
"_keepTemplateKey",
|
|
3669
|
-
"_id",
|
|
3670
|
-
"_template",
|
|
3671
|
-
"_collection",
|
|
3672
|
-
"$_body"
|
|
3673
|
-
]);
|
|
3674
|
-
const extra = {};
|
|
3675
|
-
if (keepTemplateKey) {
|
|
3676
|
-
extra["_template"] = _template;
|
|
3677
|
-
}
|
|
3678
3725
|
const ok = import_gray_matter.default.stringify(typeof $_body === "undefined" ? "" : `
|
|
3679
|
-
${$_body}`,
|
|
3726
|
+
${$_body}`, strippedContent, {
|
|
3727
|
+
language: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) || "yaml",
|
|
3728
|
+
engines: matterEngines,
|
|
3729
|
+
delimiters: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) || "---"
|
|
3730
|
+
});
|
|
3680
3731
|
return ok;
|
|
3681
3732
|
case ".json":
|
|
3682
|
-
return JSON.stringify(
|
|
3733
|
+
return JSON.stringify(strippedContent, null, 2);
|
|
3734
|
+
case ".yaml":
|
|
3735
|
+
return import_js_yaml.default.safeDump(strippedContent);
|
|
3736
|
+
case ".toml":
|
|
3737
|
+
return import_toml.default.stringify(strippedContent);
|
|
3683
3738
|
default:
|
|
3684
3739
|
throw new Error(`Must specify a valid format, got ${format}`);
|
|
3685
3740
|
}
|
|
3686
3741
|
};
|
|
3687
|
-
var parseFile = (content, format, yupSchema) => {
|
|
3742
|
+
var parseFile = (content, format, yupSchema, markdownParseConfig) => {
|
|
3688
3743
|
switch (format) {
|
|
3689
3744
|
case ".markdown":
|
|
3690
3745
|
case ".mdx":
|
|
3691
3746
|
case ".md":
|
|
3692
|
-
const contentJSON = (0, import_gray_matter.default)(content || ""
|
|
3747
|
+
const contentJSON = (0, import_gray_matter.default)(content || "", {
|
|
3748
|
+
language: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) || "yaml",
|
|
3749
|
+
delimiters: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) || "---",
|
|
3750
|
+
engines: matterEngines
|
|
3751
|
+
});
|
|
3693
3752
|
const markdownData = __spreadProps(__spreadValues({}, contentJSON.data), {
|
|
3694
3753
|
$_body: contentJSON.content
|
|
3695
3754
|
});
|
|
@@ -3700,6 +3759,16 @@ var parseFile = (content, format, yupSchema) => {
|
|
|
3700
3759
|
return {};
|
|
3701
3760
|
}
|
|
3702
3761
|
return JSON.parse(content);
|
|
3762
|
+
case ".toml":
|
|
3763
|
+
if (!content) {
|
|
3764
|
+
return {};
|
|
3765
|
+
}
|
|
3766
|
+
return import_toml.default.parse(content);
|
|
3767
|
+
case ".yaml":
|
|
3768
|
+
if (!content) {
|
|
3769
|
+
return {};
|
|
3770
|
+
}
|
|
3771
|
+
return import_js_yaml.default.safeLoad(content);
|
|
3703
3772
|
default:
|
|
3704
3773
|
throw new Error(`Must specify a valid format, got ${format}`);
|
|
3705
3774
|
}
|
|
@@ -3715,7 +3784,6 @@ var createDatabase = async (config) => {
|
|
|
3715
3784
|
}));
|
|
3716
3785
|
};
|
|
3717
3786
|
var SYSTEM_FILES = ["_schema", "_graphql", "_lookup"];
|
|
3718
|
-
var GENERATED_FOLDER = import_path3.default.join(".tina", "__generated__");
|
|
3719
3787
|
var defaultStatusCallback = () => Promise.resolve();
|
|
3720
3788
|
var Database = class {
|
|
3721
3789
|
constructor(config) {
|
|
@@ -3725,6 +3793,7 @@ var Database = class {
|
|
|
3725
3793
|
const collection = tinaSchema.getCollectionByFullPath(filepath);
|
|
3726
3794
|
return collection;
|
|
3727
3795
|
};
|
|
3796
|
+
this.getGeneratedFolder = () => import_path3.default.join(this.tinaDirectory, "__generated__");
|
|
3728
3797
|
this.get = async (filepath) => {
|
|
3729
3798
|
if (SYSTEM_FILES.includes(filepath)) {
|
|
3730
3799
|
throw new Error(`Unexpected get for config file ${filepath}`);
|
|
@@ -3850,7 +3919,10 @@ var Database = class {
|
|
|
3850
3919
|
payload = data;
|
|
3851
3920
|
}
|
|
3852
3921
|
const extension = import_path3.default.extname(filepath);
|
|
3853
|
-
const stringifiedFile = stringifyFile(payload, extension, templateInfo.type === "union"
|
|
3922
|
+
const stringifiedFile = stringifyFile(payload, extension, templateInfo.type === "union", {
|
|
3923
|
+
frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
|
|
3924
|
+
frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
|
|
3925
|
+
});
|
|
3854
3926
|
return {
|
|
3855
3927
|
stringifiedFile,
|
|
3856
3928
|
payload,
|
|
@@ -3864,7 +3936,7 @@ var Database = class {
|
|
|
3864
3936
|
return stringifiedFile;
|
|
3865
3937
|
};
|
|
3866
3938
|
this.getLookup = async (returnType) => {
|
|
3867
|
-
const lookupPath = import_path3.default.join(
|
|
3939
|
+
const lookupPath = import_path3.default.join(this.getGeneratedFolder(), `_lookup.json`);
|
|
3868
3940
|
if (!this._lookup) {
|
|
3869
3941
|
const _lookup = await this.store.get(normalizePath(lookupPath));
|
|
3870
3942
|
this._lookup = _lookup;
|
|
@@ -3872,16 +3944,16 @@ var Database = class {
|
|
|
3872
3944
|
return this._lookup[returnType];
|
|
3873
3945
|
};
|
|
3874
3946
|
this.getGraphQLSchema = async () => {
|
|
3875
|
-
const graphqlPath = import_path3.default.join(
|
|
3947
|
+
const graphqlPath = import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`);
|
|
3876
3948
|
return this.store.get(normalizePath(graphqlPath));
|
|
3877
3949
|
};
|
|
3878
3950
|
this.getGraphQLSchemaFromBridge = async () => {
|
|
3879
|
-
const graphqlPath = import_path3.default.join(
|
|
3951
|
+
const graphqlPath = import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`);
|
|
3880
3952
|
const _graphql = await this.bridge.get(normalizePath(graphqlPath));
|
|
3881
3953
|
return JSON.parse(_graphql);
|
|
3882
3954
|
};
|
|
3883
3955
|
this.getTinaSchema = async () => {
|
|
3884
|
-
const schemaPath = import_path3.default.join(
|
|
3956
|
+
const schemaPath = import_path3.default.join(this.getGeneratedFolder(), `_schema.json`);
|
|
3885
3957
|
return this.store.get(normalizePath(schemaPath));
|
|
3886
3958
|
};
|
|
3887
3959
|
this.getSchema = async () => {
|
|
@@ -3990,7 +4062,7 @@ var Database = class {
|
|
|
3990
4062
|
cursor: (0, import_datalayer2.btoa)(edge.cursor)
|
|
3991
4063
|
};
|
|
3992
4064
|
} catch (error) {
|
|
3993
|
-
if (error instanceof Error && !edge.path.includes(".tina/__generated__/_graphql.json")) {
|
|
4065
|
+
if (error instanceof Error && (!edge.path.includes(".tina/__generated__/_graphql.json") || !edge.path.includes("tina/__generated__/_graphql.json"))) {
|
|
3994
4066
|
throw new TinaQueryError({
|
|
3995
4067
|
originalError: error,
|
|
3996
4068
|
file: edge.path,
|
|
@@ -4015,21 +4087,22 @@ var Database = class {
|
|
|
4015
4087
|
tinaSchema
|
|
4016
4088
|
}) => {
|
|
4017
4089
|
if (this.bridge.supportsBuilding()) {
|
|
4018
|
-
await this.bridge.putConfig(normalizePath(import_path3.default.join(
|
|
4019
|
-
await this.bridge.putConfig(normalizePath(import_path3.default.join(
|
|
4090
|
+
await this.bridge.putConfig(normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)), JSON.stringify(graphQLSchema));
|
|
4091
|
+
await this.bridge.putConfig(normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_schema.json`)), JSON.stringify(tinaSchema.schema));
|
|
4020
4092
|
}
|
|
4021
4093
|
};
|
|
4022
4094
|
this.indexContent = async ({
|
|
4023
4095
|
graphQLSchema,
|
|
4024
|
-
tinaSchema
|
|
4096
|
+
tinaSchema,
|
|
4097
|
+
lookup: lookupFromLockFile
|
|
4025
4098
|
}) => {
|
|
4026
4099
|
await this.indexStatusCallbackWrapper(async () => {
|
|
4027
|
-
const lookup = JSON.parse(await this.bridge.get(normalizePath(import_path3.default.join(
|
|
4100
|
+
const lookup = lookupFromLockFile || JSON.parse(await this.bridge.get(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_lookup.json"))));
|
|
4028
4101
|
if (this.store.supportsSeeding()) {
|
|
4029
4102
|
await this.store.clear();
|
|
4030
|
-
await this.store.seed(normalizePath(import_path3.default.join(
|
|
4031
|
-
await this.store.seed(normalizePath(import_path3.default.join(
|
|
4032
|
-
await this.store.seed(normalizePath(import_path3.default.join(
|
|
4103
|
+
await this.store.seed(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_graphql.json")), graphQLSchema);
|
|
4104
|
+
await this.store.seed(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_schema.json")), tinaSchema.schema);
|
|
4105
|
+
await this.store.seed(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_lookup.json")), lookup);
|
|
4033
4106
|
await this._indexAllContent();
|
|
4034
4107
|
} else {
|
|
4035
4108
|
if (this.store.supportsIndexing()) {
|
|
@@ -4077,7 +4150,7 @@ var Database = class {
|
|
|
4077
4150
|
});
|
|
4078
4151
|
};
|
|
4079
4152
|
this.addToLookupMap = async (lookup) => {
|
|
4080
|
-
const lookupPath = import_path3.default.join(
|
|
4153
|
+
const lookupPath = import_path3.default.join(this.getGeneratedFolder(), `_lookup.json`);
|
|
4081
4154
|
let lookupMap;
|
|
4082
4155
|
try {
|
|
4083
4156
|
lookupMap = JSON.parse(await this.bridge.get(normalizePath(lookupPath)));
|
|
@@ -4089,6 +4162,7 @@ var Database = class {
|
|
|
4089
4162
|
});
|
|
4090
4163
|
await this.bridge.putConfig(normalizePath(lookupPath), JSON.stringify(updatedLookup));
|
|
4091
4164
|
};
|
|
4165
|
+
this.tinaDirectory = config.tinaDirectory || ".tina";
|
|
4092
4166
|
this.bridge = config.bridge;
|
|
4093
4167
|
this.store = config.store;
|
|
4094
4168
|
this.indexStatusCallback = config.indexStatusCallback || defaultStatusCallback;
|
|
@@ -4149,7 +4223,10 @@ var _indexContent = async (database, documentPaths, collection) => {
|
|
|
4149
4223
|
await sequential(documentPaths, async (filepath) => {
|
|
4150
4224
|
try {
|
|
4151
4225
|
const dataString = await database.bridge.get(normalizePath(filepath));
|
|
4152
|
-
const data = parseFile(dataString, import_path3.default.extname(filepath), (yup3) => yup3.object({})
|
|
4226
|
+
const data = parseFile(dataString, import_path3.default.extname(filepath), (yup3) => yup3.object({}), {
|
|
4227
|
+
frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
|
|
4228
|
+
frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
|
|
4229
|
+
});
|
|
4153
4230
|
if (database.store.supportsSeeding()) {
|
|
4154
4231
|
await database.store.seed(normalizePath(filepath), data, seedOptions);
|
|
4155
4232
|
}
|
package/dist/resolver/index.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export declare class Resolver {
|
|
|
42
42
|
defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
|
|
43
43
|
indexes?: import("@tinacms/schema-tools").TinaIndex[];
|
|
44
44
|
format?: "json" | "md" | "markdown" | "mdx";
|
|
45
|
+
frontmatterFormat?: "json" | "yaml" | "toml";
|
|
46
|
+
frontmatterDelimiters?: string | [string, string];
|
|
45
47
|
ui?: import("@tinacms/schema-tools").UICollection;
|
|
46
48
|
match?: string;
|
|
47
49
|
documents: {
|
|
@@ -65,6 +67,8 @@ export declare class Resolver {
|
|
|
65
67
|
defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
|
|
66
68
|
indexes?: import("@tinacms/schema-tools").TinaIndex[];
|
|
67
69
|
format?: "json" | "md" | "markdown" | "mdx";
|
|
70
|
+
frontmatterFormat?: "json" | "yaml" | "toml";
|
|
71
|
+
frontmatterDelimiters?: string | [string, string];
|
|
68
72
|
ui?: import("@tinacms/schema-tools").UICollection;
|
|
69
73
|
match?: string;
|
|
70
74
|
documents: {
|
|
@@ -164,7 +168,7 @@ export declare class Resolver {
|
|
|
164
168
|
__typename: string;
|
|
165
169
|
id: string;
|
|
166
170
|
}>;
|
|
167
|
-
resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isAddPendingDocument, isCollectionSpecific, }: {
|
|
171
|
+
resolveDocument: ({ args, collection: collectionName, isMutation, isCreation, isDeletion, isAddPendingDocument, isCollectionSpecific, isUpdateName, }: {
|
|
168
172
|
args: unknown;
|
|
169
173
|
collection?: string;
|
|
170
174
|
isMutation: boolean;
|
|
@@ -172,6 +176,7 @@ export declare class Resolver {
|
|
|
172
176
|
isDeletion?: boolean;
|
|
173
177
|
isAddPendingDocument?: boolean;
|
|
174
178
|
isCollectionSpecific?: boolean;
|
|
179
|
+
isUpdateName?: boolean;
|
|
175
180
|
}) => Promise<{
|
|
176
181
|
_sys: {
|
|
177
182
|
title: any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinacms/graphql",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -19,9 +19,10 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@graphql-tools/relay-operation-optimizer": "^6.4.1",
|
|
22
|
-
"@
|
|
23
|
-
"@tinacms/
|
|
24
|
-
"@tinacms/mdx": "1.
|
|
22
|
+
"@iarna/toml": "^2.2.5",
|
|
23
|
+
"@tinacms/datalayer": "1.0.1",
|
|
24
|
+
"@tinacms/mdx": "1.1.1",
|
|
25
|
+
"@tinacms/schema-tools": "1.2.1",
|
|
25
26
|
"body-parser": "^1.19.0",
|
|
26
27
|
"cors": "^2.8.5",
|
|
27
28
|
"dataloader": "^2.0.0",
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
"graphql": "15.8.0",
|
|
37
38
|
"graphql-type-json": "^0.3.2",
|
|
38
39
|
"gray-matter": "^4.0.2",
|
|
39
|
-
"js-yaml": "^3.14.
|
|
40
|
+
"js-yaml": "^3.14.1",
|
|
40
41
|
"leveldown": "^6.1.0",
|
|
41
42
|
"lodash": "^4.17.20",
|
|
42
43
|
"mdast": "^3.0.0",
|
|
@@ -71,9 +72,9 @@
|
|
|
71
72
|
"directory": "packages/tina-graphql"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
|
-
"@tinacms/datalayer": "1.0.
|
|
75
|
-
"@tinacms/schema-tools": "1.1
|
|
76
|
-
"@tinacms/scripts": "1.0.
|
|
75
|
+
"@tinacms/datalayer": "1.0.1",
|
|
76
|
+
"@tinacms/schema-tools": "1.2.1",
|
|
77
|
+
"@tinacms/scripts": "1.0.1",
|
|
77
78
|
"@types/cors": "^2.8.7",
|
|
78
79
|
"@types/estree": "^0.0.50",
|
|
79
80
|
"@types/express": "^4.17.8",
|