@tinacms/graphql 0.0.0-d7c745e-20250102002342 → 0.0.0-db8aa8e-20250228034006

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.mjs CHANGED
@@ -1029,41 +1029,6 @@ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
1029
1029
  yield maybeNode;
1030
1030
  visited.add(maybeNode);
1031
1031
  }
1032
- function addNamespaceToSchema(maybeNode, namespace = []) {
1033
- if (typeof maybeNode === "string") {
1034
- return maybeNode;
1035
- }
1036
- if (typeof maybeNode === "boolean") {
1037
- return maybeNode;
1038
- }
1039
- const newNode = maybeNode;
1040
- const keys = Object.keys(maybeNode);
1041
- Object.values(maybeNode).map((m, index) => {
1042
- const key = keys[index];
1043
- if (Array.isArray(m)) {
1044
- newNode[key] = m.map((element) => {
1045
- if (!element) {
1046
- return;
1047
- }
1048
- if (!element.hasOwnProperty("name")) {
1049
- return element;
1050
- }
1051
- const value = element.name || element.value;
1052
- return addNamespaceToSchema(element, [...namespace, value]);
1053
- });
1054
- } else {
1055
- if (!m) {
1056
- return;
1057
- }
1058
- if (!m.hasOwnProperty("name")) {
1059
- newNode[key] = m;
1060
- } else {
1061
- newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
1062
- }
1063
- }
1064
- });
1065
- return { ...newNode, namespace };
1066
- }
1067
1032
  var generateNamespacedFieldName = (names, suffix = "") => {
1068
1033
  return (suffix ? [...names, suffix] : names).map(capitalize).join("");
1069
1034
  };
