content-query 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,119 @@
1
+ import { _ as Relationship, g as QueryData, i as CollectionRegistry, u as LoadedMarker, v as RelationshipsOf } from "./types-Dz1vTXa2.mjs";
2
+ import { n as RelationalCountOptions, t as RelationalCollectionQueries, v as Query } from "./relational-types-CTcalUNW.mjs";
3
+ import { i as QueryStyleMember, n as QueryStyle, r as QueryStyleDisabled, t as MembersOf } from "./query-style-C2FcT1f9.mjs";
4
+ //#region src/shared/errors.d.ts
5
+ type ContentErrorCode = "variant-not-found" | "not-renderable" | "source-error" | "validation-error" | "duplicate-id" | "invalid-reference" | "invalid-query" | "invalid-cursor" | "artifact-error" | "render-error";
6
+ type ContentDiagnostic = {
7
+ code: ContentErrorCode;
8
+ message: string;
9
+ operation?: string;
10
+ collection?: string;
11
+ id?: string;
12
+ source?: string;
13
+ path?: readonly PropertyKey[];
14
+ /** The custom payload being resolved or loaded. */
15
+ payload?: string;
16
+ /** The payload's variant combination, with keys in sorted order. */
17
+ variant?: Readonly<Record<string, string>>;
18
+ issues?: readonly unknown[];
19
+ cause?: unknown;
20
+ };
21
+ /** A contextual library failure; inspect code and diagnostics instead of message text. */
22
+ declare class ContentError extends Error {
23
+ /** Recognizes contextual errors across preparation and separately bundled loader modules. */
24
+ static [Symbol.hasInstance](value: unknown): boolean;
25
+ readonly code: ContentErrorCode;
26
+ readonly operation?: string;
27
+ readonly collection?: string;
28
+ readonly id?: string;
29
+ readonly source?: string;
30
+ readonly path?: readonly PropertyKey[];
31
+ readonly payload?: string;
32
+ readonly variant?: Readonly<Record<string, string>>;
33
+ readonly issues?: readonly unknown[];
34
+ readonly diagnostics: readonly ContentDiagnostic[];
35
+ /** Creates one failure or a grouped report preserving individual causes and issues. */
36
+ constructor(options: ContentDiagnostic & {
37
+ diagnostics?: readonly ContentDiagnostic[];
38
+ });
39
+ }
40
+ //#endregion
41
+ //#region src/collection/registry-types.d.ts
42
+ type Scalar = string | number | bigint | boolean | Date;
43
+ type Element<Value> = NonNullable<Value> extends readonly (infer Item)[] ? NonNullable<Item> : NonNullable<Value>;
44
+ type Compatible<Left, Right> = NonNullable<Left> extends readonly unknown[] ? NonNullable<Right> extends readonly unknown[] ? false : ScalarCompatible<Left, Right> : ScalarCompatible<Left, Right>;
45
+ type ScalarCompatible<Left, Right> = [Element<Left> | Element<Right>] extends [Scalar] ? [Element<Left>] extends [never] ? true : [Element<Right>] extends [never] ? true : [Extract<Element<Left>, Element<Right>> | Extract<Element<Right>, Element<Left>>] extends [never] ? false : true : false;
46
+ type CheckRelation<Registry extends CollectionRegistry, Name extends keyof Registry, Link extends Relationship> = Link["collection"] extends keyof Registry ? Link["from"] extends keyof QueryData<Registry[Name]> ? Link["to"] extends keyof QueryData<Registry[Link["collection"]]> ? Compatible<QueryData<Registry[Name]>[Link["from"]], QueryData<Registry[Link["collection"]]>[Link["to"]]> extends true ? never : "incompatible-relationship-fields" : "unknown-target-field" : "unknown-source-field" : "unknown-target-collection";
47
+ /** Registry-level relationship checks require the complete inferred collection map. */
48
+ type InvalidRelationships<Registry extends CollectionRegistry> = { [Name in keyof Registry]: { [Link in keyof RelationshipsOf<Registry[Name]>]: RelationshipsOf<Registry[Name]>[Link] extends Relationship ? CheckRelation<Registry, Name, RelationshipsOf<Registry[Name]>[Link]> : "invalid-relationship"; }[keyof RelationshipsOf<Registry[Name]>]; }[keyof Registry];
49
+ //#endregion
50
+ //#region src/runtime/collection-types.d.ts
51
+ declare const collectionType: unique symbol;
52
+ /**
53
+ * The registry a query scope sees: only the loaded collections, each marked so it offers only the
54
+ * relationships into loaded collections.
55
+ */
56
+ type LoadedRegistry<Registry extends CollectionRegistry, Loaded extends keyof Registry & string> = { [Name in Loaded]: Registry[Name] & LoadedMarker<Loaded>; };
57
+ /** The members that start a fluent query; terminals such as `all()` follow one of them. */
58
+ type FluentMember = MembersOf<"fluent">;
59
+ /** The relational members, apart from `count`, which both styles share. */
60
+ type RelationalMember = "findMany" | "findFirst" | "paginate";
61
+ /** Every member before `queryStyle` gating. */
62
+ type CollectionMethods<Registry extends CollectionRegistry, Name extends keyof Registry & string> = Pick<Query<Registry, Name>, FluentMember & keyof Query<Registry, Name>> & RelationalCollectionQueries<Registry, Name>;
63
+ /**
64
+ * Members outside the allowed style. Calls report the message as the required `this` type,
65
+ * whatever arguments they pass.
66
+ */
67
+ type DisabledMembers<Name extends string, Style extends QueryStyle> = { readonly [Member in Exclude<FluentMember | RelationalMember, MembersOf<Style>>]: (this: QueryStyleDisabled<Name, Member & QueryStyleMember, Style>, ...arguments_: readonly unknown[]) => never; };
68
+ /** `count()` counts every entry in both styles; options take relational filters. */
69
+ type CountMember<Registry extends CollectionRegistry, Name extends keyof Registry & string, Style extends QueryStyle> = [Style] extends ["fluent"] ? {
70
+ /** Counts every entry. Count filtered entries with `where(...).count()`. */
71
+ count(): Promise<number>;
72
+ } : {
73
+ /** Counts matching entries before pagination, like the fluent `count()` terminal. */
74
+ count(options?: RelationalCountOptions<Registry, Name>): Promise<number>;
75
+ };
76
+ /** Reads the collections a collection handle loads. */
77
+ type LoadedOf<Handle> = Handle extends {
78
+ readonly [collectionType]: {
79
+ loaded: infer Loaded;
80
+ };
81
+ } ? Loaded : never;
82
+ /** Any collection handle, as `using()` accepts it. */
83
+ type AnyCollection = {
84
+ readonly [collectionType]: {
85
+ loaded: string;
86
+ };
87
+ };
88
+ /**
89
+ * One collection's query API, as its generated entry exports it.
90
+ *
91
+ * Queries load only this collection and the collections passed to `using()`. Relationships into
92
+ * any other collection are type errors here and `invalid-query` errors at runtime. `Style` narrows
93
+ * the members to the `queryStyle` exported by content-query.config; the default allows both.
94
+ *
95
+ * @typeParam Registry - The configured collection registry.
96
+ * @typeParam Name - The queried collection.
97
+ * @typeParam Style - The allowed query style.
98
+ * @typeParam Loaded - The collections this handle loads, including `Name`.
99
+ */
100
+ type Collection<Registry extends CollectionRegistry, Name extends keyof Registry & string, Style extends QueryStyle = QueryStyle, Loaded extends keyof Registry & string = Name> = InvalidRelationships<Registry> extends never ? Pick<CollectionMethods<LoadedRegistry<Registry, Loaded | Name>, Name>, Extract<FluentMember | RelationalMember, MembersOf<Style>>> & DisabledMembers<Name, Style> & CountMember<LoadedRegistry<Registry, Loaded | Name>, Name, Style> & {
101
+ /**
102
+ * Supplies other collections, so this collection's queries can follow relationships
103
+ * into them. Nested relationships need each collection they reach.
104
+ *
105
+ * @param collections - Collections imported from their own entries.
106
+ * @returns A handle over this collection that also loads the supplied collections.
107
+ */
108
+ using<const Supplied extends readonly AnyCollection[]>(...collections: Supplied): Collection<Registry, Name, Style, Loaded | (LoadedOf<Supplied[number]> & keyof Registry & string)>;
109
+ readonly [collectionType]: {
110
+ readonly name: Name;
111
+ readonly loaded: Loaded | Name;
112
+ };
113
+ } : {
114
+ readonly invalidRelationships: InvalidRelationships<Registry>;
115
+ };
116
+ /** One handle per collection, keyed by collection name, each loading only its own collection. */
117
+ type CollectionHandles<Registry extends CollectionRegistry, Style extends QueryStyle = QueryStyle> = { readonly [Name in keyof Registry & string]: Collection<Registry, Name, Style>; };
118
+ //#endregion
119
+ export { InvalidRelationships as a, ContentErrorCode as c, LoadedRegistry as i, Collection as n, ContentDiagnostic as o, CollectionHandles as r, ContentError as s, AnyCollection as t };
@@ -1,5 +1,5 @@
1
1
  import { g as MaybePromise } from "./descriptor-bcPa6XLk.mjs";
