@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.js CHANGED
@@ -1,58 +1,30 @@
1
1
  var __create = Object.create;
2
2
  var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
5
  var __getProtoOf = Object.getPrototypeOf;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
25
- var __objRest = (source, exclude) => {
26
- var target = {};
27
- for (var prop in source)
28
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
- target[prop] = source[prop];
30
- if (source != null && __getOwnPropSymbols)
31
- for (var prop of __getOwnPropSymbols(source)) {
32
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
- target[prop] = source[prop];
34
- }
35
- return target;
36
- };
37
7
  var __export = (target, all) => {
38
- __markAsModule(target);
39
- for (var name2 in all)
40
- __defProp(target, name2, { get: all[name2], enumerable: true });
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
41
10
  };
42
- var __reExport = (target, module3, desc) => {
43
- if (module3 && typeof module3 === "object" || typeof module3 === "function") {
44
- for (let key of __getOwnPropNames(module3))
45
- if (!__hasOwnProp.call(target, key) && key !== "default")
46
- __defProp(target, key, { get: () => module3[key], enumerable: !(desc = __getOwnPropDesc(module3, key)) || desc.enumerable });
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
47
16
  }
48
- return target;
49
- };
50
- var __toModule = (module3) => {
51
- return __reExport(__markAsModule(__defProp(module3 != null ? __create(__getProtoOf(module3)) : {}, "default", module3 && module3.__esModule && "default" in module3 ? { get: () => module3.default, enumerable: true } : { value: module3, enumerable: true })), module3);
17
+ return to;
52
18
  };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
+ mod
22
+ ));
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
53
24
 
54
25
  // src/index.ts
