@tinacms/graphql 1.5.16 → 1.5.18

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
@@ -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
  }
@@ -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.16",
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,7 +3109,6 @@ 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
  },
@@ -3171,7 +3163,6 @@ var package_default = {
3171
3163
  "@types/yup": "^0.29.14",
3172
3164
  "jest-file-snapshot": "^0.5.0",
3173
3165
  "memory-level": "^1.0.0",
3174
- nodemon: "3.1.4",
3175
3166
  typescript: "^5.7.3",
3176
3167
  vite: "^4.5.9",
3177
3168
  vitest: "^0.32.4",
@@ -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
  );
@@ -3622,9 +3612,8 @@ var cleanUpSlashes = (path7) => {
3622
3612
  return "";
3623
3613
  };
3624
3614
  var hasTinaMediaConfig = (schema) => {
3625
- var _a, _b, _c, _d, _e, _f, _g, _h;
3626
- if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3627
- 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")
3628
3617
  return false;
3629
3618
  return true;
3630
3619
  };
@@ -3731,22 +3720,20 @@ var replaceNameOverrides = (template, obj) => {
3731
3720
  }
3732
3721
  };
3733
3722
  function isBlockField(field) {
3734
- var _a;
3735
- return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
3723
+ return field && field.type === "object" && field.templates?.length > 0;
3736
3724
  }
