@tinacms/graphql 0.0.0-c72bb45-20241118014035 → 0.0.0-cef656e-20250119001929

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.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) => {
@@ -1010,41 +1029,6 @@ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
1010
1029
  yield maybeNode;
1011
1030
  visited.add(maybeNode);
1012
1031
  }
1013
- function addNamespaceToSchema(maybeNode, namespace = []) {
1014
- if (typeof maybeNode === "string") {
1015
- return maybeNode;
1016
- }
1017
- if (typeof maybeNode === "boolean") {
1018
- return maybeNode;
1019
- }
1020
- const newNode = maybeNode;
1021
- const keys = Object.keys(maybeNode);
1022
- Object.values(maybeNode).map((m, index) => {
1023
- const key = keys[index];
1024
- if (Array.isArray(m)) {
1025
- newNode[key] = m.map((element) => {
1026
- if (!element) {
1027
- return;
1028
- }
1029
- if (!element.hasOwnProperty("name")) {
1030
- return element;
1031
- }
1032
- const value = element.name || element.value;
1033
- return addNamespaceToSchema(element, [...namespace, value]);
1034
- });
1035
- } else {
1036
- if (!m) {
1037
- return;
1038
- }
1039
- if (!m.hasOwnProperty("name")) {
1040
- newNode[key] = m;
1041
- } else {
1042
- newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
1043
- }
1044
- }
1045
- });
1046
- return { ...newNode, namespace };
1047
- }
1048
1032
  var generateNamespacedFieldName = (names, suffix = "") => {
1049
1033
  return (suffix ? [...names, suffix] : names).map(capitalize).join("");
1050
1034
  };
@@ -1422,6 +1406,19 @@ var Builder = class {
1422
1406
  this.addToLookupMap = (lookup) => {
1423
1407
  this.lookupMap[lookup.type] = lookup;
1424
1408
  };
1409
+ /**
1410
+ * ```graphql
1411
+ * # ex.
1412
+ * {
1413
+ * getCollection(collection: $collection) {
1414
+ * name
1415
+ * documents {...}
1416
+ * }
1417
+ * }
1418
+ * ```
1419
+ *
1420
+ * @param collections
1421
+ */
1425
1422
  this.buildCollectionDefinition = async (collections) => {
1426
1423
  const name = "collection";
1427
1424
  const typeName = "Collection";
@@ -1492,6 +1489,19 @@ var Builder = class {
1492
1489
  required: true
1493
1490
  });
1494
1491
  };
1492
+ /**
1493
+ * ```graphql
1494
+ * # ex.
1495
+ * {
1496
+ * getCollections {
1497
+ * name
1498
+ * documents {...}
1499
+ * }
1500
+ * }
1501
+ * ```
1502
+ *
1503
+ * @param collections
1504
+ */
1495
1505
  this.buildMultiCollectionDefinition = async (collections) => {
1496
1506
  const name = "collections";
1497
1507
  const typeName = "Collection";
@@ -1502,6 +1512,17 @@ var Builder = class {
1502
1512
  required: true
1503
1513
  });
1504
1514
  };
1515
+ /**
1516
+ * ```graphql
1517
+ * # ex.
1518
+ * {
1519
+ * node(id: $id) {
1520
+ * id
1521
+ * data {...}
1522
+ * }
1523
+ * }
1524
+ * ```
1525
+ */
1505
1526
  this.multiNodeDocument = async () => {
1506
1527
  const name = "node";
1507
1528
  const args = [
@@ -1522,6 +1543,19 @@ var Builder = class {
1522
1543
  required: true
1523
1544
  });
1524
1545
  };
1546
+ /**
1547
+ * ```graphql
1548
+ * # ex.
1549
+ * {
1550
+ * getDocument(collection: $collection, relativePath: $relativePath) {
1551
+ * id
1552
+ * data {...}
1553
+ * }
1554
+ * }
1555
+ * ```
1556
+ *
1557
+ * @param collections
1558
+ */
1525
1559
  this.multiCollectionDocument = async (collections) => {
1526
1560
  const name = "document";
1527
1561
  const args = [
@@ -1547,6 +1581,19 @@ var Builder = class {
1547
1581
  required: true
1548
1582
  });
1549
1583
  };