@@ -2898,6 +2863,7 @@ var filterSelections = (arr) => {
2898
2863
  import { TinaSchema } from "@tinacms/schema-tools";
2899
2864
 
2900
2865
  // src/schema/validate.ts
2866
+ import { addNamespaceToSchema } from "@tinacms/schema-tools";
2901
2867
  import deepClone from "lodash.clonedeep";
2902
2868
  import * as yup2 from "yup";
2903
2869
  import {
@@ -3053,7 +3019,7 @@ var validateField = async (field) => {
3053
3019
  // package.json
3054
3020
  var package_default = {
3055
3021
  name: "@tinacms/graphql",
3056
- version: "1.5.9",
3022
+ version: "1.5.13",
3057
3023
  main: "dist/index.js",
3058
3024
  module: "dist/index.mjs",
3059
3025
  typings: "dist/index.d.ts",
@@ -3080,8 +3046,8 @@ var package_default = {
3080
3046
  build: "tinacms-scripts build",
3081
3047
  docs: "pnpm typedoc",
3082
3048
  serve: "pnpm nodemon dist/server.js",
3083
- test: "jest",
3084
- "test-watch": "jest --watch"
3049
+ test: "vitest run",
3050
+ "test-watch": "vitest"
3085
3051
  },
3086
3052
  dependencies: {
3087
3053
  "@iarna/toml": "^2.2.5",
@@ -3089,12 +3055,12 @@ var package_default = {
3089
3055
  "@tinacms/schema-tools": "workspace:*",
3090
3056
  "abstract-level": "^1.0.4",
3091
3057
  "date-fns": "^2.30.0",
3092
- "fast-glob": "^3.3.2",
3093
- "fs-extra": "^11.2.0",
3058
+ "fast-glob": "^3.3.3",
3059
+ "fs-extra": "^11.3.0",
3094
3060
  "glob-parent": "^6.0.2",
3095
3061
  graphql: "15.8.0",
3096
3062
  "gray-matter": "^4.0.3",
3097
- "isomorphic-git": "^1.27.1",
3063
+ "isomorphic-git": "^1.29.0",
3098
3064
  "js-sha1": "^0.6.0",
3099
3065
  "js-yaml": "^3.14.1",
3100
3066
  "jsonpath-plus": "10.1.0",
@@ -3104,7 +3070,7 @@ var package_default = {
3104
3070
  "many-level": "^2.0.0",
3105
3071
  micromatch: "4.0.8",
3106
3072
  "normalize-path": "^3.0.0",
3107
- "readable-stream": "^4.5.2",
3073
+ "readable-stream": "^4.7.0",
3108
3074
  scmp: "^2.1.0",
3109
3075
  yup: "^0.32.11"
3110
3076
  },
@@ -3122,24 +3088,23 @@ var package_default = {
3122
3088
  "@types/estree": "^0.0.50",
3123
3089
  "@types/express": "^4.17.21",
3124
3090
  "@types/fs-extra": "^9.0.13",
3125
- "@types/jest": "^26.0.24",
3126
3091
  "@types/js-yaml": "^3.12.10",
3127
3092
  "@types/lodash.camelcase": "^4.3.9",
3128
3093
  "@types/lodash.upperfirst": "^4.3.9",
3129
3094
  "@types/lru-cache": "^5.1.1",
3130
3095
  "@types/mdast": "^3.0.15",
3131
3096
  "@types/micromatch": "^4.0.9",
3132
- "@types/node": "^22.9.0",
3097
+ "@types/node": "^22.13.1",
3133
3098
  "@types/normalize-path": "^3.0.2",
3134
3099
  "@types/ws": "^7.4.7",
3135
3100
  "@types/yup": "^0.29.14",
3136
- jest: "^29.7.0",
3137
- "jest-diff": "^29.7.0",
3138
3101
  "jest-file-snapshot": "^0.5.0",
3139
- "jest-matcher-utils": "^29.7.0",
3140
3102
  "memory-level": "^1.0.0",
3141
3103
  nodemon: "3.1.4",
3142
- typescript: "^5.6.3"
3104
+ typescript: "^5.7.3",
3105
+ vite: "^4.5.9",
3106
+ vitest: "^0.32.4",
3107
+ zod: "^3.24.2"
3143
3108
  }
3144
3109
  };
3145
3110
 
@@ -3995,6 +3960,9 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
3995
3960
 
3996
3961
  // src/database/datalayer.ts
3997
3962
  var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
3963
+ var REFS_COLLECTIONS_SORT_KEY = "__refs__";
3964
+ var REFS_REFERENCE_FIELD = "__tina_ref__";
3965
+ var REFS_PATH_FIELD = "__tina_ref_path__";
3998
3966
  var DEFAULT_NUMERIC_LPAD = 4;
3999
3967
  var applyPadding = (input, pad) => {
4000
3968
  if (pad) {
@@ -4568,6 +4536,51 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
4568
4536
  }
4569
4537
  return result;
4570
4538
  };
4539
+ var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
4540
+ const result = [];
4541
+ if (collection) {
4542
+ for (const [c, referencePaths] of Object.entries(references || {})) {
4543
+ if (!referencePaths.length) {
4544
+ continue;
4545
+ }
4546
+ const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
4547
+ const refSublevel = collectionSublevel.sublevel(
4548
+ REFS_COLLECTIONS_SORT_KEY,
4549
+ SUBLEVEL_OPTIONS
4550
+ );
4551
+ const references2 = {};
4552
+ for (const path7 of referencePaths) {
4553
+ const ref = JSONPath({ path: path7, json: data });
4554
+ if (Array.isArray(ref)) {
4555
+ for (const r of ref) {
4556
+ if (references2[r]) {
4557
+ references2[r].push(path7);
4558
+ } else {
4559
+ references2[r] = [path7];
4560
+ }
4561
+ }
4562
+ } else {
4563
+ if (references2[ref]) {
4564
+ references2[ref].push(path7);
4565
+ } else {
4566
+ references2[ref] = [path7];
4567
+ }
4568
+ }
4569
+ }
4570
+ for (const ref of Object.keys(references2)) {
4571
+ for (const path7 of references2[ref]) {
4572
+ result.push({
4573
+ type: opType,
4574
+ key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4575
+ sublevel: refSublevel,
4576
+ value: opType === "put" ? {} : void 0
4577
+ });
4578
+ }
4579
+ }
4580
+ }
4581
+ }
4582
+ return result;
4583
+ };
4571
4584
  var makeStringEscaper = (regex, replacement) => {
4572
4585
  return (input) => {
4573
4586
  if (Array.isArray(input)) {
@@ -4788,20 +4801,22 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4788
4801
  throw e;
4789
4802
  }
4790
4803
  };
4791
- var updateObjectWithJsonPath = (obj, path7, newValue) => {
4804
+ var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
4792
4805
  if (!path7.includes(".") && !path7.includes("[")) {
4793
- if (path7 in obj) {
4806
+ if (path7 in obj && obj[path7] === oldValue) {
4794
4807
  obj[path7] = newValue;
4795
4808
  }
4796
4809
  return obj;
4797
4810
  }
4798
- const parentPath = path7.replace(/\.[^.]+$/, "");
4799
- const keyToUpdate = path7.match(/[^.]+$/)[0];
4811
+ const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
4812
+ const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
4800
4813
  const parents = JSONPath2({ path: parentPath, json: obj, resultType: "value" });
4801
4814
  if (parents.length > 0) {
4802
4815
  parents.forEach((parent) => {
4803
4816
  if (parent && typeof parent === "object" && keyToUpdate in parent) {
4804
- parent[keyToUpdate] = newValue;
4817
+ if (parent[keyToUpdate] === oldValue) {
4818
+ parent[keyToUpdate] = newValue;
4819
+ }
4805
4820
  }
4806
4821
  });
4807
4822
  }
@@ -5183,17 +5198,15 @@ var Resolver = class {
5183
5198
  await this.deleteDocument(realPath);
5184
5199
  if (await this.hasReferences(realPath, collection)) {
5185
5200
  const collRefs = await this.findReferences(realPath, collection);
5186
- for (const [collection2, refFields] of Object.entries(collRefs)) {
5187
- for (const [refPath, refs] of Object.entries(refFields)) {
5188
- let refDoc = await this.getRaw(refPath);
5189
- for (const ref of refs) {
5190
- refDoc = updateObjectWithJsonPath(
5191
- refDoc,
5192
- ref.path.join("."),
5193
- null
5194
- );
5201
+ for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
5202
+ for (const [pathToDocWithRef, referencePaths] of Object.entries(
5203
+ docsWithRefs
5204
+ )) {
5205
+ let refDoc = await this.getRaw(pathToDocWithRef);
5206
+ for (const path7 of referencePaths) {
5207
+ refDoc = updateObjectWithJsonPath(refDoc, path7, realPath, null);
5195
5208
  }
5196
- await this.database.put(refPath, refDoc, collection2);
5209
+ await this.database.put(pathToDocWithRef, refDoc, collection2);
5197
5210
  }
5198
5211
  }
5199
5212
  }
@@ -5213,20 +5226,26 @@ var Resolver = class {
5213
5226
  collection?.path,
5214
5227
  args.params.relativePath
5215
5228
  );
5229
+ if (newRealPath === realPath) {
5230
+ return doc;
5231
+ }
5216
5232
  await this.database.put(newRealPath, doc._rawData, collection.name);
5217
5233
  await this.deleteDocument(realPath);
5218
5234
  const collRefs = await this.findReferences(realPath, collection);
5219
- for (const [collection2, refFields] of Object.entries(collRefs)) {
5220
- for (const [refPath, refs] of Object.entries(refFields)) {
5221
- let refDoc = await this.getRaw(refPath);
5222
- for (const ref of refs) {
5223
- refDoc = updateObjectWithJsonPath(
5224
- refDoc,
5225
- ref.path.join("."),
5235
+ for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
5236
+ for (const [pathToDocWithRef, referencePaths] of Object.entries(
5237
+ docsWithRefs
5238
+ )) {
5239
+ let docWithRef = await this.getRaw(pathToDocWithRef);
5240
+ for (const path7 of referencePaths) {
5241
+ docWithRef = updateObjectWithJsonPath(
5242
+ docWithRef,
5243
+ path7,
5244
+ realPath,
5226
5245
  newRealPath
5227
5246
  );
5228
5247
  }
5229
- await this.database.put(refPath, refDoc, collection2);
5248
+ await this.database.put(pathToDocWithRef, docWithRef, collection2);
5230
5249
  }
5231
5250
  }
5232
5251
  return this.getDocument(newRealPath);
@@ -5358,35 +5377,30 @@ var Resolver = class {
5358
5377
  */
5359
5378
  this.hasReferences = async (id, c) => {
5360
5379
  let count = 0;
5361
- const deepRefs = this.tinaSchema.findReferences(c.name);
5362
- for (const [collection, refs] of Object.entries(deepRefs)) {
5363
- for (const ref of refs) {
5364
- await this.database.query(
5365
- {
5366
- collection,
5367
- filterChain: makeFilterChain({
5368
- conditions: [
5369
- {
5370
- filterPath: ref.path.join("."),
5371
- filterExpression: {
5372
- _type: "reference",
5373
- _list: false,
5374
- eq: id
5375
- }
5376
- }
5377
- ]
5378
- }),
5379
- sort: ref.field.name
5380
- },
5381
- (refId) => {
5382
- count++;
5383
- return refId;
5384
- }
5385
- );
5386
- if (count) {
5387
- return true;
5388
- }
5380
+ await this.database.query(
5381
+ {
5382
+ collection: c.name,
5383
+ filterChain: makeFilterChain({
5384
+ conditions: [
5385
+ {
5386
+ filterPath: REFS_REFERENCE_FIELD,
5387
+ filterExpression: {
5388
+ _type: "string",
5389
+ _list: false,
5390
+ eq: id
5391
+ }
5392
+ }
5393
+ ]
5394
+ }),
5395
+ sort: REFS_COLLECTIONS_SORT_KEY
5396
+ },
5397
+ (refId) => {
5398
+ count++;
5399
+ return refId;
5389
5400
  }
5401
+ );
5402
+ if (count) {
5403
+ return true;
5390
5404
  }
5391
5405
  return false;
5392
5406
  };
@@ -5394,46 +5408,41 @@ var Resolver = class {
5394
5408
  * Finds references to a document
5395
5409
  * @param id the id of the document to find references to
5396
5410
  * @param c the collection to find references in
5397
- * @returns references to the document in the form of a map of collection names to a list of fields that reference the document
5411
+ * @returns a map of references to the document
5398
5412
  */
5399
5413
  this.findReferences = async (id, c) => {
5400
5414
  const references = {};
5401
- const deepRefs = this.tinaSchema.findReferences(c.name);
5402
- for (const [collection, refs] of Object.entries(deepRefs)) {
5403
- for (const ref of refs) {
5404
- await this.database.query(
5405
- {
5406
- collection,
5407
- filterChain: makeFilterChain({
5408
- conditions: [
5409
- {
5410
- filterPath: ref.path.join("."),
5411
- filterExpression: {
5412
- _type: "reference",
5413
- _list: false,
5414
- eq: id
5415
- }
5416
- }
5417
- ]
5418
- }),
5419
- sort: ref.field.name
5420
- },
5421
- (refId) => {
5422
- if (!references[collection]) {
5423
- references[collection] = {};
5424
- }
5425
- if (!references[collection][refId]) {
5426
- references[collection][refId] = [];
5415
+ await this.database.query(
5416
+ {
5417
+ collection: c.name,
5418
+ filterChain: makeFilterChain({
5419
+ conditions: [
5420
+ {
5421
+ filterPath: REFS_REFERENCE_FIELD,
5422
+ filterExpression: {
5423
+ _type: "string",
5424
+ _list: false,
5425
+ eq: id
5426
+ }
5427
5427
  }
5428
- references[collection][refId].push({
5429
- path: ref.path,
5430
- field: ref.field
5431
- });
5432
- return refId;
5433
- }
5434
- );
5428
+ ]
5429
+ }),
5430
+ sort: REFS_COLLECTIONS_SORT_KEY
5431
+ },
5432
+ (refId, rawItem) => {
5433
+ if (!references[c.name]) {
5434
+ references[c.name] = {};
5435
+ }
5436
+ if (!references[c.name][refId]) {
5437
+ references[c.name][refId] = [];
5438
+ }
5439
+ const referencePath = rawItem?.[REFS_PATH_FIELD];
5440
+ if (referencePath) {
5441
+ references[c.name][refId].push(referencePath);
5442
+ }
5443
+ return refId;
5435
5444
  }
5436
- }
5445
+ );
5437
5446
  return references;
5438
5447
  };
5439
5448
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
@@ -6177,6 +6186,7 @@ var Database = class {
6177
6186
  );
6178
6187
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6179
6188
  const collectionIndexDefinitions = indexDefinitions?.[collection.name];
6189
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
6180
6190
  const normalizedPath = normalizePath(filepath);
6181
6191
  if (!collection?.isDetached) {
6182
6192
  if (this.bridge) {
@@ -6205,6 +6215,14 @@ var Database = class {
6205
6215
  let delOps = [];
6206
6216
  if (!isGitKeep(normalizedPath, collection)) {
6207
6217
  putOps = [
6218
+ ...makeRefOpsForDocument(
6219
+ normalizedPath,
6220
+ collection?.name,
6221
+ collectionReferences,
6222
+ dataFields,
6223
+ "put",
6224
+ level
6225
+ ),
6208
6226
  ...makeIndexOpsForDocument(
6209
6227
  normalizedPath,
6210
6228
  collection?.name,
@@ -6228,6 +6246,14 @@ var Database = class {
6228
6246
  SUBLEVEL_OPTIONS
6229
6247
  ).get(normalizedPath);
6230
6248
  delOps = existingItem ? [
6249
+ ...makeRefOpsForDocument(
6250
+ normalizedPath,
6251
+ collection?.name,
6252
+ collectionReferences,
6253
+ existingItem,
6254
+ "del",
6255
+ level
6256
+ ),
6231
6257
  ...makeIndexOpsForDocument(
6232
6258
  normalizedPath,
6233
6259
  collection?.name,
@@ -6275,6 +6301,7 @@ var Database = class {
6275
6301
  );
6276
6302
  collectionIndexDefinitions = indexDefinitions?.[collectionName];
6277
6303
  }
6304
+ const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
6278
6305
  const normalizedPath = normalizePath(filepath);
6279
6306
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6280
6307
  const collection = await this.collectionForPath(filepath);
@@ -6322,6 +6349,14 @@ var Database = class {
6322
6349
  let delOps = [];
6323
6350
  if (!isGitKeep(normalizedPath, collection)) {
6324
6351
  putOps = [
6352
+ ...makeRefOpsForDocument(
6353
+ normalizedPath,
6354
+ collectionName,
6355
+ collectionReferences,
6356
+ dataFields,
6357
+ "put",
6358
+ level
6359
+ ),
6325
6360
  ...makeIndexOpsForDocument(
6326
6361
  normalizedPath,
6327
6362
  collectionName,
@@ -6345,6 +6380,14 @@ var Database = class {
6345
6380
  SUBLEVEL_OPTIONS
6346
6381
  ).get(normalizedPath);
6347
6382
  delOps = existingItem ? [
6383
+ ...makeRefOpsForDocument(
6384
+ normalizedPath,
6385
+ collectionName,
6386
+ collectionReferences,
6387
+ existingItem,
6388
+ "del",
6389
+ level
6390
+ ),
6348
6391
  ...makeIndexOpsForDocument(
6349
6392
  normalizedPath,
6350
6393
  collectionName,
@@ -6507,6 +6550,22 @@ var Database = class {
6507
6550
  this.tinaSchema = await createSchema({ schema });
6508
6551
  return this.tinaSchema;
6509
6552
  };
6553
+ this.getCollectionReferences = async (level) => {
6554
+ if (this.collectionReferences) {
6555
+ return this.collectionReferences;
6556
+ }
6557
+ const result = {};
6558
+ const schema = await this.getSchema(level || this.contentLevel);
6559
+ const collections = schema.getCollections();
6560
+ for (const collection of collections) {
6561
+ const collectionReferences = this.tinaSchema.findReferencesFromCollection(
6562
+ collection.name
6563
+ );
6564
+ result[collection.name] = collectionReferences;
6565
+ }
6566
+ this.collectionReferences = result;
6567
+ return result;
6568
+ };
6510
6569
  this.getIndexDefinitions = async (level) => {
6511
6570
  if (!this.collectionIndexDefinitions) {
6512
6571
  await new Promise(async (resolve2, reject) => {
@@ -6516,8 +6575,23 @@ var Database = class {
6516
6575
  const collections = schema.getCollections();
6517
6576
  for (const collection of collections) {
6518
6577
  const indexDefinitions = {
6519
- [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
6578
+ [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] },
6520
6579
  // provide a default sort key which is the file sort
6580
+ // pseudo-index for the collection's references
6581
+ [REFS_COLLECTIONS_SORT_KEY]: {
6582
+ fields: [
6583
+ {
6584
+ name: REFS_REFERENCE_FIELD,
6585
+ type: "string",
6586
+ list: false
6587
+ },
6588
+ {
6589
+ name: REFS_PATH_FIELD,
6590
+ type: "string",
6591
+ list: false
6592
+ }
6593
+ ]
6594
+ }
6521
6595
  };
6522
6596
  if (collection.fields) {
6523
6597
  for (const field of collection.fields) {
@@ -6668,29 +6742,36 @@ var Database = class {
6668
6742
  }
6669
6743
  startKey = startKey || key || "";
6670
6744
  endKey = key || "";
6671
- edges = [...edges, { cursor: key, path: filepath }];
6745
+ edges = [...edges, { cursor: key, path: filepath, value: itemRecord }];
6672
6746
  }
6673
6747
  return {
6674
- edges: await sequential(edges, async (edge) => {
6675
- try {
6676
- const node = await hydrator(edge.path);
6677
- return {
6678
- node,
6679
- cursor: btoa(edge.cursor)
6680
- };
6681
- } catch (error) {
6682
- console.log(error);
6683
- if (error instanceof Error && (!edge.path.includes(".tina/__generated__/_graphql.json") || !edge.path.includes("tina/__generated__/_graphql.json"))) {
6684
- throw new TinaQueryError({
6685
- originalError: error,
6686
- file: edge.path,
6687
- collection: collection.name,
6688
- stack: error.stack
6689
- });
6748
+ edges: await sequential(
6749
+ edges,
6750
+ async ({
6751
+ cursor,
6752
+ path: path7,
6753
+ value
6754
+ }) => {
6755
+ try {
6756
+ const node = await hydrator(path7, value);
6757
+ return {
6758
+ node,
6759
+ cursor: btoa(cursor)
6760
+ };
6761
+ } catch (error) {
6762
+ console.log(error);
6763
+ if (error instanceof Error && (!path7.includes(".tina/__generated__/_graphql.json") || !path7.includes("tina/__generated__/_graphql.json"))) {
6764
+ throw new TinaQueryError({
6765
+ originalError: error,
6766
+ file: path7,
6767
+ collection: collection.name,
6768
+ stack: error.stack
6769
+ });
6770
+ }
6771
+ throw error;
6690
6772
  }
6691
- throw error;
6692
6773
  }
6693
- }),
6774
+ ),
6694
6775
  pageInfo: {
6695
6776
  hasPreviousPage,
6696
6777
  hasNextPage,
@@ -6836,6 +6917,7 @@ var Database = class {
6836
6917
  throw new Error(`No collection found for path: ${filepath}`);
6837
6918
  }
6838
6919
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6920
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
6839
6921
  const collectionIndexDefinitions = indexDefinitions?.[collection.name];
6840
6922
  let level = this.contentLevel;
6841
6923
  if (collection?.isDetached) {
@@ -6854,6 +6936,14 @@ var Database = class {
6854
6936
  collection.path || ""
6855
6937
  );
6856
6938
  await this.contentLevel.batch([
6939
+ ...makeRefOpsForDocument(
6940
+ normalizedPath,
6941
+ collection.name,
6942
+ collectionReferences,
6943
+ item,
6944
+ "del",
6945
+ level
6946
+ ),
6857
6947
  ...makeIndexOpsForDocument(
6858
6948
  normalizedPath,
6859
6949
  collection.name,
@@ -7081,6 +7171,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7081
7171
  }
7082
7172
  collectionPath = collection.path;
7083
7173
  }
7174
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7084
7175
  const tinaSchema = await database.getSchema();
7085
7176
  let templateInfo = null;
7086
7177
  if (collection) {
@@ -7102,12 +7193,59 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7102
7193
  await hashPasswordValues(aliasedData, passwordFields);
7103
7194
  }
7104
7195
  const normalizedPath = normalizePath(filepath);
7196
+ const rootSublevel = level.sublevel(
7197
+ CONTENT_ROOT_PREFIX,
7198
+ SUBLEVEL_OPTIONS
7199
+ );
7105
7200
  const folderKey = folderTreeBuilder.update(
7106
7201
  normalizedPath,
7107
7202
  collectionPath || ""
7108
7203
  );
7204
+ const item = await rootSublevel.get(normalizedPath);
7205
+ if (item) {
7206
+ await database.contentLevel.batch([
7207
+ ...makeRefOpsForDocument(
7208
+ normalizedPath,
7209
+ collection?.name,
7210
+ collectionReferences,
7211
+ item,
7212
+ "del",
7213
+ level
7214
+ ),
7215
+ ...makeIndexOpsForDocument(
7216
+ normalizedPath,
7217
+ collection.name,
7218
+ collectionIndexDefinitions,
7219
+ item,
7220
+ "del",
7221
+ level
7222
+ ),
7223
+ // folder indices
7224
+ ...makeIndexOpsForDocument(
7225
+ normalizedPath,
7226
+ `${collection.name}_${folderKey}`,
7227
+ collectionIndexDefinitions,
7228
+ item,
7229
+ "del",
7230
+ level
7231
+ ),
7232
+ {
7233
+ type: "del",
7234
+ key: normalizedPath,
7235
+ sublevel: rootSublevel
7236
+ }
7237
+ ]);
7238
+ }
7109
7239
  if (!isGitKeep(filepath, collection)) {
7110
7240
  await enqueueOps([
7241
+ ...makeRefOpsForDocument(
7242
+ normalizedPath,
7243
+ collection?.name,
7244
+ collectionReferences,
7245
+ aliasedData,
7246
+ "put",
7247
+ level
7248
+ ),
7111
7249
  ...makeIndexOpsForDocument(
7112
7250
  normalizedPath,
7113
7251
  collection?.name,
@@ -7171,6 +7309,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7171
7309
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7172
7310
  }
7173
7311
  }
7312
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7174
7313
  const tinaSchema = await database.getSchema();
7175
7314
  let templateInfo = null;
7176
7315
  if (collection) {
@@ -7194,6 +7333,14 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7194
7333
  item
7195
7334
  ) : item;
7196
7335
  await enqueueOps([
7336
+ ...makeRefOpsForDocument(
7337
+ itemKey,
7338
+ collection?.name,
7339
+ collectionReferences,
7340
+ aliasedData,
7341
+ "del",
7342
+ database.contentLevel
7343
+ ),
7197
7344
  ...makeIndexOpsForDocument(
7198
7345
  itemKey,
7199
7346
  collection.name,