@wdprlib/parser 5.4.0 → 6.0.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 (44) hide show
  1. package/dist/index.cjs +420 -127
  2. package/dist/index.d.cts +93 -8
  3. package/dist/index.d.ts +93 -8
  4. package/dist/index.js +380 -84
  5. package/package.json +2 -2
  6. package/src/build-info.generated.ts +2 -2
  7. package/src/index.ts +3 -0
  8. package/src/parser/rules/block/module/index.ts +3 -2
  9. package/src/parser/rules/block/module/listpages/extraction/listpages.ts +5 -0
  10. package/src/parser/rules/block/module/listpages/extraction/query.ts +1 -0
  11. package/src/parser/rules/block/module/listpages/extraction/template.ts +16 -0
  12. package/src/parser/rules/block/module/listpages/extraction/variables.ts +1 -0
  13. package/src/parser/rules/block/module/listpages/index.ts +1 -0
  14. package/src/parser/rules/block/module/listpages/normalization/order-parent.ts +9 -1
  15. package/src/parser/rules/block/module/listpages/normalize.ts +1 -0
  16. package/src/parser/rules/block/module/listpages/parser.ts +1 -0
  17. package/src/parser/rules/block/module/listpages/resolve.ts +4 -2
  18. package/src/parser/rules/block/module/listpages/template/excerpt.ts +63 -0
  19. package/src/parser/rules/block/module/listpages/template/format/content.ts +0 -32
  20. package/src/parser/rules/block/module/listpages/template/format/index.ts +1 -1
  21. package/src/parser/rules/block/module/listpages/template/getters/index.ts +14 -0
  22. package/src/parser/rules/block/module/listpages/template/getters/parameterized.ts +3 -1
  23. package/src/parser/rules/block/module/listpages/template/getters/registered.ts +52 -0
  24. package/src/parser/rules/block/module/listpages/template/getters/simple.ts +15 -5
  25. package/src/parser/rules/block/module/listpages/template/literal.ts +6 -0
  26. package/src/parser/rules/block/module/listpages/template/syntax.ts +10 -1
  27. package/src/parser/rules/block/module/listpages/types/data-requirements.ts +6 -0
  28. package/src/parser/rules/block/module/listpages/types/external-data.ts +36 -2
  29. package/src/parser/rules/block/module/listpages/types/normalized-query.ts +14 -4
  30. package/src/parser/rules/block/module/listpages/types/query.ts +2 -0
  31. package/src/parser/rules/block/module/listpages/types/variables.ts +5 -0
  32. package/src/parser/rules/block/module/listpages/url-resolution/fields.ts +2 -0
  33. package/src/parser/rules/block/module/listusers/resolve.ts +2 -1
  34. package/src/parser/rules/block/module/mapping.ts +2 -1
  35. package/src/parser/rules/block/module/rate/index.ts +16 -19
  36. package/src/parser/rules/block/module/rate/resolve.ts +108 -0
  37. package/src/parser/rules/block/module/rate/types.ts +6 -16
  38. package/src/parser/rules/block/module/resolution/resolve-async.ts +2 -1
  39. package/src/parser/rules/block/module/resolve.ts +10 -8
  40. package/src/parser/rules/block/module/types-common.ts +4 -0
  41. package/src/parser/rules/inline/parsing/inline-content.ts +10 -1
  42. package/src/parser/rules/inline/size/content.ts +31 -4
  43. package/src/pipeline/process.ts +13 -0
  44. package/src/pipeline/types.ts +19 -0
package/dist/index.d.cts CHANGED
@@ -4,6 +4,7 @@ declare const buildInfo: Readonly<{
4
4
  sha: string | null;
5
5
  dirty: boolean | null;
6
6
  }>;
7
+ import { RatingRef as RatingRef3, RatingVote, RatingAggregate as RatingAggregate2, RatingState as RatingState3 } from "@wdprlib/ast";
7
8
  import { Position as Position2, Point, Version as Version2, Element as Element8, SyntaxTree as SyntaxTree5, ContainerType, ContainerData, AttributeMap, VariableMap, Alignment, LinkType, LinkLocation, LinkLabel, PageRef as PageRef7, ImageSource, FloatAlignment, ListType, ListItem, ListData, CodeBlockData as CodeBlockData2, TabData, TableCell, TableRow, TableData, DefinitionListItem, Module as Module5, CollapsibleData, ClearFloat, AnchorTarget, HeaderType, AlignType, HeadingLevel, Heading, DateItem, Embed, TocEntry as TocEntry2, GallerySize, GalleryOrder, GalleryItem, GalleryContent, GalleryData, Diagnostic as Diagnostic4, DiagnosticSeverity, ParseResult as ParseResult4 } from "@wdprlib/ast";
8
9
  import { createPoint, createPosition, text, container, paragraph, bold, italics, heading, lineBreak, horizontalRule, link, list, listItemElements, listItemSubList } from "@wdprlib/ast";
9
10
  import { WikitextMode, WikitextSettings as WikitextSettings5 } from "@wdprlib/ast";
