@tinacms/graphql 1.5.17 → 1.5.19

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.17",
3086
+ version: "1.5.19",
3094
3087
  main: "dist/index.js",
3095
3088
  module: "dist/index.mjs",
3096
3089
  typings: "dist/index.d.ts",
@@ -3255,7 +3248,6 @@ var _buildQueries = async (builder, tinaSchema) => {
3255
3248
  const operationsDefinitions = [];
3256
3249
  const collections = tinaSchema.getCollections();
3257
3250
  await sequential(collections, async (collection) => {
3258
- var _a, _b, _c;
3259
3251
  const queryName = NAMER.queryName(collection.namespace);
3260
3252
  const queryListName = NAMER.generateQueryListName(collection.namespace);
3261
3253
  const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
@@ -3270,7 +3262,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3270
3262
  filterType: queryFilterTypeName,
3271
3263
  // look for flag to see if the data layer is enabled
3272
3264
  dataLayer: Boolean(
3273
- (_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")
3274
3266
  )
3275
3267
  })
3276
3268
  );
@@ -3382,251 +3374,11 @@ var import_graphql5 = require("graphql");
3382
3374
  // src/resolver/index.ts
3383
3375
  var import_path3 = __toESM(require("path"));
3384
3376
  var import_isValid = __toESM(require("date-fns/isValid/index.js"));
3377
+ var import_jsonpath_plus2 = require("jsonpath-plus");
3385
3378
 
3386
3379
  // src/mdx/index.ts
3387
3380
  var import_mdx = require("@tinacms/mdx");
3388
3381
 
3389
- // src/resolver/index.ts
3390
- var import_jsonpath_plus2 = require("jsonpath-plus");
3391
-
3392
- // src/resolver/error.ts
3393
- var TinaGraphQLError = class extends Error {
3394
- constructor(message, extensions) {
3395
- super(message);
3396
- if (!this.name) {
3397
- Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
3398
- }
3399
- this.extensions = { ...extensions };
3400
- }
3401
- };
3402
- var TinaFetchError = class extends Error {
3403
- constructor(message, args) {
3404
- super(message);
3405
- this.name = "TinaFetchError";
3406
- this.collection = args.collection;
3407
- this.stack = args.stack;
3408
- this.file = args.file;
3409
- this.originalError = args.originalError;
3410
- }
3411
- };
3412
- var TinaQueryError = class extends TinaFetchError {
3413
- constructor(args) {
3414
- super(
3415
- `Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
3416
- args
3417
- );
3418
- }
3419
- };
3420
- var TinaParseDocumentError = class extends TinaFetchError {
3421
- constructor(args) {
3422
- super(
3423
- `Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
3424
- args
3425
- );
3426
- }
3427
- toString() {
3428
- return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
3429
- }
3430
- };
3431
- var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
3432
- var handleFetchErrorError = (e, verbose) => {
3433
- if (e instanceof Error) {
3434
- if (e instanceof TinaFetchError) {
3435
- if (verbose) {
3436
- console.log(e.toString());
3437
- console.log(e);
3438
- console.log(e.stack);
3439
- }
3440
- }
3441
- } else {
3442
- console.error(e);
3443
- }
3444
- throw e;
3445
- };
3446
-
3447
- // src/resolver/filter-utils.ts
3448
- var resolveReferences = async (filter, fields, resolver) => {
3449
- for (const fieldKey of Object.keys(filter)) {
3450
- const fieldDefinition = fields.find(
3451
- (f) => f.name === fieldKey
3452
- );
3453
- if (fieldDefinition) {
3454
- if (fieldDefinition.type === "reference") {
3455
- const { edges, values } = await resolver(filter, fieldDefinition);
3456
- if (edges.length === 1) {
3457
- filter[fieldKey] = {
3458
- eq: values[0]
3459
- };
3460
- } else if (edges.length > 1) {
3461
- filter[fieldKey] = {
3462
- in: values
3463
- };
3464
- } else {
3465
- filter[fieldKey] = {
3466
- eq: "___null___"
3467
- };
3468
- }
3469
- } else if (fieldDefinition.type === "object") {
3470
- if (fieldDefinition.templates) {
3471
- for (const templateName of Object.keys(filter[fieldKey])) {
3472
- const template = fieldDefinition.templates.find(
3473
- (template2) => !(typeof template2 === "string") && template2.name === templateName
3474
- );
3475
- if (template) {
3476
- await resolveReferences(
3477
- filter[fieldKey][templateName],
3478
- template.fields,
3479
- resolver
3480
- );
3481
- } else {
3482
- throw new Error(`Template ${templateName} not found`);
3483
- }
3484
- }
3485
- } else {
3486
- await resolveReferences(
3487
- filter[fieldKey],
3488
- fieldDefinition.fields,
3489
- resolver
3490
- );
3491
- }
3492
- }
3493
- } else {
3494
- throw new Error(`Unable to find field ${fieldKey}`);
3495
- }
3496
- }
3497
- };
3498
- var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
3499
- for (const childFieldName of Object.keys(filterNode)) {
3500
- const childField = fields.find((field) => field.name === childFieldName);
3501
- if (!childField) {
3502
- throw new Error(`Unable to find type for field ${childFieldName}`);
3503
- }
3504
- collectConditionsForField(
3505
- childFieldName,
3506
- childField,
3507
- filterNode[childFieldName],
3508
- pathExpression,
3509
- collectCondition
3510
- );
3511
- }
3512
- };
3513
- var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
3514
- if (field.list && field.templates) {
3515
- for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
3516
- const template = field.templates.find(
3517
- (template2) => !(typeof template2 === "string") && template2.name === filterKey
3518
- );
3519
- const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
3520
- const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
3521
- collectConditionsForChildFields(
3522
- childFilterNode,
3523
- template.fields,
3524
- filterPath,
3525
- collectCondition
3526
- );
3527
- }
3528
- } else {
3529
- const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
3530
- const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
3531
- collectConditionsForChildFields(
3532
- filterNode,
3533
- field.fields,
3534
- filterPath,
3535
- collectCondition
3536
- );
3537
- }
3538
- };
3539
- var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
3540
- if (field.type === "object") {
3541
- collectConditionsForObjectField(
3542
- fieldName,
3543
- field,
3544
- filterNode,
3545
- pathExpression,
3546
- collectCondition
3547
- );
3548
- } else {
3549
- collectCondition({
3550
- filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
3551
- filterExpression: {
3552
- _type: field.type,
3553
- _list: !!field.list,
3554
- ...filterNode
3555
- }
3556
- });
3557
- }
3558
- };
3559
-
3560
- // src/resolver/media-utils.ts
3561
- var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
3562
- if (config && value) {
3563
- if (config.useRelativeMedia === true) {
3564
- return value;
3565
- }
3566
- if (hasTinaMediaConfig(schema) === true) {
3567
- const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
3568
- if (typeof value === "string" && value.includes(assetsURL)) {
3569
- const cleanMediaRoot = cleanUpSlashes(
3570
- schema.config.media.tina.mediaRoot
3571
- );
3572
- const strippedURL = value.replace(assetsURL, "");
3573
- return `${cleanMediaRoot}${strippedURL}`;
3574
- }
3575
- if (Array.isArray(value)) {
3576
- return value.map((v) => {
3577
- if (!v || typeof v !== "string") return v;
3578
- const cleanMediaRoot = cleanUpSlashes(
3579
- schema.config.media.tina.mediaRoot
3580
- );
3581
- const strippedURL = v.replace(assetsURL, "");
3582
- return `${cleanMediaRoot}${strippedURL}`;
3583
- });
3584
- }
3585
- return value;
3586
- }
3587
- return value;
3588
- } else {
3589
- return value;
3590
- }
3591
- };
3592
- var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
3593
- if (config && value) {
3594
- if (config.useRelativeMedia === true) {
3595
- return value;
3596
- }
3597
- if (hasTinaMediaConfig(schema) === true) {
3598
- const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
3599
- if (typeof value === "string") {
3600
- const strippedValue = value.replace(cleanMediaRoot, "");
3601
- return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3602
- }
3603
- if (Array.isArray(value)) {
3604
- return value.map((v) => {
3605
- if (!v || typeof v !== "string") return v;
3606
- const strippedValue = v.replace(cleanMediaRoot, "");
3607
- return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3608
- });
3609
- }
3610
- }
3611
- return value;
3612
- } else {
3613
- return value;
3614
- }
3615
- };
3616
- var cleanUpSlashes = (path7) => {
3617
- if (path7) {
3618
- return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
3619
- }
3620
- return "";
3621
- };
3622
- var hasTinaMediaConfig = (schema) => {
3623
- var _a, _b, _c, _d, _e, _f, _g, _h;
3624
- if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3625
- if (typeof ((_e = (_d = (_c = schema.config) == null ? void 0 : _c.media) == null ? void 0 : _d.tina) == null ? void 0 : _e.publicFolder) !== "string" && typeof ((_h = (_g = (_f = schema.config) == null ? void 0 : _f.media) == null ? void 0 : _g.tina) == null ? void 0 : _h.mediaRoot) !== "string")
3626
- return false;
3627
- return true;
3628
- };
3629
-
3630
3382
  // src/resolver/index.ts