2
- import { a as ComputedContext } from "./types-DbFfF6JE.mjs";
2
+ import { a as ComputedContext } from "./types-Dz1vTXa2.mjs";
3
3
  import { StandardSchemaV1 } from "@standard-schema/spec";
4
4
  //#region src/computed/text.d.ts
5
5
  /** The syntax removed before computing text-derived fields; literal text preserves all characters. */
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as DataStore, c as Loader, d as LoaderLogger, f as LoaderSource, g as MaybePromise, h as RecordLoader, i as DataEntry, l as LoaderConfig, m as MetaStore, n as GlobOptions, o as FileEntrySource, p as LoaderWatcher, r as BodyLoader, s as FileSource, u as LoaderContext } from "./descriptor-bcPa6XLk.mjs";
2
2
  import { n as ContentRenderResult, r as RenderedContent, t as ContentHeading } from "./types-Dh-Sydyw.mjs";
3
- import { C as VariantValues, S as VariantOf, a as ComputedContext, b as VariantContext, c as EntryFiles, d as PayloadData, f as PayloadDeclaration, g as Relationship, h as QueryData, i as CollectionRegistry, l as FileEntry, m as PayloadsOf, n as BuiltinPayloads, o as CustomPayload, p as PayloadDefinition, r as CollectionDefinition, s as CustomPayloadMarker, t as BuiltinPayloadMarker, u as PayloadContext, v as Schema, x as VariantField, y as SchemaOutput } from "./types-DbFfF6JE.mjs";
4
- import { n as QueryStyle } from "./query-style-eXENQJ0O.mjs";
3
+ import { C as VariantContext, E as VariantValues, T as VariantOf, _ as Relationship, a as ComputedContext, b as SchemaOutput, c as EntryFiles, d as PayloadContext, f as PayloadData, g as QueryData, h as PayloadsOf, i as CollectionRegistry, l as FileEntry, m as PayloadDefinition, n as BuiltinPayloads, o as CustomPayload, p as PayloadDeclaration, r as CollectionDefinition, s as CustomPayloadMarker, t as BuiltinPayloadMarker, w as VariantField, y as Schema } from "./types-Dz1vTXa2.mjs";
4
+ import { n as QueryStyle } from "./query-style-C2FcT1f9.mjs";
5
5
  import { StandardSchemaV1 } from "@standard-schema/spec";
