@tryghost/mg-context 0.5.0 → 0.7.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.
@@ -13,7 +13,8 @@ CREATE TABLE IF NOT EXISTS Posts (
13
13
  updated_at TEXT,
14
14
  published_at TEXT,
15
15
  original_slug TEXT,
16
- slug TEXT
16
+ slug TEXT,
17
+ webscrape_data TEXT
17
18
  );
18
19
  CREATE INDEX IF NOT EXISTS idx_posts_lookup_key ON Posts(lookup_key);
19
20
  CREATE INDEX IF NOT EXISTS idx_posts_created_at ON Posts(created_at);
@@ -60,12 +61,19 @@ CREATE TABLE IF NOT EXISTS PostAuthors (
60
61
  );
61
62
  CREATE INDEX IF NOT EXISTS idx_postauthors_post_id ON PostAuthors(post_id);
62
63
  CREATE INDEX IF NOT EXISTS idx_postauthors_author_id ON PostAuthors(author_id);
64
+
65
+ CREATE TABLE IF NOT EXISTS Links (
66
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
67
+ old_url TEXT NOT NULL,
68
+ new_url TEXT NOT NULL
69
+ );
70
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_links_old_url ON Links(old_url);
63
71
  `;
64
72
  function prepareStatements(db) {
65
73
  return {
66
74
  // Posts
67
- insertPost: db.prepare('INSERT INTO Posts (data, source, meta, content_format, lookup_key, ghost_id, created_at, updated_at, published_at, original_slug, slug) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'),
68
- updatePost: db.prepare('UPDATE Posts SET data = ?, source = ?, meta = ?, content_format = ?, lookup_key = ?, ghost_id = ?, created_at = ?, updated_at = ?, published_at = ?, slug = ? WHERE id = ?'),
75
+ insertPost: db.prepare('INSERT INTO Posts (data, source, meta, content_format, lookup_key, ghost_id, created_at, updated_at, published_at, original_slug, slug, webscrape_data) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'),
76
+ updatePost: db.prepare('UPDATE Posts SET data = ?, source = ?, meta = ?, content_format = ?, lookup_key = ?, ghost_id = ?, created_at = ?, updated_at = ?, published_at = ?, slug = ?, webscrape_data = ? WHERE id = ?'),
69
77
  updatePostData: db.prepare('UPDATE Posts SET data = ? WHERE id = ?'),
70
78
  updatePostSlug: db.prepare('UPDATE Posts SET slug = ?, data = ? WHERE id = ?'),
71
79
  findPostById: db.prepare('SELECT * FROM Posts WHERE id = ?'),
@@ -86,6 +94,7 @@ function prepareStatements(db) {
86
94
  findTagsByName: db.prepare('SELECT * FROM Tags WHERE name = ?'),
87
95
  findAllTags: db.prepare('SELECT * FROM Tags'),
88
96
  findUsedTags: db.prepare('SELECT DISTINCT t.* FROM Tags t INNER JOIN PostTags pt ON t.id = pt.tag_id ORDER BY t.id ASC'),
97
+ findUsedTagIds: db.prepare('SELECT DISTINCT t.id FROM Tags t INNER JOIN PostTags pt ON t.id = pt.tag_id ORDER BY t.id ASC'),
89
98
  // Authors
90
99
  insertAuthor: db.prepare('INSERT INTO Authors (data, slug, name, email, ghost_id) VALUES (?, ?, ?, ?, ?)'),
91
100
  updateAuthorById: db.prepare('UPDATE Authors SET data = ?, slug = ?, name = ?, email = ?, ghost_id = ? WHERE id = ?'),
@@ -98,6 +107,7 @@ function prepareStatements(db) {
98
107
  findAuthorsByEmail: db.prepare('SELECT * FROM Authors WHERE email = ?'),
99
108
  findAllAuthors: db.prepare('SELECT * FROM Authors'),
100
109
  findUsedAuthors: db.prepare('SELECT DISTINCT a.* FROM Authors a INNER JOIN PostAuthors pa ON a.id = pa.author_id ORDER BY a.id ASC'),
110
+ findUsedAuthorIds: db.prepare('SELECT DISTINCT a.id FROM Authors a INNER JOIN PostAuthors pa ON a.id = pa.author_id ORDER BY a.id ASC'),
101
111
  // PostTag junction
102
112
  insertPostTag: db.prepare('INSERT INTO PostTags (post_id, tag_id, sort_order) VALUES (?, ?, ?)'),
103
113
  deletePostTagsByPostId: db.prepare('DELETE FROM PostTags WHERE post_id = ?'),
@@ -107,7 +117,10 @@ function prepareStatements(db) {
107
117
  insertPostAuthor: db.prepare('INSERT INTO PostAuthors (post_id, author_id, sort_order) VALUES (?, ?, ?)'),
108
118
  deletePostAuthorsByPostId: db.prepare('DELETE FROM PostAuthors WHERE post_id = ?'),
109
119
  findPostAuthorsByPostId: db.prepare('SELECT * FROM PostAuthors WHERE post_id = ? ORDER BY sort_order ASC'),
110
- findPostAuthorsByAuthorId: db.prepare('SELECT * FROM PostAuthors WHERE author_id = ?')
120
+ findPostAuthorsByAuthorId: db.prepare('SELECT * FROM PostAuthors WHERE author_id = ?'),
121
+ // Links
122
+ insertLink: db.prepare('INSERT OR IGNORE INTO Links (old_url, new_url) VALUES (?, ?)'),
123
+ findLink: db.prepare('SELECT new_url FROM Links WHERE old_url = ? LIMIT 1')
111
124
  };
112
125
  }
113
126
  export function createDatabase(dbPath) {
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/lib/database.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AAqEzC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Dd,CAAC;AAEF,SAAS,iBAAiB,CAAC,EAAgB;IACvC,OAAO;QACH,QAAQ;QACR,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,kLAAkL,CAAC;QAC1M,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,4KAA4K,CAAC;QACpM,cAAc,EAAE,EAAE,CAAC,OAAO,CAAC,wCAAwC,CAAC;QACpE,cAAc,EAAE,EAAE,CAAC,OAAO,CAAC,kDAAkD,CAAC;QAC9E,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,kCAAkC,CAAC;QAC5D,mBAAmB,EAAE,EAAE,CAAC,OAAO,CAAC,0CAA0C,CAAC;QAC3E,eAAe,EAAE,EAAE,CAAC,OAAO,CAAC,oDAAoD,CAAC;QACjF,UAAU,EAA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  assert.equal(foundTags, null);
295
295
  });
296
296
  });
297
+ describe('forEachTag', () => {
298
+ it('Iterates and saves all used tags', async () => {
299
+ const instance = new MigrateContext();
300
+ await instance.init();
301
+ const post = await instance.addPost();
302
+ post.set('title', 'Post');
303
+ post.set('slug', 'post');
304
+ post.set('created_at', new Date('2023-01-01T00:00:00.000Z'));
305
+ post.addTag({ name: 'Alpha', slug: 'alpha' });
306
+ post.addTag({ name: 'Beta', slug: 'beta' });
307
+ await post.save(instance.db);
308
+ const slugs = [];
309
+ await instance.forEachTag(async (tag) => {
310
+ slugs.push(tag.data.slug);
311
+ tag.set('description', `Desc for ${tag.data.slug}`);
312
+ });
313
+ assert.deepEqual(slugs, ['alpha', 'beta']);
314
+ // Verify saves persisted
315
+ const tags = await instance.findTags({ slug: 'alpha' });
316
+ assert.equal(tags[0].data.description, 'Desc for alpha');
317
+ await instance.close();
318
+ });
319
+ });
320
+ describe('forEachAuthor', () => {
321
+ it('Iterates and saves all used authors', async () => {
322
+ const instance = new MigrateContext();
323
+ await instance.init();
324
+ const post = await instance.addPost();
325
+ post.set('title', 'Post');
326
+ post.set('slug', 'post');
327
+ post.set('created_at', new Date('2023-01-01T00:00:00.000Z'));
328
+ post.addAuthor({ name: 'Alice', slug: 'alice', email: 'alice@example.com' });
329
+ await post.save(instance.db);
330
+ const slugs = [];
331
+ await instance.forEachAuthor(async (author) => {
332
+ slugs.push(author.data.slug);
333
+ author.set('bio', 'Updated bio');
334
+ });
335
+ assert.deepEqual(slugs, ['alice']);
336
+ // Verify saves persisted
337
+ const authors = await instance.findAuthors({ slug: 'alice' });
338
+ assert.equal(authors[0].data.bio, 'Updated bio');
339
+ await instance.close();
340
+ });
341
+ });
297
342
  describe('findAuthors', () => {
298
343
  let reusedInstance;
299
344
  before(async () => {
@@ -343,6 +388,41 @@ describe('MigrateContext', () => {
343
388
  assert.equal(foundTags, null);
344
389
  });
345
390
  });
391
+ describe('addLink / findLink', () => {
392
+ it('Stores and retrieves links', async () => {
393
+ const instance = new MigrateContext();
394
+ await instance.init();
395
+ instance.addLink('example.com/my-post/', '/my-post/');
396
+ instance.addLink('example.com/other-post/', '/other-post/');
397
+ assert.equal(instance.findLink('example.com/my-post/'), '/my-post/');
398
+ assert.equal(instance.findLink('example.com/other-post/'), '/other-post/');
399
+ await instance.close();
400
+ });
401
+ it('Ignores duplicate old_url entries', async () => {
402
+ const instance = new MigrateContext();
403
+ await instance.init();
404
+ instance.addLink('example.com/my-post/', '/my-post/');
405
+ instance.addLink('example.com/my-post/', '/different-path/');
406
+ assert.equal(instance.findLink('example.com/my-post/'), '/my-post/');
407
+ await instance.close();
408
+ });
409
+ it('Returns null when no match exists', async () => {
410
+ const instance = new MigrateContext();
411
+ await instance.init();
412
+ assert.equal(instance.findLink('example.com/missing/'), null);
413
+ await instance.close();
414
+ });
415
+ it('Finds a single link by old_url', async () => {
416
+ const instance = new MigrateContext();
417
+ await instance.init();
418
+ instance.addLink('example.com/my-post/', '/my-post/');
419
+ instance.addLink('example.com/other-post/', '/other-post/');
420
+ assert.equal(instance.findLink('example.com/my-post/'), '/my-post/');
421
+ assert.equal(instance.findLink('example.com/other-post/'), '/other-post/');
422
+ assert.equal(instance.findLink('example.com/missing/'), null);
423
+ await instance.close();
424
+ });
425
+ });
346
426
  describe('forEachGhostPost', () => {
347
427
  it('Iterates all posts with valid Ghost JSON', async () => {
348
428
  const instance = new MigrateContext();
@@ -932,7 +1012,7 @@ describe('MigrateContext', () => {
932
1012
  await post.save(instance.db);
933
1013
  assert.throws(() => {
934
1014
  withTransaction(instance.db, () => {
935
- instance.db.stmts.updatePost.run(JSON.stringify({ title: 'Rolled Back', slug: 'before-rollback' }), '{}', '{}', 'lexical', null, post.ghostId, '2023-11-23T00:00:00.000Z', null, null, 'before-rollback', post.dbId);
1015
+ instance.db.stmts.updatePost.run(JSON.stringify({ title: 'Rolled Back', slug: 'before-rollback' }), '{}', '{}', 'lexical', null, post.ghostId, '2023-11-23T00:00:00.000Z', null, null, 'before-rollback', null, post.dbId);
936
1016
  throw new errors.InternalServerError({ message: 'sync rollback' });
937
1017
  });
938
1018
  }, { message: 'sync rollback' });
@@ -951,7 +1031,7 @@ describe('MigrateContext', () => {
951
1031
  // Outer transaction via ctx.transaction, inner via withTransaction
952
1032
  await instance.transaction(async () => {
953
1033
  withTransaction(instance.db, () => {
954
- instance.db.stmts.updatePost.run(JSON.stringify({ title: 'Updated In Nested', slug: 'nested-tx' }), '{}', '{}', 'lexical', null, post.ghostId, '2023-11-23T00:00:00.000Z', null, null, 'nested-tx', post.dbId);
1034
+ instance.db.stmts.updatePost.run(JSON.stringify({ title: 'Updated In Nested', slug: 'nested-tx' }), '{}', '{}', 'lexical', null, post.ghostId, '2023-11-23T00:00:00.000Z', null, null, 'nested-tx', null, post.dbId);
955
1035
  });
956
1036
  });
957
1037
  const allPosts = await instance.getAllPosts();
@@ -1085,6 +1165,32 @@ describe('MigrateContext', () => {
1085
1165
  assert.equal(p.data.authors[0].data.name, 'Author One');
1086
1166
  await instance.close();
1087
1167
  });
1168
+ it('Preserves webscrape_data through save and load', async () => {
1169
+ const instance = new MigrateContext();
1170
+ await instance.init();
1171
+ const post = await instance.addPost();
1172
+ post.set('title', 'Scraped Post');
1173
+ post.set('slug', 'scraped-post');
1174
+ post.set('created_at', new Date('2023-11-23T12:00:00.000Z'));
1175
+ post.webscrapeData = { meta_title: 'Scraped Title', og_image: 'https://example.com/img.jpg' };
1176
+ await post.save(instance.db);
1177
+ const loaded = await instance.getAllPosts();
1178
+ assert.equal(loaded.length, 1);
1179
+ assert.deepEqual(loaded[0].webscrapeData, { meta_title: 'Scraped Title', og_image: 'https://example.com/img.jpg' });
1180
+ await instance.close();
1181
+ });
1182
+ it('webscrape_data defaults to null', async () => {
1183
+ const instance = new MigrateContext();
1184
+ await instance.init();
1185
+ const post = await instance.addPost();
1186
+ post.set('title', 'No Scrape');
1187
+ post.set('slug', 'no-scrape');
1188
+ post.set('created_at', new Date('2023-11-23T12:00:00.000Z'));
1189
+ await post.save(instance.db);
1190
+ const loaded = await instance.getAllPosts();
1191
+ assert.equal(loaded[0].webscrapeData, null);
1192
+ await instance.close();
1193
+ });
1088
1194
  it('Tags are shared across posts', async () => {
1089
1195
  const instance = new MigrateContext();
1090
1196
  await instance.init();
@@ -1524,6 +1630,52 @@ describe('MigrateContext', () => {
1524
1630
  await empty.close();
1525
1631
  });
1526
1632
  });
1633
+ describe('streamPosts', () => {
1634
+ it('yields all posts as PostContext objects', async () => {
1635
+ const titles = [];
1636
+ for await (const post of ctx.streamPosts()) {
1637
+ titles.push(post.data.title);
1638
+ }
1639
+ assert.equal(titles.length, 5);
1640
+ });
1641
+ it('supports filter option', async () => {
1642
+ const titles = [];
1643
+ for await (const post of ctx.streamPosts({ filter: { tag: { slug: 'news' } } })) {
1644
+ titles.push(post.data.title);
1645
+ }
1646
+ assert.deepEqual(titles, ['Post A', 'Post B']);
1647
+ });
1648
+ it('yields zero posts on empty context', async () => {
1649
+ const empty = new MigrateContext();
1650
+ await empty.init();
1651
+ let count = 0;
1652
+ for await (const _post of empty.streamPosts()) { // eslint-disable-line no-unused-vars
1653
+ count += 1;
1654
+ }
1655
+ assert.equal(count, 0);
1656
+ await empty.close();
1657
+ });
1658
+ });
1659
+ describe('streamTags', () => {
1660
+ it('yields all used tags', async () => {
1661
+ const slugs = [];
1662
+ for await (const tag of ctx.streamTags()) {
1663
+ slugs.push(tag.data.slug);
1664
+ }
1665
+ assert.ok(slugs.includes('news'));
1666
+ assert.ok(slugs.includes('tech'));
1667
+ });
1668
+ });
1669
+ describe('streamAuthors', () => {
1670
+ it('yields all used authors', async () => {
1671
+ const slugs = [];
1672
+ for await (const author of ctx.streamAuthors()) {
1673
+ slugs.push(author.data.slug);
1674
+ }
1675
+ assert.ok(slugs.includes('alice'));
1676
+ assert.ok(slugs.includes('bob'));
1677
+ });
1678
+ });
1527
1679
  describe('forEachGhostPost', () => {
1528
1680
  it('Tag filter works read-only', async () => {
1529
1681
  const titles = [];