@tinacms/graphql 0.0.0-c72bb45-20241118014035 → 0.0.0-c852462-20250131014229

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -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) => {
@@ -1072,41 +1095,6 @@ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
1072
1095
  yield maybeNode;
1073
1096
  visited.add(maybeNode);
1074
1097
  }
1075
- function addNamespaceToSchema(maybeNode, namespace = []) {
1076
- if (typeof maybeNode === "string") {
1077
- return maybeNode;
1078
- }
1079
- if (typeof maybeNode === "boolean") {
1080
- return maybeNode;
1081
- }
1082
- const newNode = maybeNode;
1083
- const keys = Object.keys(maybeNode);
1084
- Object.values(maybeNode).map((m, index) => {
1085
- const key = keys[index];
1086
- if (Array.isArray(m)) {
1087
- newNode[key] = m.map((element) => {
1088
- if (!element) {
1089
- return;
1090
- }
1091
- if (!element.hasOwnProperty("name")) {
1092
- return element;
1093
- }
1094
- const value = element.name || element.value;
1095
- return addNamespaceToSchema(element, [...namespace, value]);
1096
- });
1097
- } else {
1098
- if (!m) {
1099
- return;
1100
- }
1101
- if (!m.hasOwnProperty("name")) {
1102
- newNode[key] = m;
1103
- } else {
1104
- newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
1105
- }
1106
- }
1107
- });
1108
- return { ...newNode, namespace };
1109
- }
1110
1098
  var generateNamespacedFieldName = (names, suffix = "") => {
1111
1099
  return (suffix ? [...names, suffix] : names).map(capitalize).join("");
1112
1100
  };
@@ -1485,6 +1473,19 @@ var Builder = class {
1485
1473
  this.addToLookupMap = (lookup) => {
1486
1474
  this.lookupMap[lookup.type] = lookup;
1487
1475
  };
1476
+ /**
1477
+ * ```graphql
1478
+ * # ex.
1479
+ * {
1480
+ * getCollection(collection: $collection) {
1481
+ * name
1482
+ * documents {...}
1483
+ * }
1484
+ * }
1485
+ * ```
1486
+ *
1487
+ * @param collections
1488
+ */
1488
1489
  this.buildCollectionDefinition = async (collections) => {
1489
1490
  const name = "collection";
1490
1491
  const typeName = "Collection";
@@ -1555,6 +1556,19 @@ var Builder = class {
1555
1556
  required: true
1556
1557
  });
1557
1558
  };
1559
+ /**
1560
+ * ```graphql
1561
+ * # ex.
1562
+ * {
1563
+ * getCollections {
1564
+ * name
1565
+ * documents {...}
1566
+ * }
1567
+ * }
1568
+ * ```
1569
+ *
1570
+ * @param collections
1571
+ */
1558
1572
  this.buildMultiCollectionDefinition = async (collections) => {
1559
1573
  const name = "collections";
1560
1574
  const typeName = "Collection";
@@ -1565,6 +1579,17 @@ var Builder = class {
1565
1579
  required: true
1566
1580
  });
1567
1581
  };
1582
+ /**
1583
+ * ```graphql
1584
+ * # ex.
1585
+ * {
1586
+ * node(id: $id) {
1587
+ * id
1588
+ * data {...}
1589
+ * }
1590
+ * }
1591
+ * ```
1592
+ */
1568
1593
  this.multiNodeDocument = async () => {
1569
1594
  const name = "node";
1570
1595
  const args = [
@@ -1585,6 +1610,19 @@ var Builder = class {
1585
1610
  required: true
1586
1611
  });
1587
1612
  };
1613
+ /**
1614
+ * ```graphql
1615
+ * # ex.
1616
+ * {
1617
+ * getDocument(collection: $collection, relativePath: $relativePath) {
1618
+ * id
1619
+ * data {...}
1620
+ * }
1621
+ * }
1622
+ * ```
1623
+ *
1624
+ * @param collections
1625
+ */
1588
1626
  this.multiCollectionDocument = async (collections) => {
1589
1627
  const name = "document";
1590
1628
  const args = [
@@ -1610,6 +1648,19 @@ var Builder = class {
1610
1648
  required: true
1611
1649
  });
1612
1650
  };