6
6
  //#region src/collection/source.d.ts
7
7
  type CollectionSource = string | ({
@@ -56,6 +56,11 @@ type CollectionFields<SourceSchema extends Schema | undefined, ComputedSchemas e
56
56
  }; };
57
57
  /** Directories, relative to the project root, that resolvers' `files` helpers may also read. */
58
58
  sharedFiles?: readonly string[];
59
+ /**
60
+ * The singular name in generated types, such as `"Category"` for `ContentCategory`. Defaults to
61
+ * the export name without one trailing `s`, so `jobs` generates `ContentJob`.
62
+ */
63
+ typeName?: string;
59
64
  /** Named per-entry data resolved during preparation and loaded only when a query requests it. */
60
65
  payloads?: PayloadDeclarations<SourceSchema, ComputedSchemas, PayloadSchemas, PayloadVariants, Source>;
61
66
  };
@@ -83,6 +88,11 @@ declare function collectionOf<SourceSchema extends StandardSchemaV1<unknown, Rec
83
88
  source: CollectionSource;
84
89
  /** Directories, relative to the project root, that resolvers' `files` helpers may also read. */
85
90
  sharedFiles?: readonly string[];
91
+ /**
92
+ * The singular name in generated types, such as `"Category"` for `ContentCategory`. Defaults to
93
+ * the export name without one trailing `s`, so `jobs` generates `ContentJob`.
94
+ */
95
+ typeName?: string;
86
96
  /** Named per-entry data resolved during preparation and loaded only when a query requests it. */