3631
3383
  var import_graphql3 = require("graphql");
3632
3384
 
@@ -3688,11 +3440,11 @@ var import_path2 = __toESM(require("path"));
3688
3440
 
3689
3441
  // src/database/util.ts
3690
3442
  var import_toml = __toESM(require("@iarna/toml"));
3691
- var import_js_yaml = __toESM(require("js-yaml"));
3692
- var import_gray_matter = __toESM(require("gray-matter"));
3693
3443
  var import_schema_tools4 = require("@tinacms/schema-tools");
3694
- var import_micromatch = __toESM(require("micromatch"));
3444
+ var import_gray_matter = __toESM(require("gray-matter"));
3445
+ var import_js_yaml = __toESM(require("js-yaml"));
3695
3446
  var import_path = __toESM(require("path"));
3447
+ var import_micromatch = __toESM(require("micromatch"));
3696
3448
 
3697
3449
  // src/database/alias-utils.ts
3698
3450
  var replaceBlockAliases = (template, item) => {
@@ -3729,22 +3481,20 @@ var replaceNameOverrides = (template, obj) => {
3729
3481
  }
3730
3482
  };
3731
3483
  function isBlockField(field) {
3732
- var _a;
3733
- return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
3484
+ return field && field.type === "object" && field.templates?.length > 0;
3734
3485
  }
