@tinacms/graphql 0.0.0-ea204c9-20250318044256 → 0.0.0-eaa6ed5-20250729073245

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
  }
@@ -1914,7 +1913,7 @@ var Builder = class {
1914
1913
  * ```
1915
1914
  *
1916
1915
  * @public
1917
- * @param collection a Tina Cloud collection
1916
+ * @param collection a TinaCloud collection
1918
1917
  */
1919
1918
  this.collectionFragment = async (collection) => {
1920
1919
  const name = NAMER.dataTypeName(collection.namespace);
@@ -1944,13 +1943,12 @@ var Builder = class {
1944
1943
  *
1945
1944
  * */
1946
1945
  this._getCollectionFragmentSelections = async (collection, depth) => {
1947
- var _a;
1948
1946
  const selections = [];
1949
1947
  selections.push({
1950
1948
  name: { kind: "Name", value: "__typename" },
1951
1949
  kind: "Field"
1952
1950
  });
1953
- if (((_a = collection.fields) == null ? void 0 : _a.length) > 0) {
1951
+ if (collection.fields?.length > 0) {
1954
1952
  await sequential(collection.fields, async (x) => {
1955
1953
  const field = await this._buildFieldNodeForFragments(x, depth);
1956
1954
  selections.push(field);
@@ -1965,7 +1963,6 @@ var Builder = class {
1965
1963
  return selections;
1966
1964
  };
1967
1965
  this._buildFieldNodeForFragments = async (field, depth) => {
1968
- var _a, _b;
1969
1966
  switch (field.type) {
1970
1967
  case "string":
1971
1968
  case "image":
@@ -1998,7 +1995,7 @@ var Builder = class {
1998
1995
  selections: filterSelections([passwordValue, passwordChangeRequired])
1999
1996
  });
2000
1997
  case "object":
2001
- if (((_a = field.fields) == null ? void 0 : _a.length) > 0) {
1998
+ if (field.fields?.length > 0) {
2002
1999
  const selections2 = [];
2003
2000
  await sequential(field.fields, async (item) => {
2004
2001
  const field2 = await this._buildFieldNodeForFragments(item, depth);
@@ -2011,7 +2008,7 @@ var Builder = class {
2011
2008
  ...filterSelections(selections2)
2012
2009
  ]
2013
2010
  });
2014
- } else if (((_b = field.templates) == null ? void 0 : _b.length) > 0) {
2011
+ } else if (field.templates?.length > 0) {
2015
2012
  const selections2 = [];
2016
2013
  await sequential(field.templates, async (tem) => {
2017
2014
  if (typeof tem === "object") {
@@ -2673,7 +2670,7 @@ var Builder = class {
2673
2670
  this.addToLookupMap({
2674
2671
  type: name,
2675
2672
  resolveType: "unionData",
2676
- collection: collection == null ? void 0 : collection.name,
2673
+ collection: collection?.name,
2677
2674
  typeMap
2678
2675
  });
2679
2676
  return astBuilder.UnionTypeDefinition({ name, types });
@@ -2883,9 +2880,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2883
2880
  ]
2884
2881
  });
2885
2882
  };
2886
- var _a, _b, _c, _d;
2887
2883
  this.maxDepth = // @ts-ignore
2888
- (_d = (_c = (_b = (_a = config == null ? void 0 : config.tinaSchema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.client) == null ? void 0 : _c.referenceDepth) != null ? _d : 2;
2884
+ config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
2889
2885
  this.tinaSchema = config.tinaSchema;
2890
2886
  this.lookupMap = {};
2891
2887
  }
@@ -2974,7 +2970,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2974
2970
  return;
2975
2971
  }
2976
2972
  const noMatchCollections = collections.filter((x) => {
2977
- return typeof (x == null ? void 0 : x.match) === "undefined";
2973
+ return typeof x?.match === "undefined";
2978
2974
  }).map((x) => `${x.path}${x.format || "md"}`);
2979
2975
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2980
2976
  throw new Error(
@@ -2985,10 +2981,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2985
2981
  const hasMatchAndPath = collections.filter((x) => {
2986
2982
  return typeof x.path !== "undefined" && typeof x.match !== "undefined";
2987
2983
  }).map(
2988
- (x) => {
2989
- var _a, _b;
2990
- return `${x.path}|${((_a = x == null ? void 0 : x.match) == null ? void 0 : _a.exclude) || ""}|${((_b = x == null ? void 0 : x.match) == null ? void 0 : _b.include) || ""}|${x.format || "md"}`;
2991
- }
2984
+ (x) => `${x.path}|${x?.match?.exclude || ""}|${x?.match?.include || ""}|${x.format || "md"}`
2992
2985
  );
2993
2986
  if (hasMatchAndPath.length !== new Set(hasMatchAndPath).size) {
2994
2987
  throw new Error(
@@ -3012,7 +3005,7 @@ var validationCollectionsPathAndMatch = (collections) => {
3012
3005
  );
3013
3006
  }
3014
3007
  const matches = collectionsArr.map(
3015
- (x) => typeof (x == null ? void 0 : x.match) === "object" ? JSON.stringify(x.match) : ""
3008
+ (x) => typeof x?.match === "object" ? JSON.stringify(x.match) : ""
3016
3009
  );
3017
3010
  if (matches.length === new Set(matches).size) {
3018
3011
  return;
@@ -3090,7 +3083,7 @@ var validateField = async (field) => {
3090
3083
  // package.json
3091
3084
  var package_default = {
3092
3085
  name: "@tinacms/graphql",
3093
- version: "1.5.14",
3086
+ version: "1.6.0",
3094
3087
  main: "dist/index.js",
3095
3088
  module: "dist/index.mjs",
3096
3089
  typings: "dist/index.d.ts",
@@ -3116,33 +3109,32 @@ var package_default = {
3116
3109
  types: "pnpm tsc",
3117
3110
  build: "tinacms-scripts build",
3118
3111
  docs: "pnpm typedoc",
3119
- serve: "pnpm nodemon dist/server.js",
3120
3112
  test: "vitest run",
3121
3113
  "test-watch": "vitest"
3122
3114
  },
3123
3115
  dependencies: {
3124
- "@iarna/toml": "^2.2.5",
3116
+ "@iarna/toml": "catalog:",
3125
3117
  "@tinacms/mdx": "workspace:*",
3126
3118
  "@tinacms/schema-tools": "workspace:*",
3127
- "abstract-level": "^1.0.4",
3119
+ "abstract-level": "catalog:",
3128
3120
  "date-fns": "^2.30.0",
3129
- "fast-glob": "^3.3.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
3140
  publishConfig: {
@@ -3157,21 +3149,20 @@ var package_default = {
3157
3149
  "@tinacms/scripts": "workspace:*",
3158
3150
  "@types/cors": "^2.8.17",
3159
3151
  "@types/estree": "^0.0.50",
3160
- "@types/express": "^4.17.21",
3152
+ "@types/express": "catalog:",
3161
3153
  "@types/fs-extra": "^9.0.13",
3162
3154
  "@types/js-yaml": "^3.12.10",
3163
- "@types/lodash.camelcase": "^4.3.9",
3164
- "@types/lodash.upperfirst": "^4.3.9",
3165
- "@types/lru-cache": "^5.1.1",
3166
- "@types/mdast": "^3.0.15",
3167
- "@types/micromatch": "^4.0.9",
3155
+ "@types/lodash.camelcase": "catalog:",
3156
+ "@types/lodash.upperfirst": "catalog:",
3157
+ "@types/lru-cache": "catalog:",
3158
+ "@types/mdast": "catalog:",
3159
+ "@types/micromatch": "catalog:",
3168
3160
  "@types/node": "^22.13.1",
3169
- "@types/normalize-path": "^3.0.2",
3170
- "@types/ws": "^7.4.7",
3161
+ "@types/normalize-path": "catalog:",
3162
+ "@types/ws": "catalog:",
3171
3163
  "@types/yup": "^0.29.14",
3172
3164
  "jest-file-snapshot": "^0.5.0",
3173
- "memory-level": "^1.0.0",
3174
- nodemon: "3.1.4",
3165
+ "memory-level": "catalog:",
3175
3166
  typescript: "^5.7.3",
3176
3167
  vite: "^4.5.9",
3177
3168
  vitest: "^0.32.4",
@@ -3257,7 +3248,6 @@ var _buildQueries = async (builder, tinaSchema) => {
3257
3248
  const operationsDefinitions = [];
3258
3249
  const collections = tinaSchema.getCollections();
3259
3250
  await sequential(collections, async (collection) => {
3260
- var _a, _b, _c;
3261
3251
  const queryName = NAMER.queryName(collection.namespace);
3262
3252
  const queryListName = NAMER.generateQueryListName(collection.namespace);
3263
3253
  const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
@@ -3272,7 +3262,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3272
3262
  filterType: queryFilterTypeName,
3273
3263
  // look for flag to see if the data layer is enabled
3274
3264
  dataLayer: Boolean(
3275
- (_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
3265
+ tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
3276
3266
  )
3277
3267
  })
3278
3268
  );
@@ -3384,251 +3374,11 @@ var import_graphql5 = require("graphql");
3384
3374
  // src/resolver/index.ts
3385
3375
  var import_path3 = __toESM(require("path"));
3386
3376
  var import_isValid = __toESM(require("date-fns/isValid/index.js"));
3377
+ var import_jsonpath_plus2 = require("jsonpath-plus");
3387
3378
 
3388
3379
  // src/mdx/index.ts
3389
3380
  var import_mdx = require("@tinacms/mdx");
3390
3381
 
3391
- // src/resolver/index.ts
3392
- var import_jsonpath_plus2 = require("jsonpath-plus");
3393
-
3394
- // src/resolver/error.ts
3395
- var TinaGraphQLError = class extends Error {
3396
- constructor(message, extensions) {
3397
- super(message);
3398
- if (!this.name) {
3399
- Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
3400
- }
3401
- this.extensions = { ...extensions };
3402
- }
3403
- };
3404
- var TinaFetchError = class extends Error {
3405
- constructor(message, args) {
3406
- super(message);
3407
- this.name = "TinaFetchError";
3408
- this.collection = args.collection;
3409
- this.stack = args.stack;
3410
- this.file = args.file;
3411
- this.originalError = args.originalError;
3412
- }
3413
- };
3414
- var TinaQueryError = class extends TinaFetchError {
3415
- constructor(args) {
3416
- super(
3417
- `Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
3418
- args
3419
- );
3420
- }
3421
- };
3422
- var TinaParseDocumentError = class extends TinaFetchError {
3423
- constructor(args) {
3424
- super(
3425
- `Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
3426
- args
3427
- );
3428
- }
3429
- toString() {
3430
- return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
3431
- }
3432
- };
3433
- var auditMessage = (includeAuditMessage = true) => includeAuditMessage ? `Please run "tinacms audit" or add the --verbose option for more info` : "";
3434
- var handleFetchErrorError = (e, verbose) => {
3435
- if (e instanceof Error) {
3436
- if (e instanceof TinaFetchError) {
3437
- if (verbose) {
3438
- console.log(e.toString());
3439
- console.log(e);
3440
- console.log(e.stack);
3441
- }
3442
- }
3443
- } else {
3444
- console.error(e);
3445
- }
3446
- throw e;
3447
- };
3448
-
3449
- // src/resolver/filter-utils.ts
3450
- var resolveReferences = async (filter, fields, resolver) => {
3451
- for (const fieldKey of Object.keys(filter)) {
3452
- const fieldDefinition = fields.find(
3453
- (f) => f.name === fieldKey
3454
- );
3455
- if (fieldDefinition) {
3456
- if (fieldDefinition.type === "reference") {
3457
- const { edges, values } = await resolver(filter, fieldDefinition);
3458
- if (edges.length === 1) {
3459
- filter[fieldKey] = {
3460
- eq: values[0]
3461
- };
3462
- } else if (edges.length > 1) {
3463
- filter[fieldKey] = {
3464
- in: values
3465
- };
3466
- } else {
3467
- filter[fieldKey] = {
3468
- eq: "___null___"
3469
- };
3470
- }
3471
- } else if (fieldDefinition.type === "object") {
3472
- if (fieldDefinition.templates) {
3473
- for (const templateName of Object.keys(filter[fieldKey])) {
3474
- const template = fieldDefinition.templates.find(
3475
- (template2) => !(typeof template2 === "string") && template2.name === templateName
3476
- );
3477
- if (template) {
3478
- await resolveReferences(
3479
- filter[fieldKey][templateName],
3480
- template.fields,
3481
- resolver
3482
- );
3483
- } else {
3484
- throw new Error(`Template ${templateName} not found`);
3485
- }
3486
- }
3487
- } else {
3488
- await resolveReferences(
3489
- filter[fieldKey],
3490
- fieldDefinition.fields,
3491
- resolver
3492
- );
3493
- }
3494
- }
3495
- } else {
3496
- throw new Error(`Unable to find field ${fieldKey}`);
3497
- }
3498
- }
3499
- };
3500
- var collectConditionsForChildFields = (filterNode, fields, pathExpression, collectCondition) => {
3501
- for (const childFieldName of Object.keys(filterNode)) {
3502
- const childField = fields.find((field) => field.name === childFieldName);
3503
- if (!childField) {
3504
- throw new Error(`Unable to find type for field ${childFieldName}`);
3505
- }
3506
- collectConditionsForField(
3507
- childFieldName,
3508
- childField,
3509
- filterNode[childFieldName],
3510
- pathExpression,
3511
- collectCondition
3512
- );
3513
- }
3514
- };
3515
- var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
3516
- if (field.list && field.templates) {
3517
- for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
3518
- const template = field.templates.find(
3519
- (template2) => !(typeof template2 === "string") && template2.name === filterKey
3520
- );
3521
- const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
3522
- const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
3523
- collectConditionsForChildFields(
3524
- childFilterNode,
3525
- template.fields,
3526
- filterPath,
3527
- collectCondition
3528
- );
3529
- }
3530
- } else {
3531
- const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
3532
- const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
3533
- collectConditionsForChildFields(
3534
- filterNode,
3535
- field.fields,
3536
- filterPath,
3537
- collectCondition
3538
- );
3539
- }
3540
- };
3541
- var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
3542
- if (field.type === "object") {
3543
- collectConditionsForObjectField(
3544
- fieldName,
3545
- field,
3546
- filterNode,
3547
- pathExpression,
3548
- collectCondition
3549
- );
3550
- } else {
3551
- collectCondition({
3552
- filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
3553
- filterExpression: {
3554
- _type: field.type,
3555
- _list: !!field.list,
3556
- ...filterNode
3557
- }
3558
- });
3559
- }
3560
- };
3561
-
3562
- // src/resolver/media-utils.ts
3563
- var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, schema) => {
3564
- if (config && value) {
3565
- if (config.useRelativeMedia === true) {
3566
- return value;
3567
- }
3568
- if (hasTinaMediaConfig(schema) === true) {
3569
- const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
3570
- if (typeof value === "string" && value.includes(assetsURL)) {
3571
- const cleanMediaRoot = cleanUpSlashes(
3572
- schema.config.media.tina.mediaRoot
3573
- );
3574
- const strippedURL = value.replace(assetsURL, "");
3575
- return `${cleanMediaRoot}${strippedURL}`;
3576
- }
3577
- if (Array.isArray(value)) {
3578
- return value.map((v) => {
3579
- if (!v || typeof v !== "string") return v;
3580
- const cleanMediaRoot = cleanUpSlashes(
3581
- schema.config.media.tina.mediaRoot
3582
- );
3583
- const strippedURL = v.replace(assetsURL, "");
3584
- return `${cleanMediaRoot}${strippedURL}`;
3585
- });
3586
- }
3587
- return value;
3588
- }
3589
- return value;
3590
- } else {
3591
- return value;
3592
- }
3593
- };
3594
- var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, schema) => {
3595
- if (config && value) {
3596
- if (config.useRelativeMedia === true) {
3597
- return value;
3598
- }
3599
- if (hasTinaMediaConfig(schema) === true) {
3600
- const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
3601
- if (typeof value === "string") {
3602
- const strippedValue = value.replace(cleanMediaRoot, "");
3603
- return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3604
- }
3605
- if (Array.isArray(value)) {
3606
- return value.map((v) => {
3607
- if (!v || typeof v !== "string") return v;
3608
- const strippedValue = v.replace(cleanMediaRoot, "");
3609
- return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3610
- });
3611
- }
3612
- }
3613
- return value;
3614
- } else {
3615
- return value;
3616
- }
3617
- };
3618
- var cleanUpSlashes = (path7) => {
3619
- if (path7) {
3620
- return `/${path7.replace(/^\/+|\/+$/gm, "")}`;
3621
- }
3622
- return "";
3623
- };
3624
- var hasTinaMediaConfig = (schema) => {
3625
- var _a, _b, _c, _d, _e, _f, _g, _h;
3626
- if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3627
- if (typeof ((_e = (_d = (_c = schema.config) == null ? void 0 : _c.media) == null ? void 0 : _d.tina) == null ? void 0 : _e.publicFolder) !== "string" && typeof ((_h = (_g = (_f = schema.config) == null ? void 0 : _f.media) == null ? void 0 : _g.tina) == null ? void 0 : _h.mediaRoot) !== "string")
3628
- return false;
3629
- return true;
3630
- };
3631
-
3632
3382
  // src/resolver/index.ts
3633
3383
  var import_graphql3 = require("graphql");
3634
3384
 
@@ -3690,11 +3440,11 @@ var import_path2 = __toESM(require("path"));
3690
3440
 
3691
3441
  // src/database/util.ts
3692
3442
  var import_toml = __toESM(require("@iarna/toml"));
3693
- var import_js_yaml = __toESM(require("js-yaml"));
3694
- var import_gray_matter = __toESM(require("gray-matter"));
3695
3443
  var import_schema_tools4 = require("@tinacms/schema-tools");
3696
- var import_micromatch = __toESM(require("micromatch"));
3444
+ var import_gray_matter = __toESM(require("gray-matter"));
3445
+ var import_js_yaml = __toESM(require("js-yaml"));
3697
3446
  var import_path = __toESM(require("path"));
3447
+ var import_micromatch = __toESM(require("micromatch"));
3698
3448
 
3699
3449
  // src/database/alias-utils.ts
3700
3450
  var replaceBlockAliases = (template, item) => {
@@ -3731,22 +3481,20 @@ var replaceNameOverrides = (template, obj) => {
3731
3481
  }
3732
3482
  };
3733
3483
  function isBlockField(field) {
3734
- var _a;
3735
- return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
3484
+ return field && field.type === "object" && field.templates?.length > 0;
3736
3485
  }
3737
3486
  var _replaceNameOverrides = (fields, obj) => {
3738
3487
  const output = {};
3739
3488
  Object.keys(obj).forEach((key) => {
3740
3489
  const field = fields.find(
3741
- (fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key
3490
+ (fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
3742
3491
  );
3743
- 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];
3744
3493
  });
3745
3494
  return output;
3746
3495
  };
3747
3496
  var getTemplateForData = (field, data) => {
3748
- var _a;
3749
- if ((_a = field.templates) == null ? void 0 : _a.length) {
3497
+ if (field.templates?.length) {
3750
3498
  const templateKey = "_template";
3751
3499
  if (data[templateKey]) {
3752
3500
  const result = field.templates.find(
@@ -3804,8 +3552,8 @@ var _applyNameOverrides = (fields, obj) => {
3804
3552
  const output = {};
3805
3553
  Object.keys(obj).forEach((key) => {
3806
3554
  const field = fields.find((field2) => field2.name === key);
3807
- const outputKey = (field == null ? void 0 : field.nameOverride) || key;
3808
- output[outputKey] = (field == null ? void 0 : field.type) === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
3555
+ const outputKey = field?.nameOverride || key;
3556
+ output[outputKey] = field?.type === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
3809
3557
  });
3810
3558
  return output;
3811
3559
  };
@@ -3818,7 +3566,6 @@ var matterEngines = {
3818
3566
  }
3819
3567
  };
3820
3568
  var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3821
- var _a, _b;
3822
3569
  const {
3823
3570
  _relativePath,
3824
3571
  _keepTemplateKey,
@@ -3842,9 +3589,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3842
3589
  ${$_body}`,
3843
3590
  strippedContent,
3844
3591
  {
3845
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3592
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3846
3593
  engines: matterEngines,
3847
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---"
3594
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
3848
3595
  }
3849
3596
  );
3850
3597
  return ok;
@@ -3860,15 +3607,14 @@ ${$_body}`,
3860
3607
  }
3861
3608
  };
3862
3609
  var parseFile = (content, format, yupSchema, markdownParseConfig) => {
3863
- var _a, _b;
3864
3610
  try {
3865
3611
  switch (format) {
3866
3612
  case ".markdown":
3867
3613
  case ".mdx":
3868
3614
  case ".md":
3869
3615
  const contentJSON = (0, import_gray_matter.default)(content || "", {
3870
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3871
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---",
3616
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3617
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
3872
3618
  engines: matterEngines
3873
3619
  });
3874
3620
  const markdownData = {
@@ -3967,7 +3713,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3967
3713
  ),
3968
3714
  template: void 0
3969
3715
  } : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
3970
- const field = template == null ? void 0 : template.fields.find((field2) => {
3716
+ const field = template?.fields.find((field2) => {
3971
3717
  if (field2.type === "string" || field2.type === "rich-text") {
3972
3718
  if (field2.isBody) {
3973
3719
  return true;
@@ -3987,7 +3733,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3987
3733
  ...data,
3988
3734
  _collection: collection.name,
3989
3735
  _keepTemplateKey: !!collection.templates,
3990
- _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,
3991
3737
  _relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
3992
3738
  _id: filepath
3993
3739
  };
@@ -3996,10 +3742,10 @@ function hasOwnProperty(obj, prop) {
3996
3742
  return obj.hasOwnProperty(prop);
3997
3743
  }
3998
3744
  var getTemplateForFile = (templateInfo, data) => {
3999
- if ((templateInfo == null ? void 0 : templateInfo.type) === "object") {
3745
+ if (templateInfo?.type === "object") {
4000
3746
  return templateInfo.template;
4001
3747
  }
4002
- if ((templateInfo == null ? void 0 : templateInfo.type) === "union") {
3748
+ if (templateInfo?.type === "union") {
4003
3749
  if (hasOwnProperty(data, "_template")) {
4004
3750
  const template = templateInfo.templates.find(
4005
3751
  (t) => lastItem(t.namespace) === data._template
@@ -4023,8 +3769,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
4023
3769
  import_path.default.extname(filepath),
4024
3770
  (yup3) => yup3.object({}),
4025
3771
  {
4026
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
4027
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
3772
+ frontmatterDelimiters: collection?.frontmatterDelimiters,
3773
+ frontmatterFormat: collection?.frontmatterFormat
4028
3774
  }
4029
3775
  );
4030
3776
  const template = getTemplateForFile(templateInfo, data);
@@ -4585,113 +4331,349 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
4585
4331
  });
4586
4332
  }
4587
4333
  }
4588
- return result;
4334
+ return result;
4335
+ };
4336
+ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opType, level, escapeStr = stringEscaper) => {
4337
+ const result = [];
4338
+ if (collection) {
4339
+ const collectionSublevel = level.sublevel(collection, SUBLEVEL_OPTIONS);
4340
+ for (const [sort, definition] of Object.entries(indexDefinitions)) {
4341
+ const indexedValue = makeKeyForField(definition, data, escapeStr);
4342
+ const indexSublevel = collectionSublevel.sublevel(sort, SUBLEVEL_OPTIONS);
4343
+ if (sort === DEFAULT_COLLECTION_SORT_KEY) {
4344
+ result.push({
4345
+ type: opType,
4346
+ key: filepath,
4347
+ sublevel: indexSublevel,
4348
+ value: opType === "put" ? {} : void 0
4349
+ });
4350
+ } else {
4351
+ if (indexedValue) {
4352
+ result.push({
4353
+ type: opType,
4354
+ key: `${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4355
+ sublevel: indexSublevel,
4356
+ value: opType === "put" ? {} : void 0
4357
+ });
4358
+ }
4359
+ }
4360
+ }
4361
+ }
4362
+ return result;
4363
+ };
4364
+ var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
4365
+ const result = [];
4366
+ if (collection) {
4367
+ for (const [c, referencePaths] of Object.entries(references || {})) {
4368
+ if (!referencePaths.length) {
4369
+ continue;
4370
+ }
4371
+ const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
4372
+ const refSublevel = collectionSublevel.sublevel(
4373
+ REFS_COLLECTIONS_SORT_KEY,
4374
+ SUBLEVEL_OPTIONS
4375
+ );
4376
+ const references2 = {};
4377
+ for (const path7 of referencePaths) {
4378
+ const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
4379
+ if (!ref) {
4380
+ continue;
4381
+ }
4382
+ if (Array.isArray(ref)) {
4383
+ for (const r of ref) {
4384
+ if (!r) {
4385
+ continue;
4386
+ }
4387
+ if (references2[r]) {
4388
+ references2[r].push(path7);
4389
+ } else {
4390
+ references2[r] = [path7];
4391
+ }
4392
+ }
4393
+ } else {
4394
+ if (references2[ref]) {
4395
+ references2[ref].push(path7);
4396
+ } else {
4397
+ references2[ref] = [path7];
4398
+ }
4399
+ }
4400
+ }
4401
+ for (const ref of Object.keys(references2)) {
4402
+ for (const path7 of references2[ref]) {
4403
+ result.push({
4404
+ type: opType,
4405
+ key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4406
+ sublevel: refSublevel,
4407
+ value: opType === "put" ? {} : void 0
4408
+ });
4409
+ }
4410
+ }
4411
+ }
4412
+ }
4413
+ return result;
4414
+ };
4415
+ var makeStringEscaper = (regex, replacement) => {
4416
+ return (input) => {
4417
+ if (Array.isArray(input)) {
4418
+ return input.map(
4419
+ (val) => val.replace(regex, replacement)
4420
+ );
4421
+ } else {
4422
+ if (typeof input === "string") {
4423
+ return input.replace(regex, replacement);
4424
+ } else {
4425
+ return input;
4426
+ }
4427
+ }
4428
+ };
4429
+ };
4430
+ var stringEscaper = makeStringEscaper(
4431
+ new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
4432
+ encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
4433
+ );
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
+ }
4589
4555
  };