87
97
  payloads?: PayloadDeclarations<SourceSchema, ComputedSchemas, PayloadSchemas, PayloadVariants, FileSource> | undefined;
88
98
  } | {
@@ -99,6 +109,11 @@ declare function collectionOf<SourceSchema extends StandardSchemaV1<unknown, Rec
99
109
  source?: never;
100
110
  /** Directories, relative to the project root, that resolvers' `files` helpers may also read. */
101
111
  sharedFiles?: readonly string[];
112
+ /**
113
+ * The singular name in generated types, such as `"Category"` for `ContentCategory`. Defaults to
114
+ * the export name without one trailing `s`, so `jobs` generates `ContentJob`.
115
+ */
116
+ typeName?: string;
102
117
  /** Named per-entry data resolved during preparation and loaded only when a query requests it. */
103
118
  payloads?: PayloadDeclarations<SourceSchema, ComputedSchemas, PayloadSchemas, PayloadVariants, LoaderSource<NoInfer<ContentLoader>>> | undefined;
104
119
  };
@@ -1,8 +1,9 @@
1
- import { n as createLiveRuntime, o as ContentError, r as PreparedRevision, t as Content } from "./content-CwTKqRs9.mjs";
1
+ import { n as Collection, r as CollectionHandles, s as ContentError } from "./collection-types-CsQtGw7_.mjs";
2
2
  import { n as ContentRenderResult } from "./types-Dh-Sydyw.mjs";
3
- import { i as CollectionRegistry } from "./types-DbFfF6JE.mjs";
4
- import { b as QueryRegistry } from "./relational-types-C8xJtLG5.mjs";
5
- import { n as QueryStyle } from "./query-style-eXENQJ0O.mjs";
3
+ import { i as CollectionRegistry } from "./types-Dz1vTXa2.mjs";
4
+ import { O as QueryRegistry } from "./relational-types-CTcalUNW.mjs";
5
+ import { n as QueryStyle } from "./query-style-C2FcT1f9.mjs";
6
+ import { n as PreparedRevision, t as ContentState } from "./revision-DBwU-aC9.mjs";
6
7
  //#region src/artifacts/types.d.ts
