@tinacms/graphql 0.0.0-d524599-20241117111320 → 0.0.0-d7c5ec1-20250219020924
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 +485 -105
- package/dist/index.mjs +453 -77
- package/package.json +16 -17
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.12",
|
|
2833
3023
|
main: "dist/index.js",
|
|
2834
3024
|
module: "dist/index.mjs",
|
|
2835
3025
|
typings: "dist/index.d.ts",
|
|
@@ -2856,8 +3046,8 @@ var package_default = {
|
|
|
2856
3046
|
build: "tinacms-scripts build",
|
|
2857
3047
|
docs: "pnpm typedoc",
|
|
2858
3048
|
serve: "pnpm nodemon dist/server.js",
|
|
2859
|
-
test: "
|
|
2860
|
-
"test-watch": "
|
|
3049
|
+
test: "vitest run",
|
|
3050
|
+
"test-watch": "vitest"
|
|
2861
3051
|
},
|
|
2862
3052
|
dependencies: {
|
|
2863
3053
|
"@iarna/toml": "^2.2.5",
|
|
@@ -2865,12 +3055,12 @@ var package_default = {
|
|
|
2865
3055
|
"@tinacms/schema-tools": "workspace:*",
|
|
2866
3056
|
"abstract-level": "^1.0.4",
|
|
2867
3057
|
"date-fns": "^2.30.0",
|
|
2868
|
-
"fast-glob": "^3.3.
|
|
2869
|
-
"fs-extra": "^11.
|
|
3058
|
+
"fast-glob": "^3.3.3",
|
|
3059
|
+
"fs-extra": "^11.3.0",
|
|
2870
3060
|
"glob-parent": "^6.0.2",
|
|
2871
3061
|
graphql: "15.8.0",
|
|
2872
3062
|
"gray-matter": "^4.0.3",
|
|
2873
|
-
"isomorphic-git": "^1.
|
|
3063
|
+
"isomorphic-git": "^1.29.0",
|
|
2874
3064
|
"js-sha1": "^0.6.0",
|
|
2875
3065
|
"js-yaml": "^3.14.1",
|
|
2876
3066
|
"jsonpath-plus": "10.1.0",
|
|
@@ -2880,7 +3070,7 @@ var package_default = {
|
|
|
2880
3070
|
"many-level": "^2.0.0",
|
|
2881
3071
|
micromatch: "4.0.8",
|
|
2882
3072
|
"normalize-path": "^3.0.0",
|
|
2883
|
-
"readable-stream": "^4.
|
|
3073
|
+
"readable-stream": "^4.7.0",
|
|
2884
3074
|
scmp: "^2.1.0",
|
|
2885
3075
|
yup: "^0.32.11"
|
|
2886
3076
|
},
|
|
@@ -2898,24 +3088,23 @@ var package_default = {
|
|
|
2898
3088
|
"@types/estree": "^0.0.50",
|
|
2899
3089
|
"@types/express": "^4.17.21",
|
|
2900
3090
|
"@types/fs-extra": "^9.0.13",
|
|
2901
|
-
"@types/jest": "^26.0.24",
|
|
2902
3091
|
"@types/js-yaml": "^3.12.10",
|
|
2903
3092
|
"@types/lodash.camelcase": "^4.3.9",
|
|
2904
3093
|
"@types/lodash.upperfirst": "^4.3.9",
|
|
2905
3094
|
"@types/lru-cache": "^5.1.1",
|
|
2906
3095
|
"@types/mdast": "^3.0.15",
|
|
2907
3096
|
"@types/micromatch": "^4.0.9",
|
|
2908
|
-
"@types/node": "^22.
|
|
3097
|
+
"@types/node": "^22.13.1",
|
|
2909
3098
|
"@types/normalize-path": "^3.0.2",
|
|
2910
3099
|
"@types/ws": "^7.4.7",
|
|
2911
3100
|
"@types/yup": "^0.29.14",
|
|
2912
|
-
jest: "^29.7.0",
|
|
2913
|
-
"jest-diff": "^29.7.0",
|
|
2914
3101
|
"jest-file-snapshot": "^0.5.0",
|
|
2915
|
-
"jest-matcher-utils": "^29.7.0",
|
|
2916
3102
|
"memory-level": "^1.0.0",
|
|
2917
3103
|
nodemon: "3.1.4",
|
|
2918
|
-
typescript: "^5.
|
|
3104
|
+
typescript: "^5.7.3",
|
|
3105
|
+
vite: "^4.5.9",
|
|
3106
|
+
vitest: "^0.32.4",
|
|
3107
|
+
zod: "^3.24.2"
|
|
2919
3108
|
}
|
|
2920
3109
|
};
|
|
2921
3110
|
|
|
@@ -2986,6 +3175,7 @@ var _buildFragments = async (builder, tinaSchema) => {
|
|
|
2986
3175
|
const fragDoc = {
|
|
2987
3176
|
kind: "Document",
|
|
2988
3177
|
definitions: uniqBy2(
|
|
3178
|
+
// @ts-ignore
|
|
2989
3179
|
extractInlineTypes(fragmentDefinitionsFields),
|
|
2990
3180
|
(node) => node.name.value
|
|
2991
3181
|
)
|
|
@@ -3008,6 +3198,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3008
3198
|
fragName,
|
|
3009
3199
|
queryName: queryListName,
|
|
3010
3200
|
filterType: queryFilterTypeName,
|
|
3201
|
+
// look for flag to see if the data layer is enabled
|
|
3011
3202
|
dataLayer: Boolean(
|
|
3012
3203
|
tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
|
|
3013
3204
|
)
|
|
@@ -3017,6 +3208,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3017
3208
|
const queryDoc = {
|
|
3018
3209
|
kind: "Document",
|
|
3019
3210
|
definitions: uniqBy2(
|
|
3211
|
+
// @ts-ignore
|
|
3020
3212
|
extractInlineTypes(operationsDefinitions),
|
|
3021
3213
|
(node) => node.name.value
|
|
3022
3214
|
)
|
|
@@ -3105,6 +3297,7 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3105
3297
|
return {
|
|
3106
3298
|
kind: "Document",
|
|
3107
3299
|
definitions: uniqBy2(
|
|
3300
|
+
// @ts-ignore
|
|
3108
3301
|
extractInlineTypes(definitions),
|
|
3109
3302
|
(node) => node.name.value
|
|
3110
3303
|
)
|
|
@@ -3309,8 +3502,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
|
|
|
3309
3502
|
}
|
|
3310
3503
|
if (Array.isArray(value)) {
|
|
3311
3504
|
return value.map((v) => {
|
|
3312
|
-
if (!v || typeof v !== "string")
|
|
3313
|
-
return v;
|
|
3505
|
+
if (!v || typeof v !== "string") return v;
|
|
3314
3506
|
const cleanMediaRoot = cleanUpSlashes(
|
|
3315
3507
|
schema.config.media.tina.mediaRoot
|
|
3316
3508
|
);
|
|
@@ -3338,8 +3530,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
|
|
|
3338
3530
|
}
|
|
3339
3531
|
if (Array.isArray(value)) {
|
|
3340
3532
|
return value.map((v) => {
|
|
3341
|
-
if (!v || typeof v !== "string")
|
|
3342
|
-
return v;
|
|
3533
|
+
if (!v || typeof v !== "string") return v;
|
|
3343
3534
|
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3344
3535
|
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3345
3536
|
});
|
|
@@ -3357,8 +3548,7 @@ var cleanUpSlashes = (path7) => {
|
|
|
3357
3548
|
return "";
|
|
3358
3549
|
};
|
|
3359
3550
|
var hasTinaMediaConfig = (schema) => {
|
|
3360
|
-
if (!schema.config?.media?.tina)
|
|
3361
|
-
return false;
|
|
3551
|
+
if (!schema.config?.media?.tina) return false;
|
|
3362
3552
|
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
3363
3553
|
return false;
|
|
3364
3554
|
return true;
|
|
@@ -3402,6 +3592,7 @@ var LevelProxyHandler = {
|
|
|
3402
3592
|
} else if (property === "sublevel") {
|
|
3403
3593
|
return (...args) => {
|
|
3404
3594
|
return new Proxy(
|
|
3595
|
+
// eslint-disable-next-line prefer-spread
|
|
3405
3596
|
target[property].apply(target, args),
|
|
3406
3597
|
LevelProxyHandler
|
|
3407
3598
|
);
|
|
@@ -4278,6 +4469,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
|
|
|
4278
4469
|
result.push({
|
|
4279
4470
|
type: opType,
|
|
4280
4471
|
key: `${collection.path}/${subFolderKey}.${collection.format}`,
|
|
4472
|
+
// replace the root with the collection path
|
|
4281
4473
|
sublevel: indexSublevel,
|
|
4282
4474
|
value: {}
|
|
4283
4475
|
});
|
|
@@ -4392,6 +4584,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4392
4584
|
case "password":
|
|
4393
4585
|
accumulator[field.name] = {
|
|
4394
4586
|
value: void 0,
|
|
4587
|
+
// never resolve the password hash
|
|
4395
4588
|
passwordChangeRequired: value["passwordChangeRequired"] ?? false
|
|
4396
4589
|
};
|
|
4397
4590
|
break;
|
|
@@ -4586,6 +4779,7 @@ var Resolver = class {
|
|
|
4586
4779
|
const collection = this.tinaSchema.getCollection(collectionName);
|
|
4587
4780
|
const extraFields = {};
|
|
4588
4781
|
return {
|
|
4782
|
+
// return the collection and hasDocuments to resolve documents at a lower level
|
|
4589
4783
|
documents: { collection, hasDocuments },
|
|
4590
4784
|
...collection,
|
|
4591
4785
|
...extraFields
|
|
@@ -4672,7 +4866,9 @@ var Resolver = class {
|
|
|
4672
4866
|
);
|
|
4673
4867
|
} else {
|
|
4674
4868
|
return this.buildFieldMutations(
|
|
4869
|
+
// @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
|
|
4675
4870
|
fieldValue,
|
|
4871
|
+
//@ts-ignore
|
|
4676
4872
|
objectTemplate,
|
|
4677
4873
|
existingData
|
|
4678
4874
|
);
|
|
@@ -4684,6 +4880,7 @@ var Resolver = class {
|
|
|
4684
4880
|
fieldValue.map(async (item) => {
|
|
4685
4881
|
if (typeof item === "string") {
|
|
4686
4882
|
throw new Error(
|
|
4883
|
+
//@ts-ignore
|
|
4687
4884
|
`Expected object for template value for field ${field.name}`
|
|
4688
4885
|
);
|
|
4689
4886
|
}
|
|
@@ -4692,16 +4889,19 @@ var Resolver = class {
|
|
|
4692
4889
|
});
|
|
4693
4890
|
const [templateName] = Object.entries(item)[0];
|
|
4694
4891
|
const template = templates.find(
|
|
4892
|
+
//@ts-ignore
|
|
4695
4893
|
(template2) => template2.name === templateName
|
|
4696
4894
|
);
|
|
4697
4895
|
if (!template) {
|
|
4698
4896
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4699
4897
|
}
|
|
4700
4898
|
return {
|
|
4899
|
+
// @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
4900
|
...await this.buildFieldMutations(
|
|
4702
4901
|
item[template.name],
|
|
4703
4902
|
template
|
|
4704
4903
|
),
|
|
4904
|
+
//@ts-ignore
|
|
4705
4905
|
_template: template.name
|
|
4706
4906
|
};
|
|
4707
4907
|
})
|
|
@@ -4709,6 +4909,7 @@ var Resolver = class {
|
|
|
4709
4909
|
} else {
|
|
4710
4910
|
if (typeof fieldValue === "string") {
|
|
4711
4911
|
throw new Error(
|
|
4912
|
+
//@ts-ignore
|
|
4712
4913
|
`Expected object for template value for field ${field.name}`
|
|
4713
4914
|
);
|
|
4714
4915
|
}
|
|
@@ -4717,16 +4918,19 @@ var Resolver = class {
|
|
|
4717
4918
|
});
|
|
4718
4919
|
const [templateName] = Object.entries(fieldValue)[0];
|
|
4719
4920
|
const template = templates.find(
|
|
4921
|
+
//@ts-ignore
|
|
4720
4922
|
(template2) => template2.name === templateName
|
|
4721
4923
|
);
|
|
4722
4924
|
if (!template) {
|
|
4723
4925
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4724
4926
|
}
|
|
4725
4927
|
return {
|
|
4928
|
+
// @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
4929
|
...await this.buildFieldMutations(
|
|
4727
4930
|
fieldValue[template.name],
|
|
4728
4931
|
template
|
|
4729
4932
|
),
|
|
4933
|
+
//@ts-ignore
|
|
4730
4934
|
_template: template.name
|
|
4731
4935
|
};
|
|
4732
4936
|
}
|
|
@@ -4766,6 +4970,7 @@ var Resolver = class {
|
|
|
4766
4970
|
return this.getDocument(realPath);
|
|
4767
4971
|
}
|
|
4768
4972
|
const params = await this.buildObjectMutations(
|
|
4973
|
+
// @ts-ignore
|
|
4769
4974
|
args.params[collection.name],
|
|
4770
4975
|
collection
|
|
4771
4976
|
);
|
|
@@ -4811,6 +5016,7 @@ var Resolver = class {
|
|
|
4811
5016
|
const values = {
|
|
4812
5017
|
...oldDoc,
|
|
4813
5018
|
...await this.buildFieldMutations(
|
|
5019
|
+
// @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
|
|
4814
5020
|
templateParams,
|
|
4815
5021
|
template,
|
|
4816
5022
|
doc?._rawData
|
|
@@ -4824,6 +5030,7 @@ var Resolver = class {
|
|
|
4824
5030
|
return this.getDocument(realPath);
|
|
4825
5031
|
}
|
|
4826
5032
|
const params = await this.buildObjectMutations(
|
|
5033
|
+
//@ts-ignore
|
|
4827
5034
|
isCollectionSpecific ? args.params : args.params[collection.name],
|
|
4828
5035
|
collection,
|
|
4829
5036
|
doc?._rawData
|
|
@@ -4831,6 +5038,10 @@ var Resolver = class {
|
|
|
4831
5038
|
await this.database.put(realPath, { ...oldDoc, ...params }, collection.name);
|
|
4832
5039
|
return this.getDocument(realPath);
|
|
4833
5040
|
};
|
|
5041
|
+
/**
|
|
5042
|
+
* Returns top-level fields which are not defined in the collection, so their
|
|
5043
|
+
* values are not eliminated from Tina when new values are saved
|
|
5044
|
+
*/
|
|
4834
5045
|
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
4835
5046
|
const legacyValues = {};
|
|
4836
5047
|
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
@@ -4967,6 +5178,9 @@ var Resolver = class {
|
|
|
4967
5178
|
collection?.path,
|
|
4968
5179
|
args.params.relativePath
|
|
4969
5180
|
);
|
|
5181
|
+
if (newRealPath === realPath) {
|
|
5182
|
+
return doc;
|
|
5183
|
+
}
|
|
4970
5184
|
await this.database.put(newRealPath, doc._rawData, collection.name);
|
|
4971
5185
|
await this.deleteDocument(realPath);
|
|
4972
5186
|
const collRefs = await this.findReferences(realPath, collection);
|
|
@@ -5036,6 +5250,7 @@ var Resolver = class {
|
|
|
5036
5250
|
},
|
|
5037
5251
|
collection: referencedCollection,
|
|
5038
5252
|
hydrator: (path7) => path7
|
|
5253
|
+
// just return the path
|
|
5039
5254
|
}
|
|
5040
5255
|
);
|
|
5041
5256
|
const { edges } = resolvedCollectionConnection;
|
|
@@ -5103,6 +5318,12 @@ var Resolver = class {
|
|
|
5103
5318
|
}
|
|
5104
5319
|
};
|
|
5105
5320
|
};
|
|
5321
|
+
/**
|
|
5322
|
+
* Checks if a document has references to it
|
|
5323
|
+
* @param id The id of the document to check for references
|
|
5324
|
+
* @param c The collection to check for references
|
|
5325
|
+
* @returns true if the document has references, false otherwise
|
|
5326
|
+
*/
|
|
5106
5327
|
this.hasReferences = async (id, c) => {
|
|
5107
5328
|
let count = 0;
|
|
5108
5329
|
const deepRefs = this.tinaSchema.findReferences(c.name);
|
|
@@ -5137,6 +5358,12 @@ var Resolver = class {
|
|
|
5137
5358
|
}
|
|
5138
5359
|
return false;
|
|
5139
5360
|
};
|
|
5361
|
+
/**
|
|
5362
|
+
* Finds references to a document
|
|
5363
|
+
* @param id the id of the document to find references to
|
|
5364
|
+
* @param c the collection to find references in
|
|
5365
|
+
* @returns references to the document in the form of a map of collection names to a list of fields that reference the document
|
|
5366
|
+
*/
|
|
5140
5367
|
this.findReferences = async (id, c) => {
|
|
5141
5368
|
const references = {};
|
|
5142
5369
|
const deepRefs = this.tinaSchema.findReferences(c.name);
|
|
@@ -5263,6 +5490,27 @@ var Resolver = class {
|
|
|
5263
5490
|
}
|
|
5264
5491
|
return accum;
|
|
5265
5492
|
};
|
|
5493
|
+
/**
|
|
5494
|
+
* A mutation looks nearly identical between updateDocument:
|
|
5495
|
+
* ```graphql
|
|
5496
|
+
* updateDocument(collection: $collection,relativePath: $path, params: {
|
|
5497
|
+
* post: {
|
|
5498
|
+
* title: "Hello, World"
|
|
5499
|
+
* }
|
|
5500
|
+
* })`
|
|
5501
|
+
* ```
|
|
5502
|
+
* and `updatePostDocument`:
|
|
5503
|
+
* ```graphql
|
|
5504
|
+
* updatePostDocument(relativePath: $path, params: {
|
|
5505
|
+
* title: "Hello, World"
|
|
5506
|
+
* })
|
|
5507
|
+
* ```
|
|
5508
|
+
* The problem here is that we don't know whether the payload came from `updateDocument`
|
|
5509
|
+
* or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
|
|
5510
|
+
* But we do know that when given a `args.collection` value, we can assume that
|
|
5511
|
+
* this was a `updateDocument` request, and thus - should grab the data
|
|
5512
|
+
* from the corresponding field name in the key
|
|
5513
|
+
*/
|
|
5266
5514
|
this.buildParams = (args) => {
|
|
5267
5515
|
try {
|
|
5268
5516
|
assertShape(
|
|
@@ -5362,7 +5610,10 @@ var resolve = async ({
|
|
|
5362
5610
|
const graphQLSchema = buildASTSchema(graphQLSchemaAst);
|
|
5363
5611
|
const tinaConfig = await database.getTinaSchema();
|
|
5364
5612
|
const tinaSchema = await createSchema({
|
|
5613
|
+
// TODO: please update all the types to import from @tinacms/schema-tools
|
|
5614
|
+
// @ts-ignore
|
|
5365
5615
|
schema: tinaConfig,
|
|
5616
|
+
// @ts-ignore
|
|
5366
5617
|
flags: tinaConfig?.meta?.flags
|
|
5367
5618
|
});
|
|
5368
5619
|
const resolver = createResolver({
|
|
@@ -5379,8 +5630,7 @@ var resolve = async ({
|
|
|
5379
5630
|
database
|
|
5380
5631
|
},
|
|
5381
5632
|
typeResolver: async (source, _args, info) => {
|
|
5382
|
-
if (source.__typename)
|
|
5383
|
-
return source.__typename;
|
|
5633
|
+
if (source.__typename) return source.__typename;
|
|
5384
5634
|
const namedType = getNamedType(info.returnType).toString();
|
|
5385
5635
|
const lookup = await database.getLookup(namedType);
|
|
5386
5636
|
if (lookup.resolveType === "unionData") {
|
|
@@ -5529,11 +5779,13 @@ var resolve = async ({
|
|
|
5529
5779
|
set(
|
|
5530
5780
|
params,
|
|
5531
5781
|
userField.path.slice(1),
|
|
5782
|
+
// remove _rawData from users path
|
|
5532
5783
|
users.map((u) => {
|
|
5533
5784
|
if (user[idFieldName] === u[idFieldName]) {
|
|
5534
5785
|
return user;
|
|
5535
5786
|
}
|
|
5536
5787
|
return {
|
|
5788
|
+
// don't overwrite other users' passwords
|
|
5537
5789
|
...u,
|
|
5538
5790
|
[passwordFieldName]: {
|
|
5539
5791
|
...u[passwordFieldName],
|
|
@@ -5556,6 +5808,9 @@ var resolve = async ({
|
|
|
5556
5808
|
}
|
|
5557
5809
|
const isCreation = lookup[info.fieldName] === "create";
|
|
5558
5810
|
switch (lookup.resolveType) {
|
|
5811
|
+
/**
|
|
5812
|
+
* `node(id: $id)`
|
|
5813
|
+
*/
|
|
5559
5814
|
case "nodeDocument":
|
|
5560
5815
|
assertShape(
|
|
5561
5816
|
args,
|
|
@@ -5587,6 +5842,7 @@ var resolve = async ({
|
|
|
5587
5842
|
collection: args.collection,
|
|
5588
5843
|
isMutation,
|
|
5589
5844
|
isCreation,
|
|
5845
|
+
// Right now this is the only case for deletion
|
|
5590
5846
|
isDeletion: info.fieldName === "deleteDocument",
|
|
5591
5847
|
isFolderCreation: info.fieldName === "createFolder",
|
|
5592
5848
|
isUpdateName: Boolean(args?.params?.relativePath),
|
|
@@ -5596,6 +5852,9 @@ var resolve = async ({
|
|
|
5596
5852
|
return result;
|
|
5597
5853
|
}
|
|
5598
5854
|
return value;
|
|
5855
|
+
/**
|
|
5856
|
+
* eg `getMovieDocument.data.actors`
|
|
5857
|
+
*/
|
|
5599
5858
|
case "multiCollectionDocumentList":
|
|
5600
5859
|
if (Array.isArray(value)) {
|
|
5601
5860
|
return {
|
|
@@ -5607,7 +5866,15 @@ var resolve = async ({
|
|
|
5607
5866
|
}
|
|
5608
5867
|
if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
|
|
5609
5868
|
let filter = args.filter;
|
|
5610
|
-
if (
|
|
5869
|
+
if (
|
|
5870
|
+
// 1. Make sure that the filter exists
|
|
5871
|
+
typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
|
|
5872
|
+
// @ts-ignore
|
|
5873
|
+
typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
|
|
5874
|
+
// @ts-ignore
|
|
5875
|
+
Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
|
|
5876
|
+
typeof args.filter[value?.collection?.name] !== "undefined"
|
|
5877
|
+
) {
|
|
5611
5878
|
filter = args.filter[value.collection.name];
|
|
5612
5879
|
}
|
|
5613
5880
|
return resolver.resolveCollectionConnection({
|
|
@@ -5615,12 +5882,20 @@ var resolve = async ({
|
|
|
5615
5882
|
...args,
|
|
5616
5883
|
filter
|
|
5617
5884
|
},
|
|
5885
|
+
// @ts-ignore
|
|
5618
5886
|
collection: value.collection
|
|
5619
5887
|
});
|
|
5620
5888
|
}
|
|
5621
5889
|
throw new Error(
|
|
5622
5890
|
`Expected an array for result of ${info.fieldName} at ${info.path}`
|
|
5623
5891
|
);
|
|
5892
|
+
/**
|
|
5893
|
+
* Collections-specific getter
|
|
5894
|
+
* eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
|
|
5895
|
+
*
|
|
5896
|
+
* if coming from a query result
|
|
5897
|
+
* the field will be `node`
|
|
5898
|
+
*/
|
|
5624
5899
|
case "collectionDocument": {
|
|
5625
5900
|
if (value) {
|
|
5626
5901
|
return value;
|
|
@@ -5635,11 +5910,32 @@ var resolve = async ({
|
|
|
5635
5910
|
});
|
|
5636
5911
|
return result;
|
|
5637
5912
|
}
|
|
5913
|
+
/**
|
|
5914
|
+
* Collections-specific list getter
|
|
5915
|
+
* eg. `getPageList`
|
|
5916
|
+
*/
|
|
5638
5917
|
case "collectionDocumentList":
|
|
5639
5918
|
return resolver.resolveCollectionConnection({
|
|
5640
5919
|
args,
|
|
5641
5920
|
collection: tinaSchema.getCollection(lookup.collection)
|
|
5642
5921
|
});
|
|
5922
|
+
/**
|
|
5923
|
+
* A polymorphic data set, it can be from a document's data
|
|
5924
|
+
* of any nested object which can be one of many shapes
|
|
5925
|
+
*
|
|
5926
|
+
* ```graphql
|
|
5927
|
+
* getPostDocument(relativePath: $relativePath) {
|
|
5928
|
+
* data {...} <- this part
|
|
5929
|
+
* }
|
|
5930
|
+
* ```
|
|
5931
|
+
* ```graphql
|
|
5932
|
+
* getBlockDocument(relativePath: $relativePath) {
|
|
5933
|
+
* data {
|
|
5934
|
+
* blocks {...} <- or this part
|
|
5935
|
+
* }
|
|
5936
|
+
* }
|
|
5937
|
+
* ```
|
|
5938
|
+
*/
|
|
5643
5939
|
case "unionData":
|
|
5644
5940
|
if (!value) {
|
|
5645
5941
|
if (args.relativePath) {
|
|
@@ -5704,8 +6000,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5704
6000
|
this.port = port || 9e3;
|
|
5705
6001
|
}
|
|
5706
6002
|
openConnection() {
|
|
5707
|
-
if (this._connected)
|
|
5708
|
-
return;
|
|
6003
|
+
if (this._connected) return;
|
|
5709
6004
|
const socket = connect(this.port);
|
|
5710
6005
|
pipeline(socket, this.createRpcStream(), socket, () => {
|
|
5711
6006
|
this._connected = false;
|
|
@@ -5715,7 +6010,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5715
6010
|
};
|
|
5716
6011
|
|
|
5717
6012
|
// src/database/index.ts
|
|
5718
|
-
import path4 from "path";
|
|
6013
|
+
import path4 from "node:path";
|
|
5719
6014
|
import { GraphQLError as GraphQLError5 } from "graphql";
|
|
5720
6015
|
import micromatch2 from "micromatch";
|
|
5721
6016
|
import sha2 from "js-sha1";
|
|
@@ -5886,6 +6181,7 @@ var Database = class {
|
|
|
5886
6181
|
"put",
|
|
5887
6182
|
level
|
|
5888
6183
|
),
|
|
6184
|
+
// folder indices
|
|
5889
6185
|
...makeIndexOpsForDocument(
|
|
5890
6186
|
normalizedPath,
|
|
5891
6187
|
`${collection?.name}_${folderKey}`,
|
|
@@ -5908,6 +6204,7 @@ var Database = class {
|
|
|
5908
6204
|
"del",
|
|
5909
6205
|
level
|
|
5910
6206
|
),
|
|
6207
|
+
// folder indices
|
|
5911
6208
|
...makeIndexOpsForDocument(
|
|
5912
6209
|
normalizedPath,
|
|
5913
6210
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6001,6 +6298,7 @@ var Database = class {
|
|
|
6001
6298
|
"put",
|
|
6002
6299
|
level
|
|
6003
6300
|
),
|
|
6301
|
+
// folder indices
|
|
6004
6302
|
...makeIndexOpsForDocument(
|
|
6005
6303
|
normalizedPath,
|
|
6006
6304
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6023,6 +6321,7 @@ var Database = class {
|
|
|
6023
6321
|
"del",
|
|
6024
6322
|
level
|
|
6025
6323
|
),
|
|
6324
|
+
// folder indices
|
|
6026
6325
|
...makeIndexOpsForDocument(
|
|
6027
6326
|
normalizedPath,
|
|
6028
6327
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6100,6 +6399,7 @@ var Database = class {
|
|
|
6100
6399
|
aliasedData,
|
|
6101
6400
|
extension,
|
|
6102
6401
|
writeTemplateKey,
|
|
6402
|
+
//templateInfo.type === 'union',
|
|
6103
6403
|
{
|
|
6104
6404
|
frontmatterFormat: collection?.frontmatterFormat,
|
|
6105
6405
|
frontmatterDelimiters: collection?.frontmatterDelimiters
|
|
@@ -6138,6 +6438,7 @@ var Database = class {
|
|
|
6138
6438
|
SUBLEVEL_OPTIONS
|
|
6139
6439
|
).get(graphqlPath);
|
|
6140
6440
|
};
|
|
6441
|
+
//TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
|
|
6141
6442
|
this.getGraphQLSchemaFromBridge = async () => {
|
|
6142
6443
|
if (!this.bridge) {
|
|
6143
6444
|
throw new Error(`No bridge configured`);
|
|
@@ -6184,6 +6485,7 @@ var Database = class {
|
|
|
6184
6485
|
for (const collection of collections) {
|
|
6185
6486
|
const indexDefinitions = {
|
|
6186
6487
|
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
|
|
6488
|
+
// provide a default sort key which is the file sort
|
|
6187
6489
|
};
|
|
6188
6490
|
if (collection.fields) {
|
|
6189
6491
|
for (const field of collection.fields) {
|
|
@@ -6507,12 +6809,12 @@ var Database = class {
|
|
|
6507
6809
|
if (collection?.isDetached) {
|
|
6508
6810
|
level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
|
|
6509
6811
|
}
|
|
6510
|
-
const
|
|
6812
|
+
const normalizedPath = normalizePath(filepath);
|
|
6511
6813
|
const rootSublevel = level.sublevel(
|
|
6512
6814
|
CONTENT_ROOT_PREFIX,
|
|
6513
6815
|
SUBLEVEL_OPTIONS
|
|
6514
6816
|
);
|
|
6515
|
-
const item = await rootSublevel.get(
|
|
6817
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
6516
6818
|
if (item) {
|
|
6517
6819
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
6518
6820
|
const folderKey = folderTreeBuilder.update(
|
|
@@ -6521,15 +6823,16 @@ var Database = class {
|
|
|
6521
6823
|
);
|
|
6522
6824
|
await this.contentLevel.batch([
|
|
6523
6825
|
...makeIndexOpsForDocument(
|
|
6524
|
-
|
|
6826
|
+
normalizedPath,
|
|
6525
6827
|
collection.name,
|
|
6526
6828
|
collectionIndexDefinitions,
|
|
6527
6829
|
item,
|
|
6528
6830
|
"del",
|
|
6529
6831
|
level
|
|
6530
6832
|
),
|
|
6833
|
+
// folder indices
|
|
6531
6834
|
...makeIndexOpsForDocument(
|
|
6532
|
-
|
|
6835
|
+
normalizedPath,
|
|
6533
6836
|
`${collection.name}_${folderKey}`,
|
|
6534
6837
|
collectionIndexDefinitions,
|
|
6535
6838
|
item,
|
|
@@ -6538,17 +6841,17 @@ var Database = class {
|
|
|
6538
6841
|
),
|
|
6539
6842
|
{
|
|
6540
6843
|
type: "del",
|
|
6541
|
-
key:
|
|
6844
|
+
key: normalizedPath,
|
|
6542
6845
|
sublevel: rootSublevel
|
|
6543
6846
|
}
|
|
6544
6847
|
]);
|
|
6545
6848
|
}
|
|
6546
6849
|
if (!collection?.isDetached) {
|
|
6547
6850
|
if (this.bridge) {
|
|
6548
|
-
await this.bridge.delete(
|
|
6851
|
+
await this.bridge.delete(normalizedPath);
|
|
6549
6852
|
}
|
|
6550
6853
|
try {
|
|
6551
|
-
await this.onDelete(
|
|
6854
|
+
await this.onDelete(normalizedPath);
|
|
6552
6855
|
} catch (e) {
|
|
6553
6856
|
throw new GraphQLError5(
|
|
6554
6857
|
`Error running onDelete hook for ${filepath}: ${e}`,
|
|
@@ -6682,6 +6985,9 @@ var Database = class {
|
|
|
6682
6985
|
info: templateInfo
|
|
6683
6986
|
};
|
|
6684
6987
|
}
|
|
6988
|
+
/**
|
|
6989
|
+
* Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
|
|
6990
|
+
*/
|
|
6685
6991
|
clearCache() {
|
|
6686
6992
|
this.tinaSchema = null;
|
|
6687
6993
|
this._lookup = null;
|
|
@@ -6764,10 +7070,41 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6764
7070
|
await hashPasswordValues(aliasedData, passwordFields);
|
|
6765
7071
|
}
|
|
6766
7072
|
const normalizedPath = normalizePath(filepath);
|
|
7073
|
+
const rootSublevel = level.sublevel(
|
|
7074
|
+
CONTENT_ROOT_PREFIX,
|
|
7075
|
+
SUBLEVEL_OPTIONS
|
|
7076
|
+
);
|
|
6767
7077
|
const folderKey = folderTreeBuilder.update(
|
|
6768
7078
|
normalizedPath,
|
|
6769
7079
|
collectionPath || ""
|
|
6770
7080
|
);
|
|
7081
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
7082
|
+
if (item) {
|
|
7083
|
+
await database.contentLevel.batch([
|
|
7084
|
+
...makeIndexOpsForDocument(
|
|
7085
|
+
normalizedPath,
|
|
7086
|
+
collection.name,
|
|
7087
|
+
collectionIndexDefinitions,
|
|
7088
|
+
item,
|
|
7089
|
+
"del",
|
|
7090
|
+
level
|
|
7091
|
+
),
|
|
7092
|
+
// folder indices
|
|
7093
|
+
...makeIndexOpsForDocument(
|
|
7094
|
+
normalizedPath,
|
|
7095
|
+
`${collection.name}_${folderKey}`,
|
|
7096
|
+
collectionIndexDefinitions,
|
|
7097
|
+
item,
|
|
7098
|
+
"del",
|
|
7099
|
+
level
|
|
7100
|
+
),
|
|
7101
|
+
{
|
|
7102
|
+
type: "del",
|
|
7103
|
+
key: normalizedPath,
|
|
7104
|
+
sublevel: rootSublevel
|
|
7105
|
+
}
|
|
7106
|
+
]);
|
|
7107
|
+
}
|
|
6771
7108
|
if (!isGitKeep(filepath, collection)) {
|
|
6772
7109
|
await enqueueOps([
|
|
6773
7110
|
...makeIndexOpsForDocument(
|
|
@@ -6778,6 +7115,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6778
7115
|
"put",
|
|
6779
7116
|
level
|
|
6780
7117
|
),
|
|
7118
|
+
// folder indexes
|
|
6781
7119
|
...makeIndexOpsForDocument(
|
|
6782
7120
|
normalizedPath,
|
|
6783
7121
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6863,6 +7201,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6863
7201
|
"del",
|
|
6864
7202
|
database.contentLevel
|
|
6865
7203
|
),
|
|
7204
|
+
// folder indexes
|
|
6866
7205
|
...makeIndexOpsForDocument(
|
|
6867
7206
|
itemKey,
|
|
6868
7207
|
`${collection?.name}_${folderKey}`,
|
|
@@ -7078,17 +7417,26 @@ var IsomorphicBridge = class {
|
|
|
7078
7417
|
getAuthor() {
|
|
7079
7418
|
return {
|
|
7080
7419
|
...this.author,
|
|
7081
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7420
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
7082
7421
|
timezoneOffset: 0
|
|
7083
7422
|
};
|
|
7084
7423
|
}
|
|
7085
7424
|
getCommitter() {
|
|
7086
7425
|
return {
|
|
7087
7426
|
...this.committer,
|
|
7088
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7427
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
7089
7428
|
timezoneOffset: 0
|
|
7090
7429
|
};
|
|
7091
7430
|
}
|
|
7431
|
+
/**
|
|
7432
|
+
* Recursively populate paths matching `pattern` for the given `entry`
|
|
7433
|
+
*
|
|
7434
|
+
* @param pattern - pattern to filter paths by
|
|
7435
|
+
* @param entry - TreeEntry to start building list from
|
|
7436
|
+
* @param path - base path
|
|
7437
|
+
* @param results
|
|
7438
|
+
* @private
|
|
7439
|
+
*/
|
|
7092
7440
|
async listEntries({
|
|
7093
7441
|
pattern,
|
|
7094
7442
|
entry,
|
|
@@ -7121,6 +7469,15 @@ var IsomorphicBridge = class {
|
|
|
7121
7469
|
});
|
|
7122
7470
|
}
|
|
7123
7471
|
}
|
|
7472
|
+
/**
|
|
7473
|
+
* For the specified path, returns an object with an array containing the parts of the path (pathParts)
|
|
7474
|
+
* and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
|
|
7475
|
+
* pathEntries are placeholders for non-existent entries.
|
|
7476
|
+
*
|
|
7477
|
+
* @param path - path being resolved
|
|
7478
|
+
* @param ref - ref to resolve path entries for
|
|
7479
|
+
* @private
|
|
7480
|
+
*/
|
|
7124
7481
|
async resolvePathEntries(path7, ref) {
|
|
7125
7482
|
let pathParts = path7.split("/");
|
|
7126
7483
|
const result = await git2.walk({
|
|
@@ -7151,6 +7508,17 @@ var IsomorphicBridge = class {
|
|
|
7151
7508
|
}
|
|
7152
7509
|
return { pathParts, pathEntries };
|
|
7153
7510
|
}
|
|
7511
|
+
/**
|
|
7512
|
+
* Updates tree entry and associated parent tree entries
|
|
7513
|
+
*
|
|
7514
|
+
* @param existingOid - the existing OID
|
|
7515
|
+
* @param updatedOid - the updated OID
|
|
7516
|
+
* @param path - the path of the entry being updated
|
|
7517
|
+
* @param type - the type of the entry being updated (blob or tree)
|
|
7518
|
+
* @param pathEntries - parent path entries
|
|
7519
|
+
* @param pathParts - parent path parts
|
|
7520
|
+
* @private
|
|
7521
|
+
*/
|
|
7154
7522
|
async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
|
|
7155
7523
|
const lastIdx = pathEntries.length - 1;
|
|
7156
7524
|
const parentEntry = pathEntries[lastIdx];
|
|
@@ -7206,6 +7574,13 @@ var IsomorphicBridge = class {
|
|
|
7206
7574
|
);
|
|
7207
7575
|
}
|
|
7208
7576
|
}
|
|
7577
|
+
/**
|
|
7578
|
+
* Creates a commit for the specified tree and updates the specified ref to point to the commit
|
|
7579
|
+
*
|
|
7580
|
+
* @param treeSha - sha of the new tree
|
|
7581
|
+
* @param ref - the ref that should be updated
|
|
7582
|
+
* @private
|
|
7583
|
+
*/
|
|
7209
7584
|
async commitTree(treeSha, ref) {
|
|
7210
7585
|
const commitSha = await git2.writeCommit({
|
|
7211
7586
|
...this.isomorphicConfig,
|
|
@@ -7218,6 +7593,7 @@ var IsomorphicBridge = class {
|
|
|
7218
7593
|
})
|
|
7219
7594
|
],
|
|
7220
7595
|
message: this.commitMessage,
|
|
7596
|
+
// TODO these should be configurable
|
|
7221
7597
|
author: this.getAuthor(),
|
|
7222
7598
|
committer: this.getCommitter()
|
|
7223
7599
|
}
|
|
@@ -7455,5 +7831,5 @@ export {
|
|
|
7455
7831
|
transformDocument,
|
|
7456
7832
|
transformDocumentIntoPayload
|
|
7457
7833
|
};
|
|
7458
|
-
//! Replaces _.flattenDeep()
|
|
7459
7834
|
//! Replaces _.get()
|
|
7835
|
+
//! Replaces _.flattenDeep()
|