diff --git a/apps/web/src/app/api/search/route.ts b/apps/web/src/app/api/search/route.ts index 6c48be33a..eead153dc 100644 --- a/apps/web/src/app/api/search/route.ts +++ b/apps/web/src/app/api/search/route.ts @@ -17,7 +17,7 @@ export async function GET(request: Request) { parents: { parents: {}, select: { - id: Entry.entryId, + id: Entry.id, title: Entry.title } } diff --git a/apps/web/src/layout/Header.tsx b/apps/web/src/layout/Header.tsx index a372e85a0..ba2770ff7 100644 --- a/apps/web/src/layout/Header.tsx +++ b/apps/web/src/layout/Header.tsx @@ -55,7 +55,7 @@ async function MobileNav() { const docs = await cms.find({ location: cms.workspaces.main.pages.docs, select: { - id: Entry.entryId, + id: Entry.id, type: Entry.type, url: Entry.url, title: Entry.title, diff --git a/apps/web/src/page/BlogPage.tsx b/apps/web/src/page/BlogPage.tsx index 71e15d8fd..8ca920e50 100644 --- a/apps/web/src/page/BlogPage.tsx +++ b/apps/web/src/page/BlogPage.tsx @@ -23,7 +23,7 @@ export default async function BlogPage() { type: BlogPost, select: { ...Entry, - id: Entry.entryId, + id: Entry.id, introduction: BlogPost.introduction, author: BlogPost.author, publishDate: BlogPost.publishDate diff --git a/apps/web/src/page/DocPage.tsx b/apps/web/src/page/DocPage.tsx index a9b562523..f65561deb 100644 --- a/apps/web/src/page/DocPage.tsx +++ b/apps/web/src/page/DocPage.tsx @@ -27,7 +27,7 @@ interface DocPageProps { } const summary = { - id: Entry.entryId, + id: Entry.id, title: Entry.title, url: Entry.url } @@ -47,7 +47,7 @@ async function getPage(params: DocPageParams) { filter: {_url: url}, include: { ...Doc, - id: Entry.entryId, + id: Entry.id, level: Entry.level, parents: { parents: {}, @@ -98,7 +98,7 @@ export async function generateMetadata({ export default async function DocPage({params}: DocPageProps) { const {doc, framework} = await getPage(params) const select = { - id: Entry.entryId, + id: Entry.id, type: Entry.type, url: Entry.url, title: Entry.title, diff --git a/src/backend/Database.test.ts b/src/backend/Database.test.ts index 63bde636e..6b42c3fe7 100644 --- a/src/backend/Database.test.ts +++ b/src/backend/Database.test.ts @@ -16,9 +16,9 @@ test('create', async () => { await example.commit(parent) const result = await example.get({ select: Entry, - filter: {_id: parent.entryId} + filter: {_id: parent.id} }) - assert.is(result.entryId, parent.entryId) + assert.is(result.id, parent.id) assert.is(result.title, 'New parent') }) @@ -37,9 +37,9 @@ test('index is correct', async () => { }) const first = generateKeyBetween(null, null) const second = generateKeyBetween(first, null) - assert.is(entries[0]._id, entryA.entryId) + assert.is(entries[0]._id, entryA.id) assert.is(entries[0]._index, first) - assert.is(entries[1]._id, entryB.entryId) + assert.is(entries[1]._id, entryB.id) assert.is(entries[1]._index, second) }) @@ -51,11 +51,11 @@ test('remove child entries', async () => { const entry = sub.createChild(Page) await example.commit(parent, sub, entry) const res1 = await example.get({ - filter: {_id: entry.entryId} + filter: {_id: entry.id} }) - assert.is(res1._parent, sub.entryId) - await example.commit(Edit.remove(parent.entryId)) - const res2 = await example.find({first: true, filter: {_id: entry.entryId}}) + assert.is(res1._parent, sub.id) + await example.commit(Edit.remove(parent.id)) + const res2 = await example.find({first: true, filter: {_id: entry.id}}) assert.not.ok(res2) }) @@ -67,36 +67,36 @@ test('change draft path', async () => { await example.commit(parent, sub) const resParent0 = await example.get({ select: Entry, - filter: {_id: parent.entryId} + filter: {_id: parent.id} }) assert.is(resParent0.url, '/parent') // Changing entry paths in draft should not have an influence on // computed properties such as url, filePath etc. until we publish. await example.commit( - Edit.update(parent.entryId, Container).set({path: 'new-path'}).draft() + Edit.update(parent.id, Container).set({path: 'new-path'}).draft() ) const resParent1 = await example.get({ select: Entry, - filter: {_id: parent.entryId}, + filter: {_id: parent.id}, status: 'draft' }) assert.is(resParent1.url, '/parent') const res1 = await example.get({ select: Entry, - filter: {_id: sub.entryId} + filter: {_id: sub.id} }) assert.is(res1.url, '/parent/sub') // Once we publish, the computed properties should be updated. - await example.commit(Edit.publish(parent.entryId)) + await example.commit(Edit.publish(parent.id)) const resParent2 = await example.get({ select: Entry, - filter: {_id: parent.entryId} + filter: {_id: parent.id} }) assert.is(resParent2.url, '/new-path') const res2 = await example.get({ select: Entry, - filter: {_id: sub.entryId} + filter: {_id: sub.id} }) assert.is(res2.url, '/new-path/sub') }) @@ -145,7 +145,7 @@ test('change published path for entry with language', async () => { assert.is(localised3.url, '/en/localised2/localised3') // Archive localised3 - await example.commit(Edit.archive(localised3.entryId)) + await example.commit(Edit.archive(localised3.id)) const localised3Archived = await example.get({ location: example.workspaces.main.multiLanguage, @@ -156,7 +156,7 @@ test('change published path for entry with language', async () => { assert.is(localised3Archived.phase, EntryPhase.Archived) // And publish again - await example.commit(Edit.publish(localised3.entryId)) + await example.commit(Edit.publish(localised3.id)) const localised3Publish = await example.get({ locale: 'en', select: Entry, @@ -222,7 +222,7 @@ test('field creators', async () => { await example.commit(entry) const listRes = await example.get({ select: Fields.list, - filter: {_id: entry.entryId} + filter: {_id: entry.id} }) const res = listRes[0] if (res[Node.type] !== 'Text') throw new Error('Expected Text') @@ -243,15 +243,15 @@ test('remove media library and files', async () => { const upload = Edit.upload([ 'test.txt', new TextEncoder().encode('Hello, World!') - ]).setParent(library.entryId) + ]).setParent(library.id) await example.commit(upload) const result = await example.get({ select: Entry, filter: {_id: upload.entryId} }) - assert.is(result.parent, library.entryId) + assert.is(result.parent, library.id) assert.is(result.root, 'media') - await example.commit(Edit.remove(library.entryId)) + await example.commit(Edit.remove(library.id)) const result2 = await example.first({ filter: {_id: upload.entryId} }) @@ -265,14 +265,14 @@ test('create multi language entries', async () => { select: Entry, filter: {_path: 'localised2'} }) - const entry = Edit.create(Page).setParent(localised2.entryId).set({ + const entry = Edit.create(Page).setParent(localised2.id).set({ title: 'New entry', path: 'new-entry' }) await example.commit(entry) const result = await example.get({ select: Entry, - filter: {_id: entry.entryId} + filter: {_id: entry.id} }) assert.is(result.url, '/en/localised2/new-entry') }) diff --git a/src/backend/Database.ts b/src/backend/Database.ts index ff0b49eb4..28f112862 100644 --- a/src/backend/Database.ts +++ b/src/backend/Database.ts @@ -150,10 +150,7 @@ export class Database implements Syncable { childrenDir: next.childrenDir, url: next.url }) - .where( - eq(EntryRow.entryId, entry.entryId), - eq(EntryRow.phase, entry.phase) - ) + .where(eq(EntryRow.id, entry.id), eq(EntryRow.phase, entry.phase)) return this.updateChildren(tx, entry, next) } @@ -186,10 +183,7 @@ export class Database implements Syncable { parentDir, url }) - .where( - eq(EntryRow.entryId, child.entryId), - eq(EntryRow.phase, child.phase) - ) + .where(eq(EntryRow.id, child.id), eq(EntryRow.phase, child.phase)) } return children } @@ -202,7 +196,7 @@ export class Database implements Syncable { for (const entry of entries) { console.info( entry.url.padEnd(35), - entry.entryId.padEnd(12), + entry.id.padEnd(12), entry.phase.padEnd(12), entry.title ) @@ -216,7 +210,7 @@ export class Database implements Syncable { switch (mutation.type) { case MutationType.Create: { const condition = and( - eq(EntryRow.entryId, mutation.entryId), + eq(EntryRow.id, mutation.entryId), eq(EntryRow.phase, mutation.entry.phase) ) const current = await tx.select().from(EntryRow).where(condition).get() @@ -227,7 +221,7 @@ export class Database implements Syncable { case MutationType.Edit: { const {entryId, entry} = mutation const condition = and( - eq(EntryRow.entryId, entryId), + eq(EntryRow.id, entryId), eq(EntryRow.phase, entry.phase) ) const current = await tx.select().from(EntryRow).where(condition).get() @@ -242,8 +236,8 @@ export class Database implements Syncable { this.updateHash( tx, inArray( - EntryRow.entryId, - children.map(e => e.entryId) + EntryRow.id, + children.map(e => e.id) ) ).then(children => self.concat(children)) ) @@ -252,7 +246,7 @@ export class Database implements Syncable { case MutationType.Patch: { const {patch} = mutation const condition = and( - eq(EntryRow.entryId, mutation.entryId), + eq(EntryRow.id, mutation.entryId), eq(EntryRow.main, true) ) const current = await tx.select().from(EntryRow).where(condition).get() @@ -265,11 +259,11 @@ export class Database implements Syncable { } case MutationType.Archive: { const archived = and( - eq(EntryRow.entryId, mutation.entryId), + eq(EntryRow.id, mutation.entryId), eq(EntryRow.phase, EntryPhase.Archived) ) const condition = and( - eq(EntryRow.entryId, mutation.entryId), + eq(EntryRow.id, mutation.entryId), eq(EntryRow.phase, EntryPhase.Published) ) const published = await tx @@ -296,14 +290,14 @@ export class Database implements Syncable { .from(EntryRow) .where( and( - eq(EntryRow.entryId, mutation.entryId), + eq(EntryRow.id, mutation.entryId), eq(EntryRow.phase, mutation.phase) ) ) .get() if (!promoting) return const condition = and( - eq(EntryRow.entryId, mutation.entryId), + eq(EntryRow.id, mutation.entryId), eq(EntryRow.phase, EntryPhase.Published) ) await tx.delete(EntryRow).where(condition) @@ -313,8 +307,8 @@ export class Database implements Syncable { return this.updateHash( tx, inArray( - EntryRow.entryId, - children.map(e => e.entryId) + EntryRow.id, + children.map(e => e.id) ) ).then(r => rows.concat(r)) }) @@ -325,7 +319,7 @@ export class Database implements Syncable { const phases = await tx .select() .from(EntryRow) - .where(eq(EntryRow.entryId, mutation.entryId)) + .where(eq(EntryRow.id, mutation.entryId)) if (phases.length === 0) return // Remove child entries for (const phase of phases) { @@ -338,34 +332,34 @@ export class Database implements Syncable { ) ) } - await tx.delete(EntryRow).where(eq(EntryRow.entryId, mutation.entryId)) + await tx.delete(EntryRow).where(eq(EntryRow.id, mutation.entryId)) return async () => [phases[0].i18nId] } case MutationType.Discard: { const existing = await tx .select() .from(EntryRow) - .where(eq(EntryRow.entryId, mutation.entryId)) + .where(eq(EntryRow.id, mutation.entryId)) .get() if (!existing) return await tx .delete(EntryRow) .where( and( - eq(EntryRow.entryId, mutation.entryId), + eq(EntryRow.id, mutation.entryId), eq(EntryRow.phase, EntryPhase.Draft) ) ) return async () => [existing.i18nId] } case MutationType.Order: { - const condition = eq(EntryRow.entryId, mutation.entryId) + const condition = eq(EntryRow.id, mutation.entryId) // Todo: apply this to other languages too await tx.update(EntryRow).set({index: mutation.index}).where(condition) return () => this.updateHash(tx, condition) } case MutationType.Move: { - const condition = eq(EntryRow.entryId, mutation.entryId) + const condition = eq(EntryRow.id, mutation.entryId) await tx .update(EntryRow) .set({ @@ -384,7 +378,7 @@ export class Database implements Syncable { // syncing to the client after a successful deploy will overwrite this // change. const condition = and( - eq(EntryRow.entryId, mutation.entryId), + eq(EntryRow.id, mutation.entryId), eq(EntryRow.phase, EntryPhase.Published) ) const existing = await tx.select().from(EntryRow).where(condition).get() @@ -419,10 +413,7 @@ export class Database implements Syncable { fileHash: updated.fileHash, rowHash: updated.rowHash }) - .where( - eq(EntryRow.entryId, entry.entryId), - eq(EntryRow.phase, entry.phase) - ) + .where(eq(EntryRow.id, entry.id), eq(EntryRow.phase, entry.phase)) } return changed } @@ -440,7 +431,7 @@ export class Database implements Syncable { static async index(tx: Store) { const Parent = alias(EntryRow, 'Parent') const parent = tx - .select(Parent.entryId) + .select(Parent.id) .from(Parent) .where( eq(Parent.childrenDir, EntryRow.parentDir), @@ -521,7 +512,7 @@ export class Database implements Syncable { ) const childrenDir = paths.join(parentDir, entryPath) - if (!recordMeta.entryId) throw new Error(`missing id`) + if (!recordMeta.id) throw new Error(`missing id`) const urlMeta: EntryUrlMeta = { locale, @@ -549,7 +540,7 @@ export class Database implements Syncable { active: false, main: false, - entryId: recordMeta.entryId, + id: recordMeta.id, phase: entryPhase, type: recordMeta.type, @@ -559,7 +550,7 @@ export class Database implements Syncable { level: parentDir === '/' ? 0 : segments.length, index: recordMeta.index, locale, - i18nId: recordMeta.i18nId ?? recordMeta.entryId, + i18nId: recordMeta.i18nId ?? recordMeta.id, path: entryPath, title, @@ -694,14 +685,11 @@ export class Database implements Syncable { } await tx .delete(EntryRow) - .where( - eq(EntryRow.entryId, entry.entryId), - eq(EntryRow.phase, entry.phase) - ) + .where(eq(EntryRow.id, entry.id), eq(EntryRow.phase, entry.phase)) seenSeeds.add(key) await tx.insert(EntryRow).values(withHash) - seenVersions.push(`${entry.entryId}.${entry.phase}`) - inserted.push(`${entry.entryId}.${entry.phase}`) + seenVersions.push(`${entry.id}.${entry.phase}`) + inserted.push(`${entry.id}.${entry.phase}`) } catch (e: any) { console.info(`> skipped ${file.filePath} — ${e.message}`) console.error(e) @@ -731,7 +719,7 @@ export class Database implements Syncable { } const entry = this.computeEntry( createRecord({ - entryId: createId(), + id: createId(), i18nId, type: typeName, index: 'a0', @@ -747,8 +735,8 @@ export class Database implements Syncable { const fileHash = await createFileHash(fileContents) const withHash = {...entry, fileHash, rowHash: ''} await tx.insert(EntryRow).values(withHash) - seenVersions.push(`${withHash.entryId}.${withHash.phase}`) - inserted.push(`${entry.entryId}.${entry.phase}`) + seenVersions.push(`${withHash.id}.${withHash.phase}`) + inserted.push(`${entry.id}.${entry.phase}`) publishSeed.push({ ...withHash, title: undefined!, @@ -786,10 +774,7 @@ export class Database implements Syncable { .set({ rowHash }) - .where( - eq(EntryRow.entryId, entry.entryId), - eq(EntryRow.phase, entry.phase) - ) + .where(eq(EntryRow.id, entry.id), eq(EntryRow.phase, entry.phase)) } await this.writeMeta(tx, commitHash) }) @@ -824,7 +809,7 @@ export class Database implements Syncable { // Temporarily add preview entry await tx .delete(EntryRow) - .where(eq(EntryRow.entryId, entry.entryId), eq(EntryRow.active, true)) + .where(eq(EntryRow.id, entry.id), eq(EntryRow.active, true)) await tx.insert(EntryRow).values(entry) await Database.index(tx) const result = await query(tx) @@ -846,25 +831,19 @@ namespace EntryRealm { builder .select() .from(Alt) - .where(eq(Alt.phase, EntryPhase.Draft), eq(Alt.entryId, EntryRow.entryId)) + .where(eq(Alt.phase, EntryPhase.Draft), eq(Alt.id, EntryRow.id)) ) const hasPublished = exists( builder .select() .from(Alt) - .where( - eq(Alt.phase, EntryPhase.Published), - eq(Alt.entryId, EntryRow.entryId) - ) + .where(eq(Alt.phase, EntryPhase.Published), eq(Alt.id, EntryRow.id)) ) const hasArchived = exists( builder .select() .from(Alt) - .where( - eq(Alt.phase, EntryPhase.Archived), - eq(Alt.entryId, EntryRow.entryId) - ) + .where(eq(Alt.phase, EntryPhase.Archived), eq(Alt.id, EntryRow.id)) ) const isPublishedWithoutDraft = and(isPublished, not(hasDraft)) const isArchivedWithoutDraftOrPublished = and( diff --git a/src/backend/resolver/EntryResolver.ts b/src/backend/resolver/EntryResolver.ts index 103ac9072..01b54bf71 100644 --- a/src/backend/resolver/EntryResolver.ts +++ b/src/backend/resolver/EntryResolver.ts @@ -87,7 +87,7 @@ export class EntryResolver { } selectCount(ctx: ResolveContext, hasSearch: boolean): SelectionInput { - return count(hasSearch ? EntrySearch.rowid : ctx.Table.entryId).as('count') + return count(hasSearch ? EntrySearch.rowid : ctx.Table.id).as('count') } projectTypes(types: Array): Array<[string, Expr]> { @@ -148,7 +148,7 @@ export class EntryResolver { const from = alias(EntryRow, `E${ctx.depth - 1}`) // .as(source.id) switch (querySource(query)) { case 'parent': - return cursor.where(eq(ctx.Table.entryId, from.parent)).limit(1) + return cursor.where(eq(ctx.Table.id, from.parent)).limit(1) case 'next': return cursor .where( @@ -166,36 +166,34 @@ export class EntryResolver { case 'siblings': return cursor.where( eq(ctx.Table.parent, from.parent), - query.siblings?.includeSelf - ? undefined - : ne(ctx.Table.entryId, from.entryId) + query.siblings?.includeSelf ? undefined : ne(ctx.Table.id, from.id) ) case 'translations': return cursor.where( eq(ctx.Table.i18nId, from.i18nId), query.translations?.includeSelf ? undefined - : ne(ctx.Table.entryId, from.entryId) + : ne(ctx.Table.id, from.id) ) case 'children': const Child = alias(EntryRow, 'Child') const children = builder.$with('children').as( builder .select({ - entryId: Child.entryId, + entryId: Child.id, parent: Child.parent, level: sql`0` }) .from(Child) .where( - eq(Child.entryId, from.entryId), + eq(Child.id, from.id), this.conditionStatus(Child, ctx.status), this.conditionLocale(Child, ctx.locale) ) .unionAll(self => builder .select({ - entryId: Child.entryId, + entryId: Child.id, parent: Child.parent, level: sql`${self.level} + 1` }) @@ -218,32 +216,32 @@ export class EntryResolver { .limit(-1) .offset(1) return cursor - .where(inArray(ctx.Table.entryId, childrenIds)) + .where(inArray(ctx.Table.id, childrenIds)) .orderBy(asc(ctx.Table.index)) case 'parents': const Parent = alias(EntryRow, 'Parent') const parents = builder.$with('parents').as( builder .select({ - entryId: Parent.entryId, + entryId: Parent.id, parent: Parent.parent, level: sql`0` }) .from(Parent) .where( - eq(Parent.entryId, from.entryId), + eq(Parent.id, from.id), this.conditionStatus(Parent, ctx.status), this.conditionLocale(Parent, ctx.locale) ) .unionAll(self => builder .select({ - entryId: Parent.entryId, + entryId: Parent.id, parent: Parent.parent, level: sql`${self.level} + 1` }) .from(Parent) - .innerJoin(self, eq(self.parent, Parent.entryId)) + .innerJoin(self, eq(self.parent, Parent.id)) .where( this.conditionStatus(Parent, ctx.status), this.conditionLocale(Parent, ctx.locale), @@ -261,7 +259,7 @@ export class EntryResolver { .limit(-1) .offset(1) return cursor - .where(inArray(ctx.Table.entryId, parentIds)) + .where(inArray(ctx.Table.id, parentIds)) .orderBy(asc(ctx.Table.level)) default: return cursor.orderBy(asc(ctx.Table.index)) @@ -366,9 +364,7 @@ export class EntryResolver { function filterField(ctx: ResolveContext, name: string): HasSql { if (name.startsWith('_')) { const entryProp = name.slice(1) - const key = ( - entryProp === 'id' ? 'entryId' : entryProp - ) as keyof EntryRow + const key = entryProp as keyof EntryRow if (!(key in ctx.Table)) throw new Error(`Unknown field: "${name}"`) return ctx.Table[key] } diff --git a/src/backend/resolver/LinkResolver.ts b/src/backend/resolver/LinkResolver.ts index b69dc5c45..052c285bf 100644 --- a/src/backend/resolver/LinkResolver.ts +++ b/src/backend/resolver/LinkResolver.ts @@ -22,7 +22,7 @@ export class LinkResolver { new ResolveContext({status: this.status}), { select: { - entryId: Entry.entryId, + entryId: Entry.id, projection: projection }, filter: {_id: {in: ids}} diff --git a/src/core/Entry.ts b/src/core/Entry.ts index cd052e6ec..8e9735eb8 100644 --- a/src/core/Entry.ts +++ b/src/core/Entry.ts @@ -3,7 +3,7 @@ import {Expr} from './Expr.js' import {Expand} from './util/Types.js' export interface Entry { - entryId: string + id: string phase: EntryPhase title: string type: string @@ -28,7 +28,7 @@ export interface Entry { searchableText: string } export const Entry = { - entryId: new Expr(), + id: new Expr(), phase: new Expr(), title: new Expr(), type: new Expr(), diff --git a/src/core/EntryFields.ts b/src/core/EntryFields.ts index 906ed8120..ad2880ba6 100644 --- a/src/core/EntryFields.ts +++ b/src/core/EntryFields.ts @@ -17,7 +17,7 @@ export interface EntryFields { } export const EntryFields = { - _id: Entry.entryId, + _id: Entry.id, _type: Entry.type, _index: Entry.index, _i18nId: Entry.i18nId, diff --git a/src/core/EntryRecord.ts b/src/core/EntryRecord.ts index e7cb928a9..7f03ed025 100644 --- a/src/core/EntryRecord.ts +++ b/src/core/EntryRecord.ts @@ -36,27 +36,26 @@ interface OldMeta { } export interface RequiredEntryFields extends Partial { - entryId: string + id: string type: string index: string data: Record } export function parseRecord(record: EntryRecord) { - const oldest = record.alinea as any const { [META_KEY]: old, - [EntryRecord.id]: entryId = old?.entryId! ?? record.id, - [EntryRecord.type]: type = old?.type! ?? record.type, - [EntryRecord.index]: index = old?.index! ?? oldest?.index, - [EntryRecord.i18nId]: i18nId = old?.i18nId! ?? oldest?.i18nId, - [EntryRecord.root]: root = old?.root! ?? oldest?.root, - [EntryRecord.seeded]: seeded = (old?.seeded as string) ?? oldest?.seeded, + [EntryRecord.id]: id, + [EntryRecord.type]: type, + [EntryRecord.index]: index, + [EntryRecord.i18nId]: i18nId, + [EntryRecord.root]: root, + [EntryRecord.seeded]: seeded, ...data } = record return { meta: { - entryId, + id, type, index, i18nId, @@ -70,7 +69,7 @@ export function parseRecord(record: EntryRecord) { export function createRecord(entry: RequiredEntryFields): EntryRecord { const {path = entry.path, title = entry.title, ...data} = entry.data const meta: EntryRecord = { - [EntryRecord.id]: entry.entryId, + [EntryRecord.id]: entry.id, [EntryRecord.type]: entry.type, [EntryRecord.index]: entry.index, [EntryRecord.i18nId]: entry.i18nId diff --git a/src/core/EntryRow.ts b/src/core/EntryRow.ts index 86c7cc010..0bfa45313 100644 --- a/src/core/EntryRow.ts +++ b/src/core/EntryRow.ts @@ -21,7 +21,7 @@ export const EntryRow = table( 'Entry', { // Entry data - entryId: column.text().$default(createId), + id: column.text().$default(createId), phase: column.text().notNull().$type(), title: column.text().notNull(), type: column.text().notNull(), @@ -61,7 +61,7 @@ export const EntryRow = table( }, EntryRow => { return { - primary: primaryKey(EntryRow.entryId, EntryRow.phase), + primary: primaryKey(EntryRow.id, EntryRow.phase), rowHash: index().on(EntryRow.rowHash), type: index().on(EntryRow.type), parent: index().on(EntryRow.parent), @@ -89,7 +89,7 @@ export function concat(...slices: Array>) { } export function entryVersionId(entry = EntryRow) { - return concat(entry.entryId, sql.value('.'), entry.phase) + return concat(entry.id, sql.value('.'), entry.phase) } /** diff --git a/src/core/Transaction.ts b/src/core/Transaction.ts index 2dcc1cce0..cd3666a84 100644 --- a/src/core/Transaction.ts +++ b/src/core/Transaction.ts @@ -117,7 +117,7 @@ export class UploadOperation extends Operation { 'MediaFile', { path, - entryId: this.entryId, + id: this.entryId, workspace, root, data: entryData @@ -135,7 +135,7 @@ export class UploadOperation extends Operation { }, { type: MutationType.Create, - entryId: entry.entryId, + entryId: entry.id, file: entryFile, entry } @@ -299,7 +299,7 @@ export class CreateOperation extends Operation { status: 'preferPublished', select: Entry.index, filter: { - _parent: parent?.entryId ?? null + _parent: parent?.id ?? null }, orderBy: {desc: Entry.index, caseSensitive: true} }) @@ -319,13 +319,13 @@ export class CreateOperation extends Operation { return [ { type: MutationType.Create, - entryId: entry.entryId, + entryId: entry.id, file, entry: entry } ] }) - this.entry = {entryId: createId(), ...entry} + this.entry = {id: createId(), ...entry} } setParent(parentId: string) { @@ -357,8 +357,8 @@ export class CreateOperation extends Operation { return new CreateOperation({}, type, this.entryRow) } - get entryId() { - return this.entry.entryId! + get id() { + return this.entry.id! } static fromType(type: Type) { @@ -389,10 +389,10 @@ async function createEntry( (partial.path ?? title) ) const entryData = {title, path, ...partial.data} - const entryId = partial.entryId ?? createId() + const id = partial.id ?? createId() const i18nId = partial.i18nId ?? createId() const details = { - entryId, + id, phase, type: typeName, title, @@ -401,7 +401,7 @@ async function createEntry( workspace: workspace, root: root, level: parent ? parent.level + 1 : 0, - parent: parent?.entryId ?? null, + parent: parent?.id ?? null, locale, index: partial.index ?? 'a0', i18nId, diff --git a/src/core/media/Summary.ts b/src/core/media/Summary.ts index 8700d7f8f..e7e6b10e9 100644 --- a/src/core/media/Summary.ts +++ b/src/core/media/Summary.ts @@ -5,7 +5,7 @@ import {MediaFile as MediaFileType} from './MediaTypes.js' export function summarySelection(schema: Schema) { const MediaFile = schema.MediaFile as typeof MediaFileType return { - entryId: Entry.entryId, + entryId: Entry.id, i18nId: Entry.i18nId, type: Entry.type, workspace: Entry.workspace, @@ -22,7 +22,7 @@ export function summarySelection(schema: Schema) { parents: { parents: {}, select: { - entryId: Entry.entryId, + entryId: Entry.id, i18nId: Entry.i18nId, title: Entry.title } diff --git a/src/core/util/ContentHash.ts b/src/core/util/ContentHash.ts index 52b734b49..3e81ecce5 100644 --- a/src/core/util/ContentHash.ts +++ b/src/core/util/ContentHash.ts @@ -16,7 +16,7 @@ export async function createFileHash(data: Uint8Array) { export async function createRowHash(entry: Omit) { const encoder = new TextEncoder() const data = encoder.encode( - `entryId ${entry.entryId}` + + `entryId ${entry.id}` + `phase ${entry.phase}` + `title ${entry.title}` + `type ${entry.type}` + diff --git a/src/dashboard/Routes.tsx b/src/dashboard/Routes.tsx index 2f2ccc277..18cae7226 100644 --- a/src/dashboard/Routes.tsx +++ b/src/dashboard/Routes.tsx @@ -40,7 +40,7 @@ const editLoader = atomFamily(() => { const graph = await get(graphAtom) const entry = await graph.first({ select: { - entryId: Entry.entryId, + entryId: Entry.id, locale: Entry.locale, i18nId: Entry.i18nId, root: Entry.root, diff --git a/src/dashboard/atoms/EntryAtoms.ts b/src/dashboard/atoms/EntryAtoms.ts index 8846897d3..ed319e6d9 100644 --- a/src/dashboard/atoms/EntryAtoms.ts +++ b/src/dashboard/atoms/EntryAtoms.ts @@ -76,7 +76,7 @@ const entryTreeItemLoaderAtom = atom(async get => { const search = (ids as Array).filter(id => id !== rootId(root.name)) const data = { id: Entry.i18nId, - entryId: Entry.entryId, + entryId: Entry.id, type: Entry.type, title: Entry.title, phase: Entry.phase, @@ -93,7 +93,7 @@ const entryTreeItemLoaderAtom = atom(async get => { groupBy: Entry.i18nId, select: { id: Entry.i18nId, - entryId: Entry.entryId, + entryId: Entry.id, index: Entry.index, type: Entry.type, data, diff --git a/src/dashboard/atoms/EntryEditorAtoms.ts b/src/dashboard/atoms/EntryEditorAtoms.ts index f36398e0f..4837076d0 100644 --- a/src/dashboard/atoms/EntryEditorAtoms.ts +++ b/src/dashboard/atoms/EntryEditorAtoms.ts @@ -100,7 +100,7 @@ export const entryEditorAtoms = atomFamily( }) } if (!entry) return undefined - const entryId = entry.entryId + const entryId = entry.id get(entryRevisionAtoms(entry.i18nId)) const type = config.schema[entry.type] const edits = get(entryEditsAtoms(entryId)) @@ -148,7 +148,7 @@ export const entryEditorAtoms = atomFamily( parents: { parents: {}, select: { - entryId: Entry.entryId, + entryId: Entry.id, path: Entry.path } } @@ -161,7 +161,7 @@ export const entryEditorAtoms = atomFamily( const translations = (await graph.find({ select: { locale: Entry.locale, - entryId: Entry.entryId + entryId: Entry.id }, filter: { _locale: {isNot: null}, @@ -254,7 +254,7 @@ export function createEntryEditor(entryData: EntryData) { } ) - const transition = entryTransitionAtoms(activeVersion.entryId) + const transition = entryTransitionAtoms(activeVersion.id) const phaseInUrl = atom(get => { const {search} = get(locationAtom) @@ -320,7 +320,7 @@ export function createEntryEditor(entryData: EntryData) { type: MutationType.Edit, previousFile: entryFile(activeVersion), file: entryFile(entry), - entryId: activeVersion.entryId, + entryId: activeVersion.id, entry, update } @@ -346,7 +346,7 @@ export function createEntryEditor(entryData: EntryData) { ? await graph.get({ locale, select: { - entryId: Entry.entryId, + entryId: Entry.id, path: Entry.path, paths: { parents: {}, @@ -414,7 +414,7 @@ export function createEntryEditor(entryData: EntryData) { res.push({ type: MutationType.Patch, file: entryFile(translation, translation.parentPaths), - entryId: translation.entryId, + entryId: translation.id, patch: shared }) } @@ -453,7 +453,7 @@ export function createEntryEditor(entryData: EntryData) { type: MutationType.Edit, previousFile: currentFile, file: editedFile, - entryId: activeVersion.entryId, + entryId: activeVersion.id, entry, update }) @@ -485,7 +485,7 @@ export function createEntryEditor(entryData: EntryData) { type: MutationType.Edit, previousFile: editedFile, file: editedFile, - entryId: activeVersion.entryId, + entryId: activeVersion.id, entry, update } @@ -503,7 +503,7 @@ export function createEntryEditor(entryData: EntryData) { { type: MutationType.Publish, phase: EntryPhase.Draft, - entryId: activeVersion.entryId, + entryId: activeVersion.id, file: entryFile(activeVersion) } ] @@ -520,7 +520,7 @@ export function createEntryEditor(entryData: EntryData) { const discardDraft = atom(null, (get, set) => { const mutation: Mutation = { type: MutationType.Discard, - entryId: activeVersion.entryId, + entryId: activeVersion.id, file: entryFile(activeVersion) } return set(transact, { @@ -534,7 +534,7 @@ export function createEntryEditor(entryData: EntryData) { const published = entryData.phases[EntryPhase.Published] const mutation: Mutation = { type: MutationType.Archive, - entryId: published.entryId, + entryId: published.id, file: entryFile(published) } return set(transact, { @@ -549,7 +549,7 @@ export function createEntryEditor(entryData: EntryData) { const mutation: Mutation = { type: MutationType.Publish, phase: EntryPhase.Archived, - entryId: archived.entryId, + entryId: archived.id, file: entryFile(archived) } return set(transact, { @@ -568,12 +568,12 @@ export function createEntryEditor(entryData: EntryData) { const mutations: Array = [ { type: MutationType.Archive, - entryId: published.entryId, + entryId: published.id, file: entryFile(published) }, { type: MutationType.Remove, - entryId: published.entryId, + entryId: published.id, file: entryFile({...published, phase: EntryPhase.Archived}) } ] @@ -592,7 +592,7 @@ export function createEntryEditor(entryData: EntryData) { const file = published.data as MediaFile const mutation: Mutation = { type: MutationType.FileRemove, - entryId: published.entryId, + entryId: published.id, workspace: published.workspace, location: MEDIA_LOCATION in file @@ -612,7 +612,7 @@ export function createEntryEditor(entryData: EntryData) { const archived = entryData.phases[EntryPhase.Archived] const mutation: Mutation = { type: MutationType.Remove, - entryId: archived.entryId, + entryId: archived.id, file: entryFile(archived) } return set(transact, { @@ -637,7 +637,7 @@ export function createEntryEditor(entryData: EntryData) { const phase = options.phase ?? activeVersion.phase const locale = options.locale ?? activeVersion.locale const path = options.path ?? data.path ?? activeVersion.path - const entryId = options.entryId ?? activeVersion.entryId + const entryId = options.entryId ?? activeVersion.id const parent = options.parent ?? activeVersion.parent const parentPaths = options.parentPaths ?? entryData.parents.map(p => p.path) @@ -729,7 +729,7 @@ export function createEntryEditor(entryData: EntryData) { const update = get(yUpdate) const phase = get(selectedPhase) return encodePreviewPayload({ - entryId: activeVersion.entryId, + entryId: activeVersion.id, contentHash, phase, update diff --git a/src/dashboard/hook/UseUploads.ts b/src/dashboard/hook/UseUploads.ts index 2abf34141..2241fb709 100644 --- a/src/dashboard/hook/UseUploads.ts +++ b/src/dashboard/hook/UseUploads.ts @@ -174,7 +174,7 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) { const parent = await graph.first({ select: { level: Entry.level, - entryId: Entry.entryId, + entryId: Entry.id, url: Entry.url, path: Entry.path, parentPaths: { @@ -220,7 +220,7 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) { const entry = await createEntryRow>(config, { ...entryLocation, parent: parent?.entryId ?? null, - entryId: entryId, + id: entryId, type: 'MediaFile', url: (parent ? parent.url : '') + '/' + path, title, @@ -296,13 +296,13 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) { await batchMutations( { type: MutationType.Create, - entryId: entry.entryId, + entryId: entry.id, file, entry }, { type: MutationType.Upload, - entryId: entry.entryId, + entryId: entry.id, url: info.previewUrl, file: info.location } @@ -317,19 +317,19 @@ export function useUploads(onSelect?: (entry: EntryRow) => void) { await batchMutations( { type: MutationType.Edit, - entryId: replace.entry.entryId, + entryId: replace.entry.id, file: replace.entryFile, entry: newEntry }, { type: MutationType.Upload, - entryId: replace.entry.entryId, + entryId: replace.entry.id, url: info.previewUrl, file: info.location }, { type: MutationType.FileRemove, - entryId: replace.entry.entryId, + entryId: replace.entry.id, file: replace.entryFile, workspace: replace.entry.workspace, location: diff --git a/src/dashboard/view/MediaExplorer.tsx b/src/dashboard/view/MediaExplorer.tsx index 2eb8a14bb..8b89673f0 100644 --- a/src/dashboard/view/MediaExplorer.tsx +++ b/src/dashboard/view/MediaExplorer.tsx @@ -54,7 +54,7 @@ export function MediaExplorer({editor}: MediaExplorerProps) { async () => { const query: QueryWithResult = { select: undefined!, - orderBy: [{desc: Entry.type}, {desc: Entry.entryId}], + orderBy: [{desc: Entry.type}, {desc: Entry.id}], filter: condition } const info = await graph.first({ diff --git a/src/dashboard/view/entry/NewEntry.tsx b/src/dashboard/view/entry/NewEntry.tsx index 7a6f07cec..8cb568209 100644 --- a/src/dashboard/view/entry/NewEntry.tsx +++ b/src/dashboard/view/entry/NewEntry.tsx @@ -43,7 +43,7 @@ import css from './NewEntry.module.scss' const styles = styler(css) const parentData = { - id: Entry.entryId, + id: Entry.id, i18nId: Entry.i18nId, type: Entry.type, path: Entry.path, @@ -240,7 +240,7 @@ function NewEntryForm({parentId}: NewEntryProps) { }) : {} const entry = await createEntryRow(config, { - entryId, + id: entryId, ...data, filePath, type: selected, @@ -262,7 +262,7 @@ function NewEntryForm({parentId}: NewEntryProps) { return mutate([ { type: MutationType.Create, - entryId: entry.entryId, + entryId: entry.id, entry, file: entryFileName(config, data, parentPaths) } diff --git a/src/dashboard/view/explorer/Explorer.tsx b/src/dashboard/view/explorer/Explorer.tsx index cacbff148..9698538bf 100644 --- a/src/dashboard/view/explorer/Explorer.tsx +++ b/src/dashboard/view/explorer/Explorer.tsx @@ -23,7 +23,7 @@ const defaultSummaryView = { } export interface ExporerItemSelect { - entryId: string + id: string type: string workspace: string root: string diff --git a/src/dashboard/view/explorer/ExplorerItem.tsx b/src/dashboard/view/explorer/ExplorerItem.tsx index 2c1c8e4d6..96d143df4 100644 --- a/src/dashboard/view/explorer/ExplorerItem.tsx +++ b/src/dashboard/view/explorer/ExplorerItem.tsx @@ -57,19 +57,19 @@ export function ExplorerItem({ explorer.selection.find( v => EntryReference.isEntryReference(v) && - v[EntryReference.entry] === entry.entryId + v[EntryReference.entry] === entry.id ) ) const childrenAmount = entry.childrenAmount ?? 0 function navigateTo() { - explorer.onNavigate?.(entry.entryId) + explorer.onNavigate?.(entry.id) } return (
extends EntryReference { } export namespace EntryLink { - export const entryId = Entry.entryId + export const entryId = Entry.id export const i18nId = Entry.i18nId export const title = Entry.title export const entryType = Entry.type diff --git a/src/picker/entry/EntryPicker.browser.tsx b/src/picker/entry/EntryPicker.browser.tsx index 5fd233613..7a333136e 100644 --- a/src/picker/entry/EntryPicker.browser.tsx +++ b/src/picker/entry/EntryPicker.browser.tsx @@ -121,7 +121,7 @@ export function EntryPickerModal({ parents: { parents: {}, select: { - id: Entry.entryId, + id: Entry.id, title: Entry.title } } @@ -179,7 +179,7 @@ export function EntryPickerModal({ const index = selected.findIndex( ref => EntryReference.isEntryReference(ref) && - ref[EntryReference.entry] === entry.entryId + ref[EntryReference.entry] === entry.id ) let res = selected.slice() if (index === -1) { @@ -187,7 +187,7 @@ export function EntryPickerModal({ .concat({ [Reference.id]: createId(), [Reference.type]: type, - [EntryReference.entry]: entry.entryId + [EntryReference.entry]: entry.id } as EntryReference) .slice(-(max || 0)) } else {