@tinacms/graphql 0.0.0-d69e892-20241003042309 → 0.0.0-d6f7570-20250523032937
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/README.md +144 -0
- package/dist/ast-builder/index.d.ts +0 -1
- package/dist/builder/index.d.ts +2 -2
- package/dist/database/bridge/filesystem.d.ts +1 -1
- package/dist/database/datalayer.d.ts +5 -1
- package/dist/database/index.d.ts +2 -0
- package/dist/index.js +1045 -287
- package/dist/index.mjs +910 -134
- package/dist/resolver/index.d.ts +37 -2
- package/dist/resolver/media-utils.d.ts +3 -3
- package/dist/schema/createSchema.d.ts +0 -3
- package/dist/schema/validate.d.ts +0 -3
- package/package.json +17 -20
- package/readme.md +0 -194
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: {
|
|
@@ -86,6 +95,15 @@ var SysFieldDefinition = {
|
|
|
86
95
|
arguments: [],
|
|
87
96
|
directives: []
|
|
88
97
|
},
|
|
98
|
+
{
|
|
99
|
+
kind: "Field",
|
|
100
|
+
name: {
|
|
101
|
+
kind: "Name",
|
|
102
|
+
value: "hasReferences"
|
|
103
|
+
},
|
|
104
|
+
arguments: [],
|
|
105
|
+
directives: []
|
|
106
|
+
},
|
|
89
107
|
{
|
|
90
108
|
kind: "Field",
|
|
91
109
|
name: {
|
|
@@ -126,6 +144,10 @@ var SysFieldDefinition = {
|
|
|
126
144
|
}
|
|
127
145
|
};
|
|
128
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
|
+
*/
|
|
129
151
|
FormFieldBuilder: ({
|
|
130
152
|
name,
|
|
131
153
|
additionalFields
|
|
@@ -349,6 +371,8 @@ var astBuilder = {
|
|
|
349
371
|
kind: "Name",
|
|
350
372
|
value: name
|
|
351
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
|
|
352
376
|
fields
|
|
353
377
|
}),
|
|
354
378
|
UnionTypeDefinition: ({
|
|
@@ -361,6 +385,8 @@ var astBuilder = {
|
|
|
361
385
|
value: name
|
|
362
386
|
},
|
|
363
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
|
|
364
390
|
types: types.map((name2) => ({
|
|
365
391
|
kind: "NamedType",
|
|
366
392
|
name: {
|
|
@@ -457,8 +483,11 @@ var astBuilder = {
|
|
|
457
483
|
string: "String",
|
|
458
484
|
boolean: "Boolean",
|
|
459
485
|
number: "Float",
|
|
486
|
+
// FIXME - needs to be float or int
|
|
460
487
|
datetime: "String",
|
|
488
|
+
// FIXME
|
|
461
489
|
image: "String",
|
|
490
|
+
// FIXME
|
|
462
491
|
text: "String"
|
|
463
492
|
};
|
|
464
493
|
return scalars[type];
|
|
@@ -957,8 +986,7 @@ var astBuilder = {
|
|
|
957
986
|
}
|
|
958
987
|
};
|
|
959
988
|
var capitalize = (s) => {
|
|
960
|
-
if (typeof s !== "string")
|
|
961
|
-
return "";
|
|
989
|
+
if (typeof s !== "string") return "";
|
|
962
990
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
963
991
|
};
|
|
964
992
|
var extractInlineTypes = (item) => {
|
|
@@ -1001,41 +1029,6 @@ function* walk(maybeNode, visited = /* @__PURE__ */ new WeakSet()) {
|
|
|
1001
1029
|
yield maybeNode;
|
|
1002
1030
|
visited.add(maybeNode);
|
|
1003
1031
|
}
|
|
1004
|
-
function addNamespaceToSchema(maybeNode, namespace = []) {
|
|
1005
|
-
if (typeof maybeNode === "string") {
|
|
1006
|
-
return maybeNode;
|
|
1007
|
-
}
|
|
1008
|
-
if (typeof maybeNode === "boolean") {
|
|
1009
|
-
return maybeNode;
|
|
1010
|
-
}
|
|
1011
|
-
const newNode = maybeNode;
|
|
1012
|
-
const keys = Object.keys(maybeNode);
|
|
1013
|
-
Object.values(maybeNode).map((m, index) => {
|
|
1014
|
-
const key = keys[index];
|
|
1015
|
-
if (Array.isArray(m)) {
|
|
1016
|
-
newNode[key] = m.map((element) => {
|
|
1017
|
-
if (!element) {
|
|
1018
|
-
return;
|
|
1019
|
-
}
|
|
1020
|
-
if (!element.hasOwnProperty("name")) {
|
|
1021
|
-
return element;
|
|
1022
|
-
}
|
|
1023
|
-
const value = element.name || element.value;
|
|
1024
|
-
return addNamespaceToSchema(element, [...namespace, value]);
|
|
1025
|
-
});
|
|
1026
|
-
} else {
|
|
1027
|
-
if (!m) {
|
|
1028
|
-
return;
|
|
1029
|
-
}
|
|
1030
|
-
if (!m.hasOwnProperty("name")) {
|
|
1031
|
-
newNode[key] = m;
|
|
1032
|
-
} else {
|
|
1033
|
-
newNode[key] = addNamespaceToSchema(m, [...namespace, m.name]);
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
});
|
|
1037
|
-
return { ...newNode, namespace };
|
|
1038
|
-
}
|
|
1039
1032
|
var generateNamespacedFieldName = (names, suffix = "") => {
|
|
1040
1033
|
return (suffix ? [...names, suffix] : names).map(capitalize).join("");
|
|
1041
1034
|
};
|
|
@@ -1195,6 +1188,11 @@ var scalarDefinitions = [
|
|
|
1195
1188
|
required: true,
|
|
1196
1189
|
type: astBuilder.TYPES.String
|
|
1197
1190
|
}),
|
|
1191
|
+
astBuilder.FieldDefinition({
|
|
1192
|
+
name: "hasReferences",
|
|
1193
|
+
required: false,
|
|
1194
|
+
type: astBuilder.TYPES.Boolean
|
|
1195
|
+
}),
|
|
1198
1196
|
astBuilder.FieldDefinition({
|
|
1199
1197
|
name: "breadcrumbs",
|
|
1200
1198
|
required: true,
|
|
@@ -1408,6 +1406,19 @@ var Builder = class {
|
|
|
1408
1406
|
this.addToLookupMap = (lookup) => {
|
|
1409
1407
|
this.lookupMap[lookup.type] = lookup;
|
|
1410
1408
|
};
|
|
1409
|
+
/**
|
|
1410
|
+
* ```graphql
|
|
1411
|
+
* # ex.
|
|
1412
|
+
* {
|
|
1413
|
+
* getCollection(collection: $collection) {
|
|
1414
|
+
* name
|
|
1415
|
+
* documents {...}
|
|
1416
|
+
* }
|
|
1417
|
+
* }
|
|
1418
|
+
* ```
|
|
1419
|
+
*
|
|
1420
|
+
* @param collections
|
|
1421
|
+
*/
|
|
1411
1422
|
this.buildCollectionDefinition = async (collections) => {
|
|
1412
1423
|
const name = "collection";
|
|
1413
1424
|
const typeName = "Collection";
|
|
@@ -1478,6 +1489,19 @@ var Builder = class {
|
|
|
1478
1489
|
required: true
|
|
1479
1490
|
});
|
|
1480
1491
|
};
|
|
1492
|
+
/**
|
|
1493
|
+
* ```graphql
|
|
1494
|
+
* # ex.
|
|
1495
|
+
* {
|
|
1496
|
+
* getCollections {
|
|
1497
|
+
* name
|
|
1498
|
+
* documents {...}
|
|
1499
|
+
* }
|
|
1500
|
+
* }
|
|
1501
|
+
* ```
|
|
1502
|
+
*
|
|
1503
|
+
* @param collections
|
|
1504
|
+
*/
|
|
1481
1505
|
this.buildMultiCollectionDefinition = async (collections) => {
|
|
1482
1506
|
const name = "collections";
|
|
1483
1507
|
const typeName = "Collection";
|
|
@@ -1488,6 +1512,17 @@ var Builder = class {
|
|
|
1488
1512
|
required: true
|
|
1489
1513
|
});
|
|
1490
1514
|
};
|
|
1515
|
+
/**
|
|
1516
|
+
* ```graphql
|
|
1517
|
+
* # ex.
|
|
1518
|
+
* {
|
|
1519
|
+
* node(id: $id) {
|
|
1520
|
+
* id
|
|
1521
|
+
* data {...}
|
|
1522
|
+
* }
|
|
1523
|
+
* }
|
|
1524
|
+
* ```
|
|
1525
|
+
*/
|
|
1491
1526
|
this.multiNodeDocument = async () => {
|
|
1492
1527
|
const name = "node";
|
|
1493
1528
|
const args = [
|
|
@@ -1508,6 +1543,19 @@ var Builder = class {
|
|
|
1508
1543
|
required: true
|
|
1509
1544
|
});
|
|
1510
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
|
+
*/
|
|
1511
1559
|
this.multiCollectionDocument = async (collections) => {
|
|
1512
1560
|
const name = "document";
|
|
1513
1561
|
const args = [
|
|
@@ -1533,6 +1581,19 @@ var Builder = class {
|
|
|
1533
1581
|
required: true
|
|
1534
1582
|
});
|
|
1535
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
|
+
*/
|
|
1536
1597
|
this.addMultiCollectionDocumentMutation = async () => {
|
|
1537
1598
|
return astBuilder.FieldDefinition({
|
|
1538
1599
|
name: "addPendingDocument",
|
|
@@ -1557,6 +1618,19 @@ var Builder = class {
|
|
|
1557
1618
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1558
1619
|
});
|
|
1559
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
|
+
*/
|
|
1560
1634
|
this.buildCreateCollectionDocumentMutation = async (collections) => {
|
|
1561
1635
|
return astBuilder.FieldDefinition({
|
|
1562
1636
|
name: "createDocument",
|
|
@@ -1584,6 +1658,19 @@ var Builder = class {
|
|
|
1584
1658
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1585
1659
|
});
|
|
1586
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
|
+
*/
|
|
1587
1674
|
this.buildUpdateCollectionDocumentMutation = async (collections) => {
|
|
1588
1675
|
return astBuilder.FieldDefinition({
|
|
1589
1676
|
name: "updateDocument",
|
|
@@ -1611,6 +1698,19 @@ var Builder = class {
|
|
|
1611
1698
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1612
1699
|
});
|
|
1613
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
|
+
*/
|
|
1614
1714
|
this.buildDeleteCollectionDocumentMutation = async (collections) => {
|
|
1615
1715
|
return astBuilder.FieldDefinition({
|
|
1616
1716
|
name: "deleteDocument",
|
|
@@ -1630,6 +1730,19 @@ var Builder = class {
|
|
|
1630
1730
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1631
1731
|
});
|
|
1632
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
|
+
*/
|
|
1633
1746
|
this.buildCreateCollectionFolderMutation = async () => {
|
|
1634
1747
|
return astBuilder.FieldDefinition({
|
|
1635
1748
|
name: "createFolder",
|
|
@@ -1649,6 +1762,19 @@ var Builder = class {
|
|
|
1649
1762
|
type: astBuilder.TYPES.MultiCollectionDocument
|
|
1650
1763
|
});
|
|
1651
1764
|
};
|
|
1765
|
+
/**
|
|
1766
|
+
* ```graphql
|
|
1767
|
+
* # ex.
|
|
1768
|
+
* {
|
|
1769
|
+
* getPostDocument(relativePath: $relativePath) {
|
|
1770
|
+
* id
|
|
1771
|
+
* data {...}
|
|
1772
|
+
* }
|
|
1773
|
+
* }
|
|
1774
|
+
* ```
|
|
1775
|
+
*
|
|
1776
|
+
* @param collection
|
|
1777
|
+
*/
|
|
1652
1778
|
this.collectionDocument = async (collection) => {
|
|
1653
1779
|
const name = NAMER.queryName([collection.name]);
|
|
1654
1780
|
const type = await this._buildCollectionDocumentType(collection);
|
|
@@ -1709,6 +1835,20 @@ var Builder = class {
|
|
|
1709
1835
|
const args = [];
|
|
1710
1836
|
return astBuilder.FieldDefinition({ type, name, args, required: false });
|
|
1711
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
|
+
*/
|
|
1712
1852
|
this.collectionFragment = async (collection) => {
|
|
1713
1853
|
const name = NAMER.dataTypeName(collection.namespace);
|
|
1714
1854
|
const fragmentName = NAMER.fragmentName(collection.namespace);
|
|
@@ -1722,6 +1862,20 @@ var Builder = class {
|
|
|
1722
1862
|
selections: filterSelections(selections)
|
|
1723
1863
|
});
|
|
1724
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
|
+
* */
|
|
1725
1879
|
this._getCollectionFragmentSelections = async (collection, depth) => {
|
|
1726
1880
|
const selections = [];
|
|
1727
1881
|
selections.push({
|
|
@@ -1803,9 +1957,9 @@ var Builder = class {
|
|
|
1803
1957
|
]
|
|
1804
1958
|
});
|
|
1805
1959
|
}
|
|
1960
|
+
// TODO: Should we throw here?
|
|
1806
1961
|
case "reference":
|
|
1807
|
-
if (depth >= this.maxDepth)
|
|
1808
|
-
return false;
|
|
1962
|
+
if (depth >= this.maxDepth) return false;
|
|
1809
1963
|
if (!("collections" in field)) {
|
|
1810
1964
|
return false;
|
|
1811
1965
|
}
|
|
@@ -1837,6 +1991,7 @@ var Builder = class {
|
|
|
1837
1991
|
name: field.name,
|
|
1838
1992
|
selections: [
|
|
1839
1993
|
...selections,
|
|
1994
|
+
// This is ... on Document { id }
|
|
1840
1995
|
{
|
|
1841
1996
|
kind: "InlineFragment",
|
|
1842
1997
|
typeCondition: {
|
|
@@ -1867,6 +2022,19 @@ var Builder = class {
|
|
|
1867
2022
|
});
|
|
1868
2023
|
}
|
|
1869
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
|
+
*/
|
|
1870
2038
|
this.updateCollectionDocumentMutation = async (collection) => {
|
|
1871
2039
|
return astBuilder.FieldDefinition({
|
|
1872
2040
|
type: await this._buildCollectionDocumentType(collection),
|
|
@@ -1886,6 +2054,19 @@ var Builder = class {
|
|
|
1886
2054
|
]
|
|
1887
2055
|
});
|
|
1888
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
|
+
*/
|
|
1889
2070
|
this.createCollectionDocumentMutation = async (collection) => {
|
|
1890
2071
|
return astBuilder.FieldDefinition({
|
|
1891
2072
|
type: await this._buildCollectionDocumentType(collection),
|
|
@@ -1905,6 +2086,22 @@ var Builder = class {
|
|
|
1905
2086
|
]
|
|
1906
2087
|
});
|
|
1907
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
|
+
*/
|
|
1908
2105
|
this.collectionDocumentList = async (collection) => {
|
|
1909
2106
|
const connectionName = NAMER.referenceConnectionType(collection.namespace);
|
|
1910
2107
|
this.addToLookupMap({
|
|
@@ -1920,6 +2117,10 @@ var Builder = class {
|
|
|
1920
2117
|
collection
|
|
1921
2118
|
});
|
|
1922
2119
|
};
|
|
2120
|
+
/**
|
|
2121
|
+
* GraphQL type definitions which remain unchanged regardless
|
|
2122
|
+
* of the supplied Tina schema. Ex. "node" interface
|
|
2123
|
+
*/
|
|
1923
2124
|
this.buildStaticDefinitions = () => staticDefinitions;
|
|
1924
2125
|
this._buildCollectionDocumentType = async (collection, suffix = "", extraFields = [], extraInterfaces = []) => {
|
|
1925
2126
|
const documentTypeName = NAMER.documentTypeName(collection.namespace);
|
|
@@ -2424,6 +2625,7 @@ var Builder = class {
|
|
|
2424
2625
|
name: NAMER.dataFilterTypeName(namespace),
|
|
2425
2626
|
fields: await sequential(collections, async (collection2) => {
|
|
2426
2627
|
return astBuilder.InputValueDefinition({
|
|
2628
|
+
// @ts-ignore
|
|
2427
2629
|
name: collection2.name,
|
|
2428
2630
|
type: NAMER.dataFilterTypeName(collection2.namespace)
|
|
2429
2631
|
});
|
|
@@ -2612,7 +2814,8 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2612
2814
|
]
|
|
2613
2815
|
});
|
|
2614
2816
|
};
|
|
2615
|
-
this.maxDepth =
|
|
2817
|
+
this.maxDepth = // @ts-ignore
|
|
2818
|
+
config?.tinaSchema.schema?.config?.client?.referenceDepth ?? 2;
|
|
2616
2819
|
this.tinaSchema = config.tinaSchema;
|
|
2617
2820
|
this.lookupMap = {};
|
|
2618
2821
|
}
|
|
@@ -2623,8 +2826,7 @@ Visit https://tina.io/docs/errors/ui-not-supported/ for more information
|
|
|
2623
2826
|
selections.push(field);
|
|
2624
2827
|
});
|
|
2625
2828
|
const filteredSelections = filterSelections(selections);
|
|
2626
|
-
if (!filteredSelections.length)
|
|
2627
|
-
return false;
|
|
2829
|
+
if (!filteredSelections.length) return false;
|
|
2628
2830
|
return astBuilder.InlineFragmentDefinition({
|
|
2629
2831
|
selections: filteredSelections,
|
|
2630
2832
|
name: NAMER.dataTypeName(template.namespace)
|
|
@@ -2661,6 +2863,7 @@ var filterSelections = (arr) => {
|
|
|
2661
2863
|
import { TinaSchema } from "@tinacms/schema-tools";
|
|
2662
2864
|
|
|
2663
2865
|
// src/schema/validate.ts
|
|
2866
|
+
import { addNamespaceToSchema } from "@tinacms/schema-tools";
|
|
2664
2867
|
import deepClone from "lodash.clonedeep";
|
|
2665
2868
|
import * as yup2 from "yup";
|
|
2666
2869
|
import {
|
|
@@ -2707,6 +2910,7 @@ var validationCollectionsPathAndMatch = (collections) => {
|
|
|
2707
2910
|
}).map((x) => `${x.path}${x.format || "md"}`);
|
|
2708
2911
|
if (noMatchCollections.length !== new Set(noMatchCollections).size) {
|
|
2709
2912
|
throw new Error(
|
|
2913
|
+
// TODO: add a link to the docs
|
|
2710
2914
|
"Two collections without match can not have the same `path`. Please make the `path` unique or add a matches property to the collection."
|
|
2711
2915
|
);
|
|
2712
2916
|
}
|
|
@@ -2815,7 +3019,7 @@ var validateField = async (field) => {
|
|
|
2815
3019
|
// package.json
|
|
2816
3020
|
var package_default = {
|
|
2817
3021
|
name: "@tinacms/graphql",
|
|
2818
|
-
version: "1.5.
|
|
3022
|
+
version: "1.5.17",
|
|
2819
3023
|
main: "dist/index.js",
|
|
2820
3024
|
module: "dist/index.mjs",
|
|
2821
3025
|
typings: "dist/index.d.ts",
|
|
@@ -2841,9 +3045,8 @@ var package_default = {
|
|
|
2841
3045
|
types: "pnpm tsc",
|
|
2842
3046
|
build: "tinacms-scripts build",
|
|
2843
3047
|
docs: "pnpm typedoc",
|
|
2844
|
-
|
|
2845
|
-
test: "
|
|
2846
|
-
"test-watch": "jest --watch"
|
|
3048
|
+
test: "vitest run",
|
|
3049
|
+
"test-watch": "vitest"
|
|
2847
3050
|
},
|
|
2848
3051
|
dependencies: {
|
|
2849
3052
|
"@iarna/toml": "^2.2.5",
|
|
@@ -2851,22 +3054,22 @@ var package_default = {
|
|
|
2851
3054
|
"@tinacms/schema-tools": "workspace:*",
|
|
2852
3055
|
"abstract-level": "^1.0.4",
|
|
2853
3056
|
"date-fns": "^2.30.0",
|
|
2854
|
-
"fast-glob": "^3.3.
|
|
2855
|
-
"fs-extra": "^11.
|
|
3057
|
+
"fast-glob": "^3.3.3",
|
|
3058
|
+
"fs-extra": "^11.3.0",
|
|
2856
3059
|
"glob-parent": "^6.0.2",
|
|
2857
3060
|
graphql: "15.8.0",
|
|
2858
3061
|
"gray-matter": "^4.0.3",
|
|
2859
|
-
"isomorphic-git": "^1.
|
|
3062
|
+
"isomorphic-git": "^1.29.0",
|
|
2860
3063
|
"js-sha1": "^0.6.0",
|
|
2861
3064
|
"js-yaml": "^3.14.1",
|
|
2862
|
-
"jsonpath-plus": "
|
|
3065
|
+
"jsonpath-plus": "10.1.0",
|
|
2863
3066
|
"lodash.clonedeep": "^4.5.0",
|
|
2864
3067
|
"lodash.set": "^4.3.2",
|
|
2865
3068
|
"lodash.uniqby": "^4.7.0",
|
|
2866
3069
|
"many-level": "^2.0.0",
|
|
2867
3070
|
micromatch: "4.0.8",
|
|
2868
3071
|
"normalize-path": "^3.0.0",
|
|
2869
|
-
"readable-stream": "^4.
|
|
3072
|
+
"readable-stream": "^4.7.0",
|
|
2870
3073
|
scmp: "^2.1.0",
|
|
2871
3074
|
yup: "^0.32.11"
|
|
2872
3075
|
},
|
|
@@ -2884,24 +3087,22 @@ var package_default = {
|
|
|
2884
3087
|
"@types/estree": "^0.0.50",
|
|
2885
3088
|
"@types/express": "^4.17.21",
|
|
2886
3089
|
"@types/fs-extra": "^9.0.13",
|
|
2887
|
-
"@types/jest": "^26.0.24",
|
|
2888
3090
|
"@types/js-yaml": "^3.12.10",
|
|
2889
3091
|
"@types/lodash.camelcase": "^4.3.9",
|
|
2890
3092
|
"@types/lodash.upperfirst": "^4.3.9",
|
|
2891
3093
|
"@types/lru-cache": "^5.1.1",
|
|
2892
3094
|
"@types/mdast": "^3.0.15",
|
|
2893
3095
|
"@types/micromatch": "^4.0.9",
|
|
2894
|
-
"@types/node": "^22.
|
|
3096
|
+
"@types/node": "^22.13.1",
|
|
2895
3097
|
"@types/normalize-path": "^3.0.2",
|
|
2896
3098
|
"@types/ws": "^7.4.7",
|
|
2897
3099
|
"@types/yup": "^0.29.14",
|
|
2898
|
-
jest: "^29.7.0",
|
|
2899
|
-
"jest-diff": "^29.7.0",
|
|
2900
3100
|
"jest-file-snapshot": "^0.5.0",
|
|
2901
|
-
"jest-matcher-utils": "^29.7.0",
|
|
2902
3101
|
"memory-level": "^1.0.0",
|
|
2903
|
-
|
|
2904
|
-
|
|
3102
|
+
typescript: "^5.7.3",
|
|
3103
|
+
vite: "^4.5.9",
|
|
3104
|
+
vitest: "^0.32.4",
|
|
3105
|
+
zod: "^3.24.2"
|
|
2905
3106
|
}
|
|
2906
3107
|
};
|
|
2907
3108
|
|
|
@@ -2972,6 +3173,7 @@ var _buildFragments = async (builder, tinaSchema) => {
|
|
|
2972
3173
|
const fragDoc = {
|
|
2973
3174
|
kind: "Document",
|
|
2974
3175
|
definitions: uniqBy2(
|
|
3176
|
+
// @ts-ignore
|
|
2975
3177
|
extractInlineTypes(fragmentDefinitionsFields),
|
|
2976
3178
|
(node) => node.name.value
|
|
2977
3179
|
)
|
|
@@ -2994,6 +3196,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
2994
3196
|
fragName,
|
|
2995
3197
|
queryName: queryListName,
|
|
2996
3198
|
filterType: queryFilterTypeName,
|
|
3199
|
+
// look for flag to see if the data layer is enabled
|
|
2997
3200
|
dataLayer: Boolean(
|
|
2998
3201
|
tinaSchema.config?.meta?.flags?.find((x) => x === "experimentalData")
|
|
2999
3202
|
)
|
|
@@ -3003,6 +3206,7 @@ var _buildQueries = async (builder, tinaSchema) => {
|
|
|
3003
3206
|
const queryDoc = {
|
|
3004
3207
|
kind: "Document",
|
|
3005
3208
|
definitions: uniqBy2(
|
|
3209
|
+
// @ts-ignore
|
|
3006
3210
|
extractInlineTypes(operationsDefinitions),
|
|
3007
3211
|
(node) => node.name.value
|
|
3008
3212
|
)
|
|
@@ -3054,7 +3258,9 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3054
3258
|
await builder.buildCreateCollectionFolderMutation()
|
|
3055
3259
|
);
|
|
3056
3260
|
await sequential(collections, async (collection) => {
|
|
3057
|
-
queryTypeDefinitionFields.push(
|
|
3261
|
+
queryTypeDefinitionFields.push(
|
|
3262
|
+
await builder.collectionDocument(collection)
|
|
3263
|
+
);
|
|
3058
3264
|
if (collection.isAuthCollection) {
|
|
3059
3265
|
queryTypeDefinitionFields.push(
|
|
3060
3266
|
await builder.authenticationCollectionDocument(collection)
|
|
@@ -3091,6 +3297,7 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
3091
3297
|
return {
|
|
3092
3298
|
kind: "Document",
|
|
3093
3299
|
definitions: uniqBy2(
|
|
3300
|
+
// @ts-ignore
|
|
3094
3301
|
extractInlineTypes(definitions),
|
|
3095
3302
|
(node) => node.name.value
|
|
3096
3303
|
)
|
|
@@ -3107,6 +3314,9 @@ import isValid from "date-fns/isValid/index.js";
|
|
|
3107
3314
|
// src/mdx/index.ts
|
|
3108
3315
|
import { parseMDX, stringifyMDX } from "@tinacms/mdx";
|
|
3109
3316
|
|
|
3317
|
+
// src/resolver/index.ts
|
|
3318
|
+
import { JSONPath as JSONPath2 } from "jsonpath-plus";
|
|
3319
|
+
|
|
3110
3320
|
// src/resolver/error.ts
|
|
3111
3321
|
var TinaGraphQLError = class extends Error {
|
|
3112
3322
|
constructor(message, extensions) {
|
|
@@ -3292,8 +3502,7 @@ var resolveMediaCloudToRelative = (value, config = { useRelativeMedia: true }, s
|
|
|
3292
3502
|
}
|
|
3293
3503
|
if (Array.isArray(value)) {
|
|
3294
3504
|
return value.map((v) => {
|
|
3295
|
-
if (!v || typeof v !== "string")
|
|
3296
|
-
return v;
|
|
3505
|
+
if (!v || typeof v !== "string") return v;
|
|
3297
3506
|
const cleanMediaRoot = cleanUpSlashes(
|
|
3298
3507
|
schema.config.media.tina.mediaRoot
|
|
3299
3508
|
);
|
|
@@ -3321,8 +3530,7 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
|
|
|
3321
3530
|
}
|
|
3322
3531
|
if (Array.isArray(value)) {
|
|
3323
3532
|
return value.map((v) => {
|
|
3324
|
-
if (!v || typeof v !== "string")
|
|
3325
|
-
return v;
|
|
3533
|
+
if (!v || typeof v !== "string") return v;
|
|
3326
3534
|
const strippedValue = v.replace(cleanMediaRoot, "");
|
|
3327
3535
|
return `https://${config.assetsHost}/${config.clientId}${strippedValue}`;
|
|
3328
3536
|
});
|
|
@@ -3340,8 +3548,7 @@ var cleanUpSlashes = (path7) => {
|
|
|
3340
3548
|
return "";
|
|
3341
3549
|
};
|
|
3342
3550
|
var hasTinaMediaConfig = (schema) => {
|
|
3343
|
-
if (!schema.config?.media?.tina)
|
|
3344
|
-
return false;
|
|
3551
|
+
if (!schema.config?.media?.tina) return false;
|
|
3345
3552
|
if (typeof schema.config?.media?.tina?.publicFolder !== "string" && typeof schema.config?.media?.tina?.mediaRoot !== "string")
|
|
3346
3553
|
return false;
|
|
3347
3554
|
return true;
|
|
@@ -3368,7 +3575,9 @@ var LevelProxyHandler = {
|
|
|
3368
3575
|
throw new Error(`The property, ${property.toString()}, doesn't exist`);
|
|
3369
3576
|
}
|
|
3370
3577
|
if (typeof target[property] !== "function") {
|
|
3371
|
-
throw new Error(
|
|
3578
|
+
throw new Error(
|
|
3579
|
+
`The property, ${property.toString()}, is not a function`
|
|
3580
|
+
);
|
|
3372
3581
|
}
|
|
3373
3582
|
if (property === "get") {
|
|
3374
3583
|
return async (...args) => {
|
|
@@ -3385,6 +3594,7 @@ var LevelProxyHandler = {
|
|
|
3385
3594
|
} else if (property === "sublevel") {
|
|
3386
3595
|
return (...args) => {
|
|
3387
3596
|
return new Proxy(
|
|
3597
|
+
// eslint-disable-next-line prefer-spread
|
|
3388
3598
|
target[property].apply(target, args),
|
|
3389
3599
|
LevelProxyHandler
|
|
3390
3600
|
);
|
|
@@ -3752,6 +3962,9 @@ var loadAndParseWithAliases = async (bridge, filepath, collection, templateInfo)
|
|
|
3752
3962
|
|
|
3753
3963
|
// src/database/datalayer.ts
|
|
3754
3964
|
var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
|
|
3965
|
+
var REFS_COLLECTIONS_SORT_KEY = "__refs__";
|
|
3966
|
+
var REFS_REFERENCE_FIELD = "__tina_ref__";
|
|
3967
|
+
var REFS_PATH_FIELD = "__tina_ref_path__";
|
|
3755
3968
|
var DEFAULT_NUMERIC_LPAD = 4;
|
|
3756
3969
|
var applyPadding = (input, pad) => {
|
|
3757
3970
|
if (pad) {
|
|
@@ -4261,6 +4474,7 @@ var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opTy
|
|
|
4261
4474
|
result.push({
|
|
4262
4475
|
type: opType,
|
|
4263
4476
|
key: `${collection.path}/${subFolderKey}.${collection.format}`,
|
|
4477
|
+
// replace the root with the collection path
|
|
4264
4478
|
sublevel: indexSublevel,
|
|
4265
4479
|
value: {}
|
|
4266
4480
|
});
|
|
@@ -4324,6 +4538,57 @@ var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opT
|
|
|
4324
4538
|
}
|
|
4325
4539
|
return result;
|
|
4326
4540
|
};
|
|
4541
|
+
var makeRefOpsForDocument = (filepath, collection, references, data, opType, level) => {
|
|
4542
|
+
const result = [];
|
|
4543
|
+
if (collection) {
|
|
4544
|
+
for (const [c, referencePaths] of Object.entries(references || {})) {
|
|
4545
|
+
if (!referencePaths.length) {
|
|
4546
|
+
continue;
|
|
4547
|
+
}
|
|
4548
|
+
const collectionSublevel = level.sublevel(c, SUBLEVEL_OPTIONS);
|
|
4549
|
+
const refSublevel = collectionSublevel.sublevel(
|
|
4550
|
+
REFS_COLLECTIONS_SORT_KEY,
|
|
4551
|
+
SUBLEVEL_OPTIONS
|
|
4552
|
+
);
|
|
4553
|
+
const references2 = {};
|
|
4554
|
+
for (const path7 of referencePaths) {
|
|
4555
|
+
const ref = JSONPath({ path: path7, json: data });
|
|
4556
|
+
if (!ref) {
|
|
4557
|
+
continue;
|
|
4558
|
+
}
|
|
4559
|
+
if (Array.isArray(ref)) {
|
|
4560
|
+
for (const r of ref) {
|
|
4561
|
+
if (!r) {
|
|
4562
|
+
continue;
|
|
4563
|
+
}
|
|
4564
|
+
if (references2[r]) {
|
|
4565
|
+
references2[r].push(path7);
|
|
4566
|
+
} else {
|
|
4567
|
+
references2[r] = [path7];
|
|
4568
|
+
}
|
|
4569
|
+
}
|
|
4570
|
+
} else {
|
|
4571
|
+
if (references2[ref]) {
|
|
4572
|
+
references2[ref].push(path7);
|
|
4573
|
+
} else {
|
|
4574
|
+
references2[ref] = [path7];
|
|
4575
|
+
}
|
|
4576
|
+
}
|
|
4577
|
+
}
|
|
4578
|
+
for (const ref of Object.keys(references2)) {
|
|
4579
|
+
for (const path7 of references2[ref]) {
|
|
4580
|
+
result.push({
|
|
4581
|
+
type: opType,
|
|
4582
|
+
key: `${ref}${INDEX_KEY_FIELD_SEPARATOR}${path7}${INDEX_KEY_FIELD_SEPARATOR}${filepath}`,
|
|
4583
|
+
sublevel: refSublevel,
|
|
4584
|
+
value: opType === "put" ? {} : void 0
|
|
4585
|
+
});
|
|
4586
|
+
}
|
|
4587
|
+
}
|
|
4588
|
+
}
|
|
4589
|
+
}
|
|
4590
|
+
return result;
|
|
4591
|
+
};
|
|
4327
4592
|
var makeStringEscaper = (regex, replacement) => {
|
|
4328
4593
|
return (input) => {
|
|
4329
4594
|
if (Array.isArray(input)) {
|
|
@@ -4375,6 +4640,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4375
4640
|
case "password":
|
|
4376
4641
|
accumulator[field.name] = {
|
|
4377
4642
|
value: void 0,
|
|
4643
|
+
// never resolve the password hash
|
|
4378
4644
|
passwordChangeRequired: value["passwordChangeRequired"] ?? false
|
|
4379
4645
|
};
|
|
4380
4646
|
break;
|
|
@@ -4469,7 +4735,7 @@ var resolveFieldData = async ({ namespace, ...field }, rawData, accumulator, tin
|
|
|
4469
4735
|
}
|
|
4470
4736
|
return accumulator;
|
|
4471
4737
|
};
|
|
4472
|
-
var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config, isAudit) => {
|
|
4738
|
+
var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config, isAudit, hasReferences) => {
|
|
4473
4739
|
const collection = tinaSchema.getCollection(rawData._collection);
|
|
4474
4740
|
try {
|
|
4475
4741
|
const template = tinaSchema.getTemplateForData({
|
|
@@ -4523,6 +4789,7 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4523
4789
|
basename,
|
|
4524
4790
|
filename,
|
|
4525
4791
|
extension,
|
|
4792
|
+
hasReferences,
|
|
4526
4793
|
path: fullPath,
|
|
4527
4794
|
relativePath,
|
|
4528
4795
|
breadcrumbs,
|
|
@@ -4542,6 +4809,34 @@ var transformDocumentIntoPayload = async (fullPath, rawData, tinaSchema, config,
|
|
|
4542
4809
|
throw e;
|
|
4543
4810
|
}
|
|
4544
4811
|
};
|
|
4812
|
+
var updateObjectWithJsonPath = (obj, path7, oldValue, newValue) => {
|
|
4813
|
+
let updated = false;
|
|
4814
|
+
if (!path7.includes(".") && !path7.includes("[")) {
|
|
4815
|
+
if (path7 in obj && obj[path7] === oldValue) {
|
|
4816
|
+
obj[path7] = newValue;
|
|
4817
|
+
updated = true;
|
|
4818
|
+
}
|
|
4819
|
+
return { object: obj, updated };
|
|
4820
|
+
}
|
|
4821
|
+
const parentPath = path7.replace(/\.[^.\[\]]+$/, "");
|
|
4822
|
+
const keyToUpdate = path7.match(/[^.\[\]]+$/)[0];
|
|
4823
|
+
const parents = JSONPath2({
|
|
4824
|
+
path: parentPath,
|
|
4825
|
+
json: obj,
|
|
4826
|
+
resultType: "value"
|
|
4827
|
+
});
|
|
4828
|
+
if (parents.length > 0) {
|
|
4829
|
+
parents.forEach((parent) => {
|
|
4830
|
+
if (parent && typeof parent === "object" && keyToUpdate in parent) {
|
|
4831
|
+
if (parent[keyToUpdate] === oldValue) {
|
|
4832
|
+
parent[keyToUpdate] = newValue;
|
|
4833
|
+
updated = true;
|
|
4834
|
+
}
|
|
4835
|
+
}
|
|
4836
|
+
});
|
|
4837
|
+
}
|
|
4838
|
+
return { object: obj, updated };
|
|
4839
|
+
};
|
|
4545
4840
|
var Resolver = class {
|
|
4546
4841
|
constructor(init) {
|
|
4547
4842
|
this.init = init;
|
|
@@ -4549,6 +4844,7 @@ var Resolver = class {
|
|
|
4549
4844
|
const collection = this.tinaSchema.getCollection(collectionName);
|
|
4550
4845
|
const extraFields = {};
|
|
4551
4846
|
return {
|
|
4847
|
+
// return the collection and hasDocuments to resolve documents at a lower level
|
|
4552
4848
|
documents: { collection, hasDocuments },
|
|
4553
4849
|
...collection,
|
|
4554
4850
|
...extraFields
|
|
@@ -4556,7 +4852,9 @@ var Resolver = class {
|
|
|
4556
4852
|
};
|
|
4557
4853
|
this.getRaw = async (fullPath) => {
|
|
4558
4854
|
if (typeof fullPath !== "string") {
|
|
4559
|
-
throw new Error(
|
|
4855
|
+
throw new Error(
|
|
4856
|
+
`fullPath must be of type string for getDocument request`
|
|
4857
|
+
);
|
|
4560
4858
|
}
|
|
4561
4859
|
return this.database.get(fullPath);
|
|
4562
4860
|
};
|
|
@@ -4583,22 +4881,28 @@ var Resolver = class {
|
|
|
4583
4881
|
);
|
|
4584
4882
|
}
|
|
4585
4883
|
};
|
|
4586
|
-
this.getDocument = async (fullPath) => {
|
|
4884
|
+
this.getDocument = async (fullPath, opts = {}) => {
|
|
4587
4885
|
if (typeof fullPath !== "string") {
|
|
4588
|
-
throw new Error(
|
|
4886
|
+
throw new Error(
|
|
4887
|
+
`fullPath must be of type string for getDocument request`
|
|
4888
|
+
);
|
|
4589
4889
|
}
|
|
4590
4890
|
const rawData = await this.getRaw(fullPath);
|
|
4891
|
+
const hasReferences = opts?.checkReferences ? await this.hasReferences(fullPath, opts.collection) : void 0;
|
|
4591
4892
|
return transformDocumentIntoPayload(
|
|
4592
4893
|
fullPath,
|
|
4593
4894
|
rawData,
|
|
4594
4895
|
this.tinaSchema,
|
|
4595
4896
|
this.config,
|
|
4596
|
-
this.isAudit
|
|
4897
|
+
this.isAudit,
|
|
4898
|
+
hasReferences
|
|
4597
4899
|
);
|
|
4598
4900
|
};
|
|
4599
4901
|
this.deleteDocument = async (fullPath) => {
|
|
4600
4902
|
if (typeof fullPath !== "string") {
|
|
4601
|
-
throw new Error(
|
|
4903
|
+
throw new Error(
|
|
4904
|
+
`fullPath must be of type string for getDocument request`
|
|
4905
|
+
);
|
|
4602
4906
|
}
|
|
4603
4907
|
await this.database.delete(fullPath);
|
|
4604
4908
|
};
|
|
@@ -4633,7 +4937,9 @@ var Resolver = class {
|
|
|
4633
4937
|
);
|
|
4634
4938
|
} else {
|
|
4635
4939
|
return this.buildFieldMutations(
|
|
4940
|
+
// @ts-ignore FIXME Argument of type 'string | object' is not assignable to parameter of type '{ [fieldName: string]: string | object | (string | object)[]; }'
|
|
4636
4941
|
fieldValue,
|
|
4942
|
+
//@ts-ignore
|
|
4637
4943
|
objectTemplate,
|
|
4638
4944
|
existingData
|
|
4639
4945
|
);
|
|
@@ -4645,6 +4951,7 @@ var Resolver = class {
|
|
|
4645
4951
|
fieldValue.map(async (item) => {
|
|
4646
4952
|
if (typeof item === "string") {
|
|
4647
4953
|
throw new Error(
|
|
4954
|
+
//@ts-ignore
|
|
4648
4955
|
`Expected object for template value for field ${field.name}`
|
|
4649
4956
|
);
|
|
4650
4957
|
}
|
|
@@ -4653,16 +4960,19 @@ var Resolver = class {
|
|
|
4653
4960
|
});
|
|
4654
4961
|
const [templateName] = Object.entries(item)[0];
|
|
4655
4962
|
const template = templates.find(
|
|
4963
|
+
//@ts-ignore
|
|
4656
4964
|
(template2) => template2.name === templateName
|
|
4657
4965
|
);
|
|
4658
4966
|
if (!template) {
|
|
4659
4967
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4660
4968
|
}
|
|
4661
4969
|
return {
|
|
4970
|
+
// @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
|
|
4662
4971
|
...await this.buildFieldMutations(
|
|
4663
4972
|
item[template.name],
|
|
4664
4973
|
template
|
|
4665
4974
|
),
|
|
4975
|
+
//@ts-ignore
|
|
4666
4976
|
_template: template.name
|
|
4667
4977
|
};
|
|
4668
4978
|
})
|
|
@@ -4670,6 +4980,7 @@ var Resolver = class {
|
|
|
4670
4980
|
} else {
|
|
4671
4981
|
if (typeof fieldValue === "string") {
|
|
4672
4982
|
throw new Error(
|
|
4983
|
+
//@ts-ignore
|
|
4673
4984
|
`Expected object for template value for field ${field.name}`
|
|
4674
4985
|
);
|
|
4675
4986
|
}
|
|
@@ -4678,16 +4989,19 @@ var Resolver = class {
|
|
|
4678
4989
|
});
|
|
4679
4990
|
const [templateName] = Object.entries(fieldValue)[0];
|
|
4680
4991
|
const template = templates.find(
|
|
4992
|
+
//@ts-ignore
|
|
4681
4993
|
(template2) => template2.name === templateName
|
|
4682
4994
|
);
|
|
4683
4995
|
if (!template) {
|
|
4684
4996
|
throw new Error(`Expected to find template ${templateName}`);
|
|
4685
4997
|
}
|
|
4686
4998
|
return {
|
|
4999
|
+
// @ts-ignore FIXME Argument of type 'unknown' is not assignable to parameter of type '{ [fieldName: string]: string | { [key: string]: unknown; } | (string | { [key: string]: unknown; })[]; }'
|
|
4687
5000
|
...await this.buildFieldMutations(
|
|
4688
5001
|
fieldValue[template.name],
|
|
4689
5002
|
template
|
|
4690
5003
|
),
|
|
5004
|
+
//@ts-ignore
|
|
4691
5005
|
_template: template.name
|
|
4692
5006
|
};
|
|
4693
5007
|
}
|
|
@@ -4727,6 +5041,7 @@ var Resolver = class {
|
|
|
4727
5041
|
return this.getDocument(realPath);
|
|
4728
5042
|
}
|
|
4729
5043
|
const params = await this.buildObjectMutations(
|
|
5044
|
+
// @ts-ignore
|
|
4730
5045
|
args.params[collection.name],
|
|
4731
5046
|
collection
|
|
4732
5047
|
);
|
|
@@ -4772,6 +5087,7 @@ var Resolver = class {
|
|
|
4772
5087
|
const values = {
|
|
4773
5088
|
...oldDoc,
|
|
4774
5089
|
...await this.buildFieldMutations(
|
|
5090
|
+
// @ts-ignore FIXME: failing on unknown, which we don't need to know because it's recursive
|
|
4775
5091
|
templateParams,
|
|
4776
5092
|
template,
|
|
4777
5093
|
doc?._rawData
|
|
@@ -4785,13 +5101,22 @@ var Resolver = class {
|
|
|
4785
5101
|
return this.getDocument(realPath);
|
|
4786
5102
|
}
|
|
4787
5103
|
const params = await this.buildObjectMutations(
|
|
5104
|
+
//@ts-ignore
|
|
4788
5105
|
isCollectionSpecific ? args.params : args.params[collection.name],
|
|
4789
5106
|
collection,
|
|
4790
5107
|
doc?._rawData
|
|
4791
5108
|
);
|
|
4792
|
-
await this.database.put(
|
|
5109
|
+
await this.database.put(
|
|
5110
|
+
realPath,
|
|
5111
|
+
{ ...oldDoc, ...params },
|
|
5112
|
+
collection.name
|
|
5113
|
+
);
|
|
4793
5114
|
return this.getDocument(realPath);
|
|
4794
5115
|
};
|
|
5116
|
+
/**
|
|
5117
|
+
* Returns top-level fields which are not defined in the collection, so their
|
|
5118
|
+
* values are not eliminated from Tina when new values are saved
|
|
5119
|
+
*/
|
|
4795
5120
|
this.resolveLegacyValues = (oldDoc, collection) => {
|
|
4796
5121
|
const legacyValues = {};
|
|
4797
5122
|
Object.entries(oldDoc).forEach(([key, value]) => {
|
|
@@ -4896,6 +5221,40 @@ var Resolver = class {
|
|
|
4896
5221
|
if (isDeletion) {
|
|
4897
5222
|
const doc = await this.getDocument(realPath);
|
|
4898
5223
|
await this.deleteDocument(realPath);
|
|
5224
|
+
if (await this.hasReferences(realPath, collection)) {
|
|
5225
|
+
const collRefs = await this.findReferences(realPath, collection);
|
|
5226
|
+
for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
|
|
5227
|
+
for (const [pathToDocWithRef, referencePaths] of Object.entries(
|
|
5228
|
+
docsWithRefs
|
|
5229
|
+
)) {
|
|
5230
|
+
let refDoc = await this.getRaw(pathToDocWithRef);
|
|
5231
|
+
let hasUpdate = false;
|
|
5232
|
+
for (const path7 of referencePaths) {
|
|
5233
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5234
|
+
refDoc,
|
|
5235
|
+
path7,
|
|
5236
|
+
realPath,
|
|
5237
|
+
null
|
|
5238
|
+
);
|
|
5239
|
+
refDoc = object2;
|
|
5240
|
+
hasUpdate = updated || hasUpdate;
|
|
5241
|
+
}
|
|
5242
|
+
if (hasUpdate) {
|
|
5243
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5244
|
+
if (!collectionWithRef) {
|
|
5245
|
+
throw new Error(
|
|
5246
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5247
|
+
);
|
|
5248
|
+
}
|
|
5249
|
+
await this.database.put(
|
|
5250
|
+
pathToDocWithRef,
|
|
5251
|
+
refDoc,
|
|
5252
|
+
collectionWithRef.name
|
|
5253
|
+
);
|
|
5254
|
+
}
|
|
5255
|
+
}
|
|
5256
|
+
}
|
|
5257
|
+
}
|
|
4899
5258
|
return doc;
|
|
4900
5259
|
}
|
|
4901
5260
|
if (isUpdateName) {
|
|
@@ -4912,12 +5271,49 @@ var Resolver = class {
|
|
|
4912
5271
|
collection?.path,
|
|
4913
5272
|
args.params.relativePath
|
|
4914
5273
|
);
|
|
5274
|
+
if (newRealPath === realPath) {
|
|
5275
|
+
return doc;
|
|
5276
|
+
}
|
|
4915
5277
|
await this.database.put(newRealPath, doc._rawData, collection.name);
|
|
4916
5278
|
await this.deleteDocument(realPath);
|
|
5279
|
+
const collRefs = await this.findReferences(realPath, collection);
|
|
5280
|
+
for (const [collection2, docsWithRefs] of Object.entries(collRefs)) {
|
|
5281
|
+
for (const [pathToDocWithRef, referencePaths] of Object.entries(
|
|
5282
|
+
docsWithRefs
|
|
5283
|
+
)) {
|
|
5284
|
+
let docWithRef = await this.getRaw(pathToDocWithRef);
|
|
5285
|
+
let hasUpdate = false;
|
|
5286
|
+
for (const path7 of referencePaths) {
|
|
5287
|
+
const { object: object2, updated } = updateObjectWithJsonPath(
|
|
5288
|
+
docWithRef,
|
|
5289
|
+
path7,
|
|
5290
|
+
realPath,
|
|
5291
|
+
newRealPath
|
|
5292
|
+
);
|
|
5293
|
+
docWithRef = object2;
|
|
5294
|
+
hasUpdate = updated || hasUpdate;
|
|
5295
|
+
}
|
|
5296
|
+
if (hasUpdate) {
|
|
5297
|
+
const collectionWithRef = this.tinaSchema.getCollectionByFullPath(pathToDocWithRef);
|
|
5298
|
+
if (!collectionWithRef) {
|
|
5299
|
+
throw new Error(
|
|
5300
|
+
`Unable to find collection for ${pathToDocWithRef}`
|
|
5301
|
+
);
|
|
5302
|
+
}
|
|
5303
|
+
await this.database.put(
|
|
5304
|
+
pathToDocWithRef,
|
|
5305
|
+
docWithRef,
|
|
5306
|
+
collectionWithRef.name
|
|
5307
|
+
);
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
4917
5311
|
return this.getDocument(newRealPath);
|
|
4918
5312
|
}
|
|
4919
5313
|
if (alreadyExists === false) {
|
|
4920
|
-
throw new Error(
|
|
5314
|
+
throw new Error(
|
|
5315
|
+
`Unable to update document, ${realPath} does not exist`
|
|
5316
|
+
);
|
|
4921
5317
|
}
|
|
4922
5318
|
return this.updateResolveDocument({
|
|
4923
5319
|
collection,
|
|
@@ -4927,7 +5323,10 @@ var Resolver = class {
|
|
|
4927
5323
|
isCollectionSpecific
|
|
4928
5324
|
});
|
|
4929
5325
|
} else {
|
|
4930
|
-
return this.getDocument(realPath
|
|
5326
|
+
return this.getDocument(realPath, {
|
|
5327
|
+
collection,
|
|
5328
|
+
checkReferences: true
|
|
5329
|
+
});
|
|
4931
5330
|
}
|
|
4932
5331
|
};
|
|
4933
5332
|
this.resolveCollectionConnections = async ({ ids }) => {
|
|
@@ -4964,6 +5363,7 @@ var Resolver = class {
|
|
|
4964
5363
|
},
|
|
4965
5364
|
collection: referencedCollection,
|
|
4966
5365
|
hydrator: (path7) => path7
|
|
5366
|
+
// just return the path
|
|
4967
5367
|
}
|
|
4968
5368
|
);
|
|
4969
5369
|
const { edges } = resolvedCollectionConnection;
|
|
@@ -5031,6 +5431,82 @@ var Resolver = class {
|
|
|
5031
5431
|
}
|
|
5032
5432
|
};
|
|
5033
5433
|
};
|
|
5434
|
+
/**
|
|
5435
|
+
* Checks if a document has references to it
|
|
5436
|
+
* @param id The id of the document to check for references
|
|
5437
|
+
* @param c The collection to check for references
|
|
5438
|
+
* @returns true if the document has references, false otherwise
|
|
5439
|
+
*/
|
|
5440
|
+
this.hasReferences = async (id, c) => {
|
|
5441
|
+
let count = 0;
|
|
5442
|
+
await this.database.query(
|
|
5443
|
+
{
|
|
5444
|
+
collection: c.name,
|
|
5445
|
+
filterChain: makeFilterChain({
|
|
5446
|
+
conditions: [
|
|
5447
|
+
{
|
|
5448
|
+
filterPath: REFS_REFERENCE_FIELD,
|
|
5449
|
+
filterExpression: {
|
|
5450
|
+
_type: "string",
|
|
5451
|
+
_list: false,
|
|
5452
|
+
eq: id
|
|
5453
|
+
}
|
|
5454
|
+
}
|
|
5455
|
+
]
|
|
5456
|
+
}),
|
|
5457
|
+
sort: REFS_COLLECTIONS_SORT_KEY
|
|
5458
|
+
},
|
|
5459
|
+
(refId) => {
|
|
5460
|
+
count++;
|
|
5461
|
+
return refId;
|
|
5462
|
+
}
|
|
5463
|
+
);
|
|
5464
|
+
if (count) {
|
|
5465
|
+
return true;
|
|
5466
|
+
}
|
|
5467
|
+
return false;
|
|
5468
|
+
};
|
|
5469
|
+
/**
|
|
5470
|
+
* Finds references to a document
|
|
5471
|
+
* @param id the id of the document to find references to
|
|
5472
|
+
* @param c the collection to find references in
|
|
5473
|
+
* @returns a map of references to the document
|
|
5474
|
+
*/
|
|
5475
|
+
this.findReferences = async (id, c) => {
|
|
5476
|
+
const references = {};
|
|
5477
|
+
await this.database.query(
|
|
5478
|
+
{
|
|
5479
|
+
collection: c.name,
|
|
5480
|
+
filterChain: makeFilterChain({
|
|
5481
|
+
conditions: [
|
|
5482
|
+
{
|
|
5483
|
+
filterPath: REFS_REFERENCE_FIELD,
|
|
5484
|
+
filterExpression: {
|
|
5485
|
+
_type: "string",
|
|
5486
|
+
_list: false,
|
|
5487
|
+
eq: id
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
]
|
|
5491
|
+
}),
|
|
5492
|
+
sort: REFS_COLLECTIONS_SORT_KEY
|
|
5493
|
+
},
|
|
5494
|
+
(refId, rawItem) => {
|
|
5495
|
+
if (!references[c.name]) {
|
|
5496
|
+
references[c.name] = {};
|
|
5497
|
+
}
|
|
5498
|
+
if (!references[c.name][refId]) {
|
|
5499
|
+
references[c.name][refId] = [];
|
|
5500
|
+
}
|
|
5501
|
+
const referencePath = rawItem?.[REFS_PATH_FIELD];
|
|
5502
|
+
if (referencePath) {
|
|
5503
|
+
references[c.name][refId].push(referencePath);
|
|
5504
|
+
}
|
|
5505
|
+
return refId;
|
|
5506
|
+
}
|
|
5507
|
+
);
|
|
5508
|
+
return references;
|
|
5509
|
+
};
|
|
5034
5510
|
this.buildFieldMutations = async (fieldParams, template, existingData) => {
|
|
5035
5511
|
const accum = {};
|
|
5036
5512
|
for (const passwordField of template.fields.filter(
|
|
@@ -5117,6 +5593,27 @@ var Resolver = class {
|
|
|
5117
5593
|
}
|
|
5118
5594
|
return accum;
|
|
5119
5595
|
};
|
|
5596
|
+
/**
|
|
5597
|
+
* A mutation looks nearly identical between updateDocument:
|
|
5598
|
+
* ```graphql
|
|
5599
|
+
* updateDocument(collection: $collection,relativePath: $path, params: {
|
|
5600
|
+
* post: {
|
|
5601
|
+
* title: "Hello, World"
|
|
5602
|
+
* }
|
|
5603
|
+
* })`
|
|
5604
|
+
* ```
|
|
5605
|
+
* and `updatePostDocument`:
|
|
5606
|
+
* ```graphql
|
|
5607
|
+
* updatePostDocument(relativePath: $path, params: {
|
|
5608
|
+
* title: "Hello, World"
|
|
5609
|
+
* })
|
|
5610
|
+
* ```
|
|
5611
|
+
* The problem here is that we don't know whether the payload came from `updateDocument`
|
|
5612
|
+
* or `updatePostDocument` (we could, but for now it's easier not to pipe those details through),
|
|
5613
|
+
* But we do know that when given a `args.collection` value, we can assume that
|
|
5614
|
+
* this was a `updateDocument` request, and thus - should grab the data
|
|
5615
|
+
* from the corresponding field name in the key
|
|
5616
|
+
*/
|
|
5120
5617
|
this.buildParams = (args) => {
|
|
5121
5618
|
try {
|
|
5122
5619
|
assertShape(
|
|
@@ -5216,7 +5713,10 @@ var resolve = async ({
|
|
|
5216
5713
|
const graphQLSchema = buildASTSchema(graphQLSchemaAst);
|
|
5217
5714
|
const tinaConfig = await database.getTinaSchema();
|
|
5218
5715
|
const tinaSchema = await createSchema({
|
|
5716
|
+
// TODO: please update all the types to import from @tinacms/schema-tools
|
|
5717
|
+
// @ts-ignore
|
|
5219
5718
|
schema: tinaConfig,
|
|
5719
|
+
// @ts-ignore
|
|
5220
5720
|
flags: tinaConfig?.meta?.flags
|
|
5221
5721
|
});
|
|
5222
5722
|
const resolver = createResolver({
|
|
@@ -5233,8 +5733,7 @@ var resolve = async ({
|
|
|
5233
5733
|
database
|
|
5234
5734
|
},
|
|
5235
5735
|
typeResolver: async (source, _args, info) => {
|
|
5236
|
-
if (source.__typename)
|
|
5237
|
-
return source.__typename;
|
|
5736
|
+
if (source.__typename) return source.__typename;
|
|
5238
5737
|
const namedType = getNamedType(info.returnType).toString();
|
|
5239
5738
|
const lookup = await database.getLookup(namedType);
|
|
5240
5739
|
if (lookup.resolveType === "unionData") {
|
|
@@ -5383,11 +5882,13 @@ var resolve = async ({
|
|
|
5383
5882
|
set(
|
|
5384
5883
|
params,
|
|
5385
5884
|
userField.path.slice(1),
|
|
5885
|
+
// remove _rawData from users path
|
|
5386
5886
|
users.map((u) => {
|
|
5387
5887
|
if (user[idFieldName] === u[idFieldName]) {
|
|
5388
5888
|
return user;
|
|
5389
5889
|
}
|
|
5390
5890
|
return {
|
|
5891
|
+
// don't overwrite other users' passwords
|
|
5391
5892
|
...u,
|
|
5392
5893
|
[passwordFieldName]: {
|
|
5393
5894
|
...u[passwordFieldName],
|
|
@@ -5410,6 +5911,9 @@ var resolve = async ({
|
|
|
5410
5911
|
}
|
|
5411
5912
|
const isCreation = lookup[info.fieldName] === "create";
|
|
5412
5913
|
switch (lookup.resolveType) {
|
|
5914
|
+
/**
|
|
5915
|
+
* `node(id: $id)`
|
|
5916
|
+
*/
|
|
5413
5917
|
case "nodeDocument":
|
|
5414
5918
|
assertShape(
|
|
5415
5919
|
args,
|
|
@@ -5441,6 +5945,7 @@ var resolve = async ({
|
|
|
5441
5945
|
collection: args.collection,
|
|
5442
5946
|
isMutation,
|
|
5443
5947
|
isCreation,
|
|
5948
|
+
// Right now this is the only case for deletion
|
|
5444
5949
|
isDeletion: info.fieldName === "deleteDocument",
|
|
5445
5950
|
isFolderCreation: info.fieldName === "createFolder",
|
|
5446
5951
|
isUpdateName: Boolean(args?.params?.relativePath),
|
|
@@ -5450,6 +5955,9 @@ var resolve = async ({
|
|
|
5450
5955
|
return result;
|
|
5451
5956
|
}
|
|
5452
5957
|
return value;
|
|
5958
|
+
/**
|
|
5959
|
+
* eg `getMovieDocument.data.actors`
|
|
5960
|
+
*/
|
|
5453
5961
|
case "multiCollectionDocumentList":
|
|
5454
5962
|
if (Array.isArray(value)) {
|
|
5455
5963
|
return {
|
|
@@ -5461,7 +5969,15 @@ var resolve = async ({
|
|
|
5461
5969
|
}
|
|
5462
5970
|
if (info.fieldName === "documents" && value?.collection && value?.hasDocuments) {
|
|
5463
5971
|
let filter = args.filter;
|
|
5464
|
-
if (
|
|
5972
|
+
if (
|
|
5973
|
+
// 1. Make sure that the filter exists
|
|
5974
|
+
typeof args?.filter !== "undefined" && args?.filter !== null && // 2. Make sure that the collection name exists
|
|
5975
|
+
// @ts-ignore
|
|
5976
|
+
typeof value?.collection?.name === "string" && // 3. Make sure that the collection name is in the filter and is not undefined
|
|
5977
|
+
// @ts-ignore
|
|
5978
|
+
Object.keys(args.filter).includes(value?.collection?.name) && // @ts-ignore
|
|
5979
|
+
typeof args.filter[value?.collection?.name] !== "undefined"
|
|
5980
|
+
) {
|
|
5465
5981
|
filter = args.filter[value.collection.name];
|
|
5466
5982
|
}
|
|
5467
5983
|
return resolver.resolveCollectionConnection({
|
|
@@ -5469,12 +5985,20 @@ var resolve = async ({
|
|
|
5469
5985
|
...args,
|
|
5470
5986
|
filter
|
|
5471
5987
|
},
|
|
5988
|
+
// @ts-ignore
|
|
5472
5989
|
collection: value.collection
|
|
5473
5990
|
});
|
|
5474
5991
|
}
|
|
5475
5992
|
throw new Error(
|
|
5476
5993
|
`Expected an array for result of ${info.fieldName} at ${info.path}`
|
|
5477
5994
|
);
|
|
5995
|
+
/**
|
|
5996
|
+
* Collections-specific getter
|
|
5997
|
+
* eg. `getPostDocument`/`createPostDocument`/`updatePostDocument`
|
|
5998
|
+
*
|
|
5999
|
+
* if coming from a query result
|
|
6000
|
+
* the field will be `node`
|
|
6001
|
+
*/
|
|
5478
6002
|
case "collectionDocument": {
|
|
5479
6003
|
if (value) {
|
|
5480
6004
|
return value;
|
|
@@ -5489,11 +6013,32 @@ var resolve = async ({
|
|
|
5489
6013
|
});
|
|
5490
6014
|
return result;
|
|
5491
6015
|
}
|
|
6016
|
+
/**
|
|
6017
|
+
* Collections-specific list getter
|
|
6018
|
+
* eg. `getPageList`
|
|
6019
|
+
*/
|
|
5492
6020
|
case "collectionDocumentList":
|
|
5493
6021
|
return resolver.resolveCollectionConnection({
|
|
5494
6022
|
args,
|
|
5495
6023
|
collection: tinaSchema.getCollection(lookup.collection)
|
|
5496
6024
|
});
|
|
6025
|
+
/**
|
|
6026
|
+
* A polymorphic data set, it can be from a document's data
|
|
6027
|
+
* of any nested object which can be one of many shapes
|
|
6028
|
+
*
|
|
6029
|
+
* ```graphql
|
|
6030
|
+
* getPostDocument(relativePath: $relativePath) {
|
|
6031
|
+
* data {...} <- this part
|
|
6032
|
+
* }
|
|
6033
|
+
* ```
|
|
6034
|
+
* ```graphql
|
|
6035
|
+
* getBlockDocument(relativePath: $relativePath) {
|
|
6036
|
+
* data {
|
|
6037
|
+
* blocks {...} <- or this part
|
|
6038
|
+
* }
|
|
6039
|
+
* }
|
|
6040
|
+
* ```
|
|
6041
|
+
*/
|
|
5497
6042
|
case "unionData":
|
|
5498
6043
|
if (!value) {
|
|
5499
6044
|
if (args.relativePath) {
|
|
@@ -5558,8 +6103,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5558
6103
|
this.port = port || 9e3;
|
|
5559
6104
|
}
|
|
5560
6105
|
openConnection() {
|
|
5561
|
-
if (this._connected)
|
|
5562
|
-
return;
|
|
6106
|
+
if (this._connected) return;
|
|
5563
6107
|
const socket = connect(this.port);
|
|
5564
6108
|
pipeline(socket, this.createRpcStream(), socket, () => {
|
|
5565
6109
|
this._connected = false;
|
|
@@ -5569,7 +6113,7 @@ var TinaLevelClient = class extends ManyLevelGuest {
|
|
|
5569
6113
|
};
|
|
5570
6114
|
|
|
5571
6115
|
// src/database/index.ts
|
|
5572
|
-
import path4 from "path";
|
|
6116
|
+
import path4 from "node:path";
|
|
5573
6117
|
import { GraphQLError as GraphQLError5 } from "graphql";
|
|
5574
6118
|
import micromatch2 from "micromatch";
|
|
5575
6119
|
import sha2 from "js-sha1";
|
|
@@ -5704,6 +6248,7 @@ var Database = class {
|
|
|
5704
6248
|
);
|
|
5705
6249
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
5706
6250
|
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6251
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
5707
6252
|
const normalizedPath = normalizePath(filepath);
|
|
5708
6253
|
if (!collection?.isDetached) {
|
|
5709
6254
|
if (this.bridge) {
|
|
@@ -5732,6 +6277,14 @@ var Database = class {
|
|
|
5732
6277
|
let delOps = [];
|
|
5733
6278
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
5734
6279
|
putOps = [
|
|
6280
|
+
...makeRefOpsForDocument(
|
|
6281
|
+
normalizedPath,
|
|
6282
|
+
collection?.name,
|
|
6283
|
+
collectionReferences,
|
|
6284
|
+
dataFields,
|
|
6285
|
+
"put",
|
|
6286
|
+
level
|
|
6287
|
+
),
|
|
5735
6288
|
...makeIndexOpsForDocument(
|
|
5736
6289
|
normalizedPath,
|
|
5737
6290
|
collection?.name,
|
|
@@ -5740,6 +6293,7 @@ var Database = class {
|
|
|
5740
6293
|
"put",
|
|
5741
6294
|
level
|
|
5742
6295
|
),
|
|
6296
|
+
// folder indices
|
|
5743
6297
|
...makeIndexOpsForDocument(
|
|
5744
6298
|
normalizedPath,
|
|
5745
6299
|
`${collection?.name}_${folderKey}`,
|
|
@@ -5754,6 +6308,14 @@ var Database = class {
|
|
|
5754
6308
|
SUBLEVEL_OPTIONS
|
|
5755
6309
|
).get(normalizedPath);
|
|
5756
6310
|
delOps = existingItem ? [
|
|
6311
|
+
...makeRefOpsForDocument(
|
|
6312
|
+
normalizedPath,
|
|
6313
|
+
collection?.name,
|
|
6314
|
+
collectionReferences,
|
|
6315
|
+
existingItem,
|
|
6316
|
+
"del",
|
|
6317
|
+
level
|
|
6318
|
+
),
|
|
5757
6319
|
...makeIndexOpsForDocument(
|
|
5758
6320
|
normalizedPath,
|
|
5759
6321
|
collection?.name,
|
|
@@ -5762,6 +6324,7 @@ var Database = class {
|
|
|
5762
6324
|
"del",
|
|
5763
6325
|
level
|
|
5764
6326
|
),
|
|
6327
|
+
// folder indices
|
|
5765
6328
|
...makeIndexOpsForDocument(
|
|
5766
6329
|
normalizedPath,
|
|
5767
6330
|
`${collection?.name}_${folderKey}`,
|
|
@@ -5800,6 +6363,7 @@ var Database = class {
|
|
|
5800
6363
|
);
|
|
5801
6364
|
collectionIndexDefinitions = indexDefinitions?.[collectionName];
|
|
5802
6365
|
}
|
|
6366
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collectionName];
|
|
5803
6367
|
const normalizedPath = normalizePath(filepath);
|
|
5804
6368
|
const dataFields = await this.formatBodyOnPayload(filepath, data);
|
|
5805
6369
|
const collection = await this.collectionForPath(filepath);
|
|
@@ -5847,6 +6411,14 @@ var Database = class {
|
|
|
5847
6411
|
let delOps = [];
|
|
5848
6412
|
if (!isGitKeep(normalizedPath, collection)) {
|
|
5849
6413
|
putOps = [
|
|
6414
|
+
...makeRefOpsForDocument(
|
|
6415
|
+
normalizedPath,
|
|
6416
|
+
collectionName,
|
|
6417
|
+
collectionReferences,
|
|
6418
|
+
dataFields,
|
|
6419
|
+
"put",
|
|
6420
|
+
level
|
|
6421
|
+
),
|
|
5850
6422
|
...makeIndexOpsForDocument(
|
|
5851
6423
|
normalizedPath,
|
|
5852
6424
|
collectionName,
|
|
@@ -5855,6 +6427,7 @@ var Database = class {
|
|
|
5855
6427
|
"put",
|
|
5856
6428
|
level
|
|
5857
6429
|
),
|
|
6430
|
+
// folder indices
|
|
5858
6431
|
...makeIndexOpsForDocument(
|
|
5859
6432
|
normalizedPath,
|
|
5860
6433
|
`${collection?.name}_${folderKey}`,
|
|
@@ -5869,6 +6442,14 @@ var Database = class {
|
|
|
5869
6442
|
SUBLEVEL_OPTIONS
|
|
5870
6443
|
).get(normalizedPath);
|
|
5871
6444
|
delOps = existingItem ? [
|
|
6445
|
+
...makeRefOpsForDocument(
|
|
6446
|
+
normalizedPath,
|
|
6447
|
+
collectionName,
|
|
6448
|
+
collectionReferences,
|
|
6449
|
+
existingItem,
|
|
6450
|
+
"del",
|
|
6451
|
+
level
|
|
6452
|
+
),
|
|
5872
6453
|
...makeIndexOpsForDocument(
|
|
5873
6454
|
normalizedPath,
|
|
5874
6455
|
collectionName,
|
|
@@ -5877,6 +6458,7 @@ var Database = class {
|
|
|
5877
6458
|
"del",
|
|
5878
6459
|
level
|
|
5879
6460
|
),
|
|
6461
|
+
// folder indices
|
|
5880
6462
|
...makeIndexOpsForDocument(
|
|
5881
6463
|
normalizedPath,
|
|
5882
6464
|
`${collection?.name}_${folderKey}`,
|
|
@@ -5954,6 +6536,7 @@ var Database = class {
|
|
|
5954
6536
|
aliasedData,
|
|
5955
6537
|
extension,
|
|
5956
6538
|
writeTemplateKey,
|
|
6539
|
+
//templateInfo.type === 'union',
|
|
5957
6540
|
{
|
|
5958
6541
|
frontmatterFormat: collection?.frontmatterFormat,
|
|
5959
6542
|
frontmatterDelimiters: collection?.frontmatterDelimiters
|
|
@@ -5992,6 +6575,7 @@ var Database = class {
|
|
|
5992
6575
|
SUBLEVEL_OPTIONS
|
|
5993
6576
|
).get(graphqlPath);
|
|
5994
6577
|
};
|
|
6578
|
+
//TODO - is there a reason why the database fetches some config with "bridge.get", and some with "store.get"?
|
|
5995
6579
|
this.getGraphQLSchemaFromBridge = async () => {
|
|
5996
6580
|
if (!this.bridge) {
|
|
5997
6581
|
throw new Error(`No bridge configured`);
|
|
@@ -6028,6 +6612,22 @@ var Database = class {
|
|
|
6028
6612
|
this.tinaSchema = await createSchema({ schema });
|
|
6029
6613
|
return this.tinaSchema;
|
|
6030
6614
|
};
|
|
6615
|
+
this.getCollectionReferences = async (level) => {
|
|
6616
|
+
if (this.collectionReferences) {
|
|
6617
|
+
return this.collectionReferences;
|
|
6618
|
+
}
|
|
6619
|
+
const result = {};
|
|
6620
|
+
const schema = await this.getSchema(level || this.contentLevel);
|
|
6621
|
+
const collections = schema.getCollections();
|
|
6622
|
+
for (const collection of collections) {
|
|
6623
|
+
const collectionReferences = this.tinaSchema.findReferencesFromCollection(
|
|
6624
|
+
collection.name
|
|
6625
|
+
);
|
|
6626
|
+
result[collection.name] = collectionReferences;
|
|
6627
|
+
}
|
|
6628
|
+
this.collectionReferences = result;
|
|
6629
|
+
return result;
|
|
6630
|
+
};
|
|
6031
6631
|
this.getIndexDefinitions = async (level) => {
|
|
6032
6632
|
if (!this.collectionIndexDefinitions) {
|
|
6033
6633
|
await new Promise(async (resolve2, reject) => {
|
|
@@ -6037,10 +6637,53 @@ var Database = class {
|
|
|
6037
6637
|
const collections = schema.getCollections();
|
|
6038
6638
|
for (const collection of collections) {
|
|
6039
6639
|
const indexDefinitions = {
|
|
6040
|
-
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] }
|
|
6640
|
+
[DEFAULT_COLLECTION_SORT_KEY]: { fields: [] },
|
|
6641
|
+
// provide a default sort key which is the file sort
|
|
6642
|
+
// pseudo-index for the collection's references
|
|
6643
|
+
[REFS_COLLECTIONS_SORT_KEY]: {
|
|
6644
|
+
fields: [
|
|
6645
|
+
{
|
|
6646
|
+
name: REFS_REFERENCE_FIELD,
|
|
6647
|
+
type: "string",
|
|
6648
|
+
list: false
|
|
6649
|
+
},
|
|
6650
|
+
{
|
|
6651
|
+
name: REFS_PATH_FIELD,
|
|
6652
|
+
type: "string",
|
|
6653
|
+
list: false
|
|
6654
|
+
}
|
|
6655
|
+
]
|
|
6656
|
+
}
|
|
6041
6657
|
};
|
|
6042
|
-
|
|
6043
|
-
|
|
6658
|
+
let fields = [];
|
|
6659
|
+
if (collection.templates) {
|
|
6660
|
+
const templateFieldMap = {};
|
|
6661
|
+
const conflictedFields = /* @__PURE__ */ new Set();
|
|
6662
|
+
for (const template of collection.templates) {
|
|
6663
|
+
for (const field of template.fields) {
|
|
6664
|
+
if (!templateFieldMap[field.name]) {
|
|
6665
|
+
templateFieldMap[field.name] = field;
|
|
6666
|
+
} else {
|
|
6667
|
+
if (templateFieldMap[field.name].type !== field.type) {
|
|
6668
|
+
console.warn(
|
|
6669
|
+
`Field ${field.name} has conflicting types in templates - skipping index`
|
|
6670
|
+
);
|
|
6671
|
+
conflictedFields.add(field.name);
|
|
6672
|
+
}
|
|
6673
|
+
}
|
|
6674
|
+
}
|
|
6675
|
+
}
|
|
6676
|
+
for (const conflictedField in conflictedFields) {
|
|
6677
|
+
delete templateFieldMap[conflictedField];
|
|
6678
|
+
}
|
|
6679
|
+
for (const field of Object.values(templateFieldMap)) {
|
|
6680
|
+
fields.push(field);
|
|
6681
|
+
}
|
|
6682
|
+
} else if (collection.fields) {
|
|
6683
|
+
fields = collection.fields;
|
|
6684
|
+
}
|
|
6685
|
+
if (fields) {
|
|
6686
|
+
for (const field of fields) {
|
|
6044
6687
|
if (field.indexed !== void 0 && field.indexed === false || field.type === "object") {
|
|
6045
6688
|
continue;
|
|
6046
6689
|
}
|
|
@@ -6188,29 +6831,36 @@ var Database = class {
|
|
|
6188
6831
|
}
|
|
6189
6832
|
startKey = startKey || key || "";
|
|
6190
6833
|
endKey = key || "";
|
|
6191
|
-
edges = [...edges, { cursor: key, path: filepath }];
|
|
6834
|
+
edges = [...edges, { cursor: key, path: filepath, value: itemRecord }];
|
|
6192
6835
|
}
|
|
6193
6836
|
return {
|
|
6194
|
-
edges: await sequential(
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
|
|
6201
|
-
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
|
|
6207
|
-
|
|
6208
|
-
|
|
6209
|
-
|
|
6837
|
+
edges: await sequential(
|
|
6838
|
+
edges,
|
|
6839
|
+
async ({
|
|
6840
|
+
cursor,
|
|
6841
|
+
path: path7,
|
|
6842
|
+
value
|
|
6843
|
+
}) => {
|
|
6844
|
+
try {
|
|
6845
|
+
const node = await hydrator(path7, value);
|
|
6846
|
+
return {
|
|
6847
|
+
node,
|
|
6848
|
+
cursor: btoa(cursor)
|
|
6849
|
+
};
|
|
6850
|
+
} catch (error) {
|
|
6851
|
+
console.log(error);
|
|
6852
|
+
if (error instanceof Error && (!path7.includes(".tina/__generated__/_graphql.json") || !path7.includes("tina/__generated__/_graphql.json"))) {
|
|
6853
|
+
throw new TinaQueryError({
|
|
6854
|
+
originalError: error,
|
|
6855
|
+
file: path7,
|
|
6856
|
+
collection: collection.name,
|
|
6857
|
+
stack: error.stack
|
|
6858
|
+
});
|
|
6859
|
+
}
|
|
6860
|
+
throw error;
|
|
6210
6861
|
}
|
|
6211
|
-
throw error;
|
|
6212
6862
|
}
|
|
6213
|
-
|
|
6863
|
+
),
|
|
6214
6864
|
pageInfo: {
|
|
6215
6865
|
hasPreviousPage,
|
|
6216
6866
|
hasNextPage,
|
|
@@ -6334,13 +6984,14 @@ var Database = class {
|
|
|
6334
6984
|
documentPaths,
|
|
6335
6985
|
async (collection, documentPaths2) => {
|
|
6336
6986
|
if (collection && !collection.isDetached) {
|
|
6337
|
-
await _indexContent(
|
|
6338
|
-
this,
|
|
6339
|
-
this.contentLevel,
|
|
6340
|
-
documentPaths2,
|
|
6987
|
+
await _indexContent({
|
|
6988
|
+
database: this,
|
|
6989
|
+
level: this.contentLevel,
|
|
6990
|
+
documentPaths: documentPaths2,
|
|
6341
6991
|
enqueueOps,
|
|
6342
|
-
collection
|
|
6343
|
-
|
|
6992
|
+
collection,
|
|
6993
|
+
isPartialReindex: true
|
|
6994
|
+
});
|
|
6344
6995
|
}
|
|
6345
6996
|
}
|
|
6346
6997
|
);
|
|
@@ -6356,17 +7007,18 @@ var Database = class {
|
|
|
6356
7007
|
throw new Error(`No collection found for path: ${filepath}`);
|
|
6357
7008
|
}
|
|
6358
7009
|
const indexDefinitions = await this.getIndexDefinitions(this.contentLevel);
|
|
7010
|
+
const collectionReferences = (await this.getCollectionReferences())?.[collection.name];
|
|
6359
7011
|
const collectionIndexDefinitions = indexDefinitions?.[collection.name];
|
|
6360
7012
|
let level = this.contentLevel;
|
|
6361
7013
|
if (collection?.isDetached) {
|
|
6362
7014
|
level = this.appLevel.sublevel(collection?.name, SUBLEVEL_OPTIONS);
|
|
6363
7015
|
}
|
|
6364
|
-
const
|
|
7016
|
+
const normalizedPath = normalizePath(filepath);
|
|
6365
7017
|
const rootSublevel = level.sublevel(
|
|
6366
7018
|
CONTENT_ROOT_PREFIX,
|
|
6367
7019
|
SUBLEVEL_OPTIONS
|
|
6368
7020
|
);
|
|
6369
|
-
const item = await rootSublevel.get(
|
|
7021
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
6370
7022
|
if (item) {
|
|
6371
7023
|
const folderTreeBuilder = new FolderTreeBuilder();
|
|
6372
7024
|
const folderKey = folderTreeBuilder.update(
|
|
@@ -6374,16 +7026,25 @@ var Database = class {
|
|
|
6374
7026
|
collection.path || ""
|
|
6375
7027
|
);
|
|
6376
7028
|
await this.contentLevel.batch([
|
|
7029
|
+
...makeRefOpsForDocument(
|
|
7030
|
+
normalizedPath,
|
|
7031
|
+
collection.name,
|
|
7032
|
+
collectionReferences,
|
|
7033
|
+
item,
|
|
7034
|
+
"del",
|
|
7035
|
+
level
|
|
7036
|
+
),
|
|
6377
7037
|
...makeIndexOpsForDocument(
|
|
6378
|
-
|
|
7038
|
+
normalizedPath,
|
|
6379
7039
|
collection.name,
|
|
6380
7040
|
collectionIndexDefinitions,
|
|
6381
7041
|
item,
|
|
6382
7042
|
"del",
|
|
6383
7043
|
level
|
|
6384
7044
|
),
|
|
7045
|
+
// folder indices
|
|
6385
7046
|
...makeIndexOpsForDocument(
|
|
6386
|
-
|
|
7047
|
+
normalizedPath,
|
|
6387
7048
|
`${collection.name}_${folderKey}`,
|
|
6388
7049
|
collectionIndexDefinitions,
|
|
6389
7050
|
item,
|
|
@@ -6392,17 +7053,17 @@ var Database = class {
|
|
|
6392
7053
|
),
|
|
6393
7054
|
{
|
|
6394
7055
|
type: "del",
|
|
6395
|
-
key:
|
|
7056
|
+
key: normalizedPath,
|
|
6396
7057
|
sublevel: rootSublevel
|
|
6397
7058
|
}
|
|
6398
7059
|
]);
|
|
6399
7060
|
}
|
|
6400
7061
|
if (!collection?.isDetached) {
|
|
6401
7062
|
if (this.bridge) {
|
|
6402
|
-
await this.bridge.delete(
|
|
7063
|
+
await this.bridge.delete(normalizedPath);
|
|
6403
7064
|
}
|
|
6404
7065
|
try {
|
|
6405
|
-
await this.onDelete(
|
|
7066
|
+
await this.onDelete(normalizedPath);
|
|
6406
7067
|
} catch (e) {
|
|
6407
7068
|
throw new GraphQLError5(
|
|
6408
7069
|
`Error running onDelete hook for ${filepath}: ${e}`,
|
|
@@ -6437,20 +7098,26 @@ var Database = class {
|
|
|
6437
7098
|
);
|
|
6438
7099
|
const doc = await level2.keys({ limit: 1 }).next();
|
|
6439
7100
|
if (!doc) {
|
|
6440
|
-
await _indexContent(
|
|
6441
|
-
this,
|
|
6442
|
-
level2,
|
|
6443
|
-
contentPaths,
|
|
7101
|
+
await _indexContent({
|
|
7102
|
+
database: this,
|
|
7103
|
+
level: level2,
|
|
7104
|
+
documentPaths: contentPaths,
|
|
6444
7105
|
enqueueOps,
|
|
6445
7106
|
collection,
|
|
6446
|
-
userFields.map((field) => [
|
|
7107
|
+
passwordFields: userFields.map((field) => [
|
|
6447
7108
|
...field.path,
|
|
6448
7109
|
field.passwordFieldName
|
|
6449
7110
|
])
|
|
6450
|
-
);
|
|
7111
|
+
});
|
|
6451
7112
|
}
|
|
6452
7113
|
} else {
|
|
6453
|
-
await _indexContent(
|
|
7114
|
+
await _indexContent({
|
|
7115
|
+
database: this,
|
|
7116
|
+
level,
|
|
7117
|
+
documentPaths: contentPaths,
|
|
7118
|
+
enqueueOps,
|
|
7119
|
+
collection
|
|
7120
|
+
});
|
|
6454
7121
|
}
|
|
6455
7122
|
}
|
|
6456
7123
|
);
|
|
@@ -6536,6 +7203,9 @@ var Database = class {
|
|
|
6536
7203
|
info: templateInfo
|
|
6537
7204
|
};
|
|
6538
7205
|
}
|
|
7206
|
+
/**
|
|
7207
|
+
* Clears the internal cache of the tinaSchema and the lookup file. This allows the state to be reset
|
|
7208
|
+
*/
|
|
6539
7209
|
clearCache() {
|
|
6540
7210
|
this.tinaSchema = null;
|
|
6541
7211
|
this._lookup = null;
|
|
@@ -6586,7 +7256,15 @@ var hashPasswordValues = async (data, passwordFields) => Promise.all(
|
|
|
6586
7256
|
)
|
|
6587
7257
|
);
|
|
6588
7258
|
var isGitKeep = (filepath, collection) => filepath.endsWith(`.gitkeep.${collection?.format || "md"}`);
|
|
6589
|
-
var _indexContent = async (
|
|
7259
|
+
var _indexContent = async ({
|
|
7260
|
+
database,
|
|
7261
|
+
level,
|
|
7262
|
+
documentPaths,
|
|
7263
|
+
enqueueOps,
|
|
7264
|
+
collection,
|
|
7265
|
+
passwordFields,
|
|
7266
|
+
isPartialReindex
|
|
7267
|
+
}) => {
|
|
6590
7268
|
let collectionIndexDefinitions;
|
|
6591
7269
|
let collectionPath;
|
|
6592
7270
|
if (collection) {
|
|
@@ -6597,6 +7275,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6597
7275
|
}
|
|
6598
7276
|
collectionPath = collection.path;
|
|
6599
7277
|
}
|
|
7278
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
6600
7279
|
const tinaSchema = await database.getSchema();
|
|
6601
7280
|
let templateInfo = null;
|
|
6602
7281
|
if (collection) {
|
|
@@ -6618,12 +7297,61 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6618
7297
|
await hashPasswordValues(aliasedData, passwordFields);
|
|
6619
7298
|
}
|
|
6620
7299
|
const normalizedPath = normalizePath(filepath);
|
|
7300
|
+
const rootSublevel = level.sublevel(
|
|
7301
|
+
CONTENT_ROOT_PREFIX,
|
|
7302
|
+
SUBLEVEL_OPTIONS
|
|
7303
|
+
);
|
|
6621
7304
|
const folderKey = folderTreeBuilder.update(
|
|
6622
7305
|
normalizedPath,
|
|
6623
7306
|
collectionPath || ""
|
|
6624
7307
|
);
|
|
7308
|
+
if (isPartialReindex) {
|
|
7309
|
+
const item = await rootSublevel.get(normalizedPath);
|
|
7310
|
+
if (item) {
|
|
7311
|
+
await database.contentLevel.batch([
|
|
7312
|
+
...makeRefOpsForDocument(
|
|
7313
|
+
normalizedPath,
|
|
7314
|
+
collection?.name,
|
|
7315
|
+
collectionReferences,
|
|
7316
|
+
item,
|
|
7317
|
+
"del",
|
|
7318
|
+
level
|
|
7319
|
+
),
|
|
7320
|
+
...makeIndexOpsForDocument(
|
|
7321
|
+
normalizedPath,
|
|
7322
|
+
collection.name,
|
|
7323
|
+
collectionIndexDefinitions,
|
|
7324
|
+
item,
|
|
7325
|
+
"del",
|
|
7326
|
+
level
|
|
7327
|
+
),
|
|
7328
|
+
// folder indices
|
|
7329
|
+
...makeIndexOpsForDocument(
|
|
7330
|
+
normalizedPath,
|
|
7331
|
+
`${collection.name}_${folderKey}`,
|
|
7332
|
+
collectionIndexDefinitions,
|
|
7333
|
+
item,
|
|
7334
|
+
"del",
|
|
7335
|
+
level
|
|
7336
|
+
),
|
|
7337
|
+
{
|
|
7338
|
+
type: "del",
|
|
7339
|
+
key: normalizedPath,
|
|
7340
|
+
sublevel: rootSublevel
|
|
7341
|
+
}
|
|
7342
|
+
]);
|
|
7343
|
+
}
|
|
7344
|
+
}
|
|
6625
7345
|
if (!isGitKeep(filepath, collection)) {
|
|
6626
7346
|
await enqueueOps([
|
|
7347
|
+
...makeRefOpsForDocument(
|
|
7348
|
+
normalizedPath,
|
|
7349
|
+
collection?.name,
|
|
7350
|
+
collectionReferences,
|
|
7351
|
+
aliasedData,
|
|
7352
|
+
"put",
|
|
7353
|
+
level
|
|
7354
|
+
),
|
|
6627
7355
|
...makeIndexOpsForDocument(
|
|
6628
7356
|
normalizedPath,
|
|
6629
7357
|
collection?.name,
|
|
@@ -6632,6 +7360,7 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
6632
7360
|
"put",
|
|
6633
7361
|
level
|
|
6634
7362
|
),
|
|
7363
|
+
// folder indexes
|
|
6635
7364
|
...makeIndexOpsForDocument(
|
|
6636
7365
|
normalizedPath,
|
|
6637
7366
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6686,6 +7415,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6686
7415
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
6687
7416
|
}
|
|
6688
7417
|
}
|
|
7418
|
+
const collectionReferences = (await database.getCollectionReferences())?.[collection?.name];
|
|
6689
7419
|
const tinaSchema = await database.getSchema();
|
|
6690
7420
|
let templateInfo = null;
|
|
6691
7421
|
if (collection) {
|
|
@@ -6709,6 +7439,14 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6709
7439
|
item
|
|
6710
7440
|
) : item;
|
|
6711
7441
|
await enqueueOps([
|
|
7442
|
+
...makeRefOpsForDocument(
|
|
7443
|
+
itemKey,
|
|
7444
|
+
collection?.name,
|
|
7445
|
+
collectionReferences,
|
|
7446
|
+
aliasedData,
|
|
7447
|
+
"del",
|
|
7448
|
+
database.contentLevel
|
|
7449
|
+
),
|
|
6712
7450
|
...makeIndexOpsForDocument(
|
|
6713
7451
|
itemKey,
|
|
6714
7452
|
collection.name,
|
|
@@ -6717,6 +7455,7 @@ var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection
|
|
|
6717
7455
|
"del",
|
|
6718
7456
|
database.contentLevel
|
|
6719
7457
|
),
|
|
7458
|
+
// folder indexes
|
|
6720
7459
|
...makeIndexOpsForDocument(
|
|
6721
7460
|
itemKey,
|
|
6722
7461
|
`${collection?.name}_${folderKey}`,
|
|
@@ -6837,8 +7576,8 @@ import path6 from "path";
|
|
|
6837
7576
|
import normalize from "normalize-path";
|
|
6838
7577
|
var FilesystemBridge = class {
|
|
6839
7578
|
constructor(rootPath, outputPath) {
|
|
6840
|
-
this.rootPath = rootPath
|
|
6841
|
-
this.outputPath = outputPath
|
|
7579
|
+
this.rootPath = path6.resolve(rootPath);
|
|
7580
|
+
this.outputPath = outputPath ? path6.resolve(outputPath) : this.rootPath;
|
|
6842
7581
|
}
|
|
6843
7582
|
async glob(pattern, extension) {
|
|
6844
7583
|
const basePath = path6.join(this.outputPath, ...pattern.split("/"));
|
|
@@ -6850,19 +7589,19 @@ var FilesystemBridge = class {
|
|
|
6850
7589
|
}
|
|
6851
7590
|
);
|
|
6852
7591
|
const posixRootPath = normalize(this.outputPath);
|
|
6853
|
-
return items.map(
|
|
6854
|
-
|
|
6855
|
-
|
|
7592
|
+
return items.map(
|
|
7593
|
+
(item) => item.substring(posixRootPath.length).replace(/^\/|\/$/g, "")
|
|
7594
|
+
);
|
|
6856
7595
|
}
|
|
6857
7596
|
async delete(filepath) {
|
|
6858
7597
|
await fs2.remove(path6.join(this.outputPath, filepath));
|
|
6859
7598
|
}
|
|
6860
7599
|
async get(filepath) {
|
|
6861
|
-
return fs2.
|
|
7600
|
+
return (await fs2.readFile(path6.join(this.outputPath, filepath))).toString();
|
|
6862
7601
|
}
|
|
6863
7602
|
async put(filepath, data, basePathOverride) {
|
|
6864
7603
|
const basePath = basePathOverride || this.outputPath;
|
|
6865
|
-
await fs2.
|
|
7604
|
+
await fs2.outputFile(path6.join(basePath, filepath), data);
|
|
6866
7605
|
}
|
|
6867
7606
|
};
|
|
6868
7607
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|
|
@@ -6932,17 +7671,26 @@ var IsomorphicBridge = class {
|
|
|
6932
7671
|
getAuthor() {
|
|
6933
7672
|
return {
|
|
6934
7673
|
...this.author,
|
|
6935
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7674
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
6936
7675
|
timezoneOffset: 0
|
|
6937
7676
|
};
|
|
6938
7677
|
}
|
|
6939
7678
|
getCommitter() {
|
|
6940
7679
|
return {
|
|
6941
7680
|
...this.committer,
|
|
6942
|
-
timestamp: Math.round(new Date().getTime() / 1e3),
|
|
7681
|
+
timestamp: Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3),
|
|
6943
7682
|
timezoneOffset: 0
|
|
6944
7683
|
};
|
|
6945
7684
|
}
|
|
7685
|
+
/**
|
|
7686
|
+
* Recursively populate paths matching `pattern` for the given `entry`
|
|
7687
|
+
*
|
|
7688
|
+
* @param pattern - pattern to filter paths by
|
|
7689
|
+
* @param entry - TreeEntry to start building list from
|
|
7690
|
+
* @param path - base path
|
|
7691
|
+
* @param results
|
|
7692
|
+
* @private
|
|
7693
|
+
*/
|
|
6946
7694
|
async listEntries({
|
|
6947
7695
|
pattern,
|
|
6948
7696
|
entry,
|
|
@@ -6975,6 +7723,15 @@ var IsomorphicBridge = class {
|
|
|
6975
7723
|
});
|
|
6976
7724
|
}
|
|
6977
7725
|
}
|
|
7726
|
+
/**
|
|
7727
|
+
* For the specified path, returns an object with an array containing the parts of the path (pathParts)
|
|
7728
|
+
* and an array containing the WalkerEntry objects for the path parts (pathEntries). Any null elements in the
|
|
7729
|
+
* pathEntries are placeholders for non-existent entries.
|
|
7730
|
+
*
|
|
7731
|
+
* @param path - path being resolved
|
|
7732
|
+
* @param ref - ref to resolve path entries for
|
|
7733
|
+
* @private
|
|
7734
|
+
*/
|
|
6978
7735
|
async resolvePathEntries(path7, ref) {
|
|
6979
7736
|
let pathParts = path7.split("/");
|
|
6980
7737
|
const result = await git2.walk({
|
|
@@ -7005,6 +7762,17 @@ var IsomorphicBridge = class {
|
|
|
7005
7762
|
}
|
|
7006
7763
|
return { pathParts, pathEntries };
|
|
7007
7764
|
}
|
|
7765
|
+
/**
|
|
7766
|
+
* Updates tree entry and associated parent tree entries
|
|
7767
|
+
*
|
|
7768
|
+
* @param existingOid - the existing OID
|
|
7769
|
+
* @param updatedOid - the updated OID
|
|
7770
|
+
* @param path - the path of the entry being updated
|
|
7771
|
+
* @param type - the type of the entry being updated (blob or tree)
|
|
7772
|
+
* @param pathEntries - parent path entries
|
|
7773
|
+
* @param pathParts - parent path parts
|
|
7774
|
+
* @private
|
|
7775
|
+
*/
|
|
7008
7776
|
async updateTreeHierarchy(existingOid, updatedOid, path7, type, pathEntries, pathParts) {
|
|
7009
7777
|
const lastIdx = pathEntries.length - 1;
|
|
7010
7778
|
const parentEntry = pathEntries[lastIdx];
|
|
@@ -7060,6 +7828,13 @@ var IsomorphicBridge = class {
|
|
|
7060
7828
|
);
|
|
7061
7829
|
}
|
|
7062
7830
|
}
|
|
7831
|
+
/**
|
|
7832
|
+
* Creates a commit for the specified tree and updates the specified ref to point to the commit
|
|
7833
|
+
*
|
|
7834
|
+
* @param treeSha - sha of the new tree
|
|
7835
|
+
* @param ref - the ref that should be updated
|
|
7836
|
+
* @private
|
|
7837
|
+
*/
|
|
7063
7838
|
async commitTree(treeSha, ref) {
|
|
7064
7839
|
const commitSha = await git2.writeCommit({
|
|
7065
7840
|
...this.isomorphicConfig,
|
|
@@ -7072,6 +7847,7 @@ var IsomorphicBridge = class {
|
|
|
7072
7847
|
})
|
|
7073
7848
|
],
|
|
7074
7849
|
message: this.commitMessage,
|
|
7850
|
+
// TODO these should be configurable
|
|
7075
7851
|
author: this.getAuthor(),
|
|
7076
7852
|
committer: this.getCommitter()
|
|
7077
7853
|
}
|
|
@@ -7309,5 +8085,5 @@ export {
|
|
|
7309
8085
|
transformDocument,
|
|
7310
8086
|
transformDocumentIntoPayload
|
|
7311
8087
|
};
|
|
7312
|
-
//! Replaces _.flattenDeep()
|
|
7313
8088
|
//! Replaces _.get()
|
|
8089
|
+
//! Replaces _.flattenDeep()
|