@tinacms/graphql 0.0.0-d9672bc-20250218033222 → 0.0.0-dbef36f-20250616005720

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