@pluv/io 5.0.1 → 5.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/README.md +38 -42
- package/dist/index.d.mts +542 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1427 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +8 -8
- package/CHANGELOG.md +0 -2353
- package/eslint.config.mjs +0 -4
- package/src/AbstractPersistence.ts +0 -29
- package/src/AbstractPlatform.ts +0 -105
- package/src/AbstractPubSub.ts +0 -20
- package/src/AbstractWebSocket.ts +0 -134
- package/src/IORoom.ts +0 -1245
- package/src/Persistence.ts +0 -81
- package/src/PluvIO.ts +0 -239
- package/src/PluvProcedure.ts +0 -203
- package/src/PluvRouter.ts +0 -61
- package/src/PluvServer.ts +0 -487
- package/src/PubSub.ts +0 -70
- package/src/authorize.ts +0 -76
- package/src/constants.ts +0 -6
- package/src/createIO.ts +0 -55
- package/src/index.ts +0 -55
- package/src/types.ts +0 -287
- package/src/utils/index.ts +0 -2
- package/src/utils/oneLine.ts +0 -7
- package/src/utils/pickBy.ts +0 -16
- package/src/version.ts +0 -3
- package/tsconfig.json +0 -9
- package/tsdown.config.ts +0 -14
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
<a href="https://pluv.io/docs/introduction">
|
|
3
|
-
<img src="https://github.com/pluv-io/pluv/blob/
|
|
3
|
+
<img src="https://github.com/pluv-io/pluv/blob/main/assets/pluv-icon-192x192.png?raw=true" alt="Pluv.IO" width="156" style="border-radius:16px" />
|
|
4
4
|
</a>
|
|
5
5
|
</div>
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<a href="https://www.npmjs.com/package/@pluv/io">
|
|
12
12
|
<img src="https://img.shields.io/npm/v/@pluv/io" alt="npm @pluv/io" />
|
|
13
13
|
</a>
|
|
14
|
-
<a href="https://github.com/pluv-io/pluv/blob/
|
|
14
|
+
<a href="https://github.com/pluv-io/pluv/blob/main/LICENSE">
|
|
15
15
|
<img alt="GitHub" src="https://img.shields.io/github/license/pluv-io/pluv" alt="License MIT" />
|
|
16
16
|
</a>
|
|
17
17
|
<a href="https://commitizen.github.io/cz-cli/">
|
|
@@ -39,25 +39,25 @@ Create your pluv.io backend
|
|
|
39
39
|
```ts
|
|
40
40
|
// backend
|
|
41
41
|
const io = createIO(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
platformNode({
|
|
43
|
+
context: () => ({ db }),
|
|
44
|
+
crdt: yjs,
|
|
45
|
+
}),
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
export const ioServer = io.server({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
getInitialStorage: async ({ context: { db }, room }) => {
|
|
50
|
+
return await db.room
|
|
51
|
+
.findUnique({ where: { id: room } })
|
|
52
|
+
.then((result) => result?.encodedState ?? null);
|
|
53
|
+
},
|
|
54
|
+
router: io.router({
|
|
55
|
+
sendGreeting: io.procedure
|
|
56
|
+
.input(z.object({ message: z.string() }))
|
|
57
|
+
.broadcast(({ message }) => ({
|
|
58
|
+
receiveGreeting: { message },
|
|
59
|
+
})),
|
|
60
|
+
}),
|
|
61
61
|
});
|
|
62
62
|
```
|
|
63
63
|
|
|
@@ -67,29 +67,25 @@ Create your frontend client with your backend types
|
|
|
67
67
|
// frontend
|
|
68
68
|
const types = infer((i) => ({ io: i<typeof ioServer> }));
|
|
69
69
|
const io = createClient({
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
types,
|
|
71
|
+
initialStorage: yjs.doc((t) => ({
|
|
72
|
+
messages: t.array<string>("messages"),
|
|
73
|
+
})),
|
|
74
|
+
presence: z.object({
|
|
75
|
+
selectionId: z.string().nullable(),
|
|
76
|
+
}),
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
-
const {
|
|
80
|
-
event,
|
|
81
|
-
useBroadcast,
|
|
82
|
-
useMyPresence,
|
|
83
|
-
useOthers,
|
|
84
|
-
useStorage
|
|
85
|
-
} = createBundle(io);
|
|
79
|
+
const { event, useBroadcast, useMyPresence, useOthers, useStorage } = createBundle(io);
|
|
86
80
|
```
|
|
87
81
|
|
|
88
82
|
Use powerful primitives to build realtime features
|
|
89
83
|
|
|
90
84
|
```tsx
|
|
91
85
|
// react
|
|
92
|
-
event.receiveGreeting.useEvent(({ data }) => {
|
|
86
|
+
event.receiveGreeting.useEvent(({ data }) => {
|
|
87
|
+
/* ... */
|
|
88
|
+
});
|
|
93
89
|
// ^? const data: { message: string }
|
|
94
90
|
|
|
95
91
|
const broadcast = useBroadcast();
|
|
@@ -98,20 +94,20 @@ broadcast.sendGreeting({ message: "hello world" });
|
|
|
98
94
|
// ^? const sendGreeting: (data: { message: string }) => void
|
|
99
95
|
|
|
100
96
|
const [mySelection, update] = useMyPresence((presence) => {
|
|
101
|
-
// ^? const mySelection: string | null
|
|
102
|
-
|
|
97
|
+
// ^? const mySelection: string | null
|
|
98
|
+
return presence.selectionId;
|
|
103
99
|
});
|
|
104
100
|
|
|
105
101
|
const others = useOthers((others) => {
|
|
106
|
-
// ^? const others = string[]
|
|
107
|
-
|
|
102
|
+
// ^? const others = string[]
|
|
103
|
+
return others.map((other) => other.presence.selectionId);
|
|
108
104
|
});
|
|
109
105
|
|
|
110
106
|
const [
|
|
111
|
-
|
|
112
|
-
// ^? const messages: string[] | null
|
|
113
|
-
|
|
114
|
-
// ^? YArray<string> | null
|
|
107
|
+
messages,
|
|
108
|
+
// ^? const messages: string[] | null
|
|
109
|
+
sharedType,
|
|
110
|
+
// ^? YArray<string> | null
|
|
115
111
|
] = useStorage("messages");
|
|
116
112
|
```
|
|
117
113
|
|
|
@@ -196,4 +192,4 @@ This software uses the following open source tooling and libraries:
|
|
|
196
192
|
|
|
197
193
|
## License
|
|
198
194
|
|
|
199
|
-
[MIT](https://github.com/pluv-io/pluv/blob/
|
|
195
|
+
[MIT](https://github.com/pluv-io/pluv/blob/main/LICENSE)
|