3737
3725
  var _replaceNameOverrides = (fields, obj) => {
3738
3726
  const output = {};
3739
3727
  Object.keys(obj).forEach((key) => {
3740
3728
  const field = fields.find(
3741
- (fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key
3729
+ (fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
3742
3730
  );
3743
- 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];
3744
3732
  });
3745
3733
  return output;
3746
3734
  };
3747
3735
  var getTemplateForData = (field, data) => {
3748
- var _a;
3749
- if ((_a = field.templates) == null ? void 0 : _a.length) {
3736
+ if (field.templates?.length) {
3750
3737
  const templateKey = "_template";
3751
3738
  if (data[templateKey]) {
3752
3739
  const result = field.templates.find(
@@ -3804,8 +3791,8 @@ var _applyNameOverrides = (fields, obj) => {
3804
3791
  const output = {};
3805
3792
  Object.keys(obj).forEach((key) => {
3806
3793
  const field = fields.find((field2) => field2.name === key);
3807
- const outputKey = (field == null ? void 0 : field.nameOverride) || key;
3808
- 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];
3809
3796
  });
3810
3797
  return output;
3811
3798
  };
@@ -3818,7 +3805,6 @@ var matterEngines = {
3818
3805
  }
3819
3806
  };
3820
3807
  var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3821
- var _a, _b;
3822
3808
  const {
3823
3809
  _relativePath,
3824
3810
  _keepTemplateKey,
@@ -3842,9 +3828,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3842
3828
  ${$_body}`,
3843
3829
  strippedContent,
3844
3830
  {
3845
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3831
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3846
3832
  engines: matterEngines,
3847
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---"
3833
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
3848
3834
  }
3849
3835
  );
3850
3836
  return ok;
@@ -3860,15 +3846,14 @@ ${$_body}`,
3860
3846
  }
3861
3847
  };
3862
3848
  var parseFile = (content, format, yupSchema, markdownParseConfig) => {
3863
- var _a, _b;
3864
3849
  try {
3865
3850
  switch (format) {
3866
3851
  case ".markdown":
3867
3852
  case ".mdx":
3868
3853
  case ".md":
3869
3854
  const contentJSON = (0, import_gray_matter.default)(content || "", {
3870
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3871
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---",
3855
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3856
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
3872
3857
  engines: matterEngines
3873
3858
  });
3874
3859
  const markdownData = {
@@ -3967,7 +3952,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3967
3952
  ),
3968
3953
  template: void 0
3969
3954
  } : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
3970
- const field = template == null ? void 0 : template.fields.find((field2) => {
3955
+ const field = template?.fields.find((field2) => {
3971
3956
  if (field2.type === "string" || field2.type === "rich-text") {
3972
3957
  if (field2.isBody) {
3973
3958
  return true;
@@ -3987,7 +3972,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3987
3972
  ...data,
3988
3973
  _collection: collection.name,
3989
3974
  _keepTemplateKey: !!collection.templates,
3990
- _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,
3991
3976
  _relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
3992
3977
  _id: filepath
3993
3978
  };
@@ -3996,10 +3981,10 @@ function hasOwnProperty(obj, prop) {
3996
3981
  return obj.hasOwnProperty(prop);
3997
3982
  }
3998
3983
  var getTemplateForFile = (templateInfo, data) => {
3999
- if ((templateInfo == null ? void 0 : templateInfo.type) === "object") {
3984
+ if (templateInfo?.type === "object") {
4000
3985
  return templateInfo.template;
4001
3986
  }
4002
- if ((templateInfo == null ? void 0 : templateInfo.type) === "union") {
3987
+ if (templateInfo?.type === "union") {
4003
3988
  if (hasOwnProperty(data, "_template")) {
4004
3989
  const template = templateInfo.templates.find(
4005
3990
  (t) => lastItem(t.namespace) === data._template
@@ -4023,8 +4008,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
4023
4008
  import_path.default.extname(filepath),
4024
4009
  (yup3) => yup3.object({}),
4025
4010
  {
4026
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
4027
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
4011
+ frontmatterDelimiters: collection?.frontmatterDelimiters,
4012
+ frontmatterFormat: collection?.frontmatterFormat
4028
4013
  }
4029
4014
  );
4030
4015
  const template = getTemplateForFile(templateInfo, data);
@@ -4691,7 +4676,6 @@ var createResolver = (args) => {
4691
4676
  return new Resolver(args);
4692
4677
  };
4693
4678
  var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4694
- var _a, _b;
4695
4679
  if (!rawData) {
4696
4680
  return void 0;
4697
4681
  }
@@ -4719,7 +4703,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4719
4703
  accumulator[field.name] = {
4720
4704
  value: void 0,
4721
4705
  // never resolve the password hash
4722
- passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4706
+ passwordChangeRequired: value["passwordChangeRequired"] ?? false
4723
4707
  };
4724
4708
  break;
4725
4709
  case "image":
@@ -4735,11 +4719,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4735
4719
  field,
4736
4720
  (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4737
4721
  );
4738
- if (((_b = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _b.type) === "invalid_markdown") {
4722
+ if (tree?.children[0]?.type === "invalid_markdown") {
4739
4723
  if (isAudit) {
4740
- const invalidNode = tree == null ? void 0 : tree.children[0];
4724
+ const invalidNode = tree?.children[0];
4741
4725
  throw new import_graphql3.GraphQLError(
4742
- `${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}` : ""}`
4743
4727
  );
4744
4728
  }
4745
4729
  }
@@ -4852,11 +4836,11 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4852
4836
  });
4853
4837
  }
4854
4838
  const titleField = template.fields.find((x) => {
4855
- if (x.type === "string" && (x == null ? void 0 : x.isTitle)) {
4839
+ if (x.type === "string" && x?.isTitle) {
4856
4840
  return true;
4857
4841
  }
4858
4842
  });
4859
- const titleFieldName = titleField == null ? void 0 : titleField.name;
4843
+ const titleFieldName = titleField?.name;
4860
4844
  const title = data[titleFieldName || " "] || null;
4861
4845
  return {
4862
4846
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
@@ -4966,7 +4950,7 @@ var Resolver = class {
4966
4950
  );
4967
4951
  }
4968
4952
  const rawData = await this.getRaw(fullPath);
4969
- 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;
4970
4954
  return transformDocumentIntoPayload(
4971
4955
  fullPath,
4972
4956
  rawData,
@@ -5006,9 +4990,9 @@ var Resolver = class {
5006
4990
  return this.buildFieldMutations(
5007
4991
  item,
5008
4992
  objectTemplate,
5009
- idField && existingData && (existingData == null ? void 0 : existingData.find(
4993
+ idField && existingData && existingData?.find(
5010
4994
  (d) => d[idField.name] === item[idField.name]
5011
- ))
4995
+ )
5012
4996
  );
5013
4997
  }
5014
4998
  )
@@ -5134,7 +5118,7 @@ var Resolver = class {
5134
5118
  isCollectionSpecific
5135
5119
  }) => {
5136
5120
  const doc = await this.getDocument(realPath);
5137
- const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
5121
+ const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
5138
5122
  if (isAddPendingDocument === true) {
5139
5123
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
5140
5124
  const params2 = this.buildParams(args);
@@ -5144,7 +5128,7 @@ var Resolver = class {
5144
5128
  const values = await this.buildFieldMutations(
5145
5129
  params2,
5146
5130
  templateInfo.template,
5147
- doc == null ? void 0 : doc._rawData
5131
+ doc?._rawData
5148
5132
  );
5149
5133
  await this.database.put(
5150
5134
  realPath,
@@ -5168,7 +5152,7 @@ var Resolver = class {
5168
5152
  // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
5169
5153
  templateParams,
5170
5154
  template,
5171
- doc == null ? void 0 : doc._rawData
5155
+ doc?._rawData
5172
5156
  ),
5173
5157
  _template: lastItem(template.namespace)
5174
5158
  };
@@ -5182,7 +5166,7 @@ var Resolver = class {
5182
5166
  //@ts-ignore
5183
5167
  isCollectionSpecific ? args.params : args.params[collection.name],
5184
5168
  collection,
5185
- doc == null ? void 0 : doc._rawData
5169
+ doc?._rawData
5186
5170
  );
5187
5171
  await this.database.put(
5188
5172
  realPath,
@@ -5198,7 +5182,6 @@ var Resolver = class {
5198
5182
  this.resolveLegacyValues = (oldDoc, collection) => {
5199
5183
  const legacyValues = {};
5200
5184
  Object.entries(oldDoc).forEach(([key, value]) => {
5201
- var _a;
5202
5185
  const reservedKeys = [
5203
5186
  "$_body",
5204
5187
  "_collection",
@@ -5211,7 +5194,7 @@ var Resolver = class {
5211
5194
  return;
5212
5195
  }
5213
5196
  if (oldDoc._template && collection.templates) {
5214
- const template = (_a = collection.templates) == null ? void 0 : _a.find(
5197
+ const template = collection.templates?.find(
5215
5198
  ({ name }) => name === oldDoc._template
5216
5199
  );
5217
5200
  if (template) {
@@ -5258,7 +5241,7 @@ var Resolver = class {
5258
5241
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5259
5242
  );
5260
5243
  const collection = await this.tinaSchema.getCollection(collectionLookup);
5261
- 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);
5262
5245
  if (isFolderCreation) {
5263
5246
  realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
5264
5247
  }
@@ -5342,12 +5325,12 @@ var Resolver = class {
5342
5325
  (yup3) => yup3.object({ params: yup3.object().required() })
5343
5326
  );
5344
5327
  assertShape(
5345
- args == null ? void 0 : args.params,
5328
+ args?.params,
5346
5329
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5347
5330
  );
5348
5331
  const doc = await this.getDocument(realPath);
5349
5332
  const newRealPath = import_path3.default.join(
5350
- collection == null ? void 0 : collection.path,
5333
+ collection?.path,
5351
5334
  args.params.relativePath
5352
5335
  );
5353
5336
  if (newRealPath === realPath) {
@@ -5577,7 +5560,7 @@ var Resolver = class {
5577
5560
  if (!references[c.name][refId]) {
5578
5561
  references[c.name][refId] = [];
5579
5562
  }
5580
- const referencePath = rawItem == null ? void 0 : rawItem[REFS_PATH_FIELD];
5563
+ const referencePath = rawItem?.[REFS_PATH_FIELD];
5581
5564
  if (referencePath) {
5582
5565
  references[c.name][refId].push(referencePath);
5583
5566
  }
@@ -5587,7 +5570,6 @@ var Resolver = class {
5587
5570
  return references;
5588
5571
  };
5589
5572
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
5590
- var _a;
5591
5573
  const accum = {};
5592
5574
  for (const passwordField of template.fields.filter(
5593
5575
  (f) => f.type === "password"
@@ -5630,7 +5612,7 @@ var Resolver = class {
5630
5612
  accum[fieldName] = await this.buildObjectMutations(
5631
5613
  fieldValue,
5632
5614
  field,
5633
- existingData == null ? void 0 : existingData[fieldName]
5615
+ existingData?.[fieldName]
5634
5616
  );
5635
5617
  break;
5636
5618
  case "password":
@@ -5649,7 +5631,7 @@ var Resolver = class {
5649
5631
  } else {
5650
5632
  accum[fieldName] = {
5651
5633
  ...fieldValue,
5652
- value: (_a = existingData == null ? void 0 : existingData[fieldName]) == null ? void 0 : _a["value"]
5634
+ value: existingData?.[fieldName]?.["value"]
5653
5635
  };
5654
5636
  }
5655
5637
  break;
@@ -5784,9 +5766,8 @@ var resolve = async ({
5784
5766
  isAudit,
5785
5767
  ctxUser
5786
5768
  }) => {
5787
- var _a;
5788
5769
  try {
5789
- const verboseValue = verbose != null ? verbose : true;
5770
+ const verboseValue = verbose ?? true;
5790
5771
  const graphQLSchemaAst = await database.getGraphQLSchema();
5791
5772
  if (!graphQLSchemaAst) {
5792
5773
  throw new import_graphql5.GraphQLError("GraphQL schema not found");
@@ -5798,7 +5779,7 @@ var resolve = async ({
5798
5779
  // @ts-ignore
5799
5780
  schema: tinaConfig,
5800
5781
  // @ts-ignore
5801
- flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5782
+ flags: tinaConfig?.meta?.flags
5802
5783
  });
5803
5784
  const resolver = createResolver({
5804
5785
  config,
@@ -5823,7 +5804,6 @@ var resolve = async ({
5823
5804
  throw new Error(`Unable to find lookup key for ${namedType}`);
5824
5805
  },
5825
5806
  fieldResolver: async (source = {}, _args = {}, _context, info) => {
5826
- var _a2, _b, _c, _d;
5827
5807
  try {
5828
5808
  const args = JSON.parse(JSON.stringify(_args));
5829
5809
  const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
@@ -5840,8 +5820,7 @@ var resolve = async ({
5840
5820
  );
5841
5821
  const hasDocuments2 = collectionNode2.selectionSet.selections.find(
5842
5822
  (x) => {
5843
- var _a3;
5844
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5823
+ return x?.name?.value === "documents";
5845
5824
  }
5846
5825
  );
5847
5826
  return tinaSchema.getCollections().map((collection) => {
@@ -5857,8 +5836,7 @@ var resolve = async ({
5857
5836
  );
5858
5837
  const hasDocuments = collectionNode.selectionSet.selections.find(
5859
5838
  (x) => {
5860
- var _a3;
5861
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5839
+ return x?.name?.value === "documents";
5862
5840
  }
5863
5841
  );
5864
5842
  return resolver.resolveCollection(
@@ -5877,7 +5855,7 @@ var resolve = async ({
5877
5855
  }
5878
5856
  }
5879
5857
  if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
5880
- const sub = args.sub || (ctxUser == null ? void 0 : ctxUser.sub);
5858
+ const sub = args.sub || ctxUser?.sub;
5881
5859
  const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5882
5860
  if (!collection) {
5883
5861
  throw new Error("Auth collection not found");
@@ -5925,7 +5903,7 @@ var resolve = async ({
5925
5903
  return user;
5926
5904
  }
5927
5905
  if (info.fieldName === "updatePassword") {
5928
- if (!(ctxUser == null ? void 0 : ctxUser.sub)) {
5906
+ if (!ctxUser?.sub) {
5929
5907
  throw new Error("Not authorized");
5930
5908
  }
5931
5909
  if (!args.password) {
@@ -6008,7 +5986,7 @@ var resolve = async ({
6008
5986
  if (typeof value === "string" && value !== "") {
6009
5987
  return resolver.getDocument(value);
6010
5988
  }
6011
- if ((args == null ? void 0 : args.collection) && info.fieldName === "addPendingDocument") {
5989
+ if (args?.collection && info.fieldName === "addPendingDocument") {
6012
5990
  return resolver.resolveDocument({
6013
5991
  args: { ...args, params: {} },
6014
5992
  collection: args.collection,
@@ -6032,7 +6010,7 @@ var resolve = async ({
6032
6010
  // Right now this is the only case for deletion
6033
6011
  isDeletion: info.fieldName === "deleteDocument",
6034
6012
  isFolderCreation: info.fieldName === "createFolder",
6035
- isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
6013
+ isUpdateName: Boolean(args?.params?.relativePath),
6036
6014
  isAddPendingDocument: false,
6037
6015
  isCollectionSpecific: false
6038
6016
  });
@@ -6051,16 +6029,16 @@ var resolve = async ({
6051
6029
  })
6052
6030
  };
6053
6031
  }
6054
- 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) {
6055
6033
  let filter = args.filter;
6056
6034
  if (
6057
6035
  // 1. Make sure that the filter exists
6058
- 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
6059
6037
  // @ts-ignore
6060
- 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
6061
6039
  // @ts-ignore
6062
- Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
6063
- 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"
6064
6042
  ) {
6065
6043
  filter = args.filter[value.collection.name];
6066
6044
  }
@@ -6197,15 +6175,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
6197
6175
  };
6198
6176
 
6199
6177
  // src/database/index.ts
6200
- var import_node_path = __toESM(require("path"));
6178
+ var import_node_path = __toESM(require("node:path"));
6201
6179
  var import_graphql6 = require("graphql");
6202
6180
  var import_micromatch2 = __toESM(require("micromatch"));
6203
6181
  var import_js_sha12 = __toESM(require("js-sha1"));
6204
6182
  var import_lodash5 = __toESM(require("lodash.set"));
6205
6183
  var createLocalDatabase = (config) => {
6206
- const level = new TinaLevelClient(config == null ? void 0 : config.port);
6184
+ const level = new TinaLevelClient(config?.port);
6207
6185
  level.openConnection();
6208
- const fsBridge = new FilesystemBridge((config == null ? void 0 : config.rootPath) || process.cwd());
6186
+ const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
6209
6187
  return new Database({
6210
6188
  bridge: fsBridge,
6211
6189
  ...config || {},
@@ -6278,7 +6256,7 @@ var Database = class {
6278
6256
  );
6279
6257
  }
6280
6258
  const metadata = await metadataLevel.get(`metadata_${key}`);
6281
- return metadata == null ? void 0 : metadata.value;
6259
+ return metadata?.value;
6282
6260
  };
6283
6261
  this.setMetadata = async (key, value) => {
6284
6262
  await this.initLevel();
@@ -6300,7 +6278,7 @@ var Database = class {
6300
6278
  let level = this.contentLevel;
6301
6279
  if (this.appLevel) {
6302
6280
  collection = await this.collectionForPath(filepath);
6303
- if (collection == null ? void 0 : collection.isDetached) {
6281
+ if (collection?.isDetached) {
6304
6282
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6305
6283
  }
6306
6284
  }
@@ -6319,7 +6297,6 @@ var Database = class {
6319
6297
  }
6320
6298
  };
6321
6299
  this.addPendingDocument = async (filepath, data) => {
6322
- var _a;
6323
6300
  await this.initLevel();
6324
6301
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6325
6302
  const collection = await this.collectionForPath(filepath);
@@ -6332,10 +6309,10 @@ var Database = class {
6332
6309
  collection
6333
6310
  );
6334
6311
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6335
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
6336
- 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];
6337
6314
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6338
- if (!(collection == null ? void 0 : collection.isDetached)) {
6315
+ if (!collection?.isDetached) {
6339
6316
  if (this.bridge) {
6340
6317
  await this.bridge.put(normalizedPath, stringifiedFile);
6341
6318
  }
@@ -6353,7 +6330,7 @@ var Database = class {
6353
6330
  }
6354
6331
  }
6355
6332
  let level = this.contentLevel;
6356
- if (collection == null ? void 0 : collection.isDetached) {
6333
+ if (collection?.isDetached) {
6357
6334
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6358
6335
  }
6359
6336
  const folderTreeBuilder = new FolderTreeBuilder();
@@ -6364,7 +6341,7 @@ var Database = class {
6364
6341
  putOps = [
6365
6342
  ...makeRefOpsForDocument(
6366
6343
  normalizedPath,
6367
- collection == null ? void 0 : collection.name,
6344
+ collection?.name,
6368
6345
  collectionReferences,
6369
6346
  dataFields,
6370
6347
  "put",
@@ -6372,7 +6349,7 @@ var Database = class {
6372
6349
  ),
6373
6350
  ...makeIndexOpsForDocument(
6374
6351
  normalizedPath,
6375
- collection == null ? void 0 : collection.name,
6352
+ collection?.name,
6376
6353
  collectionIndexDefinitions,
6377
6354
  dataFields,
6378
6355
  "put",
@@ -6381,7 +6358,7 @@ var Database = class {
6381
6358
  // folder indices
6382
6359
  ...makeIndexOpsForDocument(
6383
6360
  normalizedPath,
6384
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6361
+ `${collection?.name}_${folderKey}`,
6385
6362
  collectionIndexDefinitions,
6386
6363
  dataFields,
6387
6364
  "put",
@@ -6395,7 +6372,7 @@ var Database = class {
6395
6372
  delOps = existingItem ? [
6396
6373
  ...makeRefOpsForDocument(
6397
6374
  normalizedPath,
6398
- collection == null ? void 0 : collection.name,
6375
+ collection?.name,
6399
6376
  collectionReferences,
6400
6377
  existingItem,
6401
6378
  "del",
@@ -6403,7 +6380,7 @@ var Database = class {
6403
6380
  ),
6404
6381
  ...makeIndexOpsForDocument(
6405
6382
  normalizedPath,
6406
- collection == null ? void 0 : collection.name,
6383
+ collection?.name,
6407
6384
  collectionIndexDefinitions,
6408
6385
  existingItem,
6409
6386
  "del",
@@ -6412,7 +6389,7 @@ var Database = class {
6412
6389
  // folder indices
6413
6390
  ...makeIndexOpsForDocument(
6414
6391
  normalizedPath,
6415
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6392
+ `${collection?.name}_${folderKey}`,
6416
6393
  collectionIndexDefinitions,
6417
6394
  existingItem,
6418
6395
  "del",
@@ -6436,7 +6413,6 @@ var Database = class {
6436
6413
  await level.batch(ops);
6437
6414
  };
6438
6415
  this.put = async (filepath, data, collectionName) => {
6439
- var _a, _b, _c;
6440
6416
  await this.initLevel();
6441
6417
  try {
6442
6418
  if (SYSTEM_FILES.includes(filepath)) {
@@ -6447,16 +6423,16 @@ var Database = class {
6447
6423
  const indexDefinitions = await this.getIndexDefinitions(
6448
6424
  this.contentLevel
6449
6425
  );
6450
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
6426
+ collectionIndexDefinitions = indexDefinitions?.[collectionName];
6451
6427
  }
6452
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collectionName];
6428
+ const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
6453
6429
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6454
6430
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6455
6431
  const collection = await this.collectionForPath(filepath);
6456
6432
  if (!collection) {
6457
6433
  throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
6458
6434
  }
6459
- 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) {
6460
6436
  const matches = this.tinaSchema.getMatches({ collection });
6461
6437
  const match = import_micromatch2.default.isMatch(filepath, matches);
6462
6438
  if (!match) {
@@ -6470,7 +6446,7 @@ var Database = class {
6470
6446
  const stringifiedFile = filepath.endsWith(
6471
6447
  `.gitkeep.${collection.format || "md"}`
6472
6448
  ) ? "" : await this.stringifyFile(filepath, dataFields, collection);
6473
- if (!(collection == null ? void 0 : collection.isDetached)) {
6449
+ if (!collection?.isDetached) {
6474
6450
  if (this.bridge) {
6475
6451
  await this.bridge.put(normalizedPath, stringifiedFile);
6476
6452
  }
@@ -6492,7 +6468,7 @@ var Database = class {
6492
6468
  filepath,
6493
6469
  collection.path || ""
6494
6470
  );
6495
- 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;
6496
6472
  let putOps = [];
6497
6473
  let delOps = [];
6498
6474
  if (!isGitKeep(normalizedPath, collection)) {
@@ -6516,7 +6492,7 @@ var Database = class {
6516
6492
  // folder indices
6517
6493
  ...makeIndexOpsForDocument(
6518
6494
  normalizedPath,
6519
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6495
+ `${collection?.name}_${folderKey}`,
6520
6496
  collectionIndexDefinitions,
6521
6497
  dataFields,
6522
6498
  "put",
@@ -6547,7 +6523,7 @@ var Database = class {
6547
6523
  // folder indices
6548
6524
  ...makeIndexOpsForDocument(
6549
6525
  normalizedPath,
6550
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6526
+ `${collection?.name}_${folderKey}`,
6551
6527
  collectionIndexDefinitions,
6552
6528
  existingItem,
6553
6529
  "del",
@@ -6624,8 +6600,8 @@ var Database = class {
6624
6600
  writeTemplateKey,
6625
6601
  //templateInfo.type === 'union',
6626
6602
  {
6627
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6628
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
6603
+ frontmatterFormat: collection?.frontmatterFormat,
6604
+ frontmatterDelimiters: collection?.frontmatterDelimiters
6629
6605
  }
6630
6606
  );
6631
6607
  };
@@ -6794,8 +6770,8 @@ var Database = class {
6794
6770
  );
6795
6771
  return {
6796
6772
  name: indexField.name,
6797
- type: field == null ? void 0 : field.type,
6798
- list: !!(field == null ? void 0 : field.list)
6773
+ type: field?.type,
6774
+ list: !!field?.list
6799
6775
  };
6800
6776
  })
6801
6777
  };
@@ -6821,7 +6797,6 @@ var Database = class {
6821
6797
  return true;
6822
6798
  };
6823
6799
  this.query = async (queryOptions, hydrator) => {
6824
- var _a;
6825
6800
  await this.initLevel();
6826
6801
  const {
6827
6802
  first,
@@ -6849,14 +6824,14 @@ var Database = class {
6849
6824
  const allIndexDefinitions = await this.getIndexDefinitions(
6850
6825
  this.contentLevel
6851
6826
  );
6852
- const indexDefinitions = allIndexDefinitions == null ? void 0 : allIndexDefinitions[collection.name];
6827
+ const indexDefinitions = allIndexDefinitions?.[collection.name];
6853
6828
  if (!indexDefinitions) {
6854
6829
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
6855
6830
  }
6856
6831
  const filterChain = coerceFilterChainOperands(rawFilterChain);
6857
- const indexDefinition = sort && (indexDefinitions == null ? void 0 : indexDefinitions[sort]);
6832
+ const indexDefinition = sort && indexDefinitions?.[sort];
6858
6833
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
6859
- 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;
6860
6835
  const rootLevel = level.sublevel(
6861
6836
  CONTENT_ROOT_PREFIX,
6862
6837
  SUBLEVEL_OPTIONS
@@ -6866,17 +6841,17 @@ var Database = class {
6866
6841
  SUBLEVEL_OPTIONS
6867
6842
  ).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
6868
6843
  if (!query.gt && !query.gte) {
6869
- query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
6844
+ query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
6870
6845
  }
6871
6846
  if (!query.lt && !query.lte) {
6872
- query.lte = (filterSuffixes == null ? void 0 : filterSuffixes.right) ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6847
+ query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6873
6848
  }
6874
6849
  let edges = [];
6875
6850
  let startKey = "";
6876
6851
  let endKey = "";
6877
6852
  let hasPreviousPage = false;
6878
6853
  let hasNextPage = false;
6879
- 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("")}` : "";
6880
6855
  const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
6881
6856
  const itemFilter = makeFilter({ filterChain });
6882
6857
  const iterator = sublevel.iterator(query);
@@ -7071,13 +7046,14 @@ var Database = class {
7071
7046
  documentPaths,
7072
7047
  async (collection, documentPaths2) => {
7073
7048
  if (collection && !collection.isDetached) {
7074
- await _indexContent(
7075
- this,
7076
- this.contentLevel,
7077
- documentPaths2,
7049
+ await _indexContent({
7050
+ database: this,
7051
+ level: this.contentLevel,
7052
+ documentPaths: documentPaths2,
7078
7053
  enqueueOps,
7079
- collection
7080
- );
7054
+ collection,
7055
+ isPartialReindex: true
7056
+ });
7081
7057
  }
7082
7058
  }
7083
7059
  );
@@ -7087,18 +7063,17 @@ var Database = class {
7087
7063
  }
7088
7064
  };
7089
7065
  this.delete = async (filepath) => {
7090
- var _a;
7091
7066
  await this.initLevel();
7092
7067
  const collection = await this.collectionForPath(filepath);
7093
7068
  if (!collection) {
7094
7069
  throw new Error(`No collection found for path: ${filepath}`);
7095
7070
  }
7096
7071
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
7097
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
7098
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7072
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
7073
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
7099
7074
  let level = this.contentLevel;
7100
- if (collection == null ? void 0 : collection.isDetached) {
7101
- 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);
7102
7077
  }
7103
7078
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
7104
7079
  const rootSublevel = level.sublevel(
@@ -7145,7 +7120,7 @@ var Database = class {
7145
7120
  }
7146
7121
  ]);
7147
7122
  }
7148
- if (!(collection == null ? void 0 : collection.isDetached)) {
7123
+ if (!collection?.isDetached) {
7149
7124
  if (this.bridge) {
7150
7125
  await this.bridge.delete(normalizedPath);
7151
7126
  }
@@ -7185,26 +7160,26 @@ var Database = class {
7185
7160
  );
7186
7161
  const doc = await level2.keys({ limit: 1 }).next();
7187
7162
  if (!doc) {
7188
- await _indexContent(
7189
- this,
7190
- level2,
7191
- contentPaths,
7163
+ await _indexContent({
7164
+ database: this,
7165
+ level: level2,
7166
+ documentPaths: contentPaths,
7192
7167
  enqueueOps,
7193
7168
  collection,
7194
- userFields.map((field) => [
7169
+ passwordFields: userFields.map((field) => [
7195
7170
  ...field.path,
7196
7171
  field.passwordFieldName
7197
7172
  ])
7198
- );
7173
+ });
7199
7174
  }
7200
7175
  } else {
7201
- await _indexContent(
7202
- this,
7176
+ await _indexContent({
7177
+ database: this,
7203
7178
  level,
7204
- contentPaths,
7179
+ documentPaths: contentPaths,
7205
7180
  enqueueOps,
7206
7181
  collection
7207
- );
7182
+ });
7208
7183
  }
7209
7184
  }
7210
7185
  );
@@ -7240,7 +7215,7 @@ var Database = class {
7240
7215
  );
7241
7216
  }
7242
7217
  const metadata = await metadataLevel.get("metadata");
7243
- return metadata == null ? void 0 : metadata.version;
7218
+ return metadata?.version;
7244
7219
  }
7245
7220
  async initLevel() {
7246
7221
  if (this.contentLevel) {
@@ -7326,7 +7301,7 @@ var hashPasswordVisitor = async (node, path7) => {
7326
7301
  };
7327
7302
  var visitNodes = async (node, path7, callback) => {
7328
7303
  const [currentLevel, ...remainingLevels] = path7;
7329
- if (!(remainingLevels == null ? void 0 : remainingLevels.length)) {
7304
+ if (!remainingLevels?.length) {
7330
7305
  return callback(node, path7);
7331
7306
  }
7332
7307
  if (Array.isArray(node[currentLevel])) {
@@ -7342,20 +7317,27 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
7342
7317
  async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
7343
7318
  )
7344
7319
  );
7345
- var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${(collection == null ? void 0 : collection.format) || "md"}`);
7346
- var _indexContent = async (database, level, documentPaths, enqueueOps, collection, passwordFields) => {
7347
- 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
+ }) => {
7348
7330
  let collectionIndexDefinitions;
7349
7331
  let collectionPath;
7350
7332
  if (collection) {
7351
7333
  const indexDefinitions = await database.getIndexDefinitions(level);
7352
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7334
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7353
7335
  if (!collectionIndexDefinitions) {
7354
7336
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7355
7337
  }
7356
7338
  collectionPath = collection.path;
7357
7339
  }
7358
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7340
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7359
7341
  const tinaSchema = await database.getSchema();
7360
7342
  let templateInfo = null;
7361
7343
  if (collection) {
@@ -7373,7 +7355,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7373
7355
  if (!aliasedData) {
7374
7356
  return;
7375
7357
  }
7376
- if (passwordFields == null ? void 0 : passwordFields.length) {
7358
+ if (passwordFields?.length) {
7377
7359
  await hashPasswordValues(aliasedData, passwordFields);
7378
7360
  }
7379
7361
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
@@ -7385,46 +7367,48 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7385
7367
  normalizedPath,
7386
7368
  collectionPath || ""
7387
7369
  );
7388
- const item = await rootSublevel.get(normalizedPath);
7389
- if (item) {
7390
- await database.contentLevel.batch([
7391
- ...makeRefOpsForDocument(
7392
- normalizedPath,
7393
- collection == null ? void 0 : collection.name,
7394
- collectionReferences,
7395
- item,
7396
- "del",
7397
- level
7398
- ),
7399
- ...makeIndexOpsForDocument(
7400
- normalizedPath,
7401
- collection.name,
7402
- collectionIndexDefinitions,
7403
- item,
7404
- "del",
7405
- level
7406
- ),
7407
- // folder indices
7408
- ...makeIndexOpsForDocument(
7409
- normalizedPath,
7410
- `${collection.name}_${folderKey}`,
7411
- collectionIndexDefinitions,
7412
- item,
7413
- "del",
7414
- level
7415
- ),
7416
- {
7417
- type: "del",
7418
- key: normalizedPath,
7419
- sublevel: rootSublevel
7420
- }
7421
- ]);
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
+ }
7422
7406
  }
7423
7407
  if (!isGitKeep(filepath, collection)) {
7424
7408
  await enqueueOps([
7425
7409
  ...makeRefOpsForDocument(
7426
7410
  normalizedPath,
7427
- collection == null ? void 0 : collection.name,
7411
+ collection?.name,
7428
7412
  collectionReferences,
7429
7413
  aliasedData,
7430
7414
  "put",
@@ -7432,7 +7416,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7432
7416
  ),
7433
7417
  ...makeIndexOpsForDocument(
7434
7418
  normalizedPath,
7435
- collection == null ? void 0 : collection.name,
7419
+ collection?.name,
7436
7420
  collectionIndexDefinitions,
7437
7421
  aliasedData,
7438
7422
  "put",
@@ -7441,7 +7425,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7441
7425
  // folder indexes
7442
7426
  ...makeIndexOpsForDocument(
7443
7427
  normalizedPath,
7444
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7428
+ `${collection?.name}_${folderKey}`,
7445
7429
  collectionIndexDefinitions,
7446
7430
  aliasedData,
7447
7431
  "put",
@@ -7462,7 +7446,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7462
7446
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7463
7447
  originalError: error,
7464
7448
  file: filepath,
7465
- collection: collection == null ? void 0 : collection.name,
7449
+ collection: collection?.name,
7466
7450
  stack: error.stack
7467
7451
  });
7468
7452
  }
@@ -7480,7 +7464,6 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7480
7464
  }
7481
7465
  };
7482
7466
  var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
7483
- var _a;
7484
7467
  if (!documentPaths.length) {
7485
7468
  return;
7486
7469
  }
@@ -7489,12 +7472,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7489
7472
  const indexDefinitions = await database.getIndexDefinitions(
7490
7473
  database.contentLevel
7491
7474
  );
7492
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7475
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7493
7476
  if (!collectionIndexDefinitions) {
7494
7477
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7495
7478
  }
7496
7479
  }
7497
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7480
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7498
7481
  const tinaSchema = await database.getSchema();
7499
7482
  let templateInfo = null;
7500
7483
  if (collection) {
@@ -7511,7 +7494,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7511
7494
  if (item) {
7512
7495
  const folderKey = folderTreeBuilder.update(
7513
7496
  itemKey,
7514
- (collection == null ? void 0 : collection.path) || ""
7497
+ collection?.path || ""
7515
7498
  );
7516
7499
  const aliasedData = templateInfo ? replaceNameOverrides(
7517
7500
  getTemplateForFile(templateInfo, item),
@@ -7520,7 +7503,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7520
7503
  await enqueueOps([
7521
7504
  ...makeRefOpsForDocument(
7522
7505
  itemKey,
7523
- collection == null ? void 0 : collection.name,
7506
+ collection?.name,
7524
7507
  collectionReferences,
7525
7508
  aliasedData,
7526
7509
  "del",
@@ -7537,7 +7520,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7537
7520
  // folder indexes
7538
7521
  ...makeIndexOpsForDocument(
7539
7522
  itemKey,
7540
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7523
+ `${collection?.name}_${folderKey}`,
7541
7524
  collectionIndexDefinitions,
7542
7525
  aliasedData,
7543
7526
  "del",
@@ -7622,12 +7605,12 @@ var getChangedFiles = async ({
7622
7605
  }
7623
7606
  }
7624
7607
  }
7625
- if (await (B == null ? void 0 : B.type()) === "tree") {
7608
+ if (await B?.type() === "tree") {
7626
7609
  return;
7627
7610
  }
7628
7611
  if (matches) {
7629
- const oidA = await (A == null ? void 0 : A.oid());
7630
- const oidB = await (B == null ? void 0 : B.oid());
7612
+ const oidA = await A?.oid();
7613
+ const oidB = await B?.oid();
7631
7614
  if (oidA !== oidB) {
7632
7615
  if (oidA === void 0) {
7633
7616
  results.added.push(relativePath);
@@ -7655,8 +7638,8 @@ var import_path5 = __toESM(require("path"));
7655
7638
  var import_normalize_path = __toESM(require("normalize-path"));
7656
7639
  var FilesystemBridge = class {
7657
7640
  constructor(rootPath, outputPath) {
7658
- this.rootPath = rootPath || "";
7659
- this.outputPath = outputPath || rootPath;
7641
+ this.rootPath = import_path5.default.resolve(rootPath);
7642
+ this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
7660
7643
  }
7661
7644
  async glob(pattern, extension) {
7662
7645
  const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
@@ -7668,19 +7651,19 @@ var FilesystemBridge = class {
7668
7651
  }
7669
7652
  );
7670
7653
  const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
7671
- return items.map((item) => {
7672
- return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
7673
- });
7654
+ return items.map(
7655
+ (item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
7656
+ );
7674
7657
  }
7675
7658
  async delete(filepath) {
7676
7659
  await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
7677
7660
  }
7678
7661
  async get(filepath) {
7679
- 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();
7680
7663
  }
7681
7664
  async put(filepath, data, basePathOverride) {
7682
7665
  const basePath = basePathOverride || this.outputPath;
7683
- 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);
7684
7667
  }
7685
7668
  };
7686
7669
  var AuditFileSystemBridge = class extends FilesystemBridge {