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,184 @@
1
+ var _a;
2
+ import { unserialize } from "php-serialize";
3
+ import { processURL } from "@/services/utilities/process-url";
4
+ import { wpdb } from "@/wpdb/wpdb";
5
+ const excerptLength = (_a = nextpressConfig.excerptLength) !== null && _a !== void 0 ? _a : 55;
6
+ /**
7
+ * Implementation of IPost entity.
8
+ */
9
+ export class Post {
10
+ constructor(ID) {
11
+ this.ID = ID;
12
+ }
13
+ /**
14
+ * Retrieves array of Post instances by IDs.
15
+ *
16
+ * @param {number[]} ids - Array of post IDs to retrieve.
17
+ * @returns {Promise<Post[]>} Promise resolving to array of Post instances.
18
+ */
19
+ static async get(ids) {
20
+ var _a;
21
+ ids = ids.filter(Boolean);
22
+ if (!ids || !ids.length)
23
+ return [];
24
+ const postsData = await wpdb
25
+ .selectFrom('wpPosts')
26
+ .where('ID', 'in', ids)
27
+ .selectAll()
28
+ .execute();
29
+ const metaData = await wpdb
30
+ .selectFrom('wpPostmeta')
31
+ .where('postId', 'in', ids)
32
+ .where('metaKey', 'in', [
33
+ '_nextpress_path',
34
+ '_thumbnail_id',
35
+ '_wp_attachment_image_alt',
36
+ '_wp_attachment_metadata',
37
+ '_menu_item_type',
38
+ '_menu_item_object_id',
39
+ '_menu_item_url',
40
+ '_menu_item_menu_item_parent'
41
+ ])
42
+ .select(['postId', 'metaKey', 'metaValue'])
43
+ .execute();
44
+ const metaByPostId = new Map();
45
+ for (const row of metaData) {
46
+ const postId = Number(row.postId);
47
+ if (!metaByPostId.has(postId)) {
48
+ metaByPostId.set(postId, new Map());
49
+ }
50
+ (_a = metaByPostId.get(postId)) === null || _a === void 0 ? void 0 : _a.set(row.metaKey || '', row.metaValue || '');
51
+ }
52
+ const postDataMap = new Map(postsData.map(post => [Number(post.ID), post]));
53
+ return ids.map(id => {
54
+ const instance = new Post(id);
55
+ instance.postData = postDataMap.get(id);
56
+ instance.metaMap = metaByPostId.get(id) || new Map();
57
+ postLoader.prime([instance.thumbnailId]);
58
+ return instance;
59
+ });
60
+ }
61
+ get path() {
62
+ var _a, _b;
63
+ return (_b = (_a = this.metaMap) === null || _a === void 0 ? void 0 : _a.get('_nextpress_path')) !== null && _b !== void 0 ? _b : '';
64
+ }
65
+ get thumbnailId() {
66
+ var _a;
67
+ const val = (_a = this.metaMap) === null || _a === void 0 ? void 0 : _a.get('_thumbnail_id');
68
+ return val ? Number(val) : 0;
69
+ }
70
+ get imageAttributes() {
71
+ var _a;
72
+ if (this._imageAttributes !== undefined)
73
+ return this._imageAttributes;
74
+ if (!this.metaMap)
75
+ return {};
76
+ const alt = (_a = this.metaMap.get('_wp_attachment_image_alt')) !== null && _a !== void 0 ? _a : '';
77
+ const rawMetadata = this.metaMap.get('_wp_attachment_metadata');
78
+ if (!rawMetadata && !alt) {
79
+ this._imageAttributes = {};
80
+ return this._imageAttributes;
81
+ }
82
+ const guid = this.guid;
83
+ const index = guid.indexOf('/wp-content');
84
+ const path = index !== -1 ? guid.slice(index) : guid;
85
+ const srcPath = `${process.env.WP_SERVICE_URL}${path}`;
86
+ try {
87
+ const metadata = unserialize(rawMetadata !== null && rawMetadata !== void 0 ? rawMetadata : 'a:0:{}');
88
+ this._imageAttributes = {
89
+ src: srcPath,
90
+ alt: alt,
91
+ height: metadata.height ? Number(metadata.height) : undefined,
92
+ width: metadata.width ? Number(metadata.width) : undefined
93
+ };
94
+ }
95
+ catch (error) {
96
+ console.warn('Error while getting post: Could not unserialize php: ', error.message);
97
+ this._imageAttributes = {};
98
+ }
99
+ return this._imageAttributes;
100
+ }
101
+ get menuItemAttributes() {
102
+ var _a, _b;
103
+ if (this._menuItemAttributes !== undefined)
104
+ return this._menuItemAttributes;
105
+ if (!this.metaMap)
106
+ return null;
107
+ const typeMeta = this.metaMap.get('_menu_item_type');
108
+ const type = ['custom', 'post_type', 'taxonomy'].includes(typeMeta !== null && typeMeta !== void 0 ? typeMeta : '')
109
+ ? typeMeta
110
+ : undefined;
111
+ let url;
112
+ let objectId;
113
+ if (type === 'custom') {
114
+ const urlMeta = this.metaMap.get('_menu_item_url');
115
+ url = urlMeta ? processURL(urlMeta) : '';
116
+ }
117
+ else {
118
+ objectId = Number(this.metaMap.get('_menu_item_object_id'));
119
+ }
120
+ const parentId = (_a = Number(this.metaMap.get('_menu_item_menu_item_parent'))) !== null && _a !== void 0 ? _a : 0;
121
+ const label = (_b = this.postTitle) !== null && _b !== void 0 ? _b : '';
122
+ return {
123
+ label,
124
+ type: type !== null && type !== void 0 ? type : 'custom',
125
+ parentId,
126
+ objectId: objectId !== null && objectId !== void 0 ? objectId : 0,
127
+ url: url !== null && url !== void 0 ? url : ''
128
+ };
129
+ }
130
+ get postExcerpt() {
131
+ var _a, _b;
132
+ if (this._postExcerpt !== undefined)
133
+ return this._postExcerpt;
134
+ const excerpt = (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postExcerpt']) !== null && _b !== void 0 ? _b : '';
135
+ if (excerpt)
136
+ return excerpt;
137
+ const postContent = this.postContent;
138
+ if (!postContent)
139
+ return '';
140
+ const plainText = postContent
141
+ .replace(/<[^>]+>/g, ' ') // Strip HTML tags
142
+ .replace(/\s+/g, ' ') // Normalize multiple spaces into a single space
143
+ .trim();
144
+ const words = plainText.split(' ');
145
+ if (words.length > (excerptLength)) {
146
+ return words.slice(0, excerptLength).join(' ') + '...';
147
+ }
148
+ this._postExcerpt = plainText;
149
+ return this._postExcerpt;
150
+ }
151
+ get commentCount() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['commentCount']) !== null && _b !== void 0 ? _b : 0; }
152
+ get commentStatus() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['commentStatus']) !== null && _b !== void 0 ? _b : 'closed'; }
153
+ get guid() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['guid']) !== null && _b !== void 0 ? _b : ''; }
154
+ get menuOrder() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['menuOrder']) !== null && _b !== void 0 ? _b : 0; }
155
+ get pinged() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['pinged']) !== null && _b !== void 0 ? _b : ''; }
156
+ get pingStatus() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['pingStatus']) !== null && _b !== void 0 ? _b : 'closed'; }
157
+ get postAuthor() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postAuthor']) !== null && _b !== void 0 ? _b : 0; }
158
+ get postContent() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postContent']) !== null && _b !== void 0 ? _b : ''; }
159
+ get postContentFiltered() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postContentFiltered']) !== null && _b !== void 0 ? _b : ''; }
160
+ get postDate() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postDate']) !== null && _b !== void 0 ? _b : new Date(); }
161
+ get postDateGmt() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postDateGmt']) !== null && _b !== void 0 ? _b : new Date(); }
162
+ get postMimeType() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postMimeType']) !== null && _b !== void 0 ? _b : ''; }
163
+ get postModified() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postModified']) !== null && _b !== void 0 ? _b : new Date(); }
164
+ get postModifiedGmt() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postModifiedGmt']) !== null && _b !== void 0 ? _b : new Date(); }
165
+ get postName() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postName']) !== null && _b !== void 0 ? _b : ''; }
166
+ get postParent() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postParent']) !== null && _b !== void 0 ? _b : 0; }
167
+ get postPassword() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postPassword']) !== null && _b !== void 0 ? _b : ''; }
168
+ get postStatus() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postStatus']) !== null && _b !== void 0 ? _b : 'draft'; }
169
+ get postTitle() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postTitle']) !== null && _b !== void 0 ? _b : ''; }
170
+ get postType() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['postType']) !== null && _b !== void 0 ? _b : 'post'; }
171
+ get toPing() { var _a, _b; return (_b = (_a = this.postData) === null || _a === void 0 ? void 0 : _a['toPing']) !== null && _b !== void 0 ? _b : ''; }
172
+ async getFields(name) {
173
+ const meta = await wpdb
174
+ .selectFrom('wpPostmeta')
175
+ .where('metaKey', 'like', `${name}%`)
176
+ .where('postId', '=', this.ID)
177
+ .select(['metaKey', 'metaValue'])
178
+ .execute();
179
+ return meta.map(m => ({
180
+ key: m.metaKey || '',
181
+ value: m.metaValue || ''
182
+ }));
183
+ }
184
+ }
@@ -0,0 +1,28 @@
1
+ import { ITerm } from "./term.interface";
2
+ /**
3
+ * Implementation of ITerm entity.
4
+ */
5
+ export declare class Term implements ITerm {
6
+ termId: number;
7
+ constructor(termId: number);
8
+ /** Raw term data from database. */
9
+ private termData?;
10
+ /** Map of term meta key-value pairs. */
11
+ private metaMap?;
12
+ /**
13
+ * Retrieves array of Term instances by IDs.
14
+ *
15
+ * @param {number[]} ids - Array of term IDs to retrieve.
16
+ * @returns {Promise<Term[]>} Promise resolving to array of Term instances.
17
+ */
18
+ static get(ids: number[]): Promise<Term[]>;
19
+ get path(): string;
20
+ get name(): string;
21
+ get slug(): string;
22
+ get termGroup(): number;
23
+ get parent(): number;
24
+ get description(): string;
25
+ get termTaxonomyId(): number;
26
+ get count(): number;
27
+ get taxonomy(): string;
28
+ }
@@ -0,0 +1,67 @@
1
+ import { wpdb } from "@/wpdb/wpdb";
2
+ /**
3
+ * Implementation of ITerm entity.
4
+ */
5
+ export class Term {
6
+ constructor(termId) {
7
+ this.termId = termId;
8
+ }
9
+ /**
10
+ * Retrieves array of Term instances by IDs.
11
+ *
12
+ * @param {number[]} ids - Array of term IDs to retrieve.
13
+ * @returns {Promise<Term[]>} Promise resolving to array of Term instances.
14
+ */
15
+ static async get(ids) {
16
+ var _a;
17
+ ids = ids.filter(Boolean);
18
+ if (!ids || !ids.length)
19
+ return [];
20
+ const combinedData = await wpdb
21
+ .selectFrom('wpTerms as term')
22
+ .innerJoin('wpTermTaxonomy as taxonomy', 'term.termId', 'taxonomy.termId')
23
+ .where('term.termId', 'in', ids)
24
+ .select([
25
+ 'term.termId as termId',
26
+ 'term.name as name',
27
+ 'term.slug as slug',
28
+ 'term.termGroup as termGroup',
29
+ 'taxonomy.termTaxonomyId as termTaxonomyId',
30
+ 'taxonomy.taxonomy as taxonomy',
31
+ 'taxonomy.description as description',
32
+ 'taxonomy.parent as parent',
33
+ 'taxonomy.count as count'
34
+ ])
35
+ .execute();
36
+ const metaData = await wpdb
37
+ .selectFrom('wpTermmeta')
38
+ .where('termId', 'in', ids)
39
+ .where('metaKey', '=', '_nextpress_path')
40
+ .select(['termId', 'metaKey', 'metaValue'])
41
+ .execute();
42
+ const metaByTermId = new Map();
43
+ for (const row of metaData) {
44
+ const termId = Number(row.termId);
45
+ if (!metaByTermId.has(termId)) {
46
+ metaByTermId.set(termId, new Map());
47
+ }
48
+ (_a = metaByTermId.get(termId)) === null || _a === void 0 ? void 0 : _a.set(row.metaKey || '', row.metaValue || '');
49
+ }
50
+ const combinedDataMap = new Map(combinedData.map(row => [Number(row.termId), row]));
51
+ return ids.map(id => {
52
+ const instance = new Term(id);
53
+ instance.termData = combinedDataMap.get(id);
54
+ instance.metaMap = metaByTermId.get(id) || new Map();
55
+ return instance;
56
+ });
57
+ }
58
+ get path() { var _a, _b; return (_b = (_a = this.metaMap) === null || _a === void 0 ? void 0 : _a.get('_nextpress_path')) !== null && _b !== void 0 ? _b : ''; }
59
+ get name() { var _a, _b; return (_b = (_a = this.termData) === null || _a === void 0 ? void 0 : _a['name']) !== null && _b !== void 0 ? _b : ''; }
60
+ get slug() { var _a, _b; return (_b = (_a = this.termData) === null || _a === void 0 ? void 0 : _a['slug']) !== null && _b !== void 0 ? _b : ''; }
61
+ get termGroup() { var _a; return ((_a = this.termData) === null || _a === void 0 ? void 0 : _a['termGroup']) ? Number(this.termData['termGroup']) : 0; }
62
+ get parent() { var _a; return ((_a = this.termData) === null || _a === void 0 ? void 0 : _a['parent']) ? Number(this.termData['parent']) : 0; }
63
+ get description() { var _a, _b; return (_b = (_a = this.termData) === null || _a === void 0 ? void 0 : _a['description']) !== null && _b !== void 0 ? _b : ''; }
64
+ get termTaxonomyId() { var _a; return ((_a = this.termData) === null || _a === void 0 ? void 0 : _a['termTaxonomyId']) ? Number(this.termData['termTaxonomyId']) : 0; }
65
+ get count() { var _a; return ((_a = this.termData) === null || _a === void 0 ? void 0 : _a['count']) ? Number(this.termData['count']) : 0; }
66
+ get taxonomy() { var _a, _b; return (_b = (_a = this.termData) === null || _a === void 0 ? void 0 : _a['taxonomy']) !== null && _b !== void 0 ? _b : ''; }
67
+ }
@@ -0,0 +1,27 @@
1
+ import { IUser } from "./user.interface";
2
+ export declare class User implements IUser {
3
+ ID: number;
4
+ constructor(ID: number);
5
+ /** Raw user data from database. */
6
+ private userData?;
7
+ /** Map of user meta key-value pairs. */
8
+ private metaMap?;
9
+ /**
10
+ * Retrieves array of User instances by IDs.
11
+ *
12
+ * @param {number[]} ids - Array of user IDs to retrieve.
13
+ * @returns {Promise<User[]>} Promise resolving to array of User instances.
14
+ */
15
+ static get(ids: number[]): Promise<User[]>;
16
+ get roles(): string[];
17
+ get showAdminBar(): boolean;
18
+ get displayName(): string;
19
+ get userActivationKey(): string;
20
+ get userEmail(): string;
21
+ get userLogin(): string;
22
+ get userNicename(): string;
23
+ get userPass(): string;
24
+ get userRegistered(): Date;
25
+ get userStatus(): number;
26
+ get userUrl(): string;
27
+ }
@@ -0,0 +1,74 @@
1
+ import { unserialize } from "php-serialize";
2
+ import { wpdb } from "@/wpdb/wpdb";
3
+ export class User {
4
+ constructor(ID) {
5
+ this.ID = ID;
6
+ }
7
+ /**
8
+ * Retrieves array of User instances by IDs.
9
+ *
10
+ * @param {number[]} ids - Array of user IDs to retrieve.
11
+ * @returns {Promise<User[]>} Promise resolving to array of User instances.
12
+ */
13
+ static async get(ids) {
14
+ var _a;
15
+ ids = ids.filter(Boolean);
16
+ if (!ids || !ids.length)
17
+ return [];
18
+ const usersData = await wpdb
19
+ .selectFrom('wpUsers')
20
+ .where('ID', 'in', ids)
21
+ .selectAll()
22
+ .execute();
23
+ const metaData = await wpdb
24
+ .selectFrom('wpUsermeta')
25
+ .where('userId', 'in', ids)
26
+ .where('metaKey', 'in', [
27
+ 'wp_capabilities',
28
+ 'show_admin_bar_front'
29
+ ])
30
+ .select(['userId', 'metaKey', 'metaValue'])
31
+ .execute();
32
+ const metaByUserId = new Map();
33
+ for (const row of metaData) {
34
+ const userId = Number(row.userId);
35
+ if (!metaByUserId.has(userId)) {
36
+ metaByUserId.set(userId, new Map());
37
+ }
38
+ (_a = metaByUserId.get(userId)) === null || _a === void 0 ? void 0 : _a.set(row.metaKey || '', row.metaValue || '');
39
+ }
40
+ const userDataMap = new Map(usersData.map(user => [Number(user.ID), user]));
41
+ return ids.map(id => {
42
+ const instance = new User(id);
43
+ instance.userData = userDataMap.get(id);
44
+ instance.metaMap = metaByUserId.get(id) || new Map();
45
+ return instance;
46
+ });
47
+ }
48
+ get roles() {
49
+ var _a;
50
+ const rawCapabilities = (_a = this.metaMap) === null || _a === void 0 ? void 0 : _a.get('wp_capabilities');
51
+ if (!rawCapabilities)
52
+ return [];
53
+ try {
54
+ return Object.keys(unserialize(rawCapabilities));
55
+ }
56
+ catch (error) {
57
+ console.warn('Error while getting user: Could not unserialize php: ', error.message);
58
+ return [];
59
+ }
60
+ }
61
+ get showAdminBar() {
62
+ var _a;
63
+ return ((_a = this.metaMap) === null || _a === void 0 ? void 0 : _a.get('show_admin_bar_front')) === 'true';
64
+ }
65
+ get displayName() { var _a, _b; return (_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a['displayName']) !== null && _b !== void 0 ? _b : ''; }
66
+ get userActivationKey() { var _a, _b; return (_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a['userActivationKey']) !== null && _b !== void 0 ? _b : ''; }
67
+ get userEmail() { var _a, _b; return (_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a['userEmail']) !== null && _b !== void 0 ? _b : ''; }
68
+ get userLogin() { var _a, _b; return (_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a['userLogin']) !== null && _b !== void 0 ? _b : ''; }
69
+ get userNicename() { var _a, _b; return (_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a['userNicename']) !== null && _b !== void 0 ? _b : ''; }
70
+ get userPass() { var _a, _b; return (_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a['userPass']) !== null && _b !== void 0 ? _b : ''; }
71
+ get userRegistered() { var _a, _b; return (_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a['userRegistered']) !== null && _b !== void 0 ? _b : new Date(); }
72
+ get userStatus() { var _a; return ((_a = this.userData) === null || _a === void 0 ? void 0 : _a['userStatus']) ? Number(this.userData['userStatus']) : 0; }
73
+ get userUrl() { var _a, _b; return (_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a['userUrl']) !== null && _b !== void 0 ? _b : ''; }
74
+ }
@@ -0,0 +1,65 @@
1
+ import { EntityLoader, EntityQuery } from "./entity-loader";
2
+ /**
3
+ * Constructor type for entity queries.
4
+ */
5
+ type QueryConstructor<TArgs> = new (args: TArgs) => EntityQuery<TArgs>;
6
+ export interface ILoaderStorage<TEntity> {
7
+ loadQueue: Set<number>;
8
+ entityCache: Map<number, TEntity>;
9
+ promisedEntities: Map<number, Promise<TEntity[]>>;
10
+ }
11
+ export declare abstract class EntityLoaderBase<TEntity, TArgs> implements EntityLoader<TEntity, TArgs> {
12
+ /** Query class used to fetch entity IDs. */
13
+ protected abstract queryClass: QueryConstructor<TArgs>;
14
+ /**
15
+ * Fetches entities from the database by ID.
16
+ *
17
+ * @param {number[]} ids Array of entity IDs.
18
+ *
19
+ * @returns {Promise<TEntity[]>} Array of fetched entities.
20
+ * @throws {Error} If database fetch fails.
21
+ */
22
+ protected abstract fetchFromDatabase(ids: number[]): Promise<TEntity[]>;
23
+ /**
24
+ * Gets the ID of an entity.
25
+ *
26
+ * @param {TEntity} entity The entity.
27
+ *
28
+ * @returns {number} The entity ID.
29
+ */
30
+ protected abstract getEntityId(entity: TEntity): number;
31
+ /**
32
+ * Retrieves the local state for the loader from the global cache.
33
+ *
34
+ * @returns {ILoaderStorage<TEntity>} The loader storage.
35
+ */
36
+ private getLocalState;
37
+ /**
38
+ * Adds IDs to the loading queue.
39
+ *
40
+ * @param {number[]} ids Array of IDs to prime.
41
+ */
42
+ prime(ids: number[]): void;
43
+ /**
44
+ * Finds entity IDs matching the arguments and queues them for loading.
45
+ *
46
+ * @param {TArgs} args Query arguments.
47
+ *
48
+ * @returns {Promise<{ ids: number[]; count: number }>} Matching IDs and total count.
49
+ * @throws {Error} If query execution fails.
50
+ */
51
+ findAndPrime(args: TArgs): Promise<{
52
+ ids: number[];
53
+ count: number;
54
+ }>;
55
+ /**
56
+ * Retrieves entities by ID.
57
+ *
58
+ * @param {number[]} ids Array of entity IDs.
59
+ *
60
+ * @returns {Promise<TEntity[]>} Array of entities.
61
+ * @throws {Error} If entity fetching fails.
62
+ */
63
+ get(ids: number[]): Promise<TEntity[]>;
64
+ }
65
+ export {};
@@ -1,50 +1,13 @@
1
- import { EntityLoader, EntityQuery } from "./entity-loader";
2
1
  import { queriedObjectState } from "../globals";
