@tinacms/graphql 1.5.9 → 1.5.10
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 +437 -90
- package/dist/index.mjs +408 -65
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -68,6 +68,15 @@ var SysFieldDefinition = {
|
|
|
68
68
|
selectionSet: {
|
|
69
69
|
kind: "SelectionSet",
|
|
70
70
|
selections: [
|
|
71
|
+
// {
|
|
72
|
+
// kind: 'Field' as const,
|
|
73
|
+
// name: {
|
|
74
|
+
// kind: 'Name' as const,
|
|
75
|
+
// value: 'title',
|
|
76
|
+
// },
|
|
77
|
+
// arguments: [],
|
|
78
|
+
// directives: [],
|
|
79
|
+
// },
|
|
71
80
|
{
|
|
72
81
|
kind: "Field",
|
|
73
82
|
name: {
|
|
@@ -135,6 +144,10 @@ var SysFieldDefinition = {
|
|
|
135
144
|
}
|
|
136
145
|
};
|
|
137
146
|
var astBuilder = {
|
|
147
|
+
/**
|
|
148
|
+
* `FormFieldBuilder` acts as a shortcut to building an entire `ObjectTypeDefinition`, we use this
|
|
149
|
+
* because all Tina field objects share a common set of fields ('name', 'label', 'component')
|
|
150
|
+
*/
|
|
138
151
|
FormFieldBuilder: ({
|
|
139
152
|
name,
|
|
140
153
|
additionalFields
|
|
@@ -358,6 +371,8 @@ var astBuilder = {
|
|
|
358
371
|
kind: "Name",
|
|
359
372
|
value: name
|
|
360
373
|
},
|
|
374
|
+
// @ts-ignore FIXME; this is being handled properly but we're lying to
|
|
375
|
+
// ts and then fixing it in the `extractInlineTypes` function
|
|
361
376
|
fields
|
|
362
377
|
}),
|
|
363
378
|
UnionTypeDefinition: ({
|
|
@@ -370,6 +385,8 @@ var astBuilder = {
|
|
|
370
385
|
value: name
|
|
371
386
|
},
|
|
372
387
|
directives: [],
|
|
388
|
+
// @ts-ignore FIXME; this is being handled properly but we're lying to
|
|
389
|
+
// ts and then fixing it in the `extractInlineTypes` function
|
|
373
390
|
types: types.map((name2) => ({
|
|
374
391
|
kind: "NamedType",
|
|
375
392
|
name: {
|
|
@@ -466,8 +483,11 @@ var astBuilder = {
|
|
|
466
483
|
string: "String",
|
|
467
484
|
boolean: "Boolean",
|
|
468
485
|
number: "Float",
|
|
486
|
+
// FIXME - needs to be float or int
|
|
469
487
|
datetime: "String",
|
|
488
|
+
// FIXME
|
|
470
489
|
image: "String",
|
|
490
|
+
// FIXME
|
|
471
491
|
text: "String"
|
|
472
492
|
};
|
|
473
493
|
return scalars[type];
|
|
@@ -966,8 +986,7 @@ var astBuilder = {
|
|
|
966
986
|
}
|
|
967
987
|
};
|
|
968
988
|
var capitalize = (s) => {
|
|
969
|
-
if (typeof s !== "string")
|
|
970
|
-
return "";
|
|
989
|
+
if (typeof s !== "string") return "";
|
|
971
990
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
972
991
|
};
|
|
973
992
|
var extractInlineTypes = (item) => {
|
|
@@ -1010,41 +1029,6 @@ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
|
|
|
1010
1029
|
yield maybeNode;
|
|
1011
1030
|
visited.add(maybeNode);
|
|
1012
1031
|
}
|
|
1013
|
-
function addNamespaceToSchema(maybeNode, namespace = []) {
|
|
1014
|
-
if (typeof maybeNode === "string") {
|
|
1015
|
-
return maybeNode;
|
|
1016
|
-
}
|
|
1017
|
-
if (typeof maybeNode === "boolean") {
|
|
1018
|
-
return maybeNode;
|
|
1019
|
-
}
|
|
1020
|
-
const newNode = maybeNode;
|
|
1021
|
-
const keys = Object.keys(maybeNode);
|
|
1022
|
-
Object.values(maybeNode).map((m, index) => {
|
|
1023
|
-
const key = keys[index];
|
|
1024
|
-
if (Array.isArray(m)) {
|
|
1025
|
-
newNode[key] = m.map((element) => {
|
|
1026
|
-
if (!element) {
|
|
1027
|
-
return;
|
|
1028
|
-
}
|
|
1029
|
-
if (!element.hasOwnProperty("name")) {
|
|
1030
|
-
return element;
|
|
1031
|
-
}
|
|
1032
|
-
const value = element.name || element.value;
|
|
1033
|
-
return addNamespaceToSchema(element, [...namespace, value]);
|
|
1034
|
-
});
|
|
1035
|
-
} else {
|
|
1036
|
-
if (!m) {
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
if (!m.hasOwnProperty("name")) {
|
|
1040
|
-
newNode[key] = m;
|
|
1041
|
-
} else {
|
|
1042
|
-
newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
});
|
|
1046
|
-
return { ...newNode, namespace };
|
|
1047
|
-
}
|
|
1048
1032
|
var generateNamespacedFieldName = (names, suffix = "") => {
|
|
1049
1033
|
return (suffix ? [...names, suffix] : names).map(capitalize).join("");
|
|
1050
1034
|
};
|
|
@@ -1422,6 +1406,19 @@ var Builder = class {
|
|
|
1422
1406
|
this.addToLookupMap = (lookup) => {
|
|
1423
1407
|
this.lookupMap[lookup.type] = lookup;
|
|
1424
1408
|
};
|
|
1409
|
+
/**
|
|
1410
|
+
* ```graphql
|
|
1411
|
+
* # ex.
|
|
1412
|
+
* {
|
|
1413
|
+
* getCollection(collection: $collection) {
|
|
1414
|
+
* name
|
|
1415
|
+
* documents {...}
|
|
1416
|
+
* }
|
|
1417
|
+
* }
|
|
1418
|
+
* ```
|
|
1419
|
+
*
|
|
1420
|
+
* @param collections
|
|
1421
|
+
*/
|
|
1425
1422
|
this.buildCollectionDefinition = async (collections) => {
|
|
1426
1423
|
const name = "collection";
|
|
1427
1424
|
const typeName = "Collection";
|
|
@@ -1492,6 +1489,19 @@ var Builder = class {
|
|
|
1492
1489
|
required: true
|
|
1493
1490
|
});
|
|
1494
1491
|
};
|
|
1492
|
+
/**
|
|
1493
|
+
* ```graphql
|
|
1494
|
+
* # ex.
|
|
1495
|
+
* {
|
|
1496
|
+
* getCollections {
|
|
1497
|
+
* name
|
|
1498
|
+
* documents {...}
|
|
1499
|
+
* }
|
|
1500
|
+
* }
|
|
1501
|
+
* ```
|
|
1502
|
+
*
|
|
1503
|
+
* @param collections
|
|
1504
|
+
*/
|
|
1495
1505
|
this.buildMultiCollectionDefinition = async (collections) => {
|
|
1496
1506
|
const name = "collections";
|
|
1497
1507
|
const typeName = "Collection";
|
|
@@ -1502,6 +1512,17 @@ var Builder = class {
|
|
|
1502
1512
|
required: true
|
|
1503
1513
|
});
|
|
1504
1514
|
};
|
|
1515
|
+
/**
|
|
1516
|
+
* ```graphql
|
|
1517
|
+
* # ex.
|
|
1518
|
+
* {
|
|
1519
|
+
* node(id: $id) {
|
|
1520
|
+
* id
|
|
1521
|
+
* data {...}
|
|
1522
|
+
* }
|
|
1523
|
+
* }
|
|
1524
|
+
* ```
|
|
1525
|
+
*/
|
|
1505
1526
|
this.multiNodeDocument = async () => {
|
|
1506
1527
|
const name = "node";
|
|
1507
1528
|
const args = [
|
|
@@ -1522,6 +1543,19 @@ var Builder = class {
|
|
|
1522
1543
|
required: true
|
|
1523
1544
|
});
|
|
1524
1545
|
};
|
|
1546
|
+
/**
|
|
1547
|
+
* ```graphql
|
|
1548
|
+
* # ex.
|
|
1549
|
+
* {
|
|
1550
|
+
* getDocument(collection: $collection, relativePath: $relativePath) {
|
|
1551
|
+
* id
|
|
1552
|
+
* data {...}
|
|
1553
|
+
* }
|
|
1554
|
+
* }
|
|
1555
|
+
* ```
|
|
1556
|
+
*
|
|
1557
|
+
* @param collections
|
|
1558
|
+
*/
|
|
1525
1559
|
this.multiCollectionDocument = async (collections) => {
|
|
1526
1560
|
const name = "document";
|
|
1527
1561
|
const args = [
|
|
@@ -1547,6 +1581,19 @@ var Builder = class {
|
|
|
1547
1581
|
required: true
|
|
1548
1582
|
});
|
|
1549
1583
|
};
|
|
1584
|
+
/**
|
|
1585
|
+
* ```graphql
|
|
1586
|
+
* # ex.
|
|
1587
|
+
* {
|
|
1588
|
+
* addPendingDocument(collection: $collection, relativePath: $relativePath, params: $params) {
|
|
1589
|
+
* id
|
|
1590
|
+
* data {...}
|
|
1591
|
+
* }
|
|
1592
|
+
* }
|
|
1593
|
+
* ```
|
|
1594
|
+
*
|
|
1595
|
+
* @param collections
|
|
1596
|
+
*/
|
|
1550
1597
|
this.addMultiCollectionDocumentMutation = async () => {
|
|
1551
1598
|
return astBuilder.FieldDefinition({
|
|
1552
1599
|
name: "addPendingDocument",
|
|
@@ -1571,6 +1618,19 @@ var Builder = class {
|
|
|
1571
1618
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1572
1619
|
});
|
|
1573
1620
|
};
|
|
1621
|
+
/**
|
|
1622
|
+
* ```graphql
|
|
1623
|
+
* # ex.
|
|
1624
|
+
* {
|
|
1625
|
+
* createDocument(relativePath: $relativePath, params: $params) {
|
|
1626
|
+
* id
|
|
1627
|
+
* data {...}
|
|
1628
|
+
* }
|
|
1629
|
+
* }
|
|
1630
|
+
* ```
|
|
1631
|
+
*
|
|
1632
|
+
* @param collections
|
|
1633
|
+
*/
|
|
1574
1634
|
this.buildCreateCollectionDocumentMutation = async (collections) => {
|
|
1575
1635
|
return astBuilder.FieldDefinition({
|
|
1576
1636
|
name: "createDocument",
|
|
@@ -1598,6 +1658,19 @@ var Builder = class {
|
|
|
1598
1658
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1599
1659
|
});
|
|
1600
1660
|
};
|
|
1661
|
+
/**
|
|
1662
|
+
* ```graphql
|
|
1663
|
+
* # ex.
|
|
1664
|
+
* {
|
|
1665
|
+
* updateDocument(relativePath: $relativePath, params: $params) {
|
|
1666
|
+
* id
|
|
1667
|
+
* data {...}
|
|
1668
|
+
* }
|
|
1669
|
+
* }
|
|
1670
|
+
* ```
|
|
1671
|
+
*
|
|
1672
|
+
* @param collections
|
|
1673
|
+
*/
|
|
1601
1674
|
this.buildUpdateCollectionDocumentMutation = async (collections) => {
|
|
1602
1675
|
return astBuilder.FieldDefinition({
|
|
1603
1676
|
name: "updateDocument",
|
|
@@ -1625,6 +1698,19 @@ var Builder = class {
|
|
|
1625
1698
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1626
1699
|
});
|
|
1627
1700
|
};
|
|
1701
|
+
/**
|
|
1702
|
+
* ```graphql
|
|
1703
|
+
* # ex.
|
|
1704
|
+
* {
|
|
1705
|
+
* deleteDocument(relativePath: $relativePath, params: $params) {
|
|
1706
|
+
* id
|
|
1707
|
+
* data {...}
|
|
1708
|
+
* }
|
|
1709
|
+
* }
|
|
1710
|
+
* ```
|
|
1711
|
+
*
|
|
1712
|
+
* @param collections
|
|
1713
|
+
*/
|
|
1628
1714
|
this.buildDeleteCollectionDocumentMutation = async (collections) => {
|
|
1629
1715
|
return astBuilder.FieldDefinition({
|
|
1630
1716
|
name: "deleteDocument",
|
|
@@ -1644,6 +1730,19 @@ var Builder = class {
|
|
|
1644
1730
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1645
1731
|
});
|
|
1646
1732
|
};
|
|
1733
|
+
/**
|
|
1734
|
+
* ```graphql
|
|
1735
|
+
* # ex.
|
|
1736
|
+
* {
|
|
1737
|
+
* createFolder(folderName: $folderName, params: $params) {
|
|
1738
|
+
* id
|
|
1739
|
+
* data {...}
|
|
1740
|
+
* }
|
|
1741
|
+
* }
|
|
1742
|
+
* ```
|
|
1743
|
+
*
|
|
1744
|
+
* @param collections
|
|
1745
|
+
*/
|
|
1647
1746
|
this.buildCreateCollectionFolderMutation = async () => {
|
|
1648
1747
|
return astBuilder.FieldDefinition({
|
|
1649
1748
|
name: "createFolder",
|
|
@@ -1663,6 +1762,19 @@ var Builder = class {
|
|
|
1663
1762
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1664
1763
|
});
|
|
1665
1764
|
};
|
|
1765
|
+
/**
|
|
1766
|
+
* ```graphql
|
|
1767
|
+
* # ex.
|
|
1768
|
+
* {
|
|
1769
|
+
* getPostDocument(relativePath: $relativePath) {
|
|
1770
|
+
* id
|
|
1771
|
+
* data {...}
|
|
1772
|
+
* }
|
|
1773
|
+
* }
|
|
1774
|
+
* ```
|
|
1775
|
+
*
|
|
1776
|
+
* @param collection
|
|
1777
|
+
*/
|
|
1666
1778
|
this.collectionDocument = async (collection) => {
|
|
1667
1779
|
const name = NAMER.queryName([collection.name]);
|
|
1668
1780
|
const type = await this._buildCollectionDocumentType(collection);
|
|
@@ -1723,6 +1835,20 @@ var Builder = class {
|
|
|
1723
1835
|
const args = [];
|
|
1724
1836
|
return astBuilder.FieldDefinition({ type, name, args, required: false });
|
|
1725
1837
|
};
|
|
1838
|
+
/**
|
|
1839
|
+
* Turns a collection into a fragment that gets updated on build. This fragment does not resolve references
|
|
1840
|
+
* ```graphql
|
|
1841
|
+
* # ex.
|
|
1842
|
+
* fragment AuthorsParts on Authors {
|
|
1843
|
+
* name
|
|
1844
|
+
* avatar
|
|
1845
|
+
* ...
|
|
1846
|
+
* }
|
|
1847
|
+
* ```
|
|
1848
|
+
*
|
|
1849
|
+
* @public
|
|
1850
|
+
* @param collection a Tina Cloud collection
|
|
1851
|
+
*/
|
|
1726
1852
|
this.collectionFragment = async (collection) => {
|
|
1727
1853
|
const name = NAMER.dataTypeName(collection.namespace);
|
|
1728
1854
|
const fragmentName = NAMER.fragmentName(collection.namespace);
|
|
@@ -1736,6 +1862,20 @@ var Builder = class {
|
|
|
1736
1862
|
selections: filterSelections(selections)
|
|
1737
1863
|
});
|
|
1738
1864
|
};
|
|
1865
|
+
/**
|
|
1866
|
+
* Given a collection this function returns its selections set. For example for Post this would return
|
|
1867
|
+
*
|
|
1868
|
+
* "
|
|
1869
|
+
* body
|
|
1870
|
+
* title
|
|
1871
|
+
* ... on Author {
|
|
1872
|
+
* name
|
|
1873
|
+
* heroImg
|
|
1874
|
+
* }
|
|
1875
|
+
*
|
|
1876
|
+
* But in the AST format
|
|
1877
|
+
*
|
|
1878
|
+
* */
|
|
1739
1879
|
this._getCollectionFragmentSelections = async (collection, depth) => {
|
|
1740
1880
|
const selections = [];
|
|
1741
1881
|
selections.push({
|
|
@@ -1817,9 +1957,9 @@ var Builder = class {
|
|
|
1817
1957
|
]
|
|
1818
1958
|
});
|
|
1819
1959
|
}
|
|
1960
|
+
// TODO: Should we throw here?
|
|
1820
1961
|
case "reference":
|
|
1821
|
-
if (depth >= this.maxDepth)
|
|
1822
|
-
return false;
|
|
1962
|
+
if (depth >= this.maxDepth) return false;
|
|
1823
1963
|
if (!("collections" in field)) {
|
|
1824
1964
|
return false;
|
|
1825
1965
|
}
|
|
@@ -1851,6 +1991,7 @@ var Builder = class {
|
|
|
1851
1991
|
name: field.name,
|
|
1852
1992
|
selections: [
|
|
1853
1993
|
...selections,
|
|
1994
|
+
// This is ... on Document { id }
|
|
1854
1995
|
{
|
|
1855
1996
|
kind: "InlineFragment",
|
|
1856
1997
|
typeCondition: {
|
|
@@ -1881,6 +2022,19 @@ var Builder = class {
|
|
|
1881
2022
|
});
|
|
1882
2023
|
}
|
|
1883
2024
|
};
|
|
2025
|
+
/**
|
|
2026
|
+
* ```graphql
|
|
2027
|
+
* # ex.
|
|
2028
|
+
* mutation {
|
|
2029
|
+
* updatePostDocument(relativePath: $relativePath, params: $params) {
|
|
2030
|
+
* id
|
|
2031
|
+
* data {...}
|
|
2032
|
+
* }
|
|
2033
|
+
* }
|
|
2034
|
+
* ```
|
|
2035
|
+
*
|
|
2036
|
+
* @param collection
|
|
2037
|
+
*/
|
|
1884
2038
|
this.updateCollectionDocumentMutation = async (collection) => {
|
|
1885
2039
|
return astBuilder.FieldDefinition({
|
|
1886
2040
|
type: await this._buildCollectionDocumentType(collection),
|
|
@@ -1900,6 +2054,19 @@ var Builder = class {
|
|
|
1900
2054
|
]
|
|
1901
2055
|
});
|
|
1902
2056
|
};
|
|
2057
|
+
/**
|
|
2058
|
+
* ```graphql
|
|
2059
|
+
* # ex.
|
|
2060
|
+
* mutation {
|
|
2061
|
+
* createPostDocument(relativePath: $relativePath, params: $params) {
|
|
2062
|
+
* id
|
|
2063
|
+
* data {...}
|
|
2064
|
+
* }
|
|
2065
|
+
* }
|
|
2066
|
+
* ```
|
|
2067
|
+
*
|
|
2068
|
+
* @param collection
|
|
2069
|
+
*/
|
|
1903
2070
|
this.createCollectionDocumentMutation = async (collection) => {
|
|
1904
2071
|
return astBuilder.FieldDefinition({
|
|
1905
2072
|
type: await this._buildCollectionDocumentType(collection),
|
|
@@ -1919,6 +2086,22 @@ var Builder = class {
|
|
|
1919
2086
|
]
|
|
1920
2087
|
});
|
|
1921
2088
|
};
|
|
2089
|
+
/**
|
|
2090
|
+
* ```graphql
|
|
2091
|
+
* # ex.
|
|
2092
|
+
* {
|
|
2093
|
+
* getPostList(first: 10) {
|
|
2094
|
+
* edges {
|
|
2095
|
+
* node {
|
|
2096
|
+
* id
|
|
2097
|
+
* }
|
|
2098
|
+
* }
|
|
2099
|
+
* }
|
|
2100
|
+
* }
|
|
2101
|
+
* ```
|
|
2102
|
+
*
|
|
2103
|
+
* @param collection
|
|
2104
|
+
*/
|
|
1922
2105
|
this.collectionDocumentList = async (collection) => {
|
|
1923
2106
|
const connectionName = NAMER.referenceConnectionType(collection.namespace);
|
|
1924
2107
|
this.addToLookupMap({
|
|
@@ -1934,6 +2117,10 @@ var Builder = class {
|
|
|
1934
2117
|
collection
|
|
1935
2118
|
});
|
|
1936
2119
|
};
|
|
2120
|
+
/**
|
|
2121
|
+
* GraphQL type definitions which remain unchanged regardless
|
|
2122
|
+
* of the supplied Tina schema. Ex. "node" interface
|
|
2123
|
+
*/
|
|
1937
2124
|
this.buildStaticDefinitions = () => staticDefinitions;
|
|
1938
2125
|
this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
|
|
1939
2126
|
const documentTypeName = NAMER.documentTypeName(collection.namespace);
|
|
@@ -2438,6 +2625,7 @@ var Builder = class {
|
|
|
2438
2625
|
name: NAMER.dataFilterTypeName(namespace),
|
|
2439
2626
|
fields: await sequential(collections, async (collection2) => {
|
|
2440
2627
|
return astBuilder.InputValueDefinition({
|
|
2628
|
+
// @ts-ignore
|
|
2441
2629
|
name: collection2.name,
|
|
2442
2630
|
type: NAMER.dataFilterTypeName(collection2.namespace)
|
|
2443
2631
|
});
|
|
@@ -2626,7 +2814,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2626
2814
|
]
|
|
2627
2815
|
});
|
|
2628
2816
|
};
|
|
2629
|
-
this.maxDepth =
|
|
2817
|
+
this.maxDepth = // @ts-ignore
|
|
2818
|
+
config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
|
|
2630
2819
|
this.tinaSchema = config.tinaSchema;
|
|
2631
2820
|
this.lookupMap = {};
|
|
2632
2821
|
}
|
|
@@ -2637,8 +2826,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2637
2826
|
selections.push(field);
|
|
2638
2827
|
});
|
|
2639
2828
|
const filteredSelections = filterSelections(selections);
|
|
2640
|
-
if (!filteredSelections.length)
|
|
2641
|
-
return false;
|
|
2829
|
+
if (!filteredSelections.length) return false;
|
|
2642
2830
|
return astBuilder.InlineFragmentDefinition({
|
|
2643
2831
|
selections: filteredSelections,
|
|
2644
2832
|
name: NAMER.dataTypeName(template.namespace)
|
|
@@ -2675,6 +2863,7 @@ var filterSelections = (arr) => {
|
|
|
2675
2863
|
import { TinaSchema } from "@tinacms/schema-tools";
|
|
2676
2864
|
|
|
2677
2865
|
// src/schema/validate.ts
|
|
2866
|
+
import { addNamespaceToSchema } from "@tinacms/schema-tools";
|
|
2678
2867
|
import deepClone from "lodash.clonedeep";
|
|
2679
2868
|
import * as yup2 from "yup";
|
|
2680
2869
|
import {
|
|
@@ -2721,6 +2910,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
2721
2910
|
}).map((x) => `${x.path}${x.format || "md"}`);
|
|
2722
2911
|
if (noMatchCollections.length !== new Set(noMatchCollections).size) {
|
|
2723
2912
|
throw new Error(
|
|
2913
|
+
// TODO: add a link to the docs
|
|
2724
2914
|
"Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
|
|
2725
2915
|
);
|
|
2726
2916
|
}
|
|
@@ -2829,7 +3019,7 @@ var validateField = async (field) => {
|
|
|
2829
3019
|
// package.json
|
|
2830
3020
|
var package_default = {
|
|
2831
3021
|
name: "@tinacms/graphql",
|
|
2832
|
-
version: "1.5.
|
|
3022
|
+
version: "1.5.10",
|
|
2833
3023
|
main: "dist/index.js",
|
|
2834
3024
|
module: "dist/index.mjs",
|
|
2835
3025
|
typings: "dist/index.d.ts",
|
|
@@ -2986,6 +3176,7 @@ var _buildFragments = async (builder, tinaSchema) => {
|
|
|
2986
3176
|
const fragDoc = {
|
|
2987
3177
|
kind: "Document",
|
|
2988
3178
|
definitions: uniqBy2(
|
|
3179
|
+
// @ts-ignore
|
|
2989
3180
|
extractInlineTypes(fragmentDefinitionsFields),
|
|
2990
3181
|
(node) => node.name.value
|
|
2991
3182
|
)
|
|
@@ -3008,6 +3199,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3008
3199
|
fragName,
|
|
3009
3200
|
queryName: queryListName,
|
|
3010
3201
|
filterType: queryFilterTypeName,
|
|
3202
|
+
// look for flag to see if the data layer is enabled
|
|
3011
3203
|
dataLayer: Boolean(
|
|
3012
3204
|
tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
|
|
3013
3205
|
)
|
|
@@ -3017,6 +3209,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3017
3209
|
const queryDoc = {
|
|
3018
3210
|
kind: "Document",
|
|
3019
3211
|
definitions: uniqBy2(
|
|
3212
|
+
// @ts-ignore
|
|
3020
3213
|
extractInlineTypes(operationsDefinitions),
|
|
3021
3214
|
(node) => node.name.value
|
|
3022
3215
|
)
|
|
@@ -3105,6 +3298,7 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3105
3298
|
return {
|
|
3106
3299
|
kind: "Document",
|
|
3107
3300
|
definitions: uniqBy2(
|
|
3301
|
+
// @ts-ignore
|
|
3108
3302
|
extractInlineTypes(definitions),
|
|
3109
3303
|
(node) => node.name.value
|
|
3110
3304
|
)
|
|
@@ -3309,8 +3503,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
|
|
|
3309
3503
|
}
|
|
3310
3504
|
if (Array.isArray(value)) {
|
|
3311
3505
|
return value.map((v) => {
|
|
3312
|
-
if (!v || typeof v !== "string")
|
|
3313
|
-
return v;
|
|
3506
|
+
if (!v || typeof v !== "string") return v;
|
|
3314
3507
|
const cleanMediaRoot = cleanUpSlashes(
|
|
3315
3508
|
schema.config.media.tina.mediaRoot
|
|
3316
3509
|
);
|
|
@@ -3338,8 +3531,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
|
|
|
3338
3531
|
}
|
|
3339
3532
|
if (Array.isArray(value)) {
|
|
3340
3533
|
return value.map((v) => {
|
|
3341
|
-
if (!v || typeof v !== "string")
|
|
3342
|
-
return v;
|
|
3534
|
+
if (!v || typeof v !== "string") return v;
|
|
3343
3535
|
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3344
3536
|
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3345
3537
|
});
|
|
@@ -3357,8 +3549,7 @@ var cleanUpSlashes = (path7) => {
|
|
|
3357
3549
|
return "";
|
|
3358
3550
|
};
|
|
3359
3551
|
var hasTinaMediaConfig = (schema) => {
|
|
3360
|
-
if (!schema.config?.media?.tina)
|
|
3361
|
-
return false;
|
|
3552
|
+
if (!schema.config?.media?.tina) return false;
|
|
3362
3553
|
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
3363
3554
|
return false;
|
|
3364
3555
|
return true;
|
|
@@ -3402,6 +3593,7 @@ var LevelProxyHandler = {
|
|
|
3402
3593
|
} else if (property === "sublevel") {
|
|
3403
3594
|
return (...args) => {
|
|
3404
3595
|
return new Proxy(
|
|
3596
|
+
// eslint-disable-next-line prefer-spread
|
|
3405
3597
|
target[property].apply(target, args),
|
|
3406
3598
|
LevelProxyHandler
|
|
3407
3599
|
);
|
|
@@ -4278,6 +4470,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
|
|
|
4278
4470
|
result.push({
|
|
4279
4471
|
type: opType,
|
|
4280
4472
|
key: `${collection.path}/${subFolderKey}.${collection.format}`,
|
|
4473
|
+
// replace the root with the collection path
|
|
4281
4474
|
sublevel: indexSublevel,
|
|
4282
4475
|
value: {}
|
|
4283
4476
|
});
|
|
@@ -4392,6 +4585,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4392
4585
|
case "password":
|
|
4393
4586
|
accumulator[field.name] = {
|
|
4394
4587
|
value: void 0,
|
|
4588
|
+
// never resolve the password hash
|
|
4395
4589
|
passwordChangeRequired: value["passwordChangeRequired"] ?? false
|
|
4396
4590
|
};
|
|
4397
4591
|
break;
|
|
@@ -4586,6 +4780,7 @@ var Resolver = class {
|
|
|
4586
4780
|
const collection = this.tinaSchema.getCollection(collectionName);
|
|
4587
4781
|
const extraFields = {};
|
|
4588
4782
|
return {
|
|
4783
|
+
// return the collection and hasDocuments to resolve documents at a lower level
|
|
4589
4784
|
documents: { collection, hasDocuments },
|
|
4590
4785
|
...collection,
|
|
4591
4786
|
...extraFields
|
|
@@ -4672,7 +4867,9 @@ var Resolver = class {
|
|
|
4672
4867
|
);
|
|
4673
4868
|
} else {
|
|
4674
4869
|
return this.buildFieldMutations(
|
|
4870
|
+
// @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
|
|
4675
4871
|
fieldValue,
|
|
4872
|
+
//@ts-ignore
|
|
4676
4873
|
objectTemplate,
|
|
4677
4874
|
existingData
|
|
4678
4875
|
);
|
|
@@ -4684,6 +4881,7 @@ var Resolver = class {
|
|
|
4684
4881
|
fieldValue.map(async (item) => {
|
|
4685
4882
|
if (typeof item === "string") {
|
|
4686
4883
|
throw new Error(
|
|
4884
|
+
//@ts-ignore
|
|
4687
4885
|
`Expected object for template value for field ${field.name}`
|
|
4688
4886
|
);
|
|
4689
4887
|
}
|
|
@@ -4692,16 +4890,19 @@ var Resolver = class {
|
|
|
4692
4890
|
});
|
|
4693
4891
|
const [templateName] = Object.entries(item)[0];
|
|
4694
4892
|
const template = templates.find(
|
|
4893
|
+
//@ts-ignore
|
|
4695
4894
|
(template2) => template2.name === templateName
|
|
4696
4895
|
);
|
|
4697
4896
|
if (!template) {
|
|
4698
4897
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4699
4898
|
}
|
|
4700
4899
|
return {
|
|
4900
|
+
// @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
|
|
4701
4901
|
...await this.buildFieldMutations(
|
|
4702
4902
|
item[template.name],
|
|
4703
4903
|
template
|
|
4704
4904
|
),
|
|
4905
|
+
//@ts-ignore
|
|
4705
4906
|
_template: template.name
|
|
4706
4907
|
};
|
|
4707
4908
|
})
|
|
@@ -4709,6 +4910,7 @@ var Resolver = class {
|
|
|
4709
4910
|
} else {
|
|
4710
4911
|
if (typeof fieldValue === "string") {
|
|
4711
4912
|
throw new Error(
|
|
4913
|
+
//@ts-ignore
|
|
4712
4914
|
`Expected object for template value for field ${field.name}`
|
|
4713
4915
|
);
|
|
4714
4916
|
}
|
|
@@ -4717,16 +4919,19 @@ var Resolver = class {
|
|
|
4717
4919
|
});
|
|
4718
4920
|
const [templateName] = Object.entries(fieldValue)[0];
|
|
4719
4921
|
const template = templates.find(
|
|
4922
|
+
//@ts-ignore
|
|
4720
4923
|
(template2) => template2.name === templateName
|
|
4721
4924
|
);
|
|
4722
4925
|
if (!template) {
|
|
4723
4926
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4724
4927
|
}
|
|
4725
4928
|
return {
|
|
4929
|
+
// @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
|
|
4726
4930
|
...await this.buildFieldMutations(
|
|
4727
4931
|
fieldValue[template.name],
|
|
4728
4932
|
template
|
|
4729
4933
|
),
|
|
4934
|
+
//@ts-ignore
|
|
4730
4935
|
_template: template.name
|
|
4731
4936
|
};
|
|
4732
4937
|
}
|
|
@@ -4766,6 +4971,7 @@ var Resolver = class {
|
|
|
4766
4971
|
return this.getDocument(realPath);
|
|
4767
4972
|
}
|
|
4768
4973
|
const params = await this.buildObjectMutations(
|
|
4974
|
+
// @ts-ignore
|
|
4769
4975
|
args.params[collection.name],
|
|
4770
4976
|
collection
|
|
4771
4977
|
);
|
|
@@ -4811,6 +5017,7 @@ var Resolver = class {
|
|
|
4811
5017
|
const values = {
|
|
4812
5018
|
...oldDoc,
|
|
4813
5019
|
...await this.buildFieldMutations(
|
|
5020
|
+
// @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
|
|
4814
5021
|
templateParams,
|
|
4815
5022
|
template,
|
|
4816
5023
|
doc?._rawData
|
|
@@ -4824,6 +5031,7 @@ var Resolver = class {
|
|
|
4824
5031
|
return this.getDocument(realPath);
|
|
4825
5032
|
}
|
|
4826
5033
|
const params = await this.buildObjectMutations(
|
|
5034
|
+
//@ts-ignore
|
|
4827
5035
|
isCollectionSpecific ? args.params : args.params[collection.name],
|
|
4828
5036
|
collection,
|
|
4829
5037
|
doc?._rawData
|
|
@@ -4831,6 +5039,10 @@ var Resolver = class {
|
|
|
4831
5039
|
await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
|
|
4832
5040
|
return this.getDocument(realPath);
|
|
4833
5041
|
};
|
|
5042
|
+
/**
|
|
5043
|
+
* Returns top-level fields which are not defined in the collection, so their
|
|
5044
|
+
* values are not eliminated from Tina when new values are saved
|
|
5045
|
+
*/
|
|
4834
5046
|
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
4835
5047
|
const legacyValues = {};
|
|
4836
5048
|
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
@@ -5036,6 +5248,7 @@ var Resolver = class {
|
|
|
5036
5248
|
},
|
|
5037
5249
|
collection: referencedCollection,
|
|
5038
5250
|
hydrator: (path7) => path7
|
|
5251
|
+
// just return the path
|
|
5039
5252
|
}
|
|
5040
5253
|
);
|
|
5041
5254
|
const { edges } = resolvedCollectionConnection;
|
|
@@ -5103,6 +5316,12 @@ var Resolver = class {
|
|
|
5103
5316
|
}
|
|
5104
5317
|
};
|
|
5105
5318
|
};
|
|
5319
|
+
/**
|
|
5320
|
+
* Checks if a document has references to it
|
|
5321
|
+
* @param id The id of the document to check for references
|
|
5322
|
+
* @param c The collection to check for references
|
|
5323
|
+
* @returns true if the document has references, false otherwise
|
|
5324
|
+
*/
|
|
5106
5325
|
this.hasReferences = async (id, c) => {
|
|
5107
5326
|
let count = 0;
|
|
5108
5327
|
const deepRefs = this.tinaSchema.findReferences(c.name);
|
|
@@ -5137,6 +5356,12 @@ var Resolver = class {
|
|
|
5137
5356
|
}
|
|
5138
5357
|
return false;
|
|
5139
5358
|
};
|
|
5359
|
+
/**
|
|
5360
|
+
* Finds references to a document
|
|
5361
|
+
* @param id the id of the document to find references to
|
|
5362
|
+
* @param c the collection to find references in
|
|
5363
|
+
* @returns references to the document in the form of a map of collection names to a list of fields that reference the document
|
|
5364
|
+
*/
|
|
5140
5365
|
this.findReferences = async (id, c) => {
|
|
5141
5366
|
const references = {};
|
|
5142
5367
|
const deepRefs = this.tinaSchema.findReferences(c.name);
|
|
@@ -5263,6 +5488,27 @@ var Resolver = class {
|
|
|
5263
5488
|
}
|
|
5264
5489
|
return accum;
|
|
5265
5490
|
};
|
|
5491
|
+
/**
|
|
5492
|
+
* A mutation looks nearly identical between updateDocument:
|
|
5493
|
+
* ```graphql
|
|
5494
|
+
* updateDocument(collection: $collection,relativePath: $path, params: {
|
|
5495
|
+
* post: {
|
|
5496
|
+
* title: "Hello, World"
|
|
5497
|
+
* }
|
|
5498
|
+
* })`
|
|
5499
|
+
* ```
|
|
5500
|
+
* and `updatePostDocument`:
|
|
5501
|
+
* ```graphql
|
|
5502
|
+
* updatePostDocument(relativePath: $path, params: {
|
|
5503
|
+
* title: "Hello, World"
|
|
5504
|
+
* })
|
|
5505
|
+
* ```
|
|
5506
|
+
* The problem here is that we don't know whether the payload came from `updateDocument`
|
|
5507
|
+
* or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
|
|
5508
|
+
* But we do know that when given a `args.collection` value, we can assume that
|
|
5509
|
+
* this was a `updateDocument` request, and thus - should grab the data
|
|
5510
|
+
* from the corresponding field name in the key
|
|
5511
|
+
*/
|
|
5266
5512
|
this.buildParams = (args) => {
|
|
5267
5513
|
try {
|
|
5268
5514
|
assertShape(
|
|
@@ -5362,7 +5608,10 @@ var resolve = async ({
|
|
|
5362
5608
|
const graphQLSchema = buildASTSchema(graphQLSchemaAst);
|
|
5363
5609
|
const tinaConfig = await database.getTinaSchema();
|
|
5364
5610
|
const tinaSchema = await createSchema({
|
|
5611
|
+
// TODO: please update all the types to import from @tinacms/schema-tools
|
|
5612
|
+
// @ts-ignore
|
|
5365
5613
|
schema: tinaConfig,
|
|
5614
|
+
// @ts-ignore
|
|
5366
5615
|
flags: tinaConfig?.meta?.flags
|
|
5367
5616
|
});
|
|
5368
5617
|
const resolver = createResolver({
|
|
@@ -5379,8 +5628,7 @@ var resolve = async ({
|
|
|
5379
5628
|
database
|
|
5380
5629
|
},
|
|
5381
5630
|
typeResolver: async (source, _args, info) => {
|
|
5382
|
-
if (source.__typename)
|
|
5383
|
-
return source.__typename;
|
|
5631
|
+
if (source.__typename) return source.__typename;
|
|
5384
5632
|
const namedType = getNamedType(info.returnType).toString();
|
|
5385
5633
|
const lookup = await database.getLookup(namedType);
|
|
5386
5634
|
if (lookup.resolveType === "unionData") {
|
|
@@ -5529,11 +5777,13 @@ var resolve = async ({
|
|
|
5529
5777
|
set(
|
|
5530
5778
|
params,
|
|
5531
5779
|
userField.path.slice(1),
|
|
5780
|
+
// remove _rawData from users path
|
|
5532
5781
|
users.map((u) => {
|
|
5533
5782
|
if (user[idFieldName] === u[idFieldName]) {
|
|
5534
5783
|
return user;
|
|
5535
5784
|
}
|
|
5536
5785
|
return {
|
|
5786
|
+
// don't overwrite other users' passwords
|
|
5537
5787
|
...u,
|
|
5538
5788
|
[passwordFieldName]: {
|
|
5539
5789
|
...u[passwordFieldName],
|
|
@@ -5556,6 +5806,9 @@ var resolve = async ({
|
|
|
5556
5806
|
}
|
|
5557
5807
|
const isCreation = lookup[info.fieldName] === "create";
|
|
5558
5808
|
switch (lookup.resolveType) {
|
|
5809
|
+
/**
|
|
5810
|
+
* `node(id: $id)`
|
|
5811
|
+
*/
|
|
5559
5812
|
case "nodeDocument":
|
|
5560
5813
|
assertShape(
|
|
5561
5814
|
args,
|
|
@@ -5587,6 +5840,7 @@ var resolve = async ({
|
|
|
5587
5840
|
collection: args.collection,
|
|
5588
5841
|
isMutation,
|
|
5589
5842
|
isCreation,
|
|
5843
|
+
// Right now this is the only case for deletion
|
|
5590
5844
|
isDeletion: info.fieldName === "deleteDocument",
|
|
5591
5845
|
isFolderCreation: info.fieldName === "createFolder",
|
|
5592
5846
|
isUpdateName: Boolean(args?.params?.relativePath),
|
|
@@ -5596,6 +5850,9 @@ var resolve = async ({
|
|
|
5596
5850
|
return result;
|
|
5597
5851
|
}
|
|
5598
5852
|
return value;
|
|
5853
|
+
/**
|
|
5854
|
+
* eg `getMovieDocument.data.actors`
|
|
5855
|
+
*/
|
|
5599
5856
|
case "multiCollectionDocumentList":
|
|
5600
5857
|
if (Array.isArray(value)) {
|
|
5601
5858
|
return {
|
|
@@ -5607,7 +5864,15 @@ var resolve = async ({
|
|
|
5607
5864
|
}
|
|
5608
5865
|
if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
|
|
5609
5866
|
let filter = args.filter;
|
|
5610
|
-
if (
|
|
5867
|
+
if (
|
|
5868
|
+
// 1. Make sure that the filter exists
|
|
5869
|
+
typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
|
|
5870
|
+
// @ts-ignore
|
|
5871
|
+
typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
|
|
5872
|
+
// @ts-ignore
|
|
5873
|
+
Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
|
|
5874
|
+
typeof args.filter[value?.collection?.name] !== "undefined"
|
|
5875
|
+
) {
|
|
5611
5876
|
filter = args.filter[value.collection.name];
|
|
5612
5877
|
}
|
|
5613
5878
|
return resolver.resolveCollectionConnection({
|
|
@@ -5615,12 +5880,20 @@ var resolve = async ({
|
|
|
5615
5880
|
...args,
|
|
5616
5881
|
filter
|
|
5617
5882
|
},
|
|
5883
|
+
// @ts-ignore
|
|
5618
5884
|
collection: value.collection
|
|
5619
5885
|
});
|
|
5620
5886
|
}
|
|
5621
5887
|
throw new Error(
|
|
5622
5888
|
`Expected an array for result of ${info.fieldName} at ${info.path}`
|
|
5623
5889
|
);
|
|
5890
|
+
/**
|
|
5891
|
+
* Collections-specific getter
|
|
5892
|
+
* eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
|
|
5893
|
+
*
|
|
5894
|
+
* if coming from a query result
|
|
5895
|
+
* the field will be `node`
|
|
5896
|
+
*/
|
|
5624
5897
|
case "collectionDocument": {
|
|
5625
5898
|
if (value) {
|
|
5626
5899
|
return value;
|
|
@@ -5635,11 +5908,32 @@ var resolve = async ({
|
|
|
5635
5908
|
});
|
|
5636
5909
|
return result;
|
|
5637
5910
|
}
|
|
5911
|
+
/**
|
|
5912
|
+
* Collections-specific list getter
|
|
5913
|
+
* eg. `getPageList`
|
|
5914
|
+
*/
|
|
5638
5915
|
case "collectionDocumentList":
|
|
5639
5916
|
return resolver.resolveCollectionConnection({
|
|
5640
5917
|
args,
|
|
5641
5918
|
collection: tinaSchema.getCollection(lookup.collection)
|
|
5642
5919
|
});
|
|
5920
|
+
/**
|
|
5921
|
+
* A polymorphic data set, it can be from a document's data
|
|
5922
|
+
* of any nested object which can be one of many shapes
|
|
5923
|
+
*
|
|
5924
|
+
* ```graphql
|
|
5925
|
+
* getPostDocument(relativePath: $relativePath) {
|
|
5926
|
+
* data {...} <- this part
|
|
5927
|
+
* }
|
|
5928
|
+
* ```
|
|
5929
|
+
* ```graphql
|
|
5930
|
+
* getBlockDocument(relativePath: $relativePath) {
|
|
5931
|
+
* data {
|
|
5932
|
+
* blocks {...} <- or this part
|
|
5933
|
+
* }
|
|
5934
|
+
* }
|
|
5935
|
+
* ```
|
|
5936
|
+
*/
|
|
5643
5937
|
case "unionData":
|
|
5644
5938
|
if (!value) {
|
|
5645
5939
|
if (args.relativePath) {
|
|
@@ -5704,8 +5998,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5704
5998
|
this.port = port || 9e3;
|
|
5705
5999
|
}
|
|
5706
6000
|
openConnection() {
|
|
5707
|
-
if (this._connected)
|
|
5708
|
-
return;
|
|
6001
|
+
if (this._connected) return;
|
|
5709
6002
|
const socket = connect(this.port);
|
|
5710
6003
|
pipeline(socket, this.createRpcStream(), socket, () => {
|
|
5711
6004
|
this._connected = false;
|
|
@@ -5715,7 +6008,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5715
6008
|
};
|
|
5716
6009
|
|
|
5717
6010
|
// src/database/index.ts
|
|
5718
|
-
import path4 from "path";
|
|
6011
|
+
import path4 from "node:path";
|
|
5719
6012
|
import { GraphQLError as GraphQLError5 } from "graphql";
|
|
5720
6013
|
import micromatch2 from "micromatch";
|
|
5721
6014
|
import sha2 from "js-sha1";
|
|
@@ -5886,6 +6179,7 @@ var Database = class {
|
|
|
5886
6179
|
"put",
|
|
5887
6180
|
level
|
|
5888
6181
|
),
|
|
6182
|
+
// folder indices
|
|
5889
6183
|
...makeIndexOpsForDocument(
|
|
5890
6184
|
normalizedPath,
|
|
5891
6185
|
`${collection?.name}_${folderKey}`,
|
|
@@ -5908,6 +6202,7 @@ var Database = class {
|
|
|
5908
6202
|
"del",
|
|
5909
6203
|
level
|
|
5910
6204
|
),
|
|
6205
|
+
// folder indices
|
|
5911
6206
|
...makeIndexOpsForDocument(
|
|
5912
6207
|
normalizedPath,
|
|
5913
6208
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6001,6 +6296,7 @@ var Database = class {
|
|
|
6001
6296
|
"put",
|
|
6002
6297
|
level
|
|
6003
6298
|
),
|
|
6299
|
+
// folder indices
|
|
6004
6300
|
...makeIndexOpsForDocument(
|
|
6005
6301
|
normalizedPath,
|
|
6006
6302
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6023,6 +6319,7 @@ var Database = class {
|
|
|
6023
6319
|
"del",
|
|
6024
6320
|
level
|
|
6025
6321
|
),
|
|
6322
|
+
// folder indices
|
|
6026
6323
|
...makeIndexOpsForDocument(
|
|
6027
6324
|
normalizedPath,
|
|
6028
6325
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6100,6 +6397,7 @@ var Database = class {
|
|
|
6100
6397
|
aliasedData,
|
|
6101
6398
|
extension,
|
|
6102
6399
|
writeTemplateKey,
|
|
6400
|
+
//templateInfo.type === 'union',
|
|
6103
6401
|
{
|
|
6104
6402
|
frontmatterFormat: collection?.frontmatterFormat,
|
|
6105
6403
|
frontmatterDelimiters: collection?.frontmatterDelimiters
|
|
@@ -6138,6 +6436,7 @@ var Database = class {
|
|
|
6138
6436
|
SUBLEVEL_OPTIONS
|
|
6139
6437
|
).get(graphqlPath);
|
|
6140
6438
|
};
|
|
6439
|
+
//TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
|
|
6141
6440
|
this.getGraphQLSchemaFromBridge = async () => {
|
|
6142
6441
|
if (!this.bridge) {
|
|
6143
6442
|
throw new Error(`No bridge configured`);
|
|
@@ -6184,6 +6483,7 @@ var Database = class {
|
|
|
6184
6483
|
for (const collection of collections) {
|
|
6185
6484
|
const indexDefinitions = {
|
|
6186
6485
|
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
|
|
6486
|
+
// provide a default sort key which is the file sort
|
|
6187
6487
|
};
|
|
6188
6488
|
if (collection.fields) {
|
|
6189
6489
|
for (const field of collection.fields) {
|
|
@@ -6507,12 +6807,12 @@ var Database = class {
|
|
|
6507
6807
|
if (collection?.isDetached) {
|
|
6508
6808
|
level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
|
|
6509
6809
|
}
|
|
6510
|
-
const
|
|
6810
|
+
const normalizedPath = normalizePath(filepath);
|
|
6511
6811
|
const rootSublevel = level.sublevel(
|
|
6512
6812
|
CONTENT_ROOT_PREFIX,
|
|
6513
6813
|
SUBLEVEL_OPTIONS
|
|
6514
6814
|
);
|
|
6515
|
-
const item = await rootSublevel.get(
|
|
6815
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
6516
6816
|
if (item) {
|
|
6517
6817
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
6518
6818
|
const folderKey = folderTreeBuilder.update(
|
|
@@ -6521,15 +6821,16 @@ var Database = class {
|
|
|
6521
6821
|
);
|
|
6522
6822
|
await this.contentLevel.batch([
|
|
6523
6823
|
...makeIndexOpsForDocument(
|
|
6524
|
-
|
|
6824
|
+
normalizedPath,
|
|
6525
6825
|
collection.name,
|
|
6526
6826
|
collectionIndexDefinitions,
|
|
6527
6827
|
item,
|
|
6528
6828
|
"del",
|
|
6529
6829
|
level
|
|
6530
6830
|
),
|
|
6831
|
+
// folder indices
|
|
6531
6832
|
...makeIndexOpsForDocument(
|
|
6532
|
-
|
|
6833
|
+
normalizedPath,
|
|
6533
6834
|
`${collection.name}_${folderKey}`,
|
|
6534
6835
|
collectionIndexDefinitions,
|
|
6535
6836
|
item,
|
|
@@ -6538,17 +6839,17 @@ var Database = class {
|
|
|
6538
6839
|
),
|
|
6539
6840
|
{
|
|
6540
6841
|
type: "del",
|
|
6541
|
-
key:
|
|
6842
|
+
key: normalizedPath,
|
|
6542
6843
|
sublevel: rootSublevel
|
|
6543
6844
|
}
|
|
6544
6845
|
]);
|
|
6545
6846
|
}
|
|
6546
6847
|
if (!collection?.isDetached) {
|
|
6547
6848
|
if (this.bridge) {
|
|
6548
|
-
await this.bridge.delete(
|
|
6849
|
+
await this.bridge.delete(normalizedPath);
|
|
6549
6850
|
}
|
|
6550
6851
|
try {
|
|
6551
|
-
await this.onDelete(
|
|
6852
|
+
await this.onDelete(normalizedPath);
|
|
6552
6853
|
} catch (e) {
|
|
6553
6854
|
throw new GraphQLError5(
|
|
6554
6855
|
`Error running onDelete hook for ${filepath}: ${e}`,
|
|
@@ -6682,6 +6983,9 @@ var Database = class {
|
|
|
6682
6983
|
info: templateInfo
|
|
6683
6984
|
};
|
|
6684
6985
|
}
|
|
6986
|
+
/**
|
|
6987
|
+
* Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
|
|
6988
|
+
*/
|
|
6685
6989
|
clearCache() {
|
|
6686
6990
|
this.tinaSchema = null;
|
|
6687
6991
|
this._lookup = null;
|
|
@@ -6778,6 +7082,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6778
7082
|
"put",
|
|
6779
7083
|
level
|
|
6780
7084
|
),
|
|
7085
|
+
// folder indexes
|
|
6781
7086
|
...makeIndexOpsForDocument(
|
|
6782
7087
|
normalizedPath,
|
|
6783
7088
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6863,6 +7168,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6863
7168
|
"del",
|
|
6864
7169
|
database.contentLevel
|
|
6865
7170
|
),
|
|
7171
|
+
// folder indexes
|
|
6866
7172
|
...makeIndexOpsForDocument(
|
|
6867
7173
|
itemKey,
|
|
6868
7174
|
`${collection?.name}_${folderKey}`,
|
|
@@ -7078,17 +7384,26 @@ var IsomorphicBridge = class {
|
|
|
7078
7384
|
getAuthor() {
|
|
7079
7385
|
return {
|
|
7080
7386
|
...this.author,
|
|
7081
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7387
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
7082
7388
|
timezoneOffset: 0
|
|
7083
7389
|
};
|
|
7084
7390
|
}
|
|
7085
7391
|
getCommitter() {
|
|
7086
7392
|
return {
|
|
7087
7393
|
...this.committer,
|
|
7088
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7394
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
7089
7395
|
timezoneOffset: 0
|
|
7090
7396
|
};
|
|
7091
7397
|
}
|
|
7398
|
+
/**
|
|
7399
|
+
* Recursively populate paths matching `pattern` for the given `entry`
|
|
7400
|
+
*
|
|
7401
|
+
* @param pattern - pattern to filter paths by
|
|
7402
|
+
* @param entry - TreeEntry to start building list from
|
|
7403
|
+
* @param path - base path
|
|
7404
|
+
* @param results
|
|
7405
|
+
* @private
|
|
7406
|
+
*/
|
|
7092
7407
|
async listEntries({
|
|
7093
7408
|
pattern,
|
|
7094
7409
|
entry,
|
|
@@ -7121,6 +7436,15 @@ var IsomorphicBridge = class {
|
|
|
7121
7436
|
});
|
|
7122
7437
|
}
|
|
7123
7438
|
}
|
|
7439
|
+
/**
|
|
7440
|
+
* For the specified path, returns an object with an array containing the parts of the path (pathParts)
|
|
7441
|
+
* and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
|
|
7442
|
+
* pathEntries are placeholders for non-existent entries.
|
|
7443
|
+
*
|
|
7444
|
+
* @param path - path being resolved
|
|
7445
|
+
* @param ref - ref to resolve path entries for
|
|
7446
|
+
* @private
|
|
7447
|
+
*/
|
|
7124
7448
|
async resolvePathEntries(path7, ref) {
|
|
7125
7449
|
let pathParts = path7.split("/");
|
|
7126
7450
|
const result = await git2.walk({
|
|
@@ -7151,6 +7475,17 @@ var IsomorphicBridge = class {
|
|
|
7151
7475
|
}
|
|
7152
7476
|
return { pathParts, pathEntries };
|
|
7153
7477
|
}
|
|
7478
|
+
/**
|
|
7479
|
+
* Updates tree entry and associated parent tree entries
|
|
7480
|
+
*
|
|
7481
|
+
* @param existingOid - the existing OID
|
|
7482
|
+
* @param updatedOid - the updated OID
|
|
7483
|
+
* @param path - the path of the entry being updated
|
|
7484
|
+
* @param type - the type of the entry being updated (blob or tree)
|
|
7485
|
+
* @param pathEntries - parent path entries
|
|
7486
|
+
* @param pathParts - parent path parts
|
|
7487
|
+
* @private
|
|
7488
|
+
*/
|
|
7154
7489
|
async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
|
|
7155
7490
|
const lastIdx = pathEntries.length - 1;
|
|
7156
7491
|
const parentEntry = pathEntries[lastIdx];
|
|
@@ -7206,6 +7541,13 @@ var IsomorphicBridge = class {
|
|
|
7206
7541
|
);
|
|
7207
7542
|
}
|
|
7208
7543
|
}
|
|
7544
|
+
/**
|
|
7545
|
+
* Creates a commit for the specified tree and updates the specified ref to point to the commit
|
|
7546
|
+
*
|
|
7547
|
+
* @param treeSha - sha of the new tree
|
|
7548
|
+
* @param ref - the ref that should be updated
|
|
7549
|
+
* @private
|
|
7550
|
+
*/
|
|
7209
7551
|
async commitTree(treeSha, ref) {
|
|
7210
7552
|
const commitSha = await git2.writeCommit({
|
|
7211
7553
|
...this.isomorphicConfig,
|
|
@@ -7218,6 +7560,7 @@ var IsomorphicBridge = class {
|
|
|
7218
7560
|
})
|
|
7219
7561
|
],
|
|
7220
7562
|
message: this.commitMessage,
|
|
7563
|
+
// TODO these should be configurable
|
|
7221
7564
|
author: this.getAuthor(),
|
|
7222
7565
|
committer: this.getCommitter()
|
|
7223
7566
|
}
|
|
@@ -7455,5 +7798,5 @@ export {
|
|
|
7455
7798
|
transformDocument,
|
|
7456
7799
|
transformDocumentIntoPayload
|
|
7457
7800
|
};
|
|
7458
|
-
//! Replaces _.flattenDeep()
|
|
7459
7801
|
//! Replaces _.get()
|
|
7802
|
+
//! Replaces _.flattenDeep()
|