4590
- var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opType, level, escapeStr = stringEscaper) => {
4591
- const result = [];
4592
- if (collection) {
4593
- const collectionSublevel = level.sublevel(collection, SUBLEVEL_OPTIONS);
4594
- for (const [sort, definition] of Object.entries(indexDefinitions)) {
4595
- const indexedValue = makeKeyForField(definition, data, escapeStr);
4596
- const indexSublevel = collectionSublevel.sublevel(sort, SUBLEVEL_OPTIONS);
4597
- if (sort === DEFAULT_COLLECTION_SORT_KEY) {
4598
- result.push({
4599
- type: opType,
4600
- key: filepath,
4601
- sublevel: indexSublevel,
4602
- value: opType === "put" ? {} : void 0
4603
- });
4604
- } else {
4605
- if (indexedValue) {
4606
- result.push({
4607
- type: opType,
4608
- key: `${indexedValue}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4609
- sublevel: indexSublevel,
4610
- value: opType === "put" ? {} : void 0
4611
- });
4612
- }
4613
- }
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
+ );
4614
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
+ );
4615
4580
  }
4616
- return result;
4617
4581
  };
4618
- var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
4619
- const result = [];
4620
- if (collection) {
4621
- for (const [c, referencePaths] of Object.entries(references || {})) {
4622
- if (!referencePaths.length) {
4623
- continue;
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
4624
4598
  }
4625
- const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
4626
- const refSublevel = collectionSublevel.sublevel(
4627
- REFS_COLLECTIONS_SORT_KEY,
4628
- SUBLEVEL_OPTIONS
4629
- );
4630
- const references2 = {};
4631
- for (const path7 of referencePaths) {
4632
- const ref = (0, import_jsonpath_plus.JSONPath)({ path: path7, json: data });
4633
- if (!ref) {
4634
- continue;
4635
- }
4636
- if (Array.isArray(ref)) {
4637
- for (const r of ref) {
4638
- if (!r) {
4639
- continue;
4640
- }
4641
- if (references2[r]) {
4642
- references2[r].push(path7);
4643
- } else {
4644
- references2[r] = [path7];
4645
- }
4646
- }
4647
- } else {
4648
- if (references2[ref]) {
4649
- references2[ref].push(path7);
4650
- } else {
4651
- references2[ref] = [path7];
4652
- }
4653
- }
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}`;
4654
4617
  }
4655
- for (const ref of Object.keys(references2)) {
4656
- for (const path7 of references2[ref]) {
4657
- result.push({
4658
- type: opType,
4659
- key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
4660
- sublevel: refSublevel,
4661
- value: opType === "put" ? {} : void 0
4662
- });
4663
- }
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
+ });
4664
4627
  }
4628
+ return value;
4665
4629
  }
4630
+ return value;
4631
+ } else {
4632
+ return value;
4666
4633
  }
4667
- return result;
4668
4634
  };
4669
- var makeStringEscaper = (regex, replacement) => {
4670
- return (input) => {
4671
- if (Array.isArray(input)) {
4672
- return input.map(
4673
- (val) => val.replace(regex, replacement)
4674
- );
4675
- } else {
4676
- if (typeof input === "string") {
4677
- return input.replace(regex, replacement);
4678
- } else {
4679
- return input;
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
+ });
4680
4652
  }
4681
4653
  }
4682
- };
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;
4683
4670
  };
