meridian-vue 0.5.0
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/dist/index.cjs +110 -0
- package/dist/index.js +78 -0
- package/package.json +34 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
useDoc: () => useDoc,
|
|
24
|
+
useLiveQuery: () => useLiveQuery,
|
|
25
|
+
useMutation: () => useMutation,
|
|
26
|
+
usePresence: () => usePresence,
|
|
27
|
+
useQuery: () => useQuery,
|
|
28
|
+
useSync: () => useSync
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
|
|
32
|
+
// src/composables.ts
|
|
33
|
+
var import_vue = require("vue");
|
|
34
|
+
function useQuery(query) {
|
|
35
|
+
const data = (0, import_vue.shallowRef)(void 0);
|
|
36
|
+
(0, import_vue.onMounted)(() => {
|
|
37
|
+
const unsub = query.subscribe((result) => {
|
|
38
|
+
data.value = result;
|
|
39
|
+
});
|
|
40
|
+
(0, import_vue.onUnmounted)(unsub);
|
|
41
|
+
});
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
function useLiveQuery(collection, options = {}) {
|
|
45
|
+
const data = (0, import_vue.shallowRef)(void 0);
|
|
46
|
+
(0, import_vue.watch)(
|
|
47
|
+
() => [options.where, options.orderBy, options.limit],
|
|
48
|
+
() => {
|
|
49
|
+
const query = collection.live(options);
|
|
50
|
+
const unsub = query.subscribe((result) => {
|
|
51
|
+
data.value = result;
|
|
52
|
+
});
|
|
53
|
+
return unsub;
|
|
54
|
+
},
|
|
55
|
+
{ immediate: true }
|
|
56
|
+
);
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
function useDoc(collection, docId) {
|
|
60
|
+
const doc = (0, import_vue.shallowRef)(void 0);
|
|
61
|
+
(0, import_vue.watch)(docId, (id, _oldId, onCleanup) => {
|
|
62
|
+
if (!id) {
|
|
63
|
+
doc.value = null;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const unsub = collection.findOne(id).subscribe((result) => {
|
|
67
|
+
doc.value = result;
|
|
68
|
+
});
|
|
69
|
+
onCleanup(unsub);
|
|
70
|
+
}, { immediate: true });
|
|
71
|
+
return doc;
|
|
72
|
+
}
|
|
73
|
+
function useSync(client) {
|
|
74
|
+
const connected = (0, import_vue.ref)(false);
|
|
75
|
+
const pendingCount = (0, import_vue.ref)(0);
|
|
76
|
+
let interval;
|
|
77
|
+
(0, import_vue.onMounted)(() => {
|
|
78
|
+
interval = setInterval(async () => {
|
|
79
|
+
connected.value = client.connectionState === "connected";
|
|
80
|
+
const pending = await client.debug.getPendingOps();
|
|
81
|
+
pendingCount.value = pending.length;
|
|
82
|
+
}, 1e3);
|
|
83
|
+
});
|
|
84
|
+
(0, import_vue.onUnmounted)(() => clearInterval(interval));
|
|
85
|
+
return { connected, pendingCount };
|
|
86
|
+
}
|
|
87
|
+
function usePresence(client) {
|
|
88
|
+
const peers = (0, import_vue.ref)({});
|
|
89
|
+
(0, import_vue.onMounted)(() => {
|
|
90
|
+
return client.presence.subscribe((p) => {
|
|
91
|
+
peers.value = { ...p };
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return peers;
|
|
95
|
+
}
|
|
96
|
+
function useMutation(collection) {
|
|
97
|
+
const put = (doc) => collection.put(doc);
|
|
98
|
+
const update = (id, fields) => collection.update(id, fields);
|
|
99
|
+
const remove = (id) => collection.delete(id);
|
|
100
|
+
return { put, update, remove };
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
useDoc,
|
|
105
|
+
useLiveQuery,
|
|
106
|
+
useMutation,
|
|
107
|
+
usePresence,
|
|
108
|
+
useQuery,
|
|
109
|
+
useSync
|
|
110
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/composables.ts
|
|
2
|
+
import { ref, watch, onMounted, onUnmounted, shallowRef } from "vue";
|
|
3
|
+
function useQuery(query) {
|
|
4
|
+
const data = shallowRef(void 0);
|
|
5
|
+
onMounted(() => {
|
|
6
|
+
const unsub = query.subscribe((result) => {
|
|
7
|
+
data.value = result;
|
|
8
|
+
});
|
|
9
|
+
onUnmounted(unsub);
|
|
10
|
+
});
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
function useLiveQuery(collection, options = {}) {
|
|
14
|
+
const data = shallowRef(void 0);
|
|
15
|
+
watch(
|
|
16
|
+
() => [options.where, options.orderBy, options.limit],
|
|
17
|
+
() => {
|
|
18
|
+
const query = collection.live(options);
|
|
19
|
+
const unsub = query.subscribe((result) => {
|
|
20
|
+
data.value = result;
|
|
21
|
+
});
|
|
22
|
+
return unsub;
|
|
23
|
+
},
|
|
24
|
+
{ immediate: true }
|
|
25
|
+
);
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function useDoc(collection, docId) {
|
|
29
|
+
const doc = shallowRef(void 0);
|
|
30
|
+
watch(docId, (id, _oldId, onCleanup) => {
|
|
31
|
+
if (!id) {
|
|
32
|
+
doc.value = null;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const unsub = collection.findOne(id).subscribe((result) => {
|
|
36
|
+
doc.value = result;
|
|
37
|
+
});
|
|
38
|
+
onCleanup(unsub);
|
|
39
|
+
}, { immediate: true });
|
|
40
|
+
return doc;
|
|
41
|
+
}
|
|
42
|
+
function useSync(client) {
|
|
43
|
+
const connected = ref(false);
|
|
44
|
+
const pendingCount = ref(0);
|
|
45
|
+
let interval;
|
|
46
|
+
onMounted(() => {
|
|
47
|
+
interval = setInterval(async () => {
|
|
48
|
+
connected.value = client.connectionState === "connected";
|
|
49
|
+
const pending = await client.debug.getPendingOps();
|
|
50
|
+
pendingCount.value = pending.length;
|
|
51
|
+
}, 1e3);
|
|
52
|
+
});
|
|
53
|
+
onUnmounted(() => clearInterval(interval));
|
|
54
|
+
return { connected, pendingCount };
|
|
55
|
+
}
|
|
56
|
+
function usePresence(client) {
|
|
57
|
+
const peers = ref({});
|
|
58
|
+
onMounted(() => {
|
|
59
|
+
return client.presence.subscribe((p) => {
|
|
60
|
+
peers.value = { ...p };
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
return peers;
|
|
64
|
+
}
|
|
65
|
+
function useMutation(collection) {
|
|
66
|
+
const put = (doc) => collection.put(doc);
|
|
67
|
+
const update = (id, fields) => collection.update(id, fields);
|
|
68
|
+
const remove = (id) => collection.delete(id);
|
|
69
|
+
return { put, update, remove };
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
useDoc,
|
|
73
|
+
useLiveQuery,
|
|
74
|
+
useMutation,
|
|
75
|
+
usePresence,
|
|
76
|
+
useQuery,
|
|
77
|
+
useSync
|
|
78
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "meridian-vue",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Vue 3 composables for Meridian — useQuery, useLiveQuery, useDoc, useSync, useMutation",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup src/index.ts --format esm,cjs --external vue",
|
|
10
|
+
"test": "vitest run --passWithNoTests",
|
|
11
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --external vue"
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"vue": "^3.3.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"meridian-client": "workspace:*",
|
|
18
|
+
"meridian-shared": "workspace:*"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"tsup": "^8.0.0",
|
|
22
|
+
"typescript": "^5.5.0",
|
|
23
|
+
"vitest": "^2.0.0",
|
|
24
|
+
"vue": "^3.5.0"
|
|
25
|
+
},
|
|
26
|
+
"files": ["dist"],
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/vahapogut/MeridianDB"
|
|
31
|
+
},
|
|
32
|
+
"keywords": ["vue", "composables", "meridian", "sync", "local-first", "realtime", "crdt"],
|
|
33
|
+
"author": "Abdulvahap OGUT <info@ipeclabs.com>"
|
|
34
|
+
}
|