@tinacms/graphql 0.0.0-bdc07c1-20250506013835 → 0.0.0-bdea884-20250606054015

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,38 +3109,34 @@ 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.3",
3130
- "fs-extra": "^11.3.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.29.0",
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.7.0",
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
- peerDependencies: {
3149
- "@tinacms/common": "workspace:*"
3150
- },
3151
3140
  publishConfig: {
3152
3141
  registry: "https://registry.npmjs.org"
3153
3142
  },
@@ -3160,21 +3149,20 @@ var package_default = {
3160
3149
  "@tinacms/scripts": "workspace:*",
3161
3150
  "@types/cors": "^2.8.17",
3162
3151
  "@types/estree": "^0.0.50",
3163
- "@types/express": "^4.17.21",
3152
+ "@types/express": "catalog:",
3164
3153
  "@types/fs-extra": "^9.0.13",
3165
3154
  "@types/js-yaml": "^3.12.10",
3166
- "@types/lodash.camelcase": "^4.3.9",
3167
- "@types/lodash.upperfirst": "^4.3.9",
3168
- "@types/lru-cache": "^5.1.1",
3169
- "@types/mdast": "^3.0.15",
3170
- "@types/micromatch": "^4.0.9",
3155
+ "@types/lodash.camelcase": "catalog:",
3156
+ "@types/lodash.upperfirst": "catalog:",
3157
+ "@types/lru-cache": "catalog:",
3158
+ "@types/mdast": "catalog:",
3159
+ "@types/micromatch": "catalog:",
3171
3160
  "@types/node": "^22.13.1",
3172
- "@types/normalize-path": "^3.0.2",
3173
- "@types/ws": "^7.4.7",
3161
+ "@types/normalize-path": "catalog:",
3162
+ "@types/ws": "catalog:",
3174
3163
  "@types/yup": "^0.29.14",
3175
3164
  "jest-file-snapshot": "^0.5.0",
3176
- "memory-level": "^1.0.0",
3177
- nodemon: "3.1.4",
3165
+ "memory-level": "catalog:",
3178
3166
  typescript: "^5.7.3",
3179
3167
  vite: "^4.5.9",
3180
3168
  vitest: "^0.32.4",
@@ -3260,7 +3248,6 @@ var _buildQueries = async (builder, tinaSchema) => {
3260
3248
  const operationsDefinitions = [];
3261
3249
  const collections = tinaSchema.getCollections();
3262
3250
  await sequential(collections, async (collection) => {
3263
- var _a, _b, _c;
3264
3251
  const queryName = NAMER.queryName(collection.namespace);
3265
3252
  const queryListName = NAMER.generateQueryListName(collection.namespace);
3266
3253
  const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
@@ -3275,7 +3262,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3275
3262
  filterType: queryFilterTypeName,
3276
3263
  // look for flag to see if the data layer is enabled
3277
3264
  dataLayer: Boolean(
3278
- (_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")
3279
3266
  )
3280
3267
  })
3281
3268
  );
@@ -3625,9 +3612,8 @@ var cleanUpSlashes = (path7) => {
3625
3612
  return "";
3626
3613
  };
3627
3614
  var hasTinaMediaConfig = (schema) => {
3628
- var _a, _b, _c, _d, _e, _f, _g, _h;
3629
- if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3630
- 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")
3631
3617
  return false;
3632
3618
  return true;
3633
3619
  };
@@ -3734,22 +3720,20 @@ var replaceNameOverrides = (template, obj) => {
3734
3720
  }
3735
3721
  };
3736
3722
  function isBlockField(field) {
3737
- var _a;
3738
- return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
3723
+ return field && field.type === "object" && field.templates?.length > 0;
3739
3724
  }
3740
3725
  var _replaceNameOverrides = (fields, obj) => {
3741
3726
  const output = {};
3742
3727
  Object.keys(obj).forEach((key) => {
3743
3728
  const field = fields.find(
3744
- (fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key
3729
+ (fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
3745
3730
  );
3746
- 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];
3747
3732
  });
3748
3733
  return output;
3749
3734
  };
3750
3735
  var getTemplateForData = (field, data) => {
3751
- var _a;
3752
- if ((_a = field.templates) == null ? void 0 : _a.length) {
3736
+ if (field.templates?.length) {
3753
3737
  const templateKey = "_template";
3754
3738
  if (data[templateKey]) {
3755
3739
  const result = field.templates.find(
@@ -3807,8 +3791,8 @@ var _applyNameOverrides = (fields, obj) => {
3807
3791
  const output = {};
3808
3792
  Object.keys(obj).forEach((key) => {
3809
3793
  const field = fields.find((field2) => field2.name === key);
3810
- const outputKey = (field == null ? void 0 : field.nameOverride) || key;
3811
- 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];
3812
3796
  });
3813
3797
  return output;
3814
3798
  };
@@ -3821,7 +3805,6 @@ var matterEngines = {
3821
3805
  }
3822
3806
  };
3823
3807
  var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3824
- var _a, _b;
3825
3808
  const {
3826
3809
  _relativePath,
3827
3810
  _keepTemplateKey,
@@ -3845,9 +3828,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3845
3828
  ${$_body}`,
3846
3829
  strippedContent,
3847
3830
  {
3848
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3831
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3849
3832
  engines: matterEngines,
3850
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---"
3833
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
3851
3834
  }
3852
3835
  );
3853
3836
  return ok;
@@ -3863,15 +3846,14 @@ ${$_body}`,
3863
3846
  }
3864
3847
  };
3865
3848
  var parseFile = (content, format, yupSchema, markdownParseConfig) => {
3866
- var _a, _b;
3867
3849
  try {
3868
3850
  switch (format) {
3869
3851
  case ".markdown":
3870
3852
  case ".mdx":
3871
3853
  case ".md":
3872
3854
  const contentJSON = (0, import_gray_matter.default)(content || "", {
3873
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3874
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---",
3855
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3856
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
3875
3857
  engines: matterEngines
3876
3858
  });
3877
3859
  const markdownData = {
@@ -3970,7 +3952,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3970
3952
  ),
3971
3953
  template: void 0
3972
3954
  } : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
3973
- const field = template == null ? void 0 : template.fields.find((field2) => {
3955
+ const field = template?.fields.find((field2) => {
3974
3956
  if (field2.type === "string" || field2.type === "rich-text") {
3975
3957
  if (field2.isBody) {
3976
3958
  return true;
@@ -3990,7 +3972,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3990
3972
  ...data,
3991
3973
  _collection: collection.name,
3992
3974
  _keepTemplateKey: !!collection.templates,
3993
- _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,
3994
3976
  _relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
3995
3977
  _id: filepath
3996
3978
  };
@@ -3999,10 +3981,10 @@ function hasOwnProperty(obj, prop) {
3999
3981
  return obj.hasOwnProperty(prop);
4000
3982
  }
4001
3983
  var getTemplateForFile = (templateInfo, data) => {
4002
- if ((templateInfo == null ? void 0 : templateInfo.type) === "object") {
3984
+ if (templateInfo?.type === "object") {
4003
3985
  return templateInfo.template;
4004
3986
  }
4005
- if ((templateInfo == null ? void 0 : templateInfo.type) === "union") {
3987
+ if (templateInfo?.type === "union") {
4006
3988
  if (hasOwnProperty(data, "_template")) {
4007
3989
  const template = templateInfo.templates.find(
4008
3990
  (t) => lastItem(t.namespace) === data._template
@@ -4026,8 +4008,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
4026
4008
  import_path.default.extname(filepath),
4027
4009
  (yup3) => yup3.object({}),
4028
4010
  {
4029
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
4030
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
4011
+ frontmatterDelimiters: collection?.frontmatterDelimiters,
4012
+ frontmatterFormat: collection?.frontmatterFormat
4031
4013
  }
4032
4014
  );
4033
4015
  const template = getTemplateForFile(templateInfo, data);
@@ -4694,7 +4676,6 @@ var createResolver = (args) => {
4694
4676
  return new Resolver(args);
4695
4677
  };
4696
4678
  var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4697
- var _a, _b;
4698
4679
  if (!rawData) {
4699
4680
  return void 0;
4700
4681
  }
@@ -4722,7 +4703,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4722
4703
  accumulator[field.name] = {
4723
4704
  value: void 0,
4724
4705
  // never resolve the password hash
4725
- passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4706
+ passwordChangeRequired: value["passwordChangeRequired"] ?? false
4726
4707
  };
4727
4708
  break;
4728
4709
  case "image":
@@ -4738,11 +4719,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4738
4719
  field,
4739
4720
  (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4740
4721
  );
4741
- if (((_b = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _b.type) === "invalid_markdown") {
4722
+ if (tree?.children[0]?.type === "invalid_markdown") {
4742
4723
  if (isAudit) {
4743
- const invalidNode = tree == null ? void 0 : tree.children[0];
4724
+ const invalidNode = tree?.children[0];
4744
4725
  throw new import_graphql3.GraphQLError(
4745
- `${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}` : ""}`
4746
4727
  );
4747
4728
  }
4748
4729
  }
@@ -4855,11 +4836,11 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4855
4836
  });
4856
4837
  }
4857
4838
  const titleField = template.fields.find((x) => {
4858
- if (x.type === "string" && (x == null ? void 0 : x.isTitle)) {
4839
+ if (x.type === "string" && x?.isTitle) {
4859
4840
  return true;
4860
4841
  }
4861
4842
  });
4862
- const titleFieldName = titleField == null ? void 0 : titleField.name;
4843
+ const titleFieldName = titleField?.name;
4863
4844
  const title = data[titleFieldName || " "] || null;
4864
4845
  return {
4865
4846
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
@@ -4969,7 +4950,7 @@ var Resolver = class {
4969
4950
  );
4970
4951
  }
4971
4952
  const rawData = await this.getRaw(fullPath);
4972
- 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;
4973
4954
  return transformDocumentIntoPayload(
4974
4955
  fullPath,
4975
4956
  rawData,
@@ -5009,9 +4990,9 @@ var Resolver = class {
5009
4990
  return this.buildFieldMutations(
5010
4991
  item,
5011
4992
  objectTemplate,
5012
- idField && existingData && (existingData == null ? void 0 : existingData.find(
4993
+ idField && existingData && existingData?.find(
5013
4994
  (d) => d[idField.name] === item[idField.name]
5014
- ))
4995
+ )
5015
4996
  );
5016
4997
  }
5017
4998
  )
@@ -5137,7 +5118,7 @@ var Resolver = class {
5137
5118
  isCollectionSpecific
5138
5119
  }) => {
5139
5120
  const doc = await this.getDocument(realPath);
5140
- const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
5121
+ const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
5141
5122
  if (isAddPendingDocument === true) {
5142
5123
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
5143
5124
  const params2 = this.buildParams(args);
@@ -5147,7 +5128,7 @@ var Resolver = class {
5147
5128
  const values = await this.buildFieldMutations(
5148
5129
  params2,
5149
5130
  templateInfo.template,
5150
- doc == null ? void 0 : doc._rawData
5131
+ doc?._rawData
5151
5132
  );
5152
5133
  await this.database.put(
5153
5134
  realPath,
@@ -5171,7 +5152,7 @@ var Resolver = class {
5171
5152
  // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
5172
5153
  templateParams,
5173
5154
  template,
5174
- doc == null ? void 0 : doc._rawData
5155
+ doc?._rawData
5175
5156
  ),
5176
5157
  _template: lastItem(template.namespace)
5177
5158
  };
@@ -5185,7 +5166,7 @@ var Resolver = class {
5185
5166
  //@ts-ignore
5186
5167
  isCollectionSpecific ? args.params : args.params[collection.name],
5187
5168
  collection,
5188
- doc == null ? void 0 : doc._rawData
5169
+ doc?._rawData
5189
5170
  );
5190
5171
  await this.database.put(
5191
5172
  realPath,
@@ -5201,7 +5182,6 @@ var Resolver = class {
5201
5182
  this.resolveLegacyValues = (oldDoc, collection) => {
5202
5183
  const legacyValues = {};
5203
5184
  Object.entries(oldDoc).forEach(([key, value]) => {
5204
- var _a;
5205
5185
  const reservedKeys = [
5206
5186
  "$_body",
5207
5187
  "_collection",
@@ -5214,7 +5194,7 @@ var Resolver = class {
5214
5194
  return;
5215
5195
  }
5216
5196
  if (oldDoc._template && collection.templates) {
5217
- const template = (_a = collection.templates) == null ? void 0 : _a.find(
5197
+ const template = collection.templates?.find(
5218
5198
  ({ name }) => name === oldDoc._template
5219
5199
  );
5220
5200
  if (template) {
@@ -5261,7 +5241,7 @@ var Resolver = class {
5261
5241
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5262
5242
  );
5263
5243
  const collection = await this.tinaSchema.getCollection(collectionLookup);
5264
- 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);
5265
5245
  if (isFolderCreation) {
5266
5246
  realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
5267
5247
  }
@@ -5345,12 +5325,12 @@ var Resolver = class {
5345
5325
  (yup3) => yup3.object({ params: yup3.object().required() })
5346
5326
  );
5347
5327
  assertShape(
5348
- args == null ? void 0 : args.params,
5328
+ args?.params,
5349
5329
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5350
5330
  );
5351
5331
  const doc = await this.getDocument(realPath);
5352
5332
  const newRealPath = import_path3.default.join(
5353
- collection == null ? void 0 : collection.path,
5333
+ collection?.path,
5354
5334
  args.params.relativePath
5355
5335
  );
5356
5336
  if (newRealPath === realPath) {
@@ -5580,7 +5560,7 @@ var Resolver = class {
5580
5560
  if (!references[c.name][refId]) {
5581
5561
  references[c.name][refId] = [];
5582
5562
  }
5583
- const referencePath = rawItem == null ? void 0 : rawItem[REFS_PATH_FIELD];
5563
+ const referencePath = rawItem?.[REFS_PATH_FIELD];
5584
5564
  if (referencePath) {
5585
5565
  references[c.name][refId].push(referencePath);
5586
5566
  }
@@ -5590,7 +5570,6 @@ var Resolver = class {
5590
5570
  return references;
5591
5571
  };
5592
5572
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
5593
- var _a;
5594
5573
  const accum = {};
5595
5574
  for (const passwordField of template.fields.filter(
5596
5575
  (f) => f.type === "password"
@@ -5633,7 +5612,7 @@ var Resolver = class {
5633
5612
  accum[fieldName] = await this.buildObjectMutations(
5634
5613
  fieldValue,
5635
5614
  field,
5636
- existingData == null ? void 0 : existingData[fieldName]
5615
+ existingData?.[fieldName]
5637
5616
  );
5638
5617
  break;
5639
5618
  case "password":
@@ -5652,7 +5631,7 @@ var Resolver = class {
5652
5631
  } else {
5653
5632
  accum[fieldName] = {
5654
5633
  ...fieldValue,
5655
- value: (_a = existingData == null ? void 0 : existingData[fieldName]) == null ? void 0 : _a["value"]
5634
+ value: existingData?.[fieldName]?.["value"]
5656
5635
  };
5657
5636
  }
5658
5637
  break;
@@ -5787,9 +5766,8 @@ var resolve = async ({
5787
5766
  isAudit,
5788
5767
  ctxUser
5789
5768
  }) => {
5790
- var _a;
5791
5769
  try {
5792
- const verboseValue = verbose != null ? verbose : true;
5770
+ const verboseValue = verbose ?? true;
5793
5771
  const graphQLSchemaAst = await database.getGraphQLSchema();
5794
5772
  if (!graphQLSchemaAst) {
5795
5773
  throw new import_graphql5.GraphQLError("GraphQL schema not found");
@@ -5801,7 +5779,7 @@ var resolve = async ({
5801
5779
  // @ts-ignore
5802
5780
  schema: tinaConfig,
5803
5781
  // @ts-ignore
5804
- flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5782
+ flags: tinaConfig?.meta?.flags
5805
5783
  });
5806
5784
  const resolver = createResolver({
5807
5785
  config,
@@ -5826,7 +5804,6 @@ var resolve = async ({
5826
5804
  throw new Error(`Unable to find lookup key for ${namedType}`);
5827
5805
  },
5828
5806
  fieldResolver: async (source = {}, _args = {}, _context, info) => {
5829
- var _a2, _b, _c, _d;
5830
5807
  try {
5831
5808
  const args = JSON.parse(JSON.stringify(_args));
5832
5809
  const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
@@ -5843,8 +5820,7 @@ var resolve = async ({
5843
5820
  );
5844
5821
  const hasDocuments2 = collectionNode2.selectionSet.selections.find(
5845
5822
  (x) => {
5846
- var _a3;
5847
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5823
+ return x?.name?.value === "documents";
5848
5824
  }
5849
5825
  );
5850
5826
  return tinaSchema.getCollections().map((collection) => {
@@ -5860,8 +5836,7 @@ var resolve = async ({
5860
5836
  );
5861
5837
  const hasDocuments = collectionNode.selectionSet.selections.find(
5862
5838
  (x) => {
5863
- var _a3;
5864
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5839
+ return x?.name?.value === "documents";
5865
5840
  }
5866
5841
  );
5867
5842
  return resolver.resolveCollection(
@@ -5880,7 +5855,7 @@ var resolve = async ({
5880
5855
  }
5881
5856
  }
5882
5857
  if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
5883
- const sub = args.sub || (ctxUser == null ? void 0 : ctxUser.sub);
5858
+ const sub = args.sub || ctxUser?.sub;
5884
5859
  const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5885
5860
  if (!collection) {
5886
5861
  throw new Error("Auth collection not found");
@@ -5928,7 +5903,7 @@ var resolve = async ({
5928
5903
  return user;
5929
5904
  }
5930
5905
  if (info.fieldName === "updatePassword") {
5931
- if (!(ctxUser == null ? void 0 : ctxUser.sub)) {
5906
+ if (!ctxUser?.sub) {
5932
5907
  throw new Error("Not authorized");
5933
5908
  }
5934
5909
  if (!args.password) {
@@ -6011,7 +5986,7 @@ var resolve = async ({
6011
5986
  if (typeof value === "string" && value !== "") {
6012
5987
  return resolver.getDocument(value);
6013
5988
  }
6014
- if ((args == null ? void 0 : args.collection) && info.fieldName === "addPendingDocument") {
5989
+ if (args?.collection && info.fieldName === "addPendingDocument") {
6015
5990
  return resolver.resolveDocument({
6016
5991
  args: { ...args, params: {} },
6017
5992
  collection: args.collection,
@@ -6035,7 +6010,7 @@ var resolve = async ({
6035
6010
  // Right now this is the only case for deletion
6036
6011
  isDeletion: info.fieldName === "deleteDocument",
6037
6012
  isFolderCreation: info.fieldName === "createFolder",
6038
- isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
6013
+ isUpdateName: Boolean(args?.params?.relativePath),
6039
6014
  isAddPendingDocument: false,
6040
6015
  isCollectionSpecific: false
6041
6016
  });
@@ -6054,16 +6029,16 @@ var resolve = async ({
6054
6029
  })
6055
6030
  };
6056
6031
  }
6057
- 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) {
6058
6033
  let filter = args.filter;
6059
6034
  if (
6060
6035
  // 1. Make sure that the filter exists
6061
- 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
6062
6037
  // @ts-ignore
6063
- 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
6064
6039
  // @ts-ignore
6065
- Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
6066
- 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"
6067
6042
  ) {
6068
6043
  filter = args.filter[value.collection.name];
6069
6044
  }
@@ -6200,15 +6175,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
6200
6175
  };
6201
6176
 
6202
6177
  // src/database/index.ts
6203
- var import_node_path = __toESM(require("path"));
6178
+ var import_node_path = __toESM(require("node:path"));
6204
6179
  var import_graphql6 = require("graphql");
6205
6180
  var import_micromatch2 = __toESM(require("micromatch"));
6206
6181
  var import_js_sha12 = __toESM(require("js-sha1"));
6207
6182
  var import_lodash5 = __toESM(require("lodash.set"));
6208
6183
  var createLocalDatabase = (config) => {
6209
- const level = new TinaLevelClient(config == null ? void 0 : config.port);
6184
+ const level = new TinaLevelClient(config?.port);
6210
6185
  level.openConnection();
6211
- const fsBridge = new FilesystemBridge((config == null ? void 0 : config.rootPath) || process.cwd());
6186
+ const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
6212
6187
  return new Database({
6213
6188
  bridge: fsBridge,
6214
6189
  ...config || {},
@@ -6281,7 +6256,7 @@ var Database = class {
6281
6256
  );
6282
6257
  }
6283
6258
  const metadata = await metadataLevel.get(`metadata_${key}`);
6284
- return metadata == null ? void 0 : metadata.value;
6259
+ return metadata?.value;
6285
6260
  };
6286
6261
  this.setMetadata = async (key, value) => {
6287
6262
  await this.initLevel();
@@ -6303,7 +6278,7 @@ var Database = class {
6303
6278
  let level = this.contentLevel;
6304
6279
  if (this.appLevel) {
6305
6280
  collection = await this.collectionForPath(filepath);
6306
- if (collection == null ? void 0 : collection.isDetached) {
6281
+ if (collection?.isDetached) {
6307
6282
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6308
6283
  }
6309
6284
  }
@@ -6322,7 +6297,6 @@ var Database = class {
6322
6297
  }
6323
6298
  };
6324
6299
  this.addPendingDocument = async (filepath, data) => {
6325
- var _a;
6326
6300
  await this.initLevel();
6327
6301
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6328
6302
  const collection = await this.collectionForPath(filepath);
@@ -6335,10 +6309,10 @@ var Database = class {
6335
6309
  collection
6336
6310
  );
6337
6311
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6338
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
6339
- 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];
6340
6314
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6341
- if (!(collection == null ? void 0 : collection.isDetached)) {
6315
+ if (!collection?.isDetached) {
6342
6316
  if (this.bridge) {
6343
6317
  await this.bridge.put(normalizedPath, stringifiedFile);
6344
6318
  }
@@ -6356,7 +6330,7 @@ var Database = class {
6356
6330
  }
6357
6331
  }
6358
6332
  let level = this.contentLevel;
6359
- if (collection == null ? void 0 : collection.isDetached) {
6333
+ if (collection?.isDetached) {
6360
6334
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6361
6335
  }
6362
6336
  const folderTreeBuilder = new FolderTreeBuilder();
@@ -6367,7 +6341,7 @@ var Database = class {
6367
6341
  putOps = [
6368
6342
  ...makeRefOpsForDocument(
6369
6343
  normalizedPath,
6370
- collection == null ? void 0 : collection.name,
6344
+ collection?.name,
6371
6345
  collectionReferences,
6372
6346
  dataFields,
6373
6347
  "put",
@@ -6375,7 +6349,7 @@ var Database = class {
6375
6349
  ),
6376
6350
  ...makeIndexOpsForDocument(
6377
6351
  normalizedPath,
6378
- collection == null ? void 0 : collection.name,
6352
+ collection?.name,
6379
6353
  collectionIndexDefinitions,
6380
6354
  dataFields,
6381
6355
  "put",
@@ -6384,7 +6358,7 @@ var Database = class {
6384
6358
  // folder indices
6385
6359
  ...makeIndexOpsForDocument(
6386
6360
  normalizedPath,
6387
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6361
+ `${collection?.name}_${folderKey}`,
6388
6362
  collectionIndexDefinitions,
6389
6363
  dataFields,
6390
6364
  "put",
@@ -6398,7 +6372,7 @@ var Database = class {
6398
6372
  delOps = existingItem ? [
6399
6373
  ...makeRefOpsForDocument(
6400
6374
  normalizedPath,
6401
- collection == null ? void 0 : collection.name,
6375
+ collection?.name,
6402
6376
  collectionReferences,
6403
6377
  existingItem,
6404
6378
  "del",
@@ -6406,7 +6380,7 @@ var Database = class {
6406
6380
  ),
6407
6381
  ...makeIndexOpsForDocument(
6408
6382
  normalizedPath,
6409
- collection == null ? void 0 : collection.name,
6383
+ collection?.name,
6410
6384
  collectionIndexDefinitions,
6411
6385
  existingItem,
6412
6386
  "del",
@@ -6415,7 +6389,7 @@ var Database = class {
6415
6389
  // folder indices
6416
6390
  ...makeIndexOpsForDocument(
6417
6391
  normalizedPath,
6418
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6392
+ `${collection?.name}_${folderKey}`,
6419
6393
  collectionIndexDefinitions,
6420
6394
  existingItem,
6421
6395
  "del",
@@ -6439,7 +6413,6 @@ var Database = class {
6439
6413
  await level.batch(ops);
6440
6414
  };
6441
6415
  this.put = async (filepath, data, collectionName) => {
6442
- var _a, _b, _c;
6443
6416
  await this.initLevel();
6444
6417
  try {
6445
6418
  if (SYSTEM_FILES.includes(filepath)) {
@@ -6450,16 +6423,16 @@ var Database = class {
6450
6423
  const indexDefinitions = await this.getIndexDefinitions(
6451
6424
  this.contentLevel
6452
6425
  );
6453
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
6426
+ collectionIndexDefinitions = indexDefinitions?.[collectionName];
6454
6427
  }
6455
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collectionName];
6428
+ const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
6456
6429
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6457
6430
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6458
6431
  const collection = await this.collectionForPath(filepath);
6459
6432
  if (!collection) {
6460
6433
  throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
6461
6434
  }
6462
- 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) {
6463
6436
  const matches = this.tinaSchema.getMatches({ collection });
6464
6437
  const match = import_micromatch2.default.isMatch(filepath, matches);
6465
6438
  if (!match) {
@@ -6473,7 +6446,7 @@ var Database = class {
6473
6446
  const stringifiedFile = filepath.endsWith(
6474
6447
  `.gitkeep.${collection.format || "md"}`
6475
6448
  ) ? "" : await this.stringifyFile(filepath, dataFields, collection);
6476
- if (!(collection == null ? void 0 : collection.isDetached)) {
6449
+ if (!collection?.isDetached) {
6477
6450
  if (this.bridge) {
6478
6451
  await this.bridge.put(normalizedPath, stringifiedFile);
6479
6452
  }
@@ -6495,7 +6468,7 @@ var Database = class {
6495
6468
  filepath,
6496
6469
  collection.path || ""
6497
6470
  );
6498
- 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;
6499
6472
  let putOps = [];
6500
6473
  let delOps = [];
6501
6474
  if (!isGitKeep(normalizedPath, collection)) {
@@ -6519,7 +6492,7 @@ var Database = class {
6519
6492
  // folder indices
6520
6493
  ...makeIndexOpsForDocument(
6521
6494
  normalizedPath,
6522
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6495
+ `${collection?.name}_${folderKey}`,
6523
6496
  collectionIndexDefinitions,
6524
6497
  dataFields,
6525
6498
  "put",
@@ -6550,7 +6523,7 @@ var Database = class {
6550
6523
  // folder indices
6551
6524
  ...makeIndexOpsForDocument(
6552
6525
  normalizedPath,
6553
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6526
+ `${collection?.name}_${folderKey}`,
6554
6527
  collectionIndexDefinitions,
6555
6528
  existingItem,
6556
6529
  "del",
@@ -6627,8 +6600,8 @@ var Database = class {
6627
6600
  writeTemplateKey,
6628
6601
  //templateInfo.type === 'union',
6629
6602
  {
6630
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6631
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
6603
+ frontmatterFormat: collection?.frontmatterFormat,
6604
+ frontmatterDelimiters: collection?.frontmatterDelimiters
6632
6605
  }
6633
6606
  );
6634
6607
  };
@@ -6797,8 +6770,8 @@ var Database = class {
6797
6770
  );
6798
6771
  return {
6799
6772
  name: indexField.name,
6800
- type: field == null ? void 0 : field.type,
6801
- list: !!(field == null ? void 0 : field.list)
6773
+ type: field?.type,
6774
+ list: !!field?.list
6802
6775
  };
6803
6776
  })
6804
6777
  };
@@ -6824,7 +6797,6 @@ var Database = class {
6824
6797
  return true;
6825
6798
  };
6826
6799
  this.query = async (queryOptions, hydrator) => {
6827
- var _a;
6828
6800
  await this.initLevel();
6829
6801
  const {
6830
6802
  first,
@@ -6852,14 +6824,14 @@ var Database = class {
6852
6824
  const allIndexDefinitions = await this.getIndexDefinitions(
6853
6825
  this.contentLevel
6854
6826
  );
6855
- const indexDefinitions = allIndexDefinitions == null ? void 0 : allIndexDefinitions[collection.name];
6827
+ const indexDefinitions = allIndexDefinitions?.[collection.name];
6856
6828
  if (!indexDefinitions) {
6857
6829
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
6858
6830
  }
6859
6831
  const filterChain = coerceFilterChainOperands(rawFilterChain);
6860
- const indexDefinition = sort && (indexDefinitions == null ? void 0 : indexDefinitions[sort]);
6832
+ const indexDefinition = sort && indexDefinitions?.[sort];
6861
6833
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
6862
- 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;
6863
6835
  const rootLevel = level.sublevel(
6864
6836
  CONTENT_ROOT_PREFIX,
6865
6837
  SUBLEVEL_OPTIONS
@@ -6869,17 +6841,17 @@ var Database = class {
6869
6841
  SUBLEVEL_OPTIONS
6870
6842
  ).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
6871
6843
  if (!query.gt && !query.gte) {
6872
- query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
6844
+ query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
6873
6845
  }
6874
6846
  if (!query.lt && !query.lte) {
6875
- query.lte = (filterSuffixes == null ? void 0 : filterSuffixes.right) ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6847
+ query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6876
6848
  }
6877
6849
  let edges = [];
6878
6850
  let startKey = "";
6879
6851
  let endKey = "";
6880
6852
  let hasPreviousPage = false;
6881
6853
  let hasNextPage = false;
6882
- 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("")}` : "";
6883
6855
  const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
6884
6856
  const itemFilter = makeFilter({ filterChain });
6885
6857
  const iterator = sublevel.iterator(query);
@@ -7091,18 +7063,17 @@ var Database = class {
7091
7063
  }
7092
7064
  };
7093
7065
  this.delete = async (filepath) => {
7094
- var _a;
7095
7066
  await this.initLevel();
7096
7067
  const collection = await this.collectionForPath(filepath);
7097
7068
  if (!collection) {
7098
7069
  throw new Error(`No collection found for path: ${filepath}`);
7099
7070
  }
7100
7071
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
7101
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
7102
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7072
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
7073
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
7103
7074
  let level = this.contentLevel;
7104
- if (collection == null ? void 0 : collection.isDetached) {
7105
- 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);
7106
7077
  }
7107
7078
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
7108
7079
  const rootSublevel = level.sublevel(
@@ -7149,7 +7120,7 @@ var Database = class {
7149
7120
  }
7150
7121
  ]);
7151
7122
  }
7152
- if (!(collection == null ? void 0 : collection.isDetached)) {
7123
+ if (!collection?.isDetached) {
7153
7124
  if (this.bridge) {
7154
7125
  await this.bridge.delete(normalizedPath);
7155
7126
  }
@@ -7244,7 +7215,7 @@ var Database = class {
7244
7215
  );
7245
7216
  }
7246
7217
  const metadata = await metadataLevel.get("metadata");
7247
- return metadata == null ? void 0 : metadata.version;
7218
+ return metadata?.version;
7248
7219
  }
7249
7220
  async initLevel() {
7250
7221
  if (this.contentLevel) {
@@ -7330,7 +7301,7 @@ var hashPasswordVisitor = async (node, path7) => {
7330
7301
  };
7331
7302
  var visitNodes = async (node, path7, callback) => {
7332
7303
  const [currentLevel, ...remainingLevels] = path7;
7333
- if (!(remainingLevels == null ? void 0 : remainingLevels.length)) {
7304
+ if (!remainingLevels?.length) {
7334
7305
  return callback(node, path7);
7335
7306
  }
7336
7307
  if (Array.isArray(node[currentLevel])) {
@@ -7346,7 +7317,7 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
7346
7317
  async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
7347
7318
  )
7348
7319
  );
7349
- var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${(collection == null ? void 0 : collection.format) || "md"}`);
7320
+ var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
7350
7321
  var _indexContent = async ({
7351
7322
  database,
7352
7323
  level,
@@ -7356,18 +7327,17 @@ var _indexContent = async ({
7356
7327
  passwordFields,
7357
7328
  isPartialReindex
7358
7329
  }) => {
7359
- var _a;
7360
7330
  let collectionIndexDefinitions;
7361
7331
  let collectionPath;
7362
7332
  if (collection) {
7363
7333
  const indexDefinitions = await database.getIndexDefinitions(level);
7364
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7334
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7365
7335
  if (!collectionIndexDefinitions) {
7366
7336
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7367
7337
  }
7368
7338
  collectionPath = collection.path;
7369
7339
  }
7370
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7340
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7371
7341
  const tinaSchema = await database.getSchema();
7372
7342
  let templateInfo = null;
7373
7343
  if (collection) {
@@ -7385,7 +7355,7 @@ var _indexContent = async ({
7385
7355
  if (!aliasedData) {
7386
7356
  return;
7387
7357
  }
7388
- if (passwordFields == null ? void 0 : passwordFields.length) {
7358
+ if (passwordFields?.length) {
7389
7359
  await hashPasswordValues(aliasedData, passwordFields);
7390
7360
  }
7391
7361
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
@@ -7403,7 +7373,7 @@ var _indexContent = async ({
7403
7373
  await database.contentLevel.batch([
7404
7374
  ...makeRefOpsForDocument(
7405
7375
  normalizedPath,
7406
- collection == null ? void 0 : collection.name,
7376
+ collection?.name,
7407
7377
  collectionReferences,
7408
7378
  item,
7409
7379
  "del",
@@ -7438,7 +7408,7 @@ var _indexContent = async ({
7438
7408
  await enqueueOps([
7439
7409
  ...makeRefOpsForDocument(
7440
7410
  normalizedPath,
7441
- collection == null ? void 0 : collection.name,
7411
+ collection?.name,
7442
7412
  collectionReferences,
7443
7413
  aliasedData,
7444
7414
  "put",
@@ -7446,7 +7416,7 @@ var _indexContent = async ({
7446
7416
  ),
7447
7417
  ...makeIndexOpsForDocument(
7448
7418
  normalizedPath,
7449
- collection == null ? void 0 : collection.name,
7419
+ collection?.name,
7450
7420
  collectionIndexDefinitions,
7451
7421
  aliasedData,
7452
7422
  "put",
@@ -7455,7 +7425,7 @@ var _indexContent = async ({
7455
7425
  // folder indexes
7456
7426
  ...makeIndexOpsForDocument(
7457
7427
  normalizedPath,
7458
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7428
+ `${collection?.name}_${folderKey}`,
7459
7429
  collectionIndexDefinitions,
7460
7430
  aliasedData,
7461
7431
  "put",
@@ -7476,7 +7446,7 @@ var _indexContent = async ({
7476
7446
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7477
7447
  originalError: error,
7478
7448
  file: filepath,
7479
- collection: collection == null ? void 0 : collection.name,
7449
+ collection: collection?.name,
7480
7450
  stack: error.stack
7481
7451
  });
7482
7452
  }
@@ -7494,7 +7464,6 @@ var _indexContent = async ({
7494
7464
  }
7495
7465
  };
7496
7466
  var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
7497
- var _a;
7498
7467
  if (!documentPaths.length) {
7499
7468
  return;
7500
7469
  }
@@ -7503,12 +7472,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7503
7472
  const indexDefinitions = await database.getIndexDefinitions(
7504
7473
  database.contentLevel
7505
7474
  );
7506
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7475
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7507
7476
  if (!collectionIndexDefinitions) {
7508
7477
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7509
7478
  }
7510
7479
  }
7511
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7480
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7512
7481
  const tinaSchema = await database.getSchema();
7513
7482
  let templateInfo = null;
7514
7483
  if (collection) {
@@ -7525,7 +7494,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7525
7494
  if (item) {
7526
7495
  const folderKey = folderTreeBuilder.update(
7527
7496
  itemKey,
7528
- (collection == null ? void 0 : collection.path) || ""
7497
+ collection?.path || ""
7529
7498
  );
7530
7499
  const aliasedData = templateInfo ? replaceNameOverrides(
7531
7500
  getTemplateForFile(templateInfo, item),
@@ -7534,7 +7503,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7534
7503
  await enqueueOps([
7535
7504
  ...makeRefOpsForDocument(
7536
7505
  itemKey,
7537
- collection == null ? void 0 : collection.name,
7506
+ collection?.name,
7538
7507
  collectionReferences,
7539
7508
  aliasedData,
7540
7509
  "del",
@@ -7551,7 +7520,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7551
7520
  // folder indexes
7552
7521
  ...makeIndexOpsForDocument(
7553
7522
  itemKey,
7554
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7523
+ `${collection?.name}_${folderKey}`,
7555
7524
  collectionIndexDefinitions,
7556
7525
  aliasedData,
7557
7526
  "del",
@@ -7636,12 +7605,12 @@ var getChangedFiles = async ({
7636
7605
  }
7637
7606
  }
7638
7607
  }
7639
- if (await (B == null ? void 0 : B.type()) === "tree") {
7608
+ if (await B?.type() === "tree") {
7640
7609
  return;
7641
7610
  }
7642
7611
  if (matches) {
7643
- const oidA = await (A == null ? void 0 : A.oid());
7644
- const oidB = await (B == null ? void 0 : B.oid());
7612
+ const oidA = await A?.oid();
7613
+ const oidB = await B?.oid();
7645
7614
  if (oidA !== oidB) {
7646
7615
  if (oidA === void 0) {
7647
7616
  results.added.push(relativePath);
@@ -7669,8 +7638,8 @@ var import_path5 = __toESM(require("path"));
7669
7638
  var import_normalize_path = __toESM(require("normalize-path"));
7670
7639
  var FilesystemBridge = class {
7671
7640
  constructor(rootPath, outputPath) {
7672
- this.rootPath = rootPath || "";
7673
- this.outputPath = outputPath || rootPath;
7641
+ this.rootPath = import_path5.default.resolve(rootPath);
7642
+ this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
7674
7643
  }
7675
7644
  async glob(pattern, extension) {
7676
7645
  const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
@@ -7682,19 +7651,19 @@ var FilesystemBridge = class {
7682
7651
  }
7683
7652
  );
7684
7653
  const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
7685
- return items.map((item) => {
7686
- return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
7687
- });
7654
+ return items.map(
7655
+ (item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
7656
+ );
7688
7657
  }
7689
7658
  async delete(filepath) {
7690
7659
  await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
7691
7660
  }
7692
7661
  async get(filepath) {
7693
- 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();
7694
7663
  }
7695
7664
  async put(filepath, data, basePathOverride) {
7696
7665
  const basePath = basePathOverride || this.outputPath;
7697
- 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);
7698
7667
  }
7699
7668
  };
7700
7669
  var AuditFileSystemBridge = class extends FilesystemBridge {