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.
- package/dist/acf-functions/core/acf-builder.d.ts +50 -0
- package/{lib/acf-functions/core/acf-builder.ts → dist/acf-functions/core/acf-builder.js} +17 -41
- package/dist/acf-functions/core/acf-component-autoloader.d.ts +11 -0
- package/{lib/acf-functions/core/acf-component-autoloader.ts → dist/acf-functions/core/acf-component-autoloader.js} +7 -13
- package/dist/acf-functions/core/acf-field-group-autoloader.d.ts +9 -0
- package/{lib/acf-functions/core/acf-field-group-autoloader.ts → dist/acf-functions/core/acf-field-group-autoloader.js} +4 -9
- package/dist/acf-functions/field-props.d.ts +196 -0
- package/dist/acf-functions/field-props.js +1 -0
- package/dist/acf-functions/services/define-field-group.d.ts +8 -0
- package/{lib/acf-functions/services/define-field-group.ts → dist/acf-functions/services/define-field-group.js} +1 -1
- package/dist/acf-functions/services/define-layout.d.ts +8 -0
- package/{lib/acf-functions/services/define-layout.ts → dist/acf-functions/services/define-layout.js} +1 -1
- package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +2 -0
- package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +18 -0
- package/dist/acf-functions/services/map-fields/map-fields.d.ts +18 -0
- package/{lib/acf-functions/services/map-fields/map-fields.ts → dist/acf-functions/services/map-fields/map-fields.js} +88 -124
- package/dist/entities/option/option.d.ts +19 -0
- package/{lib/entities/option/option.ts → dist/entities/option/option.js} +13 -20
- package/dist/entities/post/post.d.ts +50 -0
- package/dist/entities/post/post.js +184 -0
- package/dist/entities/term/term.d.ts +28 -0
- package/dist/entities/term/term.js +67 -0
- package/dist/entities/user/user.d.ts +27 -0
- package/dist/entities/user/user.js +74 -0
- package/dist/globals/entity-loader/entity-loader-base.d.ts +65 -0
- package/{lib/globals/entity-loader/entity-loader-base.ts → dist/globals/entity-loader/entity-loader-base.js} +10 -64
- package/dist/globals/entity-loader/option-loader.d.ts +15 -0
- package/dist/globals/entity-loader/option-loader.js +31 -0
- package/dist/globals/entity-loader/post-loader.d.ts +21 -0
- package/dist/globals/entity-loader/post-loader.js +28 -0
- package/dist/globals/entity-loader/term-loader.d.ts +21 -0
- package/dist/globals/entity-loader/term-loader.js +28 -0
- package/dist/globals/entity-loader/user-loader.d.ts +21 -0
- package/dist/globals/entity-loader/user-loader.js +28 -0
- package/dist/globals/get-field/get-field.d.ts +17 -0
- package/dist/globals/get-field/get-field.js +44 -0
- package/dist/globals/globals.d.ts +18 -0
- package/{lib/globals/globals.ts → dist/globals/globals.js} +3 -8
- package/dist/globals/nextpress-config/nextpress-config.d.ts +4 -0
- package/{lib/globals/nextpress-config/nextpress-config.ts → dist/globals/nextpress-config/nextpress-config.js} +0 -5
- package/dist/globals/queried-object/queried-object.d.ts +62 -0
- package/dist/globals/queried-object/queried-object.js +56 -0
- package/dist/repository/optionquery/option-query.d.ts +12 -0
- package/dist/repository/optionquery/option-query.js +20 -0
- package/dist/repository/postquery/post-query.d.ts +12 -0
- package/dist/repository/postquery/post-query.js +272 -0
- package/dist/repository/termquery/term-query.d.ts +11 -0
- package/dist/repository/termquery/term-query.js +213 -0
- package/dist/repository/userquery/user-query.d.ts +12 -0
- package/{lib/repository/userquery/user-query.ts → dist/repository/userquery/user-query.js} +75 -91
- package/dist/router/helpers.d.ts +14 -0
- package/{lib/router/helpers.ts → dist/router/helpers.js} +4 -4
- package/dist/router/nextpress-layout.d.ts +11 -0
- package/{lib/router/nextpress-layout.tsx → dist/router/nextpress-layout.js} +6 -23
- package/dist/router/nextpress-proxy.d.ts +8 -0
- package/{lib/router/nextpress-proxy.ts → dist/router/nextpress-proxy.js} +3 -15
- package/dist/router/nextpress-static-params.d.ts +9 -0
- package/{lib/router/nextpress-static-params.ts → dist/router/nextpress-static-params.js} +5 -17
- package/dist/router/router.d.ts +23 -0
- package/{lib/router/router.tsx → dist/router/router.js} +21 -29
- package/dist/router/routes/api/api-get-admin-bar.d.ts +8 -0
- package/{lib/router/routes/api/api-get-admin-bar.ts → dist/router/routes/api/api-get-admin-bar.js} +6 -8
- package/dist/router/routes/api/api-get-draft-mode.d.ts +8 -0
- package/{lib/router/routes/api/api-get-draft-mode.ts → dist/router/routes/api/api-get-draft-mode.js} +6 -15
- package/dist/router/routes/api/api-get-field-groups.d.ts +7 -0
- package/{lib/router/routes/api/api-get-field-groups.ts → dist/router/routes/api/api-get-field-groups.js} +6 -11
- package/dist/router/routes/api/api-post-revalidate.d.ts +7 -0
- package/{lib/router/routes/api/api-post-revalidate.ts → dist/router/routes/api/api-post-revalidate.js} +4 -6
- package/dist/router/routes/api/helpers.d.ts +8 -0
- package/{lib/router/routes/api/helpers.ts → dist/router/routes/api/helpers.js} +3 -4
- package/dist/router/routes/author-archive.d.ts +25 -0
- package/{lib/router/routes/author-archive.tsx → dist/router/routes/author-archive.js} +11 -37
- package/dist/router/routes/not-found-page.d.ts +15 -0
- package/{lib/router/routes/not-found-page.tsx → dist/router/routes/not-found-page.js} +3 -5
- package/dist/router/routes/post-index-page.d.ts +25 -0
- package/dist/router/routes/post-index-page.js +33 -0
- package/dist/router/routes/singular-page.d.ts +29 -0
- package/dist/router/routes/singular-page.js +51 -0
- package/dist/router/routes/site-front-page.d.ts +27 -0
- package/dist/router/routes/site-front-page.js +26 -0
- package/dist/router/routes/term-archive.d.ts +29 -0
- package/{lib/router/routes/term-archive.tsx → dist/router/routes/term-archive.js} +17 -45
- package/dist/services/get-menu.d.ts +13 -0
- package/{lib/services/get-menu.ts → dist/services/get-menu.js} +32 -56
- package/dist/services/get-theme-mods.d.ts +7 -0
- package/{lib/services/get-theme-mods.ts → dist/services/get-theme-mods.js} +4 -6
- package/dist/services/metadata/get-blogname.d.ts +6 -0
- package/{lib/services/metadata/get-blogname.ts → dist/services/metadata/get-blogname.js} +2 -2
- package/dist/services/metadata/get-favicon-url.d.ts +6 -0
- package/{lib/services/metadata/get-favicon-url.ts → dist/services/metadata/get-favicon-url.js} +4 -5
- package/dist/services/metadata/get-language-attribute.d.ts +6 -0
- package/{lib/services/metadata/get-language-attribute.ts → dist/services/metadata/get-language-attribute.js} +1 -1
- package/{lib/services/services.ts → dist/services/services.d.ts} +1 -5
- package/dist/services/services.js +3 -0
- package/dist/services/utilities/capitalise-first-letter.d.ts +7 -0
- package/{lib/services/utilities/capitalise-first-letter.ts → dist/services/utilities/capitalise-first-letter.js} +3 -2
- package/dist/services/utilities/esc-html.d.ts +7 -0
- package/{lib/services/utilities/esc-html.ts → dist/services/utilities/esc-html.js} +1 -3
- package/dist/services/utilities/get-date-time-formatter.d.ts +6 -0
- package/{lib/services/utilities/get-date-time-formatter.ts → dist/services/utilities/get-date-time-formatter.js} +6 -16
- package/dist/services/utilities/index.js +1 -0
- package/dist/services/utilities/kses-post.d.ts +7 -0
- package/{lib/services/utilities/kses-post.ts → dist/services/utilities/kses-post.js} +1 -2
- package/dist/services/utilities/process-url.d.ts +7 -0
- package/{lib/services/utilities/process-url.ts → dist/services/utilities/process-url.js} +3 -4
- package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +9 -0
- package/{lib/template-heirarchy/_autoloader/template-autoloader.ts → dist/template-heirarchy/_autoloader/template-autoloader.js} +9 -18
- package/dist/template-heirarchy/archive/archive.d.ts +16 -0
- package/{lib/template-heirarchy/archive/archive.tsx → dist/template-heirarchy/archive/archive.js} +7 -10
- package/dist/template-heirarchy/archive/author.d.ts +16 -0
- package/{lib/template-heirarchy/archive/author.tsx → dist/template-heirarchy/archive/author.js} +7 -10
- package/dist/template-heirarchy/archive/category.d.ts +16 -0
- package/{lib/template-heirarchy/archive/category.tsx → dist/template-heirarchy/archive/category.js} +7 -11
- package/dist/template-heirarchy/archive/posttypearchive.d.ts +24 -0
- package/{lib/template-heirarchy/archive/posttypearchive.tsx → dist/template-heirarchy/archive/posttypearchive.js} +7 -10
- package/dist/template-heirarchy/archive/tag.d.ts +16 -0
- package/{lib/template-heirarchy/archive/tag.tsx → dist/template-heirarchy/archive/tag.js} +7 -12
- package/dist/template-heirarchy/archive/taxonomy.d.ts +16 -0
- package/{lib/template-heirarchy/archive/taxonomy.tsx → dist/template-heirarchy/archive/taxonomy.js} +7 -10
- package/dist/template-heirarchy/home/home.d.ts +16 -0
- package/{lib/template-heirarchy/home/home.tsx → dist/template-heirarchy/home/home.js} +7 -10
- package/dist/template-heirarchy/index.d.ts +17 -0
- package/{lib/template-heirarchy/index.tsx → dist/template-heirarchy/index.js} +5 -9
- package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +16 -0
- package/{lib/template-heirarchy/not-found.tsx/not-found.tsx → dist/template-heirarchy/not-found.tsx/not-found.js} +7 -10
- package/dist/template-heirarchy/page/page.d.ts +16 -0
- package/{lib/template-heirarchy/page/page.tsx → dist/template-heirarchy/page/page.js} +7 -10
- package/dist/template-heirarchy/page/posttype.d.ts +24 -0
- package/{lib/template-heirarchy/page/posttype.tsx → dist/template-heirarchy/page/posttype.js} +7 -11
- package/dist/template-heirarchy/page/single.d.ts +16 -0
- package/{lib/template-heirarchy/page/single.tsx → dist/template-heirarchy/page/single.js} +7 -10
- package/dist/template-heirarchy/page/singular.d.ts +16 -0
- package/{lib/template-heirarchy/page/singular.tsx → dist/template-heirarchy/page/singular.js} +7 -10
- package/dist/ui/render-attachment-image.d.ts +12 -0
- package/dist/ui/render-attachment-image.js +24 -0
- package/{lib/ui/render-components.tsx → dist/ui/render-components.d.ts} +4 -7
- package/dist/ui/render-components.js +7 -0
- package/dist/ui/render-the-admin-bar.d.ts +8 -0
- package/dist/ui/render-the-admin-bar.js +36 -0
- package/dist/ui/render-the-logo.d.ts +10 -0
- package/dist/ui/render-the-logo.js +16 -0
- package/dist/wpdb/wpdb.d.ts +3 -0
- package/{lib/wpdb/wpdb.ts → dist/wpdb/wpdb.js} +5 -9
- package/package.json +7 -3
- package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +0 -20
- package/lib/acf-functions/types/acf-field-group.d.ts +0 -118
- package/lib/acf-functions/types/acf-field.d.ts +0 -2851
- package/lib/acf-functions/types/acf-layout.d.ts +0 -20
- package/lib/acf-functions/types/acf-values.d.ts +0 -4
- package/lib/acf-functions/types/components/field-props.d.ts +0 -189
- package/lib/acf-functions/types/components/nextpress-component.d.ts +0 -11
- package/lib/ambient.d.ts +0 -15
- package/lib/entities/common.d.ts +0 -30
- package/lib/entities/option/option.interface.d.ts +0 -8
- package/lib/entities/post/post.interface.d.ts +0 -72
- package/lib/entities/post/post.ts +0 -209
- package/lib/entities/term/term.interface.d.ts +0 -8
- package/lib/entities/term/term.ts +0 -82
- package/lib/entities/user/user.interface.d.ts +0 -10
- package/lib/entities/user/user.ts +0 -86
- package/lib/globals/entity-loader/entity-loader.d.ts +0 -50
- package/lib/globals/entity-loader/option-loader.ts +0 -56
- package/lib/globals/entity-loader/post-loader.ts +0 -59
- package/lib/globals/entity-loader/term-loader.ts +0 -59
- package/lib/globals/entity-loader/user-loader.ts +0 -60
- package/lib/globals/get-field/get-field.ts +0 -75
- package/lib/globals/nextpress-config/nextpress-config.interface.d.ts +0 -18
- package/lib/globals/queried-object/queried-object.ts +0 -124
- package/lib/repository/optionquery/option-query-args.d.ts +0 -21
- package/lib/repository/optionquery/option-query.ts +0 -29
- package/lib/repository/postquery/post-query-args.d.ts +0 -108
- package/lib/repository/postquery/post-query.ts +0 -281
- package/lib/repository/termquery/term-query-args.d.ts +0 -61
- package/lib/repository/termquery/term-query.ts +0 -243
- package/lib/repository/userquery/user-query-args.d.ts +0 -75
- package/lib/router/routes/post-index-page.tsx +0 -58
- package/lib/router/routes/singular-page.tsx +0 -78
- package/lib/router/routes/site-front-page.tsx +0 -51
- package/lib/router/types.d.ts +0 -9
- package/lib/ui/render-attachment-image.tsx +0 -29
- package/lib/ui/render-the-admin-bar.tsx +0 -79
- package/lib/ui/render-the-logo.tsx +0 -24
- package/lib/wpdb/wpdb.interface.d.ts +0 -171
- /package/{lib/services/utilities/index.ts → dist/services/utilities/index.d.ts} +0 -0
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { unserialize } from "php-serialize";
|
|
2
|
-
import { IUser } from "./user.interface";
|
|
3
|
-
import { wpdb } from "@/wpdb/wpdb";
|
|
4
|
-
|
|
5
|
-
export class User implements IUser {
|
|
6
|
-
constructor(
|
|
7
|
-
public ID: number
|
|
8
|
-
) {}
|
|
9
|
-
|
|
10
|
-
/** Raw user data from database. */
|
|
11
|
-
private userData?: Record<string, any>;
|
|
12
|
-
/** Map of user meta key-value pairs. */
|
|
13
|
-
private metaMap?: Map<string, string>;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Retrieves array of User instances by IDs.
|
|
17
|
-
*
|
|
18
|
-
* @param {number[]} ids - Array of user IDs to retrieve.
|
|
19
|
-
* @returns {Promise<User[]>} Promise resolving to array of User instances.
|
|
20
|
-
*/
|
|
21
|
-
static async get(ids: number[]): Promise<User[]> {
|
|
22
|
-
ids = ids.filter(Boolean);
|
|
23
|
-
if (!ids || !ids.length) return [];
|
|
24
|
-
|
|
25
|
-
const usersData = await wpdb
|
|
26
|
-
.selectFrom('wpUsers')
|
|
27
|
-
.where('ID', 'in', ids)
|
|
28
|
-
.selectAll()
|
|
29
|
-
.execute();
|
|
30
|
-
|
|
31
|
-
const metaData = await wpdb
|
|
32
|
-
.selectFrom('wpUsermeta')
|
|
33
|
-
.where('userId', 'in', ids)
|
|
34
|
-
.where('metaKey', 'in', [
|
|
35
|
-
'wp_capabilities',
|
|
36
|
-
'show_admin_bar_front'
|
|
37
|
-
])
|
|
38
|
-
.select(['userId', 'metaKey', 'metaValue'])
|
|
39
|
-
.execute();
|
|
40
|
-
|
|
41
|
-
const metaByUserId = new Map<number, Map<string, string>>();
|
|
42
|
-
for (const row of metaData) {
|
|
43
|
-
const userId = Number(row.userId);
|
|
44
|
-
if (!metaByUserId.has(userId)) {
|
|
45
|
-
metaByUserId.set(userId, new Map());
|
|
46
|
-
}
|
|
47
|
-
metaByUserId.get(userId)?.set(row.metaKey || '', row.metaValue || '');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const userDataMap = new Map(usersData.map(user => [Number(user.ID), user]));
|
|
51
|
-
|
|
52
|
-
return ids.map(id => {
|
|
53
|
-
const instance = new User(id);
|
|
54
|
-
|
|
55
|
-
instance.userData = userDataMap.get(id);
|
|
56
|
-
instance.metaMap = metaByUserId.get(id) || new Map<string, string>();
|
|
57
|
-
|
|
58
|
-
return instance;
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get roles(): string[] {
|
|
63
|
-
const rawCapabilities = this.metaMap?.get('wp_capabilities');
|
|
64
|
-
if (!rawCapabilities) return [];
|
|
65
|
-
try {
|
|
66
|
-
return Object.keys(unserialize(rawCapabilities));
|
|
67
|
-
} catch (error: any) {
|
|
68
|
-
console.warn('Error while getting user: Could not unserialize php: ', error.message);
|
|
69
|
-
return [];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get showAdminBar(): boolean {
|
|
74
|
-
return this.metaMap?.get('show_admin_bar_front') === 'true';
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get displayName(): string { return this.userData?.['displayName'] ?? ''; }
|
|
78
|
-
get userActivationKey(): string { return this.userData?.['userActivationKey'] ?? ''; }
|
|
79
|
-
get userEmail(): string { return this.userData?.['userEmail'] ?? ''; }
|
|
80
|
-
get userLogin(): string { return this.userData?.['userLogin'] ?? ''; }
|
|
81
|
-
get userNicename(): string { return this.userData?.['userNicename'] ?? ''; }
|
|
82
|
-
get userPass(): string { return this.userData?.['userPass'] ?? ''; }
|
|
83
|
-
get userRegistered(): Date { return this.userData?.['userRegistered'] ?? new Date(); }
|
|
84
|
-
get userStatus(): number { return this.userData?.['userStatus'] ? Number(this.userData['userStatus']) : 0; }
|
|
85
|
-
get userUrl(): string { return this.userData?.['userUrl'] ?? ''; }
|
|
86
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Defines the contract for an entity loader.
|
|
3
|
-
*
|
|
4
|
-
* @template EntityT The type of entity being loaded.
|
|
5
|
-
* @template QueryArgsT The type of arguments used for querying the entity.
|
|
6
|
-
*/
|
|
7
|
-
export interface EntityLoader<EntityT, QueryArgsT> {
|
|
8
|
-
/**
|
|
9
|
-
* Queues entity IDs for loading.
|
|
10
|
-
*
|
|
11
|
-
* @param {number[]} ids Array of entity IDs.
|
|
12
|
-
*/
|
|
13
|
-
prime: (ids: number[]) => void;
|
|
14
|
-
/**
|
|
15
|
-
* Finds entity IDs based on query arguments and queues them for loading.
|
|
16
|
-
*
|
|
17
|
-
* @param {QueryArgsT} args Query arguments.
|
|
18
|
-
* @returns {Promise<{ids: number[], count: number}>} Array of found IDs and the total count.
|
|
19
|
-
* @throws {Error} If the query fails.
|
|
20
|
-
*/
|
|
21
|
-
findAndPrime: (args: QueryArgsT) => Promise<{ids: number[], count: number}>;
|
|
22
|
-
/**
|
|
23
|
-
* Retrieves entities by their IDs.
|
|
24
|
-
*
|
|
25
|
-
* @param {number[]} ids Array of entity IDs.
|
|
26
|
-
* @returns {Promise<EntityT[]>} Array of entities.
|
|
27
|
-
* @throws {Error} If retrieval fails.
|
|
28
|
-
*/
|
|
29
|
-
get: (ids: number[]) => Promise<EntityT[]>;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Defines the contract for an entity query.
|
|
34
|
-
*
|
|
35
|
-
* @template TArgs The type of query arguments.
|
|
36
|
-
*/
|
|
37
|
-
export interface EntityQuery<TArgs> {
|
|
38
|
-
/**
|
|
39
|
-
* Executes the query and returns the matching entity IDs.
|
|
40
|
-
*
|
|
41
|
-
* @returns {Promise<number[]>} Array of entity IDs.
|
|
42
|
-
* @throws {Error} If the query fails.
|
|
43
|
-
*/
|
|
44
|
-
getIds(): Promise<number[]>;
|
|
45
|
-
/**
|
|
46
|
-
* Retrieves the total count of entities matching the query.
|
|
47
|
-
* @returns {number | undefined} Total count, or undefined if not computed.
|
|
48
|
-
*/
|
|
49
|
-
getCount(): number | undefined;
|
|
50
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { OptionQuery } from "@/repository/optionquery/option-query";
|
|
2
|
-
import { Option } from "../../entities/option/option";
|
|
3
|
-
import { IOption } from "../../entities/option/option.interface";
|
|
4
|
-
import { OptionQueryArgs } from "../../repository/optionquery/option-query-args";
|
|
5
|
-
import { EntityLoader } from "./entity-loader";
|
|
6
|
-
import { EntityLoaderBase } from "./entity-loader-base";
|
|
7
|
-
|
|
8
|
-
class OptionLoader extends EntityLoaderBase<IOption, OptionQueryArgs> {
|
|
9
|
-
private static _instance: OptionLoader;
|
|
10
|
-
|
|
11
|
-
protected queryClass = OptionQuery;
|
|
12
|
-
|
|
13
|
-
private constructor() {
|
|
14
|
-
super();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public static instance(): OptionLoader {
|
|
18
|
-
if (!this._instance) {
|
|
19
|
-
this._instance = new OptionLoader();
|
|
20
|
-
}
|
|
21
|
-
return this._instance;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected async fetchFromDatabase(ids: number[]): Promise<IOption[]> {
|
|
25
|
-
return await Option.get(ids);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
protected getEntityId(option: IOption): number {
|
|
29
|
-
return option.optionId;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
declare global {
|
|
34
|
-
/** Global instance of the OptionLoader. */
|
|
35
|
-
var optionLoader: EntityLoader<IOption, OptionQueryArgs>
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Retrieves an option value by name.
|
|
39
|
-
*
|
|
40
|
-
* @param {string} name The option name.
|
|
41
|
-
*
|
|
42
|
-
* @returns {Promise<string | undefined>} The option value or undefined.
|
|
43
|
-
*/
|
|
44
|
-
var getOption: (name: string) => Promise<string | undefined>;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
globalThis.optionLoader = OptionLoader.instance();
|
|
48
|
-
globalThis.getOption = async (name) => {
|
|
49
|
-
const foundOptions = await optionLoader.findAndPrime({
|
|
50
|
-
column: 'optionName',
|
|
51
|
-
operand: '=',
|
|
52
|
-
value: name
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
return (await optionLoader.get(foundOptions.ids))[0]?.optionValue;
|
|
56
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Post } from "@/entities/post/post";
|
|
2
|
-
import { IPost } from "../../entities/post/post.interface";
|
|
3
|
-
import { EntityLoader } from "./entity-loader";
|
|
4
|
-
import { EntityLoaderBase } from "./entity-loader-base";
|
|
5
|
-
import { PostQuery } from "@/repository/postquery/post-query";
|
|
6
|
-
|
|
7
|
-
class PostLoader extends EntityLoaderBase<IPost, PostQueryArgs> {
|
|
8
|
-
private static _instance: PostLoader;
|
|
9
|
-
|
|
10
|
-
protected queryClass = PostQuery;
|
|
11
|
-
|
|
12
|
-
private constructor() {
|
|
13
|
-
super();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static instance(): PostLoader {
|
|
17
|
-
if (!this._instance) {
|
|
18
|
-
this._instance = new PostLoader();
|
|
19
|
-
}
|
|
20
|
-
return this._instance;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected async fetchFromDatabase(ids: number[]): Promise<IPost[]> {
|
|
24
|
-
return await Post.get(ids);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected getEntityId(post: IPost): number {
|
|
28
|
-
return post.ID;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare global {
|
|
33
|
-
/** Global instance of the PostLoader. */
|
|
34
|
-
var postLoader: EntityLoader<IPost, PostQueryArgs>
|
|
35
|
-
/**
|
|
36
|
-
* Retrieves posts by their IDs.
|
|
37
|
-
*
|
|
38
|
-
* @param {number[]} ids Array of post IDs.
|
|
39
|
-
* @returns {Promise<IPost[]>} Array of posts.
|
|
40
|
-
*/
|
|
41
|
-
var getPosts: (ids: number[]) => Promise<IPost[]>
|
|
42
|
-
/**
|
|
43
|
-
* Retrieves a single post by ID.
|
|
44
|
-
*
|
|
45
|
-
* @param {number} id The post ID.
|
|
46
|
-
* @returns {Promise<IPost | undefined>} The post or undefined.
|
|
47
|
-
*/
|
|
48
|
-
var getPost: (id: number) => Promise<IPost | undefined>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
globalThis.postLoader = PostLoader.instance();
|
|
52
|
-
globalThis.getPosts = async (ids) => {
|
|
53
|
-
return await postLoader.get(ids);
|
|
54
|
-
}
|
|
55
|
-
globalThis.getPost = async (id) => {
|
|
56
|
-
return (await postLoader.get([id]))[0];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { Term } from "@/entities/term/term";
|
|
2
|
-
import { ITerm } from "../../entities/term/term.interface";
|
|
3
|
-
import { EntityLoader } from "./entity-loader";
|
|
4
|
-
import { EntityLoaderBase } from "./entity-loader-base";
|
|
5
|
-
import { TermQuery } from "@/repository/termquery/term-query";
|
|
6
|
-
|
|
7
|
-
class TermLoader extends EntityLoaderBase<ITerm, TermQueryArgs> {
|
|
8
|
-
private static _instance: TermLoader;
|
|
9
|
-
|
|
10
|
-
protected queryClass = TermQuery;
|
|
11
|
-
|
|
12
|
-
private constructor() {
|
|
13
|
-
super();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static instance(): TermLoader {
|
|
17
|
-
if (!this._instance) {
|
|
18
|
-
this._instance = new TermLoader();
|
|
19
|
-
}
|
|
20
|
-
return this._instance;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected async fetchFromDatabase(ids: number[]): Promise<ITerm[]> {
|
|
24
|
-
return await Term.get(ids);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected getEntityId(term: ITerm): number {
|
|
28
|
-
return term.termId;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare global {
|
|
33
|
-
/** Global instance of the TermLoader. */
|
|
34
|
-
var termLoader: EntityLoader<ITerm, TermQueryArgs>
|
|
35
|
-
/**
|
|
36
|
-
* Retrieves terms by their IDs.
|
|
37
|
-
*
|
|
38
|
-
* @param {number[]} ids Array of term IDs.
|
|
39
|
-
* @returns {Promise<ITerm[]>} Array of terms.
|
|
40
|
-
*/
|
|
41
|
-
var getTerms: (ids: number[]) => Promise<ITerm[]>
|
|
42
|
-
/**
|
|
43
|
-
* Retrieves a single term by ID.
|
|
44
|
-
*
|
|
45
|
-
* @param {number} id The term ID.
|
|
46
|
-
* @returns {Promise<ITerm | undefined>} The term or undefined.
|
|
47
|
-
*/
|
|
48
|
-
var getTerm: (id: number) => Promise<ITerm | undefined>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
globalThis.termLoader = TermLoader.instance();
|
|
52
|
-
globalThis.getTerms = async (ids) => {
|
|
53
|
-
return await termLoader.get(ids);
|
|
54
|
-
}
|
|
55
|
-
globalThis.getTerm = async (id) => {
|
|
56
|
-
return (await termLoader.get([id]))[0];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export {};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { User } from "@/entities/user/user";
|
|
2
|
-
import { IUser } from "../../entities/user/user.interface";
|
|
3
|
-
import { EntityLoader } from "./entity-loader";
|
|
4
|
-
import { EntityLoaderBase } from "./entity-loader-base";
|
|
5
|
-
import { UserQuery } from "@/repository/userquery/user-query";
|
|
6
|
-
|
|
7
|
-
class UserLoader extends EntityLoaderBase<IUser, UserQueryArgs> {
|
|
8
|
-
private static _instance: UserLoader;
|
|
9
|
-
|
|
10
|
-
protected queryClass = UserQuery;
|
|
11
|
-
|
|
12
|
-
private constructor() {
|
|
13
|
-
super();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public static instance(): UserLoader {
|
|
17
|
-
if (!this._instance) {
|
|
18
|
-
this._instance = new UserLoader();
|
|
19
|
-
}
|
|
20
|
-
return this._instance;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
protected async fetchFromDatabase(ids: number[]): Promise<IUser[]> {
|
|
24
|
-
return await User.get(ids);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected getEntityId(user: IUser): number {
|
|
28
|
-
return user.ID;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
declare global {
|
|
33
|
-
/** Global instance of the UserLoader. */
|
|
34
|
-
var userLoader: EntityLoader<IUser, UserQueryArgs>
|
|
35
|
-
/**
|
|
36
|
-
* Retrieves users by their IDs.
|
|
37
|
-
*
|
|
38
|
-
* @param {number[]} ids Array of user IDs.
|
|
39
|
-
* @returns {Promise<IUser[]>} Array of users.
|
|
40
|
-
*/
|
|
41
|
-
var getUsers: (ids: number[]) => Promise<IUser[]>
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Retrieves a single user by ID.
|
|
45
|
-
*
|
|
46
|
-
* @param {number} id The user ID.
|
|
47
|
-
* @returns {Promise<IUser | undefined>} The user or undefined.
|
|
48
|
-
*/
|
|
49
|
-
var getUser: (id: number) => Promise<IUser | undefined>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
globalThis.userLoader = UserLoader.instance();
|
|
53
|
-
globalThis.getUsers = async (ids) => {
|
|
54
|
-
return await userLoader.get(ids);
|
|
55
|
-
}
|
|
56
|
-
globalThis.getUser = async (id) => {
|
|
57
|
-
return (await userLoader.get([id]))[0];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { mapField } from "../../acf-functions/services/map-fields/map-fields";
|
|
2
|
-
import { IFieldLocation } from "../../entities/common";
|
|
3
|
-
import { FieldProps } from "../../acf-functions/types/components/field-props";
|
|
4
|
-
|
|
5
|
-
/** Specifies location to retrieve fields from. */
|
|
6
|
-
type Location = IFieldLocation | 'options';
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
/**
|
|
10
|
-
* Retrieves, parses, and maps an Advanced Custom Fields (ACF) value to its corresponding component properties.
|
|
11
|
-
*
|
|
12
|
-
* @param {T} fieldGroup The configuration object defining the ACF field group and its schema.
|
|
13
|
-
* @param {K} selector The key name of the field to retrieve.
|
|
14
|
-
* @param {Location} [location] The database entity or context from which to load the field data. Accepts an `IFieldLocation` object or the string `'options'`. Defaults to the current queried object if omitted.
|
|
15
|
-
*
|
|
16
|
-
* @returns {Promise<FieldProps<T>[K]>} A promise resolving to the mapped field properties.
|
|
17
|
-
*/
|
|
18
|
-
var getField: <
|
|
19
|
-
T extends NextpressFieldGroup,
|
|
20
|
-
K extends keyof FieldProps<T> & string
|
|
21
|
-
>(
|
|
22
|
-
fieldGroup: T,
|
|
23
|
-
selector: K,
|
|
24
|
-
location?: Location
|
|
25
|
-
) => Promise<FieldProps<T>[K]>;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
globalThis.getField = async (fieldGroup, selector, location) => {
|
|
29
|
-
if (!location) {
|
|
30
|
-
switch(queriedObject.objectType) {
|
|
31
|
-
case 'post':
|
|
32
|
-
location = await getThePost();
|
|
33
|
-
break;
|
|
34
|
-
// TODO: Add support for Term and User
|
|
35
|
-
// case 'term':
|
|
36
|
-
// location = await getTheTerm();
|
|
37
|
-
// break;
|
|
38
|
-
// case 'user':
|
|
39
|
-
// location = await getTheUser();
|
|
40
|
-
// break;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (!location) return [];
|
|
44
|
-
|
|
45
|
-
const values = await (async () => {
|
|
46
|
-
if (location === 'options') {
|
|
47
|
-
const prefix = 'options_';
|
|
48
|
-
|
|
49
|
-
const foundOptions = await optionLoader.findAndPrime({
|
|
50
|
-
column: 'optionName',
|
|
51
|
-
operand: 'like',
|
|
52
|
-
value: `${prefix}%`
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const options = await optionLoader.get(foundOptions.ids);
|
|
56
|
-
|
|
57
|
-
return options.map(option => ({
|
|
58
|
-
key: option.optionName.slice(prefix.length),
|
|
59
|
-
value: option.optionValue
|
|
60
|
-
}))
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return await location.getFields(selector);
|
|
64
|
-
})() ?? [];
|
|
65
|
-
|
|
66
|
-
const valueMap: Map<string, string> = values.reduce((map, value) => {
|
|
67
|
-
map.set(value.key, value.value);
|
|
68
|
-
return map;
|
|
69
|
-
}, new Map());
|
|
70
|
-
|
|
71
|
-
const field = fieldGroup.fields.find(field => field.name === selector);
|
|
72
|
-
if (!field) return;
|
|
73
|
-
|
|
74
|
-
return mapField(field, valueMap) as any;
|
|
75
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
type NextpressConfig = {
|
|
2
|
-
/** Custom taxonomies used to categorize and group content (like categories or tags). Expects the taxonomy's URL prefix, so tag instead of post_tag */
|
|
3
|
-
readonly publicTaxonomies?: string[],
|
|
4
|
-
|
|
5
|
-
/** Custom post types registered for public consumption (like posts, pages, or portfolio). */
|
|
6
|
-
readonly publicPostTypes?: string[],
|
|
7
|
-
|
|
8
|
-
/** Post types that should display archive pages on the frontend. */
|
|
9
|
-
readonly archivedPostTypes?: string[],
|
|
10
|
-
|
|
11
|
-
/** The word/character count limit for automatically generated post teasers. */
|
|
12
|
-
readonly excerptLength?: number,
|
|
13
|
-
|
|
14
|
-
/** Database option keys (from wp_options) to fetch early for performance optimization. */
|
|
15
|
-
readonly preLoadOptions?: string[],
|
|
16
|
-
} & {
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
};
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { IPost } from "../../entities/post/post.interface";
|
|
2
|
-
import { ITerm } from "../../entities/term/term.interface";
|
|
3
|
-
import { IUser } from "../../entities/user/user.interface";
|
|
4
|
-
import { queriedObjectState } from "../globals";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Represents the state of the queried object.
|
|
8
|
-
*/
|
|
9
|
-
interface IQueriedObject {
|
|
10
|
-
/** Type of the queried object. */
|
|
11
|
-
objectType: 'post' | 'term' | 'user' | null,
|
|
12
|
-
/** Array of post IDs associated with the query. */
|
|
13
|
-
posts: number[],
|
|
14
|
-
/** Current page number. */
|
|
15
|
-
page: number,
|
|
16
|
-
/** Total page count. */
|
|
17
|
-
pageCount: number,
|
|
18
|
-
/** ID of the main queried term. */
|
|
19
|
-
mainTerm?: number,
|
|
20
|
-
/** Array of term IDs associated with the query. */
|
|
21
|
-
terms: number[],
|
|
22
|
-
/** ID of the queried user. */
|
|
23
|
-
user?: number,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Creates a blank queried object state.
|
|
28
|
-
*
|
|
29
|
-
* @returns {IQueriedObject} Blank state object.
|
|
30
|
-
*/
|
|
31
|
-
const createBlankState = (): IQueriedObject => ({
|
|
32
|
-
objectType: null,
|
|
33
|
-
posts: [],
|
|
34
|
-
page: 1,
|
|
35
|
-
pageCount: 1,
|
|
36
|
-
terms: [],
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
declare global {
|
|
40
|
-
/** The current queried object. */
|
|
41
|
-
var queriedObject: IQueriedObject
|
|
42
|
-
/**
|
|
43
|
-
* Retrieves the first post from the queried object.
|
|
44
|
-
* @returns {Promise<IPost | undefined>} The post.
|
|
45
|
-
*/
|
|
46
|
-
var getThePost: () => Promise<IPost | undefined>
|
|
47
|
-
/**
|
|
48
|
-
* Retrieves all posts from the queried object.
|
|
49
|
-
* @returns {Promise<IPost[]>} Array of posts.
|
|
50
|
-
*/
|
|
51
|
-
var getThePosts: () => Promise<IPost[]>
|
|
52
|
-
/**
|
|
53
|
-
* Retrieves the current page number.
|
|
54
|
-
* @returns {number} Page number.
|
|
55
|
-
*/
|
|
56
|
-
var getThePage: () => number
|
|
57
|
-
/**
|
|
58
|
-
* Retrieves the total page count.
|
|
59
|
-
* @returns {number} Page count.
|
|
60
|
-
*/
|
|
61
|
-
var getThePageCount: () => number
|
|
62
|
-
/**
|
|
63
|
-
* Retrieves the main term from the queried object.
|
|
64
|
-
* @returns {Promise<ITerm | undefined>} The term.
|
|
65
|
-
*/
|
|
66
|
-
var getTheTerm: () => Promise<ITerm | undefined>
|
|
67
|
-
/**
|
|
68
|
-
* Retrieves all terms from the queried object.
|
|
69
|
-
* @returns {Promise<ITerm[]>} Array of terms.
|
|
70
|
-
*/
|
|
71
|
-
var getTheTerms: () => Promise<ITerm[]>
|
|
72
|
-
/**
|
|
73
|
-
* Retrieves the user from the queried object.
|
|
74
|
-
* @returns {Promise<IUser | undefined>} The user.
|
|
75
|
-
*/
|
|
76
|
-
var getTheUser: () => Promise<IUser | undefined>
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
Object.defineProperty(globalThis, 'queriedObject', {
|
|
80
|
-
configurable: true,
|
|
81
|
-
enumerable: true,
|
|
82
|
-
get() {
|
|
83
|
-
const state = queriedObjectState();
|
|
84
|
-
return state.currentState || createBlankState();
|
|
85
|
-
},
|
|
86
|
-
set(newData: IQueriedObject) {
|
|
87
|
-
const store = queriedObjectState();
|
|
88
|
-
|
|
89
|
-
if (newData.posts) postLoader.prime(newData.posts);
|
|
90
|
-
if (newData.mainTerm) termLoader.prime([newData.mainTerm]);
|
|
91
|
-
if (newData.terms) termLoader.prime(newData.terms);
|
|
92
|
-
if (newData.user) userLoader.prime([newData.user]);
|
|
93
|
-
|
|
94
|
-
if (!store.currentState) store.currentState = {};
|
|
95
|
-
Object.assign(store.currentState, newData);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
globalThis.getThePost = async () => {
|
|
100
|
-
return (await postLoader.get(globalThis.queriedObject.posts))[0];
|
|
101
|
-
};
|
|
102
|
-
globalThis.getThePosts = () => {
|
|
103
|
-
return postLoader.get(globalThis.queriedObject.posts);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
globalThis.getThePage = () => globalThis.queriedObject.page;
|
|
107
|
-
|
|
108
|
-
globalThis.getThePageCount = () => globalThis.queriedObject.pageCount;
|
|
109
|
-
|
|
110
|
-
globalThis.getTheTerm = async () => {
|
|
111
|
-
if (!globalThis.queriedObject.mainTerm) return;
|
|
112
|
-
return (await termLoader.get([globalThis.queriedObject.mainTerm]))[0];
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
globalThis.getTheTerms = () => {
|
|
116
|
-
return termLoader.get(globalThis.queriedObject.terms);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
globalThis.getTheUser = async () => {
|
|
120
|
-
if (!globalThis.queriedObject.user) return;
|
|
121
|
-
return (await userLoader.get([globalThis.queriedObject.user]))[0];
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { DB, WpOption } from "../../wpdb/wpdb.interface";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Defines the arguments for querying options.
|
|
5
|
-
*/
|
|
6
|
-
interface OptionQueryArgs {
|
|
7
|
-
/**
|
|
8
|
-
* Database column reference to query against.
|
|
9
|
-
*/
|
|
10
|
-
column: ReferenceExpression<DB, WpOption>;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Comparison operator for the query.
|
|
14
|
-
*/
|
|
15
|
-
operand?: ComparisonOperatorExpression;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Value or array of values to compare.
|
|
19
|
-
*/
|
|
20
|
-
value: string | string[];
|
|
21
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ComparisonOperatorExpression } from "kysely";
|
|
2
|
-
import { EntityQuery } from "../../globals/entity-loader/entity-loader";
|
|
3
|
-
import { OptionQueryArgs } from "./option-query-args";
|
|
4
|
-
import { IOption } from "../../entities/option/option.interface";
|
|
5
|
-
import { wpdb } from "@/wpdb/wpdb";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Executes database queries to retrieve option IDs (or keys) based on provided arguments.
|
|
9
|
-
*/
|
|
10
|
-
export class OptionQuery implements EntityQuery<IOption>
|
|
11
|
-
{
|
|
12
|
-
constructor(
|
|
13
|
-
private args: OptionQueryArgs
|
|
14
|
-
) {}
|
|
15
|
-
|
|
16
|
-
public getCount(): number | undefined {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public async getIds(): Promise<number[]> {
|
|
21
|
-
const operand: ComparisonOperatorExpression = this.args.operand || '=';
|
|
22
|
-
|
|
23
|
-
return (await wpdb
|
|
24
|
-
.selectFrom('wpOptions')
|
|
25
|
-
.select('optionId')
|
|
26
|
-
.where(this.args.column, operand, this.args.value)
|
|
27
|
-
.execute()).map(option => option.optionId);
|
|
28
|
-
}
|
|
29
|
-
}
|