content-query 0.0.2 → 0.2.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.
Files changed (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +91 -2
  3. package/dist/build-DfKd2bpf.d.mts +25 -0
  4. package/dist/build-Dxz7P1ur.mjs +1439 -0
  5. package/dist/build.d.mts +2 -0
  6. package/dist/build.mjs +1 -0
  7. package/dist/cli.d.mts +1 -0
  8. package/dist/cli.mjs +97 -0
  9. package/dist/computed.d.mts +43 -0
  10. package/dist/computed.mjs +139 -0
  11. package/dist/content-G69dPPuo.d.mts +109 -0
  12. package/dist/content-N1gYshjg.mjs +1028 -0
  13. package/dist/descriptor-D9Th5hzk.d.mts +18 -0
  14. package/dist/diagnostics-Cu94mZhl.mjs +80 -0
  15. package/dist/dist-C7_FOzY_.mjs +5405 -0
  16. package/dist/errors-C2iuBM0G.mjs +72 -0
  17. package/dist/github-slugger-BMgR_Q0I.mjs +72 -0
  18. package/dist/glob-Bv0dpvCQ.mjs +159 -0
  19. package/dist/index.d.mts +78 -0
  20. package/dist/index.mjs +46 -0
  21. package/dist/internal/markdown.d.mts +5 -0
  22. package/dist/internal/markdown.mjs +1 -0
  23. package/dist/internal.d.mts +54 -0
  24. package/dist/internal.mjs +89 -0
  25. package/dist/loaders.d.mts +11 -0
  26. package/dist/loaders.mjs +86 -0
  27. package/dist/markdown-CHvBBJNa.mjs +54 -0
  28. package/dist/next.d.mts +20 -0
  29. package/dist/next.mjs +142 -0
  30. package/dist/operators-UqWUhKQJ.mjs +173 -0
  31. package/dist/query.d.mts +44 -0
  32. package/dist/query.mjs +1 -0
  33. package/dist/relational-types-DgK3rLuw.d.mts +278 -0
  34. package/dist/rolldown-runtime-Bg1v5YCA.mjs +34 -0
  35. package/dist/runtime.d.mts +3 -0
  36. package/dist/runtime.mjs +5 -0
  37. package/dist/schema-C5Str-E8.mjs +20 -0
  38. package/dist/schema.d.mts +11 -0
  39. package/dist/schema.mjs +1 -0
  40. package/dist/server-only-CIJUlyL-.mjs +7 -0
  41. package/dist/types-C-kdMblM.d.mts +69 -0
  42. package/dist/types-ChaNhj42.d.mts +143 -0
  43. package/dist/types-Dh-Sydyw.d.mts +20 -0
  44. package/dist/validation-D_XdE1pF.mjs +84 -0
  45. package/dist/values-BbTV4QT-.mjs +901 -0
  46. package/dist/vite.d.mts +6 -0
  47. package/dist/vite.mjs +296 -0
  48. package/package.json +92 -10
@@ -0,0 +1,84 @@
1
+ import { n as contentError, t as ContentError } from "./errors-C2iuBM0G.mjs";
2
+ import { i as detach } from "./values-BbTV4QT-.mjs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ //#region src/loaders/descriptor.ts
6
+ const builtinSymbol = Symbol.for("content-query.builtin-loader");
7
+ /** Finds library-owned loader settings without depending on module instance identity. */
8
+ function builtinLoader(loader) {
9
+ return loader[builtinSymbol];
10
+ }
11
+ /** Resolves a loader's watch root from the application root, including file URLs. */
12
+ function builtinPath(descriptor, root) {
13
+ if (descriptor.kind === "file") return path.resolve(root, descriptor.filename);
14
+ return descriptor.options.base instanceof URL ? path.resolve(fileURLToPath(descriptor.options.base)) : path.resolve(root, descriptor.options.base ?? ".");
15
+ }
16
+ //#endregion
17
+ //#region src/preparation/validation.ts
18
+ /** Checks records independently from validation-provider schema introspection. */
19
+ function isRecord(value) {
20
+ return !!value && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
21
+ }
22
+ /** Validates one result, retaining structured provider issues and their original detail. */
23
+ async function validate(schema, value, context) {
24
+ if (!schema) return value;
25
+ try {
26
+ const result = await schema["~standard"].validate(value);
27
+ if (result.issues) {
28
+ const firstPath = result.issues[0]?.path?.map((segment) => typeof segment === "object" ? segment.key : segment);
29
+ throw new ContentError({
30
+ ...context,
31
+ code: "validation-error",
32
+ message: result.issues.map((issue) => issue.message).join("; "),
33
+ issues: result.issues,
34
+ path: [...context.path ?? [], ...firstPath ?? []]
35
+ });
36
+ }
37
+ return result.value;
38
+ } catch (cause) {
39
+ throw contentError(cause, {
40
+ ...context,
41
+ code: "validation-error",
42
+ message: "Schema validation failed."
43
+ });
44
+ }
45
+ }
46
+ /** Checks loader transport structure and rejects duplicate snapshot/upsert identities. */
47
+ function normalizeSnapshot(entries, collection) {
48
+ if (!Array.isArray(entries)) throw new ContentError({
49
+ code: "source-error",
50
+ collection,
51
+ message: "load() must return an array of structured entries."
52
+ });
53
+ const snapshot = /* @__PURE__ */ new Map();
54
+ for (const entry of entries) {
55
+ if (!entry || typeof entry.id !== "string" || !entry.id || !isRecord(entry.data) || entry.body !== void 0 && typeof entry.body !== "string" || entry.source !== void 0 && typeof entry.source !== "string") throw new ContentError({
56
+ code: "source-error",
57
+ collection,
58
+ id: entry && typeof entry === "object" && typeof entry.id === "string" ? entry.id : void 0,
59
+ source: entry && typeof entry === "object" && typeof entry.source === "string" ? entry.source : void 0,
60
+ message: "Invalid structured loader entry."
61
+ });
62
+ if (snapshot.has(entry.id)) throw new ContentError({
63
+ code: "duplicate-id",
64
+ collection,
65
+ id: entry.id,
66
+ source: entry.source,
67
+ message: `Duplicate entry ID "${entry.id}".`
68
+ });
69
+ snapshot.set(entry.id, entry);
70
+ }
71
+ return snapshot;
72
+ }
73
+ /** Validates supplied rendering data and normalizes omitted headings. */
74
+ function renderedPayload(entry) {
75
+ if (entry.rendered === void 0) return;
76
+ const rendered = entry.rendered;
77
+ if (!rendered || typeof rendered.html !== "string" || rendered.metadata !== void 0 && (!isRecord(rendered.metadata) || rendered.metadata.headings !== void 0 && (!Array.isArray(rendered.metadata.headings) || rendered.metadata.headings.some((heading) => !heading || !Number.isInteger(heading.depth) || heading.depth < 1 || heading.depth > 6 || typeof heading.slug !== "string" || typeof heading.text !== "string")))) throw new Error("Invalid supplied HTML/headings payload.");
78
+ return {
79
+ html: rendered.html,
80
+ headings: detach(rendered.metadata?.headings ?? [])
81
+ };
82
+ }
83
+ //#endregion
84
+ export { builtinLoader as a, validate as i, normalizeSnapshot as n, builtinPath as o, renderedPayload as r, builtinSymbol as s, isRecord as t };