@tinacms/graphql 1.4.7 → 1.4.8
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 +1 -0
- package/dist/database/datalayer.d.ts +10 -0
- package/dist/database/index.d.ts +7 -1
- package/dist/index.es.js +398 -104
- package/dist/index.js +399 -105
- package/dist/resolver/index.d.ts +64 -30
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -506,6 +506,7 @@ var astBuilder = {
|
|
|
506
506
|
},
|
|
507
507
|
MultiCollectionDocument: "DocumentNode",
|
|
508
508
|
CollectionDocumentUnion: "DocumentUnion",
|
|
509
|
+
Folder: "Folder",
|
|
509
510
|
String: "String",
|
|
510
511
|
Reference: "Reference",
|
|
511
512
|
Collection: "Collection",
|
|
@@ -1274,6 +1275,21 @@ var scalarDefinitions = [
|
|
|
1274
1275
|
})
|
|
1275
1276
|
]
|
|
1276
1277
|
}),
|
|
1278
|
+
astBuilder.ObjectTypeDefinition({
|
|
1279
|
+
name: astBuilder.TYPES.Folder,
|
|
1280
|
+
fields: [
|
|
1281
|
+
astBuilder.FieldDefinition({
|
|
1282
|
+
name: "name",
|
|
1283
|
+
required: true,
|
|
1284
|
+
type: astBuilder.TYPES.String
|
|
1285
|
+
}),
|
|
1286
|
+
astBuilder.FieldDefinition({
|
|
1287
|
+
name: "path",
|
|
1288
|
+
required: true,
|
|
1289
|
+
type: astBuilder.TYPES.String
|
|
1290
|
+
})
|
|
1291
|
+
]
|
|
1292
|
+
}),
|
|
1277
1293
|
astBuilder.ObjectTypeDefinition({
|
|
1278
1294
|
name: "PageInfo",
|
|
1279
1295
|
fields: [
|
|
@@ -1326,7 +1342,8 @@ var Builder = class {
|
|
|
1326
1342
|
namespace: ["document"],
|
|
1327
1343
|
nodeType: astBuilder.TYPES.MultiCollectionDocument,
|
|
1328
1344
|
collections,
|
|
1329
|
-
connectionNamespace: ["document"]
|
|
1345
|
+
connectionNamespace: ["document"],
|
|
1346
|
+
includeFolderFilter: true
|
|
1330
1347
|
});
|
|
1331
1348
|
const type = astBuilder.ObjectTypeDefinition({
|
|
1332
1349
|
name: typeName,
|
|
@@ -1425,7 +1442,8 @@ var Builder = class {
|
|
|
1425
1442
|
];
|
|
1426
1443
|
const type = await this._buildMultiCollectionDocumentDefinition({
|
|
1427
1444
|
fieldName: astBuilder.TYPES.MultiCollectionDocument,
|
|
1428
|
-
collections
|
|
1445
|
+
collections,
|
|
1446
|
+
includeFolderType: true
|
|
1429
1447
|
});
|
|
1430
1448
|
return astBuilder.FieldDefinition({
|
|
1431
1449
|
name,
|
|
@@ -1856,7 +1874,8 @@ var Builder = class {
|
|
|
1856
1874
|
};
|
|
1857
1875
|
this._buildMultiCollectionDocumentDefinition = async ({
|
|
1858
1876
|
fieldName,
|
|
1859
|
-
collections
|
|
1877
|
+
collections,
|
|
1878
|
+
includeFolderType
|
|
1860
1879
|
}) => {
|
|
1861
1880
|
const types = [];
|
|
1862
1881
|
collections.forEach((collection) => {
|
|
@@ -1866,14 +1885,14 @@ var Builder = class {
|
|
|
1866
1885
|
}
|
|
1867
1886
|
if (collection.templates) {
|
|
1868
1887
|
collection.templates.forEach((template) => {
|
|
1869
|
-
if (typeof template === "string") {
|
|
1870
|
-
throw new Error("Global templates not yet supported");
|
|
1871
|
-
}
|
|
1872
1888
|
const typeName = NAMER.documentTypeName(template.namespace);
|
|
1873
1889
|
types.push(typeName);
|
|
1874
1890
|
});
|
|
1875
1891
|
}
|
|
1876
1892
|
});
|
|
1893
|
+
if (includeFolderType) {
|
|
1894
|
+
types.push(astBuilder.TYPES.Folder);
|
|
1895
|
+
}
|
|
1877
1896
|
const type = astBuilder.UnionTypeDefinition({
|
|
1878
1897
|
name: fieldName,
|
|
1879
1898
|
types
|
|
@@ -1891,7 +1910,8 @@ var Builder = class {
|
|
|
1891
1910
|
namespace,
|
|
1892
1911
|
nodeType,
|
|
1893
1912
|
collections,
|
|
1894
|
-
connectionNamespace
|
|
1913
|
+
connectionNamespace,
|
|
1914
|
+
includeFolderFilter
|
|
1895
1915
|
}) => {
|
|
1896
1916
|
const connectionName = NAMER.referenceConnectionType(namespace);
|
|
1897
1917
|
await this.database.addToLookupMap({
|
|
@@ -1904,7 +1924,8 @@ var Builder = class {
|
|
|
1904
1924
|
namespace: connectionNamespace,
|
|
1905
1925
|
connectionName,
|
|
1906
1926
|
nodeType,
|
|
1907
|
-
collections
|
|
1927
|
+
collections,
|
|
1928
|
+
includeFolderFilter
|
|
1908
1929
|
});
|
|
1909
1930
|
};
|
|
1910
1931
|
this._buildFieldFilter = async (field) => {
|
|
@@ -2211,7 +2232,8 @@ var Builder = class {
|
|
|
2211
2232
|
connectionName,
|
|
2212
2233
|
nodeType,
|
|
2213
2234
|
collection,
|
|
2214
|
-
collections
|
|
2235
|
+
collections,
|
|
2236
|
+
includeFolderFilter
|
|
2215
2237
|
}) => {
|
|
2216
2238
|
const extra = [
|
|
2217
2239
|
await this._connectionFilterBuilder({
|
|
@@ -2221,6 +2243,14 @@ var Builder = class {
|
|
|
2221
2243
|
collections
|
|
2222
2244
|
})
|
|
2223
2245
|
];
|
|
2246
|
+
if (includeFolderFilter) {
|
|
2247
|
+
extra.push(
|
|
2248
|
+
astBuilder.InputValueDefinition({
|
|
2249
|
+
name: "folder",
|
|
2250
|
+
type: astBuilder.TYPES.String
|
|
2251
|
+
})
|
|
2252
|
+
);
|
|
2253
|
+
}
|
|
2224
2254
|
return astBuilder.FieldDefinition({
|
|
2225
2255
|
name: fieldName,
|
|
2226
2256
|
required: true,
|
|
@@ -2487,7 +2517,12 @@ var validateCollection = async (collection) => {
|
|
|
2487
2517
|
name: yup2.string().matches(/^[a-zA-Z0-9_]*$/, {
|
|
2488
2518
|
message: (obj) => `Collection's "name" must match ${obj.regex} at ${messageName}`
|
|
2489
2519
|
}).required(),
|
|
2490
|
-
path: yup2.string().required(
|
|
2520
|
+
path: yup2.string().test("is-required", "path is a required field", (value) => {
|
|
2521
|
+
if (value === "") {
|
|
2522
|
+
return true;
|
|
2523
|
+
}
|
|
2524
|
+
return yup2.string().required().isValidSync(value);
|
|
2525
|
+
}).transform((value) => {
|
|
2491
2526
|
return value.replace(/^\/|\/$/g, "");
|
|
2492
2527
|
})
|
|
2493
2528
|
});
|
|
@@ -2542,7 +2577,7 @@ var validateField = async (field) => {
|
|
|
2542
2577
|
// package.json
|
|
2543
2578
|
var package_default = {
|
|
2544
2579
|
name: "@tinacms/graphql",
|
|
2545
|
-
version: "1.4.
|
|
2580
|
+
version: "1.4.8",
|
|
2546
2581
|
main: "dist/index.js",
|
|
2547
2582
|
module: "dist/index.es.js",
|
|
2548
2583
|
typings: "dist/index.d.ts",
|
|
@@ -2594,6 +2629,7 @@ var package_default = {
|
|
|
2594
2629
|
"graphql-type-json": "^0.3.2",
|
|
2595
2630
|
"gray-matter": "^4.0.2",
|
|
2596
2631
|
"isomorphic-git": "^1.21.0",
|
|
2632
|
+
"js-sha1": "^0.6.0",
|
|
2597
2633
|
"js-yaml": "^3.14.1",
|
|
2598
2634
|
"jsonpath-plus": "^6.0.1",
|
|
2599
2635
|
leveldown: "^6.1.0",
|
|
@@ -2857,7 +2893,7 @@ var _buildSchema = async (builder, tinaSchema) => {
|
|
|
2857
2893
|
var import_graphql4 = require("graphql");
|
|
2858
2894
|
|
|
2859
2895
|
// src/resolver/index.ts
|
|
2860
|
-
var
|
|
2896
|
+
var import_path2 = __toESM(require("path"));
|
|
2861
2897
|
var import_isValid = __toESM(require("date-fns/isValid"));
|
|
2862
2898
|
|
|
2863
2899
|
// src/mdx/index.ts
|
|
@@ -3088,9 +3124,9 @@ var resolveMediaRelativeToCloud = (value, config = { useRelativeMedia: true }, s
|
|
|
3088
3124
|
return value;
|
|
3089
3125
|
}
|
|
3090
3126
|
};
|
|
3091
|
-
var cleanUpSlashes = (
|
|
3092
|
-
if (
|
|
3093
|
-
return `/${
|
|
3127
|
+
var cleanUpSlashes = (path5) => {
|
|
3128
|
+
if (path5) {
|
|
3129
|
+
return `/${path5.replace(/^\/+|\/+$/gm, "")}`;
|
|
3094
3130
|
}
|
|
3095
3131
|
return "";
|
|
3096
3132
|
};
|
|
@@ -3107,6 +3143,7 @@ var import_graphql3 = require("graphql");
|
|
|
3107
3143
|
|
|
3108
3144
|
// src/database/datalayer.ts
|
|
3109
3145
|
var import_jsonpath_plus = require("jsonpath-plus");
|
|
3146
|
+
var import_js_sha1 = __toESM(require("js-sha1"));
|
|
3110
3147
|
|
|
3111
3148
|
// src/database/level.ts
|
|
3112
3149
|
var INDEX_KEY_FIELD_SEPARATOR = "";
|
|
@@ -3154,6 +3191,7 @@ var LevelProxy = class {
|
|
|
3154
3191
|
};
|
|
3155
3192
|
|
|
3156
3193
|
// src/database/datalayer.ts
|
|
3194
|
+
var import_path = __toESM(require("path"));
|
|
3157
3195
|
var DEFAULT_COLLECTION_SORT_KEY = "__filepath__";
|
|
3158
3196
|
var DEFAULT_NUMERIC_LPAD = 4;
|
|
3159
3197
|
var applyPadding = (input, pad) => {
|
|
@@ -3520,6 +3558,106 @@ var makeFilterSuffixes = (filterChain, index) => {
|
|
|
3520
3558
|
return {};
|
|
3521
3559
|
}
|
|
3522
3560
|
};
|
|
3561
|
+
var FOLDER_ROOT = "~";
|
|
3562
|
+
var stripCollectionFromPath = (collectionPath, path5) => {
|
|
3563
|
+
const collectionPathParts = collectionPath.split("/");
|
|
3564
|
+
const pathParts = path5.split("/");
|
|
3565
|
+
const strippedPathParts = pathParts.slice(collectionPathParts.length);
|
|
3566
|
+
return strippedPathParts.join("/");
|
|
3567
|
+
};
|
|
3568
|
+
var FolderTreeBuilder = class {
|
|
3569
|
+
constructor() {
|
|
3570
|
+
this._tree = {
|
|
3571
|
+
[FOLDER_ROOT]: /* @__PURE__ */ new Set()
|
|
3572
|
+
};
|
|
3573
|
+
}
|
|
3574
|
+
get tree() {
|
|
3575
|
+
return this._tree;
|
|
3576
|
+
}
|
|
3577
|
+
update(documentPath, collectionPath) {
|
|
3578
|
+
let folderPath = import_path.default.dirname(documentPath);
|
|
3579
|
+
if (collectionPath) {
|
|
3580
|
+
folderPath = stripCollectionFromPath(collectionPath, folderPath);
|
|
3581
|
+
}
|
|
3582
|
+
const parent = [FOLDER_ROOT];
|
|
3583
|
+
folderPath.split("/").filter((part) => part.length).forEach((part) => {
|
|
3584
|
+
const current2 = parent.join("/");
|
|
3585
|
+
if (!this._tree[current2]) {
|
|
3586
|
+
this._tree[current2] = /* @__PURE__ */ new Set();
|
|
3587
|
+
}
|
|
3588
|
+
this._tree[current2].add(import_path.default.join(current2, part));
|
|
3589
|
+
parent.push(part);
|
|
3590
|
+
});
|
|
3591
|
+
const current = parent.join("/");
|
|
3592
|
+
if (!this._tree[current]) {
|
|
3593
|
+
this._tree[current] = /* @__PURE__ */ new Set();
|
|
3594
|
+
}
|
|
3595
|
+
return current === FOLDER_ROOT ? FOLDER_ROOT : import_js_sha1.default.hex(current);
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3598
|
+
var makeFolderOpsForCollection = (folderTree, collection, indexDefinitions, opType, level, escapeStr = stringEscaper) => {
|
|
3599
|
+
const result = [];
|
|
3600
|
+
const data = {};
|
|
3601
|
+
const indexedValues = {};
|
|
3602
|
+
for (const [sort, indexDefinition] of Object.entries(indexDefinitions)) {
|
|
3603
|
+
for (const field of indexDefinition.fields) {
|
|
3604
|
+
data[field.name] = "";
|
|
3605
|
+
}
|
|
3606
|
+
indexedValues[sort] = makeKeyForField(indexDefinition, data, escapeStr);
|
|
3607
|
+
}
|
|
3608
|
+
const baseCharacter = "a".charCodeAt(0);
|
|
3609
|
+
for (const [folderName, folder] of Object.entries(folderTree)) {
|
|
3610
|
+
const parentFolderKey = folderName === FOLDER_ROOT ? FOLDER_ROOT : import_js_sha1.default.hex(folderName);
|
|
3611
|
+
const folderCollectionSublevel = level.sublevel(
|
|
3612
|
+
`${collection.name}_${parentFolderKey}`,
|
|
3613
|
+
SUBLEVEL_OPTIONS
|
|
3614
|
+
);
|
|
3615
|
+
let folderSortingIdx = 0;
|
|
3616
|
+
for (const path5 of Array.from(folder).sort()) {
|
|
3617
|
+
for (const [sort] of Object.entries(indexDefinitions)) {
|
|
3618
|
+
const indexSublevel = folderCollectionSublevel.sublevel(
|
|
3619
|
+
sort,
|
|
3620
|
+
SUBLEVEL_OPTIONS
|
|
3621
|
+
);
|
|
3622
|
+
const subFolderKey = import_js_sha1.default.hex(path5);
|
|
3623
|
+
if (sort === DEFAULT_COLLECTION_SORT_KEY) {
|
|
3624
|
+
result.push({
|
|
3625
|
+
type: opType,
|
|
3626
|
+
key: `${collection.path}/${subFolderKey}.${collection.format}`,
|
|
3627
|
+
sublevel: indexSublevel,
|
|
3628
|
+
value: {}
|
|
3629
|
+
});
|
|
3630
|
+
} else {
|
|
3631
|
+
const indexValue = `${String.fromCharCode(
|
|
3632
|
+
baseCharacter + folderSortingIdx
|
|
3633
|
+
)}${indexedValues[sort].substring(1)}`;
|
|
3634
|
+
result.push({
|
|
3635
|
+
type: opType,
|
|
3636
|
+
key: `${indexValue}${INDEX_KEY_FIELD_SEPARATOR}${collection.path}/${subFolderKey}.${collection.format}`,
|
|
3637
|
+
sublevel: indexSublevel,
|
|
3638
|
+
value: {}
|
|
3639
|
+
});
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
folderSortingIdx++;
|
|
3643
|
+
}
|
|
3644
|
+
if (folderName !== FOLDER_ROOT) {
|
|
3645
|
+
result.push({
|
|
3646
|
+
type: "put",
|
|
3647
|
+
key: `${collection.path}/${parentFolderKey}.${collection.format}`,
|
|
3648
|
+
value: {
|
|
3649
|
+
__folderBasename: import_path.default.basename(folderName),
|
|
3650
|
+
__folderPath: folderName
|
|
3651
|
+
},
|
|
3652
|
+
sublevel: level.sublevel(
|
|
3653
|
+
CONTENT_ROOT_PREFIX,
|
|
3654
|
+
SUBLEVEL_OPTIONS
|
|
3655
|
+
)
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
return result;
|
|
3660
|
+
};
|
|
3523
3661
|
var makeIndexOpsForDocument = (filepath, collection, indexDefinitions, data, opType, level, escapeStr = stringEscaper) => {
|
|
3524
3662
|
const result = [];
|
|
3525
3663
|
if (collection) {
|
|
@@ -3584,11 +3722,37 @@ var Resolver = class {
|
|
|
3584
3722
|
...extraFields
|
|
3585
3723
|
};
|
|
3586
3724
|
};
|
|
3725
|
+
this.getRaw = async (fullPath) => {
|
|
3726
|
+
if (typeof fullPath !== "string") {
|
|
3727
|
+
throw new Error(`fullPath must be of type string for getDocument request`);
|
|
3728
|
+
}
|
|
3729
|
+
return this.database.get(fullPath);
|
|
3730
|
+
};
|
|
3731
|
+
this.getDocumentOrDirectory = async (fullPath) => {
|
|
3732
|
+
if (typeof fullPath !== "string") {
|
|
3733
|
+
throw new Error(
|
|
3734
|
+
`fullPath must be of type string for getDocumentOrDirectory request`
|
|
3735
|
+
);
|
|
3736
|
+
}
|
|
3737
|
+
const rawData = await this.getRaw(fullPath);
|
|
3738
|
+
if (rawData["__folderBasename"]) {
|
|
3739
|
+
return {
|
|
3740
|
+
__typename: "Folder",
|
|
3741
|
+
name: rawData["__folderBasename"],
|
|
3742
|
+
path: rawData["__folderPath"]
|
|
3743
|
+
};
|
|
3744
|
+
} else {
|
|
3745
|
+
return this.transformDocumentIntoPayload(fullPath, rawData);
|
|
3746
|
+
}
|
|
3747
|
+
};
|
|
3587
3748
|
this.getDocument = async (fullPath) => {
|
|
3588
3749
|
if (typeof fullPath !== "string") {
|
|
3589
3750
|
throw new Error(`fullPath must be of type string for getDocument request`);
|
|
3590
3751
|
}
|
|
3591
|
-
const rawData = await this.
|
|
3752
|
+
const rawData = await this.getRaw(fullPath);
|
|
3753
|
+
return this.transformDocumentIntoPayload(fullPath, rawData);
|
|
3754
|
+
};
|
|
3755
|
+
this.transformDocumentIntoPayload = async (fullPath, rawData) => {
|
|
3592
3756
|
const collection = this.tinaSchema.getCollection(rawData._collection);
|
|
3593
3757
|
try {
|
|
3594
3758
|
const template = await this.tinaSchema.getTemplateForData({
|
|
@@ -3599,7 +3763,7 @@ var Resolver = class {
|
|
|
3599
3763
|
base: basename,
|
|
3600
3764
|
ext: extension,
|
|
3601
3765
|
name: filename
|
|
3602
|
-
} =
|
|
3766
|
+
} = import_path2.default.parse(fullPath);
|
|
3603
3767
|
const relativePath = fullPath.replace(/\\/g, "/").replace(collection.path, "").replace(/^\/|\/$/g, "");
|
|
3604
3768
|
const breadcrumbs = relativePath.replace(extension, "").split("/");
|
|
3605
3769
|
const data = {
|
|
@@ -3631,7 +3795,7 @@ var Resolver = class {
|
|
|
3631
3795
|
id: fullPath,
|
|
3632
3796
|
...data,
|
|
3633
3797
|
_sys: {
|
|
3634
|
-
title,
|
|
3798
|
+
title: title || "",
|
|
3635
3799
|
basename,
|
|
3636
3800
|
filename,
|
|
3637
3801
|
extension,
|
|
@@ -3842,7 +4006,7 @@ var Resolver = class {
|
|
|
3842
4006
|
(yup3) => yup3.object({ relativePath: yup3.string().required() })
|
|
3843
4007
|
);
|
|
3844
4008
|
const collection = await this.tinaSchema.getCollection(collectionLookup);
|
|
3845
|
-
const realPath =
|
|
4009
|
+
const realPath = import_path2.default.join(collection == null ? void 0 : collection.path, args.relativePath);
|
|
3846
4010
|
const alreadyExists = await this.database.documentExists(realPath);
|
|
3847
4011
|
if (isMutation) {
|
|
3848
4012
|
if (isCreation) {
|
|
@@ -3883,7 +4047,7 @@ var Resolver = class {
|
|
|
3883
4047
|
(yup3) => yup3.object({ relativePath: yup3.string().required() })
|
|
3884
4048
|
);
|
|
3885
4049
|
const doc = await this.getDocument(realPath);
|
|
3886
|
-
const newRealPath =
|
|
4050
|
+
const newRealPath = import_path2.default.join(
|
|
3887
4051
|
collection == null ? void 0 : collection.path,
|
|
3888
4052
|
args.params.relativePath
|
|
3889
4053
|
);
|
|
@@ -3938,7 +4102,7 @@ var Resolver = class {
|
|
|
3938
4102
|
first: -1
|
|
3939
4103
|
},
|
|
3940
4104
|
collection: referencedCollection,
|
|
3941
|
-
hydrator: (
|
|
4105
|
+
hydrator: (path5) => path5
|
|
3942
4106
|
}
|
|
3943
4107
|
);
|
|
3944
4108
|
const { edges } = resolvedCollectionConnection;
|
|
@@ -3986,11 +4150,12 @@ var Resolver = class {
|
|
|
3986
4150
|
first: args.first,
|
|
3987
4151
|
last: args.last,
|
|
3988
4152
|
before: args.before,
|
|
3989
|
-
after: args.after
|
|
4153
|
+
after: args.after,
|
|
4154
|
+
folder: args.folder
|
|
3990
4155
|
};
|
|
3991
4156
|
const result = await this.database.query(
|
|
3992
4157
|
queryOptions,
|
|
3993
|
-
hydrator ? hydrator : this.
|
|
4158
|
+
hydrator ? hydrator : this.getDocumentOrDirectory
|
|
3994
4159
|
);
|
|
3995
4160
|
const edges = result.edges;
|
|
3996
4161
|
const pageInfo = result.pageInfo;
|
|
@@ -4472,7 +4637,7 @@ var resolve = async ({
|
|
|
4472
4637
|
};
|
|
4473
4638
|
|
|
4474
4639
|
// src/database/index.ts
|
|
4475
|
-
var
|
|
4640
|
+
var import_path3 = __toESM(require("path"));
|
|
4476
4641
|
var import_graphql5 = require("graphql");
|
|
4477
4642
|
var import_micromatch = __toESM(require("micromatch"));
|
|
4478
4643
|
|
|
@@ -4682,6 +4847,7 @@ var _applyNameOverrides = (fields, obj) => {
|
|
|
4682
4847
|
};
|
|
4683
4848
|
|
|
4684
4849
|
// src/database/index.ts
|
|
4850
|
+
var import_js_sha12 = __toESM(require("js-sha1"));
|
|
4685
4851
|
var createDatabase = (config) => {
|
|
4686
4852
|
return new Database({
|
|
4687
4853
|
...config,
|
|
@@ -4700,14 +4866,14 @@ var Database = class {
|
|
|
4700
4866
|
const tinaSchema = await this.getSchema(this.level);
|
|
4701
4867
|
return tinaSchema.getCollectionByFullPath(filepath);
|
|
4702
4868
|
};
|
|
4703
|
-
this.getGeneratedFolder = () =>
|
|
4869
|
+
this.getGeneratedFolder = () => import_path3.default.join(this.tinaDirectory, "__generated__");
|
|
4704
4870
|
this.get = async (filepath) => {
|
|
4705
4871
|
await this.initLevel();
|
|
4706
4872
|
if (SYSTEM_FILES.includes(filepath)) {
|
|
4707
4873
|
throw new Error(`Unexpected get for config file ${filepath}`);
|
|
4708
4874
|
} else {
|
|
4709
4875
|
const tinaSchema = await this.getSchema(this.level);
|
|
4710
|
-
const extension =
|
|
4876
|
+
const extension = import_path3.default.extname(filepath);
|
|
4711
4877
|
const contentObject = await this.level.sublevel(
|
|
4712
4878
|
CONTENT_ROOT_PREFIX,
|
|
4713
4879
|
SUBLEVEL_OPTIONS
|
|
@@ -4762,26 +4928,48 @@ var Database = class {
|
|
|
4762
4928
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
4763
4929
|
}
|
|
4764
4930
|
await this.onPut(normalizedPath, stringifiedFile);
|
|
4765
|
-
const
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4931
|
+
const folderTreeBuilder = new FolderTreeBuilder();
|
|
4932
|
+
const folderKey = folderTreeBuilder.update(filepath, collection.path || "");
|
|
4933
|
+
const putOps = [
|
|
4934
|
+
...makeIndexOpsForDocument(
|
|
4935
|
+
normalizedPath,
|
|
4936
|
+
collection == null ? void 0 : collection.name,
|
|
4937
|
+
collectionIndexDefinitions,
|
|
4938
|
+
dataFields,
|
|
4939
|
+
"put",
|
|
4940
|
+
this.level
|
|
4941
|
+
),
|
|
4942
|
+
...makeIndexOpsForDocument(
|
|
4943
|
+
normalizedPath,
|
|
4944
|
+
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
4945
|
+
collectionIndexDefinitions,
|
|
4946
|
+
dataFields,
|
|
4947
|
+
"put",
|
|
4948
|
+
this.level
|
|
4949
|
+
)
|
|
4950
|
+
];
|
|
4773
4951
|
const existingItem = await this.level.sublevel(
|
|
4774
4952
|
CONTENT_ROOT_PREFIX,
|
|
4775
4953
|
SUBLEVEL_OPTIONS
|
|
4776
4954
|
).get(normalizedPath);
|
|
4777
|
-
const delOps = existingItem ?
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4955
|
+
const delOps = existingItem ? [
|
|
4956
|
+
...makeIndexOpsForDocument(
|
|
4957
|
+
normalizedPath,
|
|
4958
|
+
collection == null ? void 0 : collection.name,
|
|
4959
|
+
collectionIndexDefinitions,
|
|
4960
|
+
existingItem,
|
|
4961
|
+
"del",
|
|
4962
|
+
this.level
|
|
4963
|
+
),
|
|
4964
|
+
...makeIndexOpsForDocument(
|
|
4965
|
+
normalizedPath,
|
|
4966
|
+
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
4967
|
+
collectionIndexDefinitions,
|
|
4968
|
+
existingItem,
|
|
4969
|
+
"del",
|
|
4970
|
+
this.level
|
|
4971
|
+
)
|
|
4972
|
+
] : [];
|
|
4785
4973
|
const ops = [
|
|
4786
4974
|
...delOps,
|
|
4787
4975
|
...putOps,
|
|
@@ -4832,26 +5020,51 @@ var Database = class {
|
|
|
4832
5020
|
await this.bridge.put(normalizedPath, stringifiedFile);
|
|
4833
5021
|
}
|
|
4834
5022
|
await this.onPut(normalizedPath, stringifiedFile);
|
|
4835
|
-
const
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
dataFields,
|
|
4840
|
-
"put",
|
|
4841
|
-
this.level
|
|
5023
|
+
const folderTreeBuilder = new FolderTreeBuilder();
|
|
5024
|
+
const folderKey = folderTreeBuilder.update(
|
|
5025
|
+
filepath,
|
|
5026
|
+
collection.path || ""
|
|
4842
5027
|
);
|
|
5028
|
+
const putOps = [
|
|
5029
|
+
...makeIndexOpsForDocument(
|
|
5030
|
+
normalizedPath,
|
|
5031
|
+
collectionName,
|
|
5032
|
+
collectionIndexDefinitions,
|
|
5033
|
+
dataFields,
|
|
5034
|
+
"put",
|
|
5035
|
+
this.level
|
|
5036
|
+
),
|
|
5037
|
+
...makeIndexOpsForDocument(
|
|
5038
|
+
normalizedPath,
|
|
5039
|
+
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
5040
|
+
collectionIndexDefinitions,
|
|
5041
|
+
dataFields,
|
|
5042
|
+
"put",
|
|
5043
|
+
this.level
|
|
5044
|
+
)
|
|
5045
|
+
];
|
|
4843
5046
|
const existingItem = await this.level.sublevel(
|
|
4844
5047
|
CONTENT_ROOT_PREFIX,
|
|
4845
5048
|
SUBLEVEL_OPTIONS
|
|
4846
5049
|
).get(normalizedPath);
|
|
4847
|
-
const delOps = existingItem ?
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
5050
|
+
const delOps = existingItem ? [
|
|
5051
|
+
...makeIndexOpsForDocument(
|
|
5052
|
+
normalizedPath,
|
|
5053
|
+
collectionName,
|
|
5054
|
+
collectionIndexDefinitions,
|
|
5055
|
+
existingItem,
|
|
5056
|
+
"del",
|
|
5057
|
+
this.level
|
|
5058
|
+
),
|
|
5059
|
+
...makeIndexOpsForDocument(
|
|
5060
|
+
normalizedPath,
|
|
5061
|
+
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
5062
|
+
collectionIndexDefinitions,
|
|
5063
|
+
existingItem,
|
|
5064
|
+
"del",
|
|
5065
|
+
this.level
|
|
5066
|
+
)
|
|
5067
|
+
] : [];
|
|
4855
5068
|
const ops = [
|
|
4856
5069
|
...delOps,
|
|
4857
5070
|
...putOps,
|
|
@@ -4909,7 +5122,7 @@ var Database = class {
|
|
|
4909
5122
|
);
|
|
4910
5123
|
const writeTemplateKey = templateDetails.info.type === "union";
|
|
4911
5124
|
const aliasedData = applyNameOverrides(templateDetails.template, payload);
|
|
4912
|
-
const extension =
|
|
5125
|
+
const extension = import_path3.default.extname(filepath);
|
|
4913
5126
|
const stringifiedFile = stringifyFile(
|
|
4914
5127
|
aliasedData,
|
|
4915
5128
|
extension,
|
|
@@ -4935,7 +5148,7 @@ var Database = class {
|
|
|
4935
5148
|
this.getLookup = async (returnType) => {
|
|
4936
5149
|
await this.initLevel();
|
|
4937
5150
|
const lookupPath = (0, import_schema_tools3.normalizePath)(
|
|
4938
|
-
|
|
5151
|
+
import_path3.default.join(this.getGeneratedFolder(), `_lookup.json`)
|
|
4939
5152
|
);
|
|
4940
5153
|
if (!this._lookup) {
|
|
4941
5154
|
const _lookup = await this.level.sublevel(
|
|
@@ -4949,7 +5162,7 @@ var Database = class {
|
|
|
4949
5162
|
this.getGraphQLSchema = async () => {
|
|
4950
5163
|
await this.initLevel();
|
|
4951
5164
|
const graphqlPath = (0, import_schema_tools3.normalizePath)(
|
|
4952
|
-
|
|
5165
|
+
import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)
|
|
4953
5166
|
);
|
|
4954
5167
|
return await this.level.sublevel(
|
|
4955
5168
|
CONTENT_ROOT_PREFIX,
|
|
@@ -4961,7 +5174,7 @@ var Database = class {
|
|
|
4961
5174
|
throw new Error(`No bridge configured`);
|
|
4962
5175
|
}
|
|
4963
5176
|
const graphqlPath = (0, import_schema_tools3.normalizePath)(
|
|
4964
|
-
|
|
5177
|
+
import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)
|
|
4965
5178
|
);
|
|
4966
5179
|
const _graphql = await this.bridge.get(graphqlPath);
|
|
4967
5180
|
return JSON.parse(_graphql);
|
|
@@ -4969,7 +5182,7 @@ var Database = class {
|
|
|
4969
5182
|
this.getTinaSchema = async (level) => {
|
|
4970
5183
|
await this.initLevel();
|
|
4971
5184
|
const schemaPath = (0, import_schema_tools3.normalizePath)(
|
|
4972
|
-
|
|
5185
|
+
import_path3.default.join(this.getGeneratedFolder(), `_schema.json`)
|
|
4973
5186
|
);
|
|
4974
5187
|
return await (level || this.level).sublevel(
|
|
4975
5188
|
CONTENT_ROOT_PREFIX,
|
|
@@ -4985,7 +5198,7 @@ var Database = class {
|
|
|
4985
5198
|
if (!schema) {
|
|
4986
5199
|
throw new Error(
|
|
4987
5200
|
`Unable to get schema from level db: ${(0, import_schema_tools3.normalizePath)(
|
|
4988
|
-
|
|
5201
|
+
import_path3.default.join(this.getGeneratedFolder(), `_schema.json`)
|
|
4989
5202
|
)}`
|
|
4990
5203
|
);
|
|
4991
5204
|
}
|
|
@@ -5063,7 +5276,8 @@ var Database = class {
|
|
|
5063
5276
|
before,
|
|
5064
5277
|
sort = DEFAULT_COLLECTION_SORT_KEY,
|
|
5065
5278
|
collection,
|
|
5066
|
-
filterChain: rawFilterChain
|
|
5279
|
+
filterChain: rawFilterChain,
|
|
5280
|
+
folder
|
|
5067
5281
|
} = queryOptions;
|
|
5068
5282
|
let limit = 50;
|
|
5069
5283
|
if (first) {
|
|
@@ -5091,12 +5305,15 @@ var Database = class {
|
|
|
5091
5305
|
CONTENT_ROOT_PREFIX,
|
|
5092
5306
|
SUBLEVEL_OPTIONS
|
|
5093
5307
|
);
|
|
5094
|
-
const sublevel = indexDefinition ? this.level.sublevel(
|
|
5308
|
+
const sublevel = indexDefinition ? this.level.sublevel(
|
|
5309
|
+
`${collection}${folder ? `_${folder === FOLDER_ROOT ? folder : import_js_sha12.default.hex(folder)}` : ""}`,
|
|
5310
|
+
SUBLEVEL_OPTIONS
|
|
5311
|
+
).sublevel(sort, SUBLEVEL_OPTIONS) : rootLevel;
|
|
5095
5312
|
if (!query.gt && !query.gte) {
|
|
5096
5313
|
query.gte = (filterSuffixes == null ? void 0 : filterSuffixes.left) ? filterSuffixes.left : "";
|
|
5097
5314
|
}
|
|
5098
5315
|
if (!query.lt && !query.lte) {
|
|
5099
|
-
query.lte = (filterSuffixes == null ? void 0 : filterSuffixes.right) ? `${filterSuffixes.right}\
|
|
5316
|
+
query.lte = (filterSuffixes == null ? void 0 : filterSuffixes.right) ? `${filterSuffixes.right}\uFFFF` : "\uFFFF";
|
|
5100
5317
|
}
|
|
5101
5318
|
let edges = [];
|
|
5102
5319
|
let startKey = "";
|
|
@@ -5165,11 +5382,11 @@ var Database = class {
|
|
|
5165
5382
|
}) => {
|
|
5166
5383
|
if (this.bridge && this.bridge.supportsBuilding()) {
|
|
5167
5384
|
await this.bridge.putConfig(
|
|
5168
|
-
(0, import_schema_tools3.normalizePath)(
|
|
5385
|
+
(0, import_schema_tools3.normalizePath)(import_path3.default.join(this.getGeneratedFolder(), `_graphql.json`)),
|
|
5169
5386
|
JSON.stringify(graphQLSchema)
|
|
5170
5387
|
);
|
|
5171
5388
|
await this.bridge.putConfig(
|
|
5172
|
-
(0, import_schema_tools3.normalizePath)(
|
|
5389
|
+
(0, import_schema_tools3.normalizePath)(import_path3.default.join(this.getGeneratedFolder(), `_schema.json`)),
|
|
5173
5390
|
JSON.stringify(tinaSchema.schema)
|
|
5174
5391
|
);
|
|
5175
5392
|
}
|
|
@@ -5189,7 +5406,7 @@ var Database = class {
|
|
|
5189
5406
|
const lookup = lookupFromLockFile || JSON.parse(
|
|
5190
5407
|
await this.bridge.get(
|
|
5191
5408
|
(0, import_schema_tools3.normalizePath)(
|
|
5192
|
-
|
|
5409
|
+
import_path3.default.join(this.getGeneratedFolder(), "_lookup.json")
|
|
5193
5410
|
)
|
|
5194
5411
|
)
|
|
5195
5412
|
);
|
|
@@ -5204,15 +5421,15 @@ var Database = class {
|
|
|
5204
5421
|
}
|
|
5205
5422
|
const contentRootLevel = nextLevel.sublevel(CONTENT_ROOT_PREFIX, SUBLEVEL_OPTIONS);
|
|
5206
5423
|
await contentRootLevel.put(
|
|
5207
|
-
(0, import_schema_tools3.normalizePath)(
|
|
5424
|
+
(0, import_schema_tools3.normalizePath)(import_path3.default.join(this.getGeneratedFolder(), "_graphql.json")),
|
|
5208
5425
|
graphQLSchema
|
|
5209
5426
|
);
|
|
5210
5427
|
await contentRootLevel.put(
|
|
5211
|
-
(0, import_schema_tools3.normalizePath)(
|
|
5428
|
+
(0, import_schema_tools3.normalizePath)(import_path3.default.join(this.getGeneratedFolder(), "_schema.json")),
|
|
5212
5429
|
tinaSchema.schema
|
|
5213
5430
|
);
|
|
5214
5431
|
await contentRootLevel.put(
|
|
5215
|
-
(0, import_schema_tools3.normalizePath)(
|
|
5432
|
+
(0, import_schema_tools3.normalizePath)(import_path3.default.join(this.getGeneratedFolder(), "_lookup.json")),
|
|
5216
5433
|
lookup
|
|
5217
5434
|
);
|
|
5218
5435
|
const result = await this._indexAllContent(
|
|
@@ -5253,7 +5470,9 @@ var Database = class {
|
|
|
5253
5470
|
collections[collection]
|
|
5254
5471
|
);
|
|
5255
5472
|
}
|
|
5256
|
-
|
|
5473
|
+
if (nonCollectionPaths.length) {
|
|
5474
|
+
await _deleteIndexContent(this, nonCollectionPaths, enqueueOps, null);
|
|
5475
|
+
}
|
|
5257
5476
|
});
|
|
5258
5477
|
while (operations.length) {
|
|
5259
5478
|
await this.level.batch(operations.splice(0, 25));
|
|
@@ -5304,6 +5523,11 @@ var Database = class {
|
|
|
5304
5523
|
);
|
|
5305
5524
|
const item = await rootSublevel.get(itemKey);
|
|
5306
5525
|
if (item) {
|
|
5526
|
+
const folderTreeBuilder = new FolderTreeBuilder();
|
|
5527
|
+
const folderKey = folderTreeBuilder.update(
|
|
5528
|
+
filepath,
|
|
5529
|
+
collection.path || ""
|
|
5530
|
+
);
|
|
5307
5531
|
await this.level.batch([
|
|
5308
5532
|
...makeIndexOpsForDocument(
|
|
5309
5533
|
filepath,
|
|
@@ -5313,6 +5537,14 @@ var Database = class {
|
|
|
5313
5537
|
"del",
|
|
5314
5538
|
this.level
|
|
5315
5539
|
),
|
|
5540
|
+
...makeIndexOpsForDocument(
|
|
5541
|
+
filepath,
|
|
5542
|
+
`${collection.name}_${folderKey}`,
|
|
5543
|
+
collectionIndexDefinitions,
|
|
5544
|
+
item,
|
|
5545
|
+
"del",
|
|
5546
|
+
this.level
|
|
5547
|
+
),
|
|
5316
5548
|
{
|
|
5317
5549
|
type: "del",
|
|
5318
5550
|
key: itemKey,
|
|
@@ -5344,17 +5576,17 @@ var Database = class {
|
|
|
5344
5576
|
const documentPaths = await this.bridge.glob(normalPath, format);
|
|
5345
5577
|
const matches = this.tinaSchema.getMatches({ collection });
|
|
5346
5578
|
const filteredPaths = matches.length > 0 ? (0, import_micromatch.default)(documentPaths, matches) : documentPaths;
|
|
5347
|
-
filteredPaths.forEach((
|
|
5348
|
-
if (filesSeen.has(
|
|
5349
|
-
filesSeen.get(
|
|
5350
|
-
duplicateFiles.add(
|
|
5579
|
+
filteredPaths.forEach((path5) => {
|
|
5580
|
+
if (filesSeen.has(path5)) {
|
|
5581
|
+
filesSeen.get(path5).push(collection.name);
|
|
5582
|
+
duplicateFiles.add(path5);
|
|
5351
5583
|
} else {
|
|
5352
|
-
filesSeen.set(
|
|
5584
|
+
filesSeen.set(path5, [collection.name]);
|
|
5353
5585
|
}
|
|
5354
5586
|
});
|
|
5355
|
-
duplicateFiles.forEach((
|
|
5587
|
+
duplicateFiles.forEach((path5) => {
|
|
5356
5588
|
warnings.push(
|
|
5357
|
-
`"${
|
|
5589
|
+
`"${path5}" Found in multiple collections: ${filesSeen.get(path5).map((collection2) => `"${collection2}"`).join(
|
|
5358
5590
|
", "
|
|
5359
5591
|
)}. This can cause unexpected behavior. We recommend updating the \`match\` property of those collections so that each file is in only one collection.
|
|
5360
5592
|
This will be an error in the future. See https://tina.io/docs/errors/file-in-mutpliple-collections/
|
|
@@ -5372,7 +5604,7 @@ This will be an error in the future. See https://tina.io/docs/errors/file-in-mut
|
|
|
5372
5604
|
if (!this.bridge) {
|
|
5373
5605
|
throw new Error("No bridge configured");
|
|
5374
5606
|
}
|
|
5375
|
-
const lookupPath =
|
|
5607
|
+
const lookupPath = import_path3.default.join(this.getGeneratedFolder(), `_lookup.json`);
|
|
5376
5608
|
let lookupMap;
|
|
5377
5609
|
try {
|
|
5378
5610
|
lookupMap = JSON.parse(await this.bridge.get((0, import_schema_tools3.normalizePath)(lookupPath)));
|
|
@@ -5490,24 +5722,27 @@ function hasOwnProperty(obj, prop) {
|
|
|
5490
5722
|
}
|
|
5491
5723
|
var _indexContent = async (database, level, documentPaths, enqueueOps, collection) => {
|
|
5492
5724
|
let collectionIndexDefinitions;
|
|
5725
|
+
let collectionPath;
|
|
5493
5726
|
if (collection) {
|
|
5494
5727
|
const indexDefinitions = await database.getIndexDefinitions(level);
|
|
5495
5728
|
collectionIndexDefinitions = indexDefinitions == null ? void 0 : indexDefinitions[collection.name];
|
|
5496
5729
|
if (!collectionIndexDefinitions) {
|
|
5497
5730
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
5498
5731
|
}
|
|
5732
|
+
collectionPath = collection.path;
|
|
5499
5733
|
}
|
|
5500
5734
|
const tinaSchema = await database.getSchema();
|
|
5501
5735
|
let templateInfo = null;
|
|
5502
5736
|
if (collection) {
|
|
5503
5737
|
templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
|
|
5504
5738
|
}
|
|
5739
|
+
const folderTreeBuilder = new FolderTreeBuilder();
|
|
5505
5740
|
await sequential(documentPaths, async (filepath) => {
|
|
5506
5741
|
try {
|
|
5507
5742
|
const dataString = await database.bridge.get((0, import_schema_tools3.normalizePath)(filepath));
|
|
5508
5743
|
const data = parseFile(
|
|
5509
5744
|
dataString,
|
|
5510
|
-
|
|
5745
|
+
import_path3.default.extname(filepath),
|
|
5511
5746
|
(yup3) => yup3.object({}),
|
|
5512
5747
|
{
|
|
5513
5748
|
frontmatterDelimiters: collection == null ? void 0 : collection.frontmatterDelimiters,
|
|
@@ -5522,6 +5757,10 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5522
5757
|
return;
|
|
5523
5758
|
}
|
|
5524
5759
|
const normalizedPath = (0, import_schema_tools3.normalizePath)(filepath);
|
|
5760
|
+
const folderKey = folderTreeBuilder.update(
|
|
5761
|
+
normalizedPath,
|
|
5762
|
+
collectionPath || ""
|
|
5763
|
+
);
|
|
5525
5764
|
const aliasedData = templateInfo ? replaceNameOverrides(template, data) : data;
|
|
5526
5765
|
await enqueueOps([
|
|
5527
5766
|
...makeIndexOpsForDocument(
|
|
@@ -5532,6 +5771,14 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5532
5771
|
"put",
|
|
5533
5772
|
level
|
|
5534
5773
|
),
|
|
5774
|
+
...makeIndexOpsForDocument(
|
|
5775
|
+
normalizedPath,
|
|
5776
|
+
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
5777
|
+
collectionIndexDefinitions,
|
|
5778
|
+
aliasedData,
|
|
5779
|
+
"put",
|
|
5780
|
+
level
|
|
5781
|
+
),
|
|
5535
5782
|
{
|
|
5536
5783
|
type: "put",
|
|
5537
5784
|
key: normalizedPath,
|
|
@@ -5551,8 +5798,22 @@ var _indexContent = async (database, level, documentPaths, enqueueOps, collectio
|
|
|
5551
5798
|
});
|
|
5552
5799
|
}
|
|
5553
5800
|
});
|
|
5801
|
+
if (collection) {
|
|
5802
|
+
await enqueueOps(
|
|
5803
|
+
makeFolderOpsForCollection(
|
|
5804
|
+
folderTreeBuilder.tree,
|
|
5805
|
+
collection,
|
|
5806
|
+
collectionIndexDefinitions,
|
|
5807
|
+
"put",
|
|
5808
|
+
level
|
|
5809
|
+
)
|
|
5810
|
+
);
|
|
5811
|
+
}
|
|
5554
5812
|
};
|
|
5555
|
-
var _deleteIndexContent = async (database, documentPaths,
|
|
5813
|
+
var _deleteIndexContent = async (database, documentPaths, enqueueOps, collection) => {
|
|
5814
|
+
if (!documentPaths.length) {
|
|
5815
|
+
return;
|
|
5816
|
+
}
|
|
5556
5817
|
let collectionIndexDefinitions;
|
|
5557
5818
|
if (collection) {
|
|
5558
5819
|
const indexDefinitions = await database.getIndexDefinitions(database.level);
|
|
@@ -5561,20 +5822,42 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
|
|
|
5561
5822
|
throw new Error(`No indexDefinitions for collection ${collection.name}`);
|
|
5562
5823
|
}
|
|
5563
5824
|
}
|
|
5825
|
+
const tinaSchema = await database.getSchema();
|
|
5826
|
+
let templateInfo = null;
|
|
5827
|
+
if (collection) {
|
|
5828
|
+
templateInfo = await tinaSchema.getTemplatesForCollectable(collection);
|
|
5829
|
+
}
|
|
5564
5830
|
const rootLevel = database.level.sublevel(
|
|
5565
5831
|
CONTENT_ROOT_PREFIX,
|
|
5566
5832
|
SUBLEVEL_OPTIONS
|
|
5567
5833
|
);
|
|
5834
|
+
const folderTreeBuilder = new FolderTreeBuilder();
|
|
5568
5835
|
await sequential(documentPaths, async (filepath) => {
|
|
5569
5836
|
const itemKey = (0, import_schema_tools3.normalizePath)(filepath);
|
|
5570
5837
|
const item = await rootLevel.get(itemKey);
|
|
5571
5838
|
if (item) {
|
|
5572
|
-
|
|
5839
|
+
const folderKey = folderTreeBuilder.update(
|
|
5840
|
+
itemKey,
|
|
5841
|
+
(collection == null ? void 0 : collection.path) || ""
|
|
5842
|
+
);
|
|
5843
|
+
const aliasedData = templateInfo ? replaceNameOverrides(
|
|
5844
|
+
getTemplateForFile(templateInfo, item),
|
|
5845
|
+
item
|
|
5846
|
+
) : item;
|
|
5847
|
+
await enqueueOps([
|
|
5573
5848
|
...makeIndexOpsForDocument(
|
|
5574
5849
|
itemKey,
|
|
5575
5850
|
collection.name,
|
|
5576
5851
|
collectionIndexDefinitions,
|
|
5577
|
-
|
|
5852
|
+
aliasedData,
|
|
5853
|
+
"del",
|
|
5854
|
+
database.level
|
|
5855
|
+
),
|
|
5856
|
+
...makeIndexOpsForDocument(
|
|
5857
|
+
itemKey,
|
|
5858
|
+
`${collection == null ? void 0 : collection.name}_${folderKey}`,
|
|
5859
|
+
collectionIndexDefinitions,
|
|
5860
|
+
aliasedData,
|
|
5578
5861
|
"del",
|
|
5579
5862
|
database.level
|
|
5580
5863
|
),
|
|
@@ -5582,6 +5865,17 @@ var _deleteIndexContent = async (database, documentPaths, enequeueOps, collectio
|
|
|
5582
5865
|
]);
|
|
5583
5866
|
}
|
|
5584
5867
|
});
|
|
5868
|
+
if (collectionIndexDefinitions) {
|
|
5869
|
+
await enqueueOps(
|
|
5870
|
+
makeFolderOpsForCollection(
|
|
5871
|
+
folderTreeBuilder.tree,
|
|
5872
|
+
collection,
|
|
5873
|
+
collectionIndexDefinitions,
|
|
5874
|
+
"del",
|
|
5875
|
+
database.level
|
|
5876
|
+
)
|
|
5877
|
+
);
|
|
5878
|
+
}
|
|
5585
5879
|
};
|
|
5586
5880
|
var getTemplateForFile = (templateInfo, data) => {
|
|
5587
5881
|
if (templateInfo.type === "object") {
|
|
@@ -5629,7 +5923,7 @@ var TinaLevelClient = class extends import_many_level.ManyLevelGuest {
|
|
|
5629
5923
|
// src/database/bridge/filesystem.ts
|
|
5630
5924
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
5631
5925
|
var import_fast_glob = __toESM(require("fast-glob"));
|
|
5632
|
-
var
|
|
5926
|
+
var import_path4 = __toESM(require("path"));
|
|
5633
5927
|
var import_normalize_path = __toESM(require("normalize-path"));
|
|
5634
5928
|
var FilesystemBridge = class {
|
|
5635
5929
|
constructor(rootPath, outputPath) {
|
|
@@ -5637,9 +5931,9 @@ var FilesystemBridge = class {
|
|
|
5637
5931
|
this.outputPath = outputPath || rootPath;
|
|
5638
5932
|
}
|
|
5639
5933
|
async glob(pattern, extension) {
|
|
5640
|
-
const basePath =
|
|
5934
|
+
const basePath = import_path4.default.join(this.outputPath, ...pattern.split("/"));
|
|
5641
5935
|
const items = await (0, import_fast_glob.default)(
|
|
5642
|
-
|
|
5936
|
+
import_path4.default.join(basePath, "**", `/*${extension}`).replace(/\\/g, "/"),
|
|
5643
5937
|
{
|
|
5644
5938
|
dot: true
|
|
5645
5939
|
}
|
|
@@ -5653,10 +5947,10 @@ var FilesystemBridge = class {
|
|
|
5653
5947
|
return true;
|
|
5654
5948
|
}
|
|
5655
5949
|
async delete(filepath) {
|
|
5656
|
-
await import_fs_extra.default.remove(
|
|
5950
|
+
await import_fs_extra.default.remove(import_path4.default.join(this.outputPath, filepath));
|
|
5657
5951
|
}
|
|
5658
5952
|
async get(filepath) {
|
|
5659
|
-
return import_fs_extra.default.readFileSync(
|
|
5953
|
+
return import_fs_extra.default.readFileSync(import_path4.default.join(this.outputPath, filepath)).toString();
|
|
5660
5954
|
}
|
|
5661
5955
|
async putConfig(filepath, data) {
|
|
5662
5956
|
if (this.rootPath !== this.outputPath) {
|
|
@@ -5668,7 +5962,7 @@ var FilesystemBridge = class {
|
|
|
5668
5962
|
}
|
|
5669
5963
|
async put(filepath, data, basePathOverride) {
|
|
5670
5964
|
const basePath = basePathOverride || this.outputPath;
|
|
5671
|
-
await import_fs_extra.default.outputFileSync(
|
|
5965
|
+
await import_fs_extra.default.outputFileSync(import_path4.default.join(basePath, filepath), data);
|
|
5672
5966
|
}
|
|
5673
5967
|
};
|
|
5674
5968
|
var AuditFileSystemBridge = class extends FilesystemBridge {
|
|
@@ -5690,7 +5984,7 @@ var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
|
5690
5984
|
var import_glob_parent = __toESM(require("glob-parent"));
|
|
5691
5985
|
var import_normalize_path2 = __toESM(require("normalize-path"));
|
|
5692
5986
|
var import_graphql6 = require("graphql");
|
|
5693
|
-
var
|
|
5987
|
+
var import_path5 = require("path");
|
|
5694
5988
|
var flat = typeof Array.prototype.flat === "undefined" ? (entries) => entries.reduce((acc, x) => acc.concat(x), []) : (entries) => entries.flat();
|
|
5695
5989
|
var toUint8Array = (buf) => {
|
|
5696
5990
|
const ab = new ArrayBuffer(buf.length);
|
|
@@ -5749,7 +6043,7 @@ var IsomorphicBridge = class {
|
|
|
5749
6043
|
async listEntries({
|
|
5750
6044
|
pattern,
|
|
5751
6045
|
entry,
|
|
5752
|
-
path:
|
|
6046
|
+
path: path5,
|
|
5753
6047
|
results
|
|
5754
6048
|
}) {
|
|
5755
6049
|
const treeResult = await import_isomorphic_git.default.readTree({
|
|
@@ -5759,7 +6053,7 @@ var IsomorphicBridge = class {
|
|
|
5759
6053
|
});
|
|
5760
6054
|
const children = [];
|
|
5761
6055
|
for (const childEntry of treeResult.tree) {
|
|
5762
|
-
const childPath =
|
|
6056
|
+
const childPath = path5 ? `${path5}/${childEntry.path}` : childEntry.path;
|
|
5763
6057
|
if (childEntry.type === "tree") {
|
|
5764
6058
|
children.push(childEntry);
|
|
5765
6059
|
} else {
|
|
@@ -5769,7 +6063,7 @@ var IsomorphicBridge = class {
|
|
|
5769
6063
|
}
|
|
5770
6064
|
}
|
|
5771
6065
|
for (const childEntry of children) {
|
|
5772
|
-
const childPath =
|
|
6066
|
+
const childPath = path5 ? `${path5}/${childEntry.path}` : childEntry.path;
|
|
5773
6067
|
await this.listEntries({
|
|
5774
6068
|
pattern,
|
|
5775
6069
|
entry: childEntry,
|
|
@@ -5778,17 +6072,17 @@ var IsomorphicBridge = class {
|
|
|
5778
6072
|
});
|
|
5779
6073
|
}
|
|
5780
6074
|
}
|
|
5781
|
-
async resolvePathEntries(
|
|
5782
|
-
let pathParts =
|
|
6075
|
+
async resolvePathEntries(path5, ref) {
|
|
6076
|
+
let pathParts = path5.split("/");
|
|
5783
6077
|
const result = await import_isomorphic_git.default.walk({
|
|
5784
6078
|
...this.isomorphicConfig,
|
|
5785
6079
|
map: async (filepath, [head]) => {
|
|
5786
6080
|
if (head._fullpath === ".") {
|
|
5787
6081
|
return head;
|
|
5788
6082
|
}
|
|
5789
|
-
if (
|
|
5790
|
-
if ((0,
|
|
5791
|
-
if (
|
|
6083
|
+
if (path5.startsWith(filepath)) {
|
|
6084
|
+
if ((0, import_path5.dirname)(path5) === (0, import_path5.dirname)(filepath)) {
|
|
6085
|
+
if (path5 === filepath) {
|
|
5792
6086
|
return head;
|
|
5793
6087
|
}
|
|
5794
6088
|
} else {
|
|
@@ -5808,7 +6102,7 @@ var IsomorphicBridge = class {
|
|
|
5808
6102
|
}
|
|
5809
6103
|
return { pathParts, pathEntries };
|
|
5810
6104
|
}
|
|
5811
|
-
async updateTreeHierarchy(existingOid, updatedOid,
|
|
6105
|
+
async updateTreeHierarchy(existingOid, updatedOid, path5, type, pathEntries, pathParts) {
|
|
5812
6106
|
const lastIdx = pathEntries.length - 1;
|
|
5813
6107
|
const parentEntry = pathEntries[lastIdx];
|
|
5814
6108
|
const parentPath = pathParts[lastIdx];
|
|
@@ -5823,7 +6117,7 @@ var IsomorphicBridge = class {
|
|
|
5823
6117
|
cache: this.cache
|
|
5824
6118
|
});
|
|
5825
6119
|
tree = existingOid ? treeResult.tree.map((entry) => {
|
|
5826
|
-
if (entry.path ===
|
|
6120
|
+
if (entry.path === path5) {
|
|
5827
6121
|
entry.oid = updatedOid;
|
|
5828
6122
|
}
|
|
5829
6123
|
return entry;
|
|
@@ -5832,7 +6126,7 @@ var IsomorphicBridge = class {
|
|
|
5832
6126
|
{
|
|
5833
6127
|
oid: updatedOid,
|
|
5834
6128
|
type,
|
|
5835
|
-
path:
|
|
6129
|
+
path: path5,
|
|
5836
6130
|
mode
|
|
5837
6131
|
}
|
|
5838
6132
|
];
|
|
@@ -5841,7 +6135,7 @@ var IsomorphicBridge = class {
|
|
|
5841
6135
|
{
|
|
5842
6136
|
oid: updatedOid,
|
|
5843
6137
|
type,
|
|
5844
|
-
path:
|
|
6138
|
+
path: path5,
|
|
5845
6139
|
mode
|
|
5846
6140
|
}
|
|
5847
6141
|
];
|
|
@@ -5942,7 +6236,7 @@ var IsomorphicBridge = class {
|
|
|
5942
6236
|
path: parentPath,
|
|
5943
6237
|
results
|
|
5944
6238
|
});
|
|
5945
|
-
return results.map((
|
|
6239
|
+
return results.map((path5) => this.unqualifyPath(path5)).filter((path5) => path5.endsWith(extension));
|
|
5946
6240
|
}
|
|
5947
6241
|
supportsBuilding() {
|
|
5948
6242
|
return true;
|