@tinacms/graphql 1.4.14 → 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 +34 -17
- package/dist/index.js +34 -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",
|
|
@@ -4521,6 +4521,9 @@ var resolve = async ({
|
|
|
4521
4521
|
try {
|
|
4522
4522
|
const verboseValue = verbose ?? true;
|
|
4523
4523
|
const graphQLSchemaAst = await database.getGraphQLSchema();
|
|
4524
|
+
if (!graphQLSchemaAst) {
|
|
4525
|
+
throw new GraphQLError3(`GraphQL schema not found`);
|
|
4526
|
+
}
|
|
4524
4527
|
const graphQLSchema = buildASTSchema(graphQLSchemaAst);
|
|
4525
4528
|
const tinaConfig = await database.getTinaSchema();
|
|
4526
4529
|
const tinaSchema = await createSchema({
|
|
@@ -4883,7 +4886,10 @@ var Database = class {
|
|
|
4883
4886
|
this.config = config;
|
|
4884
4887
|
this.collectionForPath = async (filepath) => {
|
|
4885
4888
|
const tinaSchema = await this.getSchema(this.level);
|
|
4886
|
-
|
|
4889
|
+
try {
|
|
4890
|
+
return tinaSchema.getCollectionByFullPath(filepath);
|
|
4891
|
+
} catch (e) {
|
|
4892
|
+
}
|
|
4887
4893
|
};
|
|
4888
4894
|
this.getGeneratedFolder = () => path3.join(this.tinaDirectory, "__generated__");
|
|
4889
4895
|
this.get = async (filepath) => {
|
|
@@ -4940,16 +4946,16 @@ var Database = class {
|
|
|
4940
4946
|
await this.initLevel();
|
|
4941
4947
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
4942
4948
|
const collection = await this.collectionForPath(filepath);
|
|
4949
|
+
if (!collection) {
|
|
4950
|
+
throw new GraphQLError4(`Unable to find collection for ${filepath}`);
|
|
4951
|
+
}
|
|
4943
4952
|
const stringifiedFile = await this.stringifyFile(
|
|
4944
4953
|
filepath,
|
|
4945
4954
|
dataFields,
|
|
4946
4955
|
collection
|
|
4947
4956
|
);
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
4951
|
-
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
4952
|
-
}
|
|
4957
|
+
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
4958
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
4953
4959
|
const normalizedPath = normalizePath(filepath);
|
|
4954
4960
|
if (this.bridge) {
|
|
4955
4961
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
@@ -5026,6 +5032,9 @@ var Database = class {
|
|
|
5026
5032
|
const normalizedPath = normalizePath(filepath);
|
|
5027
5033
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5028
5034
|
const collection = await this.collectionForPath(filepath);
|
|
5035
|
+
if (!collection) {
|
|
5036
|
+
throw new GraphQLError4(`Unable to find collection for ${filepath}.`);
|
|
5037
|
+
}
|
|
5029
5038
|
if (collection.match?.exclude || collection.match?.include) {
|
|
5030
5039
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
5031
5040
|
const match = micromatch.isMatch(filepath, matches);
|
|
@@ -5117,8 +5126,10 @@ var Database = class {
|
|
|
5117
5126
|
}
|
|
5118
5127
|
};
|
|
5119
5128
|
this.formatBodyOnPayload = async (filepath, data) => {
|
|
5120
|
-
const
|
|
5121
|
-
|
|
5129
|
+
const collection = await this.collectionForPath(filepath);
|
|
5130
|
+
if (!collection) {
|
|
5131
|
+
throw new Error(`Unable to find collection for path ${filepath}`);
|
|
5132
|
+
}
|
|
5122
5133
|
const { template } = await this.getTemplateDetailsForFile(collection, data);
|
|
5123
5134
|
const bodyField = template.fields.find((field) => {
|
|
5124
5135
|
if (field.type === "string" || field.type === "rich-text") {
|
|
@@ -5164,6 +5175,9 @@ var Database = class {
|
|
|
5164
5175
|
const data = await this.get(filepath);
|
|
5165
5176
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5166
5177
|
const collection = await this.collectionForPath(filepath);
|
|
5178
|
+
if (!collection) {
|
|
5179
|
+
throw new Error(`Unable to find collection for path ${filepath}`);
|
|
5180
|
+
}
|
|
5167
5181
|
const stringifiedFile = await this.stringifyFile(
|
|
5168
5182
|
filepath,
|
|
5169
5183
|
dataFields,
|
|
@@ -5548,11 +5562,11 @@ var Database = class {
|
|
|
5548
5562
|
this.delete = async (filepath) => {
|
|
5549
5563
|
await this.initLevel();
|
|
5550
5564
|
const collection = await this.collectionForPath(filepath);
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5554
|
-
collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
5565
|
+
if (!collection) {
|
|
5566
|
+
throw new Error(`No collection found for path: ${filepath}`);
|
|
5555
5567
|
}
|
|
5568
|
+
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5569
|
+
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
5556
5570
|
this.level.sublevel(
|
|
5557
5571
|
CONTENT_ROOT_PREFIX,
|
|
5558
5572
|
SUBLEVEL_OPTIONS
|
|
@@ -5685,7 +5699,10 @@ This will be an error in the future. See https://tina.io/docs/errors/file-in-mut
|
|
|
5685
5699
|
let version = await this.getDatabaseVersion();
|
|
5686
5700
|
if (!version) {
|
|
5687
5701
|
version = "";
|
|
5688
|
-
|
|
5702
|
+
try {
|
|
5703
|
+
await this.updateDatabaseVersion(version);
|
|
5704
|
+
} catch (e) {
|
|
5705
|
+
}
|
|
5689
5706
|
}
|
|
5690
5707
|
this.level = this.rootLevel.sublevel(version, SUBLEVEL_OPTIONS);
|
|
5691
5708
|
}
|
|
@@ -5814,7 +5831,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5814
5831
|
throw new TinaFetchError(`Unable to seed ${filepath}`, {
|
|
5815
5832
|
originalError: error,
|
|
5816
5833
|
file: filepath,
|
|
5817
|
-
collection: collection
|
|
5834
|
+
collection: collection?.name,
|
|
5818
5835
|
stack: error.stack
|
|
5819
5836
|
});
|
|
5820
5837
|
}
|
|
@@ -5899,10 +5916,10 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
5899
5916
|
}
|
|
5900
5917
|
};
|
|
5901
5918
|
var getTemplateForFile = (templateInfo, data) => {
|
|
5902
|
-
if (templateInfo
|
|
5919
|
+
if (templateInfo?.type === "object") {
|
|
5903
5920
|
return templateInfo.template;
|
|
5904
5921
|
}
|
|
5905
|
-
if (templateInfo
|
|
5922
|
+
if (templateInfo?.type === "union") {
|
|
5906
5923
|
if (hasOwnProperty(data, "_template")) {
|
|
5907
5924
|
const template = templateInfo.templates.find(
|
|
5908
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",
|
|
@@ -4572,6 +4572,9 @@ var resolve = async ({
|
|
|
4572
4572
|
try {
|
|
4573
4573
|
const verboseValue = verbose != null ? verbose : true;
|
|
4574
4574
|
const graphQLSchemaAst = await database.getGraphQLSchema();
|
|
4575
|
+
if (!graphQLSchemaAst) {
|
|
4576
|
+
throw new import_graphql4.GraphQLError(`GraphQL schema not found`);
|
|
4577
|
+
}
|
|
4575
4578
|
const graphQLSchema = (0, import_graphql4.buildASTSchema)(graphQLSchemaAst);
|
|
4576
4579
|
const tinaConfig = await database.getTinaSchema();
|
|
4577
4580
|
const tinaSchema = await createSchema({
|
|
@@ -4939,7 +4942,10 @@ var Database = class {
|
|
|
4939
4942
|
this.config = config;
|
|
4940
4943
|
this.collectionForPath = async (filepath) => {
|
|
4941
4944
|
const tinaSchema = await this.getSchema(this.level);
|
|
4942
|
-
|
|
4945
|
+
try {
|
|
4946
|
+
return tinaSchema.getCollectionByFullPath(filepath);
|
|
4947
|
+
} catch (e) {
|
|
4948
|
+
}
|
|
4943
4949
|
};
|
|
4944
4950
|
this.getGeneratedFolder = () => import_path3.default.join(this.tinaDirectory, "__generated__");
|
|
4945
4951
|
this.get = async (filepath) => {
|
|
@@ -4996,16 +5002,16 @@ var Database = class {
|
|
|
4996
5002
|
await this.initLevel();
|
|
4997
5003
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
4998
5004
|
const collection = await this.collectionForPath(filepath);
|
|
5005
|
+
if (!collection) {
|
|
5006
|
+
throw new import_graphql5.GraphQLError(`Unable to find collection for ${filepath}`);
|
|
5007
|
+
}
|
|
4999
5008
|
const stringifiedFile = await this.stringifyFile(
|
|
5000
5009
|
filepath,
|
|
5001
5010
|
dataFields,
|
|
5002
5011
|
collection
|
|
5003
5012
|
);
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5007
|
-
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5008
|
-
}
|
|
5013
|
+
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5014
|
+
const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5009
5015
|
const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
|
|
5010
5016
|
if (this.bridge) {
|
|
5011
5017
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
@@ -5083,6 +5089,9 @@ var Database = class {
|
|
|
5083
5089
|
const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
|
|
5084
5090
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5085
5091
|
const collection = await this.collectionForPath(filepath);
|
|
5092
|
+
if (!collection) {
|
|
5093
|
+
throw new import_graphql5.GraphQLError(`Unable to find collection for ${filepath}.`);
|
|
5094
|
+
}
|
|
5086
5095
|
if (((_a = collection.match) == null ? void 0 : _a.exclude) || ((_b = collection.match) == null ? void 0 : _b.include)) {
|
|
5087
5096
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
5088
5097
|
const match = import_micromatch.default.isMatch(filepath, matches);
|
|
@@ -5174,8 +5183,10 @@ var Database = class {
|
|
|
5174
5183
|
}
|
|
5175
5184
|
};
|
|
5176
5185
|
this.formatBodyOnPayload = async (filepath, data) => {
|
|
5177
|
-
const
|
|
5178
|
-
|
|
5186
|
+
const collection = await this.collectionForPath(filepath);
|
|
5187
|
+
if (!collection) {
|
|
5188
|
+
throw new Error(`Unable to find collection for path ${filepath}`);
|
|
5189
|
+
}
|
|
5179
5190
|
const { template } = await this.getTemplateDetailsForFile(collection, data);
|
|
5180
5191
|
const bodyField = template.fields.find((field) => {
|
|
5181
5192
|
if (field.type === "string" || field.type === "rich-text") {
|
|
@@ -5221,6 +5232,9 @@ var Database = class {
|
|
|
5221
5232
|
const data = await this.get(filepath);
|
|
5222
5233
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5223
5234
|
const collection = await this.collectionForPath(filepath);
|
|
5235
|
+
if (!collection) {
|
|
5236
|
+
throw new Error(`Unable to find collection for path ${filepath}`);
|
|
5237
|
+
}
|
|
5224
5238
|
const stringifiedFile = await this.stringifyFile(
|
|
5225
5239
|
filepath,
|
|
5226
5240
|
dataFields,
|
|
@@ -5606,11 +5620,11 @@ var Database = class {
|
|
|
5606
5620
|
this.delete = async (filepath) => {
|
|
5607
5621
|
await this.initLevel();
|
|
5608
5622
|
const collection = await this.collectionForPath(filepath);
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5612
|
-
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5623
|
+
if (!collection) {
|
|
5624
|
+
throw new Error(`No collection found for path: ${filepath}`);
|
|
5613
5625
|
}
|
|
5626
|
+
const indexDefinitions = await this.getIndexDefinitions(this.level);
|
|
5627
|
+
const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5614
5628
|
this.level.sublevel(
|
|
5615
5629
|
CONTENT_ROOT_PREFIX,
|
|
5616
5630
|
SUBLEVEL_OPTIONS
|
|
@@ -5743,7 +5757,10 @@ This will be an error in the future. See https://tina.io/docs/errors/file-in-mut
|
|
|
5743
5757
|
let version = await this.getDatabaseVersion();
|
|
5744
5758
|
if (!version) {
|
|
5745
5759
|
version = "";
|
|
5746
|
-
|
|
5760
|
+
try {
|
|
5761
|
+
await this.updateDatabaseVersion(version);
|
|
5762
|
+
} catch (e) {
|
|
5763
|
+
}
|
|
5747
5764
|
}
|
|
5748
5765
|
this.level = this.rootLevel.sublevel(version, SUBLEVEL_OPTIONS);
|
|
5749
5766
|
}
|
|
@@ -5872,7 +5889,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5872
5889
|
throw new TinaFetchError(`Unable to seed ${filepath}`, {
|
|
5873
5890
|
originalError: error,
|
|
5874
5891
|
file: filepath,
|
|
5875
|
-
collection: collection.name,
|
|
5892
|
+
collection: collection == null ? void 0 : collection.name,
|
|
5876
5893
|
stack: error.stack
|
|
5877
5894
|
});
|
|
5878
5895
|
}
|
|
@@ -5957,10 +5974,10 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
5957
5974
|
}
|
|
5958
5975
|
};
|
|
5959
5976
|
var getTemplateForFile = (templateInfo, data) => {
|
|
5960
|
-
if (templateInfo.type === "object") {
|
|
5977
|
+
if ((templateInfo == null ? void 0 : templateInfo.type) === "object") {
|
|
5961
5978
|
return templateInfo.template;
|
|
5962
5979
|
}
|
|
5963
|
-
if (templateInfo.type === "union") {
|
|
5980
|
+
if ((templateInfo == null ? void 0 : templateInfo.type) === "union") {
|
|
5964
5981
|
if (hasOwnProperty(data, "_template")) {
|
|
5965
5982
|
const template = templateInfo.templates.find(
|
|
5966
5983
|
(t) => lastItem(t.namespace) === data._template
|