content-query 0.0.2 → 0.1.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 +69 -2
  3. package/dist/build-C5ef0kkR.mjs +1401 -0
  4. package/dist/build-DSyoRxkZ.d.mts +24 -0
  5. package/dist/build.d.mts +2 -0
  6. package/dist/build.mjs +2 -0
  7. package/dist/chunk-CJs4Fogs.mjs +34 -0
  8. package/dist/cli.d.mts +1 -0
  9. package/dist/cli.mjs +97 -0
  10. package/dist/computed.d.mts +37 -0
  11. package/dist/computed.mjs +138 -0
  12. package/dist/content-Crag1Uch.d.mts +99 -0
  13. package/dist/content-Dj2fQCJ5.mjs +902 -0
  14. package/dist/descriptor-Xbo9u5eR.d.mts +19 -0
  15. package/dist/diagnostics-Dol6ANtq.mjs +79 -0
  16. package/dist/dist-BQGVLZyl.mjs +5396 -0
  17. package/dist/errors-C8lWyiy2.mjs +72 -0
  18. package/dist/github-slugger-BCAkwEOL.mjs +72 -0
  19. package/dist/glob-DJmebCMM.mjs +159 -0
  20. package/dist/index.d.mts +60 -0
  21. package/dist/index.mjs +43 -0
  22. package/dist/internal/markdown.d.mts +7 -0
  23. package/dist/internal/markdown.mjs +2 -0
  24. package/dist/internal.d.mts +54 -0
  25. package/dist/internal.mjs +89 -0
  26. package/dist/loaders.d.mts +12 -0
  27. package/dist/loaders.mjs +85 -0
  28. package/dist/markdown-CZBL4Ux_.mjs +54 -0
  29. package/dist/next.d.mts +21 -0
  30. package/dist/next.mjs +142 -0
  31. package/dist/operators-BQpLfJlx.mjs +173 -0
  32. package/dist/query.d.mts +45 -0
  33. package/dist/query.mjs +2 -0
  34. package/dist/relational-types-DLniKi5S.d.mts +245 -0
  35. package/dist/runtime.d.mts +3 -0
  36. package/dist/runtime.mjs +6 -0
  37. package/dist/schema-CnCbMosm.mjs +20 -0
  38. package/dist/schema.d.mts +13 -0
  39. package/dist/schema.mjs +2 -0
  40. package/dist/server-only-CIE-FHx0.mjs +7 -0
  41. package/dist/types-BPh2cBPs.d.mts +48 -0
  42. package/dist/types-DcvHRmxO.d.mts +20 -0
  43. package/dist/types-hmDOw87q.d.mts +135 -0
  44. package/dist/validation-BvvjSUFc.mjs +84 -0
  45. package/dist/values-B7lo_2_x.mjs +900 -0
  46. package/dist/vite.d.mts +8 -0
  47. package/dist/vite.mjs +296 -0
  48. package/package.json +90 -10
