@vermeulen.solutions/eventual 0.0.0-stage → 0.18.2
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/LICENSE +21 -0
- package/README.md +139 -2
- package/astro/EventList.astro +57 -0
- package/astro/admin.d.mts +3 -0
- package/astro/admin.mjs +158 -0
- package/astro/blueprint.d.mts +51 -0
- package/astro/blueprint.mjs +236 -0
- package/astro/cache.ts +82 -0
- package/astro/descriptor.mjs +7 -0
- package/astro/editor-compat.mjs +197 -0
- package/astro/editor-i18n.d.mts +8 -0
- package/astro/editor-i18n.mjs +157 -0
- package/astro/event-details.ts +29 -0
- package/astro/event-list.ts +56 -0
- package/astro/feed.ts +201 -0
- package/astro/install.d.mts +9 -0
- package/astro/install.mjs +66 -0
- package/astro/schema.ts +88 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +1585 -0
- package/dist/plugin.d.mts +6 -0
- package/dist/plugin.mjs +13 -0
- package/docs/collection-setup.md +46 -0
- package/docs/history.md +16 -0
- package/docs/native-modernization.md +99 -0
- package/docs/public-feed-caching.md +259 -0
- package/docs/registry-installation.md +13 -0
- package/docs/release-notes-0.14.0.md +27 -0
- package/docs/release-notes-0.14.1.md +40 -0
- package/docs/release-notes-0.15.0.md +18 -0
- package/docs/release-notes-0.16.0.md +7 -0
- package/docs/release-notes-0.17.0.md +7 -0
- package/docs/release-notes-0.18.0.md +8 -0
- package/docs/release-notes-0.18.1.md +7 -0
- package/docs/release-notes-0.18.2.md +6 -0
- package/docs/upgrade-0.13.0.md +21 -0
- package/docs/user-guide.md +40 -0
- package/emdash-plugin.jsonc +77 -0
- package/package.json +143 -4
- package/scripts/check-editor-installation.mjs +32 -0
- package/scripts/export-native-schema.mjs +28 -0
- package/scripts/upgrade-native-editor.mjs +296 -0
- package/src/domain/calendar-links.ts +80 -0
- package/src/domain/category.ts +32 -0
- package/src/domain/collections.ts +101 -0
- package/src/domain/date-time.ts +220 -0
- package/src/domain/description.ts +108 -0
- package/src/domain/event-data.ts +217 -0
- package/src/domain/event-expansion.ts +305 -0
- package/src/domain/event.ts +195 -0
- package/src/domain/icalendar.ts +165 -0
- package/src/domain/image.ts +18 -0
- package/src/domain/invocation-budget.ts +56 -0
- package/src/domain/messages.ts +8 -0
- package/src/domain/migration.ts +666 -0
- package/src/domain/native-calendar.ts +256 -0
- package/src/domain/native-references.ts +41 -0
- package/src/domain/native-source.ts +261 -0
- package/src/domain/native-validation.ts +366 -0
- package/src/domain/occurrences.ts +54 -0
- package/src/domain/portable-text.ts +180 -0
- package/src/domain/public-cache.ts +24 -0
- package/src/domain/recurrence-rule.ts +34 -0
- package/src/domain/recurrence.ts +350 -0
- package/src/domain/request-memo.ts +8 -0
- package/src/domain/schedule-history.ts +14 -0
- package/src/domain/text.ts +2 -0
- package/src/domain/time-entry.ts +23 -0
- package/src/domain/venue-adapter.ts +101 -0
- package/src/domain/venue.ts +42 -0
- package/src/public-event.ts +88 -0
- package/src/schema/blueprint.ts +315 -0
- package/src/storage.ts +257 -0
- package/transfer/index.d.mts +13 -0
- package/transfer/index.mjs +155 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/** Host-side helpers. None of this module is included in the sandbox bundle. */
|
|
2
|
+
const collections = ['venues', 'organizers', 'events'];
|
|
3
|
+
const now = () => new Date().toISOString();
|
|
4
|
+
const validDate = value => /^\d{4}-\d{2}-\d{2}$/.test(value) && Number.isFinite(Date.parse(`${value}T00:00:00Z`)) && new Date(`${value}T00:00:00Z`).toISOString().slice(0, 10) === value;
|
|
5
|
+
const baseEvent = (id, fields) => ({ id, title: '', description: '', start: '', end: '', allDay: false, timezone: 'UTC', location: '', organizer: '', externalUrl: '', imageUrl: '', categories: [], published: false, status: 'draft', exceptions: [], createdAt: now(), updatedAt: now(), ...fields });
|
|
6
|
+
|
|
7
|
+
/** RFC 4180 CSV, including quoted newlines and escaped quotes. */
|
|
8
|
+
export function parseCsv(text) {
|
|
9
|
+
if (typeof text !== 'string' || text.length > 5_000_000) throw new Error('CSV must be text under 5 MB.');
|
|
10
|
+
const rows = [];
|
|
11
|
+
let row = [], cell = '', quoted = false, closed = false;
|
|
12
|
+
text = text.replace(/^\uFEFF/, '');
|
|
13
|
+
for (let i = 0; i < text.length; i++) {
|
|
14
|
+
const char = text[i];
|
|
15
|
+
if (quoted) {
|
|
16
|
+
if (char === '"' && text[i + 1] === '"') { cell += '"'; i++; }
|
|
17
|
+
else if (char === '"') { quoted = false; closed = true; }
|
|
18
|
+
else cell += char;
|
|
19
|
+
} else if (char === '"') {
|
|
20
|
+
if (cell || closed) throw new Error('Unexpected quote in CSV.');
|
|
21
|
+
quoted = true;
|
|
22
|
+
} else if (char === ',' || char === '\n' || char === '\r') {
|
|
23
|
+
row.push(cell); cell = ''; closed = false;
|
|
24
|
+
if (char !== ',') { rows.push(row); row = []; if (char === '\r' && text[i + 1] === '\n') i++; }
|
|
25
|
+
} else { if (closed) throw new Error('Unexpected text after CSV quote.'); cell += char; }
|
|
26
|
+
}
|
|
27
|
+
if (quoted) throw new Error('Unclosed CSV quote.');
|
|
28
|
+
if (cell || row.length || closed) { row.push(cell); rows.push(row); }
|
|
29
|
+
return rows;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function csvToRecords(text) {
|
|
33
|
+
const [headers, ...rows] = parseCsv(text);
|
|
34
|
+
const allowed = ['sourceId', 'title', 'description', 'start', 'end', 'allDay', 'timezone', 'location', 'locationType', 'virtualUrl', 'organizer', 'externalUrl', 'imageUrl', 'categories'];
|
|
35
|
+
if (!headers || new Set(headers).size !== headers.length || headers.some(key => !allowed.includes(key)) || !['sourceId', 'title', 'start', 'end', 'allDay'].every(key => headers.includes(key))) throw new Error('Use unique supported headers including sourceId,title,start,end,allDay.');
|
|
36
|
+
const records = [], errors = [];
|
|
37
|
+
for (const [index, cells] of rows.entries()) {
|
|
38
|
+
if (cells.every(cell => cell === '')) continue;
|
|
39
|
+
if (cells.length !== headers.length) { errors.push({ row: index + 2, error: 'Column count does not match headers.' }); continue; }
|
|
40
|
+
const fields = Object.fromEntries(headers.map((header, column) => [header, cells[column]]));
|
|
41
|
+
const sourceId = fields.sourceId;
|
|
42
|
+
if (!sourceId || !['true', 'false'].includes(fields.allDay)) { errors.push({ row: index + 2, error: 'sourceId is required and allDay must be true or false.' }); continue; }
|
|
43
|
+
delete fields.sourceId;
|
|
44
|
+
fields.allDay = fields.allDay === 'true';
|
|
45
|
+
fields.categories = (fields.categories ?? '').split(/[;\n]/).map(value => value.trim()).filter(Boolean);
|
|
46
|
+
if ([fields.start, fields.end].some(value => !validDate(value.slice(0, 10))) || fields.allDay && (!validDate(fields.start) || !validDate(fields.end) || fields.end < fields.start)) { errors.push({ row: index + 2, error: 'Invalid calendar dates.' }); continue; }
|
|
47
|
+
// Timed CSV values must contain an explicit offset; DST wall times need a deliberate choice.
|
|
48
|
+
if (!fields.allDay && [fields.start, fields.end].some(value => !/^\d{4}-\d{2}-\d{2}T.*(?:Z|[+-]\d{2}:\d{2})$/.test(value) || !Number.isFinite(Date.parse(value)))) { errors.push({ row: index + 2, error: 'Timed CSV dates require ISO timestamps with Z or an explicit offset.' }); continue; }
|
|
49
|
+
if (!fields.allDay) { fields.start = new Date(fields.start).toISOString(); fields.end = new Date(fields.end).toISOString(); }
|
|
50
|
+
records.push({ sourceId, data: baseEvent(sourceId, fields) });
|
|
51
|
+
}
|
|
52
|
+
return { records, errors };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function icalText(value) { return value.replace(/\\([nN,;\\])/g, (_, char) => char === 'n' || char === 'N' ? '\n' : char); }
|
|
56
|
+
function icalDate(value, dateOnly) {
|
|
57
|
+
const date = `${value.slice(0, 4)}-${value.slice(4, 6)}-${value.slice(6, 8)}`;
|
|
58
|
+
if (!validDate(date)) throw new Error('Invalid calendar date.');
|
|
59
|
+
if (dateOnly && /^\d{8}$/.test(value)) return date;
|
|
60
|
+
if (!dateOnly && /^\d{8}T\d{6}Z$/.test(value)) return `${value.slice(0, 4)}-${value.slice(4, 6)}-${value.slice(6, 8)}T${value.slice(9, 11)}:${value.slice(11, 13)}:${value.slice(13, 15)}.000Z`;
|
|
61
|
+
throw new Error('Only UTC timestamps and VALUE=DATE schedules are supported; floating and TZID times need conversion first.');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Deliberately accepts standalone events only; never silently drops recurrence. */
|
|
65
|
+
export function icsToRecords(text) {
|
|
66
|
+
if (typeof text !== 'string' || text.length > 5_000_000) throw new Error('Calendar must be text under 5 MB.');
|
|
67
|
+
if (!/^BEGIN:VCALENDAR\r?\n/.test(text) || !/\r?\nEND:VCALENDAR(?:\r?\n)?$/.test(text)) throw new Error('Expected a VCALENDAR document.');
|
|
68
|
+
const lines = text.replace(/\r?\n[ \t]/g, '').split(/\r?\n/);
|
|
69
|
+
const records = [], errors = [];
|
|
70
|
+
let event = null, row = 0, unsupported = '';
|
|
71
|
+
for (const line of lines) {
|
|
72
|
+
if (line === 'BEGIN:VEVENT') { if (event) throw new Error('Nested VEVENT.'); event = new Map(); unsupported = ''; row++; continue; }
|
|
73
|
+
if (line === 'END:VEVENT') {
|
|
74
|
+
if (!event) throw new Error('Unexpected END:VEVENT.');
|
|
75
|
+
try {
|
|
76
|
+
if (unsupported) throw new Error(unsupported);
|
|
77
|
+
const get = key => event.get(key);
|
|
78
|
+
const uid = get('UID')?.value;
|
|
79
|
+
if (!uid || !get('SUMMARY') || !get('DTSTART')) throw new Error('UID, SUMMARY, and DTSTART are required.');
|
|
80
|
+
const allDay = get('DTSTART').params === 'VALUE=DATE';
|
|
81
|
+
const start = icalDate(get('DTSTART').value, allDay);
|
|
82
|
+
const endField = get('DTEND');
|
|
83
|
+
if (!allDay && !endField) throw new Error('Timed events require DTEND.');
|
|
84
|
+
if (endField && endField.params !== get('DTSTART').params) throw new Error('DTSTART and DTEND value types must match.');
|
|
85
|
+
let end = endField ? icalDate(endField.value, allDay) : start;
|
|
86
|
+
if (allDay && endField) {
|
|
87
|
+
const date = new Date(`${end}T00:00:00Z`);
|
|
88
|
+
if (!Number.isFinite(date.getTime()) || date.toISOString().slice(0, 10) !== end || end <= start) throw new Error('All-day DTEND must be a valid exclusive date after DTSTART.');
|
|
89
|
+
date.setUTCDate(date.getUTCDate() - 1); end = date.toISOString().slice(0, 10);
|
|
90
|
+
}
|
|
91
|
+
records.push({ sourceId: uid, data: baseEvent(uid, { title: icalText(get('SUMMARY').value), description: icalText(get('DESCRIPTION')?.value ?? ''), start, end, allDay, location: icalText(get('LOCATION')?.value ?? ''), externalUrl: get('URL')?.value ?? '' }) });
|
|
92
|
+
} catch (error) { errors.push({ row, error: error.message }); }
|
|
93
|
+
event = null; continue;
|
|
94
|
+
}
|
|
95
|
+
if (!event) continue;
|
|
96
|
+
if (line.startsWith('END:')) { unsupported = 'Nested components require conversion first.'; continue; }
|
|
97
|
+
const colon = line.indexOf(':');
|
|
98
|
+
if (colon < 0) { unsupported = 'Malformed VEVENT property.'; continue; }
|
|
99
|
+
const [key, ...params] = line.slice(0, colon).split(';');
|
|
100
|
+
if (['RRULE', 'RDATE', 'EXDATE', 'RECURRENCE-ID', 'DURATION'].includes(key) || key === 'BEGIN') unsupported = 'Recurring events, DURATION, and nested components require conversion first.';
|
|
101
|
+
if (['UID', 'SUMMARY', 'DESCRIPTION', 'DTSTART', 'DTEND', 'LOCATION', 'URL'].includes(key)) {
|
|
102
|
+
if (event.has(key)) unsupported = `Duplicate ${key}.`;
|
|
103
|
+
if ((key === 'DTSTART' || key === 'DTEND') && params.join(';') !== '' && params.join(';') !== 'VALUE=DATE') unsupported = 'Only UTC timestamps and VALUE=DATE are supported.';
|
|
104
|
+
event.set(key, { params: params.join(';'), value: line.slice(colon + 1) });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (event) throw new Error('Unclosed VEVENT.');
|
|
108
|
+
return { records, errors };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Invoke is an authenticated MCP adapter: (toolName, input) => the tool result. */
|
|
112
|
+
export async function exportBackup(invoke) {
|
|
113
|
+
const backup = { format: 'eventual-data', version: 1, exportedAt: now(), collections: {} };
|
|
114
|
+
for (const collection of collections) {
|
|
115
|
+
const records = [], seen = new Set();
|
|
116
|
+
let cursor;
|
|
117
|
+
do {
|
|
118
|
+
let result = await invoke('exportRecords', { collection, ...(cursor ? { cursor } : {}), limit: 5 });
|
|
119
|
+
if (result.error === 'EXPORT_PAGE_TOO_LARGE') result = await invoke('exportRecords', { collection, ...(cursor ? { cursor } : {}), limit: 1 });
|
|
120
|
+
if (!result.ok || !Array.isArray(result.records)) throw new Error(result.error ?? 'Invalid export response.');
|
|
121
|
+
records.push(...result.records);
|
|
122
|
+
cursor = result.nextCursor;
|
|
123
|
+
if (cursor && seen.has(cursor)) throw new Error('Repeated export cursor.');
|
|
124
|
+
if (cursor) seen.add(cursor);
|
|
125
|
+
} while (cursor);
|
|
126
|
+
backup.collections[collection] = records;
|
|
127
|
+
}
|
|
128
|
+
return backup;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export async function transferRecords(invoke, collection, records, { source, mode = 'copy', write = false } = {}) {
|
|
132
|
+
if (!collections.includes(collection) || !source || !['copy', 'restore'].includes(mode)) throw new Error('Choose a collection, a stable source, and copy or restore mode.');
|
|
133
|
+
const rows = [];
|
|
134
|
+
let batch = [];
|
|
135
|
+
const flush = async () => {
|
|
136
|
+
if (!batch.length) return;
|
|
137
|
+
const result = await invoke(write ? 'importRecords' : 'previewImport', { collection, source, mode, records: batch });
|
|
138
|
+
if (!Array.isArray(result.rows)) throw new Error(result.error ?? 'Invalid import response.');
|
|
139
|
+
rows.push(...result.rows); batch = [];
|
|
140
|
+
};
|
|
141
|
+
for (const record of records) {
|
|
142
|
+
if (batch.length === 10 || new TextEncoder().encode(JSON.stringify({ collection, source, mode, records: [...batch, record] })).length > 65536) await flush();
|
|
143
|
+
if (new TextEncoder().encode(JSON.stringify({ collection, source, mode, records: [record] })).length > 65536) throw new Error(`Record ${record.sourceId} exceeds 64 KiB.`);
|
|
144
|
+
batch.push(record);
|
|
145
|
+
}
|
|
146
|
+
await flush();
|
|
147
|
+
return rows;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function restoreBackup(invoke, backup, { source = 'backup', write = false } = {}) {
|
|
151
|
+
if (backup?.format !== 'eventual-data' || backup.version !== 1 || !backup.collections || !collections.every(key => Array.isArray(backup.collections[key]))) throw new Error('Unsupported Eventual data export.');
|
|
152
|
+
const result = {};
|
|
153
|
+
for (const collection of collections) result[collection] = await transferRecords(invoke, collection, backup.collections[collection], { source, mode: 'restore', write });
|
|
154
|
+
return result;
|
|
155
|
+
}
|