@tinacms/graphql 0.0.0-c8b1d84-20241003015733 → 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.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: {
@@ -148,6 +161,15 @@ var SysFieldDefinition = {
148
161
  arguments: [],
149
162
  directives: []
150
163
  },
164
+ {
165
+ kind: "Field",
166
+ name: {
167
+ kind: "Name",
168
+ value: "hasReferences"
169
+ },
170
+ arguments: [],
171
+ directives: []
172
+ },
151
173
  {
152
174
  kind: "Field",
153
175
  name: {
@@ -188,6 +210,10 @@ var SysFieldDefinition = {
188
210
  }
189
211
  };
190
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
+ */
191
217
  FormFieldBuilder: ({
192
218
  name,
193
219
  additionalFields
@@ -411,6 +437,8 @@ var astBuilder = {
411
437
  kind: "Name",
412
438
  value: name
413
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
414
442
  fields
415
443
  }),
416
444
  UnionTypeDefinition: ({
@@ -423,6 +451,8 @@ var astBuilder = {
423
451
  value: name
424
452
  },
425
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
426
456
  types: types.map((name2) => ({
427
457
  kind: "NamedType",
428
458
  name: {
@@ -519,8 +549,11 @@ var astBuilder = {
519
549
  string: "String",
520
550
  boolean: "Boolean",
521
551
  number: "Float",
552
+ // FIXME - needs to be float or int
522
553
  datetime: "String",
554
+ // FIXME
523
555
  image: "String",
556
+ // FIXME
524
557
  text: "String"
525
558
  };
526
559
  return scalars[type];
@@ -1019,8 +1052,7 @@ var astBuilder = {
1019
1052
  }
1020
1053
  };
1021
1054
  var capitalize = (s) => {
1022
- if (typeof s !== "string")
1023
- return "";
1055
+ if (typeof s !== "string") return "";
1024
1056
  return s.charAt(0).toUpperCase() + s.slice(1);
1025
1057
  };
1026
1058
  var extractInlineTypes = (item) => {
@@ -1063,41 +1095,6 @@ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
1063
1095
  yield maybeNode;
1064
1096
  visited.add(maybeNode);
1065
1097
  }
1066
- function addNamespaceToSchema(maybeNode, namespace = []) {
1067
- if (typeof maybeNode === "string") {
1068
- return maybeNode;
1069
- }
1070
- if (typeof maybeNode === "boolean") {
1071
- return maybeNode;
1072
- }
1073
- const newNode = maybeNode;
1074
- const keys = Object.keys(maybeNode);
1075
- Object.values(maybeNode).map((m, index) => {
1076
- const key = keys[index];
1077
- if (Array.isArray(m)) {
1078
- newNode[key] = m.map((element) => {
1079
- if (!element) {
1080
- return;
1081
- }
1082
- if (!element.hasOwnProperty("name")) {
1083
- return element;
1084
- }
1085
- const value = element.name || element.value;
1086
- return addNamespaceToSchema(element, [...namespace, value]);
1087
- });
1088
- } else {
1089
- if (!m) {
1090
- return;
1091
- }
1092
- if (!m.hasOwnProperty("name")) {
1093
- newNode[key] = m;
1094
- } else {
1095
- newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
1096
- }
1097
- }
1098
- });
1099
- return { ...newNode, namespace };
1100
- }
1101
1098
  var generateNamespacedFieldName = (names, suffix = "") => {
1102
1099
  return (suffix ? [...names, suffix] : names).map(capitalize).join("");
1103
1100
  };
@@ -1257,6 +1254,11 @@ var scalarDefinitions = [
1257
1254
  required: true,
1258
1255
  type: astBuilder.TYPES.String
1259
1256
  }),
1257
+ astBuilder.FieldDefinition({
1258
+ name: "hasReferences",
1259
+ required: false,
1260
+ type: astBuilder.TYPES.Boolean
1261
+ }),
1260
1262
  astBuilder.FieldDefinition({
1261
1263
  name: "breadcrumbs",
1262
1264
  required: true,
@@ -1471,6 +1473,19 @@ var Builder = class {
1471
1473
  this.addToLookupMap = (lookup) => {
1472
1474
  this.lookupMap[lookup.type] = lookup;
1473
1475
  };
1476
+ /**
1477
+ * ```graphql
1478
+ * # ex.
1479
+ * {
1480
+ * getCollection(collection: $collection) {
1481
+ * name
1482
+ * documents {...}
1483
+ * }
1484
+ * }
1485
+ * ```
1486
+ *
1487
+ * @param collections
1488
+ */
1474
1489
  this.buildCollectionDefinition = async (collections) => {
1475
1490
  const name = "collection";
1476
1491
  const typeName = "Collection";
@@ -1541,6 +1556,19 @@ var Builder = class {
1541
1556
  required: true
1542
1557
  });
1543
1558
  };
1559
+ /**
1560
+ * ```graphql
1561
+ * # ex.
1562
+ * {
1563
+ * getCollections {
1564
+ * name
1565
+ * documents {...}
1566
+ * }
1567
+ * }
1568
+ * ```
1569
+ *
1570
+ * @param collections
1571
+ */
1544
1572
  this.buildMultiCollectionDefinition = async (collections) => {
1545
1573
  const name = "collections";
1546
1574
  const typeName = "Collection";
@@ -1551,6 +1579,17 @@ var Builder = class {
1551
1579
  required: true
1552
1580
  });
1553
1581
  };
1582
+ /**
1583
+ * ```graphql
1584
+ * # ex.
1585
+ * {
1586
+ * node(id: $id) {
1587
+ * id
1588
+ * data {...}
1589
+ * }
1590
+ * }
1591
+ * ```
1592
+ */
1554
1593
  this.multiNodeDocument = async () => {
1555
1594
  const name = "node";
1556
1595
  const args = [
@@ -1571,6 +1610,19 @@ var Builder = class {
1571
1610
  required: true
1572
1611
  });
1573
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
+ */
1574
1626
  this.multiCollectionDocument = async (collections) => {
1575
1627
  const name = "document";
1576
1628
  const args = [
@@ -1596,6 +1648,19 @@ var Builder = class {
1596
1648
  required: true
1597
1649
  });
1598
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
+ */
1599
1664
  this.addMultiCollectionDocumentMutation = async () => {
1600
1665
  return astBuilder.FieldDefinition({
1601
1666
  name: "addPendingDocument",
@@ -1620,6 +1685,19 @@ var Builder = class {
1620
1685
  type: astBuilder.TYPES.MultiCollectionDocument
1621
1686
  });
1622
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
+ */
1623
1701
  this.buildCreateCollectionDocumentMutation = async (collections) => {
1624
1702
  return astBuilder.FieldDefinition({
1625
1703
  name: "createDocument",
@@ -1647,6 +1725,19 @@ var Builder = class {
1647
1725
  type: astBuilder.TYPES.MultiCollectionDocument
1648
1726
  });
1649
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
+ */
1650
1741
  this.buildUpdateCollectionDocumentMutation = async (collections) => {
1651
1742
  return astBuilder.FieldDefinition({
1652
1743
  name: "updateDocument",
@@ -1674,6 +1765,19 @@ var Builder = class {
1674
1765
  type: astBuilder.TYPES.MultiCollectionDocument
1675
1766
  });
1676
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
+ */
1677
1781
  this.buildDeleteCollectionDocumentMutation = async (collections) => {
1678
1782
  return astBuilder.FieldDefinition({
1679
1783
  name: "deleteDocument",
@@ -1693,6 +1797,19 @@ var Builder = class {
1693
1797
  type: astBuilder.TYPES.MultiCollectionDocument
1694
1798
  });
1695
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
+ */
1696
1813
  this.buildCreateCollectionFolderMutation = async () => {
1697
1814
  return astBuilder.FieldDefinition({
1698
1815
  name: "createFolder",
@@ -1712,6 +1829,19 @@ var Builder = class {
1712
1829
  type: astBuilder.TYPES.MultiCollectionDocument
1713
1830
  });
1714
1831
  };
1832
+ /**
1833
+ * ```graphql
1834
+ * # ex.
1835
+ * {
1836
+ * getPostDocument(relativePath: $relativePath) {
1837
+ * id
1838
+ * data {...}
1839
+ * }
1840
+ * }
1841
+ * ```
1842
+ *
1843
+ * @param collection
1844
+ */
1715
1845
  this.collectionDocument = async (collection) => {
1716
1846
  const name = NAMER.queryName([collection.name]);
1717
1847
  const type = await this._buildCollectionDocumentType(collection);
@@ -1772,6 +1902,20 @@ var Builder = class {
1772
1902
  const args = [];
1773
1903
  return astBuilder.FieldDefinition({ type, name, args, required: false });
1774
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
+ */
1775
1919
  this.collectionFragment = async (collection) => {
1776
1920
  const name = NAMER.dataTypeName(collection.namespace);
1777
1921
  const fragmentName = NAMER.fragmentName(collection.namespace);
@@ -1785,6 +1929,20 @@ var Builder = class {
1785
1929
  selections: filterSelections(selections)
1786
1930
  });
1787
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
+ * */
1788
1946
  this._getCollectionFragmentSelections = async (collection, depth) => {
1789
1947
  var _a;
1790
1948
  const selections = [];
@@ -1868,9 +2026,9 @@ var Builder = class {
1868
2026
  ]
1869
2027
  });
1870
2028
  }
2029
+ // TODO: Should we throw here?
1871
2030
  case "reference":
1872
- if (depth >= this.maxDepth)
1873
- return false;
2031
+ if (depth >= this.maxDepth) return false;
1874
2032
  if (!("collections" in field)) {
1875
2033
  return false;
1876
2034
  }
@@ -1902,6 +2060,7 @@ var Builder = class {
1902
2060
  name: field.name,
1903
2061
  selections: [
1904
2062
  ...selections,
2063
+ // This is ... on Document { id }
1905
2064
  {
1906
2065
  kind: "InlineFragment",
1907
2066
  typeCondition: {
@@ -1932,6 +2091,19 @@ var Builder = class {
1932
2091
  });
1933
2092
  }
1934
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
+ */
1935
2107
  this.updateCollectionDocumentMutation = async (collection) => {
1936
2108
  return astBuilder.FieldDefinition({
1937
2109
  type: await this._buildCollectionDocumentType(collection),
@@ -1951,6 +2123,19 @@ var Builder = class {
1951
2123
  ]
1952
2124
  });
1953
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
+ */
1954
2139
  this.createCollectionDocumentMutation = async (collection) => {
1955
2140
  return astBuilder.FieldDefinition({
1956
2141
  type: await this._buildCollectionDocumentType(collection),
@@ -1970,6 +2155,22 @@ var Builder = class {
1970
2155
  ]
1971
2156
  });
1972
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
+ */
1973
2174
  this.collectionDocumentList = async (collection) => {
1974
2175
  const connectionName = NAMER.referenceConnectionType(collection.namespace);
1975
2176
  this.addToLookupMap({
@@ -1985,6 +2186,10 @@ var Builder = class {
1985
2186
  collection
1986
2187
  });
1987
2188
  };
2189
+ /**
2190
+ * GraphQL type definitions which remain unchanged regardless
2191
+ * of the supplied Tina schema. Ex. "node" interface
2192
+ */
1988
2193
  this.buildStaticDefinitions = () => staticDefinitions;
1989
2194
  this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
1990
2195
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
@@ -2489,6 +2694,7 @@ var Builder = class {
2489
2694
  name: NAMER.dataFilterTypeName(namespace),
2490
2695
  fields: await sequential(collections, async (collection2) => {
2491
2696
  return astBuilder.InputValueDefinition({
2697
+ // @ts-ignore
2492
2698
  name: collection2.name,
2493
2699
  type: NAMER.dataFilterTypeName(collection2.namespace)
2494
2700
  });
@@ -2678,7 +2884,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2678
2884
  });
2679
2885
  };
2680
2886
  var _a, _b, _c, _d;
2681
- 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;
2682
2889
  this.tinaSchema = config.tinaSchema;
2683
2890
  this.lookupMap = {};
2684
2891
  }
@@ -2689,8 +2896,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2689
2896
  selections.push(field);
2690
2897
  });
2691
2898
  const filteredSelections = filterSelections(selections);
2692
- if (!filteredSelections.length)
2693
- return false;
2899
+ if (!filteredSelections.length) return false;
2694
2900
  return astBuilder.InlineFragmentDefinition({
2695
2901
  selections: filteredSelections,
2696
2902
  name: NAMER.dataTypeName(template.namespace)
@@ -2724,12 +2930,13 @@ var filterSelections = (arr) => {
2724
2930
  };
2725
2931
 
2726
2932
  // src/schema/createSchema.ts
2727
- var import_schema_tools2 = require("@tinacms/schema-tools");
2933
+ var import_schema_tools3 = require("@tinacms/schema-tools");
2728
2934
 
2729
2935
  // src/schema/validate.ts
2936
+ var import_schema_tools = require("@tinacms/schema-tools");
2730
2937
  var import_lodash2 = __toESM(require("lodash.clonedeep"));
2731
2938
  var yup2 = __toESM(require("yup"));
2732
- var import_schema_tools = require("@tinacms/schema-tools");
2939
+ var import_schema_tools2 = require("@tinacms/schema-tools");
2733
2940
  var FIELD_TYPES = [
2734
2941
  "string",
2735
2942
  "number",
@@ -2742,7 +2949,7 @@ var FIELD_TYPES = [
2742
2949
  "password"
2743
2950
  ];
2744
2951
  var validateSchema = async (schema) => {
2745
- const schema2 = addNamespaceToSchema(
2952
+ const schema2 = (0, import_schema_tools.addNamespaceToSchema)(
2746
2953
  (0, import_lodash2.default)(schema)
2747
2954
  );
2748
2955
  const collections = await sequential(
@@ -2751,7 +2958,7 @@ var validateSchema = async (schema) => {
2751
2958
  );
2752
2959
  validationCollectionsPathAndMatch(collections);
2753
2960
  if (schema2.config) {
2754
- const config = (0, import_schema_tools.validateTinaCloudSchemaConfig)(schema2.config);
2961
+ const config = (0, import_schema_tools2.validateTinaCloudSchemaConfig)(schema2.config);
2755
2962
  return {
2756
2963
  collections,
2757
2964
  config
@@ -2771,6 +2978,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2771
2978
  }).map((x) => `${x.path}${x.format || "md"}`);
2772
2979
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2773
2980
  throw new Error(
2981
+ // TODO: add a link to the docs
2774
2982
  "Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
2775
2983
  );
2776
2984
  }
@@ -2882,7 +3090,7 @@ var validateField = async (field) => {
2882
3090
  // package.json
2883
3091
  var package_default = {
2884
3092
  name: "@tinacms/graphql",
2885
- version: "1.5.4",
3093
+ version: "1.5.10",
2886
3094
  main: "dist/index.js",
2887
3095
  module: "dist/index.mjs",
2888
3096
  typings: "dist/index.d.ts",
@@ -2909,8 +3117,7 @@ var package_default = {
2909
3117
  build: "tinacms-scripts build",
2910
3118
  docs: "pnpm typedoc",
2911
3119
  serve: "pnpm nodemon dist/server.js",
2912
- test: "jest",
2913
- "test-watch": "jest --watch"
3120
+ test: "vitest"
2914
3121
  },
2915
3122
  dependencies: {
2916
3123
  "@iarna/toml": "^2.2.5",
@@ -2926,7 +3133,7 @@ var package_default = {
2926
3133
  "isomorphic-git": "^1.27.1",
2927
3134
  "js-sha1": "^0.6.0",
2928
3135
  "js-yaml": "^3.14.1",
2929
- "jsonpath-plus": "^6.0.1",
3136
+ "jsonpath-plus": "10.1.0",
2930
3137
  "lodash.clonedeep": "^4.5.0",
2931
3138
  "lodash.set": "^4.3.2",
2932
3139
  "lodash.uniqby": "^4.7.0",
@@ -2951,24 +3158,23 @@ var package_default = {
2951
3158
  "@types/estree": "^0.0.50",
2952
3159
  "@types/express": "^4.17.21",
2953
3160
  "@types/fs-extra": "^9.0.13",
2954
- "@types/jest": "^26.0.24",
2955
3161
  "@types/js-yaml": "^3.12.10",
2956
3162
  "@types/lodash.camelcase": "^4.3.9",
2957
3163
  "@types/lodash.upperfirst": "^4.3.9",
2958
3164
  "@types/lru-cache": "^5.1.1",
2959
3165
  "@types/mdast": "^3.0.15",
2960
3166
  "@types/micromatch": "^4.0.9",
2961
- "@types/node": "^22.7.4",
3167
+ "@types/node": "^22.9.0",
2962
3168
  "@types/normalize-path": "^3.0.2",
2963
3169
  "@types/ws": "^7.4.7",
2964
3170
  "@types/yup": "^0.29.14",
2965
- jest: "^29.7.0",
2966
- "jest-diff": "^29.7.0",
2967
3171
  "jest-file-snapshot": "^0.5.0",
2968
- "jest-matcher-utils": "^29.7.0",
2969
3172
  "memory-level": "^1.0.0",
2970
3173
  nodemon: "3.1.4",
2971
- typescript: "^5.6.2"
3174
+ typescript: "^5.6.3",
3175
+ vite: "^4.3.9",
3176
+ vitest: "^0.32.2",
3177
+ zod: "^3.23.8"
2972
3178
  }
2973
3179
  };
2974
3180
 
@@ -2983,7 +3189,7 @@ var createSchema = async ({
2983
3189
  if (flags && flags.length > 0) {
2984
3190
  meta["flags"] = flags;
2985
3191
  }
2986
- return new import_schema_tools2.TinaSchema({
3192
+ return new import_schema_tools3.TinaSchema({
2987
3193
  version: {
2988
3194
  fullVersion: package_default.version,
2989
3195
  major,
@@ -3039,6 +3245,7 @@ var _buildFragments = async (builder, tinaSchema) => {
3039
3245
  const fragDoc = {
3040
3246
  kind: "Document",
3041
3247
  definitions: (0, import_lodash3.default)(
3248
+ // @ts-ignore
3042
3249
  extractInlineTypes(fragmentDefinitionsFields),
3043
3250
  (node) => node.name.value
3044
3251
  )
@@ -3062,6 +3269,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3062
3269
  fragName,
3063
3270
  queryName: queryListName,
3064
3271
  filterType: queryFilterTypeName,
3272
+ // look for flag to see if the data layer is enabled
3065
3273
  dataLayer: Boolean(
3066
3274
  (_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
3067
3275
  )
@@ -3071,6 +3279,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3071
3279
  const queryDoc = {
3072
3280
  kind: "Document",
3073
3281
  definitions: (0, import_lodash3.default)(
3282
+ // @ts-ignore
3074
3283
  extractInlineTypes(operationsDefinitions),
3075
3284
  (node) => node.name.value
3076
3285
  )
@@ -3159,6 +3368,7 @@ var _buildSchema = async (builder, tinaSchema) => {
3159
3368
  return {
3160
3369
  kind: "Document",
3161
3370
  definitions: (0, import_lodash3.default)(
3371
+ // @ts-ignore
3162
3372
  extractInlineTypes(definitions),
3163
3373
  (node) => node.name.value
3164
3374
  )
@@ -3175,6 +3385,9 @@ var import_isValid = __toESM(require("date-fns/isValid/index.js"));
3175
3385
  // src/mdx/index.ts
3176
3386
  var import_mdx = require("@tinacms/mdx");
3177
3387
 
3388
+ // src/resolver/index.ts
3389
+ var import_jsonpath_plus2 = require("jsonpath-plus");
3390
+
3178
3391
  // src/resolver/error.ts
3179
3392
  var TinaGraphQLError = class extends Error {
3180
3393
  constructor(message, extensions) {
@@ -3360,8 +3573,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
3360
3573
  }
3361
3574
  if (Array.isArray(value)) {
3362
3575
  return value.map((v) => {
3363
- if (!v || typeof v !== "string")
3364
- return v;
3576
+ if (!v || typeof v !== "string") return v;
3365
3577
  const cleanMediaRoot = cleanUpSlashes(
3366
3578
  schema.config.media.tina.mediaRoot
3367
3579
  );
@@ -3389,8 +3601,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3389
3601
  }
3390
3602
  if (Array.isArray(value)) {
3391
3603
  return value.map((v) => {
3392
- if (!v || typeof v !== "string")
3393
- return v;
3604
+ if (!v || typeof v !== "string") return v;
3394
3605
  const strippedValue = v.replace(cleanMediaRoot, "");
3395
3606
  return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3396
3607
  });
@@ -3409,8 +3620,7 @@ var cleanUpSlashes = (path7) => {
3409
3620
  };
3410
3621
  var hasTinaMediaConfig = (schema) => {
3411
3622
  var _a, _b, _c, _d, _e, _f, _g, _h;
3412
- if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina))
3413
- return false;
3623
+ if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3414
3624
  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")
3415
3625
  return false;
3416
3626
  return true;
@@ -3454,6 +3664,7 @@ var LevelProxyHandler = {
3454
3664
  } else if (property === "sublevel") {
3455
3665
  return (...args) => {
3456
3666
  return new Proxy(
3667
+ // eslint-disable-next-line prefer-spread
3457
3668
  target[property].apply(target, args),
3458
3669
  LevelProxyHandler
3459
3670
  );
@@ -3476,7 +3687,7 @@ var import_path2 = __toESM(require("path"));
3476
3687
  var import_toml = __toESM(require("@iarna/toml"));
3477
3688
  var import_js_yaml = __toESM(require("js-yaml"));
3478
3689
  var import_gray_matter = __toESM(require("gray-matter"));
3479
- var import_schema_tools3 = require("@tinacms/schema-tools");
3690
+ var import_schema_tools4 = require("@tinacms/schema-tools");
3480
3691
  var import_micromatch = __toESM(require("micromatch"));
3481
3692
  var import_path = __toESM(require("path"));
3482
3693
 
@@ -3689,7 +3900,7 @@ var scanAllContent = async (tinaSchema, bridge, callback) => {
3689
3900
  const filesSeen = /* @__PURE__ */ new Map();
3690
3901
  const duplicateFiles = /* @__PURE__ */ new Set();
3691
3902
  await sequential(tinaSchema.getCollections(), async (collection) => {
3692
- const normalPath = (0, import_schema_tools3.normalizePath)(collection.path);
3903
+ const normalPath = (0, import_schema_tools4.normalizePath)(collection.path);
3693
3904
  const format = collection.format || "md";
3694
3905
  const documentPaths = await bridge.glob(normalPath, format);
3695
3906
  const matches = tinaSchema.getMatches({ collection });
@@ -3801,7 +4012,7 @@ var getTemplateForFile = (templateInfo, data) => {
3801
4012
  throw new Error(`Unable to determine template`);
3802
4013
  };
3803
4014
  var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo) => {
3804
- const dataString = await bridge.get((0, import_schema_tools3.normalizePath)(filepath));
4015
+ const dataString = await bridge.get((0, import_schema_tools4.normalizePath)(filepath));
3805
4016
  const data = parseFile(
3806
4017
  dataString,
3807
4018
  import_path.default.extname(filepath),
@@ -4280,7 +4491,7 @@ var FolderTreeBuilder = class {
4280
4491
  return this._tree;
4281
4492
  }
4282
4493
  update(documentPath, collectionPath) {
4283
- let folderPath = import_path2.default.dirname((0, import_schema_tools3.normalizePath)(documentPath));
4494
+ let folderPath = import_path2.default.dirname((0, import_schema_tools4.normalizePath)(documentPath));
4284
4495
  if (folderPath === ".") {
4285
4496
  folderPath = "";
4286
4497
  }
@@ -4293,7 +4504,7 @@ var FolderTreeBuilder = class {
4293
4504
  if (!this._tree[current2]) {
4294
4505
  this._tree[current2] = /* @__PURE__ */ new Set();
4295
4506
  }
4296
- this._tree[current2].add((0, import_schema_tools3.normalizePath)(import_path2.default.join(current2, part)));
4507
+ this._tree[current2].add((0, import_schema_tools4.normalizePath)(import_path2.default.join(current2, part)));
4297
4508
  parent.push(part);
4298
4509
  });
4299
4510
  const current = parent.join("/");
@@ -4332,6 +4543,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
4332
4543
  result.push({
4333
4544
  type: opType,
4334
4545
  key: `${collection.path}/${subFolderKey}.${collection.format}`,
4546
+ // replace the root with the collection path
4335
4547
  sublevel: indexSublevel,
4336
4548
  value: {}
4337
4549
  });
@@ -4419,8 +4631,17 @@ var stringEscaper = makeStringEscaper(
4419
4631
  var createResolver = (args) => {
4420
4632
  return new Resolver(args);
4421
4633
  };
4422
- var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tinaSchema, config, isAudit) => {
4634
+ var resolveFieldData = async (args) => {
4423
4635
  var _a, _b;
4636
+ const {
4637
+ field: { namespace, ...field },
4638
+ rawData,
4639
+ accumulator,
4640
+ tinaSchema,
4641
+ config,
4642
+ isAudit,
4643
+ context
4644
+ } = args;
4424
4645
  if (!rawData) {
4425
4646
  return void 0;
4426
4647
  }
@@ -4447,6 +4668,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4447
4668
  case "password":
4448
4669
  accumulator[field.name] = {
4449
4670
  value: void 0,
4671
+ // never resolve the password hash
4450
4672
  passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4451
4673
  };
4452
4674
  break;
@@ -4459,9 +4681,11 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4459
4681
  break;
4460
4682
  case "rich-text":
4461
4683
  const tree = (0, import_mdx.parseMDX)(
4684
+ // @ts-ignore value is unknown
4462
4685
  value,
4463
4686
  field,
4464
- (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema)
4687
+ (value2) => resolveMediaRelativeToCloud(value2, config, tinaSchema.schema),
4688
+ context
4465
4689
  );
4466
4690
  if (((_b = tree == null ? void 0 : tree.children[0]) == null ? void 0 : _b.type) === "invalid_markdown") {
4467
4691
  if (isAudit) {
@@ -4492,14 +4716,15 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4492
4716
  });
4493
4717
  const payload = {};
4494
4718
  await sequential(template.fields, async (field2) => {
4495
- await resolveFieldData(
4496
- field2,
4497
- item,
4498
- payload,
4719
+ await resolveFieldData({
4720
+ field: field2,
4721
+ rawData: item,
4722
+ accumulator: payload,
4499
4723
  tinaSchema,
4500
4724
  config,
4501
- isAudit
4502
- );
4725
+ isAudit,
4726
+ context
4727
+ });
4503
4728
  });
4504
4729
  const isUnion = !!field.templates;
4505
4730
  return isUnion ? {
@@ -4520,14 +4745,15 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4520
4745
  });
4521
4746
  const payload = {};
4522
4747
  await sequential(template.fields, async (field2) => {
4523
- await resolveFieldData(
4524
- field2,
4525
- value,
4526
- payload,
4748
+ await resolveFieldData({
4749
+ field: field2,
4750
+ rawData: value,
4751
+ accumulator: payload,
4527
4752
  tinaSchema,
4528
4753
  config,
4529
- isAudit
4530
- );
4754
+ isAudit,
4755
+ context
4756
+ });
4531
4757
  });
4532
4758
  const isUnion = !!field.templates;
4533
4759
  accumulator[field.name] = isUnion ? {
@@ -4541,7 +4767,8 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4541
4767
  }
4542
4768
  return accumulator;
4543
4769
  };
4544
- var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config, isAudit) => {
4770
+ var transformDocumentIntoPayload = async (args) => {
4771
+ const { fullPath, rawData, tinaSchema, config, isAudit, context } = args;
4545
4772
  const collection = tinaSchema.getCollection(rawData._collection);
4546
4773
  try {
4547
4774
  const template = tinaSchema.getTemplateForData({
@@ -4561,14 +4788,15 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4561
4788
  };
4562
4789
  try {
4563
4790
  await sequential(template.fields, async (field) => {
4564
- return resolveFieldData(
4791
+ return resolveFieldData({
4565
4792
  field,
4566
4793
  rawData,
4567
- data,
4794
+ accumulator: data,
4568
4795
  tinaSchema,
4569
4796
  config,
4570
- isAudit
4571
- );
4797
+ isAudit,
4798
+ context
4799
+ });
4572
4800
  });
4573
4801
  } catch (e) {
4574
4802
  throw new TinaParseDocumentError({
@@ -4595,6 +4823,7 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4595
4823
  basename,
4596
4824
  filename,
4597
4825
  extension,
4826
+ hasReferences: args.hasReferences,
4598
4827
  path: fullPath,
4599
4828
  relativePath,
4600
4829
  breadcrumbs,
@@ -4614,13 +4843,34 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4614
4843
  throw e;
4615
4844
  }
4616
4845
  };
4846
+ var updateObjectWithJsonPath = (obj, path7, newValue) => {
4847
+ if (!path7.includes(".") && !path7.includes("[")) {
4848
+ if (path7 in obj) {
4849
+ obj[path7] = newValue;
4850
+ }
4851
+ return obj;
4852
+ }
4853
+ const parentPath = path7.replace(/\.[^.]+$/, "");
4854
+ const keyToUpdate = path7.match(/[^.]+$/)[0];
4855
+ const parents = (0, import_jsonpath_plus2.JSONPath)({ path: parentPath, json: obj, resultType: "value" });
4856
+ if (parents.length > 0) {
4857
+ parents.forEach((parent) => {
4858
+ if (parent && typeof parent === "object" && keyToUpdate in parent) {
4859
+ parent[keyToUpdate] = newValue;
4860
+ }
4861
+ });
4862
+ }
4863
+ return obj;
4864
+ };
4617
4865
  var Resolver = class {
4618
4866
  constructor(init) {
4619
4867
  this.init = init;
4868
+ this.context = {};
4620
4869
  this.resolveCollection = async (args, collectionName, hasDocuments) => {
4621
4870
  const collection = this.tinaSchema.getCollection(collectionName);
4622
4871
  const extraFields = {};
4623
4872
  return {
4873
+ // return the collection and hasDocuments to resolve documents at a lower level
4624
4874
  documents: { collection, hasDocuments },
4625
4875
  ...collection,
4626
4876
  ...extraFields
@@ -4646,27 +4896,33 @@ var Resolver = class {
4646
4896
  path: rawData["__folderPath"]
4647
4897
  };
4648
4898
  } else {
4649
- return transformDocumentIntoPayload(
4899
+ this.context = { ...rawData };
4900
+ return transformDocumentIntoPayload({
4650
4901
  fullPath,
4651
4902
  rawData,
4652
- this.tinaSchema,
4653
- this.config,
4654
- this.isAudit
4655
- );
4903
+ tinaSchema: this.tinaSchema,
4904
+ config: this.config,
4905
+ isAudit: this.isAudit,
4906
+ context: this.context
4907
+ });
4656
4908
  }
4657
4909
  };
4658
- this.getDocument = async (fullPath) => {
4910
+ this.getDocument = async (fullPath, opts = {}) => {
4659
4911
  if (typeof fullPath !== "string") {
4660
4912
  throw new Error(`fullPath must be of type string for getDocument request`);
4661
4913
  }
4662
4914
  const rawData = await this.getRaw(fullPath);
4663
- return transformDocumentIntoPayload(
4915
+ this.context = { ...rawData };
4916
+ const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
4917
+ return transformDocumentIntoPayload({
4664
4918
  fullPath,
4665
4919
  rawData,
4666
- this.tinaSchema,
4667
- this.config,
4668
- this.isAudit
4669
- );
4920
+ tinaSchema: this.tinaSchema,
4921
+ config: this.config,
4922
+ isAudit: this.isAudit,
4923
+ context: this.context,
4924
+ hasReferences
4925
+ });
4670
4926
  };
4671
4927
  this.deleteDocument = async (fullPath) => {
4672
4928
  if (typeof fullPath !== "string") {
@@ -4705,7 +4961,9 @@ var Resolver = class {
4705
4961
  );
4706
4962
  } else {
4707
4963
  return this.buildFieldMutations(
4964
+ // @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
4708
4965
  fieldValue,
4966
+ //@ts-ignore
4709
4967
  objectTemplate,
4710
4968
  existingData
4711
4969
  );
@@ -4717,6 +4975,7 @@ var Resolver = class {
4717
4975
  fieldValue.map(async (item) => {
4718
4976
  if (typeof item === "string") {
4719
4977
  throw new Error(
4978
+ //@ts-ignore
4720
4979
  `Expected object for template value for field ${field.name}`
4721
4980
  );
4722
4981
  }
@@ -4725,16 +4984,19 @@ var Resolver = class {
4725
4984
  });
4726
4985
  const [templateName] = Object.entries(item)[0];
4727
4986
  const template = templates.find(
4987
+ //@ts-ignore
4728
4988
  (template2) => template2.name === templateName
4729
4989
  );
4730
4990
  if (!template) {
4731
4991
  throw new Error(`Expected to find template ${templateName}`);
4732
4992
  }
4733
4993
  return {
4994
+ // @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
4734
4995
  ...await this.buildFieldMutations(
4735
4996
  item[template.name],
4736
4997
  template
4737
4998
  ),
4999
+ //@ts-ignore
4738
5000
  _template: template.name
4739
5001
  };
4740
5002
  })
@@ -4742,6 +5004,7 @@ var Resolver = class {
4742
5004
  } else {
4743
5005
  if (typeof fieldValue === "string") {
4744
5006
  throw new Error(
5007
+ //@ts-ignore
4745
5008
  `Expected object for template value for field ${field.name}`
4746
5009
  );
4747
5010
  }
@@ -4750,16 +5013,19 @@ var Resolver = class {
4750
5013
  });
4751
5014
  const [templateName] = Object.entries(fieldValue)[0];
4752
5015
  const template = templates.find(
5016
+ //@ts-ignore
4753
5017
  (template2) => template2.name === templateName
4754
5018
  );
4755
5019
  if (!template) {
4756
5020
  throw new Error(`Expected to find template ${templateName}`);
4757
5021
  }
4758
5022
  return {
5023
+ // @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
4759
5024
  ...await this.buildFieldMutations(
4760
5025
  fieldValue[template.name],
4761
5026
  template
4762
5027
  ),
5028
+ //@ts-ignore
4763
5029
  _template: template.name
4764
5030
  };
4765
5031
  }
@@ -4799,6 +5065,7 @@ var Resolver = class {
4799
5065
  return this.getDocument(realPath);
4800
5066
  }
4801
5067
  const params = await this.buildObjectMutations(
5068
+ // @ts-ignore
4802
5069
  args.params[collection.name],
4803
5070
  collection
4804
5071
  );
@@ -4812,58 +5079,68 @@ var Resolver = class {
4812
5079
  isAddPendingDocument,
4813
5080
  isCollectionSpecific
4814
5081
  }) => {
5082
+ var _a;
4815
5083
  const doc = await this.getDocument(realPath);
4816
5084
  const oldDoc = this.resolveLegacyValues((doc == null ? void 0 : doc._rawData) || {}, collection);
5085
+ let values;
4817
5086
  if (isAddPendingDocument === true) {
4818
5087
  const templateInfo = this.tinaSchema.getTemplatesForCollectable(collection);
4819
- const params2 = this.buildParams(args);
5088
+ const params = this.buildParams(args);
4820
5089
  switch (templateInfo.type) {
4821
5090
  case "object":
4822
- if (params2) {
4823
- const values = await this.buildFieldMutations(
4824
- params2,
5091
+ if (params) {
5092
+ const mutationValues = await this.buildFieldMutations(
5093
+ params,
4825
5094
  templateInfo.template,
4826
5095
  doc == null ? void 0 : doc._rawData
4827
5096
  );
4828
- await this.database.put(
4829
- realPath,
4830
- { ...oldDoc, ...values },
4831
- collection.name
4832
- );
5097
+ values = { ...oldDoc, ...mutationValues };
4833
5098
  }
4834
5099
  break;
4835
- case "union":
5100
+ case "union": {
4836
5101
  await sequential(templateInfo.templates, async (template) => {
4837
- const templateParams = params2[lastItem(template.namespace)];
5102
+ const templateParams = params[lastItem(template.namespace)];
4838
5103
  if (templateParams) {
4839
5104
  if (typeof templateParams === "string") {
4840
5105
  throw new Error(
4841
5106
  `Expected to find an object for template params, but got string`
4842
5107
  );
4843
5108
  }
4844
- const values = {
5109
+ values = {
4845
5110
  ...oldDoc,
4846
5111
  ...await this.buildFieldMutations(
5112
+ // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
4847
5113
  templateParams,
4848
5114
  template,
4849
5115
  doc == null ? void 0 : doc._rawData
4850
5116
  ),
4851
5117
  _template: lastItem(template.namespace)
4852
5118
  };
4853
- await this.database.put(realPath, values, collection.name);
4854
5119
  }
4855
5120
  });
5121
+ }
4856
5122
  }
4857
- return this.getDocument(realPath);
5123
+ } else {
5124
+ const params = await this.buildObjectMutations(
5125
+ //@ts-expect-error FIXME: Argument of type 'unknown' is not assignable to parameter of type 'FieldParams'
5126
+ isCollectionSpecific ? args.params : args.params[collection.name],
5127
+ collection,
5128
+ doc == null ? void 0 : doc._rawData
5129
+ );
5130
+ values = { ...oldDoc, ...params };
4858
5131
  }
4859
- const params = await this.buildObjectMutations(
4860
- isCollectionSpecific ? args.params : args.params[collection.name],
4861
- collection,
4862
- doc == null ? void 0 : doc._rawData
5132
+ const _tinaEmbeds = ((_a = this.context) == null ? void 0 : _a._tinaEmbeds) ? { _tinaEmbeds: this.context._tinaEmbeds } : {};
5133
+ await this.database.put(
5134
+ realPath,
5135
+ { ...values, ..._tinaEmbeds },
5136
+ collection.name
4863
5137
  );
4864
- await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
4865
5138
  return this.getDocument(realPath);
4866
5139
  };
5140
+ /**
5141
+ * Returns top-level fields which are not defined in the collection, so their
5142
+ * values are not eliminated from Tina when new values are saved
5143
+ */
4867
5144
  this.resolveLegacyValues = (oldDoc, collection) => {
4868
5145
  const legacyValues = {};
4869
5146
  Object.entries(oldDoc).forEach(([key, value]) => {
@@ -4969,6 +5246,22 @@ var Resolver = class {
4969
5246
  if (isDeletion) {
4970
5247
  const doc = await this.getDocument(realPath);
4971
5248
  await this.deleteDocument(realPath);
5249
+ if (await this.hasReferences(realPath, collection)) {
5250
+ const collRefs = await this.findReferences(realPath, collection);
5251
+ for (const [collection2, refFields] of Object.entries(collRefs)) {
5252
+ for (const [refPath, refs] of Object.entries(refFields)) {
5253
+ let refDoc = await this.getRaw(refPath);
5254
+ for (const ref of refs) {
5255
+ refDoc = updateObjectWithJsonPath(
5256
+ refDoc,
5257
+ ref.path.join("."),
5258
+ null
5259
+ );
5260
+ }
5261
+ await this.database.put(refPath, refDoc, collection2);
5262
+ }
5263
+ }
5264
+ }
4972
5265
  return doc;
4973
5266
  }
4974
5267
  if (isUpdateName) {
@@ -4987,6 +5280,20 @@ var Resolver = class {
4987
5280
  );
4988
5281
  await this.database.put(newRealPath, doc._rawData, collection.name);
4989
5282
  await this.deleteDocument(realPath);
5283
+ const collRefs = await this.findReferences(realPath, collection);
5284
+ for (const [collection2, refFields] of Object.entries(collRefs)) {
5285
+ for (const [refPath, refs] of Object.entries(refFields)) {
5286
+ let refDoc = await this.getRaw(refPath);
5287
+ for (const ref of refs) {
5288
+ refDoc = updateObjectWithJsonPath(
5289
+ refDoc,
5290
+ ref.path.join("."),
5291
+ newRealPath
5292
+ );
5293
+ }
5294
+ await this.database.put(refPath, refDoc, collection2);
5295
+ }
5296
+ }
4990
5297
  return this.getDocument(newRealPath);
4991
5298
  }
4992
5299
  if (alreadyExists === false) {
@@ -5000,7 +5307,10 @@ var Resolver = class {
5000
5307
  isCollectionSpecific
5001
5308
  });
5002
5309
  } else {
5003
- return this.getDocument(realPath);
5310
+ return this.getDocument(realPath, {
5311
+ collection,
5312
+ checkReferences: true
5313
+ });
5004
5314
  }
5005
5315
  };
5006
5316
  this.resolveCollectionConnections = async ({ ids }) => {
@@ -5037,6 +5347,7 @@ var Resolver = class {
5037
5347
  },
5038
5348
  collection: referencedCollection,
5039
5349
  hydrator: (path7) => path7
5350
+ // just return the path
5040
5351
  }
5041
5352
  );
5042
5353
  const { edges } = resolvedCollectionConnection;
@@ -5104,6 +5415,92 @@ var Resolver = class {
5104
5415
  }
5105
5416
  };
5106
5417
  };
5418
+ /**
5419
+ * Checks if a document has references to it
5420
+ * @param id The id of the document to check for references
5421
+ * @param c The collection to check for references
5422
+ * @returns true if the document has references, false otherwise
5423
+ */
5424
+ this.hasReferences = async (id, c) => {
5425
+ let count = 0;
5426
+ const deepRefs = this.tinaSchema.findReferences(c.name);
5427
+ for (const [collection, refs] of Object.entries(deepRefs)) {
5428
+ for (const ref of refs) {
5429
+ await this.database.query(
5430
+ {
5431
+ collection,
5432
+ filterChain: makeFilterChain({
5433
+ conditions: [
5434
+ {
5435
+ filterPath: ref.path.join("."),
5436
+ filterExpression: {
5437
+ _type: "reference",
5438
+ _list: false,
5439
+ eq: id
5440
+ }
5441
+ }
5442
+ ]
5443
+ }),
5444
+ sort: ref.field.name
5445
+ },
5446
+ (refId) => {
5447
+ count++;
5448
+ return refId;
5449
+ }
5450
+ );
5451
+ if (count) {
5452
+ return true;
5453
+ }
5454
+ }
5455
+ }
5456
+ return false;
5457
+ };
5458
+ /**
5459
+ * Finds references to a document
5460
+ * @param id the id of the document to find references to
5461
+ * @param c the collection to find references in
5462
+ * @returns references to the document in the form of a map of collection names to a list of fields that reference the document
5463
+ */
5464
+ this.findReferences = async (id, c) => {
5465
+ const references = {};
5466
+ const deepRefs = this.tinaSchema.findReferences(c.name);
5467
+ for (const [collection, refs] of Object.entries(deepRefs)) {
5468
+ for (const ref of refs) {
5469
+ await this.database.query(
5470
+ {
5471
+ collection,
5472
+ filterChain: makeFilterChain({
5473
+ conditions: [
5474
+ {
5475
+ filterPath: ref.path.join("."),
5476
+ filterExpression: {
5477
+ _type: "reference",
5478
+ _list: false,
5479
+ eq: id
5480
+ }
5481
+ }
5482
+ ]
5483
+ }),
5484
+ sort: ref.field.name
5485
+ },
5486
+ (refId) => {
5487
+ if (!references[collection]) {
5488
+ references[collection] = {};
5489
+ }
5490
+ if (!references[collection][refId]) {
5491
+ references[collection][refId] = [];
5492
+ }
5493
+ references[collection][refId].push({
5494
+ path: ref.path,
5495
+ field: ref.field
5496
+ });
5497
+ return refId;
5498
+ }
5499
+ );
5500
+ }
5501
+ }
5502
+ return references;
5503
+ };
5107
5504
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
5108
5505
  var _a;
5109
5506
  const accum = {};
@@ -5173,13 +5570,15 @@ var Resolver = class {
5173
5570
  break;
5174
5571
  case "rich-text":
5175
5572
  accum[fieldName] = (0, import_mdx.stringifyMDX)(
5573
+ // @ts-ignore
5176
5574
  fieldValue,
5177
5575
  field,
5178
5576
  (fieldValue2) => resolveMediaCloudToRelative(
5179
5577
  fieldValue2,
5180
5578
  this.config,
5181
5579
  this.tinaSchema.schema
5182
- )
5580
+ ),
5581
+ this.context
5183
5582
  );
5184
5583
  break;
5185
5584
  case "reference":
@@ -5191,6 +5590,27 @@ var Resolver = class {
5191
5590
  }
5192
5591
  return accum;
5193
5592
  };
5593
+ /**
5594
+ * A mutation looks nearly identical between updateDocument:
5595
+ * ```graphql
5596
+ * updateDocument(collection: $collection,relativePath: $path, params: {
5597
+ * post: {
5598
+ * title: "Hello, World"
5599
+ * }
5600
+ * })`
5601
+ * ```
5602
+ * and `updatePostDocument`:
5603
+ * ```graphql
5604
+ * updatePostDocument(relativePath: $path, params: {
5605
+ * title: "Hello, World"
5606
+ * })
5607
+ * ```
5608
+ * The problem here is that we don't know whether the payload came from `updateDocument`
5609
+ * or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
5610
+ * But we do know that when given a `args.collection` value, we can assume that
5611
+ * this was a `updateDocument` request, and thus - should grab the data
5612
+ * from the corresponding field name in the key
5613
+ */
5194
5614
  this.buildParams = (args) => {
5195
5615
  try {
5196
5616
  assertShape(
@@ -5291,7 +5711,10 @@ var resolve = async ({
5291
5711
  const graphQLSchema = (0, import_graphql5.buildASTSchema)(graphQLSchemaAst);
5292
5712
  const tinaConfig = await database.getTinaSchema();
5293
5713
  const tinaSchema = await createSchema({
5714
+ // TODO: please update all the types to import from @tinacms/schema-tools
5715
+ // @ts-ignore
5294
5716
  schema: tinaConfig,
5717
+ // @ts-ignore
5295
5718
  flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5296
5719
  });
5297
5720
  const resolver = createResolver({
@@ -5308,8 +5731,7 @@ var resolve = async ({
5308
5731
  database
5309
5732
  },
5310
5733
  typeResolver: async (source, _args, info) => {
5311
- if (source.__typename)
5312
- return source.__typename;
5734
+ if (source.__typename) return source.__typename;
5313
5735
  const namedType = (0, import_graphql5.getNamedType)(info.returnType).toString();
5314
5736
  const lookup = await database.getLookup(namedType);
5315
5737
  if (lookup.resolveType === "unionData") {
@@ -5461,11 +5883,13 @@ var resolve = async ({
5461
5883
  (0, import_lodash4.default)(
5462
5884
  params,
5463
5885
  userField.path.slice(1),
5886
+ // remove _rawData from users path
5464
5887
  users.map((u) => {
5465
5888
  if (user[idFieldName] === u[idFieldName]) {
5466
5889
  return user;
5467
5890
  }
5468
5891
  return {
5892
+ // don't overwrite other users' passwords
5469
5893
  ...u,
5470
5894
  [passwordFieldName]: {
5471
5895
  ...u[passwordFieldName],
@@ -5488,6 +5912,9 @@ var resolve = async ({
5488
5912
  }
5489
5913
  const isCreation = lookup[info.fieldName] === "create";
5490
5914
  switch (lookup.resolveType) {
5915
+ /**
5916
+ * `node(id: $id)`
5917
+ */
5491
5918
  case "nodeDocument":
5492
5919
  assertShape(
5493
5920
  args,
@@ -5519,6 +5946,7 @@ var resolve = async ({
5519
5946
  collection: args.collection,
5520
5947
  isMutation,
5521
5948
  isCreation,
5949
+ // Right now this is the only case for deletion
5522
5950
  isDeletion: info.fieldName === "deleteDocument",
5523
5951
  isFolderCreation: info.fieldName === "createFolder",
5524
5952
  isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
@@ -5528,6 +5956,9 @@ var resolve = async ({
5528
5956
  return result;
5529
5957
  }
5530
5958
  return value;
5959
+ /**
5960
+ * eg `getMovieDocument.data.actors`
5961
+ */
5531
5962
  case "multiCollectionDocumentList":
5532
5963
  if (Array.isArray(value)) {
5533
5964
  return {
@@ -5539,7 +5970,15 @@ var resolve = async ({
5539
5970
  }
5540
5971
  if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
5541
5972
  let filter = args.filter;
5542
- 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") {
5973
+ if (
5974
+ // 1. Make sure that the filter exists
5975
+ typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
5976
+ // @ts-ignore
5977
+ 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
5978
+ // @ts-ignore
5979
+ Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
5980
+ typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
5981
+ ) {
5543
5982
  filter = args.filter[value.collection.name];
5544
5983
  }
5545
5984
  return resolver.resolveCollectionConnection({
@@ -5547,12 +5986,20 @@ var resolve = async ({
5547
5986
  ...args,
5548
5987
  filter
5549
5988
  },
5989
+ // @ts-ignore
5550
5990
  collection: value.collection
5551
5991
  });
5552
5992
  }
5553
5993
  throw new Error(
5554
5994
  `Expected an array for result of ${info.fieldName} at ${info.path}`
5555
5995
  );
5996
+ /**
5997
+ * Collections-specific getter
5998
+ * eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
5999
+ *
6000
+ * if coming from a query result
6001
+ * the field will be `node`
6002
+ */
5556
6003
  case "collectionDocument": {
5557
6004
  if (value) {
5558
6005
  return value;
@@ -5567,11 +6014,32 @@ var resolve = async ({
5567
6014
  });
5568
6015
  return result;
5569
6016
  }
6017
+ /**
6018
+ * Collections-specific list getter
6019
+ * eg. `getPageList`
6020
+ */
5570
6021
  case "collectionDocumentList":
5571
6022
  return resolver.resolveCollectionConnection({
5572
6023
  args,
5573
6024
  collection: tinaSchema.getCollection(lookup.collection)
5574
6025
  });
6026
+ /**
6027
+ * A polymorphic data set, it can be from a document's data
6028
+ * of any nested object which can be one of many shapes
6029
+ *
6030
+ * ```graphql
6031
+ * getPostDocument(relativePath: $relativePath) {
6032
+ * data {...} <- this part
6033
+ * }
6034
+ * ```
6035
+ * ```graphql
6036
+ * getBlockDocument(relativePath: $relativePath) {
6037
+ * data {
6038
+ * blocks {...} <- or this part
6039
+ * }
6040
+ * }
6041
+ * ```
6042
+ */
5575
6043
  case "unionData":
5576
6044
  if (!value) {
5577
6045
  if (args.relativePath) {
@@ -5636,8 +6104,7 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
5636
6104
  this.port = port || 9e3;
5637
6105
  }
5638
6106
  openConnection() {
5639
- if (this._connected)
5640
- return;
6107
+ if (this._connected) return;
5641
6108
  const socket = (0, import_net.connect)(this.port);
5642
6109
  (0, import_readable_stream.pipeline)(socket, this.createRpcStream(), socket, () => {
5643
6110
  this._connected = false;
@@ -5757,7 +6224,7 @@ var Database = class {
5757
6224
  const contentObject = await level.sublevel(
5758
6225
  CONTENT_ROOT_PREFIX,
5759
6226
  SUBLEVEL_OPTIONS
5760
- ).get((0, import_schema_tools3.normalizePath)(filepath));
6227
+ ).get((0, import_schema_tools4.normalizePath)(filepath));
5761
6228
  if (!contentObject) {
5762
6229
  throw new NotFoundError(`Unable to find record ${filepath}`);
5763
6230
  }
@@ -5782,7 +6249,7 @@ var Database = class {
5782
6249
  );
5783
6250
  const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
5784
6251
  const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
5785
- const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
6252
+ const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
5786
6253
  if (!(collection == null ? void 0 : collection.isDetached)) {
5787
6254
  if (this.bridge) {
5788
6255
  await this.bridge.put(normalizedPath, stringifiedFile);
@@ -5818,6 +6285,7 @@ var Database = class {
5818
6285
  "put",
5819
6286
  level
5820
6287
  ),
6288
+ // folder indices
5821
6289
  ...makeIndexOpsForDocument(
5822
6290
  normalizedPath,
5823
6291
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -5840,6 +6308,7 @@ var Database = class {
5840
6308
  "del",
5841
6309
  level
5842
6310
  ),
6311
+ // folder indices
5843
6312
  ...makeIndexOpsForDocument(
5844
6313
  normalizedPath,
5845
6314
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -5879,7 +6348,7 @@ var Database = class {
5879
6348
  );
5880
6349
  collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
5881
6350
  }
5882
- const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
6351
+ const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
5883
6352
  const dataFields = await this.formatBodyOnPayload(filepath, data);
5884
6353
  const collection = await this.collectionForPath(filepath);
5885
6354
  if (!collection) {
@@ -5934,6 +6403,7 @@ var Database = class {
5934
6403
  "put",
5935
6404
  level
5936
6405
  ),
6406
+ // folder indices
5937
6407
  ...makeIndexOpsForDocument(
5938
6408
  normalizedPath,
5939
6409
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -5956,6 +6426,7 @@ var Database = class {
5956
6426
  "del",
5957
6427
  level
5958
6428
  ),
6429
+ // folder indices
5959
6430
  ...makeIndexOpsForDocument(
5960
6431
  normalizedPath,
5961
6432
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6033,6 +6504,7 @@ var Database = class {
6033
6504
  aliasedData,
6034
6505
  extension,
6035
6506
  writeTemplateKey,
6507
+ //templateInfo.type === 'union',
6036
6508
  {
6037
6509
  frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6038
6510
  frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
@@ -6050,7 +6522,7 @@ var Database = class {
6050
6522
  };
6051
6523
  this.getLookup = async (returnType) => {
6052
6524
  await this.initLevel();
6053
- const lookupPath = (0, import_schema_tools3.normalizePath)(
6525
+ const lookupPath = (0, import_schema_tools4.normalizePath)(
6054
6526
  import_node_path.default.join(this.getGeneratedFolder(), `_lookup.json`)
6055
6527
  );
6056
6528
  if (!this._lookup) {
@@ -6063,7 +6535,7 @@ var Database = class {
6063
6535
  };
6064
6536
  this.getGraphQLSchema = async () => {
6065
6537
  await this.initLevel();
6066
- const graphqlPath = (0, import_schema_tools3.normalizePath)(
6538
+ const graphqlPath = (0, import_schema_tools4.normalizePath)(
6067
6539
  import_node_path.default.join(this.getGeneratedFolder(), `_graphql.json`)
6068
6540
  );
6069
6541
  return await this.contentLevel.sublevel(
@@ -6071,11 +6543,12 @@ var Database = class {
6071
6543
  SUBLEVEL_OPTIONS
6072
6544
  ).get(graphqlPath);
6073
6545
  };
6546
+ //TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
6074
6547
  this.getGraphQLSchemaFromBridge = async () => {
6075
6548
  if (!this.bridge) {
6076
6549
  throw new Error(`No bridge configured`);
6077
6550
  }
6078
- const graphqlPath = (0, import_schema_tools3.normalizePath)(
6551
+ const graphqlPath = (0, import_schema_tools4.normalizePath)(
6079
6552
  import_node_path.default.join(this.getGeneratedFolder(), `_graphql.json`)
6080
6553
  );
6081
6554
  const _graphql = await this.bridge.get(graphqlPath);
@@ -6083,7 +6556,7 @@ var Database = class {
6083
6556
  };
6084
6557
  this.getTinaSchema = async (level) => {
6085
6558
  await this.initLevel();
6086
- const schemaPath = (0, import_schema_tools3.normalizePath)(
6559
+ const schemaPath = (0, import_schema_tools4.normalizePath)(
6087
6560
  import_node_path.default.join(this.getGeneratedFolder(), `_schema.json`)
6088
6561
  );
6089
6562
  return await (level || this.contentLevel).sublevel(
@@ -6099,7 +6572,7 @@ var Database = class {
6099
6572
  const schema = existingSchema || await this.getTinaSchema(level || this.contentLevel);
6100
6573
  if (!schema) {
6101
6574
  throw new Error(
6102
- `Unable to get schema from level db: ${(0, import_schema_tools3.normalizePath)(
6575
+ `Unable to get schema from level db: ${(0, import_schema_tools4.normalizePath)(
6103
6576
  import_node_path.default.join(this.getGeneratedFolder(), `_schema.json`)
6104
6577
  )}`
6105
6578
  );
@@ -6117,6 +6590,7 @@ var Database = class {
6117
6590
  for (const collection of collections) {
6118
6591
  const indexDefinitions = {
6119
6592
  [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
6593
+ // provide a default sort key which is the file sort
6120
6594
  };
6121
6595
  if (collection.fields) {
6122
6596
  for (const field of collection.fields) {
@@ -6315,7 +6789,7 @@ var Database = class {
6315
6789
  try {
6316
6790
  lookup = lookupFromLockFile || JSON.parse(
6317
6791
  await this.bridge.get(
6318
- (0, import_schema_tools3.normalizePath)(
6792
+ (0, import_schema_tools4.normalizePath)(
6319
6793
  import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")
6320
6794
  )
6321
6795
  )
@@ -6340,15 +6814,15 @@ var Database = class {
6340
6814
  }
6341
6815
  const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
6342
6816
  await contentRootLevel.put(
6343
- (0, import_schema_tools3.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_graphql.json")),
6817
+ (0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_graphql.json")),
6344
6818
  graphQLSchema
6345
6819
  );
6346
6820
  await contentRootLevel.put(
6347
- (0, import_schema_tools3.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_schema.json")),
6821
+ (0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_schema.json")),
6348
6822
  tinaSchema.schema
6349
6823
  );
6350
6824
  await contentRootLevel.put(
6351
- (0, import_schema_tools3.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")),
6825
+ (0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")),
6352
6826
  lookup
6353
6827
  );
6354
6828
  const result = await this._indexAllContent(
@@ -6441,12 +6915,12 @@ var Database = class {
6441
6915
  if (collection == null ? void 0 : collection.isDetached) {
6442
6916
  level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
6443
6917
  }
6444
- const itemKey = (0, import_schema_tools3.normalizePath)(filepath);
6918
+ const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6445
6919
  const rootSublevel = level.sublevel(
6446
6920
  CONTENT_ROOT_PREFIX,
6447
6921
  SUBLEVEL_OPTIONS
6448
6922
  );
6449
- const item = await rootSublevel.get(itemKey);
6923
+ const item = await rootSublevel.get(normalizedPath);
6450
6924
  if (item) {
6451
6925
  const folderTreeBuilder = new FolderTreeBuilder();
6452
6926
  const folderKey = folderTreeBuilder.update(
@@ -6455,15 +6929,16 @@ var Database = class {
6455
6929
  );
6456
6930
  await this.contentLevel.batch([
6457
6931
  ...makeIndexOpsForDocument(
6458
- filepath,
6932
+ normalizedPath,
6459
6933
  collection.name,
6460
6934
  collectionIndexDefinitions,
6461
6935
  item,
6462
6936
  "del",
6463
6937
  level
6464
6938
  ),
6939
+ // folder indices
6465
6940
  ...makeIndexOpsForDocument(
6466
- filepath,
6941
+ normalizedPath,
6467
6942
  `${collection.name}_${folderKey}`,
6468
6943
  collectionIndexDefinitions,
6469
6944
  item,
@@ -6472,17 +6947,17 @@ var Database = class {
6472
6947
  ),
6473
6948
  {
6474
6949
  type: "del",
6475
- key: itemKey,
6950
+ key: normalizedPath,
6476
6951
  sublevel: rootSublevel
6477
6952
  }
6478
6953
  ]);
6479
6954
  }
6480
6955
  if (!(collection == null ? void 0 : collection.isDetached)) {
6481
6956
  if (this.bridge) {
6482
- await this.bridge.delete((0, import_schema_tools3.normalizePath)(filepath));
6957
+ await this.bridge.delete(normalizedPath);
6483
6958
  }
6484
6959
  try {
6485
- await this.onDelete((0, import_schema_tools3.normalizePath)(filepath));
6960
+ await this.onDelete(normalizedPath);
6486
6961
  } catch (e) {
6487
6962
  throw new import_graphql6.GraphQLError(
6488
6963
  `Error running onDelete hook for ${filepath}: ${e}`,
@@ -6616,6 +7091,9 @@ var Database = class {
6616
7091
  info: templateInfo
6617
7092
  };
6618
7093
  }
7094
+ /**
7095
+ * Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
7096
+ */
6619
7097
  clearCache() {
6620
7098
  this.tinaSchema = null;
6621
7099
  this._lookup = null;
@@ -6697,7 +7175,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
6697
7175
  if (passwordFields == null ? void 0 : passwordFields.length) {
6698
7176
  await hashPasswordValues(aliasedData, passwordFields);
6699
7177
  }
6700
- const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
7178
+ const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
6701
7179
  const folderKey = folderTreeBuilder.update(
6702
7180
  normalizedPath,
6703
7181
  collectionPath || ""
@@ -6712,6 +7190,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
6712
7190
  "put",
6713
7191
  level
6714
7192
  ),
7193
+ // folder indexes
6715
7194
  ...makeIndexOpsForDocument(
6716
7195
  normalizedPath,
6717
7196
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6777,7 +7256,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
6777
7256
  );
6778
7257
  const folderTreeBuilder = new FolderTreeBuilder();
6779
7258
  await sequential(documentPaths, async (filepath) => {
6780
- const itemKey = (0, import_schema_tools3.normalizePath)(filepath);
7259
+ const itemKey = (0, import_schema_tools4.normalizePath)(filepath);
6781
7260
  const item = await rootLevel.get(itemKey);
6782
7261
  if (item) {
6783
7262
  const folderKey = folderTreeBuilder.update(
@@ -6797,6 +7276,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
6797
7276
  "del",
6798
7277
  database.contentLevel
6799
7278
  ),
7279
+ // folder indexes
6800
7280
  ...makeIndexOpsForDocument(
6801
7281
  itemKey,
6802
7282
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6863,14 +7343,14 @@ var getChangedFiles = async ({
6863
7343
  const rootDir = await findGitRoot(dir);
6864
7344
  let pathPrefix = "";
6865
7345
  if (rootDir !== dir) {
6866
- pathPrefix = (0, import_schema_tools3.normalizePath)(dir.substring(rootDir.length + 1));
7346
+ pathPrefix = (0, import_schema_tools4.normalizePath)(dir.substring(rootDir.length + 1));
6867
7347
  }
6868
7348
  await import_isomorphic_git.default.walk({
6869
7349
  fs: fs4,
6870
7350
  dir: rootDir,
6871
7351
  trees: [import_isomorphic_git.default.TREE({ ref: from }), import_isomorphic_git.default.TREE({ ref: to })],
6872
7352
  map: async function(filename, [A, B]) {
6873
- const relativePath = (0, import_schema_tools3.normalizePath)(filename).substring(pathPrefix.length);
7353
+ const relativePath = (0, import_schema_tools4.normalizePath)(filename).substring(pathPrefix.length);
6874
7354
  let matches = false;
6875
7355
  for (const [key, matcher] of Object.entries(pathFilter)) {
6876
7356
  if (relativePath.startsWith(key)) {
@@ -7012,17 +7492,26 @@ var IsomorphicBridge = class {
7012
7492
  getAuthor() {
7013
7493
  return {
7014
7494
  ...this.author,
7015
- timestamp: Math.round(new Date().getTime() / 1e3),
7495
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7016
7496
  timezoneOffset: 0
7017
7497
  };
7018
7498
  }
7019
7499
  getCommitter() {
7020
7500
  return {
7021
7501
  ...this.committer,
7022
- timestamp: Math.round(new Date().getTime() / 1e3),
7502
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7023
7503
  timezoneOffset: 0
7024
7504
  };
7025
7505
  }
7506
+ /**
7507
+ * Recursively populate paths matching `pattern` for the given `entry`
7508
+ *
7509
+ * @param pattern - pattern to filter paths by
7510
+ * @param entry - TreeEntry to start building list from
7511
+ * @param path - base path
7512
+ * @param results
7513
+ * @private
7514
+ */
7026
7515
  async listEntries({
7027
7516
  pattern,
7028
7517
  entry,
@@ -7055,6 +7544,15 @@ var IsomorphicBridge = class {
7055
7544
  });
7056
7545
  }
7057
7546
  }
7547
+ /**
7548
+ * For the specified path, returns an object with an array containing the parts of the path (pathParts)
7549
+ * and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
7550
+ * pathEntries are placeholders for non-existent entries.
7551
+ *
7552
+ * @param path - path being resolved
7553
+ * @param ref - ref to resolve path entries for
7554
+ * @private
7555
+ */
7058
7556
  async resolvePathEntries(path7, ref) {
7059
7557
  let pathParts = path7.split("/");
7060
7558
  const result = await import_isomorphic_git2.default.walk({
@@ -7085,6 +7583,17 @@ var IsomorphicBridge = class {
7085
7583
  }
7086
7584
  return { pathParts, pathEntries };
7087
7585
  }
7586
+ /**
7587
+ * Updates tree entry and associated parent tree entries
7588
+ *
7589
+ * @param existingOid - the existing OID
7590
+ * @param updatedOid - the updated OID
7591
+ * @param path - the path of the entry being updated
7592
+ * @param type - the type of the entry being updated (blob or tree)
7593
+ * @param pathEntries - parent path entries
7594
+ * @param pathParts - parent path parts
7595
+ * @private
7596
+ */
7088
7597
  async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
7089
7598
  const lastIdx = pathEntries.length - 1;
7090
7599
  const parentEntry = pathEntries[lastIdx];
@@ -7140,6 +7649,13 @@ var IsomorphicBridge = class {
7140
7649
  );
7141
7650
  }
7142
7651
  }
7652
+ /**
7653
+ * Creates a commit for the specified tree and updates the specified ref to point to the commit
7654
+ *
7655
+ * @param treeSha - sha of the new tree
7656
+ * @param ref - the ref that should be updated
7657
+ * @private
7658
+ */
7143
7659
  async commitTree(treeSha, ref) {
7144
7660
  const commitSha = await import_isomorphic_git2.default.writeCommit({
7145
7661
  ...this.isomorphicConfig,
@@ -7152,6 +7668,7 @@ var IsomorphicBridge = class {
7152
7668
  })
7153
7669
  ],
7154
7670
  message: this.commitMessage,
7671
+ // TODO these should be configurable
7155
7672
  author: this.getAuthor(),
7156
7673
  committer: this.getCommitter()
7157
7674
  }
@@ -7390,5 +7907,5 @@ var buildSchema = async (config, flags) => {
7390
7907
  transformDocument,
7391
7908
  transformDocumentIntoPayload
7392
7909
  });
7393
- //! Replaces _.flattenDeep()
7394
7910
  //! Replaces _.get()
7911
+ //! Replaces _.flattenDeep()