@@ -0,0 +1,245 @@
1
+ import { a as Relationship, i as QueryData, n as CollectionRegistry, o as RelationshipsOf } from "./types-BPh2cBPs.mjs";
2
+
3
+ //#region src/query/plan.d.ts
4
+ type PredicateOperator = "eq" | "ne" | "gt" | "gte" | "lt" | "lte" | "in-array" | "not-in-array" | "contains" | "starts-with" | "ends-with" | "like" | "ilike" | "array-contains" | "array-contains-any" | "array-contains-all" | "array-contained" | "is-null" | "is-undefined" | "is-missing";
5
+ type Expression = {
6
+ kind: "predicate";
7
+ operator: PredicateOperator;
8
+ field: string;
9
+ value?: unknown;
10
+ } | {
11
+ kind: "relation";
12
+ collection: string;
13
+ field: string;
14
+ target: string;
15
+ expression: Expression;
16
+ } | {
17
+ kind: "and" | "or" | "not";
18
+ expressions: readonly Expression[];
19
+ };
20
+ type QueryPlan = {
21
+ collection: string;
22
+ select?: readonly string[];
23
+ allFields?: boolean;
24
+ exclude?: readonly string[];
25
+ filters: readonly Expression[];
26
+ order: readonly {
27
+ field: string;
28
+ direction: "asc" | "desc";
29
+ }[];
30
+ limit?: number;
31
+ offset?: number;
32
+ with: Readonly<Record<string, QueryPlan>>;
33
+ adjacent?: true | QueryPlan;
34
+ };
35
+ type QueryRegistry = Record<string, {
36
+ relationships: Record<string, Relationship>;
37
+ }>;
38
+ //#endregion
39
+ //#region src/query/types.d.ts
40
+ declare const queryType: unique symbol;
41
+ declare const fieldType: unique symbol;
42
+ type Field$1<Value> = {
43
+ readonly name: string;
44
+ readonly [fieldType]: Value;
45
+ };
46
+ type Fields<Data> = { readonly [Name in keyof Data]-?: Field$1<Data[Name]> };
47
+ type Scalar = string | number | bigint | boolean | Date | null | undefined;
48
+ type ScalarField<Value> = Field$1<Value> & ([Value] extends [Scalar] ? unknown : never);
49
+ type Ordered<Value> = NonNullable<Value> extends string ? unknown : NonNullable<Value> extends number ? unknown : NonNullable<Value> extends bigint ? unknown : NonNullable<Value> extends Date ? unknown : never;
50
+ type SortKey<Data> = { [Name in keyof Data]-?: Ordered<Data[Name]> extends never ? NonNullable<Data[Name]> extends boolean ? Name : never : Name }[keyof Data] & string;
51
+ type QueryInfo<Result = unknown, Selected extends boolean = boolean, Filtered extends boolean = boolean> = {
52
+ readonly [queryType]: {
53
+ result: Result;
54
+ selected: Selected;
55
+ filtered: Filtered;
56
+ };
57
+ };
58
+ type Simplify$1<Value> = { [Key in keyof Value]: Value[Key] };
59
+ type ResultOf<Configured> = Configured extends QueryInfo<infer Result> ? Result : never;
60
+ type FilteredOf<Configured> = Configured extends QueryInfo<unknown, boolean, infer Filtered> ? Filtered : false;
61
+ type RelationOf<Registry extends CollectionRegistry, Name extends keyof Registry, Key extends keyof RelationshipsOf<Registry[Name]>> = RelationshipsOf<Registry[Name]>[Key] & Relationship;
62
+ type RelatedName$1<Registry extends CollectionRegistry, Relation extends Relationship> = Relation["collection"] & keyof Registry & string;
63
+ /** Applies declared relationship cardinality, optional reference fields, and filtering to a result. */
64
+ type RelationshipResult<Definition, Relation extends Relationship, Result, Filtered extends boolean = false> = Relation["type"] extends "many" ? Result[] : Result | (Filtered extends true ? null : Relation["referenceSide"] extends "from" ? Relation["from"] extends keyof QueryData<Definition> ? null extends QueryData<Definition>[Relation["from"]] ? null : undefined extends QueryData<Definition>[Relation["from"]] ? null : never : null : null);
65
+ type RelationValue<Definition, Relation extends Relationship, Configured> = RelationshipResult<Definition, Relation, ResultOf<Configured>, FilteredOf<Configured>>;
66
+ type Query<Registry extends CollectionRegistry, Name extends keyof Registry & string, Result = {}, Selected extends boolean = false, Many extends boolean = true, Root extends boolean = true, Filtered extends boolean = false, AllowAdjacent extends boolean = true, Pagination extends boolean = true> = QueryInfo<Result, Selected, Filtered> & {
67
+ select<const Keys extends readonly [keyof QueryData<Registry[Name]> & string, ...(keyof QueryData<Registry[Name]> & string)[]]>(...keys: Keys): Query<Registry, Name, { [Key in Exclude<keyof Result, keyof QueryData<Registry[Name]>> | Keys[number]]: Key extends Keys[number] ? QueryData<Registry[Name]>[Key & keyof QueryData<Registry[Name]>] : Key extends keyof Result ? Result[Key] : never }, true, Many, Root, Filtered, AllowAdjacent, Pagination>;
68
+ where(configure: (fields: Fields<QueryData<Registry[Name]>>) => Expression): Query<Registry, Name, Result, Selected, Many, Root, true, AllowAdjacent, Pagination>;
69
+ with<Key extends keyof RelationshipsOf<Registry[Name]> & string, Configured extends QueryInfo<unknown, true>>(name: Key, configure: (query: Query<Registry, RelatedName$1<Registry, RelationOf<Registry, Name, Key>>, {}, false, RelationOf<Registry, Name, Key>["type"] extends "many" ? true : false, false, false, AllowAdjacent>) => Configured): Query<Registry, Name, Result & { [Property in Key]: RelationValue<Registry[Name], RelationOf<Registry, Name, Key>, Configured> }, true, Many, Root, Filtered, AllowAdjacent, Pagination>;
70
+ } & (Many extends true ? {
71
+ orderBy(field: SortKey<QueryData<Registry[Name]>>, direction?: "asc" | "desc"): Query<Registry, Name, Result, Selected, Many, Root, Filtered, AllowAdjacent, Pagination>;
72
+ } : {}) & (Many extends true ? Pagination extends true ? {
73
+ limit(value: number): Query<Registry, Name, Result, Selected, Many, Root, Filtered, AllowAdjacent, Pagination>;
74
+ offset(value: number): Query<Registry, Name, Result, Selected, Many, Root, Filtered, AllowAdjacent, Pagination>;
75
+ } : {} : {}) & (AllowAdjacent extends true ? {
76
+ selectAdjacent(): Query<Registry, Name, Result & {
77
+ _adjacent: Adjacent<{
78
+ id: string;
79
+ }>;
80
+ }, true, Many, Root, Filtered, AllowAdjacent, Pagination>;
81
+ selectAdjacent<Configured extends QueryInfo<unknown, true>>(configure: (siblings: Query<Registry, Name, {}, false, true, false, false, false, false>) => Configured): Query<Registry, Name, Result & {
82
+ _adjacent: Adjacent<ResultOf<Configured>>;
83
+ }, true, Many, Root, Filtered, AllowAdjacent, Pagination>;
84
+ selectAdjacent<const Options extends AdjacentOptions<Registry, Name>>(options: Options & CheckedOptions<Registry, Name, NoInfer<Options>, true, false, false>): Query<Registry, Name, Result & {
85
+ _adjacent: Adjacent<SelectionResult<Registry, Name, Options["select"]>>;
86
+ }, true, Many, Root, Filtered, AllowAdjacent, Pagination>;
87
+ } : {}) & (Root extends true ? {
88
+ all: Selected extends true ? () => Promise<Simplify$1<Result>[]> : never;
89
+ execute: Selected extends true ? () => Promise<Simplify$1<Result>[]> : never;
90
+ then: Selected extends true ? Promise<Simplify$1<Result>[]>["then"] : never;
91
+ first: Selected extends true ? () => Promise<Simplify$1<Result> | undefined> : never;
92
+ count(): Promise<number>;
93
+ } : {});
94
+ type Adjacent<Entry> = {
95
+ previous: Entry | null;
96
+ next: Entry | null;
97
+ };
98
+ type PresenceFilter = {
99
+ isNull?: boolean;
100
+ isUndefined?: boolean;
101
+ isMissing?: boolean;
102
+ };
103
+ type ScalarFilter<Value> = {
104
+ equals?: Value;
105
+ not?: Value | ScalarFilter<Value>;
106
+ in?: readonly Value[];
107
+ notIn?: readonly Value[];
108
+ } & (Ordered<Value> extends never ? {} : {
109
+ gt?: NonNullable<Value>;
110
+ gte?: NonNullable<Value>;
111
+ lt?: NonNullable<Value>;
112
+ lte?: NonNullable<Value>;
113
+ }) & (NonNullable<Value> extends string ? {
114
+ contains?: string;
115
+ startsWith?: string;
116
+ endsWith?: string;
117
+ } : {});
118
+ type FieldFilter$1<Value> = PresenceFilter & (NonNullable<Value> extends readonly (infer Item)[] ? Item extends Scalar ? {
119
+ has?: Item;
120
+ hasSome?: readonly Item[];
121
+ hasEvery?: readonly Item[];
122
+ } : {} : [Value] extends [Scalar] ? ScalarFilter<Value> : {});
123
+ type Where<Data> = { [Name in keyof Data]?: [Data[Name]] extends [Scalar] ? Data[Name] | FieldFilter$1<Data[Name]> : FieldFilter$1<Data[Name]> } & {
124
+ AND?: Where<Data> | readonly Where<Data>[];
125
+ OR?: readonly Where<Data>[];
126
+ NOT?: Where<Data> | readonly Where<Data>[];
127
+ };
128
+ type OrderBy<Data> = Partial<Record<SortKey<Data>, "asc" | "desc">>;
129
+ type ObjectScope<Registry extends CollectionRegistry, Name extends keyof Registry & string, Many extends boolean> = {
130
+ where?: Where<QueryData<Registry[Name]>> | ((fields: Fields<QueryData<Registry[Name]>>) => Expression);
131
+ } & (Many extends true ? {
132
+ orderBy?: OrderBy<QueryData<Registry[Name]>> | readonly OrderBy<QueryData<Registry[Name]>>[];
133
+ limit?: number;
134
+ offset?: number;
135
+ } : {});
136
+ type QueryOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string, Many extends boolean = true, AllowAdjacent extends boolean = true> = ObjectScope<Registry, Name, Many> & {
137
+ select: Selection<Registry, Name, AllowAdjacent>;
138
+ };
139
+ type AdjacentOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string> = Omit<QueryOptions<Registry, Name, true, false>, "limit" | "offset">;
140
+ type Selection<Registry extends CollectionRegistry, Name extends keyof Registry & string, AllowAdjacent extends boolean = true> = { [Field in keyof QueryData<Registry[Name]>]?: boolean } & { [Key in keyof RelationshipsOf<Registry[Name]>]?: QueryOptions<Registry, RelatedName$1<Registry, RelationOf<Registry, Name, Key>>, RelationOf<Registry, Name, Key>["type"] extends "many" ? true : false, AllowAdjacent> | false } & (AllowAdjacent extends true ? {
141
+ _adjacent?: true | AdjacentOptions<Registry, Name>;
142
+ } : {});
143
+ type ObjectRelationValue<Registry extends CollectionRegistry, Name extends keyof Registry & string, Key extends keyof RelationshipsOf<Registry[Name]>, Options> = Options extends {
144
+ select: infer Projection;
145
+ } ? RelationValue<Registry[Name], RelationOf<Registry, Name, Key>, QueryInfo<SelectionResult<Registry, RelatedName$1<Registry, RelationOf<Registry, Name, Key>>, Projection>, true, "where" extends keyof Options ? true : false>> : never;
146
+ type SelectionResult<Registry extends CollectionRegistry, Name extends keyof Registry & string, Projection> = { -readonly [Key in keyof Projection as Projection[Key] extends false | undefined ? never : Key]-?: Key extends "_adjacent" ? Projection[Key] extends true ? Adjacent<{
147
+ id: string;
148
+ }> : Projection[Key] extends {
149
+ select: infer Neighbors;
150
+ } ? Adjacent<SelectionResult<Registry, Name, Neighbors>> : never : Key extends keyof RelationshipsOf<Registry[Name]> ? ObjectRelationValue<Registry, Name, Key, Projection[Key]> : Key extends keyof QueryData<Registry[Name]> ? QueryData<Registry[Name]>[Key] : never };
151
+ type CheckedField<Value, Filter> = Filter extends Scalar ? Filter : { [Operator in keyof Filter]: Operator extends keyof FieldFilter$1<Value> ? Operator extends "not" ? CheckedField<Value, Filter[Operator]> : Filter[Operator] : never };
152
+ type CheckedWhereList$1<Data, Filters extends readonly unknown[]> = { [Index in keyof Filters]: CheckedWhere$1<Data, Filters[Index]> };
153
+ type CheckedWhere$1<Data, Filter> = Filter extends ((...arguments_: never[]) => unknown) ? Filter : { [Key in keyof Filter]: Key extends "AND" | "OR" | "NOT" ? Filter[Key] extends readonly unknown[] ? CheckedWhereList$1<Data, Filter[Key]> : CheckedWhere$1<Data, Filter[Key]> : Key extends keyof Data ? CheckedField<Data[Key], Filter[Key]> : never };
154
+ type CheckedSelection<Registry extends CollectionRegistry, Name extends keyof Registry & string, Projection, AllowAdjacent extends boolean> = { [Key in keyof Projection]: Key extends "_adjacent" ? AllowAdjacent extends true ? Projection[Key] extends true ? true : CheckedOptions<Registry, Name, Projection[Key], true, false, false> : never : Key extends keyof RelationshipsOf<Registry[Name]> ? Projection[Key] extends false ? false : CheckedOptions<Registry, RelatedName$1<Registry, RelationOf<Registry, Name, Key>>, Projection[Key], RelationOf<Registry, Name, Key>["type"] extends "many" ? true : false, AllowAdjacent> : Key extends keyof QueryData<Registry[Name]> ? Projection[Key] : never };
155
+ /** Rejects extra properties throughout inferred options, including recursive neighbor projections. */
156
+ type CheckedOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string, Options, Many extends boolean = true, AllowAdjacent extends boolean = true, Pagination extends boolean = true> = { [Key in keyof Options]: Key extends "select" ? CheckedSelection<Registry, Name, Options[Key], AllowAdjacent> : Key extends "where" ? CheckedWhere$1<QueryData<Registry[Name]>, Options[Key]> : Key extends "limit" | "offset" ? Pagination extends true ? Many extends true ? Options[Key] : never : never : Key extends keyof ObjectScope<Registry, Name, Many> ? Options[Key] : never };
157
+ //#endregion
158
+ //#region src/query/relational-types.d.ts
159
+ type RelatedName<Registry extends CollectionRegistry, Name extends keyof Registry, Key extends keyof RelationshipsOf<Registry[Name]>> = (RelationshipsOf<Registry[Name]>[Key] & Relationship)["collection"] & keyof Registry & string;
160
+ type IsMany<Registry extends CollectionRegistry, Name extends keyof Registry, Key extends keyof RelationshipsOf<Registry[Name]>> = RelationshipsOf<Registry[Name]>[Key] extends {
161
+ type: "many";
162
+ } ? true : false;
163
+ type Condition<Value> = ([Value] extends [Scalar] ? Value : never) | FieldFilter<Value>;
164
+ type FieldFilter<Value> = {
165
+ isNull?: boolean;
166
+ isNotNull?: boolean;
167
+ isUndefined?: boolean;
168
+ isMissing?: boolean;
169
+ AND?: readonly Condition<Value>[];
170
+ OR?: readonly Condition<Value>[];
171
+ NOT?: Condition<Value>;
172
+ } & ([Value] extends [Scalar] ? {
173
+ eq?: Value;
174
+ ne?: Value;
175
+ in?: readonly Value[];
176
+ notIn?: readonly Value[];
177
+ } : {}) & (Ordered<Value> extends never ? {} : {
178
+ gt?: NonNullable<Value>;
179
+ gte?: NonNullable<Value>;
180
+ lt?: NonNullable<Value>;
181
+ lte?: NonNullable<Value>;
182
+ }) & (NonNullable<Value> extends string ? {
183
+ like?: string;
184
+ ilike?: string;
185
+ notLike?: string;
186
+ notIlike?: string;
187
+ contains?: string;
188
+ startsWith?: string;
189
+ endsWith?: string;
190
+ } : {}) & (NonNullable<Value> extends readonly (infer Item)[] ? Item extends Scalar ? {
191
+ arrayContains?: readonly Item[];
192
+ arrayOverlaps?: readonly Item[];
193
+ arrayContained?: readonly Item[];
194
+ } : {} : {});
195
+ /** Object predicates over prepared fields and existential filters over related entries. */
196
+ type RelationalWhere<Registry extends CollectionRegistry, Name extends keyof Registry & string> = { [Key in keyof QueryData<Registry[Name]>]?: Condition<QueryData<Registry[Name]>[Key]> } & { [Key in keyof RelationshipsOf<Registry[Name]>]?: boolean | RelationalWhere<Registry, RelatedName<Registry, Name, Key>> } & {
197
+ AND?: RelationalWhere<Registry, Name> | readonly RelationalWhere<Registry, Name>[];
198
+ OR?: readonly RelationalWhere<Registry, Name>[];
199
+ NOT?: RelationalWhere<Registry, Name> | readonly RelationalWhere<Registry, Name>[];
200
+ RAW?: (fields: Fields<QueryData<Registry[Name]>>) => Expression;
201
+ };
202
+ /** Collection-scoped metadata queries with Drizzle-style columns, relationships, and filters. */
203
+ type RelationalQueryOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string, Many extends boolean = true, AllowAdjacent extends boolean = true, Pagination extends boolean = true> = {
204
+ columns?: Partial<Record<keyof QueryData<Registry[Name]>, boolean>>;
205
+ where?: RelationalWhere<Registry, Name>;
206
+ with?: { [Key in keyof RelationshipsOf<Registry[Name]>]?: boolean | RelationalQueryOptions<Registry, RelatedName<Registry, Name, Key>, IsMany<Registry, Name, Key>, AllowAdjacent> };
207
+ } & (Many extends true ? {
208
+ orderBy?: OrderBy<QueryData<Registry[Name]>>;
209
+ } : {}) & (Many extends true ? (Pagination extends true ? {
210
+ limit?: number;
211
+ offset?: number;
212
+ } : {}) : {}) & (AllowAdjacent extends true ? {
213
+ adjacent?: true | RelationalQueryOptions<Registry, Name, true, false, false>;
214
+ } : {});
215
+ /** Options accepted by the root count helper, whose result ignores sorting and pagination. */
216
+ type RelationalCountOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string> = Pick<RelationalQueryOptions<Registry, Name>, "where" | "orderBy" | "offset" | "limit">;
217
+ type ColumnResult<Data, Options> = Options extends {
218
+ columns: infer Columns;
219
+ } ? keyof Columns extends never ? {} : true extends Columns[keyof Columns] ? { -readonly [Key in keyof Columns as Columns[Key] extends false | undefined ? never : Key]-?: Key extends keyof Data ? Data[Key] : never } : Omit<Data, { [Key in keyof Columns]: Columns[Key] extends false ? Key : never }[keyof Columns]> : Data;
220
+ type IncludedResult<Registry extends CollectionRegistry, Name extends keyof Registry & string, Options> = Options extends {
221
+ with: infer Related;
222
+ } ? { -readonly [Key in keyof Related as Related[Key] extends false | undefined ? never : Key]-?: Key extends keyof RelationshipsOf<Registry[Name]> ? RelationshipResult<Registry[Name], RelationshipsOf<Registry[Name]>[Key] & Relationship, RelationalQueryResult<Registry, RelatedName<Registry, Name, Key>, Related[Key] extends true ? {} : Related[Key]>, "where" extends keyof Related[Key] ? true : false> : never } : {};
223
+ type AdjacentResult<Registry extends CollectionRegistry, Name extends keyof Registry & string, Options> = Options extends {
224
+ adjacent: infer Neighbors;
225
+ } ? {
226
+ _adjacent: Neighbors extends true ? Adjacent<{
227
+ id: string;
228
+ }> : Adjacent<RelationalQueryResult<Registry, Name, Neighbors>>;
229
+ } : {};
230
+ type Simplify<Value> = { [Key in keyof Value]: Value[Key] };
231
+ /** Infers selected columns and relationships, preserving optional metadata in default projections. */
232
+ type RelationalQueryResult<Registry extends CollectionRegistry, Name extends keyof Registry & string, Options> = Options extends unknown ? Simplify<ColumnResult<QueryData<Registry[Name]>, Options> & IncludedResult<Registry, Name, Options> & AdjacentResult<Registry, Name, Options>> : never;
233
+ type CheckedConditions<Value, Filters extends readonly unknown[]> = { [Index in keyof Filters]: CheckedCondition<Value, Filters[Index]> };
234
+ type CheckedCondition<Value, Filter> = Filter extends Scalar ? Filter : { [Key in keyof Filter]: Key extends "AND" | "OR" ? Filter[Key] extends readonly unknown[] ? CheckedConditions<Value, Filter[Key]> : never : Key extends "NOT" ? CheckedCondition<Value, Filter[Key]> : Key extends keyof FieldFilter<Value> ? Filter[Key] : never };
235
+ type CheckedWhereList<Registry extends CollectionRegistry, Name extends keyof Registry & string, Filters extends readonly unknown[]> = { [Index in keyof Filters]: CheckedWhere<Registry, Name, Filters[Index]> };
236
+ type CheckedWhere<Registry extends CollectionRegistry, Name extends keyof Registry & string, Filter> = { [Key in keyof Filter]: Key extends "AND" | "OR" | "NOT" ? Filter[Key] extends readonly unknown[] ? CheckedWhereList<Registry, Name, Filter[Key]> : CheckedWhere<Registry, Name, Filter[Key]> : Key extends "RAW" ? Filter[Key] : Key extends keyof RelationshipsOf<Registry[Name]> ? Filter[Key] extends boolean ? Filter[Key] : CheckedWhere<Registry, RelatedName<Registry, Name, Key>, Filter[Key]> : Key extends keyof QueryData<Registry[Name]> ? CheckedCondition<QueryData<Registry[Name]>[Key], Filter[Key]> : never };
237
+ /** Rejects unknown options recursively, including options supplied through inferred variables. */
238
+ type CheckedRelationalOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string, Options, Many extends boolean = true, AllowAdjacent extends boolean = true, Pagination extends boolean = true> = { [Key in keyof Options]: Key extends "columns" ? { [Column in keyof Options[Key]]: Column extends keyof QueryData<Registry[Name]> ? Options[Key][Column] : never } : Key extends "where" ? CheckedWhere<Registry, Name, Options[Key]> : Key extends "with" ? { [Related in keyof Options[Key]]: Related extends keyof RelationshipsOf<Registry[Name]> ? Options[Key][Related] extends boolean ? Options[Key][Related] : CheckedRelationalOptions<Registry, RelatedName<Registry, Name, Related>, Options[Key][Related], IsMany<Registry, Name, Related>, AllowAdjacent> : never } : Key extends "adjacent" ? AllowAdjacent extends true ? Options[Key] extends true ? true : CheckedRelationalOptions<Registry, Name, Options[Key], true, false, false> : never : Key extends "orderBy" ? Key extends keyof RelationalQueryOptions<Registry, Name, Many, AllowAdjacent, Pagination> ? { [Field in keyof Options[Key]]: Field extends keyof OrderBy<QueryData<Registry[Name]>> ? Options[Key][Field] : never } : never : Key extends keyof RelationalQueryOptions<Registry, Name, Many, AllowAdjacent, Pagination> ? Options[Key] : never };
239
+ /** Typed per-collection query entry points that never expose source configuration at runtime. */
240
+ type RelationalQueries<Registry extends CollectionRegistry> = string extends keyof Registry ? {} : { readonly [Name in keyof Registry & string]: {
241
+ /** Returns matching metadata rows and requested relationships. */findMany<const Options extends RelationalQueryOptions<Registry, Name> = {}>(options?: Options & CheckedRelationalOptions<Registry, Name, NoInfer<Options>>): Promise<RelationalQueryResult<Registry, Name, Options>[]>; /** Returns the first matching entry, or undefined when none matches. */
242
+ findFirst<const Options extends RelationalQueryOptions<Registry, Name> = {}>(options?: Options & CheckedRelationalOptions<Registry, Name, NoInfer<Options>>): Promise<RelationalQueryResult<Registry, Name, Options> | undefined>;
243
+ } };
244
+ //#endregion
245
+ export { QueryPlan as _, RelationalWhere as a, Fields as c, Scalar as d, ScalarField as f, Expression as g, Where as h, RelationalQueryResult as i, Ordered as l, SelectionResult as m, RelationalQueries as n, Adjacent as o, Selection as p, RelationalQueryOptions as r, Field$1 as s, RelationalCountOptions as t, Query as u, QueryRegistry as v };
@@ -0,0 +1,3 @@
1
+ import { n as ContentRenderResult, t as ContentHeading } from "./types-DcvHRmxO.mjs";
2
+ import { a as ContentError, i as ContentDiagnostic, o as ContentErrorCode, t as Content } from "./content-Crag1Uch.mjs";
3
+ export { type Content, type ContentDiagnostic, ContentError, type ContentErrorCode, type ContentHeading, type ContentRenderResult };
@@ -0,0 +1,6 @@
1
+ import { t as ContentError } from "./errors-C8lWyiy2.mjs";
2
+ import { t as assertServerOnly } from "./server-only-CIE-FHx0.mjs";
3
+ //#region src/runtime.ts
4
+ assertServerOnly();
5
+ //#endregion
6
+ export { ContentError };
@@ -0,0 +1,20 @@
1
+ import { n as __exportAll } from "./chunk-CJs4Fogs.mjs";
2
+ import { array, bigint, boolean, coerce, date, enum as enum$1, literal, number, object, record, string, union, unknown } from "zod";
3
+ //#region src/schema/builders.ts
4
+ var builders_exports = /* @__PURE__ */ __exportAll({
5
+ array: () => array,
6
+ bigint: () => bigint,
7
+ boolean: () => boolean,
8
+ coerce: () => coerce,
9
+ date: () => date,
10
+ enum: () => enum$1,
11
+ literal: () => literal,
12
+ number: () => number,
13
+ object: () => object,
14
+ record: () => record,
15
+ string: () => string,
16
+ union: () => union,
17
+ unknown: () => unknown
18
+ });
19
+ //#endregion
20
+ export { number as n, string as r, builders_exports as t };
@@ -0,0 +1,13 @@
1
+ import { array, bigint, boolean, coerce, date, enum as enum$1, literal, number, object, record, string, union, unknown } from "zod";
2
+ import { StandardSchemaV1 } from "@standard-schema/spec";
3
+
4
+ //#region src/schema/builders.d.ts
5
+ declare namespace builders_d_exports {
6
+ export { array, bigint, boolean, coerce, date, enum$1 as enum, output as infer, input, literal, number, object, output, record, string, union, unknown };
7
+ }
8
+ /** Infers the input type of any Standard Schema V1 validator. */
9
+ type input<Validator extends StandardSchemaV1> = StandardSchemaV1.InferInput<Validator>;
10
+ /** Infers the validated output type of any Standard Schema V1 validator. */
11
+ type output<Validator extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Validator>;
12
+ //#endregion
13
+ export { builders_d_exports as schema };
@@ -0,0 +1,2 @@
1
+ import { t as builders_exports } from "./schema-CnCbMosm.mjs";
2
+ export { builders_exports as schema };
@@ -0,0 +1,7 @@
1
+ //#region src/shared/server-only.ts
2
+ /** Provides a fallback when a host has not rejected a server import during bundling. */
3
+ function assertServerOnly() {
4
+ if (globalThis.window !== void 0) throw new Error("[content-query] Content querying and preparation are server-only.");
5
+ }
6
+ //#endregion
7
+ export { assertServerOnly as t };
@@ -0,0 +1,48 @@
1
+ import { a as Loader } from "./types-hmDOw87q.mjs";
2
+ import { StandardSchemaV1 } from "@standard-schema/spec";
3
+
4
+ //#region src/collection/types.d.ts
5
+ type Schema = StandardSchemaV1;
6
+ type SchemaOutput<Value> = Value extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Value> : Record<string, unknown>;
7
+ type ComputedContext<Data, Source = unknown> = {
8
+ /** The collection's key in the configured registry. */collection: string;
9
+ id: string; /** Loader-provided source metadata, detached from stored entries for this resolver. */
10
+ source?: Source extends object ? Readonly<Source> : Source;
11
+ data: Readonly<Data>;
12
+ readBody(this: void): Promise<string | undefined>;
13
+ signal: AbortSignal;
14
+ };
15
+ type ComputedDefinition<Data = Record<string, unknown>, Source = unknown> = {
16
+ schema: Schema;
17
+ resolve(context: ComputedContext<Data, Source>): unknown;
18
+ };
19
+ type Relationship = {
20
+ collection: string;
21
+ type: "one" | "many";
22
+ from: string;
23
+ to: string;
24
+ referenceSide: "from" | "to" | "none";
25
+ };
26
+ 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>> = {
27
+ loader: Loader;
28
+ schema?: SourceSchema;
29
+ computed?: Computed;
30
+ relationships?: Relationships;
31
+ };
32
+ type CollectionRegistry = Record<string, CollectionDefinition>;
33
+ type EntryData<Definition> = Definition extends {
34
+ schema: infer SourceSchema;
35
+ } ? SchemaOutput<SourceSchema> : Record<string, unknown>;
36
+ type ComputedData<Definition> = Definition extends {
37
+ computed: infer Computed;
38
+ } ? { [Name in keyof Computed]: Computed[Name] extends {
39
+ schema: infer ResultSchema;
40
+ } ? SchemaOutput<ResultSchema> : never } : {};
41
+ type QueryData<Definition> = {
42
+ id: string;
43
+ } & EntryData<Definition> & ComputedData<Definition>;
44
+ type RelationshipsOf<Definition> = Definition extends {
45
+ relationships: infer Relationships;
46
+ } ? Relationships : {};
47
+ //#endregion
48
+ export { Relationship as a, SchemaOutput as c, QueryData as i, CollectionRegistry as n, RelationshipsOf as o, ComputedContext as r, Schema as s, CollectionDefinition as t };
@@ -0,0 +1,20 @@
1
+ //#region src/runtime/types.d.ts
2
+ type ContentHeading = {
3
+ depth: number;
4
+ slug: string;
5
+ text: string;
6
+ };
7
+ type ContentRenderResult = {
8
+ html: string;
9
+ headings: ContentHeading[];
10
+ };
11
+ type RenderedContent = {
12
+ html: string;
13
+ metadata?: {
14
+ headings?: ContentHeading[];
15
+ imagePaths?: string[];
16
+ [key: string]: unknown;
17
+ };
18
+ };
19
+ //#endregion
20
+ export { ContentRenderResult as n, RenderedContent as r, ContentHeading as t };
@@ -0,0 +1,135 @@
1
+ import { r as RenderedContent } from "./types-DcvHRmxO.mjs";
2
+
3
+ //#region src/shared/types.d.ts
4
+ type MaybePromise<Value> = Value | Promise<Value>;
5
+ //#endregion
6
+ //#region src/loaders/types.d.ts
7
+ declare const loaderSourceType: unique symbol;
8
+ /** A stored content record, following Astro's build-time DataEntry contract. */
9
+ type DataEntry<Data extends Record<string, unknown> = Record<string, unknown>, Source = unknown> = {
10
+ id: string;
11
+ data: Data;
12
+ body?: string;
13
+ rendered?: RenderedContent;
14
+ filePath?: string;
15
+ digest?: string | number;
16
+ deferredRender?: boolean;
17
+ assetImports?: string[];
18
+ imageImports?: (string | number)[][]; /** Optional ContentQuery metadata; Astro stores do not retain this extension. */
19
+ source?: Source;
20
+ };
21
+ /** Source metadata supplied by loaders of individual local files. */
22
+ type FileSource = {
23
+ filePath: string;
24
+ };
25
+ /** Source metadata identifying a record within a shared local file. */
26
+ type FileEntrySource = FileSource & {
27
+ key: string;
28
+ };
29
+ type DataStore<in Source = unknown> = {
30
+ get<Data extends Record<string, unknown> = Record<string, unknown>>(key: string): DataEntry<Data> | undefined;
31
+ set<Data extends Record<string, unknown>>(entry: DataEntry<Data, Source>): boolean;
32
+ entries(): [string, DataEntry][];
33
+ values(): DataEntry[];
34
+ keys(): string[];
35
+ has(key: string): boolean;
36
+ delete(key: string): void;
37
+ clear(): void;
38
+ addModuleImport(filename: string): void;
39
+ };
40
+ type MetaStore = {
41
+ get(key: string): string | undefined;
42
+ set(key: string, value: string): void;
43
+ has(key: string): boolean;
44
+ delete(key: string): void;
45
+ };
46
+ type LoaderConfig = {
47
+ root: URL;
48
+ srcDir: URL;
49
+ publicDir: URL;
50
+ outDir: URL;
51
+ cacheDir: URL;
52
+ base: string;
53
+ site?: string;
54
+ output: "static" | "server" | "hybrid";
55
+ };
56
+ type LoaderLogger = {
57
+ label: string;
58
+ options: {
59
+ level: "debug" | "info" | "warn" | "error" | "silent";
60
+ destination: {
61
+ write(message: {
62
+ label: string | null;
63
+ level: "debug" | "info" | "warn" | "error" | "silent";
64
+ message: string;
65
+ newLine: boolean;
66
+ }): void;
67
+ flush?(): void | Promise<void>;
68
+ close?(): void | Promise<void>;
69
+ };
70
+ };
71
+ info(message: string): void;
72
+ warn(message: string): void;
73
+ error(message: string): void;
74
+ debug(message: string): void;
75
+ fork(label: string): LoaderLogger;
76
+ flush(): void;
77
+ close(): void;
78
+ };
79
+ type LoaderWatchEvents = {
80
+ add: [filename: string];
81
+ change: [filename: string];
82
+ unlink: [filename: string];
83
+ addDir: [filename: string];
84
+ unlinkDir: [filename: string];
85
+ all: [event: string, filename: string];
86
+ error: [cause: Error];
87
+ ready: [];
88
+ };
89
+ /** Shared filesystem watcher; loader callbacks are serialized and published as complete batches. */
90
+ interface LoaderWatcher {
91
+ on<Event extends keyof LoaderWatchEvents>(event: Event, listener: (...arguments_: LoaderWatchEvents[Event]) => unknown): LoaderWatcher;
92
+ once<Event extends keyof LoaderWatchEvents>(event: Event, listener: (...arguments_: LoaderWatchEvents[Event]) => unknown): LoaderWatcher;
93
+ off<Event extends keyof LoaderWatchEvents>(event: Event, listener: (...arguments_: LoaderWatchEvents[Event]) => unknown): LoaderWatcher;
94
+ removeListener<Event extends keyof LoaderWatchEvents>(event: Event, listener: (...arguments_: LoaderWatchEvents[Event]) => unknown): LoaderWatcher;
95
+ removeAllListeners(event?: string): LoaderWatcher;
96
+ add(paths: string | readonly string[]): LoaderWatcher;
97
+ unwatch(paths: string | readonly string[]): LoaderWatcher;
98
+ close(): Promise<void>;
99
+ }
100
+ type LoaderContext<in Source = unknown> = {
101
+ collection: string;
102
+ store: DataStore<Source>;
103
+ meta: MetaStore;
104
+ config: LoaderConfig;
105
+ logger: LoaderLogger;
106
+ watcher?: LoaderWatcher; /** ContentQuery extension: cancellation for this load attempt. */
107
+ signal?: AbortSignal;
108
+ parseData<Data extends Record<string, unknown>>(options: {
109
+ id: string;
110
+ data: Data;
111
+ filePath?: string;
112
+ }): Promise<Data>;
113
+ renderMarkdown(content: string, options?: {
114
+ fileURL?: URL;
115
+ }): Promise<RenderedContent>;
116
+ generateDigest(data: Record<string, unknown> | string): string;
117
+ refreshContextData?: Record<string, unknown>;
118
+ };
119
+ /** An Astro-compatible, named build-time content loader. */
120
+ type Loader<out Source = unknown> = {
121
+ /** Type-only marker preserving metadata inference without changing Astro's load signature. */readonly [loaderSourceType]?: Source;
122
+ name: string;
123
+ schema?: unknown;
124
+ createSchema?(): MaybePromise<{
125
+ schema: unknown;
126
+ types?: string;
127
+ }>;
128
+ load(context: LoaderContext<Source>): Promise<void>;
129
+ };
130
+ /** Infers the source metadata a typed loader supplies to computed resolvers. */
131
+ type LoaderSource<Value> = Value extends {
132
+ readonly [loaderSourceType]?: infer Source;
133
+ } ? Source : unknown;
134
+ //#endregion
135
+ export { Loader as a, LoaderLogger as c, MetaStore as d, MaybePromise as f, FileSource as i, LoaderSource as l, DataStore as n, LoaderConfig as o, FileEntrySource as r, LoaderContext as s, DataEntry as t, LoaderWatcher as u };
@@ -0,0 +1,84 @@
1
+ import { n as contentError, t as ContentError } from "./errors-C8lWyiy2.mjs";
2
+ import { i as detach } from "./values-B7lo_2_x.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 };