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

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/entities.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Transform } from 'stream';
2
+ import { pipeline } from 'stream/promises';
2
3
  import split2 from 'split2';
3
4
  import { stream, parseDuration } from '@miso.ai/server-commons';
4
5
  import { WordPressClient } from '../src/index.js';
@@ -52,12 +53,12 @@ export async function runTerms(client, name, options) {
52
53
  }
53
54
 
54
55
  export async function runGet(client, name, { transform, ...options }) {
55
- await stream.pipelineToStdout(
56
+ await pipeline(
56
57
  await client.entities(name).stream({
57
58
  ...options,
58
59
  transform,
59
60
  }),
60
- stream.stringify(),
61
+ new stream.OutputStream(),
61
62
  );
62
63
  }
63
64
 
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 { getYear } from './utils.js';
4
3
 
5
4
  function build(yargs) {
6
5
  return yargs;
package/cli/utils.js CHANGED
@@ -1,19 +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 function getYear(dateStr) {
15
- return new Date(dateStr).getFullYear();
16
- }
15
+ */
17
16
 
18
17
  export function buildForEntities(yargs) {
19
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.15",
20
+ "@miso.ai/server-commons": "0.6.3-beta.17",
21
21
  "axios": "^1.6.2",
22
22
  "axios-retry": "^3.3.1"
23
23
  },
24
- "version": "0.6.3-beta.15"
24
+ "version": "0.6.3-beta.17"
25
25
  }
@@ -1,12 +1,11 @@
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';
7
7
  import defaultTransform from './transform-default.js';
8
8
  import legacyTransform from './transform-legacy.js';
9
- import { getFirstPostDate, getLastPostDate, getYear } from './utils.js';
10
9
 
11
10
  export default class Entities {
12
11
 
@@ -95,8 +94,8 @@ export default class Entities {
95
94
  async dateRange() {
96
95
  // TODO: options?
97
96
  return Promise.all([
98
- getFirstPostDate(this._client),
99
- getLastPostDate(this._client),
97
+ getPostDate(this._client, 'asc'),
98
+ getPostDate(this._client, 'desc'),
100
99
  ]);
101
100
  }
102
101
 
@@ -118,15 +117,6 @@ export default class Entities {
118
117
 
119
118
  }
120
119
 
121
- function aggregateIds(records, propName) {
122
- return Array.from(records.reduce((idSet, record) => {
123
- for (const id of asArray(record[propName])) {
124
- idSet.add(id);
125
- }
126
- return idSet;
127
- }, new Set()));
128
- }
129
-
130
120
  async function getTransformFn(client, name, transform) {
131
121
  switch (transform) {
132
122
  case 'default':
@@ -150,3 +140,16 @@ async function getTransformFn(client, name, transform) {
150
140
  }
151
141
  return undefined;
152
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, options = {}) {
165
- const { after, before, modifiedAfter, modifiedBefore, order, orderBy, page, pageSize, offset, include, exclude } = options;
166
- let { fields } = options;
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.15';
1
+ export default '0.6.3-beta.17';
@@ -1,15 +0,0 @@
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
- }