@tinacms/graphql 0.0.0-d9672bc-20250218033222 → 0.0.0-df15737-20250329200825

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/index.d.ts CHANGED
@@ -1,32 +1 @@
1
- import type { Schema, Collection, Template as TinaTemplate } from '@tinacms/schema-tools';
2
- import { buildDotTinaFiles } from './build';
3
- export { resolve } from './resolve';
4
- export { transformDocumentIntoPayload } from './resolver';
5
- export * from './resolver/error';
6
- export { TinaLevelClient } from './level/tinaLevel';
7
- export type { Level } from './database/level';
8
- export type { QueryOptions, OnDeleteCallback, OnPutCallback, DatabaseArgs, GitProvider, CreateDatabase, } from './database';
9
- export { Database, createDatabaseInternal, createDatabase, createLocalDatabase, } from './database';
10
- import type { Config } from '@tinacms/schema-tools';
11
- export { getChangedFiles, getSha, shaExists } from './git';
12
- export * from './auth/utils';
13
- export { sequential, assertShape } from './util';
14
- export { loadAndParseWithAliases, stringifyFile, parseFile, scanAllContent, scanContentByPaths, transformDocument, } from './database/util';
15
- export { createSchema } from './schema/createSchema';
16
- export { buildDotTinaFiles };
17
- export type DummyType = unknown;
18
- export declare const buildSchema: (config: Config, flags?: string[]) => Promise<{
19
- graphQLSchema: {
20
- kind: "Document";
21
- definitions: any;
22
- };
23
- tinaSchema: import("@tinacms/schema-tools").TinaSchema;
24
- lookup: Record<string, import("./database").LookupMapType>;
25
- fragDoc: string;
26
- queryDoc: string;
27
- }>;
28
- export type TinaSchema = Schema;
29
- export type { TinaTemplate, Schema, Collection };
30
- export { FilesystemBridge, AuditFileSystemBridge, } from './database/bridge/filesystem';
31
- export { IsomorphicBridge } from './database/bridge/isomorphic';
32
- export type { Bridge } from './database/bridge';
1
+ export * from "../src/index"
package/dist/index.js CHANGED
@@ -27,8 +27,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
 
29
29
  // src/index.ts
