@miso.ai/server-wordpress 0.6.3-beta.14 → 0.6.3-beta.16
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/download.js +2 -7
- package/cli/summarize.js +3 -5
- package/cli/utils.js +3 -16
- package/package.json +2 -2
- package/src/entities/index.js +30 -10
- package/src/helpers.js +18 -4
- package/src/version.js +1 -1
package/cli/download.js
CHANGED
|
@@ -3,7 +3,7 @@ import { access, mkdir } from 'fs/promises';
|
|
|
3
3
|
import { createGzip } from 'zlib';
|
|
4
4
|
import { startOfDate, endOfDate, stream } from '@miso.ai/server-commons';
|
|
5
5
|
import { WordPressClient } from '../src/index.js';
|
|
6
|
-
import {
|
|
6
|
+
import { buildForEntities } from './utils.js';
|
|
7
7
|
|
|
8
8
|
function build(yargs) {
|
|
9
9
|
return buildForEntities(yargs);
|
|
@@ -16,12 +16,7 @@ async function run({
|
|
|
16
16
|
} = {}) {
|
|
17
17
|
const client = new WordPressClient(options);
|
|
18
18
|
|
|
19
|
-
const
|
|
20
|
-
getFirstPostDate(client),
|
|
21
|
-
getLastPostDate(client),
|
|
22
|
-
]);
|
|
23
|
-
const firstPostYear = getYear(firstPostDate);
|
|
24
|
-
const lastPostYear = getYear(lastPostDate);
|
|
19
|
+
const [firstPostYear, lastPostYear] = await client.posts.yearRange();
|
|
25
20
|
|
|
26
21
|
// divide into batches
|
|
27
22
|
const batches = [];
|
package/cli/summarize.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { startOfDate, endOfDate } from '@miso.ai/server-commons';
|
|
1
|
+
import { startOfDate, endOfDate, getYear } from '@miso.ai/server-commons';
|
|
2
2
|
import { WordPressClient } from '../src/index.js';
|
|
3
|
-
import { getFirstPostDate, getLastPostDate, getYear } from './utils.js';
|
|
4
3
|
|
|
5
4
|
function build(yargs) {
|
|
6
5
|
return yargs;
|
|
@@ -8,10 +7,9 @@ function build(yargs) {
|
|
|
8
7
|
|
|
9
8
|
async function run({ ...options } = {}) {
|
|
10
9
|
const client = new WordPressClient(options);
|
|
11
|
-
const [total, firstPostDate, lastPostDate] = await Promise.all([
|
|
10
|
+
const [total, [firstPostDate, lastPostDate]] = await Promise.all([
|
|
12
11
|
client.posts.count(options),
|
|
13
|
-
|
|
14
|
-
getLastPostDate(client),
|
|
12
|
+
client.posts.dateRange(),
|
|
15
13
|
]);
|
|
16
14
|
const totalStrLength = `${total}`.length;
|
|
17
15
|
console.log();
|
package/cli/utils.js
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
1
|
import { startOfDate, endOfDate } from '@miso.ai/server-commons';
|
|
2
2
|
|
|
3
3
|
export function normalizeOptions({ date, after, before, ids, include, ...options }) {
|
|
4
|
+
// TODO: should be able to turn this off, as it's covered by helper
|
|
4
5
|
[after, before] = [startOfDate(date || after), endOfDate(date || before)];
|
|
5
6
|
// TODO: rely on yargs to coerce to array
|
|
6
7
|
ids = ids ? `${ids}`.split(',').map(s => s.trim()) : ids;
|
|
7
8
|
return { ...options, after, before, ids };
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
/*
|
|
10
12
|
export function parseDate(value) {
|
|
11
13
|
return Date.parse(`${value}Z`);
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
export async function getFirstPostDate(client, options) {
|
|
15
|
-
return getPostDate(client, 'asc', options);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function getLastPostDate(client, options) {
|
|
19
|
-
return getPostDate(client, 'desc', options);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function getPostDate(client, order, options = {}) {
|
|
23
|
-
return (await client.posts.getAll({ ...options, limit: 1, order, fields: ['date_gmt'] }))[0].date_gmt;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function getYear(dateStr) {
|
|
27
|
-
return new Date(dateStr).getFullYear();
|
|
28
|
-
}
|
|
15
|
+
*/
|
|
29
16
|
|
|
30
17
|
export function buildForEntities(yargs) {
|
|
31
18
|
// TODO: make them mutually exclusive
|
package/package.json
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"simonpai <simon.pai@askmiso.com>"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@miso.ai/server-commons": "0.6.3-beta.
|
|
20
|
+
"@miso.ai/server-commons": "0.6.3-beta.16",
|
|
21
21
|
"axios": "^1.6.2",
|
|
22
22
|
"axios-retry": "^3.3.1"
|
|
23
23
|
},
|
|
24
|
-
"version": "0.6.3-beta.
|
|
24
|
+
"version": "0.6.3-beta.16"
|
|
25
25
|
}
|
package/src/entities/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { Transform } from 'stream';
|
|
3
|
-
import { asArray, stream } from '@miso.ai/server-commons';
|
|
3
|
+
import { asArray, stream, getYear } from '@miso.ai/server-commons';
|
|
4
4
|
import EntityIndex from './entity-index.js';
|
|
5
5
|
import EntityTransformStream from './transform.js';
|
|
6
6
|
import EntityPresenceStream from './presence.js';
|
|
@@ -72,6 +72,10 @@ export default class Entities {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async getAll(options) {
|
|
75
|
+
return this.all(options);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async all(options) {
|
|
75
79
|
return stream.collect(await this.stream(options));
|
|
76
80
|
}
|
|
77
81
|
|
|
@@ -87,6 +91,18 @@ export default class Entities {
|
|
|
87
91
|
return new EntityPresenceStream(this._client, this.name, options);
|
|
88
92
|
}
|
|
89
93
|
|
|
94
|
+
async dateRange() {
|
|
95
|
+
// TODO: options?
|
|
96
|
+
return Promise.all([
|
|
97
|
+
getPostDate(this._client, 'asc'),
|
|
98
|
+
getPostDate(this._client, 'desc'),
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async yearRange() {
|
|
103
|
+
return (await this.dateRange()).map(getYear);
|
|
104
|
+
}
|
|
105
|
+
|
|
90
106
|
get index() {
|
|
91
107
|
return this._index;
|
|
92
108
|
}
|
|
@@ -101,15 +117,6 @@ export default class Entities {
|
|
|
101
117
|
|
|
102
118
|
}
|
|
103
119
|
|
|
104
|
-
function aggregateIds(records, propName) {
|
|
105
|
-
return Array.from(records.reduce((idSet, record) => {
|
|
106
|
-
for (const id of asArray(record[propName])) {
|
|
107
|
-
idSet.add(id);
|
|
108
|
-
}
|
|
109
|
-
return idSet;
|
|
110
|
-
}, new Set()));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
120
|
async function getTransformFn(client, name, transform) {
|
|
114
121
|
switch (transform) {
|
|
115
122
|
case 'default':
|
|
@@ -133,3 +140,16 @@ async function getTransformFn(client, name, transform) {
|
|
|
133
140
|
}
|
|
134
141
|
return undefined;
|
|
135
142
|
}
|
|
143
|
+
|
|
144
|
+
function aggregateIds(records, propName) {
|
|
145
|
+
return Array.from(records.reduce((idSet, record) => {
|
|
146
|
+
for (const id of asArray(record[propName])) {
|
|
147
|
+
idSet.add(id);
|
|
148
|
+
}
|
|
149
|
+
return idSet;
|
|
150
|
+
}, new Set()));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function getPostDate(client, order, options = {}) {
|
|
154
|
+
return (await client.posts.getAll({ ...options, limit: 1, order, fields: ['date_gmt'] }))[0].date_gmt;
|
|
155
|
+
}
|
package/src/helpers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
2
|
import axiosRetry from 'axios-retry';
|
|
3
|
-
import { asNumber, splitObj, stream } from '@miso.ai/server-commons';
|
|
3
|
+
import { asNumber, splitObj, stream, startOfDate, endOfDate } from '@miso.ai/server-commons';
|
|
4
4
|
import DataSource from './source/index.js';
|
|
5
5
|
import version from './version.js';
|
|
6
6
|
|
|
@@ -161,13 +161,27 @@ class Url {
|
|
|
161
161
|
|
|
162
162
|
// modifiedAfter, modifiedBefore is supported since WordPress 5.7
|
|
163
163
|
// https://make.wordpress.org/core/2021/02/23/rest-api-changes-in-wordpress-5-7/
|
|
164
|
-
async append(url,
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
async append(url, {
|
|
165
|
+
date,
|
|
166
|
+
after,
|
|
167
|
+
before,
|
|
168
|
+
modifiedAfter,
|
|
169
|
+
modifiedBefore,
|
|
170
|
+
order,
|
|
171
|
+
orderBy,
|
|
172
|
+
page,
|
|
173
|
+
pageSize,
|
|
174
|
+
offset,
|
|
175
|
+
include,
|
|
176
|
+
exclude,
|
|
177
|
+
fields,
|
|
178
|
+
} = {}) {
|
|
167
179
|
const params = [];
|
|
168
180
|
|
|
169
181
|
// TODO: support single id
|
|
170
182
|
|
|
183
|
+
[after, before] = [startOfDate(date || after), endOfDate(date || before)];
|
|
184
|
+
|
|
171
185
|
// The date is compared against site's local time, not UTC, so we have to work on timezone offset
|
|
172
186
|
if (has(after) || has(before) || has(modifiedAfter) || has(modifiedBefore)) {
|
|
173
187
|
const utcOffset = await this._helpers.utcOffsetInMs();
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.6.3-beta.
|
|
1
|
+
export default '0.6.3-beta.16';
|