diff --git a/package-lock.json b/package-lock.json index 9db551ff..14639521 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3925,9 +3925,6 @@ "arm" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3942,9 +3939,6 @@ "arm" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3959,9 +3953,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -3976,9 +3967,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -3993,9 +3981,6 @@ "loong64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4010,9 +3995,6 @@ "loong64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4027,9 +4009,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4044,9 +4023,6 @@ "ppc64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4061,9 +4037,6 @@ "riscv64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4078,9 +4051,6 @@ "riscv64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4095,9 +4065,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4111,9 +4078,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -4128,9 +4092,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -4679,9 +4640,6 @@ "arm64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -4699,9 +4657,6 @@ "arm64" ], "dev": true, - "libc": [ - "musl" - ], "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -4719,9 +4674,6 @@ "ppc64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -4739,9 +4691,6 @@ "s390x" ], "dev": true, - "libc": [ - "glibc" - ], "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -4759,9 +4708,6 @@ "x64" ], "dev": true, - "libc": [ - "glibc" - ], "license": "Apache-2.0 AND MIT", "optional": true, "os": [ @@ -4779,9 +4725,6 @@ "x64" ], "dev": true, - "libc": [ - "musl" - ], "license": "Apache-2.0 AND MIT", "optional": true, "os": [ diff --git a/src/backend/services/resource_service.ts b/src/backend/services/resource_service.ts index 136cd606..2979eb8b 100644 --- a/src/backend/services/resource_service.ts +++ b/src/backend/services/resource_service.ts @@ -7,7 +7,7 @@ import type { ResourceBundle, ResourceIndexItem, ResourcePayload, - ResourceStoryUsage, + ResourceUsage, TextBundle, VideoBundle, } from '../../types.js'; @@ -64,7 +64,7 @@ export class ResourceService { return models.map((model) => this.toResourceItem(model)); } - public async countStoryUsagesByLocale(locale: string): Promise> { + async usageCountForLocale(locale: string): Promise> { const localisations = await StoryLocalisation.query() .where('locale', locale) .select('resources'); @@ -82,7 +82,7 @@ export class ResourceService { public async listIndexItems(locale: string): Promise { const models = await Resource.query().where('locale', locale).orderBy('title', 'asc'); - const usageCounts = await this.countStoryUsagesByLocale(locale); + const usageCounts = await this.usageCountForLocale(locale); return models.map((model) => ({ ...this.toIndexItem(model), @@ -162,17 +162,17 @@ export class ResourceService { }); } - public async listStoryUsages( + public async storyUsageFor( resourceId: string, locale: string, - ): Promise { + ): Promise { const localisations = await StoryLocalisation.query() .where('locale', locale) .whereRaw('resources @> ?::jsonb', [JSON.stringify([resourceId])]) .orderBy('title', 'asc'); return localisations.map((localisation) => ({ - storyId: localisation.storyId, + id: localisation.storyId, title: localisation.title, })); } diff --git a/src/backend/services/story_service.ts b/src/backend/services/story_service.ts index 6f69461f..a980c192 100644 --- a/src/backend/services/story_service.ts +++ b/src/backend/services/story_service.ts @@ -216,7 +216,7 @@ export class StoryService { return props; } - public async buildUpdatePayload( + public async updatePayloadFor( storyId: number, locale: string, ): Promise { @@ -256,13 +256,13 @@ export class StoryService { }; } - public async prepSections( + public async preppedSections( version: StoryVersion, sections?: PostedSection[], ): Promise { if (!sections) return []; const sourceLocale = this.config.languages[0].locale; - if (version.locale === sourceLocale) return this.sourceSections(sections); + if (version.locale === sourceLocale) return this.indexedSections(sections); const sourceLocalisation = await StoryLocalisation.query() .where('storyId', version.storyId) @@ -282,7 +282,7 @@ export class StoryService { }); } - sourceSections(sections: PostedSection[]): StorySection[] { + public indexedSections(sections: PostedSection[]): StorySection[] { return sections.map((section) => { return { id: section.id?.trim() ? section.id : randomUUID(), @@ -465,7 +465,7 @@ export class StoryService { }; } - private formatBespokeTemplateForDisplay(template: BundleTemplate): BundleTemplate { + private templateItemForPicklist(template: BundleTemplate): BundleTemplate { return { ...template, name: template.name.endsWith(' (custom)') @@ -477,7 +477,7 @@ export class StoryService { private templatesForEditDisplay(): BundleTemplate[] { return [ ...this.config.bespokeTemplates.map((template) => - this.formatBespokeTemplateForDisplay(template), + this.templateItemForPicklist(template), ), ...this.config.storyTemplates, ]; diff --git a/src/backend/stubs/controllers/resources_controller.stub b/src/backend/stubs/controllers/resources_controller.stub index fd3e46bb..f8ff5c21 100644 --- a/src/backend/stubs/controllers/resources_controller.stub +++ b/src/backend/stubs/controllers/resources_controller.stub @@ -70,7 +70,7 @@ export default class ResourcesController { return ctx.inertia.render('ResourceNotFound', {}); } - const usedInStories = await service.listStoryUsages(model.id, version.locale); + const usedInStories = await service.storyUsageFor(model.id, version.locale); const props: ResourceEditProps = { providers, diff --git a/src/backend/stubs/controllers/stories_controller.stub b/src/backend/stubs/controllers/stories_controller.stub index 90c2bdef..b04df4de 100644 --- a/src/backend/stubs/controllers/stories_controller.stub +++ b/src/backend/stubs/controllers/stories_controller.stub @@ -93,7 +93,7 @@ export default class StoriesController { coverImage: payload.coverImage, description: payload.description, tags: payload.tags, - sections: storyService.sourceSections(payload.sections ?? []), + sections: storyService.indexedSections(payload.sections ?? []), resources: payload.resources ?? [], }); local.useTransaction(trx); @@ -160,7 +160,7 @@ export default class StoriesController { if (story === undefined) return ctx.response.notFound(); if (story.isPublished) return ctx.response.redirect().back(); - const payload = await storyService.buildUpdatePayload(version.storyId, version.locale); + const payload = await storyService.updatePayloadFor(version.storyId, version.locale); if (!payload) return ctx.response.notFound(); payload.isPublished = true; @@ -208,7 +208,7 @@ export default class StoriesController { resources?: string[]; }, ) { - const sections = await storyService.prepSections(version, payload.sections); + const sections = await storyService.preppedSections(version, payload.sections); await db.transaction(async (trx) => { // update the story if it's the source locale diff --git a/src/backend/stubs/tests/unit/resource_service.stub b/src/backend/stubs/tests/unit/resource_service.stub index d2647886..b2495eb6 100644 --- a/src/backend/stubs/tests/unit/resource_service.stub +++ b/src/backend/stubs/tests/unit/resource_service.stub @@ -121,7 +121,7 @@ test.group('Resource service', (group) => { assert.equal(unattachedItem?.usedInCount, 0); }); - test('listStoryUsages returns stories in locale ordered by title', async ({ assert }) => { + test('storyUsageFor returns stories in locale ordered by title', async ({ assert }) => { const resource = await ResourceFactory.merge({ locale: 'en' }).create(); const alphaStory = await StoryFactory.with('localisations').create(); @@ -143,7 +143,7 @@ test.group('Resource service', (group) => { await otherLocaleLocalisation.save(); const service = new ResourceService(); - const usages = await service.listStoryUsages(resource.id, 'en'); + const usages = await service.storyUsageFor(resource.id, 'en'); assert.lengthOf(usages, 2); assert.deepEqual(usages, [ diff --git a/src/backend/stubs/tests/unit/story_service.stub b/src/backend/stubs/tests/unit/story_service.stub index daae9080..08eda341 100644 --- a/src/backend/stubs/tests/unit/story_service.stub +++ b/src/backend/stubs/tests/unit/story_service.stub @@ -344,7 +344,7 @@ test.group('Story service', (group) => { assert.isFalse(translationGallery.find((item) => item.id === story.id)?.isPublished); }); - test('editProps and buildUpdatePayload use localisation publish status', async ({ + test('editProps and updatePayloadFor use localisation publish status', async ({ assert, }) => { const story = await StoryFactory.with('localisations').merge({ isPublished: true }).create(); @@ -370,7 +370,7 @@ test.group('Story service', (group) => { const translationProps = await service.editProps( createMockHttpContext({ storyId: story.id, locale: translationLocale }), ); - const translationPayload = await service.buildUpdatePayload(story.id, translationLocale); + const translationPayload = await service.updatePayloadFor(story.id, translationLocale); assert.isTrue(sourceProps!.model.isPublished); assert.isFalse(translationProps!.model.isPublished); @@ -446,13 +446,13 @@ test.group('Story service', (group) => { }); }); -test.group('StoryService.prepSections', (group) => { +test.group('StoryService.preppedSections', (group) => { group.each.setup(() => testUtils.db().wrapInGlobalTransaction()); const service = new StoryService(testCmsConfig); test('returns an empty array when sections are omitted', async ({ assert }) => { - const result = await service.prepSections(versionFor(1, sourceLocale)); + const result = await service.preppedSections(versionFor(1, sourceLocale)); assert.deepEqual(result, []); }); @@ -460,7 +460,7 @@ test.group('StoryService.prepSections', (group) => { test('returns an empty array when sections are an empty array on the source locale', async ({ assert, }) => { - const result = await service.prepSections(versionFor(1, sourceLocale), []); + const result = await service.preppedSections(versionFor(1, sourceLocale), []); assert.deepEqual(result, []); }); @@ -475,7 +475,7 @@ test.group('StoryService.prepSections', (group) => { { title: 'Part Four' }, ]; - const result = await service.prepSections(versionFor(1, sourceLocale), posted); + const result = await service.preppedSections(versionFor(1, sourceLocale), posted); assert.lengthOf(result, 4); assert.equal(result[0].id, 'existing-id'); @@ -501,7 +501,7 @@ test.group('StoryService.prepSections', (group) => { }) => { const story = await StoryFactory.merge({ id: 90 }).create(); - const result = await service.prepSections(versionFor(story.id, translationLocale), [ + const result = await service.preppedSections(versionFor(story.id, translationLocale), [ { id: 'ignored', title: 'Translated title' }, ]); @@ -519,7 +519,7 @@ test.group('StoryService.prepSections', (group) => { sourceLocal.sections = []; await sourceLocal.save(); - const result = await service.prepSections(versionFor(story.id, translationLocale), [ + const result = await service.preppedSections(versionFor(story.id, translationLocale), [ { id: 'ignored', title: 'Translated title' }, ]); @@ -547,7 +547,7 @@ test.group('StoryService.prepSections', (group) => { { id: 'client-id-b', title: 'Profundizar', description: 'ES body' }, ]; - const result = await service.prepSections( + const result = await service.preppedSections( versionFor(story.id, translationLocale), posted, ); @@ -574,7 +574,7 @@ test.group('StoryService.prepSections', (group) => { sourceLocal.sections = sourceSections; await sourceLocal.save(); - const result = await service.prepSections(versionFor(story.id, translationLocale), [ + const result = await service.preppedSections(versionFor(story.id, translationLocale), [ { id: 'client-id-a', title: 'Solo intro', description: 'Solo ES' }, ]); @@ -598,7 +598,7 @@ test.group('StoryService.prepSections', (group) => { ]; await sourceLocal.save(); - const result = await service.prepSections(versionFor(story.id, translationLocale), [ + const result = await service.preppedSections(versionFor(story.id, translationLocale), [ { id: 'section-a', title: 'Introducción', description: 'ES intro' }, { id: 'section-b', title: 'Extra', description: 'Should be dropped' }, ]); diff --git a/src/frontend/resources/resource-used-in.vue b/src/frontend/resources/resource-used-in.vue index a36af9f7..62e070ab 100644 --- a/src/frontend/resources/resource-used-in.vue +++ b/src/frontend/resources/resource-used-in.vue @@ -12,8 +12,8 @@
import { computed } from 'vue'; import { BookOpen } from '@lucide/vue'; -import type { ResourceStoryUsage } from '../../types'; +import type { ResourceUsage } from '../../types'; const props = defineProps<{ - stories: ResourceStoryUsage[]; + stories: ResourceUsage[]; locale: string; }>(); diff --git a/src/frontend/test/mocks.ts b/src/frontend/test/mocks.ts index 0672d393..4b0273f0 100644 --- a/src/frontend/test/mocks.ts +++ b/src/frontend/test/mocks.ts @@ -4564,8 +4564,8 @@ const toEditResource = ( }); export const mockUsedInStories: ResourceEditProps['usedInStories'] = [ - { storyId: 1, title: 'Biblical Foundations' }, - { storyId: 2, title: 'The Gospel of John' }, + { id: 1, title: 'Biblical Foundations' }, + { id: 2, title: 'The Gospel of John' }, ]; export const mockNewResourceEdit: ResourceEditProps = { diff --git a/src/types.ts b/src/types.ts index a087af32..298949a3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -200,8 +200,8 @@ export interface ResourceIndexProps { resources: ResourceIndexItem[]; } -export interface ResourceStoryUsage { - storyId: number; +export interface ResourceUsage { + id: number; title: string; } @@ -209,7 +209,7 @@ export interface ResourceEditProps { providers: Providers; resource: ResourceMeta; bundle: any; - usedInStories: ResourceStoryUsage[]; + usedInStories: ResourceUsage[]; } export type ResourceNotFoundProps = SharedPageProps; @@ -808,10 +808,7 @@ export interface LanguageListItemProps { } export type SupportCode = - | 'REMOVE_LANGUAGE' - | 'UPDATE_LANGUAGE' - | 'UPDATE_CONTENT' - | 'UPDATE_APP'; + 'REMOVE_LANGUAGE' | 'UPDATE_LANGUAGE' | 'UPDATE_CONTENT' | 'UPDATE_APP'; export interface SupportRequest { supportCode: SupportCode;