Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwigschub committed Oct 3, 2023
2 parents 2cf9035 + d37c7f0 commit 691b080
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shex-methods",
"version": "0.2.11",
"version": "0.2.14",
"description": "",
"main": "lib/index.js",
"homepage": "https://ludwigschubi.github.io/shex-methods/",
Expand Down
15 changes: 5 additions & 10 deletions src/handlers/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export async function create<ShapeType, CreateShapeArgs>(
resolve({ doc, errors })
} else {
if (!doesntExist) {
await updateExisting(shape.store, doc, [], ins)
await updateExisting(shape.store, [], ins)
.catch((err) => resolve({ doc, errors: [err] }))
.then(() => resolve({ doc, data: newShape[0], errors }))
} else {
Expand Down Expand Up @@ -100,19 +100,14 @@ export function validateNewShape<ShapeType, CreateShapeArgs>(

export function updateExisting(
store: IndexedFormula,
doc: string,
del: Statement[],
ins: Statement[],
): Promise<void> {
return new Promise((resolve, reject) => {
store.remove(del)
store.add(ins)
store.fetcher
?.putBack(new NamedNode(doc), { withCredentials: false })
.then((res) => {
if (res.ok) resolve()
else reject()
})
store.updater?.update(del, ins, (_doc, ok, err) => {
if (ok) resolve()
else reject(err)
})
})
}

Expand Down
6 changes: 4 additions & 2 deletions src/handlers/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export function update<ShapeType, CreateShapeArgs>(
if (!newShapes || errors) {
resolve({ doc, errors })
} else {
await updateExisting(shape.store, doc, del, ins)
.catch((err) => resolve({ doc, errors: [...(errors ?? []), err] }))
await updateExisting(shape.store, del, ins)
.catch((err) =>
resolve({ doc, errors: err ? [...(errors ?? []), err] : undefined }),
)
.then(() => {
resolve({ doc, data: newShapes[0], errors })
})
Expand Down

0 comments on commit 691b080

Please sign in to comment.