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