@jcbuisson/express-x-plugins 4.0.2 → 4.0.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/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Shape, ShapeStream } from '@electric-sql/client'
|
|
2
|
-
import { Observable } from 'rxjs'
|
|
2
|
+
import { firstValueFrom, Observable } from 'rxjs'
|
|
3
3
|
import { getCurrentScope, onScopeDispose, ref } from 'vue'
|
|
4
4
|
|
|
5
5
|
|
|
@@ -54,6 +54,10 @@ export function electricClientPlugin(app, options = {}) {
|
|
|
54
54
|
return value
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
function firstResult(where = {}) {
|
|
58
|
+
return firstValueFrom(getObservable(where))
|
|
59
|
+
}
|
|
60
|
+
|
|
57
61
|
async function create(data) {
|
|
58
62
|
assertPlainObject(data, 'mutation data')
|
|
59
63
|
const uid = globalThis.crypto?.randomUUID?.()
|
|
@@ -73,7 +77,7 @@ export function electricClientPlugin(app, options = {}) {
|
|
|
73
77
|
return value
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
return { getObservable, getVueRef, create, update, remove }
|
|
80
|
+
return { getObservable, getVueRef, firstResult, create, update, remove }
|
|
77
81
|
}
|
|
78
82
|
|
|
79
83
|
return Object.assign(app, { createElectricModel })
|
|
@@ -61,6 +61,21 @@ test('getVueRef returns Shape rows in a Vue ref and cleans up with its scope', (
|
|
|
61
61
|
assert.equal(shape.unsubscribed, true)
|
|
62
62
|
})
|
|
63
63
|
|
|
64
|
+
test('firstResult resolves with the first Shape rows and cleans up its subscription', async () => {
|
|
65
|
+
const app = { service: () => ({}) }
|
|
66
|
+
electricClientPlugin(app, { ShapeStream: FakeStream, Shape: FakeShape })
|
|
67
|
+
const todo = app.createElectricModel('todos')
|
|
68
|
+
|
|
69
|
+
const rows = await todo.firstResult({ completed: false })
|
|
70
|
+
|
|
71
|
+
assert.deepEqual(rows, [{ uid: 'one', completed: false }])
|
|
72
|
+
const stream = FakeStream.instances.at(-1)
|
|
73
|
+
assert.deepEqual(stream.options.params, {
|
|
74
|
+
where: '"completed" = $1', params: ['false'],
|
|
75
|
+
})
|
|
76
|
+
assert.equal(stream.shape.unsubscribed, true)
|
|
77
|
+
})
|
|
78
|
+
|
|
64
79
|
test('model mutations retain the simple Express-X API', async () => {
|
|
65
80
|
const calls = []
|
|
66
81
|
const service = {
|