nextpress-core 1.0.0 → 1.0.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.
Files changed (182) 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/services/define-field-group.d.ts +8 -0
  8. package/{lib/acf-functions/services/define-field-group.ts → dist/acf-functions/services/define-field-group.js} +1 -1
  9. package/dist/acf-functions/services/define-layout.d.ts +8 -0
  10. package/{lib/acf-functions/services/define-layout.ts → dist/acf-functions/services/define-layout.js} +1 -1
  11. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +2 -0
  12. package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +18 -0
  13. package/dist/acf-functions/services/map-fields/map-fields.d.ts +18 -0
  14. package/{lib/acf-functions/services/map-fields/map-fields.ts → dist/acf-functions/services/map-fields/map-fields.js} +88 -124
  15. package/dist/entities/option/option.d.ts +19 -0
  16. package/{lib/entities/option/option.ts → dist/entities/option/option.js} +13 -20
  17. package/dist/entities/post/post.d.ts +50 -0
  18. package/dist/entities/post/post.js +184 -0
  19. package/dist/entities/term/term.d.ts +28 -0
  20. package/dist/entities/term/term.js +67 -0
  21. package/dist/entities/user/user.d.ts +27 -0
  22. package/dist/entities/user/user.js +74 -0
  23. package/dist/globals/entity-loader/entity-loader-base.d.ts +65 -0
  24. package/{lib/globals/entity-loader/entity-loader-base.ts → dist/globals/entity-loader/entity-loader-base.js} +10 -64
  25. package/dist/globals/entity-loader/option-loader.d.ts +15 -0
  26. package/dist/globals/entity-loader/option-loader.js +31 -0
  27. package/dist/globals/entity-loader/post-loader.d.ts +21 -0
  28. package/dist/globals/entity-loader/post-loader.js +28 -0
  29. package/dist/globals/entity-loader/term-loader.d.ts +21 -0
  30. package/dist/globals/entity-loader/term-loader.js +28 -0
  31. package/dist/globals/entity-loader/user-loader.d.ts +21 -0
  32. package/dist/globals/entity-loader/user-loader.js +28 -0
  33. package/dist/globals/get-field/get-field.d.ts +17 -0
  34. package/dist/globals/get-field/get-field.js +44 -0
  35. package/dist/globals/globals.d.ts +18 -0
  36. package/{lib/globals/globals.ts → dist/globals/globals.js} +3 -8
  37. package/dist/globals/nextpress-config/nextpress-config.d.ts +4 -0
  38. package/{lib/globals/nextpress-config/nextpress-config.ts → dist/globals/nextpress-config/nextpress-config.js} +0 -5
  39. package/dist/globals/queried-object/queried-object.d.ts +62 -0
  40. package/dist/globals/queried-object/queried-object.js +56 -0
  41. package/dist/repository/optionquery/option-query.d.ts +12 -0
  42. package/dist/repository/optionquery/option-query.js +20 -0
  43. package/dist/repository/postquery/post-query.d.ts +12 -0
  44. package/dist/repository/postquery/post-query.js +272 -0
  45. package/dist/repository/termquery/term-query.d.ts +11 -0
  46. package/dist/repository/termquery/term-query.js +213 -0
  47. package/dist/repository/userquery/user-query.d.ts +12 -0
  48. package/{lib/repository/userquery/user-query.ts → dist/repository/userquery/user-query.js} +75 -91
  49. package/dist/router/helpers.d.ts +14 -0
  50. package/{lib/router/helpers.ts → dist/router/helpers.js} +4 -4
  51. package/dist/router/nextpress-layout.d.ts +11 -0
  52. package/{lib/router/nextpress-layout.tsx → dist/router/nextpress-layout.js} +6 -23
  53. package/dist/router/nextpress-proxy.d.ts +8 -0
  54. package/{lib/router/nextpress-proxy.ts → dist/router/nextpress-proxy.js} +3 -15
  55. package/dist/router/nextpress-static-params.d.ts +9 -0
  56. package/{lib/router/nextpress-static-params.ts → dist/router/nextpress-static-params.js} +5 -17
  57. package/dist/router/router.d.ts +23 -0
  58. package/{lib/router/router.tsx → dist/router/router.js} +21 -29
  59. package/dist/router/routes/api/api-get-admin-bar.d.ts +8 -0
  60. package/{lib/router/routes/api/api-get-admin-bar.ts → dist/router/routes/api/api-get-admin-bar.js} +6 -8
  61. package/dist/router/routes/api/api-get-draft-mode.d.ts +8 -0
  62. package/{lib/router/routes/api/api-get-draft-mode.ts → dist/router/routes/api/api-get-draft-mode.js} +6 -15
  63. package/dist/router/routes/api/api-get-field-groups.d.ts +7 -0
  64. package/{lib/router/routes/api/api-get-field-groups.ts → dist/router/routes/api/api-get-field-groups.js} +6 -11
  65. package/dist/router/routes/api/api-post-revalidate.d.ts +7 -0
  66. package/{lib/router/routes/api/api-post-revalidate.ts → dist/router/routes/api/api-post-revalidate.js} +4 -6
  67. package/dist/router/routes/api/helpers.d.ts +8 -0
  68. package/{lib/router/routes/api/helpers.ts → dist/router/routes/api/helpers.js} +3 -4
  69. package/dist/router/routes/author-archive.d.ts +25 -0
  70. package/{lib/router/routes/author-archive.tsx → dist/router/routes/author-archive.js} +11 -37
  71. package/dist/router/routes/not-found-page.d.ts +15 -0
  72. package/{lib/router/routes/not-found-page.tsx → dist/router/routes/not-found-page.js} +3 -5
  73. package/dist/router/routes/post-index-page.d.ts +25 -0
  74. package/dist/router/routes/post-index-page.js +33 -0
  75. package/dist/router/routes/singular-page.d.ts +29 -0
  76. package/dist/router/routes/singular-page.js +51 -0
  77. package/dist/router/routes/site-front-page.d.ts +27 -0
  78. package/dist/router/routes/site-front-page.js +26 -0
  79. package/dist/router/routes/term-archive.d.ts +29 -0
  80. package/{lib/router/routes/term-archive.tsx → dist/router/routes/term-archive.js} +17 -45
  81. package/dist/services/get-menu.d.ts +13 -0
  82. package/{lib/services/get-menu.ts → dist/services/get-menu.js} +32 -56
  83. package/dist/services/get-theme-mods.d.ts +7 -0
  84. package/{lib/services/get-theme-mods.ts → dist/services/get-theme-mods.js} +4 -6
  85. package/dist/services/metadata/get-blogname.d.ts +6 -0
  86. package/{lib/services/metadata/get-blogname.ts → dist/services/metadata/get-blogname.js} +2 -2
  87. package/dist/services/metadata/get-favicon-url.d.ts +6 -0
  88. package/{lib/services/metadata/get-favicon-url.ts → dist/services/metadata/get-favicon-url.js} +4 -5
  89. package/dist/services/metadata/get-language-attribute.d.ts +6 -0
  90. package/{lib/services/metadata/get-language-attribute.ts → dist/services/metadata/get-language-attribute.js} +1 -1
  91. package/{lib/services/services.ts → dist/services/services.d.ts} +1 -5
  92. package/dist/services/services.js +3 -0
  93. package/dist/services/utilities/capitalise-first-letter.d.ts +7 -0
  94. package/{lib/services/utilities/capitalise-first-letter.ts → dist/services/utilities/capitalise-first-letter.js} +3 -2
  95. package/dist/services/utilities/esc-html.d.ts +7 -0
  96. package/{lib/services/utilities/esc-html.ts → dist/services/utilities/esc-html.js} +1 -3
  97. package/dist/services/utilities/get-date-time-formatter.d.ts +6 -0
  98. package/{lib/services/utilities/get-date-time-formatter.ts → dist/services/utilities/get-date-time-formatter.js} +6 -16
  99. package/dist/services/utilities/index.js +1 -0
  100. package/dist/services/utilities/kses-post.d.ts +7 -0
  101. package/{lib/services/utilities/kses-post.ts → dist/services/utilities/kses-post.js} +1 -2
  102. package/dist/services/utilities/process-url.d.ts +7 -0
  103. package/{lib/services/utilities/process-url.ts → dist/services/utilities/process-url.js} +3 -4
  104. package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +9 -0
  105. package/{lib/template-heirarchy/_autoloader/template-autoloader.ts → dist/template-heirarchy/_autoloader/template-autoloader.js} +9 -18
  106. package/dist/template-heirarchy/archive/archive.d.ts +16 -0
  107. package/{lib/template-heirarchy/archive/archive.tsx → dist/template-heirarchy/archive/archive.js} +7 -10
  108. package/dist/template-heirarchy/archive/author.d.ts +16 -0
  109. package/{lib/template-heirarchy/archive/author.tsx → dist/template-heirarchy/archive/author.js} +7 -10
  110. package/dist/template-heirarchy/archive/category.d.ts +16 -0
  111. package/{lib/template-heirarchy/archive/category.tsx → dist/template-heirarchy/archive/category.js} +7 -11
  112. package/dist/template-heirarchy/archive/posttypearchive.d.ts +24 -0
  113. package/{lib/template-heirarchy/archive/posttypearchive.tsx → dist/template-heirarchy/archive/posttypearchive.js} +7 -10
  114. package/dist/template-heirarchy/archive/tag.d.ts +16 -0
  115. package/{lib/template-heirarchy/archive/tag.tsx → dist/template-heirarchy/archive/tag.js} +7 -12
  116. package/dist/template-heirarchy/archive/taxonomy.d.ts +16 -0
  117. package/{lib/template-heirarchy/archive/taxonomy.tsx → dist/template-heirarchy/archive/taxonomy.js} +7 -10
  118. package/dist/template-heirarchy/home/home.d.ts +16 -0
  119. package/{lib/template-heirarchy/home/home.tsx → dist/template-heirarchy/home/home.js} +7 -10
  120. package/dist/template-heirarchy/index.d.ts +17 -0
  121. package/{lib/template-heirarchy/index.tsx → dist/template-heirarchy/index.js} +5 -9
  122. package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +16 -0
  123. package/{lib/template-heirarchy/not-found.tsx/not-found.tsx → dist/template-heirarchy/not-found.tsx/not-found.js} +7 -10
  124. package/dist/template-heirarchy/page/page.d.ts +16 -0
  125. package/{lib/template-heirarchy/page/page.tsx → dist/template-heirarchy/page/page.js} +7 -10
  126. package/dist/template-heirarchy/page/posttype.d.ts +24 -0
  127. package/{lib/template-heirarchy/page/posttype.tsx → dist/template-heirarchy/page/posttype.js} +7 -11
  128. package/dist/template-heirarchy/page/single.d.ts +16 -0
  129. package/{lib/template-heirarchy/page/single.tsx → dist/template-heirarchy/page/single.js} +7 -10
  130. package/dist/template-heirarchy/page/singular.d.ts +16 -0
  131. package/{lib/template-heirarchy/page/singular.tsx → dist/template-heirarchy/page/singular.js} +7 -10
  132. package/dist/ui/render-attachment-image.d.ts +12 -0
  133. package/dist/ui/render-attachment-image.js +24 -0
  134. package/{lib/ui/render-components.tsx → dist/ui/render-components.d.ts} +4 -7
  135. package/dist/ui/render-components.js +7 -0
  136. package/dist/ui/render-the-admin-bar.d.ts +8 -0
  137. package/dist/ui/render-the-admin-bar.js +36 -0
  138. package/dist/ui/render-the-logo.d.ts +10 -0
  139. package/dist/ui/render-the-logo.js +16 -0
  140. package/dist/wpdb/wpdb.d.ts +3 -0
  141. package/{lib/wpdb/wpdb.ts → dist/wpdb/wpdb.js} +5 -9
  142. package/package.json +7 -3
  143. package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +0 -20
  144. package/lib/acf-functions/types/acf-field-group.d.ts +0 -118
  145. package/lib/acf-functions/types/acf-field.d.ts +0 -2851
  146. package/lib/acf-functions/types/acf-layout.d.ts +0 -20
  147. package/lib/acf-functions/types/acf-values.d.ts +0 -4
  148. package/lib/acf-functions/types/components/field-props.d.ts +0 -189
  149. package/lib/acf-functions/types/components/nextpress-component.d.ts +0 -11
  150. package/lib/ambient.d.ts +0 -15
  151. package/lib/entities/common.d.ts +0 -30
  152. package/lib/entities/option/option.interface.d.ts +0 -8
  153. package/lib/entities/post/post.interface.d.ts +0 -72
  154. package/lib/entities/post/post.ts +0 -209
  155. package/lib/entities/term/term.interface.d.ts +0 -8
  156. package/lib/entities/term/term.ts +0 -82
  157. package/lib/entities/user/user.interface.d.ts +0 -10
  158. package/lib/entities/user/user.ts +0 -86
  159. package/lib/globals/entity-loader/entity-loader.d.ts +0 -50
  160. package/lib/globals/entity-loader/option-loader.ts +0 -56
  161. package/lib/globals/entity-loader/post-loader.ts +0 -59
  162. package/lib/globals/entity-loader/term-loader.ts +0 -59
  163. package/lib/globals/entity-loader/user-loader.ts +0 -60
  164. package/lib/globals/get-field/get-field.ts +0 -75
  165. package/lib/globals/nextpress-config/nextpress-config.interface.d.ts +0 -18
  166. package/lib/globals/queried-object/queried-object.ts +0 -124
  167. package/lib/repository/optionquery/option-query-args.d.ts +0 -21
  168. package/lib/repository/optionquery/option-query.ts +0 -29
  169. package/lib/repository/postquery/post-query-args.d.ts +0 -108
  170. package/lib/repository/postquery/post-query.ts +0 -281
  171. package/lib/repository/termquery/term-query-args.d.ts +0 -61
  172. package/lib/repository/termquery/term-query.ts +0 -243
  173. package/lib/repository/userquery/user-query-args.d.ts +0 -75
  174. package/lib/router/routes/post-index-page.tsx +0 -58
  175. package/lib/router/routes/singular-page.tsx +0 -78
  176. package/lib/router/routes/site-front-page.tsx +0 -51
  177. package/lib/router/types.d.ts +0 -9
  178. package/lib/ui/render-attachment-image.tsx +0 -29
  179. package/lib/ui/render-the-admin-bar.tsx +0 -79
  180. package/lib/ui/render-the-logo.tsx +0 -24
  181. package/lib/wpdb/wpdb.interface.d.ts +0 -171
  182. /package/{lib/services/utilities/index.ts → dist/services/utilities/index.d.ts} +0 -0
