@monkeyplus/flow 6.0.39 → 6.0.40
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.
|
@@ -42,8 +42,23 @@ function parseContentFile(keyPath, raw) {
|
|
|
42
42
|
const extension = extname(keyPath).toLowerCase();
|
|
43
43
|
const normalizedPath = normalizeContentPath(keyPath);
|
|
44
44
|
if (extension === ".json") {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
let parsed = {};
|
|
46
|
+
let body = raw;
|
|
47
|
+
if (typeof raw === "string") {
|
|
48
|
+
body = raw;
|
|
49
|
+
const trimmed = raw.trim();
|
|
50
|
+
if (trimmed) {
|
|
51
|
+
try {
|
|
52
|
+
parsed = JSON.parse(trimmed);
|
|
53
|
+
} catch (e) {
|
|
54
|
+
consola.warn("parseContentFile", keyPath, e);
|
|
55
|
+
parsed = {};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
parsed = raw;
|
|
60
|
+
body = JSON.stringify(raw);
|
|
61
|
+
}
|
|
47
62
|
return {
|
|
48
63
|
...normalizedPath,
|
|
49
64
|
extension,
|
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ export interface QueryContentBuilder {
|
|
|
7
7
|
select: (...fields: string[]) => QueryContentBuilder;
|
|
8
8
|
find: () => Promise<ContentEntry[]>;
|
|
9
9
|
findOne: () => Promise<ContentEntry | null>;
|
|
10
|
+
findEntries: () => Promise<Record<string, unknown>>;
|
|
10
11
|
all: () => Promise<ContentEntry[]>;
|
|
11
12
|
first: () => Promise<ContentEntry | null>;
|
|
12
13
|
surround: (targetPath: string) => Promise<[ContentEntry | null, ContentEntry | null]>;
|
|
@@ -176,6 +176,15 @@ export function queryContent(path = "") {
|
|
|
176
176
|
const entries = await this.find();
|
|
177
177
|
return entries[0] || null;
|
|
178
178
|
},
|
|
179
|
+
async findEntries() {
|
|
180
|
+
const entries = await this.find();
|
|
181
|
+
return entries.reduce((acc, curr) => {
|
|
182
|
+
return {
|
|
183
|
+
...acc,
|
|
184
|
+
[curr.name]: curr.data
|
|
185
|
+
};
|
|
186
|
+
}, {});
|
|
187
|
+
},
|
|
179
188
|
async all() {
|
|
180
189
|
return await this.find();
|
|
181
190
|
},
|