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.
- package/LICENSE +21 -0
- package/README.md +91 -2
- package/dist/build-DfKd2bpf.d.mts +25 -0
- package/dist/build-Dxz7P1ur.mjs +1439 -0
- package/dist/build.d.mts +2 -0
- package/dist/build.mjs +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +97 -0
- package/dist/computed.d.mts +43 -0
- package/dist/computed.mjs +139 -0
- package/dist/content-G69dPPuo.d.mts +109 -0
- package/dist/content-N1gYshjg.mjs +1028 -0
- package/dist/descriptor-D9Th5hzk.d.mts +18 -0
- package/dist/diagnostics-Cu94mZhl.mjs +80 -0
- package/dist/dist-C7_FOzY_.mjs +5405 -0
- package/dist/errors-C2iuBM0G.mjs +72 -0
- package/dist/github-slugger-BMgR_Q0I.mjs +72 -0
- package/dist/glob-Bv0dpvCQ.mjs +159 -0
- package/dist/index.d.mts +78 -0
- package/dist/index.mjs +46 -0
- package/dist/internal/markdown.d.mts +5 -0
- package/dist/internal/markdown.mjs +1 -0
- package/dist/internal.d.mts +54 -0
- package/dist/internal.mjs +89 -0
- package/dist/loaders.d.mts +11 -0
- package/dist/loaders.mjs +86 -0
- package/dist/markdown-CHvBBJNa.mjs +54 -0
- package/dist/next.d.mts +20 -0
- package/dist/next.mjs +142 -0
- package/dist/operators-UqWUhKQJ.mjs +173 -0
- package/dist/query.d.mts +44 -0
- package/dist/query.mjs +1 -0
- package/dist/relational-types-DgK3rLuw.d.mts +278 -0
- package/dist/rolldown-runtime-Bg1v5YCA.mjs +34 -0
- package/dist/runtime.d.mts +3 -0
- package/dist/runtime.mjs +5 -0
- package/dist/schema-C5Str-E8.mjs +20 -0
- package/dist/schema.d.mts +11 -0
- package/dist/schema.mjs +1 -0
- package/dist/server-only-CIJUlyL-.mjs +7 -0
- package/dist/types-C-kdMblM.d.mts +69 -0
- package/dist/types-ChaNhj42.d.mts +143 -0
- package/dist/types-Dh-Sydyw.d.mts +20 -0
- package/dist/validation-D_XdE1pF.mjs +84 -0
- package/dist/values-BbTV4QT-.mjs +901 -0
- package/dist/vite.d.mts +6 -0
- package/dist/vite.mjs +296 -0
- package/package.json +92 -10
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { c as Relationship, i as CollectionRegistry, l as RelationshipsOf, o as PayloadsOf, s as QueryData } from "./types-C-kdMblM.mjs";
|
|
2
|
+
//#region src/query/plan.d.ts
|
|
3
|
+
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";
|
|
4
|
+
type Expression = {
|
|
5
|
+
kind: "predicate";
|
|
6
|
+
operator: PredicateOperator;
|
|
7
|
+
field: string;
|
|
8
|
+
value?: unknown;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "relation";
|
|
11
|
+
collection: string;
|
|
12
|
+
field: string;
|
|
13
|
+
target: string;
|
|
14
|
+
expression: Expression;
|
|
15
|
+
} | {
|
|
16
|
+
kind: "and" | "or" | "not";
|
|
17
|
+
expressions: readonly Expression[];
|
|
18
|
+
};
|
|
19
|
+
type QueryPlan = {
|
|
20
|
+
collection: string;
|
|
21
|
+
select?: readonly string[];
|
|
22
|
+
allFields?: boolean;
|
|
23
|
+
exclude?: readonly string[];
|
|
24
|
+
filters: readonly Expression[];
|
|
25
|
+
order: readonly {
|
|
26
|
+
field: string;
|
|
27
|
+
direction: "asc" | "desc";
|
|
28
|
+
}[];
|
|
29
|
+
limit?: number;
|
|
30
|
+
offset?: number;
|
|
31
|
+
with: Readonly<Record<string, QueryPlan>>;
|
|
32
|
+
adjacent?: true | QueryPlan;
|
|
33
|
+
/** Payloads to attach under `_payloads` after filtering, ordering, and pagination. */
|
|
34
|
+
payloads?: Readonly<Record<string, PlanPayload>>;
|
|
35
|
+
};
|
|
36
|
+
/** One requested payload; variant keys are empty for payloads without variants. */
|
|
37
|
+
type PlanPayload = {
|
|
38
|
+
variant: Readonly<Record<string, string>>;
|
|
39
|
+
};
|
|
40
|
+
/** Describes a payload that queries may request, without its resolver or schema. */
|
|
41
|
+
type PayloadDescriptor = {
|
|
42
|
+
variants: readonly string[];
|
|
43
|
+
};
|
|
44
|
+
type QueryRegistry = Record<string, {
|
|
45
|
+
relationships: Record<string, Relationship>;
|
|
46
|
+
/** Payload names available to queries; omitted when the collection has none. */
|
|
47
|
+
payloads?: Record<string, PayloadDescriptor>;
|
|
48
|
+
}>;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/query/types.d.ts
|
|
51
|
+
declare const queryType: unique symbol;
|
|
52
|
+
declare const fieldType: unique symbol;
|
|
53
|
+
type Field$1<Value> = {
|
|
54
|
+
readonly name: string;
|
|
55
|
+
readonly [fieldType]: Value;
|
|
56
|
+
};
|
|
57
|
+
type Fields<Data> = { readonly [Name in keyof Data]-?: Field$1<Data[Name]>; };
|
|
58
|
+
type Scalar = string | number | bigint | boolean | Date | null | undefined;
|
|
59
|
+
type ScalarField<Value> = Field$1<Value> & ([Value] extends [Scalar] ? unknown : never);
|
|
60
|
+
type Ordered<Value> = NonNullable<Value> extends string ? unknown : NonNullable<Value> extends number ? unknown : NonNullable<Value> extends bigint ? unknown : NonNullable<Value> extends Date ? unknown : never;
|
|
61
|
+
type SortKey<Data> = { [Name in keyof Data]-?: Ordered<Data[Name]> extends never ? NonNullable<Data[Name]> extends boolean ? Name : never : Name; }[keyof Data] & string;
|
|
62
|
+
type QueryInfo<Result = unknown, Selected extends boolean = boolean, Filtered extends boolean = boolean> = {
|
|
63
|
+
readonly [queryType]: {
|
|
64
|
+
result: Result;
|
|
65
|
+
selected: Selected;
|
|
66
|
+
filtered: Filtered;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
type Simplify$1<Value> = { [Key in keyof Value]: Value[Key]; };
|
|
70
|
+
/** Adds one requested payload to a result's `_payloads`, keeping earlier requests. */
|
|
71
|
+
type WithPayload<Result, Key extends PropertyKey, Value> = Omit<Result, "_payloads"> & {
|
|
72
|
+
_payloads: Simplify$1<(Result extends {
|
|
73
|
+
_payloads: infer Existing;
|
|
74
|
+
} ? Existing : {}) & { [Name in Key]: Value; }>;
|
|
75
|
+
};
|
|
76
|
+
type ResultOf<Configured> = Configured extends QueryInfo<infer Result> ? Result : never;
|
|
77
|
+
type FilteredOf<Configured> = Configured extends QueryInfo<unknown, boolean, infer Filtered> ? Filtered : false;
|
|
78
|
+
type RelationOf<Registry extends CollectionRegistry, Name extends keyof Registry, Key extends keyof RelationshipsOf<Registry[Name]>> = RelationshipsOf<Registry[Name]>[Key] & Relationship;
|
|
79
|
+
type RelatedName$1<Registry extends CollectionRegistry, Relation extends Relationship> = Relation["collection"] & keyof Registry & string;
|
|
80
|
+
/** Applies declared relationship cardinality, optional reference fields, and filtering to a result. */
|
|
81
|
+
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);
|
|
82
|
+
type RelationValue<Definition, Relation extends Relationship, Configured> = RelationshipResult<Definition, Relation, ResultOf<Configured>, FilteredOf<Configured>>;
|
|
83
|
+
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> & {
|
|
84
|
+
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>;
|
|
85
|
+
where(configure: (fields: Fields<QueryData<Registry[Name]>>) => Expression): Query<Registry, Name, Result, Selected, Many, Root, true, AllowAdjacent, Pagination>;
|
|
86
|
+
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>;
|
|
87
|
+
} & (Many extends true ? {
|
|
88
|
+
orderBy(field: SortKey<QueryData<Registry[Name]>>, direction?: "asc" | "desc"): Query<Registry, Name, Result, Selected, Many, Root, Filtered, AllowAdjacent, Pagination>;
|
|
89
|
+
} : {}) & (Many extends true ? Pagination extends true ? {
|
|
90
|
+
limit(value: number): Query<Registry, Name, Result, Selected, Many, Root, Filtered, AllowAdjacent, Pagination>;
|
|
91
|
+
offset(value: number): Query<Registry, Name, Result, Selected, Many, Root, Filtered, AllowAdjacent, Pagination>;
|
|
92
|
+
} : {} : {}) & (AllowAdjacent extends true ? {
|
|
93
|
+
/** Attaches a payload under `_payloads` after filtering, ordering, and pagination. */
|
|
94
|
+
withPayload<Key extends keyof PayloadsOf<Registry[Name]> & string>(name: Key): Query<Registry, Name, WithPayload<Result, Key, PayloadsOf<Registry[Name]>[Key]>, Selected, Many, Root, Filtered, AllowAdjacent, Pagination>;
|
|
95
|
+
selectAdjacent(): Query<Registry, Name, Result & {
|
|
96
|
+
_adjacent: Adjacent<{
|
|
97
|
+
id: string;
|
|
98
|
+
}>;
|
|
99
|
+
}, true, Many, Root, Filtered, AllowAdjacent, Pagination>;
|
|
100
|
+
selectAdjacent<Configured extends QueryInfo<unknown, true>>(configure: (siblings: Query<Registry, Name, {}, false, true, false, false, false, false>) => Configured): Query<Registry, Name, Result & {
|
|
101
|
+
_adjacent: Adjacent<ResultOf<Configured>>;
|
|
102
|
+
}, true, Many, Root, Filtered, AllowAdjacent, Pagination>;
|
|
103
|
+
selectAdjacent<const Options extends AdjacentOptions<Registry, Name>>(options: Options & CheckedOptions<Registry, Name, NoInfer<Options>, true, false, false>): Query<Registry, Name, Result & {
|
|
104
|
+
_adjacent: Adjacent<SelectionResult<Registry, Name, Options["select"]>>;
|
|
105
|
+
}, true, Many, Root, Filtered, AllowAdjacent, Pagination>;
|
|
106
|
+
} : {}) & (Root extends true ? {
|
|
107
|
+
all: Selected extends true ? () => Promise<Simplify$1<Result>[]> : never;
|
|
108
|
+
execute: Selected extends true ? () => Promise<Simplify$1<Result>[]> : never;
|
|
109
|
+
then: Selected extends true ? Promise<Simplify$1<Result>[]>["then"] : never;
|
|
110
|
+
first: Selected extends true ? () => Promise<Simplify$1<Result> | undefined> : never;
|
|
111
|
+
/** Counts matching entries; unavailable once payloads are requested. */
|
|
112
|
+
count: [Result] extends [never] ? () => Promise<number> : [Result] extends [{
|
|
113
|
+
_payloads: unknown;
|
|
114
|
+
}] ? never : () => Promise<number>;
|
|
115
|
+
} : {});
|
|
116
|
+
type Adjacent<Entry> = {
|
|
117
|
+
previous: Entry | null;
|
|
118
|
+
next: Entry | null;
|
|
119
|
+
};
|
|
120
|
+
type PresenceFilter = {
|
|
121
|
+
isNull?: boolean;
|
|
122
|
+
isUndefined?: boolean;
|
|
123
|
+
isMissing?: boolean;
|
|
124
|
+
};
|
|
125
|
+
type ScalarFilter<Value> = {
|
|
126
|
+
equals?: Value;
|
|
127
|
+
not?: Value | ScalarFilter<Value>;
|
|
128
|
+
in?: readonly Value[];
|
|
129
|
+
notIn?: readonly Value[];
|
|
130
|
+
} & (Ordered<Value> extends never ? {} : {
|
|
131
|
+
gt?: NonNullable<Value>;
|
|
132
|
+
gte?: NonNullable<Value>;
|
|
133
|
+
lt?: NonNullable<Value>;
|
|
134
|
+
lte?: NonNullable<Value>;
|
|
135
|
+
}) & (NonNullable<Value> extends string ? {
|
|
136
|
+
contains?: string;
|
|
137
|
+
startsWith?: string;
|
|
138
|
+
endsWith?: string;
|
|
139
|
+
} : {});
|
|
140
|
+
type FieldFilter$1<Value> = PresenceFilter & (NonNullable<Value> extends readonly (infer Item)[] ? Item extends Scalar ? {
|
|
141
|
+
has?: Item;
|
|
142
|
+
hasSome?: readonly Item[];
|
|
143
|
+
hasEvery?: readonly Item[];
|
|
144
|
+
} : {} : [Value] extends [Scalar] ? ScalarFilter<Value> : {});
|
|
145
|
+
type Where<Data> = { [Name in keyof Data]?: [Data[Name]] extends [Scalar] ? Data[Name] | FieldFilter$1<Data[Name]> : FieldFilter$1<Data[Name]>; } & {
|
|
146
|
+
AND?: Where<Data> | readonly Where<Data>[];
|
|
147
|
+
OR?: readonly Where<Data>[];
|
|
148
|
+
NOT?: Where<Data> | readonly Where<Data>[];
|
|
149
|
+
};
|
|
150
|
+
type OrderBy<Data> = Partial<Record<SortKey<Data>, "asc" | "desc">>;
|
|
151
|
+
type ObjectScope<Registry extends CollectionRegistry, Name extends keyof Registry & string, Many extends boolean> = {
|
|
152
|
+
where?: Where<QueryData<Registry[Name]>> | ((fields: Fields<QueryData<Registry[Name]>>) => Expression);
|
|
153
|
+
} & (Many extends true ? {
|
|
154
|
+
orderBy?: OrderBy<QueryData<Registry[Name]>> | readonly OrderBy<QueryData<Registry[Name]>>[];
|
|
155
|
+
limit?: number;
|
|
156
|
+
offset?: number;
|
|
157
|
+
} : {});
|
|
158
|
+
type QueryOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string, Many extends boolean = true, AllowAdjacent extends boolean = true> = ObjectScope<Registry, Name, Many> & {
|
|
159
|
+
select: Selection<Registry, Name, AllowAdjacent>;
|
|
160
|
+
};
|
|
161
|
+
type AdjacentOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string> = Omit<QueryOptions<Registry, Name, true, false>, "limit" | "offset">;
|
|
162
|
+
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 ? {
|
|
163
|
+
_adjacent?: true | AdjacentOptions<Registry, Name>;
|
|
164
|
+
} : {});
|
|
165
|
+
type ObjectRelationValue<Registry extends CollectionRegistry, Name extends keyof Registry & string, Key extends keyof RelationshipsOf<Registry[Name]>, Options> = Options extends {
|
|
166
|
+
select: infer Projection;
|
|
167
|
+
} ? 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;
|
|
168
|
+
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<{
|
|
169
|
+
id: string;
|
|
170
|
+
}> : Projection[Key] extends {
|
|
171
|
+
select: infer Neighbors;
|
|
172
|
+
} ? 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; };
|
|
173
|
+
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; };
|
|
174
|
+
type CheckedWhereList$1<Data, Filters extends readonly unknown[]> = { [Index in keyof Filters]: CheckedWhere$1<Data, Filters[Index]>; };
|
|
175
|
+
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; };
|
|
176
|
+
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; };
|
|
177
|
+
/** Rejects extra properties throughout inferred options, including recursive neighbor projections. */
|
|
178
|
+
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; };
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/query/relational-types.d.ts
|
|
181
|
+
type RelatedName<Registry extends CollectionRegistry, Name extends keyof Registry, Key extends keyof RelationshipsOf<Registry[Name]>> = (RelationshipsOf<Registry[Name]>[Key] & Relationship)["collection"] & keyof Registry & string;
|
|
182
|
+
type IsMany<Registry extends CollectionRegistry, Name extends keyof Registry, Key extends keyof RelationshipsOf<Registry[Name]>> = RelationshipsOf<Registry[Name]>[Key] extends {
|
|
183
|
+
type: "many";
|
|
184
|
+
} ? true : false;
|
|
185
|
+
type Condition<Value> = ([Value] extends [Scalar] ? Value : never) | FieldFilter<Value>;
|
|
186
|
+
type FieldFilter<Value> = {
|
|
187
|
+
isNull?: boolean;
|
|
188
|
+
isNotNull?: boolean;
|
|
189
|
+
isUndefined?: boolean;
|
|
190
|
+
isMissing?: boolean;
|
|
191
|
+
AND?: readonly Condition<Value>[];
|
|
192
|
+
OR?: readonly Condition<Value>[];
|
|
193
|
+
NOT?: Condition<Value>;
|
|
194
|
+
} & ([Value] extends [Scalar] ? {
|
|
195
|
+
eq?: Value;
|
|
196
|
+
ne?: Value;
|
|
197
|
+
in?: readonly Value[];
|
|
198
|
+
notIn?: readonly Value[];
|
|
199
|
+
} : {}) & (Ordered<Value> extends never ? {} : {
|
|
200
|
+
gt?: NonNullable<Value>;
|
|
201
|
+
gte?: NonNullable<Value>;
|
|
202
|
+
lt?: NonNullable<Value>;
|
|
203
|
+
lte?: NonNullable<Value>;
|
|
204
|
+
}) & (NonNullable<Value> extends string ? {
|
|
205
|
+
like?: string;
|
|
206
|
+
ilike?: string;
|
|
207
|
+
notLike?: string;
|
|
208
|
+
notIlike?: string;
|
|
209
|
+
contains?: string;
|
|
210
|
+
startsWith?: string;
|
|
211
|
+
endsWith?: string;
|
|
212
|
+
} : {}) & (NonNullable<Value> extends readonly (infer Item)[] ? Item extends Scalar ? {
|
|
213
|
+
arrayContains?: readonly Item[];
|
|
214
|
+
arrayOverlaps?: readonly Item[];
|
|
215
|
+
arrayContained?: readonly Item[];
|
|
216
|
+
} : {} : {});
|
|
217
|
+
/** Object predicates over prepared fields and existential filters over related entries. */
|
|
218
|
+
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>>; } & {
|
|
219
|
+
AND?: RelationalWhere<Registry, Name> | readonly RelationalWhere<Registry, Name>[];
|
|
220
|
+
OR?: readonly RelationalWhere<Registry, Name>[];
|
|
221
|
+
NOT?: RelationalWhere<Registry, Name> | readonly RelationalWhere<Registry, Name>[];
|
|
222
|
+
RAW?: (fields: Fields<QueryData<Registry[Name]>>) => Expression;
|
|
223
|
+
};
|
|
224
|
+
/** Payloads to attach under `_payloads`; payloads set to false are omitted. */
|
|
225
|
+
type PayloadOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string> = { [Key in keyof PayloadsOf<Registry[Name]>]?: boolean; };
|
|
226
|
+
/** Collection-scoped metadata queries with Drizzle-style columns, relationships, and filters. */
|
|
227
|
+
type RelationalQueryOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string, Many extends boolean = true, AllowAdjacent extends boolean = true, Pagination extends boolean = true> = {
|
|
228
|
+
columns?: Partial<Record<keyof QueryData<Registry[Name]>, boolean>>;
|
|
229
|
+
where?: RelationalWhere<Registry, Name>;
|
|
230
|
+
with?: { [Key in keyof RelationshipsOf<Registry[Name]>]?: boolean | RelationalQueryOptions<Registry, RelatedName<Registry, Name, Key>, IsMany<Registry, Name, Key>, AllowAdjacent>; };
|
|
231
|
+
} & (Many extends true ? {
|
|
232
|
+
orderBy?: OrderBy<QueryData<Registry[Name]>>;
|
|
233
|
+
} : {}) & (Many extends true ? (Pagination extends true ? {
|
|
234
|
+
limit?: number;
|
|
235
|
+
offset?: number;
|
|
236
|
+
} : {}) : {}) & (AllowAdjacent extends true ? {
|
|
237
|
+
adjacent?: true | RelationalQueryOptions<Registry, Name, true, false, false>;
|
|
238
|
+
payloads?: PayloadOptions<Registry, Name>;
|
|
239
|
+
} : {});
|
|
240
|
+
/** Options accepted by the root count helper, whose result ignores sorting and pagination. */
|
|
241
|
+
type RelationalCountOptions<Registry extends CollectionRegistry, Name extends keyof Registry & string> = Pick<RelationalQueryOptions<Registry, Name>, "where" | "orderBy" | "offset" | "limit">;
|
|
242
|
+
type ColumnResult<Data, Options> = Options extends {
|
|
243
|
+
columns: infer Columns;
|
|
244
|
+
} ? 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;
|
|
245
|
+
type IncludedResult<Registry extends CollectionRegistry, Name extends keyof Registry & string, Options> = Options extends {
|
|
246
|
+
with: infer Related;
|
|
247
|
+
} ? { -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; } : {};
|
|
248
|
+
type AdjacentResult<Registry extends CollectionRegistry, Name extends keyof Registry & string, Options> = Options extends {
|
|
249
|
+
adjacent: infer Neighbors;
|
|
250
|
+
} ? {
|
|
251
|
+
_adjacent: Neighbors extends true ? Adjacent<{
|
|
252
|
+
id: string;
|
|
253
|
+
}> : Adjacent<RelationalQueryResult<Registry, Name, Neighbors>>;
|
|
254
|
+
} : {};
|
|
255
|
+
type Simplify<Value> = { [Key in keyof Value]: Value[Key]; };
|
|
256
|
+
type RequestedPayloads<Payloads, Requested> = { -readonly [Key in keyof Requested as Requested[Key] extends false | undefined ? never : Key]-?: Key extends keyof Payloads ? Payloads[Key] : never; };
|
|
257
|
+
type PayloadResult<Registry extends CollectionRegistry, Name extends keyof Registry & string, Options> = Options extends {
|
|
258
|
+
payloads: infer Requested;
|
|
259
|
+
} ? keyof RequestedPayloads<PayloadsOf<Registry[Name]>, Requested> extends never ? {} : {
|
|
260
|
+
_payloads: Simplify<RequestedPayloads<PayloadsOf<Registry[Name]>, Requested>>;
|
|
261
|
+
} : {};
|
|
262
|
+
/** Infers selected columns and relationships, preserving optional metadata in default projections. */
|
|
263
|
+
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> & PayloadResult<Registry, Name, Options>> : never;
|
|
264
|
+
type CheckedConditions<Value, Filters extends readonly unknown[]> = { [Index in keyof Filters]: CheckedCondition<Value, Filters[Index]>; };
|
|
265
|
+
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; };
|
|
266
|
+
type CheckedWhereList<Registry extends CollectionRegistry, Name extends keyof Registry & string, Filters extends readonly unknown[]> = { [Index in keyof Filters]: CheckedWhere<Registry, Name, Filters[Index]>; };
|
|
267
|
+
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; };
|
|
268
|
+
/** Rejects unknown options recursively, including options supplied through inferred variables. */
|
|
269
|
+
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 "payloads" ? AllowAdjacent extends true ? { [Payload in keyof Options[Key]]: Payload extends keyof PayloadsOf<Registry[Name]> ? Options[Key][Payload] : never; } : 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; };
|
|
270
|
+
/** Typed per-collection query entry points that never expose source configuration at runtime. */
|
|
271
|
+
type RelationalQueries<Registry extends CollectionRegistry> = string extends keyof Registry ? {} : { readonly [Name in keyof Registry & string]: {
|
|
272
|
+
/** Returns matching metadata rows and requested relationships. */
|
|
273
|
+
findMany<const Options extends RelationalQueryOptions<Registry, Name> = {}>(options?: Options & CheckedRelationalOptions<Registry, Name, NoInfer<Options>>): Promise<RelationalQueryResult<Registry, Name, Options>[]>;
|
|
274
|
+
/** Returns the first matching entry, or undefined when none matches. */
|
|
275
|
+
findFirst<const Options extends RelationalQueryOptions<Registry, Name> = {}>(options?: Options & CheckedRelationalOptions<Registry, Name, NoInfer<Options>>): Promise<RelationalQueryResult<Registry, Name, Options> | undefined>;
|
|
276
|
+
}; };
|
|
277
|
+
//#endregion
|
|
278
|
+
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,34 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
10
|
+
var __exportAll = (all, no_symbols) => {
|
|
11
|
+
let target = {};
|
|
12
|
+
for (var name in all) __defProp(target, name, {
|
|
13
|
+
get: all[name],
|
|
14
|
+
enumerable: true
|
|
15
|
+
});
|
|
16
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
21
|
+
key = keys[i];
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
23
|
+
get: ((k) => from[k]).bind(null, key),
|
|
24
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return to;
|
|
28
|
+
};
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
//#endregion
|
|
34
|
+
export { __exportAll as n, __toESM as r, __commonJSMin as t };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { n as ContentRenderResult, t as ContentHeading } from "./types-Dh-Sydyw.mjs";
|
|
2
|
+
import { a as ContentError, i as ContentDiagnostic, o as ContentErrorCode, t as Content } from "./content-G69dPPuo.mjs";
|
|
3
|
+
export { type Content, type ContentDiagnostic, ContentError, type ContentErrorCode, type ContentHeading, type ContentRenderResult };
|
package/dist/runtime.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { n as __exportAll } from "./rolldown-runtime-Bg1v5YCA.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,11 @@
|
|
|
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
|
+
declare namespace builders_d_exports {
|
|
4
|
+
export { array, bigint, boolean, coerce, date, enum$1 as enum, output as infer, input, literal, number, object, output, record, string, union, unknown };
|
|
5
|
+
}
|
|
6
|
+
/** Infers the input type of any Standard Schema V1 validator. */
|
|
7
|
+
type input<Validator extends StandardSchemaV1> = StandardSchemaV1.InferInput<Validator>;
|
|
8
|
+
/** Infers the validated output type of any Standard Schema V1 validator. */
|
|
9
|
+
type output<Validator extends StandardSchemaV1> = StandardSchemaV1.InferOutput<Validator>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { builders_d_exports as schema };
|
package/dist/schema.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as schema } from "./schema-C5Str-E8.mjs";
|
|
@@ -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,69 @@
|
|
|
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 };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { r as RenderedContent } from "./types-Dh-Sydyw.mjs";
|
|
2
|
+
//#region src/shared/types.d.ts
|
|
3
|
+
type MaybePromise<Value> = Value | Promise<Value>;
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/loaders/types.d.ts
|
|
6
|
+
declare const loaderSourceType: unique symbol;
|
|
7
|
+
declare const recordLoaderType: 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)[][];
|
|
19
|
+
/** Optional ContentQuery metadata; Astro stores do not retain this extension. */
|
|
20
|
+
source?: Source;
|
|
21
|
+
};
|
|
22
|
+
/** Source metadata supplied by loaders of individual local files. */
|
|
23
|
+
type FileSource = {
|
|
24
|
+
filePath: string;
|
|
25
|
+
};
|
|
26
|
+
/** Source metadata identifying a record within a shared local file. */
|
|
27
|
+
type FileEntrySource = FileSource & {
|
|
28
|
+
key: string;
|
|
29
|
+
};
|
|
30
|
+
type DataStore<in Source = unknown> = {
|
|
31
|
+
get<Data extends Record<string, unknown> = Record<string, unknown>>(key: string): DataEntry<Data> | undefined;
|
|
32
|
+
set<Data extends Record<string, unknown>>(entry: DataEntry<Data, Source>): boolean;
|
|
33
|
+
entries(): [string, DataEntry][];
|
|
34
|
+
values(): DataEntry[];
|
|
35
|
+
keys(): string[];
|
|
36
|
+
has(key: string): boolean;
|
|
37
|
+
delete(key: string): void;
|
|
38
|
+
clear(): void;
|
|
39
|
+
addModuleImport(filename: string): void;
|
|
40
|
+
};
|
|
41
|
+
type MetaStore = {
|
|
42
|
+
get(key: string): string | undefined;
|
|
43
|
+
set(key: string, value: string): void;
|
|
44
|
+
has(key: string): boolean;
|
|
45
|
+
delete(key: string): void;
|
|
46
|
+
};
|
|
47
|
+
type LoaderConfig = {
|
|
48
|
+
root: URL;
|
|
49
|
+
srcDir: URL;
|
|
50
|
+
publicDir: URL;
|
|
51
|
+
outDir: URL;
|
|
52
|
+
cacheDir: URL;
|
|
53
|
+
base: string;
|
|
54
|
+
site?: string;
|
|
55
|
+
output: "static" | "server" | "hybrid";
|
|
56
|
+
};
|
|
57
|
+
type LoaderLogger = {
|
|
58
|
+
label: string;
|
|
59
|
+
options: {
|
|
60
|
+
level: "debug" | "info" | "warn" | "error" | "silent";
|
|
61
|
+
destination: {
|
|
62
|
+
write(message: {
|
|
63
|
+
label: string | null;
|
|
64
|
+
level: "debug" | "info" | "warn" | "error" | "silent";
|
|
65
|
+
message: string;
|
|
66
|
+
newLine: boolean;
|
|
67
|
+
}): void;
|
|
68
|
+
flush?(): void | Promise<void>;
|
|
69
|
+
close?(): void | Promise<void>;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
info(message: string): void;
|
|
73
|
+
warn(message: string): void;
|
|
74
|
+
error(message: string): void;
|
|
75
|
+
debug(message: string): void;
|
|
76
|
+
fork(label: string): LoaderLogger;
|
|
77
|
+
flush(): void;
|
|
78
|
+
close(): void;
|
|
79
|
+
};
|
|
80
|
+
type LoaderWatchEvents = {
|
|
81
|
+
add: [filename: string];
|
|
82
|
+
change: [filename: string];
|
|
83
|
+
unlink: [filename: string];
|
|
84
|
+
addDir: [filename: string];
|
|
85
|
+
unlinkDir: [filename: string];
|
|
86
|
+
all: [event: string, filename: string];
|
|
87
|
+
error: [cause: Error];
|
|
88
|
+
ready: [];
|
|
89
|
+
};
|
|
90
|
+
/** Shared filesystem watcher; loader callbacks are serialized and published as complete batches. */
|
|
91
|
+
interface LoaderWatcher {
|
|
92
|
+
on<Event extends keyof LoaderWatchEvents>(event: Event, listener: (...arguments_: LoaderWatchEvents[Event]) => unknown): LoaderWatcher;
|
|
93
|
+
once<Event extends keyof LoaderWatchEvents>(event: Event, listener: (...arguments_: LoaderWatchEvents[Event]) => unknown): LoaderWatcher;
|
|
94
|
+
off<Event extends keyof LoaderWatchEvents>(event: Event, listener: (...arguments_: LoaderWatchEvents[Event]) => unknown): LoaderWatcher;
|
|
95
|
+
removeListener<Event extends keyof LoaderWatchEvents>(event: Event, listener: (...arguments_: LoaderWatchEvents[Event]) => unknown): LoaderWatcher;
|
|
96
|
+
removeAllListeners(event?: string): LoaderWatcher;
|
|
97
|
+
add(paths: string | readonly string[]): LoaderWatcher;
|
|
98
|
+
unwatch(paths: string | readonly string[]): LoaderWatcher;
|
|
99
|
+
close(): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
type LoaderContext<in Source = unknown> = {
|
|
102
|
+
collection: string;
|
|
103
|
+
store: DataStore<Source>;
|
|
104
|
+
meta: MetaStore;
|
|
105
|
+
config: LoaderConfig;
|
|
106
|
+
logger: LoaderLogger;
|
|
107
|
+
watcher?: LoaderWatcher;
|
|
108
|
+
/** ContentQuery extension: cancellation for this load attempt. */
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
parseData<Data extends Record<string, unknown>>(options: {
|
|
111
|
+
id: string;
|
|
112
|
+
data: Data;
|
|
113
|
+
filePath?: string;
|
|
114
|
+
}): Promise<Data>;
|
|
115
|
+
renderMarkdown(content: string, options?: {
|
|
116
|
+
fileURL?: URL;
|
|
117
|
+
}): Promise<RenderedContent>;
|
|
118
|
+
generateDigest(data: Record<string, unknown> | string): string;
|
|
119
|
+
refreshContextData?: Record<string, unknown>;
|
|
120
|
+
};
|
|
121
|
+
/** An Astro-compatible, named build-time content loader. */
|
|
122
|
+
type Loader<out Source = unknown> = {
|
|
123
|
+
/** Type-only marker preserving metadata inference without changing Astro's load signature. */
|
|
124
|
+
readonly [loaderSourceType]?: Source;
|
|
125
|
+
name: string;
|
|
126
|
+
schema?: unknown;
|
|
127
|
+
createSchema?(): MaybePromise<{
|
|
128
|
+
schema: unknown;
|
|
129
|
+
types?: string;
|
|
130
|
+
}>;
|
|
131
|
+
load(context: LoaderContext<Source>): Promise<void>;
|
|
132
|
+
};
|
|
133
|
+
/** A loader whose entries are data records without bodies or rendered output, such as `file()`. */
|
|
134
|
+
type RecordLoader<Source = unknown> = Loader<Source> & {
|
|
135
|
+
/** Type-only marker: entries never carry built-in `_body` or `_rendered` payloads. */
|
|
136
|
+
readonly [recordLoaderType]: true;
|
|
137
|
+
};
|
|
138
|
+
/** Infers the source metadata a typed loader supplies to computed resolvers. */
|
|
139
|
+
type LoaderSource<Value> = Value extends {
|
|
140
|
+
readonly [loaderSourceType]?: infer Source;
|
|
141
|
+
} ? Source : unknown;
|
|
142
|
+
//#endregion
|
|
143
|
+
export { Loader as a, LoaderLogger as c, MetaStore as d, RecordLoader as f, FileSource as i, LoaderSource as l, DataStore as n, LoaderConfig as o, MaybePromise as p, FileEntrySource as r, LoaderContext as s, DataEntry as t, LoaderWatcher as u };
|
|
@@ -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 };
|