@tinacms/graphql 0.0.0-fbcd928-20241024223724 → 0.0.0-fd664d8-20250407054012
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/builder/index.d.ts +2 -2
- package/dist/database/datalayer.d.ts +5 -1
- package/dist/database/index.d.ts +2 -0
- package/dist/index.js +853 -224
- package/dist/index.mjs +815 -194
- package/dist/resolver/index.d.ts +12 -1
- package/dist/resolver/media-utils.d.ts +3 -3
- package/package.json +17 -18
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 TinaCloud 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.15",
|
|
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,22 +3055,22 @@ 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
|
-
"jsonpath-plus": "
|
|
3066
|
+
"jsonpath-plus": "10.1.0",
|
|
2877
3067
|
"lodash.clonedeep": "^4.5.0",
|
|
2878
3068
|
"lodash.set": "^4.3.2",
|
|
2879
3069
|
"lodash.uniqby": "^4.7.0",
|
|
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
|
)
|
|
@@ -3068,7 +3260,9 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3068
3260
|
await builder.buildCreateCollectionFolderMutation()
|
|
3069
3261
|
);
|
|
3070
3262
|
await sequential(collections, async (collection) => {
|
|
3071
|
-
queryTypeDefinitionFields.push(
|
|
3263
|
+
queryTypeDefinitionFields.push(
|
|
3264
|
+
await builder.collectionDocument(collection)
|
|
3265
|
+
);
|
|
3072
3266
|
if (collection.isAuthCollection) {
|
|
3073
3267
|
queryTypeDefinitionFields.push(
|
|
3074
3268
|
await builder.authenticationCollectionDocument(collection)
|
|
@@ -3105,6 +3299,7 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3105
3299
|
return {
|
|
3106
3300
|
kind: "Document",
|
|
3107
3301
|
definitions: uniqBy2(
|
|
3302
|
+
// @ts-ignore
|
|
3108
3303
|
extractInlineTypes(definitions),
|
|
3109
3304
|
(node) => node.name.value
|
|
3110
3305
|
)
|
|
@@ -3309,8 +3504,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
|
|
|
3309
3504
|
}
|
|
3310
3505
|
if (Array.isArray(value)) {
|
|
3311
3506
|
return value.map((v) => {
|
|
3312
|
-
if (!v || typeof v !== "string")
|
|
3313
|
-
return v;
|
|
3507
|
+
if (!v || typeof v !== "string") return v;
|
|
3314
3508
|
const cleanMediaRoot = cleanUpSlashes(
|
|
3315
3509
|
schema.config.media.tina.mediaRoot
|
|
3316
3510
|
);
|
|
@@ -3338,8 +3532,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
|
|
|
3338
3532
|
}
|
|
3339
3533
|
if (Array.isArray(value)) {
|
|
3340
3534
|
return value.map((v) => {
|
|
3341
|
-
if (!v || typeof v !== "string")
|
|
3342
|
-
return v;
|
|
3535
|
+
if (!v || typeof v !== "string") return v;
|
|
3343
3536
|
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3344
3537
|
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3345
3538
|
});
|
|
@@ -3357,8 +3550,7 @@ var cleanUpSlashes = (path7) => {
|
|
|
3357
3550
|
return "";
|
|
3358
3551
|
};
|
|
3359
3552
|
var hasTinaMediaConfig = (schema) => {
|
|
3360
|
-
if (!schema.config?.media?.tina)
|
|
3361
|
-
return false;
|
|
3553
|
+
if (!schema.config?.media?.tina) return false;
|
|
3362
3554
|
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
3363
3555
|
return false;
|
|
3364
3556
|
return true;
|
|
@@ -3385,7 +3577,9 @@ var LevelProxyHandler = {
|
|
|
3385
3577
|
throw new Error(`The property, ${property.toString()}, doesn't exist`);
|
|
3386
3578
|
}
|
|
3387
3579
|
if (typeof target[property] !== "function") {
|
|
3388
|
-
throw new Error(
|
|
3580
|
+
throw new Error(
|
|
3581
|
+
`The property, ${property.toString()}, is not a function`
|
|
3582
|
+
);
|
|
3389
3583
|
}
|
|
3390
3584
|
if (property === "get") {
|
|
3391
3585
|
return async (...args) => {
|
|
@@ -3402,6 +3596,7 @@ var LevelProxyHandler = {
|
|
|
3402
3596
|
} else if (property === "sublevel") {
|
|
3403
3597
|
return (...args) => {
|
|
3404
3598
|
return new Proxy(
|
|
3599
|
+
// eslint-disable-next-line prefer-spread
|
|
3405
3600
|
target[property].apply(target, args),
|
|
3406
3601
|
LevelProxyHandler
|
|
3407
3602
|
);
|
|
@@ -3769,6 +3964,9 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
|
|
|
3769
3964
|
|
|
3770
3965
|
// src/database/datalayer.ts
|
|
3771
3966
|
var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
|
|
3967
|
+
var REFS_COLLECTIONS_SORT_KEY = "__refs__";
|
|
3968
|
+
var REFS_REFERENCE_FIELD = "__tina_ref__";
|
|
3969
|
+
var REFS_PATH_FIELD = "__tina_ref_path__";
|
|
3772
3970
|
var DEFAULT_NUMERIC_LPAD = 4;
|
|
3773
3971
|
var applyPadding = (input, pad) => {
|
|
3774
3972
|
if (pad) {
|
|
@@ -4278,6 +4476,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
|
|
|
4278
4476
|
result.push({
|
|
4279
4477
|
type: opType,
|
|
4280
4478
|
key: `${collection.path}/${subFolderKey}.${collection.format}`,
|
|
4479
|
+
// replace the root with the collection path
|
|
4281
4480
|
sublevel: indexSublevel,
|
|
4282
4481
|
value: {}
|
|
4283
4482
|
});
|
|
@@ -4341,6 +4540,57 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
|
|
|
4341
4540
|
}
|
|
4342
4541
|
return result;
|
|
4343
4542
|
};
|
|
4543
|
+
var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
|
|
4544
|
+
const result = [];
|
|
4545
|
+
if (collection) {
|
|
4546
|
+
for (const [c, referencePaths] of Object.entries(references || {})) {
|
|
4547
|
+
if (!referencePaths.length) {
|
|
4548
|
+
continue;
|
|
4549
|
+
}
|
|
4550
|
+
const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
|
|
4551
|
+
const refSublevel = collectionSublevel.sublevel(
|
|
4552
|
+
REFS_COLLECTIONS_SORT_KEY,
|
|
4553
|
+
SUBLEVEL_OPTIONS
|
|
4554
|
+
);
|
|
4555
|
+
const references2 = {};
|
|
4556
|
+
for (const path7 of referencePaths) {
|
|
4557
|
+
const ref = JSONPath({ path: path7, json: data });
|
|
4558
|
+
if (!ref) {
|
|
4559
|
+
continue;
|
|
4560
|
+
}
|
|
4561
|
+
if (Array.isArray(ref)) {
|
|
4562
|
+
for (const r of ref) {
|
|
4563
|
+
if (!r) {
|
|
4564
|
+
continue;
|
|
4565
|
+
}
|
|
4566
|
+
if (references2[r]) {
|
|
4567
|
+
references2[r].push(path7);
|
|
4568
|
+
} else {
|
|
4569
|
+
references2[r] = [path7];
|
|
4570
|
+
}
|
|
4571
|
+
}
|
|
4572
|
+
} else {
|
|
4573
|
+
if (references2[ref]) {
|
|
4574
|
+
references2[ref].push(path7);
|
|
4575
|
+
} else {
|
|
4576
|
+
references2[ref] = [path7];
|
|
4577
|
+
}
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4580
|
+
for (const ref of Object.keys(references2)) {
|
|
4581
|
+
for (const path7 of references2[ref]) {
|
|
4582
|
+
result.push({
|
|
4583
|
+
type: opType,
|
|
4584
|
+
key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
|
|
4585
|
+
sublevel: refSublevel,
|
|
4586
|
+
value: opType === "put" ? {} : void 0
|
|
4587
|
+
});
|
|
4588
|
+
}
|
|
4589
|
+
}
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
return result;
|
|
4593
|
+
};
|
|
4344
4594
|
var makeStringEscaper = (regex, replacement) => {
|
|
4345
4595
|
return (input) => {
|
|
4346
4596
|
if (Array.isArray(input)) {
|
|
@@ -4392,6 +4642,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4392
4642
|
case "password":
|
|
4393
4643
|
accumulator[field.name] = {
|
|
4394
4644
|
value: void 0,
|
|
4645
|
+
// never resolve the password hash
|
|
4395
4646
|
passwordChangeRequired: value["passwordChangeRequired"] ?? false
|
|
4396
4647
|
};
|
|
4397
4648
|
break;
|
|
@@ -4560,24 +4811,33 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4560
4811
|
throw e;
|
|
4561
4812
|
}
|
|
4562
4813
|
};
|
|
4563
|
-
var updateObjectWithJsonPath = (obj, path7, newValue) => {
|
|
4814
|
+
var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
|
|
4815
|
+
let updated = false;
|
|
4564
4816
|
if (!path7.includes(".") && !path7.includes("[")) {
|
|
4565
|
-
if (path7 in obj) {
|
|
4817
|
+
if (path7 in obj && obj[path7] === oldValue) {
|
|
4566
4818
|
obj[path7] = newValue;
|
|
4819
|
+
updated = true;
|
|
4567
4820
|
}
|
|
4568
|
-
return obj;
|
|
4569
|
-
}
|
|
4570
|
-
const parentPath = path7.replace(/\.[
|
|
4571
|
-
const keyToUpdate = path7.match(/[
|
|
4572
|
-
const parents = JSONPath2({
|
|
4821
|
+
return { object: obj, updated };
|
|
4822
|
+
}
|
|
4823
|
+
const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
|
|
4824
|
+
const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
|
|
4825
|
+
const parents = JSONPath2({
|
|
4826
|
+
path: parentPath,
|
|
4827
|
+
json: obj,
|
|
4828
|
+
resultType: "value"
|
|
4829
|
+
});
|
|
4573
4830
|
if (parents.length > 0) {
|
|
4574
4831
|
parents.forEach((parent) => {
|
|
4575
4832
|
if (parent && typeof parent === "object" && keyToUpdate in parent) {
|
|
4576
|
-
parent[keyToUpdate]
|
|
4833
|
+
if (parent[keyToUpdate] === oldValue) {
|
|
4834
|
+
parent[keyToUpdate] = newValue;
|
|
4835
|
+
updated = true;
|
|
4836
|
+
}
|
|
4577
4837
|
}
|
|
4578
4838
|
});
|
|
4579
4839
|
}
|
|
4580
|
-
return obj;
|
|
4840
|
+
return { object: obj, updated };
|
|
4581
4841
|
};
|
|
4582
4842
|
var Resolver = class {
|
|
4583
4843
|
constructor(init) {
|
|
@@ -4586,6 +4846,7 @@ var Resolver = class {
|
|
|
4586
4846
|
const collection = this.tinaSchema.getCollection(collectionName);
|
|
4587
4847
|
const extraFields = {};
|
|
4588
4848
|
return {
|
|
4849
|
+
// return the collection and hasDocuments to resolve documents at a lower level
|
|
4589
4850
|
documents: { collection, hasDocuments },
|
|
4590
4851
|
...collection,
|
|
4591
4852
|
...extraFields
|
|
@@ -4593,7 +4854,9 @@ var Resolver = class {
|
|
|
4593
4854
|
};
|
|
4594
4855
|
this.getRaw = async (fullPath) => {
|
|
4595
4856
|
if (typeof fullPath !== "string") {
|
|
4596
|
-
throw new Error(
|
|
4857
|
+
throw new Error(
|
|
4858
|
+
`fullPath must be of type string for getDocument request`
|
|
4859
|
+
);
|
|
4597
4860
|
}
|
|
4598
4861
|
return this.database.get(fullPath);
|
|
4599
4862
|
};
|
|
@@ -4622,7 +4885,9 @@ var Resolver = class {
|
|
|
4622
4885
|
};
|
|
4623
4886
|
this.getDocument = async (fullPath, opts = {}) => {
|
|
4624
4887
|
if (typeof fullPath !== "string") {
|
|
4625
|
-
throw new Error(
|
|
4888
|
+
throw new Error(
|
|
4889
|
+
`fullPath must be of type string for getDocument request`
|
|
4890
|
+
);
|
|
4626
4891
|
}
|
|
4627
4892
|
const rawData = await this.getRaw(fullPath);
|
|
4628
4893
|
const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
|
|
@@ -4637,7 +4902,9 @@ var Resolver = class {
|
|
|
4637
4902
|
};
|
|
4638
4903
|
this.deleteDocument = async (fullPath) => {
|
|
4639
4904
|
if (typeof fullPath !== "string") {
|
|
4640
|
-
throw new Error(
|
|
4905
|
+
throw new Error(
|
|
4906
|
+
`fullPath must be of type string for getDocument request`
|
|
4907
|
+
);
|
|
4641
4908
|
}
|
|
4642
4909
|
await this.database.delete(fullPath);
|
|
4643
4910
|
};
|
|
@@ -4672,7 +4939,9 @@ var Resolver = class {
|
|
|
4672
4939
|
);
|
|
4673
4940
|
} else {
|
|
4674
4941
|
return this.buildFieldMutations(
|
|
4942
|
+
// @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
|
|
4675
4943
|
fieldValue,
|
|
4944
|
+
//@ts-ignore
|
|
4676
4945
|
objectTemplate,
|
|
4677
4946
|
existingData
|
|
4678
4947
|
);
|
|
@@ -4684,6 +4953,7 @@ var Resolver = class {
|
|
|
4684
4953
|
fieldValue.map(async (item) => {
|
|
4685
4954
|
if (typeof item === "string") {
|
|
4686
4955
|
throw new Error(
|
|
4956
|
+
//@ts-ignore
|
|
4687
4957
|
`Expected object for template value for field ${field.name}`
|
|
4688
4958
|
);
|
|
4689
4959
|
}
|
|
@@ -4692,16 +4962,19 @@ var Resolver = class {
|
|
|
4692
4962
|
});
|
|
4693
4963
|
const [templateName] = Object.entries(item)[0];
|
|
4694
4964
|
const template = templates.find(
|
|
4965
|
+
//@ts-ignore
|
|
4695
4966
|
(template2) => template2.name === templateName
|
|
4696
4967
|
);
|
|
4697
4968
|
if (!template) {
|
|
4698
4969
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4699
4970
|
}
|
|
4700
4971
|
return {
|
|
4972
|
+
// @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
4973
|
...await this.buildFieldMutations(
|
|
4702
4974
|
item[template.name],
|
|
4703
4975
|
template
|
|
4704
4976
|
),
|
|
4977
|
+
//@ts-ignore
|
|
4705
4978
|
_template: template.name
|
|
4706
4979
|
};
|
|
4707
4980
|
})
|
|
@@ -4709,6 +4982,7 @@ var Resolver = class {
|
|
|
4709
4982
|
} else {
|
|
4710
4983
|
if (typeof fieldValue === "string") {
|
|
4711
4984
|
throw new Error(
|
|
4985
|
+
//@ts-ignore
|
|
4712
4986
|
`Expected object for template value for field ${field.name}`
|
|
4713
4987
|
);
|
|
4714
4988
|
}
|
|
@@ -4717,16 +4991,19 @@ var Resolver = class {
|
|
|
4717
4991
|
});
|
|
4718
4992
|
const [templateName] = Object.entries(fieldValue)[0];
|
|
4719
4993
|
const template = templates.find(
|
|
4994
|
+
//@ts-ignore
|
|
4720
4995
|
(template2) => template2.name === templateName
|
|
4721
4996
|
);
|
|
4722
4997
|
if (!template) {
|
|
4723
4998
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4724
4999
|
}
|
|
4725
5000
|
return {
|
|
5001
|
+
// @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
5002
|
...await this.buildFieldMutations(
|
|
4727
5003
|
fieldValue[template.name],
|
|
4728
5004
|
template
|
|
4729
5005
|
),
|
|
5006
|
+
//@ts-ignore
|
|
4730
5007
|
_template: template.name
|
|
4731
5008
|
};
|
|
4732
5009
|
}
|
|
@@ -4766,6 +5043,7 @@ var Resolver = class {
|
|
|
4766
5043
|
return this.getDocument(realPath);
|
|
4767
5044
|
}
|
|
4768
5045
|
const params = await this.buildObjectMutations(
|
|
5046
|
+
// @ts-ignore
|
|
4769
5047
|
args.params[collection.name],
|
|
4770
5048
|
collection
|
|
4771
5049
|
);
|
|
@@ -4811,6 +5089,7 @@ var Resolver = class {
|
|
|
4811
5089
|
const values = {
|
|
4812
5090
|
...oldDoc,
|
|
4813
5091
|
...await this.buildFieldMutations(
|
|
5092
|
+
// @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
|
|
4814
5093
|
templateParams,
|
|
4815
5094
|
template,
|
|
4816
5095
|
doc?._rawData
|
|
@@ -4824,13 +5103,22 @@ var Resolver = class {
|
|
|
4824
5103
|
return this.getDocument(realPath);
|
|
4825
5104
|
}
|
|
4826
5105
|
const params = await this.buildObjectMutations(
|
|
5106
|
+
//@ts-ignore
|
|
4827
5107
|
isCollectionSpecific ? args.params : args.params[collection.name],
|
|
4828
5108
|
collection,
|
|
4829
5109
|
doc?._rawData
|
|
4830
5110
|
);
|
|
4831
|
-
await this.database.put(
|
|
5111
|
+
await this.database.put(
|
|
5112
|
+
realPath,
|
|
5113
|
+
{ ...oldDoc, ...params },
|
|
5114
|
+
collection.name
|
|
5115
|
+
);
|
|
4832
5116
|
return this.getDocument(realPath);
|
|
4833
5117
|
};
|
|
5118
|
+
/**
|
|
5119
|
+
* Returns top-level fields which are not defined in the collection, so their
|
|
5120
|
+
* values are not eliminated from Tina when new values are saved
|
|
5121
|
+
*/
|
|
4834
5122
|
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
4835
5123
|
const legacyValues = {};
|
|
4836
5124
|
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
@@ -4937,17 +5225,35 @@ var Resolver = class {
|
|
|
4937
5225
|
await this.deleteDocument(realPath);
|
|
4938
5226
|
if (await this.hasReferences(realPath, collection)) {
|
|
4939
5227
|
const collRefs = await this.findReferences(realPath, collection);
|
|
4940
|
-
for (const [collection2,
|
|
4941
|
-
for (const [
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
5228
|
+
for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
|
|
5229
|
+
for (const [pathToDocWithRef, referencePaths] of Object.entries(
|
|
5230
|
+
docsWithRefs
|
|
5231
|
+
)) {
|
|
5232
|
+
let refDoc = await this.getRaw(pathToDocWithRef);
|
|
5233
|
+
let hasUpdate = false;
|
|
5234
|
+
for (const path7 of referencePaths) {
|
|
5235
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
4945
5236
|
refDoc,
|
|
4946
|
-
|
|
5237
|
+
path7,
|
|
5238
|
+
realPath,
|
|
4947
5239
|
null
|
|
4948
5240
|
);
|
|
5241
|
+
refDoc = object2;
|
|
5242
|
+
hasUpdate = updated || hasUpdate;
|
|
5243
|
+
}
|
|
5244
|
+
if (hasUpdate) {
|
|
5245
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5246
|
+
if (!collectionWithRef) {
|
|
5247
|
+
throw new Error(
|
|
5248
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5249
|
+
);
|
|
5250
|
+
}
|
|
5251
|
+
await this.database.put(
|
|
5252
|
+
pathToDocWithRef,
|
|
5253
|
+
refDoc,
|
|
5254
|
+
collectionWithRef.name
|
|
5255
|
+
);
|
|
4949
5256
|
}
|
|
4950
|
-
await this.database.put(refPath, refDoc, collection2);
|
|
4951
5257
|
}
|
|
4952
5258
|
}
|
|
4953
5259
|
}
|
|
@@ -4967,26 +5273,49 @@ var Resolver = class {
|
|
|
4967
5273
|
collection?.path,
|
|
4968
5274
|
args.params.relativePath
|
|
4969
5275
|
);
|
|
5276
|
+
if (newRealPath === realPath) {
|
|
5277
|
+
return doc;
|
|
5278
|
+
}
|
|
4970
5279
|
await this.database.put(newRealPath, doc._rawData, collection.name);
|
|
4971
5280
|
await this.deleteDocument(realPath);
|
|
4972
5281
|
const collRefs = await this.findReferences(realPath, collection);
|
|
4973
|
-
for (const [collection2,
|
|
4974
|
-
for (const [
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
5282
|
+
for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
|
|
5283
|
+
for (const [pathToDocWithRef, referencePaths] of Object.entries(
|
|
5284
|
+
docsWithRefs
|
|
5285
|
+
)) {
|
|
5286
|
+
let docWithRef = await this.getRaw(pathToDocWithRef);
|
|
5287
|
+
let hasUpdate = false;
|
|
5288
|
+
for (const path7 of referencePaths) {
|
|
5289
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5290
|
+
docWithRef,
|
|
5291
|
+
path7,
|
|
5292
|
+
realPath,
|
|
4980
5293
|
newRealPath
|
|
4981
5294
|
);
|
|
5295
|
+
docWithRef = object2;
|
|
5296
|
+
hasUpdate = updated || hasUpdate;
|
|
5297
|
+
}
|
|
5298
|
+
if (hasUpdate) {
|
|
5299
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5300
|
+
if (!collectionWithRef) {
|
|
5301
|
+
throw new Error(
|
|
5302
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5303
|
+
);
|
|
5304
|
+
}
|
|
5305
|
+
await this.database.put(
|
|
5306
|
+
pathToDocWithRef,
|
|
5307
|
+
docWithRef,
|
|
5308
|
+
collectionWithRef.name
|
|
5309
|
+
);
|
|
4982
5310
|
}
|
|
4983
|
-
await this.database.put(refPath, refDoc, collection2);
|
|
4984
5311
|
}
|
|
4985
5312
|
}
|
|
4986
5313
|
return this.getDocument(newRealPath);
|
|
4987
5314
|
}
|
|
4988
5315
|
if (alreadyExists === false) {
|
|
4989
|
-
throw new Error(
|
|
5316
|
+
throw new Error(
|
|
5317
|
+
`Unable to update document, ${realPath} does not exist`
|
|
5318
|
+
);
|
|
4990
5319
|
}
|
|
4991
5320
|
return this.updateResolveDocument({
|
|
4992
5321
|
collection,
|
|
@@ -5036,6 +5365,7 @@ var Resolver = class {
|
|
|
5036
5365
|
},
|
|
5037
5366
|
collection: referencedCollection,
|
|
5038
5367
|
hydrator: (path7) => path7
|
|
5368
|
+
// just return the path
|
|
5039
5369
|
}
|
|
5040
5370
|
);
|
|
5041
5371
|
const { edges } = resolvedCollectionConnection;
|
|
@@ -5103,78 +5433,80 @@ var Resolver = class {
|
|
|
5103
5433
|
}
|
|
5104
5434
|
};
|
|
5105
5435
|
};
|
|
5436
|
+
/**
|
|
5437
|
+
* Checks if a document has references to it
|
|
5438
|
+
* @param id The id of the document to check for references
|
|
5439
|
+
* @param c The collection to check for references
|
|
5440
|
+
* @returns true if the document has references, false otherwise
|
|
5441
|
+
*/
|
|
5106
5442
|
this.hasReferences = async (id, c) => {
|
|
5107
5443
|
let count = 0;
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
(refId) => {
|
|
5129
|
-
count++;
|
|
5130
|
-
return refId;
|
|
5131
|
-
}
|
|
5132
|
-
);
|
|
5133
|
-
if (count) {
|
|
5134
|
-
return true;
|
|
5135
|
-
}
|
|
5444
|
+
await this.database.query(
|
|
5445
|
+
{
|
|
5446
|
+
collection: c.name,
|
|
5447
|
+
filterChain: makeFilterChain({
|
|
5448
|
+
conditions: [
|
|
5449
|
+
{
|
|
5450
|
+
filterPath: REFS_REFERENCE_FIELD,
|
|
5451
|
+
filterExpression: {
|
|
5452
|
+
_type: "string",
|
|
5453
|
+
_list: false,
|
|
5454
|
+
eq: id
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5457
|
+
]
|
|
5458
|
+
}),
|
|
5459
|
+
sort: REFS_COLLECTIONS_SORT_KEY
|
|
5460
|
+
},
|
|
5461
|
+
(refId) => {
|
|
5462
|
+
count++;
|
|
5463
|
+
return refId;
|
|
5136
5464
|
}
|
|
5465
|
+
);
|
|
5466
|
+
if (count) {
|
|
5467
|
+
return true;
|
|
5137
5468
|
}
|
|
5138
5469
|
return false;
|
|
5139
5470
|
};
|
|
5471
|
+
/**
|
|
5472
|
+
* Finds references to a document
|
|
5473
|
+
* @param id the id of the document to find references to
|
|
5474
|
+
* @param c the collection to find references in
|
|
5475
|
+
* @returns a map of references to the document
|
|
5476
|
+
*/
|
|
5140
5477
|
this.findReferences = async (id, c) => {
|
|
5141
5478
|
const references = {};
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
_list: false,
|
|
5155
|
-
eq: id
|
|
5156
|
-
}
|
|
5157
|
-
}
|
|
5158
|
-
]
|
|
5159
|
-
}),
|
|
5160
|
-
sort: ref.field.name
|
|
5161
|
-
},
|
|
5162
|
-
(refId) => {
|
|
5163
|
-
if (!references[collection]) {
|
|
5164
|
-
references[collection] = {};
|
|
5165
|
-
}
|
|
5166
|
-
if (!references[collection][refId]) {
|
|
5167
|
-
references[collection][refId] = [];
|
|
5479
|
+
await this.database.query(
|
|
5480
|
+
{
|
|
5481
|
+
collection: c.name,
|
|
5482
|
+
filterChain: makeFilterChain({
|
|
5483
|
+
conditions: [
|
|
5484
|
+
{
|
|
5485
|
+
filterPath: REFS_REFERENCE_FIELD,
|
|
5486
|
+
filterExpression: {
|
|
5487
|
+
_type: "string",
|
|
5488
|
+
_list: false,
|
|
5489
|
+
eq: id
|
|
5490
|
+
}
|
|
5168
5491
|
}
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5492
|
+
]
|
|
5493
|
+
}),
|
|
5494
|
+
sort: REFS_COLLECTIONS_SORT_KEY
|
|
5495
|
+
},
|
|
5496
|
+
(refId, rawItem) => {
|
|
5497
|
+
if (!references[c.name]) {
|
|
5498
|
+
references[c.name] = {};
|
|
5499
|
+
}
|
|
5500
|
+
if (!references[c.name][refId]) {
|
|
5501
|
+
references[c.name][refId] = [];
|
|
5502
|
+
}
|
|
5503
|
+
const referencePath = rawItem?.[REFS_PATH_FIELD];
|
|
5504
|
+
if (referencePath) {
|
|
5505
|
+
references[c.name][refId].push(referencePath);
|
|
5506
|
+
}
|
|
5507
|
+
return refId;
|
|
5176
5508
|
}
|
|
5177
|
-
|
|
5509
|
+
);
|
|
5178
5510
|
return references;
|
|
5179
5511
|
};
|
|
5180
5512
|
this.buildFieldMutations = async (fieldParams, template, existingData) => {
|
|
@@ -5263,6 +5595,27 @@ var Resolver = class {
|
|
|
5263
5595
|
}
|
|
5264
5596
|
return accum;
|
|
5265
5597
|
};
|
|
5598
|
+
/**
|
|
5599
|
+
* A mutation looks nearly identical between updateDocument:
|
|
5600
|
+
* ```graphql
|
|
5601
|
+
* updateDocument(collection: $collection,relativePath: $path, params: {
|
|
5602
|
+
* post: {
|
|
5603
|
+
* title: "Hello, World"
|
|
5604
|
+
* }
|
|
5605
|
+
* })`
|
|
5606
|
+
* ```
|
|
5607
|
+
* and `updatePostDocument`:
|
|
5608
|
+
* ```graphql
|
|
5609
|
+
* updatePostDocument(relativePath: $path, params: {
|
|
5610
|
+
* title: "Hello, World"
|
|
5611
|
+
* })
|
|
5612
|
+
* ```
|
|
5613
|
+
* The problem here is that we don't know whether the payload came from `updateDocument`
|
|
5614
|
+
* or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
|
|
5615
|
+
* But we do know that when given a `args.collection` value, we can assume that
|
|
5616
|
+
* this was a `updateDocument` request, and thus - should grab the data
|
|
5617
|
+
* from the corresponding field name in the key
|
|
5618
|
+
*/
|
|
5266
5619
|
this.buildParams = (args) => {
|
|
5267
5620
|
try {
|
|
5268
5621
|
assertShape(
|
|
@@ -5362,7 +5715,10 @@ var resolve = async ({
|
|
|
5362
5715
|
const graphQLSchema = buildASTSchema(graphQLSchemaAst);
|
|
5363
5716
|
const tinaConfig = await database.getTinaSchema();
|
|
5364
5717
|
const tinaSchema = await createSchema({
|
|
5718
|
+
// TODO: please update all the types to import from @tinacms/schema-tools
|
|
5719
|
+
// @ts-ignore
|
|
5365
5720
|
schema: tinaConfig,
|
|
5721
|
+
// @ts-ignore
|
|
5366
5722
|
flags: tinaConfig?.meta?.flags
|
|
5367
5723
|
});
|
|
5368
5724
|
const resolver = createResolver({
|
|
@@ -5379,8 +5735,7 @@ var resolve = async ({
|
|
|
5379
5735
|
database
|
|
5380
5736
|
},
|
|
5381
5737
|
typeResolver: async (source, _args, info) => {
|
|
5382
|
-
if (source.__typename)
|
|
5383
|
-
return source.__typename;
|
|
5738
|
+
if (source.__typename) return source.__typename;
|
|
5384
5739
|
const namedType = getNamedType(info.returnType).toString();
|
|
5385
5740
|
const lookup = await database.getLookup(namedType);
|
|
5386
5741
|
if (lookup.resolveType === "unionData") {
|
|
@@ -5529,11 +5884,13 @@ var resolve = async ({
|
|
|
5529
5884
|
set(
|
|
5530
5885
|
params,
|
|
5531
5886
|
userField.path.slice(1),
|
|
5887
|
+
// remove _rawData from users path
|
|
5532
5888
|
users.map((u) => {
|
|
5533
5889
|
if (user[idFieldName] === u[idFieldName]) {
|
|
5534
5890
|
return user;
|
|
5535
5891
|
}
|
|
5536
5892
|
return {
|
|
5893
|
+
// don't overwrite other users' passwords
|
|
5537
5894
|
...u,
|
|
5538
5895
|
[passwordFieldName]: {
|
|
5539
5896
|
...u[passwordFieldName],
|
|
@@ -5556,6 +5913,9 @@ var resolve = async ({
|
|
|
5556
5913
|
}
|
|
5557
5914
|
const isCreation = lookup[info.fieldName] === "create";
|
|
5558
5915
|
switch (lookup.resolveType) {
|
|
5916
|
+
/**
|
|
5917
|
+
* `node(id: $id)`
|
|
5918
|
+
*/
|
|
5559
5919
|
case "nodeDocument":
|
|
5560
5920
|
assertShape(
|
|
5561
5921
|
args,
|
|
@@ -5587,6 +5947,7 @@ var resolve = async ({
|
|
|
5587
5947
|
collection: args.collection,
|
|
5588
5948
|
isMutation,
|
|
5589
5949
|
isCreation,
|
|
5950
|
+
// Right now this is the only case for deletion
|
|
5590
5951
|
isDeletion: info.fieldName === "deleteDocument",
|
|
5591
5952
|
isFolderCreation: info.fieldName === "createFolder",
|
|
5592
5953
|
isUpdateName: Boolean(args?.params?.relativePath),
|
|
@@ -5596,6 +5957,9 @@ var resolve = async ({
|
|
|
5596
5957
|
return result;
|
|
5597
5958
|
}
|
|
5598
5959
|
return value;
|
|
5960
|
+
/**
|
|
5961
|
+
* eg `getMovieDocument.data.actors`
|
|
5962
|
+
*/
|
|
5599
5963
|
case "multiCollectionDocumentList":
|
|
5600
5964
|
if (Array.isArray(value)) {
|
|
5601
5965
|
return {
|
|
@@ -5607,7 +5971,15 @@ var resolve = async ({
|
|
|
5607
5971
|
}
|
|
5608
5972
|
if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
|
|
5609
5973
|
let filter = args.filter;
|
|
5610
|
-
if (
|
|
5974
|
+
if (
|
|
5975
|
+
// 1. Make sure that the filter exists
|
|
5976
|
+
typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
|
|
5977
|
+
// @ts-ignore
|
|
5978
|
+
typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
|
|
5979
|
+
// @ts-ignore
|
|
5980
|
+
Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
|
|
5981
|
+
typeof args.filter[value?.collection?.name] !== "undefined"
|
|
5982
|
+
) {
|
|
5611
5983
|
filter = args.filter[value.collection.name];
|
|
5612
5984
|
}
|
|
5613
5985
|
return resolver.resolveCollectionConnection({
|
|
@@ -5615,12 +5987,20 @@ var resolve = async ({
|
|
|
5615
5987
|
...args,
|
|
5616
5988
|
filter
|
|
5617
5989
|
},
|
|
5990
|
+
// @ts-ignore
|
|
5618
5991
|
collection: value.collection
|
|
5619
5992
|
});
|
|
5620
5993
|
}
|
|
5621
5994
|
throw new Error(
|
|
5622
5995
|
`Expected an array for result of ${info.fieldName} at ${info.path}`
|
|
5623
5996
|
);
|
|
5997
|
+
/**
|
|
5998
|
+
* Collections-specific getter
|
|
5999
|
+
* eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
|
|
6000
|
+
*
|
|
6001
|
+
* if coming from a query result
|
|
6002
|
+
* the field will be `node`
|
|
6003
|
+
*/
|
|
5624
6004
|
case "collectionDocument": {
|
|
5625
6005
|
if (value) {
|
|
5626
6006
|
return value;
|
|
@@ -5635,11 +6015,32 @@ var resolve = async ({
|
|
|
5635
6015
|
});
|
|
5636
6016
|
return result;
|
|
5637
6017
|
}
|
|
6018
|
+
/**
|
|
6019
|
+
* Collections-specific list getter
|
|
6020
|
+
* eg. `getPageList`
|
|
6021
|
+
*/
|
|
5638
6022
|
case "collectionDocumentList":
|
|
5639
6023
|
return resolver.resolveCollectionConnection({
|
|
5640
6024
|
args,
|
|
5641
6025
|
collection: tinaSchema.getCollection(lookup.collection)
|
|
5642
6026
|
});
|
|
6027
|
+
/**
|
|
6028
|
+
* A polymorphic data set, it can be from a document's data
|
|
6029
|
+
* of any nested object which can be one of many shapes
|
|
6030
|
+
*
|
|
6031
|
+
* ```graphql
|
|
6032
|
+
* getPostDocument(relativePath: $relativePath) {
|
|
6033
|
+
* data {...} <- this part
|
|
6034
|
+
* }
|
|
6035
|
+
* ```
|
|
6036
|
+
* ```graphql
|
|
6037
|
+
* getBlockDocument(relativePath: $relativePath) {
|
|
6038
|
+
* data {
|
|
6039
|
+
* blocks {...} <- or this part
|
|
6040
|
+
* }
|
|
6041
|
+
* }
|
|
6042
|
+
* ```
|
|
6043
|
+
*/
|
|
5643
6044
|
case "unionData":
|
|
5644
6045
|
if (!value) {
|
|
5645
6046
|
if (args.relativePath) {
|
|
@@ -5704,8 +6105,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5704
6105
|
this.port = port || 9e3;
|
|
5705
6106
|
}
|
|
5706
6107
|
openConnection() {
|
|
5707
|
-
if (this._connected)
|
|
5708
|
-
return;
|
|
6108
|
+
if (this._connected) return;
|
|
5709
6109
|
const socket = connect(this.port);
|
|
5710
6110
|
pipeline(socket, this.createRpcStream(), socket, () => {
|
|
5711
6111
|
this._connected = false;
|
|
@@ -5715,7 +6115,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5715
6115
|
};
|
|
5716
6116
|
|
|
5717
6117
|
// src/database/index.ts
|
|
5718
|
-
import path4 from "path";
|
|
6118
|
+
import path4 from "node:path";
|
|
5719
6119
|
import { GraphQLError as GraphQLError5 } from "graphql";
|
|
5720
6120
|
import micromatch2 from "micromatch";
|
|
5721
6121
|
import sha2 from "js-sha1";
|
|
@@ -5850,6 +6250,7 @@ var Database = class {
|
|
|
5850
6250
|
);
|
|
5851
6251
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
5852
6252
|
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6253
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
5853
6254
|
const normalizedPath = normalizePath(filepath);
|
|
5854
6255
|
if (!collection?.isDetached) {
|
|
5855
6256
|
if (this.bridge) {
|
|
@@ -5878,6 +6279,14 @@ var Database = class {
|
|
|
5878
6279
|
let delOps = [];
|
|
5879
6280
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
5880
6281
|
putOps = [
|
|
6282
|
+
...makeRefOpsForDocument(
|
|
6283
|
+
normalizedPath,
|
|
6284
|
+
collection?.name,
|
|
6285
|
+
collectionReferences,
|
|
6286
|
+
dataFields,
|
|
6287
|
+
"put",
|
|
6288
|
+
level
|
|
6289
|
+
),
|
|
5881
6290
|
...makeIndexOpsForDocument(
|
|
5882
6291
|
normalizedPath,
|
|
5883
6292
|
collection?.name,
|
|
@@ -5886,6 +6295,7 @@ var Database = class {
|
|
|
5886
6295
|
"put",
|
|
5887
6296
|
level
|
|
5888
6297
|
),
|
|
6298
|
+
// folder indices
|
|
5889
6299
|
...makeIndexOpsForDocument(
|
|
5890
6300
|
normalizedPath,
|
|
5891
6301
|
`${collection?.name}_${folderKey}`,
|
|
@@ -5900,6 +6310,14 @@ var Database = class {
|
|
|
5900
6310
|
SUBLEVEL_OPTIONS
|
|
5901
6311
|
).get(normalizedPath);
|
|
5902
6312
|
delOps = existingItem ? [
|
|
6313
|
+
...makeRefOpsForDocument(
|
|
6314
|
+
normalizedPath,
|
|
6315
|
+
collection?.name,
|
|
6316
|
+
collectionReferences,
|
|
6317
|
+
existingItem,
|
|
6318
|
+
"del",
|
|
6319
|
+
level
|
|
6320
|
+
),
|
|
5903
6321
|
...makeIndexOpsForDocument(
|
|
5904
6322
|
normalizedPath,
|
|
5905
6323
|
collection?.name,
|
|
@@ -5908,6 +6326,7 @@ var Database = class {
|
|
|
5908
6326
|
"del",
|
|
5909
6327
|
level
|
|
5910
6328
|
),
|
|
6329
|
+
// folder indices
|
|
5911
6330
|
...makeIndexOpsForDocument(
|
|
5912
6331
|
normalizedPath,
|
|
5913
6332
|
`${collection?.name}_${folderKey}`,
|
|
@@ -5946,6 +6365,7 @@ var Database = class {
|
|
|
5946
6365
|
);
|
|
5947
6366
|
collectionIndexDefinitions = indexDefinitions?.[collectionName];
|
|
5948
6367
|
}
|
|
6368
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
|
|
5949
6369
|
const normalizedPath = normalizePath(filepath);
|
|
5950
6370
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5951
6371
|
const collection = await this.collectionForPath(filepath);
|
|
@@ -5993,6 +6413,14 @@ var Database = class {
|
|
|
5993
6413
|
let delOps = [];
|
|
5994
6414
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
5995
6415
|
putOps = [
|
|
6416
|
+
...makeRefOpsForDocument(
|
|
6417
|
+
normalizedPath,
|
|
6418
|
+
collectionName,
|
|
6419
|
+
collectionReferences,
|
|
6420
|
+
dataFields,
|
|
6421
|
+
"put",
|
|
6422
|
+
level
|
|
6423
|
+
),
|
|
5996
6424
|
...makeIndexOpsForDocument(
|
|
5997
6425
|
normalizedPath,
|
|
5998
6426
|
collectionName,
|
|
@@ -6001,6 +6429,7 @@ var Database = class {
|
|
|
6001
6429
|
"put",
|
|
6002
6430
|
level
|
|
6003
6431
|
),
|
|
6432
|
+
// folder indices
|
|
6004
6433
|
...makeIndexOpsForDocument(
|
|
6005
6434
|
normalizedPath,
|
|
6006
6435
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6015,6 +6444,14 @@ var Database = class {
|
|
|
6015
6444
|
SUBLEVEL_OPTIONS
|
|
6016
6445
|
).get(normalizedPath);
|
|
6017
6446
|
delOps = existingItem ? [
|
|
6447
|
+
...makeRefOpsForDocument(
|
|
6448
|
+
normalizedPath,
|
|
6449
|
+
collectionName,
|
|
6450
|
+
collectionReferences,
|
|
6451
|
+
existingItem,
|
|
6452
|
+
"del",
|
|
6453
|
+
level
|
|
6454
|
+
),
|
|
6018
6455
|
...makeIndexOpsForDocument(
|
|
6019
6456
|
normalizedPath,
|
|
6020
6457
|
collectionName,
|
|
@@ -6023,6 +6460,7 @@ var Database = class {
|
|
|
6023
6460
|
"del",
|
|
6024
6461
|
level
|
|
6025
6462
|
),
|
|
6463
|
+
// folder indices
|
|
6026
6464
|
...makeIndexOpsForDocument(
|
|
6027
6465
|
normalizedPath,
|
|
6028
6466
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6100,6 +6538,7 @@ var Database = class {
|
|
|
6100
6538
|
aliasedData,
|
|
6101
6539
|
extension,
|
|
6102
6540
|
writeTemplateKey,
|
|
6541
|
+
//templateInfo.type === 'union',
|
|
6103
6542
|
{
|
|
6104
6543
|
frontmatterFormat: collection?.frontmatterFormat,
|
|
6105
6544
|
frontmatterDelimiters: collection?.frontmatterDelimiters
|
|
@@ -6138,6 +6577,7 @@ var Database = class {
|
|
|
6138
6577
|
SUBLEVEL_OPTIONS
|
|
6139
6578
|
).get(graphqlPath);
|
|
6140
6579
|
};
|
|
6580
|
+
//TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
|
|
6141
6581
|
this.getGraphQLSchemaFromBridge = async () => {
|
|
6142
6582
|
if (!this.bridge) {
|
|
6143
6583
|
throw new Error(`No bridge configured`);
|
|
@@ -6174,6 +6614,22 @@ var Database = class {
|
|
|
6174
6614
|
this.tinaSchema = await createSchema({ schema });
|
|
6175
6615
|
return this.tinaSchema;
|
|
6176
6616
|
};
|
|
6617
|
+
this.getCollectionReferences = async (level) => {
|
|
6618
|
+
if (this.collectionReferences) {
|
|
6619
|
+
return this.collectionReferences;
|
|
6620
|
+
}
|
|
6621
|
+
const result = {};
|
|
6622
|
+
const schema = await this.getSchema(level || this.contentLevel);
|
|
6623
|
+
const collections = schema.getCollections();
|
|
6624
|
+
for (const collection of collections) {
|
|
6625
|
+
const collectionReferences = this.tinaSchema.findReferencesFromCollection(
|
|
6626
|
+
collection.name
|
|
6627
|
+
);
|
|
6628
|
+
result[collection.name] = collectionReferences;
|
|
6629
|
+
}
|
|
6630
|
+
this.collectionReferences = result;
|
|
6631
|
+
return result;
|
|
6632
|
+
};
|
|
6177
6633
|
this.getIndexDefinitions = async (level) => {
|
|
6178
6634
|
if (!this.collectionIndexDefinitions) {
|
|
6179
6635
|
await new Promise(async (resolve2, reject) => {
|
|
@@ -6183,10 +6639,53 @@ var Database = class {
|
|
|
6183
6639
|
const collections = schema.getCollections();
|
|
6184
6640
|
for (const collection of collections) {
|
|
6185
6641
|
const indexDefinitions = {
|
|
6186
|
-
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
|
|
6642
|
+
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] },
|
|
6643
|
+
// provide a default sort key which is the file sort
|
|
6644
|
+
// pseudo-index for the collection's references
|
|
6645
|
+
[REFS_COLLECTIONS_SORT_KEY]: {
|
|
6646
|
+
fields: [
|
|
6647
|
+
{
|
|
6648
|
+
name: REFS_REFERENCE_FIELD,
|
|
6649
|
+
type: "string",
|
|
6650
|
+
list: false
|
|
6651
|
+
},
|
|
6652
|
+
{
|
|
6653
|
+
name: REFS_PATH_FIELD,
|
|
6654
|
+
type: "string",
|
|
6655
|
+
list: false
|
|
6656
|
+
}
|
|
6657
|
+
]
|
|
6658
|
+
}
|
|
6187
6659
|
};
|
|
6188
|
-
|
|
6189
|
-
|
|
6660
|
+
let fields = [];
|
|
6661
|
+
if (collection.templates) {
|
|
6662
|
+
const templateFieldMap = {};
|
|
6663
|
+
const conflictedFields = /* @__PURE__ */ new Set();
|
|
6664
|
+
for (const template of collection.templates) {
|
|
6665
|
+
for (const field of template.fields) {
|
|
6666
|
+
if (!templateFieldMap[field.name]) {
|
|
6667
|
+
templateFieldMap[field.name] = field;
|
|
6668
|
+
} else {
|
|
6669
|
+
if (templateFieldMap[field.name].type !== field.type) {
|
|
6670
|
+
console.warn(
|
|
6671
|
+
`Field ${field.name} has conflicting types in templates - skipping index`
|
|
6672
|
+
);
|
|
6673
|
+
conflictedFields.add(field.name);
|
|
6674
|
+
}
|
|
6675
|
+
}
|
|
6676
|
+
}
|
|
6677
|
+
}
|
|
6678
|
+
for (const conflictedField in conflictedFields) {
|
|
6679
|
+
delete templateFieldMap[conflictedField];
|
|
6680
|
+
}
|
|
6681
|
+
for (const field of Object.values(templateFieldMap)) {
|
|
6682
|
+
fields.push(field);
|
|
6683
|
+
}
|
|
6684
|
+
} else if (collection.fields) {
|
|
6685
|
+
fields = collection.fields;
|
|
6686
|
+
}
|
|
6687
|
+
if (fields) {
|
|
6688
|
+
for (const field of fields) {
|
|
6190
6689
|
if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
|
|
6191
6690
|
continue;
|
|
6192
6691
|
}
|
|
@@ -6334,29 +6833,36 @@ var Database = class {
|
|
|
6334
6833
|
}
|
|
6335
6834
|
startKey = startKey || key || "";
|
|
6336
6835
|
endKey = key || "";
|
|
6337
|
-
edges = [...edges, { cursor: key, path: filepath }];
|
|
6836
|
+
edges = [...edges, { cursor: key, path: filepath, value: itemRecord }];
|
|
6338
6837
|
}
|
|
6339
6838
|
return {
|
|
6340
|
-
edges: await sequential(
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
|
|
6344
|
-
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6839
|
+
edges: await sequential(
|
|
6840
|
+
edges,
|
|
6841
|
+
async ({
|
|
6842
|
+
cursor,
|
|
6843
|
+
path: path7,
|
|
6844
|
+
value
|
|
6845
|
+
}) => {
|
|
6846
|
+
try {
|
|
6847
|
+
const node = await hydrator(path7, value);
|
|
6848
|
+
return {
|
|
6849
|
+
node,
|
|
6850
|
+
cursor: btoa(cursor)
|
|
6851
|
+
};
|
|
6852
|
+
} catch (error) {
|
|
6853
|
+
console.log(error);
|
|
6854
|
+
if (error instanceof Error && (!path7.includes(".tina/__generated__/_graphql.json") || !path7.includes("tina/__generated__/_graphql.json"))) {
|
|
6855
|
+
throw new TinaQueryError({
|
|
6856
|
+
originalError: error,
|
|
6857
|
+
file: path7,
|
|
6858
|
+
collection: collection.name,
|
|
6859
|
+
stack: error.stack
|
|
6860
|
+
});
|
|
6861
|
+
}
|
|
6862
|
+
throw error;
|
|
6356
6863
|
}
|
|
6357
|
-
throw error;
|
|
6358
6864
|
}
|
|
6359
|
-
|
|
6865
|
+
),
|
|
6360
6866
|
pageInfo: {
|
|
6361
6867
|
hasPreviousPage,
|
|
6362
6868
|
hasNextPage,
|
|
@@ -6502,17 +7008,18 @@ var Database = class {
|
|
|
6502
7008
|
throw new Error(`No collection found for path: ${filepath}`);
|
|
6503
7009
|
}
|
|
6504
7010
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
7011
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
6505
7012
|
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6506
7013
|
let level = this.contentLevel;
|
|
6507
7014
|
if (collection?.isDetached) {
|
|
6508
7015
|
level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
|
|
6509
7016
|
}
|
|
6510
|
-
const
|
|
7017
|
+
const normalizedPath = normalizePath(filepath);
|
|
6511
7018
|
const rootSublevel = level.sublevel(
|
|
6512
7019
|
CONTENT_ROOT_PREFIX,
|
|
6513
7020
|
SUBLEVEL_OPTIONS
|
|
6514
7021
|
);
|
|
6515
|
-
const item = await rootSublevel.get(
|
|
7022
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
6516
7023
|
if (item) {
|
|
6517
7024
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
6518
7025
|
const folderKey = folderTreeBuilder.update(
|
|
@@ -6520,16 +7027,25 @@ var Database = class {
|
|
|
6520
7027
|
collection.path || ""
|
|
6521
7028
|
);
|
|
6522
7029
|
await this.contentLevel.batch([
|
|
7030
|
+
...makeRefOpsForDocument(
|
|
7031
|
+
normalizedPath,
|
|
7032
|
+
collection.name,
|
|
7033
|
+
collectionReferences,
|
|
7034
|
+
item,
|
|
7035
|
+
"del",
|
|
7036
|
+
level
|
|
7037
|
+
),
|
|
6523
7038
|
...makeIndexOpsForDocument(
|
|
6524
|
-
|
|
7039
|
+
normalizedPath,
|
|
6525
7040
|
collection.name,
|
|
6526
7041
|
collectionIndexDefinitions,
|
|
6527
7042
|
item,
|
|
6528
7043
|
"del",
|
|
6529
7044
|
level
|
|
6530
7045
|
),
|
|
7046
|
+
// folder indices
|
|
6531
7047
|
...makeIndexOpsForDocument(
|
|
6532
|
-
|
|
7048
|
+
normalizedPath,
|
|
6533
7049
|
`${collection.name}_${folderKey}`,
|
|
6534
7050
|
collectionIndexDefinitions,
|
|
6535
7051
|
item,
|
|
@@ -6538,17 +7054,17 @@ var Database = class {
|
|
|
6538
7054
|
),
|
|
6539
7055
|
{
|
|
6540
7056
|
type: "del",
|
|
6541
|
-
key:
|
|
7057
|
+
key: normalizedPath,
|
|
6542
7058
|
sublevel: rootSublevel
|
|
6543
7059
|
}
|
|
6544
7060
|
]);
|
|
6545
7061
|
}
|
|
6546
7062
|
if (!collection?.isDetached) {
|
|
6547
7063
|
if (this.bridge) {
|
|
6548
|
-
await this.bridge.delete(
|
|
7064
|
+
await this.bridge.delete(normalizedPath);
|
|
6549
7065
|
}
|
|
6550
7066
|
try {
|
|
6551
|
-
await this.onDelete(
|
|
7067
|
+
await this.onDelete(normalizedPath);
|
|
6552
7068
|
} catch (e) {
|
|
6553
7069
|
throw new GraphQLError5(
|
|
6554
7070
|
`Error running onDelete hook for ${filepath}: ${e}`,
|
|
@@ -6596,7 +7112,13 @@ var Database = class {
|
|
|
6596
7112
|
);
|
|
6597
7113
|
}
|
|
6598
7114
|
} else {
|
|
6599
|
-
await _indexContent(
|
|
7115
|
+
await _indexContent(
|
|
7116
|
+
this,
|
|
7117
|
+
level,
|
|
7118
|
+
contentPaths,
|
|
7119
|
+
enqueueOps,
|
|
7120
|
+
collection
|
|
7121
|
+
);
|
|
6600
7122
|
}
|
|
6601
7123
|
}
|
|
6602
7124
|
);
|
|
@@ -6682,6 +7204,9 @@ var Database = class {
|
|
|
6682
7204
|
info: templateInfo
|
|
6683
7205
|
};
|
|
6684
7206
|
}
|
|
7207
|
+
/**
|
|
7208
|
+
* Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
|
|
7209
|
+
*/
|
|
6685
7210
|
clearCache() {
|
|
6686
7211
|
this.tinaSchema = null;
|
|
6687
7212
|
this._lookup = null;
|
|
@@ -6743,6 +7268,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6743
7268
|
}
|
|
6744
7269
|
collectionPath = collection.path;
|
|
6745
7270
|
}
|
|
7271
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
6746
7272
|
const tinaSchema = await database.getSchema();
|
|
6747
7273
|
let templateInfo = null;
|
|
6748
7274
|
if (collection) {
|
|
@@ -6764,12 +7290,59 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6764
7290
|
await hashPasswordValues(aliasedData, passwordFields);
|
|
6765
7291
|
}
|
|
6766
7292
|
const normalizedPath = normalizePath(filepath);
|
|
7293
|
+
const rootSublevel = level.sublevel(
|
|
7294
|
+
CONTENT_ROOT_PREFIX,
|
|
7295
|
+
SUBLEVEL_OPTIONS
|
|
7296
|
+
);
|
|
6767
7297
|
const folderKey = folderTreeBuilder.update(
|
|
6768
7298
|
normalizedPath,
|
|
6769
7299
|
collectionPath || ""
|
|
6770
7300
|
);
|
|
7301
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
7302
|
+
if (item) {
|
|
7303
|
+
await database.contentLevel.batch([
|
|
7304
|
+
...makeRefOpsForDocument(
|
|
7305
|
+
normalizedPath,
|
|
7306
|
+
collection?.name,
|
|
7307
|
+
collectionReferences,
|
|
7308
|
+
item,
|
|
7309
|
+
"del",
|
|
7310
|
+
level
|
|
7311
|
+
),
|
|
7312
|
+
...makeIndexOpsForDocument(
|
|
7313
|
+
normalizedPath,
|
|
7314
|
+
collection.name,
|
|
7315
|
+
collectionIndexDefinitions,
|
|
7316
|
+
item,
|
|
7317
|
+
"del",
|
|
7318
|
+
level
|
|
7319
|
+
),
|
|
7320
|
+
// folder indices
|
|
7321
|
+
...makeIndexOpsForDocument(
|
|
7322
|
+
normalizedPath,
|
|
7323
|
+
`${collection.name}_${folderKey}`,
|
|
7324
|
+
collectionIndexDefinitions,
|
|
7325
|
+
item,
|
|
7326
|
+
"del",
|
|
7327
|
+
level
|
|
7328
|
+
),
|
|
7329
|
+
{
|
|
7330
|
+
type: "del",
|
|
7331
|
+
key: normalizedPath,
|
|
7332
|
+
sublevel: rootSublevel
|
|
7333
|
+
}
|
|
7334
|
+
]);
|
|
7335
|
+
}
|
|
6771
7336
|
if (!isGitKeep(filepath, collection)) {
|
|
6772
7337
|
await enqueueOps([
|
|
7338
|
+
...makeRefOpsForDocument(
|
|
7339
|
+
normalizedPath,
|
|
7340
|
+
collection?.name,
|
|
7341
|
+
collectionReferences,
|
|
7342
|
+
aliasedData,
|
|
7343
|
+
"put",
|
|
7344
|
+
level
|
|
7345
|
+
),
|
|
6773
7346
|
...makeIndexOpsForDocument(
|
|
6774
7347
|
normalizedPath,
|
|
6775
7348
|
collection?.name,
|
|
@@ -6778,6 +7351,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6778
7351
|
"put",
|
|
6779
7352
|
level
|
|
6780
7353
|
),
|
|
7354
|
+
// folder indexes
|
|
6781
7355
|
...makeIndexOpsForDocument(
|
|
6782
7356
|
normalizedPath,
|
|
6783
7357
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6832,6 +7406,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6832
7406
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
6833
7407
|
}
|
|
6834
7408
|
}
|
|
7409
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
6835
7410
|
const tinaSchema = await database.getSchema();
|
|
6836
7411
|
let templateInfo = null;
|
|
6837
7412
|
if (collection) {
|
|
@@ -6855,6 +7430,14 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6855
7430
|
item
|
|
6856
7431
|
) : item;
|
|
6857
7432
|
await enqueueOps([
|
|
7433
|
+
...makeRefOpsForDocument(
|
|
7434
|
+
itemKey,
|
|
7435
|
+
collection?.name,
|
|
7436
|
+
collectionReferences,
|
|
7437
|
+
aliasedData,
|
|
7438
|
+
"del",
|
|
7439
|
+
database.contentLevel
|
|
7440
|
+
),
|
|
6858
7441
|
...makeIndexOpsForDocument(
|
|
6859
7442
|
itemKey,
|
|
6860
7443
|
collection.name,
|
|
@@ -6863,6 +7446,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6863
7446
|
"del",
|
|
6864
7447
|
database.contentLevel
|
|
6865
7448
|
),
|
|
7449
|
+
// folder indexes
|
|
6866
7450
|
...makeIndexOpsForDocument(
|
|
6867
7451
|
itemKey,
|
|
6868
7452
|
`${collection?.name}_${folderKey}`,
|
|
@@ -7078,17 +7662,26 @@ var IsomorphicBridge = class {
|
|
|
7078
7662
|
getAuthor() {
|
|
7079
7663
|
return {
|
|
7080
7664
|
...this.author,
|
|
7081
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7665
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
7082
7666
|
timezoneOffset: 0
|
|
7083
7667
|
};
|
|
7084
7668
|
}
|
|
7085
7669
|
getCommitter() {
|
|
7086
7670
|
return {
|
|
7087
7671
|
...this.committer,
|
|
7088
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7672
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
7089
7673
|
timezoneOffset: 0
|
|
7090
7674
|
};
|
|
7091
7675
|
}
|
|
7676
|
+
/**
|
|
7677
|
+
* Recursively populate paths matching `pattern` for the given `entry`
|
|
7678
|
+
*
|
|
7679
|
+
* @param pattern - pattern to filter paths by
|
|
7680
|
+
* @param entry - TreeEntry to start building list from
|
|
7681
|
+
* @param path - base path
|
|
7682
|
+
* @param results
|
|
7683
|
+
* @private
|
|
7684
|
+
*/
|
|
7092
7685
|
async listEntries({
|
|
7093
7686
|
pattern,
|
|
7094
7687
|
entry,
|
|
@@ -7121,6 +7714,15 @@ var IsomorphicBridge = class {
|
|
|
7121
7714
|
});
|
|
7122
7715
|
}
|
|
7123
7716
|
}
|
|
7717
|
+
/**
|
|
7718
|
+
* For the specified path, returns an object with an array containing the parts of the path (pathParts)
|
|
7719
|
+
* and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
|
|
7720
|
+
* pathEntries are placeholders for non-existent entries.
|
|
7721
|
+
*
|
|
7722
|
+
* @param path - path being resolved
|
|
7723
|
+
* @param ref - ref to resolve path entries for
|
|
7724
|
+
* @private
|
|
7725
|
+
*/
|
|
7124
7726
|
async resolvePathEntries(path7, ref) {
|
|
7125
7727
|
let pathParts = path7.split("/");
|
|
7126
7728
|
const result = await git2.walk({
|
|
@@ -7151,6 +7753,17 @@ var IsomorphicBridge = class {
|
|
|
7151
7753
|
}
|
|
7152
7754
|
return { pathParts, pathEntries };
|
|
7153
7755
|
}
|
|
7756
|
+
/**
|
|
7757
|
+
* Updates tree entry and associated parent tree entries
|
|
7758
|
+
*
|
|
7759
|
+
* @param existingOid - the existing OID
|
|
7760
|
+
* @param updatedOid - the updated OID
|
|
7761
|
+
* @param path - the path of the entry being updated
|
|
7762
|
+
* @param type - the type of the entry being updated (blob or tree)
|
|
7763
|
+
* @param pathEntries - parent path entries
|
|
7764
|
+
* @param pathParts - parent path parts
|
|
7765
|
+
* @private
|
|
7766
|
+
*/
|
|
7154
7767
|
async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
|
|
7155
7768
|
const lastIdx = pathEntries.length - 1;
|
|
7156
7769
|
const parentEntry = pathEntries[lastIdx];
|
|
@@ -7206,6 +7819,13 @@ var IsomorphicBridge = class {
|
|
|
7206
7819
|
);
|
|
7207
7820
|
}
|
|
7208
7821
|
}
|
|
7822
|
+
/**
|
|
7823
|
+
* Creates a commit for the specified tree and updates the specified ref to point to the commit
|
|
7824
|
+
*
|
|
7825
|
+
* @param treeSha - sha of the new tree
|
|
7826
|
+
* @param ref - the ref that should be updated
|
|
7827
|
+
* @private
|
|
7828
|
+
*/
|
|
7209
7829
|
async commitTree(treeSha, ref) {
|
|
7210
7830
|
const commitSha = await git2.writeCommit({
|
|
7211
7831
|
...this.isomorphicConfig,
|
|
@@ -7218,6 +7838,7 @@ var IsomorphicBridge = class {
|
|
|
7218
7838
|
})
|
|
7219
7839
|
],
|
|
7220
7840
|
message: this.commitMessage,
|
|
7841
|
+
// TODO these should be configurable
|
|
7221
7842
|
author: this.getAuthor(),
|
|
7222
7843
|
committer: this.getCommitter()
|
|
7223
7844
|
}
|
|
@@ -7455,5 +8076,5 @@ export {
|
|
|
7455
8076
|
transformDocument,
|
|
7456
8077
|
transformDocumentIntoPayload
|
|
7457
8078
|
};
|
|
7458
|
-
//! Replaces _.flattenDeep()
|
|
7459
8079
|
//! Replaces _.get()
|
|
8080
|
+
//! Replaces _.flattenDeep()
|