nextpress-core 1.0.0 → 1.0.2

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 (184) hide show
  1. package/dist/acf-functions/core/acf-builder.d.ts +50 -0
  2. package/{lib/acf-functions/core/acf-builder.ts → dist/acf-functions/core/acf-builder.js} +17 -41
  3. package/dist/acf-functions/core/acf-component-autoloader.d.ts +11 -0
  4. package/{lib/acf-functions/core/acf-component-autoloader.ts → dist/acf-functions/core/acf-component-autoloader.js} +7 -13
  5. package/dist/acf-functions/core/acf-field-group-autoloader.d.ts +9 -0
  6. package/{lib/acf-functions/core/acf-field-group-autoloader.ts → dist/acf-functions/core/acf-field-group-autoloader.js} +4 -9
  7. package/dist/acf-functions/field-props.d.ts +196 -0
  8. package/dist/acf-functions/field-props.js +1 -0
  9. package/dist/acf-functions/services/define-field-group.d.ts +8 -0
  10. package/{lib/acf-functions/services/define-field-group.ts → dist/acf-functions/services/define-field-group.js} +1 -1
  11. package/dist/acf-functions/services/define-layout.d.ts +8 -0
  12. package/{lib/acf-functions/services/define-layout.ts → dist/acf-functions/services/define-layout.js} +1 -1
  13. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +2 -0
  14. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +18 -0
  15. package/dist/acf-functions/services/map-fields/map-fields.d.ts +18 -0
  16. package/{lib/acf-functions/services/map-fields/map-fields.ts → dist/acf-functions/services/map-fields/map-fields.js} +88 -124
  17. package/dist/entities/option/option.d.ts +19 -0
  18. package/{lib/entities/option/option.ts → dist/entities/option/option.js} +13 -20
  19. package/dist/entities/post/post.d.ts +50 -0
  20. package/dist/entities/post/post.js +184 -0
  21. package/dist/entities/term/term.d.ts +28 -0
  22. package/dist/entities/term/term.js +67 -0
  23. package/dist/entities/user/user.d.ts +27 -0
  24. package/dist/entities/user/user.js +74 -0
  25. package/dist/globals/entity-loader/entity-loader-base.d.ts +65 -0
  26. package/{lib/globals/entity-loader/entity-loader-base.ts → dist/globals/entity-loader/entity-loader-base.js} +10 -64
  27. package/dist/globals/entity-loader/option-loader.d.ts +15 -0
  28. package/dist/globals/entity-loader/option-loader.js +31 -0
  29. package/dist/globals/entity-loader/post-loader.d.ts +21 -0
  30. package/dist/globals/entity-loader/post-loader.js +28 -0
  31. package/dist/globals/entity-loader/term-loader.d.ts +21 -0
  32. package/dist/globals/entity-loader/term-loader.js +28 -0
  33. package/dist/globals/entity-loader/user-loader.d.ts +21 -0
  34. package/dist/globals/entity-loader/user-loader.js +28 -0
  35. package/dist/globals/get-field/get-field.d.ts +17 -0
  36. package/dist/globals/get-field/get-field.js +44 -0
  37. package/dist/globals/globals.d.ts +18 -0
  38. package/{lib/globals/globals.ts → dist/globals/globals.js} +3 -8
  39. package/dist/globals/nextpress-config/nextpress-config.d.ts +4 -0
  40. package/{lib/globals/nextpress-config/nextpress-config.ts → dist/globals/nextpress-config/nextpress-config.js} +0 -5
  41. package/dist/globals/queried-object/queried-object.d.ts +62 -0
  42. package/dist/globals/queried-object/queried-object.js +56 -0
  43. package/dist/repository/optionquery/option-query.d.ts +12 -0
  44. package/dist/repository/optionquery/option-query.js +20 -0
  45. package/dist/repository/postquery/post-query.d.ts +12 -0
  46. package/dist/repository/postquery/post-query.js +272 -0
  47. package/dist/repository/termquery/term-query.d.ts +11 -0
  48. package/dist/repository/termquery/term-query.js +213 -0
  49. package/dist/repository/userquery/user-query.d.ts +12 -0
  50. package/{lib/repository/userquery/user-query.ts → dist/repository/userquery/user-query.js} +75 -91
  51. package/dist/router/helpers.d.ts +14 -0
  52. package/{lib/router/helpers.ts → dist/router/helpers.js} +4 -4
  53. package/dist/router/nextpress-layout.d.ts +11 -0
  54. package/{lib/router/nextpress-layout.tsx → dist/router/nextpress-layout.js} +6 -23
  55. package/dist/router/nextpress-proxy.d.ts +8 -0
  56. package/{lib/router/nextpress-proxy.ts → dist/router/nextpress-proxy.js} +3 -15
  57. package/dist/router/nextpress-static-params.d.ts +9 -0
  58. package/{lib/router/nextpress-static-params.ts → dist/router/nextpress-static-params.js} +5 -17
  59. package/dist/router/router.d.ts +23 -0
  60. package/{lib/router/router.tsx → dist/router/router.js} +21 -29
  61. package/dist/router/routes/api/api-get-admin-bar.d.ts +8 -0
  62. package/{lib/router/routes/api/api-get-admin-bar.ts → dist/router/routes/api/api-get-admin-bar.js} +6 -8
  63. package/dist/router/routes/api/api-get-draft-mode.d.ts +8 -0
  64. package/{lib/router/routes/api/api-get-draft-mode.ts → dist/router/routes/api/api-get-draft-mode.js} +6 -15
  65. package/dist/router/routes/api/api-get-field-groups.d.ts +7 -0
  66. package/{lib/router/routes/api/api-get-field-groups.ts → dist/router/routes/api/api-get-field-groups.js} +6 -11
  67. package/dist/router/routes/api/api-post-revalidate.d.ts +7 -0
  68. package/{lib/router/routes/api/api-post-revalidate.ts → dist/router/routes/api/api-post-revalidate.js} +4 -6
  69. package/dist/router/routes/api/helpers.d.ts +8 -0
  70. package/{lib/router/routes/api/helpers.ts → dist/router/routes/api/helpers.js} +3 -4
  71. package/dist/router/routes/author-archive.d.ts +25 -0
  72. package/{lib/router/routes/author-archive.tsx → dist/router/routes/author-archive.js} +11 -37
  73. package/dist/router/routes/not-found-page.d.ts +15 -0
  74. package/{lib/router/routes/not-found-page.tsx → dist/router/routes/not-found-page.js} +3 -5
  75. package/dist/router/routes/post-index-page.d.ts +25 -0
  76. package/dist/router/routes/post-index-page.js +33 -0
  77. package/dist/router/routes/singular-page.d.ts +29 -0
  78. package/dist/router/routes/singular-page.js +51 -0
  79. package/dist/router/routes/site-front-page.d.ts +27 -0
  80. package/dist/router/routes/site-front-page.js +26 -0
  81. package/dist/router/routes/term-archive.d.ts +29 -0
  82. package/{lib/router/routes/term-archive.tsx → dist/router/routes/term-archive.js} +17 -45
  83. package/dist/services/get-menu.d.ts +13 -0
  84. package/{lib/services/get-menu.ts → dist/services/get-menu.js} +32 -56
  85. package/dist/services/get-theme-mods.d.ts +7 -0
  86. package/{lib/services/get-theme-mods.ts → dist/services/get-theme-mods.js} +4 -6
  87. package/dist/services/metadata/get-blogname.d.ts +6 -0
  88. package/{lib/services/metadata/get-blogname.ts → dist/services/metadata/get-blogname.js} +2 -2
  89. package/dist/services/metadata/get-favicon-url.d.ts +6 -0
  90. package/{lib/services/metadata/get-favicon-url.ts → dist/services/metadata/get-favicon-url.js} +4 -5
  91. package/dist/services/metadata/get-language-attribute.d.ts +6 -0
  92. package/{lib/services/metadata/get-language-attribute.ts → dist/services/metadata/get-language-attribute.js} +1 -1
  93. package/{lib/services/services.ts → dist/services/services.d.ts} +1 -5
  94. package/dist/services/services.js +3 -0
  95. package/dist/services/utilities/capitalise-first-letter.d.ts +7 -0
  96. package/{lib/services/utilities/capitalise-first-letter.ts → dist/services/utilities/capitalise-first-letter.js} +3 -2
  97. package/dist/services/utilities/esc-html.d.ts +7 -0
  98. package/{lib/services/utilities/esc-html.ts → dist/services/utilities/esc-html.js} +1 -3
  99. package/dist/services/utilities/get-date-time-formatter.d.ts +6 -0
  100. package/{lib/services/utilities/get-date-time-formatter.ts → dist/services/utilities/get-date-time-formatter.js} +6 -16
  101. package/dist/services/utilities/index.js +1 -0
  102. package/dist/services/utilities/kses-post.d.ts +7 -0
  103. package/{lib/services/utilities/kses-post.ts → dist/services/utilities/kses-post.js} +1 -2
  104. package/dist/services/utilities/process-url.d.ts +7 -0
  105. package/{lib/services/utilities/process-url.ts → dist/services/utilities/process-url.js} +3 -4
  106. package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +9 -0
  107. package/{lib/template-heirarchy/_autoloader/template-autoloader.ts → dist/template-heirarchy/_autoloader/template-autoloader.js} +9 -18
  108. package/dist/template-heirarchy/archive/archive.d.ts +16 -0
  109. package/{lib/template-heirarchy/archive/archive.tsx → dist/template-heirarchy/archive/archive.js} +7 -10
  110. package/dist/template-heirarchy/archive/author.d.ts +16 -0
  111. package/{lib/template-heirarchy/archive/author.tsx → dist/template-heirarchy/archive/author.js} +7 -10
  112. package/dist/template-heirarchy/archive/category.d.ts +16 -0
  113. package/{lib/template-heirarchy/archive/category.tsx → dist/template-heirarchy/archive/category.js} +7 -11
  114. package/dist/template-heirarchy/archive/posttypearchive.d.ts +24 -0
  115. package/{lib/template-heirarchy/archive/posttypearchive.tsx → dist/template-heirarchy/archive/posttypearchive.js} +7 -10
  116. package/dist/template-heirarchy/archive/tag.d.ts +16 -0
  117. package/{lib/template-heirarchy/archive/tag.tsx → dist/template-heirarchy/archive/tag.js} +7 -12
  118. package/dist/template-heirarchy/archive/taxonomy.d.ts +16 -0
  119. package/{lib/template-heirarchy/archive/taxonomy.tsx → dist/template-heirarchy/archive/taxonomy.js} +7 -10
  120. package/dist/template-heirarchy/home/home.d.ts +16 -0
  121. package/{lib/template-heirarchy/home/home.tsx → dist/template-heirarchy/home/home.js} +7 -10
  122. package/dist/template-heirarchy/index.d.ts +17 -0
  123. package/{lib/template-heirarchy/index.tsx → dist/template-heirarchy/index.js} +5 -9
  124. package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +16 -0
  125. package/{lib/template-heirarchy/not-found.tsx/not-found.tsx → dist/template-heirarchy/not-found.tsx/not-found.js} +7 -10
  126. package/dist/template-heirarchy/page/page.d.ts +16 -0
  127. package/{lib/template-heirarchy/page/page.tsx → dist/template-heirarchy/page/page.js} +7 -10
  128. package/dist/template-heirarchy/page/posttype.d.ts +24 -0
  129. package/{lib/template-heirarchy/page/posttype.tsx → dist/template-heirarchy/page/posttype.js} +7 -11
  130. package/dist/template-heirarchy/page/single.d.ts +16 -0
  131. package/{lib/template-heirarchy/page/single.tsx → dist/template-heirarchy/page/single.js} +7 -10
  132. package/dist/template-heirarchy/page/singular.d.ts +16 -0
  133. package/{lib/template-heirarchy/page/singular.tsx → dist/template-heirarchy/page/singular.js} +7 -10
  134. package/dist/ui/render-attachment-image.d.ts +12 -0
  135. package/dist/ui/render-attachment-image.js +24 -0
  136. package/{lib/ui/render-components.tsx → dist/ui/render-components.d.ts} +4 -7
  137. package/dist/ui/render-components.js +7 -0
  138. package/dist/ui/render-the-admin-bar.d.ts +8 -0
  139. package/dist/ui/render-the-admin-bar.js +36 -0
  140. package/dist/ui/render-the-logo.d.ts +10 -0
  141. package/dist/ui/render-the-logo.js +16 -0
  142. package/dist/wpdb/wpdb.d.ts +3 -0
  143. package/{lib/wpdb/wpdb.ts → dist/wpdb/wpdb.js} +5 -9
  144. package/package.json +7 -3
  145. package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +0 -20
  146. package/lib/acf-functions/types/acf-field-group.d.ts +0 -118
  147. package/lib/acf-functions/types/acf-field.d.ts +0 -2851
  148. package/lib/acf-functions/types/acf-layout.d.ts +0 -20
  149. package/lib/acf-functions/types/acf-values.d.ts +0 -4
  150. package/lib/acf-functions/types/components/field-props.d.ts +0 -189
  151. package/lib/acf-functions/types/components/nextpress-component.d.ts +0 -11
  152. package/lib/ambient.d.ts +0 -15
  153. package/lib/entities/common.d.ts +0 -30
  154. package/lib/entities/option/option.interface.d.ts +0 -8
  155. package/lib/entities/post/post.interface.d.ts +0 -72
  156. package/lib/entities/post/post.ts +0 -209
  157. package/lib/entities/term/term.interface.d.ts +0 -8
  158. package/lib/entities/term/term.ts +0 -82
  159. package/lib/entities/user/user.interface.d.ts +0 -10
  160. package/lib/entities/user/user.ts +0 -86
  161. package/lib/globals/entity-loader/entity-loader.d.ts +0 -50
  162. package/lib/globals/entity-loader/option-loader.ts +0 -56
  163. package/lib/globals/entity-loader/post-loader.ts +0 -59
  164. package/lib/globals/entity-loader/term-loader.ts +0 -59
  165. package/lib/globals/entity-loader/user-loader.ts +0 -60
  166. package/lib/globals/get-field/get-field.ts +0 -75
  167. package/lib/globals/nextpress-config/nextpress-config.interface.d.ts +0 -18
  168. package/lib/globals/queried-object/queried-object.ts +0 -124
  169. package/lib/repository/optionquery/option-query-args.d.ts +0 -21
  170. package/lib/repository/optionquery/option-query.ts +0 -29
  171. package/lib/repository/postquery/post-query-args.d.ts +0 -108
  172. package/lib/repository/postquery/post-query.ts +0 -281
  173. package/lib/repository/termquery/term-query-args.d.ts +0 -61
  174. package/lib/repository/termquery/term-query.ts +0 -243
  175. package/lib/repository/userquery/user-query-args.d.ts +0 -75
  176. package/lib/router/routes/post-index-page.tsx +0 -58
  177. package/lib/router/routes/singular-page.tsx +0 -78
  178. package/lib/router/routes/site-front-page.tsx +0 -51
  179. package/lib/router/types.d.ts +0 -9
  180. package/lib/ui/render-attachment-image.tsx +0 -29
  181. package/lib/ui/render-the-admin-bar.tsx +0 -79
  182. package/lib/ui/render-the-logo.tsx +0 -24
  183. package/lib/wpdb/wpdb.interface.d.ts +0 -171
  184. /package/{lib/services/utilities/index.ts → dist/services/utilities/index.d.ts} +0 -0
