@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.mjs CHANGED
@@ -68,6 +68,15 @@ var SysFieldDefinition = {
68
68
  selectionSet: {
69
69
  kind: "SelectionSet",
70
70
  selections: [
71
+ // {
72
+ // kind: 'Field' as const,
73
+ // name: {
74
+ // kind: 'Name' as const,
75
+ // value: 'title',
76
+ // },
77
+ // arguments: [],
78
+ // directives: [],
79
+ // },
71
80
  {
72
81
  kind: "Field",
73
82
  name: {
@@ -135,6 +144,10 @@ var SysFieldDefinition = {
135
144
  }
136
145
  };
137
146
  var astBuilder = {
147
+ /**
148
+ * `FormFieldBuilder` acts as a shortcut to building an entire `ObjectTypeDefinition`, we use this
149
+ * because all Tina field objects share a common set of fields ('name', 'label', 'component')
150
+ */
138
151
  FormFieldBuilder: ({
139
152
  name,
140
153
  additionalFields
@@ -358,6 +371,8 @@ var astBuilder = {
358
371
  kind: "Name",
359
372
  value: name
360
373
  },
374
+ // @ts-ignore FIXME; this is being handled properly but we're lying to
375
+ // ts and then fixing it in the `extractInlineTypes` function
361
376
  fields
362
377
  }),
363
378
  UnionTypeDefinition: ({
@@ -370,6 +385,8 @@ var astBuilder = {
370
385
  value: name
371
386
  },
372
387
  directives: [],
388
+ // @ts-ignore FIXME; this is being handled properly but we're lying to
389
+ // ts and then fixing it in the `extractInlineTypes` function
373
390
  types: types.map((name2) => ({
374
391
  kind: "NamedType",
375
392
  name: {
@@ -466,8 +483,11 @@ var astBuilder = {
466
483
  string: "String",
467
484
  boolean: "Boolean",
468
485
  number: "Float",
486
+ // FIXME - needs to be float or int
469
487
  datetime: "String",
488
+ // FIXME
470
489
  image: "String",
490
+ // FIXME
471
491
  text: "String"
472
492
  };
473
493
  return scalars[type];
@@ -966,8 +986,7 @@ var astBuilder = {
966
986
  }
967
987
  };
968
988
  var capitalize = (s) => {
969
- if (typeof s !== "string")
970
- return "";
989
+ if (typeof s !== "string") return "";
971
990
  return s.charAt(0).toUpperCase() + s.slice(1);
972
991
  };
973
992
  var extractInlineTypes = (item) => {
@@ -1422,6 +1441,19 @@ var Builder = class {
1422
1441
  this.addToLookupMap = (lookup) => {
1423
1442
  this.lookupMap[lookup.type] = lookup;
1424
1443
  };
1444
+ /**
1445
+ * ```graphql
1446
+ * # ex.
1447
+ * {
1448
+ * getCollection(collection: $collection) {
1449
+ * name
1450
+ * documents {...}
1451
+ * }
1452
+ * }
1453
+ * ```
1454
+ *
1455
+ * @param collections
1456
+ */
1425
1457
  this.buildCollectionDefinition = async (collections) => {
1426
1458
  const name = "collection";
1427
1459
  const typeName = "Collection";
@@ -1492,6 +1524,19 @@ var Builder = class {
1492
1524
  required: true
1493
1525
  });
1494
1526
  };
1527
+ /**
1528
+ * ```graphql
1529
+ * # ex.
1530
+ * {
1531
+ * getCollections {
1532
+ * name
1533
+ * documents {...}
1534
+ * }
1535
+ * }
1536
+ * ```
1537
+ *
1538
+ * @param collections
1539
+ */
1495
1540
  this.buildMultiCollectionDefinition = async (collections) => {
1496
1541
  const name = "collections";
1497
1542
  const typeName = "Collection";
@@ -1502,6 +1547,17 @@ var Builder = class {
1502
1547
  required: true
1503
1548
  });
1504
1549
  };
1550
+ /**
1551
+ * ```graphql
1552
+ * # ex.
1553
+ * {
1554
+ * node(id: $id) {
1555
+ * id
1556
+ * data {...}
1557
+ * }
1558
+ * }
1559
+ * ```
1560
+ */
1505
1561
  this.multiNodeDocument = async () => {
1506
1562
  const name = "node";
1507
1563
  const args = [
@@ -1522,6 +1578,19 @@ var Builder = class {
1522
1578
  required: true
1523
1579
  });
1524
1580
  };
1581
+ /**
1582
+ * ```graphql
1583
+ * # ex.
1584
+ * {
1585
+ * getDocument(collection: $collection, relativePath: $relativePath) {
1586
+ * id
1587
+ * data {...}
1588
+ * }
1589
+ * }
1590
+ * ```
1591
+ *
1592
+ * @param collections
1593
+ */
1525
1594
  this.multiCollectionDocument = async (collections) => {
1526
1595
  const name = "document";
1527
1596
  const args = [
@@ -1547,6 +1616,19 @@ var Builder = class {
1547
1616
  required: true
1548
1617
  });
1549
1618
  };
1619
+ /**
1620
+ * ```graphql
1621
+ * # ex.
1622
+ * {
1623
+ * addPendingDocument(collection: $collection, relativePath: $relativePath, params: $params) {
1624
+ * id
1625
+ * data {...}
1626
+ * }
1627
+ * }
1628
+ * ```
1629
+ *
1630
+ * @param collections
1631
+ */
1550
1632
  this.addMultiCollectionDocumentMutation = async () => {
1551
1633
  return astBuilder.FieldDefinition({
1552
1634
  name: "addPendingDocument",
@@ -1571,6 +1653,19 @@ var Builder = class {
1571
1653
  type: astBuilder.TYPES.MultiCollectionDocument
1572
1654
  });
1573
1655
  };
1656
+ /**
1657
+ * ```graphql
1658
+ * # ex.
1659
+ * {
1660
+ * createDocument(relativePath: $relativePath, params: $params) {
1661
+ * id
1662
+ * data {...}
1663
+ * }
1664
+ * }
1665
+ * ```
1666
+ *
1667
+ * @param collections
1668
+ */
1574
1669
  this.buildCreateCollectionDocumentMutation = async (collections) => {
1575
1670
  return astBuilder.FieldDefinition({
1576
1671
  name: "createDocument",
@@ -1598,6 +1693,19 @@ var Builder = class {
1598
1693
  type: astBuilder.TYPES.MultiCollectionDocument
1599
1694
  });
1600
1695
  };
1696
+ /**
1697
+ * ```graphql
1698
+ * # ex.
1699
+ * {
1700
+ * updateDocument(relativePath: $relativePath, params: $params) {
1701
+ * id
1702
+ * data {...}
1703
+ * }
1704
+ * }
1705
+ * ```
1706
+ *
1707
+ * @param collections
1708
+ */
1601
1709
  this.buildUpdateCollectionDocumentMutation = async (collections) => {
1602
1710
  return astBuilder.FieldDefinition({
1603
1711
  name: "updateDocument",
@@ -1625,6 +1733,19 @@ var Builder = class {
1625
1733
  type: astBuilder.TYPES.MultiCollectionDocument
1626
1734
  });
1627
1735
  };
1736
+ /**
1737
+ * ```graphql
1738
+ * # ex.
1739
+ * {
1740
+ * deleteDocument(relativePath: $relativePath, params: $params) {
1741
+ * id
1742
+ * data {...}
1743
+ * }
1744
+ * }
1745
+ * ```
1746
+ *
1747
+ * @param collections
1748
+ */
1628
1749
  this.buildDeleteCollectionDocumentMutation = async (collections) => {
1629
1750
  return astBuilder.FieldDefinition({
1630
1751
  name: "deleteDocument",
@@ -1644,6 +1765,19 @@ var Builder = class {
1644
1765
  type: astBuilder.TYPES.MultiCollectionDocument
1645
1766
  });
1646
1767
  };
1768
+ /**
1769
+ * ```graphql
1770
+ * # ex.
1771
+ * {
1772
+ * createFolder(folderName: $folderName, params: $params) {
1773
+ * id
1774
+ * data {...}
1775
+ * }
1776
+ * }
1777
+ * ```
1778
+ *
1779
+ * @param collections
1780
+ */
1647
1781
  this.buildCreateCollectionFolderMutation = async () => {
1648
1782
  return astBuilder.FieldDefinition({
1649
1783
  name: "createFolder",
@@ -1663,6 +1797,19 @@ var Builder = class {
1663
1797
  type: astBuilder.TYPES.MultiCollectionDocument
1664
1798
  });
1665
1799
  };
1800
+ /**
1801
+ * ```graphql
1802
+ * # ex.
1803
+ * {
1804
+ * getPostDocument(relativePath: $relativePath) {
1805
+ * id
1806
+ * data {...}
1807
+ * }
1808
+ * }
1809
+ * ```
1810
+ *
1811
+ * @param collection
1812
+ */
1666
1813
  this.collectionDocument = async (collection) => {
1667
1814
  const name = NAMER.queryName([collection.name]);
1668
1815
  const type = await this._buildCollectionDocumentType(collection);
@@ -1723,6 +1870,20 @@ var Builder = class {
1723
1870
  const args = [];
1724
1871
  return astBuilder.FieldDefinition({ type, name, args, required: false });
1725
1872
  };
1873
+ /**
1874
+ * Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
1875
+ * ```graphql
1876
+ * # ex.
1877
+ * fragment AuthorsParts on Authors {
1878
+ * name
1879
+ * avatar
1880
+ * ...
1881
+ * }
1882
+ * ```
1883
+ *
1884
+ * @public
1885
+ * @param collection a Tina Cloud collection
1886
+ */
1726
1887
  this.collectionFragment = async (collection) => {
1727
1888
  const name = NAMER.dataTypeName(collection.namespace);
1728
1889
  const fragmentName = NAMER.fragmentName(collection.namespace);
@@ -1736,6 +1897,20 @@ var Builder = class {
1736
1897
  selections: filterSelections(selections)
1737
1898
  });
1738
1899
  };
1900
+ /**
1901
+ * Given a collection this function returns its selections set. For example for Post this would return
1902
+ *
1903
+ * "
1904
+ * body
1905
+ * title
1906
+ * ... on Author {
1907
+ * name
1908
+ * heroImg
1909
+ * }
1910
+ *
1911
+ * But in the AST format
1912
+ *
1913
+ * */
1739
1914
  this._getCollectionFragmentSelections = async (collection, depth) => {
1740
1915
  const selections = [];
1741
1916
  selections.push({
@@ -1817,9 +1992,9 @@ var Builder = class {
1817
1992
  ]
1818
1993
  });
1819
1994
  }
1995
+ // TODO: Should we throw here?
1820
1996
  case "reference":
1821
- if (depth >= this.maxDepth)
1822
- return false;
1997
+ if (depth >= this.maxDepth) return false;
1823
1998
  if (!("collections" in field)) {
1824
1999
  return false;
1825
2000
  }
@@ -1851,6 +2026,7 @@ var Builder = class {
1851
2026
  name: field.name,
1852
2027
  selections: [
1853
2028
  ...selections,
2029
+ // This is ... on Document { id }
1854
2030
  {
1855
2031
  kind: "InlineFragment",
1856
2032
  typeCondition: {
@@ -1881,6 +2057,19 @@ var Builder = class {
1881
2057
  });
1882
2058
  }
1883
2059
  };
2060
+ /**
2061
+ * ```graphql
2062
+ * # ex.
2063
+ * mutation {
2064
+ * updatePostDocument(relativePath: $relativePath, params: $params) {
2065
+ * id
2066
+ * data {...}
2067
+ * }
2068
+ * }
2069
+ * ```
2070
+ *
2071
+ * @param collection
2072
+ */
1884
2073
  this.updateCollectionDocumentMutation = async (collection) => {
1885
2074
  return astBuilder.FieldDefinition({
1886
2075
  type: await this._buildCollectionDocumentType(collection),
@@ -1900,6 +2089,19 @@ var Builder = class {
1900
2089
  ]
1901
2090
  });
1902
2091
  };
2092
+ /**
2093
+ * ```graphql
2094
+ * # ex.
2095
+ * mutation {
2096
+ * createPostDocument(relativePath: $relativePath, params: $params) {
2097
+ * id
2098
+ * data {...}
2099
+ * }
2100
+ * }
2101
+ * ```
2102
+ *
2103
+ * @param collection
2104
+ */
1903
2105
  this.createCollectionDocumentMutation = async (collection) => {
1904
2106
  return astBuilder.FieldDefinition({
1905
2107
  type: await this._buildCollectionDocumentType(collection),
@@ -1919,6 +2121,22 @@ var Builder = class {
1919
2121
  ]
1920
2122
  });
1921
2123
  };
2124
+ /**
2125
+ * ```graphql
2126
+ * # ex.
2127
+ * {
2128
+ * getPostList(first: 10) {
2129
+ * edges {
2130
+ * node {
2131
+ * id
2132
+ * }
2133
+ * }
2134
+ * }
2135
+ * }
2136
+ * ```
2137
+ *
2138
+ * @param collection
2139
+ */
1922
2140
  this.collectionDocumentList = async (collection) => {
1923
2141
  const connectionName = NAMER.referenceConnectionType(collection.namespace);
1924
2142
  this.addToLookupMap({
@@ -1934,6 +2152,10 @@ var Builder = class {
1934
2152
  collection
1935
2153
  });
1936
2154
  };
2155
+ /**
2156
+ * GraphQL type definitions which remain unchanged regardless
2157
+ * of the supplied Tina schema. Ex. "node" interface
2158
+ */
1937
2159
  this.buildStaticDefinitions = () => staticDefinitions;
1938
2160
  this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
1939
2161
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
@@ -2438,6 +2660,7 @@ var Builder = class {
2438
2660
  name: NAMER.dataFilterTypeName(namespace),
2439
2661
  fields: await sequential(collections, async (collection2) => {
2440
2662
  return astBuilder.InputValueDefinition({
2663
+ // @ts-ignore
2441
2664
  name: collection2.name,
2442
2665
  type: NAMER.dataFilterTypeName(collection2.namespace)
2443
2666
  });
@@ -2626,7 +2849,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2626
2849
  ]
2627
2850
  });
2628
2851
  };
2629
- this.maxDepth = config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
2852
+ this.maxDepth = // @ts-ignore
2853
+ config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
2630
2854
  this.tinaSchema = config.tinaSchema;
2631
2855
  this.lookupMap = {};
2632
2856
  }
@@ -2637,8 +2861,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2637
2861
  selections.push(field);
2638
2862
  });
2639
2863
  const filteredSelections = filterSelections(selections);
2640
- if (!filteredSelections.length)
2641
- return false;
2864
+ if (!filteredSelections.length) return false;
2642
2865
  return astBuilder.InlineFragmentDefinition({
2643
2866
  selections: filteredSelections,
2644
2867
  name: NAMER.dataTypeName(template.namespace)
@@ -2721,6 +2944,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2721
2944
  }).map((x) => `${x.path}${x.format || "md"}`);
2722
2945
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2723
2946
  throw new Error(
2947
+ // TODO: add a link to the docs
2724
2948
  "Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
2725
2949
  );
2726
2950
  }
@@ -2829,7 +3053,7 @@ var validateField = async (field) => {
2829
3053
  // package.json
2830
3054
  var package_default = {
2831
3055
  name: "@tinacms/graphql",
2832
- version: "1.5.7",
3056
+ version: "1.5.9",
2833
3057
  main: "dist/index.js",
2834
3058
  module: "dist/index.mjs",
2835
3059
  typings: "dist/index.d.ts",
@@ -2986,6 +3210,7 @@ var _buildFragments = async (builder, tinaSchema) => {
2986
3210
  const fragDoc = {
2987
3211
  kind: "Document",
2988
3212
  definitions: uniqBy2(
3213
+ // @ts-ignore
2989
3214
  extractInlineTypes(fragmentDefinitionsFields),
2990
3215
  (node) => node.name.value
2991
3216
  )
@@ -3008,6 +3233,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3008
3233
  fragName,
3009
3234
  queryName: queryListName,
3010
3235
  filterType: queryFilterTypeName,
3236
+ // look for flag to see if the data layer is enabled
3011
3237
  dataLayer: Boolean(
3012
3238
  tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
3013
3239
  )
@@ -3017,6 +3243,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3017
3243
  const queryDoc = {
3018
3244
  kind: "Document",
3019
3245
  definitions: uniqBy2(
3246
+ // @ts-ignore
3020
3247
  extractInlineTypes(operationsDefinitions),
3021
3248
  (node) => node.name.value
3022
3249
  )
@@ -3105,6 +3332,7 @@ var _buildSchema = async (builder, tinaSchema) => {
3105
3332
  return {
3106
3333
  kind: "Document",
3107
3334
  definitions: uniqBy2(
3335
+ // @ts-ignore
3108
3336
  extractInlineTypes(definitions),
3109
3337
  (node) => node.name.value
3110
3338
  )
@@ -3309,8 +3537,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
3309
3537
  }
3310
3538
  if (Array.isArray(value)) {
3311
3539
  return value.map((v) => {
3312
- if (!v || typeof v !== "string")
3313
- return v;
3540
+ if (!v || typeof v !== "string") return v;
3314
3541
  const cleanMediaRoot = cleanUpSlashes(
3315
3542
  schema.config.media.tina.mediaRoot
3316
3543
  );
@@ -3338,8 +3565,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3338
3565
  }
3339
3566
  if (Array.isArray(value)) {
3340
3567
  return value.map((v) => {
3341
- if (!v || typeof v !== "string")
3342
- return v;
3568
+ if (!v || typeof v !== "string") return v;
3343
3569
  const strippedValue = v.replace(cleanMediaRoot, "");
3344
3570
  return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3345
3571
  });
@@ -3357,8 +3583,7 @@ var cleanUpSlashes = (path7) => {
3357
3583
  return "";
3358
3584
  };
3359
3585
  var hasTinaMediaConfig = (schema) => {
3360
- if (!schema.config?.media?.tina)
3361
- return false;
3586
+ if (!schema.config?.media?.tina) return false;
3362
3587
  if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
3363
3588
  return false;
3364
3589
  return true;
@@ -3402,6 +3627,7 @@ var LevelProxyHandler = {
3402
3627
  } else if (property === "sublevel") {
3403
3628
  return (...args) => {
3404
3629
  return new Proxy(
3630
+ // eslint-disable-next-line prefer-spread
3405
3631
  target[property].apply(target, args),
3406
3632
  LevelProxyHandler
3407
3633
  );
@@ -4278,6 +4504,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
4278
4504
  result.push({
4279
4505
  type: opType,
4280
4506
  key: `${collection.path}/${subFolderKey}.${collection.format}`,
4507
+ // replace the root with the collection path
4281
4508
  sublevel: indexSublevel,
4282
4509
  value: {}
4283
4510
  });
@@ -4392,6 +4619,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4392
4619
  case "password":
4393
4620
  accumulator[field.name] = {
4394
4621
  value: void 0,
4622
+ // never resolve the password hash
4395
4623
  passwordChangeRequired: value["passwordChangeRequired"] ?? false
4396
4624
  };
4397
4625
  break;
@@ -4586,6 +4814,7 @@ var Resolver = class {
4586
4814
  const collection = this.tinaSchema.getCollection(collectionName);
4587
4815
  const extraFields = {};
4588
4816
  return {
4817
+ // return the collection and hasDocuments to resolve documents at a lower level
4589
4818
  documents: { collection, hasDocuments },
4590
4819
  ...collection,
4591
4820
  ...extraFields
@@ -4672,7 +4901,9 @@ var Resolver = class {
4672
4901
  );
4673
4902
  } else {
4674
4903
  return this.buildFieldMutations(
4904
+ // @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
4675
4905
  fieldValue,
4906
+ //@ts-ignore
4676
4907
  objectTemplate,
4677
4908
  existingData
4678
4909
  );
@@ -4684,6 +4915,7 @@ var Resolver = class {
4684
4915
  fieldValue.map(async (item) => {
4685
4916
  if (typeof item === "string") {
4686
4917
  throw new Error(
4918
+ //@ts-ignore
4687
4919
  `Expected object for template value for field ${field.name}`
4688
4920
  );
4689
4921
  }
@@ -4692,16 +4924,19 @@ var Resolver = class {
4692
4924
  });
4693
4925
  const [templateName] = Object.entries(item)[0];
4694
4926
  const template = templates.find(
4927
+ //@ts-ignore
4695
4928
  (template2) => template2.name === templateName
4696
4929
  );
4697
4930
  if (!template) {
4698
4931
  throw new Error(`Expected to find template ${templateName}`);
4699
4932
  }
4700
4933
  return {
4934
+ // @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
4701
4935
  ...await this.buildFieldMutations(
4702
4936
  item[template.name],
4703
4937
  template
4704
4938
  ),
4939
+ //@ts-ignore
4705
4940
  _template: template.name
4706
4941
  };
4707
4942
  })
@@ -4709,6 +4944,7 @@ var Resolver = class {
4709
4944
  } else {
4710
4945
  if (typeof fieldValue === "string") {
4711
4946
  throw new Error(
4947
+ //@ts-ignore
4712
4948
  `Expected object for template value for field ${field.name}`
4713
4949
  );
4714
4950
  }
@@ -4717,16 +4953,19 @@ var Resolver = class {
4717
4953
  });
4718
4954
  const [templateName] = Object.entries(fieldValue)[0];
4719
4955
  const template = templates.find(
4956
+ //@ts-ignore
4720
4957
  (template2) => template2.name === templateName
4721
4958
  );
4722
4959
  if (!template) {
4723
4960
  throw new Error(`Expected to find template ${templateName}`);
4724
4961
  }
4725
4962
  return {
4963
+ // @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
4726
4964
  ...await this.buildFieldMutations(
4727
4965
  fieldValue[template.name],
4728
4966
  template
4729
4967
  ),
4968
+ //@ts-ignore
4730
4969
  _template: template.name
4731
4970
  };
4732
4971
  }
@@ -4766,6 +5005,7 @@ var Resolver = class {
4766
5005
  return this.getDocument(realPath);
4767
5006
  }
4768
5007
  const params = await this.buildObjectMutations(
5008
+ // @ts-ignore
4769
5009
  args.params[collection.name],
4770
5010
  collection
4771
5011
  );
@@ -4811,6 +5051,7 @@ var Resolver = class {
4811
5051
  const values = {
4812
5052
  ...oldDoc,
4813
5053
  ...await this.buildFieldMutations(
5054
+ // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
4814
5055
  templateParams,
4815
5056
  template,
4816
5057
  doc?._rawData
@@ -4824,6 +5065,7 @@ var Resolver = class {
4824
5065
  return this.getDocument(realPath);
4825
5066
  }
4826
5067
  const params = await this.buildObjectMutations(
5068
+ //@ts-ignore
4827
5069
  isCollectionSpecific ? args.params : args.params[collection.name],
4828
5070
  collection,
4829
5071
  doc?._rawData
@@ -4831,6 +5073,10 @@ var Resolver = class {
4831
5073
  await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
4832
5074
  return this.getDocument(realPath);
4833
5075
  };
5076
+ /**
5077
+ * Returns top-level fields which are not defined in the collection, so their
5078
+ * values are not eliminated from Tina when new values are saved
5079
+ */
4834
5080
  this.resolveLegacyValues = (oldDoc, collection) => {
4835
5081
  const legacyValues = {};
4836
5082
  Object.entries(oldDoc).forEach(([key, value]) => {
@@ -5036,6 +5282,7 @@ var Resolver = class {
5036
5282
  },
5037
5283
  collection: referencedCollection,
5038
5284
  hydrator: (path7) => path7
5285
+ // just return the path
5039
5286
  }
5040
5287
  );
5041
5288
  const { edges } = resolvedCollectionConnection;
@@ -5103,6 +5350,12 @@ var Resolver = class {
5103
5350
  }
5104
5351
  };
5105
5352
  };
5353
+ /**
5354
+ * Checks if a document has references to it
5355
+ * @param id The id of the document to check for references
5356
+ * @param c The collection to check for references
5357
+ * @returns true if the document has references, false otherwise
5358
+ */
5106
5359
  this.hasReferences = async (id, c) => {
5107
5360
  let count = 0;
5108
5361
  const deepRefs = this.tinaSchema.findReferences(c.name);
@@ -5137,6 +5390,12 @@ var Resolver = class {
5137
5390
  }
5138
5391
  return false;
5139
5392
  };
5393
+ /**
5394
+ * Finds references to a document
5395
+ * @param id the id of the document to find references to
5396
+ * @param c the collection to find references in
5397
+ * @returns references to the document in the form of a map of collection names to a list of fields that reference the document
5398
+ */
5140
5399
  this.findReferences = async (id, c) => {
5141
5400
  const references = {};
5142
5401
  const deepRefs = this.tinaSchema.findReferences(c.name);
@@ -5263,6 +5522,27 @@ var Resolver = class {
5263
5522
  }
5264
5523
  return accum;
5265
5524
  };
5525
+ /**
5526
+ * A mutation looks nearly identical between updateDocument:
5527
+ * ```graphql
5528
+ * updateDocument(collection: $collection,relativePath: $path, params: {
5529
+ * post: {
5530
+ * title: "Hello, World"
5531
+ * }
5532
+ * })`
5533
+ * ```
5534
+ * and `updatePostDocument`:
5535
+ * ```graphql
5536
+ * updatePostDocument(relativePath: $path, params: {
5537
+ * title: "Hello, World"
5538
+ * })
5539
+ * ```
5540
+ * The problem here is that we don't know whether the payload came from `updateDocument`
5541
+ * or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
5542
+ * But we do know that when given a `args.collection` value, we can assume that
5543
+ * this was a `updateDocument` request, and thus - should grab the data
5544
+ * from the corresponding field name in the key
5545
+ */
5266
5546
  this.buildParams = (args) => {
5267
5547
  try {
5268
5548
  assertShape(
@@ -5362,7 +5642,10 @@ var resolve = async ({
5362
5642
  const graphQLSchema = buildASTSchema(graphQLSchemaAst);
5363
5643
  const tinaConfig = await database.getTinaSchema();
5364
5644
  const tinaSchema = await createSchema({
5645
+ // TODO: please update all the types to import from @tinacms/schema-tools
5646
+ // @ts-ignore
5365
5647
  schema: tinaConfig,
5648
+ // @ts-ignore
5366
5649
  flags: tinaConfig?.meta?.flags
5367
5650
  });
5368
5651
  const resolver = createResolver({
@@ -5379,8 +5662,7 @@ var resolve = async ({
5379
5662
  database
5380
5663
  },
5381
5664
  typeResolver: async (source, _args, info) => {
5382
- if (source.__typename)
5383
- return source.__typename;
5665
+ if (source.__typename) return source.__typename;
5384
5666
  const namedType = getNamedType(info.returnType).toString();
5385
5667
  const lookup = await database.getLookup(namedType);
5386
5668
  if (lookup.resolveType === "unionData") {
@@ -5529,11 +5811,13 @@ var resolve = async ({
5529
5811
  set(
5530
5812
  params,
5531
5813
  userField.path.slice(1),
5814
+ // remove _rawData from users path
5532
5815
  users.map((u) => {
5533
5816
  if (user[idFieldName] === u[idFieldName]) {
5534
5817
  return user;
5535
5818
  }
5536
5819
  return {
5820
+ // don't overwrite other users' passwords
5537
5821
  ...u,
5538
5822
  [passwordFieldName]: {
5539
5823
  ...u[passwordFieldName],
@@ -5556,6 +5840,9 @@ var resolve = async ({
5556
5840
  }
5557
5841
  const isCreation = lookup[info.fieldName] === "create";
5558
5842
  switch (lookup.resolveType) {
5843
+ /**
5844
+ * `node(id: $id)`
5845
+ */
5559
5846
  case "nodeDocument":
5560
5847
  assertShape(
5561
5848
  args,
@@ -5587,6 +5874,7 @@ var resolve = async ({
5587
5874
  collection: args.collection,
5588
5875
  isMutation,
5589
5876
  isCreation,
5877
+ // Right now this is the only case for deletion
5590
5878
  isDeletion: info.fieldName === "deleteDocument",
5591
5879
  isFolderCreation: info.fieldName === "createFolder",
5592
5880
  isUpdateName: Boolean(args?.params?.relativePath),
@@ -5596,6 +5884,9 @@ var resolve = async ({
5596
5884
  return result;
5597
5885
  }
5598
5886
  return value;
5887
+ /**
5888
+ * eg `getMovieDocument.data.actors`
5889
+ */
5599
5890
  case "multiCollectionDocumentList":
5600
5891
  if (Array.isArray(value)) {
5601
5892
  return {
@@ -5607,7 +5898,15 @@ var resolve = async ({
5607
5898
  }
5608
5899
  if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
5609
5900
  let filter = args.filter;
5610
- if (typeof args?.filter !== "undefined" && args?.filter !== null && typeof value?.collection?.name === "string" && Object.keys(args.filter).includes(value?.collection?.name) && typeof args.filter[value?.collection?.name] !== "undefined") {
5901
+ if (
5902
+ // 1. Make sure that the filter exists
5903
+ typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
5904
+ // @ts-ignore
5905
+ typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
5906
+ // @ts-ignore
5907
+ Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
5908
+ typeof args.filter[value?.collection?.name] !== "undefined"
5909
+ ) {
5611
5910
  filter = args.filter[value.collection.name];
5612
5911
  }
5613
5912
  return resolver.resolveCollectionConnection({
@@ -5615,12 +5914,20 @@ var resolve = async ({
5615
5914
  ...args,
5616
5915
  filter
5617
5916
  },
5917
+ // @ts-ignore
5618
5918
  collection: value.collection
5619
5919
  });
5620
5920
  }
5621
5921
  throw new Error(
5622
5922
  `Expected an array for result of ${info.fieldName} at ${info.path}`
5623
5923
  );
5924
+ /**
5925
+ * Collections-specific getter
5926
+ * eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
5927
+ *
5928
+ * if coming from a query result
5929
+ * the field will be `node`
5930
+ */
5624
5931
  case "collectionDocument": {
5625
5932
  if (value) {
5626
5933
  return value;
@@ -5635,11 +5942,32 @@ var resolve = async ({
5635
5942
  });
5636
5943
  return result;
5637
5944
  }
5945
+ /**
5946
+ * Collections-specific list getter
5947
+ * eg. `getPageList`
5948
+ */
5638
5949
  case "collectionDocumentList":
5639
5950
  return resolver.resolveCollectionConnection({
5640
5951
  args,
5641
5952
  collection: tinaSchema.getCollection(lookup.collection)
5642
5953
  });
5954
+ /**
5955
+ * A polymorphic data set, it can be from a document's data
5956
+ * of any nested object which can be one of many shapes
5957
+ *
5958
+ * ```graphql
5959
+ * getPostDocument(relativePath: $relativePath) {
5960
+ * data {...} <- this part
5961
+ * }
5962
+ * ```
5963
+ * ```graphql
5964
+ * getBlockDocument(relativePath: $relativePath) {
5965
+ * data {
5966
+ * blocks {...} <- or this part
5967
+ * }
5968
+ * }
5969
+ * ```
5970
+ */
5643
5971
  case "unionData":
5644
5972
  if (!value) {
5645
5973
  if (args.relativePath) {
@@ -5704,8 +6032,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
5704
6032
  this.port = port || 9e3;
5705
6033
  }
5706
6034
  openConnection() {
5707
- if (this._connected)
5708
- return;
6035
+ if (this._connected) return;
5709
6036
  const socket = connect(this.port);
5710
6037
  pipeline(socket, this.createRpcStream(), socket, () => {
5711
6038
  this._connected = false;
@@ -5715,7 +6042,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
5715
6042
  };
5716
6043
 
5717
6044
  // src/database/index.ts
5718
- import path4 from "path";
6045
+ import path4 from "node:path";
5719
6046
  import { GraphQLError as GraphQLError5 } from "graphql";
5720
6047
  import micromatch2 from "micromatch";
5721
6048
  import sha2 from "js-sha1";
@@ -5886,6 +6213,7 @@ var Database = class {
5886
6213
  "put",
5887
6214
  level
5888
6215
  ),
6216
+ // folder indices
5889
6217
  ...makeIndexOpsForDocument(
5890
6218
  normalizedPath,
5891
6219
  `${collection?.name}_${folderKey}`,
@@ -5908,6 +6236,7 @@ var Database = class {
5908
6236
  "del",
5909
6237
  level
5910
6238
  ),
6239
+ // folder indices
5911
6240
  ...makeIndexOpsForDocument(
5912
6241
  normalizedPath,
5913
6242
  `${collection?.name}_${folderKey}`,
@@ -6001,6 +6330,7 @@ var Database = class {
6001
6330
  "put",
6002
6331
  level
6003
6332
  ),
6333
+ // folder indices
6004
6334
  ...makeIndexOpsForDocument(
6005
6335
  normalizedPath,
6006
6336
  `${collection?.name}_${folderKey}`,
@@ -6023,6 +6353,7 @@ var Database = class {
6023
6353
  "del",
6024
6354
  level
6025
6355
  ),
6356
+ // folder indices
6026
6357
  ...makeIndexOpsForDocument(
6027
6358
  normalizedPath,
6028
6359
  `${collection?.name}_${folderKey}`,
@@ -6100,6 +6431,7 @@ var Database = class {
6100
6431
  aliasedData,
6101
6432
  extension,
6102
6433
  writeTemplateKey,
6434
+ //templateInfo.type === 'union',
6103
6435
  {
6104
6436
  frontmatterFormat: collection?.frontmatterFormat,
6105
6437
  frontmatterDelimiters: collection?.frontmatterDelimiters
@@ -6138,6 +6470,7 @@ var Database = class {
6138
6470
  SUBLEVEL_OPTIONS
6139
6471
  ).get(graphqlPath);
6140
6472
  };
6473
+ //TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
6141
6474
  this.getGraphQLSchemaFromBridge = async () => {
6142
6475
  if (!this.bridge) {
6143
6476
  throw new Error(`No bridge configured`);
@@ -6184,6 +6517,7 @@ var Database = class {
6184
6517
  for (const collection of collections) {
6185
6518
  const indexDefinitions = {
6186
6519
  [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
6520
+ // provide a default sort key which is the file sort
6187
6521
  };
6188
6522
  if (collection.fields) {
6189
6523
  for (const field of collection.fields) {
@@ -6507,12 +6841,12 @@ var Database = class {
6507
6841
  if (collection?.isDetached) {
6508
6842
  level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
6509
6843
  }
6510
- const itemKey = normalizePath(filepath);
6844
+ const normalizedPath = normalizePath(filepath);
6511
6845
  const rootSublevel = level.sublevel(
6512
6846
  CONTENT_ROOT_PREFIX,
6513
6847
  SUBLEVEL_OPTIONS
6514
6848
  );
6515
- const item = await rootSublevel.get(itemKey);
6849
+ const item = await rootSublevel.get(normalizedPath);
6516
6850
  if (item) {
6517
6851
  const folderTreeBuilder = new FolderTreeBuilder();
6518
6852
  const folderKey = folderTreeBuilder.update(
@@ -6521,15 +6855,16 @@ var Database = class {
6521
6855
  );
6522
6856
  await this.contentLevel.batch([
6523
6857
  ...makeIndexOpsForDocument(
6524
- filepath,
6858
+ normalizedPath,
6525
6859
  collection.name,
6526
6860
  collectionIndexDefinitions,
6527
6861
  item,
6528
6862
  "del",
6529
6863
  level
6530
6864
  ),
6865
+ // folder indices
6531
6866
  ...makeIndexOpsForDocument(
6532
- filepath,
6867
+ normalizedPath,
6533
6868
  `${collection.name}_${folderKey}`,
6534
6869
  collectionIndexDefinitions,
6535
6870
  item,
@@ -6538,17 +6873,17 @@ var Database = class {
6538
6873
  ),
6539
6874
  {
6540
6875
  type: "del",
6541
- key: itemKey,
6876
+ key: normalizedPath,
6542
6877
  sublevel: rootSublevel
6543
6878
  }
6544
6879
  ]);
6545
6880
  }
6546
6881
  if (!collection?.isDetached) {
6547
6882
  if (this.bridge) {
6548
- await this.bridge.delete(normalizePath(filepath));
6883
+ await this.bridge.delete(normalizedPath);
6549
6884
  }
6550
6885
  try {
6551
- await this.onDelete(normalizePath(filepath));
6886
+ await this.onDelete(normalizedPath);
6552
6887
  } catch (e) {
6553
6888
  throw new GraphQLError5(
6554
6889
  `Error running onDelete hook for ${filepath}: ${e}`,
@@ -6682,6 +7017,9 @@ var Database = class {
6682
7017
  info: templateInfo
6683
7018
  };
6684
7019
  }
7020
+ /**
7021
+ * Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
7022
+ */
6685
7023
  clearCache() {
6686
7024
  this.tinaSchema = null;
6687
7025
  this._lookup = null;
@@ -6778,6 +7116,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
6778
7116
  "put",
6779
7117
  level
6780
7118
  ),
7119
+ // folder indexes
6781
7120
  ...makeIndexOpsForDocument(
6782
7121
  normalizedPath,
6783
7122
  `${collection?.name}_${folderKey}`,
@@ -6863,6 +7202,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
6863
7202
  "del",
6864
7203
  database.contentLevel
6865
7204
  ),
7205
+ // folder indexes
6866
7206
  ...makeIndexOpsForDocument(
6867
7207
  itemKey,
6868
7208
  `${collection?.name}_${folderKey}`,
@@ -7078,17 +7418,26 @@ var IsomorphicBridge = class {
7078
7418
  getAuthor() {
7079
7419
  return {
7080
7420
  ...this.author,
7081
- timestamp: Math.round(new Date().getTime() / 1e3),
7421
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7082
7422
  timezoneOffset: 0
7083
7423
  };
7084
7424
  }
7085
7425
  getCommitter() {
7086
7426
  return {
7087
7427
  ...this.committer,
7088
- timestamp: Math.round(new Date().getTime() / 1e3),
7428
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7089
7429
  timezoneOffset: 0
7090
7430
  };
7091
7431
  }
7432
+ /**
7433
+ * Recursively populate paths matching `pattern` for the given `entry`
7434
+ *
7435
+ * @param pattern - pattern to filter paths by
7436
+ * @param entry - TreeEntry to start building list from
7437
+ * @param path - base path
7438
+ * @param results
7439
+ * @private
7440
+ */
7092
7441
  async listEntries({
7093
7442
  pattern,
7094
7443
  entry,
@@ -7121,6 +7470,15 @@ var IsomorphicBridge = class {
7121
7470
  });
7122
7471
  }
7123
7472
  }
7473
+ /**
7474
+ * For the specified path, returns an object with an array containing the parts of the path (pathParts)
7475
+ * and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
7476
+ * pathEntries are placeholders for non-existent entries.
7477
+ *
7478
+ * @param path - path being resolved
7479
+ * @param ref - ref to resolve path entries for
7480
+ * @private
7481
+ */
7124
7482
  async resolvePathEntries(path7, ref) {
7125
7483
  let pathParts = path7.split("/");
7126
7484
  const result = await git2.walk({
@@ -7151,6 +7509,17 @@ var IsomorphicBridge = class {
7151
7509
  }
7152
7510
  return { pathParts, pathEntries };
7153
7511
  }
7512
+ /**
7513
+ * Updates tree entry and associated parent tree entries
7514
+ *
7515
+ * @param existingOid - the existing OID
7516
+ * @param updatedOid - the updated OID
7517
+ * @param path - the path of the entry being updated
7518
+ * @param type - the type of the entry being updated (blob or tree)
7519
+ * @param pathEntries - parent path entries
7520
+ * @param pathParts - parent path parts
7521
+ * @private
7522
+ */
7154
7523
  async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
7155
7524
  const lastIdx = pathEntries.length - 1;
7156
7525
  const parentEntry = pathEntries[lastIdx];
@@ -7206,6 +7575,13 @@ var IsomorphicBridge = class {
7206
7575
  );
7207
7576
  }
7208
7577
  }
7578
+ /**
7579
+ * Creates a commit for the specified tree and updates the specified ref to point to the commit
7580
+ *
7581
+ * @param treeSha - sha of the new tree
7582
+ * @param ref - the ref that should be updated
7583
+ * @private
7584
+ */
7209
7585
  async commitTree(treeSha, ref) {
7210
7586
  const commitSha = await git2.writeCommit({
7211
7587
  ...this.isomorphicConfig,
@@ -7218,6 +7594,7 @@ var IsomorphicBridge = class {
7218
7594
  })
7219
7595
  ],
7220
7596
  message: this.commitMessage,
7597
+ // TODO these should be configurable
7221
7598
  author: this.getAuthor(),
7222
7599
  committer: this.getCommitter()
7223
7600
  }
@@ -7455,5 +7832,5 @@ export {
7455
7832
  transformDocument,
7456
7833
  transformDocumentIntoPayload
7457
7834
  };
7458
- //! Replaces _.flattenDeep()
7459
7835
  //! Replaces _.get()
7836
+ //! Replaces _.flattenDeep()