30
- var src_exports = {};
31
- __export(src_exports, {
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
32
  AuditFileSystemBridge: () => AuditFileSystemBridge,
33
33
  Database: () => Database,
34
34
  FilesystemBridge: () => FilesystemBridge,
@@ -62,7 +62,7 @@ __export(src_exports, {
62
62
  transformDocument: () => transformDocument,
63
63
  transformDocumentIntoPayload: () => transformDocumentIntoPayload
64
64
  });
65
- module.exports = __toCommonJS(src_exports);
65
+ module.exports = __toCommonJS(index_exports);
66
66
 
67
67
  // src/build.ts
68
68
  var import_graphql2 = require("graphql");
@@ -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.12",
3093
+ version: "1.5.15",
3094
3094
  main: "dist/index.js",
3095
3095
  module: "dist/index.mjs",
3096
3096
  typings: "dist/index.d.ts",
@@ -3126,12 +3126,12 @@ var package_default = {
3126
3126
  "@tinacms/schema-tools": "workspace:*",
3127
3127
  "abstract-level": "^1.0.4",
3128
3128
  "date-fns": "^2.30.0",
3129
- "fast-glob": "^3.3.2",
3130
- "fs-extra": "^11.2.0",
3129
+ "fast-glob": "^3.3.3",
3130
+ "fs-extra": "^11.3.0",
3131
3131
  "glob-parent": "^6.0.2",
3132
3132
  graphql: "15.8.0",
3133
3133
  "gray-matter": "^4.0.3",
3134
- "isomorphic-git": "^1.27.1",
3134
+ "isomorphic-git": "^1.29.0",
3135
3135
  "js-sha1": "^0.6.0",
3136
3136
  "js-yaml": "^3.14.1",
3137
3137
  "jsonpath-plus": "10.1.0",
@@ -3141,7 +3141,7 @@ var package_default = {
3141
3141
  "many-level": "^2.0.0",
3142
3142
  micromatch: "4.0.8",
3143
3143
  "normalize-path": "^3.0.0",
3144
- "readable-stream": "^4.5.2",
3144
+ "readable-stream": "^4.7.0",
3145
3145
  scmp: "^2.1.0",
3146
3146
  yup: "^0.32.11"
3147
3147
  },
@@ -3165,17 +3165,17 @@ var package_default = {
3165
3165
  "@types/lru-cache": "^5.1.1",
3166
3166
  "@types/mdast": "^3.0.15",
3167
3167
  "@types/micromatch": "^4.0.9",
3168
- "@types/node": "^22.9.0",
3168
+ "@types/node": "^22.13.1",
3169
3169
  "@types/normalize-path": "^3.0.2",
3170
3170
  "@types/ws": "^7.4.7",
3171
3171
  "@types/yup": "^0.29.14",
3172
3172
  "jest-file-snapshot": "^0.5.0",
3173
3173
  "memory-level": "^1.0.0",
3174
3174
  nodemon: "3.1.4",
3175
- typescript: "^5.6.3",
3176
- vite: "^4.3.9",
3177
- vitest: "^0.32.2",
3178
- zod: "^3.23.8"
3175
+ typescript: "^5.7.3",
3176
+ vite: "^4.5.9",
3177
+ vitest: "^0.32.4",
3178
+ zod: "^3.24.2"
3179
3179
  }
3180
3180
  };
3181
3181
 
@@ -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) => {
@@ -4626,10 +4630,26 @@ var makeRefOpsForDocument = (filepath, collection, references, data, opType, lev
4626
4630
  const references2 = {};
4627
4631
  for (const path7 of referencePaths) {
4628
4632
  const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
4629
- if (references2[ref]) {
4630
- references2[ref].push(path7);
4633
+ if (!ref) {
4634
+ continue;
4635
+ }
4636
+ if (Array.isArray(ref)) {
4637
+ for (const r of ref) {
4638
+ if (!r) {
4639
+ continue;
4640
+ }
4641
+ if (references2[r]) {
4642
+ references2[r].push(path7);
4643
+ } else {
4644
+ references2[r] = [path7];
4645
+ }
4646
+ }
4631
4647
  } else {
4632
- references2[ref] = [path7];
4648
+ if (references2[ref]) {
4649
+ references2[ref].push(path7);
4650
+ } else {
4651
+ references2[ref] = [path7];
4652
+ }
4633
4653
  }
4634
4654
  }
4635
4655
  for (const ref of Object.keys(references2)) {
@@ -4867,24 +4887,33 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4867
4887
  throw e;
4868
4888
  }
4869
4889
  };
4870
- var updateObjectWithJsonPath = (obj, path7, newValue) => {
4890
+ var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
4891
+ let updated = false;
4871
4892
  if (!path7.includes(".") && !path7.includes("[")) {
4872
- if (path7 in obj) {
4893
+ if (path7 in obj && obj[path7] === oldValue) {
4873
4894
  obj[path7] = newValue;
4895
+ updated = true;
4874
4896
  }
4875
- return obj;
4876
- }
4877
- const parentPath = path7.replace(/\.[^.]+$/, "");
4878
- const keyToUpdate = path7.match(/[^.]+$/)[0];
4879
- const parents = (0, import_jsonpath_plus2.JSONPath)({ path: parentPath, json: obj, resultType: "value" });
4897
+ return { object: obj, updated };
4898
+ }
4899
+ const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
4900
+ const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
4901
+ const parents = (0, import_jsonpath_plus2.JSONPath)({
4902
+ path: parentPath,
4903
+ json: obj,
4904
+ resultType: "value"
4905
+ });
4880
4906
  if (parents.length > 0) {
4881
4907
  parents.forEach((parent) => {
4882
4908
  if (parent && typeof parent === "object" && keyToUpdate in parent) {
4883
- parent[keyToUpdate] = newValue;
4909
+ if (parent[keyToUpdate] === oldValue) {
4910
+ parent[keyToUpdate] = newValue;
4911
+ updated = true;
4912
+ }
4884
4913
  }
4885
4914
  });
4886
4915
  }
4887
- return obj;
4916
+ return { object: obj, updated };
4888
4917
  };
4889
4918
  var Resolver = class {
4890
4919
  constructor(init) {
@@ -4901,7 +4930,9 @@ var Resolver = class {
4901
4930
  };
4902
4931
  this.getRaw = async (fullPath) => {
4903
4932
  if (typeof fullPath !== "string") {
4904
- 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
+ );
4905
4936
  }
4906
4937
  return this.database.get(fullPath);
4907
4938
  };
@@ -4930,7 +4961,9 @@ var Resolver = class {
4930
4961
  };
4931
4962
  this.getDocument = async (fullPath, opts = {}) => {
4932
4963
  if (typeof fullPath !== "string") {
4933
- 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
+ );
4934
4967
  }
4935
4968
  const rawData = await this.getRaw(fullPath);
4936
4969
  const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
@@ -4945,7 +4978,9 @@ var Resolver = class {
4945
4978
  };
4946
4979
  this.deleteDocument = async (fullPath) => {
4947
4980
  if (typeof fullPath !== "string") {
4948
- 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
+ );
4949
4984
  }
4950
4985
  await this.database.delete(fullPath);
4951
4986
  };
@@ -5149,7 +5184,11 @@ var Resolver = class {
5149
5184
  collection,
5150
5185
  doc == null ? void 0 : doc._rawData
5151
5186
  );
5152
- await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
5187
+ await this.database.put(
5188
+ realPath,
5189
+ { ...oldDoc, ...params },
5190
+ collection.name
5191
+ );
5153
5192
  return this.getDocument(realPath);
5154
5193
  };
5155
5194
  /**
@@ -5268,10 +5307,30 @@ var Resolver = class {
5268
5307
  docsWithRefs
5269
5308
  )) {
5270
5309
  let refDoc = await this.getRaw(pathToDocWithRef);
5310
+ let hasUpdate = false;
5271
5311
  for (const path7 of referencePaths) {
5272
- refDoc = updateObjectWithJsonPath(refDoc, path7, null);
5312
+ const { object: object2, updated } = updateObjectWithJsonPath(
5313
+ refDoc,
5314
+ path7,
5315
+ realPath,
5316
+ null
5317
+ );
5318
+ refDoc = object2;
5319
+ hasUpdate = updated || hasUpdate;
5320
+ }
5321
+ if (hasUpdate) {
5322
+ const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
5323
+ if (!collectionWithRef) {
5324
+ throw new Error(
5325
+ `Unable to find collection for ${pathToDocWithRef}`
5326
+ );
5327
+ }
5328
+ await this.database.put(
5329
+ pathToDocWithRef,
5330
+ refDoc,
5331
+ collectionWithRef.name
5332
+ );
5273
5333
  }
5274
- await this.database.put(pathToDocWithRef, refDoc, collection2);
5275
5334
  }
5276
5335
  }
5277
5336
  }
@@ -5291,6 +5350,9 @@ var Resolver = class {
5291
5350
  collection == null ? void 0 : collection.path,
5292
5351
  args.params.relativePath
5293
5352
  );
5353
+ if (newRealPath === realPath) {
5354
+ return doc;
5355
+ }
5294
5356
  await this.database.put(newRealPath, doc._rawData, collection.name);
5295
5357
  await this.deleteDocument(realPath);
5296
5358
  const collRefs = await this.findReferences(realPath, collection);
@@ -5299,20 +5361,38 @@ var Resolver = class {
5299
5361
  docsWithRefs
5300
5362
  )) {
5301
5363
  let docWithRef = await this.getRaw(pathToDocWithRef);
5364
+ let hasUpdate = false;
5302
5365
  for (const path7 of referencePaths) {
5303
- docWithRef = updateObjectWithJsonPath(
5366
+ const { object: object2, updated } = updateObjectWithJsonPath(
5304
5367
  docWithRef,
5305
5368
  path7,
5369
+ realPath,
5306
5370
  newRealPath
5307
5371
  );
5372
+ docWithRef = object2;
5373
+ hasUpdate = updated || hasUpdate;
5374
+ }
5375
+ if (hasUpdate) {
5376
+ const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
5377
+ if (!collectionWithRef) {
5378
+ throw new Error(
5379
+ `Unable to find collection for ${pathToDocWithRef}`
5380
+ );
5381
+ }
5382
+ await this.database.put(
5383
+ pathToDocWithRef,
5384
+ docWithRef,
5385
+ collectionWithRef.name
5386
+ );
5308
5387
  }
5309
- await this.database.put(pathToDocWithRef, docWithRef, collection2);
5310
5388
  }
5311
5389
  }
5312
5390
  return this.getDocument(newRealPath);
5313
5391
  }
5314
5392
  if (alreadyExists === false) {
5315
- 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
+ );
5316
5396
  }
5317
5397
  return this.updateResolveDocument({
5318
5398
  collection,
@@ -6661,8 +6741,35 @@ var Database = class {
6661
6741
  ]
6662
6742
  }
6663
6743
  };
6664
- if (collection.fields) {
6665
- 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) {
6666
6773
  if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
6667
6774
  continue;
6668
6775
  }
@@ -7091,7 +7198,13 @@ var Database = class {
7091
7198
  );
7092
7199
  }
7093
7200
  } else {
7094
- await _indexContent(this, level, contentPaths, enqueueOps, collection);
7201
+ await _indexContent(
7202
+ this,
7203
+ level,
7204
+ contentPaths,
7205
+ enqueueOps,
7206
+ collection
7207
+ );
7095
7208
  }
7096
7209
  }
7097
7210
  );
package/dist/index.mjs CHANGED
@@ -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.12",
3022
+ version: "1.5.15",
3023
3023
  main: "dist/index.js",
3024
3024
  module: "dist/index.mjs",
3025
3025
  typings: "dist/index.d.ts",
@@ -3055,12 +3055,12 @@ var package_default = {
3055
3055
  "@tinacms/schema-tools": "workspace:*",
3056
3056
  "abstract-level": "^1.0.4",
3057
3057
  "date-fns": "^2.30.0",
3058
- "fast-glob": "^3.3.2",
3059
- "fs-extra": "^11.2.0",
3058
+ "fast-glob": "^3.3.3",
3059
+ "fs-extra": "^11.3.0",
3060
3060
  "glob-parent": "^6.0.2",
3061
3061
  graphql: "15.8.0",
3062
3062
  "gray-matter": "^4.0.3",
3063
- "isomorphic-git": "^1.27.1",
3063
+ "isomorphic-git": "^1.29.0",
3064
3064
  "js-sha1": "^0.6.0",
3065
3065
  "js-yaml": "^3.14.1",
3066
3066
  "jsonpath-plus": "10.1.0",
@@ -3070,7 +3070,7 @@ var package_default = {
3070
3070
  "many-level": "^2.0.0",
3071
3071
  micromatch: "4.0.8",
3072
3072
  "normalize-path": "^3.0.0",
3073
- "readable-stream": "^4.5.2",
3073
+ "readable-stream": "^4.7.0",
3074
3074
  scmp: "^2.1.0",
3075
3075
  yup: "^0.32.11"
3076
3076
  },
@@ -3094,17 +3094,17 @@ var package_default = {
3094
3094
  "@types/lru-cache": "^5.1.1",
3095
3095
  "@types/mdast": "^3.0.15",
3096
3096
  "@types/micromatch": "^4.0.9",
3097
- "@types/node": "^22.9.0",
3097
+ "@types/node": "^22.13.1",
3098
3098
  "@types/normalize-path": "^3.0.2",
3099
3099
  "@types/ws": "^7.4.7",
3100
3100
  "@types/yup": "^0.29.14",
3101
3101
  "jest-file-snapshot": "^0.5.0",
3102
3102
  "memory-level": "^1.0.0",
3103
3103
  nodemon: "3.1.4",
3104
- typescript: "^5.6.3",
3105
- vite: "^4.3.9",
3106
- vitest: "^0.32.2",
3107
- zod: "^3.23.8"
3104
+ typescript: "^5.7.3",
3105
+ vite: "^4.5.9",
3106
+ vitest: "^0.32.4",
3107
+ zod: "^3.24.2"
3108
3108
  }
3109
3109
  };
3110
3110
 
@@ -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) => {
@@ -4551,10 +4555,26 @@ var makeRefOpsForDocument = (filepath, collection, references, data, opType, lev
4551
4555
  const references2 = {};
4552
4556
  for (const path7 of referencePaths) {
4553
4557
  const ref = JSONPath({ path: path7, json: data });
4554
- if (references2[ref]) {
4555
- references2[ref].push(path7);
4558
+ if (!ref) {
4559
+ continue;
4560
+ }
4561
+ if (Array.isArray(ref)) {
4562
+ for (const r of ref) {
4563
+ if (!r) {
4564
+ continue;
4565
+ }
4566
+ if (references2[r]) {
4567
+ references2[r].push(path7);
4568
+ } else {
4569
+ references2[r] = [path7];
4570
+ }
4571
+ }
4556
4572
  } else {
4557
- references2[ref] = [path7];
4573
+ if (references2[ref]) {
4574
+ references2[ref].push(path7);
4575
+ } else {
4576
+ references2[ref] = [path7];
4577
+ }
4558
4578
  }
4559
4579
  }
4560
4580
  for (const ref of Object.keys(references2)) {
@@ -4791,24 +4811,33 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4791
4811
  throw e;
4792
4812
  }
4793
4813
  };
4794
- var updateObjectWithJsonPath = (obj, path7, newValue) => {
4814
+ var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
4815
+ let updated = false;
4795
4816
  if (!path7.includes(".") && !path7.includes("[")) {
4796
- if (path7 in obj) {
4817
+ if (path7 in obj && obj[path7] === oldValue) {
4797
4818
  obj[path7] = newValue;
4819
+ updated = true;
4798
4820
  }
4799
- return obj;
4800
- }
4801
- const parentPath = path7.replace(/\.[^.]+$/, "");
4802
- const keyToUpdate = path7.match(/[^.]+$/)[0];
4803
- const parents = JSONPath2({ path: parentPath, json: obj, resultType: "value" });
4821
+ return { object: obj, updated };
4822
+ }
4823
+ const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
4824
+ const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
4825
+ const parents = JSONPath2({
4826
+ path: parentPath,
4827
+ json: obj,
4828
+ resultType: "value"
4829
+ });
4804
4830
  if (parents.length > 0) {
4805
4831
  parents.forEach((parent) => {
4806
4832
  if (parent && typeof parent === "object" && keyToUpdate in parent) {
4807
- parent[keyToUpdate] = newValue;
4833
+ if (parent[keyToUpdate] === oldValue) {
4834
+ parent[keyToUpdate] = newValue;
4835
+ updated = true;
4836
+ }
4808
4837
  }
4809
4838
  });
4810
4839
  }
4811
- return obj;
4840
+ return { object: obj, updated };
4812
4841
  };
4813
4842
  var Resolver = class {
4814
4843
  constructor(init) {
@@ -4825,7 +4854,9 @@ var Resolver = class {
4825
4854
  };
4826
4855
  this.getRaw = async (fullPath) => {
4827
4856
  if (typeof fullPath !== "string") {
4828
- 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
+ );
4829
4860
  }
4830
4861
  return this.database.get(fullPath);
4831
4862
  };
@@ -4854,7 +4885,9 @@ var Resolver = class {
4854
4885
  };
4855
4886
  this.getDocument = async (fullPath, opts = {}) => {
4856
4887
  if (typeof fullPath !== "string") {
4857
- 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
+ );
4858
4891
  }
4859
4892
  const rawData = await this.getRaw(fullPath);
4860
4893
  const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
@@ -4869,7 +4902,9 @@ var Resolver = class {
4869
4902
  };
4870
4903
  this.deleteDocument = async (fullPath) => {
4871
4904
  if (typeof fullPath !== "string") {
4872
- 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
+ );
4873
4908
  }
4874
4909
  await this.database.delete(fullPath);
4875
4910
  };
@@ -5073,7 +5108,11 @@ var Resolver = class {
5073
5108
  collection,
5074
5109
  doc?._rawData
5075
5110
  );
5076
- await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
5111
+ await this.database.put(
5112
+ realPath,
5113
+ { ...oldDoc, ...params },
5114
+ collection.name
5115
+ );
5077
5116
  return this.getDocument(realPath);
5078
5117
  };
5079
5118
  /**
@@ -5191,10 +5230,30 @@ var Resolver = class {
5191
5230
  docsWithRefs
5192
5231
  )) {
5193
5232
  let refDoc = await this.getRaw(pathToDocWithRef);
5233
+ let hasUpdate = false;
5194
5234
  for (const path7 of referencePaths) {
5195
- refDoc = updateObjectWithJsonPath(refDoc, path7, null);
5235
+ const { object: object2, updated } = updateObjectWithJsonPath(
5236
+ refDoc,
5237
+ path7,
5238
+ realPath,
5239
+ null
5240
+ );
5241
+ refDoc = object2;
5242
+ hasUpdate = updated || hasUpdate;
5243
+ }
5244
+ if (hasUpdate) {
5245
+ const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
5246
+ if (!collectionWithRef) {
5247
+ throw new Error(
5248
+ `Unable to find collection for ${pathToDocWithRef}`
5249
+ );
5250
+ }
5251
+ await this.database.put(
5252
+ pathToDocWithRef,
5253
+ refDoc,
5254
+ collectionWithRef.name
5255
+ );
5196
5256
  }
5197
- await this.database.put(pathToDocWithRef, refDoc, collection2);
5198
5257
  }
5199
5258
  }
5200
5259
  }
@@ -5214,6 +5273,9 @@ var Resolver = class {
5214
5273
  collection?.path,
5215
5274
  args.params.relativePath
5216
5275
  );
5276
+ if (newRealPath === realPath) {
5277
+ return doc;
5278
+ }
5217
5279
  await this.database.put(newRealPath, doc._rawData, collection.name);
5218
5280
  await this.deleteDocument(realPath);
5219
5281
  const collRefs = await this.findReferences(realPath, collection);
@@ -5222,20 +5284,38 @@ var Resolver = class {
5222
5284
  docsWithRefs
5223
5285
  )) {
5224
5286
  let docWithRef = await this.getRaw(pathToDocWithRef);
5287
+ let hasUpdate = false;
5225
5288
  for (const path7 of referencePaths) {
5226
- docWithRef = updateObjectWithJsonPath(
5289
+ const { object: object2, updated } = updateObjectWithJsonPath(
5227
5290
  docWithRef,
5228
5291
  path7,
5292
+ realPath,
5229
5293
  newRealPath
5230
5294
  );
5295
+ docWithRef = object2;
5296
+ hasUpdate = updated || hasUpdate;
5297
+ }
5298
+ if (hasUpdate) {
5299
+ const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
5300
+ if (!collectionWithRef) {
5301
+ throw new Error(
5302
+ `Unable to find collection for ${pathToDocWithRef}`
5303
+ );
5304
+ }
5305
+ await this.database.put(
5306
+ pathToDocWithRef,
5307
+ docWithRef,
5308
+ collectionWithRef.name
5309
+ );
5231
5310
  }
5232
- await this.database.put(pathToDocWithRef, docWithRef, collection2);
5233
5311
  }
5234
5312
  }
5235
5313
  return this.getDocument(newRealPath);
5236
5314
  }
5237
5315
  if (alreadyExists === false) {
5238
- 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
+ );
5239
5319
  }
5240
5320
  return this.updateResolveDocument({
5241
5321
  collection,
@@ -6577,8 +6657,35 @@ var Database = class {
6577
6657
  ]
6578
6658
  }
6579
6659
  };
6580
- if (collection.fields) {
6581
- 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) {
6582
6689
  if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
6583
6690
  continue;
6584
6691
  }
@@ -7005,7 +7112,13 @@ var Database = class {
7005
7112
  );
7006
7113
  }
7007
7114
  } else {
7008
- await _indexContent(this, level, contentPaths, enqueueOps, collection);
7115
+ await _indexContent(
7116
+ this,
7117
+ level,
7118
+ contentPaths,
7119
+ enqueueOps,
7120
+ collection
7121
+ );
7009
7122
  }
7010
7123
  }
7011
7124
  );
@@ -40,6 +40,17 @@ export declare const transformDocumentIntoPayload: (fullPath: string, rawData: {
40
40
  __typename: string;
41
41
  id: string;
42
42
  }>;
43
+ /**
44
+ * Updates a property in an object using a JSONPath.
45
+ * @param obj - The object to update.
46
+ * @param path - The JSONPath string.
47
+ * @param newValue - The new value to set at the specified path.
48
+ * @returns the updated object.
49
+ */
50
+ export declare const updateObjectWithJsonPath: (obj: any, path: string, oldValue: any, newValue: any) => {
51
+ object: any;
52
+ updated: boolean;
53
+ };
43
54
  /**
44
55
  * The resolver provides functions for all possible types of lookup
45
56
  * values and retrieves them from the database
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "0.0.0-d9672bc-20250218033222",
3
+ "version": "0.0.0-df15737-20250329200825",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "typings": "dist/index.d.ts",
@@ -26,12 +26,12 @@
26
26
  "@iarna/toml": "^2.2.5",
27
27
  "abstract-level": "^1.0.4",
28
28
  "date-fns": "^2.30.0",
29
- "fast-glob": "^3.3.2",
30
- "fs-extra": "^11.2.0",
29
+ "fast-glob": "^3.3.3",
30
+ "fs-extra": "^11.3.0",
31
31
  "glob-parent": "^6.0.2",
32
32
  "graphql": "15.8.0",
33
33
  "gray-matter": "^4.0.3",
34
- "isomorphic-git": "^1.27.1",
34
+ "isomorphic-git": "^1.29.0",
35
35
  "js-sha1": "^0.6.0",
36
36
  "js-yaml": "^3.14.1",
37
37
  "jsonpath-plus": "10.1.0",
@@ -41,11 +41,11 @@
41
41
  "many-level": "^2.0.0",
42
42
  "micromatch": "4.0.8",
43
43
  "normalize-path": "^3.0.0",
44
- "readable-stream": "^4.5.2",
44
+ "readable-stream": "^4.7.0",
45
45
  "scmp": "^2.1.0",
46
46
  "yup": "^0.32.11",
47
- "@tinacms/mdx": "0.0.0-d9672bc-20250218033222",
48
- "@tinacms/schema-tools": "0.0.0-d9672bc-20250218033222"
47
+ "@tinacms/mdx": "1.6.1",
48
+ "@tinacms/schema-tools": "1.7.2"
49
49
  },
50
50
  "publishConfig": {
51
51
  "registry": "https://registry.npmjs.org"
@@ -65,19 +65,19 @@
65
65
  "@types/lru-cache": "^5.1.1",
66
66
  "@types/mdast": "^3.0.15",
67
67
  "@types/micromatch": "^4.0.9",
68
- "@types/node": "^22.9.0",
68
+ "@types/node": "^22.13.1",
69
69
  "@types/normalize-path": "^3.0.2",
70
70
  "@types/ws": "^7.4.7",
71
71
  "@types/yup": "^0.29.14",
72
72
  "jest-file-snapshot": "^0.5.0",
73
73
  "memory-level": "^1.0.0",
74
74
  "nodemon": "3.1.4",
75
- "typescript": "^5.6.3",
76
- "vite": "^4.3.9",
77
- "vitest": "^0.32.2",
78
- "zod": "^3.23.8",
79
- "@tinacms/schema-tools": "0.0.0-d9672bc-20250218033222",
80
- "@tinacms/scripts": "1.3.1"
75
+ "typescript": "^5.7.3",
76
+ "vite": "^4.5.9",
77
+ "vitest": "^0.32.4",
78
+ "zod": "^3.24.2",
79
+ "@tinacms/schema-tools": "1.7.2",
80
+ "@tinacms/scripts": "1.3.3"
81
81
  },
82
82
  "scripts": {
83
83
  "types": "pnpm tsc",