@tinacms/graphql 1.4.13 → 1.4.15
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/dist/database/datalayer.d.ts +1 -1
- package/dist/database/index.d.ts +3 -3
- package/dist/index.es.js +36 -17
- package/dist/index.js +36 -17
- package/package.json +1 -1
|
@@ -70,7 +70,7 @@ export declare class FolderTreeBuilder {
|
|
|
70
70
|
update(documentPath: string, collectionPath: string): any;
|
|
71
71
|
}
|
|
72
72
|
export declare const makeFolderOpsForCollection: <T extends object>(folderTree: FolderTree, collection: Collection<true>, indexDefinitions: IndexDefinition[], opType: 'put' | 'del', level: Level, escapeStr?: StringEscaper) => BatchOp[];
|
|
73
|
-
export declare const makeIndexOpsForDocument: <T extends object>(filepath: string, collection: string | undefined, indexDefinitions:
|
|
73
|
+
export declare const makeIndexOpsForDocument: <T extends object>(filepath: string, collection: string | undefined, indexDefinitions: Record<string, IndexDefinition>, data: T, opType: 'put' | 'del', level: Level, escapeStr?: StringEscaper) => BatchOp[];
|
|
74
74
|
export declare const makeStringEscaper: (regex: RegExp, replacement: string) => StringEscaper;
|
|
75
75
|
export declare const stringEscaper: StringEscaper;
|
|
76
76
|
export {};
|
package/dist/database/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocumentNode } from 'graphql';
|
|
2
|
-
import type { CollectionTemplateable, Schema,
|
|
2
|
+
import type { Collection, CollectionTemplateable, Schema, TinaSchema } from '@tinacms/schema-tools';
|
|
3
3
|
import type { Bridge } from './bridge';
|
|
4
4
|
import { BinaryFilter, IndexDefinition, TernaryFilter } from './datalayer';
|
|
5
5
|
import { Level } from './level';
|
|
@@ -58,7 +58,7 @@ export declare class Database {
|
|
|
58
58
|
put: (filepath: string, data: {
|
|
59
59
|
[key: string]: unknown;
|
|
60
60
|
}, collectionName?: string) => Promise<boolean>;
|
|
61
|
-
getTemplateDetailsForFile(collection:
|
|
61
|
+
getTemplateDetailsForFile(collection: Collection<true>, data: {
|
|
62
62
|
[key: string]: unknown;
|
|
63
63
|
}): Promise<{
|
|
64
64
|
template: {
|
|
@@ -84,7 +84,7 @@ export declare class Database {
|
|
|
84
84
|
}>;
|
|
85
85
|
stringifyFile: (filepath: string, payload: {
|
|
86
86
|
[key: string]: unknown;
|
|
87
|
-
}, collection:
|
|
87
|
+
}, collection: Collection<true>) => Promise<string>;
|
|
88
88
|
/**
|
|
89
89
|
* Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
|
|
90
90
|
*/
|
package/dist/index.es.js
CHANGED
|
@@ -2525,7 +2525,7 @@ var validateField = async (field) => {
|
|
|
2525
2525
|
// package.json
|
|
2526
2526
|
var package_default = {
|
|
2527
2527
|
name: "@tinacms/graphql",
|
|
2528
|
-
version: "1.4.
|
|
2528
|
+
version: "1.4.15",
|
|
2529
2529
|
main: "dist/index.js",
|
|
2530
2530
|
module: "dist/index.es.js",
|
|
2531
2531
|
typings: "dist/index.d.ts",
|
|
@@ -4352,6 +4352,8 @@ var Resolver = class {
|
|
|
4352
4352
|
case "string":
|
|
4353
4353
|
case "boolean":
|
|
4354
4354
|
case "number":
|
|
4355
|
+
accumulator[field.name] = value;
|
|
4356
|
+
break;
|
|
4355
4357
|
case "reference":
|
|
4356
4358
|
if (value) {
|
|
4357
4359
|
accumulator[field.name] = value;
|
|
@@ -4519,6 +4521,9 @@ var resolve = async ({
|
|
|
4519
4521
|
try {
|
|
4520
4522
|
const verboseValue = verbose ?? true;
|
|
4521
4523
|
const graphQLSchemaAst = await database.getGraphQLSchema();
|
|
4524
|
+
if (!graphQLSchemaAst) {
|
|
4525
|
+
throw new GraphQLError3(`GraphQL schema not found`);
|
|
4526
|
+
}
|
|
4522
4527
|
const graphQLSchema = buildASTSchema(graphQLSchemaAst);
|
|
4523
4528
|
const tinaConfig = await database.getTinaSchema();
|
|
4524
4529
|
const tinaSchema = await createSchema({
|
|
@@ -4881,7 +4886,10 @@ var Database = class {
|
|
|
4881
4886
|
this.config = config;
|
|
4882
4887
|
this.collectionForPath = async (filepath) => {
|
|
4883
4888
|
const tinaSchema = await this.getSchema(this.level);
|
|
4884
|
-
|
|
4889
|
+
try {
|
|
4890
|
+
return tinaSchema.getCollectionByFullPath(filepath);
|
|
4891
|
+
} catch (e) {
|
|
4892
|
+
}
|
|
4885
4893
|
};
|
|
4886
4894
|
this.getGeneratedFolder = () => path3.join(this.tinaDirectory, "__generated__");
|
|
4887
4895
|
this.get = async (filepath) => {
|
|
@@ -4938,16 +4946,16 @@ var Database = class {
|
|
|
4938
4946
|
await this.initLevel();
|
|
4939
4947
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
4940
4948
|
const collection = await this.collectionForPath(filepath);
|
|
4949
|
+
if (!collection) {
|
|
4950
|
+
throw new GraphQLError4(`Unable to find collection for ${filepath}`);
|
|
4951
|
+
}
|
|
4941
4952
|
const stringifiedFile = await this.stringifyFile(
|
|
4942
4953
|
filepath,
|
|
4943
4954
|
dataFields,
|
|
4944
4955
|
collection
|
|
4945
4956
|
);
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
4949
|
-
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
4950
|
-
}
|
|
4957
|
+
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
4958
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
4951
4959
|
const normalizedPath = normalizePath(filepath);
|
|
4952
4960
|
if (this.bridge) {
|
|
4953
4961
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
@@ -5024,6 +5032,9 @@ var Database = class {
|
|
|
5024
5032
|
const normalizedPath = normalizePath(filepath);
|
|
5025
5033
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5026
5034
|
const collection = await this.collectionForPath(filepath);
|
|
5035
|
+
if (!collection) {
|
|
5036
|
+
throw new GraphQLError4(`Unable to find collection for ${filepath}.`);
|
|
5037
|
+
}
|
|
5027
5038
|
if (collection.match?.exclude || collection.match?.include) {
|
|
5028
5039
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
5029
5040
|
const match = micromatch.isMatch(filepath, matches);
|
|
@@ -5115,8 +5126,10 @@ var Database = class {
|
|
|
5115
5126
|
}
|
|
5116
5127
|
};
|
|
5117
5128
|
this.formatBodyOnPayload = async (filepath, data) => {
|
|
5118
|
-
const
|
|
5119
|
-
|
|
5129
|
+
const collection = await this.collectionForPath(filepath);
|
|
5130
|
+
if (!collection) {
|
|
5131
|
+
throw new Error(`Unable to find collection for path ${filepath}`);
|
|
5132
|
+
}
|
|
5120
5133
|
const { template } = await this.getTemplateDetailsForFile(collection, data);
|
|
5121
5134
|
const bodyField = template.fields.find((field) => {
|
|
5122
5135
|
if (field.type === "string" || field.type === "rich-text") {
|
|
@@ -5162,6 +5175,9 @@ var Database = class {
|
|
|
5162
5175
|
const data = await this.get(filepath);
|
|
5163
5176
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5164
5177
|
const collection = await this.collectionForPath(filepath);
|
|
5178
|
+
if (!collection) {
|
|
5179
|
+
throw new Error(`Unable to find collection for path ${filepath}`);
|
|
5180
|
+
}
|
|
5165
5181
|
const stringifiedFile = await this.stringifyFile(
|
|
5166
5182
|
filepath,
|
|
5167
5183
|
dataFields,
|
|
@@ -5546,11 +5562,11 @@ var Database = class {
|
|
|
5546
5562
|
this.delete = async (filepath) => {
|
|
5547
5563
|
await this.initLevel();
|
|
5548
5564
|
const collection = await this.collectionForPath(filepath);
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5552
|
-
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
5565
|
+
if (!collection) {
|
|
5566
|
+
throw new Error(`No collection found for path: ${filepath}`);
|
|
5553
5567
|
}
|
|
5568
|
+
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5569
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
5554
5570
|
this.level.sublevel(
|
|
5555
5571
|
CONTENT_ROOT_PREFIX,
|
|
5556
5572
|
SUBLEVEL_OPTIONS
|
|
@@ -5683,7 +5699,10 @@ This will be an error in the future. See https://tina.io/docs/errors/file-in-mut
|
|
|
5683
5699
|
let version = await this.getDatabaseVersion();
|
|
5684
5700
|
if (!version) {
|
|
5685
5701
|
version = "";
|
|
5686
|
-
|
|
5702
|
+
try {
|
|
5703
|
+
await this.updateDatabaseVersion(version);
|
|
5704
|
+
} catch (e) {
|
|
5705
|
+
}
|
|
5687
5706
|
}
|
|
5688
5707
|
this.level = this.rootLevel.sublevel(version, SUBLEVEL_OPTIONS);
|
|
5689
5708
|
}
|
|
@@ -5812,7 +5831,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5812
5831
|
throw new TinaFetchError(`Unable to seed ${filepath}`, {
|
|
5813
5832
|
originalError: error,
|
|
5814
5833
|
file: filepath,
|
|
5815
|
-
collection: collection
|
|
5834
|
+
collection: collection?.name,
|
|
5816
5835
|
stack: error.stack
|
|
5817
5836
|
});
|
|
5818
5837
|
}
|
|
@@ -5897,10 +5916,10 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
5897
5916
|
}
|
|
5898
5917
|
};
|
|
5899
5918
|
var getTemplateForFile = (templateInfo, data) => {
|
|
5900
|
-
if (templateInfo
|
|
5919
|
+
if (templateInfo?.type === "object") {
|
|
5901
5920
|
return templateInfo.template;
|
|
5902
5921
|
}
|
|
5903
|
-
if (templateInfo
|
|
5922
|
+
if (templateInfo?.type === "union") {
|
|
5904
5923
|
if (hasOwnProperty(data, "_template")) {
|
|
5905
5924
|
const template = templateInfo.templates.find(
|
|
5906
5925
|
(t) => lastItem(t.namespace) === data._template
|
package/dist/index.js
CHANGED
|
@@ -2577,7 +2577,7 @@ var validateField = async (field) => {
|
|
|
2577
2577
|
// package.json
|
|
2578
2578
|
var package_default = {
|
|
2579
2579
|
name: "@tinacms/graphql",
|
|
2580
|
-
version: "1.4.
|
|
2580
|
+
version: "1.4.15",
|
|
2581
2581
|
main: "dist/index.js",
|
|
2582
2582
|
module: "dist/index.es.js",
|
|
2583
2583
|
typings: "dist/index.d.ts",
|
|
@@ -4402,6 +4402,8 @@ var Resolver = class {
|
|
|
4402
4402
|
case "string":
|
|
4403
4403
|
case "boolean":
|
|
4404
4404
|
case "number":
|
|
4405
|
+
accumulator[field.name] = value;
|
|
4406
|
+
break;
|
|
4405
4407
|
case "reference":
|
|
4406
4408
|
if (value) {
|
|
4407
4409
|
accumulator[field.name] = value;
|
|
@@ -4570,6 +4572,9 @@ var resolve = async ({
|
|
|
4570
4572
|
try {
|
|
4571
4573
|
const verboseValue = verbose != null ? verbose : true;
|
|
4572
4574
|
const graphQLSchemaAst = await database.getGraphQLSchema();
|
|
4575
|
+
if (!graphQLSchemaAst) {
|
|
4576
|
+
throw new import_graphql4.GraphQLError(`GraphQL schema not found`);
|
|
4577
|
+
}
|
|
4573
4578
|
const graphQLSchema = (0, import_graphql4.buildASTSchema)(graphQLSchemaAst);
|
|
4574
4579
|
const tinaConfig = await database.getTinaSchema();
|
|
4575
4580
|
const tinaSchema = await createSchema({
|
|
@@ -4937,7 +4942,10 @@ var Database = class {
|
|
|
4937
4942
|
this.config = config;
|
|
4938
4943
|
this.collectionForPath = async (filepath) => {
|
|
4939
4944
|
const tinaSchema = await this.getSchema(this.level);
|
|
4940
|
-
|
|
4945
|
+
try {
|
|
4946
|
+
return tinaSchema.getCollectionByFullPath(filepath);
|
|
4947
|
+
} catch (e) {
|
|
4948
|
+
}
|
|
4941
4949
|
};
|
|
4942
4950
|
this.getGeneratedFolder = () => import_path3.default.join(this.tinaDirectory, "__generated__");
|
|
4943
4951
|
this.get = async (filepath) => {
|
|
@@ -4994,16 +5002,16 @@ var Database = class {
|
|
|
4994
5002
|
await this.initLevel();
|
|
4995
5003
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
4996
5004
|
const collection = await this.collectionForPath(filepath);
|
|
5005
|
+
if (!collection) {
|
|
5006
|
+
throw new import_graphql5.GraphQLError(`Unable to find collection for ${filepath}`);
|
|
5007
|
+
}
|
|
4997
5008
|
const stringifiedFile = await this.stringifyFile(
|
|
4998
5009
|
filepath,
|
|
4999
5010
|
dataFields,
|
|
5000
5011
|
collection
|
|
5001
5012
|
);
|
|
5002
|
-
|
|
5003
|
-
|
|
5004
|
-
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5005
|
-
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5006
|
-
}
|
|
5013
|
+
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5014
|
+
const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5007
5015
|
const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
|
|
5008
5016
|
if (this.bridge) {
|
|
5009
5017
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
@@ -5081,6 +5089,9 @@ var Database = class {
|
|
|
5081
5089
|
const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
|
|
5082
5090
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5083
5091
|
const collection = await this.collectionForPath(filepath);
|
|
5092
|
+
if (!collection) {
|
|
5093
|
+
throw new import_graphql5.GraphQLError(`Unable to find collection for ${filepath}.`);
|
|
5094
|
+
}
|
|
5084
5095
|
if (((_a = collection.match) == null ? void 0 : _a.exclude) || ((_b = collection.match) == null ? void 0 : _b.include)) {
|
|
5085
5096
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
5086
5097
|
const match = import_micromatch.default.isMatch(filepath, matches);
|
|
@@ -5172,8 +5183,10 @@ var Database = class {
|
|
|
5172
5183
|
}
|
|
5173
5184
|
};
|
|
5174
5185
|
this.formatBodyOnPayload = async (filepath, data) => {
|
|
5175
|
-
const
|
|
5176
|
-
|
|
5186
|
+
const collection = await this.collectionForPath(filepath);
|
|
5187
|
+
if (!collection) {
|
|
5188
|
+
throw new Error(`Unable to find collection for path ${filepath}`);
|
|
5189
|
+
}
|
|
5177
5190
|
const { template } = await this.getTemplateDetailsForFile(collection, data);
|
|
5178
5191
|
const bodyField = template.fields.find((field) => {
|
|
5179
5192
|
if (field.type === "string" || field.type === "rich-text") {
|
|
@@ -5219,6 +5232,9 @@ var Database = class {
|
|
|
5219
5232
|
const data = await this.get(filepath);
|
|
5220
5233
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5221
5234
|
const collection = await this.collectionForPath(filepath);
|
|
5235
|
+
if (!collection) {
|
|
5236
|
+
throw new Error(`Unable to find collection for path ${filepath}`);
|
|
5237
|
+
}
|
|
5222
5238
|
const stringifiedFile = await this.stringifyFile(
|
|
5223
5239
|
filepath,
|
|
5224
5240
|
dataFields,
|
|
@@ -5604,11 +5620,11 @@ var Database = class {
|
|
|
5604
5620
|
this.delete = async (filepath) => {
|
|
5605
5621
|
await this.initLevel();
|
|
5606
5622
|
const collection = await this.collectionForPath(filepath);
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5610
|
-
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5623
|
+
if (!collection) {
|
|
5624
|
+
throw new Error(`No collection found for path: ${filepath}`);
|
|
5611
5625
|
}
|
|
5626
|
+
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5627
|
+
const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5612
5628
|
this.level.sublevel(
|
|
5613
5629
|
CONTENT_ROOT_PREFIX,
|
|
5614
5630
|
SUBLEVEL_OPTIONS
|
|
@@ -5741,7 +5757,10 @@ This will be an error in the future. See https://tina.io/docs/errors/file-in-mut
|
|
|
5741
5757
|
let version = await this.getDatabaseVersion();
|
|
5742
5758
|
if (!version) {
|
|
5743
5759
|
version = "";
|
|
5744
|
-
|
|
5760
|
+
try {
|
|
5761
|
+
await this.updateDatabaseVersion(version);
|
|
5762
|
+
} catch (e) {
|
|
5763
|
+
}
|
|
5745
5764
|
}
|
|
5746
5765
|
this.level = this.rootLevel.sublevel(version, SUBLEVEL_OPTIONS);
|
|
5747
5766
|
}
|
|
@@ -5870,7 +5889,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5870
5889
|
throw new TinaFetchError(`Unable to seed ${filepath}`, {
|
|
5871
5890
|
originalError: error,
|
|
5872
5891
|
file: filepath,
|
|
5873
|
-
collection: collection.name,
|
|
5892
|
+
collection: collection == null ? void 0 : collection.name,
|
|
5874
5893
|
stack: error.stack
|
|
5875
5894
|
});
|
|
5876
5895
|
}
|
|
@@ -5955,10 +5974,10 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
5955
5974
|
}
|
|
5956
5975
|
};
|
|
5957
5976
|
var getTemplateForFile = (templateInfo, data) => {
|
|
5958
|
-
if (templateInfo.type === "object") {
|
|
5977
|
+
if ((templateInfo == null ? void 0 : templateInfo.type) === "object") {
|
|
5959
5978
|
return templateInfo.template;
|
|
5960
5979
|
}
|
|
5961
|
-
if (templateInfo.type === "union") {
|
|
5980
|
+
if ((templateInfo == null ? void 0 : templateInfo.type) === "union") {
|
|
5962
5981
|
if (hasOwnProperty(data, "_template")) {
|
|
5963
5982
|
const template = templateInfo.templates.find(
|
|
5964
5983
|
(t) => lastItem(t.namespace) === data._template
|