@tinacms/graphql 0.0.0-d524599-20241117111320 → 0.0.0-d7c745e-20250102002342

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +410 -29
  2. package/dist/index.mjs +407 -30
  3. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  return to;
18
18
  };
19
19
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
24
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
25
  mod
22
26
  ));
@@ -130,6 +134,15 @@ var SysFieldDefinition = {
130
134
  selectionSet: {
131
135
  kind: "SelectionSet",
132
136
  selections: [
137
+ // {
138
+ // kind: 'Field' as const,
139
+ // name: {
140
+ // kind: 'Name' as const,
141
+ // value: 'title',
142
+ // },
143
+ // arguments: [],
144
+ // directives: [],
145
+ // },
133
146
  {
134
147
  kind: "Field",
135
148
  name: {
@@ -197,6 +210,10 @@ var SysFieldDefinition = {
197
210
  }
198
211
  };
199
212
  var astBuilder = {
213
+ /**
214
+ * `FormFieldBuilder` acts as a shortcut to building an entire `ObjectTypeDefinition`, we use this
215
+ * because all Tina field objects share a common set of fields ('name', 'label', 'component')
216
+ */
200
217
  FormFieldBuilder: ({
201
218
  name,
202
219
  additionalFields
@@ -420,6 +437,8 @@ var astBuilder = {
420
437
  kind: "Name",
421
438
  value: name
422
439
  },
440
+ // @ts-ignore FIXME; this is being handled properly but we're lying to
441
+ // ts and then fixing it in the `extractInlineTypes` function
423
442
  fields
424
443
  }),
425
444
  UnionTypeDefinition: ({
@@ -432,6 +451,8 @@ var astBuilder = {
432
451
  value: name
433
452
  },
434
453
  directives: [],
454
+ // @ts-ignore FIXME; this is being handled properly but we're lying to
455
+ // ts and then fixing it in the `extractInlineTypes` function
435
456
  types: types.map((name2) => ({
436
457
  kind: "NamedType",
437
458
  name: {
@@ -528,8 +549,11 @@ var astBuilder = {
528
549
  string: "String",
529
550
  boolean: "Boolean",
530
551
  number: "Float",
552
+ // FIXME - needs to be float or int
531
553
  datetime: "String",
554
+ // FIXME
532
555
  image: "String",
556
+ // FIXME
533
557
  text: "String"
534
558
  };
535
559
  return scalars[type];
@@ -1028,8 +1052,7 @@ var astBuilder = {
1028
1052
  }
1029
1053
  };
1030
1054
  var capitalize = (s) => {
1031
- if (typeof s !== "string")
1032
- return "";
1055
+ if (typeof s !== "string") return "";
1033
1056
  return s.charAt(0).toUpperCase() + s.slice(1);
1034
1057
  };
1035
1058
  var extractInlineTypes = (item) => {
@@ -1485,6 +1508,19 @@ var Builder = class {
1485
1508
  this.addToLookupMap = (lookup) => {
1486
1509
  this.lookupMap[lookup.type] = lookup;
1487
1510
  };
1511
+ /**
1512
+ * ```graphql
1513
+ * # ex.
1514
+ * {
1515
+ * getCollection(collection: $collection) {
1516
+ * name
1517
+ * documents {...}
1518
+ * }
1519
+ * }
1520
+ * ```
1521
+ *
1522
+ * @param collections
1523
+ */
1488
1524
  this.buildCollectionDefinition = async (collections) => {
1489
1525
  const name = "collection";
1490
1526
  const typeName = "Collection";
@@ -1555,6 +1591,19 @@ var Builder = class {
1555
1591
  required: true
1556
1592
  });
1557
1593
  };
1594
+ /**
1595
+ * ```graphql
1596
+ * # ex.
1597
+ * {
1598
+ * getCollections {
1599
+ * name
1600
+ * documents {...}
1601
+ * }
1602
+ * }
1603
+ * ```
1604
+ *
1605
+ * @param collections
1606
+ */
1558
1607
  this.buildMultiCollectionDefinition = async (collections) => {
1559
1608
  const name = "collections";
1560
1609
  const typeName = "Collection";
@@ -1565,6 +1614,17 @@ var Builder = class {
1565
1614
  required: true
1566
1615
  });
1567
1616
  };
1617
+ /**
1618
+ * ```graphql
1619
+ * # ex.
1620
+ * {
1621
+ * node(id: $id) {
1622
+ * id
1623
+ * data {...}
1624
+ * }
1625
+ * }
1626
+ * ```
1627
+ */
1568
1628
  this.multiNodeDocument = async () => {
1569
1629
  const name = "node";
1570
1630
  const args = [
@@ -1585,6 +1645,19 @@ var Builder = class {
1585
1645
  required: true
1586
1646
  });
1587
1647
  };
1648
+ /**
1649
+ * ```graphql
1650
+ * # ex.
1651
+ * {
1652
+ * getDocument(collection: $collection, relativePath: $relativePath) {
1653
+ * id
1654
+ * data {...}
1655
+ * }
1656
+ * }
1657
+ * ```
1658
+ *
1659
+ * @param collections
1660
+ */
1588
1661
  this.multiCollectionDocument = async (collections) => {
1589
1662
  const name = "document";
1590
1663
  const args = [
@@ -1610,6 +1683,19 @@ var Builder = class {
1610
1683
  required: true
1611
1684
  });
1612
1685
  };
1686
+ /**
1687
+ * ```graphql
1688
+ * # ex.
1689
+ * {
1690
+ * addPendingDocument(collection: $collection, relativePath: $relativePath, params: $params) {
1691
+ * id
1692
+ * data {...}
1693
+ * }
1694
+ * }
1695
+ * ```
1696
+ *
1697
+ * @param collections
1698
+ */
1613
1699
  this.addMultiCollectionDocumentMutation = async () => {
1614
1700
  return astBuilder.FieldDefinition({
1615
1701
  name: "addPendingDocument",
@@ -1634,6 +1720,19 @@ var Builder = class {
1634
1720
  type: astBuilder.TYPES.MultiCollectionDocument
1635
1721
  });
1636
1722
  };
1723
+ /**
1724
+ * ```graphql
1725
+ * # ex.
1726
+ * {
1727
+ * createDocument(relativePath: $relativePath, params: $params) {
1728
+ * id
1729
+ * data {...}
1730
+ * }
1731
+ * }
1732
+ * ```
1733
+ *
1734
+ * @param collections
1735
+ */
1637
1736
  this.buildCreateCollectionDocumentMutation = async (collections) => {
1638
1737
  return astBuilder.FieldDefinition({
1639
1738
  name: "createDocument",
@@ -1661,6 +1760,19 @@ var Builder = class {
1661
1760
  type: astBuilder.TYPES.MultiCollectionDocument
1662
1761
  });
1663
1762
  };
1763
+ /**
1764
+ * ```graphql
1765
+ * # ex.
1766
+ * {
1767
+ * updateDocument(relativePath: $relativePath, params: $params) {
1768
+ * id
1769
+ * data {...}
1770
+ * }
1771
+ * }
1772
+ * ```
1773
+ *
1774
+ * @param collections
1775
+ */
1664
1776
  this.buildUpdateCollectionDocumentMutation = async (collections) => {
1665
1777
  return astBuilder.FieldDefinition({
1666
1778
  name: "updateDocument",
@@ -1688,6 +1800,19 @@ var Builder = class {
1688
1800
  type: astBuilder.TYPES.MultiCollectionDocument
1689
1801
  });
1690
1802
  };
1803
+ /**
1804
+ * ```graphql
1805
+ * # ex.
1806
+ * {
1807
+ * deleteDocument(relativePath: $relativePath, params: $params) {
1808
+ * id
1809
+ * data {...}
1810
+ * }
1811
+ * }
1812
+ * ```
1813
+ *
1814
+ * @param collections
1815
+ */
1691
1816
  this.buildDeleteCollectionDocumentMutation = async (collections) => {
1692
1817
  return astBuilder.FieldDefinition({
1693
1818
  name: "deleteDocument",
@@ -1707,6 +1832,19 @@ var Builder = class {
1707
1832
  type: astBuilder.TYPES.MultiCollectionDocument
1708
1833
  });
1709
1834
  };
1835
+ /**
1836
+ * ```graphql
1837
+ * # ex.
1838
+ * {
1839
+ * createFolder(folderName: $folderName, params: $params) {
1840
+ * id
1841
+ * data {...}
1842
+ * }
1843
+ * }
1844
+ * ```
1845
+ *
1846
+ * @param collections
1847
+ */
1710
1848
  this.buildCreateCollectionFolderMutation = async () => {
1711
1849
  return astBuilder.FieldDefinition({
1712
1850
  name: "createFolder",
@@ -1726,6 +1864,19 @@ var Builder = class {
1726
1864
  type: astBuilder.TYPES.MultiCollectionDocument
1727
1865
  });
1728
1866
  };
1867
+ /**
1868
+ * ```graphql
1869
+ * # ex.
1870
+ * {
1871
+ * getPostDocument(relativePath: $relativePath) {
1872
+ * id
1873
+ * data {...}
1874
+ * }
1875
+ * }
1876
+ * ```
1877
+ *
1878
+ * @param collection
1879
+ */
1729
1880
  this.collectionDocument = async (collection) => {
1730
1881
  const name = NAMER.queryName([collection.name]);
1731
1882
  const type = await this._buildCollectionDocumentType(collection);
@@ -1786,6 +1937,20 @@ var Builder = class {
1786
1937
  const args = [];
1787
1938
  return astBuilder.FieldDefinition({ type, name, args, required: false });
1788
1939
  };
1940
+ /**
1941
+ * Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
1942
+ * ```graphql
1943
+ * # ex.
1944
+ * fragment AuthorsParts on Authors {
1945
+ * name
1946
+ * avatar
1947
+ * ...
1948
+ * }
1949
+ * ```
1950
+ *
1951
+ * @public
1952
+ * @param collection a Tina Cloud collection
1953
+ */
1789
1954
  this.collectionFragment = async (collection) => {
1790
1955
  const name = NAMER.dataTypeName(collection.namespace);
1791
1956
  const fragmentName = NAMER.fragmentName(collection.namespace);
@@ -1799,6 +1964,20 @@ var Builder = class {
1799
1964
  selections: filterSelections(selections)
1800
1965
  });
1801
1966
  };
1967
+ /**
1968
+ * Given a collection this function returns its selections set. For example for Post this would return
1969
+ *
1970
+ * "
1971
+ * body
1972
+ * title
1973
+ * ... on Author {
1974
+ * name
1975
+ * heroImg
1976
+ * }
1977
+ *
1978
+ * But in the AST format
1979
+ *
1980
+ * */
1802
1981
  this._getCollectionFragmentSelections = async (collection, depth) => {
1803
1982
  var _a;
1804
1983
  const selections = [];
@@ -1882,9 +2061,9 @@ var Builder = class {
1882
2061
  ]
1883
2062
  });
1884
2063
  }
2064
+ // TODO: Should we throw here?
1885
2065
  case "reference":
1886
- if (depth >= this.maxDepth)
1887
- return false;
2066
+ if (depth >= this.maxDepth) return false;
1888
2067
  if (!("collections" in field)) {
1889
2068
  return false;
1890
2069
  }
@@ -1916,6 +2095,7 @@ var Builder = class {
1916
2095
  name: field.name,
1917
2096
  selections: [
1918
2097
  ...selections,
2098
+ // This is ... on Document { id }
1919
2099
  {
1920
2100
  kind: "InlineFragment",
1921
2101
  typeCondition: {
@@ -1946,6 +2126,19 @@ var Builder = class {
1946
2126
  });
1947
2127
  }
1948
2128
  };
2129
+ /**
2130
+ * ```graphql
2131
+ * # ex.
2132
+ * mutation {
2133
+ * updatePostDocument(relativePath: $relativePath, params: $params) {
2134
+ * id
2135
+ * data {...}
2136
+ * }
2137
+ * }
2138
+ * ```
2139
+ *
2140
+ * @param collection
2141
+ */
1949
2142
  this.updateCollectionDocumentMutation = async (collection) => {
1950
2143
  return astBuilder.FieldDefinition({
1951
2144
  type: await this._buildCollectionDocumentType(collection),
@@ -1965,6 +2158,19 @@ var Builder = class {
1965
2158
  ]
1966
2159
  });
1967
2160
  };
2161
+ /**
2162
+ * ```graphql
2163
+ * # ex.
2164
+ * mutation {
2165
+ * createPostDocument(relativePath: $relativePath, params: $params) {
2166
+ * id
2167
+ * data {...}
2168
+ * }
2169
+ * }
2170
+ * ```
2171
+ *
2172
+ * @param collection
2173
+ */
1968
2174
  this.createCollectionDocumentMutation = async (collection) => {
1969
2175
  return astBuilder.FieldDefinition({
1970
2176
  type: await this._buildCollectionDocumentType(collection),
@@ -1984,6 +2190,22 @@ var Builder = class {
1984
2190
  ]
1985
2191
  });
1986
2192
  };
2193
+ /**
2194
+ * ```graphql
2195
+ * # ex.
2196
+ * {
2197
+ * getPostList(first: 10) {
2198
+ * edges {
2199
+ * node {
2200
+ * id
2201
+ * }
2202
+ * }
2203
+ * }
2204
+ * }
2205
+ * ```
2206
+ *
2207
+ * @param collection
2208
+ */
1987
2209
  this.collectionDocumentList = async (collection) => {
1988
2210
  const connectionName = NAMER.referenceConnectionType(collection.namespace);
1989
2211
  this.addToLookupMap({
@@ -1999,6 +2221,10 @@ var Builder = class {
1999
2221
  collection
2000
2222
  });
2001
2223
  };
2224
+ /**
2225
+ * GraphQL type definitions which remain unchanged regardless
2226
+ * of the supplied Tina schema. Ex. "node" interface
2227
+ */
2002
2228
  this.buildStaticDefinitions = () => staticDefinitions;
2003
2229
  this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
2004
2230
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
@@ -2503,6 +2729,7 @@ var Builder = class {
2503
2729
  name: NAMER.dataFilterTypeName(namespace),
2504
2730
  fields: await sequential(collections, async (collection2) => {
2505
2731
  return astBuilder.InputValueDefinition({
2732
+ // @ts-ignore
2506
2733
  name: collection2.name,
2507
2734
  type: NAMER.dataFilterTypeName(collection2.namespace)
2508
2735
  });
@@ -2692,7 +2919,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2692
2919
  });
2693
2920
  };
2694
2921
  var _a, _b, _c, _d;
2695
- this.maxDepth = (_d = (_c = (_b = (_a = config == null ? void 0 : config.tinaSchema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.client) == null ? void 0 : _c.referenceDepth) != null ? _d : 2;
2922
+ this.maxDepth = // @ts-ignore
2923
+ (_d = (_c = (_b = (_a = config == null ? void 0 : config.tinaSchema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.client) == null ? void 0 : _c.referenceDepth) != null ? _d : 2;
2696
2924
  this.tinaSchema = config.tinaSchema;
2697
2925
  this.lookupMap = {};
2698
2926
  }
@@ -2703,8 +2931,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2703
2931
  selections.push(field);
2704
2932
  });
2705
2933
  const filteredSelections = filterSelections(selections);
2706
- if (!filteredSelections.length)
2707
- return false;
2934
+ if (!filteredSelections.length) return false;
2708
2935
  return astBuilder.InlineFragmentDefinition({
2709
2936
  selections: filteredSelections,
2710
2937
  name: NAMER.dataTypeName(template.namespace)
@@ -2785,6 +3012,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2785
3012
  }).map((x) => `${x.path}${x.format || "md"}`);
2786
3013
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2787
3014
  throw new Error(
3015
+ // TODO: add a link to the docs
2788
3016
  "Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
2789
3017
  );
2790
3018
  }
@@ -2896,7 +3124,7 @@ var validateField = async (field) => {
2896
3124
  // package.json
2897
3125
  var package_default = {
2898
3126
  name: "@tinacms/graphql",
2899
- version: "1.5.7",
3127
+ version: "1.5.9",
2900
3128
  main: "dist/index.js",
2901
3129
  module: "dist/index.mjs",
2902
3130
  typings: "dist/index.d.ts",
@@ -3053,6 +3281,7 @@ var _buildFragments = async (builder, tinaSchema) => {
3053
3281
  const fragDoc = {
3054
3282
  kind: "Document",
3055
3283
  definitions: (0, import_lodash3.default)(
3284
+ // @ts-ignore
3056
3285
  extractInlineTypes(fragmentDefinitionsFields),
3057
3286
  (node) => node.name.value
3058
3287
  )
@@ -3076,6 +3305,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3076
3305
  fragName,
3077
3306
  queryName: queryListName,
3078
3307
  filterType: queryFilterTypeName,
3308
+ // look for flag to see if the data layer is enabled
3079
3309
  dataLayer: Boolean(
3080
3310
  (_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
3081
3311
  )
@@ -3085,6 +3315,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3085
3315
  const queryDoc = {
3086
3316
  kind: "Document",
3087
3317
  definitions: (0, import_lodash3.default)(
3318
+ // @ts-ignore
3088
3319
  extractInlineTypes(operationsDefinitions),
3089
3320
  (node) => node.name.value
3090
3321
  )
@@ -3173,6 +3404,7 @@ var _buildSchema = async (builder, tinaSchema) => {
3173
3404
  return {
3174
3405
  kind: "Document",
3175
3406
  definitions: (0, import_lodash3.default)(
3407
+ // @ts-ignore
3176
3408
  extractInlineTypes(definitions),
3177
3409
  (node) => node.name.value
3178
3410
  )
@@ -3377,8 +3609,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
3377
3609
  }
3378
3610
  if (Array.isArray(value)) {
3379
3611
  return value.map((v) => {
3380
- if (!v || typeof v !== "string")
3381
- return v;
3612
+ if (!v || typeof v !== "string") return v;
3382
3613
  const cleanMediaRoot = cleanUpSlashes(
3383
3614
  schema.config.media.tina.mediaRoot
3384
3615
  );
@@ -3406,8 +3637,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3406
3637
  }
3407
3638
  if (Array.isArray(value)) {
3408
3639
  return value.map((v) => {
3409
- if (!v || typeof v !== "string")
3410
- return v;
3640
+ if (!v || typeof v !== "string") return v;
3411
3641
  const strippedValue = v.replace(cleanMediaRoot, "");
3412
3642
  return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3413
3643
  });
@@ -3426,8 +3656,7 @@ var cleanUpSlashes = (path7) => {
3426
3656
  };
3427
3657
  var hasTinaMediaConfig = (schema) => {
3428
3658
  var _a, _b, _c, _d, _e, _f, _g, _h;
3429
- if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina))
3430
- return false;
3659
+ if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3431
3660
  if (typeof ((_e = (_d = (_c = schema.config) == null ? void 0 : _c.media) == null ? void 0 : _d.tina) == null ? void 0 : _e.publicFolder) !== "string" && typeof ((_h = (_g = (_f = schema.config) == null ? void 0 : _f.media) == null ? void 0 : _g.tina) == null ? void 0 : _h.mediaRoot) !== "string")
3432
3661
  return false;
3433
3662
  return true;
@@ -3471,6 +3700,7 @@ var LevelProxyHandler = {
3471
3700
  } else if (property === "sublevel") {
3472
3701
  return (...args) => {
3473
3702
  return new Proxy(
3703
+ // eslint-disable-next-line prefer-spread
3474
3704
  target[property].apply(target, args),
3475
3705
  LevelProxyHandler
3476
3706
  );
@@ -4349,6 +4579,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
4349
4579
  result.push({
4350
4580
  type: opType,
4351
4581
  key: `${collection.path}/${subFolderKey}.${collection.format}`,
4582
+ // replace the root with the collection path
4352
4583
  sublevel: indexSublevel,
4353
4584
  value: {}
4354
4585
  });
@@ -4464,6 +4695,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4464
4695
  case "password":
4465
4696
  accumulator[field.name] = {
4466
4697
  value: void 0,
4698
+ // never resolve the password hash
4467
4699
  passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4468
4700
  };
4469
4701
  break;
@@ -4658,6 +4890,7 @@ var Resolver = class {
4658
4890
  const collection = this.tinaSchema.getCollection(collectionName);
4659
4891
  const extraFields = {};
4660
4892
  return {
4893
+ // return the collection and hasDocuments to resolve documents at a lower level
4661
4894
  documents: { collection, hasDocuments },
4662
4895
  ...collection,
4663
4896
  ...extraFields
@@ -4744,7 +4977,9 @@ var Resolver = class {
4744
4977
  );
4745
4978
  } else {
4746
4979
  return this.buildFieldMutations(
4980
+ // @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
4747
4981
  fieldValue,
4982
+ //@ts-ignore
4748
4983
  objectTemplate,
4749
4984
  existingData
4750
4985
  );
@@ -4756,6 +4991,7 @@ var Resolver = class {
4756
4991
  fieldValue.map(async (item) => {
4757
4992
  if (typeof item === "string") {
4758
4993
  throw new Error(
4994
+ //@ts-ignore
4759
4995
  `Expected object for template value for field ${field.name}`
4760
4996
  );
4761
4997
  }
@@ -4764,16 +5000,19 @@ var Resolver = class {
4764
5000
  });
4765
5001
  const [templateName] = Object.entries(item)[0];
4766
5002
  const template = templates.find(
5003
+ //@ts-ignore
4767
5004
  (template2) => template2.name === templateName
4768
5005
  );
4769
5006
  if (!template) {
4770
5007
  throw new Error(`Expected to find template ${templateName}`);
4771
5008
  }
4772
5009
  return {
5010
+ // @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
4773
5011
  ...await this.buildFieldMutations(
4774
5012
  item[template.name],
4775
5013
  template
4776
5014
  ),
5015
+ //@ts-ignore
4777
5016
  _template: template.name
4778
5017
  };
4779
5018
  })
@@ -4781,6 +5020,7 @@ var Resolver = class {
4781
5020
  } else {
4782
5021
  if (typeof fieldValue === "string") {
4783
5022
  throw new Error(
5023
+ //@ts-ignore
4784
5024
  `Expected object for template value for field ${field.name}`
4785
5025
  );
4786
5026
  }
@@ -4789,16 +5029,19 @@ var Resolver = class {
4789
5029
  });
4790
5030
  const [templateName] = Object.entries(fieldValue)[0];
4791
5031
  const template = templates.find(
5032
+ //@ts-ignore
4792
5033
  (template2) => template2.name === templateName
4793
5034
  );
4794
5035
  if (!template) {
4795
5036
  throw new Error(`Expected to find template ${templateName}`);
4796
5037
  }
4797
5038
  return {
5039
+ // @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
4798
5040
  ...await this.buildFieldMutations(
4799
5041
  fieldValue[template.name],
4800
5042
  template
4801
5043
  ),
5044
+ //@ts-ignore
4802
5045
  _template: template.name
4803
5046
  };
4804
5047
  }
@@ -4838,6 +5081,7 @@ var Resolver = class {
4838
5081
  return this.getDocument(realPath);
4839
5082
  }
4840
5083
  const params = await this.buildObjectMutations(
5084
+ // @ts-ignore
4841
5085
  args.params[collection.name],
4842
5086
  collection
4843
5087
  );
@@ -4883,6 +5127,7 @@ var Resolver = class {
4883
5127
  const values = {
4884
5128
  ...oldDoc,
4885
5129
  ...await this.buildFieldMutations(
5130
+ // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
4886
5131
  templateParams,
4887
5132
  template,
4888
5133
  doc == null ? void 0 : doc._rawData
@@ -4896,6 +5141,7 @@ var Resolver = class {
4896
5141
  return this.getDocument(realPath);
4897
5142
  }
4898
5143
  const params = await this.buildObjectMutations(
5144
+ //@ts-ignore
4899
5145
  isCollectionSpecific ? args.params : args.params[collection.name],
4900
5146
  collection,
4901
5147
  doc == null ? void 0 : doc._rawData
@@ -4903,6 +5149,10 @@ var Resolver = class {
4903
5149
  await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
4904
5150
  return this.getDocument(realPath);
4905
5151
  };
5152
+ /**
5153
+ * Returns top-level fields which are not defined in the collection, so their
5154
+ * values are not eliminated from Tina when new values are saved
5155
+ */
4906
5156
  this.resolveLegacyValues = (oldDoc, collection) => {
4907
5157
  const legacyValues = {};
4908
5158
  Object.entries(oldDoc).forEach(([key, value]) => {
@@ -5109,6 +5359,7 @@ var Resolver = class {
5109
5359
  },
5110
5360
  collection: referencedCollection,
5111
5361
  hydrator: (path7) => path7
5362
+ // just return the path
5112
5363
  }
5113
5364
  );
5114
5365
  const { edges } = resolvedCollectionConnection;
@@ -5176,6 +5427,12 @@ var Resolver = class {
5176
5427
  }
5177
5428
  };
5178
5429
  };
5430
+ /**
5431
+ * Checks if a document has references to it
5432
+ * @param id The id of the document to check for references
5433
+ * @param c The collection to check for references
5434
+ * @returns true if the document has references, false otherwise
5435
+ */
5179
5436
  this.hasReferences = async (id, c) => {
5180
5437
  let count = 0;
5181
5438
  const deepRefs = this.tinaSchema.findReferences(c.name);
@@ -5210,6 +5467,12 @@ var Resolver = class {
5210
5467
  }
5211
5468
  return false;
5212
5469
  };
5470
+ /**
5471
+ * Finds references to a document
5472
+ * @param id the id of the document to find references to
5473
+ * @param c the collection to find references in
5474
+ * @returns references to the document in the form of a map of collection names to a list of fields that reference the document
5475
+ */
5213
5476
  this.findReferences = async (id, c) => {
5214
5477
  const references = {};
5215
5478
  const deepRefs = this.tinaSchema.findReferences(c.name);
@@ -5337,6 +5600,27 @@ var Resolver = class {
5337
5600
  }
5338
5601
  return accum;
5339
5602
  };
5603
+ /**
5604
+ * A mutation looks nearly identical between updateDocument:
5605
+ * ```graphql
5606
+ * updateDocument(collection: $collection,relativePath: $path, params: {
5607
+ * post: {
5608
+ * title: "Hello, World"
5609
+ * }
5610
+ * })`
5611
+ * ```
5612
+ * and `updatePostDocument`:
5613
+ * ```graphql
5614
+ * updatePostDocument(relativePath: $path, params: {
5615
+ * title: "Hello, World"
5616
+ * })
5617
+ * ```
5618
+ * The problem here is that we don't know whether the payload came from `updateDocument`
5619
+ * or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
5620
+ * But we do know that when given a `args.collection` value, we can assume that
5621
+ * this was a `updateDocument` request, and thus - should grab the data
5622
+ * from the corresponding field name in the key
5623
+ */
5340
5624
  this.buildParams = (args) => {
5341
5625
  try {
5342
5626
  assertShape(
@@ -5437,7 +5721,10 @@ var resolve = async ({
5437
5721
  const graphQLSchema = (0, import_graphql5.buildASTSchema)(graphQLSchemaAst);
5438
5722
  const tinaConfig = await database.getTinaSchema();
5439
5723
  const tinaSchema = await createSchema({
5724
+ // TODO: please update all the types to import from @tinacms/schema-tools
5725
+ // @ts-ignore
5440
5726
  schema: tinaConfig,
5727
+ // @ts-ignore
5441
5728
  flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5442
5729
  });
5443
5730
  const resolver = createResolver({
@@ -5454,8 +5741,7 @@ var resolve = async ({
5454
5741
  database
5455
5742
  },
5456
5743
  typeResolver: async (source, _args, info) => {
5457
- if (source.__typename)
5458
- return source.__typename;
5744
+ if (source.__typename) return source.__typename;
5459
5745
  const namedType = (0, import_graphql5.getNamedType)(info.returnType).toString();
5460
5746
  const lookup = await database.getLookup(namedType);
5461
5747
  if (lookup.resolveType === "unionData") {
@@ -5607,11 +5893,13 @@ var resolve = async ({
5607
5893
  (0, import_lodash4.default)(
5608
5894
  params,
5609
5895
  userField.path.slice(1),
5896
+ // remove _rawData from users path
5610
5897
  users.map((u) => {
5611
5898
  if (user[idFieldName] === u[idFieldName]) {
5612
5899
  return user;
5613
5900
  }
5614
5901
  return {
5902
+ // don't overwrite other users' passwords
5615
5903
  ...u,
5616
5904
  [passwordFieldName]: {
5617
5905
  ...u[passwordFieldName],
@@ -5634,6 +5922,9 @@ var resolve = async ({
5634
5922
  }
5635
5923
  const isCreation = lookup[info.fieldName] === "create";
5636
5924
  switch (lookup.resolveType) {
5925
+ /**
5926
+ * `node(id: $id)`
5927
+ */
5637
5928
  case "nodeDocument":
5638
5929
  assertShape(
5639
5930
  args,
@@ -5665,6 +5956,7 @@ var resolve = async ({
5665
5956
  collection: args.collection,
5666
5957
  isMutation,
5667
5958
  isCreation,
5959
+ // Right now this is the only case for deletion
5668
5960
  isDeletion: info.fieldName === "deleteDocument",
5669
5961
  isFolderCreation: info.fieldName === "createFolder",
5670
5962
  isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
@@ -5674,6 +5966,9 @@ var resolve = async ({
5674
5966
  return result;
5675
5967
  }
5676
5968
  return value;
5969
+ /**
5970
+ * eg `getMovieDocument.data.actors`
5971
+ */
5677
5972
  case "multiCollectionDocumentList":
5678
5973
  if (Array.isArray(value)) {
5679
5974
  return {
@@ -5685,7 +5980,15 @@ var resolve = async ({
5685
5980
  }
5686
5981
  if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
5687
5982
  let filter = args.filter;
5688
- if (typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && typeof ((_b = value == null ? void 0 : value.collection) == null ? void 0 : _b.name) === "string" && Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined") {
5983
+ if (
5984
+ // 1. Make sure that the filter exists
5985
+ typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
5986
+ // @ts-ignore
5987
+ typeof ((_b = value == null ? void 0 : value.collection) == null ? void 0 : _b.name) === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
5988
+ // @ts-ignore
5989
+ Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
5990
+ typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
5991
+ ) {
5689
5992
  filter = args.filter[value.collection.name];
5690
5993
  }
5691
5994
  return resolver.resolveCollectionConnection({
@@ -5693,12 +5996,20 @@ var resolve = async ({
5693
5996
  ...args,
5694
5997
  filter
5695
5998
  },
5999
+ // @ts-ignore
5696
6000
  collection: value.collection
5697
6001
  });
5698
6002
  }
5699
6003
  throw new Error(
5700
6004
  `Expected an array for result of ${info.fieldName} at ${info.path}`
5701
6005
  );
6006
+ /**
6007
+ * Collections-specific getter
6008
+ * eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
6009
+ *
6010
+ * if coming from a query result
6011
+ * the field will be `node`
6012
+ */
5702
6013
  case "collectionDocument": {
5703
6014
  if (value) {
5704
6015
  return value;
@@ -5713,11 +6024,32 @@ var resolve = async ({
5713
6024
  });
5714
6025
  return result;
5715
6026
  }
6027
+ /**
6028
+ * Collections-specific list getter
6029
+ * eg. `getPageList`
6030
+ */
5716
6031
  case "collectionDocumentList":
5717
6032
  return resolver.resolveCollectionConnection({
5718
6033
  args,
5719
6034
  collection: tinaSchema.getCollection(lookup.collection)
5720
6035
  });
6036
+ /**
6037
+ * A polymorphic data set, it can be from a document's data
6038
+ * of any nested object which can be one of many shapes
6039
+ *
6040
+ * ```graphql
6041
+ * getPostDocument(relativePath: $relativePath) {
6042
+ * data {...} <- this part
6043
+ * }
6044
+ * ```
6045
+ * ```graphql
6046
+ * getBlockDocument(relativePath: $relativePath) {
6047
+ * data {
6048
+ * blocks {...} <- or this part
6049
+ * }
6050
+ * }
6051
+ * ```
6052
+ */
5721
6053
  case "unionData":
5722
6054
  if (!value) {
5723
6055
  if (args.relativePath) {
@@ -5782,8 +6114,7 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
5782
6114
  this.port = port || 9e3;
5783
6115
  }
5784
6116
  openConnection() {
5785
- if (this._connected)
5786
- return;
6117
+ if (this._connected) return;
5787
6118
  const socket = (0, import_net.connect)(this.port);
5788
6119
  (0, import_readable_stream.pipeline)(socket, this.createRpcStream(), socket, () => {
5789
6120
  this._connected = false;
@@ -5964,6 +6295,7 @@ var Database = class {
5964
6295
  "put",
5965
6296
  level
5966
6297
  ),
6298
+ // folder indices
5967
6299
  ...makeIndexOpsForDocument(
5968
6300
  normalizedPath,
5969
6301
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -5986,6 +6318,7 @@ var Database = class {
5986
6318
  "del",
5987
6319
  level
5988
6320
  ),
6321
+ // folder indices
5989
6322
  ...makeIndexOpsForDocument(
5990
6323
  normalizedPath,
5991
6324
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6080,6 +6413,7 @@ var Database = class {
6080
6413
  "put",
6081
6414
  level
6082
6415
  ),
6416
+ // folder indices
6083
6417
  ...makeIndexOpsForDocument(
6084
6418
  normalizedPath,
6085
6419
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6102,6 +6436,7 @@ var Database = class {
6102
6436
  "del",
6103
6437
  level
6104
6438
  ),
6439
+ // folder indices
6105
6440
  ...makeIndexOpsForDocument(
6106
6441
  normalizedPath,
6107
6442
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6179,6 +6514,7 @@ var Database = class {
6179
6514
  aliasedData,
6180
6515
  extension,
6181
6516
  writeTemplateKey,
6517
+ //templateInfo.type === 'union',
6182
6518
  {
6183
6519
  frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6184
6520
  frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
@@ -6217,6 +6553,7 @@ var Database = class {
6217
6553
  SUBLEVEL_OPTIONS
6218
6554
  ).get(graphqlPath);
6219
6555
  };
6556
+ //TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
6220
6557
  this.getGraphQLSchemaFromBridge = async () => {
6221
6558
  if (!this.bridge) {
6222
6559
  throw new Error(`No bridge configured`);
@@ -6263,6 +6600,7 @@ var Database = class {
6263
6600
  for (const collection of collections) {
6264
6601
  const indexDefinitions = {
6265
6602
  [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
6603
+ // provide a default sort key which is the file sort
6266
6604
  };
6267
6605
  if (collection.fields) {
6268
6606
  for (const field of collection.fields) {
@@ -6587,12 +6925,12 @@ var Database = class {
6587
6925
  if (collection == null ? void 0 : collection.isDetached) {
6588
6926
  level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
6589
6927
  }
6590
- const itemKey = (0, import_schema_tools3.normalizePath)(filepath);
6928
+ const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
6591
6929
  const rootSublevel = level.sublevel(
6592
6930
  CONTENT_ROOT_PREFIX,
6593
6931
  SUBLEVEL_OPTIONS
6594
6932
  );
6595
- const item = await rootSublevel.get(itemKey);
6933
+ const item = await rootSublevel.get(normalizedPath);
6596
6934
  if (item) {
6597
6935
  const folderTreeBuilder = new FolderTreeBuilder();
6598
6936
  const folderKey = folderTreeBuilder.update(
@@ -6601,15 +6939,16 @@ var Database = class {
6601
6939
  );
6602
6940
  await this.contentLevel.batch([
6603
6941
  ...makeIndexOpsForDocument(
6604
- filepath,
6942
+ normalizedPath,
6605
6943
  collection.name,
6606
6944
  collectionIndexDefinitions,
6607
6945
  item,
6608
6946
  "del",
6609
6947
  level
6610
6948
  ),
6949
+ // folder indices
6611
6950
  ...makeIndexOpsForDocument(
6612
- filepath,
6951
+ normalizedPath,
6613
6952
  `${collection.name}_${folderKey}`,
6614
6953
  collectionIndexDefinitions,
6615
6954
  item,
@@ -6618,17 +6957,17 @@ var Database = class {
6618
6957
  ),
6619
6958
  {
6620
6959
  type: "del",
6621
- key: itemKey,
6960
+ key: normalizedPath,
6622
6961
  sublevel: rootSublevel
6623
6962
  }
6624
6963
  ]);
6625
6964
  }
6626
6965
  if (!(collection == null ? void 0 : collection.isDetached)) {
6627
6966
  if (this.bridge) {
6628
- await this.bridge.delete((0, import_schema_tools3.normalizePath)(filepath));
6967
+ await this.bridge.delete(normalizedPath);
6629
6968
  }
6630
6969
  try {
6631
- await this.onDelete((0, import_schema_tools3.normalizePath)(filepath));
6970
+ await this.onDelete(normalizedPath);
6632
6971
  } catch (e) {
6633
6972
  throw new import_graphql6.GraphQLError(
6634
6973
  `Error running onDelete hook for ${filepath}: ${e}`,
@@ -6762,6 +7101,9 @@ var Database = class {
6762
7101
  info: templateInfo
6763
7102
  };
6764
7103
  }
7104
+ /**
7105
+ * Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
7106
+ */
6765
7107
  clearCache() {
6766
7108
  this.tinaSchema = null;
6767
7109
  this._lookup = null;
@@ -6858,6 +7200,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
6858
7200
  "put",
6859
7201
  level
6860
7202
  ),
7203
+ // folder indexes
6861
7204
  ...makeIndexOpsForDocument(
6862
7205
  normalizedPath,
6863
7206
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6943,6 +7286,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
6943
7286
  "del",
6944
7287
  database.contentLevel
6945
7288
  ),
7289
+ // folder indexes
6946
7290
  ...makeIndexOpsForDocument(
6947
7291
  itemKey,
6948
7292
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -7158,17 +7502,26 @@ var IsomorphicBridge = class {
7158
7502
  getAuthor() {
7159
7503
  return {
7160
7504
  ...this.author,
7161
- timestamp: Math.round(new Date().getTime() / 1e3),
7505
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7162
7506
  timezoneOffset: 0
7163
7507
  };
7164
7508
  }
7165
7509
  getCommitter() {
7166
7510
  return {
7167
7511
  ...this.committer,
7168
- timestamp: Math.round(new Date().getTime() / 1e3),
7512
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7169
7513
  timezoneOffset: 0
7170
7514
  };
7171
7515
  }
7516
+ /**
7517
+ * Recursively populate paths matching `pattern` for the given `entry`
7518
+ *
7519
+ * @param pattern - pattern to filter paths by
7520
+ * @param entry - TreeEntry to start building list from
7521
+ * @param path - base path
7522
+ * @param results
7523
+ * @private
7524
+ */
7172
7525
  async listEntries({
7173
7526
  pattern,
7174
7527
  entry,
@@ -7201,6 +7554,15 @@ var IsomorphicBridge = class {
7201
7554
  });
7202
7555
  }
7203
7556
  }
7557
+ /**
7558
+ * For the specified path, returns an object with an array containing the parts of the path (pathParts)
7559
+ * and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
7560
+ * pathEntries are placeholders for non-existent entries.
7561
+ *
7562
+ * @param path - path being resolved
7563
+ * @param ref - ref to resolve path entries for
7564
+ * @private
7565
+ */
7204
7566
  async resolvePathEntries(path7, ref) {
7205
7567
  let pathParts = path7.split("/");
7206
7568
  const result = await import_isomorphic_git2.default.walk({
@@ -7231,6 +7593,17 @@ var IsomorphicBridge = class {
7231
7593
  }
7232
7594
  return { pathParts, pathEntries };
7233
7595
  }
7596
+ /**
7597
+ * Updates tree entry and associated parent tree entries
7598
+ *
7599
+ * @param existingOid - the existing OID
7600
+ * @param updatedOid - the updated OID
7601
+ * @param path - the path of the entry being updated
7602
+ * @param type - the type of the entry being updated (blob or tree)
7603
+ * @param pathEntries - parent path entries
7604
+ * @param pathParts - parent path parts
7605
+ * @private
7606
+ */
7234
7607
  async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
7235
7608
  const lastIdx = pathEntries.length - 1;
7236
7609
  const parentEntry = pathEntries[lastIdx];
@@ -7286,6 +7659,13 @@ var IsomorphicBridge = class {
7286
7659
  );
7287
7660
  }
7288
7661
  }
7662
+ /**
7663
+ * Creates a commit for the specified tree and updates the specified ref to point to the commit
7664
+ *
7665
+ * @param treeSha - sha of the new tree
7666
+ * @param ref - the ref that should be updated
7667
+ * @private
7668
+ */
7289
7669
  async commitTree(treeSha, ref) {
7290
7670
  const commitSha = await import_isomorphic_git2.default.writeCommit({
7291
7671
  ...this.isomorphicConfig,
@@ -7298,6 +7678,7 @@ var IsomorphicBridge = class {
7298
7678
  })
7299
7679
  ],
7300
7680
  message: this.commitMessage,
7681
+ // TODO these should be configurable
7301
7682
  author: this.getAuthor(),
7302
7683
  committer: this.getCommitter()
7303
7684
  }
@@ -7536,5 +7917,5 @@ var buildSchema = async (config, flags) => {
7536
7917
  transformDocument,
7537
7918
  transformDocumentIntoPayload
7538
7919
  });
7539
- //! Replaces _.flattenDeep()
7540
7920
  //! Replaces _.get()
7921
+ //! Replaces _.flattenDeep()