@tinacms/graphql 0.0.0-ecea7ac-20241011043815 → 0.0.0-ed38135-20250102012919

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) => {
@@ -1257,6 +1289,11 @@ var scalarDefinitions = [
1257
1289
  required: true,
1258
1290
  type: astBuilder.TYPES.String
1259
1291
  }),
1292
+ astBuilder.FieldDefinition({
1293
+ name: "hasReferences",
1294
+ required: false,
1295
+ type: astBuilder.TYPES.Boolean
1296
+ }),
1260
1297
  astBuilder.FieldDefinition({
1261
1298
  name: "breadcrumbs",
1262
1299
  required: true,
@@ -1471,6 +1508,19 @@ var Builder = class {
1471
1508
  this.addToLookupMap = (lookup) => {
1472
1509
  this.lookupMap[lookup.type] = lookup;
1473
1510
  };
1511
+ /**
1512
+ * ```graphql
1513
+ * # ex.
1514
+ * {
1515
+ * getCollection(collection: $collection) {
1516
+ * name
1517
+ * documents {...}
1518
+ * }
1519
+ * }
1520
+ * ```
1521
+ *
1522
+ * @param collections
1523
+ */
1474
1524
  this.buildCollectionDefinition = async (collections) => {
1475
1525
  const name = "collection";
1476
1526
  const typeName = "Collection";
@@ -1541,6 +1591,19 @@ var Builder = class {
1541
1591
  required: true
1542
1592
  });
1543
1593
  };
1594
+ /**
1595
+ * ```graphql
1596
+ * # ex.
1597
+ * {
1598
+ * getCollections {
1599
+ * name
1600
+ * documents {...}
1601
+ * }
1602
+ * }
1603
+ * ```
1604
+ *
1605
+ * @param collections
1606
+ */
1544
1607
  this.buildMultiCollectionDefinition = async (collections) => {
1545
1608
  const name = "collections";
1546
1609
  const typeName = "Collection";
@@ -1551,6 +1614,17 @@ var Builder = class {
1551
1614
  required: true
1552
1615
  });
1553
1616
  };
1617
+ /**
1618
+ * ```graphql
1619
+ * # ex.
1620
+ * {
1621
+ * node(id: $id) {
1622
+ * id
1623
+ * data {...}
1624
+ * }
1625
+ * }
1626
+ * ```
1627
+ */
1554
1628
  this.multiNodeDocument = async () => {
1555
1629
  const name = "node";
1556
1630
  const args = [
@@ -1571,6 +1645,19 @@ var Builder = class {
1571
1645
  required: true
1572
1646
  });
1573
1647
  };
1648
+ /**
1649
+ * ```graphql
1650
+ * # ex.
1651
+ * {
1652
+ * getDocument(collection: $collection, relativePath: $relativePath) {
1653
+ * id
1654
+ * data {...}
1655
+ * }
1656
+ * }
1657
+ * ```
1658
+ *
1659
+ * @param collections
1660
+ */
1574
1661
  this.multiCollectionDocument = async (collections) => {
1575
1662
  const name = "document";
1576
1663
  const args = [
@@ -1596,6 +1683,19 @@ var Builder = class {
1596
1683
  required: true
1597
1684
  });
1598
1685
  };
1686
+ /**
1687
+ * ```graphql
1688
+ * # ex.
1689
+ * {
1690
+ * addPendingDocument(collection: $collection, relativePath: $relativePath, params: $params) {
1691
+ * id
1692
+ * data {...}
1693
+ * }
1694
+ * }
1695
+ * ```
1696
+ *
1697
+ * @param collections
1698
+ */
1599
1699
  this.addMultiCollectionDocumentMutation = async () => {
1600
1700
  return astBuilder.FieldDefinition({
1601
1701
  name: "addPendingDocument",
@@ -1620,6 +1720,19 @@ var Builder = class {
1620
1720
  type: astBuilder.TYPES.MultiCollectionDocument
1621
1721
  });
1622
1722
  };
1723
+ /**
1724
+ * ```graphql
1725
+ * # ex.
1726
+ * {
1727
+ * createDocument(relativePath: $relativePath, params: $params) {
1728
+ * id
1729
+ * data {...}
1730
+ * }
1731
+ * }
1732
+ * ```
1733
+ *
1734
+ * @param collections
1735
+ */
1623
1736
  this.buildCreateCollectionDocumentMutation = async (collections) => {
1624
1737
  return astBuilder.FieldDefinition({
1625
1738
  name: "createDocument",
@@ -1647,6 +1760,19 @@ var Builder = class {
1647
1760
  type: astBuilder.TYPES.MultiCollectionDocument
1648
1761
  });
1649
1762
  };
1763
+ /**
1764
+ * ```graphql
1765
+ * # ex.
1766
+ * {
1767
+ * updateDocument(relativePath: $relativePath, params: $params) {
1768
+ * id
1769
+ * data {...}
1770
+ * }
1771
+ * }
1772
+ * ```
1773
+ *
1774
+ * @param collections
1775
+ */
1650
1776
  this.buildUpdateCollectionDocumentMutation = async (collections) => {
1651
1777
  return astBuilder.FieldDefinition({
1652
1778
  name: "updateDocument",
@@ -1674,6 +1800,19 @@ var Builder = class {
1674
1800
  type: astBuilder.TYPES.MultiCollectionDocument
1675
1801
  });
1676
1802
  };
1803
+ /**
1804
+ * ```graphql
1805
+ * # ex.
1806
+ * {
1807
+ * deleteDocument(relativePath: $relativePath, params: $params) {
1808
+ * id
1809
+ * data {...}
1810
+ * }
1811
+ * }
1812
+ * ```
1813
+ *
1814
+ * @param collections
1815
+ */
1677
1816
  this.buildDeleteCollectionDocumentMutation = async (collections) => {
1678
1817
  return astBuilder.FieldDefinition({
1679
1818
  name: "deleteDocument",
@@ -1693,6 +1832,19 @@ var Builder = class {
1693
1832
  type: astBuilder.TYPES.MultiCollectionDocument
1694
1833
  });
1695
1834
  };
1835
+ /**
1836
+ * ```graphql
1837
+ * # ex.
1838
+ * {
1839
+ * createFolder(folderName: $folderName, params: $params) {
1840
+ * id
1841
+ * data {...}
1842
+ * }
1843
+ * }
1844
+ * ```
1845
+ *
1846
+ * @param collections
1847
+ */
1696
1848
  this.buildCreateCollectionFolderMutation = async () => {
1697
1849
  return astBuilder.FieldDefinition({
1698
1850
  name: "createFolder",
@@ -1712,6 +1864,19 @@ var Builder = class {
1712
1864
  type: astBuilder.TYPES.MultiCollectionDocument
1713
1865
  });
1714
1866
  };
1867
+ /**
1868
+ * ```graphql
1869
+ * # ex.
1870
+ * {
1871
+ * getPostDocument(relativePath: $relativePath) {
1872
+ * id
1873
+ * data {...}
1874
+ * }
1875
+ * }
1876
+ * ```
1877
+ *
1878
+ * @param collection
1879
+ */
1715
1880
  this.collectionDocument = async (collection) => {
1716
1881
  const name = NAMER.queryName([collection.name]);
1717
1882
  const type = await this._buildCollectionDocumentType(collection);
@@ -1772,6 +1937,20 @@ var Builder = class {
1772
1937
  const args = [];
1773
1938
  return astBuilder.FieldDefinition({ type, name, args, required: false });
1774
1939
  };
1940
+ /**
1941
+ * Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
1942
+ * ```graphql
1943
+ * # ex.
1944
+ * fragment AuthorsParts on Authors {
1945
+ * name
1946
+ * avatar
1947
+ * ...
1948
+ * }
1949
+ * ```
1950
+ *
1951
+ * @public
1952
+ * @param collection a Tina Cloud collection
1953
+ */
1775
1954
  this.collectionFragment = async (collection) => {
1776
1955
  const name = NAMER.dataTypeName(collection.namespace);
1777
1956
  const fragmentName = NAMER.fragmentName(collection.namespace);
@@ -1785,6 +1964,20 @@ var Builder = class {
1785
1964
  selections: filterSelections(selections)
1786
1965
  });
1787
1966
  };
1967
+ /**
1968
+ * Given a collection this function returns its selections set. For example for Post this would return
1969
+ *
1970
+ * "
1971
+ * body
1972
+ * title
1973
+ * ... on Author {
1974
+ * name
1975
+ * heroImg
1976
+ * }
1977
+ *
1978
+ * But in the AST format
1979
+ *
1980
+ * */
1788
1981
  this._getCollectionFragmentSelections = async (collection, depth) => {
1789
1982
  var _a;
1790
1983
  const selections = [];
@@ -1868,9 +2061,9 @@ var Builder = class {
1868
2061
  ]
1869
2062
  });
1870
2063
  }
2064
+ // TODO: Should we throw here?
1871
2065
  case "reference":
1872
- if (depth >= this.maxDepth)
1873
- return false;
2066
+ if (depth >= this.maxDepth) return false;
1874
2067
  if (!("collections" in field)) {
1875
2068
  return false;
1876
2069
  }
@@ -1902,6 +2095,7 @@ var Builder = class {
1902
2095
  name: field.name,
1903
2096
  selections: [
1904
2097
  ...selections,
2098
+ // This is ... on Document { id }
1905
2099
  {
1906
2100
  kind: "InlineFragment",
1907
2101
  typeCondition: {
@@ -1932,6 +2126,19 @@ var Builder = class {
1932
2126
  });
1933
2127
  }
1934
2128
  };
2129
+ /**
2130
+ * ```graphql
2131
+ * # ex.
2132
+ * mutation {
2133
+ * updatePostDocument(relativePath: $relativePath, params: $params) {
2134
+ * id
2135
+ * data {...}
2136
+ * }
2137
+ * }
2138
+ * ```
2139
+ *
2140
+ * @param collection
2141
+ */
1935
2142
  this.updateCollectionDocumentMutation = async (collection) => {
1936
2143
  return astBuilder.FieldDefinition({
1937
2144
  type: await this._buildCollectionDocumentType(collection),
@@ -1951,6 +2158,19 @@ var Builder = class {
1951
2158
  ]
1952
2159
  });
1953
2160
  };
2161
+ /**
2162
+ * ```graphql
2163
+ * # ex.
2164
+ * mutation {
2165
+ * createPostDocument(relativePath: $relativePath, params: $params) {
2166
+ * id
2167
+ * data {...}
2168
+ * }
2169
+ * }
2170
+ * ```
2171
+ *
2172
+ * @param collection
2173
+ */
1954
2174
  this.createCollectionDocumentMutation = async (collection) => {
1955
2175
  return astBuilder.FieldDefinition({
1956
2176
  type: await this._buildCollectionDocumentType(collection),
@@ -1970,6 +2190,22 @@ var Builder = class {
1970
2190
  ]
1971
2191
  });
1972
2192
  };
2193
+ /**
2194
+ * ```graphql
2195
+ * # ex.
2196
+ * {
2197
+ * getPostList(first: 10) {
2198
+ * edges {
2199
+ * node {
2200
+ * id
2201
+ * }
2202
+ * }
2203
+ * }
2204
+ * }
2205
+ * ```
2206
+ *
2207
+ * @param collection
2208
+ */
1973
2209
  this.collectionDocumentList = async (collection) => {
1974
2210
  const connectionName = NAMER.referenceConnectionType(collection.namespace);
1975
2211
  this.addToLookupMap({
@@ -1985,6 +2221,10 @@ var Builder = class {
1985
2221
  collection
1986
2222
  });
1987
2223
  };
2224
+ /**
2225
+ * GraphQL type definitions which remain unchanged regardless
2226
+ * of the supplied Tina schema. Ex. "node" interface
2227
+ */
1988
2228
  this.buildStaticDefinitions = () => staticDefinitions;
1989
2229
  this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
1990
2230
  const documentTypeName = NAMER.documentTypeName(collection.namespace);
@@ -2489,6 +2729,7 @@ var Builder = class {
2489
2729
  name: NAMER.dataFilterTypeName(namespace),
2490
2730
  fields: await sequential(collections, async (collection2) => {
2491
2731
  return astBuilder.InputValueDefinition({
2732
+ // @ts-ignore
2492
2733
  name: collection2.name,
2493
2734
  type: NAMER.dataFilterTypeName(collection2.namespace)
2494
2735
  });
@@ -2678,7 +2919,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2678
2919
  });
2679
2920
  };
2680
2921
  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;
2922
+ this.maxDepth = // @ts-ignore
2923
+ (_d = (_c = (_b = (_a = config == null ? void 0 : config.tinaSchema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.client) == null ? void 0 : _c.referenceDepth) != null ? _d : 2;
2682
2924
  this.tinaSchema = config.tinaSchema;
2683
2925
  this.lookupMap = {};
2684
2926
  }
@@ -2689,8 +2931,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
2689
2931
  selections.push(field);
2690
2932
  });
2691
2933
  const filteredSelections = filterSelections(selections);
2692
- if (!filteredSelections.length)
2693
- return false;
2934
+ if (!filteredSelections.length) return false;
2694
2935
  return astBuilder.InlineFragmentDefinition({
2695
2936
  selections: filteredSelections,
2696
2937
  name: NAMER.dataTypeName(template.namespace)
@@ -2771,6 +3012,7 @@ var validationCollectionsPathAndMatch = (collections) => {
2771
3012
  }).map((x) => `${x.path}${x.format || "md"}`);
2772
3013
  if (noMatchCollections.length !== new Set(noMatchCollections).size) {
2773
3014
  throw new Error(
3015
+ // TODO: add a link to the docs
2774
3016
  "Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
2775
3017
  );
2776
3018
  }
@@ -2882,7 +3124,7 @@ var validateField = async (field) => {
2882
3124
  // package.json
2883
3125
  var package_default = {
2884
3126
  name: "@tinacms/graphql",
2885
- version: "1.5.5",
3127
+ version: "1.5.9",
2886
3128
  main: "dist/index.js",
2887
3129
  module: "dist/index.mjs",
2888
3130
  typings: "dist/index.d.ts",
@@ -2926,7 +3168,7 @@ var package_default = {
2926
3168
  "isomorphic-git": "^1.27.1",
2927
3169
  "js-sha1": "^0.6.0",
2928
3170
  "js-yaml": "^3.14.1",
2929
- "jsonpath-plus": "^6.0.1",
3171
+ "jsonpath-plus": "10.1.0",
2930
3172
  "lodash.clonedeep": "^4.5.0",
2931
3173
  "lodash.set": "^4.3.2",
2932
3174
  "lodash.uniqby": "^4.7.0",
@@ -2958,7 +3200,7 @@ var package_default = {
2958
3200
  "@types/lru-cache": "^5.1.1",
2959
3201
  "@types/mdast": "^3.0.15",
2960
3202
  "@types/micromatch": "^4.0.9",
2961
- "@types/node": "^22.7.4",
3203
+ "@types/node": "^22.9.0",
2962
3204
  "@types/normalize-path": "^3.0.2",
2963
3205
  "@types/ws": "^7.4.7",
2964
3206
  "@types/yup": "^0.29.14",
@@ -2968,7 +3210,7 @@ var package_default = {
2968
3210
  "jest-matcher-utils": "^29.7.0",
2969
3211
  "memory-level": "^1.0.0",
2970
3212
  nodemon: "3.1.4",
2971
- typescript: "^5.6.2"
3213
+ typescript: "^5.6.3"
2972
3214
  }
2973
3215
  };
2974
3216
 
@@ -3039,6 +3281,7 @@ var _buildFragments = async (builder, tinaSchema) => {
3039
3281
  const fragDoc = {
3040
3282
  kind: "Document",
3041
3283
  definitions: (0, import_lodash3.default)(
3284
+ // @ts-ignore
3042
3285
  extractInlineTypes(fragmentDefinitionsFields),
3043
3286
  (node) => node.name.value
3044
3287
  )
@@ -3062,6 +3305,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3062
3305
  fragName,
3063
3306
  queryName: queryListName,
3064
3307
  filterType: queryFilterTypeName,
3308
+ // look for flag to see if the data layer is enabled
3065
3309
  dataLayer: Boolean(
3066
3310
  (_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
3067
3311
  )
@@ -3071,6 +3315,7 @@ var _buildQueries = async (builder, tinaSchema) => {
3071
3315
  const queryDoc = {
3072
3316
  kind: "Document",
3073
3317
  definitions: (0, import_lodash3.default)(
3318
+ // @ts-ignore
3074
3319
  extractInlineTypes(operationsDefinitions),
3075
3320
  (node) => node.name.value
3076
3321
  )
@@ -3159,6 +3404,7 @@ var _buildSchema = async (builder, tinaSchema) => {
3159
3404
  return {
3160
3405
  kind: "Document",
3161
3406
  definitions: (0, import_lodash3.default)(
3407
+ // @ts-ignore
3162
3408
  extractInlineTypes(definitions),
3163
3409
  (node) => node.name.value
3164
3410
  )
@@ -3175,6 +3421,9 @@ var import_isValid = __toESM(require("date-fns/isValid/index.js"));
3175
3421
  // src/mdx/index.ts
3176
3422
  var import_mdx = require("@tinacms/mdx");
3177
3423
 
3424
+ // src/resolver/index.ts
3425
+ var import_jsonpath_plus2 = require("jsonpath-plus");
3426
+
3178
3427
  // src/resolver/error.ts
3179
3428
  var TinaGraphQLError = class extends Error {
3180
3429
  constructor(message, extensions) {
@@ -3360,8 +3609,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
3360
3609
  }
3361
3610
  if (Array.isArray(value)) {
3362
3611
  return value.map((v) => {
3363
- if (!v || typeof v !== "string")
3364
- return v;
3612
+ if (!v || typeof v !== "string") return v;
3365
3613
  const cleanMediaRoot = cleanUpSlashes(
3366
3614
  schema.config.media.tina.mediaRoot
3367
3615
  );
@@ -3389,8 +3637,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
3389
3637
  }
3390
3638
  if (Array.isArray(value)) {
3391
3639
  return value.map((v) => {
3392
- if (!v || typeof v !== "string")
3393
- return v;
3640
+ if (!v || typeof v !== "string") return v;
3394
3641
  const strippedValue = v.replace(cleanMediaRoot, "");
3395
3642
  return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
3396
3643
  });
@@ -3409,8 +3656,7 @@ var cleanUpSlashes = (path7) => {
3409
3656
  };
3410
3657
  var hasTinaMediaConfig = (schema) => {
3411
3658
  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;
3659
+ if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
3414
3660
  if (typeof ((_e = (_d = (_c = schema.config) == null ? void 0 : _c.media) == null ? void 0 : _d.tina) == null ? void 0 : _e.publicFolder) !== "string" && typeof ((_h = (_g = (_f = schema.config) == null ? void 0 : _f.media) == null ? void 0 : _g.tina) == null ? void 0 : _h.mediaRoot) !== "string")
3415
3661
  return false;
3416
3662
  return true;
@@ -3454,6 +3700,7 @@ var LevelProxyHandler = {
3454
3700
  } else if (property === "sublevel") {
3455
3701
  return (...args) => {
3456
3702
  return new Proxy(
3703
+ // eslint-disable-next-line prefer-spread
3457
3704
  target[property].apply(target, args),
3458
3705
  LevelProxyHandler
3459
3706
  );
@@ -4332,6 +4579,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
4332
4579
  result.push({
4333
4580
  type: opType,
4334
4581
  key: `${collection.path}/${subFolderKey}.${collection.format}`,
4582
+ // replace the root with the collection path
4335
4583
  sublevel: indexSublevel,
4336
4584
  value: {}
4337
4585
  });
@@ -4447,6 +4695,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4447
4695
  case "password":
4448
4696
  accumulator[field.name] = {
4449
4697
  value: void 0,
4698
+ // never resolve the password hash
4450
4699
  passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
4451
4700
  };
4452
4701
  break;
@@ -4541,7 +4790,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
4541
4790
  }
4542
4791
  return accumulator;
4543
4792
  };
4544
- var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config, isAudit) => {
4793
+ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config, isAudit, hasReferences) => {
4545
4794
  const collection = tinaSchema.getCollection(rawData._collection);
4546
4795
  try {
4547
4796
  const template = tinaSchema.getTemplateForData({
@@ -4595,6 +4844,7 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4595
4844
  basename,
4596
4845
  filename,
4597
4846
  extension,
4847
+ hasReferences,
4598
4848
  path: fullPath,
4599
4849
  relativePath,
4600
4850
  breadcrumbs,
@@ -4614,6 +4864,25 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
4614
4864
  throw e;
4615
4865
  }
4616
4866
  };
4867
+ var updateObjectWithJsonPath = (obj, path7, newValue) => {
4868
+ if (!path7.includes(".") && !path7.includes("[")) {
4869
+ if (path7 in obj) {
4870
+ obj[path7] = newValue;
4871
+ }
4872
+ return obj;
4873
+ }
4874
+ const parentPath = path7.replace(/\.[^.]+$/, "");
4875
+ const keyToUpdate = path7.match(/[^.]+$/)[0];
4876
+ const parents = (0, import_jsonpath_plus2.JSONPath)({ path: parentPath, json: obj, resultType: "value" });
4877
+ if (parents.length > 0) {
4878
+ parents.forEach((parent) => {
4879
+ if (parent && typeof parent === "object" && keyToUpdate in parent) {
4880
+ parent[keyToUpdate] = newValue;
4881
+ }
4882
+ });
4883
+ }
4884
+ return obj;
4885
+ };
4617
4886
  var Resolver = class {
4618
4887
  constructor(init) {
4619
4888
  this.init = init;
@@ -4621,6 +4890,7 @@ var Resolver = class {
4621
4890
  const collection = this.tinaSchema.getCollection(collectionName);
4622
4891
  const extraFields = {};
4623
4892
  return {
4893
+ // return the collection and hasDocuments to resolve documents at a lower level
4624
4894
  documents: { collection, hasDocuments },
4625
4895
  ...collection,
4626
4896
  ...extraFields
@@ -4655,17 +4925,19 @@ var Resolver = class {
4655
4925
  );
4656
4926
  }
4657
4927
  };
4658
- this.getDocument = async (fullPath) => {
4928
+ this.getDocument = async (fullPath, opts = {}) => {
4659
4929
  if (typeof fullPath !== "string") {
4660
4930
  throw new Error(`fullPath must be of type string for getDocument request`);
4661
4931
  }
4662
4932
  const rawData = await this.getRaw(fullPath);
4933
+ const hasReferences = (opts == null ? void 0 : opts.checkReferences) ? await this.hasReferences(fullPath, opts.collection) : void 0;
4663
4934
  return transformDocumentIntoPayload(
4664
4935
  fullPath,
4665
4936
  rawData,
4666
4937
  this.tinaSchema,
4667
4938
  this.config,
4668
- this.isAudit
4939
+ this.isAudit,
4940
+ hasReferences
4669
4941
  );
4670
4942
  };
4671
4943
  this.deleteDocument = async (fullPath) => {
@@ -4705,7 +4977,9 @@ var Resolver = class {
4705
4977
  );
4706
4978
  } else {
4707
4979
  return this.buildFieldMutations(
4980
+ // @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
4708
4981
  fieldValue,
4982
+ //@ts-ignore
4709
4983
  objectTemplate,
4710
4984
  existingData
4711
4985
  );
@@ -4717,6 +4991,7 @@ var Resolver = class {
4717
4991
  fieldValue.map(async (item) => {
4718
4992
  if (typeof item === "string") {
4719
4993
  throw new Error(
4994
+ //@ts-ignore
4720
4995
  `Expected object for template value for field ${field.name}`
4721
4996
  );
4722
4997
  }
@@ -4725,16 +5000,19 @@ var Resolver = class {
4725
5000
  });
4726
5001
  const [templateName] = Object.entries(item)[0];
4727
5002
  const template = templates.find(
5003
+ //@ts-ignore
4728
5004
  (template2) => template2.name === templateName
4729
5005
  );
4730
5006
  if (!template) {
4731
5007
  throw new Error(`Expected to find template ${templateName}`);
4732
5008
  }
4733
5009
  return {
5010
+ // @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
4734
5011
  ...await this.buildFieldMutations(
4735
5012
  item[template.name],
4736
5013
  template
4737
5014
  ),
5015
+ //@ts-ignore
4738
5016
  _template: template.name
4739
5017
  };
4740
5018
  })
@@ -4742,6 +5020,7 @@ var Resolver = class {
4742
5020
  } else {
4743
5021
  if (typeof fieldValue === "string") {
4744
5022
  throw new Error(
5023
+ //@ts-ignore
4745
5024
  `Expected object for template value for field ${field.name}`
4746
5025
  );
4747
5026
  }
@@ -4750,16 +5029,19 @@ var Resolver = class {
4750
5029
  });
4751
5030
  const [templateName] = Object.entries(fieldValue)[0];
4752
5031
  const template = templates.find(
5032
+ //@ts-ignore
4753
5033
  (template2) => template2.name === templateName
4754
5034
  );
4755
5035
  if (!template) {
4756
5036
  throw new Error(`Expected to find template ${templateName}`);
4757
5037
  }
4758
5038
  return {
5039
+ // @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
4759
5040
  ...await this.buildFieldMutations(
4760
5041
  fieldValue[template.name],
4761
5042
  template
4762
5043
  ),
5044
+ //@ts-ignore
4763
5045
  _template: template.name
4764
5046
  };
4765
5047
  }
@@ -4799,6 +5081,7 @@ var Resolver = class {
4799
5081
  return this.getDocument(realPath);
4800
5082
  }
4801
5083
  const params = await this.buildObjectMutations(
5084
+ // @ts-ignore
4802
5085
  args.params[collection.name],
4803
5086
  collection
4804
5087
  );
@@ -4844,6 +5127,7 @@ var Resolver = class {
4844
5127
  const values = {
4845
5128
  ...oldDoc,
4846
5129
  ...await this.buildFieldMutations(
5130
+ // @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
4847
5131
  templateParams,
4848
5132
  template,
4849
5133
  doc == null ? void 0 : doc._rawData
@@ -4857,6 +5141,7 @@ var Resolver = class {
4857
5141
  return this.getDocument(realPath);
4858
5142
  }
4859
5143
  const params = await this.buildObjectMutations(
5144
+ //@ts-ignore
4860
5145
  isCollectionSpecific ? args.params : args.params[collection.name],
4861
5146
  collection,
4862
5147
  doc == null ? void 0 : doc._rawData
@@ -4864,6 +5149,10 @@ var Resolver = class {
4864
5149
  await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
4865
5150
  return this.getDocument(realPath);
4866
5151
  };
5152
+ /**
5153
+ * Returns top-level fields which are not defined in the collection, so their
5154
+ * values are not eliminated from Tina when new values are saved
5155
+ */
4867
5156
  this.resolveLegacyValues = (oldDoc, collection) => {
4868
5157
  const legacyValues = {};
4869
5158
  Object.entries(oldDoc).forEach(([key, value]) => {
@@ -4969,6 +5258,22 @@ var Resolver = class {
4969
5258
  if (isDeletion) {
4970
5259
  const doc = await this.getDocument(realPath);
4971
5260
  await this.deleteDocument(realPath);
5261
+ if (await this.hasReferences(realPath, collection)) {
5262
+ const collRefs = await this.findReferences(realPath, collection);
5263
+ for (const [collection2, refFields] of Object.entries(collRefs)) {
5264
+ for (const [refPath, refs] of Object.entries(refFields)) {
5265
+ let refDoc = await this.getRaw(refPath);
5266
+ for (const ref of refs) {
5267
+ refDoc = updateObjectWithJsonPath(
5268
+ refDoc,
5269
+ ref.path.join("."),
5270
+ null
5271
+ );
5272
+ }
5273
+ await this.database.put(refPath, refDoc, collection2);
5274
+ }
5275
+ }
5276
+ }
4972
5277
  return doc;
4973
5278
  }
4974
5279
  if (isUpdateName) {
@@ -4987,6 +5292,20 @@ var Resolver = class {
4987
5292
  );
4988
5293
  await this.database.put(newRealPath, doc._rawData, collection.name);
4989
5294
  await this.deleteDocument(realPath);
5295
+ const collRefs = await this.findReferences(realPath, collection);
5296
+ for (const [collection2, refFields] of Object.entries(collRefs)) {
5297
+ for (const [refPath, refs] of Object.entries(refFields)) {
5298
+ let refDoc = await this.getRaw(refPath);
5299
+ for (const ref of refs) {
5300
+ refDoc = updateObjectWithJsonPath(
5301
+ refDoc,
5302
+ ref.path.join("."),
5303
+ newRealPath
5304
+ );
5305
+ }
5306
+ await this.database.put(refPath, refDoc, collection2);
5307
+ }
5308
+ }
4990
5309
  return this.getDocument(newRealPath);
4991
5310
  }
4992
5311
  if (alreadyExists === false) {
@@ -5000,7 +5319,10 @@ var Resolver = class {
5000
5319
  isCollectionSpecific
5001
5320
  });
5002
5321
  } else {
5003
- return this.getDocument(realPath);
5322
+ return this.getDocument(realPath, {
5323
+ collection,
5324
+ checkReferences: true
5325
+ });
5004
5326
  }
5005
5327
  };
5006
5328
  this.resolveCollectionConnections = async ({ ids }) => {
@@ -5037,6 +5359,7 @@ var Resolver = class {
5037
5359
  },
5038
5360
  collection: referencedCollection,
5039
5361
  hydrator: (path7) => path7
5362
+ // just return the path
5040
5363
  }
5041
5364
  );
5042
5365
  const { edges } = resolvedCollectionConnection;
@@ -5104,6 +5427,92 @@ var Resolver = class {
5104
5427
  }
5105
5428
  };
5106
5429
  };
5430
+ /**
5431
+ * Checks if a document has references to it
5432
+ * @param id The id of the document to check for references
5433
+ * @param c The collection to check for references
5434
+ * @returns true if the document has references, false otherwise
5435
+ */
5436
+ this.hasReferences = async (id, c) => {
5437
+ let count = 0;
5438
+ const deepRefs = this.tinaSchema.findReferences(c.name);
5439
+ for (const [collection, refs] of Object.entries(deepRefs)) {
5440
+ for (const ref of refs) {
5441
+ await this.database.query(
5442
+ {
5443
+ collection,
5444
+ filterChain: makeFilterChain({
5445
+ conditions: [
5446
+ {
5447
+ filterPath: ref.path.join("."),
5448
+ filterExpression: {
5449
+ _type: "reference",
5450
+ _list: false,
5451
+ eq: id
5452
+ }
5453
+ }
5454
+ ]
5455
+ }),
5456
+ sort: ref.field.name
5457
+ },
5458
+ (refId) => {
5459
+ count++;
5460
+ return refId;
5461
+ }
5462
+ );
5463
+ if (count) {
5464
+ return true;
5465
+ }
5466
+ }
5467
+ }
5468
+ return false;
5469
+ };
5470
+ /**
5471
+ * Finds references to a document
5472
+ * @param id the id of the document to find references to
5473
+ * @param c the collection to find references in
5474
+ * @returns references to the document in the form of a map of collection names to a list of fields that reference the document
5475
+ */
5476
+ this.findReferences = async (id, c) => {
5477
+ const references = {};
5478
+ const deepRefs = this.tinaSchema.findReferences(c.name);
5479
+ for (const [collection, refs] of Object.entries(deepRefs)) {
5480
+ for (const ref of refs) {
5481
+ await this.database.query(
5482
+ {
5483
+ collection,
5484
+ filterChain: makeFilterChain({
5485
+ conditions: [
5486
+ {
5487
+ filterPath: ref.path.join("."),
5488
+ filterExpression: {
5489
+ _type: "reference",
5490
+ _list: false,
5491
+ eq: id
5492
+ }
5493
+ }
5494
+ ]
5495
+ }),
5496
+ sort: ref.field.name
5497
+ },
5498
+ (refId) => {
5499
+ if (!references[collection]) {
5500
+ references[collection] = {};
5501
+ }
5502
+ if (!references[collection][refId]) {
5503
+ references[collection][refId] = [];
5504
+ }
5505
+ references[collection][refId].push({
5506
+ path: ref.path,
5507
+ field: ref.field
5508
+ });
5509
+ return refId;
5510
+ }
5511
+ );
5512
+ }
5513
+ }
5514
+ return references;
5515
+ };
5107
5516
  this.buildFieldMutations = async (fieldParams, template, existingData) => {
5108
5517
  var _a;
5109
5518
  const accum = {};
@@ -5191,6 +5600,27 @@ var Resolver = class {
5191
5600
  }
5192
5601
  return accum;
5193
5602
  };
5603
+ /**
5604
+ * A mutation looks nearly identical between updateDocument:
5605
+ * ```graphql
5606
+ * updateDocument(collection: $collection,relativePath: $path, params: {
5607
+ * post: {
5608
+ * title: "Hello, World"
5609
+ * }
5610
+ * })`
5611
+ * ```
5612
+ * and `updatePostDocument`:
5613
+ * ```graphql
5614
+ * updatePostDocument(relativePath: $path, params: {
5615
+ * title: "Hello, World"
5616
+ * })
5617
+ * ```
5618
+ * The problem here is that we don't know whether the payload came from `updateDocument`
5619
+ * or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
5620
+ * But we do know that when given a `args.collection` value, we can assume that
5621
+ * this was a `updateDocument` request, and thus - should grab the data
5622
+ * from the corresponding field name in the key
5623
+ */
5194
5624
  this.buildParams = (args) => {
5195
5625
  try {
5196
5626
  assertShape(
@@ -5291,7 +5721,10 @@ var resolve = async ({
5291
5721
  const graphQLSchema = (0, import_graphql5.buildASTSchema)(graphQLSchemaAst);
5292
5722
  const tinaConfig = await database.getTinaSchema();
5293
5723
  const tinaSchema = await createSchema({
5724
+ // TODO: please update all the types to import from @tinacms/schema-tools
5725
+ // @ts-ignore
5294
5726
  schema: tinaConfig,
5727
+ // @ts-ignore
5295
5728
  flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
5296
5729
  });
5297
5730
  const resolver = createResolver({
@@ -5308,8 +5741,7 @@ var resolve = async ({
5308
5741
  database
5309
5742
  },
5310
5743
  typeResolver: async (source, _args, info) => {
5311
- if (source.__typename)
5312
- return source.__typename;
5744
+ if (source.__typename) return source.__typename;
5313
5745
  const namedType = (0, import_graphql5.getNamedType)(info.returnType).toString();
5314
5746
  const lookup = await database.getLookup(namedType);
5315
5747
  if (lookup.resolveType === "unionData") {
@@ -5461,11 +5893,13 @@ var resolve = async ({
5461
5893
  (0, import_lodash4.default)(
5462
5894
  params,
5463
5895
  userField.path.slice(1),
5896
+ // remove _rawData from users path
5464
5897
  users.map((u) => {
5465
5898
  if (user[idFieldName] === u[idFieldName]) {
5466
5899
  return user;
5467
5900
  }
5468
5901
  return {
5902
+ // don't overwrite other users' passwords
5469
5903
  ...u,
5470
5904
  [passwordFieldName]: {
5471
5905
  ...u[passwordFieldName],
@@ -5488,6 +5922,9 @@ var resolve = async ({
5488
5922
  }
5489
5923
  const isCreation = lookup[info.fieldName] === "create";
5490
5924
  switch (lookup.resolveType) {
5925
+ /**
5926
+ * `node(id: $id)`
5927
+ */
5491
5928
  case "nodeDocument":
5492
5929
  assertShape(
5493
5930
  args,
@@ -5519,6 +5956,7 @@ var resolve = async ({
5519
5956
  collection: args.collection,
5520
5957
  isMutation,
5521
5958
  isCreation,
5959
+ // Right now this is the only case for deletion
5522
5960
  isDeletion: info.fieldName === "deleteDocument",
5523
5961
  isFolderCreation: info.fieldName === "createFolder",
5524
5962
  isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
@@ -5528,6 +5966,9 @@ var resolve = async ({
5528
5966
  return result;
5529
5967
  }
5530
5968
  return value;
5969
+ /**
5970
+ * eg `getMovieDocument.data.actors`
5971
+ */
5531
5972
  case "multiCollectionDocumentList":
5532
5973
  if (Array.isArray(value)) {
5533
5974
  return {
@@ -5539,7 +5980,15 @@ var resolve = async ({
5539
5980
  }
5540
5981
  if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
5541
5982
  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") {
5983
+ if (
5984
+ // 1. Make sure that the filter exists
5985
+ typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
5986
+ // @ts-ignore
5987
+ typeof ((_b = value == null ? void 0 : value.collection) == null ? void 0 : _b.name) === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
5988
+ // @ts-ignore
5989
+ Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
5990
+ typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
5991
+ ) {
5543
5992
  filter = args.filter[value.collection.name];
5544
5993
  }
5545
5994
  return resolver.resolveCollectionConnection({
@@ -5547,12 +5996,20 @@ var resolve = async ({
5547
5996
  ...args,
5548
5997
  filter
5549
5998
  },
5999
+ // @ts-ignore
5550
6000
  collection: value.collection
5551
6001
  });
5552
6002
  }
5553
6003
  throw new Error(
5554
6004
  `Expected an array for result of ${info.fieldName} at ${info.path}`
5555
6005
  );
6006
+ /**
6007
+ * Collections-specific getter
6008
+ * eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
6009
+ *
6010
+ * if coming from a query result
6011
+ * the field will be `node`
6012
+ */
5556
6013
  case "collectionDocument": {
5557
6014
  if (value) {
5558
6015
  return value;
@@ -5567,11 +6024,32 @@ var resolve = async ({
5567
6024
  });
5568
6025
  return result;
5569
6026
  }
6027
+ /**
6028
+ * Collections-specific list getter
6029
+ * eg. `getPageList`
6030
+ */
5570
6031
  case "collectionDocumentList":
5571
6032
  return resolver.resolveCollectionConnection({
5572
6033
  args,
5573
6034
  collection: tinaSchema.getCollection(lookup.collection)
5574
6035
  });
6036
+ /**
6037
+ * A polymorphic data set, it can be from a document's data
6038
+ * of any nested object which can be one of many shapes
6039
+ *
6040
+ * ```graphql
6041
+ * getPostDocument(relativePath: $relativePath) {
6042
+ * data {...} <- this part
6043
+ * }
6044
+ * ```
6045
+ * ```graphql
6046
+ * getBlockDocument(relativePath: $relativePath) {
6047
+ * data {
6048
+ * blocks {...} <- or this part
6049
+ * }
6050
+ * }
6051
+ * ```
6052
+ */
5575
6053
  case "unionData":
5576
6054
  if (!value) {
5577
6055
  if (args.relativePath) {
@@ -5636,8 +6114,7 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
5636
6114
  this.port = port || 9e3;
5637
6115
  }
5638
6116
  openConnection() {
5639
- if (this._connected)
5640
- return;
6117
+ if (this._connected) return;
5641
6118
  const socket = (0, import_net.connect)(this.port);
5642
6119
  (0, import_readable_stream.pipeline)(socket, this.createRpcStream(), socket, () => {
5643
6120
  this._connected = false;
@@ -5818,6 +6295,7 @@ var Database = class {
5818
6295
  "put",
5819
6296
  level
5820
6297
  ),
6298
+ // folder indices
5821
6299
  ...makeIndexOpsForDocument(
5822
6300
  normalizedPath,
5823
6301
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -5840,6 +6318,7 @@ var Database = class {
5840
6318
  "del",
5841
6319
  level
5842
6320
  ),
6321
+ // folder indices
5843
6322
  ...makeIndexOpsForDocument(
5844
6323
  normalizedPath,
5845
6324
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -5934,6 +6413,7 @@ var Database = class {
5934
6413
  "put",
5935
6414
  level
5936
6415
  ),
6416
+ // folder indices
5937
6417
  ...makeIndexOpsForDocument(
5938
6418
  normalizedPath,
5939
6419
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -5956,6 +6436,7 @@ var Database = class {
5956
6436
  "del",
5957
6437
  level
5958
6438
  ),
6439
+ // folder indices
5959
6440
  ...makeIndexOpsForDocument(
5960
6441
  normalizedPath,
5961
6442
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6033,6 +6514,7 @@ var Database = class {
6033
6514
  aliasedData,
6034
6515
  extension,
6035
6516
  writeTemplateKey,
6517
+ //templateInfo.type === 'union',
6036
6518
  {
6037
6519
  frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
6038
6520
  frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
@@ -6071,6 +6553,7 @@ var Database = class {
6071
6553
  SUBLEVEL_OPTIONS
6072
6554
  ).get(graphqlPath);
6073
6555
  };
6556
+ //TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
6074
6557
  this.getGraphQLSchemaFromBridge = async () => {
6075
6558
  if (!this.bridge) {
6076
6559
  throw new Error(`No bridge configured`);
@@ -6117,6 +6600,7 @@ var Database = class {
6117
6600
  for (const collection of collections) {
6118
6601
  const indexDefinitions = {
6119
6602
  [DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
6603
+ // provide a default sort key which is the file sort
6120
6604
  };
6121
6605
  if (collection.fields) {
6122
6606
  for (const field of collection.fields) {
@@ -6441,12 +6925,12 @@ var Database = class {
6441
6925
  if (collection == null ? void 0 : collection.isDetached) {
6442
6926
  level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
6443
6927
  }
6444
- const itemKey = (0, import_schema_tools3.normalizePath)(filepath);
6928
+ const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
6445
6929
  const rootSublevel = level.sublevel(
6446
6930
  CONTENT_ROOT_PREFIX,
6447
6931
  SUBLEVEL_OPTIONS
6448
6932
  );
6449
- const item = await rootSublevel.get(itemKey);
6933
+ const item = await rootSublevel.get(normalizedPath);
6450
6934
  if (item) {
6451
6935
  const folderTreeBuilder = new FolderTreeBuilder();
6452
6936
  const folderKey = folderTreeBuilder.update(
@@ -6455,15 +6939,16 @@ var Database = class {
6455
6939
  );
6456
6940
  await this.contentLevel.batch([
6457
6941
  ...makeIndexOpsForDocument(
6458
- filepath,
6942
+ normalizedPath,
6459
6943
  collection.name,
6460
6944
  collectionIndexDefinitions,
6461
6945
  item,
6462
6946
  "del",
6463
6947
  level
6464
6948
  ),
6949
+ // folder indices
6465
6950
  ...makeIndexOpsForDocument(
6466
- filepath,
6951
+ normalizedPath,
6467
6952
  `${collection.name}_${folderKey}`,
6468
6953
  collectionIndexDefinitions,
6469
6954
  item,
@@ -6472,17 +6957,17 @@ var Database = class {
6472
6957
  ),
6473
6958
  {
6474
6959
  type: "del",
6475
- key: itemKey,
6960
+ key: normalizedPath,
6476
6961
  sublevel: rootSublevel
6477
6962
  }
6478
6963
  ]);
6479
6964
  }
6480
6965
  if (!(collection == null ? void 0 : collection.isDetached)) {
6481
6966
  if (this.bridge) {
6482
- await this.bridge.delete((0, import_schema_tools3.normalizePath)(filepath));
6967
+ await this.bridge.delete(normalizedPath);
6483
6968
  }
6484
6969
  try {
6485
- await this.onDelete((0, import_schema_tools3.normalizePath)(filepath));
6970
+ await this.onDelete(normalizedPath);
6486
6971
  } catch (e) {
6487
6972
  throw new import_graphql6.GraphQLError(
6488
6973
  `Error running onDelete hook for ${filepath}: ${e}`,
@@ -6616,6 +7101,9 @@ var Database = class {
6616
7101
  info: templateInfo
6617
7102
  };
6618
7103
  }
7104
+ /**
7105
+ * Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
7106
+ */
6619
7107
  clearCache() {
6620
7108
  this.tinaSchema = null;
6621
7109
  this._lookup = null;
@@ -6712,6 +7200,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
6712
7200
  "put",
6713
7201
  level
6714
7202
  ),
7203
+ // folder indexes
6715
7204
  ...makeIndexOpsForDocument(
6716
7205
  normalizedPath,
6717
7206
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -6797,6 +7286,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
6797
7286
  "del",
6798
7287
  database.contentLevel
6799
7288
  ),
7289
+ // folder indexes
6800
7290
  ...makeIndexOpsForDocument(
6801
7291
  itemKey,
6802
7292
  `${collection == null ? void 0 : collection.name}_${folderKey}`,
@@ -7012,17 +7502,26 @@ var IsomorphicBridge = class {
7012
7502
  getAuthor() {
7013
7503
  return {
7014
7504
  ...this.author,
7015
- timestamp: Math.round(new Date().getTime() / 1e3),
7505
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7016
7506
  timezoneOffset: 0
7017
7507
  };
7018
7508
  }
7019
7509
  getCommitter() {
7020
7510
  return {
7021
7511
  ...this.committer,
7022
- timestamp: Math.round(new Date().getTime() / 1e3),
7512
+ timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
7023
7513
  timezoneOffset: 0
7024
7514
  };
7025
7515
  }
7516
+ /**
7517
+ * Recursively populate paths matching `pattern` for the given `entry`
7518
+ *
7519
+ * @param pattern - pattern to filter paths by
7520
+ * @param entry - TreeEntry to start building list from
7521
+ * @param path - base path
7522
+ * @param results
7523
+ * @private
7524
+ */
7026
7525
  async listEntries({
7027
7526
  pattern,
7028
7527
  entry,
@@ -7055,6 +7554,15 @@ var IsomorphicBridge = class {
7055
7554
  });
7056
7555
  }
7057
7556
  }
7557
+ /**
7558
+ * For the specified path, returns an object with an array containing the parts of the path (pathParts)
7559
+ * and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
7560
+ * pathEntries are placeholders for non-existent entries.
7561
+ *
7562
+ * @param path - path being resolved
7563
+ * @param ref - ref to resolve path entries for
7564
+ * @private
7565
+ */
7058
7566
  async resolvePathEntries(path7, ref) {
7059
7567
  let pathParts = path7.split("/");
7060
7568
  const result = await import_isomorphic_git2.default.walk({
@@ -7085,6 +7593,17 @@ var IsomorphicBridge = class {
7085
7593
  }
7086
7594
  return { pathParts, pathEntries };
7087
7595
  }
7596
+ /**
7597
+ * Updates tree entry and associated parent tree entries
7598
+ *
7599
+ * @param existingOid - the existing OID
7600
+ * @param updatedOid - the updated OID
7601
+ * @param path - the path of the entry being updated
7602
+ * @param type - the type of the entry being updated (blob or tree)
7603
+ * @param pathEntries - parent path entries
7604
+ * @param pathParts - parent path parts
7605
+ * @private
7606
+ */
7088
7607
  async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
7089
7608
  const lastIdx = pathEntries.length - 1;
7090
7609
  const parentEntry = pathEntries[lastIdx];
@@ -7140,6 +7659,13 @@ var IsomorphicBridge = class {
7140
7659
  );
7141
7660
  }
7142
7661
  }
7662
+ /**
7663
+ * Creates a commit for the specified tree and updates the specified ref to point to the commit
7664
+ *
7665
+ * @param treeSha - sha of the new tree
7666
+ * @param ref - the ref that should be updated
7667
+ * @private
7668
+ */
7143
7669
  async commitTree(treeSha, ref) {
7144
7670
  const commitSha = await import_isomorphic_git2.default.writeCommit({
7145
7671
  ...this.isomorphicConfig,
@@ -7152,6 +7678,7 @@ var IsomorphicBridge = class {
7152
7678
  })
7153
7679
  ],
7154
7680
  message: this.commitMessage,
7681
+ // TODO these should be configurable
7155
7682
  author: this.getAuthor(),
7156
7683
  committer: this.getCommitter()
7157
7684
  }
@@ -7390,5 +7917,5 @@ var buildSchema = async (config, flags) => {
7390
7917
  transformDocument,
7391
7918
  transformDocumentIntoPayload
7392
7919
  });
7393
- //! Replaces _.flattenDeep()
7394
7920
  //! Replaces _.get()
7921
+ //! Replaces _.flattenDeep()