@tinacms/graphql 1.5.17 → 1.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import type { Bridge } from './index';
6
6
  */
7
7
  export declare class FilesystemBridge implements Bridge {
8
8
  rootPath: string;
9
- outputPath?: string;
9
+ outputPath: string;
10
10
  constructor(rootPath: string, outputPath?: string);
11
11
  glob(pattern: string, extension: string): Promise<string[]>;
12
12
  delete(filepath: string): Promise<void>;
@@ -1,19 +1,16 @@
1
- /**
2
-
3
- */
4
1
  import * as yup from 'yup';
5
2
  import { Collection, CollectionTemplateable, normalizePath, TinaSchema } from '@tinacms/schema-tools';
6
3
  import { Bridge } from './bridge';
4
+ import { ContentFormat, ContentFrontmatterFormat } from '@tinacms/schema-tools';
7
5
  export { normalizePath };
8
- export declare const stringifyFile: (content: object, format: FormatType | string, keepTemplateKey: boolean, markdownParseConfig?: {
9
- frontmatterFormat?: "toml" | "yaml" | "json";
6
+ export declare const stringifyFile: (content: object, format: ContentFormat | string, keepTemplateKey: boolean, markdownParseConfig?: {
7
+ frontmatterFormat?: ContentFrontmatterFormat;
10
8
  frontmatterDelimiters?: [string, string] | string;
11
9
  }) => string;
12
- export declare const parseFile: <T extends object>(content: string, format: FormatType | string, yupSchema: (args: typeof yup) => yup.ObjectSchema<any>, markdownParseConfig?: {
13
- frontmatterFormat?: "toml" | "yaml" | "json";
10
+ export declare const parseFile: <T extends object>(content: string, format: ContentFormat | string, yupSchema: (args: typeof yup) => yup.ObjectSchema<any>, markdownParseConfig?: {
11
+ frontmatterFormat?: ContentFrontmatterFormat;
14
12
  frontmatterDelimiters?: [string, string] | string;
15
13
  }) => T;
16
- export type FormatType = 'json' | 'md' | 'mdx' | 'markdown';
17
14
  export declare const atob: (b64Encoded: string) => string;
18
15
  export declare const btoa: (string: string) => string;
19
16
  export declare const scanAllContent: (tinaSchema: TinaSchema, bridge: Bridge, callback: (collection: Collection<true>, contentPaths: string[]) => Promise<void>) => Promise<string[]>;
package/dist/index.js CHANGED
@@ -1435,13 +1435,12 @@ var checkPasswordHash = async ({
1435
1435
  return true;
1436
1436
  };
1437
1437
  var mapUserFields = (collectable, prefix = []) => {
1438
- var _a, _b, _c, _d, _e;
1439
1438
  const results = [];
1440
- const passwordFields = ((_a = collectable.fields) == null ? void 0 : _a.filter((field) => field.type === "password")) || [];
1439
+ const passwordFields = collectable.fields?.filter((field) => field.type === "password") || [];
1441
1440
  if (passwordFields.length > 1) {
1442
1441
  throw new Error("Only one password field is allowed");
1443
1442
  }
1444
- const idFields = ((_b = collectable.fields) == null ? void 0 : _b.filter((field) => field.uid)) || [];
1443
+ const idFields = collectable.fields?.filter((field) => field.uid) || [];
1445
1444
  if (idFields.length > 1) {
1446
1445
  throw new Error("Only one uid field is allowed");
1447
1446
  }
@@ -1449,11 +1448,11 @@ var mapUserFields = (collectable, prefix = []) => {
1449
1448
  results.push({
1450
1449
  path: prefix,
1451
1450
  collectable,
1452
- idFieldName: (_c = idFields[0]) == null ? void 0 : _c.name,
1453
- passwordFieldName: (_d = passwordFields[0]) == null ? void 0 : _d.name
1451
+ idFieldName: idFields[0]?.name,
1452
+ passwordFieldName: passwordFields[0]?.name
1454
1453
  });
1455
1454
  }
1456
- (_e = collectable.fields) == null ? void 0 : _e.forEach((field) => {
1455
+ collectable.fields?.forEach((field) => {
1457
1456
  if (field.type === "object" && field.fields) {
1458
1457
  results.push(...mapUserFields(field, [...prefix, field.name]));
1459
1458
  }
@@ -1944,13 +1943,12 @@ var Builder = class {
1944
1943
  *
1945
1944
  * */
1946
1945
  this._getCollectionFragmentSelections = async (collection, depth) => {
1947
- var _a;
1948
1946
  const selections = [];
1949
1947
  selections.push({
1950
1948
  name: { kind: "Name", value: "__typename" },
1951
1949
  kind: "Field"
1952
1950
  });
1953
- if (((_a = collection.fields) == null ? void 0 : _a.length) > 0) {
1951
+ if (collection.fields?.length > 0) {
1954
1952
  await sequential(collection.fields, async (x) => {
1955
1953
  const field = await this._buildFieldNodeForFragments(x, depth);
1956
1954
  selections.push(field);
@@ -1965,7 +1963,6 @@ var Builder = class {
1965
1963
  return selections;
1966
1964
  };
1967
1965
  this._buildFieldNodeForFragments = async (field, depth) => {
1968
- var _a, _b;
1969
1966
  switch (field.type) {
1970
1967
  case "string":
1971
1968
  case "image":
@@ -1998,7 +1995,7 @@ var Builder = class {
1998
1995
  selections: filterSelections([passwordValue, passwordChangeRequired])
1999
1996
  });
2000
1997
  case "object":
2001
- if (((_a = field.fields) == null ? void 0 : _a.length) > 0) {
1998
+ if (field.fields?.length > 0) {
2002
1999
  const selections2 = [];
2003
2000
  await sequential(field.fields, async (item) => {
2004
2001
  const field2 = await this._buildFieldNodeForFragments(item, depth);
@@ -2011,7 +2008,7 @@ var Builder = class {
2011
2008
  ...filterSelections(selections2)
2012
2009
  ]
2013
2010
  });
2014
- } else if (((_b = field.templates) == null ? void 0 : _b.length) > 0) {
2011
+ } else if (field.templates?.length > 0) {
2015
2012
  const selections2 = [];
2016
2013
  await sequential(field.templates, async (tem) => {
2017
2014
  if (typeof tem === "object") {
@@ -2673,7 +2670,7 @@ var Builder = class {
2673
2670
  this.addToLookupMap({
2674
2671
  type: name,
2675
2672
  resolveType: "unionData",
2676
- collection: collection == null ? void 0 : collection.name,
2673
+ collection: collection?.name,
2677
2674
  typeMap
2678
2675
  });
2679
2676
  return astBuilder.UnionTypeDefinition({ name, types });
@@ -2883,9 +2880,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2883
2880
  ]
2884
2881
  });
2885
2882
  };
2886
- var _a, _b, _c, _d;
2887
2883
  this.maxDepth = // @ts-ignore
2888
- (_d = (_c = (_b = (_a = config == null ? void 0 : config.tinaSchema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.client) == null ? void 0 : _c.referenceDepth) != null ? _d : 2;
2884
+ config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
2889
2885
  this.tinaSchema = config.tinaSchema;
2890
2886
  this.lookupMap = {};
2891
2887
  }
@@ -2974,7 +2970,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2974
2970
  return;
2975
2971
  }
2976
2972
  const noMatchCollections = collections.filter((x) => {
2977
- return typeof (x == null ? void 0 : x.match) === "undefined";
2973
+ return typeof x?.match === "undefined";
2978
2974
  }).map((x) => `${x.path}${x.format || "md"}`);
2979
2975
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2980
2976
  throw new Error(
@@ -2985,10 +2981,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2985
2981
  const hasMatchAndPath = collections.filter((x) => {
2986
2982
  return typeof x.path !== "undefined" && typeof x.match !== "undefined";
2987
2983
  }).map(
2988
- (x) => {
2989
- var _a, _b;
2990
- return `${x.path}|${((_a = x == null ? void 0 : x.match) == null ? void 0 : _a.exclude) || ""}|${((_b = x == null ? void 0 : x.match) == null ? void 0 : _b.include) || ""}|${x.format || "md"}`;
2991
- }
2984
+ (x) => `${x.path}|${x?.match?.exclude || ""}|${x?.match?.include || ""}|${x.format || "md"}`
2992
2985
  );
2993
2986
  if (hasMatchAndPath.length !== new Set(hasMatchAndPath).size) {
2994
2987
  throw new Error(
@@ -3012,7 +3005,7 @@ var validationCollectionsPathAndMatch = (collections) => {
3012
3005
  );
3013
3006
  }
3014
3007
  const matches = collectionsArr.map(
3015
- (x) => typeof (x == null ? void 0 : x.match) === "object" ? JSON.stringify(x.match) : ""
3008
+ (x) => typeof x?.match === "object" ? JSON.stringify(x.match) : ""
3016
3009
  );
3017
3010
  if (matches.length === new Set(matches).size) {
3018
3011
  return;
@@ -3090,7 +3083,7 @@ var validateField = async (field) => {
3090
3083
  // package.json
3091
3084
  var package_default = {
3092
3085
  name: "@tinacms/graphql",
3093
- version: "1.5.17",
3086
+ version: "1.5.18",
3094
3087
  main: "dist/index.js",
3095
3088
  module: "dist/index.mjs",
3096
3089
  typings: "dist/index.d.ts",
@@ -3255,7 +3248,6 @@ var _buildQueries = async (builder, tinaSchema) => {
3255
3248
  const operationsDefinitions = [];
3256
3249
  const collections = tinaSchema.getCollections();
3257
3250
  await sequential(collections, async (collection) => {
3258
- var _a, _b, _c;
3259
3251
  const queryName = NAMER.queryName(collection.namespace);
3260
3252
  const queryListName = NAMER.generateQueryListName(collection.namespace);
3261
3253
  const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
@@ -3270,7 +3262,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3270
3262
  filterType: queryFilterTypeName,
3271
3263
  // look for flag to see if the data layer is enabled
3272
3264
  dataLayer: Boolean(
3273
- (_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
3265
+ tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
3274
3266
  )
3275
3267
  })
3276
3268
  );
@@ -3620,9 +3612,8 @@ var cleanUpSlashes = (path7) => {
3620
3612
  return "";
3621
3613
  };
3622
3614
  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")
3615
+ if (!schema.config?.media?.tina) return false;
3616
+ if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
3626
3617
  return false;
3627
3618
  return true;
3628
3619
  };
@@ -3729,22 +3720,20 @@ var replaceNameOverrides = (template, obj) => {
3729
3720
  }
3730
3721
  };
3731
3722
  function isBlockField(field) {
3732
- var _a;
3733
- return field && field.type === "object" && ((_a = field.templates) == null ? void 0 : _a.length) > 0;
3723
+ return field && field.type === "object" && field.templates?.length > 0;
3734
3724
  }
3735
3725
  var _replaceNameOverrides = (fields, obj) => {
3736
3726
  const output = {};
3737
3727
  Object.keys(obj).forEach((key) => {
3738
3728
  const field = fields.find(
3739
- (fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key
3729
+ (fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
3740
3730
  );
3741
- output[(field == null ? void 0 : field.name) || key] = (field == null ? void 0 : field.type) == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
3731
+ output[field?.name || key] = field?.type == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
3742
3732
  });
3743
3733
  return output;
3744
3734
  };
3745
3735
  var getTemplateForData = (field, data) => {
3746
- var _a;
3747
- if ((_a = field.templates) == null ? void 0 : _a.length) {
3736
+ if (field.templates?.length) {
3748
3737
  const templateKey = "_template";
3749
3738
  if (data[templateKey]) {
3750
3739
  const result = field.templates.find(
@@ -3802,8 +3791,8 @@ var _applyNameOverrides = (fields, obj) => {
3802
3791
  const output = {};
3803
3792
  Object.keys(obj).forEach((key) => {
3804
3793
  const field = fields.find((field2) => field2.name === key);
3805
- const outputKey = (field == null ? void 0 : field.nameOverride) || key;
3806
- output[outputKey] = (field == null ? void 0 : field.type) === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
3794
+ const outputKey = field?.nameOverride || key;
3795
+ output[outputKey] = field?.type === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
3807
3796
  });
3808
3797
  return output;
3809
3798
  };
@@ -3816,7 +3805,6 @@ var matterEngines = {
3816
3805
  }
3817
3806
  };
3818
3807
  var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3819
- var _a, _b;
3820
3808
  const {
3821
3809
  _relativePath,
3822
3810
  _keepTemplateKey,
@@ -3840,9 +3828,9 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
3840
3828
  ${$_body}`,
3841
3829
  strippedContent,
3842
3830
  {
3843
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3831
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3844
3832
  engines: matterEngines,
3845
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---"
3833
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---"
3846
3834
  }
3847
3835
  );
3848
3836
  return ok;
@@ -3858,15 +3846,14 @@ ${$_body}`,
3858
3846
  }
3859
3847
  };
3860
3848
  var parseFile = (content, format, yupSchema, markdownParseConfig) => {
3861
- var _a, _b;
3862
3849
  try {
3863
3850
  switch (format) {
3864
3851
  case ".markdown":
3865
3852
  case ".mdx":
3866
3853
  case ".md":
3867
3854
  const contentJSON = (0, import_gray_matter.default)(content || "", {
3868
- language: (_a = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) != null ? _a : "yaml",
3869
- delimiters: (_b = markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) != null ? _b : "---",
3855
+ language: markdownParseConfig?.frontmatterFormat ?? "yaml",
3856
+ delimiters: markdownParseConfig?.frontmatterDelimiters ?? "---",
3870
3857
  engines: matterEngines
3871
3858
  });
3872
3859
  const markdownData = {
@@ -3965,7 +3952,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3965
3952
  ),
3966
3953
  template: void 0
3967
3954
  } : tinaSchema.getCollectionAndTemplateByFullPath(filepath, templateName);
3968
- const field = template == null ? void 0 : template.fields.find((field2) => {
3955
+ const field = template?.fields.find((field2) => {
3969
3956
  if (field2.type === "string" || field2.type === "rich-text") {
3970
3957
  if (field2.isBody) {
3971
3958
  return true;
@@ -3985,7 +3972,7 @@ var transformDocument = (filepath, contentObject, tinaSchema) => {
3985
3972
  ...data,
3986
3973
  _collection: collection.name,
3987
3974
  _keepTemplateKey: !!collection.templates,
3988
- _template: (template == null ? void 0 : template.namespace) ? lastItem(template == null ? void 0 : template.namespace) : void 0,
3975
+ _template: template?.namespace ? lastItem(template?.namespace) : void 0,
3989
3976
  _relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
3990
3977
  _id: filepath
3991
3978
  };
@@ -3994,10 +3981,10 @@ function hasOwnProperty(obj, prop) {
3994
3981
  return obj.hasOwnProperty(prop);
3995
3982
  }
3996
3983
  var getTemplateForFile = (templateInfo, data) => {
3997
- if ((templateInfo == null ? void 0 : templateInfo.type) === "object") {
3984
+ if (templateInfo?.type === "object") {
3998
3985
  return templateInfo.template;
3999
3986
  }
4000
- if ((templateInfo == null ? void 0 : templateInfo.type) === "union") {
3987
+ if (templateInfo?.type === "union") {
4001
3988
  if (hasOwnProperty(data, "_template")) {
4002
3989
  const template = templateInfo.templates.find(
4003
3990
  (t) => lastItem(t.namespace) === data._template
@@ -4021,8 +4008,8 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
4021
4008
  import_path.default.extname(filepath),
4022
4009
  (yup3) => yup3.object({}),
4023
4010
  {
4024
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
4025
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
4011
+ frontmatterDelimiters: collection?.frontmatterDelimiters,
4012
+ frontmatterFormat: collection?.frontmatterFormat
4026
4013
  }
4027
4014
  );
4028
4015
  const template = getTemplateForFile(templateInfo, data);
@@ -4689,7 +4676,6 @@ var createResolver = (args) => {
4689
4676
  return new Resolver(args);
4690
4677
  };
4691
4678
  var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4692
- var _a, _b;
4693
4679
  if (!rawData) {
4694
4680
  return void 0;
4695
4681
  }
@@ -4717,7 +4703,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4717
4703
  accumulator[field.name] = {
4718
4704
  value: void 0,
4719
4705
  // never resolve the password hash
4720
- passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4706
+ passwordChangeRequired: value["passwordChangeRequired"] ?? false
4721
4707
  };
4722
4708
  break;
4723
4709
  case "image":
@@ -4733,11 +4719,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4733
4719
  field,
4734
4720
  (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4735
4721
  );
4736
- if (((_b = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _b.type) === "invalid_markdown") {
4722
+ if (tree?.children[0]?.type === "invalid_markdown") {
4737
4723
  if (isAudit) {
4738
- const invalidNode = tree == null ? void 0 : tree.children[0];
4724
+ const invalidNode = tree?.children[0];
4739
4725
  throw new import_graphql3.GraphQLError(
4740
- `${invalidNode == null ? void 0 : invalidNode.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4726
+ `${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4741
4727
  );
4742
4728
  }
4743
4729
  }
@@ -4850,11 +4836,11 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4850
4836
  });
4851
4837
  }
4852
4838
  const titleField = template.fields.find((x) => {
4853
- if (x.type === "string" && (x == null ? void 0 : x.isTitle)) {
4839
+ if (x.type === "string" && x?.isTitle) {
4854
4840
  return true;
4855
4841
  }
4856
4842
  });
4857
- const titleFieldName = titleField == null ? void 0 : titleField.name;
4843
+ const titleFieldName = titleField?.name;
4858
4844
  const title = data[titleFieldName || " "] || null;
4859
4845
  return {
4860
4846
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
@@ -4964,7 +4950,7 @@ var Resolver = class {
4964
4950
  );
4965
4951
  }
4966
4952
  const rawData = await this.getRaw(fullPath);
4967
- const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
4953
+ const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
4968
4954
  return transformDocumentIntoPayload(
4969
4955
  fullPath,
4970
4956
  rawData,
@@ -5004,9 +4990,9 @@ var Resolver = class {
5004
4990
  return this.buildFieldMutations(
5005
4991
  item,
5006
4992
  objectTemplate,
5007
- idField && existingData && (existingData == null ? void 0 : existingData.find(
4993
+ idField && existingData && existingData?.find(
5008
4994
  (d) => d[idField.name] === item[idField.name]
5009
- ))
4995
+ )
5010
4996
  );
5011
4997
  }
5012
4998
  )
@@ -5132,7 +5118,7 @@ var Resolver = class {
5132
5118
  isCollectionSpecific
5133
5119
  }) => {
5134
5120
  const doc = await this.getDocument(realPath);
5135
- const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
5121
+ const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
5136
5122
  if (isAddPendingDocument === true) {
5137
5123
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
5138
5124
  const params2 = this.buildParams(args);
@@ -5142,7 +5128,7 @@ var Resolver = class {
5142
5128
  const values = await this.buildFieldMutations(
5143
5129
  params2,
5144
5130
  templateInfo.template,
5145
- doc == null ? void 0 : doc._rawData
5131
+ doc?._rawData
5146
5132
  );
5147
5133
  await this.database.put(
5148
5134
  realPath,
@@ -5166,7 +5152,7 @@ var Resolver = class {
5166
5152
  // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
5167
5153
  templateParams,
5168
5154
  template,
5169
- doc == null ? void 0 : doc._rawData
5155
+ doc?._rawData
5170
5156
  ),
5171
5157
  _template: lastItem(template.namespace)
5172
5158
  };
@@ -5180,7 +5166,7 @@ var Resolver = class {
5180
5166
  //@ts-ignore
5181
5167
  isCollectionSpecific ? args.params : args.params[collection.name],
5182
5168
  collection,
5183
- doc == null ? void 0 : doc._rawData
5169
+ doc?._rawData
5184
5170
  );
5185
5171
  await this.database.put(
5186
5172
  realPath,
@@ -5196,7 +5182,6 @@ var Resolver = class {
5196
5182
  this.resolveLegacyValues = (oldDoc, collection) => {
5197
5183
  const legacyValues = {};
5198
5184
  Object.entries(oldDoc).forEach(([key, value]) => {
5199
- var _a;
5200
5185
  const reservedKeys = [
5201
5186
  "$_body",
5202
5187
  "_collection",
@@ -5209,7 +5194,7 @@ var Resolver = class {
5209
5194
  return;
5210
5195
  }
5211
5196
  if (oldDoc._template && collection.templates) {
5212
- const template = (_a = collection.templates) == null ? void 0 : _a.find(
5197
+ const template = collection.templates?.find(
5213
5198
  ({ name }) => name === oldDoc._template
5214
5199
  );
5215
5200
  if (template) {
@@ -5256,7 +5241,7 @@ var Resolver = class {
5256
5241
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5257
5242
  );
5258
5243
  const collection = await this.tinaSchema.getCollection(collectionLookup);
5259
- let realPath = import_path3.default.join(collection == null ? void 0 : collection.path, args.relativePath);
5244
+ let realPath = import_path3.default.join(collection?.path, args.relativePath);
5260
5245
  if (isFolderCreation) {
5261
5246
  realPath = `${realPath}/.gitkeep.${collection.format || "md"}`;
5262
5247
  }
@@ -5340,12 +5325,12 @@ var Resolver = class {
5340
5325
  (yup3) => yup3.object({ params: yup3.object().required() })
5341
5326
  );
5342
5327
  assertShape(
5343
- args == null ? void 0 : args.params,
5328
+ args?.params,
5344
5329
  (yup3) => yup3.object({ relativePath: yup3.string().required() })
5345
5330
  );
5346
5331
  const doc = await this.getDocument(realPath);
5347
5332
  const newRealPath = import_path3.default.join(
5348
- collection == null ? void 0 : collection.path,
5333
+ collection?.path,
5349
5334
  args.params.relativePath
5350
5335
  );
5351
5336
  if (newRealPath === realPath) {
@@ -5575,7 +5560,7 @@ var Resolver = class {
5575
5560
  if (!references[c.name][refId]) {
5576
5561
  references[c.name][refId] = [];
5577
5562
  }
5578
- const referencePath = rawItem == null ? void 0 : rawItem[REFS_PATH_FIELD];
5563
+ const referencePath = rawItem?.[REFS_PATH_FIELD];
5579
5564
  if (referencePath) {
5580
5565
  references[c.name][refId].push(referencePath);
5581
5566
  }
@@ -5585,7 +5570,6 @@ var Resolver = class {
5585
5570
  return references;
5586
5571
  };
5587
5572
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
5588
- var _a;
5589
5573
  const accum = {};
5590
5574
  for (const passwordField of template.fields.filter(
5591
5575
  (f) => f.type === "password"
@@ -5628,7 +5612,7 @@ var Resolver = class {
5628
5612
  accum[fieldName] = await this.buildObjectMutations(
5629
5613
  fieldValue,
5630
5614
  field,
5631
- existingData == null ? void 0 : existingData[fieldName]
5615
+ existingData?.[fieldName]
5632
5616
  );
5633
5617
  break;
5634
5618
  case "password":
@@ -5647,7 +5631,7 @@ var Resolver = class {
5647
5631
  } else {
5648
5632
  accum[fieldName] = {
5649
5633
  ...fieldValue,
5650
- value: (_a = existingData == null ? void 0 : existingData[fieldName]) == null ? void 0 : _a["value"]
5634
+ value: existingData?.[fieldName]?.["value"]
5651
5635
  };
5652
5636
  }
5653
5637
  break;
@@ -5782,9 +5766,8 @@ var resolve = async ({
5782
5766
  isAudit,
5783
5767
  ctxUser
5784
5768
  }) => {
5785
- var _a;
5786
5769
  try {
5787
- const verboseValue = verbose != null ? verbose : true;
5770
+ const verboseValue = verbose ?? true;
5788
5771
  const graphQLSchemaAst = await database.getGraphQLSchema();
5789
5772
  if (!graphQLSchemaAst) {
5790
5773
  throw new import_graphql5.GraphQLError("GraphQL schema not found");
@@ -5796,7 +5779,7 @@ var resolve = async ({
5796
5779
  // @ts-ignore
5797
5780
  schema: tinaConfig,
5798
5781
  // @ts-ignore
5799
- flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5782
+ flags: tinaConfig?.meta?.flags
5800
5783
  });
5801
5784
  const resolver = createResolver({
5802
5785
  config,
@@ -5821,7 +5804,6 @@ var resolve = async ({
5821
5804
  throw new Error(`Unable to find lookup key for ${namedType}`);
5822
5805
  },
5823
5806
  fieldResolver: async (source = {}, _args = {}, _context, info) => {
5824
- var _a2, _b, _c, _d;
5825
5807
  try {
5826
5808
  const args = JSON.parse(JSON.stringify(_args));
5827
5809
  const returnType = (0, import_graphql5.getNamedType)(info.returnType).toString();
@@ -5838,8 +5820,7 @@ var resolve = async ({
5838
5820
  );
5839
5821
  const hasDocuments2 = collectionNode2.selectionSet.selections.find(
5840
5822
  (x) => {
5841
- var _a3;
5842
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5823
+ return x?.name?.value === "documents";
5843
5824
  }
5844
5825
  );
5845
5826
  return tinaSchema.getCollections().map((collection) => {
@@ -5855,8 +5836,7 @@ var resolve = async ({
5855
5836
  );
5856
5837
  const hasDocuments = collectionNode.selectionSet.selections.find(
5857
5838
  (x) => {
5858
- var _a3;
5859
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
5839
+ return x?.name?.value === "documents";
5860
5840
  }
5861
5841
  );
5862
5842
  return resolver.resolveCollection(
@@ -5875,7 +5855,7 @@ var resolve = async ({
5875
5855
  }
5876
5856
  }
5877
5857
  if (info.fieldName === "authenticate" || info.fieldName === "authorize") {
5878
- const sub = args.sub || (ctxUser == null ? void 0 : ctxUser.sub);
5858
+ const sub = args.sub || ctxUser?.sub;
5879
5859
  const collection = tinaSchema.getCollections().find((c) => c.isAuthCollection);
5880
5860
  if (!collection) {
5881
5861
  throw new Error("Auth collection not found");
@@ -5923,7 +5903,7 @@ var resolve = async ({
5923
5903
  return user;
5924
5904
  }
5925
5905
  if (info.fieldName === "updatePassword") {
5926
- if (!(ctxUser == null ? void 0 : ctxUser.sub)) {
5906
+ if (!ctxUser?.sub) {
5927
5907
  throw new Error("Not authorized");
5928
5908
  }
5929
5909
  if (!args.password) {
@@ -6006,7 +5986,7 @@ var resolve = async ({
6006
5986
  if (typeof value === "string" && value !== "") {
6007
5987
  return resolver.getDocument(value);
6008
5988
  }
6009
- if ((args == null ? void 0 : args.collection) && info.fieldName === "addPendingDocument") {
5989
+ if (args?.collection && info.fieldName === "addPendingDocument") {
6010
5990
  return resolver.resolveDocument({
6011
5991
  args: { ...args, params: {} },
6012
5992
  collection: args.collection,
@@ -6030,7 +6010,7 @@ var resolve = async ({
6030
6010
  // Right now this is the only case for deletion
6031
6011
  isDeletion: info.fieldName === "deleteDocument",
6032
6012
  isFolderCreation: info.fieldName === "createFolder",
6033
- isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
6013
+ isUpdateName: Boolean(args?.params?.relativePath),
6034
6014
  isAddPendingDocument: false,
6035
6015
  isCollectionSpecific: false
6036
6016
  });
@@ -6049,16 +6029,16 @@ var resolve = async ({
6049
6029
  })
6050
6030
  };
6051
6031
  }
6052
- if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
6032
+ if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
6053
6033
  let filter = args.filter;
6054
6034
  if (
6055
6035
  // 1. Make sure that the filter exists
6056
- typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
6036
+ typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
6057
6037
  // @ts-ignore
6058
- typeof ((_b = value == null ? void 0 : value.collection) == null ? void 0 : _b.name) === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
6038
+ typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
6059
6039
  // @ts-ignore
6060
- Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
6061
- typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
6040
+ Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
6041
+ typeof args.filter[value?.collection?.name] !== "undefined"
6062
6042
  ) {
6063
6043
  filter = args.filter[value.collection.name];
6064
6044
  }
@@ -6195,15 +6175,15 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
6195
6175
  };
6196
6176
 
6197
6177
  // src/database/index.ts
6198
- var import_node_path = __toESM(require("path"));
6178
+ var import_node_path = __toESM(require("node:path"));
6199
6179
  var import_graphql6 = require("graphql");
6200
6180
  var import_micromatch2 = __toESM(require("micromatch"));
6201
6181
  var import_js_sha12 = __toESM(require("js-sha1"));
6202
6182
  var import_lodash5 = __toESM(require("lodash.set"));
6203
6183
  var createLocalDatabase = (config) => {
6204
- const level = new TinaLevelClient(config == null ? void 0 : config.port);
6184
+ const level = new TinaLevelClient(config?.port);
6205
6185
  level.openConnection();
6206
- const fsBridge = new FilesystemBridge((config == null ? void 0 : config.rootPath) || process.cwd());
6186
+ const fsBridge = new FilesystemBridge(config?.rootPath || process.cwd());
6207
6187
  return new Database({
6208
6188
  bridge: fsBridge,
6209
6189
  ...config || {},
@@ -6276,7 +6256,7 @@ var Database = class {
6276
6256
  );
6277
6257
  }
6278
6258
  const metadata = await metadataLevel.get(`metadata_${key}`);
6279
- return metadata == null ? void 0 : metadata.value;
6259
+ return metadata?.value;
6280
6260
  };
6281
6261
  this.setMetadata = async (key, value) => {
6282
6262
  await this.initLevel();
@@ -6298,7 +6278,7 @@ var Database = class {
6298
6278
  let level = this.contentLevel;
6299
6279
  if (this.appLevel) {
6300
6280
  collection = await this.collectionForPath(filepath);
6301
- if (collection == null ? void 0 : collection.isDetached) {
6281
+ if (collection?.isDetached) {
6302
6282
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6303
6283
  }
6304
6284
  }
@@ -6317,7 +6297,6 @@ var Database = class {
6317
6297
  }
6318
6298
  };
6319
6299
  this.addPendingDocument = async (filepath, data) => {
6320
- var _a;
6321
6300
  await this.initLevel();
6322
6301
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6323
6302
  const collection = await this.collectionForPath(filepath);
@@ -6330,10 +6309,10 @@ var Database = class {
6330
6309
  collection
6331
6310
  );
6332
6311
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
6333
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
6334
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
6312
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
6313
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
6335
6314
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6336
- if (!(collection == null ? void 0 : collection.isDetached)) {
6315
+ if (!collection?.isDetached) {
6337
6316
  if (this.bridge) {
6338
6317
  await this.bridge.put(normalizedPath, stringifiedFile);
6339
6318
  }
@@ -6351,7 +6330,7 @@ var Database = class {
6351
6330
  }
6352
6331
  }
6353
6332
  let level = this.contentLevel;
6354
- if (collection == null ? void 0 : collection.isDetached) {
6333
+ if (collection?.isDetached) {
6355
6334
  level = this.appLevel.sublevel(collection.name, SUBLEVEL_OPTIONS);
6356
6335
  }
6357
6336
  const folderTreeBuilder = new FolderTreeBuilder();
@@ -6362,7 +6341,7 @@ var Database = class {
6362
6341
  putOps = [
6363
6342
  ...makeRefOpsForDocument(
6364
6343
  normalizedPath,
6365
- collection == null ? void 0 : collection.name,
6344
+ collection?.name,
6366
6345
  collectionReferences,
6367
6346
  dataFields,
6368
6347
  "put",
@@ -6370,7 +6349,7 @@ var Database = class {
6370
6349
  ),
6371
6350
  ...makeIndexOpsForDocument(
6372
6351
  normalizedPath,
6373
- collection == null ? void 0 : collection.name,
6352
+ collection?.name,
6374
6353
  collectionIndexDefinitions,
6375
6354
  dataFields,
6376
6355
  "put",
@@ -6379,7 +6358,7 @@ var Database = class {
6379
6358
  // folder indices
6380
6359
  ...makeIndexOpsForDocument(
6381
6360
  normalizedPath,
6382
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6361
+ `${collection?.name}_${folderKey}`,
6383
6362
  collectionIndexDefinitions,
6384
6363
  dataFields,
6385
6364
  "put",
@@ -6393,7 +6372,7 @@ var Database = class {
6393
6372
  delOps = existingItem ? [
6394
6373
  ...makeRefOpsForDocument(
6395
6374
  normalizedPath,
6396
- collection == null ? void 0 : collection.name,
6375
+ collection?.name,
6397
6376
  collectionReferences,
6398
6377
  existingItem,
6399
6378
  "del",
@@ -6401,7 +6380,7 @@ var Database = class {
6401
6380
  ),
6402
6381
  ...makeIndexOpsForDocument(
6403
6382
  normalizedPath,
6404
- collection == null ? void 0 : collection.name,
6383
+ collection?.name,
6405
6384
  collectionIndexDefinitions,
6406
6385
  existingItem,
6407
6386
  "del",
@@ -6410,7 +6389,7 @@ var Database = class {
6410
6389
  // folder indices
6411
6390
  ...makeIndexOpsForDocument(
6412
6391
  normalizedPath,
6413
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6392
+ `${collection?.name}_${folderKey}`,
6414
6393
  collectionIndexDefinitions,
6415
6394
  existingItem,
6416
6395
  "del",
@@ -6434,7 +6413,6 @@ var Database = class {
6434
6413
  await level.batch(ops);
6435
6414
  };
6436
6415
  this.put = async (filepath, data, collectionName) => {
6437
- var _a, _b, _c;
6438
6416
  await this.initLevel();
6439
6417
  try {
6440
6418
  if (SYSTEM_FILES.includes(filepath)) {
@@ -6445,16 +6423,16 @@ var Database = class {
6445
6423
  const indexDefinitions = await this.getIndexDefinitions(
6446
6424
  this.contentLevel
6447
6425
  );
6448
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
6426
+ collectionIndexDefinitions = indexDefinitions?.[collectionName];
6449
6427
  }
6450
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collectionName];
6428
+ const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
6451
6429
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6452
6430
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6453
6431
  const collection = await this.collectionForPath(filepath);
6454
6432
  if (!collection) {
6455
6433
  throw new import_graphql6.GraphQLError(`Unable to find collection for ${filepath}.`);
6456
6434
  }
6457
- if (((_b = collection.match) == null ? void 0 : _b.exclude) || ((_c = collection.match) == null ? void 0 : _c.include)) {
6435
+ if (collection.match?.exclude || collection.match?.include) {
6458
6436
  const matches = this.tinaSchema.getMatches({ collection });
6459
6437
  const match = import_micromatch2.default.isMatch(filepath, matches);
6460
6438
  if (!match) {
@@ -6468,7 +6446,7 @@ var Database = class {
6468
6446
  const stringifiedFile = filepath.endsWith(
6469
6447
  `.gitkeep.${collection.format || "md"}`
6470
6448
  ) ? "" : await this.stringifyFile(filepath, dataFields, collection);
6471
- if (!(collection == null ? void 0 : collection.isDetached)) {
6449
+ if (!collection?.isDetached) {
6472
6450
  if (this.bridge) {
6473
6451
  await this.bridge.put(normalizedPath, stringifiedFile);
6474
6452
  }
@@ -6490,7 +6468,7 @@ var Database = class {
6490
6468
  filepath,
6491
6469
  collection.path || ""
6492
6470
  );
6493
- const level = (collection == null ? void 0 : collection.isDetached) ? this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6471
+ const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6494
6472
  let putOps = [];
6495
6473
  let delOps = [];
6496
6474
  if (!isGitKeep(normalizedPath, collection)) {
@@ -6514,7 +6492,7 @@ var Database = class {
6514
6492
  // folder indices
6515
6493
  ...makeIndexOpsForDocument(
6516
6494
  normalizedPath,
6517
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6495
+ `${collection?.name}_${folderKey}`,
6518
6496
  collectionIndexDefinitions,
6519
6497
  dataFields,
6520
6498
  "put",
@@ -6545,7 +6523,7 @@ var Database = class {
6545
6523
  // folder indices
6546
6524
  ...makeIndexOpsForDocument(
6547
6525
  normalizedPath,
6548
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
6526
+ `${collection?.name}_${folderKey}`,
6549
6527
  collectionIndexDefinitions,
6550
6528
  existingItem,
6551
6529
  "del",
@@ -6622,8 +6600,8 @@ var Database = class {
6622
6600
  writeTemplateKey,
6623
6601
  //templateInfo.type === 'union',
6624
6602
  {
6625
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6626
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
6603
+ frontmatterFormat: collection?.frontmatterFormat,
6604
+ frontmatterDelimiters: collection?.frontmatterDelimiters
6627
6605
  }
6628
6606
  );
6629
6607
  };
@@ -6792,8 +6770,8 @@ var Database = class {
6792
6770
  );
6793
6771
  return {
6794
6772
  name: indexField.name,
6795
- type: field == null ? void 0 : field.type,
6796
- list: !!(field == null ? void 0 : field.list)
6773
+ type: field?.type,
6774
+ list: !!field?.list
6797
6775
  };
6798
6776
  })
6799
6777
  };
@@ -6819,7 +6797,6 @@ var Database = class {
6819
6797
  return true;
6820
6798
  };
6821
6799
  this.query = async (queryOptions, hydrator) => {
6822
- var _a;
6823
6800
  await this.initLevel();
6824
6801
  const {
6825
6802
  first,
@@ -6847,14 +6824,14 @@ var Database = class {
6847
6824
  const allIndexDefinitions = await this.getIndexDefinitions(
6848
6825
  this.contentLevel
6849
6826
  );
6850
- const indexDefinitions = allIndexDefinitions == null ? void 0 : allIndexDefinitions[collection.name];
6827
+ const indexDefinitions = allIndexDefinitions?.[collection.name];
6851
6828
  if (!indexDefinitions) {
6852
6829
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
6853
6830
  }
6854
6831
  const filterChain = coerceFilterChainOperands(rawFilterChain);
6855
- const indexDefinition = sort && (indexDefinitions == null ? void 0 : indexDefinitions[sort]);
6832
+ const indexDefinition = sort && indexDefinitions?.[sort];
6856
6833
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
6857
- const level = (collection == null ? void 0 : collection.isDetached) ? this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6834
+ const level = collection?.isDetached ? this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS) : this.contentLevel;
6858
6835
  const rootLevel = level.sublevel(
6859
6836
  CONTENT_ROOT_PREFIX,
6860
6837
  SUBLEVEL_OPTIONS
@@ -6864,17 +6841,17 @@ var Database = class {
6864
6841
  SUBLEVEL_OPTIONS
6865
6842
  ).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
6866
6843
  if (!query.gt && !query.gte) {
6867
- query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
6844
+ query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
6868
6845
  }
6869
6846
  if (!query.lt && !query.lte) {
6870
- query.lte = (filterSuffixes == null ? void 0 : filterSuffixes.right) ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6847
+ query.lte = filterSuffixes?.right ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
6871
6848
  }
6872
6849
  let edges = [];
6873
6850
  let startKey = "";
6874
6851
  let endKey = "";
6875
6852
  let hasPreviousPage = false;
6876
6853
  let hasNextPage = false;
6877
- const fieldsPattern = ((_a = indexDefinition == null ? void 0 : indexDefinition.fields) == null ? void 0 : _a.length) ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
6854
+ const fieldsPattern = indexDefinition?.fields?.length ? `${indexDefinition.fields.map((p) => `(?<${p.name}>.+)${INDEX_KEY_FIELD_SEPARATOR}`).join("")}` : "";
6878
6855
  const valuesRegex = indexDefinition ? new RegExp(`^${fieldsPattern}(?<_filepath_>.+)`) : new RegExp(`^(?<_filepath_>.+)`);
6879
6856
  const itemFilter = makeFilter({ filterChain });
6880
6857
  const iterator = sublevel.iterator(query);
@@ -7086,18 +7063,17 @@ var Database = class {
7086
7063
  }
7087
7064
  };
7088
7065
  this.delete = async (filepath) => {
7089
- var _a;
7090
7066
  await this.initLevel();
7091
7067
  const collection = await this.collectionForPath(filepath);
7092
7068
  if (!collection) {
7093
7069
  throw new Error(`No collection found for path: ${filepath}`);
7094
7070
  }
7095
7071
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
7096
- const collectionReferences = (_a = await this.getCollectionReferences()) == null ? void 0 : _a[collection.name];
7097
- const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7072
+ const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
7073
+ const collectionIndexDefinitions = indexDefinitions?.[collection.name];
7098
7074
  let level = this.contentLevel;
7099
- if (collection == null ? void 0 : collection.isDetached) {
7100
- level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
7075
+ if (collection?.isDetached) {
7076
+ level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
7101
7077
  }
7102
7078
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
7103
7079
  const rootSublevel = level.sublevel(
@@ -7144,7 +7120,7 @@ var Database = class {
7144
7120
  }
7145
7121
  ]);
7146
7122
  }
7147
- if (!(collection == null ? void 0 : collection.isDetached)) {
7123
+ if (!collection?.isDetached) {
7148
7124
  if (this.bridge) {
7149
7125
  await this.bridge.delete(normalizedPath);
7150
7126
  }
@@ -7239,7 +7215,7 @@ var Database = class {
7239
7215
  );
7240
7216
  }
7241
7217
  const metadata = await metadataLevel.get("metadata");
7242
- return metadata == null ? void 0 : metadata.version;
7218
+ return metadata?.version;
7243
7219
  }
7244
7220
  async initLevel() {
7245
7221
  if (this.contentLevel) {
@@ -7325,7 +7301,7 @@ var hashPasswordVisitor = async (node, path7) => {
7325
7301
  };
7326
7302
  var visitNodes = async (node, path7, callback) => {
7327
7303
  const [currentLevel, ...remainingLevels] = path7;
7328
- if (!(remainingLevels == null ? void 0 : remainingLevels.length)) {
7304
+ if (!remainingLevels?.length) {
7329
7305
  return callback(node, path7);
7330
7306
  }
7331
7307
  if (Array.isArray(node[currentLevel])) {
@@ -7341,7 +7317,7 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
7341
7317
  async (passwordField) => visitNodes(data, passwordField, hashPasswordVisitor)
7342
7318
  )
7343
7319
  );
7344
- var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${(collection == null ? void 0 : collection.format) || "md"}`);
7320
+ var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
7345
7321
  var _indexContent = async ({
7346
7322
  database,
7347
7323
  level,
@@ -7351,18 +7327,17 @@ var _indexContent = async ({
7351
7327
  passwordFields,
7352
7328
  isPartialReindex
7353
7329
  }) => {
7354
- var _a;
7355
7330
  let collectionIndexDefinitions;
7356
7331
  let collectionPath;
7357
7332
  if (collection) {
7358
7333
  const indexDefinitions = await database.getIndexDefinitions(level);
7359
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7334
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7360
7335
  if (!collectionIndexDefinitions) {
7361
7336
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7362
7337
  }
7363
7338
  collectionPath = collection.path;
7364
7339
  }
7365
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7340
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7366
7341
  const tinaSchema = await database.getSchema();
7367
7342
  let templateInfo = null;
7368
7343
  if (collection) {
@@ -7380,7 +7355,7 @@ var _indexContent = async ({
7380
7355
  if (!aliasedData) {
7381
7356
  return;
7382
7357
  }
7383
- if (passwordFields == null ? void 0 : passwordFields.length) {
7358
+ if (passwordFields?.length) {
7384
7359
  await hashPasswordValues(aliasedData, passwordFields);
7385
7360
  }
7386
7361
  const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
@@ -7398,7 +7373,7 @@ var _indexContent = async ({
7398
7373
  await database.contentLevel.batch([
7399
7374
  ...makeRefOpsForDocument(
7400
7375
  normalizedPath,
7401
- collection == null ? void 0 : collection.name,
7376
+ collection?.name,
7402
7377
  collectionReferences,
7403
7378
  item,
7404
7379
  "del",
@@ -7433,7 +7408,7 @@ var _indexContent = async ({
7433
7408
  await enqueueOps([
7434
7409
  ...makeRefOpsForDocument(
7435
7410
  normalizedPath,
7436
- collection == null ? void 0 : collection.name,
7411
+ collection?.name,
7437
7412
  collectionReferences,
7438
7413
  aliasedData,
7439
7414
  "put",
@@ -7441,7 +7416,7 @@ var _indexContent = async ({
7441
7416
  ),
7442
7417
  ...makeIndexOpsForDocument(
7443
7418
  normalizedPath,
7444
- collection == null ? void 0 : collection.name,
7419
+ collection?.name,
7445
7420
  collectionIndexDefinitions,
7446
7421
  aliasedData,
7447
7422
  "put",
@@ -7450,7 +7425,7 @@ var _indexContent = async ({
7450
7425
  // folder indexes
7451
7426
  ...makeIndexOpsForDocument(
7452
7427
  normalizedPath,
7453
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7428
+ `${collection?.name}_${folderKey}`,
7454
7429
  collectionIndexDefinitions,
7455
7430
  aliasedData,
7456
7431
  "put",
@@ -7471,7 +7446,7 @@ var _indexContent = async ({
7471
7446
  throw new TinaFetchError(`Unable to seed ${filepath}`, {
7472
7447
  originalError: error,
7473
7448
  file: filepath,
7474
- collection: collection == null ? void 0 : collection.name,
7449
+ collection: collection?.name,
7475
7450
  stack: error.stack
7476
7451
  });
7477
7452
  }
@@ -7489,7 +7464,6 @@ var _indexContent = async ({
7489
7464
  }
7490
7465
  };
7491
7466
  var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
7492
- var _a;
7493
7467
  if (!documentPaths.length) {
7494
7468
  return;
7495
7469
  }
@@ -7498,12 +7472,12 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7498
7472
  const indexDefinitions = await database.getIndexDefinitions(
7499
7473
  database.contentLevel
7500
7474
  );
7501
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
7475
+ collectionIndexDefinitions = indexDefinitions?.[collection.name];
7502
7476
  if (!collectionIndexDefinitions) {
7503
7477
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
7504
7478
  }
7505
7479
  }
7506
- const collectionReferences = (_a = await database.getCollectionReferences()) == null ? void 0 : _a[collection == null ? void 0 : collection.name];
7480
+ const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
7507
7481
  const tinaSchema = await database.getSchema();
7508
7482
  let templateInfo = null;
7509
7483
  if (collection) {
@@ -7520,7 +7494,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7520
7494
  if (item) {
7521
7495
  const folderKey = folderTreeBuilder.update(
7522
7496
  itemKey,
7523
- (collection == null ? void 0 : collection.path) || ""
7497
+ collection?.path || ""
7524
7498
  );
7525
7499
  const aliasedData = templateInfo ? replaceNameOverrides(
7526
7500
  getTemplateForFile(templateInfo, item),
@@ -7529,7 +7503,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7529
7503
  await enqueueOps([
7530
7504
  ...makeRefOpsForDocument(
7531
7505
  itemKey,
7532
- collection == null ? void 0 : collection.name,
7506
+ collection?.name,
7533
7507
  collectionReferences,
7534
7508
  aliasedData,
7535
7509
  "del",
@@ -7546,7 +7520,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
7546
7520
  // folder indexes
7547
7521
  ...makeIndexOpsForDocument(
7548
7522
  itemKey,
7549
- `${collection == null ? void 0 : collection.name}_${folderKey}`,
7523
+ `${collection?.name}_${folderKey}`,
7550
7524
  collectionIndexDefinitions,
7551
7525
  aliasedData,
7552
7526
  "del",
@@ -7631,12 +7605,12 @@ var getChangedFiles = async ({
7631
7605
  }
7632
7606
  }
7633
7607
  }
7634
- if (await (B == null ? void 0 : B.type()) === "tree") {
7608
+ if (await B?.type() === "tree") {
7635
7609
  return;
7636
7610
  }
7637
7611
  if (matches) {
7638
- const oidA = await (A == null ? void 0 : A.oid());
7639
- const oidB = await (B == null ? void 0 : B.oid());
7612
+ const oidA = await A?.oid();
7613
+ const oidB = await B?.oid();
7640
7614
  if (oidA !== oidB) {
7641
7615
  if (oidA === void 0) {
7642
7616
  results.added.push(relativePath);
@@ -7664,8 +7638,8 @@ var import_path5 = __toESM(require("path"));
7664
7638
  var import_normalize_path = __toESM(require("normalize-path"));
7665
7639
  var FilesystemBridge = class {
7666
7640
  constructor(rootPath, outputPath) {
7667
- this.rootPath = rootPath || "";
7668
- this.outputPath = outputPath || rootPath;
7641
+ this.rootPath = import_path5.default.resolve(rootPath);
7642
+ this.outputPath = outputPath ? import_path5.default.resolve(outputPath) : this.rootPath;
7669
7643
  }
7670
7644
  async glob(pattern, extension) {
7671
7645
  const basePath = import_path5.default.join(this.outputPath, ...pattern.split("/"));
@@ -7677,19 +7651,19 @@ var FilesystemBridge = class {
7677
7651
  }
7678
7652
  );
7679
7653
  const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
7680
- return items.map((item) => {
7681
- return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
7682
- });
7654
+ return items.map(
7655
+ (item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
7656
+ );
7683
7657
  }
7684
7658
  async delete(filepath) {
7685
7659
  await import_fs_extra2.default.remove(import_path5.default.join(this.outputPath, filepath));
7686
7660
  }
7687
7661
  async get(filepath) {
7688
- return import_fs_extra2.default.readFileSync(import_path5.default.join(this.outputPath, filepath)).toString();
7662
+ return (await import_fs_extra2.default.readFile(import_path5.default.join(this.outputPath, filepath))).toString();
7689
7663
  }
7690
7664
  async put(filepath, data, basePathOverride) {
7691
7665
  const basePath = basePathOverride || this.outputPath;
7692
- await import_fs_extra2.default.outputFileSync(import_path5.default.join(basePath, filepath), data);
7666
+ await import_fs_extra2.default.outputFile(import_path5.default.join(basePath, filepath), data);
7693
7667
  }
7694
7668
  };
7695
7669
  var AuditFileSystemBridge = class extends FilesystemBridge {
package/dist/index.mjs CHANGED
@@ -3019,7 +3019,7 @@ var validateField = async (field) => {
3019
3019
  // package.json
3020
3020
  var package_default = {
3021
3021
  name: "@tinacms/graphql",
3022
- version: "1.5.17",
3022
+ version: "1.5.18",
3023
3023
  main: "dist/index.js",
3024
3024
  module: "dist/index.mjs",
3025
3025
  typings: "dist/index.d.ts",
@@ -7576,8 +7576,8 @@ import path6 from "path";
7576
7576
  import normalize from "normalize-path";
7577
7577
  var FilesystemBridge = class {
7578
7578
  constructor(rootPath, outputPath) {
7579
- this.rootPath = rootPath || "";
7580
- this.outputPath = outputPath || rootPath;
7579
+ this.rootPath = path6.resolve(rootPath);
7580
+ this.outputPath = outputPath ? path6.resolve(outputPath) : this.rootPath;
7581
7581
  }
7582
7582
  async glob(pattern, extension) {
7583
7583
  const basePath = path6.join(this.outputPath, ...pattern.split("/"));
@@ -7589,19 +7589,19 @@ var FilesystemBridge = class {
7589
7589
  }
7590
7590
  );
7591
7591
  const posixRootPath = normalize(this.outputPath);
7592
- return items.map((item) => {
7593
- return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
7594
- });
7592
+ return items.map(
7593
+ (item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
7594
+ );
7595
7595
  }
7596
7596
  async delete(filepath) {
7597
7597
  await fs2.remove(path6.join(this.outputPath, filepath));
7598
7598
  }
7599
7599
  async get(filepath) {
7600
- return fs2.readFileSync(path6.join(this.outputPath, filepath)).toString();
7600
+ return (await fs2.readFile(path6.join(this.outputPath, filepath))).toString();
7601
7601
  }
7602
7602
  async put(filepath, data, basePathOverride) {
7603
7603
  const basePath = basePathOverride || this.outputPath;
7604
- await fs2.outputFileSync(path6.join(basePath, filepath), data);
7604
+ await fs2.outputFile(path6.join(basePath, filepath), data);
7605
7605
  }
7606
7606
  };
7607
7607
  var AuditFileSystemBridge = class extends FilesystemBridge {
@@ -74,10 +74,10 @@ export declare class Resolver {
74
74
  name: string;
75
75
  }[];
76
76
  }[];
77
- format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "yml" | "toml";
77
+ format?: import("@tinacms/schema-tools").ContentFormat;
78
78
  ui?: import("@tinacms/schema-tools").UICollection;
79
79
  defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
80
- frontmatterFormat?: "yaml" | "toml" | "json";
80
+ frontmatterFormat?: import("@tinacms/schema-tools").ContentFrontmatterFormat;
81
81
  frontmatterDelimiters?: [string, string] | string;
82
82
  match?: {
83
83
  include?: string;
@@ -102,10 +102,10 @@ export declare class Resolver {
102
102
  name: string;
103
103
  }[];
104
104
  }[];
105
- format?: "json" | "md" | "markdown" | "mdx" | "yaml" | "yml" | "toml";
105
+ format?: import("@tinacms/schema-tools").ContentFormat;
106
106
  ui?: import("@tinacms/schema-tools").UICollection;
107
107
  defaultItem?: import("@tinacms/schema-tools").DefaultItem<Record<string, any>>;
108
- frontmatterFormat?: "yaml" | "toml" | "json";
108
+ frontmatterFormat?: import("@tinacms/schema-tools").ContentFrontmatterFormat;
109
109
  frontmatterDelimiters?: [string, string] | string;
110
110
  match?: {
111
111
  include?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinacms/graphql",
3
- "version": "1.5.17",
3
+ "version": "1.5.18",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "typings": "dist/index.d.ts",
@@ -44,8 +44,8 @@
44
44
  "readable-stream": "^4.7.0",
45
45
  "scmp": "^2.1.0",
46
46
  "yup": "^0.32.11",
47
- "@tinacms/mdx": "1.6.2",
48
- "@tinacms/schema-tools": "1.7.3"
47
+ "@tinacms/mdx": "1.6.3",
48
+ "@tinacms/schema-tools": "1.7.4"
49
49
  },
50
50
  "publishConfig": {
51
51
  "registry": "https://registry.npmjs.org"
@@ -75,8 +75,8 @@
75
75
  "vite": "^4.5.9",
76
76
  "vitest": "^0.32.4",
77
77
  "zod": "^3.24.2",
78
- "@tinacms/schema-tools": "1.7.3",
79
- "@tinacms/scripts": "1.3.4"
78
+ "@tinacms/schema-tools": "1.7.4",
79
+ "@tinacms/scripts": "1.3.5"
80
80
  },
81
81
  "scripts": {
82
82
  "types": "pnpm tsc",