@content-collections/core 0.6.4 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -28,7 +28,7 @@ Content Collections offers a variety of adapters that seamlessly integrate with
28
28
  - [Qwik](https://www.content-collections.dev/docs/quickstart/qwik)
29
29
  - [Remix (Vite)](https://www.content-collections.dev/docs/quickstart/remix-vite)
30
30
  - [Solid Start](https://www.content-collections.dev/docs/quickstart/solid)
31
- - [Svelte Kit](https://www.content-collections.dev/docs/quickstart/svelte-kit)
31
+ - [SvelteKit](https://www.content-collections.dev/docs/quickstart/svelte-kit)
32
32
  - [Vite](https://www.content-collections.dev/docs/quickstart/vite)
33
33
 
34
34
  If your framework is not listed, you can still use Content Collections by using the [CLI](https://www.content-collections.dev/docs/quickstart/cli). Please open a ticket if you want to see your framework listed.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import z__default, { ZodRawShape, z as z$1, ZodObject, ZodTypeAny, ZodString } from 'zod';
2
2
  export * from 'zod';
3
3
 
4
+ type CacheFn = <TInput, TOutput>(input: TInput, compute: (input: TInput) => Promise<TOutput> | TOutput) => Promise<TOutput>;
5
+
4
6
  type Parsers = typeof parsers;
5
7
  type Parser = keyof typeof parsers;
6
8
  declare function parseYaml(content: string): any;
@@ -14,7 +16,7 @@ declare const parsers: {
14
16
  };
15
17
  readonly json: {
16
18
  readonly hasContent: false;
17
- readonly parse: (text: string, reviver?: ((this: any, key: string, value: any) => any) | undefined) => any;
19
+ readonly parse: (text: string, reviver?: (this: any, key: string, value: any) => any) => any;
18
20
  };
19
21
  readonly yaml: {
20
22
  readonly hasContent: false;
@@ -22,8 +24,6 @@ declare const parsers: {
22
24
  };
23
25
  };
24
26
 
25
- type CacheFn = <TInput, TOutput>(input: TInput, compute: (input: TInput) => Promise<TOutput> | TOutput) => Promise<TOutput>;
26
-
27
27
  declare const literalSchema: z__default.ZodUnion<[z__default.ZodString, z__default.ZodNumber, z__default.ZodBoolean, z__default.ZodNull, z__default.ZodUndefined, z__default.ZodDate, z__default.ZodMap<z__default.ZodUnknown, z__default.ZodUnknown>, z__default.ZodSet<z__default.ZodUnknown>, z__default.ZodBigInt]>;
28
28
  type Literal = z__default.infer<typeof literalSchema>;
29
29
  type SchemaType = Literal | {
@@ -54,12 +54,13 @@ type GetShape<TParser extends Parser | undefined, TShape extends ZodRawShape> =
54
54
  type Schema<TParser extends Parser | undefined, TShape extends ZodRawShape> = z$1.infer<ZodObject<GetShape<TParser, TShape>>> & {
55
55
  _meta: Meta;
56
56
  };
57
- type Context = {
57
+ type Context<TSchema = unknown> = {
58
58
  documents<TCollection extends AnyCollection>(collection: TCollection): Array<Schema<TCollection["parser"], TCollection["schema"]>>;
59
59
  cache: CacheFn;
60
60
  collection: {
61
61
  name: string;
62
62
  directory: string;
63
+ documents: () => Promise<Array<TSchema>>;
63
64
  };
64
65
  };
65
66
  type Z = typeof z$1;
@@ -68,7 +69,7 @@ type CollectionRequest<TName extends string, TShape extends ZodRawShape, TParser
68
69
  parser?: TParser;
69
70
  typeName?: string;
70
71
  schema: (z: Z) => TShape;
71
- transform?: (data: TSchema, context: Context) => TTransformResult;
72
+ transform?: (data: TSchema, context: Context<TSchema>) => TTransformResult;
72
73
  directory: string;
73
74
  include: string | string[];
74
75
  exclude?: string | string[];
@@ -150,12 +151,31 @@ declare class TransformError extends Error {
150
151
  }
151
152
 
152
153
  type WatcherEvents = {
153
- "watcher:file-changed": {
154
- filePath: string;
155
- modification: Modification;
154
+ "watcher:subscribe-error": {
155
+ paths: Array<string>;
156
+ error: Error;
157
+ };
158
+ "watcher:subscribed": {
159
+ paths: Array<string>;
156
160
  };
161
+ "watcher:unsubscribed": {
162
+ paths: Array<string>;
163
+ };
164
+ };
165
+ type SyncFn = (modification: Modification, path: string) => Promise<unknown>;
166
+ type WatchableCollection = {
167
+ directory: string;
168
+ };
169
+ type WatcherConfiguration = {
170
+ inputPaths: Array<string>;
171
+ collections: Array<WatchableCollection>;
157
172
  };
173
+ declare function createWatcher(emitter: Emitter, baseDirectory: string, configuration: WatcherConfiguration, sync: SyncFn): Promise<{
174
+ unsubscribe: () => Promise<void>;
175
+ }>;
176
+ type Watcher = Awaited<ReturnType<typeof createWatcher>>;
158
177
 
178
+ type EventMap = Record<string, object>;
159
179
  type EventWithError = {
160
180
  error: Error;
161
181
  };
@@ -168,6 +188,16 @@ type SystemEvents = {
168
188
  _error: ErrorEvent;
169
189
  _all: SystemEvent;
170
190
  };
191
+ type Keys<TEvents extends EventMap> = keyof TEvents & string;
192
+ type Listener<TEvent> = (event: TEvent) => void;
193
+ declare function createEmitter<TEvents extends EventMap>(): {
194
+ on: {
195
+ <TKey extends Keys<TEvents>>(key: TKey, listener: Listener<TEvents[TKey]>): void;
196
+ <TKey extends Keys<SystemEvents>>(key: TKey, listener: Listener<SystemEvents[TKey]>): void;
197
+ };
198
+ emit: <TKey extends Keys<TEvents>>(key: TKey, event: TEvents[TKey]) => void;
199
+ };
200
+ type Emitter = ReturnType<typeof createEmitter<Events>>;
171
201
 
172
202
  type ErrorType = "Read" | "Compile";
173
203
  declare class ConfigurationError extends Error {
@@ -179,29 +209,56 @@ type Options$1 = {
179
209
  cacheDir?: string;
180
210
  };
181
211
 
182
- type BuilderEvents = {
212
+ type BuildEvents = {
183
213
  "builder:start": {
184
214
  startedAt: number;
185
215
  };
186
216
  "builder:end": {
187
217
  startedAt: number;
188
218
  endedAt: number;
219
+ stats: {
220
+ collections: number;
221
+ documents: number;
222
+ };
223
+ };
224
+ };
225
+
226
+ type BuilderEvents = BuildEvents & {
227
+ "builder:created": {
228
+ createdAt: number;
229
+ configurationPath: string;
230
+ outputDirectory: string;
231
+ };
232
+ "watcher:file-changed": {
233
+ filePath: string;
234
+ modification: Modification;
235
+ };
236
+ "watcher:config-changed": {
237
+ filePath: string;
238
+ modification: Modification;
239
+ };
240
+ "watcher:config-reload-error": {
241
+ error: Error;
242
+ configurationPath: string;
189
243
  };
190
244
  };
191
245
  type Options = Options$1 & {
192
246
  outputDir?: string;
193
247
  };
194
- declare function createBuilder(configurationPath: string, options?: Options): Promise<{
195
- sync: (modification: Modification, filePath: string) => Promise<boolean>;
248
+ declare class ConfigurationReloadError extends Error {
249
+ constructor(message: string);
250
+ }
251
+ declare function createBuilder(configurationPath: string, options?: Options, emitter?: Emitter): Promise<{
196
252
  build: () => Promise<void>;
253
+ sync: (modification: Modification, filePath: string) => Promise<boolean>;
197
254
  watch: () => Promise<{
198
255
  unsubscribe: () => Promise<void>;
199
256
  }>;
200
257
  on: {
201
- <TKey extends "builder:start" | "builder:end" | "collector:read-error" | "collector:parse-error" | "transformer:validation-error" | "transformer:result-error" | "transformer:error" | "watcher:file-changed">(key: TKey, listener: (event: Events[TKey]) => void): void;
202
- <TKey_1 extends "_error" | "_all">(key: TKey_1, listener: (event: SystemEvents[TKey_1]) => void): void;
258
+ <TKey extends "builder:start" | "builder:end" | "builder:created" | "watcher:file-changed" | "watcher:config-changed" | "watcher:config-reload-error" | "collector:read-error" | "collector:parse-error" | "transformer:validation-error" | "transformer:result-error" | "transformer:error" | "watcher:subscribe-error" | "watcher:subscribed" | "watcher:unsubscribed">(key: TKey, listener: (event: Events[TKey]) => void): void;
259
+ <TKey extends "_error" | "_all">(key: TKey, listener: (event: SystemEvents[TKey]) => void): void;
203
260
  };
204
261
  }>;
205
262
  type Builder = Awaited<ReturnType<typeof createBuilder>>;
206
263
 
207
- export { type AnyCollection, type AnyConfiguration, type Builder, type BuilderEvents, CollectError, type Collection, type CollectionRequest, type Configuration, ConfigurationError, type Context, type Document, type GetTypeByName, type Meta, type Modification, type Schema, TransformError, createBuilder, defineCollection, defineConfig };
264
+ export { type AnyCollection, type AnyConfiguration, type Builder, type BuilderEvents, CollectError, type Collection, type CollectionRequest, type Configuration, ConfigurationError, ConfigurationReloadError, type Context, type Document, type GetTypeByName, type Meta, type Modification, type Schema, TransformError, type Watcher, createBuilder, defineCollection, defineConfig };