Skip to content

Commit

Permalink
Add index when creating entries through the api
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Oct 15, 2024
1 parent dfe9625 commit 9ecc203
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/core/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ export class GraphRealm implements GraphRealmApi {
if (Type.isType(select)) select = select().first()
const selection = createSelection(select)
serializeSelection(this.#targets, selection)
return this.#resolver.resolve({
...this.#params,
selection
})
return (
(await this.#resolver.resolve({
...this.#params,
selection
})) ?? null
)
}

get<S extends Projection | Type>(select: S): Promise<Projection.InferOne<S>>
Expand Down
9 changes: 8 additions & 1 deletion src/core/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
workspaceMediaDir
} from './util/EntryFilenames.js'
import {createEntryRow, entryParentPaths} from './util/EntryRows.js'
import {generateKeyBetween} from './util/FractionalIndexing.js'
import {basename, extname, join, normalize} from './util/Paths.js'
import {slugify} from './util/Slugs.js'

Expand Down Expand Up @@ -276,7 +277,13 @@ export class CreateOperation<Definition> extends Operation {
: partial.parent
? cms.graph.preferPublished.get(Entry({entryId: partial.parent}))
: undefined)
return createEntry(cms.config, type, partial, parent)
const previousIndex = await cms.graph.preferPublished.maybeGet(
Entry({parent: parent?.entryId ?? null})
.select(Entry.index)
.orderBy(Entry.index.desc())
)
const index = generateKeyBetween(previousIndex, null)
return createEntry(cms.config, type, {...partial, index}, parent)
}

constructor(
Expand Down

0 comments on commit 9ecc203

Please sign in to comment.