@tinacms/graphql 0.0.0-d9672bc-20250218033222 → 0.0.0-ddc5e8e-20250611011547

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");
@@ -1435,13 +1435,12 @@ var checkPasswordHash = async ({
1435
1435
  return true;
1436
1436
  };
1437
1437
  var mapUserFields = (collectable, prefix = []) => {
1438
- var _a, _b, _c, _d, _e;
1439
1438
  const results = [];
1440
- const passwordFields = ((_a = collectable.fields) == null ? void 0 : _a.filter((field) => field.type === "password")) || [];
1439
+ const passwordFields = collectable.fields?.filter((field) => field.type === "password") || [];
1441
1440
  if (passwordFields.length > 1) {
1442
1441
  throw new Error("Only one password field is allowed");
1443
1442
  }
1444
- const idFields = ((_b = collectable.fields) == null ? void 0 : _b.filter((field) => field.uid)) || [];
1443
+ const idFields = collectable.fields?.filter((field) => field.uid) || [];
1445
1444
  if (idFields.length > 1) {
1446
1445
  throw new Error("Only one uid field is allowed");
1447
1446
  }
@@ -1449,11 +1448,11 @@ var mapUserFields = (collectable, prefix = []) => {
1449
1448
  results.push({
1450
1449
  path: prefix,
1451
1450
  collectable,
1452
- idFieldName: (_c = idFields[0]) == null ? void 0 : _c.name,
1453
- passwordFieldName: (_d = passwordFields[0]) == null ? void 0 : _d.name
1451
+ idFieldName: idFields[0]?.name,
1452
+ passwordFieldName: passwordFields[0]?.name
1454
1453
  });
1455
1454
  }
1456
- (_e = collectable.fields) == null ? void 0 : _e.forEach((field) => {
1455
+ collectable.fields?.forEach((field) => {
1457
1456
  if (field.type === "object" && field.fields) {
1458
1457
  results.push(...mapUserFields(field, [...prefix, field.name]));
1459
1458
  }
@@ -1914,7 +1913,7 @@ var Builder = class {
1914
1913
  * ```
1915
1914
  *
1916
1915
  * @public
1917
- * @param collection a Tina Cloud collection
1916
+ * @param collection a TinaCloud collection
1918
1917
  */
1919
1918
  this.collectionFragment = async (collection) => {
1920
1919
  const name = NAMER.dataTypeName(collection.namespace);
@@ -1944,13 +1943,12 @@ var Builder = class {
1944
1943
  *
1945
1944
  * */
1946
1945
  this._getCollectionFragmentSelections = async (collection, depth) => {
1947
- var _a;
1948
1946
  const selections = [];
1949
1947
  selections.push({
1950
1948
  name: { kind: "Name", value: "__typename" },
1951
1949
  kind: "Field"
1952
1950
  });
1953
- if (((_a = collection.fields) == null ? void 0 : _a.length) > 0) {
1951
+ if (collection.fields?.length > 0) {
1954
1952
  await sequential(collection.fields, async (x) => {
1955
1953
  const field = await this._buildFieldNodeForFragments(x, depth);
1956
1954
  selections.push(field);
@@ -1965,7 +1963,6 @@ var Builder = class {
1965
1963
  return selections;
1966
1964
  };
1967
1965
  this._buildFieldNodeForFragments = async (field, depth) => {
1968
- var _a, _b;
1969
1966
  switch (field.type) {
1970
1967
  case "string":
1971
1968
  case "image":
@@ -1998,7 +1995,7 @@ var Builder = class {
1998
1995
  selections: filterSelections([passwordValue, passwordChangeRequired])
1999
1996
  });
2000
1997
  case "object":
2001
- if (((_a = field.fields) == null ? void 0 : _a.length) > 0) {
1998
+ if (field.fields?.length > 0) {
2002
1999
  const selections2 = [];
2003
2000
  await sequential(field.fields, async (item) => {
2004
2001
  const field2 = await this._buildFieldNodeForFragments(item, depth);
@@ -2011,7 +2008,7 @@ var Builder = class {
2011
2008
  ...filterSelections(selections2)
2012
2009
  ]
2013
2010
  });
2014
- } else if (((_b = field.templates) == null ? void 0 : _b.length) > 0) {
2011
+ } else if (field.templates?.length > 0) {
2015
2012
  const selections2 = [];
2016
2013
  await sequential(field.templates, async (tem) => {
2017
2014
  if (typeof tem === "object") {
@@ -2673,7 +2670,7 @@ var Builder = class {
2673
2670
  this.addToLookupMap({
2674
2671
  type: name,
2675
2672
  resolveType: "unionData",
2676
- collection: collection == null ? void 0 : collection.name,
2673
+ collection: collection?.name,
2677
2674
  typeMap
2678
2675
  });
2679
2676
  return astBuilder.UnionTypeDefinition({ name, types });
@@ -2883,9 +2880,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2883
2880
  ]
2884
2881
  });
2885
2882
  };
2886
- var _a, _b, _c, _d;
2887
2883
  this.maxDepth = // @ts-ignore
2888
- (_d = (_c = (_b = (_a = config == null ? void 0 : config.tinaSchema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.client) == null ? void 0 : _c.referenceDepth) != null ? _d : 2;
2884
+ config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
2889
2885
  this.tinaSchema = config.tinaSchema;
2890
2886
  this.lookupMap = {};
2891
2887
  }
@@ -2974,7 +2970,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2974
2970
  return;
2975
2971
  }
2976
2972
  const noMatchCollections = collections.filter((x) => {
2977
- return typeof (x == null ? void 0 : x.match) === "undefined";
2973
+ return typeof x?.match === "undefined";
2978
2974
  }).map((x) => `${x.path}${x.format || "md"}`);
2979
2975
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2980
2976
  throw new Error(
@@ -2985,10 +2981,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2985
2981
  const hasMatchAndPath = collections.filter((x) => {
2986
2982
  return typeof x.path !== "undefined" && typeof x.match !== "undefined";
2987
2983
  }).map(
2988
- (x) => {
2989
- var _a, _b;
2990
- return `${x.path}|${((_a = x == null ? void 0 : x.match) == null ? void 0 : _a.exclude) || ""}|${((_b = x == null ? void 0 : x.match) == null ? void 0 : _b.include) || ""}|${x.format || "md"}`;
2991
- }
2984
+ (x) => `${x.path}|${x?.match?.exclude || ""}|${x?.match?.include || ""}|${x.format || "md"}`
2992
2985
  );
2993
2986
  if (hasMatchAndPath.length !== new Set(hasMatchAndPath).size) {
2994
2987
  throw new Error(
@@ -3012,7 +3005,7 @@ var validationCollectionsPathAndMatch = (collections) => {
3012
3005
  );
3013
3006
  }
3014
3007
  const matches = collectionsArr.map(
3015
- (x) => typeof (x == null ? void 0 : x.match) === "object" ? JSON.stringify(x.match) : ""
3008
+ (x) => typeof x?.match === "object" ? JSON.stringify(x.match) : ""
3016
3009
  );
3017
3010
  if (matches.length === new Set(matches).size) {
3018
3011
  return;
@@ -3090,7 +3083,7 @@ var validateField = async (field) => {
3090
3083
  // package.json
3091
3084
  var package_default = {
3092
3085
  name: "@tinacms/graphql",
3093
- version: "1.5.12",
3086
+ version: "1.5.18",
3094
3087
  main: "dist/index.js",
3095
3088
  module: "dist/index.mjs",
3096
3089
  typings: "dist/index.d.ts",
@@ -3116,33 +3109,32 @@ var package_default = {
3116
3109
  types: "pnpm tsc",
3117
3110
  build: "tinacms-scripts build",
3118
3111
  docs: "pnpm typedoc",
3119
- serve: "pnpm nodemon dist/server.js",
3120
3112
  test: "vitest run",
3121
3113
  "test-watch": "vitest"
3122
3114
  },
3123
3115
  dependencies: {
3124
- "@iarna/toml": "^2.2.5",
3116
+ "@iarna/toml": "catalog:",
3125
3117
  "@tinacms/mdx": "workspace:*",
3126
3118
  "@tinacms/schema-tools": "workspace:*",
3127
- "abstract-level": "^1.0.4",
3119
+ "abstract-level": "catalog:",
3128
3120
  "date-fns": "^2.30.0",
3129
- "fast-glob": "^3.3.2",
3130
- "fs-extra": "^11.2.0",
3131
- "glob-parent": "^6.0.2",
3121
+ "fast-glob": "catalog:",
3122
+ "fs-extra": "catalog:",
3123
+ "glob-parent": "catalog:",
3132
3124
  graphql: "15.8.0",
3133
- "gray-matter": "^4.0.3",
3134
- "isomorphic-git": "^1.27.1",
3135
- "js-sha1": "^0.6.0",
3125
+ "gray-matter": "catalog:",
3126
+ "isomorphic-git": "catalog:",
3127
+ "js-sha1": "catalog:",
3136
3128
  "js-yaml": "^3.14.1",
3137
- "jsonpath-plus": "10.1.0",
3138
- "lodash.clonedeep": "^4.5.0",
3139
- "lodash.set": "^4.3.2",
3140
- "lodash.uniqby": "^4.7.0",
3141
- "many-level": "^2.0.0",
3142
- micromatch: "4.0.8",
3143
- "normalize-path": "^3.0.0",
3144
- "readable-stream": "^4.5.2",
3145
- scmp: "^2.1.0",
3129
+ "jsonpath-plus": "catalog:",
3130
+ "lodash.clonedeep": "catalog:",
3131
+ "lodash.set": "catalog:",
3132
+ "lodash.uniqby": "catalog:",
3133
+ "many-level": "catalog:",
3134
+ micromatch: "catalog:",
3135
+ "normalize-path": "catalog:",
3136
+ "readable-stream": "catalog:",
3137
+ scmp: "catalog:",
3146
3138
  yup: "^0.32.11"
3147
3139
  },
3148
3140
  publishConfig: {
@@ -3157,25 +3149,24 @@ var package_default = {
3157
3149
  "@tinacms/scripts": "workspace:*",
3158
3150
  "@types/cors": "^2.8.17",
3159
3151
  "@types/estree": "^0.0.50",
3160
- "@types/express": "^4.17.21",
3152
+ "@types/express": "catalog:",
3161
3153
  "@types/fs-extra": "^9.0.13",
3162
3154
  "@types/js-yaml": "^3.12.10",
3163
- "@types/lodash.camelcase": "^4.3.9",
3164
- "@types/lodash.upperfirst": "^4.3.9",
3165
- "@types/lru-cache": "^5.1.1",
3166
- "@types/mdast": "^3.0.15",
3167
- "@types/micromatch": "^4.0.9",
3168
- "@types/node": "^22.9.0",
3169
- "@types/normalize-path": "^3.0.2",
3170
- "@types/ws": "^7.4.7",
3155
+ "@types/lodash.camelcase": "catalog:",
3156
+ "@types/lodash.upperfirst": "catalog:",
3157
+ "@types/lru-cache": "catalog:",
3158
+ "@types/mdast": "catalog:",
3159
+ "@types/micromatch": "catalog:",
3160
+ "@types/node": "^22.13.1",
3161
+ "@types/normalize-path": "catalog:",
3162
+ "@types/ws": "catalog:",
3171
3163
  "@types/yup": "^0.29.14",
3172
3164
  "jest-file-snapshot": "^0.5.0",
3173
- "memory-level": "^1.0.0",
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"
3165
+ "memory-level": "catalog:",
3166
+ typescript: "^5.7.3",
3167
+ vite: "^4.5.9",
3168
+ vitest: "^0.32.4",
3169
+ zod: "^3.24.2"
3179
3170
  }
3180
3171
  };
3181
3172
 
@@ -3257,7 +3248,6 @@ var _buildQueries = async (builder, tinaSchema) => {
3257
3248
  const operationsDefinitions = [];
3258
3249
  const collections = tinaSchema.getCollections();
3259
3250
  await sequential(collections, async (collection) => {
3260
- var _a, _b, _c;
3261
3251
  const queryName = NAMER.queryName(collection.namespace);
3262
3252
  const queryListName = NAMER.generateQueryListName(collection.namespace);
3263
3253
  const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
@@ -3272,7 +3262,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3272
3262
  filterType: queryFilterTypeName,
3273
3263
  // look for flag to see if the data layer is enabled
3274
3264
  dataLayer: Boolean(
3275
- (_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
3265
+ tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
3276
3266
  )
3277
3267
  })
3278
3268
  );
@@ -3332,7 +3322,9 @@ var _buildSchema = async (builder, tinaSchema) => {
3332
3322
  await builder.buildCreateCollectionFolderMutation()
3333
3323
  );
3334
3324
  await sequential(collections, async (collection) => {
3335
- queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
3325
+ queryTypeDefinitionFields.push(
3326
+ await builder.collectionDocument(collection)
3327
+ );
3336
3328
  if (collection.isAuthCollection) {
3337
3329
  queryTypeDefinitionFields.push(
3338
3330
  await builder.authenticationCollectionDocument(collection)
@@ -3620,9 +3612,8 @@ var cleanUpSlashes = (path7) => {
3620
3612
  return "";
3621
3613
  };
3622
3614
  var hasTinaMediaConfig = (schema) => {
3623
- var _a, _b, _c, _d, _e, _f, _g, _h;
3624
- if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3625
- if (typeof ((_e = (_d = (_c = schema.config) == null ? void 0 : _c.media) == null ? void 0 : _d.tina) == null ? void 0 : _e.publicFolder) !== "string" && typeof ((_h = (_g = (_f = schema.config) == null ? void 0 : _f.media) == null ? void 0 : _g.tina) == null ? void 0 : _h.mediaRoot) !== "string")
3615
+ if (!schema.config?.media?.tina) return false;
3616
+ if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
3626
3617
  return false;
3627
3618
  return true;
3628
3619
  };
@@ -3648,7 +3639,9 @@ var LevelProxyHandler = {
3648
3639
  throw new Error(`The property, ${property.toString()}, doesn't exist`);
3649
3640
  }
3650
3641
  if (typeof target[property] !== "function") {
3651
- throw new Error(`The property, ${property.toString()}, is not a function`);
3642
+ throw new Error(
3643
+ `The property, ${property.toString()}, is not a function`
3644
+ );
3652
3645
  }
3653
3646
  if (property === "get") {
3654
3647
  return async (...args) => {
@@ -3727,22 +3720,20 @@ var replaceNameOverrides = (template, obj) => {
3727
3720
  }
3728
3721
  };
3729
3722
  function isBlockField(field) {
3730
- var _a;
3731
- return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
3723
+ return field && field.type === "object" && field.templates?.length > 0;
3732
3724
  }
3733
3725
  var _replaceNameOverrides = (fields, obj) => {
3734
3726
  const output = {};
3735
3727
  Object.keys(obj).forEach((key) => {
3736
3728
  const field = fields.find(
3737
- (fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key
3729
+ (fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
3738
3730
  );
3739
- output[(field == null ? void 0 : field.name) || key] = (field == null ? void 0 : field.type) == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
3731
+ output[field?.name || key] = field?.type == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
3740
3732
  });
3741
3733
  return output;
3742
3734
  };
3743
3735
  var getTemplateForData = (field, data) => {
3744
- var _a;
3745
- if ((_a = field.templates) == null ? void 0 : _a.length) {
3736
+ if (field.templates?.length) {
3746
3737
  const templateKey = "_template";
3747
3738
  if (data[templateKey]) {
3748
3739
  const result = field.templates.find(
@@ -3800,8 +3791,8 @@ var _applyNameOverrides = (fields, obj) => {
3800
3791
  const output = {};
3801
3792
  Object.keys(obj).forEach((key) => {
3802
3793
  const field = fields.find((field2) => field2.name === key);
3803
- const outputKey = (field == null ? void 0 : field.nameOverride) || key;
3804
- output[outputKey] = (field == null ? void 0 : field.type) === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
3794
+ const outputKey = field?.nameOverride || key;
3795
+ output[outputKey] = field?.type === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
3805
3796
  });
3806
3797
  return output;
3807
3798
  };
@@ -3814,7 +3805,6 @@ var matterEngines = {
3814
3805
  }
3815
3806
  };
3816
3807
  var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3817
- var _a, _b;
3818
3808
  const {
3819
3809
  _relativePath,
3820
3810
  _keepTemplateKey,
@@ -3838,9 +3828,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3838
3828
  ${$_body}`,
3839
3829
  strippedContent,
3840
3830
  {
3841
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3831
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3842
3832
  engines: matterEngines,
3843
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---"
3833
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
3844
3834
  }
3845
3835
  );
3846
3836
  return ok;
@@ -3856,15 +3846,14 @@ ${$_body}`,
3856
3846
  }
3857
3847
  };
3858
3848
  var parseFile = (content, format, yupSchema, markdownParseConfig) => {
3859
- var _a, _b;
3860
3849
  try {
3861
3850
  switch (format) {
3862
3851
  case ".markdown":
3863
3852
  case ".mdx":
3864
3853
  case ".md":
3865
3854
  const contentJSON = (0, import_gray_matter.default)(content || "", {
3866
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3867
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---",
3855
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3856
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
3868
3857
  engines: matterEngines
3869
3858
  });
3870
3859
  const markdownData = {
@@ -3963,7 +3952,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3963
3952
  ),
3964
3953
  template: void 0
3965
3954
  } : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
3966
- const field = template == null ? void 0 : template.fields.find((field2) => {
3955
+ const field = template?.fields.find((field2) => {
3967
3956
  if (field2.type === "string" || field2.type === "rich-text") {
3968
3957
  if (field2.isBody) {
3969
3958
  return true;
@@ -3983,7 +3972,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3983
3972
  ...data,
3984
3973
  _collection: collection.name,
3985
3974
  _keepTemplateKey: !!collection.templates,
3986
- _template: (template == null ? void 0 : template.namespace) ? lastItem(template == null ? void 0 : template.namespace) : void 0,
3975
+ _template: template?.namespace ? lastItem(template?.namespace) : void 0,
3987
3976
  _relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
3988
3977
  _id: filepath
3989
3978
  };
@@ -3992,10 +3981,10 @@ function hasOwnProperty(obj, prop) {
3992
3981
  return obj.hasOwnProperty(prop);
3993
3982
  }
3994
3983
  var getTemplateForFile = (templateInfo, data) => {
3995
- if ((templateInfo == null ? void 0 : templateInfo.type) === "object") {
3984
+ if (templateInfo?.type === "object") {
3996
3985
  return templateInfo.template;
3997
3986
  }
3998
- if ((templateInfo == null ? void 0 : templateInfo.type) === "union") {
3987
+ if (templateInfo?.type === "union") {
3999
3988
  if (hasOwnProperty(data, "_template")) {
4000
3989
  const template = templateInfo.templates.find(
4001
3990
  (t) => lastItem(t.namespace) === data._template
@@ -4019,8 +4008,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
4019
4008
  import_path.default.extname(filepath),
4020
4009
  (yup3) => yup3.object({}),
4021
4010
  {
4022
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
4023
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
4011
+ frontmatterDelimiters: collection?.frontmatterDelimiters,
4012
+ frontmatterFormat: collection?.frontmatterFormat
4024
4013
  }
4025
4014
  );
4026
4015
  const template = getTemplateForFile(templateInfo, data);
@@ -4626,10 +4615,26 @@ var makeRefOpsForDocument = (filepath, collection, references, data, opType, lev
4626
4615
  const references2 = {};
4627
4616
  for (const path7 of referencePaths) {
4628
4617
  const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
4629
- if (references2[ref]) {
4630
- references2[ref].push(path7);
4618
+ if (!ref) {
4619
+ continue;
4620
+ }
4621
+ if (Array.isArray(ref)) {
4622
+ for (const r of ref) {
4623
+ if (!r) {
4624
+ continue;
4625
+ }
4626
+ if (references2[r]) {
4627
+ references2[r].push(path7);
4628
+ } else {
4629
+ references2[r] = [path7];
4630
+ }
4631
+ }
4631
4632
  } else {
4632
- references2[ref] = [path7];
4633
+ if (references2[ref]) {
4634
+ references2[ref].push(path7);
4635
+ } else {
4636
+ references2[ref] = [path7];
4637
+ }
4633
4638
  }
4634
4639
  }
4635
4640
  for (const ref of Object.keys(references2)) {
@@ -4671,7 +4676,6 @@ var createResolver = (args) => {
4671
4676
  return new Resolver(args);
4672
4677
  };
4673
4678
  var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4674
- var _a, _b;
4675
4679
  if (!rawData) {
4676
4680
  return void 0;
4677
4681
  }
@@ -4699,7 +4703,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4699
4703
  accumulator[field.name] = {
4700
4704
  value: void 0,
4701
4705
  // never resolve the password hash
4702
- passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4706
+ passwordChangeRequired: value["passwordChangeRequired"] ?? false
4703
4707
  };
4704
4708
  break;
4705
4709
  case "image":
@@ -4715,11 +4719,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4715
4719
  field,
4716
4720
  (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4717
4721
  );
4718
- if (((_b = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _b.type) === "invalid_markdown") {
4722
+ if (tree?.children[0]?.type === "invalid_markdown") {
4719
4723
  if (isAudit) {
4720
- const invalidNode = tree == null ? void 0 : tree.children[0];
4724
+ const invalidNode = tree?.children[0];
4721
4725
  throw new import_graphql3.GraphQLError(
4722
- `${invalidNode == null ? void 0 : invalidNode.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4726
+ `${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4723
4727
  );
4724
4728
  }
4725
4729
  }
@@ -4832,11 +4836,11 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4832
4836
  });
4833
4837
  }
4834
4838
  const titleField = template.fields.find((x) => {
4835
- if (x.type === "string" && (x == null ? void 0 : x.isTitle)) {
4839
+ if (x.type === "string" && x?.isTitle) {
4836
4840
  return true;
4837
4841
  }
4838
4842
  });
4839
- const titleFieldName = titleField == null ? void 0 : titleField.name;
4843
+ const titleFieldName = titleField?.name;
4840
4844
  const title = data[titleFieldName || " "] || null;
4841
4845
  return {
4842
4846
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
@@ -4867,24 +4871,33 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4867
4871
  throw e;
4868
4872
  }
4869
4873
  };
4870
- var updateObjectWithJsonPath = (obj, path7, newValue) => {
4874
+ var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
4875
+ let updated = false;
4871
4876
  if (!path7.includes(".") && !path7.includes("[")) {
4872
- if (path7 in obj) {
4877
+ if (path7 in obj && obj[path7] === oldValue) {
4873
4878
  obj[path7] = newValue;
4879
+ updated = true;
4874
4880
  }
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" });
4881
+ return { object: obj, updated };
4882
+ }
4883
+ const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
4884
+ const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
4885
+ const parents = (0, import_jsonpath_plus2.JSONPath)({
4886
+ path: parentPath,
4887
+ json: obj,
4888
+ resultType: "value"
4889
+ });
4880
4890
  if (parents.length > 0) {
4881
4891
  parents.forEach((parent) => {
4882
4892
  if (parent && typeof parent === "object" && keyToUpdate in parent) {
4883
- parent[keyToUpdate] = newValue;
4893
+ if (parent[keyToUpdate] === oldValue) {
4894
+ parent[keyToUpdate] = newValue;
4895
+ updated = true;
4896
+ }
4884
4897
  }
4885
4898
  });
4886
4899
  }
4887
- return obj;
4900
+ return { object: obj, updated };
4888
4901
  };
4889
4902
  var Resolver = class {
4890
4903
  constructor(init) {
@@ -4901,7 +4914,9 @@ var Resolver = class {
4901
4914
  };
4902
4915
  this.getRaw = async (fullPath) => {
4903
4916
  if (typeof fullPath !== "string") {
4904
- throw new Error(`fullPath must be of type string for getDocument request`);
4917
+ throw new Error(
4918
+ `fullPath must be of type string for getDocument request`
4919
+ );
4905
4920
  }
4906
4921
  return this.database.get(fullPath);
4907
4922
  };
@@ -4930,10 +4945,12 @@ var Resolver = class {
4930
4945
  };
4931
4946
  this.getDocument = async (fullPath, opts = {}) => {
4932
4947
  if (typeof fullPath !== "string") {
4933
- throw new Error(`fullPath must be of type string for getDocument request`);
4948
+ throw new Error(
4949
+ `fullPath must be of type string for getDocument request`
4950
+ );
4934
4951
  }
4935
4952
  const rawData = await this.getRaw(fullPath);
4936
- const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
4953
+ const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
4937
4954
  return transformDocumentIntoPayload(
4938
4955
  fullPath,
4939
4956
  rawData,
@@ -4945,7 +4962,9 @@ var Resolver = class {
4945
4962
  };
4946
4963
  this.deleteDocument = async (fullPath) => {
4947
4964
  if (typeof fullPath !== "string") {
4948
- throw new Error(`fullPath must be of type string for getDocument request`);
4965
+ throw new Error(
4966
+ `fullPath must be of type string for getDocument request`
4967
+ );
4949
4968
  }
4950
4969
  await this.database.delete(fullPath);
4951
4970
  };
@@ -4971,9 +4990,9 @@ var Resolver = class {
4971
4990
  return this.buildFieldMutations(
4972
4991
  item,
4973
4992
  objectTemplate,
4974
- idField && existingData && (existingData == null ? void 0 : existingData.find(
4993
+ idField && existingData && existingData?.find(
4975
4994
  (d) => d[idField.name] === item[idField.name]
4976
- ))
4995
+ )
4977
4996
  );
4978
4997
  }
4979
4998
  )
@@ -5099,7 +5118,7 @@ var Resolver = class {
5099
5118
  isCollectionSpecific
5100
5119
  }) => {
5101
5120
  const doc = await this.getDocument(realPath);
5102
- const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
5121
+ const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
5103
5122
  if (isAddPendingDocument === true) {
5104
5123
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
5105
5124
  const params2 = this.buildParams(args);
@@ -5109,7 +5128,7 @@ var Resolver = class {
5109
5128
  const values = await this.buildFieldMutations(
5110
5129
  params2,
5111
5130
  templateInfo.template,
5112
- doc == null ? void 0 : doc._rawData
5131
+ doc?._rawData
5113
5132
  );
5114
5133
  await this.database.put(
5115
5134
  realPath,
@@ -5133,7 +5152,7 @@ var Resolver = class {
5133
5152
  // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
5134
5153
  templateParams,
5135
5154
  template,
5136
- doc == null ? void 0 : doc._rawData
5155
+ doc?._rawData
5137
5156
  ),
5138
5157
  _template: lastItem(template.namespace)
5139
5158
  };
@@ -5147,9 +5166,13 @@ var Resolver = class {
5147
5166
  //@ts-ignore
5148
5167
  isCollectionSpecific ? args.params : args.params[collection.name],
5149
5168
  collection,
5150
- doc == null ? void 0 : doc._rawData
5169
+ doc?._rawData
5170
+ );
5171
+ await this.database.put(
5172
+ realPath,
5173
+ { ...oldDoc, ...params },
5174
+ collection.name
5151
5175
  );
5152
- await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
5153
5176
  return this.getDocument(realPath);
5154
5177
  };
5155
5178
  /**
@@ -5159,7 +5182,6 @@ var Resolver = class {
5159
5182
  this.resolveLegacyValues = (oldDoc, collection) => {
5160
5183
  const legacyValues = {};
5161
5184
  Object.entries(oldDoc).forEach(([key, value]) => {
5162
- var _a;
5163
5185
  const reservedKeys = [
5164
5186
  "$_body",
5165
5187
  "_collection",
@@ -5172,7 +5194,7 @@ var Resolver = class {
5172
5194
  return;
5173
5195
  }
5174
5196
  if (oldDoc._template && collection.templates) {
5175
- const template = (_a = collection.templates) == null ? void 0 : _a.find(
5197
+ const template = collection.templates?.find(
5176
5198
  ({ name }) => name === oldDoc._template
5177
5199
  );
5178
5200
  if (template) {
@@ -5219,7 +5241,7 @@ var Resolver = class {
5219
5241
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5220
5242
  );
5221
5243
  const collection = await this.tinaSchema.getCollection(collectionLookup);
5222
- let realPath = import_path3.default.join(collection == null ? void 0 : collection.path, args.relativePath);
5244
+ let realPath = import_path3.default.join(collection?.path, args.relativePath);
5223
5245
  if (isFolderCreation) {
5224
5246
  realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
5225
5247
  }
@@ -5268,10 +5290,30 @@ var Resolver = class {
5268
5290
  docsWithRefs
5269
5291
  )) {
5270
5292
  let refDoc = await this.getRaw(pathToDocWithRef);
5293
+ let hasUpdate = false;
5271
5294
  for (const path7 of referencePaths) {
5272
- refDoc = updateObjectWithJsonPath(refDoc, path7, null);
5295
+ const { object: object2, updated } = updateObjectWithJsonPath(
5296
+ refDoc,
5297
+ path7,
5298
+ realPath,
5299
+ null
5300
+ );
5301
+ refDoc = object2;
5302
+ hasUpdate = updated || hasUpdate;
5303
+ }
5304
+ if (hasUpdate) {
5305
+ const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
5306
+ if (!collectionWithRef) {
5307
+ throw new Error(
5308
+ `Unable to find collection for ${pathToDocWithRef}`
5309
+ );
5310
+ }
5311
+ await this.database.put(
5312
+ pathToDocWithRef,
5313
+ refDoc,
5314
+ collectionWithRef.name
5315
+ );
5273
5316
  }
5274
- await this.database.put(pathToDocWithRef, refDoc, collection2);
5275
5317
  }
5276
5318
  }
5277
5319
  }
@@ -5283,14 +5325,17 @@ var Resolver = class {
5283
5325
  (yup3) => yup3.object({ params: yup3.object().required() })
5284
5326
  );
5285
5327
  assertShape(
5286
- args == null ? void 0 : args.params,
5328
+ args?.params,
5287
5329
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5288
5330
  );
5289
5331
  const doc = await this.getDocument(realPath);
5290
5332
  const newRealPath = import_path3.default.join(
5291
- collection == null ? void 0 : collection.path,
5333
+ collection?.path,
5292
5334
  args.params.relativePath
5293
5335
  );
5336
+ if (newRealPath === realPath) {
5337
+ return doc;
5338
+ }
5294
5339
  await this.database.put(newRealPath, doc._rawData, collection.name);
5295
5340
  await this.deleteDocument(realPath);
5296
5341
  const collRefs = await this.findReferences(realPath, collection);
@@ -5299,20 +5344,38 @@ var Resolver = class {
5299
5344
  docsWithRefs
5300
5345
  )) {
5301
5346
  let docWithRef = await this.getRaw(pathToDocWithRef);
5347
+ let hasUpdate = false;
5302
5348
  for (const path7 of referencePaths) {
5303
- docWithRef = updateObjectWithJsonPath(
5349
+ const { object: object2, updated } = updateObjectWithJsonPath(
5304
5350
  docWithRef,
5305
5351
  path7,
5352
+ realPath,
5306
5353
  newRealPath
5307
5354
  );
5355
+ docWithRef = object2;
5356
+ hasUpdate = updated || hasUpdate;
5357
+ }
5358
+ if (hasUpdate) {
5359
+ const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
5360
+ if (!collectionWithRef) {
5361
+ throw new Error(
5362
+ `Unable to find collection for ${pathToDocWithRef}`
5363
+ );
5364
+ }
5365
+ await this.database.put(
5366
+ pathToDocWithRef,
5367
+ docWithRef,
5368
+ collectionWithRef.name
5369
+ );
5308
5370
  }
5309
- await this.database.put(pathToDocWithRef, docWithRef, collection2);
5310
5371
  }
5311
5372
  }
5312
5373
  return this.getDocument(newRealPath);
5313
5374
  }
5314
5375
  if (alreadyExists === false) {
5315
- throw new Error(`Unable to update document, ${realPath} does not exist`);
5376
+ throw new Error(
5377
+ `Unable to update document, ${realPath} does not exist`
5378
+ );
5316
5379
  }
5317
5380
  return this.updateResolveDocument({
5318
5381
  collection,
@@ -5497,7 +5560,7 @@ var Resolver = class {
5497
5560
  if (!references[c.name][refId]) {
5498
5561
  references[c.name][refId] = [];
5499
5562
  }
5500
- const referencePath = rawItem == null ? void 0 : rawItem[REFS_PATH_FIELD];
5563
+ const referencePath = rawItem?.[REFS_PATH_FIELD];
5501
5564
  if (referencePath) {
5502
5565
  references[c.name][refId].push(referencePath);
5503
5566
  }
@@ -5507,7 +5570,6 @@ var Resolver = class {
5507
5570
  return references;
5508
5571
  };
5509
5572
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
5510
- var _a;
5511
5573
  const accum = {};
5512
5574
  for (const passwordField of template.fields.filter(
5513
5575
  (f) => f.type === "password"
@@ -5550,7 +5612,7 @@ var Resolver = class {
5550
5612
  accum[fieldName] = await this.buildObjectMutations(
5551
5613
  fieldValue,
5552
5614
  field,
5553
- existingData == null ? void 0 : existingData[fieldName]
5615
+ existingData?.[fieldName]
5554
5616
  );
5555
5617
  break;
5556
5618
  case "password":
@@ -5569,7 +5631,7 @@ var Resolver = class {
5569
5631
  } else {
5570
5632
  accum[fieldName] = {
5571
5633
  ...fieldValue,
5572
- value: (_a = existingData == null ? void 0 : existingData[fieldName]) == null ? void 0 : _a["value"]
5634
+ value: existingData?.[fieldName]?.["value"]
5573
5635
  };
5574
5636
  }
5575
5637
  break;
@@ -5704,9 +5766,8 @@ var resolve = async ({
5704
5766
  isAudit,
5705
5767
  ctxUser
5706
5768
  }) => {
5707
- var _a;
5708
5769
  try {
5709
- const verboseValue = verbose != null ? verbose : true;
5770
+ const verboseValue = verbose ?? true;
5710
5771
  const graphQLSchemaAst = await database.getGraphQLSchema();
5711
5772
  if (!graphQLSchemaAst) {
5712
5773
  throw new import_graphql5.GraphQLError("GraphQL schema not found");
@@ -5718,7 +5779,7 @@ var resolve = async ({
5718
5779
  // @ts-ignore
5719
5780
  schema: tinaConfig,
5720
5781
  // @ts-ignore
5721
- flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5782
+ flags: tinaConfig?.meta?.flags
5722
5783
  });
5723
5784
  const resolver = createResolver({
5724
5785
  config,
@@ -5743,7 +5804,6 @@ var resolve = async ({
5743
5804
  throw new Error(`Unable to find lookup key for ${namedType}`);
5744
5805
  },
5745
5806
  fieldResolver: async (source = {}, _args = {}, _context, info) => {
5746
- var _a2, _b, _c, _d;
5747
5807
  try {
5748
5808
  const args = JSON.parse(JSON.stringify(_args));
5749
5809
  const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
@@ -5760,8 +5820,7 @@ var resolve = async ({
5760
5820
  );
5761
5821
  const hasDocuments2 = collectionNode2.selectionSet.selections.find(
5762
5822
  (x) => {
5763
- var _a3;
5764
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5823
+ return x?.name?.value === "documents";
5765
5824
  }
5766
5825
  );
5767
5826
  return tinaSchema.getCollections().map((collection) => {
@@ -5777,8 +5836,7 @@ var resolve = async ({
5777
5836
  );
5778
5837
  const hasDocuments = collectionNode.selectionSet.selections.find(
5779
5838
  (x) => {
5780
- var _a3;
5781
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5839
+ return x?.name?.value === "documents";
5782
5840
  }
5783
5841
  );
5784
5842
  return resolver.resolveCollection(
@@ -5797,7 +5855,7 @@ var resolve = async ({
5797
5855
  }
5798
5856
  }
5799
5857
  if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
5800
- const sub = args.sub || (ctxUser == null ? void 0 : ctxUser.sub);
5858
+ const sub = args.sub || ctxUser?.sub;
5801
5859
  const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5802
5860
  if (!collection) {
5803
5861
  throw new Error("Auth collection not found");
@@ -5845,7 +5903,7 @@ var resolve = async ({
5845
5903
  return user;
5846
5904
  }
5847
5905
  if (info.fieldName === "updatePassword") {
5848
- if (!(ctxUser == null ? void 0 : ctxUser.sub)) {
5906
+ if (!ctxUser?.sub) {
5849
5907
  throw new Error("Not authorized");
5850
5908
  }
5851
5909
  if (!args.password) {
@@ -5928,7 +5986,7 @@ var resolve = async ({
5928
5986
  if (typeof value === "string" && value !== "") {
5929
5987
  return resolver.getDocument(value);
5930
5988
  }
5931
- if ((args == null ? void 0 : args.collection) && info.fieldName === "addPendingDocument") {
5989
+ if (args?.collection && info.fieldName === "addPendingDocument") {
5932
5990
  return resolver.resolveDocument({
5933
5991
  args: { ...args, params: {} },
5934
5992
  collection: args.collection,
@@ -5952,7 +6010,7 @@ var resolve = async ({
5952
6010
  // Right now this is the only case for deletion
5953
6011
  isDeletion: info.fieldName === "deleteDocument",
5954
6012
  isFolderCreation: info.fieldName === "createFolder",
5955
- isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
6013
+ isUpdateName: Boolean(args?.params?.relativePath),
5956
6014
  isAddPendingDocument: false,
5957
6015
  isCollectionSpecific: false
5958
6016
  });
@@ -5971,16 +6029,16 @@ var resolve = async ({
5971
6029
  })
5972
6030
  };
5973
6031
  }
5974
- if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
6032
+ if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
5975
6033
  let filter = args.filter;
5976
6034
  if (
5977
6035
  // 1. Make sure that the filter exists
5978
- typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
6036
+ typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
5979
6037
  // @ts-ignore
5980
- typeof ((_b = value == null ? void 0 : value.collection) == null ? void 0 : _b.name) === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
6038
+ typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
5981
6039
  // @ts-ignore
5982
- Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
5983
- typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
6040
+ Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
6041
+ typeof args.filter[value?.collection?.name] !== "undefined"
5984
6042
  ) {
5985
6043
  filter = args.filter[value.collection.name];
5986
6044
  }
@@ -6117,15 +6175,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
6117
6175
  };
6118
6176
 
6119
6177
  // src/database/index.ts
6120
- var import_node_path = __toESM(require("path"));
6178
+ var import_node_path = __toESM(require("node:path"));
6121
6179
  var import_graphql6 = require("graphql");
6122
6180
  var import_micromatch2 = __toESM(require("micromatch"));
6123
6181
  var import_js_sha12 = __toESM(require("js-sha1"));
6124
6182
  var import_lodash5 = __toESM(require("lodash.set"));
6125
6183
  var createLocalDatabase = (config) => {
6126
- const level = new TinaLevelClient(config == null ? void 0 : config.port);
6184
+ const level = new TinaLevelClient(config?.port);
6127
6185
  level.openConnection();
6128
- const fsBridge = new FilesystemBridge((config == null ? void 0 : config.rootPath) || process.cwd());
6186
+ const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
6129
6187
  return new Database({
6130
6188
  bridge: fsBridge,
6131
6189
  ...config || {},
@@ -6198,7 +6256,7 @@ var Database = class {
6198
6256
  );
6199
6257
  }
6200
6258
  const metadata = await metadataLevel.get(`metadata_${key}`);
6201
- return metadata == null ? void 0 : metadata.value;
6259
+ return metadata?.value;
6202
6260
  };
6203
6261
  this.setMetadata = async (key, value) => {
6204
6262
  await this.initLevel();
@@ -6220,7 +6278,7 @@ var Database = class {
6220
6278
  let level = this.contentLevel;
6221
6279
  if (this.appLevel) {
6222
6280
  collection = await this.collectionForPath(filepath);
6223
- if (collection == null ? void 0 : collection.isDetached) {
6281
+ if (collection?.isDetached) {
6224
6282
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6225
6283
  }
6226
6284
  }
@@ -6239,7 +6297,6 @@ var Database = class {
6239
6297
  }
6240
6298
  };
6241
6299
  this.addPendingDocument = async (filepath, data) => {
6242
- var _a;
6243
6300
  await this.initLevel();
6244
6301
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6245
6302
  const collection = await this.collectionForPath(filepath);
@@ -6252,10 +6309,10 @@ var Database = class {
6252
6309
  collection
6253
6310
  );
6254
6311
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6255
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
6256
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
6312
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
6313
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
6257
6314
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6258
- if (!(collection == null ? void 0 : collection.isDetached)) {
6315
+ if (!collection?.isDetached) {
6259
6316
  if (this.bridge) {
6260
6317
  await this.bridge.put(normalizedPath, stringifiedFile);
6261
6318
  }
@@ -6273,7 +6330,7 @@ var Database = class {
6273
6330
  }
6274
6331
  }
6275
6332
  let level = this.contentLevel;
6276
- if (collection == null ? void 0 : collection.isDetached) {
6333
+ if (collection?.isDetached) {
6277
6334
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6278
6335
  }
6279
6336
  const folderTreeBuilder = new FolderTreeBuilder();
@@ -6284,7 +6341,7 @@ var Database = class {
6284
6341
  putOps = [
6285
6342
  ...makeRefOpsForDocument(
6286
6343
  normalizedPath,
6287
- collection == null ? void 0 : collection.name,
6344
+ collection?.name,
6288
6345
  collectionReferences,
6289
6346
  dataFields,
6290
6347
  "put",
@@ -6292,7 +6349,7 @@ var Database = class {
6292
6349
  ),
6293
6350
  ...makeIndexOpsForDocument(
6294
6351
  normalizedPath,
6295
- collection == null ? void 0 : collection.name,
6352
+ collection?.name,
6296
6353
  collectionIndexDefinitions,
6297
6354
  dataFields,
6298
6355
  "put",
@@ -6301,7 +6358,7 @@ var Database = class {
6301
6358
  // folder indices
6302
6359
  ...makeIndexOpsForDocument(
6303
6360
  normalizedPath,
6304
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6361
+ `${collection?.name}_${folderKey}`,
6305
6362
  collectionIndexDefinitions,
6306
6363
  dataFields,
6307
6364
  "put",
@@ -6315,7 +6372,7 @@ var Database = class {
6315
6372
  delOps = existingItem ? [
6316
6373
  ...makeRefOpsForDocument(
6317
6374
  normalizedPath,
6318
- collection == null ? void 0 : collection.name,
6375
+ collection?.name,
6319
6376
  collectionReferences,
6320
6377
  existingItem,
6321
6378
  "del",
@@ -6323,7 +6380,7 @@ var Database = class {
6323
6380
  ),
6324
6381
  ...makeIndexOpsForDocument(
6325
6382
  normalizedPath,
6326
- collection == null ? void 0 : collection.name,
6383
+ collection?.name,
6327
6384
  collectionIndexDefinitions,
6328
6385
  existingItem,
6329
6386
  "del",
@@ -6332,7 +6389,7 @@ var Database = class {
6332
6389
  // folder indices
6333
6390
  ...makeIndexOpsForDocument(
6334
6391
  normalizedPath,
6335
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6392
+ `${collection?.name}_${folderKey}`,
6336
6393
  collectionIndexDefinitions,
6337
6394
  existingItem,
6338
6395
  "del",
@@ -6356,7 +6413,6 @@ var Database = class {
6356
6413
  await level.batch(ops);
6357
6414
  };
6358
6415
  this.put = async (filepath, data, collectionName) => {
6359
- var _a, _b, _c;
6360
6416
  await this.initLevel();
6361
6417
  try {
6362
6418
  if (SYSTEM_FILES.includes(filepath)) {
@@ -6367,16 +6423,16 @@ var Database = class {
6367
6423
  const indexDefinitions = await this.getIndexDefinitions(
6368
6424
  this.contentLevel
6369
6425
  );
6370
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
6426
+ collectionIndexDefinitions = indexDefinitions?.[collectionName];
6371
6427
  }
6372
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collectionName];
6428
+ const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
6373
6429
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6374
6430
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6375
6431
  const collection = await this.collectionForPath(filepath);
6376
6432
  if (!collection) {
6377
6433
  throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
6378
6434
  }
6379
- if (((_b = collection.match) == null ? void 0 : _b.exclude) || ((_c = collection.match) == null ? void 0 : _c.include)) {
6435
+ if (collection.match?.exclude || collection.match?.include) {
6380
6436
  const matches = this.tinaSchema.getMatches({ collection });
6381
6437
  const match = import_micromatch2.default.isMatch(filepath, matches);
6382
6438
  if (!match) {
@@ -6390,7 +6446,7 @@ var Database = class {
6390
6446
  const stringifiedFile = filepath.endsWith(
6391
6447
  `.gitkeep.${collection.format || "md"}`
6392
6448
  ) ? "" : await this.stringifyFile(filepath, dataFields, collection);
6393
- if (!(collection == null ? void 0 : collection.isDetached)) {
6449
+ if (!collection?.isDetached) {
6394
6450
  if (this.bridge) {
6395
6451
  await this.bridge.put(normalizedPath, stringifiedFile);
6396
6452
  }
@@ -6412,7 +6468,7 @@ var Database = class {
6412
6468
  filepath,
6413
6469
  collection.path || ""
6414
6470
  );
6415
- const level = (collection == null ? void 0 : collection.isDetached) ? this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6471
+ const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6416
6472
  let putOps = [];
6417
6473
  let delOps = [];
6418
6474
  if (!isGitKeep(normalizedPath, collection)) {
@@ -6436,7 +6492,7 @@ var Database = class {
6436
6492
  // folder indices
6437
6493
  ...makeIndexOpsForDocument(
6438
6494
  normalizedPath,
6439
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6495
+ `${collection?.name}_${folderKey}`,
6440
6496
  collectionIndexDefinitions,
6441
6497
  dataFields,
6442
6498
  "put",
@@ -6467,7 +6523,7 @@ var Database = class {
6467
6523
  // folder indices
6468
6524
  ...makeIndexOpsForDocument(
6469
6525
  normalizedPath,
6470
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6526
+ `${collection?.name}_${folderKey}`,
6471
6527
  collectionIndexDefinitions,
6472
6528
  existingItem,
6473
6529
  "del",
@@ -6544,8 +6600,8 @@ var Database = class {
6544
6600
  writeTemplateKey,
6545
6601
  //templateInfo.type === 'union',
6546
6602
  {
6547
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6548
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
6603
+ frontmatterFormat: collection?.frontmatterFormat,
6604
+ frontmatterDelimiters: collection?.frontmatterDelimiters
6549
6605
  }
6550
6606
  );
6551
6607
  };
@@ -6661,8 +6717,35 @@ var Database = class {
6661
6717
  ]
6662
6718
  }
6663
6719
  };
6664
- if (collection.fields) {
6665
- for (const field of collection.fields) {
6720
+ let fields = [];
6721
+ if (collection.templates) {
6722
+ const templateFieldMap = {};
6723
+ const conflictedFields = /* @__PURE__ */ new Set();
6724
+ for (const template of collection.templates) {
6725
+ for (const field of template.fields) {
6726
+ if (!templateFieldMap[field.name]) {
6727
+ templateFieldMap[field.name] = field;
6728
+ } else {
6729
+ if (templateFieldMap[field.name].type !== field.type) {
6730
+ console.warn(
6731
+ `Field ${field.name} has conflicting types in templates - skipping index`
6732
+ );
6733
+ conflictedFields.add(field.name);
6734
+ }
6735
+ }
6736
+ }
6737
+ }
6738
+ for (const conflictedField in conflictedFields) {
6739
+ delete templateFieldMap[conflictedField];
6740
+ }
6741
+ for (const field of Object.values(templateFieldMap)) {
6742
+ fields.push(field);
6743
+ }
6744
+ } else if (collection.fields) {
6745
+ fields = collection.fields;
6746
+ }
6747
+ if (fields) {
6748
+ for (const field of fields) {
6666
6749
  if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
6667
6750
  continue;
6668
6751
  }
@@ -6687,8 +6770,8 @@ var Database = class {
6687
6770
  );
6688
6771
  return {
6689
6772
  name: indexField.name,
6690
- type: field == null ? void 0 : field.type,
6691
- list: !!(field == null ? void 0 : field.list)
6773
+ type: field?.type,
6774
+ list: !!field?.list
6692
6775
  };
6693
6776
  })
6694
6777
  };
@@ -6714,7 +6797,6 @@ var Database = class {
6714
6797
  return true;
6715
6798
  };
6716
6799
  this.query = async (queryOptions, hydrator) => {
6717
- var _a;
6718
6800
  await this.initLevel();
6719
6801
  const {
6720
6802
  first,
@@ -6742,14 +6824,14 @@ var Database = class {
6742
6824
  const allIndexDefinitions = await this.getIndexDefinitions(
6743
6825
  this.contentLevel
6744
6826
  );
6745
- const indexDefinitions = allIndexDefinitions == null ? void 0 : allIndexDefinitions[collection.name];
6827
+ const indexDefinitions = allIndexDefinitions?.[collection.name];
6746
6828
  if (!indexDefinitions) {
6747
6829
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
6748
6830
  }
6749
6831
  const filterChain = coerceFilterChainOperands(rawFilterChain);
6750
- const indexDefinition = sort && (indexDefinitions == null ? void 0 : indexDefinitions[sort]);
6832
+ const indexDefinition = sort && indexDefinitions?.[sort];
6751
6833
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
6752
- const level = (collection == null ? void 0 : collection.isDetached) ? this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6834
+ const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6753
6835
  const rootLevel = level.sublevel(
6754
6836
  CONTENT_ROOT_PREFIX,
6755
6837
  SUBLEVEL_OPTIONS
@@ -6759,17 +6841,17 @@ var Database = class {
6759
6841
  SUBLEVEL_OPTIONS
6760
6842
  ).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
6761
6843
  if (!query.gt && !query.gte) {
6762
- query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
6844
+ query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
6763
6845
  }
6764
6846
  if (!query.lt && !query.lte) {
6765
- query.lte = (filterSuffixes == null ? void 0 : filterSuffixes.right) ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6847
+ query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6766
6848
  }
6767
6849
  let edges = [];
6768
6850
  let startKey = "";
6769
6851
  let endKey = "";
6770
6852
  let hasPreviousPage = false;
6771
6853
  let hasNextPage = false;
6772
- const fieldsPattern = ((_a = indexDefinition == null ? void 0 : indexDefinition.fields) == null ? void 0 : _a.length) ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
6854
+ const fieldsPattern = indexDefinition?.fields?.length ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
6773
6855
  const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
6774
6856
  const itemFilter = makeFilter({ filterChain });
6775
6857
  const iterator = sublevel.iterator(query);
@@ -6964,13 +7046,14 @@ var Database = class {
6964
7046
  documentPaths,
6965
7047
  async (collection, documentPaths2) => {
6966
7048
  if (collection && !collection.isDetached) {
6967
- await _indexContent(
6968
- this,
6969
- this.contentLevel,
6970
- documentPaths2,
7049
+ await _indexContent({
7050
+ database: this,
7051
+ level: this.contentLevel,
7052
+ documentPaths: documentPaths2,
6971
7053
  enqueueOps,
6972
- collection
6973
- );
7054
+ collection,
7055
+ isPartialReindex: true
7056
+ });
6974
7057
  }
6975
7058
  }
6976
7059
  );
@@ -6980,18 +7063,17 @@ var Database = class {
6980
7063
  }
6981
7064
  };
6982
7065
  this.delete = async (filepath) => {
6983
- var _a;
6984
7066
  await this.initLevel();
6985
7067
  const collection = await this.collectionForPath(filepath);
6986
7068
  if (!collection) {
6987
7069
  throw new Error(`No collection found for path: ${filepath}`);
6988
7070
  }
6989
7071
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6990
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
6991
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7072
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
7073
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
6992
7074
  let level = this.contentLevel;
6993
- if (collection == null ? void 0 : collection.isDetached) {
6994
- level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
7075
+ if (collection?.isDetached) {
7076
+ level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
6995
7077
  }
6996
7078
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6997
7079
  const rootSublevel = level.sublevel(
@@ -7038,7 +7120,7 @@ var Database = class {
7038
7120
  }
7039
7121
  ]);
7040
7122
  }
7041
- if (!(collection == null ? void 0 : collection.isDetached)) {
7123
+ if (!collection?.isDetached) {
7042
7124
  if (this.bridge) {
7043
7125
  await this.bridge.delete(normalizedPath);
7044
7126
  }
@@ -7078,20 +7160,26 @@ var Database = class {
7078
7160
  );
7079
7161
  const doc = await level2.keys({ limit: 1 }).next();
7080
7162
  if (!doc) {
7081
- await _indexContent(
7082
- this,
7083
- level2,
7084
- contentPaths,
7163
+ await _indexContent({
7164
+ database: this,
7165
+ level: level2,
7166
+ documentPaths: contentPaths,
7085
7167
  enqueueOps,
7086
7168
  collection,
7087
- userFields.map((field) => [
7169
+ passwordFields: userFields.map((field) => [
7088
7170
  ...field.path,
7089
7171
  field.passwordFieldName
7090
7172
  ])
7091
- );
7173
+ });
7092
7174
  }
7093
7175
  } else {
7094
- await _indexContent(this, level, contentPaths, enqueueOps, collection);
7176
+ await _indexContent({
7177
+ database: this,
7178
+ level,
7179
+ documentPaths: contentPaths,
7180
+ enqueueOps,
7181
+ collection
7182
+ });
7095
7183
  }
7096
7184
  }
7097
7185
  );
@@ -7127,7 +7215,7 @@ var Database = class {
7127
7215
  );
7128
7216
  }
7129
7217
  const metadata = await metadataLevel.get("metadata");
7130
- return metadata == null ? void 0 : metadata.version;
7218
+ return metadata?.version;
7131
7219
  }
7132
7220
  async initLevel() {
7133
7221
  if (this.contentLevel) {
@@ -7213,7 +7301,7 @@ var hashPasswordVisitor = async (node, path7) => {
7213
7301
  };
7214
7302
  var visitNodes = async (node, path7, callback) => {
7215
7303
  const [currentLevel, ...remainingLevels] = path7;
7216
- if (!(remainingLevels == null ? void 0 : remainingLevels.length)) {
7304
+ if (!remainingLevels?.length) {
7217
7305
  return callback(node, path7);
7218
7306
  }
7219
7307
  if (Array.isArray(node[currentLevel])) {
@@ -7229,20 +7317,27 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
7229
7317
  async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
7230
7318
  )
7231
7319
  );
7232
- var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${(collection == null ? void 0 : collection.format) || "md"}`);
7233
- var _indexContent = async (database, level, documentPaths, enqueueOps, collection, passwordFields) => {
7234
- var _a;
7320
+ var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
7321
+ var _indexContent = async ({
7322
+ database,
7323
+ level,
7324
+ documentPaths,
7325
+ enqueueOps,
7326
+ collection,
7327
+ passwordFields,
7328
+ isPartialReindex
7329
+ }) => {
7235
7330
  let collectionIndexDefinitions;
7236
7331
  let collectionPath;
7237
7332
  if (collection) {
7238
7333
  const indexDefinitions = await database.getIndexDefinitions(level);
7239
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7334
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7240
7335
  if (!collectionIndexDefinitions) {
7241
7336
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7242
7337
  }
7243
7338
  collectionPath = collection.path;
7244
7339
  }
7245
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7340
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7246
7341
  const tinaSchema = await database.getSchema();
7247
7342
  let templateInfo = null;
7248
7343
  if (collection) {
@@ -7260,7 +7355,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7260
7355
  if (!aliasedData) {
7261
7356
  return;
7262
7357
  }
7263
- if (passwordFields == null ? void 0 : passwordFields.length) {
7358
+ if (passwordFields?.length) {
7264
7359
  await hashPasswordValues(aliasedData, passwordFields);
7265
7360
  }
7266
7361
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
@@ -7272,46 +7367,48 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7272
7367
  normalizedPath,
7273
7368
  collectionPath || ""
7274
7369
  );
7275
- const item = await rootSublevel.get(normalizedPath);
7276
- if (item) {
7277
- await database.contentLevel.batch([
7278
- ...makeRefOpsForDocument(
7279
- normalizedPath,
7280
- collection == null ? void 0 : collection.name,
7281
- collectionReferences,
7282
- item,
7283
- "del",
7284
- level
7285
- ),
7286
- ...makeIndexOpsForDocument(
7287
- normalizedPath,
7288
- collection.name,
7289
- collectionIndexDefinitions,
7290
- item,
7291
- "del",
7292
- level
7293
- ),
7294
- // folder indices
7295
- ...makeIndexOpsForDocument(
7296
- normalizedPath,
7297
- `${collection.name}_${folderKey}`,
7298
- collectionIndexDefinitions,
7299
- item,
7300
- "del",
7301
- level
7302
- ),
7303
- {
7304
- type: "del",
7305
- key: normalizedPath,
7306
- sublevel: rootSublevel
7307
- }
7308
- ]);
7370
+ if (isPartialReindex) {
7371
+ const item = await rootSublevel.get(normalizedPath);
7372
+ if (item) {
7373
+ await database.contentLevel.batch([
7374
+ ...makeRefOpsForDocument(
7375
+ normalizedPath,
7376
+ collection?.name,
7377
+ collectionReferences,
7378
+ item,
7379
+ "del",
7380
+ level
7381
+ ),
7382
+ ...makeIndexOpsForDocument(
7383
+ normalizedPath,
7384
+ collection.name,
7385
+ collectionIndexDefinitions,
7386
+ item,
7387
+ "del",
7388
+ level
7389
+ ),
7390
+ // folder indices
7391
+ ...makeIndexOpsForDocument(
7392
+ normalizedPath,
7393
+ `${collection.name}_${folderKey}`,
7394
+ collectionIndexDefinitions,
7395
+ item,
7396
+ "del",
7397
+ level
7398
+ ),
7399
+ {
7400
+ type: "del",
7401
+ key: normalizedPath,
7402
+ sublevel: rootSublevel
7403
+ }
7404
+ ]);
7405
+ }
7309
7406
  }
7310
7407
  if (!isGitKeep(filepath, collection)) {
7311
7408
  await enqueueOps([
7312
7409
  ...makeRefOpsForDocument(
7313
7410
  normalizedPath,
7314
- collection == null ? void 0 : collection.name,
7411
+ collection?.name,
7315
7412
  collectionReferences,
7316
7413
  aliasedData,
7317
7414
  "put",
@@ -7319,7 +7416,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7319
7416
  ),
7320
7417
  ...makeIndexOpsForDocument(
7321
7418
  normalizedPath,
7322
- collection == null ? void 0 : collection.name,
7419
+ collection?.name,
7323
7420
  collectionIndexDefinitions,
7324
7421
  aliasedData,
7325
7422
  "put",
@@ -7328,7 +7425,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7328
7425
  // folder indexes
7329
7426
  ...makeIndexOpsForDocument(
7330
7427
  normalizedPath,
7331
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7428
+ `${collection?.name}_${folderKey}`,
7332
7429
  collectionIndexDefinitions,
7333
7430
  aliasedData,
7334
7431
  "put",
@@ -7349,7 +7446,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7349
7446
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7350
7447
  originalError: error,
7351
7448
  file: filepath,
7352
- collection: collection == null ? void 0 : collection.name,
7449
+ collection: collection?.name,
7353
7450
  stack: error.stack
7354
7451
  });
7355
7452
  }
@@ -7367,7 +7464,6 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7367
7464
  }
7368
7465
  };
7369
7466
  var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
7370
- var _a;
7371
7467
  if (!documentPaths.length) {
7372
7468
  return;
7373
7469
  }
@@ -7376,12 +7472,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7376
7472
  const indexDefinitions = await database.getIndexDefinitions(
7377
7473
  database.contentLevel
7378
7474
  );
7379
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7475
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7380
7476
  if (!collectionIndexDefinitions) {
7381
7477
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7382
7478
  }
7383
7479
  }
7384
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7480
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7385
7481
  const tinaSchema = await database.getSchema();
7386
7482
  let templateInfo = null;
7387
7483
  if (collection) {
@@ -7398,7 +7494,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7398
7494
  if (item) {
7399
7495
  const folderKey = folderTreeBuilder.update(
7400
7496
  itemKey,
7401
- (collection == null ? void 0 : collection.path) || ""
7497
+ collection?.path || ""
7402
7498
  );
7403
7499
  const aliasedData = templateInfo ? replaceNameOverrides(
7404
7500
  getTemplateForFile(templateInfo, item),
@@ -7407,7 +7503,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7407
7503
  await enqueueOps([
7408
7504
  ...makeRefOpsForDocument(
7409
7505
  itemKey,
7410
- collection == null ? void 0 : collection.name,
7506
+ collection?.name,
7411
7507
  collectionReferences,
7412
7508
  aliasedData,
7413
7509
  "del",
@@ -7424,7 +7520,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7424
7520
  // folder indexes
7425
7521
  ...makeIndexOpsForDocument(
7426
7522
  itemKey,
7427
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7523
+ `${collection?.name}_${folderKey}`,
7428
7524
  collectionIndexDefinitions,
7429
7525
  aliasedData,
7430
7526
  "del",
@@ -7509,12 +7605,12 @@ var getChangedFiles = async ({
7509
7605
  }
7510
7606
  }
7511
7607
  }
7512
- if (await (B == null ? void 0 : B.type()) === "tree") {
7608
+ if (await B?.type() === "tree") {
7513
7609
  return;
7514
7610
  }
7515
7611
  if (matches) {
7516
- const oidA = await (A == null ? void 0 : A.oid());
7517
- const oidB = await (B == null ? void 0 : B.oid());
7612
+ const oidA = await A?.oid();
7613
+ const oidB = await B?.oid();
7518
7614
  if (oidA !== oidB) {
7519
7615
  if (oidA === void 0) {
7520
7616
  results.added.push(relativePath);
@@ -7542,8 +7638,8 @@ var import_path5 = __toESM(require("path"));
7542
7638
  var import_normalize_path = __toESM(require("normalize-path"));
7543
7639
  var FilesystemBridge = class {
7544
7640
  constructor(rootPath, outputPath) {
7545
- this.rootPath = rootPath || "";
7546
- this.outputPath = outputPath || rootPath;
7641
+ this.rootPath = import_path5.default.resolve(rootPath);
7642
+ this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
7547
7643
  }
7548
7644
  async glob(pattern, extension) {
7549
7645
  const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
@@ -7555,19 +7651,19 @@ var FilesystemBridge = class {
7555
7651
  }
7556
7652
  );
7557
7653
  const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
7558
- return items.map((item) => {
7559
- return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
7560
- });
7654
+ return items.map(
7655
+ (item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
7656
+ );
7561
7657
  }
7562
7658
  async delete(filepath) {
7563
7659
  await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
7564
7660
  }
7565
7661
  async get(filepath) {
7566
- return import_fs_extra2.default.readFileSync(import_path5.default.join(this.outputPath, filepath)).toString();
7662
+ return (await import_fs_extra2.default.readFile(import_path5.default.join(this.outputPath, filepath))).toString();
7567
7663
  }
7568
7664
  async put(filepath, data, basePathOverride) {
7569
7665
  const basePath = basePathOverride || this.outputPath;
7570
- await import_fs_extra2.default.outputFileSync(import_path5.default.join(basePath, filepath), data);
7666
+ await import_fs_extra2.default.outputFile(import_path5.default.join(basePath, filepath), data);
7571
7667
  }
7572
7668
  };
7573
7669
  var AuditFileSystemBridge = class extends FilesystemBridge {