3
-
4
- /**
5
- * Constructor type for entity queries.
6
- */
7
- type QueryConstructor<TArgs> = new (args: TArgs) => EntityQuery<TArgs>;
8
-
9
- export interface ILoaderStorage<TEntity> {
10
- loadQueue: Set<number>;
11
- entityCache: Map<number, TEntity>;
12
- promisedEntities: Map<number, Promise<TEntity[]>>;
13
- }
14
-
15
- export abstract class EntityLoaderBase<TEntity, TArgs> implements EntityLoader<TEntity, TArgs>
16
- {
17
- /** Query class used to fetch entity IDs. */
18
- protected abstract queryClass: QueryConstructor<TArgs>;
19
-
20
- /**
21
- * Fetches entities from the database by ID.
22
- *
23
- * @param {number[]} ids Array of entity IDs.
24
- *
25
- * @returns {Promise<TEntity[]>} Array of fetched entities.
26
- * @throws {Error} If database fetch fails.
27
- */
28
- protected abstract fetchFromDatabase(ids: number[]): Promise<TEntity[]>;
29
-
30
- /**
31
- * Gets the ID of an entity.
32
- *
33
- * @param {TEntity} entity The entity.
34
- *
35
- * @returns {number} The entity ID.
36
- */
37
- protected abstract getEntityId(entity: TEntity): number;
38
-
2
+ export class EntityLoaderBase {
39
3
  /**
40
4
  * Retrieves the local state for the loader from the global cache.
41
5
  *
42
6
  * @returns {ILoaderStorage<TEntity>} The loader storage.
43
7
  */
44
- private getLocalState(): ILoaderStorage<TEntity> {
8
+ getLocalState() {
45
9
  const state = queriedObjectState();
46
10
  const loaderKey = `__loader_${this.constructor.name}`;
47
-
48
11
  if (!state.loaderStates[loaderKey]) {
49
12
  state.loaderStates[loaderKey] = {
50
13
  loadQueue: new Set(),
@@ -54,13 +17,12 @@ export abstract class EntityLoaderBase<TEntity, TArgs> implements EntityLoader<T
54
17
  }
55
18
  return state.loaderStates[loaderKey];
56
19
  }
57
-
58
20
  /**
59
21
  * Adds IDs to the loading queue.
60
22
  *
61
23
  * @param {number[]} ids Array of IDs to prime.
62
24
  */
63
- public prime(ids: number[]): void {
25
+ prime(ids) {
64
26
  const state = this.getLocalState();
65
27
  for (const id of ids) {
66
28
  if (state.loadQueue.has(id) || state.entityCache.has(id) || state.promisedEntities.has(id)) {
@@ -69,7 +31,6 @@ export abstract class EntityLoaderBase<TEntity, TArgs> implements EntityLoader<T
69
31
  state.loadQueue.add(id);
70
32
  }
71
33
  }
72
-
73
34
  /**
74
35
  * Finds entity IDs matching the arguments and queues them for loading.
75
36
  *
@@ -78,17 +39,14 @@ export abstract class EntityLoaderBase<TEntity, TArgs> implements EntityLoader<T
78
39
  * @returns {Promise<{ ids: number[]; count: number }>} Matching IDs and total count.
79
40
  * @throws {Error} If query execution fails.
80
41
  */
81
- public async findAndPrime(args: TArgs): Promise<{ ids: number[]; count: number }> {
42
+ async findAndPrime(args) {
43
+ var _a;
82
44
  const query = new this.queryClass(args);
83
-
84
45
  const ids = await query.getIds();
85
- const count = query.getCount() ?? ids.length;
86
-
46
+ const count = (_a = query.getCount()) !== null && _a !== void 0 ? _a : ids.length;
87
47
  this.get(ids);
88
-
89
48
  return { ids, count };
90
49
  }
91
-
92
50
  /**
93
51
  * Retrieves entities by ID.
94
52
  *
@@ -97,42 +55,30 @@ export abstract class EntityLoaderBase<TEntity, TArgs> implements EntityLoader<T
97
55
  * @returns {Promise<TEntity[]>} Array of entities.
98
56
  * @throws {Error} If entity fetching fails.
99
57
  */
100
- public async get(ids: number[]): Promise<TEntity[]> {
58
+ async get(ids) {
101
59
  const state = this.getLocalState();
102
-
103
60
  const newIds = ids.filter(id => !state.entityCache.has(id) && !state.promisedEntities.has(id));
104
-
105
61
  if (newIds.length > 0) {
106
62
  this.prime(newIds);
107
63
  }
108
-
109
64
  if (state.loadQueue.size > 0) {
110
65
  const queue = Array.from(state.loadQueue);
111
66
  state.loadQueue.clear();
112
-
113
67
  const fetchPromise = this.fetchFromDatabase(queue).then(queuedEntities => {
114
68
  queuedEntities.forEach(entity => state.entityCache.set(this.getEntityId(entity), entity));
115
69
  queue.forEach(id => state.promisedEntities.delete(id));
116
70
  return queuedEntities;
117
71
  });
118
-
119
72
  queue.forEach(id => {
120
73
  state.promisedEntities.set(id, fetchPromise);
121
74
  });
122
75
  }
123
-
124
- const activePromises = Array.from(
125
- new Set(
126
- ids
127
- .map(id => state.promisedEntities.get(id))
128
- .filter((p): p is Promise<TEntity[]> => !!p)
129
- )
130
- );
131
-
76
+ const activePromises = Array.from(new Set(ids
77
+ .map(id => state.promisedEntities.get(id))
78
+ .filter((p) => !!p)));
132
79
  if (activePromises.length > 0) {
133
80
  await Promise.all(activePromises);
134
81
  }
135
-
136
82
  return ids.flatMap(id => {
137
83
  const entity = state.entityCache.get(id);
138
84
  return entity ? [entity] : [];
@@ -0,0 +1,15 @@
1
+ import { IOption } from "../../entities/option/option.interface";
2
+ import { OptionQueryArgs } from "../../repository/optionquery/option-query-args";
3
+ import { EntityLoader } from "./entity-loader";
4
+ declare global {
5
+ /** Global instance of the OptionLoader. */
6
+ var optionLoader: EntityLoader<IOption, OptionQueryArgs>;
7
+ /**
8
+ * Retrieves an option value by name.
9
+ *
10
+ * @param {string} name The option name.
11
+ *
12
+ * @returns {Promise<string | undefined>} The option value or undefined.
13
+ */
14
+ var getOption: (name: string) => Promise<string | undefined>;
15
+ }
@@ -0,0 +1,31 @@
1
+ import { OptionQuery } from "@/repository/optionquery/option-query";
2
+ import { Option } from "../../entities/option/option";
3
+ import { EntityLoaderBase } from "./entity-loader-base";
4
+ class OptionLoader extends EntityLoaderBase {
5
+ constructor() {
6
+ super();
7
+ this.queryClass = OptionQuery;
8
+ }
9
+ static instance() {
10
+ if (!this._instance) {
11
+ this._instance = new OptionLoader();
12
+ }
13
+ return this._instance;
14
+ }
15
+ async fetchFromDatabase(ids) {
16
+ return await Option.get(ids);
17
+ }
18
+ getEntityId(option) {
19
+ return option.optionId;
20
+ }
21
+ }
22
+ globalThis.optionLoader = OptionLoader.instance();
23
+ globalThis.getOption = async (name) => {
24
+ var _a;
25
+ const foundOptions = await optionLoader.findAndPrime({
26
+ column: 'optionName',
27
+ operand: '=',
28
+ value: name
29
+ });
30
+ return (_a = (await optionLoader.get(foundOptions.ids))[0]) === null || _a === void 0 ? void 0 : _a.optionValue;
31
+ };
@@ -0,0 +1,21 @@
1
+ import { IPost } from "../../entities/post/post.interface";
2
+ import { EntityLoader } from "./entity-loader";
3
+ declare global {
4
+ /** Global instance of the PostLoader. */
5
+ var postLoader: EntityLoader<IPost, PostQueryArgs>;
6
+ /**
7
+ * Retrieves posts by their IDs.
8
+ *
9
+ * @param {number[]} ids Array of post IDs.
10
+ * @returns {Promise<IPost[]>} Array of posts.
11
+ */
12
+ var getPosts: (ids: number[]) => Promise<IPost[]>;
13
+ /**
14
+ * Retrieves a single post by ID.
15
+ *
16
+ * @param {number} id The post ID.
17
+ * @returns {Promise<IPost | undefined>} The post or undefined.
18
+ */
19
+ var getPost: (id: number) => Promise<IPost | undefined>;
20
+ }
21
+ export {};