7
8
  type ArtifactManifest = {
8
9
  version: number;
@@ -24,10 +25,36 @@ type EncodedCollection = {
24
25
  };
25
26
  //#endregion
26
27
  //#region src/artifacts/runtime.d.ts
27
- /** Initializes generated/embedded prepared content. This versioned wiring is internal. */
28
+ /**
29
+ * Initializes generated/embedded prepared content. This versioned wiring is internal.
30
+ * Relationships are related when a query scope combines the collections it loads.
31
+ *
32
+ * @param manifest - The entry's manifest; its registry lists exactly the collections it serves.
33
+ * @param collections - Generated collection modules by name.
34
+ * @param renderMarkdown - The packaged renderer, when a served collection captured Markdown.
35
+ * @returns The prepared revision.
36
+ */
28
37
  export declare function createArtifactRevision(manifest: ArtifactManifest, collections: Record<string, EncodedCollection>, renderMarkdown?: (body: string) => Promise<ContentRenderResult>): PreparedRevision;
29
- /** Initializes the public generated server export from a complete immutable artifact revision. */
30
- export declare function createArtifactRuntime<Registry extends CollectionRegistry>(manifest: ArtifactManifest, collections: Record<string, EncodedCollection>, renderMarkdown?: (body: string) => Promise<ContentRenderResult>): Content<Registry, QueryStyle>;
38
+ /**
39
+ * Initializes one generated collection entry's export.
40
+ *
41
+ * @param manifest - The entry's manifest, which lists only this collection.
42
+ * @param name - The collection's name.
43
+ * @param collection - The generated collection module.
44
+ * @param renderMarkdown - The packaged renderer, when the collection captured Markdown.
45
+ * @returns The collection handle the entry exports.
46
+ */
47
+ export declare function createArtifactCollection<Registry extends CollectionRegistry, Name extends keyof Registry & string, Style extends QueryStyle = QueryStyle>(manifest: ArtifactManifest, name: Name, collection: EncodedCollection, renderMarkdown?: (body: string) => Promise<ContentRenderResult>): Collection<Registry, Name, Style>;
48
+ /**
49
+ * Initializes handles for every collection of one artifact revision, sharing its caches. Tests
50
+ * and integrations use it; applications import each collection's own entry instead.
51
+ *
52
+ * @param manifest - A manifest that lists every collection in `collections`.
53
+ * @param collections - Generated collection modules by name.
54
+ * @param renderMarkdown - The packaged renderer, when a collection captured Markdown.
55
+ * @returns Collection handles keyed by collection name.
56
+ */
57
+ export declare function createArtifactCollections<Registry extends CollectionRegistry, Style extends QueryStyle = QueryStyle>(manifest: ArtifactManifest, collections: Record<string, EncodedCollection>, renderMarkdown?: (body: string) => Promise<ContentRenderResult>): CollectionHandles<Registry, Style>;
31
58
  //#endregion
32
59
  //#region src/artifacts/payloads.d.ts
33
60
  /**
@@ -54,8 +81,21 @@ type PayloadChunk = {
54
81
  */
55
82
  export declare function createPayloadLoaders(chunks: readonly PayloadChunk[]): EncodedCollection["builtins"];
56
83
  //#endregion
84
+ //#region src/runtime/collection.d.ts
85
+ /**
86
+ * Keeps one collection handle live across host-delivered development revisions.
87
+ *
88
+ * @param initial - The first prepared state.
89
+ * @param name - The collection the handle queries.
90
+ * @returns The handle and an `update()` that switches its state to a newer revision or error.
91
+ */
92
+ export declare function createLiveCollection(initial: ContentState, name: string): {
93
+ collection: object;
94
+ update(next: ContentState): void;
95
+ };
96
+ //#endregion
57
97
  //#region src/runtime/diagnostics.d.ts
58
98
  /** Restores the library error and its causes in a generated or isolated development runtime. */
59
99
  export declare function restoreContentError(encoded: string): ContentError;
60
100
  //#endregion
61
- export { createLiveRuntime };
101
+ export {};