4684
- var stringEscaper = makeStringEscaper(
4685
- new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
4686
- encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
4687
- );
4688
4671
 
4689
4672
  // src/resolver/index.ts
4690
4673
  var createResolver = (args) => {
4691
4674
  return new Resolver(args);
4692
4675
  };
4693
4676
  var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4694
- var _a, _b;
4695
4677
  if (!rawData) {
4696
4678
  return void 0;
4697
4679
  }
@@ -4719,7 +4701,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4719
4701
  accumulator[field.name] = {
4720
4702
  value: void 0,
4721
4703
  // never resolve the password hash
4722
- passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4704
+ passwordChangeRequired: value["passwordChangeRequired"] ?? false
4723
4705
  };
4724
4706
  break;
4725
4707
  case "image":
@@ -4735,11 +4717,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4735
4717
  field,
4736
4718
  (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4737
4719
  );
4738
- if (((_b = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _b.type) === "invalid_markdown") {
4720
+ if (tree?.children[0]?.type === "invalid_markdown") {
4739
4721
  if (isAudit) {
4740
- const invalidNode = tree == null ? void 0 : tree.children[0];
4722
+ const invalidNode = tree?.children[0];
4741
4723
  throw new import_graphql3.GraphQLError(
4742
- `${invalidNode == null ? void 0 : invalidNode.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4724
+ `${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4743
4725
  );
4744
4726
  }
4745
4727
  }
@@ -4852,11 +4834,11 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4852
4834
  });
4853
4835
  }
