@content-collections/core 0.11.1 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.d.ts +900 -237
- package/dist/index.js +2154 -1248
- package/package.json +8 -9
package/dist/index.js
CHANGED
|
@@ -1,1386 +1,2292 @@
|
|
|
1
|
-
|
|
2
|
-
import path9 from "node:path";
|
|
3
|
-
|
|
4
|
-
// src/cache.ts
|
|
1
|
+
import path, { basename, dirname, extname, join, resolve } from "node:path";
|
|
5
2
|
import { createHash } from "node:crypto";
|
|
6
3
|
import { existsSync } from "node:fs";
|
|
7
|
-
import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
import fs, { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
5
|
+
import { readFile as readFile$1 } from "fs/promises";
|
|
6
|
+
import { glob } from "tinyglobby";
|
|
7
|
+
import matter from "gray-matter";
|
|
8
|
+
import { parse, stringify } from "yaml";
|
|
9
|
+
import camelcase from "camelcase";
|
|
10
|
+
import pluralize from "pluralize";
|
|
11
|
+
import picomatch from "picomatch";
|
|
12
|
+
import os from "node:os";
|
|
13
|
+
import pLimit from "p-limit";
|
|
14
|
+
import fs2 from "fs";
|
|
15
|
+
import path2 from "path";
|
|
16
|
+
import { build } from "esbuild";
|
|
17
|
+
import { createRequire } from "module";
|
|
18
|
+
import serializeJs from "serialize-javascript";
|
|
19
|
+
import { EventEmitter } from "node:events";
|
|
20
|
+
import chokidar from "chokidar";
|
|
21
|
+
|
|
22
|
+
//#region src/cache.ts
|
|
23
|
+
function createKey(config$1, input, key) {
|
|
24
|
+
return createHash("sha256").update(config$1).update(JSON.stringify(input)).update(key).digest("hex");
|
|
11
25
|
}
|
|
12
26
|
async function createCacheDirectory(directory) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
return cacheDirectory;
|
|
27
|
+
const cacheDirectory = path.join(directory, ".content-collections", "cache");
|
|
28
|
+
if (!existsSync(cacheDirectory)) await mkdir(cacheDirectory, { recursive: true });
|
|
29
|
+
return cacheDirectory;
|
|
18
30
|
}
|
|
19
31
|
function fileName(input) {
|
|
20
|
-
|
|
32
|
+
return input.replace(/[^a-z0-9]/gi, "_").toLowerCase();
|
|
21
33
|
}
|
|
22
34
|
async function readMapping(mappingPath) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return {};
|
|
35
|
+
if (existsSync(mappingPath)) try {
|
|
36
|
+
return JSON.parse(await readFile(mappingPath, "utf-8"));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.error("Failed to parse the cache mapping. We will recreate the cache.");
|
|
39
|
+
}
|
|
40
|
+
return {};
|
|
33
41
|
}
|
|
34
42
|
async function createCacheManager(baseDirectory, configChecksum) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
if (collectionMapping) {
|
|
89
|
-
collectionMapping[file] = newFileMapping;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
cacheFn,
|
|
94
|
-
tidyUp
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
cache,
|
|
99
|
-
flush
|
|
100
|
-
};
|
|
43
|
+
const cacheDirectory = await createCacheDirectory(baseDirectory);
|
|
44
|
+
const mappingPath = join(cacheDirectory, "mapping.json");
|
|
45
|
+
const mapping = await readMapping(mappingPath);
|
|
46
|
+
async function flush() {
|
|
47
|
+
await writeFile(mappingPath, JSON.stringify(mapping));
|
|
48
|
+
}
|
|
49
|
+
function cache(collection, file) {
|
|
50
|
+
const directory = join(cacheDirectory, fileName(collection), fileName(file));
|
|
51
|
+
let collectionMapping = mapping[collection];
|
|
52
|
+
if (!collectionMapping) {
|
|
53
|
+
collectionMapping = {};
|
|
54
|
+
mapping[collection] = collectionMapping;
|
|
55
|
+
}
|
|
56
|
+
let fileMapping = collectionMapping[file];
|
|
57
|
+
if (!fileMapping) {
|
|
58
|
+
fileMapping = [];
|
|
59
|
+
collectionMapping[file] = fileMapping;
|
|
60
|
+
}
|
|
61
|
+
let newFileMapping = [];
|
|
62
|
+
const cacheFn = async (input, fn, options) => {
|
|
63
|
+
const key = createKey(configChecksum, input, options?.key || "");
|
|
64
|
+
newFileMapping.push(key);
|
|
65
|
+
const filePath = join(directory, `${key}.cache`);
|
|
66
|
+
if (fileMapping?.includes(key) || newFileMapping.includes(key)) {
|
|
67
|
+
if (existsSync(filePath)) try {
|
|
68
|
+
return JSON.parse(await readFile(filePath, "utf-8"));
|
|
69
|
+
} catch (e) {
|
|
70
|
+
console.error("Failed to parse the cache file. We will recompute the value.");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const output = await fn(input);
|
|
74
|
+
if (!existsSync(directory)) await mkdir(directory, { recursive: true });
|
|
75
|
+
await writeFile(filePath, JSON.stringify(output));
|
|
76
|
+
return output;
|
|
77
|
+
};
|
|
78
|
+
const tidyUp = async () => {
|
|
79
|
+
const filesToDelete = fileMapping?.filter((key) => !newFileMapping.includes(key)) || [];
|
|
80
|
+
for (const key of filesToDelete) {
|
|
81
|
+
const filePath = join(directory, `${key}.cache`);
|
|
82
|
+
if (existsSync(filePath)) await unlink(filePath);
|
|
83
|
+
}
|
|
84
|
+
if (collectionMapping) collectionMapping[file] = newFileMapping;
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
cacheFn,
|
|
88
|
+
tidyUp
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
cache,
|
|
93
|
+
flush
|
|
94
|
+
};
|
|
101
95
|
}
|
|
102
96
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
import path3 from "node:path";
|
|
106
|
-
import { glob } from "tinyglobby";
|
|
107
|
-
|
|
108
|
-
// src/parser.ts
|
|
109
|
-
import matter from "gray-matter";
|
|
110
|
-
import { parse, stringify } from "yaml";
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/parser.ts
|
|
111
99
|
function parseYaml(content) {
|
|
112
|
-
|
|
100
|
+
return parse(content.trim());
|
|
113
101
|
}
|
|
114
102
|
function frontmatter(fileContent) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
stringify
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
});
|
|
103
|
+
return matter(fileContent, { engines: { yaml: {
|
|
104
|
+
parse: parseYaml,
|
|
105
|
+
stringify
|
|
106
|
+
} } });
|
|
123
107
|
}
|
|
124
108
|
function frontmatterParser(fileContent) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
109
|
+
const { data, content } = frontmatter(fileContent);
|
|
110
|
+
return {
|
|
111
|
+
...data,
|
|
112
|
+
content: content.trim()
|
|
113
|
+
};
|
|
130
114
|
}
|
|
131
115
|
function frontmatterOnlyParser(fileContent) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
116
|
+
const { data } = frontmatter(fileContent);
|
|
117
|
+
return data;
|
|
118
|
+
}
|
|
119
|
+
const parsers = {
|
|
120
|
+
frontmatter: {
|
|
121
|
+
hasContent: true,
|
|
122
|
+
parse: frontmatterParser
|
|
123
|
+
},
|
|
124
|
+
["frontmatter-only"]: {
|
|
125
|
+
hasContent: false,
|
|
126
|
+
parse: frontmatterOnlyParser
|
|
127
|
+
},
|
|
128
|
+
json: {
|
|
129
|
+
hasContent: false,
|
|
130
|
+
parse: JSON.parse
|
|
131
|
+
},
|
|
132
|
+
yaml: {
|
|
133
|
+
hasContent: false,
|
|
134
|
+
parse: parseYaml
|
|
135
|
+
}
|
|
152
136
|
};
|
|
153
137
|
function getParser(configuredParser) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
return configuredParser;
|
|
138
|
+
if (typeof configuredParser === "string") return parsers[configuredParser];
|
|
139
|
+
return configuredParser;
|
|
158
140
|
}
|
|
159
141
|
function defineParser(parser) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
return parser;
|
|
142
|
+
if (typeof parser === "function") return {
|
|
143
|
+
hasContent: false,
|
|
144
|
+
parse: parser
|
|
145
|
+
};
|
|
146
|
+
return parser;
|
|
167
147
|
}
|
|
168
148
|
function isValidParser(parser) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
return "hasContent" in parser && typeof parser.parse === "function";
|
|
149
|
+
if (typeof parser === "string") return parser in parsers;
|
|
150
|
+
return "hasContent" in parser && typeof parser.parse === "function";
|
|
173
151
|
}
|
|
174
152
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
import pluralize from "pluralize";
|
|
178
|
-
import path2 from "node:path";
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/utils.ts
|
|
179
155
|
function generateTypeName(name) {
|
|
180
|
-
|
|
181
|
-
return camelcase(singularName, { pascalCase: true });
|
|
156
|
+
return camelcase(pluralize.singular(name), { pascalCase: true });
|
|
182
157
|
}
|
|
183
158
|
function isDefined(value) {
|
|
184
|
-
|
|
159
|
+
return value !== void 0 && value !== null;
|
|
185
160
|
}
|
|
186
161
|
function orderByPath(a, b) {
|
|
187
|
-
|
|
162
|
+
return a.path.localeCompare(b.path);
|
|
188
163
|
}
|
|
189
164
|
function removeChildPaths(paths) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
return path10.startsWith(otherPath);
|
|
198
|
-
});
|
|
199
|
-
})
|
|
200
|
-
)
|
|
201
|
-
);
|
|
165
|
+
return Array.from(new Set(paths.filter((path$1) => {
|
|
166
|
+
return !paths.some((otherPath) => {
|
|
167
|
+
if (path$1 === otherPath) return false;
|
|
168
|
+
return path$1.startsWith(otherPath);
|
|
169
|
+
});
|
|
170
|
+
})));
|
|
202
171
|
}
|
|
203
172
|
function posixToNativePath(pathName) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
return pathName;
|
|
173
|
+
if (path.sep !== path.posix.sep) return pathName.replaceAll(path.posix.sep, path.sep);
|
|
174
|
+
return pathName;
|
|
208
175
|
}
|
|
209
176
|
function toError(error) {
|
|
210
|
-
|
|
177
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
211
178
|
}
|
|
212
179
|
|
|
213
|
-
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/collector.ts
|
|
214
182
|
var CollectError = class extends Error {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
183
|
+
type;
|
|
184
|
+
constructor(type, message) {
|
|
185
|
+
super(message);
|
|
186
|
+
this.type = type;
|
|
187
|
+
}
|
|
220
188
|
};
|
|
221
189
|
function createCollector(emitter, baseDirectory = ".") {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
ignore: createIgnorePattern(collection)
|
|
276
|
-
});
|
|
277
|
-
const promises = filePaths.map(
|
|
278
|
-
(filePath) => collectFile(collection, posixToNativePath(filePath))
|
|
279
|
-
);
|
|
280
|
-
const files = await Promise.all(promises);
|
|
281
|
-
return {
|
|
282
|
-
...collection,
|
|
283
|
-
files: files.filter(isDefined).sort(orderByPath)
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
async function collect(unresolvedCollections) {
|
|
287
|
-
const promises = unresolvedCollections.map(
|
|
288
|
-
(collection) => resolveCollection(collection)
|
|
289
|
-
);
|
|
290
|
-
return await Promise.all(promises);
|
|
291
|
-
}
|
|
292
|
-
return {
|
|
293
|
-
collect,
|
|
294
|
-
collectFile
|
|
295
|
-
};
|
|
190
|
+
async function read(filePath) {
|
|
191
|
+
try {
|
|
192
|
+
return await readFile$1(filePath, "utf-8");
|
|
193
|
+
} catch (error) {
|
|
194
|
+
emitter.emit("collector:read-error", {
|
|
195
|
+
filePath,
|
|
196
|
+
error: new CollectError("Read", String(error))
|
|
197
|
+
});
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
async function collectFile(collection, filePath) {
|
|
202
|
+
const file = await read(path.join(baseDirectory, collection.directory, filePath));
|
|
203
|
+
if (!file) return null;
|
|
204
|
+
try {
|
|
205
|
+
return {
|
|
206
|
+
data: await getParser(collection.parser).parse(file),
|
|
207
|
+
path: filePath
|
|
208
|
+
};
|
|
209
|
+
} catch (error) {
|
|
210
|
+
emitter.emit("collector:parse-error", {
|
|
211
|
+
filePath: path.join(collection.directory, filePath),
|
|
212
|
+
error: new CollectError("Parse", String(error))
|
|
213
|
+
});
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function createIgnorePattern(collection) {
|
|
218
|
+
if (collection.exclude) if (Array.isArray(collection.exclude)) return collection.exclude;
|
|
219
|
+
else return [collection.exclude];
|
|
220
|
+
}
|
|
221
|
+
async function resolveCollection(collection) {
|
|
222
|
+
const collectionDirectory = path.join(baseDirectory, collection.directory);
|
|
223
|
+
const promises = (await glob(Array.isArray(collection.include) ? collection.include : [collection.include], {
|
|
224
|
+
cwd: collectionDirectory,
|
|
225
|
+
onlyFiles: true,
|
|
226
|
+
absolute: false,
|
|
227
|
+
ignore: createIgnorePattern(collection)
|
|
228
|
+
})).map((filePath) => collectFile(collection, posixToNativePath(filePath)));
|
|
229
|
+
const files = await Promise.all(promises);
|
|
230
|
+
return {
|
|
231
|
+
...collection,
|
|
232
|
+
files: files.filter(isDefined).sort(orderByPath)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async function collect(unresolvedCollections) {
|
|
236
|
+
const promises = unresolvedCollections.map((collection) => resolveCollection(collection));
|
|
237
|
+
return await Promise.all(promises);
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
collect,
|
|
241
|
+
collectFile
|
|
242
|
+
};
|
|
296
243
|
}
|
|
297
244
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
import picomatch from "picomatch";
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/synchronizer.ts
|
|
301
247
|
function createSynchronizer(readCollectionFile, collections, baseDirectory = ".") {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
for (const { collection, relativePath } of resolvedCollections) {
|
|
359
|
-
const index = collection.files.findIndex(
|
|
360
|
-
(file2) => file2.path === relativePath
|
|
361
|
-
);
|
|
362
|
-
const file = await readCollectionFile(collection, relativePath);
|
|
363
|
-
if (file) {
|
|
364
|
-
changed2 = true;
|
|
365
|
-
if (index === -1) {
|
|
366
|
-
collection.files.push(file);
|
|
367
|
-
collection.files.sort(orderByPath);
|
|
368
|
-
} else {
|
|
369
|
-
collection.files[index] = file;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
return changed2;
|
|
374
|
-
}
|
|
375
|
-
return {
|
|
376
|
-
deleted,
|
|
377
|
-
changed
|
|
378
|
-
};
|
|
248
|
+
function findCollections(filePath) {
|
|
249
|
+
const resolvedFilePath = path.resolve(filePath);
|
|
250
|
+
return collections.filter((collection) => {
|
|
251
|
+
return resolvedFilePath.startsWith(path.resolve(baseDirectory, collection.directory));
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function createRelativePath(collectionPath, filePath) {
|
|
255
|
+
const resolvedCollectionPath = path.resolve(baseDirectory, collectionPath);
|
|
256
|
+
let relativePath = path.resolve(filePath).slice(resolvedCollectionPath.length);
|
|
257
|
+
if (relativePath.startsWith(path.sep)) relativePath = relativePath.slice(path.sep.length);
|
|
258
|
+
return relativePath;
|
|
259
|
+
}
|
|
260
|
+
function resolve$1(filePath) {
|
|
261
|
+
return findCollections(filePath).map((collection) => {
|
|
262
|
+
return {
|
|
263
|
+
collection,
|
|
264
|
+
relativePath: createRelativePath(collection.directory, filePath)
|
|
265
|
+
};
|
|
266
|
+
}).filter(({ collection, relativePath }) => {
|
|
267
|
+
return picomatch.isMatch(relativePath, collection.include, {
|
|
268
|
+
windows: process.platform === "win32",
|
|
269
|
+
ignore: collection.exclude
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function deleted(filePath) {
|
|
274
|
+
const resolvedCollections = resolve$1(filePath);
|
|
275
|
+
if (resolvedCollections.length === 0) return false;
|
|
276
|
+
let changed$1 = false;
|
|
277
|
+
for (const { collection, relativePath } of resolvedCollections) {
|
|
278
|
+
const index = collection.files.findIndex((file) => file.path === relativePath);
|
|
279
|
+
if (collection.files.splice(index, 1).length > 0) changed$1 = true;
|
|
280
|
+
}
|
|
281
|
+
return changed$1;
|
|
282
|
+
}
|
|
283
|
+
async function changed(filePath) {
|
|
284
|
+
const resolvedCollections = resolve$1(filePath);
|
|
285
|
+
if (resolvedCollections.length === 0) return false;
|
|
286
|
+
let changed$1 = false;
|
|
287
|
+
for (const { collection, relativePath } of resolvedCollections) {
|
|
288
|
+
const index = collection.files.findIndex((file$1) => file$1.path === relativePath);
|
|
289
|
+
const file = await readCollectionFile(collection, relativePath);
|
|
290
|
+
if (file) {
|
|
291
|
+
changed$1 = true;
|
|
292
|
+
if (index === -1) {
|
|
293
|
+
collection.files.push(file);
|
|
294
|
+
collection.files.sort(orderByPath);
|
|
295
|
+
} else collection.files[index] = file;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return changed$1;
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
deleted,
|
|
302
|
+
changed
|
|
303
|
+
};
|
|
379
304
|
}
|
|
380
305
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
import { basename, dirname as dirname2, extname, join as join3 } from "node:path";
|
|
384
|
-
import pLimit from "p-limit";
|
|
385
|
-
|
|
386
|
-
// src/config.ts
|
|
387
|
-
import { z } from "zod";
|
|
388
|
-
|
|
389
|
-
// src/warn.ts
|
|
390
|
-
var deprecations = {
|
|
391
|
-
legacySchema: `The use of a function as a schema is deprecated.
|
|
392
|
-
Please use a StandardSchema compliant library directly.
|
|
393
|
-
For more information, see:
|
|
394
|
-
https://content-collections.dev/docs/deprecations/schema-as-function`
|
|
395
|
-
};
|
|
396
|
-
var _suppressDeprecatedWarnings = [];
|
|
397
|
-
function suppressDeprecatedWarnings(...suppresses) {
|
|
398
|
-
for (const deprecation of suppresses) {
|
|
399
|
-
if (deprecation === "all") {
|
|
400
|
-
_suppressDeprecatedWarnings.push(
|
|
401
|
-
...Object.keys(deprecations)
|
|
402
|
-
);
|
|
403
|
-
return;
|
|
404
|
-
} else {
|
|
405
|
-
_suppressDeprecatedWarnings.push(deprecation);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
function warnDeprecated(deprecation, logger = console.warn) {
|
|
410
|
-
if (_suppressDeprecatedWarnings.includes(deprecation)) {
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
logger(`[CC DEPRECATED]: ${deprecations[deprecation]}`);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// src/configurationReader.ts
|
|
417
|
-
import { createHash as createHash2 } from "node:crypto";
|
|
418
|
-
import { existsSync as existsSync2 } from "node:fs";
|
|
419
|
-
import fs2 from "node:fs/promises";
|
|
420
|
-
import path6 from "node:path";
|
|
421
|
-
|
|
422
|
-
// ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.25.6/node_modules/bundle-require/dist/index.js
|
|
423
|
-
import {
|
|
424
|
-
build,
|
|
425
|
-
context
|
|
426
|
-
} from "esbuild";
|
|
427
|
-
|
|
428
|
-
// ../../node_modules/.pnpm/load-tsconfig@0.2.5/node_modules/load-tsconfig/dist/index.js
|
|
429
|
-
import path5 from "path";
|
|
430
|
-
import fs from "fs";
|
|
431
|
-
import { createRequire } from "module";
|
|
306
|
+
//#endregion
|
|
307
|
+
//#region ../../node_modules/.pnpm/load-tsconfig@0.2.5/node_modules/load-tsconfig/dist/index.js
|
|
432
308
|
var singleComment = Symbol("singleComment");
|
|
433
309
|
var multiComment = Symbol("multiComment");
|
|
434
310
|
var stripWithoutWhitespace = () => "";
|
|
435
|
-
var stripWithWhitespace = (string, start, end) => string.slice(start, end).replace(/\S/g, " ");
|
|
311
|
+
var stripWithWhitespace = (string$2, start, end) => string$2.slice(start, end).replace(/\S/g, " ");
|
|
436
312
|
var isEscaped = (jsonString, quotePosition) => {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
313
|
+
let index = quotePosition - 1;
|
|
314
|
+
let backslashCount = 0;
|
|
315
|
+
while (jsonString[index] === "\\") {
|
|
316
|
+
index -= 1;
|
|
317
|
+
backslashCount += 1;
|
|
318
|
+
}
|
|
319
|
+
return Boolean(backslashCount % 2);
|
|
444
320
|
};
|
|
445
321
|
function stripJsonComments(jsonString, { whitespace = true, trailingCommas = false } = {}) {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
buffer = "";
|
|
511
|
-
offset = index;
|
|
512
|
-
commaIndex = index;
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
return result + buffer + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
|
|
322
|
+
if (typeof jsonString !== "string") throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof jsonString}\``);
|
|
323
|
+
const strip = whitespace ? stripWithWhitespace : stripWithoutWhitespace;
|
|
324
|
+
let isInsideString = false;
|
|
325
|
+
let isInsideComment = false;
|
|
326
|
+
let offset = 0;
|
|
327
|
+
let buffer = "";
|
|
328
|
+
let result = "";
|
|
329
|
+
let commaIndex = -1;
|
|
330
|
+
for (let index = 0; index < jsonString.length; index++) {
|
|
331
|
+
const currentCharacter = jsonString[index];
|
|
332
|
+
const nextCharacter = jsonString[index + 1];
|
|
333
|
+
if (!isInsideComment && currentCharacter === "\"") {
|
|
334
|
+
if (!isEscaped(jsonString, index)) isInsideString = !isInsideString;
|
|
335
|
+
}
|
|
336
|
+
if (isInsideString) continue;
|
|
337
|
+
if (!isInsideComment && currentCharacter + nextCharacter === "//") {
|
|
338
|
+
buffer += jsonString.slice(offset, index);
|
|
339
|
+
offset = index;
|
|
340
|
+
isInsideComment = singleComment;
|
|
341
|
+
index++;
|
|
342
|
+
} else if (isInsideComment === singleComment && currentCharacter + nextCharacter === "\r\n") {
|
|
343
|
+
index++;
|
|
344
|
+
isInsideComment = false;
|
|
345
|
+
buffer += strip(jsonString, offset, index);
|
|
346
|
+
offset = index;
|
|
347
|
+
continue;
|
|
348
|
+
} else if (isInsideComment === singleComment && currentCharacter === "\n") {
|
|
349
|
+
isInsideComment = false;
|
|
350
|
+
buffer += strip(jsonString, offset, index);
|
|
351
|
+
offset = index;
|
|
352
|
+
} else if (!isInsideComment && currentCharacter + nextCharacter === "/*") {
|
|
353
|
+
buffer += jsonString.slice(offset, index);
|
|
354
|
+
offset = index;
|
|
355
|
+
isInsideComment = multiComment;
|
|
356
|
+
index++;
|
|
357
|
+
continue;
|
|
358
|
+
} else if (isInsideComment === multiComment && currentCharacter + nextCharacter === "*/") {
|
|
359
|
+
index++;
|
|
360
|
+
isInsideComment = false;
|
|
361
|
+
buffer += strip(jsonString, offset, index + 1);
|
|
362
|
+
offset = index + 1;
|
|
363
|
+
continue;
|
|
364
|
+
} else if (trailingCommas && !isInsideComment) {
|
|
365
|
+
if (commaIndex !== -1) {
|
|
366
|
+
if (currentCharacter === "}" || currentCharacter === "]") {
|
|
367
|
+
buffer += jsonString.slice(offset, index);
|
|
368
|
+
result += strip(buffer, 0, 1) + buffer.slice(1);
|
|
369
|
+
buffer = "";
|
|
370
|
+
offset = index;
|
|
371
|
+
commaIndex = -1;
|
|
372
|
+
} else if (currentCharacter !== " " && currentCharacter !== " " && currentCharacter !== "\r" && currentCharacter !== "\n") {
|
|
373
|
+
buffer += jsonString.slice(offset, index);
|
|
374
|
+
offset = index;
|
|
375
|
+
commaIndex = -1;
|
|
376
|
+
}
|
|
377
|
+
} else if (currentCharacter === ",") {
|
|
378
|
+
result += buffer + jsonString.slice(offset, index);
|
|
379
|
+
buffer = "";
|
|
380
|
+
offset = index;
|
|
381
|
+
commaIndex = index;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return result + buffer + (isInsideComment ? strip(jsonString.slice(offset)) : jsonString.slice(offset));
|
|
517
386
|
}
|
|
518
387
|
function jsoncParse(data) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}
|
|
525
|
-
var req =
|
|
526
|
-
var findUp = (name, startDir, stopDir =
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
}
|
|
539
|
-
return null;
|
|
388
|
+
try {
|
|
389
|
+
return new Function("return " + stripJsonComments(data).trim())();
|
|
390
|
+
} catch (_) {
|
|
391
|
+
return {};
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
var req = createRequire(import.meta.url);
|
|
395
|
+
var findUp = (name, startDir, stopDir = path2.parse(startDir).root) => {
|
|
396
|
+
let dir = startDir;
|
|
397
|
+
while (dir !== stopDir) {
|
|
398
|
+
const file = path2.join(dir, name);
|
|
399
|
+
if (fs2.existsSync(file)) return file;
|
|
400
|
+
if (!file.endsWith(".json")) {
|
|
401
|
+
const fileWithExt = file + ".json";
|
|
402
|
+
if (fs2.existsSync(fileWithExt)) return fileWithExt;
|
|
403
|
+
}
|
|
404
|
+
dir = path2.dirname(dir);
|
|
405
|
+
}
|
|
406
|
+
return null;
|
|
540
407
|
};
|
|
541
408
|
var resolveTsConfigFromFile = (cwd, filename) => {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
return findUp(filename, cwd);
|
|
409
|
+
if (path2.isAbsolute(filename)) return fs2.existsSync(filename) ? filename : null;
|
|
410
|
+
return findUp(filename, cwd);
|
|
545
411
|
};
|
|
546
412
|
var resolveTsConfigFromExtends = (cwd, name) => {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
return findUp(name, cwd);
|
|
551
|
-
const id = req.resolve(name, { paths: [cwd] });
|
|
552
|
-
return id;
|
|
413
|
+
if (path2.isAbsolute(name)) return fs2.existsSync(name) ? name : null;
|
|
414
|
+
if (name.startsWith(".")) return findUp(name, cwd);
|
|
415
|
+
return req.resolve(name, { paths: [cwd] });
|
|
553
416
|
};
|
|
554
417
|
var loadTsConfigInternal = (dir = process.cwd(), name = "tsconfig.json", isExtends = false) => {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
delete data.extends;
|
|
595
|
-
return { path: id, data, files: [...extendsFiles, id] };
|
|
418
|
+
var _a, _b;
|
|
419
|
+
dir = path2.resolve(dir);
|
|
420
|
+
const id = isExtends ? resolveTsConfigFromExtends(dir, name) : resolveTsConfigFromFile(dir, name);
|
|
421
|
+
if (!id) return null;
|
|
422
|
+
const data = jsoncParse(fs2.readFileSync(id, "utf-8"));
|
|
423
|
+
const configDir = path2.dirname(id);
|
|
424
|
+
if ((_a = data.compilerOptions) == null ? void 0 : _a.baseUrl) data.compilerOptions.baseUrl = path2.join(configDir, data.compilerOptions.baseUrl);
|
|
425
|
+
let extendsFiles = [];
|
|
426
|
+
if (data.extends) {
|
|
427
|
+
const extendsList = Array.isArray(data.extends) ? data.extends : [data.extends];
|
|
428
|
+
const extendsData = {};
|
|
429
|
+
for (const name2 of extendsList) {
|
|
430
|
+
const parentConfig = loadTsConfigInternal(configDir, name2, true);
|
|
431
|
+
if (parentConfig) {
|
|
432
|
+
Object.assign(extendsData, {
|
|
433
|
+
...parentConfig == null ? void 0 : parentConfig.data,
|
|
434
|
+
compilerOptions: {
|
|
435
|
+
...extendsData.compilerOptions,
|
|
436
|
+
...(_b = parentConfig == null ? void 0 : parentConfig.data) == null ? void 0 : _b.compilerOptions
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
extendsFiles.push(...parentConfig.files);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
Object.assign(data, {
|
|
443
|
+
...extendsData,
|
|
444
|
+
...data,
|
|
445
|
+
compilerOptions: {
|
|
446
|
+
...extendsData.compilerOptions,
|
|
447
|
+
...data.compilerOptions
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
delete data.extends;
|
|
452
|
+
return {
|
|
453
|
+
path: id,
|
|
454
|
+
data,
|
|
455
|
+
files: [...extendsFiles, id]
|
|
456
|
+
};
|
|
596
457
|
};
|
|
597
458
|
var loadTsConfig = (dir, name) => loadTsConfigInternal(dir, name);
|
|
598
459
|
|
|
599
|
-
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region ../../node_modules/.pnpm/bundle-require@5.0.0_esbuild@0.25.11/node_modules/bundle-require/dist/index.js
|
|
600
462
|
var tsconfigPathsToRegExp = (paths) => {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
463
|
+
return Object.keys(paths || {}).map((key) => {
|
|
464
|
+
return /* @__PURE__ */ new RegExp(`^${key.replace(/\*/, ".*")}$`);
|
|
465
|
+
});
|
|
604
466
|
};
|
|
605
467
|
var match = (id, patterns) => {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
return id === p || id.startsWith(p + "/");
|
|
613
|
-
});
|
|
468
|
+
if (!patterns) return false;
|
|
469
|
+
return patterns.some((p) => {
|
|
470
|
+
if (p instanceof RegExp) return p.test(id);
|
|
471
|
+
return id === p || id.startsWith(p + "/");
|
|
472
|
+
});
|
|
614
473
|
};
|
|
615
474
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
import { dirname, join as join2 } from "node:path";
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/esbuild.ts
|
|
619
477
|
function tsconfigResolvePaths(configPath) {
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
478
|
+
let tsconfig = loadTsConfig(dirname(configPath));
|
|
479
|
+
if (!tsconfig) tsconfig = loadTsConfig();
|
|
480
|
+
return tsconfig?.data?.compilerOptions?.paths || {};
|
|
481
|
+
}
|
|
482
|
+
const NON_NODE_MODULE_RE = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
|
|
483
|
+
function isCoreImport(path$1, kind) {
|
|
484
|
+
return path$1 === "@content-collections/core" && kind === "import-statement";
|
|
625
485
|
}
|
|
626
|
-
var NON_NODE_MODULE_RE = /^[A-Z]:[/\\]|^\.{0,2}\/|^\.{1,2}$/;
|
|
627
486
|
function createExternalsPlugin(configPath) {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
setup(build4) {
|
|
653
|
-
build4.onResolve({ filter: /^\@content-collections\/core$/ }, () => {
|
|
654
|
-
return { path: join2(__dirname, "index.ts"), external: true };
|
|
655
|
-
});
|
|
656
|
-
}
|
|
657
|
-
};
|
|
487
|
+
const resolvePatterns = tsconfigPathsToRegExp(tsconfigResolvePaths(configPath));
|
|
488
|
+
return {
|
|
489
|
+
name: "external-packages",
|
|
490
|
+
setup: (build$2) => {
|
|
491
|
+
build$2.onResolve({ filter: /.*/ }, ({ path: path$1, kind }) => {
|
|
492
|
+
if (process.env.NODE_ENV === "test" && isCoreImport(path$1, kind)) return {
|
|
493
|
+
path: join(__dirname, "index.ts"),
|
|
494
|
+
external: true
|
|
495
|
+
};
|
|
496
|
+
if (match(path$1, resolvePatterns)) {
|
|
497
|
+
if (kind === "dynamic-import") return {
|
|
498
|
+
path: path$1,
|
|
499
|
+
external: true
|
|
500
|
+
};
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (!NON_NODE_MODULE_RE.test(path$1)) return {
|
|
504
|
+
path: path$1,
|
|
505
|
+
external: true
|
|
506
|
+
};
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
}
|
|
658
511
|
async function compile(configurationPath, outfile) {
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
outfile,
|
|
671
|
-
metafile: true
|
|
672
|
-
});
|
|
673
|
-
return Object.keys(result.metafile.inputs);
|
|
512
|
+
const result = await build({
|
|
513
|
+
entryPoints: [configurationPath],
|
|
514
|
+
packages: "external",
|
|
515
|
+
bundle: true,
|
|
516
|
+
platform: "node",
|
|
517
|
+
format: "esm",
|
|
518
|
+
plugins: [createExternalsPlugin(configurationPath)],
|
|
519
|
+
outfile,
|
|
520
|
+
metafile: true
|
|
521
|
+
});
|
|
522
|
+
return Object.keys(result.metafile.inputs);
|
|
674
523
|
}
|
|
675
524
|
|
|
676
|
-
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/configurationReader.ts
|
|
677
527
|
var ConfigurationError = class extends Error {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
528
|
+
type;
|
|
529
|
+
constructor(type, message) {
|
|
530
|
+
super(message);
|
|
531
|
+
this.type = type;
|
|
532
|
+
}
|
|
683
533
|
};
|
|
684
|
-
|
|
685
|
-
function resolveCacheDir(config, options) {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
}
|
|
689
|
-
return path6.join(path6.dirname(config), ".content-collections", "cache");
|
|
534
|
+
const defaultConfigName = "content-collection-config.mjs";
|
|
535
|
+
function resolveCacheDir(config$1, options) {
|
|
536
|
+
if (options.cacheDir) return options.cacheDir;
|
|
537
|
+
return path.join(path.dirname(config$1), ".content-collections", "cache");
|
|
690
538
|
}
|
|
691
539
|
function createConfigurationReader() {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
540
|
+
return async (configurationPath, options = { configName: defaultConfigName }) => {
|
|
541
|
+
if (!existsSync(configurationPath)) throw new ConfigurationError("Read", `configuration file ${configurationPath} does not exist`);
|
|
542
|
+
const cacheDir = resolveCacheDir(configurationPath, options);
|
|
543
|
+
await fs.mkdir(cacheDir, { recursive: true });
|
|
544
|
+
const outfile = path.join(cacheDir, options.configName);
|
|
545
|
+
try {
|
|
546
|
+
const configurationPaths = await compile(configurationPath, outfile);
|
|
547
|
+
const module = await import(`file://${path.resolve(outfile)}?x=${Date.now()}`);
|
|
548
|
+
const hash = createHash("sha256");
|
|
549
|
+
hash.update(await fs.readFile(outfile, "utf-8"));
|
|
550
|
+
const checksum = hash.digest("hex");
|
|
551
|
+
return {
|
|
552
|
+
...module.default,
|
|
553
|
+
path: configurationPath,
|
|
554
|
+
inputPaths: configurationPaths.map((p) => path.resolve(p)),
|
|
555
|
+
generateTypes: true,
|
|
556
|
+
checksum
|
|
557
|
+
};
|
|
558
|
+
} catch (error) {
|
|
559
|
+
throw new ConfigurationError("Compile", `configuration file ${configurationPath} is invalid: ${error}`);
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
//#endregion
|
|
565
|
+
//#region src/features.ts
|
|
566
|
+
const deprecations = { implicitContentProperty: `The implicit addition of a content property to schemas is deprecated.
|
|
567
|
+
Please add an explicit content property to your schema.
|
|
568
|
+
For more information, see:
|
|
569
|
+
https://content-collections.dev/docs/deprecations/implicit-content-property` };
|
|
570
|
+
const _suppressDeprecatedWarnings = [];
|
|
571
|
+
function suppressDeprecatedWarnings(...suppresses) {
|
|
572
|
+
for (const deprecation of suppresses) if (deprecation === "all") {
|
|
573
|
+
_suppressDeprecatedWarnings.push(...Object.keys(deprecations));
|
|
574
|
+
return;
|
|
575
|
+
} else _suppressDeprecatedWarnings.push(deprecation);
|
|
576
|
+
}
|
|
577
|
+
function deprecated(deprecation, logger = console.warn) {
|
|
578
|
+
if (_suppressDeprecatedWarnings.includes(deprecation)) return;
|
|
579
|
+
logger(`[CC DEPRECATED]: ${deprecations[deprecation]}`);
|
|
580
|
+
}
|
|
581
|
+
const retiredFeatures = { legacySchema: `The use of a function as a schema is retired.
|
|
582
|
+
Please use a StandardSchema compliant library directly.
|
|
583
|
+
For more information, see:
|
|
584
|
+
https://content-collections.dev/docs/deprecations/schema-as-function` };
|
|
585
|
+
var RetiredFeatureError = class RetiredFeatureError extends Error {
|
|
586
|
+
feature;
|
|
587
|
+
constructor(feature) {
|
|
588
|
+
super(`This feature has been removed:\n${retiredFeatures[feature]}`);
|
|
589
|
+
this.feature = feature;
|
|
590
|
+
this.name = "RetiredFeatureError";
|
|
591
|
+
Object.setPrototypeOf(this, RetiredFeatureError.prototype);
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
function retired(feature) {
|
|
595
|
+
throw new RetiredFeatureError(feature);
|
|
724
596
|
}
|
|
725
597
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
598
|
+
//#endregion
|
|
599
|
+
//#region src/config.ts
|
|
600
|
+
const skippedSymbol = Symbol("skipped");
|
|
729
601
|
function defineCollection(collection) {
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
schema2 = z.object(schema2(z));
|
|
747
|
-
}
|
|
748
|
-
return {
|
|
749
|
-
...collection,
|
|
750
|
-
typeName,
|
|
751
|
-
parser,
|
|
752
|
-
schema: schema2
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
function defineConfig(config) {
|
|
756
|
-
return config;
|
|
602
|
+
let typeName = collection.typeName;
|
|
603
|
+
if (!typeName) typeName = generateTypeName(collection.name);
|
|
604
|
+
let parser = collection.parser;
|
|
605
|
+
if (!parser) parser = "frontmatter";
|
|
606
|
+
else if (!isValidParser(parser)) throw new ConfigurationError("Read", `Parser ${parser} is not valid a parser`);
|
|
607
|
+
let schema$1 = collection.schema;
|
|
608
|
+
if (!schema$1["~standard"]) retired("legacySchema");
|
|
609
|
+
return {
|
|
610
|
+
...collection,
|
|
611
|
+
typeName,
|
|
612
|
+
parser,
|
|
613
|
+
schema: schema$1
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
function defineConfig(config$1) {
|
|
617
|
+
return config$1;
|
|
757
618
|
}
|
|
758
619
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/core/core.js
|
|
622
|
+
/** A special constant with type `never` */
|
|
623
|
+
const NEVER = Object.freeze({ status: "aborted" });
|
|
624
|
+
function $constructor(name, initializer$1, params) {
|
|
625
|
+
function init(inst, def) {
|
|
626
|
+
var _a;
|
|
627
|
+
Object.defineProperty(inst, "_zod", {
|
|
628
|
+
value: inst._zod ?? {},
|
|
629
|
+
enumerable: false
|
|
630
|
+
});
|
|
631
|
+
(_a = inst._zod).traits ?? (_a.traits = /* @__PURE__ */ new Set());
|
|
632
|
+
inst._zod.traits.add(name);
|
|
633
|
+
initializer$1(inst, def);
|
|
634
|
+
for (const k in _.prototype) if (!(k in inst)) Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
|
|
635
|
+
inst._zod.constr = _;
|
|
636
|
+
inst._zod.def = def;
|
|
637
|
+
}
|
|
638
|
+
const Parent = params?.Parent ?? Object;
|
|
639
|
+
class Definition extends Parent {}
|
|
640
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
641
|
+
function _(def) {
|
|
642
|
+
var _a;
|
|
643
|
+
const inst = params?.Parent ? new Definition() : this;
|
|
644
|
+
init(inst, def);
|
|
645
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
646
|
+
for (const fn of inst._zod.deferred) fn();
|
|
647
|
+
return inst;
|
|
648
|
+
}
|
|
649
|
+
Object.defineProperty(_, "init", { value: init });
|
|
650
|
+
Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
|
|
651
|
+
if (params?.Parent && inst instanceof params.Parent) return true;
|
|
652
|
+
return inst?._zod?.traits?.has(name);
|
|
653
|
+
} });
|
|
654
|
+
Object.defineProperty(_, "name", { value: name });
|
|
655
|
+
return _;
|
|
656
|
+
}
|
|
657
|
+
const $brand = Symbol("zod_brand");
|
|
658
|
+
var $ZodAsyncError = class extends Error {
|
|
659
|
+
constructor() {
|
|
660
|
+
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
const globalConfig = {};
|
|
664
|
+
function config(newConfig) {
|
|
665
|
+
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
666
|
+
return globalConfig;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
//#endregion
|
|
670
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/core/util.js
|
|
671
|
+
function jsonStringifyReplacer(_, value) {
|
|
672
|
+
if (typeof value === "bigint") return value.toString();
|
|
673
|
+
return value;
|
|
674
|
+
}
|
|
675
|
+
function cached(getter) {
|
|
676
|
+
return { get value() {
|
|
677
|
+
{
|
|
678
|
+
const value = getter();
|
|
679
|
+
Object.defineProperty(this, "value", { value });
|
|
680
|
+
return value;
|
|
681
|
+
}
|
|
682
|
+
throw new Error("cached value already set");
|
|
683
|
+
} };
|
|
684
|
+
}
|
|
685
|
+
function cleanRegex(source) {
|
|
686
|
+
const start = source.startsWith("^") ? 1 : 0;
|
|
687
|
+
const end = source.endsWith("$") ? source.length - 1 : source.length;
|
|
688
|
+
return source.slice(start, end);
|
|
689
|
+
}
|
|
690
|
+
const EVALUATING = Symbol("evaluating");
|
|
691
|
+
function defineLazy(object$1, key, getter) {
|
|
692
|
+
let value = void 0;
|
|
693
|
+
Object.defineProperty(object$1, key, {
|
|
694
|
+
get() {
|
|
695
|
+
if (value === EVALUATING) return;
|
|
696
|
+
if (value === void 0) {
|
|
697
|
+
value = EVALUATING;
|
|
698
|
+
value = getter();
|
|
699
|
+
}
|
|
700
|
+
return value;
|
|
701
|
+
},
|
|
702
|
+
set(v) {
|
|
703
|
+
Object.defineProperty(object$1, key, { value: v });
|
|
704
|
+
},
|
|
705
|
+
configurable: true
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {};
|
|
709
|
+
function isObject(data) {
|
|
710
|
+
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
711
|
+
}
|
|
712
|
+
const allowsEval = cached(() => {
|
|
713
|
+
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
|
|
714
|
+
try {
|
|
715
|
+
new Function("");
|
|
716
|
+
return true;
|
|
717
|
+
} catch (_) {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
function isPlainObject(o) {
|
|
722
|
+
if (isObject(o) === false) return false;
|
|
723
|
+
const ctor = o.constructor;
|
|
724
|
+
if (ctor === void 0) return true;
|
|
725
|
+
const prot = ctor.prototype;
|
|
726
|
+
if (isObject(prot) === false) return false;
|
|
727
|
+
if (Object.prototype.hasOwnProperty.call(prot, "isPrototypeOf") === false) return false;
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
const propertyKeyTypes = new Set([
|
|
731
|
+
"string",
|
|
732
|
+
"number",
|
|
733
|
+
"symbol"
|
|
734
|
+
]);
|
|
735
|
+
function escapeRegex(str) {
|
|
736
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
737
|
+
}
|
|
738
|
+
function clone(inst, def, params) {
|
|
739
|
+
const cl = new inst._zod.constr(def ?? inst._zod.def);
|
|
740
|
+
if (!def || params?.parent) cl._zod.parent = inst;
|
|
741
|
+
return cl;
|
|
742
|
+
}
|
|
743
|
+
function normalizeParams(_params) {
|
|
744
|
+
const params = _params;
|
|
745
|
+
if (!params) return {};
|
|
746
|
+
if (typeof params === "string") return { error: () => params };
|
|
747
|
+
if (params?.message !== void 0) {
|
|
748
|
+
if (params?.error !== void 0) throw new Error("Cannot specify both `message` and `error` params");
|
|
749
|
+
params.error = params.message;
|
|
750
|
+
}
|
|
751
|
+
delete params.message;
|
|
752
|
+
if (typeof params.error === "string") return {
|
|
753
|
+
...params,
|
|
754
|
+
error: () => params.error
|
|
755
|
+
};
|
|
756
|
+
return params;
|
|
757
|
+
}
|
|
758
|
+
function optionalKeys(shape) {
|
|
759
|
+
return Object.keys(shape).filter((k) => {
|
|
760
|
+
return shape[k]._zod.optin === "optional" && shape[k]._zod.optout === "optional";
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
const NUMBER_FORMAT_RANGES = {
|
|
764
|
+
safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
|
|
765
|
+
int32: [-2147483648, 2147483647],
|
|
766
|
+
uint32: [0, 4294967295],
|
|
767
|
+
float32: [-34028234663852886e22, 34028234663852886e22],
|
|
768
|
+
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
769
|
+
};
|
|
770
|
+
function aborted(x, startIndex = 0) {
|
|
771
|
+
if (x.aborted === true) return true;
|
|
772
|
+
for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
function prefixIssues(path$1, issues) {
|
|
776
|
+
return issues.map((iss) => {
|
|
777
|
+
var _a;
|
|
778
|
+
(_a = iss).path ?? (_a.path = []);
|
|
779
|
+
iss.path.unshift(path$1);
|
|
780
|
+
return iss;
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
function unwrapMessage(message) {
|
|
784
|
+
return typeof message === "string" ? message : message?.message;
|
|
785
|
+
}
|
|
786
|
+
function finalizeIssue(iss, ctx, config$1) {
|
|
787
|
+
const full = {
|
|
788
|
+
...iss,
|
|
789
|
+
path: iss.path ?? []
|
|
790
|
+
};
|
|
791
|
+
if (!iss.message) full.message = unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config$1.customError?.(iss)) ?? unwrapMessage(config$1.localeError?.(iss)) ?? "Invalid input";
|
|
792
|
+
delete full.inst;
|
|
793
|
+
delete full.continue;
|
|
794
|
+
if (!ctx?.reportInput) delete full.input;
|
|
795
|
+
return full;
|
|
796
|
+
}
|
|
762
797
|
|
|
763
|
-
|
|
764
|
-
|
|
798
|
+
//#endregion
|
|
799
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/core/errors.js
|
|
800
|
+
const initializer = (inst, def) => {
|
|
801
|
+
inst.name = "$ZodError";
|
|
802
|
+
Object.defineProperty(inst, "_zod", {
|
|
803
|
+
value: inst._zod,
|
|
804
|
+
enumerable: false
|
|
805
|
+
});
|
|
806
|
+
Object.defineProperty(inst, "issues", {
|
|
807
|
+
value: def,
|
|
808
|
+
enumerable: false
|
|
809
|
+
});
|
|
810
|
+
inst.message = JSON.stringify(def, jsonStringifyReplacer, 2);
|
|
811
|
+
Object.defineProperty(inst, "toString", {
|
|
812
|
+
value: () => inst.message,
|
|
813
|
+
enumerable: false
|
|
814
|
+
});
|
|
815
|
+
};
|
|
816
|
+
const $ZodError = $constructor("$ZodError", initializer);
|
|
817
|
+
const $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
|
818
|
+
|
|
819
|
+
//#endregion
|
|
820
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/core/parse.js
|
|
821
|
+
const _parse = (_Err) => (schema$1, value, _ctx, _params) => {
|
|
822
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: false }) : { async: false };
|
|
823
|
+
const result = schema$1._zod.run({
|
|
824
|
+
value,
|
|
825
|
+
issues: []
|
|
826
|
+
}, ctx);
|
|
827
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
828
|
+
if (result.issues.length) {
|
|
829
|
+
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
830
|
+
captureStackTrace(e, _params?.callee);
|
|
831
|
+
throw e;
|
|
832
|
+
}
|
|
833
|
+
return result.value;
|
|
834
|
+
};
|
|
835
|
+
const parse$1 = /* @__PURE__ */ _parse($ZodRealError);
|
|
836
|
+
const _parseAsync = (_Err) => async (schema$1, value, _ctx, params) => {
|
|
837
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
838
|
+
let result = schema$1._zod.run({
|
|
839
|
+
value,
|
|
840
|
+
issues: []
|
|
841
|
+
}, ctx);
|
|
842
|
+
if (result instanceof Promise) result = await result;
|
|
843
|
+
if (result.issues.length) {
|
|
844
|
+
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
845
|
+
captureStackTrace(e, params?.callee);
|
|
846
|
+
throw e;
|
|
847
|
+
}
|
|
848
|
+
return result.value;
|
|
849
|
+
};
|
|
850
|
+
const parseAsync = /* @__PURE__ */ _parseAsync($ZodRealError);
|
|
851
|
+
const _safeParse = (_Err) => (schema$1, value, _ctx) => {
|
|
852
|
+
const ctx = _ctx ? {
|
|
853
|
+
..._ctx,
|
|
854
|
+
async: false
|
|
855
|
+
} : { async: false };
|
|
856
|
+
const result = schema$1._zod.run({
|
|
857
|
+
value,
|
|
858
|
+
issues: []
|
|
859
|
+
}, ctx);
|
|
860
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
861
|
+
return result.issues.length ? {
|
|
862
|
+
success: false,
|
|
863
|
+
error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
864
|
+
} : {
|
|
865
|
+
success: true,
|
|
866
|
+
data: result.value
|
|
867
|
+
};
|
|
868
|
+
};
|
|
869
|
+
const safeParse = /* @__PURE__ */ _safeParse($ZodRealError);
|
|
870
|
+
const _safeParseAsync = (_Err) => async (schema$1, value, _ctx) => {
|
|
871
|
+
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
872
|
+
let result = schema$1._zod.run({
|
|
873
|
+
value,
|
|
874
|
+
issues: []
|
|
875
|
+
}, ctx);
|
|
876
|
+
if (result instanceof Promise) result = await result;
|
|
877
|
+
return result.issues.length ? {
|
|
878
|
+
success: false,
|
|
879
|
+
error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
880
|
+
} : {
|
|
881
|
+
success: true,
|
|
882
|
+
data: result.value
|
|
883
|
+
};
|
|
884
|
+
};
|
|
885
|
+
const safeParseAsync = /* @__PURE__ */ _safeParseAsync($ZodRealError);
|
|
886
|
+
const _encode = (_Err) => (schema$1, value, _ctx) => {
|
|
887
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
888
|
+
return _parse(_Err)(schema$1, value, ctx);
|
|
889
|
+
};
|
|
890
|
+
const encode = /* @__PURE__ */ _encode($ZodRealError);
|
|
891
|
+
const _decode = (_Err) => (schema$1, value, _ctx) => {
|
|
892
|
+
return _parse(_Err)(schema$1, value, _ctx);
|
|
893
|
+
};
|
|
894
|
+
const decode = /* @__PURE__ */ _decode($ZodRealError);
|
|
895
|
+
const _encodeAsync = (_Err) => async (schema$1, value, _ctx) => {
|
|
896
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
897
|
+
return _parseAsync(_Err)(schema$1, value, ctx);
|
|
898
|
+
};
|
|
899
|
+
const encodeAsync = /* @__PURE__ */ _encodeAsync($ZodRealError);
|
|
900
|
+
const _decodeAsync = (_Err) => async (schema$1, value, _ctx) => {
|
|
901
|
+
return _parseAsync(_Err)(schema$1, value, _ctx);
|
|
902
|
+
};
|
|
903
|
+
const decodeAsync = /* @__PURE__ */ _decodeAsync($ZodRealError);
|
|
904
|
+
const _safeEncode = (_Err) => (schema$1, value, _ctx) => {
|
|
905
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
906
|
+
return _safeParse(_Err)(schema$1, value, ctx);
|
|
907
|
+
};
|
|
908
|
+
const safeEncode = /* @__PURE__ */ _safeEncode($ZodRealError);
|
|
909
|
+
const _safeDecode = (_Err) => (schema$1, value, _ctx) => {
|
|
910
|
+
return _safeParse(_Err)(schema$1, value, _ctx);
|
|
911
|
+
};
|
|
912
|
+
const safeDecode = /* @__PURE__ */ _safeDecode($ZodRealError);
|
|
913
|
+
const _safeEncodeAsync = (_Err) => async (schema$1, value, _ctx) => {
|
|
914
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
915
|
+
return _safeParseAsync(_Err)(schema$1, value, ctx);
|
|
916
|
+
};
|
|
917
|
+
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync($ZodRealError);
|
|
918
|
+
const _safeDecodeAsync = (_Err) => async (schema$1, value, _ctx) => {
|
|
919
|
+
return _safeParseAsync(_Err)(schema$1, value, _ctx);
|
|
920
|
+
};
|
|
921
|
+
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync($ZodRealError);
|
|
922
|
+
|
|
923
|
+
//#endregion
|
|
924
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/core/regexes.js
|
|
925
|
+
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
926
|
+
const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
|
|
927
|
+
const string$1 = (params) => {
|
|
928
|
+
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
929
|
+
return /* @__PURE__ */ new RegExp(`^${regex}$`);
|
|
930
|
+
};
|
|
931
|
+
const bigint$1 = /^-?\d+n?$/;
|
|
932
|
+
const number$1 = /^-?\d+(?:\.\d+)?/;
|
|
933
|
+
const boolean$1 = /^(?:true|false)$/i;
|
|
934
|
+
const _null$2 = /^null$/i;
|
|
935
|
+
const _undefined$2 = /^undefined$/i;
|
|
936
|
+
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/core/versions.js
|
|
939
|
+
const version = {
|
|
940
|
+
major: 4,
|
|
941
|
+
minor: 1,
|
|
942
|
+
patch: 11
|
|
943
|
+
};
|
|
944
|
+
|
|
945
|
+
//#endregion
|
|
946
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/core/schemas.js
|
|
947
|
+
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
948
|
+
var _a;
|
|
949
|
+
inst ?? (inst = {});
|
|
950
|
+
inst._zod.def = def;
|
|
951
|
+
inst._zod.bag = inst._zod.bag || {};
|
|
952
|
+
inst._zod.version = version;
|
|
953
|
+
const checks = [...inst._zod.def.checks ?? []];
|
|
954
|
+
if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
|
|
955
|
+
for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
|
|
956
|
+
if (checks.length === 0) {
|
|
957
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
958
|
+
inst._zod.deferred?.push(() => {
|
|
959
|
+
inst._zod.run = inst._zod.parse;
|
|
960
|
+
});
|
|
961
|
+
} else {
|
|
962
|
+
const runChecks = (payload, checks$1, ctx) => {
|
|
963
|
+
let isAborted = aborted(payload);
|
|
964
|
+
let asyncResult;
|
|
965
|
+
for (const ch of checks$1) {
|
|
966
|
+
if (ch._zod.def.when) {
|
|
967
|
+
if (!ch._zod.def.when(payload)) continue;
|
|
968
|
+
} else if (isAborted) continue;
|
|
969
|
+
const currLen = payload.issues.length;
|
|
970
|
+
const _ = ch._zod.check(payload);
|
|
971
|
+
if (_ instanceof Promise && ctx?.async === false) throw new $ZodAsyncError();
|
|
972
|
+
if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
973
|
+
await _;
|
|
974
|
+
if (payload.issues.length === currLen) return;
|
|
975
|
+
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
976
|
+
});
|
|
977
|
+
else {
|
|
978
|
+
if (payload.issues.length === currLen) continue;
|
|
979
|
+
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if (asyncResult) return asyncResult.then(() => {
|
|
983
|
+
return payload;
|
|
984
|
+
});
|
|
985
|
+
return payload;
|
|
986
|
+
};
|
|
987
|
+
const handleCanaryResult = (canary, payload, ctx) => {
|
|
988
|
+
if (aborted(canary)) {
|
|
989
|
+
canary.aborted = true;
|
|
990
|
+
return canary;
|
|
991
|
+
}
|
|
992
|
+
const checkResult = runChecks(payload, checks, ctx);
|
|
993
|
+
if (checkResult instanceof Promise) {
|
|
994
|
+
if (ctx.async === false) throw new $ZodAsyncError();
|
|
995
|
+
return checkResult.then((checkResult$1) => inst._zod.parse(checkResult$1, ctx));
|
|
996
|
+
}
|
|
997
|
+
return inst._zod.parse(checkResult, ctx);
|
|
998
|
+
};
|
|
999
|
+
inst._zod.run = (payload, ctx) => {
|
|
1000
|
+
if (ctx.skipChecks) return inst._zod.parse(payload, ctx);
|
|
1001
|
+
if (ctx.direction === "backward") {
|
|
1002
|
+
const canary = inst._zod.parse({
|
|
1003
|
+
value: payload.value,
|
|
1004
|
+
issues: []
|
|
1005
|
+
}, {
|
|
1006
|
+
...ctx,
|
|
1007
|
+
skipChecks: true
|
|
1008
|
+
});
|
|
1009
|
+
if (canary instanceof Promise) return canary.then((canary$1) => {
|
|
1010
|
+
return handleCanaryResult(canary$1, payload, ctx);
|
|
1011
|
+
});
|
|
1012
|
+
return handleCanaryResult(canary, payload, ctx);
|
|
1013
|
+
}
|
|
1014
|
+
const result = inst._zod.parse(payload, ctx);
|
|
1015
|
+
if (result instanceof Promise) {
|
|
1016
|
+
if (ctx.async === false) throw new $ZodAsyncError();
|
|
1017
|
+
return result.then((result$1) => runChecks(result$1, checks, ctx));
|
|
1018
|
+
}
|
|
1019
|
+
return runChecks(result, checks, ctx);
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
inst["~standard"] = {
|
|
1023
|
+
validate: (value) => {
|
|
1024
|
+
try {
|
|
1025
|
+
const r = safeParse(inst, value);
|
|
1026
|
+
return r.success ? { value: r.data } : { issues: r.error?.issues };
|
|
1027
|
+
} catch (_) {
|
|
1028
|
+
return safeParseAsync(inst, value).then((r) => r.success ? { value: r.data } : { issues: r.error?.issues });
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
vendor: "zod",
|
|
1032
|
+
version: 1
|
|
1033
|
+
};
|
|
1034
|
+
});
|
|
1035
|
+
const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
1036
|
+
$ZodType.init(inst, def);
|
|
1037
|
+
inst._zod.pattern = [...inst?._zod.bag?.patterns ?? []].pop() ?? string$1(inst._zod.bag);
|
|
1038
|
+
inst._zod.parse = (payload, _) => {
|
|
1039
|
+
if (def.coerce) try {
|
|
1040
|
+
payload.value = String(payload.value);
|
|
1041
|
+
} catch (_$1) {}
|
|
1042
|
+
if (typeof payload.value === "string") return payload;
|
|
1043
|
+
payload.issues.push({
|
|
1044
|
+
expected: "string",
|
|
1045
|
+
code: "invalid_type",
|
|
1046
|
+
input: payload.value,
|
|
1047
|
+
inst
|
|
1048
|
+
});
|
|
1049
|
+
return payload;
|
|
1050
|
+
};
|
|
1051
|
+
});
|
|
1052
|
+
const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
1053
|
+
$ZodType.init(inst, def);
|
|
1054
|
+
inst._zod.pattern = inst._zod.bag.pattern ?? number$1;
|
|
1055
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1056
|
+
if (def.coerce) try {
|
|
1057
|
+
payload.value = Number(payload.value);
|
|
1058
|
+
} catch (_) {}
|
|
1059
|
+
const input = payload.value;
|
|
1060
|
+
if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
|
|
1061
|
+
const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? "Infinity" : void 0 : void 0;
|
|
1062
|
+
payload.issues.push({
|
|
1063
|
+
expected: "number",
|
|
1064
|
+
code: "invalid_type",
|
|
1065
|
+
input,
|
|
1066
|
+
inst,
|
|
1067
|
+
...received ? { received } : {}
|
|
1068
|
+
});
|
|
1069
|
+
return payload;
|
|
1070
|
+
};
|
|
1071
|
+
});
|
|
1072
|
+
const $ZodBoolean = /* @__PURE__ */ $constructor("$ZodBoolean", (inst, def) => {
|
|
1073
|
+
$ZodType.init(inst, def);
|
|
1074
|
+
inst._zod.pattern = boolean$1;
|
|
1075
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1076
|
+
if (def.coerce) try {
|
|
1077
|
+
payload.value = Boolean(payload.value);
|
|
1078
|
+
} catch (_) {}
|
|
1079
|
+
const input = payload.value;
|
|
1080
|
+
if (typeof input === "boolean") return payload;
|
|
1081
|
+
payload.issues.push({
|
|
1082
|
+
expected: "boolean",
|
|
1083
|
+
code: "invalid_type",
|
|
1084
|
+
input,
|
|
1085
|
+
inst
|
|
1086
|
+
});
|
|
1087
|
+
return payload;
|
|
1088
|
+
};
|
|
1089
|
+
});
|
|
1090
|
+
const $ZodBigInt = /* @__PURE__ */ $constructor("$ZodBigInt", (inst, def) => {
|
|
1091
|
+
$ZodType.init(inst, def);
|
|
1092
|
+
inst._zod.pattern = bigint$1;
|
|
1093
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1094
|
+
if (def.coerce) try {
|
|
1095
|
+
payload.value = BigInt(payload.value);
|
|
1096
|
+
} catch (_) {}
|
|
1097
|
+
if (typeof payload.value === "bigint") return payload;
|
|
1098
|
+
payload.issues.push({
|
|
1099
|
+
expected: "bigint",
|
|
1100
|
+
code: "invalid_type",
|
|
1101
|
+
input: payload.value,
|
|
1102
|
+
inst
|
|
1103
|
+
});
|
|
1104
|
+
return payload;
|
|
1105
|
+
};
|
|
1106
|
+
});
|
|
1107
|
+
const $ZodUndefined = /* @__PURE__ */ $constructor("$ZodUndefined", (inst, def) => {
|
|
1108
|
+
$ZodType.init(inst, def);
|
|
1109
|
+
inst._zod.pattern = _undefined$2;
|
|
1110
|
+
inst._zod.values = new Set([void 0]);
|
|
1111
|
+
inst._zod.optin = "optional";
|
|
1112
|
+
inst._zod.optout = "optional";
|
|
1113
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1114
|
+
const input = payload.value;
|
|
1115
|
+
if (typeof input === "undefined") return payload;
|
|
1116
|
+
payload.issues.push({
|
|
1117
|
+
expected: "undefined",
|
|
1118
|
+
code: "invalid_type",
|
|
1119
|
+
input,
|
|
1120
|
+
inst
|
|
1121
|
+
});
|
|
1122
|
+
return payload;
|
|
1123
|
+
};
|
|
1124
|
+
});
|
|
1125
|
+
const $ZodNull = /* @__PURE__ */ $constructor("$ZodNull", (inst, def) => {
|
|
1126
|
+
$ZodType.init(inst, def);
|
|
1127
|
+
inst._zod.pattern = _null$2;
|
|
1128
|
+
inst._zod.values = new Set([null]);
|
|
1129
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1130
|
+
const input = payload.value;
|
|
1131
|
+
if (input === null) return payload;
|
|
1132
|
+
payload.issues.push({
|
|
1133
|
+
expected: "null",
|
|
1134
|
+
code: "invalid_type",
|
|
1135
|
+
input,
|
|
1136
|
+
inst
|
|
1137
|
+
});
|
|
1138
|
+
return payload;
|
|
1139
|
+
};
|
|
1140
|
+
});
|
|
1141
|
+
const $ZodUnknown = /* @__PURE__ */ $constructor("$ZodUnknown", (inst, def) => {
|
|
1142
|
+
$ZodType.init(inst, def);
|
|
1143
|
+
inst._zod.parse = (payload) => payload;
|
|
1144
|
+
});
|
|
1145
|
+
const $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
1146
|
+
$ZodType.init(inst, def);
|
|
1147
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1148
|
+
if (def.coerce) try {
|
|
1149
|
+
payload.value = new Date(payload.value);
|
|
1150
|
+
} catch (_err) {}
|
|
1151
|
+
const input = payload.value;
|
|
1152
|
+
const isDate = input instanceof Date;
|
|
1153
|
+
if (isDate && !Number.isNaN(input.getTime())) return payload;
|
|
1154
|
+
payload.issues.push({
|
|
1155
|
+
expected: "date",
|
|
1156
|
+
code: "invalid_type",
|
|
1157
|
+
input,
|
|
1158
|
+
...isDate ? { received: "Invalid Date" } : {},
|
|
1159
|
+
inst
|
|
1160
|
+
});
|
|
1161
|
+
return payload;
|
|
1162
|
+
};
|
|
1163
|
+
});
|
|
1164
|
+
function handleArrayResult(result, final, index) {
|
|
1165
|
+
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
1166
|
+
final.value[index] = result.value;
|
|
1167
|
+
}
|
|
1168
|
+
const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
1169
|
+
$ZodType.init(inst, def);
|
|
1170
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1171
|
+
const input = payload.value;
|
|
1172
|
+
if (!Array.isArray(input)) {
|
|
1173
|
+
payload.issues.push({
|
|
1174
|
+
expected: "array",
|
|
1175
|
+
code: "invalid_type",
|
|
1176
|
+
input,
|
|
1177
|
+
inst
|
|
1178
|
+
});
|
|
1179
|
+
return payload;
|
|
1180
|
+
}
|
|
1181
|
+
payload.value = Array(input.length);
|
|
1182
|
+
const proms = [];
|
|
1183
|
+
for (let i = 0; i < input.length; i++) {
|
|
1184
|
+
const item = input[i];
|
|
1185
|
+
const result = def.element._zod.run({
|
|
1186
|
+
value: item,
|
|
1187
|
+
issues: []
|
|
1188
|
+
}, ctx);
|
|
1189
|
+
if (result instanceof Promise) proms.push(result.then((result$1) => handleArrayResult(result$1, payload, i)));
|
|
1190
|
+
else handleArrayResult(result, payload, i);
|
|
1191
|
+
}
|
|
1192
|
+
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1193
|
+
return payload;
|
|
1194
|
+
};
|
|
1195
|
+
});
|
|
1196
|
+
function handlePropertyResult(result, final, key, input) {
|
|
1197
|
+
if (result.issues.length) final.issues.push(...prefixIssues(key, result.issues));
|
|
1198
|
+
if (result.value === void 0) {
|
|
1199
|
+
if (key in input) final.value[key] = void 0;
|
|
1200
|
+
} else final.value[key] = result.value;
|
|
1201
|
+
}
|
|
1202
|
+
function normalizeDef(def) {
|
|
1203
|
+
const keys = Object.keys(def.shape);
|
|
1204
|
+
for (const k of keys) if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) throw new Error(`Invalid element at key "${k}": expected a Zod schema`);
|
|
1205
|
+
const okeys = optionalKeys(def.shape);
|
|
1206
|
+
return {
|
|
1207
|
+
...def,
|
|
1208
|
+
keys,
|
|
1209
|
+
keySet: new Set(keys),
|
|
1210
|
+
numKeys: keys.length,
|
|
1211
|
+
optionalKeys: new Set(okeys)
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
1215
|
+
const unrecognized = [];
|
|
1216
|
+
const keySet = def.keySet;
|
|
1217
|
+
const _catchall = def.catchall._zod;
|
|
1218
|
+
const t = _catchall.def.type;
|
|
1219
|
+
for (const key of Object.keys(input)) {
|
|
1220
|
+
if (keySet.has(key)) continue;
|
|
1221
|
+
if (t === "never") {
|
|
1222
|
+
unrecognized.push(key);
|
|
1223
|
+
continue;
|
|
1224
|
+
}
|
|
1225
|
+
const r = _catchall.run({
|
|
1226
|
+
value: input[key],
|
|
1227
|
+
issues: []
|
|
1228
|
+
}, ctx);
|
|
1229
|
+
if (r instanceof Promise) proms.push(r.then((r$1) => handlePropertyResult(r$1, payload, key, input)));
|
|
1230
|
+
else handlePropertyResult(r, payload, key, input);
|
|
1231
|
+
}
|
|
1232
|
+
if (unrecognized.length) payload.issues.push({
|
|
1233
|
+
code: "unrecognized_keys",
|
|
1234
|
+
keys: unrecognized,
|
|
1235
|
+
input,
|
|
1236
|
+
inst
|
|
1237
|
+
});
|
|
1238
|
+
if (!proms.length) return payload;
|
|
1239
|
+
return Promise.all(proms).then(() => {
|
|
1240
|
+
return payload;
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
1244
|
+
$ZodType.init(inst, def);
|
|
1245
|
+
if (!Object.getOwnPropertyDescriptor(def, "shape")?.get) {
|
|
1246
|
+
const sh = def.shape;
|
|
1247
|
+
Object.defineProperty(def, "shape", { get: () => {
|
|
1248
|
+
const newSh = { ...sh };
|
|
1249
|
+
Object.defineProperty(def, "shape", { value: newSh });
|
|
1250
|
+
return newSh;
|
|
1251
|
+
} });
|
|
1252
|
+
}
|
|
1253
|
+
const _normalized = cached(() => normalizeDef(def));
|
|
1254
|
+
defineLazy(inst._zod, "propValues", () => {
|
|
1255
|
+
const shape = def.shape;
|
|
1256
|
+
const propValues = {};
|
|
1257
|
+
for (const key in shape) {
|
|
1258
|
+
const field = shape[key]._zod;
|
|
1259
|
+
if (field.values) {
|
|
1260
|
+
propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
|
|
1261
|
+
for (const v of field.values) propValues[key].add(v);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return propValues;
|
|
1265
|
+
});
|
|
1266
|
+
const isObject$1 = isObject;
|
|
1267
|
+
const catchall = def.catchall;
|
|
1268
|
+
let value;
|
|
1269
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1270
|
+
value ?? (value = _normalized.value);
|
|
1271
|
+
const input = payload.value;
|
|
1272
|
+
if (!isObject$1(input)) {
|
|
1273
|
+
payload.issues.push({
|
|
1274
|
+
expected: "object",
|
|
1275
|
+
code: "invalid_type",
|
|
1276
|
+
input,
|
|
1277
|
+
inst
|
|
1278
|
+
});
|
|
1279
|
+
return payload;
|
|
1280
|
+
}
|
|
1281
|
+
payload.value = {};
|
|
1282
|
+
const proms = [];
|
|
1283
|
+
const shape = value.shape;
|
|
1284
|
+
for (const key of value.keys) {
|
|
1285
|
+
const r = shape[key]._zod.run({
|
|
1286
|
+
value: input[key],
|
|
1287
|
+
issues: []
|
|
1288
|
+
}, ctx);
|
|
1289
|
+
if (r instanceof Promise) proms.push(r.then((r$1) => handlePropertyResult(r$1, payload, key, input)));
|
|
1290
|
+
else handlePropertyResult(r, payload, key, input);
|
|
1291
|
+
}
|
|
1292
|
+
if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1293
|
+
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
1294
|
+
};
|
|
1295
|
+
});
|
|
1296
|
+
function handleUnionResults(results, final, inst, ctx) {
|
|
1297
|
+
for (const result of results) if (result.issues.length === 0) {
|
|
1298
|
+
final.value = result.value;
|
|
1299
|
+
return final;
|
|
1300
|
+
}
|
|
1301
|
+
const nonaborted = results.filter((r) => !aborted(r));
|
|
1302
|
+
if (nonaborted.length === 1) {
|
|
1303
|
+
final.value = nonaborted[0].value;
|
|
1304
|
+
return nonaborted[0];
|
|
1305
|
+
}
|
|
1306
|
+
final.issues.push({
|
|
1307
|
+
code: "invalid_union",
|
|
1308
|
+
input: final.value,
|
|
1309
|
+
inst,
|
|
1310
|
+
errors: results.map((result) => result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
1311
|
+
});
|
|
1312
|
+
return final;
|
|
1313
|
+
}
|
|
1314
|
+
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
1315
|
+
$ZodType.init(inst, def);
|
|
1316
|
+
defineLazy(inst._zod, "optin", () => def.options.some((o) => o._zod.optin === "optional") ? "optional" : void 0);
|
|
1317
|
+
defineLazy(inst._zod, "optout", () => def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
|
|
1318
|
+
defineLazy(inst._zod, "values", () => {
|
|
1319
|
+
if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
1320
|
+
});
|
|
1321
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
1322
|
+
if (def.options.every((o) => o._zod.pattern)) {
|
|
1323
|
+
const patterns = def.options.map((o) => o._zod.pattern);
|
|
1324
|
+
return /* @__PURE__ */ new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
1325
|
+
}
|
|
1326
|
+
});
|
|
1327
|
+
const single = def.options.length === 1;
|
|
1328
|
+
const first = def.options[0]._zod.run;
|
|
1329
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1330
|
+
if (single) return first(payload, ctx);
|
|
1331
|
+
let async = false;
|
|
1332
|
+
const results = [];
|
|
1333
|
+
for (const option of def.options) {
|
|
1334
|
+
const result = option._zod.run({
|
|
1335
|
+
value: payload.value,
|
|
1336
|
+
issues: []
|
|
1337
|
+
}, ctx);
|
|
1338
|
+
if (result instanceof Promise) {
|
|
1339
|
+
results.push(result);
|
|
1340
|
+
async = true;
|
|
1341
|
+
} else {
|
|
1342
|
+
if (result.issues.length === 0) return result;
|
|
1343
|
+
results.push(result);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
if (!async) return handleUnionResults(results, payload, inst, ctx);
|
|
1347
|
+
return Promise.all(results).then((results$1) => {
|
|
1348
|
+
return handleUnionResults(results$1, payload, inst, ctx);
|
|
1349
|
+
});
|
|
1350
|
+
};
|
|
1351
|
+
});
|
|
1352
|
+
const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
1353
|
+
$ZodType.init(inst, def);
|
|
1354
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1355
|
+
const input = payload.value;
|
|
1356
|
+
if (!isPlainObject(input)) {
|
|
1357
|
+
payload.issues.push({
|
|
1358
|
+
expected: "record",
|
|
1359
|
+
code: "invalid_type",
|
|
1360
|
+
input,
|
|
1361
|
+
inst
|
|
1362
|
+
});
|
|
1363
|
+
return payload;
|
|
1364
|
+
}
|
|
1365
|
+
const proms = [];
|
|
1366
|
+
if (def.keyType._zod.values) {
|
|
1367
|
+
const values = def.keyType._zod.values;
|
|
1368
|
+
payload.value = {};
|
|
1369
|
+
for (const key of values) if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
1370
|
+
const result = def.valueType._zod.run({
|
|
1371
|
+
value: input[key],
|
|
1372
|
+
issues: []
|
|
1373
|
+
}, ctx);
|
|
1374
|
+
if (result instanceof Promise) proms.push(result.then((result$1) => {
|
|
1375
|
+
if (result$1.issues.length) payload.issues.push(...prefixIssues(key, result$1.issues));
|
|
1376
|
+
payload.value[key] = result$1.value;
|
|
1377
|
+
}));
|
|
1378
|
+
else {
|
|
1379
|
+
if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
|
|
1380
|
+
payload.value[key] = result.value;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
let unrecognized;
|
|
1384
|
+
for (const key in input) if (!values.has(key)) {
|
|
1385
|
+
unrecognized = unrecognized ?? [];
|
|
1386
|
+
unrecognized.push(key);
|
|
1387
|
+
}
|
|
1388
|
+
if (unrecognized && unrecognized.length > 0) payload.issues.push({
|
|
1389
|
+
code: "unrecognized_keys",
|
|
1390
|
+
input,
|
|
1391
|
+
inst,
|
|
1392
|
+
keys: unrecognized
|
|
1393
|
+
});
|
|
1394
|
+
} else {
|
|
1395
|
+
payload.value = {};
|
|
1396
|
+
for (const key of Reflect.ownKeys(input)) {
|
|
1397
|
+
if (key === "__proto__") continue;
|
|
1398
|
+
const keyResult = def.keyType._zod.run({
|
|
1399
|
+
value: key,
|
|
1400
|
+
issues: []
|
|
1401
|
+
}, ctx);
|
|
1402
|
+
if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
|
|
1403
|
+
if (keyResult.issues.length) {
|
|
1404
|
+
payload.issues.push({
|
|
1405
|
+
code: "invalid_key",
|
|
1406
|
+
origin: "record",
|
|
1407
|
+
issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
|
|
1408
|
+
input: key,
|
|
1409
|
+
path: [key],
|
|
1410
|
+
inst
|
|
1411
|
+
});
|
|
1412
|
+
payload.value[keyResult.value] = keyResult.value;
|
|
1413
|
+
continue;
|
|
1414
|
+
}
|
|
1415
|
+
const result = def.valueType._zod.run({
|
|
1416
|
+
value: input[key],
|
|
1417
|
+
issues: []
|
|
1418
|
+
}, ctx);
|
|
1419
|
+
if (result instanceof Promise) proms.push(result.then((result$1) => {
|
|
1420
|
+
if (result$1.issues.length) payload.issues.push(...prefixIssues(key, result$1.issues));
|
|
1421
|
+
payload.value[keyResult.value] = result$1.value;
|
|
1422
|
+
}));
|
|
1423
|
+
else {
|
|
1424
|
+
if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
|
|
1425
|
+
payload.value[keyResult.value] = result.value;
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1430
|
+
return payload;
|
|
1431
|
+
};
|
|
1432
|
+
});
|
|
1433
|
+
const $ZodMap = /* @__PURE__ */ $constructor("$ZodMap", (inst, def) => {
|
|
1434
|
+
$ZodType.init(inst, def);
|
|
1435
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1436
|
+
const input = payload.value;
|
|
1437
|
+
if (!(input instanceof Map)) {
|
|
1438
|
+
payload.issues.push({
|
|
1439
|
+
expected: "map",
|
|
1440
|
+
code: "invalid_type",
|
|
1441
|
+
input,
|
|
1442
|
+
inst
|
|
1443
|
+
});
|
|
1444
|
+
return payload;
|
|
1445
|
+
}
|
|
1446
|
+
const proms = [];
|
|
1447
|
+
payload.value = /* @__PURE__ */ new Map();
|
|
1448
|
+
for (const [key, value] of input) {
|
|
1449
|
+
const keyResult = def.keyType._zod.run({
|
|
1450
|
+
value: key,
|
|
1451
|
+
issues: []
|
|
1452
|
+
}, ctx);
|
|
1453
|
+
const valueResult = def.valueType._zod.run({
|
|
1454
|
+
value,
|
|
1455
|
+
issues: []
|
|
1456
|
+
}, ctx);
|
|
1457
|
+
if (keyResult instanceof Promise || valueResult instanceof Promise) proms.push(Promise.all([keyResult, valueResult]).then(([keyResult$1, valueResult$1]) => {
|
|
1458
|
+
handleMapResult(keyResult$1, valueResult$1, payload, key, input, inst, ctx);
|
|
1459
|
+
}));
|
|
1460
|
+
else handleMapResult(keyResult, valueResult, payload, key, input, inst, ctx);
|
|
1461
|
+
}
|
|
1462
|
+
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1463
|
+
return payload;
|
|
1464
|
+
};
|
|
1465
|
+
});
|
|
1466
|
+
function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
|
|
1467
|
+
if (keyResult.issues.length) if (propertyKeyTypes.has(typeof key)) final.issues.push(...prefixIssues(key, keyResult.issues));
|
|
1468
|
+
else final.issues.push({
|
|
1469
|
+
code: "invalid_key",
|
|
1470
|
+
origin: "map",
|
|
1471
|
+
input,
|
|
1472
|
+
inst,
|
|
1473
|
+
issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
1474
|
+
});
|
|
1475
|
+
if (valueResult.issues.length) if (propertyKeyTypes.has(typeof key)) final.issues.push(...prefixIssues(key, valueResult.issues));
|
|
1476
|
+
else final.issues.push({
|
|
1477
|
+
origin: "map",
|
|
1478
|
+
code: "invalid_element",
|
|
1479
|
+
input,
|
|
1480
|
+
inst,
|
|
1481
|
+
key,
|
|
1482
|
+
issues: valueResult.issues.map((iss) => finalizeIssue(iss, ctx, config()))
|
|
1483
|
+
});
|
|
1484
|
+
final.value.set(keyResult.value, valueResult.value);
|
|
1485
|
+
}
|
|
1486
|
+
const $ZodSet = /* @__PURE__ */ $constructor("$ZodSet", (inst, def) => {
|
|
1487
|
+
$ZodType.init(inst, def);
|
|
1488
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1489
|
+
const input = payload.value;
|
|
1490
|
+
if (!(input instanceof Set)) {
|
|
1491
|
+
payload.issues.push({
|
|
1492
|
+
input,
|
|
1493
|
+
inst,
|
|
1494
|
+
expected: "set",
|
|
1495
|
+
code: "invalid_type"
|
|
1496
|
+
});
|
|
1497
|
+
return payload;
|
|
1498
|
+
}
|
|
1499
|
+
const proms = [];
|
|
1500
|
+
payload.value = /* @__PURE__ */ new Set();
|
|
1501
|
+
for (const item of input) {
|
|
1502
|
+
const result = def.valueType._zod.run({
|
|
1503
|
+
value: item,
|
|
1504
|
+
issues: []
|
|
1505
|
+
}, ctx);
|
|
1506
|
+
if (result instanceof Promise) proms.push(result.then((result$1) => handleSetResult(result$1, payload)));
|
|
1507
|
+
else handleSetResult(result, payload);
|
|
1508
|
+
}
|
|
1509
|
+
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1510
|
+
return payload;
|
|
1511
|
+
};
|
|
1512
|
+
});
|
|
1513
|
+
function handleSetResult(result, final) {
|
|
1514
|
+
if (result.issues.length) final.issues.push(...result.issues);
|
|
1515
|
+
final.value.add(result.value);
|
|
1516
|
+
}
|
|
1517
|
+
const $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
|
|
1518
|
+
$ZodType.init(inst, def);
|
|
1519
|
+
if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
|
|
1520
|
+
inst._zod.values = new Set(def.values);
|
|
1521
|
+
inst._zod.pattern = /* @__PURE__ */ new RegExp(`^(${def.values.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$`);
|
|
1522
|
+
inst._zod.parse = (payload, _ctx) => {
|
|
1523
|
+
const input = payload.value;
|
|
1524
|
+
if (inst._zod.values.has(input)) return payload;
|
|
1525
|
+
payload.issues.push({
|
|
1526
|
+
code: "invalid_value",
|
|
1527
|
+
values: def.values,
|
|
1528
|
+
input,
|
|
1529
|
+
inst
|
|
1530
|
+
});
|
|
1531
|
+
return payload;
|
|
1532
|
+
};
|
|
1533
|
+
});
|
|
1534
|
+
function handleOptionalResult(result, input) {
|
|
1535
|
+
if (result.issues.length && input === void 0) return {
|
|
1536
|
+
issues: [],
|
|
1537
|
+
value: void 0
|
|
1538
|
+
};
|
|
1539
|
+
return result;
|
|
1540
|
+
}
|
|
1541
|
+
const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
1542
|
+
$ZodType.init(inst, def);
|
|
1543
|
+
inst._zod.optin = "optional";
|
|
1544
|
+
inst._zod.optout = "optional";
|
|
1545
|
+
defineLazy(inst._zod, "values", () => {
|
|
1546
|
+
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, void 0]) : void 0;
|
|
1547
|
+
});
|
|
1548
|
+
defineLazy(inst._zod, "pattern", () => {
|
|
1549
|
+
const pattern = def.innerType._zod.pattern;
|
|
1550
|
+
return pattern ? /* @__PURE__ */ new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
1551
|
+
});
|
|
1552
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1553
|
+
if (def.innerType._zod.optin === "optional") {
|
|
1554
|
+
const result = def.innerType._zod.run(payload, ctx);
|
|
1555
|
+
if (result instanceof Promise) return result.then((r) => handleOptionalResult(r, payload.value));
|
|
1556
|
+
return handleOptionalResult(result, payload.value);
|
|
1557
|
+
}
|
|
1558
|
+
if (payload.value === void 0) return payload;
|
|
1559
|
+
return def.innerType._zod.run(payload, ctx);
|
|
1560
|
+
};
|
|
1561
|
+
});
|
|
1562
|
+
const $ZodLazy = /* @__PURE__ */ $constructor("$ZodLazy", (inst, def) => {
|
|
1563
|
+
$ZodType.init(inst, def);
|
|
1564
|
+
defineLazy(inst._zod, "innerType", () => def.getter());
|
|
1565
|
+
defineLazy(inst._zod, "pattern", () => inst._zod.innerType._zod.pattern);
|
|
1566
|
+
defineLazy(inst._zod, "propValues", () => inst._zod.innerType._zod.propValues);
|
|
1567
|
+
defineLazy(inst._zod, "optin", () => inst._zod.innerType._zod.optin ?? void 0);
|
|
1568
|
+
defineLazy(inst._zod, "optout", () => inst._zod.innerType._zod.optout ?? void 0);
|
|
1569
|
+
inst._zod.parse = (payload, ctx) => {
|
|
1570
|
+
return inst._zod.innerType._zod.run(payload, ctx);
|
|
1571
|
+
};
|
|
1572
|
+
});
|
|
1573
|
+
|
|
1574
|
+
//#endregion
|
|
1575
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/core/api.js
|
|
1576
|
+
function _string(Class, params) {
|
|
1577
|
+
return new Class({
|
|
1578
|
+
type: "string",
|
|
1579
|
+
...normalizeParams(params)
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
function _number(Class, params) {
|
|
1583
|
+
return new Class({
|
|
1584
|
+
type: "number",
|
|
1585
|
+
checks: [],
|
|
1586
|
+
...normalizeParams(params)
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
function _boolean(Class, params) {
|
|
1590
|
+
return new Class({
|
|
1591
|
+
type: "boolean",
|
|
1592
|
+
...normalizeParams(params)
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
function _bigint(Class, params) {
|
|
1596
|
+
return new Class({
|
|
1597
|
+
type: "bigint",
|
|
1598
|
+
...normalizeParams(params)
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
function _undefined$1(Class, params) {
|
|
1602
|
+
return new Class({
|
|
1603
|
+
type: "undefined",
|
|
1604
|
+
...normalizeParams(params)
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
function _null$1(Class, params) {
|
|
1608
|
+
return new Class({
|
|
1609
|
+
type: "null",
|
|
1610
|
+
...normalizeParams(params)
|
|
1611
|
+
});
|
|
1612
|
+
}
|
|
1613
|
+
function _unknown(Class) {
|
|
1614
|
+
return new Class({ type: "unknown" });
|
|
1615
|
+
}
|
|
1616
|
+
function _date(Class, params) {
|
|
1617
|
+
return new Class({
|
|
1618
|
+
type: "date",
|
|
1619
|
+
...normalizeParams(params)
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
//#endregion
|
|
1624
|
+
//#region ../../node_modules/.pnpm/zod@4.1.11/node_modules/zod/v4/mini/schemas.js
|
|
1625
|
+
const ZodMiniType = /* @__PURE__ */ $constructor("ZodMiniType", (inst, def) => {
|
|
1626
|
+
if (!inst._zod) throw new Error("Uninitialized schema in ZodMiniType.");
|
|
1627
|
+
$ZodType.init(inst, def);
|
|
1628
|
+
inst.def = def;
|
|
1629
|
+
inst.type = def.type;
|
|
1630
|
+
inst.parse = (data, params) => parse$1(inst, data, params, { callee: inst.parse });
|
|
1631
|
+
inst.safeParse = (data, params) => safeParse(inst, data, params);
|
|
1632
|
+
inst.parseAsync = async (data, params) => parseAsync(inst, data, params, { callee: inst.parseAsync });
|
|
1633
|
+
inst.safeParseAsync = async (data, params) => safeParseAsync(inst, data, params);
|
|
1634
|
+
inst.check = (...checks) => {
|
|
1635
|
+
return inst.clone({
|
|
1636
|
+
...def,
|
|
1637
|
+
checks: [...def.checks ?? [], ...checks.map((ch) => typeof ch === "function" ? { _zod: {
|
|
1638
|
+
check: ch,
|
|
1639
|
+
def: { check: "custom" },
|
|
1640
|
+
onattach: []
|
|
1641
|
+
} } : ch)]
|
|
1642
|
+
});
|
|
1643
|
+
};
|
|
1644
|
+
inst.clone = (_def, params) => clone(inst, _def, params);
|
|
1645
|
+
inst.brand = () => inst;
|
|
1646
|
+
inst.register = ((reg, meta) => {
|
|
1647
|
+
reg.add(inst, meta);
|
|
1648
|
+
return inst;
|
|
1649
|
+
});
|
|
1650
|
+
});
|
|
1651
|
+
const ZodMiniString = /* @__PURE__ */ $constructor("ZodMiniString", (inst, def) => {
|
|
1652
|
+
$ZodString.init(inst, def);
|
|
1653
|
+
ZodMiniType.init(inst, def);
|
|
1654
|
+
});
|
|
1655
|
+
function string(params) {
|
|
1656
|
+
return _string(ZodMiniString, params);
|
|
1657
|
+
}
|
|
1658
|
+
const ZodMiniNumber = /* @__PURE__ */ $constructor("ZodMiniNumber", (inst, def) => {
|
|
1659
|
+
$ZodNumber.init(inst, def);
|
|
1660
|
+
ZodMiniType.init(inst, def);
|
|
1661
|
+
});
|
|
1662
|
+
function number(params) {
|
|
1663
|
+
return _number(ZodMiniNumber, params);
|
|
1664
|
+
}
|
|
1665
|
+
const ZodMiniBoolean = /* @__PURE__ */ $constructor("ZodMiniBoolean", (inst, def) => {
|
|
1666
|
+
$ZodBoolean.init(inst, def);
|
|
1667
|
+
ZodMiniType.init(inst, def);
|
|
1668
|
+
});
|
|
1669
|
+
function boolean(params) {
|
|
1670
|
+
return _boolean(ZodMiniBoolean, params);
|
|
1671
|
+
}
|
|
1672
|
+
const ZodMiniBigInt = /* @__PURE__ */ $constructor("ZodMiniBigInt", (inst, def) => {
|
|
1673
|
+
$ZodBigInt.init(inst, def);
|
|
1674
|
+
ZodMiniType.init(inst, def);
|
|
1675
|
+
});
|
|
1676
|
+
function bigint(params) {
|
|
1677
|
+
return _bigint(ZodMiniBigInt, params);
|
|
1678
|
+
}
|
|
1679
|
+
const ZodMiniUndefined = /* @__PURE__ */ $constructor("ZodMiniUndefined", (inst, def) => {
|
|
1680
|
+
$ZodUndefined.init(inst, def);
|
|
1681
|
+
ZodMiniType.init(inst, def);
|
|
1682
|
+
});
|
|
1683
|
+
function _undefined(params) {
|
|
1684
|
+
return _undefined$1(ZodMiniUndefined, params);
|
|
1685
|
+
}
|
|
1686
|
+
const ZodMiniNull = /* @__PURE__ */ $constructor("ZodMiniNull", (inst, def) => {
|
|
1687
|
+
$ZodNull.init(inst, def);
|
|
1688
|
+
ZodMiniType.init(inst, def);
|
|
1689
|
+
});
|
|
1690
|
+
function _null(params) {
|
|
1691
|
+
return _null$1(ZodMiniNull, params);
|
|
1692
|
+
}
|
|
1693
|
+
const ZodMiniUnknown = /* @__PURE__ */ $constructor("ZodMiniUnknown", (inst, def) => {
|
|
1694
|
+
$ZodUnknown.init(inst, def);
|
|
1695
|
+
ZodMiniType.init(inst, def);
|
|
1696
|
+
});
|
|
1697
|
+
function unknown() {
|
|
1698
|
+
return _unknown(ZodMiniUnknown);
|
|
1699
|
+
}
|
|
1700
|
+
const ZodMiniDate = /* @__PURE__ */ $constructor("ZodMiniDate", (inst, def) => {
|
|
1701
|
+
$ZodDate.init(inst, def);
|
|
1702
|
+
ZodMiniType.init(inst, def);
|
|
1703
|
+
});
|
|
1704
|
+
function date(params) {
|
|
1705
|
+
return _date(ZodMiniDate, params);
|
|
1706
|
+
}
|
|
1707
|
+
const ZodMiniArray = /* @__PURE__ */ $constructor("ZodMiniArray", (inst, def) => {
|
|
1708
|
+
$ZodArray.init(inst, def);
|
|
1709
|
+
ZodMiniType.init(inst, def);
|
|
1710
|
+
});
|
|
1711
|
+
function array(element, params) {
|
|
1712
|
+
return new ZodMiniArray({
|
|
1713
|
+
type: "array",
|
|
1714
|
+
element,
|
|
1715
|
+
...normalizeParams(params)
|
|
1716
|
+
});
|
|
1717
|
+
}
|
|
1718
|
+
const ZodMiniObject = /* @__PURE__ */ $constructor("ZodMiniObject", (inst, def) => {
|
|
1719
|
+
$ZodObject.init(inst, def);
|
|
1720
|
+
ZodMiniType.init(inst, def);
|
|
1721
|
+
defineLazy(inst, "shape", () => def.shape);
|
|
1722
|
+
});
|
|
1723
|
+
function object(shape, params) {
|
|
1724
|
+
return new ZodMiniObject({
|
|
1725
|
+
type: "object",
|
|
1726
|
+
shape: shape ?? {},
|
|
1727
|
+
...normalizeParams(params)
|
|
1728
|
+
});
|
|
1729
|
+
}
|
|
1730
|
+
const ZodMiniUnion = /* @__PURE__ */ $constructor("ZodMiniUnion", (inst, def) => {
|
|
1731
|
+
$ZodUnion.init(inst, def);
|
|
1732
|
+
ZodMiniType.init(inst, def);
|
|
1733
|
+
});
|
|
1734
|
+
function union(options, params) {
|
|
1735
|
+
return new ZodMiniUnion({
|
|
1736
|
+
type: "union",
|
|
1737
|
+
options,
|
|
1738
|
+
...normalizeParams(params)
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
const ZodMiniRecord = /* @__PURE__ */ $constructor("ZodMiniRecord", (inst, def) => {
|
|
1742
|
+
$ZodRecord.init(inst, def);
|
|
1743
|
+
ZodMiniType.init(inst, def);
|
|
1744
|
+
});
|
|
1745
|
+
function record(keyType, valueType, params) {
|
|
1746
|
+
return new ZodMiniRecord({
|
|
1747
|
+
type: "record",
|
|
1748
|
+
keyType,
|
|
1749
|
+
valueType,
|
|
1750
|
+
...normalizeParams(params)
|
|
1751
|
+
});
|
|
1752
|
+
}
|
|
1753
|
+
const ZodMiniMap = /* @__PURE__ */ $constructor("ZodMiniMap", (inst, def) => {
|
|
1754
|
+
$ZodMap.init(inst, def);
|
|
1755
|
+
ZodMiniType.init(inst, def);
|
|
1756
|
+
});
|
|
1757
|
+
function map(keyType, valueType, params) {
|
|
1758
|
+
return new ZodMiniMap({
|
|
1759
|
+
type: "map",
|
|
1760
|
+
keyType,
|
|
1761
|
+
valueType,
|
|
1762
|
+
...normalizeParams(params)
|
|
1763
|
+
});
|
|
1764
|
+
}
|
|
1765
|
+
const ZodMiniSet = /* @__PURE__ */ $constructor("ZodMiniSet", (inst, def) => {
|
|
1766
|
+
$ZodSet.init(inst, def);
|
|
1767
|
+
ZodMiniType.init(inst, def);
|
|
1768
|
+
});
|
|
1769
|
+
function set(valueType, params) {
|
|
1770
|
+
return new ZodMiniSet({
|
|
1771
|
+
type: "set",
|
|
1772
|
+
valueType,
|
|
1773
|
+
...normalizeParams(params)
|
|
1774
|
+
});
|
|
1775
|
+
}
|
|
1776
|
+
const ZodMiniLiteral = /* @__PURE__ */ $constructor("ZodMiniLiteral", (inst, def) => {
|
|
1777
|
+
$ZodLiteral.init(inst, def);
|
|
1778
|
+
ZodMiniType.init(inst, def);
|
|
1779
|
+
});
|
|
1780
|
+
function literal(value, params) {
|
|
1781
|
+
return new ZodMiniLiteral({
|
|
1782
|
+
type: "literal",
|
|
1783
|
+
values: Array.isArray(value) ? value : [value],
|
|
1784
|
+
...normalizeParams(params)
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
const ZodMiniOptional = /* @__PURE__ */ $constructor("ZodMiniOptional", (inst, def) => {
|
|
1788
|
+
$ZodOptional.init(inst, def);
|
|
1789
|
+
ZodMiniType.init(inst, def);
|
|
1790
|
+
});
|
|
1791
|
+
function optional(innerType) {
|
|
1792
|
+
return new ZodMiniOptional({
|
|
1793
|
+
type: "optional",
|
|
1794
|
+
innerType
|
|
1795
|
+
});
|
|
1796
|
+
}
|
|
1797
|
+
const ZodMiniLazy = /* @__PURE__ */ $constructor("ZodMiniLazy", (inst, def) => {
|
|
1798
|
+
$ZodLazy.init(inst, def);
|
|
1799
|
+
ZodMiniType.init(inst, def);
|
|
1800
|
+
});
|
|
1801
|
+
function _lazy(getter) {
|
|
1802
|
+
return new ZodMiniLazy({
|
|
1803
|
+
type: "lazy",
|
|
1804
|
+
getter
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
//#endregion
|
|
1809
|
+
//#region src/import.ts
|
|
1810
|
+
const importSchema = object({
|
|
1811
|
+
__cc_import: literal(true),
|
|
1812
|
+
path: string(),
|
|
1813
|
+
name: optional(string())
|
|
1814
|
+
});
|
|
765
1815
|
function isImport(value) {
|
|
766
|
-
|
|
1816
|
+
return value && value.__cc_import;
|
|
767
1817
|
}
|
|
768
|
-
function createDefaultImport(
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
1818
|
+
function createDefaultImport(path$1) {
|
|
1819
|
+
return {
|
|
1820
|
+
__cc_import: true,
|
|
1821
|
+
path: path$1
|
|
1822
|
+
};
|
|
773
1823
|
}
|
|
774
|
-
function createNamedImport(name,
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
1824
|
+
function createNamedImport(name, path$1) {
|
|
1825
|
+
return {
|
|
1826
|
+
__cc_import: true,
|
|
1827
|
+
path: path$1,
|
|
1828
|
+
name
|
|
1829
|
+
};
|
|
780
1830
|
}
|
|
781
1831
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
1832
|
+
//#endregion
|
|
1833
|
+
//#region src/serializer.ts
|
|
1834
|
+
const literalSchema = union([
|
|
1835
|
+
string(),
|
|
1836
|
+
number(),
|
|
1837
|
+
boolean(),
|
|
1838
|
+
_null(),
|
|
1839
|
+
_undefined(),
|
|
1840
|
+
date(),
|
|
1841
|
+
map(unknown(), unknown()),
|
|
1842
|
+
set(unknown()),
|
|
1843
|
+
bigint(),
|
|
1844
|
+
importSchema
|
|
795
1845
|
]);
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
)
|
|
799
|
-
|
|
800
|
-
|
|
1846
|
+
const schema = _lazy(() => union([
|
|
1847
|
+
literalSchema,
|
|
1848
|
+
array(schema),
|
|
1849
|
+
record(string(), schema)
|
|
1850
|
+
]));
|
|
1851
|
+
const extension = "js";
|
|
1852
|
+
const serializableSchema = record(string(), schema);
|
|
801
1853
|
function createImport(imp, variableName) {
|
|
802
|
-
|
|
803
|
-
return `import ${variableDeclaration} from "${imp.path}";
|
|
804
|
-
`;
|
|
1854
|
+
return `import ${imp.name ? `{ ${imp.name} as ${variableName} }` : variableName} from "${imp.path}";\n`;
|
|
805
1855
|
}
|
|
806
1856
|
function serialize(value) {
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
return `__v_${index}`;
|
|
831
|
-
});
|
|
832
|
-
serializedValue += "export default " + js;
|
|
833
|
-
return serializedValue;
|
|
1857
|
+
let serializedValue = "";
|
|
1858
|
+
let counter = 0;
|
|
1859
|
+
function handleImports(item) {
|
|
1860
|
+
if (item instanceof Object) Object.entries(item).forEach(([key, value$1]) => {
|
|
1861
|
+
if (isImport(value$1)) {
|
|
1862
|
+
counter++;
|
|
1863
|
+
const variableName = `__v_${counter}`;
|
|
1864
|
+
serializedValue += createImport(value$1, variableName);
|
|
1865
|
+
item[key] = variableName;
|
|
1866
|
+
} else if (value$1 instanceof Object) handleImports(value$1);
|
|
1867
|
+
});
|
|
1868
|
+
}
|
|
1869
|
+
value.forEach(handleImports);
|
|
1870
|
+
serializedValue += "\n";
|
|
1871
|
+
const js = serializeJs(value, {
|
|
1872
|
+
space: 2,
|
|
1873
|
+
unsafe: true,
|
|
1874
|
+
ignoreFunction: true
|
|
1875
|
+
}).replace(/"__v_(\d+)"/g, (_, index) => {
|
|
1876
|
+
return `__v_${index}`;
|
|
1877
|
+
});
|
|
1878
|
+
serializedValue += "export default " + js;
|
|
1879
|
+
return serializedValue;
|
|
834
1880
|
}
|
|
835
1881
|
|
|
836
|
-
|
|
1882
|
+
//#endregion
|
|
1883
|
+
//#region src/transformer.ts
|
|
837
1884
|
var TransformError = class extends Error {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1885
|
+
type;
|
|
1886
|
+
constructor(type, message) {
|
|
1887
|
+
super(message);
|
|
1888
|
+
this.type = type;
|
|
1889
|
+
}
|
|
843
1890
|
};
|
|
844
1891
|
function isSkippedSignal(signal) {
|
|
845
|
-
|
|
1892
|
+
return signal[skippedSymbol] === true;
|
|
1893
|
+
}
|
|
1894
|
+
function createPath(path$1, ext) {
|
|
1895
|
+
let p = path$1.slice(0, -ext.length);
|
|
1896
|
+
if (p.endsWith("/index")) p = p.slice(0, -6);
|
|
1897
|
+
return p;
|
|
846
1898
|
}
|
|
847
|
-
function
|
|
848
|
-
|
|
849
|
-
if (p.endsWith("/index")) {
|
|
850
|
-
p = p.slice(0, -6);
|
|
851
|
-
}
|
|
852
|
-
return p;
|
|
1899
|
+
function isContentDefined(value) {
|
|
1900
|
+
return value !== null && typeof value === "object" && "content" in value;
|
|
853
1901
|
}
|
|
854
1902
|
function createTransformer(emitter, cacheManager) {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
}
|
|
988
|
-
return collection.documents;
|
|
989
|
-
}
|
|
990
|
-
async function validateDocuments(collection, documents) {
|
|
991
|
-
const docs = [];
|
|
992
|
-
for (const doc of documents) {
|
|
993
|
-
let parsedData = await serializableSchema.safeParseAsync(doc.document);
|
|
994
|
-
if (parsedData.success) {
|
|
995
|
-
docs.push(doc);
|
|
996
|
-
} else {
|
|
997
|
-
emitter.emit("transformer:result-error", {
|
|
998
|
-
collection,
|
|
999
|
-
document: doc.document,
|
|
1000
|
-
error: new TransformError("Result", parsedData.error.message)
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
return docs;
|
|
1005
|
-
}
|
|
1006
|
-
return async (untransformedCollections) => {
|
|
1007
|
-
const promises = untransformedCollections.map(
|
|
1008
|
-
(collection) => parseCollection(collection)
|
|
1009
|
-
);
|
|
1010
|
-
const collections = await Promise.all(promises);
|
|
1011
|
-
for (const collection of collections) {
|
|
1012
|
-
const documents = await transformCollection(collections, collection);
|
|
1013
|
-
collection.documents = await validateDocuments(collection, documents);
|
|
1014
|
-
}
|
|
1015
|
-
return collections;
|
|
1016
|
-
};
|
|
1903
|
+
const deprecatedWarnings = /* @__PURE__ */ new Set();
|
|
1904
|
+
function warnImplicitContentProperty(collection) {
|
|
1905
|
+
const key = `implicitContentProperty:${collection.name}`;
|
|
1906
|
+
if (deprecatedWarnings.has(key)) return;
|
|
1907
|
+
deprecatedWarnings.add(key);
|
|
1908
|
+
deprecated("implicitContentProperty");
|
|
1909
|
+
}
|
|
1910
|
+
async function parseFile(collection, file) {
|
|
1911
|
+
const { data, path: path$1 } = file;
|
|
1912
|
+
const parsedData = await collection.schema["~standard"].validate(data);
|
|
1913
|
+
if (parsedData.issues) {
|
|
1914
|
+
emitter.emit("transformer:validation-error", {
|
|
1915
|
+
collection,
|
|
1916
|
+
file,
|
|
1917
|
+
error: new TransformError("Validation", parsedData.issues.map((issue) => issue.message).join(", "))
|
|
1918
|
+
});
|
|
1919
|
+
return null;
|
|
1920
|
+
}
|
|
1921
|
+
let values = parsedData.value;
|
|
1922
|
+
if (getParser(collection.parser).hasContent && !isContentDefined(values)) {
|
|
1923
|
+
warnImplicitContentProperty(collection);
|
|
1924
|
+
if (typeof data.content !== "string") {
|
|
1925
|
+
emitter.emit("transformer:validation-error", {
|
|
1926
|
+
collection,
|
|
1927
|
+
file,
|
|
1928
|
+
error: new TransformError("Validation", `The content property is not a string`)
|
|
1929
|
+
});
|
|
1930
|
+
return null;
|
|
1931
|
+
}
|
|
1932
|
+
values = {
|
|
1933
|
+
...values,
|
|
1934
|
+
content: data.content
|
|
1935
|
+
};
|
|
1936
|
+
}
|
|
1937
|
+
const ext = extname(path$1);
|
|
1938
|
+
let extension$1 = ext;
|
|
1939
|
+
if (extension$1.startsWith(".")) extension$1 = extension$1.slice(1);
|
|
1940
|
+
return { document: {
|
|
1941
|
+
...values,
|
|
1942
|
+
_meta: {
|
|
1943
|
+
filePath: path$1,
|
|
1944
|
+
fileName: basename(path$1),
|
|
1945
|
+
directory: dirname(path$1),
|
|
1946
|
+
extension: extension$1,
|
|
1947
|
+
path: createPath(path$1, ext)
|
|
1948
|
+
}
|
|
1949
|
+
} };
|
|
1950
|
+
}
|
|
1951
|
+
async function parseCollection(collection) {
|
|
1952
|
+
const promises = collection.files.map((file) => parseFile(collection, file));
|
|
1953
|
+
return {
|
|
1954
|
+
...collection,
|
|
1955
|
+
documents: (await Promise.all(promises)).filter(isDefined)
|
|
1956
|
+
};
|
|
1957
|
+
}
|
|
1958
|
+
function createContext(collections, collection, cache) {
|
|
1959
|
+
return {
|
|
1960
|
+
documents: (collection$1) => {
|
|
1961
|
+
const resolved = collections.find((c) => c.name === collection$1.name);
|
|
1962
|
+
if (!resolved) throw new TransformError("Configuration", `Collection ${collection$1.name} not found, do you have registered it in your configuration?`);
|
|
1963
|
+
return resolved.documents.map((doc) => doc.document);
|
|
1964
|
+
},
|
|
1965
|
+
collection: {
|
|
1966
|
+
name: collection.name,
|
|
1967
|
+
directory: collection.directory,
|
|
1968
|
+
documents: async () => {
|
|
1969
|
+
return collection.documents.map((doc) => doc.document);
|
|
1970
|
+
}
|
|
1971
|
+
},
|
|
1972
|
+
cache: cache.cacheFn,
|
|
1973
|
+
skip: (reason) => ({
|
|
1974
|
+
[skippedSymbol]: true,
|
|
1975
|
+
reason
|
|
1976
|
+
})
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1979
|
+
async function transformDocument(collections, collection, transform, doc) {
|
|
1980
|
+
const cache = cacheManager.cache(collection.name, doc.document._meta.path);
|
|
1981
|
+
const context = createContext(collections, collection, cache);
|
|
1982
|
+
try {
|
|
1983
|
+
const document = await transform(doc.document, context);
|
|
1984
|
+
await cache.tidyUp();
|
|
1985
|
+
if (isSkippedSignal(document)) emitter.emit("transformer:document-skipped", {
|
|
1986
|
+
collection,
|
|
1987
|
+
filePath: join(collection.directory, doc.document._meta.filePath),
|
|
1988
|
+
reason: document.reason
|
|
1989
|
+
});
|
|
1990
|
+
else return {
|
|
1991
|
+
...doc,
|
|
1992
|
+
document
|
|
1993
|
+
};
|
|
1994
|
+
} catch (error) {
|
|
1995
|
+
if (error instanceof TransformError) emitter.emit("transformer:error", {
|
|
1996
|
+
collection,
|
|
1997
|
+
error
|
|
1998
|
+
});
|
|
1999
|
+
else emitter.emit("transformer:error", {
|
|
2000
|
+
collection,
|
|
2001
|
+
error: new TransformError("Transform", String(error))
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
async function transformCollection(collections, collection) {
|
|
2006
|
+
const transform = collection.transform;
|
|
2007
|
+
if (transform) {
|
|
2008
|
+
const limit = pLimit(os.cpus().length);
|
|
2009
|
+
const docs = collection.documents.map((doc) => limit(() => transformDocument(collections, collection, transform, doc)));
|
|
2010
|
+
const transformed = await Promise.all(docs);
|
|
2011
|
+
await cacheManager.flush();
|
|
2012
|
+
return transformed.filter(isDefined);
|
|
2013
|
+
}
|
|
2014
|
+
return collection.documents;
|
|
2015
|
+
}
|
|
2016
|
+
async function validateDocuments(collection, documents) {
|
|
2017
|
+
const docs = [];
|
|
2018
|
+
for (const doc of documents) {
|
|
2019
|
+
let parsedData = await serializableSchema.safeParseAsync(doc.document);
|
|
2020
|
+
if (parsedData.success) docs.push(doc);
|
|
2021
|
+
else emitter.emit("transformer:result-error", {
|
|
2022
|
+
collection,
|
|
2023
|
+
document: doc.document,
|
|
2024
|
+
error: new TransformError("Result", parsedData.error.message)
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
return docs;
|
|
2028
|
+
}
|
|
2029
|
+
return async (untransformedCollections) => {
|
|
2030
|
+
const promises = untransformedCollections.map((collection) => parseCollection(collection));
|
|
2031
|
+
const collections = await Promise.all(promises);
|
|
2032
|
+
for (const collection of collections) collection.documents = await validateDocuments(collection, await transformCollection(collections, collection));
|
|
2033
|
+
return collections;
|
|
2034
|
+
};
|
|
1017
2035
|
}
|
|
1018
2036
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
import path7 from "node:path";
|
|
1022
|
-
import pluralize2 from "pluralize";
|
|
2037
|
+
//#endregion
|
|
2038
|
+
//#region src/writer.ts
|
|
1023
2039
|
function createArrayConstName(name) {
|
|
1024
|
-
|
|
1025
|
-
return "all" + pluralize2(suffix);
|
|
2040
|
+
return "all" + pluralize(name.charAt(0).toUpperCase() + name.slice(1));
|
|
1026
2041
|
}
|
|
1027
2042
|
async function createDataFile(directory, collection) {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
`${createArrayConstName(collection.name)}.${extension}`
|
|
1031
|
-
);
|
|
1032
|
-
await fs3.writeFile(
|
|
1033
|
-
dataPath,
|
|
1034
|
-
serialize(collection.documents.map((doc) => doc.document))
|
|
1035
|
-
);
|
|
2043
|
+
const dataPath = path.join(directory, `${createArrayConstName(collection.name)}.${extension}`);
|
|
2044
|
+
await fs.writeFile(dataPath, serialize(collection.documents.map((doc) => doc.document)));
|
|
1036
2045
|
}
|
|
1037
2046
|
function createDataFiles(directory, collections) {
|
|
1038
|
-
|
|
1039
|
-
collections.map((collection) => createDataFile(directory, collection))
|
|
1040
|
-
);
|
|
2047
|
+
return Promise.all(collections.map((collection) => createDataFile(directory, collection)));
|
|
1041
2048
|
}
|
|
1042
2049
|
async function createJavaScriptFile(directory, configuration) {
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
for (const name of collections) {
|
|
1050
|
-
content += `import ${name} from "./${name}.${extension}";
|
|
1051
|
-
`;
|
|
1052
|
-
}
|
|
1053
|
-
content += "\n";
|
|
1054
|
-
content += "export { " + collections.join(", ") + " };\n";
|
|
1055
|
-
await fs3.writeFile(path7.join(directory, "index.js"), content, "utf-8");
|
|
2050
|
+
const collections = configuration.collections.map(({ name }) => createArrayConstName(name));
|
|
2051
|
+
let content = `// generated by content-collections at ${/* @__PURE__ */ new Date()}\n\n`;
|
|
2052
|
+
for (const name of collections) content += `import ${name} from "./${name}.${extension}";\n`;
|
|
2053
|
+
content += "\n";
|
|
2054
|
+
content += "export { " + collections.join(", ") + " };\n";
|
|
2055
|
+
await fs.writeFile(path.join(directory, "index.js"), content, "utf-8");
|
|
1056
2056
|
}
|
|
1057
2057
|
function createImportPath(directory, target) {
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
if (!importPath.startsWith(".")) {
|
|
1062
|
-
importPath = "./" + importPath;
|
|
1063
|
-
}
|
|
1064
|
-
return importPath;
|
|
2058
|
+
let importPath = path.posix.join(...path.relative(directory, target).split(path.sep));
|
|
2059
|
+
if (!importPath.startsWith(".")) importPath = "./" + importPath;
|
|
2060
|
+
return importPath;
|
|
1065
2061
|
}
|
|
1066
2062
|
async function createTypeDefinitionFile(directory, configuration) {
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
}
|
|
1070
|
-
const importPath = createImportPath(directory, configuration.path);
|
|
1071
|
-
let content = `import configuration from "${importPath}";
|
|
2063
|
+
if (!configuration.generateTypes) return;
|
|
2064
|
+
let content = `import configuration from "${createImportPath(directory, configuration.path)}";
|
|
1072
2065
|
import { GetTypeByName } from "@content-collections/core";
|
|
1073
2066
|
`;
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
`;
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
`;
|
|
1084
|
-
}
|
|
1085
|
-
content += "\n";
|
|
1086
|
-
content += "export {};\n";
|
|
1087
|
-
await fs3.writeFile(path7.join(directory, "index.d.ts"), content, "utf-8");
|
|
2067
|
+
const collections = configuration.collections;
|
|
2068
|
+
for (const collection of collections) {
|
|
2069
|
+
content += `\n`;
|
|
2070
|
+
content += `export type ${collection.typeName} = GetTypeByName<typeof configuration, "${collection.name}">;\n`;
|
|
2071
|
+
content += `export declare const ${createArrayConstName(collection.name)}: Array<${collection.typeName}>;\n`;
|
|
2072
|
+
}
|
|
2073
|
+
content += "\n";
|
|
2074
|
+
content += "export {};\n";
|
|
2075
|
+
await fs.writeFile(path.join(directory, "index.d.ts"), content, "utf-8");
|
|
1088
2076
|
}
|
|
1089
2077
|
async function createWriter(directory) {
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
2078
|
+
await fs.mkdir(directory, { recursive: true });
|
|
2079
|
+
return {
|
|
2080
|
+
createJavaScriptFile: (configuration) => createJavaScriptFile(directory, configuration),
|
|
2081
|
+
createTypeDefinitionFile: (configuration) => createTypeDefinitionFile(directory, configuration),
|
|
2082
|
+
createDataFiles: (collections) => createDataFiles(directory, collections)
|
|
2083
|
+
};
|
|
1096
2084
|
}
|
|
1097
2085
|
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
writer.createTypeDefinitionFile(configuration),
|
|
1142
|
-
writer.createJavaScriptFile(configuration)
|
|
1143
|
-
]);
|
|
1144
|
-
const pendingOnSuccess = collections.filter((collection) => Boolean(collection.onSuccess)).map(
|
|
1145
|
-
(collection) => collection.onSuccess?.(collection.documents.map((doc) => doc.document))
|
|
1146
|
-
);
|
|
1147
|
-
await Promise.all(pendingOnSuccess.filter(isDefined));
|
|
1148
|
-
const stats = collections.reduce(
|
|
1149
|
-
(acc, collection) => {
|
|
1150
|
-
acc.collections++;
|
|
1151
|
-
acc.documents += collection.documents.length;
|
|
1152
|
-
return acc;
|
|
1153
|
-
},
|
|
1154
|
-
{
|
|
1155
|
-
collections: 0,
|
|
1156
|
-
documents: 0
|
|
1157
|
-
}
|
|
1158
|
-
);
|
|
1159
|
-
emitter.emit("builder:end", {
|
|
1160
|
-
startedAt,
|
|
1161
|
-
endedAt: Date.now(),
|
|
1162
|
-
stats
|
|
1163
|
-
});
|
|
2086
|
+
//#endregion
|
|
2087
|
+
//#region src/build.ts
|
|
2088
|
+
async function createBuildContext({ emitter, outputDirectory, baseDirectory, configuration }) {
|
|
2089
|
+
const collector = createCollector(emitter, baseDirectory);
|
|
2090
|
+
const [writer, resolved, cacheManager] = await Promise.all([
|
|
2091
|
+
createWriter(outputDirectory),
|
|
2092
|
+
collector.collect(configuration.collections),
|
|
2093
|
+
createCacheManager(baseDirectory, configuration.checksum)
|
|
2094
|
+
]);
|
|
2095
|
+
return {
|
|
2096
|
+
resolved,
|
|
2097
|
+
writer,
|
|
2098
|
+
synchronizer: createSynchronizer(collector.collectFile, resolved, baseDirectory),
|
|
2099
|
+
transform: createTransformer(emitter, cacheManager),
|
|
2100
|
+
emitter,
|
|
2101
|
+
cacheManager,
|
|
2102
|
+
configuration
|
|
2103
|
+
};
|
|
2104
|
+
}
|
|
2105
|
+
async function build$1({ emitter, transform, resolved, writer, configuration }) {
|
|
2106
|
+
const startedAt = Date.now();
|
|
2107
|
+
emitter.emit("builder:start", { startedAt });
|
|
2108
|
+
const collections = await transform(resolved);
|
|
2109
|
+
await Promise.all([
|
|
2110
|
+
writer.createDataFiles(collections),
|
|
2111
|
+
writer.createTypeDefinitionFile(configuration),
|
|
2112
|
+
writer.createJavaScriptFile(configuration)
|
|
2113
|
+
]);
|
|
2114
|
+
const pendingOnSuccess = collections.filter((collection) => Boolean(collection.onSuccess)).map((collection) => collection.onSuccess?.(collection.documents.map((doc) => doc.document)));
|
|
2115
|
+
await Promise.all(pendingOnSuccess.filter(isDefined));
|
|
2116
|
+
const stats = collections.reduce((acc, collection) => {
|
|
2117
|
+
acc.collections++;
|
|
2118
|
+
acc.documents += collection.documents.length;
|
|
2119
|
+
return acc;
|
|
2120
|
+
}, {
|
|
2121
|
+
collections: 0,
|
|
2122
|
+
documents: 0
|
|
2123
|
+
});
|
|
2124
|
+
emitter.emit("builder:end", {
|
|
2125
|
+
startedAt,
|
|
2126
|
+
endedAt: Date.now(),
|
|
2127
|
+
stats
|
|
2128
|
+
});
|
|
1164
2129
|
}
|
|
1165
2130
|
|
|
1166
|
-
|
|
1167
|
-
|
|
2131
|
+
//#endregion
|
|
2132
|
+
//#region src/events.ts
|
|
1168
2133
|
function isEventWithError(event) {
|
|
1169
|
-
|
|
2134
|
+
return typeof event === "object" && event !== null && "error" in event;
|
|
1170
2135
|
}
|
|
1171
2136
|
function createEmitter() {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
emit
|
|
1192
|
-
};
|
|
2137
|
+
const emitter = new EventEmitter();
|
|
2138
|
+
function on(key, listener) {
|
|
2139
|
+
emitter.on(key, listener);
|
|
2140
|
+
}
|
|
2141
|
+
function emit(key, event) {
|
|
2142
|
+
emitter.emit(key, event);
|
|
2143
|
+
if (isEventWithError(event)) emitter.emit("_error", {
|
|
2144
|
+
...event,
|
|
2145
|
+
_event: key
|
|
2146
|
+
});
|
|
2147
|
+
emitter.emit("_all", {
|
|
2148
|
+
...event,
|
|
2149
|
+
_event: key
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
return {
|
|
2153
|
+
on,
|
|
2154
|
+
emit
|
|
2155
|
+
};
|
|
1193
2156
|
}
|
|
1194
2157
|
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
import path8, { dirname as dirname3, resolve } from "node:path";
|
|
2158
|
+
//#endregion
|
|
2159
|
+
//#region src/watcher.ts
|
|
1198
2160
|
async function createWatcher(emitter, baseDirectory, configuration, sync) {
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
emitter.emit("watcher:subscribed", {
|
|
1236
|
-
paths
|
|
1237
|
-
});
|
|
1238
|
-
resolve2();
|
|
1239
|
-
});
|
|
1240
|
-
watcher.on("error", reject);
|
|
1241
|
-
});
|
|
1242
|
-
return {
|
|
1243
|
-
unsubscribe: async () => {
|
|
1244
|
-
await watcher.close();
|
|
1245
|
-
emitter.emit("watcher:unsubscribed", {
|
|
1246
|
-
paths
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
};
|
|
2161
|
+
const paths = removeChildPaths([...configuration.collections.map((collection) => path.join(baseDirectory, collection.directory)).map((p) => resolve(p)), ...configuration.inputPaths.map((p) => dirname(p))]);
|
|
2162
|
+
const watcher = chokidar.watch(paths, {
|
|
2163
|
+
ignored: [/(^|[\/\\])\../, /(^|[\/\\])node_modules([\/\\]|$)/],
|
|
2164
|
+
persistent: true,
|
|
2165
|
+
ignoreInitial: true
|
|
2166
|
+
});
|
|
2167
|
+
const handleEvent = async (modification, filePath) => {
|
|
2168
|
+
try {
|
|
2169
|
+
await sync(modification, filePath);
|
|
2170
|
+
} catch (error) {
|
|
2171
|
+
emitter.emit("watcher:subscribe-error", {
|
|
2172
|
+
paths,
|
|
2173
|
+
error: toError(error)
|
|
2174
|
+
});
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
watcher.on("add", (filePath) => handleEvent("create", filePath));
|
|
2178
|
+
watcher.on("change", (filePath) => handleEvent("update", filePath));
|
|
2179
|
+
watcher.on("unlink", (filePath) => handleEvent("delete", filePath));
|
|
2180
|
+
watcher.on("error", (error) => {
|
|
2181
|
+
emitter.emit("watcher:subscribe-error", {
|
|
2182
|
+
paths,
|
|
2183
|
+
error: toError(error)
|
|
2184
|
+
});
|
|
2185
|
+
});
|
|
2186
|
+
await new Promise((resolve$1, reject) => {
|
|
2187
|
+
watcher.on("ready", () => {
|
|
2188
|
+
emitter.emit("watcher:subscribed", { paths });
|
|
2189
|
+
resolve$1();
|
|
2190
|
+
});
|
|
2191
|
+
watcher.on("error", reject);
|
|
2192
|
+
});
|
|
2193
|
+
return { unsubscribe: async () => {
|
|
2194
|
+
await watcher.close();
|
|
2195
|
+
emitter.emit("watcher:unsubscribed", { paths });
|
|
2196
|
+
} };
|
|
1250
2197
|
}
|
|
1251
2198
|
|
|
1252
|
-
|
|
2199
|
+
//#endregion
|
|
2200
|
+
//#region src/builder.ts
|
|
1253
2201
|
function resolveOutputDir(baseDirectory, options) {
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
}
|
|
1257
|
-
return path9.join(baseDirectory, ".content-collections", "generated");
|
|
2202
|
+
if (options.outputDir) return options.outputDir;
|
|
2203
|
+
return path.join(baseDirectory, ".content-collections", "generated");
|
|
1258
2204
|
}
|
|
1259
2205
|
var ConfigurationReloadError = class extends Error {
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
2206
|
+
constructor(message) {
|
|
2207
|
+
super(message);
|
|
2208
|
+
}
|
|
1263
2209
|
};
|
|
1264
|
-
async function createBuilder(configurationPath, options = {
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
const baseDirectory = path9.dirname(configurationPath);
|
|
1269
|
-
const configuration = await readConfiguration(configurationPath, options);
|
|
1270
|
-
return createInternalBuilder(
|
|
1271
|
-
configuration,
|
|
1272
|
-
baseDirectory,
|
|
1273
|
-
options,
|
|
1274
|
-
emitter
|
|
1275
|
-
);
|
|
2210
|
+
async function createBuilder(configurationPath, options = { configName: defaultConfigName }, emitter = createEmitter()) {
|
|
2211
|
+
const readConfiguration = createConfigurationReader();
|
|
2212
|
+
const baseDirectory = path.dirname(configurationPath);
|
|
2213
|
+
return createInternalBuilder(await readConfiguration(configurationPath, options), baseDirectory, options, emitter);
|
|
1276
2214
|
}
|
|
1277
2215
|
async function createInternalBuilder(initialConfiguration, baseDirectory, options, emitter) {
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
async function watch() {
|
|
1356
|
-
watcher = await createWatcher(emitter, baseDirectory, configuration, sync);
|
|
1357
|
-
return {
|
|
1358
|
-
unsubscribe: async () => {
|
|
1359
|
-
if (watcher) {
|
|
1360
|
-
await watcher.unsubscribe();
|
|
1361
|
-
}
|
|
1362
|
-
}
|
|
1363
|
-
};
|
|
1364
|
-
}
|
|
1365
|
-
return {
|
|
1366
|
-
build: () => build3(context2),
|
|
1367
|
-
sync,
|
|
1368
|
-
watch,
|
|
1369
|
-
on: emitter.on
|
|
1370
|
-
};
|
|
1371
|
-
}
|
|
1372
|
-
export {
|
|
1373
|
-
CollectError,
|
|
1374
|
-
ConfigurationError,
|
|
1375
|
-
ConfigurationReloadError,
|
|
1376
|
-
TransformError,
|
|
1377
|
-
createBuilder,
|
|
1378
|
-
createDefaultImport,
|
|
1379
|
-
createInternalBuilder,
|
|
1380
|
-
createNamedImport,
|
|
1381
|
-
defineCollection,
|
|
1382
|
-
defineConfig,
|
|
1383
|
-
defineParser,
|
|
1384
|
-
skippedSymbol,
|
|
1385
|
-
suppressDeprecatedWarnings
|
|
1386
|
-
};
|
|
2216
|
+
const readConfiguration = createConfigurationReader();
|
|
2217
|
+
const configurationPath = initialConfiguration.path;
|
|
2218
|
+
const outputDirectory = resolveOutputDir(baseDirectory, options);
|
|
2219
|
+
emitter.emit("builder:created", {
|
|
2220
|
+
createdAt: Date.now(),
|
|
2221
|
+
configurationPath,
|
|
2222
|
+
outputDirectory
|
|
2223
|
+
});
|
|
2224
|
+
let configuration = initialConfiguration;
|
|
2225
|
+
let watcher = null;
|
|
2226
|
+
let context = await createBuildContext({
|
|
2227
|
+
emitter,
|
|
2228
|
+
baseDirectory,
|
|
2229
|
+
outputDirectory,
|
|
2230
|
+
configuration
|
|
2231
|
+
});
|
|
2232
|
+
async function sync(modification, filePath) {
|
|
2233
|
+
if (configuration.inputPaths.includes(filePath)) {
|
|
2234
|
+
if (await onConfigurationChange()) {
|
|
2235
|
+
emitter.emit("watcher:config-changed", {
|
|
2236
|
+
filePath,
|
|
2237
|
+
modification
|
|
2238
|
+
});
|
|
2239
|
+
await build$1(context);
|
|
2240
|
+
return true;
|
|
2241
|
+
}
|
|
2242
|
+
} else if (await onFileChange(modification, filePath)) {
|
|
2243
|
+
emitter.emit("watcher:file-changed", {
|
|
2244
|
+
filePath,
|
|
2245
|
+
modification
|
|
2246
|
+
});
|
|
2247
|
+
await build$1(context);
|
|
2248
|
+
return true;
|
|
2249
|
+
}
|
|
2250
|
+
return false;
|
|
2251
|
+
}
|
|
2252
|
+
async function onConfigurationChange() {
|
|
2253
|
+
try {
|
|
2254
|
+
configuration = await readConfiguration(configurationPath, options);
|
|
2255
|
+
} catch (error) {
|
|
2256
|
+
emitter.emit("watcher:config-reload-error", {
|
|
2257
|
+
error: new ConfigurationReloadError(`Failed to reload configuration: ${error}`),
|
|
2258
|
+
configurationPath
|
|
2259
|
+
});
|
|
2260
|
+
return false;
|
|
2261
|
+
}
|
|
2262
|
+
if (watcher) await watcher.unsubscribe();
|
|
2263
|
+
context = await createBuildContext({
|
|
2264
|
+
emitter,
|
|
2265
|
+
baseDirectory,
|
|
2266
|
+
outputDirectory,
|
|
2267
|
+
configuration
|
|
2268
|
+
});
|
|
2269
|
+
if (watcher) watcher = await createWatcher(emitter, baseDirectory, configuration, sync);
|
|
2270
|
+
return true;
|
|
2271
|
+
}
|
|
2272
|
+
async function onFileChange(modification, filePath) {
|
|
2273
|
+
const { synchronizer } = context;
|
|
2274
|
+
if (modification === "delete") return synchronizer.deleted(filePath);
|
|
2275
|
+
else return synchronizer.changed(filePath);
|
|
2276
|
+
}
|
|
2277
|
+
async function watch() {
|
|
2278
|
+
watcher = await createWatcher(emitter, baseDirectory, configuration, sync);
|
|
2279
|
+
return { unsubscribe: async () => {
|
|
2280
|
+
if (watcher) await watcher.unsubscribe();
|
|
2281
|
+
} };
|
|
2282
|
+
}
|
|
2283
|
+
return {
|
|
2284
|
+
build: () => build$1(context),
|
|
2285
|
+
sync,
|
|
2286
|
+
watch,
|
|
2287
|
+
on: emitter.on
|
|
2288
|
+
};
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
//#endregion
|
|
2292
|
+
export { CollectError, ConfigurationError, ConfigurationReloadError, TransformError, createBuilder, createDefaultImport, createInternalBuilder, createNamedImport, defineCollection, defineConfig, defineParser, skippedSymbol, suppressDeprecatedWarnings };
|