@@ -1,108 +0,0 @@
1
- type WPQueryOrderByParam =
2
- | 'none' | 'id' | 'author' | 'title' | 'name' | 'date' | 'modified'
3
- | 'parent' | 'menuOrder'| 'commentCount' | 'rand' | `RAND(${number})`
4
- | (string & {});
5
-
6
- /**
7
- * Defines the arguments for querying posts.
8
- * Maps standard WordPress WP_Query parameters.
9
- */
10
- interface PostQueryArgs {
11
- /** Post ID. */
12
- postId?: number;
13
- /** An array of post IDs to retrieve, sticky posts will be included. */
14
- postIn?: number[];
15
- /** An array of post IDs not to retrieve. */
16
- postNotIn?: number[];
17
- /** Path to post */
18
- path?: string;
19
- /** A post type slug (string) or array of post type slugs. */
20
- postType?: string | string[];
21
- /** A post type slug (string) or array of post type slugs to NOT include. */
22
- postTypeNot?: string | string[];
23
- /** A post status (string) or array of post statuses. */
24
- postStatus?: string | string[];
25
- /** A post slug (string) or array of post slugs. */
26
- postSlug?: string | string[];
27
- /** A post id to retrieve anscestry tree off */
28
- postAncestryOf?: string;
29
- /** Post title. */
30
- title?: string;
31
- /** The mime type of the post. Used for 'attachment' post_type. */
32
- postMimeType?: string;
33
- /** Page ID to retrieve child pages for. Use 0 to only retrieve top-level pages. */
34
- postParent?: number;
35
- /** An array containing parent page IDs to query child pages from. */
36
- postParentIn?: number[];
37
- /** An array containing parent page IDs not to query child pages from. */
38
- postParentNotIn?: number[];
39
- /** Term ID. */
40
- termId?: number;
41
- /** An array of term IDs (AND in). */
42
- termAnd?: number[];
43
- /** An array of term IDs (OR in). */
44
- termIn?: number[];
45
- /** An array of term IDs (NOT in). */
46
- termNotIn?: number[];
47
- /** Use term slug (not name, this or any children). */
48
- termSlug?: string;
49
- /** An array of term slugs (AND in). */
50
- termSlugAnd?: string[];
51
- /** An array of term slugs (OR in). */
52
- termSlugIn?: string[];
53
- /** Author ID. */
54
- authorId?: number;
55
- /** User 'user_nicename'. */
56
- authorName?: string;
57
- /** An array of author IDs to query from. */
58
- authorIn?: number[];
59
- /** An array of author IDs not to query from. */
60
- authorNotIn?: number[];
61
- /** search keyword(s). */
62
- search?: string;
63
- /** Whether to search by exact keyword. Default false. */
64
- exact?: boolean;
65
- /** array of column names to be searched. accepts 'postTitle', 'postExcerpt' and 'postContent'. */
66
- searchColumns?: ('postTitle' | 'postExcerpt' | 'postContent')[];
67
- /** Combination YearMonth. Accepts any four-digit year and month numbers 01-12. */
68
- yyyymm?: number;
69
- /** The four-digit year. Default empty. Accepts any four-digit year. */
70
- year?: number;
71
- /** The two-digit month. Default empty. Accepts numbers 1-12. */
72
- monthnum?: number;
73
- /** The week number of the year. Default empty. Accepts numbers 0-53. */
74
- w?: number;
75
- /** Day of the month. Default empty. Accepts numbers 1-31. */
76
- day?: number;
77
- /** Hour of the day. Default empty. Accepts numbers 0-23. */
78
- hour?: number;
79
- /** Minute of the hour. Default empty. Accepts numbers 0-59. */
80
- minute?: number;
81
- /** Second of the minute. Default empty. Accepts numbers 0-59. */
82
- second?: number;
83
- /** Whether to ignore sticky posts or not. Default false. */
84
- ignoreStickyPosts?: boolean;
85
- /** Designates ascending or descending order of posts. Default 'DESC'. */
86
- order?: 'ASC' | 'DESC';
87
- /** Sort retrieved posts by parameter. */
88
- orderBy?: WPQueryOrderByParam;
89
- /** Show posts that would show up on page X of a static front page. */
90
- page?: number;
91
- /** Show all posts (true) or paginate (false). Default false. */
92
- noPaging?: boolean;
93
- /** The number of posts to offset before retrieval. */
94
- offset?: number;
95
- /** The number of posts to query for. Use -1 to request all posts. */
96
- postsPerPage?: number;
97
- /** Whether to skip counting the total rows found. Default false. */
98
- noFoundRows?: boolean;
99
- /** Meta query */
100
- metaQuery?: {
101
- /** Meta key */
102
- metaKey: string,
103
- /** Variable name to save result to */
104
- as: string
105
- }[]
106
- /** Whether to get multiple, default true */
107
- multiple?: bool
108
- }
@@ -1,281 +0,0 @@
1
- import { QueryCreator, sql } from "kysely";
2
- import { DB } from "../../wpdb/wpdb.interface";
3
- import * as phpSerialize from "php-serialize";
4
- import { EntityQuery } from "../../globals/entity-loader/entity-loader";
5
- import { IPost } from "../../entities/post/post.interface";
6
- import { wpdb } from "@/wpdb/wpdb";
7
-
8
- /**
9
- * Executes database queries to retrieve post IDs and counts based on provided arguments.
10
- */
11
- export class PostQuery implements EntityQuery<IPost>
12
- {
13
- private postCount?: number;
14
-
15
- constructor(
16
- private args: PostQueryArgs
17
- ) {}
18
-
19
- public getCount(): number | undefined {
20
- return this.postCount;
21
- }
22
-
23
- public async getIds(): Promise<number[]> {
24
- let builder = wpdb as QueryCreator<any>;
25
-
26
- if (this.args.postAncestryOf) {
27
- builder = builder.withRecursive('decendent_tree', (qb) =>
28
- qb.selectFrom('wpPosts')
29
- .select(['wpPosts.ID', 'wpPosts.postName', 'wpPosts.postParent'])
30
- .where('wpPosts.postName', '=', this.args.postAncestryOf)
31
- .unionAll(
32
- qb.selectFrom('wpPosts as p')
33
- .select(['p.ID', 'p.postName', 'p.postParent'])
34
- .innerJoin('decendent_tree as d', 'p.postParent', 'd.ID')
35
- )
36
- )
37
- }
38
-
39
- let query = (builder as QueryCreator<DB>).selectFrom('wpPosts');
40
-
41
- if (this.args.postAncestryOf) {
42
- query = query.where('wpPosts.postName', 'in', (qb: any) =>
43
- qb.selectFrom('decendent_tree').select('postName')
44
- );
45
- }
46
-
47
- // --- ID Filters ---
48
- if (this.args.postId) query = query.where('wpPosts.ID', '=', this.args.postId);
49
- if (this.args.postIn) query = query.where('wpPosts.ID', 'in', this.args.postIn);
50
- if (this.args.postNotIn) query = query.where('wpPosts.ID', 'not in', this.args.postNotIn);
51
-
52
- if (this.args.path) {
53
- query = query.where((eb) => eb.exists(
54
- eb.selectFrom('wpPostmeta')
55
- .select('postId')
56
- .whereRef('postId', '=', 'wpPosts.ID')
57
- .where('wpPostmeta.metaKey', '=', '_nextpress_path')
58
- .where('wpPostmeta.metaValue', '=', this.args.path as string)
59
- ));
60
- }
61
- // --- Type Filters ---
62
- if (this.args.postType) {
63
- const types = Array.isArray(this.args.postType) ? this.args.postType : [this.args.postType];
64
- query = query.where('wpPosts.postType', 'in', types);
65
- }
66
- if (this.args.postTypeNot) {
67
- const types = Array.isArray(this.args.postTypeNot) ? this.args.postTypeNot : [this.args.postTypeNot];
68
- query = query.where('wpPosts.postType', 'not in', types);
69
- }
70
-
71
- // --- Status Filters ---
72
- if (this.args.postStatus) {
73
- const statuses = Array.isArray(this.args.postStatus) ? this.args.postStatus : [this.args.postStatus];
74
- query = query.where('wpPosts.postStatus', 'in', statuses);
75
- }
76
-
77
- // --- Content Filters ---
78
- if (this.args.postSlug) {
79
- const postSlugs = Array.isArray(this.args.postSlug) ? this.args.postSlug : [this.args.postSlug];
80
- query = query.where('wpPosts.postName', 'in', postSlugs);
81
- }
82
- if (this.args.title) query = query.where('wpPosts.postTitle', '=', this.args.title);
83
- if (this.args.postMimeType) query = query.where('wpPosts.postMimeType', 'like', `%${this.args.postMimeType}%`);
84
-
85
- // --- Parent Filters ---
86
- if (this.args.postParent !== undefined) query = query.where('wpPosts.postParent', '=', this.args.postParent);
87
- if (this.args.postParentIn) query = query.where('wpPosts.postParent', 'in', this.args.postParentIn);
88
- if (this.args.postParentNotIn) query = query.where('wpPosts.postParent', 'not in', this.args.postParentNotIn);
89
-
90
- // --- Term Filters ---
91
- if (this.args.termId) {
92
- query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
93
- .where('wpTermRelationships.termTaxonomyId', '=', this.args.termId);
94
- }
95
- if (this.args.termAnd) {
96
- query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
97
- .where('wpTermRelationships.termTaxonomyId', 'in', this.args.termAnd)
98
- .groupBy('wpPosts.ID')
99
- .having((eb) => eb.fn.count('wpTermRelationships.termTaxonomyId'), '=', this.args.termAnd!.length);
100
- }
101
- if (this.args.termIn) {
102
- query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
103
- .where('wpTermRelationships.termTaxonomyId', 'in', this.args.termIn);
104
- }
105
- if (this.args.termNotIn) {
106
- query = query.where('wpPosts.ID', 'not in',
107
- (qb) =>
108
- qb.selectFrom('wpTermRelationships')
109
- .select('wpTermRelationships.objectId')
110
- .where('wpTermRelationships.termTaxonomyId', 'in', this.args.termNotIn!)
111
- );
112
- }
113
- if (this.args.termSlug) {
114
- query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
115
- .innerJoin('wpTerms', 'wpTermRelationships.termTaxonomyId', 'wpTerms.termId')
116
- .where('wpTerms.slug', '=', this.args.termSlug)
117
- .groupBy('wpPosts.ID');
118
- }
119
- if (this.args.termSlugAnd) {
120
- query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
121
- .innerJoin('wpTerms', 'wpTermRelationships.termTaxonomyId', 'wpTerms.termId')
122
- .where('wpTerms.slug', 'in', this.args.termSlugAnd)
123
- .groupBy('wpPosts.ID')
124
- .having((eb) => eb.fn.count('wpTermRelationships.termTaxonomyId'), '=', this.args.termSlugAnd!.length);
125
- }
126
- if (this.args.termSlugIn) {
127
- query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
128
- .innerJoin('wpTerms', 'wpTermRelationships.termTaxonomyId', 'wpTerms.termId')
129
- .where('wpTerms.slug', 'in', this.args.termSlugIn)
130
- .groupBy('wpPosts.ID');
131
- }
132
-
133
- // --- Author Filters ---
134
- if (this.args.authorId) query = query.where('wpPosts.postAuthor', '=', this.args.authorId);
135
- if (this.args.authorIn) query = query.where('wpPosts.postAuthor', 'in', this.args.authorIn);
136
- if (this.args.authorNotIn) query = query.where('wpPosts.postAuthor', 'not in', this.args.authorNotIn);
137
- if (this.args.authorName) {
138
- query = query.innerJoin('wpUsers', 'wpPosts.postAuthor', 'wpUsers.ID')
139
- .where('wpUsers.displayName', '=', this.args.authorName);
140
- }
141
-
142
- // --- Search Filters ---
143
- if (this.args.search) {
144
- const searchTerm = this.args.exact ? this.args.search : `%${this.args.search}%`;
145
- const searchCols = this.args.searchColumns || ['postTitle', 'postContent', 'postExcerpt'];
146
- const isExact = this.args.exact;
147
-
148
- query = query.where((eb) => {
149
- const orClauses = searchCols.map(col => eb(col, isExact ? '=' : 'like', searchTerm));
150
- return eb.or(orClauses);
151
- });
152
- }
153
-
154
- // --- Date Filters ---
155
- if (this.args.yyyymm) {
156
- const mStr = String(this.args.yyyymm);
157
- const y = Number(mStr.substring(0, 4));
158
- const mon = Number(mStr.substring(4, 6));
159
- query = query.where((eb) => eb.fn('YEAR', [eb.ref('wpPosts.postDate')]), '=', y)
160
- .where((eb) => eb.fn('MONTH', [eb.ref('wpPosts.postDate')]), '=', mon);
161
- }
162
- if (this.args.year) query = query.where((eb) => eb.fn('YEAR', [eb.ref('wpPosts.postDate')]), '=', this.args.year);
163
- if (this.args.monthnum) query = query.where((eb) => eb.fn('MONTH', [eb.ref('wpPosts.postDate')]), '=', this.args.monthnum);
164
- if (this.args.w) query = query.where((eb) => eb.fn('WEEK', [eb.ref('wpPosts.postDate')]), '=', this.args.w);
165
- if (this.args.day) query = query.where((eb) => eb.fn('DAY', [eb.ref('wpPosts.postDate')]), '=', this.args.day);
166
- if (this.args.hour !== undefined) query = query.where((eb) => eb.fn('HOUR', [eb.ref('wpPosts.postDate')]), '=', this.args.hour);
167
- if (this.args.minute !== undefined) query = query.where((eb) => eb.fn('MINUTE', [eb.ref('wpPosts.postDate')]), '=', this.args.minute);
168
- if (this.args.second !== undefined) query = query.where((eb) => eb.fn('SECOND', [eb.ref('wpPosts.postDate')]), '=', this.args.second);
169
-
170
- // -- Calculate Total Count (Before Limits/Offsets) --
171
- if (!this.args.noFoundRows) {
172
- try {
173
- const countQueryBase = query.clearSelect().select('wpPosts.ID').distinct();
174
- const countResult = await wpdb.selectFrom(countQueryBase.as('sub'))
175
- .select(sql<number>`count(*)`.as('count'))
176
- .executeTakeFirst();
177
-
178
- this.postCount = countResult ? Number(countResult.count) : undefined;
179
- } catch (error: any) {
180
- console.error('WPPostQuery: Cannot get row count: ', error.message);
181
- this.postCount = undefined;
182
- }
183
- } else {
184
- this.postCount = undefined;
185
- }
186
-
187
- // -- Apply ORDER BY --
188
- if (!this.args.ignoreStickyPosts) {
189
- const rawStickyPostIds = await getOption('sticky_posts');
190
-
191
- let stickyPosts: number[] = [];
192
- try {
193
- const parsed = phpSerialize.unserialize(rawStickyPostIds ?? 'a:0:{}');
194
- stickyPosts = Object.values(parsed as Record<string, number> | number[]);
195
- } catch (error) {
196
- console.warn('WPPostQuery: Failed to parse sticky_posts option. Defaulting to empty.', error);
197
- }
198
-
199
- if (stickyPosts.length > 0) {
200
- query = query.orderBy(
201
- sql`CASE WHEN wp_posts.ID IN (${sql.join(stickyPosts)}) THEN 0 ELSE 1 END`,
202
- 'asc'
203
- );
204
- }
205
- }
206
-
207
- const orderDirection = this.args.order === 'ASC' ? 'asc' : 'desc';
208
- const orderBy = this.args.orderBy || 'none';
209
-
210
- switch(orderBy) {
211
- case 'none': break;
212
- case 'id': query = query.orderBy('wpPosts.ID', orderDirection); break;
213
- case 'author': query = query.orderBy('wpPosts.postAuthor', orderDirection).orderBy('wpPosts.ID', orderDirection); break;
214
- case 'title': query = query.orderBy('wpPosts.postTitle', orderDirection).orderBy('wpPosts.ID', orderDirection); break;
215
- case 'name': query = query.orderBy('wpPosts.postName', orderDirection).orderBy('wpPosts.ID', orderDirection); break;
216
- case 'date': query = query.orderBy('wpPosts.postDate', orderDirection).orderBy('wpPosts.ID', orderDirection); break;
217
- case 'modified': query = query.orderBy('wpPosts.postModified', orderDirection).orderBy('wpPosts.ID', orderDirection); break;
218
- case 'parent': query = query.orderBy('wpPosts.postParent', orderDirection).orderBy('wpPosts.ID', orderDirection); break;
219
- case 'menuOrder': query = query.orderBy('wpPosts.menuOrder', orderDirection).orderBy('wpPosts.ID', orderDirection); break;
220
- case 'commentCount': query = query.orderBy('wpPosts.commentCount', orderDirection).orderBy('wpPosts.ID', orderDirection); break;
221
- case 'rand': query = query.orderBy((eb) => eb.fn('RAND', [])).orderBy('wpPosts.ID', orderDirection); break;
222
- default:
223
- if (orderBy.startsWith('RAND(')) {
224
- const seed = parseInt(orderBy.replace(/\D/g, ''), 10);
225
- query = query.orderBy((eb) => eb.fn('RAND', [eb.val(seed)])).orderBy('wpPosts.ID', orderDirection);
226
- } else {
227
- query = query.orderBy('wpPosts.postDate', orderDirection).orderBy('wpPosts.ID', orderDirection);
228
- }
229
- break;
230
- }
231
-
232
- // -- Apply LIMIT & OFFSET --
233
- if (!this.args.noPaging) {
234
- const perPage = this.args.postsPerPage ?? 10;
235
-
236
- if (perPage > -1) {
237
- query = query.limit(perPage);
238
-
239
- const page = this.args.page ?? 1;
240
- const baseOffset = this.args.offset ?? 0;
241
- const offsetAmount = ((page - 1) * perPage) + baseOffset;
242
-
243
- if (offsetAmount > 0) {
244
- query = query.offset(offsetAmount);
245
- }
246
- }
247
- }
248
-
249
- if (this.args.metaQuery) {
250
- let dynamicQuery: any = query;
251
-
252
- for (let metaQuery of this.args.metaQuery) {
253
- const uniqueAlias = `meta_${metaQuery.as}`;
254
-
255
- dynamicQuery = dynamicQuery.leftJoin(`wpPostmeta as ${uniqueAlias}`, (join: any) =>
256
- join
257
- .onRef(`${uniqueAlias}.postId`, '=', 'wpPosts.ID')
258
- .on(`${uniqueAlias}.metaKey`, '=', metaQuery.metaKey)
259
- )
260
- .select(`${uniqueAlias}.metaValue as ${metaQuery.as}`);
261
- }
262
-
263
- query = dynamicQuery;
264
- }
265
-
266
- try {
267
- if(this.args.multiple !== false) {
268
- return (await query
269
- .select('wpPosts.ID as id')
270
- .groupBy('wpPosts.ID')
271
- .execute()).map(res => res.id);
272
- } else {
273
- return (await query
274
- .select('wpPosts.ID as id')
275
- .execute()).map(res => res.id);
276
- }
277
- } catch (error: any) {
278
- throw new Error(`WPPostQuery: Cannot get posts: ${error.message}`, { cause: error });
279
- }
280
- }
281
- }
@@ -1,61 +0,0 @@
1
- /**
2
- * Defines the arguments for querying terms.
3
- * Maps standard WordPress WP_Term_Query parameters.
4
- */
5
- interface TermQueryArgs {
6
- /** Taxonomy name, or array of taxonomy names, to which results should be limited. */
7
- taxonomy?: string | string[];
8
- /** Taxonomy ID, or array of term taxonomy IDs, to match when querying terms. */
9
- taxonomyId?: number | number[];
10
- /** TermId or array of term IDs to include along with all of their descendant terms. */
11
- termId?: number | number[];
12
- /** TermId or array of term IDs to exclude along with all of their descendant terms. */
13
- termIdNot?: number | number[];
14
- /** Slug or array of slugs to return term(s) for. Default empty. */
15
- termSlug?: string | string[];
16
- /** Slug or array of slugs to return term(s) for. Default empty. */
17
- termSlugNot?: string | string[];
18
- /** Name or array of names to return term(s) for. Default empty. */
19
- termName?: string | string[];
20
- /** Nextpress path to the term */
21
- path?: string;
22
- /** Whether to hide terms not assigned to any posts. Default true. */
23
- hideEmpty?: boolean;
24
- /** Field(s) to order terms by. Default 'none'. */
25
- orderBy?:
26
- | 'term_id'
27
- | 'name'
28
- | 'slug'
29
- | 'term_group'
30
- | 'description'
31
- | 'parent'
32
- | 'term_order'
33
- | 'count'
34
- | 'none'
35
- | string;
36
- /** Whether to order terms in ascending or descending order. Default 'ASC'. */
37
- order?: 'ASC' | 'DESC';
38
- /** Maximum number of terms to return. Accepts 0 (all) or any positive number. Default 0 (all). */
39
- number?: number;
40
- /** The number by which to offset the terms query. Default empty. */
41
- offset?: number;
42
- /** Parent term ID to retrieve direct-child terms of. Default empty. */
43
- parent?: number;
44
- /** True to limit results to terms that have no children. This parameter has no effect on non-hierarchical taxonomies. Default false. */
45
- childless?: boolean;
46
- /** Search criteria to match terms. Will be SQL-formatted with wildcards before and after. Default empty. */
47
- search?: string;
48
- /** Retrieve terms with criteria by which a term is LIKE `$nameLike`. Default empty. */
49
- nameLike?: string;
50
- /** Retrieve terms where the description is LIKE `$descriptionLike`. Default empty. */
51
- descriptionLike?: string;
52
- /** Meta query */
53
- metaQuery?: {
54
- /** Meta key */
55
- metaKey: string,
56
- /** Variable name to save result to */
57
- as: string
58
- }[]
59
- /** Whether to get multiple, default true */
60
- multiple?: bool
61
- }