@tinacms/graphql 1.5.12 → 1.5.14

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.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.14",
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
 
@@ -4035,6 +4035,9 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
4035
4035
 
4036
4036
  // src/database/datalayer.ts
4037
4037
  var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
4038
+ var REFS_COLLECTIONS_SORT_KEY = "__refs__";
4039
+ var REFS_REFERENCE_FIELD = "__tina_ref__";
4040
+ var REFS_PATH_FIELD = "__tina_ref_path__";
4038
4041
  var DEFAULT_NUMERIC_LPAD = 4;
4039
4042
  var applyPadding = (input, pad) => {
4040
4043
  if (pad) {
@@ -4608,6 +4611,57 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
4608
4611
  }
4609
4612
  return result;
4610
4613
  };
4614
+ var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
4615
+ const result = [];
4616
+ if (collection) {
4617
+ for (const [c, referencePaths] of Object.entries(references || {})) {
4618
+ if (!referencePaths.length) {
4619
+ continue;
4620
+ }
4621
+ const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
4622
+ const refSublevel = collectionSublevel.sublevel(
4623
+ REFS_COLLECTIONS_SORT_KEY,
4624
+ SUBLEVEL_OPTIONS
4625
+ );
4626
+ const references2 = {};
4627
+ for (const path7 of referencePaths) {
4628
+ const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
4629
+ if (!ref) {
4630
+ continue;
4631
+ }
4632
+ if (Array.isArray(ref)) {
4633
+ for (const r of ref) {
4634
+ if (!r) {
4635
+ continue;
4636
+ }
4637
+ if (references2[r]) {
4638
+ references2[r].push(path7);
4639
+ } else {
4640
+ references2[r] = [path7];
4641
+ }
4642
+ }
4643
+ } else {
4644
+ if (references2[ref]) {
4645
+ references2[ref].push(path7);
4646
+ } else {
4647
+ references2[ref] = [path7];
4648
+ }
4649
+ }
4650
+ }
4651
+ for (const ref of Object.keys(references2)) {
4652
+ for (const path7 of references2[ref]) {
4653
+ result.push({
4654
+ type: opType,
4655
+ key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4656
+ sublevel: refSublevel,
4657
+ value: opType === "put" ? {} : void 0
4658
+ });
4659
+ }
4660
+ }
4661
+ }
4662
+ }
4663
+ return result;
4664
+ };
4611
4665
  var makeStringEscaper = (regex, replacement) => {
4612
4666
  return (input) => {
4613
4667
  if (Array.isArray(input)) {
@@ -4829,24 +4883,29 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4829
4883
  throw e;
4830
4884
  }
4831
4885
  };
4832
- var updateObjectWithJsonPath = (obj, path7, newValue) => {
4886
+ var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
4887
+ let updated = false;
4833
4888
  if (!path7.includes(".") && !path7.includes("[")) {
4834
- if (path7 in obj) {
4889
+ if (path7 in obj && obj[path7] === oldValue) {
4835
4890
  obj[path7] = newValue;
4891
+ updated = true;
4836
4892
  }
4837
- return obj;
4893
+ return { object: obj, updated };
4838
4894
  }
4839
- const parentPath = path7.replace(/\.[^.]+$/, "");
4840
- const keyToUpdate = path7.match(/[^.]+$/)[0];
4895
+ const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
4896
+ const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
4841
4897
  const parents = (0, import_jsonpath_plus2.JSONPath)({ path: parentPath, json: obj, resultType: "value" });
4842
4898
  if (parents.length > 0) {
4843
4899
  parents.forEach((parent) => {
4844
4900
  if (parent && typeof parent === "object" && keyToUpdate in parent) {
4845
- parent[keyToUpdate] = newValue;
4901
+ if (parent[keyToUpdate] === oldValue) {
4902
+ parent[keyToUpdate] = newValue;
4903
+ updated = true;
4904
+ }
4846
4905
  }
4847
4906
  });
4848
4907
  }
4849
- return obj;
4908
+ return { object: obj, updated };
4850
4909
  };
4851
4910
  var Resolver = class {
4852
4911
  constructor(init) {
@@ -5225,17 +5284,35 @@ var Resolver = class {
5225
5284
  await this.deleteDocument(realPath);
5226
5285
  if (await this.hasReferences(realPath, collection)) {
5227
5286
  const collRefs = await this.findReferences(realPath, collection);
5228
- for (const [collection2, refFields] of Object.entries(collRefs)) {
5229
- for (const [refPath, refs] of Object.entries(refFields)) {
5230
- let refDoc = await this.getRaw(refPath);
5231
- for (const ref of refs) {
5232
- refDoc = updateObjectWithJsonPath(
5287
+ for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
5288
+ for (const [pathToDocWithRef, referencePaths] of Object.entries(
5289
+ docsWithRefs
5290
+ )) {
5291
+ let refDoc = await this.getRaw(pathToDocWithRef);
5292
+ let hasUpdate = false;
5293
+ for (const path7 of referencePaths) {
5294
+ const { object: object2, updated } = updateObjectWithJsonPath(
5233
5295
  refDoc,
5234
- ref.path.join("."),
5296
+ path7,
5297
+ realPath,
5235
5298
  null
5236
5299
  );
5300
+ refDoc = object2;
5301
+ hasUpdate = updated || hasUpdate;
5302
+ }
5303
+ if (hasUpdate) {
5304
+ const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
5305
+ if (!collectionWithRef) {
5306
+ throw new Error(
5307
+ `Unable to find collection for ${pathToDocWithRef}`
5308
+ );
5309
+ }
5310
+ await this.database.put(
5311
+ pathToDocWithRef,
5312
+ refDoc,
5313
+ collectionWithRef.name
5314
+ );
5237
5315
  }
5238
- await this.database.put(refPath, refDoc, collection2);
5239
5316
  }
5240
5317
  }
5241
5318
  }
@@ -5255,20 +5332,41 @@ var Resolver = class {
5255
5332
  collection == null ? void 0 : collection.path,
5256
5333
  args.params.relativePath
5257
5334
  );
5335
+ if (newRealPath === realPath) {
5336
+ return doc;
5337
+ }
5258
5338
  await this.database.put(newRealPath, doc._rawData, collection.name);
5259
5339
  await this.deleteDocument(realPath);
5260
5340
  const collRefs = await this.findReferences(realPath, collection);
5261
- for (const [collection2, refFields] of Object.entries(collRefs)) {
5262
- for (const [refPath, refs] of Object.entries(refFields)) {
5263
- let refDoc = await this.getRaw(refPath);
5264
- for (const ref of refs) {
5265
- refDoc = updateObjectWithJsonPath(
5266
- refDoc,
5267
- ref.path.join("."),
5341
+ for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
5342
+ for (const [pathToDocWithRef, referencePaths] of Object.entries(
5343
+ docsWithRefs
5344
+ )) {
5345
+ let docWithRef = await this.getRaw(pathToDocWithRef);
5346
+ let hasUpdate = false;
5347
+ for (const path7 of referencePaths) {
5348
+ const { object: object2, updated } = updateObjectWithJsonPath(
5349
+ docWithRef,
5350
+ path7,
5351
+ realPath,
5268
5352
  newRealPath
5269
5353
  );
5354
+ docWithRef = object2;
5355
+ hasUpdate = updated || hasUpdate;
5356
+ }
5357
+ if (hasUpdate) {
5358
+ const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
5359
+ if (!collectionWithRef) {
5360
+ throw new Error(
5361
+ `Unable to find collection for ${pathToDocWithRef}`
5362
+ );
5363
+ }
5364
+ await this.database.put(
5365
+ pathToDocWithRef,
5366
+ docWithRef,
5367
+ collectionWithRef.name
5368
+ );
5270
5369
  }
5271
- await this.database.put(refPath, refDoc, collection2);
5272
5370
  }
5273
5371
  }
5274
5372
  return this.getDocument(newRealPath);
@@ -5400,35 +5498,30 @@ var Resolver = class {
5400
5498
  */
5401
5499
  this.hasReferences = async (id, c) => {
5402
5500
  let count = 0;
5403
- const deepRefs = this.tinaSchema.findReferences(c.name);
5404
- for (const [collection, refs] of Object.entries(deepRefs)) {
5405
- for (const ref of refs) {
5406
- await this.database.query(
5407
- {
5408
- collection,
5409
- filterChain: makeFilterChain({
5410
- conditions: [
5411
- {
5412
- filterPath: ref.path.join("."),
5413
- filterExpression: {
5414
- _type: "reference",
5415
- _list: false,
5416
- eq: id
5417
- }
5418
- }
5419
- ]
5420
- }),
5421
- sort: ref.field.name
5422
- },
5423
- (refId) => {
5424
- count++;
5425
- return refId;
5426
- }
5427
- );
5428
- if (count) {
5429
- return true;
5430
- }
5501
+ await this.database.query(
5502
+ {
5503
+ collection: c.name,
5504
+ filterChain: makeFilterChain({
5505
+ conditions: [
5506
+ {
5507
+ filterPath: REFS_REFERENCE_FIELD,
5508
+ filterExpression: {
5509
+ _type: "string",
5510
+ _list: false,
5511
+ eq: id
5512
+ }
5513
+ }
5514
+ ]
5515
+ }),
5516
+ sort: REFS_COLLECTIONS_SORT_KEY
5517
+ },
5518
+ (refId) => {
5519
+ count++;
5520
+ return refId;
5431
5521
  }
5522
+ );
5523
+ if (count) {
5524
+ return true;
5432
5525
  }
5433
5526
  return false;
5434
5527
  };
@@ -5436,46 +5529,41 @@ var Resolver = class {
5436
5529
  * Finds references to a document
5437
5530
  * @param id the id of the document to find references to
5438
5531
  * @param c the collection to find references in
5439
- * @returns references to the document in the form of a map of collection names to a list of fields that reference the document
5532
+ * @returns a map of references to the document
5440
5533
  */
5441
5534
  this.findReferences = async (id, c) => {
5442
5535
  const references = {};
5443
- const deepRefs = this.tinaSchema.findReferences(c.name);
5444
- for (const [collection, refs] of Object.entries(deepRefs)) {
5445
- for (const ref of refs) {
5446
- await this.database.query(
5447
- {
5448
- collection,
5449
- filterChain: makeFilterChain({
5450
- conditions: [
5451
- {
5452
- filterPath: ref.path.join("."),
5453
- filterExpression: {
5454
- _type: "reference",
5455
- _list: false,
5456
- eq: id
5457
- }
5458
- }
5459
- ]
5460
- }),
5461
- sort: ref.field.name
5462
- },
5463
- (refId) => {
5464
- if (!references[collection]) {
5465
- references[collection] = {};
5466
- }
5467
- if (!references[collection][refId]) {
5468
- references[collection][refId] = [];
5536
+ await this.database.query(
5537
+ {
5538
+ collection: c.name,
5539
+ filterChain: makeFilterChain({
5540
+ conditions: [
5541
+ {
5542
+ filterPath: REFS_REFERENCE_FIELD,
5543
+ filterExpression: {
5544
+ _type: "string",
5545
+ _list: false,
5546
+ eq: id
5547
+ }
5469
5548
  }
5470
- references[collection][refId].push({
5471
- path: ref.path,
5472
- field: ref.field
5473
- });
5474
- return refId;
5475
- }
5476
- );
5549
+ ]
5550
+ }),
5551
+ sort: REFS_COLLECTIONS_SORT_KEY
5552
+ },
5553
+ (refId, rawItem) => {
5554
+ if (!references[c.name]) {
5555
+ references[c.name] = {};
5556
+ }
5557
+ if (!references[c.name][refId]) {
5558
+ references[c.name][refId] = [];
5559
+ }
5560
+ const referencePath = rawItem == null ? void 0 : rawItem[REFS_PATH_FIELD];
5561
+ if (referencePath) {
5562
+ references[c.name][refId].push(referencePath);
5563
+ }
5564
+ return refId;
5477
5565
  }
5478
- }
5566
+ );
5479
5567
  return references;
5480
5568
  };
5481
5569
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
@@ -6211,6 +6299,7 @@ var Database = class {
6211
6299
  }
6212
6300
  };
6213
6301
  this.addPendingDocument = async (filepath, data) => {
6302
+ var _a;
6214
6303
  await this.initLevel();
6215
6304
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6216
6305
  const collection = await this.collectionForPath(filepath);
@@ -6224,6 +6313,7 @@ var Database = class {
6224
6313
  );
6225
6314
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6226
6315
  const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
6316
+ const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
6227
6317
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6228
6318
  if (!(collection == null ? void 0 : collection.isDetached)) {
6229
6319
  if (this.bridge) {
@@ -6252,6 +6342,14 @@ var Database = class {
6252
6342
  let delOps = [];
6253
6343
  if (!isGitKeep(normalizedPath, collection)) {
6254
6344
  putOps = [
6345
+ ...makeRefOpsForDocument(
6346
+ normalizedPath,
6347
+ collection == null ? void 0 : collection.name,
6348
+ collectionReferences,
6349
+ dataFields,
6350
+ "put",
6351
+ level
6352
+ ),
6255
6353
  ...makeIndexOpsForDocument(
6256
6354
  normalizedPath,
6257
6355
  collection == null ? void 0 : collection.name,
@@ -6275,6 +6373,14 @@ var Database = class {
6275
6373
  SUBLEVEL_OPTIONS
6276
6374
  ).get(normalizedPath);
6277
6375
  delOps = existingItem ? [
6376
+ ...makeRefOpsForDocument(
6377
+ normalizedPath,
6378
+ collection == null ? void 0 : collection.name,
6379
+ collectionReferences,
6380
+ existingItem,
6381
+ "del",
6382
+ level
6383
+ ),
6278
6384
  ...makeIndexOpsForDocument(
6279
6385
  normalizedPath,
6280
6386
  collection == null ? void 0 : collection.name,
@@ -6310,7 +6416,7 @@ var Database = class {
6310
6416
  await level.batch(ops);
6311
6417
  };
6312
6418
  this.put = async (filepath, data, collectionName) => {
6313
- var _a, _b;
6419
+ var _a, _b, _c;
6314
6420
  await this.initLevel();
6315
6421
  try {
6316
6422
  if (SYSTEM_FILES.includes(filepath)) {
@@ -6323,13 +6429,14 @@ var Database = class {
6323
6429
  );
6324
6430
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
6325
6431
  }
6432
+ const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collectionName];
6326
6433
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6327
6434
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6328
6435
  const collection = await this.collectionForPath(filepath);
6329
6436
  if (!collection) {
6330
6437
  throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
6331
6438
  }
6332
- if (((_a = collection.match) == null ? void 0 : _a.exclude) || ((_b = collection.match) == null ? void 0 : _b.include)) {
6439
+ if (((_b = collection.match) == null ? void 0 : _b.exclude) || ((_c = collection.match) == null ? void 0 : _c.include)) {
6333
6440
  const matches = this.tinaSchema.getMatches({ collection });
6334
6441
  const match = import_micromatch2.default.isMatch(filepath, matches);
6335
6442
  if (!match) {
@@ -6370,6 +6477,14 @@ var Database = class {
6370
6477
  let delOps = [];
6371
6478
  if (!isGitKeep(normalizedPath, collection)) {
6372
6479
  putOps = [
6480
+ ...makeRefOpsForDocument(
6481
+ normalizedPath,
6482
+ collectionName,
6483
+ collectionReferences,
6484
+ dataFields,
6485
+ "put",
6486
+ level
6487
+ ),
6373
6488
  ...makeIndexOpsForDocument(
6374
6489
  normalizedPath,
6375
6490
  collectionName,
@@ -6393,6 +6508,14 @@ var Database = class {
6393
6508
  SUBLEVEL_OPTIONS
6394
6509
  ).get(normalizedPath);
6395
6510
  delOps = existingItem ? [
6511
+ ...makeRefOpsForDocument(
6512
+ normalizedPath,
6513
+ collectionName,
6514
+ collectionReferences,
6515
+ existingItem,
6516
+ "del",
6517
+ level
6518
+ ),
6396
6519
  ...makeIndexOpsForDocument(
6397
6520
  normalizedPath,
6398
6521
  collectionName,
@@ -6555,6 +6678,22 @@ var Database = class {
6555
6678
  this.tinaSchema = await createSchema({ schema });
6556
6679
  return this.tinaSchema;
6557
6680
  };
6681
+ this.getCollectionReferences = async (level) => {
6682
+ if (this.collectionReferences) {
6683
+ return this.collectionReferences;
6684
+ }
6685
+ const result = {};
6686
+ const schema = await this.getSchema(level || this.contentLevel);
6687
+ const collections = schema.getCollections();
6688
+ for (const collection of collections) {
6689
+ const collectionReferences = this.tinaSchema.findReferencesFromCollection(
6690
+ collection.name
6691
+ );
6692
+ result[collection.name] = collectionReferences;
6693
+ }
6694
+ this.collectionReferences = result;
6695
+ return result;
6696
+ };
6558
6697
  this.getIndexDefinitions = async (level) => {
6559
6698
  if (!this.collectionIndexDefinitions) {
6560
6699
  await new Promise(async (resolve2, reject) => {
@@ -6564,8 +6703,23 @@ var Database = class {
6564
6703
  const collections = schema.getCollections();
6565
6704
  for (const collection of collections) {
6566
6705
  const indexDefinitions = {
6567
- [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
6706
+ [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] },
6568
6707
  // provide a default sort key which is the file sort
6708
+ // pseudo-index for the collection's references
6709
+ [REFS_COLLECTIONS_SORT_KEY]: {
6710
+ fields: [
6711
+ {
6712
+ name: REFS_REFERENCE_FIELD,
6713
+ type: "string",
6714
+ list: false
6715
+ },
6716
+ {
6717
+ name: REFS_PATH_FIELD,
6718
+ type: "string",
6719
+ list: false
6720
+ }
6721
+ ]
6722
+ }
6569
6723
  };
6570
6724
  if (collection.fields) {
6571
6725
  for (const field of collection.fields) {
@@ -6717,29 +6871,36 @@ var Database = class {
6717
6871
  }
6718
6872
  startKey = startKey || key || "";
6719
6873
  endKey = key || "";
6720
- edges = [...edges, { cursor: key, path: filepath }];
6874
+ edges = [...edges, { cursor: key, path: filepath, value: itemRecord }];
6721
6875
  }
6722
6876
  return {
6723
- edges: await sequential(edges, async (edge) => {
6724
- try {
6725
- const node = await hydrator(edge.path);
6726
- return {
6727
- node,
6728
- cursor: btoa(edge.cursor)
6729
- };
6730
- } catch (error) {
6731
- console.log(error);
6732
- if (error instanceof Error && (!edge.path.includes(".tina/__generated__/_graphql.json") || !edge.path.includes("tina/__generated__/_graphql.json"))) {
6733
- throw new TinaQueryError({
6734
- originalError: error,
6735
- file: edge.path,
6736
- collection: collection.name,
6737
- stack: error.stack
6738
- });
6877
+ edges: await sequential(
6878
+ edges,
6879
+ async ({
6880
+ cursor,
6881
+ path: path7,
6882
+ value
6883
+ }) => {
6884
+ try {
6885
+ const node = await hydrator(path7, value);
6886
+ return {
6887
+ node,
6888
+ cursor: btoa(cursor)
6889
+ };
6890
+ } catch (error) {
6891
+ console.log(error);
6892
+ if (error instanceof Error && (!path7.includes(".tina/__generated__/_graphql.json") || !path7.includes("tina/__generated__/_graphql.json"))) {
6893
+ throw new TinaQueryError({
6894
+ originalError: error,
6895
+ file: path7,
6896
+ collection: collection.name,
6897
+ stack: error.stack
6898
+ });
6899
+ }
6900
+ throw error;
6739
6901
  }
6740
- throw error;
6741
6902
  }
6742
- }),
6903
+ ),
6743
6904
  pageInfo: {
6744
6905
  hasPreviousPage,
6745
6906
  hasNextPage,
@@ -6879,12 +7040,14 @@ var Database = class {
6879
7040
  }
6880
7041
  };
6881
7042
  this.delete = async (filepath) => {
7043
+ var _a;
6882
7044
  await this.initLevel();
6883
7045
  const collection = await this.collectionForPath(filepath);
6884
7046
  if (!collection) {
6885
7047
  throw new Error(`No collection found for path: ${filepath}`);
6886
7048
  }
6887
7049
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
7050
+ const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
6888
7051
  const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
6889
7052
  let level = this.contentLevel;
6890
7053
  if (collection == null ? void 0 : collection.isDetached) {
@@ -6903,6 +7066,14 @@ var Database = class {
6903
7066
  collection.path || ""
6904
7067
  );
6905
7068
  await this.contentLevel.batch([
7069
+ ...makeRefOpsForDocument(
7070
+ normalizedPath,
7071
+ collection.name,
7072
+ collectionReferences,
7073
+ item,
7074
+ "del",
7075
+ level
7076
+ ),
6906
7077
  ...makeIndexOpsForDocument(
6907
7078
  normalizedPath,
6908
7079
  collection.name,
@@ -7120,6 +7291,7 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
7120
7291
  );
7121
7292
  var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${(collection == null ? void 0 : collection.format) || "md"}`);
7122
7293
  var _indexContent = async (database, level, documentPaths, enqueueOps, collection, passwordFields) => {
7294
+ var _a;
7123
7295
  let collectionIndexDefinitions;
7124
7296
  let collectionPath;
7125
7297
  if (collection) {
@@ -7130,6 +7302,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7130
7302
  }
7131
7303
  collectionPath = collection.path;
7132
7304
  }
7305
+ const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7133
7306
  const tinaSchema = await database.getSchema();
7134
7307
  let templateInfo = null;
7135
7308
  if (collection) {
@@ -7162,6 +7335,14 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7162
7335
  const item = await rootSublevel.get(normalizedPath);
7163
7336
  if (item) {
7164
7337
  await database.contentLevel.batch([
7338
+ ...makeRefOpsForDocument(
7339
+ normalizedPath,
7340
+ collection == null ? void 0 : collection.name,
7341
+ collectionReferences,
7342
+ item,
7343
+ "del",
7344
+ level
7345
+ ),
7165
7346
  ...makeIndexOpsForDocument(
7166
7347
  normalizedPath,
7167
7348
  collection.name,
@@ -7188,6 +7369,14 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7188
7369
  }
7189
7370
  if (!isGitKeep(filepath, collection)) {
7190
7371
  await enqueueOps([
7372
+ ...makeRefOpsForDocument(
7373
+ normalizedPath,
7374
+ collection == null ? void 0 : collection.name,
7375
+ collectionReferences,
7376
+ aliasedData,
7377
+ "put",
7378
+ level
7379
+ ),
7191
7380
  ...makeIndexOpsForDocument(
7192
7381
  normalizedPath,
7193
7382
  collection == null ? void 0 : collection.name,
@@ -7238,6 +7427,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7238
7427
  }
7239
7428
  };
7240
7429
  var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
7430
+ var _a;
7241
7431
  if (!documentPaths.length) {
7242
7432
  return;
7243
7433
  }
@@ -7251,6 +7441,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7251
7441
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7252
7442
  }
7253
7443
  }
7444
+ const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7254
7445
  const tinaSchema = await database.getSchema();
7255
7446
  let templateInfo = null;
7256
7447
  if (collection) {
@@ -7274,6 +7465,14 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7274
7465
  item
7275
7466
  ) : item;
7276
7467
  await enqueueOps([
7468
+ ...makeRefOpsForDocument(
7469
+ itemKey,
7470
+ collection == null ? void 0 : collection.name,
7471
+ collectionReferences,
7472
+ aliasedData,
7473
+ "del",
7474
+ database.contentLevel
7475
+ ),
7277
7476
  ...makeIndexOpsForDocument(
7278
7477
  itemKey,
7279
7478
  collection.name,