@tinacms/graphql 1.3.2 → 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.
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,21 +1551,25 @@ 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
  });
1581
1568
  };
1582
1569
  this._getCollectionFragmentSelections = async (collection, depth) => {
1570
+ var _a;
1583
1571
  const selections = [];
1584
- if (typeof collection.fields === "object") {
1572
+ if (((_a = collection.fields) == null ? void 0 : _a.length) > 0) {
1585
1573
  await sequential(collection.fields, async (x) => {
1586
1574
  const field = await this._buildFieldNodeForFragments(x, depth);
1587
1575
  selections.push(field);
@@ -1596,6 +1584,7 @@ var Builder = class {
1596
1584
  return selections;
1597
1585
  };
1598
1586
  this._buildFieldNodeForFragments = async (field, depth) => {
1587
+ var _a, _b;
1599
1588
  switch (field.type) {
1600
1589
  case "string":
1601
1590
  case "image":
@@ -1605,7 +1594,7 @@ var Builder = class {
1605
1594
  case "rich-text":
1606
1595
  return astBuilder.FieldNodeDefinition(field);
1607
1596
  case "object":
1608
- if (typeof field.fields === "object") {
1597
+ if (((_a = field.fields) == null ? void 0 : _a.length) > 0) {
1609
1598
  const selections2 = [];
1610
1599
  await sequential(field.fields, async (item) => {
1611
1600
  const field2 = await this._buildFieldNodeForFragments(item, depth);
@@ -1618,7 +1607,7 @@ var Builder = class {
1618
1607
  ...filterSelections(selections2)
1619
1608
  ]
1620
1609
  });
1621
- } else if (typeof field.templates === "object") {
1610
+ } else if (((_b = field.templates) == null ? void 0 : _b.length) > 0) {
1622
1611
  const selections2 = [];
1623
1612
  await sequential(field.templates, async (tem) => {
1624
1613
  if (typeof tem === "object") {
@@ -1654,7 +1643,12 @@ var Builder = class {
1654
1643
  directives: [],
1655
1644
  selectionSet: {
1656
1645
  kind: "SelectionSet",
1657
- selections: filterSelections(await this._getCollectionFragmentSelections(collection, depth + 1))
1646
+ selections: filterSelections(
1647
+ await this._getCollectionFragmentSelections(
1648
+ collection,
1649
+ depth + 1
1650
+ )
1651
+ )
1658
1652
  }
1659
1653
  });
1660
1654
  });
@@ -1749,28 +1743,35 @@ var Builder = class {
1749
1743
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
1750
1744
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
1751
1745
  if (templateInfo.type === "union") {
1752
- return this._buildObjectOrUnionData(__spreadValues({}, templateInfo), [
1753
- astBuilder.FieldDefinition({
1754
- name: "id",
1755
- required: true,
1756
- type: astBuilder.TYPES.ID
1757
- }),
1758
- astBuilder.FieldDefinition({
1759
- name: "_sys",
1760
- required: true,
1761
- type: astBuilder.TYPES.SystemInfo
1762
- }),
1763
- ...extraFields,
1764
- astBuilder.FieldDefinition({
1765
- name: "_values",
1766
- required: true,
1767
- type: "JSON"
1768
- })
1769
- ], [
1770
- astBuilder.NamedType({ name: astBuilder.TYPES.Node }),
1771
- astBuilder.NamedType({ name: astBuilder.TYPES.Document }),
1772
- ...extraInterfaces
1773
- ], 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
+ );
1774
1775
  }
1775
1776
  const fields = templateInfo.template.fields;
1776
1777
  const templateFields = await sequential(fields, async (field) => {
@@ -2059,7 +2060,9 @@ var Builder = class {
2059
2060
  const filter = await this._connectionFilterBuilder({
2060
2061
  fieldName: field.name,
2061
2062
  namespace: field.namespace,
2062
- collections: await this.tinaSchema.getCollectionsByName(field.collections)
2063
+ collections: await this.tinaSchema.getCollectionsByName(
2064
+ field.collections
2065
+ )
2063
2066
  });
2064
2067
  return astBuilder.InputValueDefinition({
2065
2068
  name: field.name,
@@ -2115,25 +2118,33 @@ var Builder = class {
2115
2118
  this._buildReferenceMutation = async (field) => {
2116
2119
  return astBuilder.InputObjectTypeDefinition({
2117
2120
  name: NAMER.dataMutationTypeName(field.namespace),
2118
- 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) => {
2119
2136
  return astBuilder.InputValueDefinition({
2120
2137
  name: collection.name,
2121
2138
  type: NAMER.dataMutationTypeName([collection.name])
2122
2139
  });
2140
+ }
2141
+ );
2142
+ fields.push(
2143
+ astBuilder.InputValueDefinition({
2144
+ name: "relativePath",
2145
+ type: astBuilder.TYPES.String
2123
2146
  })
2124
- });
2125
- };
2126
- this._buildUpdateDocumentMutationParams = async (field) => {
2127
- const fields = await sequential(this.tinaSchema.getCollectionsByName(field.collections), async (collection) => {
2128
- return astBuilder.InputValueDefinition({
2129
- name: collection.name,
2130
- type: NAMER.dataMutationTypeName([collection.name])
2131
- });
2132
- });
2133
- fields.push(astBuilder.InputValueDefinition({
2134
- name: "relativePath",
2135
- type: astBuilder.TYPES.String
2136
- }));
2147
+ );
2137
2148
  return astBuilder.InputObjectTypeDefinition({
2138
2149
  name: NAMER.dataMutationUpdateTypeName(field.namespace),
2139
2150
  fields
@@ -2141,20 +2152,27 @@ var Builder = class {
2141
2152
  };
2142
2153
  this._buildObjectOrUnionData = async (collectableTemplate, extraFields = [], extraInterfaces = [], collection) => {
2143
2154
  if (collectableTemplate.type === "union") {
2144
- const name2 = NAMER.dataTypeName(collectableTemplate.namespace);
2155
+ const name = NAMER.dataTypeName(collectableTemplate.namespace);
2145
2156
  const typeMap = {};
2146
- const types = await sequential(collectableTemplate.templates, async (template) => {
2147
- const type = await this._buildTemplateData(template, extraFields, extraInterfaces);
2148
- typeMap[template.namespace[template.namespace.length - 1]] = type.name.value;
2149
- return type;
2150
- });
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
+ );
2151
2169
  await this.database.addToLookupMap({
2152
- type: name2,
2170
+ type: name,
2153
2171
  resolveType: "unionData",
2154
2172
  collection: collection == null ? void 0 : collection.name,
2155
2173
  typeMap
2156
2174
  });
2157
- return astBuilder.UnionTypeDefinition({ name: name2, types });
2175
+ return astBuilder.UnionTypeDefinition({ name, types });
2158
2176
  }
2159
2177
  return this._buildTemplateData(collectableTemplate.template);
2160
2178
  };
@@ -2184,7 +2202,9 @@ var Builder = class {
2184
2202
  type: await this._filterCollectionDocumentType(collection)
2185
2203
  });
2186
2204
  } else {
2187
- 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
+ );
2188
2208
  }
2189
2209
  return filter;
2190
2210
  };
@@ -2269,7 +2289,9 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2269
2289
  name: field.name,
2270
2290
  list: field.list,
2271
2291
  required: field.required,
2272
- type: await this._buildObjectOrUnionData(this.tinaSchema.getTemplatesForCollectable(field))
2292
+ type: await this._buildObjectOrUnionData(
2293
+ this.tinaSchema.getTemplatesForCollectable(field)
2294
+ )
2273
2295
  });
2274
2296
  case "rich-text":
2275
2297
  return astBuilder.FieldDefinition({
@@ -2279,23 +2301,29 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2279
2301
  type: astBuilder.TYPES.JSON
2280
2302
  });
2281
2303
  case "reference":
2282
- const name2 = NAMER.documentTypeName(field.namespace);
2304
+ const name = NAMER.documentTypeName(field.namespace);
2283
2305
  if (field.list) {
2284
2306
  console.warn(listWarningMsg);
2285
2307
  return this._buildMultiCollectionDocumentListDefinition({
2286
2308
  fieldName: field.name,
2287
2309
  namespace: field.namespace,
2288
2310
  nodeType: astBuilder.UnionTypeDefinition({
2289
- name: name2,
2290
- types: field.collections.map((collectionName) => NAMER.documentTypeName([collectionName]))
2311
+ name,
2312
+ types: field.collections.map(
2313
+ (collectionName) => NAMER.documentTypeName([collectionName])
2314
+ )
2291
2315
  }),
2292
- collections: this.tinaSchema.getCollectionsByName(field.collections),
2316
+ collections: this.tinaSchema.getCollectionsByName(
2317
+ field.collections
2318
+ ),
2293
2319
  connectionNamespace: field.namespace
2294
2320
  });
2295
2321
  } else {
2296
2322
  const type = await this._buildMultiCollectionDocumentDefinition({
2297
- fieldName: name2,
2298
- collections: this.tinaSchema.getCollectionsByName(field.collections)
2323
+ fieldName: name,
2324
+ collections: this.tinaSchema.getCollectionsByName(
2325
+ field.collections
2326
+ )
2299
2327
  });
2300
2328
  return astBuilder.FieldDefinition({
2301
2329
  name: field.name,
@@ -2365,12 +2393,12 @@ var filterSelections = (arr) => {
2365
2393
  };
2366
2394
 
2367
2395
  // src/schema/createSchema.ts
2368
- var import_schema_tools2 = __toModule(require("@tinacms/schema-tools"));
2396
+ var import_schema_tools2 = require("@tinacms/schema-tools");
2369
2397
 
2370
2398
  // src/schema/validate.ts
2371
- var import_lodash2 = __toModule(require("lodash"));
2372
- var yup2 = __toModule(require("yup"));
2373
- 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");
2374
2402
  var FIELD_TYPES = [
2375
2403
  "string",
2376
2404
  "number",
@@ -2382,8 +2410,13 @@ var FIELD_TYPES = [
2382
2410
  "rich-text"
2383
2411
  ];
2384
2412
  var validateSchema = async (schema) => {
2385
- const schema2 = addNamespaceToSchema(import_lodash2.default.cloneDeep(schema));
2386
- 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
+ );
2387
2420
  validationCollectionsPathAndMatch(collections);
2388
2421
  if (schema2.config) {
2389
2422
  const config = (0, import_schema_tools.validateTinaCloudSchemaConfig)(schema2.config);
@@ -2417,7 +2450,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2417
2450
  r[a.path] = r[a.path] || [];
2418
2451
  r[a.path].push(a);
2419
2452
  return r;
2420
- }, Object.create(null));
2453
+ }, /* @__PURE__ */ Object.create(null));
2421
2454
  Object.keys(groupbyPath).forEach((key) => {
2422
2455
  const collectionsArr = groupbyPath[key];
2423
2456
  if (collectionsArr.length === 1) {
@@ -2444,17 +2477,22 @@ var validateCollection = async (collection) => {
2444
2477
  })
2445
2478
  });
2446
2479
  await collectionSchema.validate(collection);
2447
- const validCollection = await collectionSchema.cast(collection);
2480
+ const validCollection = await collectionSchema.cast(
2481
+ collection
2482
+ );
2448
2483
  if (validCollection.templates) {
2449
- templates = await sequential(validCollection.templates, async (template) => {
2450
- if (typeof template === "string") {
2451
- throw new Error(`Global templates are not yet supported`);
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
+ };
2452
2494
  }
2453
- const fields2 = await sequential(template.fields, async (field) => {
2454
- return validateField(field);
2455
- });
2456
- return __spreadValues(__spreadValues({}, validCollection), fields2);
2457
- });
2495
+ );
2458
2496
  }
2459
2497
  if (validCollection.fields) {
2460
2498
  if (typeof validCollection.fields === "string") {
@@ -2463,9 +2501,10 @@ var validateCollection = async (collection) => {
2463
2501
  fields = await sequential(validCollection.fields, async (field) => {
2464
2502
  return validateField(field);
2465
2503
  });
2466
- return __spreadProps(__spreadValues({}, validCollection), {
2504
+ return {
2505
+ ...validCollection,
2467
2506
  fields
2468
- });
2507
+ };
2469
2508
  }
2470
2509
  return collection;
2471
2510
  };
@@ -2475,144 +2514,134 @@ var validateField = async (field) => {
2475
2514
  name: yup2.string().matches(/^[a-zA-Z0-9_]*$/, {
2476
2515
  message: (obj) => `Field's 'name' must match ${obj.regex} at ${messageName}`
2477
2516
  }).required(),
2478
- 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
+ )
2479
2521
  });
2480
2522
  await schema.validate(field);
2481
- return field;
2523
+ const validField = await schema.cast(field);
2524
+ return validField;
2482
2525
  };
2483
2526
 
2484
2527
  // package.json
2485
- var name = "@tinacms/graphql";
2486
- var version = "1.3.2";
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);
@@ -2842,25 +2929,26 @@ var resolveReferences = async (filter, fields, resolver) => {
2842
2929
  }
2843
2930
  } else if (fieldDefinition.type === "object") {
2844
2931
  if (fieldDefinition.templates) {
2845
- const globalTemplates = {};
2846
- for (const template of fieldDefinition.templates) {
2847
- if (typeof template === "string") {
2848
- globalTemplates[template] = 1;
2849
- }
2850
- }
2851
2932
  for (const templateName of Object.keys(filter[fieldKey])) {
2852
- if (templateName in globalTemplates) {
2853
- throw new Error("Global templates not yet supported for queries");
2854
- }
2855
- 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
+ );
2856
2936
  if (template) {
2857
- await resolveReferences(filter[fieldKey][templateName], template.fields, resolver);
2937
+ await resolveReferences(
2938
+ filter[fieldKey][templateName],
2939
+ template.fields,
2940
+ resolver
2941
+ );
2858
2942
  } else {
2859
2943
  throw new Error(`Template ${templateName} not found`);
2860
2944
  }
2861
2945
  }
2862
2946
  } else {
2863
- await resolveReferences(filter[fieldKey], fieldDefinition.fields, resolver);
2947
+ await resolveReferences(
2948
+ filter[fieldKey],
2949
+ fieldDefinition.fields,
2950
+ resolver
2951
+ );
2864
2952
  }
2865
2953
  }
2866
2954
  } else {
@@ -2874,41 +2962,57 @@ var collectConditionsForChildFields = (filterNode, fields, pathExpression, colle
2874
2962
  if (!childField) {
2875
2963
  throw new Error(`Unable to find type for field ${childFieldName}`);
2876
2964
  }
2877
- collectConditionsForField(childFieldName, childField, filterNode[childFieldName], pathExpression, collectCondition);
2965
+ collectConditionsForField(
2966
+ childFieldName,
2967
+ childField,
2968
+ filterNode[childFieldName],
2969
+ pathExpression,
2970
+ collectCondition
2971
+ );
2878
2972
  }
2879
2973
  };
2880
2974
  var collectConditionsForObjectField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
2881
2975
  if (field.list && field.templates) {
2882
- const globalTemplates = {};
2883
- for (const template of field.templates) {
2884
- if (typeof template === "string") {
2885
- globalTemplates[template] = 1;
2886
- }
2887
- }
2888
2976
  for (const [filterKey, childFilterNode] of Object.entries(filterNode)) {
2889
- if (filterKey in globalTemplates) {
2890
- throw new Error("Global templates not yet supported for queries");
2891
- }
2892
- 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
+ );
2893
2980
  const jsonPath = `${fieldName}[?(@._template=="${filterKey}")]`;
2894
2981
  const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : jsonPath;
2895
- collectConditionsForChildFields(childFilterNode, template.fields, filterPath, collectCondition);
2982
+ collectConditionsForChildFields(
2983
+ childFilterNode,
2984
+ template.fields,
2985
+ filterPath,
2986
+ collectCondition
2987
+ );
2896
2988
  }
2897
2989
  } else {
2898
2990
  const jsonPath = `${fieldName}${field.list ? "[*]" : ""}`;
2899
2991
  const filterPath = pathExpression ? `${pathExpression}.${jsonPath}` : `${jsonPath}`;
2900
- collectConditionsForChildFields(filterNode, field.fields, filterPath, collectCondition);
2992
+ collectConditionsForChildFields(
2993
+ filterNode,
2994
+ field.fields,
2995
+ filterPath,
2996
+ collectCondition
2997
+ );
2901
2998
  }
2902
2999
  };
2903
3000
  var collectConditionsForField = (fieldName, field, filterNode, pathExpression, collectCondition) => {
2904
3001
  if (field.type === "object") {
2905
- collectConditionsForObjectField(fieldName, field, filterNode, pathExpression, collectCondition);
3002
+ collectConditionsForObjectField(
3003
+ fieldName,
3004
+ field,
3005
+ filterNode,
3006
+ pathExpression,
3007
+ collectCondition
3008
+ );
2906
3009
  } else {
2907
3010
  collectCondition({
2908
3011
  filterPath: pathExpression ? `${pathExpression}.${fieldName}` : fieldName,
2909
- filterExpression: __spreadValues({
2910
- _type: field.type
2911
- }, filterNode)
3012
+ filterExpression: {
3013
+ _type: field.type,
3014
+ ...filterNode
3015
+ }
2912
3016
  });
2913
3017
  }
2914
3018
  };
@@ -2922,7 +3026,9 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
2922
3026
  if (hasTinaMediaConfig(schema) === true) {
2923
3027
  const assetsURL = `https://${config.assetsHost}/${config.clientId}`;
2924
3028
  if (typeof value === "string" && value.includes(assetsURL)) {
2925
- const cleanMediaRoot = cleanUpSlashes(schema.config.media.tina.mediaRoot);
3029
+ const cleanMediaRoot = cleanUpSlashes(
3030
+ schema.config.media.tina.mediaRoot
3031
+ );
2926
3032
  const strippedURL = value.replace(assetsURL, "");
2927
3033
  return `${cleanMediaRoot}${strippedURL}`;
2928
3034
  }
@@ -2963,10 +3069,10 @@ var hasTinaMediaConfig = (schema) => {
2963
3069
  };
2964
3070
 
2965
3071
  // src/resolver/index.ts
2966
- var import_graphql3 = __toModule(require("graphql"));
3072
+ var import_graphql3 = require("graphql");
2967
3073
 
2968
3074
  // src/database/datalayer.ts
2969
- var import_jsonpath_plus = __toModule(require("jsonpath-plus"));
3075
+ var import_jsonpath_plus = require("jsonpath-plus");
2970
3076
 
2971
3077
  // src/database/level.ts
2972
3078
  var INDEX_KEY_FIELD_SEPARATOR = "";
@@ -2997,7 +3103,10 @@ var LevelProxyHandler = {
2997
3103
  };
2998
3104
  } else if (property === "sublevel") {
2999
3105
  return (...args) => {
3000
- return new Proxy(target[property].apply(target, args), LevelProxyHandler);
3106
+ return new Proxy(
3107
+ target[property].apply(target, args),
3108
+ LevelProxyHandler
3109
+ );
3001
3110
  };
3002
3111
  } else {
3003
3112
  return (...args) => target[property].apply(target, args);
@@ -3011,22 +3120,14 @@ var LevelProxy = class {
3011
3120
  };
3012
3121
 
3013
3122
  // src/database/datalayer.ts
3014
- var OP;
3015
- (function(OP2) {
3016
- OP2["EQ"] = "eq";
3017
- OP2["GT"] = "gt";
3018
- OP2["LT"] = "lt";
3019
- OP2["GTE"] = "gte";
3020
- OP2["LTE"] = "lte";
3021
- OP2["STARTS_WITH"] = "startsWith";
3022
- OP2["IN"] = "in";
3023
- })(OP || (OP = {}));
3024
3123
  var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
3025
3124
  var DEFAULT_NUMERIC_LPAD = 4;
3026
3125
  var applyPadding = (input, pad) => {
3027
3126
  if (pad) {
3028
3127
  if (Array.isArray(input)) {
3029
- 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
+ );
3030
3131
  } else {
3031
3132
  return String(input).padStart(pad.maxLength, pad.fillString);
3032
3133
  }
@@ -3039,23 +3140,23 @@ var getFilterOperator = (expression, operand) => {
3039
3140
  var inferOperatorFromFilter = (filterOperator) => {
3040
3141
  switch (filterOperator) {
3041
3142
  case "after":
3042
- return OP.GT;
3143
+ return "gt" /* GT */;
3043
3144
  case "before":
3044
- return OP.LT;
3145
+ return "lt" /* LT */;
3045
3146
  case "eq":
3046
- return OP.EQ;
3147
+ return "eq" /* EQ */;
3047
3148
  case "startsWith":
3048
- return OP.STARTS_WITH;
3149
+ return "startsWith" /* STARTS_WITH */;
3049
3150
  case "lt":
3050
- return OP.LT;
3151
+ return "lt" /* LT */;
3051
3152
  case "lte":
3052
- return OP.LTE;
3153
+ return "lte" /* LTE */;
3053
3154
  case "gt":
3054
- return OP.GT;
3155
+ return "gt" /* GT */;
3055
3156
  case "gte":
3056
- return OP.GTE;
3157
+ return "gte" /* GTE */;
3057
3158
  case "in":
3058
- return OP.IN;
3159
+ return "in" /* IN */;
3059
3160
  default:
3060
3161
  throw new Error(`unsupported filter condition: '${filterOperator}'`);
3061
3162
  }
@@ -3065,7 +3166,9 @@ var makeKeyForField = (definition, data, stringEscaper2, maxStringLength = 100)
3065
3166
  for (const field of definition.fields) {
3066
3167
  if (field.name in data && data[field.name] !== void 0 && data[field.name] !== null) {
3067
3168
  const rawValue = data[field.name];
3068
- 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);
3069
3172
  valueParts.push(applyPadding(resolvedValue, field.pad));
3070
3173
  } else {
3071
3174
  return null;
@@ -3080,34 +3183,54 @@ var coerceFilterChainOperands = (filterChain, escapeString = stringEscaper) => {
3080
3183
  const dataType = filter.type;
3081
3184
  if (dataType === "datetime") {
3082
3185
  if (filter.leftOperand !== void 0) {
3083
- result.push(__spreadProps(__spreadValues({}, filter), {
3186
+ result.push({
3187
+ ...filter,
3084
3188
  rightOperand: new Date(filter.rightOperand).getTime(),
3085
- leftOperand: new Date(filter.leftOperand).getTime()
3086
- }));
3189
+ leftOperand: new Date(
3190
+ filter.leftOperand
3191
+ ).getTime()
3192
+ });
3087
3193
  } else {
3088
3194
  if (Array.isArray(filter.rightOperand)) {
3089
- result.push(__spreadProps(__spreadValues({}, filter), {
3090
- rightOperand: filter.rightOperand.map((operand) => new Date(operand).getTime())
3091
- }));
3195
+ result.push({
3196
+ ...filter,
3197
+ rightOperand: filter.rightOperand.map(
3198
+ (operand) => new Date(operand).getTime()
3199
+ )
3200
+ });
3092
3201
  } else {
3093
- result.push(__spreadProps(__spreadValues({}, filter), {
3202
+ result.push({
3203
+ ...filter,
3094
3204
  rightOperand: new Date(filter.rightOperand).getTime()
3095
- }));
3205
+ });
3096
3206
  }
3097
3207
  }
3098
3208
  } else if (dataType === "string") {
3099
3209
  if (filter.leftOperand !== void 0) {
3100
- result.push(__spreadProps(__spreadValues({}, filter), {
3101
- rightOperand: applyPadding(escapeString(filter.rightOperand), filter.pad),
3102
- leftOperand: applyPadding(escapeString(filter.leftOperand), filter.pad)
3103
- }));
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
+ });
3104
3223
  } else {
3105
- result.push(__spreadProps(__spreadValues({}, filter), {
3106
- rightOperand: applyPadding(escapeString(filter.rightOperand), filter.pad)
3107
- }));
3224
+ result.push({
3225
+ ...filter,
3226
+ rightOperand: applyPadding(
3227
+ escapeString(filter.rightOperand),
3228
+ filter.pad
3229
+ )
3230
+ });
3108
3231
  }
3109
3232
  } else {
3110
- result.push(__spreadValues({}, filter));
3233
+ result.push({ ...filter });
3111
3234
  }
3112
3235
  }
3113
3236
  }
@@ -3137,7 +3260,9 @@ var makeFilter = ({
3137
3260
  return isNaN(coerced) ? Number(resolvedValue) : coerced;
3138
3261
  });
3139
3262
  } else if (dataType === "boolean") {
3140
- 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
+ );
3141
3266
  } else {
3142
3267
  throw new Error(`Unexpected datatype ${dataType}`);
3143
3268
  }
@@ -3145,12 +3270,14 @@ var makeFilter = ({
3145
3270
  let matches = false;
3146
3271
  if (operator) {
3147
3272
  switch (operator) {
3148
- case OP.EQ:
3149
- if (operands.findIndex((operand) => operand === filter.rightOperand) >= 0) {
3273
+ case "eq" /* EQ */:
3274
+ if (operands.findIndex(
3275
+ (operand) => operand === filter.rightOperand
3276
+ ) >= 0) {
3150
3277
  matches = true;
3151
3278
  }
3152
3279
  break;
3153
- case OP.GT:
3280
+ case "gt" /* GT */:
3154
3281
  for (const operand of operands) {
3155
3282
  if (operand > filter.rightOperand) {
3156
3283
  matches = true;
@@ -3158,7 +3285,7 @@ var makeFilter = ({
3158
3285
  }
3159
3286
  }
3160
3287
  break;
3161
- case OP.LT:
3288
+ case "lt" /* LT */:
3162
3289
  for (const operand of operands) {
3163
3290
  if (operand < filter.rightOperand) {
3164
3291
  matches = true;
@@ -3166,7 +3293,7 @@ var makeFilter = ({
3166
3293
  }
3167
3294
  }
3168
3295
  break;
3169
- case OP.GTE:
3296
+ case "gte" /* GTE */:
3170
3297
  for (const operand of operands) {
3171
3298
  if (operand >= filter.rightOperand) {
3172
3299
  matches = true;
@@ -3174,7 +3301,7 @@ var makeFilter = ({
3174
3301
  }
3175
3302
  }
3176
3303
  break;
3177
- case OP.LTE:
3304
+ case "lte" /* LTE */:
3178
3305
  for (const operand of operands) {
3179
3306
  if (operand <= filter.rightOperand) {
3180
3307
  matches = true;
@@ -3182,7 +3309,7 @@ var makeFilter = ({
3182
3309
  }
3183
3310
  }
3184
3311
  break;
3185
- case OP.IN:
3312
+ case "in" /* IN */:
3186
3313
  for (const operand of operands) {
3187
3314
  if (filter.rightOperand.indexOf(operand) >= 0) {
3188
3315
  matches = true;
@@ -3190,7 +3317,7 @@ var makeFilter = ({
3190
3317
  }
3191
3318
  }
3192
3319
  break;
3193
- case OP.STARTS_WITH:
3320
+ case "startsWith" /* STARTS_WITH */:
3194
3321
  for (const operand of operands) {
3195
3322
  if (operand.startsWith(filter.rightOperand)) {
3196
3323
  matches = true;
@@ -3206,14 +3333,14 @@ var makeFilter = ({
3206
3333
  for (const operand of operands) {
3207
3334
  let rightMatches = false;
3208
3335
  let leftMatches = false;
3209
- if (rightOperator === OP.LTE && operand <= rightOperand) {
3336
+ if (rightOperator === "lte" /* LTE */ && operand <= rightOperand) {
3210
3337
  rightMatches = true;
3211
- } else if (rightOperator === OP.LT && operand < rightOperand) {
3338
+ } else if (rightOperator === "lt" /* LT */ && operand < rightOperand) {
3212
3339
  rightMatches = true;
3213
3340
  }
3214
- if (leftOperator === OP.GTE && operand >= leftOperand) {
3341
+ if (leftOperator === "gte" /* GTE */ && operand >= leftOperand) {
3215
3342
  leftMatches = true;
3216
- } else if (leftOperator === OP.GT && operand > leftOperand) {
3343
+ } else if (leftOperator === "gt" /* GT */ && operand > leftOperand) {
3217
3344
  leftMatches = true;
3218
3345
  }
3219
3346
  if (rightMatches && leftMatches) {
@@ -3238,10 +3365,12 @@ var makeFilterChain = ({
3238
3365
  }
3239
3366
  for (const condition of conditions) {
3240
3367
  const { filterPath, filterExpression } = condition;
3241
- const _a = filterExpression, { _type } = _a, keys = __objRest(_a, ["_type"]);
3368
+ const { _type, ...keys } = filterExpression;
3242
3369
  const [key1, key2, ...extraKeys] = Object.keys(keys);
3243
3370
  if (extraKeys.length) {
3244
- throw new Error(`Unexpected keys: [${extraKeys.join(",")}] in filter expression`);
3371
+ throw new Error(
3372
+ `Unexpected keys: [${extraKeys.join(",")}] in filter expression`
3373
+ );
3245
3374
  }
3246
3375
  if (key1 && !key2) {
3247
3376
  filterChain.push({
@@ -3274,7 +3403,9 @@ var makeFilterChain = ({
3274
3403
  pad: _type === "number" ? { fillString: "0", maxLength: DEFAULT_NUMERIC_LPAD } : void 0
3275
3404
  });
3276
3405
  } else {
3277
- 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
+ );
3278
3409
  }
3279
3410
  }
3280
3411
  }
@@ -3289,7 +3420,7 @@ var makeFilterSuffixes = (filterChain, index) => {
3289
3420
  if (idx === -1) {
3290
3421
  return;
3291
3422
  }
3292
- if (filter.operator && filter.operator === OP.IN) {
3423
+ if (filter.operator && filter.operator === "in" /* IN */) {
3293
3424
  return;
3294
3425
  }
3295
3426
  orderedFilterChain[idx] = filter;
@@ -3311,20 +3442,34 @@ var makeFilterSuffixes = (filterChain, index) => {
3311
3442
  return;
3312
3443
  }
3313
3444
  const binaryFilter = filter;
3314
- if (binaryFilter.operator !== OP.EQ) {
3445
+ if (binaryFilter.operator !== "eq" /* EQ */) {
3315
3446
  return;
3316
3447
  }
3317
- baseFragments.push(applyPadding(orderedFilterChain[i].rightOperand, orderedFilterChain[i].pad));
3448
+ baseFragments.push(
3449
+ applyPadding(
3450
+ orderedFilterChain[i].rightOperand,
3451
+ orderedFilterChain[i].pad
3452
+ )
3453
+ );
3318
3454
  } else {
3319
3455
  if (ternaryFilter) {
3320
- leftSuffix = applyPadding(orderedFilterChain[i].leftOperand, orderedFilterChain[i].pad);
3321
- 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
+ );
3322
3464
  } else {
3323
3465
  const op = orderedFilterChain[i].operator;
3324
- const operand = applyPadding(orderedFilterChain[i].rightOperand, orderedFilterChain[i].pad);
3325
- 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 */) {
3326
3471
  rightSuffix = operand;
3327
- } else if (op === OP.GT || op === OP.GTE) {
3472
+ } else if (op === "gt" /* GT */ || op === "gte" /* GTE */) {
3328
3473
  leftSuffix = operand;
3329
3474
  } else {
3330
3475
  rightSuffix = operand;
@@ -3372,13 +3517,18 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
3372
3517
  var makeStringEscaper = (regex, replacement) => {
3373
3518
  return (input) => {
3374
3519
  if (Array.isArray(input)) {
3375
- return input.map((val) => val.replace(regex, replacement));
3520
+ return input.map(
3521
+ (val) => val.replace(regex, replacement)
3522
+ );
3376
3523
  } else {
3377
3524
  return input.replace(regex, replacement);
3378
3525
  }
3379
3526
  };
3380
3527
  };
3381
- 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
+ );
3382
3532
 
3383
3533
  // src/resolver/index.ts
3384
3534
  var createResolver = (args) => {
@@ -3390,9 +3540,11 @@ var Resolver = class {
3390
3540
  this.resolveCollection = async (args, collectionName, hasDocuments) => {
3391
3541
  const collection = this.tinaSchema.getCollection(collectionName);
3392
3542
  const extraFields = {};
3393
- return __spreadValues(__spreadValues({
3394
- documents: { collection, hasDocuments }
3395
- }, collection), extraFields);
3543
+ return {
3544
+ documents: { collection, hasDocuments },
3545
+ ...collection,
3546
+ ...extraFields
3547
+ };
3396
3548
  };
3397
3549
  this.getDocument = async (fullPath) => {
3398
3550
  if (typeof fullPath !== "string") {
@@ -3436,10 +3588,10 @@ var Resolver = class {
3436
3588
  });
3437
3589
  const titleFieldName = titleField == null ? void 0 : titleField.name;
3438
3590
  const title = data[titleFieldName || " "] || null;
3439
- return __spreadProps(__spreadValues({
3591
+ return {
3440
3592
  __typename: collection.fields ? NAMER.documentTypeName(collection.namespace) : NAMER.documentTypeName(template.namespace),
3441
- id: fullPath
3442
- }, data), {
3593
+ id: fullPath,
3594
+ ...data,
3443
3595
  _sys: {
3444
3596
  title,
3445
3597
  basename,
@@ -3453,12 +3605,13 @@ var Resolver = class {
3453
3605
  },
3454
3606
  _values: data,
3455
3607
  _rawData: rawData
3456
- });
3608
+ };
3457
3609
  } catch (e) {
3458
3610
  if (e instanceof TinaGraphQLError) {
3459
- throw new TinaGraphQLError(e.message, __spreadValues({
3460
- requestedDocument: fullPath
3461
- }, e.extensions));
3611
+ throw new TinaGraphQLError(e.message, {
3612
+ requestedDocument: fullPath,
3613
+ ...e.extensions
3614
+ });
3462
3615
  }
3463
3616
  throw e;
3464
3617
  }
@@ -3471,52 +3624,61 @@ var Resolver = class {
3471
3624
  };
3472
3625
  this.buildObjectMutations = (fieldValue, field) => {
3473
3626
  if (field.fields) {
3474
- const objectTemplate = typeof field.fields === "string" ? this.tinaSchema.getGlobalTemplate(field.fields) : field;
3627
+ const objectTemplate = field;
3475
3628
  if (Array.isArray(fieldValue)) {
3476
- return fieldValue.map((item) => this.buildFieldMutations(item, objectTemplate));
3629
+ return fieldValue.map(
3630
+ (item) => this.buildFieldMutations(item, objectTemplate)
3631
+ );
3477
3632
  } else {
3478
- return this.buildFieldMutations(fieldValue, objectTemplate);
3633
+ return this.buildFieldMutations(
3634
+ fieldValue,
3635
+ objectTemplate
3636
+ );
3479
3637
  }
3480
3638
  }
3481
3639
  if (field.templates) {
3482
3640
  if (Array.isArray(fieldValue)) {
3483
3641
  return fieldValue.map((item) => {
3484
3642
  if (typeof item === "string") {
3485
- 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
+ );
3486
3646
  }
3487
3647
  const templates = field.templates.map((templateOrTemplateName) => {
3488
- if (typeof templateOrTemplateName === "string") {
3489
- return this.tinaSchema.getGlobalTemplate(templateOrTemplateName);
3490
- }
3491
3648
  return templateOrTemplateName;
3492
3649
  });
3493
3650
  const [templateName] = Object.entries(item)[0];
3494
- const template = templates.find((template2) => template2.name === templateName);
3651
+ const template = templates.find(
3652
+ (template2) => template2.name === templateName
3653
+ );
3495
3654
  if (!template) {
3496
3655
  throw new Error(`Expected to find template ${templateName}`);
3497
3656
  }
3498
- return __spreadProps(__spreadValues({}, this.buildFieldMutations(item[template.name], template)), {
3657
+ return {
3658
+ ...this.buildFieldMutations(item[template.name], template),
3499
3659
  _template: template.name
3500
- });
3660
+ };
3501
3661
  });
3502
3662
  } else {
3503
3663
  if (typeof fieldValue === "string") {
3504
- 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
+ );
3505
3667
  }
3506
3668
  const templates = field.templates.map((templateOrTemplateName) => {
3507
- if (typeof templateOrTemplateName === "string") {
3508
- return this.tinaSchema.getGlobalTemplate(templateOrTemplateName);
3509
- }
3510
3669
  return templateOrTemplateName;
3511
3670
  });
3512
3671
  const [templateName] = Object.entries(fieldValue)[0];
3513
- const template = templates.find((template2) => template2.name === templateName);
3672
+ const template = templates.find(
3673
+ (template2) => template2.name === templateName
3674
+ );
3514
3675
  if (!template) {
3515
3676
  throw new Error(`Expected to find template ${templateName}`);
3516
3677
  }
3517
- return __spreadProps(__spreadValues({}, this.buildFieldMutations(fieldValue[template.name], template)), {
3678
+ return {
3679
+ ...this.buildFieldMutations(fieldValue[template.name], template),
3518
3680
  _template: template.name
3519
- });
3681
+ };
3520
3682
  }
3521
3683
  }
3522
3684
  };
@@ -3534,12 +3696,18 @@ var Resolver = class {
3534
3696
  break;
3535
3697
  case "union":
3536
3698
  const templateString = args.template;
3537
- const template = templateInfo.templates.find((template2) => lastItem(template2.namespace) === templateString);
3699
+ const template = templateInfo.templates.find(
3700
+ (template2) => lastItem(template2.namespace) === templateString
3701
+ );
3538
3702
  if (!args.template) {
3539
- 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
+ );
3540
3706
  }
3541
3707
  if (!template) {
3542
- 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
+ );
3543
3711
  }
3544
3712
  await this.database.addPendingDocument(realPath, {
3545
3713
  _template: lastItem(template.namespace)
@@ -3547,7 +3715,10 @@ var Resolver = class {
3547
3715
  }
3548
3716
  return this.getDocument(realPath);
3549
3717
  }
3550
- const params = this.buildObjectMutations(args.params[collection.name], collection);
3718
+ const params = this.buildObjectMutations(
3719
+ args.params[collection.name],
3720
+ collection
3721
+ );
3551
3722
  await this.database.put(realPath, params, collection.name);
3552
3723
  return this.getDocument(realPath);
3553
3724
  };
@@ -3566,8 +3737,15 @@ var Resolver = class {
3566
3737
  switch (templateInfo.type) {
3567
3738
  case "object":
3568
3739
  if (params2) {
3569
- const values = this.buildFieldMutations(params2, templateInfo.template);
3570
- 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
+ );
3571
3749
  }
3572
3750
  break;
3573
3751
  case "union":
@@ -3575,19 +3753,26 @@ var Resolver = class {
3575
3753
  const templateParams = params2[lastItem(template.namespace)];
3576
3754
  if (templateParams) {
3577
3755
  if (typeof templateParams === "string") {
3578
- 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
+ );
3579
3759
  }
3580
- const values = __spreadProps(__spreadValues(__spreadValues({}, oldDoc), this.buildFieldMutations(templateParams, template)), {
3760
+ const values = {
3761
+ ...oldDoc,
3762
+ ...this.buildFieldMutations(templateParams, template),
3581
3763
  _template: lastItem(template.namespace)
3582
- });
3764
+ };
3583
3765
  await this.database.put(realPath, values, collection.name);
3584
3766
  }
3585
3767
  });
3586
3768
  }
3587
3769
  return this.getDocument(realPath);
3588
3770
  }
3589
- const params = this.buildObjectMutations(isCollectionSpecific ? args.params : args.params[collection.name], collection);
3590
- 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);
3591
3776
  return this.getDocument(realPath);
3592
3777
  };
3593
3778
  this.resolveDocument = async ({
@@ -3605,10 +3790,19 @@ var Resolver = class {
3605
3790
  collectionLookup = Object.keys(args.params)[0];
3606
3791
  }
3607
3792
  const collectionNames = this.tinaSchema.getCollections().map((item) => item.name);
3608
- assertShape(collectionLookup, (yup3) => {
3609
- return yup3.mixed().oneOf(collectionNames);
3610
- }, `"collection" must be one of: [${collectionNames.join(", ")}] but got ${collectionLookup}`);
3611
- 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
+ );
3612
3806
  const collection = await this.tinaSchema.getCollection(collectionLookup);
3613
3807
  const realPath = import_path2.default.join(collection == null ? void 0 : collection.path, args.relativePath);
3614
3808
  const alreadyExists = await this.database.documentExists(realPath);
@@ -3626,10 +3820,14 @@ var Resolver = class {
3626
3820
  }
3627
3821
  if (!alreadyExists) {
3628
3822
  if (isDeletion) {
3629
- 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
+ );
3630
3826
  }
3631
3827
  if (isUpdateName) {
3632
- 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
+ );
3633
3831
  }
3634
3832
  }
3635
3833
  if (isDeletion) {
@@ -3638,10 +3836,19 @@ var Resolver = class {
3638
3836
  return doc;
3639
3837
  }
3640
3838
  if (isUpdateName) {
3641
- assertShape(args, (yup3) => yup3.object({ params: yup3.object().required() }));
3642
- 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
+ );
3643
3847
  const doc = await this.getDocument(realPath);
3644
- 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
+ );
3645
3852
  await this.database.put(newRealPath, doc._rawData, collection.name);
3646
3853
  await this.deleteDocument(realPath);
3647
3854
  return this.getDocument(newRealPath);
@@ -3672,20 +3879,30 @@ var Resolver = class {
3672
3879
  };
3673
3880
  };
3674
3881
  this.referenceResolver = async (filter, fieldDefinition) => {
3675
- const referencedCollection = this.tinaSchema.getCollection(fieldDefinition.collections[0]);
3882
+ const referencedCollection = this.tinaSchema.getCollection(
3883
+ fieldDefinition.collections[0]
3884
+ );
3676
3885
  if (!referencedCollection) {
3677
- 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
+ );
3678
3889
  }
3679
- const sortKeys = Object.keys(filter[fieldDefinition.name][referencedCollection.name]);
3680
- const resolvedCollectionConnection = await this.resolveCollectionConnection({
3681
- args: {
3682
- sort: sortKeys.length === 1 ? sortKeys[0] : void 0,
3683
- filter: __spreadValues({}, filter[fieldDefinition.name][referencedCollection.name]),
3684
- first: -1
3685
- },
3686
- collection: referencedCollection,
3687
- hydrator: (path6) => path6
3688
- });
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
+ );
3689
3906
  const { edges } = resolvedCollectionConnection;
3690
3907
  const values = edges.map((edge) => edge.node);
3691
3908
  return { edges, values };
@@ -3698,14 +3915,26 @@ var Resolver = class {
3698
3915
  let conditions;
3699
3916
  if (args.filter) {
3700
3917
  if (collection.fields) {
3701
- 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
+ );
3702
3923
  } else if (collection.templates) {
3703
3924
  for (const templateName of Object.keys(args.filter)) {
3704
- const template = collection.templates.find((template2) => template2.name === templateName);
3925
+ const template = collection.templates.find(
3926
+ (template2) => template2.name === templateName
3927
+ );
3705
3928
  if (template) {
3706
- 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
+ );
3707
3934
  } else {
3708
- 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
+ );
3709
3938
  }
3710
3939
  }
3711
3940
  }
@@ -3721,7 +3950,10 @@ var Resolver = class {
3721
3950
  before: args.before,
3722
3951
  after: args.after
3723
3952
  };
3724
- 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
+ );
3725
3957
  const edges = result.edges;
3726
3958
  const pageInfo = result.pageInfo;
3727
3959
  return {
@@ -3758,13 +3990,25 @@ var Resolver = class {
3758
3990
  accum[fieldName] = fieldValue;
3759
3991
  break;
3760
3992
  case "image":
3761
- accum[fieldName] = resolveMediaCloudToRelative(fieldValue, this.config, this.tinaSchema.schema);
3993
+ accum[fieldName] = resolveMediaCloudToRelative(
3994
+ fieldValue,
3995
+ this.config,
3996
+ this.tinaSchema.schema
3997
+ );
3762
3998
  break;
3763
3999
  case "object":
3764
4000
  accum[fieldName] = this.buildObjectMutations(fieldValue, field);
3765
4001
  break;
3766
4002
  case "rich-text":
3767
- 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
+ );
3768
4012
  break;
3769
4013
  case "reference":
3770
4014
  accum[fieldName] = fieldValue;
@@ -3775,9 +4019,8 @@ var Resolver = class {
3775
4019
  });
3776
4020
  return accum;
3777
4021
  };
3778
- this.resolveFieldData = async (_a, rawData, accumulator) => {
3779
- var _b = _a, { namespace } = _b, field = __objRest(_b, ["namespace"]);
3780
- var _a2;
4022
+ this.resolveFieldData = async ({ namespace, ...field }, rawData, accumulator) => {
4023
+ var _a;
3781
4024
  if (!rawData) {
3782
4025
  return void 0;
3783
4026
  }
@@ -3798,14 +4041,28 @@ var Resolver = class {
3798
4041
  accumulator[field.name] = value;
3799
4042
  break;
3800
4043
  case "image":
3801
- 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
+ );
3802
4049
  break;
3803
4050
  case "rich-text":
3804
- const tree = (0, import_mdx.parseMDX)(value, field, (value2) => resolveMediaRelativeToCloud(value2, this.config, this.tinaSchema.schema));
3805
- 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") {
3806
4061
  if (this.isAudit) {
3807
4062
  const invalidNode = tree == null ? void 0 : tree.children[0];
3808
- 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
+ );
3809
4066
  }
3810
4067
  }
3811
4068
  accumulator[field.name] = tree;
@@ -3815,22 +4072,27 @@ var Resolver = class {
3815
4072
  if (!value) {
3816
4073
  return;
3817
4074
  }
3818
- assertShape(value, (yup3) => yup3.array().of(yup3.object().required()));
4075
+ assertShape(
4076
+ value,
4077
+ (yup3) => yup3.array().of(yup3.object().required())
4078
+ );
3819
4079
  accumulator[field.name] = await sequential(value, async (item) => {
3820
4080
  const template = await this.tinaSchema.getTemplateForData({
3821
4081
  data: item,
3822
- collection: __spreadValues({
3823
- namespace
3824
- }, field)
4082
+ collection: {
4083
+ namespace,
4084
+ ...field
4085
+ }
3825
4086
  });
3826
4087
  const payload = {};
3827
4088
  await sequential(template.fields, async (field2) => {
3828
4089
  await this.resolveFieldData(field2, item, payload);
3829
4090
  });
3830
4091
  const isUnion = !!field.templates;
3831
- return isUnion ? __spreadValues({
3832
- _template: lastItem(template.namespace)
3833
- }, payload) : payload;
4092
+ return isUnion ? {
4093
+ _template: lastItem(template.namespace),
4094
+ ...payload
4095
+ } : payload;
3834
4096
  });
3835
4097
  } else {
3836
4098
  if (!value) {
@@ -3838,18 +4100,20 @@ var Resolver = class {
3838
4100
  }
3839
4101
  const template = await this.tinaSchema.getTemplateForData({
3840
4102
  data: value,
3841
- collection: __spreadValues({
3842
- namespace
3843
- }, field)
4103
+ collection: {
4104
+ namespace,
4105
+ ...field
4106
+ }
3844
4107
  });
3845
4108
  const payload = {};
3846
4109
  await sequential(template.fields, async (field2) => {
3847
4110
  await this.resolveFieldData(field2, value, payload);
3848
4111
  });
3849
4112
  const isUnion = !!field.templates;
3850
- accumulator[field.name] = isUnion ? __spreadValues({
3851
- _template: lastItem(template.namespace)
3852
- }, payload) : payload;
4113
+ accumulator[field.name] = isUnion ? {
4114
+ _template: lastItem(template.namespace),
4115
+ ...payload
4116
+ } : payload;
3853
4117
  }
3854
4118
  break;
3855
4119
  default:
@@ -3859,16 +4123,22 @@ var Resolver = class {
3859
4123
  };
3860
4124
  this.buildParams = (args) => {
3861
4125
  try {
3862
- assertShape(args, (yup3) => yup3.object({
3863
- collection: yup3.string().required(),
3864
- params: yup3.object().required()
3865
- }));
4126
+ assertShape(
4127
+ args,
4128
+ (yup3) => yup3.object({
4129
+ collection: yup3.string().required(),
4130
+ params: yup3.object().required()
4131
+ })
4132
+ );
3866
4133
  return args.params[args.collection];
3867
4134
  } catch (e) {
3868
4135
  }
3869
- assertShape(args, (yup3) => yup3.object({
3870
- params: yup3.object().required()
3871
- }));
4136
+ assertShape(
4137
+ args,
4138
+ (yup3) => yup3.object({
4139
+ params: yup3.object().required()
4140
+ })
4141
+ );
3872
4142
  return args.params;
3873
4143
  };
3874
4144
  this.config = init.config;
@@ -3883,17 +4153,29 @@ var Resolver = class {
3883
4153
  throw new Error("Error parsing filter - unable to generate filterPath");
3884
4154
  }
3885
4155
  if (!condition.filterExpression) {
3886
- 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
+ );
3887
4159
  }
3888
4160
  conditions.push(condition);
3889
4161
  };
3890
4162
  await resolveReferences(filter, fields, this.referenceResolver);
3891
4163
  for (const fieldName of Object.keys(filter)) {
3892
- const field = fields.find((field2) => field2.name === fieldName);
4164
+ const field = fields.find(
4165
+ (field2) => field2.name === fieldName
4166
+ );
3893
4167
  if (!field) {
3894
- throw new Error(`${fieldName} not found in collection ${collectionName}`);
4168
+ throw new Error(
4169
+ `${fieldName} not found in collection ${collectionName}`
4170
+ );
3895
4171
  }
3896
- collectConditionsForField(fieldName, field, filter[fieldName], "", conditionCollector);
4172
+ collectConditionsForField(
4173
+ fieldName,
4174
+ field,
4175
+ filter[fieldName],
4176
+ "",
4177
+ conditionCollector
4178
+ );
3897
4179
  }
3898
4180
  return conditions;
3899
4181
  }
@@ -3907,7 +4189,7 @@ var resolveDateInput = (value) => {
3907
4189
  };
3908
4190
 
3909
4191
  // src/resolve.ts
3910
- var import_relay_operation_optimizer = __toModule(require("@graphql-tools/relay-operation-optimizer"));
4192
+ var import_relay_operation_optimizer = require("@graphql-tools/relay-operation-optimizer");
3911
4193
  var resolve = async ({
3912
4194
  config,
3913
4195
  query,
@@ -3964,32 +4246,54 @@ var resolve = async ({
3964
4246
  return value;
3965
4247
  }
3966
4248
  if (info.fieldName === "collections") {
3967
- const collectionNode2 = info.fieldNodes.find((x) => x.name.value === "collections");
3968
- const hasDocuments2 = collectionNode2.selectionSet.selections.find((x) => {
3969
- var _a3;
3970
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
3971
- });
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
+ );
3972
4258
  return tinaSchema.getCollections().map((collection) => {
3973
- return resolver.resolveCollection(args, collection.name, Boolean(hasDocuments2));
4259
+ return resolver.resolveCollection(
4260
+ args,
4261
+ collection.name,
4262
+ Boolean(hasDocuments2)
4263
+ );
3974
4264
  });
3975
4265
  }
3976
- const collectionNode = info.fieldNodes.find((x) => x.name.value === "collection");
3977
- const hasDocuments = collectionNode.selectionSet.selections.find((x) => {
3978
- var _a3;
3979
- return ((_a3 = x == null ? void 0 : x.name) == null ? void 0 : _a3.value) === "documents";
3980
- });
3981
- 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
+ );
3982
4280
  }
3983
4281
  if (info.fieldName === "getOptimizedQuery") {
3984
4282
  try {
3985
- const [optimizedQuery] = (0, import_relay_operation_optimizer.optimizeDocuments)(info.schema, [(0, import_graphql4.parse)(args.queryString)], {
3986
- assumeValid: true,
3987
- includeFragments: false,
3988
- noLocation: true
3989
- });
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
+ );
3990
4292
  return (0, import_graphql4.print)(optimizedQuery);
3991
4293
  } catch (e) {
3992
- throw new Error(`Invalid query provided, Error message: ${e.message}`);
4294
+ throw new Error(
4295
+ `Invalid query provided, Error message: ${e.message}`
4296
+ );
3993
4297
  }
3994
4298
  }
3995
4299
  if (!lookup) {
@@ -3998,7 +4302,10 @@ var resolve = async ({
3998
4302
  const isCreation = lookup[info.fieldName] === "create";
3999
4303
  switch (lookup.resolveType) {
4000
4304
  case "nodeDocument":
4001
- assertShape(args, (yup3) => yup3.object({ id: yup3.string().required() }));
4305
+ assertShape(
4306
+ args,
4307
+ (yup3) => yup3.object({ id: yup3.string().required() })
4308
+ );
4002
4309
  return resolver.getDocument(args.id);
4003
4310
  case "multiCollectionDocument":
4004
4311
  if (typeof value === "string") {
@@ -4006,7 +4313,7 @@ var resolve = async ({
4006
4313
  }
4007
4314
  if (args && args.collection && info.fieldName === "addPendingDocument") {
4008
4315
  return resolver.resolveDocument({
4009
- args: __spreadProps(__spreadValues({}, args), { params: {} }),
4316
+ args: { ...args, params: {} },
4010
4317
  collection: args.collection,
4011
4318
  isMutation,
4012
4319
  isCreation: true,
@@ -4046,13 +4353,16 @@ var resolve = async ({
4046
4353
  filter = args.filter[value.collection.name];
4047
4354
  }
4048
4355
  return resolver.resolveCollectionConnection({
4049
- args: __spreadProps(__spreadValues({}, args), {
4356
+ args: {
4357
+ ...args,
4050
4358
  filter
4051
- }),
4359
+ },
4052
4360
  collection: value.collection
4053
4361
  });
4054
4362
  } else {
4055
- 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
+ );
4056
4366
  }
4057
4367
  case "collectionDocument":
4058
4368
  if (value) {
@@ -4124,13 +4434,13 @@ var resolve = async ({
4124
4434
  };
4125
4435
 
4126
4436
  // src/database/index.ts
4127
- var import_path3 = __toModule(require("path"));
4128
- var import_graphql5 = __toModule(require("graphql"));
4437
+ var import_path3 = __toESM(require("path"));
4438
+ var import_graphql5 = require("graphql");
4129
4439
 
4130
4440
  // src/database/util.ts
4131
- var import_toml = __toModule(require("@iarna/toml"));
4132
- var import_js_yaml = __toModule(require("js-yaml"));
4133
- 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"));
4134
4444
  var matterEngines = {
4135
4445
  toml: {
4136
4446
  parse: (val) => import_toml.default.parse(val),
@@ -4138,36 +4448,34 @@ var matterEngines = {
4138
4448
  }
4139
4449
  };
4140
4450
  var stringifyFile = (content, format, keepTemplateKey, markdownParseConfig) => {
4141
- const _a = content, {
4451
+ const {
4142
4452
  _relativePath,
4143
4453
  _keepTemplateKey,
4144
4454
  _id,
4145
4455
  _template,
4146
4456
  _collection,
4147
- $_body
4148
- } = _a, rest = __objRest(_a, [
4149
- "_relativePath",
4150
- "_keepTemplateKey",
4151
- "_id",
4152
- "_template",
4153
- "_collection",
4154
- "$_body"
4155
- ]);
4457
+ $_body,
4458
+ ...rest
4459
+ } = content;
4156
4460
  const extra = {};
4157
4461
  if (keepTemplateKey) {
4158
4462
  extra["_template"] = _template;
4159
4463
  }
4160
- const strippedContent = __spreadValues(__spreadValues({}, rest), extra);
4464
+ const strippedContent = { ...rest, ...extra };
4161
4465
  switch (format) {
4162
4466
  case ".markdown":
4163
4467
  case ".mdx":
4164
4468
  case ".md":
4165
- const ok = import_gray_matter.default.stringify(typeof $_body === "undefined" ? "" : `
4166
- ${$_body}`, strippedContent, {
4167
- language: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterFormat) || "yaml",
4168
- engines: matterEngines,
4169
- delimiters: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) || "---"
4170
- });
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
+ );
4171
4479
  return ok;
4172
4480
  case ".json":
4173
4481
  return JSON.stringify(strippedContent, null, 2);
@@ -4190,9 +4498,10 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
4190
4498
  delimiters: (markdownParseConfig == null ? void 0 : markdownParseConfig.frontmatterDelimiters) || "---",
4191
4499
  engines: matterEngines
4192
4500
  });
4193
- const markdownData = __spreadProps(__spreadValues({}, contentJSON.data), {
4501
+ const markdownData = {
4502
+ ...contentJSON.data,
4194
4503
  $_body: contentJSON.content
4195
- });
4504
+ };
4196
4505
  assertShape(markdownData, yupSchema);
4197
4506
  return markdownData;
4198
4507
  case ".json":
@@ -4217,12 +4526,83 @@ var parseFile = (content, format, yupSchema, markdownParseConfig) => {
4217
4526
  };
4218
4527
  var normalizePath = (filepath) => filepath.replace(/\\/g, "/");
4219
4528
 
4529
+ // src/database/alias-utils.ts
4530
+ var replaceNameOverrides = (template, obj) => {
4531
+ if (template.list) {
4532
+ return obj.map((item) => {
4533
+ return _replaceNameOverrides(
4534
+ getTemplateForData(template, item).fields,
4535
+ item
4536
+ );
4537
+ });
4538
+ } else {
4539
+ return _replaceNameOverrides(getTemplateForData(template, obj).fields, obj);
4540
+ }
4541
+ };
4542
+ var _replaceNameOverrides = (fields, obj) => {
4543
+ const output = {};
4544
+ Object.keys(obj).forEach((key) => {
4545
+ const field = fields.find(
4546
+ (fieldWithMatchingAlias) => ((fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.nameOverride) || (fieldWithMatchingAlias == null ? void 0 : fieldWithMatchingAlias.name)) === key
4547
+ );
4548
+ output[(field == null ? void 0 : field.name) || key] = (field == null ? void 0 : field.type) == "object" ? replaceNameOverrides(field, obj[key]) : obj[key];
4549
+ });
4550
+ return output;
4551
+ };
4552
+ var getTemplateKey = (field) => {
4553
+ var _a, _b, _c;
4554
+ const DEFAULT_TEMPLATE_KEY = "_template";
4555
+ if ((_a = field.templates) == null ? void 0 : _a.length) {
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
+ );
4559
+ return (templateField == null ? void 0 : templateField.alias) || DEFAULT_TEMPLATE_KEY;
4560
+ }
4561
+ return DEFAULT_TEMPLATE_KEY;
4562
+ };
4563
+ var getTemplateForData = (field, data) => {
4564
+ var _a;
4565
+ if ((_a = field.templates) == null ? void 0 : _a.length) {
4566
+ const templateKey = getTemplateKey(field);
4567
+ if (data[templateKey]) {
4568
+ return field.templates.find(
4569
+ (template) => template.name === data[templateKey]
4570
+ );
4571
+ }
4572
+ } else {
4573
+ return field;
4574
+ }
4575
+ throw new Error("No template found for field " + field.name);
4576
+ };
4577
+ var applyNameOverrides = (template, obj) => {
4578
+ if (template.list) {
4579
+ return obj.map((item) => {
4580
+ return _applyNameOverrides(
4581
+ getTemplateForData(template, item).fields,
4582
+ item
4583
+ );
4584
+ });
4585
+ } else {
4586
+ return _applyNameOverrides(getTemplateForData(template, obj).fields, obj);
4587
+ }
4588
+ };
4589
+ var _applyNameOverrides = (fields, obj) => {
4590
+ const output = {};
4591
+ Object.keys(obj).forEach((key) => {
4592
+ const field = fields.find((field2) => field2.name === key);
4593
+ const outputKey = (field == null ? void 0 : field.nameOverride) || key;
4594
+ output[outputKey] = (field == null ? void 0 : field.type) === "object" ? applyNameOverrides(field, obj[key]) : obj[key];
4595
+ });
4596
+ return output;
4597
+ };
4598
+
4220
4599
  // src/database/index.ts
4221
4600
  var createDatabase = (config) => {
4222
- return new Database(__spreadProps(__spreadValues({}, config), {
4601
+ return new Database({
4602
+ ...config,
4223
4603
  bridge: config.bridge,
4224
4604
  level: config.level
4225
- }));
4605
+ });
4226
4606
  };
4227
4607
  var SYSTEM_FILES = ["_schema", "_graphql", "_lookup"];
4228
4608
  var defaultStatusCallback = () => Promise.resolve();
@@ -4243,7 +4623,10 @@ var Database = class {
4243
4623
  } else {
4244
4624
  const tinaSchema = await this.getSchema(this.level);
4245
4625
  const extension = import_path3.default.extname(filepath);
4246
- 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));
4247
4630
  if (!contentObject) {
4248
4631
  throw new import_graphql5.GraphQLError(`Unable to find record ${filepath}`);
4249
4632
  }
@@ -4260,24 +4643,30 @@ var Database = class {
4260
4643
  let data = contentObject;
4261
4644
  if ((extension === ".md" || extension === ".mdx") && field) {
4262
4645
  if (hasOwnProperty(contentObject, "$_body")) {
4263
- const _a = contentObject, { $_body } = _a, rest = __objRest(_a, ["$_body"]);
4646
+ const { $_body, ...rest } = contentObject;
4264
4647
  data = rest;
4265
4648
  data[field.name] = $_body;
4266
4649
  }
4267
4650
  }
4268
- return __spreadProps(__spreadValues({}, data), {
4651
+ return {
4652
+ ...data,
4269
4653
  _collection: collection.name,
4270
4654
  _keepTemplateKey: !!collection.templates,
4271
4655
  _template: lastItem(template.namespace),
4272
4656
  _relativePath: filepath.replace(collection.path, "").replace(/^\/|\/$/g, ""),
4273
4657
  _id: filepath
4274
- });
4658
+ };
4275
4659
  }
4276
4660
  };
4277
4661
  this.addPendingDocument = async (filepath, data) => {
4278
4662
  await this.initLevel();
4279
- const { stringifiedFile, payload } = await this.stringifyFile(filepath, data);
4663
+ const dataFields = await this.formatBodyOnPayload(filepath, data);
4280
4664
  const collection = await this.collectionForPath(filepath);
4665
+ const stringifiedFile = await this.stringifyFile(
4666
+ filepath,
4667
+ dataFields,
4668
+ collection
4669
+ );
4281
4670
  let collectionIndexDefinitions;
4282
4671
  if (collection) {
4283
4672
  const indexDefinitions = await this.getIndexDefinitions(this.level);
@@ -4288,49 +4677,95 @@ var Database = class {
4288
4677
  await this.bridge.put(normalizedPath, stringifiedFile);
4289
4678
  }
4290
4679
  await this.onPut(normalizedPath, stringifiedFile);
4291
- const putOps = makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, payload, "put", this.level);
4292
- const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4293
- 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
+ ) : [];
4294
4700
  const ops = [
4295
4701
  ...delOps,
4296
4702
  ...putOps,
4297
4703
  {
4298
4704
  type: "put",
4299
4705
  key: normalizedPath,
4300
- value: payload,
4301
- sublevel: this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
4706
+ value: dataFields,
4707
+ sublevel: this.level.sublevel(
4708
+ CONTENT_ROOT_PREFIX,
4709
+ SUBLEVEL_OPTIONS
4710
+ )
4302
4711
  }
4303
4712
  ];
4304
4713
  await this.level.batch(ops);
4305
4714
  };
4306
- this.put = async (filepath, data, collection) => {
4715
+ this.put = async (filepath, data, collectionName) => {
4307
4716
  await this.initLevel();
4308
4717
  try {
4309
4718
  if (SYSTEM_FILES.includes(filepath)) {
4310
4719
  throw new Error(`Unexpected put for config file ${filepath}`);
4311
4720
  } else {
4312
4721
  let collectionIndexDefinitions;
4313
- if (collection) {
4722
+ if (collectionName) {
4314
4723
  const indexDefinitions = await this.getIndexDefinitions(this.level);
4315
- collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection];
4724
+ collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
4316
4725
  }
4317
4726
  const normalizedPath = normalizePath(filepath);
4318
- const { stringifiedFile, payload } = await this.stringifyFile(filepath, data);
4727
+ const dataFields = await this.formatBodyOnPayload(filepath, data);
4728
+ const collection = await this.collectionForPath(filepath);
4729
+ const stringifiedFile = await this.stringifyFile(
4730
+ filepath,
4731
+ dataFields,
4732
+ collection
4733
+ );
4319
4734
  if (this.bridge) {
4320
4735
  await this.bridge.put(normalizedPath, stringifiedFile);
4321
4736
  }
4322
4737
  await this.onPut(normalizedPath, stringifiedFile);
4323
- const putOps = makeIndexOpsForDocument(normalizedPath, collection, collectionIndexDefinitions, payload, "put", this.level);
4324
- const existingItem = await this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS).get(normalizedPath);
4325
- const delOps = existingItem ? makeIndexOpsForDocument(normalizedPath, collection, 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
+ ) : [];
4326
4758
  const ops = [
4327
4759
  ...delOps,
4328
4760
  ...putOps,
4329
4761
  {
4330
4762
  type: "put",
4331
4763
  key: normalizedPath,
4332
- value: payload,
4333
- sublevel: this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
4764
+ value: dataFields,
4765
+ sublevel: this.level.sublevel(
4766
+ CONTENT_ROOT_PREFIX,
4767
+ SUBLEVEL_OPTIONS
4768
+ )
4334
4769
  }
4335
4770
  ];
4336
4771
  await this.level.batch(ops);
@@ -4340,94 +4775,109 @@ var Database = class {
4340
4775
  throw new TinaFetchError(`Error in PUT for ${filepath}`, {
4341
4776
  originalError: error,
4342
4777
  file: filepath,
4343
- collection,
4778
+ collection: collectionName,
4344
4779
  stack: error.stack
4345
4780
  });
4346
4781
  }
4347
4782
  };
4348
- this.stringifyFile = async (filepath, data) => {
4349
- if (SYSTEM_FILES.includes(filepath)) {
4350
- throw new Error(`Unexpected put for config file ${filepath}`);
4351
- } else {
4352
- const tinaSchema = await this.getSchema(this.level);
4353
- const collection = tinaSchema.getCollectionByFullPath(filepath);
4354
- const templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
4355
- let template;
4356
- if (templateInfo.type === "object") {
4357
- template = templateInfo.template;
4358
- }
4359
- if (templateInfo.type === "union") {
4360
- if (hasOwnProperty(data, "_template")) {
4361
- template = templateInfo.templates.find((t) => lastItem(t.namespace) === data._template);
4362
- } else {
4363
- throw new Error(`Expected _template to be provided for document in an ambiguous collection`);
4783
+ this.formatBodyOnPayload = async (filepath, data) => {
4784
+ const tinaSchema = await this.getSchema(this.level);
4785
+ const collection = tinaSchema.getCollectionByFullPath(filepath);
4786
+ const { template } = await this.getTemplateDetailsForFile(collection, data);
4787
+ const bodyField = template.fields.find((field) => {
4788
+ if (field.type === "string" || field.type === "rich-text") {
4789
+ if (field.isBody) {
4790
+ return true;
4364
4791
  }
4365
4792
  }
4366
- if (!template) {
4367
- throw new Error(`Unable to determine template`);
4368
- }
4369
- const field = template.fields.find((field2) => {
4370
- if (field2.type === "string" || field2.type === "rich-text") {
4371
- if (field2.isBody) {
4372
- return true;
4373
- }
4793
+ return false;
4794
+ });
4795
+ let payload = {};
4796
+ if (["md", "mdx"].includes(collection.format) && bodyField) {
4797
+ Object.entries(data).forEach(([key, value]) => {
4798
+ if (key !== bodyField.name) {
4799
+ payload[key] = value;
4374
4800
  }
4375
- return false;
4376
4801
  });
4377
- let payload = {};
4378
- if (["md", "mdx"].includes(collection.format) && field) {
4379
- Object.entries(data).forEach(([key, value]) => {
4380
- if (key !== field.name) {
4381
- payload[key] = value;
4382
- }
4383
- });
4384
- payload["$_body"] = data[field.name];
4385
- } else {
4386
- payload = data;
4387
- }
4388
- const extension = import_path3.default.extname(filepath);
4389
- const stringifiedFile = stringifyFile(payload, extension, templateInfo.type === "union", {
4802
+ payload["$_body"] = data[bodyField.name];
4803
+ } else {
4804
+ payload = data;
4805
+ }
4806
+ return payload;
4807
+ };
4808
+ this.stringifyFile = async (filepath, payload, collection) => {
4809
+ const templateDetails = await this.getTemplateDetailsForFile(
4810
+ collection,
4811
+ payload
4812
+ );
4813
+ const writeTemplateKey = templateDetails.info.type === "union";
4814
+ const aliasedData = applyNameOverrides(templateDetails.template, payload);
4815
+ const extension = import_path3.default.extname(filepath);
4816
+ const stringifiedFile = stringifyFile(
4817
+ aliasedData,
4818
+ extension,
4819
+ writeTemplateKey,
4820
+ {
4390
4821
  frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
4391
4822
  frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
4392
- });
4393
- return {
4394
- stringifiedFile,
4395
- payload,
4396
- keepTemplateKey: templateInfo.type === "union"
4397
- };
4398
- }
4823
+ }
4824
+ );
4825
+ return stringifiedFile;
4399
4826
  };
4400
4827
  this.flush = async (filepath) => {
4401
4828
  const data = await this.get(filepath);
4402
- const { stringifiedFile } = await this.stringifyFile(filepath, data);
4829
+ const dataFields = await this.formatBodyOnPayload(filepath, data);
4830
+ const collection = await this.collectionForPath(filepath);
4831
+ const stringifiedFile = await this.stringifyFile(
4832
+ filepath,
4833
+ dataFields,
4834
+ collection
4835
+ );
4403
4836
  return stringifiedFile;
4404
4837
  };
4405
4838
  this.getLookup = async (returnType) => {
4406
4839
  await this.initLevel();
4407
- 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
+ );
4408
4843
  if (!this._lookup) {
4409
- 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);
4410
4848
  this._lookup = _lookup;
4411
4849
  }
4412
4850
  return this._lookup[returnType];
4413
4851
  };
4414
4852
  this.getGraphQLSchema = async () => {
4415
4853
  await this.initLevel();
4416
- const graphqlPath = normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`));
4417
- 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);
4418
4861
  };
4419
4862
  this.getGraphQLSchemaFromBridge = async () => {
4420
4863
  if (!this.bridge) {
4421
4864
  throw new Error(`No bridge configured`);
4422
4865
  }
4423
- 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
+ );
4424
4869
  const _graphql = await this.bridge.get(graphqlPath);
4425
4870
  return JSON.parse(_graphql);
4426
4871
  };
4427
4872
  this.getTinaSchema = async (level) => {
4428
4873
  await this.initLevel();
4429
- const schemaPath = normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_schema.json`));
4430
- 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);
4431
4881
  };
4432
4882
  this.getSchema = async (level) => {
4433
4883
  if (this.tinaSchema) {
@@ -4472,7 +4922,9 @@ var Database = class {
4472
4922
  var _a;
4473
4923
  return {
4474
4924
  name: indexField.name,
4475
- 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
4476
4928
  };
4477
4929
  })
4478
4930
  };
@@ -4524,12 +4976,17 @@ var Database = class {
4524
4976
  const allIndexDefinitions = await this.getIndexDefinitions(this.level);
4525
4977
  const indexDefinitions = allIndexDefinitions == null ? void 0 : allIndexDefinitions[queryOptions.collection];
4526
4978
  if (!indexDefinitions) {
4527
- throw new Error(`No indexDefinitions for collection ${queryOptions.collection}`);
4979
+ throw new Error(
4980
+ `No indexDefinitions for collection ${queryOptions.collection}`
4981
+ );
4528
4982
  }
4529
4983
  const filterChain = coerceFilterChainOperands(rawFilterChain);
4530
4984
  const indexDefinition = sort && (indexDefinitions == null ? void 0 : indexDefinitions[sort]);
4531
4985
  const filterSuffixes = indexDefinition && makeFilterSuffixes(filterChain, indexDefinition);
4532
- const rootLevel = this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
4986
+ const rootLevel = this.level.sublevel(
4987
+ CONTENT_ROOT_PREFIX,
4988
+ SUBLEVEL_OPTIONS
4989
+ );
4533
4990
  const sublevel = indexDefinition ? this.level.sublevel(collection, SUBLEVEL_OPTIONS).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
4534
4991
  if (!query.gt && !query.gte) {
4535
4992
  query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
@@ -4552,7 +5009,9 @@ var Database = class {
4552
5009
  continue;
4553
5010
  }
4554
5011
  const filepath = matcher.groups["_filepath_"];
4555
- 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
+ )) {
4556
5015
  continue;
4557
5016
  }
4558
5017
  if (limit !== -1 && edges.length >= limit) {
@@ -4601,8 +5060,14 @@ var Database = class {
4601
5060
  tinaSchema
4602
5061
  }) => {
4603
5062
  if (this.bridge && this.bridge.supportsBuilding()) {
4604
- await this.bridge.putConfig(normalizePath(import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)), JSON.stringify(graphQLSchema));
4605
- 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
+ );
4606
5071
  }
4607
5072
  };
4608
5073
  this.indexContent = async ({
@@ -4615,21 +5080,37 @@ var Database = class {
4615
5080
  }
4616
5081
  await this.initLevel();
4617
5082
  await this.indexStatusCallbackWrapper(async () => {
4618
- 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
+ );
4619
5088
  let nextLevel;
4620
5089
  let nextVersion;
4621
5090
  if (!this.config.version) {
4622
5091
  await this.level.clear();
4623
5092
  nextLevel = this.level;
4624
5093
  } else {
4625
- const version2 = await this.getDatabaseVersion();
4626
- nextVersion = version2 ? `${parseInt(version2) + 1}` : "0";
5094
+ const version = await this.getDatabaseVersion();
5095
+ nextVersion = version ? `${parseInt(version) + 1}` : "0";
4627
5096
  nextLevel = this.rootLevel.sublevel(nextVersion, SUBLEVEL_OPTIONS);
4628
5097
  }
4629
- const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
4630
- await contentRootLevel.put(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_graphql.json")), graphQLSchema);
4631
- await contentRootLevel.put(normalizePath(import_path3.default.join(this.getGeneratedFolder(), "_schema.json")), tinaSchema.schema);
4632
- 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
+ );
4633
5114
  await this._indexAllContent(nextLevel);
4634
5115
  if (this.config.version) {
4635
5116
  await this.updateDatabaseVersion(nextVersion);
@@ -4652,7 +5133,12 @@ var Database = class {
4652
5133
  await this.indexStatusCallbackWrapper(async () => {
4653
5134
  const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
4654
5135
  for (const collection of Object.keys(pathsByCollection)) {
4655
- await _deleteIndexContent(this, pathsByCollection[collection], enqueueOps, collections[collection]);
5136
+ await _deleteIndexContent(
5137
+ this,
5138
+ pathsByCollection[collection],
5139
+ enqueueOps,
5140
+ collections[collection]
5141
+ );
4656
5142
  }
4657
5143
  await _deleteIndexContent(this, nonCollectionPaths, enqueueOps, null);
4658
5144
  });
@@ -4672,7 +5158,13 @@ var Database = class {
4672
5158
  await this.indexStatusCallbackWrapper(async () => {
4673
5159
  const { pathsByCollection, nonCollectionPaths, collections } = await this.partitionPathsByCollection(documentPaths);
4674
5160
  for (const collection of Object.keys(pathsByCollection)) {
4675
- 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
+ );
4676
5168
  }
4677
5169
  await _indexContent(this, this.level, nonCollectionPaths, enqueueOps);
4678
5170
  });
@@ -4688,13 +5180,26 @@ var Database = class {
4688
5180
  const indexDefinitions = await this.getIndexDefinitions(this.level);
4689
5181
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
4690
5182
  }
4691
- this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5183
+ this.level.sublevel(
5184
+ CONTENT_ROOT_PREFIX,
5185
+ SUBLEVEL_OPTIONS
5186
+ );
4692
5187
  const itemKey = normalizePath(filepath);
4693
- const rootSublevel = this.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5188
+ const rootSublevel = this.level.sublevel(
5189
+ CONTENT_ROOT_PREFIX,
5190
+ SUBLEVEL_OPTIONS
5191
+ );
4694
5192
  const item = await rootSublevel.get(itemKey);
4695
5193
  if (item) {
4696
5194
  await this.level.batch([
4697
- ...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
+ ),
4698
5203
  {
4699
5204
  type: "del",
4700
5205
  key: itemKey,
@@ -4718,7 +5223,10 @@ var Database = class {
4718
5223
  }
4719
5224
  };
4720
5225
  await sequential(tinaSchema.getCollections(), async (collection) => {
4721
- 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
+ );
4722
5230
  await _indexContent(this, level, documentPaths, enqueueOps, collection);
4723
5231
  });
4724
5232
  while (operations.length) {
@@ -4736,10 +5244,14 @@ var Database = class {
4736
5244
  } catch (e) {
4737
5245
  lookupMap = {};
4738
5246
  }
4739
- const updatedLookup = __spreadProps(__spreadValues({}, lookupMap), {
5247
+ const updatedLookup = {
5248
+ ...lookupMap,
4740
5249
  [lookup.type]: lookup
4741
- });
4742
- await this.bridge.putConfig(normalizePath(lookupPath), JSON.stringify(updatedLookup));
5250
+ };
5251
+ await this.bridge.putConfig(
5252
+ normalizePath(lookupPath),
5253
+ JSON.stringify(updatedLookup)
5254
+ );
4743
5255
  };
4744
5256
  this.tinaDirectory = config.tinaDirectory || ".tina";
4745
5257
  this.bridge = config.bridge;
@@ -4766,9 +5278,9 @@ var Database = class {
4766
5278
  }
4767
5279
  return { pathsByCollection, nonCollectionPaths, collections };
4768
5280
  }
4769
- async updateDatabaseVersion(version2) {
5281
+ async updateDatabaseVersion(version) {
4770
5282
  const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
4771
- await metadataLevel.put("metadata", { version: version2 });
5283
+ await metadataLevel.put("metadata", { version });
4772
5284
  }
4773
5285
  async getDatabaseVersion() {
4774
5286
  const metadataLevel = this.rootLevel.sublevel("_metadata", SUBLEVEL_OPTIONS);
@@ -4782,17 +5294,43 @@ var Database = class {
4782
5294
  if (!this.config.version) {
4783
5295
  this.level = this.rootLevel;
4784
5296
  } else {
4785
- let version2 = await this.getDatabaseVersion();
4786
- if (!version2) {
4787
- version2 = "";
4788
- await this.updateDatabaseVersion(version2);
5297
+ let version = await this.getDatabaseVersion();
5298
+ if (!version) {
5299
+ version = "";
5300
+ await this.updateDatabaseVersion(version);
4789
5301
  }
4790
- this.level = this.rootLevel.sublevel(version2, SUBLEVEL_OPTIONS);
5302
+ this.level = this.rootLevel.sublevel(version, SUBLEVEL_OPTIONS);
4791
5303
  }
4792
5304
  if (!this.level) {
4793
5305
  throw new import_graphql5.GraphQLError("Error initializing LevelDB instance");
4794
5306
  }
4795
5307
  }
5308
+ async getTemplateDetailsForFile(collection, data) {
5309
+ const tinaSchema = await this.getSchema();
5310
+ const templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
5311
+ let template;
5312
+ if (templateInfo.type === "object") {
5313
+ template = templateInfo.template;
5314
+ }
5315
+ if (templateInfo.type === "union") {
5316
+ if (hasOwnProperty(data, "_template")) {
5317
+ template = templateInfo.templates.find(
5318
+ (t) => lastItem(t.namespace) === data._template
5319
+ );
5320
+ } else {
5321
+ throw new Error(
5322
+ `Expected _template to be provided for document in an ambiguous collection`
5323
+ );
5324
+ }
5325
+ }
5326
+ if (!template) {
5327
+ throw new Error(`Unable to determine template`);
5328
+ }
5329
+ return {
5330
+ template,
5331
+ info: templateInfo
5332
+ };
5333
+ }
4796
5334
  clearCache() {
4797
5335
  this.tinaSchema = null;
4798
5336
  this._lookup = null;
@@ -4820,21 +5358,45 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
4820
5358
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
4821
5359
  }
4822
5360
  }
5361
+ const tinaSchema = await database.getSchema();
5362
+ let templateInfo = null;
5363
+ if (collection) {
5364
+ templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
5365
+ }
4823
5366
  await sequential(documentPaths, async (filepath) => {
4824
5367
  try {
4825
5368
  const dataString = await database.bridge.get(normalizePath(filepath));
4826
- const data = parseFile(dataString, import_path3.default.extname(filepath), (yup3) => yup3.object({}), {
4827
- frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
4828
- frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat
4829
- });
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
+ );
4830
5378
  const normalizedPath = normalizePath(filepath);
5379
+ const aliasedData = templateInfo ? replaceNameOverrides(
5380
+ getTemplateForFile(templateInfo, data),
5381
+ data
5382
+ ) : data;
4831
5383
  await enqueueOps([
4832
- ...makeIndexOpsForDocument(normalizedPath, collection == null ? void 0 : collection.name, collectionIndexDefinitions, data, "put", level),
5384
+ ...makeIndexOpsForDocument(
5385
+ normalizedPath,
5386
+ collection == null ? void 0 : collection.name,
5387
+ collectionIndexDefinitions,
5388
+ aliasedData,
5389
+ "put",
5390
+ level
5391
+ ),
4833
5392
  {
4834
5393
  type: "put",
4835
5394
  key: normalizedPath,
4836
- value: data,
4837
- sublevel: level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS)
5395
+ value: aliasedData,
5396
+ sublevel: level.sublevel(
5397
+ CONTENT_ROOT_PREFIX,
5398
+ SUBLEVEL_OPTIONS
5399
+ )
4838
5400
  }
4839
5401
  ]);
4840
5402
  } catch (error) {
@@ -4856,23 +5418,50 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
4856
5418
  throw new Error(`No indexDefinitions for collection ${collection.name}`);
4857
5419
  }
4858
5420
  }
4859
- const rootLevel = database.level.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
5421
+ const rootLevel = database.level.sublevel(
5422
+ CONTENT_ROOT_PREFIX,
5423
+ SUBLEVEL_OPTIONS
5424
+ );
4860
5425
  await sequential(documentPaths, async (filepath) => {
4861
5426
  const itemKey = normalizePath(filepath);
4862
5427
  const item = await rootLevel.get(itemKey);
4863
5428
  if (item) {
4864
5429
  await enequeueOps([
4865
- ...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
+ ),
4866
5438
  { type: "del", key: itemKey, sublevel: rootLevel }
4867
5439
  ]);
4868
5440
  }
4869
5441
  });
4870
5442
  };
5443
+ var getTemplateForFile = (templateInfo, data) => {
5444
+ if (templateInfo.type === "object") {
5445
+ return templateInfo.template;
5446
+ }
5447
+ if (templateInfo.type === "union") {
5448
+ if (hasOwnProperty(data, "_template")) {
5449
+ return templateInfo.templates.find(
5450
+ (t) => lastItem(t.namespace) === data._template
5451
+ );
5452
+ } else {
5453
+ throw new Error(
5454
+ `Expected _template to be provided for document in an ambiguous collection`
5455
+ );
5456
+ }
5457
+ }
5458
+ throw new Error(`Unable to determine template`);
5459
+ };
4871
5460
 
4872
5461
  // src/level/tinaLevel.ts
4873
- var import_many_level = __toModule(require("many-level"));
4874
- var import_readable_stream = __toModule(require("readable-stream"));
4875
- 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");
4876
5465
  var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
4877
5466
  constructor() {
4878
5467
  super(...arguments);
@@ -4890,10 +5479,10 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
4890
5479
  };
4891
5480
 
4892
5481
  // src/database/bridge/filesystem.ts
4893
- var import_fs_extra2 = __toModule(require("fs-extra"));
4894
- var import_fast_glob = __toModule(require("fast-glob"));
4895
- var import_path4 = __toModule(require("path"));
4896
- 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"));
4897
5486
  var FilesystemBridge = class {
4898
5487
  constructor(rootPath) {
4899
5488
  this.rootPath = rootPath || "";
@@ -4904,9 +5493,12 @@ var FilesystemBridge = class {
4904
5493
  }
4905
5494
  async glob(pattern, extension) {
4906
5495
  const basePath = import_path4.default.join(this.outputPath, ...pattern.split("/"));
4907
- const items = await (0, import_fast_glob.default)(import_path4.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"), {
4908
- dot: true
4909
- });
5496
+ const items = await (0, import_fast_glob.default)(
5497
+ import_path4.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"),
5498
+ {
5499
+ dot: true
5500
+ }
5501
+ );
4910
5502
  const posixRootPath = (0, import_normalize_path.default)(this.outputPath);
4911
5503
  return items.map((item) => {
4912
5504
  return item.replace(posixRootPath, "").replace(/^\/|\/$/g, "");
@@ -4948,12 +5540,12 @@ var AuditFileSystemBridge = class extends FilesystemBridge {
4948
5540
  };
4949
5541
 
4950
5542
  // src/database/bridge/isomorphic.ts
4951
- var import_isomorphic_git = __toModule(require("isomorphic-git"));
4952
- var import_fs_extra3 = __toModule(require("fs-extra"));
4953
- var import_glob_parent = __toModule(require("glob-parent"));
4954
- var import_normalize_path2 = __toModule(require("normalize-path"));
4955
- var import_graphql6 = __toModule(require("graphql"));
4956
- 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");
4957
5549
  var flat = typeof Array.prototype.flat === "undefined" ? (entries) => entries.reduce((acc, x) => acc.concat(x), []) : (entries) => entries.flat();
4958
5550
  var toUint8Array = (buf) => {
4959
5551
  const ab = new ArrayBuffer(buf.length);
@@ -4996,16 +5588,18 @@ var IsomorphicBridge = class {
4996
5588
  });
4997
5589
  }
4998
5590
  getAuthor() {
4999
- return __spreadProps(__spreadValues({}, this.author), {
5591
+ return {
5592
+ ...this.author,
5000
5593
  timestamp: Math.round(new Date().getTime() / 1e3),
5001
5594
  timezoneOffset: 0
5002
- });
5595
+ };
5003
5596
  }
5004
5597
  getCommitter() {
5005
- return __spreadProps(__spreadValues({}, this.committer), {
5598
+ return {
5599
+ ...this.committer,
5006
5600
  timestamp: Math.round(new Date().getTime() / 1e3),
5007
5601
  timezoneOffset: 0
5008
- });
5602
+ };
5009
5603
  }
5010
5604
  async listEntries({
5011
5605
  pattern,
@@ -5013,10 +5607,11 @@ var IsomorphicBridge = class {
5013
5607
  path: path6,
5014
5608
  results
5015
5609
  }) {
5016
- const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5610
+ const treeResult = await import_isomorphic_git.default.readTree({
5611
+ ...this.isomorphicConfig,
5017
5612
  oid: entry.oid,
5018
5613
  cache: this.cache
5019
- }));
5614
+ });
5020
5615
  const children = [];
5021
5616
  for (const childEntry of treeResult.tree) {
5022
5617
  const childPath = path6 ? `${path6}/${childEntry.path}` : childEntry.path;
@@ -5040,7 +5635,8 @@ var IsomorphicBridge = class {
5040
5635
  }
5041
5636
  async resolvePathEntries(path6, ref) {
5042
5637
  let pathParts = path6.split("/");
5043
- const result = await import_isomorphic_git.default.walk(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5638
+ const result = await import_isomorphic_git.default.walk({
5639
+ ...this.isomorphicConfig,
5044
5640
  map: async (filepath, [head]) => {
5045
5641
  if (head._fullpath === ".") {
5046
5642
  return head;
@@ -5057,7 +5653,7 @@ var IsomorphicBridge = class {
5057
5653
  },
5058
5654
  cache: this.cache,
5059
5655
  trees: [import_isomorphic_git.default.TREE({ ref })]
5060
- }));
5656
+ });
5061
5657
  const pathEntries = flat(result);
5062
5658
  if (pathParts.indexOf(".") === -1) {
5063
5659
  pathParts = [".", ...pathParts];
@@ -5076,10 +5672,11 @@ var IsomorphicBridge = class {
5076
5672
  const mode = type === "blob" ? "100644" : "040000";
5077
5673
  if (parentEntry) {
5078
5674
  parentOid = await parentEntry.oid();
5079
- const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5675
+ const treeResult = await import_isomorphic_git.default.readTree({
5676
+ ...this.isomorphicConfig,
5080
5677
  oid: parentOid,
5081
5678
  cache: this.cache
5082
- }));
5679
+ });
5083
5680
  tree = existingOid ? treeResult.tree.map((entry) => {
5084
5681
  if (entry.path === path6) {
5085
5682
  entry.oid = updatedOid;
@@ -5104,44 +5701,64 @@ var IsomorphicBridge = class {
5104
5701
  }
5105
5702
  ];
5106
5703
  }
5107
- const updatedParentOid = await import_isomorphic_git.default.writeTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5704
+ const updatedParentOid = await import_isomorphic_git.default.writeTree({
5705
+ ...this.isomorphicConfig,
5108
5706
  tree
5109
- }));
5707
+ });
5110
5708
  if (lastIdx === 0) {
5111
5709
  return updatedParentOid;
5112
5710
  } else {
5113
- 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
+ );
5114
5719
  }
5115
5720
  }
5116
5721
  async commitTree(treeSha, ref) {
5117
- const commitSha = await import_isomorphic_git.default.writeCommit(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5722
+ const commitSha = await import_isomorphic_git.default.writeCommit({
5723
+ ...this.isomorphicConfig,
5118
5724
  commit: {
5119
5725
  tree: treeSha,
5120
5726
  parent: [
5121
- await import_isomorphic_git.default.resolveRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5727
+ await import_isomorphic_git.default.resolveRef({
5728
+ ...this.isomorphicConfig,
5122
5729
  ref
5123
- }))
5730
+ })
5124
5731
  ],
5125
5732
  message: this.commitMessage,
5126
5733
  author: this.getAuthor(),
5127
5734
  committer: this.getCommitter()
5128
5735
  }
5129
- }));
5130
- await import_isomorphic_git.default.writeRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5736
+ });
5737
+ await import_isomorphic_git.default.writeRef({
5738
+ ...this.isomorphicConfig,
5131
5739
  ref,
5132
5740
  value: commitSha,
5133
5741
  force: true
5134
- }));
5742
+ });
5135
5743
  }
5136
5744
  async getRef() {
5137
5745
  if (this.ref) {
5138
5746
  return this.ref;
5139
5747
  }
5140
- const ref = await import_isomorphic_git.default.currentBranch(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5748
+ const ref = await import_isomorphic_git.default.currentBranch({
5749
+ ...this.isomorphicConfig,
5141
5750
  fullname: true
5142
- }));
5751
+ });
5143
5752
  if (!ref) {
5144
- 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
+ );
5145
5762
  }
5146
5763
  this.ref = ref;
5147
5764
  return ref;
@@ -5149,17 +5766,21 @@ var IsomorphicBridge = class {
5149
5766
  async glob(pattern, extension) {
5150
5767
  const ref = await this.getRef();
5151
5768
  const parent = (0, import_glob_parent.default)(this.qualifyPath(pattern));
5152
- const { pathParts, pathEntries } = await this.resolvePathEntries(parent, ref);
5769
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5770
+ parent,
5771
+ ref
5772
+ );
5153
5773
  const leafEntry = pathEntries[pathEntries.length - 1];
5154
5774
  const entryPath = pathParts[pathParts.length - 1];
5155
5775
  const parentEntry = pathEntries[pathEntries.length - 2];
5156
5776
  let treeEntry;
5157
5777
  let parentPath;
5158
5778
  if (parentEntry) {
5159
- const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5779
+ const treeResult = await import_isomorphic_git.default.readTree({
5780
+ ...this.isomorphicConfig,
5160
5781
  oid: await parentEntry.oid(),
5161
5782
  cache: this.cache
5162
- }));
5783
+ });
5163
5784
  treeEntry = treeResult.tree.find((entry) => entry.path === entryPath);
5164
5785
  parentPath = pathParts.slice(1, pathParts.length).join("/");
5165
5786
  } else {
@@ -5183,7 +5804,10 @@ var IsomorphicBridge = class {
5183
5804
  }
5184
5805
  async delete(filepath) {
5185
5806
  const ref = await this.getRef();
5186
- const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
5807
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5808
+ this.qualifyPath(filepath),
5809
+ ref
5810
+ );
5187
5811
  let oidToRemove;
5188
5812
  let ptr = pathEntries.length - 1;
5189
5813
  while (ptr >= 1) {
@@ -5193,33 +5817,53 @@ var IsomorphicBridge = class {
5193
5817
  oidToRemove = oidToRemove || await leafEntry.oid();
5194
5818
  const parentEntry = pathEntries[ptr - 1];
5195
5819
  const existingOid = await parentEntry.oid();
5196
- const treeResult = await import_isomorphic_git.default.readTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5820
+ const treeResult = await import_isomorphic_git.default.readTree({
5821
+ ...this.isomorphicConfig,
5197
5822
  oid: existingOid,
5198
5823
  cache: this.cache
5199
- }));
5200
- const updatedTree = treeResult.tree.filter((value) => value.path !== nodePath);
5824
+ });
5825
+ const updatedTree = treeResult.tree.filter(
5826
+ (value) => value.path !== nodePath
5827
+ );
5201
5828
  if (updatedTree.length === 0) {
5202
5829
  ptr -= 1;
5203
5830
  continue;
5204
5831
  }
5205
- const updatedTreeOid = await import_isomorphic_git.default.writeTree(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5832
+ const updatedTreeOid = await import_isomorphic_git.default.writeTree({
5833
+ ...this.isomorphicConfig,
5206
5834
  tree: updatedTree
5207
- }));
5208
- 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
+ );
5209
5844
  await this.commitTree(updatedRootTreeOid, ref);
5210
5845
  break;
5211
5846
  } else {
5212
- 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
+ );
5213
5856
  }
5214
5857
  }
5215
5858
  if (oidToRemove) {
5216
- await import_isomorphic_git.default.updateIndex(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5859
+ await import_isomorphic_git.default.updateIndex({
5860
+ ...this.isomorphicConfig,
5217
5861
  filepath: this.qualifyPath(filepath),
5218
5862
  force: true,
5219
5863
  remove: true,
5220
5864
  oid: oidToRemove,
5221
5865
  cache: this.cache
5222
- }));
5866
+ });
5223
5867
  }
5224
5868
  await this.onDelete(filepath);
5225
5869
  }
@@ -5231,14 +5875,16 @@ var IsomorphicBridge = class {
5231
5875
  }
5232
5876
  async get(filepath) {
5233
5877
  const ref = await this.getRef();
5234
- const oid = await import_isomorphic_git.default.resolveRef(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5878
+ const oid = await import_isomorphic_git.default.resolveRef({
5879
+ ...this.isomorphicConfig,
5235
5880
  ref
5236
- }));
5237
- 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,
5238
5884
  oid,
5239
5885
  filepath: this.qualifyPath(filepath),
5240
5886
  cache: this.cache
5241
- }));
5887
+ });
5242
5888
  return Buffer.from(blob).toString("utf8");
