@tryghost/mg-context 0.11.1 → 0.11.3
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/README.md +2 -2
- package/build/index.js.map +1 -1
- package/build/lib/AuthorContext.js +4 -1
- package/build/lib/AuthorContext.js.map +1 -1
- package/build/lib/MigrateBase.js +3 -3
- package/build/lib/MigrateBase.js.map +1 -1
- package/build/lib/MigrateContext.js +11 -8
- package/build/lib/MigrateContext.js.map +1 -1
- package/build/lib/PostContext.d.ts +2 -2
- package/build/lib/PostContext.js +3 -3
- package/build/lib/PostContext.js.map +1 -1
- package/build/lib/TagContext.js +1 -0
- package/build/lib/TagContext.js.map +1 -1
- package/build/lib/database.js.map +1 -1
- package/build/lib/db-helpers.js +8 -3
- package/build/lib/db-helpers.js.map +1 -1
- package/build/lib/zod-schema-utils.js.map +1 -1
- package/build/test/lib/NoErrorThrownError.js.map +1 -1
- package/build/test/migrate-base.test.js +11 -1
- package/build/test/migrate-base.test.js.map +1 -1
- package/build/test/migrate-context.test.js +36 -8
- package/build/test/migrate-context.test.js.map +1 -1
- package/build/test/post-context.test.js +32 -7
- package/build/test/post-context.test.js.map +1 -1
- package/build/test/tasks.test.js +2 -0
- package/build/test/tasks.test.js.map +1 -1
- package/package.json +3 -7
|
@@ -134,7 +134,10 @@ describe('MigrateContext', () => {
|
|
|
134
134
|
const allPosts = await instance.getAllPosts();
|
|
135
135
|
assert.equal(allPosts[0].data.status, 'published');
|
|
136
136
|
assert.equal(allPosts[1].data.status, 'published');
|
|
137
|
-
assert.deepEqual(progressCalls, [
|
|
137
|
+
assert.deepEqual(progressCalls, [
|
|
138
|
+
[1, 2],
|
|
139
|
+
[2, 2]
|
|
140
|
+
]);
|
|
138
141
|
await instance.close();
|
|
139
142
|
});
|
|
140
143
|
describe('findPosts', () => {
|
|
@@ -479,7 +482,10 @@ describe('MigrateContext', () => {
|
|
|
479
482
|
progressCalls.push([processed, total]);
|
|
480
483
|
});
|
|
481
484
|
await instance.forEachGhostPost(async () => { }, { batchSize: 2 });
|
|
482
|
-
assert.deepEqual(progressCalls, [
|
|
485
|
+
assert.deepEqual(progressCalls, [
|
|
486
|
+
[2, 3],
|
|
487
|
+
[3, 3]
|
|
488
|
+
]);
|
|
483
489
|
await instance.close();
|
|
484
490
|
});
|
|
485
491
|
it('Does not persist callback mutations', async () => {
|
|
@@ -531,7 +537,14 @@ describe('MigrateContext', () => {
|
|
|
531
537
|
assert.equal(writtenFiles[0].name, 'posts.json');
|
|
532
538
|
const ghostJSON = JSON.parse(await readFile(writtenFiles[0].path, 'utf-8'));
|
|
533
539
|
assert.deepEqual(Object.keys(ghostJSON), ['meta', 'data']);
|
|
534
|
-
assert.deepEqual(Object.keys(ghostJSON.data), [
|
|
540
|
+
assert.deepEqual(Object.keys(ghostJSON.data), [
|
|
541
|
+
'posts',
|
|
542
|
+
'users',
|
|
543
|
+
'tags',
|
|
544
|
+
'posts_authors',
|
|
545
|
+
'posts_tags',
|
|
546
|
+
'posts_meta'
|
|
547
|
+
]);
|
|
535
548
|
assert.deepEqual(ghostJSON.data.posts.length, 2);
|
|
536
549
|
assert.equal(ghostJSON.data.posts_meta.length, 1);
|
|
537
550
|
assert.equal(ghostJSON.data.posts_meta[0].meta_title, 'SEO Title');
|
|
@@ -1052,7 +1065,9 @@ describe('MigrateContext', () => {
|
|
|
1052
1065
|
it('Throws when init() is called twice without close()', async () => {
|
|
1053
1066
|
const instance = new MigrateContext();
|
|
1054
1067
|
await instance.init();
|
|
1055
|
-
await assert.rejects(() => instance.init(), {
|
|
1068
|
+
await assert.rejects(() => instance.init(), {
|
|
1069
|
+
message: 'MigrateContext is already initialized. Call close() before reinitializing.'
|
|
1070
|
+
});
|
|
1056
1071
|
await instance.close();
|
|
1057
1072
|
});
|
|
1058
1073
|
});
|
|
@@ -1077,7 +1092,11 @@ describe('MigrateContext', () => {
|
|
|
1077
1092
|
// Insert author directly into DB, bypassing the cache
|
|
1078
1093
|
instance.db.stmts.insertAuthor.run(JSON.stringify({ name: 'Pre-existing', slug: 'pre-author', email: 'pre@example.com' }), 'pre-author', 'Pre-existing', 'pre@example.com', null);
|
|
1079
1094
|
// Save an AuthorContext with the same slug — should hit the existing.update branch
|
|
1080
|
-
const author = new AuthorContext({
|
|
1095
|
+
const author = new AuthorContext({
|
|
1096
|
+
name: 'Updated Pre-existing',
|
|
1097
|
+
slug: 'pre-author',
|
|
1098
|
+
email: 'pre@example.com'
|
|
1099
|
+
});
|
|
1081
1100
|
await author.save(instance.db);
|
|
1082
1101
|
assert.ok(author.dbId);
|
|
1083
1102
|
const found = await instance.findAuthors({ slug: 'pre-author' });
|
|
@@ -1154,7 +1173,10 @@ describe('MigrateContext', () => {
|
|
|
1154
1173
|
await post.save(instance.db);
|
|
1155
1174
|
const loaded = await instance.getAllPosts();
|
|
1156
1175
|
assert.equal(loaded.length, 1);
|
|
1157
|
-
assert.deepEqual(loaded[0].webscrapeData, {
|
|
1176
|
+
assert.deepEqual(loaded[0].webscrapeData, {
|
|
1177
|
+
meta_title: 'Scraped Title',
|
|
1178
|
+
og_image: 'https://example.com/img.jpg'
|
|
1179
|
+
});
|
|
1158
1180
|
await instance.close();
|
|
1159
1181
|
});
|
|
1160
1182
|
it('webscrape_data defaults to null', async () => {
|
|
@@ -1647,7 +1669,8 @@ describe('MigrateContext', () => {
|
|
|
1647
1669
|
const empty = new MigrateContext();
|
|
1648
1670
|
await empty.init();
|
|
1649
1671
|
let count = 0;
|
|
1650
|
-
for await (const _post of empty.streamPosts()) {
|
|
1672
|
+
for await (const _post of empty.streamPosts()) {
|
|
1673
|
+
// eslint-disable-line no-unused-vars
|
|
1651
1674
|
count += 1;
|
|
1652
1675
|
}
|
|
1653
1676
|
assert.equal(count, 0);
|
|
@@ -1817,7 +1840,12 @@ describe('MigrateContext', () => {
|
|
|
1817
1840
|
const dir = join(tmpdir(), `mg-filter-single-date-${Date.now()}`);
|
|
1818
1841
|
const files = await ctx.writeGhostJson(dir, {
|
|
1819
1842
|
batchSize: 1,
|
|
1820
|
-
filter: {
|
|
1843
|
+
filter: {
|
|
1844
|
+
createdAt: {
|
|
1845
|
+
after: new Date('2023-12-14T00:00:00.000Z'),
|
|
1846
|
+
before: new Date('2023-12-16T00:00:00.000Z')
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1821
1849
|
});
|
|
1822
1850
|
assert.equal(files.length, 1);
|
|
1823
1851
|
assert.equal(files[0].posts, 1);
|