55
- __export(exports, {
26
+ var src_exports = {};
27
+ __export(src_exports, {
56
28
  AuditFileSystemBridge: () => AuditFileSystemBridge,
57
29
  FilesystemBridge: () => FilesystemBridge,
58
30
  IsomorphicBridge: () => IsomorphicBridge,
@@ -73,21 +45,22 @@ __export(exports, {
73
45
  sequential: () => sequential,
74
46
  stringifyFile: () => stringifyFile
75
47
  });
76
- var import_fs_extra4 = __toModule(require("fs-extra"));
77
- var import_path6 = __toModule(require("path"));
78
- var import_graphql7 = __toModule(require("graphql"));
48
+ module.exports = __toCommonJS(src_exports);
49
+ var import_fs_extra4 = __toESM(require("fs-extra"));
50
+ var import_path6 = __toESM(require("path"));
51
+ var import_graphql7 = require("graphql");
79
52
 
80
53
  // src/build.ts
81
- var import_lodash3 = __toModule(require("lodash"));
82
- var import_fs_extra = __toModule(require("fs-extra"));
83
- var import_graphql2 = __toModule(require("graphql"));
54
+ var import_lodash3 = __toESM(require("lodash"));
55
+ var import_fs_extra = __toESM(require("fs-extra"));
56
+ var import_graphql2 = require("graphql");
84
57
 
85
58
  // src/ast-builder/index.ts
86
- var import_lodash = __toModule(require("lodash"));
59
+ var import_lodash = __toESM(require("lodash"));
87
60
 
88
61
  // src/util.ts
89
- var yup = __toModule(require("yup"));
90
- var import_graphql = __toModule(require("graphql"));
62
+ var yup = __toESM(require("yup"));
63
+ var import_graphql = require("graphql");
91
64
  var sequential = async (items, callback) => {
92
65
  const accum = [];
93
66
  if (!items) {
@@ -198,11 +171,11 @@ var SysFieldDefinition = {
198
171
  };
199
172
  var astBuilder = {
200
173
  FormFieldBuilder: ({
201
- name: name2,
174
+ name,
202
175
  additionalFields
203
176
  }) => {
204
177
  return astBuilder.ObjectTypeDefinition({
205
- name: name2,
178
+ name,
206
179
  interfaces: [astBuilder.NamedType({ name: "FormField" })],
207
180
  fields: [
208
181
  astBuilder.FieldDefinition({
@@ -225,14 +198,14 @@ var astBuilder = {
225
198
  });
226
199
  },
227
200
  ScalarTypeDefinition: ({
228
- name: name2,
201
+ name,
229
202
  description
230
203
  }) => {
231
204
  return {
232
205
  kind: "ScalarTypeDefinition",
233
206
  name: {
234
207
  kind: "Name",
235
- value: name2
208
+ value: name
236
209
  },
237
210
  description: {
238
211
  kind: "StringValue",
@@ -242,7 +215,7 @@ var astBuilder = {
242
215
  };
243
216
  },
244
217
  InputValueDefinition: ({
245
- name: name2,
218
+ name,
246
219
  type,
247
220
  list,
248
221
  required
@@ -259,12 +232,13 @@ var astBuilder = {
259
232
  kind: "InputValueDefinition",
260
233
  name: {
261
234
  kind: "Name",
262
- value: name2
235
+ value: name
263
236
  }
264
237
  };
265
238
  if (list) {
266
239
  if (required) {
267
- res = __spreadProps(__spreadValues({}, def), {
240
+ res = {
241
+ ...def,
268
242
  type: {
269
243
  kind: "ListType",
270
244
  type: {
@@ -272,27 +246,30 @@ var astBuilder = {
272
246
  type: namedType
273
247
  }
274
248
  }
275
- });
249
+ };
276
250
  } else {
277
- res = __spreadProps(__spreadValues({}, def), {
251
+ res = {
252
+ ...def,
278
253
  type: {
279
254
  kind: "ListType",
280
255
  type: namedType
281
256
  }
282
- });
257
+ };
283
258
  }
284
259
  } else {
285
260
  if (required) {
286
- res = __spreadProps(__spreadValues({}, def), {
261
+ res = {
262
+ ...def,
287
263
  type: {
288
264
  kind: "NonNullType",
289
265
  type: namedType
290
266
  }
291
- });
267
+ };
292
268
  } else {
293
- res = __spreadProps(__spreadValues({}, def), {
269
+ res = {
270
+ ...def,
294
271
  type: namedType
295
- });
272
+ };
296
273
  }
297
274
  }
298
275
  return res;
@@ -316,17 +293,17 @@ var astBuilder = {
316
293
  };
317
294
  },
318
295
  FieldNodeDefinition: ({
319
- name: name2,
296
+ name,
320
297
  type,
321
298
  args = [],
322
299
  list,
323
300
  required
324
301
  }) => ({
325
- name: { kind: "Name", value: name2 },
302
+ name: { kind: "Name", value: name },
326
303
  kind: "Field"
327
304
  }),
328
305
  FieldDefinition: ({
329
- name: name2,
306
+ name,
330
307
  type,
331
308
  args = [],
332
309
  list,
@@ -344,13 +321,14 @@ var astBuilder = {
344
321
  kind: "FieldDefinition",
345
322
  name: {
346
323
  kind: "Name",
347
- value: name2
324
+ value: name
348
325
  },
349
326
  arguments: args
350
327
  };
351
328
  if (list) {
352
329
  if (required) {
353
- res = __spreadProps(__spreadValues({}, def), {
330
+ res = {
331
+ ...def,
354
332
  type: {
355
333
  kind: "NonNullType",
356
334
  type: {
@@ -361,33 +339,36 @@ var astBuilder = {
361
339
  }
362
340
  }
363
341
  }
364
- });
342
+ };
365
343
  } else {
366
- res = __spreadProps(__spreadValues({}, def), {
344
+ res = {
345
+ ...def,
367
346
  type: {
368
347
  kind: "ListType",
369
348
  type: namedType
370
349
  }
371
- });
350
+ };
372
351
  }
373
352
  } else {
374
353
  if (required) {
375
- res = __spreadProps(__spreadValues({}, def), {
354
+ res = {
355
+ ...def,
376
356
  type: {
377
357
  kind: "NonNullType",
378
358
  type: namedType
379
359
  }
380
- });
360
+ };
381
361
  } else {
382
- res = __spreadProps(__spreadValues({}, def), {
362
+ res = {
363
+ ...def,
383
364
  type: namedType
384
- });
365
+ };
385
366
  }
386
367
  }
387
368
  return res;
388
369
  },
389
370
  InterfaceTypeDefinition: ({
390
- name: name2,
371
+ name,
391
372
  fields,
392
373
  description = ""
393
374
  }) => {
@@ -396,7 +377,7 @@ var astBuilder = {
396
377
  description: { kind: "StringValue", value: description },
397
378
  name: {
398
379
  kind: "Name",
399
- value: name2
380
+ value: name
400
381
  },
401
382
  interfaces: [],
402
383
  directives: [],
@@ -404,45 +385,45 @@ var astBuilder = {
404
385
  };
405
386
  },
406
387
  InputObjectTypeDefinition: ({
407
- name: name2,
388
+ name,
408
389
  fields
409
390
  }) => ({
410
391
  kind: "InputObjectTypeDefinition",
411
392
  name: {
412
393
  kind: "Name",
413
- value: name2
394
+ value: name
414
395
  },
415
396
  fields
416
397
  }),
417
398
  UnionTypeDefinition: ({
418
- name: name2,
399
+ name,
419
400
  types
420
401
  }) => ({
421
402
  kind: "UnionTypeDefinition",
422
403
  name: {
423
404
  kind: "Name",
424
- value: name2
405
+ value: name
425
406
  },
426
407
  directives: [],
427
- types: types.map((name3) => ({
408
+ types: types.map((name2) => ({
428
409
  kind: "NamedType",
429
410
  name: {
430
411
  kind: "Name",
431
- value: name3
412
+ value: name2
432
413
  }
433
414
  }))
434
415
  }),
435
- NamedType: ({ name: name2 }) => {
416
+ NamedType: ({ name }) => {
436
417
  return {
437
418
  kind: "NamedType",
438
419
  name: {
439
420
  kind: "Name",
440
- value: name2
421
+ value: name
441
422
  }
442
423
  };
443
424
  },
444
425
  ObjectTypeDefinition: ({
445
- name: name2,
426
+ name,
446
427
  fields,
447
428
  interfaces = [],
448
429
  directives = [],
@@ -453,16 +434,16 @@ var astBuilder = {
453
434
  directives,
454
435
  name: {
455
436
  kind: "Name",
456
- value: name2
437
+ value: name
457
438
  },
458
439
  fields
459
440
  }),
460
441
  FieldWithSelectionSetDefinition: ({
461
- name: name2,
442
+ name,
462
443
  selections
463
444
  }) => {
464
445
  return {
465
- name: { kind: "Name", value: name2 },
446
+ name: { kind: "Name", value: name },
466
447
  kind: "Field",
467
448
  selectionSet: {
468
449
  kind: "SelectionSet",
@@ -471,7 +452,7 @@ var astBuilder = {
471
452
  };
472
453
  },
473
454
  InlineFragmentDefinition: ({
474
- name: name2,
455
+ name,
475
456
  selections
476
457
  }) => {
477
458
  return {
@@ -484,13 +465,13 @@ var astBuilder = {
484
465
  kind: "NamedType",
485
466
  name: {
486
467
  kind: "Name",
487
- value: name2
468
+ value: name
488
469
  }
489
470
  }
490
471
  };
491
472
  },
492
473
  FragmentDefinition: ({
493
- name: name2,
474
+ name,
494
475
  fragmentName,
495
476
  selections
496
477
  }) => {
@@ -504,7 +485,7 @@ var astBuilder = {
504
485
  kind: "NamedType",
505
486
  name: {
506
487
  kind: "Name",
507
- value: name2
488
+ value: name
508
489
  }
509
490
  },
510
491
  directives: [],
@@ -1003,11 +984,14 @@ var astBuilder = {
1003
984
  };
1004
985
  },
1005
986
  toGraphQLAst: (ast) => {
1006
- const definitions = import_lodash.default.uniqBy([
1007
- ...extractInlineTypes(ast.query),
1008
- ...extractInlineTypes(ast.globalTemplates),
1009
- ...ast.definitions
1010
- ], (field) => field.name.value);
987
+ const definitions = import_lodash.default.uniqBy(
988
+ [
989
+ ...extractInlineTypes(ast.query),
990
+ ...extractInlineTypes(ast.globalTemplates),
991
+ ...ast.definitions
992
+ ],
993
+ (field) => field.name.value
994
+ );
1011
995
  return {
1012
996
  kind: "Document",
1013
997
  definitions
@@ -1041,7 +1025,7 @@ var extractInlineTypes = (item) => {
1041
1025
  return accumulator;
1042
1026
  }
1043
1027
  };
1044
- function* walk(maybeNode, visited = new WeakSet()) {
1028
+ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
1045
1029
  if (typeof maybeNode === "string") {
1046
1030
  return;
1047
1031
  }
@@ -1093,7 +1077,7 @@ function addNamespaceToSchema(maybeNode, namespace = []) {
1093
1077
  }
1094
1078
  }
1095
1079
  });
1096
- return __spreadProps(__spreadValues({}, newNode), { namespace });
1080
+ return { ...newNode, namespace };
1097
1081
  }
1098
1082
  var generateNamespacedFieldName = (names, suffix = "") => {
1099
1083
  return (suffix ? [...names, suffix] : names).map(capitalize).join("");
@@ -1332,7 +1316,7 @@ var Builder = class {
1332
1316
  constructor(config) {
1333
1317
  this.config = config;
1334
1318
  this.buildCollectionDefinition = async (collections) => {
1335
- const name2 = "collection";
1319
+ const name = "collection";
1336
1320
  const typeName = "Collection";
1337
1321
  const args = [
1338
1322
  astBuilder.InputValueDefinition({
@@ -1395,23 +1379,23 @@ var Builder = class {
1395
1379
  });
1396
1380
  return astBuilder.FieldDefinition({
1397
1381
  type,
1398
- name: name2,
1382
+ name,
1399
1383
  args,
1400
1384
  required: true
1401
1385
  });
1402
1386
  };
1403
1387
  this.buildMultiCollectionDefinition = async (collections) => {
1404
- const name2 = "collections";
1388
+ const name = "collections";
1405
1389
  const typeName = "Collection";
1406
1390
  return astBuilder.FieldDefinition({
1407
1391
  type: typeName,
1408
- name: name2,
1392
+ name,
1409
1393
  list: true,
1410
1394
  required: true
1411
1395
  });
1412
1396
  };
1413
1397
  this.multiNodeDocument = async () => {
1414
- const name2 = "node";
1398
+ const name = "node";
1415
1399
  const args = [
1416
1400
  astBuilder.InputValueDefinition({
1417
1401
  name: "id",
@@ -1423,7 +1407,7 @@ var Builder = class {
1423
1407
  resolveType: "nodeDocument"
1424
1408
  });
1425
1409
  return astBuilder.FieldDefinition({
1426
- name: name2,
1410
+ name,
1427
1411
  args,
1428
1412
  list: false,
1429
1413
  type: astBuilder.TYPES.Node,
@@ -1431,7 +1415,7 @@ var Builder = class {
1431
1415
  });
1432
1416
  };
1433
1417
  this.multiCollectionDocument = async (collections) => {
1434
- const name2 = "document";
1418
+ const name = "document";
1435
1419
  const args = [
1436
1420
  astBuilder.InputValueDefinition({
1437
1421
  name: "collection",
@@ -1447,7 +1431,7 @@ var Builder = class {
1447
1431
  collections
1448
1432
  });
1449
1433
  return astBuilder.FieldDefinition({
1450
- name: name2,
1434
+ name,
1451
1435
  args,
1452
1436
  list: false,
1453
1437
  type,
@@ -1552,7 +1536,7 @@ var Builder = class {
1552
1536
  });
1553
1537
  };
1554
1538
  this.collectionDocument = async (collection) => {
1555
- const name2 = NAMER.queryName([collection.name]);
1539
+ const name = NAMER.queryName([collection.name]);
1556
1540
  const type = await this._buildCollectionDocumentType(collection);
1557
1541
  const args = [
1558
1542
  astBuilder.InputValueDefinition({
@@ -1567,14 +1551,17 @@ var Builder = class {
1567
1551
  [NAMER.createName([collection.name])]: "create",
1568
1552
  [NAMER.updateName([collection.name])]: "update"
1569
1553
  });
1570
- return astBuilder.FieldDefinition({ type, name: name2, args, required: true });
1554
+ return astBuilder.FieldDefinition({ type, name, args, required: true });
1571
1555
  };
1572
1556
  this.collectionFragment = async (collection) => {
1573
- const name2 = NAMER.dataTypeName(collection.namespace);
1557
+ const name = NAMER.dataTypeName(collection.namespace);
1574
1558
  const fragmentName = NAMER.fragmentName(collection.namespace);
1575
- const selections = await this._getCollectionFragmentSelections(collection, 0);
1559
+ const selections = await this._getCollectionFragmentSelections(
1560
+ collection,
1561
+ 0
1562
+ );
1576
1563
  return astBuilder.FragmentDefinition({
1577
- name: name2,
1564
+ name,
1578
1565
  fragmentName,
1579
1566
  selections: filterSelections(selections)
1580
1567
  });
@@ -1656,7 +1643,12 @@ var Builder = class {
1656
1643
  directives: [],
1657
1644
  selectionSet: {
1658
1645
  kind: "SelectionSet",
1659
- selections: filterSelections(await this._getCollectionFragmentSelections(collection, depth + 1))
1646
+ selections: filterSelections(
1647
+ await this._getCollectionFragmentSelections(
1648
+ collection,
1649
+ depth + 1
1650
+ )
1651
+ )
1660
1652
  }
1661
1653
  });
1662
1654
  });
@@ -1751,28 +1743,35 @@ var Builder = class {
1751
1743
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
1752
1744
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
1753
1745
  if (templateInfo.type === "union") {
1754
- return this._buildObjectOrUnionData(__spreadValues({}, templateInfo), [
1755
- astBuilder.FieldDefinition({
1756
- name: "id",
1757
- required: true,
1758
- type: astBuilder.TYPES.ID
1759
- }),
1760
- astBuilder.FieldDefinition({
1761
- name: "_sys",
1762
- required: true,
1763
- type: astBuilder.TYPES.SystemInfo
1764
- }),
1765
- ...extraFields,
1766
- astBuilder.FieldDefinition({
1767
- name: "_values",
1768
- required: true,
1769
- type: "JSON"
1770
- })
1771
- ], [
1772
- astBuilder.NamedType({ name: astBuilder.TYPES.Node }),
1773
- astBuilder.NamedType({ name: astBuilder.TYPES.Document }),
1774
- ...extraInterfaces
1775
- ], collection);
1746
+ return this._buildObjectOrUnionData(
1747
+ {
1748
+ ...templateInfo
1749
+ },
1750
+ [
1751
+ astBuilder.FieldDefinition({
1752
+ name: "id",
1753
+ required: true,
1754
+ type: astBuilder.TYPES.ID
1755
+ }),
1756
+ astBuilder.FieldDefinition({
1757
+ name: "_sys",
1758
+ required: true,
1759
+ type: astBuilder.TYPES.SystemInfo
1760
+ }),
1761
+ ...extraFields,
1762
+ astBuilder.FieldDefinition({
1763
+ name: "_values",
1764
+ required: true,
1765
+ type: "JSON"
1766
+ })
1767
+ ],
1768
+ [
1769
+ astBuilder.NamedType({ name: astBuilder.TYPES.Node }),
1770
+ astBuilder.NamedType({ name: astBuilder.TYPES.Document }),
1771
+ ...extraInterfaces
1772
+ ],
1773
+ collection
1774
+ );
1776
1775
  }
1777
1776
  const fields = templateInfo.template.fields;
1778
1777
  const templateFields = await sequential(fields, async (field) => {
@@ -2061,7 +2060,9 @@ var Builder = class {
2061
2060
  const filter = await this._connectionFilterBuilder({
2062
2061
  fieldName: field.name,
2063
2062
  namespace: field.namespace,
2064
- collections: await this.tinaSchema.getCollectionsByName(field.collections)
2063
+ collections: await this.tinaSchema.getCollectionsByName(
2064
+ field.collections
2065
+ )
2065
2066
  });
2066
2067
  return astBuilder.InputValueDefinition({
2067
2068
  name: field.name,
@@ -2117,25 +2118,33 @@ var Builder = class {
2117
2118
  this._buildReferenceMutation = async (field) => {
2118
2119
  return astBuilder.InputObjectTypeDefinition({
2119
2120
  name: NAMER.dataMutationTypeName(field.namespace),
2120
- fields: await sequential(this.tinaSchema.getCollectionsByName(field.collections), async (collection) => {
2121
+ fields: await sequential(
2122
+ this.tinaSchema.getCollectionsByName(field.collections),
2123
+ async (collection) => {
2124
+ return astBuilder.InputValueDefinition({
2125
+ name: collection.name,
2126
+ type: NAMER.dataMutationTypeName([collection.name])
2127
+ });
2128
+ }
2129
+ )
2130
+ });
2131
+ };
2132
+ this._buildUpdateDocumentMutationParams = async (field) => {
2133
+ const fields = await sequential(
2134
+ this.tinaSchema.getCollectionsByName(field.collections),
2135
+ async (collection) => {
2121
2136
  return astBuilder.InputValueDefinition({
2122
2137
  name: collection.name,
2123
2138
  type: NAMER.dataMutationTypeName([collection.name])
2124
2139
  });
2140
+ }
2141
+ );
2142
+ fields.push(
2143
+ astBuilder.InputValueDefinition({
2144
+ name: "relativePath",
2145
+ type: astBuilder.TYPES.String
2125
2146
  })
2126
- });
2127
- };
2128
- this._buildUpdateDocumentMutationParams = async (field) => {
2129
- const fields = await sequential(this.tinaSchema.getCollectionsByName(field.collections), async (collection) => {
2130
- return astBuilder.InputValueDefinition({
2131
- name: collection.name,
2132
- type: NAMER.dataMutationTypeName([collection.name])
2133
- });
2134
- });
2135
- fields.push(astBuilder.InputValueDefinition({
2136
- name: "relativePath",
2137
- type: astBuilder.TYPES.String
2138
- }));
2147
+ );
2139
2148
  return astBuilder.InputObjectTypeDefinition({
2140
2149
  name: NAMER.dataMutationUpdateTypeName(field.namespace),
2141
2150
  fields
@@ -2143,20 +2152,27 @@ var Builder = class {
2143
2152
  };
2144
2153
  this._buildObjectOrUnionData = async (collectableTemplate, extraFields = [], extraInterfaces = [], collection) => {
2145
2154
  if (collectableTemplate.type === "union") {
2146
- const name2 = NAMER.dataTypeName(collectableTemplate.namespace);
2155
+ const name = NAMER.dataTypeName(collectableTemplate.namespace);
2147
2156
  const typeMap = {};
2148
- const types = await sequential(collectableTemplate.templates, async (template) => {
2149
- const type = await this._buildTemplateData(template, extraFields, extraInterfaces);
2150
- typeMap[template.namespace[template.namespace.length - 1]] = type.name.value;
2151
- return type;
2152
- });
2157
+ const types = await sequential(
2158
+ collectableTemplate.templates,
2159
+ async (template) => {
2160
+ const type = await this._buildTemplateData(
2161
+ template,
2162
+ extraFields,
2163
+ extraInterfaces
2164
+ );
2165
+ typeMap[template.namespace[template.namespace.length - 1]] = type.name.value;
2166
+ return type;
2167
+ }
2168
+ );
2153
2169
  await this.database.addToLookupMap({
2154
- type: name2,
2170
+ type: name,
2155
2171
  resolveType: "unionData",
2156
2172
  collection: collection == null ? void 0 : collection.name,
2157
2173
  typeMap
2158
2174
  });
2159
- return astBuilder.UnionTypeDefinition({ name: name2, types });
2175
+ return astBuilder.UnionTypeDefinition({ name, types });
2160
2176
  }
2161
2177
  return this._buildTemplateData(collectableTemplate.template);
2162
2178
  };
@@ -2186,7 +2202,9 @@ var Builder = class {
2186
2202
  type: await this._filterCollectionDocumentType(collection)
2187
2203
  });
2188
2204
  } else {
2189
- throw new Error(`Must provide either collection or collections to filter field builder`);
2205
+ throw new Error(
2206
+ `Must provide either collection or collections to filter field builder`
2207
+ );
2190
2208
  }
2191
2209
  return filter;
2192
2210
  };
@@ -2271,7 +2289,9 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2271
2289
  name: field.name,
2272
2290
  list: field.list,
2273
2291
  required: field.required,
2274
- type: await this._buildObjectOrUnionData(this.tinaSchema.getTemplatesForCollectable(field))
2292
+ type: await this._buildObjectOrUnionData(
2293
+ this.tinaSchema.getTemplatesForCollectable(field)
2294
+ )
2275
2295
  });
2276
2296
  case "rich-text":
2277
2297
  return astBuilder.FieldDefinition({
@@ -2281,23 +2301,29 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2281
2301
  type: astBuilder.TYPES.JSON
2282
2302
  });
2283
2303
  case "reference":
2284
- const name2 = NAMER.documentTypeName(field.namespace);
2304
+ const name = NAMER.documentTypeName(field.namespace);
2285
2305
  if (field.list) {
2286
2306
  console.warn(listWarningMsg);
2287
2307
  return this._buildMultiCollectionDocumentListDefinition({
2288
2308
  fieldName: field.name,
2289
2309
  namespace: field.namespace,
2290
2310
  nodeType: astBuilder.UnionTypeDefinition({
2291
- name: name2,
2292
- types: field.collections.map((collectionName) => NAMER.documentTypeName([collectionName]))
2311
+ name,
2312
+ types: field.collections.map(
2313
+ (collectionName) => NAMER.documentTypeName([collectionName])
2314
+ )
2293
2315
  }),
2294
- collections: this.tinaSchema.getCollectionsByName(field.collections),
2316
+ collections: this.tinaSchema.getCollectionsByName(
2317
+ field.collections
2318
+ ),
2295
2319
  connectionNamespace: field.namespace
2296
2320
  });
2297
2321
  } else {
2298
2322
  const type = await this._buildMultiCollectionDocumentDefinition({
2299
- fieldName: name2,
2300
- collections: this.tinaSchema.getCollectionsByName(field.collections)
2323
+ fieldName: name,
2324
+ collections: this.tinaSchema.getCollectionsByName(
2325
+ field.collections
2326
+ )
2301
2327
  });
2302
2328
  return astBuilder.FieldDefinition({
2303
2329
  name: field.name,
@@ -2367,12 +2393,12 @@ var filterSelections = (arr) => {
2367
2393
  };
2368
2394
 
2369
2395
  // src/schema/createSchema.ts
2370
- var import_schema_tools2 = __toModule(require("@tinacms/schema-tools"));
2396
+ var import_schema_tools2 = require("@tinacms/schema-tools");
2371
2397
 
2372
2398
  // src/schema/validate.ts
2373
- var import_lodash2 = __toModule(require("lodash"));
2374
- var yup2 = __toModule(require("yup"));
2375
- var import_schema_tools = __toModule(require("@tinacms/schema-tools"));
2399
+ var import_lodash2 = __toESM(require("lodash"));
2400
+ var yup2 = __toESM(require("yup"));
2401
+ var import_schema_tools = require("@tinacms/schema-tools");
2376
2402
  var FIELD_TYPES = [
2377
2403
  "string",
2378
2404
  "number",
@@ -2384,8 +2410,13 @@ var FIELD_TYPES = [
2384
2410
  "rich-text"
2385
2411
  ];
2386
2412
  var validateSchema = async (schema) => {
2387
- const schema2 = addNamespaceToSchema(import_lodash2.default.cloneDeep(schema));
2388
- const collections = await sequential(schema2.collections, async (collection) => validateCollection(collection));
2413
+ const schema2 = addNamespaceToSchema(
2414
+ import_lodash2.default.cloneDeep(schema)
2415
+ );
2416
+ const collections = await sequential(
2417
+ schema2.collections,
2418
+ async (collection) => validateCollection(collection)
2419
+ );
2389
2420
  validationCollectionsPathAndMatch(collections);
2390
2421
  if (schema2.config) {
2391
2422
  const config = (0, import_schema_tools.validateTinaCloudSchemaConfig)(schema2.config);
@@ -2419,7 +2450,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2419
2450
  r[a.path] = r[a.path] || [];
2420
2451
  r[a.path].push(a);
2421
2452
  return r;
2422
- }, Object.create(null));
2453
+ }, /* @__PURE__ */ Object.create(null));
2423
2454
  Object.keys(groupbyPath).forEach((key) => {
2424
2455
  const collectionsArr = groupbyPath[key];
2425
2456
  if (collectionsArr.length === 1) {
@@ -2446,14 +2477,22 @@ var validateCollection = async (collection) => {
2446
2477
  })
2447
2478
  });
2448
2479
  await collectionSchema.validate(collection);
2449
- const validCollection = await collectionSchema.cast(collection);
2480
+ const validCollection = await collectionSchema.cast(
2481
+ collection
2482
+ );
2450
2483
  if (validCollection.templates) {
2451
- templates = await sequential(validCollection.templates, async (template) => {
2452
- const fields2 = await sequential(template.fields, async (field) => {
2453
- return validateField(field);
2454
- });
2455
- return __spreadValues(__spreadValues({}, validCollection), fields2);
2456
- });
2484
+ templates = await sequential(
2485
+ validCollection.templates,
2486
+ async (template) => {
2487
+ const fields2 = await sequential(template.fields, async (field) => {
2488
+ return validateField(field);
2489
+ });
2490
+ return {
2491
+ ...validCollection,
2492
+ ...fields2
2493
+ };
2494
+ }
2495
+ );
2457
2496
  }
2458
2497
  if (validCollection.fields) {
2459
2498
  if (typeof validCollection.fields === "string") {
@@ -2462,9 +2501,10 @@ var validateCollection = async (collection) => {
2462
2501
  fields = await sequential(validCollection.fields, async (field) => {
2463
2502
  return validateField(field);
2464
2503
  });
2465
- return __spreadProps(__spreadValues({}, validCollection), {
2504
+ return {
2505
+ ...validCollection,
2466
2506
  fields
2467
- });
2507
+ };
2468
2508
  }
2469
2509
  return collection;
2470
2510
  };
@@ -2474,7 +2514,10 @@ var validateField = async (field) => {
2474
2514
  name: yup2.string().matches(/^[a-zA-Z0-9_]*$/, {
2475
2515
  message: (obj) => `Field's 'name' must match ${obj.regex} at ${messageName}`
2476
2516
  }).required(),
2477
- type: yup2.string().oneOf(FIELD_TYPES, (obj) => `'type' must be one of: ${obj.values}, but got '${obj.value}' at ${messageName}`)
2517
+ type: yup2.string().oneOf(
2518
+ FIELD_TYPES,
2519
+ (obj) => `'type' must be one of: ${obj.values}, but got '${obj.value}' at ${messageName}`
2520
+ )
2478
2521
  });
2479
2522
  await schema.validate(field);
2480
2523
  const validField = await schema.cast(field);
@@ -2482,137 +2525,123 @@ var validateField = async (field) => {
2482
2525
  };
2483
2526
 
2484
2527
  // package.json
2485
- var name = "@tinacms/graphql";
2486
- var version = "1.3.3";
2487
- var main = "dist/index.js";
2488
- var module2 = "dist/index.es.js";
2489
- var typings = "dist/index.d.ts";
2490
- var files = [
2491
- "package.json",
2492
- "dist"
2493
- ];
2494
- var exports = {
2495
- import: "./dist/index.es.js",
2496
- require: "./dist/index.js"
2497
- };
2498
- var license = "SEE LICENSE IN LICENSE";
2499
- var buildConfig = {
2500
- entryPoints: [
2501
- {
2502
- name: "src/index.ts",
2503
- target: "node",
2504
- bundle: []
2505
- }
2506
- ]
2507
- };
2508
- var scripts = {
2509
- types: "pnpm tsc",
2510
- build: "tinacms-scripts build",
2511
- docs: "yarn typedoc",
2512
- serve: "yarn nodemon dist/server.js",
2513
- test: "jest",
2514
- "test-watch": "jest --watch"
2515
- };
2516
- var dependencies = {
2517
- "@graphql-tools/relay-operation-optimizer": "^6.4.1",
2518
- "@iarna/toml": "^2.2.5",
2519
- "@tinacms/mdx": "workspace:*",
2520
- "@tinacms/schema-tools": "workspace:*",
2521
- "abstract-level": "^1.0.3",
2522
- "body-parser": "^1.19.0",
2523
- cors: "^2.8.5",
2524
- dataloader: "^2.0.0",
2525
- "date-fns": "^2.21.1",
2526
- "encoding-down": "^7.1.0",
2527
- esbuild: "^0.12.25",
2528
- "esbuild-jest": "^0.5.0",
2529
- "estree-walker": "^3.0.0",
2530
- "fast-glob": "^3.2.5",
2531
- flat: "^5.0.2",
2532
- "fs-extra": "^9.0.1",
2533
- "glob-parent": "^6.0.2",
2534
- graphql: "15.8.0",
2535
- "graphql-type-json": "^0.3.2",
2536
- "gray-matter": "^4.0.2",
2537
- "isomorphic-git": "^1.21.0",
2538
- "js-yaml": "^3.14.1",
2539
- "jsonpath-plus": "^6.0.1",
2540
- leveldown: "^6.1.0",
2541
- lodash: "^4.17.20",
2542
- "many-level": "^2.0.0",
2543
- mdast: "^3.0.0",
2544
- "mdast-util-from-markdown": "^1.0.0",
2545
- "mdast-util-mdx": "^1.1.0",
2546
- "mdast-util-mdx-expression": "^1.1.0",
2547
- "mdast-util-to-markdown": "^1.2.1",
2548
- "micromark-extension-mdxjs": "^1.0.0",
2549
- "normalize-path": "^3.0.0",
2550
- prettier: "^2.2.1",
2551
- "readable-stream": "^4.3.0",
2552
- "rehype-format": "^3.1.0",
2553
- "rehype-stringify": "^8.0.0",
2554
- remark: "^13.0.0",
2555
- "remark-frontmatter": "^3.0.0",
2556
- "remark-mdx": "next",
2557
- "remark-parse": "^10.0.0",
2558
- "remark-rehype": "^8.0.0",
2559
- "remark-slate": "^1.8.0",
2560
- "remark-stringify": "^8.1.1",
2561
- unified: "^10.1.0",
2562
- "unist-util-remove-position": "^3.0.0",
2563
- "unist-util-visit": "^4.0.0",
2564
- vfile: "^4.2.0",
2565
- ws: "^7.3.1",
2566
- yup: "^0.32.9"
2567
- };
2568
- var publishConfig = {
2569
- registry: "https://registry.npmjs.org"
2570
- };
2571
- var repository = {
2572
- url: "https://github.com/tinacms/tinacms.git",
2573
- directory: "packages/tina-graphql"
2574
- };
2575
- var devDependencies = {
2576
- "@tinacms/schema-tools": "workspace:*",
2577
- "@tinacms/scripts": "workspace:*",
2578
- "@types/cors": "^2.8.7",
2579
- "@types/estree": "^0.0.50",
2580
- "@types/express": "^4.17.8",
2581
- "@types/fs-extra": "^9.0.2",
2582
- "@types/jest": "^26.0.4",
2583
- "@types/js-yaml": "^3.12.5",
2584
- "@types/lodash": "^4.14.161",
2585
- "@types/lodash.camelcase": "^4.3.6",
2586
- "@types/lodash.upperfirst": "^4.3.6",
2587
- "@types/lru-cache": "^5.1.0",
2588
- "@types/mdast": "^3.0.10",
2589
- "@types/node": "^14.17.34",
2590
- "@types/normalize-path": "^3.0.0",
2591
- "@types/ws": "^7.2.6",
2592
- "@types/yup": "^0.29.7",
2593
- jest: "27.0.6",
2594
- "jest-diff": "27.0.6",
2595
- "jest-file-snapshot": "^0.5.0",
2596
- "jest-matcher-utils": "27.0.6",
2597
- "memory-level": "^1.0.0",
2598
- nodemon: "2.0.19",
2599
- typescript: "4.3.5"
2600
- };
2601
2528
  var package_default = {
2602
- name,
2603
- version,
2604
- main,
2605
- module: module2,
2606
- typings,
2607
- files,
2608
- exports,
2609
- license,
2610
- buildConfig,
2611
- scripts,
2612
- dependencies,
2613
- publishConfig,
2614
- repository,
2615
- devDependencies
2529
+ name: "@tinacms/graphql",
2530
+ version: "1.3.4",
2531
+ main: "dist/index.js",
2532
+ module: "dist/index.es.js",
2533
+ typings: "dist/index.d.ts",
2534
+ files: [
2535
+ "package.json",
2536
+ "dist"
2537
+ ],
2538
+ exports: {
2539
+ import: "./dist/index.es.js",
2540
+ require: "./dist/index.js"
2541
+ },
2542
+ license: "SEE LICENSE IN LICENSE",
2543
+ buildConfig: {
2544
+ entryPoints: [
2545
+ {
2546
+ name: "src/index.ts",
2547
+ target: "node",
2548
+ bundle: []
2549
+ }
2550
+ ]
2551
+ },
2552
+ scripts: {
2553
+ types: "pnpm tsc",
2554
+ build: "tinacms-scripts build",
2555
+ docs: "yarn typedoc",
2556
+ serve: "yarn nodemon dist/server.js",
2557
+ test: "jest",
2558
+ "test-watch": "jest --watch"
2559
+ },
2560
+ dependencies: {
2561
+ "@graphql-tools/relay-operation-optimizer": "^6.4.1",
2562
+ "@iarna/toml": "^2.2.5",
2563
+ "@tinacms/mdx": "workspace:*",
2564
+ "@tinacms/schema-tools": "workspace:*",
2565
+ "abstract-level": "^1.0.3",
2566
+ "body-parser": "^1.19.0",
2567
+ cors: "^2.8.5",
2568
+ dataloader: "^2.0.0",
2569
+ "date-fns": "^2.21.1",
2570
+ "encoding-down": "^7.1.0",
2571
+ esbuild: "^0.15.5",
2572
+ "esbuild-jest": "^0.5.0",
2573
+ "estree-walker": "^3.0.0",
2574
+ "fast-glob": "^3.2.5",
2575
+ flat: "^5.0.2",
2576
+ "fs-extra": "^9.0.1",
2577
+ "glob-parent": "^6.0.2",
2578
+ graphql: "15.8.0",
2579
+ "graphql-type-json": "^0.3.2",
2580
+ "gray-matter": "^4.0.2",
2581
+ "isomorphic-git": "^1.21.0",
2582
+ "js-yaml": "^3.14.1",
2583
+ "jsonpath-plus": "^6.0.1",
2584
+ leveldown: "^6.1.0",
2585
+ lodash: "^4.17.20",
2586
+ "many-level": "^2.0.0",
2587
+ mdast: "^3.0.0",
2588
+ "mdast-util-from-markdown": "^1.0.0",
2589
+ "mdast-util-mdx": "^1.1.0",
2590
+ "mdast-util-mdx-expression": "^1.1.0",
2591
+ "mdast-util-to-markdown": "^1.2.1",
2592
+ "micromark-extension-mdxjs": "^1.0.0",
2593
+ "normalize-path": "^3.0.0",
2594
+ prettier: "^2.2.1",
2595
+ "readable-stream": "^4.3.0",
2596
+ "rehype-format": "^3.1.0",
2597
+ "rehype-stringify": "^8.0.0",
2598
+ remark: "^13.0.0",
2599
+ "remark-frontmatter": "^3.0.0",
2600
+ "remark-mdx": "next",
2601
+ "remark-parse": "^10.0.0",
2602
+ "remark-rehype": "^8.0.0",
2603
+ "remark-slate": "^1.8.0",
2604
+ "remark-stringify": "^8.1.1",
2605
+ unified: "^10.1.0",
2606
+ "unist-util-remove-position": "^3.0.0",
2607
+ "unist-util-visit": "^4.0.0",
2608
+ vfile: "^4.2.0",
2609
+ ws: "^7.3.1",
2610
+ yup: "^0.32.9"
2611
+ },
2612
+ publishConfig: {
2613
+ registry: "https://registry.npmjs.org"
2614
+ },
2615
+ repository: {
2616
+ url: "https://github.com/tinacms/tinacms.git",
2617
+ directory: "packages/tina-graphql"
2618
+ },
2619
+ devDependencies: {
2620
+ "@tinacms/schema-tools": "workspace:*",
2621
+ "@tinacms/scripts": "workspace:*",
2622
+ "@types/cors": "^2.8.7",
2623
+ "@types/estree": "^0.0.50",
2624
+ "@types/express": "^4.17.8",
2625
+ "@types/fs-extra": "^9.0.2",
2626
+ "@types/jest": "^26.0.4",
2627
+ "@types/js-yaml": "^3.12.5",
2628
+ "@types/lodash": "^4.14.161",
2629
+ "@types/lodash.camelcase": "^4.3.6",
2630
+ "@types/lodash.upperfirst": "^4.3.6",
2631
+ "@types/lru-cache": "^5.1.0",
2632
+ "@types/mdast": "^3.0.10",
2633
+ "@types/node": "^14.17.34",
2634
+ "@types/normalize-path": "^3.0.0",
2635
+ "@types/ws": "^7.2.6",
2636
+ "@types/yup": "^0.29.7",
2637
+ jest: "27.0.6",
2638
+ "jest-diff": "27.0.6",
2639
+ "jest-file-snapshot": "^0.5.0",
2640
+ "jest-matcher-utils": "27.0.6",
2641
+ "memory-level": "^1.0.0",
2642
+ nodemon: "2.0.19",
2643
+ typescript: "4.3.5"
2644
+ }
2616
2645
  };
2617
2646
 
2618
2647
  // src/schema/createSchema.ts
@@ -2626,19 +2655,20 @@ var createSchema = async ({
2626
2655
  if (flags && flags.length > 0) {
2627
2656
  meta["flags"] = flags;
2628
2657
  }
2629
- return new import_schema_tools2.TinaSchema(__spreadValues({
2658
+ return new import_schema_tools2.TinaSchema({
2630
2659
  version: {
2631
2660
  fullVersion: package_default.version,
2632
2661
  major,
2633
2662
  minor,
2634
2663
  patch
2635
2664
  },
2636
- meta
2637
- }, validSchema));
2665
+ meta,
2666
+ ...validSchema
2667
+ });
2638
2668
  };
2639
2669
 
2640
2670
  // src/build.ts
2641
- var import_path = __toModule(require("path"));
2671
+ var import_path = __toESM(require("path"));
2642
2672
  var buildDotTinaFiles = async ({
2643
2673
  database,
2644
2674
  config,
@@ -2658,7 +2688,9 @@ var buildDotTinaFiles = async ({
2658
2688
  graphQLSchema = await _buildSchema(builder, tinaSchema);
2659
2689
  await database.putConfigFiles({ graphQLSchema, tinaSchema });
2660
2690
  } else {
2661
- graphQLSchema = JSON.parse(await database.bridge.get(".tina/__generated__/_graphql.json"));
2691
+ graphQLSchema = JSON.parse(
2692
+ await database.bridge.get(".tina/__generated__/_graphql.json")
2693
+ );
2662
2694
  }
2663
2695
  if (buildSDK) {
2664
2696
  await _buildFragments(builder, tinaSchema, database.bridge.rootPath);
@@ -2670,25 +2702,34 @@ var _buildFragments = async (builder, tinaSchema, rootPath) => {
2670
2702
  const fragmentDefinitionsFields = [];
2671
2703
  const collections = tinaSchema.getCollections();
2672
2704
  await sequential(collections, async (collection) => {
2673
- const frag = await builder.collectionFragment(collection);
2705
+ const frag = await builder.collectionFragment(
2706
+ collection
2707
+ );
2674
2708
  fragmentDefinitionsFields.push(frag);
2675
2709
  });
2676
2710
  const fragDoc = {
2677
2711
  kind: "Document",
2678
- definitions: import_lodash3.default.uniqBy(extractInlineTypes(fragmentDefinitionsFields), (node) => node.name.value)
2712
+ definitions: import_lodash3.default.uniqBy(
2713
+ extractInlineTypes(fragmentDefinitionsFields),
2714
+ (node) => node.name.value
2715
+ )
2679
2716
  };
2680
2717
  const fragPath = import_path.default.join(rootPath, ".tina", "__generated__");
2681
2718
  await import_fs_extra.default.outputFile(import_path.default.join(fragPath, "frags.gql"), (0, import_graphql2.print)(fragDoc));
2682
2719
  if (await (await import_fs_extra.default.stat(import_path.default.join(fragPath, "frags.gql"))).size > 100 * 1024) {
2683
- console.warn("Warning: frags.gql is very large (>100kb). Consider setting the reference depth to 1 or 0. See code snippet below.");
2684
- console.log(`const schema = defineSchema({
2720
+ console.warn(
2721
+ "Warning: frags.gql is very large (>100kb). Consider setting the reference depth to 1 or 0. See code snippet below."
2722
+ );
2723
+ console.log(
2724
+ `const schema = defineSchema({
2685
2725
  config: {
2686
2726
  client: {
2687
2727
  referenceDepth: 1,
2688
2728
  },
2689
2729
  }
2690
2730
  // ...
2691
- })`);
2731
+ })`
2732
+ );
2692
2733
  }
2693
2734
  };
2694
2735
  var _buildQueries = async (builder, tinaSchema, rootPath) => {
@@ -2700,17 +2741,26 @@ var _buildQueries = async (builder, tinaSchema, rootPath) => {
2700
2741
  const queryListName = NAMER.generateQueryListName(collection.namespace);
2701
2742
  const queryFilterTypeName = NAMER.dataFilterTypeName(collection.namespace);
2702
2743
  const fragName = NAMER.fragmentName(collection.namespace);
2703
- operationsDefinitions.push(astBuilder.QueryOperationDefinition({ fragName, queryName }));
2704
- operationsDefinitions.push(astBuilder.ListQueryOperationDefinition({
2705
- fragName,
2706
- queryName: queryListName,
2707
- filterType: queryFilterTypeName,
2708
- dataLayer: Boolean((_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData"))
2709
- }));
2744
+ operationsDefinitions.push(
2745
+ astBuilder.QueryOperationDefinition({ fragName, queryName })
2746
+ );
2747
+ operationsDefinitions.push(
2748
+ astBuilder.ListQueryOperationDefinition({
2749
+ fragName,
2750
+ queryName: queryListName,
2751
+ filterType: queryFilterTypeName,
2752
+ dataLayer: Boolean(
2753
+ (_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
2754
+ )
2755
+ })
2756
+ );
2710
2757
  });
2711
2758
  const queryDoc = {
2712
2759
  kind: "Document",
2713
- definitions: import_lodash3.default.uniqBy(extractInlineTypes(operationsDefinitions), (node) => node.name.value)
2760
+ definitions: import_lodash3.default.uniqBy(
2761
+ extractInlineTypes(operationsDefinitions),
2762
+ (node) => node.name.value
2763
+ )
2714
2764
  };
2715
2765
  const fragPath = import_path.default.join(rootPath, ".tina", "__generated__");
2716
2766
  await import_fs_extra.default.outputFile(import_path.default.join(fragPath, "queries.gql"), (0, import_graphql2.print)(queryDoc));
@@ -2721,55 +2771,84 @@ var _buildSchema = async (builder, tinaSchema) => {
2721
2771
  const queryTypeDefinitionFields = [];
2722
2772
  const mutationTypeDefinitionFields = [];
2723
2773
  const collections = tinaSchema.getCollections();
2724
- queryTypeDefinitionFields.push(astBuilder.FieldDefinition({
2725
- name: "getOptimizedQuery",
2726
- args: [
2727
- astBuilder.InputValueDefinition({
2728
- name: "queryString",
2729
- type: astBuilder.TYPES.String,
2730
- required: true
2731
- })
2732
- ],
2733
- type: astBuilder.TYPES.String
2734
- }));
2735
- queryTypeDefinitionFields.push(await builder.buildCollectionDefinition(collections));
2736
- queryTypeDefinitionFields.push(await builder.buildMultiCollectionDefinition(collections));
2774
+ queryTypeDefinitionFields.push(
2775
+ astBuilder.FieldDefinition({
2776
+ name: "getOptimizedQuery",
2777
+ args: [
2778
+ astBuilder.InputValueDefinition({
2779
+ name: "queryString",
2780
+ type: astBuilder.TYPES.String,
2781
+ required: true
2782
+ })
2783
+ ],
2784
+ type: astBuilder.TYPES.String
2785
+ })
2786
+ );
2787
+ queryTypeDefinitionFields.push(
2788
+ await builder.buildCollectionDefinition(collections)
2789
+ );
2790
+ queryTypeDefinitionFields.push(
2791
+ await builder.buildMultiCollectionDefinition(collections)
2792
+ );
2737
2793
  queryTypeDefinitionFields.push(await builder.multiNodeDocument());
2738
- queryTypeDefinitionFields.push(await builder.multiCollectionDocument(collections));
2739
- mutationTypeDefinitionFields.push(await builder.addMultiCollectionDocumentMutation());
2740
- mutationTypeDefinitionFields.push(await builder.buildUpdateCollectionDocumentMutation(collections));
2741
- mutationTypeDefinitionFields.push(await builder.buildDeleteCollectionDocumentMutation(collections));
2742
- mutationTypeDefinitionFields.push(await builder.buildCreateCollectionDocumentMutation(collections));
2794
+ queryTypeDefinitionFields.push(
2795
+ await builder.multiCollectionDocument(collections)
2796
+ );
2797
+ mutationTypeDefinitionFields.push(
2798
+ await builder.addMultiCollectionDocumentMutation()
2799
+ );
2800
+ mutationTypeDefinitionFields.push(
2801
+ await builder.buildUpdateCollectionDocumentMutation(collections)
2802
+ );
2803
+ mutationTypeDefinitionFields.push(
2804
+ await builder.buildDeleteCollectionDocumentMutation(collections)
2805
+ );
2806
+ mutationTypeDefinitionFields.push(
2807
+ await builder.buildCreateCollectionDocumentMutation(collections)
2808
+ );
2743
2809
  await sequential(collections, async (collection) => {
2744
2810
  queryTypeDefinitionFields.push(await builder.collectionDocument(collection));
2745
- mutationTypeDefinitionFields.push(await builder.updateCollectionDocumentMutation(collection));
2746
- mutationTypeDefinitionFields.push(await builder.createCollectionDocumentMutation(collection));
2747
- queryTypeDefinitionFields.push(await builder.collectionDocumentList(collection));
2811
+ mutationTypeDefinitionFields.push(
2812
+ await builder.updateCollectionDocumentMutation(collection)
2813
+ );
2814
+ mutationTypeDefinitionFields.push(
2815
+ await builder.createCollectionDocumentMutation(collection)
2816
+ );
2817
+ queryTypeDefinitionFields.push(
2818
+ await builder.collectionDocumentList(collection)
2819
+ );
2748
2820
  });
2749
- definitions.push(astBuilder.ObjectTypeDefinition({
2750
- name: "Query",
2751
- fields: queryTypeDefinitionFields
2752
- }));
2753
- definitions.push(astBuilder.ObjectTypeDefinition({
2754
- name: "Mutation",
2755
- fields: mutationTypeDefinitionFields
2756
- }));
2821
+ definitions.push(
2822
+ astBuilder.ObjectTypeDefinition({
2823
+ name: "Query",
2824
+ fields: queryTypeDefinitionFields
2825
+ })
2826
+ );
2827
+ definitions.push(
2828
+ astBuilder.ObjectTypeDefinition({
2829
+ name: "Mutation",
2830
+ fields: mutationTypeDefinitionFields
2831
+ })
2832
+ );
2757
2833
  const doc = {
2758
2834
  kind: "Document",
2759
- definitions: import_lodash3.default.uniqBy(extractInlineTypes(definitions), (node) => node.name.value)
2835
+ definitions: import_lodash3.default.uniqBy(
2836
+ extractInlineTypes(definitions),
2837
+ (node) => node.name.value
2838
+ )
2760
2839
  };
2761
2840
  return doc;
2762
2841
  };
2763
2842
 
2764
2843
  // src/resolve.ts
2765
- var import_graphql4 = __toModule(require("graphql"));
2844
+ var import_graphql4 = require("graphql");
2766
2845
 
2767
2846
  // src/resolver/index.ts
2768
- var import_path2 = __toModule(require("path"));
2769
- var import_isValid = __toModule(require("date-fns/isValid"));
2847
+ var import_path2 = __toESM(require("path"));
2848
+ var import_isValid = __toESM(require("date-fns/isValid"));
2770
2849
 
2771
2850
  // src/mdx/index.ts
2772
- var import_mdx = __toModule(require("@tinacms/mdx"));
2851
+ var import_mdx = require("@tinacms/mdx");
2773
2852
 
2774
2853
  // src/resolver/error.ts
2775
2854
  var TinaGraphQLError = class extends Error {
@@ -2778,7 +2857,7 @@ var TinaGraphQLError = class extends Error {
2778
2857
  if (!this.name) {
2779
2858
  Object.defineProperty(this, "name", { value: "TinaGraphQLError" });
2780
2859
  }
2781
- this.extensions = __spreadValues({}, extensions);
2860
+ this.extensions = { ...extensions };
2782
2861
  }
2783
2862
  };
2784
2863
  var TinaFetchError = class extends Error {
@@ -2793,12 +2872,18 @@ var TinaFetchError = class extends Error {
2793
2872
  };
2794
2873
  var TinaQueryError = class extends TinaFetchError {
2795
2874
  constructor(args) {
2796
- super(`Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2875
+ super(
2876
+ `Error querying file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
2877
+ args
2878
+ );
2797
2879
  }
2798
2880
  };
2799
2881
  var TinaParseDocumentError = class extends TinaFetchError {
2800
2882
  constructor(args) {
2801
- super(`Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`, args);
2883
+ super(
2884
+ `Error parsing file ${args.file} from collection ${args.collection}. ${auditMessage(args.includeAuditMessage)}`,
2885
+ args
2886
+ );
2802
2887
  }
2803
2888
  toString() {
2804
2889
  return super.toString() + "\n OriginalError: \n" + this.originalError.toString();
@@ -2823,7 +2908,9 @@ var handleFetchErrorError = (e, verbose) => {
2823
2908
  // src/resolver/filter-utils.ts
2824
2909
  var resolveReferences = async (filter, fields, resolver) => {
2825
2910
  for (const fieldKey of Object.keys(filter)) {
2826
- const fieldDefinition = fields.find((f) => f.name === fieldKey);
2911
+ const fieldDefinition = fields.find(
2912
+ (f) => f.name === fieldKey
2913
+ );
2827
2914
  if (fieldDefinition) {
2828
2915
  if (fieldDefinition.type === "reference") {
2829
2916
  const { edges, values } = await resolver(filter, fieldDefinition);
@@ -2843,15 +2930,25 @@ var resolveReferences = async (filter, fields, resolver) => {
2843
2930
  } else if (fieldDefinition.type === "object") {
2844
2931
  if (fieldDefinition.templates) {
2845
2932
  for (const templateName of Object.keys(filter[fieldKey])) {
2846
- const template = fieldDefinition.templates.find((template2) => !(typeof template2 === "string") && template2.name === templateName);
2933
+ const template = fieldDefinition.templates.find(
2934
+ (template2) => !(typeof template2 === "string") && template2.name === templateName
2935
+ );
2847
2936
  if (template) {
2848
- await resolveReferences(filter[fieldKey][templateName], template.fields, resolver);
2937
+ await resolveReferences(
2938
+ filter[fieldKey][templateName],
2939
+ template.fields,
2940
+ resolver
2941
+ );
2849
2942
  } else {
2850
2943
  throw new Error(`Template ${templateName} not found`);
2851
2944
  }
2852
2945
  }
2853
2946
  } else {
2854
- await resolveReferences(filter[fieldKey], fieldDefinition.fields, resolver);
2947
+ await resolveReferences(
2948
+ filter[fieldKey],
2949
+ fieldDefinition.fields,
2950
+ resolver
2951
+ );
2855
2952
  }
2856
2953
  }
2857
2954
  } else {
@@ -2865,32 +2962,57 @@ var collectConditionsForChildFields = (filterNode, fields, pathExpression, colle
2865
2962
  if (!childField) {
2866
2963
  throw new Error(`Unable to find type for field ${childFieldName}`);
2867
2964
  }
2868
- collectConditionsForField(childFieldName, childField, filterNode[childFieldName], pathExpression, collectCondition);
2965
+ collectConditionsForField(
2966
+ childFieldName,
2967
+ childField,
2968
+ filterNode[childFieldName],
2969
+ pathExpression,
2970
+ collectCondition
2971
+ );
2869
2972
  }
2870
2973
  };
2871
2974
  var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
2872
2975
  if (field.list && field.templates) {
2873
2976
  for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
2874
- const template = field.templates.find((template2) => !(typeof template2 === "string") && template2.name === filterKey);
2977
+ const template = field.templates.find(
2978
+ (template2) => !(typeof template2 === "string") && template2.name === filterKey
2979
+ );
2875
2980
  const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
2876
2981
  const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
2877
- collectConditionsForChildFields(childFilterNode, template.fields, filterPath, collectCondition);
2982
+ collectConditionsForChildFields(
2983
+ childFilterNode,
2984
+ template.fields,
2985
+ filterPath,
2986
+ collectCondition
2987
+ );
2878
2988
  }
2879
2989
  } else {
2880
2990
  const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
2881
2991
  const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
2882
- collectConditionsForChildFields(filterNode, field.fields, filterPath, collectCondition);
2992
+ collectConditionsForChildFields(
2993
+ filterNode,
2994
+ field.fields,
2995
+ filterPath,
2996
+ collectCondition
2997
+ );
2883
2998
  }
2884
2999
  };
2885
3000
  var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
2886
3001
  if (field.type === "object") {
2887
- collectConditionsForObjectField(fieldName, field, filterNode, pathExpression, collectCondition);
3002
+ collectConditionsForObjectField(
3003
+ fieldName,
3004
+ field,
3005
+ filterNode,
3006
+ pathExpression,
3007
+ collectCondition
3008
+ );
2888
3009
  } else {
2889
3010
  collectCondition({
2890
3011
  filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
2891
- filterExpression: __spreadValues({
2892
- _type: field.type
2893
- }, filterNode)
3012
+ filterExpression: {
3013
+ _type: field.type,
3014
+ ...filterNode
3015
+ }
2894
3016
  });
2895
3017
  }
2896
3018
  };
@@ -2904,7 +3026,9 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
2904
3026
  if (hasTinaMediaConfig(schema) === true) {
2905
3027
  const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
2906
3028
  if (typeof value === "string" && value.includes(assetsURL)) {
2907
- const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
3029
+ const cleanMediaRoot = cleanUpSlashes(
3030
+ schema.config.media.tina.mediaRoot
3031
+ );
2908
3032
  const strippedURL = value.replace(assetsURL, "");
2909
3033
  return `${cleanMediaRoot}${strippedURL}`;
2910
3034
  }
@@ -2945,10 +3069,10 @@ var hasTinaMediaConfig = (schema) => {
2945
3069
  };
2946
3070
 
2947
3071
  // src/resolver/index.ts
2948
- var import_graphql3 = __toModule(require("graphql"));
3072
+ var import_graphql3 = require("graphql");
2949
3073
 
2950
3074
  // src/database/datalayer.ts
2951
- var import_jsonpath_plus = __toModule(require("jsonpath-plus"));
3075
+ var import_jsonpath_plus = require("jsonpath-plus");
2952
3076
 
2953
3077
  // src/database/level.ts
2954
3078
  var INDEX_KEY_FIELD_SEPARATOR = "";
@@ -2979,7 +3103,10 @@ var LevelProxyHandler = {
2979
3103
  };
2980
3104
  } else if (property === "sublevel") {
2981
3105
  return (...args) => {
2982
- return new Proxy(target[property].apply(target, args), LevelProxyHandler);
3106
+ return new Proxy(
3107
+ target[property].apply(target, args),
3108
+ LevelProxyHandler
3109
+ );
2983
3110
  };
2984
3111
  } else {
2985
3112
  return (...args) => target[property].apply(target, args);
@@ -2993,22 +3120,14 @@ var LevelProxy = class {
2993
3120
  };
2994
3121
 
2995
3122
  // src/database/datalayer.ts
2996
- var OP;
2997
- (function(OP2) {
2998
- OP2["EQ"] = "eq";
2999
- OP2["GT"] = "gt";
3000
- OP2["LT"] = "lt";
3001
- OP2["GTE"] = "gte";
3002
- OP2["LTE"] = "lte";
3003
- OP2["STARTS_WITH"] = "startsWith";
3004
- OP2["IN"] = "in";
3005
- })(OP || (OP = {}));
3006
3123
  var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
3007
3124
  var DEFAULT_NUMERIC_LPAD = 4;
3008
3125
  var applyPadding = (input, pad) => {
3009
3126
  if (pad) {
3010
3127
  if (Array.isArray(input)) {
3011
- return input.map((val) => String(val).padStart(pad.maxLength, pad.fillString));
3128
+ return input.map(
3129
+ (val) => String(val).padStart(pad.maxLength, pad.fillString)
3130
+ );
3012
3131
  } else {
3013
3132
  return String(input).padStart(pad.maxLength, pad.fillString);
3014
3133
  }
@@ -3021,23 +3140,23 @@ var getFilterOperator = (expression, operand) => {
3021
3140
  var inferOperatorFromFilter = (filterOperator) => {
3022
3141
  switch (filterOperator) {
3023
3142
  case "after":
3024
- return OP.GT;
3143
+ return "gt" /* GT */;
3025
3144
  case "before":
3026
- return OP.LT;
3145
+ return "lt" /* LT */;
3027
3146
  case "eq":
3028
- return OP.EQ;
3147
+ return "eq" /* EQ */;
3029
3148
  case "startsWith":
3030
- return OP.STARTS_WITH;
3149
+ return "startsWith" /* STARTS_WITH */;
3031
3150
  case "lt":
3032
- return OP.LT;
3151
+ return "lt" /* LT */;
3033
3152
  case "lte":
3034
- return OP.LTE;
3153
+ return "lte" /* LTE */;
3035
3154
  case "gt":
3036
- return OP.GT;
3155
+ return "gt" /* GT */;
3037
3156
  case "gte":
3038
- return OP.GTE;
3157
+ return "gte" /* GTE */;
3039
3158
  case "in":
3040
- return OP.IN;
3159
+ return "in" /* IN */;
3041
3160
  default:
3042
3161
  throw new Error(`unsupported filter condition: '${filterOperator}'`);
3043
3162
  }
@@ -3047,7 +3166,9 @@ var makeKeyForField = (definition, data, stringEscaper2, maxStringLength = 100)
3047
3166
  for (const field of definition.fields) {
3048
3167
  if (field.name in data && data[field.name] !== void 0 && data[field.name] !== null) {
3049
3168
  const rawValue = data[field.name];
3050
- const resolvedValue = String(field.type === "datetime" ? new Date(rawValue).getTime() : field.type === "string" ? stringEscaper2(rawValue) : rawValue).substring(0, maxStringLength);
3169
+ const resolvedValue = String(
3170
+ field.type === "datetime" ? new Date(rawValue).getTime() : field.type === "string" ? stringEscaper2(rawValue) : rawValue
3171
+ ).substring(0, maxStringLength);
3051
3172
  valueParts.push(applyPadding(resolvedValue, field.pad));
3052
3173
  } else {
3053
3174
  return null;
@@ -3062,34 +3183,54 @@ var coerceFilterChainOperands = (filterChain, escapeString = stringEscaper) => {
3062
3183
  const dataType = filter.type;
3063
3184
  if (dataType === "datetime") {
3064
3185
  if (filter.leftOperand !== void 0) {
3065
- result.push(__spreadProps(__spreadValues({}, filter), {
3186
+ result.push({
3187
+ ...filter,
3066
3188
  rightOperand: new Date(filter.rightOperand).getTime(),
3067
- leftOperand: new Date(filter.leftOperand).getTime()
3068
- }));
3189
+ leftOperand: new Date(
3190
+ filter.leftOperand
3191
+ ).getTime()
3192
+ });
3069
3193
  } else {
3070
3194
  if (Array.isArray(filter.rightOperand)) {
3071
- result.push(__spreadProps(__spreadValues({}, filter), {
3072
- rightOperand: filter.rightOperand.map((operand) => new Date(operand).getTime())
3073
- }));
3195
+ result.push({
3196
+ ...filter,
3197
+ rightOperand: filter.rightOperand.map(
3198
+ (operand) => new Date(operand).getTime()
3199
+ )
3200
+ });
3074
3201
  } else {
3075
- result.push(__spreadProps(__spreadValues({}, filter), {
3202
+ result.push({
3203
+ ...filter,
3076
3204
  rightOperand: new Date(filter.rightOperand).getTime()
3077
- }));
3205
+ });
3078
3206
  }
3079
3207
  }
3080
3208
  } else if (dataType === "string") {
3081
3209
  if (filter.leftOperand !== void 0) {
3082
- result.push(__spreadProps(__spreadValues({}, filter), {
3083
- rightOperand: applyPadding(escapeString(filter.rightOperand), filter.pad),
3084
- leftOperand: applyPadding(escapeString(filter.leftOperand), filter.pad)
3085
- }));
3210
+ result.push({
3211
+ ...filter,
3212
+ rightOperand: applyPadding(
3213
+ escapeString(filter.rightOperand),
3214
+ filter.pad
3215
+ ),
3216
+ leftOperand: applyPadding(
3217
+ escapeString(
3218
+ filter.leftOperand
3219
+ ),
3220
+ filter.pad
3221
+ )
3222
+ });
3086
3223
  } else {
3087
- result.push(__spreadProps(__spreadValues({}, filter), {
3088
- rightOperand: applyPadding(escapeString(filter.rightOperand), filter.pad)
3089
- }));
3224
+ result.push({
3225
+ ...filter,
3226
+ rightOperand: applyPadding(
3227
+ escapeString(filter.rightOperand),
3228
+ filter.pad
3229
+ )
3230
+ });
3090
3231
  }
3091
3232
  } else {
3092
- result.push(__spreadValues({}, filter));
3233
+ result.push({ ...filter });
3093
3234
  }
3094
3235
  }
3095
3236
  }
@@ -3119,7 +3260,9 @@ var makeFilter = ({
3119
3260
  return isNaN(coerced) ? Number(resolvedValue) : coerced;
3120
3261
  });
3121
3262
  } else if (dataType === "boolean") {
3122
- operands = resolvedValues.map((resolvedValue) => typeof resolvedValue === "boolean" && resolvedValue || resolvedValue === "true" || resolvedValue === "1");
3263
+ operands = resolvedValues.map(
3264
+ (resolvedValue) => typeof resolvedValue === "boolean" && resolvedValue || resolvedValue === "true" || resolvedValue === "1"
3265
+ );
3123
3266
  } else {
3124
3267
  throw new Error(`Unexpected datatype ${dataType}`);
3125
3268
  }
@@ -3127,12 +3270,14 @@ var makeFilter = ({
3127
3270
  let matches = false;
3128
3271
  if (operator) {
3129
3272
  switch (operator) {
3130
- case OP.EQ:
3131
- if (operands.findIndex((operand) => operand === filter.rightOperand) >= 0) {
3273
+ case "eq" /* EQ */:
3274
+ if (operands.findIndex(
3275
+ (operand) => operand === filter.rightOperand
3276
+ ) >= 0) {
3132
3277
  matches = true;
3133
3278
  }
3134
3279
  break;
3135
- case OP.GT:
3280
+ case "gt" /* GT */:
3136
3281
  for (const operand of operands) {
3137
3282
  if (operand > filter.rightOperand) {
3138
3283
  matches = true;
@@ -3140,7 +3285,7 @@ var makeFilter = ({
3140
3285
  }
3141
3286
  }
3142
3287
  break;
3143
- case OP.LT:
3288
+ case "lt" /* LT */:
3144
3289
  for (const operand of operands) {
3145
3290
  if (operand < filter.rightOperand) {
3146
3291
  matches = true;
@@ -3148,7 +3293,7 @@ var makeFilter = ({
3148
3293
  }
3149
3294
  }
3150
3295
  break;
3151
- case OP.GTE:
3296
+ case "gte" /* GTE */:
3152
3297
  for (const operand of operands) {
3153
3298
  if (operand >= filter.rightOperand) {
3154
3299
  matches = true;
@@ -3156,7 +3301,7 @@ var makeFilter = ({
3156
3301
  }
3157
3302
  }
3158
3303
  break;
3159
- case OP.LTE:
3304
+ case "lte" /* LTE */:
3160
3305
  for (const operand of operands) {
3161
3306
  if (operand <= filter.rightOperand) {
3162
3307
  matches = true;
@@ -3164,7 +3309,7 @@ var makeFilter = ({
3164
3309
  }
3165
3310
  }
3166
3311
  break;
3167
- case OP.IN:
3312
+ case "in" /* IN */:
3168
3313
  for (const operand of operands) {
3169
3314
  if (filter.rightOperand.indexOf(operand) >= 0) {
3170
3315
  matches = true;
@@ -3172,7 +3317,7 @@ var makeFilter = ({
3172
3317
  }
3173
3318
  }
3174
3319
  break;
3175
- case OP.STARTS_WITH:
3320
+ case "startsWith" /* STARTS_WITH */:
3176
3321
  for (const operand of operands) {
3177
3322
  if (operand.startsWith(filter.rightOperand)) {
3178
3323
  matches = true;
@@ -3188,14 +3333,14 @@ var makeFilter = ({
3188
3333
  for (const operand of operands) {
3189
3334
  let rightMatches = false;
3190
3335
  let leftMatches = false;
3191
- if (rightOperator === OP.LTE && operand <= rightOperand) {
3336
+ if (rightOperator === "lte" /* LTE */ && operand <= rightOperand) {
3192
3337
  rightMatches = true;
3193
- } else if (rightOperator === OP.LT && operand < rightOperand) {
3338
+ } else if (rightOperator === "lt" /* LT */ && operand < rightOperand) {
3194
3339
  rightMatches = true;
3195
3340
  }
3196
- if (leftOperator === OP.GTE && operand >= leftOperand) {
3341
+ if (leftOperator === "gte" /* GTE */ && operand >= leftOperand) {
3197
3342
  leftMatches = true;
3198
- } else if (leftOperator === OP.GT && operand > leftOperand) {
3343
+ } else if (leftOperator === "gt" /* GT */ && operand > leftOperand) {
3199
3344
  leftMatches = true;
3200
3345
  }
3201
3346
  if (rightMatches && leftMatches) {
@@ -3220,10 +3365,12 @@ var makeFilterChain = ({
3220
3365
  }
3221
3366
  for (const condition of conditions) {
3222
3367
  const { filterPath, filterExpression } = condition;
3223
- const _a = filterExpression, { _type } = _a, keys = __objRest(_a, ["_type"]);
3368
+ const { _type, ...keys } = filterExpression;
3224
3369
  const [key1, key2, ...extraKeys] = Object.keys(keys);
3225
3370
  if (extraKeys.length) {
3226
- throw new Error(`Unexpected keys: [${extraKeys.join(",")}] in filter expression`);
3371
+ throw new Error(
3372
+ `Unexpected keys: [${extraKeys.join(",")}] in filter expression`
3373
+ );
3227
3374
  }
3228
3375
  if (key1 && !key2) {
3229
3376
  filterChain.push({
@@ -3256,7 +3403,9 @@ var makeFilterChain = ({
3256
3403
  pad: _type === "number" ? { fillString: "0", maxLength: DEFAULT_NUMERIC_LPAD } : void 0
3257
3404
  });
3258
3405
  } else {
3259
- throw new Error(`Filter on field '${filterPath}' has invalid combination of conditions: '${key1}, ${key2}'`);
3406
+ throw new Error(
3407
+ `Filter on field '${filterPath}' has invalid combination of conditions: '${key1}, ${key2}'`
3408
+ );
3260
3409
  }
3261
3410
  }
3262
3411
  }
@@ -3271,7 +3420,7 @@ var makeFilterSuffixes = (filterChain, index) => {
3271
3420
  if (idx === -1) {
3272
3421
  return;
3273
3422
  }
3274
- if (filter.operator && filter.operator === OP.IN) {
3423
+ if (filter.operator && filter.operator === "in" /* IN */) {
3275
3424
  return;
3276
3425
  }
3277
3426
  orderedFilterChain[idx] = filter;
@@ -3293,20 +3442,34 @@ var makeFilterSuffixes = (filterChain, index) => {
3293
3442
  return;
3294
3443
  }
3295
3444
  const binaryFilter = filter;
3296
- if (binaryFilter.operator !== OP.EQ) {
3445
+ if (binaryFilter.operator !== "eq" /* EQ */) {
3297
3446
  return;
3298
3447
  }
3299
- baseFragments.push(applyPadding(orderedFilterChain[i].rightOperand, orderedFilterChain[i].pad));
3448
+ baseFragments.push(
3449
+ applyPadding(
3450
+ orderedFilterChain[i].rightOperand,
3451
+ orderedFilterChain[i].pad
3452
+ )
3453
+ );
3300
3454
  } else {
3301
3455
  if (ternaryFilter) {
3302
- leftSuffix = applyPadding(orderedFilterChain[i].leftOperand, orderedFilterChain[i].pad);
3303
- rightSuffix = applyPadding(orderedFilterChain[i].rightOperand, orderedFilterChain[i].pad);
3456
+ leftSuffix = applyPadding(
3457
+ orderedFilterChain[i].leftOperand,
3458
+ orderedFilterChain[i].pad
3459
+ );
3460
+ rightSuffix = applyPadding(
3461
+ orderedFilterChain[i].rightOperand,
3462
+ orderedFilterChain[i].pad
3463
+ );
3304
3464
  } else {
3305
3465
  const op = orderedFilterChain[i].operator;
3306
- const operand = applyPadding(orderedFilterChain[i].rightOperand, orderedFilterChain[i].pad);
3307
- if (op === OP.LT || op === OP.LTE) {
3466
+ const operand = applyPadding(
3467
+ orderedFilterChain[i].rightOperand,
3468
+ orderedFilterChain[i].pad
3469
+ );
3470
+ if (op === "lt" /* LT */ || op === "lte" /* LTE */) {
3308
3471
  rightSuffix = operand;
3309
- } else if (op === OP.GT || op === OP.GTE) {
3472
+ } else if (op === "gt" /* GT */ || op === "gte" /* GTE */) {
3310
3473
  leftSuffix = operand;
3311
3474
  } else {
3312
3475
  rightSuffix = operand;
@@ -3354,13 +3517,18 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
3354
3517
  var makeStringEscaper = (regex, replacement) => {
3355
3518
  return (input) => {
3356
3519
  if (Array.isArray(input)) {
3357
- return input.map((val) => val.replace(regex, replacement));
3520
+ return input.map(
3521
+ (val) => val.replace(regex, replacement)
3522
+ );
3358
3523
  } else {
3359
3524
  return input.replace(regex, replacement);
3360
3525
  }
3361
3526
  };
3362
3527
  };
3363
- var stringEscaper = makeStringEscaper(new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"), encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR));
3528
+ var stringEscaper = makeStringEscaper(
3529
+ new RegExp(INDEX_KEY_FIELD_SEPARATOR, "gm"),
3530
+ encodeURIComponent(INDEX_KEY_FIELD_SEPARATOR)
3531
+ );
3364
3532
 
3365
3533
  // src/resolver/index.ts
3366
3534
  var createResolver = (args) => {
@@ -3372,9 +3540,11 @@ var Resolver = class {
3372
3540
  this.resolveCollection = async (args, collectionName, hasDocuments) => {
3373
3541
  const collection = this.tinaSchema.getCollection(collectionName);
3374
3542
  const extraFields = {};
3375
- return __spreadValues(__spreadValues({
3376
- documents: { collection, hasDocuments }
3377
- }, collection), extraFields);
3543
+ return {
3544
+ documents: { collection, hasDocuments },
3545
+ ...collection,
3546
+ ...extraFields
3547
+ };
3378
3548
  };
3379
3549
  this.getDocument = async (fullPath) => {
3380
3550
  if (typeof fullPath !== "string") {
@@ -3418,10 +3588,10 @@ var Resolver = class {
3418
3588
  });
3419
3589
  const titleFieldName = titleField == null ? void 0 : titleField.name;
3420
3590
  const title = data[titleFieldName || " "] || null;
3421
- return __spreadProps(__spreadValues({
3591
+ return {
3422
3592
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
3423
- id: fullPath
3424
- }, data), {
3593
+ id: fullPath,
3594
+ ...data,
3425
3595
  _sys: {
3426
3596
  title,
3427
3597
  basename,
@@ -3435,12 +3605,13 @@ var Resolver = class {
3435
3605
  },
3436
3606
  _values: data,
3437
3607
  _rawData: rawData
3438
- });
3608
+ };
3439
3609
  } catch (e) {
3440
3610
  if (e instanceof TinaGraphQLError) {
3441
- throw new TinaGraphQLError(e.message, __spreadValues({
3442
- requestedDocument: fullPath
3443
- }, e.extensions));
3611
+ throw new TinaGraphQLError(e.message, {
3612
+ requestedDocument: fullPath,
3613
+ ...e.extensions
3614
+ });
3444
3615
  }
3445
3616
  throw e;
3446
3617
  }
@@ -3455,44 +3626,59 @@ var Resolver = class {
3455
3626
  if (field.fields) {
3456
3627
  const objectTemplate = field;
3457
3628
  if (Array.isArray(fieldValue)) {
3458
- return fieldValue.map((item) => this.buildFieldMutations(item, objectTemplate));
3629
+ return fieldValue.map(
3630
+ (item) => this.buildFieldMutations(item, objectTemplate)
3631
+ );
3459
3632
  } else {
3460
- return this.buildFieldMutations(fieldValue, objectTemplate);
3633
+ return this.buildFieldMutations(
3634
+ fieldValue,
3635
+ objectTemplate
3636
+ );
3461
3637
  }
3462
3638
  }
3463
3639
  if (field.templates) {
3464
3640
  if (Array.isArray(fieldValue)) {
3465
3641
  return fieldValue.map((item) => {
3466
3642
  if (typeof item === "string") {
3467
- throw new Error(`Expected object for template value for field ${field.name}`);
3643
+ throw new Error(
3644
+ `Expected object for template value for field ${field.name}`
3645
+ );
3468
3646
  }
3469
3647
  const templates = field.templates.map((templateOrTemplateName) => {
3470
3648
  return templateOrTemplateName;
3471
3649
  });
3472
3650
  const [templateName] = Object.entries(item)[0];
3473
- const template = templates.find((template2) => template2.name === templateName);
3651
+ const template = templates.find(
3652
+ (template2) => template2.name === templateName
3653
+ );
3474
3654
  if (!template) {
3475
3655
  throw new Error(`Expected to find template ${templateName}`);
3476
3656
  }
3477
- return __spreadProps(__spreadValues({}, this.buildFieldMutations(item[template.name], template)), {
3657
+ return {
3658
+ ...this.buildFieldMutations(item[template.name], template),
3478
3659
  _template: template.name
3479
- });
3660
+ };
3480
3661
  });
3481
3662
  } else {
3482
3663
  if (typeof fieldValue === "string") {
3483
- throw new Error(`Expected object for template value for field ${field.name}`);
3664
+ throw new Error(
3665
+ `Expected object for template value for field ${field.name}`
3666
+ );
3484
3667
  }
3485
3668
  const templates = field.templates.map((templateOrTemplateName) => {
3486
3669
  return templateOrTemplateName;
3487
3670
  });
3488
3671
  const [templateName] = Object.entries(fieldValue)[0];
3489
- const template = templates.find((template2) => template2.name === templateName);
3672
+ const template = templates.find(
3673
+ (template2) => template2.name === templateName
3674
+ );
3490
3675
  if (!template) {
3491
3676
  throw new Error(`Expected to find template ${templateName}`);
3492
3677
  }
3493
- return __spreadProps(__spreadValues({}, this.buildFieldMutations(fieldValue[template.name], template)), {
3678
+ return {
3679
+ ...this.buildFieldMutations(fieldValue[template.name], template),
3494
3680
  _template: template.name
3495
- });
3681
+ };
3496
3682
  }
3497
3683
  }
3498
3684
  };
@@ -3510,12 +3696,18 @@ var Resolver = class {
3510
3696
  break;
3511
3697
  case "union":
3512
3698
  const templateString = args.template;
3513
- const template = templateInfo.templates.find((template2) => lastItem(template2.namespace) === templateString);
3699
+ const template = templateInfo.templates.find(
3700
+ (template2) => lastItem(template2.namespace) === templateString
3701
+ );
3514
3702
  if (!args.template) {
3515
- 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(" ")}`);
3703
+ throw new Error(
3704
+ `Must specify a template when creating content for a collection with multiple templates. Possible templates are: ${templateInfo.templates.map((t) => lastItem(t.namespace)).join(" ")}`
3705
+ );
3516
3706
  }
3517
3707
  if (!template) {
3518
- 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(" ")}`);
3708
+ throw new Error(
3709
+ `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(" ")}`
3710
+ );
3519
3711
  }
3520
3712
  await this.database.addPendingDocument(realPath, {
3521
3713
  _template: lastItem(template.namespace)
@@ -3523,7 +3715,10 @@ var Resolver = class {
3523
3715
  }
3524
3716
  return this.getDocument(realPath);
3525
3717
  }
3526
- const params = this.buildObjectMutations(args.params[collection.name], collection);
3718
+ const params = this.buildObjectMutations(
3719
+ args.params[collection.name],
3720
+ collection
3721
+ );
3527
3722
  await this.database.put(realPath, params, collection.name);
3528
3723
  return this.getDocument(realPath);
3529
3724
  };
@@ -3542,8 +3737,15 @@ var Resolver = class {
3542
3737
  switch (templateInfo.type) {
3543
3738
  case "object":
3544
3739
  if (params2) {
3545
- const values = this.buildFieldMutations(params2, templateInfo.template);
3546
- await this.database.put(realPath, __spreadValues(__spreadValues({}, oldDoc), values), collection.name);
3740
+ const values = this.buildFieldMutations(
3741
+ params2,
3742
+ templateInfo.template
3743
+ );
3744
+ await this.database.put(
3745
+ realPath,
3746
+ { ...oldDoc, ...values },
3747
+ collection.name
3748
+ );
3547
3749
  }
3548
3750
  break;
3549
3751
  case "union":
@@ -3551,19 +3753,26 @@ var Resolver = class {
3551
3753
  const templateParams = params2[lastItem(template.namespace)];
3552
3754
  if (templateParams) {
3553
3755
  if (typeof templateParams === "string") {
3554
- throw new Error(`Expected to find an object for template params, but got string`);
3756
+ throw new Error(
3757
+ `Expected to find an object for template params, but got string`
3758
+ );
3555
3759
  }
3556
- const values = __spreadProps(__spreadValues(__spreadValues({}, oldDoc), this.buildFieldMutations(templateParams, template)), {
3760
+ const values = {
3761
+ ...oldDoc,
3762
+ ...this.buildFieldMutations(templateParams, template),
3557
3763
  _template: lastItem(template.namespace)
3558
- });
3764
+ };
3559
3765
  await this.database.put(realPath, values, collection.name);
3560
3766
  }
3561
3767
  });
3562
3768
  }
3563
3769
  return this.getDocument(realPath);
3564
3770
  }
3565
- const params = this.buildObjectMutations(isCollectionSpecific ? args.params : args.params[collection.name], collection);
3566
- await this.database.put(realPath, __spreadValues(__spreadValues({}, oldDoc), params), collection.name);
3771
+ const params = this.buildObjectMutations(
3772
+ isCollectionSpecific ? args.params : args.params[collection.name],
3773
+ collection
3774
+ );
3775
+ await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
3567
3776
  return this.getDocument(realPath);
3568
3777
  };
3569
3778
  this.resolveDocument = async ({
@@ -3581,10 +3790,19 @@ var Resolver = class {
3581
3790
  collectionLookup = Object.keys(args.params)[0];
3582
3791
  }
3583
3792
  const collectionNames = this.tinaSchema.getCollections().map((item) => item.name);
3584
- assertShape(collectionLookup, (yup3) => {
3585
- return yup3.mixed().oneOf(collectionNames);
3586
- }, `"collection" must be one of: [${collectionNames.join(", ")}] but got ${collectionLookup}`);
3587
- assertShape(args, (yup3) => yup3.object({ relativePath: yup3.string().required() }));
3793
+ assertShape(
3794
+ collectionLookup,
3795
+ (yup3) => {
3796
+ return yup3.mixed().oneOf(collectionNames);
3797
+ },
3798
+ `"collection" must be one of: [${collectionNames.join(
3799
+ ", "
3800
+ )}] but got ${collectionLookup}`
3801
+ );
3802
+ assertShape(
3803
+ args,
3804
+ (yup3) => yup3.object({ relativePath: yup3.string().required() })
3805
+ );
3588
3806
  const collection = await this.tinaSchema.getCollection(collectionLookup);
3589
3807
  const realPath = import_path2.default.join(collection == null ? void 0 : collection.path, args.relativePath);
3590
3808
  const alreadyExists = await this.database.documentExists(realPath);
@@ -3602,10 +3820,14 @@ var Resolver = class {
3602
3820
  }
3603
3821
  if (!alreadyExists) {
3604
3822
  if (isDeletion) {
3605
- throw new Error(`Unable to delete document, ${realPath} does not exist`);
3823
+ throw new Error(
3824
+ `Unable to delete document, ${realPath} does not exist`
3825
+ );
3606
3826
  }
3607
3827
  if (isUpdateName) {
3608
- throw new Error(`Unable to update document, ${realPath} does not exist`);
3828
+ throw new Error(
3829
+ `Unable to update document, ${realPath} does not exist`
3830
+ );
3609
3831
  }
3610
3832
  }
3611
3833
  if (isDeletion) {
@@ -3614,10 +3836,19 @@ var Resolver = class {
3614
3836
  return doc;
3615
3837
  }
3616
3838
  if (isUpdateName) {
3617
- assertShape(args, (yup3) => yup3.object({ params: yup3.object().required() }));
3618
- assertShape(args == null ? void 0 : args.params, (yup3) => yup3.object({ relativePath: yup3.string().required() }));
3839
+ assertShape(
3840
+ args,
3841
+ (yup3) => yup3.object({ params: yup3.object().required() })
3842
+ );
3843
+ assertShape(
3844
+ args == null ? void 0 : args.params,
3845
+ (yup3) => yup3.object({ relativePath: yup3.string().required() })
3846
+ );
3619
3847
  const doc = await this.getDocument(realPath);
3620
- const newRealPath = import_path2.default.join(collection == null ? void 0 : collection.path, args.params.relativePath);
3848
+ const newRealPath = import_path2.default.join(
3849
+ collection == null ? void 0 : collection.path,
3850
+ args.params.relativePath
3851
+ );
3621
3852
  await this.database.put(newRealPath, doc._rawData, collection.name);
3622
3853
  await this.deleteDocument(realPath);
3623
3854
  return this.getDocument(newRealPath);
@@ -3648,20 +3879,30 @@ var Resolver = class {
3648
3879
  };
3649
3880
  };
3650
3881
  this.referenceResolver = async (filter, fieldDefinition) => {
3651
- const referencedCollection = this.tinaSchema.getCollection(fieldDefinition.collections[0]);
3882
+ const referencedCollection = this.tinaSchema.getCollection(
3883
+ fieldDefinition.collections[0]
3884
+ );
3652
3885
  if (!referencedCollection) {
3653
- throw new Error(`Unable to find collection for ${fieldDefinition.collections[0]} querying ${fieldDefinition.name}`);
3886
+ throw new Error(
3887
+ `Unable to find collection for ${fieldDefinition.collections[0]} querying ${fieldDefinition.name}`
3888
+ );
3654
3889
  }
3655
- const sortKeys = Object.keys(filter[fieldDefinition.name][referencedCollection.name]);
3656
- const resolvedCollectionConnection = await this.resolveCollectionConnection({
3657
- args: {
3658
- sort: sortKeys.length === 1 ? sortKeys[0] : void 0,
3659
- filter: __spreadValues({}, filter[fieldDefinition.name][referencedCollection.name]),
3660
- first: -1
3661
- },
3662
- collection: referencedCollection,
3663
- hydrator: (path6) => path6
3664
- });
3890
+ const sortKeys = Object.keys(
3891
+ filter[fieldDefinition.name][referencedCollection.name]
3892
+ );
3893
+ const resolvedCollectionConnection = await this.resolveCollectionConnection(
3894
+ {
3895
+ args: {
3896
+ sort: sortKeys.length === 1 ? sortKeys[0] : void 0,
3897
+ filter: {
3898
+ ...filter[fieldDefinition.name][referencedCollection.name]
3899
+ },
3900
+ first: -1
3901
+ },
3902
+ collection: referencedCollection,
3903
+ hydrator: (path6) => path6
3904
+ }
3905
+ );
3665
3906
  const { edges } = resolvedCollectionConnection;
3666
3907
  const values = edges.map((edge) => edge.node);
3667
3908
  return { edges, values };
@@ -3674,14 +3915,26 @@ var Resolver = class {
3674
3915
  let conditions;
3675
3916
  if (args.filter) {
3676
3917
  if (collection.fields) {
3677
- conditions = await this.resolveFilterConditions(args.filter, collection.fields, collection.name);
3918
+ conditions = await this.resolveFilterConditions(
3919
+ args.filter,
3920
+ collection.fields,
3921
+ collection.name
3922
+ );
3678
3923
  } else if (collection.templates) {
3679
3924
  for (const templateName of Object.keys(args.filter)) {
3680
- const template = collection.templates.find((template2) => template2.name === templateName);
3925
+ const template = collection.templates.find(
3926
+ (template2) => template2.name === templateName
3927
+ );
3681
3928
  if (template) {
3682
- conditions = await this.resolveFilterConditions(args.filter[templateName], template.fields, `${collection.name}.${templateName}`);
3929
+ conditions = await this.resolveFilterConditions(
3930
+ args.filter[templateName],
3931
+ template.fields,
3932
+ `${collection.name}.${templateName}`
3933
+ );
3683
3934
  } else {
3684
- throw new Error(`Error template not found: ${templateName} in collection ${collection.name}`);
3935
+ throw new Error(
3936
+ `Error template not found: ${templateName} in collection ${collection.name}`
3937
+ );
3685
3938
  }
3686
3939
  }
3687
3940
  }
@@ -3697,7 +3950,10 @@ var Resolver = class {
3697
3950
  before: args.before,
3698
3951
  after: args.after
3699
3952
  };
3700
- const result = await this.database.query(queryOptions, hydrator ? hydrator : this.getDocument);
3953
+ const result = await this.database.query(
3954
+ queryOptions,
3955
+ hydrator ? hydrator : this.getDocument
3956
+ );
3701
3957
  const edges = result.edges;
3702
3958
  const pageInfo = result.pageInfo;
3703
3959
  return {
@@ -3734,13 +3990,25 @@ var Resolver = class {
3734
3990
  accum[fieldName] = fieldValue;
3735
3991
  break;
3736
3992
  case "image":
3737
- accum[fieldName] = resolveMediaCloudToRelative(fieldValue, this.config, this.tinaSchema.schema);
3993
+ accum[fieldName] = resolveMediaCloudToRelative(
3994
+ fieldValue,
3995
+ this.config,
3996
+ this.tinaSchema.schema
3997
+ );
3738
3998
  break;
3739
3999
  case "object":
3740
4000
  accum[fieldName] = this.buildObjectMutations(fieldValue, field);
3741
4001
  break;
3742
4002
  case "rich-text":
3743
- accum[fieldName] = (0, import_mdx.stringifyMDX)(fieldValue, field, (fieldValue2) => resolveMediaCloudToRelative(fieldValue2, this.config, this.tinaSchema.schema));
4003
+ accum[fieldName] = (0, import_mdx.stringifyMDX)(
4004
+ fieldValue,
4005
+ field,
4006
+ (fieldValue2) => resolveMediaCloudToRelative(
4007
+ fieldValue2,
4008
+ this.config,
4009
+ this.tinaSchema.schema
4010
+ )
4011
+ );
3744
4012
  break;
3745
4013
  case "reference":
3746
4014
  accum[fieldName] = fieldValue;
@@ -3751,9 +4019,8 @@ var Resolver = class {
3751
4019
  });
3752
4020
  return accum;
3753
4021
  };
3754
- this.resolveFieldData = async (_a, rawData, accumulator) => {
3755
- var _b = _a, { namespace } = _b, field = __objRest(_b, ["namespace"]);
3756
- var _a2;
4022
+ this.resolveFieldData = async ({ namespace, ...field }, rawData, accumulator) => {
4023
+ var _a;
3757
4024
  if (!rawData) {
3758
4025
  return void 0;
3759
4026
  }
@@ -3774,14 +4041,28 @@ var Resolver = class {
3774
4041
  accumulator[field.name] = value;
3775
4042
  break;
3776
4043
  case "image":
3777
- accumulator[field.name] = resolveMediaRelativeToCloud(value, this.config, this.tinaSchema.schema);
4044
+ accumulator[field.name] = resolveMediaRelativeToCloud(
4045
+ value,
4046
+ this.config,
4047
+ this.tinaSchema.schema
4048
+ );
3778
4049
  break;
3779
4050
  case "rich-text":
3780
- const tree = (0, import_mdx.parseMDX)(value, field, (value2) => resolveMediaRelativeToCloud(value2, this.config, this.tinaSchema.schema));
3781
- if (((_a2 = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _a2.type) === "invalid_markdown") {
4051
+ const tree = (0, import_mdx.parseMDX)(
4052
+ value,
4053
+ field,
4054
+ (value2) => resolveMediaRelativeToCloud(
4055
+ value2,
4056
+ this.config,
4057
+ this.tinaSchema.schema
4058
+ )
4059
+ );
4060
+ if (((_a = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _a.type) === "invalid_markdown") {
3782
4061
  if (this.isAudit) {
3783
4062
  const invalidNode = tree == null ? void 0 : tree.children[0];
3784
- throw new import_graphql3.GraphQLError(`${invalidNode == null ? void 0 : invalidNode.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`);
4063
+ throw new import_graphql3.GraphQLError(
4064
+ `${invalidNode == null ? void 0 : invalidNode.message}${invalidNode.position ? ` at line ${invalidNode.position.start.line}, column ${invalidNode.position.start.column}` : ""}`
4065
+ );
3785
4066
  }
3786
4067
  }
3787
4068
  accumulator[field.name] = tree;
@@ -3791,22 +4072,27 @@ var Resolver = class {
3791
4072
  if (!value) {
3792
4073
  return;
3793
4074
  }
3794
- assertShape(value, (yup3) => yup3.array().of(yup3.object().required()));
4075
+ assertShape(
4076
+ value,
4077
+ (yup3) => yup3.array().of(yup3.object().required())
4078
+ );
3795
4079
  accumulator[field.name] = await sequential(value, async (item) => {
3796
4080
  const template = await this.tinaSchema.getTemplateForData({
3797
4081
  data: item,
3798
- collection: __spreadValues({
3799
- namespace
3800
- }, field)
4082
+ collection: {
4083
+ namespace,
4084
+ ...field
4085
+ }
3801
4086
  });
3802
4087
  const payload = {};
3803
4088
  await sequential(template.fields, async (field2) => {
3804
4089
  await this.resolveFieldData(field2, item, payload);
3805
4090
  });
3806
4091
  const isUnion = !!field.templates;
3807
- return isUnion ? __spreadValues({
3808
- _template: lastItem(template.namespace)
3809
- }, payload) : payload;
4092
+ return isUnion ? {
4093
+ _template: lastItem(template.namespace),
4094
+ ...payload
4095
+ } : payload;
3810
4096
  });
3811
4097
  } else {
3812
4098
  if (!value) {
@@ -3814,18 +4100,20 @@ var Resolver = class {
3814
4100
  }
3815
4101
  const template = await this.tinaSchema.getTemplateForData({
3816
4102
  data: value,
3817
- collection: __spreadValues({
3818
- namespace
3819
- }, field)
4103
+ collection: {
4104
+ namespace,
4105
+ ...field
4106
+ }
3820
4107
  });
3821
4108
  const payload = {};
3822
4109
  await sequential(template.fields, async (field2) => {
3823
4110
  await this.resolveFieldData(field2, value, payload);
3824
4111
  });
3825
4112
  const isUnion = !!field.templates;
3826
- accumulator[field.name] = isUnion ? __spreadValues({
3827
- _template: lastItem(template.namespace)
3828
- }, payload) : payload;
4113
+ accumulator[field.name] = isUnion ? {
4114
+ _template: lastItem(template.namespace),
4115
+ ...payload
4116
+ } : payload;
3829
4117
  }
3830
4118
  break;
3831
4119
  default:
@@ -3835,16 +4123,22 @@ var Resolver = class {
3835
4123
  };
3836
4124
  this.buildParams = (args) => {
3837
4125
  try {
3838
- assertShape(args, (yup3) => yup3.object({
3839
- collection: yup3.string().required(),
3840
- params: yup3.object().required()
3841
- }));
4126
+ assertShape(
4127
+ args,
4128
+ (yup3) => yup3.object({
4129
+ collection: yup3.string().required(),
4130
+ params: yup3.object().required()
4131
+ })
4132
+ );
3842
4133
  return args.params[args.collection];
3843
4134
  } catch (e) {
3844
4135
  }
3845
- assertShape(args, (yup3) => yup3.object({
3846
- params: yup3.object().required()
3847
- }));
4136
+ assertShape(
4137
+ args,
4138
+ (yup3) => yup3.object({
4139
+ params: yup3.object().required()
4140
+ })
4141
+ );
3848
4142
  return args.params;
3849
4143
  };
3850
4144
  this.config = init.config;
@@ -3859,17 +4153,29 @@ var Resolver = class {
3859
4153
  throw new Error("Error parsing filter - unable to generate filterPath");
3860
4154
  }
3861
4155
  if (!condition.filterExpression) {
3862
- throw new Error(`Error parsing filter - missing expression for ${condition.filterPath}`);
4156
+ throw new Error(
4157
+ `Error parsing filter - missing expression for ${condition.filterPath}`
4158
+ );
3863
4159
  }
3864
4160
  conditions.push(condition);
3865
4161
  };
3866
4162
  await resolveReferences(filter, fields, this.referenceResolver);
3867
4163
  for (const fieldName of Object.keys(filter)) {
3868
- const field = fields.find((field2) => field2.name === fieldName);
4164
+ const field = fields.find(
4165
+ (field2) => field2.name === fieldName
4166
+ );
3869
4167
  if (!field) {
3870
- throw new Error(`${fieldName} not found in collection ${collectionName}`);
4168
+ throw new Error(
4169
+ `${fieldName} not found in collection ${collectionName}`
4170
+ );
3871
4171
  }
3872
- collectConditionsForField(fieldName, field, filter[fieldName], "", conditionCollector);
4172
+ collectConditionsForField(
4173
+ fieldName,
4174
+ field,
4175
+ filter[fieldName],
4176
+ "",
4177
+ conditionCollector
4178
+ );
3873
4179
  }
3874
4180
  return conditions;
3875
4181
  }
@@ -3883,7 +4189,7 @@ var resolveDateInput = (value) => {
3883
4189
  };
3884
4190
 
3885
4191
  // src/resolve.ts
3886
- var import_relay_operation_optimizer = __toModule(require("@graphql-tools/relay-operation-optimizer"));
4192
+ var import_relay_operation_optimizer = require("@graphql-tools/relay-operation-optimizer");
3887
4193
  var resolve = async ({
3888
4194
  config,
3889
4195
  query,
@@ -3940,32 +4246,54 @@ var resolve = async ({
3940
4246
  return value;
3941
4247
  }
3942
4248
  if (info.fieldName === "collections") {
3943
- const collectionNode2 = info.fieldNodes.find((x) => x.name.value === "collections");
3944
- const hasDocuments2 = collectionNode2.selectionSet.selections.find((x) => {
3945
- var _a3;
3946
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
3947
- });
4249
+ const collectionNode2 = info.fieldNodes.find(
4250
+ (x) => x.name.value === "collections"
4251
+ );
4252
+ const hasDocuments2 = collectionNode2.selectionSet.selections.find(
4253
+ (x) => {
4254
+ var _a3;
4255
+ return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
4256
+ }
4257
+ );
3948
4258
  return tinaSchema.getCollections().map((collection) => {
3949
- return resolver.resolveCollection(args, collection.name, Boolean(hasDocuments2));
4259
+ return resolver.resolveCollection(
4260
+ args,
4261
+ collection.name,
4262
+ Boolean(hasDocuments2)
4263
+ );
3950
4264
  });
3951
4265
  }
3952
- const collectionNode = info.fieldNodes.find((x) => x.name.value === "collection");
3953
- const hasDocuments = collectionNode.selectionSet.selections.find((x) => {
3954
- var _a3;
3955
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
3956
- });
3957
- return resolver.resolveCollection(args, args.collection, Boolean(hasDocuments));
4266
+ const collectionNode = info.fieldNodes.find(
4267
+ (x) => x.name.value === "collection"
4268
+ );
4269
+ const hasDocuments = collectionNode.selectionSet.selections.find(
4270
+ (x) => {
4271
+ var _a3;
4272
+ return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
4273
+ }
4274
+ );
4275
+ return resolver.resolveCollection(
4276
+ args,
4277
+ args.collection,
4278
+ Boolean(hasDocuments)
4279
+ );
3958
4280
  }
3959
4281
  if (info.fieldName === "getOptimizedQuery") {
3960
4282
  try {
3961
- const [optimizedQuery] = (0, import_relay_operation_optimizer.optimizeDocuments)(info.schema, [(0, import_graphql4.parse)(args.queryString)], {
3962
- assumeValid: true,
3963
- includeFragments: false,
3964
- noLocation: true
3965
- });
4283
+ const [optimizedQuery] = (0, import_relay_operation_optimizer.optimizeDocuments)(
4284
+ info.schema,
4285
+ [(0, import_graphql4.parse)(args.queryString)],
4286
+ {
4287
+ assumeValid: true,
4288
+ includeFragments: false,
4289
+ noLocation: true
4290
+ }
4291
+ );
3966
4292
  return (0, import_graphql4.print)(optimizedQuery);
3967
4293
  } catch (e) {
3968
- throw new Error(`Invalid query provided, Error message: ${e.message}`);
4294
+ throw new Error(
4295
+ `Invalid query provided, Error message: ${e.message}`
4296
+ );
3969
4297
  }
3970
4298
  }
3971
4299
  if (!lookup) {
@@ -3974,7 +4302,10 @@ var resolve = async ({
3974
4302
  const isCreation = lookup[info.fieldName] === "create";
3975
4303
  switch (lookup.resolveType) {
3976
4304
  case "nodeDocument":
3977
- assertShape(args, (yup3) => yup3.object({ id: yup3.string().required() }));
4305
+ assertShape(
4306
+ args,
4307
+ (yup3) => yup3.object({ id: yup3.string().required() })
4308
+ );
3978
4309
  return resolver.getDocument(args.id);
3979
4310
  case "multiCollectionDocument":
3980
4311
  if (typeof value === "string") {
@@ -3982,7 +4313,7 @@ var resolve = async ({
3982
4313
  }
3983
4314
  if (args && args.collection && info.fieldName === "addPendingDocument") {
3984
4315
  return resolver.resolveDocument({
3985
- args: __spreadProps(__spreadValues({}, args), { params: {} }),
4316
+ args: { ...args, params: {} },
3986
4317
  collection: args.collection,
3987
4318
  isMutation,
3988
4319
  isCreation: true,
@@ -4022,13 +4353,16 @@ var resolve = async ({
4022
4353
  filter = args.filter[value.collection.name];
4023
4354
  }
4024
4355
  return resolver.resolveCollectionConnection({
4025
- args: __spreadProps(__spreadValues({}, args), {
4356
+ args: {
4357
+ ...args,
4026
4358
  filter
4027
- }),
4359
+ },
4028
4360
  collection: value.collection
4029
4361
  });
4030
4362
  } else {
4031
- throw new Error(`Expected an array for result of ${info.fieldName} at ${info.path}`);
4363
+ throw new Error(
4364
+ `Expected an array for result of ${info.fieldName} at ${info.path}`
4365
+ );
4032
4366
  }
4033
4367
  case "collectionDocument":
4034
4368
  if (value) {
@@ -4100,13 +4434,13 @@ var resolve = async ({
4100
4434
  };
4101
4435
 
4102
4436
  // src/database/index.ts
4103
- var import_path3 = __toModule(require("path"));
4104
- var import_graphql5 = __toModule(require("graphql"));
4437
+ var import_path3 = __toESM(require("path"));
4438
+ var import_graphql5 = require("graphql");
4105
4439
 
4106
4440
  // src/database/util.ts
4107
- var import_toml = __toModule(require("@iarna/toml"));
4108
- var import_js_yaml = __toModule(require("js-yaml"));
4109
- var import_gray_matter = __toModule(require("gray-matter"));
4441
+ var import_toml = __toESM(require("@iarna/toml"));
4442
+ var import_js_yaml = __toESM(require("js-yaml"));
4443
+ var import_gray_matter = __toESM(require("gray-matter"));
4110
4444
  var matterEngines = {
4111
4445
  toml: {
4112
4446
  parse: (val) => import_toml.default.parse(val),
@@ -4114,36 +4448,34 @@ var matterEngines = {
4114
4448
  }
4115
4449
  };
4116
4450
  var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
4117
- const _a = content, {
4451
+ const {
4118
4452
  _relativePath,
4119
4453
  _keepTemplateKey,
4120
4454
  _id,
4121
4455
  _template,
4122
4456
  _collection,
4123
- $_body
4124
- } = _a, rest = __objRest(_a, [
4125
- "_relativePath",
4126
- "_keepTemplateKey",
4127
- "_id",
4128
- "_template",
4129
- "_collection",
4130
- "$_body"
4131
- ]);
4457
+ $_body,
4458
+ ...rest
4459
+ } = content;
4132
4460
  const extra = {};
4133
4461
  if (keepTemplateKey) {
4134
4462
  extra["_template"] = _template;
4135
4463
  }
4136
- const strippedContent = __spreadValues(__spreadValues({}, rest), extra);
4464
+ const strippedContent = { ...rest, ...extra };
4137
4465
  switch (format) {
4138
4466
  case ".markdown":
4139
4467
  case ".mdx":
4140
4468
  case ".md":
4141
- const ok = import_gray_matter.default.stringify(typeof $_body === "undefined" ? "" : `
4142
- ${$_body}`, strippedContent, {
4143
- language: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) || "yaml",
4144
- engines: matterEngines,
4145
- delimiters: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) || "---"
4146
- });
4469
+ const ok = import_gray_matter.default.stringify(
4470
+ typeof $_body === "undefined" ? "" : `
4471
+ ${$_body}`,
4472
+ strippedContent,
4473
+ {
4474
+ language: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) || "yaml",
4475
+ engines: matterEngines,
4476
+ delimiters: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) || "---"
4477
+ }
4478
+ );
4147
4479
  return ok;
4148
4480
  case ".json":
4149
4481
  return JSON.stringify(strippedContent, null, 2);
@@ -4166,9 +4498,10 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
4166
4498
  delimiters: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) || "---",
4167
4499
  engines: matterEngines
4168
4500
  });
4169
- const markdownData = __spreadProps(__spreadValues({}, contentJSON.data), {
4501
+ const markdownData = {
4502
+ ...contentJSON.data,
4170
4503
  $_body: contentJSON.content
4171
- });
4504
+ };
4172
4505
  assertShape(markdownData, yupSchema);
4173
4506
  return markdownData;
4174
4507
  case ".json":
@@ -4197,7 +4530,10 @@ var normalizePath = (filepath) => filepath.replace(/\\/g, "/");
4197
4530
  var replaceNameOverrides = (template, obj) => {
4198
4531
  if (template.list) {
4199
4532
  return obj.map((item) => {
4200
- return _replaceNameOverrides(getTemplateForData(template, item).fields, item);
4533
+ return _replaceNameOverrides(
4534
+ getTemplateForData(template, item).fields,
4535
+ item
4536
+ );
4201
4537
  });
4202
4538
  } else {
4203
4539
  return _replaceNameOverrides(getTemplateForData(template, obj).fields, obj);
@@ -4206,7 +4542,9 @@ var replaceNameOverrides = (template, obj) => {
4206
4542
  var _replaceNameOverrides = (fields, obj) => {
4207
4543
  const output = {};
4208
4544
  Object.keys(obj).forEach((key) => {
4209
- const field = fields.find((fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key);
4545
+ const field = fields.find(
4546
+ (fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key
4547
+ );
4210
4548
  output[(field == null ? void 0 : field.name) || key] = (field == null ? void 0 : field.type) == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
4211
4549
  });
4212
4550
  return output;
@@ -4215,7 +4553,9 @@ var getTemplateKey = (field) => {
4215
4553
  var _a, _b, _c;
4216
4554
  const DEFAULT_TEMPLATE_KEY = "_template";
4217
4555
  if ((_a = field.templates) == null ? void 0 : _a.length) {
4218
- const templateField = (_c = (_b = field.templates[0]) == null ? void 0 : _b.fields) == null ? void 0 : _c.find((field2) => field2.name === DEFAULT_TEMPLATE_KEY);
4556
+ const templateField = (_c = (_b = field.templates[0]) == null ? void 0 : _b.fields) == null ? void 0 : _c.find(
4557
+ (field2) => field2.name === DEFAULT_TEMPLATE_KEY
4558
+ );
4219
4559
  return (templateField == null ? void 0 : templateField.alias) || DEFAULT_TEMPLATE_KEY;
4220
4560
  }
4221
4561
  return DEFAULT_TEMPLATE_KEY;
@@ -4225,7 +4565,9 @@ var getTemplateForData = (field, data) => {
4225
4565
  if ((_a = field.templates) == null ? void 0 : _a.length) {
4226
4566
  const templateKey = getTemplateKey(field);
4227
4567
  if (data[templateKey]) {
4228
- return field.templates.find((template) => template.name === data[templateKey]);
4568
+ return field.templates.find(
4569
+ (template) => template.name === data[templateKey]
4570
+ );
4229
4571
  }
4230
4572
  } else {
4231
4573
  return field;
@@ -4235,7 +4577,10 @@ var getTemplateForData = (field, data) => {
4235
4577
  var applyNameOverrides = (template, obj) => {
4236
4578
  if (template.list) {
4237
4579
  return obj.map((item) => {
4238
- return _applyNameOverrides(getTemplateForData(template, item).fields, item);
4580
+ return _applyNameOverrides(
4581
+ getTemplateForData(template, item).fields,
4582
+ item
4583
+ );
4239
4584
  });
4240
4585
  } else {
4241
4586
  return _applyNameOverrides(getTemplateForData(template, obj).fields, obj);
@@ -4253,10 +4598,11 @@ var _applyNameOverrides = (fields, obj) => {
4253
4598
 
4254
4599
  // src/database/index.ts
4255
4600
  var createDatabase = (config) => {
4256
- return new Database(__spreadProps(__spreadValues({}, config), {
4601
+ return new Database({
4602
+ ...config,
4257
4603
  bridge: config.bridge,
4258
4604
  level: config.level
4259
- }));
4605
+ });
4260
4606
  };
4261
4607
  var SYSTEM_FILES = ["_schema", "_graphql", "_lookup"];
4262
4608
  var defaultStatusCallback = () => Promise.resolve();
@@ -4277,7 +4623,10 @@ var Database = class {
4277
4623
  } else {
4278
4624
  const tinaSchema = await this.getSchema(this.level);
4279
4625
  const extension = import_path3.default.extname(filepath);
4280
- const contentObject = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizePath(filepath));
4626
+ const contentObject = await this.level.sublevel(
4627
+ CONTENT_ROOT_PREFIX,
4628
+ SUBLEVEL_OPTIONS
4629
+ ).get(normalizePath(filepath));
4281
4630
  if (!contentObject) {
4282
4631
  throw new import_graphql5.GraphQLError(`Unable to find record ${filepath}`);
4283
4632
  }
@@ -4294,25 +4643,30 @@ var Database = class {
4294
4643
  let data = contentObject;
4295
4644
  if ((extension === ".md" || extension === ".mdx") && field) {
4296
4645
  if (hasOwnProperty(contentObject, "$_body")) {
4297
- const _a = contentObject, { $_body } = _a, rest = __objRest(_a, ["$_body"]);
4646
+ const { $_body, ...rest } = contentObject;
4298
4647
  data = rest;
4299
4648
  data[field.name] = $_body;
4300
4649
  }
4301
4650
  }
4302
- return __spreadProps(__spreadValues({}, data), {
4651
+ return {
4652
+ ...data,
4303
4653
  _collection: collection.name,
4304
4654
  _keepTemplateKey: !!collection.templates,
4305
4655
  _template: lastItem(template.namespace),
4306
4656
  _relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
4307
4657
  _id: filepath
4308
- });
4658
+ };
4309
4659
  }
4310
4660
  };
4311
4661
  this.addPendingDocument = async (filepath, data) => {
4312
4662
  await this.initLevel();
4313
4663
  const dataFields = await this.formatBodyOnPayload(filepath, data);
4314
4664
  const collection = await this.collectionForPath(filepath);
4315
- const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
4665
+ const stringifiedFile = await this.stringifyFile(
4666
+ filepath,
4667
+ dataFields,
4668
+ collection
4669
+ );
4316
4670
  let collectionIndexDefinitions;
4317
4671
  if (collection) {
4318
4672
  const indexDefinitions = await this.getIndexDefinitions(this.level);
@@ -4323,9 +4677,26 @@ var Database = class {
4323
4677
  await this.bridge.put(normalizedPath, stringifiedFile);
4324
4678
  }
4325
4679
  await this.onPut(normalizedPath, stringifiedFile);
4326
- const putOps = makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, dataFields, "put", this.level);
4327
- const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4328
- const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, existingItem, "del", this.level) : [];
4680
+ const putOps = makeIndexOpsForDocument(
4681
+ normalizedPath,
4682
+ collection == null ? void 0 : collection.name,
4683
+ collectionIndexDefinitions,
4684
+ dataFields,
4685
+ "put",
4686
+ this.level
4687
+ );
4688
+ const existingItem = await this.level.sublevel(
4689
+ CONTENT_ROOT_PREFIX,
4690
+ SUBLEVEL_OPTIONS
4691
+ ).get(normalizedPath);
4692
+ const delOps = existingItem ? makeIndexOpsForDocument(
4693
+ normalizedPath,
4694
+ collection == null ? void 0 : collection.name,
4695
+ collectionIndexDefinitions,
4696
+ existingItem,
4697
+ "del",
4698
+ this.level
4699
+ ) : [];
4329
4700
  const ops = [
4330
4701
  ...delOps,
4331
4702
  ...putOps,
@@ -4333,7 +4704,10 @@ var Database = class {
4333
4704
  type: "put",
4334
4705
  key: normalizedPath,
4335
4706
  value: dataFields,
4336
- sublevel: this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
4707
+ sublevel: this.level.sublevel(
4708
+ CONTENT_ROOT_PREFIX,
4709
+ SUBLEVEL_OPTIONS
4710
+ )
4337
4711
  }
4338
4712
  ];
4339
4713
  await this.level.batch(ops);
@@ -4352,14 +4726,35 @@ var Database = class {
4352
4726
  const normalizedPath = normalizePath(filepath);
4353
4727
  const dataFields = await this.formatBodyOnPayload(filepath, data);
4354
4728
  const collection = await this.collectionForPath(filepath);
4355
- const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
4729
+ const stringifiedFile = await this.stringifyFile(
4730
+ filepath,
4731
+ dataFields,
4732
+ collection
4733
+ );
4356
4734
  if (this.bridge) {
4357
4735
  await this.bridge.put(normalizedPath, stringifiedFile);
4358
4736
  }
4359
4737
  await this.onPut(normalizedPath, stringifiedFile);
4360
- const putOps = makeIndexOpsForDocument(normalizedPath, collectionName, collectionIndexDefinitions, dataFields, "put", this.level);
4361
- const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4362
- const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collectionName, collectionIndexDefinitions, existingItem, "del", this.level) : [];
4738
+ const putOps = makeIndexOpsForDocument(
4739
+ normalizedPath,
4740
+ collectionName,
4741
+ collectionIndexDefinitions,
4742
+ dataFields,
4743
+ "put",
4744
+ this.level
4745
+ );
4746
+ const existingItem = await this.level.sublevel(
4747
+ CONTENT_ROOT_PREFIX,
4748
+ SUBLEVEL_OPTIONS
4749
+ ).get(normalizedPath);
4750
+ const delOps = existingItem ? makeIndexOpsForDocument(
4751
+ normalizedPath,
4752
+ collectionName,
4753
+ collectionIndexDefinitions,
4754
+ existingItem,
4755
+ "del",
4756
+ this.level
4757
+ ) : [];
4363
4758
  const ops = [
4364
4759
  ...delOps,
4365
4760
  ...putOps,
@@ -4367,7 +4762,10 @@ var Database = class {
4367
4762
  type: "put",
4368
4763
  key: normalizedPath,
4369
4764
  value: dataFields,
4370
- sublevel: this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
4765
+ sublevel: this.level.sublevel(
4766
+ CONTENT_ROOT_PREFIX,
4767
+ SUBLEVEL_OPTIONS
4768
+ )
4371
4769
  }
4372
4770
  ];
4373
4771
  await this.level.batch(ops);
@@ -4408,49 +4806,78 @@ var Database = class {
4408
4806
  return payload;
4409
4807
  };
4410
4808
  this.stringifyFile = async (filepath, payload, collection) => {
4411
- const templateDetails = await this.getTemplateDetailsForFile(collection, payload);
4809
+ const templateDetails = await this.getTemplateDetailsForFile(
4810
+ collection,
4811
+ payload
4812
+ );
4412
4813
  const writeTemplateKey = templateDetails.info.type === "union";
4413
4814
  const aliasedData = applyNameOverrides(templateDetails.template, payload);
4414
4815
  const extension = import_path3.default.extname(filepath);
4415
- const stringifiedFile = stringifyFile(aliasedData, extension, writeTemplateKey, {
4416
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
4417
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
4418
- });
4816
+ const stringifiedFile = stringifyFile(
4817
+ aliasedData,
4818
+ extension,
4819
+ writeTemplateKey,
4820
+ {
4821
+ frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
4822
+ frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
4823
+ }
4824
+ );
4419
4825
  return stringifiedFile;
4420
4826
  };
4421
4827
  this.flush = async (filepath) => {
4422
4828
  const data = await this.get(filepath);
4423
4829
  const dataFields = await this.formatBodyOnPayload(filepath, data);
4424
4830
  const collection = await this.collectionForPath(filepath);
4425
- const stringifiedFile = await this.stringifyFile(filepath, dataFields, collection);
4831
+ const stringifiedFile = await this.stringifyFile(
4832
+ filepath,
4833
+ dataFields,
4834
+ collection
4835
+ );
4426
4836
  return stringifiedFile;
4427
4837
  };
4428
4838
  this.getLookup = async (returnType) => {
4429
4839
  await this.initLevel();
4430
- const lookupPath = normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_lookup.json`));
4840
+ const lookupPath = normalizePath(
4841
+ import_path3.default.join(this.getGeneratedFolder(), `_lookup.json`)
4842
+ );
4431
4843
  if (!this._lookup) {
4432
- const _lookup = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(lookupPath);
4844
+ const _lookup = await this.level.sublevel(
4845
+ CONTENT_ROOT_PREFIX,
4846
+ SUBLEVEL_OPTIONS
4847
+ ).get(lookupPath);
4433
4848
  this._lookup = _lookup;
4434
4849
  }
4435
4850
  return this._lookup[returnType];
4436
4851
  };
4437
4852
  this.getGraphQLSchema = async () => {
4438
4853
  await this.initLevel();
4439
- const graphqlPath = normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`));
4440
- return await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(graphqlPath);
4854
+ const graphqlPath = normalizePath(
4855
+ import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)
4856
+ );
4857
+ return await this.level.sublevel(
4858
+ CONTENT_ROOT_PREFIX,
4859
+ SUBLEVEL_OPTIONS
4860
+ ).get(graphqlPath);
4441
4861
  };
4442
4862
  this.getGraphQLSchemaFromBridge = async () => {
4443
4863
  if (!this.bridge) {
4444
4864
  throw new Error(`No bridge configured`);
4445
4865
  }
4446
- const graphqlPath = normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`));
4866
+ const graphqlPath = normalizePath(
4867
+ import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)
4868
+ );
4447
4869
  const _graphql = await this.bridge.get(graphqlPath);
4448
4870
  return JSON.parse(_graphql);
4449
4871
  };
4450
4872
  this.getTinaSchema = async (level) => {
4451
4873
  await this.initLevel();
4452
- const schemaPath = normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_schema.json`));
4453
- return await (level || this.level).sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(schemaPath);
4874
+ const schemaPath = normalizePath(
4875
+ import_path3.default.join(this.getGeneratedFolder(), `_schema.json`)
4876
+ );
4877
+ return await (level || this.level).sublevel(
4878
+ CONTENT_ROOT_PREFIX,
4879
+ SUBLEVEL_OPTIONS
4880
+ ).get(schemaPath);
4454
4881
  };
4455
4882
  this.getSchema = async (level) => {
4456
4883
  if (this.tinaSchema) {
@@ -4495,7 +4922,9 @@ var Database = class {
4495
4922
  var _a;
4496
4923
  return {
4497
4924
  name: indexField.name,
4498
- type: (_a = collection.fields.find((field) => indexField.name === field.name)) == null ? void 0 : _a.type
4925
+ type: (_a = collection.fields.find(
4926
+ (field) => indexField.name === field.name
4927
+ )) == null ? void 0 : _a.type
4499
4928
  };
4500
4929
  })
4501
4930
  };
@@ -4547,12 +4976,17 @@ var Database = class {
4547
4976
  const allIndexDefinitions = await this.getIndexDefinitions(this.level);
4548
4977
  const indexDefinitions = allIndexDefinitions == null ? void 0 : allIndexDefinitions[queryOptions.collection];
4549
4978
  if (!indexDefinitions) {
4550
- throw new Error(`No indexDefinitions for collection ${queryOptions.collection}`);
4979
+ throw new Error(
4980
+ `No indexDefinitions for collection ${queryOptions.collection}`
4981
+ );
4551
4982
  }
4552
4983
  const filterChain = coerceFilterChainOperands(rawFilterChain);
4553
4984
  const indexDefinition = sort && (indexDefinitions == null ? void 0 : indexDefinitions[sort]);
4554
4985
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
4555
- const rootLevel = this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
4986
+ const rootLevel = this.level.sublevel(
4987
+ CONTENT_ROOT_PREFIX,
4988
+ SUBLEVEL_OPTIONS
4989
+ );
4556
4990
  const sublevel = indexDefinition ? this.level.sublevel(collection, SUBLEVEL_OPTIONS).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
4557
4991
  if (!query.gt && !query.gte) {
4558
4992
  query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
@@ -4575,7 +5009,9 @@ var Database = class {
4575
5009
  continue;
4576
5010
  }
4577
5011
  const filepath = matcher.groups["_filepath_"];
4578
- if (!itemFilter(filterSuffixes ? matcher.groups : indexDefinition ? await rootLevel.get(filepath) : value)) {
5012
+ if (!itemFilter(
5013
+ filterSuffixes ? matcher.groups : indexDefinition ? await rootLevel.get(filepath) : value
5014
+ )) {
4579
5015
  continue;
4580
5016
  }
4581
5017
  if (limit !== -1 && edges.length >= limit) {
@@ -4624,8 +5060,14 @@ var Database = class {
4624
5060
  tinaSchema
4625
5061
  }) => {
4626
5062
  if (this.bridge && this.bridge.supportsBuilding()) {
4627
- await this.bridge.putConfig(normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)), JSON.stringify(graphQLSchema));
4628
- await this.bridge.putConfig(normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_schema.json`)), JSON.stringify(tinaSchema.schema));
5063
+ await this.bridge.putConfig(
5064
+ normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)),
5065
+ JSON.stringify(graphQLSchema)
5066
+ );
5067
+ await this.bridge.putConfig(
5068
+ normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_schema.json`)),
5069
+ JSON.stringify(tinaSchema.schema)
5070
+ );
4629
5071
  }
4630
5072
  };
4631
5073
  this.indexContent = async ({
@@ -4638,21 +5080,37 @@ var Database = class {
4638
5080
  }
4639
5081
  await this.initLevel();
4640
5082
  await this.indexStatusCallbackWrapper(async () => {
4641
- const lookup = lookupFromLockFile || JSON.parse(await this.bridge.get(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_lookup.json"))));
5083
+ const lookup = lookupFromLockFile || JSON.parse(
5084
+ await this.bridge.get(
5085
+ normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_lookup.json"))
5086
+ )
5087
+ );
4642
5088
  let nextLevel;
4643
5089
  let nextVersion;
4644
5090
  if (!this.config.version) {
4645
5091
  await this.level.clear();
4646
5092
  nextLevel = this.level;
4647
5093
  } else {
4648
- const version2 = await this.getDatabaseVersion();
4649
- nextVersion = version2 ? `${parseInt(version2) + 1}` : "0";
5094
+ const version = await this.getDatabaseVersion();
5095
+ nextVersion = version ? `${parseInt(version) + 1}` : "0";
4650
5096
  nextLevel = this.rootLevel.sublevel(nextVersion, SUBLEVEL_OPTIONS);
4651
5097
  }
4652
- const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
4653
- await contentRootLevel.put(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_graphql.json")), graphQLSchema);
4654
- await contentRootLevel.put(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_schema.json")), tinaSchema.schema);
4655
- await contentRootLevel.put(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_lookup.json")), lookup);
5098
+ const contentRootLevel = nextLevel.sublevel(
5099
+ CONTENT_ROOT_PREFIX,
5100
+ SUBLEVEL_OPTIONS
5101
+ );
5102
+ await contentRootLevel.put(
5103
+ normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_graphql.json")),
5104
+ graphQLSchema
5105
+ );
5106
+ await contentRootLevel.put(
5107
+ normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_schema.json")),
5108
+ tinaSchema.schema
5109
+ );
5110
+ await contentRootLevel.put(
5111
+ normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_lookup.json")),
5112
+ lookup
5113
+ );
4656
5114
  await this._indexAllContent(nextLevel);
4657
5115
  if (this.config.version) {
4658
5116
  await this.updateDatabaseVersion(nextVersion);
@@ -4675,7 +5133,12 @@ var Database = class {
4675
5133
  await this.indexStatusCallbackWrapper(async () => {
4676
5134
  const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
4677
5135
  for (const collection of Object.keys(pathsByCollection)) {
4678
- await _deleteIndexContent(this, pathsByCollection[collection], enqueueOps, collections[collection]);
5136
+ await _deleteIndexContent(
5137
+ this,
5138
+ pathsByCollection[collection],
5139
+ enqueueOps,
5140
+ collections[collection]
5141
+ );
4679
5142
  }
4680
5143
  await _deleteIndexContent(this, nonCollectionPaths, enqueueOps, null);
4681
5144
  });
@@ -4695,7 +5158,13 @@ var Database = class {
4695
5158
  await this.indexStatusCallbackWrapper(async () => {
4696
5159
  const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
4697
5160
  for (const collection of Object.keys(pathsByCollection)) {
4698
- await _indexContent(this, this.level, pathsByCollection[collection], enqueueOps, collections[collection]);
5161
+ await _indexContent(
5162
+ this,
5163
+ this.level,
5164
+ pathsByCollection[collection],
5165
+ enqueueOps,
5166
+ collections[collection]
5167
+ );
4699
5168
  }
4700
5169
  await _indexContent(this, this.level, nonCollectionPaths, enqueueOps);
4701
5170
  });
@@ -4711,13 +5180,26 @@ var Database = class {
4711
5180
  const indexDefinitions = await this.getIndexDefinitions(this.level);
4712
5181
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
4713
5182
  }
4714
- this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5183
+ this.level.sublevel(
5184
+ CONTENT_ROOT_PREFIX,
5185
+ SUBLEVEL_OPTIONS
5186
+ );
4715
5187
  const itemKey = normalizePath(filepath);
4716
- const rootSublevel = this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5188
+ const rootSublevel = this.level.sublevel(
5189
+ CONTENT_ROOT_PREFIX,
5190
+ SUBLEVEL_OPTIONS
5191
+ );
4717
5192
  const item = await rootSublevel.get(itemKey);
4718
5193
  if (item) {
4719
5194
  await this.level.batch([
4720
- ...makeIndexOpsForDocument(filepath, collection.name, collectionIndexDefinitions, item, "del", this.level),
5195
+ ...makeIndexOpsForDocument(
5196
+ filepath,
5197
+ collection.name,
5198
+ collectionIndexDefinitions,
5199
+ item,
5200
+ "del",
5201
+ this.level
5202
+ ),
4721
5203
  {
4722
5204
  type: "del",
4723
5205
  key: itemKey,
@@ -4741,7 +5223,10 @@ var Database = class {
4741
5223
  }
4742
5224
  };
4743
5225
  await sequential(tinaSchema.getCollections(), async (collection) => {
4744
- const documentPaths = await this.bridge.glob(normalizePath(collection.path), collection.format || "md");
5226
+ const documentPaths = await this.bridge.glob(
5227
+ normalizePath(collection.path),
5228
+ collection.format || "md"
5229
+ );
4745
5230
  await _indexContent(this, level, documentPaths, enqueueOps, collection);
4746
5231
  });
4747
5232
  while (operations.length) {
@@ -4759,10 +5244,14 @@ var Database = class {
4759
5244
  } catch (e) {
4760
5245
  lookupMap = {};
4761
5246
  }
4762
- const updatedLookup = __spreadProps(__spreadValues({}, lookupMap), {
5247
+ const updatedLookup = {
5248
+ ...lookupMap,
4763
5249
  [lookup.type]: lookup
4764
- });
4765
- await this.bridge.putConfig(normalizePath(lookupPath), JSON.stringify(updatedLookup));
5250
+ };
5251
+ await this.bridge.putConfig(
5252
+ normalizePath(lookupPath),
5253
+ JSON.stringify(updatedLookup)
5254
+ );
4766
5255
  };
4767
5256
  this.tinaDirectory = config.tinaDirectory || ".tina";
4768
5257
  this.bridge = config.bridge;
@@ -4789,9 +5278,9 @@ var Database = class {
4789
5278
  }
4790
5279
  return { pathsByCollection, nonCollectionPaths, collections };
4791
5280
  }
4792
- async updateDatabaseVersion(version2) {
5281
+ async updateDatabaseVersion(version) {
4793
5282
  const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4794
- await metadataLevel.put("metadata", { version: version2 });
5283
+ await metadataLevel.put("metadata", { version });
4795
5284
  }
4796
5285
  async getDatabaseVersion() {
4797
5286
  const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
@@ -4805,12 +5294,12 @@ var Database = class {
4805
5294
  if (!this.config.version) {
4806
5295
  this.level = this.rootLevel;
4807
5296
  } else {
4808
- let version2 = await this.getDatabaseVersion();
4809
- if (!version2) {
4810
- version2 = "";
4811
- await this.updateDatabaseVersion(version2);
5297
+ let version = await this.getDatabaseVersion();
5298
+ if (!version) {
5299
+ version = "";
5300
+ await this.updateDatabaseVersion(version);
4812
5301
  }
4813
- this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
5302
+ this.level = this.rootLevel.sublevel(version, SUBLEVEL_OPTIONS);
4814
5303
  }
4815
5304
  if (!this.level) {
4816
5305
  throw new import_graphql5.GraphQLError("Error initializing LevelDB instance");
@@ -4825,9 +5314,13 @@ var Database = class {
4825
5314
  }
4826
5315
  if (templateInfo.type === "union") {
4827
5316
  if (hasOwnProperty(data, "_template")) {
4828
- template = templateInfo.templates.find((t) => lastItem(t.namespace) === data._template);
5317
+ template = templateInfo.templates.find(
5318
+ (t) => lastItem(t.namespace) === data._template
5319
+ );
4829
5320
  } else {
4830
- throw new Error(`Expected _template to be provided for document in an ambiguous collection`);
5321
+ throw new Error(
5322
+ `Expected _template to be provided for document in an ambiguous collection`
5323
+ );
4831
5324
  }
4832
5325
  }
4833
5326
  if (!template) {
@@ -4873,19 +5366,37 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
4873
5366
  await sequential(documentPaths, async (filepath) => {
4874
5367
  try {
4875
5368
  const dataString = await database.bridge.get(normalizePath(filepath));
4876
- const data = parseFile(dataString, import_path3.default.extname(filepath), (yup3) => yup3.object({}), {
4877
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
4878
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
4879
- });
5369
+ const data = parseFile(
5370
+ dataString,
5371
+ import_path3.default.extname(filepath),
5372
+ (yup3) => yup3.object({}),
5373
+ {
5374
+ frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
5375
+ frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
5376
+ }
5377
+ );
4880
5378
  const normalizedPath = normalizePath(filepath);
4881
- const aliasedData = templateInfo ? replaceNameOverrides(getTemplateForFile(templateInfo, data), data) : data;
5379
+ const aliasedData = templateInfo ? replaceNameOverrides(
5380
+ getTemplateForFile(templateInfo, data),
5381
+ data
5382
+ ) : data;
4882
5383
  await enqueueOps([
4883
- ...makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, aliasedData, "put", level),
5384
+ ...makeIndexOpsForDocument(
5385
+ normalizedPath,
5386
+ collection == null ? void 0 : collection.name,
5387
+ collectionIndexDefinitions,
5388
+ aliasedData,
5389
+ "put",
5390
+ level
5391
+ ),
4884
5392
  {
4885
5393
  type: "put",
4886
5394
  key: normalizedPath,
4887
5395
  value: aliasedData,
4888
- sublevel: level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
5396
+ sublevel: level.sublevel(
5397
+ CONTENT_ROOT_PREFIX,
5398
+ SUBLEVEL_OPTIONS
5399
+ )
4889
5400
  }
4890
5401
  ]);
4891
5402
  } catch (error) {
@@ -4907,13 +5418,23 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
4907
5418
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
4908
5419
  }
4909
5420
  }
4910
- const rootLevel = database.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5421
+ const rootLevel = database.level.sublevel(
5422
+ CONTENT_ROOT_PREFIX,
5423
+ SUBLEVEL_OPTIONS
5424
+ );
4911
5425
  await sequential(documentPaths, async (filepath) => {
4912
5426
  const itemKey = normalizePath(filepath);
4913
5427
  const item = await rootLevel.get(itemKey);
4914
5428
  if (item) {
4915
5429
  await enequeueOps([
4916
- ...makeIndexOpsForDocument(itemKey, collection.name, collectionIndexDefinitions, item, "del", database.level),
5430
+ ...makeIndexOpsForDocument(
5431
+ itemKey,
5432
+ collection.name,
5433
+ collectionIndexDefinitions,
5434
+ item,
5435
+ "del",
5436
+ database.level
5437
+ ),
4917
5438
  { type: "del", key: itemKey, sublevel: rootLevel }
4918
5439
  ]);
4919
5440
  }
@@ -4925,18 +5446,22 @@ var getTemplateForFile = (templateInfo, data) => {
4925
5446
  }
4926
5447
  if (templateInfo.type === "union") {
4927
5448
  if (hasOwnProperty(data, "_template")) {
4928
- return templateInfo.templates.find((t) => lastItem(t.namespace) === data._template);
5449
+ return templateInfo.templates.find(
5450
+ (t) => lastItem(t.namespace) === data._template
5451
+ );
4929
5452
  } else {
4930
- throw new Error(`Expected _template to be provided for document in an ambiguous collection`);
5453
+ throw new Error(
5454
+ `Expected _template to be provided for document in an ambiguous collection`
5455
+ );
4931
5456
  }
4932
5457
  }
4933
5458
  throw new Error(`Unable to determine template`);
4934
5459
  };
4935
5460
 
4936
5461
  // src/level/tinaLevel.ts
4937
- var import_many_level = __toModule(require("many-level"));
4938
- var import_readable_stream = __toModule(require("readable-stream"));
4939
- var import_net = __toModule(require("net"));
5462
+ var import_many_level = require("many-level");
5463
+ var import_readable_stream = require("readable-stream");
5464
+ var import_net = require("net");
4940
5465
  var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
4941
5466
  constructor() {
4942
5467
  super(...arguments);
@@ -4954,10 +5479,10 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
4954
5479
  };
4955
5480
 
4956
5481
  // src/database/bridge/filesystem.ts
4957
- var import_fs_extra2 = __toModule(require("fs-extra"));
4958
- var import_fast_glob = __toModule(require("fast-glob"));
4959
- var import_path4 = __toModule(require("path"));
4960
- var import_normalize_path = __toModule(require("normalize-path"));
5482
+ var import_fs_extra2 = __toESM(require("fs-extra"));
5483
+ var import_fast_glob = __toESM(require("fast-glob"));
5484
+ var import_path4 = __toESM(require("path"));
5485
+ var import_normalize_path = __toESM(require("normalize-path"));
4961
5486
  var FilesystemBridge = class {
4962
5487
  constructor(rootPath) {
4963
5488
  this.rootPath = rootPath || "";
@@ -4968,9 +5493,12 @@ var FilesystemBridge = class {
4968
5493
  }
4969
5494
  async glob(pattern, extension) {
4970
5495
  const basePath = import_path4.default.join(this.outputPath, ...pattern.split("/"));
4971
- const items = await (0, import_fast_glob.default)(import_path4.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"), {
4972
- dot: true
4973
- });
5496
+ const items = await (0, import_fast_glob.default)(
5497
+ import_path4.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"),
5498
+ {
5499
+ dot: true
5500
+ }
5501
+ );
4974
5502
  const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
4975
5503
  return items.map((item) => {
4976
5504
  return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
@@ -5012,12 +5540,12 @@ var AuditFileSystemBridge = class extends FilesystemBridge {
5012
5540
  };
5013
5541
 
5014
5542
  // src/database/bridge/isomorphic.ts
5015
- var import_isomorphic_git = __toModule(require("isomorphic-git"));
5016
- var import_fs_extra3 = __toModule(require("fs-extra"));
5017
- var import_glob_parent = __toModule(require("glob-parent"));
5018
- var import_normalize_path2 = __toModule(require("normalize-path"));
5019
- var import_graphql6 = __toModule(require("graphql"));
5020
- var import_path5 = __toModule(require("path"));
5543
+ var import_isomorphic_git = __toESM(require("isomorphic-git"));
5544
+ var import_fs_extra3 = __toESM(require("fs-extra"));
5545
+ var import_glob_parent = __toESM(require("glob-parent"));
5546
+ var import_normalize_path2 = __toESM(require("normalize-path"));
5547
+ var import_graphql6 = require("graphql");
5548
+ var import_path5 = require("path");
5021
5549
  var flat = typeof Array.prototype.flat === "undefined" ? (entries) => entries.reduce((acc, x) => acc.concat(x), []) : (entries) => entries.flat();
5022
5550
  var toUint8Array = (buf) => {
5023
5551
  const ab = new ArrayBuffer(buf.length);
@@ -5060,16 +5588,18 @@ var IsomorphicBridge = class {
5060
5588
  });
5061
5589
  }
5062
5590
  getAuthor() {
5063
- return __spreadProps(__spreadValues({}, this.author), {
5591
+ return {
5592
+ ...this.author,
5064
5593
  timestamp: Math.round(new Date().getTime() / 1e3),
5065
5594
  timezoneOffset: 0
5066
- });
5595
+ };
5067
5596
  }
5068
5597
  getCommitter() {
5069
- return __spreadProps(__spreadValues({}, this.committer), {
5598
+ return {
5599
+ ...this.committer,
5070
5600
  timestamp: Math.round(new Date().getTime() / 1e3),
5071
5601
  timezoneOffset: 0
5072
- });
5602
+ };
5073
5603
  }
5074
5604
  async listEntries({
5075
5605
  pattern,
@@ -5077,10 +5607,11 @@ var IsomorphicBridge = class {
5077
5607
  path: path6,
5078
5608
  results
5079
5609
  }) {
5080
- const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5610
+ const treeResult = await import_isomorphic_git.default.readTree({
5611
+ ...this.isomorphicConfig,
5081
5612
  oid: entry.oid,
5082
5613
  cache: this.cache
5083
- }));
5614
+ });
5084
5615
  const children = [];
5085
5616
  for (const childEntry of treeResult.tree) {
5086
5617
  const childPath = path6 ? `${path6}/${childEntry.path}` : childEntry.path;
@@ -5104,7 +5635,8 @@ var IsomorphicBridge = class {
5104
5635
  }
5105
5636
  async resolvePathEntries(path6, ref) {
5106
5637
  let pathParts = path6.split("/");
5107
- const result = await import_isomorphic_git.default.walk(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5638
+ const result = await import_isomorphic_git.default.walk({
5639
+ ...this.isomorphicConfig,
5108
5640
  map: async (filepath, [head]) => {
5109
5641
  if (head._fullpath === ".") {
5110
5642
  return head;
@@ -5121,7 +5653,7 @@ var IsomorphicBridge = class {
5121
5653
  },
5122
5654
  cache: this.cache,
5123
5655
  trees: [import_isomorphic_git.default.TREE({ ref })]
5124
- }));
5656
+ });
5125
5657
  const pathEntries = flat(result);
5126
5658
  if (pathParts.indexOf(".") === -1) {
5127
5659
  pathParts = [".", ...pathParts];
@@ -5140,10 +5672,11 @@ var IsomorphicBridge = class {
5140
5672
  const mode = type === "blob" ? "100644" : "040000";
5141
5673
  if (parentEntry) {
5142
5674
  parentOid = await parentEntry.oid();
5143
- const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5675
+ const treeResult = await import_isomorphic_git.default.readTree({
5676
+ ...this.isomorphicConfig,
5144
5677
  oid: parentOid,
5145
5678
  cache: this.cache
5146
- }));
5679
+ });
5147
5680
  tree = existingOid ? treeResult.tree.map((entry) => {
5148
5681
  if (entry.path === path6) {
5149
5682
  entry.oid = updatedOid;
@@ -5168,44 +5701,64 @@ var IsomorphicBridge = class {
5168
5701
  }
5169
5702
  ];
5170
5703
  }
5171
- const updatedParentOid = await import_isomorphic_git.default.writeTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5704
+ const updatedParentOid = await import_isomorphic_git.default.writeTree({
5705
+ ...this.isomorphicConfig,
5172
5706
  tree
5173
- }));
5707
+ });
5174
5708
  if (lastIdx === 0) {
5175
5709
  return updatedParentOid;
5176
5710
  } else {
5177
- return await this.updateTreeHierarchy(parentOid, updatedParentOid, parentPath, "tree", pathEntries.slice(0, lastIdx), pathParts.slice(0, lastIdx));
5711
+ return await this.updateTreeHierarchy(
5712
+ parentOid,
5713
+ updatedParentOid,
5714
+ parentPath,
5715
+ "tree",
5716
+ pathEntries.slice(0, lastIdx),
5717
+ pathParts.slice(0, lastIdx)
5718
+ );
5178
5719
  }
5179
5720
  }
5180
5721
  async commitTree(treeSha, ref) {
5181
- const commitSha = await import_isomorphic_git.default.writeCommit(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5722
+ const commitSha = await import_isomorphic_git.default.writeCommit({
5723
+ ...this.isomorphicConfig,
5182
5724
  commit: {
5183
5725
  tree: treeSha,
5184
5726
  parent: [
5185
- await import_isomorphic_git.default.resolveRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5727
+ await import_isomorphic_git.default.resolveRef({
5728
+ ...this.isomorphicConfig,
5186
5729
  ref
5187
- }))
5730
+ })
5188
5731
  ],
5189
5732
  message: this.commitMessage,
5190
5733
  author: this.getAuthor(),
5191
5734
  committer: this.getCommitter()
5192
5735
  }
5193
- }));
5194
- await import_isomorphic_git.default.writeRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5736
+ });
5737
+ await import_isomorphic_git.default.writeRef({
5738
+ ...this.isomorphicConfig,
5195
5739
  ref,
5196
5740
  value: commitSha,
5197
5741
  force: true
5198
- }));
5742
+ });
5199
5743
  }
5200
5744
  async getRef() {
5201
5745
  if (this.ref) {
5202
5746
  return this.ref;
5203
5747
  }
5204
- const ref = await import_isomorphic_git.default.currentBranch(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5748
+ const ref = await import_isomorphic_git.default.currentBranch({
5749
+ ...this.isomorphicConfig,
5205
5750
  fullname: true
5206
- }));
5751
+ });
5207
5752
  if (!ref) {
5208
- throw new import_graphql6.GraphQLError(`Unable to determine current branch from HEAD`, null, null, null, null, null, {});
5753
+ throw new import_graphql6.GraphQLError(
5754
+ `Unable to determine current branch from HEAD`,
5755
+ null,
5756
+ null,
5757
+ null,
5758
+ null,
5759
+ null,
5760
+ {}
5761
+ );
5209
5762
  }
5210
5763
  this.ref = ref;
5211
5764
  return ref;
@@ -5213,17 +5766,21 @@ var IsomorphicBridge = class {
5213
5766
  async glob(pattern, extension) {
5214
5767
  const ref = await this.getRef();
5215
5768
  const parent = (0, import_glob_parent.default)(this.qualifyPath(pattern));
5216
- const { pathParts, pathEntries } = await this.resolvePathEntries(parent, ref);
5769
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5770
+ parent,
5771
+ ref
5772
+ );
5217
5773
  const leafEntry = pathEntries[pathEntries.length - 1];
5218
5774
  const entryPath = pathParts[pathParts.length - 1];
5219
5775
  const parentEntry = pathEntries[pathEntries.length - 2];
5220
5776
  let treeEntry;
5221
5777
  let parentPath;
5222
5778
  if (parentEntry) {
5223
- const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5779
+ const treeResult = await import_isomorphic_git.default.readTree({
5780
+ ...this.isomorphicConfig,
5224
5781
  oid: await parentEntry.oid(),
5225
5782
  cache: this.cache
5226
- }));
5783
+ });
5227
5784
  treeEntry = treeResult.tree.find((entry) => entry.path === entryPath);
5228
5785
  parentPath = pathParts.slice(1, pathParts.length).join("/");
5229
5786
  } else {
@@ -5247,7 +5804,10 @@ var IsomorphicBridge = class {
5247
5804
  }
5248
5805
  async delete(filepath) {
5249
5806
  const ref = await this.getRef();
5250
- const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
5807
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5808
+ this.qualifyPath(filepath),
5809
+ ref
5810
+ );
5251
5811
  let oidToRemove;
5252
5812
  let ptr = pathEntries.length - 1;
5253
5813
  while (ptr >= 1) {
@@ -5257,33 +5817,53 @@ var IsomorphicBridge = class {
5257
5817
  oidToRemove = oidToRemove || await leafEntry.oid();
5258
5818
  const parentEntry = pathEntries[ptr - 1];
5259
5819
  const existingOid = await parentEntry.oid();
5260
- const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5820
+ const treeResult = await import_isomorphic_git.default.readTree({
5821
+ ...this.isomorphicConfig,
5261
5822
  oid: existingOid,
5262
5823
  cache: this.cache
5263
- }));
5264
- const updatedTree = treeResult.tree.filter((value) => value.path !== nodePath);
5824
+ });
5825
+ const updatedTree = treeResult.tree.filter(
5826
+ (value) => value.path !== nodePath
5827
+ );
5265
5828
  if (updatedTree.length === 0) {
5266
5829
  ptr -= 1;
5267
5830
  continue;
5268
5831
  }
5269
- const updatedTreeOid = await import_isomorphic_git.default.writeTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5832
+ const updatedTreeOid = await import_isomorphic_git.default.writeTree({
5833
+ ...this.isomorphicConfig,
5270
5834
  tree: updatedTree
5271
- }));
5272
- const updatedRootTreeOid = await this.updateTreeHierarchy(existingOid, updatedTreeOid, pathParts[ptr - 1], "tree", pathEntries.slice(0, ptr - 1), pathParts.slice(0, ptr - 1));
5835
+ });
5836
+ const updatedRootTreeOid = await this.updateTreeHierarchy(
5837
+ existingOid,
5838
+ updatedTreeOid,
5839
+ pathParts[ptr - 1],
5840
+ "tree",
5841
+ pathEntries.slice(0, ptr - 1),
5842
+ pathParts.slice(0, ptr - 1)
5843
+ );
5273
5844
  await this.commitTree(updatedRootTreeOid, ref);
5274
5845
  break;
5275
5846
  } else {
5276
- throw new import_graphql6.GraphQLError(`Unable to resolve path: ${filepath}`, null, null, null, null, null, { status: 404 });
5847
+ throw new import_graphql6.GraphQLError(
5848
+ `Unable to resolve path: ${filepath}`,
5849
+ null,
5850
+ null,
5851
+ null,
5852
+ null,
5853
+ null,
5854
+ { status: 404 }
5855
+ );
5277
5856
  }
5278
5857
  }
5279
5858
  if (oidToRemove) {
5280
- await import_isomorphic_git.default.updateIndex(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5859
+ await import_isomorphic_git.default.updateIndex({
5860
+ ...this.isomorphicConfig,
5281
5861
  filepath: this.qualifyPath(filepath),
5282
5862
  force: true,
5283
5863
  remove: true,
5284
5864
  oid: oidToRemove,
5285
5865
  cache: this.cache
5286
- }));
5866
+ });
5287
5867
  }
5288
5868
  await this.onDelete(filepath);
5289
5869
  }
@@ -5295,14 +5875,16 @@ var IsomorphicBridge = class {
5295
5875
  }
5296
5876
  async get(filepath) {
5297
5877
  const ref = await this.getRef();
5298
- const oid = await import_isomorphic_git.default.resolveRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5878
+ const oid = await import_isomorphic_git.default.resolveRef({
5879
+ ...this.isomorphicConfig,
5299
5880
  ref
5300
- }));
5301
- const { blob } = await import_isomorphic_git.default.readBlob(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5881
+ });
5882
+ const { blob } = await import_isomorphic_git.default.readBlob({
5883
+ ...this.isomorphicConfig,
5302
5884
  oid,
5303
5885
  filepath: this.qualifyPath(filepath),
5304
5886
  cache: this.cache
5305
- }));
5887
+ });
5306
5888
  return Buffer.from(blob).toString("utf8");
5307
5889
  }
5308
5890
  async putConfig(filepath, data) {
@@ -5310,7 +5892,10 @@ var IsomorphicBridge = class {
5310
5892
  }
5311
5893
  async put(filepath, data) {
5312
5894
  const ref = await this.getRef();
5313
- const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
5895
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5896
+ this.qualifyPath(filepath),
5897
+ ref
5898
+ );
5314
5899
  const blobUpdate = toUint8Array(Buffer.from(data));
5315
5900
  let existingOid;
5316
5901
  const leafEntry = pathEntries[pathEntries.length - 1];
@@ -5323,17 +5908,26 @@ var IsomorphicBridge = class {
5323
5908
  return;
5324
5909
  }
5325
5910
  }
5326
- const updatedOid = await import_isomorphic_git.default.writeBlob(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5911
+ const updatedOid = await import_isomorphic_git.default.writeBlob({
5912
+ ...this.isomorphicConfig,
5327
5913
  blob: blobUpdate
5328
- }));
5329
- const updatedRootSha = await this.updateTreeHierarchy(existingOid, updatedOid, nodePath, "blob", pathEntries.slice(0, pathEntries.length - 1), pathParts.slice(0, pathParts.length - 1));
5914
+ });
5915
+ const updatedRootSha = await this.updateTreeHierarchy(
5916
+ existingOid,
5917
+ updatedOid,
5918
+ nodePath,
5919
+ "blob",
5920
+ pathEntries.slice(0, pathEntries.length - 1),
5921
+ pathParts.slice(0, pathParts.length - 1)
5922
+ );
5330
5923
  await this.commitTree(updatedRootSha, ref);
5331
- await import_isomorphic_git.default.updateIndex(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5924
+ await import_isomorphic_git.default.updateIndex({
5925
+ ...this.isomorphicConfig,
5332
5926
  filepath: this.qualifyPath(filepath),
5333
5927
  add: true,
5334
5928
  oid: updatedOid,
5335
5929
  cache: this.cache
5336
- }));
5930
+ });
5337
5931
  await this.onPut(filepath, data);
5338
5932
  }
5339
5933
  };