5243
5889
  }
5244
5890
  async putConfig(filepath, data) {
@@ -5246,7 +5892,10 @@ var IsomorphicBridge = class {
5246
5892
  }
5247
5893
  async put(filepath, data) {
5248
5894
  const ref = await this.getRef();
5249
- const { pathParts, pathEntries } = await this.resolvePathEntries(this.qualifyPath(filepath), ref);
5895
+ const { pathParts, pathEntries } = await this.resolvePathEntries(
5896
+ this.qualifyPath(filepath),
5897
+ ref
5898
+ );
5250
5899
  const blobUpdate = toUint8Array(Buffer.from(data));
5251
5900
  let existingOid;
5252
5901
  const leafEntry = pathEntries[pathEntries.length - 1];
@@ -5259,17 +5908,26 @@ var IsomorphicBridge = class {
5259
5908
  return;
5260
5909
  }
5261
5910
  }
5262
- const updatedOid = await import_isomorphic_git.default.writeBlob(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5911
+ const updatedOid = await import_isomorphic_git.default.writeBlob({
5912
+ ...this.isomorphicConfig,
5263
5913
  blob: blobUpdate
5264
- }));
5265
- 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
+ );
5266
5923
  await this.commitTree(updatedRootSha, ref);
5267
- await import_isomorphic_git.default.updateIndex(__spreadProps(__spreadValues({}, this.isomorphicConfig), {
5924
+ await import_isomorphic_git.default.updateIndex({
5925
+ ...this.isomorphicConfig,
5268
5926
  filepath: this.qualifyPath(filepath),
5269
5927
  add: true,
5270
5928
  oid: updatedOid,
5271
5929
  cache: this.cache
5272
- }));
5930
+ });
5273
5931
  await this.onPut(filepath, data);
5274
5932
  }
5275
5933
  };