@tinacms/graphql 1.5.14 → 1.5.16

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  */
4
4
  import { LookupMapType } from '../database';
5
- import type { ObjectTypeDefinitionNode, InlineFragmentNode, FieldDefinitionNode } from 'graphql';
5
+ import type { FieldDefinitionNode, InlineFragmentNode, ObjectTypeDefinitionNode } from 'graphql';
6
6
  import type { Collection, Template } from '@tinacms/schema-tools';
7
7
  import { TinaSchema } from '@tinacms/schema-tools';
8
8
  export declare const createBuilder: ({ tinaSchema, }: {
@@ -177,7 +177,7 @@ export declare class Builder {
177
177
  * ```
178
178
  *
179
179
  * @public
180
- * @param collection a Tina Cloud collection
180
+ * @param collection a TinaCloud collection
181
181
  */
182
182
  collectionFragment: (collection: Collection<true>) => Promise<import("graphql").FragmentDefinitionNode>;
183
183
  /**
package/dist/index.js CHANGED
@@ -1914,7 +1914,7 @@ var Builder = class {
1914
1914
  * ```
1915
1915
  *
1916
1916
  * @public
1917
- * @param collection a Tina Cloud collection
1917
+ * @param collection a TinaCloud collection
1918
1918
  */
1919
1919
  this.collectionFragment = async (collection) => {
1920
1920
  const name = NAMER.dataTypeName(collection.namespace);
@@ -3090,7 +3090,7 @@ var validateField = async (field) => {
3090
3090
  // package.json
3091
3091
  var package_default = {
3092
3092
  name: "@tinacms/graphql",
3093
- version: "1.5.14",
3093
+ version: "1.5.16",
3094
3094
  main: "dist/index.js",
3095
3095
  module: "dist/index.mjs",
3096
3096
  typings: "dist/index.d.ts",
@@ -3332,7 +3332,9 @@ var _buildSchema = async (builder, tinaSchema) => {
3332
3332
  await builder.buildCreateCollectionFolderMutation()
3333
3333
  );
3334
3334
  await sequential(collections, async (collection) => {
3335
- queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
3335
+ queryTypeDefinitionFields.push(
3336
+ await builder.collectionDocument(collection)
3337
+ );
3336
3338
  if (collection.isAuthCollection) {
3337
3339
  queryTypeDefinitionFields.push(
3338
3340
  await builder.authenticationCollectionDocument(collection)
@@ -3648,7 +3650,9 @@ var LevelProxyHandler = {
3648
3650
  throw new Error(`The property, ${property.toString()}, doesn't exist`);
3649
3651
  }
3650
3652
  if (typeof target[property] !== "function") {
3651
- throw new Error(`The property, ${property.toString()}, is not a function`);
3653
+ throw new Error(
3654
+ `The property, ${property.toString()}, is not a function`
3655
+ );
3652
3656
  }
3653
3657
  if (property === "get") {
3654
3658
  return async (...args) => {
@@ -4894,7 +4898,11 @@ var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
4894
4898
  }
4895
4899
  const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
4896
4900
  const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
4897
- const parents = (0, import_jsonpath_plus2.JSONPath)({ path: parentPath, json: obj, resultType: "value" });
4901
+ const parents = (0, import_jsonpath_plus2.JSONPath)({
4902
+ path: parentPath,
4903
+ json: obj,
4904
+ resultType: "value"
4905
+ });
4898
4906
  if (parents.length > 0) {
4899
4907
  parents.forEach((parent) => {
4900
4908
  if (parent && typeof parent === "object" && keyToUpdate in parent) {
@@ -4922,7 +4930,9 @@ var Resolver = class {
4922
4930
  };
4923
4931
  this.getRaw = async (fullPath) => {
4924
4932
  if (typeof fullPath !== "string") {
4925
- throw new Error(`fullPath must be of type string for getDocument request`);
4933
+ throw new Error(
4934
+ `fullPath must be of type string for getDocument request`
4935
+ );
4926
4936
  }
4927
4937
  return this.database.get(fullPath);
4928
4938
  };
@@ -4951,7 +4961,9 @@ var Resolver = class {
4951
4961
  };
4952
4962
  this.getDocument = async (fullPath, opts = {}) => {
4953
4963
  if (typeof fullPath !== "string") {
4954
- throw new Error(`fullPath must be of type string for getDocument request`);
4964
+ throw new Error(
4965
+ `fullPath must be of type string for getDocument request`
4966
+ );
4955
4967
  }
4956
4968
  const rawData = await this.getRaw(fullPath);
4957
4969
  const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
@@ -4966,7 +4978,9 @@ var Resolver = class {
4966
4978
  };
4967
4979
  this.deleteDocument = async (fullPath) => {
4968
4980
  if (typeof fullPath !== "string") {
4969
- throw new Error(`fullPath must be of type string for getDocument request`);
4981
+ throw new Error(
4982
+ `fullPath must be of type string for getDocument request`
4983
+ );
4970
4984
  }
4971
4985
  await this.database.delete(fullPath);
4972
4986
  };
@@ -5170,7 +5184,11 @@ var Resolver = class {
5170
5184
  collection,
5171
5185
  doc == null ? void 0 : doc._rawData
5172
5186
  );
5173
- await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
5187
+ await this.database.put(
5188
+ realPath,
5189
+ { ...oldDoc, ...params },
5190
+ collection.name
5191
+ );
5174
5192
  return this.getDocument(realPath);
5175
5193
  };
5176
5194
  /**
@@ -5372,7 +5390,9 @@ var Resolver = class {
5372
5390
  return this.getDocument(newRealPath);
5373
5391
  }
5374
5392
  if (alreadyExists === false) {
5375
- throw new Error(`Unable to update document, ${realPath} does not exist`);
5393
+ throw new Error(
5394
+ `Unable to update document, ${realPath} does not exist`
5395
+ );
5376
5396
  }
5377
5397
  return this.updateResolveDocument({
5378
5398
  collection,
@@ -6721,8 +6741,35 @@ var Database = class {
6721
6741
  ]
6722
6742
  }
6723
6743
  };
6724
- if (collection.fields) {
6725
- for (const field of collection.fields) {
6744
+ let fields = [];
6745
+ if (collection.templates) {
6746
+ const templateFieldMap = {};
6747
+ const conflictedFields = /* @__PURE__ */ new Set();
6748
+ for (const template of collection.templates) {
6749
+ for (const field of template.fields) {
6750
+ if (!templateFieldMap[field.name]) {
6751
+ templateFieldMap[field.name] = field;
6752
+ } else {
6753
+ if (templateFieldMap[field.name].type !== field.type) {
6754
+ console.warn(
6755
+ `Field ${field.name} has conflicting types in templates - skipping index`
6756
+ );
6757
+ conflictedFields.add(field.name);
6758
+ }
6759
+ }
6760
+ }
6761
+ }
6762
+ for (const conflictedField in conflictedFields) {
6763
+ delete templateFieldMap[conflictedField];
6764
+ }
6765
+ for (const field of Object.values(templateFieldMap)) {
6766
+ fields.push(field);
6767
+ }
6768
+ } else if (collection.fields) {
6769
+ fields = collection.fields;
6770
+ }
6771
+ if (fields) {
6772
+ for (const field of fields) {
6726
6773
  if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
6727
6774
  continue;
6728
6775
  }
@@ -7151,7 +7198,13 @@ var Database = class {
7151
7198
  );
7152
7199
  }
7153
7200
  } else {
7154
- await _indexContent(this, level, contentPaths, enqueueOps, collection);
7201
+ await _indexContent(
7202
+ this,
7203
+ level,
7204
+ contentPaths,
7205
+ enqueueOps,
7206
+ collection
7207
+ );
7155
7208
  }
7156
7209
  }
7157
7210
  );
package/dist/index.mjs CHANGED
@@ -1847,7 +1847,7 @@ var Builder = class {
1847
1847
  * ```
1848
1848
  *
1849
1849
  * @public
1850
- * @param collection a Tina Cloud collection
1850
+ * @param collection a TinaCloud collection
1851
1851
  */
1852
1852
  this.collectionFragment = async (collection) => {
1853
1853
  const name = NAMER.dataTypeName(collection.namespace);
@@ -3019,7 +3019,7 @@ var validateField = async (field) => {
3019
3019
  // package.json
3020
3020
  var package_default = {
3021
3021
  name: "@tinacms/graphql",
3022
- version: "1.5.14",
3022
+ version: "1.5.16",
3023
3023
  main: "dist/index.js",
3024
3024
  module: "dist/index.mjs",
3025
3025
  typings: "dist/index.d.ts",
@@ -3260,7 +3260,9 @@ var _buildSchema = async (builder, tinaSchema) => {
3260
3260
  await builder.buildCreateCollectionFolderMutation()
3261
3261
  );
3262
3262
  await sequential(collections, async (collection) => {
3263
- queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
3263
+ queryTypeDefinitionFields.push(
3264
+ await builder.collectionDocument(collection)
3265
+ );
3264
3266
  if (collection.isAuthCollection) {
3265
3267
  queryTypeDefinitionFields.push(
3266
3268
  await builder.authenticationCollectionDocument(collection)
@@ -3575,7 +3577,9 @@ var LevelProxyHandler = {
3575
3577
  throw new Error(`The property, ${property.toString()}, doesn't exist`);
3576
3578
  }
3577
3579
  if (typeof target[property] !== "function") {
3578
- throw new Error(`The property, ${property.toString()}, is not a function`);
3580
+ throw new Error(
3581
+ `The property, ${property.toString()}, is not a function`
3582
+ );
3579
3583
  }
3580
3584
  if (property === "get") {
3581
3585
  return async (...args) => {
@@ -4818,7 +4822,11 @@ var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
4818
4822
  }
4819
4823
  const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
4820
4824
  const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
4821
- const parents = JSONPath2({ path: parentPath, json: obj, resultType: "value" });
4825
+ const parents = JSONPath2({
4826
+ path: parentPath,
4827
+ json: obj,
4828
+ resultType: "value"
4829
+ });
4822
4830
  if (parents.length > 0) {
4823
4831
  parents.forEach((parent) => {
4824
4832
  if (parent && typeof parent === "object" && keyToUpdate in parent) {
@@ -4846,7 +4854,9 @@ var Resolver = class {
4846
4854
  };
4847
4855
  this.getRaw = async (fullPath) => {
4848
4856
  if (typeof fullPath !== "string") {
4849
- throw new Error(`fullPath must be of type string for getDocument request`);
4857
+ throw new Error(
4858
+ `fullPath must be of type string for getDocument request`
4859
+ );
4850
4860
  }
4851
4861
  return this.database.get(fullPath);
4852
4862
  };
@@ -4875,7 +4885,9 @@ var Resolver = class {
4875
4885
  };
4876
4886
  this.getDocument = async (fullPath, opts = {}) => {
4877
4887
  if (typeof fullPath !== "string") {
4878
- throw new Error(`fullPath must be of type string for getDocument request`);
4888
+ throw new Error(
4889
+ `fullPath must be of type string for getDocument request`
4890
+ );
4879
4891
  }
4880
4892
  const rawData = await this.getRaw(fullPath);
4881
4893
  const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
@@ -4890,7 +4902,9 @@ var Resolver = class {
4890
4902
  };
4891
4903
  this.deleteDocument = async (fullPath) => {
4892
4904
  if (typeof fullPath !== "string") {
4893
- throw new Error(`fullPath must be of type string for getDocument request`);
4905
+ throw new Error(
4906
+ `fullPath must be of type string for getDocument request`
4907
+ );
4894
4908
  }
4895
4909
  await this.database.delete(fullPath);
4896
4910
  };
@@ -5094,7 +5108,11 @@ var Resolver = class {
5094
5108
  collection,
5095
5109
  doc?._rawData
5096
5110
  );
5097
- await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
5111
+ await this.database.put(
5112
+ realPath,
5113
+ { ...oldDoc, ...params },
5114
+ collection.name
5115
+ );
5098
5116
  return this.getDocument(realPath);
5099
5117
  };
5100
5118
  /**
@@ -5295,7 +5313,9 @@ var Resolver = class {
5295
5313
  return this.getDocument(newRealPath);
5296
5314
  }
5297
5315
  if (alreadyExists === false) {
5298
- throw new Error(`Unable to update document, ${realPath} does not exist`);
5316
+ throw new Error(
5317
+ `Unable to update document, ${realPath} does not exist`
5318
+ );
5299
5319
  }
5300
5320
  return this.updateResolveDocument({
5301
5321
  collection,
@@ -6637,8 +6657,35 @@ var Database = class {
6637
6657
  ]
6638
6658
  }
6639
6659
  };
6640
- if (collection.fields) {
6641
- for (const field of collection.fields) {
6660
+ let fields = [];
6661
+ if (collection.templates) {
6662
+ const templateFieldMap = {};
6663
+ const conflictedFields = /* @__PURE__ */ new Set();
6664
+ for (const template of collection.templates) {
6665
+ for (const field of template.fields) {
6666
+ if (!templateFieldMap[field.name]) {
6667
+ templateFieldMap[field.name] = field;
6668
+ } else {
6669
+ if (templateFieldMap[field.name].type !== field.type) {
6670
+ console.warn(
6671
+ `Field ${field.name} has conflicting types in templates - skipping index`
6672
+ );
6673
+ conflictedFields.add(field.name);
6674
+ }
6675
+ }
6676
+ }
6677
+ }
6678
+ for (const conflictedField in conflictedFields) {
6679
+ delete templateFieldMap[conflictedField];
6680
+ }
6681
+ for (const field of Object.values(templateFieldMap)) {
6682
+ fields.push(field);
6683
+ }
6684
+ } else if (collection.fields) {
6685
+ fields = collection.fields;
6686
+ }
6687
+ if (fields) {
6688
+ for (const field of fields) {
6642
6689
  if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
6643
6690
  continue;
6644
6691
  }
@@ -7065,7 +7112,13 @@ var Database = class {
7065
7112
  );
7066
7113
  }
7067
7114
  } else {
7068
- await _indexContent(this, level, contentPaths, enqueueOps, collection);
7115
+ await _indexContent(
7116
+ this,
7117
+ level,
7118
+ contentPaths,
7119
+ enqueueOps,
7120
+ collection
7121
+ );
7069
7122
  }
7070
7123
  }
7071
7124
  );
@@ -1,10 +1,10 @@
1
1
  /**
2
2
 
3
3
  */
4
- import type { GraphQLConfig } from '../types';
5
4
  import type { Schema } from '@tinacms/schema-tools';
5
+ import type { GraphQLConfig } from '../types';
6
6
  /**
7
- * Strips away the Tina Cloud Asset URL from an `image` value
7
+ * Strips away the TinaCloud Asset URL from an `image` value
8
8
  *
9
9
  * @param {string | string[]} value
10
10
  * @param {GraphQLConfig} config
@@ -12,7 +12,7 @@ import type { Schema } from '@tinacms/schema-tools';
12
12
  */
13
13
  export declare const resolveMediaCloudToRelative: (value: string | string[], config: GraphQLConfig, schema: Schema<true>) => string | string[];
14
14
  /**
15
- * Adds Tina Cloud Asset URL to an `image` value
15
+ * Adds TinaCloud Asset URL to an `image` value
16
16
  *
17
17
  * @param {string | string[]} value
18
18
  * @param {GraphQLConfig} config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "1.5.14",
3
+ "version": "1.5.16",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "typings": "dist/index.d.ts",
@@ -44,8 +44,8 @@
44
44
  "readable-stream": "^4.7.0",
45
45
  "scmp": "^2.1.0",
46
46
  "yup": "^0.32.11",
47
- "@tinacms/schema-tools": "1.7.2",
48
- "@tinacms/mdx": "1.6.1"
47
+ "@tinacms/mdx": "1.6.2",
48
+ "@tinacms/schema-tools": "1.7.3"
49
49
  },
50
50
  "publishConfig": {
51
51
  "registry": "https://registry.npmjs.org"
@@ -76,8 +76,8 @@
76
76
  "vite": "^4.5.9",
77
77
  "vitest": "^0.32.4",
78
78
  "zod": "^3.24.2",
79
- "@tinacms/schema-tools": "1.7.2",
80
- "@tinacms/scripts": "1.3.3"
79
+ "@tinacms/schema-tools": "1.7.3",
80
+ "@tinacms/scripts": "1.3.4"
81
81
  },
82
82
  "scripts": {
83
83
  "types": "pnpm tsc",