@agentshouse/mdruntime 0.1.0-cfe9798bf3c30 → 0.1.0-cfef69803eb1c
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/dist/acceptance.js +1 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +16 -12
- package/dist/adapter.d.ts +27 -3
- package/dist/adapter.d.ts.map +1 -1
- package/dist/authored.d.ts.map +1 -1
- package/dist/authored.js +0 -2
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +5 -2
- package/dist/conversation-row.d.ts +4 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +8 -2
- package/dist/conversation.d.ts +1 -0
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +8 -7
- package/dist/download.d.ts.map +1 -1
- package/dist/download.js +2 -2
- package/dist/entry.d.ts +1 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +15 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +16 -0
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +4 -3
- package/dist/parts.d.ts +1 -0
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +1 -1
- package/dist/queue.d.ts +1 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +4 -2
- package/dist/rows.d.ts +0 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.js +1 -1
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +3 -2
- package/dist/shown.d.ts +1 -1
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +13 -12
- package/dist/source.d.ts +25 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +41 -8
- package/dist/tables.d.ts +0 -1
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +0 -1
- package/package.json +3 -3
- package/dist/reference-forms.d.ts +0 -4
- package/dist/reference-forms.d.ts.map +0 -1
- package/dist/reference-forms.js +0 -74
package/dist/reference-forms.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { ATTACHMENT_REFERENCE_PREFIX, CROCKFORD_CHARACTER, CROCKFORD_LEADING_CHARACTER, DOCUMENT_REFERENCE_PREFIX, REVISION_REFERENCE_PREFIX, } from '@agentshouse/mdmodel';
|
|
2
|
-
import { text, texts } from './column.js';
|
|
3
|
-
import { markdownPath } from './rows.js';
|
|
4
|
-
const ORDINAL = `${CROCKFORD_LEADING_CHARACTER}${CROCKFORD_CHARACTER}*`;
|
|
5
|
-
const OLD_REVISION = new RegExp(`^fr_(${ORDINAL}\\.${ORDINAL}\\.${CROCKFORD_CHARACTER})$`, 'u');
|
|
6
|
-
const OLD_ENTRY = new RegExp(`^af_(${ORDINAL})\\.(${CROCKFORD_CHARACTER})$`, 'u');
|
|
7
|
-
const RECORDS = [
|
|
8
|
-
['authored_pending', 'batch', ['locator', 'id']],
|
|
9
|
-
['authored_pending', 'state', ['locator', 'id']],
|
|
10
|
-
['authored_room_drafts', 'record', ['locator', 'path']],
|
|
11
|
-
['authored_chat_drafts', 'record', ['conversation']],
|
|
12
|
-
['authored_calls', 'record', ['operation']],
|
|
13
|
-
];
|
|
14
|
-
const REVISIONS = [
|
|
15
|
-
['replica_entries', 'revision'],
|
|
16
|
-
['opened_files', 'revision'],
|
|
17
|
-
];
|
|
18
|
-
export function kindedRevision(value) {
|
|
19
|
-
const revision = OLD_REVISION.exec(value);
|
|
20
|
-
return revision === null ? value : `${REVISION_REFERENCE_PREFIX}${revision[1]}`;
|
|
21
|
-
}
|
|
22
|
-
function kindedReference(value, paths) {
|
|
23
|
-
const revised = kindedRevision(value);
|
|
24
|
-
if (revised !== value)
|
|
25
|
-
return revised;
|
|
26
|
-
const entry = OLD_ENTRY.exec(value);
|
|
27
|
-
const path = entry === null ? undefined : paths.get(entry[1]);
|
|
28
|
-
if (entry === null || path === undefined)
|
|
29
|
-
return value;
|
|
30
|
-
const prefix = markdownPath(path) ? DOCUMENT_REFERENCE_PREFIX : ATTACHMENT_REFERENCE_PREFIX;
|
|
31
|
-
return `${prefix}${entry[1]}.${entry[2]}`;
|
|
32
|
-
}
|
|
33
|
-
function kinded(value, paths) {
|
|
34
|
-
if (typeof value === 'string')
|
|
35
|
-
return kindedReference(value, paths);
|
|
36
|
-
if (Array.isArray(value))
|
|
37
|
-
return value.map((item) => kinded(item, paths));
|
|
38
|
-
if (value === null || typeof value !== 'object')
|
|
39
|
-
return value;
|
|
40
|
-
return Object.fromEntries(Object.entries(value).map(([name, item]) => [name, kinded(item, paths)]));
|
|
41
|
-
}
|
|
42
|
-
function heldColumns(connection, table) {
|
|
43
|
-
return new Set(texts(connection.rows('SELECT name FROM pragma_table_info(?)', [table]), 'name'));
|
|
44
|
-
}
|
|
45
|
-
function heldPaths(connection) {
|
|
46
|
-
const columns = heldColumns(connection, 'replica_entries');
|
|
47
|
-
if (!columns.has('file_id') || !columns.has('path'))
|
|
48
|
-
return new Map();
|
|
49
|
-
return new Map(connection
|
|
50
|
-
.rows('SELECT DISTINCT file_id, path FROM replica_entries WHERE file_id IS NOT NULL')
|
|
51
|
-
.map((row) => [text(row.file_id), text(row.path)]));
|
|
52
|
-
}
|
|
53
|
-
function holdingOldForm(column) {
|
|
54
|
-
return `(${column} LIKE '%"fr\\_%' ESCAPE '\\' OR ${column} LIKE '%"af\\_%' ESCAPE '\\')`;
|
|
55
|
-
}
|
|
56
|
-
export function kindedReferences(connection) {
|
|
57
|
-
for (const [table, column] of REVISIONS) {
|
|
58
|
-
if (!heldColumns(connection, table).has(column))
|
|
59
|
-
continue;
|
|
60
|
-
connection.run(`UPDATE ${table} SET ${column} = '${REVISION_REFERENCE_PREFIX}' || substr(${column}, 4) WHERE ${column} LIKE 'fr\\_%' ESCAPE '\\'`);
|
|
61
|
-
}
|
|
62
|
-
let paths = null;
|
|
63
|
-
for (const [table, column, keys] of RECORDS) {
|
|
64
|
-
const held = connection.rows(`SELECT ${keys.join(', ')}, ${column} AS value FROM ${table} WHERE ${holdingOldForm(column)}`);
|
|
65
|
-
for (const row of held) {
|
|
66
|
-
paths ??= heldPaths(connection);
|
|
67
|
-
const value = JSON.parse(text(row.value));
|
|
68
|
-
const written = JSON.stringify(kinded(value, paths));
|
|
69
|
-
if (written === JSON.stringify(value))
|
|
70
|
-
continue;
|
|
71
|
-
connection.run(`UPDATE ${table} SET ${column} = ? WHERE ${keys.map((key) => `${key} = ?`).join(' AND ')}`, [written, ...keys.map((key) => row[key])]);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|