@tinacms/graphql 1.3.3 → 1.3.4

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.
Files changed (3) hide show
  1. package/dist/index.es.js +1095 -527
  2. package/dist/index.js +1320 -726
  3. package/package.json +4 -4
package/dist/index.es.js CHANGED
@@ -124,11 +124,11 @@ var SysFieldDefinition = {
124
124
  };
125
125
  var astBuilder = {
126
126
  FormFieldBuilder: ({
127
- name: name2,
127
+ name,
128
128
  additionalFields
129
129
  }) => {
130
130
  return astBuilder.ObjectTypeDefinition({
131
- name: name2,
131
+ name,
132
132
  interfaces: [astBuilder.NamedType({ name: "FormField" })],
133
133
  fields: [
134
134
  astBuilder.FieldDefinition({
@@ -151,14 +151,14 @@ var astBuilder = {
151
151
  });
152
152
  },
153
153
  ScalarTypeDefinition: ({
154
- name: name2,
154
+ name,
155
155
  description
156
156
  }) => {
157
157
  return {
158
158
  kind: "ScalarTypeDefinition",
159
159
  name: {
160
160
  kind: "Name",
161
- value: name2
161
+ value: name
162
162
  },
163
163
  description: {
164
164
  kind: "StringValue",
@@ -168,7 +168,7 @@ var astBuilder = {
168
168
  };
169
169
  },
170
170
  InputValueDefinition: ({
171
- name: name2,
171
+ name,
172
172
  type,
173
173
  list,
174
174
  required
@@ -185,7 +185,7 @@ var astBuilder = {
185
185
  kind: "InputValueDefinition",
186
186
  name: {
187
187
  kind: "Name",
188
- value: name2
188
+ value: name
189
189
  }
190
190
  };
191
191
  if (list) {
@@ -246,17 +246,17 @@ var astBuilder = {
246
246
  };
247
247
  },
248
248
  FieldNodeDefinition: ({
249
- name: name2,
249
+ name,
250
250
  type,
251
251
  args = [],
252
252
  list,
253
253
  required
254
254
  }) => ({
255
- name: { kind: "Name", value: name2 },
255
+ name: { kind: "Name", value: name },
256
256
  kind: "Field"
257
257
  }),
258
258
  FieldDefinition: ({
259
- name: name2,
259
+ name,
260
260
  type,
261
261
  args = [],
262
262
  list,
@@ -274,7 +274,7 @@ var astBuilder = {
274
274
  kind: "FieldDefinition",
275
275
  name: {
276
276
  kind: "Name",
277
- value: name2
277
+ value: name
278
278
  },
279
279
  arguments: args
280
280
  };
@@ -321,7 +321,7 @@ var astBuilder = {
321
321
  return res;
322
322
  },
323
323
  InterfaceTypeDefinition: ({
324
- name: name2,
324
+ name,
325
325
  fields,
326
326
  description = ""
327
327
  }) => {
@@ -330,7 +330,7 @@ var astBuilder = {
330
330
  description: { kind: "StringValue", value: description },
331
331
  name: {
332
332
  kind: "Name",
333
- value: name2
333
+ value: name
334
334
  },
335
335
  interfaces: [],
336
336
  directives: [],
@@ -338,45 +338,45 @@ var astBuilder = {
338
338
  };
339
339
  },
340
340
  InputObjectTypeDefinition: ({
341
- name: name2,
341
+ name,
342
342
  fields
343
343
  }) => ({
344
344
  kind: "InputObjectTypeDefinition",
345
345
  name: {
346
346
  kind: "Name",
347
- value: name2
347
+ value: name
348
348
  },
349
349
  fields
350
350
  }),
351
351
  UnionTypeDefinition: ({
352
- name: name2,
352
+ name,
353
353
  types
354
354
  }) => ({
355
355
  kind: "UnionTypeDefinition",
356
356
  name: {
357
357
  kind: "Name",
358
- value: name2
358
+ value: name
359
359
  },
360
360
  directives: [],
361
- types: types.map((name3) => ({
361
+ types: types.map((name2) => ({
362
362
  kind: "NamedType",
363
363
  name: {
364
364
  kind: "Name",
365
- value: name3
365
+ value: name2
366
366
  }
367
367
  }))
368
368
  }),
369
- NamedType: ({ name: name2 }) => {
369
+ NamedType: ({ name }) => {
370
370
  return {
371
371
  kind: "NamedType",
372
372
  name: {
373
373
  kind: "Name",
374
- value: name2
374
+ value: name
375
375
  }
376
376
  };
377
377
  },
378
378
  ObjectTypeDefinition: ({
379
- name: name2,
379
+ name,
380
380
  fields,
381
381
  interfaces = [],
382
382
  directives = [],
@@ -387,16 +387,16 @@ var astBuilder = {
387
387
  directives,
388
388
  name: {
389
389
  kind: "Name",
390
- value: name2
390
+ value: name
391
391
  },
392
392
  fields
393
393
  }),
394
394
  FieldWithSelectionSetDefinition: ({
395
- name: name2,
395
+ name,
396
396
  selections
397
397
  }) => {
398
398
  return {
399
- name: { kind: "Name", value: name2 },
399
+ name: { kind: "Name", value: name },
400
400
  kind: "Field",
401
401
  selectionSet: {
402
402
  kind: "SelectionSet",
@@ -405,7 +405,7 @@ var astBuilder = {
405
405
  };
406
406
  },
407
407
  InlineFragmentDefinition: ({
408
- name: name2,
408
+ name,
409
409
  selections
410
410
  }) => {
411
411
  return {
@@ -418,13 +418,13 @@ var astBuilder = {
418
418
  kind: "NamedType",
419
419
  name: {
420
420
  kind: "Name",
421
- value: name2
421
+ value: name
422
422
  }
423
423
  }
424
424
  };
425
425
  },
426
426
  FragmentDefinition: ({
427
- name: name2,
427
+ name,
428
428
  fragmentName,
429
429
  selections
430
430
  }) => {
@@ -438,7 +438,7 @@ var astBuilder = {
438
438
  kind: "NamedType",
439
439
  name: {
440
440
  kind: "Name",
441
- value: name2
441
+ value: name
442
442
  }
443
443
  },
444
444
  directives: [],
@@ -937,11 +937,14 @@ var astBuilder = {
937
937
  };
938
938
  },
939
939
  toGraphQLAst: (ast) => {
940
- const definitions = _.uniqBy([
941
- ...extractInlineTypes(ast.query),
942
- ...extractInlineTypes(ast.globalTemplates),
943
- ...ast.definitions
944
- ], (field) => field.name.value);
940
+ const definitions = _.uniqBy(
941
+ [
942
+ ...extractInlineTypes(ast.query),
943
+ ...extractInlineTypes(ast.globalTemplates),
944
+ ...ast.definitions
945
+ ],
946
+ (field) => field.name.value
947
+ );
945
948
  return {
946
949
  kind: "Document",
947
950
  definitions
@@ -975,7 +978,7 @@ var extractInlineTypes = (item) => {
975
978
  return accumulator;
976
979
  }
977
980
  };
978
- function* walk(maybeNode, visited = new WeakSet()) {
981
+ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
979
982
  if (typeof maybeNode === "string") {
980
983
  return;
981
984
  }
@@ -1266,7 +1269,7 @@ var Builder = class {
1266
1269
  constructor(config) {
1267
1270
  this.config = config;
1268
1271
  this.buildCollectionDefinition = async (collections) => {
1269
- const name2 = "collection";
1272
+ const name = "collection";
1270
1273
  const typeName = "Collection";
1271
1274
  const args = [
1272
1275
  astBuilder.InputValueDefinition({
@@ -1329,23 +1332,23 @@ var Builder = class {
1329
1332
  });
1330
1333
  return astBuilder.FieldDefinition({
1331
1334
  type,
1332
- name: name2,
1335
+ name,
1333
1336
  args,
1334
1337
  required: true
1335
1338
  });
1336
1339
  };
1337
1340
  this.buildMultiCollectionDefinition = async (collections) => {
1338
- const name2 = "collections";
1341
+ const name = "collections";
1339
1342
  const typeName = "Collection";
1340
1343
  return astBuilder.FieldDefinition({
1341
1344
  type: typeName,
1342
- name: name2,
1345
+ name,
1343
1346
  list: true,
1344
1347
  required: true
1345
1348
  });
1346
1349
  };
1347
1350
  this.multiNodeDocument = async () => {
1348
- const name2 = "node";
1351
+ const name = "node";
1349
1352
  const args = [
1350
1353
  astBuilder.InputValueDefinition({
1351
1354
  name: "id",
@@ -1357,7 +1360,7 @@ var Builder = class {
1357
1360
  resolveType: "nodeDocument"
1358
1361
  });
1359
1362
  return astBuilder.FieldDefinition({
1360
- name: name2,
1363
+ name,
1361
1364
  args,
1362
1365
  list: false,
1363
1366
  type: astBuilder.TYPES.Node,
@@ -1365,7 +1368,7 @@ var Builder = class {
1365
1368
  });
1366
1369
  };
1367
1370
  this.multiCollectionDocument = async (collections) => {
1368
- const name2 = "document";
1371
+ const name = "document";
1369
1372
  const args = [
1370
1373
  astBuilder.InputValueDefinition({
1371
1374
  name: "collection",
@@ -1381,7 +1384,7 @@ var Builder = class {
1381
1384
  collections
1382
1385
  });
1383
1386
  return astBuilder.FieldDefinition({
1384
- name: name2,
1387
+ name,
1385
1388
  args,
1386
1389
  list: false,
1387
1390
  type,
@@ -1486,7 +1489,7 @@ var Builder = class {
1486
1489
  });
1487
1490
  };
1488
1491
  this.collectionDocument = async (collection) => {
1489
- const name2 = NAMER.queryName([collection.name]);
1492
+ const name = NAMER.queryName([collection.name]);
1490
1493
  const type = await this._buildCollectionDocumentType(collection);
1491
1494
  const args = [
1492
1495
  astBuilder.InputValueDefinition({
@@ -1501,14 +1504,17 @@ var Builder = class {
1501
1504
  [NAMER.createName([collection.name])]: "create",
1502
1505
  [NAMER.updateName([collection.name])]: "update"
1503
1506
  });
1504
- return astBuilder.FieldDefinition({ type, name: name2, args, required: true });
1507
+ return astBuilder.FieldDefinition({ type, name, args, required: true });
1505
1508
  };
1506
1509
  this.collectionFragment = async (collection) => {
1507
- const name2 = NAMER.dataTypeName(collection.namespace);
1510
+ const name = NAMER.dataTypeName(collection.namespace);
1508
1511
  const fragmentName = NAMER.fragmentName(collection.namespace);
1509
- const selections = await this._getCollectionFragmentSelections(collection, 0);
1512
+ const selections = await this._getCollectionFragmentSelections(
1513
+ collection,
1514
+ 0
1515
+ );
1510
1516
  return astBuilder.FragmentDefinition({
1511
- name: name2,
1517
+ name,
1512
1518
  fragmentName,
1513
1519
  selections: filterSelections(selections)
1514
1520
  });
@@ -1588,7 +1594,12 @@ var Builder = class {
1588
1594
  directives: [],
1589
1595
  selectionSet: {
1590
1596
  kind: "SelectionSet",
1591
- selections: filterSelections(await this._getCollectionFragmentSelections(collection, depth + 1))
1597
+ selections: filterSelections(
1598
+ await this._getCollectionFragmentSelections(
1599
+ collection,
1600
+ depth + 1
1601
+ )
1602
+ )
1592
1603
  }
1593
1604
  });
1594
1605
  });
@@ -1683,30 +1694,35 @@ var Builder = class {
1683
1694
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
1684
1695
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
1685
1696
  if (templateInfo.type === "union") {
1686
- return this._buildObjectOrUnionData({
1687
- ...templateInfo
1688
- }, [
1689
- astBuilder.FieldDefinition({
1690
- name: "id",
1691
- required: true,
1692
- type: astBuilder.TYPES.ID
1693
- }),
1694
- astBuilder.FieldDefinition({
1695
- name: "_sys",
1696
- required: true,
1697
- type: astBuilder.TYPES.SystemInfo
1698
- }),
1699
- ...extraFields,
1700
- astBuilder.FieldDefinition({
1701
- name: "_values",
1702
- required: true,
1703
- type: "JSON"
1704
- })
1705
- ], [
1706
- astBuilder.NamedType({ name: astBuilder.TYPES.Node }),
1707
- astBuilder.NamedType({ name: astBuilder.TYPES.Document }),
1708
- ...extraInterfaces
1709
- ], collection);
1697
+ return this._buildObjectOrUnionData(
1698
+ {
1699
+ ...templateInfo
1700
+ },
1701
+ [
1702
+ astBuilder.FieldDefinition({
1703
+ name: "id",
1704
+ required: true,
1705
+ type: astBuilder.TYPES.ID
1706
+ }),
1707
+ astBuilder.FieldDefinition({
1708
+ name: "_sys",
1709
+ required: true,
1710
+ type: astBuilder.TYPES.SystemInfo
1711
+ }),
1712
+ ...extraFields,
1713
+ astBuilder.FieldDefinition({
1714
+ name: "_values",
1715
+ required: true,
1716
+ type: "JSON"
1717
+ })
1718
+ ],
1719
+ [
1720
+ astBuilder.NamedType({ name: astBuilder.TYPES.Node }),
1721
+ astBuilder.NamedType({ name: astBuilder.TYPES.Document }),
1722
+ ...extraInterfaces
1723
+ ],
1724
+ collection
1725
+ );
1710
1726
  }
1711
1727
  const fields = templateInfo.template.fields;
1712
1728
  const templateFields = await sequential(fields, async (field) => {
@@ -1995,7 +2011,9 @@ var Builder = class {
1995
2011
  const filter = await this._connectionFilterBuilder({
1996
2012
  fieldName: field.name,
1997
2013
  namespace: field.namespace,
1998
- collections: await this.tinaSchema.getCollectionsByName(field.collections)
2014
+ collections: await this.tinaSchema.getCollectionsByName(
2015
+ field.collections
2016
+ )
1999
2017
  });
2000
2018
  return astBuilder.InputValueDefinition({
2001
2019
  name: field.name,
@@ -2051,25 +2069,33 @@ var Builder = class {
2051
2069
  this._buildReferenceMutation = async (field) => {
2052
2070
  return astBuilder.InputObjectTypeDefinition({
2053
2071
  name: NAMER.dataMutationTypeName(field.namespace),
2054
- fields: await sequential(this.tinaSchema.getCollectionsByName(field.collections), async (collection) => {
2072
+ fields: await sequential(
2073
+ this.tinaSchema.getCollectionsByName(field.collections),
2074
+ async (collection) => {
2075
+ return astBuilder.InputValueDefinition({
2076
+ name: collection.name,
2077
+ type: NAMER.dataMutationTypeName([collection.name])
2078
+ });
2079
+ }
2080
+ )
2081
+ });
2082
+ };
2083
+ this._buildUpdateDocumentMutationParams = async (field) => {
2084
+ const fields = await sequential(
2085
+ this.tinaSchema.getCollectionsByName(field.collections),
2086
+ async (collection) => {
2055
2087
  return astBuilder.InputValueDefinition({
2056
2088
  name: collection.name,
2057
2089
  type: NAMER.dataMutationTypeName([collection.name])
2058
2090
  });
2091
+ }
2092
+ );
2093
+ fields.push(
2094
+ astBuilder.InputValueDefinition({
2095
+ name: "relativePath",
2096
+ type: astBuilder.TYPES.String
2059
2097
  })
2060
- });
2061
- };
2062
- this._buildUpdateDocumentMutationParams = async (field) => {
2063
- const fields = await sequential(this.tinaSchema.getCollectionsByName(field.collections), async (collection) => {
2064
- return astBuilder.InputValueDefinition({
2065
- name: collection.name,
2066
- type: NAMER.dataMutationTypeName([collection.name])
2067
- });
2068
- });
2069
- fields.push(astBuilder.InputValueDefinition({
2070
- name: "relativePath",
2071
- type: astBuilder.TYPES.String
2072
- }));
2098
+ );
2073
2099
  return astBuilder.InputObjectTypeDefinition({
2074
2100
  name: NAMER.dataMutationUpdateTypeName(field.namespace),
2075
2101
  fields
@@ -2077,20 +2103,27 @@ var Builder = class {
2077
2103
  };
2078
2104
  this._buildObjectOrUnionData = async (collectableTemplate, extraFields = [], extraInterfaces = [], collection) => {
2079
2105
  if (collectableTemplate.type === "union") {
2080
- const name2 = NAMER.dataTypeName(collectableTemplate.namespace);
2106
+ const name = NAMER.dataTypeName(collectableTemplate.namespace);
2081
2107
  const typeMap = {};
2082
- const types = await sequential(collectableTemplate.templates, async (template) => {
2083
- const type = await this._buildTemplateData(template, extraFields, extraInterfaces);
2084
- typeMap[template.namespace[template.namespace.length - 1]] = type.name.value;
2085
- return type;
2086
- });
2108
+ const types = await sequential(
2109
+ collectableTemplate.templates,
2110
+ async (template) => {
2111
+ const type = await this._buildTemplateData(
2112
+ template,
2113
+ extraFields,
2114
+ extraInterfaces
2115
+ );
2116
+ typeMap[template.namespace[template.namespace.length - 1]] = type.name.value;
2117
+ return type;
2118
+ }
2119
+ );
2087
2120
  await this.database.addToLookupMap({
2088
- type: name2,
2121
+ type: name,
2089
2122
  resolveType: "unionData",
2090
2123
  collection: collection?.name,
2091
2124
  typeMap
2092
2125
  });
2093
- return astBuilder.UnionTypeDefinition({ name: name2, types });
2126
+ return astBuilder.UnionTypeDefinition({ name, types });
2094
2127
  }
2095
2128
  return this._buildTemplateData(collectableTemplate.template);
2096
2129
  };
@@ -2120,7 +2153,9 @@ var Builder = class {
2120
2153
  type: await this._filterCollectionDocumentType(collection)
2121
2154
  });
2122
2155
  } else {
2123
- throw new Error(`Must provide either collection or collections to filter field builder`);
2156
+ throw new Error(
2157
+ `Must provide either collection or collections to filter field builder`
2158
+ );
2124
2159
  }
2125
2160
  return filter;
2126
2161
  };
@@ -2205,7 +2240,9 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2205
2240
  name: field.name,
2206
2241
  list: field.list,
2207
2242
  required: field.required,
2208
- type: await this._buildObjectOrUnionData(this.tinaSchema.getTemplatesForCollectable(field))
2243
+ type: await this._buildObjectOrUnionData(
2244
+ this.tinaSchema.getTemplatesForCollectable(field)
2245
+ )
2209
2246
  });
2210
2247
  case "rich-text":
2211
2248
  return astBuilder.FieldDefinition({
@@ -2215,23 +2252,29 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2215
2252
  type: astBuilder.TYPES.JSON
2216
2253
  });
2217
2254
  case "reference":
2218
- const name2 = NAMER.documentTypeName(field.namespace);
2255
+ const name = NAMER.documentTypeName(field.namespace);
2219
2256
  if (field.list) {
2220
2257
  console.warn(listWarningMsg);
2221
2258
  return this._buildMultiCollectionDocumentListDefinition({
2222
2259
  fieldName: field.name,
2223
2260
  namespace: field.namespace,
2224
2261
  nodeType: astBuilder.UnionTypeDefinition({
2225
- name: name2,
2226
- types: field.collections.map((collectionName) => NAMER.documentTypeName([collectionName]))
2262
+ name,
2263
+ types: field.collections.map(
2264
+ (collectionName) => NAMER.documentTypeName([collectionName])
2265
+ )
2227
2266
  }),
2228
- collections: this.tinaSchema.getCollectionsByName(field.collections),
2267
+ collections: this.tinaSchema.getCollectionsByName(
2268
+ field.collections
2269
+ ),
2229
2270
  connectionNamespace: field.namespace
2230
2271
  });
2231
2272
  } else {
2232
2273
  const type = await this._buildMultiCollectionDocumentDefinition({
2233
- fieldName: name2,
2234
- collections: this.tinaSchema.getCollectionsByName(field.collections)
2274
+ fieldName: name,
2275
+ collections: this.tinaSchema.getCollectionsByName(
2276
+ field.collections
2277
+ )
2235
2278
  });
2236
2279
  return astBuilder.FieldDefinition({
2237
2280
  name: field.name,
@@ -2304,10 +2347,7 @@ import { TinaSchema } from "@tinacms/schema-tools";
2304
2347
 
2305
2348
  // src/schema/validate.ts
2306
2349
  import _2 from "lodash";
2307
- import {
2308
- object,
2309
- string
2310
- } from "yup";
2350
+ import * as yup2 from "yup";
2311
2351
  import {
2312
2352
  validateTinaCloudSchemaConfig
2313
2353
  } from "@tinacms/schema-tools";
@@ -2322,8 +2362,13 @@ var FIELD_TYPES = [
2322
2362
  "rich-text"
2323
2363
  ];
2324
2364
  var validateSchema = async (schema) => {
2325
- const schema2 = addNamespaceToSchema(_2.cloneDeep(schema));
2326
- const collections = await sequential(schema2.collections, async (collection) => validateCollection(collection));
2365
+ const schema2 = addNamespaceToSchema(
2366
+ _2.cloneDeep(schema)
2367
+ );
2368
+ const collections = await sequential(
2369
+ schema2.collections,
2370
+ async (collection) => validateCollection(collection)
2371
+ );
2327
2372
  validationCollectionsPathAndMatch(collections);
2328
2373
  if (schema2.config) {
2329
2374
  const config = validateTinaCloudSchemaConfig(schema2.config);
@@ -2357,7 +2402,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2357
2402
  r[a.path] = r[a.path] || [];
2358
2403
  r[a.path].push(a);
2359
2404
  return r;
2360
- }, Object.create(null));
2405
+ }, /* @__PURE__ */ Object.create(null));
2361
2406
  Object.keys(groupbyPath).forEach((key) => {
2362
2407
  const collectionsArr = groupbyPath[key];
2363
2408
  if (collectionsArr.length === 1) {
@@ -2375,26 +2420,31 @@ var validateCollection = async (collection) => {
2375
2420
  let templates = [];
2376
2421
  let fields = [];
2377
2422
  const messageName = collection.namespace.join(".");
2378
- const collectionSchema = object({
2379
- name: string().matches(/^[a-zA-Z0-9_]*$/, {
2423
+ const collectionSchema = yup2.object({
2424
+ name: yup2.string().matches(/^[a-zA-Z0-9_]*$/, {
2380
2425
  message: (obj) => `Collection's "name" must match ${obj.regex} at ${messageName}`
2381
2426
  }).required(),
2382
- path: string().required().transform((value) => {
2427
+ path: yup2.string().required().transform((value) => {
2383
2428
  return value.replace(/^\/|\/$/g, "");
2384
2429
  })
2385
2430
  });
2386
2431
  await collectionSchema.validate(collection);
2387
- const validCollection = await collectionSchema.cast(collection);
2432
+ const validCollection = await collectionSchema.cast(
2433
+ collection
2434
+ );
2388
2435
  if (validCollection.templates) {
2389
- templates = await sequential(validCollection.templates, async (template) => {
2390
- const fields2 = await sequential(template.fields, async (field) => {
2391
- return validateField(field);
2392
- });
2393
- return {
2394
- ...validCollection,
2395
- ...fields2
2396
- };
2397
- });
2436
+ templates = await sequential(
2437
+ validCollection.templates,
2438
+ async (template) => {
2439
+ const fields2 = await sequential(template.fields, async (field) => {
2440
+ return validateField(field);
2441
+ });
2442
+ return {
2443
+ ...validCollection,
2444
+ ...fields2
2445
+ };
2446
+ }
2447
+ );
2398
2448
  }
2399
2449
  if (validCollection.fields) {
2400
2450
  if (typeof validCollection.fields === "string") {
@@ -2412,11 +2462,14 @@ var validateCollection = async (collection) => {
2412
2462
  };
2413
2463
  var validateField = async (field) => {
2414
2464
  const messageName = field.namespace.join(".");
2415
- const schema = object({
2416
- name: string().matches(/^[a-zA-Z0-9_]*$/, {
2465
+ const schema = yup2.object({
2466
+ name: yup2.string().matches(/^[a-zA-Z0-9_]*$/, {
2417
2467
  message: (obj) => `Field's 'name' must match ${obj.regex} at ${messageName}`
2418
2468
  }).required(),
2419
- type: string().oneOf(FIELD_TYPES, (obj) => `'type' must be one of: ${obj.values}, but got '${obj.value}' at ${messageName}`)
2469
+ type: yup2.string().oneOf(
2470
+ FIELD_TYPES,
2471
+ (obj) => `'type' must be one of: ${obj.values}, but got '${obj.value}' at ${messageName}`
2472
+ )
2420
2473
  });
2421
2474
  await schema.validate(field);
2422
2475
  const validField = await schema.cast(field);
@@ -2424,137 +2477,123 @@ var validateField = async (field) => {
2424
2477
  };
2425
2478
 
2426
2479
  // package.json
2427
- var name = "@tinacms/graphql";
2428
- var version = "1.3.3";
2429
- var main = "dist/index.js";
2430
- var module = "dist/index.es.js";
2431
- var typings = "dist/index.d.ts";
2432
- var files = [
2433
- "package.json",
2434
- "dist"
2435
- ];
2436
- var exports = {
2437
- import: "./dist/index.es.js",
2438
- require: "./dist/index.js"
2439
- };
2440
- var license = "SEE LICENSE IN LICENSE";
2441
- var buildConfig = {
2442
- entryPoints: [
2443
- {
2444
- name: "src/index.ts",
2445
- target: "node",
2446
- bundle: []
2447
- }
2448
- ]
2449
- };
2450
- var scripts = {
2451
- types: "pnpm tsc",
2452
- build: "tinacms-scripts build",
2453
- docs: "yarn typedoc",
2454
- serve: "yarn nodemon dist/server.js",
2455
- test: "jest",
2456
- "test-watch": "jest --watch"
2457
- };
2458
- var dependencies = {
2459
- "@graphql-tools/relay-operation-optimizer": "^6.4.1",
2460
- "@iarna/toml": "^2.2.5",
2461
- "@tinacms/mdx": "workspace:*",
2462
- "@tinacms/schema-tools": "workspace:*",
2463
- "abstract-level": "^1.0.3",
2464
- "body-parser": "^1.19.0",
2465
- cors: "^2.8.5",
2466
- dataloader: "^2.0.0",
2467
- "date-fns": "^2.21.1",
2468
- "encoding-down": "^7.1.0",
2469
- esbuild: "^0.12.25",
2470
- "esbuild-jest": "^0.5.0",
2471
- "estree-walker": "^3.0.0",
2472
- "fast-glob": "^3.2.5",
2473
- flat: "^5.0.2",
2474
- "fs-extra": "^9.0.1",
2475
- "glob-parent": "^6.0.2",
2476
- graphql: "15.8.0",
2477
- "graphql-type-json": "^0.3.2",
2478
- "gray-matter": "^4.0.2",
2479
- "isomorphic-git": "^1.21.0",
2480
- "js-yaml": "^3.14.1",
2481
- "jsonpath-plus": "^6.0.1",
2482
- leveldown: "^6.1.0",
2483
- lodash: "^4.17.20",
2484
- "many-level": "^2.0.0",
2485
- mdast: "^3.0.0",
2486
- "mdast-util-from-markdown": "^1.0.0",
2487
- "mdast-util-mdx": "^1.1.0",
2488
- "mdast-util-mdx-expression": "^1.1.0",
2489
- "mdast-util-to-markdown": "^1.2.1",
2490
- "micromark-extension-mdxjs": "^1.0.0",
2491
- "normalize-path": "^3.0.0",
2492
- prettier: "^2.2.1",
2493
- "readable-stream": "^4.3.0",
2494
- "rehype-format": "^3.1.0",
2495
- "rehype-stringify": "^8.0.0",
2496
- remark: "^13.0.0",
2497
- "remark-frontmatter": "^3.0.0",
2498
- "remark-mdx": "next",
2499
- "remark-parse": "^10.0.0",
2500
- "remark-rehype": "^8.0.0",
2501
- "remark-slate": "^1.8.0",
2502
- "remark-stringify": "^8.1.1",
2503
- unified: "^10.1.0",
2504
- "unist-util-remove-position": "^3.0.0",
2505
- "unist-util-visit": "^4.0.0",
2506
- vfile: "^4.2.0",
2507
- ws: "^7.3.1",
2508
- yup: "^0.32.9"
2509
- };
2510
- var publishConfig = {
2511
- registry: "https://registry.npmjs.org"
2512
- };
2513
- var repository = {
2514
- url: "https://github.com/tinacms/tinacms.git",
2515
- directory: "packages/tina-graphql"
2516
- };
2517
- var devDependencies = {
2518
- "@tinacms/schema-tools": "workspace:*",
2519
- "@tinacms/scripts": "workspace:*",
2520
- "@types/cors": "^2.8.7",
2521
- "@types/estree": "^0.0.50",
2522
- "@types/express": "^4.17.8",
2523
- "@types/fs-extra": "^9.0.2",
2524
- "@types/jest": "^26.0.4",
2525
- "@types/js-yaml": "^3.12.5",
2526
- "@types/lodash": "^4.14.161",
2527
- "@types/lodash.camelcase": "^4.3.6",
2528
- "@types/lodash.upperfirst": "^4.3.6",
2529
- "@types/lru-cache": "^5.1.0",
2530
- "@types/mdast": "^3.0.10",
2531
- "@types/node": "^14.17.34",
2532
- "@types/normalize-path": "^3.0.0",
2533
- "@types/ws": "^7.2.6",
2534
- "@types/yup": "^0.29.7",
2535
- jest: "27.0.6",
2536
- "jest-diff": "27.0.6",
2537
- "jest-file-snapshot": "^0.5.0",
2538
- "jest-matcher-utils": "27.0.6",
2539
- "memory-level": "^1.0.0",
2540
- nodemon: "2.0.19",
2541
- typescript: "4.3.5"
2542
- };
2543
2480
  var package_default = {
2544
- name,
2545
- version,
2546
- main,
2547
- module,
2548
- typings,
2549
- files,
2550
- exports,
2551
- license,
2552
- buildConfig,
2553
- scripts,
2554
- dependencies,
2555
- publishConfig,
2556
- repository,
2557
- devDependencies
2481
+ name: "@tinacms/graphql",
2482
+ version: "1.3.4",
2483
+ main: "dist/index.js",
2484
+ module: "dist/index.es.js",
2485
+ typings: "dist/index.d.ts",
2486
+ files: [
2487
+ "package.json",
2488
+ "dist"
2489
+ ],
2490
+ exports: {
2491
+ import: "./dist/index.es.js",
2492
+ require: "./dist/index.js"
2493
+ },
2494
+ license: "SEE LICENSE IN LICENSE",
2495
+ buildConfig: {
2496
+ entryPoints: [
2497
+ {
2498
+ name: "src/index.ts",
2499
+ target: "node",
2500
+ bundle: []
2501
+ }
2502
+ ]
2503
+ },
2504
+ scripts: {
2505
+ types: "pnpm tsc",
2506
+ build: "tinacms-scripts build",
2507
+ docs: "yarn typedoc",
2508
+ serve: "yarn nodemon dist/server.js",
2509
+ test: "jest",
2510
+ "test-watch": "jest --watch"
2511
+ },
2512
+ dependencies: {
2513
+ "@graphql-tools/relay-operation-optimizer": "^6.4.1",
2514
+ "@iarna/toml": "^2.2.5",
2515
+ "@tinacms/mdx": "workspace:*",
2516
+ "@tinacms/schema-tools": "workspace:*",
2517
+ "abstract-level": "^1.0.3",
2518
+ "body-parser": "^1.19.0",
2519
+ cors: "^2.8.5",
2520
+ dataloader: "^2.0.0",
2521
+ "date-fns": "^2.21.1",
2522
+ "encoding-down": "^7.1.0",
2523
+ esbuild: "^0.15.5",
2524
+ "esbuild-jest": "^0.5.0",
2525
+ "estree-walker": "^3.0.0",
2526
+ "fast-glob": "^3.2.5",
2527
+ flat: "^5.0.2",
2528
+ "fs-extra": "^9.0.1",
2529
+ "glob-parent": "^6.0.2",
2530
+ graphql: "15.8.0",
2531
+ "graphql-type-json": "^0.3.2",
2532
+ "gray-matter": "^4.0.2",
2533
+ "isomorphic-git": "^1.21.0",
2534
+ "js-yaml": "^3.14.1",
2535
+ "jsonpath-plus": "^6.0.1",
2536
+ leveldown: "^6.1.0",
2537
+ lodash: "^4.17.20",
2538
+ "many-level": "^2.0.0",
2539
+ mdast: "^3.0.0",
2540
+ "mdast-util-from-markdown": "^1.0.0",
2541
+ "mdast-util-mdx": "^1.1.0",
2542
+ "mdast-util-mdx-expression": "^1.1.0",
2543
+ "mdast-util-to-markdown": "^1.2.1",
2544
+ "micromark-extension-mdxjs": "^1.0.0",
2545
+ "normalize-path": "^3.0.0",
2546
+ prettier: "^2.2.1",
2547
+ "readable-stream": "^4.3.0",
2548
+ "rehype-format": "^3.1.0",
2549
+ "rehype-stringify": "^8.0.0",
2550
+ remark: "^13.0.0",
2551
+ "remark-frontmatter": "^3.0.0",
2552
+ "remark-mdx": "next",
2553
+ "remark-parse": "^10.0.0",
2554
+ "remark-rehype": "^8.0.0",
2555
+ "remark-slate": "^1.8.0",
2556
+ "remark-stringify": "^8.1.1",
2557
+ unified: "^10.1.0",
2558
+ "unist-util-remove-position": "^3.0.0",
2559
+ "unist-util-visit": "^4.0.0",
2560
+ vfile: "^4.2.0",
2561
+ ws: "^7.3.1",
2562
+ yup: "^0.32.9"
2563
+ },
2564
+ publishConfig: {
2565
+ registry: "https://registry.npmjs.org"
2566
+ },
2567
+ repository: {
2568
+ url: "https://github.com/tinacms/tinacms.git",
2569
+ directory: "packages/tina-graphql"
2570
+ },
2571
+ devDependencies: {
2572
+ "@tinacms/schema-tools": "workspace:*",
2573
+ "@tinacms/scripts": "workspace:*",
2574
+ "@types/cors": "^2.8.7",
2575
+ "@types/estree": "^0.0.50",
2576
+ "@types/express": "^4.17.8",
2577
+ "@types/fs-extra": "^9.0.2",
2578
+ "@types/jest": "^26.0.4",
2579
+ "@types/js-yaml": "^3.12.5",
2580
+ "@types/lodash": "^4.14.161",
2581
+ "@types/lodash.camelcase": "^4.3.6",
2582
+ "@types/lodash.upperfirst": "^4.3.6",
2583
+ "@types/lru-cache": "^5.1.0",
2584
+ "@types/mdast": "^3.0.10",
2585
+ "@types/node": "^14.17.34",
2586
+ "@types/normalize-path": "^3.0.0",
2587
+ "@types/ws": "^7.2.6",
2588
+ "@types/yup": "^0.29.7",
2589
+ jest: "27.0.6",
2590
+ "jest-diff": "27.0.6",
2591
+ "jest-file-snapshot": "^0.5.0",
2592
+ "jest-matcher-utils": "27.0.6",
2593
+ "memory-level": "^1.0.0",
2594
+ nodemon: "2.0.19",
2595
+ typescript: "4.3.5"
2596
+ }
2558
2597
  };
2559
2598
 
2560
2599
  // src/schema/createSchema.ts
@@ -2601,7 +2640,9 @@ var buildDotTinaFiles = async ({
2601
2640
  graphQLSchema = await _buildSchema(builder, tinaSchema);
2602
2641
  await database.putConfigFiles({ graphQLSchema, tinaSchema });
2603
2642
  } else {
2604
- graphQLSchema = JSON.parse(await database.bridge.get(".tina/__generated__/_graphql.json"));
2643
+ graphQLSchema = JSON.parse(
2644
+ await database.bridge.get(".tina/__generated__/_graphql.json")
2645
+ );
2605
2646
  }
2606
2647
  if (buildSDK) {
2607
2648
  await _buildFragments(builder, tinaSchema, database.bridge.rootPath);
@@ -2613,25 +2654,34 @@ var _buildFragments = async (builder, tinaSchema, rootPath) => {
2613
2654
  const fragmentDefinitionsFields = [];
2614
2655
  const collections = tinaSchema.getCollections();
2615
2656
  await sequential(collections, async (collection) => {
2616
- const frag = await builder.collectionFragment(collection);
2657
+ const frag = await builder.collectionFragment(
2658
+ collection
2659
+ );
2617
2660
  fragmentDefinitionsFields.push(frag);
2618
2661
  });
2619
2662
  const fragDoc = {
2620
2663
  kind: "Document",
2621
- definitions: _3.uniqBy(extractInlineTypes(fragmentDefinitionsFields), (node) => node.name.value)
2664
+ definitions: _3.uniqBy(
2665
+ extractInlineTypes(fragmentDefinitionsFields),
2666
+ (node) => node.name.value
2667
+ )
2622
2668
  };
2623
2669
  const fragPath = path.join(rootPath, ".tina", "__generated__");
2624
2670
  await fs.outputFile(path.join(fragPath, "frags.gql"), print(fragDoc));
2625
2671
  if (await (await fs.stat(path.join(fragPath, "frags.gql"))).size > 100 * 1024) {
2626
- console.warn("Warning: frags.gql is very large (>100kb). Consider setting the reference depth to 1 or 0. See code snippet below.");
2627
- console.log(`const schema = defineSchema({
2672
+ console.warn(
2673
+ "Warning: frags.gql is very large (>100kb). Consider setting the reference depth to 1 or 0. See code snippet below."
2674
+ );
2675
+ console.log(
2676
+ `const schema = defineSchema({
2628
2677
  config: {
2629
2678
  client: {
2630
2679
  referenceDepth: 1,
2631
2680
  },
2632
2681
  }
2633
2682
  // ...
2634
- })`);
2683
+ })`
2684
+ );
2635
2685
  }
2636
2686
  };
2637
2687
  var _buildQueries = async (builder, tinaSchema, rootPath) => {
@@ -2642,17 +2692,26 @@ var _buildQueries = async (builder, tinaSchema, rootPath) => {
2642
2692
  const queryListName = NAMER.generateQueryListName(collection.namespace);
2643
2693
  const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
2644
2694
  const fragName = NAMER.fragmentName(collection.namespace);
2645
- operationsDefinitions.push(astBuilder.QueryOperationDefinition({ fragName, queryName }));
2646
- operationsDefinitions.push(astBuilder.ListQueryOperationDefinition({
2647
- fragName,
2648
- queryName: queryListName,
2649
- filterType: queryFilterTypeName,
2650
- dataLayer: Boolean(tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData"))
2651
- }));
2695
+ operationsDefinitions.push(
2696
+ astBuilder.QueryOperationDefinition({ fragName, queryName })
2697
+ );
2698
+ operationsDefinitions.push(
2699
+ astBuilder.ListQueryOperationDefinition({
2700
+ fragName,
2701
+ queryName: queryListName,
2702
+ filterType: queryFilterTypeName,
2703
+ dataLayer: Boolean(
2704
+ tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
2705
+ )
2706
+ })
2707
+ );
2652
2708
  });
2653
2709
  const queryDoc = {
2654
2710
  kind: "Document",
2655
- definitions: _3.uniqBy(extractInlineTypes(operationsDefinitions), (node) => node.name.value)
2711
+ definitions: _3.uniqBy(
2712
+ extractInlineTypes(operationsDefinitions),
2713
+ (node) => node.name.value
2714
+ )
2656
2715
  };
2657
2716
  const fragPath = path.join(rootPath, ".tina", "__generated__");
2658
2717
  await fs.outputFile(path.join(fragPath, "queries.gql"), print(queryDoc));
@@ -2663,42 +2722,71 @@ var _buildSchema = async (builder, tinaSchema) => {
2663
2722
  const queryTypeDefinitionFields = [];
2664
2723
  const mutationTypeDefinitionFields = [];
2665
2724
  const collections = tinaSchema.getCollections();
2666
- queryTypeDefinitionFields.push(astBuilder.FieldDefinition({
2667
- name: "getOptimizedQuery",
2668
- args: [
2669
- astBuilder.InputValueDefinition({
2670
- name: "queryString",
2671
- type: astBuilder.TYPES.String,
2672
- required: true
2673
- })
2674
- ],
2675
- type: astBuilder.TYPES.String
2676
- }));
2677
- queryTypeDefinitionFields.push(await builder.buildCollectionDefinition(collections));
2678
- queryTypeDefinitionFields.push(await builder.buildMultiCollectionDefinition(collections));
2725
+ queryTypeDefinitionFields.push(
2726
+ astBuilder.FieldDefinition({
2727
+ name: "getOptimizedQuery",
2728
+ args: [
2729
+ astBuilder.InputValueDefinition({
2730
+ name: "queryString",
2731
+ type: astBuilder.TYPES.String,
2732
+ required: true
2733
+ })
2734
+ ],
2735
+ type: astBuilder.TYPES.String
2736
+ })
2737
+ );
2738
+ queryTypeDefinitionFields.push(
2739
+ await builder.buildCollectionDefinition(collections)
2740
+ );
2741
+ queryTypeDefinitionFields.push(
2742
+ await builder.buildMultiCollectionDefinition(collections)
2743
+ );
2679
2744
  queryTypeDefinitionFields.push(await builder.multiNodeDocument());
2680
- queryTypeDefinitionFields.push(await builder.multiCollectionDocument(collections));
2681
- mutationTypeDefinitionFields.push(await builder.addMultiCollectionDocumentMutation());
2682
- mutationTypeDefinitionFields.push(await builder.buildUpdateCollectionDocumentMutation(collections));
2683
- mutationTypeDefinitionFields.push(await builder.buildDeleteCollectionDocumentMutation(collections));
2684
- mutationTypeDefinitionFields.push(await builder.buildCreateCollectionDocumentMutation(collections));
2745
+ queryTypeDefinitionFields.push(
2746
+ await builder.multiCollectionDocument(collections)
2747
+ );
2748
+ mutationTypeDefinitionFields.push(
2749
+ await builder.addMultiCollectionDocumentMutation()
2750
+ );
2751
+ mutationTypeDefinitionFields.push(
2752
+ await builder.buildUpdateCollectionDocumentMutation(collections)
2753
+ );
2754
+ mutationTypeDefinitionFields.push(
2755
+ await builder.buildDeleteCollectionDocumentMutation(collections)
2756
+ );
2757
+ mutationTypeDefinitionFields.push(
2758
+ await builder.buildCreateCollectionDocumentMutation(collections)
2759
+ );
2685
2760
  await sequential(collections, async (collection) => {
2686
2761
  queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
2687
- mutationTypeDefinitionFields.push(await builder.updateCollectionDocumentMutation(collection));
2688
- mutationTypeDefinitionFields.push(await builder.createCollectionDocumentMutation(collection));
2689
- queryTypeDefinitionFields.push(await builder.collectionDocumentList(collection));
2762
+ mutationTypeDefinitionFields.push(
2763
+ await builder.updateCollectionDocumentMutation(collection)
2764
+ );
2765
+ mutationTypeDefinitionFields.push(
2766
+ await builder.createCollectionDocumentMutation(collection)
2767
+ );
2768
+ queryTypeDefinitionFields.push(
2769
+ await builder.collectionDocumentList(collection)
2770
+ );
2690
2771
  });
2691
- definitions.push(astBuilder.ObjectTypeDefinition({
2692
- name: "Query",
2693
- fields: queryTypeDefinitionFields
2694
- }));
2695
- definitions.push(astBuilder.ObjectTypeDefinition({
2696
- name: "Mutation",
2697
- fields: mutationTypeDefinitionFields
2698
- }));
2772
+ definitions.push(
2773
+ astBuilder.ObjectTypeDefinition({
2774
+ name: "Query",
2775
+ fields: queryTypeDefinitionFields
2776
+ })
2777
+ );
2778
+ definitions.push(
2779
+ astBuilder.ObjectTypeDefinition({
2780
+ name: "Mutation",
2781
+ fields: mutationTypeDefinitionFields
2782
+ })
2783
+ );
2699
2784
  const doc = {
2700
2785
  kind: "Document",
2701
- definitions: _3.uniqBy(extractInlineTypes(definitions), (node) => node.name.value)
2786
+ definitions: _3.uniqBy(
2787
+ extractInlineTypes(definitions),
2788
+ (node) => node.name.value
2789
+ )
2702
2790
  };
2703
2791
  return doc;
2704
2792
  };
@@ -2742,12 +2830,18 @@ var TinaFetchError = class extends Error {
2742
2830
  };
2743
2831
  var TinaQueryError = class extends TinaFetchError {
2744
2832
  constructor(args) {
2745
- super(`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2833
+ super(
2834
+ `Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
2835
+ args
2836
+ );
2746
2837
  }
2747
2838
  };
2748
2839
  var TinaParseDocumentError = class extends TinaFetchError {
2749
2840
  constructor(args) {
2750
- super(`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2841
+ super(
2842
+ `Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
2843
+ args
2844
+ );
2751
2845
  }
2752
2846
  toString() {
2753
2847
  return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
@@ -2772,7 +2866,9 @@ var handleFetchErrorError = (e, verbose) => {
2772
2866
  // src/resolver/filter-utils.ts
2773
2867
  var resolveReferences = async (filter, fields, resolver) => {
2774
2868
  for (const fieldKey of Object.keys(filter)) {
2775
- const fieldDefinition = fields.find((f) => f.name === fieldKey);
2869
+ const fieldDefinition = fields.find(
2870
+ (f) => f.name === fieldKey
2871
+ );
2776
2872
  if (fieldDefinition) {
2777
2873
  if (fieldDefinition.type === "reference") {
2778
2874
  const { edges, values } = await resolver(filter, fieldDefinition);
@@ -2792,15 +2888,25 @@ var resolveReferences = async (filter, fields, resolver) => {
2792
2888
  } else if (fieldDefinition.type === "object") {
2793
2889
  if (fieldDefinition.templates) {
2794
2890
  for (const templateName of Object.keys(filter[fieldKey])) {
2795
- const template = fieldDefinition.templates.find((template2) => !(typeof template2 === "string") && template2.name === templateName);
2891
+ const template = fieldDefinition.templates.find(
2892
+ (template2) => !(typeof template2 === "string") && template2.name === templateName
2893
+ );
2796
2894
  if (template) {
2797
- await resolveReferences(filter[fieldKey][templateName], template.fields, resolver);
2895
+ await resolveReferences(
2896
+ filter[fieldKey][templateName],
2897
+ template.fields,
2898
+ resolver
2899
+ );
2798
2900
  } else {
2799
2901
  throw new Error(`Template ${templateName} not found`);
2800
2902
  }
2801
2903
  }
2802
2904
  } else {
2803
- await resolveReferences(filter[fieldKey], fieldDefinition.fields, resolver);
2905
+ await resolveReferences(
2906
+ filter[fieldKey],
2907
+ fieldDefinition.fields,
2908
+ resolver
2909
+ );
2804
2910
  }
2805
2911
  }
2806
2912
  } else {
@@ -2814,26 +2920,50 @@ var collectConditionsForChildFields = (filterNode, fields, pathExpression, colle
2814
2920
  if (!childField) {
2815
2921
  throw new Error(`Unable to find type for field ${childFieldName}`);
2816
2922
  }
2817
- collectConditionsForField(childFieldName, childField, filterNode[childFieldName], pathExpression, collectCondition);
2923
+ collectConditionsForField(
2924
+ childFieldName,
2925
+ childField,
2926
+ filterNode[childFieldName],
2927
+ pathExpression,
2928
+ collectCondition
2929
+ );
2818
2930
  }
2819
2931
  };
2820
2932
  var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
2821
2933
  if (field.list && field.templates) {
2822
2934
  for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
2823
- const template = field.templates.find((template2) => !(typeof template2 === "string") && template2.name === filterKey);
2935
+ const template = field.templates.find(
2936
+ (template2) => !(typeof template2 === "string") && template2.name === filterKey
2937
+ );
2824
2938
  const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
2825
2939
  const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
2826
- collectConditionsForChildFields(childFilterNode, template.fields, filterPath, collectCondition);
2940
+ collectConditionsForChildFields(
2941
+ childFilterNode,
2942
+ template.fields,
2943
+ filterPath,
2944
+ collectCondition
2945
+ );
2827
2946
  }
2828
2947
  } else {
2829
2948
  const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
2830
2949
  const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
2831
- collectConditionsForChildFields(filterNode, field.fields, filterPath, collectCondition);
2950
+ collectConditionsForChildFields(
2951
+ filterNode,
2952
+ field.fields,
2953
+ filterPath,
2954
+ collectCondition
2955
+ );
2832
2956
  }
2833
2957
  };
2834
2958
  var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
2835
2959
  if (field.type === "object") {
2836
- collectConditionsForObjectField(fieldName, field, filterNode, pathExpression, collectCondition);
2960
+ collectConditionsForObjectField(
2961
+ fieldName,
2962
+ field,
2963
+ filterNode,
2964
+ pathExpression,
2965
+ collectCondition
2966
+ );
2837
2967
  } else {
2838
2968
  collectCondition({
2839
2969
  filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
@@ -2854,7 +2984,9 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
2854
2984
  if (hasTinaMediaConfig(schema) === true) {
2855
2985
  const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
2856
2986
  if (typeof value === "string" && value.includes(assetsURL)) {
2857
- const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
2987
+ const cleanMediaRoot = cleanUpSlashes(
2988
+ schema.config.media.tina.mediaRoot
2989
+ );
2858
2990
  const strippedURL = value.replace(assetsURL, "");
2859
2991
  return `${cleanMediaRoot}${strippedURL}`;
2860
2992
  }
@@ -2928,7 +3060,10 @@ var LevelProxyHandler = {
2928
3060
  };
2929
3061
  } else if (property === "sublevel") {
2930
3062
  return (...args) => {
2931
- return new Proxy(target[property].apply(target, args), LevelProxyHandler);
3063
+ return new Proxy(
3064
+ target[property].apply(target, args),
3065
+ LevelProxyHandler
3066
+ );
2932
3067
  };
2933
3068
  } else {
2934
3069
  return (...args) => target[property].apply(target, args);
@@ -2942,22 +3077,14 @@ var LevelProxy = class {
2942
3077
  };
2943
3078
 
2944
3079
  // src/database/datalayer.ts
2945
- var OP;
2946
- (function(OP2) {
2947
- OP2["EQ"] = "eq";
2948
- OP2["GT"] = "gt";
2949
- OP2["LT"] = "lt";
2950
- OP2["GTE"] = "gte";
2951
- OP2["LTE"] = "lte";
2952
- OP2["STARTS_WITH"] = "startsWith";
2953
- OP2["IN"] = "in";
2954
- })(OP || (OP = {}));
2955
3080
  var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
2956
3081
  var DEFAULT_NUMERIC_LPAD = 4;
2957
3082
  var applyPadding = (input, pad) => {
2958
3083
  if (pad) {
2959
3084
  if (Array.isArray(input)) {
2960
- return input.map((val) => String(val).padStart(pad.maxLength, pad.fillString));
3085
+ return input.map(
3086
+ (val) => String(val).padStart(pad.maxLength, pad.fillString)
3087
+ );
2961
3088
  } else {
2962
3089
  return String(input).padStart(pad.maxLength, pad.fillString);
2963
3090
  }
@@ -2970,23 +3097,23 @@ var getFilterOperator = (expression, operand) => {
2970
3097
  var inferOperatorFromFilter = (filterOperator) => {
2971
3098
  switch (filterOperator) {
2972
3099
  case "after":
2973
- return OP.GT;
3100
+ return "gt" /* GT */;
2974
3101
  case "before":
2975
- return OP.LT;
3102
+ return "lt" /* LT */;
2976
3103
  case "eq":
2977
- return OP.EQ;
3104
+ return "eq" /* EQ */;
2978
3105
  case "startsWith":
2979
- return OP.STARTS_WITH;
3106
+ return "startsWith" /* STARTS_WITH */;
2980
3107
  case "lt":
2981
- return OP.LT;
3108
+ return "lt" /* LT */;
2982
3109
  case "lte":
2983
- return OP.LTE;
3110
+ return "lte" /* LTE */;
2984
3111
  case "gt":
2985
- return OP.GT;
3112
+ return "gt" /* GT */;
2986
3113
  case "gte":
2987
- return OP.GTE;
3114
+ return "gte" /* GTE */;
2988
3115
  case "in":
2989
- return OP.IN;
3116
+ return "in" /* IN */;
2990
3117
  default:
2991
3118
  throw new Error(`unsupported filter condition: '${filterOperator}'`);
2992
3119
  }
@@ -2996,7 +3123,9 @@ var makeKeyForField = (definition, data, stringEscaper2, maxStringLength = 100)
2996
3123
  for (const field of definition.fields) {
2997
3124
  if (field.name in data && data[field.name] !== void 0 && data[field.name] !== null) {
2998
3125
  const rawValue = data[field.name];
2999
- const resolvedValue = String(field.type === "datetime" ? new Date(rawValue).getTime() : field.type === "string" ? stringEscaper2(rawValue) : rawValue).substring(0, maxStringLength);
3126
+ const resolvedValue = String(
3127
+ field.type === "datetime" ? new Date(rawValue).getTime() : field.type === "string" ? stringEscaper2(rawValue) : rawValue
3128
+ ).substring(0, maxStringLength);
3000
3129
  valueParts.push(applyPadding(resolvedValue, field.pad));
3001
3130
  } else {
3002
3131
  return null;
@@ -3014,13 +3143,17 @@ var coerceFilterChainOperands = (filterChain, escapeString = stringEscaper) => {
3014
3143
  result.push({
3015
3144
  ...filter,
3016
3145
  rightOperand: new Date(filter.rightOperand).getTime(),
3017
- leftOperand: new Date(filter.leftOperand).getTime()
3146
+ leftOperand: new Date(
3147
+ filter.leftOperand
3148
+ ).getTime()
3018
3149
  });
3019
3150
  } else {
3020
3151
  if (Array.isArray(filter.rightOperand)) {
3021
3152
  result.push({
3022
3153
  ...filter,
3023
- rightOperand: filter.rightOperand.map((operand) => new Date(operand).getTime())
3154
+ rightOperand: filter.rightOperand.map(
3155
+ (operand) => new Date(operand).getTime()
3156
+ )
3024
3157
  });
3025
3158
  } else {
3026
3159
  result.push({
@@ -3033,13 +3166,24 @@ var coerceFilterChainOperands = (filterChain, escapeString = stringEscaper) => {
3033
3166
  if (filter.leftOperand !== void 0) {
3034
3167
  result.push({
3035
3168
  ...filter,
3036
- rightOperand: applyPadding(escapeString(filter.rightOperand), filter.pad),
3037
- leftOperand: applyPadding(escapeString(filter.leftOperand), filter.pad)
3169
+ rightOperand: applyPadding(
3170
+ escapeString(filter.rightOperand),
3171
+ filter.pad
3172
+ ),
3173
+ leftOperand: applyPadding(
3174
+ escapeString(
3175
+ filter.leftOperand
3176
+ ),
3177
+ filter.pad
3178
+ )
3038
3179
  });
3039
3180
  } else {
3040
3181
  result.push({
3041
3182
  ...filter,
3042
- rightOperand: applyPadding(escapeString(filter.rightOperand), filter.pad)
3183
+ rightOperand: applyPadding(
3184
+ escapeString(filter.rightOperand),
3185
+ filter.pad
3186
+ )
3043
3187
  });
3044
3188
  }
3045
3189
  } else {
@@ -3073,7 +3217,9 @@ var makeFilter = ({
3073
3217
  return isNaN(coerced) ? Number(resolvedValue) : coerced;
3074
3218
  });
3075
3219
  } else if (dataType === "boolean") {
3076
- operands = resolvedValues.map((resolvedValue) => typeof resolvedValue === "boolean" && resolvedValue || resolvedValue === "true" || resolvedValue === "1");
3220
+ operands = resolvedValues.map(
3221
+ (resolvedValue) => typeof resolvedValue === "boolean" && resolvedValue || resolvedValue === "true" || resolvedValue === "1"
3222
+ );
3077
3223
  } else {
3078
3224
  throw new Error(`Unexpected datatype ${dataType}`);
3079
3225
  }
@@ -3081,12 +3227,14 @@ var makeFilter = ({
3081
3227
  let matches = false;
3082
3228
  if (operator) {
3083
3229
  switch (operator) {
3084
- case OP.EQ:
3085
- if (operands.findIndex((operand) => operand === filter.rightOperand) >= 0) {
3230
+ case "eq" /* EQ */:
3231
+ if (operands.findIndex(
3232
+ (operand) => operand === filter.rightOperand
3233
+ ) >= 0) {
3086
3234
  matches = true;
3087
3235
  }
3088
3236
  break;
3089
- case OP.GT:
3237
+ case "gt" /* GT */:
3090
3238
  for (const operand of operands) {
3091
3239
  if (operand > filter.rightOperand) {
3092
3240
  matches = true;
@@ -3094,7 +3242,7 @@ var makeFilter = ({
3094
3242
  }
3095
3243
  }
3096
3244
  break;
3097
- case OP.LT:
3245
+ case "lt" /* LT */:
3098
3246
  for (const operand of operands) {
3099
3247
  if (operand < filter.rightOperand) {
3100
3248
  matches = true;
@@ -3102,7 +3250,7 @@ var makeFilter = ({
3102
3250
  }
3103
3251
  }
3104
3252
  break;
3105
- case OP.GTE:
3253
+ case "gte" /* GTE */:
3106
3254
  for (const operand of operands) {
3107
3255
  if (operand >= filter.rightOperand) {
3108
3256
  matches = true;
@@ -3110,7 +3258,7 @@ var makeFilter = ({
3110
3258
  }
3111
3259
  }
3112
3260
  break;
3113
- case OP.LTE:
3261
+ case "lte" /* LTE */:
3114
3262
  for (const operand of operands) {
3115
3263
  if (operand <= filter.rightOperand) {
3116
3264
  matches = true;
@@ -3118,7 +3266,7 @@ var makeFilter = ({
3118
3266
  }
3119
3267
  }
3120
3268
  break;
3121
- case OP.IN:
3269
+ case "in" /* IN */:
3122
3270
  for (const operand of operands) {
3123
3271
  if (filter.rightOperand.indexOf(operand) >= 0) {
3124
3272
  matches = true;
@@ -3126,7 +3274,7 @@ var makeFilter = ({
3126
3274
  }
3127
3275
  }
3128
3276
  break;
3129
- case OP.STARTS_WITH:
3277
+ case "startsWith" /* STARTS_WITH */:
3130
3278
  for (const operand of operands) {
3131
3279
  if (operand.startsWith(filter.rightOperand)) {
3132
3280
  matches = true;
@@ -3142,14 +3290,14 @@ var makeFilter = ({
3142
3290
  for (const operand of operands) {
3143
3291
  let rightMatches = false;
3144
3292
  let leftMatches = false;
3145
- if (rightOperator === OP.LTE && operand <= rightOperand) {
3293
+ if (rightOperator === "lte" /* LTE */ && operand <= rightOperand) {
3146
3294
  rightMatches = true;
3147
- } else if (rightOperator === OP.LT && operand < rightOperand) {
3295
+ } else if (rightOperator === "lt" /* LT */ && operand < rightOperand) {
3148
3296
  rightMatches = true;
3149
3297
  }
3150
- if (leftOperator === OP.GTE && operand >= leftOperand) {
3298
+ if (leftOperator === "gte" /* GTE */ && operand >= leftOperand) {
3151
3299
  leftMatches = true;
3152
- } else if (leftOperator === OP.GT && operand > leftOperand) {
3300
+ } else if (leftOperator === "gt" /* GT */ && operand > leftOperand) {
3153
3301
  leftMatches = true;
3154
3302
  }
3155
3303
  if (rightMatches && leftMatches) {
@@ -3177,7 +3325,9 @@ var makeFilterChain = ({
3177
3325
  const { _type, ...keys } = filterExpression;
3178
3326
  const [key1, key2, ...extraKeys] = Object.keys(keys);
3179
3327
  if (extraKeys.length) {
3180
- throw new Error(`Unexpected keys: [${extraKeys.join(",")}] in filter expression`);
3328
+ throw new Error(
3329
+ `Unexpected keys: [${extraKeys.join(",")}] in filter expression`
3330
+ );
3181
3331
  }
3182
3332
  if (key1 && !key2) {
3183
3333
  filterChain.push({
@@ -3210,7 +3360,9 @@ var makeFilterChain = ({
3210
3360
  pad: _type === "number" ? { fillString: "0", maxLength: DEFAULT_NUMERIC_LPAD } : void 0
3211
3361
  });
3212
3362
  } else {
3213
- throw new Error(`Filter on field '${filterPath}' has invalid combination of conditions: '${key1}, ${key2}'`);
3363
+ throw new Error(
3364
+ `Filter on field '${filterPath}' has invalid combination of conditions: '${key1}, ${key2}'`
3365
+ );
3214
3366
  }
3215
3367
  }
3216
3368
  }
@@ -3225,7 +3377,7 @@ var makeFilterSuffixes = (filterChain, index) => {
3225
3377
  if (idx === -1) {
3226
3378
  return;
3227
3379
  }
3228
- if (filter.operator && filter.operator === OP.IN) {
3380
+ if (filter.operator && filter.operator === "in" /* IN */) {
3229
3381
  return;
3230
3382
  }
3231
3383
  orderedFilterChain[idx] = filter;
@@ -3247,20 +3399,34 @@ var makeFilterSuffixes = (filterChain, index) => {
3247
3399
  return;
3248
3400
  }
3249
3401
  const binaryFilter = filter;
3250
- if (binaryFilter.operator !== OP.EQ) {
3402
+ if (binaryFilter.operator !== "eq" /* EQ */) {
3251
3403
  return;
3252
3404
  }
3253
- baseFragments.push(applyPadding(orderedFilterChain[i].rightOperand, orderedFilterChain[i].pad));
3405
+ baseFragments.push(
3406
+ applyPadding(
3407
+ orderedFilterChain[i].rightOperand,
3408
+ orderedFilterChain[i].pad
3409
+ )
3410
+ );
3254
3411
  } else {
3255
3412
  if (ternaryFilter) {
3256
- leftSuffix = applyPadding(orderedFilterChain[i].leftOperand, orderedFilterChain[i].pad);
3257
- rightSuffix = applyPadding(orderedFilterChain[i].rightOperand, orderedFilterChain[i].pad);
3413
+ leftSuffix = applyPadding(
3414
+ orderedFilterChain[i].leftOperand,
3415
+ orderedFilterChain[i].pad
3416
+ );
3417
+ rightSuffix = applyPadding(
3418
+ orderedFilterChain[i].rightOperand,
3419
+ orderedFilterChain[i].pad
3420
+ );
3258
3421
  } else {
3259
3422
  const op = orderedFilterChain[i].operator;
3260
- const operand = applyPadding(orderedFilterChain[i].rightOperand, orderedFilterChain[i].pad);
3261
- if (op === OP.LT || op === OP.LTE) {
3423
+ const operand = applyPadding(
3424
+ orderedFilterChain[i].rightOperand,
3425
+ orderedFilterChain[i].pad
3426
+ );
3427
+ if (op === "lt" /* LT */ || op === "lte" /* LTE */) {
3262
3428
  rightSuffix = operand;
3263
- } else if (op === OP.GT || op === OP.GTE) {
3429
+ } else if (op === "gt" /* GT */ || op === "gte" /* GTE */) {
3264
3430
  leftSuffix = operand;
3265
3431
  } else {
3266
3432
  rightSuffix = operand;
@@ -3308,13 +3474,18 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
3308
3474
  var makeStringEscaper = (regex, replacement) => {
3309
3475
  return (input) => {
3310
3476
  if (Array.isArray(input)) {
3311
- return input.map((val) => val.replace(regex, replacement));
3477
+ return input.map(
3478
+ (val) => val.replace(regex, replacement)
3479
+ );
3312
3480
  } else {
3313
3481
  return input.replace(regex, replacement);
3314
3482
  }
3315
3483
  };
3316
3484
  };
3317
- var stringEscaper = makeStringEscaper(new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"), encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR));
3485
+ var stringEscaper = makeStringEscaper(
3486
+ new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
3487
+ encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
3488
+ );
3318
3489
 
3319
3490
  // src/resolver/index.ts
3320
3491
  var createResolver = (args) => {
@@ -3412,22 +3583,31 @@ var Resolver = class {
3412
3583
  if (field.fields) {
3413
3584
  const objectTemplate = field;
3414
3585
  if (Array.isArray(fieldValue)) {
3415
- return fieldValue.map((item) => this.buildFieldMutations(item, objectTemplate));
3586
+ return fieldValue.map(
3587
+ (item) => this.buildFieldMutations(item, objectTemplate)
3588
+ );
3416
3589
  } else {
3417
- return this.buildFieldMutations(fieldValue, objectTemplate);
3590
+ return this.buildFieldMutations(
3591
+ fieldValue,
3592
+ objectTemplate
3593
+ );
3418
3594
  }
3419
3595
  }
3420
3596
  if (field.templates) {
3421
3597
  if (Array.isArray(fieldValue)) {
3422
3598
  return fieldValue.map((item) => {
3423
3599
  if (typeof item === "string") {
3424
- throw new Error(`Expected object for template value for field ${field.name}`);
3600
+ throw new Error(
3601
+ `Expected object for template value for field ${field.name}`
3602
+ );
3425
3603
  }
3426
3604
  const templates = field.templates.map((templateOrTemplateName) => {
3427
3605
  return templateOrTemplateName;
3428
3606
  });
3429
3607
  const [templateName] = Object.entries(item)[0];
3430
- const template = templates.find((template2) => template2.name === templateName);
3608
+ const template = templates.find(
3609
+ (template2) => template2.name === templateName
3610
+ );
3431
3611
  if (!template) {
3432
3612
  throw new Error(`Expected to find template ${templateName}`);
3433
3613
  }
@@ -3438,13 +3618,17 @@ var Resolver = class {
3438
3618
  });
3439
3619
  } else {
3440
3620
  if (typeof fieldValue === "string") {
3441
- throw new Error(`Expected object for template value for field ${field.name}`);
3621
+ throw new Error(
3622
+ `Expected object for template value for field ${field.name}`
3623
+ );
3442
3624
  }
3443
3625
  const templates = field.templates.map((templateOrTemplateName) => {
3444
3626
  return templateOrTemplateName;
3445
3627
  });
3446
3628
  const [templateName] = Object.entries(fieldValue)[0];
3447
- const template = templates.find((template2) => template2.name === templateName);
3629
+ const template = templates.find(
3630
+ (template2) => template2.name === templateName
3631
+ );
3448
3632
  if (!template) {
3449
3633
  throw new Error(`Expected to find template ${templateName}`);
3450
3634
  }
@@ -3469,12 +3653,18 @@ var Resolver = class {
3469
3653
  break;
3470
3654
  case "union":
3471
3655
  const templateString = args.template;
3472
- const template = templateInfo.templates.find((template2) => lastItem(template2.namespace) === templateString);
3656
+ const template = templateInfo.templates.find(
3657
+ (template2) => lastItem(template2.namespace) === templateString
3658
+ );
3473
3659
  if (!args.template) {
3474
- throw new Error(`Must specify a template when creating content for a collection with multiple templates. Possible templates are: ${templateInfo.templates.map((t) => lastItem(t.namespace)).join(" ")}`);
3660
+ throw new Error(
3661
+ `Must specify a template when creating content for a collection with multiple templates. Possible templates are: ${templateInfo.templates.map((t) => lastItem(t.namespace)).join(" ")}`
3662
+ );
3475
3663
  }
3476
3664
  if (!template) {
3477
- throw new Error(`Expected to find template named ${templateString} in collection "${collection.name}" but none was found. Possible templates are: ${templateInfo.templates.map((t) => lastItem(t.namespace)).join(" ")}`);
3665
+ throw new Error(
3666
+ `Expected to find template named ${templateString} in collection "${collection.name}" but none was found. Possible templates are: ${templateInfo.templates.map((t) => lastItem(t.namespace)).join(" ")}`
3667
+ );
3478
3668
  }
3479
3669
  await this.database.addPendingDocument(realPath, {
3480
3670
  _template: lastItem(template.namespace)
@@ -3482,7 +3672,10 @@ var Resolver = class {
3482
3672
  }
3483
3673
  return this.getDocument(realPath);
3484
3674
  }
3485
- const params = this.buildObjectMutations(args.params[collection.name], collection);
3675
+ const params = this.buildObjectMutations(
3676
+ args.params[collection.name],
3677
+ collection
3678
+ );
3486
3679
  await this.database.put(realPath, params, collection.name);
3487
3680
  return this.getDocument(realPath);
3488
3681
  };
@@ -3501,8 +3694,15 @@ var Resolver = class {
3501
3694
  switch (templateInfo.type) {
3502
3695
  case "object":
3503
3696
  if (params2) {
3504
- const values = this.buildFieldMutations(params2, templateInfo.template);
3505
- await this.database.put(realPath, { ...oldDoc, ...values }, collection.name);
3697
+ const values = this.buildFieldMutations(
3698
+ params2,
3699
+ templateInfo.template
3700
+ );
3701
+ await this.database.put(
3702
+ realPath,
3703
+ { ...oldDoc, ...values },
3704
+ collection.name
3705
+ );
3506
3706
  }
3507
3707
  break;
3508
3708
  case "union":
@@ -3510,7 +3710,9 @@ var Resolver = class {
3510
3710
  const templateParams = params2[lastItem(template.namespace)];
3511
3711
  if (templateParams) {
3512
3712
  if (typeof templateParams === "string") {
3513
- throw new Error(`Expected to find an object for template params, but got string`);
3713
+ throw new Error(
3714
+ `Expected to find an object for template params, but got string`
3715
+ );
3514
3716
  }
3515
3717
  const values = {
3516
3718
  ...oldDoc,
@@ -3523,7 +3725,10 @@ var Resolver = class {
3523
3725
  }
3524
3726
  return this.getDocument(realPath);
3525
3727
  }
3526
- const params = this.buildObjectMutations(isCollectionSpecific ? args.params : args.params[collection.name], collection);
3728
+ const params = this.buildObjectMutations(
3729
+ isCollectionSpecific ? args.params : args.params[collection.name],
3730
+ collection
3731
+ );
3527
3732
  await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
3528
3733
  return this.getDocument(realPath);
3529
3734
  };
@@ -3542,10 +3747,19 @@ var Resolver = class {
3542
3747
  collectionLookup = Object.keys(args.params)[0];
3543
3748
  }
3544
3749
  const collectionNames = this.tinaSchema.getCollections().map((item) => item.name);
3545
- assertShape(collectionLookup, (yup3) => {
3546
- return yup3.mixed().oneOf(collectionNames);
3547
- }, `"collection" must be one of: [${collectionNames.join(", ")}] but got ${collectionLookup}`);
3548
- assertShape(args, (yup3) => yup3.object({ relativePath: yup3.string().required() }));
3750
+ assertShape(
3751
+ collectionLookup,
3752
+ (yup3) => {
3753
+ return yup3.mixed().oneOf(collectionNames);
3754
+ },
3755
+ `"collection" must be one of: [${collectionNames.join(
3756
+ ", "
3757
+ )}] but got ${collectionLookup}`
3758
+ );
3759
+ assertShape(
3760
+ args,
3761
+ (yup3) => yup3.object({ relativePath: yup3.string().required() })
3762
+ );
3549
3763
  const collection = await this.tinaSchema.getCollection(collectionLookup);
3550
3764
  const realPath = path2.join(collection?.path, args.relativePath);
3551
3765
  const alreadyExists = await this.database.documentExists(realPath);
@@ -3563,10 +3777,14 @@ var Resolver = class {
3563
3777
  }
3564
3778
  if (!alreadyExists) {
3565
3779
  if (isDeletion) {
3566
- throw new Error(`Unable to delete document, ${realPath} does not exist`);
3780
+ throw new Error(
3781
+ `Unable to delete document, ${realPath} does not exist`
3782
+ );
3567
3783
  }
3568
3784
  if (isUpdateName) {
3569
- throw new Error(`Unable to update document, ${realPath} does not exist`);
3785
+ throw new Error(
3786
+ `Unable to update document, ${realPath} does not exist`
3787
+ );
3570
3788
  }
3571
3789
  }
3572
3790
  if (isDeletion) {
@@ -3575,10 +3793,19 @@ var Resolver = class {
3575
3793
  return doc;
3576
3794
  }
3577
3795
  if (isUpdateName) {
3578
- assertShape(args, (yup3) => yup3.object({ params: yup3.object().required() }));
3579
- assertShape(args?.params, (yup3) => yup3.object({ relativePath: yup3.string().required() }));
3796
+ assertShape(
3797
+ args,
3798
+ (yup3) => yup3.object({ params: yup3.object().required() })
3799
+ );
3800
+ assertShape(
3801
+ args?.params,
3802
+ (yup3) => yup3.object({ relativePath: yup3.string().required() })
3803
+ );
3580
3804
  const doc = await this.getDocument(realPath);
3581
- const newRealPath = path2.join(collection?.path, args.params.relativePath);
3805
+ const newRealPath = path2.join(
3806
+ collection?.path,
3807
+ args.params.relativePath
3808
+ );
3582
3809
  await this.database.put(newRealPath, doc._rawData, collection.name);
3583
3810
  await this.deleteDocument(realPath);
3584
3811
  return this.getDocument(newRealPath);
@@ -3609,22 +3836,30 @@ var Resolver = class {
3609
3836
  };
3610
3837
  };
3611
3838
  this.referenceResolver = async (filter, fieldDefinition) => {
3612
- const referencedCollection = this.tinaSchema.getCollection(fieldDefinition.collections[0]);
3839
+ const referencedCollection = this.tinaSchema.getCollection(
3840
+ fieldDefinition.collections[0]
3841
+ );
3613
3842
  if (!referencedCollection) {
3614
- throw new Error(`Unable to find collection for ${fieldDefinition.collections[0]} querying ${fieldDefinition.name}`);
3843
+ throw new Error(
3844
+ `Unable to find collection for ${fieldDefinition.collections[0]} querying ${fieldDefinition.name}`
3845
+ );
3615
3846
  }
3616
- const sortKeys = Object.keys(filter[fieldDefinition.name][referencedCollection.name]);
3617
- const resolvedCollectionConnection = await this.resolveCollectionConnection({
3618
- args: {
3619
- sort: sortKeys.length === 1 ? sortKeys[0] : void 0,
3620
- filter: {
3621
- ...filter[fieldDefinition.name][referencedCollection.name]
3847
+ const sortKeys = Object.keys(
3848
+ filter[fieldDefinition.name][referencedCollection.name]
3849
+ );
3850
+ const resolvedCollectionConnection = await this.resolveCollectionConnection(
3851
+ {
3852
+ args: {
3853
+ sort: sortKeys.length === 1 ? sortKeys[0] : void 0,
3854
+ filter: {
3855
+ ...filter[fieldDefinition.name][referencedCollection.name]
3856
+ },
3857
+ first: -1
3622
3858
  },
3623
- first: -1
3624
- },
3625
- collection: referencedCollection,
3626
- hydrator: (path6) => path6
3627
- });
3859
+ collection: referencedCollection,
3860
+ hydrator: (path6) => path6
3861
+ }
3862
+ );
3628
3863
  const { edges } = resolvedCollectionConnection;
3629
3864
  const values = edges.map((edge) => edge.node);
3630
3865
  return { edges, values };
@@ -3637,14 +3872,26 @@ var Resolver = class {
3637
3872
  let conditions;
3638
3873
  if (args.filter) {
3639
3874
  if (collection.fields) {
3640
- conditions = await this.resolveFilterConditions(args.filter, collection.fields, collection.name);
3875
+ conditions = await this.resolveFilterConditions(
3876
+ args.filter,
3877
+ collection.fields,
3878
+ collection.name
3879
+ );
3641
3880
  } else if (collection.templates) {
3642
3881
  for (const templateName of Object.keys(args.filter)) {
3643
- const template = collection.templates.find((template2) => template2.name === templateName);
3882
+ const template = collection.templates.find(
3883
+ (template2) => template2.name === templateName
3884
+ );
3644
3885
  if (template) {
3645
- conditions = await this.resolveFilterConditions(args.filter[templateName], template.fields, `${collection.name}.${templateName}`);
3886
+ conditions = await this.resolveFilterConditions(
3887
+ args.filter[templateName],
3888
+ template.fields,
3889
+ `${collection.name}.${templateName}`
3890
+ );
3646
3891
  } else {
3647
- throw new Error(`Error template not found: ${templateName} in collection ${collection.name}`);
3892
+ throw new Error(
3893
+ `Error template not found: ${templateName} in collection ${collection.name}`
3894
+ );
3648
3895
  }
3649
3896
  }
3650
3897
  }
@@ -3660,7 +3907,10 @@ var Resolver = class {
3660
3907
  before: args.before,
3661
3908
  after: args.after
3662
3909
  };
3663
- const result = await this.database.query(queryOptions, hydrator ? hydrator : this.getDocument);
3910
+ const result = await this.database.query(
3911
+ queryOptions,
3912
+ hydrator ? hydrator : this.getDocument
3913
+ );
3664
3914
  const edges = result.edges;
3665
3915
  const pageInfo = result.pageInfo;
3666
3916
  return {
@@ -3697,13 +3947,25 @@ var Resolver = class {
3697
3947
  accum[fieldName] = fieldValue;
3698
3948
  break;
3699
3949
  case "image":
3700
- accum[fieldName] = resolveMediaCloudToRelative(fieldValue, this.config, this.tinaSchema.schema);
3950
+ accum[fieldName] = resolveMediaCloudToRelative(
3951
+ fieldValue,
3952
+ this.config,
3953
+ this.tinaSchema.schema
3954
+ );
3701
3955
  break;
3702
3956
  case "object":
3703
3957
  accum[fieldName] = this.buildObjectMutations(fieldValue, field);
3704
3958
  break;
3705
3959
  case "rich-text":
3706
- accum[fieldName] = stringifyMDX(fieldValue, field, (fieldValue2) => resolveMediaCloudToRelative(fieldValue2, this.config, this.tinaSchema.schema));
3960
+ accum[fieldName] = stringifyMDX(
3961
+ fieldValue,
3962
+ field,
3963
+ (fieldValue2) => resolveMediaCloudToRelative(
3964
+ fieldValue2,
3965
+ this.config,
3966
+ this.tinaSchema.schema
3967
+ )
3968
+ );
3707
3969
  break;
3708
3970
  case "reference":
3709
3971
  accum[fieldName] = fieldValue;
@@ -3735,14 +3997,28 @@ var Resolver = class {
3735
3997
  accumulator[field.name] = value;
3736
3998
  break;
3737
3999
  case "image":
3738
- accumulator[field.name] = resolveMediaRelativeToCloud(value, this.config, this.tinaSchema.schema);
4000
+ accumulator[field.name] = resolveMediaRelativeToCloud(
4001
+ value,
4002
+ this.config,
4003
+ this.tinaSchema.schema
4004
+ );
3739
4005
  break;
3740
4006
  case "rich-text":
3741
- const tree = parseMDX(value, field, (value2) => resolveMediaRelativeToCloud(value2, this.config, this.tinaSchema.schema));
4007
+ const tree = parseMDX(
4008
+ value,
4009
+ field,
4010
+ (value2) => resolveMediaRelativeToCloud(
4011
+ value2,
4012
+ this.config,
4013
+ this.tinaSchema.schema
4014
+ )
4015
+ );
3742
4016
  if (tree?.children[0]?.type === "invalid_markdown") {
3743
4017
  if (this.isAudit) {
3744
4018
  const invalidNode = tree?.children[0];
3745
- throw new GraphQLError2(`${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`);
4019
+ throw new GraphQLError2(
4020
+ `${invalidNode?.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4021
+ );
3746
4022
  }
3747
4023
  }
3748
4024
  accumulator[field.name] = tree;
@@ -3752,7 +4028,10 @@ var Resolver = class {
3752
4028
  if (!value) {
3753
4029
  return;
3754
4030
  }
3755
- assertShape(value, (yup3) => yup3.array().of(yup3.object().required()));
4031
+ assertShape(
4032
+ value,
4033
+ (yup3) => yup3.array().of(yup3.object().required())
4034
+ );
3756
4035
  accumulator[field.name] = await sequential(value, async (item) => {
3757
4036
  const template = await this.tinaSchema.getTemplateForData({
3758
4037
  data: item,
@@ -3800,16 +4079,22 @@ var Resolver = class {
3800
4079
  };
3801
4080
  this.buildParams = (args) => {
3802
4081
  try {
3803
- assertShape(args, (yup3) => yup3.object({
3804
- collection: yup3.string().required(),
3805
- params: yup3.object().required()
3806
- }));
4082
+ assertShape(
4083
+ args,
4084
+ (yup3) => yup3.object({
4085
+ collection: yup3.string().required(),
4086
+ params: yup3.object().required()
4087
+ })
4088
+ );
3807
4089
  return args.params[args.collection];
3808
4090
  } catch (e) {
3809
4091
  }
3810
- assertShape(args, (yup3) => yup3.object({
3811
- params: yup3.object().required()
3812
- }));
4092
+ assertShape(
4093
+ args,
4094
+ (yup3) => yup3.object({
4095
+ params: yup3.object().required()
4096
+ })
4097
+ );
3813
4098
  return args.params;
3814
4099
  };
3815
4100
  this.config = init.config;
@@ -3824,17 +4109,29 @@ var Resolver = class {
3824
4109
  throw new Error("Error parsing filter - unable to generate filterPath");
3825
4110
  }
3826
4111
  if (!condition.filterExpression) {
3827
- throw new Error(`Error parsing filter - missing expression for ${condition.filterPath}`);
4112
+ throw new Error(
4113
+ `Error parsing filter - missing expression for ${condition.filterPath}`
4114
+ );
3828
4115
  }
3829
4116
  conditions.push(condition);
3830
4117
  };
3831
4118
  await resolveReferences(filter, fields, this.referenceResolver);
3832
4119
  for (const fieldName of Object.keys(filter)) {
3833
- const field = fields.find((field2) => field2.name === fieldName);
4120
+ const field = fields.find(
4121
+ (field2) => field2.name === fieldName
4122
+ );
3834
4123
  if (!field) {
3835
- throw new Error(`${fieldName} not found in collection ${collectionName}`);
4124
+ throw new Error(
4125
+ `${fieldName} not found in collection ${collectionName}`
4126
+ );
3836
4127
  }
3837
- collectConditionsForField(fieldName, field, filter[fieldName], "", conditionCollector);
4128
+ collectConditionsForField(
4129
+ fieldName,
4130
+ field,
4131
+ filter[fieldName],
4132
+ "",
4133
+ conditionCollector
4134
+ );
3838
4135
  }
3839
4136
  return conditions;
3840
4137
  }
@@ -3903,30 +4200,52 @@ var resolve = async ({
3903
4200
  return value;
3904
4201
  }
3905
4202
  if (info.fieldName === "collections") {
3906
- const collectionNode2 = info.fieldNodes.find((x) => x.name.value === "collections");
3907
- const hasDocuments2 = collectionNode2.selectionSet.selections.find((x) => {
3908
- return x?.name?.value === "documents";
3909
- });
4203
+ const collectionNode2 = info.fieldNodes.find(
4204
+ (x) => x.name.value === "collections"
4205
+ );
4206
+ const hasDocuments2 = collectionNode2.selectionSet.selections.find(
4207
+ (x) => {
4208
+ return x?.name?.value === "documents";
4209
+ }
4210
+ );
3910
4211
  return tinaSchema.getCollections().map((collection) => {
3911
- return resolver.resolveCollection(args, collection.name, Boolean(hasDocuments2));
4212
+ return resolver.resolveCollection(
4213
+ args,
4214
+ collection.name,
4215
+ Boolean(hasDocuments2)
4216
+ );
3912
4217
  });
3913
4218
  }
3914
- const collectionNode = info.fieldNodes.find((x) => x.name.value === "collection");
3915
- const hasDocuments = collectionNode.selectionSet.selections.find((x) => {
3916
- return x?.name?.value === "documents";
3917
- });
3918
- return resolver.resolveCollection(args, args.collection, Boolean(hasDocuments));
4219
+ const collectionNode = info.fieldNodes.find(
4220
+ (x) => x.name.value === "collection"
4221
+ );
4222
+ const hasDocuments = collectionNode.selectionSet.selections.find(
4223
+ (x) => {
4224
+ return x?.name?.value === "documents";
4225
+ }
4226
+ );
4227
+ return resolver.resolveCollection(
4228
+ args,
4229
+ args.collection,
4230
+ Boolean(hasDocuments)
4231
+ );
3919
4232
  }
3920
4233
  if (info.fieldName === "getOptimizedQuery") {
3921
4234
  try {
3922
- const [optimizedQuery] = optimizeDocuments(info.schema, [parse(args.queryString)], {
3923
- assumeValid: true,
3924
- includeFragments: false,
3925
- noLocation: true
3926
- });
4235
+ const [optimizedQuery] = optimizeDocuments(
4236
+ info.schema,
4237
+ [parse(args.queryString)],
4238
+ {
4239
+ assumeValid: true,
4240
+ includeFragments: false,
4241
+ noLocation: true
4242
+ }
4243
+ );
3927
4244
  return print2(optimizedQuery);
3928
4245
  } catch (e) {
3929
- throw new Error(`Invalid query provided, Error message: ${e.message}`);
4246
+ throw new Error(
4247
+ `Invalid query provided, Error message: ${e.message}`
4248
+ );
3930
4249
  }
3931
4250
  }
3932
4251
  if (!lookup) {
@@ -3935,7 +4254,10 @@ var resolve = async ({
3935
4254
  const isCreation = lookup[info.fieldName] === "create";
3936
4255
  switch (lookup.resolveType) {
3937
4256
  case "nodeDocument":
3938
- assertShape(args, (yup3) => yup3.object({ id: yup3.string().required() }));
4257
+ assertShape(
4258
+ args,
4259
+ (yup3) => yup3.object({ id: yup3.string().required() })
4260
+ );
3939
4261
  return resolver.getDocument(args.id);
3940
4262
  case "multiCollectionDocument":
3941
4263
  if (typeof value === "string") {
@@ -3990,7 +4312,9 @@ var resolve = async ({
3990
4312
  collection: value.collection
3991
4313
  });
3992
4314
  } else {
3993
- throw new Error(`Expected an array for result of ${info.fieldName} at ${info.path}`);
4315
+ throw new Error(
4316
+ `Expected an array for result of ${info.fieldName} at ${info.path}`
4317
+ );
3994
4318
  }
3995
4319
  case "collectionDocument":
3996
4320
  if (value) {
@@ -4094,12 +4418,16 @@ var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
4094
4418
  case ".markdown":
4095
4419
  case ".mdx":
4096
4420
  case ".md":
4097
- const ok = matter.stringify(typeof $_body === "undefined" ? "" : `
4098
- ${$_body}`, strippedContent, {
4099
- language: markdownParseConfig?.frontmatterFormat || "yaml",
4100
- engines: matterEngines,
4101
- delimiters: markdownParseConfig?.frontmatterDelimiters || "---"
4102
- });
4421
+ const ok = matter.stringify(
4422
+ typeof $_body === "undefined" ? "" : `
4423
+ ${$_body}`,
4424
+ strippedContent,
4425
+ {
4426
+ language: markdownParseConfig?.frontmatterFormat || "yaml",
4427
+ engines: matterEngines,
4428
+ delimiters: markdownParseConfig?.frontmatterDelimiters || "---"
4429
+ }
4430
+ );
4103
4431
  return ok;
4104
4432
  case ".json":
4105
4433
  return JSON.stringify(strippedContent, null, 2);
@@ -4154,7 +4482,10 @@ var normalizePath = (filepath) => filepath.replace(/\\/g, "/");
4154
4482
  var replaceNameOverrides = (template, obj) => {
4155
4483
  if (template.list) {
4156
4484
  return obj.map((item) => {
4157
- return _replaceNameOverrides(getTemplateForData(template, item).fields, item);
4485
+ return _replaceNameOverrides(
4486
+ getTemplateForData(template, item).fields,
4487
+ item
4488
+ );
4158
4489
  });
4159
4490
  } else {
4160
4491
  return _replaceNameOverrides(getTemplateForData(template, obj).fields, obj);
@@ -4163,7 +4494,9 @@ var replaceNameOverrides = (template, obj) => {
4163
4494
  var _replaceNameOverrides = (fields, obj) => {
4164
4495
  const output = {};
4165
4496
  Object.keys(obj).forEach((key) => {
4166
- const field = fields.find((fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key);
4497
+ const field = fields.find(
4498
+ (fieldWithMatchingAlias) => (fieldWithMatchingAlias?.nameOverride || fieldWithMatchingAlias?.name) === key
4499
+ );
4167
4500
  output[field?.name || key] = field?.type == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
4168
4501
  });
4169
4502
  return output;
@@ -4171,7 +4504,9 @@ var _replaceNameOverrides = (fields, obj) => {
4171
4504
  var getTemplateKey = (field) => {
4172
4505
  const DEFAULT_TEMPLATE_KEY = "_template";
4173
4506
  if (field.templates?.length) {
4174
- const templateField = field.templates[0]?.fields?.find((field2) => field2.name === DEFAULT_TEMPLATE_KEY);
4507
+ const templateField = field.templates[0]?.fields?.find(
4508
+ (field2) => field2.name === DEFAULT_TEMPLATE_KEY
4509
+ );
4175
4510
  return templateField?.alias || DEFAULT_TEMPLATE_KEY;
4176
4511
  }
4177
4512
  return DEFAULT_TEMPLATE_KEY;
@@ -4180,7 +4515,9 @@ var getTemplateForData = (field, data) => {
4180
4515
  if (field.templates?.length) {
4181
4516
  const templateKey = getTemplateKey(field);
4182
4517
  if (data[templateKey]) {
4183
- return field.templates.find((template) => template.name === data[templateKey]);
4518
+ return field.templates.find(
4519
+ (template) => template.name === data[templateKey]
4520
+ );
4184
4521
  }
4185
4522
  } else {
4186
4523
  return field;
@@ -4190,7 +4527,10 @@ var getTemplateForData = (field, data) => {
4190
4527
  var applyNameOverrides = (template, obj) => {
4191
4528
  if (template.list) {
4192
4529
  return obj.map((item) => {
4193
- return _applyNameOverrides(getTemplateForData(template, item).fields, item);
4530
+ return _applyNameOverrides(
4531
+ getTemplateForData(template, item).fields,
4532
+ item
4533
+ );
4194
4534
  });
4195
4535
  } else {
4196
4536
  return _applyNameOverrides(getTemplateForData(template, obj).fields, obj);
@@ -4233,7 +4573,10 @@ var Database = class {
4233
4573
  } else {
4234
4574
  const tinaSchema = await this.getSchema(this.level);
4235
4575
  const extension = path3.extname(filepath);
4236
- const contentObject = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizePath(filepath));
4576
+ const contentObject = await this.level.sublevel(
4577
+ CONTENT_ROOT_PREFIX,
4578
+ SUBLEVEL_OPTIONS
4579
+ ).get(normalizePath(filepath));
4237
4580
  if (!contentObject) {
4238
4581
  throw new GraphQLError4(`Unable to find record ${filepath}`);
4239
4582
  }
@@ -4269,7 +4612,11 @@ var Database = class {
4269
4612
  await this.initLevel();
4270
4613
  const dataFields = await this.formatBodyOnPayload(filepath, data);
4271
4614
  const collection = await this.collectionForPath(filepath);
4272
- const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
4615
+ const stringifiedFile = await this.stringifyFile(
4616
+ filepath,
4617
+ dataFields,
4618
+ collection
4619
+ );
4273
4620
  let collectionIndexDefinitions;
4274
4621
  if (collection) {
4275
4622
  const indexDefinitions = await this.getIndexDefinitions(this.level);
@@ -4280,9 +4627,26 @@ var Database = class {
4280
4627
  await this.bridge.put(normalizedPath, stringifiedFile);
4281
4628
  }
4282
4629
  await this.onPut(normalizedPath, stringifiedFile);
4283
- const putOps = makeIndexOpsForDocument(normalizedPath, collection?.name, collectionIndexDefinitions, dataFields, "put", this.level);
4284
- const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4285
- const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection?.name, collectionIndexDefinitions, existingItem, "del", this.level) : [];
4630
+ const putOps = makeIndexOpsForDocument(
4631
+ normalizedPath,
4632
+ collection?.name,
4633
+ collectionIndexDefinitions,
4634
+ dataFields,
4635
+ "put",
4636
+ this.level
4637
+ );
4638
+ const existingItem = await this.level.sublevel(
4639
+ CONTENT_ROOT_PREFIX,
4640
+ SUBLEVEL_OPTIONS
4641
+ ).get(normalizedPath);
4642
+ const delOps = existingItem ? makeIndexOpsForDocument(
4643
+ normalizedPath,
4644
+ collection?.name,
4645
+ collectionIndexDefinitions,
4646
+ existingItem,
4647
+ "del",
4648
+ this.level
4649
+ ) : [];
4286
4650
  const ops = [
4287
4651
  ...delOps,
4288
4652
  ...putOps,
@@ -4290,7 +4654,10 @@ var Database = class {
4290
4654
  type: "put",
4291
4655
  key: normalizedPath,
4292
4656
  value: dataFields,
4293
- sublevel: this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
4657
+ sublevel: this.level.sublevel(
4658
+ CONTENT_ROOT_PREFIX,
4659
+ SUBLEVEL_OPTIONS
4660
+ )
4294
4661
  }
4295
4662
  ];
4296
4663
  await this.level.batch(ops);
@@ -4309,14 +4676,35 @@ var Database = class {
4309
4676
  const normalizedPath = normalizePath(filepath);
4310
4677
  const dataFields = await this.formatBodyOnPayload(filepath, data);
4311
4678
  const collection = await this.collectionForPath(filepath);
4312
- const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
4679
+ const stringifiedFile = await this.stringifyFile(
4680
+ filepath,
4681
+ dataFields,
4682
+ collection
4683
+ );
4313
4684
  if (this.bridge) {
4314
4685
  await this.bridge.put(normalizedPath, stringifiedFile);
4315
4686
  }
4316
4687
  await this.onPut(normalizedPath, stringifiedFile);
4317
- const putOps = makeIndexOpsForDocument(normalizedPath, collectionName, collectionIndexDefinitions, dataFields, "put", this.level);
4318
- const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4319
- const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collectionName, collectionIndexDefinitions, existingItem, "del", this.level) : [];
4688
+ const putOps = makeIndexOpsForDocument(
4689
+ normalizedPath,
4690
+ collectionName,
4691
+ collectionIndexDefinitions,
4692
+ dataFields,
4693
+ "put",
4694
+ this.level
4695
+ );
4696
+ const existingItem = await this.level.sublevel(
4697
+ CONTENT_ROOT_PREFIX,
4698
+ SUBLEVEL_OPTIONS
4699
+ ).get(normalizedPath);
4700
+ const delOps = existingItem ? makeIndexOpsForDocument(
4701
+ normalizedPath,
4702
+ collectionName,
4703
+ collectionIndexDefinitions,
4704
+ existingItem,
4705
+ "del",
4706
+ this.level
4707
+ ) : [];
4320
4708
  const ops = [
4321
4709
  ...delOps,
4322
4710
  ...putOps,
@@ -4324,7 +4712,10 @@ var Database = class {
4324
4712
  type: "put",
4325
4713
  key: normalizedPath,
4326
4714
  value: dataFields,
4327
- sublevel: this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
4715
+ sublevel: this.level.sublevel(
4716
+ CONTENT_ROOT_PREFIX,
4717
+ SUBLEVEL_OPTIONS
4718
+ )
4328
4719
  }
4329
4720
  ];
4330
4721
  await this.level.batch(ops);
@@ -4365,49 +4756,78 @@ var Database = class {
4365
4756
  return payload;
4366
4757
  };
4367
4758
  this.stringifyFile = async (filepath, payload, collection) => {
4368
- const templateDetails = await this.getTemplateDetailsForFile(collection, payload);
4759
+ const templateDetails = await this.getTemplateDetailsForFile(
4760
+ collection,
4761
+ payload
4762
+ );
4369
4763
  const writeTemplateKey = templateDetails.info.type === "union";
4370
4764
  const aliasedData = applyNameOverrides(templateDetails.template, payload);
4371
4765
  const extension = path3.extname(filepath);
4372
- const stringifiedFile = stringifyFile(aliasedData, extension, writeTemplateKey, {
4373
- frontmatterFormat: collection?.frontmatterFormat,
4374
- frontmatterDelimiters: collection?.frontmatterDelimiters
4375
- });
4766
+ const stringifiedFile = stringifyFile(
4767
+ aliasedData,
4768
+ extension,
4769
+ writeTemplateKey,
4770
+ {
4771
+ frontmatterFormat: collection?.frontmatterFormat,
4772
+ frontmatterDelimiters: collection?.frontmatterDelimiters
4773
+ }
4774
+ );
4376
4775
  return stringifiedFile;
4377
4776
  };
4378
4777
  this.flush = async (filepath) => {
4379
4778
  const data = await this.get(filepath);
4380
4779
  const dataFields = await this.formatBodyOnPayload(filepath, data);
4381
4780
  const collection = await this.collectionForPath(filepath);
4382
- const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
4781
+ const stringifiedFile = await this.stringifyFile(
4782
+ filepath,
4783
+ dataFields,
4784
+ collection
4785
+ );
4383
4786
  return stringifiedFile;
4384
4787
  };
4385
4788
  this.getLookup = async (returnType) => {
4386
4789
  await this.initLevel();
4387
- const lookupPath = normalizePath(path3.join(this.getGeneratedFolder(), `_lookup.json`));
4790
+ const lookupPath = normalizePath(
4791
+ path3.join(this.getGeneratedFolder(), `_lookup.json`)
4792
+ );
4388
4793
  if (!this._lookup) {
4389
- const _lookup = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(lookupPath);
4794
+ const _lookup = await this.level.sublevel(
4795
+ CONTENT_ROOT_PREFIX,
4796
+ SUBLEVEL_OPTIONS
4797
+ ).get(lookupPath);
4390
4798
  this._lookup = _lookup;
4391
4799
  }
4392
4800
  return this._lookup[returnType];
4393
4801
  };
4394
4802
  this.getGraphQLSchema = async () => {
4395
4803
  await this.initLevel();
4396
- const graphqlPath = normalizePath(path3.join(this.getGeneratedFolder(), `_graphql.json`));
4397
- return await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(graphqlPath);
4804
+ const graphqlPath = normalizePath(
4805
+ path3.join(this.getGeneratedFolder(), `_graphql.json`)
4806
+ );
4807
+ return await this.level.sublevel(
4808
+ CONTENT_ROOT_PREFIX,
4809
+ SUBLEVEL_OPTIONS
4810
+ ).get(graphqlPath);
4398
4811
  };
4399
4812
  this.getGraphQLSchemaFromBridge = async () => {
4400
4813
  if (!this.bridge) {
4401
4814
  throw new Error(`No bridge configured`);
4402
4815
  }
4403
- const graphqlPath = normalizePath(path3.join(this.getGeneratedFolder(), `_graphql.json`));
4816
+ const graphqlPath = normalizePath(
4817
+ path3.join(this.getGeneratedFolder(), `_graphql.json`)
4818
+ );
4404
4819
  const _graphql = await this.bridge.get(graphqlPath);
4405
4820
  return JSON.parse(_graphql);
4406
4821
  };
4407
4822
  this.getTinaSchema = async (level) => {
4408
4823
  await this.initLevel();
4409
- const schemaPath = normalizePath(path3.join(this.getGeneratedFolder(), `_schema.json`));
4410
- return await (level || this.level).sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(schemaPath);
4824
+ const schemaPath = normalizePath(
4825
+ path3.join(this.getGeneratedFolder(), `_schema.json`)
4826
+ );
4827
+ return await (level || this.level).sublevel(
4828
+ CONTENT_ROOT_PREFIX,
4829
+ SUBLEVEL_OPTIONS
4830
+ ).get(schemaPath);
4411
4831
  };
4412
4832
  this.getSchema = async (level) => {
4413
4833
  if (this.tinaSchema) {
@@ -4450,7 +4870,9 @@ var Database = class {
4450
4870
  indexDefinitions[index.name] = {
4451
4871
  fields: index.fields.map((indexField) => ({
4452
4872
  name: indexField.name,
4453
- type: collection.fields.find((field) => indexField.name === field.name)?.type
4873
+ type: collection.fields.find(
4874
+ (field) => indexField.name === field.name
4875
+ )?.type
4454
4876
  }))
4455
4877
  };
4456
4878
  }
@@ -4500,12 +4922,17 @@ var Database = class {
4500
4922
  const allIndexDefinitions = await this.getIndexDefinitions(this.level);
4501
4923
  const indexDefinitions = allIndexDefinitions?.[queryOptions.collection];
4502
4924
  if (!indexDefinitions) {
4503
- throw new Error(`No indexDefinitions for collection ${queryOptions.collection}`);
4925
+ throw new Error(
4926
+ `No indexDefinitions for collection ${queryOptions.collection}`
4927
+ );
4504
4928
  }
4505
4929
  const filterChain = coerceFilterChainOperands(rawFilterChain);
4506
4930
  const indexDefinition = sort && indexDefinitions?.[sort];
4507
4931
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
4508
- const rootLevel = this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
4932
+ const rootLevel = this.level.sublevel(
4933
+ CONTENT_ROOT_PREFIX,
4934
+ SUBLEVEL_OPTIONS
4935
+ );
4509
4936
  const sublevel = indexDefinition ? this.level.sublevel(collection, SUBLEVEL_OPTIONS).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
4510
4937
  if (!query.gt && !query.gte) {
4511
4938
  query.gte = filterSuffixes?.left ? filterSuffixes.left : "";
@@ -4528,7 +4955,9 @@ var Database = class {
4528
4955
  continue;
4529
4956
  }
4530
4957
  const filepath = matcher.groups["_filepath_"];
4531
- if (!itemFilter(filterSuffixes ? matcher.groups : indexDefinition ? await rootLevel.get(filepath) : value)) {
4958
+ if (!itemFilter(
4959
+ filterSuffixes ? matcher.groups : indexDefinition ? await rootLevel.get(filepath) : value
4960
+ )) {
4532
4961
  continue;
4533
4962
  }
4534
4963
  if (limit !== -1 && edges.length >= limit) {
@@ -4577,8 +5006,14 @@ var Database = class {
4577
5006
  tinaSchema
4578
5007
  }) => {
4579
5008
  if (this.bridge && this.bridge.supportsBuilding()) {
4580
- await this.bridge.putConfig(normalizePath(path3.join(this.getGeneratedFolder(), `_graphql.json`)), JSON.stringify(graphQLSchema));
4581
- await this.bridge.putConfig(normalizePath(path3.join(this.getGeneratedFolder(), `_schema.json`)), JSON.stringify(tinaSchema.schema));
5009
+ await this.bridge.putConfig(
5010
+ normalizePath(path3.join(this.getGeneratedFolder(), `_graphql.json`)),
5011
+ JSON.stringify(graphQLSchema)
5012
+ );
5013
+ await this.bridge.putConfig(
5014
+ normalizePath(path3.join(this.getGeneratedFolder(), `_schema.json`)),
5015
+ JSON.stringify(tinaSchema.schema)
5016
+ );
4582
5017
  }
4583
5018
  };
4584
5019
  this.indexContent = async ({
@@ -4591,21 +5026,37 @@ var Database = class {
4591
5026
  }
4592
5027
  await this.initLevel();
4593
5028
  await this.indexStatusCallbackWrapper(async () => {
4594
- const lookup = lookupFromLockFile || JSON.parse(await this.bridge.get(normalizePath(path3.join(this.getGeneratedFolder(), "_lookup.json"))));
5029
+ const lookup = lookupFromLockFile || JSON.parse(
5030
+ await this.bridge.get(
5031
+ normalizePath(path3.join(this.getGeneratedFolder(), "_lookup.json"))
5032
+ )
5033
+ );
4595
5034
  let nextLevel;
4596
5035
  let nextVersion;
4597
5036
  if (!this.config.version) {
4598
5037
  await this.level.clear();
4599
5038
  nextLevel = this.level;
4600
5039
  } else {
4601
- const version2 = await this.getDatabaseVersion();
4602
- nextVersion = version2 ? `${parseInt(version2) + 1}` : "0";
5040
+ const version = await this.getDatabaseVersion();
5041
+ nextVersion = version ? `${parseInt(version) + 1}` : "0";
4603
5042
  nextLevel = this.rootLevel.sublevel(nextVersion, SUBLEVEL_OPTIONS);
4604
5043
  }
4605
- const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
4606
- await contentRootLevel.put(normalizePath(path3.join(this.getGeneratedFolder(), "_graphql.json")), graphQLSchema);
4607
- await contentRootLevel.put(normalizePath(path3.join(this.getGeneratedFolder(), "_schema.json")), tinaSchema.schema);
4608
- await contentRootLevel.put(normalizePath(path3.join(this.getGeneratedFolder(), "_lookup.json")), lookup);
5044
+ const contentRootLevel = nextLevel.sublevel(
5045
+ CONTENT_ROOT_PREFIX,
5046
+ SUBLEVEL_OPTIONS
5047
+ );
5048
+ await contentRootLevel.put(
5049
+ normalizePath(path3.join(this.getGeneratedFolder(), "_graphql.json")),
5050
+ graphQLSchema
5051
+ );
5052
+ await contentRootLevel.put(
5053
+ normalizePath(path3.join(this.getGeneratedFolder(), "_schema.json")),
5054
+ tinaSchema.schema
5055
+ );
5056
+ await contentRootLevel.put(
5057
+ normalizePath(path3.join(this.getGeneratedFolder(), "_lookup.json")),
5058
+ lookup
5059
+ );
4609
5060
  await this._indexAllContent(nextLevel);
4610
5061
  if (this.config.version) {
4611
5062
  await this.updateDatabaseVersion(nextVersion);
@@ -4628,7 +5079,12 @@ var Database = class {
4628
5079
  await this.indexStatusCallbackWrapper(async () => {
4629
5080
  const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
4630
5081
  for (const collection of Object.keys(pathsByCollection)) {
4631
- await _deleteIndexContent(this, pathsByCollection[collection], enqueueOps, collections[collection]);
5082
+ await _deleteIndexContent(
5083
+ this,
5084
+ pathsByCollection[collection],
5085
+ enqueueOps,
5086
+ collections[collection]
5087
+ );
4632
5088
  }
4633
5089
  await _deleteIndexContent(this, nonCollectionPaths, enqueueOps, null);
4634
5090
  });
@@ -4648,7 +5104,13 @@ var Database = class {
4648
5104
  await this.indexStatusCallbackWrapper(async () => {
4649
5105
  const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
4650
5106
  for (const collection of Object.keys(pathsByCollection)) {
4651
- await _indexContent(this, this.level, pathsByCollection[collection], enqueueOps, collections[collection]);
5107
+ await _indexContent(
5108
+ this,
5109
+ this.level,
5110
+ pathsByCollection[collection],
5111
+ enqueueOps,
5112
+ collections[collection]
5113
+ );
4652
5114
  }
4653
5115
  await _indexContent(this, this.level, nonCollectionPaths, enqueueOps);
4654
5116
  });
@@ -4664,13 +5126,26 @@ var Database = class {
4664
5126
  const indexDefinitions = await this.getIndexDefinitions(this.level);
4665
5127
  collectionIndexDefinitions = indexDefinitions?.[collection.name];
4666
5128
  }
4667
- this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5129
+ this.level.sublevel(
5130
+ CONTENT_ROOT_PREFIX,
5131
+ SUBLEVEL_OPTIONS
5132
+ );
4668
5133
  const itemKey = normalizePath(filepath);
4669
- const rootSublevel = this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5134
+ const rootSublevel = this.level.sublevel(
5135
+ CONTENT_ROOT_PREFIX,
5136
+ SUBLEVEL_OPTIONS
5137
+ );
4670
5138
  const item = await rootSublevel.get(itemKey);
4671
5139
  if (item) {
4672
5140
  await this.level.batch([
4673
- ...makeIndexOpsForDocument(filepath, collection.name, collectionIndexDefinitions, item, "del", this.level),
5141
+ ...makeIndexOpsForDocument(
5142
+ filepath,
5143
+ collection.name,
5144
+ collectionIndexDefinitions,
5145
+ item,
5146
+ "del",
5147
+ this.level
5148
+ ),
4674
5149
  {
4675
5150
  type: "del",
4676
5151
  key: itemKey,
@@ -4694,7 +5169,10 @@ var Database = class {
4694
5169
  }
4695
5170
  };
4696
5171
  await sequential(tinaSchema.getCollections(), async (collection) => {
4697
- const documentPaths = await this.bridge.glob(normalizePath(collection.path), collection.format || "md");
5172
+ const documentPaths = await this.bridge.glob(
5173
+ normalizePath(collection.path),
5174
+ collection.format || "md"
5175
+ );
4698
5176
  await _indexContent(this, level, documentPaths, enqueueOps, collection);
4699
5177
  });
4700
5178
  while (operations.length) {
@@ -4716,7 +5194,10 @@ var Database = class {
4716
5194
  ...lookupMap,
4717
5195
  [lookup.type]: lookup
4718
5196
  };
4719
- await this.bridge.putConfig(normalizePath(lookupPath), JSON.stringify(updatedLookup));
5197
+ await this.bridge.putConfig(
5198
+ normalizePath(lookupPath),
5199
+ JSON.stringify(updatedLookup)
5200
+ );
4720
5201
  };
4721
5202
  this.tinaDirectory = config.tinaDirectory || ".tina";
4722
5203
  this.bridge = config.bridge;
@@ -4743,9 +5224,9 @@ var Database = class {
4743
5224
  }
4744
5225
  return { pathsByCollection, nonCollectionPaths, collections };
4745
5226
  }
4746
- async updateDatabaseVersion(version2) {
5227
+ async updateDatabaseVersion(version) {
4747
5228
  const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4748
- await metadataLevel.put("metadata", { version: version2 });
5229
+ await metadataLevel.put("metadata", { version });
4749
5230
  }
4750
5231
  async getDatabaseVersion() {
4751
5232
  const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
@@ -4759,12 +5240,12 @@ var Database = class {
4759
5240
  if (!this.config.version) {
4760
5241
  this.level = this.rootLevel;
4761
5242
  } else {
4762
- let version2 = await this.getDatabaseVersion();
4763
- if (!version2) {
4764
- version2 = "";
4765
- await this.updateDatabaseVersion(version2);
5243
+ let version = await this.getDatabaseVersion();
5244
+ if (!version) {
5245
+ version = "";
5246
+ await this.updateDatabaseVersion(version);
4766
5247
  }
4767
- this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
5248
+ this.level = this.rootLevel.sublevel(version, SUBLEVEL_OPTIONS);
4768
5249
  }
4769
5250
  if (!this.level) {
4770
5251
  throw new GraphQLError4("Error initializing LevelDB instance");
@@ -4779,9 +5260,13 @@ var Database = class {
4779
5260
  }
4780
5261
  if (templateInfo.type === "union") {
4781
5262
  if (hasOwnProperty(data, "_template")) {
4782
- template = templateInfo.templates.find((t) => lastItem(t.namespace) === data._template);
5263
+ template = templateInfo.templates.find(
5264
+ (t) => lastItem(t.namespace) === data._template
5265
+ );
4783
5266
  } else {
4784
- throw new Error(`Expected _template to be provided for document in an ambiguous collection`);
5267
+ throw new Error(
5268
+ `Expected _template to be provided for document in an ambiguous collection`
5269
+ );
4785
5270
  }
4786
5271
  }
4787
5272
  if (!template) {
@@ -4827,19 +5312,37 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
4827
5312
  await sequential(documentPaths, async (filepath) => {
4828
5313
  try {
4829
5314
  const dataString = await database.bridge.get(normalizePath(filepath));
4830
- const data = parseFile(dataString, path3.extname(filepath), (yup3) => yup3.object({}), {
4831
- frontmatterDelimiters: collection?.frontmatterDelimiters,
4832
- frontmatterFormat: collection?.frontmatterFormat
4833
- });
5315
+ const data = parseFile(
5316
+ dataString,
5317
+ path3.extname(filepath),
5318
+ (yup3) => yup3.object({}),
5319
+ {
5320
+ frontmatterDelimiters: collection?.frontmatterDelimiters,
5321
+ frontmatterFormat: collection?.frontmatterFormat
5322
+ }
5323
+ );
4834
5324
  const normalizedPath = normalizePath(filepath);
4835
- const aliasedData = templateInfo ? replaceNameOverrides(getTemplateForFile(templateInfo, data), data) : data;
5325
+ const aliasedData = templateInfo ? replaceNameOverrides(
5326
+ getTemplateForFile(templateInfo, data),
5327
+ data
5328
+ ) : data;
4836
5329
  await enqueueOps([
4837
- ...makeIndexOpsForDocument(normalizedPath, collection?.name, collectionIndexDefinitions, aliasedData, "put", level),
5330
+ ...makeIndexOpsForDocument(
5331
+ normalizedPath,
5332
+ collection?.name,
5333
+ collectionIndexDefinitions,
5334
+ aliasedData,
5335
+ "put",
5336
+ level
5337
+ ),
4838
5338
  {
4839
5339
  type: "put",
4840
5340
  key: normalizedPath,
4841
5341
  value: aliasedData,
4842
- sublevel: level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
5342
+ sublevel: level.sublevel(
5343
+ CONTENT_ROOT_PREFIX,
5344
+ SUBLEVEL_OPTIONS
5345
+ )
4843
5346
  }
4844
5347
  ]);
4845
5348
  } catch (error) {
@@ -4861,13 +5364,23 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
4861
5364
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
4862
5365
  }
4863
5366
  }
4864
- const rootLevel = database.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5367
+ const rootLevel = database.level.sublevel(
5368
+ CONTENT_ROOT_PREFIX,
5369
+ SUBLEVEL_OPTIONS
5370
+ );
4865
5371
  await sequential(documentPaths, async (filepath) => {
4866
5372
  const itemKey = normalizePath(filepath);
4867
5373
  const item = await rootLevel.get(itemKey);
4868
5374
  if (item) {
4869
5375
  await enequeueOps([
4870
- ...makeIndexOpsForDocument(itemKey, collection.name, collectionIndexDefinitions, item, "del", database.level),
5376
+ ...makeIndexOpsForDocument(
5377
+ itemKey,
5378
+ collection.name,
5379
+ collectionIndexDefinitions,
5380
+ item,
5381
+ "del",
5382
+ database.level
5383
+ ),
4871
5384
  { type: "del", key: itemKey, sublevel: rootLevel }
4872
5385
  ]);
4873
5386
  }
@@ -4879,9 +5392,13 @@ var getTemplateForFile = (templateInfo, data) => {
4879
5392
  }
4880
5393
  if (templateInfo.type === "union") {
4881
5394
  if (hasOwnProperty(data, "_template")) {
4882
- return templateInfo.templates.find((t) => lastItem(t.namespace) === data._template);
5395
+ return templateInfo.templates.find(
5396
+ (t) => lastItem(t.namespace) === data._template
5397
+ );
4883
5398
  } else {
4884
- throw new Error(`Expected _template to be provided for document in an ambiguous collection`);
5399
+ throw new Error(
5400
+ `Expected _template to be provided for document in an ambiguous collection`
5401
+ );
4885
5402
  }
4886
5403
  }
4887
5404
  throw new Error(`Unable to determine template`);
@@ -4922,9 +5439,12 @@ var FilesystemBridge = class {
4922
5439
  }
4923
5440
  async glob(pattern, extension) {
4924
5441
  const basePath = path4.join(this.outputPath, ...pattern.split("/"));
4925
- const items = await fg(path4.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"), {
4926
- dot: true
4927
- });
5442
+ const items = await fg(
5443
+ path4.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"),
5444
+ {
5445
+ dot: true
5446
+ }
5447
+ );
4928
5448
  const posixRootPath = normalize(this.outputPath);
4929
5449
  return items.map((item) => {
4930
5450
  return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
@@ -5134,7 +5654,14 @@ var IsomorphicBridge = class {
5134
5654
  if (lastIdx === 0) {
5135
5655
  return updatedParentOid;
5136
5656
  } else {
5137
- return await this.updateTreeHierarchy(parentOid, updatedParentOid, parentPath, "tree", pathEntries.slice(0, lastIdx), pathParts.slice(0, lastIdx));
5657
+ return await this.updateTreeHierarchy(
5658
+ parentOid,
5659
+ updatedParentOid,
5660
+ parentPath,
5661
+ "tree",
5662
+ pathEntries.slice(0, lastIdx),
5663
+ pathParts.slice(0, lastIdx)
5664
+ );
5138
5665
  }
5139
5666
  }
5140
5667
  async commitTree(treeSha, ref) {
@@ -5169,7 +5696,15 @@ var IsomorphicBridge = class {
5169
5696
  fullname: true
5170
5697
  });
5171
5698
  if (!ref) {
5172
- throw new GraphQLError5(`Unable to determine current branch from HEAD`, null, null, null, null, null, {});
5699
+ throw new GraphQLError5(
5700
+ `Unable to determine current branch from HEAD`,
5701
+ null,
5702
+ null,
5703
+ null,
5704
+ null,
5705
+ null,
5706
+ {}
5707
+ );
5173
5708
  }
5174
5709
  this.ref = ref;
5175
5710
  return ref;
@@ -5177,7 +5712,10 @@ var IsomorphicBridge = class {
5177
5712
  async glob(pattern, extension) {
5178
5713
  const ref = await this.getRef();
5179
5714
  const parent = globParent(this.qualifyPath(pattern));
5180
- const { pathParts, pathEntries } = await this.resolvePathEntries(parent, ref);
5715
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5716
+ parent,
5717
+ ref
5718
+ );
5181
5719
  const leafEntry = pathEntries[pathEntries.length - 1];
5182
5720
  const entryPath = pathParts[pathParts.length - 1];
5183
5721
  const parentEntry = pathEntries[pathEntries.length - 2];
@@ -5212,7 +5750,10 @@ var IsomorphicBridge = class {
5212
5750
  }
5213
5751
  async delete(filepath) {
5214
5752
  const ref = await this.getRef();
5215
- const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
5753
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5754
+ this.qualifyPath(filepath),
5755
+ ref
5756
+ );
5216
5757
  let oidToRemove;
5217
5758
  let ptr = pathEntries.length - 1;
5218
5759
  while (ptr >= 1) {
@@ -5227,7 +5768,9 @@ var IsomorphicBridge = class {
5227
5768
  oid: existingOid,
5228
5769
  cache: this.cache
5229
5770
  });
5230
- const updatedTree = treeResult.tree.filter((value) => value.path !== nodePath);
5771
+ const updatedTree = treeResult.tree.filter(
5772
+ (value) => value.path !== nodePath
5773
+ );
5231
5774
  if (updatedTree.length === 0) {
5232
5775
  ptr -= 1;
5233
5776
  continue;
@@ -5236,11 +5779,26 @@ var IsomorphicBridge = class {
5236
5779
  ...this.isomorphicConfig,
5237
5780
  tree: updatedTree
5238
5781
  });
5239
- const updatedRootTreeOid = await this.updateTreeHierarchy(existingOid, updatedTreeOid, pathParts[ptr - 1], "tree", pathEntries.slice(0, ptr - 1), pathParts.slice(0, ptr - 1));
5782
+ const updatedRootTreeOid = await this.updateTreeHierarchy(
5783
+ existingOid,
5784
+ updatedTreeOid,
5785
+ pathParts[ptr - 1],
5786
+ "tree",
5787
+ pathEntries.slice(0, ptr - 1),
5788
+ pathParts.slice(0, ptr - 1)
5789
+ );
5240
5790
  await this.commitTree(updatedRootTreeOid, ref);
5241
5791
  break;
5242
5792
  } else {
5243
- throw new GraphQLError5(`Unable to resolve path: ${filepath}`, null, null, null, null, null, { status: 404 });
5793
+ throw new GraphQLError5(
5794
+ `Unable to resolve path: ${filepath}`,
5795
+ null,
5796
+ null,
5797
+ null,
5798
+ null,
5799
+ null,
5800
+ { status: 404 }
5801
+ );
5244
5802
  }
5245
5803
  }
5246
5804
  if (oidToRemove) {
@@ -5280,7 +5838,10 @@ var IsomorphicBridge = class {
5280
5838
  }
5281
5839
  async put(filepath, data) {
5282
5840
  const ref = await this.getRef();
5283
- const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
5841
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5842
+ this.qualifyPath(filepath),
5843
+ ref
5844
+ );
5284
5845
  const blobUpdate = toUint8Array(Buffer.from(data));
5285
5846
  let existingOid;
5286
5847
  const leafEntry = pathEntries[pathEntries.length - 1];
@@ -5297,7 +5858,14 @@ var IsomorphicBridge = class {
5297
5858
  ...this.isomorphicConfig,
5298
5859
  blob: blobUpdate
5299
5860
  });
5300
- const updatedRootSha = await this.updateTreeHierarchy(existingOid, updatedOid, nodePath, "blob", pathEntries.slice(0, pathEntries.length - 1), pathParts.slice(0, pathParts.length - 1));
5861
+ const updatedRootSha = await this.updateTreeHierarchy(
5862
+ existingOid,
5863
+ updatedOid,
5864
+ nodePath,
5865
+ "blob",
5866
+ pathEntries.slice(0, pathEntries.length - 1),
5867
+ pathParts.slice(0, pathParts.length - 1)
5868
+ );
5301
5869
  await this.commitTree(updatedRootSha, ref);
5302
5870
  await git.updateIndex({
5303
5871
  ...this.isomorphicConfig,