@tinacms/graphql 1.5.9 → 1.5.11
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/ast-builder/index.d.ts +0 -1
- package/dist/index.js +443 -97
- package/dist/index.mjs +414 -72
- package/package.json +10 -11
package/dist/index.js
CHANGED
|
@@ -17,6 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
24
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
25
|
mod
|
|
22
26
|
));
|
|
@@ -130,6 +134,15 @@ var SysFieldDefinition = {
|
|
|
130
134
|
selectionSet: {
|
|
131
135
|
kind: "SelectionSet",
|
|
132
136
|
selections: [
|
|
137
|
+
// {
|
|
138
|
+
// kind: 'Field' as const,
|
|
139
|
+
// name: {
|
|
140
|
+
// kind: 'Name' as const,
|
|
141
|
+
// value: 'title',
|
|
142
|
+
// },
|
|
143
|
+
// arguments: [],
|
|
144
|
+
// directives: [],
|
|
145
|
+
// },
|
|
133
146
|
{
|
|
134
147
|
kind: "Field",
|
|
135
148
|
name: {
|
|
@@ -197,6 +210,10 @@ var SysFieldDefinition = {
|
|
|
197
210
|
}
|
|
198
211
|
};
|
|
199
212
|
var astBuilder = {
|
|
213
|
+
/**
|
|
214
|
+
* `FormFieldBuilder` acts as a shortcut to building an entire `ObjectTypeDefinition`, we use this
|
|
215
|
+
* because all Tina field objects share a common set of fields ('name', 'label', 'component')
|
|
216
|
+
*/
|
|
200
217
|
FormFieldBuilder: ({
|
|
201
218
|
name,
|
|
202
219
|
additionalFields
|
|
@@ -420,6 +437,8 @@ var astBuilder = {
|
|
|
420
437
|
kind: "Name",
|
|
421
438
|
value: name
|
|
422
439
|
},
|
|
440
|
+
// @ts-ignore FIXME; this is being handled properly but we're lying to
|
|
441
|
+
// ts and then fixing it in the `extractInlineTypes` function
|
|
423
442
|
fields
|
|
424
443
|
}),
|
|
425
444
|
UnionTypeDefinition: ({
|
|
@@ -432,6 +451,8 @@ var astBuilder = {
|
|
|
432
451
|
value: name
|
|
433
452
|
},
|
|
434
453
|
directives: [],
|
|
454
|
+
// @ts-ignore FIXME; this is being handled properly but we're lying to
|
|
455
|
+
// ts and then fixing it in the `extractInlineTypes` function
|
|
435
456
|
types: types.map((name2) => ({
|
|
436
457
|
kind: "NamedType",
|
|
437
458
|
name: {
|
|
@@ -528,8 +549,11 @@ var astBuilder = {
|
|
|
528
549
|
string: "String",
|
|
529
550
|
boolean: "Boolean",
|
|
530
551
|
number: "Float",
|
|
552
|
+
// FIXME - needs to be float or int
|
|
531
553
|
datetime: "String",
|
|
554
|
+
// FIXME
|
|
532
555
|
image: "String",
|
|
556
|
+
// FIXME
|
|
533
557
|
text: "String"
|
|
534
558
|
};
|
|
535
559
|
return scalars[type];
|
|
@@ -1028,8 +1052,7 @@ var astBuilder = {
|
|
|
1028
1052
|
}
|
|
1029
1053
|
};
|
|
1030
1054
|
var capitalize = (s) => {
|
|
1031
|
-
if (typeof s !== "string")
|
|
1032
|
-
return "";
|
|
1055
|
+
if (typeof s !== "string") return "";
|
|
1033
1056
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
1034
1057
|
};
|
|
1035
1058
|
var extractInlineTypes = (item) => {
|
|
@@ -1072,41 +1095,6 @@ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
|
|
|
1072
1095
|
yield maybeNode;
|
|
1073
1096
|
visited.add(maybeNode);
|
|
1074
1097
|
}
|
|
1075
|
-
function addNamespaceToSchema(maybeNode, namespace = []) {
|
|
1076
|
-
if (typeof maybeNode === "string") {
|
|
1077
|
-
return maybeNode;
|
|
1078
|
-
}
|
|
1079
|
-
if (typeof maybeNode === "boolean") {
|
|
1080
|
-
return maybeNode;
|
|
1081
|
-
}
|
|
1082
|
-
const newNode = maybeNode;
|
|
1083
|
-
const keys = Object.keys(maybeNode);
|
|
1084
|
-
Object.values(maybeNode).map((m, index) => {
|
|
1085
|
-
const key = keys[index];
|
|
1086
|
-
if (Array.isArray(m)) {
|
|
1087
|
-
newNode[key] = m.map((element) => {
|
|
1088
|
-
if (!element) {
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
if (!element.hasOwnProperty("name")) {
|
|
1092
|
-
return element;
|
|
1093
|
-
}
|
|
1094
|
-
const value = element.name || element.value;
|
|
1095
|
-
return addNamespaceToSchema(element, [...namespace, value]);
|
|
1096
|
-
});
|
|
1097
|
-
} else {
|
|
1098
|
-
if (!m) {
|
|
1099
|
-
return;
|
|
1100
|
-
}
|
|
1101
|
-
if (!m.hasOwnProperty("name")) {
|
|
1102
|
-
newNode[key] = m;
|
|
1103
|
-
} else {
|
|
1104
|
-
newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
});
|
|
1108
|
-
return { ...newNode, namespace };
|
|
1109
|
-
}
|
|
1110
1098
|
var generateNamespacedFieldName = (names, suffix = "") => {
|
|
1111
1099
|
return (suffix ? [...names, suffix] : names).map(capitalize).join("");
|
|
1112
1100
|
};
|
|
@@ -1485,6 +1473,19 @@ var Builder = class {
|
|
|
1485
1473
|
this.addToLookupMap = (lookup) => {
|
|
1486
1474
|
this.lookupMap[lookup.type] = lookup;
|
|
1487
1475
|
};
|
|
1476
|
+
/**
|
|
1477
|
+
* ```graphql
|
|
1478
|
+
* # ex.
|
|
1479
|
+
* {
|
|
1480
|
+
* getCollection(collection: $collection) {
|
|
1481
|
+
* name
|
|
1482
|
+
* documents {...}
|
|
1483
|
+
* }
|
|
1484
|
+
* }
|
|
1485
|
+
* ```
|
|
1486
|
+
*
|
|
1487
|
+
* @param collections
|
|
1488
|
+
*/
|
|
1488
1489
|
this.buildCollectionDefinition = async (collections) => {
|
|
1489
1490
|
const name = "collection";
|
|
1490
1491
|
const typeName = "Collection";
|
|
@@ -1555,6 +1556,19 @@ var Builder = class {
|
|
|
1555
1556
|
required: true
|
|
1556
1557
|
});
|
|
1557
1558
|
};
|
|
1559
|
+
/**
|
|
1560
|
+
* ```graphql
|
|
1561
|
+
* # ex.
|
|
1562
|
+
* {
|
|
1563
|
+
* getCollections {
|
|
1564
|
+
* name
|
|
1565
|
+
* documents {...}
|
|
1566
|
+
* }
|
|
1567
|
+
* }
|
|
1568
|
+
* ```
|
|
1569
|
+
*
|
|
1570
|
+
* @param collections
|
|
1571
|
+
*/
|
|
1558
1572
|
this.buildMultiCollectionDefinition = async (collections) => {
|
|
1559
1573
|
const name = "collections";
|
|
1560
1574
|
const typeName = "Collection";
|
|
@@ -1565,6 +1579,17 @@ var Builder = class {
|
|
|
1565
1579
|
required: true
|
|
1566
1580
|
});
|
|
1567
1581
|
};
|
|
1582
|
+
/**
|
|
1583
|
+
* ```graphql
|
|
1584
|
+
* # ex.
|
|
1585
|
+
* {
|
|
1586
|
+
* node(id: $id) {
|
|
1587
|
+
* id
|
|
1588
|
+
* data {...}
|
|
1589
|
+
* }
|
|
1590
|
+
* }
|
|
1591
|
+
* ```
|
|
1592
|
+
*/
|
|
1568
1593
|
this.multiNodeDocument = async () => {
|
|
1569
1594
|
const name = "node";
|
|
1570
1595
|
const args = [
|
|
@@ -1585,6 +1610,19 @@ var Builder = class {
|
|
|
1585
1610
|
required: true
|
|
1586
1611
|
});
|
|
1587
1612
|
};
|
|
1613
|
+
/**
|
|
1614
|
+
* ```graphql
|
|
1615
|
+
* # ex.
|
|
1616
|
+
* {
|
|
1617
|
+
* getDocument(collection: $collection, relativePath: $relativePath) {
|
|
1618
|
+
* id
|
|
1619
|
+
* data {...}
|
|
1620
|
+
* }
|
|
1621
|
+
* }
|
|
1622
|
+
* ```
|
|
1623
|
+
*
|
|
1624
|
+
* @param collections
|
|
1625
|
+
*/
|
|
1588
1626
|
this.multiCollectionDocument = async (collections) => {
|
|
1589
1627
|
const name = "document";
|
|
1590
1628
|
const args = [
|
|
@@ -1610,6 +1648,19 @@ var Builder = class {
|
|
|
1610
1648
|
required: true
|
|
1611
1649
|
});
|
|
1612
1650
|
};
|
|
1651
|
+
/**
|
|
1652
|
+
* ```graphql
|
|
1653
|
+
* # ex.
|
|
1654
|
+
* {
|
|
1655
|
+
* addPendingDocument(collection: $collection, relativePath: $relativePath, params: $params) {
|
|
1656
|
+
* id
|
|
1657
|
+
* data {...}
|
|
1658
|
+
* }
|
|
1659
|
+
* }
|
|
1660
|
+
* ```
|
|
1661
|
+
*
|
|
1662
|
+
* @param collections
|
|
1663
|
+
*/
|
|
1613
1664
|
this.addMultiCollectionDocumentMutation = async () => {
|
|
1614
1665
|
return astBuilder.FieldDefinition({
|
|
1615
1666
|
name: "addPendingDocument",
|
|
@@ -1634,6 +1685,19 @@ var Builder = class {
|
|
|
1634
1685
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1635
1686
|
});
|
|
1636
1687
|
};
|
|
1688
|
+
/**
|
|
1689
|
+
* ```graphql
|
|
1690
|
+
* # ex.
|
|
1691
|
+
* {
|
|
1692
|
+
* createDocument(relativePath: $relativePath, params: $params) {
|
|
1693
|
+
* id
|
|
1694
|
+
* data {...}
|
|
1695
|
+
* }
|
|
1696
|
+
* }
|
|
1697
|
+
* ```
|
|
1698
|
+
*
|
|
1699
|
+
* @param collections
|
|
1700
|
+
*/
|
|
1637
1701
|
this.buildCreateCollectionDocumentMutation = async (collections) => {
|
|
1638
1702
|
return astBuilder.FieldDefinition({
|
|
1639
1703
|
name: "createDocument",
|
|
@@ -1661,6 +1725,19 @@ var Builder = class {
|
|
|
1661
1725
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1662
1726
|
});
|
|
1663
1727
|
};
|
|
1728
|
+
/**
|
|
1729
|
+
* ```graphql
|
|
1730
|
+
* # ex.
|
|
1731
|
+
* {
|
|
1732
|
+
* updateDocument(relativePath: $relativePath, params: $params) {
|
|
1733
|
+
* id
|
|
1734
|
+
* data {...}
|
|
1735
|
+
* }
|
|
1736
|
+
* }
|
|
1737
|
+
* ```
|
|
1738
|
+
*
|
|
1739
|
+
* @param collections
|
|
1740
|
+
*/
|
|
1664
1741
|
this.buildUpdateCollectionDocumentMutation = async (collections) => {
|
|
1665
1742
|
return astBuilder.FieldDefinition({
|
|
1666
1743
|
name: "updateDocument",
|
|
@@ -1688,6 +1765,19 @@ var Builder = class {
|
|
|
1688
1765
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1689
1766
|
});
|
|
1690
1767
|
};
|
|
1768
|
+
/**
|
|
1769
|
+
* ```graphql
|
|
1770
|
+
* # ex.
|
|
1771
|
+
* {
|
|
1772
|
+
* deleteDocument(relativePath: $relativePath, params: $params) {
|
|
1773
|
+
* id
|
|
1774
|
+
* data {...}
|
|
1775
|
+
* }
|
|
1776
|
+
* }
|
|
1777
|
+
* ```
|
|
1778
|
+
*
|
|
1779
|
+
* @param collections
|
|
1780
|
+
*/
|
|
1691
1781
|
this.buildDeleteCollectionDocumentMutation = async (collections) => {
|
|
1692
1782
|
return astBuilder.FieldDefinition({
|
|
1693
1783
|
name: "deleteDocument",
|
|
@@ -1707,6 +1797,19 @@ var Builder = class {
|
|
|
1707
1797
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1708
1798
|
});
|
|
1709
1799
|
};
|
|
1800
|
+
/**
|
|
1801
|
+
* ```graphql
|
|
1802
|
+
* # ex.
|
|
1803
|
+
* {
|
|
1804
|
+
* createFolder(folderName: $folderName, params: $params) {
|
|
1805
|
+
* id
|
|
1806
|
+
* data {...}
|
|
1807
|
+
* }
|
|
1808
|
+
* }
|
|
1809
|
+
* ```
|
|
1810
|
+
*
|
|
1811
|
+
* @param collections
|
|
1812
|
+
*/
|
|
1710
1813
|
this.buildCreateCollectionFolderMutation = async () => {
|
|
1711
1814
|
return astBuilder.FieldDefinition({
|
|
1712
1815
|
name: "createFolder",
|
|
@@ -1726,6 +1829,19 @@ var Builder = class {
|
|
|
1726
1829
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1727
1830
|
});
|
|
1728
1831
|
};
|
|
1832
|
+
/**
|
|
1833
|
+
* ```graphql
|
|
1834
|
+
* # ex.
|
|
1835
|
+
* {
|
|
1836
|
+
* getPostDocument(relativePath: $relativePath) {
|
|
1837
|
+
* id
|
|
1838
|
+
* data {...}
|
|
1839
|
+
* }
|
|
1840
|
+
* }
|
|
1841
|
+
* ```
|
|
1842
|
+
*
|
|
1843
|
+
* @param collection
|
|
1844
|
+
*/
|
|
1729
1845
|
this.collectionDocument = async (collection) => {
|
|
1730
1846
|
const name = NAMER.queryName([collection.name]);
|
|
1731
1847
|
const type = await this._buildCollectionDocumentType(collection);
|
|
@@ -1786,6 +1902,20 @@ var Builder = class {
|
|
|
1786
1902
|
const args = [];
|
|
1787
1903
|
return astBuilder.FieldDefinition({ type, name, args, required: false });
|
|
1788
1904
|
};
|
|
1905
|
+
/**
|
|
1906
|
+
* Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
|
|
1907
|
+
* ```graphql
|
|
1908
|
+
* # ex.
|
|
1909
|
+
* fragment AuthorsParts on Authors {
|
|
1910
|
+
* name
|
|
1911
|
+
* avatar
|
|
1912
|
+
* ...
|
|
1913
|
+
* }
|
|
1914
|
+
* ```
|
|
1915
|
+
*
|
|
1916
|
+
* @public
|
|
1917
|
+
* @param collection a Tina Cloud collection
|
|
1918
|
+
*/
|
|
1789
1919
|
this.collectionFragment = async (collection) => {
|
|
1790
1920
|
const name = NAMER.dataTypeName(collection.namespace);
|
|
1791
1921
|
const fragmentName = NAMER.fragmentName(collection.namespace);
|
|
@@ -1799,6 +1929,20 @@ var Builder = class {
|
|
|
1799
1929
|
selections: filterSelections(selections)
|
|
1800
1930
|
});
|
|
1801
1931
|
};
|
|
1932
|
+
/**
|
|
1933
|
+
* Given a collection this function returns its selections set. For example for Post this would return
|
|
1934
|
+
*
|
|
1935
|
+
* "
|
|
1936
|
+
* body
|
|
1937
|
+
* title
|
|
1938
|
+
* ... on Author {
|
|
1939
|
+
* name
|
|
1940
|
+
* heroImg
|
|
1941
|
+
* }
|
|
1942
|
+
*
|
|
1943
|
+
* But in the AST format
|
|
1944
|
+
*
|
|
1945
|
+
* */
|
|
1802
1946
|
this._getCollectionFragmentSelections = async (collection, depth) => {
|
|
1803
1947
|
var _a;
|
|
1804
1948
|
const selections = [];
|
|
@@ -1882,9 +2026,9 @@ var Builder = class {
|
|
|
1882
2026
|
]
|
|
1883
2027
|
});
|
|
1884
2028
|
}
|
|
2029
|
+
// TODO: Should we throw here?
|
|
1885
2030
|
case "reference":
|
|
1886
|
-
if (depth >= this.maxDepth)
|
|
1887
|
-
return false;
|
|
2031
|
+
if (depth >= this.maxDepth) return false;
|
|
1888
2032
|
if (!("collections" in field)) {
|
|
1889
2033
|
return false;
|
|
1890
2034
|
}
|
|
@@ -1916,6 +2060,7 @@ var Builder = class {
|
|
|
1916
2060
|
name: field.name,
|
|
1917
2061
|
selections: [
|
|
1918
2062
|
...selections,
|
|
2063
|
+
// This is ... on Document { id }
|
|
1919
2064
|
{
|
|
1920
2065
|
kind: "InlineFragment",
|
|
1921
2066
|
typeCondition: {
|
|
@@ -1946,6 +2091,19 @@ var Builder = class {
|
|
|
1946
2091
|
});
|
|
1947
2092
|
}
|
|
1948
2093
|
};
|
|
2094
|
+
/**
|
|
2095
|
+
* ```graphql
|
|
2096
|
+
* # ex.
|
|
2097
|
+
* mutation {
|
|
2098
|
+
* updatePostDocument(relativePath: $relativePath, params: $params) {
|
|
2099
|
+
* id
|
|
2100
|
+
* data {...}
|
|
2101
|
+
* }
|
|
2102
|
+
* }
|
|
2103
|
+
* ```
|
|
2104
|
+
*
|
|
2105
|
+
* @param collection
|
|
2106
|
+
*/
|
|
1949
2107
|
this.updateCollectionDocumentMutation = async (collection) => {
|
|
1950
2108
|
return astBuilder.FieldDefinition({
|
|
1951
2109
|
type: await this._buildCollectionDocumentType(collection),
|
|
@@ -1965,6 +2123,19 @@ var Builder = class {
|
|
|
1965
2123
|
]
|
|
1966
2124
|
});
|
|
1967
2125
|
};
|
|
2126
|
+
/**
|
|
2127
|
+
* ```graphql
|
|
2128
|
+
* # ex.
|
|
2129
|
+
* mutation {
|
|
2130
|
+
* createPostDocument(relativePath: $relativePath, params: $params) {
|
|
2131
|
+
* id
|
|
2132
|
+
* data {...}
|
|
2133
|
+
* }
|
|
2134
|
+
* }
|
|
2135
|
+
* ```
|
|
2136
|
+
*
|
|
2137
|
+
* @param collection
|
|
2138
|
+
*/
|
|
1968
2139
|
this.createCollectionDocumentMutation = async (collection) => {
|
|
1969
2140
|
return astBuilder.FieldDefinition({
|
|
1970
2141
|
type: await this._buildCollectionDocumentType(collection),
|
|
@@ -1984,6 +2155,22 @@ var Builder = class {
|
|
|
1984
2155
|
]
|
|
1985
2156
|
});
|
|
1986
2157
|
};
|
|
2158
|
+
/**
|
|
2159
|
+
* ```graphql
|
|
2160
|
+
* # ex.
|
|
2161
|
+
* {
|
|
2162
|
+
* getPostList(first: 10) {
|
|
2163
|
+
* edges {
|
|
2164
|
+
* node {
|
|
2165
|
+
* id
|
|
2166
|
+
* }
|
|
2167
|
+
* }
|
|
2168
|
+
* }
|
|
2169
|
+
* }
|
|
2170
|
+
* ```
|
|
2171
|
+
*
|
|
2172
|
+
* @param collection
|
|
2173
|
+
*/
|
|
1987
2174
|
this.collectionDocumentList = async (collection) => {
|
|
1988
2175
|
const connectionName = NAMER.referenceConnectionType(collection.namespace);
|
|
1989
2176
|
this.addToLookupMap({
|
|
@@ -1999,6 +2186,10 @@ var Builder = class {
|
|
|
1999
2186
|
collection
|
|
2000
2187
|
});
|
|
2001
2188
|
};
|
|
2189
|
+
/**
|
|
2190
|
+
* GraphQL type definitions which remain unchanged regardless
|
|
2191
|
+
* of the supplied Tina schema. Ex. "node" interface
|
|
2192
|
+
*/
|
|
2002
2193
|
this.buildStaticDefinitions = () => staticDefinitions;
|
|
2003
2194
|
this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
|
|
2004
2195
|
const documentTypeName = NAMER.documentTypeName(collection.namespace);
|
|
@@ -2503,6 +2694,7 @@ var Builder = class {
|
|
|
2503
2694
|
name: NAMER.dataFilterTypeName(namespace),
|
|
2504
2695
|
fields: await sequential(collections, async (collection2) => {
|
|
2505
2696
|
return astBuilder.InputValueDefinition({
|
|
2697
|
+
// @ts-ignore
|
|
2506
2698
|
name: collection2.name,
|
|
2507
2699
|
type: NAMER.dataFilterTypeName(collection2.namespace)
|
|
2508
2700
|
});
|
|
@@ -2692,7 +2884,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2692
2884
|
});
|
|
2693
2885
|
};
|
|
2694
2886
|
var _a, _b, _c, _d;
|
|
2695
|
-
this.maxDepth =
|
|
2887
|
+
this.maxDepth = // @ts-ignore
|
|
2888
|
+
(_d = (_c = (_b = (_a = config == null ? void 0 : config.tinaSchema.schema) == null ? void 0 : _a.config) == null ? void 0 : _b.client) == null ? void 0 : _c.referenceDepth) != null ? _d : 2;
|
|
2696
2889
|
this.tinaSchema = config.tinaSchema;
|
|
2697
2890
|
this.lookupMap = {};
|
|
2698
2891
|
}
|
|
@@ -2703,8 +2896,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2703
2896
|
selections.push(field);
|
|
2704
2897
|
});
|
|
2705
2898
|
const filteredSelections = filterSelections(selections);
|
|
2706
|
-
if (!filteredSelections.length)
|
|
2707
|
-
return false;
|
|
2899
|
+
if (!filteredSelections.length) return false;
|
|
2708
2900
|
return astBuilder.InlineFragmentDefinition({
|
|
2709
2901
|
selections: filteredSelections,
|
|
2710
2902
|
name: NAMER.dataTypeName(template.namespace)
|
|
@@ -2738,12 +2930,13 @@ var filterSelections = (arr) => {
|
|
|
2738
2930
|
};
|
|
2739
2931
|
|
|
2740
2932
|
// src/schema/createSchema.ts
|
|
2741
|
-
var
|
|
2933
|
+
var import_schema_tools3 = require("@tinacms/schema-tools");
|
|
2742
2934
|
|
|
2743
2935
|
// src/schema/validate.ts
|
|
2936
|
+
var import_schema_tools = require("@tinacms/schema-tools");
|
|
2744
2937
|
var import_lodash2 = __toESM(require("lodash.clonedeep"));
|
|
2745
2938
|
var yup2 = __toESM(require("yup"));
|
|
2746
|
-
var
|
|
2939
|
+
var import_schema_tools2 = require("@tinacms/schema-tools");
|
|
2747
2940
|
var FIELD_TYPES = [
|
|
2748
2941
|
"string",
|
|
2749
2942
|
"number",
|
|
@@ -2756,7 +2949,7 @@ var FIELD_TYPES = [
|
|
|
2756
2949
|
"password"
|
|
2757
2950
|
];
|
|
2758
2951
|
var validateSchema = async (schema) => {
|
|
2759
|
-
const schema2 = addNamespaceToSchema(
|
|
2952
|
+
const schema2 = (0, import_schema_tools.addNamespaceToSchema)(
|
|
2760
2953
|
(0, import_lodash2.default)(schema)
|
|
2761
2954
|
);
|
|
2762
2955
|
const collections = await sequential(
|
|
@@ -2765,7 +2958,7 @@ var validateSchema = async (schema) => {
|
|
|
2765
2958
|
);
|
|
2766
2959
|
validationCollectionsPathAndMatch(collections);
|
|
2767
2960
|
if (schema2.config) {
|
|
2768
|
-
const config = (0,
|
|
2961
|
+
const config = (0, import_schema_tools2.validateTinaCloudSchemaConfig)(schema2.config);
|
|
2769
2962
|
return {
|
|
2770
2963
|
collections,
|
|
2771
2964
|
config
|
|
@@ -2785,6 +2978,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
2785
2978
|
}).map((x) => `${x.path}${x.format || "md"}`);
|
|
2786
2979
|
if (noMatchCollections.length !== new Set(noMatchCollections).size) {
|
|
2787
2980
|
throw new Error(
|
|
2981
|
+
// TODO: add a link to the docs
|
|
2788
2982
|
"Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
|
|
2789
2983
|
);
|
|
2790
2984
|
}
|
|
@@ -2896,7 +3090,7 @@ var validateField = async (field) => {
|
|
|
2896
3090
|
// package.json
|
|
2897
3091
|
var package_default = {
|
|
2898
3092
|
name: "@tinacms/graphql",
|
|
2899
|
-
version: "1.5.
|
|
3093
|
+
version: "1.5.11",
|
|
2900
3094
|
main: "dist/index.js",
|
|
2901
3095
|
module: "dist/index.mjs",
|
|
2902
3096
|
typings: "dist/index.d.ts",
|
|
@@ -2923,8 +3117,8 @@ var package_default = {
|
|
|
2923
3117
|
build: "tinacms-scripts build",
|
|
2924
3118
|
docs: "pnpm typedoc",
|
|
2925
3119
|
serve: "pnpm nodemon dist/server.js",
|
|
2926
|
-
test: "
|
|
2927
|
-
"test-watch": "
|
|
3120
|
+
test: "vitest run",
|
|
3121
|
+
"test-watch": "vitest"
|
|
2928
3122
|
},
|
|
2929
3123
|
dependencies: {
|
|
2930
3124
|
"@iarna/toml": "^2.2.5",
|
|
@@ -2965,7 +3159,6 @@ var package_default = {
|
|
|
2965
3159
|
"@types/estree": "^0.0.50",
|
|
2966
3160
|
"@types/express": "^4.17.21",
|
|
2967
3161
|
"@types/fs-extra": "^9.0.13",
|
|
2968
|
-
"@types/jest": "^26.0.24",
|
|
2969
3162
|
"@types/js-yaml": "^3.12.10",
|
|
2970
3163
|
"@types/lodash.camelcase": "^4.3.9",
|
|
2971
3164
|
"@types/lodash.upperfirst": "^4.3.9",
|
|
@@ -2976,13 +3169,13 @@ var package_default = {
|
|
|
2976
3169
|
"@types/normalize-path": "^3.0.2",
|
|
2977
3170
|
"@types/ws": "^7.4.7",
|
|
2978
3171
|
"@types/yup": "^0.29.14",
|
|
2979
|
-
jest: "^29.7.0",
|
|
2980
|
-
"jest-diff": "^29.7.0",
|
|
2981
3172
|
"jest-file-snapshot": "^0.5.0",
|
|
2982
|
-
"jest-matcher-utils": "^29.7.0",
|
|
2983
3173
|
"memory-level": "^1.0.0",
|
|
2984
3174
|
nodemon: "3.1.4",
|
|
2985
|
-
typescript: "^5.6.3"
|
|
3175
|
+
typescript: "^5.6.3",
|
|
3176
|
+
vite: "^4.3.9",
|
|
3177
|
+
vitest: "^0.32.2",
|
|
3178
|
+
zod: "^3.23.8"
|
|
2986
3179
|
}
|
|
2987
3180
|
};
|
|
2988
3181
|
|
|
@@ -2997,7 +3190,7 @@ var createSchema = async ({
|
|
|
2997
3190
|
if (flags && flags.length > 0) {
|
|
2998
3191
|
meta["flags"] = flags;
|
|
2999
3192
|
}
|
|
3000
|
-
return new
|
|
3193
|
+
return new import_schema_tools3.TinaSchema({
|
|
3001
3194
|
version: {
|
|
3002
3195
|
fullVersion: package_default.version,
|
|
3003
3196
|
major,
|
|
@@ -3053,6 +3246,7 @@ var _buildFragments = async (builder, tinaSchema) => {
|
|
|
3053
3246
|
const fragDoc = {
|
|
3054
3247
|
kind: "Document",
|
|
3055
3248
|
definitions: (0, import_lodash3.default)(
|
|
3249
|
+
// @ts-ignore
|
|
3056
3250
|
extractInlineTypes(fragmentDefinitionsFields),
|
|
3057
3251
|
(node) => node.name.value
|
|
3058
3252
|
)
|
|
@@ -3076,6 +3270,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3076
3270
|
fragName,
|
|
3077
3271
|
queryName: queryListName,
|
|
3078
3272
|
filterType: queryFilterTypeName,
|
|
3273
|
+
// look for flag to see if the data layer is enabled
|
|
3079
3274
|
dataLayer: Boolean(
|
|
3080
3275
|
(_c = (_b = (_a = tinaSchema.config) == null ? void 0 : _a.meta) == null ? void 0 : _b.flags) == null ? void 0 : _c.find((x) => x === "experimentalData")
|
|
3081
3276
|
)
|
|
@@ -3085,6 +3280,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3085
3280
|
const queryDoc = {
|
|
3086
3281
|
kind: "Document",
|
|
3087
3282
|
definitions: (0, import_lodash3.default)(
|
|
3283
|
+
// @ts-ignore
|
|
3088
3284
|
extractInlineTypes(operationsDefinitions),
|
|
3089
3285
|
(node) => node.name.value
|
|
3090
3286
|
)
|
|
@@ -3173,6 +3369,7 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3173
3369
|
return {
|
|
3174
3370
|
kind: "Document",
|
|
3175
3371
|
definitions: (0, import_lodash3.default)(
|
|
3372
|
+
// @ts-ignore
|
|
3176
3373
|
extractInlineTypes(definitions),
|
|
3177
3374
|
(node) => node.name.value
|
|
3178
3375
|
)
|
|
@@ -3377,8 +3574,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
|
|
|
3377
3574
|
}
|
|
3378
3575
|
if (Array.isArray(value)) {
|
|
3379
3576
|
return value.map((v) => {
|
|
3380
|
-
if (!v || typeof v !== "string")
|
|
3381
|
-
return v;
|
|
3577
|
+
if (!v || typeof v !== "string") return v;
|
|
3382
3578
|
const cleanMediaRoot = cleanUpSlashes(
|
|
3383
3579
|
schema.config.media.tina.mediaRoot
|
|
3384
3580
|
);
|
|
@@ -3406,8 +3602,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
|
|
|
3406
3602
|
}
|
|
3407
3603
|
if (Array.isArray(value)) {
|
|
3408
3604
|
return value.map((v) => {
|
|
3409
|
-
if (!v || typeof v !== "string")
|
|
3410
|
-
return v;
|
|
3605
|
+
if (!v || typeof v !== "string") return v;
|
|
3411
3606
|
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3412
3607
|
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3413
3608
|
});
|
|
@@ -3426,8 +3621,7 @@ var cleanUpSlashes = (path7) => {
|
|
|
3426
3621
|
};
|
|
3427
3622
|
var hasTinaMediaConfig = (schema) => {
|
|
3428
3623
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3429
|
-
if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina))
|
|
3430
|
-
return false;
|
|
3624
|
+
if (!((_b = (_a = schema.config) == null ? void 0 : _a.media) == null ? void 0 : _b.tina)) return false;
|
|
3431
3625
|
if (typeof ((_e = (_d = (_c = schema.config) == null ? void 0 : _c.media) == null ? void 0 : _d.tina) == null ? void 0 : _e.publicFolder) !== "string" && typeof ((_h = (_g = (_f = schema.config) == null ? void 0 : _f.media) == null ? void 0 : _g.tina) == null ? void 0 : _h.mediaRoot) !== "string")
|
|
3432
3626
|
return false;
|
|
3433
3627
|
return true;
|
|
@@ -3471,6 +3665,7 @@ var LevelProxyHandler = {
|
|
|
3471
3665
|
} else if (property === "sublevel") {
|
|
3472
3666
|
return (...args) => {
|
|
3473
3667
|
return new Proxy(
|
|
3668
|
+
// eslint-disable-next-line prefer-spread
|
|
3474
3669
|
target[property].apply(target, args),
|
|
3475
3670
|
LevelProxyHandler
|
|
3476
3671
|
);
|
|
@@ -3493,7 +3688,7 @@ var import_path2 = __toESM(require("path"));
|
|
|
3493
3688
|
var import_toml = __toESM(require("@iarna/toml"));
|
|
3494
3689
|
var import_js_yaml = __toESM(require("js-yaml"));
|
|
3495
3690
|
var import_gray_matter = __toESM(require("gray-matter"));
|
|
3496
|
-
var
|
|
3691
|
+
var import_schema_tools4 = require("@tinacms/schema-tools");
|
|
3497
3692
|
var import_micromatch = __toESM(require("micromatch"));
|
|
3498
3693
|
var import_path = __toESM(require("path"));
|
|
3499
3694
|
|
|
@@ -3706,7 +3901,7 @@ var scanAllContent = async (tinaSchema, bridge, callback) => {
|
|
|
3706
3901
|
const filesSeen = /* @__PURE__ */ new Map();
|
|
3707
3902
|
const duplicateFiles = /* @__PURE__ */ new Set();
|
|
3708
3903
|
await sequential(tinaSchema.getCollections(), async (collection) => {
|
|
3709
|
-
const normalPath = (0,
|
|
3904
|
+
const normalPath = (0, import_schema_tools4.normalizePath)(collection.path);
|
|
3710
3905
|
const format = collection.format || "md";
|
|
3711
3906
|
const documentPaths = await bridge.glob(normalPath, format);
|
|
3712
3907
|
const matches = tinaSchema.getMatches({ collection });
|
|
@@ -3818,7 +4013,7 @@ var getTemplateForFile = (templateInfo, data) => {
|
|
|
3818
4013
|
throw new Error(`Unable to determine template`);
|
|
3819
4014
|
};
|
|
3820
4015
|
var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo) => {
|
|
3821
|
-
const dataString = await bridge.get((0,
|
|
4016
|
+
const dataString = await bridge.get((0, import_schema_tools4.normalizePath)(filepath));
|
|
3822
4017
|
const data = parseFile(
|
|
3823
4018
|
dataString,
|
|
3824
4019
|
import_path.default.extname(filepath),
|
|
@@ -4297,7 +4492,7 @@ var FolderTreeBuilder = class {
|
|
|
4297
4492
|
return this._tree;
|
|
4298
4493
|
}
|
|
4299
4494
|
update(documentPath, collectionPath) {
|
|
4300
|
-
let folderPath = import_path2.default.dirname((0,
|
|
4495
|
+
let folderPath = import_path2.default.dirname((0, import_schema_tools4.normalizePath)(documentPath));
|
|
4301
4496
|
if (folderPath === ".") {
|
|
4302
4497
|
folderPath = "";
|
|
4303
4498
|
}
|
|
@@ -4310,7 +4505,7 @@ var FolderTreeBuilder = class {
|
|
|
4310
4505
|
if (!this._tree[current2]) {
|
|
4311
4506
|
this._tree[current2] = /* @__PURE__ */ new Set();
|
|
4312
4507
|
}
|
|
4313
|
-
this._tree[current2].add((0,
|
|
4508
|
+
this._tree[current2].add((0, import_schema_tools4.normalizePath)(import_path2.default.join(current2, part)));
|
|
4314
4509
|
parent.push(part);
|
|
4315
4510
|
});
|
|
4316
4511
|
const current = parent.join("/");
|
|
@@ -4349,6 +4544,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
|
|
|
4349
4544
|
result.push({
|
|
4350
4545
|
type: opType,
|
|
4351
4546
|
key: `${collection.path}/${subFolderKey}.${collection.format}`,
|
|
4547
|
+
// replace the root with the collection path
|
|
4352
4548
|
sublevel: indexSublevel,
|
|
4353
4549
|
value: {}
|
|
4354
4550
|
});
|
|
@@ -4464,6 +4660,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4464
4660
|
case "password":
|
|
4465
4661
|
accumulator[field.name] = {
|
|
4466
4662
|
value: void 0,
|
|
4663
|
+
// never resolve the password hash
|
|
4467
4664
|
passwordChangeRequired: (_a = value["passwordChangeRequired"]) != null ? _a : false
|
|
4468
4665
|
};
|
|
4469
4666
|
break;
|
|
@@ -4658,6 +4855,7 @@ var Resolver = class {
|
|
|
4658
4855
|
const collection = this.tinaSchema.getCollection(collectionName);
|
|
4659
4856
|
const extraFields = {};
|
|
4660
4857
|
return {
|
|
4858
|
+
// return the collection and hasDocuments to resolve documents at a lower level
|
|
4661
4859
|
documents: { collection, hasDocuments },
|
|
4662
4860
|
...collection,
|
|
4663
4861
|
...extraFields
|
|
@@ -4744,7 +4942,9 @@ var Resolver = class {
|
|
|
4744
4942
|
);
|
|
4745
4943
|
} else {
|
|
4746
4944
|
return this.buildFieldMutations(
|
|
4945
|
+
// @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
|
|
4747
4946
|
fieldValue,
|
|
4947
|
+
//@ts-ignore
|
|
4748
4948
|
objectTemplate,
|
|
4749
4949
|
existingData
|
|
4750
4950
|
);
|
|
@@ -4756,6 +4956,7 @@ var Resolver = class {
|
|
|
4756
4956
|
fieldValue.map(async (item) => {
|
|
4757
4957
|
if (typeof item === "string") {
|
|
4758
4958
|
throw new Error(
|
|
4959
|
+
//@ts-ignore
|
|
4759
4960
|
`Expected object for template value for field ${field.name}`
|
|
4760
4961
|
);
|
|
4761
4962
|
}
|
|
@@ -4764,16 +4965,19 @@ var Resolver = class {
|
|
|
4764
4965
|
});
|
|
4765
4966
|
const [templateName] = Object.entries(item)[0];
|
|
4766
4967
|
const template = templates.find(
|
|
4968
|
+
//@ts-ignore
|
|
4767
4969
|
(template2) => template2.name === templateName
|
|
4768
4970
|
);
|
|
4769
4971
|
if (!template) {
|
|
4770
4972
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4771
4973
|
}
|
|
4772
4974
|
return {
|
|
4975
|
+
// @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
|
|
4773
4976
|
...await this.buildFieldMutations(
|
|
4774
4977
|
item[template.name],
|
|
4775
4978
|
template
|
|
4776
4979
|
),
|
|
4980
|
+
//@ts-ignore
|
|
4777
4981
|
_template: template.name
|
|
4778
4982
|
};
|
|
4779
4983
|
})
|
|
@@ -4781,6 +4985,7 @@ var Resolver = class {
|
|
|
4781
4985
|
} else {
|
|
4782
4986
|
if (typeof fieldValue === "string") {
|
|
4783
4987
|
throw new Error(
|
|
4988
|
+
//@ts-ignore
|
|
4784
4989
|
`Expected object for template value for field ${field.name}`
|
|
4785
4990
|
);
|
|
4786
4991
|
}
|
|
@@ -4789,16 +4994,19 @@ var Resolver = class {
|
|
|
4789
4994
|
});
|
|
4790
4995
|
const [templateName] = Object.entries(fieldValue)[0];
|
|
4791
4996
|
const template = templates.find(
|
|
4997
|
+
//@ts-ignore
|
|
4792
4998
|
(template2) => template2.name === templateName
|
|
4793
4999
|
);
|
|
4794
5000
|
if (!template) {
|
|
4795
5001
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4796
5002
|
}
|
|
4797
5003
|
return {
|
|
5004
|
+
// @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
|
|
4798
5005
|
...await this.buildFieldMutations(
|
|
4799
5006
|
fieldValue[template.name],
|
|
4800
5007
|
template
|
|
4801
5008
|
),
|
|
5009
|
+
//@ts-ignore
|
|
4802
5010
|
_template: template.name
|
|
4803
5011
|
};
|
|
4804
5012
|
}
|
|
@@ -4838,6 +5046,7 @@ var Resolver = class {
|
|
|
4838
5046
|
return this.getDocument(realPath);
|
|
4839
5047
|
}
|
|
4840
5048
|
const params = await this.buildObjectMutations(
|
|
5049
|
+
// @ts-ignore
|
|
4841
5050
|
args.params[collection.name],
|
|
4842
5051
|
collection
|
|
4843
5052
|
);
|
|
@@ -4883,6 +5092,7 @@ var Resolver = class {
|
|
|
4883
5092
|
const values = {
|
|
4884
5093
|
...oldDoc,
|
|
4885
5094
|
...await this.buildFieldMutations(
|
|
5095
|
+
// @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
|
|
4886
5096
|
templateParams,
|
|
4887
5097
|
template,
|
|
4888
5098
|
doc == null ? void 0 : doc._rawData
|
|
@@ -4896,6 +5106,7 @@ var Resolver = class {
|
|
|
4896
5106
|
return this.getDocument(realPath);
|
|
4897
5107
|
}
|
|
4898
5108
|
const params = await this.buildObjectMutations(
|
|
5109
|
+
//@ts-ignore
|
|
4899
5110
|
isCollectionSpecific ? args.params : args.params[collection.name],
|
|
4900
5111
|
collection,
|
|
4901
5112
|
doc == null ? void 0 : doc._rawData
|
|
@@ -4903,6 +5114,10 @@ var Resolver = class {
|
|
|
4903
5114
|
await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
|
|
4904
5115
|
return this.getDocument(realPath);
|
|
4905
5116
|
};
|
|
5117
|
+
/**
|
|
5118
|
+
* Returns top-level fields which are not defined in the collection, so their
|
|
5119
|
+
* values are not eliminated from Tina when new values are saved
|
|
5120
|
+
*/
|
|
4906
5121
|
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
4907
5122
|
const legacyValues = {};
|
|
4908
5123
|
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
@@ -5109,6 +5324,7 @@ var Resolver = class {
|
|
|
5109
5324
|
},
|
|
5110
5325
|
collection: referencedCollection,
|
|
5111
5326
|
hydrator: (path7) => path7
|
|
5327
|
+
// just return the path
|
|
5112
5328
|
}
|
|
5113
5329
|
);
|
|
5114
5330
|
const { edges } = resolvedCollectionConnection;
|
|
@@ -5176,6 +5392,12 @@ var Resolver = class {
|
|
|
5176
5392
|
}
|
|
5177
5393
|
};
|
|
5178
5394
|
};
|
|
5395
|
+
/**
|
|
5396
|
+
* Checks if a document has references to it
|
|
5397
|
+
* @param id The id of the document to check for references
|
|
5398
|
+
* @param c The collection to check for references
|
|
5399
|
+
* @returns true if the document has references, false otherwise
|
|
5400
|
+
*/
|
|
5179
5401
|
this.hasReferences = async (id, c) => {
|
|
5180
5402
|
let count = 0;
|
|
5181
5403
|
const deepRefs = this.tinaSchema.findReferences(c.name);
|
|
@@ -5210,6 +5432,12 @@ var Resolver = class {
|
|
|
5210
5432
|
}
|
|
5211
5433
|
return false;
|
|
5212
5434
|
};
|
|
5435
|
+
/**
|
|
5436
|
+
* Finds references to a document
|
|
5437
|
+
* @param id the id of the document to find references to
|
|
5438
|
+
* @param c the collection to find references in
|
|
5439
|
+
* @returns references to the document in the form of a map of collection names to a list of fields that reference the document
|
|
5440
|
+
*/
|
|
5213
5441
|
this.findReferences = async (id, c) => {
|
|
5214
5442
|
const references = {};
|
|
5215
5443
|
const deepRefs = this.tinaSchema.findReferences(c.name);
|
|
@@ -5337,6 +5565,27 @@ var Resolver = class {
|
|
|
5337
5565
|
}
|
|
5338
5566
|
return accum;
|
|
5339
5567
|
};
|
|
5568
|
+
/**
|
|
5569
|
+
* A mutation looks nearly identical between updateDocument:
|
|
5570
|
+
* ```graphql
|
|
5571
|
+
* updateDocument(collection: $collection,relativePath: $path, params: {
|
|
5572
|
+
* post: {
|
|
5573
|
+
* title: "Hello, World"
|
|
5574
|
+
* }
|
|
5575
|
+
* })`
|
|
5576
|
+
* ```
|
|
5577
|
+
* and `updatePostDocument`:
|
|
5578
|
+
* ```graphql
|
|
5579
|
+
* updatePostDocument(relativePath: $path, params: {
|
|
5580
|
+
* title: "Hello, World"
|
|
5581
|
+
* })
|
|
5582
|
+
* ```
|
|
5583
|
+
* The problem here is that we don't know whether the payload came from `updateDocument`
|
|
5584
|
+
* or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
|
|
5585
|
+
* But we do know that when given a `args.collection` value, we can assume that
|
|
5586
|
+
* this was a `updateDocument` request, and thus - should grab the data
|
|
5587
|
+
* from the corresponding field name in the key
|
|
5588
|
+
*/
|
|
5340
5589
|
this.buildParams = (args) => {
|
|
5341
5590
|
try {
|
|
5342
5591
|
assertShape(
|
|
@@ -5437,7 +5686,10 @@ var resolve = async ({
|
|
|
5437
5686
|
const graphQLSchema = (0, import_graphql5.buildASTSchema)(graphQLSchemaAst);
|
|
5438
5687
|
const tinaConfig = await database.getTinaSchema();
|
|
5439
5688
|
const tinaSchema = await createSchema({
|
|
5689
|
+
// TODO: please update all the types to import from @tinacms/schema-tools
|
|
5690
|
+
// @ts-ignore
|
|
5440
5691
|
schema: tinaConfig,
|
|
5692
|
+
// @ts-ignore
|
|
5441
5693
|
flags: (_a = tinaConfig == null ? void 0 : tinaConfig.meta) == null ? void 0 : _a.flags
|
|
5442
5694
|
});
|
|
5443
5695
|
const resolver = createResolver({
|
|
@@ -5454,8 +5706,7 @@ var resolve = async ({
|
|
|
5454
5706
|
database
|
|
5455
5707
|
},
|
|
5456
5708
|
typeResolver: async (source, _args, info) => {
|
|
5457
|
-
if (source.__typename)
|
|
5458
|
-
return source.__typename;
|
|
5709
|
+
if (source.__typename) return source.__typename;
|
|
5459
5710
|
const namedType = (0, import_graphql5.getNamedType)(info.returnType).toString();
|
|
5460
5711
|
const lookup = await database.getLookup(namedType);
|
|
5461
5712
|
if (lookup.resolveType === "unionData") {
|
|
@@ -5607,11 +5858,13 @@ var resolve = async ({
|
|
|
5607
5858
|
(0, import_lodash4.default)(
|
|
5608
5859
|
params,
|
|
5609
5860
|
userField.path.slice(1),
|
|
5861
|
+
// remove _rawData from users path
|
|
5610
5862
|
users.map((u) => {
|
|
5611
5863
|
if (user[idFieldName] === u[idFieldName]) {
|
|
5612
5864
|
return user;
|
|
5613
5865
|
}
|
|
5614
5866
|
return {
|
|
5867
|
+
// don't overwrite other users' passwords
|
|
5615
5868
|
...u,
|
|
5616
5869
|
[passwordFieldName]: {
|
|
5617
5870
|
...u[passwordFieldName],
|
|
@@ -5634,6 +5887,9 @@ var resolve = async ({
|
|
|
5634
5887
|
}
|
|
5635
5888
|
const isCreation = lookup[info.fieldName] === "create";
|
|
5636
5889
|
switch (lookup.resolveType) {
|
|
5890
|
+
/**
|
|
5891
|
+
* `node(id: $id)`
|
|
5892
|
+
*/
|
|
5637
5893
|
case "nodeDocument":
|
|
5638
5894
|
assertShape(
|
|
5639
5895
|
args,
|
|
@@ -5665,6 +5921,7 @@ var resolve = async ({
|
|
|
5665
5921
|
collection: args.collection,
|
|
5666
5922
|
isMutation,
|
|
5667
5923
|
isCreation,
|
|
5924
|
+
// Right now this is the only case for deletion
|
|
5668
5925
|
isDeletion: info.fieldName === "deleteDocument",
|
|
5669
5926
|
isFolderCreation: info.fieldName === "createFolder",
|
|
5670
5927
|
isUpdateName: Boolean((_a2 = args == null ? void 0 : args.params) == null ? void 0 : _a2.relativePath),
|
|
@@ -5674,6 +5931,9 @@ var resolve = async ({
|
|
|
5674
5931
|
return result;
|
|
5675
5932
|
}
|
|
5676
5933
|
return value;
|
|
5934
|
+
/**
|
|
5935
|
+
* eg `getMovieDocument.data.actors`
|
|
5936
|
+
*/
|
|
5677
5937
|
case "multiCollectionDocumentList":
|
|
5678
5938
|
if (Array.isArray(value)) {
|
|
5679
5939
|
return {
|
|
@@ -5685,7 +5945,15 @@ var resolve = async ({
|
|
|
5685
5945
|
}
|
|
5686
5946
|
if (info.fieldName === "documents" && (value == null ? void 0 : value.collection) && (value == null ? void 0 : value.hasDocuments)) {
|
|
5687
5947
|
let filter = args.filter;
|
|
5688
|
-
if (
|
|
5948
|
+
if (
|
|
5949
|
+
// 1. Make sure that the filter exists
|
|
5950
|
+
typeof (args == null ? void 0 : args.filter) !== "undefined" && (args == null ? void 0 : args.filter) !== null && // 2. Make sure that the collection name exists
|
|
5951
|
+
// @ts-ignore
|
|
5952
|
+
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
|
|
5953
|
+
// @ts-ignore
|
|
5954
|
+
Object.keys(args.filter).includes((_c = value == null ? void 0 : value.collection) == null ? void 0 : _c.name) && // @ts-ignore
|
|
5955
|
+
typeof args.filter[(_d = value == null ? void 0 : value.collection) == null ? void 0 : _d.name] !== "undefined"
|
|
5956
|
+
) {
|
|
5689
5957
|
filter = args.filter[value.collection.name];
|
|
5690
5958
|
}
|
|
5691
5959
|
return resolver.resolveCollectionConnection({
|
|
@@ -5693,12 +5961,20 @@ var resolve = async ({
|
|
|
5693
5961
|
...args,
|
|
5694
5962
|
filter
|
|
5695
5963
|
},
|
|
5964
|
+
// @ts-ignore
|
|
5696
5965
|
collection: value.collection
|
|
5697
5966
|
});
|
|
5698
5967
|
}
|
|
5699
5968
|
throw new Error(
|
|
5700
5969
|
`Expected an array for result of ${info.fieldName} at ${info.path}`
|
|
5701
5970
|
);
|
|
5971
|
+
/**
|
|
5972
|
+
* Collections-specific getter
|
|
5973
|
+
* eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
|
|
5974
|
+
*
|
|
5975
|
+
* if coming from a query result
|
|
5976
|
+
* the field will be `node`
|
|
5977
|
+
*/
|
|
5702
5978
|
case "collectionDocument": {
|
|
5703
5979
|
if (value) {
|
|
5704
5980
|
return value;
|
|
@@ -5713,11 +5989,32 @@ var resolve = async ({
|
|
|
5713
5989
|
});
|
|
5714
5990
|
return result;
|
|
5715
5991
|
}
|
|
5992
|
+
/**
|
|
5993
|
+
* Collections-specific list getter
|
|
5994
|
+
* eg. `getPageList`
|
|
5995
|
+
*/
|
|
5716
5996
|
case "collectionDocumentList":
|
|
5717
5997
|
return resolver.resolveCollectionConnection({
|
|
5718
5998
|
args,
|
|
5719
5999
|
collection: tinaSchema.getCollection(lookup.collection)
|
|
5720
6000
|
});
|
|
6001
|
+
/**
|
|
6002
|
+
* A polymorphic data set, it can be from a document's data
|
|
6003
|
+
* of any nested object which can be one of many shapes
|
|
6004
|
+
*
|
|
6005
|
+
* ```graphql
|
|
6006
|
+
* getPostDocument(relativePath: $relativePath) {
|
|
6007
|
+
* data {...} <- this part
|
|
6008
|
+
* }
|
|
6009
|
+
* ```
|
|
6010
|
+
* ```graphql
|
|
6011
|
+
* getBlockDocument(relativePath: $relativePath) {
|
|
6012
|
+
* data {
|
|
6013
|
+
* blocks {...} <- or this part
|
|
6014
|
+
* }
|
|
6015
|
+
* }
|
|
6016
|
+
* ```
|
|
6017
|
+
*/
|
|
5721
6018
|
case "unionData":
|
|
5722
6019
|
if (!value) {
|
|
5723
6020
|
if (args.relativePath) {
|
|
@@ -5782,8 +6079,7 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
|
|
|
5782
6079
|
this.port = port || 9e3;
|
|
5783
6080
|
}
|
|
5784
6081
|
openConnection() {
|
|
5785
|
-
if (this._connected)
|
|
5786
|
-
return;
|
|
6082
|
+
if (this._connected) return;
|
|
5787
6083
|
const socket = (0, import_net.connect)(this.port);
|
|
5788
6084
|
(0, import_readable_stream.pipeline)(socket, this.createRpcStream(), socket, () => {
|
|
5789
6085
|
this._connected = false;
|
|
@@ -5903,7 +6199,7 @@ var Database = class {
|
|
|
5903
6199
|
const contentObject = await level.sublevel(
|
|
5904
6200
|
CONTENT_ROOT_PREFIX,
|
|
5905
6201
|
SUBLEVEL_OPTIONS
|
|
5906
|
-
).get((0,
|
|
6202
|
+
).get((0, import_schema_tools4.normalizePath)(filepath));
|
|
5907
6203
|
if (!contentObject) {
|
|
5908
6204
|
throw new NotFoundError(`Unable to find record ${filepath}`);
|
|
5909
6205
|
}
|
|
@@ -5928,7 +6224,7 @@ var Database = class {
|
|
|
5928
6224
|
);
|
|
5929
6225
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
5930
6226
|
const collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5931
|
-
const normalizedPath = (0,
|
|
6227
|
+
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
5932
6228
|
if (!(collection == null ? void 0 : collection.isDetached)) {
|
|
5933
6229
|
if (this.bridge) {
|
|
5934
6230
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
@@ -5964,6 +6260,7 @@ var Database = class {
|
|
|
5964
6260
|
"put",
|
|
5965
6261
|
level
|
|
5966
6262
|
),
|
|
6263
|
+
// folder indices
|
|
5967
6264
|
...makeIndexOpsForDocument(
|
|
5968
6265
|
normalizedPath,
|
|
5969
6266
|
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
@@ -5986,6 +6283,7 @@ var Database = class {
|
|
|
5986
6283
|
"del",
|
|
5987
6284
|
level
|
|
5988
6285
|
),
|
|
6286
|
+
// folder indices
|
|
5989
6287
|
...makeIndexOpsForDocument(
|
|
5990
6288
|
normalizedPath,
|
|
5991
6289
|
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
@@ -6025,7 +6323,7 @@ var Database = class {
|
|
|
6025
6323
|
);
|
|
6026
6324
|
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collectionName];
|
|
6027
6325
|
}
|
|
6028
|
-
const normalizedPath = (0,
|
|
6326
|
+
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6029
6327
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
6030
6328
|
const collection = await this.collectionForPath(filepath);
|
|
6031
6329
|
if (!collection) {
|
|
@@ -6080,6 +6378,7 @@ var Database = class {
|
|
|
6080
6378
|
"put",
|
|
6081
6379
|
level
|
|
6082
6380
|
),
|
|
6381
|
+
// folder indices
|
|
6083
6382
|
...makeIndexOpsForDocument(
|
|
6084
6383
|
normalizedPath,
|
|
6085
6384
|
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
@@ -6102,6 +6401,7 @@ var Database = class {
|
|
|
6102
6401
|
"del",
|
|
6103
6402
|
level
|
|
6104
6403
|
),
|
|
6404
|
+
// folder indices
|
|
6105
6405
|
...makeIndexOpsForDocument(
|
|
6106
6406
|
normalizedPath,
|
|
6107
6407
|
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
@@ -6179,6 +6479,7 @@ var Database = class {
|
|
|
6179
6479
|
aliasedData,
|
|
6180
6480
|
extension,
|
|
6181
6481
|
writeTemplateKey,
|
|
6482
|
+
//templateInfo.type === 'union',
|
|
6182
6483
|
{
|
|
6183
6484
|
frontmatterFormat: collection == null ? void 0 : collection.frontmatterFormat,
|
|
6184
6485
|
frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters
|
|
@@ -6196,7 +6497,7 @@ var Database = class {
|
|
|
6196
6497
|
};
|
|
6197
6498
|
this.getLookup = async (returnType) => {
|
|
6198
6499
|
await this.initLevel();
|
|
6199
|
-
const lookupPath = (0,
|
|
6500
|
+
const lookupPath = (0, import_schema_tools4.normalizePath)(
|
|
6200
6501
|
import_node_path.default.join(this.getGeneratedFolder(), `_lookup.json`)
|
|
6201
6502
|
);
|
|
6202
6503
|
if (!this._lookup) {
|
|
@@ -6209,7 +6510,7 @@ var Database = class {
|
|
|
6209
6510
|
};
|
|
6210
6511
|
this.getGraphQLSchema = async () => {
|
|
6211
6512
|
await this.initLevel();
|
|
6212
|
-
const graphqlPath = (0,
|
|
6513
|
+
const graphqlPath = (0, import_schema_tools4.normalizePath)(
|
|
6213
6514
|
import_node_path.default.join(this.getGeneratedFolder(), `_graphql.json`)
|
|
6214
6515
|
);
|
|
6215
6516
|
return await this.contentLevel.sublevel(
|
|
@@ -6217,11 +6518,12 @@ var Database = class {
|
|
|
6217
6518
|
SUBLEVEL_OPTIONS
|
|
6218
6519
|
).get(graphqlPath);
|
|
6219
6520
|
};
|
|
6521
|
+
//TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
|
|
6220
6522
|
this.getGraphQLSchemaFromBridge = async () => {
|
|
6221
6523
|
if (!this.bridge) {
|
|
6222
6524
|
throw new Error(`No bridge configured`);
|
|
6223
6525
|
}
|
|
6224
|
-
const graphqlPath = (0,
|
|
6526
|
+
const graphqlPath = (0, import_schema_tools4.normalizePath)(
|
|
6225
6527
|
import_node_path.default.join(this.getGeneratedFolder(), `_graphql.json`)
|
|
6226
6528
|
);
|
|
6227
6529
|
const _graphql = await this.bridge.get(graphqlPath);
|
|
@@ -6229,7 +6531,7 @@ var Database = class {
|
|
|
6229
6531
|
};
|
|
6230
6532
|
this.getTinaSchema = async (level) => {
|
|
6231
6533
|
await this.initLevel();
|
|
6232
|
-
const schemaPath = (0,
|
|
6534
|
+
const schemaPath = (0, import_schema_tools4.normalizePath)(
|
|
6233
6535
|
import_node_path.default.join(this.getGeneratedFolder(), `_schema.json`)
|
|
6234
6536
|
);
|
|
6235
6537
|
return await (level || this.contentLevel).sublevel(
|
|
@@ -6245,7 +6547,7 @@ var Database = class {
|
|
|
6245
6547
|
const schema = existingSchema || await this.getTinaSchema(level || this.contentLevel);
|
|
6246
6548
|
if (!schema) {
|
|
6247
6549
|
throw new Error(
|
|
6248
|
-
`Unable to get schema from level db: ${(0,
|
|
6550
|
+
`Unable to get schema from level db: ${(0, import_schema_tools4.normalizePath)(
|
|
6249
6551
|
import_node_path.default.join(this.getGeneratedFolder(), `_schema.json`)
|
|
6250
6552
|
)}`
|
|
6251
6553
|
);
|
|
@@ -6263,6 +6565,7 @@ var Database = class {
|
|
|
6263
6565
|
for (const collection of collections) {
|
|
6264
6566
|
const indexDefinitions = {
|
|
6265
6567
|
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
|
|
6568
|
+
// provide a default sort key which is the file sort
|
|
6266
6569
|
};
|
|
6267
6570
|
if (collection.fields) {
|
|
6268
6571
|
for (const field of collection.fields) {
|
|
@@ -6461,7 +6764,7 @@ var Database = class {
|
|
|
6461
6764
|
try {
|
|
6462
6765
|
lookup = lookupFromLockFile || JSON.parse(
|
|
6463
6766
|
await this.bridge.get(
|
|
6464
|
-
(0,
|
|
6767
|
+
(0, import_schema_tools4.normalizePath)(
|
|
6465
6768
|
import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")
|
|
6466
6769
|
)
|
|
6467
6770
|
)
|
|
@@ -6486,15 +6789,15 @@ var Database = class {
|
|
|
6486
6789
|
}
|
|
6487
6790
|
const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
|
|
6488
6791
|
await contentRootLevel.put(
|
|
6489
|
-
(0,
|
|
6792
|
+
(0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_graphql.json")),
|
|
6490
6793
|
graphQLSchema
|
|
6491
6794
|
);
|
|
6492
6795
|
await contentRootLevel.put(
|
|
6493
|
-
(0,
|
|
6796
|
+
(0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_schema.json")),
|
|
6494
6797
|
tinaSchema.schema
|
|
6495
6798
|
);
|
|
6496
6799
|
await contentRootLevel.put(
|
|
6497
|
-
(0,
|
|
6800
|
+
(0, import_schema_tools4.normalizePath)(import_node_path.default.join(this.getGeneratedFolder(), "_lookup.json")),
|
|
6498
6801
|
lookup
|
|
6499
6802
|
);
|
|
6500
6803
|
const result = await this._indexAllContent(
|
|
@@ -6587,12 +6890,12 @@ var Database = class {
|
|
|
6587
6890
|
if (collection == null ? void 0 : collection.isDetached) {
|
|
6588
6891
|
level = this.appLevel.sublevel(collection == null ? void 0 : collection.name, SUBLEVEL_OPTIONS);
|
|
6589
6892
|
}
|
|
6590
|
-
const
|
|
6893
|
+
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6591
6894
|
const rootSublevel = level.sublevel(
|
|
6592
6895
|
CONTENT_ROOT_PREFIX,
|
|
6593
6896
|
SUBLEVEL_OPTIONS
|
|
6594
6897
|
);
|
|
6595
|
-
const item = await rootSublevel.get(
|
|
6898
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
6596
6899
|
if (item) {
|
|
6597
6900
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
6598
6901
|
const folderKey = folderTreeBuilder.update(
|
|
@@ -6601,15 +6904,16 @@ var Database = class {
|
|
|
6601
6904
|
);
|
|
6602
6905
|
await this.contentLevel.batch([
|
|
6603
6906
|
...makeIndexOpsForDocument(
|
|
6604
|
-
|
|
6907
|
+
normalizedPath,
|
|
6605
6908
|
collection.name,
|
|
6606
6909
|
collectionIndexDefinitions,
|
|
6607
6910
|
item,
|
|
6608
6911
|
"del",
|
|
6609
6912
|
level
|
|
6610
6913
|
),
|
|
6914
|
+
// folder indices
|
|
6611
6915
|
...makeIndexOpsForDocument(
|
|
6612
|
-
|
|
6916
|
+
normalizedPath,
|
|
6613
6917
|
`${collection.name}_${folderKey}`,
|
|
6614
6918
|
collectionIndexDefinitions,
|
|
6615
6919
|
item,
|
|
@@ -6618,17 +6922,17 @@ var Database = class {
|
|
|
6618
6922
|
),
|
|
6619
6923
|
{
|
|
6620
6924
|
type: "del",
|
|
6621
|
-
key:
|
|
6925
|
+
key: normalizedPath,
|
|
6622
6926
|
sublevel: rootSublevel
|
|
6623
6927
|
}
|
|
6624
6928
|
]);
|
|
6625
6929
|
}
|
|
6626
6930
|
if (!(collection == null ? void 0 : collection.isDetached)) {
|
|
6627
6931
|
if (this.bridge) {
|
|
6628
|
-
await this.bridge.delete(
|
|
6932
|
+
await this.bridge.delete(normalizedPath);
|
|
6629
6933
|
}
|
|
6630
6934
|
try {
|
|
6631
|
-
await this.onDelete(
|
|
6935
|
+
await this.onDelete(normalizedPath);
|
|
6632
6936
|
} catch (e) {
|
|
6633
6937
|
throw new import_graphql6.GraphQLError(
|
|
6634
6938
|
`Error running onDelete hook for ${filepath}: ${e}`,
|
|
@@ -6762,6 +7066,9 @@ var Database = class {
|
|
|
6762
7066
|
info: templateInfo
|
|
6763
7067
|
};
|
|
6764
7068
|
}
|
|
7069
|
+
/**
|
|
7070
|
+
* Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
|
|
7071
|
+
*/
|
|
6765
7072
|
clearCache() {
|
|
6766
7073
|
this.tinaSchema = null;
|
|
6767
7074
|
this._lookup = null;
|
|
@@ -6843,7 +7150,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6843
7150
|
if (passwordFields == null ? void 0 : passwordFields.length) {
|
|
6844
7151
|
await hashPasswordValues(aliasedData, passwordFields);
|
|
6845
7152
|
}
|
|
6846
|
-
const normalizedPath = (0,
|
|
7153
|
+
const normalizedPath = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6847
7154
|
const folderKey = folderTreeBuilder.update(
|
|
6848
7155
|
normalizedPath,
|
|
6849
7156
|
collectionPath || ""
|
|
@@ -6858,6 +7165,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6858
7165
|
"put",
|
|
6859
7166
|
level
|
|
6860
7167
|
),
|
|
7168
|
+
// folder indexes
|
|
6861
7169
|
...makeIndexOpsForDocument(
|
|
6862
7170
|
normalizedPath,
|
|
6863
7171
|
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
@@ -6923,7 +7231,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6923
7231
|
);
|
|
6924
7232
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
6925
7233
|
await sequential(documentPaths, async (filepath) => {
|
|
6926
|
-
const itemKey = (0,
|
|
7234
|
+
const itemKey = (0, import_schema_tools4.normalizePath)(filepath);
|
|
6927
7235
|
const item = await rootLevel.get(itemKey);
|
|
6928
7236
|
if (item) {
|
|
6929
7237
|
const folderKey = folderTreeBuilder.update(
|
|
@@ -6943,6 +7251,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6943
7251
|
"del",
|
|
6944
7252
|
database.contentLevel
|
|
6945
7253
|
),
|
|
7254
|
+
// folder indexes
|
|
6946
7255
|
...makeIndexOpsForDocument(
|
|
6947
7256
|
itemKey,
|
|
6948
7257
|
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
@@ -7009,14 +7318,14 @@ var getChangedFiles = async ({
|
|
|
7009
7318
|
const rootDir = await findGitRoot(dir);
|
|
7010
7319
|
let pathPrefix = "";
|
|
7011
7320
|
if (rootDir !== dir) {
|
|
7012
|
-
pathPrefix = (0,
|
|
7321
|
+
pathPrefix = (0, import_schema_tools4.normalizePath)(dir.substring(rootDir.length + 1));
|
|
7013
7322
|
}
|
|
7014
7323
|
await import_isomorphic_git.default.walk({
|
|
7015
7324
|
fs: fs4,
|
|
7016
7325
|
dir: rootDir,
|
|
7017
7326
|
trees: [import_isomorphic_git.default.TREE({ ref: from }), import_isomorphic_git.default.TREE({ ref: to })],
|
|
7018
7327
|
map: async function(filename, [A, B]) {
|
|
7019
|
-
const relativePath = (0,
|
|
7328
|
+
const relativePath = (0, import_schema_tools4.normalizePath)(filename).substring(pathPrefix.length);
|
|
7020
7329
|
let matches = false;
|
|
7021
7330
|
for (const [key, matcher] of Object.entries(pathFilter)) {
|
|
7022
7331
|
if (relativePath.startsWith(key)) {
|
|
@@ -7158,17 +7467,26 @@ var IsomorphicBridge = class {
|
|
|
7158
7467
|
getAuthor() {
|
|
7159
7468
|
return {
|
|
7160
7469
|
...this.author,
|
|
7161
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7470
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
7162
7471
|
timezoneOffset: 0
|
|
7163
7472
|
};
|
|
7164
7473
|
}
|
|
7165
7474
|
getCommitter() {
|
|
7166
7475
|
return {
|
|
7167
7476
|
...this.committer,
|
|
7168
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7477
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
7169
7478
|
timezoneOffset: 0
|
|
7170
7479
|
};
|
|
7171
7480
|
}
|
|
7481
|
+
/**
|
|
7482
|
+
* Recursively populate paths matching `pattern` for the given `entry`
|
|
7483
|
+
*
|
|
7484
|
+
* @param pattern - pattern to filter paths by
|
|
7485
|
+
* @param entry - TreeEntry to start building list from
|
|
7486
|
+
* @param path - base path
|
|
7487
|
+
* @param results
|
|
7488
|
+
* @private
|
|
7489
|
+
*/
|
|
7172
7490
|
async listEntries({
|
|
7173
7491
|
pattern,
|
|
7174
7492
|
entry,
|
|
@@ -7201,6 +7519,15 @@ var IsomorphicBridge = class {
|
|
|
7201
7519
|
});
|
|
7202
7520
|
}
|
|
7203
7521
|
}
|
|
7522
|
+
/**
|
|
7523
|
+
* For the specified path, returns an object with an array containing the parts of the path (pathParts)
|
|
7524
|
+
* and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
|
|
7525
|
+
* pathEntries are placeholders for non-existent entries.
|
|
7526
|
+
*
|
|
7527
|
+
* @param path - path being resolved
|
|
7528
|
+
* @param ref - ref to resolve path entries for
|
|
7529
|
+
* @private
|
|
7530
|
+
*/
|
|
7204
7531
|
async resolvePathEntries(path7, ref) {
|
|
7205
7532
|
let pathParts = path7.split("/");
|
|
7206
7533
|
const result = await import_isomorphic_git2.default.walk({
|
|
@@ -7231,6 +7558,17 @@ var IsomorphicBridge = class {
|
|
|
7231
7558
|
}
|
|
7232
7559
|
return { pathParts, pathEntries };
|
|
7233
7560
|
}
|
|
7561
|
+
/**
|
|
7562
|
+
* Updates tree entry and associated parent tree entries
|
|
7563
|
+
*
|
|
7564
|
+
* @param existingOid - the existing OID
|
|
7565
|
+
* @param updatedOid - the updated OID
|
|
7566
|
+
* @param path - the path of the entry being updated
|
|
7567
|
+
* @param type - the type of the entry being updated (blob or tree)
|
|
7568
|
+
* @param pathEntries - parent path entries
|
|
7569
|
+
* @param pathParts - parent path parts
|
|
7570
|
+
* @private
|
|
7571
|
+
*/
|
|
7234
7572
|
async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
|
|
7235
7573
|
const lastIdx = pathEntries.length - 1;
|
|
7236
7574
|
const parentEntry = pathEntries[lastIdx];
|
|
@@ -7286,6 +7624,13 @@ var IsomorphicBridge = class {
|
|
|
7286
7624
|
);
|
|
7287
7625
|
}
|
|
7288
7626
|
}
|
|
7627
|
+
/**
|
|
7628
|
+
* Creates a commit for the specified tree and updates the specified ref to point to the commit
|
|
7629
|
+
*
|
|
7630
|
+
* @param treeSha - sha of the new tree
|
|
7631
|
+
* @param ref - the ref that should be updated
|
|
7632
|
+
* @private
|
|
7633
|
+
*/
|
|
7289
7634
|
async commitTree(treeSha, ref) {
|
|
7290
7635
|
const commitSha = await import_isomorphic_git2.default.writeCommit({
|
|
7291
7636
|
...this.isomorphicConfig,
|
|
@@ -7298,6 +7643,7 @@ var IsomorphicBridge = class {
|
|
|
7298
7643
|
})
|
|
7299
7644
|
],
|
|
7300
7645
|
message: this.commitMessage,
|
|
7646
|
+
// TODO these should be configurable
|
|
7301
7647
|
author: this.getAuthor(),
|
|
7302
7648
|
committer: this.getCommitter()
|
|
7303
7649
|
}
|
|
@@ -7536,5 +7882,5 @@ var buildSchema = async (config, flags) => {
|
|
|
7536
7882
|
transformDocument,
|
|
7537
7883
|
transformDocumentIntoPayload
|
|
7538
7884
|
});
|
|
7539
|
-
//! Replaces _.flattenDeep()
|
|
7540
7885
|
//! Replaces _.get()
|
|
7886
|
+
//! Replaces _.flattenDeep()
|