@@ -0,0 +1,272 @@
1
+ import { sql } from "kysely";
2
+ import * as phpSerialize from "php-serialize";
3
+ import { wpdb } from "@/wpdb/wpdb";
4
+ /**
5
+ * Executes database queries to retrieve post IDs and counts based on provided arguments.
6
+ */
7
+ export class PostQuery {
8
+ constructor(args) {
9
+ this.args = args;
10
+ }
11
+ getCount() {
12
+ return this.postCount;
13
+ }
14
+ async getIds() {
15
+ var _a, _b, _c;
16
+ let builder = wpdb;
17
+ if (this.args.postAncestryOf) {
18
+ builder = builder.withRecursive('decendent_tree', (qb) => qb.selectFrom('wpPosts')
19
+ .select(['wpPosts.ID', 'wpPosts.postName', 'wpPosts.postParent'])
20
+ .where('wpPosts.postName', '=', this.args.postAncestryOf)
21
+ .unionAll(qb.selectFrom('wpPosts as p')
22
+ .select(['p.ID', 'p.postName', 'p.postParent'])
23
+ .innerJoin('decendent_tree as d', 'p.postParent', 'd.ID')));
24
+ }
25
+ let query = builder.selectFrom('wpPosts');
26
+ if (this.args.postAncestryOf) {
27
+ query = query.where('wpPosts.postName', 'in', (qb) => qb.selectFrom('decendent_tree').select('postName'));
28
+ }
29
+ // --- ID Filters ---
30
+ if (this.args.postId)
31
+ query = query.where('wpPosts.ID', '=', this.args.postId);
32
+ if (this.args.postIn)
33
+ query = query.where('wpPosts.ID', 'in', this.args.postIn);
34
+ if (this.args.postNotIn)
35
+ query = query.where('wpPosts.ID', 'not in', this.args.postNotIn);
36
+ if (this.args.path) {
37
+ query = query.where((eb) => eb.exists(eb.selectFrom('wpPostmeta')
38
+ .select('postId')
39
+ .whereRef('postId', '=', 'wpPosts.ID')
40
+ .where('wpPostmeta.metaKey', '=', '_nextpress_path')
41
+ .where('wpPostmeta.metaValue', '=', this.args.path)));
42
+ }
43
+ // --- Type Filters ---
44
+ if (this.args.postType) {
45
+ const types = Array.isArray(this.args.postType) ? this.args.postType : [this.args.postType];
46
+ query = query.where('wpPosts.postType', 'in', types);
47
+ }
48
+ if (this.args.postTypeNot) {
49
+ const types = Array.isArray(this.args.postTypeNot) ? this.args.postTypeNot : [this.args.postTypeNot];
50
+ query = query.where('wpPosts.postType', 'not in', types);
51
+ }
52
+ // --- Status Filters ---
53
+ if (this.args.postStatus) {
54
+ const statuses = Array.isArray(this.args.postStatus) ? this.args.postStatus : [this.args.postStatus];
55
+ query = query.where('wpPosts.postStatus', 'in', statuses);
56
+ }
57
+ // --- Content Filters ---
58
+ if (this.args.postSlug) {
59
+ const postSlugs = Array.isArray(this.args.postSlug) ? this.args.postSlug : [this.args.postSlug];
60
+ query = query.where('wpPosts.postName', 'in', postSlugs);
61
+ }
62
+ if (this.args.title)
63
+ query = query.where('wpPosts.postTitle', '=', this.args.title);
64
+ if (this.args.postMimeType)
65
+ query = query.where('wpPosts.postMimeType', 'like', `%${this.args.postMimeType}%`);
66
+ // --- Parent Filters ---
67
+ if (this.args.postParent !== undefined)
68
+ query = query.where('wpPosts.postParent', '=', this.args.postParent);
69
+ if (this.args.postParentIn)
70
+ query = query.where('wpPosts.postParent', 'in', this.args.postParentIn);
71
+ if (this.args.postParentNotIn)
72
+ query = query.where('wpPosts.postParent', 'not in', this.args.postParentNotIn);
73
+ // --- Term Filters ---
74
+ if (this.args.termId) {
75
+ query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
76
+ .where('wpTermRelationships.termTaxonomyId', '=', this.args.termId);
77
+ }
78
+ if (this.args.termAnd) {
79
+ query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
80
+ .where('wpTermRelationships.termTaxonomyId', 'in', this.args.termAnd)
81
+ .groupBy('wpPosts.ID')
82
+ .having((eb) => eb.fn.count('wpTermRelationships.termTaxonomyId'), '=', this.args.termAnd.length);
83
+ }
84
+ if (this.args.termIn) {
85
+ query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
86
+ .where('wpTermRelationships.termTaxonomyId', 'in', this.args.termIn);
87
+ }
88
+ if (this.args.termNotIn) {
89
+ query = query.where('wpPosts.ID', 'not in', (qb) => qb.selectFrom('wpTermRelationships')
90
+ .select('wpTermRelationships.objectId')
91
+ .where('wpTermRelationships.termTaxonomyId', 'in', this.args.termNotIn));
92
+ }
93
+ if (this.args.termSlug) {
94
+ query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
95
+ .innerJoin('wpTerms', 'wpTermRelationships.termTaxonomyId', 'wpTerms.termId')
96
+ .where('wpTerms.slug', '=', this.args.termSlug)
97
+ .groupBy('wpPosts.ID');
98
+ }
99
+ if (this.args.termSlugAnd) {
100
+ query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
101
+ .innerJoin('wpTerms', 'wpTermRelationships.termTaxonomyId', 'wpTerms.termId')
102
+ .where('wpTerms.slug', 'in', this.args.termSlugAnd)
103
+ .groupBy('wpPosts.ID')
104
+ .having((eb) => eb.fn.count('wpTermRelationships.termTaxonomyId'), '=', this.args.termSlugAnd.length);
105
+ }
106
+ if (this.args.termSlugIn) {
107
+ query = query.innerJoin('wpTermRelationships', 'wpPosts.ID', 'wpTermRelationships.objectId')
108
+ .innerJoin('wpTerms', 'wpTermRelationships.termTaxonomyId', 'wpTerms.termId')
109
+ .where('wpTerms.slug', 'in', this.args.termSlugIn)
110
+ .groupBy('wpPosts.ID');
111
+ }
112
+ // --- Author Filters ---
113
+ if (this.args.authorId)
114
+ query = query.where('wpPosts.postAuthor', '=', this.args.authorId);
115
+ if (this.args.authorIn)
116
+ query = query.where('wpPosts.postAuthor', 'in', this.args.authorIn);
117
+ if (this.args.authorNotIn)
118
+ query = query.where('wpPosts.postAuthor', 'not in', this.args.authorNotIn);
119
+ if (this.args.authorName) {
120
+ query = query.innerJoin('wpUsers', 'wpPosts.postAuthor', 'wpUsers.ID')
121
+ .where('wpUsers.displayName', '=', this.args.authorName);
122
+ }
123
+ // --- Search Filters ---
124
+ if (this.args.search) {
125
+ const searchTerm = this.args.exact ? this.args.search : `%${this.args.search}%`;
126
+ const searchCols = this.args.searchColumns || ['postTitle', 'postContent', 'postExcerpt'];
127
+ const isExact = this.args.exact;
128
+ query = query.where((eb) => {
129
+ const orClauses = searchCols.map(col => eb(col, isExact ? '=' : 'like', searchTerm));
130
+ return eb.or(orClauses);
131
+ });
132
+ }
133
+ // --- Date Filters ---
134
+ if (this.args.yyyymm) {
135
+ const mStr = String(this.args.yyyymm);
136
+ const y = Number(mStr.substring(0, 4));
137
+ const mon = Number(mStr.substring(4, 6));
138
+ query = query.where((eb) => eb.fn('YEAR', [eb.ref('wpPosts.postDate')]), '=', y)
139
+ .where((eb) => eb.fn('MONTH', [eb.ref('wpPosts.postDate')]), '=', mon);
140
+ }
141
+ if (this.args.year)
142
+ query = query.where((eb) => eb.fn('YEAR', [eb.ref('wpPosts.postDate')]), '=', this.args.year);
143
+ if (this.args.monthnum)
144
+ query = query.where((eb) => eb.fn('MONTH', [eb.ref('wpPosts.postDate')]), '=', this.args.monthnum);
145
+ if (this.args.w)
146
+ query = query.where((eb) => eb.fn('WEEK', [eb.ref('wpPosts.postDate')]), '=', this.args.w);
147
+ if (this.args.day)
148
+ query = query.where((eb) => eb.fn('DAY', [eb.ref('wpPosts.postDate')]), '=', this.args.day);
149
+ if (this.args.hour !== undefined)
150
+ query = query.where((eb) => eb.fn('HOUR', [eb.ref('wpPosts.postDate')]), '=', this.args.hour);
151
+ if (this.args.minute !== undefined)
152
+ query = query.where((eb) => eb.fn('MINUTE', [eb.ref('wpPosts.postDate')]), '=', this.args.minute);
153
+ if (this.args.second !== undefined)
154
+ query = query.where((eb) => eb.fn('SECOND', [eb.ref('wpPosts.postDate')]), '=', this.args.second);
155
+ // -- Calculate Total Count (Before Limits/Offsets) --
156
+ if (!this.args.noFoundRows) {
157
+ try {
158
+ const countQueryBase = query.clearSelect().select('wpPosts.ID').distinct();
159
+ const countResult = await wpdb.selectFrom(countQueryBase.as('sub'))
160
+ .select(sql `count(*)`.as('count'))
161
+ .executeTakeFirst();
162
+ this.postCount = countResult ? Number(countResult.count) : undefined;
163
+ }
164
+ catch (error) {
165
+ console.error('WPPostQuery: Cannot get row count: ', error.message);
166
+ this.postCount = undefined;
167
+ }
168
+ }
169
+ else {
170
+ this.postCount = undefined;
171
+ }
172
+ // -- Apply ORDER BY --
173
+ if (!this.args.ignoreStickyPosts) {
174
+ const rawStickyPostIds = await getOption('sticky_posts');
175
+ let stickyPosts = [];
176
+ try {
177
+ const parsed = phpSerialize.unserialize(rawStickyPostIds !== null && rawStickyPostIds !== void 0 ? rawStickyPostIds : 'a:0:{}');
178
+ stickyPosts = Object.values(parsed);
179
+ }
180
+ catch (error) {
181
+ console.warn('WPPostQuery: Failed to parse sticky_posts option. Defaulting to empty.', error);
182
+ }
183
+ if (stickyPosts.length > 0) {
184
+ query = query.orderBy(sql `CASE WHEN wp_posts.ID IN (${sql.join(stickyPosts)}) THEN 0 ELSE 1 END`, 'asc');
185
+ }
186
+ }
187
+ const orderDirection = this.args.order === 'ASC' ? 'asc' : 'desc';
188
+ const orderBy = this.args.orderBy || 'none';
189
+ switch (orderBy) {
190
+ case 'none': break;
191
+ case 'id':
192
+ query = query.orderBy('wpPosts.ID', orderDirection);
193
+ break;
194
+ case 'author':
195
+ query = query.orderBy('wpPosts.postAuthor', orderDirection).orderBy('wpPosts.ID', orderDirection);
196
+ break;
197
+ case 'title':
198
+ query = query.orderBy('wpPosts.postTitle', orderDirection).orderBy('wpPosts.ID', orderDirection);
199
+ break;
200
+ case 'name':
201
+ query = query.orderBy('wpPosts.postName', orderDirection).orderBy('wpPosts.ID', orderDirection);
202
+ break;
203
+ case 'date':
204
+ query = query.orderBy('wpPosts.postDate', orderDirection).orderBy('wpPosts.ID', orderDirection);
205
+ break;
206
+ case 'modified':
207
+ query = query.orderBy('wpPosts.postModified', orderDirection).orderBy('wpPosts.ID', orderDirection);
208
+ break;
209
+ case 'parent':
210
+ query = query.orderBy('wpPosts.postParent', orderDirection).orderBy('wpPosts.ID', orderDirection);
211
+ break;
212
+ case 'menuOrder':
213
+ query = query.orderBy('wpPosts.menuOrder', orderDirection).orderBy('wpPosts.ID', orderDirection);
214
+ break;
215
+ case 'commentCount':
216
+ query = query.orderBy('wpPosts.commentCount', orderDirection).orderBy('wpPosts.ID', orderDirection);
217
+ break;
218
+ case 'rand':
219
+ query = query.orderBy((eb) => eb.fn('RAND', [])).orderBy('wpPosts.ID', orderDirection);
220
+ break;
221
+ default:
222
+ if (orderBy.startsWith('RAND(')) {
223
+ const seed = parseInt(orderBy.replace(/\D/g, ''), 10);
224
+ query = query.orderBy((eb) => eb.fn('RAND', [eb.val(seed)])).orderBy('wpPosts.ID', orderDirection);
225
+ }
226
+ else {
227
+ query = query.orderBy('wpPosts.postDate', orderDirection).orderBy('wpPosts.ID', orderDirection);
228
+ }
229
+ break;
230
+ }
231
+ // -- Apply LIMIT & OFFSET --
232
+ if (!this.args.noPaging) {
233
+ const perPage = (_a = this.args.postsPerPage) !== null && _a !== void 0 ? _a : 10;
234
+ if (perPage > -1) {
235
+ query = query.limit(perPage);
236
+ const page = (_b = this.args.page) !== null && _b !== void 0 ? _b : 1;
237
+ const baseOffset = (_c = this.args.offset) !== null && _c !== void 0 ? _c : 0;
238
+ const offsetAmount = ((page - 1) * perPage) + baseOffset;
239
+ if (offsetAmount > 0) {
240
+ query = query.offset(offsetAmount);
241
+ }
242
+ }
243
+ }
244
+ if (this.args.metaQuery) {
245
+ let dynamicQuery = query;
246
+ for (let metaQuery of this.args.metaQuery) {
247
+ const uniqueAlias = `meta_${metaQuery.as}`;
248
+ dynamicQuery = dynamicQuery.leftJoin(`wpPostmeta as ${uniqueAlias}`, (join) => join
249
+ .onRef(`${uniqueAlias}.postId`, '=', 'wpPosts.ID')
250
+ .on(`${uniqueAlias}.metaKey`, '=', metaQuery.metaKey))
251
+ .select(`${uniqueAlias}.metaValue as ${metaQuery.as}`);
252
+ }
253
+ query = dynamicQuery;
254
+ }
255
+ try {
256
+ if (this.args.multiple !== false) {
257
+ return (await query
258
+ .select('wpPosts.ID as id')
259
+ .groupBy('wpPosts.ID')
260
+ .execute()).map(res => res.id);
261
+ }
262
+ else {
263
+ return (await query
264
+ .select('wpPosts.ID as id')
265
+ .execute()).map(res => res.id);
266
+ }
267
+ }
268
+ catch (error) {
269
+ throw new Error(`WPPostQuery: Cannot get posts: ${error.message}`, { cause: error });
270
+ }
271
+ }
272
+ }
@@ -0,0 +1,11 @@
1
+ import { EntityQuery } from "../../globals/entity-loader/entity-loader";
2
+ import { ITerm } from "../../entities/term/term.interface";
3
+ /**
4
+ * Executes database queries to retrieve term IDs based on provided arguments.
5
+ */
6
+ export declare class TermQuery implements EntityQuery<ITerm> {
7
+ private args;
8
+ constructor(args: TermQueryArgs);
9
+ getCount(): undefined;
10
+ getIds(): Promise<number[]>;
11
+ }
@@ -0,0 +1,213 @@
1
+ import { wpdb } from "@/wpdb/wpdb";
2
+ /**
3
+ * Executes database queries to retrieve term IDs based on provided arguments.
4
+ */
5
+ export class TermQuery {
6
+ constructor(args) {
7
+ this.args = args;
8
+ }
9
+ getCount() {
10
+ return undefined;
11
+ }
12
+ async getIds() {
13
+ var _a, _b;
14
+ let builder = wpdb;
15
+ const isMultiple = this.args.multiple !== false;
16
+ // -- Build CTEs --
17
+ if (this.args.termId) {
18
+ const termIds = Array.isArray(this.args.termId) ? this.args.termId : [this.args.termId];
19
+ const baseQuery = (qb) => qb.selectFrom('wpTermTaxonomy')
20
+ .select(['termId', 'parent'])
21
+ .where((eb) => eb.or([
22
+ eb('termId', 'in', termIds),
23
+ eb('parent', 'in', termIds)
24
+ ]));
25
+ if (isMultiple) {
26
+ builder = builder.withRecursive('included_branch_id', (qb) => baseQuery(qb).unionAll(qb.selectFrom('wpTermTaxonomy as t')
27
+ .select(['t.termId', 't.parent'])
28
+ .innerJoin('included_branch_id as f', 'f.termId', 't.parent')));
29
+ }
30
+ else {
31
+ builder = builder.with('included_branch_id', baseQuery);
32
+ }
33
+ }
34
+ if (this.args.termIdNot) {
35
+ const termIds = Array.isArray(this.args.termIdNot) ? this.args.termIdNot : [this.args.termIdNot];
36
+ const baseQuery = (qb) => qb.selectFrom('wpTermTaxonomy')
37
+ .select(['termId', 'parent'])
38
+ .where((eb) => eb.or([
39
+ eb('termId', 'in', termIds),
40
+ eb('parent', 'in', termIds)
41
+ ]));
42
+ if (isMultiple) {
43
+ builder = builder.withRecursive('excluded_branch_id', (qb) => baseQuery(qb).unionAll(qb.selectFrom('wpTermTaxonomy as t')
44
+ .select(['t.termId', 't.parent'])
45
+ .innerJoin('excluded_branch_id as f', 'f.termId', 't.parent')));
46
+ }
47
+ else {
48
+ builder = builder.with('excluded_branch_id', baseQuery);
49
+ }
50
+ }
51
+ if (this.args.termName) {
52
+ const names = Array.isArray(this.args.termName) ? this.args.termName : [this.args.termName];
53
+ const baseQuery = (qb) => qb.selectFrom('wpTermTaxonomy')
54
+ .innerJoin('wpTerms', 'wpTerms.termId', 'wpTermTaxonomy.termId')
55
+ .select(['wpTermTaxonomy.termId', 'wpTermTaxonomy.parent'])
56
+ .where('wpTerms.name', 'in', names);
57
+ if (isMultiple) {
58
+ builder = builder.withRecursive('included_branch_name', (qb) => baseQuery(qb).unionAll(qb.selectFrom('wpTermTaxonomy as t')
59
+ .select(['t.termId', 't.parent'])
60
+ .innerJoin('included_branch_name as f', 'f.termId', 't.parent')));
61
+ }
62
+ else {
63
+ builder = builder.with('included_branch_name', baseQuery);
64
+ }
65
+ }
66
+ if (this.args.termSlug) {
67
+ const slugs = Array.isArray(this.args.termSlug) ? this.args.termSlug : [this.args.termSlug];
68
+ const baseQuery = (qb) => qb.selectFrom('wpTermTaxonomy')
69
+ .innerJoin('wpTerms', 'wpTerms.termId', 'wpTermTaxonomy.termId')
70
+ .select(['wpTermTaxonomy.termId', 'wpTermTaxonomy.parent'])
71
+ .where('wpTerms.slug', 'in', slugs);
72
+ if (isMultiple) {
73
+ builder = builder.withRecursive('included_branch_slug', (qb) => baseQuery(qb).unionAll(qb.selectFrom('wpTermTaxonomy as t')
74
+ .select(['t.termId', 't.parent'])
75
+ .innerJoin('included_branch_slug as f', 'f.termId', 't.parent')));
76
+ }
77
+ else {
78
+ builder = builder.with('included_branch_slug', baseQuery);
79
+ }
80
+ }
81
+ if (this.args.termSlugNot) {
82
+ const slugs = Array.isArray(this.args.termSlugNot) ? this.args.termSlugNot : [this.args.termSlugNot];
83
+ const baseQuery = (qb) => qb.selectFrom('wpTermTaxonomy')
84
+ .innerJoin('wpTerms', 'wpTerms.termId', 'wpTermTaxonomy.termId')
85
+ .select(['wpTermTaxonomy.termId', 'wpTermTaxonomy.parent'])
86
+ .where('wpTerms.slug', 'in', slugs);
87
+ if (isMultiple) {
88
+ builder = builder.withRecursive('excluded_branch_slug', (qb) => baseQuery(qb).unionAll(qb.selectFrom('wpTermTaxonomy as t')
89
+ .select(['t.termId', 't.parent'])
90
+ .innerJoin('excluded_branch_slug as f', 'f.termId', 't.parent')));
91
+ }
92
+ else {
93
+ builder = builder.with('excluded_branch_slug', baseQuery);
94
+ }
95
+ }
96
+ // -- Begin Main SELECT Statement --
97
+ let query = builder.selectFrom('wpTerms')
98
+ .innerJoin('wpTermTaxonomy', 'wpTerms.termId', 'wpTermTaxonomy.termId');
99
+ // -- Apply Filters (WHERE clauses) --
100
+ if (this.args.taxonomy) {
101
+ const taxonomies = Array.isArray(this.args.taxonomy) ? this.args.taxonomy : [this.args.taxonomy];
102
+ query = query.where('wpTermTaxonomy.taxonomy', 'in', taxonomies);
103
+ }
104
+ if (this.args.taxonomyId) {
105
+ const ids = Array.isArray(this.args.taxonomyId) ? this.args.taxonomyId : [this.args.taxonomyId];
106
+ query = query.where('wpTermTaxonomy.termTaxonomyId', 'in', ids);
107
+ }
108
+ if (this.args.termId)
109
+ query = query.where('wpTerms.termId', 'in', (qb) => qb.selectFrom('included_branch_id').select('termId'));
110
+ if (this.args.termIdNot)
111
+ query = query.where('wpTerms.termId', 'not in', (qb) => qb.selectFrom('excluded_branch_id').select('termId'));
112
+ if (this.args.termName)
113
+ query = query.where('wpTerms.termId', 'in', (qb) => qb.selectFrom('included_branch_name').select('termId'));
114
+ if (this.args.termSlug)
115
+ query = query.where('wpTerms.termId', 'in', (qb) => qb.selectFrom('included_branch_slug').select('termId'));
116
+ if (this.args.termSlugNot)
117
+ query = query.where('wpTerms.termId', 'not in', (qb) => qb.selectFrom('excluded_branch_slug').select('termId'));
118
+ if (this.args.hideEmpty !== false)
119
+ query = query.where('wpTermTaxonomy.count', '>', 0);
120
+ if (this.args.parent !== undefined) {
121
+ query = query.where('wpTermTaxonomy.parent', '=', this.args.parent);
122
+ }
123
+ if (this.args.childless) {
124
+ query = query.where('wpTerms.termId', 'not in', (qb) => qb.selectFrom('wpTermTaxonomy').select('wpTermTaxonomy.parent').where('wpTermTaxonomy.parent', '>', 0));
125
+ }
126
+ if (this.args.search) {
127
+ const searchStr = `%${this.args.search}%`;
128
+ query = query.where((eb) => eb.or([
129
+ eb('wpTerms.name', 'like', searchStr),
130
+ eb('wpTerms.slug', 'like', searchStr)
131
+ ]));
132
+ }
133
+ if (this.args.nameLike) {
134
+ query = query.where('wpTerms.name', 'like', this.args.nameLike);
135
+ }
136
+ if (this.args.descriptionLike) {
137
+ query = query.where('wpTermTaxonomy.description', 'like', this.args.descriptionLike);
138
+ }
139
+ if (this.args.path) {
140
+ query = query.where((eb) => eb.exists(eb.selectFrom('wpTermmeta')
141
+ .select('wpTerms.termId')
142
+ .whereRef('wpTermmeta.termId', '=', 'wpTerms.termId')
143
+ .where('wpTermmeta.metaKey', '=', '_nextpress_path')
144
+ .where('wpTermmeta.metaValue', '=', this.args.path)));
145
+ }
146
+ // -- Apply ORDER BY --
147
+ const orderDirection = this.args.order === 'DESC' ? 'desc' : 'asc';
148
+ const orderBy = this.args.orderBy || 'none';
149
+ switch (orderBy) {
150
+ case 'none': break;
151
+ case 'term_id':
152
+ query = query.orderBy('wpTerms.termId', orderDirection);
153
+ break;
154
+ case 'name':
155
+ query = query.orderBy('wpTerms.name', orderDirection).orderBy('wpTerms.termId', orderDirection);
156
+ break;
157
+ case 'slug':
158
+ query = query.orderBy('wpTerms.slug', orderDirection).orderBy('wpTerms.termId', orderDirection);
159
+ break;
160
+ case 'term_group':
161
+ query = query.orderBy('wpTerms.termGroup', orderDirection).orderBy('wpTerms.termId', orderDirection);
162
+ break;
163
+ case 'description':
164
+ query = query.orderBy('wpTermTaxonomy.description', orderDirection).orderBy('wpTerms.termId', orderDirection);
165
+ break;
166
+ case 'parent':
167
+ query = query.orderBy('wpTermTaxonomy.parent', orderDirection).orderBy('wpTerms.termId', orderDirection);
168
+ break;
169
+ case 'count':
170
+ query = query.orderBy('wpTermTaxonomy.count', orderDirection).orderBy('wpTerms.termId', orderDirection);
171
+ break;
172
+ default:
173
+ query = query.orderBy('wpTerms.name', orderDirection).orderBy('wpTerms.termId', orderDirection);
174
+ break;
175
+ }
176
+ // -- Apply LIMIT & OFFSET --
177
+ const limit = (_a = this.args.number) !== null && _a !== void 0 ? _a : 0;
178
+ if (limit > 0) {
179
+ query = query.limit(limit);
180
+ }
181
+ const offsetAmount = (_b = this.args.offset) !== null && _b !== void 0 ? _b : 0;
182
+ if (offsetAmount > 0) {
183
+ query = query.offset(offsetAmount);
184
+ }
185
+ if (this.args.metaQuery) {
186
+ let dynamicQuery = query;
187
+ for (let metaQuery of this.args.metaQuery) {
188
+ const uniqueAlias = `meta_${metaQuery.as}`;
189
+ dynamicQuery = dynamicQuery.leftJoin(`wpTermmeta as ${uniqueAlias}`, (join) => join
190
+ .onRef(`${uniqueAlias}.termId`, '=', 'wpTerms.termId')
191
+ .on(`${uniqueAlias}.metaKey`, '=', metaQuery.metaKey))
192
+ .select(`${uniqueAlias}.metaValue as ${metaQuery.as}`);
193
+ }
194
+ query = dynamicQuery;
195
+ }
196
+ try {
197
+ if (isMultiple) {
198
+ return (await query
199
+ .select('wpTerms.termId')
200
+ .groupBy('wpTerms.termId')
201
+ .execute()).map((res) => res.termId);
202
+ }
203
+ else {
204
+ return (await query
205
+ .select('wpTerms.termId')
206
+ .execute()).map((res) => res.termId);
207
+ }
208
+ }
209
+ catch (error) {
210
+ throw new Error(`WPTermQuery: Cannot get terms: ${error.message}`, { cause: error });
211
+ }
212
+ }
213
+ }
@@ -0,0 +1,12 @@
1
+ import { IUser } from "../../entities/user/user.interface";
2
+ import { EntityQuery } from "../../globals/entity-loader/entity-loader";
3
+ /**
4
+ * Executes database queries to retrieve user IDs and counts based on provided arguments.
5
+ */
6
+ export declare class UserQuery implements EntityQuery<IUser> {
7
+ private args;
8
+ private userCount?;
9
+ constructor(args: UserQueryArgs);
10
+ getCount(): number | undefined;
11
+ getIds(): Promise<number[]>;
12
+ }