1584
+ /**
1585
+ * ```graphql
1586
+ * # ex.
1587
+ * {
1588
+ * addPendingDocument(collection: $collection, relativePath: $relativePath, params: $params) {
1589
+ * id
1590
+ * data {...}
1591
+ * }
1592
+ * }
1593
+ * ```
1594
+ *
1595
+ * @param collections
1596
+ */
1550
1597
  this.addMultiCollectionDocumentMutation = async () => {
1551
1598
  return astBuilder.FieldDefinition({
1552
1599
  name: "addPendingDocument",
@@ -1571,6 +1618,19 @@ var Builder = class {
1571
1618
  type: astBuilder.TYPES.MultiCollectionDocument
1572
1619
  });
1573
1620
  };
1621
+ /**
1622
+ * ```graphql
1623
+ * # ex.
1624
+ * {
1625
+ * createDocument(relativePath: $relativePath, params: $params) {
1626
+ * id
1627
+ * data {...}
1628
+ * }
1629
+ * }
1630
+ * ```
1631
+ *
1632
+ * @param collections
1633
+ */
1574
1634
  this.buildCreateCollectionDocumentMutation = async (collections) => {
1575
1635
  return astBuilder.FieldDefinition({
1576
1636
  name: "createDocument",
@@ -1598,6 +1658,19 @@ var Builder = class {
1598
1658
  type: astBuilder.TYPES.MultiCollectionDocument
1599
1659
  });
1600
1660
  };
1661
+ /**
1662
+ * ```graphql
1663
+ * # ex.
1664
+ * {
1665
+ * updateDocument(relativePath: $relativePath, params: $params) {
1666
+ * id
1667
+ * data {...}
1668
+ * }
1669
+ * }
1670
+ * ```
1671
+ *
1672
+ * @param collections
1673
+ */
1601
1674
  this.buildUpdateCollectionDocumentMutation = async (collections) => {
1602
1675
  return astBuilder.FieldDefinition({
1603
1676
  name: "updateDocument",
@@ -1625,6 +1698,19 @@ var Builder = class {
1625
1698
  type: astBuilder.TYPES.MultiCollectionDocument
1626
1699
  });
1627
1700
  };
1701
+ /**
1702
+ * ```graphql
1703
+ * # ex.
1704
+ * {
1705
+ * deleteDocument(relativePath: $relativePath, params: $params) {
1706
+ * id
1707
+ * data {...}
1708
+ * }
1709
+ * }
1710
+ * ```
1711
+ *
1712
+ * @param collections
1713
+ */
1628
1714
  this.buildDeleteCollectionDocumentMutation = async (collections) => {
1629
1715
  return astBuilder.FieldDefinition({
1630
1716
  name: "deleteDocument",
@@ -1644,6 +1730,19 @@ var Builder = class {
1644
1730
  type: astBuilder.TYPES.MultiCollectionDocument
1645
1731
  });
1646
1732
  };
1733
+ /**
1734
+ * ```graphql
1735
+ * # ex.
1736
+ * {
1737
+ * createFolder(folderName: $folderName, params: $params) {
1738
+ * id
1739
+ * data {...}
1740
+ * }
1741
+ * }
1742
+ * ```
1743
+ *
1744
+ * @param collections
1745
+ */
1647
1746
  this.buildCreateCollectionFolderMutation = async () => {
1648
1747
  return astBuilder.FieldDefinition({
1649
1748
  name: "createFolder",
@@ -1663,6 +1762,19 @@ var Builder = class {
1663
1762
  type: astBuilder.TYPES.MultiCollectionDocument
1664
1763
  });
1665
1764
  };
1765
+ /**
1766
+ * ```graphql
1767
+ * # ex.
1768
+ * {
1769
+ * getPostDocument(relativePath: $relativePath) {
1770
+ * id
1771
+ * data {...}
1772
+ * }
1773
+ * }
1774
+ * ```
1775
+ *
1776
+ * @param collection
1777
+ */
1666
1778
  this.collectionDocument = async (collection) => {
1667
1779
  const name = NAMER.queryName([collection.name]);
1668
1780
  const type = await this._buildCollectionDocumentType(collection);
@@ -1723,6 +1835,20 @@ var Builder = class {
1723
1835
  const args = [];
1724
1836
  return astBuilder.FieldDefinition({ type, name, args, required: false });
1725
1837
  };
1838
+ /**
1839
+ * Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
1840
+ * ```graphql
1841
+ * # ex.
1842
+ * fragment AuthorsParts on Authors {
1843
+ * name
1844
+ * avatar
1845
+ * ...
1846
+ * }
1847
+ * ```
1848
+ *
1849
+ * @public
1850
+ * @param collection a Tina Cloud collection
1851
+ */
1726
1852
  this.collectionFragment = async (collection) => {
1727
1853
  const name = NAMER.dataTypeName(collection.namespace);
1728
1854
  const fragmentName = NAMER.fragmentName(collection.namespace);
@@ -1736,6 +1862,20 @@ var Builder = class {
1736
1862
  selections: filterSelections(selections)
1737
1863
  });
1738
1864
  };
1865
+ /**
1866
+ * Given a collection this function returns its selections set. For example for Post this would return
1867
+ *
1868
+ * "
1869
+ * body
1870
+ * title
1871
+ * ... on Author {
1872
+ * name
1873
+ * heroImg
1874
+ * }
1875
+ *
1876
+ * But in the AST format
1877
+ *
1878
+ * */
1739
1879
  this._getCollectionFragmentSelections = async (collection, depth) => {
1740
1880
  const selections = [];
1741
1881
  selections.push({
@@ -1817,9 +1957,9 @@ var Builder = class {
1817
1957
  ]
1818
1958
  });
1819
1959
  }
1960
+ // TODO: Should we throw here?
1820
1961
  case "reference":
1821
- if (depth >= this.maxDepth)
1822
- return false;
1962
+ if (depth >= this.maxDepth) return false;
1823
1963
  if (!("collections" in field)) {
1824
1964
  return false;
1825
1965
  }
@@ -1851,6 +1991,7 @@ var Builder = class {
1851
1991
  name: field.name,
1852
1992
  selections: [
1853
1993
  ...selections,
1994
+ // This is ... on Document { id }
1854
1995
  {
1855
1996
  kind: "InlineFragment",
1856
1997
  typeCondition: {
@@ -1881,6 +2022,19 @@ var Builder = class {
1881
2022
  });
1882
2023
  }
1883
2024
  };
2025
+ /**
2026
+ * ```graphql
2027
+ * # ex.
2028
+ * mutation {
2029
+ * updatePostDocument(relativePath: $relativePath, params: $params) {
2030
+ * id
2031
+ * data {...}
2032
+ * }
2033
+ * }
2034
+ * ```
2035
+ *
2036
+ * @param collection
2037
+ */
1884
2038
  this.updateCollectionDocumentMutation = async (collection) => {
1885
2039
  return astBuilder.FieldDefinition({
1886
2040
  type: await this._buildCollectionDocumentType(collection),
@@ -1900,6 +2054,19 @@ var Builder = class {
1900
2054
  ]
1901
2055
  });
1902
2056
  };
2057
+ /**
2058
+ * ```graphql
2059
+ * # ex.
2060
+ * mutation {
2061
+ * createPostDocument(relativePath: $relativePath, params: $params) {
2062
+ * id
2063
+ * data {...}
2064
+ * }
2065
+ * }
2066
+ * ```
2067
+ *
2068
+ * @param collection
2069
+ */
1903
2070
  this.createCollectionDocumentMutation = async (collection) => {
1904
2071
  return astBuilder.FieldDefinition({
1905
2072
  type: await this._buildCollectionDocumentType(collection),
@@ -1919,6 +2086,22 @@ var Builder = class {
1919
2086
  ]
1920
2087
  });
1921
2088
  };
2089
+ /**
2090
+ * ```graphql
2091
+ * # ex.
2092
+ * {
2093
+ * getPostList(first: 10) {
2094
+ * edges {
2095
+ * node {
2096
+ * id
2097
+ * }
2098
+ * }
2099
+ * }
2100
+ * }
2101
+ * ```
2102
+ *
2103
+ * @param collection
2104
+ */
1922
2105
  this.collectionDocumentList = async (collection) => {
1923
2106
  const connectionName = NAMER.referenceConnectionType(collection.namespace);
1924
2107
  this.addToLookupMap({
@@ -1934,6 +2117,10 @@ var Builder = class {
1934
2117
  collection
1935
2118
  });
1936
2119
  };
2120
+ /**
2121
+ * GraphQL type definitions which remain unchanged regardless
2122
+ * of the supplied Tina schema. Ex. "node" interface
2123
+ */
1937
2124
  this.buildStaticDefinitions = () => staticDefinitions;
1938
2125
  this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
1939
2126
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
@@ -2438,6 +2625,7 @@ var Builder = class {
2438
2625
  name: NAMER.dataFilterTypeName(namespace),
2439
2626
  fields: await sequential(collections, async (collection2) => {
2440
2627
  return astBuilder.InputValueDefinition({
2628
+ // @ts-ignore
2441
2629
  name: collection2.name,
2442
2630
  type: NAMER.dataFilterTypeName(collection2.namespace)
2443
2631
  });
@@ -2626,7 +2814,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2626
2814
  ]
2627
2815
  });
2628
2816
  };
2629
- this.maxDepth = config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
2817
+ this.maxDepth = // @ts-ignore
2818
+ config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
2630
2819
  this.tinaSchema = config.tinaSchema;
2631
2820
  this.lookupMap = {};
2632
2821
  }
@@ -2637,8 +2826,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2637
2826
  selections.push(field);
2638
2827
  });
2639
2828
  const filteredSelections = filterSelections(selections);
2640
- if (!filteredSelections.length)
2641
- return false;
2829
+ if (!filteredSelections.length) return false;
2642
2830
  return astBuilder.InlineFragmentDefinition({
2643
2831
  selections: filteredSelections,
2644
2832
  name: NAMER.dataTypeName(template.namespace)
@@ -2675,6 +2863,7 @@ var filterSelections = (arr) => {
2675
2863
  import { TinaSchema } from "@tinacms/schema-tools";
2676
2864
 
2677
2865
  // src/schema/validate.ts
2866
+ import { addNamespaceToSchema } from "@tinacms/schema-tools";
2678
2867
  import deepClone from "lodash.clonedeep";
2679
2868
  import * as yup2 from "yup";
2680
2869
  import {
@@ -2721,6 +2910,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2721
2910
  }).map((x) => `${x.path}${x.format || "md"}`);
2722
2911
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2723
2912
  throw new Error(
2913
+ // TODO: add a link to the docs
2724
2914
  "Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
2725
2915
  );
2726
2916
  }
@@ -2829,7 +3019,7 @@ var validateField = async (field) => {
2829
3019
  // package.json
2830
3020
  var package_default = {
2831
3021
  name: "@tinacms/graphql",
2832
- version: "1.5.7",
3022
+ version: "1.5.10",
2833
3023
  main: "dist/index.js",
2834
3024
  module: "dist/index.mjs",
2835
3025
  typings: "dist/index.d.ts",
@@ -2856,8 +3046,7 @@ var package_default = {
2856
3046
  build: "tinacms-scripts build",
2857
3047
  docs: "pnpm typedoc",
2858
3048
  serve: "pnpm nodemon dist/server.js",
2859
- test: "jest",
2860
- "test-watch": "jest --watch"
3049
+ test: "vitest"
2861
3050
  },
2862
3051
  dependencies: {
2863
3052
  "@iarna/toml": "^2.2.5",
@@ -2898,7 +3087,6 @@ var package_default = {
2898
3087
  "@types/estree": "^0.0.50",
2899
3088
  "@types/express": "^4.17.21",
2900
3089
  "@types/fs-extra": "^9.0.13",
2901
- "@types/jest": "^26.0.24",
2902
3090
  "@types/js-yaml": "^3.12.10",
2903
3091
  "@types/lodash.camelcase": "^4.3.9",
2904
3092
  "@types/lodash.upperfirst": "^4.3.9",
@@ -2909,13 +3097,13 @@ var package_default = {
2909
3097
  "@types/normalize-path": "^3.0.2",
2910
3098
  "@types/ws": "^7.4.7",
2911
3099
  "@types/yup": "^0.29.14",
2912
- jest: "^29.7.0",
2913
- "jest-diff": "^29.7.0",
2914
3100
  "jest-file-snapshot": "^0.5.0",
2915
- "jest-matcher-utils": "^29.7.0",
2916
3101
  "memory-level": "^1.0.0",
2917
3102
  nodemon: "3.1.4",
2918
- typescript: "^5.6.3"
3103
+ typescript: "^5.6.3",
3104
+ vite: "^4.3.9",
3105
+ vitest: "^0.32.2",
3106
+ zod: "^3.23.8"
2919
3107
  }
2920
3108
  };
2921
3109
 
@@ -2986,6 +3174,7 @@ var _buildFragments = async (builder, tinaSchema) => {
2986
3174
  const fragDoc = {
2987
3175
  kind: "Document",
2988
3176
  definitions: uniqBy2(
3177
+ // @ts-ignore
2989
3178
  extractInlineTypes(fragmentDefinitionsFields),
2990
3179
  (node) => node.name.value
2991
3180
  )
@@ -3008,6 +3197,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3008
3197
  fragName,
3009
3198
  queryName: queryListName,
3010
3199
  filterType: queryFilterTypeName,
3200
+ // look for flag to see if the data layer is enabled
3011
3201
  dataLayer: Boolean(
3012
3202
  tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
3013
3203
  )
@@ -3017,6 +3207,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3017
3207
  const queryDoc = {
3018
3208
  kind: "Document",
3019
3209
  definitions: uniqBy2(
3210
+ // @ts-ignore
3020
3211
  extractInlineTypes(operationsDefinitions),
3021
3212
  (node) => node.name.value
3022
3213
  )
@@ -3105,6 +3296,7 @@ var _buildSchema = async (builder, tinaSchema) => {
3105
3296
  return {
3106
3297
  kind: "Document",
3107
3298
  definitions: uniqBy2(
3299
+ // @ts-ignore
3108
3300
  extractInlineTypes(definitions),
3109
3301
  (node) => node.name.value
3110
3302
  )
@@ -3309,8 +3501,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
3309
3501
  }
3310
3502
  if (Array.isArray(value)) {
3311
3503
  return value.map((v) => {
3312
- if (!v || typeof v !== "string")
3313
- return v;
3504
+ if (!v || typeof v !== "string") return v;
3314
3505
  const cleanMediaRoot = cleanUpSlashes(
3315
3506
  schema.config.media.tina.mediaRoot
3316
3507
  );
@@ -3338,8 +3529,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3338
3529
  }
3339
3530
  if (Array.isArray(value)) {
3340
3531
  return value.map((v) => {
3341
- if (!v || typeof v !== "string")
3342
- return v;
3532
+ if (!v || typeof v !== "string") return v;
3343
3533
  const strippedValue = v.replace(cleanMediaRoot, "");
3344
3534
  return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3345
3535
  });
@@ -3357,8 +3547,7 @@ var cleanUpSlashes = (path7) => {
3357
3547
  return "";
3358
3548
  };
3359
3549
  var hasTinaMediaConfig = (schema) => {
3360
- if (!schema.config?.media?.tina)
3361
- return false;
3550
+ if (!schema.config?.media?.tina) return false;
3362
3551
  if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
3363
3552
  return false;
3364
3553
  return true;
@@ -3402,6 +3591,7 @@ var LevelProxyHandler = {
3402
3591
  } else if (property === "sublevel") {
3403
3592
  return (...args) => {
3404
3593
  return new Proxy(
3594
+ // eslint-disable-next-line prefer-spread
3405
3595
  target[property].apply(target, args),
3406
3596
  LevelProxyHandler
3407
3597
  );
@@ -4278,6 +4468,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
4278
4468
  result.push({
4279
4469
  type: opType,
4280
4470
  key: `${collection.path}/${subFolderKey}.${collection.format}`,
4471
+ // replace the root with the collection path
4281
4472
  sublevel: indexSublevel,
4282
4473
  value: {}
4283
4474
  });
@@ -4365,7 +4556,16 @@ var stringEscaper = makeStringEscaper(
4365
4556
  var createResolver = (args) => {
4366
4557
  return new Resolver(args);
4367
4558
  };
4368
- var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4559
+ var resolveFieldData = async (args) => {
4560
+ const {
4561
+ field: { namespace, ...field },
4562
+ rawData,
4563
+ accumulator,
4564
+ tinaSchema,
4565
+ config,
4566
+ isAudit,
4567
+ context
4568
+ } = args;
4369
4569
  if (!rawData) {
4370
4570
  return void 0;
4371
4571
  }
@@ -4392,6 +4592,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4392
4592
  case "password":
4393
4593
  accumulator[field.name] = {
4394
4594
  value: void 0,
4595
+ // never resolve the password hash
4395
4596
  passwordChangeRequired: value["passwordChangeRequired"] ?? false
4396
4597
  };
4397
4598
  break;
@@ -4404,9 +4605,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4404
4605
  break;
4405
4606
  case "rich-text":
4406
4607
  const tree = parseMDX(
4608
+ // @ts-ignore value is unknown
4407
4609
  value,
4408
4610
  field,
4409
- (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4611
+ (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema),
4612
+ context
4410
4613
  );
4411
4614
  if (tree?.children[0]?.type === "invalid_markdown") {
4412
4615
  if (isAudit) {
@@ -4437,14 +4640,15 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4437
4640
  });
4438
4641
  const payload = {};
4439
4642
  await sequential(template.fields, async (field2) => {
4440
- await resolveFieldData(
4441
- field2,
4442
- item,
4443
- payload,
4643
+ await resolveFieldData({
4644
+ field: field2,
4645
+ rawData: item,
4646
+ accumulator: payload,
4444
4647
  tinaSchema,
4445
4648
  config,
4446
- isAudit
4447
- );
4649
+ isAudit,
4650
+ context
4651
+ });
4448
4652
  });
4449
4653
  const isUnion = !!field.templates;
4450
4654
  return isUnion ? {
@@ -4465,14 +4669,15 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4465
4669
  });
4466
4670
  const payload = {};
4467
4671
  await sequential(template.fields, async (field2) => {
4468
- await resolveFieldData(
4469
- field2,
4470
- value,
4471
- payload,
4672
+ await resolveFieldData({
4673
+ field: field2,
4674
+ rawData: value,
4675
+ accumulator: payload,
4472
4676
  tinaSchema,
4473
4677
  config,
4474
- isAudit
4475
- );
4678
+ isAudit,
4679
+ context
4680
+ });
4476
4681
  });
4477
4682
  const isUnion = !!field.templates;
4478
4683
  accumulator[field.name] = isUnion ? {
@@ -4486,7 +4691,8 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4486
4691
  }
4487
4692
  return accumulator;
4488
4693
  };
4489
- var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config, isAudit, hasReferences) => {
4694
+ var transformDocumentIntoPayload = async (args) => {
4695
+ const { fullPath, rawData, tinaSchema, config, isAudit, context } = args;
4490
4696
  const collection = tinaSchema.getCollection(rawData._collection);
4491
4697
  try {
4492
4698
  const template = tinaSchema.getTemplateForData({
@@ -4506,14 +4712,15 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4506
4712
  };
4507
4713
  try {
4508
4714
  await sequential(template.fields, async (field) => {
4509
- return resolveFieldData(
4715
+ return resolveFieldData({
4510
4716
  field,
4511
4717
  rawData,
4512
- data,
4718
+ accumulator: data,
4513
4719
  tinaSchema,
4514
4720
  config,
4515
- isAudit
4516
- );
4721
+ isAudit,
4722
+ context
4723
+ });
4517
4724
  });
4518
4725
  } catch (e) {
4519
4726
  throw new TinaParseDocumentError({
@@ -4540,7 +4747,7 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4540
4747
  basename,
4541
4748
  filename,
4542
4749
  extension,
4543
- hasReferences,
4750
+ hasReferences: args.hasReferences,
4544
4751
  path: fullPath,
4545
4752
  relativePath,
4546
4753
  breadcrumbs,
@@ -4582,10 +4789,12 @@ var updateObjectWithJsonPath = (obj, path7, newValue) => {
4582
4789
  var Resolver = class {
4583
4790
  constructor(init) {
4584
4791
  this.init = init;
4792
+ this.context = {};
4585
4793
  this.resolveCollection = async (args, collectionName, hasDocuments) => {
4586
4794
  const collection = this.tinaSchema.getCollection(collectionName);
4587
4795
  const extraFields = {};
4588
4796
  return {
4797
+ // return the collection and hasDocuments to resolve documents at a lower level
4589
4798
  documents: { collection, hasDocuments },
4590
4799
  ...collection,
4591
4800
  ...extraFields
@@ -4611,13 +4820,15 @@ var Resolver = class {
4611
4820
  path: rawData["__folderPath"]
4612
4821
  };
4613
4822
  } else {
4614
- return transformDocumentIntoPayload(
4823
+ this.context = { ...rawData };
4824
+ return transformDocumentIntoPayload({
4615
4825
  fullPath,
4616
4826
  rawData,
4617
- this.tinaSchema,
4618
- this.config,
4619
- this.isAudit
4620
- );
4827
+ tinaSchema: this.tinaSchema,
4828
+ config: this.config,
4829
+ isAudit: this.isAudit,
4830
+ context: this.context
4831
+ });
4621
4832
  }
4622
4833
  };
4623
4834
  this.getDocument = async (fullPath, opts = {}) => {
@@ -4625,15 +4836,17 @@ var Resolver = class {
4625
4836
  throw new Error(`fullPath must be of type string for getDocument request`);
4626
4837
  }
4627
4838
  const rawData = await this.getRaw(fullPath);
4839
+ this.context = { ...rawData };
4628
4840
  const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
4629
- return transformDocumentIntoPayload(
4841
+ return transformDocumentIntoPayload({
4630
4842
  fullPath,
4631
4843
  rawData,
4632
- this.tinaSchema,
4633
- this.config,
4634
- this.isAudit,
4844
+ tinaSchema: this.tinaSchema,
4845
+ config: this.config,
4846
+ isAudit: this.isAudit,
4847
+ context: this.context,
4635
4848
  hasReferences
4636
- );
4849
+ });
4637
4850
  };
4638
4851
  this.deleteDocument = async (fullPath) => {
4639
4852
  if (typeof fullPath !== "string") {
@@ -4672,7 +4885,9 @@ var Resolver = class {
4672
4885
  );
4673
4886
  } else {
4674
4887
  return this.buildFieldMutations(
4888
+ // @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
4675
4889
  fieldValue,
4890
+ //@ts-ignore
4676
4891
  objectTemplate,
4677
4892
  existingData
4678
4893
  );
@@ -4684,6 +4899,7 @@ var Resolver = class {
4684
4899
  fieldValue.map(async (item) => {
4685
4900
  if (typeof item === "string") {
4686
4901
  throw new Error(
4902
+ //@ts-ignore
4687
4903
  `Expected object for template value for field ${field.name}`
4688
4904
  );
4689
4905
  }
@@ -4692,16 +4908,19 @@ var Resolver = class {
4692
4908
  });
4693
4909
  const [templateName] = Object.entries(item)[0];
4694
4910
  const template = templates.find(
4911
+ //@ts-ignore
4695
4912
  (template2) => template2.name === templateName
4696
4913
  );
4697
4914
  if (!template) {
4698
4915
  throw new Error(`Expected to find template ${templateName}`);
4699
4916
  }
4700
4917
  return {
4918
+ // @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
4919
  ...await this.buildFieldMutations(
4702
4920
  item[template.name],
4703
4921
  template
4704
4922
  ),
4923
+ //@ts-ignore
4705
4924
  _template: template.name
4706
4925
  };
4707
4926
  })
@@ -4709,6 +4928,7 @@ var Resolver = class {
4709
4928
  } else {
4710
4929
  if (typeof fieldValue === "string") {
4711
4930
  throw new Error(
4931
+ //@ts-ignore
4712
4932
  `Expected object for template value for field ${field.name}`
4713
4933
  );
4714
4934
  }
@@ -4717,16 +4937,19 @@ var Resolver = class {
4717
4937
  });
4718
4938
  const [templateName] = Object.entries(fieldValue)[0];
4719
4939
  const template = templates.find(
4940
+ //@ts-ignore
4720
4941
  (template2) => template2.name === templateName
4721
4942
  );
4722
4943
  if (!template) {
4723
4944
  throw new Error(`Expected to find template ${templateName}`);
4724
4945
  }
4725
4946
  return {
4947
+ // @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
4948
  ...await this.buildFieldMutations(
4727
4949
  fieldValue[template.name],
4728
4950
  template
4729
4951
  ),
4952
+ //@ts-ignore
4730
4953
  _template: template.name
4731
4954
  };
4732
4955
  }
@@ -4766,6 +4989,7 @@ var Resolver = class {
4766
4989
  return this.getDocument(realPath);
4767
4990
  }
4768
4991
  const params = await this.buildObjectMutations(
4992
+ // @ts-ignore
4769
4993
  args.params[collection.name],
4770
4994
  collection
4771
4995
  );
@@ -4781,56 +5005,65 @@ var Resolver = class {
4781
5005
  }) => {
4782
5006
  const doc = await this.getDocument(realPath);
4783
5007
  const oldDoc = this.resolveLegacyValues(doc?._rawData || {}, collection);
5008
+ let values;
4784
5009
  if (isAddPendingDocument === true) {
4785
5010
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
4786
- const params2 = this.buildParams(args);
5011
+ const params = this.buildParams(args);
4787
5012
  switch (templateInfo.type) {
4788
5013
  case "object":
4789
- if (params2) {
4790
- const values = await this.buildFieldMutations(
4791
- params2,
5014
+ if (params) {
5015
+ const mutationValues = await this.buildFieldMutations(
5016
+ params,
4792
5017
  templateInfo.template,
4793
5018
  doc?._rawData
4794
5019
  );
4795
- await this.database.put(
4796
- realPath,
4797
- { ...oldDoc, ...values },
4798
- collection.name
4799
- );
5020
+ values = { ...oldDoc, ...mutationValues };
4800
5021
  }
4801
5022
  break;
4802
- case "union":
5023
+ case "union": {
4803
5024
  await sequential(templateInfo.templates, async (template) => {
4804
- const templateParams = params2[lastItem(template.namespace)];
5025
+ const templateParams = params[lastItem(template.namespace)];
4805
5026
  if (templateParams) {
4806
5027
  if (typeof templateParams === "string") {
4807
5028
  throw new Error(
4808
5029
  `Expected to find an object for template params, but got string`
4809
5030
  );
4810
5031
  }
4811
- const values = {
5032
+ values = {
4812
5033
  ...oldDoc,
4813
5034
  ...await this.buildFieldMutations(
5035
+ // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
4814
5036
  templateParams,
4815
5037
  template,
4816
5038
  doc?._rawData
4817
5039
  ),
4818
5040
  _template: lastItem(template.namespace)
4819
5041
  };
4820
- await this.database.put(realPath, values, collection.name);
4821
5042
  }
4822
5043
  });
5044
+ }
4823
5045
  }
4824
- return this.getDocument(realPath);
5046
+ } else {
5047
+ const params = await this.buildObjectMutations(
5048
+ //@ts-expect-error FIXME: Argument of type 'unknown' is not assignable to parameter of type 'FieldParams'
5049
+ isCollectionSpecific ? args.params : args.params[collection.name],
5050
+ collection,
5051
+ doc?._rawData
5052
+ );
5053
+ values = { ...oldDoc, ...params };
4825
5054
  }
4826
- const params = await this.buildObjectMutations(
4827
- isCollectionSpecific ? args.params : args.params[collection.name],
4828
- collection,
4829
- doc?._rawData
5055
+ const _tinaEmbeds = this.context?._tinaEmbeds ? { _tinaEmbeds: this.context._tinaEmbeds } : {};
5056
+ await this.database.put(
5057
+ realPath,
5058
+ { ...values, ..._tinaEmbeds },
5059
+ collection.name
4830
5060
  );
4831
- await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
4832
5061
  return this.getDocument(realPath);
4833
5062
  };
5063
+ /**
5064
+ * Returns top-level fields which are not defined in the collection, so their
5065
+ * values are not eliminated from Tina when new values are saved
5066
+ */
4834
5067
  this.resolveLegacyValues = (oldDoc, collection) => {
4835
5068
  const legacyValues = {};
4836
5069
  Object.entries(oldDoc).forEach(([key, value]) => {
@@ -5036,6 +5269,7 @@ var Resolver = class {
5036
5269
  },
5037
5270
  collection: referencedCollection,
5038
5271
  hydrator: (path7) => path7
5272
+ // just return the path
5039
5273
  }
5040
5274
  );
5041
5275
  const { edges } = resolvedCollectionConnection;
@@ -5103,6 +5337,12 @@ var Resolver = class {
5103
5337
  }
5104
5338
  };
5105
5339
  };
5340
+ /**
5341
+ * Checks if a document has references to it
5342
+ * @param id The id of the document to check for references
5343
+ * @param c The collection to check for references
5344
+ * @returns true if the document has references, false otherwise
5345
+ */
5106
5346
  this.hasReferences = async (id, c) => {
5107
5347
  let count = 0;
5108
5348
  const deepRefs = this.tinaSchema.findReferences(c.name);
@@ -5137,6 +5377,12 @@ var Resolver = class {
5137
5377
  }
5138
5378
  return false;
5139
5379
  };
5380
+ /**
5381
+ * Finds references to a document
5382
+ * @param id the id of the document to find references to
5383
+ * @param c the collection to find references in
5384
+ * @returns references to the document in the form of a map of collection names to a list of fields that reference the document
5385
+ */
5140
5386
  this.findReferences = async (id, c) => {
5141
5387
  const references = {};
5142
5388
  const deepRefs = this.tinaSchema.findReferences(c.name);
@@ -5245,13 +5491,15 @@ var Resolver = class {
5245
5491
  break;
5246
5492
  case "rich-text":
5247
5493
  accum[fieldName] = stringifyMDX(
5494
+ // @ts-ignore
5248
5495
  fieldValue,
5249
5496
  field,
5250
5497
  (fieldValue2) => resolveMediaCloudToRelative(
5251
5498
  fieldValue2,
5252
5499
  this.config,
5253
5500
  this.tinaSchema.schema
5254
- )
5501
+ ),
5502
+ this.context
5255
5503
  );
5256
5504
  break;
5257
5505
  case "reference":
@@ -5263,6 +5511,27 @@ var Resolver = class {
5263
5511
  }
5264
5512
  return accum;
5265
5513
  };
5514
+ /**
5515
+ * A mutation looks nearly identical between updateDocument:
5516
+ * ```graphql
5517
+ * updateDocument(collection: $collection,relativePath: $path, params: {
5518
+ * post: {
5519
+ * title: "Hello, World"
5520
+ * }
5521
+ * })`
5522
+ * ```
5523
+ * and `updatePostDocument`:
5524
+ * ```graphql
5525
+ * updatePostDocument(relativePath: $path, params: {
5526
+ * title: "Hello, World"
5527
+ * })
5528
+ * ```
5529
+ * The problem here is that we don't know whether the payload came from `updateDocument`
5530
+ * or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
5531
+ * But we do know that when given a `args.collection` value, we can assume that
5532
+ * this was a `updateDocument` request, and thus - should grab the data
5533
+ * from the corresponding field name in the key
5534
+ */
5266
5535
  this.buildParams = (args) => {
5267
5536
  try {
5268
5537
  assertShape(
@@ -5362,7 +5631,10 @@ var resolve = async ({
5362
5631
  const graphQLSchema = buildASTSchema(graphQLSchemaAst);
5363
5632
  const tinaConfig = await database.getTinaSchema();
5364
5633
  const tinaSchema = await createSchema({
5634
+ // TODO: please update all the types to import from @tinacms/schema-tools
5635
+ // @ts-ignore
5365
5636
  schema: tinaConfig,
5637
+ // @ts-ignore
5366
5638
  flags: tinaConfig?.meta?.flags
5367
5639
  });
5368
5640
  const resolver = createResolver({
@@ -5379,8 +5651,7 @@ var resolve = async ({
5379
5651
  database
5380
5652
  },
5381
5653
  typeResolver: async (source, _args, info) => {
5382
- if (source.__typename)
5383
- return source.__typename;
5654
+ if (source.__typename) return source.__typename;
5384
5655
  const namedType = getNamedType(info.returnType).toString();
5385
5656
  const lookup = await database.getLookup(namedType);
5386
5657
  if (lookup.resolveType === "unionData") {
@@ -5529,11 +5800,13 @@ var resolve = async ({
5529
5800
  set(
5530
5801
  params,
5531
5802
  userField.path.slice(1),
5803
+ // remove _rawData from users path
5532
5804
  users.map((u) => {
5533
5805
  if (user[idFieldName] === u[idFieldName]) {
5534
5806
  return user;
5535
5807
  }
5536
5808
  return {
5809
+ // don't overwrite other users' passwords
5537
5810
  ...u,
5538
5811
  [passwordFieldName]: {
5539
5812
  ...u[passwordFieldName],
@@ -5556,6 +5829,9 @@ var resolve = async ({
5556
5829
  }
5557
5830
  const isCreation = lookup[info.fieldName] === "create";
5558
5831
  switch (lookup.resolveType) {
5832
+ /**
5833
+ * `node(id: $id)`
5834
+ */
5559
5835
  case "nodeDocument":
5560
5836
  assertShape(
5561
5837
  args,
@@ -5587,6 +5863,7 @@ var resolve = async ({
5587
5863
  collection: args.collection,
5588
5864
  isMutation,
5589
5865
  isCreation,
5866
+ // Right now this is the only case for deletion
5590
5867
  isDeletion: info.fieldName === "deleteDocument",
5591
5868
  isFolderCreation: info.fieldName === "createFolder",
5592
5869
  isUpdateName: Boolean(args?.params?.relativePath),
@@ -5596,6 +5873,9 @@ var resolve = async ({
5596
5873
  return result;
5597
5874
  }
5598
5875
  return value;
5876
+ /**
5877
+ * eg `getMovieDocument.data.actors`
5878
+ */
5599
5879
  case "multiCollectionDocumentList":
5600
5880
  if (Array.isArray(value)) {
5601
5881
  return {
@@ -5607,7 +5887,15 @@ var resolve = async ({
5607
5887
  }
5608
5888
  if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
5609
5889
  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") {
5890
+ if (
5891
+ // 1. Make sure that the filter exists
5892
+ typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
5893
+ // @ts-ignore
5894
+ typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
5895
+ // @ts-ignore
5896
+ Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
5897
+ typeof args.filter[value?.collection?.name] !== "undefined"
5898
+ ) {
5611
5899
  filter = args.filter[value.collection.name];
5612
5900
  }
5613
5901
  return resolver.resolveCollectionConnection({
@@ -5615,12 +5903,20 @@ var resolve = async ({
5615
5903
  ...args,
5616
5904
  filter
5617
5905
  },
5906
+ // @ts-ignore
5618
5907
  collection: value.collection
5619
5908
  });
5620
5909
  }
5621
5910
  throw new Error(
5622
5911
  `Expected an array for result of ${info.fieldName} at ${info.path}`
5623
5912
  );
5913
+ /**
5914
+ * Collections-specific getter
5915
+ * eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
5916
+ *
5917
+ * if coming from a query result
5918
+ * the field will be `node`
5919
+ */
5624
5920
  case "collectionDocument": {
5625
5921
  if (value) {
5626
5922
  return value;
@@ -5635,11 +5931,32 @@ var resolve = async ({
5635
5931
  });
5636
5932
  return result;
5637
5933
  }
5934
+ /**
5935
+ * Collections-specific list getter
5936
+ * eg. `getPageList`
5937
+ */
5638
5938
  case "collectionDocumentList":
5639
5939
  return resolver.resolveCollectionConnection({
5640
5940
  args,
5641
5941
  collection: tinaSchema.getCollection(lookup.collection)
5642
5942
  });
5943
+ /**
5944
+ * A polymorphic data set, it can be from a document's data
5945
+ * of any nested object which can be one of many shapes
5946
+ *
5947
+ * ```graphql
5948
+ * getPostDocument(relativePath: $relativePath) {
5949
+ * data {...} <- this part
5950
+ * }
5951
+ * ```
5952
+ * ```graphql
5953
+ * getBlockDocument(relativePath: $relativePath) {
5954
+ * data {
5955
+ * blocks {...} <- or this part
5956
+ * }
5957
+ * }
5958
+ * ```
5959
+ */
5643
5960
  case "unionData":
5644
5961
  if (!value) {
5645
5962
  if (args.relativePath) {
@@ -5704,8 +6021,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
5704
6021
  this.port = port || 9e3;
5705
6022
  }
5706
6023
  openConnection() {
5707
- if (this._connected)
5708
- return;
6024
+ if (this._connected) return;
5709
6025
  const socket = connect(this.port);
5710
6026
  pipeline(socket, this.createRpcStream(), socket, () => {
5711
6027
  this._connected = false;
@@ -5715,7 +6031,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
5715
6031
  };
5716
6032
 
5717
6033
  // src/database/index.ts
5718
- import path4 from "path";
6034
+ import path4 from "node:path";
5719
6035
  import { GraphQLError as GraphQLError5 } from "graphql";
5720
6036
  import micromatch2 from "micromatch";
5721
6037
  import sha2 from "js-sha1";
@@ -5886,6 +6202,7 @@ var Database = class {
5886
6202
  "put",
5887
6203
  level
5888
6204
  ),
6205
+ // folder indices
5889
6206
  ...makeIndexOpsForDocument(
5890
6207
  normalizedPath,
5891
6208
  `${collection?.name}_${folderKey}`,
@@ -5908,6 +6225,7 @@ var Database = class {
5908
6225
  "del",
5909
6226
  level
5910
6227
  ),
6228
+ // folder indices
5911
6229
  ...makeIndexOpsForDocument(
5912
6230
  normalizedPath,
5913
6231
  `${collection?.name}_${folderKey}`,
@@ -6001,6 +6319,7 @@ var Database = class {
6001
6319
  "put",
6002
6320
  level
6003
6321
  ),
6322
+ // folder indices
6004
6323
  ...makeIndexOpsForDocument(
6005
6324
  normalizedPath,
6006
6325
  `${collection?.name}_${folderKey}`,
@@ -6023,6 +6342,7 @@ var Database = class {
6023
6342
  "del",
6024
6343
  level
6025
6344
  ),
6345
+ // folder indices
6026
6346
  ...makeIndexOpsForDocument(
6027
6347
  normalizedPath,
6028
6348
  `${collection?.name}_${folderKey}`,
@@ -6100,6 +6420,7 @@ var Database = class {
6100
6420
  aliasedData,
6101
6421
  extension,
6102
6422
  writeTemplateKey,
6423
+ //templateInfo.type === 'union',
6103
6424
  {
6104
6425
  frontmatterFormat: collection?.frontmatterFormat,
6105
6426
  frontmatterDelimiters: collection?.frontmatterDelimiters
@@ -6138,6 +6459,7 @@ var Database = class {
6138
6459
  SUBLEVEL_OPTIONS
6139
6460
  ).get(graphqlPath);
6140
6461
  };
6462
+ //TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
6141
6463
  this.getGraphQLSchemaFromBridge = async () => {
6142
6464
  if (!this.bridge) {
6143
6465
  throw new Error(`No bridge configured`);
@@ -6184,6 +6506,7 @@ var Database = class {
6184
6506
  for (const collection of collections) {
6185
6507
  const indexDefinitions = {
6186
6508
  [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
6509
+ // provide a default sort key which is the file sort
6187
6510
  };
6188
6511
  if (collection.fields) {
6189
6512
  for (const field of collection.fields) {
@@ -6507,12 +6830,12 @@ var Database = class {
6507
6830
  if (collection?.isDetached) {
6508
6831
  level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
6509
6832
  }
6510
- const itemKey = normalizePath(filepath);
6833
+ const normalizedPath = normalizePath(filepath);
6511
6834
  const rootSublevel = level.sublevel(
6512
6835
  CONTENT_ROOT_PREFIX,
6513
6836
  SUBLEVEL_OPTIONS
6514
6837
  );
6515
- const item = await rootSublevel.get(itemKey);
6838
+ const item = await rootSublevel.get(normalizedPath);
6516
6839
  if (item) {
6517
6840
  const folderTreeBuilder = new FolderTreeBuilder();
6518
6841
  const folderKey = folderTreeBuilder.update(
@@ -6521,15 +6844,16 @@ var Database = class {
6521
6844
  );
6522
6845
  await this.contentLevel.batch([
6523
6846
  ...makeIndexOpsForDocument(
6524
- filepath,
6847
+ normalizedPath,
6525
6848
  collection.name,
6526
6849
  collectionIndexDefinitions,
6527
6850
  item,
6528
6851
  "del",
6529
6852
  level
6530
6853
  ),
6854
+ // folder indices
6531
6855
  ...makeIndexOpsForDocument(
6532
- filepath,
6856
+ normalizedPath,
6533
6857
  `${collection.name}_${folderKey}`,
6534
6858
  collectionIndexDefinitions,
6535
6859
  item,
@@ -6538,17 +6862,17 @@ var Database = class {
6538
6862
  ),
6539
6863
  {
6540
6864
  type: "del",
6541
- key: itemKey,
6865
+ key: normalizedPath,
6542
6866
  sublevel: rootSublevel
6543
6867
  }
6544
6868
  ]);
6545
6869
  }
6546
6870
  if (!collection?.isDetached) {
6547
6871
  if (this.bridge) {
6548
- await this.bridge.delete(normalizePath(filepath));
6872
+ await this.bridge.delete(normalizedPath);
6549
6873
  }
6550
6874
  try {
6551
- await this.onDelete(normalizePath(filepath));
6875
+ await this.onDelete(normalizedPath);
6552
6876
  } catch (e) {
6553
6877
  throw new GraphQLError5(
6554
6878
  `Error running onDelete hook for ${filepath}: ${e}`,
@@ -6682,6 +7006,9 @@ var Database = class {
6682
7006
  info: templateInfo
6683
7007
  };
6684
7008
  }
7009
+ /**
7010
+ * Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
7011
+ */
6685
7012
  clearCache() {
6686
7013
  this.tinaSchema = null;
6687
7014
  this._lookup = null;
@@ -6778,6 +7105,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
6778
7105
  "put",
6779
7106
  level
6780
7107
  ),
7108
+ // folder indexes
6781
7109
  ...makeIndexOpsForDocument(
6782
7110
  normalizedPath,
6783
7111
  `${collection?.name}_${folderKey}`,
@@ -6863,6 +7191,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
6863
7191
  "del",
6864
7192
  database.contentLevel
6865
7193
  ),
7194
+ // folder indexes
6866
7195
  ...makeIndexOpsForDocument(
6867
7196
  itemKey,
6868
7197
  `${collection?.name}_${folderKey}`,
@@ -7078,17 +7407,26 @@ var IsomorphicBridge = class {
7078
7407
  getAuthor() {
7079
7408
  return {
7080
7409
  ...this.author,
7081
- timestamp: Math.round(new Date().getTime() / 1e3),
7410
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7082
7411
  timezoneOffset: 0
7083
7412
  };
7084
7413
  }
7085
7414
  getCommitter() {
7086
7415
  return {
7087
7416
  ...this.committer,
7088
- timestamp: Math.round(new Date().getTime() / 1e3),
7417
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7089
7418
  timezoneOffset: 0
7090
7419
  };
7091
7420
  }
7421
+ /**
7422
+ * Recursively populate paths matching `pattern` for the given `entry`
7423
+ *
7424
+ * @param pattern - pattern to filter paths by
7425
+ * @param entry - TreeEntry to start building list from
7426
+ * @param path - base path
7427
+ * @param results
7428
+ * @private
7429
+ */
7092
7430
  async listEntries({
7093
7431
  pattern,
7094
7432
  entry,
@@ -7121,6 +7459,15 @@ var IsomorphicBridge = class {
7121
7459
  });
7122
7460
  }
7123
7461
  }
7462
+ /**
7463
+ * For the specified path, returns an object with an array containing the parts of the path (pathParts)
7464
+ * and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
7465
+ * pathEntries are placeholders for non-existent entries.
7466
+ *
7467
+ * @param path - path being resolved
7468
+ * @param ref - ref to resolve path entries for
7469
+ * @private
7470
+ */
7124
7471
  async resolvePathEntries(path7, ref) {
7125
7472
  let pathParts = path7.split("/");
7126
7473
  const result = await git2.walk({
@@ -7151,6 +7498,17 @@ var IsomorphicBridge = class {
7151
7498
  }
7152
7499
  return { pathParts, pathEntries };
7153
7500
  }
7501
+ /**
7502
+ * Updates tree entry and associated parent tree entries
7503
+ *
7504
+ * @param existingOid - the existing OID
7505
+ * @param updatedOid - the updated OID
7506
+ * @param path - the path of the entry being updated
7507
+ * @param type - the type of the entry being updated (blob or tree)
7508
+ * @param pathEntries - parent path entries
7509
+ * @param pathParts - parent path parts
7510
+ * @private
7511
+ */
7154
7512
  async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
7155
7513
  const lastIdx = pathEntries.length - 1;
7156
7514
  const parentEntry = pathEntries[lastIdx];
@@ -7206,6 +7564,13 @@ var IsomorphicBridge = class {
7206
7564
  );
7207
7565
  }
7208
7566
  }
7567
+ /**
7568
+ * Creates a commit for the specified tree and updates the specified ref to point to the commit
7569
+ *
7570
+ * @param treeSha - sha of the new tree
7571
+ * @param ref - the ref that should be updated
7572
+ * @private
7573
+ */
7209
7574
  async commitTree(treeSha, ref) {
7210
7575
  const commitSha = await git2.writeCommit({
7211
7576
  ...this.isomorphicConfig,
@@ -7218,6 +7583,7 @@ var IsomorphicBridge = class {
7218
7583
  })
7219
7584
  ],
7220
7585
  message: this.commitMessage,
7586
+ // TODO these should be configurable
7221
7587
  author: this.getAuthor(),
7222
7588
  committer: this.getCommitter()
7223
7589
  }
@@ -7455,5 +7821,5 @@ export {
7455
7821
  transformDocument,
7456
7822
  transformDocumentIntoPayload
7457
7823
  };
7458
- //! Replaces _.flattenDeep()
7459
7824
  //! Replaces _.get()
7825
+ //! Replaces _.flattenDeep()