content-query 0.3.0 → 0.5.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 (39) hide show
  1. package/README.md +46 -15
  2. package/dist/{build-CI4s0oFP.mjs → build-DWpB69_c.mjs} +826 -69
  3. package/dist/{build-jKnjDjQE.d.mts → build-DfoncKL8.d.mts} +17 -5
  4. package/dist/build.d.mts +1 -1
  5. package/dist/build.mjs +1 -1
  6. package/dist/cli.mjs +14 -8
  7. package/dist/{content-N1gYshjg.mjs → collection-Cb5eWGnv.mjs} +998 -344
  8. package/dist/collection-types-CsQtGw7_.d.mts +119 -0
  9. package/dist/computed.d.mts +2 -2
  10. package/dist/{types-FmUJ3cH1.d.mts → descriptor-bcPa6XLk.d.mts} +17 -1
  11. package/dist/{diagnostics-Cu94mZhl.mjs → diagnostics-DmUZtrJ6.mjs} +3 -1
  12. package/dist/{errors-C2iuBM0G.mjs → errors-Bfd0R4_P.mjs} +16 -1
  13. package/dist/file-DSOcdFj0.mjs +81 -0
  14. package/dist/{glob-Bv0dpvCQ.mjs → glob-BXJuwy_p.mjs} +94 -6
  15. package/dist/index.d.mts +76 -18
  16. package/dist/index.mjs +1 -1
  17. package/dist/internal.d.mts +54 -7
  18. package/dist/internal.mjs +424 -19
  19. package/dist/loaders.d.mts +1 -2
  20. package/dist/loaders.mjs +2 -81
  21. package/dist/next.d.mts +3 -2
  22. package/dist/next.mjs +67 -14
  23. package/dist/operators-D-w1-gDg.mjs +391 -0
  24. package/dist/query-style-C2FcT1f9.d.mts +23 -0
  25. package/dist/query.d.mts +25 -2
  26. package/dist/query.mjs +1 -1
  27. package/dist/{relational-types-B45zM34W.d.mts → relational-types-CTcalUNW.d.mts} +241 -50
  28. package/dist/revision-DBwU-aC9.d.mts +56 -0
  29. package/dist/runtime.d.mts +3 -2
  30. package/dist/runtime.mjs +1 -1
  31. package/dist/types-Dz1vTXa2.d.mts +214 -0
  32. package/dist/vite.d.mts +1 -1
  33. package/dist/vite.mjs +77 -35
  34. package/package.json +1 -1
  35. package/dist/content-lwPxE9Yu.d.mts +0 -109
  36. package/dist/descriptor-BUPT2J7X.d.mts +0 -18
  37. package/dist/operators-UqWUhKQJ.mjs +0 -173
  38. package/dist/types-BC8gVJ6u.d.mts +0 -69
  39. package/dist/validation-D_XdE1pF.mjs +0 -84
