nextpress-core 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/install.js +27 -0
- package/{dist/acf-functions/core/acf-builder.js → lib/acf-functions/core/acf-builder.ts} +45 -17
- package/{dist/acf-functions/core/acf-component-autoloader.js → lib/acf-functions/core/acf-component-autoloader.ts} +13 -7
- package/{dist/acf-functions/core/acf-field-group-autoloader.js → lib/acf-functions/core/acf-field-group-autoloader.ts} +11 -5
- package/{dist/acf-functions/services/define-field-group.d.ts → lib/acf-functions/services/define-field-group.ts} +4 -1
- package/{dist/acf-functions/services/define-layout.d.ts → lib/acf-functions/services/define-layout.ts} +4 -1
- package/lib/acf-functions/services/map-fields/helpers/map-choice-object.ts +20 -0
- package/{dist/acf-functions/services/map-fields/map-fields.js → lib/acf-functions/services/map-fields/map-fields.ts} +128 -89
- package/{dist/acf-functions/types/acf-field-group.d.ts → lib/acf-functions/types/acf-field-group.ts} +49 -28
- package/lib/acf-functions/types/acf-field.ts +2853 -0
- package/lib/acf-functions/types/acf-layout.ts +22 -0
- package/lib/acf-functions/types/components/field-props.ts +189 -0
- package/{dist/acf-functions/types/components/nextpress-component.d.ts → lib/acf-functions/types/components/nextpress-component.ts} +4 -3
- package/lib/ambient.d.ts +16 -0
- package/{dist/entities/common.d.ts → lib/entities/common.ts} +6 -4
- package/{dist/entities/option/option.interface.d.ts → lib/entities/option/option.interface.ts} +3 -3
- package/{dist/entities/option/option.js → lib/entities/option/option.ts} +21 -14
- package/{dist/entities/post/post.interface.d.ts → lib/entities/post/post.interface.ts} +26 -21
- package/lib/entities/post/post.ts +209 -0
- package/{dist/entities/term/term.interface.d.ts → lib/entities/term/term.interface.ts} +3 -3
- package/lib/entities/term/term.ts +82 -0
- package/{dist/entities/user/user.interface.d.ts → lib/entities/user/user.interface.ts} +2 -1
- package/lib/entities/user/user.ts +86 -0
- package/{dist/globals/entity-loader/entity-loader-base.js → lib/globals/entity-loader/entity-loader-base.ts} +64 -10
- package/{dist/globals/entity-loader/entity-loader.interface.d.ts → lib/globals/entity-loader/entity-loader.ts} +2 -4
- package/lib/globals/entity-loader/option-loader.ts +56 -0
- package/lib/globals/entity-loader/post-loader.ts +60 -0
- package/lib/globals/entity-loader/term-loader.ts +60 -0
- package/lib/globals/entity-loader/user-loader.ts +61 -0
- package/lib/globals/get-field/get-field.ts +76 -0
- package/{dist/globals/globals.js → lib/globals/globals.ts} +8 -3
- package/{dist/globals/nextpress-config/nextpress-config.interface.d.ts → lib/globals/nextpress-config/nextpress-config.interface.ts} +10 -6
- package/lib/globals/nextpress-config/nextpress-config.ts +8 -0
- package/lib/globals/queried-object/queried-object.ts +124 -0
- package/{dist/repository/optionquery/option-query-args.d.ts → lib/repository/optionquery/option-query-args.ts} +5 -2
- package/lib/repository/optionquery/option-query.ts +29 -0
- package/{dist/repository/postquery/post-query-args.d.ts → lib/repository/postquery/post-query-args.ts} +10 -6
- package/lib/repository/postquery/post-query.ts +282 -0
- package/{dist/repository/termquery/term-query-args.d.ts → lib/repository/termquery/term-query-args.ts} +16 -6
- package/lib/repository/termquery/term-query.ts +244 -0
- package/{dist/repository/userquery/user-query-args.d.ts → lib/repository/userquery/user-query-args.ts} +19 -7
- package/{dist/repository/userquery/user-query.js → lib/repository/userquery/user-query.ts} +93 -76
- package/{dist/router/helpers.js → lib/router/helpers.ts} +4 -4
- package/{dist/router/nextpress-layout.js → lib/router/nextpress-layout.tsx} +28 -9
- package/{dist/router/routes/not-found-page.js → lib/router/nextpress-not-found-route.tsx} +7 -5
- package/{dist/router/nextpress-proxy.js → lib/router/nextpress-proxy.ts} +15 -3
- package/{dist/router/nextpress-static-params.js → lib/router/nextpress-static-params.ts} +17 -5
- package/{dist/router/router.js → lib/router/router.tsx} +29 -22
- package/{dist/router/routes/api/api-get-admin-bar.js → lib/router/routes/api/api-get-admin-bar.ts} +8 -6
- package/{dist/router/routes/api/api-get-draft-mode.js → lib/router/routes/api/api-get-draft-mode.ts} +15 -6
- package/{dist/router/routes/api/api-get-field-groups.js → lib/router/routes/api/api-get-field-groups.ts} +13 -8
- package/{dist/router/routes/api/api-post-revalidate.js → lib/router/routes/api/api-post-revalidate.ts} +6 -4
- package/{dist/router/routes/api/helpers.js → lib/router/routes/api/helpers.ts} +4 -3
- package/lib/router/routes/author-archive.tsx +75 -0
- package/lib/router/routes/post-index-page.tsx +58 -0
- package/lib/router/routes/singular-page.tsx +78 -0
- package/lib/router/routes/site-front-page.tsx +51 -0
- package/lib/router/routes/term-archive.tsx +93 -0
- package/{dist/router/types.d.ts → lib/router/types.ts} +4 -2
- package/{dist/services/get-menu.js → lib/services/get-menu.ts} +56 -32
- package/{dist/services/get-theme-mods.js → lib/services/get-theme-mods.ts} +6 -4
- package/{dist/services/metadata/get-blogname.js → lib/services/metadata/get-blogname.ts} +2 -2
- package/{dist/services/metadata/get-favicon-url.js → lib/services/metadata/get-favicon-url.ts} +5 -4
- package/{dist/services/metadata/get-language-attribute.js → lib/services/metadata/get-language-attribute.ts} +1 -1
- package/{dist/services/utilities/capitalise-first-letter.js → lib/services/utilities/capitalise-first-letter.ts} +2 -3
- package/{dist/services/utilities/esc-html.js → lib/services/utilities/esc-html.ts} +3 -1
- package/{dist/services/utilities/get-date-time-formatter.js → lib/services/utilities/get-date-time-formatter.ts} +16 -6
- package/{dist/services/utilities/kses-post.js → lib/services/utilities/kses-post.ts} +2 -1
- package/{dist/services/utilities/process-url.js → lib/services/utilities/process-url.ts} +4 -3
- package/{dist/template-heirarchy/_autoloader/template-autoloader.js → lib/template-heirarchy/_autoloader/template-autoloader.ts} +18 -9
- package/{dist/template-heirarchy/archive/archive.js → lib/template-heirarchy/archive/archive.tsx} +10 -7
- package/{dist/template-heirarchy/archive/author.js → lib/template-heirarchy/archive/author.tsx} +10 -7
- package/{dist/template-heirarchy/archive/category.js → lib/template-heirarchy/archive/category.tsx} +11 -7
- package/{dist/template-heirarchy/archive/posttypearchive.js → lib/template-heirarchy/archive/posttypearchive.tsx} +11 -8
- package/{dist/template-heirarchy/archive/tag.js → lib/template-heirarchy/archive/tag.tsx} +12 -7
- package/{dist/template-heirarchy/archive/taxonomy.js → lib/template-heirarchy/archive/taxonomy.tsx} +10 -7
- package/{dist/template-heirarchy/home/home.js → lib/template-heirarchy/home/home.tsx} +10 -7
- package/{dist/template-heirarchy/index.js → lib/template-heirarchy/index.tsx} +9 -5
- package/{dist/template-heirarchy/not-found.tsx/not-found.js → lib/template-heirarchy/not-found.tsx/not-found.tsx} +10 -7
- package/{dist/template-heirarchy/page/page.js → lib/template-heirarchy/page/page.tsx} +10 -7
- package/{dist/template-heirarchy/page/posttype.js → lib/template-heirarchy/page/posttype.tsx} +12 -8
- package/{dist/template-heirarchy/page/single.js → lib/template-heirarchy/page/single.tsx} +10 -7
- package/{dist/template-heirarchy/page/singular.js → lib/template-heirarchy/page/singular.tsx} +10 -7
- package/lib/ui/render-attachment-image.tsx +28 -0
- package/lib/ui/render-components.tsx +12 -0
- package/lib/ui/render-the-admin-bar.tsx +79 -0
- package/lib/ui/render-the-logo.tsx +24 -0
- package/{dist/wpdb/wpdb.interface.d.ts → lib/wpdb/wpdb.interface.ts} +20 -1
- package/{dist/wpdb/wpdb.js → lib/wpdb/wpdb.ts} +9 -5
- package/package.json +8 -15
- package/dist/acf-functions/core/acf-builder.d.ts +0 -51
- package/dist/acf-functions/core/acf-component-autoloader.d.ts +0 -11
- package/dist/acf-functions/core/acf-field-group-autoloader.d.ts +0 -10
- package/dist/acf-functions/field-props.d.ts +0 -196
- package/dist/acf-functions/field-props.js +0 -1
- package/dist/acf-functions/services/define-field-group.js +0 -10
- package/dist/acf-functions/services/define-layout.js +0 -10
- package/dist/acf-functions/services/map-fields/helpers/map-choice-object.d.ts +0 -2
- package/dist/acf-functions/services/map-fields/helpers/map-choice-object.js +0 -18
- package/dist/acf-functions/services/map-fields/map-fields.d.ts +0 -21
- package/dist/acf-functions/types/acf-field-group.js +0 -1
- package/dist/acf-functions/types/acf-field.d.ts +0 -2813
- package/dist/acf-functions/types/acf-field.js +0 -1
- package/dist/acf-functions/types/acf-layout.d.ts +0 -19
- package/dist/acf-functions/types/acf-layout.js +0 -1
- package/dist/acf-functions/types/acf-values.js +0 -1
- package/dist/acf-functions/types/components/field-props.d.ts +0 -196
- package/dist/acf-functions/types/components/field-props.js +0 -1
- package/dist/acf-functions/types/components/nextpress-component.js +0 -1
- package/dist/entities/common.js +0 -1
- package/dist/entities/option/option.d.ts +0 -19
- package/dist/entities/option/option.interface.js +0 -2
- package/dist/entities/post/post.d.ts +0 -50
- package/dist/entities/post/post.interface.js +0 -2
- package/dist/entities/post/post.js +0 -184
- package/dist/entities/term/term.d.ts +0 -28
- package/dist/entities/term/term.interface.js +0 -1
- package/dist/entities/term/term.js +0 -67
- package/dist/entities/user/user.d.ts +0 -27
- package/dist/entities/user/user.interface.js +0 -1
- package/dist/entities/user/user.js +0 -74
- package/dist/globals/entity-loader/entity-loader-base.d.ts +0 -65
- package/dist/globals/entity-loader/entity-loader.interface.js +0 -1
- package/dist/globals/entity-loader/option-loader.d.ts +0 -15
- package/dist/globals/entity-loader/option-loader.js +0 -31
- package/dist/globals/entity-loader/post-loader.d.ts +0 -21
- package/dist/globals/entity-loader/post-loader.js +0 -28
- package/dist/globals/entity-loader/term-loader.d.ts +0 -21
- package/dist/globals/entity-loader/term-loader.js +0 -28
- package/dist/globals/entity-loader/user-loader.d.ts +0 -21
- package/dist/globals/entity-loader/user-loader.js +0 -28
- package/dist/globals/get-field/get-field.d.ts +0 -18
- package/dist/globals/get-field/get-field.js +0 -44
- package/dist/globals/globals.d.ts +0 -18
- package/dist/globals/nextpress-config/nextpress-config.d.ts +0 -4
- package/dist/globals/nextpress-config/nextpress-config.interface.js +0 -1
- package/dist/globals/nextpress-config/nextpress-config.js +0 -2
- package/dist/globals/queried-object/queried-object.d.ts +0 -62
- package/dist/globals/queried-object/queried-object.js +0 -56
- package/dist/repository/optionquery/option-query-args.js +0 -1
- package/dist/repository/optionquery/option-query.d.ts +0 -12
- package/dist/repository/optionquery/option-query.js +0 -20
- package/dist/repository/postquery/post-query-args.js +0 -1
- package/dist/repository/postquery/post-query.d.ts +0 -12
- package/dist/repository/postquery/post-query.js +0 -272
- package/dist/repository/termquery/term-query-args.js +0 -1
- package/dist/repository/termquery/term-query.d.ts +0 -11
- package/dist/repository/termquery/term-query.js +0 -213
- package/dist/repository/userquery/user-query-args.js +0 -1
- package/dist/repository/userquery/user-query.d.ts +0 -12
- package/dist/router/helpers.d.ts +0 -14
- package/dist/router/nextpress-layout.d.ts +0 -11
- package/dist/router/nextpress-proxy.d.ts +0 -8
- package/dist/router/nextpress-static-params.d.ts +0 -9
- package/dist/router/router.d.ts +0 -23
- package/dist/router/routes/api/api-get-admin-bar.d.ts +0 -8
- package/dist/router/routes/api/api-get-draft-mode.d.ts +0 -8
- package/dist/router/routes/api/api-get-field-groups.d.ts +0 -7
- package/dist/router/routes/api/api-post-revalidate.d.ts +0 -7
- package/dist/router/routes/api/helpers.d.ts +0 -8
- package/dist/router/routes/author-archive.d.ts +0 -25
- package/dist/router/routes/author-archive.js +0 -49
- package/dist/router/routes/not-found-page.d.ts +0 -15
- package/dist/router/routes/post-index-page.d.ts +0 -25
- package/dist/router/routes/post-index-page.js +0 -33
- package/dist/router/routes/singular-page.d.ts +0 -29
- package/dist/router/routes/singular-page.js +0 -51
- package/dist/router/routes/site-front-page.d.ts +0 -27
- package/dist/router/routes/site-front-page.js +0 -26
- package/dist/router/routes/term-archive.d.ts +0 -29
- package/dist/router/routes/term-archive.js +0 -65
- package/dist/router/types.js +0 -1
- package/dist/services/get-menu.d.ts +0 -13
- package/dist/services/get-theme-mods.d.ts +0 -7
- package/dist/services/metadata/get-blogname.d.ts +0 -6
- package/dist/services/metadata/get-favicon-url.d.ts +0 -6
- package/dist/services/metadata/get-language-attribute.d.ts +0 -6
- package/dist/services/services.d.ts +0 -3
- package/dist/services/services.js +0 -3
- package/dist/services/utilities/capitalise-first-letter.d.ts +0 -7
- package/dist/services/utilities/esc-html.d.ts +0 -7
- package/dist/services/utilities/get-date-time-formatter.d.ts +0 -6
- package/dist/services/utilities/index.d.ts +0 -0
- package/dist/services/utilities/index.js +0 -1
- package/dist/services/utilities/kses-post.d.ts +0 -7
- package/dist/services/utilities/process-url.d.ts +0 -7
- package/dist/template-heirarchy/_autoloader/template-autoloader.d.ts +0 -9
- package/dist/template-heirarchy/archive/archive.d.ts +0 -16
- package/dist/template-heirarchy/archive/author.d.ts +0 -16
- package/dist/template-heirarchy/archive/category.d.ts +0 -16
- package/dist/template-heirarchy/archive/posttypearchive.d.ts +0 -24
- package/dist/template-heirarchy/archive/tag.d.ts +0 -16
- package/dist/template-heirarchy/archive/taxonomy.d.ts +0 -16
- package/dist/template-heirarchy/home/home.d.ts +0 -16
- package/dist/template-heirarchy/index.d.ts +0 -17
- package/dist/template-heirarchy/not-found.tsx/not-found.d.ts +0 -16
- package/dist/template-heirarchy/page/page.d.ts +0 -16
- package/dist/template-heirarchy/page/posttype.d.ts +0 -24
- package/dist/template-heirarchy/page/single.d.ts +0 -16
- package/dist/template-heirarchy/page/singular.d.ts +0 -16
- package/dist/ui/render-attachment-image.d.ts +0 -12
- package/dist/ui/render-attachment-image.js +0 -24
- package/dist/ui/render-components.d.ts +0 -9
- package/dist/ui/render-components.js +0 -7
- package/dist/ui/render-the-admin-bar.d.ts +0 -8
- package/dist/ui/render-the-admin-bar.js +0 -36
- package/dist/ui/render-the-logo.d.ts +0 -10
- package/dist/ui/render-the-logo.js +0 -16
- package/dist/wpdb/wpdb.d.ts +0 -3
- package/dist/wpdb/wpdb.interface.js +0 -5
- /package/{dist/acf-functions/types/acf-values.d.ts → lib/acf-functions/types/acf-values.ts} +0 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { QueryCreator } from "kysely";
|
|
2
|
+
import { EntityQuery } from "../../globals/entity-loader/entity-loader";
|
|
3
|
+
import { ITerm } from "../../entities/term/term.interface";
|
|
4
|
+
import { TermQueryArgs } from "./term-query-args";
|
|
5
|
+
import { DB } from "nextpress/wpdb/wpdb.interface";
|
|
6
|
+
import { wpdb } from "nextpress/wpdb/wpdb";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Executes database queries to retrieve term IDs based on provided arguments.
|
|
10
|
+
*/
|
|
11
|
+
export class TermQuery implements EntityQuery<ITerm>
|
|
12
|
+
{
|
|
13
|
+
public constructor(
|
|
14
|
+
private args: TermQueryArgs
|
|
15
|
+
) {}
|
|
16
|
+
|
|
17
|
+
public getCount() {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async getIds(): Promise<number[]> {
|
|
22
|
+
let builder = wpdb as QueryCreator<any>;
|
|
23
|
+
|
|
24
|
+
const isMultiple = this.args.multiple !== false;
|
|
25
|
+
|
|
26
|
+
// -- Build CTEs --
|
|
27
|
+
if (this.args.termId) {
|
|
28
|
+
const termIds = Array.isArray(this.args.termId) ? this.args.termId : [this.args.termId];
|
|
29
|
+
const baseQuery = (qb: any) => qb.selectFrom('wpTermTaxonomy')
|
|
30
|
+
.select(['termId', 'parent'])
|
|
31
|
+
.where((eb: any) => eb.or([
|
|
32
|
+
eb('termId', 'in', termIds),
|
|
33
|
+
eb('parent', 'in', termIds)
|
|
34
|
+
]));
|
|
35
|
+
|
|
36
|
+
if (isMultiple) {
|
|
37
|
+
builder = builder.withRecursive('included_branch_id', (qb) =>
|
|
38
|
+
baseQuery(qb).unionAll(
|
|
39
|
+
qb.selectFrom('wpTermTaxonomy as t')
|
|
40
|
+
.select(['t.termId', 't.parent'])
|
|
41
|
+
.innerJoin('included_branch_id as f', 'f.termId', 't.parent')
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
} else {
|
|
45
|
+
builder = builder.with('included_branch_id', baseQuery);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.args.termIdNot) {
|
|
50
|
+
const termIds = Array.isArray(this.args.termIdNot) ? this.args.termIdNot : [this.args.termIdNot];
|
|
51
|
+
const baseQuery = (qb: any) => qb.selectFrom('wpTermTaxonomy')
|
|
52
|
+
.select(['termId', 'parent'])
|
|
53
|
+
.where((eb: any) => eb.or([
|
|
54
|
+
eb('termId', 'in', termIds),
|
|
55
|
+
eb('parent', 'in', termIds)
|
|
56
|
+
]));
|
|
57
|
+
|
|
58
|
+
if (isMultiple) {
|
|
59
|
+
builder = builder.withRecursive('excluded_branch_id', (qb) =>
|
|
60
|
+
baseQuery(qb).unionAll(
|
|
61
|
+
qb.selectFrom('wpTermTaxonomy as t')
|
|
62
|
+
.select(['t.termId', 't.parent'])
|
|
63
|
+
.innerJoin('excluded_branch_id as f', 'f.termId', 't.parent')
|
|
64
|
+
)
|
|
65
|
+
);
|
|
66
|
+
} else {
|
|
67
|
+
builder = builder.with('excluded_branch_id', baseQuery);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (this.args.termName) {
|
|
72
|
+
const names = Array.isArray(this.args.termName) ? this.args.termName : [this.args.termName];
|
|
73
|
+
const baseQuery = (qb: any) => qb.selectFrom('wpTermTaxonomy')
|
|
74
|
+
.innerJoin('wpTerms', 'wpTerms.termId', 'wpTermTaxonomy.termId')
|
|
75
|
+
.select(['wpTermTaxonomy.termId', 'wpTermTaxonomy.parent'])
|
|
76
|
+
.where('wpTerms.name', 'in', names);
|
|
77
|
+
|
|
78
|
+
if (isMultiple) {
|
|
79
|
+
builder = builder.withRecursive('included_branch_name', (qb) =>
|
|
80
|
+
baseQuery(qb).unionAll(
|
|
81
|
+
qb.selectFrom('wpTermTaxonomy as t')
|
|
82
|
+
.select(['t.termId', 't.parent'])
|
|
83
|
+
.innerJoin('included_branch_name as f', 'f.termId', 't.parent')
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
builder = builder.with('included_branch_name', baseQuery);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (this.args.termSlug) {
|
|
92
|
+
const slugs = Array.isArray(this.args.termSlug) ? this.args.termSlug : [this.args.termSlug];
|
|
93
|
+
const baseQuery = (qb: any) => qb.selectFrom('wpTermTaxonomy')
|
|
94
|
+
.innerJoin('wpTerms', 'wpTerms.termId', 'wpTermTaxonomy.termId')
|
|
95
|
+
.select(['wpTermTaxonomy.termId', 'wpTermTaxonomy.parent'])
|
|
96
|
+
.where('wpTerms.slug', 'in', slugs);
|
|
97
|
+
|
|
98
|
+
if (isMultiple) {
|
|
99
|
+
builder = builder.withRecursive('included_branch_slug', (qb) =>
|
|
100
|
+
baseQuery(qb).unionAll(
|
|
101
|
+
qb.selectFrom('wpTermTaxonomy as t')
|
|
102
|
+
.select(['t.termId', 't.parent'])
|
|
103
|
+
.innerJoin('included_branch_slug as f', 'f.termId', 't.parent')
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
} else {
|
|
107
|
+
builder = builder.with('included_branch_slug', baseQuery);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (this.args.termSlugNot) {
|
|
112
|
+
const slugs = Array.isArray(this.args.termSlugNot) ? this.args.termSlugNot : [this.args.termSlugNot];
|
|
113
|
+
const baseQuery = (qb: any) => qb.selectFrom('wpTermTaxonomy')
|
|
114
|
+
.innerJoin('wpTerms', 'wpTerms.termId', 'wpTermTaxonomy.termId')
|
|
115
|
+
.select(['wpTermTaxonomy.termId', 'wpTermTaxonomy.parent'])
|
|
116
|
+
.where('wpTerms.slug', 'in', slugs);
|
|
117
|
+
|
|
118
|
+
if (isMultiple) {
|
|
119
|
+
builder = builder.withRecursive('excluded_branch_slug', (qb) =>
|
|
120
|
+
baseQuery(qb).unionAll(
|
|
121
|
+
qb.selectFrom('wpTermTaxonomy as t')
|
|
122
|
+
.select(['t.termId', 't.parent'])
|
|
123
|
+
.innerJoin('excluded_branch_slug as f', 'f.termId', 't.parent')
|
|
124
|
+
)
|
|
125
|
+
);
|
|
126
|
+
} else {
|
|
127
|
+
builder = builder.with('excluded_branch_slug', baseQuery);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// -- Begin Main SELECT Statement --
|
|
132
|
+
let query = (builder as QueryCreator<DB>).selectFrom('wpTerms')
|
|
133
|
+
.innerJoin('wpTermTaxonomy', 'wpTerms.termId', 'wpTermTaxonomy.termId');
|
|
134
|
+
|
|
135
|
+
// -- Apply Filters (WHERE clauses) --
|
|
136
|
+
if (this.args.taxonomy) {
|
|
137
|
+
const taxonomies = Array.isArray(this.args.taxonomy) ? this.args.taxonomy : [this.args.taxonomy];
|
|
138
|
+
query = query.where('wpTermTaxonomy.taxonomy', 'in', taxonomies);
|
|
139
|
+
}
|
|
140
|
+
if (this.args.taxonomyId) {
|
|
141
|
+
const ids = Array.isArray(this.args.taxonomyId) ? this.args.taxonomyId : [this.args.taxonomyId];
|
|
142
|
+
query = query.where('wpTermTaxonomy.termTaxonomyId', 'in', ids);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (this.args.termId) query = query.where('wpTerms.termId', 'in', (qb: any) => qb.selectFrom('included_branch_id').select('termId'));
|
|
146
|
+
if (this.args.termIdNot) query = query.where('wpTerms.termId', 'not in', (qb: any) => qb.selectFrom('excluded_branch_id').select('termId'));
|
|
147
|
+
if (this.args.termName) query = query.where('wpTerms.termId', 'in', (qb: any) => qb.selectFrom('included_branch_name').select('termId'));
|
|
148
|
+
if (this.args.termSlug) query = query.where('wpTerms.termId', 'in', (qb: any) => qb.selectFrom('included_branch_slug').select('termId'));
|
|
149
|
+
if (this.args.termSlugNot) query = query.where('wpTerms.termId', 'not in', (qb: any) => qb.selectFrom('excluded_branch_slug').select('termId'));
|
|
150
|
+
if (this.args.hideEmpty !== false) query = query.where('wpTermTaxonomy.count', '>', 0);
|
|
151
|
+
|
|
152
|
+
if (this.args.parent !== undefined) {
|
|
153
|
+
query = query.where('wpTermTaxonomy.parent', '=', this.args.parent);
|
|
154
|
+
}
|
|
155
|
+
if (this.args.childless) {
|
|
156
|
+
query = query.where('wpTerms.termId', 'not in', (qb) =>
|
|
157
|
+
qb.selectFrom('wpTermTaxonomy').select('wpTermTaxonomy.parent').where('wpTermTaxonomy.parent', '>', 0)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (this.args.search) {
|
|
162
|
+
const searchStr = `%${this.args.search}%`;
|
|
163
|
+
query = query.where((eb) => eb.or([
|
|
164
|
+
eb('wpTerms.name', 'like', searchStr),
|
|
165
|
+
eb('wpTerms.slug', 'like', searchStr)
|
|
166
|
+
]));
|
|
167
|
+
}
|
|
168
|
+
if (this.args.nameLike) {
|
|
169
|
+
query = query.where('wpTerms.name', 'like', this.args.nameLike);
|
|
170
|
+
}
|
|
171
|
+
if (this.args.descriptionLike) {
|
|
172
|
+
query = query.where('wpTermTaxonomy.description', 'like', this.args.descriptionLike);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (this.args.path) {
|
|
176
|
+
query = query.where((eb) => eb.exists(
|
|
177
|
+
eb.selectFrom('wpTermmeta')
|
|
178
|
+
.select('wpTerms.termId')
|
|
179
|
+
.whereRef('wpTermmeta.termId', '=', 'wpTerms.termId')
|
|
180
|
+
.where('wpTermmeta.metaKey', '=', '_nextpress_path')
|
|
181
|
+
.where('wpTermmeta.metaValue', '=', this.args.path as string)
|
|
182
|
+
));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// -- Apply ORDER BY --
|
|
186
|
+
const orderDirection = this.args.order === 'DESC' ? 'desc' : 'asc';
|
|
187
|
+
const orderBy = this.args.orderBy || 'none';
|
|
188
|
+
|
|
189
|
+
switch(orderBy) {
|
|
190
|
+
case 'none': break;
|
|
191
|
+
case 'term_id': query = query.orderBy('wpTerms.termId', orderDirection); break;
|
|
192
|
+
case 'name': query = query.orderBy('wpTerms.name', orderDirection).orderBy('wpTerms.termId', orderDirection); break;
|
|
193
|
+
case 'slug': query = query.orderBy('wpTerms.slug', orderDirection).orderBy('wpTerms.termId', orderDirection); break;
|
|
194
|
+
case 'term_group': query = query.orderBy('wpTerms.termGroup', orderDirection).orderBy('wpTerms.termId', orderDirection); break;
|
|
195
|
+
case 'description': query = query.orderBy('wpTermTaxonomy.description', orderDirection).orderBy('wpTerms.termId', orderDirection); break;
|
|
196
|
+
case 'parent': query = query.orderBy('wpTermTaxonomy.parent', orderDirection).orderBy('wpTerms.termId', orderDirection); break;
|
|
197
|
+
case 'count': query = query.orderBy('wpTermTaxonomy.count', orderDirection).orderBy('wpTerms.termId', orderDirection); break;
|
|
198
|
+
default: query = query.orderBy('wpTerms.name', orderDirection).orderBy('wpTerms.termId', orderDirection); break;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// -- Apply LIMIT & OFFSET --
|
|
202
|
+
const limit = this.args.number ?? 0;
|
|
203
|
+
if (limit > 0) {
|
|
204
|
+
query = query.limit(limit);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const offsetAmount = this.args.offset ?? 0;
|
|
208
|
+
if (offsetAmount > 0) {
|
|
209
|
+
query = query.offset(offsetAmount);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (this.args.metaQuery) {
|
|
213
|
+
let dynamicQuery: any = query;
|
|
214
|
+
|
|
215
|
+
for (let metaQuery of this.args.metaQuery) {
|
|
216
|
+
const uniqueAlias = `meta_${metaQuery.as}`;
|
|
217
|
+
|
|
218
|
+
dynamicQuery = dynamicQuery.leftJoin(`wpTermmeta as ${uniqueAlias}`, (join: any) =>
|
|
219
|
+
join
|
|
220
|
+
.onRef(`${uniqueAlias}.termId`, '=', 'wpTerms.termId')
|
|
221
|
+
.on(`${uniqueAlias}.metaKey`, '=', metaQuery.metaKey)
|
|
222
|
+
)
|
|
223
|
+
.select(`${uniqueAlias}.metaValue as ${metaQuery.as}`);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
query = dynamicQuery;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
if (isMultiple) {
|
|
231
|
+
return (await query
|
|
232
|
+
.select('wpTerms.termId')
|
|
233
|
+
.groupBy('wpTerms.termId')
|
|
234
|
+
.execute()).map((res: any) => res.termId);
|
|
235
|
+
} else {
|
|
236
|
+
return (await query
|
|
237
|
+
.select('wpTerms.termId')
|
|
238
|
+
.execute()).map((res: any) => res.termId);
|
|
239
|
+
}
|
|
240
|
+
} catch (error: any) {
|
|
241
|
+
throw new Error(`WPTermQuery: Cannot get terms: ${error.message}`, { cause: error });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Defines the arguments for querying users.
|
|
3
3
|
* Maps standard WordPress WP_User_Query parameters.
|
|
4
4
|
*/
|
|
5
|
-
interface UserQueryArgs {
|
|
5
|
+
export interface UserQueryArgs {
|
|
6
6
|
/** User ID, or array of user IDs, to match when querying terms. */
|
|
7
7
|
userId?: number | number[];
|
|
8
8
|
/** An array of user IDs to exclude. Default empty array. */
|
|
@@ -34,9 +34,21 @@ interface UserQueryArgs {
|
|
|
34
34
|
/** Search keyword. Searches for possible string matches on columns. */
|
|
35
35
|
search?: string;
|
|
36
36
|
/** Array of column names to be searched. */
|
|
37
|
-
search_columns?: ('ID' | 'userLogin' | 'userEmail' | 'userUrl' | 'userNicename' | 'displayName')[]
|
|
37
|
+
search_columns?: ('ID' | 'userLogin' | 'userEmail' | 'userUrl' | 'userNicename' | 'displayName')[]
|
|
38
38
|
/** Field(s) to order terms by. Default 'none'. */
|
|
39
|
-
orderBy?:
|
|
39
|
+
orderBy?:
|
|
40
|
+
| 'ID'
|
|
41
|
+
| 'name'
|
|
42
|
+
| 'login'
|
|
43
|
+
| 'nicename'
|
|
44
|
+
| 'first_name'
|
|
45
|
+
| 'last_name'
|
|
46
|
+
| 'email'
|
|
47
|
+
| 'registered'
|
|
48
|
+
| 'post_count'
|
|
49
|
+
| 'count'
|
|
50
|
+
| 'none'
|
|
51
|
+
| string;
|
|
40
52
|
/** Designates ascending or descending order of users. Accepts 'ASC', 'DESC'. Default 'ASC'. */
|
|
41
53
|
order?: 'ASC' | 'DESC';
|
|
42
54
|
/** Number of users to offset in retrieved results. Can be used in conjunction with pagination. Default 0. */
|
|
@@ -54,10 +66,10 @@ interface UserQueryArgs {
|
|
|
54
66
|
/** Meta query */
|
|
55
67
|
metaQuery?: {
|
|
56
68
|
/** Meta key */
|
|
57
|
-
metaKey: string
|
|
69
|
+
metaKey: string,
|
|
58
70
|
/** Variable name to save result to */
|
|
59
|
-
as: string
|
|
60
|
-
}[]
|
|
71
|
+
as: string
|
|
72
|
+
}[]
|
|
61
73
|
/** Whether to get multiple, default false */
|
|
62
|
-
multiple?: boolean
|
|
74
|
+
multiple?: boolean
|
|
63
75
|
}
|
|
@@ -1,178 +1,195 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IUser } from "../../entities/user/user.interface";
|
|
2
|
+
import { EntityQuery } from "../../globals/entity-loader/entity-loader";
|
|
2
3
|
import { sql } from "kysely";
|
|
4
|
+
import { UserQueryArgs } from "./user-query-args";
|
|
5
|
+
import { wpdb } from "nextpress/wpdb/wpdb";
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Executes database queries to retrieve user IDs and counts based on provided arguments.
|
|
5
9
|
*/
|
|
6
|
-
export class UserQuery
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export class UserQuery implements EntityQuery<IUser>
|
|
11
|
+
{
|
|
12
|
+
private userCount?: number;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
private args: UserQueryArgs
|
|
16
|
+
) {}
|
|
17
|
+
|
|
18
|
+
public getCount(): number | undefined {
|
|
11
19
|
return this.userCount;
|
|
12
20
|
}
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
|
|
22
|
+
public async getIds(): Promise<number[]> {
|
|
15
23
|
let query = wpdb.selectFrom('wpUsers');
|
|
24
|
+
|
|
16
25
|
// --- ID Filters ---
|
|
17
26
|
if (this.args.userId) {
|
|
18
27
|
const types = Array.isArray(this.args.userId) ? this.args.userId : [this.args.userId];
|
|
19
28
|
query = query.where('wpUsers.ID', 'in', types);
|
|
20
29
|
}
|
|
21
|
-
if (this.args.userIdsNotIn)
|
|
22
|
-
|
|
30
|
+
if (this.args.userIdsNotIn) query = query.where('wpUsers.ID', 'not in', this.args.userIdsNotIn);
|
|
31
|
+
|
|
23
32
|
// --- Nicename Filters ---
|
|
24
|
-
if (this.args.nicename)
|
|
25
|
-
|
|
26
|
-
if (this.args.
|
|
27
|
-
|
|
28
|
-
if (this.args.nicenameNotIn)
|
|
29
|
-
query = query.where('wpUsers.userNicename', 'not in', this.args.nicenameNotIn);
|
|
33
|
+
if (this.args.nicename) query = query.where('wpUsers.userNicename', '=', this.args.nicename);
|
|
34
|
+
if (this.args.nicenameIn) query = query.where('wpUsers.userNicename', 'in', this.args.nicenameIn);
|
|
35
|
+
if (this.args.nicenameNotIn) query = query.where('wpUsers.userNicename', 'not in', this.args.nicenameNotIn);
|
|
36
|
+
|
|
30
37
|
// --- Display name Filters ---
|
|
31
|
-
if (this.args.displayName)
|
|
32
|
-
|
|
33
|
-
if (this.args.
|
|
34
|
-
|
|
35
|
-
if (this.args.displayNameNotIn)
|
|
36
|
-
query = query.where('wpUsers.displayName', 'not in', this.args.displayNameNotIn);
|
|
38
|
+
if (this.args.displayName) query = query.where('wpUsers.displayName', '=', this.args.displayName);
|
|
39
|
+
if (this.args.displayNameIn) query = query.where('wpUsers.displayName', 'in', this.args.displayNameIn);
|
|
40
|
+
if (this.args.displayNameNotIn) query = query.where('wpUsers.displayName', 'not in', this.args.displayNameNotIn);
|
|
41
|
+
|
|
37
42
|
// --- Login Filters ---
|
|
38
|
-
if (this.args.login)
|
|
39
|
-
|
|
40
|
-
if (this.args.
|
|
41
|
-
|
|
42
|
-
if (this.args.loginNotIn)
|
|
43
|
-
query = query.where('wpUsers.userLogin', 'not in', this.args.loginNotIn);
|
|
43
|
+
if (this.args.login) query = query.where('wpUsers.userLogin', '=', this.args.login);
|
|
44
|
+
if (this.args.loginIn) query = query.where('wpUsers.userLogin', 'in', this.args.loginIn);
|
|
45
|
+
if (this.args.loginNotIn) query = query.where('wpUsers.userLogin', 'not in', this.args.loginNotIn);
|
|
46
|
+
|
|
44
47
|
// --- Role Filters ---
|
|
45
48
|
if (this.args.roleIn) {
|
|
46
49
|
query = query
|
|
47
50
|
.innerJoin('wpUsermeta as um_role_in', 'wpUsers.ID', 'um_role_in.userId')
|
|
48
51
|
.where('um_role_in.metaKey', '=', 'wp_capabilities')
|
|
49
52
|
.where((eb) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
const orClauses = this.args.roleIn!.map(role =>
|
|
54
|
+
eb('um_role_in.metaValue', 'like', `%"${role}"%`)
|
|
55
|
+
);
|
|
56
|
+
return eb.or(orClauses);
|
|
57
|
+
});
|
|
53
58
|
}
|
|
59
|
+
|
|
54
60
|
if (this.args.roleAnd) {
|
|
55
61
|
this.args.roleAnd.forEach((role, index) => {
|
|
56
|
-
const alias = `um_role_and_${index}
|
|
62
|
+
const alias = `um_role_and_${index}` as const;
|
|
63
|
+
|
|
57
64
|
query = query
|
|
58
65
|
.innerJoin(`wpUsermeta as ${alias}`, 'wpUsers.ID', `${alias}.userId`)
|
|
59
66
|
.where(`${alias}.metaKey`, '=', 'wp_capabilities')
|
|
60
67
|
.where(`${alias}.metaValue`, 'like', `%"${role}"%`);
|
|
61
68
|
});
|
|
62
69
|
}
|
|
70
|
+
|
|
63
71
|
if (this.args.roleNotIn) {
|
|
64
72
|
this.args.roleNotIn.forEach((role, index) => {
|
|
65
|
-
const alias = `um_role_not_${index}
|
|
73
|
+
const alias = `um_role_not_${index}` as const;
|
|
74
|
+
|
|
66
75
|
query = query
|
|
67
76
|
.innerJoin(`wpUsermeta as ${alias}`, 'wpUsers.ID', `${alias}.userId`)
|
|
68
77
|
.where(`${alias}.metaKey`, '=', 'wp_capabilities')
|
|
69
78
|
.where(`${alias}.metaValue`, 'not like', `%"${role}"%`);
|
|
70
79
|
});
|
|
71
80
|
}
|
|
81
|
+
|
|
72
82
|
// --- Search Filters ---
|
|
73
83
|
if (this.args.search) {
|
|
74
84
|
const searchTerm = `%${this.args.search}%`;
|
|
75
85
|
const searchCols = this.args.search_columns || ['ID', 'userLogin', 'userEmail', 'userUrl', 'userNicename', 'displayName'];
|
|
86
|
+
|
|
76
87
|
query = query.where((eb) => {
|
|
77
88
|
const orClauses = searchCols.map(col => eb(col, 'like', searchTerm));
|
|
78
89
|
return eb.or(orClauses);
|
|
79
90
|
});
|
|
80
91
|
}
|
|
92
|
+
|
|
81
93
|
// --- Published Posts Filter ---
|
|
82
94
|
if (this.args.hasPublishedPosts) {
|
|
83
|
-
query = query.where((eb) => eb(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
query = query.where((eb) => eb(
|
|
96
|
+
eb.selectFrom('wpPosts')
|
|
97
|
+
.select(eb.fn.count<number>('ID').as('count'))
|
|
98
|
+
.whereRef('wpPosts.postAuthor', '=', 'wpUsers.ID')
|
|
99
|
+
.where('wpPosts.postStatus', '=', 'publish'),
|
|
100
|
+
'>', 0
|
|
101
|
+
));
|
|
87
102
|
}
|
|
103
|
+
|
|
88
104
|
// 3. Calculate Total Count (Before Limits/Offsets)
|
|
89
105
|
if (!this.args.noFoundRows) {
|
|
90
106
|
try {
|
|
91
107
|
const countQueryBase = query.clearSelect().select('wpUsers.ID').distinct();
|
|
92
108
|
const countResult = await wpdb.selectFrom(countQueryBase.as('sub'))
|
|
93
|
-
.select(sql
|
|
109
|
+
.select(sql<number>`count(*)`.as('count'))
|
|
94
110
|
.executeTakeFirst();
|
|
111
|
+
|
|
95
112
|
this.userCount = countResult ? Number(countResult.count) : undefined;
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
113
|
+
} catch (error: any) {
|
|
98
114
|
console.error('WPUserQuery: Cannot get row count: ', error.message);
|
|
99
115
|
this.userCount = undefined;
|
|
100
116
|
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
117
|
+
} else {
|
|
103
118
|
this.userCount = undefined;
|
|
104
119
|
}
|
|
120
|
+
|
|
105
121
|
// 4. Apply ORDER BY
|
|
106
122
|
const orderDirection = this.args.order === 'DESC' ? 'desc' : 'asc';
|
|
107
123
|
const orderBy = this.args.orderBy || 'none';
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
case '
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
case '
|
|
116
|
-
query = query.orderBy('wpUsers.userLogin', orderDirection).orderBy('wpUsers.ID', orderDirection);
|
|
117
|
-
break;
|
|
118
|
-
case 'nicename':
|
|
119
|
-
query = query.orderBy('wpUsers.userNicename', orderDirection).orderBy('wpUsers.ID', orderDirection);
|
|
120
|
-
break;
|
|
121
|
-
case 'email':
|
|
122
|
-
query = query.orderBy('wpUsers.userEmail', orderDirection).orderBy('wpUsers.ID', orderDirection);
|
|
123
|
-
break;
|
|
124
|
-
case 'registered':
|
|
125
|
-
query = query.orderBy('wpUsers.userRegistered', orderDirection).orderBy('wpUsers.ID', orderDirection);
|
|
126
|
-
break;
|
|
124
|
+
|
|
125
|
+
switch(orderBy) {
|
|
126
|
+
case 'ID': query = query.orderBy('wpUsers.ID', orderDirection).orderBy('wpUsers.ID', orderDirection); break;
|
|
127
|
+
case 'name': query = query.orderBy('wpUsers.displayName', orderDirection).orderBy('wpUsers.ID', orderDirection); break;
|
|
128
|
+
case 'login': query = query.orderBy('wpUsers.userLogin', orderDirection).orderBy('wpUsers.ID', orderDirection); break;
|
|
129
|
+
case 'nicename': query = query.orderBy('wpUsers.userNicename', orderDirection).orderBy('wpUsers.ID', orderDirection); break;
|
|
130
|
+
case 'email': query = query.orderBy('wpUsers.userEmail', orderDirection).orderBy('wpUsers.ID', orderDirection); break;
|
|
131
|
+
case 'registered': query = query.orderBy('wpUsers.userRegistered', orderDirection).orderBy('wpUsers.ID', orderDirection); break;
|
|
127
132
|
case 'post_count':
|
|
128
|
-
query = query.orderBy(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
133
|
+
query = query.orderBy(
|
|
134
|
+
(eb) => eb.selectFrom('wpPosts')
|
|
135
|
+
.select(eb.fn.count('ID').as('count'))
|
|
136
|
+
.whereRef('wpPosts.postAuthor', '=', 'wpUsers.ID')
|
|
137
|
+
.where('wpPosts.postStatus', '=', 'publish'),
|
|
138
|
+
orderDirection
|
|
139
|
+
).orderBy('wpUsers.ID', orderDirection);
|
|
132
140
|
break;
|
|
133
141
|
case 'none': break;
|
|
134
142
|
default:
|
|
135
143
|
query = query.orderBy('wpUsers.userLogin', orderDirection).orderBy('wpUsers.ID', orderDirection);
|
|
136
144
|
break;
|
|
137
145
|
}
|
|
146
|
+
|
|
138
147
|
// 5. Apply LIMIT & OFFSET
|
|
139
148
|
if (!this.args.noPaging) {
|
|
140
|
-
const perPage =
|
|
149
|
+
const perPage = this.args.usersPerPage ?? -1;
|
|
150
|
+
|
|
141
151
|
if (perPage > -1) {
|
|
142
152
|
query = query.limit(perPage);
|
|
143
|
-
|
|
144
|
-
const
|
|
153
|
+
|
|
154
|
+
const page = this.args.page ?? 1;
|
|
155
|
+
const baseOffset = this.args.offset ?? 0;
|
|
145
156
|
const offsetAmount = ((page - 1) * perPage) + baseOffset;
|
|
157
|
+
|
|
146
158
|
if (offsetAmount > 0) {
|
|
147
159
|
query = query.offset(offsetAmount);
|
|
148
160
|
}
|
|
149
161
|
}
|
|
150
162
|
}
|
|
163
|
+
|
|
151
164
|
if (this.args.metaQuery) {
|
|
152
|
-
let dynamicQuery = query;
|
|
165
|
+
let dynamicQuery: any = query;
|
|
166
|
+
|
|
153
167
|
for (let metaQuery of this.args.metaQuery) {
|
|
154
168
|
const uniqueAlias = `meta_${metaQuery.as}`;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
169
|
+
|
|
170
|
+
dynamicQuery = dynamicQuery.leftJoin(`wpUsermeta as ${uniqueAlias}`, (join: any) =>
|
|
171
|
+
join
|
|
172
|
+
.onRef(`${uniqueAlias}.userId`, '=', 'wpUsers.ID')
|
|
173
|
+
.on(`${uniqueAlias}.metaKey`, '=', metaQuery.metaKey)
|
|
174
|
+
)
|
|
158
175
|
.select(`${uniqueAlias}.metaValue as ${metaQuery.as}`);
|
|
159
176
|
}
|
|
177
|
+
|
|
160
178
|
query = dynamicQuery;
|
|
161
179
|
}
|
|
180
|
+
|
|
162
181
|
try {
|
|
163
182
|
if (this.args.multiple !== false) {
|
|
164
183
|
return (await query
|
|
165
184
|
.select('wpUsers.ID as id')
|
|
166
185
|
.groupBy('wpUsers.ID')
|
|
167
186
|
.execute()).map(res => res.id);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
187
|
+
} else {
|
|
170
188
|
return (await query
|
|
171
189
|
.select('wpUsers.ID as id')
|
|
172
190
|
.execute()).map(res => res.id);
|
|
173
191
|
}
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
192
|
+
} catch (error: any) {
|
|
176
193
|
throw new Error(`WPUserQuery: Cannot get users: ${error.message}`, { cause: error });
|
|
177
194
|
}
|
|
178
195
|
}
|
|
@@ -4,17 +4,17 @@
|
|
|
4
4
|
* @param {string[]} path - Array of path segments.
|
|
5
5
|
* @returns {number | undefined} Page number or undefined.
|
|
6
6
|
*/
|
|
7
|
-
export function getPageNumber(path) {
|
|
7
|
+
export function getPageNumber(path: string[]): number|undefined {
|
|
8
8
|
return path[path.length - 2] === 'page' ? Number(path[path.length - 1]) || undefined : undefined;
|
|
9
9
|
}
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Splits path string into array of segments.
|
|
12
13
|
*
|
|
13
14
|
* @param {string} path - Path string.
|
|
14
15
|
* @returns {string[]} Array of path segments.
|
|
15
16
|
*/
|
|
16
|
-
export function splitPath(path) {
|
|
17
|
-
if (!path)
|
|
18
|
-
return [];
|
|
17
|
+
export function splitPath(path: string): string[] {
|
|
18
|
+
if (!path) return [];
|
|
19
19
|
return path.split('/').filter(Boolean);
|
|
20
20
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import "nextpress/globals/globals";
|
|
2
|
+
import "@/app/_css/globals.css";
|
|
3
3
|
import { LayoutTemplate } from "@/app/_templates/layout";
|
|
4
4
|
import { cookies, draftMode } from "next/headers";
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
5
|
+
import fonts from "@/fonts";
|
|
6
|
+
import { getLanguageAttributes } from "nextpress/services/metadata/get-language-attribute";
|
|
7
|
+
import { RenderTheAdminBar } from "nextpress/ui/render-the-admin-bar";
|
|
8
|
+
|
|
7
9
|
const fontClasses = fonts.map(font => font.className).join(' ');
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* The layout for the application.
|
|
10
13
|
* Defines the main HTML shell, handles Draft Mode validation, primes necessary global WordPress options,
|
|
@@ -13,19 +16,35 @@ const fontClasses = fonts.map(font => font.className).join(' ');
|
|
|
13
16
|
* @param {Readonly<{children: React.ReactNode;}>} props - Component properties, wrapping the children pages.
|
|
14
17
|
* @returns {Promise<JSX.Element>} The root layout of the entire app.
|
|
15
18
|
*/
|
|
16
|
-
export async function NextpressLayout({ children }) {
|
|
17
|
-
var _a, _b;
|
|
19
|
+
export async function NextpressLayout({ children }: Readonly<{children: React.ReactNode;}>) {
|
|
18
20
|
const draftModeEnabled = (await draftMode()).isEnabled;
|
|
19
21
|
let loggedInUserId = 0;
|
|
20
22
|
if (draftModeEnabled) {
|
|
21
23
|
const cookieStore = await cookies();
|
|
22
|
-
loggedInUserId = Number(
|
|
24
|
+
loggedInUserId = Number(cookieStore.get('nextpress_logged_in_user_id')?.value) || 0;
|
|
23
25
|
}
|
|
26
|
+
|
|
24
27
|
optionLoader.findAndPrime({
|
|
25
28
|
column: 'optionName',
|
|
26
29
|
operand: 'in',
|
|
27
30
|
value: nextpressConfig.preLoadOptions || ''
|
|
28
|
-
})
|
|
31
|
+
})
|
|
32
|
+
|
|
29
33
|
const languageAttributes = await getLanguageAttributes();
|
|
30
|
-
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<html
|
|
37
|
+
lang={languageAttributes}
|
|
38
|
+
className={fontClasses}
|
|
39
|
+
>
|
|
40
|
+
<body className="">
|
|
41
|
+
{(draftModeEnabled && (await getUser(loggedInUserId))?.showAdminBar) && <RenderTheAdminBar loggedInUserId={loggedInUserId}/>}
|
|
42
|
+
<LayoutTemplate>
|
|
43
|
+
{children}
|
|
44
|
+
</LayoutTemplate>
|
|
45
|
+
</body>
|
|
46
|
+
</html>
|
|
47
|
+
);
|
|
31
48
|
}
|
|
49
|
+
|
|
50
|
+
|