@wirecat/cli-core 0.704.0 → 0.705.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/CHANGELOG.md +86 -0
- package/dist/cli/bot/api-http.d.ts +8 -2
- package/dist/cli/bot/api-http.js +20 -4
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +3 -3
- package/dist/cli/messenger/store-maintenance-command.js +6 -2
- package/dist/cli/service-api-call.d.ts +13 -3
- package/dist/cli/service-api-call.js +19 -9
- package/dist/cli/service-api-manifest.d.ts +11 -2
- package/dist/cli/service-api-manifest.js +30 -9
- package/dist/cli/service-api.d.ts +14 -6
- package/dist/cli/service-api.js +137 -29
- package/dist/cli/token-session.d.ts +5 -2
- package/dist/cli/token-session.js +13 -4
- package/dist/content/cli/index.d.ts +33 -0
- package/dist/content/cli/index.js +368 -0
- package/dist/content/index.d.ts +8 -0
- package/dist/content/index.js +7 -0
- package/dist/content/manifest/index.d.ts +4 -0
- package/dist/content/manifest/index.js +4 -0
- package/dist/content/manifest/manifest.d.ts +92 -0
- package/dist/content/manifest/manifest.js +137 -0
- package/dist/content/manifest/map.d.ts +25 -0
- package/dist/content/manifest/map.js +94 -0
- package/dist/content/manifest/source.d.ts +41 -0
- package/dist/content/manifest/source.js +288 -0
- package/dist/content/manifest/writer.d.ts +26 -0
- package/dist/content/manifest/writer.js +133 -0
- package/dist/content/source.d.ts +64 -0
- package/dist/content/source.js +2 -0
- package/dist/content/sync.d.ts +61 -0
- package/dist/content/sync.js +387 -0
- package/dist/content/testing/index.d.ts +4 -0
- package/dist/content/testing/index.js +4 -0
- package/dist/content/testing/source-contract.d.ts +38 -0
- package/dist/content/testing/source-contract.js +274 -0
- package/dist/content/testing/source.d.ts +55 -0
- package/dist/content/testing/source.js +276 -0
- package/dist/content/testing/sync-contract.d.ts +10 -0
- package/dist/content/testing/sync-contract.js +172 -0
- package/dist/content/testing/write-contract.d.ts +14 -0
- package/dist/content/testing/write-contract.js +102 -0
- package/dist/content/writer.d.ts +64 -0
- package/dist/content/writer.js +38 -0
- package/dist/content/writes.d.ts +58 -0
- package/dist/content/writes.js +129 -0
- package/dist/documents/file-mirror-model.d.ts +3 -1
- package/dist/documents/index.d.ts +3 -3
- package/dist/documents/index.js +1 -1
- package/dist/domain/content.d.ts +102 -0
- package/dist/domain/content.js +11 -0
- package/dist/errors/reasons.js +14 -0
- package/dist/manifest/index.d.ts +21 -7
- package/dist/manifest/index.js +7 -4
- package/dist/services/documents/mirrors.d.ts +13 -1
- package/dist/services/documents/mirrors.js +12 -3
- package/dist/services/files/mirror.d.ts +20 -8
- package/dist/services/files/mirror.js +84 -27
- package/dist/services/files/versions.d.ts +17 -7
- package/dist/services/files/versions.js +56 -21
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/recover.js +2 -0
- package/dist/store/sqlite/account-purge.js +7 -0
- package/dist/store/sqlite/content.d.ts +100 -0
- package/dist/store/sqlite/content.js +375 -0
- package/dist/store/sqlite/entity-types.d.ts +1 -0
- package/dist/store/sqlite/entity-types.js +1 -0
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +26 -0
- package/dist/store/sqlite/schema.d.ts +1140 -0
- package/dist/store/sqlite/schema.js +100 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/package.json +12 -4
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import { annotate, sharedCommand } from "@wirecat/cli-base/commands";
|
|
4
|
+
import { InvalidArgumentError } from "commander";
|
|
5
|
+
import * as v from "valibot";
|
|
6
|
+
import { answerEntity } from "../../cli/answer-entity.js";
|
|
7
|
+
import { environmentOf, inCommandRun, outputFor, runBudgetOf } from "../../cli/context.js";
|
|
8
|
+
import { honoursDryRun } from "../../cli/dry-run-guard.js";
|
|
9
|
+
import { FETCH, LOCAL_READ, NO_EFFECTS, REMOTE_WRITE } from "../../cli/effects.js";
|
|
10
|
+
import { itemOf, listOf, renderAnswer } from "../../cli/envelope.js";
|
|
11
|
+
import { listQuery, nativeTermLists, termField, typedQuery, withQuery } from "../../cli/list-query.js";
|
|
12
|
+
import { terminalAsker } from "../../cli/messenger/ask.js";
|
|
13
|
+
import { CONTENT_KINDS, POST_STATUSES, POST_TYPES } from "../../domain/content.js";
|
|
14
|
+
import { aheadOf } from "../../domain/moment.js";
|
|
15
|
+
import { count, text } from "../../entities/fields.js";
|
|
16
|
+
import { refusedPlace } from "../../sends/upload.js";
|
|
17
|
+
import { syncContent } from "../sync.js";
|
|
18
|
+
import { createPost, deletePost, publishPost, schedulePost, unpublishPost, updatePost, } from "../writes.js";
|
|
19
|
+
const MOST = 500;
|
|
20
|
+
const integer = (most) => (value) => {
|
|
21
|
+
const number = Number(value);
|
|
22
|
+
if (!Number.isSafeInteger(number) || number < 1 || number > most)
|
|
23
|
+
throw new InvalidArgumentError(`a whole number from 1 to ${most}`);
|
|
24
|
+
return number;
|
|
25
|
+
};
|
|
26
|
+
const POSTS_QUERY = {
|
|
27
|
+
entity: "content_post",
|
|
28
|
+
backend: "native",
|
|
29
|
+
fields: [
|
|
30
|
+
termField("status", "enum", "status:published", {
|
|
31
|
+
values: [...POST_STATUSES],
|
|
32
|
+
relation: "repeat for any of several",
|
|
33
|
+
}),
|
|
34
|
+
termField("type", "enum", "type:page", { values: [...POST_TYPES] }),
|
|
35
|
+
termField("channel", "kw", "channel:site", { relation: "the channel's id, as channels list shows it" }),
|
|
36
|
+
termField("term", "kw", "term:12", { relation: "a tag's or category's id, as terms list shows it" }),
|
|
37
|
+
termField("author", "kw", "author:3", { relation: "the author's id, as authors list shows it" }),
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
const TIMES = new Set(["createdAt", "updatedAt", "publishedAt", "scheduledFor"]);
|
|
41
|
+
const snake = (name) => name.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
42
|
+
/** A source's text is someone else's: an agent reads these fields as data, never as instructions. */
|
|
43
|
+
const UNTRUSTED = {
|
|
44
|
+
author: ["name", "slug"],
|
|
45
|
+
term: ["name", "slug"],
|
|
46
|
+
post: ["title", "body", "excerpt", "slug", "url"],
|
|
47
|
+
};
|
|
48
|
+
const viewOf = (item, extra = {}) => ({
|
|
49
|
+
kind: item.kind,
|
|
50
|
+
...Object.fromEntries(Object.entries(item.record).map(([name, value]) => [
|
|
51
|
+
snake(name),
|
|
52
|
+
TIMES.has(name) && typeof value === "number" ? new Date(value).toISOString() : value,
|
|
53
|
+
])),
|
|
54
|
+
...extra,
|
|
55
|
+
deleted: item.deletedAt !== null,
|
|
56
|
+
untrusted: UNTRUSTED[item.kind] ?? [],
|
|
57
|
+
});
|
|
58
|
+
const postBody = (post) => viewOf({ kind: "post", record: post, deletedAt: null, syncedAt: 0 });
|
|
59
|
+
const contentView = v.looseObject({ kind: v.picklist(CONTENT_KINDS), external_id: text, deleted: v.boolean() });
|
|
60
|
+
const channelView = v.looseObject({ external_id: text, kind: text, network: text, name: text });
|
|
61
|
+
const contentWrite = v.looseObject({ operation_id: text, post: v.optional(contentView) });
|
|
62
|
+
const contentSync = v.looseObject({
|
|
63
|
+
provider: text,
|
|
64
|
+
account: text,
|
|
65
|
+
state: v.picklist(["partial", "complete"]),
|
|
66
|
+
complete: v.boolean(),
|
|
67
|
+
channels: count,
|
|
68
|
+
due: count,
|
|
69
|
+
metrics: count,
|
|
70
|
+
synced: v.array(v.looseObject({
|
|
71
|
+
kind: v.picklist(CONTENT_KINDS),
|
|
72
|
+
round: v.picklist(["full", "changes"]),
|
|
73
|
+
state: v.picklist(["partial", "complete"]),
|
|
74
|
+
saved: count,
|
|
75
|
+
unlisted: count,
|
|
76
|
+
})),
|
|
77
|
+
gaps: v.array(v.looseObject({ kind: v.picklist(CONTENT_KINDS), message: text })),
|
|
78
|
+
});
|
|
79
|
+
const dayOrTime = (flag) => (typed) => {
|
|
80
|
+
const at = Date.parse(typed);
|
|
81
|
+
if (Number.isNaN(at))
|
|
82
|
+
throw new InvalidArgumentError(`${flag} takes a day (YYYY-MM-DD) or an ISO 8601 time`);
|
|
83
|
+
return at;
|
|
84
|
+
};
|
|
85
|
+
const collect = (value, previous) => [...previous, value];
|
|
86
|
+
const addContentCommandsDefinition = (program, options) => {
|
|
87
|
+
const now = () => options.now?.() ?? Date.now();
|
|
88
|
+
const within = (command, readOnly, work) => inCommandRun(command, async () => {
|
|
89
|
+
const run = await options.open(command, { readOnly });
|
|
90
|
+
let body;
|
|
91
|
+
try {
|
|
92
|
+
body = await work(run);
|
|
93
|
+
}
|
|
94
|
+
finally {
|
|
95
|
+
await run.close?.();
|
|
96
|
+
}
|
|
97
|
+
renderAnswer(command, outputFor(command), body);
|
|
98
|
+
});
|
|
99
|
+
const example = (command, ...lines) => annotate(command, { examples: lines.map((line) => `${options.app.command} work ${line}`) });
|
|
100
|
+
const paging = (command) => command
|
|
101
|
+
.option("--limit <n>", `rows per page, 1–${MOST}`, integer(MOST), 50)
|
|
102
|
+
.option("--page <n>", "which page, starting at 1", integer(1_000_000), 1);
|
|
103
|
+
example(answerEntity(annotate(program.command("sync"), { effects: FETCH, offline: false, cooperative: true, partial: true }), "content_sync", contentSync).description("bring the copy of your posts up to date: channels, authors, tags and categories, and posts that changed since " +
|
|
104
|
+
"the last sync, or everything with --rescan. Once a day it also finds what the site deleted for good; trash " +
|
|
105
|
+
"stays a status. A site whose address changed, or a sign-in that sees only part, marks nothing deleted"), "sync", "sync --rescan")
|
|
106
|
+
.option("--rescan", "list everything again, every id too, dropping a round in progress")
|
|
107
|
+
.option("--max-pages <pages>", "at most this many requests to the source in this run", integer(100_000))
|
|
108
|
+
.action(async (opts, command) => {
|
|
109
|
+
const { signal } = environmentOf(command);
|
|
110
|
+
await within(command, false, async (run) => {
|
|
111
|
+
const report = await syncContent(run.source(), run.store, run.account, {
|
|
112
|
+
now: now(),
|
|
113
|
+
budget: runBudgetOf(command, opts.maxPages),
|
|
114
|
+
...(signal ? { signal } : {}),
|
|
115
|
+
...(opts.rescan ? { rescan: true } : {}),
|
|
116
|
+
});
|
|
117
|
+
const failed = report.synced.filter((one) => one.error !== undefined);
|
|
118
|
+
const next = report.state === "partial" && report.progress.steps > 0
|
|
119
|
+
? [
|
|
120
|
+
{
|
|
121
|
+
kind: "command",
|
|
122
|
+
step: "content.sync",
|
|
123
|
+
command: "sync",
|
|
124
|
+
args: opts.maxPages === undefined ? {} : { max_pages: opts.maxPages },
|
|
125
|
+
why: failed.length
|
|
126
|
+
? "a kind failed to sync; running sync again retries it"
|
|
127
|
+
: "the sync stopped before its end; running it again goes on from there",
|
|
128
|
+
safe_to_auto_execute: true,
|
|
129
|
+
},
|
|
130
|
+
]
|
|
131
|
+
: undefined;
|
|
132
|
+
const issues = [
|
|
133
|
+
...failed.map((one) => ({
|
|
134
|
+
code: "provider_error",
|
|
135
|
+
reason: "sync.partial",
|
|
136
|
+
source: `content:${one.kind}`,
|
|
137
|
+
})),
|
|
138
|
+
...report.synced
|
|
139
|
+
.filter((one) => one.pass === "held")
|
|
140
|
+
.map((one) => ({
|
|
141
|
+
code: "validation_error",
|
|
142
|
+
reason: "content.unlisted-held",
|
|
143
|
+
source: `content:${one.kind}`,
|
|
144
|
+
})),
|
|
145
|
+
];
|
|
146
|
+
return itemOf(report, {
|
|
147
|
+
...(report.state === "partial" || issues.length
|
|
148
|
+
? { meta: { complete: false, ...(issues.length ? { issues } : {}) } }
|
|
149
|
+
: {}),
|
|
150
|
+
...(next ? { next } : {}),
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
const channels = annotate(program.command("channels"), { effects: NO_EFFECTS }).description("the sites and social accounts this profile publishes on");
|
|
155
|
+
example(answerEntity(annotate(channels.command("list"), { effects: LOCAL_READ }), "content_channel", channelView).description("the channels copied by the last sync"), "channels list").action(async (_opts, command) => {
|
|
156
|
+
await within(command, true, async (run) => {
|
|
157
|
+
const items = (await run.store.content.channels(run.account)).map((one) => ({
|
|
158
|
+
...Object.fromEntries(Object.entries(one).map(([name, value]) => [snake(name), value])),
|
|
159
|
+
untrusted: ["name", "handle"],
|
|
160
|
+
}));
|
|
161
|
+
return listOf("channels list", { items, limit: items.length, page: 1, has_more: false });
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
const posts = annotate(program.command("posts"), { effects: NO_EFFECTS }).description("posts and pages as last synced, with their text as Markdown");
|
|
165
|
+
example(paging(withQuery(answerEntity(annotate(posts.command("list"), { effects: LOCAL_READ }), "content_post", contentView), POSTS_QUERY)
|
|
166
|
+
.description("posts copied from the source, newest change first; run sync to bring them up to date")
|
|
167
|
+
.option("--since <day>", "published on or after this day or time", dayOrTime("--since"))
|
|
168
|
+
.option("--until <day>", "published before this day or time", dayOrTime("--until"))), "posts list status:draft", "posts list type:page --since 2026-01-01").action(async (words, opts, command) => {
|
|
169
|
+
const lists = nativeTermLists(listQuery(typedQuery(words), POSTS_QUERY, "posts list"), "posts list", ["status"]);
|
|
170
|
+
if ([...lists.values()].flat().some((one) => one.operator !== "term" && one.operator !== "phrase"))
|
|
171
|
+
throw new InvalidArgumentError("posts list takes field:value terms, each one whole value");
|
|
172
|
+
const statuses = (lists.get("status") ?? []).map((one) => String(one.value).toLowerCase());
|
|
173
|
+
const terms = new Map([...lists].filter(([field]) => field !== "status").map(([field, [one]]) => [field, String(one?.value)]));
|
|
174
|
+
await within(command, true, async (run) => {
|
|
175
|
+
const filter = {
|
|
176
|
+
...(statuses.length ? { statuses } : {}),
|
|
177
|
+
...(terms.has("type") ? { type: terms.get("type") } : {}),
|
|
178
|
+
...(terms.has("channel") ? { channel: terms.get("channel") } : {}),
|
|
179
|
+
...(terms.has("term") ? { term: terms.get("term") } : {}),
|
|
180
|
+
...(terms.has("author") ? { author: terms.get("author") } : {}),
|
|
181
|
+
...(opts.since === undefined ? {} : { since: opts.since }),
|
|
182
|
+
...(opts.until === undefined ? {} : { until: opts.until }),
|
|
183
|
+
limit: opts.limit,
|
|
184
|
+
offset: (opts.page - 1) * opts.limit,
|
|
185
|
+
};
|
|
186
|
+
const found = await run.store.content.list(run.account, "post", filter);
|
|
187
|
+
return listOf("posts list", {
|
|
188
|
+
items: found.items.map((one) => viewOf({ ...one, record: { ...one.record, body: undefined } })),
|
|
189
|
+
limit: opts.limit,
|
|
190
|
+
page: opts.page,
|
|
191
|
+
has_more: found.hasMore,
|
|
192
|
+
...(words.length ? { args: { query: words } } : {}),
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
example(answerEntity(annotate(posts.command("show"), { effects: LOCAL_READ }), "content_post_detail", contentView)
|
|
197
|
+
.description("one post with its text, its authors and tags by name, its earlier versions and its last numbers")
|
|
198
|
+
.argument("<post>", "the post's id at the source, as posts list shows it"), "posts show 10").action(async (id, _opts, command) => {
|
|
199
|
+
await within(command, true, async (run) => {
|
|
200
|
+
const found = await run.store.content.get(run.account, "post", id);
|
|
201
|
+
if (!found)
|
|
202
|
+
throw new CliError("not_found", `no post ${id} in the copy; run sync, then try again`);
|
|
203
|
+
const named = async (kind, ids = []) => (await Promise.all(ids.map((one) => run.store.content.get(run.account, kind, one)))).flatMap((one) => one ? [{ external_id: one.record.externalId, name: one.record.name }] : []);
|
|
204
|
+
const people = new Map((await run.store.content.people(run.account, found.record.authors ?? [])).map((one) => [one.author, one]));
|
|
205
|
+
const versions = await run.store.content.revisions(run.account, id);
|
|
206
|
+
const [metric] = await run.store.content.metrics(run.account, id, 1);
|
|
207
|
+
return itemOf(viewOf(found, {
|
|
208
|
+
authors_named: (await named("author", found.record.authors)).map((one) => ({
|
|
209
|
+
...one,
|
|
210
|
+
...(people.has(one.external_id) ? { person: people.get(one.external_id)?.person } : {}),
|
|
211
|
+
})),
|
|
212
|
+
terms_named: await named("term", found.record.terms),
|
|
213
|
+
versions: versions.map((one) => ({
|
|
214
|
+
title: one.title,
|
|
215
|
+
status: one.status,
|
|
216
|
+
reason: one.reason,
|
|
217
|
+
at: new Date(one.createdAt).toISOString(),
|
|
218
|
+
})),
|
|
219
|
+
...(metric ? { metrics: { ...metric, at: new Date(metric.at).toISOString() } } : {}),
|
|
220
|
+
}));
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
example(paging(answerEntity(annotate(posts.command("search"), { effects: LOCAL_READ }), "content_hit", contentView)
|
|
224
|
+
.description("find posts in the copy by the words of their title and text")
|
|
225
|
+
.argument("<words...>", "every word must match; prefixes of three letters or more match too")), 'posts search "pricing change"').action(async (words, opts, command) => {
|
|
226
|
+
await within(command, true, async (run) => {
|
|
227
|
+
const found = await run.store.content.find({
|
|
228
|
+
words,
|
|
229
|
+
accounts: [run.account],
|
|
230
|
+
limit: opts.limit,
|
|
231
|
+
offset: (opts.page - 1) * opts.limit,
|
|
232
|
+
});
|
|
233
|
+
return listOf("posts search", {
|
|
234
|
+
items: found.items.map((hit) => viewOf({ ...hit.item, record: { ...hit.item.record, body: undefined } }, { excerpt: hit.excerpt })),
|
|
235
|
+
limit: opts.limit,
|
|
236
|
+
page: opts.page,
|
|
237
|
+
has_more: found.hasMore,
|
|
238
|
+
args: { words },
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
for (const [kind, plural, what] of [
|
|
243
|
+
["author", "authors", "the source's authors, each with the person the store knows by the same e-mail"],
|
|
244
|
+
["term", "terms", "the source's tags and categories"],
|
|
245
|
+
]) {
|
|
246
|
+
const group = annotate(program.command(plural), { effects: NO_EFFECTS }).description(what);
|
|
247
|
+
example(paging(answerEntity(annotate(group.command("list"), { effects: LOCAL_READ }), `content_${kind}`, contentView)).description(`${plural} copied from the source`), `${plural} list`).action(async (opts, command) => {
|
|
248
|
+
await within(command, true, async (run) => {
|
|
249
|
+
const found = await run.store.content.list(run.account, kind, {
|
|
250
|
+
limit: opts.limit,
|
|
251
|
+
offset: (opts.page - 1) * opts.limit,
|
|
252
|
+
});
|
|
253
|
+
const people = kind === "author"
|
|
254
|
+
? new Map((await run.store.content.people(run.account, found.items.map((one) => one.record.externalId))).map((one) => [one.author, one.person]))
|
|
255
|
+
: new Map();
|
|
256
|
+
return listOf(`${plural} list`, {
|
|
257
|
+
items: found.items.map((one) => viewOf(one, people.has(one.record.externalId) ? { person: people.get(one.record.externalId) } : {})),
|
|
258
|
+
limit: opts.limit,
|
|
259
|
+
page: opts.page,
|
|
260
|
+
has_more: found.hasMore,
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
const metrics = annotate(program.command("metrics"), { effects: NO_EFFECTS }).description("readings of a post's numbers, one per sync, each kept");
|
|
266
|
+
example(answerEntity(annotate(metrics.command("show"), { effects: LOCAL_READ }), "content_metric", v.looseObject({ post: text, at: text }))
|
|
267
|
+
.description("a post's readings, the newest first")
|
|
268
|
+
.argument("<post>", "the post's id at the source"), "metrics show 10").action(async (id, _opts, command) => {
|
|
269
|
+
await within(command, true, async (run) => {
|
|
270
|
+
const items = (await run.store.content.metrics(run.account, id)).map((one) => ({
|
|
271
|
+
...one,
|
|
272
|
+
at: new Date(one.at).toISOString(),
|
|
273
|
+
}));
|
|
274
|
+
return listOf("metrics show", { items, limit: items.length, page: 1, has_more: false });
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
if (!options.writes)
|
|
278
|
+
return;
|
|
279
|
+
const contextOf = (run, command) => {
|
|
280
|
+
if (!run.writes)
|
|
281
|
+
throw new CliError("configuration_error", "this profile cannot write to its source");
|
|
282
|
+
return {
|
|
283
|
+
store: run.store,
|
|
284
|
+
account: run.account,
|
|
285
|
+
writes: run.writes(command),
|
|
286
|
+
ask: terminalAsker(command),
|
|
287
|
+
source: run.source,
|
|
288
|
+
now,
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
const bodyOf = (run, path) => {
|
|
292
|
+
if (path === undefined)
|
|
293
|
+
return undefined;
|
|
294
|
+
if (path !== "-" && refusedPlace(path, options.app, run.env ?? process.env))
|
|
295
|
+
throw new CliError("validation_error", `--body-file may not read ${path}: it holds sign-ins or state`, {
|
|
296
|
+
param: "--body-file",
|
|
297
|
+
});
|
|
298
|
+
return readFileSync(path === "-" ? 0 : path, "utf8");
|
|
299
|
+
};
|
|
300
|
+
const answered = (operationId, post, extra = {}) => itemOf({ operation_id: operationId, ...(post ? { post: postBody(post) } : {}), ...extra });
|
|
301
|
+
const write = (name, description) => answerEntity(annotate(posts.command(name), { effects: REMOTE_WRITE, offline: false }), "content_write", contentWrite).description(description);
|
|
302
|
+
const fields = (command) => command
|
|
303
|
+
.option("--title <title>", "the post's title")
|
|
304
|
+
.option("--body-file <path>", "the text as Markdown, from a file, or - for stdin")
|
|
305
|
+
.option("--excerpt <text>", "the short text lists show")
|
|
306
|
+
.option("--slug <slug>", "the address's last part")
|
|
307
|
+
.option("--term <id>", "a tag's or category's id, as terms list shows it; repeat it; replaces the list", collect, []);
|
|
308
|
+
const fieldsOf = (run, typed) => {
|
|
309
|
+
const body = bodyOf(run, typed.bodyFile);
|
|
310
|
+
return {
|
|
311
|
+
...(typed.title === undefined ? {} : { title: typed.title }),
|
|
312
|
+
...(body === undefined ? {} : { body }),
|
|
313
|
+
...(typed.excerpt === undefined ? {} : { excerpt: typed.excerpt }),
|
|
314
|
+
...(typed.slug === undefined ? {} : { slug: typed.slug }),
|
|
315
|
+
...(typed.term.length ? { terms: typed.term } : {}),
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
example(fields(write("create", "write a new draft; publishing is its own step, posts publish")).option("--type <type>", `${POST_TYPES.join(" or ")}; post when left out`), "posts create --title 'Version 3' --body-file notes.md").action(async (typed, command) => {
|
|
319
|
+
if (typed.type !== undefined && !POST_TYPES.includes(typed.type))
|
|
320
|
+
throw new InvalidArgumentError(`--type is ${POST_TYPES.join(" or ")}`);
|
|
321
|
+
await within(command, false, async (run) => {
|
|
322
|
+
const done = await createPost(contextOf(run, command), {
|
|
323
|
+
...fieldsOf(run, typed),
|
|
324
|
+
...(typed.type ? { type: typed.type } : {}),
|
|
325
|
+
});
|
|
326
|
+
return answered(done.operationId, done.post);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
example(fields(write("update", "change a post's fields; a published or scheduled post's change is public and checks posts.publish too").argument("<post>", "the post's id at the source")).option("--replace-body", "write the body over a post whose blocks or embeds Markdown cannot keep, flattening them"), "posts update 10 --title 'Version 2 is out now'").action(async (id, typed, command) => {
|
|
330
|
+
await within(command, false, async (run) => {
|
|
331
|
+
const done = await updatePost(contextOf(run, command), id, fieldsOf(run, typed), {
|
|
332
|
+
...(typed.replaceBody ? { replaceBody: true } : {}),
|
|
333
|
+
});
|
|
334
|
+
return answered(done.operationId, done.post);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
for (const [name, description, act] of [
|
|
338
|
+
["publish", "publish a post now; a published post is answered as it is", publishPost],
|
|
339
|
+
["unpublish", "bring a published or scheduled post back to a draft", unpublishPost],
|
|
340
|
+
])
|
|
341
|
+
example(write(name, description).argument("<post>", "the post's id at the source"), `posts ${name} 11`).action(async (id, _opts, command) => {
|
|
342
|
+
await within(command, false, async (run) => {
|
|
343
|
+
const done = await act(contextOf(run, command), id);
|
|
344
|
+
return answered(done.operationId, done.post, done.unchanged ? { unchanged: true } : {});
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
example(write("schedule", "publish a post at a later time; checks posts.publish too")
|
|
348
|
+
.argument("<post>", "the post's id at the source")
|
|
349
|
+
.requiredOption("--at <time>", "when it goes out: an ISO 8601 time, a day, or 3d from now; it must be ahead", (typed) => aheadOf(typed, "--at", Date.now())), "posts schedule 11 --at 2026-12-01T09:00:00Z").action(async (id, opts, command) => {
|
|
350
|
+
await within(command, false, async (run) => {
|
|
351
|
+
const done = await schedulePost(contextOf(run, command), id, opts.at);
|
|
352
|
+
return answered(done.operationId, done.post);
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
example(write("delete", "move a post to the source's trash, from which it comes back; --force deletes it for good")
|
|
356
|
+
.argument("<post>", "the post's id at the source")
|
|
357
|
+
.option("--force", "delete it for good, past the trash; checks posts.delete.force"), "posts delete 11").action(async (id, opts, command) => {
|
|
358
|
+
await within(command, false, async (run) => {
|
|
359
|
+
const done = await deletePost(contextOf(run, command), id, opts.force ? { force: true } : {});
|
|
360
|
+
return answered(done.operationId, done.post, { deleted: done.deleted });
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* The content commands: `sync`, `channels list`, `posts list|show|search`, `authors list`, `terms list`,
|
|
366
|
+
* `metrics show`, and with `writes` `posts create|update|publish|schedule|unpublish|delete`.
|
|
367
|
+
*/
|
|
368
|
+
export const addContentCommands = honoursDryRun(sharedCommand(addContentCommandsDefinition));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { CHANNEL_KINDS, type ChannelKind, CONTENT_KINDS, type ContentAuthor, type ContentChannel, type ContentKind, type ContentMedia, type ContentMetric, type ContentPost, type ContentRecords, type ContentTerm, POST_STATUSES, POST_TYPES, type PostStatus, type PostType, TERM_KINDS, type TermKind, } from "../domain/content.js";
|
|
2
|
+
export { addContentCommands, type ContentCommandOptions, type ContentRun } from "./cli/index.js";
|
|
3
|
+
export * from "./manifest/index.js";
|
|
4
|
+
export type { ContentCallContext, ContentChanges, ContentGap, ContentIdPage, ContentPage, ContentSource, ContentSourceTraits, } from "./source.js";
|
|
5
|
+
export { GET_UNSUPPORTED } from "./source.js";
|
|
6
|
+
export { type ContentSyncOptions, type ContentSyncReport, type ContentSyncResult, contentCursorName, contentGapsOf, syncContent, } from "./sync.js";
|
|
7
|
+
export { CONTENT_WRITE_DEFAULTS, CONTENT_WRITE_KEYS, type ContentDraft, type ContentFields, type ContentWriteOptions, type ContentWriter, contentAlsoChecks, contentConflict, POSTS_DELETE_FORCE_KEY, POSTS_PUBLISH_KEY, } from "./writer.js";
|
|
8
|
+
export { type ContentWriteContext, type ContentWrites, type ContentWritten, createPost, deletePost, publishPost, schedulePost, unpublishPost, updatePost, } from "./writes.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { CHANNEL_KINDS, CONTENT_KINDS, POST_STATUSES, POST_TYPES, TERM_KINDS, } from "../domain/content.js";
|
|
2
|
+
export { addContentCommands } from "./cli/index.js";
|
|
3
|
+
export * from "./manifest/index.js";
|
|
4
|
+
export { GET_UNSUPPORTED } from "./source.js";
|
|
5
|
+
export { contentCursorName, contentGapsOf, syncContent, } from "./sync.js";
|
|
6
|
+
export { CONTENT_WRITE_DEFAULTS, CONTENT_WRITE_KEYS, contentAlsoChecks, contentConflict, POSTS_DELETE_FORCE_KEY, POSTS_PUBLISH_KEY, } from "./writer.js";
|
|
7
|
+
export { createPost, deletePost, publishPost, schedulePost, unpublishPost, updatePost, } from "./writes.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BODY_FORMATS, type BodyFormat, type ContentChangesCall, type ContentManifest, type ContentManifestEntity, type ContentManifestWrites, parseContentManifest, } from "./manifest.js";
|
|
2
|
+
export { CONTENT_FIELDS, mapContentRecord, utcEpoch } from "./map.js";
|
|
3
|
+
export { type ContentManifestSourceOptions, type ContentReadCall, contentSourceFromManifest } from "./source.js";
|
|
4
|
+
export { type ContentManifestWriterOptions, type ContentWriteCall, contentWriterFromManifest } from "./writer.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { ServiceApiManifest } from "../../cli/service-api-manifest.js";
|
|
2
|
+
import type { CrmOperationCall, CrmRule } from "../../crm/manifest/manifest.js";
|
|
3
|
+
import { type ChannelKind, type ContentKind, TERM_KINDS } from "../../domain/content.js";
|
|
4
|
+
/** How the source keeps a post's text, which the engine turns into Markdown and back. */
|
|
5
|
+
export declare const BODY_FORMATS: readonly ["markdown", "html", "wp-blocks"];
|
|
6
|
+
export type BodyFormat = (typeof BODY_FORMATS)[number];
|
|
7
|
+
export interface ContentChangesCall extends CrmOperationCall {
|
|
8
|
+
/** How `{since}` is written: ISO in UTC, or epoch seconds or ms as digits. */
|
|
9
|
+
since: "iso" | "seconds" | "ms";
|
|
10
|
+
/**
|
|
11
|
+
* The answer is sorted by `field`, a time, ascending, and the source reads strictly after `{since}`: each next page
|
|
12
|
+
* starts `step` ms before the last row's time, so a row changed mid-round never moves a page over another row.
|
|
13
|
+
*/
|
|
14
|
+
keyset?: {
|
|
15
|
+
field: string;
|
|
16
|
+
step?: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** One call a kind is read by; a kind read from several (tags and categories, posts and pages) lists one per call. */
|
|
20
|
+
export interface ContentManifestEntity {
|
|
21
|
+
/** Every row, page by page by the operation's own `pagination`. Sorted by id, so a change never moves a page. */
|
|
22
|
+
list: CrmOperationCall;
|
|
23
|
+
/** Rows changed since `{since}`; absent, every sync lists the kind in full. */
|
|
24
|
+
changes?: ContentChangesCall;
|
|
25
|
+
/** Every id, to find deletions; absent, `list`. */
|
|
26
|
+
ids?: CrmOperationCall;
|
|
27
|
+
/** One row by `{id}`; a 404 is a row deleted for good. */
|
|
28
|
+
get?: CrmOperationCall;
|
|
29
|
+
map: Readonly<Record<string, CrmRule>>;
|
|
30
|
+
/** A post's text: where it is and in what format; `fallback` when the sign-in may not read the first. */
|
|
31
|
+
body?: {
|
|
32
|
+
path: string;
|
|
33
|
+
format: BodyFormat;
|
|
34
|
+
fallback?: {
|
|
35
|
+
path: string;
|
|
36
|
+
format: BodyFormat;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The sign-in may be refused this call (a role without the right): a gap with this text, and the rest syncs. A
|
|
41
|
+
* source that leaves rows out without an error names `requires`: a read whose value at `check` is true when the
|
|
42
|
+
* sign-in sees every row; false or missing is the same gap.
|
|
43
|
+
*/
|
|
44
|
+
optional?: {
|
|
45
|
+
message: string;
|
|
46
|
+
scope?: string;
|
|
47
|
+
requires?: CrmOperationCall & {
|
|
48
|
+
check: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** A post's writes, as calls and values over the update call. `"{id}"` and `"{at}"` are filled by the engine. */
|
|
53
|
+
export interface ContentManifestWrites {
|
|
54
|
+
create: CrmOperationCall;
|
|
55
|
+
update: CrmOperationCall;
|
|
56
|
+
trash: CrmOperationCall;
|
|
57
|
+
/** Deleting for good, past the trash; absent, the source has no such write. */
|
|
58
|
+
delete?: CrmOperationCall;
|
|
59
|
+
/** Where each of our fields goes in a write's body, a dotted path (`title.raw`); `terms` by the term's kind. */
|
|
60
|
+
fields: {
|
|
61
|
+
title?: string;
|
|
62
|
+
body?: string;
|
|
63
|
+
excerpt?: string;
|
|
64
|
+
slug?: string;
|
|
65
|
+
terms?: Partial<Record<(typeof TERM_KINDS)[number], string>>;
|
|
66
|
+
};
|
|
67
|
+
/** Body values over `update` that publish now, schedule at `"{at}"` (ISO in UTC), and bring back to a draft. */
|
|
68
|
+
publish: Readonly<Record<string, unknown>>;
|
|
69
|
+
schedule: Readonly<Record<string, unknown>>;
|
|
70
|
+
unpublish: Readonly<Record<string, unknown>>;
|
|
71
|
+
}
|
|
72
|
+
/** A content account described as data. */
|
|
73
|
+
export interface ContentManifest {
|
|
74
|
+
provider: string;
|
|
75
|
+
kinds: readonly ContentKind[];
|
|
76
|
+
/** Re-read before the last cursor. Default 10 min. */
|
|
77
|
+
overlapMs?: number;
|
|
78
|
+
/** The site the profile signed in to is the channel: its address, as the profile keeps it, is its id. */
|
|
79
|
+
channel: {
|
|
80
|
+
kind: ChannelKind;
|
|
81
|
+
network: string;
|
|
82
|
+
};
|
|
83
|
+
entities: {
|
|
84
|
+
readonly [K in ContentKind]?: readonly ContentManifestEntity[];
|
|
85
|
+
};
|
|
86
|
+
writes?: ContentManifestWrites;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The manifest checked against its shape and the generated API: each operation exists and reads or writes as its
|
|
90
|
+
* place says, a change call places `{since}`, a get `{id}`, each map names only our fields. Every error names where.
|
|
91
|
+
*/
|
|
92
|
+
export declare const parseContentManifest: (input: unknown, api: ServiceApiManifest) => ContentManifest;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { crmRuleSchema } from "../../crm/manifest/manifest.js";
|
|
4
|
+
import { CHANNEL_KINDS, CONTENT_KINDS, TERM_KINDS } from "../../domain/content.js";
|
|
5
|
+
import { editDistance } from "../../search/correct.js";
|
|
6
|
+
import { CONTENT_FIELDS } from "./map.js";
|
|
7
|
+
/** How the source keeps a post's text, which the engine turns into Markdown and back. */
|
|
8
|
+
export const BODY_FORMATS = ["markdown", "html", "wp-blocks"];
|
|
9
|
+
const path = v.pipe(v.string(), v.regex(/^[^.\s]+(\.[^.\s]+)*$/, "a dotted path such as title.raw"));
|
|
10
|
+
const call = v.strictObject({
|
|
11
|
+
operation: v.pipe(v.string(), v.minLength(1)),
|
|
12
|
+
path: v.optional(v.record(v.string(), v.string())),
|
|
13
|
+
query: v.optional(v.record(v.string(), v.union([v.string(), v.number(), v.boolean()]))),
|
|
14
|
+
body: v.optional(v.unknown()),
|
|
15
|
+
items: v.optional(path),
|
|
16
|
+
});
|
|
17
|
+
const format = v.picklist(BODY_FORMATS);
|
|
18
|
+
const entity = v.strictObject({
|
|
19
|
+
list: call,
|
|
20
|
+
changes: v.optional(v.strictObject({
|
|
21
|
+
...call.entries,
|
|
22
|
+
since: v.picklist(["iso", "seconds", "ms"]),
|
|
23
|
+
keyset: v.optional(v.strictObject({ field: path, step: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1))) })),
|
|
24
|
+
})),
|
|
25
|
+
ids: v.optional(call),
|
|
26
|
+
get: v.optional(call),
|
|
27
|
+
map: v.record(v.string(), crmRuleSchema),
|
|
28
|
+
body: v.optional(v.strictObject({ path, format, fallback: v.optional(v.strictObject({ path, format })) })),
|
|
29
|
+
optional: v.optional(v.strictObject({
|
|
30
|
+
message: v.pipe(v.string(), v.minLength(1)),
|
|
31
|
+
scope: v.optional(v.string()),
|
|
32
|
+
requires: v.optional(v.strictObject({ ...call.entries, check: path })),
|
|
33
|
+
})),
|
|
34
|
+
});
|
|
35
|
+
const schema = v.strictObject({
|
|
36
|
+
provider: v.pipe(v.string(), v.regex(/^[a-z][a-z0-9-]*$/, "a registry name such as wordpress")),
|
|
37
|
+
kinds: v.pipe(v.array(v.picklist(CONTENT_KINDS)), v.minLength(1)),
|
|
38
|
+
overlapMs: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0))),
|
|
39
|
+
channel: v.strictObject({ kind: v.picklist(CHANNEL_KINDS), network: v.pipe(v.string(), v.minLength(1)) }),
|
|
40
|
+
entities: v.record(v.picklist(CONTENT_KINDS), v.optional(v.pipe(v.array(entity), v.minLength(1)))),
|
|
41
|
+
writes: v.optional(v.strictObject({
|
|
42
|
+
create: call,
|
|
43
|
+
update: call,
|
|
44
|
+
trash: call,
|
|
45
|
+
delete: v.optional(call),
|
|
46
|
+
fields: v.strictObject({
|
|
47
|
+
title: v.optional(v.string()),
|
|
48
|
+
body: v.optional(v.string()),
|
|
49
|
+
excerpt: v.optional(v.string()),
|
|
50
|
+
slug: v.optional(v.string()),
|
|
51
|
+
terms: v.optional(v.record(v.picklist(TERM_KINDS), v.optional(v.string()))),
|
|
52
|
+
}),
|
|
53
|
+
publish: v.record(v.string(), v.unknown()),
|
|
54
|
+
schedule: v.record(v.string(), v.unknown()),
|
|
55
|
+
unpublish: v.record(v.string(), v.unknown()),
|
|
56
|
+
})),
|
|
57
|
+
});
|
|
58
|
+
const invalid = (where, message) => new CliError("configuration_error", `source manifest: ${where}: ${message}`, { reason: "manifest.invalid" });
|
|
59
|
+
const nearest = (wanted, known) => known
|
|
60
|
+
.map((one) => ({ one, edits: editDistance(wanted, one, 2) }))
|
|
61
|
+
.filter(({ edits }) => edits <= 2)
|
|
62
|
+
.sort((a, b) => a.edits - b.edits)[0]?.one;
|
|
63
|
+
const holds = (value, placeholder) => value === placeholder ||
|
|
64
|
+
(Array.isArray(value) && value.some((one) => holds(one, placeholder))) ||
|
|
65
|
+
(typeof value === "object" && value !== null && Object.values(value).some((one) => holds(one, placeholder)));
|
|
66
|
+
/**
|
|
67
|
+
* The manifest checked against its shape and the generated API: each operation exists and reads or writes as its
|
|
68
|
+
* place says, a change call places `{since}`, a get `{id}`, each map names only our fields. Every error names where.
|
|
69
|
+
*/
|
|
70
|
+
export const parseContentManifest = (input, api) => {
|
|
71
|
+
const parsed = v.safeParse(schema, input);
|
|
72
|
+
if (!parsed.success) {
|
|
73
|
+
const [issue] = parsed.issues;
|
|
74
|
+
throw invalid(v.getDotPath(issue) ?? "(root)", issue.message);
|
|
75
|
+
}
|
|
76
|
+
const manifest = parsed.output;
|
|
77
|
+
const operations = new Map(api.operations.map((one) => [one.id, one]));
|
|
78
|
+
const known = [...operations.keys()];
|
|
79
|
+
const checkCall = (where, one, reads) => {
|
|
80
|
+
const operation = operations.get(one.operation);
|
|
81
|
+
if (!operation) {
|
|
82
|
+
const near = nearest(one.operation, known);
|
|
83
|
+
throw invalid(`${where}.operation`, `no operation ${one.operation} in the API${near ? `; did you mean ${near}?` : ""}`);
|
|
84
|
+
}
|
|
85
|
+
if (reads !== (operation.effect === "read"))
|
|
86
|
+
throw invalid(`${where}.operation`, `${one.operation} is a ${operation.effect}, and this place ${reads ? "reads" : "writes"}`);
|
|
87
|
+
};
|
|
88
|
+
for (const kind of manifest.kinds) {
|
|
89
|
+
const calls = manifest.entities[kind];
|
|
90
|
+
if (!calls)
|
|
91
|
+
throw invalid(`entities.${kind}`, `${kind} is in kinds but has no entity`);
|
|
92
|
+
calls.forEach((one, at) => {
|
|
93
|
+
const where = `entities.${kind}.${at}`;
|
|
94
|
+
checkCall(`${where}.list`, one.list, true);
|
|
95
|
+
if (one.changes) {
|
|
96
|
+
checkCall(`${where}.changes`, one.changes, true);
|
|
97
|
+
if (!holds([one.changes.path, one.changes.query, one.changes.body], "{since}"))
|
|
98
|
+
throw invalid(`${where}.changes`, 'no "{since}" in its path, query or body');
|
|
99
|
+
}
|
|
100
|
+
if (one.ids)
|
|
101
|
+
checkCall(`${where}.ids`, one.ids, true);
|
|
102
|
+
if (one.optional?.requires)
|
|
103
|
+
checkCall(`${where}.optional.requires`, one.optional.requires, true);
|
|
104
|
+
if (one.get) {
|
|
105
|
+
checkCall(`${where}.get`, one.get, true);
|
|
106
|
+
if (!holds([one.get.path, one.get.query], "{id}"))
|
|
107
|
+
throw invalid(`${where}.get`, 'no "{id}" in its path or query');
|
|
108
|
+
}
|
|
109
|
+
if (one.map.externalId === undefined)
|
|
110
|
+
throw invalid(`${where}.map.externalId`, "every kind maps its id");
|
|
111
|
+
const fields = Object.keys(CONTENT_FIELDS[kind]);
|
|
112
|
+
for (const field of Object.keys(one.map))
|
|
113
|
+
if (!fields.includes(field)) {
|
|
114
|
+
const near = nearest(field, fields);
|
|
115
|
+
throw invalid(`${where}.map.${field}`, `${kind} has no such field${near ? `; did you mean ${near}?` : ""}`);
|
|
116
|
+
}
|
|
117
|
+
if (one.body && kind !== "post")
|
|
118
|
+
throw invalid(`${where}.body`, "only a post has a text");
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
const writes = manifest.writes;
|
|
122
|
+
if (writes) {
|
|
123
|
+
if (!manifest.entities.post?.some((one) => one.get))
|
|
124
|
+
throw invalid("writes", "a write checks the post's version first, and no post entity has a get");
|
|
125
|
+
for (const name of ["create", "update", "trash", "delete"]) {
|
|
126
|
+
const one = writes[name];
|
|
127
|
+
if (!one)
|
|
128
|
+
continue;
|
|
129
|
+
checkCall(`writes.${name}`, one, false);
|
|
130
|
+
if (name !== "create" && !holds([one.path, one.query], "{id}"))
|
|
131
|
+
throw invalid(`writes.${name}`, 'no "{id}" in its path or query');
|
|
132
|
+
}
|
|
133
|
+
if (!holds(writes.schedule, "{at}"))
|
|
134
|
+
throw invalid("writes.schedule", 'no "{at}" for the time it goes out');
|
|
135
|
+
}
|
|
136
|
+
return manifest;
|
|
137
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { crmValues } from "../../crm/index.js";
|
|
2
|
+
import type { CrmRule } from "../../crm/manifest/manifest.js";
|
|
3
|
+
import { type Conversion } from "../../crm/manifest/map.js";
|
|
4
|
+
import { type ContentKind, type ContentRecords } from "../../domain/content.js";
|
|
5
|
+
import type { ContentManifestEntity } from "./manifest.js";
|
|
6
|
+
/** A time: read by `utcEpoch`, so a time the source wrote with no offset is UTC, as WordPress's `*_gmt` fields are. */
|
|
7
|
+
declare const TIME = "time";
|
|
8
|
+
type Field = Conversion | typeof TIME;
|
|
9
|
+
/** Each of our fields and how a value the source sent becomes it. */
|
|
10
|
+
export declare const CONTENT_FIELDS: {
|
|
11
|
+
readonly [K in ContentKind]: Readonly<Record<string, Field>>;
|
|
12
|
+
};
|
|
13
|
+
/** Epoch ms from ISO, or from epoch seconds or ms; an ISO time without an offset is UTC. */
|
|
14
|
+
export declare const utcEpoch: (value: unknown) => number | null;
|
|
15
|
+
/**
|
|
16
|
+
* One row as our record of the kind, or null for a row without an id, a term of no known kind, or a post of no known
|
|
17
|
+
* status: a post whose status we cannot say could be taken for published.
|
|
18
|
+
*/
|
|
19
|
+
export declare const mapContentRecord: <K extends ContentKind>(kind: K, map: Readonly<Record<string, CrmRule | undefined>>, raw: crmValues.CrmRaw) => ContentRecords[K] | null;
|
|
20
|
+
/** A post's text as Markdown, and whether its source markup is more than Markdown keeps. */
|
|
21
|
+
export declare const postBodyOf: (entity: ContentManifestEntity, raw: crmValues.CrmRaw) => Promise<{
|
|
22
|
+
body?: string;
|
|
23
|
+
lossy?: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
export {};
|