3735
3486
  var _replaceNameOverrides = (fields, obj) => {
3736
3487
  const output = {};
3737
3488
  Object.keys(obj).forEach((key) => {
3738
3489
  const field = fields.find(
3739
- (fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key
3490
+ (fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
3740
3491
  );
3741
- output[(field == null ? void 0 : field.name) || key] = (field == null ? void 0 : field.type) == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
3492
+ output[field?.name || key] = field?.type == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
3742
3493
  });
3743
3494
  return output;
3744
3495
  };
3745
3496
  var getTemplateForData = (field, data) => {
3746
- var _a;
3747
- if ((_a = field.templates) == null ? void 0 : _a.length) {
3497
+ if (field.templates?.length) {
3748
3498
  const templateKey = "_template";
3749
3499
  if (data[templateKey]) {
3750
3500
  const result = field.templates.find(
@@ -3802,8 +3552,8 @@ var _applyNameOverrides = (fields, obj) => {
3802
3552
  const output = {};
3803
3553
  Object.keys(obj).forEach((key) => {
3804
3554
  const field = fields.find((field2) => field2.name === key);
3805
- const outputKey = (field == null ? void 0 : field.nameOverride) || key;
3806
- output[outputKey] = (field == null ? void 0 : field.type) === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
3555
+ const outputKey = field?.nameOverride || key;
3556
+ output[outputKey] = field?.type === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
3807
3557
  });
3808
3558
  return output;
3809
3559
  };
@@ -3816,7 +3566,6 @@ var matterEngines = {
3816
3566
  }
3817
3567
  };
3818
3568
  var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3819
- var _a, _b;
3820
3569
  const {
3821
3570
  _relativePath,
3822
3571
  _keepTemplateKey,
@@ -3840,9 +3589,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3840
3589
  ${$_body}`,
3841
3590
  strippedContent,
3842
3591
  {
3843
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3592
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3844
3593
  engines: matterEngines,
3845
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---"
3594
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
3846
3595
  }
3847
3596
  );
3848
3597
  return ok;
@@ -3858,15 +3607,14 @@ ${$_body}`,
3858
3607
  }
3859
3608
  };
3860
3609
  var parseFile = (content, format, yupSchema, markdownParseConfig) => {
3861
- var _a, _b;
3862
3610
  try {
3863
3611
  switch (format) {
3864
3612
  case ".markdown":
3865
3613
  case ".mdx":
3866
3614
  case ".md":
3867
3615
  const contentJSON = (0, import_gray_matter.default)(content || "", {
3868
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3869
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---",
3616
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3617
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
3870
3618
  engines: matterEngines
3871
3619
  });
3872
3620
  const markdownData = {
@@ -3965,7 +3713,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3965
3713
  ),
3966
3714
  template: void 0
3967
3715
  } : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
3968
- const field = template == null ? void 0 : template.fields.find((field2) => {
3716
+ const field = template?.fields.find((field2) => {
3969
3717
  if (field2.type === "string" || field2.type === "rich-text") {
3970
3718
  if (field2.isBody) {
3971
3719
  return true;
@@ -3985,7 +3733,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3985
3733
  ...data,
3986
3734
  _collection: collection.name,
3987
3735
  _keepTemplateKey: !!collection.templates,
3988
- _template: (template == null ? void 0 : template.namespace) ? lastItem(template == null ? void 0 : template.namespace) : void 0,
3736
+ _template: template?.namespace ? lastItem(template?.namespace) : void 0,
3989
3737
  _relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
3990
3738
  _id: filepath
3991
3739
  };
@@ -3994,10 +3742,10 @@ function hasOwnProperty(obj, prop) {
3994
3742
  return obj.hasOwnProperty(prop);
3995
3743
  }
3996
3744
  var getTemplateForFile = (templateInfo, data) => {
3997
- if ((templateInfo == null ? void 0 : templateInfo.type) === "object") {
3745
+ if (templateInfo?.type === "object") {
3998
3746
  return templateInfo.template;
3999
3747
  }
4000
- if ((templateInfo == null ? void 0 : templateInfo.type) === "union") {
3748
+ if (templateInfo?.type === "union") {
4001
3749
  if (hasOwnProperty(data, "_template")) {
4002
3750
  const template = templateInfo.templates.find(
4003
3751
  (t) => lastItem(t.namespace) === data._template
@@ -4021,8 +3769,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
4021
3769
  import_path.default.extname(filepath),
4022
3770
  (yup3) => yup3.object({}),
4023
3771
  {
4024
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
4025
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
3772
+ frontmatterDelimiters: collection?.frontmatterDelimiters,
3773
+ frontmatterFormat: collection?.frontmatterFormat
4026
3774
  }
4027
3775
  );
4028
3776
  const template = getTemplateForFile(templateInfo, data);
@@ -4684,12 +4432,248 @@ var stringEscaper = makeStringEscaper(
4684
4432
  encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
4685
4433
  );
4686
4434
 
4435
+ // src/resolver/error.ts
4436
+ var TinaGraphQLError = class extends Error {
4437
+ constructor(message, extensions) {
4438
+ super(message);
4439
+ if (!this.name) {
4440
+ Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
4441
+ }
4442
+ this.extensions = { ...extensions };
4443
+ }
4444
+ };
4445
+ var TinaFetchError = class extends Error {
4446
+ constructor(message, args) {
4447
+ super(message);
4448
+ this.name = "TinaFetchError";
4449
+ this.collection = args.collection;
4450
+ this.stack = args.stack;
4451
+ this.file = args.file;
4452
+ this.originalError = args.originalError;
4453
+ }
4454
+ };
4455
+ var TinaQueryError = class extends TinaFetchError {
4456
+ constructor(args) {
4457
+ super(
4458
+ `Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
4459
+ args
4460
+ );
4461
+ }
4462
+ };
4463
+ var TinaParseDocumentError = class extends TinaFetchError {
4464
+ constructor(args) {
4465
+ super(
4466
+ `Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
4467
+ args
4468
+ );
4469
+ }
4470
+ toString() {
4471
+ return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
4472
+ }
4473
+ };
4474
+ var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
4475
+ var handleFetchErrorError = (e, verbose) => {
4476
+ if (e instanceof Error) {
4477
+ if (e instanceof TinaFetchError) {
4478
+ if (verbose) {
4479
+ console.log(e.toString());
4480
+ console.log(e);
4481
+ console.log(e.stack);
4482
+ }
4483
+ }
4484
+ } else {
4485
+ console.error(e);
4486
+ }
4487
+ throw e;
4488
+ };
4489
+
4490
+ // src/resolver/filter-utils.ts
4491
+ var resolveReferences = async (filter, fields, resolver) => {
4492
+ for (const fieldKey of Object.keys(filter)) {
4493
+ const fieldDefinition = fields.find(
4494
+ (f) => f.name === fieldKey
4495
+ );
4496
+ if (fieldDefinition) {
4497
+ if (fieldDefinition.type === "reference") {
4498
+ const { edges, values } = await resolver(filter, fieldDefinition);
4499
+ if (edges.length === 1) {
4500
+ filter[fieldKey] = {
4501
+ eq: values[0]
4502
+ };
4503
+ } else if (edges.length > 1) {
4504
+ filter[fieldKey] = {
4505
+ in: values
4506
+ };
4507
+ } else {
4508
+ filter[fieldKey] = {
4509
+ eq: "___null___"
4510
+ };
4511
+ }
4512
+ } else if (fieldDefinition.type === "object") {
4513
+ if (fieldDefinition.templates) {
4514
+ for (const templateName of Object.keys(filter[fieldKey])) {
4515
+ const template = fieldDefinition.templates.find(
4516
+ (template2) => !(typeof template2 === "string") && template2.name === templateName
4517
+ );
4518
+ if (template) {
4519
+ await resolveReferences(
4520
+ filter[fieldKey][templateName],
4521
+ template.fields,
4522
+ resolver
4523
+ );
4524
+ } else {
4525
+ throw new Error(`Template ${templateName} not found`);
4526
+ }
4527
+ }
4528
+ } else {
4529
+ await resolveReferences(
4530
+ filter[fieldKey],
4531
+ fieldDefinition.fields,
4532
+ resolver
4533
+ );
4534
+ }
4535
+ }
4536
+ } else {
4537
+ throw new Error(`Unable to find field ${fieldKey}`);
4538
+ }
4539
+ }
4540
+ };
4541
+ var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
4542
+ for (const childFieldName of Object.keys(filterNode)) {
4543
+ const childField = fields.find((field) => field.name === childFieldName);
4544
+ if (!childField) {
4545
+ throw new Error(`Unable to find type for field ${childFieldName}`);
4546
+ }
4547
+ collectConditionsForField(
4548
+ childFieldName,
4549
+ childField,
4550
+ filterNode[childFieldName],
4551
+ pathExpression,
4552
+ collectCondition
4553
+ );
4554
+ }
4555
+ };
4556
+ var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
4557
+ if (field.list && field.templates) {
4558
+ for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
4559
+ const template = field.templates.find(
4560
+ (template2) => !(typeof template2 === "string") && template2.name === filterKey
4561
+ );
4562
+ const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
4563
+ const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
4564
+ collectConditionsForChildFields(
4565
+ childFilterNode,
4566
+ template.fields,
4567
+ filterPath,
4568
+ collectCondition
4569
+ );
4570
+ }
4571
+ } else {
4572
+ const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
4573
+ const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
4574
+ collectConditionsForChildFields(
4575
+ filterNode,
4576
+ field.fields,
4577
+ filterPath,
4578
+ collectCondition
4579
+ );
4580
+ }
4581
+ };
4582
+ var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
4583
+ if (field.type === "object") {
4584
+ collectConditionsForObjectField(
4585
+ fieldName,
4586
+ field,
4587
+ filterNode,
4588
+ pathExpression,
4589
+ collectCondition
4590
+ );
4591
+ } else {
4592
+ collectCondition({
4593
+ filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
4594
+ filterExpression: {
4595
+ _type: field.type,
4596
+ _list: !!field.list,
4597
+ ...filterNode
4598
+ }
4599
+ });
4600
+ }
4601
+ };
4602
+
4603
+ // src/resolver/media-utils.ts
4604
+ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
4605
+ if (config && value) {
4606
+ if (config.useRelativeMedia === true) {
4607
+ return value;
4608
+ }
4609
+ if (hasTinaMediaConfig(schema) === true) {
4610
+ const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
4611
+ if (typeof value === "string" && value.includes(assetsURL)) {
4612
+ const cleanMediaRoot = cleanUpSlashes(
4613
+ schema.config.media.tina.mediaRoot
4614
+ );
4615
+ const strippedURL = value.replace(assetsURL, "");
4616
+ return `${cleanMediaRoot}${strippedURL}`;
4617
+ }
4618
+ if (Array.isArray(value)) {
4619
+ return value.map((v) => {
4620
+ if (!v || typeof v !== "string") return v;
4621
+ const cleanMediaRoot = cleanUpSlashes(
4622
+ schema.config.media.tina.mediaRoot
4623
+ );
4624
+ const strippedURL = v.replace(assetsURL, "");
4625
+ return `${cleanMediaRoot}${strippedURL}`;
4626
+ });
4627
+ }
4628
+ return value;
4629
+ }
4630
+ return value;
4631
+ } else {
4632
+ return value;
4633
+ }
4634
+ };
4635
+ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
4636
+ if (config && value) {
4637
+ if (config.useRelativeMedia === true) {
4638
+ return value;
4639
+ }
4640
+ if (hasTinaMediaConfig(schema) === true) {
4641
+ const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
4642
+ if (typeof value === "string") {
4643
+ const strippedValue = value.replace(cleanMediaRoot, "");
4644
+ return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
4645
+ }
4646
+ if (Array.isArray(value)) {
4647
+ return value.map((v) => {
4648
+ if (!v || typeof v !== "string") return v;
4649
+ const strippedValue = v.replace(cleanMediaRoot, "");
4650
+ return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
4651
+ });
4652
+ }
4653
+ }
4654
+ return value;
4655
+ } else {
4656
+ return value;
4657
+ }
4658
+ };
4659
+ var cleanUpSlashes = (path7) => {
4660
+ if (path7) {
4661
+ return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
4662
+ }
4663
+ return "";
4664
+ };
4665
+ var hasTinaMediaConfig = (schema) => {
4666
+ if (!schema.config?.media?.tina) return false;
4667
+ if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
4668
+ return false;
4669
+ return true;
4670
+ };
4671
+
4687
4672
  // src/resolver/index.ts
4688
4673
  var createResolver = (args) => {
4689
4674
  return new Resolver(args);
4690
4675
  };
4691
4676
  var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4692
- var _a, _b;
4693
4677
  if (!rawData) {
4694
4678
  return void 0;
4695
4679
  }
@@ -4717,7 +4701,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4717
4701
  accumulator[field.name] = {
4718
4702
  value: void 0,
4719
4703
  // never resolve the password hash
4720
- passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4704
+ passwordChangeRequired: value["passwordChangeRequired"] ?? false
4721
4705
  };
4722
4706
  break;
4723
4707
  case "image":
@@ -4733,11 +4717,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4733
4717
  field,
4734
4718
  (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4735
4719
  );
4736
- if (((_b = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _b.type) === "invalid_markdown") {
4720
+ if (tree?.children[0]?.type === "invalid_markdown") {
4737
4721
  if (isAudit) {
4738
- const invalidNode = tree == null ? void 0 : tree.children[0];
4722
+ const invalidNode = tree?.children[0];
4739
4723
  throw new import_graphql3.GraphQLError(
4740
- `${invalidNode == null ? void 0 : invalidNode.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4724
+ `${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4741
4725
  );
4742
4726
  }
4743
4727
  }
@@ -4850,11 +4834,11 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4850
4834
  });
4851
4835
  }
4852
4836
  const titleField = template.fields.find((x) => {
4853
- if (x.type === "string" && (x == null ? void 0 : x.isTitle)) {
4837
+ if (x.type === "string" && x?.isTitle) {
4854
4838
  return true;
4855
4839
  }
4856
4840
  });
4857
- const titleFieldName = titleField == null ? void 0 : titleField.name;
4841
+ const titleFieldName = titleField?.name;
4858
4842
  const title = data[titleFieldName || " "] || null;
4859
4843
  return {
4860
4844
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
@@ -4964,7 +4948,7 @@ var Resolver = class {
4964
4948
  );
4965
4949
  }
4966
4950
  const rawData = await this.getRaw(fullPath);
4967
- const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
4951
+ const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
4968
4952
  return transformDocumentIntoPayload(
4969
4953
  fullPath,
4970
4954
  rawData,
@@ -5004,9 +4988,9 @@ var Resolver = class {
5004
4988
  return this.buildFieldMutations(
5005
4989
  item,
5006
4990
  objectTemplate,
5007
- idField && existingData && (existingData == null ? void 0 : existingData.find(
4991
+ idField && existingData && existingData?.find(
5008
4992
  (d) => d[idField.name] === item[idField.name]
5009
- ))
4993
+ )
5010
4994
  );
5011
4995
  }
5012
4996
  )
@@ -5132,7 +5116,7 @@ var Resolver = class {
5132
5116
  isCollectionSpecific
5133
5117
  }) => {
5134
5118
  const doc = await this.getDocument(realPath);
5135
- const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
5119
+ const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
5136
5120
  if (isAddPendingDocument === true) {
5137
5121
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
5138
5122
  const params2 = this.buildParams(args);
@@ -5142,7 +5126,7 @@ var Resolver = class {
5142
5126
  const values = await this.buildFieldMutations(
5143
5127
  params2,
5144
5128
  templateInfo.template,
5145
- doc == null ? void 0 : doc._rawData
5129
+ doc?._rawData
5146
5130
  );
5147
5131
  await this.database.put(
5148
5132
  realPath,
@@ -5166,7 +5150,7 @@ var Resolver = class {
5166
5150
  // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
5167
5151
  templateParams,
5168
5152
  template,
5169
- doc == null ? void 0 : doc._rawData
5153
+ doc?._rawData
5170
5154
  ),
5171
5155
  _template: lastItem(template.namespace)
5172
5156
  };
@@ -5180,7 +5164,7 @@ var Resolver = class {
5180
5164
  //@ts-ignore
5181
5165
  isCollectionSpecific ? args.params : args.params[collection.name],
5182
5166
  collection,
5183
- doc == null ? void 0 : doc._rawData
5167
+ doc?._rawData
5184
5168
  );
5185
5169
  await this.database.put(
5186
5170
  realPath,
@@ -5196,7 +5180,6 @@ var Resolver = class {
5196
5180
  this.resolveLegacyValues = (oldDoc, collection) => {
5197
5181
  const legacyValues = {};
5198
5182
  Object.entries(oldDoc).forEach(([key, value]) => {
5199
- var _a;
5200
5183
  const reservedKeys = [
5201
5184
  "$_body",
5202
5185
  "_collection",
@@ -5209,7 +5192,7 @@ var Resolver = class {
5209
5192
  return;
5210
5193
  }
5211
5194
  if (oldDoc._template && collection.templates) {
5212
- const template = (_a = collection.templates) == null ? void 0 : _a.find(
5195
+ const template = collection.templates?.find(
5213
5196
  ({ name }) => name === oldDoc._template
5214
5197
  );
5215
5198
  if (template) {
@@ -5256,7 +5239,7 @@ var Resolver = class {
5256
5239
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5257
5240
  );
5258
5241
  const collection = await this.tinaSchema.getCollection(collectionLookup);
5259
- let realPath = import_path3.default.join(collection == null ? void 0 : collection.path, args.relativePath);
5242
+ let realPath = import_path3.default.join(collection?.path, args.relativePath);
5260
5243
  if (isFolderCreation) {
5261
5244
  realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
5262
5245
  }
@@ -5340,12 +5323,12 @@ var Resolver = class {
5340
5323
  (yup3) => yup3.object({ params: yup3.object().required() })
5341
5324
  );
5342
5325
  assertShape(
5343
- args == null ? void 0 : args.params,
5326
+ args?.params,
5344
5327
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5345
5328
  );
5346
5329
  const doc = await this.getDocument(realPath);
5347
5330
  const newRealPath = import_path3.default.join(
5348
- collection == null ? void 0 : collection.path,
5331
+ collection?.path,
5349
5332
  args.params.relativePath
5350
5333
  );
5351
5334
  if (newRealPath === realPath) {
@@ -5575,7 +5558,7 @@ var Resolver = class {
5575
5558
  if (!references[c.name][refId]) {
5576
5559
  references[c.name][refId] = [];
5577
5560
  }
5578
- const referencePath = rawItem == null ? void 0 : rawItem[REFS_PATH_FIELD];
5561
+ const referencePath = rawItem?.[REFS_PATH_FIELD];
5579
5562
  if (referencePath) {
5580
5563
  references[c.name][refId].push(referencePath);
5581
5564
  }
@@ -5585,7 +5568,6 @@ var Resolver = class {
5585
5568
  return references;
5586
5569
  };
5587
5570
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
5588
- var _a;
5589
5571
  const accum = {};
5590
5572
  for (const passwordField of template.fields.filter(
5591
5573
  (f) => f.type === "password"
@@ -5628,7 +5610,7 @@ var Resolver = class {
5628
5610
  accum[fieldName] = await this.buildObjectMutations(
5629
5611
  fieldValue,
5630
5612
  field,
5631
- existingData == null ? void 0 : existingData[fieldName]
5613
+ existingData?.[fieldName]
5632
5614
  );
5633
5615
  break;
5634
5616
  case "password":
@@ -5647,12 +5629,12 @@ var Resolver = class {
5647
5629
  } else {
5648
5630
  accum[fieldName] = {
5649
5631
  ...fieldValue,
5650
- value: (_a = existingData == null ? void 0 : existingData[fieldName]) == null ? void 0 : _a["value"]
5632
+ value: existingData?.[fieldName]?.["value"]
5651
5633
  };
5652
5634
  }
5653
5635
  break;
5654
5636
  case "rich-text":
5655
- accum[fieldName] = (0, import_mdx.stringifyMDX)(
5637
+ accum[fieldName] = (0, import_mdx.serializeMDX)(
5656
5638
  fieldValue,
5657
5639
  field,
5658
5640
  (fieldValue2) => resolveMediaCloudToRelative(
@@ -5782,9 +5764,8 @@ var resolve = async ({
5782
5764
  isAudit,
5783
5765
  ctxUser
5784
5766
  }) => {
5785
- var _a;
5786
5767
  try {
5787
- const verboseValue = verbose != null ? verbose : true;
5768
+ const verboseValue = verbose ?? true;
5788
5769
  const graphQLSchemaAst = await database.getGraphQLSchema();
5789
5770
  if (!graphQLSchemaAst) {
5790
5771
  throw new import_graphql5.GraphQLError("GraphQL schema not found");
@@ -5796,7 +5777,7 @@ var resolve = async ({
5796
5777
  // @ts-ignore
5797
5778
  schema: tinaConfig,
5798
5779
  // @ts-ignore
5799
- flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5780
+ flags: tinaConfig?.meta?.flags
5800
5781
  });
5801
5782
  const resolver = createResolver({
5802
5783
  config,
@@ -5821,7 +5802,6 @@ var resolve = async ({
5821
5802
  throw new Error(`Unable to find lookup key for ${namedType}`);
5822
5803
  },
5823
5804
  fieldResolver: async (source = {}, _args = {}, _context, info) => {
5824
- var _a2, _b, _c, _d;
5825
5805
  try {
5826
5806
  const args = JSON.parse(JSON.stringify(_args));
5827
5807
  const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
@@ -5838,8 +5818,7 @@ var resolve = async ({
5838
5818
  );
5839
5819
  const hasDocuments2 = collectionNode2.selectionSet.selections.find(
5840
5820
  (x) => {
5841
- var _a3;
5842
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5821
+ return x?.name?.value === "documents";
5843
5822
  }
5844
5823
  );
5845
5824
  return tinaSchema.getCollections().map((collection) => {
@@ -5855,8 +5834,7 @@ var resolve = async ({
5855
5834
  );
5856
5835
  const hasDocuments = collectionNode.selectionSet.selections.find(
5857
5836
  (x) => {
5858
- var _a3;
5859
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5837
+ return x?.name?.value === "documents";
5860
5838
  }
5861
5839
  );
5862
5840
  return resolver.resolveCollection(
@@ -5875,7 +5853,7 @@ var resolve = async ({
5875
5853
  }
5876
5854
  }
5877
5855
  if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
5878
- const sub = args.sub || (ctxUser == null ? void 0 : ctxUser.sub);
5856
+ const sub = args.sub || ctxUser?.sub;
5879
5857
  const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5880
5858
  if (!collection) {
5881
5859
  throw new Error("Auth collection not found");
@@ -5923,7 +5901,7 @@ var resolve = async ({
5923
5901
  return user;
5924
5902
  }
5925
5903
  if (info.fieldName === "updatePassword") {
5926
- if (!(ctxUser == null ? void 0 : ctxUser.sub)) {
5904
+ if (!ctxUser?.sub) {
5927
5905
  throw new Error("Not authorized");
5928
5906
  }
5929
5907
  if (!args.password) {
@@ -6006,7 +5984,7 @@ var resolve = async ({
6006
5984
  if (typeof value === "string" && value !== "") {
6007
5985
  return resolver.getDocument(value);
6008
5986
  }
6009
- if ((args == null ? void 0 : args.collection) && info.fieldName === "addPendingDocument") {
5987
+ if (args?.collection && info.fieldName === "addPendingDocument") {
6010
5988
  return resolver.resolveDocument({
6011
5989
  args: { ...args, params: {} },
6012
5990
  collection: args.collection,
@@ -6030,7 +6008,7 @@ var resolve = async ({
6030
6008
  // Right now this is the only case for deletion
6031
6009
  isDeletion: info.fieldName === "deleteDocument",
6032
6010
  isFolderCreation: info.fieldName === "createFolder",
6033
- isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
6011
+ isUpdateName: Boolean(args?.params?.relativePath),
6034
6012
  isAddPendingDocument: false,
6035
6013
  isCollectionSpecific: false
6036
6014
  });
@@ -6049,16 +6027,16 @@ var resolve = async ({
6049
6027
  })
6050
6028
  };
6051
6029
  }
6052
- if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
6030
+ if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
6053
6031
  let filter = args.filter;
6054
6032
  if (
6055
6033
  // 1. Make sure that the filter exists
6056
- typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
6034
+ typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
6057
6035
  // @ts-ignore
6058
- 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
6036
+ typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
6059
6037
  // @ts-ignore
6060
- Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
6061
- typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
6038
+ Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
6039
+ typeof args.filter[value?.collection?.name] !== "undefined"
6062
6040
  ) {
6063
6041
  filter = args.filter[value.collection.name];
6064
6042
  }
@@ -6195,15 +6173,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
6195
6173
  };
6196
6174
 
6197
6175
  // src/database/index.ts
6198
- var import_node_path = __toESM(require("path"));
6176
+ var import_node_path = __toESM(require("node:path"));
6199
6177
  var import_graphql6 = require("graphql");
6200
6178
  var import_micromatch2 = __toESM(require("micromatch"));
6201
6179
  var import_js_sha12 = __toESM(require("js-sha1"));
6202
6180
  var import_lodash5 = __toESM(require("lodash.set"));
6203
6181
  var createLocalDatabase = (config) => {
6204
- const level = new TinaLevelClient(config == null ? void 0 : config.port);
6182
+ const level = new TinaLevelClient(config?.port);
6205
6183
  level.openConnection();
6206
- const fsBridge = new FilesystemBridge((config == null ? void 0 : config.rootPath) || process.cwd());
6184
+ const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
6207
6185
  return new Database({
6208
6186
  bridge: fsBridge,
6209
6187
  ...config || {},
@@ -6276,7 +6254,7 @@ var Database = class {
6276
6254
  );
6277
6255
  }
6278
6256
  const metadata = await metadataLevel.get(`metadata_${key}`);
6279
- return metadata == null ? void 0 : metadata.value;
6257
+ return metadata?.value;
6280
6258
  };
6281
6259
  this.setMetadata = async (key, value) => {
6282
6260
  await this.initLevel();
@@ -6298,7 +6276,7 @@ var Database = class {
6298
6276
  let level = this.contentLevel;
6299
6277
  if (this.appLevel) {
6300
6278
  collection = await this.collectionForPath(filepath);
6301
- if (collection == null ? void 0 : collection.isDetached) {
6279
+ if (collection?.isDetached) {
6302
6280
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6303
6281
  }
6304
6282
  }
@@ -6317,7 +6295,6 @@ var Database = class {
6317
6295
  }
6318
6296
  };
6319
6297
  this.addPendingDocument = async (filepath, data) => {
6320
- var _a;
6321
6298
  await this.initLevel();
6322
6299
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6323
6300
  const collection = await this.collectionForPath(filepath);
@@ -6330,10 +6307,10 @@ var Database = class {
6330
6307
  collection
6331
6308
  );
6332
6309
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6333
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
6334
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
6310
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
6311
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
6335
6312
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6336
- if (!(collection == null ? void 0 : collection.isDetached)) {
6313
+ if (!collection?.isDetached) {
6337
6314
  if (this.bridge) {
6338
6315
  await this.bridge.put(normalizedPath, stringifiedFile);
6339
6316
  }
@@ -6351,7 +6328,7 @@ var Database = class {
6351
6328
  }
6352
6329
  }
6353
6330
  let level = this.contentLevel;
6354
- if (collection == null ? void 0 : collection.isDetached) {
6331
+ if (collection?.isDetached) {
6355
6332
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6356
6333
  }
6357
6334
  const folderTreeBuilder = new FolderTreeBuilder();
@@ -6362,7 +6339,7 @@ var Database = class {
6362
6339
  putOps = [
6363
6340
  ...makeRefOpsForDocument(
6364
6341
  normalizedPath,
6365
- collection == null ? void 0 : collection.name,
6342
+ collection?.name,
6366
6343
  collectionReferences,
6367
6344
  dataFields,
6368
6345
  "put",
@@ -6370,7 +6347,7 @@ var Database = class {
6370
6347
  ),
6371
6348
  ...makeIndexOpsForDocument(
6372
6349
  normalizedPath,
6373
- collection == null ? void 0 : collection.name,
6350
+ collection?.name,
6374
6351
  collectionIndexDefinitions,
6375
6352
  dataFields,
6376
6353
  "put",
@@ -6379,7 +6356,7 @@ var Database = class {
6379
6356
  // folder indices
6380
6357
  ...makeIndexOpsForDocument(
6381
6358
  normalizedPath,
6382
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6359
+ `${collection?.name}_${folderKey}`,
6383
6360
  collectionIndexDefinitions,
6384
6361
  dataFields,
6385
6362
  "put",
@@ -6393,7 +6370,7 @@ var Database = class {
6393
6370
  delOps = existingItem ? [
6394
6371
  ...makeRefOpsForDocument(
6395
6372
  normalizedPath,
6396
- collection == null ? void 0 : collection.name,
6373
+ collection?.name,
6397
6374
  collectionReferences,
6398
6375
  existingItem,
6399
6376
  "del",
@@ -6401,7 +6378,7 @@ var Database = class {
6401
6378
  ),
6402
6379
  ...makeIndexOpsForDocument(
6403
6380
  normalizedPath,
6404
- collection == null ? void 0 : collection.name,
6381
+ collection?.name,
6405
6382
  collectionIndexDefinitions,
6406
6383
  existingItem,
6407
6384
  "del",
@@ -6410,7 +6387,7 @@ var Database = class {
6410
6387
  // folder indices
6411
6388
  ...makeIndexOpsForDocument(
6412
6389
  normalizedPath,
6413
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6390
+ `${collection?.name}_${folderKey}`,
6414
6391
  collectionIndexDefinitions,
6415
6392
  existingItem,
6416
6393
  "del",
@@ -6434,7 +6411,6 @@ var Database = class {
6434
6411
  await level.batch(ops);
6435
6412
  };
6436
6413
  this.put = async (filepath, data, collectionName) => {
6437
- var _a, _b, _c;
6438
6414
  await this.initLevel();
6439
6415
  try {
6440
6416
  if (SYSTEM_FILES.includes(filepath)) {
@@ -6445,16 +6421,16 @@ var Database = class {
6445
6421
  const indexDefinitions = await this.getIndexDefinitions(
6446
6422
  this.contentLevel
6447
6423
  );
6448
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
6424
+ collectionIndexDefinitions = indexDefinitions?.[collectionName];
6449
6425
  }
6450
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collectionName];
6426
+ const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
6451
6427
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6452
6428
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6453
6429
  const collection = await this.collectionForPath(filepath);
6454
6430
  if (!collection) {
6455
6431
  throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
6456
6432
  }
6457
- if (((_b = collection.match) == null ? void 0 : _b.exclude) || ((_c = collection.match) == null ? void 0 : _c.include)) {
6433
+ if (collection.match?.exclude || collection.match?.include) {
6458
6434
  const matches = this.tinaSchema.getMatches({ collection });
6459
6435
  const match = import_micromatch2.default.isMatch(filepath, matches);
6460
6436
  if (!match) {
@@ -6468,7 +6444,7 @@ var Database = class {
6468
6444
  const stringifiedFile = filepath.endsWith(
6469
6445
  `.gitkeep.${collection.format || "md"}`
6470
6446
  ) ? "" : await this.stringifyFile(filepath, dataFields, collection);
6471
- if (!(collection == null ? void 0 : collection.isDetached)) {
6447
+ if (!collection?.isDetached) {
6472
6448
  if (this.bridge) {
6473
6449
  await this.bridge.put(normalizedPath, stringifiedFile);
6474
6450
  }
@@ -6490,7 +6466,7 @@ var Database = class {
6490
6466
  filepath,
6491
6467
  collection.path || ""
6492
6468
  );
6493
- const level = (collection == null ? void 0 : collection.isDetached) ? this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6469
+ const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6494
6470
  let putOps = [];
6495
6471
  let delOps = [];
6496
6472
  if (!isGitKeep(normalizedPath, collection)) {
@@ -6514,7 +6490,7 @@ var Database = class {
6514
6490
  // folder indices
6515
6491
  ...makeIndexOpsForDocument(
6516
6492
  normalizedPath,
6517
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6493
+ `${collection?.name}_${folderKey}`,
6518
6494
  collectionIndexDefinitions,
6519
6495
  dataFields,
6520
6496
  "put",
@@ -6545,7 +6521,7 @@ var Database = class {
6545
6521
  // folder indices
6546
6522
  ...makeIndexOpsForDocument(
6547
6523
  normalizedPath,
6548
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6524
+ `${collection?.name}_${folderKey}`,
6549
6525
  collectionIndexDefinitions,
6550
6526
  existingItem,
6551
6527
  "del",
@@ -6622,8 +6598,8 @@ var Database = class {
6622
6598
  writeTemplateKey,
6623
6599
  //templateInfo.type === 'union',
6624
6600
  {
6625
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6626
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
6601
+ frontmatterFormat: collection?.frontmatterFormat,
6602
+ frontmatterDelimiters: collection?.frontmatterDelimiters
6627
6603
  }
6628
6604
  );
6629
6605
  };
@@ -6792,8 +6768,8 @@ var Database = class {
6792
6768
  );
6793
6769
  return {
6794
6770
  name: indexField.name,
6795
- type: field == null ? void 0 : field.type,
6796
- list: !!(field == null ? void 0 : field.list)
6771
+ type: field?.type,
6772
+ list: !!field?.list
6797
6773
  };
6798
6774
  })
6799
6775
  };
@@ -6819,7 +6795,6 @@ var Database = class {
6819
6795
  return true;
6820
6796
  };
6821
6797
  this.query = async (queryOptions, hydrator) => {
6822
- var _a;
6823
6798
  await this.initLevel();
6824
6799
  const {
6825
6800
  first,
@@ -6847,14 +6822,14 @@ var Database = class {
6847
6822
  const allIndexDefinitions = await this.getIndexDefinitions(
6848
6823
  this.contentLevel
6849
6824
  );
6850
- const indexDefinitions = allIndexDefinitions == null ? void 0 : allIndexDefinitions[collection.name];
6825
+ const indexDefinitions = allIndexDefinitions?.[collection.name];
6851
6826
  if (!indexDefinitions) {
6852
6827
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
6853
6828
  }
6854
6829
  const filterChain = coerceFilterChainOperands(rawFilterChain);
6855
- const indexDefinition = sort && (indexDefinitions == null ? void 0 : indexDefinitions[sort]);
6830
+ const indexDefinition = sort && indexDefinitions?.[sort];
6856
6831
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
6857
- const level = (collection == null ? void 0 : collection.isDetached) ? this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6832
+ const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6858
6833
  const rootLevel = level.sublevel(
6859
6834
  CONTENT_ROOT_PREFIX,
6860
6835
  SUBLEVEL_OPTIONS
@@ -6864,17 +6839,17 @@ var Database = class {
6864
6839
  SUBLEVEL_OPTIONS
6865
6840
  ).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
6866
6841
  if (!query.gt && !query.gte) {
6867
- query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
6842
+ query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
6868
6843
  }
6869
6844
  if (!query.lt && !query.lte) {
6870
- query.lte = (filterSuffixes == null ? void 0 : filterSuffixes.right) ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6845
+ query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6871
6846
  }
6872
6847
  let edges = [];
6873
6848
  let startKey = "";
6874
6849
  let endKey = "";
6875
6850
  let hasPreviousPage = false;
6876
6851
  let hasNextPage = false;
6877
- 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("")}` : "";
6852
+ const fieldsPattern = indexDefinition?.fields?.length ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
6878
6853
  const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
6879
6854
  const itemFilter = makeFilter({ filterChain });
6880
6855
  const iterator = sublevel.iterator(query);
@@ -7086,18 +7061,17 @@ var Database = class {
7086
7061
  }
7087
7062
  };
7088
7063
  this.delete = async (filepath) => {
7089
- var _a;
7090
7064
  await this.initLevel();
7091
7065
  const collection = await this.collectionForPath(filepath);
7092
7066
  if (!collection) {
7093
7067
  throw new Error(`No collection found for path: ${filepath}`);
7094
7068
  }
7095
7069
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
7096
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
7097
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7070
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
7071
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
7098
7072
  let level = this.contentLevel;
7099
- if (collection == null ? void 0 : collection.isDetached) {
7100
- level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
7073
+ if (collection?.isDetached) {
7074
+ level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
7101
7075
  }
7102
7076
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
7103
7077
  const rootSublevel = level.sublevel(
@@ -7144,7 +7118,7 @@ var Database = class {
7144
7118
  }
7145
7119
  ]);
7146
7120
  }
7147
- if (!(collection == null ? void 0 : collection.isDetached)) {
7121
+ if (!collection?.isDetached) {
7148
7122
  if (this.bridge) {
7149
7123
  await this.bridge.delete(normalizedPath);
7150
7124
  }
@@ -7239,7 +7213,7 @@ var Database = class {
7239
7213
  );
7240
7214
  }
7241
7215
  const metadata = await metadataLevel.get("metadata");
7242
- return metadata == null ? void 0 : metadata.version;
7216
+ return metadata?.version;
7243
7217
  }
7244
7218
  async initLevel() {
7245
7219
  if (this.contentLevel) {
@@ -7325,7 +7299,7 @@ var hashPasswordVisitor = async (node, path7) => {
7325
7299
  };
7326
7300
  var visitNodes = async (node, path7, callback) => {
7327
7301
  const [currentLevel, ...remainingLevels] = path7;
7328
- if (!(remainingLevels == null ? void 0 : remainingLevels.length)) {
7302
+ if (!remainingLevels?.length) {
7329
7303
  return callback(node, path7);
7330
7304
  }
7331
7305
  if (Array.isArray(node[currentLevel])) {
@@ -7341,7 +7315,7 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
7341
7315
  async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
7342
7316
  )
7343
7317
  );
7344
- var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${(collection == null ? void 0 : collection.format) || "md"}`);
7318
+ var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
7345
7319
  var _indexContent = async ({
7346
7320
  database,
7347
7321
  level,
@@ -7351,18 +7325,17 @@ var _indexContent = async ({
7351
7325
  passwordFields,
7352
7326
  isPartialReindex
7353
7327
  }) => {
7354
- var _a;
7355
7328
  let collectionIndexDefinitions;
7356
7329
  let collectionPath;
7357
7330
  if (collection) {
7358
7331
  const indexDefinitions = await database.getIndexDefinitions(level);
7359
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7332
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7360
7333
  if (!collectionIndexDefinitions) {
7361
7334
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7362
7335
  }
7363
7336
  collectionPath = collection.path;
7364
7337
  }
7365
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7338
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7366
7339
  const tinaSchema = await database.getSchema();
7367
7340
  let templateInfo = null;
7368
7341
  if (collection) {
@@ -7380,7 +7353,7 @@ var _indexContent = async ({
7380
7353
  if (!aliasedData) {
7381
7354
  return;
7382
7355
  }
7383
- if (passwordFields == null ? void 0 : passwordFields.length) {
7356
+ if (passwordFields?.length) {
7384
7357
  await hashPasswordValues(aliasedData, passwordFields);
7385
7358
  }
7386
7359
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
@@ -7398,7 +7371,7 @@ var _indexContent = async ({
7398
7371
  await database.contentLevel.batch([
7399
7372
  ...makeRefOpsForDocument(
7400
7373
  normalizedPath,
7401
- collection == null ? void 0 : collection.name,
7374
+ collection?.name,
7402
7375
  collectionReferences,
7403
7376
  item,
7404
7377
  "del",
@@ -7433,7 +7406,7 @@ var _indexContent = async ({
7433
7406
  await enqueueOps([
7434
7407
  ...makeRefOpsForDocument(
7435
7408
  normalizedPath,
7436
- collection == null ? void 0 : collection.name,
7409
+ collection?.name,
7437
7410
  collectionReferences,
7438
7411
  aliasedData,
7439
7412
  "put",
@@ -7441,7 +7414,7 @@ var _indexContent = async ({
7441
7414
  ),
7442
7415
  ...makeIndexOpsForDocument(
7443
7416
  normalizedPath,
7444
- collection == null ? void 0 : collection.name,
7417
+ collection?.name,
7445
7418
  collectionIndexDefinitions,
7446
7419
  aliasedData,
7447
7420
  "put",
@@ -7450,7 +7423,7 @@ var _indexContent = async ({
7450
7423
  // folder indexes
7451
7424
  ...makeIndexOpsForDocument(
7452
7425
  normalizedPath,
7453
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7426
+ `${collection?.name}_${folderKey}`,
7454
7427
  collectionIndexDefinitions,
7455
7428
  aliasedData,
7456
7429
  "put",
@@ -7471,7 +7444,7 @@ var _indexContent = async ({
7471
7444
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7472
7445
  originalError: error,
7473
7446
  file: filepath,
7474
- collection: collection == null ? void 0 : collection.name,
7447
+ collection: collection?.name,
7475
7448
  stack: error.stack
7476
7449
  });
7477
7450
  }
@@ -7489,7 +7462,6 @@ var _indexContent = async ({
7489
7462
  }
7490
7463
  };
7491
7464
  var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
7492
- var _a;
7493
7465
  if (!documentPaths.length) {
7494
7466
  return;
7495
7467
  }
@@ -7498,12 +7470,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7498
7470
  const indexDefinitions = await database.getIndexDefinitions(
7499
7471
  database.contentLevel
7500
7472
  );
7501
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7473
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7502
7474
  if (!collectionIndexDefinitions) {
7503
7475
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7504
7476
  }
7505
7477
  }
7506
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7478
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7507
7479
  const tinaSchema = await database.getSchema();
7508
7480
  let templateInfo = null;
7509
7481
  if (collection) {
@@ -7520,7 +7492,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7520
7492
  if (item) {
7521
7493
  const folderKey = folderTreeBuilder.update(
7522
7494
  itemKey,
7523
- (collection == null ? void 0 : collection.path) || ""
7495
+ collection?.path || ""
7524
7496
  );
7525
7497
  const aliasedData = templateInfo ? replaceNameOverrides(
7526
7498
  getTemplateForFile(templateInfo, item),
@@ -7529,7 +7501,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7529
7501
  await enqueueOps([
7530
7502
  ...makeRefOpsForDocument(
7531
7503
  itemKey,
7532
- collection == null ? void 0 : collection.name,
7504
+ collection?.name,
7533
7505
  collectionReferences,
7534
7506
  aliasedData,
7535
7507
  "del",
@@ -7546,7 +7518,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7546
7518
  // folder indexes
7547
7519
  ...makeIndexOpsForDocument(
7548
7520
  itemKey,
7549
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7521
+ `${collection?.name}_${folderKey}`,
7550
7522
  collectionIndexDefinitions,
7551
7523
  aliasedData,
7552
7524
  "del",
@@ -7631,12 +7603,12 @@ var getChangedFiles = async ({
7631
7603
  }
7632
7604
  }
7633
7605
  }
7634
- if (await (B == null ? void 0 : B.type()) === "tree") {
7606
+ if (await B?.type() === "tree") {
7635
7607
  return;
7636
7608
  }
7637
7609
  if (matches) {
7638
- const oidA = await (A == null ? void 0 : A.oid());
7639
- const oidB = await (B == null ? void 0 : B.oid());
7610
+ const oidA = await A?.oid();
7611
+ const oidB = await B?.oid();
7640
7612
  if (oidA !== oidB) {
7641
7613
  if (oidA === void 0) {
7642
7614
  results.added.push(relativePath);
@@ -7664,8 +7636,8 @@ var import_path5 = __toESM(require("path"));
7664
7636
  var import_normalize_path = __toESM(require("normalize-path"));
7665
7637
  var FilesystemBridge = class {
7666
7638
  constructor(rootPath, outputPath) {
7667
- this.rootPath = rootPath || "";
7668
- this.outputPath = outputPath || rootPath;
7639
+ this.rootPath = import_path5.default.resolve(rootPath);
7640
+ this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
7669
7641
  }
7670
7642
  async glob(pattern, extension) {
7671
7643
  const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
@@ -7677,19 +7649,19 @@ var FilesystemBridge = class {
7677
7649
  }
7678
7650
  );
7679
7651
  const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
7680
- return items.map((item) => {
7681
- return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
7682
- });
7652
+ return items.map(
7653
+ (item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
7654
+ );
7683
7655
  }
7684
7656
  async delete(filepath) {
7685
7657
  await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
7686
7658
  }
7687
7659
  async get(filepath) {
7688
- return import_fs_extra2.default.readFileSync(import_path5.default.join(this.outputPath, filepath)).toString();
7660
+ return (await import_fs_extra2.default.readFile(import_path5.default.join(this.outputPath, filepath))).toString();
7689
7661
  }
7690
7662
  async put(filepath, data, basePathOverride) {
7691
7663
  const basePath = basePathOverride || this.outputPath;
7692
- await import_fs_extra2.default.outputFileSync(import_path5.default.join(basePath, filepath), data);
7664
+ await import_fs_extra2.default.outputFile(import_path5.default.join(basePath, filepath), data);
7693
7665
  }
7694
7666
  };
7695
7667
  var AuditFileSystemBridge = class extends FilesystemBridge {