4854
4836
  const titleField = template.fields.find((x) => {
4855
- if (x.type === "string" && (x == null ? void 0 : x.isTitle)) {
4837
+ if (x.type === "string" && x?.isTitle) {
4856
4838
  return true;
4857
4839
  }
4858
4840
  });
4859
- const titleFieldName = titleField == null ? void 0 : titleField.name;
4841
+ const titleFieldName = titleField?.name;
4860
4842
  const title = data[titleFieldName || " "] || null;
4861
4843
  return {
4862
4844
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
@@ -4966,7 +4948,7 @@ var Resolver = class {
4966
4948
  );
4967
4949
  }
4968
4950
  const rawData = await this.getRaw(fullPath);
4969
- 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;
4970
4952
  return transformDocumentIntoPayload(
4971
4953
  fullPath,
4972
4954
  rawData,
@@ -5006,9 +4988,9 @@ var Resolver = class {
5006
4988
  return this.buildFieldMutations(
5007
4989
  item,
5008
4990
  objectTemplate,
5009
- idField && existingData && (existingData == null ? void 0 : existingData.find(
4991
+ idField && existingData && existingData?.find(
5010
4992
  (d) => d[idField.name] === item[idField.name]
5011
- ))
4993
+ )
5012
4994
  );
5013
4995
  }
5014
4996
  )
@@ -5134,7 +5116,7 @@ var Resolver = class {
5134
5116
  isCollectionSpecific
5135
5117
  }) => {
5136
5118
  const doc = await this.getDocument(realPath);
5137
- const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
5119
+ const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
5138
5120
  if (isAddPendingDocument === true) {
5139
5121
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
5140
5122
  const params2 = this.buildParams(args);
@@ -5144,7 +5126,7 @@ var Resolver = class {
5144
5126
  const values = await this.buildFieldMutations(
5145
5127
  params2,
5146
5128
  templateInfo.template,
5147
- doc == null ? void 0 : doc._rawData
5129
+ doc?._rawData
5148
5130
  );
5149
5131
  await this.database.put(
5150
5132
  realPath,
@@ -5168,7 +5150,7 @@ var Resolver = class {
5168
5150
  // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
5169
5151
  templateParams,
5170
5152
  template,
5171
- doc == null ? void 0 : doc._rawData
5153
+ doc?._rawData
5172
5154
  ),
5173
5155
  _template: lastItem(template.namespace)
5174
5156
  };
@@ -5182,7 +5164,7 @@ var Resolver = class {
5182
5164
  //@ts-ignore
5183
5165
  isCollectionSpecific ? args.params : args.params[collection.name],
5184
5166
  collection,
5185
- doc == null ? void 0 : doc._rawData
5167
+ doc?._rawData
5186
5168
  );
5187
5169
  await this.database.put(
5188
5170
  realPath,
@@ -5198,7 +5180,6 @@ var Resolver = class {
5198
5180
  this.resolveLegacyValues = (oldDoc, collection) => {
5199
5181
  const legacyValues = {};
5200
5182
  Object.entries(oldDoc).forEach(([key, value]) => {
5201
- var _a;
5202
5183
  const reservedKeys = [
5203
5184
  "$_body",
5204
5185
  "_collection",
@@ -5211,7 +5192,7 @@ var Resolver = class {
5211
5192
  return;
5212
5193
  }
5213
5194
  if (oldDoc._template && collection.templates) {
5214
- const template = (_a = collection.templates) == null ? void 0 : _a.find(
5195
+ const template = collection.templates?.find(
5215
5196
  ({ name }) => name === oldDoc._template
5216
5197
  );
5217
5198
  if (template) {
@@ -5258,7 +5239,7 @@ var Resolver = class {
5258
5239
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5259
5240
  );
5260
5241
  const collection = await this.tinaSchema.getCollection(collectionLookup);
5261
- 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);
5262
5243
  if (isFolderCreation) {
5263
5244
  realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
5264
5245
  }
@@ -5342,12 +5323,12 @@ var Resolver = class {
5342
5323
  (yup3) => yup3.object({ params: yup3.object().required() })
5343
5324
  );
5344
5325
  assertShape(
5345
- args == null ? void 0 : args.params,
5326
+ args?.params,
5346
5327
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5347
5328
  );
5348
5329
  const doc = await this.getDocument(realPath);
5349
5330
  const newRealPath = import_path3.default.join(
5350
- collection == null ? void 0 : collection.path,
5331
+ collection?.path,
5351
5332
  args.params.relativePath
5352
5333
  );
5353
5334
  if (newRealPath === realPath) {
@@ -5577,7 +5558,7 @@ var Resolver = class {
5577
5558
  if (!references[c.name][refId]) {
5578
5559
  references[c.name][refId] = [];
5579
5560
  }
5580
- const referencePath = rawItem == null ? void 0 : rawItem[REFS_PATH_FIELD];
5561
+ const referencePath = rawItem?.[REFS_PATH_FIELD];
5581
5562
  if (referencePath) {
5582
5563
  references[c.name][refId].push(referencePath);
5583
5564
  }
@@ -5587,7 +5568,6 @@ var Resolver = class {
5587
5568
  return references;
5588
5569
  };
5589
5570
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
5590
- var _a;
5591
5571
  const accum = {};
5592
5572
  for (const passwordField of template.fields.filter(
5593
5573
  (f) => f.type === "password"
@@ -5630,7 +5610,7 @@ var Resolver = class {
5630
5610
  accum[fieldName] = await this.buildObjectMutations(
5631
5611
  fieldValue,
5632
5612
  field,
5633
- existingData == null ? void 0 : existingData[fieldName]
5613
+ existingData?.[fieldName]
5634
5614
  );
5635
5615
  break;
5636
5616
  case "password":
@@ -5649,12 +5629,12 @@ var Resolver = class {
5649
5629
  } else {
5650
5630
  accum[fieldName] = {
5651
5631
  ...fieldValue,
5652
- value: (_a = existingData == null ? void 0 : existingData[fieldName]) == null ? void 0 : _a["value"]
5632
+ value: existingData?.[fieldName]?.["value"]
5653
5633
  };
5654
5634
  }
5655
5635
  break;
5656
5636
  case "rich-text":
5657
- accum[fieldName] = (0, import_mdx.stringifyMDX)(
5637
+ accum[fieldName] = (0, import_mdx.serializeMDX)(
5658
5638
  fieldValue,
5659
5639
  field,
5660
5640
  (fieldValue2) => resolveMediaCloudToRelative(
@@ -5784,9 +5764,8 @@ var resolve = async ({
5784
5764
  isAudit,
5785
5765
  ctxUser
5786
5766
  }) => {
5787
- var _a;
5788
5767
  try {
5789
- const verboseValue = verbose != null ? verbose : true;
5768
+ const verboseValue = verbose ?? true;
5790
5769
  const graphQLSchemaAst = await database.getGraphQLSchema();
5791
5770
  if (!graphQLSchemaAst) {
5792
5771
  throw new import_graphql5.GraphQLError("GraphQL schema not found");
@@ -5798,7 +5777,7 @@ var resolve = async ({
5798
5777
  // @ts-ignore
5799
5778
  schema: tinaConfig,
5800
5779
  // @ts-ignore
5801
- flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5780
+ flags: tinaConfig?.meta?.flags
5802
5781
  });
5803
5782
  const resolver = createResolver({
5804
5783
  config,
@@ -5823,7 +5802,6 @@ var resolve = async ({
5823
5802
  throw new Error(`Unable to find lookup key for ${namedType}`);
5824
5803
  },
5825
5804
  fieldResolver: async (source = {}, _args = {}, _context, info) => {
5826
- var _a2, _b, _c, _d;
5827
5805
  try {
5828
5806
  const args = JSON.parse(JSON.stringify(_args));
5829
5807
  const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
@@ -5840,8 +5818,7 @@ var resolve = async ({
5840
5818
  );
5841
5819
  const hasDocuments2 = collectionNode2.selectionSet.selections.find(
5842
5820
  (x) => {
5843
- var _a3;
5844
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5821
+ return x?.name?.value === "documents";
5845
5822
  }
5846
5823
  );
5847
5824
  return tinaSchema.getCollections().map((collection) => {
@@ -5857,8 +5834,7 @@ var resolve = async ({
5857
5834
  );
5858
5835
  const hasDocuments = collectionNode.selectionSet.selections.find(
5859
5836
  (x) => {
5860
- var _a3;
5861
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5837
+ return x?.name?.value === "documents";
5862
5838
  }
5863
5839
  );
5864
5840
  return resolver.resolveCollection(
@@ -5877,7 +5853,7 @@ var resolve = async ({
5877
5853
  }
5878
5854
  }
5879
5855
  if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
5880
- const sub = args.sub || (ctxUser == null ? void 0 : ctxUser.sub);
5856
+ const sub = args.sub || ctxUser?.sub;
5881
5857
  const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5882
5858
  if (!collection) {
5883
5859
  throw new Error("Auth collection not found");
@@ -5925,7 +5901,7 @@ var resolve = async ({
5925
5901
  return user;
5926
5902
  }
5927
5903
  if (info.fieldName === "updatePassword") {
5928
- if (!(ctxUser == null ? void 0 : ctxUser.sub)) {
5904
+ if (!ctxUser?.sub) {
5929
5905
  throw new Error("Not authorized");
5930
5906
  }
5931
5907
  if (!args.password) {
@@ -6008,7 +5984,7 @@ var resolve = async ({
6008
5984
  if (typeof value === "string" && value !== "") {
6009
5985
  return resolver.getDocument(value);
6010
5986
  }
6011
- if ((args == null ? void 0 : args.collection) && info.fieldName === "addPendingDocument") {
5987
+ if (args?.collection && info.fieldName === "addPendingDocument") {
6012
5988
  return resolver.resolveDocument({
6013
5989
  args: { ...args, params: {} },
6014
5990
  collection: args.collection,
@@ -6032,7 +6008,7 @@ var resolve = async ({
6032
6008
  // Right now this is the only case for deletion
6033
6009
  isDeletion: info.fieldName === "deleteDocument",
6034
6010
  isFolderCreation: info.fieldName === "createFolder",
6035
- isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
6011
+ isUpdateName: Boolean(args?.params?.relativePath),
6036
6012
  isAddPendingDocument: false,
6037
6013
  isCollectionSpecific: false
6038
6014
  });
@@ -6051,16 +6027,16 @@ var resolve = async ({
6051
6027
  })
6052
6028
  };
6053
6029
  }
6054
- 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) {
6055
6031
  let filter = args.filter;
6056
6032
  if (
6057
6033
  // 1. Make sure that the filter exists
6058
- typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
6034
+ typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
6059
6035
  // @ts-ignore
6060
- typeof ((_b = value == null ? void 0 : value.collection) == null ? void 0 : _b.name) === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
6036
+ typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
6061
6037
  // @ts-ignore
6062
- Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
6063
- typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
6038
+ Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
6039
+ typeof args.filter[value?.collection?.name] !== "undefined"
6064
6040
  ) {
6065
6041
  filter = args.filter[value.collection.name];
6066
6042
  }
@@ -6197,15 +6173,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
6197
6173
  };
6198
6174
 
6199
6175
  // src/database/index.ts
6200
- var import_node_path = __toESM(require("path"));
6176
+ var import_node_path = __toESM(require("node:path"));
6201
6177
  var import_graphql6 = require("graphql");
6202
6178
  var import_micromatch2 = __toESM(require("micromatch"));
6203
6179
  var import_js_sha12 = __toESM(require("js-sha1"));
6204
6180
  var import_lodash5 = __toESM(require("lodash.set"));
6205
6181
  var createLocalDatabase = (config) => {
6206
- const level = new TinaLevelClient(config == null ? void 0 : config.port);
6182
+ const level = new TinaLevelClient(config?.port);
6207
6183
  level.openConnection();
6208
- const fsBridge = new FilesystemBridge((config == null ? void 0 : config.rootPath) || process.cwd());
6184
+ const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
6209
6185
  return new Database({
6210
6186
  bridge: fsBridge,
6211
6187
  ...config || {},
@@ -6278,7 +6254,7 @@ var Database = class {
6278
6254
  );
6279
6255
  }
6280
6256
  const metadata = await metadataLevel.get(`metadata_${key}`);
6281
- return metadata == null ? void 0 : metadata.value;
6257
+ return metadata?.value;
6282
6258
  };
6283
6259
  this.setMetadata = async (key, value) => {
6284
6260
  await this.initLevel();
@@ -6300,7 +6276,7 @@ var Database = class {
6300
6276
  let level = this.contentLevel;
6301
6277
  if (this.appLevel) {
6302
6278
  collection = await this.collectionForPath(filepath);
6303
- if (collection == null ? void 0 : collection.isDetached) {
6279
+ if (collection?.isDetached) {
6304
6280
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6305
6281
  }
6306
6282
  }
@@ -6319,7 +6295,6 @@ var Database = class {
6319
6295
  }
6320
6296
  };
6321
6297
  this.addPendingDocument = async (filepath, data) => {
6322
- var _a;
6323
6298
  await this.initLevel();
6324
6299
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6325
6300
  const collection = await this.collectionForPath(filepath);
@@ -6332,10 +6307,10 @@ var Database = class {
6332
6307
  collection
6333
6308
  );
6334
6309
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6335
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
6336
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
6310
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
6311
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
6337
6312
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6338
- if (!(collection == null ? void 0 : collection.isDetached)) {
6313
+ if (!collection?.isDetached) {
6339
6314
  if (this.bridge) {
6340
6315
  await this.bridge.put(normalizedPath, stringifiedFile);
6341
6316
  }
@@ -6353,7 +6328,7 @@ var Database = class {
6353
6328
  }
6354
6329
  }
6355
6330
  let level = this.contentLevel;
6356
- if (collection == null ? void 0 : collection.isDetached) {
6331
+ if (collection?.isDetached) {
6357
6332
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6358
6333
  }
6359
6334
  const folderTreeBuilder = new FolderTreeBuilder();
@@ -6364,7 +6339,7 @@ var Database = class {
6364
6339
  putOps = [
6365
6340
  ...makeRefOpsForDocument(
6366
6341
  normalizedPath,
6367
- collection == null ? void 0 : collection.name,
6342
+ collection?.name,
6368
6343
  collectionReferences,
6369
6344
  dataFields,
6370
6345
  "put",
@@ -6372,7 +6347,7 @@ var Database = class {
6372
6347
  ),
6373
6348
  ...makeIndexOpsForDocument(
6374
6349
  normalizedPath,
6375
- collection == null ? void 0 : collection.name,
6350
+ collection?.name,
6376
6351
  collectionIndexDefinitions,
6377
6352
  dataFields,
6378
6353
  "put",
@@ -6381,7 +6356,7 @@ var Database = class {
6381
6356
  // folder indices
6382
6357
  ...makeIndexOpsForDocument(
6383
6358
  normalizedPath,
6384
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6359
+ `${collection?.name}_${folderKey}`,
6385
6360
  collectionIndexDefinitions,
6386
6361
  dataFields,
6387
6362
  "put",
@@ -6395,7 +6370,7 @@ var Database = class {
6395
6370
  delOps = existingItem ? [
6396
6371
  ...makeRefOpsForDocument(
6397
6372
  normalizedPath,
6398
- collection == null ? void 0 : collection.name,
6373
+ collection?.name,
6399
6374
  collectionReferences,
6400
6375
  existingItem,
6401
6376
  "del",
@@ -6403,7 +6378,7 @@ var Database = class {
6403
6378
  ),
6404
6379
  ...makeIndexOpsForDocument(
6405
6380
  normalizedPath,
6406
- collection == null ? void 0 : collection.name,
6381
+ collection?.name,
6407
6382
  collectionIndexDefinitions,
6408
6383
  existingItem,
6409
6384
  "del",
@@ -6412,7 +6387,7 @@ var Database = class {
6412
6387
  // folder indices
6413
6388
  ...makeIndexOpsForDocument(
6414
6389
  normalizedPath,
6415
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6390
+ `${collection?.name}_${folderKey}`,
6416
6391
  collectionIndexDefinitions,
6417
6392
  existingItem,
6418
6393
  "del",
@@ -6436,7 +6411,6 @@ var Database = class {
6436
6411
  await level.batch(ops);
6437
6412
  };
6438
6413
  this.put = async (filepath, data, collectionName) => {
6439
- var _a, _b, _c;
6440
6414
  await this.initLevel();
6441
6415
  try {
6442
6416
  if (SYSTEM_FILES.includes(filepath)) {
@@ -6447,16 +6421,16 @@ var Database = class {
6447
6421
  const indexDefinitions = await this.getIndexDefinitions(
6448
6422
  this.contentLevel
6449
6423
  );
6450
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
6424
+ collectionIndexDefinitions = indexDefinitions?.[collectionName];
6451
6425
  }
6452
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collectionName];
6426
+ const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
6453
6427
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6454
6428
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6455
6429
  const collection = await this.collectionForPath(filepath);
6456
6430
  if (!collection) {
6457
6431
  throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
6458
6432
  }
6459
- 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) {
6460
6434
  const matches = this.tinaSchema.getMatches({ collection });
6461
6435
  const match = import_micromatch2.default.isMatch(filepath, matches);
6462
6436
  if (!match) {
@@ -6470,7 +6444,7 @@ var Database = class {
6470
6444
  const stringifiedFile = filepath.endsWith(
6471
6445
  `.gitkeep.${collection.format || "md"}`
6472
6446
  ) ? "" : await this.stringifyFile(filepath, dataFields, collection);
6473
- if (!(collection == null ? void 0 : collection.isDetached)) {
6447
+ if (!collection?.isDetached) {
6474
6448
  if (this.bridge) {
6475
6449
  await this.bridge.put(normalizedPath, stringifiedFile);
6476
6450
  }
@@ -6492,7 +6466,7 @@ var Database = class {
6492
6466
  filepath,
6493
6467
  collection.path || ""
6494
6468
  );
6495
- 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;
6496
6470
  let putOps = [];
6497
6471
  let delOps = [];
6498
6472
  if (!isGitKeep(normalizedPath, collection)) {
@@ -6516,7 +6490,7 @@ var Database = class {
6516
6490
  // folder indices
6517
6491
  ...makeIndexOpsForDocument(
6518
6492
  normalizedPath,
6519
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6493
+ `${collection?.name}_${folderKey}`,
6520
6494
  collectionIndexDefinitions,
6521
6495
  dataFields,
6522
6496
  "put",
@@ -6547,7 +6521,7 @@ var Database = class {
6547
6521
  // folder indices
6548
6522
  ...makeIndexOpsForDocument(
6549
6523
  normalizedPath,
6550
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6524
+ `${collection?.name}_${folderKey}`,
6551
6525
  collectionIndexDefinitions,
6552
6526
  existingItem,
6553
6527
  "del",
@@ -6624,8 +6598,8 @@ var Database = class {
6624
6598
  writeTemplateKey,
6625
6599
  //templateInfo.type === 'union',
6626
6600
  {
6627
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6628
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
6601
+ frontmatterFormat: collection?.frontmatterFormat,
6602
+ frontmatterDelimiters: collection?.frontmatterDelimiters
6629
6603
  }
6630
6604
  );
6631
6605
  };
@@ -6794,8 +6768,8 @@ var Database = class {
6794
6768
  );
6795
6769
  return {
6796
6770
  name: indexField.name,
6797
- type: field == null ? void 0 : field.type,
6798
- list: !!(field == null ? void 0 : field.list)
6771
+ type: field?.type,
6772
+ list: !!field?.list
6799
6773
  };
6800
6774
  })
6801
6775
  };
@@ -6821,7 +6795,6 @@ var Database = class {
6821
6795
  return true;
6822
6796
  };
6823
6797
  this.query = async (queryOptions, hydrator) => {
6824
- var _a;
6825
6798
  await this.initLevel();
6826
6799
  const {
6827
6800
  first,
@@ -6849,14 +6822,14 @@ var Database = class {
6849
6822
  const allIndexDefinitions = await this.getIndexDefinitions(
6850
6823
  this.contentLevel
6851
6824
  );
6852
- const indexDefinitions = allIndexDefinitions == null ? void 0 : allIndexDefinitions[collection.name];
6825
+ const indexDefinitions = allIndexDefinitions?.[collection.name];
6853
6826
  if (!indexDefinitions) {
6854
6827
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
6855
6828
  }
6856
6829
  const filterChain = coerceFilterChainOperands(rawFilterChain);
6857
- const indexDefinition = sort && (indexDefinitions == null ? void 0 : indexDefinitions[sort]);
6830
+ const indexDefinition = sort && indexDefinitions?.[sort];
6858
6831
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
6859
- const level = (collection == null ? void 0 : collection.isDetached) ? this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6832
+ const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6860
6833
  const rootLevel = level.sublevel(
6861
6834
  CONTENT_ROOT_PREFIX,
6862
6835
  SUBLEVEL_OPTIONS
@@ -6866,17 +6839,17 @@ var Database = class {
6866
6839
  SUBLEVEL_OPTIONS
6867
6840
  ).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
6868
6841
  if (!query.gt && !query.gte) {
6869
- query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
6842
+ query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
6870
6843
  }
6871
6844
  if (!query.lt && !query.lte) {
6872
- query.lte = (filterSuffixes == null ? void 0 : filterSuffixes.right) ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6845
+ query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6873
6846
  }
6874
6847
  let edges = [];
6875
6848
  let startKey = "";
6876
6849
  let endKey = "";
6877
6850
  let hasPreviousPage = false;
6878
6851
  let hasNextPage = false;
6879
- const fieldsPattern = ((_a = indexDefinition == null ? void 0 : indexDefinition.fields) == null ? void 0 : _a.length) ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
6852
+ const fieldsPattern = indexDefinition?.fields?.length ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
6880
6853
  const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
6881
6854
  const itemFilter = makeFilter({ filterChain });
6882
6855
  const iterator = sublevel.iterator(query);
@@ -7071,13 +7044,14 @@ var Database = class {
7071
7044
  documentPaths,
7072
7045
  async (collection, documentPaths2) => {
7073
7046
  if (collection && !collection.isDetached) {
7074
- await _indexContent(
7075
- this,
7076
- this.contentLevel,
7077
- documentPaths2,
7047
+ await _indexContent({
7048
+ database: this,
7049
+ level: this.contentLevel,
7050
+ documentPaths: documentPaths2,
7078
7051
  enqueueOps,
7079
- collection
7080
- );
7052
+ collection,
7053
+ isPartialReindex: true
7054
+ });
7081
7055
  }
7082
7056
  }
7083
7057
  );
@@ -7087,18 +7061,17 @@ var Database = class {
7087
7061
  }
7088
7062
  };
7089
7063
  this.delete = async (filepath) => {
7090
- var _a;
7091
7064
  await this.initLevel();
7092
7065
  const collection = await this.collectionForPath(filepath);
7093
7066
  if (!collection) {
7094
7067
  throw new Error(`No collection found for path: ${filepath}`);
7095
7068
  }
7096
7069
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
7097
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
7098
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7070
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
7071
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
7099
7072
  let level = this.contentLevel;
7100
- if (collection == null ? void 0 : collection.isDetached) {
7101
- level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
7073
+ if (collection?.isDetached) {
7074
+ level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
7102
7075
  }
7103
7076
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
7104
7077
  const rootSublevel = level.sublevel(
@@ -7145,7 +7118,7 @@ var Database = class {
7145
7118
  }
7146
7119
  ]);
7147
7120
  }
7148
- if (!(collection == null ? void 0 : collection.isDetached)) {
7121
+ if (!collection?.isDetached) {
7149
7122
  if (this.bridge) {
7150
7123
  await this.bridge.delete(normalizedPath);
7151
7124
  }
@@ -7185,26 +7158,26 @@ var Database = class {
7185
7158
  );
7186
7159
  const doc = await level2.keys({ limit: 1 }).next();
7187
7160
  if (!doc) {
7188
- await _indexContent(
7189
- this,
7190
- level2,
7191
- contentPaths,
7161
+ await _indexContent({
7162
+ database: this,
7163
+ level: level2,
7164
+ documentPaths: contentPaths,
7192
7165
  enqueueOps,
7193
7166
  collection,
7194
- userFields.map((field) => [
7167
+ passwordFields: userFields.map((field) => [
7195
7168
  ...field.path,
7196
7169
  field.passwordFieldName
7197
7170
  ])
7198
- );
7171
+ });
7199
7172
  }
7200
7173
  } else {
7201
- await _indexContent(
7202
- this,
7174
+ await _indexContent({
7175
+ database: this,
7203
7176
  level,
7204
- contentPaths,
7177
+ documentPaths: contentPaths,
7205
7178
  enqueueOps,
7206
7179
  collection
7207
- );
7180
+ });
7208
7181
  }
7209
7182
  }
7210
7183
  );
@@ -7240,7 +7213,7 @@ var Database = class {
7240
7213
  );
7241
7214
  }
7242
7215
  const metadata = await metadataLevel.get("metadata");
7243
- return metadata == null ? void 0 : metadata.version;
7216
+ return metadata?.version;
7244
7217
  }
7245
7218
  async initLevel() {
7246
7219
  if (this.contentLevel) {
@@ -7326,7 +7299,7 @@ var hashPasswordVisitor = async (node, path7) => {
7326
7299
  };
7327
7300
  var visitNodes = async (node, path7, callback) => {
7328
7301
  const [currentLevel, ...remainingLevels] = path7;
7329
- if (!(remainingLevels == null ? void 0 : remainingLevels.length)) {
7302
+ if (!remainingLevels?.length) {
7330
7303
  return callback(node, path7);
7331
7304
  }
7332
7305
  if (Array.isArray(node[currentLevel])) {
@@ -7342,20 +7315,27 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
7342
7315
  async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
7343
7316
  )
7344
7317
  );
7345
- var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${(collection == null ? void 0 : collection.format) || "md"}`);
7346
- var _indexContent = async (database, level, documentPaths, enqueueOps, collection, passwordFields) => {
7347
- var _a;
7318
+ var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
7319
+ var _indexContent = async ({
7320
+ database,
7321
+ level,
7322
+ documentPaths,
7323
+ enqueueOps,
7324
+ collection,
7325
+ passwordFields,
7326
+ isPartialReindex
7327
+ }) => {
7348
7328
  let collectionIndexDefinitions;
7349
7329
  let collectionPath;
7350
7330
  if (collection) {
7351
7331
  const indexDefinitions = await database.getIndexDefinitions(level);
7352
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7332
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7353
7333
  if (!collectionIndexDefinitions) {
7354
7334
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7355
7335
  }
7356
7336
  collectionPath = collection.path;
7357
7337
  }
7358
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7338
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7359
7339
  const tinaSchema = await database.getSchema();
7360
7340
  let templateInfo = null;
7361
7341
  if (collection) {
@@ -7373,7 +7353,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7373
7353
  if (!aliasedData) {
7374
7354
  return;
7375
7355
  }
7376
- if (passwordFields == null ? void 0 : passwordFields.length) {
7356
+ if (passwordFields?.length) {
7377
7357
  await hashPasswordValues(aliasedData, passwordFields);
7378
7358
  }
7379
7359
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
@@ -7385,46 +7365,48 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7385
7365
  normalizedPath,
7386
7366
  collectionPath || ""
7387
7367
  );
7388
- const item = await rootSublevel.get(normalizedPath);
7389
- if (item) {
7390
- await database.contentLevel.batch([
7391
- ...makeRefOpsForDocument(
7392
- normalizedPath,
7393
- collection == null ? void 0 : collection.name,
7394
- collectionReferences,
7395
- item,
7396
- "del",
7397
- level
7398
- ),
7399
- ...makeIndexOpsForDocument(
7400
- normalizedPath,
7401
- collection.name,
7402
- collectionIndexDefinitions,
7403
- item,
7404
- "del",
7405
- level
7406
- ),
7407
- // folder indices
7408
- ...makeIndexOpsForDocument(
7409
- normalizedPath,
7410
- `${collection.name}_${folderKey}`,
7411
- collectionIndexDefinitions,
7412
- item,
7413
- "del",
7414
- level
7415
- ),
7416
- {
7417
- type: "del",
7418
- key: normalizedPath,
7419
- sublevel: rootSublevel
7420
- }
7421
- ]);
7368
+ if (isPartialReindex) {
7369
+ const item = await rootSublevel.get(normalizedPath);
7370
+ if (item) {
7371
+ await database.contentLevel.batch([
7372
+ ...makeRefOpsForDocument(
7373
+ normalizedPath,
7374
+ collection?.name,
7375
+ collectionReferences,
7376
+ item,
7377
+ "del",
7378
+ level
7379
+ ),
7380
+ ...makeIndexOpsForDocument(
7381
+ normalizedPath,
7382
+ collection.name,
7383
+ collectionIndexDefinitions,
7384
+ item,
7385
+ "del",
7386
+ level
7387
+ ),
7388
+ // folder indices
7389
+ ...makeIndexOpsForDocument(
7390
+ normalizedPath,
7391
+ `${collection.name}_${folderKey}`,
7392
+ collectionIndexDefinitions,
7393
+ item,
7394
+ "del",
7395
+ level
7396
+ ),
7397
+ {
7398
+ type: "del",
7399
+ key: normalizedPath,
7400
+ sublevel: rootSublevel
7401
+ }
7402
+ ]);
7403
+ }
7422
7404
  }
7423
7405
  if (!isGitKeep(filepath, collection)) {
7424
7406
  await enqueueOps([
7425
7407
  ...makeRefOpsForDocument(
7426
7408
  normalizedPath,
7427
- collection == null ? void 0 : collection.name,
7409
+ collection?.name,
7428
7410
  collectionReferences,
7429
7411
  aliasedData,
7430
7412
  "put",
@@ -7432,7 +7414,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7432
7414
  ),
7433
7415
  ...makeIndexOpsForDocument(
7434
7416
  normalizedPath,
7435
- collection == null ? void 0 : collection.name,
7417
+ collection?.name,
7436
7418
  collectionIndexDefinitions,
7437
7419
  aliasedData,
7438
7420
  "put",
@@ -7441,7 +7423,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7441
7423
  // folder indexes
7442
7424
  ...makeIndexOpsForDocument(
7443
7425
  normalizedPath,
7444
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7426
+ `${collection?.name}_${folderKey}`,
7445
7427
  collectionIndexDefinitions,
7446
7428
  aliasedData,
7447
7429
  "put",
@@ -7462,7 +7444,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7462
7444
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7463
7445
  originalError: error,
7464
7446
  file: filepath,
7465
- collection: collection == null ? void 0 : collection.name,
7447
+ collection: collection?.name,
7466
7448
  stack: error.stack
7467
7449
  });
7468
7450
  }
@@ -7480,7 +7462,6 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
7480
7462
  }
7481
7463
  };
7482
7464
  var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
7483
- var _a;
7484
7465
  if (!documentPaths.length) {
7485
7466
  return;
7486
7467
  }
@@ -7489,12 +7470,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7489
7470
  const indexDefinitions = await database.getIndexDefinitions(
7490
7471
  database.contentLevel
7491
7472
  );
7492
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7473
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7493
7474
  if (!collectionIndexDefinitions) {
7494
7475
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7495
7476
  }
7496
7477
  }
7497
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7478
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7498
7479
  const tinaSchema = await database.getSchema();
7499
7480
  let templateInfo = null;
7500
7481
  if (collection) {
@@ -7511,7 +7492,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7511
7492
  if (item) {
7512
7493
  const folderKey = folderTreeBuilder.update(
7513
7494
  itemKey,
7514
- (collection == null ? void 0 : collection.path) || ""
7495
+ collection?.path || ""
7515
7496
  );
7516
7497
  const aliasedData = templateInfo ? replaceNameOverrides(
7517
7498
  getTemplateForFile(templateInfo, item),
@@ -7520,7 +7501,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7520
7501
  await enqueueOps([
7521
7502
  ...makeRefOpsForDocument(
7522
7503
  itemKey,
7523
- collection == null ? void 0 : collection.name,
7504
+ collection?.name,
7524
7505
  collectionReferences,
7525
7506
  aliasedData,
7526
7507
  "del",
@@ -7537,7 +7518,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7537
7518
  // folder indexes
7538
7519
  ...makeIndexOpsForDocument(
7539
7520
  itemKey,
7540
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7521
+ `${collection?.name}_${folderKey}`,
7541
7522
  collectionIndexDefinitions,
7542
7523
  aliasedData,
7543
7524
  "del",
@@ -7622,12 +7603,12 @@ var getChangedFiles = async ({
7622
7603
  }
7623
7604
  }
7624
7605
  }
7625
- if (await (B == null ? void 0 : B.type()) === "tree") {
7606
+ if (await B?.type() === "tree") {
7626
7607
  return;
7627
7608
  }
7628
7609
  if (matches) {
7629
- const oidA = await (A == null ? void 0 : A.oid());
7630
- const oidB = await (B == null ? void 0 : B.oid());
7610
+ const oidA = await A?.oid();
7611
+ const oidB = await B?.oid();
7631
7612
  if (oidA !== oidB) {
7632
7613
  if (oidA === void 0) {
7633
7614
  results.added.push(relativePath);
@@ -7655,8 +7636,8 @@ var import_path5 = __toESM(require("path"));
7655
7636
  var import_normalize_path = __toESM(require("normalize-path"));
7656
7637
  var FilesystemBridge = class {
7657
7638
  constructor(rootPath, outputPath) {
7658
- this.rootPath = rootPath || "";
7659
- this.outputPath = outputPath || rootPath;
7639
+ this.rootPath = import_path5.default.resolve(rootPath);
7640
+ this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
7660
7641
  }
7661
7642
  async glob(pattern, extension) {
7662
7643
  const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
@@ -7668,19 +7649,19 @@ var FilesystemBridge = class {
7668
7649
  }
7669
7650
  );
7670
7651
  const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
7671
- return items.map((item) => {
7672
- return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
7673
- });
7652
+ return items.map(
7653
+ (item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
7654
+ );
7674
7655
  }
7675
7656
  async delete(filepath) {
7676
7657
  await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
7677
7658
  }
7678
7659
  async get(filepath) {
7679
- 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();
7680
7661
  }
7681
7662
  async put(filepath, data, basePathOverride) {
7682
7663
  const basePath = basePathOverride || this.outputPath;
7683
- 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);
7684
7665
  }
7685
7666
  };
7686
7667
  var AuditFileSystemBridge = class extends FilesystemBridge {