@@ -1,173 +0,0 @@
1
- import { a as invalidQuery } from "./errors-C2iuBM0G.mjs";
2
- import { c as isScalar, i as detach } from "./values-BbTV4QT-.mjs";
3
- //#region src/query/operators.ts
4
- /** Builds a checked, backend-independent predicate instead of a per-entry callback. */
5
- function predicate(operator, field, value) {
6
- if (!field || typeof field.name !== "string" || !field.name) invalidQuery("A filter must reference a query field.");
7
- if ([
8
- "in-array",
9
- "not-in-array",
10
- "array-contains-any",
11
- "array-contains-all",
12
- "array-contained"
13
- ].includes(operator)) {
14
- if (!Array.isArray(value) || !value.every(isScalar)) invalidQuery("Choice arguments must be arrays of scalar values.");
15
- } else if ([
16
- "contains",
17
- "starts-with",
18
- "ends-with",
19
- "like",
20
- "ilike"
21
- ].includes(operator)) {
22
- if (typeof value !== "string") invalidQuery("String predicates require a string argument.");
23
- } else if (!operator.startsWith("is-") && !isScalar(value)) invalidQuery("This predicate requires a scalar argument.");
24
- if ([
25
- "gt",
26
- "gte",
27
- "lt",
28
- "lte"
29
- ].includes(operator) && (value == null || typeof value === "boolean")) invalidQuery("Range predicates require a string, number, bigint, or date.");
30
- return {
31
- kind: "predicate",
32
- operator,
33
- field: field.name,
34
- value: detach(value)
35
- };
36
- }
37
- /** Matches a scalar using strict value/date equality. */
38
- function eq(field, value) {
39
- return predicate("eq", field, value);
40
- }
41
- /** Negates scalar equality. */
42
- function ne(field, value) {
43
- return predicate("ne", field, value);
44
- }
45
- /** Matches values greater than the supplied scalar. */
46
- function gt(field, value) {
47
- return predicate("gt", field, value);
48
- }
49
- /** Matches values greater than or equal to the supplied scalar. */
50
- function gte(field, value) {
51
- return predicate("gte", field, value);
52
- }
53
- /** Matches values less than the supplied scalar. */
54
- function lt(field, value) {
55
- return predicate("lt", field, value);
56
- }
57
- /** Matches values less than or equal to the supplied scalar. */
58
- function lte(field, value) {
59
- return predicate("lte", field, value);
60
- }
61
- /** Matches one of a list of scalar choices. */
62
- function inArray(field, values) {
63
- return predicate("in-array", field, values);
64
- }
65
- /** Matches none of a list of scalar choices. */
66
- function notInArray(field, values) {
67
- return predicate("not-in-array", field, values);
68
- }
69
- /** Matches a literal substring, without SQL wildcard interpretation. */
70
- function contains(field, value) {
71
- return predicate("contains", field, value);
72
- }
73
- /** Matches a literal string prefix. */
74
- function startsWith(field, value) {
75
- return predicate("starts-with", field, value);
76
- }
77
- /** Matches a literal string suffix. */
78
- function endsWith(field, value) {
79
- return predicate("ends-with", field, value);
80
- }
81
- /** Tests scalar membership in an array, ignoring holes. */
82
- function arrayContains(field, value) {
83
- return predicate("array-contains", field, value);
84
- }
85
- /** Tests whether any candidate belongs to an existing scalar array. */
86
- function arrayContainsAny(field, values) {
87
- return predicate("array-contains-any", field, values);
88
- }
89
- /** Tests whether every candidate belongs to an existing scalar array. */
90
- function arrayContainsAll(field, values) {
91
- return predicate("array-contains-all", field, values);
92
- }
93
- /** Checks explicit null independently from undefined and absence. */
94
- function isNull(field) {
95
- return predicate("is-null", field);
96
- }
97
- /** Checks undefined, including a missing property. */
98
- function isUndefined(field) {
99
- return predicate("is-undefined", field);
100
- }
101
- /** Checks own-property absence before projection. */
102
- function isMissing(field) {
103
- return predicate("is-missing", field);
104
- }
105
- /** Requires all child predicates; an empty conjunction is true. */
106
- function and(...expressions) {
107
- expressions.forEach(validateExpression);
108
- return {
109
- kind: "and",
110
- expressions
111
- };
112
- }
113
- /** Requires any child predicate; an empty disjunction is false. */
114
- function or(...expressions) {
115
- expressions.forEach(validateExpression);
116
- return {
117
- kind: "or",
118
- expressions
119
- };
120
- }
121
- /** Negates a predicate's boolean result. */
122
- function not(expression) {
123
- validateExpression(expression);
124
- return {
125
- kind: "not",
126
- expressions: [expression]
127
- };
128
- }
129
- /** Checks the shape of expression trees even when TypeScript was bypassed. */
130
- function validateExpression(expression) {
131
- if (!expression || typeof expression !== "object") invalidQuery("where() must return a structured expression.");
132
- if (expression.kind === "predicate") {
133
- if (![
134
- "eq",
135
- "ne",
136
- "gt",
137
- "gte",
138
- "lt",
139
- "lte",
140
- "in-array",
141
- "not-in-array",
142
- "contains",
143
- "starts-with",
144
- "ends-with",
145
- "like",
146
- "ilike",
147
- "array-contains",
148
- "array-contains-any",
149
- "array-contains-all",
150
- "array-contained",
151
- "is-null",
152
- "is-undefined",
153
- "is-missing"
154
- ].includes(expression.operator)) invalidQuery("Unknown filter operator.");
155
- predicate(expression.operator, { name: expression.field }, expression.value);
156
- } else if (expression.kind === "relation") {
157
- if ([
158
- expression.collection,
159
- expression.field,
160
- expression.target
161
- ].some((name) => typeof name !== "string" || !name)) invalidQuery("Relationship filters require registered collection and relationship names.");
162
- validateExpression(expression.expression);
163
- } else if ([
164
- "and",
165
- "or",
166
- "not"
167
- ].includes(expression.kind) && Array.isArray(expression.expressions)) {
168
- if (expression.kind === "not" && expression.expressions.length !== 1) invalidQuery("not() requires one expression.");
169
- expression.expressions.forEach(validateExpression);
170
- } else invalidQuery("Invalid expression structure.");
171
- }
172
- //#endregion
173
- export { not as _, contains as a, startsWith as b, gt as c, isMissing as d, isNull as f, ne as g, lte as h, arrayContainsAny as i, gte as l, lt as m, arrayContains as n, endsWith as o, isUndefined as p, arrayContainsAll as r, eq as s, and as t, inArray as u, notInArray as v, validateExpression as x, or as y };
@@ -1,69 +0,0 @@
1
- import { o as Loader } from "./types-FmUJ3cH1.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 which built-in payloads a defined collection carries. */
61
- type BuiltinPayloadMarker<Available extends keyof BuiltinPayloads> = {
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
- } ? Pick<BuiltinPayloads, Available & keyof 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 };