content-query 0.2.0 → 0.4.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 +28 -3
- package/dist/{build-Dxz7P1ur.mjs → build-CcqIpkes.mjs} +763 -39
- package/dist/build-DL1GzmRy.d.mts +55 -0
- package/dist/build.d.mts +2 -2
- package/dist/build.mjs +1 -1
- package/dist/cli.mjs +14 -8
- package/dist/computed.d.mts +2 -2
- package/dist/{content-N1gYshjg.mjs → content-BXrgP7nL.mjs} +271 -81
- package/dist/{content-G69dPPuo.d.mts → content-CwTKqRs9.d.mts} +49 -24
- package/dist/{types-ChaNhj42.d.mts → descriptor-bcPa6XLk.d.mts} +26 -1
- package/dist/{diagnostics-Cu94mZhl.mjs → diagnostics-DmUZtrJ6.mjs} +3 -1
- package/dist/{errors-C2iuBM0G.mjs → errors-Bfd0R4_P.mjs} +16 -1
- package/dist/file-DSOcdFj0.mjs +81 -0
- package/dist/{glob-Bv0dpvCQ.mjs → glob-BXJuwy_p.mjs} +94 -6
- package/dist/index.d.mts +61 -17
- package/dist/index.mjs +1 -1
- package/dist/internal.d.mts +11 -4
- package/dist/internal.mjs +29 -5
- package/dist/loaders.d.mts +2 -3
- package/dist/loaders.mjs +2 -81
- package/dist/next.d.mts +1 -1
- package/dist/next.mjs +2 -2
- package/dist/{operators-UqWUhKQJ.mjs → operators-Cwy8Kx4o.mjs} +88 -2
- package/dist/query-style-eXENQJ0O.d.mts +22 -0
- package/dist/query.d.mts +25 -2
- package/dist/query.mjs +1 -1
- package/dist/{relational-types-DgK3rLuw.d.mts → relational-types-C8xJtLG5.d.mts} +113 -38
- package/dist/runtime.d.mts +3 -2
- package/dist/runtime.mjs +1 -1
- package/dist/types-DbFfF6JE.d.mts +181 -0
- package/dist/vite.d.mts +15 -3
- package/dist/vite.mjs +25 -2
- package/package.json +2 -2
- package/dist/build-DfKd2bpf.d.mts +0 -25
- package/dist/descriptor-D9Th5hzk.d.mts +0 -18
- package/dist/types-C-kdMblM.d.mts +0 -69
- package/dist/validation-D_XdE1pF.mjs +0 -84
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { p as MaybePromise } from "./types-ChaNhj42.mjs";
|
|
2
|
-
//#region src/loaders/descriptor.d.ts
|
|
3
|
-
type GlobOptions = {
|
|
4
|
-
pattern: string | string[];
|
|
5
|
-
base?: string | URL;
|
|
6
|
-
generateId?: (context: {
|
|
7
|
-
entry: string;
|
|
8
|
-
base: URL;
|
|
9
|
-
data: Record<string, unknown>;
|
|
10
|
-
}) => string;
|
|
11
|
-
retainBody?: boolean;
|
|
12
|
-
deferRender?: boolean;
|
|
13
|
-
};
|
|
14
|
-
type FileOptions = {
|
|
15
|
-
parser?: (text: string) => MaybePromise<unknown>;
|
|
16
|
-
};
|
|
17
|
-
//#endregion
|
|
18
|
-
export { GlobOptions as n, FileOptions as t };
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { a as Loader } from "./types-ChaNhj42.mjs";
|
|
2
|
-
import { n as ContentRenderResult } from "./types-Dh-Sydyw.mjs";
|
|
3
|
-
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
4
|
-
//#region src/collection/types.d.ts
|
|
5
|
-
declare const builtinPayloadsType: unique symbol;
|
|
6
|
-
type Schema = StandardSchemaV1;
|
|
7
|
-
type SchemaOutput<Value> = Value extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Value> : Record<string, unknown>;
|
|
8
|
-
type ComputedContext<Data, Source = unknown> = {
|
|
9
|
-
/** The collection's key in the configured registry. */
|
|
10
|
-
collection: string;
|
|
11
|
-
id: string;
|
|
12
|
-
/** Loader-provided source metadata, detached from stored entries for this resolver. */
|
|
13
|
-
source?: Source extends object ? Readonly<Source> : Source;
|
|
14
|
-
data: Readonly<Data>;
|
|
15
|
-
readBody(this: void): Promise<string | undefined>;
|
|
16
|
-
signal: AbortSignal;
|
|
17
|
-
};
|
|
18
|
-
type ComputedDefinition<Data = Record<string, unknown>, Source = unknown> = {
|
|
19
|
-
schema: Schema;
|
|
20
|
-
resolve(context: ComputedContext<Data, Source>): unknown;
|
|
21
|
-
};
|
|
22
|
-
type Relationship = {
|
|
23
|
-
collection: string;
|
|
24
|
-
type: "one" | "many";
|
|
25
|
-
from: string;
|
|
26
|
-
to: string;
|
|
27
|
-
referenceSide: "from" | "to" | "none";
|
|
28
|
-
};
|
|
29
|
-
type CollectionDefinition<SourceSchema extends Schema | undefined = Schema | undefined, Computed extends Record<string, ComputedDefinition<never, never>> = Record<string, ComputedDefinition<never, never>>, Relationships extends Record<string, Relationship> = Record<string, Relationship>> = {
|
|
30
|
-
loader: Loader;
|
|
31
|
-
schema?: SourceSchema;
|
|
32
|
-
computed?: Computed;
|
|
33
|
-
relationships?: Relationships;
|
|
34
|
-
};
|
|
35
|
-
type CollectionRegistry = Record<string, CollectionDefinition>;
|
|
36
|
-
type EntryData<Definition> = Definition extends {
|
|
37
|
-
schema: infer SourceSchema;
|
|
38
|
-
} ? SchemaOutput<SourceSchema> : Record<string, unknown>;
|
|
39
|
-
type ComputedData<Definition> = Definition extends {
|
|
40
|
-
computed: infer Computed;
|
|
41
|
-
} ? { [Name in keyof Computed]: Computed[Name] extends {
|
|
42
|
-
schema: infer ResultSchema;
|
|
43
|
-
} ? SchemaOutput<ResultSchema> : never; } : {};
|
|
44
|
-
type QueryData<Definition> = {
|
|
45
|
-
id: string;
|
|
46
|
-
} & EntryData<Definition> & ComputedData<Definition>;
|
|
47
|
-
type RelationshipsOf<Definition> = Definition extends {
|
|
48
|
-
relationships: infer Relationships;
|
|
49
|
-
} ? Relationships : {};
|
|
50
|
-
/**
|
|
51
|
-
* Payloads that Markdown sources, `glob()`, and custom loaders provide for every entry.
|
|
52
|
-
* Built-in names start with an underscore, so they never collide with custom payloads.
|
|
53
|
-
*/
|
|
54
|
-
type BuiltinPayloads = {
|
|
55
|
-
/** The retained raw body, or undefined when the entry has none or retention is disabled. */
|
|
56
|
-
_body: string | undefined;
|
|
57
|
-
/** HTML and headings; entries without a rendering path reject with `not-renderable`. */
|
|
58
|
-
_rendered: ContentRenderResult;
|
|
59
|
-
};
|
|
60
|
-
/** Type-only marker recording whether a defined collection carries built-in payloads. */
|
|
61
|
-
type BuiltinPayloadMarker<Available extends boolean> = {
|
|
62
|
-
readonly [builtinPayloadsType]?: Available;
|
|
63
|
-
};
|
|
64
|
-
/** Payload names and value types that queries can request for a collection definition. */
|
|
65
|
-
type PayloadsOf<Definition> = Definition extends {
|
|
66
|
-
readonly [builtinPayloadsType]?: infer Available;
|
|
67
|
-
} ? [Available] extends [false | undefined] ? {} : BuiltinPayloads : BuiltinPayloads;
|
|
68
|
-
//#endregion
|
|
69
|
-
export { ComputedContext as a, Relationship as c, SchemaOutput as d, CollectionRegistry as i, RelationshipsOf as l, BuiltinPayloads as n, PayloadsOf as o, CollectionDefinition as r, QueryData as s, BuiltinPayloadMarker as t, Schema as u };
|
|
@@ -1,84 +0,0 @@
|
|
|
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 };
|