@miso.ai/server-wordpress 0.6.3-beta.14 → 0.6.3-beta.15

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 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 { getFirstPostDate, getLastPostDate, getYear, buildForEntities } from './utils.js';
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 [firstPostDate, lastPostDate] = await Promise.all([
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,6 @@
1
1
  import { startOfDate, endOfDate } from '@miso.ai/server-commons';
2
2
  import { WordPressClient } from '../src/index.js';
3
- import { getFirstPostDate, getLastPostDate, getYear } from './utils.js';
3
+ import { getYear } from './utils.js';
4
4
 
5
5
  function build(yargs) {
6
6
  return yargs;
@@ -8,10 +8,9 @@ function build(yargs) {
8
8
 
9
9
  async function run({ ...options } = {}) {
10
10
  const client = new WordPressClient(options);
11
- const [total, firstPostDate, lastPostDate] = await Promise.all([
11
+ const [total, [firstPostDate, lastPostDate]] = await Promise.all([
12
12
  client.posts.count(options),
13
- getFirstPostDate(client),
14
- getLastPostDate(client),
13
+ client.posts.dateRange(),
15
14
  ]);
16
15
  const totalStrLength = `${total}`.length;
17
16
  console.log();
package/cli/utils.js CHANGED
@@ -11,18 +11,6 @@ export function parseDate(value) {
11
11
  return Date.parse(`${value}Z`);
12
12
  }
13
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
14
  export function getYear(dateStr) {
27
15
  return new Date(dateStr).getFullYear();
28
16
  }
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.14",
20
+ "@miso.ai/server-commons": "0.6.3-beta.15",
21
21
  "axios": "^1.6.2",
22
22
  "axios-retry": "^3.3.1"
23
23
  },
24
- "version": "0.6.3-beta.14"
24
+ "version": "0.6.3-beta.15"
25
25
  }
@@ -6,6 +6,7 @@ import EntityTransformStream from './transform.js';
6
6
  import EntityPresenceStream from './presence.js';
7
7
  import defaultTransform from './transform-default.js';
8
8
  import legacyTransform from './transform-legacy.js';
9
+ import { getFirstPostDate, getLastPostDate, getYear } from './utils.js';
9
10
 
10
11
  export default class Entities {
11
12
 
@@ -72,6 +73,10 @@ export default class Entities {
72
73
  }
73
74
 
74
75
  async getAll(options) {
76
+ return this.all(options);
77
+ }
78
+
79
+ async all(options) {
75
80
  return stream.collect(await this.stream(options));
76
81
  }
77
82
 
@@ -87,6 +92,18 @@ export default class Entities {
87
92
  return new EntityPresenceStream(this._client, this.name, options);
88
93
  }
89
94
 
95
+ async dateRange() {
96
+ // TODO: options?
97
+ return Promise.all([
98
+ getFirstPostDate(this._client),
99
+ getLastPostDate(this._client),
100
+ ]);
101
+ }
102
+
103
+ async yearRange() {
104
+ return (await this.dateRange()).map(getYear);
105
+ }
106
+
90
107
  get index() {
91
108
  return this._index;
92
109
  }
@@ -0,0 +1,15 @@
1
+ export async function getFirstPostDate(client, options) {
2
+ return getPostDate(client, 'asc', options);
3
+ }
4
+
5
+ export async function getLastPostDate(client, options) {
6
+ return getPostDate(client, 'desc', options);
7
+ }
8
+
9
+ async function getPostDate(client, order, options = {}) {
10
+ return (await client.posts.getAll({ ...options, limit: 1, order, fields: ['date_gmt'] }))[0].date_gmt;
11
+ }
12
+
13
+ export function getYear(dateStr) {
14
+ return new Date(dateStr).getFullYear();
15
+ }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '0.6.3-beta.14';
1
+ export default '0.6.3-beta.15';