@@ -236,7 +237,7 @@ declare class Parser {
236
237
  */
237
238
  declare function parse(source: string, options?: ParserOptions): ParseResult2;
238
239
  import { WikitextPageContext as WikitextPageContext2 } from "@wdprlib/ast";
239
- import { Diagnostic, PageRef as PageRef5, SyntaxTree, WikitextPageContext, WikitextSettings as WikitextSettings3 } from "@wdprlib/ast";
240
+ import { Diagnostic, PageRef as PageRef5, SyntaxTree, WikitextPageContext, WikitextSettings as WikitextSettings3, RatingRef, RatingState, ReadableTextOptions } from "@wdprlib/ast";
240
241
  import { PageRef as PageRef4, WikitextSettings as WikitextSettings2 } from "@wdprlib/ast";
241
242
  interface IncludeAssignment {
242
243
  key: string;
@@ -412,6 +413,8 @@ interface ListPagesQuery {
412
413
  createdBy?: string;
413
414
  /** Rating selector. @untrusted User input. */
414
415
  rating?: string;
416
+ /** Exact registered custom key for rating/votes filters and order; omitted means main. */
417
+ ratingAxis?: string;
415
418
  /** Votes selector. @untrusted User input. */
416
419
  votes?: string;
417
420
  /** Page name selector. @untrusted User input. */
@@ -436,7 +439,7 @@ interface ListPagesQuery {
436
439
  /**
437
440
  * All supported ListPages template variables.
438
441
  */
439
- type ListPagesVariable = "created_at" | "created_by" | "created_by_unix" | "created_by_id" | "created_by_linked" | "updated_at" | "updated_by" | "updated_by_unix" | "updated_by_id" | "updated_by_linked" | "commented_at" | "commented_by" | "commented_by_unix" | "commented_by_id" | "commented_by_linked" | "name" | "category" | "fullname" | "title" | "title_linked" | "link" | "parent_name" | "parent_category" | "parent_fullname" | "parent_title" | "parent_title_linked" | "content" | "content_n" | "preview" | "preview_n" | "summary" | "first_paragraph" | "tags" | "tags_linked" | "_tags" | "_tags_linked" | "form_data" | "form_raw" | "form_label" | "form_hint" | "children" | "comments" | "size" | "rating" | "rating_votes" | "rating_percent" | "revisions" | "index" | "total" | "limit" | "total_or_limit" | "site_title" | "site_name" | "site_domain";
442
+ type ListPagesVariable = "metadata" | "customrate" | "customrate_votes" | "customrate_percent" | "created_at" | "created_by" | "created_by_unix" | "created_by_id" | "created_by_linked" | "updated_at" | "updated_by" | "updated_by_unix" | "updated_by_id" | "updated_by_linked" | "commented_at" | "commented_by" | "commented_by_unix" | "commented_by_id" | "commented_by_linked" | "name" | "category" | "fullname" | "title" | "title_linked" | "link" | "parent_name" | "parent_category" | "parent_fullname" | "parent_title" | "parent_title_linked" | "content" | "content_n" | "preview" | "preview_n" | "excerpt" | "summary" | "first_paragraph" | "tags" | "tags_linked" | "_tags" | "_tags_linked" | "form_data" | "form_raw" | "form_label" | "form_hint" | "children" | "comments" | "size" | "rating" | "rating_votes" | "rating_percent" | "revisions" | "index" | "total" | "limit" | "total_or_limit" | "site_title" | "site_name" | "site_domain";
440
443
  /**
441
444
  *
442
445
  * Type definitions for the ListUsers module.
@@ -614,6 +617,12 @@ interface ListPagesDataRequirement {
614
617
  previewLengths?: number[];
615
618
  /** Field names needed for form_data{field} etc. */
616
619
  formFields?: string[];
620
+ /** Exact metadata keys used by display templates. Also validate query.order on the host. */
621
+ metadataKeys?: string[];
622
+ /** Exact custom rating keys needed for display, independent of query.ratingAxis. */
623
+ customRateKeys?: string[];
624
+ /** Supply PageData.readableText and firstParagraph for previews, excerpts, and summaries. */
625
+ needsReadableText?: boolean;
617
626
  /** Prefix for tags_linked|prefix */
618
627
  tagsLinkPrefix?: string;
619
628
  /** Prefix for _tags_linked|prefix */
@@ -637,6 +646,21 @@ interface DataRequirements {
637
646
  listUsers: ListUsersDataRequirement[];
638
647
  tagCloud: TagCloudDataRequirement[];
639
648
  }
649
+ import { RatingAggregate } from "@wdprlib/ast";
650
+ /** Values for host-registered metadata keys. Missing entries remain unavailable. */
651
+ type PageMetadataValue = {
652
+ type: "text";
653
+ value: string;
654
+ } | {
655
+ type: "number";
656
+ value: number;
657
+ } | {
658
+ type: "date";
659
+ value: Date;
660
+ } | {
661
+ type: "user";
662
+ value: UserInfo;
663
+ };
640
664
  /**
641
665
  * User information.
642
666
  */
@@ -649,6 +673,18 @@ interface UserInfo {
649
673
  * Page data provided by an external source.
650
674
  */
651
675
  interface PageData {
676
+ /**
677
+ * `%%metadata{key}%%`: only registered, readable entries; keys are case-sensitive.
678
+ * Values are literal text. Date values accept strftime; user format is name, |id or |unix.
679
+ * Tag change date/editor may be host-defined keys; WDPR reserves no such keys.
680
+ */
681
+ metadata?: Readonly<Record<string, PageMetadataValue | null>>;
682
+ /**
683
+ * `%%customrate{key}%%`, `%%customrate_votes{key}%%`, `%%customrate_percent{key}%%`.
684
+ * Supply readable aggregates for requirement.customRateKeys, just as formFields selects
685
+ * form data. Missing keys expand to empty text; a supplied zero remains zero.
686
+ */
687
+ customRates?: Readonly<Record<string, RatingAggregate | null>>;
652
688
  name: string;
653
689
  category: string;
654
690
  fullname: string;
@@ -664,6 +700,19 @@ interface PageData {
664
700
  parentFullname?: string;
665
701
  parentTitle?: string;
666
702
  content?: string;
703
+ /**
704
+ * Text extracted from this page's resolved AST for preview and
705
+ * `%%excerpt{pattern="..." group="1" match="2" max="200"}%%`.
706
+ * Values stay literal; raw content is never a fallback.
707
+ * The host owns extraction policy, dependency invalidation and recursion limits.
708
+ */
709
+ readableText?: string;
710
+ /**
711
+ * First nonempty paragraph from extractFirstParagraph, for summary and first_paragraph.
712
+ * Uses the same extraction policy as readableText. Empty when no readable paragraph
713
+ * exists; undefined when unavailable. Headings and appended footnotes are excluded.
714
+ */
715
+ firstParagraph?: string;
667
716
  tags: string[];
668
717
  hiddenTags: string[];
669
718
  formData?: Record<string, string>;
@@ -672,7 +721,8 @@ interface PageData {
672
721
  formHint?: Record<string, string>;
673
722
  children: number;
674
723
  comments: number;
675
- size: number;
724
+ /** Materialized readable character count, computed with countCharacters. */
725
+ size?: number;
676
726
  rating: number;
677
727
  ratingVotes: number;
678
728
  ratingPercent?: number;
@@ -738,18 +788,25 @@ interface NormalizedCategory {
738
788
  /**
739
789
  * Order field options.
740
790
  */
741
- type OrderField = "created_at" | "updated_at" | "title" | "fullname" | "rating" | "votes" | "revisions" | "comments" | "size" | "random";
791
+ type OrderField = "created_at" | "updated_at" | "commented_at" | "metadata" | "title" | "fullname" | "rating" | "votes" | "revisions" | "comments" | "size" | "random";
742
792
  /**
743
793
  * Order direction.
744
794
  */
745
795
  type OrderDirection = "asc" | "desc";
746
796
  /**
747
797
  * Normalized order specification.
798
+ * Providers validate metadata registration, readability and sortability without falling back
799
+ * to another field. Sort before pagination with a stable page ID tie-breaker. For commented_at,
800
+ * put pages without comments last and use the same visible, non-deleted comments as the count.
748
801
  */
749
- interface NormalizedOrder {
750
- field: OrderField;
802
+ type NormalizedOrder = {
803
+ field: Exclude<OrderField, "metadata">;
751
804
  direction: OrderDirection;
752
- }
805
+ } | {
806
+ field: "metadata";
807
+ key: string;
808
+ direction: OrderDirection;
809
+ };
753
810
  /**
754
811
  * Normalized parent selector.
755
812
  */
@@ -815,6 +872,12 @@ interface NormalizedListPagesQuery {
815
872
  updatedAt?: NormalizedDateSelector;
816
873
  createdBy?: string;
817
874
  rating?: NormalizedNumericSelector;
875
+ /**
876
+ * `rating-axis` selects the custom aggregate for rating/votes filters and order; omission
877
+ * selects main. Verify registration and read access before filtering, counting or sorting.
878
+ * Unknown keys must not fall back to main. Display variables select their own keys.
879
+ */
880
+ ratingAxis?: string;
818
881
  votes?: NormalizedNumericSelector;
819
882
  name?: string;
820
883
  fullname?: string;
@@ -853,6 +916,14 @@ interface ProcessWikitextCallbackContext<TPage extends WikitextPageContext> {
853
916
  settings: WikitextSettings3;
854
917
  }
855
918
  interface ProcessWikitextDataProvider<TPage extends WikitextPageContext> {
919
+ /**
920
+ * Read only authorized, registered ratings in context.page, including declarations
921
+ * from its includes. Keys match exactly. Omit no-rate and inaccessible references.
922
+ * Main category policy and custom policies are independent. Votes belong to page + ref.
923
+ * ListPages/ListUsers output cannot declare ratings, including its nested includes.
924
+ * The host owns registration, aggregation and invalidation when included declarations change.
925
+ */
926
+ fetchRatings?: (refs: readonly RatingRef[], context: ProcessWikitextCallbackContext<TPage>) => Promise<readonly RatingState[]>;
856
927
  fetchInclude?: (pageRef: PageRef5, context: ProcessWikitextCallbackContext<TPage>) => Promise<string | null>;
857
928
  fetchListPages?: (query: NormalizedListPagesQuery, requirement: ListPagesDataRequirement, context: ProcessWikitextCallbackContext<TPage>) => Promise<ListPagesExternalData | null | undefined>;
858
929
  fetchListUsers?: (requirement: ListUsersDataRequirement, context: ProcessWikitextCallbackContext<TPage>) => Promise<ListUsersExternalData | null | undefined>;
@@ -863,9 +934,14 @@ interface ProcessWikitextOptions<TPage extends WikitextPageContext> {
863
934
  settings?: WikitextSettings3;
864
935
  dataProvider?: ProcessWikitextDataProvider<TPage>;
865
936
  includeMaxIterations?: number;
937
+ readableText?: ReadableTextOptions;
866
938
  }
867
939
  interface ProcessedWikitextDocument<TPage extends WikitextPageContext = WikitextPageContext> {
868
940
  ast: SyntaxTree;
941
+ readableText: string;
942
+ /** First nonempty body paragraph, excluding headings and appended footnotes. */
943
+ firstParagraph: string;
944
+ characterCount: number;
869
945
  page: TPage;
870
946
  settings: WikitextSettings3;
871
947
  diagnostics: Diagnostic[];
@@ -885,6 +961,13 @@ import { ParseResult as ParseResult3, SyntaxTree as SyntaxTree2 } from "@wdprlib
885
961
  */
886
962
  type ModuleParseResult = SyntaxTree2 | ParseResult3;
887
963
  type ParseFunction = (input: string) => ModuleParseResult;
964
+ import { RatingRef as RatingRef2, RatingState as RatingState2 } from "@wdprlib/ast";
965
+ /**
966
+ * Read authorized ratings for the displayed page. Omit unknown, disabled, or
967
+ * inaccessible references. The host owns registration, category policies,
968
+ * access checks, aggregates, and persistence; rendering must never create data.
969
+ */
970
+ type RatingsFetcher = (refs: readonly RatingRef2[]) => Promise<readonly RatingState2[]>;
888
971
  /**
889
972
  * Callback to retrieve the current page's tags during the resolve phase.
890
973
  *
@@ -905,6 +988,8 @@ type IfTagsResolver = () => string[];
905
988
  * @group Module Resolution
906
989
  */
907
990
  interface DataProvider {
991
+ /** Read registered ratings for the displayed page; omitted references stay hidden. */
992
+ fetchRatings?: RatingsFetcher;
908
993
  /**
909
994
  * Fetch page data for `[[module ListPages]]` expansion.
910
995
  *
@@ -1217,4 +1302,4 @@ interface ResolveOptions {
1217
1302
  */
1218
1303
  declare function resolveModules(ast: SyntaxTree4, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree4>;
1219
1304
  import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
1220
- export { tokenize, text, resolveTagCloud, resolveModules, resolveListUsers, resolveIncludesWithTrace, resolveIncludesAsyncWithTrace, resolveIncludesAsync, resolveIncludes, processWikitext, preprocessIftags, parseTags, parseParent, parseOrder, parseNumericSelector, parseDateSelector, parseCategory, parse, paragraph, normalizeQuery, matchesListPagesSelectors, listItemSubList, listItemElements, list, link, lineBreak, italics, isTagCloudModule, isListUsersModule, horizontalRule, heading, extractListUsersVariables, extractIncludeReferences, extractDataRequirements, definePageData, createToken, createSettings, createPosition, createPoint, container, compileTemplate, compileListUsersTemplate, buildInfo, bold, WikitextSettings5 as WikitextSettings, WikitextMode, Version2 as Version, VariableMap, VariableContext, UserInfo, TokenType, Token, TocEntry2 as TocEntry, TagCloudTagData, TagCloudModuleData, TagCloudExternalData, TagCloudDataRequirement, TagCloudDataFetcher, TableRow, TableData, TableCell, TabData, SyntaxTree5 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesTraceResult, ResolveIncludesOptions, ProcessedWikitextDocument, ProcessWikitextOptions, ProcessWikitextDataProvider, ProcessWikitextCallbackContext, Position2 as Position, Point, ParserOptions, Parser, ParseResult4 as ParseResult, ParseFunction, PageRef7 as PageRef, PageData, NormalizedTags, NormalizedParent, NormalizedOrder, NormalizedNumericSelector, NormalizedListPagesQuery, NormalizedDateSelector, NormalizedCategory, ModuleSourceTransform, ModuleParseResult, Module5 as Module, ListUsersVariableContext, ListUsersVariable, ListUsersUserData, ListUsersExternalData, ListUsersDataRequirement, ListUsersDataFetcher, ListUsersCompiledTemplate, ListType, ListPagesVariable, ListPagesQuery, ListPagesExternalData, ListPagesDataRequirement, ListPagesDataFetcher, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LexerOptions, Lexer, IncludeReference, IncludeIterationTrace, IncludeFetcher, IncludeDependency, ImageSource, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FloatAlignment, ExtractionResult, Embed, Element8 as Element, DiagnosticSeverity, Diagnostic4 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };
1305
+ export { tokenize, text, resolveTagCloud, resolveModules, resolveListUsers, resolveIncludesWithTrace, resolveIncludesAsyncWithTrace, resolveIncludesAsync, resolveIncludes, processWikitext, preprocessIftags, parseTags, parseParent, parseOrder, parseNumericSelector, parseDateSelector, parseCategory, parse, paragraph, normalizeQuery, matchesListPagesSelectors, listItemSubList, listItemElements, list, link, lineBreak, italics, isTagCloudModule, isListUsersModule, horizontalRule, heading, extractListUsersVariables, extractIncludeReferences, extractDataRequirements, definePageData, createToken, createSettings, createPosition, createPoint, container, compileTemplate, compileListUsersTemplate, buildInfo, bold, WikitextSettings5 as WikitextSettings, WikitextMode, Version2 as Version, VariableMap, VariableContext, UserInfo, TokenType, Token, TocEntry2 as TocEntry, TagCloudTagData, TagCloudModuleData, TagCloudExternalData, TagCloudDataRequirement, TagCloudDataFetcher, TableRow, TableData, TableCell, TabData, SyntaxTree5 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesTraceResult, ResolveIncludesOptions, RatingsFetcher, RatingVote, RatingState3 as RatingState, RatingRef3 as RatingRef, RatingAggregate2 as RatingAggregate, ProcessedWikitextDocument, ProcessWikitextOptions, ProcessWikitextDataProvider, ProcessWikitextCallbackContext, Position2 as Position, Point, ParserOptions, Parser, ParseResult4 as ParseResult, ParseFunction, PageRef7 as PageRef, PageMetadataValue, PageData, NormalizedTags, NormalizedParent, NormalizedOrder, NormalizedNumericSelector, NormalizedListPagesQuery, NormalizedDateSelector, NormalizedCategory, ModuleSourceTransform, ModuleParseResult, Module5 as Module, ListUsersVariableContext, ListUsersVariable, ListUsersUserData, ListUsersExternalData, ListUsersDataRequirement, ListUsersDataFetcher, ListUsersCompiledTemplate, ListType, ListPagesVariable, ListPagesQuery, ListPagesExternalData, ListPagesDataRequirement, ListPagesDataFetcher, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LexerOptions, Lexer, IncludeReference, IncludeIterationTrace, IncludeFetcher, IncludeDependency, ImageSource, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FloatAlignment, ExtractionResult, Embed, Element8 as Element, DiagnosticSeverity, Diagnostic4 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ declare const buildInfo: Readonly<{
4
4
  sha: string | null;
5
5
  dirty: boolean | null;
6
6
  }>;
7
+ import { RatingRef as RatingRef3, RatingVote, RatingAggregate as RatingAggregate2, RatingState as RatingState3 } from "@wdprlib/ast";
7
8
  import { Position as Position2, Point, Version as Version2, Element as Element8, SyntaxTree as SyntaxTree5, ContainerType, ContainerData, AttributeMap, VariableMap, Alignment, LinkType, LinkLocation, LinkLabel, PageRef as PageRef7, ImageSource, FloatAlignment, ListType, ListItem, ListData, CodeBlockData as CodeBlockData2, TabData, TableCell, TableRow, TableData, DefinitionListItem, Module as Module5, CollapsibleData, ClearFloat, AnchorTarget, HeaderType, AlignType, HeadingLevel, Heading, DateItem, Embed, TocEntry as TocEntry2, GallerySize, GalleryOrder, GalleryItem, GalleryContent, GalleryData, Diagnostic as Diagnostic4, DiagnosticSeverity, ParseResult as ParseResult4 } from "@wdprlib/ast";
8
9
  import { createPoint, createPosition, text, container, paragraph, bold, italics, heading, lineBreak, horizontalRule, link, list, listItemElements, listItemSubList } from "@wdprlib/ast";
9
10
  import { WikitextMode, WikitextSettings as WikitextSettings5 } from "@wdprlib/ast";
@@ -236,7 +237,7 @@ declare class Parser {
236
237
  */
237
238
  declare function parse(source: string, options?: ParserOptions): ParseResult2;
238
239
  import { WikitextPageContext as WikitextPageContext2 } from "@wdprlib/ast";
239
- import { Diagnostic, PageRef as PageRef5, SyntaxTree, WikitextPageContext, WikitextSettings as WikitextSettings3 } from "@wdprlib/ast";
240
+ import { Diagnostic, PageRef as PageRef5, SyntaxTree, WikitextPageContext, WikitextSettings as WikitextSettings3, RatingRef, RatingState, ReadableTextOptions } from "@wdprlib/ast";
240
241
  import { PageRef as PageRef4, WikitextSettings as WikitextSettings2 } from "@wdprlib/ast";
241
242
  interface IncludeAssignment {
242
243
  key: string;
@@ -412,6 +413,8 @@ interface ListPagesQuery {
412
413
  createdBy?: string;
413
414
  /** Rating selector. @untrusted User input. */
414
415
  rating?: string;
416
+ /** Exact registered custom key for rating/votes filters and order; omitted means main. */
417
+ ratingAxis?: string;
415
418
  /** Votes selector. @untrusted User input. */
416
419
  votes?: string;
417
420
  /** Page name selector. @untrusted User input. */
@@ -436,7 +439,7 @@ interface ListPagesQuery {
436
439
  /**
437
440
  * All supported ListPages template variables.
438
441
  */
439
- type ListPagesVariable = "created_at" | "created_by" | "created_by_unix" | "created_by_id" | "created_by_linked" | "updated_at" | "updated_by" | "updated_by_unix" | "updated_by_id" | "updated_by_linked" | "commented_at" | "commented_by" | "commented_by_unix" | "commented_by_id" | "commented_by_linked" | "name" | "category" | "fullname" | "title" | "title_linked" | "link" | "parent_name" | "parent_category" | "parent_fullname" | "parent_title" | "parent_title_linked" | "content" | "content_n" | "preview" | "preview_n" | "summary" | "first_paragraph" | "tags" | "tags_linked" | "_tags" | "_tags_linked" | "form_data" | "form_raw" | "form_label" | "form_hint" | "children" | "comments" | "size" | "rating" | "rating_votes" | "rating_percent" | "revisions" | "index" | "total" | "limit" | "total_or_limit" | "site_title" | "site_name" | "site_domain";
442
+ type ListPagesVariable = "metadata" | "customrate" | "customrate_votes" | "customrate_percent" | "created_at" | "created_by" | "created_by_unix" | "created_by_id" | "created_by_linked" | "updated_at" | "updated_by" | "updated_by_unix" | "updated_by_id" | "updated_by_linked" | "commented_at" | "commented_by" | "commented_by_unix" | "commented_by_id" | "commented_by_linked" | "name" | "category" | "fullname" | "title" | "title_linked" | "link" | "parent_name" | "parent_category" | "parent_fullname" | "parent_title" | "parent_title_linked" | "content" | "content_n" | "preview" | "preview_n" | "excerpt" | "summary" | "first_paragraph" | "tags" | "tags_linked" | "_tags" | "_tags_linked" | "form_data" | "form_raw" | "form_label" | "form_hint" | "children" | "comments" | "size" | "rating" | "rating_votes" | "rating_percent" | "revisions" | "index" | "total" | "limit" | "total_or_limit" | "site_title" | "site_name" | "site_domain";
440
443
  /**
441
444
  *
442
445
  * Type definitions for the ListUsers module.
@@ -614,6 +617,12 @@ interface ListPagesDataRequirement {
614
617
  previewLengths?: number[];
615
618
  /** Field names needed for form_data{field} etc. */
616
619
  formFields?: string[];
620
+ /** Exact metadata keys used by display templates. Also validate query.order on the host. */
621
+ metadataKeys?: string[];
622
+ /** Exact custom rating keys needed for display, independent of query.ratingAxis. */
623
+ customRateKeys?: string[];
624
+ /** Supply PageData.readableText and firstParagraph for previews, excerpts, and summaries. */
625
+ needsReadableText?: boolean;
617
626
  /** Prefix for tags_linked|prefix */
618
627
  tagsLinkPrefix?: string;
619
628
  /** Prefix for _tags_linked|prefix */
@@ -637,6 +646,21 @@ interface DataRequirements {
637
646
  listUsers: ListUsersDataRequirement[];
638
647
  tagCloud: TagCloudDataRequirement[];
639
648
  }
649
+ import { RatingAggregate } from "@wdprlib/ast";
650
+ /** Values for host-registered metadata keys. Missing entries remain unavailable. */
651
+ type PageMetadataValue = {
652
+ type: "text";
653
+ value: string;
654
+ } | {
655
+ type: "number";
656
+ value: number;
657
+ } | {
658
+ type: "date";
659
+ value: Date;
660
+ } | {
661
+ type: "user";
662
+ value: UserInfo;
663
+ };
640
664
  /**
641
665
  * User information.
642
666
  */
@@ -649,6 +673,18 @@ interface UserInfo {
649
673
  * Page data provided by an external source.
650
674
  */
651
675
  interface PageData {
676
+ /**
677
+ * `%%metadata{key}%%`: only registered, readable entries; keys are case-sensitive.
678
+ * Values are literal text. Date values accept strftime; user format is name, |id or |unix.
679
+ * Tag change date/editor may be host-defined keys; WDPR reserves no such keys.
680
+ */
681
+ metadata?: Readonly<Record<string, PageMetadataValue | null>>;
682
+ /**
683
+ * `%%customrate{key}%%`, `%%customrate_votes{key}%%`, `%%customrate_percent{key}%%`.
684
+ * Supply readable aggregates for requirement.customRateKeys, just as formFields selects
685
+ * form data. Missing keys expand to empty text; a supplied zero remains zero.
686
+ */
687
+ customRates?: Readonly<Record<string, RatingAggregate | null>>;
652
688
  name: string;
653
689
  category: string;
654
690
  fullname: string;
@@ -664,6 +700,19 @@ interface PageData {
664
700
  parentFullname?: string;
665
701
  parentTitle?: string;
666
702
  content?: string;
703
+ /**
704
+ * Text extracted from this page's resolved AST for preview and
705
+ * `%%excerpt{pattern="..." group="1" match="2" max="200"}%%`.
706
+ * Values stay literal; raw content is never a fallback.
707
+ * The host owns extraction policy, dependency invalidation and recursion limits.
708
+ */
709
+ readableText?: string;
710
+ /**
711
+ * First nonempty paragraph from extractFirstParagraph, for summary and first_paragraph.
712
+ * Uses the same extraction policy as readableText. Empty when no readable paragraph
713
+ * exists; undefined when unavailable. Headings and appended footnotes are excluded.
714
+ */
715
+ firstParagraph?: string;
667
716
  tags: string[];
668
717
  hiddenTags: string[];
669
718
  formData?: Record<string, string>;
@@ -672,7 +721,8 @@ interface PageData {
672
721
  formHint?: Record<string, string>;
673
722
  children: number;
674
723
  comments: number;
675
- size: number;
724
+ /** Materialized readable character count, computed with countCharacters. */
725
+ size?: number;
676
726
  rating: number;
677
727
  ratingVotes: number;
678
728
  ratingPercent?: number;
@@ -738,18 +788,25 @@ interface NormalizedCategory {
738
788
  /**
739
789
  * Order field options.
740
790
  */
741
- type OrderField = "created_at" | "updated_at" | "title" | "fullname" | "rating" | "votes" | "revisions" | "comments" | "size" | "random";
791
+ type OrderField = "created_at" | "updated_at" | "commented_at" | "metadata" | "title" | "fullname" | "rating" | "votes" | "revisions" | "comments" | "size" | "random";
742
792
  /**
743
793
  * Order direction.
744
794
  */
745
795
  type OrderDirection = "asc" | "desc";
746
796
  /**
747
797
  * Normalized order specification.
798
+ * Providers validate metadata registration, readability and sortability without falling back
799
+ * to another field. Sort before pagination with a stable page ID tie-breaker. For commented_at,
800
+ * put pages without comments last and use the same visible, non-deleted comments as the count.
748
801
  */
749
- interface NormalizedOrder {
750
- field: OrderField;
802
+ type NormalizedOrder = {
803
+ field: Exclude<OrderField, "metadata">;
751
804
  direction: OrderDirection;
752
- }
805
+ } | {
806
+ field: "metadata";
807
+ key: string;
808
+ direction: OrderDirection;
809
+ };
753
810
  /**
754
811
  * Normalized parent selector.
755
812
  */
@@ -815,6 +872,12 @@ interface NormalizedListPagesQuery {
815
872
  updatedAt?: NormalizedDateSelector;
816
873
  createdBy?: string;
817
874
  rating?: NormalizedNumericSelector;
875
+ /**
876
+ * `rating-axis` selects the custom aggregate for rating/votes filters and order; omission
877
+ * selects main. Verify registration and read access before filtering, counting or sorting.
878
+ * Unknown keys must not fall back to main. Display variables select their own keys.
879
+ */
880
+ ratingAxis?: string;
818
881
  votes?: NormalizedNumericSelector;
819
882
  name?: string;
820
883
  fullname?: string;
@@ -853,6 +916,14 @@ interface ProcessWikitextCallbackContext<TPage extends WikitextPageContext> {
853
916
  settings: WikitextSettings3;
854
917
  }
855
918
  interface ProcessWikitextDataProvider<TPage extends WikitextPageContext> {
919
+ /**
920
+ * Read only authorized, registered ratings in context.page, including declarations
921
+ * from its includes. Keys match exactly. Omit no-rate and inaccessible references.
922
+ * Main category policy and custom policies are independent. Votes belong to page + ref.
923
+ * ListPages/ListUsers output cannot declare ratings, including its nested includes.
924
+ * The host owns registration, aggregation and invalidation when included declarations change.
925
+ */
926
+ fetchRatings?: (refs: readonly RatingRef[], context: ProcessWikitextCallbackContext<TPage>) => Promise<readonly RatingState[]>;
856
927
  fetchInclude?: (pageRef: PageRef5, context: ProcessWikitextCallbackContext<TPage>) => Promise<string | null>;
857
928
  fetchListPages?: (query: NormalizedListPagesQuery, requirement: ListPagesDataRequirement, context: ProcessWikitextCallbackContext<TPage>) => Promise<ListPagesExternalData | null | undefined>;
858
929
  fetchListUsers?: (requirement: ListUsersDataRequirement, context: ProcessWikitextCallbackContext<TPage>) => Promise<ListUsersExternalData | null | undefined>;
@@ -863,9 +934,14 @@ interface ProcessWikitextOptions<TPage extends WikitextPageContext> {
863
934
  settings?: WikitextSettings3;
864
935
  dataProvider?: ProcessWikitextDataProvider<TPage>;
865
936
  includeMaxIterations?: number;
937
+ readableText?: ReadableTextOptions;
866
938
  }
867
939
  interface ProcessedWikitextDocument<TPage extends WikitextPageContext = WikitextPageContext> {
868
940
  ast: SyntaxTree;
941
+ readableText: string;
942
+ /** First nonempty body paragraph, excluding headings and appended footnotes. */
943
+ firstParagraph: string;
944
+ characterCount: number;
869
945
  page: TPage;
870
946
  settings: WikitextSettings3;
871
947
  diagnostics: Diagnostic[];
@@ -885,6 +961,13 @@ import { ParseResult as ParseResult3, SyntaxTree as SyntaxTree2 } from "@wdprlib
885
961
  */
886
962
  type ModuleParseResult = SyntaxTree2 | ParseResult3;
887
963
  type ParseFunction = (input: string) => ModuleParseResult;
964
+ import { RatingRef as RatingRef2, RatingState as RatingState2 } from "@wdprlib/ast";
965
+ /**
966
+ * Read authorized ratings for the displayed page. Omit unknown, disabled, or
967
+ * inaccessible references. The host owns registration, category policies,
968
+ * access checks, aggregates, and persistence; rendering must never create data.
969
+ */
970
+ type RatingsFetcher = (refs: readonly RatingRef2[]) => Promise<readonly RatingState2[]>;
888
971
  /**
889
972
  * Callback to retrieve the current page's tags during the resolve phase.
890
973
  *
@@ -905,6 +988,8 @@ type IfTagsResolver = () => string[];
905
988
  * @group Module Resolution
906
989
  */
907
990
  interface DataProvider {
991
+ /** Read registered ratings for the displayed page; omitted references stay hidden. */
992
+ fetchRatings?: RatingsFetcher;
908
993
  /**
909
994
  * Fetch page data for `[[module ListPages]]` expansion.
910
995
  *
@@ -1217,4 +1302,4 @@ interface ResolveOptions {
1217
1302
  */
1218
1303
  declare function resolveModules(ast: SyntaxTree4, dataProvider: DataProvider, options: ResolveOptions): Promise<SyntaxTree4>;
1219
1304
  import { STYLE_SLOT_PREFIX } from "@wdprlib/ast";
1220
- export { tokenize, text, resolveTagCloud, resolveModules, resolveListUsers, resolveIncludesWithTrace, resolveIncludesAsyncWithTrace, resolveIncludesAsync, resolveIncludes, processWikitext, preprocessIftags, parseTags, parseParent, parseOrder, parseNumericSelector, parseDateSelector, parseCategory, parse, paragraph, normalizeQuery, matchesListPagesSelectors, listItemSubList, listItemElements, list, link, lineBreak, italics, isTagCloudModule, isListUsersModule, horizontalRule, heading, extractListUsersVariables, extractIncludeReferences, extractDataRequirements, definePageData, createToken, createSettings, createPosition, createPoint, container, compileTemplate, compileListUsersTemplate, buildInfo, bold, WikitextSettings5 as WikitextSettings, WikitextMode, Version2 as Version, VariableMap, VariableContext, UserInfo, TokenType, Token, TocEntry2 as TocEntry, TagCloudTagData, TagCloudModuleData, TagCloudExternalData, TagCloudDataRequirement, TagCloudDataFetcher, TableRow, TableData, TableCell, TabData, SyntaxTree5 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesTraceResult, ResolveIncludesOptions, ProcessedWikitextDocument, ProcessWikitextOptions, ProcessWikitextDataProvider, ProcessWikitextCallbackContext, Position2 as Position, Point, ParserOptions, Parser, ParseResult4 as ParseResult, ParseFunction, PageRef7 as PageRef, PageData, NormalizedTags, NormalizedParent, NormalizedOrder, NormalizedNumericSelector, NormalizedListPagesQuery, NormalizedDateSelector, NormalizedCategory, ModuleSourceTransform, ModuleParseResult, Module5 as Module, ListUsersVariableContext, ListUsersVariable, ListUsersUserData, ListUsersExternalData, ListUsersDataRequirement, ListUsersDataFetcher, ListUsersCompiledTemplate, ListType, ListPagesVariable, ListPagesQuery, ListPagesExternalData, ListPagesDataRequirement, ListPagesDataFetcher, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LexerOptions, Lexer, IncludeReference, IncludeIterationTrace, IncludeFetcher, IncludeDependency, ImageSource, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FloatAlignment, ExtractionResult, Embed, Element8 as Element, DiagnosticSeverity, Diagnostic4 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };
1305
+ export { tokenize, text, resolveTagCloud, resolveModules, resolveListUsers, resolveIncludesWithTrace, resolveIncludesAsyncWithTrace, resolveIncludesAsync, resolveIncludes, processWikitext, preprocessIftags, parseTags, parseParent, parseOrder, parseNumericSelector, parseDateSelector, parseCategory, parse, paragraph, normalizeQuery, matchesListPagesSelectors, listItemSubList, listItemElements, list, link, lineBreak, italics, isTagCloudModule, isListUsersModule, horizontalRule, heading, extractListUsersVariables, extractIncludeReferences, extractDataRequirements, definePageData, createToken, createSettings, createPosition, createPoint, container, compileTemplate, compileListUsersTemplate, buildInfo, bold, WikitextSettings5 as WikitextSettings, WikitextMode, Version2 as Version, VariableMap, VariableContext, UserInfo, TokenType, Token, TocEntry2 as TocEntry, TagCloudTagData, TagCloudModuleData, TagCloudExternalData, TagCloudDataRequirement, TagCloudDataFetcher, TableRow, TableData, TableCell, TabData, SyntaxTree5 as SyntaxTree, SiteContext, STYLE_SLOT_PREFIX, ResolveOptions, ResolveIncludesTraceResult, ResolveIncludesOptions, RatingsFetcher, RatingVote, RatingState3 as RatingState, RatingRef3 as RatingRef, RatingAggregate2 as RatingAggregate, ProcessedWikitextDocument, ProcessWikitextOptions, ProcessWikitextDataProvider, ProcessWikitextCallbackContext, Position2 as Position, Point, ParserOptions, Parser, ParseResult4 as ParseResult, ParseFunction, PageRef7 as PageRef, PageMetadataValue, PageData, NormalizedTags, NormalizedParent, NormalizedOrder, NormalizedNumericSelector, NormalizedListPagesQuery, NormalizedDateSelector, NormalizedCategory, ModuleSourceTransform, ModuleParseResult, Module5 as Module, ListUsersVariableContext, ListUsersVariable, ListUsersUserData, ListUsersExternalData, ListUsersDataRequirement, ListUsersDataFetcher, ListUsersCompiledTemplate, ListType, ListPagesVariable, ListPagesQuery, ListPagesExternalData, ListPagesDataRequirement, ListPagesDataFetcher, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LexerOptions, Lexer, IncludeReference, IncludeIterationTrace, IncludeFetcher, IncludeDependency, ImageSource, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FloatAlignment, ExtractionResult, Embed, Element8 as Element, DiagnosticSeverity, Diagnostic4 as Diagnostic, DefinitionListItem, DateItem, DataRequirements, DataProvider, DEFAULT_SETTINGS, ContainerType, ContainerData, CompiledTemplate, CollapsibleData, CodeBlockData2 as CodeBlockData, ClearFloat, AttributeMap, AsyncIncludeFetcher, AnchorTarget, Alignment, AlignType };