@wirecat/cli-core 0.614.0 → 0.615.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 +21 -0
- package/dist/background/report/render.d.ts +18 -4
- package/dist/background/report/render.js +59 -18
- package/dist/background/report/stored-templates.d.ts +64 -0
- package/dist/background/report/stored-templates.js +80 -0
- package/dist/background/report/templates/morning-digest.sample.json +150 -0
- package/dist/background/schedules.d.ts +4 -2
- package/dist/background/schedules.js +2 -1
- package/dist/cli/index.d.ts +2 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/schedule/schedule-command.d.ts +2 -0
- package/dist/cli/schedule/schedule-command.js +20 -2
- package/dist/cli/shared-command-exports.d.ts +1 -0
- package/dist/cli/shared-command-exports.js +2 -0
- package/dist/cli/templates-command.d.ts +16 -0
- package/dist/cli/templates-command.js +243 -0
- package/dist/errors/reasons.js +7 -0
- package/dist/services/metadata.d.ts +1 -1
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/index.d.ts +1 -0
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/migrations.generated.js +8 -0
- package/dist/store/sqlite/schema/templates.d.ts +242 -0
- package/dist/store/sqlite/schema/templates.js +23 -0
- package/dist/store/sqlite/schema.d.ts +1 -0
- package/dist/store/sqlite/schema.js +1 -0
- package/dist/store/sqlite/templates.d.ts +38 -0
- package/dist/store/sqlite/templates.js +69 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/package.json +4 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { index, integer, primaryKey, sqliteTable, text } from "../drizzle/core.js";
|
|
2
|
+
/** A template the owner saved over the shipped one, per key, channel and language. */
|
|
3
|
+
export const templates = sqliteTable("templates", {
|
|
4
|
+
key: text("key").notNull(),
|
|
5
|
+
channel: text("channel").notNull(),
|
|
6
|
+
language: text("language").notNull(),
|
|
7
|
+
body: text("body").notNull(),
|
|
8
|
+
updatedAt: integer("updated_at").notNull(),
|
|
9
|
+
updatedBy: text("updated_by").notNull(),
|
|
10
|
+
}, (table) => [primaryKey({ columns: [table.key, table.channel, table.language] })]);
|
|
11
|
+
/** Every body a save or a reset replaced. */
|
|
12
|
+
export const templatesHistory = sqliteTable("templates_history", {
|
|
13
|
+
id: integer("id").primaryKey(),
|
|
14
|
+
key: text("key").notNull(),
|
|
15
|
+
channel: text("channel").notNull(),
|
|
16
|
+
language: text("language").notNull(),
|
|
17
|
+
body: text("body").notNull(),
|
|
18
|
+
savedAt: integer("saved_at").notNull(),
|
|
19
|
+
savedBy: text("saved_by").notNull(),
|
|
20
|
+
replacedAt: integer("replaced_at").notNull(),
|
|
21
|
+
}, (table) => [
|
|
22
|
+
index("templates_history_by_key_channel_language_id").on(table.key, table.channel, table.language, table.id),
|
|
23
|
+
]);
|
|
@@ -19487,6 +19487,7 @@ export declare const transactionSplits: import("drizzle-orm/sqlite-core").SQLite
|
|
|
19487
19487
|
}>;
|
|
19488
19488
|
export { decisionRequests } from "./schema/decision-requests.js";
|
|
19489
19489
|
export { enrichments } from "./schema/enrichments.js";
|
|
19490
|
+
export { templates, templatesHistory } from "./schema/templates.js";
|
|
19490
19491
|
/** What a source said about one of its records, as it said it: the layer under the entity an import makes. */
|
|
19491
19492
|
export declare const records: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
|
|
19492
19493
|
name: "records";
|
|
@@ -1934,6 +1934,7 @@ export const transactionSplits = sqliteTable("transaction_splits", {
|
|
|
1934
1934
|
]);
|
|
1935
1935
|
export { decisionRequests } from "./schema/decision-requests.js";
|
|
1936
1936
|
export { enrichments } from "./schema/enrichments.js";
|
|
1937
|
+
export { templates, templatesHistory } from "./schema/templates.js";
|
|
1937
1938
|
/** What a source said about one of its records, as it said it: the layer under the entity an import makes. */
|
|
1938
1939
|
export const records = sqliteTable("records", {
|
|
1939
1940
|
id: integer("id").primaryKey(),
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CacheDatabase } from "../driver.js";
|
|
2
|
+
import type { StoreContext } from "./open.js";
|
|
3
|
+
/** Which template: `report/morning-digest`, `telegram`, `ru`. */
|
|
4
|
+
export interface TemplateAddress {
|
|
5
|
+
key: string;
|
|
6
|
+
channel: string;
|
|
7
|
+
language: string;
|
|
8
|
+
}
|
|
9
|
+
export interface StoredTemplate extends TemplateAddress {
|
|
10
|
+
body: string;
|
|
11
|
+
updatedAt: number;
|
|
12
|
+
updatedBy: string;
|
|
13
|
+
}
|
|
14
|
+
/** A body a save or a reset replaced. */
|
|
15
|
+
export interface TemplateHistoryEntry extends TemplateAddress {
|
|
16
|
+
id: number;
|
|
17
|
+
body: string;
|
|
18
|
+
savedAt: number;
|
|
19
|
+
savedBy: string;
|
|
20
|
+
replacedAt: number;
|
|
21
|
+
}
|
|
22
|
+
/** The owner's templates over the shipped ones. Nothing here checks a body: the caller does, before `save`. */
|
|
23
|
+
export interface TemplateStore {
|
|
24
|
+
list(): StoredTemplate[];
|
|
25
|
+
get(address: TemplateAddress): StoredTemplate | undefined;
|
|
26
|
+
/** Stores `body`, and keeps the body it replaces in the history. */
|
|
27
|
+
save(address: TemplateAddress, body: string, by: string): StoredTemplate;
|
|
28
|
+
/** Deletes the stored body, kept in the history, so the shipped one applies; false when there was none. */
|
|
29
|
+
reset(address: TemplateAddress): boolean;
|
|
30
|
+
/** Newest first. */
|
|
31
|
+
history(address: TemplateAddress, limit?: number): TemplateHistoryEntry[];
|
|
32
|
+
}
|
|
33
|
+
export declare const templateStoreOver: ({ database, now }: StoreContext) => TemplateStore;
|
|
34
|
+
/**
|
|
35
|
+
* The stored bodies of one key and language, by channel, read without migrating the file: a store older than the
|
|
36
|
+
* table has none.
|
|
37
|
+
*/
|
|
38
|
+
export declare const storedTemplateBodies: (database: CacheDatabase, key: string, language: string) => Record<string, string>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { write } from "./transaction.js";
|
|
2
|
+
const templateOf = (row) => ({
|
|
3
|
+
key: row.key,
|
|
4
|
+
channel: row.channel,
|
|
5
|
+
language: row.language,
|
|
6
|
+
body: row.body,
|
|
7
|
+
updatedAt: row.updated_at,
|
|
8
|
+
updatedBy: row.updated_by,
|
|
9
|
+
});
|
|
10
|
+
const WHERE = "key = ? AND channel = ? AND language = ?";
|
|
11
|
+
const at = ({ key, channel, language }) => [key, channel, language];
|
|
12
|
+
export const templateStoreOver = ({ database, now }) => {
|
|
13
|
+
const get = (address) => {
|
|
14
|
+
const row = database.prepare(`SELECT * FROM templates WHERE ${WHERE}`).get(...at(address));
|
|
15
|
+
return row && templateOf(row);
|
|
16
|
+
};
|
|
17
|
+
const keep = (old, replacedAt) => database
|
|
18
|
+
.prepare("INSERT INTO templates_history (key, channel, language, body, saved_at, saved_by, replaced_at) " +
|
|
19
|
+
"VALUES (?, ?, ?, ?, ?, ?, ?)")
|
|
20
|
+
.run(...at(old), old.body, old.updatedAt, old.updatedBy, replacedAt);
|
|
21
|
+
return {
|
|
22
|
+
list: () => database.prepare("SELECT * FROM templates ORDER BY key, channel, language").all().map(templateOf),
|
|
23
|
+
get,
|
|
24
|
+
save: (address, body, by) => write(database, () => {
|
|
25
|
+
const time = now();
|
|
26
|
+
const old = get(address);
|
|
27
|
+
if (old)
|
|
28
|
+
keep(old, time);
|
|
29
|
+
database
|
|
30
|
+
.prepare("INSERT INTO templates (key, channel, language, body, updated_at, updated_by) VALUES (?, ?, ?, ?, ?, ?) " +
|
|
31
|
+
"ON CONFLICT (key, channel, language) DO UPDATE SET body = excluded.body, " +
|
|
32
|
+
"updated_at = excluded.updated_at, updated_by = excluded.updated_by")
|
|
33
|
+
.run(...at(address), body, time, by);
|
|
34
|
+
return { ...address, body, updatedAt: time, updatedBy: by };
|
|
35
|
+
}),
|
|
36
|
+
reset: (address) => write(database, () => {
|
|
37
|
+
const old = get(address);
|
|
38
|
+
if (!old)
|
|
39
|
+
return false;
|
|
40
|
+
keep(old, now());
|
|
41
|
+
database.prepare(`DELETE FROM templates WHERE ${WHERE}`).run(...at(address));
|
|
42
|
+
return true;
|
|
43
|
+
}),
|
|
44
|
+
history: (address, limit = 20) => database
|
|
45
|
+
.prepare(`SELECT * FROM templates_history WHERE ${WHERE} ORDER BY id DESC LIMIT ?`)
|
|
46
|
+
.all(...at(address), limit).map((row) => ({
|
|
47
|
+
id: row.id,
|
|
48
|
+
key: row.key,
|
|
49
|
+
channel: row.channel,
|
|
50
|
+
language: row.language,
|
|
51
|
+
body: row.body,
|
|
52
|
+
savedAt: row.saved_at,
|
|
53
|
+
savedBy: row.saved_by,
|
|
54
|
+
replacedAt: row.replaced_at,
|
|
55
|
+
})),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The stored bodies of one key and language, by channel, read without migrating the file: a store older than the
|
|
60
|
+
* table has none.
|
|
61
|
+
*/
|
|
62
|
+
export const storedTemplateBodies = (database, key, language) => {
|
|
63
|
+
if (!database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'templates'").get())
|
|
64
|
+
return {};
|
|
65
|
+
const rows = database
|
|
66
|
+
.prepare("SELECT channel, body FROM templates WHERE key = ? AND language = ?")
|
|
67
|
+
.all(key, language);
|
|
68
|
+
return Object.fromEntries(rows.map((row) => [row.channel, row.body]));
|
|
69
|
+
};
|
package/dist/store/store.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ import { type RecordStore } from "./sqlite/records.js";
|
|
|
49
49
|
import { type RelationsStore } from "./sqlite/reported-relations.js";
|
|
50
50
|
import { type SubscriptionsStore } from "./sqlite/subscriptions.js";
|
|
51
51
|
import { type StoreTaskStore } from "./sqlite/tasks.js";
|
|
52
|
+
import { type TemplateStore } from "./sqlite/templates.js";
|
|
52
53
|
import { type WalletsStore } from "./sqlite/wallets.js";
|
|
53
54
|
import { type SyncStore } from "./sync.js";
|
|
54
55
|
import { type TagsStore } from "./tags.js";
|
|
@@ -135,6 +136,8 @@ export interface MessageStore {
|
|
|
135
136
|
readonly relations: RelationsStore;
|
|
136
137
|
/** The one-time keys behind the buttons of a message that asks the owner to decide a batch. */
|
|
137
138
|
readonly decisionRequests: DecisionRequestStore;
|
|
139
|
+
/** The message templates the owner saved over the shipped ones, with every body a change replaced. */
|
|
140
|
+
readonly templates: TemplateStore;
|
|
138
141
|
/** What each import said, by the source's identity; `ingest` (services) is the way in. */
|
|
139
142
|
readonly records: RecordStore;
|
|
140
143
|
/** What agents concluded: summaries, digests, facts, preferences, each with evidence and a scope. */
|
package/dist/store/store.js
CHANGED
|
@@ -55,6 +55,7 @@ import { relationsStoreOver } from "./sqlite/reported-relations.js";
|
|
|
55
55
|
import * as stems from "./sqlite/stems.js";
|
|
56
56
|
import { subscriptionsStoreOver } from "./sqlite/subscriptions.js";
|
|
57
57
|
import { taskStoreOver } from "./sqlite/tasks.js";
|
|
58
|
+
import { templateStoreOver } from "./sqlite/templates.js";
|
|
58
59
|
import { walletsStoreOver } from "./sqlite/wallets.js";
|
|
59
60
|
import { storeErrors } from "./store-errors.js";
|
|
60
61
|
import { syncStoreOver } from "./sync.js";
|
|
@@ -135,6 +136,7 @@ const storeOver = (context) => {
|
|
|
135
136
|
const crm = once(() => crmCopiesOver(context, accountPeopleOver(context)));
|
|
136
137
|
const relations = once(() => relationsStoreOver(context));
|
|
137
138
|
const decisionRequests = once(() => decisionRequestStoreOver(context));
|
|
139
|
+
const templates = once(() => templateStoreOver(context));
|
|
138
140
|
const records = once(() => recordStoreOver(context));
|
|
139
141
|
const memories = once(() => memoriesStoreOver(context));
|
|
140
142
|
const proposedActions = once(() => proposedActionsStoreOver(context));
|
|
@@ -277,6 +279,9 @@ const storeOver = (context) => {
|
|
|
277
279
|
get decisionRequests() {
|
|
278
280
|
return decisionRequests();
|
|
279
281
|
},
|
|
282
|
+
get templates() {
|
|
283
|
+
return templates();
|
|
284
|
+
},
|
|
280
285
|
get records() {
|
|
281
286
|
return records();
|
|
282
287
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.615.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"wirecat": {
|
|
17
17
|
"store": {
|
|
18
|
-
"speaks":
|
|
18
|
+
"speaks": 59,
|
|
19
19
|
"minCompatible": 56
|
|
20
20
|
}
|
|
21
21
|
},
|
|
@@ -278,7 +278,7 @@
|
|
|
278
278
|
"@types/node": "^22.20.5",
|
|
279
279
|
"@types/pngjs": "6.0.5",
|
|
280
280
|
"@vitest/coverage-v8": "^5.0.5",
|
|
281
|
-
"@wirecat/cli-base": "0.
|
|
281
|
+
"@wirecat/cli-base": "0.87.0",
|
|
282
282
|
"@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
|
|
283
283
|
"ajv": "8.17.1",
|
|
284
284
|
"commander": "15.0.0",
|
|
@@ -299,7 +299,7 @@
|
|
|
299
299
|
},
|
|
300
300
|
"peerDependencies": {
|
|
301
301
|
"@napi-rs/canvas": ">=0.1.69 <2",
|
|
302
|
-
"@wirecat/cli-base": ">=0.80.7 <0.
|
|
302
|
+
"@wirecat/cli-base": ">=0.80.7 <1.0.0",
|
|
303
303
|
"commander": ">=15"
|
|
304
304
|
},
|
|
305
305
|
"bin": {
|