1651
+ /**
1652
+ * ```graphql
1653
+ * # ex.
1654
+ * {
1655
+ * addPendingDocument(collection: $collection, relativePath: $relativePath, params: $params) {
1656
+ * id
1657
+ * data {...}
1658
+ * }
1659
+ * }
1660
+ * ```
1661
+ *
1662
+ * @param collections
1663
+ */
1613
1664
  this.addMultiCollectionDocumentMutation = async () => {
1614
1665
  return astBuilder.FieldDefinition({
1615
1666
  name: "addPendingDocument",
@@ -1634,6 +1685,19 @@ var Builder = class {
1634
1685
  type: astBuilder.TYPES.MultiCollectionDocument
1635
1686
  });
1636
1687
  };
1688
+ /**
1689
+ * ```graphql
1690
+ * # ex.
1691
+ * {
1692
+ * createDocument(relativePath: $relativePath, params: $params) {
1693
+ * id
1694
+ * data {...}
1695
+ * }
1696
+ * }
1697
+ * ```
1698
+ *
1699
+ * @param collections
1700
+ */
1637
1701
  this.buildCreateCollectionDocumentMutation = async (collections) => {
1638
1702
  return astBuilder.FieldDefinition({
1639
1703
  name: "createDocument",
@@ -1661,6 +1725,19 @@ var Builder = class {
1661
1725
  type: astBuilder.TYPES.MultiCollectionDocument
1662
1726
  });
1663
1727
  };
1728
+ /**
1729
+ * ```graphql
1730
+ * # ex.
1731
+ * {
1732
+ * updateDocument(relativePath: $relativePath, params: $params) {
1733
+ * id
1734
+ * data {...}
1735
+ * }
1736
+ * }
1737
+ * ```
1738
+ *
1739
+ * @param collections
1740
+ */
1664
1741
  this.buildUpdateCollectionDocumentMutation = async (collections) => {
1665
1742
  return astBuilder.FieldDefinition({
1666
1743
  name: "updateDocument",
@@ -1688,6 +1765,19 @@ var Builder = class {
1688
1765
  type: astBuilder.TYPES.MultiCollectionDocument
1689
1766
  });
1690
1767
  };
1768
+ /**
1769
+ * ```graphql
1770
+ * # ex.
1771
+ * {
1772
+ * deleteDocument(relativePath: $relativePath, params: $params) {
1773
+ * id
1774
+ * data {...}
1775
+ * }
1776
+ * }
1777
+ * ```
1778
+ *
1779
+ * @param collections
1780
+ */
1691
1781
  this.buildDeleteCollectionDocumentMutation = async (collections) => {
1692
1782
  return astBuilder.FieldDefinition({
1693
1783
  name: "deleteDocument",
@@ -1707,6 +1797,19 @@ var Builder = class {
1707
1797
  type: astBuilder.TYPES.MultiCollectionDocument
1708
1798
  });
1709
1799
  };
1800
+ /**
1801
+ * ```graphql
1802
+ * # ex.
1803
+ * {
1804
+ * createFolder(folderName: $folderName, params: $params) {
1805
+ * id
1806
+ * data {...}
1807
+ * }
1808
+ * }
1809
+ * ```
1810
+ *
1811
+ * @param collections
1812
+ */
1710
1813
  this.buildCreateCollectionFolderMutation = async () => {
1711
1814
  return astBuilder.FieldDefinition({
1712
1815
  name: "createFolder",
@@ -1726,6 +1829,19 @@ var Builder = class {
1726
1829
  type: astBuilder.TYPES.MultiCollectionDocument
1727
1830
  });
1728
1831
  };
1832
+ /**
1833
+ * ```graphql
1834
+ * # ex.
1835
+ * {
1836
+ * getPostDocument(relativePath: $relativePath) {
1837
+ * id
1838
+ * data {...}
1839
+ * }
1840
+ * }
1841
+ * ```
1842
+ *
1843
+ * @param collection
1844
+ */
1729
1845
  this.collectionDocument = async (collection) => {
1730
1846
  const name = NAMER.queryName([collection.name]);
1731
1847
  const type = await this._buildCollectionDocumentType(collection);
@@ -1786,6 +1902,20 @@ var Builder = class {
1786
1902
  const args = [];
1787
1903
  return astBuilder.FieldDefinition({ type, name, args, required: false });
1788
1904
  };
1905
+ /**
1906
+ * Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
1907
+ * ```graphql
1908
+ * # ex.
1909
+ * fragment AuthorsParts on Authors {
1910
+ * name
1911
+ * avatar
1912
+ * ...
1913
+ * }
1914
+ * ```
1915
+ *
1916
+ * @public
1917
+ * @param collection a Tina Cloud collection
1918
+ */
1789
1919
  this.collectionFragment = async (collection) => {
1790
1920
  const name = NAMER.dataTypeName(collection.namespace);
1791
1921
  const fragmentName = NAMER.fragmentName(collection.namespace);
@@ -1799,6 +1929,20 @@ var Builder = class {
1799
1929
  selections: filterSelections(selections)
1800
1930
  });
1801
1931
  };
1932
+ /**
1933
+ * Given a collection this function returns its selections set. For example for Post this would return
1934
+ *
1935
+ * "
1936
+ * body
1937
+ * title
1938
+ * ... on Author {
1939
+ * name
1940
+ * heroImg
1941
+ * }
1942
+ *
1943
+ * But in the AST format
1944
+ *
1945
+ * */
1802
1946
  this._getCollectionFragmentSelections = async (collection, depth) => {
1803
1947
  var _a;
1804
1948
  const selections = [];
@@ -1882,9 +2026,9 @@ var Builder = class {
1882
2026
  ]
1883
2027
  });
1884
2028
  }
2029
+ // TODO: Should we throw here?
1885
2030
  case "reference":
1886
- if (depth >= this.maxDepth)
1887
- return false;
2031
+ if (depth >= this.maxDepth) return false;
1888
2032
  if (!("collections" in field)) {
1889
2033
  return false;
1890
2034
  }
@@ -1916,6 +2060,7 @@ var Builder = class {
1916
2060
  name: field.name,
1917
2061
  selections: [
1918
2062
  ...selections,
2063
+ // This is ... on Document { id }
1919
2064
  {
1920
2065
  kind: "InlineFragment",
1921
2066
  typeCondition: {
@@ -1946,6 +2091,19 @@ var Builder = class {
1946
2091
  });
1947
2092
  }
1948
2093
  };
2094
+ /**
2095
+ * ```graphql
2096
+ * # ex.
2097
+ * mutation {
2098
+ * updatePostDocument(relativePath: $relativePath, params: $params) {
2099
+ * id
2100
+ * data {...}
2101
+ * }
2102
+ * }
2103
+ * ```
2104
+ *
2105
+ * @param collection
2106
+ */
1949
2107
  this.updateCollectionDocumentMutation = async (collection) => {
1950
2108
  return astBuilder.FieldDefinition({
1951
2109
  type: await this._buildCollectionDocumentType(collection),
@@ -1965,6 +2123,19 @@ var Builder = class {
1965
2123
  ]
1966
2124
  });
1967
2125
  };
2126
+ /**
2127
+ * ```graphql
2128
+ * # ex.
2129
+ * mutation {
2130
+ * createPostDocument(relativePath: $relativePath, params: $params) {
2131
+ * id
2132
+ * data {...}
2133
+ * }
2134
+ * }
2135
+ * ```
2136
+ *
2137
+ * @param collection
2138
+ */
1968
2139
  this.createCollectionDocumentMutation = async (collection) => {
1969
2140
  return astBuilder.FieldDefinition({
1970
2141
  type: await this._buildCollectionDocumentType(collection),
@@ -1984,6 +2155,22 @@ var Builder = class {
1984
2155
  ]
1985
2156
  });
1986
2157
  };
2158
+ /**
2159
+ * ```graphql
2160
+ * # ex.
2161
+ * {
2162
+ * getPostList(first: 10) {
2163
+ * edges {
2164
+ * node {
2165
+ * id
2166
+ * }
2167
+ * }
2168
+ * }
2169
+ * }
2170
+ * ```
2171
+ *
2172
+ * @param collection
2173
+ */
1987
2174
  this.collectionDocumentList = async (collection) => {
1988
2175
  const connectionName = NAMER.referenceConnectionType(collection.namespace);
1989
2176
  this.addToLookupMap({
@@ -1999,6 +2186,10 @@ var Builder = class {
1999
2186
  collection
2000
2187
  });
2001
2188
  };
2189
+ /**
2190
+ * GraphQL type definitions which remain unchanged regardless
2191
+ * of the supplied Tina schema. Ex. "node" interface
2192
+ */
2002
2193
  this.buildStaticDefinitions = () => staticDefinitions;
2003
2194
  this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
2004
2195
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
@@ -2503,6 +2694,7 @@ var Builder = class {
2503
2694
  name: NAMER.dataFilterTypeName(namespace),
2504
2695
  fields: await sequential(collections, async (collection2) => {
2505
2696
  return astBuilder.InputValueDefinition({
2697
+ // @ts-ignore
2506
2698
  name: collection2.name,
2507
2699
  type: NAMER.dataFilterTypeName(collection2.namespace)
2508
2700
  });
@@ -2692,7 +2884,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2692
2884
  });
2693
2885
  };
2694
2886
  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;
2887
+ this.maxDepth = // @ts-ignore
2888
+ (_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
2889
  this.tinaSchema = config.tinaSchema;
2697
2890
  this.lookupMap = {};
2698
2891
  }
@@ -2703,8 +2896,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2703
2896
  selections.push(field);
2704
2897
  });
2705
2898
  const filteredSelections = filterSelections(selections);
2706
- if (!filteredSelections.length)
2707
- return false;
2899
+ if (!filteredSelections.length) return false;
2708
2900
  return astBuilder.InlineFragmentDefinition({
2709
2901
  selections: filteredSelections,
2710
2902
  name: NAMER.dataTypeName(template.namespace)
@@ -2738,12 +2930,13 @@ var filterSelections = (arr) => {
2738
2930
  };
2739
2931
 
2740
2932
  // src/schema/createSchema.ts
2741
- var import_schema_tools2 = require("@tinacms/schema-tools");
2933
+ var import_schema_tools3 = require("@tinacms/schema-tools");
2742
2934
 
2743
2935
  // src/schema/validate.ts
2936
+ var import_schema_tools = require("@tinacms/schema-tools");
2744
2937
  var import_lodash2 = __toESM(require("lodash.clonedeep"));
2745
2938
  var yup2 = __toESM(require("yup"));
2746
- var import_schema_tools = require("@tinacms/schema-tools");
2939
+ var import_schema_tools2 = require("@tinacms/schema-tools");
2747
2940
  var FIELD_TYPES = [
2748
2941
  "string",
2749
2942
  "number",
@@ -2756,7 +2949,7 @@ var FIELD_TYPES = [
2756
2949
  "password"
2757
2950
  ];
2758
2951
  var validateSchema = async (schema) => {
2759
- const schema2 = addNamespaceToSchema(
2952
+ const schema2 = (0, import_schema_tools.addNamespaceToSchema)(
2760
2953
  (0, import_lodash2.default)(schema)
2761
2954
  );
2762
2955
  const collections = await sequential(
@@ -2765,7 +2958,7 @@ var validateSchema = async (schema) => {
2765
2958
  );
2766
2959
  validationCollectionsPathAndMatch(collections);
2767
2960
  if (schema2.config) {
2768
- const config = (0, import_schema_tools.validateTinaCloudSchemaConfig)(schema2.config);
2961
+ const config = (0, import_schema_tools2.validateTinaCloudSchemaConfig)(schema2.config);
2769
2962
  return {
2770
2963
  collections,
2771
2964
  config
@@ -2785,6 +2978,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2785
2978
  }).map((x) => `${x.path}${x.format || "md"}`);
2786
2979
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2787
2980
  throw new Error(
2981
+ // TODO: add a link to the docs
2788
2982
  "Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
2789
2983
  );
2790
2984
  }
@@ -2896,7 +3090,7 @@ var validateField = async (field) => {
2896
3090
  // package.json
2897
3091
  var package_default = {
2898
3092
  name: "@tinacms/graphql",
2899
- version: "1.5.7",
3093
+ version: "1.5.11",
2900
3094
  main: "dist/index.js",
2901
3095
  module: "dist/index.mjs",
2902
3096
  typings: "dist/index.d.ts",
@@ -2923,8 +3117,8 @@ var package_default = {
2923
3117
  build: "tinacms-scripts build",
2924
3118
  docs: "pnpm typedoc",
2925
3119
  serve: "pnpm nodemon dist/server.js",
2926
- test: "jest",
2927
- "test-watch": "jest --watch"
3120
+ test: "vitest run",
3121
+ "test-watch": "vitest"
2928
3122
  },
2929
3123
  dependencies: {
2930
3124
  "@iarna/toml": "^2.2.5",
@@ -2965,7 +3159,6 @@ var package_default = {
2965
3159
  "@types/estree": "^0.0.50",
2966
3160
  "@types/express": "^4.17.21",
2967
3161
  "@types/fs-extra": "^9.0.13",
2968
- "@types/jest": "^26.0.24",
2969
3162
  "@types/js-yaml": "^3.12.10",
2970
3163
  "@types/lodash.camelcase": "^4.3.9",
2971
3164
  "@types/lodash.upperfirst": "^4.3.9",
@@ -2976,13 +3169,13 @@ var package_default = {
2976
3169
  "@types/normalize-path": "^3.0.2",
2977
3170
  "@types/ws": "^7.4.7",
2978
3171
  "@types/yup": "^0.29.14",
2979
- jest: "^29.7.0",
2980
- "jest-diff": "^29.7.0",
2981
3172
  "jest-file-snapshot": "^0.5.0",
2982
- "jest-matcher-utils": "^29.7.0",
2983
3173
  "memory-level": "^1.0.0",
2984
3174
  nodemon: "3.1.4",
2985
- typescript: "^5.6.3"
3175
+ typescript: "^5.6.3",
3176
+ vite: "^4.3.9",
3177
+ vitest: "^0.32.2",
3178
+ zod: "^3.23.8"
2986
3179
  }
2987
3180
  };
2988
3181
 
@@ -2997,7 +3190,7 @@ var createSchema = async ({
2997
3190
  if (flags && flags.length > 0) {
2998
3191
  meta["flags"] = flags;
2999
3192
  }
3000
- return new import_schema_tools2.TinaSchema({
3193
+ return new import_schema_tools3.TinaSchema({
3001
3194
  version: {
3002
3195
  fullVersion: package_default.version,
3003
3196
  major,
@@ -3053,6 +3246,7 @@ var _buildFragments = async (builder, tinaSchema) => {
3053
3246
  const fragDoc = {
3054
3247
  kind: "Document",
3055
3248
  definitions: (0, import_lodash3.default)(
3249
+ // @ts-ignore
3056
3250
  extractInlineTypes(fragmentDefinitionsFields),
3057
3251
  (node) => node.name.value
3058
3252
  )
@@ -3076,6 +3270,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3076
3270
  fragName,
3077
3271
  queryName: queryListName,
3078
3272
  filterType: queryFilterTypeName,
3273
+ // look for flag to see if the data layer is enabled
3079
3274
  dataLayer: Boolean(
3080
3275
  (_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
3081
3276
  )
@@ -3085,6 +3280,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3085
3280
  const queryDoc = {
3086
3281
  kind: "Document",
3087
3282
  definitions: (0, import_lodash3.default)(
3283
+ // @ts-ignore
3088
3284
  extractInlineTypes(operationsDefinitions),
3089
3285
  (node) => node.name.value
3090
3286
  )
@@ -3173,6 +3369,7 @@ var _buildSchema = async (builder, tinaSchema) => {
3173
3369
  return {
3174
3370
  kind: "Document",
3175
3371
  definitions: (0, import_lodash3.default)(
3372
+ // @ts-ignore
3176
3373
  extractInlineTypes(definitions),
3177
3374
  (node) => node.name.value
3178
3375
  )
@@ -3377,8 +3574,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
3377
3574
  }
3378
3575
  if (Array.isArray(value)) {
3379
3576
  return value.map((v) => {
3380
- if (!v || typeof v !== "string")
3381
- return v;
3577
+ if (!v || typeof v !== "string") return v;
3382
3578
  const cleanMediaRoot = cleanUpSlashes(
3383
3579
  schema.config.media.tina.mediaRoot
3384
3580
  );
@@ -3406,8 +3602,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3406
3602
  }
3407
3603
  if (Array.isArray(value)) {
3408
3604
  return value.map((v) => {
3409
- if (!v || typeof v !== "string")
3410
- return v;
3605
+ if (!v || typeof v !== "string") return v;
3411
3606
  const strippedValue = v.replace(cleanMediaRoot, "");
3412
3607
  return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3413
3608
  });
@@ -3426,8 +3621,7 @@ var cleanUpSlashes = (path7) => {
3426
3621
  };
3427
3622
  var hasTinaMediaConfig = (schema) => {
3428
3623
  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;
3624
+ if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3431
3625
  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
3626
  return false;
3433
3627
  return true;
@@ -3471,6 +3665,7 @@ var LevelProxyHandler = {
3471
3665
  } else if (property === "sublevel") {
3472
3666
  return (...args) => {
3473
3667
  return new Proxy(
3668
+ // eslint-disable-next-line prefer-spread
3474
3669
  target[property].apply(target, args),
3475
3670
  LevelProxyHandler
3476
3671
  );
@@ -3493,7 +3688,7 @@ var import_path2 = __toESM(require("path"));
3493
3688
  var import_toml = __toESM(require("@iarna/toml"));
3494
3689
  var import_js_yaml = __toESM(require("js-yaml"));
3495
3690
  var import_gray_matter = __toESM(require("gray-matter"));
3496
- var import_schema_tools3 = require("@tinacms/schema-tools");
3691
+ var import_schema_tools4 = require("@tinacms/schema-tools");
3497
3692
  var import_micromatch = __toESM(require("micromatch"));
3498
3693
  var import_path = __toESM(require("path"));
3499
3694
 
@@ -3706,7 +3901,7 @@ var scanAllContent = async (tinaSchema, bridge, callback) => {
3706
3901
  const filesSeen = /* @__PURE__ */ new Map();
3707
3902
  const duplicateFiles = /* @__PURE__ */ new Set();
3708
3903
  await sequential(tinaSchema.getCollections(), async (collection) => {
3709
- const normalPath = (0, import_schema_tools3.normalizePath)(collection.path);
3904
+ const normalPath = (0, import_schema_tools4.normalizePath)(collection.path);
3710
3905
  const format = collection.format || "md";
3711
3906
  const documentPaths = await bridge.glob(normalPath, format);
3712
3907
  const matches = tinaSchema.getMatches({ collection });
@@ -3818,7 +4013,7 @@ var getTemplateForFile = (templateInfo, data) => {
3818
4013
  throw new Error(`Unable to determine template`);
3819
4014
  };
3820
4015
  var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo) => {
3821
- const dataString = await bridge.get((0, import_schema_tools3.normalizePath)(filepath));
4016
+ const dataString = await bridge.get((0, import_schema_tools4.normalizePath)(filepath));
3822
4017
  const data = parseFile(
3823
4018
  dataString,
3824
4019
  import_path.default.extname(filepath),
@@ -4297,7 +4492,7 @@ var FolderTreeBuilder = class {
4297
4492
  return this._tree;
4298
4493
  }
4299
4494
  update(documentPath, collectionPath) {
4300
- let folderPath = import_path2.default.dirname((0, import_schema_tools3.normalizePath)(documentPath));
4495
+ let folderPath = import_path2.default.dirname((0, import_schema_tools4.normalizePath)(documentPath));
4301
4496
  if (folderPath === ".") {
4302
4497
  folderPath = "";
4303
4498
  }
@@ -4310,7 +4505,7 @@ var FolderTreeBuilder = class {
4310
4505
  if (!this._tree[current2]) {
4311
4506
  this._tree[current2] = /* @__PURE__ */ new Set();
4312
4507
  }
4313
- this._tree[current2].add((0, import_schema_tools3.normalizePath)(import_path2.default.join(current2, part)));
4508
+ this._tree[current2].add((0, import_schema_tools4.normalizePath)(import_path2.default.join(current2, part)));
4314
4509
  parent.push(part);
4315
4510
  });
4316
4511
  const current = parent.join("/");
@@ -4349,6 +4544,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
4349
4544
  result.push({
4350
4545
  type: opType,
4351
4546
  key: `${collection.path}/${subFolderKey}.${collection.format}`,
4547
+ // replace the root with the collection path
4352
4548
  sublevel: indexSublevel,
4353
4549
  value: {}
4354
4550
  });
@@ -4436,8 +4632,17 @@ var stringEscaper = makeStringEscaper(
4436
4632
  var createResolver = (args) => {
4437
4633
  return new Resolver(args);
4438
4634
  };
4439
- var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4635
+ var resolveFieldData = async (args) => {
4440
4636
  var _a, _b;
4637
+ const {
4638
+ field: { namespace, ...field },
4639
+ rawData,
4640
+ accumulator,
4641
+ tinaSchema,
4642
+ config,
4643
+ isAudit,
4644
+ context
4645
+ } = args;
4441
4646
  if (!rawData) {
4442
4647
  return void 0;
4443
4648
  }
@@ -4464,6 +4669,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4464
4669
  case "password":
4465
4670
  accumulator[field.name] = {
4466
4671
  value: void 0,
4672
+ // never resolve the password hash
4467
4673
  passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4468
4674
  };
4469
4675
  break;
@@ -4476,9 +4682,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4476
4682
  break;
4477
4683
  case "rich-text":
4478
4684
  const tree = (0, import_mdx.parseMDX)(
4685
+ // @ts-ignore value is unknown
4479
4686
  value,
4480
4687
  field,
4481
- (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4688
+ (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema),
4689
+ context
4482
4690
  );
4483
4691
  if (((_b = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _b.type) === "invalid_markdown") {
4484
4692
  if (isAudit) {
@@ -4509,14 +4717,15 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4509
4717
  });
4510
4718
  const payload = {};
4511
4719
  await sequential(template.fields, async (field2) => {
4512
- await resolveFieldData(
4513
- field2,
4514
- item,
4515
- payload,
4720
+ await resolveFieldData({
4721
+ field: field2,
4722
+ rawData: item,
4723
+ accumulator: payload,
4516
4724
  tinaSchema,
4517
4725
  config,
4518
- isAudit
4519
- );
4726
+ isAudit,
4727
+ context
4728
+ });
4520
4729
  });
4521
4730
  const isUnion = !!field.templates;
4522
4731
  return isUnion ? {
@@ -4537,14 +4746,15 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4537
4746
  });
4538
4747
  const payload = {};
4539
4748
  await sequential(template.fields, async (field2) => {
4540
- await resolveFieldData(
4541
- field2,
4542
- value,
4543
- payload,
4749
+ await resolveFieldData({
4750
+ field: field2,
4751
+ rawData: value,
4752
+ accumulator: payload,
4544
4753
  tinaSchema,
4545
4754
  config,
4546
- isAudit
4547
- );
4755
+ isAudit,
4756
+ context
4757
+ });
4548
4758
  });
4549
4759
  const isUnion = !!field.templates;
4550
4760
  accumulator[field.name] = isUnion ? {
@@ -4558,7 +4768,8 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4558
4768
  }
4559
4769
  return accumulator;
4560
4770
  };
4561
- var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config, isAudit, hasReferences) => {
4771
+ var transformDocumentIntoPayload = async (args) => {
4772
+ const { fullPath, rawData, tinaSchema, config, isAudit, context } = args;
4562
4773
  const collection = tinaSchema.getCollection(rawData._collection);
4563
4774
  try {
4564
4775
  const template = tinaSchema.getTemplateForData({
@@ -4578,14 +4789,15 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4578
4789
  };
4579
4790
  try {
4580
4791
  await sequential(template.fields, async (field) => {
4581
- return resolveFieldData(
4792
+ return resolveFieldData({
4582
4793
  field,
4583
4794
  rawData,
4584
- data,
4795
+ accumulator: data,
4585
4796
  tinaSchema,
4586
4797
  config,
4587
- isAudit
4588
- );
4798
+ isAudit,
4799
+ context
4800
+ });
4589
4801
  });
4590
4802
  } catch (e) {
4591
4803
  throw new TinaParseDocumentError({
@@ -4612,7 +4824,7 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4612
4824
  basename,
4613
4825
  filename,
4614
4826
  extension,
4615
- hasReferences,
4827
+ hasReferences: args.hasReferences,
4616
4828
  path: fullPath,
4617
4829
  relativePath,
4618
4830
  breadcrumbs,
@@ -4654,10 +4866,12 @@ var updateObjectWithJsonPath = (obj, path7, newValue) => {
4654
4866
  var Resolver = class {
4655
4867
  constructor(init) {
4656
4868
  this.init = init;
4869
+ this.context = {};
4657
4870
  this.resolveCollection = async (args, collectionName, hasDocuments) => {
4658
4871
  const collection = this.tinaSchema.getCollection(collectionName);
4659
4872
  const extraFields = {};
4660
4873
  return {
4874
+ // return the collection and hasDocuments to resolve documents at a lower level
4661
4875
  documents: { collection, hasDocuments },
4662
4876
  ...collection,
4663
4877
  ...extraFields
@@ -4683,13 +4897,15 @@ var Resolver = class {
4683
4897
  path: rawData["__folderPath"]
4684
4898
  };
4685
4899
  } else {
4686
- return transformDocumentIntoPayload(
4900
+ this.context = { ...rawData };
4901
+ return transformDocumentIntoPayload({
4687
4902
  fullPath,
4688
4903
  rawData,
4689
- this.tinaSchema,
4690
- this.config,
4691
- this.isAudit
4692
- );
4904
+ tinaSchema: this.tinaSchema,
4905
+ config: this.config,
4906
+ isAudit: this.isAudit,
4907
+ context: this.context
4908
+ });
4693
4909
  }
4694
4910
  };
4695
4911
  this.getDocument = async (fullPath, opts = {}) => {
@@ -4697,15 +4913,17 @@ var Resolver = class {
4697
4913
  throw new Error(`fullPath must be of type string for getDocument request`);
4698
4914
  }
4699
4915
  const rawData = await this.getRaw(fullPath);
4916
+ this.context = { ...rawData };
4700
4917
  const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
4701
- return transformDocumentIntoPayload(
4918
+ return transformDocumentIntoPayload({
4702
4919
  fullPath,
4703
4920
  rawData,
4704
- this.tinaSchema,
4705
- this.config,
4706
- this.isAudit,
4921
+ tinaSchema: this.tinaSchema,
4922
+ config: this.config,
4923
+ isAudit: this.isAudit,
4924
+ context: this.context,
4707
4925
  hasReferences
4708
- );
4926
+ });
4709
4927
  };
4710
4928
  this.deleteDocument = async (fullPath) => {
4711
4929
  if (typeof fullPath !== "string") {
@@ -4744,7 +4962,9 @@ var Resolver = class {
4744
4962
  );
4745
4963
  } else {
4746
4964
  return this.buildFieldMutations(
4965
+ // @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
4747
4966
  fieldValue,
4967
+ //@ts-ignore
4748
4968
  objectTemplate,
4749
4969
  existingData
4750
4970
  );
@@ -4756,6 +4976,7 @@ var Resolver = class {
4756
4976
  fieldValue.map(async (item) => {
4757
4977
  if (typeof item === "string") {
4758
4978
  throw new Error(
4979
+ //@ts-ignore
4759
4980
  `Expected object for template value for field ${field.name}`
4760
4981
  );
4761
4982
  }
@@ -4764,16 +4985,19 @@ var Resolver = class {
4764
4985
  });
4765
4986
  const [templateName] = Object.entries(item)[0];
4766
4987
  const template = templates.find(
4988
+ //@ts-ignore
4767
4989
  (template2) => template2.name === templateName
4768
4990
  );
4769
4991
  if (!template) {
4770
4992
  throw new Error(`Expected to find template ${templateName}`);
4771
4993
  }
4772
4994
  return {
4995
+ // @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
4996
  ...await this.buildFieldMutations(
4774
4997
  item[template.name],
4775
4998
  template
4776
4999
  ),
5000
+ //@ts-ignore
4777
5001
  _template: template.name
4778
5002
  };
4779
5003
  })
@@ -4781,6 +5005,7 @@ var Resolver = class {
4781
5005
  } else {
4782
5006
  if (typeof fieldValue === "string") {
4783
5007
  throw new Error(
5008
+ //@ts-ignore
4784
5009
  `Expected object for template value for field ${field.name}`
4785
5010
  );
4786
5011
  }
@@ -4789,16 +5014,19 @@ var Resolver = class {
4789
5014
  });
4790
5015
  const [templateName] = Object.entries(fieldValue)[0];
4791
5016
  const template = templates.find(
5017
+ //@ts-ignore
4792
5018
  (template2) => template2.name === templateName
4793
5019
  );
4794
5020
  if (!template) {
4795
5021
  throw new Error(`Expected to find template ${templateName}`);
4796
5022
  }
4797
5023
  return {
5024
+ // @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
5025
  ...await this.buildFieldMutations(
4799
5026
  fieldValue[template.name],
4800
5027
  template
4801
5028
  ),
5029
+ //@ts-ignore
4802
5030
  _template: template.name
4803
5031
  };
4804
5032
  }
@@ -4838,6 +5066,7 @@ var Resolver = class {
4838
5066
  return this.getDocument(realPath);
4839
5067
  }
4840
5068
  const params = await this.buildObjectMutations(
5069
+ // @ts-ignore
4841
5070
  args.params[collection.name],
4842
5071
  collection
4843
5072
  );
@@ -4851,58 +5080,68 @@ var Resolver = class {
4851
5080
  isAddPendingDocument,
4852
5081
  isCollectionSpecific
4853
5082
  }) => {
5083
+ var _a;
4854
5084
  const doc = await this.getDocument(realPath);
4855
5085
  const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
5086
+ let values;
4856
5087
  if (isAddPendingDocument === true) {
4857
5088
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
4858
- const params2 = this.buildParams(args);
5089
+ const params = this.buildParams(args);
4859
5090
  switch (templateInfo.type) {
4860
5091
  case "object":
4861
- if (params2) {
4862
- const values = await this.buildFieldMutations(
4863
- params2,
5092
+ if (params) {
5093
+ const mutationValues = await this.buildFieldMutations(
5094
+ params,
4864
5095
  templateInfo.template,
4865
5096
  doc == null ? void 0 : doc._rawData
4866
5097
  );
4867
- await this.database.put(
4868
- realPath,
4869
- { ...oldDoc, ...values },
4870
- collection.name
4871
- );
5098
+ values = { ...oldDoc, ...mutationValues };
4872
5099
  }
4873
5100
  break;
4874
- case "union":
5101
+ case "union": {
4875
5102
  await sequential(templateInfo.templates, async (template) => {
4876
- const templateParams = params2[lastItem(template.namespace)];
5103
+ const templateParams = params[lastItem(template.namespace)];
4877
5104
  if (templateParams) {
4878
5105
  if (typeof templateParams === "string") {
4879
5106
  throw new Error(
4880
5107
  `Expected to find an object for template params, but got string`
4881
5108
  );
4882
5109
  }
4883
- const values = {
5110
+ values = {
4884
5111
  ...oldDoc,
4885
5112
  ...await this.buildFieldMutations(
5113
+ // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
4886
5114
  templateParams,
4887
5115
  template,
4888
5116
  doc == null ? void 0 : doc._rawData
4889
5117
  ),
4890
5118
  _template: lastItem(template.namespace)
4891
5119
  };
4892
- await this.database.put(realPath, values, collection.name);
4893
5120
  }
4894
5121
  });
5122
+ }
4895
5123
  }
4896
- return this.getDocument(realPath);
5124
+ } else {
5125
+ const params = await this.buildObjectMutations(
5126
+ //@ts-expect-error FIXME: Argument of type 'unknown' is not assignable to parameter of type 'FieldParams'
5127
+ isCollectionSpecific ? args.params : args.params[collection.name],
5128
+ collection,
5129
+ doc == null ? void 0 : doc._rawData
5130
+ );
5131
+ values = { ...oldDoc, ...params };
4897
5132
  }
4898
- const params = await this.buildObjectMutations(
4899
- isCollectionSpecific ? args.params : args.params[collection.name],
4900
- collection,
4901
- doc == null ? void 0 : doc._rawData
5133
+ const _tinaEmbeds = ((_a = this.context) == null ? void 0 : _a._tinaEmbeds) ? { _tinaEmbeds: this.context._tinaEmbeds } : {};
5134
+ await this.database.put(
5135
+ realPath,
5136
+ { ...values, ..._tinaEmbeds },
5137
+ collection.name
4902
5138
  );
4903
- await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
4904
5139
  return this.getDocument(realPath);
4905
5140
  };
5141
+ /**
5142
+ * Returns top-level fields which are not defined in the collection, so their
5143
+ * values are not eliminated from Tina when new values are saved
5144
+ */
4906
5145
  this.resolveLegacyValues = (oldDoc, collection) => {
4907
5146
  const legacyValues = {};
4908
5147
  Object.entries(oldDoc).forEach(([key, value]) => {
@@ -5109,6 +5348,7 @@ var Resolver = class {
5109
5348
  },
5110
5349
  collection: referencedCollection,
5111
5350
  hydrator: (path7) => path7
5351
+ // just return the path
5112
5352
  }
5113
5353
  );
5114
5354
  const { edges } = resolvedCollectionConnection;
@@ -5176,6 +5416,12 @@ var Resolver = class {
5176
5416
  }
5177
5417
  };
5178
5418
  };
5419
+ /**
5420
+ * Checks if a document has references to it
5421
+ * @param id The id of the document to check for references
5422
+ * @param c The collection to check for references
5423
+ * @returns true if the document has references, false otherwise
5424
+ */
5179
5425
  this.hasReferences = async (id, c) => {
5180
5426
  let count = 0;
5181
5427
  const deepRefs = this.tinaSchema.findReferences(c.name);
@@ -5210,6 +5456,12 @@ var Resolver = class {
5210
5456
  }
5211
5457
  return false;
5212
5458
  };
5459
+ /**
5460
+ * Finds references to a document
5461
+ * @param id the id of the document to find references to
5462
+ * @param c the collection to find references in
5463
+ * @returns references to the document in the form of a map of collection names to a list of fields that reference the document
5464
+ */
5213
5465
  this.findReferences = async (id, c) => {
5214
5466
  const references = {};
5215
5467
  const deepRefs = this.tinaSchema.findReferences(c.name);
@@ -5319,13 +5571,15 @@ var Resolver = class {
5319
5571
  break;
5320
5572
  case "rich-text":
5321
5573
  accum[fieldName] = (0, import_mdx.stringifyMDX)(
5574
+ // @ts-ignore
5322
5575
  fieldValue,
5323
5576
  field,
5324
5577
  (fieldValue2) => resolveMediaCloudToRelative(
5325
5578
  fieldValue2,
5326
5579
  this.config,
5327
5580
  this.tinaSchema.schema
5328
- )
5581
+ ),
5582
+ this.context
5329
5583
  );
5330
5584
  break;
5331
5585
  case "reference":
@@ -5337,6 +5591,27 @@ var Resolver = class {
5337
5591
  }
5338
5592
  return accum;
5339
5593
  };
5594
+ /**
5595
+ * A mutation looks nearly identical between updateDocument:
5596
+ * ```graphql
5597
+ * updateDocument(collection: $collection,relativePath: $path, params: {
5598
+ * post: {
5599
+ * title: "Hello, World"
5600
+ * }
5601
+ * })`
5602
+ * ```
5603
+ * and `updatePostDocument`:
5604
+ * ```graphql
5605
+ * updatePostDocument(relativePath: $path, params: {
5606
+ * title: "Hello, World"
5607
+ * })
5608
+ * ```
5609
+ * The problem here is that we don't know whether the payload came from `updateDocument`
5610
+ * or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
5611
+ * But we do know that when given a `args.collection` value, we can assume that
5612
+ * this was a `updateDocument` request, and thus - should grab the data
5613
+ * from the corresponding field name in the key
5614
+ */
5340
5615
  this.buildParams = (args) => {
5341
5616
  try {
5342
5617
  assertShape(
@@ -5437,7 +5712,10 @@ var resolve = async ({
5437
5712
  const graphQLSchema = (0, import_graphql5.buildASTSchema)(graphQLSchemaAst);
5438
5713
  const tinaConfig = await database.getTinaSchema();
5439
5714
  const tinaSchema = await createSchema({
5715
+ // TODO: please update all the types to import from @tinacms/schema-tools
5716
+ // @ts-ignore
5440
5717
  schema: tinaConfig,
5718
+ // @ts-ignore
5441
5719
  flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5442
5720
  });
5443
5721
  const resolver = createResolver({
@@ -5454,8 +5732,7 @@ var resolve = async ({
5454
5732
  database
5455
5733
  },
5456
5734
  typeResolver: async (source, _args, info) => {
5457
- if (source.__typename)
5458
- return source.__typename;
5735
+ if (source.__typename) return source.__typename;
5459
5736
  const namedType = (0, import_graphql5.getNamedType)(info.returnType).toString();
5460
5737
  const lookup = await database.getLookup(namedType);
5461
5738
  if (lookup.resolveType === "unionData") {
@@ -5607,11 +5884,13 @@ var resolve = async ({
5607
5884
  (0, import_lodash4.default)(
5608
5885
  params,
5609
5886
  userField.path.slice(1),
5887
+ // remove _rawData from users path
5610
5888
  users.map((u) => {
5611
5889
  if (user[idFieldName] === u[idFieldName]) {
5612
5890
  return user;
5613
5891
  }
5614
5892
  return {
5893
+ // don't overwrite other users' passwords
5615
5894
  ...u,
5616
5895
  [passwordFieldName]: {
5617
5896
  ...u[passwordFieldName],
@@ -5634,6 +5913,9 @@ var resolve = async ({
5634
5913
  }
5635
5914
  const isCreation = lookup[info.fieldName] === "create";
5636
5915
  switch (lookup.resolveType) {
5916
+ /**
5917
+ * `node(id: $id)`
5918
+ */
5637
5919
  case "nodeDocument":
5638
5920
  assertShape(
5639
5921
  args,
@@ -5665,6 +5947,7 @@ var resolve = async ({
5665
5947
  collection: args.collection,
5666
5948
  isMutation,
5667
5949
  isCreation,
5950
+ // Right now this is the only case for deletion
5668
5951
  isDeletion: info.fieldName === "deleteDocument",
5669
5952
  isFolderCreation: info.fieldName === "createFolder",
5670
5953
  isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
@@ -5674,6 +5957,9 @@ var resolve = async ({
5674
5957
  return result;
5675
5958
  }
5676
5959
  return value;
5960
+ /**
5961
+ * eg `getMovieDocument.data.actors`
5962
+ */
5677
5963
  case "multiCollectionDocumentList":
5678
5964
  if (Array.isArray(value)) {
5679
5965
  return {
@@ -5685,7 +5971,15 @@ var resolve = async ({
5685
5971
  }
5686
5972
  if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
5687
5973
  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") {
5974
+ if (
5975
+ // 1. Make sure that the filter exists
5976
+ typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
5977
+ // @ts-ignore
5978
+ 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
5979
+ // @ts-ignore
5980
+ Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
5981
+ typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
5982
+ ) {
5689
5983
  filter = args.filter[value.collection.name];
5690
5984
  }
5691
5985
  return resolver.resolveCollectionConnection({
@@ -5693,12 +5987,20 @@ var resolve = async ({
5693
5987
  ...args,
5694
5988
  filter
5695
5989
  },
5990
+ // @ts-ignore
5696
5991
  collection: value.collection
5697
5992
  });
5698
5993
  }
5699
5994
  throw new Error(
5700
5995
  `Expected an array for result of ${info.fieldName} at ${info.path}`
5701
5996
  );
5997
+ /**
5998
+ * Collections-specific getter
5999
+ * eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
6000
+ *
6001
+ * if coming from a query result
6002
+ * the field will be `node`
6003
+ */
5702
6004
  case "collectionDocument": {
5703
6005
  if (value) {
5704
6006
  return value;
@@ -5713,11 +6015,32 @@ var resolve = async ({
5713
6015
  });
5714
6016
  return result;
5715
6017
  }
6018
+ /**
6019
+ * Collections-specific list getter
6020
+ * eg. `getPageList`
6021
+ */
5716
6022
  case "collectionDocumentList":
5717
6023
  return resolver.resolveCollectionConnection({
5718
6024
  args,
5719
6025
  collection: tinaSchema.getCollection(lookup.collection)
5720
6026
  });
6027
+ /**
6028
+ * A polymorphic data set, it can be from a document's data
6029
+ * of any nested object which can be one of many shapes
6030
+ *
6031
+ * ```graphql
6032
+ * getPostDocument(relativePath: $relativePath) {
6033
+ * data {...} <- this part
6034
+ * }
6035
+ * ```
6036
+ * ```graphql
6037
+ * getBlockDocument(relativePath: $relativePath) {
6038
+ * data {
6039
+ * blocks {...} <- or this part
6040
+ * }
6041
+ * }
6042
+ * ```
6043
+ */
5721
6044
  case "unionData":
5722
6045
  if (!value) {
5723
6046
  if (args.relativePath) {
@@ -5782,8 +6105,7 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
5782
6105
  this.port = port || 9e3;
5783
6106
  }
5784
6107
  openConnection() {
5785
- if (this._connected)
5786
- return;
6108
+ if (this._connected) return;
5787
6109
  const socket = (0, import_net.connect)(this.port);
5788
6110
  (0, import_readable_stream.pipeline)(socket, this.createRpcStream(), socket, () => {
5789
6111
  this._connected = false;
@@ -5903,7 +6225,7 @@ var Database = class {
5903
6225
  const contentObject = await level.sublevel(
5904
6226
  CONTENT_ROOT_PREFIX,
5905
6227
  SUBLEVEL_OPTIONS
5906
- ).get((0, import_schema_tools3.normalizePath)(filepath));
6228
+ ).get((0, import_schema_tools4.normalizePath)(filepath));
5907
6229
  if (!contentObject) {
5908
6230
  throw new NotFoundError(`Unable to find record ${filepath}`);
5909
6231
  }
@@ -5928,7 +6250,7 @@ var Database = class {
5928
6250
  );
5929
6251
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
5930
6252
  const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
5931
- const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
6253
+ const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
5932
6254
  if (!(collection == null ? void 0 : collection.isDetached)) {
5933
6255
  if (this.bridge) {
5934
6256
  await this.bridge.put(normalizedPath, stringifiedFile);
@@ -5964,6 +6286,7 @@ var Database = class {
5964
6286
  "put",
5965
6287
  level
5966
6288
  ),
6289
+ // folder indices
5967
6290
  ...makeIndexOpsForDocument(
5968
6291
  normalizedPath,
5969
6292
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -5986,6 +6309,7 @@ var Database = class {
5986
6309
  "del",
5987
6310
  level
5988
6311
  ),
6312
+ // folder indices
5989
6313
  ...makeIndexOpsForDocument(
5990
6314
  normalizedPath,
5991
6315
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6025,7 +6349,7 @@ var Database = class {
6025
6349
  );
6026
6350
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
6027
6351
  }
6028
- const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
6352
+ const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6029
6353
  const dataFields = await this.formatBodyOnPayload(filepath, data);
6030
6354
  const collection = await this.collectionForPath(filepath);
6031
6355
  if (!collection) {
@@ -6080,6 +6404,7 @@ var Database = class {
6080
6404
  "put",
6081
6405
  level
6082
6406
  ),
6407
+ // folder indices
6083
6408
  ...makeIndexOpsForDocument(
6084
6409
  normalizedPath,
6085
6410
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6102,6 +6427,7 @@ var Database = class {
6102
6427
  "del",
6103
6428
  level
6104
6429
  ),
6430
+ // folder indices
6105
6431
  ...makeIndexOpsForDocument(
6106
6432
  normalizedPath,
6107
6433
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6179,6 +6505,7 @@ var Database = class {
6179
6505
  aliasedData,
6180
6506
  extension,
6181
6507
  writeTemplateKey,
6508
+ //templateInfo.type === 'union',
6182
6509
  {
6183
6510
  frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6184
6511
  frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
@@ -6196,7 +6523,7 @@ var Database = class {
6196
6523
  };
6197
6524
  this.getLookup = async (returnType) => {
6198
6525
  await this.initLevel();
6199
- const lookupPath = (0, import_schema_tools3.normalizePath)(
6526
+ const lookupPath = (0, import_schema_tools4.normalizePath)(
6200
6527
  import_node_path.default.join(this.getGeneratedFolder(), `_lookup.json`)
6201
6528
  );
6202
6529
  if (!this._lookup) {
@@ -6209,7 +6536,7 @@ var Database = class {
6209
6536
  };
6210
6537
  this.getGraphQLSchema = async () => {
6211
6538
  await this.initLevel();
6212
- const graphqlPath = (0, import_schema_tools3.normalizePath)(
6539
+ const graphqlPath = (0, import_schema_tools4.normalizePath)(
6213
6540
  import_node_path.default.join(this.getGeneratedFolder(), `_graphql.json`)
6214
6541
  );
6215
6542
  return await this.contentLevel.sublevel(
@@ -6217,11 +6544,12 @@ var Database = class {
6217
6544
  SUBLEVEL_OPTIONS
6218
6545
  ).get(graphqlPath);
6219
6546
  };
6547
+ //TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
6220
6548
  this.getGraphQLSchemaFromBridge = async () => {
6221
6549
  if (!this.bridge) {
6222
6550
  throw new Error(`No bridge configured`);
6223
6551
  }
6224
- const graphqlPath = (0, import_schema_tools3.normalizePath)(
6552
+ const graphqlPath = (0, import_schema_tools4.normalizePath)(
6225
6553
  import_node_path.default.join(this.getGeneratedFolder(), `_graphql.json`)
6226
6554
  );
6227
6555
  const _graphql = await this.bridge.get(graphqlPath);
@@ -6229,7 +6557,7 @@ var Database = class {
6229
6557
  };
6230
6558
  this.getTinaSchema = async (level) => {
6231
6559
  await this.initLevel();
6232
- const schemaPath = (0, import_schema_tools3.normalizePath)(
6560
+ const schemaPath = (0, import_schema_tools4.normalizePath)(
6233
6561
  import_node_path.default.join(this.getGeneratedFolder(), `_schema.json`)
6234
6562
  );
6235
6563
  return await (level || this.contentLevel).sublevel(
@@ -6245,7 +6573,7 @@ var Database = class {
6245
6573
  const schema = existingSchema || await this.getTinaSchema(level || this.contentLevel);
6246
6574
  if (!schema) {
6247
6575
  throw new Error(
6248
- `Unable to get schema from level db: ${(0, import_schema_tools3.normalizePath)(
6576
+ `Unable to get schema from level db: ${(0, import_schema_tools4.normalizePath)(
6249
6577
  import_node_path.default.join(this.getGeneratedFolder(), `_schema.json`)
6250
6578
  )}`
6251
6579
  );
@@ -6263,6 +6591,7 @@ var Database = class {
6263
6591
  for (const collection of collections) {
6264
6592
  const indexDefinitions = {
6265
6593
  [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
6594
+ // provide a default sort key which is the file sort
6266
6595
  };
6267
6596
  if (collection.fields) {
6268
6597
  for (const field of collection.fields) {
@@ -6461,7 +6790,7 @@ var Database = class {
6461
6790
  try {
6462
6791
  lookup = lookupFromLockFile || JSON.parse(
6463
6792
  await this.bridge.get(
6464
- (0, import_schema_tools3.normalizePath)(
6793
+ (0, import_schema_tools4.normalizePath)(
6465
6794
  import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")
6466
6795
  )
6467
6796
  )
@@ -6486,15 +6815,15 @@ var Database = class {
6486
6815
  }
6487
6816
  const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
6488
6817
  await contentRootLevel.put(
6489
- (0, import_schema_tools3.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_graphql.json")),
6818
+ (0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_graphql.json")),
6490
6819
  graphQLSchema
6491
6820
  );
6492
6821
  await contentRootLevel.put(
6493
- (0, import_schema_tools3.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_schema.json")),
6822
+ (0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_schema.json")),
6494
6823
  tinaSchema.schema
6495
6824
  );
6496
6825
  await contentRootLevel.put(
6497
- (0, import_schema_tools3.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")),
6826
+ (0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")),
6498
6827
  lookup
6499
6828
  );
6500
6829
  const result = await this._indexAllContent(
@@ -6587,12 +6916,12 @@ var Database = class {
6587
6916
  if (collection == null ? void 0 : collection.isDetached) {
6588
6917
  level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
6589
6918
  }
6590
- const itemKey = (0, import_schema_tools3.normalizePath)(filepath);
6919
+ const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6591
6920
  const rootSublevel = level.sublevel(
6592
6921
  CONTENT_ROOT_PREFIX,
6593
6922
  SUBLEVEL_OPTIONS
6594
6923
  );
6595
- const item = await rootSublevel.get(itemKey);
6924
+ const item = await rootSublevel.get(normalizedPath);
6596
6925
  if (item) {
6597
6926
  const folderTreeBuilder = new FolderTreeBuilder();
6598
6927
  const folderKey = folderTreeBuilder.update(
@@ -6601,15 +6930,16 @@ var Database = class {
6601
6930
  );
6602
6931
  await this.contentLevel.batch([
6603
6932
  ...makeIndexOpsForDocument(
6604
- filepath,
6933
+ normalizedPath,
6605
6934
  collection.name,
6606
6935
  collectionIndexDefinitions,
6607
6936
  item,
6608
6937
  "del",
6609
6938
  level
6610
6939
  ),
6940
+ // folder indices
6611
6941
  ...makeIndexOpsForDocument(
6612
- filepath,
6942
+ normalizedPath,
6613
6943
  `${collection.name}_${folderKey}`,
6614
6944
  collectionIndexDefinitions,
6615
6945
  item,
@@ -6618,17 +6948,17 @@ var Database = class {
6618
6948
  ),
6619
6949
  {
6620
6950
  type: "del",
6621
- key: itemKey,
6951
+ key: normalizedPath,
6622
6952
  sublevel: rootSublevel
6623
6953
  }
6624
6954
  ]);
6625
6955
  }
6626
6956
  if (!(collection == null ? void 0 : collection.isDetached)) {
6627
6957
  if (this.bridge) {
6628
- await this.bridge.delete((0, import_schema_tools3.normalizePath)(filepath));
6958
+ await this.bridge.delete(normalizedPath);
6629
6959
  }
6630
6960
  try {
6631
- await this.onDelete((0, import_schema_tools3.normalizePath)(filepath));
6961
+ await this.onDelete(normalizedPath);
6632
6962
  } catch (e) {
6633
6963
  throw new import_graphql6.GraphQLError(
6634
6964
  `Error running onDelete hook for ${filepath}: ${e}`,
@@ -6762,6 +7092,9 @@ var Database = class {
6762
7092
  info: templateInfo
6763
7093
  };
6764
7094
  }
7095
+ /**
7096
+ * Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
7097
+ */
6765
7098
  clearCache() {
6766
7099
  this.tinaSchema = null;
6767
7100
  this._lookup = null;
@@ -6843,7 +7176,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
6843
7176
  if (passwordFields == null ? void 0 : passwordFields.length) {
6844
7177
  await hashPasswordValues(aliasedData, passwordFields);
6845
7178
  }
6846
- const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
7179
+ const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6847
7180
  const folderKey = folderTreeBuilder.update(
6848
7181
  normalizedPath,
6849
7182
  collectionPath || ""
@@ -6858,6 +7191,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
6858
7191
  "put",
6859
7192
  level
6860
7193
  ),
7194
+ // folder indexes
6861
7195
  ...makeIndexOpsForDocument(
6862
7196
  normalizedPath,
6863
7197
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6923,7 +7257,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
6923
7257
  );
6924
7258
  const folderTreeBuilder = new FolderTreeBuilder();
6925
7259
  await sequential(documentPaths, async (filepath) => {
6926
- const itemKey = (0, import_schema_tools3.normalizePath)(filepath);
7260
+ const itemKey = (0, import_schema_tools4.normalizePath)(filepath);
6927
7261
  const item = await rootLevel.get(itemKey);
6928
7262
  if (item) {
6929
7263
  const folderKey = folderTreeBuilder.update(
@@ -6943,6 +7277,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
6943
7277
  "del",
6944
7278
  database.contentLevel
6945
7279
  ),
7280
+ // folder indexes
6946
7281
  ...makeIndexOpsForDocument(
6947
7282
  itemKey,
6948
7283
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -7009,14 +7344,14 @@ var getChangedFiles = async ({
7009
7344
  const rootDir = await findGitRoot(dir);
7010
7345
  let pathPrefix = "";
7011
7346
  if (rootDir !== dir) {
7012
- pathPrefix = (0, import_schema_tools3.normalizePath)(dir.substring(rootDir.length + 1));
7347
+ pathPrefix = (0, import_schema_tools4.normalizePath)(dir.substring(rootDir.length + 1));
7013
7348
  }
7014
7349
  await import_isomorphic_git.default.walk({
7015
7350
  fs: fs4,
7016
7351
  dir: rootDir,
7017
7352
  trees: [import_isomorphic_git.default.TREE({ ref: from }), import_isomorphic_git.default.TREE({ ref: to })],
7018
7353
  map: async function(filename, [A, B]) {
7019
- const relativePath = (0, import_schema_tools3.normalizePath)(filename).substring(pathPrefix.length);
7354
+ const relativePath = (0, import_schema_tools4.normalizePath)(filename).substring(pathPrefix.length);
7020
7355
  let matches = false;
7021
7356
  for (const [key, matcher] of Object.entries(pathFilter)) {
7022
7357
  if (relativePath.startsWith(key)) {
@@ -7158,17 +7493,26 @@ var IsomorphicBridge = class {
7158
7493
  getAuthor() {
7159
7494
  return {
7160
7495
  ...this.author,
7161
- timestamp: Math.round(new Date().getTime() / 1e3),
7496
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7162
7497
  timezoneOffset: 0
7163
7498
  };
7164
7499
  }
7165
7500
  getCommitter() {
7166
7501
  return {
7167
7502
  ...this.committer,
7168
- timestamp: Math.round(new Date().getTime() / 1e3),
7503
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7169
7504
  timezoneOffset: 0
7170
7505
  };
7171
7506
  }
7507
+ /**
7508
+ * Recursively populate paths matching `pattern` for the given `entry`
7509
+ *
7510
+ * @param pattern - pattern to filter paths by
7511
+ * @param entry - TreeEntry to start building list from
7512
+ * @param path - base path
7513
+ * @param results
7514
+ * @private
7515
+ */
7172
7516
  async listEntries({
7173
7517
  pattern,
7174
7518
  entry,
@@ -7201,6 +7545,15 @@ var IsomorphicBridge = class {
7201
7545
  });
7202
7546
  }
7203
7547
  }
7548
+ /**
7549
+ * For the specified path, returns an object with an array containing the parts of the path (pathParts)
7550
+ * and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
7551
+ * pathEntries are placeholders for non-existent entries.
7552
+ *
7553
+ * @param path - path being resolved
7554
+ * @param ref - ref to resolve path entries for
7555
+ * @private
7556
+ */
7204
7557
  async resolvePathEntries(path7, ref) {
7205
7558
  let pathParts = path7.split("/");
7206
7559
  const result = await import_isomorphic_git2.default.walk({
@@ -7231,6 +7584,17 @@ var IsomorphicBridge = class {
7231
7584
  }
7232
7585
  return { pathParts, pathEntries };
7233
7586
  }
7587
+ /**
7588
+ * Updates tree entry and associated parent tree entries
7589
+ *
7590
+ * @param existingOid - the existing OID
7591
+ * @param updatedOid - the updated OID
7592
+ * @param path - the path of the entry being updated
7593
+ * @param type - the type of the entry being updated (blob or tree)
7594
+ * @param pathEntries - parent path entries
7595
+ * @param pathParts - parent path parts
7596
+ * @private
7597
+ */
7234
7598
  async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
7235
7599
  const lastIdx = pathEntries.length - 1;
7236
7600
  const parentEntry = pathEntries[lastIdx];
@@ -7286,6 +7650,13 @@ var IsomorphicBridge = class {
7286
7650
  );
7287
7651
  }
7288
7652
  }
7653
+ /**
7654
+ * Creates a commit for the specified tree and updates the specified ref to point to the commit
7655
+ *
7656
+ * @param treeSha - sha of the new tree
7657
+ * @param ref - the ref that should be updated
7658
+ * @private
7659
+ */
7289
7660
  async commitTree(treeSha, ref) {
7290
7661
  const commitSha = await import_isomorphic_git2.default.writeCommit({
7291
7662
  ...this.isomorphicConfig,
@@ -7298,6 +7669,7 @@ var IsomorphicBridge = class {
7298
7669
  })
7299
7670
  ],
7300
7671
  message: this.commitMessage,
7672
+ // TODO these should be configurable
7301
7673
  author: this.getAuthor(),
7302
7674
  committer: this.getCommitter()
7303
7675
  }
@@ -7536,5 +7908,5 @@ var buildSchema = async (config, flags) => {
7536
7908
  transformDocument,
7537
7909
  transformDocumentIntoPayload
7538
7910
  });
7539
- //! Replaces _.flattenDeep()
7540
7911
  //! Replaces _.get()
7912
+ //! Replaces _.flattenDeep()